decompiled_code:
const char *__fastcall FluidSynthDrv_ErrorString(int a1)
{
const char *result; // rax

while ( 2 )
{
switch ( a1 )
{
case -2:
case -1:
a1 = ErrorCode;
continue;
case 0:
result = "FluidSynth ok.";
break;
case 1:
result = "FluidSynth uninitialised.";
break;
case 2:
result = "Failed creating new fluid settings.";
break;
case 3:
result = "Failed creating new fluid synth.";
break;
case 4:
result = "Failed creating new fluid audio driver.";
break;
case 5:
result = "Failed creating new fluid sequencer.";
break;
case 6:
result = "Failed registering fluid synth with sequencer.";
break;
case 7:
result = "Invalid or non-existent SoundFont.";
break;
case 8:
result = "Failed creating new fluid event.";
break;
case 9:
result = "Failed creating playback thread.";
break;
default:
result = "Unknown FluidSynth error.";
break;
}
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func10(int a1)
{
const char *result; // rax

while ( 2 )
{
switch ( a1 )
{
case -2:
case -1:
a1 = ErrorCode;
continue;
case 0:
result = "FluidSynth ok.";
break;
case 1:
result = "FluidSynth uninitialised.";
break;
case 2:
result = "Failed creating new fluid settings.";
break;
case 3:
result = "Failed creating new fluid synth.";
break;
case 4:
result = "Failed creating new fluid audio driver.";
break;
case 5:
result = "Failed creating new fluid sequencer.";
break;
case 6:
result = "Failed registering fluid synth with sequencer.";
break;
case 7:
result = "Invalid or non-existent SoundFont.";
break;
case 8:
result = "Failed creating new fluid event.";
break;
case 9:
result = "Failed creating playback thread.";
break;
default:
result = "Unknown FluidSynth error.";
break;
}
break;
}
return result;
}

original_code:
const char *FluidSynthDrv_ErrorString( int ErrorNumber )
{
 const char *ErrorString;
    switch( ErrorNumber )
 {
        case FSynthErr_Warning :
        case FSynthErr_Error :
            ErrorString = FluidSynthDrv_ErrorString( ErrorCode );
            break;
        case FSynthErr_Ok :
            ErrorString = "FluidSynth ok.";
            break;
  case FSynthErr_Uninitialised:
   ErrorString = "FluidSynth uninitialised.";
   break;
        case FSynthErr_NewFluidSettings:
            ErrorString = "Failed creating new fluid settings.";
            break;
        case FSynthErr_NewFluidSynth:
            ErrorString = "Failed creating new fluid synth.";
            break;
        case FSynthErr_NewFluidAudioDriver:
            ErrorString = "Failed creating new fluid audio driver.";
            break;
        case FSynthErr_NewFluidSequencer:
            ErrorString = "Failed creating new fluid sequencer.";
            break;
        case FSynthErr_RegisterFluidSynth:
            ErrorString = "Failed registering fluid synth with sequencer.";
            break;
        case FSynthErr_BadSoundFont:
            ErrorString = "Invalid or non-existent SoundFont.";
            break;
        case FSynthErr_NewFluidEvent:
            ErrorString = "Failed creating new fluid event.";
            break;
        case FSynthErr_PlayThread:
            ErrorString = "Failed creating playback thread.";
            break;
        default:
            ErrorString = "Unknown FluidSynth error.";
            break;
    }
 return ErrorString;
}

canonical_original_code:
char *FluidSynthDrv_ErrorString(int ErrorNumber)
{
 char *ErrorString;
    switch( ErrorNumber )
 {
        case FSynthErr_Warning :
        case FSynthErr_Error :
            ErrorString = FluidSynthDrv_ErrorString( ErrorCode );
            break;
        case FSynthErr_Ok :
            ErrorString = "FluidSynth ok.";
            break;
  case FSynthErr_Uninitialised:
   ErrorString = "FluidSynth uninitialised.";
   break;
        case FSynthErr_NewFluidSettings:
            ErrorString = "Failed creating new fluid settings.";
            break;
        case FSynthErr_NewFluidSynth:
            ErrorString = "Failed creating new fluid synth.";
            break;
        case FSynthErr_NewFluidAudioDriver:
            ErrorString = "Failed creating new fluid audio driver.";
            break;
        case FSynthErr_NewFluidSequencer:
            ErrorString = "Failed creating new fluid sequencer.";
            break;
        case FSynthErr_RegisterFluidSynth:
            ErrorString = "Failed registering fluid synth with sequencer.";
            break;
        case FSynthErr_BadSoundFont:
            ErrorString = "Invalid or non-existent SoundFont.";
            break;
        case FSynthErr_NewFluidEvent:
            ErrorString = "Failed creating new fluid event.";
            break;
        case FSynthErr_PlayThread:
            ErrorString = "Failed creating playback thread.";
            break;
        default:
            ErrorString = "Unknown FluidSynth error.";
            break;
    }
 return ErrorString;
}

variable_types: ErrorNumber int

variable_types:
ErrorString
char *


repo: TermiT/sw-redux

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

if ( fluidevent )
delete_fluid_event();
if ( fluidsequencer )
delete_fluid_sequencer();
if ( fluidaudiodriver )
delete_fluid_audio_driver();
if ( fluidsynth )
delete_fluid_synth();
if ( fluidsettings )
delete_fluid_settings();
fluidevent = 0LL;
result = 0xFFFFFFFFLL;
synthseqid = -1;
fluidsequencer = 0LL;
fluidaudiodriver = 0LL;
fluidsynth = 0LL;
fluidsettings = 0LL;
return result;
}

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

if ( fluidevent )
delete_fluid_event();
if ( fluidsequencer )
delete_fluid_sequencer();
if ( fluidaudiodriver )
delete_fluid_audio_driver();
if ( fluidsynth )
delete_fluid_synth();
if ( fluidsettings )
delete_fluid_settings();
fluidevent = 0LL;
result = 0xFFFFFFFFLL;
synthseqid = -1;
fluidsequencer = 0LL;
fluidaudiodriver = 0LL;
fluidsynth = 0LL;
fluidsettings = 0LL;
return result;
}

original_code:
void FluidSynthDrv_MIDI_Shutdown(void)
{
    if (fluidevent) {
        delete_fluid_event(fluidevent);
    }
    if (fluidsequencer) {
        delete_fluid_sequencer(fluidsequencer);
    }
    if (fluidaudiodriver) {
        delete_fluid_audio_driver(fluidaudiodriver);
    }
    if (fluidsynth) {
        delete_fluid_synth(fluidsynth);
    }
    if (fluidsettings) {
        delete_fluid_settings(fluidsettings);
    }
    synthseqid = -1;
    fluidevent = 0;
    fluidsequencer = 0;
    fluidaudiodriver = 0;
    fluidsynth = 0;
    fluidsettings = 0;
}

canonical_original_code:
void FluidSynthDrv_MIDI_Shutdown()
{
    if (fluidevent) {
        delete_fluid_event(fluidevent);
    }
    if (fluidsequencer) {
        delete_fluid_sequencer(fluidsequencer);
    }
    if (fluidaudiodriver) {
        delete_fluid_audio_driver(fluidaudiodriver);
    }
    if (fluidsynth) {
        delete_fluid_synth(fluidsynth);
    }
    if (fluidsettings) {
        delete_fluid_settings(fluidsettings);
    }
    synthseqid = -1;
    fluidevent = 0;
    fluidsequencer = 0;
    fluidaudiodriver = 0;
    fluidsynth = 0;
    fluidsettings = 0;
}

return_type: void


decompiled_code:
__int64 __fastcall FluidSynthDrv_MIDI_Init(size_t (__fastcall **a1)(unsigned int a1, __int16 a2))
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rdi
__int64 v5; // rsi
__int64 v6; // rsi
__int64 v7; // rdi
__int64 v8; // rdi
__int64 result; // rax

((void (*)(void))FluidSynthDrv_MIDI_Shutdown)();
*a1 = 0LL;
a1[11] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 96) >> 3));
v2 = new_fluid_settings();
fluidsettings = v2;
if ( v2 )
{
v3 = new_fluid_synth(v2);
v4 = fluidsettings;
fluidsynth = v3;
v5 = v3;
if ( fluidsettings )
{
fluidaudiodriver = new_fluid_audio_driver(fluidsettings, v3);
if ( fluidsettings )
{
fluidsequencer = new_fluid_sequencer();
if ( fluidsettings )
{
fluidevent = new_fluid_event();
if ( fluidevent )
{
v6 = fluidsynth;
v7 = fluidsequencer;
synthseqid = fluid_sequencer_register_fluidsynth(fluidsequencer, fluidsynth);
if ( synthseqid < 0 )
{
FluidSynthDrv_MIDI_Shutdown(v7, v6);
result = 0xFFFFFFFFLL;
ErrorCode = 6;
}
else
{
v8 = fluidsynth;
if ( (int)fluid_synth_sfload(fluidsynth, "/usr/share/sounds/sf2/SGM-V2.01.sf2", 1LL) < 0 )
{
FluidSynthDrv_MIDI_Shutdown(v8, "/usr/share/sounds/sf2/SGM-V2.01.sf2");
result = 0xFFFFFFFFLL;
ErrorCode = 7;
}
else
{
fluid_event_set_source(fluidevent, 0xFFFFFFFFLL);
fluid_event_set_dest(fluidevent, (unsigned int)synthseqid);
*a1 = Func_NoteOff;
result = 0LL;
a1[1] = (size_t (__fastcall *)(unsigned int, __int16))Func_NoteOn;
a1[2] = (size_t (__fastcall *)(unsigned int, __int16))Func_PolyAftertouch;
a1[3] = (size_t (__fastcall *)(unsigned int, __int16))Func_ControlChange;
a1[4] = Func_ProgramChange;
a1[5] = (size_t (__fastcall *)(unsigned int, __int16))Func_ChannelAftertouch;
a1[6] = (size_t (__fastcall *)(unsigned int, __int16))Func_PitchBend;
}
}
}
else
{
FluidSynthDrv_MIDI_Shutdown(v4, v5);
result = 0xFFFFFFFFLL;
ErrorCode = 8;
}
}
else
{
FluidSynthDrv_MIDI_Shutdown(v4, v5);
result = 0xFFFFFFFFLL;
ErrorCode = 5;
}
}
else
{
FluidSynthDrv_MIDI_Shutdown(v4, v5);
result = 0xFFFFFFFFLL;
ErrorCode = 4;
}
}
else
{
FluidSynthDrv_MIDI_Shutdown(fluidsettings, v3);
result = 0xFFFFFFFFLL;
ErrorCode = 3;
}
}
else
{
ErrorCode = 2;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(size_t (__fastcall **a1)(unsigned int a1, __int16 a2))
{
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rdi
__int64 v5; // rsi
__int64 v6; // rsi
__int64 v7; // rdi
__int64 v8; // rdi
__int64 result; // rax

((void (*)(void))FluidSynthDrv_MIDI_Shutdown)();
*a1 = 0LL;
a1[11] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 96) >> 3));
v2 = new_fluid_settings();
fluidsettings = v2;
if ( v2 )
{
v3 = new_fluid_synth(v2);
v4 = fluidsettings;
fluidsynth = v3;
v5 = v3;
if ( fluidsettings )
{
fluidaudiodriver = new_fluid_audio_driver(fluidsettings, v3);
if ( fluidsettings )
{
fluidsequencer = new_fluid_sequencer();
if ( fluidsettings )
{
fluidevent = new_fluid_event();
if ( fluidevent )
{
v6 = fluidsynth;
v7 = fluidsequencer;
synthseqid = fluid_sequencer_register_fluidsynth(fluidsequencer, fluidsynth);
if ( synthseqid < 0 )
{
func11(v7, v6);
result = 0xFFFFFFFFLL;
ErrorCode = 6;
}
else
{
v8 = fluidsynth;
if ( (int)fluid_synth_sfload(fluidsynth, "/usr/share/sounds/sf2/SGM-V2.01.sf2", 1LL) < 0 )
{
func11(v8, "/usr/share/sounds/sf2/SGM-V2.01.sf2");
result = 0xFFFFFFFFLL;
ErrorCode = 7;
}
else
{
fluid_event_set_source(fluidevent, 0xFFFFFFFFLL);
fluid_event_set_dest(fluidevent, (unsigned int)synthseqid);
*a1 = Func_NoteOff;
result = 0LL;
a1[1] = (size_t (__fastcall *)(unsigned int, __int16))Func_NoteOn;
a1[2] = (size_t (__fastcall *)(unsigned int, __int16))Func_PolyAftertouch;
a1[3] = (size_t (__fastcall *)(unsigned int, __int16))Func_ControlChange;
a1[4] = Func_ProgramChange;
a1[5] = (size_t (__fastcall *)(unsigned int, __int16))Func_ChannelAftertouch;
a1[6] = (size_t (__fastcall *)(unsigned int, __int16))Func_PitchBend;
}
}
}
else
{
func11(v4, v5);
result = 0xFFFFFFFFLL;
ErrorCode = 8;
}
}
else
{
func11(v4, v5);
result = 0xFFFFFFFFLL;
ErrorCode = 5;
}
}
else
{
func11(v4, v5);
result = 0xFFFFFFFFLL;
ErrorCode = 4;
}
}
else
{
func11(fluidsettings, v3);
result = 0xFFFFFFFFLL;
ErrorCode = 3;
}
}
else
{
ErrorCode = 2;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int FluidSynthDrv_MIDI_Init(midifuncs *funcs)
{
    int result;
    FluidSynthDrv_MIDI_Shutdown();
    memset(funcs, 0, sizeof(midifuncs));
    fluidsettings = new_fluid_settings();
    if (!fluidsettings) {
        ErrorCode = FSynthErr_NewFluidSettings;
        return FSynthErr_Error;
    }
    fluidsynth = new_fluid_synth(fluidsettings);
    if (!fluidsettings) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidSynth;
        return FSynthErr_Error;
    }
    fluidaudiodriver = new_fluid_audio_driver(fluidsettings, fluidsynth);
    if (!fluidsettings) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidAudioDriver;
        return FSynthErr_Error;
    }
    fluidsequencer = new_fluid_sequencer();
    if (!fluidsettings) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidSequencer;
        return FSynthErr_Error;
    }
    fluidevent = new_fluid_event();
    if (!fluidevent) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidEvent;
        return FSynthErr_Error;
    }
    synthseqid = fluid_sequencer_register_fluidsynth(fluidsequencer, fluidsynth);
    if (synthseqid < 0) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_RegisterFluidSynth;
        return FSynthErr_Error;
    }
    result = fluid_synth_sfload(fluidsynth, soundFontName, 1);
    if (result < 0) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_BadSoundFont;
        return FSynthErr_Error;
    }
    fluid_event_set_source(fluidevent, -1);
    fluid_event_set_dest(fluidevent, synthseqid);
    funcs->NoteOff = Func_NoteOff;
    funcs->NoteOn = Func_NoteOn;
    funcs->PolyAftertouch = Func_PolyAftertouch;
    funcs->ControlChange = Func_ControlChange;
    funcs->ProgramChange = Func_ProgramChange;
    funcs->ChannelAftertouch = Func_ChannelAftertouch;
    funcs->PitchBend = Func_PitchBend;
    return FSynthErr_Ok;
}

canonical_original_code:
int FluidSynthDrv_MIDI_Init(struct midifuncs *funcs)
{
    int result;
    FluidSynthDrv_MIDI_Shutdown();
    memset(funcs, 0, sizeof(midifuncs));
    fluidsettings = new_fluid_settings();
    if (!fluidsettings) {
        ErrorCode = FSynthErr_NewFluidSettings;
        return FSynthErr_Error;
    }
    fluidsynth = new_fluid_synth(fluidsettings);
    if (!fluidsettings) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidSynth;
        return FSynthErr_Error;
    }
    fluidaudiodriver = new_fluid_audio_driver(fluidsettings, fluidsynth);
    if (!fluidsettings) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidAudioDriver;
        return FSynthErr_Error;
    }
    fluidsequencer = new_fluid_sequencer();
    if (!fluidsettings) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidSequencer;
        return FSynthErr_Error;
    }
    fluidevent = new_fluid_event();
    if (!fluidevent) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_NewFluidEvent;
        return FSynthErr_Error;
    }
    synthseqid = fluid_sequencer_register_fluidsynth(fluidsequencer, fluidsynth);
    if (synthseqid < 0) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_RegisterFluidSynth;
        return FSynthErr_Error;
    }
    result = fluid_synth_sfload(fluidsynth, soundFontName, 1);
    if (result < 0) {
        FluidSynthDrv_MIDI_Shutdown();
        ErrorCode = FSynthErr_BadSoundFont;
        return FSynthErr_Error;
    }
    fluid_event_set_source(fluidevent, -1);
    fluid_event_set_dest(fluidevent, synthseqid);
    funcs->NoteOff = Func_NoteOff;
    funcs->NoteOn = Func_NoteOn;
    funcs->PolyAftertouch = Func_PolyAftertouch;
    funcs->ControlChange = Func_ControlChange;
    funcs->ProgramChange = Func_ProgramChange;
    funcs->ChannelAftertouch = Func_ChannelAftertouch;
    funcs->PitchBend = Func_PitchBend;
    return FSynthErr_Ok;
}

variable_types: struct midifuncs { void (*NoteOff)(int channel, int key, int velocity); void (*NoteOn)(int channel, int key, int velocity); void (*PolyAftertouch)(int channel, int key, int pressure); void (*ControlChange)(int channel, int number, int value); void (*ProgramChange)(int channel, int program); void (*ChannelAftertouch)(int channel, int pressure); void (*PitchBend)(int channel, int lsb, int msb); void (*ReleasePatches)(); void (*LoadPatch)(int number); void (*SetVolume)(int volume); int (*GetVolume)(); void (*SysEx)(unsigned char *data, int length); } *

variable_types: result int

return_type: int


decompiled_code:
int FluidSynthDrv_MIDI_HaltPlayback()
{
int result; // eax
void *thread_return; // [rsp+0h] [rbp-10h] BYREF

result = threadRunning;
if ( threadRunning )
{
threadQuit = 1;
result = pthread_join(thread, &thread_return);
if ( result )
result = fwrite("fluidsynth pthread_join returned error\n", 1uLL, 0x27uLL, stderr);
threadRunning = 0;
}
return result;
}

canonical_decompiled_code:
int func13()
{
int result; // eax
void *thread_return; // [rsp+0h] [rbp-10h] BYREF

result = threadRunning;
if ( threadRunning )
{
threadQuit = 1;
result = pthread_join(thread, &thread_return);
if ( result )
result = fwrite("fluidsynth pthread_join returned error\n", 1uLL, 0x27uLL, stderr);
threadRunning = 0;
}
return result;
}

original_code:
void FluidSynthDrv_MIDI_HaltPlayback(void)
{
    void * ret;
    if (!threadRunning) {
        return;
    }
    threadQuit = 1;
    if (pthread_join(thread, &ret)) {
        fprintf(stderr, "fluidsynth pthread_join returned error\n");
    }
    threadRunning = 0;
}

canonical_original_code:
void FluidSynthDrv_MIDI_HaltPlayback()
{
    void *ret;
    if (!threadRunning) {
        return;
    }
    threadQuit = 1;
    if (pthread_join(thread, &ret)) {
        fprintf(stderr, "fluidsynth pthread_join returned error\n");
    }
    threadRunning = 0;
}

variable_types:
ret
void *


decompiled_code:
int __fastcall FluidSynthDrv_MIDI_StartPlayback(__int64 (__fastcall *a1)(_QWORD, _QWORD, _QWORD, _QWORD))
{
int result; // eax

FluidSynthDrv_MIDI_HaltPlayback();
threadService = a1;
threadQuit = 0;
result = pthread_create(&thread, 0LL, threadProc, 0LL);
if ( result )
{
fwrite("fluidsynth pthread_create returned error\n", 1uLL, 0x29uLL, stderr);
result = 9;
}
else
{
threadRunning = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 (__fastcall *a1)(_QWORD, _QWORD, _QWORD, _QWORD))
{
int result; // eax

func13();
threadService = a1;
threadQuit = 0;
result = pthread_create(&thread, 0LL, threadProc, 0LL);
if ( result )
{
fwrite("fluidsynth pthread_create returned error\n", 1uLL, 0x29uLL, stderr);
result = 9;
}
else
{
threadRunning = 1;
}
return result;
}

original_code:
int FluidSynthDrv_MIDI_StartPlayback(void (*service)(void))
{
    FluidSynthDrv_MIDI_HaltPlayback();
    threadService = service;
    threadQuit = 0;
    if (pthread_create(&thread, ((void *)0), threadProc, ((void *)0))) {
        fprintf(stderr, "fluidsynth pthread_create returned error\n");
        return FSynthErr_PlayThread;
    }
    threadRunning = 1;
    return 0;
}

canonical_original_code:
int FluidSynthDrv_MIDI_StartPlayback(void (*service)())
{
    FluidSynthDrv_MIDI_HaltPlayback();
    threadService = service;
    threadQuit = 0;
    if (pthread_create(&thread, ((void *)0), threadProc, ((void *)0))) {
        fprintf(stderr, "fluidsynth pthread_create returned error\n");
        return FSynthErr_PlayThread;
    }
    threadRunning = 1;
    return 0;
}

variable_types:
service
void (*)()


decompiled_code:
__int64 __fastcall FluidSynthDrv_MIDI_SetTempo(int a1, int a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
__int64 result; // rax
double v6; // [rsp+0h] [rbp-10h]

v6 = (double)a1 * (double)a2 / 60.0;
fluid_sequencer_set_time_scale(fluidsequencer);
v2 = v6 / 20.0;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v6 / 20.0) & LC20) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = v6 / 20.0;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC21)) | ~LC20 & *(_QWORD *)&v2;
}
result = (unsigned int)(int)v2;
threadQueueTicks = (int)v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, int a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
__int64 result; // rax
double v6; // [rsp+0h] [rbp-10h]

v6 = (double)a1 * (double)a2 / 60.0;
fluid_sequencer_set_time_scale(fluidsequencer);
v2 = v6 / 20.0;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v6 / 20.0) & LC20) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = v6 / 20.0;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC21)) | ~LC20 & *(_QWORD *)&v2;
}
result = (unsigned int)(int)v2;
threadQueueTicks = (int)v2;
return result;
}

original_code:
void FluidSynthDrv_MIDI_SetTempo(int tempo, int division)
{
    double tps;
    tps = ( (double) tempo * (double) division ) / 60.0;
    fluid_sequencer_set_time_scale(fluidsequencer, tps);
    threadQueueTicks = (int) ceil(tps / (double) 20);
}

variable_types: tempo int

variable_types: division int

variable_types: tps double


decompiled_code:
void FluidSynthDrv_MIDI_Lock()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void FluidSynthDrv_MIDI_Lock(void)
{
}

canonical_original_code:
void FluidSynthDrv_MIDI_Lock()
{
}


decompiled_code:
void FluidSynthDrv_MIDI_Unlock()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void FluidSynthDrv_MIDI_Unlock(void)
{
}

canonical_original_code:
void FluidSynthDrv_MIDI_Unlock()
{
}


decompiled_code:
size_t sequence_event()
{
size_t result; // rax

result = fluid_sequencer_send_at(fluidsequencer, fluidevent, (unsigned int)threadTimer, 1LL);
if ( (result & 0x80000000) != 0LL )
result = fwrite("fluidsynth could not queue event\n", 1uLL, 0x21uLL, stderr);
return result;
}

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

result = fluid_sequencer_send_at(fluidsequencer, fluidevent, (unsigned int)threadTimer, 1LL);
if ( (result & 0x80000000) != 0LL )
result = fwrite("fluidsynth could not queue event\n", 1uLL, 0x21uLL, stderr);
return result;
}

original_code:
static inline void sequence_event(void)
{
    int result = 0;
    result = fluid_sequencer_send_at(fluidsequencer, fluidevent, threadTimer, 1);
    if (result < 0) {
        fprintf(stderr, "fluidsynth could not queue event\n");
    }
}

canonical_original_code:
static inline void sequence_event()
{
    int result = 0;
    result = fluid_sequencer_send_at(fluidsequencer, fluidevent, threadTimer, 1);
    if (result < 0) {
        fprintf(stderr, "fluidsynth could not queue event\n");
    }
}


decompiled_code:
size_t __fastcall Func_PitchBend(unsigned int a1, int a2, int a3)
{
fluid_event_pitch_bend(fluidevent, a1, a2 | (unsigned int)(a3 << 7));
return sequence_event();
}

canonical_decompiled_code:
size_t __fastcall func1(unsigned int a1, int a2, int a3)
{
fluid_event_pitch_bend(fluidevent, a1, a2 | (unsigned int)(a3 << 7));
return func0();
}

original_code:
static void Func_PitchBend( int channel, int lsb, int msb )
{
    fluid_event_pitch_bend(fluidevent, channel, lsb | (msb << 7));
    sequence_event();
}

canonical_original_code:
static void Func_PitchBend(int channel, int lsb, int msb)
{
    fluid_event_pitch_bend(fluidevent, channel, lsb | (msb << 7));
    sequence_event();
}

variable_types: channel int

variable_types: lsb int

variable_types: msb int


decompiled_code:
int __fastcall Func_ChannelAftertouch(unsigned int a1)
{
return fprintf(stderr, "fluidsynth channel %d aftertouch\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1)
{
return fprintf(stderr, "fluidsynth channel %d aftertouch\n", a1);
}

original_code:
static void Func_ChannelAftertouch( int channel, int pressure )
{
    fprintf(stderr, "fluidsynth channel %d aftertouch\n", channel);
}

canonical_original_code:
static void Func_ChannelAftertouch(int channel, int pressure)
{
    fprintf(stderr, "fluidsynth channel %d aftertouch\n", channel);
}

variable_types: pressure int


decompiled_code:
int __fastcall Func_PolyAftertouch(unsigned int a1, unsigned int a2)
{
return fprintf(stderr, "fluidsynth key %d channel %d aftertouch\n", a2, a1);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, unsigned int a2)
{
return fprintf(stderr, "fluidsynth key %d channel %d aftertouch\n", a2, a1);
}

original_code:
static void Func_PolyAftertouch( int channel, int key, int pressure )
{
    fprintf(stderr, "fluidsynth key %d channel %d aftertouch\n", key, channel);
}

canonical_original_code:
static void Func_PolyAftertouch(int channel, int key, int pressure)
{
    fprintf(stderr, "fluidsynth key %d channel %d aftertouch\n", key, channel);
}

variable_types: key int


decompiled_code:
size_t __fastcall Func_ProgramChange(unsigned int a1, __int16 a2)
{
fluid_event_program_change(fluidevent, a1, (unsigned int)a2);
return sequence_event();
}

canonical_decompiled_code:
size_t __fastcall func4(unsigned int a1, __int16 a2)
{
fluid_event_program_change(fluidevent, a1, (unsigned int)a2);
return func0();
}

original_code:
static void Func_ProgramChange( int channel, int program )
{
    fluid_event_program_change(fluidevent, channel, program);
    sequence_event();
}

canonical_original_code:
static void Func_ProgramChange(int channel, int program)
{
    fluid_event_program_change(fluidevent, channel, program);
    sequence_event();
}

variable_types: program int


decompiled_code:
size_t __fastcall Func_ControlChange(unsigned int a1, __int16 a2, __int16 a3)
{
fluid_event_control_change(fluidevent, a1, (unsigned int)a2, (unsigned int)a3);
return sequence_event();
}

canonical_decompiled_code:
size_t __fastcall func5(unsigned int a1, __int16 a2, __int16 a3)
{
fluid_event_control_change(fluidevent, a1, (unsigned int)a2, (unsigned int)a3);
return func0();
}

original_code:
static void Func_ControlChange( int channel, int number, int value )
{
    fluid_event_control_change(fluidevent, channel, number, value);
    sequence_event();
}

canonical_original_code:
static void Func_ControlChange(int channel, int number, int value)
{
    fluid_event_control_change(fluidevent, channel, number, value);
    sequence_event();
}

variable_types: number int

variable_types: value int


decompiled_code:
size_t __fastcall Func_NoteOn(unsigned int a1, __int16 a2, __int16 a3)
{
fluid_event_noteon(fluidevent, a1, (unsigned int)a2, (unsigned int)a3);
return sequence_event();
}

canonical_decompiled_code:
size_t __fastcall func6(unsigned int a1, __int16 a2, __int16 a3)
{
fluid_event_noteon(fluidevent, a1, (unsigned int)a2, (unsigned int)a3);
return func0();
}

original_code:
static void Func_NoteOn( int channel, int key, int velocity )
{
    fluid_event_noteon(fluidevent, channel, key, velocity);
    sequence_event();
}

canonical_original_code:
static void Func_NoteOn(int channel, int key, int velocity)
{
    fluid_event_noteon(fluidevent, channel, key, velocity);
    sequence_event();
}

variable_types: velocity int


decompiled_code:
size_t __fastcall Func_NoteOff(unsigned int a1, __int16 a2)
{
fluid_event_noteoff(fluidevent, a1, (unsigned int)a2);
return sequence_event();
}

canonical_decompiled_code:
size_t __fastcall func7(unsigned int a1, __int16 a2)
{
fluid_event_noteoff(fluidevent, a1, (unsigned int)a2);
return func0();
}

original_code:
static void Func_NoteOff( int channel, int key, int velocity )
{
    fluid_event_noteoff(fluidevent, channel, key);
    sequence_event();
}

canonical_original_code:
static void Func_NoteOff(int channel, int key, int velocity)
{
    fluid_event_noteoff(fluidevent, channel, key);
    sequence_event();
}


threadProc

decompiled_code:
void *__fastcall threadProc(void *a1)
{
__int64 v1; // rcx
int v2; // eax
__int64 v3; // rsi
__int64 v4; // rdx
__int64 v5; // rdi
struct timeval v7; // [rsp+0h] [rbp-18h] BYREF

threadTimer = fluid_sequencer_get_tick(fluidsequencer);
for ( threadQueueTimer = threadTimer + threadQueueTicks; threadTimer < (unsigned int)threadQueueTimer; ++threadTimer )
{
if ( threadService )
((void (*)(void))threadService)();
}
LABEL_5:
LODWORD(v1) = 50000;
while ( !threadQuit )
{
v7.tv_usec = (unsigned int)v1;
v7.tv_sec = 0LL;
select(0, 0LL, 0LL, 0LL, &v7);
v2 = fluid_sequencer_get_tick(fluidsequencer);
v3 = (unsigned int)threadTimer;
v4 = (unsigned int)threadQueueTicks;
v1 = 25000LL;
v5 = (unsigned int)(threadTimer - v2);
if ( (int)v5 <= threadQueueTicks )
{
for ( threadQueueTimer = threadQueueTicks + v2; threadTimer < (unsigned int)threadQueueTimer; ++threadTimer )
{
if ( threadService )
threadService(v5, v3, v4, v1);
}
goto LABEL_5;
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
__int64 v1; // rcx
int v2; // eax
__int64 v3; // rsi
__int64 v4; // rdx
__int64 v5; // rdi
struct timeval v7; // [rsp+0h] [rbp-18h] BYREF

threadTimer = fluid_sequencer_get_tick(fluidsequencer);
for ( threadQueueTimer = threadTimer + threadQueueTicks; threadTimer < (unsigned int)threadQueueTimer; ++threadTimer )
{
if ( threadService )
((void (*)(void))threadService)();
}
LABEL_5:
LODWORD(v1) = 50000;
while ( !threadQuit )
{
v7.tv_usec = (unsigned int)v1;
v7.tv_sec = 0LL;
select(0, 0LL, 0LL, 0LL, &v7);
v2 = fluid_sequencer_get_tick(fluidsequencer);
v3 = (unsigned int)threadTimer;
v4 = (unsigned int)threadQueueTicks;
v1 = 25000LL;
v5 = (unsigned int)(threadTimer - v2);
if ( (int)v5 <= threadQueueTicks )
{
for ( threadQueueTimer = threadQueueTicks + v2; threadTimer < (unsigned int)threadQueueTimer; ++threadTimer )
{
if ( threadService )
threadService(v5, v3, v4, v1);
}
goto LABEL_5;
}
}
return 0LL;
}

original_code:
static void * threadProc(void * parm)
{
    struct timeval tv;
    int sleepAmount = 1000000 / 20;
    unsigned int sequenceTime;
    threadTimer = fluid_sequencer_get_tick(fluidsequencer);
    threadQueueTimer = threadTimer + threadQueueTicks;
    while (threadTimer < threadQueueTimer) {
        if (threadService) {
            threadService();
        }
        threadTimer++;
    }
    while (!threadQuit) {
        tv.tv_sec = 0;
        tv.tv_usec = sleepAmount;
        select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
        sequenceTime = fluid_sequencer_get_tick(fluidsequencer);
        sleepAmount = 1000000 / 20;
        if ((int)(threadTimer - sequenceTime) > threadQueueTicks) {
            sleepAmount /= 2;
            continue;
        }
        threadQueueTimer = sequenceTime + threadQueueTicks;
        while (threadTimer < threadQueueTimer) {
            if (threadService) {
                threadService();
            }
            threadTimer++;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static void *threadProc(void *parm)
{
    struct timeval tv;
    int sleepAmount = 1000000 / 20;
    unsigned int sequenceTime;
    threadTimer = fluid_sequencer_get_tick(fluidsequencer);
    threadQueueTimer = threadTimer + threadQueueTicks;
    while (threadTimer < threadQueueTimer) {
        if (threadService) {
            threadService();
        }
        threadTimer++;
    }
    while (!threadQuit) {
        tv.tv_sec = 0;
        tv.tv_usec = sleepAmount;
        select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
        sequenceTime = fluid_sequencer_get_tick(fluidsequencer);
        sleepAmount = 1000000 / 20;
        if ((int)(threadTimer - sequenceTime) > threadQueueTicks) {
            sleepAmount /= 2;
            continue;
        }
        threadQueueTimer = sequenceTime + threadQueueTicks;
        while (threadTimer < threadQueueTimer) {
            if (threadService) {
                threadService();
            }
            threadTimer++;
        }
    }
    return ((void *)0);
}

variable_types:
parm
void *

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: sleepAmount int

variable_types:
sequenceTime
unsigned int

return_type: void *


decompiled_code:
int __fastcall ASS_Sleep(int a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 1000;
v2.tv_usec = 1000 * (a1 % 1000);
return select(0, 0LL, 0LL, 0LL, &v2);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

v2.tv_sec = a1 / 1000;
v2.tv_usec = 1000 * (a1 % 1000);
return select(0, 0LL, 0LL, 0LL, &v2);
}

original_code:
void ASS_Sleep(int msec)
{
 struct timeval tv;
 tv.tv_sec = msec / 1000;
 tv.tv_usec = (msec % 1000) * 1000;
 select(0, ((void *)0), ((void *)0), ((void *)0), &tv);
}

variable_types: msec int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


original_code:
unsigned long PITCH_GetScale
   (
   int pitchoffset
   )
   {
   unsigned long scale;
   int octaveshift;
   int noteshift;
   int note;
   int detune;
   if ( pitchoffset == 0 )
      {
      return( PitchTable[ 0 ][ 0 ] );
      }
   noteshift = pitchoffset % 1200;
   if ( noteshift < 0 )
      {
      noteshift += 1200;
      }
   note = noteshift / 100;
   detune = ( noteshift % 100 ) / ( 100 / 25 );
   octaveshift = ( pitchoffset - noteshift ) / 1200;
   if ( detune < 0 )
      {
      detune += ( 100 / 25 );
      note--;
      if ( note < 0 )
         {
         note += 12;
         octaveshift--;
         }
      }
   scale = PitchTable[ note ][ detune ];
   if ( octaveshift < 0 )
      {
      scale >>= -octaveshift;
      }
   else
      {
      scale <<= octaveshift;
      }
   return( scale );
   }

canonical_original_code:
unsigned long PITCH_GetScale(int pitchoffset)
   {
   unsigned long scale;
   int octaveshift;
   int noteshift;
   int note;
   int detune;
   if ( pitchoffset == 0 )
      {
      return( PitchTable[ 0 ][ 0 ] );
      }
   noteshift = pitchoffset % 1200;
   if ( noteshift < 0 )
      {
      noteshift += 1200;
      }
   note = noteshift / 100;
   detune = ( noteshift % 100 ) / ( 100 / 25 );
   octaveshift = ( pitchoffset - noteshift ) / 1200;
   if ( detune < 0 )
      {
      detune += ( 100 / 25 );
      note--;
      if ( note < 0 )
         {
         note += 12;
         octaveshift--;
         }
      }
   scale = PitchTable[ note ][ detune ];
   if ( octaveshift < 0 )
      {
      scale >>= -octaveshift;
      }
   else
      {
      scale <<= octaveshift;
      }
   return( scale );
   }

variable_types: pitchoffset int

variable_types:
scale
unsigned long

variable_types: octaveshift int

variable_types: noteshift int

variable_types: note int

variable_types: detune int

return_type: unsigned long


findx

repo: Terminus-IMRC/DependOn

decompiled_code:
__int64 __fastcall findx(char *a1)
{
char *v1; // rbx
const unsigned __int16 **v2; // rax
char v3; // dl
unsigned int v4; // er8
const unsigned __int16 *v5; // rcx
__int64 v6; // rax

v1 = a1;
v2 = __ctype_b_loc();
v3 = 0;
v4 = 0;
v5 = *v2;
v6 = *a1;
do
{
while ( (v5[v6] & 0x800) == 0 )
{
v6 = *++v1;
v3 = 0;
if ( !(_BYTE)v6 )
return v4;
}
if ( !v3 )
{
++v4;
v3 = 1;
}
v6 = *++v1;
}
while ( (_BYTE)v6 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char *v1; // rbx
const unsigned __int16 **v2; // rax
char v3; // dl
unsigned int v4; // er8
const unsigned __int16 *v5; // rcx
__int64 v6; // rax

v1 = a1;
v2 = __ctype_b_loc();
v3 = 0;
v4 = 0;
v5 = *v2;
v6 = *a1;
do
{
while ( (v5[v6] & 0x800) == 0 )
{
v6 = *++v1;
v3 = 0;
if ( !(_BYTE)v6 )
return v4;
}
if ( !v3 )
{
++v4;
v3 = 1;
}
v6 = *++v1;
}
while ( (_BYTE)v6 );
return v4;
}

original_code:
int findx(char* str)
{
 int numcont=0;
 _Bool priortype=0;
 do{
  if(((*__ctype_b_loc ())[(int) (((int)*str))] & (unsigned short int) _ISdigit)){
   if(!priortype)
    numcont++;
   priortype=1;
  }else
   priortype=0;
 }while(*++str);
 return numcont;
}

canonical_original_code:
int findx(char *str)
{
 int numcont = 0;
 _Bool priortype = 0;
 do{
  if(((*__ctype_b_loc ())[(int) (((int)*str))] & (unsigned short) _ISdigit)){
   if(!priortype)
    numcont++;
   priortype=1;
  }else
   priortype=0;
 }while(*++str);
 return numcont;
}

variable_types:
str
char *

variable_types: numcont int


separ

decompiled_code:
__int64 __fastcall separ(__int64 a1, char *a2)
{
__int64 result; // rax
__int64 v3; // rbx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

result = (unsigned int)X;
endptr = a2;
if ( X > 0 )
{
v3 = 0LL;
do
{
result = strtol(endptr, &endptr, 10);
*(_DWORD *)(a1 + 4 * v3++) = result;
}
while ( X > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
__int64 result; // rax
__int64 v3; // rbx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

result = (unsigned int)X;
endptr = a2;
if ( X > 0 )
{
v3 = 0LL;
do
{
result = strtol(endptr, &endptr, 10);
*(_DWORD *)(a1 + 4 * v3++) = result;
}
while ( X > (int)v3 );
}
return result;
}

original_code:
void separ(int* c, char* str)
{
 int i;
 for(i=0; i<X; i++)
  c[i]=(int)strtol(str, &str, 10);
 return;
}

canonical_original_code:
void separ(int *c, char *str)
{
 int i;
 for(i=0; i<X; i++)
  c[i]=(int)strtol(str, &str, 10);
 return;
}

variable_types:
c
int *

variable_types: i int


DependOn

original_code:
void DependOn(int* ar, int place, int_fast8_t* dned)
{
 int i, j;
 int cnt=0;
 int cabricnt=0;
 for(i=0; i<Ceilings; i++)
  dned[i]=0;
 for(i=0; i<X; i++)
  dned[ar[i+place*X]]=1;
 for(i=place+1; i<ple; i++){
  for(j=0; j<X; j++)
   if(dned[ar[j+i*X]])
    cabricnt++;
  if(cabricnt==X%2){
   cnt++;
   for(j=0; j<X; j++)
    fprintf(fp, "%3d", ar[j+i*X]);
   fputc('\n', fp);
  }
  cabricnt=0;
 }
 sum+=cnt;
 return;
}

canonical_original_code:
void DependOn(int *ar, int place, char *dned)
{
 int i; int j;
 int cnt = 0;
 int cabricnt = 0;
 for(i=0; i<Ceilings; i++)
  dned[i]=0;
 for(i=0; i<X; i++)
  dned[ar[i+place*X]]=1;
 for(i=place+1; i<ple; i++){
  for(j=0; j<X; j++)
   if(dned[ar[j+i*X]])
    cabricnt++;
  if(cabricnt==X%2){
   cnt++;
   for(j=0; j<X; j++)
    fprintf(fp, "%3d", ar[j+i*X]);
   fputc('\n', fp);
  }
  cabricnt=0;
 }
 sum+=cnt;
 return;
}

variable_types:
ar
int *

variable_types: place int

variable_types:
dned
char *

variable_types: j int

variable_types: cnt int

variable_types: cabricnt int


main

canonical_name: main

repo: Terminus-IMRC/detect-endian

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int128 v4; // [rsp+0h] [rbp-108h] BYREF
char v5[232]; // [rsp+10h] [rbp-F8h] BYREF
int v6; // [rsp+F8h] [rbp-10h]
__int16 v7; // [rsp+FCh] [rbp-Ch]
char v8; // [rsp+FEh] [rbp-Ah]

v4 = 0LL;
memset(v5, 0, sizeof(v5));
v7 = 0;
v6 = 0;
v8 = 0;
strcpy((char *)&v4, "Little endian");
puts((const char *)&v4);
return 0;
}

original_code:
int main()
{
 char str[0xff]="";
 switch(1234){
  case 1234:
   strcpy(str, "Little endian");
   break;
  case 4321:
   strcpy(str, "Big endian");
   break;
  case 3412:
   strcpy(str, "PDP endian");
   break;
  default:
   strcpy(str, "Unknown endian");
   break;
 }
 printf("%s\n", str);
 return 0;
}

canonical_original_code:
int main()
{
 char str[255] = "";
 switch(1234){
  case 1234:
   strcpy(str, "Little endian");
   break;
  case 4321:
   strcpy(str, "Big endian");
   break;
  case 3412:
   strcpy(str, "PDP endian");
   break;
  default:
   strcpy(str, "Unknown endian");
   break;
 }
 printf("%s\n", str);
 return 0;
}

variable_types:
str
char [255]


repo: Terminus-IMRC/rotdash

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rbx
unsigned int v5; // er13
int v6; // ebp
int v7[11]; // [rsp+Ch] [rbp-2Ch]

result = 1;
v7[0] = 1546465148;
if ( argc == 2 )
{
v4 = 0LL;
chdir("/proc");
while ( !access(argv[1], 0) )
{
v5 = *((char *)v7 + v4);
v6 = v4 + 1;
printf("%c\b", v5);
if ( (_DWORD)v4 == 3 )
{
v6 = 0;
printf(".%c\b", v5);
}
v4 = v6;
fflush(_bss_start);
usleep(0x186A0u);
}
puts(".");
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    const char arr[] = { '|', '/', '-', '\\' };
    if (argc != 2)
 return 1;
    chdir("/proc");
    argc = 0;
    while (!access(argv[1], 0)) {
 printf("%c\b", arr[argc++]);
 if (argc == sizeof(arr)) {
     printf(".%c\b", arr[argc - 1]);
     argc = 0;
 }
 fflush(stdout);
 usleep(100000);
    }
    puts(".");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char arr[] = { '|', '/', '-', '\\' };
    if (argc != 2)
 return 1;
    chdir("/proc");
    argc = 0;
    while (!access(argv[1], 0)) {
 printf("%c\b", arr[argc++]);
 if (argc == sizeof(arr)) {
     printf(".%c\b", arr[argc - 1]);
     argc = 0;
 }
 fflush(stdout);
 usleep(100000);
    }
    puts(".");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
arr
char []


repo: Terminus-IMRC/sc

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+Ch] [rbp-Ch]

v4 = 5;
do
{
reinit_all(*(_QWORD *)&argc, argv, envp);
if ( !_setjmp(jb) )
crosschannel(0LL);
*(_QWORD *)&argc = (unsigned int)rcont;
argv = (const char **)&route;
sc_output((unsigned int)rcont, &route);
--v4;
}
while ( v4 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+Ch] [rbp-Ch]

v4 = 5;
do
{
func8(*(_QWORD *)&argc, argv, envp);
if ( !_setjmp(jb) )
func9(0LL);
*(_QWORD *)&argc = (unsigned int)rcont;
argv = (const char **)&route;
func7((unsigned int)rcont, &route);
--v4;
}
while ( v4 );
return 0;
}

original_code:
int main()
{
 int i;
 for(i=0; i<5; i++){
  reinit_all();
  if(!_setjmp (jb))
   crosschannel(0);
  sc_output(rcont, route);
 }
 return 0;
}


decompiled_code:
int __fastcall sc_output(int a1, __int64 a2)
{
int i; // eax

printf("%d", (unsigned int)a1);
sc_i = 0;
if ( a1 > 0 )
{
for ( i = 0; i < a1; sc_i = i )
{
printf("%3d", *(unsigned int *)(a2 + 4LL * i));
i = sc_i + 1;
}
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(int a1, __int64 a2)
{
int i; // eax

printf("%d", (unsigned int)a1);
sc_i = 0;
if ( a1 > 0 )
{
for ( i = 0; i < a1; sc_i = i )
{
printf("%3d", *(unsigned int *)(a2 + 4LL * i));
i = sc_i + 1;
}
}
return putchar(10);
}

original_code:
void sc_output(int sc_length, int *sc_path){
  printf("%d",sc_length);
  for(sc_i = 0; sc_i<sc_length; ++sc_i){printf("%3d",sc_path[sc_i]);
 }printf("\n");}


decompiled_code:
int reinit_all()
{
__int64 i; // rbx
char *v1; // rax
int result; // eax
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

for ( i = 0LL; i != 20; ++i )
{
v1 = fgets(v3, 32, stdin);
result = atoi(v1);
step[i] = 0;
q[i] = result;
}
rcont = 0;
return result;
}

canonical_decompiled_code:
int func8()
{
__int64 i; // rbx
char *v1; // rax
int result; // eax
char v3[40]; // [rsp+0h] [rbp-28h] BYREF

for ( i = 0LL; i != 20; ++i )
{
v1 = fgets(v3, 32, stdin);
result = atoi(v1);
step[i] = 0;
q[i] = result;
}
rcont = 0;
return result;
}

original_code:
void reinit_all()
{
 int i;
 char str[32];
 for(i=0; i<20; i++){
  q[i]=atoi(fgets(str, 32, stdin));
  step[i]=0;
 }
 rcont=0;
 return;
}

variable_types:
str
char [32]


crosschannel

decompiled_code:
__int64 __fastcall crosschannel(int a1)
{
int v1; // edx
__int64 result; // rax

v1 = rcont + 1;
route[rcont] = a1;
rcont = v1;
if ( a1 == 19 )
longjmp(jb, 1);
result = crosschannel_header_l2();
--rcont;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // edx
__int64 result; // rax

v1 = rcont + 1;
route[rcont] = a1;
rcont = v1;
if ( a1 == 19 )
longjmp(jb, 1);
result = func10();
--rcont;
return result;
}

original_code:
void crosschannel(int m)
{
 route[rcont++]=m;
 if(m==20 -1)
  longjmp(jb, 1);
 crosschannel_header_l2(m);
 rcont--;
 return;
}

variable_types: m int


decompiled_code:
__int64 __fastcall crosschannel_header_l2(int a1)
{
int v1; // ecx
int v2; // edx
int v3; // edi
int v4; // edx
__int64 v5; // rbx
__int64 result; // rax
int v7; // edi

v1 = q[a1];
v2 = v1 + a1;
v3 = a1 - v1 + 20;
v4 = v2 % 20;
v5 = v4;
result = (unsigned int)(20 * (v3 / 20));
v7 = v3 % 20;
if ( !step[v4] )
{
step[v4] = 1;
result = crosschannel(v4);
step[v5] = 0;
if ( !step[v7] )
{
step[v7] = 1;
result = crosschannel(v7);
step[v7] = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
int v1; // ecx
int v2; // edx
int v3; // edi
int v4; // edx
__int64 v5; // rbx
__int64 result; // rax
int v7; // edi

v1 = q[a1];
v2 = v1 + a1;
v3 = a1 - v1 + 20;
v4 = v2 % 20;
v5 = v4;
result = (unsigned int)(20 * (v3 / 20));
v7 = v3 % 20;
if ( !step[v4] )
{
step[v4] = 1;
result = func9(v4);
step[v5] = 0;
if ( !step[v7] )
{
step[v7] = 1;
result = func9(v7);
step[v7] = 0;
}
}
return result;
}

original_code:
void crosschannel_header_l2(int m)
{
 int i;
 int ideal[2];
 ideal[0]=(m+q[m])%20;
 ideal[1]=(m-q[m]+20)%20;
 for(i=0; i<2; i++){
  if(step[ideal[i]])
   return;
  step[ideal[i]]=1;
  crosschannel(ideal[i]);
  step[ideal[i]]=0;
 }
 return;
}

variable_types:
ideal
int [2]


repo: Tesian/lock

decompiled_code:
_BOOL8 __fastcall my_manage_password(int a1, char a2, const char *a3)
{
int v4; // eax
const char *v5; // rax

if ( c_2 == a2 )
return 1LL;
if ( a1 == 27 )
{
my_memset(pass_enter_1, 63LL, 0LL);
i_0 = -1;
}
else if ( a1 == 8 )
{
if ( i_0 >= 0 )
{
--i_0;
return 1LL;
}
}
else
{
c_2 = a2;
if ( a2 )
{
v4 = i_0;
if ( i_0 <= 61 )
{
++i_0;
pass_enter_1[v4 + 1] = a2;
}
if ( a1 == 13 )
{
pass_enter_1[i_0] = 0;
v5 = (const char *)my_crypt(pass_enter_1);
return strcmp(a3, v5) != 0;
}
}
}
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, char a2, const char *a3)
{
int v4; // eax
const char *v5; // rax

if ( c_2 == a2 )
return 1LL;
if ( a1 == 27 )
{
my_memset(pass_enter_1, 63LL, 0LL);
i_0 = -1;
}
else if ( a1 == 8 )
{
if ( i_0 >= 0 )
{
--i_0;
return 1LL;
}
}
else
{
c_2 = a2;
if ( a2 )
{
v4 = i_0;
if ( i_0 <= 61 )
{
++i_0;
pass_enter_1[v4 + 1] = a2;
}
if ( a1 == 13 )
{
pass_enter_1[i_0] = 0;
v5 = (const char *)my_crypt(pass_enter_1);
return strcmp(a3, v5) != 0;
}
}
}
return 1LL;
}

original_code:
int my_manage_password(int key, unsigned char unicode, char *pass)
{
  static int i = -1;
  static char pass_enter[64];
  int ret = 1;
  static unsigned char c = 0;
  char *pass_enter_crypt;
  if (c == unicode)
    return (1);
  if (key == SDLK_ESCAPE)
    {
      my_memset(pass_enter, 63, '\0');
      i = -1;
      return (1);
    }
  if (key == SDLK_BACKSPACE)
    {
      if (i > -1)
 i--;
      return (1);
    }
  if ((c = unicode) != 0)
    {
      if (i < 62)
 pass_enter[++i] = c;
      if (key == SDLK_RETURN)
 {
   pass_enter[i] = '\0';
   pass_enter_crypt = my_crypt(pass_enter);
   if (strcmp(pass, pass_enter_crypt) == 0)
     ret = 0;
 }
    }
  return (ret);
}

variable_types: key int

variable_types:
unicode
unsigned char

variable_types:
pass
char *

variable_types: ret int

variable_types:
c
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char v4; // bl

v3 = time(0LL);
srand(v3);
v4 = my_pars_sort(argv);
if ( argc == 2 )
{
if ( !(unsigned int)my_strcmp(argv[1], "-h") )
{
my_putstr(&unk_350);
return 0;
}
}
else if ( argc == 3 && !(unsigned int)my_strcmp(argv[1], "-p") )
{
make_password(argv[2]);
return 0;
}
my_lock(argc, (__int64)argv, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
char v4; // bl

v3 = time(0LL);
srand(v3);
v4 = my_pars_sort(argv);
if ( argc == 2 )
{
if ( !(unsigned int)my_strcmp(argv[1], "-h") )
{
my_putstr(&unk_350);
return 0;
}
}
else if ( argc == 3 && !(unsigned int)my_strcmp(argv[1], "-p") )
{
make_password(argv[2]);
return 0;
}
func2(argc, (__int64)argv, v4);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  char sort;
  srand(time(((void *)0)));
  sort = my_pars_sort(argv);
  if (argc == 2 && my_strcmp(argv[1], "-h") == 0)
    my_putstr("\nHelp lock:\n     le password doit faire moins de 60 caractères, liste des caractères\n     autorisés : azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN\n     123456789&\"'(-_)=/*-+$%!:/;.,?~#{[|`\\@]}\nlock lance le lock avec les images contenues dans le dossier par default\n     (voir lock.h)\n-h   affiche ce récapitulatif.\n-p   \"password\" remplace le password courant par \"password\".\n     lock dir1 dir2 dir3 lance le lock avec les images contenues dans les 3\n     dossiers.\n\nOptions de tris des images :\n           tri par default \"vrai aléatoire\" une images peut se répéter\n           deux fois (chaque fois une images et choisi aux hasards dans \n           l'ensemble des images).\n-t.rand    random organisé une images ne peut pas se répéter deux fois (une \n           liste est fait au départ qui met les images dans le désordre).\n-t.alpha   tri alphaphabétiques.\n-t.numeric tri numérique.\n\n");
  else if (argc == 3 && my_strcmp(argv[1], "-p") == 0)
    make_password(argv[2]);
  else
    my_lock(argc, argv, sort);
  return (0);
}

variable_types:
argv
char **

variable_types: sort char


decompiled_code:
__int64 get_password()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax
char buf; // [rsp+Fh] [rbp-59h] BYREF
char v4[88]; // [rsp+10h] [rbp-58h] BYREF

v0 = -1LL;
buf = 0;
v1 = open("/home/tesian/Prog/kikoo/lock/.password", 0);
if ( v1 == -1 )
goto LABEL_9;
while ( read(v1, &buf, 1uLL) == 1 && buf != 10 )
{
if ( (_DWORD)v0 != 62 )
v4[++v0] = buf;
}
v4[(int)v0 + 1] = 0;
if ( close(v1) == -1 )
LABEL_9:
result = 0LL;
else
result = my_strdup(v4);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax
char buf; // [rsp+Fh] [rbp-59h] BYREF
char v4[88]; // [rsp+10h] [rbp-58h] BYREF

v0 = -1LL;
buf = 0;
v1 = open("/home/tesian/Prog/kikoo/lock/.password", 0);
if ( v1 == -1 )
goto LABEL_9;
while ( read(v1, &buf, 1uLL) == 1 && buf != 10 )
{
if ( (_DWORD)v0 != 62 )
v4[++v0] = buf;
}
v4[(int)v0 + 1] = 0;
if ( close(v1) == -1 )
LABEL_9:
result = 0LL;
else
result = my_strdup(v4);
return result;
}

original_code:
char *get_password()
{
  int fd;
  char str[64];
  char c = '\0';
  int i = -1;
  if ((fd = open("/home/tesian/Prog/kikoo/lock/.password", 00)) == -1)
    return (((void *)0));
  while (read(fd, &c, 1) == 1 && c != '\n')
    if (i < 62)
      str[++i] = c;
  str[++i] = '\0';
  if (close(fd) == -1)
    return (((void *)0));
  return (my_strdup(str));
}

variable_types: fd int

variable_types:
str
char [64]

variable_types: c char

variable_types: i int

return_type: char *


decompiled_code:
char *__fastcall my_crypt(char *a1)
{
char v1; // al
char *i; // rdx

v1 = *a1;
for ( i = a1; *i; v1 = *i )
*i++ = v1 ^ 0x15;
*i = 0;
return a1;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
char v1; // al
char *i; // rdx

v1 = *a1;
for ( i = a1; *i; v1 = *i )
*i++ = v1 ^ 0x15;
*i = 0;
return a1;
}

original_code:
char *my_crypt(char *password)
{
  int i = -1;
  while (password[++i])
    password[i] = password[i] ^ 21;
  password[i] = '\0';
  return (password);
}

variable_types:
password
char *


decompiled_code:
__int64 __fastcall make_password(char *a1)
{
unsigned int v1; // er12
char *v2; // rbp
int v3; // eax

v1 = open("/home/tesian/Prog/kikoo/lock/.password", 577, 420LL);
if ( v1 == -1 )
{
my_putstr_error(&unk_1A0);
}
else
{
v2 = my_crypt(a1);
v3 = my_strlen(v2);
write(v1, v2, v3);
write(v1, &unk_1D9, 1uLL);
v1 = close(v1);
if ( v1 != -1 )
{
v1 = 0;
my_putstr("Change password done.\n");
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
unsigned int v1; // er12
char *v2; // rbp
int v3; // eax

v1 = open("/home/tesian/Prog/kikoo/lock/.password", 577, 420LL);
if ( v1 == -1 )
{
my_putstr_error(&unk_1A0);
}
else
{
v2 = func1(a1);
v3 = my_strlen(v2);
write(v1, v2, v3);
write(v1, &unk_1D9, 1uLL);
v1 = close(v1);
if ( v1 != -1 )
{
v1 = 0;
my_putstr("Change password done.\n");
}
}
return v1;
}

original_code:
int make_password(char *password)
{
  int fd;
  char *encrypt_password;
  if ((fd = open("/home/tesian/Prog/kikoo/lock/.password", 0100 | 01000 | 01,
   0400 | 0200 | (0400 >> 3) | ((0400 >> 3) >> 3))) == -1)
    {
      my_putstr_error("Une erreur a empêché la modification du mot de passe.\n");
      return (-1);
    }
  encrypt_password = my_crypt(password);
  write(fd, encrypt_password, my_strlen(encrypt_password));
  write(fd, "\n", 1);
  if (close(fd) == -1)
    return (-1);
  my_putstr("Change password done.\n");
  return (0);
}


decompiled_code:
__int64 __fastcall my_pars_sort(_QWORD *a1)
{
do
{
if ( !*a1 )
return 0LL;
if ( !(unsigned int)my_strcmp("-t.rand") )
return 1LL;
if ( !(unsigned int)my_strcmp("-t.alpha") )
return 2LL;
++a1;
}
while ( (unsigned int)my_strcmp("-t.numeric") );
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
do
{
if ( !*a1 )
return 0LL;
if ( !(unsigned int)my_strcmp("-t.rand") )
return 1LL;
if ( !(unsigned int)my_strcmp("-t.alpha") )
return 2LL;
++a1;
}
while ( (unsigned int)my_strcmp("-t.numeric") );
return 3LL;
}

original_code:
char my_pars_sort(char **av)
{
  int i = -1;
  while (av[++i])
    if (my_strcmp("-t.rand", av[i]) == 0)
      return (1);
    else if (my_strcmp("-t.alpha", av[i]) == 0)
      return (2);
    else if (my_strcmp("-t.numeric", av[i]) == 0)
      return (3);
  return (0);
}

variable_types:
av
char **

return_type: char


decompiled_code:
__int64 __fastcall my_manage_sort(__int64 a1)
{
return a1;
}

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

original_code:
t_list *my_manage_sort(t_list *list, char sort)
{
  return (list);
}

canonical_original_code:
struct s_list *my_manage_sort(struct s_list *list, char sort)
{
  return (list);
}

variable_types:
list
struct s_list *

return_type: struct s_list { char *str; struct s_list *next; } *


original_code:
int my_check_is_bmp(char *filename)
{
  int strlen = my_strlen(filename);
  if (filename[strlen - 4] == '.' &&
      filename[strlen - 3] == 'b' &&
      filename[strlen - 2] == 'm' &&
      filename[strlen - 1] == 'p')
    return (1);
  return (0);
}

variable_types:
filename
char *

variable_types: strlen int


repo: Tethik/arp-failover

decompiled_code:
void *__fastcall allocate_strmem(int a1)
{
void *result; // rax

if ( a1 <= 0 )
{
fprintf(stderr, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", (unsigned int)a1);
exit(1);
}
result = calloc(a1, 1uLL);
if ( !result )
{
fwrite("ERROR: Cannot allocate memory for array allocate_strmem().\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
void *result; // rax

if ( a1 <= 0 )
{
fprintf(stderr, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", (unsigned int)a1);
exit(1);
}
result = calloc(a1, 1uLL);
if ( !result )
{
fwrite("ERROR: Cannot allocate memory for array allocate_strmem().\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
return result;
}

original_code:
char * allocate_strmem (int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", len);
    exit (1);
  }
  tmp = (char *) malloc (len * sizeof (char));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (char));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_strmem().\n");
    exit (1);
  }
}

canonical_original_code:
char *allocate_strmem(int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_strmem().\n", len);
    exit (1);
  }
  tmp = (char *) malloc (len * sizeof (char));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (char));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_strmem().\n");
    exit (1);
  }
}

variable_types: len int

variable_types:
tmp
void *


decompiled_code:
void *__fastcall allocate_ustrmem(int a1)
{
void *result; // rax

if ( a1 <= 0 )
{
fprintf(stderr, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", (unsigned int)a1);
exit(1);
}
result = calloc(a1, 1uLL);
if ( !result )
{
fwrite("ERROR: Cannot allocate memory for array allocate_ustrmem().\n", 1uLL, 0x3CuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func9(int a1)
{
void *result; // rax

if ( a1 <= 0 )
{
fprintf(stderr, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", (unsigned int)a1);
exit(1);
}
result = calloc(a1, 1uLL);
if ( !result )
{
fwrite("ERROR: Cannot allocate memory for array allocate_ustrmem().\n", 1uLL, 0x3CuLL, stderr);
exit(1);
}
return result;
}

original_code:
uint8_t * allocate_ustrmem (int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", len);
    exit (1);
  }
  tmp = (uint8_t *) malloc (len * sizeof (uint8_t));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (uint8_t));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_ustrmem().\n");
    exit (1);
  }
}

canonical_original_code:
unsigned char *allocate_ustrmem(int len)
{
  void *tmp;
  if (len <= 0) {
    fprintf (stderr, "ERROR: Cannot allocate memory because len = %i in allocate_ustrmem().\n", len);
    exit (1);
  }
  tmp = (unsigned char *) malloc (len * sizeof (unsigned char));
  if (tmp != ((void *)0)) {
    memset (tmp, 0, len * sizeof (unsigned char));
    return (tmp);
  } else {
    fprintf (stderr, "ERROR: Cannot allocate memory for array allocate_ustrmem().\n");
    exit (1);
  }
}

return_type: unsigned char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // rdi
const char **v5; // rbp
char v7[10]; // [rsp+Ah] [rbp-11Eh] BYREF
char v8; // [rsp+14h] [rbp-114h]
char v9; // [rsp+15h] [rbp-113h] BYREF

strcpy(v7, "nano ");
system("clear");
printMenu("clear", argv);
printf("Choose an Operation:> ");
while ( 1 )
{
LABEL_2:
v3 = getchar();
do
{
if ( getchar() == 10 )
{
switch ( v3 )
{
case 'c':
printf("Change To?: ");
argv = (const char **)findFile(4LL);
v5 = argv;
strcpy(&v7[6], (const char *)argv);
if ( chdir(&v7[6]) == -1 )
{
puts("No such directory.Try again.\n");
}
else
{
system("clear");
printMenu("clear", argv);
}
goto LABEL_10;
case 'e':
printf("Edit what?: ");
v4 = &v9;
v5 = (const char **)findFile(8LL);
argv = v5;
*(_DWORD *)&v7[6] = *(_DWORD *)v7;
v8 = v7[4];
goto LABEL_9;
case 'p':
system("clear");
printMenu("clear", argv);
printf("Choose an Operation:> ");
goto LABEL_7;
case 'q':
exit(0);
case 'r':
printf("Run what?: ");
v4 = &v7[8];
v5 = (const char **)findFile(8LL);
*(_WORD *)&v7[6] = 12078;
argv = v5;
LABEL_9:
strcpy(v4, (const char *)argv);
system(&v7[6]);
LABEL_10:
printf("Choose an Operation:> ");
free(v5);
goto LABEL_2;
default:
goto LABEL_7;
}
}
}
while ( v3 != -1 );
LABEL_7:
puts("Invalid operation! Try again...");
printf("Choose an Operation:> ");
}
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char *v4; // rdi
const char **v5; // rbp
char v7[10]; // [rsp+Ah] [rbp-11Eh] BYREF
char v8; // [rsp+14h] [rbp-114h]
char v9; // [rsp+15h] [rbp-113h] BYREF

strcpy(v7, "nano ");
system("clear");
func11("clear", argv);
printf("Choose an Operation:> ");
while ( 1 )
{
LABEL_2:
v3 = getchar();
do
{
if ( getchar() == 10 )
{
switch ( v3 )
{
case 'c':
printf("Change To?: ");
argv = (const char **)func12(4LL);
v5 = argv;
strcpy(&v7[6], (const char *)argv);
if ( chdir(&v7[6]) == -1 )
{
puts("No such directory.Try again.\n");
}
else
{
system("clear");
func11("clear", argv);
}
goto LABEL_10;
case 'e':
printf("Edit what?: ");
v4 = &v9;
v5 = (const char **)func12(8LL);
argv = v5;
*(_DWORD *)&v7[6] = *(_DWORD *)v7;
v8 = v7[4];
goto LABEL_9;
case 'p':
system("clear");
func11("clear", argv);
printf("Choose an Operation:> ");
goto LABEL_7;
case 'q':
exit(0);
case 'r':
printf("Run what?: ");
v4 = &v7[8];
v5 = (const char **)func12(8LL);
*(_WORD *)&v7[6] = 12078;
argv = v5;
LABEL_9:
strcpy(v4, (const char *)argv);
system(&v7[6]);
LABEL_10:
printf("Choose an Operation:> ");
free(v5);
goto LABEL_2;
default:
goto LABEL_7;
}
}
}
while ( v3 != -1 );
LABEL_7:
puts("Invalid operation! Try again...");
printf("Choose an Operation:> ");
}
}

original_code:
int main(void)
{
    int c, l;
    char *s;
    char cmd[256];
    const char EDITOR[] = "nano ";
    system("clear");
    printMenu();
    printf("Choose an Operation:> ");
    while (1) {
        c = getchar();
        while (getchar() != '\n' && c != (-1));
        switch (c) {
            case 'q': exit(0);
            case 'c': printf("Change To?: ");
                      s = findFile(DT_DIR);
                      strcpy(cmd, s);
                      if (chdir(cmd) == -1) {
                          printf("No such directory.Try again.\n\n");
                      } else {
                          system("clear");
                          printMenu();
                      }
                      printf("Choose an Operation:> ");
                      break;
            case 'e': printf("Edit what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, EDITOR);
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'r': printf("Run what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, "./");
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'p': system("clear");
                      printMenu();
                      printf("Choose an Operation:> ");
            default: printf("Invalid operation! Try again...\n");
                      printf("Choose an Operation:> ");
                      continue;
        }
        free(s);
    }
    return 0;
}

canonical_original_code:
int main()
{
    int c; int l;
    char *s;
    char cmd[256];
    char EDITOR[] = "nano ";
    system("clear");
    printMenu();
    printf("Choose an Operation:> ");
    while (1) {
        c = getchar();
        while (getchar() != '\n' && c != (-1));
        switch (c) {
            case 'q': exit(0);
            case 'c': printf("Change To?: ");
                      s = findFile(DT_DIR);
                      strcpy(cmd, s);
                      if (chdir(cmd) == -1) {
                          printf("No such directory.Try again.\n\n");
                      } else {
                          system("clear");
                          printMenu();
                      }
                      printf("Choose an Operation:> ");
                      break;
            case 'e': printf("Edit what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, EDITOR);
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'r': printf("Run what?: ");
                      s = findFile(DT_REG);
                      strcpy(cmd, "./");
                      strcat(cmd, s);
                      system(cmd);
                      printf("Choose an Operation:> ");
                      break;
            case 'p': system("clear");
                      printMenu();
                      printf("Choose an Operation:> ");
            default: printf("Invalid operation! Try again...\n");
                      printf("Choose an Operation:> ");
                      continue;
        }
        free(s);
    }
    return 0;
}

variable_types: c int

variable_types: l int

variable_types:
s
char *

variable_types:
cmd
char [256]

variable_types:
EDITOR
char []


printDirectory

decompiled_code:
int printDirectory()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

getcwd(v1, 0xC8uLL);
return printf("Current Directory: %s\n", v1);
}

canonical_decompiled_code:
int func7()
{
char v1[264]; // [rsp+0h] [rbp-108h] BYREF

getcwd(v1, 0xC8uLL);
return printf("Current Directory: %s\n", v1);
}

original_code:
void printDirectory() {
    char s[256];
    getcwd(s, 200);
    printf("Current Directory: %s\n", s);
}

variable_types:
s
char [256]


printTime

decompiled_code:
int printTime()
{
char *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
return printf("Current time: %s\n", v0);
}

canonical_decompiled_code:
int func8()
{
char *v0; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = ctime(&timer);
return printf("Current time: %s\n", v0);
}

original_code:
void printTime() {
    time_t t;
    t = time(((void *)0));
    printf( "Current time: %s\n", ctime( &t ));
}

canonical_original_code:
void printTime() {
    long t;
    t = time(((void *)0));
    printf( "Current time: %s\n", ctime( &t ));
}

variable_types: t long


freeMem

decompiled_code:
void __fastcall freeMem(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void freeMem(char **files, int size) {
    int i;
    for (i = 0; i < size; i++) {
        free(files[i]);
    }
    free(files);
}

variable_types:
files
char **

variable_types: size int


printMenu

decompiled_code:
void printMenu()
{
const char **v0; // rbp
const char **v1; // r12
int v2; // er13
int v3; // ebx
char v4; // r15
int v5; // er13
int v6; // ebx
char v7; // r15
int v8; // [rsp+8h] [rbp-40h] BYREF
int v9[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v9[0] = 0;
printDirectory();
printTime();
v0 = (const char **)getFilesInDir(8, &v8);
v1 = (const char **)getFilesInDir(4, v9);
if ( v8 + v9[0] > 1024 )
{
printf(
"ERROR! Number of files and directories in the\ncurrent directory exceed the max of %d.\n\nExiting program...\n\n",
1024LL);
exit(1);
}
if ( v8 )
{
puts("\n====================================\n Files\n====================================");
if ( v8 > 0 )
{
v2 = 1;
printf("%d. %s\n", 0LL, *v0);
while ( v8 > v2 )
{
v3 = v2 + 1;
printf("%d. %s\n", (unsigned int)v2, v0[v2]);
if ( __ROR4__(-858993459 * (v2 + 1) + 429496728, 1) <= 0x19999998u )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v4 = getchar();
while ( getchar() != 10 )
{
if ( v4 == -1 )
goto LABEL_5;
}
if ( v4 == 112 )
{
v3 = v2 - 19;
if ( v2 - 19 < 0 )
v3 = 0;
}
else if ( v4 == 115 )
{
break;
}
}
LABEL_5:
v2 = v3;
}
}
}
else
{
puts("Files: There is no file in current directory.");
}
printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
while ( getchar() != 10 )
;
if ( v9[0] )
{
puts("\n====================================\n Directories\n====================================");
if ( v9[0] > 0 )
{
v5 = 1;
printf("%d. %s\n", 0LL, *v1);
while ( v9[0] > v5 )
{
v6 = v5 + 1;
printf("%d. %s\n", (unsigned int)v5, v1[v5]);
if ( __ROR4__(-858993459 * (v5 + 1) + 429496728, 1) <= 0x19999998u )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v7 = getchar();
while ( getchar() != 10 )
{
if ( v7 == -1 )
goto LABEL_23;
}
if ( v7 == 112 )
{
v6 = v5 - 19;
if ( v5 - 19 < 0 )
v6 = 0;
}
else if ( v7 == 115 )
{
break;
}
}
LABEL_23:
v5 = v6;
}
}
}
else
{
printf("\nDirectory: There is no sub-directory in current directory.");
}
puts("------------------------------------");
puts(
"\n"
"Operation: 'e' Edit\n"
" 'r' Run\n"
" 'c' Change directory\n"
" 'p' Print directory\n"
" 'q' Quit\n");
puts("------------------------------------");
freeMem(v0, v8);
freeMem(v1, v9[0]);
}

canonical_decompiled_code:
void func11()
{
const char **v0; // rbp
const char **v1; // r12
int v2; // er13
int v3; // ebx
char v4; // r15
int v5; // er13
int v6; // ebx
char v7; // r15
int v8; // [rsp+8h] [rbp-40h] BYREF
int v9[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v9[0] = 0;
func7();
func8();
v0 = (const char **)func10(8, &v8);
v1 = (const char **)func10(4, v9);
if ( v8 + v9[0] > 1024 )
{
printf(
"ERROR! Number of files and directories in the\ncurrent directory exceed the max of %d.\n\nExiting program...\n\n",
1024LL);
exit(1);
}
if ( v8 )
{
puts("\n====================================\n Files\n====================================");
if ( v8 > 0 )
{
v2 = 1;
printf("%d. %s\n", 0LL, *v0);
while ( v8 > v2 )
{
v3 = v2 + 1;
printf("%d. %s\n", (unsigned int)v2, v0[v2]);
if ( __ROR4__(-858993459 * (v2 + 1) + 429496728, 1) <= 0x19999998u )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v4 = getchar();
while ( getchar() != 10 )
{
if ( v4 == -1 )
goto LABEL_5;
}
if ( v4 == 112 )
{
v3 = v2 - 19;
if ( v2 - 19 < 0 )
v3 = 0;
}
else if ( v4 == 115 )
{
break;
}
}
LABEL_5:
v2 = v3;
}
}
}
else
{
puts("Files: There is no file in current directory.");
}
printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
while ( getchar() != 10 )
;
if ( v9[0] )
{
puts("\n====================================\n Directories\n====================================");
if ( v9[0] > 0 )
{
v5 = 1;
printf("%d. %s\n", 0LL, *v1);
while ( v9[0] > v5 )
{
v6 = v5 + 1;
printf("%d. %s\n", (unsigned int)v5, v1[v5]);
if ( __ROR4__(-858993459 * (v5 + 1) + 429496728, 1) <= 0x19999998u )
{
printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
v7 = getchar();
while ( getchar() != 10 )
{
if ( v7 == -1 )
goto LABEL_23;
}
if ( v7 == 112 )
{
v6 = v5 - 19;
if ( v5 - 19 < 0 )
v6 = 0;
}
else if ( v7 == 115 )
{
break;
}
}
LABEL_23:
v5 = v6;
}
}
}
else
{
printf("\nDirectory: There is no sub-directory in current directory.");
}
puts("------------------------------------");
puts(
"\n"
"Operation: 'e' Edit\n"
" 'r' Run\n"
" 'c' Change directory\n"
" 'p' Print directory\n"
" 'q' Quit\n");
puts("------------------------------------");
func9(v0, v8);
func9(v1, v9[0]);
}

original_code:
void printMenu() {
    char **files;
    char **directories;
    int fileCounter, dirCounter = 0;
    int i;
    printDirectory();
    printTime();
    files = getFilesInDir(DT_REG, &fileCounter);
    directories = getFilesInDir(DT_DIR, &dirCounter);
    if ((fileCounter + dirCounter) > 1024) {
        printf("ERROR! Number of files and directories in the\n"
                "current directory exceed the max of %d.\n\nExiting program...\n\n", 1024);
        exit(1);
    }
    if (fileCounter == 0) {
        printf("Files:        There is no file in current directory.\n");
    } else {
         printf( "\n====================================\n"
                "               Files"
                "\n====================================\n");
        i = 0;
        while (i < fileCounter) {
            printf("%d. %s\n", i, files[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = fileCounter;
                        break;
                }
            }
        }
    }
    printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
    while (getchar() != '\n');
    if (dirCounter == 0) {
        printf("\nDirectory:     There is no sub-directory in current directory.");
    } else {
        printf( "\n====================================\n"
                "             Directories"
                "\n====================================\n");
        i = 0;
        while (i < dirCounter) {
            printf("%d. %s\n", i, directories[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = dirCounter;
                        break;
                }
            }
        }
    }
    printf("------------------------------------\n");
    printf( "\n"
            "Operation:     'e'  Edit\n"
            "               'r'  Run\n"
            "               'c'  Change directory\n"
            "               'p'  Print directory\n"
            "               'q'  Quit\n"
            "\n");
    printf("------------------------------------\n");
    freeMem(files, fileCounter);
    freeMem(directories, dirCounter);
}

canonical_original_code:
void printMenu() {
    char **files;
    char **directories;
    int fileCounter; int dirCounter = 0;
    int i;
    printDirectory();
    printTime();
    files = getFilesInDir(DT_REG, &fileCounter);
    directories = getFilesInDir(DT_DIR, &dirCounter);
    if ((fileCounter + dirCounter) > 1024) {
        printf("ERROR! Number of files and directories in the\n"
                "current directory exceed the max of %d.\n\nExiting program...\n\n", 1024);
        exit(1);
    }
    if (fileCounter == 0) {
        printf("Files:        There is no file in current directory.\n");
    } else {
         printf( "\n====================================\n"
                "               Files"
                "\n====================================\n");
        i = 0;
        while (i < fileCounter) {
            printf("%d. %s\n", i, files[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = fileCounter;
                        break;
                }
            }
        }
    }
    printf("\nFinished listing files. Moving on to listing directories.\nPress Enter to continue.");
    while (getchar() != '\n');
    if (dirCounter == 0) {
        printf("\nDirectory:     There is no sub-directory in current directory.");
    } else {
        printf( "\n====================================\n"
                "             Directories"
                "\n====================================\n");
        i = 0;
        while (i < dirCounter) {
            printf("%d. %s\n", i, directories[i]);
            i++;
            if ((i % 10) == 0) {
                printf("\nEnter any key for next, 'p' for previous, or 's' to skip: ");
                char c = getchar();
                while (getchar() != '\n' && c != (-1));
                switch(c) {
                    case 'p':
                        i -= 20;
                        if (i < 0) { i = 0; }
                        break;
                    case 's':
                        i = dirCounter;
                        break;
                }
            }
        }
    }
    printf("------------------------------------\n");
    printf( "\n"
            "Operation:     'e'  Edit\n"
            "               'r'  Run\n"
            "               'c'  Change directory\n"
            "               'p'  Print directory\n"
            "               'q'  Quit\n"
            "\n");
    printf("------------------------------------\n");
    freeMem(files, fileCounter);
    freeMem(directories, dirCounter);
}

variable_types:
directories
char **

variable_types: fileCounter int

variable_types: dirCounter int

variable_types: i int

variable_types: c char


findFile

decompiled_code:
char *__fastcall findFile(char a1)
{
char *v1; // r12
const char **v2; // rbp
int v3; // er13
int v5; // [rsp+8h] [rbp-130h]
int v6; // [rsp+Ch] [rbp-12Ch] BYREF
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v1 = (char *)malloc(8uLL);
v2 = (const char **)getFilesInDir(a1, &v6);
if ( fgets(s, 256, stdin) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v3 = v6;
if ( v5 < v6 )
{
strcpy(v1, v2[v5]);
freeMem(v2, v3);
return v1;
}
}
strtok(s, "\n");
strcpy(v1, s);
}
freeMem(v2, v6);
return v1;
}

canonical_decompiled_code:
char *__fastcall func12(char a1)
{
char *v1; // r12
const char **v2; // rbp
int v3; // er13
int v5; // [rsp+8h] [rbp-130h]
int v6; // [rsp+Ch] [rbp-12Ch] BYREF
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v1 = (char *)malloc(8uLL);
v2 = (const char **)func10(a1, &v6);
if ( fgets(s, 256, stdin) )
{
if ( (unsigned int)__isoc99_sscanf() == 1 )
{
v3 = v6;
if ( v5 < v6 )
{
strcpy(v1, v2[v5]);
func9(v2, v3);
return v1;
}
}
strtok(s, "\n");
strcpy(v1, s);
}
func9(v2, v6);
return v1;
}

original_code:
char *findFile(unsigned char type) {
    char *input = malloc(sizeof(char *));
    char buffer[256];
    int i ,counter;
    char **files;
    files = getFilesInDir(type, &counter);
    if (fgets(buffer, sizeof(buffer), stdin)) {
        if (1 == sscanf(buffer, "%d", &i)) {
            if (i < counter) {
                strcpy(input, files[i]);
                freeMem(files, counter);
                return input;
            }
        }
        strtok(buffer, "\n");
        strcpy(input, buffer);
    }
    freeMem(files, counter);
    return input;
}

canonical_original_code:
char *findFile(unsigned char type) {
    char *input = malloc(sizeof(char *));
    char buffer[256];
    int i; int counter;
    char **files;
    files = getFilesInDir(type, &counter);
    if (fgets(buffer, sizeof(buffer), stdin)) {
        if (1 == sscanf(buffer, "%d", &i)) {
            if (i < counter) {
                strcpy(input, files[i]);
                freeMem(files, counter);
                return input;
            }
        }
        strtok(buffer, "\n");
        strcpy(input, buffer);
    }
    freeMem(files, counter);
    return input;
}

variable_types:
type
unsigned char

variable_types:
input
char *

variable_types:
buffer
char [256]

variable_types: counter int


genRandNum

decompiled_code:
__int64 __fastcall genRandNum(__int64 a1)
{
time_t v1; // rax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

_gmp_randinit_mt(v3);
v1 = time(0LL);
_gmp_randseed_ui(v3, v1);
return _gmpz_urandomb(a1, v3, 512LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
time_t v1; // rax
_BYTE v3[40]; // [rsp+0h] [rbp-28h] BYREF

_gmp_randinit_mt(v3);
v1 = time(0LL);
_gmp_randseed_ui(v3, v1);
return _gmpz_urandomb(a1, v3, 512LL);
}

original_code:
void genRandNum(mpz_t rop) {
  gmp_randstate_t state;
  __gmp_randinit_mt(state);
  unsigned long int seed = time(((void *)0));
  __gmp_randseed_ui(state, seed);
  mp_bitcnt_t n = 512;
  __gmpz_urandomb (rop, state, n);
}

canonical_original_code:
void genRandNum(struct __mpz_struct rop[1]) {
  struct __gmp_randstate_struct state[1];
  __gmp_randinit_mt(state);
  unsigned long seed = time(((void *)0));
  __gmp_randseed_ui(state, seed);
  unsigned long n = 512;
  __gmpz_urandomb (rop, state, n);
}

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

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types:
seed
unsigned long

variable_types:
n
unsigned long

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


isPrime

decompiled_code:
__int64 __fastcall isPrime(__int64 a1)
{
return _gmpz_probab_prime_p(a1, 50LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return _gmpz_probab_prime_p(a1, 50LL);
}

original_code:
int isPrime(mpz_t rop) {
  return __gmpz_probab_prime_p (rop, 50);
}

canonical_original_code:
int isPrime(struct __mpz_struct rop[1]) {
  return __gmpz_probab_prime_p (rop, 50);
}

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


getRandomPrime

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

do
{
genRandNum(a1);
result = isPrime(a1);
}
while ( !(_DWORD)result );
return result;
}

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

do
{
func0(a1);
result = func1(a1);
}
while ( !(_DWORD)result );
return result;
}

original_code:
int getRandomPrime(mpz_t rop) {
  do {
    genRandNum(rop);
  } while(!isPrime(rop));
}

canonical_original_code:
int getRandomPrime(struct __mpz_struct rop[1]) {
  do {
    genRandNum(rop);
  } while(!isPrime(rop));
}


printMPZ

decompiled_code:
__int64 __fastcall printMPZ(__int64 a1)
{
return _gmp_printf("%Zd\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return _gmp_printf("%Zd\n", a1);
}

original_code:
void printMPZ(mpz_t rop) {
  __gmp_printf("%Zd\n", rop);
}

canonical_original_code:
void printMPZ(struct __mpz_struct rop[1]) {
  __gmp_printf("%Zd\n", rop);
}


addMPZ

decompiled_code:
__int64 __fastcall addMPZ(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_add(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_add(a3, a1, a2);
}

original_code:
void addMPZ(mpz_t rop1, mpz_t rop2, mpz_t result) {
  __gmpz_add(result, rop1, rop2);
}

canonical_original_code:
void addMPZ(struct __mpz_struct rop1[1], struct __mpz_struct rop2[1], struct __mpz_struct result[1]) {
  __gmpz_add(result, rop1, rop2);
}

variable_types:
result
struct __mpz_struct [1]


subtractMPZ

decompiled_code:
__int64 __fastcall subtractMPZ(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_sub(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_sub(a3, a1, a2);
}

original_code:
void subtractMPZ(mpz_t rop1, mpz_t rop2, mpz_t result) {
  __gmpz_sub(result, rop1, rop2);
}

canonical_original_code:
void subtractMPZ(struct __mpz_struct rop1[1], struct __mpz_struct rop2[1], struct __mpz_struct result[1]) {
  __gmpz_sub(result, rop1, rop2);
}


multMPZ

decompiled_code:
__int64 __fastcall multMPZ(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_mul(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3)
{
return _gmpz_mul(a3, a1, a2);
}

original_code:
void multMPZ(mpz_t rop1, mpz_t rop2, mpz_t result) {
  __gmpz_mul(result, rop1, rop2);
}

canonical_original_code:
void multMPZ(struct __mpz_struct rop1[1], struct __mpz_struct rop2[1], struct __mpz_struct result[1]) {
  __gmpz_mul(result, rop1, rop2);
}


modExponentMPZ

decompiled_code:
__int64 __fastcall modExponentMPZ(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return _gmpz_powm(a4, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return _gmpz_powm(a4, a1, a2, a3);
}

original_code:
void modExponentMPZ(mpz_t base, mpz_t exp, mpz_t mod, mpz_t result) {
  __gmpz_powm (result, base, exp, mod);
}

canonical_original_code:
void modExponentMPZ(struct __mpz_struct base[1], struct __mpz_struct exp[1], struct __mpz_struct mod[1], struct __mpz_struct result[1]) {
  __gmpz_powm (result, base, exp, mod);
}

variable_types:
exp
struct __mpz_struct [1]

variable_types:
mod
struct __mpz_struct [1]


gcd

decompiled_code:
unsigned __int64 __fastcall gcd(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r8
unsigned __int64 v3; // rax
unsigned __int64 v4; // rdx

v2 = a1;
v3 = a2;
if ( !a1 )
return a2;
while ( 1 )
{
v4 = v3 % v2;
v3 = v2;
if ( !v4 )
break;
v2 = v4;
}
return v2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r8
unsigned __int64 v3; // rax
unsigned __int64 v4; // rdx

v2 = a1;
v3 = a2;
if ( !a1 )
return a2;
while ( 1 )
{
v4 = v3 % v2;
v3 = v2;
if ( !v4 )
break;
v2 = v4;
}
return v2;
}

original_code:
unsigned long int gcd (unsigned long int a, unsigned long int b)
{
  unsigned long int c;
  while (a != 0) {
    c = a;
    a = b%a;
    b = c;
  }
  return b;
}

canonical_original_code:
unsigned long gcd(unsigned long a, unsigned long b)
{
  unsigned long c;
  while (a != 0) {
    c = a;
    a = b%a;
    b = c;
  }
  return b;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
c
unsigned long


repo: Thirdhuku/TreeDB

decompiled_code:
int begin_timer()
{
return gettimeofday(&g_begin, 0LL);
}

canonical_decompiled_code:
int func3()
{
return gettimeofday(&g_begin, 0LL);
}

original_code:
void begin_timer()
{
 gettimeofday(&g_begin, ((void *)0));
}


decompiled_code:
int end_timer()
{
return gettimeofday(&g_end, 0LL);
}

canonical_decompiled_code:
int func4()
{
return gettimeofday(&g_end, 0LL);
}

original_code:
void end_timer()
{
 gettimeofday(&g_end, ((void *)0));
}


decompiled_code:
__int64 Diff_timer()
{
return (unsigned int)(1000 * LODWORD(g_end.tv_sec)
+ (int)g_end.tv_usec / 1000
- 1000 * LODWORD(g_begin.tv_sec)
- (int)g_begin.tv_usec / 1000);
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)(1000 * LODWORD(g_end.tv_sec)
+ (int)g_end.tv_usec / 1000
- 1000 * LODWORD(g_begin.tv_sec)
- (int)g_begin.tv_usec / 1000);
}

original_code:
int Diff_timer()
{
 return (g_end.tv_sec * 1000 + g_end.tv_usec / 1000) -
  (g_begin.tv_sec * 1000 + g_begin.tv_usec / 1000);
}


decompiled_code:
char **__fastcall stp_btree_open(char *file, char a2)
{
char v2; // r12
int v4; // esi
int v5; // edi
char **result; // rax
char **v7; // [rsp+8h] [rbp-B0h] BYREF
struct stat v8; // [rsp+10h] [rbp-A8h] BYREF

v2 = a2 & 0xF7;
v4 = 2;
if ( stat(file, &v8) < 0 )
{
v2 |= 0xCu;
fwrite("[WARNING] can't find the index file.\n", 1uLL, 0x25uLL, stderr);
v4 = 66;
}
v5 = open(file, v4, 484LL);
if ( v5 < 0 )
return 0LL;
v7 = 0LL;
if ( (int)read_btree_info(v5, &v7, v2) < 0 )
return 0LL;
result = v7;
*v7 = file;
return result;
}

canonical_decompiled_code:
char **__fastcall func7(char *file, char a2)
{
char v2; // r12
int v4; // esi
int v5; // edi
char **result; // rax
char **v7; // [rsp+8h] [rbp-B0h] BYREF
struct stat v8; // [rsp+10h] [rbp-A8h] BYREF

v2 = a2 & 0xF7;
v4 = 2;
if ( stat(file, &v8) < 0 )
{
v2 |= 0xCu;
fwrite("[WARNING] can't find the index file.\n", 1uLL, 0x25uLL, stderr);
v4 = 66;
}
v5 = open(file, v4, 484LL);
if ( v5 < 0 )
return 0LL;
v7 = 0LL;
if ( (int)func6(v5, &v7, v2) < 0 )
return 0LL;
result = v7;
*v7 = file;
return result;
}

original_code:
struct stp_btree_info* stp_btree_open(const char *btree_file, unsigned int mode)
{
    int bfd;
    mode_t m = 02;
    struct stat st;
    unsigned int flags = 0;
    mode &= ~(1<<3);
    if(stat(btree_file, &st) < 0) {
        mode |= (1<<3);
        fprintf(stderr,"[WARNING] can't find the index file.\n");
    }
    if(mode & (1<<3)) {
        m |= 0100;
        mode |= (1<<2);
    }
    if((bfd = open(btree_file, m, (0400|0200|0100) | (0400 >> 3) | ((0400 >> 3) >> 3))) < 0) {
        return ((void *)0);
    }
    struct stp_btree_info *tree = ((void *)0);
    if(read_btree_info(bfd, &tree, mode) < 0) {
        return ((void *)0);
    }
    tree->filename = btree_file;
    return tree;
}

canonical_original_code:
struct stp_btree_info *stp_btree_open(char *btree_file, unsigned int mode)
{
    int bfd;
    unsigned int m = 02;
    struct stat st;
    unsigned int flags = 0;
    mode &= ~(1<<3);
    if(stat(btree_file, &st) < 0) {
        mode |= (1<<3);
        fprintf(stderr,"[WARNING] can't find the index file.\n");
    }
    if(mode & (1<<3)) {
        m |= 0100;
        mode |= (1<<2);
    }
    if((bfd = open(btree_file, m, (0400|0200|0100) | (0400 >> 3) | ((0400 >> 3) >> 3))) < 0) {
        return ((void *)0);
    }
    struct stp_btree_info *tree = ((void *)0);
    if(read_btree_info(bfd, &tree, mode) < 0) {
        return ((void *)0);
    }
    tree->filename = btree_file;
    return tree;
}

variable_types:
mode
unsigned int

variable_types: bfd int

variable_types:
m
unsigned int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
flags
unsigned int

variable_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t { char __size[32]; long __align; } sem; unsigned int active; unsigned long off; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; } root; } *super; struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list { struct list *next; struct list *prev; } lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item { struct stp_header location; struct stp_bnode_key { unsigned long ino; unsigned char flags; } key[-1]; unsigned int nrkeys; struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; } ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; } *item; struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); } *ops; } *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); } *ops; } *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stp_btree_info { char *filename; int fd; unsigned char mode; unsigned long transid; union sem_t sem; unsigned int active; unsigned long off; union pthread_mutex_t mutex; struct stp_btree_super *super; struct stp_bnode *root; struct list node_list; struct list node_lru; struct list dirty_list; struct stp_btree_operations *ops; }

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

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

user_defined_types: struct stp_btree_super { unsigned int magic; unsigned int flags; unsigned long total_bytes; unsigned int nritems; unsigned long nrkeys; unsigned int bitmap[-1]; struct stp_header root; }

user_defined_types: struct stp_bnode { unsigned char flags; unsigned char ref; union pthread_mutex_t lock; struct list lru; struct list dirty; struct list list; struct stp_bnode *ptrs[-1]; struct stp_bnode *parent; struct stp_btree_info *tree; struct stp_bnode_item *item; struct stp_bnode_operations *ops; }

user_defined_types: struct stp_bnode_item { struct stp_header location; struct stp_bnode_key key[-1]; unsigned int nrkeys; struct stp_bnode_off ptrs[-1]; unsigned int nrptrs; unsigned int level; unsigned char flags; struct stp_header parent; unsigned char padding[38]; }


decompiled_code:
__int64 __fastcall insert_into_btree(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
char v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+9h] [rbp-1Fh]
__int64 v7; // [rsp+11h] [rbp-17h]

v4 = a2;
v7 = a3;
v5 = 0;
v6 = 10LL;
return do_btree_super_insert(a1, &v4, 0LL);
}

original_code:
int insert_into_btree(struct stp_btree_info *btree, u64 ino, u64 offset)
{
    struct stp_bnode_off off;
    off.ino = ino;
    off.flags = 0;
    off.offset = offset;
    off.len = 10;
    return do_btree_super_insert(btree, &off, 0);
}

canonical_original_code:
int insert_into_btree(struct stp_btree_info *btree, unsigned long ino, unsigned long offset)
{
    struct stp_bnode_off off;
    off.ino = ino;
    off.flags = 0;
    off.offset = offset;
    off.len = 10;
    return do_btree_super_insert(btree, &off, 0);
}

variable_types:
ino
unsigned long

variable_types:
offset
unsigned long

variable_types: struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; }

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct stp_btree_operations { int (*init)(struct stp_btree_info *); struct stp_bnode *(*allocate)(struct stp_btree_info *, long offset); int (*read)(struct stp_btree_info *, struct stp_bnode *, long offset); int (*sync)(struct stp_btree_info *); int (*write)(struct stp_btree_info *, struct stp_bnode *); int (*search)(struct stp_btree_info *, unsigned long ino, struct stp_bnode_off *); void (*debug)(struct stp_bnode *); void (*debug_btree)(struct stp_btree_info *); int (*insert)(struct stp_btree_info *, struct stp_bnode_off *, unsigned char); int (*rm)(struct stp_btree_info *, unsigned long ino); int (*free)(struct stp_btree_info *, struct stp_bnode *); int (*destroy)(struct stp_btree_info *); }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct stp_header { unsigned long offset; unsigned long count; unsigned char flags; unsigned int nritems; }

user_defined_types: struct list { struct list *next; struct list *prev; }

user_defined_types: struct stp_bnode_operations { int (*init)(struct stp_bnode *node); int (*insert)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*update)(struct stp_bnode *node, unsigned long ino, unsigned long start, long offset); int (*delete)(struct stp_bnode *node, unsigned long ino); struct stp_bnode *(*search)(struct stp_bnode *node, unsigned long ino, struct stp_bnode_off *off); int (*destroy)(struct stp_bnode *node); }

user_defined_types: struct stp_bnode_key { unsigned long ino; unsigned char flags; }


decompiled_code:
__int64 search_in_btree()
{
return do_btree_super_search();
}

canonical_decompiled_code:
__int64 func9()
{
return do_btree_super_search();
}

original_code:
int search_in_btree(struct stp_btree_info *btree, u64 ino, struct stp_bnode_off *off)
{
    return do_btree_super_search(btree, ino, off);
}

canonical_original_code:
int search_in_btree(struct stp_btree_info *btree, unsigned long ino, struct stp_bnode_off *off)
{
    return do_btree_super_search(btree, ino, off);
}

variable_types:
off
struct stp_bnode_off *

user_defined_types: struct stp_bnode_off { unsigned long ino; unsigned char flags; unsigned long len; unsigned long offset; }


decompiled_code:
__int64 delete_from_btree()
{
return do_btree_super_rm();
}

canonical_decompiled_code:
__int64 func10()
{
return do_btree_super_rm();
}

original_code:
int delete_from_btree(struct stp_btree_info *btree, u64 ino)
{
    return do_btree_super_rm(btree, ino);
}

canonical_original_code:
int delete_from_btree(struct stp_btree_info *btree, unsigned long ino)
{
    return do_btree_super_rm(btree, ino);
}


decompiled_code:
void __fastcall stp_btree_close(void *ptr)
{
(*(void (**)(void))(*((_QWORD *)ptr + 22) + 88LL))();
fsync(*((_DWORD *)ptr + 2));
msync(*((void **)ptr + 14), 0x2000uLL, 4);
munmap(*((void **)ptr + 14), 0x2000uLL);
close(*((_DWORD *)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
(*(void (**)(void))(*((_QWORD *)ptr + 22) + 88LL))();
fsync(*((_DWORD *)ptr + 2));
msync(*((void **)ptr + 14), 0x2000uLL, 4);
munmap(*((void **)ptr + 14), 0x2000uLL);
close(*((_DWORD *)ptr + 2));
free(ptr);
}

original_code:
void stp_btree_close(struct stp_btree_info *btree)
{
    btree->ops->destroy(btree);
    fsync(btree->fd);
    msync(btree->super,(1024*8),4);
    munmap(btree->super,(1024*8));
    close(btree->fd);
    free(btree);
}


decompiled_code:
unsigned int __fastcall test_insert(__int64 a1, int a2, int a3)
{
signed int v3; // er13
int v4; // ebx
unsigned int result; // eax
__int64 v6; // r14
int v7; // eax

v3 = a2;
v4 = a2 + a3;
result = begin_timer();
if ( a2 <= v4 )
{
v6 = a2;
while ( (int)insert_into_btree(a1, v6, v6) >= 0 )
{
result = __ROR4__(989560465 * v3 + 3435968, 4);
if ( result > 0x68DB8 )
{
++v3;
++v6;
if ( v3 > v4 )
return result;
}
else
{
++v3;
++v6;
end_timer();
v7 = Diff_timer();
printf("1ms insert %d\n", (unsigned int)(10000 / v7));
result = begin_timer();
if ( v3 > v4 )
return result;
}
}
result = fprintf(stderr, "insert error, %d\n", (unsigned int)v3);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func13(__int64 a1, int a2, int a3)
{
signed int v3; // er13
int v4; // ebx
unsigned int result; // eax
__int64 v6; // r14
int v7; // eax

v3 = a2;
v4 = a2 + a3;
result = func3();
if ( a2 <= v4 )
{
v6 = a2;
while ( (int)func8(a1, v6, v6) >= 0 )
{
result = __ROR4__(989560465 * v3 + 3435968, 4);
if ( result > 0x68DB8 )
{
++v3;
++v6;
if ( v3 > v4 )
return result;
}
else
{
++v3;
++v6;
func4();
v7 = func5();
printf("1ms insert %d\n", (unsigned int)(10000 / v7));
result = func3();
if ( v3 > v4 )
return result;
}
}
result = fprintf(stderr, "insert error, %d\n", (unsigned int)v3);
}
return result;
}

original_code:
void test_insert(struct stp_btree_info *btree, int start, int num)
{
    int rc = 0;
    int i = 0;
    begin_timer();
    for (i = start; i <= start + num; ++i) {
        rc = insert_into_btree(btree, i, i);
        if (rc < 0) {
            fprintf(stderr, "insert error, %d\n", i);
            break;
        }
        if(i % 10000 == 0){
       end_timer();
       printf("1ms insert %d\n", 10000 / Diff_timer());
       begin_timer();
        }
    }
}

variable_types: start int

variable_types: num int

variable_types: rc int

variable_types: i int