decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
char *v4; // rbx
int v5; // eax
unsigned int v6; // er12
unsigned int v7; // [rsp+4h] [rbp-2044h]
char buf[4]; // [rsp+10h] [rbp-2038h] BYREF
char v9[8244]; // [rsp+14h] [rbp-2034h] BYREF

if ( argc != 1 )
{
fprintf(stderr, "usage: %s <in-file >out-file\n", *argv);
exit(1);
}
fwrite("#\n", 1uLL, 2uLL, _bss_start);
fwrite("# Miscellaneous data structures:\n", 1uLL, 0x21uLL, _bss_start);
fwrite("# WARNING - this file is automatically generated!\n", 1uLL, 0x32uLL, _bss_start);
fwrite("#\n", 1uLL, 2uLL, _bss_start);
fputc(10, _bss_start);
fwrite("\t.data\n", 1uLL, 7uLL, _bss_start);
fwrite("\t.globl input_data\n", 1uLL, 0x13uLL, _bss_start);
fwrite("input_data:\n", 1uLL, 0xCuLL, _bss_start);
v7 = 0;
LABEL_13:
v5 = read(0, buf, 0x2000uLL);
if ( v5 <= 0 )
{
fwrite("\t.globl input_len\n", 1uLL, 0x12uLL, _bss_start);
fprintf(_bss_start, "input_len:\t.long\t0x%x\n", v7);
fflush(_bss_start);
fclose(_bss_start);
exit(0);
}
v6 = (v5 + 3) & 0xFFFFFFFC;
v4 = v9;
v3 = 0;
while ( 1 )
{
if ( v3 )
{
fprintf(
_bss_start,
"0x%02X%02X%02X%02X",
(unsigned __int8)*(v4 - 4),
(unsigned __int8)*(v4 - 3),
(unsigned __int8)*(v4 - 2),
(unsigned __int8)*(v4 - 1));
if ( ++v3 == 4 )
{
fprintf(_bss_start, " # %x \n", v7 + -12 - (unsigned int)v9 + (unsigned int)v4);
fflush(_bss_start);
v3 = 0;
goto LABEL_6;
}
}
else
{
fwrite("\t.long\t", 1uLL, 7uLL, _bss_start);
fprintf(
_bss_start,
"0x%02X%02X%02X%02X",
(unsigned __int8)*(v4 - 4),
(unsigned __int8)*(v4 - 3),
(unsigned __int8)*(v4 - 2),
(unsigned __int8)*(v4 - 1));
v3 = 1;
}
fputc(44, _bss_start);
LABEL_6:
v4 += 4;
if ( v4 == &v9[4 * ((v6 - 1) >> 2) + 4] )
{
if ( v3 )
fwrite("0\n", 1uLL, 2uLL, _bss_start);
v7 += v6;
goto LABEL_13;
}
}
}

original_code:
int
main (int argc, const char * const * argv)
{
    int offset = 0, clear_screen = 0, end_common_opts = 0, retval;
    const char *title = ((void *)0);
    (void) setlocale (6, "");
    if (argc < 2) {
 Usage (argv[0]);
 exit (-1);
    }
    while (offset < argc - 1 && !end_common_opts) {
 if (!strcmp (argv[offset + 1], "--title")) {
     if (argc - offset < 3 || title != ((void *)0)) {
  Usage (argv[0]);
  exit (-1);
     } else {
  title = argv[offset + 2];
  offset += 2;
     }
        } else if (!strcmp (argv[offset + 1], "--backtitle")) {
            if (backtitle != ((void *)0)) {
                Usage (argv[0]);
                exit (-1);
            } else {
                backtitle = argv[offset + 2];
                offset += 2;
            }
 } else if (!strcmp (argv[offset + 1], "--clear")) {
     if (clear_screen) {
  Usage (argv[0]);
  exit (-1);
     } else if (argc == 2) {
  init_dialog ();
  wrefresh(stdscr);
  end_dialog ();
  return 0;
     } else {
  clear_screen = 1;
  offset++;
     }
 } else
     end_common_opts = 1;
    }
    if (argc - 1 == offset) {
 Usage (argv[0]);
 exit (-1);
    }
    for (modePtr = modes; modePtr->name; modePtr++)
 if (!strcmp (argv[offset + 1], modePtr->name))
     break;
    if (!modePtr->name)
 Usage (argv[0]);
    if (argc - offset < modePtr->argmin)
 Usage (argv[0]);
    if (modePtr->argmax && argc - offset > modePtr->argmax)
 Usage (argv[0]);
    if (title && strlen(title) > atoi(argv[offset+4])-4)
 title[atoi(argv[offset+4])-4] = 0;
    init_dialog ();
    retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
    if (clear_screen) {
 attr_clear (stdscr, LINES, COLS, attributes[0]);
 wrefresh(stdscr);
    }
    end_dialog();
    exit (retval);
}

canonical_original_code:
int main(int argc, char **argv)
{
    int offset = 0; int clear_screen = 0; int end_common_opts = 0; int retval;
    char *title = ((void *)0);
    (void) setlocale (6, "");
    if (argc < 2) {
 Usage (argv[0]);
 exit (-1);
    }
    while (offset < argc - 1 && !end_common_opts) {
 if (!strcmp (argv[offset + 1], "--title")) {
     if (argc - offset < 3 || title != ((void *)0)) {
  Usage (argv[0]);
  exit (-1);
     } else {
  title = argv[offset + 2];
  offset += 2;
     }
        } else if (!strcmp (argv[offset + 1], "--backtitle")) {
            if (backtitle != ((void *)0)) {
                Usage (argv[0]);
                exit (-1);
            } else {
                backtitle = argv[offset + 2];
                offset += 2;
            }
 } else if (!strcmp (argv[offset + 1], "--clear")) {
     if (clear_screen) {
  Usage (argv[0]);
  exit (-1);
     } else if (argc == 2) {
  init_dialog ();
  wrefresh(stdscr);
  end_dialog ();
  return 0;
     } else {
  clear_screen = 1;
  offset++;
     }
 } else
     end_common_opts = 1;
    }
    if (argc - 1 == offset) {
 Usage (argv[0]);
 exit (-1);
    }
    for (modePtr = modes; modePtr->name; modePtr++)
 if (!strcmp (argv[offset + 1], modePtr->name))
     break;
    if (!modePtr->name)
 Usage (argv[0]);
    if (argc - offset < modePtr->argmin)
 Usage (argv[0]);
    if (modePtr->argmax && argc - offset > modePtr->argmax)
 Usage (argv[0]);
    if (title && strlen(title) > atoi(argv[offset+4])-4)
 title[atoi(argv[offset+4])-4] = 0;
    init_dialog ();
    retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
    if (clear_screen) {
 attr_clear (stdscr, LINES, COLS, attributes[0]);
 wrefresh(stdscr);
    }
    end_dialog();
    exit (retval);
}

variable_types:
argv
char **

variable_types: offset int

variable_types: retval int

variable_types:
title
char *


decompiled_code:
char *get_line()
{
__int64 v0; // rbx
char v1; // al
int v2; // ebp
int v3; // er13
int v4; // eax
int v5; // eax
void *v6; // rdx

end_reached = 0;
v0 = page;
v1 = *(_BYTE *)page;
if ( *(_BYTE *)page != 10 )
{
v2 = 0;
while ( 1 )
{
if ( v1 )
{
if ( v2 > 2047 )
{
if ( v2 == 2048 )
{
byte_1A00 = 0;
v2 = 2049;
}
page = v0 + 1;
}
else
{
page = v0 + 1;
line_0[v2++] = v1;
}
}
else
{
v3 = fd;
v4 = lseek(fd, 0LL, 1);
if ( v4 == -1 )
{
endwin();
fwrite("\nError moving file pointer in get_line().\n", 1uLL, 0x2AuLL, stderr);
exit(-1);
}
if ( file_size <= v4 )
{
if ( !end_reached )
end_reached = 1;
if ( v2 > 2048 )
return line_0;
goto LABEL_21;
}
v5 = read(v3, buf, 0x2800uLL);
bytes_read = v5;
if ( v5 == -1 )
{
endwin();
fwrite("\nError reading file in get_line().\n", 1uLL, 0x23uLL, stderr);
exit(-1);
}
v6 = buf;
*((_BYTE *)buf + v5) = 0;
page = (__int64)v6;
}
v0 = page;
v1 = *(_BYTE *)page;
if ( *(_BYTE *)page == 10 )
{
if ( v2 > 2048 )
goto LABEL_22;
goto LABEL_21;
}
}
}
v2 = 0;
LABEL_21:
line_0[v2] = 0;
LABEL_22:
if ( !end_reached )
page = v0 + 1;
return line_0;
}

canonical_decompiled_code:
char *func0()
{
__int64 v0; // rbx
char v1; // al
int v2; // ebp
int v3; // er13
int v4; // eax
int v5; // eax
void *v6; // rdx

end_reached = 0;
v0 = page;
v1 = *(_BYTE *)page;
if ( *(_BYTE *)page != 10 )
{
v2 = 0;
while ( 1 )
{
if ( v1 )
{
if ( v2 > 2047 )
{
if ( v2 == 2048 )
{
byte_1A00 = 0;
v2 = 2049;
}
page = v0 + 1;
}
else
{
page = v0 + 1;
line_0[v2++] = v1;
}
}
else
{
v3 = fd;
v4 = lseek(fd, 0LL, 1);
if ( v4 == -1 )
{
endwin();
fwrite("\nError moving file pointer in get_line().\n", 1uLL, 0x2AuLL, stderr);
exit(-1);
}
if ( file_size <= v4 )
{
if ( !end_reached )
end_reached = 1;
if ( v2 > 2048 )
return line_0;
goto LABEL_21;
}
v5 = read(v3, buf, 0x2800uLL);
bytes_read = v5;
if ( v5 == -1 )
{
endwin();
fwrite("\nError reading file in get_line().\n", 1uLL, 0x23uLL, stderr);
exit(-1);
}
v6 = buf;
*((_BYTE *)buf + v5) = 0;
page = (__int64)v6;
}
v0 = page;
v1 = *(_BYTE *)page;
if ( *(_BYTE *)page == 10 )
{
if ( v2 > 2048 )
goto LABEL_22;
goto LABEL_21;
}
}
}
v2 = 0;
LABEL_21:
line_0[v2] = 0;
LABEL_22:
if ( !end_reached )
page = v0 + 1;
return line_0;
}

original_code:
static char *
get_line (void)
{
    int i = 0, fpos;
    static char line[2048 + 1];
    end_reached = 0;
    while (*page != '\n') {
 if (*page == '\0') {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "get_line().\n");
  exit (-1);
     }
     if (fpos < file_size) {
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in get_line().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
  page = buf;
     } else {
  if (!end_reached)
      end_reached = 1;
  break;
     }
 } else if (i < 2048)
     line[i++] = *(page++);
 else {
     if (i == 2048)
  line[i++] = '\0';
     page++;
 }
    }
    if (i <= 2048)
 line[i] = '\0';
    if (!end_reached)
 page++;
    return line;
}

canonical_original_code:
static char *get_line()
{
    int i = 0; int fpos;
    static char line[-1];
    end_reached = 0;
    while (*page != '\n') {
 if (*page == '\0') {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "get_line().\n");
  exit (-1);
     }
     if (fpos < file_size) {
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in get_line().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
  page = buf;
     } else {
  if (!end_reached)
      end_reached = 1;
  break;
     }
 } else if (i < 2048)
     line[i++] = *(page++);
 else {
     if (i == 2048)
  line[i++] = '\0';
     page++;
 }
    }
    if (i <= 2048)
 line[i] = '\0';
    if (!end_reached)
 page++;
    return line;
}

variable_types: i int

variable_types: fpos int

variable_types:
line
char [-1]

return_type: char *


decompiled_code:
void __fastcall back_lines(int a1)
{
void *v1; // rbp
int v2; // er15
int v3; // er12
int v4; // eax
int v5; // ebx
int v6; // er13
int v7; // eax
int v8; // eax
void *v9; // rbx
int v10; // er13
int v11; // eax
int v12; // ebp
int v13; // er12

begin_reached = 0;
if ( !end_reached )
{
v1 = buf;
if ( (void *)page == buf )
{
v3 = fd;
v4 = lseek(fd, 0LL, 1);
v5 = v4;
if ( v4 == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
v6 = bytes_read;
if ( bytes_read >= v4 )
{
begin_reached = 1;
return;
}
if ( bytes_read + 5119 < v4 )
{
if ( lseek(v3, -5120 - bytes_read, 1) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v1 + 5120;
}
else
{
if ( lseek(v3, 0LL, 0) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v1 + v5 - (__int64)v6;
}
v7 = read(v3, v1, 0x2800uLL);
bytes_read = v7;
if ( v7 == -1 )
{
endwin();
fwrite("\nError reading file in back_lines().\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
*((_BYTE *)buf + v7) = 0;
}
if ( *(_BYTE *)--page != 10 )
{
endwin();
fwrite("\nInternal error in back_lines().\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
}
if ( a1 > 0 )
{
v2 = 0;
do
{
v9 = buf;
if ( (void *)page == buf )
{
v10 = fd;
v11 = lseek(fd, 0LL, 1);
v12 = v11;
if ( v11 == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
v13 = bytes_read;
if ( bytes_read >= v11 )
{
begin_reached = 1;
return;
}
if ( bytes_read + 5119 < v11 )
{
if ( lseek(v10, -5120 - bytes_read, 1) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v9 + 5120;
}
else
{
if ( lseek(v10, 0LL, 0) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v9 + v12 - (__int64)v13;
}
v8 = read(v10, v9, 0x2800uLL);
bytes_read = v8;
if ( v8 == -1 )
{
endwin();
fwrite("\nError reading file in back_lines().\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
*((_BYTE *)buf + v8) = 0;
}
}
while ( *(_BYTE *)--page != 10 || a1 != ++v2 );
}
++page;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
void *v1; // rbp
int v2; // er15
int v3; // er12
int v4; // eax
int v5; // ebx
int v6; // er13
int v7; // eax
int v8; // eax
void *v9; // rbx
int v10; // er13
int v11; // eax
int v12; // ebp
int v13; // er12

begin_reached = 0;
if ( !end_reached )
{
v1 = buf;
if ( (void *)page == buf )
{
v3 = fd;
v4 = lseek(fd, 0LL, 1);
v5 = v4;
if ( v4 == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
v6 = bytes_read;
if ( bytes_read >= v4 )
{
begin_reached = 1;
return;
}
if ( bytes_read + 5119 < v4 )
{
if ( lseek(v3, -5120 - bytes_read, 1) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v1 + 5120;
}
else
{
if ( lseek(v3, 0LL, 0) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v1 + v5 - (__int64)v6;
}
v7 = read(v3, v1, 0x2800uLL);
bytes_read = v7;
if ( v7 == -1 )
{
endwin();
fwrite("\nError reading file in back_lines().\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
*((_BYTE *)buf + v7) = 0;
}
if ( *(_BYTE *)--page != 10 )
{
endwin();
fwrite("\nInternal error in back_lines().\n", 1uLL, 0x21uLL, stderr);
exit(-1);
}
}
if ( a1 > 0 )
{
v2 = 0;
do
{
v9 = buf;
if ( (void *)page == buf )
{
v10 = fd;
v11 = lseek(fd, 0LL, 1);
v12 = v11;
if ( v11 == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
v13 = bytes_read;
if ( bytes_read >= v11 )
{
begin_reached = 1;
return;
}
if ( bytes_read + 5119 < v11 )
{
if ( lseek(v10, -5120 - bytes_read, 1) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v9 + 5120;
}
else
{
if ( lseek(v10, 0LL, 0) == -1 )
{
endwin();
fwrite("\nError moving file pointer in back_lines().\n", 1uLL, 0x2CuLL, stderr);
exit(-1);
}
page = (__int64)v9 + v12 - (__int64)v13;
}
v8 = read(v10, v9, 0x2800uLL);
bytes_read = v8;
if ( v8 == -1 )
{
endwin();
fwrite("\nError reading file in back_lines().\n", 1uLL, 0x25uLL, stderr);
exit(-1);
}
*((_BYTE *)buf + v8) = 0;
}
}
while ( *(_BYTE *)--page != 10 || a1 != ++v2 );
}
++page;
}

original_code:
static void
back_lines (int n)
{
    int i, fpos;
    begin_reached = 0;
    if (!end_reached) {
 if (page == buf) {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "back_lines().\n");
  exit (-1);
     }
     if (fpos > bytes_read) {
  if (fpos < (10*1024) / 2 + bytes_read) {
      if (lseek (fd, 0, 0) == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer in "
     "back_lines().\n");
   exit (-1);
      }
      page = buf + fpos - bytes_read;
  } else {
      if (lseek (fd, -((10*1024) / 2 + bytes_read), 1)
   == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer "
     "in back_lines().\n");
   exit (-1);
      }
      page = buf + (10*1024) / 2;
  }
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in back_lines().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
     } else {
  begin_reached = 1;
  return;
     }
 }
 if (*(--page) != '\n') {
     endwin ();
     fprintf (stderr, "\nInternal error in back_lines().\n");
     exit (-1);
 }
    }
    for (i = 0; i < n; i++)
 do {
     if (page == buf) {
  if ((fpos = lseek (fd, 0, 1)) == -1) {
      endwin ();
      fprintf (stderr,
     "\nError moving file pointer in back_lines().\n");
      exit (-1);
  }
  if (fpos > bytes_read) {
      if (fpos < (10*1024) / 2 + bytes_read) {
   if (lseek (fd, 0, 0) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer "
         "in back_lines().\n");
       exit (-1);
   }
   page = buf + fpos - bytes_read;
      } else {
   if (lseek (fd, -((10*1024) / 2 + bytes_read),
       1) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer"
         " in back_lines().\n");
       exit (-1);
   }
   page = buf + (10*1024) / 2;
      }
      if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
   endwin ();
   fprintf (stderr, "\nError reading file in "
     "back_lines().\n");
   exit (-1);
      }
      buf[bytes_read] = '\0';
  } else {
      begin_reached = 1;
      return;
  }
     }
 } while (*(--page) != '\n');
    page++;
}

canonical_original_code:
static void back_lines(int n)
{
    int i; int fpos;
    begin_reached = 0;
    if (!end_reached) {
 if (page == buf) {
     if ((fpos = lseek (fd, 0, 1)) == -1) {
  endwin ();
  fprintf (stderr, "\nError moving file pointer in "
    "back_lines().\n");
  exit (-1);
     }
     if (fpos > bytes_read) {
  if (fpos < (10*1024) / 2 + bytes_read) {
      if (lseek (fd, 0, 0) == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer in "
     "back_lines().\n");
   exit (-1);
      }
      page = buf + fpos - bytes_read;
  } else {
      if (lseek (fd, -((10*1024) / 2 + bytes_read), 1)
   == -1) {
   endwin ();
   fprintf (stderr, "\nError moving file pointer "
     "in back_lines().\n");
   exit (-1);
      }
      page = buf + (10*1024) / 2;
  }
  if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
      endwin ();
      fprintf (stderr, "\nError reading file in back_lines().\n");
      exit (-1);
  }
  buf[bytes_read] = '\0';
     } else {
  begin_reached = 1;
  return;
     }
 }
 if (*(--page) != '\n') {
     endwin ();
     fprintf (stderr, "\nInternal error in back_lines().\n");
     exit (-1);
 }
    }
    for (i = 0; i < n; i++)
 do {
     if (page == buf) {
  if ((fpos = lseek (fd, 0, 1)) == -1) {
      endwin ();
      fprintf (stderr,
     "\nError moving file pointer in back_lines().\n");
      exit (-1);
  }
  if (fpos > bytes_read) {
      if (fpos < (10*1024) / 2 + bytes_read) {
   if (lseek (fd, 0, 0) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer "
         "in back_lines().\n");
       exit (-1);
   }
   page = buf + fpos - bytes_read;
      } else {
   if (lseek (fd, -((10*1024) / 2 + bytes_read),
       1) == -1) {
       endwin ();
       fprintf (stderr, "\nError moving file pointer"
         " in back_lines().\n");
       exit (-1);
   }
   page = buf + (10*1024) / 2;
      }
      if ((bytes_read = read (fd, buf, (10*1024))) == -1) {
   endwin ();
   fprintf (stderr, "\nError reading file in "
     "back_lines().\n");
   exit (-1);
      }
      buf[bytes_read] = '\0';
  } else {
      begin_reached = 1;
      return;
  }
     }
 } while (*(--page) != '\n');
    page++;
}

variable_types: n int

return_type: void


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

v1 = (unsigned __int16)(a1 + WORD2(a1)) + (((unsigned int)a1 + HIDWORD(a1)) >> 16);
return (unsigned __int16)(v1 + WORD1(v1)) + (((unsigned __int16)v1 + (v1 >> 16)) >> 16);
}

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

v1 = (unsigned __int16)(a1 + WORD2(a1)) + (((unsigned int)a1 + HIDWORD(a1)) >> 16);
return (unsigned __int16)(v1 + WORD1(v1)) + (((unsigned __int16)v1 + (v1 >> 16)) >> 16);
}

original_code:
static inline unsigned short from64to16(unsigned long x)
{
 x = (x & 0xffffffff) + (x >> 32);
 x = (x & 0xffff) + (x >> 16);
 x = (x & 0xffff) + (x >> 16);
 x = (x & 0xffff) + (x >> 16);
 return x;
}

variable_types:
x
unsigned long

return_type: unsigned short


decompiled_code:
unsigned __int64 __fastcall do_csum(unsigned __int8 *a1, int a2)
{
unsigned __int64 result; // rax
int v3; // ebx
int v4; // edx
int v5; // edx
unsigned int v6; // edx
unsigned int v7; // er9
unsigned __int8 *v8; // r10
unsigned __int8 *v9; // rcx
_BOOL8 v10; // rdx
__int64 v11; // r8
unsigned __int64 v12; // rax
bool v13; // cf

result = 0LL;
if ( a2 > 0 )
{
v3 = (unsigned __int8)a1 & 1;
if ( ((unsigned __int8)a1 & 1) != 0 )
{
result = *a1 << 8;
--a2;
++a1;
}
v4 = a2 >> 1;
if ( a2 >> 1 )
{
if ( ((unsigned __int8)a1 & 2) != 0 )
{
result += *(unsigned __int16 *)a1;
--v4;
LOBYTE(a2) = a2 - 2;
a1 += 2;
}
v5 = v4 >> 1;
if ( v5 )
{
if ( ((unsigned __int8)a1 & 4) != 0 )
{
result += *(unsigned int *)a1;
--v5;
LOBYTE(a2) = a2 - 4;
a1 += 4;
}
v6 = v5 >> 1;
v7 = v6;
if ( v6 )
{
v8 = &a1[8 * v6];
v9 = a1;
v10 = 0LL;
do
{
v11 = *(_QWORD *)v9;
v9 += 8;
v12 = v10 + result;
v13 = __CFADD__(v11, v12);
result = v11 + v12;
v10 = v13;
}
while ( v9 != v8 );
a1 += 8 * v7;
result = v13 + (unsigned int)result + ((v13 + result) >> 32);
}
if ( (a2 & 4) != 0 )
{
result += *(unsigned int *)a1;
a1 += 4;
}
}
if ( (a2 & 2) != 0 )
{
result += *(unsigned __int16 *)a1;
a1 += 2;
}
}
if ( (a2 & 1) != 0 )
result += *a1;
result = (unsigned __int16)from64to16(result);
if ( v3 )
result = (unsigned __int16)((_WORD)result << 8) | (unsigned __int64)BYTE1(result);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int8 *a1, int a2)
{
unsigned __int64 result; // rax
int v3; // ebx
int v4; // edx
int v5; // edx
unsigned int v6; // edx
unsigned int v7; // er9
unsigned __int8 *v8; // r10
unsigned __int8 *v9; // rcx
_BOOL8 v10; // rdx
__int64 v11; // r8
unsigned __int64 v12; // rax
bool v13; // cf

result = 0LL;
if ( a2 > 0 )
{
v3 = (unsigned __int8)a1 & 1;
if ( ((unsigned __int8)a1 & 1) != 0 )
{
result = *a1 << 8;
--a2;
++a1;
}
v4 = a2 >> 1;
if ( a2 >> 1 )
{
if ( ((unsigned __int8)a1 & 2) != 0 )
{
result += *(unsigned __int16 *)a1;
--v4;
LOBYTE(a2) = a2 - 2;
a1 += 2;
}
v5 = v4 >> 1;
if ( v5 )
{
if ( ((unsigned __int8)a1 & 4) != 0 )
{
result += *(unsigned int *)a1;
--v5;
LOBYTE(a2) = a2 - 4;
a1 += 4;
}
v6 = v5 >> 1;
v7 = v6;
if ( v6 )
{
v8 = &a1[8 * v6];
v9 = a1;
v10 = 0LL;
do
{
v11 = *(_QWORD *)v9;
v9 += 8;
v12 = v10 + result;
v13 = __CFADD__(v11, v12);
result = v11 + v12;
v10 = v13;
}
while ( v9 != v8 );
a1 += 8 * v7;
result = v13 + (unsigned int)result + ((v13 + result) >> 32);
}
if ( (a2 & 4) != 0 )
{
result += *(unsigned int *)a1;
a1 += 4;
}
}
if ( (a2 & 2) != 0 )
{
result += *(unsigned __int16 *)a1;
a1 += 2;
}
}
if ( (a2 & 1) != 0 )
result += *a1;
result = (unsigned __int16)func0(result);
if ( v3 )
result = (unsigned __int16)((_WORD)result << 8) | (unsigned __int64)BYTE1(result);
}
return result;
}

original_code:
static inline unsigned long do_csum(unsigned char * buff, int len)
{
 int odd, count;
 unsigned long result = 0;
 if (len <= 0)
  goto out;
 odd = 1 & (unsigned long) buff;
 if (odd) {
  result = *buff << 8;
  len--;
  buff++;
 }
 count = len >> 1;
 if (count) {
  if (2 & (unsigned long) buff) {
   result += *(unsigned short *) buff;
   count--;
   len -= 2;
   buff += 2;
  }
  count >>= 1;
  if (count) {
   if (4 & (unsigned long) buff) {
    result += *(unsigned int *) buff;
    count--;
    len -= 4;
    buff += 4;
   }
   count >>= 1;
   if (count) {
    unsigned long carry = 0;
    do {
     unsigned long w = *(unsigned long *) buff;
     count--;
     buff += 8;
     result += carry;
     result += w;
     carry = (w > result);
    } while (count);
    result += carry;
    result = (result & 0xffffffff) + (result >> 32);
   }
   if (len & 4) {
    result += *(unsigned int *) buff;
    buff += 4;
   }
  }
  if (len & 2) {
   result += *(unsigned short *) buff;
   buff += 2;
  }
 }
 if (len & 1)
  result += *buff;
 result = from64to16(result);
 if (odd)
  result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
out:
 return result;
}

canonical_original_code:
static inline unsigned long do_csum(unsigned char *buff, int len)
{
 int odd; int count;
 unsigned long result = 0;
 if (len <= 0)
  goto out;
 odd = 1 & (unsigned long) buff;
 if (odd) {
  result = *buff << 8;
  len--;
  buff++;
 }
 count = len >> 1;
 if (count) {
  if (2 & (unsigned long) buff) {
   result += *(unsigned short *) buff;
   count--;
   len -= 2;
   buff += 2;
  }
  count >>= 1;
  if (count) {
   if (4 & (unsigned long) buff) {
    result += *(unsigned int *) buff;
    count--;
    len -= 4;
    buff += 4;
   }
   count >>= 1;
   if (count) {
    unsigned long carry = 0;
    do {
     unsigned long w = *(unsigned long *) buff;
     count--;
     buff += 8;
     result += carry;
     result += w;
     carry = (w > result);
    } while (count);
    result += carry;
    result = (result & 0xffffffff) + (result >> 32);
   }
   if (len & 4) {
    result += *(unsigned int *) buff;
    buff += 4;
   }
  }
  if (len & 2) {
   result += *(unsigned short *) buff;
   buff += 2;
  }
 }
 if (len & 1)
  result += *buff;
 result = from64to16(result);
 if (odd)
  result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
out:
 return result;
}

variable_types:
buff
unsigned char *

variable_types: len int

variable_types: odd int

variable_types: count int

variable_types:
result
unsigned long

variable_types:
carry
unsigned long

variable_types:
w
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall csum_tcpudp_magic(__int64 a1, __int64 a2, uint16_t a3, unsigned __int16 a4, unsigned int a5)
{
__int64 v6; // r12
int v7; // eax

v6 = a5 + a2;
LOWORD(v7) = ntohs(a3);
return (unsigned int)~from64to16(((__int64)v7 << 16) + a1 + v6 + ((unsigned __int64)a4 << 8));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, uint16_t a3, unsigned __int16 a4, unsigned int a5)
{
__int64 v6; // r12
int v7; // eax

v6 = a5 + a2;
LOWORD(v7) = ntohs(a3);
return (unsigned int)~func0(((__int64)v7 << 16) + a1 + v6 + ((unsigned __int64)a4 << 8));
}

original_code:
unsigned short int csum_tcpudp_magic(unsigned long saddr,
       unsigned long daddr,
       unsigned short len,
       unsigned short proto,
       unsigned int sum)
{
 return ~from64to16(saddr + daddr + sum +
  ((unsigned long) ntohs(len) << 16) +
  ((unsigned long) proto << 8));
}

canonical_original_code:
unsigned short csum_tcpudp_magic(unsigned long saddr, unsigned long daddr, unsigned short len, unsigned short proto, unsigned int sum)
{
 return ~from64to16(saddr + daddr + sum +
  ((unsigned long) ntohs(len) << 16) +
  ((unsigned long) proto << 8));
}

variable_types:
saddr
unsigned long

variable_types:
daddr
unsigned long

variable_types:
len
unsigned short

variable_types:
proto
unsigned short

variable_types:
sum
unsigned int


decompiled_code:
__int64 __fastcall ip_fast_csum(unsigned __int8 *a1, int a2)
{
return (unsigned int)~do_csum(a1, 4 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, int a2)
{
return (unsigned int)~func1(a1, 4 * a2);
}

original_code:
unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
{
 return ~do_csum(iph,ihl*4);
}

canonical_original_code:
unsigned short ip_fast_csum(unsigned char *iph, unsigned int ihl)
{
 return ~do_csum(iph,ihl*4);
}

variable_types:
iph
unsigned char *

variable_types:
ihl
unsigned int


decompiled_code:
unsigned __int64 __fastcall csum_partial(unsigned __int8 *a1, int a2, unsigned int a3)
{
unsigned __int64 v4; // rax

v4 = do_csum(a1, a2);
return a3 + (unsigned int)v4 + ((a3 + v4) >> 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int8 *a1, int a2, unsigned int a3)
{
unsigned __int64 v4; // rax

v4 = func1(a1, a2);
return a3 + (unsigned int)v4 + ((a3 + v4) >> 32);
}

original_code:
unsigned int csum_partial(unsigned char * buff, int len, unsigned int sum)
{
 unsigned long result = do_csum(buff, len);
 result += sum;
 result = (result & 0xffffffff) + (result >> 32);
 return result;
}

canonical_original_code:
unsigned int csum_partial(unsigned char *buff, int len, unsigned int sum)
{
 unsigned long result = do_csum(buff, len);
 result += sum;
 result = (result & 0xffffffff) + (result >> 32);
 return result;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall ip_compute_csum(unsigned __int8 *a1, int a2)
{
unsigned __int64 v2; // rax

v2 = do_csum(a1, a2);
return (unsigned int)~from64to16(v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, int a2)
{
unsigned __int64 v2; // rax

v2 = func1(a1, a2);
return (unsigned int)~func0(v2);
}

original_code:
unsigned short ip_compute_csum(unsigned char * buff, int len)
{
 return ~from64to16(do_csum(buff,len));
}

canonical_original_code:
unsigned short ip_compute_csum(unsigned char *buff, int len)
{
 return ~from64to16(do_csum(buff,len));
}


decompiled_code:
void __noreturn sys_iopl()
{
panic("sys_iopl");
}

canonical_decompiled_code:
void __noreturn func2()
{
func1("sys_iopl");
}

original_code: void sys_iopl(void) { _panic("sys_iopl"); }

canonical_original_code: void sys_iopl() { _panic("sys_iopl"); }


decompiled_code:
void __noreturn sys_vm86()
{
panic("sys_vm86");
}

canonical_decompiled_code:
void __noreturn func3()
{
func1("sys_vm86");
}

original_code: void sys_vm86(void) { _panic("sys_vm86"); }

canonical_original_code: void sys_vm86() { _panic("sys_vm86"); }


decompiled_code:
void __noreturn sys_modify_ldt()
{
panic("sys_modify_ldt");
}

canonical_decompiled_code:
void __noreturn func4()
{
func1("sys_modify_ldt");
}

original_code: void sys_modify_ldt(void) { _panic("sys_modify_ldt"); }

canonical_original_code: void sys_modify_ldt() { _panic("sys_modify_ldt"); }


decompiled_code:
void __noreturn sys_ipc()
{
panic("sys_ipc");
}

canonical_decompiled_code:
void __noreturn func5()
{
func1("sys_ipc");
}

original_code: void sys_ipc(void) {_panic("sys_ipc"); }

canonical_original_code: void sys_ipc() {_panic("sys_ipc"); }


decompiled_code:
void __noreturn sys_newselect()
{
panic("sys_newselect");
}

canonical_decompiled_code:
void __noreturn func6()
{
func1("sys_newselect");
}

original_code: void sys_newselect(void) {_panic("sys_newselect"); }

canonical_original_code: void sys_newselect() {_panic("sys_newselect"); }


decompiled_code:
__int64 saved_command_line()
{
return panic("saved_command_line");
}

canonical_decompiled_code:
__int64 func8()
{
return func1("saved_command_line");
}

original_code:
void
saved_command_line(void)
{
 panic("saved_command_line");
}

canonical_original_code:
void saved_command_line()
{
 panic("saved_command_line");
}


decompiled_code:
__int64 KSTK_EIP()
{
return panic("KSTK_EIP");
}

canonical_decompiled_code:
__int64 func9()
{
return func1("KSTK_EIP");
}

original_code:
void
KSTK_EIP(void)
{
 panic("KSTK_EIP");
}

canonical_original_code:
void KSTK_EIP()
{
 panic("KSTK_EIP");
}


decompiled_code:
__int64 KSTK_ESP()
{
return panic("KSTK_ESP");
}

canonical_decompiled_code:
__int64 func10()
{
return func1("KSTK_ESP");
}

original_code:
void
KSTK_ESP(void)
{
 panic("KSTK_ESP");
}

canonical_original_code:
void KSTK_ESP()
{
 panic("KSTK_ESP");
}


decompiled_code:
__int64 scsi_register_module()
{
return panic("scsi_register_module");
}

canonical_decompiled_code:
__int64 func11()
{
return func1("scsi_register_module");
}

original_code:
void
scsi_register_module(void)
{
 panic("scsi_register_module");
}

canonical_original_code:
void scsi_register_module()
{
 panic("scsi_register_module");
}


decompiled_code:
__int64 scsi_unregister_module()
{
return panic("scsi_unregister_module");
}

canonical_decompiled_code:
__int64 func12()
{
return func1("scsi_unregister_module");
}

original_code:
void
scsi_unregister_module(void)
{
 panic("scsi_unregister_module");
}

canonical_original_code:
void scsi_unregister_module()
{
 panic("scsi_unregister_module");
}


toOpcodeName

repo: shaybarak/MaabaGdalia

decompiled_code:
void *__fastcall toOpcodeName(unsigned int a1)
{
void *result; // rax

switch ( a1 )
{
case 0u:
result = &unk_402008;
break;
case 1u:
result = &unk_40203A;
break;
case 2u:
result = &unk_40200C;
break;
case 3u:
result = &unk_402010;
break;
case 4u:
result = &unk_402014;
break;
case 5u:
result = &unk_402019;
break;
case 6u:
result = &unk_402018;
break;
case 7u:
result = &unk_40201C;
break;
case 8u:
result = &unk_402020;
break;
case 9u:
result = &unk_402023;
break;
case 0x10u:
result = &unk_402026;
break;
case 0x11u:
result = &unk_40202A;
break;
case 0x12u:
result = &unk_40202E;
break;
case 0x13u:
result = &unk_402032;
break;
case 0x14u:
result = &unk_402036;
break;
case 0x18u:
result = &unk_402004;
break;
default:
printf("Illegal opcode %d!\n", a1);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(unsigned int a1)
{
void *result; // rax

switch ( a1 )
{
case 0u:
result = &unk_402008;
break;
case 1u:
result = &unk_40203A;
break;
case 2u:
result = &unk_40200C;
break;
case 3u:
result = &unk_402010;
break;
case 4u:
result = &unk_402014;
break;
case 5u:
result = &unk_402019;
break;
case 6u:
result = &unk_402018;
break;
case 7u:
result = &unk_40201C;
break;
case 8u:
result = &unk_402020;
break;
case 9u:
result = &unk_402023;
break;
case 0x10u:
result = &unk_402026;
break;
case 0x11u:
result = &unk_40202A;
break;
case 0x12u:
result = &unk_40202E;
break;
case 0x13u:
result = &unk_402032;
break;
case 0x14u:
result = &unk_402036;
break;
case 0x18u:
result = &unk_402004;
break;
default:
printf("Illegal opcode %d!\n", a1);
exit(1);
}
return result;
}

original_code:
char* toOpcodeName(Opcode opcode) {
   switch (opcode) {
   case ADD: return "ADD";
   case SUB: return "SUB";
   case LSF: return "LSF";
   case RSF: return "RSF";
   case AND: return "AND";
   case OR: return "OR";
   case XOR: return "XOR";
   case LHI: return "LHI";
   case LD: return "LD";
   case ST: return "ST";
   case JLT: return "JLT";
   case JLE: return "JLE";
   case JEQ: return "JEQ";
   case JNE: return "JNE";
   case JIN: return "JIN";
   case HLT: return "HLT";
   default:
 printf("Illegal opcode %d!\n", opcode);
 exit(1);
   }
   return ((void *)0);
}

canonical_original_code:
char *toOpcodeName(enum Opcode opcode) {
   switch (opcode) {
   case ADD: return "ADD";
   case SUB: return "SUB";
   case LSF: return "LSF";
   case RSF: return "RSF";
   case AND: return "AND";
   case OR: return "OR";
   case XOR: return "XOR";
   case LHI: return "LHI";
   case LD: return "LD";
   case ST: return "ST";
   case JLT: return "JLT";
   case JLE: return "JLE";
   case JEQ: return "JEQ";
   case JNE: return "JNE";
   case JIN: return "JIN";
   case HLT: return "HLT";
   default:
 printf("Illegal opcode %d!\n", opcode);
 exit(1);
   }
   return ((void *)0);
}

variable_types: enum Opcode { ADD=0, SUB=1, LSF=2, RSF=3, AND=4, OR=5, XOR=6, LHI=7, LD=8, ST=9, JLT=16, JLE=17, JEQ=18, JNE=19, JIN=20, HLT=24 }


fetch

original_code:
Instruction fetch(unsigned int inst) {
 Instruction out;
 out.opcode = (Opcode)(unsigned int)((inst >> 25) & 0x1F);
 out.dst = (inst >> 22) & 0x7;
 out.src0 = (inst >> 19) & 0x7;
 out.src1 = (inst >> 16) & 0x7;
 out.immediate = (inst) & 0xffff;
 return out;
}

canonical_original_code:
struct Instruction fetch(unsigned int inst) {
 struct Instruction out;
 out.opcode = (enum Opcode)(unsigned int)((inst >> 25) & 0x1F);
 out.dst = (inst >> 22) & 0x7;
 out.src0 = (inst >> 19) & 0x7;
 out.src1 = (inst >> 16) & 0x7;
 out.immediate = (inst) & 0xffff;
 return out;
}

variable_types:
inst
unsigned int

variable_types: struct Instruction { int unused; enum Opcode { ADD=0, SUB=1, LSF=2, RSF=3, AND=4, OR=5, XOR=6, LHI=7, LD=8, ST=9, JLT=16, JLE=17, JEQ=18, JNE=19, JIN=20, HLT=24 } opcode; unsigned int dst; unsigned int src0; unsigned int src1; int immediate; int val0; int val1; }

user_defined_types: struct Instruction { int unused; enum Opcode opcode; unsigned int dst; unsigned int src0; unsigned int src1; int immediate; int val0; int val1; }


decode

original_code:
void decode(Instruction* inst, int* regs) {
 inst->val0 = (inst->src0 == 1 || inst->opcode == LHI) ? inst->immediate : regs[inst->src0];
 inst->val1 = (inst->src1 == 1) ? inst->immediate : regs[inst->src1];
}

canonical_original_code:
void decode(struct Instruction *inst, int *regs) {
 inst->val0 = (inst->src0 == 1 || inst->opcode == LHI) ? inst->immediate : regs[inst->src0];
 inst->val1 = (inst->src1 == 1) ? inst->immediate : regs[inst->src1];
}

variable_types: struct Instruction { int unused; enum Opcode { ADD=0, SUB=1, LSF=2, RSF=3, AND=4, OR=5, XOR=6, LHI=7, LD=8, ST=9, JLT=16, JLE=17, JEQ=18, JNE=19, JIN=20, HLT=24 } opcode; unsigned int dst; unsigned int src0; unsigned int src1; int immediate; int val0; int val1; } *

variable_types:
regs
int *


XOR

repo: shazame/project-euler

decompiled_code:
__int64 __fastcall XOR(int a1, unsigned int a2)
{
return a1 ^ a2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, unsigned int a2)
{
return a1 ^ a2;
}

original_code:
char XOR(char c1, char c2) {
 return (c1 ^ c2);
}

return_type: char


decode

original_code:
int decode(char result[1201 +1], const char key[4]) {
 int i = 0;
 for (i = 0; i < 1201; i++) {
  result[i] = XOR(cipher[i], key[i%3]);
  if (i < 1201 - 1) {
   if (result[i] < 8) {
    return 0;
   }
   else {
    switch(result[i]) {
     case '{':
     case '}':
     case '#':
     case '`':
      return 0;
     default:
      break;
    }
   }
  }
 }
 result[1201] = '\0';
 return 1;
}

canonical_original_code:
int decode(char result[-1], char key[4]) {
 int i = 0;
 for (i = 0; i < 1201; i++) {
  result[i] = XOR(cipher[i], key[i%3]);
  if (i < 1201 - 1) {
   if (result[i] < 8) {
    return 0;
   }
   else {
    switch(result[i]) {
     case '{':
     case '}':
     case '#':
     case '`':
      return 0;
     default:
      break;
    }
   }
  }
 }
 result[1201] = '\0';
 return 1;
}

variable_types:
result
char [-1]

variable_types:
key
char [4]

variable_types: i int

return_type: int


genword

decompiled_code:
__int64 __fastcall genword(__int64 a1, unsigned int a2, int a3, int a4, const char *a5)
{
char *v6; // rbx
__int64 result; // rax
char v8; // r13
char v9; // bl
char v10; // r14

v6 = C;
if ( a3 == 1 )
{
if ( (unsigned int)a4 > 0x19 )
__assert_fail("curcar < NBCAR && curcar >= 0", "problem059.c", 0x40u, "genword");
*(_BYTE *)(a1 + (int)a2) = C[a4];
v8 = *(_BYTE *)a1;
v9 = *(_BYTE *)(a1 + 1);
v10 = *(_BYTE *)(a1 + 2);
if ( (unsigned int)decode((__int64)a5, a1) == 1 )
printf("%s:%s\n\n", (const char *)a1, a5);
if ( *(_BYTE *)a1 != v8 || *(_BYTE *)(a1 + 1) != v9 || *(_BYTE *)(a1 + 2) != v10 )
__assert_fail("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 0x47u, "genword");
result = (unsigned int)a4;
if ( a4 <= 24 )
result = genword(a1, a2, 1LL, (unsigned int)(a4 + 1), a5);
}
else
{
do
{
*(_BYTE *)(a1 + (int)a2) = *v6;
result = genword(a1, a2 + 1, (unsigned int)(a3 - 1), 0LL, a5);
++v6;
}
while ( v6 != &_bss_start );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, int a3, int a4, const char *a5)
{
char *v6; // rbx
__int64 result; // rax
char v8; // r13
char v9; // bl
char v10; // r14

v6 = C;
if ( a3 == 1 )
{
if ( (unsigned int)a4 > 0x19 )
__assert_fail("curcar < NBCAR && curcar >= 0", "problem059.c", 0x40u, "genword");
*(_BYTE *)(a1 + (int)a2) = C[a4];
v8 = *(_BYTE *)a1;
v9 = *(_BYTE *)(a1 + 1);
v10 = *(_BYTE *)(a1 + 2);
if ( (unsigned int)func8((__int64)a5, a1) == 1 )
printf("%s:%s\n\n", (const char *)a1, a5);
if ( *(_BYTE *)a1 != v8 || *(_BYTE *)(a1 + 1) != v9 || *(_BYTE *)(a1 + 2) != v10 )
__assert_fail("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 0x47u, "genword");
result = (unsigned int)a4;
if ( a4 <= 24 )
result = func9(a1, a2, 1LL, (unsigned int)(a4 + 1), a5);
}
else
{
do
{
*(_BYTE *)(a1 + (int)a2) = *v6;
result = func9(a1, a2 + 1, (unsigned int)(a3 - 1), 0LL, a5);
++v6;
}
while ( v6 != &_bss_start );
}
return result;
}

original_code:
void genword(char * buffer, int begin, int size, int curcar, char result[1201 +1]) {
 int i = 0;
 char tmp1, tmp2, tmp3;
 if (size == 1) {
  ((void) sizeof ((curcar < 26 && curcar >= 0) ? 1 : 0), __extension__ ({ if (curcar < 26 && curcar >= 0) ; else __assert_fail ("curcar < NBCAR && curcar >= 0", "problem059.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  buffer[begin] = C[curcar];
  tmp1 = buffer[0], tmp2 = buffer[1], tmp3 = buffer[2];
  if (decode(result, buffer) == 1) {
   printf("%s:%s\n\n", buffer, result);
  }
  ((void) sizeof ((tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ? 1 : 0), __extension__ ({ if (tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ; else __assert_fail ("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  if (curcar >= 26 -1) {
   return;
  }
  genword(buffer, begin, size, curcar+1, result);
 }
 else {
  for (i = 0; i < 26; i++) {
   buffer[begin] = C[i];
   genword(buffer, begin+1, size-1, 0, result);
  }
 }
}

canonical_original_code:
void genword(char *buffer, int begin, int size, int curcar, char result[-1]) {
 int i = 0;
 char tmp1; char tmp2; char tmp3;
 if (size == 1) {
  ((void) sizeof ((curcar < 26 && curcar >= 0) ? 1 : 0), __extension__ ({ if (curcar < 26 && curcar >= 0) ; else __assert_fail ("curcar < NBCAR && curcar >= 0", "problem059.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  buffer[begin] = C[curcar];
  tmp1 = buffer[0], tmp2 = buffer[1], tmp3 = buffer[2];
  if (decode(result, buffer) == 1) {
   printf("%s:%s\n\n", buffer, result);
  }
  ((void) sizeof ((tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ? 1 : 0), __extension__ ({ if (tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]) ; else __assert_fail ("tmp1 == buffer[0] && tmp2 == buffer[1] && tmp3 == buffer[2]", "problem059.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  if (curcar >= 26 -1) {
   return;
  }
  genword(buffer, begin, size, curcar+1, result);
 }
 else {
  for (i = 0; i < 26; i++) {
   buffer[begin] = C[i];
   genword(buffer, begin+1, size-1, 0, result);
  }
 }
}

variable_types:
buffer
char *

variable_types: begin int

variable_types: size int

variable_types: curcar int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+0h] [rbp-4C8h] BYREF
char v5[1184]; // [rsp+10h] [rbp-4B8h] BYREF
__int16 v6; // [rsp+4B0h] [rbp-18h]
int v7[3]; // [rsp+4BCh] [rbp-Ch] BYREF

v7[0] = 0;
v4[0] = 0LL;
v4[1] = 0LL;
memset(v5, 0, sizeof(v5));
v6 = 0;
genword((__int64)v7, 0, 3, 0, (const char *)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+0h] [rbp-4C8h] BYREF
char v5[1184]; // [rsp+10h] [rbp-4B8h] BYREF
__int16 v6; // [rsp+4B0h] [rbp-18h]
int v7[3]; // [rsp+4BCh] [rbp-Ch] BYREF

v7[0] = 0;
v4[0] = 0LL;
v4[1] = 0LL;
memset(v5, 0, sizeof(v5));
v6 = 0;
func9((__int64)v7, 0, 3, 0, (const char *)v4);
return 0;
}

original_code:
int main(void) {
 char buffer[4] = {0, 0, 0, 0}, result[1201 +1] = "";
 genword(buffer, 0, 3, 0, result);
 return 0;
}

canonical_original_code:
int main() {
 char buffer[4] = {0, 0, 0, 0}; char result[-1] = "";
 genword(buffer, 0, 3, 0, result);
 return 0;
}

variable_types:
buffer
char [4]


repo: shcabin/memory-leak-detector

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx

xmalloc(256LL, "test.c", 10LL);
v3 = xmalloc(128LL, "test.c", 11LL);
xstrdup("0123456789abcdef", "test.c", 12LL);
xcalloc(1LL, 32LL, "test.c", 13LL);
xfree(v3);
return report_mem_leak();
}

original_code:
void main()
{
 void *ptr;
 ptr=xmalloc(256, "test.c", 10);
 ptr=xmalloc(128, "test.c", 11);
 xstrdup("0123456789abcdef", "test.c", 12);
 xcalloc(1, 32, "test.c", 13);
 xfree(ptr);
 report_mem_leak();
}

variable_types:
ptr
void *


repo: sheepdog/sheepdog

decompiled_code:
__int64 __fastcall ec_init_tables(int a1, int a2, unsigned __int8 *a3, __int64 a4)
{
int i; // er14
__int64 result; // rax
__int64 v8; // rbp
unsigned __int8 *v9; // r12
__int64 v10; // [rsp+10h] [rbp-48h]

if ( a2 > 0 )
{
v10 = (unsigned int)(a1 - 1) + 1LL;
for ( i = 0; i != a2; ++i )
{
result = (unsigned int)(a1 - 1) + 1LL;
v9 = &a3[v10];
v8 = a4;
if ( a1 > 0 )
{
do
{
result = gf_vect_mul_init(*a3++, v8);
v8 += 32LL;
}
while ( a3 != v9 );
a4 += 32 * v10;
a3 = v9;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, unsigned __int8 *a3, __int64 a4)
{
int i; // er14
__int64 result; // rax
__int64 v8; // rbp
unsigned __int8 *v9; // r12
__int64 v10; // [rsp+10h] [rbp-48h]

if ( a2 > 0 )
{
v10 = (unsigned int)(a1 - 1) + 1LL;
for ( i = 0; i != a2; ++i )
{
result = (unsigned int)(a1 - 1) + 1LL;
v9 = &a3[v10];
v8 = a4;
if ( a1 > 0 )
{
do
{
result = gf_vect_mul_init(*a3++, v8);
v8 += 32LL;
}
while ( a3 != v9 );
a4 += 32 * v10;
a3 = v9;
}
}
}
return result;
}

original_code:
void ec_init_tables(int k, int rows, unsigned char *a, unsigned char *g_tbls)
{
 int i, j;
 for (i = 0; i < rows; i++) {
  for (j = 0; j < k; j++) {
   gf_vect_mul_init(*a++, g_tbls);
   g_tbls += 32;
  }
 }
}

canonical_original_code:
void ec_init_tables(int k, int rows, unsigned char *a, unsigned char *g_tbls)
{
 int i; int j;
 for (i = 0; i < rows; i++) {
  for (j = 0; j < k; j++) {
   gf_vect_mul_init(*a++, g_tbls);
   g_tbls += 32;
  }
 }
}

variable_types: k int

variable_types: rows int

variable_types:
a
unsigned char *

variable_types: j int


decompiled_code:
__int64 __fastcall ec_encode_data_sse(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // rbx
_QWORD *v8; // r15
__int64 v9; // rbp
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+14h] [rbp-44h]

v13 = a3;
v12 = a4;
v7 = a6;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, (unsigned int)a3, a4);
v8 = a6;
if ( a3 > 3 )
{
v11 = (int)((_DWORD)a2 << 7);
v14 = (unsigned int)(a3 - 4) >> 2;
v8 = &a6[4 * v14 + 4];
v9 = a4;
do
{
gf_4vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v9, a5, v7);
v9 += v11;
v7 += 4;
}
while ( v7 != v8 );
v12 += (v14 + 1) * v11;
v13 = v13 - 4 * v14 - 4;
}
result = v13;
switch ( v13 )
{
case 2u:
return gf_2vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 3u:
return gf_3vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 1u:
result = gf_vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v12, a5, *v8);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // rbx
_QWORD *v8; // r15
__int64 v9; // rbp
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+14h] [rbp-44h]

v13 = a3;
v12 = a4;
v7 = a6;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, (unsigned int)a3, a4);
v8 = a6;
if ( a3 > 3 )
{
v11 = (int)((_DWORD)a2 << 7);
v14 = (unsigned int)(a3 - 4) >> 2;
v8 = &a6[4 * v14 + 4];
v9 = a4;
do
{
gf_4vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v9, a5, v7);
v9 += v11;
v7 += 4;
}
while ( v7 != v8 );
v12 += (v14 + 1) * v11;
v13 = v13 - 4 * v14 - 4;
}
result = v13;
switch ( v13 )
{
case 2u:
return gf_2vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 3u:
return gf_3vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 1u:
result = gf_vect_dot_prod_sse((unsigned int)a1, (unsigned int)a2, v12, a5, *v8);
break;
}
return result;
}

original_code:
void ec_encode_data_sse(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
   unsigned char **coding)
{
 if (len < 16) {
  ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  return;
 }
 while (rows >= 4) {
  gf_4vect_dot_prod_sse(len, k, g_tbls, data, coding);
  g_tbls += 4 * k * 32;
  coding += 4;
  rows -= 4;
 }
 switch (rows) {
 case 3:
  gf_3vect_dot_prod_sse(len, k, g_tbls, data, coding);
  break;
 case 2:
  gf_2vect_dot_prod_sse(len, k, g_tbls, data, coding);
  break;
 case 1:
  gf_vect_dot_prod_sse(len, k, g_tbls, data, *coding);
  break;
 case 0:
  break;
 }
}

variable_types: len int

variable_types:
data
unsigned char **

variable_types:
coding
unsigned char **


decompiled_code:
__int64 __fastcall ec_encode_data_avx(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // rbx
_QWORD *v8; // r15
__int64 v9; // rbp
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+14h] [rbp-44h]

v13 = a3;
v12 = a4;
v7 = a6;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, (unsigned int)a3, a4);
v8 = a6;
if ( a3 > 3 )
{
v11 = (int)((_DWORD)a2 << 7);
v14 = (unsigned int)(a3 - 4) >> 2;
v8 = &a6[4 * v14 + 4];
v9 = a4;
do
{
gf_4vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v9, a5, v7);
v9 += v11;
v7 += 4;
}
while ( v7 != v8 );
v12 += (v14 + 1) * v11;
v13 = v13 - 4 * v14 - 4;
}
result = v13;
switch ( v13 )
{
case 2u:
return gf_2vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 3u:
return gf_3vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 1u:
result = gf_vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v12, a5, *v8);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // rbx
_QWORD *v8; // r15
__int64 v9; // rbp
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+14h] [rbp-44h]

v13 = a3;
v12 = a4;
v7 = a6;
if ( (int)a1 <= 15 )
return ec_encode_data_base(a1, a2, (unsigned int)a3, a4);
v8 = a6;
if ( a3 > 3 )
{
v11 = (int)((_DWORD)a2 << 7);
v14 = (unsigned int)(a3 - 4) >> 2;
v8 = &a6[4 * v14 + 4];
v9 = a4;
do
{
gf_4vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v9, a5, v7);
v9 += v11;
v7 += 4;
}
while ( v7 != v8 );
v12 += (v14 + 1) * v11;
v13 = v13 - 4 * v14 - 4;
}
result = v13;
switch ( v13 )
{
case 2u:
return gf_2vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 3u:
return gf_3vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 1u:
result = gf_vect_dot_prod_avx((unsigned int)a1, (unsigned int)a2, v12, a5, *v8);
break;
}
return result;
}

original_code:
void ec_encode_data_avx(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
   unsigned char **coding)
{
 if (len < 16) {
  ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  return;
 }
 while (rows >= 4) {
  gf_4vect_dot_prod_avx(len, k, g_tbls, data, coding);
  g_tbls += 4 * k * 32;
  coding += 4;
  rows -= 4;
 }
 switch (rows) {
 case 3:
  gf_3vect_dot_prod_avx(len, k, g_tbls, data, coding);
  break;
 case 2:
  gf_2vect_dot_prod_avx(len, k, g_tbls, data, coding);
  break;
 case 1:
  gf_vect_dot_prod_avx(len, k, g_tbls, data, *coding);
  break;
 case 0:
  break;
 }
}


decompiled_code:
__int64 __fastcall ec_encode_data_avx2(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // rbx
_QWORD *v8; // r15
__int64 v9; // rbp
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+14h] [rbp-44h]

v13 = a3;
v12 = a4;
v7 = a6;
if ( (int)a1 <= 31 )
return ec_encode_data_base(a1, a2, (unsigned int)a3, a4);
v8 = a6;
if ( a3 > 3 )
{
v11 = (int)((_DWORD)a2 << 7);
v14 = (unsigned int)(a3 - 4) >> 2;
v8 = &a6[4 * v14 + 4];
v9 = a4;
do
{
gf_4vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v9, a5, v7);
v9 += v11;
v7 += 4;
}
while ( v7 != v8 );
v12 += (v14 + 1) * v11;
v13 = v13 - 4 * v14 - 4;
}
result = v13;
switch ( v13 )
{
case 2u:
return gf_2vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 3u:
return gf_3vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 1u:
result = gf_vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v12, a5, *v8);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, _QWORD *a6)
{
_QWORD *v7; // rbx
_QWORD *v8; // r15
__int64 v9; // rbp
__int64 result; // rax
__int64 v11; // [rsp+0h] [rbp-58h]
__int64 v12; // [rsp+8h] [rbp-50h]
unsigned int v13; // [rsp+10h] [rbp-48h]
unsigned int v14; // [rsp+14h] [rbp-44h]

v13 = a3;
v12 = a4;
v7 = a6;
if ( (int)a1 <= 31 )
return ec_encode_data_base(a1, a2, (unsigned int)a3, a4);
v8 = a6;
if ( a3 > 3 )
{
v11 = (int)((_DWORD)a2 << 7);
v14 = (unsigned int)(a3 - 4) >> 2;
v8 = &a6[4 * v14 + 4];
v9 = a4;
do
{
gf_4vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v9, a5, v7);
v9 += v11;
v7 += 4;
}
while ( v7 != v8 );
v12 += (v14 + 1) * v11;
v13 = v13 - 4 * v14 - 4;
}
result = v13;
switch ( v13 )
{
case 2u:
return gf_2vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 3u:
return gf_3vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v12, a5, v8);
case 1u:
result = gf_vect_dot_prod_avx2((unsigned int)a1, (unsigned int)a2, v12, a5, *v8);
break;
}
return result;
}

original_code:
void ec_encode_data_avx2(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data,
    unsigned char **coding)
{
 if (len < 32) {
  ec_encode_data_base(len, k, rows, g_tbls, data, coding);
  return;
 }
 while (rows >= 4) {
  gf_4vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  g_tbls += 4 * k * 32;
  coding += 4;
  rows -= 4;
 }
 switch (rows) {
 case 3:
  gf_3vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  break;
 case 2:
  gf_2vect_dot_prod_avx2(len, k, g_tbls, data, coding);
  break;
 case 1:
  gf_vect_dot_prod_avx2(len, k, g_tbls, data, *coding);
  break;
 case 0:
  break;
 }
}


repo: sheheitthey/pipeserver

decompiled_code:
void *__fastcall pollset_construct(int *a1)
{
void *result; // rax

pollpool_construct();
result = malloc(8LL * *a1);
*((_QWORD *)a1 + 6) = result;
a1[14] = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int *a1)
{
void *result; // rax

pollpool_construct();
result = malloc(8LL * *a1);
*((_QWORD *)a1 + 6) = result;
a1[14] = 0;
return result;
}

original_code:
void
pollset_construct(pollset *ps, struct pollfd *ufds, int len,
                  int sendbuf_len, int recvbuf_len)
{
    pollpool_construct(&ps->pp, ufds, len, sendbuf_len, recvbuf_len);
    ps->handles=(pollconn**)malloc(sizeof(pollconn*)*ps->pp.len);
    ps->handles_len=0;
}

canonical_original_code:
void pollset_construct(struct pollset *ps, struct pollfd *ufds, int len, int sendbuf_len, int recvbuf_len)
{
    pollpool_construct(&ps->pp, ufds, len, sendbuf_len, recvbuf_len);
    ps->handles=(struct pollconn **)malloc(sizeof(struct pollconn *)*ps->pp.len);
    ps->handles_len=0;
}

variable_types: struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } *

variable_types:
ufds
struct pollfd *

user_defined_types: struct pollset { struct pollpool pp; struct pollconn **handles; int handles_len; }

user_defined_types: struct pollconn { struct pollsock s; struct sockaddr_in saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; }

user_defined_types: struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; }

user_defined_types: struct pollsock { struct pollfd *pfd; struct tcpbuf sendbuf; struct tcpbuf recvbuf; }

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 pollset_destruct(__int64 a1)
{
pollpool_destruct();
free(*(void **)(a1 + 48));
*(_QWORD *)(a1 + 48) = 0LL;
*(_DWORD *)(a1 + 56) = 0;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
pollpool_destruct();
free(*(void **)(a1 + 48));
*(_QWORD *)(a1 + 48) = 0LL;
*(_DWORD *)(a1 + 56) = 0;
}

original_code:
void
pollset_destruct(pollset *ps)
{
    pollpool_destruct(&ps->pp);
    free(ps->handles);
    ps->handles=((void *)0);
    ps->handles_len=0;
}

canonical_original_code:
void pollset_destruct(struct pollset *ps)
{
    pollpool_destruct(&ps->pp);
    free(ps->handles);
    ps->handles=((void *)0);
    ps->handles_len=0;
}

user_defined_types: struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; }

user_defined_types: struct tcpbuf { int len; int pos; unsigned char *data; }

user_defined_types: struct pollfd { int fd; short events; short revents; }


decompiled_code:
void pollset_resize()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void
pollset_resize(pollset *ps, struct pollfd *ufds, int newlen)
{
}

canonical_original_code:
void pollset_resize(struct pollset *ps, struct pollfd *ufds, int newlen)
{
}

variable_types: newlen int


decompiled_code:
__int64 pollset_connhandle()
{
return pollpool_index();
}

canonical_decompiled_code:
__int64 func3()
{
return pollpool_index();
}

original_code:
pollset_handle
pollset_connhandle(const pollset *ps, pollconn *c)
{
    return pollpool_index(&ps->pp, c);
}

canonical_original_code:
int pollset_connhandle(struct pollset *ps, struct pollconn *c)
{
    return pollpool_index(&ps->pp, c);
}

variable_types:
c
struct pollconn *


decompiled_code:
__int64 __fastcall pollset_binsearch(__int64 a1, int a2, _DWORD *a3)
{
int v4; // ebp
int v5; // er13
int v7; // ebx
int v8; // eax
unsigned int v9; // [rsp+Ch] [rbp-3Ch]

if ( a3 )
*a3 = 0;
v9 = 0;
v4 = *(_DWORD *)(a1 + 56) - 1;
if ( v4 >= 0 )
{
v5 = 0;
while ( 1 )
{
v7 = (v5 + v4) / 2;
v9 = v7;
v8 = pollset_connhandle(a1, *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * v7));
if ( v8 == a2 )
break;
if ( v5 >= v4 )
return (unsigned int)(v8 <= a2) + v7;
if ( v8 <= a2 )
v5 = v7 + 1;
else
v4 = v7 - 1;
}
if ( a3 )
*a3 = 1;
}
return v9;
}

original_code:
static int
pollset_binsearch(const pollset *ps, pollset_handle h, int *found)
{
    int l, m, r;
    pollset_handle t;
    if(found)
        *found=0;
    l=0;
    r=ps->handles_len-1;
    if(l>r)
        return 0;
    while(1)
    {
        m=(l+r)/2;
        t=pollset_connhandle(ps, ps->handles[m]);
        if(h==t)
        {
            if(found)
                *found=1;
            return m;
        }
        if(l>=r)
        {
            if(h<t)
                return m;
            else
                return m+1;
        }
        if(h<t)
            r=m-1;
        else
            l=m+1;
    }
}

canonical_original_code:
static int pollset_binsearch(struct pollset *ps, int h, int *found)
{
    int l; int m; int r;
    int t;
    if(found)
        *found=0;
    l=0;
    r=ps->handles_len-1;
    if(l>r)
        return 0;
    while(1)
    {
        m=(l+r)/2;
        t=pollset_connhandle(ps, ps->handles[m]);
        if(h==t)
        {
            if(found)
                *found=1;
            return m;
        }
        if(l>=r)
        {
            if(h<t)
                return m;
            else
                return m+1;
        }
        if(h<t)
            r=m-1;
        else
            l=m+1;
    }
}

variable_types: h int

variable_types:
found
int *

variable_types: l int

variable_types: m int

variable_types: r int

variable_types: t int


decompiled_code:
__int64 __fastcall pollset_delconn(__int64 a1, int a2)
{
int v2; // eax
int v3; // ebx
__int64 v4; // r12
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = pollset_binsearch(a1, a2, v6);
if ( !v6[0] )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = 8LL * v2;
pollpool_free(a1, *(_QWORD *)(*(_QWORD *)(a1 + 48) + v4));
memmove(
(void *)(v4 + *(_QWORD *)(a1 + 48)),
(const void *)(*(_QWORD *)(a1 + 48) + v4 + 8),
8LL * (*(_DWORD *)(a1 + 56) + ~v3));
--*(_DWORD *)(a1 + 56);
return 0LL;
}

original_code:
int
pollset_delconn(pollset *ps, pollset_handle psh)
{
    int index, found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return -1;
    pollpool_free(&ps->pp, ps->handles[index]);
    memmove(ps->handles+index, ps->handles+index+1,
            sizeof(pollconn*)*(ps->handles_len-index-1));
    (ps->handles_len)--;
    return 0;
}

canonical_original_code:
int pollset_delconn(struct pollset *ps, int psh)
{
    int index; int found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return -1;
    pollpool_free(&ps->pp, ps->handles[index]);
    memmove(ps->handles+index, ps->handles+index+1,
            sizeof(struct pollconn *)*(ps->handles_len-index-1));
    (ps->handles_len)--;
    return 0;
}

variable_types: psh int

variable_types: index int

variable_types: found int


decompiled_code:
__int64 __fastcall pollset_conn(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = pollset_binsearch(a1, a2, v4);
if ( v4[0] )
result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = func4(a1, a2, v4);
if ( v4[0] )
result = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL * v2);
else
result = 0LL;
return result;
}

original_code:
pollconn *pollset_conn(const pollset *ps, pollset_handle psh)
{
    int index, found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return ((void *)0);
    return ps->handles[index];
}

canonical_original_code:
struct pollconn *pollset_conn(struct pollset *ps, int psh)
{
    int index; int found;
    index=pollset_binsearch(ps, psh, &found);
    if(!found)
        return ((void *)0);
    return ps->handles[index];
}

variable_types: struct pollset { struct pollpool { int len; struct pollconn *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } *

return_type: struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *


decompiled_code:
__int64 __fastcall pollset_addconn_socket(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
int v3; // eax
__int64 v4; // r13
size_t v5; // rdx
__int64 v6; // rax
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = pollset_connhandle(a1, a2);
v3 = pollset_binsearch(a1, v2, v8);
if ( v8[0] )
return (unsigned int)-1;
v4 = v3;
v5 = 8LL * (*(_DWORD *)(a1 + 56) - v3);
v6 = *(_QWORD *)(a1 + 48) + 8LL * v3;
memmove((void *)(v6 + 8), (const void *)v6, v5);
*(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v4) = a2;
++*(_DWORD *)(a1 + 56);
return v2;
}

original_code:
static pollset_handle
pollset_addconn_socket(pollset *ps, pollconn *c)
{
    int index, ret, found;
    ret=pollset_connhandle(ps, c);
    index=pollset_binsearch(ps, ret, &found);
    if(found)
        return -1;
    memmove(ps->handles+index+1, ps->handles+index,
            sizeof(pollconn*)*(ps->handles_len-index));
    ps->handles[index]=c;
    (ps->handles_len)++;
    return ret;
}

canonical_original_code:
static int pollset_addconn_socket(struct pollset *ps, struct pollconn *c)
{
    int index; int ret; int found;
    ret=pollset_connhandle(ps, c);
    index=pollset_binsearch(ps, ret, &found);
    if(found)
        return -1;
    memmove(ps->handles+index+1, ps->handles+index,
            sizeof(struct pollconn *)*(ps->handles_len-index));
    ps->handles[index]=c;
    (ps->handles_len)++;
    return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall pollset_addconn(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 result; // rax

v1 = pollpool_new();
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
result = pollconn_socket(v1);
if ( (int)result >= 0 )
result = pollset_addconn_socket(a1, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 result; // rax

v1 = pollpool_new();
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = v1;
result = pollconn_socket(v1);
if ( (int)result >= 0 )
result = func7(a1, v2);
return result;
}

original_code:
pollset_handle
pollset_addconn(pollset *ps)
{
    pollset_handle ret;
    pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    ret=pollconn_socket(c);
    if(ret<0)
        return ret;
    return pollset_addconn_socket(ps, c);
}

canonical_original_code:
int pollset_addconn(struct pollset *ps)
{
    int ret;
    struct pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    ret=pollconn_socket(c);
    if(ret<0)
        return ret;
    return pollset_addconn_socket(ps, c);
}

variable_types: struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *


decompiled_code:
__int64 __fastcall pollset_addaccepted(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = pollpool_new();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
pollconn_accepted(v2, a2);
return pollset_addconn_socket(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbx

v2 = pollpool_new();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
pollconn_accepted(v2, a2);
return func7(a1, v3);
}

original_code:
pollset_handle
pollset_addaccepted(pollset *ps, int fd)
{
    pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    pollconn_accepted(c, fd);
    return pollset_addconn_socket(ps, c);
}

canonical_original_code:
int pollset_addaccepted(struct pollset *ps, int fd)
{
    struct pollconn *c;
    c=pollpool_new(&ps->pp);
    if(!c)
        return -1;
    pollconn_accepted(c, fd);
    return pollset_addconn_socket(ps, c);
}

variable_types: fd int


decompiled_code:
__int64 pollset_poll()
{
return pollpool_poll();
}

canonical_decompiled_code:
__int64 func10()
{
return pollpool_poll();
}

original_code:
int
pollset_poll(pollset *ps, int timeout)
{
    return pollpool_poll(&ps->pp, timeout);
}

canonical_original_code:
int pollset_poll(struct pollset *ps, int timeout)
{
    return pollpool_poll(&ps->pp, timeout);
}

variable_types: struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } *

variable_types: timeout int


decompiled_code:
__int64 __fastcall pollset_operate(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 56) > 0 )
{
v1 = 0LL;
do
result = pollconn_operate(*(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v1++));
while ( *(_DWORD *)(a1 + 56) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 56) > 0 )
{
v1 = 0LL;
do
result = pollconn_operate(*(_QWORD *)(*(_QWORD *)(a1 + 48) + 8 * v1++));
while ( *(_DWORD *)(a1 + 56) > (int)v1 );
}
return result;
}

original_code:
void
pollset_operate(pollset *ps)
{
    int i;
    for(i=0; i<ps->handles_len; i++)
        pollconn_operate(ps->handles[i]);
}

canonical_original_code:
void pollset_operate(struct pollset *ps)
{
    int i;
    for(i=0; i<ps->handles_len; i++)
        pollconn_operate(ps->handles[i]);
}

variable_types: i int


decompiled_code:
void sighandler_term()
{
done = 1;
}

canonical_decompiled_code:
void func0()
{
done = 1;
}

original_code:
void
sighandler_term(int signum)
{
    done=1;
}

variable_types: signum int


decompiled_code:
__int64 __fastcall handle_packets(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4; // [rsp+14h] [rbp-14h] BYREF
int v5; // [rsp+18h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+1Ch] [rbp-Ch] BYREF

while ( 1 )
{
result = lineserver_getnextevent(a2, v6, &v5);
if ( (_DWORD)result != 1 )
return result;
switch ( v5 )
{
case 0:
puts("How the heck did this happen?");
break;
case 1:
printf("Closed connection %d.\n", v6[0]);
break;
case 2:
printf("Error on connection %d.\n", v6[0]);
perror("lineserver_test");
break;
case 3:
printf("Shutdown connection %d.\n", v6[0]);
lineserver_shutdown(a2, v6[0]);
break;
case 4:
lineserver_getline(a2, v6[0], &v3, &v4);
lineserver_enqueue(a2, v6[0], v3, v4);
break;
default:
break;
}
lineserver_dequeue(a2, v6[0]);
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4; // [rsp+14h] [rbp-14h] BYREF
int v5; // [rsp+18h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+1Ch] [rbp-Ch] BYREF

while ( 1 )
{
result = lineserver_getnextevent(a2, v6, &v5);
if ( (_DWORD)result != 1 )
return result;
switch ( v5 )
{
case 0:
puts("How the heck did this happen?");
break;
case 1:
printf("Closed connection %d.\n", v6[0]);
break;
case 2:
printf("Error on connection %d.\n", v6[0]);
perror("lineserver_test");
break;
case 3:
printf("Shutdown connection %d.\n", v6[0]);
lineserver_shutdown(a2, v6[0]);
break;
case 4:
lineserver_getline(a2, v6[0], &v3, &v4);
lineserver_enqueue(a2, v6[0], v3, v4);
break;
default:
break;
}
lineserver_dequeue(a2, v6[0]);
}
}

original_code:
void
handle_packets(client_list *cl, lineserver *ls)
{
    pollset_handle h;
    lineserver_event e;
    int len, ret;
    const char *packet;
    while((ret=lineserver_getnextevent(ls, &h, &e))==1)
    {
        switch(e)
        {
        case LINESERVER_LINE:
            lineserver_getline(ls, h, &packet, &len);
            lineserver_enqueue(ls, h, packet, len);
            break;
        case LINESERVER_SHUTDOWN:
            printf("Shutdown connection %d.\n", h);
            lineserver_shutdown(ls, h);
            break;
        case LINESERVER_CLOSED:
            printf("Closed connection %d.\n", h);
            break;
        case LINESERVER_ERROR:
            printf("Error on connection %d.\n", h);
            perror("lineserver_test");
            break;
        case LINESERVER_NULLEVENT:
            printf("How the heck did this happen?\n");
            break;
        }
        lineserver_dequeue(ls, h);
    }
}

canonical_original_code:
void handle_packets(struct client_list *cl, struct lineserver *ls)
{
    int h;
    enum lineserver_event e;
    int len; int ret;
    char *packet;
    while((ret=lineserver_getnextevent(ls, &h, &e))==1)
    {
        switch(e)
        {
        case LINESERVER_LINE:
            lineserver_getline(ls, h, &packet, &len);
            lineserver_enqueue(ls, h, packet, len);
            break;
        case LINESERVER_SHUTDOWN:
            printf("Shutdown connection %d.\n", h);
            lineserver_shutdown(ls, h);
            break;
        case LINESERVER_CLOSED:
            printf("Closed connection %d.\n", h);
            break;
        case LINESERVER_ERROR:
            printf("Error on connection %d.\n", h);
            perror("lineserver_test");
            break;
        case LINESERVER_NULLEVENT:
            printf("How the heck did this happen?\n");
            break;
        }
        lineserver_dequeue(ls, h);
    }
}

variable_types: struct client_list { int *handles; int len; } *

variable_types: struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; } *

variable_types: h int

variable_types: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 }

variable_types: len int

variable_types:
packet
char *

user_defined_types: struct lineserver { struct pollset ps; struct pollconn ls; struct lineserver_client *clients; int num_clients; int max_clients; int next_conn_pos; char delim; }


decompiled_code:
void *__fastcall client_list_construct(__int64 a1)
{
void *result; // rax

*(_DWORD *)(a1 + 8) = 0;
result = malloc(0x190uLL);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1)
{
void *result; // rax

*(_DWORD *)(a1 + 8) = 0;
result = malloc(0x190uLL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void
client_list_construct(client_list *cl)
{
    cl->len=0;
    cl->handles=(pollset_handle*)malloc(sizeof(pollset_handle)*100);
}

canonical_original_code:
void client_list_construct(struct client_list *cl)
{
    cl->len=0;
    cl->handles=(int *)malloc(sizeof(pollset_handle)*100);
}

user_defined_types: struct client_list { int *handles; int len; }


decompiled_code:
void __fastcall client_list_destruct(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
free(*(void **)a1);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
*(_DWORD *)(a1 + 8) = 0;
free(*(void **)a1);
}

original_code:
void
client_list_destruct(client_list *cl)
{
    cl->len=0;
    free(cl->handles);
}

canonical_original_code:
void client_list_destruct(struct client_list *cl)
{
    cl->len=0;
    free(cl->handles);
}


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

v2 = *a1;
v3 = *((_DWORD *)a1 + 2);
*((_DWORD *)a1 + 2) = v3 + 1;
*(_DWORD *)(v2 + 4LL * v3) = a2;
return *((unsigned int *)a1 + 2);
}

original_code:
int
client_list_add(client_list *cl, pollset_handle h)
{
    cl->handles[((cl->len)++)]=h;
    return cl->len;
}

canonical_original_code:
int client_list_add(struct client_list *cl, int h)
{
    cl->handles[((cl->len)++)]=h;
    return cl->len;
}


decompiled_code:
__int64 __fastcall client_list_del(__int64 a1, int a2)
{
int v2; // er8
_DWORD *v3; // rax
__int64 v4; // rdx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD **)a1;
v4 = 0LL;
while ( *v3 != a2 )
{
++v4;
++v3;
if ( v4 == v2 )
return 0xFFFFFFFFLL;
}
memmove(v3, (const void *)(*(_QWORD *)a1 + 4 * v4 + 4), 4LL * v2 - 1 - v4);
result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // er8
_DWORD *v3; // rax
__int64 v4; // rdx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD **)a1;
v4 = 0LL;
while ( *v3 != a2 )
{
++v4;
++v3;
if ( v4 == v2 )
return 0xFFFFFFFFLL;
}
memmove(v3, (const void *)(*(_QWORD *)a1 + 4 * v4 + 4), 4LL * v2 - 1 - v4);
result = (unsigned int)(*(_DWORD *)(a1 + 8) - 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
int
client_list_del(client_list *cl, pollset_handle h)
{
    int i;
    for(i=0; i<cl->len; i++)
    {
        if(cl->handles[i]==h)
        {
            memmove(cl->handles+i, cl->handles+i+1,
                    sizeof(pollset_handle)*cl->len-i-1);
            (cl->len)--;
            return cl->len;
        }
    }
    return -1;
}

canonical_original_code:
int client_list_del(struct client_list *cl, int h)
{
    int i;
    for(i=0; i<cl->len; i++)
    {
        if(cl->handles[i]==h)
        {
            memmove(cl->handles+i, cl->handles+i+1,
                    sizeof(pollset_handle)*cl->len-i-1);
            (cl->len)--;
            return cl->len;
        }
    }
    return -1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
__int64 v6[2]; // [rsp+0h] [rbp-428h] BYREF
struct pollfd fds; // [rsp+10h] [rbp-418h] BYREF
char v8[232]; // [rsp+340h] [rbp-E8h] BYREF

signal(13, (__sighandler_t)((char *)sighandler_term + 1));
signal(15, (__sighandler_t)sighandler_term);
lineserver_construct(v8, &fds, 101LL, 4096LL, 4096LL);
client_list_construct((__int64)v6);
if ( (unsigned int)lineserver_listen(v8, 7584LL) == -1 )
{
perror("lineserver bind() and listen()");
}
else
{
while ( !done )
{
if ( poll(&fds, 0x65uLL, 100) == -1 )
{
perror("lineserver poll()");
break;
}
lineserver_operate(v8);
handle_packets((__int64)v6, (__int64)v8);
v3 = lineserver_accept(v8);
v4 = v3;
if ( v3 != -1 )
{
printf("Added new connection %d.\n", v3);
client_list_add(v6, v4);
}
}
client_list_destruct((__int64)v6);
lineserver_destruct(v8);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
__int64 v6[2]; // [rsp+0h] [rbp-428h] BYREF
struct pollfd fds; // [rsp+10h] [rbp-418h] BYREF
char v8[232]; // [rsp+340h] [rbp-E8h] BYREF

signal(13, (__sighandler_t)((char *)sighandler_term + 1));
signal(15, (__sighandler_t)sighandler_term);
lineserver_construct(v8, &fds, 101LL, 4096LL, 4096LL);
func2((__int64)v6);
if ( (unsigned int)lineserver_listen(v8, 7584LL) == -1 )
{
perror("lineserver bind() and listen()");
}
else
{
while ( !done )
{
if ( poll(&fds, 0x65uLL, 100) == -1 )
{
perror("lineserver poll()");
break;
}
lineserver_operate(v8);
func1((__int64)v6, (__int64)v8);
v3 = lineserver_accept(v8);
v4 = v3;
if ( v3 != -1 )
{
printf("Added new connection %d.\n", v3);
func4(v6, v4);
}
}
func3((__int64)v6);
lineserver_destruct(v8);
}
return 0;
}

original_code:
int
main()
{
    lineserver ls;
    struct pollfd ufds[100 +1];
    client_list cl;
    pollset_handle h;
    signal(13, ((__sighandler_t) 1));
    signal(15, sighandler_term);
    lineserver_construct(&ls, ufds, 100 +1, 4096, 4096);
    client_list_construct(&cl);
    if(lineserver_listen(&ls, 7584)==-1)
    {
        perror("lineserver bind() and listen()");
        return 0;
    }
    while(!done)
    {
        if(poll(ufds, 100 +1, 100)==-1)
        {
            perror("lineserver poll()");
            break;
        }
        lineserver_operate(&ls);
        handle_packets(&cl, &ls);
        if((h=lineserver_accept(&ls))!=-1)
        {
            printf("Added new connection %d.\n", h);
            client_list_add(&cl, h);
        }
    }
    client_list_destruct(&cl);
    lineserver_destruct(&ls);
    return 0;
}

canonical_original_code:
int main()
{
    struct lineserver ls;
    struct pollfd ufds[-1];
    struct client_list cl;
    int h;
    signal(13, ((void (*)(int)) 1));
    signal(15, sighandler_term);
    lineserver_construct(&ls, ufds, 100 +1, 4096, 4096);
    client_list_construct(&cl);
    if(lineserver_listen(&ls, 7584)==-1)
    {
        perror("lineserver bind() and listen()");
        return 0;
    }
    while(!done)
    {
        if(poll(ufds, 100 +1, 100)==-1)
        {
            perror("lineserver poll()");
            break;
        }
        lineserver_operate(&ls);
        handle_packets(&cl, &ls);
        if((h=lineserver_accept(&ls))!=-1)
        {
            printf("Added new connection %d.\n", h);
            client_list_add(&cl, h);
        }
    }
    client_list_destruct(&cl);
    lineserver_destruct(&ls);
    return 0;
}

variable_types: struct lineserver { struct pollset { struct pollpool { int len; struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *pollconns; struct pollfd *ufds; int *freelist; int freelist_head; int freelist_len; int sendbuf_len; int recvbuf_len; } pp; struct pollconn **handles; int handles_len; } ps; struct pollconn ls; struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *clients; int num_clients; int max_clients; int next_conn_pos; char delim; }

variable_types: struct pollfd { int fd; short events; short revents; } [-1]

variable_types: struct client_list { int *handles; int len; }


decompiled_code:
__int64 __fastcall lineserver_getline_i(__int64 a1, int a2, __int64 *a3, _DWORD *a4)
{
__int64 result; // rax
unsigned int *v7; // r13
__int64 v8; // rax
__int64 v9; // rdx

result = 0xFFFFFFFFLL;
if ( a2 >= 0 )
{
v7 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
result = 0LL;
if ( (v7[1] & 0x80000000) == 0 )
{
v8 = pollset_conn(a1, *v7);
v9 = pollconn_recvbuf_data(v8);
result = 0LL;
if ( *(unsigned __int8 *)(v9 + (int)v7[1]) == *(char *)(a1 + 212) )
{
if ( a3 )
*a3 = v9;
result = 1LL;
if ( a4 )
{
*a4 = v7[1];
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 *a3, _DWORD *a4)
{
__int64 result; // rax
unsigned int *v7; // r13
__int64 v8; // rax
__int64 v9; // rdx

result = 0xFFFFFFFFLL;
if ( a2 >= 0 )
{
v7 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
result = 0LL;
if ( (v7[1] & 0x80000000) == 0 )
{
v8 = pollset_conn(a1, *v7);
v9 = pollconn_recvbuf_data(v8);
result = 0LL;
if ( *(unsigned __int8 *)(v9 + (int)v7[1]) == *(char *)(a1 + 212) )
{
if ( a3 )
*a3 = v9;
result = 1LL;
if ( a4 )
{
*a4 = v7[1];
result = 1LL;
}
}
}
}
return result;
}

original_code:
static int
lineserver_getline_i(const lineserver *l, int index,
                     const char **data, int *len)
{
    lineserver_client *lsc;
    pollconn *c;
    const u_char *t;
    if(index<0)
        return -1;
    lsc=l->clients+index;
    if(lsc->next_pos<0)
        return 0;
    c=pollset_conn(&l->ps, lsc->h);
    t=pollconn_recvbuf_data(c);
    if(t[lsc->next_pos]!=l->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lsc->next_pos;
    return 1;
}

canonical_original_code:
static int lineserver_getline_i(struct lineserver *l, int index, char **data, int *len)
{
    struct lineserver_client *lsc;
    struct pollconn *c;
    unsigned char *t;
    if(index<0)
        return -1;
    lsc=l->clients+index;
    if(lsc->next_pos<0)
        return 0;
    c=pollset_conn(&l->ps, lsc->h);
    t=pollconn_recvbuf_data(c);
    if(t[lsc->next_pos]!=l->delim)
        return 0;
    if(data)
        *data=t;
    if(len)
        *len=lsc->next_pos;
    return 1;
}

variable_types: index int

variable_types:
data
char **

variable_types:
len
int *

variable_types: struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; } *

variable_types:
t
unsigned char *


decompiled_code:
__int64 __fastcall lineserver_getevent_i(__int64 a1, int a2)
{
_DWORD *v2; // rbx
__int64 result; // rax
int v4; // edx

v2 = (_DWORD *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
result = 2LL;
if ( !v2[4] )
{
v4 = lineserver_getline_i(a1, a2, 0LL, 0LL);
result = 4LL;
if ( !v4 )
{
result = 3LL;
if ( !v2[3] )
result = v2[2] != 0;
}
}
return result;
}

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

v2 = (_DWORD *)(*(_QWORD *)(a1 + 192) + 20LL * a2);
result = 2LL;
if ( !v2[4] )
{
v4 = func4(a1, a2, 0LL, 0LL);
result = 4LL;
if ( !v4 )
{
result = 3LL;
if ( !v2[3] )
result = v2[2] != 0;
}
}
return result;
}

original_code:
static lineserver_event
lineserver_getevent_i(const lineserver *l, int index)
{
    lineserver_client *lsc;
    lsc=l->clients+index;
    if(lsc->error)
        return LINESERVER_ERROR;
    if(lineserver_getline_i(l, index, ((void *)0), ((void *)0)))
        return LINESERVER_LINE;
    if(lsc->shutdown)
        return LINESERVER_SHUTDOWN;
    if(lsc->closed)
        return LINESERVER_CLOSED;
    return LINESERVER_NULLEVENT;
}

canonical_original_code:
static enum lineserver_event lineserver_getevent_i(struct lineserver *l, int index)
{
    struct lineserver_client *lsc;
    lsc=l->clients+index;
    if(lsc->error)
        return LINESERVER_ERROR;
    if(lineserver_getline_i(l, index, ((void *)0), ((void *)0)))
        return LINESERVER_LINE;
    if(lsc->shutdown)
        return LINESERVER_SHUTDOWN;
    if(lsc->closed)
        return LINESERVER_CLOSED;
    return LINESERVER_NULLEVENT;
}

return_type: enum lineserver_event { LINESERVER_NULLEVENT=0, LINESERVER_CLOSED=1, LINESERVER_ERROR=2, LINESERVER_SHUTDOWN=3, LINESERVER_LINE=4 }

user_defined_types: struct lineserver_client { int h; int next_pos; int closed; int shutdown; int error; }


decompiled_code:
void *__fastcall lineserver_construct(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
void *result; // rax

*(_DWORD *)(a1 + 200) = 0;
*(_DWORD *)(a1 + 208) = -1;
*(_BYTE *)(a1 + 212) = 10;
if ( a3 <= 0 )
{
*(_DWORD *)(a1 + 204) = 0;
pollset_construct(a1, 0LL, 0LL);
result = (void *)pollconn_construct(a1 + 64, 0LL, 0LL, 0LL);
*(_QWORD *)(a1 + 192) = 0LL;
}
else
{
v3 = (unsigned int)(a3 - 1);
*(_DWORD *)(a1 + 204) = v3;
pollset_construct(a1, a2 + 8, v3);
pollconn_construct(a1 + 64, a2, 0LL, 0LL);
pollconn_socket(a1 + 64);
result = malloc(20LL * *(int *)(a1 + 204));
*(_QWORD *)(a1 + 192) = result;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
void *result; // rax

*(_DWORD *)(a1 + 200) = 0;
*(_DWORD *)(a1 + 208) = -1;
*(_BYTE *)(a1 + 212) = 10;
if ( a3 <= 0 )
{
*(_DWORD *)(a1 + 204) = 0;
pollset_construct(a1, 0LL, 0LL);
result = (void *)pollconn_construct(a1 + 64, 0LL, 0LL, 0LL);
*(_QWORD *)(a1 + 192) = 0LL;
}
else
{
v3 = (unsigned int)(a3 - 1);
*(_DWORD *)(a1 + 204) = v3;
pollset_construct(a1, a2 + 8, v3);
pollconn_construct(a1 + 64, a2, 0LL, 0LL);
pollconn_socket(a1 + 64);
result = malloc(20LL * *(int *)(a1 + 204));
*(_QWORD *)(a1 + 192) = result;
}
return result;
}

original_code:
void lineserver_construct(lineserver *l, struct pollfd *ufds, int len,
                          int sendbuf_len, int recvbuf_len)
{
    l->num_clients=0;
    l->next_conn_pos=-1;
    l->delim='\n';
    if(len<1)
    {
        l->max_clients=0;
        pollset_construct(&l->ps, ((void *)0), 0, sendbuf_len, recvbuf_len);
        pollconn_construct(&l->ls, ((void *)0), 0, 0);
        l->clients=((void *)0);
        return;
    }
    l->max_clients=len-1;
    pollset_construct(&l->ps, ufds+1, len-1, sendbuf_len, recvbuf_len);
    pollconn_construct(&l->ls, ufds, 0, 0);
    pollconn_socket(&l->ls);
    l->clients=(lineserver_client*)
        malloc(sizeof(lineserver_client)*l->max_clients);
}

canonical_original_code:
void lineserver_construct(struct lineserver *l, struct pollfd *ufds, int len, int sendbuf_len, int recvbuf_len)
{
    l->num_clients=0;
    l->next_conn_pos=-1;
    l->delim='\n';
    if(len<1)
    {
        l->max_clients=0;
        pollset_construct(&l->ps, ((void *)0), 0, sendbuf_len, recvbuf_len);
        pollconn_construct(&l->ls, ((void *)0), 0, 0);
        l->clients=((void *)0);
        return;
    }
    l->max_clients=len-1;
    pollset_construct(&l->ps, ufds+1, len-1, sendbuf_len, recvbuf_len);
    pollconn_construct(&l->ls, ufds, 0, 0);
    pollconn_socket(&l->ls);
    l->clients=(struct lineserver_client *)
        malloc(sizeof(lineserver_client)*l->max_clients);
}

variable_types:
ufds
struct pollfd *


decompiled_code:
__int64 __fastcall lineserver_destruct(__int64 a1)
{
pollconn_destruct(a1 + 64);
return pollset_destruct(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
pollconn_destruct(a1 + 64);
return pollset_destruct(a1);
}

original_code:
void lineserver_destruct(lineserver *l)
{
    pollconn_destruct(&l->ls);
    pollset_destruct(&l->ps);
}

canonical_original_code:
void lineserver_destruct(struct lineserver *l)
{
    pollconn_destruct(&l->ls);
    pollset_destruct(&l->ps);
}


decompiled_code:
__int64 __fastcall lineserver_listen(__int64 a1, unsigned __int16 a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = _bswap_32(*(_DWORD *)(a1 + 108));
pollconn_set_saddr(a1 + 64, v2, a2);
result = pollconn_bind(a1 + 64);
if ( (_DWORD)result != -1 )
result = pollconn_listen(a1 + 64);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int16 a2)
{
unsigned int v2; // eax
__int64 result; // rax

v2 = func1(*(_DWORD *)(a1 + 108));
pollconn_set_saddr(a1 + 64, v2, a2);
result = pollconn_bind(a1 + 64);
if ( (_DWORD)result != -1 )
result = pollconn_listen(a1 + 64);
return result;
}

original_code:
int lineserver_listen(lineserver *l, u_int16_t port)
{
    pollconn_set_saddr(&l->ls, ntohl(l->ls.saddr.sin_addr.s_addr), port);
    if(pollconn_bind(&l->ls)!=-1)
        return pollconn_listen(&l->ls);
    return -1;
}

canonical_original_code:
int lineserver_listen(struct lineserver *l, unsigned int port)
{
    pollconn_set_saddr(&l->ls, ntohl(l->ls.saddr.sin_addr.s_addr), port);
    if(pollconn_bind(&l->ls)!=-1)
        return pollconn_listen(&l->ls);
    return -1;
}

variable_types:
port
unsigned int


decompiled_code:
__int64 __fastcall lineserver_bind(__int64 a1, unsigned int a2)
{
unsigned __int16 v2; // ax

v2 = _bswap_16(*(_WORD *)(a1 + 106));
pollconn_set_saddr(a1 + 64, a2, v2);
return pollconn_bind(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
unsigned __int16 v2; // ax

v2 = func2(*(_WORD *)(a1 + 106));
pollconn_set_saddr(a1 + 64, a2, v2);
return pollconn_bind(a1 + 64);
}

original_code:
int lineserver_bind(lineserver *l, u_int32_t ip_addr)
{
    pollconn_set_saddr(&l->ls, ip_addr, ntohs(l->ls.saddr.sin_port));
    return pollconn_bind(&l->ls);
}

canonical_original_code:
int lineserver_bind(struct lineserver *l, unsigned int ip_addr)
{
    pollconn_set_saddr(&l->ls, ip_addr, ntohs(l->ls.saddr.sin_port));
    return pollconn_bind(&l->ls);
}


decompiled_code:
__int64 __fastcall lineserver_operate(__int64 a1)
{
__int64 v1; // rbp
unsigned int *v2; // r13
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

*(_DWORD *)(a1 + 208) = -1;
pollset_operate();
if ( *(int *)(a1 + 200) > 0 )
{
v1 = 0LL;
do
{
v2 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20 * v1);
advance_client_pos(a1, v1);
v3 = pollset_conn(a1, *v2);
if ( (unsigned int)pollconn_did_close(v3) )
v2[2] = 1;
if ( (unsigned int)pollconn_did_recv(v3) )
{
if ( !(unsigned int)pollconn_recv_bytes(v3) )
v2[3] = 1;
v4 = pollconn_err_recv(v3);
if ( v4 )
v2[4] = v4;
}
if ( (unsigned int)pollconn_did_send(v3) )
{
v5 = pollconn_err_send(v3);
if ( v5 )
v2[4] = v5;
}
if ( (unsigned int)pollconn_did_shutdown(v3) )
{
v6 = pollconn_err_shutdown(v3);
if ( v6 )
v2[4] = v6;
}
++v1;
}
while ( *(_DWORD *)(a1 + 200) > (int)v1 );
}
return advance_next_conn(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbp
unsigned int *v2; // r13
__int64 v3; // rbx
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax

*(_DWORD *)(a1 + 208) = -1;
pollset_operate();
if ( *(int *)(a1 + 200) > 0 )
{
v1 = 0LL;
do
{
v2 = (unsigned int *)(*(_QWORD *)(a1 + 192) + 20 * v1);
func3(a1, v1);
v3 = pollset_conn(a1, *v2);
if ( (unsigned int)pollconn_did_close(v3) )
v2[2] = 1;
if ( (unsigned int)pollconn_did_recv(v3) )
{
if ( !(unsigned int)pollconn_recv_bytes(v3) )
v2[3] = 1;
v4 = pollconn_err_recv(v3);
if ( v4 )
v2[4] = v4;
}
if ( (unsigned int)pollconn_did_send(v3) )
{
v5 = pollconn_err_send(v3);
if ( v5 )
v2[4] = v5;
}
if ( (unsigned int)pollconn_did_shutdown(v3) )
{
v6 = pollconn_err_shutdown(v3);
if ( v6 )
v2[4] = v6;
}
++v1;
}
while ( *(_DWORD *)(a1 + 200) > (int)v1 );
}
return func6(a1);
}

original_code:
void lineserver_operate(lineserver *l)
{
    int i, error;
    lineserver_client *lsc;
    pollconn *c;
    l->next_conn_pos=-1;
    pollset_operate(&l->ps);
    for(i=0; i<l->num_clients; i++)
    {
        lsc=l->clients+i;
        advance_client_pos(l, i);
        c=pollset_conn(&l->ps, lsc->h);
        if(pollconn_did_close(c))
        {
            lsc->closed=1;
        }
        if(pollconn_did_recv(c))
        {
            if(pollconn_recv_bytes(c)==0)
            {
                lsc->shutdown=1;
            }
            error=pollconn_err_recv(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_send(c))
        {
            error=pollconn_err_send(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_shutdown(c))
        {
            error=pollconn_err_shutdown(c);
            if(error!=0)
                lsc->error=error;
        }
    }
    advance_next_conn(l);
}

canonical_original_code:
void lineserver_operate(struct lineserver *l)
{
    int i; int error;
    struct lineserver_client *lsc;
    struct pollconn *c;
    l->next_conn_pos=-1;
    pollset_operate(&l->ps);
    for(i=0; i<l->num_clients; i++)
    {
        lsc=l->clients+i;
        advance_client_pos(l, i);
        c=pollset_conn(&l->ps, lsc->h);
        if(pollconn_did_close(c))
        {
            lsc->closed=1;
        }
        if(pollconn_did_recv(c))
        {
            if(pollconn_recv_bytes(c)==0)
            {
                lsc->shutdown=1;
            }
            error=pollconn_err_recv(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_send(c))
        {
            error=pollconn_err_send(c);
            if(error!=0)
                lsc->error=error;
        }
        if(pollconn_did_shutdown(c))
        {
            error=pollconn_err_shutdown(c);
            if(error!=0)
                lsc->error=error;
        }
    }
    advance_next_conn(l);
}

variable_types: i int

variable_types: error int

variable_types: struct pollconn { struct pollsock { struct pollfd { int fd; short events; short revents; } *pfd; struct tcpbuf { int len; int pos; unsigned char *data; } sendbuf; struct tcpbuf recvbuf; } s; 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]; } saddr; unsigned int saddr_len; struct sockaddr_in daddr; unsigned int daddr_len; struct pollconn_flags { unsigned int bound; unsigned int connected; unsigned int connecting; unsigned int listening; unsigned int recvdone; unsigned int senddone; unsigned int finsent; unsigned int did_accept; unsigned int did_bind; unsigned int did_close; unsigned int did_connect; unsigned int did_recv; unsigned int did_send; unsigned int did_shutdown; unsigned int saddr_dirty; unsigned int padding; } flags; int ret_accept; int ret_send; int ret_recv; int err_accept; int err_bind; int err_close; int err_connect; int err_recv; int err_send; int err_shutdown; } *