repo: meridion/microsynth

decompiled_code:
__int64 __fastcall msynth_parse_args(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax

config = 0;
*(&config + 2) = -1;
*(&config + 3) = 0;
*(&config + 7) = -1;
*(&config + 6) = -1;
*((_QWORD *)&config + 2) = "default";
*(&config + 1) = 0;
while ( 2 )
{
v2 = getopt(argc, argv, "s:rvb:p:d:h");
if ( v2 == -1 )
{
result = (unsigned int)*(&config + 3);
if ( (_DWORD)result )
{
result = 0LL;
if ( *(&config + 2) == -1 )
{
puts("When enabling software resampling, you are required to\nalso specify a samplerate using -s.");
config = 1;
result = 1LL;
}
}
}
else
{
switch ( v2 )
{
case 'b':
*(&config + 6) = atoi(optarg);
continue;
case 'd':
*((_QWORD *)&config + 2) = optarg;
continue;
case 'h':
printf(
"Usage %s:\n"
" -s Set samplerate (usually 48000 or 44100)\n"
" -r Enable software resampling\n"
" -b Set buffer time in microseconds\n"
" This is used to determine the amount of memory\n"
" used to buffer samples to. (e.g. 500000)\n"
" -p Set period time in microseconds.\n"
" The period is the amount of samples written at\n"
" once to the soundcard. Is usually less than half\n"
" the buffer time. (e.g. 250000)\n",
*argv);
puts(
"\n"
" By default the buffer time will be minimized to\n"
" to reduce latency, and the period time will be\n"
" maximized to reduce synthesis overhead.\n"
"\n"
" -d Set ALSA device name (usually default or hw:0,0)\n"
" -h Show this help.");
result = 1LL;
break;
case 'p':
*(&config + 7) = atoi(optarg);
continue;
case 'r':
*(&config + 3) = 1;
continue;
case 's':
*(&config + 2) = atoi(optarg);
continue;
case 'v':
*(&config + 1) = 1;
continue;
default:
config = 1;
result = 1LL;
break;
}
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax

config = 0;
*(&config + 2) = -1;
*(&config + 3) = 0;
*(&config + 7) = -1;
*(&config + 6) = -1;
*((_QWORD *)&config + 2) = "default";
*(&config + 1) = 0;
while ( 2 )
{
v2 = getopt(argc, argv, "s:rvb:p:d:h");
if ( v2 == -1 )
{
result = (unsigned int)*(&config + 3);
if ( (_DWORD)result )
{
result = 0LL;
if ( *(&config + 2) == -1 )
{
puts("When enabling software resampling, you are required to\nalso specify a samplerate using -s.");
config = 1;
result = 1LL;
}
}
}
else
{
switch ( v2 )
{
case 'b':
*(&config + 6) = atoi(optarg);
continue;
case 'd':
*((_QWORD *)&config + 2) = optarg;
continue;
case 'h':
printf(
"Usage %s:\n"
" -s Set samplerate (usually 48000 or 44100)\n"
" -r Enable software resampling\n"
" -b Set buffer time in microseconds\n"
" This is used to determine the amount of memory\n"
" used to buffer samples to. (e.g. 500000)\n"
" -p Set period time in microseconds.\n"
" The period is the amount of samples written at\n"
" once to the soundcard. Is usually less than half\n"
" the buffer time. (e.g. 250000)\n",
*argv);
puts(
"\n"
" By default the buffer time will be minimized to\n"
" to reduce latency, and the period time will be\n"
" maximized to reduce synthesis overhead.\n"
"\n"
" -d Set ALSA device name (usually default or hw:0,0)\n"
" -h Show this help.");
result = 1LL;
break;
case 'p':
*(&config + 7) = atoi(optarg);
continue;
case 'r':
*(&config + 3) = 1;
continue;
case 's':
*(&config + 2) = atoi(optarg);
continue;
case 'v':
*(&config + 1) = 1;
continue;
default:
config = 1;
result = 1LL;
break;
}
}
break;
}
return result;
}

original_code:
static int msynth_parse_args(int argc, char *argv[])
{
    int arg;
    config.exit_code = 0;
    config.srate = -1;
    config.resample = 0;
    config.buffer_time = config.period_time = -1;
    config.device_name = "default";
    config.verbose = 0;
    while ((arg = getopt(argc, argv, "s:rvb:p:d:h")) != -1) {
        switch (arg) {
            case 's':
                config.srate = atoi(optarg);
                break;
            case 'r':
                config.resample = 1;
                break;
            case 'v':
                config.verbose = 1;
                break;
            case 'b':
                config.buffer_time = atoi(optarg);
                break;
            case 'p':
                config.period_time = atoi(optarg);
                break;
            case 'd':
                config.device_name = optarg;
                break;
            case 'h':
                printf("Usage %s:\n"
                    "    -s Set samplerate (usually 48000 or 44100)\n"
                    "    -r Enable software resampling\n"
                    "    -b Set buffer time in microseconds\n"
                    "       This is used to determine the amount of memory\n"
                    "       used to buffer samples to. (e.g. 500000)\n"
                    "    -p Set period time in microseconds.\n"
                    "       The period is the amount of samples written at\n"
                    "       once to the soundcard. Is usually less than"
                    " half\n"
                    "       the buffer time. (e.g. 250000)\n", argv[0]);
                printf(
                    "\n"
                    "    By default the buffer time will be minimized to\n"
                    "    to reduce latency, and the period time will be\n"
                    "    maximized to reduce synthesis overhead.\n"
                    "\n"
                    "    -d Set ALSA device name (usually default or hw:0,0)\n"
                    "    -h Show this help.\n");
                return 1;
            case '?':
            default:
                config.exit_code = 1;
                return 1;
        }
    }
    if (config.resample && config.srate == -1) {
        printf("When enabling software resampling, you are required to\n"
            "also specify a samplerate using -s.\n");
        config.exit_code = 1;
        return 1;
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: arg int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rbx
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi

srandom(0x1329455u);
if ( (unsigned int)msynth_parse_args(argc, (char **)argv) )
return config;
soundscript_init();
msynth_init();
puts("microsynth v0.1.1.1");
v4 = (char *)readline("msynth> ");
v5 = 0;
v6 = v4 == 0LL;
if ( v4 )
{
while ( 1 )
{
v7 = "quit";
v8 = 5LL;
v9 = v4;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
break;
add_history(v4, v9);
soundscript_parse(v4);
free(v4);
v4 = (char *)readline("msynth> ");
v5 = 0;
v6 = v4 == 0LL;
if ( !v4 )
goto LABEL_9;
}
free(v4);
}
else
{
LABEL_9:
puts(&byte_296);
}
msynth_shutdown();
soundscript_shutdown();
return config;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rbx
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
const char *v9; // rsi

srandom(0x1329455u);
if ( (unsigned int)func0(argc, (char **)argv) )
return config;
soundscript_init();
msynth_init();
puts("microsynth v0.1.1.1");
v4 = (char *)readline("msynth> ");
v5 = 0;
v6 = v4 == 0LL;
if ( v4 )
{
while ( 1 )
{
v7 = "quit";
v8 = 5LL;
v9 = v4;
do
{
if ( !v8 )
break;
v5 = *v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
break;
add_history(v4, v9);
soundscript_parse(v4);
free(v4);
v4 = (char *)readline("msynth> ");
v5 = 0;
v6 = v4 == 0LL;
if ( !v4 )
goto LABEL_9;
}
free(v4);
}
else
{
LABEL_9:
puts(&byte_296);
}
msynth_shutdown();
soundscript_shutdown();
return config;
}

original_code:
int main(int argc, char *argv[])
{
    char *line;
    srandom(20091989);
    if (msynth_parse_args(argc, argv))
        return config.exit_code;
    soundscript_init();
    msynth_init();
    puts("microsynth " "v0.1.1.1");
    line = readline("msynth> ");
    while (line) {
        if (!strcmp(line, "quit"))
            break;
        add_history(line);
        soundscript_parse(line);
        free(line);
        line = readline("msynth> ");
    }
    if (line)
        free(line);
    else
        puts("");
    msynth_shutdown();
    soundscript_shutdown();
    return config.exit_code;
}

variable_types:
line
char *

return_type: int


decompiled_code:
void __fastcall osc_advance(float *a1, float a2, float a3)
{
*a1 = fmodf((float)((float)(a2 - a1[1]) * a3) + *a1, 1.0);
a1[1] = a2;
}

canonical_decompiled_code:
void __fastcall func1(float *a1, float a2, float a3)
{
*a1 = fmodf((float)((float)(a2 - a1[1]) * a3) + *a1, 1.0);
a1[1] = a2;
}

original_code:
void osc_advance(osc_local osc, struct sampleclock sc, float hertz)
{
    osc->cycle = fmodf(osc->cycle + (sc.seconds - osc->prev_seconds) * hertz,
        1.0f);
    osc->prev_seconds = sc.seconds;
    return;
}

canonical_original_code:
void osc_advance(struct _osc_local *osc, struct sampleclock sc, float hertz)
{
    osc->cycle = fmodf(osc->cycle + (sc.seconds - osc->prev_seconds) * hertz,
        1.0f);
    osc->prev_seconds = sc.seconds;
    return;
}

variable_types:
osc
struct _osc_local { float cycle; } *

variable_types: struct sampleclock { int samplerate; int samples; float seconds; float cycle; }

variable_types: hertz float

return_type: void


decompiled_code:
float __fastcall gen_sin(float a1, float a2, __int64 a3, float **a4)
{
float *v4; // r12

gen_setup_storage(a4, a1);
v4 = *a4;
osc_advance(*a4, a1, a2);
return sin(*v4 * 6.283185307179586);
}

original_code:
float gen_sin(struct sampleclock sc, void **storage, float hertz)
{
    osc_local osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return sin(3.14159265358979323846 * 2.0f * osc->cycle);
}

canonical_original_code:
float gen_sin(struct sampleclock sc, void **storage, float hertz)
{
    struct _osc_local *osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return sin(3.14159265358979323846 * 2.0f * osc->cycle);
}

variable_types:
storage
void **

return_type: float

user_defined_types: struct sampleclock { int samplerate; int samples; float seconds; float cycle; }


decompiled_code:
float __fastcall gen_cos(float a1, float a2, __int64 a3, float **a4)
{
float *v4; // r12

gen_setup_storage(a4, a1);
v4 = *a4;
osc_advance(*a4, a1, a2);
return cos(*v4 * 6.283185307179586);
}

original_code:
float gen_cos(struct sampleclock sc, void **storage, float hertz)
{
    osc_local osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return cos(3.14159265358979323846 * 2.0f * osc->cycle);
}

canonical_original_code:
float gen_cos(struct sampleclock sc, void **storage, float hertz)
{
    struct _osc_local *osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return cos(3.14159265358979323846 * 2.0f * osc->cycle);
}


decompiled_code:
float __fastcall gen_saw(float a1, float a2, __int64 a3, float **a4)
{
float *v4; // r12

gen_setup_storage(a4, a1);
v4 = *a4;
osc_advance(*a4, a1, a2);
return (float)(*v4 + *v4) - 1.0;
}

canonical_decompiled_code:
float __fastcall func4(float a1, float a2, __int64 a3, float **a4)
{
float *v4; // r12

func0(a4, a1);
v4 = *a4;
func1(*a4, a1, a2);
return (float)(*v4 + *v4) - 1.0;
}

original_code:
float gen_saw(struct sampleclock sc, void **storage, float hertz)
{
    osc_local osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return 2.0f * osc->cycle - 1.0f;
}

canonical_original_code:
float gen_saw(struct sampleclock sc, void **storage, float hertz)
{
    struct _osc_local *osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return 2.0f * osc->cycle - 1.0f;
}


original_code:
float gen_rsaw(struct sampleclock sc, void **storage, float hertz)
{
    osc_local osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return -gen_saw(sc, storage, hertz);
}

canonical_original_code:
float gen_rsaw(struct sampleclock sc, void **storage, float hertz)
{
    struct _osc_local *osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return -gen_saw(sc, storage, hertz);
}


decompiled_code:
double __fastcall gen_pulse(__int64 a1, float **a2, float a3, float a4)
{
double result; // xmm0_8
float y; // [rsp+8h] [rbp-30h]
float v6; // [rsp+Ch] [rbp-2Ch]

y = (float)(int)a1 / a4;
gen_setup_storage(a2, a3);
osc_advance(*a2, a3, a4);
v6 = fmodf((float)SHIDWORD(a1), y);
if ( fmodf((float)(HIDWORD(a1) + 1), y) > v6 )
return 0.0;
*(_QWORD *)&result = LODWORD(LC2);
return result;
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1, float **a2, float a3, float a4)
{
double result; // xmm0_8
float y; // [rsp+8h] [rbp-30h]
float v6; // [rsp+Ch] [rbp-2Ch]

y = (float)(int)a1 / a4;
func0(a2, a3);
func1(*a2, a3, a4);
v6 = fmodf((float)SHIDWORD(a1), y);
if ( fmodf((float)(HIDWORD(a1) + 1), y) > v6 )
return 0.0;
*(_QWORD *)&result = LODWORD(LC2);
return result;
}

original_code:
float gen_pulse(struct sampleclock sc, void **storage, float hertz)
{
    float speriod = (float)sc.samplerate / hertz;
    osc_local osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return (fmodf((float)sc.samples, speriod) <
        fmodf((float)(sc.samples + 1), speriod)) ?
        0.0f : 1.0f;
}

canonical_original_code:
float gen_pulse(struct sampleclock sc, void **storage, float hertz)
{
    float speriod = (float)sc.samplerate / hertz;
    struct _osc_local *osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return (fmodf((float)sc.samples, speriod) <
        fmodf((float)(sc.samples + 1), speriod)) ?
        0.0f : 1.0f;
}

variable_types: speriod float


decompiled_code:
float __fastcall gen_square(float a1, float a2, __int64 a3, float **a4)
{
float *v4; // r12
float result; // xmm0_4

gen_setup_storage(a4, a1);
v4 = *a4;
osc_advance(*a4, a1, a2);
if ( *v4 < 0.5 )
result = LC2;
else
result = *(float *)&LC7;
return result;
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2, __int64 a3, float **a4)
{
float *v4; // r12
float result; // xmm0_4

func0(a4, a1);
v4 = *a4;
func1(*a4, a1, a2);
if ( *v4 < 0.5 )
result = LC2;
else
result = *(float *)&LC7;
return result;
}

original_code:
float gen_square(struct sampleclock sc, void **storage, float hertz)
{
    osc_local osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return osc->cycle < 0.5f ? 1.0f : -1.0f;
}

canonical_original_code:
float gen_square(struct sampleclock sc, void **storage, float hertz)
{
    struct _osc_local *osc; _gen_setup_storage(storage, sc); osc = *storage; osc_advance(osc, sc, hertz);
    return osc->cycle < 0.5f ? 1.0f : -1.0f;
}


decompiled_code:
float gen_whitenoise()
{
int v0; // eax

v0 = random();
return (double)v0 / 2147483647.0 + (double)v0 / 2147483647.0 - 1.0;
}

original_code:
float gen_whitenoise(struct sampleclock sc, void **storage)
{
    return (float)((double)random() / (double)2147483647 * 2.0 - 1.0);
}


original_code:
float tf_mul(struct sampleclock sc, void ** storage, float a, float b)
{
    return a * b;
}

canonical_original_code:
float tf_mul(struct sampleclock sc, void **storage, float a, float b)
{
    return a * b;
}

variable_types: a float

variable_types: b float


original_code:
float tf_add(struct sampleclock sc, void **storage, float a, float b)
{
    return a + b;
}


decompiled_code:
__m64 __fastcall tf_div(double a1, double a2, float a3)
{
__m64 result; // xmm0_8

if ( a3 == 0.0 )
return 0LL;
*((_DWORD *)&result + 1) = HIDWORD(a2);
*(float *)&result.m64_u64 = *(float *)&a2 / a3;
return result;
}

canonical_decompiled_code:
__m64 __fastcall func2(double a1, double a2, float a3)
{
__m64 result; // xmm0_8

if ( a3 == 0.0 )
return 0LL;
*((_DWORD *)&result + 1) = HIDWORD(a2);
*(float *)&result.m64_u64 = *(float *)&a2 / a3;
return result;
}

original_code:
float tf_div(struct sampleclock sc, void **storage, float a, float b)
{
    if (b == 0.0f)
        return 0.0f;
    return a / b;
}


original_code:
float tf_sub(struct sampleclock sc, void **storage, float a, float b)
{
    return a - b;
}


decompiled_code:
float __fastcall tf_chipify(double a1, float a2)
{
float v2; // xmm1_4
float v3; // xmm0_4

v2 = a2 * 128.0;
v3 = *(float *)&LC1;
if ( v2 <= 127.0 )
{
v3 = v2;
if ( v2 < -128.0 )
v3 = LC2;
}
return roundf(v3) * 0.0078125;
}

original_code:
float tf_chipify(struct sampleclock sc, void **storage, float in)
{
    in *= 128.0f;
    if (in > 127.0f)
        in = 127.0f;
    if (in < -128.0f)
        in = -128.0f;
    in = roundf(in);
    in /= 128.0f;
    return in;
}

variable_types: in float


original_code:
float tf_delay(struct sampleclock sc, void **storage, float in)
{
    tf_delay_info di = (tf_delay_info)*storage;
    float
        *history = (float*)(di + 1),
        r;
    if (di->delay) {
        r = history[di->pos];
        history[di->pos] = in;
        di->pos = (di->pos + 1) % di->delay;
    } else {
        r = in;
    }
    return r;
}

canonical_original_code:
float tf_delay(struct sampleclock sc, void **storage, float in)
{
    struct _tf_delay_info *di = (tf_delay_info)*storage;
    float *history = (float*)(di + 1); float r;
    if (di->delay) {
        r = history[di->pos];
        history[di->pos] = in;
        di->pos = (di->pos + 1) % di->delay;
    } else {
        r = in;
    }
    return r;
}

variable_types:
di
struct _tf_delay_info { int delay; } *

variable_types:
history
float *

variable_types: r float


decompiled_code:
float __fastcall tf_min(double a1, float a2, float a3)
{
return fminf(a2, a3);
}

canonical_decompiled_code:
float __fastcall func6(double a1, float a2, float a3)
{
return fminf(a2, a3);
}

original_code:
float tf_min(struct sampleclock sc, void **storage, float a, float b)
{
    return fminf(a, b);
}


decompiled_code:
float __fastcall tf_max(double a1, float a2, float a3)
{
return fmaxf(a2, a3);
}

canonical_decompiled_code:
float __fastcall func7(double a1, float a2, float a3)
{
return fmaxf(a2, a3);
}

original_code:
float tf_max(struct sampleclock sc, void **storage, float a, float b)
{
    return fmaxf(a, b);
}


decompiled_code:
__m128 __fastcall tf_abs(double a1, __m128 a2)
{
return _mm_and_ps(a2, (__m128)LC5);
}

canonical_decompiled_code:
__m128 __fastcall func8(double a1, __m128 a2)
{
return _mm_and_ps(a2, (__m128)LC5);
}

original_code:
float tf_abs(struct sampleclock sc, void **storage, float in)
{
    return fabsf(in);
}


original_code:
float tf_clamp(struct sampleclock sc, void **storage, float a, float b)
{
    if (fabs(a) > fabs(b))
        return b;
    else
        return a;
}


original_code:
float tf_floor(struct sampleclock sc, void **storage, float in)
{
    return floorf(in);
}


original_code:
float tf_ceil(struct sampleclock sc, void **storage, float in)
{
    return ceilf(in);
}


decompiled_code:
double __fastcall sc_from_samples(int a1, int a2)
{
__m128i v2; // xmm2
double result; // xmm0_8
unsigned int v4; // [rsp+Ch] [rbp-1Ch]

*(float *)&v4 = (float)a2 / (float)a1;
v2 = 0LL;
*(float *)v2.m128i_i32 = fmod(*(float *)&v4, 1.0);
*(_QWORD *)&result = (unsigned int)_mm_cvtsi128_si32((__m128i)v4) | ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v2) << 32);
return result;
}

canonical_decompiled_code:
double __fastcall func0(int a1, int a2)
{
__m128i v2; // xmm2
double result; // xmm0_8
unsigned int v4; // [rsp+Ch] [rbp-1Ch]

*(float *)&v4 = (float)a2 / (float)a1;
v2 = 0LL;
*(float *)v2.m128i_i32 = fmod(*(float *)&v4, 1.0);
*(_QWORD *)&result = (unsigned int)_mm_cvtsi128_si32((__m128i)v4) | ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v2) << 32);
return result;
}

original_code:
struct sampleclock sc_from_samples(int samplerate, int samples)
{
    struct sampleclock sc;
    sc.samplerate = samplerate;
    sc.samples = samples;
    sc.seconds = (float)sc.samples / (float)sc.samplerate;
    sc.cycle = fmod(sc.seconds, 1.0f);
    return sc;
}

variable_types: samplerate int

variable_types: samples int

return_type: struct sampleclock { int samplerate; int samples; float seconds; float cycle; }


decompiled_code:
double __fastcall sc_rewind(__int64 a1, int a2)
{
return sc_from_samples(a1, HIDWORD(a1) - a2);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, int a2)
{
return func0(a1, HIDWORD(a1) - a2);
}

original_code:
struct sampleclock sc_rewind(struct sampleclock sc, int samples)
{
    return sc_from_samples(sc.samplerate, sc.samples - samples);
}

variable_types:
sc
struct sampleclock


decompiled_code:
int put_recursion_error()
{
yyerror("error: All recursive variables must be referenced with a delay");
return yyerror(" of at least 1 sample, to break infinite feedback.");
}

canonical_decompiled_code:
int func1()
{
func0("error: All recursive variables must be referenced with a delay");
return func0(" of at least 1 sample, to break infinite feedback.");
}

original_code:
static void put_recursion_error() {
    yyerror("error: All recursive variables must be referenced with a delay");
    yyerror("       of at least 1 sample, to break infinite feedback.");
}


yyparse

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 2)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-20))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 38 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 5:
    {
            ssv_set_dummy((yyvsp[-1].name));
        }
    break;
  case 6:
    {
            if (ssv_validate_recursion((yyvsp[0].mod), ((void *)0))) {
                put_recursion_error();
                goto yyerrorlab;
            }
            if (ssv_speculate_cycle((yyvsp[-3].name), (yyvsp[0].mod))) {
                yyerror("Assignment would cause cycle in soundgraph,"
                    " use recursive variables instead");
                goto yyerrorlab;
            }
            soundscript_mark_use((yyvsp[0].mod));
            ssv_set_var((yyvsp[-3].name), (yyvsp[0].mod));
        }
    break;
  case 7:
    {
            ssv_set_dummy((yyvsp[-1].name));
        }
    break;
  case 8:
    {
            if (ssv_validate_recursion((yyvsp[0].mod), (yyvsp[-3].name))) {
                put_recursion_error();
                goto yyerrorlab;
            }
            soundscript_mark_use((yyvsp[0].mod));
            ssv_set_var_recursive((yyvsp[-3].name), (yyvsp[0].mod));
        }
    break;
  case 9:
    {
            if (ssv_validate_recursion((yyvsp[-1].mod), ((void *)0))) {
                put_recursion_error();
                goto yyerrorlab;
            }
            soundscript_mark_use((yyvsp[-1].mod));
            synth_replace((yyvsp[-1].mod));
        }
    break;
  case 10:
    {
            printf("Current volume: %.1f%%\n", synth_get_volume());
        }
    break;
  case 11:
    {
            if (0.f <= (yyvsp[-1].number) && (yyvsp[-1].number) <= 100.f)
                synth_set_volume((yyvsp[-1].number));
            else
                puts("Volume must be percentage from 0% to 100%");
        }
    break;
  case 13:
    { (yyval.mod) = ssb_add((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 14:
    { (yyval.mod) = ssb_sub((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 16:
    { (yyval.mod) = ssb_mul((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 17:
    { (yyval.mod) = ssb_div((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 18:
    {
            switch ((yyvsp[-1].args).argc) {
                case 0:
                    if (!ssb_can_func0((yyvsp[-3].name))) {
                        fprintf(stderr, "No such function: '%s'\n", (yyvsp[-3].name));
                        goto yyerrorlab;
                    }
                    (yyval.mod) = ssb_func0((yyvsp[-3].name));
                    break;
                case 1:
                    if (!ssb_can_func1((yyvsp[-3].name))) {
                        fprintf(stderr, "No such function: '%s'\n", (yyvsp[-3].name));
                        goto yyerrorlab;
                    }
                    (yyval.mod) = ssb_func1((yyvsp[-3].name), (yyvsp[-1].args).argv[0]);
                    break;
                case 2:
                    if (!ssb_can_func2((yyvsp[-3].name))) {
                        fprintf(stderr, "No such function: '%s'\n", (yyvsp[-3].name));
                        goto yyerrorlab;
                    }
                    (yyval.mod) = ssb_func2((yyvsp[-3].name), (yyvsp[-1].args).argv[0], (yyvsp[-1].args).argv[1]);
                    break;
                default:
                    fprintf(stderr,
                        "More than 3 arguments are not supported\n");
                    goto yyerrorlab;
            }
        }
    break;
  case 19:
    { (yyval.mod) = (yyvsp[-1].mod); }
    break;
  case 20:
    { (yyval.mod) = (yyvsp[0].mod); }
    break;
  case 21:
    {
            if (!ssv_get_var((yyvsp[0].name))) {
                fprintf(stderr, "No such variable: '%s'\n", (yyvsp[0].name));
                goto yyerrorlab;
            }
            (yyval.mod) = ssb_variable((yyvsp[0].name));
        }
    break;
  case 22:
    {
            if ((yyvsp[-3].mod)->type == 1 &&
                    ssv_get_var((yyvsp[-3].mod)->data.varname)->recursive) {
                if (roundf((yyvsp[-1].number)) == 0) {
                    fprintf(stderr, "Referencing recursive variable '%s'"
                        " with a delay of 0 samples, invalid.\n",
                        (yyvsp[-3].mod)->data.varname);
                    goto yyerrorlab;
                } else {
                    (yyval.mod) = ssb_delay((yyvsp[-3].mod), (unsigned int)roundf((yyvsp[-1].number)) - 1);
                }
            } else {
                (yyval.mod) = ssb_delay((yyvsp[-3].mod), (unsigned int)roundf((yyvsp[-1].number)));
            }
        }
    break;
  case 23:
    {
            (yyval.args).argc = 0;
        }
    break;
  case 24:
    {
            (yyval.args) = (yyvsp[0].args);
        }
    break;
  case 25:
    {
            (yyval.args).argc = 1;
            (yyval.args).argv[0] = (yyvsp[0].mod);
        }
    break;
  case 26:
    {
            (yyval.args) = (yyvsp[-2].args);
            if ((yyval.args).argc == 2) {
                fprintf(stderr,
                    "More than 3 arguments are not supported\n");
                goto yyerrorlab;
            }
            (yyval.args).argv[(yyval.args).argc++] = (yyvsp[0].mod);
        }
    break;
  case 27:
    { (yyval.mod) = ssb_number(-(yyvsp[0].number)); }
    break;
  case 28:
    { (yyval.mod) = ssb_number((yyvsp[0].number)); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 19;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 38 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-20))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 38 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 2)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-20))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 38 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 5:
    {
            ssv_set_dummy((yyvsp[-1].name));
        }
    break;
  case 6:
    {
            if (ssv_validate_recursion((yyvsp[0].mod), ((void *)0))) {
                put_recursion_error();
                goto yyerrorlab;
            }
            if (ssv_speculate_cycle((yyvsp[-3].name), (yyvsp[0].mod))) {
                yyerror("Assignment would cause cycle in soundgraph,"
                    " use recursive variables instead");
                goto yyerrorlab;
            }
            soundscript_mark_use((yyvsp[0].mod));
            ssv_set_var((yyvsp[-3].name), (yyvsp[0].mod));
        }
    break;
  case 7:
    {
            ssv_set_dummy((yyvsp[-1].name));
        }
    break;
  case 8:
    {
            if (ssv_validate_recursion((yyvsp[0].mod), (yyvsp[-3].name))) {
                put_recursion_error();
                goto yyerrorlab;
            }
            soundscript_mark_use((yyvsp[0].mod));
            ssv_set_var_recursive((yyvsp[-3].name), (yyvsp[0].mod));
        }
    break;
  case 9:
    {
            if (ssv_validate_recursion((yyvsp[-1].mod), ((void *)0))) {
                put_recursion_error();
                goto yyerrorlab;
            }
            soundscript_mark_use((yyvsp[-1].mod));
            synth_replace((yyvsp[-1].mod));
        }
    break;
  case 10:
    {
            printf("Current volume: %.1f%%\n", synth_get_volume());
        }
    break;
  case 11:
    {
            if (0.f <= (yyvsp[-1].number) && (yyvsp[-1].number) <= 100.f)
                synth_set_volume((yyvsp[-1].number));
            else
                puts("Volume must be percentage from 0% to 100%");
        }
    break;
  case 13:
    { (yyval.mod) = ssb_add((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 14:
    { (yyval.mod) = ssb_sub((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 16:
    { (yyval.mod) = ssb_mul((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 17:
    { (yyval.mod) = ssb_div((yyvsp[-2].mod), (yyvsp[0].mod)); }
    break;
  case 18:
    {
            switch ((yyvsp[-1].args).argc) {
                case 0:
                    if (!ssb_can_func0((yyvsp[-3].name))) {
                        fprintf(stderr, "No such function: '%s'\n", (yyvsp[-3].name));
                        goto yyerrorlab;
                    }
                    (yyval.mod) = ssb_func0((yyvsp[-3].name));
                    break;
                case 1:
                    if (!ssb_can_func1((yyvsp[-3].name))) {
                        fprintf(stderr, "No such function: '%s'\n", (yyvsp[-3].name));
                        goto yyerrorlab;
                    }
                    (yyval.mod) = ssb_func1((yyvsp[-3].name), (yyvsp[-1].args).argv[0]);
                    break;
                case 2:
                    if (!ssb_can_func2((yyvsp[-3].name))) {
                        fprintf(stderr, "No such function: '%s'\n", (yyvsp[-3].name));
                        goto yyerrorlab;
                    }
                    (yyval.mod) = ssb_func2((yyvsp[-3].name), (yyvsp[-1].args).argv[0], (yyvsp[-1].args).argv[1]);
                    break;
                default:
                    fprintf(stderr,
                        "More than 3 arguments are not supported\n");
                    goto yyerrorlab;
            }
        }
    break;
  case 19:
    { (yyval.mod) = (yyvsp[-1].mod); }
    break;
  case 20:
    { (yyval.mod) = (yyvsp[0].mod); }
    break;
  case 21:
    {
            if (!ssv_get_var((yyvsp[0].name))) {
                fprintf(stderr, "No such variable: '%s'\n", (yyvsp[0].name));
                goto yyerrorlab;
            }
            (yyval.mod) = ssb_variable((yyvsp[0].name));
        }
    break;
  case 22:
    {
            if ((yyvsp[-3].mod)->type == 1 &&
                    ssv_get_var((yyvsp[-3].mod)->data.varname)->recursive) {
                if (roundf((yyvsp[-1].number)) == 0) {
                    fprintf(stderr, "Referencing recursive variable '%s'"
                        " with a delay of 0 samples, invalid.\n",
                        (yyvsp[-3].mod)->data.varname);
                    goto yyerrorlab;
                } else {
                    (yyval.mod) = ssb_delay((yyvsp[-3].mod), (unsigned int)roundf((yyvsp[-1].number)) - 1);
                }
            } else {
                (yyval.mod) = ssb_delay((yyvsp[-3].mod), (unsigned int)roundf((yyvsp[-1].number)));
            }
        }
    break;
  case 23:
    {
            (yyval.args).argc = 0;
        }
    break;
  case 24:
    {
            (yyval.args) = (yyvsp[0].args);
        }
    break;
  case 25:
    {
            (yyval.args).argc = 1;
            (yyval.args).argv[0] = (yyvsp[0].mod);
        }
    break;
  case 26:
    {
            (yyval.args) = (yyvsp[-2].args);
            if ((yyval.args).argc == 2) {
                fprintf(stderr,
                    "More than 3 arguments are not supported\n");
                goto yyerrorlab;
            }
            (yyval.args).argv[(yyval.args).argc++] = (yyvsp[0].mod);
        }
    break;
  case 27:
    { (yyval.mod) = ssb_number(-(yyvsp[0].number)); }
    break;
  case 28:
    { (yyval.mod) = ssb_number((yyvsp[0].number)); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 19;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 38 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-20))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 38 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { float number; char *name; struct _msynth_modifier { int type; void *storage; union _msynth_modifier_data { struct _mod_node { struct _msynth_modifier *in; float (*func)(struct sampleclock { int samplerate; int samples; float seconds; float cycle; } sc, void **storage, float in); } node; struct _mod_node2 { struct _msynth_modifier *a; float (*func)(struct sampleclock sc, void **storage, float a, float b); } node2; struct _mod_node0 { float (*func)(struct sampleclock sc, void **storage); } node0; float constant; char *varname; } data; } *mod; struct arg_list { struct _msynth_modifier *argv[2]; int argc; } args; } [200]

variable_types: union YYSTYPE { float number; char *name; struct _msynth_modifier { int type; void *storage; union _msynth_modifier_data { struct _mod_node { struct _msynth_modifier *in; float (*func)(struct sampleclock { int samplerate; int samples; float seconds; float cycle; } sc, void **storage, float in); } node; struct _mod_node2 { struct _msynth_modifier *a; float (*func)(struct sampleclock sc, void **storage, float a, float b); } node2; struct _mod_node0 { float (*func)(struct sampleclock sc, void **storage); } node0; float constant; char *varname; } data; } *mod; struct arg_list { struct _msynth_modifier *argv[2]; int argc; } args; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { float number; char *name; struct _msynth_modifier { int type; void *storage; union _msynth_modifier_data { struct _mod_node { struct _msynth_modifier *in; float (*func)(struct sampleclock { int samplerate; int samples; float seconds; float cycle; } sc, void **storage, float in); } node; struct _mod_node2 { struct _msynth_modifier *a; float (*func)(struct sampleclock sc, void **storage, float a, float b); } node2; struct _mod_node0 { float (*func)(struct sampleclock sc, void **storage); } node0; float constant; char *varname; } data; } *mod; struct arg_list { struct _msynth_modifier *argv[2]; int argc; } args; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union YYSTYPE { float number; char *name; struct _msynth_modifier *mod; struct arg_list args; }

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }

user_defined_types: struct _msynth_modifier { int type; void *storage; union _msynth_modifier_data data; }

user_defined_types: union _msynth_modifier_data { struct _mod_node node; struct _mod_node2 node2; struct _mod_node0 node0; float constant; char *varname; }

user_defined_types: struct _mod_node { struct _msynth_modifier *in; float (*func)(struct sampleclock sc, void **storage, float in); }


repo: merimus/Programmers-Dojo

original_code:
int test_prime(prime_list_t *prime_list, uint64_t num)
{
  prime_elem_t *elem = prime_list->head;
  uint64_t s = sqrt(num);
  while( elem->prime <= s )
    {
      if( num % elem->prime == 0 )
 {
   return 0;
 }
      elem = elem->next;
    }
  return 1;
}

canonical_original_code:
int test_prime(struct prime_list_t *prime_list, unsigned long num)
{
  struct prime_elem_s *elem = prime_list->head;
  unsigned long s = sqrt(num);
  while( elem->prime <= s )
    {
      if( num % elem->prime == 0 )
 {
   return 0;
 }
      elem = elem->next;
    }
  return 1;
}

variable_types: struct prime_list_t { unsigned long length; struct prime_elem_s { unsigned long prime; struct prime_elem_s *next; } *head; struct prime_elem_s *tail; } *

variable_types:
num
unsigned long

variable_types:
s
unsigned long

user_defined_types: struct prime_list_t { unsigned long length; struct prime_elem_s *head; struct prime_elem_s *tail; }


repo: messa/oi-sr-arq

decompiled_code:
__int64 __fastcall udp_server_socket(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *v3; // rbx
const char *v4; // rax
int v5; // eax
unsigned int v6; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v4 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v4);
exit(1);
}
v3 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
fwrite("Failed\n", 1uLL, 7uLL, stderr);
exit(1);
}
while ( 1 )
{
v5 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v6 = v5;
if ( v5 == -1 )
goto LABEL_6;
if ( !bind(v5, v3->ai_addr, v3->ai_addrlen) )
break;
close(v6);
LABEL_6:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_3;
}
freeaddrinfo(pai);
return v6;
}

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

*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v4 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v4);
exit(1);
}
v3 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
fwrite("Failed\n", 1uLL, 7uLL, stderr);
exit(1);
}
while ( 1 )
{
v5 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v6 = v5;
if ( v5 == -1 )
goto LABEL_6;
if ( !bind(v5, v3->ai_addr, v3->ai_addrlen) )
break;
close(v6);
LABEL_6:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_3;
}
freeaddrinfo(pai);
return v6;
}

original_code:
int udp_server_socket(const char *host, const char *port) {
    struct addrinfo hints;
    struct addrinfo *result, *r;
    int e;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = 0x0001;
    hints.ai_protocol = 0;
    hints.ai_canonname = ((void *)0);
    hints.ai_addr = ((void *)0);
    hints.ai_next = ((void *)0);
    e = getaddrinfo(host, port, &hints, &result);
    if (e != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
        exit(1);
    }
    for (r = result; r != ((void *)0); r = r->ai_next) {
        int s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        if (s == -1) {
            continue;
        }
        if (bind(s, r->ai_addr, r->ai_addrlen) != 0) {
            close(s);
            continue;
        }
        freeaddrinfo(result);
        return s;
    }
    freeaddrinfo(result);
    fprintf(stderr, "Failed\n");
    exit(1);
}

canonical_original_code:
int udp_server_socket(char *host, char *port) {
    struct addrinfo hints;
    struct addrinfo *result; struct addrinfo *r;
    int e;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = 0x0001;
    hints.ai_protocol = 0;
    hints.ai_canonname = ((void *)0);
    hints.ai_addr = ((void *)0);
    hints.ai_next = ((void *)0);
    e = getaddrinfo(host, port, &hints, &result);
    if (e != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
        exit(1);
    }
    for (r = result; r != ((void *)0); r = r->ai_next) {
        int s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        if (s == -1) {
            continue;
        }
        if (bind(s, r->ai_addr, r->ai_addrlen) != 0) {
            close(s);
            continue;
        }
        freeaddrinfo(result);
        return s;
    }
    freeaddrinfo(result);
    fprintf(stderr, "Failed\n");
    exit(1);
}

variable_types:
host
char *

variable_types:
port
char *

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

variable_types: e int

variable_types: s int

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


decompiled_code:
__int64 __fastcall udp_client_socket(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *v3; // rbx
const char *v4; // rax
int v5; // eax
unsigned int v6; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v4 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v4);
exit(1);
}
v3 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
fwrite("Failed\n", 1uLL, 7uLL, stderr);
exit(1);
}
while ( 1 )
{
v5 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v6 = v5;
if ( v5 == -1 )
goto LABEL_6;
if ( !connect(v5, v3->ai_addr, v3->ai_addrlen) )
break;
close(v6);
LABEL_6:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_3;
}
freeaddrinfo(pai);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *v3; // rbx
const char *v4; // rax
int v5; // eax
unsigned int v6; // ebp
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
v4 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v4);
exit(1);
}
v3 = pai;
if ( !pai )
{
LABEL_3:
freeaddrinfo(pai);
fwrite("Failed\n", 1uLL, 7uLL, stderr);
exit(1);
}
while ( 1 )
{
v5 = socket(v3->ai_family, v3->ai_socktype, v3->ai_protocol);
v6 = v5;
if ( v5 == -1 )
goto LABEL_6;
if ( !connect(v5, v3->ai_addr, v3->ai_addrlen) )
break;
close(v6);
LABEL_6:
v3 = v3->ai_next;
if ( !v3 )
goto LABEL_3;
}
freeaddrinfo(pai);
return v6;
}

original_code:
int udp_client_socket(const char *host, const char *port) {
    struct addrinfo hints;
    struct addrinfo *result, *r;
    int e;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = 0;
    hints.ai_protocol = 0;
    hints.ai_canonname = ((void *)0);
    hints.ai_addr = ((void *)0);
    hints.ai_next = ((void *)0);
    e = getaddrinfo(host, port, &hints, &result);
    if (e != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
        exit(1);
    }
    for (r = result; r != ((void *)0); r = r->ai_next) {
        int s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        if (s == -1) {
            continue;
        }
        if (connect(s, r->ai_addr, r->ai_addrlen) != 0) {
            close(s);
            continue;
        }
        freeaddrinfo(result);
        return s;
    }
    freeaddrinfo(result);
    fprintf(stderr, "Failed\n");
    exit(1);
}

canonical_original_code:
int udp_client_socket(char *host, char *port) {
    struct addrinfo hints;
    struct addrinfo *result; struct addrinfo *r;
    int e;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = 0;
    hints.ai_protocol = 0;
    hints.ai_canonname = ((void *)0);
    hints.ai_addr = ((void *)0);
    hints.ai_next = ((void *)0);
    e = getaddrinfo(host, port, &hints, &result);
    if (e != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
        exit(1);
    }
    for (r = result; r != ((void *)0); r = r->ai_next) {
        int s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        if (s == -1) {
            continue;
        }
        if (connect(s, r->ai_addr, r->ai_addrlen) != 0) {
            close(s);
            continue;
        }
        freeaddrinfo(result);
        return s;
    }
    freeaddrinfo(result);
    fprintf(stderr, "Failed\n");
    exit(1);
}

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


decompiled_code:
char *__fastcall name_from_addr(const struct sockaddr *a1, socklen_t a2)
{
int v2; // eax
char *result; // rax
const char *v4; // rax
char serv[32]; // [rsp+8h] [rbp-438h] BYREF
char host[1048]; // [rsp+28h] [rbp-418h] BYREF

v2 = getnameinfo(a1, a2, host, 0x401u, serv, 0x20u, 3);
if ( v2 )
{
v4 = gai_strerror(v2);
fprintf(stderr, "getnameinfo failed: %s\n", v4);
result = 0LL;
}
else
{
snprintf(buffer_0, 0x423uLL, "%s:%s", host, serv);
result = buffer_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const struct sockaddr *a1, socklen_t a2)
{
int v2; // eax
char *result; // rax
const char *v4; // rax
char serv[32]; // [rsp+8h] [rbp-438h] BYREF
char host[1048]; // [rsp+28h] [rbp-418h] BYREF

v2 = getnameinfo(a1, a2, host, 0x401u, serv, 0x20u, 3);
if ( v2 )
{
v4 = gai_strerror(v2);
fprintf(stderr, "getnameinfo failed: %s\n", v4);
result = 0LL;
}
else
{
snprintf(buffer_0, 0x423uLL, "%s:%s", host, serv);
result = buffer_0;
}
return result;
}

original_code:
const char* name_from_addr(const struct sockaddr *sa, socklen_t saLength) {
    static char buffer[1025 + 1 + 32 + 1];
    char hbuf[1025], sbuf[32];
    int e = getnameinfo(
        sa, saLength,
        hbuf, sizeof(hbuf),
        sbuf, sizeof(sbuf),
        1 | 2);
    if (e != 0) {
        fprintf(stderr, "getnameinfo failed: %s\n", gai_strerror(e));
        return ((void *)0);
    }
    snprintf(buffer, sizeof(buffer), "%s:%s", hbuf, sbuf);
    return buffer;
}

canonical_original_code:
char *name_from_addr(struct sockaddr *sa, unsigned int saLength) {
    static char buffer[-1];
    char hbuf[1025]; char sbuf[32];
    int e = getnameinfo(
        sa, saLength,
        hbuf, sizeof(hbuf),
        sbuf, sizeof(sbuf),
        1 | 2);
    if (e != 0) {
        fprintf(stderr, "getnameinfo failed: %s\n", gai_strerror(e));
        return ((void *)0);
    }
    snprintf(buffer, sizeof(buffer), "%s:%s", hbuf, sbuf);
    return buffer;
}

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

variable_types:
saLength
unsigned int

variable_types:
buffer
char [-1]

variable_types:
hbuf
char [1025]

variable_types:
sbuf
char [32]

return_type: char *


hexdump

original_code:
static char* hexdump(const char *ptr, int size) {
    static char buf[1024];
    int pos = 0;
    int i;
    memset(&buf, 0, sizeof(buf));
    for (i = 0; i < size; i++) {
        int n;
        if (pos > sizeof(buf) - 10) {
            buf[pos++] = '.';
            buf[pos++] = '.';
            buf[pos++] = '.';
            break;
        }
        if (i > 0) {
            buf[pos++] = ' ';
        }
        n = snprintf(buf + pos, sizeof(buf) - pos, "%02x", (unsigned char) ptr[i]);
        pos += n;
    }
    buf[pos] = '\0';
    return buf;
}

canonical_original_code:
static char *hexdump(char *ptr, int size) {
    static char buf[1024];
    int pos = 0;
    int i;
    memset(&buf, 0, sizeof(buf));
    for (i = 0; i < size; i++) {
        int n;
        if (pos > sizeof(buf) - 10) {
            buf[pos++] = '.';
            buf[pos++] = '.';
            buf[pos++] = '.';
            break;
        }
        if (i > 0) {
            buf[pos++] = ' ';
        }
        n = snprintf(buf + pos, sizeof(buf) - pos, "%02x", (unsigned char) ptr[i]);
        pos += n;
    }
    buf[pos] = '\0';
    return buf;
}

variable_types:
ptr
char *

variable_types: size int

variable_types:
buf
char [1024]

variable_types: pos int

variable_types: i int

variable_types: n int


decompiled_code:
void __fastcall __noreturn run_server(int fd, int a2)
{
unsigned int v2; // ebx
const char *v3; // r14
char *v4; // rax
ssize_t v5; // r13
unsigned int v6; // eax
unsigned int v7; // er14
char v8[2]; // [rsp+Ah] [rbp-7FEh] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-7FCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-7F8h] BYREF
char buf[2]; // [rsp+90h] [rbp-778h] BYREF
char v12[206]; // [rsp+92h] [rbp-776h] BYREF
char v13[1704]; // [rsp+160h] [rbp-6A8h] BYREF

init_window(v13);
v2 = 0;
while ( 1 )
{
addr_len = 128;
v5 = recvfrom(fd, buf, 0xCBuLL, 0, &addr, &addr_len);
if ( a2 > 1 )
{
v3 = (const char *)name_from_addr(&addr, addr_len);
v4 = hexdump((__int64)buf, v5);
fprintf(stderr, "Received %s from %s\n", v4, v3);
}
if ( v5 <= 1 )
{
fwrite("Frame is too short\n", 1uLL, 0x13uLL, stderr);
}
else if ( v5 == 203 )
{
fwrite("Frame is too long\n", 1uLL, 0x12uLL, stderr);
}
else
{
v6 = read_seq(buf);
v7 = v6;
if ( v6 == -1 )
{
fwrite("Invalid seq\n", 1uLL, 0xCuLL, stderr);
}
else
{
if ( a2 > 0 )
fprintf(stderr, "Got frame with seq %d\n", v6);
if ( (unsigned int)seq_ge(v7, v2) && (unsigned int)seq_lt(v7, v2 + 8) && !(unsigned int)window_has_seq(v13, v7) )
{
if ( a2 > 0 )
fprintf(stderr, "Saving seq %d to the window\n", v7);
window_store(v13, v7, v12, (unsigned int)(v5 - 2));
}
while ( (unsigned int)window_has_seq(v13, v2) )
{
window_print_message(v13, v2, stdout);
if ( !(unsigned int)window_get_message_length(v13, v2) )
fclose(stdout);
v2 = seq_inc(v2);
}
fflush(stdout);
write_seq(v8, v2);
if ( (int)random_number() <= 89 )
sendto(fd, v8, 2uLL, 0, &addr, addr_len);
}
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int fd, int a2)
{
unsigned int v2; // ebx
const char *v3; // r14
char *v4; // rax
ssize_t v5; // r13
unsigned int v6; // eax
unsigned int v7; // er14
char v8[2]; // [rsp+Ah] [rbp-7FEh] BYREF
socklen_t addr_len; // [rsp+Ch] [rbp-7FCh] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-7F8h] BYREF
char buf[2]; // [rsp+90h] [rbp-778h] BYREF
char v12[206]; // [rsp+92h] [rbp-776h] BYREF
char v13[1704]; // [rsp+160h] [rbp-6A8h] BYREF

init_window(v13);
v2 = 0;
while ( 1 )
{
addr_len = 128;
v5 = recvfrom(fd, buf, 0xCBuLL, 0, &addr, &addr_len);
if ( a2 > 1 )
{
v3 = (const char *)name_from_addr(&addr, addr_len);
v4 = func1((__int64)buf, v5);
fprintf(stderr, "Received %s from %s\n", v4, v3);
}
if ( v5 <= 1 )
{
fwrite("Frame is too short\n", 1uLL, 0x13uLL, stderr);
}
else if ( v5 == 203 )
{
fwrite("Frame is too long\n", 1uLL, 0x12uLL, stderr);
}
else
{
v6 = read_seq(buf);
v7 = v6;
if ( v6 == -1 )
{
fwrite("Invalid seq\n", 1uLL, 0xCuLL, stderr);
}
else
{
if ( a2 > 0 )
fprintf(stderr, "Got frame with seq %d\n", v6);
if ( (unsigned int)seq_ge(v7, v2) && (unsigned int)seq_lt(v7, v2 + 8) && !(unsigned int)window_has_seq(v13, v7) )
{
if ( a2 > 0 )
fprintf(stderr, "Saving seq %d to the window\n", v7);
window_store(v13, v7, v12, (unsigned int)(v5 - 2));
}
while ( (unsigned int)window_has_seq(v13, v2) )
{
window_print_message(v13, v2, stdout);
if ( !(unsigned int)window_get_message_length(v13, v2) )
fclose(stdout);
v2 = seq_inc(v2);
}
fflush(stdout);
write_seq(v8, v2);
if ( (int)random_number() <= 89 )
sendto(fd, v8, 2uLL, 0, &addr, addr_len);
}
}
}
}

original_code:
void run_server(int listenSocket, int verbosity) {
    int waitingForSeq = 0;
    Window window;
    init_window(&window);
    for (;;) {
        char buf[2 + 200 + 1];
        int seq;
        ssize_t n;
        struct sockaddr_storage addr;
        socklen_t addrLen = sizeof(addr);
        n = recvfrom(listenSocket, buf, sizeof(buf), 0, (struct sockaddr*) &addr, &addrLen);
        if (verbosity > 1) {
            fprintf(stderr, "Received %s from %s\n", hexdump(buf, n),
                name_from_addr((struct sockaddr *) &addr, addrLen));
        }
        if (n < 2) {
            fprintf(stderr, "Frame is too short\n");
            continue;
        }
        if (n == sizeof(buf)) {
            fprintf(stderr, "Frame is too long\n");
            continue;
        }
        seq = read_seq(buf);
        if (seq == -1) {
            fprintf(stderr, "Invalid seq\n");
            continue;
        }
        if (verbosity > 0) {
            fprintf(stderr, "Got frame with seq %d\n", seq);
        }
        if (seq_ge(seq, waitingForSeq) &&
            seq_lt(seq, waitingForSeq + 8) ) {
            if (! window_has_seq(&window, seq)) {
                if (verbosity > 0) {
                    fprintf(stderr, "Saving seq %d to the window\n", seq);
                }
                window_store(&window, seq, buf+2, n-2);
            }
        }
        while (window_has_seq(&window, waitingForSeq)) {
            window_print_message(&window, waitingForSeq, stdout);
            if (window_get_message_length(&window, waitingForSeq) == 0) {
                fclose(stdout);
            }
            waitingForSeq = seq_inc(waitingForSeq);
        }
        fflush(stdout);
        {
            char ackBuf[2];
            write_seq(ackBuf, waitingForSeq);
            if (random_number() < 90) {
             n = sendto(listenSocket, ackBuf, sizeof(ackBuf), 0, (struct sockaddr*) &addr, addrLen);
            }
        }
    }
}

canonical_original_code:
void run_server(int listenSocket, int verbosity) {
    int waitingForSeq = 0;
    struct WindowItem window[8];
    init_window(&window);
    for (;;) {
        char buf[-1];
        int seq;
        long n;
        struct sockaddr_storage addr;
        unsigned int addrLen = sizeof(addr);
        n = recvfrom(listenSocket, buf, sizeof(buf), 0, (struct sockaddr *) &addr, &addrLen);
        if (verbosity > 1) {
            fprintf(stderr, "Received %s from %s\n", hexdump(buf, n),
                name_from_addr((struct sockaddr *) &addr, addrLen));
        }
        if (n < 2) {
            fprintf(stderr, "Frame is too short\n");
            continue;
        }
        if (n == sizeof(buf)) {
            fprintf(stderr, "Frame is too long\n");
            continue;
        }
        seq = read_seq(buf);
        if (seq == -1) {
            fprintf(stderr, "Invalid seq\n");
            continue;
        }
        if (verbosity > 0) {
            fprintf(stderr, "Got frame with seq %d\n", seq);
        }
        if (seq_ge(seq, waitingForSeq) &&
            seq_lt(seq, waitingForSeq + 8) ) {
            if (! window_has_seq(&window, seq)) {
                if (verbosity > 0) {
                    fprintf(stderr, "Saving seq %d to the window\n", seq);
                }
                window_store(&window, seq, buf+2, n-2);
            }
        }
        while (window_has_seq(&window, waitingForSeq)) {
            window_print_message(&window, waitingForSeq, stdout);
            if (window_get_message_length(&window, waitingForSeq) == 0) {
                fclose(stdout);
            }
            waitingForSeq = seq_inc(waitingForSeq);
        }
        fflush(stdout);
        {
            char ackBuf[2];
            write_seq(ackBuf, waitingForSeq);
            if (random_number() < 90) {
             n = sendto(listenSocket, ackBuf, sizeof(ackBuf), 0, (struct sockaddr *) &addr, addrLen);
            }
        }
    }
}

variable_types: listenSocket int

variable_types: verbosity int

variable_types: waitingForSeq int

variable_types: struct WindowItem { int seq; int length; char message[200]; } [8]

variable_types:
buf
char [-1]

variable_types: seq int

variable_types: n long

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
addrLen
unsigned int

variable_types:
ackBuf
char [2]

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


decompiled_code:
int __fastcall print_help(const char *a1)
{
print_usage(a1, stdout);
putchar(10);
puts("Options:");
puts(" -h Show this help");
puts(" -b <address> Bind to a specific address");
return puts(" -v Be more verbose; can be used multiple times");
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
func0(a1, stdout);
putchar(10);
puts("Options:");
puts(" -h Show this help");
puts(" -b <address> Bind to a specific address");
return puts(" -v Be more verbose; can be used multiple times");
}

original_code:
static void print_help(const char *programName) {
    print_usage(programName, stdout);
    printf("\n");
    printf("Options:\n");
    printf("  -h            Show this help\n");
    printf("  -b <address>  Bind to a specific address\n");
    printf("  -v            Be more verbose; can be used multiple times\n");
}

canonical_original_code:
static void print_help(char *programName) {
    print_usage(programName, stdout);
    printf("\n");
    printf("Options:\n");
    printf("  -h            Show this help\n");
    printf("  -b <address>  Bind to a specific address\n");
    printf("  -v            Be more verbose; can be used multiple times\n");
}

variable_types:
programName
char *


decompiled_code:
char *__fastcall process_arguments(int argc, char **argv, __int64 a3)
{
int v4; // eax
char *result; // rax

while ( 1 )
{
v4 = getopt(argc, argv, "hb:v");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
print_help(*argv);
exit(0);
case 'v':
++*(_DWORD *)(a3 + 16);
break;
case 'b':
*(_QWORD *)a3 = optarg;
break;
default:
print_usage(*argv, stderr);
fprintf(stderr, "Run %s -h for help.\n", *argv);
exit(1);
}
}
if ( argc - 1 != optind )
{
fwrite("Port number must be provided as argument.\n", 1uLL, 0x2AuLL, stderr);
print_usage(*argv, stderr);
exit(1);
}
result = argv[optind];
*(_QWORD *)(a3 + 8) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(int argc, char **argv, __int64 a3)
{
int v4; // eax
char *result; // rax

while ( 1 )
{
v4 = getopt(argc, argv, "hb:v");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
func2(*argv);
exit(0);
case 'v':
++*(_DWORD *)(a3 + 16);
break;
case 'b':
*(_QWORD *)a3 = optarg;
break;
default:
func0(*argv, stderr);
fprintf(stderr, "Run %s -h for help.\n", *argv);
exit(1);
}
}
if ( argc - 1 != optind )
{
fwrite("Port number must be provided as argument.\n", 1uLL, 0x2AuLL, stderr);
func0(*argv, stderr);
exit(1);
}
result = argv[optind];
*(_QWORD *)(a3 + 8) = result;
return result;
}

original_code:
static void process_arguments(int argc, char *argv[],
                              struct ServerOptions *options)
{
    int ch;
    while ((ch = getopt(argc, argv, "hb:v")) != -1) {
        switch (ch) {
            case 'h':
                print_help(argv[0]);
                exit(0);
                break;
            case 'b':
                options->host = optarg;
                break;
            case 'v':
                options->verbosity++;
                break;
            case '?':
            default:
                print_usage(argv[0], stderr);
                fprintf(stderr, "Run %s -h for help.\n", argv[0]);
                exit(1);
        }
    }
    if (optind != argc - 1) {
        fprintf(stderr, "Port number must be provided as argument.\n");
        print_usage(argv[0], stderr);
        exit(1);
    }
    options->port = argv[optind];
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct ServerOptions { char *host; char *port; int verbosity; } *

variable_types: ch int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
process_arguments(argc, (char **)argv, (__int64)&v4);
v3 = udp_server_socket(v4, v5);
run_server(v3, v6);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
func3(argc, (char **)argv, (__int64)&v4);
v3 = udp_server_socket(v4, v5);
func4(v3, v6);
}

original_code:
int main(int argc, char *argv[]) {
    int s;
    struct ServerOptions options;
    memset(&options, 0, sizeof(options));
    options.host = ((void *)0);
    options.port = ((void *)0);
    options.verbosity = 0;
    process_arguments(argc, argv, &options);
    s = udp_server_socket(options.host, options.port);
    run_server(s, options.verbosity);
    return 0;
}

variable_types: s int

variable_types: struct ServerOptions { char *host; char *port; int verbosity; }


decompiled_code:
__int64 __fastcall read_seq(unsigned __int8 *a1)
{
return (*a1 << 8) + (unsigned int)a1[1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
return (*a1 << 8) + (unsigned int)a1[1];
}

original_code:
int read_seq(const char *data) {
    int i, seq = 0;
    for (i = 0; i < 2; i++) {
        seq <<= 8;
        seq += (unsigned char) data[i];
    }
    return seq;
}

canonical_original_code:
int read_seq(char *data) {
    int i; int seq = 0;
    for (i = 0; i < 2; i++) {
        seq <<= 8;
        seq += (unsigned char) data[i];
    }
    return seq;
}

variable_types:
data
char *

variable_types: i int


decompiled_code:
__int64 __fastcall seq_lt(int a1, int a2)
{
return (a1 - a2 > 0x8000) | (unsigned __int8)((unsigned int)(a1 - a2 + 0x7FFF) <= 0x7FFE);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return (a1 - a2 > 0x8000) | (unsigned __int8)((unsigned int)(a1 - a2 + 0x7FFF) <= 0x7FFE);
}

original_code:
int seq_lt(int a, int b) {
    int d = a - b;
    if ((d < 0 && d > -0x8000) || (d > 0x8000)) {
        return 1;
    } else {
        return 0;
    }
}

variable_types: a int

variable_types: b int

variable_types: d int


decompiled_code:
__int64 __fastcall seq_gt(int a1, int a2)
{
return (a1 - a2 < -32768) | (unsigned __int8)((unsigned int)(a1 - a2 - 1) <= 0x7FFE);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
return (a1 - a2 < -32768) | (unsigned __int8)((unsigned int)(a1 - a2 - 1) <= 0x7FFE);
}

original_code:
int seq_gt(int a, int b) {
    int d = a - b;
    if ((d > 0 && d < 0x8000) || (d < -0x8000)) {
        return 1;
    } else {
        return 0;
    }
}


decompiled_code:
__int64 __fastcall seq_ge(int a1, int a2)
{
__int64 result; // rax

result = 1LL;
if ( a1 != a2 )
result = seq_gt(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
__int64 result; // rax

result = 1LL;
if ( a1 != a2 )
result = func3(a1, a2);
return result;
}

original_code:
int seq_ge(int a, int b) {
    if (a == b) {
        return 1;
    }
    return seq_gt(a, b);
}


original_code:
int seq_inc(int seq) {
    return (seq + 1) % 0x10000;
}

variable_types: seq int


decompiled_code:
__int64 random_number()
{
return (unsigned int)(rand() % 100);
}

canonical_decompiled_code:
__int64 func6()
{
return (unsigned int)(rand() % 100);
}

original_code:
int random_number() {
    int r = rand() % 100;
    return r;
}

variable_types: r int


decompiled_code:
ssize_t __fastcall send_frame(int fd, __int64 a2, unsigned int a3)
{
ssize_t result; // rax
int v6; // er13
const void *v7; // rsi
int v8; // eax
_BYTE v9[2]; // [rsp+0h] [rbp-F8h] BYREF
char dest[246]; // [rsp+2h] [rbp-F6h] BYREF

result = window_has_seq(a2, a3);
if ( (_DWORD)result )
{
write_seq(v9, a3);
v6 = window_get_message_length(a2, a3);
v7 = (const void *)window_get_message(a2, a3);
memcpy(dest, v7, v6);
result = random_number();
if ( (int)result <= 89 )
{
v8 = window_get_message_length(a2, a3);
result = write(fd, v9, v8 + 2);
if ( (_DWORD)result == -1 )
{
perror("write");
exit(1);
}
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd, __int64 a2, unsigned int a3)
{
ssize_t result; // rax
int v6; // er13
const void *v7; // rsi
int v8; // eax
_BYTE v9[2]; // [rsp+0h] [rbp-F8h] BYREF
char dest[246]; // [rsp+2h] [rbp-F6h] BYREF

result = window_has_seq(a2, a3);
if ( (_DWORD)result )
{
write_seq(v9, a3);
v6 = window_get_message_length(a2, a3);
v7 = (const void *)window_get_message(a2, a3);
memcpy(dest, v7, v6);
result = random_number();
if ( (int)result <= 89 )
{
v8 = window_get_message_length(a2, a3);
result = write(fd, v9, v8 + 2);
if ( (_DWORD)result == -1 )
{
perror("write");
exit(1);
}
}
}
return result;
}

original_code:
static void send_frame(int s, Window *window, int seq) {
    int n;
    char buf[2 + 200];
    if (!window_has_seq(window, seq)) {
        return;
    }
    write_seq(buf, seq);
    memcpy(buf + 2, window_get_message(window, seq),
            window_get_message_length(window, seq));
    if (random_number() < 90) {
        n = write(s, buf, 2 + window_get_message_length(window, seq));
        if (n == -1) {
            perror("write");
            exit(1);
        }
    }
}

canonical_original_code:
static void send_frame(int s, struct WindowItem (*window)[8], int seq) {
    int n;
    char buf[-1];
    if (!window_has_seq(window, seq)) {
        return;
    }
    write_seq(buf, seq);
    memcpy(buf + 2, window_get_message(window, seq),
            window_get_message_length(window, seq));
    if (random_number() < 90) {
        n = write(s, buf, 2 + window_get_message_length(window, seq));
        if (n == -1) {
            perror("write");
            exit(1);
        }
    }
}

variable_types: struct WindowItem { int seq; int length; char message[200]; } (*)[8]

variable_types: n int

variable_types:
buf
char [-1]


max

decompiled_code:
__int64 __fastcall max(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a, int b) {
    if (a > b) {
        return a;
    } else {
        return b;
    }
}


decompiled_code:
int __fastcall print_help(const char *a1)
{
print_usage(a1, stdout);
putchar(10);
puts("Options:");
return puts(" -h Show this help");
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
func1(a1, stdout);
putchar(10);
puts("Options:");
return puts(" -h Show this help");
}

original_code:
static void print_help(const char *programName) {
    print_usage(programName, stdout);
    printf("\n");
    printf("Options:\n");
    printf("  -h  Show this help\n");
}

canonical_original_code:
static void print_help(char *programName) {
    print_usage(programName, stdout);
    printf("\n");
    printf("Options:\n");
    printf("  -h  Show this help\n");
}

variable_types:
programName
char *


main

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

v5 = 0LL;
v4 = 0LL;
process_arguments(argc, (char *const *)argv, &v5, &v4);
fprintf(stderr, "Connecting to %s %s...\n", v5, v4);
v3 = udp_client_socket(v5, v4);
run_client(v3);
exit(0);
}

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

v5 = 0LL;
v4 = 0LL;
func3(argc, (char *const *)argv, &v5, &v4);
fprintf(stderr, "Connecting to %s %s...\n", v5, v4);
v3 = udp_client_socket(v5, v4);
func5(v3);
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
    const char *host = ((void *)0);
    const char *port = ((void *)0);
    int s;
    process_arguments(argc, argv, &host, &port);
    fprintf(stderr, "Connecting to %s %s...\n", host, port);
    s = udp_client_socket(host, port);
    run_client(s);
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    char *host = ((void *)0);
    char *port = ((void *)0);
    int s;
    process_arguments(argc, argv, &host, &port);
    fprintf(stderr, "Connecting to %s %s...\n", host, port);
    s = udp_client_socket(host, port);
    run_client(s);
    exit(0);
}

variable_types: argc int

variable_types:
host
char *

variable_types:
port
char *


decompiled_code:
_BOOL8 __fastcall window_has_seq(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 208LL * (a2 % 8)) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 208LL * (a2 % 8)) == a2;
}

original_code:
int window_has_seq(Window *window, int seq) {
    if ((*window)[seq % 8].seq == seq) {
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int window_has_seq(struct WindowItem (*window)[8], int seq) {
    if ((*window)[seq % 8].seq == seq) {
        return 1;
    } else {
        return 0;
    }
}

user_defined_types: struct WindowItem { int seq; int length; char message[200]; }


decompiled_code:
void *__fastcall window_store(__int64 a1, int a2, const void *a3, int a4)
{
_DWORD *v5; // rdx

v5 = (_DWORD *)(a1 + 208LL * (a2 % 8));
*v5 = a2;
v5[1] = a4;
return memcpy(v5 + 2, a3, a4);
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, int a2, const void *a3, int a4)
{
_DWORD *v5; // rdx

v5 = (_DWORD *)(a1 + 208LL * (a2 % 8));
*v5 = a2;
v5[1] = a4;
return memcpy(v5 + 2, a3, a4);
}

original_code:
void window_store(Window *window, int seq, char *message, int messageLength) {
    struct WindowItem *wi = &((*window)[seq % 8]);
    wi->seq = seq;
    wi->length = messageLength;
    memcpy(wi->message, message, messageLength);
}

canonical_original_code:
void window_store(struct WindowItem (*window)[8], int seq, char *message, int messageLength) {
    struct WindowItem *wi = &((*window)[seq % 8]);
    wi->seq = seq;
    wi->length = messageLength;
    memcpy(wi->message, message, messageLength);
}

variable_types:
message
char *

variable_types: messageLength int

variable_types: struct WindowItem { int seq; int length; char message[200]; } *


original_code:
const char* window_get_message(Window *window, int seq) {
    struct WindowItem *wi = &((*window)[seq % 8]);
    if (wi->seq != seq) {
        return ((void *)0);
    }
    return wi->message;
}

canonical_original_code:
char *window_get_message(struct WindowItem (*window)[8], int seq) {
    struct WindowItem *wi = &((*window)[seq % 8]);
    if (wi->seq != seq) {
        return ((void *)0);
    }
    return wi->message;
}


decompiled_code:
__int64 __fastcall window_get_message_length(__int64 a1, int a2)
{
_DWORD *v2; // rdi
__int64 result; // rax

v2 = (_DWORD *)(208LL * (a2 % 8) + a1);
result = 0LL;
if ( *v2 == a2 )
result = (unsigned int)v2[1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
_DWORD *v2; // rdi
__int64 result; // rax

v2 = (_DWORD *)(208LL * (a2 % 8) + a1);
result = 0LL;
if ( *v2 == a2 )
result = (unsigned int)v2[1];
return result;
}

original_code:
int window_get_message_length(Window *window, int seq) {
    struct WindowItem *wi = &((*window)[seq % 8]);
    if (wi->seq != seq) {
        return 0;
    }
    return wi->length;
}

canonical_original_code:
int window_get_message_length(struct WindowItem (*window)[8], int seq) {
    struct WindowItem *wi = &((*window)[seq % 8]);
    if (wi->seq != seq) {
        return 0;
    }
    return wi->length;
}


decompiled_code:
__int64 __fastcall mbug_device_list_next(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( a1 )
{
list_0 = (__int64)a1;
result = *a1;
}
else
{
v2 = list_0;
result = *(_QWORD *)list_0;
if ( *(_QWORD *)list_0 )
{
list_0 += 8LL;
result = *(_QWORD *)(v2 + 8);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx

if ( a1 )
{
list_0 = (__int64)a1;
result = *a1;
}
else
{
v2 = list_0;
result = *(_QWORD *)list_0;
if ( *(_QWORD *)list_0 )
{
list_0 += 8LL;
result = *(_QWORD *)(v2 + 8);
}
}
return result;
}

original_code:
const char * mbug_device_list_next( mbug_device_list dev_list )
{
 static mbug_device_list list = 0;
 if (dev_list != 0)
  return *(list = dev_list);
 if (*list == 0) return 0;
 return *(++list);
}

canonical_original_code:
char *mbug_device_list_next(char **dev_list)
{
 static char **list = 0;
 if (dev_list != 0)
  return *(list = dev_list);
 if (*list == 0) return 0;
 return *(++list);
}

variable_types:
list
char **


decompiled_code:
unsigned __int64 __fastcall mbug_type_from_id(char *nptr)
{
char *v1; // rbx
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = nptr;
endptr = 0LL;
if ( !memcmp(nptr, "MBUG-", 5uLL) || !memcmp(v1, "mbug-", 5uLL) )
v1 += 5;
if ( strlen(v1) != 11 )
return 0xFFFFFFFFLL;
if ( v1[4] != 45 )
return 0xFFFFFFFFLL;
result = strtoul(v1, &endptr, 10);
if ( *endptr != 45 || result - 1000 > 0x2327 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(char *nptr)
{
char *v1; // rbx
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = nptr;
endptr = 0LL;
if ( !memcmp(nptr, "MBUG-", 5uLL) || !memcmp(v1, "mbug-", 5uLL) )
v1 += 5;
if ( strlen(v1) != 11 )
return 0xFFFFFFFFLL;
if ( v1[4] != 45 )
return 0xFFFFFFFFLL;
result = strtoul(v1, &endptr, 10);
if ( *endptr != 45 || result - 1000 > 0x2327 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int16_t mbug_type_from_id( const char *id )
{
 unsigned long device_type = 0;
 char *endp = 0;
 if (!strncmp( id, "MBUG-", 5 ) || !strncmp( id, "mbug-", 5 ))
  id += 5;
 if (strlen(id)!=11 || id[4]!='-')
  return -1;
 device_type = strtoul( id, &endp, 10 );
 if (*endp != '-' || device_type<1000)
  return -1;
 if (device_type > 9999) return -1;
 return (int16_t)device_type;
}

canonical_original_code:
short mbug_type_from_id(char *id)
{
 unsigned long device_type = 0;
 char *endp = 0;
 if (!strncmp( id, "MBUG-", 5 ) || !strncmp( id, "mbug-", 5 ))
  id += 5;
 if (strlen(id)!=11 || id[4]!='-')
  return -1;
 device_type = strtoul( id, &endp, 10 );
 if (*endp != '-' || device_type<1000)
  return -1;
 if (device_type > 9999) return -1;
 return (short)device_type;
}

variable_types:
id
char *

variable_types:
endp
char *

return_type: short


decompiled_code:
unsigned __int64 __fastcall mbug_serial_from_id(char *s)
{
char *v1; // rbx
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = s;
endptr = 0LL;
if ( !memcmp(s, "MBUG-", 5uLL) || !memcmp(v1, "mbug-", 5uLL) )
v1 += 5;
if ( strlen(v1) != 11 )
return 0xFFFFFFFFLL;
if ( v1[4] != 45 )
return 0xFFFFFFFFLL;
result = strtoul(v1 + 5, &endptr, 10);
if ( *endptr )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(char *s)
{
char *v1; // rbx
unsigned __int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = s;
endptr = 0LL;
if ( !memcmp(s, "MBUG-", 5uLL) || !memcmp(v1, "mbug-", 5uLL) )
v1 += 5;
if ( strlen(v1) != 11 )
return 0xFFFFFFFFLL;
if ( v1[4] != 45 )
return 0xFFFFFFFFLL;
result = strtoul(v1 + 5, &endptr, 10);
if ( *endptr )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int32_t mbug_serial_from_id( const char *id )
{
 unsigned long serial_num = 0;
 char *endp = 0;
 if (!strncmp( id, "MBUG-", 5 ) || !strncmp( id, "mbug-", 5 ))
  id += 5;
 if (strlen(id)!=11 || id[4]!='-')
  return -1;
 serial_num = strtoul( id+5, &endp, 10 );
 if (*endp!='\0')
  return -1;
 return (int32_t)serial_num;
}

canonical_original_code:
int mbug_serial_from_id(char *id)
{
 unsigned long serial_num = 0;
 char *endp = 0;
 if (!strncmp( id, "MBUG-", 5 ) || !strncmp( id, "mbug-", 5 ))
  id += 5;
 if (strlen(id)!=11 || id[4]!='-')
  return -1;
 serial_num = strtoul( id+5, &endp, 10 );
 if (*endp!='\0')
  return -1;
 return (int)serial_num;
}


decompiled_code:
__int64 mbug_2810_list()
{
return mbug_get_device_list(2810LL);
}

canonical_decompiled_code:
__int64 func0()
{
return mbug_get_device_list(2810LL);
}

original_code:
const mbug_device_list mbug_2810_list( void )
{
 return mbug_get_device_list(2810);
}

canonical_original_code:
char **mbug_2810_list()
{
 return mbug_get_device_list(2810);
}

return_type: char **


decompiled_code:
__int64 mbug_2165_list()
{
return mbug_get_device_list(2165LL);
}

canonical_decompiled_code:
__int64 func3()
{
return mbug_get_device_list(2165LL);
}

original_code:
const mbug_device_list mbug_2165_list( void )
{
 return mbug_get_device_list(2165);
}

canonical_original_code:
char **mbug_2165_list()
{
 return mbug_get_device_list(2165);
}


decompiled_code:
__int64 mbug_2820_list()
{
return mbug_get_device_list(2820LL);
}

canonical_decompiled_code:
__int64 func0()
{
return mbug_get_device_list(2820LL);
}

original_code:
const mbug_device_list mbug_2820_list( void )
{
 return mbug_get_device_list(2820);
}

canonical_original_code:
char **mbug_2820_list()
{
 return mbug_get_device_list(2820);
}


decompiled_code:
__int64 mbug_2818_list()
{
return mbug_get_device_list(2818LL);
}

canonical_decompiled_code:
__int64 func0()
{
return mbug_get_device_list(2818LL);
}

original_code:
const mbug_device_list mbug_2818_list( void )
{
 return mbug_get_device_list(2818);
}

canonical_original_code:
char **mbug_2818_list()
{
 return mbug_get_device_list(2818);
}


decompiled_code:
__int64 mbug_2110_list()
{
return mbug_get_device_list(2110LL);
}

canonical_decompiled_code:
__int64 func0()
{
return mbug_get_device_list(2110LL);
}

original_code:
const mbug_device_list mbug_2110_list( void )
{
 return mbug_get_device_list(2110);
}

canonical_original_code:
char **mbug_2110_list()
{
 return mbug_get_device_list(2110);
}


decompiled_code:
__int64 mbug_2811_list()
{
return mbug_get_device_list(2811LL);
}

canonical_decompiled_code:
__int64 func0()
{
return mbug_get_device_list(2811LL);
}

original_code:
const mbug_device_list mbug_2811_list( void )
{
 return mbug_get_device_list(2811);
}

canonical_original_code:
char **mbug_2811_list()
{
 return mbug_get_device_list(2811);
}


repo: metachris/RPIO

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

LODWORD(result) = 150;
do
result = (unsigned int)(result - 1);
while ( (_DWORD)result );
return result;
}

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

LODWORD(result) = 150;
do
result = (unsigned int)(result - 1);
while ( (_DWORD)result );
return result;
}

original_code:
void
short_wait(void)
{
    int i;
    for (i=0; i<150; i++) {
        asm volatile("nop");
    }
}

canonical_original_code:
void short_wait()
{
    int i;
    for (i=0; i<150; i++) {
        asm volatile("nop");
    }
}

variable_types: i int


decompiled_code:
int __fastcall setup_gpio(int a1, int a2, int a3)
{
int v3; // er12
int *v4; // rdx
int result; // eax

v3 = 3 * (a1 % 10);
set_pullupdn(a1, a3);
v4 = (int *)((char *)gpio_map + 4 * (a1 / 10));
if ( a2 )
result = *v4 & ~(7 << v3);
else
result = *v4 & ~(7 << v3) | (1 << v3);
*v4 = result;
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, int a2, int a3)
{
int v3; // er12
int *v4; // rdx
int result; // eax

v3 = 3 * (a1 % 10);
func2(a1, a3);
v4 = (int *)((char *)gpio_map + 4 * (a1 / 10));
if ( a2 )
result = *v4 & ~(7 << v3);
else
result = *v4 & ~(7 << v3) | (1 << v3);
*v4 = result;
return result;
}

original_code:
void
setup_gpio(int gpio, int direction, int pud)
{
    int offset = 0 + (gpio/10);
    int shift = (gpio%10)*3;
    set_pullupdn(gpio, pud);
    if (direction == 0)
        *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift)) | (1<<shift);
    else
        *(gpio_map+offset) = (*(gpio_map+offset) & ~(7<<shift));
}

variable_types: gpio int

variable_types: direction int

variable_types: pud int

variable_types: offset int

variable_types: shift int


decompiled_code:
__int64 __fastcall gpio_function(int a1)
{
return (*((int *)gpio_map + a1 / 10) >> (3 * (a1 % 10))) & 7;
}

original_code:
int
gpio_function(int gpio)
{
    int offset = 0 + (gpio/10);
    int shift = (gpio%10)*3;
    int value = *(gpio_map+offset);
    value >>= shift;
    value &= 7;
    return value;
}

variable_types: value int


decompiled_code:
__int64 __fastcall input_gpio(int a1)
{
return *((_DWORD *)gpio_map + a1 / 32 + 13) & (unsigned int)(1 << (a1 % 32));
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
return *((_DWORD *)gpio_map + a1 / 32 + 13) & (unsigned int)(1 << (a1 % 32));
}

original_code:
int
input_gpio(int gpio)
{
   int offset, value, mask;
   offset = 13 + (gpio/32);
   mask = (1 << gpio%32);
   value = *(gpio_map+offset) & mask;
   return value;
}

canonical_original_code:
int input_gpio(int gpio)
{
   int offset; int value; int mask;
   offset = 13 + (gpio/32);
   mask = (1 << gpio%32);
   value = *(gpio_map+offset) & mask;
   return value;
}

variable_types: mask int


cleanup

decompiled_code:
int cleanup()
{
return munmap(gpio_map, 0x1000uLL);
}

canonical_decompiled_code:
int func7()
{
return munmap(gpio_map, 0x1000uLL);
}

original_code:
void
cleanup(void)
{
    munmap((void *)gpio_map, (4*1024));
}

canonical_original_code:
void cleanup()
{
    munmap((void *)gpio_map, (4*1024));
}


setup

decompiled_code:
__int64 setup()
{
int v0; // ebx
__int64 result; // rax
char *v2; // rax
char *v3; // rdi

v0 = open("/dev/mem", 1052674);
result = 1LL;
if ( v0 >= 0 )
{
v2 = (char *)malloc(0x1FFFuLL);
v3 = v2;
if ( v2 )
{
if ( ((unsigned __int16)v2 & 0xFFF) != 0 )
v3 = &v2[4096 - ((unsigned __int16)v2 & 0xFFF)];
gpio_map = mmap(v3, 0x1000uLL, 3, 17, v0, 538968064LL);
result = 0LL;
}
else
{
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
__int64 result; // rax
char *v2; // rax
char *v3; // rdi

v0 = open("/dev/mem", 1052674);
result = 1LL;
if ( v0 >= 0 )
{
v2 = (char *)malloc(0x1FFFuLL);
v3 = v2;
if ( v2 )
{
if ( ((unsigned __int16)v2 & 0xFFF) != 0 )
v3 = &v2[4096 - ((unsigned __int16)v2 & 0xFFF)];
gpio_map = mmap(v3, 0x1000uLL, 3, 17, v0, 538968064LL);
result = 0LL;
}
else
{
result = 2LL;
}
}
return result;
}

canonical_original_code:
int setup()
{
    int mem_fd;
    unsigned char *gpio_mem;
    if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0)
        return 1;
    if ((gpio_mem = malloc((4*1024) + ((4*1024)-1))) == ((void *)0))
        return 2;
    if ((unsigned int)gpio_mem % (4*1024))
        gpio_mem += (4*1024) - ((unsigned int)gpio_mem % (4*1024));
    gpio_map = (unsigned int *)mmap( (void *)gpio_mem, (4*1024), 0x1|0x2, 0x01|0x10, mem_fd, (0x20000000 + 0x200000));
    if ((unsigned int)gpio_map < 0)
        return 3;
    return 0;
}


repo: metamolecular/gocr-patched

decompiled_code:
size_t __fastcall out_version(int a1)
{
size_t result; // rax

result = fwrite(
" Optical Character Recognition --- gocr 0.50 20101021\n"
" Copyright (C) 2001-2010 Joerg Schulenburg GPG=1024D/53BDFBE3\n"
" released under the GNU General Public License\n",
1uLL,
0xA4uLL,
stderr);
if ( a1 )
{
result = fwrite(" use option -h for help\n", 1uLL, 0x18uLL, stderr);
if ( (a1 & 2) != 0 )
exit(1);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(int a1)
{
size_t result; // rax

result = fwrite(
" Optical Character Recognition --- gocr 0.50 20101021\n"
" Copyright (C) 2001-2010 Joerg Schulenburg GPG=1024D/53BDFBE3\n"
" released under the GNU General Public License\n",
1uLL,
0xA4uLL,
stderr);
if ( a1 )
{
result = fwrite(" use option -h for help\n", 1uLL, 0x18uLL, stderr);
if ( (a1 & 2) != 0 )
exit(1);
}
return result;
}

original_code:
static void out_version(int v) {
  fprintf(stderr, " Optical Character Recognition --- gocr "
          "0.50" " " "20101021" "\n"
          " Copyright (C) 2001-2010 Joerg Schulenburg  GPG=1024D/53BDFBE3\n"
          " released under the GNU General Public License\n");
  if (v)
    fprintf(stderr, " use option -h for help\n");
  if (v & 2)
    exit(1);
  return;
}

variable_types: v int


help

decompiled_code:
void __noreturn help()
{
out_version(0);
fwrite(
" using: gocr [options] pnm_file_name # use - for stdin\n"
" options (see gocr manual pages for more details):\n"
" -h, --help\n"
" -i name - input image file (pnm,pgm,pbm,ppm,pcx,...)\n"
" -o name - output file (redirection of stdout)\n"
" -e name - logging file (redirection of stderr)\n"
" -x name - progress output to fifo (see manual)\n"
" -p name - database path including final slash (default is ./db/)\n",
1uLL,
0x189uLL,
stderr);
fwrite(
" -f fmt - output format (ISO8859_1 TeX HTML XML UTF8 ASCII)\n"
" -l num - threshold grey level 0<160<=255 (0 = autodetect)\n"
" -d num - dust_size (remove small clusters, -1 = autodetect)\n"
" -s num - spacewidth/dots (0 = autodetect)\n"
" -v num - verbose (see manual page)\n"
" -c string - list of chars (debugging, see manual)\n"
" -C string - char filter (ex. hexdigits: 0-9A-Fx, only ASCII)\n"
" -m num - operation modes (bitpattern, see manual)\n",
1uLL,
0x1B9uLL,
stderr);
fwrite(
" -a num - value of certainty (in percent, 0..100, default=95)\n"
" -u string - output this string for every unrecognized character\n",
1uLL,
0x82uLL,
stderr);
fwrite(
" examples:\n"
"\tgocr -m 4 text1.pbm # do layout analyzis\n"
"\tgocr -m 130 -p ./database/ text1.pbm # extend database\n"
"\tdjpeg -pnm -gray text.jpg | gocr - # use jpeg-file via pipe\n"
"\n",
1uLL,
0xC1uLL,
stderr);
fwrite(" webpage: http://jocr.sourceforge.net/\n", 1uLL, 0x27uLL, stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
func1(0);
fwrite(
" using: gocr [options] pnm_file_name # use - for stdin\n"
" options (see gocr manual pages for more details):\n"
" -h, --help\n"
" -i name - input image file (pnm,pgm,pbm,ppm,pcx,...)\n"
" -o name - output file (redirection of stdout)\n"
" -e name - logging file (redirection of stderr)\n"
" -x name - progress output to fifo (see manual)\n"
" -p name - database path including final slash (default is ./db/)\n",
1uLL,
0x189uLL,
stderr);
fwrite(
" -f fmt - output format (ISO8859_1 TeX HTML XML UTF8 ASCII)\n"
" -l num - threshold grey level 0<160<=255 (0 = autodetect)\n"
" -d num - dust_size (remove small clusters, -1 = autodetect)\n"
" -s num - spacewidth/dots (0 = autodetect)\n"
" -v num - verbose (see manual page)\n"
" -c string - list of chars (debugging, see manual)\n"
" -C string - char filter (ex. hexdigits: 0-9A-Fx, only ASCII)\n"
" -m num - operation modes (bitpattern, see manual)\n",
1uLL,
0x1B9uLL,
stderr);
fwrite(
" -a num - value of certainty (in percent, 0..100, default=95)\n"
" -u string - output this string for every unrecognized character\n",
1uLL,
0x82uLL,
stderr);
fwrite(
" examples:\n"
"\tgocr -m 4 text1.pbm # do layout analyzis\n"
"\tgocr -m 130 -p ./database/ text1.pbm # extend database\n"
"\tdjpeg -pnm -gray text.jpg | gocr - # use jpeg-file via pipe\n"
"\n",
1uLL,
0xC1uLL,
stderr);
fwrite(" webpage: http://jocr.sourceforge.net/\n", 1uLL, 0x27uLL, stderr);
exit(0);
}

original_code:
static void help(void) {
  out_version(0);
  fprintf(stderr,
   " using: gocr [options] pnm_file_name  # use - for stdin\n"
   " options (see gocr manual pages for more details):\n"
   " -h, --help\n"
   " -i name   - input image file (pnm,pgm,pbm,ppm,pcx,...)\n"
   " -o name   - output file  (redirection of stdout)\n"
   " -e name   - logging file (redirection of stderr)\n"
   " -x name   - progress output to fifo (see manual)\n"
   " -p name   - database path including final slash (default is ./db/)\n");
  fprintf(stderr,
   " -f fmt    - output format (ISO8859_1 TeX HTML XML UTF8 ASCII)\n"
   " -l num    - threshold grey level 0<160<=255 (0 = autodetect)\n"
   " -d num    - dust_size (remove small clusters, -1 = autodetect)\n"
   " -s num    - spacewidth/dots (0 = autodetect)\n"
   " -v num    - verbose (see manual page)\n"
   " -c string - list of chars (debugging, see manual)\n"
   " -C string - char filter (ex. hexdigits: ""0-9A-Fx"", only ASCII)\n"
   " -m num    - operation modes (bitpattern, see manual)\n");
  fprintf(stderr,
   " -a num    - value of certainty (in percent, 0..100, default=95)\n"
   " -u string - output this string for every unrecognized character\n");
  fprintf(stderr,
   " examples:\n"
   "\tgocr -m 4 text1.pbm                   # do layout analyzis\n"
   "\tgocr -m 130 -p ./database/ text1.pbm  # extend database\n"
   "\tdjpeg -pnm -gray text.jpg | gocr -    # use jpeg-file via pipe\n"
   "\n");
  fprintf(stderr, " webpage: http://jocr.sourceforge.net/\n");
  exit(0);
}

canonical_original_code:
static void help() {
  out_version(0);
  fprintf(stderr,
   " using: gocr [options] pnm_file_name  # use - for stdin\n"
   " options (see gocr manual pages for more details):\n"
   " -h, --help\n"
   " -i name   - input image file (pnm,pgm,pbm,ppm,pcx,...)\n"
   " -o name   - output file  (redirection of stdout)\n"
   " -e name   - logging file (redirection of stderr)\n"
   " -x name   - progress output to fifo (see manual)\n"
   " -p name   - database path including final slash (default is ./db/)\n");
  fprintf(stderr,
   " -f fmt    - output format (ISO8859_1 TeX HTML XML UTF8 ASCII)\n"
   " -l num    - threshold grey level 0<160<=255 (0 = autodetect)\n"
   " -d num    - dust_size (remove small clusters, -1 = autodetect)\n"
   " -s num    - spacewidth/dots (0 = autodetect)\n"
   " -v num    - verbose (see manual page)\n"
   " -c string - list of chars (debugging, see manual)\n"
   " -C string - char filter (ex. hexdigits: ""0-9A-Fx"", only ASCII)\n"
   " -m num    - operation modes (bitpattern, see manual)\n");
  fprintf(stderr,
   " -a num    - value of certainty (in percent, 0..100, default=95)\n"
   " -u string - output this string for every unrecognized character\n");
  fprintf(stderr,
   " examples:\n"
   "\tgocr -m 4 text1.pbm                   # do layout analyzis\n"
   "\tgocr -m 130 -p ./database/ text1.pbm  # extend database\n"
   "\tdjpeg -pnm -gray text.jpg | gocr -    # use jpeg-file via pipe\n"
   "\n");
  fprintf(stderr, " webpage: http://jocr.sourceforge.net/\n");
  exit(0);
}