SQLValidDSN

decompiled_code:
_BOOL8 __fastcall SQLValidDSN(char *s)
{
_BOOL8 result; // rax
size_t v2; // rdx
char *v3; // rdx
char *v4; // rdx
char *v5; // rdx
char *v6; // rdx
char *v7; // rdx
char *v8; // rdx
char *v9; // rdx
char *v10; // rdx
char *v11; // rdx
char *v12; // rdx
char *v13; // rdx
char *v14; // rdx
char *v15; // rdx

inst_logClear();
if ( !s )
return 0LL;
result = 0LL;
if ( *s )
{
v2 = strlen(s);
result = 0LL;
if ( v2 <= 0x20 )
{
v3 = strchr(s, 91);
result = 0LL;
if ( !v3 )
{
v4 = strchr(s, 93);
result = 0LL;
if ( !v4 )
{
v5 = strchr(s, 123);
result = 0LL;
if ( !v5 )
{
v6 = strchr(s, 125);
result = 0LL;
if ( !v6 )
{
v7 = strchr(s, 40);
result = 0LL;
if ( !v7 )
{
v8 = strchr(s, 41);
result = 0LL;
if ( !v8 )
{
v9 = strchr(s, 44);
result = 0LL;
if ( !v9 )
{
v10 = strchr(s, 59);
result = 0LL;
if ( !v10 )
{
v11 = strchr(s, 63);
result = 0LL;
if ( !v11 )
{
v12 = strchr(s, 42);
result = 0LL;
if ( !v12 )
{
v13 = strchr(s, 61);
result = 0LL;
if ( !v13 )
{
v14 = strchr(s, 33);
result = 0LL;
if ( !v14 )
{
v15 = strchr(s, 64);
result = 0LL;
if ( !v15 )
result = strchr(s, 92) == 0LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *s)
{
_BOOL8 result; // rax
size_t v2; // rdx
char *v3; // rdx
char *v4; // rdx
char *v5; // rdx
char *v6; // rdx
char *v7; // rdx
char *v8; // rdx
char *v9; // rdx
char *v10; // rdx
char *v11; // rdx
char *v12; // rdx
char *v13; // rdx
char *v14; // rdx
char *v15; // rdx

inst_logClear();
if ( !s )
return 0LL;
result = 0LL;
if ( *s )
{
v2 = strlen(s);
result = 0LL;
if ( v2 <= 0x20 )
{
v3 = strchr(s, 91);
result = 0LL;
if ( !v3 )
{
v4 = strchr(s, 93);
result = 0LL;
if ( !v4 )
{
v5 = strchr(s, 123);
result = 0LL;
if ( !v5 )
{
v6 = strchr(s, 125);
result = 0LL;
if ( !v6 )
{
v7 = strchr(s, 40);
result = 0LL;
if ( !v7 )
{
v8 = strchr(s, 41);
result = 0LL;
if ( !v8 )
{
v9 = strchr(s, 44);
result = 0LL;
if ( !v9 )
{
v10 = strchr(s, 59);
result = 0LL;
if ( !v10 )
{
v11 = strchr(s, 63);
result = 0LL;
if ( !v11 )
{
v12 = strchr(s, 42);
result = 0LL;
if ( !v12 )
{
v13 = strchr(s, 61);
result = 0LL;
if ( !v13 )
{
v14 = strchr(s, 33);
result = 0LL;
if ( !v14 )
{
v15 = strchr(s, 64);
result = 0LL;
if ( !v15 )
result = strchr(s, 92) == 0LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
int SQLValidDSN( LPCSTR pszDSN )
{
    inst_logClear();
 if ( pszDSN == ((void *)0) )
  return 0;
 if ( strlen( pszDSN ) < 1 || strlen( pszDSN ) > 32 )
  return 0;
 if ( strstr( pszDSN, "[" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "]" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "{" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "}" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "(" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, ")" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "," ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, ";" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "?" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "*" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "=" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "!" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "@" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "\\" ) != ((void *)0) )
  return 0;
 return 1;
}

canonical_original_code:
int SQLValidDSN(char *pszDSN)
{
    inst_logClear();
 if ( pszDSN == ((void *)0) )
  return 0;
 if ( strlen( pszDSN ) < 1 || strlen( pszDSN ) > 32 )
  return 0;
 if ( strstr( pszDSN, "[" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "]" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "{" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "}" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "(" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, ")" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "," ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, ";" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "?" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "*" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "=" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "!" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "@" ) != ((void *)0) )
  return 0;
 if ( strstr( pszDSN, "\\" ) != ((void *)0) )
  return 0;
 return 1;
}

variable_types:
pszDSN
char *


SQLValidDSNW

repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
_BOOL8 __fastcall SQLValidDSNW(__int64 a1)
{
char *v1; // rbx
_BOOL4 v2; // ebp

inst_logClear();
v1 = (char *)single_string_alloc_and_copy(a1);
v2 = SQLValidDSN(v1);
free(v1);
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
char *v1; // rbx
_BOOL4 v2; // ebp

inst_logClear();
v1 = (char *)single_string_alloc_and_copy(a1);
v2 = func0(v1);
free(v1);
return v2;
}

original_code:
int SQLValidDSNW(LPCWSTR lpszDSN)
{
 char *dsn;
 int ret;
    inst_logClear();
 dsn = _single_string_alloc_and_copy( lpszDSN );
 ret = SQLValidDSN( dsn );
 free( dsn );
 return ret;
}

canonical_original_code:
int SQLValidDSNW(unsigned short *lpszDSN)
{
 char *dsn;
 int ret;
    inst_logClear();
 dsn = _single_string_alloc_and_copy( lpszDSN );
 ret = SQLValidDSN( dsn );
 free( dsn );
 return ret;
}

variable_types:
lpszDSN
unsigned short *

variable_types:
dsn
char *

variable_types: ret int

return_type: int


CreateDataSource

decompiled_code:
_BOOL8 __fastcall CreateDataSource(_BYTE *a1)
{
_BYTE *v1; // rsi
char v3[4096]; // [rsp+0h] [rbp-1018h] BYREF
__int64 v4; // [rsp+1000h] [rbp-18h]

v1 = a1;
v4 = 0LL;
strcpy(v3, "odbcinstQ4");
if ( a1 && !*a1 )
v1 = 0LL;
return (unsigned int)SQLCreateDataSource(v3, v1) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
_BYTE *v1; // rsi
char v3[4096]; // [rsp+0h] [rbp-1018h] BYREF
__int64 v4; // [rsp+1000h] [rbp-18h]

v1 = a1;
v4 = 0LL;
strcpy(v3, "odbcinstQ4");
if ( a1 && !*a1 )
v1 = 0LL;
return (unsigned int)SQLCreateDataSource(v3, v1) == 0;
}

original_code:
int CreateDataSource( char *pszDataSourceName )
{
    ODBCINSTWND odbcinstwnd;
    odbcinstwnd.hWnd = 0;
    strcpy( odbcinstwnd.szUI, "odbcinstQ4" );
    if ( SQLCreateDataSource( (HWND)&(odbcinstwnd), ( (pszDataSourceName && *pszDataSourceName) ? pszDataSourceName : 0 ) ) == 0 )
        return 1;
    return 0;
}

canonical_original_code:
int CreateDataSource(char *pszDataSourceName)
{
    struct tODBCINSTWND odbcinstwnd;
    odbcinstwnd.hWnd = 0;
    strcpy( odbcinstwnd.szUI, "odbcinstQ4" );
    if ( SQLCreateDataSource( (HWND)&(odbcinstwnd), ( (pszDataSourceName && *pszDataSourceName) ? pszDataSourceName : 0 ) ) == 0 )
        return 1;
    return 0;
}

variable_types:
pszDataSourceName
char *

variable_types: struct tODBCINSTWND { char szUI[4096]; void *hWnd; }


ManageDataSources

decompiled_code:
_BOOL8 ManageDataSources()
{
char v1[4096]; // [rsp+0h] [rbp-1018h] BYREF
__int64 v2; // [rsp+1000h] [rbp-18h]

v2 = 0LL;
strcpy(v1, "odbcinstQ4");
return (unsigned int)SQLManageDataSources(v1) == 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
char v1[4096]; // [rsp+0h] [rbp-1018h] BYREF
__int64 v2; // [rsp+1000h] [rbp-18h]

v2 = 0LL;
strcpy(v1, "odbcinstQ4");
return (unsigned int)SQLManageDataSources(v1) == 0;
}

original_code:
int ManageDataSources()
{
    ODBCINSTWND odbcinstwnd;
    odbcinstwnd.hWnd = 0;
    strcpy( odbcinstwnd.szUI, "odbcinstQ4" );
    if ( SQLManageDataSources( (HWND)&(odbcinstwnd) ) == 0 )
        return 1;
    return 0;
}

canonical_original_code:
int ManageDataSources()
{
    struct tODBCINSTWND odbcinstwnd;
    odbcinstwnd.hWnd = 0;
    strcpy( odbcinstwnd.szUI, "odbcinstQ4" );
    if ( SQLManageDataSources( (HWND)&(odbcinstwnd) ) == 0 )
        return 1;
    return 0;
}

user_defined_types: struct tODBCINSTWND { char szUI[4096]; void *hWnd; }


DriverUninstall

decompiled_code:
__int64 __fastcall DriverUninstall(const char *a1)
{
__int64 result; // rax
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)SQLRemoveDriver(a1, 0LL, &v2) )
{
if ( v2 )
{
result = 0LL;
if ( !cVerbose )
{
printf("%s usage count has been reduced to %d\n", a1, v2);
result = 0LL;
}
}
else
{
result = 0LL;
if ( !cVerbose )
{
printf("%s has been deleted (if it existed at all) because its usage count became zero\n", a1);
result = 0LL;
}
}
}
else
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( !cVerbose )
{
printf("odbcinst: SQLRemoveDriver failed with %s.\n", szError);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 result; // rax
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)SQLRemoveDriver(a1, 0LL, &v2) )
{
if ( v2 )
{
result = 0LL;
if ( !cVerbose )
{
printf("%s usage count has been reduced to %d\n", a1, v2);
result = 0LL;
}
}
else
{
result = 0LL;
if ( !cVerbose )
{
printf("%s has been deleted (if it existed at all) because its usage count became zero\n", a1);
result = 0LL;
}
}
}
else
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( !cVerbose )
{
printf("odbcinst: SQLRemoveDriver failed with %s.\n", szError);
result = 1LL;
}
}
return result;
}

original_code:
int DriverUninstall( char *pszDriver )
{
    DWORD nUsageCount;
    if ( SQLRemoveDriver( pszDriver, 0, &nUsageCount ) == 0 )
    {
        SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
        if ( cVerbose == 0 ) printf( "odbcinst: SQLRemoveDriver failed with %s.\n", szError );
        return 1;
    }
    if ( nUsageCount == 0 )
    {
        if ( cVerbose == 0 ) printf( "%s has been deleted (if it existed at all) because its usage count became zero\n", pszDriver );
    }
    else
    {
        if ( cVerbose == 0 ) printf( "%s usage count has been reduced to %d\n", pszDriver, (int)nUsageCount );
    }
    return 0;
}

canonical_original_code:
int DriverUninstall(char *pszDriver)
{
    unsigned long nUsageCount;
    if ( SQLRemoveDriver( pszDriver, 0, &nUsageCount ) == 0 )
    {
        SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
        if ( cVerbose == 0 ) printf( "odbcinst: SQLRemoveDriver failed with %s.\n", szError );
        return 1;
    }
    if ( nUsageCount == 0 )
    {
        if ( cVerbose == 0 ) printf( "%s has been deleted (if it existed at all) because its usage count became zero\n", pszDriver );
    }
    else
    {
        if ( cVerbose == 0 ) printf( "%s usage count has been reduced to %d\n", pszDriver, (int)nUsageCount );
    }
    return 0;
}

variable_types:
pszDriver
char *

variable_types:
nUsageCount
unsigned long


DriverQuery

decompiled_code:
__int64 __fastcall DriverQuery(const char *a1)
{
char *v1; // rbx
__int64 result; // rax
char *v3; // rbx
char v4[512]; // [rsp+0h] [rbp-11E8h] BYREF
char s[4072]; // [rsp+200h] [rbp-FE8h] BYREF

if ( !a1 || !*a1 )
{
if ( (int)SQLGetPrivateProfileString(0LL, 0LL, 0LL, s, 4047LL, "ODBCINST.INI") > 0 )
{
v1 = s;
result = 0LL;
if ( s[0] )
{
do
{
printf("[%s]\n", v1);
v1 += strlen(v1) + 1;
}
while ( *v1 );
result = 0LL;
}
return result;
}
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( cVerbose )
return result;
LABEL_12:
printf("odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError);
return 1LL;
}
if ( (int)SQLGetPrivateProfileString(a1, 0LL, 0LL, s, 4047LL, "ODBCINST.INI") <= 0 )
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( cVerbose )
return result;
goto LABEL_12;
}
printf("[%s]\n", a1);
if ( !s[0] )
return 0LL;
v3 = s;
do
{
printf("%s=", v3);
if ( (int)SQLGetPrivateProfileString(a1, v3, &unk_21E1, v4, 500LL, "ODBCINST.INI") > 0 )
printf("%s", v4);
putchar(10);
v3 += strlen(v3) + 1;
}
while ( *v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
char *v1; // rbx
__int64 result; // rax
char *v3; // rbx
char v4[512]; // [rsp+0h] [rbp-11E8h] BYREF
char s[4072]; // [rsp+200h] [rbp-FE8h] BYREF

if ( !a1 || !*a1 )
{
if ( (int)SQLGetPrivateProfileString(0LL, 0LL, 0LL, s, 4047LL, "ODBCINST.INI") > 0 )
{
v1 = s;
result = 0LL;
if ( s[0] )
{
do
{
printf("[%s]\n", v1);
v1 += strlen(v1) + 1;
}
while ( *v1 );
result = 0LL;
}
return result;
}
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( cVerbose )
return result;
LABEL_12:
printf("odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError);
return 1LL;
}
if ( (int)SQLGetPrivateProfileString(a1, 0LL, 0LL, s, 4047LL, "ODBCINST.INI") <= 0 )
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( cVerbose )
return result;
goto LABEL_12;
}
printf("[%s]\n", a1);
if ( !s[0] )
return 0LL;
v3 = s;
do
{
printf("%s=", v3);
if ( (int)SQLGetPrivateProfileString(a1, v3, &unk_21E1, v4, 500LL, "ODBCINST.INI") > 0 )
printf("%s", v4);
putchar(10);
v3 += strlen(v3) + 1;
}
while ( *v3 );
return 0LL;
}

original_code:
int DriverQuery( char *pszDriver )
{
    char szResults[4048];
    char szValue[501];
    char *ptr;
    if ( pszDriver && (*pszDriver) )
    {
        if ( SQLGetPrivateProfileString( pszDriver, ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBCINST.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            return 1;
        }
        printf( "[%s]\n", pszDriver );
        ptr = szResults;
        while ( *ptr )
        {
            printf( "%s=", ptr );
            if ( SQLGetPrivateProfileString( pszDriver, ptr, "", szValue, sizeof( szValue ) - 1, "ODBCINST.INI" ) > 0 )
            {
                printf( "%s", szValue );
            }
            printf( "\n" );
            ptr += strlen( ptr ) + 1;
        }
    }
    else
    {
        if ( SQLGetPrivateProfileString( ((void *)0), ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBCINST.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            return 1;
        }
        ptr = szResults;
        while ( *ptr )
        {
            printf( "[%s]\n", ptr );
            ptr += strlen( ptr ) + 1;
        }
    }
    return 0;
}

canonical_original_code:
int DriverQuery(char *pszDriver)
{
    char szResults[4048];
    char szValue[501];
    char *ptr;
    if ( pszDriver && (*pszDriver) )
    {
        if ( SQLGetPrivateProfileString( pszDriver, ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBCINST.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            return 1;
        }
        printf( "[%s]\n", pszDriver );
        ptr = szResults;
        while ( *ptr )
        {
            printf( "%s=", ptr );
            if ( SQLGetPrivateProfileString( pszDriver, ptr, "", szValue, sizeof( szValue ) - 1, "ODBCINST.INI" ) > 0 )
            {
                printf( "%s", szValue );
            }
            printf( "\n" );
            ptr += strlen( ptr ) + 1;
        }
    }
    else
    {
        if ( SQLGetPrivateProfileString( ((void *)0), ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBCINST.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            return 1;
        }
        ptr = szResults;
        while ( *ptr )
        {
            printf( "[%s]\n", ptr );
            ptr += strlen( ptr ) + 1;
        }
    }
    return 0;
}

variable_types:
szResults
char [4048]

variable_types:
szValue
char [501]

variable_types:
ptr
char *


DSNUninstall

decompiled_code:
__int64 __fastcall DSNUninstall(__int64 a1)
{
const char *v1; // rsi
__int64 result; // rax
__int16 v3[5]; // [rsp+Eh] [rbp-Ah] BYREF

if ( system_dsn )
{
SQLSetConfigMode(2LL);
}
else if ( user_dsn )
{
SQLSetConfigMode(1LL);
}
if ( (unsigned int)SQLGetConfigMode(v3) )
{
if ( (unsigned int)SQLRemoveDSNFromIni(a1) )
{
v1 = "ODBC_USER_DSN";
if ( v3[0] != 1 )
{
v1 = "ODBC_SYSTEM_DSN";
if ( v3[0] != 2 )
{
v1 = "Unknown mode";
if ( !v3[0] )
v1 = "ODBC_BOTH_DSN";
}
}
result = 0LL;
if ( !cVerbose )
{
printf("odbcinst: DSN removed (if it existed at all). %s was used as the search path.\n", v1);
result = 0LL;
}
}
else
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( !cVerbose )
{
printf("odbcinst: SQLRemoveDSNFromIni failed with %s.\n", szError);
result = 1LL;
}
}
}
else
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( !cVerbose )
{
printf("odbcinst: SQLGetConfigMode failed with %s.\n", szError);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
const char *v1; // rsi
__int64 result; // rax
__int16 v3[5]; // [rsp+Eh] [rbp-Ah] BYREF

if ( system_dsn )
{
SQLSetConfigMode(2LL);
}
else if ( user_dsn )
{
SQLSetConfigMode(1LL);
}
if ( (unsigned int)SQLGetConfigMode(v3) )
{
if ( (unsigned int)SQLRemoveDSNFromIni(a1) )
{
v1 = "ODBC_USER_DSN";
if ( v3[0] != 1 )
{
v1 = "ODBC_SYSTEM_DSN";
if ( v3[0] != 2 )
{
v1 = "Unknown mode";
if ( !v3[0] )
v1 = "ODBC_BOTH_DSN";
}
}
result = 0LL;
if ( !cVerbose )
{
printf("odbcinst: DSN removed (if it existed at all). %s was used as the search path.\n", v1);
result = 0LL;
}
}
else
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( !cVerbose )
{
printf("odbcinst: SQLRemoveDSNFromIni failed with %s.\n", szError);
result = 1LL;
}
}
}
else
{
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
result = 1LL;
if ( !cVerbose )
{
printf("odbcinst: SQLGetConfigMode failed with %s.\n", szError);
result = 1LL;
}
}
return result;
}

original_code:
int DSNUninstall( char *pszDSN )
{
    UWORD nConfigMode;
    char *pMode;
    if ( system_dsn )
    {
        SQLSetConfigMode( 2 );
    }
    else if ( user_dsn )
    {
        SQLSetConfigMode( 1 );
    }
    if ( SQLGetConfigMode( &nConfigMode ) == 0 )
    {
        SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
        if ( cVerbose == 0 ) printf( "odbcinst: SQLGetConfigMode failed with %s.\n", szError );
        return 1;
    }
    if ( SQLRemoveDSNFromIni( pszDSN ) == 0 )
    {
        SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
        if ( cVerbose == 0 ) printf( "odbcinst: SQLRemoveDSNFromIni failed with %s.\n", szError );
        return 1;
    }
    switch ( nConfigMode )
    {
        case 2:
            pMode = "ODBC_SYSTEM_DSN";
            break;
        case 1:
            pMode = "ODBC_USER_DSN";
            break;
        case 0:
            pMode = "ODBC_BOTH_DSN";
            break;
        default:
            pMode = "Unknown mode";
    }
    if ( cVerbose == 0 ) printf( "odbcinst: DSN removed (if it existed at all). %s was used as the search path.\n", pMode );
    return 0;
}

canonical_original_code:
int DSNUninstall(char *pszDSN)
{
    unsigned short nConfigMode;
    char *pMode;
    if ( system_dsn )
    {
        SQLSetConfigMode( 2 );
    }
    else if ( user_dsn )
    {
        SQLSetConfigMode( 1 );
    }
    if ( SQLGetConfigMode( &nConfigMode ) == 0 )
    {
        SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
        if ( cVerbose == 0 ) printf( "odbcinst: SQLGetConfigMode failed with %s.\n", szError );
        return 1;
    }
    if ( SQLRemoveDSNFromIni( pszDSN ) == 0 )
    {
        SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
        if ( cVerbose == 0 ) printf( "odbcinst: SQLRemoveDSNFromIni failed with %s.\n", szError );
        return 1;
    }
    switch ( nConfigMode )
    {
        case 2:
            pMode = "ODBC_SYSTEM_DSN";
            break;
        case 1:
            pMode = "ODBC_USER_DSN";
            break;
        case 0:
            pMode = "ODBC_BOTH_DSN";
            break;
        default:
            pMode = "Unknown mode";
    }
    if ( cVerbose == 0 ) printf( "odbcinst: DSN removed (if it existed at all). %s was used as the search path.\n", pMode );
    return 0;
}

variable_types:
nConfigMode
unsigned short

variable_types:
pMode
char *


DSNQuery

decompiled_code:
__int64 __fastcall DSNQuery(const char *a1)
{
char *i; // rbx
char *v3; // rbx
char v4[512]; // [rsp+0h] [rbp-27A8h] BYREF
char s[9640]; // [rsp+200h] [rbp-25A8h] BYREF

s[0] = 0;
if ( system_dsn )
{
SQLSetConfigMode(2LL);
}
else if ( user_dsn )
{
SQLSetConfigMode(1LL);
}
if ( a1 && *a1 )
{
if ( (int)SQLGetPrivateProfileString(a1, 0LL, 0LL, s, ": SQLGetConfigMode failed with %s.\n", "ODBC.INI") > 0 )
{
printf("[%s]\n", a1);
if ( s[0] )
{
v3 = s;
do
{
printf("%s=", v3);
if ( (int)SQLGetPrivateProfileString(a1, v3, &unk_21E1, v4, (_BYTE *)&loc_1F2 + 2, "ODBC.INI") > 0 )
printf("%s", v4);
putchar(10);
v3 += strlen(v3) + 1;
}
while ( *v3 );
}
goto LABEL_9;
}
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
if ( !cVerbose )
printf("odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError);
}
else
{
if ( (int)SQLGetPrivateProfileString(0LL, 0LL, 0LL, s, ": SQLGetConfigMode failed with %s.\n", "ODBC.INI") > 0 )
{
for ( i = s; *i; i += strlen(i) + 1 )
printf("[%s]\n", i);
LABEL_9:
SQLSetConfigMode(0LL);
return 0LL;
}
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
if ( !cVerbose )
printf("odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError);
}
SQLSetConfigMode(0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
char *i; // rbx
char *v3; // rbx
char v4[512]; // [rsp+0h] [rbp-27A8h] BYREF
char s[9640]; // [rsp+200h] [rbp-25A8h] BYREF

s[0] = 0;
if ( system_dsn )
{
SQLSetConfigMode(2LL);
}
else if ( user_dsn )
{
SQLSetConfigMode(1LL);
}
if ( a1 && *a1 )
{
if ( (int)SQLGetPrivateProfileString(a1, 0LL, 0LL, s, ": SQLGetConfigMode failed with %s.\n", "ODBC.INI") > 0 )
{
printf("[%s]\n", a1);
if ( s[0] )
{
v3 = s;
do
{
printf("%s=", v3);
if ( (int)SQLGetPrivateProfileString(a1, v3, &unk_21E1, v4, (_BYTE *)&loc_1F2 + 2, "ODBC.INI") > 0 )
printf("%s", v4);
putchar(10);
v3 += strlen(v3) + 1;
}
while ( *v3 );
}
goto LABEL_9;
}
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
if ( !cVerbose )
printf("odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError);
}
else
{
if ( (int)SQLGetPrivateProfileString(0LL, 0LL, 0LL, s, ": SQLGetConfigMode failed with %s.\n", "ODBC.INI") > 0 )
{
for ( i = s; *i; i += strlen(i) + 1 )
printf("[%s]\n", i);
LABEL_9:
SQLSetConfigMode(0LL);
return 0LL;
}
SQLInstallerError(1LL, &nError, szError, 4096LL, 0LL);
if ( !cVerbose )
printf("odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError);
}
SQLSetConfigMode(0LL);
return 1LL;
}

original_code:
int DSNQuery( char *pszDSN )
{
    char szResults[9601];
    char szValue[501];
    char *ptr;
    szResults[0] = '\0';
    if ( system_dsn )
        SQLSetConfigMode( 2 );
    else if ( user_dsn )
        SQLSetConfigMode( 1 );
    if ( pszDSN && (*pszDSN) )
    {
        if ( SQLGetPrivateProfileString( pszDSN, ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBC.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            SQLSetConfigMode( 0 );
            return 1;
        }
        printf( "[%s]\n", pszDSN );
        ptr = szResults;
        while ( *ptr )
        {
            printf( "%s=", ptr );
            if ( SQLGetPrivateProfileString( pszDSN, ptr, "", szValue, sizeof( szValue ) - 1, "ODBC.INI" ) > 0 )
            {
                printf( "%s", szValue );
            }
            printf( "\n" );
            ptr += strlen( ptr ) + 1;
        }
    }
    else
    {
        if ( SQLGetPrivateProfileString( ((void *)0), ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBC.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            SQLSetConfigMode( 0 );
            return 1;
        }
        ptr = szResults;
        while ( *ptr )
        {
            printf( "[%s]\n", ptr );
            ptr += strlen( ptr ) + 1;
        }
    }
    SQLSetConfigMode( 0 );
    return 0;
}

canonical_original_code:
int DSNQuery(char *pszDSN)
{
    char szResults[9601];
    char szValue[501];
    char *ptr;
    szResults[0] = '\0';
    if ( system_dsn )
        SQLSetConfigMode( 2 );
    else if ( user_dsn )
        SQLSetConfigMode( 1 );
    if ( pszDSN && (*pszDSN) )
    {
        if ( SQLGetPrivateProfileString( pszDSN, ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBC.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            SQLSetConfigMode( 0 );
            return 1;
        }
        printf( "[%s]\n", pszDSN );
        ptr = szResults;
        while ( *ptr )
        {
            printf( "%s=", ptr );
            if ( SQLGetPrivateProfileString( pszDSN, ptr, "", szValue, sizeof( szValue ) - 1, "ODBC.INI" ) > 0 )
            {
                printf( "%s", szValue );
            }
            printf( "\n" );
            ptr += strlen( ptr ) + 1;
        }
    }
    else
    {
        if ( SQLGetPrivateProfileString( ((void *)0), ((void *)0), ((void *)0), szResults, sizeof( szResults ) - 1, "ODBC.INI" ) < 1 )
        {
            SQLInstallerError( 1, &nError, szError, 4096, ((void *)0) );
            if ( cVerbose == 0 ) printf( "odbcinst: SQLGetPrivateProfileString failed with %s.\n", szError );
            SQLSetConfigMode( 0 );
            return 1;
        }
        ptr = szResults;
        while ( *ptr )
        {
            printf( "[%s]\n", ptr );
            ptr += strlen( ptr ) + 1;
        }
    }
    SQLSetConfigMode( 0 );
    return 0;
}

variable_types:
szResults
char [9601]


Syntax

decompiled_code:
int Syntax()
{
int result; // eax

if ( !cVerbose )
result = puts(szSyntax);
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax

if ( !cVerbose )
result = puts(szSyntax);
return result;
}

original_code:
void Syntax()
{
    if ( cVerbose != 0 )
        return;
    puts( szSyntax );
}

return_type: void


PrintConfigInfo

decompiled_code:
int PrintConfigInfo()
{
const char *v0; // rbx
const char *v1; // rax
__int64 v3; // [rsp+0h] [rbp-1218h] BYREF
char v4[256]; // [rsp+100h] [rbp-1118h] BYREF
char s[4120]; // [rsp+200h] [rbp-1018h] BYREF

puts("unixODBC 2.3.0");
s[0] = 0;
v0 = (const char *)odbcinst_system_file_name(&v3);
v1 = (const char *)odbcinst_system_file_path(v4);
sprintf(s, "%s/%s", v1, v0);
printf("DRIVERS............: %s\n", s);
s[0] = 0;
odbcinst_SystemINI(s, 0LL);
printf("SYSTEM DATA SOURCES: %s\n", s);
s[0] = 0;
odbcinst_FileINI(s);
printf("FILE DATA SOURCES..: %s\n", s);
s[0] = 0;
odbcinst_UserINI(s, 0LL);
printf("USER DATA SOURCES..: %s\n", s);
printf("SQLULEN Size.......: %ld\n", 8LL);
printf("SQLLEN Size........: %ld\n", 8LL);
return printf("SQLSETPOSIROW Size.: %ld\n", 2LL);
}

canonical_decompiled_code:
int func9()
{
const char *v0; // rbx
const char *v1; // rax
__int64 v3; // [rsp+0h] [rbp-1218h] BYREF
char v4[256]; // [rsp+100h] [rbp-1118h] BYREF
char s[4120]; // [rsp+200h] [rbp-1018h] BYREF

puts("unixODBC 2.3.0");
s[0] = 0;
v0 = (const char *)odbcinst_system_file_name(&v3);
v1 = (const char *)odbcinst_system_file_path(v4);
sprintf(s, "%s/%s", v1, v0);
printf("DRIVERS............: %s\n", s);
s[0] = 0;
odbcinst_SystemINI(s, 0LL);
printf("SYSTEM DATA SOURCES: %s\n", s);
s[0] = 0;
odbcinst_FileINI(s);
printf("FILE DATA SOURCES..: %s\n", s);
s[0] = 0;
odbcinst_UserINI(s, 0LL);
printf("USER DATA SOURCES..: %s\n", s);
printf("SQLULEN Size.......: %ld\n", 8LL);
printf("SQLLEN Size........: %ld\n", 8LL);
return printf("SQLSETPOSIROW Size.: %ld\n", 2LL);
}

original_code:
void PrintConfigInfo()
{
    char szFileName[4096 +1];
 char b1[ 256 ], b2[ 256 ];
    printf( "unixODBC " "2.3.0" "\n" );
    *szFileName = '\0';
    sprintf( szFileName, "%s/%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ));
    printf( "DRIVERS............: %s\n", szFileName );
    *szFileName = '\0';
    _odbcinst_SystemINI( szFileName, 0 );
    printf( "SYSTEM DATA SOURCES: %s\n", szFileName );
    *szFileName = '\0';
    _odbcinst_FileINI( szFileName );
    printf( "FILE DATA SOURCES..: %s\n", szFileName );
    *szFileName = '\0';
    _odbcinst_UserINI( szFileName, 0 );
    printf( "USER DATA SOURCES..: %s\n", szFileName );
 printf( "SQLULEN Size.......: %ld\n", (long) sizeof( SQLUINTEGER ));
 printf( "SQLLEN Size........: %ld\n", (long) sizeof( SQLINTEGER ));
 printf( "SQLSETPOSIROW Size.: %ld\n", (long) sizeof( SQLUSMALLINT ));
}

canonical_original_code:
void PrintConfigInfo()
{
    char szFileName[-1];
 char b1[256]; char b2[256];
    printf( "unixODBC " "2.3.0" "\n" );
    *szFileName = '\0';
    sprintf( szFileName, "%s/%s", odbcinst_system_file_path( b1 ), odbcinst_system_file_name( b2 ));
    printf( "DRIVERS............: %s\n", szFileName );
    *szFileName = '\0';
    _odbcinst_SystemINI( szFileName, 0 );
    printf( "SYSTEM DATA SOURCES: %s\n", szFileName );
    *szFileName = '\0';
    _odbcinst_FileINI( szFileName );
    printf( "FILE DATA SOURCES..: %s\n", szFileName );
    *szFileName = '\0';
    _odbcinst_UserINI( szFileName, 0 );
    printf( "USER DATA SOURCES..: %s\n", szFileName );
 printf( "SQLULEN Size.......: %ld\n", (long) sizeof( SQLUINTEGER ));
 printf( "SQLLEN Size........: %ld\n", (long) sizeof( SQLINTEGER ));
 printf( "SQLSETPOSIROW Size.: %ld\n", (long) sizeof( SQLUSMALLINT ));
}

variable_types:
szFileName
char [-1]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char v4; // r14
char v5; // r15
int v6; // er13
const char *v7; // rax
char v8; // dl
int v9; // edi
int result; // eax
char v11[1008]; // [rsp+0h] [rbp-1438h] BYREF
char dest[4168]; // [rsp+3F0h] [rbp-1048h] BYREF

cVerbose = 0;
if ( argc > 1 )
{
dest[0] = 0;
v11[0] = 0;
v3 = 1LL;
v4 = 0;
v5 = 0;
v6 = argc - 1;
while ( 1 )
{
v7 = argv[v3];
if ( *v7 == 45 )
{
v8 = v7[1];
switch ( v8 )
{
case '-':
puts("unixODBC 2.3.0");
exit(0);
case 'c':
case 'd':
case 'm':
case 's':
v4 = v7[1];
break;
case 'f':
if ( v6 > (int)v3 )
strncpy(dest, argv[v3 + 1], 0x1000uLL);
break;
case 'h':
user_dsn = 1;
if ( system_dsn )
{
if ( !cVerbose )
printf("odbcinst: cannot install both user and system dsn at the same time");
exit(-2);
}
return result;
case 'i':
case 'q':
case 'u':
v5 = v7[1];
break;
case 'j':
PrintConfigInfo();
exit(0);
case 'l':
system_dsn = 1;
if ( user_dsn )
{
if ( !cVerbose )
printf("odbcinst: cannot install both user and system dsn at the same time");
exit(-2);
}
return result;
case 'n':
if ( v6 > (int)v3 )
strncpy(v11, argv[v3 + 1], 0x3E8uLL);
break;
case 'r':
from_stdin = 1;
break;
case 'v':
cVerbose = 118;
break;
default:
if ( !cVerbose )
printf("odbcinst: Unknown option %c\n", (unsigned int)v8);
exit(-1);
}
}
if ( ++v3 == argc )
{
switch ( v4 )
{
case 'd':
switch ( v5 )
{
case 'i':
if ( dest[0] )
{
v9 = DriverInstall(dest);
}
else
{
if ( !from_stdin )
{
if ( !cVerbose )
puts(
"odbcinst: Please supply -f template.ini (The fileformat of template.ini is identical to odbcinst"
".ini and odbc.ini, respectively)");
Syntax();
exit(1);
}
v9 = DriverInstall((const char *)0xFFFFFFFFFFFFFFFFLL);
}
break;
case 'u':
if ( !v11[0] )
{
if ( !cVerbose )
puts("odbcinst: Please supply -n FriendlyDriverName ");
Syntax();
exit(1);
}
v9 = DriverUninstall(v11);
break;
case 'q':
v9 = DriverQuery(v11);
break;
default:
if ( !cVerbose )
puts("odbcinst: Invalid Action for Object");
Syntax();
exit(1);
}
break;
case 's':
switch ( v5 )
{
case 'i':
if ( dest[0] )
{
v9 = DSNInstall(dest);
}
else
{
if ( !from_stdin )
{
if ( !cVerbose )
puts("odbcinst: Please supply -f template.ini ");
Syntax();
exit(1);
}
v9 = DSNInstall((const char *)0xFFFFFFFFFFFFFFFFLL);
}
break;
case 'u':
if ( !v11[0] )
{
if ( !cVerbose )
puts("odbcinst: Please supply -n DataSourceName ");
Syntax();
exit(1);
}
v9 = DSNUninstall((__int64)v11);
break;
case 'q':
v9 = DSNQuery(v11);
break;
default:
if ( !cVerbose )
puts("odbcinst: Invalid Action for Object");
Syntax();
exit(1);
}
break;
case 'c':
v9 = CreateDataSource(v11);
break;
case 'm':
v9 = ManageDataSources();
break;
default:
if ( !cVerbose )
puts("odbcinst: Invalid Object");
Syntax();
exit(1);
}
exit(v9);
}
}
}
Syntax();
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char v4; // r14
char v5; // r15
int v6; // er13
const char *v7; // rax
char v8; // dl
int v9; // edi
int result; // eax
char v11[1008]; // [rsp+0h] [rbp-1438h] BYREF
char dest[4168]; // [rsp+3F0h] [rbp-1048h] BYREF

cVerbose = 0;
if ( argc > 1 )
{
dest[0] = 0;
v11[0] = 0;
v3 = 1LL;
v4 = 0;
v5 = 0;
v6 = argc - 1;
while ( 1 )
{
v7 = argv[v3];
if ( *v7 == 45 )
{
v8 = v7[1];
switch ( v8 )
{
case '-':
puts("unixODBC 2.3.0");
exit(0);
case 'c':
case 'd':
case 'm':
case 's':
v4 = v7[1];
break;
case 'f':
if ( v6 > (int)v3 )
strncpy(dest, argv[v3 + 1], 0x1000uLL);
break;
case 'h':
user_dsn = 1;
if ( system_dsn )
{
if ( !cVerbose )
printf("odbcinst: cannot install both user and system dsn at the same time");
exit(-2);
}
return result;
case 'i':
case 'q':
case 'u':
v5 = v7[1];
break;
case 'j':
func9();
exit(0);
case 'l':
system_dsn = 1;
if ( user_dsn )
{
if ( !cVerbose )
printf("odbcinst: cannot install both user and system dsn at the same time");
exit(-2);
}
return result;
case 'n':
if ( v6 > (int)v3 )
strncpy(v11, argv[v3 + 1], 0x3E8uLL);
break;
case 'r':
from_stdin = 1;
break;
case 'v':
cVerbose = 118;
break;
default:
if ( !cVerbose )
printf("odbcinst: Unknown option %c\n", (unsigned int)v8);
exit(-1);
}
}
if ( ++v3 == argc )
{
switch ( v4 )
{
case 'd':
switch ( v5 )
{
case 'i':
if ( dest[0] )
{
v9 = func2(dest);
}
else
{
if ( !from_stdin )
{
if ( !cVerbose )
puts(
"odbcinst: Please supply -f template.ini (The fileformat of template.ini is identical to odbcinst"
".ini and odbc.ini, respectively)");
func8();
exit(1);
}
v9 = func2((const char *)0xFFFFFFFFFFFFFFFFLL);
}
break;
case 'u':
if ( !v11[0] )
{
if ( !cVerbose )
puts("odbcinst: Please supply -n FriendlyDriverName ");
func8();
exit(1);
}
v9 = func3(v11);
break;
case 'q':
v9 = func4(v11);
break;
default:
if ( !cVerbose )
puts("odbcinst: Invalid Action for Object");
func8();
exit(1);
}
break;
case 's':
switch ( v5 )
{
case 'i':
if ( dest[0] )
{
v9 = func5(dest);
}
else
{
if ( !from_stdin )
{
if ( !cVerbose )
puts("odbcinst: Please supply -f template.ini ");
func8();
exit(1);
}
v9 = func5((const char *)0xFFFFFFFFFFFFFFFFLL);
}
break;
case 'u':
if ( !v11[0] )
{
if ( !cVerbose )
puts("odbcinst: Please supply -n DataSourceName ");
func8();
exit(1);
}
v9 = func6((__int64)v11);
break;
case 'q':
v9 = func7(v11);
break;
default:
if ( !cVerbose )
puts("odbcinst: Invalid Action for Object");
func8();
exit(1);
}
break;
case 'c':
v9 = func0(v11);
break;
case 'm':
v9 = func1();
break;
default:
if ( !cVerbose )
puts("odbcinst: Invalid Object");
func8();
exit(1);
}
exit(v9);
}
}
}
func8();
exit(1);
}

original_code:
int main( int argc, char *argv[] )
{
    int nArg;
    char cAction = 0;
    char cObject = 0;
    char szTemplateINI[4096 +1];
    char szObjectName[1000 +1];
    int nReturn = 0;
    cVerbose = 0;
    if ( argc < 2 )
    {
        Syntax();
        exit ( 1 );
    }
    szTemplateINI[0] = '\0';
    szObjectName[0] = '\0';
    for ( nArg = 1; nArg < argc; nArg++ )
    {
        if ( argv[nArg][0] == '-' )
        {
            switch ( argv[nArg][1] )
            {
                case 'i':
                case 'u':
                case 'q':
                    cAction = argv[nArg][1];
                    break;
                case 'j':
                    PrintConfigInfo();
                    exit(0);
                case '-':
                    printf( "unixODBC " "2.3.0" "\n" );
                    exit(0);
                case 'c':
                case 'd':
                case 's':
                case 'm':
                    cObject = argv[nArg][1];
                    break;
                case 'n':
                    if ( nArg < argc-1 )
                        strncpy( szObjectName, argv[nArg+1], 1000 );
                    break;
                case 'f':
                    if ( nArg < argc-1 )
                        strncpy( szTemplateINI, argv[nArg+1], 4096 );
                    break;
                case 'r':
                    from_stdin = 1;
                    break;
                case 'v':
                    cVerbose = argv[nArg][1];
                    break;
                case 'l':
                    system_dsn = 1;
                    if ( user_dsn )
                    {
                        if ( cVerbose == 0 ) printf( "odbcinst: cannot install both user and system dsn at the same time");
                        exit( -2 );
                    }
                    break;
                case 'h':
                    user_dsn = 1;
                    if ( system_dsn )
                    {
                        if ( cVerbose == 0 ) printf( "odbcinst: cannot install both user and system dsn at the same time");
                        exit( -2 );
                    }
                    break;
                default:
                    if ( cVerbose == 0 ) printf( "odbcinst: Unknown option %c\n", argv[nArg][1] );
                    exit( -1 );
            }
        }
    }
    if ( cObject == 'd' )
    {
        if ( cAction == 'i' )
        {
            if ( szTemplateINI[0] != '\0' )
                nReturn = DriverInstall( szTemplateINI );
            else if ( from_stdin )
                nReturn = DriverInstall( ((char*)-1) );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -f template.ini (The fileformat of template.ini is identical to odbcinst.ini and odbc.ini, respectively)\n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'u' )
        {
            if ( szObjectName[0] != '\0' )
                nReturn = DriverUninstall( szObjectName );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -n FriendlyDriverName \n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'q' )
            nReturn = DriverQuery( szObjectName );
        else
        {
            if ( cVerbose == 0 ) printf( "odbcinst: Invalid Action for Object\n" );
            Syntax();
            exit( 1 );
        }
    }
    else if ( cObject == 's' )
    {
        if ( cAction == 'i' )
        {
            if ( szTemplateINI[0] != '\0' )
                nReturn = DSNInstall( szTemplateINI );
            else if ( from_stdin )
                nReturn = DSNInstall( ((char*)-1) );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -f template.ini \n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'u' )
        {
            if ( szObjectName[0] != '\0' )
                nReturn = DSNUninstall( szObjectName );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -n DataSourceName \n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'q' )
            nReturn = DSNQuery( szObjectName );
        else
        {
            if ( cVerbose == 0 ) printf( "odbcinst: Invalid Action for Object\n" );
            Syntax();
            exit( 1 );
        }
    }
    else if ( cObject == 'c' )
    {
        nReturn = CreateDataSource( szObjectName );
    }
    else if ( cObject == 'm' )
    {
        nReturn = ManageDataSources();
    }
    else
    {
        if ( cVerbose == 0 ) printf( "odbcinst: Invalid Object\n" );
        Syntax();
        exit( 1 );
    }
    exit( nReturn );
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int nArg;
    char cAction = 0;
    char cObject = 0;
    char szTemplateINI[-1];
    char szObjectName[-1];
    int nReturn = 0;
    cVerbose = 0;
    if ( argc < 2 )
    {
        Syntax();
        exit ( 1 );
    }
    szTemplateINI[0] = '\0';
    szObjectName[0] = '\0';
    for ( nArg = 1; nArg < argc; nArg++ )
    {
        if ( argv[nArg][0] == '-' )
        {
            switch ( argv[nArg][1] )
            {
                case 'i':
                case 'u':
                case 'q':
                    cAction = argv[nArg][1];
                    break;
                case 'j':
                    PrintConfigInfo();
                    exit(0);
                case '-':
                    printf( "unixODBC " "2.3.0" "\n" );
                    exit(0);
                case 'c':
                case 'd':
                case 's':
                case 'm':
                    cObject = argv[nArg][1];
                    break;
                case 'n':
                    if ( nArg < argc-1 )
                        strncpy( szObjectName, argv[nArg+1], 1000 );
                    break;
                case 'f':
                    if ( nArg < argc-1 )
                        strncpy( szTemplateINI, argv[nArg+1], 4096 );
                    break;
                case 'r':
                    from_stdin = 1;
                    break;
                case 'v':
                    cVerbose = argv[nArg][1];
                    break;
                case 'l':
                    system_dsn = 1;
                    if ( user_dsn )
                    {
                        if ( cVerbose == 0 ) printf( "odbcinst: cannot install both user and system dsn at the same time");
                        exit( -2 );
                    }
                    break;
                case 'h':
                    user_dsn = 1;
                    if ( system_dsn )
                    {
                        if ( cVerbose == 0 ) printf( "odbcinst: cannot install both user and system dsn at the same time");
                        exit( -2 );
                    }
                    break;
                default:
                    if ( cVerbose == 0 ) printf( "odbcinst: Unknown option %c\n", argv[nArg][1] );
                    exit( -1 );
            }
        }
    }
    if ( cObject == 'd' )
    {
        if ( cAction == 'i' )
        {
            if ( szTemplateINI[0] != '\0' )
                nReturn = DriverInstall( szTemplateINI );
            else if ( from_stdin )
                nReturn = DriverInstall( ((char *)-1) );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -f template.ini (The fileformat of template.ini is identical to odbcinst.ini and odbc.ini, respectively)\n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'u' )
        {
            if ( szObjectName[0] != '\0' )
                nReturn = DriverUninstall( szObjectName );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -n FriendlyDriverName \n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'q' )
            nReturn = DriverQuery( szObjectName );
        else
        {
            if ( cVerbose == 0 ) printf( "odbcinst: Invalid Action for Object\n" );
            Syntax();
            exit( 1 );
        }
    }
    else if ( cObject == 's' )
    {
        if ( cAction == 'i' )
        {
            if ( szTemplateINI[0] != '\0' )
                nReturn = DSNInstall( szTemplateINI );
            else if ( from_stdin )
                nReturn = DSNInstall( ((char *)-1) );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -f template.ini \n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'u' )
        {
            if ( szObjectName[0] != '\0' )
                nReturn = DSNUninstall( szObjectName );
            else
            {
                if ( cVerbose == 0 ) printf( "odbcinst: Please supply -n DataSourceName \n" );
                Syntax();
                exit( 1 );
            }
        }
        else if ( cAction == 'q' )
            nReturn = DSNQuery( szObjectName );
        else
        {
            if ( cVerbose == 0 ) printf( "odbcinst: Invalid Action for Object\n" );
            Syntax();
            exit( 1 );
        }
    }
    else if ( cObject == 'c' )
    {
        nReturn = CreateDataSource( szObjectName );
    }
    else if ( cObject == 'm' )
    {
        nReturn = ManageDataSources();
    }
    else
    {
        if ( cVerbose == 0 ) printf( "odbcinst: Invalid Object\n" );
        Syntax();
        exit( 1 );
    }
    exit( nReturn );
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nArg int

variable_types: cAction char

variable_types: cObject char

variable_types:
szTemplateINI
char [-1]

variable_types:
szObjectName
char [-1]

variable_types: nReturn int


decompiled_code:
__int64 __fastcall inst_logPushMsg(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, __int64 a6)
{
unsigned int v10; // ebx

mutex_entry();
v10 = log_tried;
if ( !log_tried )
{
log_tried = 1;
if ( (unsigned int)logOpen(&hODBCINSTLog, "odbcinst", 0LL, 10LL) != 1 )
{
hODBCINSTLog = 0LL;
goto LABEL_4;
}
logOn(hODBCINSTLog, 1LL);
}
v10 = 0;
if ( hODBCINSTLog )
v10 = logPushMsg(hODBCINSTLog, a1, a2, a3, a4, a5, a6);
LABEL_4:
mutex_exit();
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, __int64 a6)
{
unsigned int v10; // ebx

func0();
v10 = log_tried;
if ( !log_tried )
{
log_tried = 1;
if ( (unsigned int)logOpen(&hODBCINSTLog, "odbcinst", 0LL, 10LL) != 1 )
{
hODBCINSTLog = 0LL;
goto LABEL_4;
}
logOn(hODBCINSTLog, 1LL);
}
v10 = 0;
if ( hODBCINSTLog )
v10 = logPushMsg(hODBCINSTLog, a1, a2, a3, a4, a5, a6);
LABEL_4:
func1();
return v10;
}

original_code:
int inst_logPushMsg( char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessage )
{
    int ret = 0;
    mutex_entry();
    if ( !log_tried )
    {
        long nMaxMessages = 10;
        log_tried = 1;
        if ( logOpen( &hODBCINSTLog, "odbcinst", ((void *)0), nMaxMessages ) != 1 )
        {
            hODBCINSTLog = ((void *)0);
        }
        else
        {
            logOn( hODBCINSTLog, 1 );
        }
    }
    if ( hODBCINSTLog )
    {
        ret = logPushMsg( hODBCINSTLog,
                pszModule,
                pszFunctionName,
                nLine,
                nSeverity,
                nCode,
                pszMessage );
    }
    mutex_exit();
    return ret;
}

canonical_original_code:
int inst_logPushMsg(char *pszModule, char *pszFunctionName, int nLine, int nSeverity, int nCode, char *pszMessage)
{
    int ret = 0;
    mutex_entry();
    if ( !log_tried )
    {
        long nMaxMessages = 10;
        log_tried = 1;
        if ( logOpen( &hODBCINSTLog, "odbcinst", ((void *)0), nMaxMessages ) != 1 )
        {
            hODBCINSTLog = ((void *)0);
        }
        else
        {
            logOn( hODBCINSTLog, 1 );
        }
    }
    if ( hODBCINSTLog )
    {
        ret = logPushMsg( hODBCINSTLog,
                pszModule,
                pszFunctionName,
                nLine,
                nSeverity,
                nCode,
                pszMessage );
    }
    mutex_exit();
    return ret;
}

variable_types:
pszModule
char *

variable_types:
pszFunctionName
char *

variable_types: nLine int

variable_types: nSeverity int

variable_types: nCode int

variable_types:
pszMessage
char *

variable_types: ret int

variable_types: nMaxMessages long


decompiled_code:
__int64 inst_logClear()
{
unsigned int v0; // ebx

mutex_entry();
v0 = 0;
if ( hODBCINSTLog )
v0 = logClear();
mutex_exit();
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx

func0();
v0 = 0;
if ( hODBCINSTLog )
v0 = logClear();
func1();
return v0;
}

original_code:
int inst_logClear( void )
{
    int ret = 0;
    mutex_entry();
    if ( hODBCINSTLog )
        ret = logClear( hODBCINSTLog );
    mutex_exit();
    return ret;
}

canonical_original_code:
int inst_logClear()
{
    int ret = 0;
    mutex_entry();
    if ( hODBCINSTLog )
        ret = logClear( hODBCINSTLog );
    mutex_exit();
    return ret;
}


popc

original_code:
static char popc(yyenv_t* penv)
{
 char c;
 c = (penv->pstmt->sqlexpr)[(penv->scanpos)];
 (penv->errpos) = (penv->scanpos);
 (penv->scanpos) ++;
 return c;
}

canonical_original_code:
static char popc(struct yyenv_t *penv)
{
 char c;
 c = (penv->pstmt->sqlexpr)[(penv->scanpos)];
 (penv->errpos) = (penv->scanpos);
 (penv->scanpos) ++;
 return c;
}

variable_types: struct yyenv_t { int extlevel; int errpos; int scanpos; char *texts_bufptr; int dummy_npar; struct yystmt_t { void *hcndes; int type; int errcode; int errpos; struct yycol_t { int iattr; char *table; union { long num; char *qstr; struct date_t { int year; int month; int day; } date; } value; } *pcol; struct yyattr_t { int stat; int wstat; int article; union { char *location; long number; struct date_t date; } value; void *nntp_hand; } *pattr; struct yypar_t { int type; union { char *location; long number; struct date_t date; } value; } *ppar; char *table; int ncol; int npar; int count; char *sqlexpr; char *texts_buf; char msgbuf[64]; struct tnode { int type; union { int cmpop; int logop; int iattr; int ipar; char *qstr; long num; struct date_t date; char esc; } value; struct tnode *left; struct tnode *right; } *srchtree; struct tnode *node_buf; int srchtreesize; int srchtreenum; char **ins_heads; struct tnode *ins_values; long artnum_min; long artnum_max; } *pstmt; } *

variable_types: c char

return_type: char

user_defined_types: struct yyenv_t { int extlevel; int errpos; int scanpos; char *texts_bufptr; int dummy_npar; struct yystmt_t *pstmt; }

user_defined_types: struct yystmt_t { void *hcndes; int type; int errcode; int errpos; struct yycol_t *pcol; struct yyattr_t *pattr; struct yypar_t *ppar; char *table; int ncol; int npar; int count; char *sqlexpr; char *texts_buf; char msgbuf[64]; struct tnode *srchtree; struct tnode *node_buf; int srchtreesize; int srchtreenum; char **ins_heads; struct tnode *ins_values; long artnum_min; long artnum_max; }

user_defined_types: struct yycol_t { int iattr; char *table; union { long num; char *qstr; struct date_t date; } value; }


getxkeywdidxbyname

decompiled_code:
__int64 __fastcall getxkeywdidxbyname(__int64 a1)
{
int v1; // edx
__int64 result; // rax
int v3; // eax

if ( (unsigned int)upper_strneq(a1, &LC0, 6LL) )
{
v3 = 0;
}
else
{
v1 = upper_strneq(a1, &LC1, 6LL);
result = 256LL;
if ( !v1 )
return result;
v3 = 1;
}
return *((unsigned int *)&xkeywd_tab + 4 * v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // edx
__int64 result; // rax
int v3; // eax

if ( (unsigned int)upper_strneq(a1, &LC0, 6LL) )
{
v3 = 0;
}
else
{
v1 = upper_strneq(a1, &LC1, 6LL);
result = 256LL;
if ( !v1 )
return result;
v3 = 1;
}
return *((unsigned int *)&xkeywd_tab + 4 * v3);
}

original_code:
static int getxkeywdidxbyname(char* name)
{
 int i, size;
 size = sizeof(xkeywd_tab)/sizeof(xkeywd_tab[0]);
 for(i=0; i<size; i++)
 {
  if(upper_strneq(name, xkeywd_tab[i].name, 6))
   return xkeywd_tab[i].idx;
 }
 return 256;
}

canonical_original_code:
static int getxkeywdidxbyname(char *name)
{
 int i; int size;
 size = sizeof(xkeywd_tab)/sizeof(xkeywd_tab[0]);
 for(i=0; i<size; i++)
 {
  if(upper_strneq(name, xkeywd_tab[i].name, 6))
   return xkeywd_tab[i].idx;
 }
 return 256;
}

variable_types:
name
char *

variable_types: i int

variable_types: size int


getkeywdidxbyname

decompiled_code:
__int64 __fastcall getkeywdidxbyname(__int64 a1)
{
char **v1; // rbp
int v2; // ebx

v1 = &off_848;
v2 = 0;
while ( !(unsigned int)upper_strneq(a1, *v1, 12LL) )
{
++v2;
v1 += 2;
if ( v2 == 41 )
return 256LL;
}
return *((unsigned int *)&keywd_tab + 4 * v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char **v1; // rbp
int v2; // ebx

v1 = &off_848;
v2 = 0;
while ( !(unsigned int)upper_strneq(a1, *v1, 12LL) )
{
++v2;
v1 += 2;
if ( v2 == 41 )
return 256LL;
}
return *((unsigned int *)&keywd_tab + 4 * v2);
}

original_code:
static int getkeywdidxbyname(char* name)
{
 int i, size;
 size = sizeof(keywd_tab)/sizeof(keywd_tab[0]);
 for(i=0; i<size; i++)
 {
  if(upper_strneq(name, keywd_tab[i].name, 12))
   return keywd_tab[i].idx;
 }
 return 256;
}

canonical_original_code:
static int getkeywdidxbyname(char *name)
{
 int i; int size;
 size = sizeof(keywd_tab)/sizeof(keywd_tab[0]);
 for(i=0; i<size; i++)
 {
  if(upper_strneq(name, keywd_tab[i].name, 12))
   return keywd_tab[i].idx;
 }
 return 256;
}


getnum

decompiled_code:
__int64 __fastcall getnum(__int64 a1)
{
int v1; // er12
__int64 v2; // rbp
char v3; // al

v1 = *(_DWORD *)(a1 + 8);
v2 = atol((const char *)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 72LL) + v1));
do
v3 = popc(a1);
while ( (unsigned int)(v3 - 48) <= 9 );
unputc(v3, a1);
*(_DWORD *)(a1 + 4) = v1;
return v2;
}

original_code:
static long getnum(yyenv_t* penv)
{
 long a;
 char c;
 int i, errpos = (penv->scanpos);
 a = atol((penv->pstmt->sqlexpr) + (penv->scanpos));
 for(i=0;;i++)
 {
  c = popc(penv);
  if( ! isdigit(c) )
  {
   unputc(c, penv);
   break;
  }
 }
 (penv->errpos) = errpos;
 return a;
}

canonical_original_code:
static long getnum(struct yyenv_t *penv)
{
 long a;
 char c;
 int i; int errpos = (penv->scanpos);
 a = atol((penv->pstmt->sqlexpr) + (penv->scanpos));
 for(i=0;;i++)
 {
  c = popc(penv);
  if( ! isdigit(c) )
  {
   unputc(c, penv);
   break;
  }
 }
 (penv->errpos) = errpos;
 return a;
}

variable_types: a long

variable_types: errpos int

return_type: long

user_defined_types: struct yyattr_t { int stat; int wstat; int article; union { char *location; long number; struct date_t date; } value; void *nntp_hand; }

user_defined_types: struct yypar_t { int type; union { char *location; long number; struct date_t date; } value; }

user_defined_types: struct tnode { int type; union { int cmpop; int logop; int iattr; int ipar; char *qstr; long num; struct date_t date; char esc; } value; struct tnode *left; struct tnode *right; }

user_defined_types: struct date_t { int year; int month; int day; }


getcmpopidxbyname

decompiled_code:
__int64 __fastcall getcmpopidxbyname(char *s1)
{
const char **v1; // rbp
int v2; // ebx

v1 = (const char **)&off_7A8;
v2 = 0;
while ( strcmp(s1, *v1) )
{
++v2;
v1 += 2;
if ( v2 == 8 )
return 256LL;
}
return *((unsigned int *)&cmpop_tab + 4 * v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1)
{
const char **v1; // rbp
int v2; // ebx

v1 = (const char **)&off_7A8;
v2 = 0;
while ( strcmp(s1, *v1) )
{
++v2;
v1 += 2;
if ( v2 == 8 )
return 256LL;
}
return *((unsigned int *)&cmpop_tab + 4 * v2);
}

original_code:
static int getcmpopidxbyname(char* name)
{
 int i, size;
 size = sizeof(cmpop_tab)/sizeof(cmpop_tab[0]);
 for(i=0; i<size; i++)
 {
  if((strcmp((char*)(name), (char*)(cmpop_tab[i].name)) == 0))
   return cmpop_tab[i].idx;
 }
 return 256;
}

canonical_original_code:
static int getcmpopidxbyname(char *name)
{
 int i; int size;
 size = sizeof(cmpop_tab)/sizeof(cmpop_tab[0]);
 for(i=0; i<size; i++)
 {
  if((strcmp((char *)(name), (char *)(cmpop_tab[i].name)) == 0))
   return cmpop_tab[i].idx;
 }
 return 256;
}


getcmpop

decompiled_code:
__int64 __fastcall getcmpop(__int64 a1)
{
int v1; // ebp
char v2; // al
char s1; // [rsp+Dh] [rbp-1Bh] BYREF
char v5; // [rsp+Eh] [rbp-1Ah]
char v6; // [rsp+Fh] [rbp-19h]

v1 = *(_DWORD *)(a1 + 8);
s1 = popc(a1);
v2 = popc(a1);
v5 = v2;
v6 = 0;
if ( (unsigned __int8)(v2 - 60) > 2u )
{
v5 = 0;
unputc(v2, a1);
}
*(_DWORD *)(a1 + 4) = v1;
return getcmpopidxbyname(&s1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebp
char v2; // al
char s1; // [rsp+Dh] [rbp-1Bh] BYREF
char v5; // [rsp+Eh] [rbp-1Ah]
char v6; // [rsp+Fh] [rbp-19h]

v1 = *(_DWORD *)(a1 + 8);
s1 = func0(a1);
v2 = func0(a1);
v5 = v2;
v6 = 0;
if ( (unsigned __int8)(v2 - 60) > 2u )
{
v5 = 0;
unputc(v2, a1);
}
*(_DWORD *)(a1 + 4) = v1;
return func6(&s1);
}

original_code:
static int getcmpop(yyenv_t* penv)
{
 char opname[3];
 char c, c1;
 int errpos = (penv->scanpos);
 opname[0] = c = popc(penv);
 opname[1] = c1= popc(penv);
 opname[2] = 0;
 if( c1 != '=' && c1 != '>' && c1 != '<' )
 {
  opname[1] = 0;
  unputc(c1, penv);
 }
 (penv->errpos) = errpos;
 return getcmpopidxbyname(opname);
}

canonical_original_code:
static int getcmpop(struct yyenv_t *penv)
{
 char opname[3];
 char c; char c1;
 int errpos = (penv->scanpos);
 opname[0] = c = popc(penv);
 opname[1] = c1= popc(penv);
 opname[2] = 0;
 if( c1 != '=' && c1 != '>' && c1 != '<' )
 {
  opname[1] = 0;
  unputc(c1, penv);
 }
 (penv->errpos) = errpos;
 return getcmpopidxbyname(opname);
}

variable_types:
opname
char [3]


original_code:
int nnsql_yylex(YYSTYPE* pyylval, yyenv_t* penv)
{
 int len, cmpop;
 char c;
 do
 { c = popc(penv); }
 while( c == ' ' || c == '\t' || c == '\n' );
 if( isalpha(c) )
 {
  int keywdidx;
  unputc(c, penv);
  len = getname(penv->texts_bufptr, -1, penv);
  if( len == 256 )
   return len;
  if( penv->extlevel )
   keywdidx = getxkeywdidxbyname( penv->texts_bufptr );
  else
   keywdidx = 256;
  if( keywdidx == 256 )
   keywdidx = getkeywdidxbyname( penv->texts_bufptr);
  if( keywdidx != 256 )
   return keywdidx;
  pyylval->name = penv->texts_bufptr;
  (penv->texts_bufptr) += (len + 1);
  return 300;
 }
 if( isdigit(c) )
 {
  unputc(c, penv);
  pyylval->number = getnum(penv);
  return 299;
 }
 switch( c )
 {
  case ';':
  case '\0':
   return ';';
  case '\'':
  case '"':
   len = getqstring(penv->texts_bufptr, -1, penv, c);
   if( len == 256 )
    return len;
   if( c == '\'' )
   {
    pyylval->qstring = penv->texts_bufptr;
    penv->texts_bufptr += (len + 1);
    return 298;
   }
   pyylval->name = penv->texts_bufptr;
   (penv->texts_bufptr) += (len + 1);
   return 300;
  case '=':
  case '<':
  case '>':
  case '!':
   unputc(c, penv);
   cmpop = getcmpop( penv );
   if(cmpop == 256 )
    return cmpop;
   pyylval->cmpop = cmpop;
   return 305;
  case '?':
   pyylval->ipar = (++(penv->dummy_npar));
   return 301;
  case '{':
   penv->extlevel ++;
   break;
  case '}':
   penv->extlevel --;
   break;
  default:
   break;
 }
 return c;
}

canonical_original_code:
int nnsql_yylex(union YYSTYPE *pyylval, struct yyenv_t *penv)
{
 int len; int cmpop;
 char c;
 do
 { c = popc(penv); }
 while( c == ' ' || c == '\t' || c == '\n' );
 if( isalpha(c) )
 {
  int keywdidx;
  unputc(c, penv);
  len = getname(penv->texts_bufptr, -1, penv);
  if( len == 256 )
   return len;
  if( penv->extlevel )
   keywdidx = getxkeywdidxbyname( penv->texts_bufptr );
  else
   keywdidx = 256;
  if( keywdidx == 256 )
   keywdidx = getkeywdidxbyname( penv->texts_bufptr);
  if( keywdidx != 256 )
   return keywdidx;
  pyylval->name = penv->texts_bufptr;
  (penv->texts_bufptr) += (len + 1);
  return 300;
 }
 if( isdigit(c) )
 {
  unputc(c, penv);
  pyylval->number = getnum(penv);
  return 299;
 }
 switch( c )
 {
  case ';':
  case '\0':
   return ';';
  case '\'':
  case '"':
   len = getqstring(penv->texts_bufptr, -1, penv, c);
   if( len == 256 )
    return len;
   if( c == '\'' )
   {
    pyylval->qstring = penv->texts_bufptr;
    penv->texts_bufptr += (len + 1);
    return 298;
   }
   pyylval->name = penv->texts_bufptr;
   (penv->texts_bufptr) += (len + 1);
   return 300;
  case '=':
  case '<':
  case '>':
  case '!':
   unputc(c, penv);
   cmpop = getcmpop( penv );
   if(cmpop == 256 )
    return cmpop;
   pyylval->cmpop = cmpop;
   return 305;
  case '?':
   pyylval->ipar = (++(penv->dummy_npar));
   return 301;
  case '{':
   penv->extlevel ++;
   break;
  case '}':
   penv->extlevel --;
   break;
  default:
   break;
 }
 return c;
}

variable_types: union YYSTYPE { char *qstring; char *name; long number; int ipar; int cmpop; char esc; int flag; int idx; void *offset; struct tnode { int type; union { int cmpop; int logop; int iattr; int ipar; char *qstr; long num; struct date_t { int year; int month; int day; } date; char esc; } value; struct tnode *left; struct tnode *right; } node; } *

variable_types: struct yyenv_t { int extlevel; int errpos; int scanpos; char *texts_bufptr; int dummy_npar; struct yystmt_t { void *hcndes; int type; int errcode; int errpos; struct yycol_t { int iattr; char *table; union { long num; char *qstr; struct date_t date; } value; } *pcol; struct yyattr_t { int stat; int wstat; int article; union { char *location; long number; struct date_t date; } value; void *nntp_hand; } *pattr; struct yypar_t { int type; union { char *location; long number; struct date_t date; } value; } *ppar; char *table; int ncol; int npar; int count; char *sqlexpr; char *texts_buf; char msgbuf[64]; struct tnode *srchtree; struct tnode *node_buf; int srchtreesize; int srchtreenum; char **ins_heads; struct tnode *ins_values; long artnum_min; long artnum_max; } *pstmt; } *

variable_types: len int

variable_types: cmpop int

variable_types: keywdidx int

user_defined_types: union YYSTYPE { char *qstring; char *name; long number; int ipar; int cmpop; char esc; int flag; int idx; void *offset; struct tnode node; }


original_code:
void nnsql_yyinit(yyenv_t* penv, yystmt_t* yystmt)
{
 penv->extlevel = 0;
 penv->dummy_npar = penv->errpos = penv->scanpos = 0;
 penv->pstmt = yystmt;
 penv->texts_bufptr = yystmt->texts_buf;
}

canonical_original_code:
void nnsql_yyinit(struct yyenv_t *penv, struct yystmt_t *yystmt)
{
 penv->extlevel = 0;
 penv->dummy_npar = penv->errpos = penv->scanpos = 0;
 penv->pstmt = yystmt;
 penv->texts_bufptr = yystmt->texts_buf;
}

variable_types:
yystmt
struct yystmt_t *


decompiled_code:
__int64 __fastcall nnodbc_getenverrstack(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
void* nnodbc_getenverrstack(void* henv)
{
 return ((env_t*)henv)->herr;
}

canonical_original_code:
void *nnodbc_getenverrstack(void *henv)
{
 return ((struct env_t *)henv)->herr;
}

variable_types:
henv
void *

return_type: void *

user_defined_types: struct env_t { void *hdbc; void *herr; }


decompiled_code:
__int64 __fastcall nnodbc_getdbcerrstack(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
void* nnodbc_getdbcerrstack(void* hdbc)
{
 return ((dbc_t*)hdbc)->herr;
}

canonical_original_code:
void *nnodbc_getdbcerrstack(void *hdbc)
{
 return ((struct DBC *)hdbc)->herr;
}

variable_types:
hdbc
void *

user_defined_types: struct DBC { void *hcndes; void *henv; struct GSTMT *stmt; void *herr; struct DBC *next; }

user_defined_types: struct GSTMT { void *hdbc; void *hstmt; struct GSTMT *next; }


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

result = nnodbc_pusherr(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = result;
return result;
}

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

result = nnodbc_pusherr(*(_QWORD *)(a1 + 24));
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
void nnodbc_pushdbcerr( void* hdbc, int code, char* msg )
{
 ((dbc_t*)hdbc)->herr = nnodbc_pusherr(((dbc_t*)hdbc)->herr, code, msg);
}

canonical_original_code:
void nnodbc_pushdbcerr(void *hdbc, int code, char *msg)
{
 ((struct DBC *)hdbc)->herr = nnodbc_pusherr(((struct DBC *)hdbc)->herr, code, msg);
}

variable_types: code int

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall nnodbc_getnntpcndes(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
void* nnodbc_getnntpcndes( void* hdbc )
{
 return ((dbc_t*)hdbc)->hcndes;
}

canonical_original_code:
void *nnodbc_getnntpcndes(void *hdbc)
{
 return ((struct DBC *)hdbc)->hcndes;
}


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

v2 = malloc(0x18uLL);
if ( v2 )
{
v2[2] = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = v2;
v2[1] = a2;
*v2 = a1;
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 24) = nnodbc_pusherr(*(_QWORD *)(a1 + 24));
result = 0xFFFFFFFFLL;
}
return result;
}

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

v2 = malloc(0x18uLL);
if ( v2 )
{
v2[2] = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = v2;
v2[1] = a2;
*v2 = a1;
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 24) = nnodbc_pusherr(*(_QWORD *)(a1 + 24));
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int nnodbc_attach_stmt(void* hdbc, void* hstmt)
{
 dbc_t* pdbc = hdbc;
 gstmt_t* pstmt;
 pstmt = (gstmt_t*)(malloc((size_t)(sizeof(gstmt_t))));
 if( ! pstmt )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, en_S1001, 0);
  return (-1);
 }
 pstmt->next = pdbc->stmt;
 pdbc->stmt = pstmt;
 pstmt->hstmt= hstmt;
 pstmt->hdbc = pdbc;
 return 0;
}

canonical_original_code:
int nnodbc_attach_stmt(void *hdbc, void *hstmt)
{
 struct DBC *pdbc = hdbc;
 struct GSTMT *pstmt;
 pstmt = (struct GSTMT *)(malloc((unsigned long)(sizeof(gstmt_t))));
 if( ! pstmt )
 {
  pdbc->herr = nnodbc_pusherr(pdbc->herr, en_S1001, 0);
  return (-1);
 }
 pstmt->next = pdbc->stmt;
 pdbc->stmt = pstmt;
 pstmt->hstmt= hstmt;
 pstmt->hdbc = pdbc;
 return 0;
}

variable_types:
hstmt
void *

variable_types: struct DBC { void *hcndes; void *henv; struct GSTMT { void *hdbc; void *hstmt; struct GSTMT *next; } *stmt; void *herr; struct DBC *next; } *


decompiled_code:
__int64 __fastcall nnodbc_detach_stmt(__int64 a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax

v3 = *(_QWORD **)(a1 + 16);
if ( !v3 )
return 0xFFFFFFFFLL;
while ( 1 )
{
if ( v3[1] == a2 )
{
*(_QWORD *)(a1 + 16) = v3[2];
free(v3);
return 0LL;
}
v4 = (_QWORD *)v3[2];
if ( v4[1] == a2 )
break;
v3 = (_QWORD *)v3[2];
if ( !v4 )
return 0xFFFFFFFFLL;
}
v3[2] = v4[2];
free(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rax

v3 = *(_QWORD **)(a1 + 16);
if ( !v3 )
return 0xFFFFFFFFLL;
while ( 1 )
{
if ( v3[1] == a2 )
{
*(_QWORD *)(a1 + 16) = v3[2];
free(v3);
return 0LL;
}
v4 = (_QWORD *)v3[2];
if ( v4[1] == a2 )
break;
v3 = (_QWORD *)v3[2];
if ( !v4 )
return 0xFFFFFFFFLL;
}
v3[2] = v4[2];
free(v4);
return 0LL;
}

original_code:
int nnodbc_detach_stmt(void* hdbc, void* hstmt)
{
 dbc_t* pdbc = hdbc;
 gstmt_t* pstmt;
 gstmt_t* ptr;
 for(pstmt=pdbc->stmt;pstmt;pstmt = pstmt->next)
 {
  if(pstmt->hstmt == hstmt)
  {
   pdbc->stmt = pstmt->next;
   {if(pstmt) free(pstmt);};
   return 0;
  }
  if(pstmt->next->hstmt == hstmt )
  {
   ptr = pstmt->next;
   pstmt->next = ptr->next;
   {if(ptr) free(ptr);};
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int nnodbc_detach_stmt(void *hdbc, void *hstmt)
{
 struct DBC *pdbc = hdbc;
 struct GSTMT *pstmt;
 struct GSTMT *ptr;
 for(pstmt=pdbc->stmt;pstmt;pstmt = pstmt->next)
 {
  if(pstmt->hstmt == hstmt)
  {
   pdbc->stmt = pstmt->next;
   {if(pstmt) free(pstmt);};
   return 0;
  }
  if(pstmt->next->hstmt == hstmt )
  {
   ptr = pstmt->next;
   pstmt->next = ptr->next;
   {if(ptr) free(ptr);};
   return 0;
  }
 }
 return -1;
}

variable_types: struct GSTMT { void *hdbc; void *hstmt; struct GSTMT *next; } *


getinitfile

decompiled_code:
void *__fastcall getinitfile(char *s, int a2)
{
void *result; // rax
__uid_t v3; // eax
const char *v4; // rbp
size_t v5; // rdx

result = 0LL;
if ( a2 > 9 )
{
v3 = getuid();
result = getpwuid(v3);
if ( result )
{
v4 = (const char *)*((_QWORD *)result + 4);
if ( v4 )
{
if ( !*v4 )
v4 = "/home";
}
else
{
v4 = "/home";
}
v5 = strlen(v4) + 10;
result = 0LL;
if ( v5 <= a2 )
{
sprintf(s, "%s%s", v4, "/.odbc.ini");
result = s;
}
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(char *s, int a2)
{
void *result; // rax
__uid_t v3; // eax
const char *v4; // rbp
size_t v5; // rdx

result = 0LL;
if ( a2 > 9 )
{
v3 = getuid();
result = getpwuid(v3);
if ( result )
{
v4 = (const char *)*((_QWORD *)result + 4);
if ( v4 )
{
if ( !*v4 )
v4 = "/home";
}
else
{
v4 = "/home";
}
v5 = strlen(v4) + 10;
result = 0LL;
if ( v5 <= a2 )
{
sprintf(s, "%s%s", v4, "/.odbc.ini");
result = s;
}
}
}
return result;
}

original_code:
char*
getinitfile(char* buf, int size)
{
 int i, j;
 char* ptr;
 j = (("/odbc.ini")? strlen((char*)("/odbc.ini")):0) + 1;
 if( size < j )
 {
  return ((void *)0);
 }
 ptr = (char*)getpwuid(getuid());
 if( ptr == ((void *)0) )
 {
  return ((void *)0);
 }
 ptr = ((struct passwd*)ptr)->pw_dir;
 if( ptr == ((void *)0) || *ptr == '\0' )
 {
  ptr = "/home";
 }
 if( size < ((ptr)? strlen((char*)(ptr)):0) + j )
 {
  return ((void *)0);
 }
 sprintf( buf, "%s%s", ptr, "/.odbc.ini");
 return buf;
}

canonical_original_code:
char *getinitfile(char *buf, int size)
{
 int i; int j;
 char *ptr;
 j = (("/odbc.ini")? strlen((char *)("/odbc.ini")):0) + 1;
 if( size < j )
 {
  return ((void *)0);
 }
 ptr = (char *)getpwuid(getuid());
 if( ptr == ((void *)0) )
 {
  return ((void *)0);
 }
 ptr = ((struct passwd *)ptr)->pw_dir;
 if( ptr == ((void *)0) || *ptr == '\0' )
 {
  ptr = "/home";
 }
 if( size < ((ptr)? strlen((char *)(ptr)):0) + j )
 {
  return ((void *)0);
 }
 sprintf( buf, "%s%s", ptr, "/.odbc.ini");
 return buf;
}

variable_types:
buf
char *

variable_types: size int

variable_types: i int

variable_types: j int

variable_types:
ptr
char *

return_type: char *

user_defined_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; }


getkeyvalinstr

decompiled_code:
char *__fastcall getkeyvalinstr(char *s, int a2, const char *a3, char *a4, int a5)
{
char *v5; // rbx
int v8; // ebp
size_t v9; // rax
size_t v10; // rdx
char *result; // rax
char sa[8]; // [rsp+10h] [rbp-438h] BYREF
__int64 v14; // [rsp+18h] [rbp-430h]
char v15[1008]; // [rsp+20h] [rbp-428h] BYREF

v5 = s;
*(_QWORD *)sa = 0LL;
v14 = 0LL;
memset(v15, 0, sizeof(v15));
if ( !s || !a4 )
return 0LL;
if ( !a3 || a5 <= 0 )
return 0LL;
if ( a2 == -3 )
a2 = strlen(s);
if ( a2 <= 0 )
return 0LL;
v8 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v5 = readtoken(v5, sa);
if ( !sa[0] )
return 0LL;
if ( strcmp(sa, ";") )
break;
v8 = 0;
}
if ( v8 != 1 )
break;
if ( !strcmp(sa, "=") )
v8 = 2;
}
if ( v8 == 2 )
break;
if ( !v8 )
{
v9 = strlen(a3);
v8 = upper_strneq(sa, a3, v9) != 0;
}
}
v10 = strlen(sa) + 1;
result = 0LL;
if ( a5 >= v10 )
result = strncpy(a4, sa, a5);
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *s, int a2, const char *a3, char *a4, int a5)
{
char *v5; // rbx
int v8; // ebp
size_t v9; // rax
size_t v10; // rdx
char *result; // rax
char sa[8]; // [rsp+10h] [rbp-438h] BYREF
__int64 v14; // [rsp+18h] [rbp-430h]
char v15[1008]; // [rsp+20h] [rbp-428h] BYREF

v5 = s;
*(_QWORD *)sa = 0LL;
v14 = 0LL;
memset(v15, 0, sizeof(v15));
if ( !s || !a4 )
return 0LL;
if ( !a3 || a5 <= 0 )
return 0LL;
if ( a2 == -3 )
a2 = strlen(s);
if ( a2 <= 0 )
return 0LL;
v8 = 0;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v5 = readtoken(v5, sa);
if ( !sa[0] )
return 0LL;
if ( strcmp(sa, ";") )
break;
v8 = 0;
}
if ( v8 != 1 )
break;
if ( !strcmp(sa, "=") )
v8 = 2;
}
if ( v8 == 2 )
break;
if ( !v8 )
{
v9 = strlen(a3);
v8 = upper_strneq(sa, a3, v9) != 0;
}
}
v10 = strlen(sa) + 1;
result = 0LL;
if ( a5 >= v10 )
result = strncpy(a4, sa, a5);
return result;
}

original_code:
char* getkeyvalinstr(
  char* cnstr,
  int cnlen,
  char* keywd,
  char* value,
  int size )
{
 char token[1024] = { '\0' };
 int flag = 0;
 if( cnstr == ((void *)0) || value == ((void *)0)
  || keywd == ((void *)0) || size < 1 )
 {
  return ((void *)0);
 }
 if( cnlen == (-3) )
 {
  cnlen = ((cnstr)? strlen((char*)(cnstr)):0);
 }
 if( cnlen <= 0 )
 {
  return ((void *)0);
 }
 for(;;)
 {
  cnstr = readtoken(cnstr, token);
  if( *token == '\0' )
  {
   break;
  }
  if( (strcmp((char*)(token), (char*)(";")) == 0) )
  {
   flag = 0;
   continue;
  }
  switch(flag)
  {
   case 0:
    if( upper_strneq(token, keywd, strlen(keywd)) )
    {
     flag = 1;
    }
    break;
   case 1:
    if( (strcmp((char*)(token), (char*)("=")) == 0) )
    {
     flag = 2;
    }
    break;
   case 2:
    if( size < strlen(token) + 1 )
    {
     return ((void *)0);
    }
    (strncpy((char*)(value), (char*)(token), (size_t)(size)));
    return value;
   default:
    break;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *getkeyvalinstr(char *cnstr, int cnlen, char *keywd, char *value, int size)
{
 char token[1024] = { '\0' };
 int flag = 0;
 if( cnstr == ((void *)0) || value == ((void *)0)
  || keywd == ((void *)0) || size < 1 )
 {
  return ((void *)0);
 }
 if( cnlen == (-3) )
 {
  cnlen = ((cnstr)? strlen((char *)(cnstr)):0);
 }
 if( cnlen <= 0 )
 {
  return ((void *)0);
 }
 for(;;)
 {
  cnstr = readtoken(cnstr, token);
  if( *token == '\0' )
  {
   break;
  }
  if( (strcmp((char *)(token), (char *)(";")) == 0) )
  {
   flag = 0;
   continue;
  }
  switch(flag)
  {
   case 0:
    if( upper_strneq(token, keywd, strlen(keywd)) )
    {
     flag = 1;
    }
    break;
   case 1:
    if( (strcmp((char *)(token), (char *)("=")) == 0) )
    {
     flag = 2;
    }
    break;
   case 2:
    if( size < strlen(token) + 1 )
    {
     return ((void *)0);
    }
    (strncpy((char *)(value), (char *)(token), (unsigned long)(size)));
    return value;
   default:
    break;
  }
 }
 return ((void *)0);
}

variable_types:
cnstr
char *

variable_types: cnlen int

variable_types:
keywd
char *

variable_types:
value
char *

variable_types:
token
char [1024]

variable_types: flag int


decompiled_code:
__int64 __fastcall nndate2date(const char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
__int64 v5; // rbx
__int64 v6; // [rsp+0h] [rbp-38h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
char nptr[44]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a1 )
return (unsigned int)-1;
if ( strlen(a1) <= 7 )
return (unsigned int)-1;
_isoc99_sscanf(a1, "%d %s %d", &v7, nptr, &v6);
if ( (unsigned int)(v6 - 1) <= 0x62 )
LODWORD(v6) = v6 + 1900;
if ( (unsigned int)(v7 - 1) > 0x1E )
return (unsigned int)-1;
v2 = atoi(nptr);
v3 = v2;
if ( v2 )
{
HIDWORD(v6) = v2;
if ( (unsigned int)(v2 - 1) > 0xB )
{
v3 = -1;
}
else
{
*(_QWORD *)a2 = v6;
*(_DWORD *)(a2 + 8) = v7;
v3 = 0;
}
}
else
{
v5 = 0LL;
while ( !(unsigned int)upper_strneq(nptr, month_name[v5], 3LL) )
{
if ( ++v5 == 12 )
return (unsigned int)-1;
}
*(_QWORD *)a2 = v6;
*(_DWORD *)(a2 + 8) = v7;
*(_DWORD *)(a2 + 4) = v5 + 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
__int64 v5; // rbx
__int64 v6; // [rsp+0h] [rbp-38h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
char nptr[44]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a1 )
return (unsigned int)-1;
if ( strlen(a1) <= 7 )
return (unsigned int)-1;
_isoc99_sscanf(a1, "%d %s %d", &v7, nptr, &v6);
if ( (unsigned int)(v6 - 1) <= 0x62 )
LODWORD(v6) = v6 + 1900;
if ( (unsigned int)(v7 - 1) > 0x1E )
return (unsigned int)-1;
v2 = atoi(nptr);
v3 = v2;
if ( v2 )
{
HIDWORD(v6) = v2;
if ( (unsigned int)(v2 - 1) > 0xB )
{
v3 = -1;
}
else
{
*(_QWORD *)a2 = v6;
*(_DWORD *)(a2 + 8) = v7;
v3 = 0;
}
}
else
{
v5 = 0LL;
while ( !(unsigned int)upper_strneq(nptr, month_name[v5], 3LL) )
{
if ( ++v5 == 12 )
return (unsigned int)-1;
}
*(_QWORD *)a2 = v6;
*(_DWORD *)(a2 + 8) = v7;
*(_DWORD *)(a2 + 4) = v5 + 1;
}
return v3;
}

original_code:
static int nndate2date(char* str, date_t* date)
{
 int i;
 char buf[4];
 date_t dt;
 if( ((str)? strlen((char*)(str)):0) < (("yyyy m d")? strlen((char*)("yyyy m d")):0) )
  return -1;
 sscanf(str, "%d %s %d", &(dt.day), buf, &(dt.year));
 if( dt.year < 100 && dt.year > 0 )
  dt.year += 1900;
 if( dt.day <= 0 || dt.day > 31 )
  return -1;
 if(i = atoi(buf))
 {
  dt.month = i;
  if( i <= 0 || i > 12 )
   return -1;
  *date = dt;
  date->month = i;
  return 0;
 }
 for(i=0;i<12;i++)
 {
  if( upper_strneq(buf, month_name[i], 3) )
  {
   *date = dt;
   date->month = i+1;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
static int nndate2date(char *str, struct date_t *date)
{
 int i;
 char buf[4];
 struct date_t dt;
 if( ((str)? strlen((char *)(str)):0) < (("yyyy m d")? strlen((char *)("yyyy m d")):0) )
  return -1;
 sscanf(str, "%d %s %d", &(dt.day), buf, &(dt.year));
 if( dt.year < 100 && dt.year > 0 )
  dt.year += 1900;
 if( dt.day <= 0 || dt.day > 31 )
  return -1;
 if(i = atoi(buf))
 {
  dt.month = i;
  if( i <= 0 || i > 12 )
   return -1;
  *date = dt;
  date->month = i;
  return 0;
 }
 for(i=0;i<12;i++)
 {
  if( upper_strneq(buf, month_name[i], 3) )
  {
   *date = dt;
   date->month = i+1;
   return 0;
  }
 }
 return -1;
}

variable_types:
str
char *

variable_types: struct date_t { int year; int month; int day; } *

variable_types:
buf
char [4]


decompiled_code:
__int64 __fastcall nnsql_nndatestr2date(const char *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+Ch] [rbp-1Ch]

if ( a1 )
{
if ( atoi(a1) )
result = nndate2date(a1, (__int64)&v3);
else
result = nndate2date(a1 + 5, (__int64)&v3);
if ( (_DWORD)result )
v4 = 0;
if ( a2 )
{
*(_QWORD *)a2 = v3;
*(_DWORD *)(a2 + 8) = v4;
}
}
else
{
result = 0LL;
if ( a2 )
*(_DWORD *)(a2 + 8) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+4h] [rbp-24h] BYREF
int v4; // [rsp+Ch] [rbp-1Ch]

if ( a1 )
{
if ( atoi(a1) )
result = func0(a1, (__int64)&v3);
else
result = func0(a1 + 5, (__int64)&v3);
if ( (_DWORD)result )
v4 = 0;
if ( a2 )
{
*(_QWORD *)a2 = v3;
*(_DWORD *)(a2 + 8) = v4;
}
}
else
{
result = 0LL;
if ( a2 )
*(_DWORD *)(a2 + 8) = 0;
}
return result;
}

original_code:
int nnsql_nndatestr2date(char* str, date_t* date)
{
 int r;
 date_t dt;
 if( !str )
 {
  if(date)
   date->day = 0;
  return 0;
 }
 if(atoi(str))
  r = nndate2date(str, &dt);
 else
  r = nndate2date(str+5, &dt);
 if( r )
  dt.day = 0;
 if( date )
  *date = dt;
 return r;
}

canonical_original_code:
int nnsql_nndatestr2date(char *str, struct date_t *date)
{
 int r;
 struct date_t dt;
 if( !str )
 {
  if(date)
   date->day = 0;
  return 0;
 }
 if(atoi(str))
  r = nndate2date(str, &dt);
 else
  r = nndate2date(str+5, &dt);
 if( r )
  dt.day = 0;
 if( date )
  *date = dt;
 return r;
}

variable_types: r int

variable_types: struct date_t { int year; int month; int day; }


decompiled_code:
__int64 __fastcall nnsql_datecmp(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)(*a1 - *a2);
if ( *a1 == *a2 )
{
result = (unsigned int)(a1[1] - a2[1]);
if ( !(_DWORD)result )
result = (unsigned int)(a1[2] - a2[2]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)(*a1 - *a2);
if ( *a1 == *a2 )
{
result = (unsigned int)(a1[1] - a2[1]);
if ( !(_DWORD)result )
result = (unsigned int)(a1[2] - a2[2]);
}
return result;
}

original_code:
int nnsql_datecmp(date_t* a, date_t* b)
{
 int r;
 if( (r = a->year - b->year) )
  return r;
 if( (r = a->month- b->month) )
  return r;
 return (a->day - b->day);
}

canonical_original_code:
int nnsql_datecmp(struct date_t *a, struct date_t *b)
{
 int r;
 if( (r = a->year - b->year) )
  return r;
 if( (r = a->month- b->month) )
  return r;
 return (a->day - b->day);
}

variable_types:
b
struct date_t *


decompiled_code:
__int64 __fastcall nnsql_odbcdatestr2date(char *nptr, int *a2)
{
int v3; // eax
int v4; // ebp
__int64 v5; // rbx
unsigned int v6; // edx
const char *v7; // rdi
int v8; // eax
int v10; // [rsp+Ch] [rbp-3Ch]

if ( nptr )
{
if ( strlen(nptr) <= 7 )
{
v6 = -1;
if ( a2 )
a2[2] = 0;
}
else
{
v10 = atoi(nptr);
v3 = atoi(nptr + 5);
v4 = v3;
if ( (unsigned int)v3 > 0xC )
{
v6 = -1;
if ( a2 )
a2[2] = 0;
}
else if ( v3 )
{
if ( nptr[5] == 48 || (v7 = nptr + 7, v3 > 9) )
v7 = nptr + 8;
LABEL_18:
v8 = atoi(v7);
if ( (unsigned int)(v8 - 1) > 0x1E )
{
v6 = -1;
if ( a2 )
a2[2] = 0;
}
else
{
v6 = 0;
if ( a2 )
{
*a2 = v10;
a2[1] = v4;
a2[2] = v8;
}
}
}
else
{
v5 = 0LL;
while ( !(unsigned int)upper_strneq(nptr + 5, month_name[v5], 3LL) )
{
if ( ++v5 == 12 )
goto LABEL_8;
}
v4 = v5 + 1;
if ( (_DWORD)v5 != -1 )
{
v7 = nptr + 9;
goto LABEL_18;
}
LABEL_8:
v6 = -1;
if ( a2 )
a2[2] = 0;
}
}
}
else
{
v6 = 0;
if ( a2 )
a2[2] = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr, int *a2)
{
int v3; // eax
int v4; // ebp
__int64 v5; // rbx
unsigned int v6; // edx
const char *v7; // rdi
int v8; // eax
int v10; // [rsp+Ch] [rbp-3Ch]

if ( nptr )
{
if ( strlen(nptr) <= 7 )
{
v6 = -1;
if ( a2 )
a2[2] = 0;
}
else
{
v10 = atoi(nptr);
v3 = atoi(nptr + 5);
v4 = v3;
if ( (unsigned int)v3 > 0xC )
{
v6 = -1;
if ( a2 )
a2[2] = 0;
}
else if ( v3 )
{
if ( nptr[5] == 48 || (v7 = nptr + 7, v3 > 9) )
v7 = nptr + 8;
LABEL_18:
v8 = atoi(v7);
if ( (unsigned int)(v8 - 1) > 0x1E )
{
v6 = -1;
if ( a2 )
a2[2] = 0;
}
else
{
v6 = 0;
if ( a2 )
{
*a2 = v10;
a2[1] = v4;
a2[2] = v8;
}
}
}
else
{
v5 = 0LL;
while ( !(unsigned int)upper_strneq(nptr + 5, month_name[v5], 3LL) )
{
if ( ++v5 == 12 )
goto LABEL_8;
}
v4 = v5 + 1;
if ( (_DWORD)v5 != -1 )
{
v7 = nptr + 9;
goto LABEL_18;
}
LABEL_8:
v6 = -1;
if ( a2 )
a2[2] = 0;
}
}
}
else
{
v6 = 0;
if ( a2 )
a2[2] = 0;
}
return v6;
}

original_code:
int nnsql_odbcdatestr2date(char* str, date_t* date)
{
 date_t dt;
 int i;
 if( ! str )
 {
  if( date )
   date->day = 0;
  return 0;
 }
 if( ((str)? strlen((char*)(str)):0) < (("yyyy-m-d")? strlen((char*)("yyyy-m-d")):0) )
 {
  if( date )
   date->day = 0;
  return -1;
 }
 dt.day = 0;
 dt.year = atoi(str); str += 5;
 dt.month = atoi(str);
 if( dt.month < 0 || dt.month > 12 )
 {
  if(date)
   date->day = 0;
  return -1;
 }
 if(! dt.month)
 {
  for(i=0;i<12;i++)
  {
   if( upper_strneq(str, month_name[i], 3) )
   {
    dt.month = i+1;
    break;
   }
  }
  if( ! dt.month )
  {
   if(date)
    date->day = 0;
   return -1;
  }
  str += 4;
 }
 else
 {
  if( *str == '0' || dt.month > 9 )
   str += 3;
  else
   str += 2;
 }
 dt.day = atoi(str);
 if( dt.day <= 0 || dt.day > 31 )
 {
  if(date)
   date->day = 0;
  return -1;
 }
 if(date)
  *date = dt;
 return 0;
}

canonical_original_code:
int nnsql_odbcdatestr2date(char *str, struct date_t *date)
{
 struct date_t dt;
 int i;
 if( ! str )
 {
  if( date )
   date->day = 0;
  return 0;
 }
 if( ((str)? strlen((char *)(str)):0) < (("yyyy-m-d")? strlen((char *)("yyyy-m-d")):0) )
 {
  if( date )
   date->day = 0;
  return -1;
 }
 dt.day = 0;
 dt.year = atoi(str); str += 5;
 dt.month = atoi(str);
 if( dt.month < 0 || dt.month > 12 )
 {
  if(date)
   date->day = 0;
  return -1;
 }
 if(! dt.month)
 {
  for(i=0;i<12;i++)
  {
   if( upper_strneq(str, month_name[i], 3) )
   {
    dt.month = i+1;
    break;
   }
  }
  if( ! dt.month )
  {
   if(date)
    date->day = 0;
   return -1;
  }
  str += 4;
 }
 else
 {
  if( *str == '0' || dt.month > 9 )
   str += 3;
  else
   str += 2;
 }
 dt.day = atoi(str);
 if( dt.day <= 0 || dt.day > 31 )
 {
  if(date)
   date->day = 0;
  return -1;
 }
 if(date)
  *date = dt;
 return 0;
}


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

result = -1LL;
if ( *a3 <= 0x270Fu )
{
result = -1LL;
if ( (unsigned int)(a3[1] - 1) <= 0xB )
{
result = -1LL;
if ( (unsigned int)(a3[2] - 1) <= 0x1E )
{
*a3 = *a1;
a3[1] = (unsigned __int16)a1[1];
a3[2] = (unsigned __int16)a1[2];
result = (__int64)a3;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 *a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

result = -1LL;
if ( *a3 <= 0x270Fu )
{
result = -1LL;
if ( (unsigned int)(a3[1] - 1) <= 0xB )
{
result = -1LL;
if ( (unsigned int)(a3[2] - 1) <= 0x1E )
{
*a3 = *a1;
a3[1] = (unsigned __int16)a1[1];
a3[2] = (unsigned __int16)a1[2];
result = (__int64)a3;
}
}
}
return result;
}

original_code:
char* odate2date( odbc_date_t* odt, int size, date_t* dt )
{
 if( dt->year < 0 || dt->year > 9999
  || dt->month< 1 || dt->month> 12
  || dt->day < 1 || dt->day > 31 )
  return (char*)(-1);
 dt->year = odt->year;
 dt->month= odt->month;
 dt->day = odt->day;
 return (char*)dt;
}

canonical_original_code:
char *odate2date(struct DATE_STRUCT *odt, int size, struct date_t *dt)
{
 if( dt->year < 0 || dt->year > 9999
  || dt->month< 1 || dt->month> 12
  || dt->day < 1 || dt->day > 31 )
  return (char *)(-1);
 dt->year = odt->year;
 dt->month= odt->month;
 dt->day = odt->day;
 return (char *)dt;
}

variable_types: struct DATE_STRUCT { short year; unsigned short month; unsigned short day; } *


decompiled_code:
__int64 __fastcall tint2num(char *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
return *a1;
}

original_code:
char* tint2num( char* d )
{
 long num = *d;
 return (char*)num;
}

canonical_original_code:
char *tint2num(char *d)
{
 long num = *d;
 return (char *)num;
}

variable_types:
d
char *

variable_types: num long


decompiled_code:
__int64 __fastcall short2num(__int16 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 *a1)
{
return *a1;
}

original_code:
char* short2num( short* d )
{
 long num = *d;
 return (char*)num;
}

canonical_original_code:
char *short2num(short *d)
{
 long num = *d;
 return (char *)num;
}

variable_types:
d
short *


decompiled_code:
__int64 __fastcall long2num(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char* long2num( long* d )
{
 return (char*)*d;
}

canonical_original_code:
char *long2num(long *d)
{
 return (char *)*d;
}

variable_types:
d
long *


decompiled_code:
__int64 __fastcall num2tint(unsigned __int64 a1, _BYTE *a2, __int64 a3, unsigned __int64 *a4)
{
__int64 result; // rax

if ( a1 <= 0xFF )
{
*a2 = a1;
result = 0LL;
}
else
{
*a4 = a1;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, _BYTE *a2, __int64 a3, unsigned __int64 *a4)
{
__int64 result; // rax

if ( a1 <= 0xFF )
{
*a2 = a1;
result = 0LL;
}
else
{
*a4 = a1;
result = -1LL;
}
return result;
}

original_code:
static char* num2tint(long x, char* buf, long size, long* psize)
{
 unsigned long a = x, b = (unsigned char)(-1);
 if( a > b )
 {
  *psize = x;
  return (char*)(-1);
 }
 *buf = (char)x;
 return 0;
}

canonical_original_code:
static char *num2tint(long x, char *buf, long size, long *psize)
{
 unsigned long a = x; unsigned long b = (unsigned char)(-1);
 if( a > b )
 {
  *psize = x;
  return (char *)(-1);
 }
 *buf = (char)x;
 return 0;
}

variable_types: x long

variable_types:
buf
char *

variable_types: size long

variable_types:
psize
long *

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
__int64 __fastcall num2short(unsigned __int64 a1, _WORD *a2, __int64 a3, unsigned __int64 *a4)
{
__int64 result; // rax

if ( a1 <= 0xFFFF )
{
*a2 = a1;
result = 0LL;
}
else
{
*a4 = a1;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, _WORD *a2, __int64 a3, unsigned __int64 *a4)
{
__int64 result; // rax

if ( a1 <= 0xFFFF )
{
*a2 = a1;
result = 0LL;
}
else
{
*a4 = a1;
result = -1LL;
}
return result;
}

original_code:
static char* num2short(long x, short* buf, long size, long* psize)
{
 unsigned long a = x, b = (unsigned short)(-1);
 if( a > b)
 {
  *psize = x;
  return (char*)(-1);
 }
 *buf = (short)x;
 return 0;
}

canonical_original_code:
static char *num2short(long x, short *buf, long size, long *psize)
{
 unsigned long a = x; unsigned long b = (unsigned short)(-1);
 if( a > b)
 {
  *psize = x;
  return (char *)(-1);
 }
 *buf = (short)x;
 return 0;
}

variable_types:
buf
short *


decompiled_code:
__int64 __fastcall num2long(__int64 a1, _QWORD *a2)
{
*a2 = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _QWORD *a2)
{
*a2 = a1;
return 0LL;
}

original_code:
static char* num2long(long x, long* buf )
{
 *buf = x;
 return 0;
}

canonical_original_code:
static char *num2long(long x, long *buf)
{
 *buf = x;
 return 0;
}

variable_types:
buf
long *


original_code:
static char* date2odate(date_t* dt, odbc_date_t* buf)
{
 buf->year = dt->year;
 buf->month= dt->month;
 buf->day = dt->day;
 return 0;
}

canonical_original_code:
static char *date2odate(struct date_t *dt, struct DATE_STRUCT *buf)
{
 buf->year = dt->year;
 buf->month= dt->month;
 buf->day = dt->day;
 return 0;
}

variable_types: struct date_t { int year; int month; int day; } *

user_defined_types: struct DATE_STRUCT { short year; unsigned short month; unsigned short day; }


decompiled_code:
char *__fastcall char2str(char *src, int a2)
{
int v2; // ebx
char *v3; // rax
char *v4; // rbp

v2 = a2;
if ( a2 < 0 )
{
v2 = 0;
if ( src )
v2 = strlen(src);
}
v3 = (char *)malloc(v2 + 1);
v4 = v3;
if ( !v3 )
return (char *)-1LL;
strncpy(v3, src, v2 + 1);
v4[v2] = 0;
return v4;
}

canonical_decompiled_code:
char *__fastcall func8(char *src, int a2)
{
int v2; // ebx
char *v3; // rax
char *v4; // rbp

v2 = a2;
if ( a2 < 0 )
{
v2 = 0;
if ( src )
v2 = strlen(src);
}
v3 = (char *)malloc(v2 + 1);
v4 = v3;
if ( !v3 )
return (char *)-1LL;
strncpy(v3, src, v2 + 1);
v4[v2] = 0;
return v4;
}

original_code:
char* char2str( char* buf, int size )
{
 char* ptr;
 int len;
 if( size < 0 )
  size = ((buf)? strlen((char*)(buf)):0);
 ptr = (char*)(malloc((size_t)(size + 1)));
 if( ! ptr )
  return (char*)(-1);
 (strncpy((char*)(ptr), (char*)(buf), (size_t)(size+1)));
 ptr[size] = 0;
 return ptr;
}

canonical_original_code:
char *char2str(char *buf, int size)
{
 char *ptr;
 int len;
 if( size < 0 )
  size = ((buf)? strlen((char *)(buf)):0);
 ptr = (char *)(malloc((unsigned long)(size + 1)));
 if( ! ptr )
  return (char *)(-1);
 (strncpy((char *)(ptr), (char *)(buf), (unsigned long)(size+1)));
 ptr[size] = 0;
 return ptr;
}

variable_types: size int

variable_types:
ptr
char *

variable_types: len int


decompiled_code:
__int64 __fastcall str2char(char *src, char *dest, signed __int64 a3, signed __int64 *a4)
{
signed __int64 v6; // rax

v6 = 1LL;
if ( src )
v6 = strlen(src) + 1;
if ( v6 <= a3 )
a3 = v6;
if ( a3 )
{
strncpy(dest, src, a3);
dest[a3 - 1] = 0;
}
*a4 = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src, char *dest, signed __int64 a3, signed __int64 *a4)
{
signed __int64 v6; // rax

v6 = 1LL;
if ( src )
v6 = strlen(src) + 1;
if ( v6 <= a3 )
a3 = v6;
if ( a3 )
{
strncpy(dest, src, a3);
dest[a3 - 1] = 0;
}
*a4 = a3;
return 0LL;
}

original_code:
static char* str2char( char* ptr, char* buf, long size, long* psize)
{
 long len;
 len = ((ptr)? strlen((char*)(ptr)):0) + 1;
 if( len > size )
  len = size;
 if( len )
 {
  (strncpy((char*)(buf), (char*)(ptr), (size_t)(len)));
  buf[len - 1] = 0;
 }
 *psize = len;
 return 0;
}

canonical_original_code:
static char *str2char(char *ptr, char *buf, long size, long *psize)
{
 long len;
 len = ((ptr)? strlen((char *)(ptr)):0) + 1;
 if( len > size )
  len = size;
 if( len )
 {
  (strncpy((char *)(buf), (char *)(ptr), (unsigned long)(len)));
  buf[len - 1] = 0;
 }
 *psize = len;
 return 0;
}

variable_types: len long


decompiled_code:
__int64 __fastcall char2num(char *src, int a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

if ( a2 < 0 )
a2 = strlen(src);
if ( a2 > 15 )
a2 = 15;
strncpy(v3, src, a2);
v3[15] = 0;
return atol(v3);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *src, int a2)
{
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

if ( a2 < 0 )
a2 = strlen(src);
if ( a2 > 15 )
a2 = 15;
strncpy(v3, src, a2);
v3[15] = 0;
return atol(v3);
}

original_code:
char* char2num( char* buf, int size)
{
 char tbuf[16];
 if( size < 0 )
  size = strlen(buf);
 if( size>15 )
  size = 15;
 (strncpy((char*)(tbuf), (char*)(buf), (size_t)(size)));
 tbuf[15] = 0;
 return (char*)atol(tbuf);
}

canonical_original_code:
char *char2num(char *buf, int size)
{
 char tbuf[16];
 if( size < 0 )
  size = strlen(buf);
 if( size>15 )
  size = 15;
 (strncpy((char *)(tbuf), (char *)(buf), (unsigned long)(size)));
 tbuf[15] = 0;
 return (char *)atol(tbuf);
}

variable_types:
tbuf
char [16]


decompiled_code:
__int64 __fastcall str2long(const char *a1, __int64 *a2)
{
*a2 = atol(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, __int64 *a2)
{
*a2 = atol(a1);
return 0LL;
}

original_code:
static char* str2long( char* ptr, long* buf)
{
 *buf = atol(ptr);
 return 0;
}

canonical_original_code:
static char *str2long(char *ptr, long *buf)
{
 *buf = atol(ptr);
 return 0;
}


decompiled_code:
__int64 __fastcall str2tint(const char *a1, _BYTE *a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rax
__int64 result; // rax

v5 = atol(a1);
if ( v5 <= 0xFF )
{
*a2 = v5;
result = 0LL;
}
else
{
*a4 = v5;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, _BYTE *a2, __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v5; // rax
__int64 result; // rax

v5 = atol(a1);
if ( v5 <= 0xFF )
{
*a2 = v5;
result = 0LL;
}
else
{
*a4 = v5;
result = -1LL;
}
return result;
}

original_code:
static char* str2tint( char* ptr, char* buf, long size, long* psize )
{
 unsigned long a, b = (unsigned char)(-1);
 a = (unsigned long)atol(ptr);
 if( a > b )
 {
  *psize = a;
  return (char*)(-1);
 }
 *buf = (char)a;
 return 0;
}

canonical_original_code:
static char *str2tint(char *ptr, char *buf, long size, long *psize)
{
 unsigned long a; unsigned long b = (unsigned char)(-1);
 a = (unsigned long)atol(ptr);
 if( a > b )
 {
  *psize = a;
  return (char *)(-1);
 }
 *buf = (char)a;
 return 0;
}


decompiled_code:
__int64 __fastcall char2date(char *src, int a2, __int64 a3)
{
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

if ( a2 < 0 )
a2 = strlen(src);
if ( a2 > 15 )
a2 = 15;
strncpy(v5, src, a2);
v5[15] = 0;
if ( (unsigned int)nnsql_odbcdatestr2date(v5, a3) )
a3 = -1LL;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *src, int a2, __int64 a3)
{
char v5[40]; // [rsp+0h] [rbp-28h] BYREF

if ( a2 < 0 )
a2 = strlen(src);
if ( a2 > 15 )
a2 = 15;
strncpy(v5, src, a2);
v5[15] = 0;
if ( (unsigned int)nnsql_odbcdatestr2date(v5, a3) )
a3 = -1LL;
return a3;
}

original_code:
char* char2date( char* buf, int size, date_t* dt)
{
 char tbuf[16];
 if( size < 0 )
  size = strlen(buf);
 if( size > 15 )
  size = 15;
 (strncpy((char*)(tbuf), (char*)(buf), (size_t)(size)));
 tbuf[15] = 0;
 if( nnsql_odbcdatestr2date(tbuf, dt) )
  return (char*)(-1);
 return (char*)dt;
}

canonical_original_code:
char *char2date(char *buf, int size, struct date_t *dt)
{
 char tbuf[16];
 if( size < 0 )
  size = strlen(buf);
 if( size > 15 )
  size = 15;
 (strncpy((char *)(tbuf), (char *)(buf), (unsigned long)(size)));
 tbuf[15] = 0;
 if( nnsql_odbcdatestr2date(tbuf, dt) )
  return (char *)(-1);
 return (char *)dt;
}


decompiled_code:
__int64 __fastcall date2str(__int16 *a1)
{
__int16 v1; // bp
__int64 v2; // rbx
unsigned __int16 v3; // r12
unsigned __int16 v5; // r13
char *v6; // rax

v1 = *a1;
v2 = -1LL;
if ( (unsigned __int16)*a1 <= 0x270Fu )
{
v3 = a1[1];
if ( (unsigned __int16)(v3 - 1) <= 0xBu )
{
v5 = a1[2];
if ( (unsigned __int16)(v5 - 1) <= 0x1Eu )
{
v6 = (char *)malloc(0xCuLL);
v2 = (__int64)v6;
if ( v6 )
sprintf(v6, "%04d-%02d-%02d", (unsigned int)v1, v3, v5);
else
v2 = -1LL;
}
}
}
return v2;
}

original_code:
char* date2str( odbc_date_t* dt )
{
 char* ptr;
 if( dt->year < 0 || dt->year > 9999
  || dt->month< 1 || dt->month> 12
  || dt->day < 1 || dt->day > 31
  || !( ptr = (char*)(malloc((size_t)(12)))) )
  return (char*)(-1);
 sprintf(ptr, "%04d-%02d-%02d", dt->year, dt->month, dt->day);
 return ptr;
}

canonical_original_code:
char *date2str(struct DATE_STRUCT *dt)
{
 char *ptr;
 if( dt->year < 0 || dt->year > 9999
  || dt->month< 1 || dt->month> 12
  || dt->day < 1 || dt->day > 31
  || !( ptr = (char *)(malloc((unsigned long)(12)))) )
  return (char *)(-1);
 sprintf(ptr, "%04d-%02d-%02d", dt->year, dt->month, dt->day);
 return ptr;
}

variable_types: struct DATE_STRUCT { short year; unsigned short month; unsigned short day; } *


decompiled_code:
__int64 __fastcall tint2str(char *a1)
{
unsigned int v1; // ebp
char *v2; // rax
char *v3; // rbx

v1 = *a1;
v2 = (char *)malloc(5uLL);
if ( !v2 )
return -1LL;
v3 = v2;
sprintf(v2, "%d", v1);
return (__int64)v3;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1)
{
unsigned int v1; // ebp
char *v2; // rax
char *v3; // rbx

v1 = *a1;
v2 = (char *)malloc(5uLL);
if ( !v2 )
return -1LL;
v3 = v2;
sprintf(v2, "%d", v1);
return (__int64)v3;
}

original_code:
char* tint2str( char* d )
{
 int c = *d;
 char* ptr;
 if( ! (ptr = (malloc((size_t)(5)))) )
  return (char*)(-1);
 sprintf(ptr, "%d", c);
 return ptr;
}

canonical_original_code:
char *tint2str(char *d)
{
 int c = *d;
 char *ptr;
 if( ! (ptr = (malloc((unsigned long)(5)))) )
  return (char *)(-1);
 sprintf(ptr, "%d", c);
 return ptr;
}

variable_types:
d
char *

variable_types: c int


decompiled_code:
__int64 __fastcall short2str(__int16 *a1)
{
unsigned int v1; // ebp
char *v2; // rax
char *v3; // rbx

v1 = *a1;
v2 = (char *)malloc(0x20uLL);
if ( !v2 )
return -1LL;
v3 = v2;
sprintf(v2, "%d", v1);
return (__int64)v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int16 *a1)
{
unsigned int v1; // ebp
char *v2; // rax
char *v3; // rbx

v1 = *a1;
v2 = (char *)malloc(0x20uLL);
if ( !v2 )
return -1LL;
v3 = v2;
sprintf(v2, "%d", v1);
return (__int64)v3;
}

original_code:
char* short2str( short* d )
{
 int c = *d;
 char* ptr;
 if( ! (ptr = (malloc((size_t)(32)))) )
  return (char*)(-1);
 sprintf(ptr, "%d", c);
 return ptr;
}

canonical_original_code:
char *short2str(short *d)
{
 int c = *d;
 char *ptr;
 if( ! (ptr = (malloc((unsigned long)(32)))) )
  return (char *)(-1);
 sprintf(ptr, "%d", c);
 return ptr;
}

variable_types:
d
short *


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

v1 = *a1;
v2 = (char *)malloc(0x40uLL);
if ( !v2 )
return -1LL;
v3 = v2;
sprintf(v2, "%ld", v1);
return (__int64)v3;
}

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

v1 = *a1;
v2 = (char *)malloc(0x40uLL);
if ( !v2 )
return -1LL;
v3 = v2;
sprintf(v2, "%ld", v1);
return (__int64)v3;
}

original_code:
char* long2str( long* d )
{
 long l = *d;
 char* ptr;
 if( ! (ptr = (malloc((size_t)(64)))) )
  return (char*)(-1);
 sprintf(ptr, "%ld", l);
 return ptr;
}

canonical_original_code:
char *long2str(long *d)
{
 long l = *d;
 char *ptr;
 if( ! (ptr = (malloc((unsigned long)(64)))) )
  return (char *)(-1);
 sprintf(ptr, "%ld", l);
 return ptr;
}

variable_types:
d
long *

variable_types: l long