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 *


repo: kichiki/WaoN

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: n int

variable_types:
p
double *

variable_types: i int

variable_types:
oct
double *

return_type: void


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 v2; // eax
unsigned int v3; // ecx
int v4; // eax
int result; // eax

if ( (a1 & 0x80000000) != 0 )
{
v3 = ~a1 / 0xC;
v4 = 12 * v3;
v1 = ~v3;
v2 = v4 + a1 + 1 + 11;
}
else
{
v1 = (unsigned int)((int)a1 / 12);
v2 = (int)a1 % 12;
}
switch ( v2 )
{
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:
result = mvprintw(6, 1, "pitch : C %+2d (%+3d)", v1, a1);
break;
}
return result;
}

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

if ( (a1 & 0x80000000) != 0 )
{
v3 = ~a1 / 0xC;
v4 = 12 * v3;
v1 = ~v3;
v2 = v4 + a1 + 1 + 11;
}
else
{
v1 = (unsigned int)((int)a1 / 12);
v2 = (int)a1 % 12;
}
switch ( v2 )
{
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:
result = mvprintw(6, 1, "pitch : C %+2d (%+3d)", v1, a1);
break;
}
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)
{
FILE *v1; // rcx
int v2; // eax
int v3; // eax

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

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

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

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)
{
int v1; // edx
__int64 v2; // rax
const char *v3; // rax
bool v4; // zf
unsigned int v5; // er8

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

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

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

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

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
unsigned int v2; // edx
const char *i; // rdi
__int64 result; // rax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0xFFFFFFFFLL;
v2 = v1 - 1;
for ( i = &a1[v1 - 1]; ; --i )
{
result = v2;
if ( *i == 47 )
break;
--v2;
if ( !(_DWORD)result )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
int v1; // eax
unsigned int v2; // edx
const char *i; // rdi
__int64 result; // rax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0xFFFFFFFFLL;
v2 = v1 - 1;
for ( i = &a1[v1 - 1]; ; --i )
{
result = v2;
if ( *i == 47 )
break;
--v2;
if ( !(_DWORD)result )
return 0xFFFFFFFFLL;
}
return result;
}

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

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

return_type: 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_B1C, a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return _isoc99_fscanf(fin, &unk_B1C, 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
__int64 result; // rax
int v3; // edx

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

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

*(_QWORD *)a1 = func10();
*(_DWORD *)(a1 + 8) = v1;
*(_QWORD *)(a1 + 12) = func10();
result = a1;
*(_DWORD *)(a1 + 20) = v3;
return result;
}

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];
v3 = a1[1];
a1[6] = *a1 - v2;
result = (unsigned int)a1[4];
a1[7] = v3 - result;
if ( v3 - (int)result < 0 )
{
result = (unsigned int)(result - v3);
a1[6] = v2 - v1;
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];
v3 = a1[1];
a1[6] = *a1 - v2;
result = (unsigned int)a1[4];
a1[7] = v3 - result;
if ( v3 - (int)result < 0 )
{
result = (unsigned int)(result - v3);
a1[6] = v2 - v1;
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:
bool __fastcall onseg(int a1, __int64 a2, unsigned __int64 a3, __int64 a4, int a5)
{
double v5; // xmm1_8
unsigned __int64 v6; // rsi
double v7; // xmm2_8
int v8; // ecx
int v9; // er8
double v10; // xmm3_8
double v11; // xmm2_8
bool result; // al

v5 = (double)(int)a3;
v6 = HIDWORD(a3);
v7 = (double)a5;
if ( (double)a5 < min((double)a1, (double)(int)a3)
|| max((double)a1, v5) < v7
|| (v10 = (double)v8, v11 = (double)v9, (double)v9 < min((double)v8, (double)(int)v6)) )
{
result = 0;
}
else
{
result = max(v10, (double)(int)v6) >= v11;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func20(int a1, __int64 a2, unsigned __int64 a3, __int64 a4, int a5)
{
double v5; // xmm1_8
unsigned __int64 v6; // rsi
double v7; // xmm2_8
int v8; // ecx
int v9; // er8
double v10; // xmm3_8
double v11; // xmm2_8
bool result; // al

v5 = (double)(int)a3;
v6 = HIDWORD(a3);
v7 = (double)a5;
if ( (double)a5 < func4((double)a1, (double)(int)a3)
|| func5((double)a1, v5) < v7
|| (v10 = (double)v8, v11 = (double)v9, (double)v9 < func4((double)v8, (double)(int)v6)) )
{
result = 0;
}
else
{
result = func5(v10, (double)(int)v6) >= v11;
}
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(int a1, __int64 a2, int a3)
{
int v3; // eax
float v4; // xmm0_4
int v5; // eax

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

canonical_decompiled_code:
__int64 __fastcall func21(int a1, __int64 a2, int a3)
{
int v3; // eax
float v4; // xmm0_4
int v5; // eax

func6((float)(a1 - a3));
v4 = func6((float)v3);
return (unsigned int)((int)v4 + 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; // xmm0_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)(v13 * (double)(a9 - HIDWORD(a7)) + 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, __int64 a3)
{
unsigned int v3; // er14
unsigned int v4; // er13
unsigned int v5; // ebp
unsigned int v6; // ebx

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

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

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

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


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)(300.0 * (float)a1) / (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)(300.0 * (float)v2) / (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)(300.0 * (float)a1) / (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)(300.0 * (float)v2) / (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


myDisplay

decompiled_code:
__int64 myDisplay()
{
__int64 v0; // rdx
__int64 v1; // rcx
int v3; // eax
int v4; // eax
__int64 v5; // rcx
int v6; // edx
__int64 v7; // rsi
int v8; // eax
__int64 v9; // rcx
int v10; // edx
__int64 v11; // rsi
double v12; // xmm0_8
float v13; // xmm1_4
__int64 v14; // rax
unsigned int v15; // edx
__int64 v16; // rax
unsigned int v17; // edx
unsigned int v18; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v19; // [rsp+10h] [rbp-28h] BYREF
unsigned int v20; // [rsp+14h] [rbp-24h] BYREF
__int64 v21; // [rsp+18h] [rbp-20h]
unsigned int v22; // [rsp+20h] [rbp-18h]

setcolour();
ChangeSize(600, 600);
if ( choice <= 15 )
glClear(0x4000LL);
glBegin(0LL);
switch ( choice )
{
case 1:
flag = 0;
choice = 18;
break;
case 2:
v16 = readpoint();
v22 = v17;
v21 = v16;
readint(&v18);
readcolor();
drawcircle(v21, v22, v18);
fclose(fin);
choice = 100;
break;
case 3:
v14 = readpoint();
v22 = v15;
v21 = v14;
readint(&v19);
readint(&v20);
readcolor();
drawellipse(v21, v22, v19, v20);
fclose(fin);
choice = 100;
break;
case 4:
flag = 0;
*((_DWORD *)&pol + 550) = 0;
choice = 22;
break;
case 5:
flag = 0;
choice = 24;
break;
case 6:
read_clip(&window, &pol_clip);
clipping(&window, &pol_clip);
fclose(fin);
choice = 100;
break;
case 7:
zbuffer();
fclose(fin);
choice = 100;
break;
case 9:
flag = 0;
con_num = 0;
choice = 20;
break;
case 10:
drawsurface();
fclose(fin);
choice = 100;
break;
case 11:
readpolygon(&pol);
drawpolygon(&pol, *(double *)&white, *((float *)&white + 2));
fclose(fin);
flag = 0;
choice = 17;
break;
case 17:
if ( flag )
fillseed(mousepoint, *((unsigned int *)&mousepoint + 2));
break;
case 18:
if ( flag )
{
choice = 19;
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = *((_DWORD *)&mousepoint + 2);
}
break;
case 19:
if ( flag == 2 )
{
v12 = *(double *)&green;
*(__int64 *)((char *)&majorline + 12) = mousepoint;
v13 = *((float *)&green + 2);
*((_DWORD *)&majorline + 5) = *((_DWORD *)&mousepoint + 2);
drawline(v12, v13);
flag = 0;
choice = 18;
}
break;
case 20:
v8 = con_num;
if ( flag > con_num )
{
v9 = mousepoint;
v10 = *((_DWORD *)&mousepoint + 2);
if ( (flag & 1) != 0 )
{
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = v10;
}
else
{
*(__int64 *)((char *)&majorline + 12) = mousepoint;
*((_DWORD *)&majorline + 5) = v10;
}
if ( v8 )
{
drawline(*(double *)&yellow, *((float *)&yellow + 2));
v8 = con_num;
v9 = mousepoint;
v10 = *((_DWORD *)&mousepoint + 2);
}
con_num = v8 + 1;
v11 = 12LL * v8;
*(__int64 *)((char *)&control + v11) = v9;
*(_DWORD *)((char *)&control + v11 + 8) = v10;
}
break;
case 21:
if ( flag == con_num )
drawcurve();
break;
case 22:
v4 = *((_DWORD *)&pol + 550);
if ( v4 < flag )
{
v5 = mousepoint;
v6 = *((_DWORD *)&mousepoint + 2);
if ( (flag & 1) != 0 )
{
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = v6;
}
else
{
*(__int64 *)((char *)&majorline + 12) = mousepoint;
*((_DWORD *)&majorline + 5) = v6;
}
if ( v4 )
{
drawline(*(double *)&white, *((float *)&white + 2));
v4 = *((_DWORD *)&pol + 550);
v5 = mousepoint;
v6 = *((_DWORD *)&mousepoint + 2);
}
*((_DWORD *)&pol + 550) = v4 + 1;
v7 = 12LL * v4;
*(__int64 *)((char *)&pol + v7) = v5;
*(_DWORD *)((char *)&pol + v7 + 8) = v6;
}
break;
case 23:
if ( *((_DWORD *)&pol + 550) == flag )
fillpolygon(&pol, *(double *)&white, *((float *)&white + 2), *(double *)&indigo, *((float *)&indigo + 2));
break;
case 24:
if ( flag )
{
choice = 25;
liangx1 = mousepoint;
liangy1 = HIDWORD(mousepoint);
}
break;
case 25:
if ( flag == 2 )
{
v3 = HIDWORD(mousepoint);
liangx2 = mousepoint;
liangy2 = v3;
if ( (int)mousepoint < liangx1 )
{
swap(&liangx1, &liangx2);
v3 = liangy2;
}
if ( liangy1 > v3 )
swap(&liangy1, &liangy2);
drawliangwindow();
flag = 0;
choice = 26;
}
break;
case 26:
if ( flag )
{
choice = 27;
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = *((_DWORD *)&mousepoint + 2);
}
break;
case 27:
if ( flag == 2 )
{
*(__int64 *)((char *)&majorline + 12) = mousepoint;
*((_DWORD *)&majorline + 5) = *((_DWORD *)&mousepoint + 2);
liang(0LL, 600LL, v0, v1);
flag = 0;
choice = 26;
}
break;
default:
break;
}
glEnd();
return glFlush();
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
__int64 v1; // rcx
int v3; // eax
int v4; // eax
__int64 v5; // rcx
int v6; // edx
__int64 v7; // rsi
int v8; // eax
__int64 v9; // rcx
int v10; // edx
__int64 v11; // rsi
double v12; // xmm0_8
float v13; // xmm1_4
__int64 v14; // rax
unsigned int v15; // edx
__int64 v16; // rax
unsigned int v17; // edx
unsigned int v18; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned int v19; // [rsp+10h] [rbp-28h] BYREF
unsigned int v20; // [rsp+14h] [rbp-24h] BYREF
__int64 v21; // [rsp+18h] [rbp-20h]
unsigned int v22; // [rsp+20h] [rbp-18h]

setcolour();
func2(600, 600);
if ( choice <= 15 )
glClear(0x4000LL);
glBegin(0LL);
switch ( choice )
{
case 1:
flag = 0;
choice = 18;
break;
case 2:
v16 = readpoint();
v22 = v17;
v21 = v16;
readint(&v18);
readcolor();
drawcircle(v21, v22, v18);
fclose(fin);
choice = 100;
break;
case 3:
v14 = readpoint();
v22 = v15;
v21 = v14;
readint(&v19);
readint(&v20);
readcolor();
drawellipse(v21, v22, v19, v20);
fclose(fin);
choice = 100;
break;
case 4:
flag = 0;
*((_DWORD *)&pol + 550) = 0;
choice = 22;
break;
case 5:
flag = 0;
choice = 24;
break;
case 6:
read_clip(&window, &pol_clip);
clipping(&window, &pol_clip);
fclose(fin);
choice = 100;
break;
case 7:
zbuffer();
fclose(fin);
choice = 100;
break;
case 9:
flag = 0;
con_num = 0;
choice = 20;
break;
case 10:
drawsurface();
fclose(fin);
choice = 100;
break;
case 11:
readpolygon(&pol);
drawpolygon(&pol, *(double *)&white, *((float *)&white + 2));
fclose(fin);
flag = 0;
choice = 17;
break;
case 17:
if ( flag )
fillseed(mousepoint, *((unsigned int *)&mousepoint + 2));
break;
case 18:
if ( flag )
{
choice = 19;
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = *((_DWORD *)&mousepoint + 2);
}
break;
case 19:
if ( flag == 2 )
{
v12 = *(double *)&green;
*(__int64 *)((char *)&majorline + 12) = mousepoint;
v13 = *((float *)&green + 2);
*((_DWORD *)&majorline + 5) = *((_DWORD *)&mousepoint + 2);
drawline(v12, v13);
flag = 0;
choice = 18;
}
break;
case 20:
v8 = con_num;
if ( flag > con_num )
{
v9 = mousepoint;
v10 = *((_DWORD *)&mousepoint + 2);
if ( (flag & 1) != 0 )
{
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = v10;
}
else
{
*(__int64 *)((char *)&majorline + 12) = mousepoint;
*((_DWORD *)&majorline + 5) = v10;
}
if ( v8 )
{
drawline(*(double *)&yellow, *((float *)&yellow + 2));
v8 = con_num;
v9 = mousepoint;
v10 = *((_DWORD *)&mousepoint + 2);
}
con_num = v8 + 1;
v11 = 12LL * v8;
*(__int64 *)((char *)&control + v11) = v9;
*(_DWORD *)((char *)&control + v11 + 8) = v10;
}
break;
case 21:
if ( flag == con_num )
drawcurve();
break;
case 22:
v4 = *((_DWORD *)&pol + 550);
if ( v4 < flag )
{
v5 = mousepoint;
v6 = *((_DWORD *)&mousepoint + 2);
if ( (flag & 1) != 0 )
{
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = v6;
}
else
{
*(__int64 *)((char *)&majorline + 12) = mousepoint;
*((_DWORD *)&majorline + 5) = v6;
}
if ( v4 )
{
drawline(*(double *)&white, *((float *)&white + 2));
v4 = *((_DWORD *)&pol + 550);
v5 = mousepoint;
v6 = *((_DWORD *)&mousepoint + 2);
}
*((_DWORD *)&pol + 550) = v4 + 1;
v7 = 12LL * v4;
*(__int64 *)((char *)&pol + v7) = v5;
*(_DWORD *)((char *)&pol + v7 + 8) = v6;
}
break;
case 23:
if ( *((_DWORD *)&pol + 550) == flag )
fillpolygon(&pol, *(double *)&white, *((float *)&white + 2), *(double *)&indigo, *((float *)&indigo + 2));
break;
case 24:
if ( flag )
{
choice = 25;
liangx1 = mousepoint;
liangy1 = HIDWORD(mousepoint);
}
break;
case 25:
if ( flag == 2 )
{
v3 = HIDWORD(mousepoint);
liangx2 = mousepoint;
liangy2 = v3;
if ( (int)mousepoint < liangx1 )
{
swap(&liangx1, &liangx2);
v3 = liangy2;
}
if ( liangy1 > v3 )
swap(&liangy1, &liangy2);
drawliangwindow();
flag = 0;
choice = 26;
}
break;
case 26:
if ( flag )
{
choice = 27;
majorline = mousepoint;
*((_DWORD *)&majorline + 2) = *((_DWORD *)&mousepoint + 2);
}
break;
case 27:
if ( flag == 2 )
{
*(__int64 *)((char *)&majorline + 12) = mousepoint;
*((_DWORD *)&majorline + 5) = *((_DWORD *)&mousepoint + 2);
liang(0LL, 600LL, v0, v1);
flag = 0;
choice = 26;
}
break;
default:
break;
}
glEnd();
return glFlush();
}

original_code:
void myDisplay(void)
{
    struct point center;
    struct colour c;
    int r,a,b;
    setcolour();
 ChangeSize(600,600);
 if (choice < 16) glClear(0x00004000);
    glBegin(0x0000);
 switch (choice)
 {
  case 1: flag = 0; choice = 18; break;
        case 2: center = readpoint(); readint(&r); c = readcolor(); drawcircle(center,r,c);
          fclose(fin); choice = 100; break;
        case 3: center = readpoint(); readint(&a); readint(&b); c = readcolor(); drawellipse(center,a,b,c);
          fclose(fin); choice = 100; break;
        case 4: flag = 0; pol.ver_num = 0; choice = 22; break;
      case 5: flag = 0; choice =24; break;
      case 6: read_clip(&window,&pol_clip);
        clipping(&window,&pol_clip);
        fclose(fin); choice = 100; break;
      case 7: zbuffer();
        fclose(fin); choice = 100; break;
        case 9: flag = 0; con_num = 0; choice = 20; break;
        case 10: drawsurface();
    fclose (fin); choice = 100; break;
  case 11: readpolygon(&pol); drawpolygon(&pol,white);
    fclose(fin); flag = 0; choice = 17; break;
  case 17: if (flag) fillseed(mousepoint); break;
  case 18: if (flag)
     {
      majorline.p1 = mousepoint;
      choice = 19;
     }
    break;
  case 19: if (flag == 2)
     {
      majorline.p2 = mousepoint;
      drawline(majorline,green);
      flag = 0;
      choice = 18;
     }
     break;
  case 20: if (flag > con_num)
     {
      if (flag&1) majorline.p1 = mousepoint;
      else majorline.p2 = mousepoint;
      if (con_num) drawline(majorline,yellow);
      control[con_num] = mousepoint;
      ++con_num;
     }
    break;
  case 21: if (flag == con_num) drawcurve(); break;
  case 22: if (flag > pol.ver_num)
     {
      if (flag&1) majorline.p1 = mousepoint;
      else majorline.p2 = mousepoint;
      if (pol.ver_num) drawline(majorline,white);
      pol.vertex[pol.ver_num] = mousepoint;
      ++pol.ver_num;
     }
     break;
  case 23: if (flag == pol.ver_num) fillpolygon(&pol,white,indigo); break;
  case 24: if (flag)
     {
      liangx1 = mousepoint.x;
      liangy1 = mousepoint.y;
      choice = 25;
     }
     break;
  case 25: if (flag == 2)
     {
      liangx2 = mousepoint.x;
      liangy2 = mousepoint.y;
      if (liangx1 > liangx2) swap(&liangx1,&liangx2);
      if (liangy1 > liangy2) swap(&liangy1,&liangy2);
      drawliangwindow();
      flag = 0;
      choice = 26;
     }
     break;
        case 26: if (flag)
           {
            majorline.p1 = mousepoint;
            choice = 27;
           }
           break;
        case 27: if (flag == 2)
           {
            majorline.p2 = mousepoint;
            liang(majorline);
            flag = 0;
            choice = 26;
           }
           break;
        default: break;
    }
    glEnd();
    glFlush();
}

canonical_original_code:
void myDisplay()
{
    struct point center;
    struct colour c;
    int r; int a; int b;
    setcolour();
 ChangeSize(600,600);
 if (choice < 16) glClear(0x00004000);
    glBegin(0x0000);
 switch (choice)
 {
  case 1: flag = 0; choice = 18; break;
        case 2: center = readpoint(); readint(&r); c = readcolor(); drawcircle(center,r,c);
          fclose(fin); choice = 100; break;
        case 3: center = readpoint(); readint(&a); readint(&b); c = readcolor(); drawellipse(center,a,b,c);
          fclose(fin); choice = 100; break;
        case 4: flag = 0; pol.ver_num = 0; choice = 22; break;
      case 5: flag = 0; choice =24; break;
      case 6: read_clip(&window,&pol_clip);
        clipping(&window,&pol_clip);
        fclose(fin); choice = 100; break;
      case 7: zbuffer();
        fclose(fin); choice = 100; break;
        case 9: flag = 0; con_num = 0; choice = 20; break;
        case 10: drawsurface();
    fclose (fin); choice = 100; break;
  case 11: readpolygon(&pol); drawpolygon(&pol,white);
    fclose(fin); flag = 0; choice = 17; break;
  case 17: if (flag) fillseed(mousepoint); break;
  case 18: if (flag)
     {
      majorline.p1 = mousepoint;
      choice = 19;
     }
    break;
  case 19: if (flag == 2)
     {
      majorline.p2 = mousepoint;
      drawline(majorline,green);
      flag = 0;
      choice = 18;
     }
     break;
  case 20: if (flag > con_num)
     {
      if (flag&1) majorline.p1 = mousepoint;
      else majorline.p2 = mousepoint;
      if (con_num) drawline(majorline,yellow);
      control[con_num] = mousepoint;
      ++con_num;
     }
    break;
  case 21: if (flag == con_num) drawcurve(); break;
  case 22: if (flag > pol.ver_num)
     {
      if (flag&1) majorline.p1 = mousepoint;
      else majorline.p2 = mousepoint;
      if (pol.ver_num) drawline(majorline,white);
      pol.vertex[pol.ver_num] = mousepoint;
      ++pol.ver_num;
     }
     break;
  case 23: if (flag == pol.ver_num) fillpolygon(&pol,white,indigo); break;
  case 24: if (flag)
     {
      liangx1 = mousepoint.x;
      liangy1 = mousepoint.y;
      choice = 25;
     }
     break;
  case 25: if (flag == 2)
     {
      liangx2 = mousepoint.x;
      liangy2 = mousepoint.y;
      if (liangx1 > liangx2) swap(&liangx1,&liangx2);
      if (liangy1 > liangy2) swap(&liangy1,&liangy2);
      drawliangwindow();
      flag = 0;
      choice = 26;
     }
     break;
        case 26: if (flag)
           {
            majorline.p1 = mousepoint;
            choice = 27;
           }
           break;
        case 27: if (flag == 2)
           {
            majorline.p2 = mousepoint;
            liang(majorline);
            flag = 0;
            choice = 26;
           }
           break;
        default: break;
    }
    glEnd();
    glFlush();
}

variable_types: r int

variable_types: a int

variable_types: b int

user_defined_types:
struct point { int x; }
struct colour { float r; }


basicgeometry

decompiled_code:
__int64 __fastcall basicgeometry(int a1)
{
FILE *v2; // rax
FILE *v3; // rax

switch ( a1 )
{
case 2:
v2 = fopen("test/circle", "r");
choice = 2;
fin = v2;
break;
case 3:
v3 = fopen("test/ellipse", "r");
choice = 3;
fin = v3;
break;
case 1:
choice = 1;
break;
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
FILE *v2; // rax
FILE *v3; // rax

switch ( a1 )
{
case 2:
v2 = fopen("test/circle", "r");
choice = 2;
fin = v2;
break;
case 3:
v3 = fopen("test/ellipse", "r");
choice = 3;
fin = v3;
break;
case 1:
choice = 1;
break;
}
return glutPostRedisplay();
}

original_code:
void basicgeometry(GLint option)
{
 switch (option)
 {
  case 1: choice = 1; break;
  case 2: fin = fopen("test/circle", "r"); choice = 2; break;
  case 3: fin = fopen("test/ellipse", "r"); choice = 3; break;
 }
 glutPostRedisplay ();
}

canonical_original_code:
void basicgeometry(int option)
{
 switch (option)
 {
  case 1: choice = 1; break;
  case 2: fin = fopen("test/circle", "r"); choice = 2; break;
  case 3: fin = fopen("test/ellipse", "r"); choice = 3; break;
 }
 glutPostRedisplay ();
}


clip

decompiled_code:
__int64 __fastcall clip(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
choice = 5;
}
else if ( a1 == 2 )
{
v1 = fopen("test/clipping", "r");
choice = 6;
fin = v1;
return glutPostRedisplay();
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
choice = 5;
}
else if ( a1 == 2 )
{
v1 = fopen("test/clipping", "r");
choice = 6;
fin = v1;
return glutPostRedisplay();
}
return glutPostRedisplay();
}

original_code:
void clip(GLint option)
{
 switch (option)
 {
  case 1: choice = 5; break;
  case 2: fin = fopen("test/clipping", "r"); choice = 6; break;
 }
 glutPostRedisplay ();
}

canonical_original_code:
void clip(int option)
{
 switch (option)
 {
  case 1: choice = 5; break;
  case 2: fin = fopen("test/clipping", "r"); choice = 6; break;
 }
 glutPostRedisplay ();
}


curve

decompiled_code:
__int64 __fastcall curve(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
choice = 9;
}
else if ( a1 == 2 )
{
v1 = fopen("test/surface", "r");
choice = 10;
fin = v1;
return glutPostRedisplay();
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
choice = 9;
}
else if ( a1 == 2 )
{
v1 = fopen("test/surface", "r");
choice = 10;
fin = v1;
return glutPostRedisplay();
}
return glutPostRedisplay();
}

original_code:
void curve(GLint option)
{
 switch (option)
 {
  case 1: choice = 9; break;
  case 2: fin = fopen("test/surface", "r"); choice = 10; break;
 }
 glutPostRedisplay ();
}

canonical_original_code:
void curve(int option)
{
 switch (option)
 {
  case 1: choice = 9; break;
  case 2: fin = fopen("test/surface", "r"); choice = 10; break;
 }
 glutPostRedisplay ();
}


fillpol

decompiled_code:
__int64 __fastcall fillpol(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
choice = 4;
}
else if ( a1 == 2 )
{
v1 = fopen("test/seed", "r");
choice = 11;
fin = v1;
return glutPostRedisplay();
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
choice = 4;
}
else if ( a1 == 2 )
{
v1 = fopen("test/seed", "r");
choice = 11;
fin = v1;
return glutPostRedisplay();
}
return glutPostRedisplay();
}

original_code:
void fillpol(GLint option)
{
 switch (option)
 {
  case 1: choice = 4; break;
  case 2: fin = fopen("test/seed","r"); choice = 11; break;
 }
 glutPostRedisplay ();
}

canonical_original_code:
void fillpol(int option)
{
 switch (option)
 {
  case 1: choice = 4; break;
  case 2: fin = fopen("test/seed","r"); choice = 11; break;
 }
 glutPostRedisplay ();
}


mousedeal

decompiled_code:
__int64 __fastcall mousedeal(int a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = (unsigned int)(300 - a4);
LODWORD(mousepoint) = a3 - 300;
HIDWORD(mousepoint) = result;
if ( a1 == 2 && !a2 )
{
result = (unsigned int)(choice - 17);
if ( (unsigned int)result <= 0xA )
{
++flag;
result = glutPostRedisplay();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, int a3, int a4)
{
__int64 result; // rax

result = (unsigned int)(300 - a4);
LODWORD(mousepoint) = a3 - 300;
HIDWORD(mousepoint) = result;
if ( a1 == 2 && !a2 )
{
result = (unsigned int)(choice - 17);
if ( (unsigned int)result <= 0xA )
{
++flag;
result = glutPostRedisplay();
}
}
return result;
}

original_code:
void mousedeal(GLint button, GLint action,GLint xMouse,GLint yMouse)
{
 mousepoint.x = xMouse - 300; mousepoint.y = 300 -yMouse;
 if (button == 0x0002 && action == 0x0000)
 {
  switch (choice)
  {
   case 17:
   case 18:
   case 19:
   case 20:
   case 21:
   case 22:
   case 23:
   case 24:
   case 25:
   case 26:
   case 27: ++flag; break;
   default: return;
  }
  glutPostRedisplay ();
 }
}

canonical_original_code:
void mousedeal(int button, int action, int xMouse, int yMouse)
{
 mousepoint.x = xMouse - 300; mousepoint.y = 300 -yMouse;
 if (button == 0x0002 && action == 0x0000)
 {
  switch (choice)
  {
   case 17:
   case 18:
   case 19:
   case 20:
   case 21:
   case 22:
   case 23:
   case 24:
   case 25:
   case 26:
   case 27: ++flag; break;
   default: return;
  }
  glutPostRedisplay ();
 }
}

variable_types: button int

variable_types: action int

variable_types: xMouse int

variable_types: yMouse int


keyfun

decompiled_code:
void __fastcall keyfun(char a1)
{
if ( a1 != 13 )
{
if ( a1 != 27 )
return;
if ( choice != 100 )
{
if ( choice > 23 )
{
choice = 5;
glutPostRedisplay();
return;
}
if ( choice > 21 )
{
choice = 4;
goto LABEL_9;
}
if ( choice > 19 )
{
choice = 9;
goto LABEL_9;
}
if ( choice > 17 )
{
choice = 1;
goto LABEL_9;
}
}
choice = 0;
goto LABEL_9;
}
if ( choice == 20 )
{
choice = 21;
glutPostRedisplay();
}
else if ( choice == 22 )
{
choice = 23;
LABEL_9:
glutPostRedisplay();
return;
}
}

canonical_decompiled_code:
void __fastcall func9(char a1)
{
if ( a1 != 13 )
{
if ( a1 != 27 )
return;
if ( choice != 100 )
{
if ( choice > 23 )
{
choice = 5;
glutPostRedisplay();
return;
}
if ( choice > 21 )
{
choice = 4;
goto LABEL_9;
}
if ( choice > 19 )
{
choice = 9;
goto LABEL_9;
}
if ( choice > 17 )
{
choice = 1;
goto LABEL_9;
}
}
choice = 0;
goto LABEL_9;
}
if ( choice == 20 )
{
choice = 21;
glutPostRedisplay();
}
else if ( choice == 22 )
{
choice = 23;
LABEL_9:
glutPostRedisplay();
return;
}
}

original_code:
void keyfun(GLubyte key, GLint xMouse, GLint yMouse)
{
 if (key == 13)
 {
  switch (choice)
  {
   case 20: choice = 21; break;
   case 22: choice = 23; break;
   default: return;
  }
  glutPostRedisplay ();
 }
 else if (key == 27)
 {
  if (choice == 100) choice = 0;
  if (choice > 23) choice = 5;
  else if (choice > 21) choice = 4;
  else if (choice > 19) choice = 9;
  else if (choice > 17) choice = 1;
  else choice = 0;
  glutPostRedisplay ();
 }
}

canonical_original_code:
void keyfun(unsigned char key, int xMouse, int yMouse)
{
 if (key == 13)
 {
  switch (choice)
  {
   case 20: choice = 21; break;
   case 22: choice = 23; break;
   default: return;
  }
  glutPostRedisplay ();
 }
 else if (key == 27)
 {
  if (choice == 100) choice = 0;
  if (choice > 23) choice = 5;
  else if (choice > 21) choice = 4;
  else if (choice > 19) choice = 9;
  else if (choice > 17) choice = 1;
  else choice = 0;
  glutPostRedisplay ();
 }
}

variable_types:
key
unsigned char


shadow

decompiled_code:
void __fastcall shadow(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
v1 = fopen("test/shadow", "r");
choice = 7;
fin = v1;
if ( v1 )
goto LABEL_3;
}
else if ( fin )
{
LABEL_3:
glutPostRedisplay();
return;
}
perror("File Does Not Exist\n");
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
FILE *v1; // rax

if ( a1 == 1 )
{
v1 = fopen("test/shadow", "r");
choice = 7;
fin = v1;
if ( v1 )
goto LABEL_3;
}
else if ( fin )
{
LABEL_3:
glutPostRedisplay();
return;
}
perror("File Does Not Exist\n");
}

original_code:
void shadow(GLint option)
{
 switch (option)
 {
  case 1: fin = fopen("test/shadow", "r"); choice = 7; break;
 }
 if (!fin) {
     perror("File Does Not Exist\n");
     return ;
    }
 glutPostRedisplay ();
}

canonical_original_code:
void shadow(int option)
{
 switch (option)
 {
  case 1: fin = fopen("test/shadow", "r"); choice = 7; break;
 }
 if (!fin) {
     perror("File Does Not Exist\n");
     return ;
    }
 glutPostRedisplay ();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er15
unsigned int v4; // er14
unsigned int v5; // er13
unsigned int v6; // er12
unsigned int v7; // ebp
int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v9[0] = argc;
glutInit(v9, argv, envp);
glutInitDisplayMode(16LL);
glutInitWindowSize(600LL, 600LL);
glutInitWindowPosition(300LL, 300LL);
glutCreateWindow("Graphic Experiment");
choice = 0;
glutReshapeFunc(ChangeSize);
glutDisplayFunc(myDisplay);
glutCreateMenu(blank);
v3 = glutCreateMenu(basicgeometry);
glutAddMenuEntry("Line", 1LL);
glutAddMenuEntry("Circle", 2LL);
glutAddMenuEntry("Ellipse", 3LL);
v4 = glutCreateMenu(fillpol);
glutAddMenuEntry("Scan line", 1LL);
glutAddMenuEntry("Seed", 2LL);
v5 = glutCreateMenu(clip);
glutAddMenuEntry("Liang", 1LL);
glutAddMenuEntry("Weiler Atherton", 2LL);
v6 = glutCreateMenu(shadow);
glutAddMenuEntry("Zbuffer", 1LL);
v7 = glutCreateMenu(curve);
glutAddMenuEntry("Bezier Curve", 1LL);
glutAddMenuEntry("Bezier Surface", 2LL);
glutCreateMenu(mainmenu);
glutAddSubMenu("Element", v3);
glutAddSubMenu("Fill", v4);
glutAddSubMenu("Clipping", v5);
glutAddSubMenu("Shadow", v6);
glutAddSubMenu("Curve", v7);
glutAttachMenu(0LL);
glutMouseFunc(mousedeal);
glutKeyboardFunc(keyfun);
glutMainLoop();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0000 | 0x0000| 0x0010);
    glutInitWindowSize(600, 600);
    glutInitWindowPosition(300, 300);
    glutCreateWindow("Graphic Experiment");
    choice = 0;
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(&myDisplay);
    GLint Basic, Clipping, Curve, Shadow, Fill;
    Basic = glutCreateMenu(blank);
    Basic = glutCreateMenu(basicgeometry);
     glutAddMenuEntry ("Line", 1);
     glutAddMenuEntry ("Circle", 2);
     glutAddMenuEntry ("Ellipse", 3);
    Fill = glutCreateMenu(fillpol);
     glutAddMenuEntry ("Scan line", 1);
     glutAddMenuEntry ("Seed", 2);
    Clipping = glutCreateMenu(clip);
     glutAddMenuEntry ("Liang", 1);
     glutAddMenuEntry ("Weiler Atherton", 2);
    Shadow = glutCreateMenu(shadow);
     glutAddMenuEntry ("Zbuffer", 1);
    Curve = glutCreateMenu(curve);
     glutAddMenuEntry ("Bezier Curve", 1);
     glutAddMenuEntry ("Bezier Surface", 2);
    glutCreateMenu(mainmenu);
     glutAddSubMenu ("Element", Basic);
     glutAddSubMenu ("Fill", Fill);
     glutAddSubMenu ("Clipping", Clipping);
     glutAddSubMenu ("Shadow", Shadow);
     glutAddSubMenu ("Curve", Curve);
    glutAttachMenu (0x0000);
    glutMouseFunc (mousedeal);
    glutKeyboardFunc (keyfun);
    glutMainLoop();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0000 | 0x0000| 0x0010);
    glutInitWindowSize(600, 600);
    glutInitWindowPosition(300, 300);
    glutCreateWindow("Graphic Experiment");
    choice = 0;
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(&myDisplay);
    int Basic; int Clipping; int Curve; int Shadow; int Fill;
    Basic = glutCreateMenu(blank);
    Basic = glutCreateMenu(basicgeometry);
     glutAddMenuEntry ("Line", 1);
     glutAddMenuEntry ("Circle", 2);
     glutAddMenuEntry ("Ellipse", 3);
    Fill = glutCreateMenu(fillpol);
     glutAddMenuEntry ("Scan line", 1);
     glutAddMenuEntry ("Seed", 2);
    Clipping = glutCreateMenu(clip);
     glutAddMenuEntry ("Liang", 1);
     glutAddMenuEntry ("Weiler Atherton", 2);
    Shadow = glutCreateMenu(shadow);
     glutAddMenuEntry ("Zbuffer", 1);
    Curve = glutCreateMenu(curve);
     glutAddMenuEntry ("Bezier Curve", 1);
     glutAddMenuEntry ("Bezier Surface", 2);
    glutCreateMenu(mainmenu);
     glutAddSubMenu ("Element", Basic);
     glutAddSubMenu ("Fill", Fill);
     glutAddSubMenu ("Clipping", Clipping);
     glutAddSubMenu ("Shadow", Shadow);
     glutAddSubMenu ("Curve", Curve);
    glutAttachMenu (0x0000);
    glutMouseFunc (mousedeal);
    glutKeyboardFunc (keyfun);
    glutMainLoop();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: Basic int

variable_types: Clipping int

variable_types: Curve int

variable_types: Shadow int

variable_types: Fill int


decompiled_code:
__int64 __fastcall comp_slope(int *a1, int *a2)
{
int v2; // eax
int v3; // edx

v2 = *a1;
v3 = *a2;
if ( *a2 * *a1 > 0 )
{
v2 *= a2[1];
v3 *= a1[1];
}
return (unsigned int)(v2 - v3);
}

original_code:
int comp_slope(const void *a,const void *b)
{
 int t1 = ((struct slope *)a)->dx * ((struct slope *)b)->dy;
 int t2 = ((struct slope *)a)->dy * ((struct slope *)b)->dx;
 int t3 = ((struct slope *)a)->dx * ((struct slope *)b)->dx;
 if (t3 <= 0) return ((struct slope *)a)->dx - ((struct slope *)b)->dx;
 else return t1-t2;
}

canonical_original_code:
int comp_slope(void *a, void *b)
{
 int t1 = ((struct slope *)a)->dx * ((struct slope *)b)->dy;
 int t2 = ((struct slope *)a)->dy * ((struct slope *)b)->dx;
 int t3 = ((struct slope *)a)->dx * ((struct slope *)b)->dx;
 if (t3 <= 0) return ((struct slope *)a)->dx - ((struct slope *)b)->dx;
 else return t1-t2;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall comp_line(const void *a1, const void *a2)
{
__int64 result; // rax

result = (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
if ( !(_DWORD)result )
{
result = (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
result = comp_slope((int *)a1 + 6, (int *)a2 + 6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
__int64 result; // rax

result = (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
if ( !(_DWORD)result )
{
result = (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
result = func0((int *)a1 + 6, (int *)a2 + 6);
}
return result;
}

original_code:
int comp_line(const void *a,const void *b)
{
 int t1 = ((struct line *)a)->p1.y-((struct line *)b)->p1.y;
 int t2 = ((struct line *)a)->p1.x-((struct line *)b)->p1.x;
 if (t1 != 0) return t1;
 else if (t2 != 0) return t2;
 else return comp_slope(&((struct line *)a)->sl,&((struct line *)b)->sl);
}

canonical_original_code:
int comp_line(void *a, void *b)
{
 int t1 = ((struct line *)a)->p1.y-((struct line *)b)->p1.y;
 int t2 = ((struct line *)a)->p1.x-((struct line *)b)->p1.x;
 if (t1 != 0) return t1;
 else if (t2 != 0) return t2;
 else return comp_slope(&((struct line *)a)->sl,&((struct line *)b)->sl);
}


makeline

original_code:
void makeline(struct poly *pol)
{
 int i;
 for (i=0;i < pol->ver_num;++i)
 {
  pol->edge[i].p1 = pol->vertex[i];
  pol->edge[i].p2 = pol->vertex[(i+1)%pol->ver_num];
 }
}

variable_types: struct poly { struct point { int x; } vertex[50]; struct line { struct point p1; struct slope { int dx; } sl; } edge[50]; int ver_num; } *

variable_types: i int

user_defined_types: struct poly { struct point vertex[50]; struct line edge[50]; int ver_num; }


nomalize

decompiled_code:
__int64 __fastcall nomalize(_DWORD *a1)
{
int v1; // eax

v1 = a1[4];
if ( a1[1] <= v1 && (a1[1] != v1 || *a1 <= a1[3]) )
return cal_sl(a1);
swap_poi(a1, a1 + 3);
return cal_sl(a1);
}

original_code:
void nomalize(struct line *l)
{
 if (l->p1.y > l->p2.y || (l->p1.y == l->p2.y && l->p1.x > l->p2.x))
   swap_poi(&l->p1,&l->p2);
  cal_sl(l);
}

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


readpolygon

original_code:
void readpolygon(struct poly *pol)
{
 readint(&pol->ver_num);
 int i;
 for (i=0;i < pol->ver_num;++i) pol->vertex[i]=readpoint();
 makeline(pol);
}


drawpolygon

decompiled_code:
__int64 __fastcall drawpolygon(__int64 a1, double a2, float a3)
{
__int64 result; // rax
int v4; // ebx

result = *(unsigned int *)(a1 + 2200);
if ( (int)result > 0 )
{
v4 = 0;
do
{
++v4;
result = drawline(a2, a3);
}
while ( *(_DWORD *)(a1 + 2200) > v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, double a2, float a3)
{
__int64 result; // rax
int v4; // ebx

result = *(unsigned int *)(a1 + 2200);
if ( (int)result > 0 )
{
v4 = 0;
do
{
++v4;
result = drawline(a2, a3);
}
while ( *(_DWORD *)(a1 + 2200) > v4 );
}
return result;
}

original_code:
void drawpolygon(struct poly *pol,struct colour c)
{
 int i;
 for (i=0;i < pol->ver_num; ++i)
 {
  drawline(pol->edge[i],c);
 }
}

canonical_original_code:
void drawpolygon(struct poly *pol, struct colour c)
{
 int i;
 for (i=0;i < pol->ver_num; ++i)
 {
  drawline(pol->edge[i],c);
 }
}

variable_types:
c
struct colour { float r; }


original_code:
int in_poly(struct poly *pol,struct point p)
{
 struct line l;
 l.p1 = p; l.p2 = p;
 l.p2.x += 601;
 l.p2.y += 1;
 int i,j = 0;
 for (i = 0;i < pol->ver_num; ++i)
  if (interset(l, pol->edge[i]) > 1) return 1;
  else if (interset(l, pol->edge[i]) == 1) ++j;
 return j&1;
}

canonical_original_code:
int in_poly(struct poly *pol, struct point p)
{
 struct line l;
 l.p1 = p; l.p2 = p;
 l.p2.x += 601;
 l.p2.y += 1;
 int i; int j = 0;
 for (i = 0;i < pol->ver_num; ++i)
  if (interset(l, pol->edge[i]) > 1) return 1;
  else if (interset(l, pol->edge[i]) == 1) ++j;
 return j&1;
}

variable_types:
p
struct point

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

variable_types: j int