decompiled_code:
int __fastcall WAON_notes_output_midi(unsigned int *a1, const char *a2, double a3)
{
size_t v5; // rax
unsigned __int64 v6; // rcx
int v7; // er15
__int64 v9; // rbp
unsigned int v10; // er14
unsigned int v11; // er12
__int64 v12; // r13
int v13; // [rsp+8h] [rbp-50h]
int v14; // [rsp+14h] [rbp-44h]
int v15; // [rsp+1Ch] [rbp-3Ch]

fprintf(stderr, "WAON_notes : n = %d\n", *a1);
fprintf(stderr, "filename : %s\n", a2);
v5 = strlen(a2);
v6 = 2LL;
if ( v5 <= 2 )
v6 = v5;
if ( !memcmp(a2, "-", v6) )
{
v7 = dup(1);
v14 = 1;
}
else
{
v7 = open(a2, 578, 384LL);
v14 = 0;
}
if ( v7 < 0 )
{
fprintf(stderr, "cannot open %s\n", a2);
exit(1);
}
if ( (unsigned int)smf_header_fmt(v7, 0, 1, (int)a3) != 14 )
return fprintf(stderr, "Error during writing mid! %d (header)\n", 0LL);
v15 = 4 * *a1 + 7;
if ( (unsigned int)smf_track_head(v7, v15) != 8 )
return fprintf(stderr, "Error during writing mid! %d (track header)\n", 14LL);
if ( (unsigned int)smf_tempo(v7, 500000) != 7 )
return fprintf(stderr, "Error during writing mid! %d (tempo)\n", 22LL);
if ( (unsigned int)smf_prog_change(v7, 0, 0) != 3 )
return fprintf(stderr, "Error during writing mid! %d (prog change)\n", 29LL);
v9 = 0LL;
v10 = 32;
v11 = 0;
if ( (int)*a1 > 0 )
{
while ( 1 )
{
v13 = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v9);
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v9) == 1 )
v12 = (unsigned int)smf_note_on(
v7,
(int)v11,
*(_BYTE *)(*((_QWORD *)a1 + 3) + v9),
*(_BYTE *)(*((_QWORD *)a1 + 4) + v9),
0);
else
v12 = (unsigned int)smf_note_off(v7, (int)v11, *(_BYTE *)(*((_QWORD *)a1 + 3) + v9), 64, 0);
if ( (int)v12 <= 3 )
{
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v9) == 1 )
fprintf(
stderr,
"Error during writing mid! %d (note-on)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v10,
v11,
(unsigned int)*(char *)(*((_QWORD *)a1 + 3) + v9),
(unsigned int)*(char *)(*((_QWORD *)a1 + 4) + v9),
v12);
else
fprintf(
stderr,
"Error during writing mid! %d (note-off)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v10,
v11,
(unsigned int)*(char *)(*((_QWORD *)a1 + 3) + v9),
64LL,
v12);
}
v10 += v12;
v11 = v9 + 1;
if ( (int)*a1 <= (int)v9 + 1 )
break;
if ( (_DWORD)v9 != -1 )
v11 = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v9 + 4) - v13;
++v9;
}
}
if ( (unsigned int)smf_track_end(v7) != 4 )
return fprintf(stderr, "Error during writing mid! %d (track end)\n", v10);
if ( v14 )
{
if ( v15 != v10 - 18 )
fwrite(
"WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the he"
"ader. Midi players may not tolerate this.\n",
1uLL,
0x9AuLL,
stderr);
return close(v7);
}
if ( lseek(v7, 14LL, 0) < 0 )
return fprintf(stderr, "Error during lseek %d (re-calc)\n", 14LL);
if ( (unsigned int)smf_track_head(v7, v10 - 18) == 8 )
return close(v7);
return fprintf(stderr, "Error during write %d (re-calc)\n", v10 + 4);
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1, const char *a2, double a3)
{
size_t v5; // rax
unsigned __int64 v6; // rcx
int v7; // er15
__int64 v9; // rbp
unsigned int v10; // er14
unsigned int v11; // er12
__int64 v12; // r13
int v13; // [rsp+8h] [rbp-50h]
int v14; // [rsp+14h] [rbp-44h]
int v15; // [rsp+1Ch] [rbp-3Ch]

fprintf(stderr, "WAON_notes : n = %d\n", *a1);
fprintf(stderr, "filename : %s\n", a2);
v5 = strlen(a2);
v6 = 2LL;
if ( v5 <= 2 )
v6 = v5;
if ( !memcmp(a2, "-", v6) )
{
v7 = dup(1);
v14 = 1;
}
else
{
v7 = open(a2, 578, 384LL);
v14 = 0;
}
if ( v7 < 0 )
{
fprintf(stderr, "cannot open %s\n", a2);
exit(1);
}
if ( (unsigned int)func15(v7, 0, 1, (int)a3) != 14 )
return fprintf(stderr, "Error during writing mid! %d (header)\n", 0LL);
v15 = 4 * *a1 + 7;
if ( (unsigned int)func13(v7, v15) != 8 )
return fprintf(stderr, "Error during writing mid! %d (track header)\n", 14LL);
if ( (unsigned int)func6(v7, 500000) != 7 )
return fprintf(stderr, "Error during writing mid! %d (tempo)\n", 22LL);
if ( (unsigned int)func5(v7, 0, 0) != 3 )
return fprintf(stderr, "Error during writing mid! %d (prog change)\n", 29LL);
v9 = 0LL;
v10 = 32;
v11 = 0;
if ( (int)*a1 > 0 )
{
while ( 1 )
{
v13 = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v9);
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v9) == 1 )
v12 = (unsigned int)func9(
v7,
(int)v11,
*(_BYTE *)(*((_QWORD *)a1 + 3) + v9),
*(_BYTE *)(*((_QWORD *)a1 + 4) + v9),
0);
else
v12 = (unsigned int)func10(v7, (int)v11, *(_BYTE *)(*((_QWORD *)a1 + 3) + v9), 64, 0);
if ( (int)v12 <= 3 )
{
if ( *(_BYTE *)(*((_QWORD *)a1 + 2) + v9) == 1 )
fprintf(
stderr,
"Error during writing mid! %d (note-on)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v10,
v11,
(unsigned int)*(char *)(*((_QWORD *)a1 + 3) + v9),
(unsigned int)*(char *)(*((_QWORD *)a1 + 4) + v9),
v12);
else
fprintf(
stderr,
"Error during writing mid! %d (note-off)\n idt = %d, note = %d, vel = %d, n_midi = %d\n",
v10,
v11,
(unsigned int)*(char *)(*((_QWORD *)a1 + 3) + v9),
64LL,
v12);
}
v10 += v12;
v11 = v9 + 1;
if ( (int)*a1 <= (int)v9 + 1 )
break;
if ( (_DWORD)v9 != -1 )
v11 = *(_DWORD *)(*((_QWORD *)a1 + 1) + 4 * v9 + 4) - v13;
++v9;
}
}
if ( (unsigned int)func7(v7) != 4 )
return fprintf(stderr, "Error during writing mid! %d (track end)\n", v10);
if ( v14 )
{
if ( v15 != v10 - 18 )
fwrite(
"WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the he"
"ader. Midi players may not tolerate this.\n",
1uLL,
0x9AuLL,
stderr);
return close(v7);
}
if ( lseek(v7, 14LL, 0) < 0 )
return fprintf(stderr, "Error during lseek %d (re-calc)\n", 14LL);
if ( (unsigned int)func13(v7, v10 - 18) == 8 )
return close(v7);
return fprintf(stderr, "Error during write %d (re-calc)\n", v10 + 4);
}

original_code:
void
WAON_notes_output_midi (struct WAON_notes *notes,
   double div, char *filename)
{
  fprintf (stderr, "WAON_notes : n = %d\n", notes->n);
  fprintf (stderr, "filename : %s\n", filename);
  int fd;
  int flag_stdout;
  if (strncmp (filename, "-", strlen (filename)) == 0)
    {
      fd = dup(1);
      flag_stdout = 1;
    }
  else
    {
      fd = open (filename, 02| 0100| 01000, 0400| 0200);
      flag_stdout = 0;
    }
  if (fd < 0)
    {
      fprintf (stderr, "cannot open %s\n", filename);
      exit (1);
    }
  int p_midi;
  int n_midi;
  p_midi = 0;
  n_midi = smf_header_fmt (fd, 0, 1, div);
  if (n_midi != 14)
    {
      fprintf (stderr, "Error during writing mid! %d (header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int h_midi;
  h_midi = p_midi;
  int nmidi = notes->n;
  n_midi = smf_track_head (fd, (7+4*nmidi));
  if (n_midi != 8)
    {
      fprintf (stderr, "Error during writing mid! %d (track header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int dh_midi;
  dh_midi = p_midi;
  n_midi = smf_tempo (fd, 500000);
  if (n_midi != 7)
    {
      fprintf (stderr, "Error during writing mid! %d (tempo)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  n_midi = smf_prog_change (fd, 0, 0);
  if (n_midi != 3)
    {
      fprintf (stderr, "Error during writing mid! %d (prog change)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int idt;
  int last_step = 0;
  int i;
  for (i = 0; i < notes->n; i ++)
    {
      if (i==0) idt = 0;
      else idt = notes->step[i] - last_step;
      last_step = notes->step[i];
      if (notes->event[i] == 1)
 {
   n_midi = smf_note_on (fd, idt,
    notes->note[i],
    notes->vel[i],
    0);
 }
      else
 {
   n_midi = smf_note_off (fd, idt,
     notes->note[i],
     64,
     0);
 }
      if (n_midi < 4)
 {
   if (notes->event[i] == 1)
     {
       fprintf (stderr, "Error during writing mid! %d (note-on)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], notes->vel[i], n_midi);
     }
   else
     {
       fprintf (stderr, "Error during writing mid! %d (note-off)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], 64, n_midi);
     }
 }
      p_midi += n_midi;
    }
  n_midi = smf_track_end (fd);
  if (n_midi != 4)
    {
      fprintf (stderr, "Error during writing mid! %d (track end)\n",
        p_midi);
      return;
    }
  p_midi += n_midi;
  if (flag_stdout == 0)
    {
      if (lseek (fd, h_midi, 0) < 0)
 {
   fprintf (stderr, "Error during lseek %d (re-calc)\n", h_midi);
   return;
 }
      n_midi = smf_track_head (fd, (p_midi - dh_midi));
      if (n_midi != 8)
 {
   fprintf (stderr, "Error during write %d (re-calc)\n", p_midi);
   return;
 }
    }
  else
    {
      if ((7 + 4 * nmidi) != (p_midi - dh_midi))
 fprintf(stderr, "WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the header. Midi players may not tolerate this.\n");
    }
  close (fd);
}

canonical_original_code:
void WAON_notes_output_midi(struct WAON_notes *notes, double div, char *filename)
{
  fprintf (stderr, "WAON_notes : n = %d\n", notes->n);
  fprintf (stderr, "filename : %s\n", filename);
  int fd;
  int flag_stdout;
  if (strncmp (filename, "-", strlen (filename)) == 0)
    {
      fd = dup(1);
      flag_stdout = 1;
    }
  else
    {
      fd = open (filename, 02| 0100| 01000, 0400| 0200);
      flag_stdout = 0;
    }
  if (fd < 0)
    {
      fprintf (stderr, "cannot open %s\n", filename);
      exit (1);
    }
  int p_midi;
  int n_midi;
  p_midi = 0;
  n_midi = smf_header_fmt (fd, 0, 1, div);
  if (n_midi != 14)
    {
      fprintf (stderr, "Error during writing mid! %d (header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int h_midi;
  h_midi = p_midi;
  int nmidi = notes->n;
  n_midi = smf_track_head (fd, (7+4*nmidi));
  if (n_midi != 8)
    {
      fprintf (stderr, "Error during writing mid! %d (track header)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int dh_midi;
  dh_midi = p_midi;
  n_midi = smf_tempo (fd, 500000);
  if (n_midi != 7)
    {
      fprintf (stderr, "Error during writing mid! %d (tempo)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  n_midi = smf_prog_change (fd, 0, 0);
  if (n_midi != 3)
    {
      fprintf (stderr, "Error during writing mid! %d (prog change)\n", p_midi);
      return;
    }
  p_midi += n_midi;
  int idt;
  int last_step = 0;
  int i;
  for (i = 0; i < notes->n; i ++)
    {
      if (i==0) idt = 0;
      else idt = notes->step[i] - last_step;
      last_step = notes->step[i];
      if (notes->event[i] == 1)
 {
   n_midi = smf_note_on (fd, idt,
    notes->note[i],
    notes->vel[i],
    0);
 }
      else
 {
   n_midi = smf_note_off (fd, idt,
     notes->note[i],
     64,
     0);
 }
      if (n_midi < 4)
 {
   if (notes->event[i] == 1)
     {
       fprintf (stderr, "Error during writing mid! %d (note-on)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], notes->vel[i], n_midi);
     }
   else
     {
       fprintf (stderr, "Error during writing mid! %d (note-off)\n"
         " idt = %d, note = %d, vel = %d, n_midi = %d\n",
         p_midi,
         idt, notes->note[i], 64, n_midi);
     }
 }
      p_midi += n_midi;
    }
  n_midi = smf_track_end (fd);
  if (n_midi != 4)
    {
      fprintf (stderr, "Error during writing mid! %d (track end)\n",
        p_midi);
      return;
    }
  p_midi += n_midi;
  if (flag_stdout == 0)
    {
      if (lseek (fd, h_midi, 0) < 0)
 {
   fprintf (stderr, "Error during lseek %d (re-calc)\n", h_midi);
   return;
 }
      n_midi = smf_track_head (fd, (p_midi - dh_midi));
      if (n_midi != 8)
 {
   fprintf (stderr, "Error during write %d (re-calc)\n", p_midi);
   return;
 }
    }
  else
    {
      if ((7 + 4 * nmidi) != (p_midi - dh_midi))
 fprintf(stderr, "WaoN warning : data size seems to differ from the header prediction, and stdout isn't seekable to correct the header. Midi players may not tolerate this.\n");
    }
  close (fd);
}

variable_types: struct WAON_notes { int n; int *step; char *event; char *note; char *vel; } *

variable_types: div double

variable_types:
filename
char *

variable_types: nmidi int

variable_types: idt int

variable_types: i int


repo: kichiki/WaoN

decompiled_code:
void __fastcall average_FFT_into_midi(int a1, __int64 a2, __int64 a3, __int64 a4, double a5)
{
_DWORD *v7; // rax
_DWORD *v8; // rbp
__int64 i; // rax
__int64 v10; // r13
double v11; // xmm0_8
double v12; // xmm0_8
signed int v13; // er12
double v14; // xmm0_8
__int64 j; // rax
int v16; // edx

v7 = malloc(0x200uLL);
if ( !v7 )
{
fwrite("average_FFT_into_midi : malloc error for n\n", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v8 = v7;
for ( i = 0LL; i != 128; ++i )
{
*(_QWORD *)(a4 + 8 * i) = 0LL;
v8[i] = 0;
}
if ( a1 > 2 )
{
v10 = 1LL;
do
{
if ( a3 )
v11 = ((double)(int)v10 / (double)a1 + *(double *)(a3 + 8 * v10)) * a5;
else
v11 = (double)(int)v10 / (double)a1 * a5;
v13 = freq_to_midi(v11);
if ( (unsigned int)v13 <= 0x7F )
{
v14 = *(double *)(a2 + 8 * v10);
if ( v14 < 0.0 )
v12 = sqrt(v14);
else
v12 = sqrt(v14);
*(double *)(a4 + 8LL * v13) = v12 + *(double *)(a4 + 8LL * v13);
++v8[v13];
}
++v10;
}
while ( (a1 + 1) / 2 > (int)v10 );
}
for ( j = 0LL; j != 128; ++j )
{
v16 = v8[j];
if ( v16 > 0 )
*(double *)(a4 + 8 * j) = *(double *)(a4 + 8 * j) / (double)v16 * (*(double *)(a4 + 8 * j) / (double)v16);
}
free(v8);
}

original_code:
void
average_FFT_into_midi (int len, double samplerate,
         const double *amp2, const double *dphi,
         double *ave2)
{
  int k;
  int midi;
  double f;
  int *n = ((void *)0);
  n = (int *) malloc (sizeof (int) * 128);
  if (n == ((void *)0)) { fprintf (stderr, "average_FFT_into_midi" " : malloc error for " "n" "\n"); exit (1); };
  for (midi = 0; midi < 128; midi ++)
    {
      ave2 [midi] = 0.0;
      n [midi] = 0;
    }
  for (k = 1; k < (len+1)/2; k ++)
    {
      if (dphi == ((void *)0))
 {
   f = (double)k / (double)len * samplerate;
 }
      else
 {
   f = ((double)k / (double)len + dphi [k]) * samplerate;
 }
      midi = freq_to_midi (f);
      if (midi >= 0 && midi < 128)
 {
   ave2 [midi] += sqrt (amp2 [k]);
   n [midi] ++;
 }
    }
  for (midi = 0; midi < 128; midi ++)
    {
      if (n [midi] > 0)
 {
   ave2 [midi] = ave2 [midi] / (double)n [midi];
   ave2 [midi] = ave2 [midi] * ave2 [midi];
 }
    }
  free (n);
}

canonical_original_code:
void average_FFT_into_midi(int len, double samplerate, double *amp2, double *dphi, double *ave2)
{
  int k;
  int midi;
  double f;
  int *n = ((void *)0);
  n = (int *) malloc (sizeof (int) * 128);
  if (n == ((void *)0)) { fprintf (stderr, "average_FFT_into_midi" " : malloc error for " "n" "\n"); exit (1); };
  for (midi = 0; midi < 128; midi ++)
    {
      ave2 [midi] = 0.0;
      n [midi] = 0;
    }
  for (k = 1; k < (len+1)/2; k ++)
    {
      if (dphi == ((void *)0))
 {
   f = (double)k / (double)len * samplerate;
 }
      else
 {
   f = ((double)k / (double)len + dphi [k]) * samplerate;
 }
      midi = freq_to_midi (f);
      if (midi >= 0 && midi < 128)
 {
   ave2 [midi] += sqrt (amp2 [k]);
   n [midi] ++;
 }
    }
  for (midi = 0; midi < 128; midi ++)
    {
      if (n [midi] > 0)
 {
   ave2 [midi] = ave2 [midi] / (double)n [midi];
   ave2 [midi] = ave2 [midi] * ave2 [midi];
 }
    }
  free (n);
}

variable_types: len int

variable_types: samplerate double

variable_types:
dphi
double *

variable_types: k int

variable_types: midi int

variable_types: f double

variable_types:
n
int *

return_type: void


original_code:
void
pickup_notes (double *amp2midi,
       double cut_ratio, double rel_cut_ratio,
       int i0, int i1,
       char *intens)
{
  extern int abs_flg;
  double oct_fac = 0.0;
  int i;
  int imax;
  double max;
  double x;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += amp2midi[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (amp2midi[i] > max)
     {
       max = amp2midi[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      in = imax;
      if (intens[in] == 0)
 {
   x = 127.0 / (double)(-cut_ratio)
     * (log10 (amp2midi[in]) - (double) cut_ratio);
   if (x >= 128.0)
     {
       intens[in] = 127;
     }
   else if (x > 0)
     {
       intens[in] = (int)x;
     }
   if (oct_fac > 0.0)
     {
       for (i = in + 12; in < 128; in += 12)
  {
    amp2midi[i] = sqrt (amp2midi[i])
      - oct_fac * sqrt (amp2midi[i-12]);
    if (amp2midi[i] < 0.0) amp2midi[i] = 0.0;
    else amp2midi[i] = amp2midi[i] * amp2midi[i];
  }
     }
 }
      amp2midi[imax] = 0.0;
    }
}

canonical_original_code:
void pickup_notes(double *amp2midi, double cut_ratio, double rel_cut_ratio, int i0, int i1, char *intens)
{
  extern int abs_flg;
  double oct_fac = 0.0;
  int i;
  int imax;
  double max;
  double x;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += amp2midi[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (amp2midi[i] > max)
     {
       max = amp2midi[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      in = imax;
      if (intens[in] == 0)
 {
   x = 127.0 / (double)(-cut_ratio)
     * (log10 (amp2midi[in]) - (double) cut_ratio);
   if (x >= 128.0)
     {
       intens[in] = 127;
     }
   else if (x > 0)
     {
       intens[in] = (int)x;
     }
   if (oct_fac > 0.0)
     {
       for (i = in + 12; in < 128; in += 12)
  {
    amp2midi[i] = sqrt (amp2midi[i])
      - oct_fac * sqrt (amp2midi[i-12]);
    if (amp2midi[i] < 0.0) amp2midi[i] = 0.0;
    else amp2midi[i] = amp2midi[i] * amp2midi[i];
  }
     }
 }
      amp2midi[imax] = 0.0;
    }
}

variable_types:
intens
char *

variable_types: imax int

variable_types: max double

variable_types: x double

variable_types: in int

variable_types: av double


decompiled_code:
double __fastcall patch_power(double a1)
{
double v1; // xmm3_8
int v2; // edx
int v3; // eax
double result; // xmm0_8
double v5; // xmm0_8

v1 = a1 * *(double *)&if0;
v2 = (int)(a1 * *(double *)&if0);
if ( v2 <= 0 )
return 0.0;
v3 = v2 + 1;
result = 0.0;
if ( npat >= v2 + 1 )
{
v5 = *(double *)(pat + 8LL * v3 - 8);
result = (v5 + (*(double *)(pat + 8LL * v3) - v5) * (v1 - (double)v2)) / *(double *)&p0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
double v1; // xmm3_8
int v2; // edx
int v3; // eax
double result; // xmm0_8
double v5; // xmm0_8

v1 = a1 * *(double *)&if0;
v2 = (int)(a1 * *(double *)&if0);
if ( v2 <= 0 )
return 0.0;
v3 = v2 + 1;
result = 0.0;
if ( npat >= v2 + 1 )
{
v5 = *(double *)(pat + 8LL * v3 - 8);
result = (v5 + (*(double *)(pat + 8LL * v3) - v5) * (v1 - (double)v2)) / *(double *)&p0;
}
return result;
}

original_code:
double
patch_power (double freq_ratio)
{
  extern double *pat;
  extern int npat;
  extern double p0;
  extern double if0;
  int i0, i1;
  double dpdf;
  double f;
  double p;
  f = (double)if0 * freq_ratio;
  i0 = (int)f;
  i1 = i0 + 1;
  if (i0 < 1 || i1 > npat)
    return 0.0;
  dpdf = pat[i1] - pat[i0];
  p = pat[i0] + dpdf * (f - (double)i0);
  return (p/p0);
}

canonical_original_code:
double patch_power(double freq_ratio)
{
  extern double *pat;
  extern int npat;
  extern double p0;
  extern double if0;
  int i0; int i1;
  double dpdf;
  double f;
  double p;
  f = (double)if0 * freq_ratio;
  i0 = (int)f;
  i1 = i0 + 1;
  if (i0 < 1 || i1 > npat)
    return 0.0;
  dpdf = pat[i1] - pat[i0];
  p = pat[i0] + dpdf * (f - (double)i0);
  return (p/p0);
}

variable_types:
pat
double *

variable_types: npat int

variable_types: dpdf double

variable_types: p double

return_type: double


original_code:
void
note_intensity (double *p, double *fp,
  double cut_ratio, double rel_cut_ratio,
  int i0, int i1,
  double t0, char *intens)
{
  extern int patch_flg;
  extern int abs_flg;
  int i;
  int imax;
  double max;
  double x;
  double freq;
  double f;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += p[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (p[i] > max)
     {
       max = p[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      if (fp == ((void *)0))
 {
   freq = (double)imax / t0;
 }
      else
 {
   freq = fp [imax];
 }
      in = get_note (freq);
      if (in >= i0 && in <= i1)
 {
   if (intens[in] == 0)
     {
       x = 127.0 / (double)(-cut_ratio)
  * (log10 (p[imax]) - (double) cut_ratio);
       if (x >= 128.0)
  {
    intens[in] = 127;
  }
       else if (x > 0)
  {
    intens[in] = (int)x;
  }
     }
 }
      if (patch_flg == 0)
 {
   p[imax] = 0.0;
   for (i = imax+1;
       p[i] != 0.0 && i < (i1-1) && p[i] >= p[i+1];
       i++)
     p[i] = 0.0;
   if (i == i1-1)
     p[i] = 0.0;
   for (i = imax-1;
        p[i] != 0.0 && i > i0 && p[i-1] <= p[i];
        i--)
     p[i] = 0.0;
   if (i == i0)
     p[i] = 0.0;
 }
      else
 {
   for (i = i0; i < i1; i++)
     {
       if (fp == ((void *)0))
  {
    f = (double)i / t0;
  }
       else
  {
    f = fp [i];
  }
       p[i] -= max * patch_power (f/freq);
       if (p[i] <0)
  {
    p[i] = 0;
  }
     }
 }
    }
}

canonical_original_code:
void note_intensity(double *p, double *fp, double cut_ratio, double rel_cut_ratio, int i0, int i1, double t0, char *intens)
{
  extern int patch_flg;
  extern int abs_flg;
  int i;
  int imax;
  double max;
  double x;
  double freq;
  double f;
  int in;
  double av;
  for (i = 0; i < 128; i++)
    {
      intens[i] = 0;
    }
  if (abs_flg == 0)
    {
      av = 0.0;
      for (i = i0; i < i1; i++)
 {
   av += p[i];
 }
      av /= (double)(i1 - i0);
    }
  else
    {
      av = 1.0;
    }
  for (;;)
    {
      if (abs_flg == 0)
 {
   max = av * pow (10.0, rel_cut_ratio);
 }
      else
 {
   max = pow (10.0, cut_ratio);
 }
      imax = -1;
      for (i = i0; i < i1; i++)
 {
   if (p[i] > max)
     {
       max = p[i];
       imax = i;
     }
 }
      if (imax == -1)
 break;
      if (fp == ((void *)0))
 {
   freq = (double)imax / t0;
 }
      else
 {
   freq = fp [imax];
 }
      in = get_note (freq);
      if (in >= i0 && in <= i1)
 {
   if (intens[in] == 0)
     {
       x = 127.0 / (double)(-cut_ratio)
  * (log10 (p[imax]) - (double) cut_ratio);
       if (x >= 128.0)
  {
    intens[in] = 127;
  }
       else if (x > 0)
  {
    intens[in] = (int)x;
  }
     }
 }
      if (patch_flg == 0)
 {
   p[imax] = 0.0;
   for (i = imax+1;
       p[i] != 0.0 && i < (i1-1) && p[i] >= p[i+1];
       i++)
     p[i] = 0.0;
   if (i == i1-1)
     p[i] = 0.0;
   for (i = imax-1;
        p[i] != 0.0 && i > i0 && p[i-1] <= p[i];
        i--)
     p[i] = 0.0;
   if (i == i0)
     p[i] = 0.0;
 }
      else
 {
   for (i = i0; i < i1; i++)
     {
       if (fp == ((void *)0))
  {
    f = (double)i / t0;
  }
       else
  {
    f = fp [i];
  }
       p[i] -= max * patch_power (f/freq);
       if (p[i] <0)
  {
    p[i] = 0;
  }
     }
 }
    }
}

variable_types:
p
double *

variable_types:
fp
double *

variable_types: i int

variable_types: freq double


hanning

decompiled_code:
double __fastcall hanning(int a1, int a2)
{
return (1.0 - cos((double)a1 * 6.283185307179586 / (double)(a2 - 1))) * 0.5;
}

variable_types: nn int


hamming

decompiled_code:
double __fastcall hamming(int a1, int a2)
{
return 0.54 - cos((double)a1 * 6.283185307179586 / (double)(a2 - 1)) * 0.46;
}


windowing

decompiled_code:
void __fastcall windowing(int a1, double *a2, int a3, double *a4, double a5)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
switch ( a3 )
{
case 0:
goto LABEL_10;
case 1:
*a4 = COERCE_DOUBLE(parzen(i, a1)) * *a2 / a5;
break;
case 2:
*a4 = COERCE_DOUBLE(welch(i, a1)) * *a2 / a5;
break;
case 3:
*a4 = hanning(i, a1) * *a2 / a5;
break;
case 4:
*a4 = hamming(i, a1) * *a2 / a5;
break;
case 5:
*a4 = blackman(i, a1) * *a2 / a5;
break;
case 6:
*a4 = steeper(i, a1) * *a2 / a5;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_10:
*a4 = *a2 / a5;
break;
}
++a2;
++a4;
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1, double *a2, int a3, double *a4, double a5)
{
int i; // ebx

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
switch ( a3 )
{
case 0:
goto LABEL_10;
case 1:
*a4 = COERCE_DOUBLE(parzen(i, a1)) * *a2 / a5;
break;
case 2:
*a4 = COERCE_DOUBLE(welch(i, a1)) * *a2 / a5;
break;
case 3:
*a4 = func0(i, a1) * *a2 / a5;
break;
case 4:
*a4 = func1(i, a1) * *a2 / a5;
break;
case 5:
*a4 = func2(i, a1) * *a2 / a5;
break;
case 6:
*a4 = func3(i, a1) * *a2 / a5;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_10:
*a4 = *a2 / a5;
break;
}
++a2;
++a4;
}
}
}

original_code:
void
windowing (int n, const double *data, int flag_window, double scale,
    double *out)
{
  int i;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   out [i] = data [i] * parzen (i, n) / scale;
   break;
 case 2:
   out [i] = data [i] * welch (i, n) / scale;
   break;
 case 3:
   out [i] = data [i] * hanning (i, n) / scale;
   break;
 case 4:
   out [i] = data [i] * hamming (i, n) / scale;
   break;
 case 5:
   out [i] = data [i] * blackman (i, n) / scale;
   break;
 case 6:
   out [i] = data [i] * steeper (i, n) / scale;
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   out [i] = data [i] / scale;
   break;
 }
    }
}

canonical_original_code:
void windowing(int n, double *data, int flag_window, double scale, double *out)
{
  int i;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   out [i] = data [i] * parzen (i, n) / scale;
   break;
 case 2:
   out [i] = data [i] * welch (i, n) / scale;
   break;
 case 3:
   out [i] = data [i] * hanning (i, n) / scale;
   break;
 case 4:
   out [i] = data [i] * hamming (i, n) / scale;
   break;
 case 5:
   out [i] = data [i] * blackman (i, n) / scale;
   break;
 case 6:
   out [i] = data [i] * steeper (i, n) / scale;
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   out [i] = data [i] / scale;
   break;
 }
    }
}

variable_types: n int

variable_types:
data
double *

variable_types: scale double

variable_types:
out
double *


decompiled_code:
double __fastcall init_den(int a1, char a2)
{
int v2; // ebx
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v10; // [rsp+8h] [rbp-20h]

if ( a1 <= 0 )
{
v10 = 0.0;
}
else
{
v2 = 0;
v10 = 0.0;
do
{
switch ( a2 )
{
case 0:
goto LABEL_10;
case 1:
v3 = COERCE_DOUBLE(parzen(v2, a1));
v10 = v3 * v3 + v10;
break;
case 2:
v4 = COERCE_DOUBLE(welch(v2, a1));
v10 = v4 * v4 + v10;
break;
case 3:
v5 = hanning(v2, a1);
v10 = v5 * v5 + v10;
break;
case 4:
v6 = hamming(v2, a1);
v10 = v6 * v6 + v10;
break;
case 5:
v7 = blackman(v2, a1);
v10 = v7 * v7 + v10;
break;
case 6:
v8 = steeper(v2, a1);
v10 = v8 * v8 + v10;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_10:
v10 = v10 + 1.0;
break;
}
++v2;
}
while ( a1 != v2 );
}
return (double)a1 * v10;
}

canonical_decompiled_code:
double __fastcall func7(int a1, char a2)
{
int v2; // ebx
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v10; // [rsp+8h] [rbp-20h]

if ( a1 <= 0 )
{
v10 = 0.0;
}
else
{
v2 = 0;
v10 = 0.0;
do
{
switch ( a2 )
{
case 0:
goto LABEL_10;
case 1:
v3 = COERCE_DOUBLE(parzen(v2, a1));
v10 = v3 * v3 + v10;
break;
case 2:
v4 = COERCE_DOUBLE(welch(v2, a1));
v10 = v4 * v4 + v10;
break;
case 3:
v5 = func0(v2, a1);
v10 = v5 * v5 + v10;
break;
case 4:
v6 = func1(v2, a1);
v10 = v6 * v6 + v10;
break;
case 5:
v7 = func2(v2, a1);
v10 = v7 * v7 + v10;
break;
case 6:
v8 = func3(v2, a1);
v10 = v8 * v8 + v10;
break;
default:
fwrite("invalid flag_window\n", 1uLL, 0x14uLL, stderr);
LABEL_10:
v10 = v10 + 1.0;
break;
}
++v2;
}
while ( a1 != v2 );
}
return (double)a1 * v10;
}

original_code:
double
init_den (int n, char flag_window)
{
  double den;
  int i;
  den = 0.0;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   den += parzen (i, n) * parzen (i, n);
   break;
 case 2:
   den += welch (i, n) * welch (i, n);
   break;
 case 3:
   den += hanning (i, n) * hanning (i, n);
   break;
 case 4:
   den += hamming (i, n) * hamming (i, n);
   break;
 case 5:
   den += blackman (i, n) * blackman (i, n);
   break;
 case 6:
   den += steeper (i, n) * steeper (i, n);
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   den += 1.0;
   break;
 }
    }
  den *= (double)n;
  return den;
}

canonical_original_code:
double init_den(int n, char flag_window)
{
  double den;
  int i;
  den = 0.0;
  for (i = 0; i < n; i ++)
    {
      switch (flag_window)
 {
 case 1:
   den += parzen (i, n) * parzen (i, n);
   break;
 case 2:
   den += welch (i, n) * welch (i, n);
   break;
 case 3:
   den += hanning (i, n) * hanning (i, n);
   break;
 case 4:
   den += hamming (i, n) * hamming (i, n);
   break;
 case 5:
   den += blackman (i, n) * blackman (i, n);
   break;
 case 6:
   den += steeper (i, n) * steeper (i, n);
   break;
 default:
   fprintf (stderr, "invalid flag_window\n");
 case 0:
   den += 1.0;
   break;
 }
    }
  den *= (double)n;
  return den;
}

variable_types: den double


original_code:
void
power_subtract_ave (int n, double *p, int m, double factor)
{
  int nlen = n/2+1;
  int i;
  int k;
  int nave;
  static double *ave = ((void *)0);
  static int n_ave = 0;
  if (ave == ((void *)0))
    {
      ave = (double *)malloc (sizeof (double) * nlen);
      if (ave == ((void *)0)) { fprintf (stderr, "power_subtract_ave" " : malloc error for " "ave" "\n"); exit (1); };
      n_ave = nlen;
    }
  else if (n_ave < nlen)
    {
      ave = (double *)realloc (ave, sizeof (double) * nlen);
      if (ave == ((void *)0)) { fprintf (stderr, "power_subtract_ave" " : malloc error for " "ave" "\n"); exit (1); };
      n_ave = nlen;
    }
  for (i = 0; i < nlen; i ++)
    {
      ave [i] = 0.0;
      nave = 0;
      for (k = -m; k <= m; k ++)
 {
   if ((i + k) < 0 || (i + k) >= nlen) continue;
   ave [i] += p [i+k];
   nave ++;
 }
      if (nave > 0) ave [i] /= (double)nave;
    }
  for (i = 0; i < nlen; i ++)
    {
      p [i] = sqrt (p[i]) - factor * sqrt (ave [i]);
      if (p [i] < 0.0) p [i] = 0.0;
      else p [i] = p [i] * p [i];
    }
}

canonical_original_code:
void power_subtract_ave(int n, double *p, int m, double factor)
{
  int nlen = n/2+1;
  int i;
  int k;
  int nave;
  static double *ave = ((void *)0);
  static int n_ave = 0;
  if (ave == ((void *)0))
    {
      ave = (double *)malloc (sizeof (double) * nlen);
      if (ave == ((void *)0)) { fprintf (stderr, "power_subtract_ave" " : malloc error for " "ave" "\n"); exit (1); };
      n_ave = nlen;
    }
  else if (n_ave < nlen)
    {
      ave = (double *)realloc (ave, sizeof (double) * nlen);
      if (ave == ((void *)0)) { fprintf (stderr, "power_subtract_ave" " : malloc error for " "ave" "\n"); exit (1); };
      n_ave = nlen;
    }
  for (i = 0; i < nlen; i ++)
    {
      ave [i] = 0.0;
      nave = 0;
      for (k = -m; k <= m; k ++)
 {
   if ((i + k) < 0 || (i + k) >= nlen) continue;
   ave [i] += p [i+k];
   nave ++;
 }
      if (nave > 0) ave [i] /= (double)nave;
    }
  for (i = 0; i < nlen; i ++)
    {
      p [i] = sqrt (p[i]) - factor * sqrt (ave [i]);
      if (p [i] < 0.0) p [i] = 0.0;
      else p [i] = p [i] * p [i];
    }
}

variable_types: m int

variable_types: factor double

variable_types: nlen int

variable_types: k int

variable_types: nave int

variable_types:
ave
double *


decompiled_code:
void __fastcall power_subtract_octave(int a1, _QWORD *a2, double a3)
{
int v3; // er14
int v4; // er12
int v5; // eax
double *v6; // rbp
__int64 v7; // rax
int v8; // edx
int v9; // ebp
__int64 v10; // r13
double v11; // r14
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm1_8

v3 = a1 + 1;
v4 = (a1 + 1) / 2;
if ( oct_1 )
{
v5 = a1 / 2;
if ( a1 / 2 >= n_oct_0 )
{
v9 = v5 + 1;
oct_1 = realloc(oct_1, 8LL * (v5 + 1));
if ( !oct_1 )
{
fwrite("power_subtract_octave : malloc error for oct\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
n_oct_0 = v9;
}
}
else
{
oct_1 = malloc(8LL * (a1 / 2 + 1));
if ( !oct_1 )
{
fwrite("power_subtract_octave : malloc error for oct\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
n_oct_0 = a1 / 2 + 1;
}
v6 = (double *)oct_1;
*(_QWORD *)oct_1 = *a2;
if ( v3 <= 3 )
{
if ( v3 <= 1 )
return;
}
else if ( a1 > 3 )
{
v7 = 2LL;
v8 = 1;
do
{
v6[v7] = a3 * *(double *)&a2[(unsigned __int64)v7 / 2];
if ( (int)v7 > 1 )
v6[v7 - 1] = a3 * 0.5 * *(double *)&a2[(unsigned __int64)v7 / 2];
if ( (int)v7 + 1 < v4 )
v6[v7 + 1] = a3 * 0.5 * *(double *)&a2[(unsigned __int64)v7 / 2];
if ( ++v8 > v3 / 4 )
break;
v7 += 2LL;
}
while ( a1 / 2 >= (int)v7 );
}
v10 = 0LL;
do
{
v14 = *(double *)&a2[v10];
if ( v14 < 0.0 )
v11 = sqrt(v14);
else
v11 = sqrt(v14);
v15 = v6[v10];
if ( v15 < 0.0 )
v12 = sqrt(v15);
else
v12 = sqrt(v15);
v16 = v11 - v12 * a3;
v13 = 0.0;
if ( v16 >= 0.0 )
v13 = v16 * v16;
*(double *)&a2[v10++] = v13;
}
while ( v4 > (int)v10 );
}

original_code:
void
power_subtract_octave (int n, double *p, double factor)
{
  int nlen = (n+1)/2;
  int i;
  int i2;
  static double *oct = ((void *)0);
  static int n_oct = 0;
  if (oct == ((void *)0))
    {
      oct = (double *)malloc (sizeof (double) * (n/2+1));
      if (oct == ((void *)0)) { fprintf (stderr, "power_subtract_octave" " : malloc error for " "oct" "\n"); exit (1); };
      n_oct = n/2+1;
    }
  else if (n_oct < (n/2+1))
    {
      oct = (double *)realloc (oct, sizeof (double) * (n/2+1));
      if (oct == ((void *)0)) { fprintf (stderr, "power_subtract_octave" " : malloc error for " "oct" "\n"); exit (1); };
      n_oct = n/2+1;
    }
  oct [0] = p [0];
  for (i = 1; i < nlen/2+1; i ++)
    {
      i2 = i * 2;
      if (i2 >= n/2+1) break;
      oct [i2] = factor * p[i];
      if (i2-1 > 0) oct [i2-1] = 0.5 * factor * p[i];
      if (i2+1 < nlen) oct [i2+1] = 0.5 * factor * p[i];
    }
  for (i = 0; i < nlen; i ++)
    {
      p [i] = sqrt (p[i]) - factor * sqrt (oct [i]);
      if (p [i] < 0.0) p [i] = 0.0;
      else p [i] = p [i] * p [i];
    }
}

canonical_original_code:
void power_subtract_octave(int n, double *p, double factor)
{
  int nlen = (n+1)/2;
  int i;
  int i2;
  static double *oct = ((void *)0);
  static int n_oct = 0;
  if (oct == ((void *)0))
    {
      oct = (double *)malloc (sizeof (double) * (n/2+1));
      if (oct == ((void *)0)) { fprintf (stderr, "power_subtract_octave" " : malloc error for " "oct" "\n"); exit (1); };
      n_oct = n/2+1;
    }
  else if (n_oct < (n/2+1))
    {
      oct = (double *)realloc (oct, sizeof (double) * (n/2+1));
      if (oct == ((void *)0)) { fprintf (stderr, "power_subtract_octave" " : malloc error for " "oct" "\n"); exit (1); };
      n_oct = n/2+1;
    }
  oct [0] = p [0];
  for (i = 1; i < nlen/2+1; i ++)
    {
      i2 = i * 2;
      if (i2 >= n/2+1) break;
      oct [i2] = factor * p[i];
      if (i2-1 > 0) oct [i2-1] = 0.5 * factor * p[i];
      if (i2+1 < nlen) oct [i2+1] = 0.5 * factor * p[i];
    }
  for (i = 0; i < nlen; i ++)
    {
      p [i] = sqrt (p[i]) - factor * sqrt (oct [i]);
      if (p [i] < 0.0) p [i] = 0.0;
      else p [i] = p [i] * p [i];
    }
}

variable_types:
oct
double *


decompiled_code:
int __fastcall curses_print_window(int a1)
{
int result; // eax

switch ( a1 )
{
case 0:
result = mvprintw(10, 1, "window : square ");
break;
case 1:
result = mvprintw(10, 1, "window : parzen ");
break;
case 2:
result = mvprintw(10, 1, "window : welch ");
break;
case 3:
result = mvprintw(10, 1, "window : hanning ");
break;
case 4:
result = mvprintw(10, 1, "window : hamming ");
break;
case 5:
result = mvprintw(10, 1, "window : blackman");
break;
case 6:
result = mvprintw(10, 1, "window : steeper ");
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = mvprintw(10, 1, "window : square ");
break;
case 1:
result = mvprintw(10, 1, "window : parzen ");
break;
case 2:
result = mvprintw(10, 1, "window : welch ");
break;
case 3:
result = mvprintw(10, 1, "window : hanning ");
break;
case 4:
result = mvprintw(10, 1, "window : hamming ");
break;
case 5:
result = mvprintw(10, 1, "window : blackman");
break;
case 6:
result = mvprintw(10, 1, "window : steeper ");
break;
default:
return result;
}
return result;
}

original_code:
static void
curses_print_window (int flag_window)
{
  switch (flag_window)
    {
    case 0:
      mvprintw ((10), 1, "window     : square  ");
      break;
    case 1:
      mvprintw ((10), 1, "window     : parzen  ");
      break;
    case 2:
      mvprintw ((10), 1, "window     : welch   ");
      break;
    case 3:
      mvprintw ((10), 1, "window     : hanning ");
      break;
    case 4:
      mvprintw ((10), 1, "window     : hamming ");
      break;
    case 5:
      mvprintw ((10), 1, "window     : blackman");
      break;
    case 6:
      mvprintw ((10), 1, "window     : steeper ");
      break;
    }
}

canonical_original_code:
static void curses_print_window(int flag_window)
{
  switch (flag_window)
    {
    case 0:
      mvprintw ((10), 1, "window     : square  ");
      break;
    case 1:
      mvprintw ((10), 1, "window     : parzen  ");
      break;
    case 2:
      mvprintw ((10), 1, "window     : welch   ");
      break;
    case 3:
      mvprintw ((10), 1, "window     : hanning ");
      break;
    case 4:
      mvprintw ((10), 1, "window     : hamming ");
      break;
    case 5:
      mvprintw ((10), 1, "window     : blackman");
      break;
    case 6:
      mvprintw ((10), 1, "window     : steeper ");
      break;
    }
}


decompiled_code:
int __fastcall curses_print_pitch(unsigned int a1)
{
__int64 v1; // rcx
int result; // eax

if ( (a1 & 0x80000000) != 0 )
{
v1 = (unsigned int)~((int)~a1 / 12);
result = 12 * ((int)~a1 / 12) + a1 + 1 + 11;
}
else
{
v1 = (unsigned int)((int)a1 / 12);
result = (int)a1 % 12;
}
switch ( result )
{
case 0:
result = mvprintw(6, 1, "pitch : C %+2d (%+3d)", v1, a1);
break;
case 1:
result = mvprintw(6, 1, "pitch : C# %+2d (%+3d)", v1, a1);
break;
case 2:
result = mvprintw(6, 1, "pitch : D %+2d (%+3d)", v1, a1);
break;
case 3:
result = mvprintw(6, 1, "pitch : Eb %+2d (%+3d)", v1, a1);
break;
case 4:
result = mvprintw(6, 1, "pitch : E %+2d (%+3d)", v1, a1);
break;
case 5:
result = mvprintw(6, 1, "pitch : F %+2d (%+3d)", v1, a1);
break;
case 6:
result = mvprintw(6, 1, "pitch : F# %+2d (%+3d)", v1, a1);
break;
case 7:
result = mvprintw(6, 1, "pitch : G %+2d (%+3d)", v1, a1);
break;
case 8:
result = mvprintw(6, 1, "pitch : G# %+2d (%+3d)", v1, a1);
break;
case 9:
result = mvprintw(6, 1, "pitch : A %+2d (%+3d)", v1, a1);
break;
case 10:
result = mvprintw(6, 1, "pitch : Bb %+2d (%+3d)", v1, a1);
break;
case 11:
result = mvprintw(6, 1, "pitch : B %+2d (%+3d)", v1, a1);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1)
{
__int64 v1; // rcx
int result; // eax

if ( (a1 & 0x80000000) != 0 )
{
v1 = (unsigned int)~((int)~a1 / 12);
result = 12 * ((int)~a1 / 12) + a1 + 1 + 11;
}
else
{
v1 = (unsigned int)((int)a1 / 12);
result = (int)a1 % 12;
}
switch ( result )
{
case 0:
result = mvprintw(6, 1, "pitch : C %+2d (%+3d)", v1, a1);
break;
case 1:
result = mvprintw(6, 1, "pitch : C# %+2d (%+3d)", v1, a1);
break;
case 2:
result = mvprintw(6, 1, "pitch : D %+2d (%+3d)", v1, a1);
break;
case 3:
result = mvprintw(6, 1, "pitch : Eb %+2d (%+3d)", v1, a1);
break;
case 4:
result = mvprintw(6, 1, "pitch : E %+2d (%+3d)", v1, a1);
break;
case 5:
result = mvprintw(6, 1, "pitch : F %+2d (%+3d)", v1, a1);
break;
case 6:
result = mvprintw(6, 1, "pitch : F# %+2d (%+3d)", v1, a1);
break;
case 7:
result = mvprintw(6, 1, "pitch : G %+2d (%+3d)", v1, a1);
break;
case 8:
result = mvprintw(6, 1, "pitch : G# %+2d (%+3d)", v1, a1);
break;
case 9:
result = mvprintw(6, 1, "pitch : A %+2d (%+3d)", v1, a1);
break;
case 10:
result = mvprintw(6, 1, "pitch : Bb %+2d (%+3d)", v1, a1);
break;
case 11:
result = mvprintw(6, 1, "pitch : B %+2d (%+3d)", v1, a1);
break;
default:
return result;
}
return result;
}

original_code:
static void
curses_print_pitch (int pv_pitch)
{
  int oct;
  int key;
  if (pv_pitch < 0)
    {
      oct = (-pv_pitch-1) / 12;
      oct = -oct-1;
      key = (-pv_pitch-1) % 12;
      key = 11-key;
    }
  else
    {
      oct = pv_pitch / 12;
      key = pv_pitch % 12;
    }
  switch (key)
    {
    case 0:
      mvprintw ((6), 1, "pitch      : C  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 1:
      mvprintw ((6), 1, "pitch      : C# %+2d (%+3d)", oct, pv_pitch);
      break;
    case 2:
      mvprintw ((6), 1, "pitch      : D  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 3:
      mvprintw ((6), 1, "pitch      : Eb %+2d (%+3d)", oct, pv_pitch);
      break;
    case 4:
      mvprintw ((6), 1, "pitch      : E  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 5:
      mvprintw ((6), 1, "pitch      : F  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 6:
      mvprintw ((6), 1, "pitch      : F# %+2d (%+3d)", oct, pv_pitch);
      break;
    case 7:
      mvprintw ((6), 1, "pitch      : G  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 8:
      mvprintw ((6), 1, "pitch      : G# %+2d (%+3d)", oct, pv_pitch);
      break;
    case 9:
      mvprintw ((6), 1, "pitch      : A  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 10:
      mvprintw ((6), 1, "pitch      : Bb %+2d (%+3d)", oct, pv_pitch);
      break;
    case 11:
      mvprintw ((6), 1, "pitch      : B  %+2d (%+3d)", oct, pv_pitch);
      break;
    default:
      break;
    }
}

canonical_original_code:
static void curses_print_pitch(int pv_pitch)
{
  int oct;
  int key;
  if (pv_pitch < 0)
    {
      oct = (-pv_pitch-1) / 12;
      oct = -oct-1;
      key = (-pv_pitch-1) % 12;
      key = 11-key;
    }
  else
    {
      oct = pv_pitch / 12;
      key = pv_pitch % 12;
    }
  switch (key)
    {
    case 0:
      mvprintw ((6), 1, "pitch      : C  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 1:
      mvprintw ((6), 1, "pitch      : C# %+2d (%+3d)", oct, pv_pitch);
      break;
    case 2:
      mvprintw ((6), 1, "pitch      : D  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 3:
      mvprintw ((6), 1, "pitch      : Eb %+2d (%+3d)", oct, pv_pitch);
      break;
    case 4:
      mvprintw ((6), 1, "pitch      : E  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 5:
      mvprintw ((6), 1, "pitch      : F  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 6:
      mvprintw ((6), 1, "pitch      : F# %+2d (%+3d)", oct, pv_pitch);
      break;
    case 7:
      mvprintw ((6), 1, "pitch      : G  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 8:
      mvprintw ((6), 1, "pitch      : G# %+2d (%+3d)", oct, pv_pitch);
      break;
    case 9:
      mvprintw ((6), 1, "pitch      : A  %+2d (%+3d)", oct, pv_pitch);
      break;
    case 10:
      mvprintw ((6), 1, "pitch      : Bb %+2d (%+3d)", oct, pv_pitch);
      break;
    case 11:
      mvprintw ((6), 1, "pitch      : B  %+2d (%+3d)", oct, pv_pitch);
      break;
    default:
      break;
    }
}

variable_types: oct int

variable_types: key int


decompiled_code:
int __fastcall sndfile_print_info(unsigned int *a1)
{
int v1; // eax
int v2; // eax

v1 = a1[4] & 0xFFF0000;
if ( v1 == 786432 )
{
fwrite("Format: Matlab (tm) V4.2 / GNU Octave 2.0\n", 1uLL, 0x2AuLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) > 0xC0000 )
{
if ( v1 == 1179648 )
{
fwrite("Format: Audio Visual Research\n", 1uLL, 0x1EuLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x120000 )
{
if ( v1 == 983040 )
{
fwrite("Format: Fasttracker 2 Extended Instrument\n", 1uLL, 0x2AuLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0xF0000 )
{
if ( v1 == 851968 )
{
fwrite("Format: Matlab (tm) V5.0 / GNU Octave 2.1\n", 1uLL, 0x2AuLL, stderr);
}
else
{
if ( v1 != 917504 )
goto LABEL_51;
fwrite("Format: Portable Voice Format\n", 1uLL, 0x1EuLL, stderr);
}
}
else if ( v1 == 0x100000 )
{
fwrite("Format: HMM Tool Kit format\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( v1 != 1114112 )
goto LABEL_51;
fwrite("Format: Midi Sample Dump Standard\n", 1uLL, 0x22uLL, stderr);
}
}
else if ( v1 == 1507328 )
{
fwrite("Format: FLAC lossless file format\n", 1uLL, 0x22uLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x170000 )
{
if ( v1 == 1245184 )
{
fwrite("Format: MS WAVE with WAVEFORMATEX\n", 1uLL, 0x22uLL, stderr);
}
else
{
if ( v1 != 1441792 )
goto LABEL_51;
fwrite("Format: Sound Designer 2\n", 1uLL, 0x19uLL, stderr);
}
}
else
{
if ( v1 != 1572864 )
goto LABEL_51;
fwrite("Format: Core Audio File format\n", 1uLL, 0x1FuLL, stderr);
}
}
else if ( v1 == 393216 )
{
fwrite("Format: Amiga IFF / SVX8 / SV16 format.\n", 1uLL, 0x28uLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x60000 )
{
if ( v1 == 196608 )
{
fwrite("Format: Sun/NeXT AU format (big endian).\n", 1uLL, 0x29uLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x30000 )
{
if ( v1 == 0x10000 )
{
fwrite("Format: Microsoft WAV format (little endian default).\n", 1uLL, 0x36uLL, stderr);
}
else
{
if ( v1 != 0x20000 )
goto LABEL_51;
fwrite("Format: Apple/SGI AIFF format (big endian).\n", 1uLL, 0x2CuLL, stderr);
}
}
else if ( v1 == 0x40000 )
{
fwrite("Format: RAW PCM data.\n", 1uLL, 0x16uLL, stderr);
}
else
{
if ( v1 != 327680 )
goto LABEL_51;
fwrite("Format: Ensoniq PARIS file format.\n", 1uLL, 0x23uLL, stderr);
}
}
else if ( v1 == 655360 )
{
fwrite("Format: Berkeley/IRCAM/CARL\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( (a1[4] & 0xFFF0000) > 0xA0000 )
{
if ( v1 == 720896 )
{
fwrite("Format: Sonic Foundry's 64 bit RIFF/WAV\n", 1uLL, 0x28uLL, stderr);
goto LABEL_38;
}
LABEL_51:
fwrite("unknown Subtype\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
if ( v1 == 458752 )
{
fwrite("Format: Sphere NIST format.\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( v1 != 0x80000 )
goto LABEL_51;
fwrite("Format: VOC files.\n", 1uLL, 0x13uLL, stderr);
}
}
LABEL_38:
switch ( *((_WORD *)a1 + 8) )
{
case 1:
fwrite("Subtype: Signed 8 bit data\n", 1uLL, 0x1BuLL, stderr);
break;
case 2:
fwrite("Subtype: Signed 16 bit data\n", 1uLL, 0x1CuLL, stderr);
break;
case 3:
fwrite("Subtype: Signed 24 bit data\n", 1uLL, 0x1CuLL, stderr);
break;
case 4:
fwrite("Subtype: Signed 32 bit data\n", 1uLL, 0x1CuLL, stderr);
break;
case 5:
fwrite("Subtype: Unsigned 8 bit data (WAV and RAW only)\n", 1uLL, 0x30uLL, stderr);
break;
case 6:
fwrite("Subtype: 32 bit float data\n", 1uLL, 0x1BuLL, stderr);
break;
case 7:
fwrite("Subtype: 64 bit float data\n", 1uLL, 0x1BuLL, stderr);
break;
case 0x10:
fwrite("Subtype: U-Law encoded.\n", 1uLL, 0x18uLL, stderr);
break;
case 0x11:
fwrite("Subtype: A-Law encoded.\n", 1uLL, 0x18uLL, stderr);
break;
case 0x12:
fwrite("Subtype: IMA ADPCM.\n", 1uLL, 0x14uLL, stderr);
break;
case 0x13:
fwrite("Subtype: Microsoft ADPCM.\n", 1uLL, 0x1AuLL, stderr);
break;
case 0x20:
fwrite("Subtype: GSM 6.10 encoding.\n", 1uLL, 0x1CuLL, stderr);
break;
case 0x21:
fwrite("Subtype: Oki Dialogic ADPCM encoding.\n", 1uLL, 0x26uLL, stderr);
break;
case 0x30:
fwrite("Subtype: 32kbs G721 ADPCM encoding.\n", 1uLL, 0x24uLL, stderr);
break;
case 0x31:
fwrite("Subtype: 24kbs G723 ADPCM encoding.\n", 1uLL, 0x24uLL, stderr);
break;
case 0x32:
fwrite("Subtype: 40kbs G723 ADPCM encoding.\n", 1uLL, 0x24uLL, stderr);
break;
case 0x40:
fwrite("Subtype: 12 bit Delta Width Variable Word encoding.\n", 1uLL, 0x34uLL, stderr);
break;
case 0x41:
fwrite("Subtype: 16 bit Delta Width Variable Word encoding.\n", 1uLL, 0x34uLL, stderr);
break;
case 0x42:
fwrite("Subtype: 24 bit Delta Width Variable Word encoding.\n", 1uLL, 0x34uLL, stderr);
break;
case 0x43:
fwrite("Subtype: N bit Delta Width Variable Word encoding.\n", 1uLL, 0x33uLL, stderr);
break;
case 0x50:
fwrite("Subtype: 8 bit differential PCM (XI only)\n", 1uLL, 0x2AuLL, stderr);
break;
case 0x51:
fwrite("Subtype: 16 bit differential PCM (XI only)\n", 1uLL, 0x2BuLL, stderr);
break;
default:
fwrite("unknown Subtype\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
v2 = a1[4] & 0x30000000;
if ( v2 == 0x20000000 )
{
fwrite("Endian type: Force big endian-ness.\n", 1uLL, 0x24uLL, stderr);
goto LABEL_83;
}
if ( (a1[4] & 0x30000000) > 0x20000000 )
{
if ( v2 == 805306368 )
{
fwrite("Endian type: Force CPU endian-ness.\n", 1uLL, 0x24uLL, stderr);
goto LABEL_83;
}
LABEL_85:
fwrite("unknown Endian type\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
if ( !v2 )
{
fwrite("Endian type: Default file endian-ness.\n", 1uLL, 0x27uLL, stderr);
goto LABEL_83;
}
if ( v2 != 0x10000000 )
goto LABEL_85;
fwrite("Endian type: Force little endian-ness.\n", 1uLL, 0x27uLL, stderr);
LABEL_83:
fprintf(stderr, "frames : %d\n", *a1);
fprintf(stderr, "samplerate : %d\n", a1[2]);
fprintf(stderr, "channels : %d\n", a1[3]);
fprintf(stderr, "sections : %d\n", a1[5]);
return fprintf(stderr, "seekable : %d\n", a1[6]);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
int v1; // eax
int v2; // eax

v1 = a1[4] & 0xFFF0000;
if ( v1 == 786432 )
{
fwrite("Format: Matlab (tm) V4.2 / GNU Octave 2.0\n", 1uLL, 0x2AuLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) > 0xC0000 )
{
if ( v1 == 1179648 )
{
fwrite("Format: Audio Visual Research\n", 1uLL, 0x1EuLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x120000 )
{
if ( v1 == 983040 )
{
fwrite("Format: Fasttracker 2 Extended Instrument\n", 1uLL, 0x2AuLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0xF0000 )
{
if ( v1 == 851968 )
{
fwrite("Format: Matlab (tm) V5.0 / GNU Octave 2.1\n", 1uLL, 0x2AuLL, stderr);
}
else
{
if ( v1 != 917504 )
goto LABEL_51;
fwrite("Format: Portable Voice Format\n", 1uLL, 0x1EuLL, stderr);
}
}
else if ( v1 == 0x100000 )
{
fwrite("Format: HMM Tool Kit format\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( v1 != 1114112 )
goto LABEL_51;
fwrite("Format: Midi Sample Dump Standard\n", 1uLL, 0x22uLL, stderr);
}
}
else if ( v1 == 1507328 )
{
fwrite("Format: FLAC lossless file format\n", 1uLL, 0x22uLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x170000 )
{
if ( v1 == 1245184 )
{
fwrite("Format: MS WAVE with WAVEFORMATEX\n", 1uLL, 0x22uLL, stderr);
}
else
{
if ( v1 != 1441792 )
goto LABEL_51;
fwrite("Format: Sound Designer 2\n", 1uLL, 0x19uLL, stderr);
}
}
else
{
if ( v1 != 1572864 )
goto LABEL_51;
fwrite("Format: Core Audio File format\n", 1uLL, 0x1FuLL, stderr);
}
}
else if ( v1 == 393216 )
{
fwrite("Format: Amiga IFF / SVX8 / SV16 format.\n", 1uLL, 0x28uLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x60000 )
{
if ( v1 == 196608 )
{
fwrite("Format: Sun/NeXT AU format (big endian).\n", 1uLL, 0x29uLL, stderr);
}
else if ( (a1[4] & 0xFFF0000) <= 0x30000 )
{
if ( v1 == 0x10000 )
{
fwrite("Format: Microsoft WAV format (little endian default).\n", 1uLL, 0x36uLL, stderr);
}
else
{
if ( v1 != 0x20000 )
goto LABEL_51;
fwrite("Format: Apple/SGI AIFF format (big endian).\n", 1uLL, 0x2CuLL, stderr);
}
}
else if ( v1 == 0x40000 )
{
fwrite("Format: RAW PCM data.\n", 1uLL, 0x16uLL, stderr);
}
else
{
if ( v1 != 327680 )
goto LABEL_51;
fwrite("Format: Ensoniq PARIS file format.\n", 1uLL, 0x23uLL, stderr);
}
}
else if ( v1 == 655360 )
{
fwrite("Format: Berkeley/IRCAM/CARL\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( (a1[4] & 0xFFF0000) > 0xA0000 )
{
if ( v1 == 720896 )
{
fwrite("Format: Sonic Foundry's 64 bit RIFF/WAV\n", 1uLL, 0x28uLL, stderr);
goto LABEL_38;
}
LABEL_51:
fwrite("unknown Subtype\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
if ( v1 == 458752 )
{
fwrite("Format: Sphere NIST format.\n", 1uLL, 0x1CuLL, stderr);
}
else
{
if ( v1 != 0x80000 )
goto LABEL_51;
fwrite("Format: VOC files.\n", 1uLL, 0x13uLL, stderr);
}
}
LABEL_38:
switch ( *((_WORD *)a1 + 8) )
{
case 1:
fwrite("Subtype: Signed 8 bit data\n", 1uLL, 0x1BuLL, stderr);
break;
case 2:
fwrite("Subtype: Signed 16 bit data\n", 1uLL, 0x1CuLL, stderr);
break;
case 3:
fwrite("Subtype: Signed 24 bit data\n", 1uLL, 0x1CuLL, stderr);
break;
case 4:
fwrite("Subtype: Signed 32 bit data\n", 1uLL, 0x1CuLL, stderr);
break;
case 5:
fwrite("Subtype: Unsigned 8 bit data (WAV and RAW only)\n", 1uLL, 0x30uLL, stderr);
break;
case 6:
fwrite("Subtype: 32 bit float data\n", 1uLL, 0x1BuLL, stderr);
break;
case 7:
fwrite("Subtype: 64 bit float data\n", 1uLL, 0x1BuLL, stderr);
break;
case 0x10:
fwrite("Subtype: U-Law encoded.\n", 1uLL, 0x18uLL, stderr);
break;
case 0x11:
fwrite("Subtype: A-Law encoded.\n", 1uLL, 0x18uLL, stderr);
break;
case 0x12:
fwrite("Subtype: IMA ADPCM.\n", 1uLL, 0x14uLL, stderr);
break;
case 0x13:
fwrite("Subtype: Microsoft ADPCM.\n", 1uLL, 0x1AuLL, stderr);
break;
case 0x20:
fwrite("Subtype: GSM 6.10 encoding.\n", 1uLL, 0x1CuLL, stderr);
break;
case 0x21:
fwrite("Subtype: Oki Dialogic ADPCM encoding.\n", 1uLL, 0x26uLL, stderr);
break;
case 0x30:
fwrite("Subtype: 32kbs G721 ADPCM encoding.\n", 1uLL, 0x24uLL, stderr);
break;
case 0x31:
fwrite("Subtype: 24kbs G723 ADPCM encoding.\n", 1uLL, 0x24uLL, stderr);
break;
case 0x32:
fwrite("Subtype: 40kbs G723 ADPCM encoding.\n", 1uLL, 0x24uLL, stderr);
break;
case 0x40:
fwrite("Subtype: 12 bit Delta Width Variable Word encoding.\n", 1uLL, 0x34uLL, stderr);
break;
case 0x41:
fwrite("Subtype: 16 bit Delta Width Variable Word encoding.\n", 1uLL, 0x34uLL, stderr);
break;
case 0x42:
fwrite("Subtype: 24 bit Delta Width Variable Word encoding.\n", 1uLL, 0x34uLL, stderr);
break;
case 0x43:
fwrite("Subtype: N bit Delta Width Variable Word encoding.\n", 1uLL, 0x33uLL, stderr);
break;
case 0x50:
fwrite("Subtype: 8 bit differential PCM (XI only)\n", 1uLL, 0x2AuLL, stderr);
break;
case 0x51:
fwrite("Subtype: 16 bit differential PCM (XI only)\n", 1uLL, 0x2BuLL, stderr);
break;
default:
fwrite("unknown Subtype\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
v2 = a1[4] & 0x30000000;
if ( v2 == 0x20000000 )
{
fwrite("Endian type: Force big endian-ness.\n", 1uLL, 0x24uLL, stderr);
goto LABEL_83;
}
if ( (a1[4] & 0x30000000) > 0x20000000 )
{
if ( v2 == 805306368 )
{
fwrite("Endian type: Force CPU endian-ness.\n", 1uLL, 0x24uLL, stderr);
goto LABEL_83;
}
LABEL_85:
fwrite("unknown Endian type\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
if ( !v2 )
{
fwrite("Endian type: Default file endian-ness.\n", 1uLL, 0x27uLL, stderr);
goto LABEL_83;
}
if ( v2 != 0x10000000 )
goto LABEL_85;
fwrite("Endian type: Force little endian-ness.\n", 1uLL, 0x27uLL, stderr);
LABEL_83:
fprintf(stderr, "frames : %d\n", *a1);
fprintf(stderr, "samplerate : %d\n", a1[2]);
fprintf(stderr, "channels : %d\n", a1[3]);
fprintf(stderr, "sections : %d\n", a1[5]);
return fprintf(stderr, "seekable : %d\n", a1[6]);
}

original_code:
void sndfile_print_info (SF_INFO *sfinfo)
{
  switch (sfinfo->format & SF_FORMAT_TYPEMASK)
    {
    case SF_FORMAT_WAV:
      fprintf (stderr, "Format: Microsoft WAV format (little endian default).\n");
      break;
    case SF_FORMAT_AIFF:
      fprintf (stderr, "Format: Apple/SGI AIFF format (big endian).\n");
      break;
    case SF_FORMAT_AU:
      fprintf (stderr, "Format: Sun/NeXT AU format (big endian).\n");
      break;
    case SF_FORMAT_RAW:
      fprintf (stderr, "Format: RAW PCM data.\n");
      break;
    case SF_FORMAT_PAF:
      fprintf (stderr, "Format: Ensoniq PARIS file format.\n");
      break;
    case SF_FORMAT_SVX:
      fprintf (stderr, "Format: Amiga IFF / SVX8 / SV16 format.\n");
      break;
    case SF_FORMAT_NIST:
      fprintf (stderr, "Format: Sphere NIST format.\n");
      break;
    case SF_FORMAT_VOC:
      fprintf (stderr, "Format: VOC files.\n");
      break;
    case SF_FORMAT_IRCAM:
      fprintf (stderr, "Format: Berkeley/IRCAM/CARL\n");
      break;
    case SF_FORMAT_W64:
      fprintf (stderr, "Format: Sonic Foundry's 64 bit RIFF/WAV\n");
      break;
    case SF_FORMAT_MAT4:
      fprintf (stderr, "Format: Matlab (tm) V4.2 / GNU Octave 2.0\n");
      break;
    case SF_FORMAT_MAT5:
      fprintf (stderr, "Format: Matlab (tm) V5.0 / GNU Octave 2.1\n");
      break;
    case SF_FORMAT_PVF:
      fprintf (stderr, "Format: Portable Voice Format\n");
      break;
    case SF_FORMAT_XI:
      fprintf (stderr, "Format: Fasttracker 2 Extended Instrument\n");
      break;
    case SF_FORMAT_HTK:
      fprintf (stderr, "Format: HMM Tool Kit format\n");
      break;
    case SF_FORMAT_SDS:
      fprintf (stderr, "Format: Midi Sample Dump Standard\n");
      break;
    case SF_FORMAT_AVR:
      fprintf (stderr, "Format: Audio Visual Research\n");
      break;
    case SF_FORMAT_WAVEX:
      fprintf (stderr, "Format: MS WAVE with WAVEFORMATEX\n");
      break;
    case SF_FORMAT_SD2:
      fprintf (stderr, "Format: Sound Designer 2\n");
      break;
    case SF_FORMAT_FLAC:
      fprintf (stderr, "Format: FLAC lossless file format\n");
      break;
    case SF_FORMAT_CAF:
      fprintf (stderr, "Format: Core Audio File format\n");
      break;
    default :
      fprintf (stderr, "unknown Subtype\n");
      exit (1);
    }
  switch (sfinfo->format & SF_FORMAT_SUBMASK)
    {
    case SF_FORMAT_PCM_S8:
      fprintf (stderr, "Subtype: Signed 8 bit data\n");
      break;
    case SF_FORMAT_PCM_16:
      fprintf (stderr, "Subtype: Signed 16 bit data\n");
      break;
    case SF_FORMAT_PCM_24:
      fprintf (stderr, "Subtype: Signed 24 bit data\n");
      break;
    case SF_FORMAT_PCM_32:
      fprintf (stderr, "Subtype: Signed 32 bit data\n");
      break;
    case SF_FORMAT_PCM_U8:
      fprintf (stderr, "Subtype: Unsigned 8 bit data (WAV and RAW only)\n");
      break;
    case SF_FORMAT_FLOAT:
      fprintf (stderr, "Subtype: 32 bit float data\n");
      break;
    case SF_FORMAT_DOUBLE:
      fprintf (stderr, "Subtype: 64 bit float data\n");
      break;
    case SF_FORMAT_ULAW:
      fprintf (stderr, "Subtype: U-Law encoded.\n");
      break;
    case SF_FORMAT_ALAW:
      fprintf (stderr, "Subtype: A-Law encoded.\n");
      break;
    case SF_FORMAT_IMA_ADPCM:
      fprintf (stderr, "Subtype: IMA ADPCM.\n");
      break;
    case SF_FORMAT_MS_ADPCM:
      fprintf (stderr, "Subtype: Microsoft ADPCM.\n");
      break;
    case SF_FORMAT_GSM610:
      fprintf (stderr, "Subtype: GSM 6.10 encoding.\n");
      break;
    case SF_FORMAT_VOX_ADPCM:
      fprintf (stderr, "Subtype: Oki Dialogic ADPCM encoding.\n");
      break;
    case SF_FORMAT_G721_32:
      fprintf (stderr, "Subtype: 32kbs G721 ADPCM encoding.\n");
      break;
    case SF_FORMAT_G723_24:
      fprintf (stderr, "Subtype: 24kbs G723 ADPCM encoding.\n");
      break;
    case SF_FORMAT_G723_40:
      fprintf (stderr, "Subtype: 40kbs G723 ADPCM encoding.\n");
      break;
    case SF_FORMAT_DWVW_12:
      fprintf (stderr, "Subtype: 12 bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DWVW_16:
      fprintf (stderr, "Subtype: 16 bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DWVW_24:
      fprintf (stderr, "Subtype: 24 bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DWVW_N:
      fprintf (stderr, "Subtype: N bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DPCM_8:
      fprintf (stderr, "Subtype: 8 bit differential PCM (XI only)\n");
      break;
    case SF_FORMAT_DPCM_16:
      fprintf (stderr, "Subtype: 16 bit differential PCM (XI only)\n");
      break;
    default :
      fprintf (stderr, "unknown Subtype\n");
      exit (1);
    }
  switch (sfinfo->format & SF_FORMAT_ENDMASK)
    {
    case SF_ENDIAN_FILE:
      fprintf (stderr, "Endian type: Default file endian-ness.\n");
      break;
    case SF_ENDIAN_LITTLE:
      fprintf (stderr, "Endian type: Force little endian-ness.\n");
      break;
    case SF_ENDIAN_BIG:
      fprintf (stderr, "Endian type: Force big endian-ness.\n");
      break;
    case SF_ENDIAN_CPU:
      fprintf (stderr, "Endian type: Force CPU endian-ness.\n");
      break;
    default :
      fprintf (stderr, "unknown Endian type\n");
      exit (1);
    }
  fprintf (stderr, "frames     : %d\n", (int)sfinfo->frames);
  fprintf (stderr, "samplerate : %d\n", sfinfo->samplerate);
  fprintf (stderr, "channels   : %d\n", sfinfo->channels);
  fprintf (stderr, "sections   : %d\n", sfinfo->sections);
  fprintf (stderr, "seekable   : %d\n", sfinfo->seekable);
}

canonical_original_code:
void sndfile_print_info(struct SF_INFO *sfinfo)
{
  switch (sfinfo->format & SF_FORMAT_TYPEMASK)
    {
    case SF_FORMAT_WAV:
      fprintf (stderr, "Format: Microsoft WAV format (little endian default).\n");
      break;
    case SF_FORMAT_AIFF:
      fprintf (stderr, "Format: Apple/SGI AIFF format (big endian).\n");
      break;
    case SF_FORMAT_AU:
      fprintf (stderr, "Format: Sun/NeXT AU format (big endian).\n");
      break;
    case SF_FORMAT_RAW:
      fprintf (stderr, "Format: RAW PCM data.\n");
      break;
    case SF_FORMAT_PAF:
      fprintf (stderr, "Format: Ensoniq PARIS file format.\n");
      break;
    case SF_FORMAT_SVX:
      fprintf (stderr, "Format: Amiga IFF / SVX8 / SV16 format.\n");
      break;
    case SF_FORMAT_NIST:
      fprintf (stderr, "Format: Sphere NIST format.\n");
      break;
    case SF_FORMAT_VOC:
      fprintf (stderr, "Format: VOC files.\n");
      break;
    case SF_FORMAT_IRCAM:
      fprintf (stderr, "Format: Berkeley/IRCAM/CARL\n");
      break;
    case SF_FORMAT_W64:
      fprintf (stderr, "Format: Sonic Foundry's 64 bit RIFF/WAV\n");
      break;
    case SF_FORMAT_MAT4:
      fprintf (stderr, "Format: Matlab (tm) V4.2 / GNU Octave 2.0\n");
      break;
    case SF_FORMAT_MAT5:
      fprintf (stderr, "Format: Matlab (tm) V5.0 / GNU Octave 2.1\n");
      break;
    case SF_FORMAT_PVF:
      fprintf (stderr, "Format: Portable Voice Format\n");
      break;
    case SF_FORMAT_XI:
      fprintf (stderr, "Format: Fasttracker 2 Extended Instrument\n");
      break;
    case SF_FORMAT_HTK:
      fprintf (stderr, "Format: HMM Tool Kit format\n");
      break;
    case SF_FORMAT_SDS:
      fprintf (stderr, "Format: Midi Sample Dump Standard\n");
      break;
    case SF_FORMAT_AVR:
      fprintf (stderr, "Format: Audio Visual Research\n");
      break;
    case SF_FORMAT_WAVEX:
      fprintf (stderr, "Format: MS WAVE with WAVEFORMATEX\n");
      break;
    case SF_FORMAT_SD2:
      fprintf (stderr, "Format: Sound Designer 2\n");
      break;
    case SF_FORMAT_FLAC:
      fprintf (stderr, "Format: FLAC lossless file format\n");
      break;
    case SF_FORMAT_CAF:
      fprintf (stderr, "Format: Core Audio File format\n");
      break;
    default :
      fprintf (stderr, "unknown Subtype\n");
      exit (1);
    }
  switch (sfinfo->format & SF_FORMAT_SUBMASK)
    {
    case SF_FORMAT_PCM_S8:
      fprintf (stderr, "Subtype: Signed 8 bit data\n");
      break;
    case SF_FORMAT_PCM_16:
      fprintf (stderr, "Subtype: Signed 16 bit data\n");
      break;
    case SF_FORMAT_PCM_24:
      fprintf (stderr, "Subtype: Signed 24 bit data\n");
      break;
    case SF_FORMAT_PCM_32:
      fprintf (stderr, "Subtype: Signed 32 bit data\n");
      break;
    case SF_FORMAT_PCM_U8:
      fprintf (stderr, "Subtype: Unsigned 8 bit data (WAV and RAW only)\n");
      break;
    case SF_FORMAT_FLOAT:
      fprintf (stderr, "Subtype: 32 bit float data\n");
      break;
    case SF_FORMAT_DOUBLE:
      fprintf (stderr, "Subtype: 64 bit float data\n");
      break;
    case SF_FORMAT_ULAW:
      fprintf (stderr, "Subtype: U-Law encoded.\n");
      break;
    case SF_FORMAT_ALAW:
      fprintf (stderr, "Subtype: A-Law encoded.\n");
      break;
    case SF_FORMAT_IMA_ADPCM:
      fprintf (stderr, "Subtype: IMA ADPCM.\n");
      break;
    case SF_FORMAT_MS_ADPCM:
      fprintf (stderr, "Subtype: Microsoft ADPCM.\n");
      break;
    case SF_FORMAT_GSM610:
      fprintf (stderr, "Subtype: GSM 6.10 encoding.\n");
      break;
    case SF_FORMAT_VOX_ADPCM:
      fprintf (stderr, "Subtype: Oki Dialogic ADPCM encoding.\n");
      break;
    case SF_FORMAT_G721_32:
      fprintf (stderr, "Subtype: 32kbs G721 ADPCM encoding.\n");
      break;
    case SF_FORMAT_G723_24:
      fprintf (stderr, "Subtype: 24kbs G723 ADPCM encoding.\n");
      break;
    case SF_FORMAT_G723_40:
      fprintf (stderr, "Subtype: 40kbs G723 ADPCM encoding.\n");
      break;
    case SF_FORMAT_DWVW_12:
      fprintf (stderr, "Subtype: 12 bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DWVW_16:
      fprintf (stderr, "Subtype: 16 bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DWVW_24:
      fprintf (stderr, "Subtype: 24 bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DWVW_N:
      fprintf (stderr, "Subtype: N bit Delta Width Variable Word encoding.\n");
      break;
    case SF_FORMAT_DPCM_8:
      fprintf (stderr, "Subtype: 8 bit differential PCM (XI only)\n");
      break;
    case SF_FORMAT_DPCM_16:
      fprintf (stderr, "Subtype: 16 bit differential PCM (XI only)\n");
      break;
    default :
      fprintf (stderr, "unknown Subtype\n");
      exit (1);
    }
  switch (sfinfo->format & SF_FORMAT_ENDMASK)
    {
    case SF_ENDIAN_FILE:
      fprintf (stderr, "Endian type: Default file endian-ness.\n");
      break;
    case SF_ENDIAN_LITTLE:
      fprintf (stderr, "Endian type: Force little endian-ness.\n");
      break;
    case SF_ENDIAN_BIG:
      fprintf (stderr, "Endian type: Force big endian-ness.\n");
      break;
    case SF_ENDIAN_CPU:
      fprintf (stderr, "Endian type: Force CPU endian-ness.\n");
      break;
    default :
      fprintf (stderr, "unknown Endian type\n");
      exit (1);
    }
  fprintf (stderr, "frames     : %d\n", (int)sfinfo->frames);
  fprintf (stderr, "samplerate : %d\n", sfinfo->samplerate);
  fprintf (stderr, "channels   : %d\n", sfinfo->channels);
  fprintf (stderr, "sections   : %d\n", sfinfo->sections);
  fprintf (stderr, "seekable   : %d\n", sfinfo->seekable);
}

variable_types: struct SF_INFO { long frames; int samplerate; int channels; int format; int sections; int seekable; } *


decompiled_code:
__int64 __fastcall check_filetype_by_extension(const char *a1)
{
__int64 v1; // rax
const char *v2; // rdx
unsigned int v3; // edx
const char *v5; // rax
bool v6; // zf

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 < 0 )
{
LABEL_5:
v1 = (int)v1;
v3 = -1;
if ( a1[(int)v1] != 46 )
return v3;
}
else
{
v2 = &a1[(int)v1];
while ( *v2 != 46 )
{
LODWORD(v1) = v1 - 1;
--v2;
if ( (_DWORD)v1 == -1 )
goto LABEL_5;
}
v1 = (int)v1;
}
v5 = &a1[v1 + 1];
v6 = strcmp(v5, "wav") == 0;
v3 = !v6;
if ( !v6 )
v3 = strcmp(v5, "flac") == 0 ? 1 : -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 v1; // rax
const char *v2; // rdx
unsigned int v3; // edx
const char *v5; // rax
bool v6; // zf

LODWORD(v1) = strlen(a1) - 1;
if ( (int)v1 < 0 )
{
LABEL_5:
v1 = (int)v1;
v3 = -1;
if ( a1[(int)v1] != 46 )
return v3;
}
else
{
v2 = &a1[(int)v1];
while ( *v2 != 46 )
{
LODWORD(v1) = v1 - 1;
--v2;
if ( (_DWORD)v1 == -1 )
goto LABEL_5;
}
v1 = (int)v1;
}
v5 = &a1[v1 + 1];
v6 = strcmp(v5, "wav") == 0;
v3 = !v6;
if ( !v6 )
v3 = strcmp(v5, "flac") == 0 ? 1 : -1;
return v3;
}

original_code:
int check_filetype_by_extension (const char *file)
{
  int len;
  len = strlen (file);
  int i;
  for (i = len-1; i >= 0; i--)
    {
      if (file [i] == '.') break;
    }
  if (file [i] != '.') return -1;
  else if (strcmp (file + i + 1, "wav") == 0) return 0;
  else if (strcmp (file + i + 1, "flac") == 0) return 1;
  else return -1;
}

canonical_original_code:
int check_filetype_by_extension(char *file)
{
  int len;
  len = strlen (file);
  int i;
  for (i = len-1; i >= 0; i--)
    {
      if (file [i] == '.') break;
    }
  if (file [i] != '.') return -1;
  else if (strcmp (file + i + 1, "wav") == 0) return 0;
  else if (strcmp (file + i + 1, "flac") == 0) return 1;
  else return -1;
}

variable_types:
file
char *

variable_types: len int

variable_types: i int

return_type: int


repo: kichiki/stokes

original_code:
static int
check_overlap (int np, double lx, double ly, double lz, double * pos)
{
  int i;
  int ix, iy, iz;
  int j;
  int jx, jy, jz;
  int kx, ky, kz;
  double rr;
  double x, y, z;
  for (i = 0; i < np; ++i)
    {
      ix = i * 3;
      iy = ix + 1;
      iz = ix + 2;
      for (j = i + 1; j < np; ++j)
 {
   jx = j * 3;
   jy = jx + 1;
   jz = jx + 2;
   for (kx = -1; kx <= 1; ++kx)
     {
       for (ky = -1; ky <= 1; ++ky)
  {
    for (kz = -1; kz <= 1; ++kz)
      {
        x = pos [ix] - pos [jx] + (double) kx * lx;
        y = pos [iy] - pos [jy] + (double) ky * ly;
        z = pos [iz] - pos [jz] + (double) kz * lz;
        rr = x * x
   + y * y
   + z * z;
        if (rr <= 4.0)
   {
     return 1;
   }
      }
  }
     }
 }
    }
  return 0;
}

canonical_original_code:
static int check_overlap(int np, double lx, double ly, double lz, double *pos)
{
  int i;
  int ix; int iy; int iz;
  int j;
  int jx; int jy; int jz;
  int kx; int ky; int kz;
  double rr;
  double x; double y; double z;
  for (i = 0; i < np; ++i)
    {
      ix = i * 3;
      iy = ix + 1;
      iz = ix + 2;
      for (j = i + 1; j < np; ++j)
 {
   jx = j * 3;
   jy = jx + 1;
   jz = jx + 2;
   for (kx = -1; kx <= 1; ++kx)
     {
       for (ky = -1; ky <= 1; ++ky)
  {
    for (kz = -1; kz <= 1; ++kz)
      {
        x = pos [ix] - pos [jx] + (double) kx * lx;
        y = pos [iy] - pos [jy] + (double) ky * ly;
        z = pos [iz] - pos [jz] + (double) kz * lz;
        rr = x * x
   + y * y
   + z * z;
        if (rr <= 4.0)
   {
     return 1;
   }
      }
  }
     }
 }
    }
  return 0;
}

variable_types: np int

variable_types: lx double

variable_types: ly double

variable_types: lz double

variable_types:
pos
double *

variable_types: ix int

variable_types: iy int

variable_types: iz int

variable_types: j int

variable_types: jx int

variable_types: jy int

variable_types: jz int

variable_types: kx int

variable_types: ky int

variable_types: kz int

variable_types: rr double

variable_types: x double

variable_types: y double

variable_types: z double


original_code:
void
init_config_SC (double phi, int nx, int ny, int nz,
  double *pos, double *lx, double *ly, double *lz)
{
  int j;
  int ix, iy, iz;
  (*lx) = (*ly) = (*lz) = pow (4.0 * 3.14159265358979323846 / phi / 3.0, 1.0 / 3.0);
  j = 0;
  for (ix = 0; ix < nx; ix ++)
    {
      for (iy = 0; iy < ny; iy ++)
 {
   for (iz = 0; iz < nz; iz ++)
     {
       pos [j * 3 + 0] = (double) ix * (*lx);
       pos [j * 3 + 1] = (double) iy * (*ly);
       pos [j * 3 + 2] = (double) iz * (*lz);
       j ++;
     }
 }
    }
  (*lx) *= (double) nx;
  (*ly) *= (double) ny;
  (*lz) *= (double) nz;
}

canonical_original_code:
void init_config_SC(double phi, int nx, int ny, int nz, double *pos, double *lx, double *ly, double *lz)
{
  int j;
  int ix; int iy; int iz;
  (*lx) = (*ly) = (*lz) = pow (4.0 * 3.14159265358979323846 / phi / 3.0, 1.0 / 3.0);
  j = 0;
  for (ix = 0; ix < nx; ix ++)
    {
      for (iy = 0; iy < ny; iy ++)
 {
   for (iz = 0; iz < nz; iz ++)
     {
       pos [j * 3 + 0] = (double) ix * (*lx);
       pos [j * 3 + 1] = (double) iy * (*ly);
       pos [j * 3 + 2] = (double) iz * (*lz);
       j ++;
     }
 }
    }
  (*lx) *= (double) nx;
  (*ly) *= (double) ny;
  (*lz) *= (double) nz;
}

variable_types: phi double

variable_types: nx int

variable_types: ny int

variable_types: nz int

variable_types:
lx
double *

variable_types:
ly
double *

variable_types:
lz
double *


original_code:
void
init_config_BCC (double phi, int nx, int ny, int nz,
   double *pos, double *lx, double *ly, double *lz)
{
  int j;
  int ix, iy, iz;
  (*lx) = (*ly) = (*lz) = pow (8.0 * 3.14159265358979323846 / phi / 3.0, 1.0 / 3.0);
  j = 0;
  for (ix = 0; ix < nx; ix ++)
    {
      for (iy = 0; iy < ny; iy ++)
 {
   for (iz = 0; iz < nz; iz ++)
     {
       pos [j * 3 + 0] = (double) ix * (*lx);
       pos [j * 3 + 1] = (double) iy * (*ly);
       pos [j * 3 + 2] = (double) iz * (*lz);
       j ++;
       pos [j * 3 + 0] = ((double) ix + 0.5) * (*lx);
       pos [j * 3 + 1] = ((double) iy + 0.5) * (*ly);
       pos [j * 3 + 2] = ((double) iz + 0.5) * (*lz);
       j ++;
     }
 }
    }
  (*lx) *= (double) nx;
  (*ly) *= (double) ny;
  (*lz) *= (double) nz;
}

canonical_original_code:
void init_config_BCC(double phi, int nx, int ny, int nz, double *pos, double *lx, double *ly, double *lz)
{
  int j;
  int ix; int iy; int iz;
  (*lx) = (*ly) = (*lz) = pow (8.0 * 3.14159265358979323846 / phi / 3.0, 1.0 / 3.0);
  j = 0;
  for (ix = 0; ix < nx; ix ++)
    {
      for (iy = 0; iy < ny; iy ++)
 {
   for (iz = 0; iz < nz; iz ++)
     {
       pos [j * 3 + 0] = (double) ix * (*lx);
       pos [j * 3 + 1] = (double) iy * (*ly);
       pos [j * 3 + 2] = (double) iz * (*lz);
       j ++;
       pos [j * 3 + 0] = ((double) ix + 0.5) * (*lx);
       pos [j * 3 + 1] = ((double) iy + 0.5) * (*ly);
       pos [j * 3 + 2] = ((double) iz + 0.5) * (*lz);
       j ++;
     }
 }
    }
  (*lx) *= (double) nx;
  (*ly) *= (double) ny;
  (*lz) *= (double) nz;
}

variable_types:
pos
double *

variable_types: j int

variable_types: ix int

variable_types: iy int

variable_types: iz int


original_code:
void
init_config_random (long seed,
      double phi, int np,
      double *pos, double *lx, double *ly, double *lz)
{
  int i;
  int ix, iy, iz;
  int i_tor = 1000;
  int j;
  srand48 (seed);
  (*lx) = (*ly) = (*lz)
    = pow (4.0 * 3.14159265358979323846 * (double) np / phi / 3.0,
    1.0 / 3.0);
  j = 0;
  for (i = 0; i < np; i ++)
    {
    retry_init_config_random:
      ix = i * 3;
      iy = ix + 1;
      iz = ix + 2;
      pos [ix] = (*lx) * drand48 ();
      pos [iy] = (*ly) * drand48 ();
      pos [iz] = (*lz) * drand48 ();
      if (check_overlap (i + 1, (*lx), (*ly), (*lz), pos) != 0)
 {
   ++j;
   if (j > i_tor)
     {
       j = 0;
       if (i > 0)
  --i;
     }
   goto retry_init_config_random;
 }
    }
}

canonical_original_code:
void init_config_random(long seed, double phi, int np, double *pos, double *lx, double *ly, double *lz)
{
  int i;
  int ix; int iy; int iz;
  int i_tor = 1000;
  int j;
  srand48 (seed);
  (*lx) = (*ly) = (*lz)
    = pow (4.0 * 3.14159265358979323846 * (double) np / phi / 3.0,
    1.0 / 3.0);
  j = 0;
  for (i = 0; i < np; i ++)
    {
    retry_init_config_random:
      ix = i * 3;
      iy = ix + 1;
      iz = ix + 2;
      pos [ix] = (*lx) * drand48 ();
      pos [iy] = (*ly) * drand48 ();
      pos [iz] = (*lz) * drand48 ();
      if (check_overlap (i + 1, (*lx), (*ly), (*lz), pos) != 0)
 {
   ++j;
   if (j > i_tor)
     {
       j = 0;
       if (i > 0)
  --i;
     }
   goto retry_init_config_random;
 }
    }
}

variable_types: seed long

variable_types: np int

variable_types: i int


decompiled_code:
__int64 __fastcall get_dir(const char *a1)
{
int v1; // eax
int v2; // edx
unsigned int v3; // eax
const char *i; // rdx
unsigned int v5; // ecx

v1 = strlen(a1);
if ( v1 <= 0 )
return (unsigned int)-1;
v2 = v1;
v3 = v1 - 1;
for ( i = &a1[v2 - 1]; ; --i )
{
v5 = v3;
if ( *i == 47 )
break;
if ( --v3 == -1 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // eax
int v2; // edx
unsigned int v3; // eax
const char *i; // rdx
unsigned int v5; // ecx

v1 = strlen(a1);
if ( v1 <= 0 )
return (unsigned int)-1;
v2 = v1;
v3 = v1 - 1;
for ( i = &a1[v2 - 1]; ; --i )
{
v5 = v3;
if ( *i == 47 )
break;
if ( --v3 == -1 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int
get_dir (const char * name)
{
  int len = strlen (name);
  int i;
  for (i = 0; i < len; i ++)
    {
      if (name [len-1-i] == '/')
 {
   return (len-1-i);
 }
    }
  return (-1);
}

canonical_original_code:
int get_dir(char *name)
{
  int len = strlen (name);
  int i;
  for (i = 0; i < len; i ++)
    {
      if (name [len-1-i] == '/')
 {
   return (len-1-i);
 }
    }
  return (-1);
}

variable_types:
name
char *

variable_types: len int


setcolour

repo: kidxin/Graphics-Experiment

decompiled_code:
void setcolour()
{
black = 0LL;
*((_DWORD *)&black + 2) = 0;
LODWORD(white) = LC1;
HIDWORD(white) = LC1;
*((_DWORD *)&white + 2) = LC1;
LODWORD(red) = LC1;
HIDWORD(red) = 0;
*((_DWORD *)&red + 2) = 0;
LODWORD(green) = 0;
*(__int64 *)((char *)&green + 4) = (unsigned int)LC1;
blue = 0LL;
*((_DWORD *)&blue + 2) = LC1;
LODWORD(yellow) = LC1;
*(__int64 *)((char *)&yellow + 4) = (unsigned int)LC1;
LODWORD(indigo) = 0;
HIDWORD(indigo) = LC1;
*((_DWORD *)&indigo + 2) = LC1;
LODWORD(magenta) = LC1;
HIDWORD(magenta) = 0;
*((_DWORD *)&magenta + 2) = LC1;
}

canonical_decompiled_code:
void func0()
{
black = 0LL;
*((_DWORD *)&black + 2) = 0;
LODWORD(white) = LC1;
HIDWORD(white) = LC1;
*((_DWORD *)&white + 2) = LC1;
LODWORD(red) = LC1;
HIDWORD(red) = 0;
*((_DWORD *)&red + 2) = 0;
LODWORD(green) = 0;
*(__int64 *)((char *)&green + 4) = (unsigned int)LC1;
blue = 0LL;
*((_DWORD *)&blue + 2) = LC1;
LODWORD(yellow) = LC1;
*(__int64 *)((char *)&yellow + 4) = (unsigned int)LC1;
LODWORD(indigo) = 0;
HIDWORD(indigo) = LC1;
*((_DWORD *)&indigo + 2) = LC1;
LODWORD(magenta) = LC1;
HIDWORD(magenta) = 0;
*((_DWORD *)&magenta + 2) = LC1;
}

original_code:
void setcolour()
{
 black.r = 0; black.g = 0; black.b = 0;
 white.r = 1; white.g = 1; white.b = 1;
 red.r = 1; red.g = 0; red.b = 0;
 green.r = 0; green.g = 1; green.b = 0;
 blue.r = 0; blue.g = 0; blue.b = 1;
 yellow.r = 1; yellow.g = 1; yellow.b = 0;
 indigo.r = 0; indigo.g = 1; indigo.b = 1;
 magenta.r = 1; magenta.g = 0; magenta.b = 1;
}


getred

decompiled_code:
__int64 __fastcall getred(__int64 a1)
{
unsigned int v2[3]; // [rsp+24h] [rbp-Ch] BYREF

glReadPixels((unsigned int)(a1 + 300), (unsigned int)(HIDWORD(a1) + 300), 1LL, 1LL, 6403LL, 5124LL, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v2[3]; // [rsp+24h] [rbp-Ch] BYREF

glReadPixels((unsigned int)(a1 + 300), (unsigned int)(HIDWORD(a1) + 300), 1LL, 1LL, 6403LL, 5124LL, v2);
return v2[0];
}

original_code:
int getred(struct point p)
{
 GLint pixel;
 glReadPixels(p.x + 300, p.y + 300, 1, 1, 0x1903, 0x1404, &pixel);
 return pixel;
}

canonical_original_code:
int getred(struct point p)
{
 int pixel;
 glReadPixels(p.x + 300, p.y + 300, 1, 1, 0x1903, 0x1404, &pixel);
 return pixel;
}

variable_types:
p
struct point { int x; }

variable_types: pixel int


getgreen

decompiled_code:
__int64 __fastcall getgreen(__int64 a1)
{
unsigned int v2[3]; // [rsp+24h] [rbp-Ch] BYREF

glReadPixels((unsigned int)(a1 + 300), (unsigned int)(HIDWORD(a1) + 300), 1LL, 1LL, 6404LL, 5124LL, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v2[3]; // [rsp+24h] [rbp-Ch] BYREF

glReadPixels((unsigned int)(a1 + 300), (unsigned int)(HIDWORD(a1) + 300), 1LL, 1LL, 6404LL, 5124LL, v2);
return v2[0];
}

original_code:
int getgreen(struct point p)
{
 GLint pixel;
 glReadPixels(p.x + 300, p.y + 300, 1, 1, 0x1904, 0x1404, &pixel);
 return pixel;
}

canonical_original_code:
int getgreen(struct point p)
{
 int pixel;
 glReadPixels(p.x + 300, p.y + 300, 1, 1, 0x1904, 0x1404, &pixel);
 return pixel;
}


getblue

decompiled_code:
__int64 __fastcall getblue(__int64 a1)
{
unsigned int v2[3]; // [rsp+24h] [rbp-Ch] BYREF

glReadPixels((unsigned int)(a1 + 300), (unsigned int)(HIDWORD(a1) + 300), 1LL, 1LL, 6405LL, 5124LL, v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v2[3]; // [rsp+24h] [rbp-Ch] BYREF

glReadPixels((unsigned int)(a1 + 300), (unsigned int)(HIDWORD(a1) + 300), 1LL, 1LL, 6405LL, 5124LL, v2);
return v2[0];
}

original_code:
int getblue(struct point p)
{
 GLint pixel;
 glReadPixels(p.x + 300, p.y + 300, 1, 1, 0x1905, 0x1404, &pixel);
 return pixel;
}

canonical_original_code:
int getblue(struct point p)
{
 int pixel;
 glReadPixels(p.x + 300, p.y + 300, 1, 1, 0x1905, 0x1404, &pixel);
 return pixel;
}


min

decompiled_code:
double __fastcall min(double a1, double a2)
{
return fmin(a1, a2);
}

canonical_decompiled_code:
double __fastcall func4(double a1, double a2)
{
return fmin(a1, a2);
}

original_code:
double min(double x,double y)
{
  if (x < y) return x;
  else return y;
}

canonical_original_code:
double min(double x, double y)
{
  if (x < y) return x;
  else return y;
}

variable_types: x double

variable_types: y double


max

decompiled_code:
double __fastcall max(double a1, double a2)
{
return fmax(a1, a2);
}

canonical_decompiled_code:
double __fastcall func5(double a1, double a2)
{
return fmax(a1, a2);
}

original_code:
double max(double x,double y)
{
 if (x > y) return x;
 return y;
}

canonical_original_code:
double max(double x, double y)
{
 if (x > y) return x;
 return y;
}


sqr

decompiled_code:
float __fastcall sqr(float a1)
{
return a1 * a1;
}

canonical_decompiled_code:
float __fastcall func6(float a1)
{
return a1 * a1;
}

original_code:
float sqr(float x)
{
    return x*x;
}

canonical_original_code:
float sqr(float x)
{
    return x*x;
}

variable_types: x float

return_type: float


swap

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(int *x,int *y)
{
    int i=*x;
    *x=*y;
    *y=i;
}

canonical_original_code:
void swap(int *x, int *y)
{
    int i = *x;
    *x=*y;
    *y=i;
}

variable_types:
x
int *

variable_types:
y
int *


readint

decompiled_code:
__int64 __fastcall readint(__int64 a1)
{
return _isoc99_fscanf(fin, &unk_AA4, a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return _isoc99_fscanf(fin, &unk_AA4, a1);
}

original_code:
void readint(int *i)
{
 fscanf(fin,"%d",i);
}

variable_types:
i
int *


readpoint

decompiled_code:
__int64 readpoint()
{
__int64 v1; // [rsp+18h] [rbp-20h] BYREF

readint((__int64)&v1);
readint((__int64)&v1 + 4);
return v1;
}

original_code:
struct point readpoint()
{
 struct point p;
 readint(&p.x);
 readint(&p.y);
 return p;
}

return_type: struct point { int x; }


readline

decompiled_code:
__int64 __fastcall readline(__int64 a1)
{
int v1; // edx
int v2; // edx

*(_QWORD *)a1 = readpoint();
*(_DWORD *)(a1 + 8) = v1;
*(_QWORD *)(a1 + 12) = readpoint();
*(_DWORD *)(a1 + 20) = v2;
return a1;
}

original_code:
struct line readline()
{
 struct line l;
 l.p1=readpoint();
 l.p2=readpoint();
 return l;
}

variable_types: struct line { struct point { int x; } p1; struct slope { int dx; } sl; }

user_defined_types: struct line { struct point p1; struct slope sl; }


readplane

decompiled_code:
__int64 readplane()
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

readint((__int64)&v1);
readint((__int64)&v1 + 4);
readint((__int64)v2);
readint((__int64)v2 + 4);
return v1;
}

original_code:
struct plane readplane()
{
 struct plane pl;
 readint(&pl.x);
 readint(&pl.y);
 readint(&pl.z);
 readint(&pl.d);
 return pl;
}

variable_types:
pl
struct plane { int x; }

return_type: struct plane { int x; }


readcolor

original_code:
struct colour readcolor()
{
 int i;
 readint(&i);
 switch (i)
 {
  case 0: return black;
  case 1: return white;
  case 2: return red;
  case 3: return green;
  case 4: return blue;
  case 5: return yellow;
  case 6: return indigo;
  case 7: return magenta;
  default : return black;
 }
}

return_type: struct colour { float r; }


decompiled_code:
_BOOL8 __fastcall eq_point(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a3 == (_DWORD)a1 )
result = HIDWORD(a3) == HIDWORD(a1);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a3 == (_DWORD)a1 )
result = HIDWORD(a3) == HIDWORD(a1);
return result;
}

original_code:
int eq_point(struct point p1,struct point p2)
{
 if (p1.x == p2.x && p2.y == p1.y) return 1;
 return 0;
}

canonical_original_code:
int eq_point(struct point p1, struct point p2)
{
 if (p1.x == p2.x && p2.y == p1.y) return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall cal_sl(int *a1)
{
int v1; // er8
int v2; // edx
int v3; // esi
__int64 result; // rax

v1 = *a1;
v2 = a1[3];
a1[6] = *a1 - v2;
v3 = a1[1];
result = (unsigned int)a1[4];
a1[7] = v3 - result;
if ( v3 - (int)result < 0 )
{
a1[6] = v2 - v1;
result = (unsigned int)(result - v3);
a1[7] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int *a1)
{
int v1; // er8
int v2; // edx
int v3; // esi
__int64 result; // rax

v1 = *a1;
v2 = a1[3];
a1[6] = *a1 - v2;
v3 = a1[1];
result = (unsigned int)a1[4];
a1[7] = v3 - result;
if ( v3 - (int)result < 0 )
{
a1[6] = v2 - v1;
result = (unsigned int)(result - v3);
a1[7] = result;
}
return result;
}

original_code:
void cal_sl(struct line *l)
{
 l->sl.dx=l->p1.x-l->p2.x;
 l->sl.dy=l->p1.y-l->p2.y;
 if (l->sl.dy<0)
 {
  l->sl.dx = -l->sl.dx;
  l->sl.dy = -l->sl.dy;
 }
}

variable_types: struct line { struct point { int x; } p1; struct slope { int dx; } sl; } *


decompiled_code:
__int64 __fastcall delta_x(__int64 a1, int a2)
{
return (unsigned int)(int)((double)(int)a1 * (double)a2 / (double)SHIDWORD(a1) + 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
return (unsigned int)(int)((double)(int)a1 * (double)a2 / (double)SHIDWORD(a1) + 0.5);
}

original_code:
int delta_x(struct slope slo,int y)
{
 return (int)(y*(double)slo.dx/slo.dy+0.5);
}

canonical_original_code:
int delta_x(struct slope slo, int y)
{
 return (int)(y*(double)slo.dx/slo.dy+0.5);
}

variable_types:
slo
struct slope { int dx; }

variable_types: y int


decompiled_code:
int __fastcall test_line(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned int a9)
{
return printf("%d %d %d %d\n", (unsigned int)a7, HIDWORD(a7), HIDWORD(a8), a9);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned int a9)
{
return printf("%d %d %d %d\n", (unsigned int)a7, HIDWORD(a7), HIDWORD(a8), a9);
}

original_code:
void test_line(struct line l)
{
 printf("%d %d %d %d\n",l.p1.x,l.p1.y,l.p2.x,l.p2.y);
}


decompiled_code:
int __fastcall test_point(unsigned __int64 a1)
{
return printf("%d %d\n", a1, HIDWORD(a1));
}

canonical_decompiled_code:
int __fastcall func18(unsigned __int64 a1)
{
return printf("%d %d\n", a1, HIDWORD(a1));
}

original_code:
void test_point(struct point p)
{
 printf("%d %d\n",p.x,p.y);
}


direction

decompiled_code:
__int64 __fastcall direction(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return (unsigned int)((a3 - a1) * (HIDWORD(a5) - HIDWORD(a1)) - (HIDWORD(a3) - HIDWORD(a1)) * (a5 - a1));
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
return (unsigned int)((a3 - a1) * (HIDWORD(a5) - HIDWORD(a1)) - (HIDWORD(a3) - HIDWORD(a1)) * (a5 - a1));
}

original_code:
int direction(struct point p0,struct point p1,struct point p2)
{
 return (p1.x - p0.x)*(p2.y - p0.y)-(p2.x - p0.x)*(p1.y - p0.y);
}

canonical_original_code:
int direction(struct point p0, struct point p1, struct point p2)
{
 return (p1.x - p0.x)*(p2.y - p0.y)-(p2.x - p0.x)*(p1.y - p0.y);
}


onseg

decompiled_code:
_BOOL8 __fastcall onseg(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4, unsigned __int64 a5)
{
unsigned __int64 v5; // r12
int v6; // ebx
unsigned __int64 v7; // r13
double v8; // r14
double v9; // xmm0_8
_BOOL8 result; // rax
double v11; // xmm0_8
double v12; // xmm5_8
double v13; // r12
double v14; // xmm0_8

v5 = HIDWORD(a3);
v6 = a5;
v7 = HIDWORD(a5);
v8 = (double)(int)a3;
v9 = min((double)(int)a1, (double)(int)a3);
result = 0LL;
if ( (double)v6 >= v9 )
{
v11 = max((double)(int)a1, v8);
result = 0LL;
if ( v11 >= (double)v6 )
{
v12 = (double)(int)v5;
v13 = (double)(int)v5;
v14 = min((double)SHIDWORD(a1), v12);
result = 0LL;
if ( (double)(int)v7 >= v14 )
result = max((double)SHIDWORD(a1), v13) >= (double)(int)v7;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func20(__int64 a1, __int64 a2, unsigned __int64 a3, __int64 a4, unsigned __int64 a5)
{
unsigned __int64 v5; // r12
int v6; // ebx
unsigned __int64 v7; // r13
double v8; // r14
double v9; // xmm0_8
_BOOL8 result; // rax
double v11; // xmm0_8
double v12; // xmm5_8
double v13; // r12
double v14; // xmm0_8

v5 = HIDWORD(a3);
v6 = a5;
v7 = HIDWORD(a5);
v8 = (double)(int)a3;
v9 = func4((double)(int)a1, (double)(int)a3);
result = 0LL;
if ( (double)v6 >= v9 )
{
v11 = func5((double)(int)a1, v8);
result = 0LL;
if ( v11 >= (double)v6 )
{
v12 = (double)(int)v5;
v13 = (double)(int)v5;
v14 = func4((double)SHIDWORD(a1), v12);
result = 0LL;
if ( (double)(int)v7 >= v14 )
result = func5((double)SHIDWORD(a1), v13) >= (double)(int)v7;
}
}
return result;
}

original_code:
int onseg(struct point p1,struct point p2, struct point t)
{
 if (min(p1.x, p2.x) <= t.x && t.x <= max(p1.x, p2.x) && min(p1.y, p2.y) <= t.y && t.y <= max(p1.y, p2.y))
  return 1;
 else return 0;
}

canonical_original_code:
int onseg(struct point p1, struct point p2, struct point t)
{
 if (min(p1.x, p2.x) <= t.x && t.x <= max(p1.x, p2.x) && min(p1.y, p2.y) <= t.y && t.y <= max(p1.y, p2.y))
  return 1;
 else return 0;
}

variable_types:
t
struct point


dis

decompiled_code:
__int64 __fastcall dis(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbp
float v5; // [rsp+4h] [rbp-34h]

v3 = HIDWORD(a3);
v5 = sqr((float)(a1 - (unsigned int)a3));
return (unsigned int)((int)sqr((float)(HIDWORD(a1) - (int)v3)) + (int)v5);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbp
float v5; // [rsp+4h] [rbp-34h]

v3 = HIDWORD(a3);
v5 = func6((float)(a1 - (unsigned int)a3));
return (unsigned int)((int)func6((float)(HIDWORD(a1) - (int)v3)) + (int)v5);
}

original_code:
int dis(struct point p1,struct point p2)
{
 return (int)sqr(p1.x-p2.x)+(int)sqr(p1.y-p2.y);
}

canonical_original_code:
int dis(struct point p1, struct point p2)
{
 return (int)sqr(p1.x-p2.x)+(int)sqr(p1.y-p2.y);
}


intersection

decompiled_code:
__int64 __fastcall intersection(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, int a9, int a10, __int64 a11, __int64 a12, int a13)
{
double v13; // xmm2_8
__int64 v15; // [rsp+0h] [rbp-14h]

v13 = (double)((HIDWORD(a11) - a13) * ((int)a7 - (int)a11) - ((int)a11 - HIDWORD(a12)) * (HIDWORD(a7) - HIDWORD(a11)))
/ (double)((HIDWORD(a11) - a13) * ((int)a7 - HIDWORD(a8)) - ((int)a11 - HIDWORD(a12)) * (HIDWORD(a7) - a9));
LODWORD(v15) = (int)((double)(HIDWORD(a8) - (int)a7) * v13 + 0.5) + a7;
HIDWORD(v15) = (int)((double)(a9 - HIDWORD(a7)) * v13 + 0.5) + HIDWORD(a7);
return v15;
}

original_code:
struct point intersection(struct line l1,struct line l2)
{
 struct point u1 = l1.p1, u2 = l1.p2, v1 = l2.p1, v2 = l2.p2;
 struct point ret = u1;
 double t=(double)((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
  /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
 ret.x += (int)((u2.x-u1.x)*t+0.5);
 ret.y += (int)((u2.y-u1.y)*t+0.5);
 return ret;
}

canonical_original_code:
struct point intersection(struct line l1, struct line l2)
{
 struct point u1 = l1.p1; struct point u2 = l1.p2; struct point v1 = l2.p1; struct point v2 = l2.p2;
 struct point ret = u1;
 double t = (double)((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
  /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
 ret.x += (int)((u2.x-u1.x)*t+0.5);
 ret.y += (int)((u2.y-u1.y)*t+0.5);
 return ret;
}

variable_types: struct line { struct point p1; struct slope { int dx; } sl; }

variable_types:
ret
struct point { int x; }

variable_types: t double


drawline

original_code:
void drawline(struct line l,struct colour c)
{
 struct point p1=l.p1, p2=l.p2;
    int dx,dy,sx,sy,change;
    glColor3f(c.r,c.g,c.b);
    dx=abs(p1.x-p2.x);
    dy=abs(p1.y-p2.y);
    if (p2.x>p1.x) sx=1; else sx=-1;
    if (p2.y>p1.y) sy=1; else sy=-1;
    if (dy>dx)
    {
 swap(&dx,&dy);
 change=1;
    }
    else change=0;
    int diff=2*dy-dx,i;
    for (i=0;i<dx;i++)
    {
  glVertex2i(p1.x,p1.y);
  while (diff>0)
  {
   if (change) p1.x=p1.x+sx; else p1.y=p1.y+sy;
   diff=diff-2*dx;
  }
  if (change) p1.y=p1.y+sy; else p1.x=p1.x+sx;
  diff=diff+2*dy;
    }
}

canonical_original_code:
void drawline(struct line l, struct colour c)
{
 struct point p1 = l.p1; struct point p2 = l.p2;
    int dx; int dy; int sx; int sy; int change;
    glColor3f(c.r,c.g,c.b);
    dx=abs(p1.x-p2.x);
    dy=abs(p1.y-p2.y);
    if (p2.x>p1.x) sx=1; else sx=-1;
    if (p2.y>p1.y) sy=1; else sy=-1;
    if (dy>dx)
    {
 swap(&dx,&dy);
 change=1;
    }
    else change=0;
    int diff = 2*dy-dx; int i;
    for (i=0;i<dx;i++)
    {
  glVertex2i(p1.x,p1.y);
  while (diff>0)
  {
   if (change) p1.x=p1.x+sx; else p1.y=p1.y+sy;
   diff=diff-2*dx;
  }
  if (change) p1.y=p1.y+sy; else p1.x=p1.x+sx;
  diff=diff+2*dy;
    }
}

variable_types:
c
struct colour { float r; }

variable_types: dx int

variable_types: dy int

variable_types: sx int

variable_types: sy int

variable_types: change int

variable_types: diff int

variable_types: i int


decompiled_code:
__int64 __fastcall draw4p(__int64 a1, __int64 a2, unsigned __int64 a3)
{
int v3; // er15
unsigned __int64 v4; // rbp
unsigned int v5; // er14
unsigned int v6; // er13

v3 = a3;
v4 = HIDWORD(a3);
v5 = HIDWORD(a1) + HIDWORD(a3);
v6 = a1 + a3;
glVertex2i((unsigned int)(a1 + a3), (unsigned int)(HIDWORD(a1) + HIDWORD(a3)));
glVertex2i((unsigned int)(a1 - v3), v5);
glVertex2i(v6, (unsigned int)(HIDWORD(a1) - v4));
return glVertex2i((unsigned int)(a1 - v3), (unsigned int)(HIDWORD(a1) - v4));
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, __int64 a2, unsigned __int64 a3)
{
int v3; // er15
unsigned __int64 v4; // rbp
unsigned int v5; // er14
unsigned int v6; // er13

v3 = a3;
v4 = HIDWORD(a3);
v5 = HIDWORD(a1) + HIDWORD(a3);
v6 = a1 + a3;
glVertex2i((unsigned int)(a1 + a3), (unsigned int)(HIDWORD(a1) + HIDWORD(a3)));
glVertex2i((unsigned int)(a1 - v3), v5);
glVertex2i(v6, (unsigned int)(HIDWORD(a1) - v4));
return glVertex2i((unsigned int)(a1 - v3), (unsigned int)(HIDWORD(a1) - v4));
}

original_code:
void draw4p(struct point center,struct point tar)
{
    glVertex2i(center.x+tar.x,center.y+tar.y);
    glVertex2i(center.x-tar.x,center.y+tar.y);
    glVertex2i(center.x+tar.x,center.y-tar.y);
    glVertex2i(center.x-tar.x,center.y-tar.y);
}

canonical_original_code:
void draw4p(struct point center, struct point tar)
{
    glVertex2i(center.x+tar.x,center.y+tar.y);
    glVertex2i(center.x-tar.x,center.y+tar.y);
    glVertex2i(center.x+tar.x,center.y-tar.y);
    glVertex2i(center.x-tar.x,center.y-tar.y);
}

variable_types:
center
struct point { int x; }

variable_types:
tar
struct point


decompiled_code:
__int64 __fastcall draw8p(__int64 a1, __int64 a2, unsigned __int64 a3, int a4)
{
unsigned __int64 v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-20h]
__int64 v7; // [rsp+10h] [rbp-18h]
unsigned int v8; // [rsp+18h] [rbp-10h]

v7 = a1;
v8 = a2;
v5 = a3;
v6 = a4;
draw4p(a1, a2, a3);
swap(&v5, (_DWORD *)&v5 + 1);
return draw4p(v7, v8, v5);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1, __int64 a2, unsigned __int64 a3, int a4)
{
unsigned __int64 v5; // [rsp+0h] [rbp-28h] BYREF
int v6; // [rsp+8h] [rbp-20h]
__int64 v7; // [rsp+10h] [rbp-18h]
unsigned int v8; // [rsp+18h] [rbp-10h]

v7 = a1;
v8 = a2;
v5 = a3;
v6 = a4;
func25(a1, a2, a3);
func7(&v5, (_DWORD *)&v5 + 1);
return func25(v7, v8, v5);
}

original_code:
void draw8p(struct point center,struct point tar)
{
    draw4p(center,tar);
    swap(&tar.x,&tar.y);
    draw4p(center,tar);
}

canonical_original_code:
void draw8p(struct point center, struct point tar)
{
    draw4p(center,tar);
    swap(&tar.x,&tar.y);
    draw4p(center,tar);
}


mainmenu

decompiled_code:
void mainmenu()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void mainmenu(GLint option)
{
 return ;
}

canonical_original_code:
void mainmenu(int option)
{
 return ;
}

variable_types: option int


blank

decompiled_code:
void blank()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void blank(GLint option)
{
}

canonical_original_code:
void blank(int option)
{
}


ChangeSize

decompiled_code:
__int64 __fastcall ChangeSize(int a1, int a2)
{
int v2; // ebx

v2 = a2;
if ( !a2 )
v2 = 1;
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)v2);
glMatrixMode(5889LL);
glLoadIdentity();
if ( v2 < a1 )
glOrtho(
(float)((float)((float)a1 * -300.0) / (float)v2),
(float)((float)((float)a1 * 300.0) / (float)v2),
-300.0,
300.0,
-300.0,
300.0);
else
glOrtho(
-300.0,
300.0,
(float)((float)((float)v2 * -300.0) / (float)a1),
(float)((float)((float)v2 * 300.0) / (float)a1),
-300.0,
300.0);
glMatrixMode(5888LL);
return glLoadIdentity();
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
int v2; // ebx

v2 = a2;
if ( !a2 )
v2 = 1;
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)v2);
glMatrixMode(5889LL);
glLoadIdentity();
if ( v2 < a1 )
glOrtho(
(float)((float)((float)a1 * -300.0) / (float)v2),
(float)((float)((float)a1 * 300.0) / (float)v2),
-300.0,
300.0,
-300.0,
300.0);
else
glOrtho(
-300.0,
300.0,
(float)((float)((float)v2 * -300.0) / (float)a1),
(float)((float)((float)v2 * 300.0) / (float)a1),
-300.0,
300.0);
glMatrixMode(5888LL);
return glLoadIdentity();
}

original_code:
void ChangeSize(int w, int h)
{
    GLfloat nRange = 300.0f;
    if(h == 0)
    h = 1;
    glViewport(0, 0, w, h);
    glMatrixMode(0x1701);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
    else
    glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
    glMatrixMode(0x1700);
    glLoadIdentity();
}

canonical_original_code:
void ChangeSize(int w, int h)
{
    float nRange = 300.0f;
    if(h == 0)
    h = 1;
    glViewport(0, 0, w, h);
    glMatrixMode(0x1701);
    glLoadIdentity();
    if (w <= h)
    glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange);
    else
    glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange);
    glMatrixMode(0x1700);
    glLoadIdentity();
}

variable_types: w int

variable_types: h int

variable_types: nRange float