LRUClockAlg

original_code:
int LRUClockAlg(int pageSequence[],int pageNumber,int frameNumber)
{
    gettimeofday(&tpstart,((void *)0));
    int frames[frameNumber+1];
    int clock[frameNumber+1];
    int i=1,k=1,l=1;
 int count=0,r=0,temp;
 int flag=0;
 for(i=1;i<=frameNumber;i++) clock[i]=0;
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
                clock[k]=0;
          frames[k]=pageSequence[i];
                k++;
       count++;
            }
   else
            {
       r++;
    flag=0;
       while(!flag)
                {
           if(clock[1]==0)
                    {
      for(l=1;l<frameNumber;l++)
                        {
                            frames[l]=frames[l+1];
                            clock[l]=clock[l+1];
                        }
           frames[frameNumber]=pageSequence[i];
                        clock[frameNumber]=0;
      flag=1;
                    }
     else
                    {
         clock[1]=0;
      temp=frames[1];
      for(l=1;l<frameNumber;l++)
                        {
                            frames[l]=frames[l+1];
                            clock[l]=clock[l+1];
                        }
      frames[frameNumber]=temp;
                        clock[frameNumber]=0;
                    }
                }
            }
        }
  else
        {
            clock[Search(frames,frameNumber,pageSequence[i])]=1;
        }
    }
    gettimeofday(&tpend,((void *)0));
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
    return r;
}

canonical_original_code:
int LRUClockAlg(int pageSequence[], int pageNumber, int frameNumber)
{
    gettimeofday(&tpstart,((void *)0));
    int frames[-1];
    int clock[-1];
    int i = 1; int k = 1; int l = 1;
 int count = 0; int r = 0; int temp;
 int flag = 0;
 for(i=1;i<=frameNumber;i++) clock[i]=0;
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
                clock[k]=0;
          frames[k]=pageSequence[i];
                k++;
       count++;
            }
   else
            {
       r++;
    flag=0;
       while(!flag)
                {
           if(clock[1]==0)
                    {
      for(l=1;l<frameNumber;l++)
                        {
                            frames[l]=frames[l+1];
                            clock[l]=clock[l+1];
                        }
           frames[frameNumber]=pageSequence[i];
                        clock[frameNumber]=0;
      flag=1;
                    }
     else
                    {
         clock[1]=0;
      temp=frames[1];
      for(l=1;l<frameNumber;l++)
                        {
                            frames[l]=frames[l+1];
                            clock[l]=clock[l+1];
                        }
      frames[frameNumber]=temp;
                        clock[frameNumber]=0;
                    }
                }
            }
        }
  else
        {
            clock[Search(frames,frameNumber,pageSequence[i])]=1;
        }
    }
    gettimeofday(&tpend,((void *)0));
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
    return r;
}

variable_types:
pageSequence
int []

variable_types: pageNumber int

variable_types: frameNumber int

variable_types:
clock
int [-1]

variable_types: k int

variable_types: l int

variable_types: temp int

variable_types: flag int


repo: ruijiege/System-Programming

decompiled_code:
__int64 __fastcall Search2(_DWORD *a1, int a2, unsigned int a3)
{
_DWORD *v3; // rax

if ( a2 > 1 )
{
v3 = a1;
while ( *v3 != a3 )
{
if ( ++v3 == &a1[a2 - 2 + 1] )
return a3;
}
a3 = 0;
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2, unsigned int a3)
{
_DWORD *v3; // rax

if ( a2 > 1 )
{
v3 = a1;
while ( *v3 != a3 )
{
if ( ++v3 == &a1[a2 - 2 + 1] )
return a3;
}
a3 = 0;
}
return a3;
}

original_code:
int Search2(int record[],int frameNumber,int singlepage)
{
    int i=0;
 while(i<frameNumber-1)
    {
     if(record[i]==singlepage)
        {
           return 0;
        }
        i++;
    }
    return singlepage;
}

canonical_original_code:
int Search2(int record[], int frameNumber, int singlepage)
{
    int i = 0;
 while(i<frameNumber-1)
    {
     if(record[i]==singlepage)
        {
           return 0;
        }
        i++;
    }
    return singlepage;
}

variable_types:
record
int []

variable_types: singlepage int

variable_types: i int

return_type: int


OptAlg

original_code:
int OptAlg(int pageSequence[],int pageNumber,int frameNumber)
{
    gettimeofday(&opttpstart,((void *)0));
    int count=0;
    int cnt=0;
    int flag=0;
    int r=0;
    int k=1;
    int m,n,rp,from,i,j;
    int record[frameNumber-1];
    for (m=0; m<frameNumber-1; m++) {record[m]=0;}
    int forsearch[frameNumber+1];
    for (n=0; n<frameNumber; n++) {forsearch[n]=n+1;}
    int frames[frameNumber+1];
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
          frames[k]=pageSequence[i];k++;
       count++;
            }
   else
            {
       r++;
                from=i+1;
                j=0;
                while ((cnt<frameNumber-1)&&(from<=pageNumber))
                {
                    flag=0;
                    if (Search(frames,frameNumber,pageSequence[from]))
                    {
                        for (m=0; m<frameNumber-1; m++)
                        {
                            if (record[m]==Search(frames,frameNumber,pageSequence[from]))
                            {
                                flag=1;
                            }
                        }
                        if (flag==0)
                        {
                            record[j]=Search(frames,frameNumber,pageSequence[from]);
                            j++;
                            cnt++;
                        }
                        from++;
                    }
                    else
                    {
                        from++;
                    }
                }
                if (cnt==(frameNumber-1))
                {
                    cnt=0;
                    for (m=0; m<frameNumber; m++)
                    {
                        rp=Search2(record,frameNumber,forsearch[m]);
                        if (rp)
                        {
                            frames[rp]=pageSequence[i];
                        }
                    }
                    for (m=0; m<frameNumber-1; m++) {record[m]=0;}
                }
                else
                {
                    cnt=0;
                    for (m=0; m<frameNumber; m++)
                    {
                        rp=Search2(record,frameNumber,forsearch[m]);
                        if (rp)
                        {
                            frames[rp]=pageSequence[i];
                        }
                    }
                    for (m=0; m<frameNumber-1; m++) {record[m]=0;}
                }
            }
        }
 }
    gettimeofday(&opttpend,((void *)0));
    opttimeuse=1000000*(opttpend.tv_sec-opttpstart.tv_sec)+opttpend.tv_usec-opttpstart.tv_usec;
    return r;
}

canonical_original_code:
int OptAlg(int pageSequence[], int pageNumber, int frameNumber)
{
    gettimeofday(&opttpstart,((void *)0));
    int count = 0;
    int cnt = 0;
    int flag = 0;
    int r = 0;
    int k = 1;
    int m; int n; int rp; int from; int i; int j;
    int record[-1];
    for (m=0; m<frameNumber-1; m++) {record[m]=0;}
    int forsearch[-1];
    for (n=0; n<frameNumber; n++) {forsearch[n]=n+1;}
    int frames[-1];
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
          frames[k]=pageSequence[i];k++;
       count++;
            }
   else
            {
       r++;
                from=i+1;
                j=0;
                while ((cnt<frameNumber-1)&&(from<=pageNumber))
                {
                    flag=0;
                    if (Search(frames,frameNumber,pageSequence[from]))
                    {
                        for (m=0; m<frameNumber-1; m++)
                        {
                            if (record[m]==Search(frames,frameNumber,pageSequence[from]))
                            {
                                flag=1;
                            }
                        }
                        if (flag==0)
                        {
                            record[j]=Search(frames,frameNumber,pageSequence[from]);
                            j++;
                            cnt++;
                        }
                        from++;
                    }
                    else
                    {
                        from++;
                    }
                }
                if (cnt==(frameNumber-1))
                {
                    cnt=0;
                    for (m=0; m<frameNumber; m++)
                    {
                        rp=Search2(record,frameNumber,forsearch[m]);
                        if (rp)
                        {
                            frames[rp]=pageSequence[i];
                        }
                    }
                    for (m=0; m<frameNumber-1; m++) {record[m]=0;}
                }
                else
                {
                    cnt=0;
                    for (m=0; m<frameNumber; m++)
                    {
                        rp=Search2(record,frameNumber,forsearch[m]);
                        if (rp)
                        {
                            frames[rp]=pageSequence[i];
                        }
                    }
                    for (m=0; m<frameNumber-1; m++) {record[m]=0;}
                }
            }
        }
 }
    gettimeofday(&opttpend,((void *)0));
    opttimeuse=1000000*(opttpend.tv_sec-opttpstart.tv_sec)+opttpend.tv_usec-opttpstart.tv_usec;
    return r;
}

variable_types: count int

variable_types: cnt int

variable_types: r int

variable_types: m int

variable_types: n int

variable_types: rp int

variable_types: from int

variable_types: j int

variable_types:
record
int [-1]

variable_types:
forsearch
int [-1]

variable_types:
frames
int [-1]


FifoAlg

original_code:
int FifoAlg(int pageSequence[],int pageNumber,int frameNumber)
{
    gettimeofday(&tpstart,((void *)0));
    int i=1,j=1,k=1;
 int count=0,r=0;
 int frames[frameNumber+1];
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
          frames[k]=pageSequence[i];k++;
       count++;
            }
   else
            {
       r++;
       for(j=1;j<frameNumber;j++)
        frames[j]=frames[j+1];
    frames[frameNumber]=pageSequence[i];
            }
  }
    }
    gettimeofday(&tpend,((void *)0));
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
    return r;
}

canonical_original_code:
int FifoAlg(int pageSequence[], int pageNumber, int frameNumber)
{
    gettimeofday(&tpstart,((void *)0));
    int i = 1; int j = 1; int k = 1;
 int count = 0; int r = 0;
 int frames[-1];
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
          frames[k]=pageSequence[i];k++;
       count++;
            }
   else
            {
       r++;
       for(j=1;j<frameNumber;j++)
        frames[j]=frames[j+1];
    frames[frameNumber]=pageSequence[i];
            }
  }
    }
    gettimeofday(&tpend,((void *)0));
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
    return r;
}

variable_types:
pageSequence
int []

variable_types: pageNumber int

variable_types: frameNumber int

variable_types: k int


LRUStackAlg

original_code:
int LRUStackAlg(int pageSequence[],int pageNumber,int frameNumber)
{
    gettimeofday(&tpstart,((void *)0));
    int i=1,k=frameNumber,l=1;
 int count=0,r=0,temp,add=0;
 int frames[frameNumber+1];
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
          frames[k]=pageSequence[i];k--;
       count++;
            }
   else
            {
       r++;
                for(l=frameNumber;l>0;l--)
                {
                    temp=frames[l-1];
                    frames[l]=temp;
                }
                frames[1]=pageSequence[i];
            }
        }
  else
        {
            add=Search(frames,frameNumber,pageSequence[i]);
            temp=frames[add];
            for(l=add;l>0;l--)
            {
                temp=frames[l-1];
                frames[l]=temp;
            }
            frames[1]=pageSequence[i];
        }
    }
    gettimeofday(&tpend,((void *)0));
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
    return r;
}

canonical_original_code:
int LRUStackAlg(int pageSequence[], int pageNumber, int frameNumber)
{
    gettimeofday(&tpstart,((void *)0));
    int i = 1; int k = frameNumber; int l = 1;
 int count = 0; int r = 0; int temp; int add = 0;
 int frames[-1];
 for(i=1;i<=frameNumber;i++) frames[i]=0;
 for(i=1;i<=pageNumber;i++)
    {
     if(!Search(frames,frameNumber,pageSequence[i]))
        {
         if(count<frameNumber)
            {
          frames[k]=pageSequence[i];k--;
       count++;
            }
   else
            {
       r++;
                for(l=frameNumber;l>0;l--)
                {
                    temp=frames[l-1];
                    frames[l]=temp;
                }
                frames[1]=pageSequence[i];
            }
        }
  else
        {
            add=Search(frames,frameNumber,pageSequence[i]);
            temp=frames[add];
            for(l=add;l>0;l--)
            {
                temp=frames[l-1];
                frames[l]=temp;
            }
            frames[1]=pageSequence[i];
        }
    }
    gettimeofday(&tpend,((void *)0));
    timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
    return r;
}

variable_types: l int

variable_types: temp int

variable_types: add int


printStack

repo: ruimiguelsantos/cstructspoc

decompiled_code:
int __fastcall printStack(__int64 a1)
{
unsigned int v1; // ebx
int v2; // eax
__int64 v3; // rbx

v1 = *(_DWORD *)(a1 + 0x2000);
printf("\nStatus [%d/%d]:\n", v1, 2048LL);
puts("--");
if ( *(_DWORD *)(a1 + 0x2000) )
{
v2 = v1 - 1;
v3 = (int)(v1 - 1);
if ( v2 >= 0 )
{
do
printf("|%d|\n", *(unsigned int *)(a1 + 4 * v3--));
while ( (int)v3 >= 0 );
}
}
else
{
puts("EMPTY");
}
return puts("--");
}

original_code:
void printStack(Buffer b){
  int i=(b->n)-1;
  printf("\nStatus [%d/%d]:\n",b->n,2048);
  printf("--\n");
  if(b -> n == 0)
    printf("EMPTY\n");
  else
    while(i >= 0){
      printf("|%d|\n",b->stack[i--]);
    }
  printf("--\n");
}

canonical_original_code:
void printStack(struct buffer *b){
  int i = (b->n)-1;
  printf("\nStatus [%d/%d]:\n",b->n,2048);
  printf("--\n");
  if(b -> n == 0)
    printf("EMPTY\n");
  else
    while(i >= 0){
      printf("|%d|\n",b->stack[i--]);
    }
  printf("--\n");
}

variable_types: struct buffer { int stack[2048]; int n; } *

variable_types: i int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
bool v4; // al
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
char *v15; // rsi
char v17; // [rsp+Bh] [rbp-45Dh]
unsigned int v18; // [rsp+Ch] [rbp-45Ch]
unsigned int s[15]; // [rsp+10h] [rbp-458h] BYREF
char v20; // [rsp+4Fh] [rbp-419h]
char v21[1048]; // [rsp+50h] [rbp-418h] BYREF

v3 = malloc(0x2004uLL);
init(v3, argv);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
printStack((__int64)v3);
printf("\naction (he for help)$ ");
fgets(v21, 1024, _bss_start);
*(&v20 + strlen(v21)) = 0;
v4 = strcmp(v21, "pu") != 0;
v5 = 0;
v6 = !v4;
if ( v4 )
break;
printf("Number to push: ");
fgets((char *)s, 50, _bss_start);
if ( (unsigned int)__isoc99_sscanf() == 2 && v17 == 10 )
{
if ( (unsigned int)add(v3, v18) )
printf("Pushed %d to stack. ", v18);
else
printf("Stack is full. ");
}
else
{
printf("Not a number. ");
}
LABEL_5:
printf("<ENTER>");
getchar();
}
v7 = "po";
v8 = 3LL;
v9 = v21;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
if ( (unsigned int)empty(v3, v9) )
goto LABEL_23;
rem(v3, s);
printf("Popped %d. ", s[0]);
printf("<ENTER>");
goto LABEL_24;
}
v10 = strcmp(v21, "to") != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
break;
if ( !(unsigned int)next(v3, s) )
{
LABEL_23:
printf("Stack is empty. <ENTER>");
goto LABEL_24;
}
printf("Stack top: %d <ENTER>", s[0]);
LABEL_24:
getchar();
}
v13 = "em";
v14 = 3LL;
v15 = v21;
do
{
if ( !v14 )
break;
v11 = (unsigned __int8)*v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) == v11 )
{
if ( (unsigned int)empty(v3, v15) )
printf("Stack is empty. ");
else
printf("stack is not empty. ");
goto LABEL_5;
}
if ( strcmp(v21, "he") )
break;
puts("\n# available actions:");
puts("# pu - push to stack;");
puts("# po - pop the stack;");
puts("# to - get stack top;");
puts("# em - check if stack is empty.");
puts("# he - print this helper.");
puts("# ex - exit.\n");
printf("<ENTER>");
getchar();
}
if ( !strcmp(v21, "ex") )
break;
printf("\nNot an action. Type he for available actions. ");
printf("<ENTER>");
getchar();
}
printf("Leaving... ");
printf("<ENTER>");
getchar();
puts("Done.");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbp
bool v4; // al
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char *v9; // rsi
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
char *v15; // rsi
char v17; // [rsp+Bh] [rbp-45Dh]
unsigned int v18; // [rsp+Ch] [rbp-45Ch]
unsigned int s[15]; // [rsp+10h] [rbp-458h] BYREF
char v20; // [rsp+4Fh] [rbp-419h]
char v21[1048]; // [rsp+50h] [rbp-418h] BYREF

v3 = malloc(0x2004uLL);
func8(v3, argv);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
func7((__int64)v3);
printf("\naction (he for help)$ ");
fgets(v21, 1024, _bss_start);
*(&v20 + strlen(v21)) = 0;
v4 = strcmp(v21, "pu") != 0;
v5 = 0;
v6 = !v4;
if ( v4 )
break;
printf("Number to push: ");
fgets((char *)s, 50, _bss_start);
if ( (unsigned int)__isoc99_sscanf() == 2 && v17 == 10 )
{
if ( (unsigned int)func10(v3, v18) )
printf("Pushed %d to stack. ", v18);
else
printf("Stack is full. ");
}
else
{
printf("Not a number. ");
}
LABEL_5:
printf("<ENTER>");
getchar();
}
v7 = "po";
v8 = 3LL;
v9 = v21;
do
{
if ( !v8 )
break;
v5 = (unsigned __int8)*v9 < (unsigned int)*v7;
v6 = *v9++ == *v7++;
--v8;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
if ( (unsigned int)func9(v3, v9) )
goto LABEL_23;
func12(v3, s);
printf("Popped %d. ", s[0]);
printf("<ENTER>");
goto LABEL_24;
}
v10 = strcmp(v21, "to") != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
break;
if ( !(unsigned int)func11(v3, s) )
{
LABEL_23:
printf("Stack is empty. <ENTER>");
goto LABEL_24;
}
printf("Stack top: %d <ENTER>", s[0]);
LABEL_24:
getchar();
}
v13 = "em";
v14 = 3LL;
v15 = v21;
do
{
if ( !v14 )
break;
v11 = (unsigned __int8)*v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) == v11 )
{
if ( (unsigned int)func9(v3, v15) )
printf("Stack is empty. ");
else
printf("stack is not empty. ");
goto LABEL_5;
}
if ( strcmp(v21, "he") )
break;
puts("\n# available actions:");
puts("# pu - push to stack;");
puts("# po - pop the stack;");
puts("# to - get stack top;");
puts("# em - check if stack is empty.");
puts("# he - print this helper.");
puts("# ex - exit.\n");
printf("<ENTER>");
getchar();
}
if ( !strcmp(v21, "ex") )
break;
printf("\nNot an action. Type he for available actions. ");
printf("<ENTER>");
getchar();
}
printf("Leaving... ");
printf("<ENTER>");
getchar();
puts("Done.");
return 1;
}

original_code:
int main(){
  Buffer b = (Buffer) malloc(sizeof(struct buffer));
  init(b);
  int r=0, resposta;
  while(r!=1){
    printStack(b);
    char input[1024];
    printf("\naction (he for help)$ ");
    fgets(input, sizeof(input), stdin);
    input[strlen(input)-1] = '\0';
    if(strcmp(input,"pu") == 0) {
      int num, scanres;
      char tempInput[50], enter;
      printf("Number to push: ");
      fgets(tempInput,sizeof(tempInput), stdin);
      scanres = sscanf(tempInput,"%d%c",&num,&enter);
      if(!(scanres == 2 && enter == '\n'))
        printf("Not a number. ");
      else {
        resposta = add(b,num);
        if(resposta)
          printf("Pushed %d to stack. ",num);
        else
          printf("Stack is full. ");
      }
      printf("<ENTER>");
      getchar();
    }
    else if(strcmp(input,"po") == 0) {
      int removed, ret;
      ret = empty(b);
      if(ret)
        printf("Stack is empty. <ENTER>");
      else {
        rem(b,&removed);
        printf("Popped %d. ",removed);
        printf("<ENTER>");
      }
      getchar();
    }
    else if(strcmp(input,"to") == 0) {
      int top, res;
      res = next(b,&top);
      if (res)
        printf("Stack top: %d <ENTER>",top);
      else
        printf("Stack is empty. <ENTER>");
      getchar();
    }
    else if(strcmp(input,"em") == 0) {
      if(empty(b))
        printf("Stack is empty. ");
      else
        printf("stack is not empty. ");
      printf("<ENTER>");
      getchar();
    }
    else if(strcmp(input,"he") == 0) {
      printf("\n# available actions:\n");
      printf("# pu - push to stack;\n");
      printf("# po - pop the stack;\n");
      printf("# to - get stack top;\n");
      printf("# em - check if stack is empty.\n");
      printf("# he - print this helper.\n");
      printf("# ex - exit.\n\n");
      printf("<ENTER>");
      getchar();
    }
    else if(strcmp(input,"ex") == 0) {
      r = 1;
      printf("Leaving... ");
      printf("<ENTER>");
      getchar();
    }
    else {
      printf("\nNot an action. Type he for available actions. ");
      printf("<ENTER>");
      getchar();
    }
  }
  printf("Done.\n");
  return 1;
}

canonical_original_code:
int main(){
  struct buffer *b = (Buffer) malloc(sizeof(struct buffer));
  init(b);
  int r = 0; int resposta;
  while(r!=1){
    printStack(b);
    char input[1024];
    printf("\naction (he for help)$ ");
    fgets(input, sizeof(input), stdin);
    input[strlen(input)-1] = '\0';
    if(strcmp(input,"pu") == 0) {
      int num; int scanres;
      char tempInput[50]; char enter;
      printf("Number to push: ");
      fgets(tempInput,sizeof(tempInput), stdin);
      scanres = sscanf(tempInput,"%d%c",&num,&enter);
      if(!(scanres == 2 && enter == '\n'))
        printf("Not a number. ");
      else {
        resposta = add(b,num);
        if(resposta)
          printf("Pushed %d to stack. ",num);
        else
          printf("Stack is full. ");
      }
      printf("<ENTER>");
      getchar();
    }
    else if(strcmp(input,"po") == 0) {
      int removed; int ret;
      ret = empty(b);
      if(ret)
        printf("Stack is empty. <ENTER>");
      else {
        rem(b,&removed);
        printf("Popped %d. ",removed);
        printf("<ENTER>");
      }
      getchar();
    }
    else if(strcmp(input,"to") == 0) {
      int top; int res;
      res = next(b,&top);
      if (res)
        printf("Stack top: %d <ENTER>",top);
      else
        printf("Stack is empty. <ENTER>");
      getchar();
    }
    else if(strcmp(input,"em") == 0) {
      if(empty(b))
        printf("Stack is empty. ");
      else
        printf("stack is not empty. ");
      printf("<ENTER>");
      getchar();
    }
    else if(strcmp(input,"he") == 0) {
      printf("\n# available actions:\n");
      printf("# pu - push to stack;\n");
      printf("# po - pop the stack;\n");
      printf("# to - get stack top;\n");
      printf("# em - check if stack is empty.\n");
      printf("# he - print this helper.\n");
      printf("# ex - exit.\n\n");
      printf("<ENTER>");
      getchar();
    }
    else if(strcmp(input,"ex") == 0) {
      r = 1;
      printf("Leaving... ");
      printf("<ENTER>");
      getchar();
    }
    else {
      printf("\nNot an action. Type he for available actions. ");
      printf("<ENTER>");
      getchar();
    }
  }
  printf("Done.\n");
  return 1;
}

variable_types: r int

variable_types: resposta int

variable_types:
input
char [1024]

variable_types: num int

variable_types: scanres int

variable_types:
tempInput
char [50]

variable_types: enter char

variable_types: removed int

variable_types: ret int

variable_types: top int

variable_types: res int

user_defined_types: struct buffer { int stack[2048]; int n; }


decompiled_code:
__int64 __fastcall cnd_rr(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("query != NULL", "nameserver.c", 0xA7u, "cnd_rr");
if ( !a2 )
_assert_fail("ip != 0x00", "nameserver.c", 0xA8u, "cnd_rr");
return make_dns_reply();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("query != NULL", "nameserver.c", 0xA7u, "cnd_rr");
if ( !a2 )
_assert_fail("ip != 0x00", "nameserver.c", 0xA8u, "cnd_rr");
return make_dns_reply();
}

original_code:
char *cnd_rr(struct dns_t *query, uint32_t ip, int *len) {
  ((void) sizeof ((query != ((void *)0)) ? 1 : 0), __extension__ ({ if (query != ((void *)0)) ; else __assert_fail ("query != NULL", "nameserver.c", 167, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ip != 0x00) ? 1 : 0), __extension__ ({ if (ip != 0x00) ; else __assert_fail ("ip != 0x00", "nameserver.c", 168, __extension__ __PRETTY_FUNCTION__); }));
  char *reply = ((void *)0);
  reply = make_dns_reply(query, ip, len);
  do{if(0) fprintf(stdout, "cnd_rr: choose ip %x\n", ip); }while(0);
  return reply;
}

canonical_original_code:
char *cnd_rr(struct dns_t *query, unsigned int ip, int *len) {
  ((void) sizeof ((query != ((void *)0)) ? 1 : 0), __extension__ ({ if (query != ((void *)0)) ; else __assert_fail ("query != NULL", "nameserver.c", 167, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((ip != 0x00) ? 1 : 0), __extension__ ({ if (ip != 0x00) ; else __assert_fail ("ip != 0x00", "nameserver.c", 168, __extension__ __PRETTY_FUNCTION__); }));
  char *reply = ((void *)0);
  reply = make_dns_reply(query, ip, len);
  do{if(0) fprintf(stdout, "cnd_rr: choose ip %x\n", ip); }while(0);
  return reply;
}

variable_types: struct dns_t { unsigned short msg_id; unsigned short flags; unsigned short QR; unsigned short OPCODE; unsigned short AA; unsigned short RD; unsigned short RA; unsigned short RCODE; unsigned short QDCOUNT; unsigned short ANCOUNT; char *QNAME; unsigned short QTYPE; unsigned short QCLASS; unsigned short NAME; unsigned short TYPE; unsigned short CLASS; unsigned int TTL; unsigned short RDLENGTH; unsigned int RDATA; } *

variable_types:
ip
unsigned int

variable_types:
len
int *

variable_types:
reply
char *

return_type: char *


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

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xC2u, "init_serverlist");
v1 = calloc(1uLL, 0x10uLL);
*a1 = v1;
*(_DWORD *)v1 = 0;
v1[1] = v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rax

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xC2u, "init_serverlist");
v1 = calloc(1uLL, 0x10uLL);
*a1 = v1;
*(_DWORD *)v1 = 0;
v1[1] = v1;
return 0LL;
}

original_code:
int init_serverlist(struct server_t **list) {
  ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "nameserver.c", 194, __extension__ __PRETTY_FUNCTION__); }));
  *list = (struct server_t *)calloc(1, sizeof(struct server_t));
  (*list)->server = 0x00;
  (*list)->next = *list;
  return 0;
}

variable_types: struct server_t { unsigned int server; struct server_t *next; } **


decompiled_code:
__int64 __fastcall push_server(__int64 a1, int a2)
{
_QWORD *v3; // rax

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xCDu, "push_server");
if ( *(_DWORD *)a1 )
{
v3 = calloc(1uLL, 0x10uLL);
*(_DWORD *)v3 = a2;
v3[1] = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v3;
}
else
{
*(_DWORD *)a1 = a2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
_QWORD *v3; // rax

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xCDu, "push_server");
if ( *(_DWORD *)a1 )
{
v3 = calloc(1uLL, 0x10uLL);
*(_DWORD *)v3 = a2;
v3[1] = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v3;
}
else
{
*(_DWORD *)a1 = a2;
}
return 0LL;
}

original_code:
int push_server(struct server_t *list, uint32_t server) {
  ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "nameserver.c", 205, __extension__ __PRETTY_FUNCTION__); }));
  if (list->server == 0x00) {
    list->server = server;
    return 0;
  }
  struct server_t *p = (struct server_t *)calloc(1, sizeof(struct server_t));
  p->server = server;
  p->next = list->next;
  list->next = p;
  return 0;
}

canonical_original_code:
int push_server(struct server_t *list, unsigned int server) {
  ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "nameserver.c", 205, __extension__ __PRETTY_FUNCTION__); }));
  if (list->server == 0x00) {
    list->server = server;
    return 0;
  }
  struct server_t *p = (struct server_t *)calloc(1, sizeof(struct server_t));
  p->server = server;
  p->next = list->next;
  list->next = p;
  return 0;
}

variable_types: struct server_t { unsigned int server; struct server_t *next; } *

variable_types:
server
unsigned int


decompiled_code:
__int64 __fastcall print_serverlist(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xE2u, "print_serverlist");
v1 = a1;
if ( *a1 )
{
do
{
printf("%x, ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( a1 != v1 );
putchar(10);
}
else
{
puts("list is null");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
unsigned int *v1; // rbx

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xE2u, "print_serverlist");
v1 = a1;
if ( *a1 )
{
do
{
printf("%x, ", *v1);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
while ( a1 != v1 );
putchar(10);
}
else
{
puts("list is null");
}
return 0LL;
}

original_code:
int print_serverlist(struct server_t *list) {
  ((void) sizeof ((list != ((void *)0)) ? 1 : 0), __extension__ ({ if (list != ((void *)0)) ; else __assert_fail ("list != NULL", "nameserver.c", 226, __extension__ __PRETTY_FUNCTION__); }));
  do{if(0) fprintf(stdout, "print_serverlist:\n"); }while(0);
  struct server_t *p = ((void *)0);
  if (list->server == 0x00) {
    printf("list is null\n");
    return 0;
  }
  p = list;
  do {
    printf("%x, ", p->server);
    p = p->next;
  } while (p != list);
  printf("\n");
  return 0;
}

user_defined_types: struct server_t { unsigned int server; struct server_t *next; }


decompiled_code:
__int64 __fastcall locate_file(__int64 a1)
{
__int64 result; // rax
_QWORD *v3; // rcx

result = 0LL;
if ( !*(_DWORD *)(a1 + 152) )
{
v3 = *(_QWORD **)(a1 + 184);
*v3 = 0LL;
v3[127] = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 1024) >> 3));
strcpy(*(char **)(a1 + 184), *(const char **)(a1 + 176));
strcat(*(char **)(a1 + 184), (const char *)(*(_QWORD *)(a1 + 112) + 2052LL));
result = (unsigned int)-((unsigned int)check_path(a1) == -1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
_QWORD *v3; // rcx

result = 0LL;
if ( !*(_DWORD *)(a1 + 152) )
{
v3 = *(_QWORD **)(a1 + 184);
*v3 = 0LL;
v3[127] = 0LL;
memset(
(void *)((unsigned __int64)(v3 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v3 - (((_DWORD)v3 + 8) & 0xFFFFFFF8) + 1024) >> 3));
strcpy(*(char **)(a1 + 184), *(const char **)(a1 + 176));
strcat(*(char **)(a1 + 184), (const char *)(*(_QWORD *)(a1 + 112) + 2052LL));
result = (unsigned int)-((unsigned int)check_path(a1) == -1);
}
return result;
}

original_code:
int locate_file(struct buf *bufp) {
    do{if(0) fprintf(stdout, "locate_file: bufp->res_line_header_create==%d\n", bufp->res_line_header_created); }while(0);
    if (bufp->res_line_header_created == 0) {
 memset(bufp->path, 0, 1024);
 do{if(0) fprintf(stdout, "locate_file: uri:%s\n", bufp->http_reply_p->uri); }while(0);
 strcpy(bufp->path, bufp->www);
 strcat(bufp->path, bufp->http_reply_p->uri);
 do{if(0) fprintf(stdout, "locate_file: save path, bufp->path:%s\n", bufp->path); }while(0);
 if (check_path(bufp) == -1) {
     do{if(0) fprintf(stdout, "lcoate_file: check_path failed"); }while(0);
     return -1;
 }
    }
    return 0;
}

variable_types: struct buf { int is_cgi_req; char https[2]; char *remote_addr; int buf_sock; struct req_queue { struct http_req { int cont_len; char cont_type[1024]; char method[1024]; char uri[1024]; char http_accept[1024]; char http_referer[1024]; char http_accept_encoding[1024]; char http_accept_language[1024]; char http_accept_charset[1024]; char host[1024]; char cookie[1024]; char user_agent[1024]; char connection[1024]; char https[1024]; char version[1024]; char *contp; int use_cgi_folder; char *cgi_arg_list[1024]; char *cgi_env_list[1024]; int fds[2]; char *orig_req; char *orig_cur; struct http_req *next; } *req_head; struct http_req *req_tail; int req_count; } *req_queue_p; struct http_req *http_req_p; int req_line_header_received; int req_body_received; int req_fully_received; int rbuf_req_count; char *rbuf; char *rbuf_head; char *rbuf_tail; char *line_head; char *line_tail; char *parse_p; int rbuf_free_size; int rbuf_size; struct http_req *http_reply_p; char *buf; char *buf_head; char *buf_tail; int buf_size; int buf_free_size; int res_line_header_created; int res_body_created; int res_fully_created; int res_fully_sent; char *cgiscript; char *www; char *path; long offset; int allocated; int server_port; int status; int sock2server; int sock2browser; double ts; double tf; unsigned long Bsize; int bitrate; char *client_ip; char *chunk_name; long recv_time; } *

user_defined_types: struct buf { int is_cgi_req; char https[2]; char *remote_addr; int buf_sock; struct req_queue *req_queue_p; struct http_req *http_req_p; int req_line_header_received; int req_body_received; int req_fully_received; int rbuf_req_count; char *rbuf; char *rbuf_head; char *rbuf_tail; char *line_head; char *line_tail; char *parse_p; int rbuf_free_size; int rbuf_size; struct http_req *http_reply_p; char *buf; char *buf_head; char *buf_tail; int buf_size; int buf_free_size; int res_line_header_created; int res_body_created; int res_fully_created; int res_fully_sent; char *cgiscript; char *www; char *path; long offset; int allocated; int server_port; int status; int sock2server; int sock2browser; double ts; double tf; unsigned long Bsize; int bitrate; char *client_ip; char *chunk_name; long recv_time; }

user_defined_types: struct req_queue { struct http_req *req_head; struct http_req *req_tail; int req_count; }


decompiled_code:
__int64 __fastcall send_response(int a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v4; // eax
unsigned int v5; // edx

v2 = *(_DWORD *)(a2 + 144);
if ( v2 )
{
v4 = send(a1, *(const void **)(a2 + 128), (int)v2, 0);
v2 = v4;
if ( v4 == -1 )
{
perror("Error! send_response: send");
}
else
{
*(_QWORD *)(a2 + 128) += (int)v4;
v5 = *(_DWORD *)(a2 + 144) - v4;
*(_DWORD *)(a2 + 144) = v5;
if ( !v5 )
reset_buf(a2);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v4; // eax
unsigned int v5; // edx

v2 = *(_DWORD *)(a2 + 144);
if ( v2 )
{
v4 = send(a1, *(const void **)(a2 + 128), (int)v2, 0);
v2 = v4;
if ( v4 == -1 )
{
perror("Error! send_response: send");
}
else
{
*(_QWORD *)(a2 + 128) += (int)v4;
v5 = *(_DWORD *)(a2 + 144) - v4;
*(_DWORD *)(a2 + 144) = v5;
if ( !v5 )
reset_buf(a2);
}
}
return v2;
}

original_code:
int send_response(int sock, struct buf *bufp) {
    int sendret;
    if (bufp->buf_size == 0) {
 do{if(0) fprintf(stdout, "send_response: buffer is empty, sending finished\n"); }while(0);
 return 0;
    }
    sendret = send(sock, bufp->buf_head, bufp->buf_size, 0);
    if (sendret == -1) {
 perror("Error! send_response: send");
 return -1;
    }
    bufp->buf_head += sendret;
    bufp->buf_size -= sendret;
    do{if(0) fprintf(stdout, "send_response: %d bytes are sent\n", sendret); }while(0);
    if (bufp->buf_size == 0) {
 reset_buf(bufp);
 do{if(0) fprintf(stdout, "send_response: whole buf is sent, reset it\n"); }while(0);
    }
    return sendret;
}

variable_types: sock int

variable_types: sendret int

user_defined_types: struct http_req { int cont_len; char cont_type[1024]; char method[1024]; char uri[1024]; char http_accept[1024]; char http_referer[1024]; char http_accept_encoding[1024]; char http_accept_language[1024]; char http_accept_charset[1024]; char host[1024]; char cookie[1024]; char user_agent[1024]; char connection[1024]; char https[1024]; char version[1024]; char *contp; int use_cgi_folder; char *cgi_arg_list[1024]; char *cgi_env_list[1024]; int fds[2]; char *orig_req; char *orig_cur; struct http_req *next; }


decompiled_code:
char *date_str()
{
char *v0; // rbx
struct tm *v1; // rax
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v0 = (char *)calloc(0x80uLL, 1uLL);
timer = time(0LL);
v1 = gmtime(&timer);
strcpy(v0, "Date: ");
v2 = asctime(v1);
strcat(v0, v2);
v0[strlen(v0) - 1] = 0;
strcat(v0, "\r\n");
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx
struct tm *v1; // rax
char *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v0 = (char *)calloc(0x80uLL, 1uLL);
timer = time(0LL);
v1 = gmtime(&timer);
strcpy(v0, "Date: ");
v2 = asctime(v1);
strcat(v0, v2);
v0[strlen(v0) - 1] = 0;
strcat(v0, "\r\n");
return v0;
}

original_code:
char *date_str() {
    time_t rawtime;
    struct tm *timeinfo;
    char *time_str = (char *)calloc(128, sizeof(char));
    rawtime = time(((void *)0));
    timeinfo = gmtime(&rawtime);
    strcpy(time_str, "Date: ");
    strcat(time_str, asctime(timeinfo));
    time_str[strlen(time_str)-1] = '\0';
    strcat(time_str, "\r\n");
    return time_str;
}

canonical_original_code:
char *date_str() {
    long rawtime;
    struct tm *timeinfo;
    char *time_str = (char *)calloc(128, sizeof(char));
    rawtime = time(((void *)0));
    timeinfo = gmtime(&rawtime);
    strcpy(time_str, "Date: ");
    strcat(time_str, asctime(timeinfo));
    time_str[strlen(time_str)-1] = '\0';
    strcat(time_str, "\r\n");
    return time_str;
}

variable_types: rawtime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


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

result = (char *)calloc(0x80uLL, 1uLL);
if ( !strcmp((const char *)(*(_QWORD *)(a1 + 32) + 11268LL), "keep-alive") )
strcpy(result, "Connection: keep-alive\r\n");
else
strcpy(result, "Connection: closed\r\n");
return result;
}

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

result = (char *)calloc(0x80uLL, 1uLL);
if ( !strcmp((const char *)(*(_QWORD *)(a1 + 32) + 11268LL), "keep-alive") )
strcpy(result, "Connection: keep-alive\r\n");
else
strcpy(result, "Connection: closed\r\n");
return result;
}

original_code:
char *connection_str(struct buf *bufp) {
    char *str = (char *)calloc(128, sizeof(char));
    if (strcmp(bufp->http_req_p->connection, "keep-alive") == 0)
 strcpy(str, "Connection: keep-alive\r\n");
    else
 strcpy(str, "Connection: closed\r\n");
    return str;
}

variable_types:
str
char *


decompiled_code:
char *__fastcall cont_type_str(__int64 a1)
{
char *v1; // rbp
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

v1 = (char *)calloc(0x80uLL, 1uLL);
v2 = strstr(*(const char **)(a1 + 184), ".html");
if ( v2 && !v2[5] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&TEXT_HTML);
v3 = strstr(*(const char **)(a1 + 184), ".css");
if ( v3 && !v3[4] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&TEXT_CSS);
v4 = strstr(*(const char **)(a1 + 184), ".png");
if ( v4 && !v4[4] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&IMAGE_PNG);
v5 = strstr(*(const char **)(a1 + 184), ".jpeg");
if ( v5 && !v5[5] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&IMAGE_JPEG);
v6 = strstr(*(const char **)(a1 + 184), ".gif");
if ( v6 && !v6[4] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&IMAGE_GIF);
return v1;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
char *v1; // rbp
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

v1 = (char *)calloc(0x80uLL, 1uLL);
v2 = strstr(*(const char **)(a1 + 184), ".html");
if ( v2 && !v2[5] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&TEXT_HTML);
v3 = strstr(*(const char **)(a1 + 184), ".css");
if ( v3 && !v3[4] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&TEXT_CSS);
v4 = strstr(*(const char **)(a1 + 184), ".png");
if ( v4 && !v4[4] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&IMAGE_PNG);
v5 = strstr(*(const char **)(a1 + 184), ".jpeg");
if ( v5 && !v5[5] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&IMAGE_JPEG);
v6 = strstr(*(const char **)(a1 + 184), ".gif");
if ( v6 && !v6[4] )
sprintf(v1, "Content-Type: %s\r\n", (const char *)&IMAGE_GIF);
return v1;
}

original_code:
char *cont_type_str(struct buf *bufp) {
    char *str = (char *)calloc(128, sizeof(char));
    char *p;
    if ((p = strstr(bufp->path, ".html")) != ((void *)0)
 && *(p + strlen(".html")) == '\0') {
 sprintf(str, "Content-Type: %s\r\n", TEXT_HTML);
    }
    if ((p = strstr(bufp->path, ".css")) != ((void *)0)
 && *(p + strlen(".css")) == '\0')
 sprintf(str, "Content-Type: %s\r\n", TEXT_CSS);
    if ((p = strstr(bufp->path, ".png")) != ((void *)0)
 && *(p + strlen(".png")) == '\0')
 sprintf(str, "Content-Type: %s\r\n", IMAGE_PNG);
    if ((p = strstr(bufp->path, ".jpeg")) != ((void *)0)
 && *(p + strlen(".jpeg")) == '\0')
 sprintf(str, "Content-Type: %s\r\n", IMAGE_JPEG);
    if ((p = strstr(bufp->path, ".gif")) != ((void *)0)
 && *(p + strlen(".gif")) == '\0')
 sprintf(str, "Content-Type: %s\r\n", IMAGE_GIF);
    return str;
}

variable_types:
p
char *


decompiled_code:
char *__fastcall last_modified_str(__int64 a1)
{
char *v1; // rbx
struct tm *v2; // rax
char *v3; // rax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)calloc(0x80uLL, 1uLL);
if ( stat(*(const char **)(a1 + 184), &v5) == -1 )
{
perror("Error! last_modified_str, stat");
strcpy(v1, "Last-Modified:\r\n");
}
else
{
v2 = gmtime(&v5.st_mtim.tv_sec);
strcpy(v1, "Last-Modified: ");
v3 = asctime(v2);
strcat(v1, v3);
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1)
{
char *v1; // rbx
struct tm *v2; // rax
char *v3; // rax
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)calloc(0x80uLL, 1uLL);
if ( stat(*(const char **)(a1 + 184), &v5) == -1 )
{
perror("Error! last_modified_str, stat");
strcpy(v1, "Last-Modified:\r\n");
}
else
{
v2 = gmtime(&v5.st_mtim.tv_sec);
strcpy(v1, "Last-Modified: ");
v3 = asctime(v2);
strcat(v1, v3);
}
return v1;
}

original_code:
char *last_modified_str(struct buf *bufp) {
    struct stat status;
    struct tm *timeinfo;
    char *str = (char *)calloc(128, sizeof(char));
    if (stat(bufp->path, &status) == -1) {
 perror("Error! last_modified_str, stat");
 strcpy(str, "Last-Modified:\r\n");
 return str;
    }
    timeinfo = gmtime(&(status.st_mtim.tv_sec));
    strcpy(str, "Last-Modified: ");
    strcat(str, asctime(timeinfo));
    return str;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
void __fastcall push_header(__int64 a1)
{
char *v1; // rbp
char *v2; // rbp
char *v3; // rbp
char *v4; // rbp
char *v5; // rbp

v1 = date_str();
push_str(a1, v1);
free(v1);
v2 = connection_str(a1);
push_str(a1, v2);
free(v2);
push_str(a1, &server);
v3 = cont_len_str(a1);
push_str(a1, v3);
free(v3);
v4 = cont_type_str(a1);
push_str(a1, v4);
free(v4);
v5 = last_modified_str(a1);
push_str(a1, v5);
free(v5);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
char *v1; // rbp
char *v2; // rbp
char *v3; // rbp
char *v4; // rbp
char *v5; // rbp

v1 = func2();
push_str(a1, v1);
free(v1);
v2 = func3(a1);
push_str(a1, v2);
free(v2);
push_str(a1, &server);
v3 = func4(a1);
push_str(a1, v3);
free(v3);
v4 = func5(a1);
push_str(a1, v4);
free(v4);
v5 = func6(a1);
push_str(a1, v5);
free(v5);
}

original_code:
void push_header(struct buf *bufp){
    char *p;
    p = date_str();
    do{if(0) fprintf(stdout, "date_str:%s", p); }while(0);
    push_str(bufp, p);
    free(p);
    p = connection_str(bufp);
    do{if(0) fprintf(stdout, "connection_str:%s", p); }while(0);
    push_str(bufp, p);
    free(p);
    do{if(0) fprintf(stdout, "server:%s", server); }while(0);
    push_str(bufp, server);
    p = cont_len_str(bufp);
    do{if(0) fprintf(stdout, "cont_len_str:%s", p); }while(0);
    push_str(bufp, p);
    free(p);
    p = cont_type_str(bufp);
    do{if(0) fprintf(stdout, "cont_type_str:%s", p); }while(0);
    push_str(bufp, p);
    free(p);
    p = last_modified_str(bufp);
    do{if(0) fprintf(stdout, "last_modified_str:%s", p); }while(0);
    push_str(bufp, p);
    free(p);
}


decompiled_code:
__int64 __fastcall create_res_body(__int64 a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rsi
const char *v5; // rdi
__int64 v6; // rcx
int v8; // eax

v1 = *(_DWORD *)(a1 + 160) == 0;
v2 = *(_DWORD *)(a1 + 160) == 1;
if ( *(_DWORD *)(a1 + 160) == 1 )
return 0LL;
v4 = (const char *)(*(_QWORD *)(a1 + 112) + 1028LL);
v5 = "GET";
v6 = 4LL;
do
{
if ( !v6 )
break;
v1 = *v4 < (unsigned int)*v5;
v2 = *v4++ == *v5++;
--v6;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
{
v8 = push_fd(a1, v4);
if ( v8 )
{
if ( v8 == -1 )
{
fwrite("Error! Failed reading file, handle this later\n", 1uLL, 0x2EuLL, stderr);
push_error((_DWORD *)a1, (__int64)&MSG500);
}
else if ( v8 == 1 )
{
*(_DWORD *)(a1 + 160) = 0;
}
}
else
{
*(_DWORD *)(a1 + 160) = 1;
}
}
else
{
*(_DWORD *)(a1 + 160) = 1;
}
return 0LL;
}

original_code:
int create_res_body(struct buf *bufp) {
    int push_ret;
    if (bufp->res_fully_created == 1) {
 do{if(0) fprintf(stdout, "create_res_body: res_fully_created == 1\n"); }while(0);
 return 0;
    }
    if (strcmp(bufp->http_reply_p->method, "GET") == 0){
 if ((push_ret = push_fd(bufp)) == 0) {
     do{if(0) fprintf(stdout, "create_res_body: file %s is read through\n", bufp->path); }while(0);
     bufp->res_fully_created = 1;
 } else if (push_ret == -1) {
     fprintf(stderr, "Error! Failed reading file, handle this later\n");
     push_error(bufp, MSG500);
 } else if (push_ret == 1) {
     do{if(0) fprintf(stdout, "create_res_body: file %s is not read through yet\n", bufp->path); }while(0);
     bufp->res_fully_created = 0;
 }
    } else {
 bufp->res_fully_created = 1;
    }
    return 0;
}


decompiled_code:
__int64 __fastcall create_line_header(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
const char *v3; // r12

v1 = 0;
if ( *(_DWORD *)(a1 + 152) != 1 )
{
v2 = *(_QWORD *)(a1 + 112);
v1 = strcmp((const char *)(v2 + 13316), &VERSION);
if ( v1 )
{
push_error((_DWORD *)a1, (__int64)&MSG505);
v1 = -1;
}
else
{
v3 = (const char *)(v2 + 1028);
if ( !strcmp(v3, "GET") || !strcmp(v3, "HEAD") || !strcmp(v3, "POST") )
{
push_str(a1, &MSG200);
push_header(a1);
push_str(a1, &CRLF);
*(_DWORD *)(a1 + 152) = 1;
}
else
{
push_error((_DWORD *)a1, (__int64)&MSG501);
v1 = -1;
}
}
}
return v1;
}

original_code:
int create_line_header(struct buf *bufp) {
    struct http_req *http_reply_p;
    http_reply_p = bufp->http_reply_p;
    if (bufp->res_line_header_created == 1)
 return 0;
    if (strcmp(http_reply_p->version, VERSION) != 0){
 do{if(0) fprintf(stdout, "create_line_header: %s not right, send msg505 back\n", http_reply_p->version); }while(0);
 push_error(bufp, MSG505);
 return -1;
    }
    if (strcmp(http_reply_p->method, "GET") == 0
 || strcmp(http_reply_p->method, "HEAD") == 0
 || strcmp(http_reply_p->method, "POST") == 0) {
 do{if(0) fprintf(stdout, "create_line_header: create status line and headers for %s method\n", bufp->http_req_p->method); }while(0);
 push_str(bufp, MSG200);
 push_header(bufp);
 push_str(bufp, CRLF);
 bufp->res_line_header_created = 1;
    } else {
 do{if(0) fprintf(stdout, "create_line_header: method not implemented\n"); }while(0);
 push_error(bufp, MSG501);
 return -1;
    }
    return 0;
}

variable_types: struct http_req { int cont_len; char cont_type[1024]; char method[1024]; char uri[1024]; char http_accept[1024]; char http_referer[1024]; char http_accept_encoding[1024]; char http_accept_language[1024]; char http_accept_charset[1024]; char host[1024]; char cookie[1024]; char user_agent[1024]; char connection[1024]; char https[1024]; char version[1024]; char *contp; int use_cgi_folder; char *cgi_arg_list[1024]; char *cgi_env_list[1024]; int fds[2]; char *orig_req; char *orig_cur; struct http_req *next; } *


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

if ( !*a1 )
dequeue_request();
if ( a1[40] == 1 )
return (unsigned int)a1[36];
v1 = locate_file((__int64)a1);
if ( v1 == -1 )
{
push_error(a1, (__int64)&MSG404);
return (unsigned int)a1[36];
}
if ( v1 )
return (unsigned int)a1[36];
if ( (unsigned int)create_line_header((__int64)a1) == -1 )
return (unsigned int)a1[36];
if ( (unsigned int)create_res_body((__int64)a1) != -1 )
return (unsigned int)a1[36];
return (unsigned int)a1[36];
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
int v1; // eax

if ( !*a1 )
dequeue_request();
if ( a1[40] == 1 )
return (unsigned int)a1[36];
v1 = func0((__int64)a1);
if ( v1 == -1 )
{
func8(a1, (__int64)&MSG404);
return (unsigned int)a1[36];
}
if ( v1 )
return (unsigned int)a1[36];
if ( (unsigned int)func10((__int64)a1) == -1 )
return (unsigned int)a1[36];
if ( (unsigned int)func9((__int64)a1) != -1 )
return (unsigned int)a1[36];
return (unsigned int)a1[36];
}

original_code:
int create_response(struct buf *bufp) {
    int locate_ret;
    if (bufp->is_cgi_req == 0)
 dequeue_request(bufp);
    if (bufp->res_fully_created == 1)
 return bufp->buf_size;
    if ((locate_ret = locate_file(bufp)) == -1) {
 do{if(0) fprintf(stdout, "create_response: file not located, create msg404\n"); }while(0);
 push_error(bufp, MSG404);
    } else if (locate_ret == 0){
 do{if(0) fprintf(stdout, "create_response: static file located, path:%s\n", bufp->path); }while(0);
 if (create_line_header(bufp) == -1) return bufp->buf_size;
 if (create_res_body(bufp) == -1) return bufp->buf_size;
 do{if(0) fprintf(stdout, "create_response: bufp->size:%d\n", bufp->buf_size); }while(0);
    }
    return bufp->buf_size;
}


original_code:
int make_answer(char *dns, uint16_t RDLENGTH, uint32_t RDATA) {
  ((void) sizeof ((dns != ((void *)0)) ? 1 : 0), __extension__ ({ if (dns != ((void *)0)) ; else __assert_fail ("dns != NULL", "dns_lib.c", 53, __extension__ __PRETTY_FUNCTION__); }));
  int offset = 0;
  uint16_t NAME = htons(0xC00C);
  memcpy(dns + offset, &NAME, 2);
  offset += 2;
  uint16_t TYPE = htons(0x01);
  memcpy(dns + offset, &TYPE, 2);
  offset += 2;
  uint16_t CLASS = htons(0x01);
  memcpy(dns + offset, &CLASS, 2);
  offset += 2;
  uint32_t TTL = htonl(0x00);
  memcpy(dns + offset, &TTL, 4);
  offset += 4;
  uint16_t RDLENGTH_n = htons(RDLENGTH);
  memcpy(dns + offset, &RDLENGTH_n, 2);
  offset += 2;
  if (RDLENGTH != 0) {
    uint32_t RDATA_n = RDATA;
    memcpy(dns + offset, &RDATA_n, 4);
    offset += 4;
  }
  return offset;
}

canonical_original_code:
int make_answer(char *dns, unsigned short RDLENGTH, unsigned int RDATA) {
  ((void) sizeof ((dns != ((void *)0)) ? 1 : 0), __extension__ ({ if (dns != ((void *)0)) ; else __assert_fail ("dns != NULL", "dns_lib.c", 53, __extension__ __PRETTY_FUNCTION__); }));
  int offset = 0;
  unsigned short NAME = htons(0xC00C);
  memcpy(dns + offset, &NAME, 2);
  offset += 2;
  unsigned short TYPE = htons(0x01);
  memcpy(dns + offset, &TYPE, 2);
  offset += 2;
  unsigned short CLASS = htons(0x01);
  memcpy(dns + offset, &CLASS, 2);
  offset += 2;
  unsigned int TTL = htonl(0x00);
  memcpy(dns + offset, &TTL, 4);
  offset += 4;
  unsigned short RDLENGTH_n = htons(RDLENGTH);
  memcpy(dns + offset, &RDLENGTH_n, 2);
  offset += 2;
  if (RDLENGTH != 0) {
    unsigned int RDATA_n = RDATA;
    memcpy(dns + offset, &RDATA_n, 4);
    offset += 4;
  }
  return offset;
}

variable_types:
dns
char *

variable_types:
RDLENGTH
unsigned short

variable_types:
RDATA
unsigned int

variable_types: offset int

variable_types:
NAME
unsigned short

variable_types:
TYPE
unsigned short

variable_types:
CLASS
unsigned short

variable_types:
TTL
unsigned int


decompiled_code:
__int64 __fastcall make_question(__int64 a1, const char *a2)
{
const char *v3; // rbx
int v4; // ebp
char *v5; // rax
char *v6; // r8
unsigned __int8 v7; // di
unsigned __int8 *v8; // rcx
__int64 v9; // rax
unsigned __int8 v10; // al
unsigned __int8 v11; // si
unsigned __int8 *v12; // rcx
int v13; // ebp
int v14; // edi
__int64 v15; // rax
__int16 v16; // ax

if ( !a1 )
__assert_fail("dns != NULL", "dns_lib.c", 0x58u, "make_question");
v3 = a2;
if ( !a2 )
__assert_fail("node != NULL", "dns_lib.c", 0x59u, "make_question");
v4 = 0;
while ( 1 )
{
v5 = strchr(v3, 46);
v6 = v5;
if ( !v5 )
break;
v7 = (_BYTE)v5 - (_BYTE)v3;
if ( (unsigned __int8)((_BYTE)v5 - (_BYTE)v3) > 0x3Fu )
__assert_fail("len <= 0x3f", "dns_lib.c", 0x64u, "make_question");
v8 = (unsigned __int8 *)(a1 + v4);
*v8 = v7;
++v4;
if ( v7 )
{
v9 = 0LL;
do
{
v8[v9 + 1] = v3[v9];
++v9;
}
while ( v7 > (int)v9 );
v4 += v7;
}
v3 = v6 + 1;
}
v10 = strlen(v3);
v11 = v10;
if ( v10 > 0x3Fu )
__assert_fail("len <= 0x3f", "dns_lib.c", 0x79u, "make_question");
v12 = (unsigned __int8 *)(a1 + v4);
*v12 = v10;
v13 = v4 + 1;
v14 = v10;
if ( v10 )
{
v15 = 0LL;
do
{
v12[v15 + 1] = v3[v15];
++v15;
}
while ( v14 > (int)v15 );
v13 += v11;
}
*(_BYTE *)(a1 + v13) = 0;
v16 = _bswap_16(1);
*(_WORD *)(a1 + v13 + 1) = v16;
*(_WORD *)(a1 + v13 + 3) = v16;
return (unsigned int)(v13 + 5);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
const char *v3; // rbx
int v4; // ebp
char *v5; // rax
char *v6; // r8
unsigned __int8 v7; // di
unsigned __int8 *v8; // rcx
__int64 v9; // rax
unsigned __int8 v10; // al
unsigned __int8 v11; // si
unsigned __int8 *v12; // rcx
int v13; // ebp
int v14; // edi
__int64 v15; // rax
__int16 v16; // ax

if ( !a1 )
__assert_fail("dns != NULL", "dns_lib.c", 0x58u, "make_question");
v3 = a2;
if ( !a2 )
__assert_fail("node != NULL", "dns_lib.c", 0x59u, "make_question");
v4 = 0;
while ( 1 )
{
v5 = strchr(v3, 46);
v6 = v5;
if ( !v5 )
break;
v7 = (_BYTE)v5 - (_BYTE)v3;
if ( (unsigned __int8)((_BYTE)v5 - (_BYTE)v3) > 0x3Fu )
__assert_fail("len <= 0x3f", "dns_lib.c", 0x64u, "make_question");
v8 = (unsigned __int8 *)(a1 + v4);
*v8 = v7;
++v4;
if ( v7 )
{
v9 = 0LL;
do
{
v8[v9 + 1] = v3[v9];
++v9;
}
while ( v7 > (int)v9 );
v4 += v7;
}
v3 = v6 + 1;
}
v10 = strlen(v3);
v11 = v10;
if ( v10 > 0x3Fu )
__assert_fail("len <= 0x3f", "dns_lib.c", 0x79u, "make_question");
v12 = (unsigned __int8 *)(a1 + v4);
*v12 = v10;
v13 = v4 + 1;
v14 = v10;
if ( v10 )
{
v15 = 0LL;
do
{
v12[v15 + 1] = v3[v15];
++v15;
}
while ( v14 > (int)v15 );
v13 += v11;
}
*(_BYTE *)(a1 + v13) = 0;
v16 = func8(1);
*(_WORD *)(a1 + v13 + 1) = v16;
*(_WORD *)(a1 + v13 + 3) = v16;
return (unsigned int)(v13 + 5);
}

original_code:
int make_question(char *dns, const char *node) {
  ((void) sizeof ((dns != ((void *)0)) ? 1 : 0), __extension__ ({ if (dns != ((void *)0)) ; else __assert_fail ("dns != NULL", "dns_lib.c", 88, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "dns_lib.c", 89, __extension__ __PRETTY_FUNCTION__); }));
  const char *p1, *p2;
  uint8_t len;
  int i, offset;
  offset = 0;
  p1 = node;
  while ((p2 = strchr(p1, '.')) != ((void *)0)) {
    len = p2 - p1;
    ((void) sizeof ((len <= 0x3f) ? 1 : 0), __extension__ ({ if (len <= 0x3f) ; else __assert_fail ("len <= 0x3f", "dns_lib.c", 100, __extension__ __PRETTY_FUNCTION__); }));
    memcpy(dns + offset, &len, 1);
    ++offset;
    for (i = 0; i < len; i++) {
      memcpy(dns + offset, p1 + i, sizeof(char));
      ++offset;
    }
    p1 = p2 + 1;
  }
  len = strlen(p1);
  ((void) sizeof ((len <= 0x3f) ? 1 : 0), __extension__ ({ if (len <= 0x3f) ; else __assert_fail ("len <= 0x3f", "dns_lib.c", 121, __extension__ __PRETTY_FUNCTION__); }));
  memcpy(dns + offset, &len, 1);
  ++offset;
  for (i = 0; i < len; i++) {
    memcpy(dns + offset, p1 + i, sizeof(char));
    ++offset;
  }
  *(dns + offset) = 0x00;
  ++offset;
  uint16_t QTYPE = htons(0x01);
  uint16_t QCLASS = htons(0x01);
  memcpy(dns + offset, &QTYPE, 2);
  offset += 2;
  memcpy(dns + offset, &QCLASS, 2);
  offset += 2;
  return offset;
}

canonical_original_code:
int make_question(char *dns, char *node) {
  ((void) sizeof ((dns != ((void *)0)) ? 1 : 0), __extension__ ({ if (dns != ((void *)0)) ; else __assert_fail ("dns != NULL", "dns_lib.c", 88, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "dns_lib.c", 89, __extension__ __PRETTY_FUNCTION__); }));
  char *p1; char *p2;
  unsigned char len;
  int i; int offset;
  offset = 0;
  p1 = node;
  while ((p2 = strchr(p1, '.')) != ((void *)0)) {
    len = p2 - p1;
    ((void) sizeof ((len <= 0x3f) ? 1 : 0), __extension__ ({ if (len <= 0x3f) ; else __assert_fail ("len <= 0x3f", "dns_lib.c", 100, __extension__ __PRETTY_FUNCTION__); }));
    memcpy(dns + offset, &len, 1);
    ++offset;
    for (i = 0; i < len; i++) {
      memcpy(dns + offset, p1 + i, sizeof(char));
      ++offset;
    }
    p1 = p2 + 1;
  }
  len = strlen(p1);
  ((void) sizeof ((len <= 0x3f) ? 1 : 0), __extension__ ({ if (len <= 0x3f) ; else __assert_fail ("len <= 0x3f", "dns_lib.c", 121, __extension__ __PRETTY_FUNCTION__); }));
  memcpy(dns + offset, &len, 1);
  ++offset;
  for (i = 0; i < len; i++) {
    memcpy(dns + offset, p1 + i, sizeof(char));
    ++offset;
  }
  *(dns + offset) = 0x00;
  ++offset;
  unsigned short QTYPE = htons(0x01);
  unsigned short QCLASS = htons(0x01);
  memcpy(dns + offset, &QTYPE, 2);
  offset += 2;
  memcpy(dns + offset, &QCLASS, 2);
  offset += 2;
  return offset;
}

variable_types:
node
char *

variable_types:
len
unsigned char

variable_types: i int

variable_types:
QTYPE
unsigned short

variable_types:
QCLASS
unsigned short


original_code:
int make_head(char *dns, uint16_t msg_id, uint16_t flags, uint16_t QDCOUNT, uint16_t ANCOUNT, uint16_t NSCOUNT, uint16_t ARCOUNT) {
  ((void) sizeof ((dns != ((void *)0)) ? 1 : 0), __extension__ ({ if (dns != ((void *)0)) ; else __assert_fail ("dns != NULL", "dns_lib.c", 153, __extension__ __PRETTY_FUNCTION__); }));
  int size = 2;
  uint16_t msg_id_n = htons(msg_id);
  memcpy(dns, &msg_id_n, size);
  uint16_t flags_n = htons(flags);
  memcpy(dns + size, &flags_n, size);
  uint16_t QDCOUNT_n = htons(QDCOUNT);
  memcpy(dns + 2*size, &QDCOUNT_n, size);
  uint16_t ANCOUNT_n = htons(ANCOUNT);
  memcpy(dns + 3*size, &ANCOUNT_n, size);
  uint16_t NSCOUNT_n = htons(NSCOUNT);
  memcpy(dns + 4*size, &NSCOUNT_n, size);
  uint16_t ARCOUNT_n = htons(ARCOUNT);
  memcpy(dns + 5*size, &ARCOUNT_n, size);
  return size*6;
}

canonical_original_code:
int make_head(char *dns, unsigned short msg_id, unsigned short flags, unsigned short QDCOUNT, unsigned short ANCOUNT, unsigned short NSCOUNT, unsigned short ARCOUNT) {
  ((void) sizeof ((dns != ((void *)0)) ? 1 : 0), __extension__ ({ if (dns != ((void *)0)) ; else __assert_fail ("dns != NULL", "dns_lib.c", 153, __extension__ __PRETTY_FUNCTION__); }));
  int size = 2;
  unsigned short msg_id_n = htons(msg_id);
  memcpy(dns, &msg_id_n, size);
  unsigned short flags_n = htons(flags);
  memcpy(dns + size, &flags_n, size);
  unsigned short QDCOUNT_n = htons(QDCOUNT);
  memcpy(dns + 2*size, &QDCOUNT_n, size);
  unsigned short ANCOUNT_n = htons(ANCOUNT);
  memcpy(dns + 3*size, &ANCOUNT_n, size);
  unsigned short NSCOUNT_n = htons(NSCOUNT);
  memcpy(dns + 4*size, &NSCOUNT_n, size);
  unsigned short ARCOUNT_n = htons(ARCOUNT);
  memcpy(dns + 5*size, &ARCOUNT_n, size);
  return size*6;
}

variable_types:
flags
unsigned short

variable_types:
QDCOUNT
unsigned short

variable_types:
ANCOUNT
unsigned short

variable_types:
NSCOUNT
unsigned short

variable_types:
ARCOUNT
unsigned short

variable_types: size int


decompiled_code:
__int64 __fastcall get_qdcount(const char *a1)
{
int i; // ebx
char *v2; // rax

if ( !a1 )
__assert_fail("node != NULL", "dns_lib.c", 0xB3u, "get_qdcount");
for ( i = 0; ; ++i )
{
v2 = strchr(a1, 46);
if ( !v2 )
break;
a1 = v2 + 1;
}
return (unsigned int)(i + 1);
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
int i; // ebx
char *v2; // rax

if ( !a1 )
__assert_fail("node != NULL", "dns_lib.c", 0xB3u, "get_qdcount");
for ( i = 0; ; ++i )
{
v2 = strchr(a1, 46);
if ( !v2 )
break;
a1 = v2 + 1;
}
return (unsigned int)(i + 1);
}

original_code:
uint16_t get_qdcount(const char *node) {
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "dns_lib.c", 179, __extension__ __PRETTY_FUNCTION__); }));
  uint16_t count = 0;
  while ((node = strchr(node, '.')) != ((void *)0)) {
    ++count;
    node += 1;
  }
  count += 1;
  return count;
}

canonical_original_code:
unsigned short get_qdcount(char *node) {
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "dns_lib.c", 179, __extension__ __PRETTY_FUNCTION__); }));
  unsigned short count = 0;
  while ((node = strchr(node, '.')) != ((void *)0)) {
    ++count;
    node += 1;
  }
  count += 1;
  return count;
}

variable_types:
count
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall print_dns(const char **a1)
{
unsigned __int16 v1; // si

if ( !a1 )
__assert_fail("q != NULL", "dns_lib.c", 0x11Cu, "print_dns");
puts("print_query/reply:");
printf("header section: ");
printf("msg_id:%x, ", *(unsigned __int16 *)a1);
printf("QR:%d, ", *((unsigned __int16 *)a1 + 2));
printf("OPCODE:%x, ", *((unsigned __int16 *)a1 + 3));
printf("AA:%d, ", *((unsigned __int16 *)a1 + 4));
printf("RD:%d, ", *((unsigned __int16 *)a1 + 5));
printf("RA:%d, ", *((unsigned __int16 *)a1 + 6));
printf("RCODE:%x, ", *((unsigned __int16 *)a1 + 7));
printf("QDCOUNT:%d, ", *((unsigned __int16 *)a1 + 8));
printf("ANCOUNT:%d\n", *((unsigned __int16 *)a1 + 9));
printf("query section: ");
printf("QNAME:%s, ", a1[3]);
printf("QTYPE:%x, QCLASS:%x\n", *((unsigned __int16 *)a1 + 16), *((unsigned __int16 *)a1 + 17));
printf("answer section: ");
printf("NAME:%x, ", *((unsigned __int16 *)a1 + 18));
printf("TYPE:%x, ", *((unsigned __int16 *)a1 + 19));
printf("CLASS:%x, ", *((unsigned __int16 *)a1 + 20));
printf("TTL:%x, ", *((unsigned int *)a1 + 11));
v1 = *((_WORD *)a1 + 24);
if ( v1 )
{
printf("RDLENGTH:%x, ", v1);
printf("RDATA:%x\n", *((unsigned int *)a1 + 13));
}
else
{
printf("RDLENGTH:%x\n", 0LL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char **a1)
{
unsigned __int16 v1; // si

if ( !a1 )
__assert_fail("q != NULL", "dns_lib.c", 0x11Cu, "print_dns");
puts("print_query/reply:");
printf("header section: ");
printf("msg_id:%x, ", *(unsigned __int16 *)a1);
printf("QR:%d, ", *((unsigned __int16 *)a1 + 2));
printf("OPCODE:%x, ", *((unsigned __int16 *)a1 + 3));
printf("AA:%d, ", *((unsigned __int16 *)a1 + 4));
printf("RD:%d, ", *((unsigned __int16 *)a1 + 5));
printf("RA:%d, ", *((unsigned __int16 *)a1 + 6));
printf("RCODE:%x, ", *((unsigned __int16 *)a1 + 7));
printf("QDCOUNT:%d, ", *((unsigned __int16 *)a1 + 8));
printf("ANCOUNT:%d\n", *((unsigned __int16 *)a1 + 9));
printf("query section: ");
printf("QNAME:%s, ", a1[3]);
printf("QTYPE:%x, QCLASS:%x\n", *((unsigned __int16 *)a1 + 16), *((unsigned __int16 *)a1 + 17));
printf("answer section: ");
printf("NAME:%x, ", *((unsigned __int16 *)a1 + 18));
printf("TYPE:%x, ", *((unsigned __int16 *)a1 + 19));
printf("CLASS:%x, ", *((unsigned __int16 *)a1 + 20));
printf("TTL:%x, ", *((unsigned int *)a1 + 11));
v1 = *((_WORD *)a1 + 24);
if ( v1 )
{
printf("RDLENGTH:%x, ", v1);
printf("RDATA:%x\n", *((unsigned int *)a1 + 13));
}
else
{
printf("RDLENGTH:%x\n", 0LL);
}
return 0LL;
}

original_code:
int print_dns(struct dns_t *q) {
  ((void) sizeof ((q != ((void *)0)) ? 1 : 0), __extension__ ({ if (q != ((void *)0)) ; else __assert_fail ("q != NULL", "dns_lib.c", 284, __extension__ __PRETTY_FUNCTION__); }));
  printf("print_query/reply:\n");
  printf("header section: ");
  printf("msg_id:%x, ", q->msg_id);
  printf("QR:%d, ", q->QR);
  printf("OPCODE:%x, ", q->OPCODE);
  printf("AA:%d, ", q->AA);
  printf("RD:%d, ", q->RD);
  printf("RA:%d, ", q->RA);
  printf("RCODE:%x, ", q->RCODE);
  printf("QDCOUNT:%d, ", q->QDCOUNT);
  printf("ANCOUNT:%d\n", q->ANCOUNT);
  printf("query section: ");
  printf("QNAME:%s, ", q->QNAME);
  printf("QTYPE:%x, QCLASS:%x\n", q->QTYPE, q->QCLASS);
  printf("answer section: ");
  printf("NAME:%x, ", q->NAME);
  printf("TYPE:%x, ", q->TYPE);
  printf("CLASS:%x, ", q->CLASS);
  printf("TTL:%x, ", q->TTL);
  if (q->RDLENGTH != 0) {
    printf("RDLENGTH:%x, ", q->RDLENGTH);
    printf("RDATA:%x\n", q->RDATA);
  } else {
    printf("RDLENGTH:%x\n", q->RDLENGTH);
  }
  return 0;
}

variable_types: struct dns_t { unsigned short msg_id; unsigned short flags; unsigned short QR; unsigned short OPCODE; unsigned short AA; unsigned short RD; unsigned short RA; unsigned short RCODE; unsigned short QDCOUNT; unsigned short ANCOUNT; char *QNAME; unsigned short QTYPE; unsigned short QCLASS; unsigned short NAME; unsigned short TYPE; unsigned short CLASS; unsigned int TTL; unsigned short RDLENGTH; unsigned int RDATA; } *


original_code:
char *recover_node(char *QNAME) {
  int len;
  char *node = ((void *)0);
  char size_buf[1];
  int size, count;
  int n_offset, q_offset;
  len = strlen(QNAME);
  node = (char *)calloc(len+1, sizeof(char));
  n_offset = 0;
  q_offset = 0;
  size = 0;
  do {
    memset(size_buf, 0, sizeof(size_buf));
    memcpy(size_buf, QNAME + q_offset, 1);
    ++q_offset;
    size = (int)*size_buf;
    node[n_offset] = '.';
    ++n_offset;
    for (count = 0; count < size; count++) {
      node[n_offset] = QNAME[q_offset + count];
      ++n_offset;
    }
    q_offset += size;
  } while (n_offset < len-1);
  memmove(node, node+1, len-1);
  node[len-1] = '\0';
  return node;
}

canonical_original_code:
char *recover_node(char *QNAME) {
  int len;
  char *node = ((void *)0);
  char size_buf[1];
  int size; int count;
  int n_offset; int q_offset;
  len = strlen(QNAME);
  node = (char *)calloc(len+1, sizeof(char));
  n_offset = 0;
  q_offset = 0;
  size = 0;
  do {
    memset(size_buf, 0, sizeof(size_buf));
    memcpy(size_buf, QNAME + q_offset, 1);
    ++q_offset;
    size = (int)*size_buf;
    node[n_offset] = '.';
    ++n_offset;
    for (count = 0; count < size; count++) {
      node[n_offset] = QNAME[q_offset + count];
      ++n_offset;
    }
    q_offset += size;
  } while (n_offset < len-1);
  memmove(node, node+1, len-1);
  node[len-1] = '\0';
  return node;
}

variable_types:
QNAME
char *

variable_types: len int

variable_types: count int


decompiled_code:
__int64 __fastcall init_mydns(char *a1, int a2)
{
if ( !a1 )
_assert_fail("ip != NULL", "mydns.c", 0x11u, "init_mydns");
if ( !a2 )
_assert_fail("port > 0", "mydns.c", 0x12u, "init_mydns");
dns_ip = a1;
dns_port = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, int a2)
{
if ( !a1 )
_assert_fail("ip != NULL", "mydns.c", 0x11u, "init_mydns");
if ( !a2 )
_assert_fail("port > 0", "mydns.c", 0x12u, "init_mydns");
dns_ip = a1;
dns_port = a2;
return 0LL;
}

original_code:
int init_mydns(const char *ip, unsigned int port) {
  ((void) sizeof ((ip != ((void *)0)) ? 1 : 0), __extension__ ({ if (ip != ((void *)0)) ; else __assert_fail ("ip != NULL", "mydns.c", 17, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((port > 0) ? 1 : 0), __extension__ ({ if (port > 0) ; else __assert_fail ("port > 0", "mydns.c", 18, __extension__ __PRETTY_FUNCTION__); }));
  dns_ip = ip;
  dns_port = port;
  return 0;
}

canonical_original_code:
int init_mydns(char *ip, unsigned int port) {
  ((void) sizeof ((ip != ((void *)0)) ? 1 : 0), __extension__ ({ if (ip != ((void *)0)) ; else __assert_fail ("ip != NULL", "mydns.c", 17, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((port > 0) ? 1 : 0), __extension__ ({ if (port > 0) ; else __assert_fail ("port > 0", "mydns.c", 18, __extension__ __PRETTY_FUNCTION__); }));
  dns_ip = ip;
  dns_port = port;
  return 0;
}

variable_types:
ip
char *

variable_types:
port
unsigned int


resolve

decompiled_code:
__int64 __fastcall resolve(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const void *v5; // rbx
__int64 v6; // rax
int v7; // eax
int v8; // er12
ssize_t v9; // rax
void *v10; // rbx
int v11; // er12
_DWORD *v12; // r12
unsigned int v14; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr inp[2]; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("node != NULL", "mydns.c", 0x1Bu, "resolve");
if ( !a2 )
_assert_fail("service != NULL", "mydns.c", 0x1Cu, "resolve");
if ( !a4 )
_assert_fail("res != NULL", "mydns.c", 0x1Du, "resolve");
v5 = (const void *)make_dns_query(a1, &v14);
v6 = parse_dns(v5);
print_dns(v6);
printf("resolve: send query of %d bytes to dns_ip:%s, dns_port:%d\n", v14, dns_ip, (unsigned int)dns_port);
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
if ( !inet_aton(dns_ip, (struct in_addr *)&inp[0].sa_data[2]) )
{
perror("Error! main, inet_aton");
exit(-1);
}
*(_WORD *)inp[0].sa_data = _bswap_16(dns_port);
v7 = socket(2, 2, 0);
v8 = v7;
if ( v7 == -1 )
{
perror("Error! mydns, socket");
exit(-1);
}
v9 = sendto(v7, v5, (int)v14, 0, inp, 0x10u);
if ( v9 != v14 )
{
perror("Error! mydns, sendto, maybe use while");
exit(-1);
}
v10 = calloc(0x2000uLL, 1uLL);
v11 = recvfrom(v8, v10, 0x2000uLL, 0, 0LL, 0LL);
printf("resolve: recvd %s\n", (const char *)v10);
if ( v11 == -1 )
{
perror("Error! mydns, recvfrom");
exit(-1);
}
v12 = calloc(1uLL, 0x30uLL);
*(_QWORD *)a4 = v12;
v12[1] = 2;
*((_QWORD *)v12 + 3) = parse_dns_reply(v10);
*(_QWORD *)(*(_QWORD *)a4 + 40LL) = 0LL;
free(v10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const void *v5; // rbx
__int64 v6; // rax
int v7; // eax
int v8; // er12
ssize_t v9; // rax
void *v10; // rbx
int v11; // er12
_DWORD *v12; // r12
unsigned int v14; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr inp[2]; // [rsp+10h] [rbp-28h] BYREF

if ( !a1 )
_assert_fail("node != NULL", "mydns.c", 0x1Bu, "resolve");
if ( !a2 )
_assert_fail("service != NULL", "mydns.c", 0x1Cu, "resolve");
if ( !a4 )
_assert_fail("res != NULL", "mydns.c", 0x1Du, "resolve");
v5 = (const void *)make_dns_query(a1, &v14);
v6 = parse_dns(v5);
print_dns(v6);
printf("resolve: send query of %d bytes to dns_ip:%s, dns_port:%d\n", v14, dns_ip, (unsigned int)dns_port);
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
if ( !inet_aton(dns_ip, (struct in_addr *)&inp[0].sa_data[2]) )
{
perror("Error! main, inet_aton");
exit(-1);
}
*(_WORD *)inp[0].sa_data = func0(dns_port);
v7 = socket(2, 2, 0);
v8 = v7;
if ( v7 == -1 )
{
perror("Error! mydns, socket");
exit(-1);
}
v9 = sendto(v7, v5, (int)v14, 0, inp, 0x10u);
if ( v9 != v14 )
{
perror("Error! mydns, sendto, maybe use while");
exit(-1);
}
v10 = calloc(0x2000uLL, 1uLL);
v11 = recvfrom(v8, v10, 0x2000uLL, 0, 0LL, 0LL);
printf("resolve: recvd %s\n", (const char *)v10);
if ( v11 == -1 )
{
perror("Error! mydns, recvfrom");
exit(-1);
}
v12 = calloc(1uLL, 0x30uLL);
*(_QWORD *)a4 = v12;
v12[1] = 2;
*((_QWORD *)v12 + 3) = parse_dns_reply(v10);
*(_QWORD *)(*(_QWORD *)a4 + 40LL) = 0LL;
free(v10);
return 0LL;
}

original_code:
int resolve(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "mydns.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((service != ((void *)0)) ? 1 : 0), __extension__ ({ if (service != ((void *)0)) ; else __assert_fail ("service != NULL", "mydns.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((res != ((void *)0)) ? 1 : 0), __extension__ ({ if (res != ((void *)0)) ; else __assert_fail ("res != NULL", "mydns.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  struct sockaddr_in addr;
  char *dns_query = ((void *)0);
  char *dns_reply = ((void *)0);
  int sock;
  int ret;
  int query_len;
  dns_query = make_dns_query(node, &query_len);
  struct dns_t *tmp = parse_dns(dns_query);
  print_dns(tmp);
  printf("resolve: send query of %d bytes to dns_ip:%s, dns_port:%d\n", query_len, dns_ip, dns_port);
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  if (inet_aton(dns_ip, &addr.sin_addr) == 0) {
    perror("Error! main, inet_aton");
    exit(-1);
  }
  addr.sin_port = htons(dns_port);
  if ((sock = socket(2, SOCK_DGRAM, 0)) == -1) {
    perror("Error! mydns, socket");
    exit(-1);
  }
  if (sendto(sock, dns_query, query_len, 0, (struct sockaddr *)&addr, sizeof(addr)) != query_len) {
    perror("Error! mydns, sendto, maybe use while");
    exit(-1);
  }
  dns_reply = (char *)calloc(8192, sizeof(char));
  ret = recvfrom(sock, dns_reply, 8192, 0, ((void *)0), ((void *)0));
  printf("resolve: recvd %s\n", dns_reply);
  if (ret == -1) {
    perror("Error! mydns, recvfrom");
    exit(-1);
  }
  *res = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
  (*res)->ai_family = 2;
  (*res)->ai_addr = parse_dns_reply(dns_reply);
  (*res)->ai_next = ((void *)0);
  free(dns_reply);
  return 0;
}

canonical_original_code:
int resolve(char *node, char *service, struct addrinfo *hints, struct addrinfo **res) {
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "mydns.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((service != ((void *)0)) ? 1 : 0), __extension__ ({ if (service != ((void *)0)) ; else __assert_fail ("service != NULL", "mydns.c", 28, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((res != ((void *)0)) ? 1 : 0), __extension__ ({ if (res != ((void *)0)) ; else __assert_fail ("res != NULL", "mydns.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  struct sockaddr_in addr;
  char *dns_query = ((void *)0);
  char *dns_reply = ((void *)0);
  int sock;
  int ret;
  int query_len;
  dns_query = make_dns_query(node, &query_len);
  struct dns_t *tmp = parse_dns(dns_query);
  print_dns(tmp);
  printf("resolve: send query of %d bytes to dns_ip:%s, dns_port:%d\n", query_len, dns_ip, dns_port);
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = 2;
  if (inet_aton(dns_ip, &addr.sin_addr) == 0) {
    perror("Error! main, inet_aton");
    exit(-1);
  }
  addr.sin_port = htons(dns_port);
  if ((sock = socket(2, SOCK_DGRAM, 0)) == -1) {
    perror("Error! mydns, socket");
    exit(-1);
  }
  if (sendto(sock, dns_query, query_len, 0, (struct sockaddr *)&addr, sizeof(addr)) != query_len) {
    perror("Error! mydns, sendto, maybe use while");
    exit(-1);
  }
  dns_reply = (char *)calloc(8192, sizeof(char));
  ret = recvfrom(sock, dns_reply, 8192, 0, ((void *)0), ((void *)0));
  printf("resolve: recvd %s\n", dns_reply);
  if (ret == -1) {
    perror("Error! mydns, recvfrom");
    exit(-1);
  }
  *res = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
  (*res)->ai_family = 2;
  (*res)->ai_addr = parse_dns_reply(dns_reply);
  (*res)->ai_next = ((void *)0);
  free(dns_reply);
  return 0;
}

variable_types:
node
char *

variable_types:
service
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
res
struct addrinfo **

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

variable_types: sock int

variable_types: ret int

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

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct dns_t { unsigned short msg_id; unsigned short flags; unsigned short QR; unsigned short OPCODE; unsigned short AA; unsigned short RD; unsigned short RA; unsigned short RCODE; unsigned short QDCOUNT; unsigned short ANCOUNT; char *QNAME; unsigned short QTYPE; unsigned short QCLASS; unsigned short NAME; unsigned short TYPE; unsigned short CLASS; unsigned int TTL; unsigned short RDLENGTH; unsigned int RDATA; }


repo: ruivaz/graphs

decompiled_code:
__int64 __fastcall graph_get_vertex(__int64 *a1, char a2)
{
__int64 result; // rax

for ( result = *a1; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_BYTE *)result == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_BYTE *)result == a2 )
break;
}
return result;
}

original_code:
vertexT *graph_get_vertex(graphT *graph, char element) {
  vertexT *temp = graph->vertices;
  while(temp!=((void *)0)) {
    if(temp->element==element) {
      return temp;
    }
    temp=temp->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct vertexTag *graph_get_vertex(struct graphTag *graph, char element) {
  struct vertexTag *temp = graph->vertices;
  while(temp!=((void *)0)) {
    if(temp->element==element) {
      return temp;
    }
    temp=temp->next;
  }
  return ((void *)0);
}

variable_types: struct graphTag { struct vertexTag *vertices; } *

variable_types: element char

variable_types: struct vertexTag { char element; int visited; struct edgeTag { struct vertexTag *connectsTo; struct edgeTag *next; } *edges; struct vertexTag *next; } *

user_defined_types: struct vertexTag { char element; int visited; struct edgeTag *edges; struct vertexTag *next; }


printEdges

decompiled_code:
int __fastcall printEdges(__int64 *a1, char a2)
{
__int64 v2; // rax
char *i; // rbx

printf("Element %c\n", (unsigned int)a2);
v2 = graph_get_vertex(a1, a2);
if ( !v2 )
{
printf("There's no Vertex with %c Element\n", (unsigned int)a2);
exit(-1);
}
for ( i = *(char **)(v2 + 8); i; i = (char *)*((_QWORD *)i + 1) )
LODWORD(v2) = printf("Connected to %c \n", (unsigned int)**(char **)i);
return v2;
}

canonical_decompiled_code:
int __fastcall func1(__int64 *a1, char a2)
{
__int64 v2; // rax
char *i; // rbx

printf("Element %c\n", (unsigned int)a2);
v2 = func0(a1, a2);
if ( !v2 )
{
printf("There's no Vertex with %c Element\n", (unsigned int)a2);
exit(-1);
}
for ( i = *(char **)(v2 + 8); i; i = (char *)*((_QWORD *)i + 1) )
LODWORD(v2) = printf("Connected to %c \n", (unsigned int)**(char **)i);
return v2;
}

original_code:
void printEdges(graphT *graph, char element) {
  printf("Element %c\n", element);
  vertexT *temp = graph_get_vertex(graph, element);
  if(temp==((void *)0)){
    printf("There's no Vertex with %c Element\n", element);
    exit(-1);
  }
  edgeT *edge = temp->edges;
  while(edge!=((void *)0)){
    printf("Connected to %c \n", edge->connectsTo->element);
    edge=edge->next;
 }
}

canonical_original_code:
void printEdges(struct graphTag *graph, char element) {
  printf("Element %c\n", element);
  struct vertexTag *temp = graph_get_vertex(graph, element);
  if(temp==((void *)0)){
    printf("There's no Vertex with %c Element\n", element);
    exit(-1);
  }
  struct edgeTag *edge = temp->edges;
  while(edge!=((void *)0)){
    printf("Connected to %c \n", edge->connectsTo->element);
    edge=edge->next;
 }
}

variable_types: struct graphTag { struct vertexTag { char element; int visited; struct edgeTag { struct vertexTag *connectsTo; struct edgeTag *next; } *edges; struct vertexTag *next; } *vertices; } *

variable_types: struct edgeTag { struct vertexTag { char element; int visited; struct edgeTag *edges; struct vertexTag *next; } *connectsTo; struct edgeTag *next; } *

user_defined_types: struct graphTag { struct vertexTag *vertices; }


GraphIsReachableRecursive

decompiled_code:
__int64 __fastcall GraphIsReachableRecursive(__int64 a1, char a2)
{
__int64 result; // rax
_QWORD *i; // rbx

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 4) != 1 )
{
result = 1LL;
if ( *(_BYTE *)a1 != a2 )
{
*(_DWORD *)(a1 + 4) = 1;
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
{
result = GraphIsReachableRecursive(*i, (unsigned int)a2);
if ( (_DWORD)result == 1 )
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2)
{
__int64 result; // rax
_QWORD *i; // rbx

if ( !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 4) != 1 )
{
result = 1LL;
if ( *(_BYTE *)a1 != a2 )
{
*(_DWORD *)(a1 + 4) = 1;
for ( i = *(_QWORD **)(a1 + 8); i; i = (_QWORD *)i[1] )
{
result = func2(*i, (unsigned int)a2);
if ( (_DWORD)result == 1 )
break;
}
}
}
return result;
}

original_code:
int GraphIsReachableRecursive(vertexT *source, char destination){
  if(source==((void *)0) || source->visited==1)
    return 0;
  if(source->element == destination)
    return 1;
  source->visited=1;
  edgeT *edge = source->edges;
  while(edge!=((void *)0)){
    if(GraphIsReachableRecursive(edge->connectsTo, destination)==1)
      return 1;
    edge=edge->next;
  }
}

canonical_original_code:
int GraphIsReachableRecursive(struct vertexTag *source, char destination){
  if(source==((void *)0) || source->visited==1)
    return 0;
  if(source->element == destination)
    return 1;
  source->visited=1;
  struct edgeTag *edge = source->edges;
  while(edge!=((void *)0)){
    if(GraphIsReachableRecursive(edge->connectsTo, destination)==1)
      return 1;
    edge=edge->next;
  }
}

variable_types: destination char

user_defined_types: struct edgeTag { struct vertexTag *connectsTo; struct edgeTag *next; }


GraphIsReachable

decompiled_code:
__int64 __fastcall GraphIsReachable(__int64 *a1, char a2, char a3)
{
__int64 i; // rax
__int64 v5; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
*(_DWORD *)(i + 4) = 0;
v5 = graph_get_vertex(a1, a2);
return GraphIsReachableRecursive(v5, a3);
}

original_code:
int GraphIsReachable(graphT *graph, char source, char destination){
  vertexT *temp = graph->vertices;
  while(temp!=((void *)0)){
    temp->visited=0;
    temp=temp->next;
  }
  vertexT *temp1 = graph_get_vertex(graph, source);
  return GraphIsReachableRecursive(temp1, destination);
}

canonical_original_code:
int GraphIsReachable(struct graphTag *graph, char source, char destination){
  struct vertexTag *temp = graph->vertices;
  while(temp!=((void *)0)){
    temp->visited=0;
    temp=temp->next;
  }
  struct vertexTag *temp1 = graph_get_vertex(graph, source);
  return GraphIsReachableRecursive(temp1, destination);
}

variable_types: source char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = (__int64)malloc(8uLL);
graph_add_vertex(v4, 98LL);
graph_add_vertex(v4, 99LL);
graph_add_vertex(v4, 100LL);
graph_add_vertex(v4, 101LL);
graph_add_vertex(v4, 102LL);
graph_add_vertex(v4, 97LL);
graph_add_edge(v4[0], 98LL, 99LL);
graph_add_edge(v4[0], 100LL, 102LL);
graph_add_edge(v4[0], 102LL, 101LL);
graph_add_edge(v4[0], 101LL, 102LL);
graph_add_edge(v4[0], 100LL, 97LL);
printEdges(v4[0], 98LL);
printEdges(v4[0], 99LL);
printEdges(v4[0], 100LL);
printEdges(v4[0], 101LL);
printEdges(v4[0], 102LL);
printEdges(v4[0], 97LL);
if ( (unsigned int)GraphIsReachable(v4[0], 99LL, 100LL) )
_assert_fail("GraphIsReachable(graph1, 'c', 'd')==0", "main.c", 0x1Fu, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 100LL, 97LL) != 1 )
_assert_fail("GraphIsReachable(graph1, 'd', 'a')==1", "main.c", 0x20u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 100LL, 102LL) != 1 )
_assert_fail("GraphIsReachable(graph1, 'd', 'f')==1", "main.c", 0x21u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 100LL, 101LL) != 1 )
_assert_fail("GraphIsReachable(graph1, 'd', 'e')==1", "main.c", 0x22u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 98LL, 99LL) != 1 )
_assert_fail("GraphIsReachable(graph1, 'b', 'c')==1", "main.c", 0x23u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 98LL, 97LL) )
_assert_fail("GraphIsReachable(graph1, 'b', 'a')==0", "main.c", 0x24u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 97LL, 100LL) )
_assert_fail("GraphIsReachable(graph1, 'a', 'd')==0", "main.c", 0x25u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 102LL, 97LL) )
_assert_fail("GraphIsReachable(graph1, 'f', 'a')==0", "main.c", 0x26u, "main");
if ( (unsigned int)GraphIsReachable(v4[0], 97LL, 98LL) )
_assert_fail("GraphIsReachable(graph1, 'a', 'b')==0", "main.c", 0x27u, "main");
return 0;
}

original_code:
int main(){
  graphT * graph1 = malloc(sizeof(graphT));
  graph_add_vertex(&graph1, 'b');
  graph_add_vertex(&graph1, 'c');
  graph_add_vertex(&graph1, 'd');
  graph_add_vertex(&graph1, 'e');
  graph_add_vertex(&graph1, 'f');
  graph_add_vertex(&graph1, 'a');
  graph_add_edge(graph1, 'b','c');
  graph_add_edge(graph1, 'd', 'f');
  graph_add_edge(graph1, 'f', 'e');
  graph_add_edge(graph1, 'e', 'f');
  graph_add_edge(graph1, 'd', 'a');
  printEdges(graph1, 'b');
  printEdges(graph1, 'c');
  printEdges(graph1, 'd');
  printEdges(graph1, 'e');
  printEdges(graph1, 'f');
  printEdges(graph1, 'a');
  ((void) sizeof ((GraphIsReachable(graph1, 'c', 'd')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'c', 'd')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'c', 'd')==0", "main.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'd', 'a')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'd', 'a')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'd', 'a')==1", "main.c", 32, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'd', 'f')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'd', 'f')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'd', 'f')==1", "main.c", 33, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'd', 'e')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'd', 'e')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'd', 'e')==1", "main.c", 34, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'b', 'c')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'b', 'c')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'b', 'c')==1", "main.c", 35, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'b', 'a')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'b', 'a')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'b', 'a')==0", "main.c", 36, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'a', 'd')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'a', 'd')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'a', 'd')==0", "main.c", 37, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'f', 'a')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'f', 'a')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'f', 'a')==0", "main.c", 38, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'a', 'b')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'a', 'b')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'a', 'b')==0", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
}

canonical_original_code:
int main(){
  struct graphTag *graph1 = malloc(sizeof(graphT));
  graph_add_vertex(&graph1, 'b');
  graph_add_vertex(&graph1, 'c');
  graph_add_vertex(&graph1, 'd');
  graph_add_vertex(&graph1, 'e');
  graph_add_vertex(&graph1, 'f');
  graph_add_vertex(&graph1, 'a');
  graph_add_edge(graph1, 'b','c');
  graph_add_edge(graph1, 'd', 'f');
  graph_add_edge(graph1, 'f', 'e');
  graph_add_edge(graph1, 'e', 'f');
  graph_add_edge(graph1, 'd', 'a');
  printEdges(graph1, 'b');
  printEdges(graph1, 'c');
  printEdges(graph1, 'd');
  printEdges(graph1, 'e');
  printEdges(graph1, 'f');
  printEdges(graph1, 'a');
  ((void) sizeof ((GraphIsReachable(graph1, 'c', 'd')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'c', 'd')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'c', 'd')==0", "main.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'd', 'a')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'd', 'a')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'd', 'a')==1", "main.c", 32, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'd', 'f')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'd', 'f')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'd', 'f')==1", "main.c", 33, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'd', 'e')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'd', 'e')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'd', 'e')==1", "main.c", 34, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'b', 'c')==1) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'b', 'c')==1) ; else __assert_fail ("GraphIsReachable(graph1, 'b', 'c')==1", "main.c", 35, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'b', 'a')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'b', 'a')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'b', 'a')==0", "main.c", 36, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'a', 'd')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'a', 'd')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'a', 'd')==0", "main.c", 37, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'f', 'a')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'f', 'a')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'f', 'a')==0", "main.c", 38, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((GraphIsReachable(graph1, 'a', 'b')==0) ? 1 : 0), __extension__ ({ if (GraphIsReachable(graph1, 'a', 'b')==0) ; else __assert_fail ("GraphIsReachable(graph1, 'a', 'b')==0", "main.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  return 0;
}


criaGemeos

decompiled_code:
__int64 __fastcall criaGemeos(__pid_t *a1)
{
__pid_t v1; // eax
unsigned int v2; // edx
__pid_t v4; // eax

v1 = fork();
if ( v1 < 0 )
{
puts("ERRO");
exit(-1);
}
v2 = 97;
if ( v1 )
{
*a1 = v1;
v4 = fork();
if ( v4 < 0 )
{
puts("ERRO");
exit(-1);
}
v2 = 98;
if ( v4 )
{
a1[1] = v4;
v2 = 112;
}
}
return v2;
}

original_code:
char criaGemeos(pid_t lista[2]){
 pid_t pid, pid2;
 pid = fork();
 if(pid < 0){
  printf("ERRO\n");
  exit(-1);
 }
 if(pid == 0)
  return 'a';
 lista[0] = pid;
 pid2 = fork();
 if(pid2 < 0){
    printf("ERRO\n");
    exit(-1);
   }
 if ( pid2==0) return 'b';
 lista[1] = pid2;
 return 'p';
}

canonical_original_code:
char criaGemeos(int lista[2]){
 int pid; int pid2;
 pid = fork();
 if(pid < 0){
  printf("ERRO\n");
  exit(-1);
 }
 if(pid == 0)
  return 'a';
 lista[0] = pid;
 pid2 = fork();
 if(pid2 < 0){
    printf("ERRO\n");
    exit(-1);
   }
 if ( pid2==0) return 'b';
 lista[1] = pid2;
 return 'p';
}

variable_types:
lista
int [2]

variable_types: pid int

return_type: char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // bl
__pid_t v5[4]; // [rsp+8h] [rbp-10h] BYREF

v3 = criaGemeos(v5);
printf("CHAR RETORNO = %c\n", (unsigned int)v3);
if ( v3 == 112 )
{
printf("PID LISTA = %d\n", (unsigned int)v5[0]);
printf("PID LISTA = %d\n", (unsigned int)v5[1]);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // bl
__pid_t v5[4]; // [rsp+8h] [rbp-10h] BYREF

v3 = func7(v5);
printf("CHAR RETORNO = %c\n", (unsigned int)v3);
if ( v3 == 112 )
{
printf("PID LISTA = %d\n", (unsigned int)v5[0]);
printf("PID LISTA = %d\n", (unsigned int)v5[1]);
}
return 0;
}

original_code:
int main(){
 pid_t lista[2];
 char a = criaGemeos(lista);
 printf("CHAR RETORNO = %c\n", a);
 if(a == 'p') {
  int i;
  for(i=0; i<2; i++){
   printf("PID LISTA  = %d\n", lista[i]);
  }
 }
 return 0;
}

canonical_original_code:
int main(){
 int lista[2];
 char a = criaGemeos(lista);
 printf("CHAR RETORNO = %c\n", a);
 if(a == 'p') {
  int i;
  for(i=0; i<2; i++){
   printf("PID LISTA  = %d\n", lista[i]);
  }
 }
 return 0;
}

variable_types: a char

variable_types: i int


repo: rumca-js/disktype

decompiled_code:
_BOOL8 __fastcall read_block_cdimage(__int64 a1, unsigned __int64 a2, __int64 a3)
{
return (unsigned __int64)get_buffer_real(
*(_QWORD *)(a1 + 48),
*(_QWORD *)(a1 + 88) + 2352 * (a2 >> 11),
2048LL,
a3,
0LL) > 0x7FF;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, unsigned __int64 a2, __int64 a3)
{
return (unsigned __int64)get_buffer_real(
*(_QWORD *)(a1 + 48),
*(_QWORD *)(a1 + 88) + 2352 * (a2 >> 11),
2048LL,
a3,
0LL) > 0x7FF;
}

original_code:
static int read_block_cdimage(SOURCE *s, u8 pos, void *buf)
{
  SOURCE *fs = s->foundation;
  u8 filepos;
  filepos = (pos / 2048) * 2352 + ((CDIMAGE_SOURCE *)s)->off;
  if (get_buffer_real(fs, filepos, 2048, buf, ((void *)0)) < 2048)
    return 0;
  return 1;
}

canonical_original_code:
static int read_block_cdimage(struct source *s, unsigned long long pos, void *buf)
{
  struct source *fs = s->foundation;
  unsigned long long filepos;
  filepos = (pos / 2048) * 2352 + ((struct cdimage_source *)s)->off;
  if (get_buffer_real(fs, filepos, 2048, buf, ((void *)0)) < 2048)
    return 0;
  return 1;
}

variable_types: struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *

variable_types:
pos
unsigned long long

variable_types:
buf
void *

variable_types:
filepos
unsigned long long

user_defined_types: struct cdimage_source { struct source c; unsigned long long off; }