FifoAlg

decompiled_code:
__int64 __fastcall FifoAlg(__int64 a1, int a2, int a3)
{
void *v4; // rsp
__int64 v5; // r14
int v6; // er13
int v7; // ecx
int v8; // er10
__int64 result; // rax
void *src; // [rsp+0h] [rbp-50h] BYREF
size_t n; // [rsp+8h] [rbp-48h] BYREF
int v12; // [rsp+10h] [rbp-40h]
unsigned int v13; // [rsp+14h] [rbp-3Ch]
int v14; // [rsp+18h] [rbp-38h]
int v15; // [rsp+1Ch] [rbp-34h]

v15 = a2;
gettimeofday(&tpstart, 0LL);
v4 = alloca(4LL * (a3 + 1));
if ( a3 > 0 )
memset((char *)&src + 4, 0, 4LL * a3);
if ( v15 > 0 )
{
v13 = 0;
v5 = 1LL;
v6 = 0;
v14 = 1;
n = 4LL * (unsigned int)(a3 - 2) + 4;
src = &n;
while ( 1 )
{
if ( (unsigned int)Search(&src, (unsigned int)a3, *(unsigned int *)(a1 + 4 * v5)) )
goto LABEL_6;
v8 = *(_DWORD *)(a1 + 4 * v5);
if ( a3 > v6 )
{
++v6;
v7 = v14;
*((_DWORD *)&src + v14) = v8;
v14 = v7 + 1;
LABEL_6:
if ( v15 < (int)++v5 )
goto LABEL_12;
}
else
{
++v13;
if ( a3 > 1 )
{
v12 = v8;
memmove((char *)&src + 4, src, n);
v8 = v12;
}
++v5;
*((_DWORD *)&src + a3) = v8;
if ( v15 < (int)v5 )
goto LABEL_12;
}
}
}
v13 = 0;
LABEL_12:
gettimeofday(&tpend, 0LL);
result = v13;
*(float *)&timeuse = (float)(LODWORD(tpend.tv_usec)
+ 1000000 * (LODWORD(tpend.tv_sec) - LODWORD(tpstart.tv_sec))
- LODWORD(tpstart.tv_usec));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
void *v4; // rsp
__int64 v5; // r14
int v6; // er13
int v7; // ecx
int v8; // er10
__int64 result; // rax
void *src; // [rsp+0h] [rbp-50h] BYREF
size_t n; // [rsp+8h] [rbp-48h] BYREF
int v12; // [rsp+10h] [rbp-40h]
unsigned int v13; // [rsp+14h] [rbp-3Ch]
int v14; // [rsp+18h] [rbp-38h]
int v15; // [rsp+1Ch] [rbp-34h]

v15 = a2;
gettimeofday(&tpstart, 0LL);
v4 = alloca(4LL * (a3 + 1));
if ( a3 > 0 )
memset((char *)&src + 4, 0, 4LL * a3);
if ( v15 > 0 )
{
v13 = 0;
v5 = 1LL;
v6 = 0;
v14 = 1;
n = 4LL * (unsigned int)(a3 - 2) + 4;
src = &n;
while ( 1 )
{
if ( (unsigned int)Search(&src, (unsigned int)a3, *(unsigned int *)(a1 + 4 * v5)) )
goto LABEL_6;
v8 = *(_DWORD *)(a1 + 4 * v5);
if ( a3 > v6 )
{
++v6;
v7 = v14;
*((_DWORD *)&src + v14) = v8;
v14 = v7 + 1;
LABEL_6:
if ( v15 < (int)++v5 )
goto LABEL_12;
}
else
{
++v13;
if ( a3 > 1 )
{
v12 = v8;
memmove((char *)&src + 4, src, n);
v8 = v12;
}
++v5;
*((_DWORD *)&src + a3) = v8;
if ( v15 < (int)v5 )
goto LABEL_12;
}
}
}
v13 = 0;
LABEL_12:
gettimeofday(&tpend, 0LL);
result = v13;
*(float *)&timeuse = (float)(LODWORD(tpend.tv_usec)
+ 1000000 * (LODWORD(tpend.tv_sec) - LODWORD(tpstart.tv_sec))
- LODWORD(tpstart.tv_usec));
return result;
}

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: i int


LRUStackAlg

repo: ruijiege/System-Programming

decompiled_code:
__int64 __fastcall LRUStackAlg(__int64 a1, int a2, int a3)
{
signed __int64 v4; // rbx
void *v5; // rsp
__int64 v6; // rax
__int64 v7; // r15
size_t v8; // rsi
int v9; // ebx
int v10; // ecx
int v11; // er11
__int64 result; // rax
int v13; // eax
_BYTE v14[4]; // [rsp+0h] [rbp-60h] BYREF
int v15; // [rsp+4h] [rbp-5Ch] BYREF
void *src; // [rsp+8h] [rbp-58h]
void *dest; // [rsp+10h] [rbp-50h]
size_t n; // [rsp+18h] [rbp-48h]
int v19; // [rsp+20h] [rbp-40h]
unsigned int v20; // [rsp+24h] [rbp-3Ch]
int v21; // [rsp+28h] [rbp-38h]
int v22; // [rsp+2Ch] [rbp-34h]

v4 = 4LL * (a3 + 1);
v21 = a2;
gettimeofday(&tpstart, 0LL);
v5 = alloca(v4);
if ( a3 > 0 )
memset(&v15, 0, 4LL * a3);
if ( v21 > 0 )
{
v6 = (unsigned int)(a3 - 1);
v22 = a3;
v7 = 1LL;
v8 = 4 * v6 + 4;
v20 = 0;
v6 *= -4LL;
n = v8;
dest = &v14[v4 - 4 + v6];
v9 = 0;
src = &v14[4 * a3 - 4 + v6];
while ( !(unsigned int)Search(v14, (unsigned int)a3, *(unsigned int *)(a1 + 4 * v7)) )
{
v11 = *(_DWORD *)(a1 + 4 * v7);
if ( a3 > v9 )
{
++v9;
v10 = v22;
*(_DWORD *)&v14[4 * v22] = v11;
v22 = v10 - 1;
LABEL_6:
if ( v21 < (int)++v7 )
goto LABEL_12;
}
else
{
++v20;
if ( a3 > 0 )
{
v19 = v11;
memmove(dest, src, n);
v11 = v19;
}
v15 = v11;
if ( v21 < (int)++v7 )
goto LABEL_12;
}
}
v13 = Search(v14, (unsigned int)a3, *(unsigned int *)(a1 + 4 * v7));
if ( v13 > 0 )
memmove(&v14[4LL * v13 - 4LL * (v13 - 1)], &v14[4 * v13 + -4 * v13], 4LL * v13);
v15 = *(_DWORD *)(a1 + 4 * v7);
goto LABEL_6;
}
v20 = 0;
LABEL_12:
gettimeofday(&tpend, 0LL);
result = v20;
*(float *)&timeuse = (float)(LODWORD(tpend.tv_usec)
+ 1000000 * (LODWORD(tpend.tv_sec) - LODWORD(tpstart.tv_sec))
- LODWORD(tpstart.tv_usec));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
signed __int64 v4; // rbx
void *v5; // rsp
__int64 v6; // rax
__int64 v7; // r15
size_t v8; // rsi
int v9; // ebx
int v10; // ecx
int v11; // er11
__int64 result; // rax
int v13; // eax
_BYTE v14[4]; // [rsp+0h] [rbp-60h] BYREF
int v15; // [rsp+4h] [rbp-5Ch] BYREF
void *src; // [rsp+8h] [rbp-58h]
void *dest; // [rsp+10h] [rbp-50h]
size_t n; // [rsp+18h] [rbp-48h]
int v19; // [rsp+20h] [rbp-40h]
unsigned int v20; // [rsp+24h] [rbp-3Ch]
int v21; // [rsp+28h] [rbp-38h]
int v22; // [rsp+2Ch] [rbp-34h]

v4 = 4LL * (a3 + 1);
v21 = a2;
gettimeofday(&tpstart, 0LL);
v5 = alloca(v4);
if ( a3 > 0 )
memset(&v15, 0, 4LL * a3);
if ( v21 > 0 )
{
v6 = (unsigned int)(a3 - 1);
v22 = a3;
v7 = 1LL;
v8 = 4 * v6 + 4;
v20 = 0;
v6 *= -4LL;
n = v8;
dest = &v14[v4 - 4 + v6];
v9 = 0;
src = &v14[4 * a3 - 4 + v6];
while ( !(unsigned int)Search(v14, (unsigned int)a3, *(unsigned int *)(a1 + 4 * v7)) )
{
v11 = *(_DWORD *)(a1 + 4 * v7);
if ( a3 > v9 )
{
++v9;
v10 = v22;
*(_DWORD *)&v14[4 * v22] = v11;
v22 = v10 - 1;
LABEL_6:
if ( v21 < (int)++v7 )
goto LABEL_12;
}
else
{
++v20;
if ( a3 > 0 )
{
v19 = v11;
memmove(dest, src, n);
v11 = v19;
}
v15 = v11;
if ( v21 < (int)++v7 )
goto LABEL_12;
}
}
v13 = Search(v14, (unsigned int)a3, *(unsigned int *)(a1 + 4 * v7));
if ( v13 > 0 )
memmove(&v14[4LL * v13 - 4LL * (v13 - 1)], &v14[4 * v13 + -4 * v13], 4LL * v13);
v15 = *(_DWORD *)(a1 + 4 * v7);
goto LABEL_6;
}
v20 = 0;
LABEL_12:
gettimeofday(&tpend, 0LL);
result = v20;
*(float *)&timeuse = (float)(LODWORD(tpend.tv_usec)
+ 1000000 * (LODWORD(tpend.tv_sec) - LODWORD(tpstart.tv_sec))
- LODWORD(tpstart.tv_usec));
return result;
}

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: k int

variable_types: l int

variable_types: count int

variable_types: r int

variable_types: temp int

variable_types: add int

variable_types:
frames
int [-1]

return_type: int


main

canonical_name: main

repo: ruimiguelsantos/cstructspoc

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rbx
char v5; // [rsp+Bh] [rbp-44Dh]
unsigned int v6; // [rsp+Ch] [rbp-44Ch]
unsigned int s[15]; // [rsp+10h] [rbp-448h] BYREF
char v8; // [rsp+4Fh] [rbp-409h]
char v9; // [rsp+50h] [rbp-408h] BYREF
char v10; // [rsp+51h] [rbp-407h]
char v11; // [rsp+52h] [rbp-406h]

v3 = malloc(0x2004uLL);
init(v3, argv);
while ( 1 )
{
while ( 1 )
{
printStack(v3);
printf("\naction (he for help)$ ");
fgets(&v9, 1024, _bss_start);
*(&v8 + strlen(&v9)) = 0;
if ( v9 == 112 && v10 == 117 && !v11 )
{
printf("Number to push: ");
fgets((char *)s, 50, _bss_start);
if ( (unsigned int)__isoc99_sscanf() == 2 && v5 == 10 )
{
if ( (unsigned int)add(v3, v6) )
printf("Pushed %d to stack. ", v6);
else
printf("Stack is full. ");
}
else
{
printf("Not a number. ");
}
goto LABEL_7;
}
if ( v9 == 112 && v10 == 111 && !v11 )
{
if ( !(unsigned int)empty(v3) )
{
rem(v3, s);
printf("Popped %d. ", s[0]);
printf("<ENTER>");
goto LABEL_8;
}
goto LABEL_29;
}
if ( v9 != 116 || v10 != 111 || v11 )
break;
if ( (unsigned int)next(v3, s) )
{
printf("Stack top: %d <ENTER>", s[0]);
goto LABEL_8;
}
LABEL_29:
printf("Stack is empty. <ENTER>");
LABEL_8:
getchar();
}
if ( v9 == 101 && v10 == 109 && !v11 )
{
if ( (unsigned int)empty(v3) )
printf("Stack is empty. ");
else
printf("stack is not empty. ");
goto LABEL_7;
}
if ( v9 != 104 || v10 != 101 || v11 )
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 ( v9 != 101 || v10 != 120 || v11 )
{
printf("\nNot an action. Type he for available actions. ");
LABEL_7:
printf("<ENTER>");
goto LABEL_8;
}
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; // rbx
char v5; // [rsp+Bh] [rbp-44Dh]
unsigned int v6; // [rsp+Ch] [rbp-44Ch]
unsigned int s[15]; // [rsp+10h] [rbp-448h] BYREF
char v8; // [rsp+4Fh] [rbp-409h]
char v9; // [rsp+50h] [rbp-408h] BYREF
char v10; // [rsp+51h] [rbp-407h]
char v11; // [rsp+52h] [rbp-406h]

v3 = malloc(0x2004uLL);
func8(v3, argv);
while ( 1 )
{
while ( 1 )
{
func7(v3);
printf("\naction (he for help)$ ");
fgets(&v9, 1024, _bss_start);
*(&v8 + strlen(&v9)) = 0;
if ( v9 == 112 && v10 == 117 && !v11 )
{
printf("Number to push: ");
fgets((char *)s, 50, _bss_start);
if ( (unsigned int)__isoc99_sscanf() == 2 && v5 == 10 )
{
if ( (unsigned int)func10(v3, v6) )
printf("Pushed %d to stack. ", v6);
else
printf("Stack is full. ");
}
else
{
printf("Not a number. ");
}
goto LABEL_7;
}
if ( v9 == 112 && v10 == 111 && !v11 )
{
if ( !(unsigned int)func9(v3) )
{
func12(v3, s);
printf("Popped %d. ", s[0]);
printf("<ENTER>");
goto LABEL_8;
}
goto LABEL_29;
}
if ( v9 != 116 || v10 != 111 || v11 )
break;
if ( (unsigned int)func11(v3, s) )
{
printf("Stack top: %d <ENTER>", s[0]);
goto LABEL_8;
}
LABEL_29:
printf("Stack is empty. <ENTER>");
LABEL_8:
getchar();
}
if ( v9 == 101 && v10 == 109 && !v11 )
{
if ( (unsigned int)func9(v3) )
printf("Stack is empty. ");
else
printf("stack is not empty. ");
goto LABEL_7;
}
if ( v9 != 104 || v10 != 101 || v11 )
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 ( v9 != 101 || v10 != 120 || v11 )
{
printf("\nNot an action. Type he for available actions. ");
LABEL_7:
printf("<ENTER>");
goto LABEL_8;
}
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: struct buffer { int stack[2048]; int n; } *

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


printStack

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

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
{
v4 = *(unsigned int *)(a1 + 4 * v3--);
printf("|%d|\n", v4);
}
while ( (int)v3 >= 0 );
}
result = puts("--");
}
else
{
puts("EMPTY");
result = puts("--");
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
unsigned int v1; // ebx
int v2; // eax
__int64 v3; // rbx
__int64 v4; // rsi
int result; // eax

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
{
v4 = *(unsigned int *)(a1 + 4 * v3--);
printf("|%d|\n", v4);
}
while ( (int)v3 >= 0 );
}
result = puts("--");
}
else
{
puts("EMPTY");
result = puts("--");
}
return result;
}

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: i int

return_type: void

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
__int64 v4; // rdx

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

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

if ( !a1 )
_assert_fail("list != NULL", "nameserver.c", 0xCDu, "push_server");
if ( *(_DWORD *)a1 )
{
v3 = calloc(1uLL, 0x10uLL);
v4 = *(_QWORD *)(a1 + 8);
*(_DWORD *)v3 = a2;
v3[1] = v4;
*(_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)
{
__int64 v1; // rsi
unsigned int *v2; // rbx
__int64 result; // rax

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

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

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

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)
{
_QWORD *v2; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_QWORD *v2; // rcx

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

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:
ssize_t __fastcall send_response(int a1, __int64 a2)
{
ssize_t result; // rax
bool v3; // zf
unsigned int v4; // [rsp+0h] [rbp-Ch]

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

canonical_decompiled_code:
ssize_t __fastcall func1(int a1, __int64 a2)
{
ssize_t result; // rax
bool v3; // zf
unsigned int v4; // [rsp+0h] [rbp-Ch]

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

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; // r12
struct tm *v1; // rax
char *v2; // rbp
size_t v3; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

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

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

v0 = (char *)calloc(0x80uLL, 1uLL);
timer = time(0LL);
v1 = gmtime(&timer);
strcpy(v0, "Date: ");
v2 = asctime(v1);
v3 = strlen(v0);
*(stpcpy(&v0[v3], v2) - 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
__m128i v2; // xmm0

result = (char *)calloc(0x80uLL, 1uLL);
if ( !strcmp((const char *)(*(_QWORD *)(a1 + 32) + 11268LL), "keep-alive") )
{
v2 = _mm_load_si128((const __m128i *)&LC2);
strcpy(result + 16, "-alive\r\n");
}
else
{
v2 = _mm_load_si128((const __m128i *)&LC3);
strcpy(result + 16, "ed\r\n");
}
*(__m128i *)result = v2;
return result;
}

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

result = (char *)calloc(0x80uLL, 1uLL);
if ( !strcmp((const char *)(*(_QWORD *)(a1 + 32) + 11268LL), "keep-alive") )
{
v2 = _mm_load_si128((const __m128i *)&LC2);
strcpy(result + 16, "-alive\r\n");
}
else
{
v2 = _mm_load_si128((const __m128i *)&LC3);
strcpy(result + 16, "ed\r\n");
}
*(__m128i *)result = v2;
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; // rax
const char *v2; // rbp
char *v3; // r12
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax

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

canonical_decompiled_code:
char *__fastcall func4(__int64 a1)
{
char *v1; // rax
const char *v2; // rbp
char *v3; // r12
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax

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

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; // r12
struct tm *v2; // rax
char *v3; // rax
char *result; // rax
__m128i v5; // xmm0
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)calloc(0x80uLL, 1uLL);
if ( stat(*(const char **)(a1 + 184), &v6) == -1 )
{
perror("Error! last_modified_str, stat");
v5 = _mm_load_si128((const __m128i *)&LC14);
v1[16] = 0;
result = v1;
*(__m128i *)v1 = v5;
}
else
{
v2 = gmtime(&v6.st_mtim.tv_sec);
*(__m128i *)v1 = _mm_load_si128((const __m128i *)&LC15);
v3 = asctime(v2);
strcat(v1, v3);
result = v1;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1)
{
char *v1; // r12
struct tm *v2; // rax
char *v3; // rax
char *result; // rax
__m128i v5; // xmm0
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v1 = (char *)calloc(0x80uLL, 1uLL);
if ( stat(*(const char **)(a1 + 184), &v6) == -1 )
{
perror("Error! last_modified_str, stat");
v5 = _mm_load_si128((const __m128i *)&LC14);
v1[16] = 0;
result = v1;
*(__m128i *)v1 = v5;
}
else
{
v2 = gmtime(&v6.st_mtim.tv_sec);
*(__m128i *)v1 = _mm_load_si128((const __m128i *)&LC15);
v3 = asctime(v2);
strcat(v1, v3);
result = v1;
}
return result;
}

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; // r12
char *v2; // r12
_WORD *v3; // r12
char *v4; // r12
char *v5; // r12

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 func6(__int64 a1)
{
char *v1; // r12
char *v2; // r12
_WORD *v3; // r12
char *v4; // r12
char *v5; // r12

v1 = func2();
push_str(a1, v1);
free(v1);
v2 = func3(a1);
push_str(a1, v2);
free(v2);
push_str(a1, &server);
v3 = cont_len_str(a1);
push_str(a1, v3);
free(v3);
v4 = func4(a1);
push_str(a1, v4);
free(v4);
v5 = func5(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
__int64 v3; // rax
__int64 v5; // rcx
const char *v6; // rdi
const char *v7; // rsi
int v9; // eax

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

v1 = 0;
if ( *(_DWORD *)(a1 + 152) != 1 )
{
v2 = *(_QWORD *)(a1 + 112);
v1 = strcmp((const char *)(v2 + 13316), &VERSION);
if ( v1 )
{
v1 = -1;
push_error(a1, (__int64)&MSG505);
}
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
{
v1 = -1;
push_error(a1, (__int64)&MSG501);
}
}
}
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 )
{
if ( !v1 && (unsigned int)create_line_header((__int64)a1) != -1 )
{
create_res_body((__int64)a1);
return (unsigned int)a1[36];
}
return (unsigned int)a1[36];
}
push_error((__int64)a1, (__int64)&MSG404);
return (unsigned int)a1[36];
}

canonical_decompiled_code:
__int64 __fastcall func10(_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 )
{
if ( !v1 && (unsigned int)func9((__int64)a1) != -1 )
{
func8((__int64)a1);
return (unsigned int)a1[36];
}
return (unsigned int)a1[36];
}
func7((__int64)a1, (__int64)&MSG404);
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 *v2; // rbx
int v4; // er12
char *v5; // rax
char *v6; // rdi
unsigned __int8 v7; // al
__int64 v8; // rcx
int v9; // esi
unsigned __int8 *v10; // rcx
__int64 v11; // rax
unsigned __int8 v12; // al
__int64 v13; // rcx
int v14; // esi
int v15; // er12
unsigned __int8 *v16; // rcx
__int64 v17; // rax
__int16 v18; // ax
__int64 v19; // rdx

if ( !a1 )
_assert_fail("dns != NULL", "dns_lib.c", 0x58u, "make_question");
v2 = a2;
if ( !a2 )
_assert_fail("node != NULL", "dns_lib.c", 0x59u, "make_question");
v4 = 0;
while ( 1 )
{
v5 = strchr(v2, 46);
v6 = v5;
if ( !v5 )
break;
v7 = (_BYTE)v5 - (_BYTE)v2;
if ( (unsigned __int8)((_BYTE)v6 - (_BYTE)v2) > 0x3Fu )
_assert_fail("len <= 0x3f", "dns_lib.c", 0x64u, "make_question");
v8 = v4;
v9 = v7;
++v4;
v10 = (unsigned __int8 *)(a1 + v8);
*v10 = v7;
if ( v7 )
{
v11 = 0LL;
do
{
v10[v11 + 1] = v2[v11];
++v11;
}
while ( v9 > (int)v11 );
v4 += v9;
}
v2 = v6 + 1;
}
v12 = strlen(v2);
if ( v12 > 0x3Fu )
_assert_fail("len <= 0x3f", "dns_lib.c", 0x79u, "make_question");
v13 = v4;
v14 = v12;
v15 = v4 + 1;
v16 = (unsigned __int8 *)(a1 + v13);
*v16 = v12;
if ( v12 )
{
v17 = 0LL;
do
{
v16[v17 + 1] = v2[v17];
++v17;
}
while ( v14 > (int)v17 );
v15 += v14;
}
*(_BYTE *)(a1 + v15) = 0;
v18 = _bswap_16(1);
*(_WORD *)(a1 + v19) = v18;
*(_WORD *)(a1 + v15 + 3) = v18;
return (unsigned int)(v15 + 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)
{
unsigned int v1; // er12
char *v2; // rax

if ( !a1 )
_assert_fail("node != NULL", "dns_lib.c", 0xB3u, "get_qdcount");
v1 = 0;
while ( 1 )
{
++v1;
v2 = strchr(a1, 46);
if ( !v2 )
break;
a1 = v2 + 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
unsigned int v1; // er12
char *v2; // rax

if ( !a1 )
_assert_fail("node != NULL", "dns_lib.c", 0xB3u, "get_qdcount");
v1 = 0;
while ( 1 )
{
++v1;
v2 = strchr(a1, 46);
if ( !v2 )
break;
a1 = v2 + 1;
}
return v1;
}

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)
{
__int64 v1; // rsi

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 = *((unsigned __int16 *)a1 + 24);
if ( (_WORD)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 func7(const char **a1)
{
__int64 v1; // rsi

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 = *((unsigned __int16 *)a1 + 24);
if ( (_WORD)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)
{
__int64 result; // rax

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;
result = 0LL;
dns_port = a2;
return result;
}

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

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;
result = 0LL;
dns_port = a2;
return result;
}

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; // rbp
__int64 v6; // rax
int v7; // edx
int v8; // eax
int v9; // er12
ssize_t v10; // rax
void *v11; // rbp
int v12; // er12
_DWORD *v13; // rax
unsigned int v15; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [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, &v15);
v6 = parse_dns(v5);
print_dns(v6);
printf("resolve: send query of %d bytes to dns_ip:%s, dns_port:%d\n", v15, dns_ip, (unsigned int)dns_port);
addr = 0LL;
addr.sa_family = 2;
if ( !inet_aton(dns_ip, (struct in_addr *)&addr.sa_data[2]) )
{
perror("Error! main, inet_aton");
exit(-1);
}
*(_WORD *)addr.sa_data = _bswap_16(dns_port);
v8 = socket(2, 2, v7);
v9 = v8;
if ( v8 == -1 )
{
perror("Error! mydns, socket");
exit(-1);
}
v10 = sendto(v8, v5, (int)v15, 0, &addr, 0x10u);
if ( v10 != v15 )
{
perror("Error! mydns, sendto, maybe use while");
exit(-1);
}
v11 = calloc(0x2000uLL, 1uLL);
v12 = recvfrom(v9, v11, 0x2000uLL, 0, 0LL, 0LL);
printf("resolve: recvd %s\n", (const char *)v11);
if ( v12 == -1 )
{
perror("Error! mydns, recvfrom");
exit(-1);
}
v13 = calloc(1uLL, 0x30uLL);
*(_QWORD *)a4 = v13;
v13[1] = 2;
*((_QWORD *)v13 + 3) = parse_dns_reply(v11);
*(_QWORD *)(*(_QWORD *)a4 + 40LL) = 0LL;
free(v11);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const void *v5; // rbp
__int64 v6; // rax
int v7; // edx
int v8; // eax
int v9; // er12
ssize_t v10; // rax
void *v11; // rbp
int v12; // er12
_DWORD *v13; // rax
unsigned int v15; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [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, &v15);
v6 = parse_dns(v5);
print_dns(v6);
printf("resolve: send query of %d bytes to dns_ip:%s, dns_port:%d\n", v15, dns_ip, (unsigned int)dns_port);
addr = 0LL;
addr.sa_family = 2;
if ( !inet_aton(dns_ip, (struct in_addr *)&addr.sa_data[2]) )
{
perror("Error! main, inet_aton");
exit(-1);
}
*(_WORD *)addr.sa_data = func0(dns_port);
v8 = socket(2, 2, v7);
v9 = v8;
if ( v8 == -1 )
{
perror("Error! mydns, socket");
exit(-1);
}
v10 = sendto(v8, v5, (int)v15, 0, &addr, 0x10u);
if ( v10 != v15 )
{
perror("Error! mydns, sendto, maybe use while");
exit(-1);
}
v11 = calloc(0x2000uLL, 1uLL);
v12 = recvfrom(v9, v11, 0x2000uLL, 0, 0LL, 0LL);
printf("resolve: recvd %s\n", (const char *)v11);
if ( v12 == -1 )
{
perror("Error! mydns, recvfrom");
exit(-1);
}
v13 = calloc(1uLL, 0x30uLL);
*(_QWORD *)a4 = v13;
v13[1] = 2;
*((_QWORD *)v13 + 3) = parse_dns_reply(v11);
*(_QWORD *)(*(_QWORD *)a4 + 40LL) = 0LL;
free(v11);
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 *v3; // rbx

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

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

result = 0LL;
if ( a1 && *(_DWORD *)(a1 + 4) != 1 )
{
if ( *(_BYTE *)a1 == a2 )
{
result = 1LL;
}
else
{
v3 = *(_QWORD **)(a1 + 8);
*(_DWORD *)(a1 + 4) = 1;
if ( v3 )
{
while ( 1 )
{
result = func2(*v3, (unsigned int)a2);
if ( (_DWORD)result == 1 )
break;
v3 = (_QWORD *)v3[1];
if ( !v3 )
return result;
}
result = 1LL;
}
}
}
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)
{
__int64 i; // rax
__int64 v3; // rax
char v4; // dl

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

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; // er8
__pid_t v4; // eax

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

canonical_decompiled_code:
__int64 __fastcall func7(__pid_t *a1)
{
__pid_t v1; // eax
unsigned int v2; // er8
__pid_t v4; // eax

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

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)
{
__int64 v3; // rsi
int v5[4]; // [rsp+8h] [rbp-10h] BYREF

v3 = (unsigned int)(char)criaGemeos(v5, argv, envp);
printf("CHAR RETORNO = %c\n", v3);
if ( (_BYTE)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)
{
__int64 v3; // rsi
int v5[4]; // [rsp+8h] [rbp-10h] BYREF

v3 = (unsigned int)(char)func7(v5, argv, envp);
printf("CHAR RETORNO = %c\n", v3);
if ( (_BYTE)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; }


decompiled_code:
unsigned __int64 __fastcall detect_cdimage(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax
__int64 v4; // rsi
_QWORD *v5; // r12
unsigned __int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

result = get_buffer(a1, 0LL, 2352LL, v6);
if ( result > 0x92F )
{
result = v6[0];
if ( *(_QWORD *)v6[0] == syncbytes && *(_DWORD *)(v6[0] + 8) == dword_1A0 )
{
result = *(unsigned __int8 *)(v6[0] + 15);
if ( (_DWORD)result == 1 )
{
print_line(a2, "Raw CD image, Mode 1");
v4 = 16LL;
goto LABEL_8;
}
if ( (_DWORD)result == 2 )
{
print_line(a2, "Raw CD image, Mode 2, assuming Form 1");
v4 = 24LL;
LABEL_8:
v5 = init_cdimage_source(a1[3], *a1 + v4);
analyze_source(v5, a2);
close_source(v5);
return stop_detect();
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_QWORD *a1, unsigned int a2)
{
unsigned __int64 result; // rax
__int64 v4; // rsi
_QWORD *v5; // r12
unsigned __int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

result = get_buffer(a1, 0LL, 2352LL, v6);
if ( result > 0x92F )
{
result = v6[0];
if ( *(_QWORD *)v6[0] == syncbytes && *(_DWORD *)(v6[0] + 8) == dword_1A0 )
{
result = *(unsigned __int8 *)(v6[0] + 15);
if ( (_DWORD)result == 1 )
{
print_line(a2, "Raw CD image, Mode 1");
v4 = 16LL;
goto LABEL_8;
}
if ( (_DWORD)result == 2 )
{
print_line(a2, "Raw CD image, Mode 2, assuming Form 1");
v4 = 24LL;
LABEL_8:
v5 = init_cdimage_source(a1[3], *a1 + v4);
analyze_source(v5, a2);
close_source(v5);
return stop_detect();
}
}
}
return result;
}

original_code:
void detect_cdimage(SECTION *section, int level)
{
  int mode, off;
  unsigned char *buf;
  SOURCE *s;
  if (get_buffer(section, 0, 2352, (void **)&buf) < 2352)
    return;
  if (memcmp(buf, syncbytes, 12) != 0)
    return;
  mode = buf[15];
  if (mode == 1) {
    print_line(level, "Raw CD image, Mode 1");
    off = 16;
  } else if (mode == 2) {
    print_line(level, "Raw CD image, Mode 2, assuming Form 1");
    off = 24;
  } else
    return;
  s = init_cdimage_source(section->source, section->pos + off);
  analyze_source(s, level);
  close_source(s);
  stop_detect();
}

canonical_original_code:
void detect_cdimage(struct section *section, int level)
{
  int mode; int off;
  unsigned char *buf;
  struct source *s;
  if (get_buffer(section, 0, 2352, (void **)&buf) < 2352)
    return;
  if (memcmp(buf, syncbytes, 12) != 0)
    return;
  mode = buf[15];
  if (mode == 1) {
    print_line(level, "Raw CD image, Mode 1");
    off = 16;
  } else if (mode == 2) {
    print_line(level, "Raw CD image, Mode 2, assuming Form 1");
    off = 24;
  } else
    return;
  s = init_cdimage_source(section->source, section->pos + off);
  analyze_source(s, level);
  close_source(s);
  stop_detect();
}

variable_types: struct section { unsigned long long pos; int flags; 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); } *source; } *

variable_types: level int

variable_types: mode int

variable_types: off int

variable_types:
buf
unsigned char *

user_defined_types: struct section { unsigned long long pos; int flags; struct source *source; }


decompiled_code:
__int64 __fastcall print_kind(int a1, __int64 a2, int a3)
{
const char *v3; // r12
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

v3 = "Regular file";
if ( a1 )
{
v3 = "Block device";
if ( a1 != 1 )
v3 = "Character device";
}
if ( !a3 )
return print_line(0LL, "%s, unknown size", v3);
format_size_verbose(v5);
return print_line(0LL, "%s, size %s", v3, v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3)
{
const char *v3; // r12
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

v3 = "Regular file";
if ( a1 )
{
v3 = "Block device";
if ( a1 != 1 )
v3 = "Character device";
}
if ( !a3 )
return print_line(0LL, "%s, unknown size", v3);
format_size_verbose(v5);
return print_line(0LL, "%s, size %s", v3, v5);
}

original_code:
static void print_kind(int filekind, u8 size, int size_known)
{
  char buf[256], *kindname;
  if (filekind == 0)
    kindname = "Regular file";
  else if (filekind == 1)
    kindname = "Block device";
  else if (filekind == 2)
    kindname = "Character device";
  else
    kindname = "Unknown kind";
  if (size_known) {
    format_size_verbose(buf, size);
    print_line(0, "%s, size %s", kindname, buf);
  } else {
    print_line(0, "%s, unknown size", kindname);
  }
}

canonical_original_code:
static void print_kind(int filekind, unsigned long long size, int size_known)
{
  char buf[256]; char *kindname;
  if (filekind == 0)
    kindname = "Regular file";
  else if (filekind == 1)
    kindname = "Block device";
  else if (filekind == 2)
    kindname = "Character device";
  else
    kindname = "Unknown kind";
  if (size_known) {
    format_size_verbose(buf, size);
    print_line(0, "%s, size %s", kindname, buf);
  } else {
    print_line(0, "%s, unknown size", kindname);
  }
}

variable_types: filekind int

variable_types:
size
unsigned long long

variable_types:
buf
char [256]

variable_types:
kindname
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rbp
char *v5; // rdi
int result; // eax

if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s <device/file>...\n", "disktype");
result = 1;
}
else
{
v3 = (char **)(argv + 1);
print_line(0LL, (const char *)&unk_316, envp);
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
analyze_file(v5);
print_line(0LL, (const char *)&unk_316);
}
while ( v3 != (char **)v4 );
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rbp
char *v5; // rdi
int result; // eax

if ( argc <= 1 )
{
fprintf(stderr, "Usage: %s <device/file>...\n", "disktype");
result = 1;
}
else
{
v3 = (char **)(argv + 1);
print_line(0LL, (const char *)&unk_316, envp);
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
func1(v5);
print_line(0LL, (const char *)&unk_316);
}
while ( v3 != (char **)v4 );
result = 0;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
  int i;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <device/file>...\n", "disktype");
    return 1;
  }
  print_line(0, "");
  for (i = 1; i < argc; i++) {
    analyze_file(argv[i]);
    print_line(0, "");
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]