original_code:
alignment* construct_alignment(int* C,int* E, int* R, char*u,int m,char* v, int n,int (*costFunc)(char,char))
{
  int j = n;
  int i,temp,a,b,c,cost;
  char vci;
  int in = costFunc('x','-');
  int del = costFunc('-','x');
  alignment* alignout = alignment_new(u,m,v,n);
  while (j > 0)
  {
    if (C[j] != C[j-1])
    {
        E[0] = in;
        R[0] = 'l';
        vci = v[j-1];
        for(i = 1; i <= C[j]-C[j-1]; i++)
        {
          a = (i-1)*del + costFunc(u[i+C[j-1]+1-2], vci);
          b = i*del + in;
          c = E[i-1] + del;
          cost = ((a < ((b < c) ? b : c)) ? a : ((b < c) ? b : c));
          if (cost == a)
            R[i] = 'd';
          else if (cost == c)
            R[i] = 'o';
          else
            R[i] = 'l';
          E[i] = cost;
        }
        i = C[j]-C[j-1];
        while (i >= 0)
        {
          if (R[i] == 'd')
          {
            alignment_add_replacement(alignout);
            alignment_add_deletions(alignout,i-1);
            i = -1;
          }
          else if (R[i] == 'l')
          {
            alignment_add_insertion(alignout);
            alignment_add_deletions(alignout,i);
            i = -1;
          }
          else
          {
            alignment_add_deletion(alignout);
            i--;
          }
        }
    }
    else
    {
      alignment_add_insertion(alignout);
    }
    j--;
  }
  alignment_reverse(alignout);
  return alignout;
}

canonical_original_code:
struct alignmentStruct *construct_alignment(int *C, int *E, int *R, char *u, int m, char *v, int n, int (*costFunc)(char, char))
{
  int j = n;
  int i; int temp; int a; int b; int c; int cost;
  char vci;
  int in = costFunc('x','-');
  int del = costFunc('-','x');
  struct alignmentStruct *alignout = alignment_new(u,m,v,n);
  while (j > 0)
  {
    if (C[j] != C[j-1])
    {
        E[0] = in;
        R[0] = 'l';
        vci = v[j-1];
        for(i = 1; i <= C[j]-C[j-1]; i++)
        {
          a = (i-1)*del + costFunc(u[i+C[j-1]+1-2], vci);
          b = i*del + in;
          c = E[i-1] + del;
          cost = ((a < ((b < c) ? b : c)) ? a : ((b < c) ? b : c));
          if (cost == a)
            R[i] = 'd';
          else if (cost == c)
            R[i] = 'o';
          else
            R[i] = 'l';
          E[i] = cost;
        }
        i = C[j]-C[j-1];
        while (i >= 0)
        {
          if (R[i] == 'd')
          {
            alignment_add_replacement(alignout);
            alignment_add_deletions(alignout,i-1);
            i = -1;
          }
          else if (R[i] == 'l')
          {
            alignment_add_insertion(alignout);
            alignment_add_deletions(alignout,i);
            i = -1;
          }
          else
          {
            alignment_add_deletion(alignout);
            i--;
          }
        }
    }
    else
    {
      alignment_add_insertion(alignout);
    }
    j--;
  }
  alignment_reverse(alignout);
  return alignout;
}

variable_types: m int

variable_types: n int

variable_types:
costFunc
int (*)(char, char)

variable_types: a int

variable_types: b int

variable_types: vci char

variable_types: struct alignmentStruct { char *s1; int len1; char *s2; int len2; struct multieditStruct { int stretch; char operation; } **edits; int editlength; int length; int maxlen; } *

user_defined_types: struct alignmentStruct { char *s1; int len1; char *s2; int len2; struct multieditStruct **edits; int editlength; int length; int maxlen; }


repo: dr-walfeld/GSA

decompiled_code:
__int64 __fastcall linear_space_alignment(const char *a1, const char *a2, __int64 (__fastcall *a3)(__int64, __int64), _DWORD *a4)
{
unsigned int v5; // ebp
int v6; // er14
_DWORD *v7; // rbx
__int64 v8; // rbp
unsigned int *v10; // [rsp+8h] [rbp-50h]
int *ptr; // [rsp+18h] [rbp-40h]

v5 = strlen(a1);
v6 = strlen(a2);
ptr = (int *)malloc(4LL * (int)(v5 + 1));
v10 = (unsigned int *)malloc(4LL * (int)(v5 + 1));
v7 = malloc(4LL * (v6 + 1));
*v7 = 0;
v7[v6] = v5;
*a4 = evaluatecrosspoints(ptr, v10, (__int64)v7, (__int64)a1, 1u, v5, (__int64)a2, 1, v6, a3);
v8 = construct_alignment((__int64)v7, ptr, v10, (__int64)a1, v5, (__int64)a2, v6, a3);
free(ptr);
free(v10);
free(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2, __int64 (__fastcall *a3)(__int64, __int64), _DWORD *a4)
{
unsigned int v5; // ebp
int v6; // er14
_DWORD *v7; // rbx
__int64 v8; // rbp
unsigned int *v10; // [rsp+8h] [rbp-50h]
int *ptr; // [rsp+18h] [rbp-40h]

v5 = strlen(a1);
v6 = strlen(a2);
ptr = (int *)malloc(4LL * (int)(v5 + 1));
v10 = (unsigned int *)malloc(4LL * (int)(v5 + 1));
v7 = malloc(4LL * (v6 + 1));
*v7 = 0;
v7[v6] = v5;
*a4 = func4(ptr, v10, (__int64)v7, (__int64)a1, 1u, v5, (__int64)a2, 1, v6, a3);
v8 = func5((__int64)v7, ptr, v10, (__int64)a1, v5, (__int64)a2, v6, a3);
free(ptr);
free(v10);
free(v7);
return v8;
}

original_code:
alignment* linear_space_alignment(char* u, char* v, int (*costFunc)(char,char), int* costs)
{
  int m = strlen(u);
  int n = strlen(v);
  int* E = (int*) malloc((m+1)*sizeof(int));
  int* R = (int*) malloc((m+1)*sizeof(int));
  int* C = (int*) malloc((n+1)*sizeof(int));
  C[0] = 0;
  C[n] = m;
  *costs = evaluatecrosspoints(E,R,C,u,1,m,v,1,n,costFunc);
  alignment* a = construct_alignment(C,E,R,u,m,v,n,costFunc);
  free (E);
  free (R);
  free (C);
  return a;
}

canonical_original_code:
struct alignmentStruct *linear_space_alignment(char *u, char *v, int (*costFunc)(char, char), int *costs)
{
  int m = strlen(u);
  int n = strlen(v);
  int *E = (int*) malloc((m+1)*sizeof(int));
  int *R = (int*) malloc((m+1)*sizeof(int));
  int *C = (int*) malloc((n+1)*sizeof(int));
  C[0] = 0;
  C[n] = m;
  *costs = evaluatecrosspoints(E,R,C,u,1,m,v,1,n,costFunc);
  struct alignmentStruct *a = construct_alignment(C,E,R,u,m,v,n,costFunc);
  free (E);
  free (R);
  free (C);
  return a;
}

variable_types:
u
char *

variable_types:
v
char *

variable_types:
costs
int *

variable_types:
E
int *

variable_types:
R
int *

variable_types:
C
int *

return_type: struct alignmentStruct { char *s1; int len1; char *s2; int len2; struct multieditStruct { int stretch; char operation; } **edits; int editlength; int length; int maxlen; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc <= 2 )
{
printf("usage: %s seq1 seq2\n", *argv);
}
else
{
v3 = linear_space_alignment(argv[1], argv[2], (__int64 (__fastcall *)(__int64, __int64))unity, v5);
alignment_show(v3);
alignment_delete(v3);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( argc <= 2 )
{
printf("usage: %s seq1 seq2\n", *argv);
}
else
{
v3 = func6(argv[1], argv[2], (__int64 (__fastcall *)(__int64, __int64))unity, v5);
alignment_show(v3);
alignment_delete(v3);
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
  if (argc < 3)
  {
    printf("usage: %s seq1 seq2\n", argv[0]);
    return 0;
  }
  char* seq1 = argv[1];
  char* seq2 = argv[2];
  int costs;
  alignment* a = linear_space_alignment(seq1,seq2,unity,&costs);
  alignment_show (a);
  alignment_delete(a);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if (argc < 3)
  {
    printf("usage: %s seq1 seq2\n", argv[0]);
    return 0;
  }
  char *seq1 = argv[1];
  char *seq2 = argv[2];
  int costs;
  struct alignmentStruct *a = linear_space_alignment(seq1,seq2,unity,&costs);
  alignment_show (a);
  alignment_delete(a);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: costs int

return_type: int

user_defined_types: struct multieditStruct { int stretch; char operation; }


decompiled_code:
__int64 __fastcall unit_cost(char a1, char a2)
{
return (a2 == 45) | (unsigned __int8)(a1 != a2 || a1 == 45);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char a2)
{
return (a2 == 45) | (unsigned __int8)(a1 != a2 || a1 == 45);
}

original_code:
int unit_cost (char a, char b)
{
  if (a == '-' || b == '-')
    return 1;
  else if (a == b)
    return 0;
  return 1;
}

canonical_original_code:
int unit_cost(char a, char b)
{
  if (a == '-' || b == '-')
    return 1;
  else if (a == b)
    return 0;
  return 1;
}

variable_types: a char

variable_types: b char


original_code:
int alignment_add_operation (alignment* a, char operation)
{
  if (a->editlength > 0 && a->edits[a->editlength-1]->operation == operation)
  {
    a->edits[a->editlength-1]->stretch++;
  }
  else if (a->editlength == 0 || a->edits[a->editlength-1]->operation != operation)
  {
    if (a->editlength == a->maxlen)
      return 1;
    a->edits[a->editlength] = multiedit_new (operation);
    a->editlength++;
  }
  a->length++;
  return 0;
}

canonical_original_code:
int alignment_add_operation(struct alignmentStruct *a, char operation)
{
  if (a->editlength > 0 && a->edits[a->editlength-1]->operation == operation)
  {
    a->edits[a->editlength-1]->stretch++;
  }
  else if (a->editlength == 0 || a->edits[a->editlength-1]->operation != operation)
  {
    if (a->editlength == a->maxlen)
      return 1;
    a->edits[a->editlength] = multiedit_new (operation);
    a->editlength++;
  }
  a->length++;
  return 0;
}

variable_types: struct alignmentStruct { char *s1; int len1; char *s2; int len2; int firstindex1; int lastindex1; int firstindex2; int lastindex2; struct multieditStruct { int stretch; char operation; } **edits; int editlength; int length; int maxlen; } *

variable_types: operation char

user_defined_types: struct alignmentStruct { char *s1; int len1; char *s2; int len2; int firstindex1; int lastindex1; int firstindex2; int lastindex2; struct multieditStruct **edits; int editlength; int length; int maxlen; }


decompiled_code:
__int64 __fastcall alignment_add_operations(__int64 a1, char a2, int a3)
{
int v4; // ebx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
v4 = 0;
do
{
result = alignment_add_operation(a1, a2);
++v4;
}
while ( a3 > v4 && !(_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2, int a3)
{
int v4; // ebx
__int64 result; // rax

if ( a3 <= 0 )
return 0LL;
v4 = 0;
do
{
result = func8(a1, a2);
++v4;
}
while ( a3 > v4 && !(_DWORD)result );
return result;
}

original_code:
int alignment_add_operations (alignment *a, char operation, int length)
{
  int i;
  int s = 0;
  for (i = 0; i < length && s == 0; i++)
  {
    s += alignment_add_operation (a, operation);
  }
  return s;
}

canonical_original_code:
int alignment_add_operations(struct alignmentStruct *a, char operation, int length)
{
  int i;
  int s = 0;
  for (i = 0; i < length && s == 0; i++)
  {
    s += alignment_add_operation (a, operation);
  }
  return s;
}

variable_types: length int

variable_types: i int

variable_types: s int


decompiled_code:
__int64 __fastcall alignment_add_deletion(__int64 a1)
{
return alignment_add_operation(a1, 68);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func8(a1, 68);
}

original_code:
int alignment_add_deletion (alignment* a)
{
  return alignment_add_operation (a, 'D');
}

canonical_original_code:
int alignment_add_deletion(struct alignmentStruct *a)
{
  return alignment_add_operation (a, 'D');
}


decompiled_code:
__int64 __fastcall alignment_add_deletions(__int64 a1, int a2)
{
return alignment_add_operations(a1, 68, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
return func9(a1, 68, a2);
}

original_code:
int alignment_add_deletions (alignment* a, int length)
{
  return alignment_add_operations (a, 'D', length);
}

canonical_original_code:
int alignment_add_deletions(struct alignmentStruct *a, int length)
{
  return alignment_add_operations (a, 'D', length);
}


decompiled_code:
__int64 __fastcall alignment_add_insertion(__int64 a1)
{
return alignment_add_operation(a1, 73);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func8(a1, 73);
}

original_code:
int alignment_add_insertion (alignment* a)
{
  return alignment_add_operation (a, 'I');
}

canonical_original_code:
int alignment_add_insertion(struct alignmentStruct *a)
{
  return alignment_add_operation (a, 'I');
}


decompiled_code:
__int64 __fastcall alignment_add_insertions(__int64 a1, int a2)
{
return alignment_add_operations(a1, 73, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
return func9(a1, 73, a2);
}

original_code:
int alignment_add_insertions (alignment* a, int length)
{
  return alignment_add_operations (a, 'I', length);
}

canonical_original_code:
int alignment_add_insertions(struct alignmentStruct *a, int length)
{
  return alignment_add_operations (a, 'I', length);
}


decompiled_code:
__int64 __fastcall alignment_add_replacement(__int64 a1)
{
return alignment_add_operation(a1, 82);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func8(a1, 82);
}

original_code:
int alignment_add_replacement (alignment* a)
{
  return alignment_add_operation (a, 'R');
}

canonical_original_code:
int alignment_add_replacement(struct alignmentStruct *a)
{
  return alignment_add_operation (a, 'R');
}


decompiled_code:
__int64 __fastcall alignment_add_replacements(__int64 a1, int a2)
{
return alignment_add_operations(a1, 82, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, int a2)
{
return func9(a1, 82, a2);
}

original_code:
int alignment_add_replacements (alignment* a, int length)
{
  return alignment_add_operations (a, 'R', length);
}

canonical_original_code:
int alignment_add_replacements(struct alignmentStruct *a, int length)
{
  return alignment_add_operations (a, 'R', length);
}


decompiled_code:
__int64 __fastcall alignment_reverse(__int64 a1)
{
__int64 result; // rax
int v2; // er9
__int64 v3; // rsi
__int64 *v4; // rcx
__int64 v5; // r8

result = *(unsigned int *)(a1 + 40);
v2 = *(_DWORD *)(a1 + 40) / 2;
if ( (int)result > 1 )
{
result = 0LL;
do
{
v3 = *(_QWORD *)(a1 + 32);
v4 = (__int64 *)(v3 + 8 * result);
v5 = *v4;
*v4 = *(_QWORD *)(v3 + 8LL * (*(_DWORD *)(a1 + 40) + ~(_DWORD)result));
*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL * (*(_DWORD *)(a1 + 40) + ~(_DWORD)result++)) = v5;
}
while ( v2 > (int)result );
}
return result;
}

original_code:
void alignment_reverse(alignment* a)
{
  int half = a->editlength/2-1;
  int i;
  multiedit* temp;
  for (i = 0; i <= half; i++)
  {
    temp = a->edits[i];
    a->edits[i] = a->edits[a->editlength-1-i];
    a->edits[a->editlength-1-i] = temp;
  }
}

canonical_original_code:
void alignment_reverse(struct alignmentStruct *a)
{
  int half = a->editlength/2-1;
  int i;
  struct multieditStruct *temp;
  for (i = 0; i <= half; i++)
  {
    temp = a->edits[i];
    a->edits[i] = a->edits[a->editlength-1-i];
    a->edits[a->editlength-1-i] = temp;
  }
}

variable_types: half int

variable_types: struct multieditStruct { int stretch; char operation; } *

return_type: void


original_code:
int alignment_evalcost (alignment* a, int (*costFunc) (char, char))
{
  int costs = 0;
  int i,j;
  int index1 = 0;
  int index2 = 0;
  multiedit* me = ((void *)0);
  int gap = costFunc ('-', '-');
  for (i = 0; i < a->editlength; i++)
  {
    me = a->edits[i];
    for (j = 0; j < me->stretch; j++)
    {
      if (me->operation == 'R')
      {
        if (a->s1[index1] == '\0' || a->s2[index2] == '\0')
          return -1;
        costs += costFunc(a->s1[index1], a->s2[index2]);
        index1++;
        index2++;
      }
      else if (me->operation == 'I')
      {
        if (a->s2[index2] == '\0')
          return -1;
        costs += gap;
        index2++;
      }
      else
      {
        if (a->s1[index1] == '\0')
          return -1;
        costs += gap;
        index1++;
      }
    }
  }
  return costs;
}

canonical_original_code:
int alignment_evalcost(struct alignmentStruct *a, int (*costFunc)(char, char))
{
  int costs = 0;
  int i; int j;
  int index1 = 0;
  int index2 = 0;
  struct multieditStruct *me = ((void *)0);
  int gap = costFunc ('-', '-');
  for (i = 0; i < a->editlength; i++)
  {
    me = a->edits[i];
    for (j = 0; j < me->stretch; j++)
    {
      if (me->operation == 'R')
      {
        if (a->s1[index1] == '\0' || a->s2[index2] == '\0')
          return -1;
        costs += costFunc(a->s1[index1], a->s2[index2]);
        index1++;
        index2++;
      }
      else if (me->operation == 'I')
      {
        if (a->s2[index2] == '\0')
          return -1;
        costs += gap;
        index2++;
      }
      else
      {
        if (a->s1[index1] == '\0')
          return -1;
        costs += gap;
        index1++;
      }
    }
  }
  return costs;
}

variable_types: struct alignmentStruct { char *s1; int len1; char *s2; int len2; struct multieditStruct { int stretch; char operation; } **edits; int editlength; int length; int maxlen; } *

variable_types:
costFunc
int (*)(char, char)

variable_types: j int

variable_types: gap int


original_code:
int alignment_compare (alignment* a, alignment* b)
{
  if (a->editlength != b->editlength)
    return 0;
  int i;
  for (i = 0; i < a->editlength; i++)
  {
    if (a->edits[i]->stretch != b->edits[i]->stretch)
      return 0;
    if (a->edits[i]->operation != b->edits[i]->operation)
      return 0;
  }
  return 1;
}

canonical_original_code:
int alignment_compare(struct alignmentStruct *a, struct alignmentStruct *b)
{
  if (a->editlength != b->editlength)
    return 0;
  int i;
  for (i = 0; i < a->editlength; i++)
  {
    if (a->edits[i]->stretch != b->edits[i]->stretch)
      return 0;
    if (a->edits[i]->operation != b->edits[i]->operation)
      return 0;
  }
  return 1;
}

variable_types:
b
struct alignmentStruct *


decompiled_code:
void __fastcall llentry_delete(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func7(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
static void llentry_delete(llentry* l)
{
  if (l == ((void *)0))
    return;
  free(l);
}

canonical_original_code:
static void llentry_delete(struct entstruct *l)
{
  if (l == ((void *)0))
    return;
  free(l);
}

variable_types: struct entstruct { struct entstruct *next; int key; void *data; } *


decompiled_code:
_BOOL8 __fastcall linked_list_is_empty(_QWORD *a1)
{
if ( !a1 )
__assert_fail("l", "linkedlist.c", 0x6Au, "linked_list_is_empty");
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_QWORD *a1)
{
if ( !a1 )
__assert_fail("l", "linkedlist.c", 0x6Au, "linked_list_is_empty");
return *a1 == 0LL;
}

original_code:
int linked_list_is_empty(linkedlist* l)
{
  ((void) sizeof ((l) ? 1 : 0), __extension__ ({ if (l) ; else __assert_fail ("l", "linkedlist.c", 106, __extension__ __PRETTY_FUNCTION__); }));
  return (l->root == ((void *)0));
}

canonical_original_code:
int linked_list_is_empty(struct llStruct *l)
{
  ((void) sizeof ((l) ? 1 : 0), __extension__ ({ if (l) ; else __assert_fail ("l", "linkedlist.c", 106, __extension__ __PRETTY_FUNCTION__); }));
  return (l->root == ((void *)0));
}

variable_types: struct llStruct { struct entstruct { struct entstruct *next; int key; void *data; } *root; struct entstruct *end; } *

user_defined_types: struct llStruct { struct entstruct *root; struct entstruct *end; }


decompiled_code:
__int64 __fastcall linked_list_pop(_QWORD **a1)
{
_QWORD *v2; // rdi
__int64 v3; // rbp

if ( !a1 )
__assert_fail("l", "linkedlist.c", 0x3Bu, "linked_list_pop");
if ( linked_list_is_empty(a1) )
__assert_fail("!linked_list_is_empty(l)", "linkedlist.c", 0x3Cu, "linked_list_pop");
v2 = *a1;
v3 = (*a1)[2];
*a1 = (_QWORD *)**a1;
if ( v2 == a1[1] )
a1[1] = 0LL;
llentry_delete(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1)
{
_QWORD *v2; // rdi
__int64 v3; // rbp

if ( !a1 )
__assert_fail("l", "linkedlist.c", 0x3Bu, "linked_list_pop");
if ( func9(a1) )
__assert_fail("!linked_list_is_empty(l)", "linkedlist.c", 0x3Cu, "linked_list_pop");
v2 = *a1;
v3 = (*a1)[2];
*a1 = (_QWORD *)**a1;
if ( v2 == a1[1] )
a1[1] = 0LL;
func7(v2);
return v3;
}

original_code:
void* linked_list_pop(linkedlist* l)
{
  void* result;
  llentry* temp;
  ((void) sizeof ((l) ? 1 : 0), __extension__ ({ if (l) ; else __assert_fail ("l", "linkedlist.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!linked_list_is_empty(l)) ? 1 : 0), __extension__ ({ if (!linked_list_is_empty(l)) ; else __assert_fail ("!linked_list_is_empty(l)", "linkedlist.c", 60, __extension__ __PRETTY_FUNCTION__); }));
  result = l->root->data;
  temp = l->root;
  l->root = l->root->next;
  if (temp == l->end)
    l->end = ((void *)0);
  llentry_delete(temp);
  return result;
}

canonical_original_code:
void *linked_list_pop(struct llStruct *l)
{
  void *result;
  struct entstruct *temp;
  ((void) sizeof ((l) ? 1 : 0), __extension__ ({ if (l) ; else __assert_fail ("l", "linkedlist.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((!linked_list_is_empty(l)) ? 1 : 0), __extension__ ({ if (!linked_list_is_empty(l)) ; else __assert_fail ("!linked_list_is_empty(l)", "linkedlist.c", 60, __extension__ __PRETTY_FUNCTION__); }));
  result = l->root->data;
  temp = l->root;
  l->root = l->root->next;
  if (temp == l->end)
    l->end = ((void *)0);
  llentry_delete(temp);
  return result;
}

variable_types:
result
void *

return_type: void *

user_defined_types: struct entstruct { struct entstruct *next; int key; void *data; }


decompiled_code:
_QWORD *linked_list_new()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
__assert_fail("temp", "linkedlist.c", 0xBu, "linked_list_new");
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
__assert_fail("temp", "linkedlist.c", 0xBu, "linked_list_new");
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
linkedlist* linked_list_new()
{
  linkedlist* temp = (linkedlist*) malloc(sizeof(linkedlist));
  ((void) sizeof ((temp) ? 1 : 0), __extension__ ({ if (temp) ; else __assert_fail ("temp", "linkedlist.c", 11, __extension__ __PRETTY_FUNCTION__); }));
  temp->root = ((void *)0);
  temp->end = ((void *)0);
  return temp;
}

canonical_original_code:
struct llStruct *linked_list_new()
{
  struct llStruct *temp = (linkedlist*) malloc(sizeof(linkedlist));
  ((void) sizeof ((temp) ? 1 : 0), __extension__ ({ if (temp) ; else __assert_fail ("temp", "linkedlist.c", 11, __extension__ __PRETTY_FUNCTION__); }));
  temp->root = ((void *)0);
  temp->end = ((void *)0);
  return temp;
}

return_type: struct llStruct { struct entstruct { struct entstruct *next; int key; void *data; } *root; struct entstruct *end; } *


decompiled_code:
void __fastcall linked_list_delete(void *ptr)
{
if ( ptr )
{
while ( !linked_list_is_empty(ptr) )
linked_list_pop((_QWORD **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
if ( ptr )
{
while ( !func9(ptr) )
func10((_QWORD **)ptr);
free(ptr);
}
}

original_code:
void linked_list_delete(linkedlist* l)
{
  if (l == ((void *)0))
    return;
  while (!linked_list_is_empty(l))
  {
    linked_list_pop(l);
  }
  free (l);
}

canonical_original_code:
void linked_list_delete(struct llStruct *l)
{
  if (l == ((void *)0))
    return;
  while (!linked_list_is_empty(l))
  {
    linked_list_pop(l);
  }
  free (l);
}


extendhitleft

original_code:
int extendhitleft(char* u,int m,char* w,int n,int q,int match,int mismatch,int xd,int i,int j)
{
  int xmax = 0;
  int scoresum = 0;
  int l = 0;
  int sc;
  while (i-1-l >= 0 && j-1-l >= 0)
  {
    if (u[i-1-l] == w[j-1-l])
      sc = match;
    else
      sc = mismatch;
    scoresum += sc;
    if (scoresum < (xmax-xd))
      break;
    if (scoresum > xmax)
      xmax = scoresum;
    l++;
  }
  return l-1;
}

canonical_original_code:
int extendhitleft(char *u, int m, char *w, int n, int q, int match, int mismatch, int xd, int i, int j)
{
  int xmax = 0;
  int scoresum = 0;
  int l = 0;
  int sc;
  while (i-1-l >= 0 && j-1-l >= 0)
  {
    if (u[i-1-l] == w[j-1-l])
      sc = match;
    else
      sc = mismatch;
    scoresum += sc;
    if (scoresum < (xmax-xd))
      break;
    if (scoresum > xmax)
      xmax = scoresum;
    l++;
  }
  return l-1;
}

variable_types:
u
char *

variable_types: m int

variable_types:
w
char *

variable_types: n int

variable_types: q int

variable_types: match int

variable_types: mismatch int

variable_types: xd int

variable_types: xmax int

variable_types: scoresum int

variable_types: l int

variable_types: sc int


extendhitright

original_code:
int extendhitright(char* u,int m,char* w,int n,int q,int match,int mismatch,int xd,int i,int j)
{
  int xmax = 0;
  int scoresum = 0;
  int r = 0;
  int sc;
  while (i+q+r < m && j+q+r < n)
  {
    if (u[i+q+r] == w[j+q+r])
      sc = match;
    else
      sc = mismatch;
    scoresum += sc;
    if (scoresum < (xmax-xd))
    {
      break;
    }
    if (scoresum > xmax)
    {
      xmax = scoresum;
    }
    r++;
  }
  return r-1;
}

canonical_original_code:
int extendhitright(char *u, int m, char *w, int n, int q, int match, int mismatch, int xd, int i, int j)
{
  int xmax = 0;
  int scoresum = 0;
  int r = 0;
  int sc;
  while (i+q+r < m && j+q+r < n)
  {
    if (u[i+q+r] == w[j+q+r])
      sc = match;
    else
      sc = mismatch;
    scoresum += sc;
    if (scoresum < (xmax-xd))
    {
      break;
    }
    if (scoresum > xmax)
    {
      xmax = scoresum;
    }
    r++;
  }
  return r-1;
}

variable_types: i int

variable_types: j int

variable_types: r int


extend

original_code:
void extend(char* database, int m, char* query, int n, int q, int match, int mismatch, int xd, int** hits, int hitlength)
{
  int i,right,left,leftbd,leftbq,rightbd,rightbq,len;
  for (i = 0; i < hitlength; i++)
  {
    left =
      extendhitleft(database,m,query,n,q,match,mismatch,xd,hits[i][0],hits[i][1]);
    right =
      extendhitright(database,m,query,n,q,match,mismatch,xd,hits[i][0],hits[i][1]);
    leftbd = hits[i][0]-1-left;
    leftbq = hits[i][1]-1-left;
    rightbd = hits[i][0]+right+q;
    rightbq = hits[i][1]+right+q;
    len = rightbd-leftbd+1;
    printf("(%d-%d) (%d-%d) length %d\n",leftbd,rightbd,leftbq,rightbq,len);
    char* print = &(database[leftbd]);
    char temp = database[rightbd+1];
    database[rightbd+1] = '\0';
    printf("%s\n",print);
    database[rightbd+1] = temp;
    print = &(query[leftbq]);
    temp = query[rightbq+1];
    query[rightbq+1] = '\0';
    printf("%s\n",print);
    query[rightbq+1] = temp;
    printf("\n");
  }
}

canonical_original_code:
void extend(char *database, int m, char *query, int n, int q, int match, int mismatch, int xd, int **hits, int hitlength)
{
  int i; int right; int left; int leftbd; int leftbq; int rightbd; int rightbq; int len;
  for (i = 0; i < hitlength; i++)
  {
    left =
      extendhitleft(database,m,query,n,q,match,mismatch,xd,hits[i][0],hits[i][1]);
    right =
      extendhitright(database,m,query,n,q,match,mismatch,xd,hits[i][0],hits[i][1]);
    leftbd = hits[i][0]-1-left;
    leftbq = hits[i][1]-1-left;
    rightbd = hits[i][0]+right+q;
    rightbq = hits[i][1]+right+q;
    len = rightbd-leftbd+1;
    printf("(%d-%d) (%d-%d) length %d\n",leftbd,rightbd,leftbq,rightbq,len);
    char *print = &(database[leftbd]);
    char temp = database[rightbd+1];
    database[rightbd+1] = '\0';
    printf("%s\n",print);
    database[rightbd+1] = temp;
    print = &(query[leftbq]);
    temp = query[rightbq+1];
    query[rightbq+1] = '\0';
    printf("%s\n",print);
    query[rightbq+1] = temp;
    printf("\n");
  }
}

variable_types:
database
char *

variable_types:
query
char *

variable_types:
hits
int **

variable_types: hitlength int

variable_types: right int

variable_types: left int

variable_types: leftbd int

variable_types: leftbq int

variable_types: rightbd int

variable_types: rightbq int

variable_types: len int

variable_types:
print
char *

variable_types: temp char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // er12
int v6; // er13
__int64 v7; // r12
__int64 v8; // rax
__int64 v9; // r13
const char *v10; // r15
const char *v11; // r14
char *v12; // rax
char *v13; // rbx
__int64 i; // rbp
unsigned int v15; // [rsp+0h] [rbp-68h]
unsigned int v16; // [rsp+8h] [rbp-60h]
int v17; // [rsp+1Ch] [rbp-4Ch] BYREF
int v18; // [rsp+20h] [rbp-48h] BYREF
int v19; // [rsp+24h] [rbp-44h] BYREF
int v20; // [rsp+28h] [rbp-40h] BYREF
signed int v21; // [rsp+2Ch] [rbp-3Ch] BYREF

if ( argc <= 7 )
{
printf("usage: %s query.fasta database.fasta blasthits q match mismatch xd\n", *argv);
v3 = 0;
}
else
{
v3 = _isoc99_sscanf(argv[4], "%d", &v21);
if ( v3 == 1 && v21 > 0 )
{
v4 = _isoc99_sscanf(argv[5], "%d", &v20);
if ( v4 == 1 )
{
v6 = _isoc99_sscanf(argv[6], "%d", &v19);
if ( v6 == 1 )
{
v3 = _isoc99_sscanf(argv[7], "%d", &v18);
if ( v3 == 1 && v18 > 0 )
{
v7 = read_fasta_file(argv[1]);
v8 = read_fasta_file(argv[2]);
v9 = v8;
if ( v7 )
{
if ( v8 )
{
v10 = *(const char **)(**(_QWORD **)(v7 + 8) + 8LL);
v11 = *(const char **)(**(_QWORD **)(v8 + 8) + 8LL);
v15 = strlen(v11);
v16 = strlen(v10);
v12 = read_hits((char *)argv[3], &v17);
v13 = v12;
if ( v12 )
{
extend((__int64)v11, v15, (__int64)v10, v16, v21, v20, v19, v18, (int **)v12, v17);
for ( i = 0LL; v17 > (int)i; ++i )
free(*(void **)&v13[8 * i]);
free(v13);
multifasta_delete(v7);
multifasta_delete(v9);
v3 = 0;
}
}
}
}
else
{
printf("%s is no valid positive integer for xd!\n", argv[7]);
v3 = v6;
}
}
else
{
printf("%s is no valid integer for mismatch!\n", argv[6]);
v3 = v4;
}
}
else
{
printf("%s is no valid integer for match!\n", argv[5]);
}
}
else
{
printf("%s is no valid positive integer for q!\n", argv[4]);
v3 = 1;
}
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // er12
int v6; // er13
__int64 v7; // r12
__int64 v8; // rax
__int64 v9; // r13
const char *v10; // r15
const char *v11; // r14
char *v12; // rax
char *v13; // rbx
__int64 i; // rbp
unsigned int v15; // [rsp+0h] [rbp-68h]
unsigned int v16; // [rsp+8h] [rbp-60h]
int v17; // [rsp+1Ch] [rbp-4Ch] BYREF
int v18; // [rsp+20h] [rbp-48h] BYREF
int v19; // [rsp+24h] [rbp-44h] BYREF
int v20; // [rsp+28h] [rbp-40h] BYREF
signed int v21; // [rsp+2Ch] [rbp-3Ch] BYREF

if ( argc <= 7 )
{
printf("usage: %s query.fasta database.fasta blasthits q match mismatch xd\n", *argv);
v3 = 0;
}
else
{
v3 = _isoc99_sscanf(argv[4], "%d", &v21);
if ( v3 == 1 && v21 > 0 )
{
v4 = _isoc99_sscanf(argv[5], "%d", &v20);
if ( v4 == 1 )
{
v6 = _isoc99_sscanf(argv[6], "%d", &v19);
if ( v6 == 1 )
{
v3 = _isoc99_sscanf(argv[7], "%d", &v18);
if ( v3 == 1 && v18 > 0 )
{
v7 = read_fasta_file(argv[1]);
v8 = read_fasta_file(argv[2]);
v9 = v8;
if ( v7 )
{
if ( v8 )
{
v10 = *(const char **)(**(_QWORD **)(v7 + 8) + 8LL);
v11 = *(const char **)(**(_QWORD **)(v8 + 8) + 8LL);
v15 = strlen(v11);
v16 = strlen(v10);
v12 = func0((char *)argv[3], &v17);
v13 = v12;
if ( v12 )
{
func3((__int64)v11, v15, (__int64)v10, v16, v21, v20, v19, v18, (int **)v12, v17);
for ( i = 0LL; v17 > (int)i; ++i )
free(*(void **)&v13[8 * i]);
free(v13);
multifasta_delete(v7);
multifasta_delete(v9);
v3 = 0;
}
}
}
}
else
{
printf("%s is no valid positive integer for xd!\n", argv[7]);
v3 = v6;
}
}
else
{
printf("%s is no valid integer for mismatch!\n", argv[6]);
v3 = v4;
}
}
else
{
printf("%s is no valid integer for match!\n", argv[5]);
}
}
else
{
printf("%s is no valid positive integer for q!\n", argv[4]);
v3 = 1;
}
}
return v3;
}

original_code:
int main(int argc, char* argv[])
{
  if (argc < 8)
  {
    printf("usage: %s query.fasta database.fasta blasthits q match mismatch xd\n",
        argv[0]);
    return 0;
  }
  int q,match,mismatch,xd;
  if (sscanf(argv[4],"%d",&q) != 1 || q <= 0)
  {
    printf("%s is no valid positive integer for q!\n", argv[4]);
    return 1;
  }
  if (sscanf(argv[5],"%d",&match) != 1)
  {
    printf("%s is no valid integer for match!\n", argv[5]);
    return 1;
  }
  if (sscanf(argv[6],"%d",&mismatch) != 1)
  {
    printf("%s is no valid integer for mismatch!\n", argv[6]);
    return 1;
  }
  if (sscanf(argv[7],"%d",&xd) != 1 || xd <= 0)
  {
    printf("%s is no valid positive integer for xd!\n", argv[7]);
    return 1;
  }
  multifasta* mf1 = read_fasta_file(argv[1]);
  multifasta* mf2 = read_fasta_file(argv[2]);
  if (mf1 == ((void *)0) || mf2 == ((void *)0))
    return 1;
  char* query = mf1->entries[0]->sequence;
  char* database = mf2->entries[0]->sequence;
  int m = strlen(database);
  int n = strlen(query);
  int length;
  int** hits = read_hits(argv[3],&length);
  if (hits == ((void *)0))
    return 1;
  extend(database, m, query, n, q, match, mismatch, xd, hits, length);
  int i;
  for (i = 0; i < length; i++)
    free(hits[i]);
  free(hits);
  multifasta_delete(mf1);
  multifasta_delete(mf2);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if (argc < 8)
  {
    printf("usage: %s query.fasta database.fasta blasthits q match mismatch xd\n",
        argv[0]);
    return 0;
  }
  int q; int match; int mismatch; int xd;
  if (sscanf(argv[4],"%d",&q) != 1 || q <= 0)
  {
    printf("%s is no valid positive integer for q!\n", argv[4]);
    return 1;
  }
  if (sscanf(argv[5],"%d",&match) != 1)
  {
    printf("%s is no valid integer for match!\n", argv[5]);
    return 1;
  }
  if (sscanf(argv[6],"%d",&mismatch) != 1)
  {
    printf("%s is no valid integer for mismatch!\n", argv[6]);
    return 1;
  }
  if (sscanf(argv[7],"%d",&xd) != 1 || xd <= 0)
  {
    printf("%s is no valid positive integer for xd!\n", argv[7]);
    return 1;
  }
  struct multifastaStruct *mf1 = read_fasta_file(argv[1]);
  struct multifastaStruct *mf2 = read_fasta_file(argv[2]);
  if (mf1 == ((void *)0) || mf2 == ((void *)0))
    return 1;
  char *query = mf1->entries[0]->sequence;
  char *database = mf2->entries[0]->sequence;
  int m = strlen(database);
  int n = strlen(query);
  int length;
  int **hits = read_hits(argv[3],&length);
  if (hits == ((void *)0))
    return 1;
  extend(database, m, query, n, q, match, mismatch, xd, hits, length);
  int i;
  for (i = 0; i < length; i++)
    free(hits[i]);
  free(hits);
  multifasta_delete(mf1);
  multifasta_delete(mf2);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: q int

variable_types: match int

variable_types: mismatch int

variable_types: xd int

variable_types: struct multifastaStruct { int length; int maxlen; struct fastaStruct { char *header; char *sequence; int length; int clength; int ssize; int csize; } **entries; } *

variable_types: m int

variable_types: n int

variable_types: length int

user_defined_types: struct multifastaStruct { int length; int maxlen; struct fastaStruct **entries; }


isBase

decompiled_code:
__int64 __fastcall isBase(char a1)
{
__int64 result; // rax

switch ( a1 )
{
case 'A':
case 'C':
case 'G':
case 'T':
case 'U':
case 'a':
case 'c':
case 'g':
case 't':
case 'u':
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
__int64 result; // rax

switch ( a1 )
{
case 'A':
case 'C':
case 'G':
case 'T':
case 'U':
case 'a':
case 'c':
case 'g':
case 't':
case 'u':
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int isBase(char c)
{
  switch (c)
  {
    case 'A':
      return 1;
    case 'a':
      return 1;
    case 'C':
      return 1;
    case 'c':
      return 1;
    case 'G':
      return 1;
    case 'g':
      return 1;
    case 'T':
      return 1;
    case 't':
      return 1;
    case 'U':
      return 1;
    case 'u':
      return 1;
    default:
      return 0;
  }
}

variable_types: c char


decompiled_code:
void __fastcall fasta_delete(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void fasta_delete (fasta* f)
{
  free (f->header);
  free (f->sequence);
  free (f);
}

canonical_original_code:
void fasta_delete(struct fastaStruct *f)
{
  free (f->header);
  free (f->sequence);
  free (f);
}

variable_types: struct fastaStruct { char *header; char *sequence; int length; int clength; int ssize; int csize; } *


original_code:
void fasta_add_base (fasta* f, char base)
{
  if (f->length == f->ssize)
  {
    f->ssize *= 2;
    f->sequence = (char *) realloc (f->sequence, sizeof(char)*f->ssize);
  }
  f->sequence[f->length] = base;
  if (base != '\0')
    f->length++;
}

canonical_original_code:
void fasta_add_base(struct fastaStruct *f, char base)
{
  if (f->length == f->ssize)
  {
    f->ssize *= 2;
    f->sequence = (char *) realloc (f->sequence, sizeof(char)*f->ssize);
  }
  f->sequence[f->length] = base;
  if (base != '\0')
    f->length++;
}

variable_types: base char

user_defined_types: struct fastaStruct { char *header; char *sequence; int length; int clength; int ssize; int csize; }


decompiled_code:
__int64 __fastcall fasta_add_header_char(__int64 a1, char a2)
{
int v3; // esi
__int64 result; // rax
int v5; // esi

v3 = *(_DWORD *)(a1 + 28);
if ( *(_DWORD *)(a1 + 20) == v3 )
{
v5 = 2 * v3;
*(_DWORD *)(a1 + 28) = v5;
*(_QWORD *)a1 = realloc(*(void **)a1, v5);
}
result = *(int *)(a1 + 20);
*(_BYTE *)(*(_QWORD *)a1 + result) = a2;
if ( a2 )
++*(_DWORD *)(a1 + 20);
return result;
}

original_code:
void fasta_add_header_char (fasta* f, char ch)
{
  if (f->clength == f->csize)
  {
    f->csize *= 2;
    f->header = (char *) realloc (f->header, sizeof(char)*f->csize);
  }
  f->header[f->clength] = ch;
  if (ch != '\0')
    f->clength++;
}

canonical_original_code:
void fasta_add_header_char(struct fastaStruct *f, char ch)
{
  if (f->clength == f->csize)
  {
    f->csize *= 2;
    f->header = (char *) realloc (f->header, sizeof(char)*f->csize);
  }
  f->header[f->clength] = ch;
  if (ch != '\0')
    f->clength++;
}

variable_types: ch char


decompiled_code:
void __fastcall multifasta_delete(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
fasta_delete(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
func8(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void multifasta_delete (multifasta* mf)
{
  int i;
  for (i = 0; i < mf->length; i++)
  {
    fasta_delete(mf->entries[i]);
  }
  free (mf->entries);
  free (mf);
}

canonical_original_code:
void multifasta_delete(struct multifastaStruct *mf)
{
  int i;
  for (i = 0; i < mf->length; i++)
  {
    fasta_delete(mf->entries[i]);
  }
  free (mf->entries);
  free (mf);
}

variable_types: i int


decompiled_code:
__int64 __fastcall multifasta_add_fasta(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 result; // rax
int v4; // eax

v2 = *(_DWORD *)(a1 + 4);
if ( *(_DWORD *)a1 == v2 )
{
v4 = 2 * v2;
*(_DWORD *)(a1 + 4) = v4;
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), 8LL * v4);
}
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8LL * (int)(*(_DWORD *)a1)++) = a2;
return result;
}

original_code:
void multifasta_add_fasta (multifasta * mf, fasta * f)
{
  if (mf->length == mf->maxlen)
  {
    mf->maxlen *= 2;
    mf->entries = (fasta **) realloc (mf->entries, sizeof(fasta*)*mf->maxlen);
  }
  mf->entries[mf->length] = f;
  mf->length++;
}

canonical_original_code:
void multifasta_add_fasta(struct multifastaStruct *mf, struct fastaStruct *f)
{
  if (mf->length == mf->maxlen)
  {
    mf->maxlen *= 2;
    mf->entries = (struct fastaStruct **) realloc (mf->entries, sizeof(struct fastaStruct *)*mf->maxlen);
  }
  mf->entries[mf->length] = f;
  mf->length++;
}

variable_types:
f
struct fastaStruct *


decompiled_code:
__int64 __fastcall construct_environment(__int64 a1, __int64 a2, int a3, unsigned int a4, __int64 a5, __int64 a6, __int64 a7)
{
void *v8; // rsp
__int64 result; // rax
__int64 i; // rdx
_QWORD *v11; // r13
__int64 *v12; // [rsp+0h] [rbp-50h] BYREF
__int64 v13; // [rsp+8h] [rbp-48h]
__int64 v14; // [rsp+10h] [rbp-40h]
unsigned int v15; // [rsp+1Ch] [rbp-34h]

v15 = a3;
v14 = a5;
v13 = a6;
v12 = (__int64 *)&v12;
v8 = alloca(a3 + 1);
*((_BYTE *)&v12 + a3) = 0;
while ( 1 )
{
result = linked_list_is_empty(a1);
if ( (_DWORD)result )
break;
for ( i = linked_list_pop(a1); *(_QWORD *)i; i = *(_QWORD *)i )
*((_BYTE *)&v12 + *(_DWORD *)(i + 32) - 1) = *(_BYTE *)(a2 + *(int *)(i + 24));
printf("(%s,%d)\n", (const char *)&v12, a4);
result = translate_qword(&v12, v15, v14, v13);
if ( (_DWORD)result == -1 )
break;
v11 = (_QWORD *)(a7 + 8LL * (int)result);
if ( !*v11 )
*v11 = linked_list_new(&v12);
linked_list_add(*v11, a4, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3, unsigned int a4, __int64 a5, __int64 a6, __int64 a7)
{
void *v8; // rsp
__int64 result; // rax
__int64 i; // rdx
_QWORD *v11; // r13
__int64 *v12; // [rsp+0h] [rbp-50h] BYREF
__int64 v13; // [rsp+8h] [rbp-48h]
__int64 v14; // [rsp+10h] [rbp-40h]
unsigned int v15; // [rsp+1Ch] [rbp-34h]

v15 = a3;
v14 = a5;
v13 = a6;
v12 = (__int64 *)&v12;
v8 = alloca(a3 + 1);
*((_BYTE *)&v12 + a3) = 0;
while ( 1 )
{
result = linked_list_is_empty(a1);
if ( (_DWORD)result )
break;
for ( i = linked_list_pop(a1); *(_QWORD *)i; i = *(_QWORD *)i )
*((_BYTE *)&v12 + *(_DWORD *)(i + 32) - 1) = *(_BYTE *)(a2 + *(int *)(i + 24));
printf("(%s,%d)\n", (const char *)&v12, a4);
result = translate_qword(&v12, v15, v14, v13);
if ( (_DWORD)result == -1 )
break;
v11 = (_QWORD *)(a7 + 8LL * (int)result);
if ( !*v11 )
*v11 = linked_list_new(&v12);
linked_list_add(*v11, a4, 0LL);
}
return result;
}

original_code:
void construct_environment(linkedlist* stack, char* alphabet, int q, int pos, int* A, int* rpot, linkedlist** environment)
{
  TrieElement* elem;
  char envstring[q+1];
  int translated;
  envstring[q] = '\0';
  while(!linked_list_is_empty(stack))
  {
    elem = (TrieElement*) linked_list_pop(stack);
    while(elem->parent != ((void *)0))
    {
      envstring[elem->dephth-1] = alphabet[elem->edge];
      elem = elem->parent;
    }
    printf("(%s,%d)\n", envstring, pos);
    translated = translate_qword(envstring, q, A, rpot);
    if (translated == -1)
    {
      return;
    }
    if (environment[translated] == ((void *)0))
    {
      environment[translated] = linked_list_new();
    }
    linked_list_add(environment[translated], pos, (void*)((void *)0));
  }
}

canonical_original_code:
void construct_environment(struct llStruct *stack, char *alphabet, int q, int pos, int *A, int *rpot, struct llStruct **environment)
{
  struct te *elem;
  char envstring[-1];
  int translated;
  envstring[q] = '\0';
  while(!linked_list_is_empty(stack))
  {
    elem = (struct te *) linked_list_pop(stack);
    while(elem->parent != ((void *)0))
    {
      envstring[elem->dephth-1] = alphabet[elem->edge];
      elem = elem->parent;
    }
    printf("(%s,%d)\n", envstring, pos);
    translated = translate_qword(envstring, q, A, rpot);
    if (translated == -1)
    {
      return;
    }
    if (environment[translated] == ((void *)0))
    {
      environment[translated] = linked_list_new();
    }
    linked_list_add(environment[translated], pos, (void *)((void *)0));
  }
}

variable_types: struct llStruct { struct entstruct { struct entstruct *next; int key; void *data; } *root; struct entstruct *end; } *

variable_types:
alphabet
char *

variable_types: pos int

variable_types:
A
int *

variable_types:
rpot
int *

variable_types:
environment
struct llStruct **

variable_types: struct te { struct te *parent; struct te *leftchild; struct te *rightsibbling; int edge; int key; int dephth; } *

variable_types:
envstring
char [-1]

variable_types: translated int


calcenv

decompiled_code:
__int64 __fastcall calcenv(__int64 a1, unsigned int a2, __int64 a3, int a4, int a5, int a6, __int64 a7, _DWORD *a8, int a9, __int64 a10, __int64 a11, __int64 a12)
{
__int64 v13; // r13
__int64 v14; // rax
__int64 v15; // rbp
__int64 v16; // r13
int v17; // eax
__int64 v18; // rbx
__int64 v20; // [rsp+10h] [rbp-68h]
_DWORD *ptr; // [rsp+18h] [rbp-60h]
__int64 v24; // [rsp+28h] [rbp-50h]
__int64 *v25; // [rsp+30h] [rbp-48h]

v13 = linked_list_new(a1);
v24 = linked_list_new(a1);
ptr = 0LL;
if ( a9 )
ptr = calclookahead(a1, a3, (unsigned int)a4, a5, a6, a7);
v25 = (__int64 *)trie_new();
v14 = add_new_trieelement(0LL, 0LL, 0LL, 0LL);
*v25 = v14;
linked_list_push(v13, 0LL, v14);
++*a8;
while ( !(unsigned int)linked_list_is_empty(v13) )
{
v18 = linked_list_pop(v13);
if ( *(_DWORD *)(v18 + 32) < a5 )
{
if ( a4 > 0 )
{
v15 = 0LL;
v20 = v13;
v16 = 0LL;
do
{
v17 = get_score(a7, (unsigned int)*(char *)(a3 + v15), (unsigned int)*(char *)(a1 + *(int *)(v18 + 32)));
if ( !a9 || *(_DWORD *)(v18 + 28) + v17 >= ptr[*(int *)(v18 + 32)] )
{
v16 = add_new_trieelement(v18, v16, (unsigned int)(*(_DWORD *)(v18 + 28) + v17), (unsigned int)v15);
linked_list_push(v20, 0LL, v16);
++*a8;
}
++v15;
}
while ( v15 != a4 );
v13 = v20;
}
}
else if ( *(_DWORD *)(v18 + 28) >= a6 )
{
linked_list_push(v24, 0LL, v18);
}
}
construct_environment(v24, a3, a5, a2, a10, a11, a12);
trie_delete(v25);
linked_list_delete(v13);
free(ptr);
return linked_list_delete(v24);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3, int a4, int a5, int a6, __int64 a7, _DWORD *a8, int a9, __int64 a10, __int64 a11, __int64 a12)
{
__int64 v13; // r13
__int64 v14; // rax
__int64 v15; // rbp
__int64 v16; // r13
int v17; // eax
__int64 v18; // rbx
__int64 v20; // [rsp+10h] [rbp-68h]
_DWORD *ptr; // [rsp+18h] [rbp-60h]
__int64 v24; // [rsp+28h] [rbp-50h]
__int64 *v25; // [rsp+30h] [rbp-48h]

v13 = linked_list_new(a1);
v24 = linked_list_new(a1);
ptr = 0LL;
if ( a9 )
ptr = calclookahead(a1, a3, (unsigned int)a4, a5, a6, a7);
v25 = (__int64 *)trie_new();
v14 = add_new_trieelement(0LL, 0LL, 0LL, 0LL);
*v25 = v14;
linked_list_push(v13, 0LL, v14);
++*a8;
while ( !(unsigned int)linked_list_is_empty(v13) )
{
v18 = linked_list_pop(v13);
if ( *(_DWORD *)(v18 + 32) < a5 )
{
if ( a4 > 0 )
{
v15 = 0LL;
v20 = v13;
v16 = 0LL;
do
{
v17 = get_score(a7, (unsigned int)*(char *)(a3 + v15), (unsigned int)*(char *)(a1 + *(int *)(v18 + 32)));
if ( !a9 || *(_DWORD *)(v18 + 28) + v17 >= ptr[*(int *)(v18 + 32)] )
{
v16 = add_new_trieelement(v18, v16, (unsigned int)(*(_DWORD *)(v18 + 28) + v17), (unsigned int)v15);
linked_list_push(v20, 0LL, v16);
++*a8;
}
++v15;
}
while ( v15 != a4 );
v13 = v20;
}
}
else if ( *(_DWORD *)(v18 + 28) >= a6 )
{
linked_list_push(v24, 0LL, v18);
}
}
func0(v24, a3, a5, a2, a10, a11, a12);
trie_delete(v25);
linked_list_delete(v13);
free(ptr);
return linked_list_delete(v24);
}

original_code:
void calcenv(char* seq, int pos, char* alphabet, int r, int q, int k, scorematrix* sm, int* pushes, int pruning, int* A, int* rpot, linkedlist** environment)
{
  linkedlist *tempstack, *environmentstack;
  TrieElement *curr,*parent;
  int i, score, *look;
  Trie* t;
  tempstack = linked_list_new();
  environmentstack = linked_list_new();
  if (pruning)
    look = calclookahead(seq, alphabet, r, q, k, sm);
  else
    look = ((void *)0);
  t = trie_new();
  t->root = add_new_trieelement(((void *)0),((void *)0),0,0);
  linked_list_push(tempstack,0,(void*)t->root);
  (*pushes)++;
  while(!linked_list_is_empty(tempstack))
  {
    parent = (TrieElement*) linked_list_pop(tempstack);
    curr = ((void *)0);
    if (parent->dephth < q)
    {
      for (i = 0; i < r; i++)
      {
        score = get_score(sm, alphabet[i], seq[parent->dephth]);
        if (pruning == 0 || parent->key + score >= look[parent->dephth])
        {
          curr = add_new_trieelement(parent,curr,parent->key + score, i);
          linked_list_push(tempstack,0,(void*)curr);
          (*pushes)++;
        }
      }
    }
    else if (parent->key >= k)
    {
      linked_list_push(environmentstack, 0, (void*) parent);
    }
  }
  construct_environment(environmentstack,alphabet,q,pos,A,rpot,environment);
  trie_delete(t);
  linked_list_delete(tempstack);
  free(look);
  linked_list_delete(environmentstack);
}

canonical_original_code:
void calcenv(char *seq, int pos, char *alphabet, int r, int q, int k, struct scorematrixStruct *sm, int *pushes, int pruning, int *A, int *rpot, struct llStruct **environment)
{
  struct llStruct *tempstack; struct llStruct *environmentstack;
  struct te *curr; struct te *parent;
  int i; int score; int *look;
  struct Trie *t;
  tempstack = linked_list_new();
  environmentstack = linked_list_new();
  if (pruning)
    look = calclookahead(seq, alphabet, r, q, k, sm);
  else
    look = ((void *)0);
  t = trie_new();
  t->root = add_new_trieelement(((void *)0),((void *)0),0,0);
  linked_list_push(tempstack,0,(void *)t->root);
  (*pushes)++;
  while(!linked_list_is_empty(tempstack))
  {
    parent = (struct te *) linked_list_pop(tempstack);
    curr = ((void *)0);
    if (parent->dephth < q)
    {
      for (i = 0; i < r; i++)
      {
        score = get_score(sm, alphabet[i], seq[parent->dephth]);
        if (pruning == 0 || parent->key + score >= look[parent->dephth])
        {
          curr = add_new_trieelement(parent,curr,parent->key + score, i);
          linked_list_push(tempstack,0,(void *)curr);
          (*pushes)++;
        }
      }
    }
    else if (parent->key >= k)
    {
      linked_list_push(environmentstack, 0, (void *) parent);
    }
  }
  construct_environment(environmentstack,alphabet,q,pos,A,rpot,environment);
  trie_delete(t);
  linked_list_delete(tempstack);
  free(look);
  linked_list_delete(environmentstack);
}

variable_types:
seq
char *

variable_types: r int

variable_types: q int

variable_types: k int

variable_types: struct scorematrixStruct { int **matrix; int *maxscore; int indel; int size; } *

variable_types:
pushes
int *

variable_types: pruning int

variable_types: struct llStruct { struct entstruct { struct entstruct *next; int key; void *data; } *root; struct entstruct *end; } **

variable_types: score int

variable_types:
look
int *

variable_types: struct Trie { struct te { struct te *parent; struct te *leftchild; struct te *rightsibbling; int edge; int key; int dephth; } *root; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char *v4; // r13
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r14
int v9; // er15
_DWORD *v10; // rbx
_QWORD **v11; // r15
__int64 v12; // r14
int result; // eax
__int64 **i; // r13
unsigned int v15; // [rsp+0h] [rbp-58h]
void *ptr; // [rsp+8h] [rbp-50h]
unsigned int v17; // [rsp+14h] [rbp-44h] BYREF
int v18; // [rsp+18h] [rbp-40h] BYREF
int v19; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( argc <= 6 )
{
printf("usage: %s scorematrix alphabet seq.fasta q k pruning\n", *argv);
result = 0;
}
else
{
v3 = read_scorematrix(argv[1], 0LL, envp);
if ( v3 )
{
v4 = argv[2];
v15 = strlen(v4);
v5 = read_fasta_file(argv[3]);
v6 = v5;
if ( v5 )
{
v7 = **(_QWORD **)(v5 + 8);
v8 = *(_QWORD *)(v7 + 8);
v9 = *(_DWORD *)(v7 + 16);
if ( (unsigned int)_isoc99_sscanf(argv[4], "%d", &v19) == 1 && v19 > 0 )
{
if ( (unsigned int)_isoc99_sscanf(argv[5], "%d", &v18) != 1 || v18 < 0 )
printf("%s is no valid threshold parameter!\n", argv[5]);
if ( (unsigned int)_isoc99_sscanf(argv[6], "%d", &v17) != 1 || v17 > 1 )
printf("%s is no valid pruning option parameter (0 or 1)!\n", argv[6]);
ptr = (void *)new_alphabet(v4);
v10 = (_DWORD *)get_pot_list(v15, (unsigned int)v19);
v11 = (_QWORD **)calculate_environment(
v8,
v9,
(__int64)v4,
v15,
v19,
v18,
v3,
v17,
(__int64)ptr,
(__int64)v10);
if ( (int)v10[v19] > 0 )
{
v12 = 0LL;
do
{
if ( v11[v12] )
{
printf("%d: ", (unsigned int)v12);
for ( i = (__int64 **)*v11[v12]; i; i = (__int64 **)*i )
printf("%d, ", *((unsigned int *)i + 2));
linked_list_delete(v11[v12]);
putchar(10);
}
++v12;
}
while ( v10[v19] > (int)v12 );
}
free(v11);
delete_scorematrix(v3);
multifasta_delete(v6);
free(ptr);
free(v10);
result = 0;
}
else
{
printf("%s is no valid word length!\n", argv[4]);
result = 1;
}
}
else
{
delete_scorematrix(v3);
result = 1;
}
}
else
{
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char *v4; // r13
__int64 v5; // rax
__int64 v6; // r12
__int64 v7; // rax
__int64 v8; // r14
int v9; // er15
_DWORD *v10; // rbx
_QWORD **v11; // r15
__int64 v12; // r14
int result; // eax
__int64 **i; // r13
unsigned int v15; // [rsp+0h] [rbp-58h]
void *ptr; // [rsp+8h] [rbp-50h]
unsigned int v17; // [rsp+14h] [rbp-44h] BYREF
int v18; // [rsp+18h] [rbp-40h] BYREF
int v19; // [rsp+1Ch] [rbp-3Ch] BYREF

if ( argc <= 6 )
{
printf("usage: %s scorematrix alphabet seq.fasta q k pruning\n", *argv);
result = 0;
}
else
{
v3 = read_scorematrix(argv[1], 0LL, envp);
if ( v3 )
{
v4 = argv[2];
v15 = strlen(v4);
v5 = read_fasta_file(argv[3]);
v6 = v5;
if ( v5 )
{
v7 = **(_QWORD **)(v5 + 8);
v8 = *(_QWORD *)(v7 + 8);
v9 = *(_DWORD *)(v7 + 16);
if ( (unsigned int)_isoc99_sscanf(argv[4], "%d", &v19) == 1 && v19 > 0 )
{
if ( (unsigned int)_isoc99_sscanf(argv[5], "%d", &v18) != 1 || v18 < 0 )
printf("%s is no valid threshold parameter!\n", argv[5]);
if ( (unsigned int)_isoc99_sscanf(argv[6], "%d", &v17) != 1 || v17 > 1 )
printf("%s is no valid pruning option parameter (0 or 1)!\n", argv[6]);
ptr = (void *)new_alphabet(v4);
v10 = (_DWORD *)get_pot_list(v15, (unsigned int)v19);
v11 = (_QWORD **)func2(
v8,
v9,
(__int64)v4,
v15,
v19,
v18,
v3,
v17,
(__int64)ptr,
(__int64)v10);
if ( (int)v10[v19] > 0 )
{
v12 = 0LL;
do
{
if ( v11[v12] )
{
printf("%d: ", (unsigned int)v12);
for ( i = (__int64 **)*v11[v12]; i; i = (__int64 **)*i )
printf("%d, ", *((unsigned int *)i + 2));
linked_list_delete(v11[v12]);
putchar(10);
}
++v12;
}
while ( v10[v19] > (int)v12 );
}
free(v11);
delete_scorematrix(v3);
multifasta_delete(v6);
free(ptr);
free(v10);
result = 0;
}
else
{
printf("%s is no valid word length!\n", argv[4]);
result = 1;
}
}
else
{
delete_scorematrix(v3);
result = 1;
}
}
else
{
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
  char *alphabet, *seq;
  int q,k,pruning,lenseq,i,lenalph,*A,*rpot;
  multifasta* mf;
  linkedlist** environment;
  llentry* te;
  if (argc < 7)
  {
    printf("usage: %s scorematrix alphabet seq.fasta q k pruning\n", argv[0]);
    return 0;
  }
  scorematrix* sm = read_scorematrix(argv[1],0);
  if (sm == ((void *)0))
    return 1;
  alphabet = argv[2];
  lenalph = strlen(alphabet);
  mf = read_fasta_file(argv[3]);
  if (mf == ((void *)0))
  {
    delete_scorematrix(sm);
    return 1;
  }
  seq = mf->entries[0]->sequence;
  lenseq = mf->entries[0]->length;
  if (sscanf(argv[4],"%d",&q) != 1 || q <= 0)
  {
    printf("%s is no valid word length!\n", argv[4]);
    return 1;
  }
  if (sscanf(argv[5],"%d",&k) != 1 || k < 0)
  {
    printf("%s is no valid threshold parameter!\n", argv[5]);
  }
  if (sscanf(argv[6],"%d",&pruning) != 1 || (pruning != 0 && pruning != 1))
  {
    printf("%s is no valid pruning option parameter (0 or 1)!\n", argv[6]);
  }
  A = new_alphabet(alphabet);
  rpot = get_pot_list(lenalph,q);
  environment = calculate_environment(seq,lenseq,alphabet,lenalph,q,k,sm, pruning,A,rpot);
  for (i = 0; i < rpot[q]; i++)
  {
    if (environment[i] != ((void *)0))
    {
      printf("%d: ", i);
      te = environment[i]->root;
      while(te != ((void *)0))
      {
        printf("%d, ", te->key);
        te = te->next;
      }
      linked_list_delete(environment[i]);
      printf("\n");
    }
  }
  free(environment);
  delete_scorematrix(sm);
  multifasta_delete(mf);
  free(A);
  free(rpot);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *alphabet; char *seq;
  int q; int k; int pruning; int lenseq; int i; int lenalph; int *A; int *rpot;
  struct multifastaStruct *mf;
  struct llStruct **environment;
  struct entstruct *te;
  if (argc < 7)
  {
    printf("usage: %s scorematrix alphabet seq.fasta q k pruning\n", argv[0]);
    return 0;
  }
  struct scorematrixStruct *sm = read_scorematrix(argv[1],0);
  if (sm == ((void *)0))
    return 1;
  alphabet = argv[2];
  lenalph = strlen(alphabet);
  mf = read_fasta_file(argv[3]);
  if (mf == ((void *)0))
  {
    delete_scorematrix(sm);
    return 1;
  }
  seq = mf->entries[0]->sequence;
  lenseq = mf->entries[0]->length;
  if (sscanf(argv[4],"%d",&q) != 1 || q <= 0)
  {
    printf("%s is no valid word length!\n", argv[4]);
    return 1;
  }
  if (sscanf(argv[5],"%d",&k) != 1 || k < 0)
  {
    printf("%s is no valid threshold parameter!\n", argv[5]);
  }
  if (sscanf(argv[6],"%d",&pruning) != 1 || (pruning != 0 && pruning != 1))
  {
    printf("%s is no valid pruning option parameter (0 or 1)!\n", argv[6]);
  }
  A = new_alphabet(alphabet);
  rpot = get_pot_list(lenalph,q);
  environment = calculate_environment(seq,lenseq,alphabet,lenalph,q,k,sm, pruning,A,rpot);
  for (i = 0; i < rpot[q]; i++)
  {
    if (environment[i] != ((void *)0))
    {
      printf("%d: ", i);
      te = environment[i]->root;
      while(te != ((void *)0))
      {
        printf("%d, ", te->key);
        te = te->next;
      }
      linked_list_delete(environment[i]);
      printf("\n");
    }
  }
  free(environment);
  delete_scorematrix(sm);
  multifasta_delete(mf);
  free(A);
  free(rpot);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
alphabet
char *

variable_types: lenseq int

variable_types: i int

variable_types: lenalph int

variable_types:
A
int *

variable_types: struct multifastaStruct { int length; int maxlen; struct fastaStruct { char *header; char *sequence; int length; int clength; int ssize; int csize; } **entries; } *

variable_types: struct entstruct { struct entstruct *next; int key; void *data; } *

user_defined_types: struct scorematrixStruct { int **matrix; int *maxscore; int indel; int size; }


decompiled_code:
_BOOL8 __fastcall unit_score(__int64 a1, char a2, char a3)
{
return a2 != a3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, char a2, char a3)
{
return a2 != a3;
}

original_code:
static int unit_score(void* scorematrix, char a, char b)
{
  return (a != b);
}

canonical_original_code:
static int unit_score(void *scorematrix, char a, char b)
{
  return (a != b);
}

variable_types:
scorematrix
void *

variable_types: a char

variable_types: b char


decompiled_code:
int __fastcall msa_show(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 16) > 0 )
{
v1 = 0LL;
do
{
printf(">%s\n", **(const char ***)(*(_QWORD *)(a1 + 8) + 8 * v1));
result = puts(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1++) + 8LL));
}
while ( *(_DWORD *)(a1 + 16) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 16) > 0 )
{
v1 = 0LL;
do
{
printf(">%s\n", **(const char ***)(*(_QWORD *)(a1 + 8) + 8 * v1));
result = puts(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1++) + 8LL));
}
while ( *(_DWORD *)(a1 + 16) > (int)v1 );
}
return result;
}

original_code:
static void msa_show(Msa* msa)
{
  int i;
  for(i = 0; i < msa->length; i++)
  {
    printf(">%s\n",msa->entries[i]->header);
    printf("%s\n",msa->entries[i]->sequence);
  }
}

canonical_original_code:
static void msa_show(struct msaStruct *msa)
{
  int i;
  for(i = 0; i < msa->length; i++)
  {
    printf(">%s\n",msa->entries[i]->header);
    printf("%s\n",msa->entries[i]->sequence);
  }
}

variable_types: struct msaStruct { struct multifastaStruct { int length; int maxlen; struct fastaStruct { char *header; char *sequence; int length; int clength; int ssize; int csize; } **entries; } *mf; struct fastaStruct **entries; int length; } *

user_defined_types: struct msaStruct { struct multifastaStruct *mf; struct fastaStruct **entries; int length; }


decompiled_code:
void __fastcall msa_delete(void *ptr)
{
multifasta_delete(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
multifasta_delete(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void msa_delete (Msa* msa)
{
  multifasta_delete(msa->mf);
  free(msa);
}

canonical_original_code:
void msa_delete(struct msaStruct *msa)
{
  multifasta_delete(msa->mf);
  free(msa);
}


original_code:
int msa_sum_of_pairs(Msa* msa, int(*score)(void*, char, char), void* scorematrix)
{
  int i,j,k,sc=0;
  for (i = 0; i < msa->entries[0]->length; i++)
  {
    for (j = 0; j < msa->length; j++)
    {
      for (k = j+1; k < msa->length; k++)
      {
        sc += score(scorematrix, msa->entries[j]->sequence[i],
            msa->entries[k]->sequence[i]);
      }
    }
  }
  return sc;
}

canonical_original_code:
int msa_sum_of_pairs(struct msaStruct *msa, int (*score)(void *, char, char), void *scorematrix)
{
  int i; int j; int k; int sc = 0;
  for (i = 0; i < msa->entries[0]->length; i++)
  {
    for (j = 0; j < msa->length; j++)
    {
      for (k = j+1; k < msa->length; k++)
      {
        sc += score(scorematrix, msa->entries[j]->sequence[i],
            msa->entries[k]->sequence[i]);
      }
    }
  }
  return sc;
}

variable_types:
score
int (*)(void *, char, char)

variable_types: j int

variable_types: k int

variable_types: sc int


original_code:
int msa_consensus_score(Msa* msa, int (*score)(void*, char, char), void* scorematrix)
{
  int i,j,sc=0,*count,maxval;
  char cons,pos;
  count = malloc((0x7f * 2 + 1)*sizeof(int));
  printf("\n");
  for (i = 0; i < msa->entries[0]->length; i++)
  {
    maxval = -1;
    cons = 0;
    for (j = 0; j < (0x7f * 2 + 1); j++)
    {
      count[j] = 0;
    }
    for (j = 0; j < msa->length; j++)
    {
      pos = msa->entries[j]->sequence[i];
      if (pos != '-')
      {
        count[(int)pos]++;
        if (count[(int)pos] >= maxval)
        {
          maxval = count[(int)pos];
          cons = pos;
        }
      }
    }
    printf("%c",cons);
    for (j = 0; j < msa->length; j++)
    {
      sc += score(scorematrix,cons,msa->entries[j]->sequence[i]);
    }
  }
  printf("\n");
  free(count);
  return sc;
}

canonical_original_code:
int msa_consensus_score(struct msaStruct *msa, int (*score)(void *, char, char), void *scorematrix)
{
  int i; int j; int sc = 0; int *count; int maxval;
  char cons; char pos;
  count = malloc((0x7f * 2 + 1)*sizeof(int));
  printf("\n");
  for (i = 0; i < msa->entries[0]->length; i++)
  {
    maxval = -1;
    cons = 0;
    for (j = 0; j < (0x7f * 2 + 1); j++)
    {
      count[j] = 0;
    }
    for (j = 0; j < msa->length; j++)
    {
      pos = msa->entries[j]->sequence[i];
      if (pos != '-')
      {
        count[(int)pos]++;
        if (count[(int)pos] >= maxval)
        {
          maxval = count[(int)pos];
          cons = pos;
        }
      }
    }
    printf("%c",cons);
    for (j = 0; j < msa->length; j++)
    {
      sc += score(scorematrix,cons,msa->entries[j]->sequence[i]);
    }
  }
  printf("\n");
  free(count);
  return sc;
}

variable_types:
count
int *

variable_types: maxval int

variable_types: cons char

variable_types: pos char


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
__int64 *v4; // rbx
unsigned int v5; // ebp
unsigned int v6; // eax

if ( argc <= 1 )
{
fprintf(stderr, "usage: %s msa.fasta\n", *argv);
}
else
{
v3 = msa_initialize((__int64)argv[1]);
v4 = v3;
if ( v3 )
{
msa_show((__int64)v3);
v5 = msa_sum_of_pairs((__int64)v4, (__int64 (__fastcall *)(__int64, _QWORD, _QWORD))unit_score, 0LL);
v6 = msa_consensus_score((__int64)v4, (__int64 (__fastcall *)(__int64, _QWORD, _QWORD))unit_score, 0LL);
printf("Consensus: %d\nSum of pairs: %d\n", v6, v5);
msa_delete(v4);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rax
__int64 *v4; // rbx
unsigned int v5; // ebp
unsigned int v6; // eax

if ( argc <= 1 )
{
fprintf(stderr, "usage: %s msa.fasta\n", *argv);
}
else
{
v3 = msa_initialize((__int64)argv[1]);
v4 = v3;
if ( v3 )
{
func2((__int64)v3);
v5 = func4((__int64)v4, (__int64 (__fastcall *)(__int64, _QWORD, _QWORD))unit_score, 0LL);
v6 = func5((__int64)v4, (__int64 (__fastcall *)(__int64, _QWORD, _QWORD))unit_score, 0LL);
printf("Consensus: %d\nSum of pairs: %d\n", v6, v5);
func3(v4);
}
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
  Msa* msa;
  int sop,cons;
  if (argc < 2)
  {
    fprintf(stderr,"usage: %s msa.fasta\n", argv[0]);
    return 0;
  }
  msa = msa_initialize(argv[1]);
  if (msa == ((void *)0))
    return 0;
  msa_show(msa);
  sop = msa_sum_of_pairs(msa,unit_score,((void *)0));
  cons = msa_consensus_score(msa,unit_score,((void *)0));
  printf("Consensus: %d\nSum of pairs: %d\n", cons,sop);
  msa_delete(msa);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct msaStruct *msa;
  int sop; int cons;
  if (argc < 2)
  {
    fprintf(stderr,"usage: %s msa.fasta\n", argv[0]);
    return 0;
  }
  msa = msa_initialize(argv[1]);
  if (msa == ((void *)0))
    return 0;
  msa_show(msa);
  sop = msa_sum_of_pairs(msa,unit_score,((void *)0));
  cons = msa_consensus_score(msa,unit_score,((void *)0));
  printf("Consensus: %d\nSum of pairs: %d\n", cons,sop);
  msa_delete(msa);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sop int

variable_types: cons int


decompiled_code:
_QWORD *trie_element_new()
{
_QWORD *result; // rax

result = malloc(0x28uLL);
if ( !result )
_assert_fail("temp", "trie.c", 0x28u, "trie_element_new");
result[1] = 0LL;
result[2] = 0LL;
*result = 0LL;
return result;
}

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

result = malloc(0x28uLL);
if ( !result )
_assert_fail("temp", "trie.c", 0x28u, "trie_element_new");
result[1] = 0LL;
result[2] = 0LL;
*result = 0LL;
return result;
}

original_code:
static TrieElement* trie_element_new()
{
  TrieElement* temp = malloc(sizeof(TrieElement));
  ((void) sizeof ((temp) ? 1 : 0), __extension__ ({ if (temp) ; else __assert_fail ("temp", "trie.c", 40, __extension__ __PRETTY_FUNCTION__); }));
  temp->leftchild = ((void *)0);
  temp->rightsibbling = ((void *)0);
  temp->parent = ((void *)0);
  return temp;
}

canonical_original_code:
static struct te *trie_element_new()
{
  struct te *temp = malloc(sizeof(TrieElement));
  ((void) sizeof ((temp) ? 1 : 0), __extension__ ({ if (temp) ; else __assert_fail ("temp", "trie.c", 40, __extension__ __PRETTY_FUNCTION__); }));
  temp->leftchild = ((void *)0);
  temp->rightsibbling = ((void *)0);
  temp->parent = ((void *)0);
  return temp;
}

variable_types: struct te { struct te *parent; struct te *leftchild; struct te *rightsibbling; int edge; int key; int dephth; } *


decompiled_code:
void __fastcall trie_element_delete(void *ptr)
{
if ( ptr )
{
trie_element_delete(*((void **)ptr + 1));
trie_element_delete(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
func1(*((void **)ptr + 1));
func1(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
static void trie_element_delete(TrieElement* te)
{
  if (te != ((void *)0))
  {
    trie_element_delete(te->leftchild);
    trie_element_delete(te->rightsibbling);
    free(te);
  }
}

canonical_original_code:
static void trie_element_delete(struct te *te)
{
  if (te != ((void *)0))
  {
    trie_element_delete(te->leftchild);
    trie_element_delete(te->rightsibbling);
    free(te);
  }
}

user_defined_types: struct te { struct te *parent; struct te *leftchild; struct te *rightsibbling; int edge; int key; int dephth; }


decompiled_code:
_QWORD *trie_new()
{
_QWORD *result; // rax

result = malloc(8uLL);
if ( !result )
_assert_fail("temp", "trie.c", 0xAu, "trie_new");
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(8uLL);
if ( !result )
_assert_fail("temp", "trie.c", 0xAu, "trie_new");
*result = 0LL;
return result;
}

original_code:
Trie* trie_new()
{
  Trie* temp = malloc (sizeof(Trie));
  ((void) sizeof ((temp) ? 1 : 0), __extension__ ({ if (temp) ; else __assert_fail ("temp", "trie.c", 10, __extension__ __PRETTY_FUNCTION__); }));
  temp->root = ((void *)0);
  return temp;
}

canonical_original_code:
struct Trie *trie_new()
{
  struct Trie *temp = malloc (sizeof(Trie));
  ((void) sizeof ((temp) ? 1 : 0), __extension__ ({ if (temp) ; else __assert_fail ("temp", "trie.c", 10, __extension__ __PRETTY_FUNCTION__); }));
  temp->root = ((void *)0);
  return temp;
}

variable_types: struct Trie { struct te { struct te *parent; struct te *leftchild; struct te *rightsibbling; int edge; int key; int dephth; } *root; } *


decompiled_code:
void __fastcall trie_delete(void *ptr)
{
if ( ptr )
{
trie_element_delete(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
func1(*(void **)ptr);
free(ptr);
}
}

original_code:
void trie_delete(Trie* t)
{
  if (t != ((void *)0))
  {
    trie_element_delete(t->root);
    free(t);
  }
}

canonical_original_code:
void trie_delete(struct Trie *t)
{
  if (t != ((void *)0))
  {
    trie_element_delete(t->root);
    free(t);
  }
}


decompiled_code:
void __fastcall delete_hash(void *ptr, int a2)
{
_QWORD *v2; // rbx

if ( ptr )
{
if ( a2 > 0 )
{
v2 = ptr;
do
{
if ( *v2 )
linked_list_delete();
++v2;
}
while ( v2 != (_QWORD *)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, int a2)
{
_QWORD *v2; // rbx

if ( ptr )
{
if ( a2 > 0 )
{
v2 = ptr;
do
{
if ( *v2 )
linked_list_delete();
++v2;
}
while ( v2 != (_QWORD *)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
free(ptr);
}
}

original_code:
void delete_hash(linkedlist** h, int len)
{
  if (h == ((void *)0))
    return;
  int i;
  for (i = 0; i < len; i++)
  {
    if (h[i] != ((void *)0))
      linked_list_delete(h[i]);
  }
  free(h);
  h = ((void *)0);
}

canonical_original_code:
void delete_hash(struct llStruct **h, int len)
{
  if (h == ((void *)0))
    return;
  int i;
  for (i = 0; i < len; i++)
  {
    if (h[i] != ((void *)0))
      linked_list_delete(h[i]);
  }
  free(h);
  h = ((void *)0);
}

variable_types: struct llStruct { struct entstruct { struct entstruct *next; int key; } *root; struct entstruct *end; } **

variable_types: len int

variable_types: i int


calcscorefasta

original_code:
int calcscorefasta(char* u, int m, linkedlist** hwc, int n, int* A, int r, int q, int* rpot)
{
  int* count = calloc(m+n+1,sizeof(int));
  int j,i;
  int max = 0;
  int c = 0;
  int fail = 0;
  for (j = 1; j <= m-q+1; j++)
  {
    if (j == 1)
    {
      for (i = 1; i <= q; i++)
      {
        c += translate(u[i-1],A,&fail)*rpot[q-i];
        if (fail)
          return -1;
      }
    }
    else
    {
      c = (c - translate(u[j-1-1],A,&fail)*rpot[q-1])*r +
        translate(u[j+q-1-1],A,&fail);
      if (fail)
        return -1;
    }
    if (hwc[c] != ((void *)0))
    {
      llentry* curr;
      for (curr = hwc[c]->root; curr != ((void *)0); curr = curr->next)
      {
        i = curr->key;
        if (++count[i-j+m] > max)
          max = count[i-j+m];
      }
    }
  }
  for (i = -m; i <= n; i++)
  {
    printf("%d:%d,", i, count[i+m]);
  }
  printf("\n");
  free(count);
  return max;
}

canonical_original_code:
int calcscorefasta(char *u, int m, struct llStruct **hwc, int n, int *A, int r, int q, int *rpot)
{
  int *count = calloc(m+n+1,sizeof(int));
  int j; int i;
  int max = 0;
  int c = 0;
  int fail = 0;
  for (j = 1; j <= m-q+1; j++)
  {
    if (j == 1)
    {
      for (i = 1; i <= q; i++)
      {
        c += translate(u[i-1],A,&fail)*rpot[q-i];
        if (fail)
          return -1;
      }
    }
    else
    {
      c = (c - translate(u[j-1-1],A,&fail)*rpot[q-1])*r +
        translate(u[j+q-1-1],A,&fail);
      if (fail)
        return -1;
    }
    if (hwc[c] != ((void *)0))
    {
      struct entstruct *curr;
      for (curr = hwc[c]->root; curr != ((void *)0); curr = curr->next)
      {
        i = curr->key;
        if (++count[i-j+m] > max)
          max = count[i-j+m];
      }
    }
  }
  for (i = -m; i <= n; i++)
  {
    printf("%d:%d,", i, count[i+m]);
  }
  printf("\n");
  free(count);
  return max;
}

variable_types:
u
char *

variable_types: m int

variable_types: n int

variable_types:
A
int *

variable_types: r int

variable_types: q int

variable_types:
rpot
int *

variable_types: max int

variable_types: c int

variable_types: fail int

variable_types: struct entstruct { struct entstruct *next; int key; } *


fastascore

decompiled_code:
__int64 __fastcall fastascore(const char *a1, const char *a2, const char *a3, unsigned int a4)
{
unsigned int v6; // er12
__int64 v7; // rax
void *v8; // rbp
unsigned int v9; // er14
char *v10; // r13
int *v11; // r15
_QWORD *v12; // rax
int v13; // er9
void *v14; // r14
unsigned int v15; // ebx
void *ptr; // [rsp+8h] [rbp-50h]
int v18; // [rsp+18h] [rbp-40h]

v18 = strlen(a1);
v6 = strlen(a2);
v7 = new_alphabet(a3);
if ( !v7 )
return (unsigned int)-1;
v8 = (void *)v7;
v9 = strlen(a3);
ptr = (void *)translate_sequence(a2, v6, a4, v9, v8);
v10 = (char *)get_pot_list(v9, a4);
v11 = (int *)&v10[4 * a4];
v12 = create_hash((__int64)ptr, v6 - a4 + 1, *v11);
v13 = v9;
v14 = v12;
v15 = calcscorefasta((__int64)a1, v18, (__int64)v12, v6, (__int64)v8, v13, a4, (__int64)v10);
delete_hash(v14, *v11);
free(ptr);
free(v8);
free(v10);
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2, const char *a3, unsigned int a4)
{
unsigned int v6; // er12
__int64 v7; // rax
void *v8; // rbp
unsigned int v9; // er14
char *v10; // r13
int *v11; // r15
_QWORD *v12; // rax
int v13; // er9
void *v14; // r14
unsigned int v15; // ebx
void *ptr; // [rsp+8h] [rbp-50h]
int v18; // [rsp+18h] [rbp-40h]

v18 = strlen(a1);
v6 = strlen(a2);
v7 = new_alphabet(a3);
if ( !v7 )
return (unsigned int)-1;
v8 = (void *)v7;
v9 = strlen(a3);
ptr = (void *)translate_sequence(a2, v6, a4, v9, v8);
v10 = (char *)get_pot_list(v9, a4);
v11 = (int *)&v10[4 * a4];
v12 = create_hash((__int64)ptr, v6 - a4 + 1, *v11);
v13 = v9;
v14 = v12;
v15 = func1((__int64)a1, v18, (__int64)v12, v6, (__int64)v8, v13, a4, (__int64)v10);
func0(v14, *v11);
free(ptr);
free(v8);
free(v10);
return v15;
}

original_code:
int fastascore(char* u, char* w, char* alphabet, int q)
{
  int m = strlen(u);
  int n = strlen(w);
  int* A = new_alphabet(alphabet);
  if (A == ((void *)0))
    return -1;
  int r = strlen(alphabet);
  int* encw = translate_sequence(w,n,q,r,A);
  int* rpot = get_pot_list(r,q);
  linkedlist** hwc = create_hash(encw,n-q+1,rpot[q]);
  int score = calcscorefasta(u,m,hwc,n,A,r,q,rpot);
  delete_hash(hwc,rpot[q]);
  free(encw);
  free(A);
  free(rpot);
  return score;
}

canonical_original_code:
int fastascore(char *u, char *w, char *alphabet, int q)
{
  int m = strlen(u);
  int n = strlen(w);
  int *A = new_alphabet(alphabet);
  if (A == ((void *)0))
    return -1;
  int r = strlen(alphabet);
  int *encw = translate_sequence(w,n,q,r,A);
  int *rpot = get_pot_list(r,q);
  struct llStruct **hwc = create_hash(encw,n-q+1,rpot[q]);
  int score = calcscorefasta(u,m,hwc,n,A,r,q,rpot);
  delete_hash(hwc,rpot[q]);
  free(encw);
  free(A);
  free(rpot);
  return score;
}

variable_types:
w
char *

variable_types:
alphabet
char *

variable_types:
encw
int *

variable_types: score int

user_defined_types: struct entstruct { struct entstruct *next; int key; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // r12
const char *v5; // r13
unsigned int v6; // eax
int result; // eax
signed int v8; // [rsp+Ch] [rbp-2Ch] BYREF

if ( argc <= 4 )
{
printf("usage: %s u w A q\n", *argv);
result = 0;
}
else
{
v3 = argv[1];
v4 = argv[2];
v5 = argv[3];
if ( (unsigned int)_isoc99_sscanf(argv[4], "%d", &v8) == 1 && v8 > 0 )
{
v6 = fastascore(v3, v4, v5, v8);
printf("score: %d\n", v6);
result = 0;
}
else
{
printf("ERROR: %s is no valid q-length!\n", argv[4]);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
const char *v4; // r12
const char *v5; // r13
unsigned int v6; // eax
int result; // eax
signed int v8; // [rsp+Ch] [rbp-2Ch] BYREF

if ( argc <= 4 )
{
printf("usage: %s u w A q\n", *argv);
result = 0;
}
else
{
v3 = argv[1];
v4 = argv[2];
v5 = argv[3];
if ( (unsigned int)_isoc99_sscanf(argv[4], "%d", &v8) == 1 && v8 > 0 )
{
v6 = func2(v3, v4, v5, v8);
printf("score: %d\n", v6);
result = 0;
}
else
{
printf("ERROR: %s is no valid q-length!\n", argv[4]);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
  if (argc < 5)
  {
    printf("usage: %s u w A q\n", argv[0]);
    return 0;
  }
  char* u = argv[1];
  char* w = argv[2];
  char* alphabet = argv[3];
  int q;
  if (sscanf(argv[4], "%d", &q) != 1 || q <= 0)
  {
    printf("ERROR: %s is no valid q-length!\n", argv[4]);
    return 1;
  }
  int score = fastascore(u,w,alphabet,q);
  printf("score: %d\n", score);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if (argc < 5)
  {
    printf("usage: %s u w A q\n", argv[0]);
    return 0;
  }
  char *u = argv[1];
  char *w = argv[2];
  char *alphabet = argv[3];
  int q;
  if (sscanf(argv[4], "%d", &q) != 1 || q <= 0)
  {
    printf("ERROR: %s is no valid q-length!\n", argv[4]);
    return 1;
  }
  int score = fastascore(u,w,alphabet,q);
  printf("score: %d\n", score);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


variable_types: struct alignentryStruct { int value; int north; int west; int northwest; } ***

variable_types: i int

variable_types: j int


approxsearch

original_code:
void approxsearch(int k, char* p, int plen, char* t, int tlen, int (*costFunc) (char, char))
{
  int i,j,oldij,oldlen,len;
  int a,b,c,min;
  int newlen = 0;
  int gap = costFunc('\001','\001');
  int* vec = (int *) malloc((plen+1)*sizeof(int));
  int* lenvec = (int *) calloc((plen+1), sizeof(int));
  char* match = (char *) malloc((tlen+1)*sizeof(char));
  vec[0] = 0;
  for (j = 0; j <= tlen; j++)
  {
    oldij = 0;
    oldlen = 0;
    for (i = 1; i <= plen; i++)
    {
      if (j == 0)
      {
        vec[i] = vec[i-1] + gap;
      }
      else
      {
        a = vec[i-1] + gap;
        b = vec[i] + gap;
        c = oldij + costFunc(p[i-1],t[j-1]);
        min = ((a < b ? a : b) < c ? (a < b ? a : b) : c);
        if (min == c)
          newlen = oldlen + 1;
        else if (min == b)
          newlen = lenvec[i] + 1;
        else if (min == a)
          newlen = lenvec[i-1];
        oldij = vec[i];
        oldlen = lenvec[i];
        lenvec[i] = newlen;
        vec[i] = min;
      }
    }
    if (vec[i-1] <= k)
    {
      len = lenvec[i-1];
      strncpy(match,&t[j-1-len+1],len);
      match[len] = '\0';
      printf("match ends at %d with length %d: %s matches %s\n",j, lenvec[i-1], match, p);
    }
  }
  free (vec);
  free (lenvec);
}

canonical_original_code:
void approxsearch(int k, char *p, int plen, char *t, int tlen, int (*costFunc)(char, char))
{
  int i; int j; int oldij; int oldlen; int len;
  int a; int b; int c; int min;
  int newlen = 0;
  int gap = costFunc('\001','\001');
  int *vec = (int *) malloc((plen+1)*sizeof(int));
  int *lenvec = (int *) calloc((plen+1), sizeof(int));
  char *match = (char *) malloc((tlen+1)*sizeof(char));
  vec[0] = 0;
  for (j = 0; j <= tlen; j++)
  {
    oldij = 0;
    oldlen = 0;
    for (i = 1; i <= plen; i++)
    {
      if (j == 0)
      {
        vec[i] = vec[i-1] + gap;
      }
      else
      {
        a = vec[i-1] + gap;
        b = vec[i] + gap;
        c = oldij + costFunc(p[i-1],t[j-1]);
        min = ((a < b ? a : b) < c ? (a < b ? a : b) : c);
        if (min == c)
          newlen = oldlen + 1;
        else if (min == b)
          newlen = lenvec[i] + 1;
        else if (min == a)
          newlen = lenvec[i-1];
        oldij = vec[i];
        oldlen = lenvec[i];
        lenvec[i] = newlen;
        vec[i] = min;
      }
    }
    if (vec[i-1] <= k)
    {
      len = lenvec[i-1];
      strncpy(match,&t[j-1-len+1],len);
      match[len] = '\0';
      printf("match ends at %d with length %d: %s matches %s\n",j, lenvec[i-1], match, p);
    }
  }
  free (vec);
  free (lenvec);
}

variable_types: k int

variable_types:
p
char *

variable_types: plen int

variable_types:
t
char *

variable_types: tlen int

variable_types:
costFunc
int (*)(char, char)

variable_types: oldij int

variable_types: oldlen int

variable_types: len int

variable_types: a int

variable_types: b int

variable_types: min int

variable_types: newlen int

variable_types: gap int

variable_types:
vec
int *

variable_types:
lenvec
int *

variable_types:
match
char *


unity

decompiled_code:
__int64 __fastcall unity(char a1, char a2)
{
return (a2 == 1) | (unsigned __int8)(a1 != a2 || a1 == 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1, char a2)
{
return (a2 == 1) | (unsigned __int8)(a1 != a2 || a1 == 1);
}

original_code:
int unity(char a, char b)
{
  if (a == '\001' || b == '\001')
    return 1;
  if (a == b)
    return 0;
  return 1;
}

variable_types: a char

variable_types: b char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax

if ( argc <= 3 )
{
printf("usage: %s k(error) p(pattern) t(text)\n", *argv);
result = 0;
}
else
{
__isoc99_sscanf();
puts("k may not be negative");
result = 1;
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
  if (argc < 4)
  {
    printf("usage: %s k(error) p(pattern) t(text)\n", argv[0]);
    return 0;
  }
  int k = -1;
  sscanf(argv[1], "%d", &k);
  if (k < 0)
  {
    printf("k may not be negative\n");
    return 1;
  }
  char* p = argv[2];
  int plen = strlen(p);
  char* t = argv[3];
  int tlen = strlen(t);
  approxsearch(k,p,plen,t,tlen,unity);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if (argc < 4)
  {
    printf("usage: %s k(error) p(pattern) t(text)\n", argv[0]);
    return 0;
  }
  int k = -1;
  sscanf(argv[1], "%d", &k);
  if (k < 0)
  {
    printf("k may not be negative\n");
    return 1;
  }
  char *p = argv[2];
  int plen = strlen(p);
  char *t = argv[3];
  int tlen = strlen(t);
  approxsearch(k,p,plen,t,tlen,unity);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: k int

variable_types:
p
char *

variable_types: plen int


original_code:
static void max_score (scorematrix* sm)
{
  int i,j,sc;
  for (i = 0; i < sm->size; i++)
  {
    sm->maxscore[i] = (-0x7fffffff - 1);
    for (j = 0; j < sm->size; j++)
    {
      if ((sc = get_score(sm, i+'A', j+'A')) > sm->maxscore[i])
      {
        sm->maxscore[i] = sc;
      }
    }
  }
}

canonical_original_code:
static void max_score(struct scorematrixStruct *sm)
{
  int i; int j; int sc;
  for (i = 0; i < sm->size; i++)
  {
    sm->maxscore[i] = (-0x7fffffff - 1);
    for (j = 0; j < sm->size; j++)
    {
      if ((sc = get_score(sm, i+'A', j+'A')) > sm->maxscore[i])
      {
        sm->maxscore[i] = sc;
      }
    }
  }
}

variable_types: struct scorematrixStruct { int **matrix; int *maxscore; int indel; int size; } *

variable_types: i int

variable_types: j int

variable_types: sc int


decompiled_code:
void __fastcall delete_scorematrix(void *ptr)
{
if ( ptr )
{
free(**(void ***)ptr);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
free(**(void ***)ptr);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void delete_scorematrix(scorematrix* sm)
{
  if (sm == ((void *)0))
    return;
  free(sm->matrix[0]);
  free(sm->matrix);
  free(sm->maxscore);
  free(sm);
}

canonical_original_code:
void delete_scorematrix(struct scorematrixStruct *sm)
{
  if (sm == ((void *)0))
    return;
  free(sm->matrix[0]);
  free(sm->matrix);
  free(sm->maxscore);
  free(sm);
}


decompiled_code:
void __fastcall show_scorematrix(__int64 a1)
{
unsigned int i; // ebp
int v2; // ebx
int v3; // er12
unsigned int v4; // eax
int v5; // [rsp+Ch] [rbp-3Ch]

for ( i = 64; i != 92; ++i )
{
v3 = 65;
v2 = 64;
v5 = 0;
while ( 1 )
{
if ( i == 64 && v2 == 64 )
{
printf(" ");
goto LABEL_6;
}
if ( i == 64 )
break;
if ( v2 != 64 )
{
if ( (int)i > 64 && v2 > 64 && (unsigned int)get_score(a1, i, (unsigned int)(char)v2) != 0x80000000 )
{
v4 = get_score(a1, i, (unsigned int)(char)v2);
printf("%2d ", v4);
}
goto LABEL_5;
}
if ( (unsigned int)get_score(a1, i, 65LL) == 0x80000000 )
goto LABEL_5;
printf("%c ", i);
v5 = 1;
LABEL_6:
++v2;
++v3;
}
if ( (unsigned int)get_score(a1, (unsigned int)(char)v2, 65LL) != 0x80000000 )
{
printf(" %c ", (unsigned int)v2);
v5 = 1;
}
LABEL_5:
if ( v3 <= 91 )
goto LABEL_6;
if ( v5 )
putchar(10);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
unsigned int i; // ebp
int v2; // ebx
int v3; // er12
unsigned int v4; // eax
int v5; // [rsp+Ch] [rbp-3Ch]

for ( i = 64; i != 92; ++i )
{
v3 = 65;
v2 = 64;
v5 = 0;
while ( 1 )
{
if ( i == 64 && v2 == 64 )
{
printf(" ");
goto LABEL_6;
}
if ( i == 64 )
break;
if ( v2 != 64 )
{
if ( (int)i > 64 && v2 > 64 && (unsigned int)get_score(a1, i, (unsigned int)(char)v2) != 0x80000000 )
{
v4 = get_score(a1, i, (unsigned int)(char)v2);
printf("%2d ", v4);
}
goto LABEL_5;
}
if ( (unsigned int)get_score(a1, i, 65LL) == 0x80000000 )
goto LABEL_5;
printf("%c ", i);
v5 = 1;
LABEL_6:
++v2;
++v3;
}
if ( (unsigned int)get_score(a1, (unsigned int)(char)v2, 65LL) != 0x80000000 )
{
printf(" %c ", (unsigned int)v2);
v5 = 1;
}
LABEL_5:
if ( v3 <= 91 )
goto LABEL_6;
if ( v5 )
putchar(10);
}
}

original_code:
void show_scorematrix(scorematrix* sm)
{
  int i,j,print;
  for (i = 'A'-1; i <= '['; i++)
  {
    print = 0;
    for (j = 'A'-1; j <= '['; j++)
    {
      if (i == 'A'-1 && j == 'A'-1)
      {
        printf("  ");
      }
      else if (i == 'A'-1 && get_score(sm,j,'A') > (-0x7fffffff - 1))
      {
        printf(" %c ", j);
        print = 1;
      }
      else if (j == 'A'-1 && get_score(sm,i,'A') > (-0x7fffffff - 1))
      {
        printf("%c ", i);
        print = 1;
      }
      else if (i >= 'A' && j >= 'A' && get_score(sm,i,j) > (-0x7fffffff - 1))
        printf("%2d ", get_score(sm,i,j));
      else
        ;
    }
    if (print)
      printf("\n");
  }
}

canonical_original_code:
void show_scorematrix(struct scorematrixStruct *sm)
{
  int i; int j; int print;
  for (i = 'A'-1; i <= '['; i++)
  {
    print = 0;
    for (j = 'A'-1; j <= '['; j++)
    {
      if (i == 'A'-1 && j == 'A'-1)
      {
        printf("  ");
      }
      else if (i == 'A'-1 && get_score(sm,j,'A') > (-0x7fffffff - 1))
      {
        printf(" %c ", j);
        print = 1;
      }
      else if (j == 'A'-1 && get_score(sm,i,'A') > (-0x7fffffff - 1))
      {
        printf("%c ", i);
        print = 1;
      }
      else if (i >= 'A' && j >= 'A' && get_score(sm,i,j) > (-0x7fffffff - 1))
        printf("%2d ", get_score(sm,i,j));
      else
        ;
    }
    if (print)
      printf("\n");
  }
}

variable_types: print int


qgdist

original_code:
int qgdist(char* u, char* v, int q, int r, int* A)
{
  int m = strlen(u);
  int n = strlen(v);
  if (q > m || q > n)
    return -1;
  int* rpot = get_pot_list(r,q);
  int* tu = (int*) calloc(rpot[q], sizeof(int));
  int* tv = (int*) calloc(rpot[q], sizeof(int));
  linkedlist* C = linked_list_new();
  unsigned long int i;
  int c = 0;
  int fail;
  for (i = 1; i <= q; i++)
  {
    c += translate(u[i-1],A,&fail)*rpot[q-i];
  }
  if (fail)
    return -1;
  tu[c] = 1;
  linked_list_add(C,c);
  for (i = 1; i <= m-q; i++)
  {
    c = (c - translate(u[i-1],A,&fail)*rpot[q-1])*r + translate(u[i+q-1],A,&fail);
    if (fail)
      return -1;
    if (tu[c] == 0)
      linked_list_add(C,c);
    tu[c]++;
  }
  c = 0;
  for (i = 1; i <= q; i++)
  {
    c += translate(v[i-1],A,&fail)*rpot[q-i];
  }
  if (fail)
    return -1;
  tv[c] = 1;
  if (tu[c] == 0)
    linked_list_add(C,c);
  for (i = 1; i <= n-q; i++)
  {
    c = (c - translate(v[i-1],A,&fail)*rpot[q-1])*r + translate(v[i+q-1],A,&fail);
    if (fail)
      return -1;
    if (tv[c] == 0 && tu[c] == 0)
      linked_list_add(C,c);
    tv[c]++;
  }
  llentry* curr = C->root;
  int result = 0;
  while (curr != ((void *)0))
  {
    c = curr->key;
    result += abs(tu[c]-tv[c]);
    curr = curr->next;
  }
  linked_list_delete(C);
  free(rpot);
  free(tu);
  free(tv);
  return result;
}

canonical_original_code:
int qgdist(char *u, char *v, int q, int r, int *A)
{
  int m = strlen(u);
  int n = strlen(v);
  if (q > m || q > n)
    return -1;
  int *rpot = get_pot_list(r,q);
  int *tu = (int*) calloc(rpot[q], sizeof(int));
  int *tv = (int*) calloc(rpot[q], sizeof(int));
  struct llStruct *C = linked_list_new();
  unsigned long i;
  int c = 0;
  int fail;
  for (i = 1; i <= q; i++)
  {
    c += translate(u[i-1],A,&fail)*rpot[q-i];
  }
  if (fail)
    return -1;
  tu[c] = 1;
  linked_list_add(C,c);
  for (i = 1; i <= m-q; i++)
  {
    c = (c - translate(u[i-1],A,&fail)*rpot[q-1])*r + translate(u[i+q-1],A,&fail);
    if (fail)
      return -1;
    if (tu[c] == 0)
      linked_list_add(C,c);
    tu[c]++;
  }
  c = 0;
  for (i = 1; i <= q; i++)
  {
    c += translate(v[i-1],A,&fail)*rpot[q-i];
  }
  if (fail)
    return -1;
  tv[c] = 1;
  if (tu[c] == 0)
    linked_list_add(C,c);
  for (i = 1; i <= n-q; i++)
  {
    c = (c - translate(v[i-1],A,&fail)*rpot[q-1])*r + translate(v[i+q-1],A,&fail);
    if (fail)
      return -1;
    if (tv[c] == 0 && tu[c] == 0)
      linked_list_add(C,c);
    tv[c]++;
  }
  struct entstruct *curr = C->root;
  int result = 0;
  while (curr != ((void *)0))
  {
    c = curr->key;
    result += abs(tu[c]-tv[c]);
    curr = curr->next;
  }
  linked_list_delete(C);
  free(rpot);
  free(tu);
  free(tv);
  return result;
}

variable_types:
u
char *

variable_types:
v
char *

variable_types: q int

variable_types: r int

variable_types:
A
int *

variable_types: m int

variable_types: n int

variable_types:
rpot
int *

variable_types:
tu
int *

variable_types:
tv
int *

variable_types: struct llStruct { struct entstruct { struct entstruct *next; int key; } *root; struct entstruct *end; } *

variable_types:
i
unsigned long

variable_types: c int

variable_types: fail int

variable_types: result int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // r13
const char *v5; // r14
int v6; // ebp
int v7; // er15
_DWORD *v8; // rax
void *v9; // rbx
unsigned int v10; // eax
int v12; // [rsp+Ch] [rbp-3Ch] BYREF

if ( argc <= 4 )
{
printf("usage: %s seq1 seq2 A q\n", *argv);
v6 = 0;
}
else
{
v3 = argv[1];
v4 = argv[2];
v5 = argv[3];
v6 = _isoc99_sscanf(argv[4], "%d", &v12);
if ( v6 == 1 && v12 > 0 )
{
v7 = strlen(v5);
v8 = new_alphabet(v5);
v9 = v8;
if ( v8 )
{
v10 = qgdist(v3, v4, v12, v7, (__int64)v8);
printf("qgdist(u,v) = %d\n", v10);
free(v9);
v6 = 0;
}
}
else
{
printf("invalid parameter q=%s\n", argv[4]);
v6 = 1;
}
}
return v6;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char *v4; // r13
const char *v5; // r14
int v6; // ebp
int v7; // er15
_DWORD *v8; // rax
void *v9; // rbx
unsigned int v10; // eax
int v12; // [rsp+Ch] [rbp-3Ch] BYREF

if ( argc <= 4 )
{
printf("usage: %s seq1 seq2 A q\n", *argv);
v6 = 0;
}
else
{
v3 = argv[1];
v4 = argv[2];
v5 = argv[3];
v6 = _isoc99_sscanf(argv[4], "%d", &v12);
if ( v6 == 1 && v12 > 0 )
{
v7 = strlen(v5);
v8 = new_alphabet(v5);
v9 = v8;
if ( v8 )
{
v10 = func0(v3, v4, v12, v7, (__int64)v8);
printf("qgdist(u,v) = %d\n", v10);
free(v9);
v6 = 0;
}
}
else
{
printf("invalid parameter q=%s\n", argv[4]);
v6 = 1;
}
}
return v6;
}

original_code:
int main(int argc, char* argv[])
{
  if (argc < 5)
  {
    printf("usage: %s seq1 seq2 A q\n", argv[0]);
    return 0;
  }
  char* u = argv[1];
  char* v = argv[2];
  char* Astring= argv[3];
  int q;
  if (sscanf(argv[4], "%d", &q) != 1 || q < 1)
  {
    printf ("invalid parameter q=%s\n", argv[4]);
    return 1;
  }
  int r = strlen(Astring);
  int* A = new_alphabet(Astring);
  if (A == ((void *)0))
    return 1;
  int cost = qgdist(u,v,q,r,A);
  printf("qgdist(u,v) = %d\n", cost);
  free(A);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if (argc < 5)
  {
    printf("usage: %s seq1 seq2 A q\n", argv[0]);
    return 0;
  }
  char *u = argv[1];
  char *v = argv[2];
  char *Astring = argv[3];
  int q;
  if (sscanf(argv[4], "%d", &q) != 1 || q < 1)
  {
    printf ("invalid parameter q=%s\n", argv[4]);
    return 1;
  }
  int r = strlen(Astring);
  int *A = new_alphabet(Astring);
  if (A == ((void *)0))
    return 1;
  int cost = qgdist(u,v,q,r,A);
  printf("qgdist(u,v) = %d\n", cost);
  free(A);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
Astring
char *

variable_types: cost int


original_code:
static void max_pssmscore (Pssm* pssm)
{
  int i,j,sc;
  for (i = 0; i < pssm->positions; i++)
  {
    pssm->maxscore[i] = (-0x7fffffff - 1);
    for (j = 0; j < pssm->characters; j++)
    {
      if ((sc = get_pssmscore(pssm, i, j+'A')) > pssm->maxscore[i])
      {
        pssm->maxscore[i] = sc;
      }
    }
  }
}

canonical_original_code:
static void max_pssmscore(struct pssmStruct *pssm)
{
  int i; int j; int sc;
  for (i = 0; i < pssm->positions; i++)
  {
    pssm->maxscore[i] = (-0x7fffffff - 1);
    for (j = 0; j < pssm->characters; j++)
    {
      if ((sc = get_pssmscore(pssm, i, j+'A')) > pssm->maxscore[i])
      {
        pssm->maxscore[i] = sc;
      }
    }
  }
}

variable_types: struct pssmStruct { int **matrix; int *maxscore; int characters; } *

variable_types: i int

variable_types: j int

variable_types: sc int


decompiled_code:
void __fastcall delete_pssm(void *ptr)
{
if ( ptr )
{
free(**(void ***)ptr);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(**(void ***)ptr);
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
void delete_pssm(Pssm* pssm)
{
  if (pssm == ((void *)0))
    return;
  free(pssm->matrix[0]);
  free(pssm->matrix);
  free(pssm->maxscore);
  free(pssm);
}

canonical_original_code:
void delete_pssm(struct pssmStruct *pssm)
{
  if (pssm == ((void *)0))
    return;
  free(pssm->matrix[0]);
  free(pssm->matrix);
  free(pssm->maxscore);
  free(pssm);
}

user_defined_types: struct pssmStruct { int **matrix; int *maxscore; int characters; }


decompiled_code:
void __fastcall show_pssmatrix(__int64 a1)
{
unsigned int i; // ebp
int v2; // er13
unsigned int v3; // eax
int v4; // ebx

for ( i = 65; i != 92; ++i )
{
v2 = 0;
v4 = -1;
if ( *(int *)(a1 + 20) >= 0 )
{
do
{
if ( v4 == -1 )
{
if ( (unsigned int)get_pssmscore(a1, 0LL, i) != 0x80000000 )
{
putchar(i);
v2 = 1;
}
}
else if ( (int)i > 64 && v4 >= 0 && (unsigned int)get_pssmscore(a1, (unsigned int)v4, i) != 0x80000000 )
{
v3 = get_pssmscore(a1, (unsigned int)v4, i);
printf(" %3d", v3);
}
++v4;
}
while ( *(_DWORD *)(a1 + 20) > v4 );
if ( v2 )
putchar(10);
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
unsigned int i; // ebp
int v2; // er13
unsigned int v3; // eax
int v4; // ebx

for ( i = 65; i != 92; ++i )
{
v2 = 0;
v4 = -1;
if ( *(int *)(a1 + 20) >= 0 )
{
do
{
if ( v4 == -1 )
{
if ( (unsigned int)get_pssmscore(a1, 0LL, i) != 0x80000000 )
{
putchar(i);
v2 = 1;
}
}
else if ( (int)i > 64 && v4 >= 0 && (unsigned int)get_pssmscore(a1, (unsigned int)v4, i) != 0x80000000 )
{
v3 = get_pssmscore(a1, (unsigned int)v4, i);
printf(" %3d", v3);
}
++v4;
}
while ( *(_DWORD *)(a1 + 20) > v4 );
if ( v2 )
putchar(10);
}
}
}

original_code:
void show_pssmatrix(Pssm* pssm)
{
  int i,j,print;
  for (i = 'A'; i <= '['; i++)
  {
    print = 0;
    for (j = -1; j < pssm->positions; j++)
    {
      if (j == -1 && get_pssmscore(pssm,0,i) > (-0x7fffffff - 1))
      {
        printf("%c", i);
        print = 1;
      }
      else if (i >= 'A' && j >= 0 && get_pssmscore(pssm,j,i) > (-0x7fffffff - 1))
        printf(" %3d", get_pssmscore(pssm,j,i));
      else
        ;
    }
    if (print)
      printf("\n");
  }
}

canonical_original_code:
void show_pssmatrix(struct pssmStruct *pssm)
{
  int i; int j; int print;
  for (i = 'A'; i <= '['; i++)
  {
    print = 0;
    for (j = -1; j < pssm->positions; j++)
    {
      if (j == -1 && get_pssmscore(pssm,0,i) > (-0x7fffffff - 1))
      {
        printf("%c", i);
        print = 1;
      }
      else if (i >= 'A' && j >= 0 && get_pssmscore(pssm,j,i) > (-0x7fffffff - 1))
        printf(" %3d", get_pssmscore(pssm,j,i));
      else
        ;
    }
    if (print)
      printf("\n");
  }
}

variable_types: print int


unity

decompiled_code:
_BOOL8 __fastcall unity(char a1, char a2)
{
_BOOL8 result; // rax

if ( a1 == 45 || a2 == 45 )
result = 1LL;
else
result = a1 != a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1, char a2)
{
_BOOL8 result; // rax

if ( a1 == 45 || a2 == 45 )
result = 1LL;
else
result = a1 != a2;
return result;
}

original_code:
int unity (char a, char b)
{
  if (a == '-' || b == '-')
    return 1;
  return (a != b);
}

canonical_original_code:
int unity(char a, char b)
{
  if (a == '-' || b == '-')
    return 1;
  return (a != b);
}

variable_types: a char

variable_types: b char