SQLSetStmtOption

decompiled_code:
__int64 __fastcall SQLSetStmtOption(_DWORD *a1, unsigned __int16 a2, __int64 a3)
{
mylog("%s: entering...\n", "SQLSetStmtOption");
if ( a1 )
return set_statement_option(0LL, a1, a2, a3);
SC_log_error("SQLSetStmtOption", &LC10, 0LL);
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, unsigned __int16 a2, __int64 a3)
{
mylog("%s: entering...\n", "SQLSetStmtOption");
if ( a1 )
return func0(0LL, a1, a2, a3);
SC_log_error("SQLSetStmtOption", &LC10, 0LL);
return 4294967294LL;
}

original_code:
RETCODE SQLSetStmtOption(
        HSTMT hstmt,
        UWORD fOption,
        SQLUINTEGER vParam)
{
static char* const func="SQLSetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 return set_statement_option(((void *)0), stmt, fOption, vParam);
}

canonical_original_code:
short SQLSetStmtOption(void *hstmt, unsigned short fOption, unsigned long vParam)
{
static char *func = "SQLSetStmtOption";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 return set_statement_option(((void *)0), stmt, fOption, vParam);
}

variable_types:
hstmt
void *

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

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


SQLGetStmtOption

repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
__int64 __fastcall SQLGetStmtOption(__int64 a1, unsigned __int16 a2, __int64 *a3)
{
__int64 result; // rax
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rcx
int v8; // edx
__int64 v9; // rax
const char *v10; // rdx
__int64 v11; // rsi
char v12[88]; // [rsp+0h] [rbp-58h] BYREF

mylog("%s: entering...\n", "SQLGetStmtOption");
if ( a1 )
{
switch ( a2 )
{
case 0u:
case 4u:
case 0xAu:
goto LABEL_4;
case 1u:
v9 = *(int *)(a1 + 24);
*a3 = v9;
mylog("GetSmtOption: MAX_ROWS, returning %d\n", v9);
return 0LL;
case 2u:
*a3 = 1LL;
return 0LL;
case 3u:
*a3 = *(int *)(a1 + 28);
return 0LL;
case 5u:
*a3 = *(int *)(a1 + 52);
return 0LL;
case 6u:
mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
*a3 = *(int *)(a1 + 40);
return 0LL;
case 7u:
mylog("GetStmtOption(): SQL_CONCURRENCY\n");
*a3 = *(int *)(a1 + 44);
return 0LL;
case 8u:
mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
*a3 = *(int *)(a1 + 36);
return 0LL;
case 9u:
*a3 = *(int *)(a1 + 32);
return 0LL;
case 0xBu:
*a3 = *(int *)(a1 + 48);
return 0LL;
case 0xCu:
*a3 = *(int *)(a1 + 56);
return 0LL;
case 0xDu:
case 0xEu:
v5 = *(_QWORD *)(a1 + 8);
v6 = *(_DWORD *)(a1 + 136);
if ( *(_BYTE *)(a1 + 218) || !globals[26] )
{
if ( v6 < 0 )
goto LABEL_29;
v7 = *(_QWORD *)(v5 + 8);
v8 = v7 ? *(_DWORD *)(v7 + 4) : *(_DWORD *)(v5 + 28);
if ( v8 <= v6 )
goto LABEL_29;
}
else if ( v6 == -1 || !v5 || !*(_QWORD *)(v5 + 96) )
{
LABEL_29:
v10 = "Not positioned on a valid row.";
v11 = 15LL;
goto LABEL_30;
}
if ( a2 != 13 || *(_DWORD *)(a1 + 56) )
{
*a3 = SC_get_bookmark(a1);
return 0LL;
}
v10 = "Operation invalid because use bookmarks not enabled.";
v11 = 25LL;
LABEL_30:
SC_set_error(a1, v11, v10);
SC_log_error("SQLGetStmtOption", &LC10, a1);
result = 0xFFFFFFFFLL;
break;
default:
if ( a2 == 0xFFFE )
{
LABEL_4:
*a3 = 0LL;
result = 0LL;
}
else
{
SC_set_error(a1, 10LL, "Unknown statement option (Get)");
sprintf(v12, "fOption=%d", a2);
SC_log_error("SQLGetStmtOption", v12, a1);
result = 0xFFFFFFFFLL;
}
return result;
}
}
else
{
SC_log_error("SQLGetStmtOption", &LC10, 0LL);
result = 4294967294LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int16 a2, __int64 *a3)
{
__int64 result; // rax
__int64 v5; // rdx
int v6; // eax
__int64 v7; // rcx
int v8; // edx
__int64 v9; // rax
const char *v10; // rdx
__int64 v11; // rsi
char v12[88]; // [rsp+0h] [rbp-58h] BYREF

mylog("%s: entering...\n", "SQLGetStmtOption");
if ( a1 )
{
switch ( a2 )
{
case 0u:
case 4u:
case 0xAu:
goto LABEL_4;
case 1u:
v9 = *(int *)(a1 + 24);
*a3 = v9;
mylog("GetSmtOption: MAX_ROWS, returning %d\n", v9);
return 0LL;
case 2u:
*a3 = 1LL;
return 0LL;
case 3u:
*a3 = *(int *)(a1 + 28);
return 0LL;
case 5u:
*a3 = *(int *)(a1 + 52);
return 0LL;
case 6u:
mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
*a3 = *(int *)(a1 + 40);
return 0LL;
case 7u:
mylog("GetStmtOption(): SQL_CONCURRENCY\n");
*a3 = *(int *)(a1 + 44);
return 0LL;
case 8u:
mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
*a3 = *(int *)(a1 + 36);
return 0LL;
case 9u:
*a3 = *(int *)(a1 + 32);
return 0LL;
case 0xBu:
*a3 = *(int *)(a1 + 48);
return 0LL;
case 0xCu:
*a3 = *(int *)(a1 + 56);
return 0LL;
case 0xDu:
case 0xEu:
v5 = *(_QWORD *)(a1 + 8);
v6 = *(_DWORD *)(a1 + 136);
if ( *(_BYTE *)(a1 + 218) || !globals[26] )
{
if ( v6 < 0 )
goto LABEL_29;
v7 = *(_QWORD *)(v5 + 8);
v8 = v7 ? *(_DWORD *)(v7 + 4) : *(_DWORD *)(v5 + 28);
if ( v8 <= v6 )
goto LABEL_29;
}
else if ( v6 == -1 || !v5 || !*(_QWORD *)(v5 + 96) )
{
LABEL_29:
v10 = "Not positioned on a valid row.";
v11 = 15LL;
goto LABEL_30;
}
if ( a2 != 13 || *(_DWORD *)(a1 + 56) )
{
*a3 = SC_get_bookmark(a1);
return 0LL;
}
v10 = "Operation invalid because use bookmarks not enabled.";
v11 = 25LL;
LABEL_30:
SC_set_error(a1, v11, v10);
SC_log_error("SQLGetStmtOption", &LC10, a1);
result = 0xFFFFFFFFLL;
break;
default:
if ( a2 == 0xFFFE )
{
LABEL_4:
*a3 = 0LL;
result = 0LL;
}
else
{
SC_set_error(a1, 10LL, "Unknown statement option (Get)");
sprintf(v12, "fOption=%d", a2);
SC_log_error("SQLGetStmtOption", v12, a1);
result = 0xFFFFFFFFLL;
}
return result;
}
}
else
{
SC_log_error("SQLGetStmtOption", &LC10, 0LL);
result = 4294967294LL;
}
return result;
}

original_code:
RETCODE SQLGetStmtOption(
        HSTMT hstmt,
        UWORD fOption,
        PTR pvParam)
{
static char* const func="SQLGetStmtOption";
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *res;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch(fOption) {
 case 13:
 case 14:
  res = stmt->result;
  if ( stmt->manual_result || ! globals.use_declarefetch) {
   if((stmt->currTuple < 0) ||
      (stmt->currTuple >= (res->manual_tuples ? (res->manual_tuples->num_tuples) : res->fcount))) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  else {
   if (stmt->currTuple == -1 || ! res || ! res->tupleField) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  if (fOption == 13 && stmt->options.use_bookmarks == 0UL) {
   SC_set_error(stmt, 25, "Operation invalid because use bookmarks not enabled.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  *((UDWORD *) pvParam) = SC_get_bookmark(stmt);
  break;
 case 4:
  *((SDWORD *) pvParam) = 0UL;
  break;
 case 5:
  *((SDWORD *) pvParam) = stmt->options.bind_size;
  break;
 case 7:
  mylog("GetStmtOption(): SQL_CONCURRENCY\n");
  *((SDWORD *)pvParam) = stmt->options.scroll_concurrency;
  break;
 case 6:
  mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
  *((SDWORD *)pvParam) = stmt->options.cursor_type;
  break;
 case 8:
  mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
  *((SDWORD *)pvParam) = stmt->options.keyset_size;
  break;
 case 3:
  *((SDWORD *)pvParam) = stmt->options.maxLength;
  break;
 case 1:
  *((SDWORD *)pvParam) = stmt->options.maxRows;
  mylog("GetSmtOption: MAX_ROWS, returning %d\n", stmt->options.maxRows);
  break;
 case 2:
  *((SDWORD *) pvParam) = 1UL;
  break;
 case 0:
  *((SDWORD *) pvParam) = 0;
  break;
 case 11:
  *((SDWORD *) pvParam) = stmt->options.retrieve_data;
  break;
 case 9:
  *((SDWORD *) pvParam) = stmt->options.rowset_size;
  break;
 case 10:
  *((SDWORD *) pvParam) = 0UL;
  break;
 case 12:
  *((SDWORD *) pvParam) = stmt->options.use_bookmarks;
  break;
    case 65534:
  *((SDWORD *) pvParam) = 0;
        break;
 default:
  {
  char option[64];
  SC_set_error(stmt, 10, "Unknown statement option (Get)");
  sprintf(option, "fOption=%d", fOption);
  SC_log_error(func, option, stmt);
  return (-1);
  }
 }
 return 0;
}

canonical_original_code:
short SQLGetStmtOption(void *hstmt, unsigned short fOption, void *pvParam)
{
static char *func = "SQLGetStmtOption";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
struct QResultClass_ *res;
 mylog("%s: entering...\n", func);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 switch(fOption) {
 case 13:
 case 14:
  res = stmt->result;
  if ( stmt->manual_result || ! globals.use_declarefetch) {
   if((stmt->currTuple < 0) ||
      (stmt->currTuple >= (res->manual_tuples ? (res->manual_tuples->num_tuples) : res->fcount))) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  else {
   if (stmt->currTuple == -1 || ! res || ! res->tupleField) {
    SC_set_error(stmt, 15, "Not positioned on a valid row.");
    SC_log_error(func, "", stmt);
    return (-1);
   }
  }
  if (fOption == 13 && stmt->options.use_bookmarks == 0UL) {
   SC_set_error(stmt, 25, "Operation invalid because use bookmarks not enabled.");
   SC_log_error(func, "", stmt);
   return (-1);
  }
  *((unsigned long *) pvParam) = SC_get_bookmark(stmt);
  break;
 case 4:
  *((long *) pvParam) = 0UL;
  break;
 case 5:
  *((long *) pvParam) = stmt->options.bind_size;
  break;
 case 7:
  mylog("GetStmtOption(): SQL_CONCURRENCY\n");
  *((long *)pvParam) = stmt->options.scroll_concurrency;
  break;
 case 6:
  mylog("GetStmtOption(): SQL_CURSOR_TYPE\n");
  *((long *)pvParam) = stmt->options.cursor_type;
  break;
 case 8:
  mylog("GetStmtOption(): SQL_KEYSET_SIZE\n");
  *((long *)pvParam) = stmt->options.keyset_size;
  break;
 case 3:
  *((long *)pvParam) = stmt->options.maxLength;
  break;
 case 1:
  *((long *)pvParam) = stmt->options.maxRows;
  mylog("GetSmtOption: MAX_ROWS, returning %d\n", stmt->options.maxRows);
  break;
 case 2:
  *((long *) pvParam) = 1UL;
  break;
 case 0:
  *((long *) pvParam) = 0;
  break;
 case 11:
  *((long *) pvParam) = stmt->options.retrieve_data;
  break;
 case 9:
  *((long *) pvParam) = stmt->options.rowset_size;
  break;
 case 10:
  *((long *) pvParam) = 0UL;
  break;
 case 12:
  *((long *) pvParam) = stmt->options.use_bookmarks;
  break;
    case 65534:
  *((long *) pvParam) = 0;
        break;
 default:
  {
  char option[64];
  SC_set_error(stmt, 10, "Unknown statement option (Get)");
  sprintf(option, "fOption=%d", fOption);
  SC_log_error(func, option, stmt);
  return (-1);
  }
 }
 return 0;
}

variable_types:
fOption
unsigned short

variable_types:
pvParam
void *

variable_types:
func
char *

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

variable_types:
option
char [64]

return_type: short

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 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 TABLE_INFO { struct col_info *col_info; char name[-1]; char alias[-1]; }

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


SQLRemoveDriverW

decompiled_code:
__int64 __fastcall SQLRemoveDriverW(__int64 a1, unsigned int a2, __int64 *a3)
{
_BYTE *v4; // rbp
unsigned int v5; // er12

v4 = (_BYTE *)single_string_alloc_and_copy();
inst_logClear();
v5 = SQLRemoveDriver(v4, a2, a3);
free(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 *a3)
{
_BYTE *v4; // rbp
unsigned int v5; // er12

v4 = (_BYTE *)single_string_alloc_and_copy();
inst_logClear();
v5 = func0(v4, a2, a3);
free(v4);
return v5;
}

original_code:
int SQLRemoveDriverW(LPCWSTR lpszDriver,
                             int fRemoveDSN,
                             LPDWORD lpdwUsageCount)
{
 int ret;
 char *drv = _single_string_alloc_and_copy( lpszDriver );
    inst_logClear();
 ret = SQLRemoveDriver( drv, fRemoveDSN, lpdwUsageCount );
 free( drv );
 return ret;
}

canonical_original_code:
int SQLRemoveDriverW(unsigned short *lpszDriver, int fRemoveDSN, unsigned long *lpdwUsageCount)
{
 int ret;
 char *drv = _single_string_alloc_and_copy( lpszDriver );
    inst_logClear();
 ret = SQLRemoveDriver( drv, fRemoveDSN, lpdwUsageCount );
 free( drv );
 return ret;
}

variable_types:
lpszDriver
unsigned short *

variable_types: fRemoveDSN int

variable_types:
lpdwUsageCount
unsigned long *

variable_types: ret int

variable_types:
drv
char *

return_type: int


SQLSetStmtAttr

decompiled_code:
__int64 __fastcall SQLSetStmtAttr(__int64 a1)
{
if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLSetStmtAttr.c", "SQLSetStmtAttr.c", 29LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSetStmtAttr.c",
"SQLSetStmtAttr.c",
34LL,
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), "SQLSetStmtAttr.c", "SQLSetStmtAttr.c", 29LL, 1LL, 1LL, a1 + 136);
logPushMsg(
*(_QWORD *)(a1 + 1160),
"SQLSetStmtAttr.c",
"SQLSetStmtAttr.c",
34LL,
1LL,
1LL,
"SQL_ERROR This function not supported");
return 0xFFFFFFFFLL;
}

original_code:
SQLRETURN SQLSetStmtAttr( SQLHSTMT statement_handle,
           SQLINTEGER attribute,
           SQLPOINTER value,
           SQLINTEGER string_length )
{
    DMHSTMT statement = (DMHSTMT) statement_handle;
    SQLRETURN ret;
    SQLCHAR s1[ 100 + 128 ];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLSetStmtAttr.c",
                    242,
                    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\tAttribute = %s\n\t\t\tValue = %p\n\t\t\tStrLen = %d",
                statement,
                __stmt_attr_as_string( s1, attribute ),
                value,
                (int)string_length );
        dm_log_write( "SQLSetStmtAttr.c",
                265,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( attribute == 7 ||
            attribute == 6 ||
            attribute == 10 ||
            attribute == 12 ||
            attribute == (-1) ||
            attribute == (-2) )
    {
        if ( statement -> state == 2 ||
                statement -> state == 3 )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    288,
                    0,
                    0,
                    "Error: HY011" );
            __post_internal_error( &statement -> error,
                 ERROR_HY011, ((void *)0),
                 statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        else if ( statement -> state == 4 ||
                statement -> state == 5 ||
                statement -> state == 6 ||
                statement -> state == 7 )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    305,
                    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);
        }
        else if ( statement -> state == 8 ||
                statement -> state == 9 ||
                statement -> state == 10 ||
                statement -> state == 11 ||
                statement -> state == 12 )
        {
            if ( statement -> prepared )
            {
                dm_log_write( "SQLSetStmtAttr.c",
                        325,
                        0,
                        0,
                        "Error: HY011" );
                __post_internal_error( &statement -> error,
                     ERROR_HY011, ((void *)0),
                     statement -> connection -> environment -> requested_version );
                return function_return_ex(3,statement,(-1),0);
            }
            else
            {
                dm_log_write( "SQLSetStmtAttr.c",
                        339,
                        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);
            }
        }
    }
    else
    {
        if ( statement -> state == 8 ||
                statement -> state == 9 ||
                statement -> state == 10 ||
                statement -> state == 11 ||
                statement -> state == 12 )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    361,
                    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[70].func!=((void *)0)) &&
          !(statement -> connection->functions[70].funcW!=((void *)0))) &&
        !(statement -> connection->functions[71].func!=((void *)0)))
    {
        dm_log_write( "SQLSetStmtAttr.c",
                379,
                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 ( attribute == 10010 )
    {
        DMHDESC desc = ( DMHDESC ) value;
  if ( desc == ((void *)0) || desc == statement -> implicit_ard )
  {
   SQLHDESC drv_desc = ((void *)0);
   ret = 0;
   if ( desc == statement -> implicit_ard )
   {
    drv_desc = statement -> implicit_ard -> driver_desc;
   }
         if ( (statement -> connection->functions[70].func!=((void *)0)))
         {
              ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,drv_desc,0);
         }
         else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
         {
             ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,statement -> implicit_ard -> driver_desc,0);
         }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,statement -> implicit_ard -> driver_desc);
            }
   if ( ret != 0 )
   {
       if ( log_info.log_flag )
       {
           sprintf( statement -> msg,
                   "\n\t\tExit:[%s]",
                       __get_return_status( ret, s1 ));
           dm_log_write( "SQLSetStmtAttr.c",
                   449,
                   0,
                   0,
                   statement -> msg );
       }
       return function_return_ex(3,statement,ret,0);
   }
   statement -> apd = statement -> implicit_apd;
      if ( log_info.log_flag )
      {
          sprintf( statement -> msg,
                  "\n\t\tExit:[%s]",
                      __get_return_status( ret, s1 ));
          dm_log_write( "SQLSetStmtAttr.c",
                  471,
                  0,
                  0,
                  statement -> msg );
      }
      return function_return_ex(3,statement,ret,0);
  }
        if ( !__validate_desc( desc ))
        {
            thread_release( 3, statement );
            sprintf( statement -> msg,
                    "\n\t\tExit:[%s]",
                    __get_return_status( (-2), s1 ));
            dm_log_write( "SQLSetStmtAttr.c",
                    489,
                    0,
                    0,
                    statement -> msg );
            return (-2);
        }
        if ( desc -> implicit &&
                desc != statement -> implicit_ard )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    501,
                    0,
                    0,
                    "Error: HY017" );
            __post_internal_error( &statement -> error,
                    ERROR_HY017, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        if ( desc -> connection !=
                statement -> connection )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    517,
                    0,
                    0,
                    "Error: HY024" );
            __post_internal_error( &statement -> error,
                    ERROR_HY024, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        value = ( SQLPOINTER ) desc -> driver_desc;
        statement -> ard = desc;
        desc -> associated_with = statement;
    }
    if ( attribute == 10011 )
    {
        DMHDESC desc = ( DMHDESC ) value;
  if ( desc == ((void *)0) || desc == statement -> implicit_apd )
  {
   SQLHDESC drv_desc = ((void *)0);
   ret = 0;
   if ( desc == statement -> implicit_apd )
   {
    drv_desc = statement -> implicit_apd -> driver_desc;
   }
         if ( (statement -> connection->functions[70].func!=((void *)0)))
         {
              ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,statement -> implicit_apd -> driver_desc,0);
         }
         else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
         {
             ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,statement -> implicit_apd -> driver_desc,0);
         }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,drv_desc);
            }
   if ( ret != 0 )
   {
       if ( log_info.log_flag )
       {
           sprintf( statement -> msg,
                   "\n\t\tExit:[%s]",
                       __get_return_status( ret, s1 ));
           dm_log_write( "SQLSetStmtAttr.c",
                   591,
                   0,
                   0,
                   statement -> msg );
       }
       return function_return_ex(3,statement,ret,0);
   }
   statement -> apd = statement -> implicit_apd;
      if ( log_info.log_flag )
      {
          sprintf( statement -> msg,
                  "\n\t\tExit:[%s]",
                      __get_return_status( ret, s1 ));
          dm_log_write( "SQLSetStmtAttr.c",
                  613,
                  0,
                  0,
                  statement -> msg );
      }
      return function_return_ex(3,statement,ret,0);
  }
        if ( !__validate_desc( desc ))
        {
            sprintf( statement -> msg,
                    "\n\t\tExit:[%s]",
                    __get_return_status( (-2), s1 ));
            dm_log_write( "SQLSetStmtAttr.c",
                    629,
                    0,
                    0,
                    statement -> msg );
            thread_release( 3, statement );
            return (-2);
        }
        if ( desc -> implicit &&
                desc != statement -> implicit_apd )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    643,
                    0,
                    0,
                    "Error: HY017" );
            __post_internal_error( &statement -> error,
                    ERROR_HY017, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        if ( desc -> connection !=
                statement -> connection )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    659,
                    0,
                    0,
                    "Error: HY024" );
            __post_internal_error( &statement -> error,
                    ERROR_HY024, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        value = ( SQLPOINTER ) desc -> driver_desc;
        statement -> apd = desc;
        desc -> associated_with = statement;
    }
    if ( attribute == 10014 )
    {
        statement -> metadata_id = (SQLINTEGER) value;
    }
    if ( attribute == 10012 ||
        attribute == 10013 )
    {
        dm_log_write( "SQLSetStmtAttr.c",
                    692,
                    0,
                    0,
                    "Error: HY017" );
        __post_internal_error( &statement -> error,
                ERROR_HY017, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    ret = dm_check_statement_attrs( statement, attribute, value );
    if ( ret != 0 )
    {
        dm_log_write( "SQLSetStmtAttr.c",
                    712,
                    0,
                    0,
                    "Error: HY024" );
        __post_internal_error( &statement -> error,
                ERROR_HY024, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    value = __attr_override( statement, 3, attribute, value, &string_length );
    if ( attribute == 16 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)) &&
            !(statement -> connection->functions[30].func!=((void *)0)))
    {
        statement -> fetch_bm_ptr = (SQLUINTEGER*) value;
        if ( statement -> connection -> cl_handle )
        {
            if ( (statement -> connection->functions[70].func!=((void *)0)))
            {
                (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
            }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
            }
        }
        ret = 0;
    }
    else if ( attribute == 25 &&
       statement -> connection -> driver_act_ver == 2UL )
    {
        statement -> row_st_arr = (SQLUSMALLINT*) value;
        if ( statement -> connection -> cl_handle )
        {
            if ( (statement -> connection->functions[70].func!=((void *)0)))
            {
                (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
            }
            else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
            {
                (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,value,string_length);
            }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
            }
        }
        ret = 0;
    }
    else if ( attribute == 26 &&
       statement -> connection -> driver_act_ver == 2UL )
    {
        statement -> row_ct_ptr = (SQLUINTEGER*) value;
        if ( statement -> connection -> cl_handle )
        {
            if ( (statement -> connection->functions[70].func!=((void *)0)))
            {
                (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
            }
            else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
            {
                (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,value,string_length);
            }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
            }
        }
        ret = 0;
    }
    else if ( attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        statement -> row_array_size = (SQLUINTEGER) value;
        if ( (statement -> connection->functions[70].func!=((void *)0)))
        {
            ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,9,value,string_length);
        }
        else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,9,value,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,9,value);
        }
    }
    else if ( (statement -> connection->functions[70].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
    }
    else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
    {
        ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,value,string_length);
    }
    else
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    891,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
    }
    if ( attribute == 12 && (((ret)&(~1))==0))
    {
        statement -> bookmarks_on = (SQLUINTEGER) value;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLSetStmtAttr.c",
                925,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

canonical_original_code:
short SQLSetStmtAttr(void *statement_handle, long attribute, void *value, long string_length)
{
    struct statement *statement = (DMHSTMT) statement_handle;
    short ret;
    unsigned char s1[-1];
    if ( !__validate_stmt( statement ))
    {
        dm_log_write( "SQLSetStmtAttr.c",
                    242,
                    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\tAttribute = %s\n\t\t\tValue = %p\n\t\t\tStrLen = %d",
                statement,
                __stmt_attr_as_string( s1, attribute ),
                value,
                (int)string_length );
        dm_log_write( "SQLSetStmtAttr.c",
                265,
                0,
                0,
                statement -> msg );
    }
    thread_protect( 3, statement );
    if ( attribute == 7 ||
            attribute == 6 ||
            attribute == 10 ||
            attribute == 12 ||
            attribute == (-1) ||
            attribute == (-2) )
    {
        if ( statement -> state == 2 ||
                statement -> state == 3 )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    288,
                    0,
                    0,
                    "Error: HY011" );
            __post_internal_error( &statement -> error,
                 ERROR_HY011, ((void *)0),
                 statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        else if ( statement -> state == 4 ||
                statement -> state == 5 ||
                statement -> state == 6 ||
                statement -> state == 7 )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    305,
                    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);
        }
        else if ( statement -> state == 8 ||
                statement -> state == 9 ||
                statement -> state == 10 ||
                statement -> state == 11 ||
                statement -> state == 12 )
        {
            if ( statement -> prepared )
            {
                dm_log_write( "SQLSetStmtAttr.c",
                        325,
                        0,
                        0,
                        "Error: HY011" );
                __post_internal_error( &statement -> error,
                     ERROR_HY011, ((void *)0),
                     statement -> connection -> environment -> requested_version );
                return function_return_ex(3,statement,(-1),0);
            }
            else
            {
                dm_log_write( "SQLSetStmtAttr.c",
                        339,
                        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);
            }
        }
    }
    else
    {
        if ( statement -> state == 8 ||
                statement -> state == 9 ||
                statement -> state == 10 ||
                statement -> state == 11 ||
                statement -> state == 12 )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    361,
                    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[70].func!=((void *)0)) &&
          !(statement -> connection->functions[70].funcW!=((void *)0))) &&
        !(statement -> connection->functions[71].func!=((void *)0)))
    {
        dm_log_write( "SQLSetStmtAttr.c",
                379,
                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 ( attribute == 10010 )
    {
        struct descriptor *desc = ( DMHDESC ) value;
  if ( desc == ((void *)0) || desc == statement -> implicit_ard )
  {
   void *drv_desc = ((void *)0);
   ret = 0;
   if ( desc == statement -> implicit_ard )
   {
    drv_desc = statement -> implicit_ard -> driver_desc;
   }
         if ( (statement -> connection->functions[70].func!=((void *)0)))
         {
              ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,drv_desc,0);
         }
         else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
         {
             ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,statement -> implicit_ard -> driver_desc,0);
         }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,statement -> implicit_ard -> driver_desc);
            }
   if ( ret != 0 )
   {
       if ( log_info.log_flag )
       {
           sprintf( statement -> msg,
                   "\n\t\tExit:[%s]",
                       __get_return_status( ret, s1 ));
           dm_log_write( "SQLSetStmtAttr.c",
                   449,
                   0,
                   0,
                   statement -> msg );
       }
       return function_return_ex(3,statement,ret,0);
   }
   statement -> apd = statement -> implicit_apd;
      if ( log_info.log_flag )
      {
          sprintf( statement -> msg,
                  "\n\t\tExit:[%s]",
                      __get_return_status( ret, s1 ));
          dm_log_write( "SQLSetStmtAttr.c",
                  471,
                  0,
                  0,
                  statement -> msg );
      }
      return function_return_ex(3,statement,ret,0);
  }
        if ( !__validate_desc( desc ))
        {
            thread_release( 3, statement );
            sprintf( statement -> msg,
                    "\n\t\tExit:[%s]",
                    __get_return_status( (-2), s1 ));
            dm_log_write( "SQLSetStmtAttr.c",
                    489,
                    0,
                    0,
                    statement -> msg );
            return (-2);
        }
        if ( desc -> implicit &&
                desc != statement -> implicit_ard )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    501,
                    0,
                    0,
                    "Error: HY017" );
            __post_internal_error( &statement -> error,
                    ERROR_HY017, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        if ( desc -> connection !=
                statement -> connection )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    517,
                    0,
                    0,
                    "Error: HY024" );
            __post_internal_error( &statement -> error,
                    ERROR_HY024, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        value = ( void * ) desc -> driver_desc;
        statement -> ard = desc;
        desc -> associated_with = statement;
    }
    if ( attribute == 10011 )
    {
        struct descriptor *desc = ( DMHDESC ) value;
  if ( desc == ((void *)0) || desc == statement -> implicit_apd )
  {
   void *drv_desc = ((void *)0);
   ret = 0;
   if ( desc == statement -> implicit_apd )
   {
    drv_desc = statement -> implicit_apd -> driver_desc;
   }
         if ( (statement -> connection->functions[70].func!=((void *)0)))
         {
              ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,statement -> implicit_apd -> driver_desc,0);
         }
         else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
         {
             ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,statement -> implicit_apd -> driver_desc,0);
         }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,drv_desc);
            }
   if ( ret != 0 )
   {
       if ( log_info.log_flag )
       {
           sprintf( statement -> msg,
                   "\n\t\tExit:[%s]",
                       __get_return_status( ret, s1 ));
           dm_log_write( "SQLSetStmtAttr.c",
                   591,
                   0,
                   0,
                   statement -> msg );
       }
       return function_return_ex(3,statement,ret,0);
   }
   statement -> apd = statement -> implicit_apd;
      if ( log_info.log_flag )
      {
          sprintf( statement -> msg,
                  "\n\t\tExit:[%s]",
                      __get_return_status( ret, s1 ));
          dm_log_write( "SQLSetStmtAttr.c",
                  613,
                  0,
                  0,
                  statement -> msg );
      }
      return function_return_ex(3,statement,ret,0);
  }
        if ( !__validate_desc( desc ))
        {
            sprintf( statement -> msg,
                    "\n\t\tExit:[%s]",
                    __get_return_status( (-2), s1 ));
            dm_log_write( "SQLSetStmtAttr.c",
                    629,
                    0,
                    0,
                    statement -> msg );
            thread_release( 3, statement );
            return (-2);
        }
        if ( desc -> implicit &&
                desc != statement -> implicit_apd )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    643,
                    0,
                    0,
                    "Error: HY017" );
            __post_internal_error( &statement -> error,
                    ERROR_HY017, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        if ( desc -> connection !=
                statement -> connection )
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    659,
                    0,
                    0,
                    "Error: HY024" );
            __post_internal_error( &statement -> error,
                    ERROR_HY024, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        value = ( void * ) desc -> driver_desc;
        statement -> apd = desc;
        desc -> associated_with = statement;
    }
    if ( attribute == 10014 )
    {
        statement -> metadata_id = (long) value;
    }
    if ( attribute == 10012 ||
        attribute == 10013 )
    {
        dm_log_write( "SQLSetStmtAttr.c",
                    692,
                    0,
                    0,
                    "Error: HY017" );
        __post_internal_error( &statement -> error,
                ERROR_HY017, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    ret = dm_check_statement_attrs( statement, attribute, value );
    if ( ret != 0 )
    {
        dm_log_write( "SQLSetStmtAttr.c",
                    712,
                    0,
                    0,
                    "Error: HY024" );
        __post_internal_error( &statement -> error,
                ERROR_HY024, ((void *)0),
                statement -> connection -> environment -> requested_version );
        return function_return_ex(3,statement,(-1),0);
    }
    value = __attr_override( statement, 3, attribute, value, &string_length );
    if ( attribute == 16 &&
            statement -> connection -> driver_act_ver == 2UL &&
            (statement -> connection->functions[28].func!=((void *)0)) &&
            !(statement -> connection->functions[30].func!=((void *)0)))
    {
        statement -> fetch_bm_ptr = (unsigned long *) value;
        if ( statement -> connection -> cl_handle )
        {
            if ( (statement -> connection->functions[70].func!=((void *)0)))
            {
                (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
            }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
            }
        }
        ret = 0;
    }
    else if ( attribute == 25 &&
       statement -> connection -> driver_act_ver == 2UL )
    {
        statement -> row_st_arr = (unsigned short *) value;
        if ( statement -> connection -> cl_handle )
        {
            if ( (statement -> connection->functions[70].func!=((void *)0)))
            {
                (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
            }
            else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
            {
                (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,value,string_length);
            }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
            }
        }
        ret = 0;
    }
    else if ( attribute == 26 &&
       statement -> connection -> driver_act_ver == 2UL )
    {
        statement -> row_ct_ptr = (unsigned long *) value;
        if ( statement -> connection -> cl_handle )
        {
            if ( (statement -> connection->functions[70].func!=((void *)0)))
            {
                (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
            }
            else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
            {
                (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,value,string_length);
            }
            else
            {
                ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
            }
        }
        ret = 0;
    }
    else if ( attribute == 27 &&
            statement -> connection -> driver_act_ver == 2UL )
    {
        statement -> row_array_size = (unsigned long) value;
        if ( (statement -> connection->functions[70].func!=((void *)0)))
        {
            ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,9,value,string_length);
        }
        else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
        {
            ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,9,value,string_length);
        }
        else
        {
            ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,9,value);
        }
    }
    else if ( (statement -> connection->functions[70].func!=((void *)0)))
    {
        ret = (statement -> connection->functions[70].func) (statement -> driver_stmt,attribute,value,string_length);
    }
    else if ( (statement -> connection->functions[70].funcW!=((void *)0)))
    {
        ret = (statement -> connection->functions[70].funcW) (statement -> driver_stmt,attribute,value,string_length);
    }
    else
    {
        if ( attribute < 20000 &&
                ( attribute > 14 || attribute < 0 ))
        {
            dm_log_write( "SQLSetStmtAttr.c",
                    891,
                    0,
                    0,
                    "Error: HY092" );
            __post_internal_error( &statement -> error,
                    ERROR_HY092, ((void *)0),
                    statement -> connection -> environment -> requested_version );
            return function_return_ex(3,statement,(-1),0);
        }
        ret = (statement -> connection->functions[71].func) (statement -> driver_stmt,attribute,value);
    }
    if ( attribute == 12 && (((ret)&(~1))==0))
    {
        statement -> bookmarks_on = (unsigned long) value;
    }
    if ( log_info.log_flag )
    {
        sprintf( statement -> msg,
                "\n\t\tExit:[%s]",
                    __get_return_status( ret, s1 ));
        dm_log_write( "SQLSetStmtAttr.c",
                925,
                0,
                0,
                statement -> msg );
    }
    return function_return_ex(3,statement,ret,0);
}

variable_types: attribute long

variable_types:
value
void *

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

variable_types: struct descriptor { int type; struct descriptor *next_class_list; char msg[1024]; int state; 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; void *driver_desc; 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 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; int implicit; void *associated_with; union pthread_mutex_t mutex; } *

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

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


SQLTables

decompiled_code:
__int64 __fastcall SQLTables(__int64 a1)
{
_QWORD *v2; // rdi
void *v3; // rdi
__int64 v4; // rdi

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLTables.c", "SQLTables.c", 62LL, 1LL, 1LL, a1 + 136);
v2 = *(_QWORD **)(a1 + 1168);
if ( *v2 )
((void (__fastcall *)(_QWORD *, const char *))FreeResults)(v2, "SQLTables.c");
v3 = *(void **)(a1 + 128);
if ( v3 )
free(v3);
v4 = *(_QWORD *)(a1 + 1160);
*(_QWORD *)(a1 + 128) = 0LL;
logPushMsg(v4, "SQLTables.c", "SQLTables.c", 95LL, 0LL, 0LL, "SQL_SUCCESS");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_QWORD *v2; // rdi
void *v3; // rdi
__int64 v4; // rdi

if ( !a1 )
return 4294967294LL;
sprintf((char *)(a1 + 136), "hStmt = $%08lX", a1);
logPushMsg(*(_QWORD *)(a1 + 1160), "SQLTables.c", "SQLTables.c", 62LL, 1LL, 1LL, a1 + 136);
v2 = *(_QWORD **)(a1 + 1168);
if ( *v2 )
((void (__fastcall *)(_QWORD *, const char *))FreeResults)(v2, "SQLTables.c");
v3 = *(void **)(a1 + 128);
if ( v3 )
free(v3);
v4 = *(_QWORD *)(a1 + 1160);
*(_QWORD *)(a1 + 128) = 0LL;
logPushMsg(v4, "SQLTables.c", "SQLTables.c", 95LL, 0LL, 0LL, "SQL_SUCCESS");
return 0LL;
}

original_code:
RETCODE SQLTables(
                          HSTMT hstmt,
                          UCHAR * szTableQualifier,
                          SWORD cbTableQualifier,
                          UCHAR * szTableOwner,
                          SWORD cbTableOwner,
                          UCHAR * szTableName,
                          SWORD cbTableName,
                          UCHAR * szTableType,
                          SWORD cbTableType)
{
static char* const func = "SQLTables";
StatementClass *stmt = (StatementClass *) hstmt;
StatementClass *tbl_stmt;
TupleNode *row;
HSTMT htbl_stmt;
RETCODE result;
char *tableType;
char tables_query[65536];
char table_name[128], table_owner[128], relkind_or_hasrules[128];
ConnectionClass *conn;
ConnInfo *ci;
char *prefix[32], prefixes[256];
char *table_type[32], table_types[128];
char show_system_tables, show_regular_tables, show_views;
char regular_table, view, systable;
int i;
mylog("%s: entering...stmt=%u\n", func, stmt);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 stmt->manual_result = (int)1;
 stmt->errormsg_created = (int)1;
 conn = (ConnectionClass *) (stmt->hdbc);
 ci = &stmt->hdbc->connInfo;
 result = PG_SQLAllocStmt( stmt->hdbc, &htbl_stmt);
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "Couldn't allocate statement for SQLTables result.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 tbl_stmt = (StatementClass *) htbl_stmt;
 if ((((conn)->pg_version_major > (int) 7.1 || ((conn)->pg_version_major == (int) 7.1 && (conn)->pg_version_minor >= atoi((strchr("7.1", '.') + 1)))))) {
  strcpy(tables_query, "select relname, usename, relkind from pg_class, pg_user");
  strcat(tables_query, " where relkind in ('r', 'v')");
 }
 else {
  strcpy(tables_query, "select relname, usename, relhasrules from pg_class, pg_user");
  strcat(tables_query, " where relkind = 'r'");
 }
 my_strcat(tables_query, " and usename like '%.*s'", (char*)szTableOwner, cbTableOwner);
 my_strcat(tables_query, " and relname like '%.*s'", (char*)szTableName, cbTableName);
 strcpy(prefixes, globals.extra_systable_prefixes);
 i = 0;
 prefix[i] = strtok(prefixes, ";");
 while (prefix[i] && i<32) {
  prefix[++i] = strtok(((void *)0), ";");
 }
 show_system_tables = (int)0;
 show_regular_tables = (int)0;
 show_views = (int)0;
 tableType = make_string((char*)szTableType, cbTableType, ((void *)0));
 if (tableType) {
  strcpy(table_types, tableType);
  free(tableType);
  i = 0;
  table_type[i] = strtok(table_types, ",");
  while (table_type[i] && i<32) {
   table_type[++i] = strtok(((void *)0), ",");
  }
  i = 0;
  while (table_type[i]) {
   if ( strstr(table_type[i], "SYSTEM TABLE"))
    show_system_tables = (int)1;
   else if ( strstr(table_type[i], "TABLE"))
    show_regular_tables = (int)1;
   else if ( strstr(table_type[i], "VIEW"))
    show_views = (int)1;
   i++;
  }
 }
 else {
  show_regular_tables = (int)1;
  show_views = (int)1;
 }
 if ( ! atoi(ci->show_system_tables) && ! show_system_tables) {
  strcat(tables_query, " and relname !~ '^" "pg_");
  i = 0;
  while(prefix[i]) {
   strcat(tables_query, "|^");
   strcat(tables_query, prefix[i]);
   i++;
  }
  strcat(tables_query, "'");
 }
 if ((! (((conn)->pg_version_major > (int) 7.1 || ((conn)->pg_version_major == (int) 7.1 && (conn)->pg_version_minor >= atoi((strchr("7.1", '.') + 1)))))))
  strcat(tables_query, " and relname !~ '^xinv[0-9]+'");
 strcat(tables_query, " and usesysid = relowner");
 strcat(tables_query, " order by relname");
 result = PG_SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((StatementClass *)htbl_stmt));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
    result = PG_SQLBindCol(htbl_stmt, 1, 1,
                        table_name, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
        return (-1);
    }
    result = PG_SQLBindCol(htbl_stmt, 2, 1,
                        table_owner, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
        return (-1);
    }
    result = PG_SQLBindCol(htbl_stmt, 3, 1,
                        relkind_or_hasrules, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
        return (-1);
    }
 stmt->result = QR_Constructor();
 if(!stmt->result) {
  SC_set_error(stmt, 4, "Couldn't allocate memory for SQLTables result.");
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
 extend_bindings(stmt, 5);
 QR_set_num_fields(stmt->result, 5);
 (CI_set_field_info(stmt->result->fields, 0, "TABLE_QUALIFIER", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 1, "TABLE_OWNER", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 2, "TABLE_NAME", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 3, "TABLE_TYPE", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 4, "REMARKS", 25, 254, -1));
 result = PG_SQLFetch(htbl_stmt);
 while((result == 0) || (result == 1)) {
  systable = (int)0;
  if( ! atoi(ci->show_system_tables)) {
   if ( strncmp(table_name, "pg_", strlen("pg_")) == 0)
    systable = (int)1;
   else {
    i = 0;
    while (prefix[i]) {
     mylog("table_name='%s', prefix[%d]='%s'\n", table_name, i, prefix[i]);
     if (strncmp(table_name, prefix[i], strlen(prefix[i])) == 0) {
      systable = (int)1;
      break;
     }
     i++;
    }
   }
  }
  if ((((conn)->pg_version_major > (int) 7.1 || ((conn)->pg_version_major == (int) 7.1 && (conn)->pg_version_minor >= atoi((strchr("7.1", '.') + 1))))))
   view = (relkind_or_hasrules[0] == 'v');
  else
   view = (relkind_or_hasrules[0] == '1');
  regular_table = ( ! systable && ! view);
  if ( (systable && show_system_tables) ||
    (view && show_views) ||
    (regular_table && show_regular_tables)) {
   row = (TupleNode *)malloc(sizeof(TupleNode) + (5 - 1) * sizeof(TupleField));
   set_tuplefield_string(&row->tuple[0], "");
   mylog("SQLTables: table_name = '%s'\n", table_name);
   set_tuplefield_string(&row->tuple[1], "");
   set_tuplefield_string(&row->tuple[2], table_name);
   set_tuplefield_string(&row->tuple[3], systable ? "SYSTEM TABLE" : (view ? "VIEW" : "TABLE"));
   set_tuplefield_string(&row->tuple[4], "");
   (TL_add_tuple(stmt->result->manual_tuples, row));
  }
  result = PG_SQLFetch(htbl_stmt);
    }
 if(result != 100) {
  SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((StatementClass *)htbl_stmt));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
 stmt->status = STMT_FINISHED;
 stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
 PG_SQLFreeStmt(htbl_stmt, 1);
 mylog("SQLTables(): EXIT,  stmt=%u\n", stmt);
 return 0;
}

canonical_original_code:
short SQLTables(void *hstmt, unsigned char *szTableQualifier, short cbTableQualifier, unsigned char *szTableOwner, short cbTableOwner, unsigned char *szTableName, short cbTableName, unsigned char *szTableType, short cbTableType)
{
static char *func = "SQLTables";
struct StatementClass_ *stmt = (StatementClass *) hstmt;
struct StatementClass_ *tbl_stmt;
struct TupleNode_ *row;
void *htbl_stmt;
short result;
char *tableType;
char tables_query[65536];
char table_name[128]; char table_owner[128]; char relkind_or_hasrules[128];
struct ConnectionClass_ *conn;
struct ConnInfo *ci;
char *prefix[32]; char prefixes[256];
char *table_type[32]; char table_types[128];
char show_system_tables; char show_regular_tables; char show_views;
char regular_table; char view; char systable;
int i;
mylog("%s: entering...stmt=%u\n", func, stmt);
 if( ! stmt) {
  SC_log_error(func, "", ((void *)0));
  return (-2);
 }
 stmt->manual_result = (int)1;
 stmt->errormsg_created = (int)1;
 conn = (struct ConnectionClass_ *) (stmt->hdbc);
 ci = &stmt->hdbc->connInfo;
 result = PG_SQLAllocStmt( stmt->hdbc, &htbl_stmt);
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, 4, "Couldn't allocate statement for SQLTables result.");
  SC_log_error(func, "", stmt);
  return (-1);
 }
 tbl_stmt = (struct StatementClass_ *) htbl_stmt;
 if ((((conn)->pg_version_major > (int) 7.1 || ((conn)->pg_version_major == (int) 7.1 && (conn)->pg_version_minor >= atoi((strchr("7.1", '.') + 1)))))) {
  strcpy(tables_query, "select relname, usename, relkind from pg_class, pg_user");
  strcat(tables_query, " where relkind in ('r', 'v')");
 }
 else {
  strcpy(tables_query, "select relname, usename, relhasrules from pg_class, pg_user");
  strcat(tables_query, " where relkind = 'r'");
 }
 my_strcat(tables_query, " and usename like '%.*s'", (char *)szTableOwner, cbTableOwner);
 my_strcat(tables_query, " and relname like '%.*s'", (char *)szTableName, cbTableName);
 strcpy(prefixes, globals.extra_systable_prefixes);
 i = 0;
 prefix[i] = strtok(prefixes, ";");
 while (prefix[i] && i<32) {
  prefix[++i] = strtok(((void *)0), ";");
 }
 show_system_tables = (int)0;
 show_regular_tables = (int)0;
 show_views = (int)0;
 tableType = make_string((char *)szTableType, cbTableType, ((void *)0));
 if (tableType) {
  strcpy(table_types, tableType);
  free(tableType);
  i = 0;
  table_type[i] = strtok(table_types, ",");
  while (table_type[i] && i<32) {
   table_type[++i] = strtok(((void *)0), ",");
  }
  i = 0;
  while (table_type[i]) {
   if ( strstr(table_type[i], "SYSTEM TABLE"))
    show_system_tables = (int)1;
   else if ( strstr(table_type[i], "TABLE"))
    show_regular_tables = (int)1;
   else if ( strstr(table_type[i], "VIEW"))
    show_views = (int)1;
   i++;
  }
 }
 else {
  show_regular_tables = (int)1;
  show_views = (int)1;
 }
 if ( ! atoi(ci->show_system_tables) && ! show_system_tables) {
  strcat(tables_query, " and relname !~ '^" "pg_");
  i = 0;
  while(prefix[i]) {
   strcat(tables_query, "|^");
   strcat(tables_query, prefix[i]);
   i++;
  }
  strcat(tables_query, "'");
 }
 if ((! (((conn)->pg_version_major > (int) 7.1 || ((conn)->pg_version_major == (int) 7.1 && (conn)->pg_version_minor >= atoi((strchr("7.1", '.') + 1)))))))
  strcat(tables_query, " and relname !~ '^xinv[0-9]+'");
 strcat(tables_query, " and usesysid = relowner");
 strcat(tables_query, " order by relname");
 result = PG_SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
 if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)htbl_stmt));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
    result = PG_SQLBindCol(htbl_stmt, 1, 1,
                        table_name, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
        return (-1);
    }
    result = PG_SQLBindCol(htbl_stmt, 2, 1,
                        table_owner, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
        return (-1);
    }
    result = PG_SQLBindCol(htbl_stmt, 3, 1,
                        relkind_or_hasrules, 128, ((void *)0));
    if((result != 0) && (result != 1)) {
  SC_set_error(stmt, (tbl_stmt->__error_number), (tbl_stmt->__error_message));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
        return (-1);
    }
 stmt->result = QR_Constructor();
 if(!stmt->result) {
  SC_set_error(stmt, 4, "Couldn't allocate memory for SQLTables result.");
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
 extend_bindings(stmt, 5);
 QR_set_num_fields(stmt->result, 5);
 (CI_set_field_info(stmt->result->fields, 0, "TABLE_QUALIFIER", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 1, "TABLE_OWNER", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 2, "TABLE_NAME", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 3, "TABLE_TYPE", 25, 128, -1));
 (CI_set_field_info(stmt->result->fields, 4, "REMARKS", 25, 254, -1));
 result = PG_SQLFetch(htbl_stmt);
 while((result == 0) || (result == 1)) {
  systable = (int)0;
  if( ! atoi(ci->show_system_tables)) {
   if ( strncmp(table_name, "pg_", strlen("pg_")) == 0)
    systable = (int)1;
   else {
    i = 0;
    while (prefix[i]) {
     mylog("table_name='%s', prefix[%d]='%s'\n", table_name, i, prefix[i]);
     if (strncmp(table_name, prefix[i], strlen(prefix[i])) == 0) {
      systable = (int)1;
      break;
     }
     i++;
    }
   }
  }
  if ((((conn)->pg_version_major > (int) 7.1 || ((conn)->pg_version_major == (int) 7.1 && (conn)->pg_version_minor >= atoi((strchr("7.1", '.') + 1))))))
   view = (relkind_or_hasrules[0] == 'v');
  else
   view = (relkind_or_hasrules[0] == '1');
  regular_table = ( ! systable && ! view);
  if ( (systable && show_system_tables) ||
    (view && show_views) ||
    (regular_table && show_regular_tables)) {
   row = (struct TupleNode_ *)malloc(sizeof(TupleNode) + (5 - 1) * sizeof(TupleField));
   set_tuplefield_string(&row->tuple[0], "");
   mylog("SQLTables: table_name = '%s'\n", table_name);
   set_tuplefield_string(&row->tuple[1], "");
   set_tuplefield_string(&row->tuple[2], table_name);
   set_tuplefield_string(&row->tuple[3], systable ? "SYSTEM TABLE" : (view ? "VIEW" : "TABLE"));
   set_tuplefield_string(&row->tuple[4], "");
   (TL_add_tuple(stmt->result->manual_tuples, row));
  }
  result = PG_SQLFetch(htbl_stmt);
    }
 if(result != 100) {
  SC_set_error(stmt, (tbl_stmt->__error_number), SC_create_errormsg((struct StatementClass_ *)htbl_stmt));
  SC_log_error(func, "", stmt);
  PG_SQLFreeStmt(htbl_stmt, 1);
  return (-1);
 }
 stmt->status = STMT_FINISHED;
 stmt->currTuple = -1;
 stmt->rowset_start = -1;
 stmt->current_col = -1;
 PG_SQLFreeStmt(htbl_stmt, 1);
 mylog("SQLTables(): EXIT,  stmt=%u\n", stmt);
 return 0;
}

variable_types:
hstmt
void *

variable_types:
szTableQualifier
unsigned char *

variable_types: cbTableQualifier short

variable_types:
szTableOwner
unsigned char *

variable_types: cbTableOwner short

variable_types:
szTableName
unsigned char *

variable_types: cbTableName short

variable_types:
szTableType
unsigned char *

variable_types: cbTableType short

variable_types: result short

variable_types:
tableType
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: 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:
prefix
char *[32]

variable_types:
prefixes
char [256]

variable_types: view char

variable_types: systable char

variable_types: i int


decompiled_code:
__int64 __fastcall SOCK_connect_to_ip(__int64 a1, __int16 a2, const char *a3)
{
__int64 result; // rax
in_addr_t v6; // eax
int v7; // edx
int v8; // eax
int v9; // er8
int v10; // edi
struct hostent *v11; // rax
struct sockaddr dest; // [rsp+0h] [rbp-28h] BYREF

if ( *(_DWORD *)(a1 + 32) == -1 )
{
dest = 0LL;
v6 = inet_addr(a3);
if ( v6 == 0xFFFFFFFFLL )
{
v11 = gethostbyname(a3);
if ( !v11 )
{
*(_DWORD *)(a1 + 48) = 2;
*(_QWORD *)(a1 + 40) = "Could not resolve hostname.";
return 0LL;
}
memcpy(&dest.sa_data[2], *(const void **)v11->h_addr_list, v11->h_length);
}
else
{
*(_QWORD *)&dest.sa_data[2] = v6;
}
dest.sa_family = 2;
*(_WORD *)dest.sa_data = _bswap_16(a2);
v8 = socket(2, 1, v7);
*(_DWORD *)(a1 + 32) = v8;
if ( v8 == -1 )
{
*(_DWORD *)(a1 + 48) = 3;
*(_QWORD *)(a1 + 40) = "Could not create Socket.";
result = 0LL;
}
else
{
v9 = connect(v8, &dest, 0x10u);
result = 1LL;
if ( v9 < 0 )
{
*(_DWORD *)(a1 + 48) = 4;
v10 = *(_DWORD *)(a1 + 32);
*(_QWORD *)(a1 + 40) = "Could not connect to remote socket.";
close(v10);
*(_DWORD *)(a1 + 32) = -1;
result = 0LL;
}
}
}
else
{
*(_DWORD *)(a1 + 48) = 1;
*(_QWORD *)(a1 + 40) = "Socket is already connected";
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int16 a2, const char *a3)
{
__int64 result; // rax
in_addr_t v6; // eax
int v7; // edx
int v8; // eax
int v9; // er8
int v10; // edi
struct hostent *v11; // rax
struct sockaddr dest; // [rsp+0h] [rbp-28h] BYREF

if ( *(_DWORD *)(a1 + 32) == -1 )
{
dest = 0LL;
v6 = inet_addr(a3);
if ( v6 == 0xFFFFFFFFLL )
{
v11 = gethostbyname(a3);
if ( !v11 )
{
*(_DWORD *)(a1 + 48) = 2;
*(_QWORD *)(a1 + 40) = "Could not resolve hostname.";
return 0LL;
}
memcpy(&dest.sa_data[2], *(const void **)v11->h_addr_list, v11->h_length);
}
else
{
*(_QWORD *)&dest.sa_data[2] = v6;
}
dest.sa_family = 2;
*(_WORD *)dest.sa_data = func0(a2);
v8 = socket(2, 1, v7);
*(_DWORD *)(a1 + 32) = v8;
if ( v8 == -1 )
{
*(_DWORD *)(a1 + 48) = 3;
*(_QWORD *)(a1 + 40) = "Could not create Socket.";
result = 0LL;
}
else
{
v9 = connect(v8, &dest, 0x10u);
result = 1LL;
if ( v9 < 0 )
{
*(_DWORD *)(a1 + 48) = 4;
v10 = *(_DWORD *)(a1 + 32);
*(_QWORD *)(a1 + 40) = "Could not connect to remote socket.";
close(v10);
*(_DWORD *)(a1 + 32) = -1;
result = 0LL;
}
}
}
else
{
*(_DWORD *)(a1 + 48) = 1;
*(_QWORD *)(a1 + 40) = "Socket is already connected";
result = 0LL;
}
return result;
}

original_code:
static char
SOCK_connect_to_ip(SocketClass *self, unsigned short port, char *hostname)
{
struct hostent *host;
struct sockaddr_in sadr;
unsigned long iaddr;
 if (self->socket != -1) {
  self->errornumber = 1;
  self->errormsg = "Socket is already connected";
  return 0;
 }
 memset((char *)&sadr, 0, sizeof(sadr));
 iaddr = inet_addr(hostname);
 if (iaddr == ((in_addr_t) 0xffffffff)) {
  host = gethostbyname(hostname);
  if (host == ((void *)0)) {
   self->errornumber = 2;
   self->errormsg = "Could not resolve hostname.";
   return 0;
  }
  memcpy(&(sadr.sin_addr), host->h_addr_list[0], host->h_length);
 }
 else
  memcpy(&(sadr.sin_addr), (struct in_addr *) &iaddr, sizeof(iaddr));
 sadr.sin_family = 2;
 sadr.sin_port = htons(port);
 self->socket = socket(2, SOCK_STREAM, 0);
 if (self->socket == -1) {
  self->errornumber = 3;
  self->errormsg = "Could not create Socket.";
  return 0;
 }
 if ( connect(self->socket, (struct sockaddr *)&(sadr),
   sizeof(sadr)) < 0) {
  self->errornumber = 4;
  self->errormsg = "Could not connect to remote socket.";
  close(self->socket);
  self->socket = (int) -1;
  return 0;
 }
 return 1;
}

canonical_original_code:
static char SOCK_connect_to_ip(struct SocketClass_ *self, unsigned short port, char *hostname)
{
struct hostent *host;
struct sockaddr_in sadr;
unsigned long iaddr;
 if (self->socket != -1) {
  self->errornumber = 1;
  self->errormsg = "Socket is already connected";
  return 0;
 }
 memset((char *)&sadr, 0, sizeof(sadr));
 iaddr = inet_addr(hostname);
 if (iaddr == ((unsigned int) 0xffffffff)) {
  host = gethostbyname(hostname);
  if (host == ((void *)0)) {
   self->errornumber = 2;
   self->errormsg = "Could not resolve hostname.";
   return 0;
  }
  memcpy(&(sadr.sin_addr), host->h_addr_list[0], host->h_length);
 }
 else
  memcpy(&(sadr.sin_addr), (struct in_addr *) &iaddr, sizeof(iaddr));
 sadr.sin_family = 2;
 sadr.sin_port = htons(port);
 self->socket = socket(2, SOCK_STREAM, 0);
 if (self->socket == -1) {
  self->errornumber = 3;
  self->errormsg = "Could not create Socket.";
  return 0;
 }
 if ( connect(self->socket, (struct sockaddr *)&(sadr),
   sizeof(sadr)) < 0) {
  self->errornumber = 4;
  self->errormsg = "Could not connect to remote socket.";
  close(self->socket);
  self->socket = (int) -1;
  return 0;
 }
 return 1;
}

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

variable_types:
port
unsigned short

variable_types:
hostname
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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

variable_types:
iaddr
unsigned long

return_type: char

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

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


decompiled_code:
void __fastcall SOCK_clear_error(__int64 a1)
{
*(_DWORD *)(a1 + 48) = 0;
*(_QWORD *)(a1 + 40) = 0LL;
}

original_code:
void
SOCK_clear_error(SocketClass *self)
{
 self->errornumber = 0;
 self->errormsg = ((void *)0);
}

canonical_original_code:
void SOCK_clear_error(struct SocketClass_ *self)
{
 self->errornumber = 0;
 self->errormsg = ((void *)0);
}

return_type: void

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


decompiled_code:
_DWORD *SOCK_Constructor()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
size_t v2; // rbp
void *v3; // rax
void *v4; // rax

v0 = malloc(0x38uLL);
if ( !v0 )
return 0LL;
*(_QWORD *)v0 = 0LL;
v1 = v0;
v0[8] = -1;
v0[2] = 0;
v2 = *((int *)&globals + 1);
v3 = malloc(v2);
*((_QWORD *)v1 + 2) = v3;
if ( !v3 )
return 0LL;
v4 = malloc(v2);
*((_QWORD *)v1 + 3) = v4;
if ( !v4 )
return 0LL;
*((_QWORD *)v1 + 5) = 0LL;
v1[12] = 0;
*((_BYTE *)v1 + 52) = 0;
return v1;
}

original_code:
SocketClass *
SOCK_Constructor()
{
SocketClass *rv;
    rv = (SocketClass *) malloc(sizeof(SocketClass));
    if (rv != ((void *)0)) {
  rv->socket = (int) -1;
  rv->buffer_filled_in = 0;
  rv->buffer_filled_out = 0;
  rv->buffer_read_in = 0;
  rv->buffer_in = (unsigned char *) malloc(globals.socket_buffersize);
  if ( ! rv->buffer_in)
   return ((void *)0);
  rv->buffer_out = (unsigned char *) malloc(globals.socket_buffersize);
  if ( ! rv->buffer_out)
   return ((void *)0);
        rv->errormsg = ((void *)0);
        rv->errornumber = 0;
  rv->reverse = (int)0;
    }
    return rv;
}

canonical_original_code:
struct SocketClass_ *SOCK_Constructor()
{
struct SocketClass_ *rv;
    rv = (struct SocketClass_ *) malloc(sizeof(SocketClass));
    if (rv != ((void *)0)) {
  rv->socket = (int) -1;
  rv->buffer_filled_in = 0;
  rv->buffer_filled_out = 0;
  rv->buffer_read_in = 0;
  rv->buffer_in = (unsigned char *) malloc(globals.socket_buffersize);
  if ( ! rv->buffer_in)
   return ((void *)0);
  rv->buffer_out = (unsigned char *) malloc(globals.socket_buffersize);
  if ( ! rv->buffer_out)
   return ((void *)0);
        rv->errormsg = ((void *)0);
        rv->errornumber = 0;
  rv->reverse = (int)0;
    }
    return rv;
}

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