decompiled_code:
void __fastcall __noreturn main_terminate(int a1)
{
dword_28B8 = 1;
if ( !exit_status )
exit_status = a1;
while ( 1 )
sleep(0x3Cu);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1)
{
dword_28B8 = 1;
if ( !exit_status )
exit_status = a1;
while ( 1 )
sleep(0x3Cu);
}

original_code:
void
main_terminate(
    MTC_STATUS status)
{
    daemon_vars.terminate_requested = 1;
    if (exit_status == 0)
    {
        exit_status = status;
    }
    for (;;)
    {
        sleep(60);
    }
}

canonical_original_code:
void main_terminate(int status)
{
    daemon_vars.terminate_requested = 1;
    if (exit_status == 0)
    {
        exit_status = status;
    }
    for (;;)
    {
        sleep(60);
    }
}


repo: xenserver/xha

decompiled_code:
__int64 main_save_scheduler()
{
__pid_t v0; // eax
int v1; // eax
int v2; // ebx
__pid_t v3; // eax
__int64 result; // rax
int *v5; // rax
int *v6; // rax
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = 0;
v0 = getpid();
v1 = sched_getscheduler(v0);
if ( v1 < 0 )
{
v5 = _errno_location();
result = log_message(131076LL, "HA daemon get scheduler policy failed (sys %d)\n", (unsigned int)*v5);
}
else
{
v2 = v1;
v3 = getpid();
if ( sched_getparam(v3, &param) )
{
v6 = _errno_location();
result = log_message(131076LL, "HA daemon get scheduler param failed (sys %d)\n", (unsigned int)*v6);
}
else
{
sched_policy_save = v2;
result = (unsigned int)param.__sched_priority;
sparam_save.__sched_priority = param.__sched_priority;
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__pid_t v0; // eax
int v1; // eax
int v2; // ebx
__pid_t v3; // eax
__int64 result; // rax
int *v5; // rax
int *v6; // rax
struct sched_param param; // [rsp+Ch] [rbp-Ch] BYREF

param.__sched_priority = 0;
v0 = getpid();
v1 = sched_getscheduler(v0);
if ( v1 < 0 )
{
v5 = _errno_location();
result = log_message(131076LL, "HA daemon get scheduler policy failed (sys %d)\n", (unsigned int)*v5);
}
else
{
v2 = v1;
v3 = getpid();
if ( sched_getparam(v3, &param) )
{
v6 = _errno_location();
result = log_message(131076LL, "HA daemon get scheduler param failed (sys %d)\n", (unsigned int)*v6);
}
else
{
sched_policy_save = v2;
result = (unsigned int)param.__sched_priority;
sparam_save.__sched_priority = param.__sched_priority;
}
}
return result;
}

original_code:
void
main_save_scheduler(void)
{
    struct sched_param sparam = {0};
    int sched_policy;
    int status;
    sched_policy = sched_getscheduler(getpid());
    if (sched_policy < 0)
    {
        log_message((4 | (1<<17)), "HA daemon get scheduler policy failed (sys %d)\n",
                    (*__errno_location ()));
        return;
    }
    status = sched_getparam(getpid(), &sparam);
    if (status != 0)
    {
        log_message((4 | (1<<17)), "HA daemon get scheduler param failed (sys %d)\n",
                    (*__errno_location ()));
        return;
    }
    sched_policy_save = sched_policy;
    sparam_save = sparam;
}

canonical_original_code:
void main_save_scheduler()
{
    struct sched_param sparam = {0};
    int sched_policy;
    int status;
    sched_policy = sched_getscheduler(getpid());
    if (sched_policy < 0)
    {
        log_message((4 | (1<<17)), "HA daemon get scheduler policy failed (sys %d)\n",
                    (*__errno_location ()));
        return;
    }
    status = sched_getparam(getpid(), &sparam);
    if (status != 0)
    {
        log_message((4 | (1<<17)), "HA daemon get scheduler param failed (sys %d)\n",
                    (*__errno_location ()));
        return;
    }
    sched_policy_save = sched_policy;
    sparam_save = sparam;
}

variable_types: struct sched_param { int sched_priority; }

variable_types: status int

return_type: void


decompiled_code:
int main_reset_scheduler()
{
int v0; // ebx
__pid_t v1; // eax

v0 = sched_policy_save;
v1 = getpid();
return sched_setscheduler(v1, v0, &sparam_save);
}

canonical_decompiled_code:
int func7()
{
int v0; // ebx
__pid_t v1; // eax

v0 = sched_policy_save;
v1 = getpid();
return sched_setscheduler(v1, v0, &sparam_save);
}

original_code:
void
main_reset_scheduler(void)
{
    int status;
    status = sched_setscheduler(getpid() , sched_policy_save, &sparam_save);
}

canonical_original_code:
void main_reset_scheduler()
{
    int status;
    status = sched_setscheduler(getpid() , sched_policy_save, &sparam_save);
}


decompiled_code:
__int64 main_log_timeouts()
{
return log_message(
131078LL,
"CONF: my_index=%d num_host=%d t1=%d T1=%d t2=%d T2=%d Wh=%d Ws=%d Tboot=%d Tenable=%d tXapi=%d TXapi=%d Resta"
"rtXapi=%d TRestartXapi=%d Tlicence=%d\n",
ha_config[985],
ha_config[11],
ha_config[972],
ha_config[973],
ha_config[974],
ha_config[975],
ha_config[976],
ha_config[977],
ha_config[978],
ha_config[979],
ha_config[980],
ha_config[981],
ha_config[982],
ha_config[983],
ha_config[984]);
}

canonical_decompiled_code:
__int64 func8()
{
return log_message(
131078LL,
"CONF: my_index=%d num_host=%d t1=%d T1=%d t2=%d T2=%d Wh=%d Ws=%d Tboot=%d Tenable=%d tXapi=%d TXapi=%d Resta"
"rtXapi=%d TRestartXapi=%d Tlicence=%d\n",
ha_config[985],
ha_config[11],
ha_config[972],
ha_config[973],
ha_config[974],
ha_config[975],
ha_config[976],
ha_config[977],
ha_config[978],
ha_config[979],
ha_config[980],
ha_config[981],
ha_config[982],
ha_config[983],
ha_config[984]);
}

original_code:
void
main_log_timeouts(void)
{
    log_message((6 | (1<<17)), "CONF: my_index=%d num_host=%d t1=%d T1=%d t2=%d T2=%d Wh=%d Ws=%d Tboot=%d Tenable=%d tXapi=%d TXapi=%d RestartXapi=%d TRestartXapi=%d Tlicence=%d\n",
               (ha_config.local.localhost_index), (ha_config.common.hostnum),
               (ha_config.common.heartbeat_interval), (ha_config.common.heartbeat_timeout),
               (ha_config.common.statefile_interval), (ha_config.common.statefile_timeout),
               (ha_config.common.heartbeat_watchdog_timeout), (ha_config.common.statefile_watchdog_timeout),
               (ha_config.common.boot_join_timeout), (ha_config.common.enable_join_timeout), (ha_config.common.xapi_healthcheck_interval), (ha_config.common.xapi_healthcheck_timeout), (ha_config.common.xapi_restart_attempts), (ha_config.common.xapi_restart_timeout), (ha_config.common.xapi_licensecheck_timeout));
}

canonical_original_code:
void main_log_timeouts()
{
    log_message((6 | (1<<17)), "CONF: my_index=%d num_host=%d t1=%d T1=%d t2=%d T2=%d Wh=%d Ws=%d Tboot=%d Tenable=%d tXapi=%d TXapi=%d RestartXapi=%d TRestartXapi=%d Tlicence=%d\n",
               (ha_config.local.localhost_index), (ha_config.common.hostnum),
               (ha_config.common.heartbeat_interval), (ha_config.common.heartbeat_timeout),
               (ha_config.common.statefile_interval), (ha_config.common.statefile_timeout),
               (ha_config.common.heartbeat_watchdog_timeout), (ha_config.common.statefile_watchdog_timeout),
               (ha_config.common.boot_join_timeout), (ha_config.common.enable_join_timeout), (ha_config.common.xapi_healthcheck_interval), (ha_config.common.xapi_healthcheck_timeout), (ha_config.common.xapi_restart_attempts), (ha_config.common.xapi_restart_timeout), (ha_config.common.xapi_licensecheck_timeout));
}


decompiled_code:
int __fastcall main_sleep(__int64 a1)
{
struct timespec v1; // rax
int result; // eax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

v1.tv_sec = mstots(a1);
v3 = v1;
for ( requested_time = v1; ; requested_time = (struct timespec)_mm_loadu_si128((const __m128i *)&v3) )
{
result = nanosleep(&requested_time, &v3);
if ( !result )
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
struct timespec v1; // rax
int result; // eax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF
struct timespec requested_time; // [rsp+10h] [rbp-18h] BYREF

v1.tv_sec = func0(a1);
v3 = v1;
for ( requested_time = v1; ; requested_time = (struct timespec)_mm_loadu_si128((const __m128i *)&v3) )
{
result = nanosleep(&requested_time, &v3);
if ( !result )
break;
}
return result;
}

original_code:
void
main_sleep(
    MTC_CLOCK msec)
{
    struct timespec ts, ts_rem;
    ts = ts_rem = mstots(msec);
    while (nanosleep(&ts, &ts_rem)) ts = ts_rem;
}

canonical_original_code:
void main_sleep(long long msec)
{
    struct timespec ts; struct timespec ts_rem;
    ts = ts_rem = mstots(msec);
    while (nanosleep(&ts, &ts_rem)) ts = ts_rem;
}

variable_types:
msec
long long

variable_types: struct timespec { long tv_sec; long tv_nsec; }


xhadlog

decompiled_code:
int xhadlog(int a1, const char *a2, ...)
{
int v2; // eax
__int64 v3; // rdx
int v4; // ebx
int v5; // edi
char *v6; // r12
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
time_t timer; // [rsp+18h] [rbp-D0h] BYREF

pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 )
{
v2 = *((_DWORD *)&prioritynames + 2);
if ( v2 == -1 )
{
v4 = 0;
}
else
{
v3 = (unsigned int)((_DWORD)&prioritynames + 24);
v4 = 0;
v5 = a1 & 7;
do
{
if ( v5 == v2 )
break;
++v4;
v3 += 16LL;
v2 = *(_DWORD *)(v3 - 16);
}
while ( v2 != -1 );
}
timer = time(0LL);
v6 = ctime(&timer);
v6[strlen(v6) - 1] = 0;
fprintf(fpLogfile, "%s [%s] ", v6, (&prioritynames)[2 * v4]);
va_start(va, a2);
vfprintf(fpLogfile, a2, va);
fflush(fpLogfile);
}
return pthread_spin_unlock(&lock);
}

canonical_decompiled_code:
int func3(int a1, const char *a2, ...)
{
int v2; // eax
__int64 v3; // rdx
int v4; // ebx
int v5; // edi
char *v6; // r12
gcc_va_list va; // [rsp+0h] [rbp-E8h] BYREF
time_t timer; // [rsp+18h] [rbp-D0h] BYREF

pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 )
{
v2 = *((_DWORD *)&prioritynames + 2);
if ( v2 == -1 )
{
v4 = 0;
}
else
{
v3 = (unsigned int)((_DWORD)&prioritynames + 24);
v4 = 0;
v5 = a1 & 7;
do
{
if ( v5 == v2 )
break;
++v4;
v3 += 16LL;
v2 = *(_DWORD *)(v3 - 16);
}
while ( v2 != -1 );
}
timer = time(0LL);
v6 = ctime(&timer);
v6[strlen(v6) - 1] = 0;
fprintf(fpLogfile, "%s [%s] ", v6, (&prioritynames)[2 * v4]);
va_start(va, a2);
vfprintf(fpLogfile, a2, va);
fflush(fpLogfile);
}
return pthread_spin_unlock(&lock);
}

original_code:
void
xhadlog(MTC_S32 priority, PMTC_S8 fmt, ...)
{
    time_t now;
    MTC_S8 *pTString;
    va_list ap;
    pthread_spin_lock(&lock);
    if (priority & (1<<17))
    {
        MTC_S32 i = 0;
        while (prioritynames[i].c_val != -1 &&
               prioritynames[i].c_val != ((priority) & 0x07))
        {
     i++;
        }
        now = time(((void *)0));
        pTString = ctime(&now);
        pTString[strlen(pTString) - 1] = '\0';
        fprintf(fpLogfile,
         "%s [%s] ", pTString, prioritynames[i].c_name);
        __builtin_va_start(ap,fmt);
        vfprintf(fpLogfile, fmt, ap);
        __builtin_va_end(ap);
        fflush(fpLogfile);
    }
    pthread_spin_unlock(&lock);
}

canonical_original_code:
void xhadlog(int priority, char *fmt, ...)
{
    long now;
    char *pTString;
    __builtin_va_list ap;
    pthread_spin_lock(&lock);
    if (priority & (1<<17))
    {
        int i = 0;
        while (prioritynames[i].c_val != -1 &&
               prioritynames[i].c_val != ((priority) & 0x07))
        {
     i++;
        }
        now = time(((void *)0));
        pTString = ctime(&now);
        pTString[strlen(pTString) - 1] = '\0';
        fprintf(fpLogfile,
         "%s [%s] ", pTString, prioritynames[i].c_name);
        __builtin_va_start(ap,fmt);
        vfprintf(fpLogfile, fmt, ap);
        __builtin_va_end(ap);
        fflush(fpLogfile);
    }
    pthread_spin_unlock(&lock);
}

variable_types: priority int

variable_types:
fmt
char *

variable_types: now long

variable_types:
pTString
char *

variable_types: i int


decompiled_code:
int __fastcall xhadlog_bin8(int a1, __int64 a2, int a3)
{
int v5; // er12
__int64 v6; // rbx
__int64 v7; // rbp
char v8; // r12
bool v9; // dl
bool v10; // al
int v11; // [rsp+8h] [rbp-60h]
unsigned int v12; // [rsp+Ch] [rbp-5Ch]
char v13[88]; // [rsp+10h] [rbp-58h] BYREF

pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 )
{
if ( a3 > 0 )
{
v11 = 0;
v12 = 0;
do
{
fprintf(fpLogfile, "\t%04x: ", v12);
if ( a3 <= v11 )
{
v13[0] = 0;
v5 = 0;
}
else
{
v6 = v11 + 1;
v7 = 1LL;
do
{
fprintf(fpLogfile, "%02x ", (unsigned int)*(char *)(a2 + v6 - 1));
v8 = *(_BYTE *)(a2 + v6 - 1);
if ( !isprint(v8) )
v8 = 46;
*((_BYTE *)&v12 + v7 + 3) = v8;
v5 = v7;
v11 = v6;
v9 = (int)v7 <= 15;
v10 = a3 > (int)v6;
++v7;
++v6;
}
while ( v10 && v9 );
v13[v5] = 0;
if ( v5 > 15 )
goto LABEL_8;
}
do
{
fwrite(" ", 1uLL, 3uLL, fpLogfile);
++v5;
}
while ( v5 <= 15 );
LABEL_8:
fprintf(fpLogfile, ": %s\n", v13);
++v12;
}
while ( v11 < a3 );
}
fflush(fpLogfile);
}
return pthread_spin_unlock(&lock);
}

canonical_decompiled_code:
int __fastcall func4(int a1, __int64 a2, int a3)
{
int v5; // er12
__int64 v6; // rbx
__int64 v7; // rbp
char v8; // r12
bool v9; // dl
bool v10; // al
int v11; // [rsp+8h] [rbp-60h]
unsigned int v12; // [rsp+Ch] [rbp-5Ch]
char v13[88]; // [rsp+10h] [rbp-58h] BYREF

pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 )
{
if ( a3 > 0 )
{
v11 = 0;
v12 = 0;
do
{
fprintf(fpLogfile, "\t%04x: ", v12);
if ( a3 <= v11 )
{
v13[0] = 0;
v5 = 0;
}
else
{
v6 = v11 + 1;
v7 = 1LL;
do
{
fprintf(fpLogfile, "%02x ", (unsigned int)*(char *)(a2 + v6 - 1));
v8 = *(_BYTE *)(a2 + v6 - 1);
if ( !isprint(v8) )
v8 = 46;
*((_BYTE *)&v12 + v7 + 3) = v8;
v5 = v7;
v11 = v6;
v9 = (int)v7 <= 15;
v10 = a3 > (int)v6;
++v7;
++v6;
}
while ( v10 && v9 );
v13[v5] = 0;
if ( v5 > 15 )
goto LABEL_8;
}
do
{
fwrite(" ", 1uLL, 3uLL, fpLogfile);
++v5;
}
while ( v5 <= 15 );
LABEL_8:
fprintf(fpLogfile, ": %s\n", v13);
++v12;
}
while ( v11 < a3 );
}
fflush(fpLogfile);
}
return pthread_spin_unlock(&lock);
}

original_code:
void
xhadlog_bin8(MTC_S32 priority, PMTC_S8 data, MTC_S32 size)
{
    MTC_S32 line, pos, col;
    MTC_S8 asc_dmp[16 + 1];
    pthread_spin_lock(&lock);
    if (priority & (1<<17))
    {
        for (line = 0, pos = 0; pos < size; line++)
        {
            fprintf(fpLogfile, "\t%04x: ", line);
            for (col = 0; col < 16 && pos < size; col++, pos++)
            {
                fprintf(fpLogfile, "%02x ", data[pos]);
                asc_dmp[col] = (isprint(data[pos]))? data[pos]: '.';
            }
            asc_dmp[col] = '\0';
            for (; col < 16; col++)
            {
                fprintf(fpLogfile, "   ");
            }
            fprintf(fpLogfile, ": %s\n", asc_dmp);
        }
        fflush(fpLogfile);
    }
    pthread_spin_unlock(&lock);
}

canonical_original_code:
void xhadlog_bin8(int priority, char *data, int size)
{
    int line; int pos; int col;
    char asc_dmp[-1];
    pthread_spin_lock(&lock);
    if (priority & (1<<17))
    {
        for (line = 0, pos = 0; pos < size; line++)
        {
            fprintf(fpLogfile, "\t%04x: ", line);
            for (col = 0; col < 16 && pos < size; col++, pos++)
            {
                fprintf(fpLogfile, "%02x ", data[pos]);
                asc_dmp[col] = (isprint(data[pos]))? data[pos]: '.';
            }
            asc_dmp[col] = '\0';
            for (; col < 16; col++)
            {
                fprintf(fpLogfile, "   ");
            }
            fprintf(fpLogfile, ": %s\n", asc_dmp);
        }
        fflush(fpLogfile);
    }
    pthread_spin_unlock(&lock);
}

variable_types:
data
char *

variable_types: size int

variable_types: line int

variable_types: pos int

variable_types: col int


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

fpLogfile = stderr;
result = pthread_spin_init(&lock, 0);
if ( result )
{
syslog(3, "can't initialize spin lock");
result = -*_errno_location();
}
return result;
}

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

fpLogfile = stderr;
result = pthread_spin_init(&lock, 0);
if ( result )
{
syslog(3, "can't initialize spin lock");
result = -*_errno_location();
}
return result;
}

original_code:
MTC_S32
log_initialize()
{
    MTC_S32 ret;
    fpLogfile = stderr;
    ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
    if (ret)
    {
        syslog(3, "can't initialize spin lock");
        return -(*__errno_location ());
    }
    return 0;
}

canonical_original_code:
int log_initialize()
{
    int ret;
    fpLogfile = stderr;
    ret = pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE);
    if (ret)
    {
        syslog(3, "can't initialize spin lock");
        return -(*__errno_location ());
    }
    return 0;
}

variable_types: ret int

return_type: int


decompiled_code:
void log_reopen()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
log_reopen()
{
}

canonical_original_code:
void log_reopen()
{
}


decompiled_code:
int log_terminate()
{
return pthread_spin_destroy(&lock);
}

canonical_decompiled_code:
int func2()
{
return pthread_spin_destroy(&lock);
}

original_code:
void
log_terminate()
{
    pthread_spin_destroy(&lock);
}


decompiled_code:
void log_message(int a1, const char *a2, ...)
{
FILE *v2; // r13
int v3; // eax
__int64 v4; // rdx
int v5; // er12
struct tm *v6; // rax
gcc_va_list va; // [rsp+0h] [rbp-F8h] BYREF
time_t timer; // [rsp+18h] [rbp-E0h] BYREF

if ( initialized )
{
pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 )
{
v2 = fpLogfile;
if ( fpLogfile )
{
if ( privatelogflag )
{
v3 = *((_DWORD *)&prioritynames + 2);
if ( v3 == -1 )
{
v5 = 0;
}
else
{
v4 = (unsigned int)((_DWORD)&prioritynames + 24);
v5 = 0;
do
{
if ( (a1 & 7) == v3 )
break;
++v5;
v4 += 16LL;
v3 = *(_DWORD *)(v4 - 16);
}
while ( v3 != -1 );
}
timer = time(0LL);
v6 = localtime(&timer);
fprintf(
v2,
"%s %02d %02d:%02d:%02d %s %04d [%s] ",
monthnames[v6->tm_mon],
(unsigned int)v6->tm_mday,
(unsigned int)v6->tm_hour,
(unsigned int)v6->tm_min,
(unsigned int)v6->tm_sec,
v6->tm_zone,
(unsigned int)(v6->tm_year + 1900),
(&prioritynames)[2 * v5]);
va_start(va, a2);
vfprintf(fpLogfile, a2, va);
fflush(fpLogfile);
}
}
}
if ( (a1 & 0x10000) != 0 )
{
va_end(va);
va_start(va, a2);
vsyslog(a1 & 7, a2, va);
}
pthread_spin_unlock(&lock);
}
}

canonical_decompiled_code:
void func3(int a1, const char *a2, ...)
{
FILE *v2; // r13
int v3; // eax
__int64 v4; // rdx
int v5; // er12
struct tm *v6; // rax
gcc_va_list va; // [rsp+0h] [rbp-F8h] BYREF
time_t timer; // [rsp+18h] [rbp-E0h] BYREF

if ( initialized )
{
pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 )
{
v2 = fpLogfile;
if ( fpLogfile )
{
if ( privatelogflag )
{
v3 = *((_DWORD *)&prioritynames + 2);
if ( v3 == -1 )
{
v5 = 0;
}
else
{
v4 = (unsigned int)((_DWORD)&prioritynames + 24);
v5 = 0;
do
{
if ( (a1 & 7) == v3 )
break;
++v5;
v4 += 16LL;
v3 = *(_DWORD *)(v4 - 16);
}
while ( v3 != -1 );
}
timer = time(0LL);
v6 = localtime(&timer);
fprintf(
v2,
"%s %02d %02d:%02d:%02d %s %04d [%s] ",
monthnames[v6->tm_mon],
(unsigned int)v6->tm_mday,
(unsigned int)v6->tm_hour,
(unsigned int)v6->tm_min,
(unsigned int)v6->tm_sec,
v6->tm_zone,
(unsigned int)(v6->tm_year + 1900),
(&prioritynames)[2 * v5]);
va_start(va, a2);
vfprintf(fpLogfile, a2, va);
fflush(fpLogfile);
}
}
}
if ( (a1 & 0x10000) != 0 )
{
va_end(va);
va_start(va, a2);
vsyslog(a1 & 7, a2, va);
}
pthread_spin_unlock(&lock);
}
}

original_code:
void log_message(MTC_S32 priority, PMTC_S8 fmt, ...)
{
    time_t now;
    struct tm *ptm;
    va_list ap;
    if (!initialized)
    {
        return;
    }
    pthread_spin_lock(&lock);
    if (priority & (1<<17) && fpLogfile != ((void *)0) && privatelogflag)
    {
        MTC_S32 i = 0;
        while (prioritynames[i].c_val != -1 &&
               prioritynames[i].c_val != ((priority) & 0x07))
        {
            i++;
        }
        now = time(((void *)0));
        ptm = localtime(&now);
        fprintf(fpLogfile, "%s %02d %02d:%02d:%02d %s %04d [%s] ",
                monthnames[ptm->tm_mon], ptm->tm_mday,
                ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
                ptm->tm_zone, 1900 + ptm->tm_year, prioritynames[i].c_name);
        __builtin_va_start(ap,fmt);
        vfprintf(fpLogfile, fmt, ap);
        __builtin_va_end(ap);
        fflush(fpLogfile);
    }
    if (priority & (1<<16))
    {
        __builtin_va_start(ap,fmt);
        vsyslog(((priority) & 0x07), fmt, ap);
        __builtin_va_end(ap);
    }
    pthread_spin_unlock(&lock);
}

canonical_original_code:
void log_message(int priority, char *fmt, ...)
{
    long now;
    struct tm *ptm;
    __builtin_va_list ap;
    if (!initialized)
    {
        return;
    }
    pthread_spin_lock(&lock);
    if (priority & (1<<17) && fpLogfile != ((void *)0) && privatelogflag)
    {
        int i = 0;
        while (prioritynames[i].c_val != -1 &&
               prioritynames[i].c_val != ((priority) & 0x07))
        {
            i++;
        }
        now = time(((void *)0));
        ptm = localtime(&now);
        fprintf(fpLogfile, "%s %02d %02d:%02d:%02d %s %04d [%s] ",
                monthnames[ptm->tm_mon], ptm->tm_mday,
                ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
                ptm->tm_zone, 1900 + ptm->tm_year, prioritynames[i].c_name);
        __builtin_va_start(ap,fmt);
        vfprintf(fpLogfile, fmt, ap);
        __builtin_va_end(ap);
        fflush(fpLogfile);
    }
    if (priority & (1<<16))
    {
        __builtin_va_start(ap,fmt);
        vsyslog(((priority) & 0x07), fmt, ap);
        __builtin_va_end(ap);
    }
    pthread_spin_unlock(&lock);
}

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
void __fastcall log_bin(int a1, __int64 a2, int a3)
{
int v4; // er12
__int64 v5; // rbx
__int64 v6; // rbp
const unsigned __int16 **v7; // rdx
char v8; // al
bool v9; // dl
bool v10; // al
int v11; // [rsp+0h] [rbp-60h]
unsigned int v12; // [rsp+4h] [rbp-5Ch]
char v13[88]; // [rsp+8h] [rbp-58h] BYREF

if ( initialized )
{
pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 && fpLogfile && privatelogflag )
{
if ( a3 > 0 )
{
v11 = 0;
v12 = 0;
do
{
fprintf(fpLogfile, "\t%04x: ", v12);
if ( a3 <= v11 )
{
v13[0] = 0;
v4 = 0;
}
else
{
v5 = v11 + 1;
v6 = 1LL;
do
{
fprintf(fpLogfile, "%02x ", *(unsigned __int8 *)(a2 + v5 - 1));
v7 = _ctype_b_loc();
v8 = *(_BYTE *)(a2 + v5 - 1);
if ( ((*v7)[v8] & 0x4000) == 0 )
v8 = 46;
*((_BYTE *)&v12 + v6 + 3) = v8;
v4 = v6;
v11 = v5;
v9 = (int)v6 <= 15;
v10 = a3 > (int)v5;
++v6;
++v5;
}
while ( v10 && v9 );
v13[v4] = 0;
if ( v4 > 15 )
goto LABEL_11;
}
do
{
fwrite(" ", 1uLL, 3uLL, fpLogfile);
++v4;
}
while ( v4 <= 15 );
LABEL_11:
fprintf(fpLogfile, ": %s\n", v13);
++v12;
}
while ( v11 < a3 );
}
fflush(fpLogfile);
}
pthread_spin_unlock(&lock);
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, __int64 a2, int a3)
{
int v4; // er12
__int64 v5; // rbx
__int64 v6; // rbp
const unsigned __int16 **v7; // rdx
char v8; // al
bool v9; // dl
bool v10; // al
int v11; // [rsp+0h] [rbp-60h]
unsigned int v12; // [rsp+4h] [rbp-5Ch]
char v13[88]; // [rsp+8h] [rbp-58h] BYREF

if ( initialized )
{
pthread_spin_lock(&lock);
if ( (a1 & 0x20000) != 0 && fpLogfile && privatelogflag )
{
if ( a3 > 0 )
{
v11 = 0;
v12 = 0;
do
{
fprintf(fpLogfile, "\t%04x: ", v12);
if ( a3 <= v11 )
{
v13[0] = 0;
v4 = 0;
}
else
{
v5 = v11 + 1;
v6 = 1LL;
do
{
fprintf(fpLogfile, "%02x ", *(unsigned __int8 *)(a2 + v5 - 1));
v7 = _ctype_b_loc();
v8 = *(_BYTE *)(a2 + v5 - 1);
if ( ((*v7)[v8] & 0x4000) == 0 )
v8 = 46;
*((_BYTE *)&v12 + v6 + 3) = v8;
v4 = v6;
v11 = v5;
v9 = (int)v6 <= 15;
v10 = a3 > (int)v5;
++v6;
++v5;
}
while ( v10 && v9 );
v13[v4] = 0;
if ( v4 > 15 )
goto LABEL_11;
}
do
{
fwrite(" ", 1uLL, 3uLL, fpLogfile);
++v4;
}
while ( v4 <= 15 );
LABEL_11:
fprintf(fpLogfile, ": %s\n", v13);
++v12;
}
while ( v11 < a3 );
}
fflush(fpLogfile);
}
pthread_spin_unlock(&lock);
}
}

original_code:
void log_bin(MTC_S32 priority, PMTC_S8 data, MTC_S32 size)
{
    MTC_S32 line, pos, col;
    MTC_S8 asc_dmp[16 + 1];
    if (!initialized)
    {
        return;
    }
    pthread_spin_lock(&lock);
    if (priority & (1<<17) && fpLogfile != ((void *)0) && privatelogflag)
    {
        for (line = 0, pos = 0; pos < size; line++)
        {
            fprintf(fpLogfile, "\t%04x: ", line);
            for (col = 0; col < 16 && pos < size; col++, pos++)
            {
                fprintf(fpLogfile, "%02x ", (MTC_U8) data[pos]);
                asc_dmp[col] = (((*__ctype_b_loc ())[(int) ((data[pos]))] & (unsigned short int) _ISprint))? data[pos]: '.';
            }
            asc_dmp[col] = '\0';
            for (; col < 16; col++)
            {
                fprintf(fpLogfile, "   ");
            }
            fprintf(fpLogfile, ": %s\n", asc_dmp);
        }
        fflush(fpLogfile);
    }
    pthread_spin_unlock(&lock);
}

canonical_original_code:
void log_bin(int priority, char *data, int size)
{
    int line; int pos; int col;
    char asc_dmp[-1];
    if (!initialized)
    {
        return;
    }
    pthread_spin_lock(&lock);
    if (priority & (1<<17) && fpLogfile != ((void *)0) && privatelogflag)
    {
        for (line = 0, pos = 0; pos < size; line++)
        {
            fprintf(fpLogfile, "\t%04x: ", line);
            for (col = 0; col < 16 && pos < size; col++, pos++)
            {
                fprintf(fpLogfile, "%02x ", (unsigned char) data[pos]);
                asc_dmp[col] = (((*__ctype_b_loc ())[(int) ((data[pos]))] & (unsigned short) _ISprint))? data[pos]: '.';
            }
            asc_dmp[col] = '\0';
            for (; col < 16; col++)
            {
                fprintf(fpLogfile, "   ");
            }
            fprintf(fpLogfile, ": %s\n", asc_dmp);
        }
        fflush(fpLogfile);
    }
    pthread_spin_unlock(&lock);
}


original_code:
void
log_logmask(void)
{
    MTC_U32 logmask_index;
    char *logmask_name[(32 - 18)] = {"DUMPPACKET", "TRACE", "FH_TRACE", "LM_TRACE", "SCRIPT", "SC_WARNING", ((void *)0)};
    log_message((6 | (1<<17)), "LOG: logmask = %x\n", logmask);
    for (logmask_index = 0; logmask_index < (32 - 18); logmask_index++)
    {
        MTC_S32 logmask_on;
        logmask_on = (1 << (logmask_index + 18)) & logmask;
        if (logmask_name[logmask_index] == ((void *)0) && logmask_on == 0)
        {
            continue;
        }
        log_message((6 | (1<<17)), "LOG:  %s:%2.2d(%s)\n",
                    (logmask_on == 0)?"OFF":"ON ",
                    logmask_index + 18,
                    (logmask_name[logmask_index] != ((void *)0))?logmask_name[logmask_index]:"UNKNOWN_MASK");
    }
    return;
}

canonical_original_code:
void log_logmask()
{
    unsigned int logmask_index;
    char *logmask_name[-1] = {"DUMPPACKET", "TRACE", "FH_TRACE", "LM_TRACE", "SCRIPT", "SC_WARNING", ((void *)0)};
    log_message((6 | (1<<17)), "LOG: logmask = %x\n", logmask);
    for (logmask_index = 0; logmask_index < (32 - 18); logmask_index++)
    {
        int logmask_on;
        logmask_on = (1 << (logmask_index + 18)) & logmask;
        if (logmask_name[logmask_index] == ((void *)0) && logmask_on == 0)
        {
            continue;
        }
        log_message((6 | (1<<17)), "LOG:  %s:%2.2d(%s)\n",
                    (logmask_on == 0)?"OFF":"ON ",
                    logmask_index + 18,
                    (logmask_name[logmask_index] != ((void *)0))?logmask_name[logmask_index]:"UNKNOWN_MASK");
    }
    return;
}


original_code:
void
log_backtrace(MTC_S32 priority)
{
    int level;
    Dl_info dli;
    void *return_address[10] = {((void *)0)};
    level = 0;
    if (__builtin_frame_address(0) == 0) { return_address[0] = ((void *)0); goto end_fill; } return_address[0] = __builtin_return_address(0);;
    if (__builtin_frame_address(1) == 0) { return_address[1] = ((void *)0); goto end_fill; } return_address[1] = __builtin_return_address(1);;
    if (__builtin_frame_address(2) == 0) { return_address[2] = ((void *)0); goto end_fill; } return_address[2] = __builtin_return_address(2);;
    if (__builtin_frame_address(3) == 0) { return_address[3] = ((void *)0); goto end_fill; } return_address[3] = __builtin_return_address(3);;
    if (__builtin_frame_address(4) == 0) { return_address[4] = ((void *)0); goto end_fill; } return_address[4] = __builtin_return_address(4);;
    if (__builtin_frame_address(5) == 0) { return_address[5] = ((void *)0); goto end_fill; } return_address[5] = __builtin_return_address(5);;
    if (__builtin_frame_address(6) == 0) { return_address[6] = ((void *)0); goto end_fill; } return_address[6] = __builtin_return_address(6);;
    if (__builtin_frame_address(7) == 0) { return_address[7] = ((void *)0); goto end_fill; } return_address[7] = __builtin_return_address(7);;
    if (__builtin_frame_address(8) == 0) { return_address[8] = ((void *)0); goto end_fill; } return_address[8] = __builtin_return_address(8);;
    if (__builtin_frame_address(9) == 0) { return_address[9] = ((void *)0); goto end_fill; } return_address[9] = __builtin_return_address(9);;
 end_fill:
    log_message(priority, "backtrace -------------\n");
    for (level = 0;
         level < 10;
         level ++)
    {
        int err;
        if (return_address[level] == ((void *)0))
        {
            break;
        }
        err = dladdr(return_address[level], &dli);
        if (err == 0 || dli.dli_sname == ((void *)0))
        {
            log_message(priority, "  %2d: (%p) --\n", level, return_address[level]);
        }
        else
        {
            log_message(priority, "  %2d: (%p) %s\n", level, return_address[level], dli.dli_sname);
        }
    }
    log_message(priority, "backtrace -------------\n");
    return;
}

canonical_original_code:
void log_backtrace(int priority)
{
    int level;
    struct Dl_info dli;
    void *return_address[10] = {((void *)0)};
    level = 0;
    if (__builtin_frame_address(0) == 0) { return_address[0] = ((void *)0); goto end_fill; } return_address[0] = __builtin_return_address(0);;
    if (__builtin_frame_address(1) == 0) { return_address[1] = ((void *)0); goto end_fill; } return_address[1] = __builtin_return_address(1);;
    if (__builtin_frame_address(2) == 0) { return_address[2] = ((void *)0); goto end_fill; } return_address[2] = __builtin_return_address(2);;
    if (__builtin_frame_address(3) == 0) { return_address[3] = ((void *)0); goto end_fill; } return_address[3] = __builtin_return_address(3);;
    if (__builtin_frame_address(4) == 0) { return_address[4] = ((void *)0); goto end_fill; } return_address[4] = __builtin_return_address(4);;
    if (__builtin_frame_address(5) == 0) { return_address[5] = ((void *)0); goto end_fill; } return_address[5] = __builtin_return_address(5);;
    if (__builtin_frame_address(6) == 0) { return_address[6] = ((void *)0); goto end_fill; } return_address[6] = __builtin_return_address(6);;
    if (__builtin_frame_address(7) == 0) { return_address[7] = ((void *)0); goto end_fill; } return_address[7] = __builtin_return_address(7);;
    if (__builtin_frame_address(8) == 0) { return_address[8] = ((void *)0); goto end_fill; } return_address[8] = __builtin_return_address(8);;
    if (__builtin_frame_address(9) == 0) { return_address[9] = ((void *)0); goto end_fill; } return_address[9] = __builtin_return_address(9);;
 end_fill:
    log_message(priority, "backtrace -------------\n");
    for (level = 0;
         level < 10;
         level ++)
    {
        int err;
        if (return_address[level] == ((void *)0))
        {
            break;
        }
        err = dladdr(return_address[level], &dli);
        if (err == 0 || dli.dli_sname == ((void *)0))
        {
            log_message(priority, "  %2d: (%p) --\n", level, return_address[level]);
        }
        else
        {
            log_message(priority, "  %2d: (%p) %s\n", level, return_address[level], dli.dli_sname);
        }
    }
    log_message(priority, "backtrace -------------\n");
    return;
}

variable_types: level int

variable_types: struct Dl_info { char *dli_fname; void *dli_fbase; char *dli_sname; void *dli_saddr; }

variable_types: err int


decompiled_code:
void __fastcall log_status(unsigned int a1, const char *a2)
{
const char *v2; // rdx

v2 = (const char *)status_to_message();
if ( a2 && *a2 )
log_message(196611, "%s (%d) %s.\n", v2, a1, a2);
else
log_message(196611, "%s (%d).\n", v2, a1);
}

canonical_decompiled_code:
void __fastcall func7(unsigned int a1, const char *a2)
{
const char *v2; // rdx

v2 = (const char *)status_to_message();
if ( a2 && *a2 )
func3(196611, "%s (%d) %s.\n", v2, a1, a2);
else
func3(196611, "%s (%d).\n", v2, a1);
}

original_code:
void
log_status(
    MTC_STATUS status,
    char *suffix)
{
    char *message;
    message = status_to_message(status);
    if (suffix == ((void *)0) || strlen(suffix) == 0)
    {
        log_message((3 | (1<<16) | (1<<17)), "%s (%d).\n", message, status);
    }
    else
    {
        log_message((3 | (1<<16) | (1<<17)), "%s (%d) %s.\n", message, status, suffix);
    }
}

canonical_original_code:
void log_status(int status, char *suffix)
{
    char *message;
    message = status_to_message(status);
    if (suffix == ((void *)0) || strlen(suffix) == 0)
    {
        log_message((3 | (1<<16) | (1<<17)), "%s (%d).\n", message, status);
    }
    else
    {
        log_message((3 | (1<<16) | (1<<17)), "%s (%d) %s.\n", message, status, suffix);
    }
}

variable_types: status int

variable_types:
suffix
char *

variable_types:
message
char *


decompiled_code:
void log_fsync()
{
int v0; // eax

if ( initialized )
{
pthread_spin_lock(&lock);
if ( fpLogfile )
{
v0 = fileno(fpLogfile);
fsync(v0);
}
pthread_spin_unlock(&lock);
}
}

canonical_decompiled_code:
void func8()
{
int v0; // eax

if ( initialized )
{
pthread_spin_lock(&lock);
if ( fpLogfile )
{
v0 = fileno(fpLogfile);
fsync(v0);
}
pthread_spin_unlock(&lock);
}
}

original_code:
void
log_fsync()
{
    if (!initialized)
    {
        return;
    }
    pthread_spin_lock(&lock);
    if (fpLogfile)
    {
        fsync(fileno(fpLogfile));
    }
    pthread_spin_unlock(&lock);
}


decompiled_code:
__int64 hostweight_initialize0()
{
__int64 result; // rax

result = 0LL;
memset(weight_table, 0, sizeof(weight_table));
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = 0LL;
memset(weight_table, 0, sizeof(weight_table));
return result;
}

original_code:
MTC_STATUS
hostweight_initialize0(void)
{
    memset(weight_table, 0, sizeof(weight_table));
    return 0;
}

canonical_original_code:
int hostweight_initialize0()
{
    memset(weight_table, 0, sizeof(weight_table));
    return 0;
}


decompiled_code:
__int64 log_hostweight()
{
__int64 result; // rax
char *v1; // rbx

result = log_message(131078LL, "SC: builtinclass=%s weight=%d\n", "native", 1LL);
v1 = weight_table;
do
{
if ( *v1 )
result = log_message(131078LL, "SC: class=%s weight=%d\n", v1, *((unsigned int *)v1 + 17));
v1 += 72;
}
while ( v1 != &error_reported );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
char *v1; // rbx

result = log_message(131078LL, "SC: builtinclass=%s weight=%d\n", "native", 1LL);
v1 = weight_table;
do
{
if ( *v1 )
result = log_message(131078LL, "SC: class=%s weight=%d\n", v1, *((unsigned int *)v1 + 17));
v1 += 72;
}
while ( v1 != &error_reported );
return result;
}

original_code:
void
log_hostweight(void)
{
    int index;
    log_message((6 | (1<<17)), "SC:     builtinclass=%s weight=%d\n",
                "native",
                1);
    for (index = 0; index < 16; index++)
    {
        if (!strcmp(weight_table[index].classname, "")) continue;
        log_message((6 | (1<<17)), "SC:     class=%s weight=%d\n",
                    weight_table[index].classname,
                    weight_table[index].weight);
    }
    return;
}

canonical_original_code:
void log_hostweight()
{
    int index;
    log_message((6 | (1<<17)), "SC:     builtinclass=%s weight=%d\n",
                "native",
                1);
    for (index = 0; index < 16; index++)
    {
        if (!strcmp(weight_table[index].classname, "")) continue;
        log_message((6 | (1<<17)), "SC:     class=%s weight=%d\n",
                    weight_table[index].classname,
                    weight_table[index].weight);
    }
    return;
}

variable_types: index int


decompiled_code:
__int64 calc_hostweight()
{
char *v0; // rax
unsigned int v1; // edx

v0 = weight_table;
v1 = 1;
do
{
if ( *v0 )
v1 += *((_DWORD *)v0 + 17);
v0 += 72;
}
while ( v0 != &error_reported );
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax
unsigned int v1; // edx

v0 = weight_table;
v1 = 1;
do
{
if ( *v0 )
v1 += *((_DWORD *)v0 + 17);
v0 += 72;
}
while ( v0 != &error_reported );
return v1;
}

original_code:
MTC_U32
calc_hostweight(void)
{
    int index;
    MTC_U32 weight;
    weight = 1;
    for (index = 0; index < 16; index++)
    {
        if (!strcmp(weight_table[index].classname, "")) continue;
        weight += weight_table[index].weight;
    }
    return weight;
}

canonical_original_code:
unsigned int calc_hostweight()
{
    int index;
    unsigned int weight;
    weight = 1;
    for (index = 0; index < 16; index++)
    {
        if (!strcmp(weight_table[index].classname, "")) continue;
        weight += weight_table[index].weight;
    }
    return weight;
}

variable_types:
weight
unsigned int

return_type: unsigned int


decompiled_code:
__int64 hostweight_reload()
{
unsigned int v0; // eax
unsigned int v1; // ebx
unsigned int v2; // eax
unsigned int v4; // [rsp+8h] [rbp-490h] BYREF
int fd; // [rsp+Ch] [rbp-48Ch] BYREF
char v6[1160]; // [rsp+10h] [rbp-488h] BYREF

v0 = open_hostweight_file(&fd, &v4);
if ( v0 )
{
v1 = v0;
if ( !error_reported )
{
log_message(196611LL, "open hostweight file error. %d (sys %d)\n", v0, v4);
error_reported = 1;
}
}
else
{
v2 = read_hostweight_file((unsigned int)fd, &v4, v6, 16LL);
v1 = v2;
if ( v2 )
{
if ( !error_reported )
{
log_message(196611LL, "open hostweight file error. %d (sys %d)\n", v2, v4);
error_reported = 1;
}
}
else
{
error_reported = 0;
v1 = hostweight_update(weight_table, v6, 16);
if ( !v1 )
hostweight_set_sm();
}
close(fd);
}
return v1;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
unsigned int v1; // ebx
unsigned int v2; // eax
unsigned int v4; // [rsp+8h] [rbp-490h] BYREF
int fd; // [rsp+Ch] [rbp-48Ch] BYREF
char v6[1160]; // [rsp+10h] [rbp-488h] BYREF

v0 = open_hostweight_file(&fd, &v4);
if ( v0 )
{
v1 = v0;
if ( !error_reported )
{
log_message(196611LL, "open hostweight file error. %d (sys %d)\n", v0, v4);
error_reported = 1;
}
}
else
{
v2 = read_hostweight_file((unsigned int)fd, &v4, v6, 16LL);
v1 = v2;
if ( v2 )
{
if ( !error_reported )
{
log_message(196611LL, "open hostweight file error. %d (sys %d)\n", v2, v4);
error_reported = 1;
}
}
else
{
error_reported = 0;
v1 = func4(weight_table, v6, 16);
if ( !v1 )
func5();
}
close(fd);
}
return v1;
}

original_code:
MTC_STATUS
hostweight_reload(void)
{
    HOST_WEIGHT_TABLE newwtable[16];
    int fd;
    int err_no;
    MTC_STATUS rs = 0;
    if ((rs = open_hostweight_file(&fd, &err_no)) != 0)
    {
        if (!error_reported)
        {
            log_message((3 | (1<<16) | (1<<17)), "open hostweight file error. %d (sys %d)\n",
                        rs, err_no);
            error_reported = 1;
        }
        return rs;
    }
    rs = read_hostweight_file(fd, &err_no, newwtable, 16);
    if (rs != 0)
    {
        if (!error_reported)
        {
            log_message((3 | (1<<16) | (1<<17)), "open hostweight file error. %d (sys %d)\n",
                        rs, err_no);
            error_reported = 1;
        }
        goto error_return;
    }
    error_reported = 0;
    rs = hostweight_update(weight_table, newwtable,
                           16);
    if (rs != 0)
    {
        goto error_return;
    }
    hostweight_set_sm();
 error_return:
    close(fd);
    return rs;
}

canonical_original_code:
int hostweight_reload()
{
    struct host_weight_table newwtable[16];
    int fd;
    int err_no;
    int rs = 0;
    if ((rs = open_hostweight_file(&fd, &err_no)) != 0)
    {
        if (!error_reported)
        {
            log_message((3 | (1<<16) | (1<<17)), "open hostweight file error. %d (sys %d)\n",
                        rs, err_no);
            error_reported = 1;
        }
        return rs;
    }
    rs = read_hostweight_file(fd, &err_no, newwtable, 16);
    if (rs != 0)
    {
        if (!error_reported)
        {
            log_message((3 | (1<<16) | (1<<17)), "open hostweight file error. %d (sys %d)\n",
                        rs, err_no);
            error_reported = 1;
        }
        goto error_return;
    }
    error_reported = 0;
    rs = hostweight_update(weight_table, newwtable,
                           16);
    if (rs != 0)
    {
        goto error_return;
    }
    hostweight_set_sm();
 error_return:
    close(fd);
    return rs;
}

variable_types: struct host_weight_table { char classname[-1]; unsigned int weight; } [16]

variable_types: fd int

variable_types: rs int


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

if ( a1 )
{
if ( a1 == 1 )
{
log_message(131078LL, "SC: hostweight_initialize(1).\n");
result = hostweight_reload();
}
else
{
log_message(131078LL, "SC: hostweight_initialize(-1).\n");
result = 0LL;
}
}
else
{
log_message(131078LL, "SC: hostweight_initialize(0).\n");
result = hostweight_initialize0();
}
return result;
}

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

if ( a1 )
{
if ( a1 == 1 )
{
log_message(131078LL, "SC: hostweight_initialize(1).\n");
result = func6();
}
else
{
log_message(131078LL, "SC: hostweight_initialize(-1).\n");
result = 0LL;
}
}
else
{
log_message(131078LL, "SC: hostweight_initialize(0).\n");
result = func0();
}
return result;
}

original_code:
MTC_S32
hostweight_initialize(
    MTC_S32 phase)
{
    MTC_STATUS ret;
    switch (phase)
    {
    case 0:
        log_message((6 | (1<<17)), "SC: hostweight_initialize(0).\n");
        ret = hostweight_initialize0();
        break;
    case 1:
        log_message((6 | (1<<17)), "SC: hostweight_initialize(1).\n");
        ret = hostweight_reload();
        break;
    case -1:
    default:
        log_message((6 | (1<<17)), "SC: hostweight_initialize(-1).\n");
        ret = 0;
        break;
    }
    return ret;
}

canonical_original_code:
int hostweight_initialize(int phase)
{
    int ret;
    switch (phase)
    {
    case 0:
        log_message((6 | (1<<17)), "SC: hostweight_initialize(0).\n");
        ret = hostweight_initialize0();
        break;
    case 1:
        log_message((6 | (1<<17)), "SC: hostweight_initialize(1).\n");
        ret = hostweight_reload();
        break;
    case -1:
    default:
        log_message((6 | (1<<17)), "SC: hostweight_initialize(-1).\n");
        ret = 0;
        break;
    }
    return ret;
}

variable_types: phase int


decompiled_code:
__int64 __fastcall uuid_strcpy(__int64 a1, char *a2)
{
char v2; // al
unsigned int v3; // edx
__int64 result; // rax
_BYTE *v5; // rax

v2 = *a2;
if ( *a2 )
{
v3 = 0;
do
{
if ( v2 != 45 )
{
if ( v3 > 0x1F )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + v3++) = v2;
}
v2 = *++a2;
}
while ( *a2 );
if ( v3 <= 0x1F )
goto LABEL_10;
result = 0LL;
}
else
{
v3 = 0;
LABEL_10:
v5 = (_BYTE *)(v3 + a1);
do
*v5++ = 0;
while ( (unsigned int)((_DWORD)v5 - a1) <= 0x1F );
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char *a2)
{
char v2; // al
unsigned int v3; // edx
__int64 result; // rax
_BYTE *v5; // rax

v2 = *a2;
if ( *a2 )
{
v3 = 0;
do
{
if ( v2 != 45 )
{
if ( v3 > 0x1F )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + v3++) = v2;
}
v2 = *++a2;
}
while ( *a2 );
if ( v3 <= 0x1F )
goto LABEL_10;
result = 0LL;
}
else
{
v3 = 0;
LABEL_10:
v5 = (_BYTE *)(v3 + a1);
do
*v5++ = 0;
while ( (unsigned int)((_DWORD)v5 - a1) <= 0x1F );
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
uuid_strcpy(
    char *packed_uuid,
    char *uuid)
{
    char *src;
    MTC_U32 count;
    count = 0;
    for (src = uuid; *src; src++)
    {
        if (*src == '-') continue;
        if (count < 32) {
            packed_uuid[count] = *src;
            count++;
        }
        else {
            return -1;
        }
    }
    if (count < 32)
    {
        for (; count < 32; count++)
        {
            packed_uuid[count] = '\0';
        }
        return -1;
    }
    return 0;
}

canonical_original_code:
static int uuid_strcpy(char *packed_uuid, char *uuid)
{
    char *src;
    unsigned int count;
    count = 0;
    for (src = uuid; *src; src++)
    {
        if (*src == '-') continue;
        if (count < 32) {
            packed_uuid[count] = *src;
            count++;
        }
        else {
            return -1;
        }
    }
    if (count < 32)
    {
        for (; count < 32; count++)
        {
            packed_uuid[count] = '\0';
        }
        return -1;
    }
    return 0;
}

variable_types:
uuid
char *

variable_types:
src
char *

variable_types:
count
unsigned int


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

if ( *(_BYTE *)(a1 + 8) )
{
if ( *(_DWORD *)(a1 + 40) )
{
if ( *(_DWORD *)(a1 + 44) )
{
if ( *(_BYTE *)(a1 + 2408) )
{
if ( *(_BYTE *)(a1 + 2472) )
{
result = 1LL;
if ( *(_DWORD *)(a1 + 2404) > 0x3Fu )
{
xhadlog(131075LL, "%s: localhost.HostID is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: StateFile is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: HeartbeatInterface is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: host num is 0\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: UDPport is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: GenerationUUID is not set\n", "valid_config");
result = 0LL;
}
return result;
}

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

if ( *(_BYTE *)(a1 + 8) )
{
if ( *(_DWORD *)(a1 + 40) )
{
if ( *(_DWORD *)(a1 + 44) )
{
if ( *(_BYTE *)(a1 + 2408) )
{
if ( *(_BYTE *)(a1 + 2472) )
{
result = 1LL;
if ( *(_DWORD *)(a1 + 2404) > 0x3Fu )
{
xhadlog(131075LL, "%s: localhost.HostID is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: StateFile is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: HeartbeatInterface is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: host num is 0\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: UDPport is not set\n", "valid_config");
result = 0LL;
}
}
else
{
xhadlog(131075LL, "%s: GenerationUUID is not set\n", "valid_config");
result = 0LL;
}
return result;
}

variable_types: struct ha_config { unsigned char version[8]; struct ha_config_common { unsigned char generation_uuid[32]; unsigned int udp_port; unsigned int hostnum; struct ha_config_host_info { unsigned char host_id[32]; unsigned int ip_address; } host[64]; unsigned int heartbeat_interval; unsigned int heartbeat_timeout; unsigned int statefile_interval; unsigned int statefile_timeout; unsigned int heartbeat_watchdog_timeout; unsigned int statefile_watchdog_timeout; unsigned int boot_join_timeout; unsigned int enable_join_timeout; unsigned int xapi_healthcheck_interval; unsigned int xapi_healthcheck_timeout; unsigned int xapi_restart_retry; unsigned int xapi_restart_timeout; unsigned int xapi_licensecheck_timeout; } common; struct ha_config_local { unsigned int localhost_index; unsigned char heartbeat_interface[64]; unsigned char statefile_path[256]; } local; } *

user_defined_types: struct ha_config { unsigned char version[8]; struct ha_config_common common; struct ha_config_local local; }

user_defined_types: struct ha_config_common { unsigned char generation_uuid[32]; unsigned int udp_port; unsigned int hostnum; struct ha_config_host_info host[64]; unsigned int heartbeat_interval; unsigned int heartbeat_timeout; unsigned int statefile_interval; unsigned int statefile_timeout; unsigned int heartbeat_watchdog_timeout; unsigned int statefile_watchdog_timeout; unsigned int boot_join_timeout; unsigned int enable_join_timeout; unsigned int xapi_healthcheck_interval; unsigned int xapi_healthcheck_timeout; unsigned int xapi_restart_retry; unsigned int xapi_restart_timeout; unsigned int xapi_licensecheck_timeout; }


decompiled_code:
_BOOL8 __fastcall valid_version(const char *a1)
{
size_t v1; // rdx
_BOOL8 result; // rax

v1 = strlen(a1);
result = 0LL;
if ( v1 <= 7 )
result = strcmp(a1, "1.0") == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
size_t v1; // rdx
_BOOL8 result; // rax

v1 = strlen(a1);
result = 0LL;
if ( v1 <= 7 )
result = strcmp(a1, "1.0") == 0;
return result;
}

original_code:
static MTC_S32
valid_version(
    char *version)
{
    if (strlen(version) >= sizeof(((HA_CONFIG *)0)->version)) {
        return 0;
    }
    if (strcmp(version, "1.0") != 0) {
        return 0;
    }
    return 1;
}

canonical_original_code:
static int valid_version(char *version)
{
    if (strlen(version) >= sizeof(((struct ha_config *)0)->version)) {
        return 0;
    }
    if (strcmp(version, "1.0") != 0) {
        return 0;
    }
    return 1;
}

variable_types:
version
char *

user_defined_types: struct ha_config_local { unsigned int localhost_index; unsigned char heartbeat_interface[64]; unsigned char statefile_path[256]; }

user_defined_types: struct ha_config_host_info { unsigned char host_id[32]; unsigned int ip_address; }


decompiled_code:
__int64 fist_initialize()
{
char **v0; // rbx
__int64 result; // rax

v0 = &fisttab;
do
{
result = fist_genhas(*v0);
*((_DWORD *)v0 + 3) = result;
v0 += 2;
}
while ( v0 != (char **)(unsigned int)((_DWORD)&fisttab + 608) );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
char **v0; // rbx
__int64 result; // rax

v0 = &fisttab;
do
{
result = func0(*v0);
*((_DWORD *)v0 + 3) = result;
v0 += 2;
}
while ( v0 != (char **)(unsigned int)((_DWORD)&fisttab + 608) );
return result;
}

original_code:
void
fist_initialize()
{
    int index;
    for (index = 0; index < sizeof(fisttab) / sizeof(struct _fisttab); index++)
    {
        fisttab[index].hash = _fist_genhas(fisttab[index].name);
    }
}

user_defined_types: struct _fisttab { char *name; unsigned char sticky; unsigned char enabled; int hash; }


chop

decompiled_code:
size_t __fastcall chop(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
if ( (_DWORD)result )
{
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 10 )
*v2 = 0;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
if ( (_DWORD)result )
{
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 10 )
*v2 = 0;
}
return result;
}

original_code:
void chop(MTC_S8 *line)
{
    MTC_U32 len = strlen(line);
    if (len > 0 && line[len - 1] == '\n')
    {
        line[len - 1] = '\0';
    }
}

canonical_original_code:
void chop(char *line)
{
    unsigned int len = strlen(line);
    if (len > 0 && line[len - 1] == '\n')
    {
        line[len - 1] = '\0';
    }
}

variable_types:
line
char *

variable_types:
len
unsigned int


decompiled_code:
int __fastcall lock_pages(__int64 a1, __int64 a2)
{
return mlock((const void *)(a1 & 0xFFFFFFFFFFFFF000LL), (a2 + 4095) & 0xFFFFFFFFFFFFF000LL);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
return mlock((const void *)(a1 & 0xFFFFFFFFFFFFF000LL), (a2 + 4095) & 0xFFFFFFFFFFFFF000LL);
}

original_code:
int
lock_pages(
    void *addr,
    size_t len)
{
    int e = 0;
    return e;
}

canonical_original_code:
int lock_pages(void *addr, unsigned long len)
{
    int e = 0;
    return e;
}

variable_types:
addr
void *

variable_types:
len
unsigned long

variable_types: e int


decompiled_code:
int __fastcall unlock_pages(__int64 a1, __int64 a2)
{
return munlock((const void *)(a1 & 0xFFFFFFFFFFFFF000LL), (a2 + 4095) & 0xFFFFFFFFFFFFF000LL);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2)
{
return munlock((const void *)(a1 & 0xFFFFFFFFFFFFF000LL), (a2 + 4095) & 0xFFFFFFFFFFFFF000LL);
}

original_code:
void
unlock_pages(
    void *addr,
    size_t len)
{
}

canonical_original_code:
void unlock_pages(void *addr, unsigned long len)
{
}


decompiled_code:
int log_message(__int64 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
fprintf(stderr, a2, va);
return fflush(stderr);
}

canonical_decompiled_code:
int func0(__int64 a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
fprintf(stderr, a2, va);
return fflush(stderr);
}

original_code:
void log_message(MTC_S32 priority, PMTC_S8 fmt, ...)
{
    time_t now;
    struct tm *ptm;
    va_list ap;
    if (!initialized)
    {
        return;
    }
    pthread_spin_lock(&lock);
    if (priority & (1<<17) && fpLogfile != ((void *)0) && privatelogflag)
    {
        MTC_S32 i = 0;
        while (prioritynames[i].c_val != -1 &&
               prioritynames[i].c_val != ((priority) & 0x07))
        {
            i++;
        }
        now = time(((void *)0));
        ptm = localtime(&now);
        fprintf(fpLogfile, "%s %02d %02d:%02d:%02d %s %04d [%s] ",
                monthnames[ptm->tm_mon], ptm->tm_mday,
                ptm->tm_hour, ptm->tm_min, ptm->tm_sec,
                ptm->tm_zone, 1900 + ptm->tm_year, prioritynames[i].c_name);
        __builtin_va_start(ap,fmt);
        vfprintf(fpLogfile, fmt, ap);
        __builtin_va_end(ap);
        fflush(fpLogfile);
    }
    if (priority & (1<<16))
    {
        __builtin_va_start(ap,fmt);
        vsyslog(((priority) & 0x07), fmt, ap);
        __builtin_va_end(ap);
    }
    pthread_spin_unlock(&lock);
}

variable_types: priority int

variable_types:
fmt
char *

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: i int


canonical_decompiled_code:
size_t __fastcall func1(const char *a1)
{
size_t result; // rax
const char *v2; // rbx

result = strlen(a1);
if ( (_DWORD)result )
{
v2 = &a1[(unsigned int)(result - 1)];
if ( *v2 == 10 )
*v2 = 0;
}
return result;
}


repo: xerpi/Znake

original_code:
void znake_update(struct znake_t *znake)
{
    if(znake->direction != DIR_NONE) {
        if(znake->body_length == 0) {
            znake->tail.x = znake->head.x;
            znake->tail.y = znake->head.y;
        } else {
            znake->tail.x = znake->body[znake->body_length-1]->x;
            znake->tail.y = znake->body[znake->body_length-1]->y;
            int i;
            for(i = znake->body_length-1; i > 0; i--) {
                znake->body[i]->x = znake->body[i-1]->x;
                znake->body[i]->y = znake->body[i-1]->y;
            }
            znake->body[0]->x = znake->head.x;
            znake->body[0]->y = znake->head.y;
        }
    }
    switch(znake->direction)
    {
    case DIR_UP:
        znake->head.y--;
        break;
    case DIR_DOWN:
        znake->head.y++;
        break;
    case DIR_RIGHT:
        znake->head.x++;
        break;
    case DIR_LEFT:
        znake->head.x--;
        break;
    default:
        break;
    }
}

variable_types: struct znake_t { struct vector2d { int x; int y; } head; struct vector2d **body; struct vector2d tail; enum znake_dir_t { DIR_NONE=0, DIR_UP=1, DIR_DOWN=2, DIR_RIGHT=3, DIR_LEFT=4 } direction; int body_length; } *

user_defined_types: struct znake_t { struct vector2d head; struct vector2d **body; struct vector2d tail; enum znake_dir_t direction; int body_length; }


original_code:
void znake_add_body(struct znake_t *znake)
{
    if(znake->body_length < znake->max_size) {
        znake->body[znake->body_length] = malloc(sizeof(struct vector2d));
        znake->body[znake->body_length]->x = znake->tail.x;
        znake->body[znake->body_length]->y = znake->tail.y;
        znake->body_length++;
    }
}

user_defined_types: enum znake_dir_t { DIR_NONE=0, DIR_UP=1, DIR_DOWN=2, DIR_RIGHT=3, DIR_LEFT=4 }


original_code:
int znake_self_collision(struct znake_t *znake)
{
    if(znake->body_length == 0) {
        return 0;
    } else {
        if((znake->head.x == znake->tail.x) && (znake->head.y == znake->tail.y)) {
            return 1;
        }
        int i;
        for(i = 0; i < znake->body_length; i++) {
            if((znake->head.x == znake->body[i]->x) && (znake->head.y == znake->body[i]->y)) {
                return 1;
            }
        }
    }
    return 0;
}


decompiled_code:
_BOOL8 __fastcall znake_head_collision(_DWORD *a1, int a2, int a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == a2 )
result = a1[1] == a3;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1, int a2, int a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == a2 )
result = a1[1] == a3;
return result;
}

original_code:
int znake_head_collision(struct znake_t *znake, int x, int y)
{
    if((znake->head.x == x) && (znake->head.y == y)) {
        return 1;
    }
    return 0;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall znake_collisions_with(_DWORD *a1, int a2, int a3)
{
int v3; // ecx
__int64 result; // rax

if ( *a1 != a2 || (result = 1LL, a1[1] != a3) )
{
if ( a1[4] != a2 || (result = 1LL, a1[5] != a3) )
{
v3 = a1[7];
result = 0LL;
if ( v3 > 0 )
{
do
{
if ( *a1 == a2 && a1[1] == a3 )
return 1LL;
LODWORD(result) = result + 1;
}
while ( (_DWORD)result != v3 );
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, int a2, int a3)
{
int v3; // ecx
__int64 result; // rax

if ( *a1 != a2 || (result = 1LL, a1[1] != a3) )
{
if ( a1[4] != a2 || (result = 1LL, a1[5] != a3) )
{
v3 = a1[7];
result = 0LL;
if ( v3 > 0 )
{
do
{
if ( *a1 == a2 && a1[1] == a3 )
return 1LL;
LODWORD(result) = result + 1;
}
while ( (_DWORD)result != v3 );
result = 0LL;
}
}
}
return result;
}

original_code:
int znake_collisions_with(struct znake_t *znake, int x, int y)
{
    if((znake->head.x == x) && (znake->head.y == y)) {
        return 1;
    }
    if((znake->tail.x == x) && (znake->tail.y == y)) {
        return 1;
    }
    int i;
    for(i = 0; i < znake->body_length; i++) {
        if((znake->head.x == x) && (znake->head.y == y)) {
            return 1;
        }
    }
    return 0;
}


original_code:
void znake_clear(struct znake_t *znake)
{
    if(znake->body_length > 0) {
        int i;
        for(i = 0; i < znake->body_length; i++) {
            free(znake->body[i]);
        }
        znake->body_length = 0;
    }
}


decompiled_code:
void __fastcall znake_init(__int64 a1, int a2, int a3, int a4)
{
*(_QWORD *)(a1 + 8) = malloc(8LL * a4);
*(_DWORD *)(a1 + 28) = 0;
*(_DWORD *)(a1 + 32) = a4;
znake_reset((_DWORD *)a1, a2, a3);
}

original_code:
void znake_init(struct znake_t *znake, int x, int y, int max_size)
{
    znake->body = malloc(sizeof(struct vector2d *) * max_size);
    znake->body_length = 0;
    znake->max_size = max_size;
    znake_reset(znake, x, y);
}


decompiled_code:
void __fastcall znake_kill(__int64 a1)
{
znake_clear(a1);
free(*(void **)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
func10(a1);
free(*(void **)(a1 + 8));
}

original_code:
void znake_kill(struct znake_t *znake)
{
    znake_clear(znake);
    free(znake->body);
}


repo: xerpi/pspload

decompiled_code:
ssize_t __fastcall pspload_send(int a1, const void *a2, unsigned int a3)
{
ssize_t v3; // rbx

v3 = send(a1, a2, a3, 0);
if ( v3 == -1 )
perror("Error sending data");
return v3;
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1, const void *a2, unsigned int a3)
{
ssize_t v3; // rbx

v3 = send(a1, a2, a3, 0);
if ( v3 == -1 )
perror("Error sending data");
return v3;
}

original_code:
ssize_t pspload_send(int sock, void *data, uint32_t size)
{
    ssize_t ret = send(sock, data, size, 0);
    if (ret == -1) {
        perror("Error sending data");
    }
    return ret;
}

canonical_original_code:
long pspload_send(int sock, void *data, unsigned int size)
{
    long ret = send(sock, data, size, 0);
    if (ret == -1) {
        perror("Error sending data");
    }
    return ret;
}

variable_types: sock int

variable_types:
data
void *

variable_types:
size
unsigned int

variable_types: ret long

return_type: long


decompiled_code:
int print_usage()
{
return puts("Usage: pspload file <args>\nwill send file to the PSP");
}

canonical_decompiled_code:
int func9()
{
return puts("Usage: pspload file <args>\nwill send file to the PSP");
}

original_code:
void print_usage()
{
    printf("Usage: pspload file <args>\nwill send file to the PSP\n");
}


redimloe

repo: xhub/vinci

decompiled_code:
__int64 __fastcall redimloe(int *a1)
{
int v1; // esi
__int64 result; // rax

v1 = *a1;
*a1 += 5;
result = my_realloc(*((_QWORD *)a1 + 1), 8LL * (v1 + 6), 40LL);
*((_QWORD *)a1 + 1) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v1; // esi
__int64 result; // rax

v1 = *a1;
*a1 += 5;
result = my_realloc(*((_QWORD *)a1 + 1), 8LL * (v1 + 6), 40LL);
*((_QWORD *)a1 + 1) = result;
return result;
}

original_code:
static void redimloe (T_VertexSet *s)
{
   s -> maxel += 5;
   s -> loe = (T_Vertex **)
              my_realloc (s -> loe, (s -> maxel + 1) * sizeof (T_Vertex *),
                          5 * sizeof (T_Vertex *));
}

canonical_original_code:
static void redimloe(struct T_VertexSet *s)
{
   s -> maxel += 5;
   s -> loe = (struct T_Vertex **)
              my_realloc (s -> loe, (s -> maxel + 1) * sizeof (struct T_Vertex *),
                          5 * sizeof (struct T_Vertex *));
}

variable_types: struct T_VertexSet { int maxel; int lastel; struct T_Vertex { double *coords; int no; } **loe; } *

user_defined_types: struct T_VertexSet { int maxel; int lastel; struct T_Vertex **loe; }


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

v0 = G_d;
my_malloc(8LL * (G_d + 6));
return (unsigned int)(v0 + 5) | 0xFFFFFFFF00000000LL;
}

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

v0 = G_d;
my_malloc(8LL * (G_d + 6));
return (unsigned int)(v0 + 5) | 0xFFFFFFFF00000000LL;
}

original_code:
T_VertexSet create_empty_set ()
{ T_VertexSet s;
   s.maxel = G_d + 5;
   s.loe = ((void *)0);
   s.lastel = -1;
   s.loe = (T_Vertex **) my_malloc ((s.maxel + 1) * sizeof (T_Vertex *));
   return s;
}

canonical_original_code:
struct T_VertexSet create_empty_set()
{ struct T_VertexSet s;
   s.maxel = G_d + 5;
   s.loe = ((void *)0);
   s.lastel = -1;
   s.loe = (struct T_Vertex **) my_malloc ((s.maxel + 1) * sizeof (struct T_Vertex *));
   return s;
}

variable_types: struct T_VertexSet { int maxel; int lastel; struct T_Vertex { double *coords; int no; } **loe; }


decompiled_code:
__int64 __fastcall free_set(int a1, __int64 a2)
{
return my_free(a2, 8LL * (a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
return my_free(a2, 8LL * (a1 + 1));
}

original_code:
void free_set (T_VertexSet s)
{
   my_free (s.loe, (s.maxel + 1) * sizeof (T_Vertex *));
}

canonical_original_code:
void free_set(struct T_VertexSet s)
{
   my_free (s.loe, (s.maxel + 1) * sizeof (struct T_Vertex *));
}

user_defined_types: struct T_Vertex { double *coords; int no; }


decompiled_code:
__int64 __fastcall free_set_and_vertices(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( a1 >= 0 )
{
v2 = 0LL;
do
free_vertex(*(_QWORD *)(a2 + 8 * v2++));
while ( SHIDWORD(a1) >= (int)v2 );
}
return free_set(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( a1 >= 0 )
{
v2 = 0LL;
do
free_vertex(*(_QWORD *)(a2 + 8 * v2++));
while ( SHIDWORD(a1) >= (int)v2 );
}
return func3(a1, a2);
}

original_code:
void free_set_and_vertices (T_VertexSet s)
{ int i;
   for (i = 0; i <= s.lastel; i++) free_vertex (s.loe [i]);
   free_set (s);
}

canonical_original_code:
void free_set_and_vertices(struct T_VertexSet s)
{ int i;
   for (i = 0; i <= s.lastel; i++) free_vertex (s.loe [i]);
   free_set (s);
}


decompiled_code:
void __fastcall clear_set(__int64 a1)
{
*(_DWORD *)(a1 + 4) = -1;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
*(_DWORD *)(a1 + 4) = -1;
}

original_code:
void clear_set (T_VertexSet *s)
{ (*s).lastel = -1;
}

canonical_original_code:
void clear_set(struct T_VertexSet *s)
{ (*s).lastel = -1;
}


decompiled_code:
__int64 __fastcall duplicate_set(__int64 a1, const void *a2)
{
void *v2; // r12

v2 = (void *)my_malloc(8LL * (HIDWORD(a1) + 1));
memcpy(v2, a2, 8LL * (HIDWORD(a1) + 1));
return (a1 >> 32 << 32) | HIDWORD(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2)
{
void *v2; // r12

v2 = (void *)my_malloc(8LL * (HIDWORD(a1) + 1));
memcpy(v2, a2, 8LL * (HIDWORD(a1) + 1));
return (a1 >> 32 << 32) | HIDWORD(a1);
}

original_code:
T_VertexSet duplicate_set (T_VertexSet s)
{ T_VertexSet newset;
   newset.maxel = s.lastel;
   newset.lastel = s.lastel;
   newset.loe = (T_Vertex **) my_malloc ((s.lastel + 1) * sizeof (T_Vertex *));
   memcpy (newset.loe, s.loe, (s.lastel + 1) * sizeof (T_Vertex *));
   return newset;
}

canonical_original_code:
struct T_VertexSet duplicate_set(struct T_VertexSet s)
{ struct T_VertexSet newset;
   newset.maxel = s.lastel;
   newset.lastel = s.lastel;
   newset.loe = (struct T_Vertex **) my_malloc ((s.lastel + 1) * sizeof (struct T_Vertex *));
   memcpy (newset.loe, s.loe, (s.lastel + 1) * sizeof (struct T_Vertex *));
   return newset;
}

variable_types:
s
struct T_VertexSet

return_type: struct T_VertexSet { int maxel; int lastel; struct T_Vertex { double *coords; int no; } **loe; }


original_code:
void renumber_vertices ()
{
   int i, j, k;
   T_Vertex *tmp_vertex;
   boolean *tmp_incidence;
   for (i = 0; i < G_n; i++)
      G_Vertices.loe [i] -> no = 0;
   for (i = 0; i < G_n; i++)
      for (j = 0; j < G_m; j++)
         if (G_Incidence [i][j])
            G_Vertices.loe [i] -> no --;
   for (i = 0; i < G_n - 1; i++)
   {
      j = i;
      for (k = i + 1; k < G_n; k++)
         if (G_Vertices.loe [k] -> no < G_Vertices.loe [j] -> no)
            j = k;
      if (i != j)
      {
         tmp_vertex = G_Vertices.loe [i];
         G_Vertices.loe [i] = G_Vertices.loe [j];
         G_Vertices.loe [j] = tmp_vertex;
         if (G_Incidence != ((void *)0))
         {
            tmp_incidence = G_Incidence [i];
            G_Incidence [i] = G_Incidence [j];
            G_Incidence [j] = tmp_incidence;
         }
      }
   }
   for (i = 0; i < G_n; i++)
      G_Vertices.loe [i] -> no = i;
   printf ("Vertices reordered.\n");
}

canonical_original_code:
void renumber_vertices()
{
   int i; int j; int k;
   struct T_Vertex *tmp_vertex;
   unsigned char *tmp_incidence;
   for (i = 0; i < G_n; i++)
      G_Vertices.loe [i] -> no = 0;
   for (i = 0; i < G_n; i++)
      for (j = 0; j < G_m; j++)
         if (G_Incidence [i][j])
            G_Vertices.loe [i] -> no --;
   for (i = 0; i < G_n - 1; i++)
   {
      j = i;
      for (k = i + 1; k < G_n; k++)
         if (G_Vertices.loe [k] -> no < G_Vertices.loe [j] -> no)
            j = k;
      if (i != j)
      {
         tmp_vertex = G_Vertices.loe [i];
         G_Vertices.loe [i] = G_Vertices.loe [j];
         G_Vertices.loe [j] = tmp_vertex;
         if (G_Incidence != ((void *)0))
         {
            tmp_incidence = G_Incidence [i];
            G_Incidence [i] = G_Incidence [j];
            G_Incidence [j] = tmp_incidence;
         }
      }
   }
   for (i = 0; i < G_n; i++)
      G_Vertices.loe [i] -> no = i;
   printf ("Vertices reordered.\n");
}

variable_types: j int

variable_types: k int

variable_types: struct T_Vertex { double *coords; int no; } *


original_code:
rational normalise_vertices ()
{
   rational *scaling = create_vector ();
   rational scaling_volume = 1;
   rational absolute;
   int i, j;
   for (j = 0; j < G_d; j ++)
      scaling [j] = -1;
   for (j = 0; j < G_d; j++)
      for (i = 0; i <= G_Vertices.lastel; i++)
      { absolute = fabs (G_Vertices.loe [i] -> coords [j]);
         if (absolute > scaling [j])
            scaling [j] = absolute;
      }
   for (j = 0; j < G_d; j++)
   { scaling_volume *= scaling [j];
      for (i = 0; i <= G_Vertices.lastel; i++)
         G_Vertices.loe [i] -> coords [j] /= scaling [j];
   }
   my_free(scaling, sizeof(rational));
   return scaling_volume;
}

canonical_original_code:
double normalise_vertices()
{
   double *scaling = create_vector ();
   double scaling_volume = 1;
   double absolute;
   int i; int j;
   for (j = 0; j < G_d; j ++)
      scaling [j] = -1;
   for (j = 0; j < G_d; j++)
      for (i = 0; i <= G_Vertices.lastel; i++)
      { absolute = fabs (G_Vertices.loe [i] -> coords [j]);
         if (absolute > scaling [j])
            scaling [j] = absolute;
      }
   for (j = 0; j < G_d; j++)
   { scaling_volume *= scaling [j];
      for (i = 0; i <= G_Vertices.lastel; i++)
         G_Vertices.loe [i] -> coords [j] /= scaling [j];
   }
   my_free(scaling, sizeof(rational));
   return scaling_volume;
}

variable_types:
scaling
double *

variable_types: absolute double

return_type: double


empty

decompiled_code:
bool __fastcall empty(__int64 a1)
{
return HIDWORD(a1) == -1;
}

canonical_decompiled_code:
bool __fastcall func9(__int64 a1)
{
return HIDWORD(a1) == -1;
}

original_code:
boolean empty (T_VertexSet s)
{
   return (s.lastel == -1);
}

canonical_original_code:
unsigned char empty(struct T_VertexSet s)
{
   return (s.lastel == -1);
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall is_in_hyperplane(__int64 a1, int a2)
{
return *(unsigned __int8 *)(*(_QWORD *)(G_Incidence + 8LL * *(int *)(a1 + 8)) + a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
return *(unsigned __int8 *)(*(_QWORD *)(G_Incidence + 8LL * *(int *)(a1 + 8)) + a2);
}

original_code:
boolean is_in_hyperplane (T_Vertex *e, int j)
{
   return G_Incidence [e -> no][j];
}

canonical_original_code:
unsigned char is_in_hyperplane(struct T_Vertex *e, int j)
{
   return G_Incidence [e -> no][j];
}


decompiled_code:
bool __fastcall are_equal_sets(__int64 a1, const void *a2, __int64 a3, const void *a4)
{
bool result; // al
bool v6; // dl

result = 0;
if ( HIDWORD(a1) == HIDWORD(a3) )
{
v6 = empty(a1);
result = 1;
if ( !v6 )
result = memcmp(a2, a4, 8LL * (HIDWORD(a1) + 1)) == 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1, const void *a2, __int64 a3, const void *a4)
{
bool result; // al
bool v6; // dl

result = 0;
if ( HIDWORD(a1) == HIDWORD(a3) )
{
v6 = func9(a1);
result = 1;
if ( !v6 )
result = memcmp(a2, a4, 8LL * (HIDWORD(a1) + 1)) == 0;
}
return result;
}

original_code:
boolean are_equal_sets (T_VertexSet s1, T_VertexSet s2)
{
   if (s1.lastel != s2.lastel) return 0;
   else if (empty (s1)) return 1;
   else
      return (!(memcmp (s1.loe, s2.loe, (s1.lastel + 1) * sizeof (T_Vertex *))));
}

canonical_original_code:
unsigned char are_equal_sets(struct T_VertexSet s1, struct T_VertexSet s2)
{
   if (s1.lastel != s2.lastel) return 0;
   else if (empty (s1)) return 1;
   else
      return (!(memcmp (s1.loe, s2.loe, (s1.lastel + 1) * sizeof (struct T_Vertex *))));
}


decompiled_code:
void __fastcall copy_set(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

clear_set(a3);
if ( a1 >= 0 )
{
v4 = 0LL;
do
add_element(a3, *(_QWORD *)(a2 + 8 * v4++));
while ( SHIDWORD(a1) >= (int)v4 );
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

func5(a3);
if ( a1 >= 0 )
{
v4 = 0LL;
do
add_element(a3, *(_QWORD *)(a2 + 8 * v4++));
while ( SHIDWORD(a1) >= (int)v4 );
}
}

original_code:
void copy_set (T_VertexSet s1, T_VertexSet *s2)
{ int i;
   clear_set (s2);
   for (i = 0; i <= s1.lastel; i++) add_element (s2, s1.loe [i]);
}

canonical_original_code:
void copy_set(struct T_VertexSet s1, struct T_VertexSet *s2)
{ int i;
   clear_set (s2);
   for (i = 0; i <= s1.lastel; i++) add_element (s2, s1.loe [i]);
}


original_code:
boolean delete_element (T_VertexSet *s, T_Vertex *e)
{ int j, position;
   position = position_of_element (e, *s);
   if (position == -1) return 0;
   else
   { for (j = position; j < s -> lastel; j++)
         s -> loe [j] = s -> loe [j+1];
      s -> lastel --;
      return 1;
   }
}

canonical_original_code:
unsigned char delete_element(struct T_VertexSet *s, struct T_Vertex *e)
{ int j; int position;
   position = position_of_element (e, *s);
   if (position == -1) return 0;
   else
   { for (j = position; j < s -> lastel; j++)
         s -> loe [j] = s -> loe [j+1];
      s -> lastel --;
      return 1;
   }
}

variable_types:
e
struct T_Vertex *

variable_types: position int


original_code:
void intersect_with_hyperplane (T_VertexSet s, int j, T_VertexSet *inter)
{
   int i;
   inter -> lastel = -1;
   if (!(empty (s)))
      for (i = 0; i <= s.lastel; i++)
         if (is_in_hyperplane (s.loe [i], j))
            {
               if (inter -> lastel == inter -> maxel) redimloe (inter);
               inter -> loe [++ inter -> lastel] = s.loe [i];
            }
}

canonical_original_code:
void intersect_with_hyperplane(struct T_VertexSet s, int j, struct T_VertexSet *inter)
{
   int i;
   inter -> lastel = -1;
   if (!(empty (s)))
      for (i = 0; i <= s.lastel; i++)
         if (is_in_hyperplane (s.loe [i], j))
            {
               if (inter -> lastel == inter -> maxel) redimloe (inter);
               inter -> loe [++ inter -> lastel] = s.loe [i];
            }
}

variable_types:
inter
struct T_VertexSet *

variable_types: i int


decompiled_code:
__int64 create_empty_superset()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func16()
{
return 0LL;
}

original_code:
T_VertexSuperset *create_empty_superset ()
{ return ((void *)0);
}

canonical_original_code:
struct T_VertexSuperset *create_empty_superset()
{ return ((void *)0);
}

return_type: struct T_VertexSuperset { struct T_VertexSuperset *next; struct T_VertexSet { int maxel; int lastel; struct T_Vertex { double *coords; int no; } **loe; } content; } *

user_defined_types: struct T_VertexSuperset { struct T_VertexSuperset *next; struct T_VertexSet content; }


decompiled_code:
bool __fastcall is_in_superset(__int64 a1, const void *a2, __int64 **a3)
{
__int64 **i; // rbx

for ( i = a3; i; i = (__int64 **)*i )
{
if ( are_equal_sets((__int64)i[1], i[2], a1, a2) )
break;
}
return i != 0LL;
}

canonical_decompiled_code:
bool __fastcall func19(__int64 a1, const void *a2, __int64 **a3)
{
__int64 **i; // rbx

for ( i = a3; i; i = (__int64 **)*i )
{
if ( func12((__int64)i[1], i[2], a1, a2) )
break;
}
return i != 0LL;
}

original_code:
boolean is_in_superset (T_VertexSet s, T_VertexSuperset *S)
{ while (S != ((void *)0) && !are_equal_sets (S -> content, s)) S = S -> next;
   if (S == ((void *)0)) return 0;
   else return 1;
}

canonical_original_code:
unsigned char is_in_superset(struct T_VertexSet s, struct T_VertexSuperset *S)
{ while (S != ((void *)0) && !are_equal_sets (S -> content, s)) S = S -> next;
   if (S == ((void *)0)) return 0;
   else return 1;
}

variable_types: struct T_VertexSuperset { struct T_VertexSuperset *next; struct T_VertexSet content; } *


decompiled_code:
__int64 __fastcall determine_data_type(const char *a1)
{
unsigned int v1; // ecx

v1 = 1;
if ( !strcmp(a1, "integer") )
return v1;
v1 = 2;
if ( !strcmp(a1, "real") )
return v1;
v1 = 3;
if ( !strcmp(a1, "rational") )
return v1;
fprintf(stderr, "\n***** ERROR: '%s' is not a known data type; use integer, real or rational.", a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // ecx

v1 = 1;
if ( !strcmp(a1, "integer") )
return v1;
v1 = 2;
if ( !strcmp(a1, "real") )
return v1;
v1 = 3;
if ( !strcmp(a1, "rational") )
return v1;
fprintf(stderr, "\n***** ERROR: '%s' is not a known data type; use integer, real or rational.", a1);
return 0LL;
}

original_code:
int determine_data_type (char *data_type)
{
   if (!strcmp (data_type, "integer"))
      return 1;
   else if (!strcmp (data_type, "real"))
      return 2;
   else if (!strcmp (data_type, "rational"))
      return 3;
   else
   { fprintf (stderr, "\n***** ERROR: '%s' is not a known data type; use integer, real or rational.",
              data_type);
      return 0;
   }
}

canonical_original_code:
int determine_data_type(char *data_type)
{
   if (!strcmp (data_type, "integer"))
      return 1;
   else if (!strcmp (data_type, "real"))
      return 2;
   else if (!strcmp (data_type, "rational"))
      return 3;
   else
   { fprintf (stderr, "\n***** ERROR: '%s' is not a known data type; use integer, real or rational.",
              data_type);
      return 0;
   }
}


original_code:
void sread_rational_value (char *s, rational *value)
{
   char *numerator_s, *denominator_s = ((void *)0), *position, token;
   int sign = 1, i;
   rational numerator, denominator;
   numerator_s = s;
   if (s [0] == '-')
   { sign = -1;
      numerator_s++;
   }
   else if (s [0] == '+')
      numerator_s++;
   position = strchr (numerator_s, '/');
   if (position != ((void *)0))
   { *position = '\0';
      denominator_s = position + 1;
   };
   numerator = 0;
   for (i = 0; i < strlen (numerator_s); i++)
   { token = numerator_s [i];
      if (strchr ("0123456789", token))
         numerator = 10 * numerator + (int) token - 48;
   }
   if (position != ((void *)0))
   { denominator = 0;
      for (i = 0; i < strlen (denominator_s); i++)
      { token = denominator_s [i];
         if (strchr ("0123456789", token))
            denominator = 10 * denominator + (int) token - 48;
      }
   }
   else denominator = 1;
   *value = sign * numerator / denominator;
}

canonical_original_code:
void sread_rational_value(char *s, double *value)
{
   char *numerator_s; char *denominator_s = ((void *)0); char *position; char token;
   int sign = 1; int i;
   double numerator; double denominator;
   numerator_s = s;
   if (s [0] == '-')
   { sign = -1;
      numerator_s++;
   }
   else if (s [0] == '+')
      numerator_s++;
   position = strchr (numerator_s, '/');
   if (position != ((void *)0))
   { *position = '\0';
      denominator_s = position + 1;
   };
   numerator = 0;
   for (i = 0; i < strlen (numerator_s); i++)
   { token = numerator_s [i];
      if (strchr ("0123456789", token))
         numerator = 10 * numerator + (int) token - 48;
   }
   if (position != ((void *)0))
   { denominator = 0;
      for (i = 0; i < strlen (denominator_s); i++)
      { token = denominator_s [i];
         if (strchr ("0123456789", token))
            denominator = 10 * denominator + (int) token - 48;
      }
   }
   else denominator = 1;
   *value = sign * numerator / denominator;
}

variable_types:
s
char *

variable_types:
value
double *

variable_types:
position
char *

variable_types: token char

variable_types: sign int

variable_types: numerator double

variable_types: denominator double


decompiled_code:
__int64 compute_incidence()
{
__int64 result; // rax
__int64 i; // r9
int j; // er8
__int64 v3; // rdi
__int64 v4; // rcx
double v5; // xmm1_8
__int64 v6; // rax

result = create_incidence();
for ( i = 0LL; G_m > (int)i; ++i )
{
v3 = 0LL;
for ( j = 0; G_n > j; v3 += 8LL )
{
v4 = *(_QWORD *)(G_Hyperplanes + 8 * i);
v5 = *(double *)(v4 + 8LL * G_d);
if ( G_d > 0 )
{
v6 = 0LL;
do
{
v5 = v5 - *(double *)(**(_QWORD **)(G_Vertices[1] + v3) + 8 * v6) * *(double *)(v4 + 8 * v6);
++v6;
}
while ( v6 != G_d );
}
result = *(_QWORD *)(G_Incidence + v3);
*(_BYTE *)(result + i) = COERCE_DOUBLE(*(_QWORD *)&v5 & LC24) < 0.000001;
++j;
}
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 i; // r9
int j; // er8
__int64 v3; // rdi
__int64 v4; // rcx
double v5; // xmm1_8
__int64 v6; // rax

result = create_incidence();
for ( i = 0LL; G_m > (int)i; ++i )
{
v3 = 0LL;
for ( j = 0; G_n > j; v3 += 8LL )
{
v4 = *(_QWORD *)(G_Hyperplanes + 8 * i);
v5 = *(double *)(v4 + 8LL * G_d);
if ( G_d > 0 )
{
v6 = 0LL;
do
{
v5 = v5 - *(double *)(**(_QWORD **)(G_Vertices[1] + v3) + 8 * v6) * *(double *)(v4 + 8 * v6);
++v6;
}
while ( v6 != G_d );
}
result = *(_QWORD *)(G_Incidence + v3);
*(_BYTE *)(result + i) = COERCE_DOUBLE(*(_QWORD *)&v5 & LC24) < 0.000001;
++j;
}
}
return result;
}

original_code:
void compute_incidence ()
{ int i, j, k;
   real diff;
   create_incidence ();
   for (j = 0; j < G_m; j++)
      for (i = 0; i < G_n; i++)
      {
         diff = G_Hyperplanes [j][G_d];
         for (k = 0; k < G_d; k++)
            diff -= (G_Vertices.loe [i] -> coords [k]) * G_Hyperplanes [j][k];
         if (fabs (diff) < 1e-6)
            G_Incidence [i][j] = 1;
         else
            G_Incidence [i][j] = 0;
     }
}

canonical_original_code:
void compute_incidence()
{ int i; int j; int k;
   double diff;
   create_incidence ();
   for (j = 0; j < G_m; j++)
      for (i = 0; i < G_n; i++)
      {
         diff = G_Hyperplanes [j][G_d];
         for (k = 0; k < G_d; k++)
            diff -= (G_Vertices.loe [i] -> coords [k]) * G_Hyperplanes [j][k];
         if (fabs (diff) < 1e-6)
            G_Incidence [i][j] = 1;
         else
            G_Incidence [i][j] = 0;
     }
}

variable_types: j int

variable_types: diff double


repo: xianjimli/png-image

decompiled_code:
void __fastcall png_image_destroy(void *ptr)
{
void *v1; // r13
int v2; // eax
void **v3; // rbx
__int64 v4; // r12

if ( ptr )
{
v1 = (void *)*((_QWORD *)ptr + 3);
if ( v1 )
{
v2 = *((_DWORD *)ptr + 3);
if ( v2 )
{
v3 = (void **)*((_QWORD *)ptr + 3);
v4 = (__int64)v1 + 8 * (unsigned int)(v2 - 1) + 8;
do
free(*v3++);
while ( v3 != (void **)v4 );
}
free(v1);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
void *v1; // r13
int v2; // eax
void **v3; // rbx
__int64 v4; // r12

if ( ptr )
{
v1 = (void *)*((_QWORD *)ptr + 3);
if ( v1 )
{
v2 = *((_DWORD *)ptr + 3);
if ( v2 )
{
v3 = (void **)*((_QWORD *)ptr + 3);
v4 = (__int64)v1 + 8 * (unsigned int)(v2 - 1) + 8;
do
free(*v3++);
while ( v3 != (void **)v4 );
}
free(v1);
}
free(ptr);
}
}

original_code:
void png_image_destroy(ImageData* image)
{
 unsigned int y = 0;
 if(image) {
  unsigned int height = image->height;
  unsigned char** row_pointers = image->rows;
  if(row_pointers) {
   for (y=0; y<height; y++)
   {
    free(row_pointers[y]);
   }
   free(row_pointers);
  }
  image->rows = ((void *)0);
  free(image);
 }
 return;
}

canonical_original_code:
void png_image_destroy(struct _ImageData *image)
{
 unsigned int y = 0;
 if(image) {
  unsigned int height = image->height;
  unsigned char **row_pointers = image->rows;
  if(row_pointers) {
   for (y=0; y<height; y++)
   {
    free(row_pointers[y]);
   }
   free(row_pointers);
  }
  image->rows = ((void *)0);
  free(image);
 }
 return;
}

variable_types: struct _ImageData { int bit_depth; int color_type; unsigned int width; unsigned int height; unsigned int rowbytes; unsigned char **rows; } *

variable_types:
y
unsigned int

variable_types:
height
unsigned int


decompiled_code:
void __fastcall process_file(__int64 a1)
{
int v1; // esi
int v2; // edx
int i; // ecx
int v4; // eax

v1 = *(_DWORD *)(a1 + 12);
v2 = *(_DWORD *)(a1 + 8);
if ( v1 )
{
for ( i = 0; i != v1; ++i )
{
v4 = 0;
if ( v2 )
{
do
++v4;
while ( v2 != v4 );
}
}
}
}

original_code:
void process_file(ImageData* image)
{
 int x, y;
 unsigned int height = image->height;
 unsigned int width = image->width;
 png_bytep* row_pointers = image->rows;
 for (y=0; y<height; y++) {
   png_byte* row = row_pointers[y];
   for (x=0; x<width; x++) {
   }
 }
}

canonical_original_code:
void process_file(struct _ImageData *image)
{
 int x; int y;
 unsigned int height = image->height;
 unsigned int width = image->width;
 unsigned char **row_pointers = image->rows;
 for (y=0; y<height; y++) {
   unsigned char *row = row_pointers[y];
   for (x=0; x<width; x++) {
   }
 }
}

variable_types: x int

variable_types: y int

variable_types:
width
unsigned int

variable_types:
row
unsigned char *

user_defined_types: struct _ImageData { int bit_depth; int color_type; unsigned int width; unsigned int height; unsigned int rowbytes; unsigned char **rows; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
FILE *v4; // rbp

if ( argc == 3 )
{
v4 = png_image_load(argv[1]);
png_image_save(argv[2]);
png_image_destroy(v4);
result = 0;
}
else
{
printf("Usage: %s <file_in> <file_out>\n", *argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
FILE *v4; // rbp

if ( argc == 3 )
{
v4 = png_image_load(argv[1]);
func7(argv[2]);
func8(v4);
result = 0;
}
else
{
printf("Usage: %s <file_in> <file_out>\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 if (argc != 3)
 {
  printf("Usage: %s <file_in> <file_out>\n", argv[0]);
  return 1;
 }
 ImageData* image = png_image_load(argv[1]);
 process_file(image);
 png_image_save(argv[2], image);
 png_image_destroy(image);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if (argc != 3)
 {
  printf("Usage: %s <file_in> <file_out>\n", argv[0]);
  return 1;
 }
 struct _ImageData *image = png_image_load(argv[1]);
 process_file(image);
 png_image_save(argv[2], image);
 png_image_destroy(image);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


usage

repo: xiaobai/fib

decompiled_code:
void __noreturn usage()
{
puts("Invalid paramters.");
puts("fib: usage: fib [terms]");
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
puts("Invalid paramters.");
puts("fib: usage: fib [terms]");
exit(0);
}

original_code:
void usage()
{
 printf("Invalid paramters.\n");
 printf("fib: usage: fib [terms]\n");
 exit(0);
}


generate

decompiled_code:
__int64 __fastcall generate(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx

__gmpz_init();
v1 = 0LL;
do
{
__gmpz_fib_ui();
__gmp_printf();
++v1;
}
while ( a1 >= v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
unsigned __int64 v1; // rbx

__gmpz_init();
v1 = 0LL;
do
{
__gmpz_fib_ui();
__gmp_printf();
++v1;
}
while ( a1 >= v1 );
return 0LL;
}

original_code:
int generate(unsigned long terms)
{
 unsigned long i;
 mpz_t F_i;
 __gmpz_init(F_i);
 for (i = 0; i <= terms; i++) {
  __gmpz_fib_ui(F_i, i);
  __gmp_printf("%Zd ", F_i);
 }
 return 0;
}

canonical_original_code:
int generate(unsigned long terms)
{
 unsigned long i;
 struct __mpz_struct F_i[1];
 __gmpz_init(F_i);
 for (i = 0; i <= terms; i++) {
  __gmpz_fib_ui(F_i, i);
  __gmp_printf("%Zd ", F_i);
 }
 return 0;
}

variable_types:
terms
unsigned long

variable_types:
i
unsigned long

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


main

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

if ( argc != 2 )
usage(argc, argv, envp);
v3 = strtol(argv[1], &endptr, 10);
generate(v3);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

if ( argc != 2 )
func7(argc, argv, envp);
v3 = strtol(argv[1], &endptr, 10);
func8(v3);
putchar(10);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc != 2) {
  usage();
 }
 char *end;
 int terms = strtol(argv[1], &end, 10);
 generate(terms);
 printf("\n");
 return 0;
}

variable_types:
argv
char *[]

variable_types:
end
char *

variable_types: terms int


repo: xiaotmiaomiao/unixODBC-SPEC

decompiled_code:
_DWORD *EN_Constructor()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
}
return result;
}

original_code:
EnvironmentClass
*EN_Constructor(void)
{
EnvironmentClass *rv;
    rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));
    if( rv) {
  rv->errormsg = 0;
  rv->errornumber = 0;
 }
    return rv;
}

canonical_original_code:
struct EnvironmentClass_ *EN_Constructor()
{
struct EnvironmentClass_ *rv;
    rv = (struct EnvironmentClass_ *) malloc(sizeof(EnvironmentClass));
    if( rv) {
  rv->errormsg = 0;
  rv->errornumber = 0;
 }
    return rv;
}

variable_types: struct EnvironmentClass_ { char *errormsg; int errornumber; } *


decompiled_code:
__int64 __fastcall EN_Destructor(void *ptr)
{
char *v1; // rbx
unsigned int v2; // er13
_BOOL4 v3; // eax

mylog("in EN_Destructor, self=%u\n", ptr);
v1 = (char *)&conns;
v2 = 1;
do
{
if ( *(_QWORD *)v1 && **(void ***)v1 == ptr )
{
v3 = 0;
if ( (_BYTE)v2 )
v3 = (unsigned __int8)CC_Destructor() != 0;
v2 = v3;
}
v1 += 8;
}
while ( v1 != (char *)&conns + 1024 );
free(ptr);
mylog("exit EN_Destructor: rv = %d\n", (unsigned int)(char)v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
char *v1; // rbx
unsigned int v2; // er13
_BOOL4 v3; // eax

mylog("in EN_Destructor, self=%u\n", ptr);
v1 = (char *)&conns;
v2 = 1;
do
{
if ( *(_QWORD *)v1 && **(void ***)v1 == ptr )
{
v3 = 0;
if ( (_BYTE)v2 )
v3 = (unsigned __int8)CC_Destructor() != 0;
v2 = v3;
}
v1 += 8;
}
while ( v1 != (char *)&conns + 1024 );
free(ptr);
mylog("exit EN_Destructor: rv = %d\n", (unsigned int)(char)v2);
return v2;
}

original_code:
char
EN_Destructor(EnvironmentClass *self)
{
int lf;
char rv = 1;
 mylog("in EN_Destructor, self=%u\n", self);
 for (lf = 0; lf < 128; lf++) {
  if (conns[lf] && conns[lf]->henv == (HENV) self)
   rv = rv && CC_Destructor(conns[lf]);
 }
    free( self );
 mylog("exit EN_Destructor: rv = %d\n", rv);
 return rv;
}

canonical_original_code:
char EN_Destructor(struct EnvironmentClass_ *self)
{
int lf;
char rv = 1;
 mylog("in EN_Destructor, self=%u\n", self);
 for (lf = 0; lf < 128; lf++) {
  if (conns[lf] && conns[lf]->henv == (void *) self)
   rv = rv && CC_Destructor(conns[lf]);
 }
    free( self );
 mylog("exit EN_Destructor: rv = %d\n", rv);
 return rv;
}

variable_types: lf int

variable_types: rv char

return_type: char

user_defined_types: struct EnvironmentClass_ { char *errormsg; int errornumber; }


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

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 8) )
{
*a3 = *(_QWORD *)a1;
*a2 = *(_DWORD *)(a1 + 8);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 8) )
{
*a3 = *(_QWORD *)a1;
*a2 = *(_DWORD *)(a1 + 8);
*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
}
return result;
}

original_code:
char
EN_get_error(EnvironmentClass *self, int *number, char **message)
{
 if(self && self->errormsg && self->errornumber) {
  *message = self->errormsg;
  *number = self->errornumber;
  self->errormsg = 0;
  self->errornumber = 0;
  return 1;
 } else {
  return 0;
 }
}

canonical_original_code:
char EN_get_error(struct EnvironmentClass_ *self, int *number, char **message)
{
 if(self && self->errormsg && self->errornumber) {
  *message = self->errormsg;
  *number = self->errornumber;
  self->errormsg = 0;
  self->errornumber = 0;
  return 1;
 } else {
  return 0;
 }
}

variable_types:
number
int *

variable_types:
message
char **


decompiled_code:
__int64 __fastcall EN_log_error(const char *a1, const char *a2, __int64 a3)
{
__int64 result; // rax

if ( a3 )
result = qlog(
"ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",
a1,
a2,
*(unsigned int *)(a3 + 8),
*(const char **)a3);
else
result = qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2, __int64 a3)
{
__int64 result; // rax

if ( a3 )
result = qlog(
"ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",
a1,
a2,
*(unsigned int *)(a3 + 8),
*(const char **)a3);
else
result = qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", a1, a2);
return result;
}

original_code:
void
EN_log_error(char *func, char *desc, EnvironmentClass *self)
{
 if (self) {
  qlog("ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, self->errormsg);
 }
 else
  qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
}

canonical_original_code:
void EN_log_error(char *func, char *desc, struct EnvironmentClass_ *self)
{
 if (self) {
  qlog("ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, self->errormsg);
 }
 else
  qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);
}

variable_types:
func
char *

variable_types:
desc
char *


SQLAllocEnv

decompiled_code:
__int64 __fastcall SQLAllocEnv(_QWORD *a1)
{
_DWORD *v1; // rax
__int64 result; // rax

mylog("**** in SQLAllocEnv ** \n");
getGlobalDefaults("PostgreSQL", "ODBCINST.INI", 0LL);
v1 = EN_Constructor();
*a1 = v1;
if ( v1 )
{
mylog("** exit SQLAllocEnv: phenv = %u **\n", v1);
result = 0LL;
}
else
{
EN_log_error("SQLAllocEnv", "Error allocating environment", 0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
_DWORD *v1; // rax
__int64 result; // rax

mylog("**** in SQLAllocEnv ** \n");
getGlobalDefaults("PostgreSQL", "ODBCINST.INI", 0LL);
v1 = func0();
*a1 = v1;
if ( v1 )
{
mylog("** exit SQLAllocEnv: phenv = %u **\n", v1);
result = 0LL;
}
else
{
func6("SQLAllocEnv", "Error allocating environment", 0LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLAllocEnv(HENV *phenv)
{
static char* const func = "SQLAllocEnv";
mylog("**** in SQLAllocEnv ** \n");
 getGlobalDefaults("PostgreSQL", "ODBCINST.INI", (int)0);
 *phenv = (HENV) EN_Constructor();
 if ( ! *phenv) {
  *phenv = 0;
  EN_log_error(func, "Error allocating environment", ((void *)0));
  return (-1);
 }
 mylog("** exit SQLAllocEnv: phenv = %u **\n", *phenv);
 return 0;
}

canonical_original_code:
short SQLAllocEnv(void **phenv)
{
static char *func = "SQLAllocEnv";
mylog("**** in SQLAllocEnv ** \n");
 getGlobalDefaults("PostgreSQL", "ODBCINST.INI", (int)0);
 *phenv = (void *) EN_Constructor();
 if ( ! *phenv) {
  *phenv = 0;
  EN_log_error(func, "Error allocating environment", ((void *)0));
  return (-1);
 }
 mylog("** exit SQLAllocEnv: phenv = %u **\n", *phenv);
 return 0;
}

variable_types:
phenv
void **

return_type: short


SQLFreeEnv

decompiled_code:
__int64 __fastcall SQLFreeEnv(void *ptr)
{
__int64 result; // rax

mylog("**** in SQLFreeEnv: env = %u ** \n", ptr);
if ( ptr && (unsigned __int8)EN_Destructor(ptr) )
{
mylog(" ok\n");
result = 0LL;
}
else
{
mylog(" error\n");
EN_log_error("SQLFreeEnv", "Error freeing environment", (__int64)ptr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
__int64 result; // rax

mylog("**** in SQLFreeEnv: env = %u ** \n", ptr);
if ( ptr && (unsigned __int8)func1(ptr) )
{
mylog(" ok\n");
result = 0LL;
}
else
{
mylog(" error\n");
func6("SQLFreeEnv", "Error freeing environment", (__int64)ptr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
RETCODE SQLFreeEnv(HENV henv)
{
static char* const func = "SQLFreeEnv";
EnvironmentClass *env = (EnvironmentClass *) henv;
mylog("**** in SQLFreeEnv: env = %u ** \n", env);
 if (env && EN_Destructor(env)) {
  mylog("   ok\n");
  return 0;
 }
 mylog("    error\n");
 EN_log_error(func, "Error freeing environment", env);
 return (-1);
}

canonical_original_code:
short SQLFreeEnv(void *henv)
{
static char *func = "SQLFreeEnv";
struct EnvironmentClass_ *env = (EnvironmentClass *) henv;
mylog("**** in SQLFreeEnv: env = %u ** \n", env);
 if (env && EN_Destructor(env)) {
  mylog("   ok\n");
  return 0;
 }
 mylog("    error\n");
 EN_log_error(func, "Error freeing environment", env);
 return (-1);
}

variable_types:
henv
void *