decompiled_code:
void __fastcall FILE_UpdateMin30Price(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v3; // r15
unsigned __int64 v4; // r12
unsigned int *v5; // r14
_DWORD *v6; // rbx
unsigned __int64 v7; // rbp
unsigned __int64 v8; // r13
__int64 v9; // rsi
void *v11; // [rsp+10h] [rbp-48h] BYREF
void *ptr; // [rsp+18h] [rbp-40h] BYREF

ptr = 0LL;
v11 = 0LL;
if ( !a2 )
_assert_fail("NULL != szSrcDir", "OrgData.c", 0x64u, "FILE_UpdateMin30Price");
if ( !a3 )
_assert_fail("NULL != szTrgDir", "OrgData.c", 0x65u, "FILE_UpdateMin30Price");
v3 = FILE_GetFileData(a1, a2, 268435461LL, &ptr);
if ( !v3 )
return;
v4 = FILE_GetFileData(a1, a3, 4026531840LL, &v11);
if ( !v4 )
_assert_fail("0!=ulOgEntryCnt", "OrgData.c", 0x6Bu, "FILE_UpdateMin30Price");
v5 = (unsigned int *)ptr;
v6 = v11;
v7 = 0LL;
v8 = 0LL;
while ( 1 )
{
v9 = FILE_ThsMin2Date(*v5);
if ( v4 > v7 )
{
while ( v6[4] != v9 )
{
++v7;
v6 += 64;
if ( v4 == v7 )
goto LABEL_14;
}
goto LABEL_10;
}
LABEL_14:
if ( v6[4] != v9 )
break;
LABEL_10:
v8 += FILE_ThsMin5ToMin30(v5, v6);
v5 = (unsigned int *)((char *)ptr + 136 * v8);
if ( v3 <= v8 )
goto LABEL_16;
}
printf("daily entry of %ld is not exist\n", v9);
LABEL_16:
FILE_SetFileData(a1, a3, 4026531840LL, v4 << 8, v11);
free(ptr);
free(v11);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v3; // r15
unsigned __int64 v4; // r12
unsigned int *v5; // r14
_DWORD *v6; // rbx
unsigned __int64 v7; // rbp
unsigned __int64 v8; // r13
__int64 v9; // rsi
void *v11; // [rsp+10h] [rbp-48h] BYREF
void *ptr; // [rsp+18h] [rbp-40h] BYREF

ptr = 0LL;
v11 = 0LL;
if ( !a2 )
_assert_fail("NULL != szSrcDir", "OrgData.c", 0x64u, "FILE_UpdateMin30Price");
if ( !a3 )
_assert_fail("NULL != szTrgDir", "OrgData.c", 0x65u, "FILE_UpdateMin30Price");
v3 = FILE_GetFileData(a1, a2, 268435461LL, &ptr);
if ( !v3 )
return;
v4 = FILE_GetFileData(a1, a3, 4026531840LL, &v11);
if ( !v4 )
_assert_fail("0!=ulOgEntryCnt", "OrgData.c", 0x6Bu, "FILE_UpdateMin30Price");
v5 = (unsigned int *)ptr;
v6 = v11;
v7 = 0LL;
v8 = 0LL;
while ( 1 )
{
v9 = FILE_ThsMin2Date(*v5);
if ( v4 > v7 )
{
while ( v6[4] != v9 )
{
++v7;
v6 += 64;
if ( v4 == v7 )
goto LABEL_14;
}
goto LABEL_10;
}
LABEL_14:
if ( v6[4] != v9 )
break;
LABEL_10:
v8 += FILE_ThsMin5ToMin30(v5, v6);
v5 = (unsigned int *)((char *)ptr + 136 * v8);
if ( v3 <= v8 )
goto LABEL_16;
}
printf("daily entry of %ld is not exist\n", v9);
LABEL_16:
FILE_SetFileData(a1, a3, 4026531840LL, v4 << 8, v11);
free(ptr);
free(v11);
}

original_code:
VOID FILE_UpdateMin30Price( ULONG ulCode, const CHAR *szSrcDir, const CHAR *szTrgDir)
{
    ULONG i, j;
    ULONG ulSrcEntryCnt, ulOgEntryCnt;
    ULONG ulCurrDate;
    FILE_THS_MIN5_ENTRY_S *astMin5Data = ((void *)0);
    FILE_THS_MIN5_ENTRY_S *pstMin5Data = ((void *)0);
    FILE_WHOLE_DATA_S *astOgData = ((void *)0);
    FILE_WHOLE_DATA_S *pstOgData = ((void *)0);
    ((void) sizeof ((((void *)0) != szSrcDir) ? 1 : 0), __extension__ ({ if (((void *)0) != szSrcDir) ; else __assert_fail ("NULL != szSrcDir", "OrgData.c", 100, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((((void *)0) != szTrgDir) ? 1 : 0), __extension__ ({ if (((void *)0) != szTrgDir) ; else __assert_fail ("NULL != szTrgDir", "OrgData.c", 101, __extension__ __PRETTY_FUNCTION__); }));
    ulSrcEntryCnt = FILE_GetFileData(ulCode, szSrcDir, 0x10000005, (VOID**)&astMin5Data);
    if (0 == ulSrcEntryCnt) return;
    ulOgEntryCnt = FILE_GetFileData(ulCode, szTrgDir, 0xF0000000, (VOID**)&astOgData);
    ((void) sizeof ((0!=ulOgEntryCnt) ? 1 : 0), __extension__ ({ if (0!=ulOgEntryCnt) ; else __assert_fail ("0!=ulOgEntryCnt", "OrgData.c", 107, __extension__ __PRETTY_FUNCTION__); }));
    i = j = 0;
    pstMin5Data = astMin5Data;
    pstOgData = astOgData;
    while (i<ulSrcEntryCnt) {
        ulCurrDate = FILE_ThsMin2Date(pstMin5Data->ulMin);
        for (;j<ulOgEntryCnt;j++,pstOgData++) {
            if (ulCurrDate == pstOgData->ulDate) break;
        }
        if (ulCurrDate != pstOgData->ulDate) {
            printf("daily entry of %ld is not exist\n", ulCurrDate);
            break;
        }
        i += FILE_ThsMin5ToMin30(pstMin5Data, pstOgData);
        pstMin5Data=astMin5Data+i;
    }
    FILE_SetFileData(ulCode, szTrgDir, 0xF0000000, sizeof(FILE_WHOLE_DATA_S)*ulOgEntryCnt, astOgData);
    free(astMin5Data);
    free(astOgData);
    return;
}

canonical_original_code:
void FILE_UpdateMin30Price(unsigned long ulCode, char *szSrcDir, char *szTrgDir)
{
    unsigned long i; unsigned long j;
    unsigned long ulSrcEntryCnt; unsigned long ulOgEntryCnt;
    unsigned long ulCurrDate;
    struct tagFile5MinuteData *astMin5Data = ((void *)0);
    struct tagFile5MinuteData *pstMin5Data = ((void *)0);
    struct tagWholeData *astOgData = ((void *)0);
    struct tagWholeData *pstOgData = ((void *)0);
    ((void) sizeof ((((void *)0) != szSrcDir) ? 1 : 0), __extension__ ({ if (((void *)0) != szSrcDir) ; else __assert_fail ("NULL != szSrcDir", "OrgData.c", 100, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((((void *)0) != szTrgDir) ? 1 : 0), __extension__ ({ if (((void *)0) != szTrgDir) ; else __assert_fail ("NULL != szTrgDir", "OrgData.c", 101, __extension__ __PRETTY_FUNCTION__); }));
    ulSrcEntryCnt = FILE_GetFileData(ulCode, szSrcDir, 0x10000005, (void **)&astMin5Data);
    if (0 == ulSrcEntryCnt) return;
    ulOgEntryCnt = FILE_GetFileData(ulCode, szTrgDir, 0xF0000000, (void **)&astOgData);
    ((void) sizeof ((0!=ulOgEntryCnt) ? 1 : 0), __extension__ ({ if (0!=ulOgEntryCnt) ; else __assert_fail ("0!=ulOgEntryCnt", "OrgData.c", 107, __extension__ __PRETTY_FUNCTION__); }));
    i = j = 0;
    pstMin5Data = astMin5Data;
    pstOgData = astOgData;
    while (i<ulSrcEntryCnt) {
        ulCurrDate = FILE_ThsMin2Date(pstMin5Data->ulMin);
        for (;j<ulOgEntryCnt;j++,pstOgData++) {
            if (ulCurrDate == pstOgData->ulDate) break;
        }
        if (ulCurrDate != pstOgData->ulDate) {
            printf("daily entry of %ld is not exist\n", ulCurrDate);
            break;
        }
        i += FILE_ThsMin5ToMin30(pstMin5Data, pstOgData);
        pstMin5Data=astMin5Data+i;
    }
    FILE_SetFileData(ulCode, szTrgDir, 0xF0000000, sizeof(FILE_WHOLE_DATA_S)*ulOgEntryCnt, astOgData);
    free(astMin5Data);
    free(astOgData);
    return;
}

variable_types:
ulCurrDate
unsigned long

variable_types: struct tagFile5MinuteData { unsigned int ulMin; unsigned int ulBeginWithCheck; unsigned int ulHighWithCheck; unsigned int ulLowWithCheck; unsigned int ulEndWithCheck; unsigned int ulRsv; unsigned int ulVolWithCheck; unsigned char aucRsv[-1]; } *


main

canonical_name: main

repo: gitslime/StockAnalyser

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp

if ( (unsigned int)(argc - 4) > 2 )
{
printf("USAGE: %s code source_path target_path [debug] [verbose]", *argv);
exit(1);
}
v3 = GetCodeByIndex(argv[1]);
v4 = argc;
if ( !strcasecmp(argv[v4 - 1], "debug") || !strcasecmp(argv[v4 - 2], "debug") )
g_bIsDebugMode = 1;
FILE_UpdateDailyPrice(v3, (__int64)argv[2], (__int64)argv[3]);
FILE_UpdateMin30Price(v3, (__int64)argv[2], (__int64)argv[3]);
FILE_UpdateWeight(v3, (__int64)argv[2], (__int64)argv[3]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp

if ( (unsigned int)(argc - 4) > 2 )
{
printf("USAGE: %s code source_path target_path [debug] [verbose]", *argv);
exit(1);
}
v3 = GetCodeByIndex(argv[1]);
v4 = argc;
if ( !strcasecmp(argv[v4 - 1], "debug") || !strcasecmp(argv[v4 - 2], "debug") )
g_bIsDebugMode = 1;
func0(v3, (__int64)argv[2], (__int64)argv[3]);
func1(v3, (__int64)argv[2], (__int64)argv[3]);
func2(v3, (__int64)argv[2], (__int64)argv[3]);
return 0;
}

original_code:
int main(int argc,char *argv[])
{
    ULONG ulStockCode;
    if ((argc < 4) || (argc > 6)) {
        printf("USAGE: %s code source_path target_path [debug] [verbose]", argv[0]);
        exit(1);
    }
    ulStockCode = GetCodeByIndex(argv[1]);
    if ((0 == strcasecmp(argv[argc-1], "debug")) || (0 == strcasecmp(argv[argc-2], "debug")))
        g_bIsDebugMode = (1);
    FILE_UpdateDailyPrice(ulStockCode, argv[2], argv[3]);
    FILE_UpdateMin30Price(ulStockCode, argv[2], argv[3]);
    FILE_UpdateWeight(ulStockCode, argv[2], argv[3]);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long ulStockCode;
    if ((argc < 4) || (argc > 6)) {
        printf("USAGE: %s code source_path target_path [debug] [verbose]", argv[0]);
        exit(1);
    }
    ulStockCode = GetCodeByIndex(argv[1]);
    if ((0 == strcasecmp(argv[argc-1], "debug")) || (0 == strcasecmp(argv[argc-2], "debug")))
        g_bIsDebugMode = (1);
    FILE_UpdateDailyPrice(ulStockCode, argv[2], argv[3]);
    FILE_UpdateMin30Price(ulStockCode, argv[2], argv[3]);
    FILE_UpdateWeight(ulStockCode, argv[2], argv[3]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ulStockCode
unsigned long

return_type: int


decompiled_code:
int __fastcall STAT_PrintWatch(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbp
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a3 + a1 >= a2 )
return printf("-100,-100,");
v6 = a4 + (a3 << 8);
GetTotalRise(a3, v6, 3LL, v7);
printf("%f,", *(float *)v7);
GetTotalRise(a3, v6, 2LL, v7);
return printf("%f,", *(float *)v7);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbp
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( a3 + a1 >= a2 )
return printf("-100,-100,");
v6 = a4 + (a3 << 8);
GetTotalRise(a3, v6, 3LL, v7);
printf("%f,", *(float *)v7);
GetTotalRise(a3, v6, 2LL, v7);
return printf("%f,", *(float *)v7);
}

original_code:
VOID STAT_PrintWatch( ULONG ulIndex, ULONG ulEntryCnt, ULONG ulWatchDays, FILE_WHOLE_DATA_S *pstCurr)
{
    FLOAT fWatchRise;
    if ((ulIndex+ulWatchDays)>=ulEntryCnt) {
        printf("-100,-100,");
    }
    else {
        (VOID)GetTotalRise(ulWatchDays, pstCurr+ulWatchDays, (0x03UL), &fWatchRise);
        printf("%f,", fWatchRise);
        (VOID)GetTotalRise(ulWatchDays, pstCurr+ulWatchDays, (0x02UL), &fWatchRise);
        printf("%f,", fWatchRise);
    }
    return;
}

canonical_original_code:
void STAT_PrintWatch(unsigned long ulIndex, unsigned long ulEntryCnt, unsigned long ulWatchDays, struct tagWholeData *pstCurr)
{
    float fWatchRise;
    if ((ulIndex+ulWatchDays)>=ulEntryCnt) {
        printf("-100,-100,");
    }
    else {
        (void)GetTotalRise(ulWatchDays, pstCurr+ulWatchDays, (0x03UL), &fWatchRise);
        printf("%f,", fWatchRise);
        (void)GetTotalRise(ulWatchDays, pstCurr+ulWatchDays, (0x02UL), &fWatchRise);
        printf("%f,", fWatchRise);
    }
    return;
}

variable_types:
ulIndex
unsigned long

variable_types:
ulEntryCnt
unsigned long

variable_types:
ulWatchDays
unsigned long

variable_types: struct tagWholeData { char szComment[16]; unsigned int ulDate; unsigned int ulRsv; struct tagPrice { unsigned int ulBegin; unsigned int ulHigh; unsigned int ulLow; unsigned int ulEnd; unsigned int ulVol; unsigned int ulFlag; } stDailyPrice; struct tagPrice astMin30Price[8]; struct tagFactor { unsigned int ulFlag; float fMulti; float fAdder; } stFactor; unsigned int ulPad; } *

variable_types: fWatchRise float

return_type: void

user_defined_types: struct tagWholeData { char szComment[16]; unsigned int ulDate; unsigned int ulRsv; struct tagPrice stDailyPrice; struct tagPrice astMin30Price[8]; struct tagFactor stFactor; unsigned int ulPad; }


decompiled_code:
void __fastcall STAT_Distribute(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v8; // rax
__int64 v9; // r12
unsigned __int64 v10; // rbx
unsigned __int64 v11; // r12
void (__fastcall *v12)(unsigned __int64, char *); // r13
char *v13; // rbp
void *ptr; // [rsp+8h] [rbp-80h] BYREF
char v15[40]; // [rsp+10h] [rbp-78h] BYREF
void (__fastcall *v16)(unsigned __int64, char *); // [rsp+38h] [rbp-50h]

ptr = 0LL;
v8 = FILE_GetFileData(a1, a2, 4026531840LL, &ptr);
if ( v8 )
{
v9 = v8;
v10 = GetIndexByDate(a4, 17LL, v8, ptr);
v11 = GetIndexByDate(a5, 16LL, v9, ptr);
if ( v10 > v11 )
{
DebugOutString("%lu: invaild begin date: %lu, end date: %lu\n", a1, a4, a5);
free(ptr);
}
else
{
METHOD_GetFuncSet(a3, v15);
v12 = v16;
v13 = (char *)ptr + 256 * v10;
do
{
v12(v10++, v13);
v13 += 256;
}
while ( v11 >= v10 );
free(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v8; // rax
__int64 v9; // r12
unsigned __int64 v10; // rbx
unsigned __int64 v11; // r12
void (__fastcall *v12)(unsigned __int64, char *); // r13
char *v13; // rbp
void *ptr; // [rsp+8h] [rbp-80h] BYREF
char v15[40]; // [rsp+10h] [rbp-78h] BYREF
void (__fastcall *v16)(unsigned __int64, char *); // [rsp+38h] [rbp-50h]

ptr = 0LL;
v8 = FILE_GetFileData(a1, a2, 4026531840LL, &ptr);
if ( v8 )
{
v9 = v8;
v10 = GetIndexByDate(a4, 17LL, v8, ptr);
v11 = GetIndexByDate(a5, 16LL, v9, ptr);
if ( v10 > v11 )
{
DebugOutString("%lu: invaild begin date: %lu, end date: %lu\n", a1, a4, a5);
free(ptr);
}
else
{
METHOD_GetFuncSet(a3, v15);
v12 = v16;
v13 = (char *)ptr + 256 * v10;
do
{
v12(v10++, v13);
v13 += 256;
}
while ( v11 >= v10 );
free(ptr);
}
}
}

original_code:
VOID STAT_Distribute( ULONG ulCode, CHAR *szDir, ULONG ulMethod, ULONG ulBeginDate, ULONG ulEndDate)
{
    ULONG i, ulEntryCnt;
    ULONG ulBeginIndex, ulEndIndex;
    METHOD_FUNC_SET_S stMethodFunc;
    Choose_PF pfChoose = ((void *)0);
    Statistics_PF pfStat = ((void *)0);
    CHOOSE_PRE_DEAL_S stDealInfo;
    FILE_WHOLE_DATA_S *astWholeData = ((void *)0);
    FILE_WHOLE_DATA_S *pstStatData = ((void *)0);
    ulEntryCnt = FILE_GetFileData(ulCode, szDir, 0xF0000000, (VOID**)&astWholeData);
    if (0 == ulEntryCnt) return;
    ulBeginIndex = GetIndexByDate(ulBeginDate, (0x11), ulEntryCnt, astWholeData);
    ulEndIndex = GetIndexByDate(ulEndDate, (0x10), ulEntryCnt, astWholeData);
    if (ulBeginIndex>ulEndIndex) {
        DebugOutString("%lu: invaild begin date: %lu, end date: %lu\n", ulCode, ulBeginDate, ulEndDate);
        free(astWholeData);
        return;
    }
    METHOD_GetFuncSet(ulMethod, &stMethodFunc);
    pfChoose = stMethodFunc.pfDailyChoose;
    pfStat = stMethodFunc.pfStatistics;
    memset(&stDealInfo, 0, sizeof(stDealInfo));
    for (i=ulBeginIndex,pstStatData = &astWholeData[ulBeginIndex];i<=ulEndIndex;i++, pstStatData++) {
        pfStat(i, pstStatData);
    }
    free(astWholeData);
    return;
}

canonical_original_code:
void STAT_Distribute(unsigned long ulCode, char *szDir, unsigned long ulMethod, unsigned long ulBeginDate, unsigned long ulEndDate)
{
    unsigned long i; unsigned long ulEntryCnt;
    unsigned long ulBeginIndex; unsigned long ulEndIndex;
    struct tagMethodFuncSet stMethodFunc;
    unsigned short (*pfChoose)(unsigned long, struct tagWholeData *, struct tagPreDealInfo *) = ((void *)0);
    void (*pfStat)(unsigned long, struct tagWholeData *) = ((void *)0);
    struct tagPreDealInfo stDealInfo;
    struct tagWholeData *astWholeData = ((void *)0);
    struct tagWholeData *pstStatData = ((void *)0);
    ulEntryCnt = FILE_GetFileData(ulCode, szDir, 0xF0000000, (void **)&astWholeData);
    if (0 == ulEntryCnt) return;
    ulBeginIndex = GetIndexByDate(ulBeginDate, (0x11), ulEntryCnt, astWholeData);
    ulEndIndex = GetIndexByDate(ulEndDate, (0x10), ulEntryCnt, astWholeData);
    if (ulBeginIndex>ulEndIndex) {
        DebugOutString("%lu: invaild begin date: %lu, end date: %lu\n", ulCode, ulBeginDate, ulEndDate);
        free(astWholeData);
        return;
    }
    METHOD_GetFuncSet(ulMethod, &stMethodFunc);
    pfChoose = stMethodFunc.pfDailyChoose;
    pfStat = stMethodFunc.pfStatistics;
    memset(&stDealInfo, 0, sizeof(stDealInfo));
    for (i=ulBeginIndex,pstStatData = &astWholeData[ulBeginIndex];i<=ulEndIndex;i++, pstStatData++) {
        pfStat(i, pstStatData);
    }
    free(astWholeData);
    return;
}

variable_types:
ulCode
unsigned long

variable_types:
szDir
char *

variable_types:
ulMethod
unsigned long

variable_types:
ulBeginDate
unsigned long

variable_types:
ulEndDate
unsigned long

variable_types:
i
unsigned long

variable_types:
ulBeginIndex
unsigned long

variable_types:
ulEndIndex
unsigned long

variable_types: struct tagMethodFuncSet { unsigned long (*pfGetGainPrice)(struct tagWholeData { char szComment[16]; unsigned int ulDate; unsigned int ulRsv; struct tagPrice { unsigned int ulBegin; unsigned int ulHigh; unsigned int ulLow; unsigned int ulEnd; unsigned int ulVol; unsigned int ulFlag; } stDailyPrice; struct tagPrice astMin30Price[8]; struct tagFactor { unsigned int ulFlag; float fMulti; float fAdder; } stFactor; unsigned int ulPad; } *, struct tagStockCtrl { unsigned int ulGainPrice; unsigned int ulLossPrice; unsigned int ulBuyDate; unsigned int ulBuyPrice; unsigned int ulSellDate; unsigned int ulSellPrice; float fContext; } *); unsigned long (*pfGetLossPrice)(struct tagWholeData *, struct tagStockCtrl *); unsigned long (*pfGetBuyPrice)(struct tagWholeData *, unsigned long); unsigned long (*pfGetSellPrice)(struct tagWholeData *, struct tagStockCtrl *); unsigned short (*pfDailyChoose)(unsigned long, struct tagWholeData *, struct tagPreDealInfo { unsigned short bIsSell; unsigned short usDealHour; unsigned short usDealMin; unsigned short bIsHigher; float fThresholdPrice; float fWeight; } *); void (*pfStatistics)(unsigned long, struct tagWholeData *); void (*pfSetParam)(unsigned long, float *); }

variable_types: unsigned short (*)(unsigned long, struct tagWholeData { char szComment[16]; unsigned int ulDate; unsigned int ulRsv; struct tagPrice { unsigned int ulBegin; unsigned int ulHigh; unsigned int ulLow; unsigned int ulEnd; unsigned int ulVol; unsigned int ulFlag; } stDailyPrice; struct tagPrice astMin30Price[8]; struct tagFactor { unsigned int ulFlag; float fMulti; float fAdder; } stFactor; unsigned int ulPad; } *, struct tagPreDealInfo { unsigned short bIsSell; unsigned short usDealHour; unsigned short usDealMin; unsigned short bIsHigher; float fThresholdPrice; float fWeight; } *)

variable_types: void (*)(unsigned long, struct tagWholeData { char szComment[16]; unsigned int ulDate; unsigned int ulRsv; struct tagPrice { unsigned int ulBegin; unsigned int ulHigh; unsigned int ulLow; unsigned int ulEnd; unsigned int ulVol; unsigned int ulFlag; } stDailyPrice; struct tagPrice astMin30Price[8]; struct tagFactor { unsigned int ulFlag; float fMulti; float fAdder; } stFactor; unsigned int ulPad; } *)

user_defined_types: struct tagMethodFuncSet { unsigned long (*pfGetGainPrice)(struct tagWholeData *, struct tagStockCtrl *); unsigned long (*pfGetLossPrice)(struct tagWholeData *, struct tagStockCtrl *); unsigned long (*pfGetBuyPrice)(struct tagWholeData *, unsigned long); unsigned long (*pfGetSellPrice)(struct tagWholeData *, struct tagStockCtrl *); unsigned short (*pfDailyChoose)(unsigned long, struct tagWholeData *, struct tagPreDealInfo *); void (*pfStatistics)(unsigned long, struct tagWholeData *); void (*pfSetParam)(unsigned long, float *); }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // r15
__int64 i; // rbx
__int64 v9[8]; // [rsp+8h] [rbp-40h] BYREF

v9[0] = 0LL;
if ( (unsigned int)(argc - 6) > 1 )
{
printf("USAGE: %s method path begin-date end-date { code | all } [debug]", *argv);
exit(1);
}
if ( !strcasecmp(argv[argc - 1], "debug") )
g_bIsDebugMode = 1;
v3 = GetMethod(argv[1]);
v4 = GetCodeList(argv[5], v9);
v5 = atol(argv[3]);
v6 = atol(argv[4]);
if ( v4 )
{
for ( i = 0LL; i != v4; ++i )
STAT_Distribute(*(_QWORD *)(v9[0] + 8 * i), (__int64)argv[2], v3, v5, v6);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 v4; // r12
__int64 v5; // r14
__int64 v6; // r15
__int64 i; // rbx
__int64 v9[8]; // [rsp+8h] [rbp-40h] BYREF

v9[0] = 0LL;
if ( (unsigned int)(argc - 6) > 1 )
{
printf("USAGE: %s method path begin-date end-date { code | all } [debug]", *argv);
exit(1);
}
if ( !strcasecmp(argv[argc - 1], "debug") )
g_bIsDebugMode = 1;
v3 = GetMethod(argv[1]);
v4 = GetCodeList(argv[5], v9);
v5 = atol(argv[3]);
v6 = atol(argv[4]);
if ( v4 )
{
for ( i = 0LL; i != v4; ++i )
func1(*(_QWORD *)(v9[0] + 8 * i), (__int64)argv[2], v3, v5, v6);
}
return 0;
}

original_code:
int main(int argc,char *argv[])
{
    ULONG i, ulCodeCnt;
    ULONG ulMethod;
    ULONG ulBeginDate, ulEndDate;
    ULONG *pulCodeList = ((void *)0);
    if ((argc < 6) || (argc > 7)) {
        printf("USAGE: %s method path begin-date end-date { code | all } [debug]", argv[0]);
        exit(1);
    }
    if (0 == strcasecmp(argv[argc-1], "debug"))
        g_bIsDebugMode = (1);
    ulMethod = GetMethod(argv[1]);
    ulCodeCnt = GetCodeList(argv[5], &pulCodeList);
    ulBeginDate = (ULONG)atol(argv[3]);
    ulEndDate = (ULONG)atol(argv[4]);
    for (i=0;i<ulCodeCnt;i++) {
        STAT_Distribute(pulCodeList[i], argv[2], ulMethod, ulBeginDate, ulEndDate);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long i; unsigned long ulCodeCnt;
    unsigned long ulMethod;
    unsigned long ulBeginDate; unsigned long ulEndDate;
    unsigned long *pulCodeList = ((void *)0);
    if ((argc < 6) || (argc > 7)) {
        printf("USAGE: %s method path begin-date end-date { code | all } [debug]", argv[0]);
        exit(1);
    }
    if (0 == strcasecmp(argv[argc-1], "debug"))
        g_bIsDebugMode = (1);
    ulMethod = GetMethod(argv[1]);
    ulCodeCnt = GetCodeList(argv[5], &pulCodeList);
    ulBeginDate = (unsigned long)atol(argv[3]);
    ulEndDate = (unsigned long)atol(argv[4]);
    for (i=0;i<ulCodeCnt;i++) {
        STAT_Distribute(pulCodeList[i], argv[2], ulMethod, ulBeginDate, ulEndDate);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
ulCodeCnt
unsigned long

variable_types:
pulCodeList
unsigned long *


decompiled_code:
__int64 __fastcall CHECK_IsPriceFit(unsigned __int64 a1, unsigned __int64 a2, char a3)
{
return ((a2 >> a3) + a2 >= a1) & (unsigned __int8)(a2 - (a2 >> a3) <= a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, unsigned __int64 a2, char a3)
{
return ((a2 >> a3) + a2 >= a1) & (unsigned __int8)(a2 - (a2 >> a3) <= a1);
}

original_code:
BOOL_T CHECK_IsPriceFit( ULONG ulCheckPrice, ULONG ulBasePrice, ULONG ulRange)
{
    ULONG ulPriceHigh = ulBasePrice + (ulBasePrice>>ulRange);
    ULONG ulPriceLow = ulBasePrice - (ulBasePrice>>ulRange);
    return ((ulCheckPrice < ulPriceLow) || (ulCheckPrice > ulPriceHigh)) ? (0) : (1);
}

canonical_original_code:
unsigned short CHECK_IsPriceFit(unsigned long ulCheckPrice, unsigned long ulBasePrice, unsigned long ulRange)
{
    unsigned long ulPriceHigh = ulBasePrice + (ulBasePrice>>ulRange);
    unsigned long ulPriceLow = ulBasePrice - (ulBasePrice>>ulRange);
    return ((ulCheckPrice < ulPriceLow) || (ulCheckPrice > ulPriceHigh)) ? (0) : (1);
}

variable_types:
ulCheckPrice
unsigned long

variable_types:
ulBasePrice
unsigned long

variable_types:
ulRange
unsigned long

variable_types:
ulPriceHigh
unsigned long

variable_types:
ulPriceLow
unsigned long

return_type: unsigned short


decompiled_code:
void __fastcall CHECK_CheckOne(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v3; // r15
char *v4; // rbx
__int64 i; // rbp
__int64 v6; // rsi
_DWORD *v7; // r13
unsigned int *v8; // r13
unsigned __int64 v9; // rbp
unsigned __int64 v10; // rbx
unsigned int *v11; // rax
__int64 v12; // r12
__int64 v13; // rdx
unsigned int v14; // ebp
unsigned int v15; // ebx
unsigned __int64 v16; // rax
unsigned __int64 v17; // [rsp+0h] [rbp-68h]
unsigned __int64 v18; // [rsp+8h] [rbp-60h]
unsigned __int64 v19; // [rsp+10h] [rbp-58h]
unsigned int v20; // [rsp+10h] [rbp-58h]
unsigned int v21; // [rsp+1Ch] [rbp-4Ch]
void *ptr; // [rsp+28h] [rbp-40h] BYREF

ptr = 0LL;
v18 = FILE_GetFileData(a1, a3, 4026531840LL, &ptr);
if ( v18 )
{
if ( *((_DWORD *)ptr + 4) != a2 )
printf("start date = %lu, data has %lu\n", a2, *((unsigned int *)ptr + 4));
v4 = (char *)ptr + 256;
if ( v18 > 1 )
{
for ( i = 1LL; i != v18; ++i )
{
if ( *((_DWORD *)v4 + 5) != -1 )
printf("%lu data invalid!\n", *((unsigned int *)v4 + 4));
v6 = *((unsigned int *)v4 + 4);
if ( (unsigned int)v6 <= *((_DWORD *)v4 - 60) )
printf("%lu data reverse!\n", v6);
v4 += 256;
}
}
v7 = ptr;
v17 = 0LL;
while ( v7[17] != -858993460 )
{
++v17;
v7 += 64;
if ( v18 == v17 )
goto LABEL_15;
}
DebugOutString("MIN30 starts at %lu\n", (unsigned int)v7[4]);
if ( v18 > v17 )
{
v8 = v7 + 12;
do
{
v19 = *v8;
v9 = v8[1];
v10 = v8[2];
v11 = v8;
v12 = 0LL;
v13 = 0LL;
while ( v11[5] == -858993460 )
{
if ( v9 < v11[1] )
v9 = v11[1];
if ( v10 > v11[2] )
v10 = v11[2];
v3 = v11[3];
v12 += v11[4];
++v13;
v11 += 6;
if ( v13 == 8 )
goto LABEL_29;
}
if ( !v13 )
{
printf("%lu min30 price miss!\n", *(v8 - 8));
goto LABEL_21;
}
LABEL_29:
v21 = *(v8 - 6);
if ( !(unsigned __int16)CHECK_IsPriceFit(v19, v21, 3) )
printf("%lu begin price not march! %lu VS %lu\n", *(v8 - 8), v19, v21);
v20 = *(v8 - 5);
if ( !(unsigned __int16)CHECK_IsPriceFit(v9, v20, 6) )
printf("%lu high price not march! %lu VS %lu\n", *(v8 - 8), v9, v20);
v14 = *(v8 - 4);
if ( !(unsigned __int16)CHECK_IsPriceFit(v10, v14, 6) )
printf("%lu low price not march! %lu VS %lu\n", *(v8 - 8), v10, v14);
v15 = *(v8 - 3);
if ( !(unsigned __int16)CHECK_IsPriceFit(v3, v15, 4) )
printf("%lu end price not march! %lu VS %lu\n", *(v8 - 8), v3, v15);
v16 = *(v8 - 2);
if ( v16 < v12 - 25 || v16 > v12 + 10 )
printf("%lu volume not march! %lu VS %lu\n", *(v8 - 8), *(v8 - 2), v12);
LABEL_21:
++v17;
v8 += 64;
}
while ( v18 != v17 );
}
LABEL_15:
free(ptr);
}
else
{
puts("can't get data");
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v3; // r15
char *v4; // rbx
__int64 i; // rbp
__int64 v6; // rsi
_DWORD *v7; // r13
unsigned int *v8; // r13
unsigned __int64 v9; // rbp
unsigned __int64 v10; // rbx
unsigned int *v11; // rax
__int64 v12; // r12
__int64 v13; // rdx
unsigned int v14; // ebp
unsigned int v15; // ebx
unsigned __int64 v16; // rax
unsigned __int64 v17; // [rsp+0h] [rbp-68h]
unsigned __int64 v18; // [rsp+8h] [rbp-60h]
unsigned __int64 v19; // [rsp+10h] [rbp-58h]
unsigned int v20; // [rsp+10h] [rbp-58h]
unsigned int v21; // [rsp+1Ch] [rbp-4Ch]
void *ptr; // [rsp+28h] [rbp-40h] BYREF

ptr = 0LL;
v18 = FILE_GetFileData(a1, a3, 4026531840LL, &ptr);
if ( v18 )
{
if ( *((_DWORD *)ptr + 4) != a2 )
printf("start date = %lu, data has %lu\n", a2, *((unsigned int *)ptr + 4));
v4 = (char *)ptr + 256;
if ( v18 > 1 )
{
for ( i = 1LL; i != v18; ++i )
{
if ( *((_DWORD *)v4 + 5) != -1 )
printf("%lu data invalid!\n", *((unsigned int *)v4 + 4));
v6 = *((unsigned int *)v4 + 4);
if ( (unsigned int)v6 <= *((_DWORD *)v4 - 60) )
printf("%lu data reverse!\n", v6);
v4 += 256;
}
}
v7 = ptr;
v17 = 0LL;
while ( v7[17] != -858993460 )
{
++v17;
v7 += 64;
if ( v18 == v17 )
goto LABEL_15;
}
DebugOutString("MIN30 starts at %lu\n", (unsigned int)v7[4]);
if ( v18 > v17 )
{
v8 = v7 + 12;
do
{
v19 = *v8;
v9 = v8[1];
v10 = v8[2];
v11 = v8;
v12 = 0LL;
v13 = 0LL;
while ( v11[5] == -858993460 )
{
if ( v9 < v11[1] )
v9 = v11[1];
if ( v10 > v11[2] )
v10 = v11[2];
v3 = v11[3];
v12 += v11[4];
++v13;
v11 += 6;
if ( v13 == 8 )
goto LABEL_29;
}
if ( !v13 )
{
printf("%lu min30 price miss!\n", *(v8 - 8));
goto LABEL_21;
}
LABEL_29:
v21 = *(v8 - 6);
if ( !(unsigned __int16)func0(v19, v21, 3) )
printf("%lu begin price not march! %lu VS %lu\n", *(v8 - 8), v19, v21);
v20 = *(v8 - 5);
if ( !(unsigned __int16)func0(v9, v20, 6) )
printf("%lu high price not march! %lu VS %lu\n", *(v8 - 8), v9, v20);
v14 = *(v8 - 4);
if ( !(unsigned __int16)func0(v10, v14, 6) )
printf("%lu low price not march! %lu VS %lu\n", *(v8 - 8), v10, v14);
v15 = *(v8 - 3);
if ( !(unsigned __int16)func0(v3, v15, 4) )
printf("%lu end price not march! %lu VS %lu\n", *(v8 - 8), v3, v15);
v16 = *(v8 - 2);
if ( v16 < v12 - 25 || v16 > v12 + 10 )
printf("%lu volume not march! %lu VS %lu\n", *(v8 - 8), *(v8 - 2), v12);
LABEL_21:
++v17;
v8 += 64;
}
while ( v18 != v17 );
}
LABEL_15:
free(ptr);
}
else
{
puts("can't get data");
}
}

original_code:
VOID CHECK_CheckOne( ULONG ulCode, ULONG ulStartDate, CHAR *szDir)
{
    ULONG i, j, ulEntryCnt;
    ULONG ulHigh, ulLow, ulBegin, ulEnd, ulVol;
    FILE_WHOLE_DATA_S *astWholeData = ((void *)0);
    FILE_WHOLE_DATA_S *pstCurrData = ((void *)0);
    FILE_WHOLE_DATA_S *pstPrevData = ((void *)0);
    PRICE_S *pstMin30Price = ((void *)0);
    PRICE_S *pstDailyPrice = ((void *)0);
    ulEntryCnt = FILE_GetFileData(ulCode, szDir, 0xF0000000, (VOID**)&astWholeData);
    if (0 == ulEntryCnt) {
        printf("can't get data\n");
        return;
    }
    if (ulStartDate != astWholeData[0].ulDate) {
        printf("start date = %lu, data has %lu\n", ulStartDate, astWholeData[0].ulDate);
    }
    pstPrevData = astWholeData;
    pstCurrData = pstPrevData+1;
    for (i=1;i<ulEntryCnt;i++,pstPrevData++,pstCurrData++) {
        if ((0xFFFFFFFF) != pstCurrData->ulRsv) {
            printf("%lu data invalid!\n", pstCurrData->ulDate);
        }
        if (pstCurrData->ulDate <= pstPrevData->ulDate) {
            printf("%lu data reverse!\n", pstCurrData->ulDate);
        }
    }
    pstCurrData = astWholeData;
    for (i=0;i<ulEntryCnt;i++,pstCurrData++) {
        if (0xCCCCCCCC == pstCurrData->astMin30Price[0].ulFlag) {
            DebugOutString("MIN30 starts at %lu\n", pstCurrData->ulDate);
            break;
        }
    }
    for (;i<ulEntryCnt;i++,pstCurrData++) {
        pstMin30Price = pstCurrData->astMin30Price;
        ulBegin = pstMin30Price->ulBegin;
        ulHigh = pstMin30Price->ulHigh;
        ulLow = pstMin30Price->ulLow;
        ulVol = 0;
        for (j=0;j<8;j++, pstMin30Price++) {
            if (0xCCCCCCCC != pstMin30Price->ulFlag) break;
            ulHigh = (((ulHigh) > (pstMin30Price->ulHigh)) ? (ulHigh) : (pstMin30Price->ulHigh));
            ulLow = (((ulLow) < (pstMin30Price->ulLow)) ? (ulLow) : (pstMin30Price->ulLow));
            ulEnd = pstMin30Price->ulEnd;
            ulVol += pstMin30Price->ulVol;
        }
        if (0 == j) {
            printf("%lu min30 price miss!\n", pstCurrData->ulDate);
            continue;
        }
        pstDailyPrice = &(pstCurrData->stDailyPrice);
        if ((0) == CHECK_IsPriceFit(ulBegin, pstDailyPrice->ulBegin, 3))
            printf("%lu begin price not march! %lu VS %lu\n", pstCurrData->ulDate, ulBegin, pstDailyPrice->ulBegin);
        if ((0) == CHECK_IsPriceFit(ulHigh, pstDailyPrice->ulHigh, 6))
            printf("%lu high price not march! %lu VS %lu\n", pstCurrData->ulDate, ulHigh, pstDailyPrice->ulHigh);
        if ((0) == CHECK_IsPriceFit(ulLow, pstDailyPrice->ulLow, 6))
            printf("%lu low price not march! %lu VS %lu\n", pstCurrData->ulDate, ulLow, pstDailyPrice->ulLow);
        if ((0) == CHECK_IsPriceFit(ulEnd, pstDailyPrice->ulEnd, 4))
            printf("%lu end price not march! %lu VS %lu\n", pstCurrData->ulDate, ulEnd, pstDailyPrice->ulEnd);
        if ((pstDailyPrice->ulVol < ulVol-25) || (pstDailyPrice->ulVol > ulVol+10))
            printf("%lu volume not march! %lu VS %lu\n", pstCurrData->ulDate, pstDailyPrice->ulVol, ulVol);
    }
    free(astWholeData);
    return;
}

canonical_original_code:
void CHECK_CheckOne(unsigned long ulCode, unsigned long ulStartDate, char *szDir)
{
    unsigned long i; unsigned long j; unsigned long ulEntryCnt;
    unsigned long ulHigh; unsigned long ulLow; unsigned long ulBegin; unsigned long ulEnd; unsigned long ulVol;
    struct tagWholeData *astWholeData = ((void *)0);
    struct tagWholeData *pstCurrData = ((void *)0);
    struct tagWholeData *pstPrevData = ((void *)0);
    struct tagPrice *pstMin30Price = ((void *)0);
    struct tagPrice *pstDailyPrice = ((void *)0);
    ulEntryCnt = FILE_GetFileData(ulCode, szDir, 0xF0000000, (void **)&astWholeData);
    if (0 == ulEntryCnt) {
        printf("can't get data\n");
        return;
    }
    if (ulStartDate != astWholeData[0].ulDate) {
        printf("start date = %lu, data has %lu\n", ulStartDate, astWholeData[0].ulDate);
    }
    pstPrevData = astWholeData;
    pstCurrData = pstPrevData+1;
    for (i=1;i<ulEntryCnt;i++,pstPrevData++,pstCurrData++) {
        if ((0xFFFFFFFF) != pstCurrData->ulRsv) {
            printf("%lu data invalid!\n", pstCurrData->ulDate);
        }
        if (pstCurrData->ulDate <= pstPrevData->ulDate) {
            printf("%lu data reverse!\n", pstCurrData->ulDate);
        }
    }
    pstCurrData = astWholeData;
    for (i=0;i<ulEntryCnt;i++,pstCurrData++) {
        if (0xCCCCCCCC == pstCurrData->astMin30Price[0].ulFlag) {
            DebugOutString("MIN30 starts at %lu\n", pstCurrData->ulDate);
            break;
        }
    }
    for (;i<ulEntryCnt;i++,pstCurrData++) {
        pstMin30Price = pstCurrData->astMin30Price;
        ulBegin = pstMin30Price->ulBegin;
        ulHigh = pstMin30Price->ulHigh;
        ulLow = pstMin30Price->ulLow;
        ulVol = 0;
        for (j=0;j<8;j++, pstMin30Price++) {
            if (0xCCCCCCCC != pstMin30Price->ulFlag) break;
            ulHigh = (((ulHigh) > (pstMin30Price->ulHigh)) ? (ulHigh) : (pstMin30Price->ulHigh));
            ulLow = (((ulLow) < (pstMin30Price->ulLow)) ? (ulLow) : (pstMin30Price->ulLow));
            ulEnd = pstMin30Price->ulEnd;
            ulVol += pstMin30Price->ulVol;
        }
        if (0 == j) {
            printf("%lu min30 price miss!\n", pstCurrData->ulDate);
            continue;
        }
        pstDailyPrice = &(pstCurrData->stDailyPrice);
        if ((0) == CHECK_IsPriceFit(ulBegin, pstDailyPrice->ulBegin, 3))
            printf("%lu begin price not march! %lu VS %lu\n", pstCurrData->ulDate, ulBegin, pstDailyPrice->ulBegin);
        if ((0) == CHECK_IsPriceFit(ulHigh, pstDailyPrice->ulHigh, 6))
            printf("%lu high price not march! %lu VS %lu\n", pstCurrData->ulDate, ulHigh, pstDailyPrice->ulHigh);
        if ((0) == CHECK_IsPriceFit(ulLow, pstDailyPrice->ulLow, 6))
            printf("%lu low price not march! %lu VS %lu\n", pstCurrData->ulDate, ulLow, pstDailyPrice->ulLow);
        if ((0) == CHECK_IsPriceFit(ulEnd, pstDailyPrice->ulEnd, 4))
            printf("%lu end price not march! %lu VS %lu\n", pstCurrData->ulDate, ulEnd, pstDailyPrice->ulEnd);
        if ((pstDailyPrice->ulVol < ulVol-25) || (pstDailyPrice->ulVol > ulVol+10))
            printf("%lu volume not march! %lu VS %lu\n", pstCurrData->ulDate, pstDailyPrice->ulVol, ulVol);
    }
    free(astWholeData);
    return;
}

variable_types:
ulCode
unsigned long

variable_types:
ulStartDate
unsigned long

variable_types:
szDir
char *

variable_types:
j
unsigned long

variable_types:
ulEntryCnt
unsigned long

variable_types:
ulHigh
unsigned long

variable_types:
ulLow
unsigned long

variable_types:
ulBegin
unsigned long

variable_types:
ulEnd
unsigned long

variable_types:
ulVol
unsigned long

variable_types: struct tagWholeData { char szComment[16]; unsigned int ulDate; unsigned int ulRsv; struct tagPrice { unsigned int ulBegin; unsigned int ulHigh; unsigned int ulLow; unsigned int ulEnd; unsigned int ulVol; unsigned int ulFlag; } stDailyPrice; struct tagPrice astMin30Price[8]; struct tagFactor { unsigned int ulFlag; float fMulti; float fAdder; } stFactor; unsigned int ulPad; } *

variable_types: struct tagPrice { unsigned int ulBegin; unsigned int ulHigh; unsigned int ulLow; unsigned int ulEnd; unsigned int ulVol; unsigned int ulFlag; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 i; // rbx
__int64 v5; // rbp
void *ptr; // [rsp+0h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

v8[0] = 0LL;
ptr = 0LL;
if ( (unsigned int)(argc - 4) > 1 )
{
printf("USAGE: %s data-path weight-path { code | all } [debug]", *argv);
exit(1);
}
if ( !strcasecmp(argv[argc - 1], "debug") )
g_bIsDebugMode = 1;
v3 = GetCodeList(argv[3], v8);
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
if ( FILE_GetFileData(*(_QWORD *)(v8[0] + 8 * i), argv[2], 536903680LL, &ptr) )
{
v5 = FILE_QlDate2Custom(*(unsigned int *)ptr);
free(ptr);
DebugOutString("========%06lu========\n", *(_QWORD *)(v8[0] + 8 * i));
CHECK_CheckOne(*(_QWORD *)(v8[0] + 8 * i), v5, (__int64)argv[1]);
}
else
{
printf("weight of %06lu not exist!\n", *(_QWORD *)(v8[0] + 8 * i));
}
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r13
__int64 i; // rbx
__int64 v5; // rbp
void *ptr; // [rsp+0h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+8h] [rbp-30h] BYREF

v8[0] = 0LL;
ptr = 0LL;
if ( (unsigned int)(argc - 4) > 1 )
{
printf("USAGE: %s data-path weight-path { code | all } [debug]", *argv);
exit(1);
}
if ( !strcasecmp(argv[argc - 1], "debug") )
g_bIsDebugMode = 1;
v3 = GetCodeList(argv[3], v8);
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
if ( FILE_GetFileData(*(_QWORD *)(v8[0] + 8 * i), argv[2], 536903680LL, &ptr) )
{
v5 = FILE_QlDate2Custom(*(unsigned int *)ptr);
free(ptr);
DebugOutString("========%06lu========\n", *(_QWORD *)(v8[0] + 8 * i));
func1(*(_QWORD *)(v8[0] + 8 * i), v5, (__int64)argv[1]);
}
else
{
printf("weight of %06lu not exist!\n", *(_QWORD *)(v8[0] + 8 * i));
}
}
}
return 0;
}

original_code:
int main(int argc,char *argv[])
{
    ULONG i, ulCodeCnt;
    ULONG ulStartDate;
    ULONG ulWgtCnt;
    ULONG *pulCodeList = ((void *)0);
    FILE_QL_WEIGHT_ENTRY_S *astWgtData = ((void *)0);
    if ((argc < 4) || (argc > 5)) {
        printf("USAGE: %s data-path weight-path { code | all } [debug]", argv[0]);
        exit(1);
    }
    if (0 == strcasecmp(argv[argc-1], "debug"))
        g_bIsDebugMode = (1);
    ulCodeCnt = GetCodeList(argv[3], &pulCodeList);
    for (i=0;i<ulCodeCnt;i++) {
        ulWgtCnt = FILE_GetFileData(pulCodeList[i], argv[2], 0x20008000, (VOID**)&astWgtData);
        if (0 == ulWgtCnt) {
            printf("weight of %06lu not exist!\n", pulCodeList[i]);
            continue;
        }
        ulStartDate = FILE_QlDate2Custom(astWgtData[0].ulQlDate);
        free(astWgtData);
        DebugOutString("========%06lu========\n", pulCodeList[i]);
        CHECK_CheckOne(pulCodeList[i], ulStartDate, argv[1]);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long i; unsigned long ulCodeCnt;
    unsigned long ulStartDate;
    unsigned long ulWgtCnt;
    unsigned long *pulCodeList = ((void *)0);
    struct tagFileWeight *astWgtData = ((void *)0);
    if ((argc < 4) || (argc > 5)) {
        printf("USAGE: %s data-path weight-path { code | all } [debug]", argv[0]);
        exit(1);
    }
    if (0 == strcasecmp(argv[argc-1], "debug"))
        g_bIsDebugMode = (1);
    ulCodeCnt = GetCodeList(argv[3], &pulCodeList);
    for (i=0;i<ulCodeCnt;i++) {
        ulWgtCnt = FILE_GetFileData(pulCodeList[i], argv[2], 0x20008000, (void **)&astWgtData);
        if (0 == ulWgtCnt) {
            printf("weight of %06lu not exist!\n", pulCodeList[i]);
            continue;
        }
        ulStartDate = FILE_QlDate2Custom(astWgtData[0].ulQlDate);
        free(astWgtData);
        DebugOutString("========%06lu========\n", pulCodeList[i]);
        CHECK_CheckOne(pulCodeList[i], ulStartDate, argv[1]);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
i
unsigned long

variable_types:
ulCodeCnt
unsigned long

variable_types:
ulWgtCnt
unsigned long

variable_types:
pulCodeList
unsigned long *

variable_types: struct tagFileWeight { unsigned int ulQlDate; unsigned int ulGift; unsigned int ulOffer; unsigned int ulOfferPrice; unsigned int ulProfit; unsigned int ulAdd; unsigned int ulTotalStock; unsigned int ulCirStock; unsigned int ulRsv; } *


GetCodeList

decompiled_code:
__int64 __fastcall GetCodeList(char *nptr, _QWORD *a2)
{
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rax

if ( !strcasecmp(nptr, "all") )
{
*a2 = g_aulStockCode;
result = 2470LL;
}
else
{
v4 = atol(nptr);
v5 = 0LL;
while ( g_aulStockCode[v5] != v4 )
{
if ( ++v5 == 2470 )
{
DebugOutString("code %06lu not found!\n", v4);
return 0LL;
}
}
*a2 = &g_aulStockCode[v5];
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *nptr, _QWORD *a2)
{
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rax

if ( !strcasecmp(nptr, "all") )
{
*a2 = g_aulStockCode;
result = 2470LL;
}
else
{
v4 = atol(nptr);
v5 = 0LL;
while ( g_aulStockCode[v5] != v4 )
{
if ( ++v5 == 2470 )
{
DebugOutString("code %06lu not found!\n", v4);
return 0LL;
}
}
*a2 = &g_aulStockCode[v5];
result = 1LL;
}
return result;
}

original_code:
ULONG GetCodeList( CHAR* szCode, ULONG **ppulList)
{
    ULONG i;
    ULONG ulCode;
    ULONG ulCodeCnt;
    if (0 == strcasecmp(szCode, "all")) {
        ulCodeCnt = g_ulTotalCount;
        *ppulList = g_aulStockCode;
    }
    else {
        ulCode = (ULONG)atol(szCode);
        for (i=0;i<g_ulTotalCount;i++) {
            if (ulCode == g_aulStockCode[i]) break;
        }
        if (g_ulTotalCount == i) {
            ulCodeCnt = 0;
            DebugOutString("code %06lu not found!\n", ulCode);
        }
        else {
            ulCodeCnt = 1;
            *ppulList = &g_aulStockCode[i];
        }
    }
    return ulCodeCnt;
}

canonical_original_code:
unsigned long GetCodeList(char *szCode, unsigned long **ppulList)
{
    unsigned long i;
    unsigned long ulCode;
    unsigned long ulCodeCnt;
    if (0 == strcasecmp(szCode, "all")) {
        ulCodeCnt = g_ulTotalCount;
        *ppulList = g_aulStockCode;
    }
    else {
        ulCode = (unsigned long)atol(szCode);
        for (i=0;i<g_ulTotalCount;i++) {
            if (ulCode == g_aulStockCode[i]) break;
        }
        if (g_ulTotalCount == i) {
            ulCodeCnt = 0;
            DebugOutString("code %06lu not found!\n", ulCode);
        }
        else {
            ulCodeCnt = 1;
            *ppulList = &g_aulStockCode[i];
        }
    }
    return ulCodeCnt;
}

variable_types:
szCode
char *

variable_types:
ppulList
unsigned long **

variable_types:
ulCode
unsigned long

return_type: unsigned long


repo: gitson/footex

decompiled_code:
int __fastcall print_arr(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

original_code:
void print_arr(int *arr, int n) {
 int i;
 for(i = 0; i < n; i++) {
  printf("%d ", arr[i]);
 }
 printf("\n");
}

variable_types:
arr
int *

variable_types: n int

variable_types: i int


decompiled_code:
__int64 __fastcall bubble_iter(int *a1, int a2)
{
int v2; // eax
__int64 v3; // rsi
int *v4; // rbx
__int64 v5; // rdx
__int64 v6; // r8
int v8; // eax
int v9; // eax

if ( a2 <= 1 )
return 1LL;
v2 = a2 - 1;
v3 = 0LL;
while ( 1 )
{
v4 = a1;
v5 = (unsigned int)*a1++;
v6 = (unsigned int)v4[1];
if ( (int)v5 > (int)v6 )
break;
v3 = (unsigned int)(v3 + 1);
if ( (_DWORD)v3 == v2 )
return 1LL;
}
printf("Swapping arr[%d]=%d and arr[%d]=%d\n", v3, v5, (unsigned int)(v3 + 1), v6);
v8 = *a1 ^ *v4;
*v4 = v8;
v9 = *a1 ^ v8;
*a1 = v9;
*v4 ^= v9;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, int a2)
{
int v2; // eax
__int64 v3; // rsi
int *v4; // rbx
__int64 v5; // rdx
__int64 v6; // r8
int v8; // eax
int v9; // eax

if ( a2 <= 1 )
return 1LL;
v2 = a2 - 1;
v3 = 0LL;
while ( 1 )
{
v4 = a1;
v5 = (unsigned int)*a1++;
v6 = (unsigned int)v4[1];
if ( (int)v5 > (int)v6 )
break;
v3 = (unsigned int)(v3 + 1);
if ( (_DWORD)v3 == v2 )
return 1LL;
}
printf("Swapping arr[%d]=%d and arr[%d]=%d\n", v3, v5, (unsigned int)(v3 + 1), v6);
v8 = *a1 ^ *v4;
*v4 = v8;
v9 = *a1 ^ v8;
*a1 = v9;
*v4 ^= v9;
return 0LL;
}

original_code:
int bubble_iter(int *arr, int n) {
 int i;
 for(i = 0; i < n - 1; i++) {
  if(arr[i] > arr[i + 1]) {
   { printf("Swapping arr[%d]=%d and arr[%d]=%d\n", i, arr[i], i + 1, arr[i + 1]); arr[i]^=arr[i + 1];arr[i + 1]^=arr[i];arr[i]^=arr[i + 1];};
   return 0;
  }
 }
 return 1;
}


decompiled_code:
int __fastcall print_futex(_DWORD *a1)
{
bool v1; // zf
const char *v2; // rdi

v1 = *a1 == 0;
v2 = "Locked";
if ( v1 )
v2 = "Unlocked";
return puts(v2);
}

canonical_decompiled_code:
int __fastcall func9(_DWORD *a1)
{
bool v1; // zf
const char *v2; // rdi

v1 = *a1 == 0;
v2 = "Locked";
if ( v1 )
v2 = "Unlocked";
return puts(v2);
}

original_code:
void print_futex(int *futex_ptr) {
     printf("%s\n", (*futex_ptr) ? "Locked": "Unlocked");
}


repo: gittoken/pthread

decompiled_code:
void *__fastcall functionCount1(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) <= 3 )
pthread_cond_wait(&condition_cond, &condition_mutex);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount1:%d\n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) <= 3 )
pthread_cond_wait(&condition_cond, &condition_mutex);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount1:%d\n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

original_code:
void *functionCount1()
{
    for(;;)
    {
        pthread_mutex_lock(&condition_mutex);
        if(count >= 3 && count <= 6)
        {
            pthread_cond_wait(&condition_cond, &condition_mutex);
        }
        pthread_mutex_unlock(&condition_mutex);
        pthread_mutex_lock(&count_mutex);
        count++;
        printf("counter value functionCount1:%d\n", count);
        pthread_mutex_unlock(&count_mutex);
        if(count >= 10)
            return ((void *)0);
    }
}

return_type: void *


decompiled_code:
void *__fastcall functionCount2(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) > 3 )
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount2:%d \n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
do
{
pthread_mutex_lock(&condition_mutex);
if ( (unsigned int)(count - 3) > 3 )
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
pthread_mutex_lock(&count_mutex);
printf("counter value functionCount2:%d \n", (unsigned int)++count);
pthread_mutex_unlock(&count_mutex);
}
while ( count <= 9 );
return 0LL;
}

original_code:
void *functionCount2()
{
    for(;;)
    {
        pthread_mutex_lock(&condition_mutex);
        if(count < 3 || count > 6)
        {
            pthread_cond_signal(&condition_cond);
        }
        pthread_mutex_unlock(&condition_mutex);
        pthread_mutex_lock(&count_mutex);
        count++;
        printf("counter value functionCount2:%d \n", count);
        pthread_mutex_unlock(&count_mutex);
        if(count >= 10)
            return ((void *)0);
    }
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

pthread_create(newthread, 0LL, functionCount1, 0LL);
pthread_create(&th, 0LL, functionCount2, 0LL);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
    pthread_t thread1, thread2;
    pthread_create(&thread1, ((void *)0), &functionCount1, ((void *)0));
    pthread_create(&thread2, ((void *)0), &functionCount2, ((void *)0));
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long thread1; unsigned long thread2;
    pthread_create(&thread1, ((void *)0), &functionCount1, ((void *)0));
    pthread_create(&thread2, ((void *)0), &functionCount2, ((void *)0));
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
    exit(0);
}

variable_types:
argv
char **


decompiled_code:
void __fastcall __noreturn thread_function(void *a1)
{
int v1; // ebx

v1 = 3;
while ( 1 )
{
if ( !pthread_mutex_lock(&mutex) )
puts("thread lock. ");
if ( run_now == 1 )
{
puts("function thread is run. ");
run_now = 2;
pthread_mutex_lock(&condition_mutex);
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
}
else
{
puts("function thread is sleep:");
usleep(0xAu);
}
if ( !pthread_mutex_unlock(&mutex) )
puts("thread unlock. ");
if ( !--v1 )
pthread_exit(0LL);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx

v1 = 3;
while ( 1 )
{
if ( !pthread_mutex_lock(&mutex) )
puts("thread lock. ");
if ( run_now == 1 )
{
puts("function thread is run. ");
run_now = 2;
pthread_mutex_lock(&condition_mutex);
pthread_cond_signal(&condition_cond);
pthread_mutex_unlock(&condition_mutex);
}
else
{
puts("function thread is sleep:");
usleep(0xAu);
}
if ( !pthread_mutex_unlock(&mutex) )
puts("thread unlock. ");
if ( !--v1 )
pthread_exit(0LL);
}
}

original_code:
void *thread_function(void *arg)
{
    int print_count2 = 0;
    while(print_count2++ < 3)
    {
        if(pthread_mutex_lock(&mutex) == 0)
        {
            printf("thread lock. \n");
        }
        if(run_now == 1)
        {
            printf("function thread is run. \n");
            run_now = 2;
            pthread_mutex_lock(&condition_mutex);
            pthread_cond_signal(&condition_cond);
            pthread_mutex_unlock(&condition_mutex);
        }
        else
        {
            printf("function thread is sleep:\n");
            usleep(10);
        }
        if(pthread_mutex_unlock(&mutex) == 0)
        {
            printf("thread unlock. \n");
        }
    }
    pthread_exit(((void *)0));
}

variable_types:
arg
void *


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = 2;
if ( pthread_create(newthread, 0LL, (void *(*)(void *))thread_function, 0LL) )
{
perror("thread creation failed.\n");
exit(1);
}
while ( 1 )
{
pthread_mutex_lock(&condition_mutex);
puts("main cond_mutex lock. ");
pthread_cond_wait(&condition_cond, &condition_mutex);
pthread_mutex_unlock(&condition_mutex);
puts("main cond_mutex unlock. ");
if ( !pthread_mutex_lock(&mutex) )
puts("main lock. ");
if ( run_now == 2 )
{
puts("main thread is run .");
run_now = 1;
}
else
{
puts("main thread is sleep");
usleep(0xAu);
}
if ( !pthread_mutex_unlock(&mutex) )
puts("main unlock. ");
if ( !--v3 )
{
pthread_mutex_destroy(&mutex);
pthread_join(newthread[0], 0LL);
exit(0);
}
}
}

original_code:
int main(int argc, char **argv)
{
    int print_count1 = 0;
    pthread_t a_thread;
    if(pthread_create(&a_thread, ((void *)0), thread_function, ((void *)0)) != 0 )
    {
        perror("thread creation failed.\n");
        exit(1);
    }
    while(print_count1++ < 2)
    {
        pthread_mutex_lock(&condition_mutex);
        printf("main cond_mutex lock. \n");
        pthread_cond_wait(&condition_cond, &condition_mutex);
        pthread_mutex_unlock(&condition_mutex);
        printf("main cond_mutex unlock. \n");
        if(pthread_mutex_lock(&mutex) == 0)
        {
            printf("main lock. \n");
        }
        if(run_now == 2)
        {
            printf("main thread is run .\n");
           run_now = 1;
        }
        else
        {
            printf("main thread is sleep\n");
            usleep(10);
        }
        if(pthread_mutex_unlock(&mutex) == 0)
        {
            printf("main unlock. \n");
        }
    }
    pthread_mutex_destroy(&mutex);
    pthread_join(a_thread, ((void *)0));
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int print_count1 = 0;
    unsigned long a_thread;
    if(pthread_create(&a_thread, ((void *)0), thread_function, ((void *)0)) != 0 )
    {
        perror("thread creation failed.\n");
        exit(1);
    }
    while(print_count1++ < 2)
    {
        pthread_mutex_lock(&condition_mutex);
        printf("main cond_mutex lock. \n");
        pthread_cond_wait(&condition_cond, &condition_mutex);
        pthread_mutex_unlock(&condition_mutex);
        printf("main cond_mutex unlock. \n");
        if(pthread_mutex_lock(&mutex) == 0)
        {
            printf("main lock. \n");
        }
        if(run_now == 2)
        {
            printf("main thread is run .\n");
           run_now = 1;
        }
        else
        {
            printf("main thread is sleep\n");
            usleep(10);
        }
        if(pthread_mutex_unlock(&mutex) == 0)
        {
            printf("main unlock. \n");
        }
    }
    pthread_mutex_destroy(&mutex);
    pthread_join(a_thread, ((void *)0));
    exit(0);
}


decompiled_code:
int __fastcall function_count(void *a1)
{
pthread_t v1; // rbp
int v2; // ebx

pthread_mutex_lock(&mutex1);
v1 = pthread_self();
v2 = 4;
do
{
++counter;
printf("pid:%ld ", v1);
printf("counter value:%d\n", (unsigned int)counter);
--v2;
}
while ( v2 );
return pthread_mutex_unlock(&mutex1);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
pthread_t v1; // rbp
int v2; // ebx

pthread_mutex_lock(&mutex1);
v1 = pthread_self();
v2 = 4;
do
{
++counter;
printf("pid:%ld ", v1);
printf("counter value:%d\n", (unsigned int)counter);
--v2;
}
while ( v2 );
return pthread_mutex_unlock(&mutex1);
}

original_code:
void *function_count(void)
{
    int i;
    pthread_mutex_lock(&mutex1);
    for(i=0;i<4;i++)
    {
        counter++;
        printf("pid:%ld ", pthread_self());
        printf("counter value:%d\n", counter);
    }
    pthread_mutex_unlock(&mutex1);
}

canonical_original_code:
void *function_count()
{
    int i;
    pthread_mutex_lock(&mutex1);
    for(i=0;i<4;i++)
    {
        counter++;
        printf("pid:%ld ", pthread_self());
        printf("counter value:%d\n", counter);
    }
    pthread_mutex_unlock(&mutex1);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
pthread_t th; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = pthread_create(newthread, 0LL, (void *(*)(void *))function_count, 0LL);
if ( v3 )
printf("thread creation failed:%d\n", v3);
v4 = pthread_create(&th, 0LL, (void *(*)(void *))function_count, 0LL);
if ( v4 )
printf("thread creation failed:%d\n", v4);
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    int rc1, rc2;
    pthread_t thread1, thread2;
    if(rc1 = pthread_create(&thread1, ((void *)0), (void*) function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc1);
    }
    if(rc2 = pthread_create(&thread2, ((void *)0), (void *)function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc2);
    }
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
}

canonical_original_code:
int main(int argc, char **argv)
{
    int rc1; int rc2;
    unsigned long thread1; unsigned long thread2;
    if(rc1 = pthread_create(&thread1, ((void *)0), (void *) function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc1);
    }
    if(rc2 = pthread_create(&thread2, ((void *)0), (void *)function_count, ((void *)0)))
    {
        printf("thread creation failed:%d\n", rc2);
    }
    pthread_join(thread1, ((void *)0));
    pthread_join(thread2, ((void *)0));
}


decompiled_code:
char *__fastcall get_ext(const char *a1)
{
char *v1; // rax

v1 = strrchr(a1, 46);
if ( !v1 )
exit(1);
return strdup(v1 + 1);
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
char *v1; // rax

v1 = strrchr(a1, 46);
if ( !v1 )
exit(1);
return strdup(v1 + 1);
}

original_code:
char *get_ext(const char *path)
{
  char *dot_addr = strrchr(path, '.');
  if(!dot_addr)
    exit(1);
  return strdup(++dot_addr);
}

canonical_original_code:
char *get_ext(char *path)
{
  char *dot_addr = strrchr(path, '.');
  if(!dot_addr)
    exit(1);
  return strdup(++dot_addr);
}

variable_types:
path
char *

return_type: char *


decompiled_code:
__int64 __fastcall in_array(char *s1, const char **a2)
{
const char **v2; // rbx
const char *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( strcasecmp(s1, v3) )
{
v3 = *++v2;
if ( !*v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, const char **a2)
{
const char **v2; // rbx
const char *v3; // rsi

v2 = a2;
v3 = *a2;
if ( !v3 )
return 0LL;
while ( strcasecmp(s1, v3) )
{
v3 = *++v2;
if ( !*v2 )
return 0LL;
}
return 1LL;
}

original_code:
int in_array(const char *str, const char **array)
{
  while (*array != ((void *)0))
  {
    if (strcasecmp(str, *array) == 0) return 1;
    array++;
  }
  return 0;
}

canonical_original_code:
int in_array(char *str, char **array)
{
  while (*array != ((void *)0))
  {
    if (strcasecmp(str, *array) == 0) return 1;
    array++;
  }
  return 0;
}

variable_types:
str
char *

variable_types:
array
char **


repo: gkhighelf/OpenRelayScaner

decompiled_code:
__int64 __fastcall lookup_host(const char *a1, char *a2)
{
char *v2; // r12
unsigned int v3; // ebx
int v4; // edi
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 2LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, 0LL, &req, &pai) )
return (unsigned int)-1;
v3 = 0;
v4 = pai->ai_family;
if ( v4 == 2 )
{
v2 = &pai->ai_addr->sa_data[2];
}
else if ( v4 == 10 )
{
v2 = &pai->ai_addr->sa_data[6];
}
inet_ntop(v4, v2, a2, 0x100u);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, char *a2)
{
char *v2; // r12
unsigned int v3; // ebx
int v4; // edi
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 2LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, 0LL, &req, &pai) )
return (unsigned int)-1;
v3 = 0;
v4 = pai->ai_family;
if ( v4 == 2 )
{
v2 = &pai->ai_addr->sa_data[2];
}
else if ( v4 == 10 )
{
v2 = &pai->ai_addr->sa_data[6];
}
inet_ntop(v4, v2, a2, 0x100u);
return v3;
}

original_code:
int lookup_host (const char *host, char *ret )
{
    struct addrinfo hints, *res;
    int errcode;
    void *ptr;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags |= 0x0002;
    errcode = getaddrinfo (host, ((void *)0), &hints, &res);
    if (errcode != 0)
    {
        return -1;
    }
        switch (res->ai_family)
        {
            case 2:
                ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
                break;
            case 10:
                ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
                break;
        }
        inet_ntop(res->ai_family, ptr, ret, 256);
    return 0;
}

canonical_original_code:
int lookup_host(char *host, char *ret)
{
    struct addrinfo hints; struct addrinfo *res;
    int errcode;
    void *ptr;
    memset(&hints, 0, sizeof (hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags |= 0x0002;
    errcode = getaddrinfo (host, ((void *)0), &hints, &res);
    if (errcode != 0)
    {
        return -1;
    }
        switch (res->ai_family)
        {
            case 2:
                ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
                break;
            case 10:
                ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
                break;
        }
        inet_ntop(res->ai_family, ptr, ret, 256);
    return 0;
}

variable_types:
host
char *

variable_types:
ret
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: errcode int

variable_types:
ptr
void *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
int __fastcall resolv_host(char *name, char *dest)
{
struct hostent *v2; // rbx
int *v4; // rbp
const char *v5; // rax
__int64 v6; // rsi
signed int v7; // eax
int result; // eax

do
{
v2->h_name = 0LL;
v2 = gethostbyname(name);
v4 = _h_errno_location();
v5 = hstrerror(*v4);
puts(v5);
v6 = (unsigned int)*v4;
}
while ( (_DWORD)v6 == 2 );
if ( v2 )
{
v7 = (unsigned int)inet_ntoa((struct in_addr)(*(struct in_addr **)v2->h_addr_list)->s_addr);
result = (unsigned int)strcpy(dest, (const char *)v7);
}
else
{
result = printf("Error %d resolving host %s\n", v6, name);
*dest = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(char *name, char *dest)
{
struct hostent *v2; // rbx
int *v4; // rbp
const char *v5; // rax
__int64 v6; // rsi
signed int v7; // eax
int result; // eax

do
{
v2->h_name = 0LL;
v2 = gethostbyname(name);
v4 = _h_errno_location();
v5 = hstrerror(*v4);
puts(v5);
v6 = (unsigned int)*v4;
}
while ( (_DWORD)v6 == 2 );
if ( v2 )
{
v7 = (unsigned int)inet_ntoa((struct in_addr)(*(struct in_addr **)v2->h_addr_list)->s_addr);
result = (unsigned int)strcpy(dest, (const char *)v7);
}
else
{
result = printf("Error %d resolving host %s\n", v6, name);
*dest = 0;
}
return result;
}

original_code:
void resolv_host( char *host, char *res )
{
    struct hostent *pp, *gethostbyname();
    for(;;)
    {
        memset( pp, 0, sizeof( pp ) );
        pp = gethostbyname( host );
        printf( "%s\n", hstrerror( (*__h_errno_location ()) ) );
        if( (*__h_errno_location ()) == 2 ) continue;
        else break;
    }
    if( pp == (struct hostent*) 0 )
    {
        printf( "Error %d resolving host %s\n", (*__h_errno_location ()), host );
        res[0] = 0x0;
        return;
    }
    sprintf( res, "%s", (char*)inet_ntoa( *(struct in_addr*)( pp->h_addr_list[0] ) ) );
}

canonical_original_code:
void resolv_host(char *host, char *res)
{
    struct hostent *pp; struct hostent *gethostbyname();
    for(;;)
    {
        memset( pp, 0, sizeof( pp ) );
        pp = gethostbyname( host );
        printf( "%s\n", hstrerror( (*__h_errno_location ()) ) );
        if( (*__h_errno_location ()) == 2 ) continue;
        else break;
    }
    if( pp == (struct hostent *) 0 )
    {
        printf( "Error %d resolving host %s\n", (*__h_errno_location ()), host );
        res[0] = 0x0;
        return;
    }
    sprintf( res, "%s", (char *)inet_ntoa( *(struct in_addr *)( pp->h_addr_list[0] ) ) );
}

variable_types:
res
char *

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


repo: glennklockwood/simulate

original_code:
void calculate_new_forces
(
    sim_params_t *simulation_parameters,
    system_info_t *system_info,
    atom_list_t *atoms
)
{
    neighbor_list_verlet_t *neighbors;
    double *restrict pos = atoms->pos,
           *restrict force = atoms->force,
           *restrict stress = atoms->stress;
    double boxl2[3];
    for ( int i = 0; i < 3; i++ )
        boxl2[i] = 2.0*system_info->boxli[i];
    neighbors = construct_neighbor_list( system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        double pos_i[3];
        for ( int k = 0; k < 3; k++ )
            pos_i[k] = pos[(i)*3 +(k)];
        for ( int m = neighbors->nlb[i]; m < neighbors->nle[i]; m++ )
        {
            double rij2 = 0.0;
            double potential_mag, force_mag;
            double rij[3],
                   fij[3];
            int j;
            j = neighbors->nlist[m];
            for ( int k = 0; k < 3; k++ )
            {
                int mx;
                rij[k] = pos[(j)*3 +(k)] - pos_i[k];
                mx = (int)(rij[k] * boxl2[k]);
                rij[k] -= (double)mx * system_info->boxl[k];
            }
            for ( int k = 0; k < 3; k++ )
                rij2 += rij[k]*rij[k];
            if ( sqrt(rij2) > system_info->boxl[0] )
            {
                fprintf( stderr, "Interatomic spacing is larger than box!\n" );
                exit(1);
            }
            simulation_parameters->calculate_2body(
                atoms->type[i],
                atoms->type[j],
                rij2,
                simulation_parameters,
                &potential_mag,
                &force_mag);
            fprintf(stderr, "Interaction at %15g is %15g erg, %15g dyne\n",
                sqrt(rij2), potential_mag, force_mag * sqrt(rij2));
            for ( int k = 0; k < 3; k++ )
            {
                fij[k] = rij[k] * force_mag;
                force[(i)*3 +(k)] += fij[k];
                force[(j)*3 +(k)] -= fij[k];
                stress[k] += fij[k] * rij[k];
            }
        }
    }
    return;
}

canonical_original_code:
void calculate_new_forces(struct sim_params *simulation_parameters, struct system_info *system_info, struct atom_list *atoms)
{
    struct neighbor_list_verlet *neighbors;
    double *pos = atoms->pos; double *force = atoms->force; double *stress = atoms->stress;
    double boxl2[3];
    for ( int i = 0; i < 3; i++ )
        boxl2[i] = 2.0*system_info->boxli[i];
    neighbors = construct_neighbor_list( system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        double pos_i[3];
        for ( int k = 0; k < 3; k++ )
            pos_i[k] = pos[(i)*3 +(k)];
        for ( int m = neighbors->nlb[i]; m < neighbors->nle[i]; m++ )
        {
            double rij2 = 0.0;
            double potential_mag; double force_mag;
            double rij[3]; double fij[3];
            int j;
            j = neighbors->nlist[m];
            for ( int k = 0; k < 3; k++ )
            {
                int mx;
                rij[k] = pos[(j)*3 +(k)] - pos_i[k];
                mx = (int)(rij[k] * boxl2[k]);
                rij[k] -= (double)mx * system_info->boxl[k];
            }
            for ( int k = 0; k < 3; k++ )
                rij2 += rij[k]*rij[k];
            if ( sqrt(rij2) > system_info->boxl[0] )
            {
                fprintf( stderr, "Interatomic spacing is larger than box!\n" );
                exit(1);
            }
            simulation_parameters->calculate_2body(
                atoms->type[i],
                atoms->type[j],
                rij2,
                simulation_parameters,
                &potential_mag,
                &force_mag);
            fprintf(stderr, "Interaction at %15g is %15g erg, %15g dyne\n",
                sqrt(rij2), potential_mag, force_mag * sqrt(rij2));
            for ( int k = 0; k < 3; k++ )
            {
                fij[k] = rij[k] * force_mag;
                force[(i)*3 +(k)] += fij[k];
                force[(j)*3 +(k)] -= fij[k];
                stress[k] += fij[k] * rij[k];
            }
        }
    }
    return;
}

variable_types: struct sim_params { int num_types; int *ltype; double timestep; double *mass; double *time_over_mass; double **pair_param; void (*calculate_2body)(int, int, double, struct sim_params *, double *, double *); void (*calculate_3body)(int, int, int, double, double, struct sim_params *, double *, double *); } *

variable_types: struct system_info { double boxl[3]; double boxli[3]; } *

variable_types: struct atom_list { unsigned int count; unsigned int *index; unsigned int *type; double *pos; double *stress; } *

variable_types: struct neighbor_list_verlet { int *nlb; int *nle; int *nlist; } *

variable_types:
pos
double *

variable_types:
force
double *

variable_types:
stress
double *

variable_types: k int

variable_types: m int

variable_types:
rij
double [3]

variable_types:
fij
double [3]

variable_types: j int

variable_types: mx int


original_code:
void pair_lj
(
    int itype,
    int jtype,
    double rij2,
    sim_params_t *simulation_parameters,
    double *potential_mag,
    double *force_mag
)
{
    double rij6;
    double rij12;
    double epsilon4, sigma, sigma12, sigma6;
    double part1, part2;
    int kt = (itype)*(simulation_parameters->num_types) - (itype)*((itype)+1)/2 + (jtype);
    rij6 = rij2*rij2*rij2;
    rij12 = rij6*rij6;
    epsilon4= 4.0 * simulation_parameters->pair_param[kt][0];
    sigma = simulation_parameters->pair_param[kt][1];
    sigma6 = sigma*sigma*sigma;
    sigma6 *= sigma6;
    sigma12 = sigma6*sigma6;
    part1 = epsilon4 * sigma12 / rij12;
    part2 = epsilon4 * sigma6 / rij6;
    *potential_mag = part1 - part2;
    *force_mag = part2 - 2.0*part1;
    *force_mag *= 6.0 / sqrt(rij2);
    return;
}

canonical_original_code:
void pair_lj(int itype, int jtype, double rij2, struct sim_params *simulation_parameters, double *potential_mag, double *force_mag)
{
    double rij6;
    double rij12;
    double epsilon4; double sigma; double sigma12; double sigma6;
    double part1; double part2;
    int kt = (itype)*(simulation_parameters->num_types) - (itype)*((itype)+1)/2 + (jtype);
    rij6 = rij2*rij2*rij2;
    rij12 = rij6*rij6;
    epsilon4= 4.0 * simulation_parameters->pair_param[kt][0];
    sigma = simulation_parameters->pair_param[kt][1];
    sigma6 = sigma*sigma*sigma;
    sigma6 *= sigma6;
    sigma12 = sigma6*sigma6;
    part1 = epsilon4 * sigma12 / rij12;
    part2 = epsilon4 * sigma6 / rij6;
    *potential_mag = part1 - part2;
    *force_mag = part2 - 2.0*part1;
    *force_mag *= 6.0 / sqrt(rij2);
    return;
}

variable_types: itype int

variable_types: jtype int

variable_types: sigma double

variable_types: kt int

user_defined_types: struct sim_params { int num_types; int *ltype; double timestep; double *mass; double *time_over_mass; double **pair_param; void (*calculate_2body)(int, int, double, struct sim_params *, double *, double *); void (*calculate_3body)(int, int, int, double, double, struct sim_params *, double *, double *); }


decompiled_code:
void __fastcall __noreturn dump_table(__int64 a1)
{
int v1; // ebx
double v2; // [rsp+8h] [rbp-30h]
double v3; // [rsp+10h] [rbp-28h] BYREF
double v4[4]; // [rsp+18h] [rbp-20h] BYREF

v1 = 96;
v2 = *(double *)&LC3;
do
{
(*(void (__fastcall **)(_QWORD, _QWORD, __int64, double *, double *, double))(a1 + 48))(
0LL,
0LL,
a1,
&v3,
v4,
v2 * v2);
printf("%15.8g %15.8g %15.8g\n", v2, v3, v2 * v4[0]);
v2 = v2 + 0.000000001;
--v1;
}
while ( v1 );
exit(0);
}

original_code:
void dump_table( sim_params_t *simulation_parameters )
{
    double r0;
    double dx = 0.10e-08;
    r0 = 0.5e-08;
    while ( r0 < 10e-08 )
    {
        double potential_mag, force_mag;
        simulation_parameters->calculate_2body(
            0, 0, r0*r0,
            simulation_parameters,
            &potential_mag,
            &force_mag);
        printf( "%15.8g %15.8g %15.8g\n",
            r0, potential_mag, force_mag*r0 );
        r0 += dx;
    }
    exit(0);
    return;
}

canonical_original_code:
void dump_table(struct sim_params *simulation_parameters)
{
    double r0;
    double dx = 0.10e-08;
    r0 = 0.5e-08;
    while ( r0 < 10e-08 )
    {
        double potential_mag; double force_mag;
        simulation_parameters->calculate_2body(
            0, 0, r0*r0,
            simulation_parameters,
            &potential_mag,
            &force_mag);
        printf( "%15.8g %15.8g %15.8g\n",
            r0, potential_mag, force_mag*r0 );
        r0 += dx;
    }
    exit(0);
    return;
}

variable_types: struct sim_params { int num_types; int *ltype; double timestep; double *mass; double *time_over_mass; double **pair_param; void (*calculate_2body)(int, int, double, struct sim_params *, double *, double *); void (*calculate_3body)(int, int, int, double, double, struct sim_params *, double *, double *); } *

variable_types: dx double


decompiled_code:
void *create_link_cell()
{
if ( cell_list_0 )
free(cell_list_0);
cell_list_0 = malloc(0x38uLL);
if ( !cell_list_0 )
malloc_error();
return cell_list_0;
}

canonical_decompiled_code:
void *func0()
{
if ( cell_list_0 )
free(cell_list_0);
cell_list_0 = malloc(0x38uLL);
if ( !cell_list_0 )
malloc_error();
return cell_list_0;
}

original_code:
cell_map_t *create_link_cell( system_info_t *system_info, atom_list_t *atoms )
{
    static cell_map_t *cell_list;
    if ( cell_list )
    {
        free(cell_list);
    }
    cell_list = malloc(sizeof(*cell_list));
    if (!cell_list)
        malloc_error();
    return cell_list;
}

canonical_original_code:
struct cell_map *create_link_cell(struct system_info *system_info, struct atom_list *atoms)
{
    static struct cell_map *cell_list;
    if ( cell_list )
    {
        free(cell_list);
    }
    cell_list = malloc(sizeof(*cell_list));
    if (!cell_list)
        malloc_error();
    return cell_list;
}

variable_types: struct system_info { double boxl[3]; double boxli[3]; } *

variable_types: struct atom_list { unsigned int count; unsigned int *index; unsigned int *type; double *pos; double *stress; } *

variable_types: struct cell_map { double lcell[3]; int ncell; int *lhead; int *llist; int *map; } *


original_code:
void next_iteration
(
    sim_params_t *simulation_parameters,
    system_info_t *system_info,
    atom_list_t *atoms
)
{
    double *restrict pos = atoms->pos,
           *restrict vel = atoms->vel,
           *restrict accel = atoms->accel,
           *restrict force = atoms->force,
           *restrict inv_mass = simulation_parameters->time_over_mass,
           *restrict boxl = system_info->boxl,
           *restrict boxli = system_info->boxli;
    for ( int i = 0; i < atoms->count; i++ )
    {
        double displacement = 0.0;
        for ( int j = 0; j < 3; j++ )
        {
            double t;
            int m, n;
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
            pos[(i)*3 +(j)] += vel[(i)*3 +(j)];
            displacement += vel[(i)*3 +(j)] * vel[(i)*3 +(j)];
            t = pos[(i)*3 +(j)] * boxli[j];
            m = (int)t;
            n = (int)(t - 1.0);
            pos[(i)*3 +(j)] = (t - (double)(m + n)) * boxl[j];
        }
    }
    calculate_new_forces( simulation_parameters, system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        for ( int j = 0; j < 3; j++ )
        {
            accel[(i)*3 +(j)] = force[(i)*3 +(j)]
                * inv_mass[atoms->type[i]];
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
        }
    }
    return;
}

canonical_original_code:
void next_iteration(struct sim_params *simulation_parameters, struct system_info *system_info, struct atom_list *atoms)
{
    double *pos = atoms->pos; double *vel = atoms->vel; double *accel = atoms->accel; double *force = atoms->force; double *inv_mass = simulation_parameters->time_over_mass; double *boxl = system_info->boxl; double *boxli = system_info->boxli;
    for ( int i = 0; i < atoms->count; i++ )
    {
        double displacement = 0.0;
        for ( int j = 0; j < 3; j++ )
        {
            double t;
            int m; int n;
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
            pos[(i)*3 +(j)] += vel[(i)*3 +(j)];
            displacement += vel[(i)*3 +(j)] * vel[(i)*3 +(j)];
            t = pos[(i)*3 +(j)] * boxli[j];
            m = (int)t;
            n = (int)(t - 1.0);
            pos[(i)*3 +(j)] = (t - (double)(m + n)) * boxl[j];
        }
    }
    calculate_new_forces( simulation_parameters, system_info, atoms );
    for ( int i = 0; i < atoms->count; i++ )
    {
        for ( int j = 0; j < 3; j++ )
        {
            accel[(i)*3 +(j)] = force[(i)*3 +(j)]
                * inv_mass[atoms->type[i]];
            vel[(i)*3 +(j)] += accel[(i)*3 +(j)];
        }
    }
    return;
}

variable_types:
pos
double *

variable_types:
vel
double *

variable_types:
accel
double *

variable_types:
force
double *

variable_types:
boxl
double *

variable_types:
boxli
double *

variable_types: i int

variable_types: displacement double

variable_types: t double

variable_types: n int

user_defined_types: struct system_info { double boxl[3]; double boxli[3]; }

user_defined_types: struct atom_list { unsigned int count; unsigned int *index; unsigned int *type; double *pos; double *stress; }


repo: glguida/libhacktm-old

decompiled_code:
__int64 __fastcall synapse_init_random(_QWORD *a1, __int64 a2, unsigned __int64 a3)
{
void *v4; // rax
__int64 v5; // rbp
_QWORD *v6; // rbx
_BYTE v8[72]; // [rsp+0h] [rbp-48h] BYREF

*a1 = 0LL;
bitar_init(v8, (a3 >> 6) + 1);
v4 = malloc(16 * a2);
a1[1] = v4;
if ( !v4 )
_assert_fail("(s->wconn) != NULL", "components.c", 0x2Cu, "synapse_init_random");
v5 = 0LL;
if ( a2 )
{
do
{
*(_QWORD *)(a1[1] + 16 * v5 + 8) = 0LL;
v6 = (_QWORD *)(a1[1] + 16 * v5);
*v6 = bitar_setrandomid_range(v8, a3);
++v5;
}
while ( a2 != v5 );
}
return bitar_fini(v8);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, unsigned __int64 a3)
{
void *v4; // rax
__int64 v5; // rbp
_QWORD *v6; // rbx
_BYTE v8[72]; // [rsp+0h] [rbp-48h] BYREF

*a1 = 0LL;
bitar_init(v8, (a3 >> 6) + 1);
v4 = malloc(16 * a2);
a1[1] = v4;
if ( !v4 )
_assert_fail("(s->wconn) != NULL", "components.c", 0x2Cu, "synapse_init_random");
v5 = 0LL;
if ( a2 )
{
do
{
*(_QWORD *)(a1[1] + 16 * v5 + 8) = 0LL;
v6 = (_QWORD *)(a1[1] + 16 * v5);
*v6 = bitar_setrandomid_range(v8, a3);
++v5;
}
while ( a2 != v5 );
}
return bitar_fini(v8);
}

original_code:
void
synapse_init_random(struct synapse *s, size_t wconns, size_t ndest)
{
  size_t i;
  bitar_t tmp;
  s->totcount = 0;
  bitar_init(&tmp, ndest/64 + 1);
  s->wconn = malloc(sizeof(struct wconn) * wconns);
  ((void) sizeof (((s->wconn) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((s->wconn) != ((void *)0)) ; else __assert_fail ("(s->wconn) != NULL", "components.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < wconns; i++ ) {
    s->wconn[i].count = 0;
    s->wconn[i].id = bitar_setrandomid_range(&tmp, ndest);
  }
  bitar_fini(&tmp);
}

canonical_original_code:
void synapse_init_random(struct synapse *s, unsigned long wconns, unsigned long ndest)
{
  unsigned long i;
  struct bitar tmp;
  s->totcount = 0;
  bitar_init(&tmp, ndest/64 + 1);
  s->wconn = malloc(sizeof(struct wconn) * wconns);
  ((void) sizeof (((s->wconn) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((s->wconn) != ((void *)0)) ; else __assert_fail ("(s->wconn) != NULL", "components.c", 44, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < wconns; i++ ) {
    s->wconn[i].count = 0;
    s->wconn[i].id = bitar_setrandomid_range(&tmp, ndest);
  }
  bitar_fini(&tmp);
}

variable_types: struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *

variable_types:
wconns
unsigned long

variable_types:
ndest
unsigned long

variable_types:
i
unsigned long

variable_types: struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; }

user_defined_types: struct synapse { unsigned long totcount; struct wconn *wconn; }


decompiled_code:
unsigned __int64 __fastcall synapse_predict(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 i; // rbx
_QWORD *v6; // rcx
unsigned __int64 result; // rax

if ( *a1 && a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v6 = (_QWORD *)(a1[1] + 16 * i);
result = (unsigned __int64)(10LL * v6[1]) / *a1;
if ( result > 7 )
result = bitar_set(a4, *v6, (unsigned __int64)(10LL * v6[1]) % *a1);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 i; // rbx
_QWORD *v6; // rcx
unsigned __int64 result; // rax

if ( *a1 && a2 )
{
for ( i = 0LL; i != a2; ++i )
{
v6 = (_QWORD *)(a1[1] + 16 * i);
result = (unsigned __int64)(10LL * v6[1]) / *a1;
if ( result > 7 )
result = bitar_set(a4, *v6, (unsigned __int64)(10LL * v6[1]) % *a1);
}
}
return result;
}

original_code:
void
synapse_predict(struct synapse *s, size_t wconns, bitar_t *src, bitar_t *dst)
{
  size_t i;
  if ( s->totcount == 0 )
    return;
  for ( i = 0; i < wconns; i++ ) {
    if ( ((s->wconn[i].count * 10) / s->totcount) > 7 )
      bitar_set(dst, s->wconn[i].id);
  }
}

canonical_original_code:
void synapse_predict(struct synapse *s, unsigned long wconns, struct bitar *src, struct bitar *dst)
{
  unsigned long i;
  if ( s->totcount == 0 )
    return;
  for ( i = 0; i < wconns; i++ ) {
    if ( ((s->wconn[i].count * 10) / s->totcount) > 7 )
      bitar_set(dst, s->wconn[i].id);
  }
}

variable_types: struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } *

variable_types:
dst
struct bitar *

user_defined_types: struct wconn { unsigned long id; unsigned long count; }


original_code:
void
synapse_dump(struct synapse *s, size_t wconns)
{
  size_t i;
  for ( i = 0; i < wconns; i++ ) {
    if ( s->wconn[i].count == 0 )
      continue;
    printf("%lu:%lu/%lu\t", s->wconn[i].id, s->wconn[i].count, s->totcount);
  }
}

canonical_original_code:
void synapse_dump(struct synapse *s, unsigned long wconns)
{
  unsigned long i;
  for ( i = 0; i < wconns; i++ ) {
    if ( s->wconn[i].count == 0 )
      continue;
    printf("%lu:%lu/%lu\t", s->wconn[i].id, s->wconn[i].count, s->totcount);
  }
}


decompiled_code:
__int64 __fastcall synarray_init_sub(_QWORD *a1, __int64 a2, unsigned __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v7; // rbx

*a1 = a2;
a1[1] = a4;
result = (__int64)malloc(16 * a2);
a1[2] = result;
if ( !result )
_assert_fail("(sa->array) != NULL", "components.c", 0x72u, "synarray_init_sub");
v7 = 0LL;
if ( a2 )
{
do
result = synapse_init_random((_QWORD *)(a1[2] + 16 * v7++), a4, a3);
while ( a2 != v7 );
}
return result;
}

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

*a1 = a2;
a1[1] = a4;
result = (__int64)malloc(16 * a2);
a1[2] = result;
if ( !result )
_assert_fail("(sa->array) != NULL", "components.c", 0x72u, "synarray_init_sub");
v7 = 0LL;
if ( a2 )
{
do
result = func0((_QWORD *)(a1[2] + 16 * v7++), a4, a3);
while ( a2 != v7 );
}
return result;
}

original_code:
void
synarray_init_sub(struct synar *sa, size_t syns, size_t dest, size_t wconns)
{
  size_t i;
  sa->syns = syns;
  sa->wconns = wconns;
  sa->array = malloc(sizeof(struct synapse) * syns);
  ((void) sizeof (((sa->array) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((sa->array) != ((void *)0)) ; else __assert_fail ("(sa->array) != NULL", "components.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < syns; i++ )
    synapse_init_random(sa->array + i, wconns, dest);
}

canonical_original_code:
void synarray_init_sub(struct synar *sa, unsigned long syns, unsigned long dest, unsigned long wconns)
{
  unsigned long i;
  sa->syns = syns;
  sa->wconns = wconns;
  sa->array = malloc(sizeof(struct synapse) * syns);
  ((void) sizeof (((sa->array) != ((void *)0)) ? 1 : 0), __extension__ ({ if ((sa->array) != ((void *)0)) ; else __assert_fail ("(sa->array) != NULL", "components.c", 114, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < syns; i++ )
    synapse_init_random(sa->array + i, wconns, dest);
}

variable_types: struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } *

variable_types:
syns
unsigned long

variable_types:
dest
unsigned long

user_defined_types: struct synar { unsigned long syns; unsigned long wconns; struct synapse *array; }


decompiled_code:
unsigned __int64 __fastcall synarray_learn(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
result = *(_QWORD *)(a2 + 8) << 6;
if ( result != *a1 )
_assert_fail("syns == bitar_bitsize(prev)", "components.c", 0x8Cu, "synarray_learn");
for ( i = 0LL; result > i; result = *(_QWORD *)(a2 + 8) << 6 )
{
if ( (unsigned int)bitar_get(a2, i) )
synapse_learn((_QWORD *)(a1[2] + 16 * i), v3, a3);
++i;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
result = *(_QWORD *)(a2 + 8) << 6;
if ( result != *a1 )
_assert_fail("syns == bitar_bitsize(prev)", "components.c", 0x8Cu, "synarray_learn");
for ( i = 0LL; result > i; result = *(_QWORD *)(a2 + 8) << 6 )
{
if ( (unsigned int)bitar_get(a2, i) )
func2((_QWORD *)(a1[2] + 16 * i), v3, a3);
++i;
}
return result;
}

original_code:
void
synarray_learn(struct synar *sa, bitar_t *prev, bitar_t *cur)
{
  size_t i;
  const size_t syns = (const size_t)sa->syns;
  const size_t wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((prev)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((prev)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(prev)", "components.c", 140, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < ((prev)->map_size * 64); i++ )
    if ( bitar_get(prev, i) )
      synapse_learn(sa->array + i, wconns, cur);
}

canonical_original_code:
void synarray_learn(struct synar *sa, struct bitar *prev, struct bitar *cur)
{
  unsigned long i;
  unsigned long syns = (const size_t)sa->syns;
  unsigned long wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((prev)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((prev)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(prev)", "components.c", 140, __extension__ __PRETTY_FUNCTION__); }));
  for ( i = 0; i < ((prev)->map_size * 64); i++ )
    if ( bitar_get(prev, i) )
      synapse_learn(sa->array + i, wconns, cur);
}

variable_types:
cur
struct bitar *

user_defined_types: struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; }


decompiled_code:
unsigned __int64 __fastcall synarray_predict(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
if ( *(_QWORD *)(a2 + 8) << 6 != *a1 )
_assert_fail("syns == bitar_bitsize(cur)", "components.c", 0x9Au, "synarray_predict");
bitar_reset(a3);
result = *(_QWORD *)(a2 + 8) << 6;
if ( result )
{
for ( i = 0LL; i < result; ++i )
{
if ( (unsigned int)bitar_get(a2, i) )
synapse_predict((_QWORD *)(a1[2] + 16 * i), v3, a2, a3);
result = *(_QWORD *)(a2 + 8) << 6;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
unsigned __int64 result; // rax
unsigned __int64 i; // rbx

v3 = a1[1];
if ( *(_QWORD *)(a2 + 8) << 6 != *a1 )
_assert_fail("syns == bitar_bitsize(cur)", "components.c", 0x9Au, "synarray_predict");
bitar_reset(a3);
result = *(_QWORD *)(a2 + 8) << 6;
if ( result )
{
for ( i = 0LL; i < result; ++i )
{
if ( (unsigned int)bitar_get(a2, i) )
func3((_QWORD *)(a1[2] + 16 * i), v3, a2, a3);
result = *(_QWORD *)(a2 + 8) << 6;
}
}
return result;
}

original_code:
void
synarray_predict(struct synar *sa, bitar_t *cur, bitar_t *next)
{
  size_t i;
  const size_t syns = (const size_t)sa->syns;
  const size_t wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((cur)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((cur)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(cur)", "components.c", 154, __extension__ __PRETTY_FUNCTION__); }));
  bitar_reset(next);
  for ( i = 0; i < ((cur)->map_size * 64); i++ ) {
    if ( bitar_get(cur, i) )
      synapse_predict(sa->array + i, wconns, cur, next);
  }
}

canonical_original_code:
void synarray_predict(struct synar *sa, struct bitar *cur, struct bitar *next)
{
  unsigned long i;
  unsigned long syns = (const size_t)sa->syns;
  unsigned long wconns = (const size_t)sa->wconns;
  ((void) sizeof ((syns == ((cur)->map_size * 64)) ? 1 : 0), __extension__ ({ if (syns == ((cur)->map_size * 64)) ; else __assert_fail ("syns == bitar_bitsize(cur)", "components.c", 154, __extension__ __PRETTY_FUNCTION__); }));
  bitar_reset(next);
  for ( i = 0; i < ((cur)->map_size * 64); i++ ) {
    if ( bitar_get(cur, i) )
      synapse_predict(sa->array + i, wconns, cur, next);
  }
}

variable_types:
next
struct bitar *


original_code:
void
synarray_dump(struct synar *sa)
{
  size_t i;
  const size_t syns = (const size_t)sa->syns;
  const size_t wconns = (const size_t)sa->wconns;
  for ( i = 0; i < syns; i++ ) {
    if ( sa->array[i].totcount < 2 )
      continue;
    printf("\n %lu\n", i);
    synapse_dump(sa->array + i, wconns);
  }
}

canonical_original_code:
void synarray_dump(struct synar *sa)
{
  unsigned long i;
  unsigned long syns = (const size_t)sa->syns;
  unsigned long wconns = (const size_t)sa->wconns;
  for ( i = 0; i < syns; i++ ) {
    if ( sa->array[i].totcount < 2 )
      continue;
    printf("\n %lu\n", i);
    synapse_dump(sa->array + i, wconns);
  }
}


original_code:
void
spool_init(struct spool *sp, size_t input_w, size_t columns_w, size_t conns, size_t maxbits)
{
  sp->input_w = input_w;
  sp->columns_w = columns_w;
  sp->conns = conns;
  sp->maxbits = maxbits;
  fdr_init(sp->in2col, input_w, columns_w, conns, maxbits);
}

canonical_original_code:
void spool_init(struct spool *sp, unsigned long input_w, unsigned long columns_w, unsigned long conns, unsigned long maxbits)
{
  sp->input_w = input_w;
  sp->columns_w = columns_w;
  sp->conns = conns;
  sp->maxbits = maxbits;
  fdr_init(sp->in2col, input_w, columns_w, conns, maxbits);
}

variable_types: struct spool { unsigned long input_w; unsigned long columns_w; unsigned long conns; unsigned long maxbits; struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } input[1]; struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar and; struct bitar *incols; struct coinc_array { unsigned long col; unsigned long val; } *coinc_array; } in2col[1]; struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } synar[1]; } *

variable_types:
conns
unsigned long

variable_types:
maxbits
unsigned long

user_defined_types: struct spool { unsigned long input_w; unsigned long columns_w; unsigned long conns; unsigned long maxbits; struct bitar input[1]; struct fdr in2col[1]; struct synar synar[1]; }

user_defined_types: struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar and; struct bitar *incols; struct coinc_array *coinc_array; }


decompiled_code:
__int64 __fastcall spool_init_std(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
return spool_init(a1, a2, a3, (a2 << 6) / a4, (a3 << 6) / a5);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
return func10(a1, a2, a3, (a2 << 6) / a4, (a3 << 6) / a5);
}

original_code:
void
spool_init_std(struct spool *sp, size_t input_w, size_t columns_w, size_t conn_factor, size_t act_factor)
{
  size_t conns = ((input_w) * 64)/conn_factor;
  size_t maxbits = ((columns_w) * 64)/act_factor;
  spool_init(sp, input_w, columns_w, conns, maxbits);
}

canonical_original_code:
void spool_init_std(struct spool *sp, unsigned long input_w, unsigned long columns_w, unsigned long conn_factor, unsigned long act_factor)
{
  unsigned long conns = ((input_w) * 64)/conn_factor;
  unsigned long maxbits = ((columns_w) * 64)/act_factor;
  spool_init(sp, input_w, columns_w, conns, maxbits);
}

user_defined_types: struct coinc_array { unsigned long col; unsigned long val; }


spool

decompiled_code:
__int64 __fastcall spool(__int64 a1)
{
return fdr_feedback_generate(a1 + 56);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return fdr_feedback_generate(a1 + 56);
}

original_code:
void spool(struct spool *sp, bitar_t *in, bitar_t *expected, bitar_t *out)
{
  fdr_feedback_generate(sp->in2col, in, expected, out);
}

canonical_original_code:
void spool(struct spool *sp, struct bitar *in, struct bitar *expected, struct bitar *out)
{
  fdr_feedback_generate(sp->in2col, in, expected, out);
}

variable_types:
in
struct bitar *

variable_types:
expected
struct bitar *

variable_types:
out
struct bitar *


original_code:
void
seqlearn_init(struct seqlearn *sq, size_t columns_w, size_t cells_per_col, size_t col2cur_conns, size_t prev2cur_conns)
{
  size_t i;
  sq->columns_w = columns_w;
  sq->output_w = columns_w * cells_per_col;
  fdr_init(sq->col2cur, sq->columns_w, sq->output_w, col2cur_conns, 1);
  synarray_init_sub(sq->prev2cur, ((sq->output_w) * 64), ((sq->output_w) * 64), prev2cur_conns);
  bitar_init(sq->col_prev, sq->columns_w);
  bitar_init(sq->prev, sq->output_w);
  bitar_init(sq->expected, sq->output_w);
  bitar_setall(sq->prev);
}

canonical_original_code:
void seqlearn_init(struct seqlearn *sq, unsigned long columns_w, unsigned long cells_per_col, unsigned long col2cur_conns, unsigned long prev2cur_conns)
{
  unsigned long i;
  sq->columns_w = columns_w;
  sq->output_w = columns_w * cells_per_col;
  fdr_init(sq->col2cur, sq->columns_w, sq->output_w, col2cur_conns, 1);
  synarray_init_sub(sq->prev2cur, ((sq->output_w) * 64), ((sq->output_w) * 64), prev2cur_conns);
  bitar_init(sq->col_prev, sq->columns_w);
  bitar_init(sq->prev, sq->output_w);
  bitar_init(sq->expected, sq->output_w);
  bitar_setall(sq->prev);
}

variable_types: struct seqlearn { unsigned long columns_w; unsigned long output_w; struct fdr { unsigned long input_mapsize; unsigned long output_mapsize; unsigned long conn_bits; unsigned long trunc; struct bitar { unsigned long count; unsigned long map_size; unsigned long *map; } and; struct bitar *incols; struct coinc_array { unsigned long col; unsigned long val; } *coinc_array; } col2cur[1]; unsigned long col2cur_conns; struct synar { unsigned long syns; unsigned long wconns; struct synapse { unsigned long totcount; struct wconn { unsigned long id; unsigned long count; } *wconn; } *array; } prev2cur[1]; struct bitar col_prev[1]; struct bitar prev[1]; struct bitar expected[1]; } *

user_defined_types: struct seqlearn { unsigned long columns_w; unsigned long output_w; struct fdr col2cur[1]; unsigned long col2cur_conns; struct synar prev2cur[1]; struct bitar col_prev[1]; struct bitar prev[1]; struct bitar expected[1]; }


decompiled_code:
__int64 __fastcall seqlearn_init_std(_QWORD *a1, __int64 a2, __int64 a3, unsigned __int64 a4)
{
return seqlearn_init(a1, a2, a3, (a2 << 6) / a4, ((a3 * a2) << 6) / a4);
}

original_code:
void
seqlearn_init_std(struct seqlearn *sq, size_t columns_w, size_t cells_per_col, size_t conn_factor)
{
  size_t col2cur_conns = ((columns_w) * 64)/conn_factor;
  size_t prev2cur_conns = (((columns_w) * 64) * cells_per_col) / conn_factor;
  seqlearn_init(sq, columns_w, cells_per_col, col2cur_conns, prev2cur_conns);
}

canonical_original_code:
void seqlearn_init_std(struct seqlearn *sq, unsigned long columns_w, unsigned long cells_per_col, unsigned long conn_factor)
{
  unsigned long col2cur_conns = ((columns_w) * 64)/conn_factor;
  unsigned long prev2cur_conns = (((columns_w) * 64) * cells_per_col) / conn_factor;
  seqlearn_init(sq, columns_w, cells_per_col, col2cur_conns, prev2cur_conns);
}


seqlearn

decompiled_code:
__int64 __fastcall seqlearn(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r14
unsigned __int64 v5; // r15
_QWORD *v7; // r13
__int64 result; // rax
int v10; // [rsp+8h] [rbp-40h]

v4 = a1[1];
v5 = *a1;
if ( *a1 != *(_QWORD *)(a2 + 8) )
_assert_fail("bitar_size(col_in) == sq->columns_w", "components.c", 0xFEu, "seqlearn");
v7 = a1 + 15;
if ( bitar_dist(a1 + 15) )
{
fdr_groupselect(a1 + 2, v4 / v5, v7, a4, a3, a2);
v10 = bitar_dist(a4);
synarray_learn(a1 + 12, (__int64)(a1 + 18), a4);
synarray_predict(a1 + 12, a4, (__int64)(a1 + 21));
bitar_copy(a1 + 18, a4);
bitar_copy(v7, a2);
result = (unsigned int)(v10 + 1);
}
else
{
bitar_copy(a4, a1 + 18);
synarray_predict(a1 + 12, a4, (__int64)(a1 + 21));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // r14
unsigned __int64 v5; // r15
_QWORD *v7; // r13
__int64 result; // rax
int v10; // [rsp+8h] [rbp-40h]

v4 = a1[1];
v5 = *a1;
if ( *a1 != *(_QWORD *)(a2 + 8) )
_assert_fail("bitar_size(col_in) == sq->columns_w", "components.c", 0xFEu, "seqlearn");
v7 = a1 + 15;
if ( bitar_dist(a1 + 15) )
{
fdr_groupselect(a1 + 2, v4 / v5, v7, a4, a3, a2);
v10 = bitar_dist(a4);
func7(a1 + 12, (__int64)(a1 + 18), a4);
func8(a1 + 12, a4, (__int64)(a1 + 21));
bitar_copy(a1 + 18, a4);
bitar_copy(v7, a2);
result = (unsigned int)(v10 + 1);
}
else
{
bitar_copy(a4, a1 + 18);
func8(a1 + 12, a4, (__int64)(a1 + 21));
result = 0LL;
}
return result;
}

original_code:
int
seqlearn(struct seqlearn *sq, bitar_t *col_in, bitar_t *feedback, bitar_t *out)
{
  size_t i;
  size_t cells_per_col = sq->output_w/sq->columns_w;
  ((void) sizeof ((((col_in)->map_size) == sq->columns_w) ? 1 : 0), __extension__ ({ if (((col_in)->map_size) == sq->columns_w) ; else __assert_fail ("bitar_size(col_in) == sq->columns_w", "components.c", 254, __extension__ __PRETTY_FUNCTION__); }));
  if ( bitar_dist(sq->col_prev, col_in) == 0 ) {
    bitar_copy(out, sq->prev);
    synarray_predict(sq->prev2cur, out, sq->expected);
    return 0;
  }
  fdr_groupselect(sq->col2cur, cells_per_col, sq->col_prev, out, feedback, col_in);
  i = bitar_dist(out, sq->expected);
  synarray_learn(sq->prev2cur, sq->prev, out);
  synarray_predict(sq->prev2cur, out, sq->expected);
  bitar_copy(sq->prev, out);
  bitar_copy(sq->col_prev, col_in);
  return 1 + i;
}

canonical_original_code:
int seqlearn(struct seqlearn *sq, struct bitar *col_in, struct bitar *feedback, struct bitar *out)
{
  unsigned long i;
  unsigned long cells_per_col = sq->output_w/sq->columns_w;
  ((void) sizeof ((((col_in)->map_size) == sq->columns_w) ? 1 : 0), __extension__ ({ if (((col_in)->map_size) == sq->columns_w) ; else __assert_fail ("bitar_size(col_in) == sq->columns_w", "components.c", 254, __extension__ __PRETTY_FUNCTION__); }));
  if ( bitar_dist(sq->col_prev, col_in) == 0 ) {
    bitar_copy(out, sq->prev);
    synarray_predict(sq->prev2cur, out, sq->expected);
    return 0;
  }
  fdr_groupselect(sq->col2cur, cells_per_col, sq->col_prev, out, feedback, col_in);
  i = bitar_dist(out, sq->expected);
  synarray_learn(sq->prev2cur, sq->prev, out);
  synarray_predict(sq->prev2cur, out, sq->expected);
  bitar_copy(sq->prev, out);
  bitar_copy(sq->col_prev, col_in);
  return 1 + i;
}

variable_types:
feedback
struct bitar *