original_code:
void init_pvoc_ps(struct pvoc_ps_t * pv,
                  int frame_size,
                  int ov_samp_fact,
                  float sample_rate)
{
    int i;
    for(i = 0; i < frame_size; ++i)
    {
        pv->window[i] = -.5*cos((float)(2.0*3.14159265358979323846*(float)i /
                                (float)frame_size))
                        + .5;
    }
    pv->over_samp_fact = ov_samp_fact;
    pv->sample_rate = sample_rate;
    pv->frame_size = frame_size;
    pv->half_frame = frame_size / 2;
    pv->step_size = frame_size / ov_samp_fact;
    pv->expct = 2.0*3.14159265358979323846*(double) pv->step_size/(double)frame_size;
    pv->freq_per_bin = sample_rate / (float) frame_size;
    for(i = 0; i < frame_size/2+1; ++i)
    {
        pv->last_phase[i] = 0.0;
        pv->sum_phase[i] = 0.0;
    }
    switch( pv->over_samp_fact )
    {
        case 1:
            pv->scale_fact = 6.0;
            break;
        case 3:
            pv->scale_fact = 3.0;
            break;
        default:
            pv->scale_fact = 2.5;
            break;
    }
}

canonical_original_code:
void init_pvoc_ps(struct pvoc_ps_t *pv, int frame_size, int ov_samp_fact, float sample_rate)
{
    int i;
    for(i = 0; i < frame_size; ++i)
    {
        pv->window[i] = -.5*cos((float)(2.0*3.14159265358979323846*(float)i /
                                (float)frame_size))
                        + .5;
    }
    pv->over_samp_fact = ov_samp_fact;
    pv->sample_rate = sample_rate;
    pv->frame_size = frame_size;
    pv->half_frame = frame_size / 2;
    pv->step_size = frame_size / ov_samp_fact;
    pv->expct = 2.0*3.14159265358979323846*(double) pv->step_size/(double)frame_size;
    pv->freq_per_bin = sample_rate / (float) frame_size;
    for(i = 0; i < frame_size/2+1; ++i)
    {
        pv->last_phase[i] = 0.0;
        pv->sum_phase[i] = 0.0;
    }
    switch( pv->over_samp_fact )
    {
        case 1:
            pv->scale_fact = 6.0;
            break;
        case 3:
            pv->scale_fact = 3.0;
            break;
        default:
            pv->scale_fact = 2.5;
            break;
    }
}

variable_types: struct pvoc_ps_t { float *window; int frame_size; float sample_rate; int over_samp_fact; struct fft_desc_t { struct complex_t { float real; float imag; } *W; int size; } *fft_desc; struct fft_desc_t *ifft_desc; int step_size; int half_frame; double expct; float freq_per_bin; double scale_fact; float *last_phase; float *sum_phase; struct complex_t *tmp_wksp; } *

user_defined_types: struct pvoc_ps_t { float *window; int frame_size; float sample_rate; int over_samp_fact; struct fft_desc_t *fft_desc; struct fft_desc_t *ifft_desc; int step_size; int half_frame; double expct; float freq_per_bin; double scale_fact; float *last_phase; float *sum_phase; struct complex_t *tmp_wksp; }

user_defined_types: struct fft_desc_t { struct complex_t *W; int size; }


repo: AaronWilhelm/YoDawgIHearYouLikeToSing

original_code:
void pvoc_ps_single_buffer(struct pvoc_ps_t * pv,
                           float * in_sig,
                           struct complex_t * out_sig,
                           float pitch_shift)
{
    int i, qpd, index;
    double re, im, tmp, phase, mag;
    for(i = 0; i < pv->frame_size; ++i)
    {
        pv->tmp_wksp[i].real = in_sig[i] * pv->window[i];
        pv->tmp_wksp[i].imag = 0;
    }
    fft_execute(pv->fft_desc, pv->tmp_wksp);
    pitch_shift = find_ratio(max_peak(pv->tmp_wksp, pv->frame_size));
    for(i = 0; i <= pv->half_frame; ++i)
    {
        re = pv->tmp_wksp[i].real;
        im = pv->tmp_wksp[i].imag;
        pv->tmp_wksp[i].real = 2.0 * sqrt(re*re + im*im);
        phase = atan2(im, re);
        tmp = phase - pv->last_phase[i];
        pv->last_phase[i] = phase;
        tmp -= (double)i * pv->expct;
        qpd = (tmp/3.14159265358979323846);
        if( qpd >= 0 )
        {
          qpd += qpd&1;
        }
        else
        {
          qpd -= qpd&1;
        }
        tmp -= (double)(3.14159265358979323846 * (double) qpd);
        tmp = (float)pv->over_samp_fact*tmp/(2.0*3.14159265358979323846);
        tmp = pv->freq_per_bin * ((float) i + tmp);
        pv->tmp_wksp[i].imag = tmp;
    }
    memset(out_sig, 0, (size_t)pv->frame_size * sizeof(struct complex_t));
    for(i = 0; i <= pv->half_frame; ++i)
    {
        index = (int)((float) i * pitch_shift);
        if( index <= pv->half_frame )
        {
            out_sig[index].real += pv->tmp_wksp[i].real;
            out_sig[index].imag = pv->tmp_wksp[i].imag * pitch_shift;
        }
    }
    for(i = 0; i <= pv->half_frame; ++i)
    {
        mag = out_sig[i].real;
        tmp = out_sig[i].imag;
        tmp -= (float)i * pv->freq_per_bin;
        tmp /= pv->freq_per_bin;
        tmp = 2*3.14159265358979323846*tmp/pv->over_samp_fact;
        tmp += (float)i*pv->expct;
        pv->sum_phase[i] += tmp;
        phase = pv->sum_phase[i];
        out_sig[i].real = mag*cos(phase);
        out_sig[i].imag = mag*sin(phase);
    }
    for(i = pv->half_frame + 1; i < pv->frame_size; ++i)
    {
        out_sig[i].real = 0;
        out_sig[i].imag = 0;
    }
    fft_execute(pv->ifft_desc, out_sig);
    for(i = 0; i < pv->frame_size; ++i)
    {
        out_sig[i].real *= 2.0*pv->window[i]/
                           (pv->half_frame*pv->over_samp_fact);
        out_sig[i].imag = 0.0;
    }
}

canonical_original_code:
void pvoc_ps_single_buffer(struct pvoc_ps_t *pv, float *in_sig, struct complex_t *out_sig, float pitch_shift)
{
    int i; int qpd; int index;
    double re; double im; double tmp; double phase; double mag;
    for(i = 0; i < pv->frame_size; ++i)
    {
        pv->tmp_wksp[i].real = in_sig[i] * pv->window[i];
        pv->tmp_wksp[i].imag = 0;
    }
    fft_execute(pv->fft_desc, pv->tmp_wksp);
    pitch_shift = find_ratio(max_peak(pv->tmp_wksp, pv->frame_size));
    for(i = 0; i <= pv->half_frame; ++i)
    {
        re = pv->tmp_wksp[i].real;
        im = pv->tmp_wksp[i].imag;
        pv->tmp_wksp[i].real = 2.0 * sqrt(re*re + im*im);
        phase = atan2(im, re);
        tmp = phase - pv->last_phase[i];
        pv->last_phase[i] = phase;
        tmp -= (double)i * pv->expct;
        qpd = (tmp/3.14159265358979323846);
        if( qpd >= 0 )
        {
          qpd += qpd&1;
        }
        else
        {
          qpd -= qpd&1;
        }
        tmp -= (double)(3.14159265358979323846 * (double) qpd);
        tmp = (float)pv->over_samp_fact*tmp/(2.0*3.14159265358979323846);
        tmp = pv->freq_per_bin * ((float) i + tmp);
        pv->tmp_wksp[i].imag = tmp;
    }
    memset(out_sig, 0, (unsigned long)pv->frame_size * sizeof(struct complex_t));
    for(i = 0; i <= pv->half_frame; ++i)
    {
        index = (int)((float) i * pitch_shift);
        if( index <= pv->half_frame )
        {
            out_sig[index].real += pv->tmp_wksp[i].real;
            out_sig[index].imag = pv->tmp_wksp[i].imag * pitch_shift;
        }
    }
    for(i = 0; i <= pv->half_frame; ++i)
    {
        mag = out_sig[i].real;
        tmp = out_sig[i].imag;
        tmp -= (float)i * pv->freq_per_bin;
        tmp /= pv->freq_per_bin;
        tmp = 2*3.14159265358979323846*tmp/pv->over_samp_fact;
        tmp += (float)i*pv->expct;
        pv->sum_phase[i] += tmp;
        phase = pv->sum_phase[i];
        out_sig[i].real = mag*cos(phase);
        out_sig[i].imag = mag*sin(phase);
    }
    for(i = pv->half_frame + 1; i < pv->frame_size; ++i)
    {
        out_sig[i].real = 0;
        out_sig[i].imag = 0;
    }
    fft_execute(pv->ifft_desc, out_sig);
    for(i = 0; i < pv->frame_size; ++i)
    {
        out_sig[i].real *= 2.0*pv->window[i]/
                           (pv->half_frame*pv->over_samp_fact);
        out_sig[i].imag = 0.0;
    }
}

variable_types: i int

variable_types: qpd int

variable_types: index int

variable_types: re double

variable_types: im double

variable_types: tmp double

variable_types: phase double

variable_types: mag double

return_type: void

user_defined_types: struct complex_t { float real; float imag; }


original_code:
void fft_c(int n, struct complex_t *x, struct complex_t *W)
{
    struct complex_t u, temp, tm;
    struct complex_t *Wptr;
    int i, j, k, len, Windex;
    Windex = 1;
    for(len = n/2 ; len > 0 ; len /= 2) {
        Wptr = W;
        for (j = 0 ; j < len ; j++) {
            u = *Wptr;
            for (i = j ; i < n ; i = i + 2*len) {
                temp.real = x[i].real + x[i+len].real;
                temp.imag = x[i].imag + x[i+len].imag;
                tm.real = x[i].real - x[i+len].real;
                tm.imag = x[i].imag - x[i+len].imag;
                x[i+len].real = tm.real*u.real - tm.imag*u.imag;
                x[i+len].imag = tm.real*u.imag + tm.imag*u.real;
                x[i] = temp;
            }
            Wptr = Wptr + Windex;
        }
        Windex = 2*Windex;
    }
 j = 0;
 for (i = 1; i < (n-1); i++) {
  k = n/2;
  while(k <= j) {
   j -= k;
   k /= 2;
  }
  j += k;
  if (i < j) {
   temp = x[j];
   x[j] = x[i];
   x[i] = temp;
  }
 }
}

canonical_original_code:
void fft_c(int n, struct complex_t *x, struct complex_t *W)
{
    struct complex_t u; struct complex_t temp; struct complex_t tm;
    struct complex_t *Wptr;
    int i; int j; int k; int len; int Windex;
    Windex = 1;
    for(len = n/2 ; len > 0 ; len /= 2) {
        Wptr = W;
        for (j = 0 ; j < len ; j++) {
            u = *Wptr;
            for (i = j ; i < n ; i = i + 2*len) {
                temp.real = x[i].real + x[i+len].real;
                temp.imag = x[i].imag + x[i+len].imag;
                tm.real = x[i].real - x[i+len].real;
                tm.imag = x[i].imag - x[i+len].imag;
                x[i+len].real = tm.real*u.real - tm.imag*u.imag;
                x[i+len].imag = tm.real*u.imag + tm.imag*u.real;
                x[i] = temp;
            }
            Wptr = Wptr + Windex;
        }
        Windex = 2*Windex;
    }
 j = 0;
 for (i = 1; i < (n-1); i++) {
  k = n/2;
  while(k <= j) {
   j -= k;
   k /= 2;
  }
  j += k;
  if (i < j) {
   temp = x[j];
   x[j] = x[i];
   x[i] = temp;
  }
 }
}

variable_types: n int

variable_types: struct complex_t { float real; float imag; } *

variable_types:
W
struct complex_t *

variable_types: j int

variable_types: k int

variable_types: len int

variable_types: Windex int


fft

decompiled_code:
void __fastcall fft(__int64 a1, __int64 a2)
{
fft_c(*(_DWORD *)(a1 + 8), a2, *(float **)a1);
}

original_code:
void fft(struct fft_desc_t * desc, struct complex_t * data)
{
  fft_c(desc->size, data, desc->W);
}

canonical_original_code:
void fft(struct fft_desc_t *desc, struct complex_t *data)
{
  fft_c(desc->size, data, desc->W);
}

variable_types: struct fft_desc_t { struct complex_t { float real; float imag; } *W; int size; } *

variable_types:
data
struct complex_t *


decompiled_code:
__int64 __fastcall init_fft_desc(__int64 *a1, int a2, int a3)
{
float v3; // xmm4_4
__int64 i; // rbx
double v5; // xmm0_8
float v6; // xmm1_4
__int64 result; // rax
float v8; // [rsp+8h] [rbp-30h]
float v9; // [rsp+Ch] [rbp-2Ch]
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

*((_DWORD *)a1 + 2) = a2;
v3 = 6.283185307179586 / (double)a2;
v9 = v3;
v8 = -1.0;
if ( a3 && a3 == 1 )
v8 = 1.0;
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(_DWORD *)(*a1 + 8 * i++ + 4) = LODWORD(v5) )
{
sincos((float)((float)((float)(int)i * v8) * v9), sinx, &cosx);
v5 = sinx[0];
v6 = cosx;
*(float *)(*a1 + 8 * i) = v6;
result = *a1;
*(float *)&v5 = v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, int a2, int a3)
{
float v3; // xmm4_4
__int64 i; // rbx
double v5; // xmm0_8
float v6; // xmm1_4
__int64 result; // rax
float v8; // [rsp+8h] [rbp-30h]
float v9; // [rsp+Ch] [rbp-2Ch]
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

*((_DWORD *)a1 + 2) = a2;
v3 = 6.283185307179586 / (double)a2;
v9 = v3;
v8 = -1.0;
if ( a3 && a3 == 1 )
v8 = 1.0;
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; *(_DWORD *)(*a1 + 8 * i++ + 4) = LODWORD(v5) )
{
sincos((float)((float)((float)(int)i * v8) * v9), sinx, &cosx);
v5 = sinx[0];
v6 = cosx;
*(float *)(*a1 + 8 * i) = v6;
result = *a1;
*(float *)&v5 = v5;
}
}
return result;
}

original_code:
void init_fft_desc(struct fft_desc_t * desc, int n, enum FFT_Direction dir)
{
    int i;
    desc->size = n;
 float a = 2.0*3.14159265358979323846/n;
    float coeff;
    switch(dir)
    {
        case FFT_FORWARD:
            coeff = -1.0;
            break;
        case FFT_BACKWARD:
            coeff = 1.0;
            break;
        default:
            break;
    }
    for(i = 0 ; i < n ; i++)
    {
      desc->W[i].real = (float) cos(coeff*i*a);
      desc->W[i].imag = (float) sin(coeff*i*a);
    }
}

canonical_original_code:
void init_fft_desc(struct fft_desc_t *desc, int n, enum FFT_Direction dir)
{
    int i;
    desc->size = n;
 float a = 2.0*3.14159265358979323846/n;
    float coeff;
    switch(dir)
    {
        case FFT_FORWARD:
            coeff = -1.0;
            break;
        case FFT_BACKWARD:
            coeff = 1.0;
            break;
        default:
            break;
    }
    for(i = 0 ; i < n ; i++)
    {
      desc->W[i].real = (float) cos(coeff*i*a);
      desc->W[i].imag = (float) sin(coeff*i*a);
    }
}

variable_types: enum FFT_Direction { FFT_FORWARD=0, FFT_BACKWARD=1 }

variable_types: i int

variable_types: a float

variable_types: coeff float


decompiled_code:
void __fastcall fft_execute(__int64 a1, __int64 a2)
{
fft_c(*(_DWORD *)(a1 + 8), a2, *(float **)a1);
}

original_code:
void fft_execute(struct fft_desc_t * desc, struct complex_t * signal)
{
    fft_c(desc->size, signal, desc->W);
}

canonical_original_code:
void fft_execute(struct fft_desc_t *desc, struct complex_t *signal)
{
    fft_c(desc->size, signal, desc->W);
}

variable_types:
signal
struct complex_t *


original_code:
void dummy_pvoc(struct pvoc_ps_t *pv, float* buff2use, struct complex_t *tmp_out_buff)
{
    int i;
    for(i = 0; i < pv->frame_size; ++i)
      tmp_out_buff[i].real = buff2use[i];
}

canonical_original_code:
void dummy_pvoc(struct pvoc_ps_t *pv, float *buff2use, struct complex_t *tmp_out_buff)
{
    int i;
    for(i = 0; i < pv->frame_size; ++i)
      tmp_out_buff[i].real = buff2use[i];
}

variable_types: struct pvoc_ps_t { float *window; int frame_size; float sample_rate; int over_samp_fact; struct fft_desc_t { struct complex_t { float real; float imag; } *W; int size; } *fft_desc; struct fft_desc_t *ifft_desc; int step_size; int half_frame; double expct; float freq_per_bin; double scale_fact; float *last_phase; float *sum_phase; struct complex_t *tmp_wksp; } *


repo: Aaylor/Printer

decompiled_code:
int create_tube()
{
int result; // eax
int *v1; // rax
char *v2; // rax

result = mkfifo(infos, 0x1FFu);
if ( result == -1 )
{
fwrite(&unk_402008, 1uLL, 0x34uLL, stderr);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s\n", v2);
exit(30);
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
int *v1; // rax
char *v2; // rax

result = mkfifo(infos, 0x1FFu);
if ( result == -1 )
{
fwrite(&unk_402008, 1uLL, 0x34uLL, stderr);
v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s\n", v2);
exit(30);
}
return result;
}

original_code:
void
create_tube(void)
{
    if (mkfifo(infos.tube_name, (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3)) == -1)
        do { do { fprintf(stderr, "Erreur lors de la création du tube de récéption.\n"); } while (0); fprintf(stderr, "%s\n", strerror((*__errno_location ()))); if ((30) > 0) exit((30)); } while (0);
}

canonical_original_code:
void create_tube()
{
    if (mkfifo(infos.tube_name, (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3)) == -1)
        do { do { fprintf(stderr, "Erreur lors de la création du tube de récéption.\n"); } while (0); fprintf(stderr, "%s\n", strerror((*__errno_location ()))); if ((30) > 0) exit((30)); } while (0);
}


decompiled_code:
__int64 __fastcall has_eof(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
int v4; // esi

result = 1LL;
if ( a2 > 9 )
{
v3 = (int)a2 - 1;
v4 = a2 - 11;
while ( v4 < (int)v3 )
{
--v3;
if ( *(_BYTE *)(a1 + v3 + 1) )
return 2LL;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
int v4; // esi

result = 1LL;
if ( a2 > 9 )
{
v3 = (int)a2 - 1;
v4 = a2 - 11;
while ( v4 < (int)v3 )
{
--v3;
if ( *(_BYTE *)(a1 + v3 + 1) )
return 2LL;
}
result = 0LL;
}
return result;
}

original_code:
int
has_eof(char *buffer, size_t buffer_size)
{
    int cpt;
    if (buffer_size < 10)
        return 1;
    cpt = buffer_size - 1;
    while(cpt > (int)(buffer_size - 10 - 1))
    {
        if (buffer[cpt--] != '\0')
            return 2;
    }
    return 0;
}

canonical_original_code:
int has_eof(char *buffer, unsigned long buffer_size)
{
    int cpt;
    if (buffer_size < 10)
        return 1;
    cpt = buffer_size - 1;
    while(cpt > (int)(buffer_size - 10 - 1))
    {
        if (buffer[cpt--] != '\0')
            return 2;
    }
    return 0;
}

variable_types:
buffer
char *

variable_types: cpt int

return_type: int


work

decompiled_code:
int work()
{
int v0; // eax
int v1; // ebp
int v2; // er12
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
unsigned __int64 v7; // rax
size_t v8; // rbx
_BYTE v10[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = open(infos, 0);
if ( v0 == -1 )
{
fprintf(stderr, "Erreur lors de l'ouverture du tube de lecture `%s`.\n", infos);
v5 = __errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s\n", v6);
exit(10);
}
v1 = v0;
v2 = open("/dev/null", 1);
if ( v2 == -1 )
{
fwrite("Erreur lors de l'ouverture de /dev/null.", 1uLL, 0x28uLL, stderr);
v3 = __errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s\n", v4);
exit(10);
}
while ( 1 )
{
v7 = read(v1, v10, 0x40uLL);
v8 = v7;
if ( !v7 )
break;
if ( (unsigned int)has_eof((__int64)v10, v7) )
{
write(v2, v10, v8);
}
else
{
write(v2, v10, v8 - 10);
sleep(v8);
}
}
close(v1);
return close(v2);
}

canonical_decompiled_code:
int func9()
{
int v0; // eax
int v1; // ebp
int v2; // er12
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
unsigned __int64 v7; // rax
size_t v8; // rbx
_BYTE v10[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = open(infos, 0);
if ( v0 == -1 )
{
fprintf(stderr, "Erreur lors de l'ouverture du tube de lecture `%s`.\n", infos);
v5 = __errno_location();
v6 = strerror(*v5);
fprintf(stderr, "%s\n", v6);
exit(10);
}
v1 = v0;
v2 = open("/dev/null", 1);
if ( v2 == -1 )
{
fwrite("Erreur lors de l'ouverture de /dev/null.", 1uLL, 0x28uLL, stderr);
v3 = __errno_location();
v4 = strerror(*v3);
fprintf(stderr, "%s\n", v4);
exit(10);
}
while ( 1 )
{
v7 = read(v1, v10, 0x40uLL);
v8 = v7;
if ( !v7 )
break;
if ( (unsigned int)func8((__int64)v10, v7) )
{
write(v2, v10, v8);
}
else
{
write(v2, v10, v8 - 10);
sleep(v8);
}
}
close(v1);
return close(v2);
}

original_code:
void
work(void)
{
    int fd_reading, fd_writing;
    size_t bytes_read, total_read;
    char buffer[64];
    fd_reading = open(infos.tube_name, 00);
    if (fd_reading == -1)
        do { do { fprintf(stderr, "Erreur lors de l'ouverture du tube de lecture `%s`.\n", infos.tube_name); } while (0); fprintf(stderr, "%s\n", strerror((*__errno_location ()))); if ((10) > 0) exit((10)); } while (0);
    fd_writing = open("/dev/null", 01);
    if (fd_writing == -1)
        do { do { fprintf(stderr, "Erreur lors de l'ouverture de /dev/null."); } while (0); fprintf(stderr, "%s\n", strerror((*__errno_location ()))); if ((10) > 0) exit((10)); } while (0);
    total_read = 0;
    while((bytes_read = read(fd_reading, buffer, 64)) > 0)
    {
        if (has_eof(buffer, bytes_read) == 0)
        {
            write(fd_writing, buffer, (bytes_read - 10));
            total_read += (bytes_read - 10);
            sleep(bytes_read);
            total_read = 0;
        }
        else
        {
            write(fd_writing, buffer, bytes_read);
            total_read += bytes_read;
        }
    }
    close(fd_reading);
    close(fd_writing);
}

canonical_original_code:
void work()
{
    int fd_reading; int fd_writing;
    unsigned long bytes_read; unsigned long total_read;
    char buffer[64];
    fd_reading = open(infos.tube_name, 00);
    if (fd_reading == -1)
        do { do { fprintf(stderr, "Erreur lors de l'ouverture du tube de lecture `%s`.\n", infos.tube_name); } while (0); fprintf(stderr, "%s\n", strerror((*__errno_location ()))); if ((10) > 0) exit((10)); } while (0);
    fd_writing = open("/dev/null", 01);
    if (fd_writing == -1)
        do { do { fprintf(stderr, "Erreur lors de l'ouverture de /dev/null."); } while (0); fprintf(stderr, "%s\n", strerror((*__errno_location ()))); if ((10) > 0) exit((10)); } while (0);
    total_read = 0;
    while((bytes_read = read(fd_reading, buffer, 64)) > 0)
    {
        if (has_eof(buffer, bytes_read) == 0)
        {
            write(fd_writing, buffer, (bytes_read - 10));
            total_read += (bytes_read - 10);
            sleep(bytes_read);
            total_read = 0;
        }
        else
        {
            write(fd_writing, buffer, bytes_read);
            total_read += bytes_read;
        }
    }
    close(fd_reading);
    close(fd_writing);
}

variable_types:
buffer
char [64]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
bool v4; // zf
_BOOL4 v5; // ebp
const char *v6; // r12

if ( argc != 5 )
{
fwrite("Nombre d'arguments invalide...\n", 1uLL, 0x1FuLL, stderr);
exit(10);
}
v3 = argv[1];
v4 = strcmp(v3, "-t") == 0;
v5 = !v4;
if ( v4 )
{
infos = (char *)argv[2];
v6 = argv[3];
if ( !strcmp(v6, "-t") )
{
fwrite(&unk_4020DC, 1uLL, 0x1AuLL, stderr);
exit(10);
}
}
else
{
if ( strcmp(v3, "-n") )
goto LABEL_14;
infos = (char *)argv[2];
v6 = argv[3];
v5 = 1;
if ( !strcmp(v6, "-t") )
{
infos = (char *)argv[4];
goto LABEL_6;
}
}
if ( strcmp(v6, "-n") )
{
LABEL_14:
fwrite("Argument inconnu.\n", 1uLL, 0x12uLL, stderr);
exit(10);
}
if ( v5 )
{
fwrite(&unk_4020F7, 1uLL, 0x1AuLL, stderr);
exit(10);
}
infos = (char *)argv[4];
LABEL_6:
create_tube();
work();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
bool v4; // zf
_BOOL4 v5; // ebp
const char *v6; // r12

if ( argc != 5 )
{
fwrite("Nombre d'arguments invalide...\n", 1uLL, 0x1FuLL, stderr);
exit(10);
}
v3 = argv[1];
v4 = strcmp(v3, "-t") == 0;
v5 = !v4;
if ( v4 )
{
infos = (char *)argv[2];
v6 = argv[3];
if ( !strcmp(v6, "-t") )
{
fwrite(&unk_4020DC, 1uLL, 0x1AuLL, stderr);
exit(10);
}
}
else
{
if ( strcmp(v3, "-n") )
goto LABEL_14;
infos = (char *)argv[2];
v6 = argv[3];
v5 = 1;
if ( !strcmp(v6, "-t") )
{
infos = (char *)argv[4];
goto LABEL_6;
}
}
if ( strcmp(v6, "-n") )
{
LABEL_14:
fwrite("Argument inconnu.\n", 1uLL, 0x12uLL, stderr);
exit(10);
}
if ( v5 )
{
fwrite(&unk_4020F7, 1uLL, 0x1AuLL, stderr);
exit(10);
}
infos = (char *)argv[4];
LABEL_6:
func7();
func9();
return 0;
}

original_code:
int
main(int argc, const char **argv)
{
    int tube_set, name_set, cpt;
    if (argc != 5)
        do { do { do { fprintf(stderr, "Nombre d'arguments invalide...\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
    tube_set = 0;
    name_set = 0;
    cpt = 1;
    while (cpt < argc)
    {
        if (strcmp(argv[cpt], "-t") == 0)
        {
            if (tube_set == 1)
                do { do { do { fprintf(stderr, "Argument -t déjà saisi.\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
            tube_set = 1;
            infos.tube_name = argv[++cpt];
        }
        else if (strcmp(argv[cpt], "-n") == 0)
        {
            if (name_set == 1)
                do { do { do { fprintf(stderr, "Argument -n déjà saisi.\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
            name_set = 1;
            infos.tube_name = argv[++cpt];
        }
        else
            do { do { do { fprintf(stderr, "Argument inconnu.\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
        ++cpt;
    }
    create_tube();
    work();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int tube_set; int name_set; int cpt;
    if (argc != 5)
        do { do { do { fprintf(stderr, "Nombre d'arguments invalide...\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
    tube_set = 0;
    name_set = 0;
    cpt = 1;
    while (cpt < argc)
    {
        if (strcmp(argv[cpt], "-t") == 0)
        {
            if (tube_set == 1)
                do { do { do { fprintf(stderr, "Argument -t déjà saisi.\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
            tube_set = 1;
            infos.tube_name = argv[++cpt];
        }
        else if (strcmp(argv[cpt], "-n") == 0)
        {
            if (name_set == 1)
                do { do { do { fprintf(stderr, "Argument -n déjà saisi.\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
            name_set = 1;
            infos.tube_name = argv[++cpt];
        }
        else
            do { do { do { fprintf(stderr, "Argument inconnu.\n"); } while (0); if ((10) > 0) exit((10)); } while (0); do { printf("%s -t printer_pipe -n printer_name", argv[0]); } while (0); } while (0);
        ++cpt;
    }
    create_tube();
    work();
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


afficherAide

decompiled_code:
int afficherAide()
{
putchar(10);
puts("-h : affiche l'aide de votre commande");
puts(aVPourActiverLe);
puts(aCPourCr);
puts("-t : pour lister les fichiers contenus dans une archive");
puts("-r : pour ajouter de nouveaux fichiers");
puts(aUPourMettre);
puts("-x : pour extraire les fichiers de l'archive");
puts("-f : pour indiquer le nom du fichier archive");
puts("-z : pour compresser le fichier d'archive");
puts("-d : pour suprimer un fichier d'une archive");
puts(aSparsePour);
puts(aMAffciherLesDi);
return putchar(10);
}

canonical_decompiled_code:
int func7()
{
putchar(10);
puts("-h : affiche l'aide de votre commande");
puts(aVPourActiverLe);
puts(aCPourCr);
puts("-t : pour lister les fichiers contenus dans une archive");
puts("-r : pour ajouter de nouveaux fichiers");
puts(aUPourMettre);
puts("-x : pour extraire les fichiers de l'archive");
puts("-f : pour indiquer le nom du fichier archive");
puts("-z : pour compresser le fichier d'archive");
puts("-d : pour suprimer un fichier d'une archive");
puts(aSparsePour);
puts(aMAffciherLesDi);
return putchar(10);
}

original_code:
void afficherAide()
{
 printf("\n");
 printf("-h : affiche l'aide de votre commande\n");
 printf("-v : pour activer le mode verbose (affiche des détails sur l'execution)\n");
 printf("-c : pour créer une archive à partir d'une liste de fichier\n");
 printf("-t : pour lister les fichiers contenus dans une archive\n");
 printf("-r : pour ajouter de nouveaux fichiers\n");
 printf("-u : pour mettre à jour l'archive si les fichiers lités sont plus récents que ceux archivés\n");
 printf("-x : pour extraire les fichiers de l'archive\n");
 printf("-f : pour indiquer le nom du fichier archive\n");
 printf("-z : pour compresser le fichier d'archive\n");
 printf("-d : pour suprimer un fichier d'une archive\n");
 printf("-sparse : pour économiser de la place pour stocker les fichiers contenant beaucoup de zéros consécutifs\n");
 printf("-m : affciher les différences entre les fichiers archivés et les fichiers existants\n");
 printf("\n");
}


compression

decompiled_code:
void __fastcall compression(const char *a1)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "gzip %s", a1);
system(ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(const char *a1)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "gzip %s", a1);
system(ptr);
free(ptr);
}

original_code:
void compression (char* archive)
{
  char* nomArchive= archive;
  char *buf;
  asprintf(&buf, "gzip %s", nomArchive);
  system(buf);
  free(buf);
}

canonical_original_code:
void compression(char *archive)
{
  char *nomArchive = archive;
  char *buf;
  asprintf(&buf, "gzip %s", nomArchive);
  system(buf);
  free(buf);
}

variable_types:
archive
char *

variable_types:
nomArchive
char *

variable_types:
buf
char *


original_code:
void * wysylanie_serwer(void *arguments)
{
  struct ArgumentyProgramu *argumenty1=arguments;
  do
  {
    bzero(argumenty1->buffer,256);
    fgets(argumenty1->buffer,255,stdin);
    if((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==1)
    {
 argumenty1->n = write(argumenty1->newsockfd,argumenty1->buffer,255);
 printf("Bye!\n");
       return ((void *)0);
    }
    else {
    argumenty1->n = write(argumenty1->newsockfd,argumenty1->buffer,255); }
  }
    while((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==0);
    return ((void *)0);
}

canonical_original_code:
void *wysylanie_serwer(void *arguments)
{
  struct ArgumentyProgramu *argumenty1 = arguments;
  do
  {
    bzero(argumenty1->buffer,256);
    fgets(argumenty1->buffer,255,stdin);
    if((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==1)
    {
 argumenty1->n = write(argumenty1->newsockfd,argumenty1->buffer,255);
 printf("Bye!\n");
       return ((void *)0);
    }
    else {
    argumenty1->n = write(argumenty1->newsockfd,argumenty1->buffer,255); }
  }
    while((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==0);
    return ((void *)0);
}

variable_types:
arguments
void *

variable_types: struct ArgumentyProgramu { int sockfd; int newsockfd; int portno; int n; char buffer[256]; } *

return_type: void *


decompiled_code:
void *__fastcall sluchanie_serwer(void *a1)
{
int v1; // eax

do
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 16 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 256) >> 3));
v1 = read(*((_DWORD *)a1 + 1), (char *)a1 + 16, 0xFFuLL);
*((_DWORD *)a1 + 3) = v1;
if ( v1 < 0 )
error("ERROR reading from socket");
printf("client: %s", (const char *)a1 + 16);
}
while ( *((int *)a1 + 3) > 0 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
int v1; // eax

do
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 16 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 256) >> 3));
v1 = read(*((_DWORD *)a1 + 1), (char *)a1 + 16, 0xFFuLL);
*((_DWORD *)a1 + 3) = v1;
if ( v1 < 0 )
func2("ERROR reading from socket");
printf("client: %s", (const char *)a1 + 16);
}
while ( *((int *)a1 + 3) > 0 );
return 0LL;
}

original_code:
void * sluchanie_serwer(void *arguments)
{
   struct ArgumentyProgramu *argumenty=arguments;
   do
  {
   bzero(argumenty->buffer,256);
   argumenty->n = read(argumenty->newsockfd,argumenty->buffer,255);
   if (argumenty->n < 0) error("ERROR reading from socket");
   printf("client: %s",argumenty->buffer);
  }
    while(argumenty->n > 0);
    return ((void *)0);
}

canonical_original_code:
void *sluchanie_serwer(void *arguments)
{
   struct ArgumentyProgramu *argumenty = arguments;
   do
  {
   bzero(argumenty->buffer,256);
   argumenty->n = read(argumenty->newsockfd,argumenty->buffer,255);
   if (argumenty->n < 0) error("ERROR reading from socket");
   printf("client: %s",argumenty->buffer);
  }
    while(argumenty->n > 0);
    return ((void *)0);
}

user_defined_types: struct ArgumentyProgramu { int sockfd; int newsockfd; int portno; int n; char buffer[256]; }


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
perror(a1);
exit(0);
}

original_code:
void error(const char *msg)
{
    perror(msg);
    exit(0);
}

canonical_original_code:
void error(char *msg)
{
    perror(msg);
    exit(0);
}

variable_types:
msg
char *


server

decompiled_code:
__int64 __fastcall server(int a1)
{
int v1; // eax
int v2; // ebp
struct sockaddr v4; // [rsp+0h] [rbp-168h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-158h] BYREF
socklen_t addr_len; // [rsp+2Ch] [rbp-13Ch] BYREF
int fd; // [rsp+30h] [rbp-138h] BYREF
int v8; // [rsp+34h] [rbp-134h]
int v9; // [rsp+38h] [rbp-130h]
pthread_t th; // [rsp+140h] [rbp-28h] BYREF
pthread_t newthread[4]; // [rsp+148h] [rbp-20h] BYREF

v1 = socket(2, 1, 0);
fd = v1;
if ( v1 < 0 )
error("ERROR opening socket");
v2 = v1;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v9 = a1;
*(_WORD *)addr.sa_data = _bswap_16(a1);
if ( bind(v2, &addr, 0x10u) < 0 )
error("ERROR on binding");
listen(fd, 5);
addr_len = 16;
v8 = accept(fd, &v4, &addr_len);
if ( v8 < 0 )
error("ERROR on accept");
pthread_create(newthread, 0LL, sluchanie_serwer, &fd);
pthread_create(&th, 0LL, wysylanie_serwer, &fd);
pthread_join(th, 0LL);
pthread_cancel(newthread[0]);
close(v8);
close(fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // eax
int v2; // ebp
struct sockaddr v4; // [rsp+0h] [rbp-168h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-158h] BYREF
socklen_t addr_len; // [rsp+2Ch] [rbp-13Ch] BYREF
int fd; // [rsp+30h] [rbp-138h] BYREF
int v8; // [rsp+34h] [rbp-134h]
int v9; // [rsp+38h] [rbp-130h]
pthread_t th; // [rsp+140h] [rbp-28h] BYREF
pthread_t newthread[4]; // [rsp+148h] [rbp-20h] BYREF

v1 = socket(2, 1, 0);
fd = v1;
if ( v1 < 0 )
func2("ERROR opening socket");
v2 = v1;
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v9 = a1;
*(_WORD *)addr.sa_data = func1(a1);
if ( bind(v2, &addr, 0x10u) < 0 )
func2("ERROR on binding");
listen(fd, 5);
addr_len = 16;
v8 = accept(fd, &v4, &addr_len);
if ( v8 < 0 )
func2("ERROR on accept");
pthread_create(newthread, 0LL, sluchanie_serwer, &fd);
pthread_create(&th, 0LL, wysylanie_serwer, &fd);
pthread_join(th, 0LL);
pthread_cancel(newthread[0]);
close(v8);
close(fd);
return 0LL;
}

original_code:
int server(int portno)
{
     pthread_t sluchanies;
     pthread_t wysylanies;
     struct ArgumentyProgramu argumenty;
     socklen_t clilen;
     struct sockaddr_in serv_addr, cli_addr;
     int n;
     argumenty.sockfd = socket(2, SOCK_STREAM, 0);
     if (argumenty.sockfd < 0)
     {
        error("ERROR opening socket");
 return 1;
    }
     bzero((char *) &serv_addr, sizeof(serv_addr));
     argumenty.portno = portno;
     serv_addr.sin_family = 2;
     serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
     serv_addr.sin_port = htons(argumenty.portno);
     if (bind(argumenty.sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
     {
              error("ERROR on binding");
       return 2;
    }
    listen(argumenty.sockfd,5);
     clilen = sizeof(cli_addr);
     argumenty.newsockfd = accept(argumenty.sockfd,
                 (struct sockaddr *) &cli_addr,
                 &clilen);
     if (argumenty.newsockfd < 0)
     {
          error("ERROR on accept");
   return 3;
     }
    pthread_create(&sluchanies,((void *)0),&sluchanie_serwer,(void*)&argumenty);
    pthread_create(&wysylanies,((void *)0),&wysylanie_serwer,(void*)&argumenty);
    pthread_join(wysylanies, ((void *)0));
    pthread_cancel(sluchanies);
    close(argumenty.newsockfd);
     close(argumenty.sockfd);
     return 0;
}

canonical_original_code:
int server(int portno)
{
     unsigned long sluchanies;
     unsigned long wysylanies;
     struct ArgumentyProgramu argumenty;
     unsigned int clilen;
     struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
     int n;
     argumenty.sockfd = socket(2, SOCK_STREAM, 0);
     if (argumenty.sockfd < 0)
     {
        error("ERROR opening socket");
 return 1;
    }
     bzero((char *) &serv_addr, sizeof(serv_addr));
     argumenty.portno = portno;
     serv_addr.sin_family = 2;
     serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
     serv_addr.sin_port = htons(argumenty.portno);
     if (bind(argumenty.sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
     {
              error("ERROR on binding");
       return 2;
    }
    listen(argumenty.sockfd,5);
     clilen = sizeof(cli_addr);
     argumenty.newsockfd = accept(argumenty.sockfd,
                 (struct sockaddr *) &cli_addr,
                 &clilen);
     if (argumenty.newsockfd < 0)
     {
          error("ERROR on accept");
   return 3;
     }
    pthread_create(&sluchanies,((void *)0),&sluchanie_serwer,(void *)&argumenty);
    pthread_create(&wysylanies,((void *)0),&wysylanie_serwer,(void *)&argumenty);
    pthread_join(wysylanies, ((void *)0));
    pthread_cancel(sluchanies);
    close(argumenty.newsockfd);
     close(argumenty.sockfd);
     return 0;
}

variable_types: portno int

variable_types:
sluchanies
unsigned long

variable_types:
wysylanies
unsigned long

variable_types: struct ArgumentyProgramu { int sockfd; int newsockfd; int portno; int n; char buffer[256]; }

variable_types:
clilen
unsigned int

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

variable_types: n int

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

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


wczytywanie

decompiled_code:
void *__fastcall wczytywanie(void *a1)
{
printf("podaj numer portu ");
_isoc99_scanf("%d", a1);
puts("podaj kim chcesz byc: \n 1 :serwer \n 2 : klient");
_isoc99_scanf("%d", (char *)a1 + 4);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
printf("podaj numer portu ");
_isoc99_scanf("%d", a1);
puts("podaj kim chcesz byc: \n 1 :serwer \n 2 : klient");
_isoc99_scanf("%d", (char *)a1 + 4);
return 0LL;
}

original_code:
void * wczytywanie(void *arguments)
{
  struct zmienne *wybieranie=arguments;
  printf("podaj numer portu ");
  scanf("%d",&wybieranie->portno);
  printf("podaj kim chcesz byc: \n 1 :serwer \n 2 : klient\n");
  scanf("%d",&wybieranie->k);
  return ((void *)0);
}

canonical_original_code:
void *wczytywanie(void *arguments)
{
  struct zmienne *wybieranie = arguments;
  printf("podaj numer portu ");
  scanf("%d",&wybieranie->portno);
  printf("podaj kim chcesz byc: \n 1 :serwer \n 2 : klient\n");
  scanf("%d",&wybieranie->k);
  return ((void *)0);
}

variable_types: struct zmienne { int portno; int k; char hostname[20]; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // ebx
unsigned int v6; // [rsp+0h] [rbp-48h] BYREF
int v7; // [rsp+4h] [rbp-44h]
pthread_t newthread[4]; // [rsp+28h] [rbp-20h] BYREF

v3 = argv[1];
pthread_create(newthread, 0LL, wczytywanie, &v6);
pthread_join(newthread[0], 0LL);
puts("\nZaczynam dzialac\n Aby wyjsc z czatu nalezy wpisac -e \n tekst wysylasz po wcisnieciu <Enter> ");
printf("Czekam na polacznie... ");
if ( v7 == 1 )
server(v6);
v4 = v7;
if ( v7 != 2 )
return 0;
if ( argc == 1 )
{
puts("wywolujac jako klient nalezy podac hostname jako argument programu ");
}
else
{
client(v6, v3);
v4 = 0;
}
return v4;
}

original_code:
int main(int argc,char* argv[])
{
  pthread_t wybor;
  struct zmienne zm_glowne;
   char *host=zm_glowne.hostname;
   host=argv[1];
   pthread_create(&wybor,((void *)0),&wczytywanie,(void*)&zm_glowne);
   pthread_join(wybor, ((void *)0));
  printf("\nZaczynam dzialac\n Aby wyjsc z czatu nalezy wpisac -e \n tekst wysylasz po wcisnieciu <Enter> \n");
  printf("Czekam na polacznie... ");
  if(zm_glowne.k==1)
  {
    server(zm_glowne.portno);
  }
  if(zm_glowne.k==2)
  {
    if(argc==1)
  {
    printf("wywolujac jako klient nalezy podac hostname jako argument programu \n");
    return 2; }
    client(zm_glowne.portno,host);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  unsigned long wybor;
  struct zmienne zm_glowne;
   char *host = zm_glowne.hostname;
   host=argv[1];
   pthread_create(&wybor,((void *)0),&wczytywanie,(void *)&zm_glowne);
   pthread_join(wybor, ((void *)0));
  printf("\nZaczynam dzialac\n Aby wyjsc z czatu nalezy wpisac -e \n tekst wysylasz po wcisnieciu <Enter> \n");
  printf("Czekam na polacznie... ");
  if(zm_glowne.k==1)
  {
    server(zm_glowne.portno);
  }
  if(zm_glowne.k==2)
  {
    if(argc==1)
  {
    printf("wywolujac jako klient nalezy podac hostname jako argument programu \n");
    return 2; }
    client(zm_glowne.portno,host);
  }
  return 0;
}

variable_types:
argv
char *[]

variable_types:
wybor
unsigned long

variable_types: struct zmienne { int portno; int k; char hostname[20]; }

variable_types:
host
char *


sendmessage

decompiled_code:
void __fastcall __noreturn sendmessage(void *a1)
{
size_t v1; // rbp
void *v2; // r12
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
char v6[96]; // [rsp+0h] [rbp-F8h] BYREF
int v7; // [rsp+60h] [rbp-98h]
char s[8]; // [rsp+70h] [rbp-88h] BYREF
__int64 v9; // [rsp+78h] [rbp-80h]
__int64 v10; // [rsp+80h] [rbp-78h]
__int64 v11; // [rsp+88h] [rbp-70h]
__int64 v12; // [rsp+90h] [rbp-68h]
__int64 v13; // [rsp+98h] [rbp-60h]
__int64 v14; // [rsp+A0h] [rbp-58h]
__int64 v15; // [rsp+A8h] [rbp-50h]
__int64 v16; // [rsp+B0h] [rbp-48h]
__int64 v17; // [rsp+B8h] [rbp-40h]

v1 = maxx - 4;
v2 = malloc(v1);
while ( 1 )
{
*(_QWORD *)s = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
memset(v6, 0, sizeof(v6));
v7 = 0;
memset(v2, 0, v1);
wrefresh(top);
wrefresh(bottom);
if ( wmove(bottom, input, 2) != -1 )
wgetnstr(bottom, s, -1);
strcpy(v6, (const char *)a1);
v3 = strlen(s);
strncat(v6, ": ", 100 - v3);
v4 = strlen(s);
strncat(v6, s, 100 - v4);
if ( !strcmp(s, "exit") )
{
done = 1;
endwin();
pthread_mutex_destroy(&mutexsum);
pthread_exit(0LL);
}
v5 = strlen(v6);
write(sockfd, v6, v5);
mvwprintw(top, line, 2, v6);
pthread_mutex_lock(&mutexsum);
if ( maxy / 2 - 2 == line )
wscrl(top, 1);
else
++line;
if ( maxy / 2 - 2 == input )
wscrl(bottom, 1);
else
++input;
pthread_mutex_unlock(&mutexsum);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
size_t v1; // rbp
void *v2; // r12
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
char v6[96]; // [rsp+0h] [rbp-F8h] BYREF
int v7; // [rsp+60h] [rbp-98h]
char s[8]; // [rsp+70h] [rbp-88h] BYREF
__int64 v9; // [rsp+78h] [rbp-80h]
__int64 v10; // [rsp+80h] [rbp-78h]
__int64 v11; // [rsp+88h] [rbp-70h]
__int64 v12; // [rsp+90h] [rbp-68h]
__int64 v13; // [rsp+98h] [rbp-60h]
__int64 v14; // [rsp+A0h] [rbp-58h]
__int64 v15; // [rsp+A8h] [rbp-50h]
__int64 v16; // [rsp+B0h] [rbp-48h]
__int64 v17; // [rsp+B8h] [rbp-40h]

v1 = maxx - 4;
v2 = malloc(v1);
while ( 1 )
{
*(_QWORD *)s = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
memset(v6, 0, sizeof(v6));
v7 = 0;
memset(v2, 0, v1);
wrefresh(top);
wrefresh(bottom);
if ( wmove(bottom, input, 2) != -1 )
wgetnstr(bottom, s, -1);
strcpy(v6, (const char *)a1);
v3 = strlen(s);
strncat(v6, ": ", 100 - v3);
v4 = strlen(s);
strncat(v6, s, 100 - v4);
if ( !strcmp(s, "exit") )
{
done = 1;
endwin();
pthread_mutex_destroy(&mutexsum);
pthread_exit(0LL);
}
v5 = strlen(v6);
write(sockfd, v6, v5);
mvwprintw(top, line, 2, v6);
pthread_mutex_lock(&mutexsum);
if ( maxy / 2 - 2 == line )
wscrl(top, 1);
else
++line;
if ( maxy / 2 - 2 == input )
wscrl(bottom, 1);
else
++input;
pthread_mutex_unlock(&mutexsum);
}
}

original_code:
void *sendmessage(void *name)
{
    char str[80];
    char msg[100];
    int bufsize=maxx-4;
    char *buffer=malloc(bufsize);
    while(1)
    {
        bzero(str,80);
        bzero(msg,100);
        bzero(buffer,bufsize);
        wrefresh(top);
        wrefresh(bottom);
        (wmove((bottom),(input),(2)) == (-1) ? (-1) : wgetnstr((bottom), (str), -1));
        strcpy(msg,name);
        strncat(msg,": \0",100-strlen(str));
        strncat(msg,str,100-strlen(str));
        if(strcmp(str,"exit")==0)
        {
            done = 1;
            endwin();
            pthread_mutex_destroy(&mutexsum);
            pthread_exit(((void *)0));
            close(sockfd);
        }
        write(sockfd,msg,strlen(msg));
        mvwprintw(top,line,2,msg);
        pthread_mutex_lock (&mutexsum);
        if(line!=maxy/2-2)
            line++;
        else
            wscrl(top,1);
        if(input!=maxy/2-2)
            input++;
        else
            wscrl(bottom,1);
        pthread_mutex_unlock (&mutexsum);
    }
}

canonical_original_code:
void *sendmessage(void *name)
{
    char str[80];
    char msg[100];
    int bufsize = maxx-4;
    char *buffer = malloc(bufsize);
    while(1)
    {
        bzero(str,80);
        bzero(msg,100);
        bzero(buffer,bufsize);
        wrefresh(top);
        wrefresh(bottom);
        (wmove((bottom),(input),(2)) == (-1) ? (-1) : wgetnstr((bottom), (str), -1));
        strcpy(msg,name);
        strncat(msg,": \0",100-strlen(str));
        strncat(msg,str,100-strlen(str));
        if(strcmp(str,"exit")==0)
        {
            done = 1;
            endwin();
            pthread_mutex_destroy(&mutexsum);
            pthread_exit(((void *)0));
            close(sockfd);
        }
        write(sockfd,msg,strlen(msg));
        mvwprintw(top,line,2,msg);
        pthread_mutex_lock (&mutexsum);
        if(line!=maxy/2-2)
            line++;
        else
            wscrl(top,1);
        if(input!=maxy/2-2)
            input++;
        else
            wscrl(bottom,1);
        pthread_mutex_unlock (&mutexsum);
    }
}

variable_types:
name
void *

variable_types:
str
char [80]

variable_types:
msg
char [100]

variable_types: bufsize int

variable_types:
buffer
char *


listener

decompiled_code:
void __fastcall __noreturn listener(void *a1)
{
size_t v1; // rbp
void *v2; // rbx

v1 = maxx - 4;
v2 = malloc(v1);
while ( 1 )
{
memset(v2, 0, v1);
wrefresh(top);
wrefresh(bottom);
read(sockfd, v2, v1);
mvwprintw(top, line, 3, (const char *)v2);
pthread_mutex_lock(&mutexsum);
if ( maxy / 2 - 2 == line )
wscrl(top, 1);
else
++line;
pthread_mutex_unlock(&mutexsum);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
size_t v1; // rbp
void *v2; // rbx

v1 = maxx - 4;
v2 = malloc(v1);
while ( 1 )
{
memset(v2, 0, v1);
wrefresh(top);
wrefresh(bottom);
read(sockfd, v2, v1);
mvwprintw(top, line, 3, (const char *)v2);
pthread_mutex_lock(&mutexsum);
if ( maxy / 2 - 2 == line )
wscrl(top, 1);
else
++line;
pthread_mutex_unlock(&mutexsum);
}
}

original_code:
void *listener()
{
    char str[80];
    int bufsize=maxx-4;
    char *buffer=malloc(bufsize);
    while(1)
    {
        bzero(buffer,bufsize);
        wrefresh(top);
        wrefresh(bottom);
        read(sockfd,buffer,bufsize);
        mvwprintw(top,line,3,buffer);
        pthread_mutex_lock (&mutexsum);
        if(line!=maxy/2-2)
            line++;
        else
            wscrl(top,1);
        pthread_mutex_unlock (&mutexsum);
    }
}

canonical_original_code:
void *listener()
{
    char str[80];
    int bufsize = maxx-4;
    char *buffer = malloc(bufsize);
    while(1)
    {
        bzero(buffer,bufsize);
        wrefresh(top);
        wrefresh(bottom);
        read(sockfd,buffer,bufsize);
        mvwprintw(top,line,3,buffer);
        pthread_mutex_lock (&mutexsum);
        if(line!=maxy/2-2)
            line++;
        else
            wscrl(top,1);
        pthread_mutex_unlock (&mutexsum);
    }
}


client

decompiled_code:
__int64 __fastcall client(__int64 a1, __int64 a2)
{
__int16 v2; // bx
const char *v3; // rdx
struct hostent *v4; // rax
const char *v5; // rdx
int v6; // eax
int v7; // esi
pthread_attr_t v9; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread; // [rsp+40h] [rbp-38h] BYREF
pthread_t v11; // [rsp+48h] [rbp-30h] BYREF
struct sockaddr dest[2]; // [rsp+50h] [rbp-28h] BYREF

printf("Podaj swoj username: ");
_isoc99_scanf("%s", &name);
v2 = atoi(*(const char **)(a2 + 16));
sockfd = socket(2, 1, 0);
if ( sockfd < 0 )
error((int)"ERROR opening socket", 1, v3);
v4 = gethostbyname(*(const char **)(a2 + 8));
if ( !v4 )
{
fwrite("ERROR, no such host\n", 1uLL, 0x14uLL, stderr);
exit(0);
}
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
memmove(&dest[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)dest[0].sa_data = _bswap_16(v2);
if ( connect(sockfd, dest, 0x10u) < 0 )
error((int)"ERROR connecting", (int)dest, v5);
initscr();
if ( stdscr )
{
v6 = stdscr->_maxy + 1;
maxy = v6;
v7 = stdscr->_maxx + 1;
}
else
{
maxy = -1;
v6 = -1;
v7 = -1;
}
maxx = v7;
top = newwin(v6 / 2, v7, 0, 0);
bottom = newwin(maxy / 2, maxx, maxy / 2, 0);
scrollok(top, 1);
scrollok(bottom, 1);
wborder(top, 0x7CuLL, 0x7CuLL, 0x3DuLL, 0x3DuLL, 0LL, 0LL, 0LL, 0LL);
wborder(bottom, 0x7CuLL, 0x7CuLL, 0x2DuLL, 0x2DuLL, 0LL, 0LL, 0LL, 0LL);
wsetscrreg(top, 1, maxy / 2 - 2);
wsetscrreg(bottom, 1, maxy / 2 - 2);
pthread_attr_init(&v9);
pthread_attr_setdetachstate(&v9, 0);
pthread_create(&newthread, &v9, (void *(*)(void *))sendmessage, &name);
pthread_create(&v11, &v9, (void *(*)(void *))listener, 0LL);
while ( !done )
;
close(sockfd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int16 v2; // bx
const char *v3; // rdx
struct hostent *v4; // rax
const char *v5; // rdx
int v6; // eax
int v7; // esi
pthread_attr_t v9; // [rsp+0h] [rbp-78h] BYREF
pthread_t newthread; // [rsp+40h] [rbp-38h] BYREF
pthread_t v11; // [rsp+48h] [rbp-30h] BYREF
struct sockaddr dest[2]; // [rsp+50h] [rbp-28h] BYREF

printf("Podaj swoj username: ");
_isoc99_scanf("%s", &name);
v2 = atoi(*(const char **)(a2 + 16));
sockfd = socket(2, 1, 0);
if ( sockfd < 0 )
error((int)"ERROR opening socket", 1, v3);
v4 = gethostbyname(*(const char **)(a2 + 8));
if ( !v4 )
{
fwrite("ERROR, no such host\n", 1uLL, 0x14uLL, stderr);
exit(0);
}
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
memmove(&dest[0].sa_data[2], *(const void **)v4->h_addr_list, v4->h_length);
*(_WORD *)dest[0].sa_data = func0(v2);
if ( connect(sockfd, dest, 0x10u) < 0 )
error((int)"ERROR connecting", (int)dest, v5);
initscr();
if ( stdscr )
{
v6 = stdscr->_maxy + 1;
maxy = v6;
v7 = stdscr->_maxx + 1;
}
else
{
maxy = -1;
v6 = -1;
v7 = -1;
}
maxx = v7;
top = newwin(v6 / 2, v7, 0, 0);
bottom = newwin(maxy / 2, maxx, maxy / 2, 0);
scrollok(top, 1);
scrollok(bottom, 1);
wborder(top, 0x7CuLL, 0x7CuLL, 0x3DuLL, 0x3DuLL, 0LL, 0LL, 0LL, 0LL);
wborder(bottom, 0x7CuLL, 0x7CuLL, 0x2DuLL, 0x2DuLL, 0LL, 0LL, 0LL, 0LL);
wsetscrreg(top, 1, maxy / 2 - 2);
wsetscrreg(bottom, 1, maxy / 2 - 2);
pthread_attr_init(&v9);
pthread_attr_setdetachstate(&v9, 0);
pthread_create(&newthread, &v9, (void *(*)(void *))sendmessage, &name);
pthread_create(&v11, &v9, (void *(*)(void *))listener, 0LL);
while ( !done )
;
close(sockfd);
return 0LL;
}

original_code:
int client(int argc, char *argv[])
{
 printf("Podaj swoj username: ");
 scanf("%s",name);
 int portno, n;
 struct sockaddr_in serv_addr;
 struct hostent *server;
 portno = atoi(argv[2]);
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  error("ERROR opening socket");
 server = gethostbyname(argv[1]);
 if (server == ((void *)0)) {
  fprintf(stderr, "ERROR, no such host\n");
  exit(0);
 }
 bzero((char *)&serv_addr, sizeof(serv_addr));
 serv_addr.sin_family = 2;
 bcopy((char *)server->h_addr_list[0],
  (char *)&serv_addr.sin_addr.s_addr,
  server->h_length);
 serv_addr.sin_port = htons(portno);
 if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
  error("ERROR connecting");
 initscr();
 (maxy = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), maxx = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 top = newwin(maxy/2,maxx,0,0);
 bottom= newwin(maxy/2,maxx,maxy/2,0);
 scrollok(top,1);
 scrollok(bottom,1);
  wborder(top, '|', '|', '=', '=', 0, 0, 0, 0);
 wborder(bottom, '|', '|', '-', '-', 0, 0, 0, 0);
  wsetscrreg(top,1,maxy/2-2);
  wsetscrreg(bottom,1,maxy/2-2);
 pthread_t threads[2];
 void *status;
 pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
     pthread_create(&threads[0], &attr, sendmessage, (void *)name);
     pthread_create(&threads[1], &attr, listener, ((void *)0));
     while(!done);
 close(sockfd);
 return 0;
}

canonical_original_code:
int client(int argc, char *argv[])
{
 printf("Podaj swoj username: ");
 scanf("%s",name);
 int portno; int n;
 struct sockaddr_in serv_addr;
 struct hostent *server;
 portno = atoi(argv[2]);
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  error("ERROR opening socket");
 server = gethostbyname(argv[1]);
 if (server == ((void *)0)) {
  fprintf(stderr, "ERROR, no such host\n");
  exit(0);
 }
 bzero((char *)&serv_addr, sizeof(serv_addr));
 serv_addr.sin_family = 2;
 bcopy((char *)server->h_addr_list[0],
  (char *)&serv_addr.sin_addr.s_addr,
  server->h_length);
 serv_addr.sin_port = htons(portno);
 if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
  error("ERROR connecting");
 initscr();
 (maxy = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), maxx = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 top = newwin(maxy/2,maxx,0,0);
 bottom= newwin(maxy/2,maxx,maxy/2,0);
 scrollok(top,1);
 scrollok(bottom,1);
  wborder(top, '|', '|', '=', '=', 0, 0, 0, 0);
 wborder(bottom, '|', '|', '-', '-', 0, 0, 0, 0);
  wsetscrreg(top,1,maxy/2-2);
  wsetscrreg(bottom,1,maxy/2-2);
 unsigned long threads[2];
 void *status;
 union pthread_attr_t attr;
 pthread_attr_init(&attr);
 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
     pthread_create(&threads[0], &attr, sendmessage, (void *)name);
     pthread_create(&threads[1], &attr, listener, ((void *)0));
     while(!done);
 close(sockfd);
 return 0;
}

variable_types: argc int

variable_types: portno int

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

variable_types:
threads
unsigned long [2]

variable_types:
status
void *

variable_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
void *__fastcall connection_handler(void *a1)
{
int i; // ebx
size_t v2; // rax
int v3; // eax

for ( i = *(_DWORD *)a1; ; write(i, client_message, v2) )
{
v3 = recv(i, client_message, 0x7D0uLL, 0);
if ( v3 <= 0 )
break;
v2 = strlen(client_message);
}
if ( v3 )
{
if ( v3 == -1 )
perror("Err RECV");
}
else
{
puts("Rozlaczono");
fflush(stdout);
}
free(a1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
int i; // ebx
size_t v2; // rax
int v3; // eax

for ( i = *(_DWORD *)a1; ; write(i, client_message, v2) )
{
v3 = recv(i, client_message, 0x7D0uLL, 0);
if ( v3 <= 0 )
break;
v2 = strlen(client_message);
}
if ( v3 )
{
if ( v3 == -1 )
perror("Err RECV");
}
else
{
puts("Rozlaczono");
fflush(stdout);
}
free(a1);
return 0LL;
}

original_code:
void *connection_handler(void *socket_desc)
{
    int sock = *(int*)socket_desc;
    int read_size;
    while( (read_size = recv(sock , client_message , 2000 , 0)) > 0 )
    {
        write(sock , client_message , strlen(client_message));
    }
    if(read_size == 0)
    {
        puts("Rozlaczono");
        fflush(stdout);
    }
    else if(read_size == -1)
    {
        perror("Err RECV");
    }
    free(socket_desc);
    return 0;
}

variable_types: sock int


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void error(const char *msg)
{
 perror(msg);
 exit(1);
}

canonical_original_code:
void error(char *msg)
{
 perror(msg);
 exit(1);
}

variable_types:
msg
char *


server

decompiled_code:
__int64 __fastcall server(int a1, __int64 a2)
{
int v2; // ebp
__int16 v3; // ax
unsigned int v4; // ebx
_DWORD *v5; // rax
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

if ( a1 <= 1 )
{
fwrite("ERROR, no port provided\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
v2 = socket(2, 1, 0);
if ( v2 < 0 )
perror("ERROR opening socket");
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v3 = atoi(*(const char **)(a2 + 8));
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v3);
if ( bind(v2, &addr, 0x10u) < 0 )
perror("ERROR on binding");
puts("\n Gotowy! ...");
listen(v2, 5);
addr_len[0] = 16;
while ( 1 )
{
v4 = accept(v2, &v8, addr_len);
if ( !v4 )
break;
puts("Polaczony");
v5 = malloc(1uLL);
*v5 = v4;
if ( pthread_create(&newthread, 0LL, connection_handler, v5) < 0 )
{
perror("Error with create_thread!");
return 1;
}
puts("Klient polaczony");
}
close(0);
close(v2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
int v2; // ebp
__int16 v3; // ax
unsigned int v4; // ebx
_DWORD *v5; // rax
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

if ( a1 <= 1 )
{
fwrite("ERROR, no port provided\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
v2 = socket(2, 1, 0);
if ( v2 < 0 )
perror("ERROR opening socket");
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v3 = atoi(*(const char **)(a2 + 8));
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(v3);
if ( bind(v2, &addr, 0x10u) < 0 )
perror("ERROR on binding");
puts("\n Gotowy! ...");
listen(v2, 5);
addr_len[0] = 16;
while ( 1 )
{
v4 = accept(v2, &v8, addr_len);
if ( !v4 )
break;
puts("Polaczony");
v5 = malloc(1uLL);
*v5 = v4;
if ( pthread_create(&newthread, 0LL, connection_handler, v5) < 0 )
{
perror("Error with create_thread!");
return 1;
}
puts("Klient polaczony");
}
close(0);
close(v2);
return v4;
}

original_code:
int server(int argc, char *argv[])
{
 int sockfd, newsockfd, portno, *new_sock;
 socklen_t clilen;
 char buffer[256];
 struct sockaddr_in serv_addr, cli_addr;
 int n;
 if (argc < 2) {
  fprintf(stderr, "ERROR, no port provided\n");
  exit(1);
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  perror("ERROR opening socket");
 bzero((char *)&serv_addr, sizeof(serv_addr));
 portno = atoi(argv[1]);
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 serv_addr.sin_port = htons(portno);
 if (bind(sockfd, (struct sockaddr *) &serv_addr,
  sizeof(serv_addr)) < 0)
  perror("ERROR on binding");
 printf("\n Gotowy! ...\n");
 listen(sockfd, 5);
 clilen = sizeof(cli_addr);
 while(newsockfd = accept(sockfd,
  (struct sockaddr *) &cli_addr,
  &clilen))
 {
  puts("Polaczony");
  pthread_t sniffer_thread;
  new_sock = malloc(1);
  *new_sock = newsockfd;
  if( pthread_create( &sniffer_thread , ((void *)0) , connection_handler , (void*) new_sock) < 0 )
  {
   perror("Error with create_thread!");
   return 1;
  }
  puts("Klient polaczony");
 }
 if (newsockfd < 0)
   error("ERROR on accept");
 close(newsockfd);
 close(sockfd);
 return 0;
}

canonical_original_code:
int server(int argc, char *argv[])
{
 int sockfd; int newsockfd; int portno; int *new_sock;
 unsigned int clilen;
 char buffer[256];
 struct sockaddr_in serv_addr; struct sockaddr_in cli_addr;
 int n;
 if (argc < 2) {
  fprintf(stderr, "ERROR, no port provided\n");
  exit(1);
 }
 sockfd = socket(2, SOCK_STREAM, 0);
 if (sockfd < 0)
  perror("ERROR opening socket");
 bzero((char *)&serv_addr, sizeof(serv_addr));
 portno = atoi(argv[1]);
 serv_addr.sin_family = 2;
 serv_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 serv_addr.sin_port = htons(portno);
 if (bind(sockfd, (struct sockaddr *) &serv_addr,
  sizeof(serv_addr)) < 0)
  perror("ERROR on binding");
 printf("\n Gotowy! ...\n");
 listen(sockfd, 5);
 clilen = sizeof(cli_addr);
 while(newsockfd = accept(sockfd,
  (struct sockaddr *) &cli_addr,
  &clilen))
 {
  puts("Polaczony");
  unsigned long sniffer_thread;
  new_sock = malloc(1);
  *new_sock = newsockfd;
  if( pthread_create( &sniffer_thread , ((void *)0) , connection_handler , (void *) new_sock) < 0 )
  {
   perror("Error with create_thread!");
   return 1;
  }
  puts("Klient polaczony");
 }
 if (newsockfd < 0)
   error("ERROR on accept");
 close(newsockfd);
 close(sockfd);
 return 0;
}

variable_types:
argv
char *[]

variable_types: sockfd int

variable_types: newsockfd int

variable_types:
clilen
unsigned int

variable_types:
buffer
char [256]

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

variable_types: n int


decompiled_code:
void *__fastcall sluchanie_client(void *a1)
{
int v1; // eax
const char *v2; // rdx

while ( 1 )
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 16 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 256) >> 3));
v1 = read(*(_DWORD *)a1, (char *)a1 + 16, 0xFFuLL);
*((_DWORD *)a1 + 3) = v1;
if ( v1 < 0 )
error((int)"ERROR reading from socket", (_DWORD)a1 + 16, v2);
if ( *((_WORD *)a1 + 8) == 25901 )
break;
printf("server: %s", (const char *)a1 + 16);
if ( *((int *)a1 + 3) <= 0 )
return 0LL;
}
puts("serwer rozlaczony\nBye");
pthread_cancel(*((_QWORD *)a1 + 35));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // eax
const char *v2; // rdx

while ( 1 )
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 16 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 256) >> 3));
v1 = read(*(_DWORD *)a1, (char *)a1 + 16, 0xFFuLL);
*((_DWORD *)a1 + 3) = v1;
if ( v1 < 0 )
error((int)"ERROR reading from socket", (_DWORD)a1 + 16, v2);
if ( *((_WORD *)a1 + 8) == 25901 )
break;
printf("server: %s", (const char *)a1 + 16);
if ( *((int *)a1 + 3) <= 0 )
return 0LL;
}
puts("serwer rozlaczony\nBye");
pthread_cancel(*((_QWORD *)a1 + 35));
return 0LL;
}

original_code:
void * sluchanie_client(void *arguments)
{
   struct ArgumentyProgramu *argumenty=arguments;
   do
  {
   bzero(argumenty->buffer,256);
   argumenty->n = read(argumenty->sockfd,argumenty->buffer,255);
   if (argumenty->n < 0) error("ERROR reading from socket");
   if((argumenty->buffer[0]=='-' && argumenty->buffer[1]=='e')==1)
      {
 printf("serwer rozlaczony\nBye\n");
 pthread_cancel(argumenty->wysylanie);
 return ((void *)0); }
   printf("server: %s",argumenty->buffer);
  }
    while(argumenty->n > 0 );
    return ((void *)0);
}

canonical_original_code:
void *sluchanie_client(void *arguments)
{
   struct ArgumentyProgramu *argumenty = arguments;
   do
  {
   bzero(argumenty->buffer,256);
   argumenty->n = read(argumenty->sockfd,argumenty->buffer,255);
   if (argumenty->n < 0) error("ERROR reading from socket");
   if((argumenty->buffer[0]=='-' && argumenty->buffer[1]=='e')==1)
      {
 printf("serwer rozlaczony\nBye\n");
 pthread_cancel(argumenty->wysylanie);
 return ((void *)0); }
   printf("server: %s",argumenty->buffer);
  }
    while(argumenty->n > 0 );
    return ((void *)0);
}

variable_types:
arguments
void *

variable_types: struct ArgumentyProgramu { int sockfd; int newsockfd; int portno; int n; char buffer[256]; unsigned long sluchanie; unsigned long wysylanie; } *


decompiled_code:
void *__fastcall wysylanie_client(void *a1)
{
while ( 1 )
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 16 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 256) >> 3));
fgets((char *)a1 + 16, 255, stdin);
if ( *((_WORD *)a1 + 8) == 25901 )
break;
*((_DWORD *)a1 + 3) = write(*(_DWORD *)a1, (char *)a1 + 16, 0xFFuLL);
if ( *((_WORD *)a1 + 8) == 25901 )
return 0LL;
}
*((_QWORD *)a1 + 8) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 72) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 72) & 0xFFFFFFF8) + 272) >> 3));
strcpy((char *)a1 + 16, "client rozlaczony wpisz -e aby rowniez sie rozlaczyc\n");
*((_DWORD *)a1 + 3) = write(*(_DWORD *)a1, (char *)a1 + 16, 0xFFuLL);
sleep(1u);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
while ( 1 )
{
*((_QWORD *)a1 + 2) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 24) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 16 - (((_DWORD)a1 + 24) & 0xFFFFFFF8) + 256) >> 3));
fgets((char *)a1 + 16, 255, stdin);
if ( *((_WORD *)a1 + 8) == 25901 )
break;
*((_DWORD *)a1 + 3) = write(*(_DWORD *)a1, (char *)a1 + 16, 0xFFuLL);
if ( *((_WORD *)a1 + 8) == 25901 )
return 0LL;
}
*((_QWORD *)a1 + 8) = 0LL;
*((_QWORD *)a1 + 33) = 0LL;
memset(
(void *)(((unsigned __int64)a1 + 72) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 72) & 0xFFFFFFF8) + 272) >> 3));
strcpy((char *)a1 + 16, "client rozlaczony wpisz -e aby rowniez sie rozlaczyc\n");
*((_DWORD *)a1 + 3) = write(*(_DWORD *)a1, (char *)a1 + 16, 0xFFuLL);
sleep(1u);
return 0LL;
}

original_code:
void * wysylanie_client(void *arguments)
{
  struct ArgumentyProgramu *argumenty1=arguments;
  do
  {
    bzero(argumenty1->buffer,256);
    fgets(argumenty1->buffer,255,stdin);
    if((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==1 )
    {
 bzero(argumenty1->buffer,256);
 strcpy(argumenty1->buffer,"client rozlaczony wpisz -e aby rowniez sie rozlaczyc\n");
 argumenty1->n = write(argumenty1->sockfd,argumenty1->buffer,255);
 sleep(1);
       return ((void *)0);
    }
    else {
     argumenty1->n = write(argumenty1->sockfd,argumenty1->buffer,255); }
  }
    while((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==0);
    return ((void *)0);
}

canonical_original_code:
void *wysylanie_client(void *arguments)
{
  struct ArgumentyProgramu *argumenty1 = arguments;
  do
  {
    bzero(argumenty1->buffer,256);
    fgets(argumenty1->buffer,255,stdin);
    if((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==1 )
    {
 bzero(argumenty1->buffer,256);
 strcpy(argumenty1->buffer,"client rozlaczony wpisz -e aby rowniez sie rozlaczyc\n");
 argumenty1->n = write(argumenty1->sockfd,argumenty1->buffer,255);
 sleep(1);
       return ((void *)0);
    }
    else {
     argumenty1->n = write(argumenty1->sockfd,argumenty1->buffer,255); }
  }
    while((argumenty1->buffer[0]=='-' && argumenty1->buffer[1]=='e')==0);
    return ((void *)0);
}

user_defined_types: struct ArgumentyProgramu { int sockfd; int newsockfd; int portno; int n; char buffer[256]; unsigned long sluchanie; unsigned long wysylanie; }


client

decompiled_code:
__int64 __fastcall client(int a1, const char *a2)
{
const char *v2; // rdx
struct hostent *v3; // rax
const char *v4; // rdx
__int64 result; // rax
struct sockaddr dest; // [rsp+0h] [rbp-138h] BYREF
int fd; // [rsp+10h] [rbp-128h] BYREF
int v8; // [rsp+18h] [rbp-120h]
pthread_t newthread; // [rsp+120h] [rbp-18h] BYREF
pthread_t th[2]; // [rsp+128h] [rbp-10h] BYREF

v8 = a1;
fd = socket(2, 1, 0);
if ( fd < 0 )
{
error((int)"ERROR opening socket", 1, v2);
result = 4LL;
}
else
{
v3 = gethostbyname(a2);
if ( !v3 )
{
fwrite("ERROR, no such host\n", 1uLL, 0x14uLL, stderr);
exit(0);
}
*(_QWORD *)&dest.sa_family = 2LL;
*(_QWORD *)&dest.sa_data[6] = 0LL;
memmove(&dest.sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)dest.sa_data = _bswap_16(v8);
if ( connect(fd, &dest, 0x10u) < 0 )
{
error((int)"ERROR connecting", (int)&dest, v4);
result = 6LL;
}
else
{
pthread_create(&newthread, 0LL, sluchanie_client, &fd);
pthread_create(th, 0LL, wysylanie_client, &fd);
pthread_join(th[0], 0LL);
pthread_cancel(newthread);
close(fd);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const char *a2)
{
const char *v2; // rdx
struct hostent *v3; // rax
const char *v4; // rdx
__int64 result; // rax
struct sockaddr dest; // [rsp+0h] [rbp-138h] BYREF
int fd; // [rsp+10h] [rbp-128h] BYREF
int v8; // [rsp+18h] [rbp-120h]
pthread_t newthread; // [rsp+120h] [rbp-18h] BYREF
pthread_t th[2]; // [rsp+128h] [rbp-10h] BYREF

v8 = a1;
fd = socket(2, 1, 0);
if ( fd < 0 )
{
error((int)"ERROR opening socket", 1, v2);
result = 4LL;
}
else
{
v3 = gethostbyname(a2);
if ( !v3 )
{
fwrite("ERROR, no such host\n", 1uLL, 0x14uLL, stderr);
exit(0);
}
*(_QWORD *)&dest.sa_family = 2LL;
*(_QWORD *)&dest.sa_data[6] = 0LL;
memmove(&dest.sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)dest.sa_data = func2(v8);
if ( connect(fd, &dest, 0x10u) < 0 )
{
error((int)"ERROR connecting", (int)&dest, v4);
result = 6LL;
}
else
{
pthread_create(&newthread, 0LL, sluchanie_client, &fd);
pthread_create(th, 0LL, wysylanie_client, &fd);
pthread_join(th[0], 0LL);
pthread_cancel(newthread);
close(fd);
result = 0LL;
}
}
return result;
}

original_code:
int client(int portno,char host[] )
{
    struct ArgumentyProgramu argumenty;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    argumenty.portno = portno;
    argumenty.sockfd = socket(2, SOCK_STREAM, 0);
    if (argumenty.sockfd < 0)
    {
        error("ERROR opening socket");
 return 4;
    }
    server = gethostbyname(host);
    if (server == ((void *)0)) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    bcopy((char *)server->h_addr_list[0],
         (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
    serv_addr.sin_port = htons(argumenty.portno);
    if (connect(argumenty.sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
    {
        error("ERROR connecting");
 return 6;
    }
   pthread_create(&argumenty.sluchanie,((void *)0),&sluchanie_client,(void*)&argumenty);
   pthread_create(&argumenty.wysylanie,((void *)0),&wysylanie_client,(void*)&argumenty);
   pthread_join(argumenty.wysylanie, ((void *)0));
   pthread_cancel(argumenty.sluchanie);
   close(argumenty.sockfd);
   return 0;
}

canonical_original_code:
int client(int portno, char host[])
{
    struct ArgumentyProgramu argumenty;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    argumenty.portno = portno;
    argumenty.sockfd = socket(2, SOCK_STREAM, 0);
    if (argumenty.sockfd < 0)
    {
        error("ERROR opening socket");
 return 4;
    }
    server = gethostbyname(host);
    if (server == ((void *)0)) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    bcopy((char *)server->h_addr_list[0],
         (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
    serv_addr.sin_port = htons(argumenty.portno);
    if (connect(argumenty.sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
    {
        error("ERROR connecting");
 return 6;
    }
   pthread_create(&argumenty.sluchanie,((void *)0),&sluchanie_client,(void *)&argumenty);
   pthread_create(&argumenty.wysylanie,((void *)0),&wysylanie_client,(void *)&argumenty);
   pthread_join(argumenty.wysylanie, ((void *)0));
   pthread_cancel(argumenty.sluchanie);
   close(argumenty.sockfd);
   return 0;
}

variable_types:
host
char []

variable_types: struct ArgumentyProgramu { int sockfd; int newsockfd; int portno; int n; char buffer[256]; unsigned long sluchanie; unsigned long wysylanie; }

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


repo: AlertProject/CCCC

decompiled_code:
void __fastcall r_intersect(__int64 a1, __int64 *a2)
{
__int64 v3; // rax
void *v4; // rdx
void *v5; // r12
__int64 v6; // r13
void *v7; // rdi

if ( a1 && *(_DWORD *)(a1 + 4) != operation_no )
{
*(_DWORD *)(a1 + 4) = operation_no;
v3 = set_and(*(unsigned int *)a2, a2[1], *(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40));
v5 = v4;
v6 = v3;
if ( (unsigned int)set_nil((unsigned int)v3, v4) )
{
if ( v5 )
free(v5);
}
else
{
v7 = (void *)a2[1];
if ( v7 )
free(v7);
*a2 = v6;
a2[1] = (__int64)v5;
}
r_intersect(*(_QWORD *)(a1 + 16), a2);
r_intersect(*(_QWORD *)(a1 + 24), a2);
}
}

original_code:
void r_intersect(struct _nfa_node* start,set* maximal_class)
{
 set temp;
 if(start && start->nfa_set != operation_no)
 {
  start->nfa_set = operation_no;
  temp = set_and(*maximal_class,start->label);
  if (!set_nil(temp))
  {
   {if ( (*maximal_class).setword != ((void *)0) ) free((char *)((*maximal_class).setword)); (*maximal_class) = empty;};
   *maximal_class = temp;
  }else{
   {if ( (temp).setword != ((void *)0) ) free((char *)((temp).setword)); (temp) = empty;};
  }
  r_intersect(start->trans[0],maximal_class);
  r_intersect(start->trans[1],maximal_class);
 }
}

canonical_original_code:
void r_intersect(struct _nfa_node *start, struct _set *maximal_class)
{
 struct _set temp;
 if(start && start->nfa_set != operation_no)
 {
  start->nfa_set = operation_no;
  temp = set_and(*maximal_class,start->label);
  if (!set_nil(temp))
  {
   {if ( (*maximal_class).setword != ((void *)0) ) free((char *)((*maximal_class).setword)); (*maximal_class) = empty;};
   *maximal_class = temp;
  }else{
   {if ( (temp).setword != ((void *)0) ) free((char *)((temp).setword)); (temp) = empty;};
  }
  r_intersect(start->trans[0],maximal_class);
  r_intersect(start->trans[1],maximal_class);
 }
}

variable_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set { unsigned int n; unsigned int *setword; } label; } *

user_defined_types: struct _nfa_node { int node_no; int nfa_set; int accept; struct _nfa_node *trans[2]; struct _set label; }


decompiled_code:
void __fastcall intersect_nfa_labels(__int64 a1, __int64 *a2)
{
++operation_no;
r_intersect(a1, a2);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 *a2)
{
++operation_no;
func0(a1, a2);
}

original_code:
void intersect_nfa_labels(struct _nfa_node* start,set* maximal_class)
{
 ++operation_no;
 r_intersect(start,maximal_class);
}

canonical_original_code:
void intersect_nfa_labels(struct _nfa_node *start, struct _set *maximal_class)
{
 ++operation_no;
 r_intersect(start,maximal_class);
}

user_defined_types: struct _set { unsigned int n; unsigned int *setword; }


partition

decompiled_code:
void __fastcall partition(__int64 a1, int a2)
{
unsigned int v2; // ebx
void *v3; // rdx
void *v4; // rbp
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rdx
int v8; // edx
__int64 v9; // rax
unsigned int v10; // eax
void *v11; // rdx
void *v12; // r12
__m128i v13; // [rsp+0h] [rbp-38h] BYREF

v2 = set_dup(used_chars, *((_QWORD *)&used_chars + 1));
v4 = v3;
class_no = 0;
while ( !(unsigned int)set_nil(v2, v4) )
{
if ( a2 <= 1 )
{
v5 = set_int(v2, v4);
v13.m128i_i32[0] = set_of(v5);
v13.m128i_i64[1] = v6;
}
else
{
v13.m128i_i32[0] = set_dup(v2, v4);
v13.m128i_i64[1] = v7;
intersect_nfa_labels(a1, v13.m128i_i64);
}
((void (__fastcall *)(_QWORD, void *))set_orel)((unsigned int)class_no, &used_classes);
v8 = set_int(v13.m128i_u32[0], v13.m128i_i64[1]);
v9 = class_no;
first_el[class_no] = v8;
class_sets[v9] = (__int128)_mm_loadu_si128(&v13);
v10 = set_dif(v2, v4, v13.m128i_u32[0], v13.m128i_i64[1]);
v12 = v11;
v2 = v10;
if ( v4 )
free(v4);
++class_no;
v4 = v12;
}
if ( v4 )
free(v4);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // ebx
void *v3; // rdx
void *v4; // rbp
unsigned int v5; // eax
__int64 v6; // rdx
__int64 v7; // rdx
int v8; // edx
__int64 v9; // rax
unsigned int v10; // eax
void *v11; // rdx
void *v12; // r12
__m128i v13; // [rsp+0h] [rbp-38h] BYREF

v2 = set_dup(used_chars, *((_QWORD *)&used_chars + 1));
v4 = v3;
class_no = 0;
while ( !(unsigned int)set_nil(v2, v4) )
{
if ( a2 <= 1 )
{
v5 = set_int(v2, v4);
v13.m128i_i32[0] = set_of(v5);
v13.m128i_i64[1] = v6;
}
else
{
v13.m128i_i32[0] = set_dup(v2, v4);
v13.m128i_i64[1] = v7;
func1(a1, v13.m128i_i64);
}
((void (__fastcall *)(_QWORD, void *))set_orel)((unsigned int)class_no, &used_classes);
v8 = set_int(v13.m128i_u32[0], v13.m128i_i64[1]);
v9 = class_no;
first_el[class_no] = v8;
class_sets[v9] = (__int128)_mm_loadu_si128(&v13);
v10 = set_dif(v2, v4, v13.m128i_u32[0], v13.m128i_i64[1]);
v12 = v11;
v2 = v10;
if ( v4 )
free(v4);
++class_no;
v4 = v12;
}
if ( v4 )
free(v4);
}

original_code:
void partition(struct _nfa_node* start,int level)
{
 set current_class;
 set unpart_chars;
 set temp;
 unpart_chars = set_dup(used_chars);
 class_no = 0;
 while (!set_nil(unpart_chars)){
  if (level <= 1){
   current_class = set_of(set_int(unpart_chars));
  }else{
   current_class = set_dup(unpart_chars);
   intersect_nfa_labels(start,&current_class);
  }
  set_orel(class_no,&used_classes);
  first_el[class_no] = set_int(current_class);
  class_sets[class_no] = current_class;
  temp = set_dif(unpart_chars,current_class);
  {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
  unpart_chars = temp;
  ++class_no;
 }
 {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
}

canonical_original_code:
void partition(struct _nfa_node *start, int level)
{
 struct _set current_class;
 struct _set unpart_chars;
 struct _set temp;
 unpart_chars = set_dup(used_chars);
 class_no = 0;
 while (!set_nil(unpart_chars)){
  if (level <= 1){
   current_class = set_of(set_int(unpart_chars));
  }else{
   current_class = set_dup(unpart_chars);
   intersect_nfa_labels(start,&current_class);
  }
  set_orel(class_no,&used_classes);
  first_el[class_no] = set_int(current_class);
  class_sets[class_no] = current_class;
  temp = set_dif(unpart_chars,current_class);
  {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
  unpart_chars = temp;
  ++class_no;
 }
 {if ( (unpart_chars).setword != ((void *)0) ) free((char *)((unpart_chars).setword)); (unpart_chars) = empty;};
}

variable_types: level int

variable_types: struct _set { unsigned int n; unsigned int *setword; }


decompiled_code:
void __fastcall label_node(__int64 a1)
{
__int64 v2; // rbx
void *v3; // rdi
__m128i v4[2]; // [rsp+0h] [rbp-28h] BYREF

if ( a1 && *(_DWORD *)(a1 + 4) != operation_no )
{
*(_DWORD *)(a1 + 4) = operation_no;
v4[0] = _mm_loadu_si128(&empty);
if ( class_no > 0 )
{
v2 = 0LL;
do
{
if ( (unsigned int)set_el((unsigned int)first_el[v2], *(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40)) )
((void (__fastcall *)(_QWORD, __m128i *))set_orel)((unsigned int)v2, v4);
++v2;
}
while ( class_no > (int)v2 );
}
v3 = *(void **)(a1 + 40);
if ( v3 )
free(v3);
*(__m128i *)(a1 + 32) = _mm_loadu_si128(v4);
label_node(*(_QWORD *)(a1 + 16));
label_node(*(_QWORD *)(a1 + 24));
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v2; // rbx
void *v3; // rdi
__m128i v4[2]; // [rsp+0h] [rbp-28h] BYREF

if ( a1 && *(_DWORD *)(a1 + 4) != operation_no )
{
*(_DWORD *)(a1 + 4) = operation_no;
v4[0] = _mm_loadu_si128(&empty);
if ( class_no > 0 )
{
v2 = 0LL;
do
{
if ( (unsigned int)set_el((unsigned int)first_el[v2], *(unsigned int *)(a1 + 32), *(_QWORD *)(a1 + 40)) )
((void (__fastcall *)(_QWORD, __m128i *))set_orel)((unsigned int)v2, v4);
++v2;
}
while ( class_no > (int)v2 );
}
v3 = *(void **)(a1 + 40);
if ( v3 )
free(v3);
*(__m128i *)(a1 + 32) = _mm_loadu_si128(v4);
func3(*(_QWORD *)(a1 + 16));
func3(*(_QWORD *)(a1 + 24));
}
}

original_code:
void label_node(struct _nfa_node *start)
{
 set new_label;
 register int i;
 if (start && start->nfa_set != operation_no){
  start->nfa_set = operation_no;
  new_label = empty;
  for (i = 0; i<class_no; ++i){
   if (set_el(first_el[i],start->label))
    set_orel(i,&new_label);
  }
  {if ( (start->label).setword != ((void *)0) ) free((char *)((start->label).setword)); (start->label) = empty;};
  start->label = new_label;
  label_node(start->trans[0]);
  label_node(start->trans[1]);
 }
}

canonical_original_code:
void label_node(struct _nfa_node *start)
{
 struct _set new_label;
 register int i;
 if (start && start->nfa_set != operation_no){
  start->nfa_set = operation_no;
  new_label = empty;
  for (i = 0; i<class_no; ++i){
   if (set_el(first_el[i],start->label))
    set_orel(i,&new_label);
  }
  {if ( (start->label).setword != ((void *)0) ) free((char *)((start->label).setword)); (start->label) = empty;};
  start->label = new_label;
  label_node(start->trans[0]);
  label_node(start->trans[1]);
 }
}

variable_types: i int


decompiled_code:
void __fastcall label_with_classes(__int64 a1)
{
++operation_no;
label_node(a1);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
++operation_no;
func3(a1);
}

original_code:
void label_with_classes(struct _nfa_node* start)
{
 ++operation_no;
 label_node(start);
}

canonical_original_code:
void label_with_classes(struct _nfa_node *start)
{
 ++operation_no;
 label_node(start);
}


relabel

decompiled_code:
__int64 __fastcall relabel(__int64 a1, int a2)
{
void *v3; // rdi
__int64 result; // rax

if ( a2 )
{
v3 = (void *)*((_QWORD *)&used_classes + 1);
if ( v3 )
free(v3);
used_classes = _mm_loadu_si128(&empty);
partition(a1, a2);
label_with_classes(a1);
result = (unsigned int)class_no;
}
else
{
class_no = 257;
result = 257LL;
}
return result;
}

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

if ( a2 )
{
v3 = (void *)*((_QWORD *)&used_classes + 1);
if ( v3 )
free(v3);
used_classes = _mm_loadu_si128(&empty);
func2(a1, a2);
func4(a1);
result = (unsigned int)class_no;
}
else
{
class_no = 257;
result = 257LL;
}
return result;
}

original_code:
int relabel(struct _nfa_node* start,int level)
{
 if (level){
  {if ( (used_classes).setword != ((void *)0) ) free((char *)((used_classes).setword)); (used_classes) = empty;};
  partition(start,level);
  label_with_classes(start);
 }else{
  class_no = (1+(255) - ((-1)));
 }
 return class_no;
}

canonical_original_code:
int relabel(struct _nfa_node *start, int level)
{
 if (level){
  {if ( (used_classes).setword != ((void *)0) ) free((char *)((used_classes).setword)); (used_classes) = empty;};
  partition(start,level);
  label_with_classes(start);
 }else{
  class_no = (1+(255) - ((-1)));
 }
 return class_no;
}


decompiled_code:
void p_comp0()
{
comp_level = 0;
}

canonical_decompiled_code:
void func0()
{
comp_level = 0;
}

original_code: void p_comp0(void) {comp_level = 0;}

canonical_original_code: void p_comp0() {comp_level = 0;}


decompiled_code:
void p_comp1()
{
comp_level = 1;
}

canonical_decompiled_code:
void func1()
{
comp_level = 1;
}

original_code: void p_comp1(void) {comp_level = 1;}

canonical_original_code: void p_comp1() {comp_level = 1;}


decompiled_code:
void p_comp2()
{
comp_level = 2;
}

canonical_decompiled_code:
void func2()
{
comp_level = 2;
}

original_code: void p_comp2(void) {comp_level = 2;}

canonical_original_code: void p_comp2() {comp_level = 2;}


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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = 0LL;
return result;
}

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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = 0LL;
return result;
}

original_code: void p_stdio(void) { file_str[numfiles++] = ((void *)0);}

canonical_original_code: void p_stdio() { file_str[numfiles++] = ((void *)0);}


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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = a1;
return result;
}

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

LODWORD(result) = numfiles++;
result = (int)result;
file_str[(int)result] = a1;
return result;
}

original_code: void p_file(char *s) { file_str[numfiles++] = s;}

variable_types:
s
char *


decompiled_code:
void __fastcall p_mode_file(__int64 a1, char *a2)
{
mode_file = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, char *a2)
{
mode_file = a2;
}

original_code: void p_mode_file(char *s, char *t){mode_file=t;}

variable_types:
t
char *


decompiled_code:
void __fastcall p_outdir(__int64 a1, char *a2)
{
OutputDirectory[0] = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, char *a2)
{
OutputDirectory[0] = a2;
}

original_code: void p_outdir(char *s,char *t) {OutputDirectory=t;}

canonical_original_code: void p_outdir(char *s, char *t) {OutputDirectory=t;}


decompiled_code:
void p_ansi()
{
gen_ansi = 1;
}

canonical_decompiled_code:
void func7()
{
gen_ansi = 1;
}

original_code: void p_ansi(void) {gen_ansi = 1;}

canonical_original_code: void p_ansi() {gen_ansi = 1;}


decompiled_code:
void p_interactive()
{
interactive = 1;
}

canonical_decompiled_code:
void func8()
{
interactive = 1;
}

original_code: void p_interactive(void) {interactive = 1;}

canonical_original_code: void p_interactive() {interactive = 1;}


decompiled_code:
void p_case_s()
{
case_insensitive = 0;
}

canonical_decompiled_code:
void func9()
{
case_insensitive = 0;
}

original_code: void p_case_s(void) { case_insensitive = 0; }


decompiled_code:
void p_case_i()
{
case_insensitive = 1;
}

canonical_decompiled_code:
void func10()
{
case_insensitive = 1;
}

original_code: void p_case_i(void) { case_insensitive = 1; }


decompiled_code:
void p_warn_ambig()
{
warn_ambig = 1;
}

canonical_decompiled_code:
void func11()
{
warn_ambig = 1;
}

original_code: void p_warn_ambig(void) { warn_ambig = 1; }

canonical_original_code: void p_warn_ambig() { warn_ambig = 1; }


decompiled_code:
void p_cpp()
{
gen_cpp = 1;
}

canonical_decompiled_code:
void func12()
{
gen_cpp = 1;
}

original_code: void p_cpp(void) { gen_cpp = 1; }

canonical_original_code: void p_cpp() { gen_cpp = 1; }


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

if ( !gen_cpp )
return warning("-cl only valid in C++ mode; -cl ignored...", 0LL);
class_name[0] = a2;
return result;
}

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

if ( !gen_cpp )
return warning("-cl only valid in C++ mode; -cl ignored...", 0LL);
class_name[0] = a2;
return result;
}

original_code:
void p_cl_name(char *s, char *t)
 {
  if ( gen_cpp ) {
   class_name = t;
  }
  else {
   warning("-cl only valid in C++ mode; -cl ignored...",0);
  }
 }


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
int v5; // ebx
int v6; // eax
const char *v7; // rdx
char **v8; // rbx
const char *v9; // rcx
int v10; // eax
void *v11; // rdi

init(argc, argv, envp);
fprintf(stderr, "%s Version %s 1989-1999\n", program, version);
if ( argc == 1 )
{
fprintf(stderr, "%s [options] f1 f2 ... fn\n", *argv);
v7 = options;
if ( *options != 42 )
{
v8 = &options;
do
{
v9 = " ";
if ( *((_DWORD *)v8 + 2) )
v9 = "___";
fprintf(stderr, "\t%s %s\t%s\n", v7, v9, v8[3]);
v8 += 4;
v7 = *v8;
}
while ( **v8 != 42 );
}
}
else
{
ProcessArgs(argc - 1, (char **)argv + 1, (unsigned __int8 **)&options);
if ( interactive && gen_cpp )
{
fputc(10, stderr);
fwrite("Interactive lexer option (\"-i\") has no effect when in C++ mode\n", 1uLL, 0x3FuLL, stderr);
fwrite("because of extra buffering provided by ANTLRTokenBuffer class.\n", 1uLL, 0x3FuLL, stderr);
fputc(10, stderr);
}
input_stream = read_stream(file_str[0]);
if ( input_stream )
{
if ( gen_cpp )
{
v3 = ClassName(".cpp");
output_stream = (FILE *)write_stream(v3);
if ( file_str[1] )
warning("output file implicit in C++ mode; ignored...", 0LL);
v4 = ClassName(".h");
class_stream = (FILE *)write_stream(v4);
mode_stream = class_stream;
}
else
{
output_stream = (FILE *)write_stream(file_str[1]);
mode_stream = (FILE *)write_stream(mode_file);
}
if ( input_stream )
{
if ( output_stream )
{
if ( mode_stream )
{
zzbufsize = 2000;
zzlextext = &zztoktext_0;
zzrdstream();
zzgettok();
v5 = zzasp;
grammar();
v6 = zzasp;
if ( v5 > zzasp )
{
do
{
v11 = (void *)zzaStack[5 * v6 + 4];
if ( v11 )
free(v11);
v10 = zzasp;
*(__m128i *)&zzaStack[5 * zzasp + 3] = _mm_loadu_si128((const __m128i *)empty);
v6 = v10 + 1;
zzasp = v6;
}
while ( v5 > v6 );
}
}
}
}
}
p_class_def2();
}
if ( output_stream )
fclose(output_stream);
if ( !gen_cpp && mode_stream )
fclose(mode_stream);
if ( class_stream )
fclose(class_stream);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
int v5; // ebx
int v6; // eax
const char *v7; // rdx
char **v8; // rbx
const char *v9; // rcx
int v10; // eax
void *v11; // rdi

func16(argc, argv, envp);
fprintf(stderr, "%s Version %s 1989-1999\n", program, version);
if ( argc == 1 )
{
fprintf(stderr, "%s [options] f1 f2 ... fn\n", *argv);
v7 = options;
if ( *options != 42 )
{
v8 = &options;
do
{
v9 = " ";
if ( *((_DWORD *)v8 + 2) )
v9 = "___";
fprintf(stderr, "\t%s %s\t%s\n", v7, v9, v8[3]);
v8 += 4;
v7 = *v8;
}
while ( **v8 != 42 );
}
}
else
{
func15(argc - 1, (char **)argv + 1, (unsigned __int8 **)&options);
if ( interactive && gen_cpp )
{
fputc(10, stderr);
fwrite("Interactive lexer option (\"-i\") has no effect when in C++ mode\n", 1uLL, 0x3FuLL, stderr);
fwrite("because of extra buffering provided by ANTLRTokenBuffer class.\n", 1uLL, 0x3FuLL, stderr);
fputc(10, stderr);
}
input_stream = read_stream(file_str[0]);
if ( input_stream )
{
if ( gen_cpp )
{
v3 = ClassName(".cpp");
output_stream = (FILE *)write_stream(v3);
if ( file_str[1] )
warning("output file implicit in C++ mode; ignored...", 0LL);
v4 = ClassName(".h");
class_stream = (FILE *)write_stream(v4);
mode_stream = class_stream;
}
else
{
output_stream = (FILE *)write_stream(file_str[1]);
mode_stream = (FILE *)write_stream(mode_file);
}
if ( input_stream )
{
if ( output_stream )
{
if ( mode_stream )
{
zzbufsize = 2000;
zzlextext = &zztoktext_0;
zzrdstream();
zzgettok();
v5 = zzasp;
grammar();
v6 = zzasp;
if ( v5 > zzasp )
{
do
{
v11 = (void *)zzaStack[5 * v6 + 4];
if ( v11 )
free(v11);
v10 = zzasp;
*(__m128i *)&zzaStack[5 * zzasp + 3] = _mm_loadu_si128((const __m128i *)empty);
v6 = v10 + 1;
zzasp = v6;
}
while ( v5 > v6 );
}
}
}
}
}
p_class_def2();
}
if ( output_stream )
fclose(output_stream);
if ( !gen_cpp && mode_stream )
fclose(mode_stream);
if ( class_stream )
fclose(class_stream);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
 init();
 fprintf(stderr, "%s  Version %s   1989-1999\n", &(program[0]),
  &(version[0]));
 if ( argc == 1 )
 {
  Opt *p = options;
  fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);
  while ( *(p->option) != '*' )
  {
   fprintf(stderr, "\t%s %s\t%s\n",
       p->option,
       (p->arg)?"___":"   ",
       p->descr);
   p++;
  }
 }else{
  ProcessArgs(argc-1, &(argv[1]), options);
  if (interactive && gen_cpp) {
   fprintf(stderr,"\n");
   fprintf(stderr,"Interactive lexer option (\"-i\") has no effect when in C++ mode\n");
   fprintf(stderr,"because of extra buffering provided by ANTLRTokenBuffer class.\n");
   fprintf(stderr,"\n");
  }
  input_stream = read_stream(file_str[0]);
  if (input_stream) {
   if ( gen_cpp ) {
    output_stream = write_stream(ClassName(".cpp"));
    if ( file_str[1]!=((void *)0) ) {
     warning("output file implicit in C++ mode; ignored...",0);
    }
    class_stream = write_stream(ClassName(".h"));
    mode_stream = class_stream;
   }
   else {
    output_stream = write_stream(file_str[1]);
    mode_stream = write_stream(mode_file);
   }
  }
  if (input_stream && output_stream && mode_stream){
   zzbufsize = 2000; {static char zztoktext[2000]; zzlextext = zztoktext; zzrdstream( input_stream ); zzgettok();}; { int zztasp1 = zzasp - 1; grammar(); for (; zzasp<(zztasp1 + 1); zzasp++) { {if ( ((&(zzaStack[zzasp]))->label).setword != ((void *)0) ) free((char *)(((&(zzaStack[zzasp]))->label).setword)); ((&(zzaStack[zzasp]))->label) = empty;};; }; } ;;
  }
  p_class_def2();
 }
 if ( output_stream!=((void *)0) ) fclose(output_stream);
 if ( !gen_cpp && mode_stream!=((void *)0) ) fclose(mode_stream);
 if ( class_stream!=((void *)0) ) fclose(class_stream);
 exit(0);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 init();
 fprintf(stderr, "%s  Version %s   1989-1999\n", &(program[0]),
  &(version[0]));
 if ( argc == 1 )
 {
  struct Opt *p = options;
  fprintf(stderr, "%s [options] f1 f2 ... fn\n",argv[0]);
  while ( *(p->option) != '*' )
  {
   fprintf(stderr, "\t%s %s\t%s\n",
       p->option,
       (p->arg)?"___":"   ",
       p->descr);
   p++;
  }
 }else{
  ProcessArgs(argc-1, &(argv[1]), options);
  if (interactive && gen_cpp) {
   fprintf(stderr,"\n");
   fprintf(stderr,"Interactive lexer option (\"-i\") has no effect when in C++ mode\n");
   fprintf(stderr,"because of extra buffering provided by ANTLRTokenBuffer class.\n");
   fprintf(stderr,"\n");
  }
  input_stream = read_stream(file_str[0]);
  if (input_stream) {
   if ( gen_cpp ) {
    output_stream = write_stream(ClassName(".cpp"));
    if ( file_str[1]!=((void *)0) ) {
     warning("output file implicit in C++ mode; ignored...",0);
    }
    class_stream = write_stream(ClassName(".h"));
    mode_stream = class_stream;
   }
   else {
    output_stream = write_stream(file_str[1]);
    mode_stream = write_stream(mode_file);
   }
  }
  if (input_stream && output_stream && mode_stream){
   zzbufsize = 2000; {static char zztoktext[2000]; zzlextext = zztoktext; zzrdstream( input_stream ); zzgettok();}; { int zztasp1 = zzasp - 1; grammar(); for (; zzasp<(zztasp1 + 1); zzasp++) { {if ( ((&(zzaStack[zzasp]))->label).setword != ((void *)0) ) free((char *)(((&(zzaStack[zzasp]))->label).setword)); ((&(zzaStack[zzasp]))->label) = empty;};; }; } ;;
  }
  p_class_def2();
 }
 if ( output_stream!=((void *)0) ) fclose(output_stream);
 if ( !gen_cpp && mode_stream!=((void *)0) ) fclose(mode_stream);
 if ( class_stream!=((void *)0) ) fclose(class_stream);
 exit(0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct Opt { char *option; int arg; void (*process)(); char *descr; } *

variable_types:
zztoktext
char [2000]


decompiled_code:
__int64 new_automaton_mode()
{
void *v0; // rdi

v0 = (void *)used_chars.m128i_i64[1];
if ( v0 )
free(v0);
used_chars = _mm_loadu_si128((const __m128i *)empty);
return clear_hash();
}

canonical_decompiled_code:
__int64 func17()
{
void *v0; // rdi

v0 = (void *)used_chars.m128i_i64[1];
if ( v0 )
free(v0);
used_chars = _mm_loadu_si128((const __m128i *)empty);
return clear_hash();
}

original_code:
void
new_automaton_mode(void)
{
 {if ( (used_chars).setword != ((void *)0) ) free((char *)((used_chars).setword)); (used_chars) = empty;};
 clear_hash();
}

canonical_original_code:
void new_automaton_mode()
{
 {if ( (used_chars).setword != ((void *)0) ) free((char *)((used_chars).setword)); (used_chars) = empty;};
 clear_hash();
}


decompiled_code:
_BOOL8 __fastcall ci_strequ(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // r13
unsigned __int8 i; // bl
char v5; // bp
const __int32_t **v6; // rax

v2 = a1;
for ( i = *a1; *v2; i = *v2 )
{
v5 = *a2;
if ( !*a2 )
break;
v6 = _ctype_toupper_loc();
if ( (*v6)[v5] != (*v6)[(char)i] )
return 0LL;
++v2;
++a2;
}
return *a2 == (char)i;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(unsigned __int8 *a1, char *a2)
{
unsigned __int8 *v2; // r13
unsigned __int8 i; // bl
char v5; // bp
const __int32_t **v6; // rax

v2 = a1;
for ( i = *a1; *v2; i = *v2 )
{
v5 = *a2;
if ( !*a2 )
break;
v6 = _ctype_toupper_loc();
if ( (*v6)[v5] != (*v6)[(char)i] )
return 0LL;
++v2;
++a2;
}
return *a2 == (char)i;
}

original_code:
static int ci_strequ(char *a,char *b)
{
  for ( ;*a != 0 && *b != 0; a++, b++) {
    if (toupper(*a) != toupper(*b)) return 0;
  }
  return (*a == *b);
}

canonical_original_code:
static int ci_strequ(char *a, char *b)
{
  for ( ;*a != 0 && *b != 0; a++, b++) {
    if (toupper(*a) != toupper(*b)) return 0;
  }
  return (*a == *b);
}

variable_types:
a
char *

variable_types:
b
char *


ProcessArgs

original_code:
void ProcessArgs(int argc, char **argv, Opt *options)
{
 Opt *p;
 while ( argc-- > 0 )
 {
  p = options;
  while ( p->option != ((void *)0) )
  {
   if ( strcmp(p->option, "*") == 0 ||
     ci_strequ(p->option,*argv) )
   {
    if ( p->arg )
    {
     (*p->process)( *argv, *(argv+1) );
     argv++;
     argc--;
    }
    else
     (*p->process)( *argv );
    break;
   }
   p++;
  }
  argv++;
 }
}

canonical_original_code:
void ProcessArgs(int argc, char **argv, struct Opt *options)
{
 struct Opt *p;
 while ( argc-- > 0 )
 {
  p = options;
  while ( p->option != ((void *)0) )
  {
   if ( strcmp(p->option, "*") == 0 ||
     ci_strequ(p->option,*argv) )
   {
    if ( p->arg )
    {
     (*p->process)( *argv, *(argv+1) );
     argv++;
     argc--;
    }
    else
     (*p->process)( *argv );
    break;
   }
   p++;
  }
  argv++;
 }
}

variable_types:
argv
char **

user_defined_types: struct Opt { char *option; int arg; void (*process)(); char *descr; }


init

decompiled_code:
__int64 init()
{
void *v0; // rax
void *v1; // rdx
unsigned int i; // ebx
__int64 result; // rax

v0 = (void *)empty[0];
v1 = (void *)empty[1];
used_chars[0] = empty[0];
used_chars[1] = v1;
used_classes = v0;
*(&used_classes + 1) = v1;
normal_chars[0] = v0;
normal_chars[1] = v1;
for ( i = 1; i != 257; ++i )
set_orel(i, normal_chars);
make_nfa_model_node();
result = clear_hash();
func_action = 0;
return result;
}

canonical_decompiled_code:
__int64 func16()
{
void *v0; // rax
void *v1; // rdx
unsigned int i; // ebx
__int64 result; // rax

v0 = (void *)empty[0];
v1 = (void *)empty[1];
used_chars[0] = empty[0];
used_chars[1] = v1;
used_classes = v0;
*(&used_classes + 1) = v1;
normal_chars[0] = v0;
normal_chars[1] = v1;
for ( i = 1; i != 257; ++i )
set_orel(i, normal_chars);
make_nfa_model_node();
result = clear_hash();
func_action = 0;
return result;
}

original_code:
void
init(void)
{
 register int i;
 used_chars = empty;
 used_classes = empty;
 normal_chars = empty;
 for (i = 1; i<(1+(255) - ((-1))); ++i){
  set_orel(i,&normal_chars);
 }
 make_nfa_model_node();
 clear_hash();
    func_action = 0;
}

canonical_original_code:
void init()
{
 register int i;
 used_chars = empty;
 used_classes = empty;
 normal_chars = empty;
 for (i = 1; i<(1+(255) - ((-1))); ++i){
  set_orel(i,&normal_chars);
 }
 make_nfa_model_node();
 clear_hash();
    func_action = 0;
}