original_code:
void parse_descriptors(int info_len,unsigned char *buf, transponder_t* transponder, transponder_t** transponders) {
  int i=0;
  int descriptor_tag,descriptor_length,j,k,pid,id;
  int service_type;
  char tmp[128];
  unsigned int freq, pol, sr;
       while (i < info_len) {
        descriptor_tag=buf[i++];
        descriptor_length=buf[i++];
        while (descriptor_length > 0) {
          switch(descriptor_tag) {
           case 0x03:
             printf("<audio_info tag=\"0x03\" info=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x06:
             printf("<data_stream_alignment tag=\"0x06\" data=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x0a:
             for (j=0;j<((descriptor_length)/4);j++) {
               printf("<iso_639 language=\"");
               if (buf[i]!=0) printf("%c",buf[i]);
               if (buf[i+1]!=0) printf("%c",buf[i+1]);
               if (buf[i+2]!=0) printf("%c",buf[i+2]);
               printf("\" type=\"%d\" />\n",buf[i+3]);
               i+=4;
               descriptor_length-=4;
             }
             break;
           case 0x0b:
             printf("<system_clock tag=\"0x0b\" data=\"%02x%02x\" />\n",buf[i],buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x09:
             k=((buf[i]<<8)|buf[i+1]);
             switch(k&0xff00) {
               case 0x0100:
                 for (j=2; j<descriptor_length; j+=15)
                 {
                   pid = ((buf[i+j] & 0x1f) << 8) | buf[i+j+1];
                   id = (buf[i+j+2] << 8) | buf[i+j+3];
                   printf("<ca_system_descriptor type=\"seca\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                 }
                 break;
               case 0x0500:
                 j = 4;
                 while (j < descriptor_length)
                 {
                   if (buf[i+j]==0x14)
                   {
                     pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                     id = (buf[i+j+2] << 16) | (buf[i+j+3] << 8) | (buf[i+j+4] & 0xf0);
                     printf("<ca_system_descriptor type=\"viaccess\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                   }
                   j += 2+buf[i+j+1];
                 }
                 break;
               case 0x0600:
               case 0x1700:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"irdeto\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x1800:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"nagra\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0b00:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"conax\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0900:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"videoguard\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               default:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"unknown\" system_id=\"0x%04x\" />\n",k);
                 break;
               }
               i+=descriptor_length;
               descriptor_length=0;
               break;
           case 0x40:
             j=descriptor_length;
             while(j > 0) {
               j--;
             }
             descriptor_length=0;
             break;
           case 0x41:
             while (descriptor_length > 0) {
               i+=3;
               descriptor_length-=3;
             }
             break;
           case 0x43:
             freq=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
             sprintf(tmp,"%x",freq);
             transponder->freq=atoi(tmp)*10;
             i+=4;
             transponder->pos=(buf[i]<<8)|buf[i+1];
             i+=2;
             transponder->we_flag=(buf[i]&0x80)>>7;
             pol=(buf[i]&0x60)>>5;
             switch(pol) {
                 case 0 : transponder->pol='H'; break;
                 case 1 : transponder->pol='V'; break;
                 case 2 : transponder->pol='L'; break;
                 case 3 : transponder->pol='R'; break;
             }
             transponder->mod=buf[i]&0x1f;
             i++;
             sr=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|(buf[i+3]&0xf0);
             sr=(unsigned int)(sr >> 4);
             sprintf(tmp,"%x",sr);
             transponder->srate=atoi(tmp)*100;
             i+=4;
             descriptor_length=0;
             add_transponder(transponder,transponders);
      break;
           case 0x48:
             service_type=buf[i++];
             printf("<description tag=\"0x48\" type=\"%d\"",service_type);
             descriptor_length--;
             j=buf[i++];
             descriptor_length-=(j+1);
             printf(" provider_name=\"");;
             while(j > 0) {
               printf("%s",xmlify(buf[i++]));
               j--;
             }
             printf("\" service_name=\"");
             j=buf[i++];
             descriptor_length-=(j+1);
             while(j > 0) {
               printf("%s",xmlify(buf[i]));
               i++;
               j--;
             }
             printf("\" />\n");
             break;
           case 0x49:
             printf("<country_availability tag=\"0x49\" type=\"%d\" countries=\" ",(buf[i]&0x80)>>7);
             i++;
             j=descriptor_length-1;
             while (j > 0) {
               printf("%c",buf[i++]);
               j--;
             }
             printf("\" />\n");
             descriptor_length=0;
             break;
          case 0x4c:
             printf("<time_shifted_copy_of tag=\"0x4c\" service_id=\"%d\" />\n",(buf[i]<<8)|buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x52:
             printf("<stream_id id=\"%d\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x53:
             printf("<ca_identifier tag=\"0x53\" length=\"%02x\">\n",descriptor_length);
             for (j=0;j<descriptor_length;j+=2) {
               k=(buf[i+j]<<8)|buf[i+j+1];
               printf("<ca_system_id>%04x</ca_system_id>\n",k);
             }
             i+=descriptor_length;
             descriptor_length=0;
             printf("</ca_identifier>\n");
             break;
          case 0x56:
             j=0;
             printf("<teletext tag=\"0x56\">\n");
             while (j < descriptor_length) {
               printf("<teletext_info lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               k=(buf[i+3]&0x07);
               printf("\" type=\"%d\" page=\"%d%02x\" />\n",(buf[i+3]&0xf8)>>3,(k==0 ? 8 : k),buf[i+4]);
               i+=5;
               j+=5;
             }
             printf("</teletext>\n");
             descriptor_length=0;
             break;
          case 0x59:
             j=0;
             printf("<subtitling_descriptor tag=\"0x59\">\n");
             while (j < descriptor_length) {
               printf("<subtitle_stream lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               printf("\" type=\"%d\" composition_page_id=\"%04x\" ancillary_page_id=\"%04x\" />\n",buf[i+3],(buf[i+4]<<8)|buf[i+5],(buf[i+6]<<8)|buf[i+7]);
               i+=8;
               j+=8;
             }
             printf("</subtitling_descriptor>\n");
             descriptor_length=0;
             break;
          case 0x6a:
             printf("<ac3_descriptor tag=\"0x6a\" data=\"");
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x73:
             printf("<default_authority_descriptor tag=\"0x%02x\" name=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short int) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0xc5:
            printf("<canal_radio tag=\"0x%02x\" id=\"%d\" name=\"",descriptor_tag,buf[i]);
            for (j=1;j<descriptor_length;j++)
              if (buf[i+j]!=0) printf("%c",buf[i+j]);
            printf("\" />\n");
            i+=descriptor_length;
            descriptor_length=0;
            break;
          default:
             printf("<descriptor tag=\"0x%02x\" data=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" text=\"");
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short int) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          }
        }
      }
}

canonical_original_code:
void parse_descriptors(int info_len, unsigned char *buf, struct _transponder_t *transponder, struct _transponder_t **transponders) {
  int i = 0;
  int descriptor_tag; int descriptor_length; int j; int k; int pid; int id;
  int service_type;
  char tmp[128];
  unsigned int freq; unsigned int pol; unsigned int sr;
       while (i < info_len) {
        descriptor_tag=buf[i++];
        descriptor_length=buf[i++];
        while (descriptor_length > 0) {
          switch(descriptor_tag) {
           case 0x03:
             printf("<audio_info tag=\"0x03\" info=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x06:
             printf("<data_stream_alignment tag=\"0x06\" data=\"%02x\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x0a:
             for (j=0;j<((descriptor_length)/4);j++) {
               printf("<iso_639 language=\"");
               if (buf[i]!=0) printf("%c",buf[i]);
               if (buf[i+1]!=0) printf("%c",buf[i+1]);
               if (buf[i+2]!=0) printf("%c",buf[i+2]);
               printf("\" type=\"%d\" />\n",buf[i+3]);
               i+=4;
               descriptor_length-=4;
             }
             break;
           case 0x0b:
             printf("<system_clock tag=\"0x0b\" data=\"%02x%02x\" />\n",buf[i],buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
           case 0x09:
             k=((buf[i]<<8)|buf[i+1]);
             switch(k&0xff00) {
               case 0x0100:
                 for (j=2; j<descriptor_length; j+=15)
                 {
                   pid = ((buf[i+j] & 0x1f) << 8) | buf[i+j+1];
                   id = (buf[i+j+2] << 8) | buf[i+j+3];
                   printf("<ca_system_descriptor type=\"seca\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                 }
                 break;
               case 0x0500:
                 j = 4;
                 while (j < descriptor_length)
                 {
                   if (buf[i+j]==0x14)
                   {
                     pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                     id = (buf[i+j+2] << 16) | (buf[i+j+3] << 8) | (buf[i+j+4] & 0xf0);
                     printf("<ca_system_descriptor type=\"viaccess\" system_id=\"0x%04x\" ecm_pid=\"%d\" ecm_id=\"%06x\" />\n",k,pid,id);
                   }
                   j += 2+buf[i+j+1];
                 }
                 break;
               case 0x0600:
               case 0x1700:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"irdeto\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x1800:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"nagra\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0b00:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"conax\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               case 0x0900:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"videoguard\" system_id=\"0x%04x\" ecm_pid=\"%d\" />\n",k,pid);
                 break;
               default:
                 pid = ((buf[i+2] & 0x1f) << 8) | buf[i+3];
                 printf("<ca_system_descriptor type=\"unknown\" system_id=\"0x%04x\" />\n",k);
                 break;
               }
               i+=descriptor_length;
               descriptor_length=0;
               break;
           case 0x40:
             j=descriptor_length;
             while(j > 0) {
               j--;
             }
             descriptor_length=0;
             break;
           case 0x41:
             while (descriptor_length > 0) {
               i+=3;
               descriptor_length-=3;
             }
             break;
           case 0x43:
             freq=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|buf[i+3];
             sprintf(tmp,"%x",freq);
             transponder->freq=atoi(tmp)*10;
             i+=4;
             transponder->pos=(buf[i]<<8)|buf[i+1];
             i+=2;
             transponder->we_flag=(buf[i]&0x80)>>7;
             pol=(buf[i]&0x60)>>5;
             switch(pol) {
                 case 0 : transponder->pol='H'; break;
                 case 1 : transponder->pol='V'; break;
                 case 2 : transponder->pol='L'; break;
                 case 3 : transponder->pol='R'; break;
             }
             transponder->mod=buf[i]&0x1f;
             i++;
             sr=(unsigned int)(buf[i]<<24)|(buf[i+1]<<16)|(buf[i+2]<<8)|(buf[i+3]&0xf0);
             sr=(unsigned int)(sr >> 4);
             sprintf(tmp,"%x",sr);
             transponder->srate=atoi(tmp)*100;
             i+=4;
             descriptor_length=0;
             add_transponder(transponder,transponders);
      break;
           case 0x48:
             service_type=buf[i++];
             printf("<description tag=\"0x48\" type=\"%d\"",service_type);
             descriptor_length--;
             j=buf[i++];
             descriptor_length-=(j+1);
             printf(" provider_name=\"");;
             while(j > 0) {
               printf("%s",xmlify(buf[i++]));
               j--;
             }
             printf("\" service_name=\"");
             j=buf[i++];
             descriptor_length-=(j+1);
             while(j > 0) {
               printf("%s",xmlify(buf[i]));
               i++;
               j--;
             }
             printf("\" />\n");
             break;
           case 0x49:
             printf("<country_availability tag=\"0x49\" type=\"%d\" countries=\" ",(buf[i]&0x80)>>7);
             i++;
             j=descriptor_length-1;
             while (j > 0) {
               printf("%c",buf[i++]);
               j--;
             }
             printf("\" />\n");
             descriptor_length=0;
             break;
          case 0x4c:
             printf("<time_shifted_copy_of tag=\"0x4c\" service_id=\"%d\" />\n",(buf[i]<<8)|buf[i+1]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x52:
             printf("<stream_id id=\"%d\" />\n",buf[i]);
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x53:
             printf("<ca_identifier tag=\"0x53\" length=\"%02x\">\n",descriptor_length);
             for (j=0;j<descriptor_length;j+=2) {
               k=(buf[i+j]<<8)|buf[i+j+1];
               printf("<ca_system_id>%04x</ca_system_id>\n",k);
             }
             i+=descriptor_length;
             descriptor_length=0;
             printf("</ca_identifier>\n");
             break;
          case 0x56:
             j=0;
             printf("<teletext tag=\"0x56\">\n");
             while (j < descriptor_length) {
               printf("<teletext_info lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               k=(buf[i+3]&0x07);
               printf("\" type=\"%d\" page=\"%d%02x\" />\n",(buf[i+3]&0xf8)>>3,(k==0 ? 8 : k),buf[i+4]);
               i+=5;
               j+=5;
             }
             printf("</teletext>\n");
             descriptor_length=0;
             break;
          case 0x59:
             j=0;
             printf("<subtitling_descriptor tag=\"0x59\">\n");
             while (j < descriptor_length) {
               printf("<subtitle_stream lang=\"");
               printf("%s",xmlify(buf[i]));
               printf("%s",xmlify(buf[i+1]));
               printf("%s",xmlify(buf[i+2]));
               printf("\" type=\"%d\" composition_page_id=\"%04x\" ancillary_page_id=\"%04x\" />\n",buf[i+3],(buf[i+4]<<8)|buf[i+5],(buf[i+6]<<8)|buf[i+7]);
               i+=8;
               j+=8;
             }
             printf("</subtitling_descriptor>\n");
             descriptor_length=0;
             break;
          case 0x6a:
             printf("<ac3_descriptor tag=\"0x6a\" data=\"");
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0x73:
             printf("<default_authority_descriptor tag=\"0x%02x\" name=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          case 0xc5:
            printf("<canal_radio tag=\"0x%02x\" id=\"%d\" name=\"",descriptor_tag,buf[i]);
            for (j=1;j<descriptor_length;j++)
              if (buf[i+j]!=0) printf("%c",buf[i+j]);
            printf("\" />\n");
            i+=descriptor_length;
            descriptor_length=0;
            break;
          default:
             printf("<descriptor tag=\"0x%02x\" data=\"",descriptor_tag);
             for (j=0;j<descriptor_length;j++) printf("%02x",buf[i+j]);
             printf("\" text=\"");
             for (j=0;j<descriptor_length;j++) printf("%c",(((*__ctype_b_loc ())[(int) ((buf[i+j]))] & (unsigned short) _ISalnum) ? buf[i+j] : '.'));
             printf("\" />\n");
             i+=descriptor_length;
             descriptor_length=0;
             break;
          }
        }
      }
}

variable_types:
buf
unsigned char *

variable_types:
transponders
struct _transponder_t **

variable_types: j int

variable_types: k int

variable_types: pid int

variable_types: id int

variable_types:
tmp
char [128]

variable_types:
freq
unsigned int

variable_types:
pol
unsigned int

variable_types:
sr
unsigned int

user_defined_types: struct _transponder_t { int id; int onid; unsigned int freq; int srate; int pos; int we_flag; char pol; int mod; int scanned; struct _transponder_t *next; }


repo: linzhi/GameMix

decompiled_code:
int snake_init()
{
_DWORD *v0; // rax
int v1; // edx
WINDOW *v2; // rdi
int v3; // kr00_4
int v4; // edx
unsigned int v5; // er12
int v6; // er12
int v7; // er14
__int64 v8; // rbp
int v9; // ebx
WINDOW *v10; // rdi
int *v11; // rax

wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
*((_DWORD *)&snake + 3) = 0;
snake = 0x800000001LL;
v0 = malloc(0x40uLL);
v1 = COLS;
v2 = stdscr;
*(&snake + 2) = (__int64)v0;
v3 = v1;
v4 = LINES;
v5 = LINES;
*v0 = v3 / 2;
v6 = (int)(v4 + (v5 >> 31)) >> 1;
v0[1] = v6;
if ( wmove(v2, v6, v3 / 2) != -1 )
waddch(stdscr, 0x58uLL);
if ( SHIDWORD(snake) > 1 )
{
v7 = v3 / 2;
v8 = 8LL;
do
{
v9 = v7++;
v10 = stdscr;
v11 = (int *)(v8 + *(&snake + 2));
*v11 = v7;
v11[1] = v6;
if ( wmove(v10, v6, v7) != -1 )
waddch(stdscr, 0x4FuLL);
v8 += 8LL;
}
while ( v9 + 2 - v3 / 2 < SHIDWORD(snake) );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
_DWORD *v0; // rax
int v1; // edx
WINDOW *v2; // rdi
int v3; // kr00_4
int v4; // edx
unsigned int v5; // er12
int v6; // er12
int v7; // er14
__int64 v8; // rbp
int v9; // ebx
WINDOW *v10; // rdi
int *v11; // rax

wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
*((_DWORD *)&snake + 3) = 0;
snake = 0x800000001LL;
v0 = malloc(0x40uLL);
v1 = COLS;
v2 = stdscr;
*(&snake + 2) = (__int64)v0;
v3 = v1;
v4 = LINES;
v5 = LINES;
*v0 = v3 / 2;
v6 = (int)(v4 + (v5 >> 31)) >> 1;
v0[1] = v6;
if ( wmove(v2, v6, v3 / 2) != -1 )
waddch(stdscr, 0x58uLL);
if ( SHIDWORD(snake) > 1 )
{
v7 = v3 / 2;
v8 = 8LL;
do
{
v9 = v7++;
v10 = stdscr;
v11 = (int *)(v8 + *(&snake + 2));
*v11 = v7;
v11[1] = v6;
if ( wmove(v10, v6, v7) != -1 )
waddch(stdscr, 0x4FuLL);
v8 += 8LL;
}
while ( v9 + 2 - v3 / 2 < SHIDWORD(snake) );
}
return wrefresh(stdscr);
}

original_code:
void snake_init()
{
    wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    int i = 0;
    snake.score = 0;
    snake.speed = 1;
    snake.size = 8;
    snake.body = malloc((snake.size) * sizeof(struct snake_body_t));
    if (snake.body == ((void *)0))
    {
        ;
    }
    int m = COLS / 2;
    int n = LINES / 2;
    snake.body[0].x = m;
    snake.body[0].y = n;
    (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
    for (i = 1; i < snake.size; i++)
    {
        m++;
        snake.body[i].x = m;
        snake.body[i].y = n;
        (wmove((stdscr),((snake.body[i].y)),((snake.body[i].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
    }
    wrefresh(stdscr);
}

variable_types: i int

variable_types: m int

variable_types: n int

return_type: void


decompiled_code:
int snake_fruit_init()
{
unsigned int v0; // eax
int v1; // eax
WINDOW *v2; // rdi
int v3; // esi
int v4; // edx
__int64 v5; // rbx
_DWORD *v6; // rax

wattr_off(stdscr, 0x500uLL, 0LL);
wattr_on(stdscr, 0x300uLL, 0LL);
v0 = time(0LL);
srand(v0);
fruit = rand() % (COLS - 2) + 1;
v1 = rand();
v2 = stdscr;
v3 = v1 % (LINES - 2) + 1;
v4 = fruit;
*(&fruit + 1) = v3;
if ( wmove(v2, v3, v4) != -1 )
waddch(stdscr, 0x24uLL);
if ( SHIDWORD(snake) > 1 )
{
v5 = 0LL;
do
{
v6 = (_DWORD *)(*(&snake + 2) + 8 * v5);
if ( fruit == *v6 && *(&fruit + 1) == v6[1] )
snake_fruit_init();
++v5;
}
while ( HIDWORD(snake) - 1 > (int)v5 );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func1()
{
unsigned int v0; // eax
int v1; // eax
WINDOW *v2; // rdi
int v3; // esi
int v4; // edx
__int64 v5; // rbx
_DWORD *v6; // rax

wattr_off(stdscr, 0x500uLL, 0LL);
wattr_on(stdscr, 0x300uLL, 0LL);
v0 = time(0LL);
srand(v0);
fruit = rand() % (COLS - 2) + 1;
v1 = rand();
v2 = stdscr;
v3 = v1 % (LINES - 2) + 1;
v4 = fruit;
*(&fruit + 1) = v3;
if ( wmove(v2, v3, v4) != -1 )
waddch(stdscr, 0x24uLL);
if ( SHIDWORD(snake) > 1 )
{
v5 = 0LL;
do
{
v6 = (_DWORD *)(*(&snake + 2) + 8 * v5);
if ( fruit == *v6 && *(&fruit + 1) == v6[1] )
func1();
++v5;
}
while ( HIDWORD(snake) - 1 > (int)v5 );
}
return wrefresh(stdscr);
}

original_code:
void snake_fruit_init()
{
    wattr_off(stdscr, (attr_t)(((((chtype)(((GREEN_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    wattr_on(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    srand((int)time(((void *)0)));
    int valid_fruit = 0;
    fruit.x_pos = (rand() % (COLS - 2)) + 1;
    fruit.y_pos = (rand() % (LINES - 2)) + 1;
    (wmove((stdscr),((fruit.y_pos)),((fruit.x_pos))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_FRUIT_CHAR))));
    int i;
    for (i = 0; i < (snake.size - 1); i++)
    {
        if ((fruit.x_pos == snake.body[i].x) &&
            (fruit.y_pos == snake.body[i].y))
        {
            snake_fruit_init();
        }
    }
    wrefresh(stdscr);
}


decompiled_code:
int snake_borders_init()
{
int v0; // ebx
int v1; // ebx

wclear(stdscr);
wattr_off(stdscr, 0x400uLL, 0LL);
wattr_on(stdscr, 0x500uLL, 0LL);
if ( LINES > 1 )
{
v0 = 1;
do
{
if ( wmove(stdscr, v0, 0) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, v0, COLS - 1) != -1 )
waddch(stdscr, 0x2BuLL);
++v0;
}
while ( LINES > v0 );
}
if ( COLS > 0 )
{
v1 = 0;
do
{
if ( wmove(stdscr, 0, v1) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, LINES - 1, v1) != -1 )
waddch(stdscr, 0x2BuLL);
++v1;
}
while ( COLS > v1 );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func2()
{
int v0; // ebx
int v1; // ebx

wclear(stdscr);
wattr_off(stdscr, 0x400uLL, 0LL);
wattr_on(stdscr, 0x500uLL, 0LL);
if ( LINES > 1 )
{
v0 = 1;
do
{
if ( wmove(stdscr, v0, 0) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, v0, COLS - 1) != -1 )
waddch(stdscr, 0x2BuLL);
++v0;
}
while ( LINES > v0 );
}
if ( COLS > 0 )
{
v1 = 0;
do
{
if ( wmove(stdscr, 0, v1) != -1 )
waddch(stdscr, 0x2BuLL);
if ( wmove(stdscr, LINES - 1, v1) != -1 )
waddch(stdscr, 0x2BuLL);
++v1;
}
while ( COLS > v1 );
}
return wrefresh(stdscr);
}


decompiled_code:
void __noreturn snake_move_init()
{
int *v0; // rax
int v1; // edi
int *v2; // rsi
int *v3; // rax
__int64 v4; // rcx
int v5; // edx
int v6; // edx

while ( 1 )
{
v0 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v0[1], *v0) != -1 )
waddch(stdscr, 0x20uLL);
v1 = HIDWORD(snake);
v2 = (int *)*(&snake + 2);
if ( v1 > 1 )
{
v3 = &v2[2 * v1];
v4 = (__int64)&v3[-2 * (v1 - 2) - 2];
do
{
v5 = *(v3 - 4);
v3 -= 2;
*v3 = v5;
v3[1] = *(v3 - 1);
}
while ( (int *)v4 != v3 );
}
v6 = *v2 - snake;
*v2 = v6;
if ( wmove(stdscr, v2[1], v6) != -1 )
waddch(stdscr, 0x58uLL);
wrefresh(stdscr);
}
}

canonical_decompiled_code:
void __noreturn func3()
{
int *v0; // rax
int v1; // edi
int *v2; // rsi
int *v3; // rax
__int64 v4; // rcx
int v5; // edx
int v6; // edx

while ( 1 )
{
v0 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v0[1], *v0) != -1 )
waddch(stdscr, 0x20uLL);
v1 = HIDWORD(snake);
v2 = (int *)*(&snake + 2);
if ( v1 > 1 )
{
v3 = &v2[2 * v1];
v4 = (__int64)&v3[-2 * (v1 - 2) - 2];
do
{
v5 = *(v3 - 4);
v3 -= 2;
*v3 = v5;
v3[1] = *(v3 - 1);
}
while ( (int *)v4 != v3 );
}
v6 = *v2 - snake;
*v2 = v6;
if ( wmove(stdscr, v2[1], v6) != -1 )
waddch(stdscr, 0x58uLL);
wrefresh(stdscr);
}
}

original_code:
void snake_move_init()
{
    while (1)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        int i;
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        wrefresh(stdscr);
    }
}


decompiled_code:
void *snake_increase()
{
int v0; // eax
void *v1; // rdi
void *result; // rax

v0 = HIDWORD(snake);
v1 = (void *)*(&snake + 2);
HIDWORD(snake) = v0 + 1;
result = realloc(v1, 8 * (v0 + 1));
*(&snake + 2) = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func4()
{
int v0; // eax
void *v1; // rdi
void *result; // rax

v0 = HIDWORD(snake);
v1 = (void *)*(&snake + 2);
HIDWORD(snake) = v0 + 1;
result = realloc(v1, 8 * (v0 + 1));
*(&snake + 2) = (__int64)result;
return result;
}

original_code:
void snake_increase()
{
    int body_size = sizeof(struct snake_body_t);
    snake.size += 1;
    snake.body = realloc(snake.body, (snake.size * body_size));
    if (snake.body == ((void *)0))
    {
        ;
    }
}


decompiled_code:
_BOOL8 snake_eat_fruit()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

v0 = (_DWORD *)*(&snake + 2);
result = 0LL;
if ( *v0 == fruit )
result = v0[1] == *(&fruit + 1);
return result;
}

canonical_decompiled_code:
_BOOL8 func5()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

v0 = (_DWORD *)*(&snake + 2);
result = 0LL;
if ( *v0 == fruit )
result = v0[1] == *(&fruit + 1);
return result;
}

original_code:
int snake_eat_fruit()
{
    if ((snake.body[0].x == fruit.x_pos) &&
        (snake.body[0].y == fruit.y_pos))
        return 1;
    else
        return 0;
}

return_type: int


decompiled_code:
_BOOL8 snake_collide_snake()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

if ( SHIDWORD(snake) > 2 )
{
v0 = (_DWORD *)*(&snake + 2);
result = 0LL;
if ( *v0 == v0[2] )
result = v0[1] == v0[3];
}
return result;
}

canonical_decompiled_code:
_BOOL8 func6()
{
_DWORD *v0; // rdx
_BOOL8 result; // rax

if ( SHIDWORD(snake) > 2 )
{
v0 = (_DWORD *)*(&snake + 2);
result = 0LL;
if ( *v0 == v0[2] )
result = v0[1] == v0[3];
}
return result;
}

original_code:
int snake_collide_snake()
{
   int i;
   for (i = 1; i < (snake.size - 1); i++)
   {
        if ((snake.body[0].x == snake.body[i].x) &&
            (snake.body[0].y == snake.body[i].y))
            return 1;
        else
            return 0;
   }
}


decompiled_code:
int snake_move()
{
int result; // eax
int *v1; // rax
int v2; // edi
int *v3; // rsi
int *v4; // rax
__int64 v5; // rcx
int v6; // edx
int v7; // er8
int v8; // edx
WINDOW *v9; // rdi
__int64 v10; // rbp
int j; // ebx
int *v12; // rax
int v13; // edi
int *v14; // rsi
int *v15; // rax
__int64 v16; // rcx
int v17; // edx
int v18; // er8
int v19; // edx
WINDOW *v20; // rdi
__int64 v21; // rbp
int i; // ebx
int *v23; // rax
int *v24; // rax
int v25; // edi
int *v26; // rsi
int *v27; // rax
__int64 v28; // rcx
int v29; // edx
int v30; // edx
__int64 v31; // rbp
int k; // ebx
int *v33; // rax
int *v34; // rax
int v35; // edi
int *v36; // rsi
int *v37; // rax
__int64 v38; // rcx
int v39; // edx
int v40; // edx
__int64 v41; // rbp
int l; // ebx
int *v43; // rax
int *v44; // rax

key_input();
if ( key_up )
{
v12 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v12[1], *v12) != -1 )
waddch(stdscr, 0x20uLL);
v13 = HIDWORD(snake);
v14 = (int *)*(&snake + 2);
if ( v13 > 1 )
{
v15 = &v14[2 * v13];
v16 = (__int64)&v15[-2 * (v13 - 2) - 2];
do
{
v17 = *(v15 - 4);
v15 -= 2;
*v15 = v17;
v15[1] = *(v15 - 1);
}
while ( v15 != (int *)v16 );
}
v18 = v14[1] - snake;
v19 = *v14;
v20 = stdscr;
v14[1] = v18;
if ( wmove(v20, v18, v19) != -1 )
waddch(stdscr, 0x58uLL);
v21 = 8LL;
for ( i = 1; SHIDWORD(snake) > i; v21 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v21 + *(&snake + 2) + 4), *(_DWORD *)(v21 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++i;
}
if ( snake_eat_fruit() )
{
*((_DWORD *)&snake + 3) += 5;
snake_increase();
v33 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v33[1], *v33) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !*(_DWORD *)(*(&snake + 2) + 4) || snake_collide_snake() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_up = 0;
}
else if ( key_down )
{
v1 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v1[1], *v1) != -1 )
waddch(stdscr, 0x20uLL);
v2 = HIDWORD(snake);
v3 = (int *)*(&snake + 2);
if ( v2 > 1 )
{
v4 = &v3[2 * v2];
v5 = (__int64)&v4[-2 * (v2 - 2) - 2];
do
{
v6 = *(v4 - 4);
v4 -= 2;
*v4 = v6;
v4[1] = *(v4 - 1);
}
while ( (int *)v5 != v4 );
}
v7 = v3[1] + snake;
v8 = *v3;
v9 = stdscr;
v3[1] = v7;
if ( wmove(v9, v7, v8) != -1 )
waddch(stdscr, 0x58uLL);
v10 = 8LL;
for ( j = 1; SHIDWORD(snake) > j; v10 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v10 + *(&snake + 2) + 4), *(_DWORD *)(v10 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++j;
}
if ( snake_eat_fruit() )
{
*((_DWORD *)&snake + 3) += 5;
snake_increase();
v23 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v23[1], *v23) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( *(_DWORD *)(*(&snake + 2) + 4) == LINES - 1 || snake_collide_snake() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_down = 0;
}
else if ( key_left )
{
v24 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v24[1], *v24) != -1 )
waddch(stdscr, 0x20uLL);
v25 = HIDWORD(snake);
v26 = (int *)*(&snake + 2);
if ( v25 > 1 )
{
v27 = &v26[2 * v25];
v28 = (__int64)&v27[-2 * (v25 - 2) - 2];
do
{
v29 = *(v27 - 4);
v27 -= 2;
*v27 = v29;
v27[1] = *(v27 - 1);
}
while ( (int *)v28 != v27 );
}
v30 = *v26 - snake;
*v26 = v30;
if ( wmove(stdscr, v26[1], v30) != -1 )
waddch(stdscr, 0x58uLL);
v31 = 8LL;
for ( k = 1; SHIDWORD(snake) > k; v31 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v31 + *(&snake + 2) + 4), *(_DWORD *)(v31 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++k;
}
if ( snake_eat_fruit() )
{
*((_DWORD *)&snake + 3) += 5;
snake_increase();
v43 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake));
if ( wmove(stdscr, v43[1], *v43) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !*(_DWORD *)*(&snake + 2) || snake_collide_snake() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_left = 0;
}
else
{
result = key_right;
if ( key_right )
{
v34 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v34[1], *v34) != -1 )
waddch(stdscr, 0x20uLL);
v35 = HIDWORD(snake);
v36 = (int *)*(&snake + 2);
if ( v35 > 1 )
{
v37 = &v36[2 * v35];
v38 = (__int64)&v37[-2 * (v35 - 2) - 2];
do
{
v39 = *(v37 - 4);
v37 -= 2;
*v37 = v39;
v37[1] = *(v37 - 1);
}
while ( v37 != (int *)v38 );
}
v40 = *v36 + snake;
*v36 = v40;
if ( wmove(stdscr, v36[1], v40) != -1 )
waddch(stdscr, 0x58uLL);
v41 = 8LL;
for ( l = 1; SHIDWORD(snake) > l; v41 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v41 + *(&snake + 2) + 4), *(_DWORD *)(v41 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++l;
}
if ( snake_eat_fruit() )
{
*((_DWORD *)&snake + 3) += 5;
snake_increase();
v44 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v44[1], *v44) != -1 )
waddch(stdscr, 0x4FuLL);
snake_fruit_init();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( *(_DWORD *)*(&snake + 2) == COLS - 1 || snake_collide_snake() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_right = 0;
}
}
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax
int *v1; // rax
int v2; // edi
int *v3; // rsi
int *v4; // rax
__int64 v5; // rcx
int v6; // edx
int v7; // er8
int v8; // edx
WINDOW *v9; // rdi
__int64 v10; // rbp
int j; // ebx
int *v12; // rax
int v13; // edi
int *v14; // rsi
int *v15; // rax
__int64 v16; // rcx
int v17; // edx
int v18; // er8
int v19; // edx
WINDOW *v20; // rdi
__int64 v21; // rbp
int i; // ebx
int *v23; // rax
int *v24; // rax
int v25; // edi
int *v26; // rsi
int *v27; // rax
__int64 v28; // rcx
int v29; // edx
int v30; // edx
__int64 v31; // rbp
int k; // ebx
int *v33; // rax
int *v34; // rax
int v35; // edi
int *v36; // rsi
int *v37; // rax
__int64 v38; // rcx
int v39; // edx
int v40; // edx
__int64 v41; // rbp
int l; // ebx
int *v43; // rax
int *v44; // rax

key_input();
if ( key_up )
{
v12 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v12[1], *v12) != -1 )
waddch(stdscr, 0x20uLL);
v13 = HIDWORD(snake);
v14 = (int *)*(&snake + 2);
if ( v13 > 1 )
{
v15 = &v14[2 * v13];
v16 = (__int64)&v15[-2 * (v13 - 2) - 2];
do
{
v17 = *(v15 - 4);
v15 -= 2;
*v15 = v17;
v15[1] = *(v15 - 1);
}
while ( v15 != (int *)v16 );
}
v18 = v14[1] - snake;
v19 = *v14;
v20 = stdscr;
v14[1] = v18;
if ( wmove(v20, v18, v19) != -1 )
waddch(stdscr, 0x58uLL);
v21 = 8LL;
for ( i = 1; SHIDWORD(snake) > i; v21 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v21 + *(&snake + 2) + 4), *(_DWORD *)(v21 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++i;
}
if ( func5() )
{
*((_DWORD *)&snake + 3) += 5;
func4();
v33 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v33[1], *v33) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !*(_DWORD *)(*(&snake + 2) + 4) || func6() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_up = 0;
}
else if ( key_down )
{
v1 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v1[1], *v1) != -1 )
waddch(stdscr, 0x20uLL);
v2 = HIDWORD(snake);
v3 = (int *)*(&snake + 2);
if ( v2 > 1 )
{
v4 = &v3[2 * v2];
v5 = (__int64)&v4[-2 * (v2 - 2) - 2];
do
{
v6 = *(v4 - 4);
v4 -= 2;
*v4 = v6;
v4[1] = *(v4 - 1);
}
while ( (int *)v5 != v4 );
}
v7 = v3[1] + snake;
v8 = *v3;
v9 = stdscr;
v3[1] = v7;
if ( wmove(v9, v7, v8) != -1 )
waddch(stdscr, 0x58uLL);
v10 = 8LL;
for ( j = 1; SHIDWORD(snake) > j; v10 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v10 + *(&snake + 2) + 4), *(_DWORD *)(v10 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++j;
}
if ( func5() )
{
*((_DWORD *)&snake + 3) += 5;
func4();
v23 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v23[1], *v23) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( *(_DWORD *)(*(&snake + 2) + 4) == LINES - 1 || func6() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_down = 0;
}
else if ( key_left )
{
v24 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v24[1], *v24) != -1 )
waddch(stdscr, 0x20uLL);
v25 = HIDWORD(snake);
v26 = (int *)*(&snake + 2);
if ( v25 > 1 )
{
v27 = &v26[2 * v25];
v28 = (__int64)&v27[-2 * (v25 - 2) - 2];
do
{
v29 = *(v27 - 4);
v27 -= 2;
*v27 = v29;
v27[1] = *(v27 - 1);
}
while ( (int *)v28 != v27 );
}
v30 = *v26 - snake;
*v26 = v30;
if ( wmove(stdscr, v26[1], v30) != -1 )
waddch(stdscr, 0x58uLL);
v31 = 8LL;
for ( k = 1; SHIDWORD(snake) > k; v31 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v31 + *(&snake + 2) + 4), *(_DWORD *)(v31 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++k;
}
if ( func5() )
{
*((_DWORD *)&snake + 3) += 5;
func4();
v43 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake));
if ( wmove(stdscr, v43[1], *v43) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( !*(_DWORD *)*(&snake + 2) || func6() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_left = 0;
}
else
{
result = key_right;
if ( key_right )
{
v34 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v34[1], *v34) != -1 )
waddch(stdscr, 0x20uLL);
v35 = HIDWORD(snake);
v36 = (int *)*(&snake + 2);
if ( v35 > 1 )
{
v37 = &v36[2 * v35];
v38 = (__int64)&v37[-2 * (v35 - 2) - 2];
do
{
v39 = *(v37 - 4);
v37 -= 2;
*v37 = v39;
v37[1] = *(v37 - 1);
}
while ( v37 != (int *)v38 );
}
v40 = *v36 + snake;
*v36 = v40;
if ( wmove(stdscr, v36[1], v40) != -1 )
waddch(stdscr, 0x58uLL);
v41 = 8LL;
for ( l = 1; SHIDWORD(snake) > l; v41 += 8LL )
{
if ( wmove(stdscr, *(_DWORD *)(v41 + *(&snake + 2) + 4), *(_DWORD *)(v41 + *(&snake + 2))) != -1 )
waddch(stdscr, 0x4FuLL);
++l;
}
if ( func5() )
{
*((_DWORD *)&snake + 3) += 5;
func4();
v44 = (int *)(*(&snake + 2) + 8LL * SHIDWORD(snake) - 8);
if ( wmove(stdscr, v44[1], *v44) != -1 )
waddch(stdscr, 0x4FuLL);
func1();
wattr_off(stdscr, 0x300uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
}
if ( *(_DWORD *)*(&snake + 2) == COLS - 1 || func6() )
{
engine_show_game_over();
free((void *)*(&snake + 2));
sleep(3u);
engine_show_game_menu();
}
result = wrefresh(stdscr);
key_right = 0;
}
}
return result;
}

original_code:
void snake_move()
{
    key_input();
    int i, j;
    int move_up = 1;
    int move_down = 0;
    int move_left = 0;
    int move_right = 0;
    if (key_up)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_up = 0;
    }
    else if (key_down)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == LINES - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_down = 0;
    }
    else if (key_left)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size].y)),((snake.body[snake.size].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_left = 0;
    }
    else if (key_right)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == COLS - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_right = 0;
    }
}

canonical_original_code:
void snake_move()
{
    key_input();
    int i; int j;
    int move_up = 1;
    int move_down = 0;
    int move_left = 0;
    int move_right = 0;
    if (key_up)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_up = 0;
    }
    else if (key_down)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].y = snake.body[0].y + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].y == LINES - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_down = 0;
    }
    else if (key_left)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x - snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size].y)),((snake.body[snake.size].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == 0) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_left = 0;
    }
    else if (key_right)
    {
        (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
        for (i = (snake.size - 1); i > 0; i--)
        {
            snake.body[i].x = snake.body[i-1].x;
            snake.body[i].y = snake.body[i-1].y;
        }
        snake.body[0].x = snake.body[0].x + snake.speed;
        (wmove((stdscr),((snake.body[0].y)),((snake.body[0].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_HEAD_CHAR))));
        for (j = 1; j < snake.size; j++)
        {
            (wmove((stdscr),((snake.body[j].y)),((snake.body[j].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
        }
        if (snake_eat_fruit())
        {
            snake.score = snake.score + 5;
            snake_increase();
            (wmove((stdscr),((snake.body[snake.size-1].y)),((snake.body[snake.size-1].x))) == (-1) ? (-1) : waddch((stdscr),((SNAKE_BODY_CHAR))));
            snake_fruit_init();
            wattr_off(stdscr, (attr_t)(((((chtype)(((RED_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
            wattr_on(stdscr, (attr_t)(((((chtype)(((BLUE_BLACK))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
        }
        if ((snake.body[0].x == COLS - 1) || snake_collide_snake())
        {
            engine_show_game_over();
            free(snake.body);
            sleep(3);
            engine_show_game_menu();
        }
        wrefresh(stdscr);
        key_right = 0;
    }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
engine_init(argc, argv, envp);
engine_show_game_menu();
while ( 1 )
{
key_input();
if ( snake_game )
break;
if ( tank_game )
{
tank_game = 0;
}
else if ( pushbox_game )
{
pushbox_game = 0;
}
else if ( esc_key )
{
engine_exit();
}
}
engine_show_snake_game_start();
snake_borders_init();
snake_fruit_init();
snake_init();
while ( 1 )
{
do
snake_move();
while ( !esc_key );
engine_exit();
}
}

original_code:
int main(int argc, char *argv[])
{
    engine_init();
    engine_show_game_menu();
    while (1)
    {
        key_input();
        if (snake_game)
        {
            engine_show_snake_game_start();
            snake_borders_init();
            snake_fruit_init();
            snake_init();
            while (1)
            {
                snake_move();
                if (esc_key)
                {
                    engine_exit();
                }
            }
            snake_game = 0;
        }
        else if (tank_game)
        {
            tank_game = 0;
        }
        else if (pushbox_game)
        {
            pushbox_game = 0;
        }
        else if (esc_key)
        {
            engine_exit();
        }
    }
    engine_exit();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int key_input()
{
int result; // eax

result = wgetch(stdscr);
if ( result == 258 )
{
key_down = 1;
return result;
}
if ( result <= 258 )
{
if ( result == 50 )
{
tank_game = 1;
return result;
}
if ( result <= 50 )
{
if ( result == 27 )
{
LABEL_7:
esc_key = 1;
return result;
}
if ( result == 49 )
snake_game = 1;
}
else if ( result == 51 )
{
pushbox_game = 1;
}
}
else
{
if ( result == 261 )
{
key_right = 1;
return result;
}
if ( result > 261 )
{
if ( result != 343 )
return result;
key_enter = 1;
goto LABEL_7;
}
if ( result == 259 )
key_up = 1;
else
key_left = 1;
}
return result;
}

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

result = wgetch(stdscr);
if ( result == 258 )
{
key_down = 1;
return result;
}
if ( result <= 258 )
{
if ( result == 50 )
{
tank_game = 1;
return result;
}
if ( result <= 50 )
{
if ( result == 27 )
{
LABEL_7:
esc_key = 1;
return result;
}
if ( result == 49 )
snake_game = 1;
}
else if ( result == 51 )
{
pushbox_game = 1;
}
}
else
{
if ( result == 261 )
{
key_right = 1;
return result;
}
if ( result > 261 )
{
if ( result != 343 )
return result;
key_enter = 1;
goto LABEL_7;
}
if ( result == 259 )
key_up = 1;
else
key_left = 1;
}
return result;
}

original_code:
void key_input()
{
    int input = wgetch(stdscr);
    switch(input)
    {
        case (-1):
            break;
        case '1':
            snake_game = 1;
            break;
        case '2':
            tank_game = 1;
            break;
        case '3':
            pushbox_game = 1;
            break;
        case 0403:
            key_up = 1;
            break;
        case 0402:
            key_down = 1;
            break;
        case 0404:
            key_left = 1;
            break;
        case 0405:
            key_right = 1;
            break;
        case 0407:
            break;
        case 0527:
            key_enter = 1;
        case 27:
            esc_key = 1;
            break;
        case 32:
            break;
        default:
            break;
    }
}

variable_types: input int


decompiled_code:
int engine_exit()
{
wclear(stdscr);
wrefresh(stdscr);
return endwin();
}

canonical_decompiled_code:
int func0()
{
wclear(stdscr);
wrefresh(stdscr);
return endwin();
}

original_code:
void engine_exit()
{
    wclear(stdscr);
    wrefresh(stdscr);
    endwin();
}


decompiled_code:
int engine_init()
{
initscr();
if ( !has_colors() )
{
engine_exit();
puts("Your terminal does not support colors.");
}
start_color();
init_pair(1, 4, 0);
init_pair(3, 1, 0);
init_pair(4, 7, 0);
init_pair(5, 2, 0);
init_pair(6, 2, 1);
init_pair(2, 3, 0);
raw();
curs_set(0);
keypad(stdscr, 1);
noecho();
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func1()
{
initscr();
if ( !has_colors() )
{
func0();
puts("Your terminal does not support colors.");
}
start_color();
init_pair(1, 4, 0);
init_pair(3, 1, 0);
init_pair(4, 7, 0);
init_pair(5, 2, 0);
init_pair(6, 2, 1);
init_pair(2, 3, 0);
raw();
curs_set(0);
keypad(stdscr, 1);
noecho();
return wrefresh(stdscr);
}

original_code:
void engine_init()
{
    initscr();
    if (has_colors() == 0)
    {
        engine_exit();
        printf("%s", "Your terminal does not support colors.\n" );
    }
    start_color();
    init_pair(BLUE_BLACK, 4, 0);
    init_pair(RED_BLACK, 1, 0);
    init_pair(WHITE_BLACK, 7, 0);
    init_pair(GREEN_BLACK, 2, 0);
    init_pair(GREEN_RED, 2, 1);
    init_pair(YELLOW_BLACK, 3, 0);
    raw();
    curs_set (0);
    keypad(stdscr, 1);
    noecho();
    wrefresh(stdscr);
}


mystart

repo: lirongyuan/ELF-Reader-and-Loader

decompiled_code:
int __fastcall mystart(__int64 a1, int a2, const char **a3)
{
FUNC_TABLE = a1;
return main(a2, a3, a3);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, const char **a3)
{
FUNC_TABLE = a1;
return main(a2, a3, a3);
}

original_code:
void mystart(FUNCPTR * func_table, int argc, char ** argv) {
  FUNC_TABLE = func_table;
  main(argc, argv);
}

canonical_original_code:
void mystart(int (**func_table)(), int argc, char **argv) {
  FUNC_TABLE = func_table;
  main(argc, argv);
}

variable_types:
argv
char **


printf

decompiled_code:
__int64 printf()
{
return (*(__int64 (**)(void))FUNC_TABLE)();
}

canonical_decompiled_code:
__int64 func1()
{
return (*(__int64 (**)(void))FUNC_TABLE)();
}

original_code:
int printf(char * s, int a1, int a2, int a3, int a4, int a5) {
  return (FUNC_TABLE[0])(s, a1, a2, a3, a4, a5);
}

canonical_original_code:
int printf(char *s, int a1, int a2, int a3, int a4, int a5) {
  return (FUNC_TABLE[0])(s, a1, a2, a3, a4, a5);
}

variable_types:
s
char *


gets

decompiled_code:
__int64 gets()
{
return (*(int (**)(void))(FUNC_TABLE + 8))();
}

canonical_decompiled_code:
__int64 func2()
{
return (*(int (**)(void))(FUNC_TABLE + 8))();
}

original_code:
char *gets(char *s){
 return (char *)(FUNC_TABLE[1])(s);
}

return_type: char *


strcpy

decompiled_code:
__int64 strcpy()
{
return (*(int (**)(void))(FUNC_TABLE + 16))();
}

canonical_decompiled_code:
__int64 func3()
{
return (*(int (**)(void))(FUNC_TABLE + 16))();
}

original_code:
char *strcpy(char *s1,char *s2){
 return (char *)(FUNC_TABLE[2])(s1,s2);
}

canonical_original_code:
char *strcpy(char *s1, char *s2){
 return (char *)(FUNC_TABLE[2])(s1,s2);
}


strlen

original_code:
int strlen(const char *s){
 return (FUNC_TABLE[3])(s);
}

canonical_original_code:
int strlen(char *s){
 return (FUNC_TABLE[3])(s);
}


scanf

original_code:
int scanf(char * s, int a1, int a2, int a3, int a4, int a5){
 return (FUNC_TABLE[4])(s,a1,a2,a3,a4,a5);
}

canonical_original_code:
int scanf(char *s, int a1, int a2, int a3, int a4, int a5){
 return (FUNC_TABLE[4])(s,a1,a2,a3,a4,a5);
}


repo: lirongyuan/Music-Generator

decompiled_code:
void __fastcall assignLittleEndian4(_DWORD *a1, int a2)
{
*a1 = a2;
}

canonical_decompiled_code:
void __fastcall func7(_DWORD *a1, int a2)
{
*a1 = a2;
}

original_code:
void assignLittleEndian4(unsigned char * dest, unsigned int value) {
 dest[0] = value & 0xFF;
 dest[1] = (value >> 8) & 0xFF;
 dest[2] = (value >> 16) & 0xFF;
 dest[3] = (value >> 24) & 0xFF;
}

canonical_original_code:
void assignLittleEndian4(unsigned char *dest, unsigned int value) {
 dest[0] = value & 0xFF;
 dest[1] = (value >> 8) & 0xFF;
 dest[2] = (value >> 16) & 0xFF;
 dest[3] = (value >> 24) & 0xFF;
}

variable_types:
dest
unsigned char *

variable_types:
value
unsigned int


repo: lisa-project/lisa-user

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

result = 0LL;
if ( a2 )
result = *(_QWORD *)(a1 + 24) + a2;
return result;
}

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

result = 0LL;
if ( a2 )
result = *(_QWORD *)(a1 + 24) + a2;
return result;
}

original_code:
static __inline__ void *mm_addr(struct mm_private *mm, mm_ptr_t p)
{
 return 0 == p ? ((void *)0) : (void *)(mm->area + p);
}

canonical_original_code:
static __inline__ void *mm_addr(struct mm_private *mm, unsigned int p)
{
 return 0 == p ? ((void *)0) : (void *)(mm->area + p);
}

variable_types: struct mm_private { int fd; union sem_t { char __size[32]; long __align; } *sem; int lock; char *area; unsigned long mapped_size; int init; } *

variable_types:
p
unsigned int

return_type: void *

user_defined_types: struct mm_private { int fd; union sem_t *sem; int lock; char *area; unsigned long mapped_size; int init; }


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

result = 0LL;
if ( a2 )
result = (unsigned int)(a2 - *(_DWORD *)(a1 + 24));
return result;
}

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

result = 0LL;
if ( a2 )
result = (unsigned int)(a2 - *(_DWORD *)(a1 + 24));
return result;
}

original_code:
static __inline__ mm_ptr_t mm_ptr(struct mm_private *mm, void *a)
{
 return ((void *)0) == a ? 0 : (char *)a - mm->area;
}

canonical_original_code:
static __inline__ unsigned int mm_ptr(struct mm_private *mm, void *a)
{
 return ((void *)0) == a ? 0 : (char *)a - mm->area;
}

variable_types:
a
void *

return_type: unsigned int

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


decompiled_code:
__int64 __fastcall mm_list_add_tail(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int *v3; // rax
unsigned int v4; // er8
unsigned int v5; // ecx

v3 = (unsigned int *)mm_addr(a1, a3);
return _mm_list_add(a1, v4, *v3, v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int *v3; // rax
unsigned int v4; // er8
unsigned int v5; // ecx

v3 = (unsigned int *)func0(a1, a3);
return func2(a1, v4, *v3, v5);
}

original_code:
static __inline__ void mm_list_add_tail(struct mm_private *mm, mm_ptr_t new,
  mm_ptr_t head)
{
 __mm_list_add(mm, new, ((struct mm_list_head *)mm_addr((mm), (head)))->prev, head);
}

canonical_original_code:
static __inline__ void mm_list_add_tail(struct mm_private *mm, unsigned int new, unsigned int head)
{
 __mm_list_add(mm, new, ((struct mm_list_head *)mm_addr((mm), (head)))->prev, head);
}

variable_types:
new
unsigned int

variable_types:
head
unsigned int

user_defined_types: struct mm_list_head { unsigned int prev; }


decompiled_code:
__int64 __fastcall mm_list_del(__int64 a1, unsigned int a2)
{
unsigned int *v2; // rax
unsigned int v3; // er9
unsigned int v4; // esi
__int64 result; // rax

v2 = (unsigned int *)mm_addr(a1, a2);
_mm_list_del(a1, *v2, v2[1]);
v4 = v3;
*(_DWORD *)mm_addr(a1, v3) = 0;
result = mm_addr(a1, v4);
*(_DWORD *)(result + 4) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
unsigned int *v2; // rax
unsigned int v3; // er9
unsigned int v4; // esi
__int64 result; // rax

v2 = (unsigned int *)func0(a1, a2);
func4(a1, *v2, v2[1]);
v4 = v3;
*(_DWORD *)func0(a1, v3) = 0;
result = func0(a1, v4);
*(_DWORD *)(result + 4) = 0;
return result;
}

original_code:
static __inline__ void mm_list_del(struct mm_private *mm, mm_ptr_t entry)
{
 __mm_list_del(mm, ((struct mm_list_head *)mm_addr((mm), (entry)))->prev, ((struct mm_list_head *)mm_addr((mm), (entry)))->next);
 ((struct mm_list_head *)mm_addr((mm), (entry)))->next = ((struct mm_list_head *)mm_addr((mm), (entry)))->prev = 0;
}

canonical_original_code:
static __inline__ void mm_list_del(struct mm_private *mm, unsigned int entry)
{
 __mm_list_del(mm, ((struct mm_list_head *)mm_addr((mm), (entry)))->prev, ((struct mm_list_head *)mm_addr((mm), (entry)))->next);
 ((struct mm_list_head *)mm_addr((mm), (entry)))->next = ((struct mm_list_head *)mm_addr((mm), (entry)))->prev = 0;
}

variable_types:
entry
unsigned int


decompiled_code:
_BOOL8 __fastcall mm_list_empty(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(mm_addr(a1, a2) + 4) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, unsigned int a2)
{
return *(_DWORD *)(func0(a1, a2) + 4) == a2;
}

original_code:
static __inline__ int mm_list_empty(struct mm_private *mm, mm_ptr_t head)
{
 return ((struct mm_list_head *)mm_addr((mm), (head)))->next == head;
}

canonical_original_code:
static __inline__ int mm_list_empty(struct mm_private *mm, unsigned int head)
{
 return ((struct mm_list_head *)mm_addr((mm), (head)))->next == head;
}


decompiled_code:
unsigned __int64 __fastcall page_size(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = sysconf(30);
return v1 * ((v1 + a1 - 1) / v1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
unsigned __int64 v1; // rax

v1 = sysconf(30);
return v1 * ((v1 + a1 - 1) / v1);
}

original_code:
static __inline__ size_t page_size(size_t size)
{
 size_t p_size = sysconf(_SC_PAGESIZE);
 return p_size * ((size + p_size - 1) / p_size);
}

canonical_original_code:
static __inline__ unsigned long page_size(unsigned long size)
{
 unsigned long p_size = sysconf(_SC_PAGESIZE);
 return p_size * ((size + p_size - 1) / p_size);
}

variable_types:
size
unsigned long

return_type: unsigned long


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

if ( (*(_DWORD *)(a1 + 16))-- == 1 )
result = sem_post(*(sem_t **)(a1 + 8));
return result;
}

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

if ( (*(_DWORD *)(a1 + 16))-- == 1 )
result = sem_post(*(sem_t **)(a1 + 8));
return result;
}

original_code:
static __inline__ void mm_unlock(struct mm_private *mm)
{
 if (--mm->lock)
  return;
 sem_post(mm->sem);
}


original_code:
struct mm_private *mm_create(const char *name, size_t static_size, size_t dynamic_size)
{
 struct mm_private *ret;
 int unlock = 0, unlink = 0;
 ret = malloc(sizeof(struct mm_private));
 if (((void *)0) == ret)
  return ((void *)0);
 ret->fd = -1;
 ret->lock = 0;
 do {
  ret->sem = sem_open(name, 0100, 0600, 1);
  if (((sem_t *) 0) == ret->sem)
   break;
  __mm_lock(ret);
  unlock = 1;
  ret->fd = shm_open(name, 0100 | 0200 | 02, 0600);
  if (-1 == ret->fd && 17 != (*__errno_location ()))
   break;
  if (-1 == ret->fd) {
   ret->fd = shm_open(name, 02, 0600);
   ret->mapped_size = sizeof(struct mm_shared);
   if (-1 == ret->fd)
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->mapped_size = sizeof(struct mm_shared) +
    ((struct mm_shared *)ret->area)->static_size +
    ((struct mm_shared *)ret->area)->dynamic_size;
   munmap(ret->area, sizeof(struct mm_shared));
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->init = 0;
  } else {
   ret->mapped_size = page_size(static_size + dynamic_size + sizeof(struct mm_shared));
   unlink = 1;
   if (-1 == ftruncate(ret->fd, ret->mapped_size))
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ((struct mm_shared *)ret->area)->static_size = static_size;
   ((struct mm_shared *)ret->area)->dynamic_size = ret->mapped_size -
    (sizeof(struct mm_shared) + static_size);
   do { ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->next = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->prev = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); } while (0);
   ret->init = 1;
  }
  mm_unlock(ret);
  return ret;
 } while(0);
 if (-1 != ret->fd)
  close(ret->fd);
 if (unlink)
  shm_unlink(name);
 if (unlock)
  mm_unlock(ret);
 free(ret);
 return ((void *)0);
}

canonical_original_code:
struct mm_private *mm_create(char *name, unsigned long static_size, unsigned long dynamic_size)
{
 struct mm_private *ret;
 int unlock = 0; int unlink = 0;
 ret = malloc(sizeof(struct mm_private));
 if (((void *)0) == ret)
  return ((void *)0);
 ret->fd = -1;
 ret->lock = 0;
 do {
  ret->sem = sem_open(name, 0100, 0600, 1);
  if (((union sem_t *) 0) == ret->sem)
   break;
  __mm_lock(ret);
  unlock = 1;
  ret->fd = shm_open(name, 0100 | 0200 | 02, 0600);
  if (-1 == ret->fd && 17 != (*__errno_location ()))
   break;
  if (-1 == ret->fd) {
   ret->fd = shm_open(name, 02, 0600);
   ret->mapped_size = sizeof(struct mm_shared);
   if (-1 == ret->fd)
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->mapped_size = sizeof(struct mm_shared) +
    ((struct mm_shared *)ret->area)->static_size +
    ((struct mm_shared *)ret->area)->dynamic_size;
   munmap(ret->area, sizeof(struct mm_shared));
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ret->init = 0;
  } else {
   ret->mapped_size = page_size(static_size + dynamic_size + sizeof(struct mm_shared));
   unlink = 1;
   if (-1 == ftruncate(ret->fd, ret->mapped_size))
    break;
   ret->area = mm_map(ret);
   if (((void *)0) == ret->area)
    break;
   ((struct mm_shared *)ret->area)->static_size = static_size;
   ((struct mm_shared *)ret->area)->dynamic_size = ret->mapped_size -
    (sizeof(struct mm_shared) + static_size);
   do { ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->next = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); ((struct mm_list_head *)mm_addr((ret), (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh))))->prev = (mm_ptr(ret, &((struct mm_shared *)ret->area)->lh)); } while (0);
   ret->init = 1;
  }
  mm_unlock(ret);
  return ret;
 } while(0);
 if (-1 != ret->fd)
  close(ret->fd);
 if (unlink)
  shm_unlink(name);
 if (unlock)
  mm_unlock(ret);
 free(ret);
 return ((void *)0);
}

variable_types:
name
char *

variable_types: unlock int

variable_types: unlink int

return_type: struct mm_private { int fd; union sem_t { char __size[32]; long __align; } *sem; int lock; char *area; unsigned long mapped_size; int init; } *

user_defined_types: struct mm_shared { unsigned long static_size; unsigned long dynamic_size; struct mm_list_head lh; }


original_code:
void mm_lock(struct mm_private *mm)
{
 size_t mm_size;
 if (mm->lock++)
  return;
 sem_wait(mm->sem);
 mm_size = sizeof(struct mm_shared) +
  ((struct mm_shared *)mm->area)->static_size +
  ((struct mm_shared *)mm->area)->dynamic_size;
 if (mm_size <= mm->mapped_size)
  return;
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
}

canonical_original_code:
void mm_lock(struct mm_private *mm)
{
 unsigned long mm_size;
 if (mm->lock++)
  return;
 sem_wait(mm->sem);
 mm_size = sizeof(struct mm_shared) +
  ((struct mm_shared *)mm->area)->static_size +
  ((struct mm_shared *)mm->area)->dynamic_size;
 if (mm_size <= mm->mapped_size)
  return;
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
}


original_code:
int mm_extend(struct mm_private *mm, size_t size)
{
 size_t mm_size;
 struct mm_shared shr = *(struct mm_shared *)mm->area;
 if (!size)
  return 0;
 mm_lock(mm);
 mm_size = mm->mapped_size + size;
 if (-1 == ftruncate(mm->fd, mm_size)) {
  mm_unlock(mm);
  return 1;
 }
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
 ((struct mm_shared *)mm->area)->static_size = shr.static_size;
 ((struct mm_shared *)mm->area)->dynamic_size = mm->mapped_size -
  (sizeof(struct mm_shared) + shr.static_size);
 ((struct mm_shared *)mm->area)->lh = shr.lh;
 mm_unlock(mm);
 return 0;
}

canonical_original_code:
int mm_extend(struct mm_private *mm, unsigned long size)
{
 unsigned long mm_size;
 struct mm_shared shr = *(struct mm_shared *)mm->area;
 if (!size)
  return 0;
 mm_lock(mm);
 mm_size = mm->mapped_size + size;
 if (-1 == ftruncate(mm->fd, mm_size)) {
  mm_unlock(mm);
  return 1;
 }
 munmap(mm->area, mm->mapped_size);
 mm->mapped_size = mm_size;
 mm->area = mm_map(mm);
 ((struct mm_shared *)mm->area)->static_size = shr.static_size;
 ((struct mm_shared *)mm->area)->dynamic_size = mm->mapped_size -
  (sizeof(struct mm_shared) + shr.static_size);
 ((struct mm_shared *)mm->area)->lh = shr.lh;
 mm_unlock(mm);
 return 0;
}

variable_types: struct mm_shared { unsigned long static_size; unsigned long dynamic_size; struct mm_list_head { unsigned int prev; } lh; }


original_code:
static int if_build_ip_list(const struct sockaddr_nl *who, const struct nlmsghdr *n,
  void *__arg)
{
 struct ifaddrmsg *ifa = ((void*)(((char*)n) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
 struct rtattr *rta_tb[(__IFA_MAX - 1)+1];
 struct build_ip_list_priv *arg = __arg;
 if (n->nlmsg_type != RTM_NEWADDR)
  return 0;
 if (n->nlmsg_len < ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))
  return 0;
 if (arg->ifindex && arg->ifindex != ifa->ifa_index)
  return 0;
 parse_rtattr(rta_tb, (__IFA_MAX - 1), ((struct rtattr*)(((char*)(ifa)) + ( ((sizeof(struct ifaddrmsg))+4U -1) & ~(4U -1) ))), n->nlmsg_len - ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))));
 if (rta_tb[IFA_LOCAL]) {
  struct if_addr *addr;
  addr = malloc(sizeof(*addr));
  if (addr == ((void *)0))
   return 0;
  addr->ifindex = ifa->ifa_index;
  addr->af = ifa->ifa_family;
  addr->inet = *(struct in_addr *)((void*)(((char*)(rta_tb[IFA_LOCAL])) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
  addr->prefixlen = ifa->ifa_prefixlen;
  list_add_tail(&addr->lh, arg->lh);
 }
 return 0;
}

canonical_original_code:
static int if_build_ip_list(struct sockaddr_nl *who, struct nlmsghdr *n, void *__arg)
{
 struct ifaddrmsg *ifa = ((void*)(((char*)n) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
 struct rtattr *rta_tb[-1];
 struct build_ip_list_priv *arg = __arg;
 if (n->nlmsg_type != RTM_NEWADDR)
  return 0;
 if (n->nlmsg_len < ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))
  return 0;
 if (arg->ifindex && arg->ifindex != ifa->ifa_index)
  return 0;
 parse_rtattr(rta_tb, (__IFA_MAX - 1), ((struct rtattr *)(((char *)(ifa)) + ( ((sizeof(struct ifaddrmsg))+4U -1) & ~(4U -1) ))), n->nlmsg_len - ((sizeof(*ifa)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))));
 if (rta_tb[IFA_LOCAL]) {
  struct if_addr *addr;
  addr = malloc(sizeof(*addr));
  if (addr == ((void *)0))
   return 0;
  addr->ifindex = ifa->ifa_index;
  addr->af = ifa->ifa_family;
  addr->inet = *(struct in_addr *)((void *)(((char *)(rta_tb[IFA_LOCAL])) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
  addr->prefixlen = ifa->ifa_prefixlen;
  list_add_tail(&addr->lh, arg->lh);
 }
 return 0;
}

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } *

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types: struct ifaddrmsg { unsigned char ifa_family; unsigned char ifa_prefixlen; unsigned char ifa_flags; unsigned char ifa_scope; unsigned int ifa_index; } *

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *[-1]

variable_types: struct build_ip_list_priv { struct list_head { struct list_head *next; } *lh; int ifindex; } *

variable_types: struct if_addr { struct list_head { struct list_head *next; } lh; int ifindex; int af; struct in_addr { unsigned int s_addr; } inet; int prefixlen; } *

user_defined_types: struct build_ip_list_priv { struct list_head *lh; int ifindex; }

user_defined_types: struct if_addr { struct list_head lh; int ifindex; int af; struct in_addr inet; int prefixlen; }


decompiled_code:
__int64 __fastcall if_parse_generic(char *s, void *src)
{
size_t v2; // rbx
void *v3; // rsp
const char *v4; // rax
size_t v5; // rax
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+8h] [rbp-28h] BYREF
int v9; // [rsp+Ch] [rbp-24h] BYREF

v2 = strlen((const char *)src);
v3 = alloca(v2 + 13);
v4 = (const char *)memcpy(&v7, src, v2);
strcpy((char *)&v4[v2], "%d%n");
if ( sscanf(s, v4, &v8, &v9) && (v5 = strlen(s), v5 == v9) )
result = v8;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, void *src)
{
size_t v2; // rbx
void *v3; // rsp
const char *v4; // rax
size_t v5; // rax
__int64 result; // rax
__int64 v7; // [rsp+0h] [rbp-30h] BYREF
unsigned int v8; // [rsp+8h] [rbp-28h] BYREF
int v9; // [rsp+Ch] [rbp-24h] BYREF

v2 = strlen((const char *)src);
v3 = alloca(v2 + 13);
v4 = (const char *)memcpy(&v7, src, v2);
strcpy((char *)&v4[v2], "%d%n");
if ( sscanf(s, v4, &v8, &v9) && (v5 = strlen(s), v5 == v9) )
result = v8;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int if_parse_generic(const char *name, const char *type)
{
 int ret, n;
 char *fmt;
 size_t len;
 fmt = __builtin_alloca ((len = strlen(type)) + 5);
 strcpy(fmt, type);
 strcpy(fmt + len, "%d%n");
 if (!sscanf(name, fmt, &ret, &n))
  return -1;
 if (strlen(name) != n)
  return -1;
 return ret;
}

canonical_original_code:
int if_parse_generic(char *name, char *type)
{
 int ret; int n;
 char *fmt;
 unsigned long len;
 fmt = __builtin_alloca ((len = strlen(type)) + 5);
 strcpy(fmt, type);
 strcpy(fmt + len, "%d%n");
 if (!sscanf(name, fmt, &ret, &n))
  return -1;
 if (strlen(name) != n)
  return -1;
 return ret;
}

variable_types:
type
char *

variable_types: ret int

variable_types: n int

variable_types:
fmt
char *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall if_get_index(const char *a1, int a2)
{
size_t v2; // rax
__int64 result; // rax
unsigned int v4; // eax
__int64 v5; // rdx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // edx
__int64 v9; // rcx
_DWORD v10[18]; // [rsp+0h] [rbp-48h] BYREF

v2 = strlen(a1);
if ( v2 > 0xF )
goto LABEL_2;
v4 = v2 + 1;
if ( v4 >= 8 )
{
v5 = v4;
v6 = v4 - 1;
*(_QWORD *)((char *)&v10[-2] + v5) = *(_QWORD *)&a1[v5 - 8];
if ( v6 >= 8 )
{
v7 = v6 & 0xFFFFFFF8;
v8 = 0;
do
{
v9 = v8;
v8 += 8;
*(_QWORD *)((char *)v10 + v9) = *(_QWORD *)&a1[v9];
}
while ( v8 < v7 );
}
}
else if ( (v4 & 4) != 0 )
{
v10[0] = *(_DWORD *)a1;
*(_DWORD *)((char *)&v10[-1] + v4) = *(_DWORD *)&a1[v4 - 4];
}
else if ( v4 )
{
LOBYTE(v10[0]) = *a1;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v10 + v4 - 2) = *(_WORD *)&a1[v4 - 2];
}
if ( a2 == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x25u, "if_get_index");
if ( ioctl(a2, 0x8933uLL, v10) )
LABEL_2:
result = 0LL;
else
result = v10[4];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, int a2)
{
size_t v2; // rax
__int64 result; // rax
unsigned int v4; // eax
__int64 v5; // rdx
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // edx
__int64 v9; // rcx
_DWORD v10[18]; // [rsp+0h] [rbp-48h] BYREF

v2 = strlen(a1);
if ( v2 > 0xF )
goto LABEL_2;
v4 = v2 + 1;
if ( v4 >= 8 )
{
v5 = v4;
v6 = v4 - 1;
*(_QWORD *)((char *)&v10[-2] + v5) = *(_QWORD *)&a1[v5 - 8];
if ( v6 >= 8 )
{
v7 = v6 & 0xFFFFFFF8;
v8 = 0;
do
{
v9 = v8;
v8 += 8;
*(_QWORD *)((char *)v10 + v9) = *(_QWORD *)&a1[v9];
}
while ( v8 < v7 );
}
}
else if ( (v4 & 4) != 0 )
{
v10[0] = *(_DWORD *)a1;
*(_DWORD *)((char *)&v10[-1] + v4) = *(_DWORD *)&a1[v4 - 4];
}
else if ( v4 )
{
LOBYTE(v10[0]) = *a1;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v10 + v4 - 2) = *(_WORD *)&a1[v4 - 2];
}
if ( a2 == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x25u, "if_get_index");
if ( ioctl(a2, 0x8933uLL, v10) )
LABEL_2:
result = 0LL;
else
result = v10[4];
return result;
}

original_code:
int if_get_index(const char *name, int sock_fd)
{
 struct ifreq ifr;
 int ret = 0;
 if (strlen(name) >= 16)
  return 0;
 strcpy(ifr.ifr_ifrn.ifrn_name, name);
 ((void) sizeof ((sock_fd != -1) ? 1 : 0), __extension__ ({ if (sock_fd != -1) ; else __assert_fail ("sock_fd != -1", "if_generic.c", 37, __extension__ __PRETTY_FUNCTION__); }));
 if (!ioctl(sock_fd, 0x8933, &ifr))
  ret = ifr.ifr_ifru.ifru_ivalue;
 return ret;
}

canonical_original_code:
int if_get_index(char *name, int sock_fd)
{
 struct ifreq ifr;
 int ret = 0;
 if (strlen(name) >= 16)
  return 0;
 strcpy(ifr.ifr_ifrn.ifrn_name, name);
 ((void) sizeof ((sock_fd != -1) ? 1 : 0), __extension__ ({ if (sock_fd != -1) ; else __assert_fail ("sock_fd != -1", "if_generic.c", 37, __extension__ __PRETTY_FUNCTION__); }));
 if (!ioctl(sock_fd, 0x8933, &ifr))
  ret = ifr.ifr_ifru.ifru_ivalue;
 return ret;
}

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
char *__fastcall canonical_if_name(__int64 a1)
{
int v1; // eax
int v2; // eax
int v4; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v4 = if_parse_generic((char *)a1, "eth");
if ( v4 < 0 )
v2 = asprintf(ptr, "netdev %s", (const char *)a1);
else
v2 = asprintf(ptr, "Ethernet %d", (unsigned int)v4);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
if ( v2 != -1 )
return ptr[0];
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
int v1; // eax
int v2; // eax
int v4; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v4 = func3((char *)a1, "eth");
if ( v4 < 0 )
v2 = asprintf(ptr, "netdev %s", (const char *)a1);
else
v2 = asprintf(ptr, "Ethernet %d", (unsigned int)v4);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
if ( v2 != -1 )
return ptr[0];
return 0LL;
}

original_code:
char *canonical_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n, status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Ethernet %d", n);
  else
   status = asprintf(&ret, "netdev %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

canonical_original_code:
char *canonical_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n; int status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Ethernet %d", n);
  else
   status = asprintf(&ret, "netdev %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

variable_types: struct net_switch_device { char name[16]; int ifindex; int type; int vlan; struct list_head { struct list_head *next; } lh; } *

variable_types:
ret
char *

variable_types: status int

user_defined_types: struct net_switch_device { char name[16]; int ifindex; int type; int vlan; struct list_head lh; }


decompiled_code:
char *__fastcall short_if_name(__int64 a1)
{
int v1; // eax
int v2; // eax
int v4; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v4 = if_parse_generic((char *)a1, "eth");
if ( v4 < 0 )
v2 = asprintf(ptr, "net %s", (const char *)a1);
else
v2 = asprintf(ptr, "Et%d", (unsigned int)v4);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
if ( v2 != -1 )
return ptr[0];
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
int v1; // eax
int v2; // eax
int v4; // eax
char *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

ptr[0] = 0LL;
if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 20);
if ( v1 <= 2 )
{
if ( v1 <= 0 )
return 0LL;
v4 = func3((char *)a1, "eth");
if ( v4 < 0 )
v2 = asprintf(ptr, "net %s", (const char *)a1);
else
v2 = asprintf(ptr, "Et%d", (unsigned int)v4);
}
else
{
if ( v1 != 4 )
return 0LL;
v2 = asprintf(ptr, "vlan %d", *(unsigned int *)(a1 + 24));
}
if ( v2 != -1 )
return ptr[0];
return 0LL;
}

original_code:
char *short_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n, status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Et%d", n);
  else
   status = asprintf(&ret, "net %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

canonical_original_code:
char *short_if_name(struct net_switch_device *nsdev)
{
 char *ret = ((void *)0);
 int n; int status = -1;
 if (nsdev == ((void *)0))
  return ((void *)0);
 switch (nsdev->type) {
 case 0x01:
 case 0x02:
  if ((n = if_parse_generic(nsdev->name, "eth")) >= 0)
   status = asprintf(&ret, "Et%d", n);
  else
   status = asprintf(&ret, "net %s", nsdev->name);
  break;
 case 0x04:
  status = asprintf(&ret, "vlan %d", nsdev->vlan);
  break;
 }
 return status == -1 ? ((void *)0) : ret;
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
char *__fastcall if_get_name(int a1, int a2, char *a3)
{
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
int v6; // [rsp+10h] [rbp-38h]

if ( a2 == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x63u, "if_get_name");
v6 = a1;
if ( ioctl(a2, 0x8910uLL, v5) )
return 0LL;
if ( a3 )
return strncpy(a3, v5, 0x10uLL);
return strdup(v5);
}

canonical_decompiled_code:
char *__fastcall func7(int a1, int a2, char *a3)
{
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
int v6; // [rsp+10h] [rbp-38h]

if ( a2 == -1 )
_assert_fail("sock_fd != -1", "if_generic.c", 0x63u, "if_get_name");
v6 = a1;
if ( ioctl(a2, 0x8910uLL, v5) )
return 0LL;
if ( a3 )
return strncpy(a3, v5, 0x10uLL);
return strdup(v5);
}

original_code:
char *if_get_name(int if_index, int sock_fd, char *name)
{
 struct ifreq ifr;
 ((void) sizeof ((sock_fd != -1) ? 1 : 0), __extension__ ({ if (sock_fd != -1) ; else __assert_fail ("sock_fd != -1", "if_generic.c", 99, __extension__ __PRETTY_FUNCTION__); }));
 ifr.ifr_ifru.ifru_ivalue = if_index;
 if (ioctl(sock_fd, 0x8910, &ifr))
  return ((void *)0);
 if (!name)
  return strdup(ifr.ifr_ifrn.ifrn_name);
 strncpy(name, ifr.ifr_ifrn.ifrn_name, 16);
 return name;
}

variable_types:
name
char *

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }

user_defined_types: struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; }

user_defined_types: struct cisco_proto { unsigned int interval; unsigned int timeout; }

user_defined_types: struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; }

user_defined_types: struct fr_proto_pvc { unsigned int dlci; }

user_defined_types: struct fr_proto_pvc_info { unsigned int dlci; char master[16]; }

user_defined_types: struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; }

user_defined_types: struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; }


decompiled_code:
__int64 __fastcall if_get_addr(int a1, __int64 a2, __int64 a3, char *a4)
{
char *v4; // rbp
__int64 result; // rax
__int64 v6; // [rsp+10h] [rbp-48h] BYREF
int v7; // [rsp+18h] [rbp-40h]
char v8[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = a4;
v6 = a3;
v7 = a1;
if ( !a4 )
{
v4 = v8;
if ( (unsigned int)rtnl_open(v8) )
return 0xFFFFFFFFLL;
a2 = (unsigned int)a2;
}
if ( (int)rtnl_wilddump_request(v4, a2, 22LL) < 0 )
{
perror("Cannot send dump request");
result = 0xFFFFFFFFLL;
}
else if ( (int)rtnl_dump_filter(v4, if_build_ip_list, &v6) < 0 )
{
fwrite("Dump terminated\n", 1uLL, 0x10uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( v4 == v8 )
{
rtnl_close(v4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2, __int64 a3, char *a4)
{
char *v4; // rbp
__int64 result; // rax
__int64 v6; // [rsp+10h] [rbp-48h] BYREF
int v7; // [rsp+18h] [rbp-40h]
char v8[56]; // [rsp+20h] [rbp-38h] BYREF

v4 = a4;
v6 = a3;
v7 = a1;
if ( !a4 )
{
v4 = v8;
if ( (unsigned int)rtnl_open(v8) )
return 0xFFFFFFFFLL;
a2 = (unsigned int)a2;
}
if ( (int)rtnl_wilddump_request(v4, a2, 22LL) < 0 )
{
perror("Cannot send dump request");
result = 0xFFFFFFFFLL;
}
else if ( (int)rtnl_dump_filter(v4, if_build_ip_list, &v6) < 0 )
{
fwrite("Dump terminated\n", 1uLL, 0x10uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
if ( v4 == v8 )
{
rtnl_close(v4);
result = 0LL;
}
}
return result;
}

original_code:
int if_get_addr(int ifindex, int af, struct list_head *lh, struct rtnl_handle *rth)
{
 struct rtnl_handle __rth;
 struct build_ip_list_priv priv = {
  .ifindex = ifindex,
  .lh = lh
 };
 if (rth == ((void *)0) && rtnl_open(rth = &__rth))
  return -1;
 if (rtnl_wilddump_request(rth, af, RTM_GETADDR) < 0) {
  perror("Cannot send dump request");
  return -1;
 }
 if (rtnl_dump_filter(rth, if_build_ip_list, &priv) < 0) {
  fprintf(stderr, "Dump terminated\n");
  return -1;
 }
 if (rth == &__rth)
  rtnl_close(rth);
 return 0;
}

variable_types: ifindex int

variable_types: af int

variable_types: struct rtnl_handle { int fd; struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; } local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; } *

variable_types: struct build_ip_list_priv { struct list_head { struct list_head *next; } *lh; int ifindex; }

user_defined_types: struct rtnl_handle { int fd; struct sockaddr_nl local; struct sockaddr_nl peer; unsigned int seq; unsigned int dump; }


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_QWORD *v1; // rax

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
v1[1] = 0LL;
*v1 = 0LL;
}

original_code:
static __inline__ void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = entry->prev = 0;
}

variable_types: struct list_head { struct list_head *next; } *


decompiled_code:
int telnet_listen()
{
unsigned int v0; // eax
__int64 v1; // rdi
__int16 v2; // ax
socklen_t v3; // edx
int result; // eax
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
telnet_sockfd = v0;
if ( v0 == -1 )
__assert_fail("telnet_sockfd != -1", "swclid.c", 0x37u, "telnet_listen");
v1 = v0;
if ( setsockopt(v0, 1, 2, &yes, 4u) == -1 )
__assert_fail("status != -1", "swclid.c", 0x3Bu, "telnet_listen");
v5.sa_family = 2;
v2 = _bswap_16_constprop_0(v1, &v5, 16LL);
*(_DWORD *)&v5.sa_data[2] = 0;
*(_WORD *)v5.sa_data = v2;
if ( bind(telnet_sockfd, &v5, v3) == -1 )
__assert_fail("status != -1", "swclid.c", 0x42u, "telnet_listen");
result = listen(telnet_sockfd, 10);
if ( result == -1 )
__assert_fail("status != -1", "swclid.c", 0x45u, "telnet_listen");
return result;
}

canonical_decompiled_code:
int func13()
{
unsigned int v0; // eax
__int64 v1; // rdi
__int16 v2; // ax
socklen_t v3; // edx
int result; // eax
struct sockaddr v5; // [rsp+0h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
telnet_sockfd = v0;
if ( v0 == -1 )
__assert_fail("telnet_sockfd != -1", "swclid.c", 0x37u, "telnet_listen");
v1 = v0;
if ( setsockopt(v0, 1, 2, &yes, 4u) == -1 )
__assert_fail("status != -1", "swclid.c", 0x3Bu, "telnet_listen");
v5.sa_family = 2;
v2 = func11(v1, &v5, 16LL);
*(_DWORD *)&v5.sa_data[2] = 0;
*(_WORD *)v5.sa_data = v2;
if ( bind(telnet_sockfd, &v5, v3) == -1 )
__assert_fail("status != -1", "swclid.c", 0x42u, "telnet_listen");
result = listen(telnet_sockfd, 10);
if ( result == -1 )
__assert_fail("status != -1", "swclid.c", 0x45u, "telnet_listen");
return result;
}

original_code:
void telnet_listen(void) {
 int status;
 struct sockaddr_in bind_addr;
 telnet_sockfd = socket(2, SOCK_STREAM, 0);
 ((void) sizeof ((telnet_sockfd != -1) ? 1 : 0), __extension__ ({ if (telnet_sockfd != -1) ; else __assert_fail ("telnet_sockfd != -1", "swclid.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 status = setsockopt(telnet_sockfd, 1, 2, &yes,
   sizeof(int));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 bind_addr.sin_family = 2;
 bind_addr.sin_port = htons(23);
 bind_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 status = bind(telnet_sockfd, (struct sockaddr *)&bind_addr,
   sizeof(struct sockaddr));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 66, __extension__ __PRETTY_FUNCTION__); }));
 status = listen(telnet_sockfd, 10);
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 69, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void telnet_listen() {
 int status;
 struct sockaddr_in bind_addr;
 telnet_sockfd = socket(2, SOCK_STREAM, 0);
 ((void) sizeof ((telnet_sockfd != -1) ? 1 : 0), __extension__ ({ if (telnet_sockfd != -1) ; else __assert_fail ("telnet_sockfd != -1", "swclid.c", 55, __extension__ __PRETTY_FUNCTION__); }));
 status = setsockopt(telnet_sockfd, 1, 2, &yes,
   sizeof(int));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 59, __extension__ __PRETTY_FUNCTION__); }));
 bind_addr.sin_family = 2;
 bind_addr.sin_port = htons(23);
 bind_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
 status = bind(telnet_sockfd, (struct sockaddr *)&bind_addr,
   sizeof(struct sockaddr));
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 66, __extension__ __PRETTY_FUNCTION__); }));
 status = listen(telnet_sockfd, 10);
 ((void) sizeof ((status != -1) ? 1 : 0), __extension__ ({ if (status != -1) ; else __assert_fail ("status != -1", "swclid.c", 69, __extension__ __PRETTY_FUNCTION__); }));
}

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

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


decompiled_code:
void __fastcall destroy_telnet_conn(__int64 a1)
{
void *v1; // r8

list_del(a1 + 24);
free(v1);
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1)
{
void *v1; // r8

func8(a1 + 24);
free(v1);
}

original_code:
void destroy_telnet_conn(struct telnet_conn *c) {
 list_del(&c->lh);
 free(c);
}

variable_types: struct telnet_conn { int pid; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } remote_addr; struct list_head { struct list_head *next; } lh; } *

user_defined_types: struct telnet_conn { int pid; struct sockaddr_in remote_addr; struct list_head lh; }