decompiled_code:
int erase_prompt()
{
fputs(erase_string, outfp);
return fflush(outfp);
}

canonical_decompiled_code:
int func2()
{
fputs(erase_string, outfp);
return fflush(outfp);
}

original_code:
static void erase_prompt(void)
{
  fputs(erase_string, outfp);
  fflush(outfp);
}

canonical_original_code:
static void erase_prompt()
{
  fputs(erase_string, outfp);
  fflush(outfp);
}


repo: cherry-wb/strmat

decompiled_code:
int print_prompt()
{
fputs(prompt_string, outfp);
return fflush(outfp);
}

canonical_decompiled_code:
int func3()
{
fputs(prompt_string, outfp);
return fflush(outfp);
}

original_code:
static void print_prompt(void)
{
  fputs(prompt_string, outfp);
  fflush(outfp);
}

canonical_original_code:
static void print_prompt()
{
  fputs(prompt_string, outfp);
  fflush(outfp);
}

return_type: void


decompiled_code:
void __fastcall restore_handler(int a1)
{
int v1; // ebp

if ( more_mode != 2 || lines_to_go )
{
if ( term_set )
{
LABEL_8:
tcsetattr(infd, 0, &oldterm);
term_set = 0;
goto LABEL_3;
}
}
else
{
erase_prompt();
if ( term_set )
goto LABEL_8;
}
LABEL_3:
signal(a1, *(&handlers + a1));
kill(0, a1);
signal(a1, restore_handler);
if ( tty_flag )
{
v1 = more_mode;
if ( more_mode )
{
term_set = 1;
tcsetattr(infd, 0, &term);
if ( v1 == 2 && !lines_to_go )
print_prompt();
}
}
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
int v1; // ebp

if ( more_mode != 2 || lines_to_go )
{
if ( term_set )
{
LABEL_8:
tcsetattr(infd, 0, &oldterm);
term_set = 0;
goto LABEL_3;
}
}
else
{
func2();
if ( term_set )
goto LABEL_8;
}
LABEL_3:
signal(a1, *(&handlers + a1));
kill(0, a1);
signal(a1, restore_handler);
if ( tty_flag )
{
v1 = more_mode;
if ( more_mode )
{
term_set = 1;
tcsetattr(infd, 0, &term);
if ( v1 == 2 && !lines_to_go )
func3();
}
}
}

original_code:
static void restore_handler(int sig, int code)
{
  if (more_mode == MOREOUTPUT && lines_to_go == 0)
    erase_prompt();
  if (term_set) {
    tcsetattr(infd, 0, &oldterm);
    term_set = 0;
  }
  signal(sig, handlers[sig]);
  kill (0, sig);
  signal(sig, (void (*)()) restore_handler);
  if (tty_flag && more_mode != NOTSTARTED) {
    term_set = 1;
    tcsetattr(infd, 0, &term);
    if (more_mode == MOREOUTPUT && lines_to_go == 0) {
      print_prompt();
    }
  }
}

variable_types: sig int

variable_types: code int


decompiled_code:
__int64 prompt_for_more()
{
FILE *i; // rbp
char j; // al
__int64 result; // rax

print_prompt();
for ( i = infp; ; clearerr(i) )
{
LABEL_2:
for ( j = fgetc(i); j != -1; j = fgetc(infp) )
{
if ( j <= 113 )
{
if ( j > 62 )
{
switch ( j )
{
case '?':
case 'H':
case 'h':
fputc(10, outfp);
fwrite("<space> Display next screenful\n", 1uLL, 0x2CuLL, outfp);
fwrite("<return> Display next line\n", 1uLL, 0x27uLL, outfp);
fwrite("d or D or ctrl-D Display next half screenful\n", 1uLL, 0x31uLL, outfp);
fwrite("h or H or ? Display this message\n", 1uLL, 0x2AuLL, outfp);
fwrite("q or Q End text display\n", 1uLL, 0x26uLL, outfp);
print_prompt();
i = infp;
goto LABEL_2;
case 'D':
case 'd':
goto LABEL_20;
case 'Q':
case 'q':
erase_prompt();
if ( quitfn )
quitfn();
more_mode = 3;
result = 0LL;
break;
default:
continue;
}
return result;
}
switch ( j )
{
case 10:
lines_to_go = 1;
erase_prompt();
return 1LL;
case 32:
lines_to_go = num_rows;
goto LABEL_8;
case 4:
LABEL_20:
lines_to_go = num_rows / 2;
erase_prompt();
return 1LL;
}
}
}
i = infp;
if ( !ferror(infp) || *_errno_location() != 4 )
break;
}
lines_to_go = -1;
more_mode = 1;
if ( tty_flag )
restore_tty();
LABEL_8:
erase_prompt();
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
FILE *i; // rbp
char j; // al
__int64 result; // rax

func3();
for ( i = infp; ; clearerr(i) )
{
LABEL_2:
for ( j = fgetc(i); j != -1; j = fgetc(infp) )
{
if ( j <= 113 )
{
if ( j > 62 )
{
switch ( j )
{
case '?':
case 'H':
case 'h':
fputc(10, outfp);
fwrite("<space> Display next screenful\n", 1uLL, 0x2CuLL, outfp);
fwrite("<return> Display next line\n", 1uLL, 0x27uLL, outfp);
fwrite("d or D or ctrl-D Display next half screenful\n", 1uLL, 0x31uLL, outfp);
fwrite("h or H or ? Display this message\n", 1uLL, 0x2AuLL, outfp);
fwrite("q or Q End text display\n", 1uLL, 0x26uLL, outfp);
func3();
i = infp;
goto LABEL_2;
case 'D':
case 'd':
goto LABEL_20;
case 'Q':
case 'q':
func2();
if ( quitfn )
quitfn();
more_mode = 3;
result = 0LL;
break;
default:
continue;
}
return result;
}
switch ( j )
{
case 10:
lines_to_go = 1;
func2();
return 1LL;
case 32:
lines_to_go = num_rows;
goto LABEL_8;
case 4:
LABEL_20:
lines_to_go = num_rows / 2;
func2();
return 1LL;
}
}
}
i = infp;
if ( !ferror(infp) || *_errno_location() != 4 )
break;
}
lines_to_go = -1;
more_mode = 1;
if ( tty_flag )
func1();
LABEL_8:
func2();
return 1LL;
}

original_code:
static int prompt_for_more(void)
{
  char ch;
  print_prompt();
  while (1) {
    if ((ch = fgetc(infp)) == (-1)) {
      if (ferror(infp) && (*__errno_location ()) == 4) {
        clearerr(infp);
        continue;
      }
      else {
        lines_to_go = -1;
        more_mode = SIMPLEOUTPUT;
        if (tty_flag)
          restore_tty();
        break;
      }
    }
    switch (ch) {
    case ' ':
      lines_to_go = num_rows;
      goto LOOP_END;
    case 'h':
    case 'H':
    case '?':
      fputc('\n', outfp);
      fputs("<space>              Display next screenful\n", outfp);
      fputs("<return>             Display next line\n", outfp);
      fputs("d or D or ctrl-D     Display next half screenful\n", outfp);
      fputs("h or H or ?          Display this message\n", outfp);
      fputs("q or Q               End text display\n", outfp);
      print_prompt();
      break;
    case '\n':
      lines_to_go = 1;
      goto LOOP_END;
    case 'd':
    case 'D':
    case '\004':
      lines_to_go = num_rows / 2;
      goto LOOP_END;
    case 'q':
    case 'Q':
      erase_prompt();
      if (quitfn != ((void *)0))
        (*quitfn)();
      more_mode = SKIPOUTPUT;
      return 0;
    }
  }
LOOP_END:
  erase_prompt();
  return 1;
}

canonical_original_code:
static int prompt_for_more()
{
  char ch;
  print_prompt();
  while (1) {
    if ((ch = fgetc(infp)) == (-1)) {
      if (ferror(infp) && (*__errno_location ()) == 4) {
        clearerr(infp);
        continue;
      }
      else {
        lines_to_go = -1;
        more_mode = SIMPLEOUTPUT;
        if (tty_flag)
          restore_tty();
        break;
      }
    }
    switch (ch) {
    case ' ':
      lines_to_go = num_rows;
      goto LOOP_END;
    case 'h':
    case 'H':
    case '?':
      fputc('\n', outfp);
      fputs("<space>              Display next screenful\n", outfp);
      fputs("<return>             Display next line\n", outfp);
      fputs("d or D or ctrl-D     Display next half screenful\n", outfp);
      fputs("h or H or ?          Display this message\n", outfp);
      fputs("q or Q               End text display\n", outfp);
      print_prompt();
      break;
    case '\n':
      lines_to_go = 1;
      goto LOOP_END;
    case 'd':
    case 'D':
    case '\004':
      lines_to_go = num_rows / 2;
      goto LOOP_END;
    case 'q':
    case 'Q':
      erase_prompt();
      if (quitfn != ((void *)0))
        (*quitfn)();
      more_mode = SKIPOUTPUT;
      return 0;
    }
  }
LOOP_END:
  erase_prompt();
  return 1;
}

variable_types: ch char

return_type: int


mputc

decompiled_code:
__int64 __fastcall mputc(char a1)
{
if ( more_mode != 2 )
{
if ( (unsigned int)more_mode > 2 )
return more_mode != 3;
if ( more_mode )
{
if ( fputc(a1, outfp) != -1 )
return 1LL;
}
else if ( fputc(a1, stdout) != -1 )
{
return 1LL;
}
return 0xFFFFFFFFLL;
}
if ( fputc(a1, outfp) == -1 )
return 0xFFFFFFFFLL;
if ( a1 != 10 )
return 1LL;
if ( --lines_to_go )
return 1LL;
return (unsigned int)prompt_for_more() != 0;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
if ( more_mode != 2 )
{
if ( (unsigned int)more_mode > 2 )
return more_mode != 3;
if ( more_mode )
{
if ( fputc(a1, outfp) != -1 )
return 1LL;
}
else if ( fputc(a1, stdout) != -1 )
{
return 1LL;
}
return 0xFFFFFFFFLL;
}
if ( fputc(a1, outfp) == -1 )
return 0xFFFFFFFFLL;
if ( a1 != 10 )
return 1LL;
if ( --lines_to_go )
return 1LL;
return (unsigned int)func5() != 0;
}

original_code:
int mputc(char c)
{
  switch (more_mode) {
  case NOTSTARTED:
    if (fputc(c, stdout) == (-1))
      return (-1);
    break;
  case SIMPLEOUTPUT:
    if (fputc(c, outfp) == (-1))
      return (-1);
    break;
  case MOREOUTPUT:
    if (fputc(c, outfp) == (-1))
      return (-1);
    if (c == '\n' && --lines_to_go == 0 && prompt_for_more() == 0)
      return 0;
    break;
  case SKIPOUTPUT:
    return 0;
  }
  return 1;
}

variable_types: c char


mputs

decompiled_code:
__int64 __fastcall mputs(const char *a1)
{
__int64 result; // rax
char *v2; // rbx
char v3; // al
bool v4; // zf
char v5; // bp

if ( more_mode == 2 )
{
v2 = (char *)(a1 + 1);
if ( !*a1 )
return 1LL;
if ( *a1 == 10 )
goto LABEL_14;
LABEL_12:
while ( 1 )
{
v3 = *v2++;
if ( !v3 )
break;
while ( v3 == 10 )
{
LABEL_14:
v4 = lines_to_go-- == 1;
v5 = *v2;
if ( !v4 )
goto LABEL_12;
*v2 = 0;
if ( fputs(a1, outfp) == -1 )
return 0xFFFFFFFFLL;
*v2 = v5;
result = prompt_for_more();
if ( !(_DWORD)result )
return result;
v3 = *v2;
a1 = v2++;
if ( !v3 )
goto LABEL_18;
}
}
LABEL_18:
if ( *a1 )
goto LABEL_4;
result = 1LL;
}
else
{
if ( (unsigned int)more_mode <= 2 )
{
if ( !more_mode )
{
if ( fputs(a1, stdout) != -1 )
return 1LL;
return 0xFFFFFFFFLL;
}
LABEL_4:
if ( fputs(a1, outfp) != -1 )
return 1LL;
return 0xFFFFFFFFLL;
}
result = more_mode != 3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
__int64 result; // rax
char *v2; // rbx
char v3; // al
bool v4; // zf
char v5; // bp

if ( more_mode == 2 )
{
v2 = (char *)(a1 + 1);
if ( !*a1 )
return 1LL;
if ( *a1 == 10 )
goto LABEL_14;
LABEL_12:
while ( 1 )
{
v3 = *v2++;
if ( !v3 )
break;
while ( v3 == 10 )
{
LABEL_14:
v4 = lines_to_go-- == 1;
v5 = *v2;
if ( !v4 )
goto LABEL_12;
*v2 = 0;
if ( fputs(a1, outfp) == -1 )
return 0xFFFFFFFFLL;
*v2 = v5;
result = func5();
if ( !(_DWORD)result )
return result;
v3 = *v2;
a1 = v2++;
if ( !v3 )
goto LABEL_18;
}
}
LABEL_18:
if ( *a1 )
goto LABEL_4;
result = 1LL;
}
else
{
if ( (unsigned int)more_mode <= 2 )
{
if ( !more_mode )
{
if ( fputs(a1, stdout) != -1 )
return 1LL;
return 0xFFFFFFFFLL;
}
LABEL_4:
if ( fputs(a1, outfp) != -1 )
return 1LL;
return 0xFFFFFFFFLL;
}
result = more_mode != 3;
}
return result;
}

original_code:
int mputs(char *s)
{
  char ch, *t;
  switch (more_mode) {
  case NOTSTARTED:
    if (fputs(s, stdout) == (-1))
      return (-1);
    break;
  case SIMPLEOUTPUT:
    if (fputs(s, outfp) == (-1))
      return (-1);
    break;
  case MOREOUTPUT:
    for (t=s; *t; t++) {
      if (*t == '\n' && --lines_to_go == 0) {
        ch = *(t+1);
        *(t+1) = '\0';
        if (fputs(s, outfp) == (-1))
          return (-1);
        *(t+1) = ch;
        if (!prompt_for_more())
          return 0;
        s = t + 1;
      }
    }
    if (*s && fputs(s, outfp) == (-1))
      return (-1);
    break;
  case SKIPOUTPUT:
    return 0;
  }
  return 1;
}

canonical_original_code:
int mputs(char *s)
{
  char ch; char *t;
  switch (more_mode) {
  case NOTSTARTED:
    if (fputs(s, stdout) == (-1))
      return (-1);
    break;
  case SIMPLEOUTPUT:
    if (fputs(s, outfp) == (-1))
      return (-1);
    break;
  case MOREOUTPUT:
    for (t=s; *t; t++) {
      if (*t == '\n' && --lines_to_go == 0) {
        ch = *(t+1);
        *(t+1) = '\0';
        if (fputs(s, outfp) == (-1))
          return (-1);
        *(t+1) = ch;
        if (!prompt_for_more())
          return 0;
        s = t + 1;
      }
    }
    if (*s && fputs(s, outfp) == (-1))
      return (-1);
    break;
  case SKIPOUTPUT:
    return 0;
  }
  return 1;
}

variable_types:
s
char *

variable_types:
t
char *


mprintf

decompiled_code:
__int64 mprintf(char *format, ...)
{
__int64 result; // rax
char v2; // al
char *v3; // rbx
const char *v4; // rdi
bool v5; // zf
char v6; // bp
FILE *v7; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( more_mode == 2 )
{
va_start(arg, format);
if ( vsprintf(&spf_buffer, format, arg) < 0 )
goto LABEL_20;
v2 = spf_buffer;
if ( !spf_buffer )
goto LABEL_17;
v3 = s;
v4 = &spf_buffer;
do
{
while ( 1 )
{
if ( v2 == 10 )
{
v5 = lines_to_go-- == 1;
v6 = *v3;
if ( v5 )
break;
}
v2 = *v3++;
if ( !v2 )
goto LABEL_16;
}
v7 = outfp;
*v3 = 0;
if ( fputs(v4, v7) == -1 )
goto LABEL_20;
*v3 = v6;
result = prompt_for_more();
if ( !(_DWORD)result )
return result;
v2 = *v3;
v4 = v3++;
}
while ( v2 );
LABEL_16:
if ( *v4 && fputs(v4, outfp) == -1 )
LABEL_20:
result = 0xFFFFFFFFLL;
else
LABEL_17:
result = 1LL;
}
else if ( (unsigned int)more_mode > 2 )
{
result = more_mode != 3;
}
else if ( more_mode )
{
va_start(arg, format);
vfprintf(outfp, format, arg);
result = 1LL;
}
else
{
va_start(arg, format);
vfprintf(stdout, format, arg);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func9(char *format, ...)
{
__int64 result; // rax
char v2; // al
char *v3; // rbx
const char *v4; // rdi
bool v5; // zf
char v6; // bp
FILE *v7; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

if ( more_mode == 2 )
{
va_start(arg, format);
if ( vsprintf(&spf_buffer, format, arg) < 0 )
goto LABEL_20;
v2 = spf_buffer;
if ( !spf_buffer )
goto LABEL_17;
v3 = s;
v4 = &spf_buffer;
do
{
while ( 1 )
{
if ( v2 == 10 )
{
v5 = lines_to_go-- == 1;
v6 = *v3;
if ( v5 )
break;
}
v2 = *v3++;
if ( !v2 )
goto LABEL_16;
}
v7 = outfp;
*v3 = 0;
if ( fputs(v4, v7) == -1 )
goto LABEL_20;
*v3 = v6;
result = func5();
if ( !(_DWORD)result )
return result;
v2 = *v3;
v4 = v3++;
}
while ( v2 );
LABEL_16:
if ( *v4 && fputs(v4, outfp) == -1 )
LABEL_20:
result = 0xFFFFFFFFLL;
else
LABEL_17:
result = 1LL;
}
else if ( (unsigned int)more_mode > 2 )
{
result = more_mode != 3;
}
else if ( more_mode )
{
va_start(arg, format);
vfprintf(outfp, format, arg);
result = 1LL;
}
else
{
va_start(arg, format);
vfprintf(stdout, format, arg);
result = 1LL;
}
return result;
}

original_code:
int mprintf(char *format, ...)
{
  va_list ap;
  char ch, *s, *t;
  switch (more_mode) {
  case NOTSTARTED:
    __builtin_va_start(ap,format);
    vfprintf(stdout, format, ap);
    break;
  case SIMPLEOUTPUT:
    __builtin_va_start(ap,format);
    vfprintf(outfp, format, ap);
    break;
  case MOREOUTPUT:
    __builtin_va_start(ap,format);
    if (vsprintf(spf_buffer, format, ap) < 0)
      return (-1);
    s = spf_buffer;
    for (t=s; *t; t++) {
      if (*t == '\n' && --lines_to_go == 0) {
        ch = *(t+1);
        *(t+1) = '\0';
        if (fputs(s, outfp) == (-1))
          return (-1);
        *(t+1) = ch;
        if (!prompt_for_more())
          return 0;
        s = t + 1;
      }
    }
    if (*s && fputs(s, outfp) == (-1))
      return (-1);
    break;
  case SKIPOUTPUT:
    return 0;
  }
  return 1;
}

canonical_original_code:
int mprintf(char *format, ...)
{
  __builtin_va_list ap;
  char ch; char *s; char *t;
  switch (more_mode) {
  case NOTSTARTED:
    __builtin_va_start(ap,format);
    vfprintf(stdout, format, ap);
    break;
  case SIMPLEOUTPUT:
    __builtin_va_start(ap,format);
    vfprintf(outfp, format, ap);
    break;
  case MOREOUTPUT:
    __builtin_va_start(ap,format);
    if (vsprintf(spf_buffer, format, ap) < 0)
      return (-1);
    s = spf_buffer;
    for (t=s; *t; t++) {
      if (*t == '\n' && --lines_to_go == 0) {
        ch = *(t+1);
        *(t+1) = '\0';
        if (fputs(s, outfp) == (-1))
          return (-1);
        *(t+1) = ch;
        if (!prompt_for_more())
          return 0;
        s = t + 1;
      }
    }
    if (*s && fputs(s, outfp) == (-1))
      return (-1);
    break;
  case SKIPOUTPUT:
    return 0;
  }
  return 1;
}

variable_types:
format
char *


mend

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

result = more_mode;
if ( more_mode )
{
if ( more_mode == 2 && a1 > 0 )
{
if ( lines_to_go + 1 >= a1 )
{
result = tty_flag;
if ( !tty_flag )
{
LABEL_6:
more_mode = 0;
return result;
}
LABEL_10:
result = restore_tty();
goto LABEL_6;
}
prompt_string = "--End--";
erase_string = "\b \b\b \b\b \b\b \b\b \b\b \b\b \b";
result = prompt_for_more();
prompt_string = "--More--";
erase_string = "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b";
}
if ( !tty_flag )
goto LABEL_6;
result = more_mode - 2;
if ( (unsigned int)(more_mode - 2) > 1 )
goto LABEL_6;
goto LABEL_10;
}
return result;
}

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

result = more_mode;
if ( more_mode )
{
if ( more_mode == 2 && a1 > 0 )
{
if ( lines_to_go + 1 >= a1 )
{
result = tty_flag;
if ( !tty_flag )
{
LABEL_6:
more_mode = 0;
return result;
}
LABEL_10:
result = func1();
goto LABEL_6;
}
prompt_string = "--End--";
erase_string = "\b \b\b \b\b \b\b \b\b \b\b \b\b \b";
result = func5();
prompt_string = "--More--";
erase_string = "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b";
}
if ( !tty_flag )
goto LABEL_6;
result = more_mode - 2;
if ( (unsigned int)(more_mode - 2) > 1 )
goto LABEL_6;
goto LABEL_10;
}
return result;
}

original_code:
void mend(int follow_lines)
{
  if (more_mode == NOTSTARTED)
    return;
  if (more_mode == MOREOUTPUT && follow_lines > 0 &&
      follow_lines >= lines_to_go + 2) {
    prompt_string = endprompt;
    erase_string = enderase;
    prompt_for_more();
    prompt_string = regprompt;
    erase_string = regerase;
  }
  if (tty_flag && (more_mode == MOREOUTPUT || more_mode == SKIPOUTPUT))
    restore_tty();
  more_mode = NOTSTARTED;
}


decompiled_code:
void *create_seq_array()
{
void *result; // rax

seqsize = 40;
num_seqs = 0;
sequences = calloc(0x140uLL, 1uLL);
if ( !sequences || (result = calloc(0xA0uLL, 1uLL), (marks = result) == 0LL) )
{
fwrite("malloc failed while initializing array of sequences.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
return result;
}

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

seqsize = 40;
num_seqs = 0;
sequences = calloc(0x140uLL, 1uLL);
if ( !sequences || (result = calloc(0xA0uLL, 1uLL), (marks = result) == 0LL) )
{
fwrite("malloc failed while initializing array of sequences.\n", 1uLL, 0x35uLL, stderr);
exit(1);
}
return result;
}

original_code:
void create_seq_array()
{
  int i;
  seqsize = 40;
  num_seqs = 0;
  if ((sequences = malloc(seqsize * sizeof(STRING *))) == ((void *)0)) {
    fprintf(stderr, "malloc failed while initializing array of sequences.\n");
    exit(1);
  }
  if ((marks = malloc(seqsize * sizeof(int))) == ((void *)0)) {
    fprintf(stderr, "malloc failed while initializing array of sequences.\n");
    exit(1);
  }
  for (i=0; i < seqsize; i++) {
    sequences[i] = ((void *)0);
    marks[i] = 0;
  }
}

canonical_original_code:
void create_seq_array()
{
  int i;
  seqsize = 40;
  num_seqs = 0;
  if ((sequences = malloc(seqsize * sizeof(struct STRING *))) == ((void *)0)) {
    fprintf(stderr, "malloc failed while initializing array of sequences.\n");
    exit(1);
  }
  if ((marks = malloc(seqsize * sizeof(int))) == ((void *)0)) {
    fprintf(stderr, "malloc failed while initializing array of sequences.\n");
    exit(1);
  }
  for (i=0; i < seqsize; i++) {
    sequences[i] = ((void *)0);
    marks[i] = 0;
  }
}

variable_types: i int

user_defined_types: struct STRING { char *sequence; int length; int alpha_size; char ident[-1]; }


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

result = 0LL;
if ( a1 > 0 && num_seqs >= a1 )
result = *((_QWORD *)sequences + a1 - 1);
return result;
}

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

result = 0LL;
if ( a1 > 0 && num_seqs >= a1 )
result = *((_QWORD *)sequences + a1 - 1);
return result;
}

canonical_original_code:
struct STRING *get_element(int num)
{
  if (num >= 1 && num <= num_seqs)
    return sequences[num-1];
  else
    return ((void *)0);
}

variable_types: num int

return_type: struct STRING { char *sequence; int length; int alpha_size; char ident[-1]; } *


decompiled_code:
__int64 get_num_sequences()
{
return (unsigned int)num_seqs;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)num_seqs;
}

original_code:
int get_num_sequences()
{
  return num_seqs;
}


decompiled_code:
void *__fastcall set_mark(int a1, int a2)
{
void *result; // rax

if ( a1 > 0 && num_seqs >= a1 )
{
result = marks;
*((_DWORD *)marks + a1 - 1) = a2;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(int a1, int a2)
{
void *result; // rax

if ( a1 > 0 && num_seqs >= a1 )
{
result = marks;
*((_DWORD *)marks + a1 - 1) = a2;
}
return result;
}

original_code:
void set_mark(int num, int value)
{
   if (num >= 1 && num <= num_seqs)
    marks[num-1] = value;
}

variable_types: value int


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

result = 0LL;
if ( a1 > 0 && num_seqs >= a1 )
result = *((unsigned int *)marks + a1 - 1);
return result;
}

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

result = 0LL;
if ( a1 > 0 && num_seqs >= a1 )
result = *((unsigned int *)marks + a1 - 1);
return result;
}

original_code:
int get_mark(int num)
{
  if (num >= 1 && num <= num_seqs)
    return marks[num-1];
  else
    return 0;
}


decompiled_code:
void *init_string()
{
return calloc(0x128uLL, 1uLL);
}

canonical_decompiled_code:
void *func5()
{
return calloc(0x128uLL, 1uLL);
}

original_code:
STRING *init_string()
{
  STRING *sptr;
  if ((sptr = malloc(sizeof(STRING))) == ((void *)0))
    return ((void *)0);
  memset(sptr, 0, sizeof(STRING));
  return sptr;
}

canonical_original_code:
struct STRING *init_string()
{
  struct STRING *sptr;
  if ((sptr = malloc(sizeof(STRING))) == ((void *)0))
    return ((void *)0);
  memset(sptr, 0, sizeof(STRING));
  return sptr;
}

variable_types: struct STRING { char *sequence; int length; int alpha_size; char ident[-1]; } *


decompiled_code:
__int64 add_element()
{
__int64 v0; // r13
_QWORD *v1; // rbp
_DWORD *v2; // r12
int v3; // ebx
__int64 result; // rax
int v5; // er14
void *v6; // rax
unsigned __int64 v7; // r15
char *v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rsi
__int64 v13; // r14

v0 = num_seqs;
v1 = sequences;
v2 = marks;
v3 = num_seqs;
if ( num_seqs != seqsize )
{
LABEL_2:
v1[v0] = init_string();
result = (unsigned int)(v3 + 1);
v2[v0] = 0;
num_seqs = v3 + 1;
return result;
}
v5 = 2 * num_seqs;
seqsize = 2 * num_seqs;
sequences = realloc(sequences, 16LL * num_seqs);
v1 = sequences;
if ( sequences )
{
v6 = realloc(marks, 4LL * v5);
marks = v6;
v2 = v6;
if ( v6 )
{
if ( (int)v0 < v5 )
{
v7 = (unsigned __int64)v6 + 4 * v0;
v8 = (char *)&v1[v0];
v9 = v0;
v10 = (unsigned int)(v5 - v0 - 1);
v11 = v0 + 1;
v12 = v0 + 1 + v10;
if ( v7 < (unsigned __int64)&v1[v12] && v8 < (char *)&v2[v12] )
{
while ( 1 )
{
v1[v9] = 0LL;
v2[v9] = 0;
v9 = v11;
if ( v5 <= (int)v11 )
break;
++v11;
}
}
else
{
v13 = v10 + 1;
memset(v8, 0, 8 * (v10 + 1));
memset(&v2[v0], 0, 4 * v13);
}
}
goto LABEL_2;
}
}
fwrite("\nRan out of memory. Cannot add new sequence.\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // r13
_QWORD *v1; // rbp
_DWORD *v2; // r12
int v3; // ebx
__int64 result; // rax
int v5; // er14
void *v6; // rax
unsigned __int64 v7; // r15
char *v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11; // rax
__int64 v12; // rsi
__int64 v13; // r14

v0 = num_seqs;
v1 = sequences;
v2 = marks;
v3 = num_seqs;
if ( num_seqs != seqsize )
{
LABEL_2:
v1[v0] = func5();
result = (unsigned int)(v3 + 1);
v2[v0] = 0;
num_seqs = v3 + 1;
return result;
}
v5 = 2 * num_seqs;
seqsize = 2 * num_seqs;
sequences = realloc(sequences, 16LL * num_seqs);
v1 = sequences;
if ( sequences )
{
v6 = realloc(marks, 4LL * v5);
marks = v6;
v2 = v6;
if ( v6 )
{
if ( (int)v0 < v5 )
{
v7 = (unsigned __int64)v6 + 4 * v0;
v8 = (char *)&v1[v0];
v9 = v0;
v10 = (unsigned int)(v5 - v0 - 1);
v11 = v0 + 1;
v12 = v0 + 1 + v10;
if ( v7 < (unsigned __int64)&v1[v12] && v8 < (char *)&v2[v12] )
{
while ( 1 )
{
v1[v9] = 0LL;
v2[v9] = 0;
v9 = v11;
if ( v5 <= (int)v11 )
break;
++v11;
}
}
else
{
v13 = v10 + 1;
memset(v8, 0, 8 * (v10 + 1));
memset(&v2[v0], 0, 4 * v13);
}
}
goto LABEL_2;
}
}
fwrite("\nRan out of memory. Cannot add new sequence.\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int add_element(void)
{
  int i;
  if (num_seqs == seqsize) {
    seqsize += seqsize;
    if ((sequences = realloc(sequences, seqsize * sizeof(STRING *))) == ((void *)0)) {
      fprintf(stderr, "\nRan out of memory.  Cannot add new sequence.\n");
      return -1;
    }
    if ((marks = realloc(marks, seqsize * sizeof(int))) == ((void *)0)) {
      fprintf(stderr, "\nRan out of memory.  Cannot add new sequence.\n");
      return -1;
    }
    for (i=num_seqs; i < seqsize; i++) {
      sequences[i] = ((void *)0);
      marks[i] = 0;
    }
  }
  sequences[num_seqs] = init_string();
  marks[num_seqs] = 0;
  num_seqs++;
  return num_seqs;
}

canonical_original_code:
int add_element()
{
  int i;
  if (num_seqs == seqsize) {
    seqsize += seqsize;
    if ((sequences = realloc(sequences, seqsize * sizeof(struct STRING *))) == ((void *)0)) {
      fprintf(stderr, "\nRan out of memory.  Cannot add new sequence.\n");
      return -1;
    }
    if ((marks = realloc(marks, seqsize * sizeof(int))) == ((void *)0)) {
      fprintf(stderr, "\nRan out of memory.  Cannot add new sequence.\n");
      return -1;
    }
    for (i=num_seqs; i < seqsize; i++) {
      sequences[i] = ((void *)0);
      marks[i] = 0;
    }
  }
  sequences[num_seqs] = init_string();
  marks[num_seqs] = 0;
  num_seqs++;
  return num_seqs;
}


decompiled_code:
void __fastcall free_string(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
free(ptr);
}
}

original_code:
void free_string(STRING *sptr)
{
  if (sptr == ((void *)0))
    return;
  if (sptr->sequence != ((void *)0)) free(sptr->sequence);
  if (sptr->desc_string != ((void *)0)) free(sptr->desc_string);
  if (sptr->raw_seq != ((void *)0)) free(sptr->raw_seq);
  free(sptr);
}

canonical_original_code:
void free_string(struct STRING *sptr)
{
  if (sptr == ((void *)0))
    return;
  if (sptr->sequence != ((void *)0)) free(sptr->sequence);
  if (sptr->desc_string != ((void *)0)) free(sptr->desc_string);
  if (sptr->raw_seq != ((void *)0)) free(sptr->raw_seq);
  free(sptr);
}


decompiled_code:
__int64 __fastcall delete_element(int a1)
{
int v1; // er12
_QWORD *v2; // rbx
int v3; // esi
_DWORD *v4; // rdx
__int64 v5; // rax
unsigned __int64 v6; // rax
_QWORD *v7; // rcx
_DWORD *v8; // rax

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
v1 = num_seqs;
if ( num_seqs < a1 )
return 0xFFFFFFFFLL;
v2 = sequences;
free_string(*((void **)sequences + a1 - 1));
v3 = v1 - 1;
v4 = marks;
v5 = a1 - 1;
if ( v1 <= a1 )
{
v7 = &v2[v5];
v8 = (char *)marks + 4 * v5;
}
else
{
do
{
v2[v5] = v2[v5 + 1];
v4[v5] = v4[v5 + 1];
++v5;
}
while ( v3 > (int)v5 );
v6 = a1 + (unsigned __int64)(unsigned int)(v3 - a1);
v7 = &v2[v6];
v8 = &v4[v6];
}
num_seqs = v1 - 1;
*v7 = 0LL;
*v8 = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // er12
_QWORD *v2; // rbx
int v3; // esi
_DWORD *v4; // rdx
__int64 v5; // rax
unsigned __int64 v6; // rax
_QWORD *v7; // rcx
_DWORD *v8; // rax

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
v1 = num_seqs;
if ( num_seqs < a1 )
return 0xFFFFFFFFLL;
v2 = sequences;
func7(*((void **)sequences + a1 - 1));
v3 = v1 - 1;
v4 = marks;
v5 = a1 - 1;
if ( v1 <= a1 )
{
v7 = &v2[v5];
v8 = (char *)marks + 4 * v5;
}
else
{
do
{
v2[v5] = v2[v5 + 1];
v4[v5] = v4[v5 + 1];
++v5;
}
while ( v3 > (int)v5 );
v6 = a1 + (unsigned __int64)(unsigned int)(v3 - a1);
v7 = &v2[v6];
v8 = &v4[v6];
}
num_seqs = v1 - 1;
*v7 = 0LL;
*v8 = 0;
return 0LL;
}

original_code:
int delete_element(int element)
{
  int i;
  if (element < 1 || element > num_seqs)
    return -1;
  free_string(sequences[element-1]);
  for (i=element-1; i < num_seqs - 1; i++) {
    sequences[i] = sequences[i+1];
    marks[i] = marks[i+1];
  }
  sequences[i] = ((void *)0);
  marks[i] = 0;
  num_seqs--;
  return 0;
}

variable_types: element int


decompiled_code:
void free_seq_ary()
{
int v0; // ebx

v0 = num_seqs;
if ( num_seqs > 0 )
{
do
delete_element(v0--);
while ( v0 );
}
free(sequences);
free(marks);
}

canonical_decompiled_code:
void func9()
{
int v0; // ebx

v0 = num_seqs;
if ( num_seqs > 0 )
{
do
func8(v0--);
while ( v0 );
}
free(sequences);
free(marks);
}

original_code:
void free_seq_ary()
{
 int i;
 for (i=num_seqs; i > 0; i--)
   delete_element(i);
 free(sequences);
 free(marks);
}


decompiled_code:
void *bmset_naive_alloc()
{
return calloc(0x50uLL, 1uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(0x50uLL, 1uLL);
}

original_code:
BMSET_NAIVE_STRUCT *bmset_naive_alloc(void)
{
  BMSET_NAIVE_STRUCT *node;
  if ((node = malloc(sizeof(BMSET_NAIVE_STRUCT))) == ((void *)0))
    return ((void *)0);
  memset(node, 0, sizeof(BMSET_NAIVE_STRUCT));
  return node;
}

canonical_original_code:
struct BMSET_NAIVE_STRUCT *bmset_naive_alloc()
{
  struct BMSET_NAIVE_STRUCT *node;
  if ((node = malloc(sizeof(BMSET_NAIVE_STRUCT))) == ((void *)0))
    return ((void *)0);
  memset(node, 0, sizeof(BMSET_NAIVE_STRUCT));
  return node;
}

variable_types: struct BMSET_NAIVE_STRUCT { int num_patterns; struct BM_STRUCT { enum BMALG_TYPE { BM_BAD=0, BM_EXT=1, BM_GOOD=2, BM_EXTGOOD=3 } type; char *P; int M; int *R; int prep_compares; int num_shifts; int num_init_mismatch; } **patterns; int *ids; char *T; int N; int startflag; char **matches; int prep_compares; int num_shifts; } *

user_defined_types: struct BMSET_NAIVE_STRUCT { int num_patterns; struct BM_STRUCT **patterns; int *ids; char *T; int N; int startflag; char **matches; int prep_compares; int num_shifts; }

user_defined_types: struct BM_STRUCT { enum BMALG_TYPE type; char *P; int M; int *R; int prep_compares; int num_shifts; int num_init_mismatch; }


original_code:
int bmset_naive_add_string(BMSET_NAIVE_STRUCT *node, char *P, int M, int id,
                           int copyflag)
{
  int i;
  BM_STRUCT *bmstruct;
  if (node->errorflag)
    return 0;
  if (node->num_patterns == node->patterns_size) {
    if (node->patterns_size == 0) {
      node->patterns_size = 16;
      node->patterns = malloc(node->patterns_size * sizeof(BM_STRUCT *));
      node->ids = malloc(node->patterns_size * sizeof(int));
      node->matches = malloc(node->patterns_size * sizeof(char *));
    }
    else {
      node->patterns_size += node->patterns_size;
      node->patterns = realloc(node->patterns,
                               node->patterns_size * sizeof(BM_STRUCT *));
      node->ids = realloc(node->ids, node->patterns_size * sizeof(int));
      node->matches = realloc(node->matches,
                              node->patterns_size * sizeof(char *));
    }
    if (node->patterns == ((void *)0) || node->ids == ((void *)0) || node->matches == ((void *)0)) {
      node->errorflag = 1;
      return 0;
    }
  }
  for (i=0; i < node->num_patterns; i++) {
    if (node->ids[i] == id) {
      fprintf(stderr, "Error in naive Boyer-Moore Set preprocessing.  "
              "Duplicate identifiers.\n");
      return 0;
    }
  }
  if ((bmstruct = bmgood_prep(P, M, copyflag)) == ((void *)0)) {
    fprintf(stderr, "Error in naive Boyer-Moore Set preprocessing.  "
            "Cannot preprocess pattern %d.\n", id);
    return 0;
  }
  node->prep_compares += bmstruct->prep_compares;
  node->patterns[node->num_patterns] = bmstruct;
  node->ids[node->num_patterns] = id;
  node->num_patterns++;
  node->initflag = 0;
  return 1;
}

canonical_original_code:
int bmset_naive_add_string(struct BMSET_NAIVE_STRUCT *node, char *P, int M, int id, int copyflag)
{
  int i;
  struct BM_STRUCT *bmstruct;
  if (node->errorflag)
    return 0;
  if (node->num_patterns == node->patterns_size) {
    if (node->patterns_size == 0) {
      node->patterns_size = 16;
      node->patterns = malloc(node->patterns_size * sizeof(struct BM_STRUCT *));
      node->ids = malloc(node->patterns_size * sizeof(int));
      node->matches = malloc(node->patterns_size * sizeof(char *));
    }
    else {
      node->patterns_size += node->patterns_size;
      node->patterns = realloc(node->patterns,
                               node->patterns_size * sizeof(struct BM_STRUCT *));
      node->ids = realloc(node->ids, node->patterns_size * sizeof(int));
      node->matches = realloc(node->matches,
                              node->patterns_size * sizeof(char *));
    }
    if (node->patterns == ((void *)0) || node->ids == ((void *)0) || node->matches == ((void *)0)) {
      node->errorflag = 1;
      return 0;
    }
  }
  for (i=0; i < node->num_patterns; i++) {
    if (node->ids[i] == id) {
      fprintf(stderr, "Error in naive Boyer-Moore Set preprocessing.  "
              "Duplicate identifiers.\n");
      return 0;
    }
  }
  if ((bmstruct = bmgood_prep(P, M, copyflag)) == ((void *)0)) {
    fprintf(stderr, "Error in naive Boyer-Moore Set preprocessing.  "
            "Cannot preprocess pattern %d.\n", id);
    return 0;
  }
  node->prep_compares += bmstruct->prep_compares;
  node->patterns[node->num_patterns] = bmstruct;
  node->ids[node->num_patterns] = id;
  node->num_patterns++;
  node->initflag = 0;
  return 1;
}

variable_types:
P
char *

variable_types: M int

variable_types: id int

variable_types: copyflag int

variable_types: struct BM_STRUCT { enum BMALG_TYPE { BM_BAD=0, BM_EXT=1, BM_GOOD=2, BM_EXTGOOD=3 } type; char *P; int M; int *R; int prep_compares; int num_shifts; int num_init_mismatch; } *


original_code:
int bmset_naive_del_string(BMSET_NAIVE_STRUCT *node, char *P, int M, int id)
{
  int i;
  if (node->errorflag)
    return 0;
  for (i=0; i < node->num_patterns; i++)
    if (node->ids[i] == id)
      break;
  if (i == node->num_patterns) {
    fprintf(stderr, "Error in naive Boyer-Moore Set preprocessing.  "
            "String to be deleted is not in tree.\n");
    return 0;
  }
  bm_free(node->patterns[i]);
  for (i++; i < node->num_patterns; i++) {
    node->patterns[i-1] = node->patterns[i];
    node->ids[i-1] = node->ids[i];
  }
  node->num_patterns--;
  node->initflag = 0;
  return 1;
}

canonical_original_code:
int bmset_naive_del_string(struct BMSET_NAIVE_STRUCT *node, char *P, int M, int id)
{
  int i;
  if (node->errorflag)
    return 0;
  for (i=0; i < node->num_patterns; i++)
    if (node->ids[i] == id)
      break;
  if (i == node->num_patterns) {
    fprintf(stderr, "Error in naive Boyer-Moore Set preprocessing.  "
            "String to be deleted is not in tree.\n");
    return 0;
  }
  bm_free(node->patterns[i]);
  for (i++; i < node->num_patterns; i++) {
    node->patterns[i-1] = node->patterns[i];
    node->ids[i-1] = node->ids[i];
  }
  node->num_patterns--;
  node->initflag = 0;
  return 1;
}

user_defined_types: enum BMALG_TYPE { BM_BAD=0, BM_EXT=1, BM_GOOD=2, BM_EXTGOOD=3 }


decompiled_code:
unsigned __int64 __fastcall bmset_naive_search_init(int *a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax
__int64 v4; // rdx

result = (unsigned int)a1[10];
if ( !(_DWORD)result )
{
a1[8] = a3;
v4 = *a1;
*((_QWORD *)a1 + 3) = a2;
if ( (int)v4 > 0 )
memset(*((void **)a1 + 7), 0, 8 * v4);
result = 0xFFFFFFFF00000000LL;
a1[9] = 1;
a1[11] = 1;
*((_QWORD *)a1 + 6) = 0xFFFFFFFF00000000LL;
*(_QWORD *)(a1 + 17) = 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(int *a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax
__int64 v4; // rdx

result = (unsigned int)a1[10];
if ( !(_DWORD)result )
{
a1[8] = a3;
v4 = *a1;
*((_QWORD *)a1 + 3) = a2;
if ( (int)v4 > 0 )
memset(*((void **)a1 + 7), 0, 8 * v4);
result = 0xFFFFFFFF00000000LL;
a1[9] = 1;
a1[11] = 1;
*((_QWORD *)a1 + 6) = 0xFFFFFFFF00000000LL;
*(_QWORD *)(a1 + 17) = 0LL;
}
return result;
}

original_code:
void bmset_naive_search_init(BMSET_NAIVE_STRUCT *node, char *T, int N)
{
  int i;
  if (node->errorflag)
    return;
  node->T = T;
  node->N = N;
  for (i=0; i < node->num_patterns; i++)
    node->matches[i] = ((void *)0);
  node->initflag = node->startflag = 1;
  node->endflag = 0;
  node->output = -1;
  node->num_compares = node->num_shifts = 0;
}

canonical_original_code:
void bmset_naive_search_init(struct BMSET_NAIVE_STRUCT *node, char *T, int N)
{
  int i;
  if (node->errorflag)
    return;
  node->T = T;
  node->N = N;
  for (i=0; i < node->num_patterns; i++)
    node->matches[i] = ((void *)0);
  node->initflag = node->startflag = 1;
  node->endflag = 0;
  node->output = -1;
  node->num_compares = node->num_shifts = 0;
}

variable_types:
T
char *

variable_types: N int


original_code:
char *bmset_naive_search(BMSET_NAIVE_STRUCT *node, int *length_out,
                         int *id_out)
{
  int i, N, M, len, pos, match, matchlen, matchpos;
  char *s, *T, **matches;
  if (node->errorflag)
    return ((void *)0);
  else if (!node->initflag) {
    fprintf(stderr, "Error in naive Boyer-Moore Set search.  "
            "bmset_naive_search_init was not called.\n");
    return ((void *)0);
  }
  else if (node->endflag)
    return ((void *)0);
  T = node->T;
  N = node->N;
  matches = node->matches;
  if (node->startflag) {
    for (i=0; i < node->num_patterns; i++)
      node->matches[i] = bmgood_search(node->patterns[i], T, N, 0);
    node->startflag = 0;
  }
  if (node->output != -1) {
    i = node->output;
    s = node->matches[i];
    len = N - (s - T);
    node->matches[i] = bmgood_search(node->patterns[i], s, len, 1);
  }
  node->num_compares = node->num_shifts = 0;
  match = -1;
  matchlen = 0;
  matchpos = 0;
  for (i=0; i < node->num_patterns; i++) {
    if (node->matches[i]) {
      M = node->patterns[i]->M;
      pos = (node->matches[i] - T) + M;
      if (match == -1 || pos < matchpos || (pos == matchpos && M > matchlen)) {
        match = i;
        matchlen = M;
        matchpos = pos;
      }
    }
    node->num_compares += node->patterns[i]->num_compares;
    node->num_shifts += node->patterns[i]->num_shifts;
  }
  if (match == -1) {
    node->endflag = 1;
    return ((void *)0);
  }
  else {
    if (id_out)
      *id_out = node->ids[match];
    if (length_out)
      *length_out = matchlen;
    node->output = match;
    return node->matches[match];
  }
}

canonical_original_code:
char *bmset_naive_search(struct BMSET_NAIVE_STRUCT *node, int *length_out, int *id_out)
{
  int i; int N; int M; int len; int pos; int match; int matchlen; int matchpos;
  char *s; char *T; char **matches;
  if (node->errorflag)
    return ((void *)0);
  else if (!node->initflag) {
    fprintf(stderr, "Error in naive Boyer-Moore Set search.  "
            "bmset_naive_search_init was not called.\n");
    return ((void *)0);
  }
  else if (node->endflag)
    return ((void *)0);
  T = node->T;
  N = node->N;
  matches = node->matches;
  if (node->startflag) {
    for (i=0; i < node->num_patterns; i++)
      node->matches[i] = bmgood_search(node->patterns[i], T, N, 0);
    node->startflag = 0;
  }
  if (node->output != -1) {
    i = node->output;
    s = node->matches[i];
    len = N - (s - T);
    node->matches[i] = bmgood_search(node->patterns[i], s, len, 1);
  }
  node->num_compares = node->num_shifts = 0;
  match = -1;
  matchlen = 0;
  matchpos = 0;
  for (i=0; i < node->num_patterns; i++) {
    if (node->matches[i]) {
      M = node->patterns[i]->M;
      pos = (node->matches[i] - T) + M;
      if (match == -1 || pos < matchpos || (pos == matchpos && M > matchlen)) {
        match = i;
        matchlen = M;
        matchpos = pos;
      }
    }
    node->num_compares += node->patterns[i]->num_compares;
    node->num_shifts += node->patterns[i]->num_shifts;
  }
  if (match == -1) {
    node->endflag = 1;
    return ((void *)0);
  }
  else {
    if (id_out)
      *id_out = node->ids[match];
    if (length_out)
      *length_out = matchlen;
    node->output = match;
    return node->matches[match];
  }
}

variable_types: len int

variable_types: pos int

variable_types: match int

variable_types: matchlen int

variable_types: matchpos int

variable_types:
matches
char **

return_type: char *


decompiled_code:
void __fastcall bmset_naive_free(void *ptr)
{
_QWORD *v2; // rdi
__int64 v3; // rbx
__int64 v4; // rdi
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(int *)ptr > 0 )
{
v3 = 0LL;
do
{
v4 = v2[v3++];
bm_free(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
}
while ( *(_DWORD *)ptr > (int)v3 );
}
free(v2);
}
v5 = (void *)*((_QWORD *)ptr + 2);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 7);
if ( v6 )
free(v6);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
_QWORD *v2; // rdi
__int64 v3; // rbx
__int64 v4; // rdi
void *v5; // rdi
void *v6; // rdi

if ( ptr )
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(int *)ptr > 0 )
{
v3 = 0LL;
do
{
v4 = v2[v3++];
bm_free(v4);
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
}
while ( *(_DWORD *)ptr > (int)v3 );
}
free(v2);
}
v5 = (void *)*((_QWORD *)ptr + 2);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 7);
if ( v6 )
free(v6);
free(ptr);
}
}

original_code:
void bmset_naive_free(BMSET_NAIVE_STRUCT *node)
{
  int i;
  if (node == ((void *)0))
    return;
  if (node->patterns != ((void *)0)) {
    for (i=0; i < node->num_patterns; i++)
      bm_free(node->patterns[i]);
    free(node->patterns);
  }
  if (node->ids != ((void *)0))
    free(node->ids);
  if (node->matches != ((void *)0))
    free(node->matches);
  free(node);
}

canonical_original_code:
void bmset_naive_free(struct BMSET_NAIVE_STRUCT *node)
{
  int i;
  if (node == ((void *)0))
    return;
  if (node->patterns != ((void *)0)) {
    for (i=0; i < node->num_patterns; i++)
      bm_free(node->patterns[i]);
    free(node->patterns);
  }
  if (node->ids != ((void *)0))
    free(node->ids);
  if (node->matches != ((void *)0))
    free(node->matches);
  free(node);
}

variable_types: i int


decompiled_code:
__int64 __fastcall print_lcp_values(__int64 a1, unsigned int a2, unsigned int a3, signed int a4, int a5)
{
int v9; // ebx
__int64 result; // rax
unsigned int v11; // er12

while ( 1 )
{
if ( a5 > 0 )
{
v9 = 0;
do
{
++v9;
mputc(32LL);
}
while ( a5 != v9 );
}
if ( !(unsigned int)mprintf("%d,%d = %d\n", a2, a3, *(unsigned int *)(a1 + 4LL * a4)) )
break;
result = a3 - a2;
if ( (_DWORD)result == 1 )
return result;
a5 += 3;
v11 = 2 * a4;
if ( !(unsigned int)print_lcp_values(a1, a2, (unsigned int)((int)(a2 + a3) / 2), v11, (unsigned int)a5) )
break;
a4 = v11 + 1;
a2 = (int)(a2 + a3) / 2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, signed int a4, int a5)
{
int v9; // ebx
__int64 result; // rax
unsigned int v11; // er12

while ( 1 )
{
if ( a5 > 0 )
{
v9 = 0;
do
{
++v9;
mputc(32LL);
}
while ( a5 != v9 );
}
if ( !(unsigned int)mprintf("%d,%d = %d\n", a2, a3, *(unsigned int *)(a1 + 4LL * a4)) )
break;
result = a3 - a2;
if ( (_DWORD)result == 1 )
return result;
a5 += 3;
v11 = 2 * a4;
if ( !(unsigned int)func0(a1, a2, (unsigned int)((int)(a2 + a3) / 2), v11, (unsigned int)a5) )
break;
a4 = v11 + 1;
a2 = (int)(a2 + a3) / 2;
}
return 0LL;
}

original_code:
static int print_lcp_values(int *lcp, int min, int max, int index, int depth)
{
  int i, midpoint;
  for (i=0; i < depth; i++)
    mputc(' ');
  if (mprintf("%d,%d  =  %d\n", min, max, lcp[index]) == 0)
    return 0;
  if (max - min == 1)
    return 1;
  midpoint = (max + min) / 2;
  if (!print_lcp_values(lcp, min, midpoint, index * 2, depth + 3))
    return 0;
  else
    return print_lcp_values(lcp, midpoint, max, index * 2 + 1, depth + 3);
}

canonical_original_code:
static int print_lcp_values(int *lcp, int min, int max, int index, int depth)
{
  int i; int midpoint;
  for (i=0; i < depth; i++)
    mputc(' ');
  if (mprintf("%d,%d  =  %d\n", min, max, lcp[index]) == 0)
    return 0;
  if (max - min == 1)
    return 1;
  midpoint = (max + min) / 2;
  if (!print_lcp_values(lcp, min, midpoint, index * 2, depth + 3))
    return 0;
  else
    return print_lcp_values(lcp, midpoint, max, index * 2 + 1, depth + 3);
}

variable_types:
lcp
int *

variable_types: min int

variable_types: max int

variable_types: index int

variable_types: depth int

variable_types: midpoint int


decompiled_code:
__int64 __fastcall strmat_sary_qsort(__int64 *a1, int a2)
{
__int64 v3; // rdi
__int64 v5; // rsi
__int64 v7; // r14
unsigned int v8; // eax
int v9; // er13
__int64 v10; // r12
__int64 v11; // rbx
char v12[32]; // [rsp-20h] [rbp-78h] BYREF
char dest[30]; // [rsp+0h] [rbp-58h] BYREF
int v14; // [rsp+1Eh] [rbp-3Ah]

if ( !a1 )
return 0LL;
v3 = *a1;
if ( !v3 )
return 0LL;
v5 = *((unsigned int *)a1 + 6);
if ( !(_DWORD)v5 )
return 0LL;
v7 = sary_qsort_build(v3, v5, 0LL);
if ( !v7 )
return 0LL;
if ( a2 )
{
mprintf("Statistics:\n");
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v7 + 40));
mprintf(" Number of Tree Ops: %d\n", *(unsigned int *)(v7 + 44));
mprintf(" Number of LCP Ops: %d\n", *(unsigned int *)(v7 + 48));
mprintf("\n");
}
mprintf("The Suffix Array:\n");
v8 = my_itoalen(*((unsigned int *)a1 + 6));
sprintf(v12, " %%%dd: %%s\n", v8);
v14 = 3026478;
v9 = *(_DWORD *)(v7 + 8);
v10 = *(_QWORD *)(v7 + 16);
if ( v9 > 0 )
{
v11 = 1LL;
do
{
strncpy(dest, (const char *)(a1[2] + *(int *)(v10 + 4 * v11) - 1), 0x1EuLL);
if ( !(unsigned int)mprintf(v12, *(unsigned int *)(v10 + 4 * v11), dest) )
return 0LL;
}
while ( v9 >= (int)++v11 );
}
sary_free(v7);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, int a2)
{
__int64 v3; // rdi
__int64 v5; // rsi
__int64 v7; // r14
unsigned int v8; // eax
int v9; // er13
__int64 v10; // r12
__int64 v11; // rbx
char v12[32]; // [rsp-20h] [rbp-78h] BYREF
char dest[30]; // [rsp+0h] [rbp-58h] BYREF
int v14; // [rsp+1Eh] [rbp-3Ah]

if ( !a1 )
return 0LL;
v3 = *a1;
if ( !v3 )
return 0LL;
v5 = *((unsigned int *)a1 + 6);
if ( !(_DWORD)v5 )
return 0LL;
v7 = sary_qsort_build(v3, v5, 0LL);
if ( !v7 )
return 0LL;
if ( a2 )
{
mprintf("Statistics:\n");
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v7 + 40));
mprintf(" Number of Tree Ops: %d\n", *(unsigned int *)(v7 + 44));
mprintf(" Number of LCP Ops: %d\n", *(unsigned int *)(v7 + 48));
mprintf("\n");
}
mprintf("The Suffix Array:\n");
v8 = my_itoalen(*((unsigned int *)a1 + 6));
sprintf(v12, " %%%dd: %%s\n", v8);
v14 = 3026478;
v9 = *(_DWORD *)(v7 + 8);
v10 = *(_QWORD *)(v7 + 16);
if ( v9 > 0 )
{
v11 = 1LL;
do
{
strncpy(dest, (const char *)(a1[2] + *(int *)(v10 + 4 * v11) - 1), 0x1EuLL);
if ( !(unsigned int)mprintf(v12, *(unsigned int *)(v10 + 4 * v11), dest) )
return 0LL;
}
while ( v9 >= (int)++v11 );
}
sary_free(v7);
return 1LL;
}

original_code:
int strmat_sary_qsort(STRING *string, int print_stats)
{
  int i, len, M, *Pos;
  char format[32], buf[36];
  SARY_STRUCT *sary;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  sary = sary_qsort_build(string->sequence, string->length, 0);
  if (sary == ((void *)0))
    return 0;
  if (print_stats) {
    mprintf("Statistics:\n");
    mprintf("   Number of Compares:  %d\n", sary->num_compares);
    mprintf("   Number of Tree Ops:  %d\n", sary->num_tree_ops);
    mprintf("   Number of LCP Ops:   %d\n", sary->num_lcp_ops);
    mprintf("\n");
  }
  mprintf("The Suffix Array:\n");
  len = my_itoalen(string->length);
  sprintf(format, "  %%%dd:  %%s\n", len);
  buf[30] = buf[31] = buf[32] = '.';
  buf[33] = '\0';
  Pos = sary->Pos;
  M = sary->M;
  for (i=1; i <= M; i++) {
    strncpy(buf, &string->raw_seq[Pos[i] - 1], 30);
    if (mprintf(format, Pos[i], buf) == 0)
      return 0;
  }
  sary_free(sary);
  return 1;
}

canonical_original_code:
int strmat_sary_qsort(struct STRING *string, int print_stats)
{
  int i; int len; int M; int *Pos;
  char format[32]; char buf[36];
  struct SARY_STRUCT *sary;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  sary = sary_qsort_build(string->sequence, string->length, 0);
  if (sary == ((void *)0))
    return 0;
  if (print_stats) {
    mprintf("Statistics:\n");
    mprintf("   Number of Compares:  %d\n", sary->num_compares);
    mprintf("   Number of Tree Ops:  %d\n", sary->num_tree_ops);
    mprintf("   Number of LCP Ops:   %d\n", sary->num_lcp_ops);
    mprintf("\n");
  }
  mprintf("The Suffix Array:\n");
  len = my_itoalen(string->length);
  sprintf(format, "  %%%dd:  %%s\n", len);
  buf[30] = buf[31] = buf[32] = '.';
  buf[33] = '\0';
  Pos = sary->Pos;
  M = sary->M;
  for (i=1; i <= M; i++) {
    strncpy(buf, &string->raw_seq[Pos[i] - 1], 30);
    if (mprintf(format, Pos[i], buf) == 0)
      return 0;
  }
  sary_free(sary);
  return 1;
}

variable_types: struct STRING { char *sequence; int length; int alpha_size; char ident[-1]; } *

variable_types: M int

variable_types:
Pos
int *

variable_types:
format
char [32]

variable_types:
buf
char [36]

variable_types: struct SARY_STRUCT { char *S; int M; int *Pos; int num_compares; } *


decompiled_code:
__int64 __fastcall strmat_sary_zerkle(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v5; // r14
unsigned int v6; // eax
int v7; // er13
__int64 v8; // r12
__int64 v9; // rbx
char v10[32]; // [rsp-20h] [rbp-78h] BYREF
char dest[30]; // [rsp+0h] [rbp-58h] BYREF
int v12; // [rsp+1Eh] [rbp-3Ah]

if ( !a1 )
return 0LL;
v2 = *a1;
if ( !v2 )
return 0LL;
v3 = *((unsigned int *)a1 + 6);
if ( !(_DWORD)v3 )
return 0LL;
v5 = sary_zerkle_build(v2, v3, 0LL);
if ( !v5 )
return 0LL;
mprintf("The Suffix Array:\n");
v6 = my_itoalen(*((unsigned int *)a1 + 6));
sprintf(v10, " %%%dd: %%s\n", v6);
v12 = 3026478;
v7 = *(_DWORD *)(v5 + 8);
v8 = *(_QWORD *)(v5 + 16);
if ( v7 > 0 )
{
v9 = 1LL;
do
{
strncpy(dest, (const char *)(a1[2] + *(int *)(v8 + 4 * v9) - 1), 0x1EuLL);
if ( !(unsigned int)mprintf(v10, *(unsigned int *)(v8 + 4 * v9), dest) )
return 0LL;
}
while ( v7 >= (int)++v9 );
}
sary_free(v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v5; // r14
unsigned int v6; // eax
int v7; // er13
__int64 v8; // r12
__int64 v9; // rbx
char v10[32]; // [rsp-20h] [rbp-78h] BYREF
char dest[30]; // [rsp+0h] [rbp-58h] BYREF
int v12; // [rsp+1Eh] [rbp-3Ah]

if ( !a1 )
return 0LL;
v2 = *a1;
if ( !v2 )
return 0LL;
v3 = *((unsigned int *)a1 + 6);
if ( !(_DWORD)v3 )
return 0LL;
v5 = sary_zerkle_build(v2, v3, 0LL);
if ( !v5 )
return 0LL;
mprintf("The Suffix Array:\n");
v6 = my_itoalen(*((unsigned int *)a1 + 6));
sprintf(v10, " %%%dd: %%s\n", v6);
v12 = 3026478;
v7 = *(_DWORD *)(v5 + 8);
v8 = *(_QWORD *)(v5 + 16);
if ( v7 > 0 )
{
v9 = 1LL;
do
{
strncpy(dest, (const char *)(a1[2] + *(int *)(v8 + 4 * v9) - 1), 0x1EuLL);
if ( !(unsigned int)mprintf(v10, *(unsigned int *)(v8 + 4 * v9), dest) )
return 0LL;
}
while ( v7 >= (int)++v9 );
}
sary_free(v5);
return 1LL;
}

original_code:
int strmat_sary_zerkle(STRING *string, int print_stats)
{
  int i, len, M, *Pos;
  char format[32], buf[36];
  SARY_STRUCT *sary;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  sary = sary_zerkle_build(string->sequence, string->length, 0);
  if (sary == ((void *)0))
    return 0;
  mprintf("The Suffix Array:\n");
  len = my_itoalen(string->length);
  sprintf(format, "  %%%dd:  %%s\n", len);
  buf[30] = buf[31] = buf[32] = '.';
  buf[33] = '\0';
  Pos = sary->Pos;
  M = sary->M;
  for (i=1; i <= M; i++) {
    strncpy(buf, &string->raw_seq[Pos[i] - 1], 30);
    if (mprintf(format, Pos[i], buf) == 0)
      return 0;
  }
  sary_free(sary);
  return 1;
}

canonical_original_code:
int strmat_sary_zerkle(struct STRING *string, int print_stats)
{
  int i; int len; int M; int *Pos;
  char format[32]; char buf[36];
  struct SARY_STRUCT *sary;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  sary = sary_zerkle_build(string->sequence, string->length, 0);
  if (sary == ((void *)0))
    return 0;
  mprintf("The Suffix Array:\n");
  len = my_itoalen(string->length);
  sprintf(format, "  %%%dd:  %%s\n", len);
  buf[30] = buf[31] = buf[32] = '.';
  buf[33] = '\0';
  Pos = sary->Pos;
  M = sary->M;
  for (i=1; i <= M; i++) {
    strncpy(buf, &string->raw_seq[Pos[i] - 1], 30);
    if (mprintf(format, Pos[i], buf) == 0)
      return 0;
  }
  sary_free(sary);
  return 1;
}

variable_types: len int

user_defined_types: struct SARY_STRUCT { char *S; int M; int *Pos; int num_compares; }


decompiled_code:
__int64 __fastcall strmat_sary_stree(__int64 *a1, int a2)
{
__int64 v3; // rdi
__int64 v5; // rsi
__int64 v7; // r14
unsigned int v8; // eax
signed int v9; // er13
__int64 v10; // r12
__int64 v11; // rbx
char v12[32]; // [rsp-20h] [rbp-78h] BYREF
char dest[30]; // [rsp+0h] [rbp-58h] BYREF
int v14; // [rsp+1Eh] [rbp-3Ah]

if ( !a1 )
return 0LL;
v3 = *a1;
if ( !v3 )
return 0LL;
v5 = *((unsigned int *)a1 + 6);
if ( !(_DWORD)v5 )
return 0LL;
v7 = sary_stree_build(v3, v5, 0LL);
if ( !v7 )
return 0LL;
if ( a2 )
{
mprintf("Statistics:\n");
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v7 + 40));
mprintf(" Number of Tree Ops: %d\n", *(unsigned int *)(v7 + 44));
mprintf(" Number of LCP Ops: %d\n", *(unsigned int *)(v7 + 48));
mprintf("\n\n");
}
mprintf("The Suffix Array:\n");
v8 = my_itoalen(*((unsigned int *)a1 + 6));
sprintf(v12, " %%%dd) %%%dd: %%s\n", v8, v8);
v14 = 3026478;
v9 = *(_DWORD *)(v7 + 8);
v10 = *(_QWORD *)(v7 + 16);
if ( v9 > 0 )
{
v11 = 1LL;
do
{
strncpy(dest, (const char *)(a1[2] + *(int *)(v10 + 4 * v11) - 1), 0x1EuLL);
if ( !(unsigned int)mprintf(v12, (unsigned int)v11, *(unsigned int *)(v10 + 4 * v11), dest) )
return 0LL;
}
while ( v9 >= (int)++v11 );
}
mprintf("\n");
mprintf("The LCP Values:\n");
if ( (unsigned int)print_lcp_values(*(_QWORD *)(v7 + 24), 1u, (v9 + 1) / 2, 2, 3) )
{
print_lcp_values(*(_QWORD *)(v7 + 24), (v9 + 1) / 2, v9, 3, 3);
mprintf("\n");
}
sary_free(v7);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, int a2)
{
__int64 v3; // rdi
__int64 v5; // rsi
__int64 v7; // r14
unsigned int v8; // eax
signed int v9; // er13
__int64 v10; // r12
__int64 v11; // rbx
char v12[32]; // [rsp-20h] [rbp-78h] BYREF
char dest[30]; // [rsp+0h] [rbp-58h] BYREF
int v14; // [rsp+1Eh] [rbp-3Ah]

if ( !a1 )
return 0LL;
v3 = *a1;
if ( !v3 )
return 0LL;
v5 = *((unsigned int *)a1 + 6);
if ( !(_DWORD)v5 )
return 0LL;
v7 = sary_stree_build(v3, v5, 0LL);
if ( !v7 )
return 0LL;
if ( a2 )
{
mprintf("Statistics:\n");
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v7 + 40));
mprintf(" Number of Tree Ops: %d\n", *(unsigned int *)(v7 + 44));
mprintf(" Number of LCP Ops: %d\n", *(unsigned int *)(v7 + 48));
mprintf("\n\n");
}
mprintf("The Suffix Array:\n");
v8 = my_itoalen(*((unsigned int *)a1 + 6));
sprintf(v12, " %%%dd) %%%dd: %%s\n", v8, v8);
v14 = 3026478;
v9 = *(_DWORD *)(v7 + 8);
v10 = *(_QWORD *)(v7 + 16);
if ( v9 > 0 )
{
v11 = 1LL;
do
{
strncpy(dest, (const char *)(a1[2] + *(int *)(v10 + 4 * v11) - 1), 0x1EuLL);
if ( !(unsigned int)mprintf(v12, (unsigned int)v11, *(unsigned int *)(v10 + 4 * v11), dest) )
return 0LL;
}
while ( v9 >= (int)++v11 );
}
mprintf("\n");
mprintf("The LCP Values:\n");
if ( (unsigned int)func0(*(_QWORD *)(v7 + 24), 1u, (v9 + 1) / 2, 2, 3) )
{
func0(*(_QWORD *)(v7 + 24), (v9 + 1) / 2, v9, 3, 3);
mprintf("\n");
}
sary_free(v7);
return 1LL;
}

original_code:
int strmat_sary_stree(STRING *string, int print_stats)
{
  int i, len, midpoint, M, *Pos;
  char format[32], buf[36];
  SARY_STRUCT *sary;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  sary = sary_stree_build(string->sequence, string->length, 0);
  if (sary == ((void *)0))
    return 0;
  if (print_stats) {
    mprintf("Statistics:\n");
    mprintf("   Number of Compares:  %d\n", sary->num_compares);
    mprintf("   Number of Tree Ops:  %d\n", sary->num_tree_ops);
    mprintf("   Number of LCP Ops:   %d\n", sary->num_lcp_ops);
    mprintf("\n\n");
  }
  mprintf("The Suffix Array:\n");
  len = my_itoalen(string->length);
  sprintf(format, "  %%%dd)  %%%dd:  %%s\n", len, len);
  buf[30] = buf[31] = buf[32] = '.';
  buf[33] = '\0';
  Pos = sary->Pos;
  M = sary->M;
  for (i=1; i <= M; i++) {
    strncpy(buf, &string->raw_seq[Pos[i] - 1], 30);
    if (mprintf(format, i, Pos[i], buf) == 0)
      return 0;
  }
  mprintf("\n");
  mprintf("The LCP Values:\n");
  midpoint = (1 + M) / 2;
  if (print_lcp_values(sary->lcp, 1, midpoint, 2, 3)) {
    print_lcp_values(sary->lcp, midpoint, M, 3, 3);
    mprintf("\n");
  }
  sary_free(sary);
  return 1;
}

canonical_original_code:
int strmat_sary_stree(struct STRING *string, int print_stats)
{
  int i; int len; int midpoint; int M; int *Pos;
  char format[32]; char buf[36];
  struct SARY_STRUCT *sary;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  sary = sary_stree_build(string->sequence, string->length, 0);
  if (sary == ((void *)0))
    return 0;
  if (print_stats) {
    mprintf("Statistics:\n");
    mprintf("   Number of Compares:  %d\n", sary->num_compares);
    mprintf("   Number of Tree Ops:  %d\n", sary->num_tree_ops);
    mprintf("   Number of LCP Ops:   %d\n", sary->num_lcp_ops);
    mprintf("\n\n");
  }
  mprintf("The Suffix Array:\n");
  len = my_itoalen(string->length);
  sprintf(format, "  %%%dd)  %%%dd:  %%s\n", len, len);
  buf[30] = buf[31] = buf[32] = '.';
  buf[33] = '\0';
  Pos = sary->Pos;
  M = sary->M;
  for (i=1; i <= M; i++) {
    strncpy(buf, &string->raw_seq[Pos[i] - 1], 30);
    if (mprintf(format, i, Pos[i], buf) == 0)
      return 0;
  }
  mprintf("\n");
  mprintf("The LCP Values:\n");
  midpoint = (1 + M) / 2;
  if (print_lcp_values(sary->lcp, 1, midpoint, 2, 3)) {
    print_lcp_values(sary->lcp, midpoint, M, 3, 3);
    mprintf("\n");
  }
  sary_free(sary);
  return 1;
}


decompiled_code:
__int64 __fastcall strmat_sary_match_naive(__int64 *a1, __int64 *a2, int a3)
{
return int_strmat_sary_match(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 *a2, int a3)
{
return func1(a1, a2, a3, 0);
}

original_code:
int strmat_sary_match_naive(STRING *pattern, STRING *text, int stats)
{ return int_strmat_sary_match(pattern, text, stats, NAIVE_MATCH); }

canonical_original_code:
int strmat_sary_match_naive(struct STRING *pattern, struct STRING *text, int stats)
{ return int_strmat_sary_match(pattern, text, stats, NAIVE_MATCH); }

variable_types:
text
struct STRING *

variable_types: stats int


decompiled_code:
__int64 __fastcall strmat_sary_match_mlr(__int64 *a1, __int64 *a2, int a3)
{
return int_strmat_sary_match(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 *a2, int a3)
{
return func1(a1, a2, a3, 1);
}

original_code:
int strmat_sary_match_mlr(STRING *pattern, STRING *text, int stats)
{ return int_strmat_sary_match(pattern, text, stats, MLR_MATCH); }

canonical_original_code:
int strmat_sary_match_mlr(struct STRING *pattern, struct STRING *text, int stats)
{ return int_strmat_sary_match(pattern, text, stats, MLR_MATCH); }


decompiled_code:
__int64 __fastcall strmat_sary_match_lcp(__int64 *a1, __int64 *a2, int a3)
{
return int_strmat_sary_match(a1, a2, a3, 2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 *a2, int a3)
{
return func1(a1, a2, a3, 2);
}

original_code:
int strmat_sary_match_lcp(STRING *pattern, STRING *text, int stats)
{ return int_strmat_sary_match(pattern, text, stats, LCP_MATCH); }

canonical_original_code:
int strmat_sary_match_lcp(struct STRING *pattern, struct STRING *text, int stats)
{ return int_strmat_sary_match(pattern, text, stats, LCP_MATCH); }


decompiled_code:
__int64 __fastcall pr_new_list(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *(int *)(a1 + 56);
v2 = v1 + 1;
result = *(_QWORD *)(a1 + 40) + 48 * v1;
*(_DWORD *)(a1 + 56) = v2;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 32) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
*(_DWORD *)(result + 40) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax

v1 = *(int *)(a1 + 56);
v2 = v1 + 1;
result = *(_QWORD *)(a1 + 40) + 48 * v1;
*(_DWORD *)(a1 + 56) = v2;
*(_QWORD *)(result + 8) = 0LL;
*(_QWORD *)result = 0LL;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 32) = 0LL;
*(_QWORD *)(result + 24) = 0LL;
*(_DWORD *)(result + 40) = 0;
return result;
}

original_code:
pr_list *pr_new_list(primitives_struct *p)
{
  pr_list *l_new;
  l_new = &p->lists[p->nextList++];
  l_new->next = l_new->prev = ((void *)0);
  l_new->atNode = ((void *)0);
  l_new->entries = l_new->last = ((void *)0);
  l_new->len = 0;
  return l_new;
}

canonical_original_code:
struct PRIMITIVES_LIST *pr_new_list(struct PRIMITIVES_STRUCT *p)
{
  struct PRIMITIVES_LIST *l_new;
  l_new = &p->lists[p->nextList++];
  l_new->next = l_new->prev = ((void *)0);
  l_new->atNode = ((void *)0);
  l_new->entries = l_new->last = ((void *)0);
  l_new->len = 0;
  return l_new;
}

variable_types:
p
struct PRIMITIVES_STRUCT *

variable_types: struct PRIMITIVES_LIST { struct PRIMITIVES_LIST *next; struct PRIMITIVES_NODE { struct PRIMITIVES_NODE *next; struct PRIMITIVES_STRUCT { char *string; int length; struct PRIMITIVES_ENTRY { struct PRIMITIVES_ENTRY *next; struct PRIMITIVES_LIST *inList; } *entries; struct PRIMITIVES_LIST *lists; int nextList; struct PRIMITIVES_NODE *nodelist; int nextNode; unsigned int num_primitive_tandem_repeat_occs; unsigned int num_compares; } *inNodelist; struct PRIMITIVES_LIST *lists; } *atNode; struct PRIMITIVES_ENTRY *entries; int len; } *

user_defined_types: struct PRIMITIVES_LIST { struct PRIMITIVES_LIST *next; struct PRIMITIVES_NODE *atNode; struct PRIMITIVES_ENTRY *entries; int len; }

user_defined_types: struct PRIMITIVES_NODE { struct PRIMITIVES_NODE *next; struct PRIMITIVES_STRUCT *inNodelist; struct PRIMITIVES_LIST *lists; }

user_defined_types: struct PRIMITIVES_STRUCT { char *string; int length; struct PRIMITIVES_ENTRY *entries; struct PRIMITIVES_LIST *lists; int nextList; struct PRIMITIVES_NODE *nodelist; int nextNode; unsigned int num_primitive_tandem_repeat_occs; unsigned int num_compares; }


original_code:
void pr_remove_entry(pr_entry *e)
{
  if(e->inList != ((void *)0)) {
    if(e->prev != ((void *)0))
      e->prev->next = e->next;
    else
      e->inList->entries = e->next;
    if(e->next != ((void *)0))
      e->next->prev = e->prev;
    else
      e->inList->last = e->prev;
    e->inList->len--;
    if(e->inList->len == 0)
      pr_remove_list(e->inList);
    e->inList = ((void *)0);
  }
  return;
}

canonical_original_code:
void pr_remove_entry(struct PRIMITIVES_ENTRY *e)
{
  if(e->inList != ((void *)0)) {
    if(e->prev != ((void *)0))
      e->prev->next = e->next;
    else
      e->inList->entries = e->next;
    if(e->next != ((void *)0))
      e->next->prev = e->prev;
    else
      e->inList->last = e->prev;
    e->inList->len--;
    if(e->inList->len == 0)
      pr_remove_list(e->inList);
    e->inList = ((void *)0);
  }
  return;
}

variable_types: struct PRIMITIVES_ENTRY { struct PRIMITIVES_ENTRY *next; struct PRIMITIVES_LIST { struct PRIMITIVES_LIST *next; struct PRIMITIVES_NODE { struct PRIMITIVES_NODE *next; struct PRIMITIVES_STRUCT { char *string; int length; struct PRIMITIVES_ENTRY *entries; struct PRIMITIVES_LIST *lists; int nextList; struct PRIMITIVES_NODE *nodelist; int nextNode; unsigned int num_primitive_tandem_repeat_occs; unsigned int num_compares; } *inNodelist; struct PRIMITIVES_LIST *lists; } *atNode; struct PRIMITIVES_ENTRY *entries; int len; } *inList; } *

user_defined_types: struct PRIMITIVES_ENTRY { struct PRIMITIVES_ENTRY *next; struct PRIMITIVES_LIST *inList; }


original_code:
void pr_next_level(primitives_struct *p)
{
  pr_node *n_tmp;
  n_tmp = p->nodelist;
  p->nodelist = p->nodelist2;
  p->nodelist2 = n_tmp;
  p->nodes2 = p->nodes;
  p->nodes = ((void *)0);
  p->last2 = p->last;
  p->last = ((void *)0);
  p->nextNode = p->nextList2 = 0;
  return;
}

canonical_original_code:
void pr_next_level(struct PRIMITIVES_STRUCT *p)
{
  struct PRIMITIVES_NODE *n_tmp;
  n_tmp = p->nodelist;
  p->nodelist = p->nodelist2;
  p->nodelist2 = n_tmp;
  p->nodes2 = p->nodes;
  p->nodes = ((void *)0);
  p->last2 = p->last;
  p->last = ((void *)0);
  p->nextNode = p->nextList2 = 0;
  return;
}

variable_types: struct PRIMITIVES_STRUCT { char *string; int length; struct PRIMITIVES_ENTRY { struct PRIMITIVES_ENTRY *next; struct PRIMITIVES_LIST { struct PRIMITIVES_LIST *next; struct PRIMITIVES_NODE { struct PRIMITIVES_NODE *next; struct PRIMITIVES_STRUCT *inNodelist; struct PRIMITIVES_LIST *lists; } *atNode; struct PRIMITIVES_ENTRY *entries; int len; } *inList; } *entries; struct PRIMITIVES_LIST *lists; int nextList; struct PRIMITIVES_NODE *nodelist; int nextNode; unsigned int num_primitive_tandem_repeat_occs; unsigned int num_compares; } *

variable_types: struct PRIMITIVES_NODE { struct PRIMITIVES_NODE *next; struct PRIMITIVES_STRUCT { char *string; int length; struct PRIMITIVES_ENTRY { struct PRIMITIVES_ENTRY *next; struct PRIMITIVES_LIST { struct PRIMITIVES_LIST *next; struct PRIMITIVES_NODE *atNode; struct PRIMITIVES_ENTRY *entries; int len; } *inList; } *entries; struct PRIMITIVES_LIST *lists; int nextList; struct PRIMITIVES_NODE *nodelist; int nextNode; unsigned int num_primitive_tandem_repeat_occs; unsigned int num_compares; } *inNodelist; struct PRIMITIVES_LIST *lists; } *


decompiled_code:
void __fastcall primitives_free(void *ptr)
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 8));
free(*((void **)ptr + 9));
free(ptr);
}

original_code:
void primitives_free(primitives_struct *p)
{
  free(p->entries);
  free(p->entries2);
  free(p->lists);
  free(p->lists2);
  free(p->nodelist);
  free(p->nodelist2);
  free(p);
  return;
}

canonical_original_code:
void primitives_free(struct PRIMITIVES_STRUCT *p)
{
  free(p->entries);
  free(p->entries2);
  free(p->lists);
  free(p->lists2);
  free(p->nodelist);
  free(p->nodelist2);
  free(p);
  return;
}


original_code:
void pr_write(char *raw_string, int pos, int len, int rep, char *type)
{
  int i, textlen, restlen;
  char *s, *t, buffer[77];
  sprintf(buffer,"%s: (%d,%d,%d) ",type,pos+1,len,rep);
  buffer[76] = '\0';
  textlen = strlen(buffer);
  restlen = 76-textlen;
  for(i=0,s=&buffer[textlen],t=&raw_string[pos];
      i<restlen && i<len*rep;
      i++,s++,t++)
    *s = ((*__ctype_b_loc ())[(int) (((int)(*t)))] & (unsigned short int) _ISprint) ? *t : '#';
  *s = '\0';
  mputs(buffer);
  if(len > restlen)
    mputs("...");
  mputc('\n');
}

canonical_original_code:
void pr_write(char *raw_string, int pos, int len, int rep, char *type)
{
  int i; int textlen; int restlen;
  char *s; char *t; char buffer[77];
  sprintf(buffer,"%s: (%d,%d,%d) ",type,pos+1,len,rep);
  buffer[76] = '\0';
  textlen = strlen(buffer);
  restlen = 76-textlen;
  for(i=0,s=&buffer[textlen],t=&raw_string[pos];
      i<restlen && i<len*rep;
      i++,s++,t++)
    *s = ((*__ctype_b_loc ())[(int) (((int)(*t)))] & (unsigned short) _ISprint) ? *t : '#';
  *s = '\0';
  mputs(buffer);
  if(len > restlen)
    mputs("...");
  mputc('\n');
}

variable_types: pos int

variable_types: rep int

variable_types:
type
char *

variable_types: i int

variable_types: textlen int

variable_types: restlen int

variable_types:
s
char *

variable_types:
t
char *

variable_types:
buffer
char [77]


original_code:
void primitives_find(primitives_struct *p)
{
  pr_node *n,*n_next,*nn,*new_n;
  pr_list *l,*l_next,*maxlist;
  pr_entry *e,*ee;
  int i, maxlistlen, pos;
  pr_create_basic_lists(p);
  for(i=1; i<p->length && p->nodes!=((void *)0); i++) {
    pr_report(p,i);
    pr_next_level(p);
    for(n=p->nodes2; n!=((void *)0); n=n_next) {
      n_next = n->next;
      maxlistlen = 0;
      for(l=n->lists; l!=((void *)0); l=l->next)
        if(l->len > maxlistlen) {
          maxlistlen = l->len;
          maxlist = l;
        }
      for(l=n->lists; l!=((void *)0); l=l_next) {
        l_next = l->next;
        if(l == maxlist)
          pr_remove_list(l);
        else
          pr_replace_list(p,l);
        if(l->len == 1)
          l->entries->inList = ((void *)0);
        else {
          new_n = pr_new_node(p);
          pr_append_node(p,new_n);
          pr_append_list(l,new_n);
        }
      }
    }
    for(n=p->nodes2; n!=((void *)0); n=n->next)
      for(l=n->lists; l!=((void *)0); l=l->next)
        for(e=l->entries; e!=((void *)0); e=e->next) {
          pos = e-p->entries2;
          if(pos != 0) {
            ee = &p->entries[pos-1];
            if(ee->inList != ((void *)0)) {
              nn = ee->inList->atNode;
              if(nn->last_source_list != l) {
                pr_append_list(pr_new_list(p),nn);
                nn->last_source_list = l;
              }
              pr_move_entry(ee,nn->last);
            }
          }
          p->num_compares++;
        }
    pr_remove_entry(&p->entries[p->length-i]);
    p->num_compares++;
  }
}

canonical_original_code:
void primitives_find(struct PRIMITIVES_STRUCT *p)
{
  struct PRIMITIVES_NODE *n; struct PRIMITIVES_NODE *n_next; struct PRIMITIVES_NODE *nn; struct PRIMITIVES_NODE *new_n;
  struct PRIMITIVES_LIST *l; struct PRIMITIVES_LIST *l_next; struct PRIMITIVES_LIST *maxlist;
  struct PRIMITIVES_ENTRY *e; struct PRIMITIVES_ENTRY *ee;
  int i; int maxlistlen; int pos;
  pr_create_basic_lists(p);
  for(i=1; i<p->length && p->nodes!=((void *)0); i++) {
    pr_report(p,i);
    pr_next_level(p);
    for(n=p->nodes2; n!=((void *)0); n=n_next) {
      n_next = n->next;
      maxlistlen = 0;
      for(l=n->lists; l!=((void *)0); l=l->next)
        if(l->len > maxlistlen) {
          maxlistlen = l->len;
          maxlist = l;
        }
      for(l=n->lists; l!=((void *)0); l=l_next) {
        l_next = l->next;
        if(l == maxlist)
          pr_remove_list(l);
        else
          pr_replace_list(p,l);
        if(l->len == 1)
          l->entries->inList = ((void *)0);
        else {
          new_n = pr_new_node(p);
          pr_append_node(p,new_n);
          pr_append_list(l,new_n);
        }
      }
    }
    for(n=p->nodes2; n!=((void *)0); n=n->next)
      for(l=n->lists; l!=((void *)0); l=l->next)
        for(e=l->entries; e!=((void *)0); e=e->next) {
          pos = e-p->entries2;
          if(pos != 0) {
            ee = &p->entries[pos-1];
            if(ee->inList != ((void *)0)) {
              nn = ee->inList->atNode;
              if(nn->last_source_list != l) {
                pr_append_list(pr_new_list(p),nn);
                nn->last_source_list = l;
              }
              pr_move_entry(ee,nn->last);
            }
          }
          p->num_compares++;
        }
    pr_remove_entry(&p->entries[p->length-i]);
    p->num_compares++;
  }
}

variable_types: maxlistlen int


original_code:
char *naive_search(NAIVE_STRUCT *node, char *T, int N, int initmatch)
{
  int j, k, M;
  char *P;
  T--;
  P = node->S;
  M = node->M;
  k = (!initmatch ? 1 : 2);
  for ( ; k + M <= N; k++) {
    j = 0;
    while (1 + j <= M && P[1+j] == T[k+j]) {
      j++;
      node->num_compares++;
    }
    node->num_compares++;
    if (j == M)
      return &T[k];
  }
  return ((void *)0);
}

canonical_original_code:
char *naive_search(struct NAIVE_STRUCT *node, char *T, int N, int initmatch)
{
  int j; int k; int M;
  char *P;
  T--;
  P = node->S;
  M = node->M;
  k = (!initmatch ? 1 : 2);
  for ( ; k + M <= N; k++) {
    j = 0;
    while (1 + j <= M && P[1+j] == T[k+j]) {
      j++;
      node->num_compares++;
    }
    node->num_compares++;
    if (j == M)
      return &T[k];
  }
  return ((void *)0);
}

variable_types: struct NAIVE_STRUCT { char *S; int M; int num_compares; } *

variable_types:
T
char *

variable_types: N int

variable_types: initmatch int

variable_types: j int

variable_types: k int

variable_types: M int

variable_types:
P
char *


decompiled_code:
void __fastcall naive_free(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
free(ptr);
}
}

original_code:
void naive_free(NAIVE_STRUCT *node)
{
  if (node == ((void *)0))
    return;
  if (node->copyflag && node->S != ((void *)0))
    free(node->S);
  free(node);
}

canonical_original_code:
void naive_free(struct NAIVE_STRUCT *node)
{
  if (node == ((void *)0))
    return;
  if (node->copyflag && node->S != ((void *)0))
    free(node->S);
  free(node);
}

user_defined_types: struct NAIVE_STRUCT { char *S; int M; int num_compares; }


decompiled_code:
_OWORD *alloc_match()
{
_OWORD *result; // rax
__int64 v1; // rdx

result = (_OWORD *)freelist;
if ( freelist )
{
v1 = *(_QWORD *)(freelist + 24);
*(_OWORD *)freelist = 0LL;
freelist = v1;
result[1] = 0LL;
}
else
{
result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
}
return result;
}

canonical_decompiled_code:
_OWORD *func0()
{
_OWORD *result; // rax
__int64 v1; // rdx

result = (_OWORD *)freelist;
if ( freelist )
{
v1 = *(_QWORD *)(freelist + 24);
*(_OWORD *)freelist = 0LL;
freelist = v1;
result[1] = 0LL;
}
else
{
result = malloc(0x20uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
}
return result;
}

original_code:
MATCH_NODE *alloc_match(void)
{
  MATCH_NODE *temp;
  if (!freelist) {
    if ((temp = malloc(sizeof(MATCH_NODE))) == ((void *)0))
      return ((void *)0);
  }
  else {
    temp = freelist;
    freelist = freelist->next;
  }
  memset(temp, 0, sizeof(MATCH_NODE));
  return temp;
}

canonical_original_code:
struct matchnode *alloc_match()
{
  struct matchnode *temp;
  if (!freelist) {
    if ((temp = malloc(sizeof(MATCH_NODE))) == ((void *)0))
      return ((void *)0);
  }
  else {
    temp = freelist;
    freelist = freelist->next;
  }
  memset(temp, 0, sizeof(MATCH_NODE));
  return temp;
}

variable_types: struct matchnode { int type; int lend; struct matchnode *next; } *


original_code:
static void init_tables(void)
{
  int i, j, lsb, msb, mask;
  j = 1;
  msb = -1;
  for (i=1; i < 256; i++) {
    if (i == j) {
      j <<= 1;
      msb++;
    }
    msb_table[i] = msb;
    for (lsb=0,mask=1; !(mask & i); lsb++,mask<<=1) ;
    lsb_table[i] = lsb;
  }
  init_flag = 1;
}

canonical_original_code:
static void init_tables()
{
  int i; int j; int lsb; int msb; int mask;
  j = 1;
  msb = -1;
  for (i=1; i < 256; i++) {
    if (i == j) {
      j <<= 1;
      msb++;
    }
    msb_table[i] = msb;
    for (lsb=0,mask=1; !(mask & i); lsb++,mask<<=1) ;
    lsb_table[i] = lsb;
  }
  init_flag = 1;
}

variable_types: lsb int

variable_types: msb int

variable_types: mask int


h

decompiled_code:
__int64 __fastcall h(unsigned int a1)
{
__int64 result; // rax

if ( !init_flag )
init_tables();
if ( (_BYTE)a1 )
return (unsigned int)lsb_table[(unsigned __int8)a1];
if ( BYTE1(a1) )
return (unsigned int)(lsb_table[BYTE1(a1)] + 8);
if ( BYTE2(a1) )
return (unsigned int)(lsb_table[BYTE2(a1)] + 16);
result = 32LL;
if ( HIBYTE(a1) )
result = (unsigned int)(lsb_table[HIBYTE(a1)] + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 result; // rax

if ( !init_flag )
func0();
if ( (_BYTE)a1 )
return (unsigned int)lsb_table[(unsigned __int8)a1];
if ( BYTE1(a1) )
return (unsigned int)(lsb_table[BYTE1(a1)] + 8);
if ( BYTE2(a1) )
return (unsigned int)(lsb_table[BYTE2(a1)] + 16);
result = 32LL;
if ( HIBYTE(a1) )
result = (unsigned int)(lsb_table[HIBYTE(a1)] + 24);
return result;
}

original_code:
static unsigned int h(unsigned int number)
{
  if (!init_flag)
    init_tables();
  if (number & 0xff)
    return lsb_table[number & 0xff];
  number >>= 8;
  if (number & 0xff)
    return 8 + lsb_table[number & 0xff];
  number >>= 8;
  if (number & 0xff)
    return 16 + lsb_table[number & 0xff];
  number >>= 8;
  if (number & 0xff)
    return 24 + lsb_table[number & 0xff];
  return 32;
}

variable_types:
number
unsigned int

return_type: unsigned int


MSB

decompiled_code:
__int64 __fastcall MSB(unsigned int a1)
{
__int64 v1; // r9
__int64 result; // rax

v1 = a1;
if ( !init_flag )
init_tables();
if ( (v1 & 0xFF000000) != 0 )
return (unsigned int)(msb_table[BYTE3(v1)] + 24);
if ( (v1 & 0xFF0000) != 0 )
return (unsigned int)(msb_table[WORD1(v1)] + 16);
if ( (v1 & 0xFF00) != 0 )
return (unsigned int)(msb_table[(unsigned int)v1 >> 8] + 8);
result = 32LL;
if ( (_BYTE)v1 )
result = (unsigned int)msb_table[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // r9
__int64 result; // rax

v1 = a1;
if ( !init_flag )
func0();
if ( (v1 & 0xFF000000) != 0 )
return (unsigned int)(msb_table[BYTE3(v1)] + 24);
if ( (v1 & 0xFF0000) != 0 )
return (unsigned int)(msb_table[WORD1(v1)] + 16);
if ( (v1 & 0xFF00) != 0 )
return (unsigned int)(msb_table[(unsigned int)v1 >> 8] + 8);
result = 32LL;
if ( (_BYTE)v1 )
result = (unsigned int)msb_table[v1];
return result;
}

original_code:
static unsigned int MSB(unsigned int number)
{
  if (!init_flag)
    init_tables();
  if (number & (0xff << 24))
    return 24 + msb_table[number >> 24];
  if (number & (0xff << 16))
    return 16 + msb_table[number >> 16];
  if (number & (0xff << 8))
    return 8 + msb_table[number >> 8];
  if (number & 0xff)
    return msb_table[number];
  return 32;
}


decompiled_code:
__int64 __fastcall strmat_repeats_primitives(__int64 a1, int a2)
{
__int64 v3; // r12

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
if ( !*(_DWORD *)(a1 + 24) )
return 0LL;
mprintf("Preprocessing...\n");
v3 = primitives_prep(*(_QWORD *)a1, *(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 24));
if ( !v3 )
return 0LL;
mprintf("\nThe following primitive tandem repeats were found:\n\n");
primitives_find(v3);
mend(17LL);
mstart(stdin, stdout, 1LL, 1LL, 0LL, 0LL);
mprintf("\nSummary:\n");
mprintf(" Primitive Tandem Repeat Occurrences: %d\n", *(unsigned int *)(v3 + 116));
if ( a2 )
{
mprintf("\nStatistics:\n");
mprintf(" String Length: %d\n", *(unsigned int *)(a1 + 24));
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v3 + 120));
mprintf("\n");
}
primitives_free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 v3; // r12

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
if ( !*(_DWORD *)(a1 + 24) )
return 0LL;
mprintf("Preprocessing...\n");
v3 = primitives_prep(*(_QWORD *)a1, *(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 24));
if ( !v3 )
return 0LL;
mprintf("\nThe following primitive tandem repeats were found:\n\n");
primitives_find(v3);
mend(17LL);
mstart(stdin, stdout, 1LL, 1LL, 0LL, 0LL);
mprintf("\nSummary:\n");
mprintf(" Primitive Tandem Repeat Occurrences: %d\n", *(unsigned int *)(v3 + 116));
if ( a2 )
{
mprintf("\nStatistics:\n");
mprintf(" String Length: %d\n", *(unsigned int *)(a1 + 24));
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v3 + 120));
mprintf("\n");
}
primitives_free(v3);
return 1LL;
}

original_code:
int strmat_repeats_primitives(STRING *string, int print_stats)
{
  primitives_struct *pr_struct;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  mprintf("Preprocessing...\n");
  pr_struct = primitives_prep(string->sequence,string->raw_seq,string->length);
  if(pr_struct == ((void *)0))
    return 0;
  mprintf("\nThe following primitive tandem repeats were found:\n\n");
  primitives_find(pr_struct);
  mend(17);
  mstart(stdin, stdout, 1, 1, 0, ((void *)0));
  mprintf("\nSummary:\n");
  mprintf("   Primitive Tandem Repeat Occurrences: %d\n",
          pr_struct->num_primitive_tandem_repeat_occs);
  if (print_stats) {
    mprintf("\nStatistics:\n");
    mprintf("   String Length:          %d\n", string->length);
    mprintf("   Number of Compares:     %d\n", pr_struct->num_compares);
    mprintf("\n");
  }
  primitives_free(pr_struct);
  return 1;
}

canonical_original_code:
int strmat_repeats_primitives(struct STRING *string, int print_stats)
{
  struct PRIMITIVES_STRUCT *pr_struct;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  mprintf("Preprocessing...\n");
  pr_struct = primitives_prep(string->sequence,string->raw_seq,string->length);
  if(pr_struct == ((void *)0))
    return 0;
  mprintf("\nThe following primitive tandem repeats were found:\n\n");
  primitives_find(pr_struct);
  mend(17);
  mstart(stdin, stdout, 1, 1, 0, ((void *)0));
  mprintf("\nSummary:\n");
  mprintf("   Primitive Tandem Repeat Occurrences: %d\n",
          pr_struct->num_primitive_tandem_repeat_occs);
  if (print_stats) {
    mprintf("\nStatistics:\n");
    mprintf("   String Length:          %d\n", string->length);
    mprintf("   Number of Compares:     %d\n", pr_struct->num_compares);
    mprintf("\n");
  }
  primitives_free(pr_struct);
  return 1;
}

variable_types: struct STRING { char *sequence; int length; int alpha_size; char ident[-1]; } *

variable_types: struct PRIMITIVES_STRUCT { char *string; int length; struct PRIMITIVES_ENTRY { struct PRIMITIVES_ENTRY *next; struct PRIMITIVES_LIST { struct PRIMITIVES_LIST *next; struct PRIMITIVES_NODE { struct PRIMITIVES_NODE *next; struct PRIMITIVES_STRUCT *inNodelist; struct PRIMITIVES_LIST *lists; } *atNode; struct PRIMITIVES_ENTRY *entries; int len; } *inList; } *entries; struct PRIMITIVES_LIST *lists; int nextList; struct PRIMITIVES_NODE *nodelist; int nextNode; unsigned int num_primitive_tandem_repeat_occs; unsigned int num_compares; } *


decompiled_code:
__int64 __fastcall strmat_repeats_nonoverlapping(__int64 a1, int a2)
{
__int64 v3; // r12

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
if ( !*(_DWORD *)(a1 + 24) )
return 0LL;
mprintf("Preprocessing...\n");
v3 = nonoverlapping_prep(*(_QWORD *)a1, *(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 24));
if ( !v3 )
return 0LL;
mprintf("\nThe following nonoverlapping maximal pairs were found:\n\n");
nonoverlapping_find(v3);
mend(17LL);
mstart(stdin, stdout, 1LL, 1LL, 0LL, 0LL);
mprintf("\nSummary:\n");
mprintf(" Nonoverlapping Maximal Pairs: %d\n", *(unsigned int *)(v3 + 284));
if ( a2 )
{
mprintf("\nStatistics:\n");
mprintf(" String Length: %d\n", *(unsigned int *)(a1 + 24));
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v3 + 288));
mprintf("\n");
}
nonoverlapping_free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v3; // r12

if ( !a1 )
return 0LL;
if ( !*(_QWORD *)a1 )
return 0LL;
if ( !*(_DWORD *)(a1 + 24) )
return 0LL;
mprintf("Preprocessing...\n");
v3 = nonoverlapping_prep(*(_QWORD *)a1, *(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 24));
if ( !v3 )
return 0LL;
mprintf("\nThe following nonoverlapping maximal pairs were found:\n\n");
nonoverlapping_find(v3);
mend(17LL);
mstart(stdin, stdout, 1LL, 1LL, 0LL, 0LL);
mprintf("\nSummary:\n");
mprintf(" Nonoverlapping Maximal Pairs: %d\n", *(unsigned int *)(v3 + 284));
if ( a2 )
{
mprintf("\nStatistics:\n");
mprintf(" String Length: %d\n", *(unsigned int *)(a1 + 24));
mprintf(" Number of Compares: %d\n", *(unsigned int *)(v3 + 288));
mprintf("\n");
}
nonoverlapping_free(v3);
return 1LL;
}

original_code:
int strmat_repeats_nonoverlapping(STRING *string, int print_stats)
{
  nonoverlapping_struct *no_struct;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  mprintf("Preprocessing...\n");
  no_struct = nonoverlapping_prep(string->sequence,string->raw_seq,
                                  string->length);
  if(no_struct == ((void *)0))
    return 0;
  mprintf("\nThe following nonoverlapping maximal pairs were found:\n\n");
  nonoverlapping_find(no_struct);
  mend(17);
  mstart(stdin, stdout, 1, 1, 0, ((void *)0));
  mprintf("\nSummary:\n");
  mprintf("   Nonoverlapping Maximal Pairs: %d\n",
          no_struct->num_nonoverlapping_maximal_pairs);
  if (print_stats) {
    mprintf("\nStatistics:\n");
    mprintf("   String Length:          %d\n", string->length);
    mprintf("   Number of Compares:     %d\n", no_struct->num_compares);
    mprintf("\n");
  }
  nonoverlapping_free(no_struct);
  return 1;
}

canonical_original_code:
int strmat_repeats_nonoverlapping(struct STRING *string, int print_stats)
{
  struct NONOVERLAPPING_STRUCT *no_struct;
  if (string == ((void *)0) || string->sequence == ((void *)0) || string->length == 0)
    return 0;
  mprintf("Preprocessing...\n");
  no_struct = nonoverlapping_prep(string->sequence,string->raw_seq,
                                  string->length);
  if(no_struct == ((void *)0))
    return 0;
  mprintf("\nThe following nonoverlapping maximal pairs were found:\n\n");
  nonoverlapping_find(no_struct);
  mend(17);
  mstart(stdin, stdout, 1, 1, 0, ((void *)0));
  mprintf("\nSummary:\n");
  mprintf("   Nonoverlapping Maximal Pairs: %d\n",
          no_struct->num_nonoverlapping_maximal_pairs);
  if (print_stats) {
    mprintf("\nStatistics:\n");
    mprintf("   String Length:          %d\n", string->length);
    mprintf("   Number of Compares:     %d\n", no_struct->num_compares);
    mprintf("\n");
  }
  nonoverlapping_free(no_struct);
  return 1;
}

variable_types: struct NONOVERLAPPING_STRUCT { char *string_space; int length; char a[-1]; int alpha_size; struct NONOVERLAPPING_ENTRY { struct NONOVERLAPPING_ENTRY *next; struct NONOVERLAPPING_LIST { struct NONOVERLAPPING_LIST *next; struct NONOVERLAPPING_NODE { struct NONOVERLAPPING_NODE *next; struct NONOVERLAPPING_STRUCT *inNodelist; struct NONOVERLAPPING_LIST *lists; } *atNode; struct NONOVERLAPPING_ENTRY **entries; int len; } *inList; } *entries; struct NONOVERLAPPING_LIST *lists; int nextList; struct NONOVERLAPPING_NODE *nodelist; int nextNode; unsigned int num_nonoverlapping_maximal_pairs; unsigned int num_compares; } *

user_defined_types: struct NONOVERLAPPING_STRUCT { char *string_space; int length; char a[-1]; int alpha_size; struct NONOVERLAPPING_ENTRY *entries; struct NONOVERLAPPING_LIST *lists; int nextList; struct NONOVERLAPPING_NODE *nodelist; int nextNode; unsigned int num_nonoverlapping_maximal_pairs; unsigned int num_compares; }

user_defined_types: struct NONOVERLAPPING_ENTRY { struct NONOVERLAPPING_ENTRY *next; struct NONOVERLAPPING_LIST *inList; }

user_defined_types: struct NONOVERLAPPING_LIST { struct NONOVERLAPPING_LIST *next; struct NONOVERLAPPING_NODE *atNode; struct NONOVERLAPPING_ENTRY **entries; int len; }


decompiled_code:
_BOOL8 __fastcall lvals_init(int a1)
{
stack = calloc(8LL * a1, 1uLL);
return stack != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1)
{
stack = calloc(8LL * a1, 1uLL);
return stack != 0LL;
}

original_code:
int lvals_init(int num_nodes)
{
  if ((stack = malloc(num_nodes * sizeof(LEFTVALS))) == ((void *)0))
    return 0;
  memset(stack, 0, num_nodes * sizeof(LEFTVALS));
  return 1;
}


original_code:
char *kmp_search(KMP_STRUCT *node, char *T, int N, int initmatch)
{
  int p, c, M, *F;
  char *P;
  T--;
  P = node->P;
  M = node->M;
  F = node->F;
  if (!initmatch) {
    c = 1;
    p = 1;
  }
  else {
    c = M + 1;
    p = F[M+1];
    node->total_shifts += M+1 - F[M+1];
    node->num_shifts++;
  }
  while (c <= N) {
    while (p <= M && c <= N && P[p] == T[c]) {
      c++;
      p++;
      node->num_compares++;
    }
    node->num_compares++;
    if (p == M + 1)
      return &T[c-M];
    else if (p == 1) {
      c++;
      node->num_init_mismatch++;
    }
    else {
      node->total_shifts += p - F[p];
      p = F[p];
      node->num_shifts++;
    }
  }
  return ((void *)0);
}

canonical_original_code:
char *kmp_search(struct KMP_STRUCT *node, char *T, int N, int initmatch)
{
  int p; int c; int M; int *F;
  char *P;
  T--;
  P = node->P;
  M = node->M;
  F = node->F;
  if (!initmatch) {
    c = 1;
    p = 1;
  }
  else {
    c = M + 1;
    p = F[M+1];
    node->total_shifts += M+1 - F[M+1];
    node->num_shifts++;
  }
  while (c <= N) {
    while (p <= M && c <= N && P[p] == T[c]) {
      c++;
      p++;
      node->num_compares++;
    }
    node->num_compares++;
    if (p == M + 1)
      return &T[c-M];
    else if (p == 1) {
      c++;
      node->num_init_mismatch++;
    }
    else {
      node->total_shifts += p - F[p];
      p = F[p];
      node->num_shifts++;
    }
  }
  return ((void *)0);
}

variable_types: struct KMP_STRUCT { char *P; int M; int *F; int prep_compares; int num_shifts; } *

variable_types: p int

variable_types: c int

variable_types:
F
int *


decompiled_code:
void __fastcall kmp_free(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void *v3; // rdi

if ( ptr )
{
if ( *((_DWORD *)ptr + 3) )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
}
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void kmp_free(KMP_STRUCT *node)
{
  if (node == ((void *)0))
    return;
  if (node->copyflag && node->P != ((void *)0))
    free(node->P);
  if (node->F != ((void *)0))
    free(node->F);
  free(node);
}

canonical_original_code:
void kmp_free(struct KMP_STRUCT *node)
{
  if (node == ((void *)0))
    return;
  if (node->copyflag && node->P != ((void *)0))
    free(node->P);
  if (node->F != ((void *)0))
    free(node->F);
  free(node);
}

user_defined_types: struct KMP_STRUCT { char *P; int M; int *F; int prep_compares; int num_shifts; }


decompiled_code:
__int64 __fastcall grow_links(int a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // ebp
char *v4; // rax

result = 1LL;
v2 = links_size;
if ( links_size <= a1 )
{
v3 = 2 * links_size;
if ( a1 >= 2 * links_size )
v3 = a1 + 1;
v4 = (char *)realloc(links, 8LL * v3);
links = v4;
if ( v4 )
{
if ( (int)v2 < v3 )
memset(&v4[8 * v2], 0, 8LL * (unsigned int)(v3 + ~(_DWORD)v2) + 8);
links_size = v3;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // ebp
char *v4; // rax

result = 1LL;
v2 = links_size;
if ( links_size <= a1 )
{
v3 = 2 * links_size;
if ( a1 >= 2 * links_size )
v3 = a1 + 1;
v4 = (char *)realloc(links, 8LL * v3);
links = v4;
if ( v4 )
{
if ( (int)v2 < v3 )
memset(&v4[8 * v2], 0, 8LL * (unsigned int)(v3 + ~(_DWORD)v2) + 8);
links_size = v3;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
static int grow_links(int newid)
{
  int i, newsize;
  if (newid < links_size)
    return 1;
  newsize = links_size + links_size;
  if (newid >= newsize)
    newsize = newid + 1;
  if ((links = realloc(links, newsize * sizeof(LINKS))) == ((void *)0))
    return 0;
  for (i=links_size; i < newsize; i++)
    links[i] = ((void *)0);
  links_size = newsize;
  return 1;
}

canonical_original_code:
static int grow_links(int newid)
{
  int i; int newsize;
  if (newid < links_size)
    return 1;
  newsize = links_size + links_size;
  if (newid >= newsize)
    newsize = newid + 1;
  if ((links = realloc(links, newsize * sizeof(LINKS))) == ((void *)0))
    return 0;
  for (i=links_size; i < newsize; i++)
    links[i] = ((void *)0);
  links_size = newsize;
  return 1;
}

variable_types: newid int

variable_types: i int

variable_types: newsize int


main

canonical_name: main

repo: cheydrick/Canonical-Arduino-Read

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v4; // ebx
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // rbp
__int64 v8; // rdx
__int64 v9; // rsi
struct termios v11; // [rsp+0h] [rbp-98h] BYREF
char v12; // [rsp+3Fh] [rbp-59h]
__int128 buf[5]; // [rsp+40h] [rbp-58h] BYREF

buf[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402090);
buf[1] = 0LL;
buf[2] = 0LL;
buf[3] = 0LL;
v3 = (unsigned int)open("/dev/ttyACM0", 258, envp);
printf("fd opened as %i\n", v3);
usleep(0x3567E0u);
tcgetattr(v3, &v11);
cfsetispeed(&v11, 0xDu);
cfsetospeed(&v11, 0xDu);
v11.c_lflag |= 2u;
v11.c_cflag = v11.c_cflag & 0xFFFFFE8F | 0x30;
tcsetattr(v3, 0, &v11);
write(v3, "0", 1uLL);
v4 = read(v3, buf, 0x40uLL);
*((_BYTE *)buf + v4) = 0;
printf("%i bytes read, buffer contains: %s\n", (unsigned int)v4, (const char *)buf);
puts("Printing individual characters in buf as integers...\n");
if ( v4 > 0 )
{
v5 = (unsigned int)(v4 - 1);
v6 = 1LL;
v7 = v5 + 2;
do
{
v8 = (unsigned int)*(&v12 + v6);
v9 = (unsigned int)v6++;
printf("Byte %i:%i, ", v9, v8);
}
while ( v6 != v7 );
}
putchar(10);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int fd, n, i;
  char buf[64] = "temp text";
  struct termios toptions;
  fd = open("/dev/ttyACM0", 02 | 0400);
  printf("fd opened as %i\n", fd);
  usleep(3500000);
  tcgetattr(fd, &toptions);
  cfsetispeed(&toptions, 0000015);
  cfsetospeed(&toptions, 0000015);
  toptions.c_cflag &= ~0000400;
  toptions.c_cflag &= ~0000100;
  toptions.c_cflag &= ~0000060;
  toptions.c_cflag |= 0000060;
  toptions.c_lflag |= 0000002;
  tcsetattr(fd, 0, &toptions);
  write(fd, "0", 1);
  n = read(fd, buf, 64);
  buf[n] = 0;
  printf("%i bytes read, buffer contains: %s\n", n, buf);
  if(1)
    {
      printf("Printing individual characters in buf as integers...\n\n");
      for(i=0; i<n; i++)
 {
   printf("Byte %i:%i, ",i+1, (int)buf[i]);
 }
      printf("\n");
    }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int fd; int n; int i;
  char buf[64] = "temp text";
  struct termios toptions;
  fd = open("/dev/ttyACM0", 02 | 0400);
  printf("fd opened as %i\n", fd);
  usleep(3500000);
  tcgetattr(fd, &toptions);
  cfsetispeed(&toptions, 0000015);
  cfsetospeed(&toptions, 0000015);
  toptions.c_cflag &= ~0000400;
  toptions.c_cflag &= ~0000100;
  toptions.c_cflag &= ~0000060;
  toptions.c_cflag |= 0000060;
  toptions.c_lflag |= 0000002;
  tcsetattr(fd, 0, &toptions);
  write(fd, "0", 1);
  n = read(fd, buf, 64);
  buf[n] = 0;
  printf("%i bytes read, buffer contains: %s\n", n, buf);
  if(1)
    {
      printf("Printing individual characters in buf as integers...\n\n");
      for(i=0; i<n; i++)
 {
   printf("Byte %i:%i, ",i+1, (int)buf[i]);
 }
      printf("\n");
    }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fd int

variable_types: n int

variable_types:
buf
char [64]

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


repo: chhquan/fibacap

original_code:
const char *fbc_ether_addr_to_string(const struct ether_addr *enaddr, char *addr_string, int max_size)
{
 sprintf(addr_string, "%02x:%02x:%02x:%02x:%02x:%02x",
   enaddr->ether_addr_octet[0], enaddr->ether_addr_octet[1],
   enaddr->ether_addr_octet[2], enaddr->ether_addr_octet[3],
   enaddr->ether_addr_octet[4], enaddr->ether_addr_octet[5]);
 return addr_string;
}

canonical_original_code:
char *fbc_ether_addr_to_string(struct ether_addr *enaddr, char *addr_string, int max_size)
{
 sprintf(addr_string, "%02x:%02x:%02x:%02x:%02x:%02x",
   enaddr->ether_addr_octet[0], enaddr->ether_addr_octet[1],
   enaddr->ether_addr_octet[2], enaddr->ether_addr_octet[3],
   enaddr->ether_addr_octet[4], enaddr->ether_addr_octet[5]);
 return addr_string;
}

variable_types: struct ether_addr { unsigned char ether_addr_octet[6]; } *


decompiled_code:
const char *__fastcall fbc_ip_addr_to_string(void *cp, char *buf, socklen_t len)
{
return inet_ntop(2, cp, buf, len);
}

canonical_decompiled_code:
const char *__fastcall func1(void *cp, char *buf, socklen_t len)
{
return inet_ntop(2, cp, buf, len);
}

original_code:
const char *fbc_ip_addr_to_string(const void *src, char *addr_string, int max_size)
{
 return inet_ntop(2, src, addr_string, max_size);
}

canonical_original_code:
char *fbc_ip_addr_to_string(void *src, char *addr_string, int max_size)
{
 return inet_ntop(2, src, addr_string, max_size);
}

variable_types:
src
void *


decompiled_code:
char *__fastcall fbc_get_addr_string(__int64 a1, unsigned __int8 *a2, socklen_t a3, char *a4)
{
if ( a4 == 0LL || a2 == 0LL || !a1 )
return 0LL;
if ( !strcmp((const char *)a1, "ETHER") )
return fbc_ether_addr_to_string(a2, a4);
if ( *(_BYTE *)a1 == 73 && *(_BYTE *)(a1 + 1) == 80 && !*(_BYTE *)(a1 + 2) )
return (char *)fbc_ip_addr_to_string(a2, a4, a3);
return (char *)&unk_330;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, unsigned __int8 *a2, socklen_t a3, char *a4)
{
if ( a4 == 0LL || a2 == 0LL || !a1 )
return 0LL;
if ( !strcmp((const char *)a1, "ETHER") )
return func0(a2, a4);
if ( *(_BYTE *)a1 == 73 && *(_BYTE *)(a1 + 1) == 80 && !*(_BYTE *)(a1 + 2) )
return (char *)func1(a2, a4, a3);
return (char *)&unk_330;
}

original_code:
const char *fbc_get_addr_string(protocol_t p, Byte *addr, int len, char *addrstring) {
 if (!p || !addr || !addrstring) return ((void *)0);
 if ((strcmp((p), ("ETHER")) == 0)) {
  return fbc_ether_addr_to_string((const struct ether_addr *)addr, addrstring, len);
 }
 if ((strcmp((p), ("IP")) == 0)) {
  return fbc_ip_addr_to_string((const void *)addr, addrstring, len);
 }
 return "";
}

canonical_original_code:
char *fbc_get_addr_string(char p[16], unsigned char *addr, int len, char *addrstring) {
 if (!p || !addr || !addrstring) return ((void *)0);
 if ((strcmp((p), ("ETHER")) == 0)) {
  return fbc_ether_addr_to_string((struct ether_addr *)addr, addrstring, len);
 }
 if ((strcmp((p), ("IP")) == 0)) {
  return fbc_ip_addr_to_string((void *)addr, addrstring, len);
 }
 return "";
}

variable_types:
p
char [16]

variable_types:
addr
unsigned char *

variable_types: len int

variable_types:
addrstring
char *

user_defined_types: struct ether_addr { unsigned char ether_addr_octet[6]; }