copy

decompiled_code:
__int64 __fastcall copy(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
int v5; // eax
_BYTE v7[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = open(a1, 0);
if ( v2 == -1 )
return 1LL;
v3 = v2;
v4 = open(a2, 2113);
if ( v4 == -1 )
return 1LL;
while ( 1 )
{
v5 = read(v3, v7, 0x200uLL);
if ( v5 <= 0 )
break;
write(v4, v7, v5);
}
close(v3);
close(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
int v5; // eax
_BYTE v7[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = open(a1, 0);
if ( v2 == -1 )
return 1LL;
v3 = v2;
v4 = open(a2, 2113);
if ( v4 == -1 )
return 1LL;
while ( 1 )
{
v5 = read(v3, v7, 0x200uLL);
if ( v5 <= 0 )
break;
write(v4, v7, v5);
}
close(v3);
close(v4);
return 0LL;
}

original_code:
int copy(char *src, char *dest) {
 int inF, ouF;
   char line[512];
   int bytes;
   if ( (inF = open(src, 00)) == -1 ) {
    return 1;
   }
   if ( (ouF = open(dest, 01 | 0100 | 04000)) == -1 ) {
      return 1;
   }
 while ( (bytes = read(inF, line, sizeof(line))) > 0 )
      write(ouF, line, bytes);
   close(inF);
   close(ouF);
   return 0;
}

canonical_original_code:
int copy(char *src, char *dest) {
 int inF; int ouF;
   char line[512];
   int bytes;
   if ( (inF = open(src, 00)) == -1 ) {
    return 1;
   }
   if ( (ouF = open(dest, 01 | 0100 | 04000)) == -1 ) {
      return 1;
   }
 while ( (bytes = read(inF, line, sizeof(line))) > 0 )
      write(ouF, line, bytes);
   close(inF);
   close(ouF);
   return 0;
}

variable_types:
src
char *

variable_types:
dest
char *

variable_types: inF int

variable_types: ouF int

variable_types:
line
char [512]

variable_types: bytes int


decompiled_code:
void __fastcall create_line(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
int create_line(line* line_obj)
{
 line_obj->ne=0;
 line_obj->alloted=0;
}

canonical_original_code:
int create_line(struct line_t *line_obj)
{
 line_obj->ne=0;
 line_obj->alloted=0;
}

variable_types: struct line_t { struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; } *coords_obj; int ne; int alloted; } *

return_type: int

user_defined_types: struct line_t { struct coords_t *coords_obj; int ne; int alloted; }


decompiled_code:
int __fastcall line_add_implemented(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
int v11; // edx
__int64 v12; // rax
unsigned int *v13; // rax
int result; // eax
void *v15; // rax

printf("ALLOTED %d\n", *(unsigned int *)(a1 + 12));
v11 = *(_DWORD *)(a1 + 12);
if ( !v11 )
{
v15 = malloc(0x60uLL);
*(_DWORD *)(a1 + 12) = 4;
*(_QWORD *)a1 = v15;
puts("Empty line");
v12 = *(int *)(a1 + 8);
if ( (_DWORD)v12 != *(_DWORD *)(a1 + 12) )
goto LABEL_3;
LABEL_5:
line_reallot(a1);
v12 = *(int *)(a1 + 8);
goto LABEL_3;
}
v12 = *(int *)(a1 + 8);
if ( (_DWORD)v12 == v11 )
goto LABEL_5;
LABEL_3:
v13 = (unsigned int *)(*(_QWORD *)a1 + 24 * v12);
*v13 = a2;
v13[1] = a3;
v13[2] = a4;
v13[3] = a5;
v13[4] = a6;
v13[5] = a7;
result = printf("%d%d%d%d\n", a2, a5, a3, a6);
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
int v11; // edx
__int64 v12; // rax
unsigned int *v13; // rax
int result; // eax
void *v15; // rax

printf("ALLOTED %d\n", *(unsigned int *)(a1 + 12));
v11 = *(_DWORD *)(a1 + 12);
if ( !v11 )
{
v15 = malloc(0x60uLL);
*(_DWORD *)(a1 + 12) = 4;
*(_QWORD *)a1 = v15;
puts("Empty line");
v12 = *(int *)(a1 + 8);
if ( (_DWORD)v12 != *(_DWORD *)(a1 + 12) )
goto LABEL_3;
LABEL_5:
func2(a1);
v12 = *(int *)(a1 + 8);
goto LABEL_3;
}
v12 = *(int *)(a1 + 8);
if ( (_DWORD)v12 == v11 )
goto LABEL_5;
LABEL_3:
v13 = (unsigned int *)(*(_QWORD *)a1 + 24 * v12);
*v13 = a2;
v13[1] = a3;
v13[2] = a4;
v13[3] = a5;
v13[4] = a6;
v13[5] = a7;
result = printf("%d%d%d%d\n", a2, a5, a3, a6);
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
int line_add_implemented(line* line_obj, int x1, int y1, int z1, int x2, int y2, int z2)
{
 printf("ALLOTED %d\n",line_obj->alloted);
 if ( line_obj->alloted == 0 )
 {
  line_obj->coords_obj=(coords*)malloc(sizeof(coords)*4);
  line_obj->alloted=4;
  printf("Empty line\n");
 }
 if ( line_obj->ne == line_obj->alloted )
  line_reallot(line_obj);
 line_obj->coords_obj[line_obj->ne].x1=x1;
 line_obj->coords_obj[line_obj->ne].y1=y1;
 line_obj->coords_obj[line_obj->ne].z1=z1;
 line_obj->coords_obj[line_obj->ne].x2=x2;
 line_obj->coords_obj[line_obj->ne].y2=y2;
 line_obj->coords_obj[line_obj->ne].z2=z2;
 printf("%d%d%d%d\n",x1,x2,y1,y2);
 line_obj->ne++;
}

canonical_original_code:
int line_add_implemented(struct line_t *line_obj, int x1, int y1, int z1, int x2, int y2, int z2)
{
 printf("ALLOTED %d\n",line_obj->alloted);
 if ( line_obj->alloted == 0 )
 {
  line_obj->coords_obj=(struct coords_t *)malloc(sizeof(coords)*4);
  line_obj->alloted=4;
  printf("Empty line\n");
 }
 if ( line_obj->ne == line_obj->alloted )
  line_reallot(line_obj);
 line_obj->coords_obj[line_obj->ne].x1=x1;
 line_obj->coords_obj[line_obj->ne].y1=y1;
 line_obj->coords_obj[line_obj->ne].z1=z1;
 line_obj->coords_obj[line_obj->ne].x2=x2;
 line_obj->coords_obj[line_obj->ne].y2=y2;
 line_obj->coords_obj[line_obj->ne].z2=z2;
 printf("%d%d%d%d\n",x1,x2,y1,y2);
 line_obj->ne++;
}

user_defined_types: struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; }


original_code:
int line_reallot(line* line_obj)
{
 int i;
 printf("New Reallot %d\n",line_obj->alloted*2);
 line line_tmp;
 line_tmp.ne=0;
 line_tmp.coords_obj=(coords*)malloc(sizeof(coords)*line_obj->alloted*2);
 line_tmp.alloted=line_obj->alloted*2;
 for(i=0; i < line_obj->ne; i++)
 {
  line_ops.line_add(&line_tmp, line_obj->coords_obj[i].x1, line_obj->coords_obj[i].y1, line_obj->coords_obj[i].z1, line_obj->coords_obj[i].x2, line_obj->coords_obj[i].y2, line_obj->coords_obj[i].z2);
 }
 free(line_obj->coords_obj);
 line_obj->coords_obj=line_tmp.coords_obj;
 line_obj->alloted*=2;
}

canonical_original_code:
int line_reallot(struct line_t *line_obj)
{
 int i;
 printf("New Reallot %d\n",line_obj->alloted*2);
 struct line_t line_tmp;
 line_tmp.ne=0;
 line_tmp.coords_obj=(struct coords_t *)malloc(sizeof(coords)*line_obj->alloted*2);
 line_tmp.alloted=line_obj->alloted*2;
 for(i=0; i < line_obj->ne; i++)
 {
  line_ops.line_add(&line_tmp, line_obj->coords_obj[i].x1, line_obj->coords_obj[i].y1, line_obj->coords_obj[i].z1, line_obj->coords_obj[i].x2, line_obj->coords_obj[i].y2, line_obj->coords_obj[i].z2);
 }
 free(line_obj->coords_obj);
 line_obj->coords_obj=line_tmp.coords_obj;
 line_obj->alloted*=2;
}

variable_types: i int

variable_types: struct line_t { struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; } *coords_obj; int ne; int alloted; }


decompiled_code:
int __fastcall line_display_implemented(__int64 a1)
{
int result; // eax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx

result = *(_DWORD *)(a1 + 8);
if ( result > 0 )
{
v2 = 0LL;
do
{
puts("COORDS");
v3 = 3 * v2++;
v4 = 8 * v3;
printf(
"\t%d %d %d\n",
*(unsigned int *)(8 * v3 + *(_QWORD *)a1),
*(unsigned int *)(8 * v3 + *(_QWORD *)a1 + 4),
*(unsigned int *)(8 * v3 + *(_QWORD *)a1 + 8));
result = printf(
"\t%d %d %d\n",
*(unsigned int *)(v4 + *(_QWORD *)a1 + 12),
*(unsigned int *)(v4 + *(_QWORD *)a1 + 16),
*(unsigned int *)(v4 + *(_QWORD *)a1 + 20));
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
int result; // eax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx

result = *(_DWORD *)(a1 + 8);
if ( result > 0 )
{
v2 = 0LL;
do
{
puts("COORDS");
v3 = 3 * v2++;
v4 = 8 * v3;
printf(
"\t%d %d %d\n",
*(unsigned int *)(8 * v3 + *(_QWORD *)a1),
*(unsigned int *)(8 * v3 + *(_QWORD *)a1 + 4),
*(unsigned int *)(8 * v3 + *(_QWORD *)a1 + 8));
result = printf(
"\t%d %d %d\n",
*(unsigned int *)(v4 + *(_QWORD *)a1 + 12),
*(unsigned int *)(v4 + *(_QWORD *)a1 + 16),
*(unsigned int *)(v4 + *(_QWORD *)a1 + 20));
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

original_code:
int line_display_implemented(line* line_obj)
{
 int i;
 for(i=0; i < line_obj->ne; i++)
 {
  printf("COORDS\n");
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x1,line_obj->coords_obj[i].y1,line_obj->coords_obj[i].z1);
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x2,line_obj->coords_obj[i].y2,line_obj->coords_obj[i].z2);
 }
}

canonical_original_code:
int line_display_implemented(struct line_t *line_obj)
{
 int i;
 for(i=0; i < line_obj->ne; i++)
 {
  printf("COORDS\n");
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x1,line_obj->coords_obj[i].y1,line_obj->coords_obj[i].z1);
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x2,line_obj->coords_obj[i].y2,line_obj->coords_obj[i].z2);
 }
}


original_code:
int hashlist_add_implemented2(hashlist2* list1,char* key_name,char* extra,int x,int y,int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (hash2*)malloc(sizeof(hash2) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        if ( alloted_percent >= 80 )
                hashlist_reallot2(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char*)malloc(sizeof(char)*strlen(key_name)+1);
        list1->Hash[hash_value].extra = (char*)malloc(sizeof(char)*strlen(extra)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        strcpy(list1->Hash[hash_value].extra,extra);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

canonical_original_code:
int hashlist_add_implemented2(struct hashlist_t2 *list1, char *key_name, char *extra, int x, int y, int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (struct hash_t2 *)malloc(sizeof(hash2) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        if ( alloted_percent >= 80 )
                hashlist_reallot2(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char *)malloc(sizeof(char)*strlen(key_name)+1);
        list1->Hash[hash_value].extra = (char *)malloc(sizeof(char)*strlen(extra)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        strcpy(list1->Hash[hash_value].extra,extra);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

variable_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; } *Hash; } *

variable_types:
extra
char *

variable_types: x int

variable_types: y int

variable_types: z int

user_defined_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 *Hash; }


original_code:
void hashlist_reallot2(hashlist2* list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        hashlist2 list2;
        list2.Hash=(hash2*)malloc(sizeof(hash2)*list1->size*2);
        list2.size=list1->size*2;
        for( i=0; i < list2.size-1; i++)
                list2.Hash[i].valid=0;
        list2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops2.hashlist_add2(&list2,list1->Hash[i].key_name,list1->Hash[i].extra,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        hash2* hash_tmp = list1->Hash;
        list1->Hash=list2.Hash;
        list1->size=list2.size;
        list1->alloted=list2.alloted;
        free(hash_tmp);
}

canonical_original_code:
void hashlist_reallot2(struct hashlist_t2 *list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        struct hashlist_t2 list2;
        list2.Hash=(struct hash_t2 *)malloc(sizeof(hash2)*list1->size*2);
        list2.size=list1->size*2;
        for( i=0; i < list2.size-1; i++)
                list2.Hash[i].valid=0;
        list2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops2.hashlist_add2(&list2,list1->Hash[i].key_name,list1->Hash[i].extra,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        struct hash_t2 *hash_tmp = list1->Hash;
        list1->Hash=list2.Hash;
        list1->size=list2.size;
        list1->alloted=list2.alloted;
        free(hash_tmp);
}

variable_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; } *Hash; }

return_type: void


decompiled_code:
int __fastcall hashlist_display_implemented2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // r12

LODWORD(v1) = puts("Displaying Hash list");
if ( *(_DWORD *)(a1 + 4) )
{
LODWORD(v1) = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = 32 * v2;
v1 = 32 * v2 + *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(v1 + 28) == 1 )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return v1;
}
++v2;
printf("\tName :- %s\t\tExtra\t:- %s\n ", *(const char **)v1, *(const char **)(v1 + 8));
LODWORD(v1) = printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 20),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 24));
}
while ( *(_DWORD *)a1 > (int)v2 );
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // r12

LODWORD(v1) = puts("Displaying Hash list");
if ( *(_DWORD *)(a1 + 4) )
{
LODWORD(v1) = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = 32 * v2;
v1 = 32 * v2 + *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(v1 + 28) == 1 )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return v1;
}
++v2;
printf("\tName :- %s\t\tExtra\t:- %s\n ", *(const char **)v1, *(const char **)(v1 + 8));
LODWORD(v1) = printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 20),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 24));
}
while ( *(_DWORD *)a1 > (int)v2 );
}
}
return v1;
}

original_code:
void hashlist_display_implemented2(hashlist2* list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\t\tExtra	:- %s\n ",list1->Hash[i].key_name, list1->Hash[i].extra);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

canonical_original_code:
void hashlist_display_implemented2(struct hashlist_t2 *list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\t\tExtra	:- %s\n ",list1->Hash[i].key_name, list1->Hash[i].extra);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

user_defined_types: struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; }


decompiled_code:
void __fastcall hashlist_initialize_implemented2(_QWORD *a1)
{
*a1 = 10LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
*a1 = 10LL;
a1[1] = 0LL;
}

original_code:
void hashlist_initialize_implemented2(hashlist2* list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}

canonical_original_code:
void hashlist_initialize_implemented2(struct hashlist_t2 *list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}


decompiled_code:
__int64 __fastcall hashlist_findhash_implemented2(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

if ( !*(_DWORD *)(a1 + 4) || *(int *)a1 <= 0 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v2 + 32LL * (unsigned int)(*(_DWORD *)a1 - 1) + 32;
while ( *(_DWORD *)(v2 + 28) != 1 || strcmp(*(const char **)v2, a2) )
{
v2 += 32LL;
if ( v2 == v3 )
return 0LL;
}
return v2;
}

original_code:
hash2* hashlist_findhash_implemented2(hashlist2* list1, char* key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

canonical_original_code:
struct hash_t2 *hashlist_findhash_implemented2(struct hashlist_t2 *list1, char *key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

variable_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 *Hash; } *

return_type: struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; } *


decompiled_code:
void __fastcall hashlist_destroy_implemented2(__int64 a1)
{
int v2; // eax
char *v3; // rdi
__int64 v4; // rbx
char *v5; // rax

if ( *(_DWORD *)(a1 + 4) )
{
v2 = *(_DWORD *)a1;
v3 = *(char **)(a1 + 8);
if ( v2 > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v5 = &v3[32 * v4];
if ( *((_DWORD *)v5 + 7) == 1 )
break;
if ( *(_DWORD *)a1 <= (int)++v4 )
goto LABEL_7;
}
++v4;
free(*(void **)v5);
v3 = *(char **)(a1 + 8);
}
while ( *(_DWORD *)a1 > (int)v4 );
}
LABEL_7:
free(v3);
}
}

original_code:
void hashlist_destroy_implemented2(hashlist2* list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}

canonical_original_code:
void hashlist_destroy_implemented2(struct hashlist_t2 *list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}


original_code:
int hashlist_add_implemented(hashlist* list1,char* key_name,int x,int y,int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (hash*)malloc(sizeof(hash) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        if ( alloted_percent >= 80 )
                hashlist_reallot(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char*)malloc(sizeof(char)*strlen(key_name)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

canonical_original_code:
int hashlist_add_implemented(struct hashlist_t *list1, char *key_name, int x, int y, int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (struct hash_t *)malloc(sizeof(hash) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        if ( alloted_percent >= 80 )
                hashlist_reallot(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char *)malloc(sizeof(char)*strlen(key_name)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

variable_types: struct hashlist_t { int size; int alloted; struct hash_t { char *key_name; int x; int y; int z; int valid; } *Hash; } *

user_defined_types: struct hashlist_t { int size; int alloted; struct hash_t *Hash; }


original_code:
void hashlist_reallot(hashlist* list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        hashlist hashlist2;
        hashlist2.Hash=(hash*)malloc(sizeof(hash)*list1->size*2);
        hashlist2.size=list1->size*2;
        for( i=0; i < hashlist2.size-1; i++)
                hashlist2.Hash[i].valid=0;
        hashlist2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops.hashlist_add(&hashlist2,list1->Hash[i].key_name,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        hash* hash_tmp = list1->Hash;
        list1->Hash=hashlist2.Hash;
        list1->size=hashlist2.size;
        list1->alloted=hashlist2.alloted;
        free(hash_tmp);
}

canonical_original_code:
void hashlist_reallot(struct hashlist_t *list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        struct hashlist_t hashlist2;
        hashlist2.Hash=(struct hash_t *)malloc(sizeof(hash)*list1->size*2);
        hashlist2.size=list1->size*2;
        for( i=0; i < hashlist2.size-1; i++)
                hashlist2.Hash[i].valid=0;
        hashlist2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops.hashlist_add(&hashlist2,list1->Hash[i].key_name,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        struct hash_t *hash_tmp = list1->Hash;
        list1->Hash=hashlist2.Hash;
        list1->size=hashlist2.size;
        list1->alloted=hashlist2.alloted;
        free(hash_tmp);
}

variable_types: struct hashlist_t { int size; int alloted; struct hash_t { char *key_name; int x; int y; int z; int valid; } *Hash; }


decompiled_code:
int __fastcall hashlist_display_implemented(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp

LODWORD(v1) = puts("Displaying Hash list");
if ( *(_DWORD *)(a1 + 4) )
{
LODWORD(v1) = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = 24 * v2;
v1 = 24 * v2 + *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(v1 + 20) == 1 )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return v1;
}
++v2;
printf("\tName :- %s\n", *(const char **)v1);
LODWORD(v1) = printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 12),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 16));
}
while ( *(_DWORD *)a1 > (int)v2 );
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp

LODWORD(v1) = puts("Displaying Hash list");
if ( *(_DWORD *)(a1 + 4) )
{
LODWORD(v1) = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = 24 * v2;
v1 = 24 * v2 + *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)(v1 + 20) == 1 )
break;
if ( *(_DWORD *)a1 <= (int)++v2 )
return v1;
}
++v2;
printf("\tName :- %s\n", *(const char **)v1);
LODWORD(v1) = printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 12),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + v3 + 16));
}
while ( *(_DWORD *)a1 > (int)v2 );
}
}
return v1;
}

original_code:
void hashlist_display_implemented(hashlist* list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\n",list1->Hash[i].key_name);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

canonical_original_code:
void hashlist_display_implemented(struct hashlist_t *list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\n",list1->Hash[i].key_name);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

user_defined_types: struct hash_t { char *key_name; int x; int y; int z; int valid; }


decompiled_code:
void __fastcall hashlist_initialize_implemented(_QWORD *a1)
{
*a1 = 10LL;
a1[1] = 0LL;
}

original_code:
void hashlist_initialize_implemented(hashlist* list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}

canonical_original_code:
void hashlist_initialize_implemented(struct hashlist_t *list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}


decompiled_code:
__int64 __fastcall hashlist_findhash_implemented(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // rbp

if ( !*(_DWORD *)(a1 + 4) || *(int *)a1 <= 0 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v2 + 24LL * (unsigned int)(*(_DWORD *)a1 - 1) + 24;
while ( *(_DWORD *)(v2 + 20) != 1 || strcmp(*(const char **)v2, a2) )
{
v2 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return v2;
}

original_code:
hash* hashlist_findhash_implemented(hashlist* list1, char* key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

canonical_original_code:
struct hash_t *hashlist_findhash_implemented(struct hashlist_t *list1, char *key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

variable_types: struct hashlist_t { int size; int alloted; struct hash_t *Hash; } *

return_type: struct hash_t { char *key_name; int x; int y; int z; int valid; } *


decompiled_code:
void __fastcall hashlist_destroy_implemented(__int64 a1)
{
int v2; // eax
char *v3; // rdi
__int64 v4; // rbx
char *v5; // rax

if ( *(_DWORD *)(a1 + 4) )
{
v2 = *(_DWORD *)a1;
v3 = *(char **)(a1 + 8);
if ( v2 > 0 )
{
v4 = 0LL;
do
{
while ( 1 )
{
v5 = &v3[24 * v4];
if ( *((_DWORD *)v5 + 5) == 1 )
break;
if ( *(_DWORD *)a1 <= (int)++v4 )
goto LABEL_7;
}
++v4;
free(*(void **)v5);
v3 = *(char **)(a1 + 8);
}
while ( *(_DWORD *)a1 > (int)v4 );
}
LABEL_7:
free(v3);
}
}

original_code:
void hashlist_destroy_implemented(hashlist* list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}

canonical_original_code:
void hashlist_destroy_implemented(struct hashlist_t *list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}


hashalgo

original_code:
int hashalgo(char* str,int M)
{
 int i,j,k,length;
 long mult,sum=0;
 length=strlen(str)/4;
 for(i=0;i<strlen(str);i++)
 {
  sum+=str[i]^(23+i%4);
 }
 sum=53*sum^3+3*sum^2-5*sum+8;
 if ( sum <0 )
   sum = -sum;
 return sum % M;
}

canonical_original_code:
int hashalgo(char *str, int M)
{
 int i; int j; int k; int length;
 long mult; long sum = 0;
 length=strlen(str)/4;
 for(i=0;i<strlen(str);i++)
 {
  sum+=str[i]^(23+i%4);
 }
 sum=53*sum^3+3*sum^2-5*sum+8;
 if ( sum <0 )
   sum = -sum;
 return sum % M;
}

variable_types:
str
char *

variable_types: M int

variable_types: j int

variable_types: k int

variable_types: length int

variable_types: mult long

variable_types: sum long


relpath

decompiled_code:
char *__fastcall relpath(void *src)
{
size_t v1; // rax
size_t v2; // r14
size_t v3; // rbp
int v4; // ebx
_BYTE *v5; // r13
int v6; // ebx
char *v7; // r12
char *v8; // rax
char *v9; // rbp
size_t v10; // rax
char delim[2]; // [rsp+Eh] [rbp-BAh] BYREF
struct stat v13; // [rsp+10h] [rbp-B8h] BYREF

v1 = strlen((const char *)src);
v2 = v1 + 1;
v3 = v1;
v4 = v1;
v5 = malloc(v1 + 1);
memcpy(v5, src, v2);
strcpy(delim, "/");
v6 = v4 - (*v5 == 47);
v7 = (char *)malloc(v3 + 2);
v8 = strtok(v5, delim);
strcpy(v7, v8);
while ( 1 )
{
if ( stat(v7, &v13) || (v13.st_mode & 0xF000) != 0x4000 )
{
if ( v6 == strlen(v7) )
return v7;
mkdir(v7, 0x1FFu);
}
v9 = strtok(0LL, delim);
if ( !v9 )
break;
v10 = strlen(v7);
v7[v10] = 47;
strcpy(&v7[v10 + 1], v9);
}
free(v7);
return v7;
}

canonical_decompiled_code:
char *__fastcall func0(void *src)
{
size_t v1; // rax
size_t v2; // r14
size_t v3; // rbp
int v4; // ebx
_BYTE *v5; // r13
int v6; // ebx
char *v7; // r12
char *v8; // rax
char *v9; // rbp
size_t v10; // rax
char delim[2]; // [rsp+Eh] [rbp-BAh] BYREF
struct stat v13; // [rsp+10h] [rbp-B8h] BYREF

v1 = strlen((const char *)src);
v2 = v1 + 1;
v3 = v1;
v4 = v1;
v5 = malloc(v1 + 1);
memcpy(v5, src, v2);
strcpy(delim, "/");
v6 = v4 - (*v5 == 47);
v7 = (char *)malloc(v3 + 2);
v8 = strtok(v5, delim);
strcpy(v7, v8);
while ( 1 )
{
if ( stat(v7, &v13) || (v13.st_mode & 0xF000) != 0x4000 )
{
if ( v6 == strlen(v7) )
return v7;
mkdir(v7, 0x1FFu);
}
v9 = strtok(0LL, delim);
if ( !v9 )
break;
v10 = strlen(v7);
v7[v10] = 47;
strcpy(&v7[v10 + 1], v9);
}
free(v7);
return v7;
}

original_code:
char* relpath(char* name)
{
    struct stat sb;
    char* name_tmp=malloc(strlen(name)*sizeof(char)+1);
    strcpy(name_tmp,name);
    int len = strlen(name_tmp);
    char delims[] = "/";
    if (name_tmp[0]=='/')
        len--;
    char *result = ((void *)0);
    char* prev=malloc(strlen(name)+sizeof(char)+1);
    result = strtok(name_tmp,delims);
    strcpy(prev,result);
    while( result != ((void *)0) )
    {
        if (!(stat(prev, &sb) == 0 && ((((sb.st_mode)) & 0170000) == (0040000))))
        {
            if ( len == strlen(prev))
            {
  return prev;
            }
            else
                mkdir(prev,0777);
        }
        result = strtok( ((void *)0), delims );
        if (result!=((void *)0))
        {
            strcat(prev,"/");
            strcat(prev,result);
        }
    }
    free(prev);
}

canonical_original_code:
char *relpath(char *name)
{
    struct stat sb;
    char *name_tmp = malloc(strlen(name)*sizeof(char)+1);
    strcpy(name_tmp,name);
    int len = strlen(name_tmp);
    char delims[] = "/";
    if (name_tmp[0]=='/')
        len--;
    char *result = ((void *)0);
    char *prev = malloc(strlen(name)+sizeof(char)+1);
    result = strtok(name_tmp,delims);
    strcpy(prev,result);
    while( result != ((void *)0) )
    {
        if (!(stat(prev, &sb) == 0 && ((((sb.st_mode)) & 0170000) == (0040000))))
        {
            if ( len == strlen(prev))
            {
  return prev;
            }
            else
                mkdir(prev,0777);
        }
        result = strtok( ((void *)0), delims );
        if (result!=((void *)0))
        {
            strcat(prev,"/");
            strcat(prev,result);
        }
    }
    free(prev);
}

variable_types:
name
char *

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]; }

variable_types: len int

variable_types:
delims
char []

variable_types:
result
char *

variable_types:
prev
char *

return_type: char *

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]; }


decompiled_code:
__int64 __fastcall set_area(_DWORD *a1, int a2, int a3, int a4, int a5, int a6)
{
__int64 result; // rax

*a1 = a2;
result = 1LL;
a1[1] = a3;
a1[2] = a4;
a1[3] = a5;
a1[4] = a6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int a2, int a3, int a4, int a5, int a6)
{
__int64 result; // rax

*a1 = a2;
result = 1LL;
a1[1] = a3;
a1[2] = a4;
a1[3] = a5;
a1[4] = a6;
return result;
}

original_code:
int set_area(area* a1,int no,int x1,int x2, int y1, int y2)
{
    a1->no=no;
    a1->x1=x1;
    a1->x2=x2;
    a1->y1=y1;
    a1->y2=y2;
    return 1;
}

canonical_original_code:
int set_area(struct area_t *a1, int no, int x1, int x2, int y1, int y2)
{
    a1->no=no;
    a1->x1=x1;
    a1->x2=x2;
    a1->y1=y1;
    a1->y2=y2;
    return 1;
}

variable_types: struct area_t { int no; int x1; int x2; int y1; int y2; } *

variable_types: no int


canonical_original_code:
int calculate_area(struct area_t *a1, struct area_t *a2, int weight, int alloted_weight)
{
    if (a1->x2 - a1->x1 >= a1->y2 - a1->y1)
    {
 a2->y1=a1->y1;
 a2->y2=a1->y2;
 a2->x1=a1->x1+((float)a1->x2/100)*alloted_weight;
 a2->x2=a2->x1+((float)a1->x2/100)*weight;
    }
    else
    {
 a2->x1=a1->x1;
 a2->x2=a1->x2;
 a2->y1=a1->y1+((float)a1->y2/100)*alloted_weight;
 a2->y2=a2->y1+((float)a1->y2/100)*weight;
    }
    return 1;
}

variable_types: weight int

user_defined_types: struct area_t { int no; int x1; int x2; int y1; int y2; }


decompiled_code:
__int64 __fastcall random_range(int a1, int a2)
{
return (unsigned int)(int)(float)((int)(float)((float)(a2 - a1 + 1) * (float)((float)rand() * 4.6566129e-10)) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
return (unsigned int)(int)(float)((int)(float)((float)(a2 - a1 + 1) * (float)((float)rand() * 4.6566129e-10)) + a1);
}

original_code:
int random_range(int a1, int a2)
{
    int num;
    float unit;
    num=rand();
    unit=num/(float) 2147483647;
    unit=a1 + (int)(unit * ((a2 - a1) + 1));
    return (int)unit;
}

variable_types: num int

variable_types: unit float


decompiled_code:
void *gnu_getcwd()
{
size_t v0; // r12
int v1; // ebx
void *i; // rbp

v0 = 100LL;
v1 = 100;
for ( i = malloc(0x64uLL); !getcwd((char *)i, v0); i = malloc(v1) )
{
v1 *= 2;
free(i);
v0 = v1;
}
return i;
}

canonical_decompiled_code:
void *func0()
{
size_t v0; // r12
int v1; // ebx
void *i; // rbp

v0 = 100LL;
v1 = 100;
for ( i = malloc(0x64uLL); !getcwd((char *)i, v0); i = malloc(v1) )
{
v1 *= 2;
free(i);
v0 = v1;
}
return i;
}

original_code:
char* gnu_getcwd ()
{
  int size = 100;
  char *buffer = (char*)malloc(sizeof(char)*size);
  while (1)
    {
      char *value = getcwd (buffer, size);
      if (value != 0)
        return buffer;
      size *= 2;
      free (buffer);
      buffer = malloc(sizeof(char)*size);
    }
}

canonical_original_code:
char *gnu_getcwd()
{
  int size = 100;
  char *buffer = (char*)malloc(sizeof(char)*size);
  while (1)
    {
      char *value = getcwd (buffer, size);
      if (value != 0)
        return buffer;
      size *= 2;
      free (buffer);
      buffer = malloc(sizeof(char)*size);
    }
}

variable_types: size int

variable_types:
buffer
char *

variable_types:
value
char *


setdata

decompiled_code:
__int64 __fastcall setdata(__int64 *a1, __int64 a2, __int64 a3)
{
const char *v4; // rbp
_QWORD *v5; // rbx
_QWORD *v6; // rbx
const char *v7; // rsi
__int64 v8; // rdi
_QWORD *v9; // rdi
__int64 v10; // rdx
__int64 v11; // r14
__int64 v12; // rbx
__int64 v13; // rbp
__int64 v14; // rax
__int64 v15; // r15
__int64 v19; // [rsp+18h] [rbp-40h]

system("rm tmp/* -rf");
v4 = (const char *)gnu_getcwd();
*(_WORD *)&v4[strlen(v4)] = 47;
v5 = malloc(0x10uLL);
puts("ADDING FILES to WRAPPER");
listfiles(v5, v4);
puts("FILES ADDED TO WRAPPER");
create_pool(a1);
v6 = (_QWORD *)*v5;
puts("$$$$$$$$$ Traversing Wrapper object starts\n");
while ( v6 )
{
while ( 1 )
{
v7 = (const char *)v6[1];
if ( !*v7 )
break;
printf("------------%s-----------\n", v7);
create_node_implemented(a1, v6[1]);
v8 = get_node_implemented(a1, v6[1]);
if ( v8 )
regexfile(v8, v6[1]);
v6 = (_QWORD *)*v6;
if ( !v6 )
goto LABEL_7;
}
}
LABEL_7:
puts("$$$$$$$$$ Traversing Wrapper object Ends\n");
display_node_implemented(a1);
if ( *((int *)a1 + 2) > 0 )
{
do
{
printf("NODE NO:- %d\n", (unsigned int)v6);
v9 = v6;
v6 = (_QWORD *)((char *)v6 + 1);
display_element_node(*a1 + 32LL * (_QWORD)v9);
}
while ( *((_DWORD *)a1 + 2) > (int)v6 );
}
hashlist_initialize_implemented(a2);
find_community(a1, a2);
hashlist_display_implemented(a2);
create_line(a3);
if ( *((int *)a1 + 2) > 0 )
{
v19 = 0LL;
v10 = *a1;
do
{
v11 = 32 * v19;
printf("NODE NAME :- %s\n", *(const char **)(v10 + 32 * v19));
v12 = hashlist_findhash_implemented(a2, *(_QWORD *)(*a1 + 32 * v19));
if ( !v12 )
{
puts("Hash1 not added properly");
exit(1);
}
v10 = *a1;
v13 = 0LL;
v14 = *a1 + v11;
if ( *(int *)(v14 + 12) > 0 )
{
do
{
printf("Name to find %s\n", *(const char **)(*(_QWORD *)(v14 + 24) + 16 * v13));
v15 = hashlist_findhash_implemented(a2, *(_QWORD *)(*(_QWORD *)(*a1 + v11 + 24) + 16 * v13));
if ( v15 )
{
puts("Not NULL");
printf("\tName :- %s\n", *(const char **)v12);
printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(v12 + 8),
*(unsigned int *)(v12 + 12),
*(unsigned int *)(v12 + 16));
printf("\tName :- %s\n", *(const char **)v15);
printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(v15 + 8),
*(unsigned int *)(v15 + 12),
*(unsigned int *)(v15 + 16));
printf("\tElement Name :- %s\n", *(const char **)(*(_QWORD *)(*a1 + v11 + 24) + 16 * v13));
line_add_implemented(
a3,
*(unsigned int *)(v12 + 8),
*(unsigned int *)(v12 + 12),
*(unsigned int *)(v12 + 16),
*(unsigned int *)(v15 + 8),
*(unsigned int *)(v15 + 12),
*(unsigned int *)(v15 + 16));
}
else
{
puts("Hash2 not added properly");
}
v10 = *a1;
++v13;
v14 = *a1 + v11;
}
while ( *(_DWORD *)(v14 + 12) > (int)v13 );
}
++v19;
}
while ( *((_DWORD *)a1 + 2) > (int)v19 );
}
return line_display_implemented(a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2, __int64 a3)
{
const char *v4; // rbp
_QWORD *v5; // rbx
_QWORD *v6; // rbx
const char *v7; // rsi
__int64 v8; // rdi
_QWORD *v9; // rdi
__int64 v10; // rdx
__int64 v11; // r14
__int64 v12; // rbx
__int64 v13; // rbp
__int64 v14; // rax
__int64 v15; // r15
__int64 v19; // [rsp+18h] [rbp-40h]

system("rm tmp/* -rf");
v4 = (const char *)gnu_getcwd();
*(_WORD *)&v4[strlen(v4)] = 47;
v5 = malloc(0x10uLL);
puts("ADDING FILES to WRAPPER");
listfiles(v5, v4);
puts("FILES ADDED TO WRAPPER");
create_pool(a1);
v6 = (_QWORD *)*v5;
puts("$$$$$$$$$ Traversing Wrapper object starts\n");
while ( v6 )
{
while ( 1 )
{
v7 = (const char *)v6[1];
if ( !*v7 )
break;
printf("------------%s-----------\n", v7);
create_node_implemented(a1, v6[1]);
v8 = get_node_implemented(a1, v6[1]);
if ( v8 )
regexfile(v8, v6[1]);
v6 = (_QWORD *)*v6;
if ( !v6 )
goto LABEL_7;
}
}
LABEL_7:
puts("$$$$$$$$$ Traversing Wrapper object Ends\n");
display_node_implemented(a1);
if ( *((int *)a1 + 2) > 0 )
{
do
{
printf("NODE NO:- %d\n", (unsigned int)v6);
v9 = v6;
v6 = (_QWORD *)((char *)v6 + 1);
display_element_node(*a1 + 32LL * (_QWORD)v9);
}
while ( *((_DWORD *)a1 + 2) > (int)v6 );
}
hashlist_initialize_implemented(a2);
find_community(a1, a2);
hashlist_display_implemented(a2);
create_line(a3);
if ( *((int *)a1 + 2) > 0 )
{
v19 = 0LL;
v10 = *a1;
do
{
v11 = 32 * v19;
printf("NODE NAME :- %s\n", *(const char **)(v10 + 32 * v19));
v12 = hashlist_findhash_implemented(a2, *(_QWORD *)(*a1 + 32 * v19));
if ( !v12 )
{
puts("Hash1 not added properly");
exit(1);
}
v10 = *a1;
v13 = 0LL;
v14 = *a1 + v11;
if ( *(int *)(v14 + 12) > 0 )
{
do
{
printf("Name to find %s\n", *(const char **)(*(_QWORD *)(v14 + 24) + 16 * v13));
v15 = hashlist_findhash_implemented(a2, *(_QWORD *)(*(_QWORD *)(*a1 + v11 + 24) + 16 * v13));
if ( v15 )
{
puts("Not NULL");
printf("\tName :- %s\n", *(const char **)v12);
printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(v12 + 8),
*(unsigned int *)(v12 + 12),
*(unsigned int *)(v12 + 16));
printf("\tName :- %s\n", *(const char **)v15);
printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(v15 + 8),
*(unsigned int *)(v15 + 12),
*(unsigned int *)(v15 + 16));
printf("\tElement Name :- %s\n", *(const char **)(*(_QWORD *)(*a1 + v11 + 24) + 16 * v13));
line_add_implemented(
a3,
*(unsigned int *)(v12 + 8),
*(unsigned int *)(v12 + 12),
*(unsigned int *)(v12 + 16),
*(unsigned int *)(v15 + 8),
*(unsigned int *)(v15 + 12),
*(unsigned int *)(v15 + 16));
}
else
{
puts("Hash2 not added properly");
}
v10 = *a1;
++v13;
v14 = *a1 + v11;
}
while ( *(_DWORD *)(v14 + 12) > (int)v13 );
}
++v19;
}
while ( *((_DWORD *)a1 + 2) > (int)v19 );
}
return line_display_implemented(a3);
}

original_code:
void setdata(pool* pool1,hashlist* hashlist1,line* line_obj)
{
     system("rm tmp/* -rf");
 int i,j;
 char* cwd=gnu_getcwd();
 strcat(cwd,"/");
 Wrapper* wrapper1=(Wrapper*)malloc(sizeof(Wrapper));
 printf("ADDING FILES to WRAPPER\n");
 listfiles(wrapper1,cwd);
 printf("FILES ADDED TO WRAPPER\n");
 create_pool(pool1);
 Filelist* list1=wrapper1->filelist1;
 node* node1;
 printf("$$$$$$$$$ Traversing Wrapper object starts\n\n");
 while(list1 != ((void *)0))
 {
  if (!strlen(list1->path)) continue;
  printf("------------%s-----------\n",list1->path);
  pool_ops.create_node(pool1,list1->path);
  node1=pool_ops.get_node(pool1,list1->path);
  if (node1!=((void *)0))
   regexfile(node1,list1->path);
  list1=list1->next;
 }
 printf("$$$$$$$$$ Traversing Wrapper object Ends\n\n");
 pool_ops.display_nodes(pool1);
 for(i=0; i< pool1->ne_pool; i++)
 {
  printf("NODE NO:- %d\n",i);
  node_ops.display_element(&pool1->node_obj[i]);
 }
 hashlist_ops.hashlist_initialize(hashlist1);
 find_community(pool1,hashlist1);
 hashlist_ops.hashlist_display(hashlist1);
 hash* hash_get1;
 hash* hash_get2;
 create_line(line_obj);
 for(i=0; i < pool1->ne_pool; i++)
 {
  printf("NODE NAME :- %s\n",pool1->node_obj[i].name);
  hash_get1=hashlist_ops.hashlist_findhash(hashlist1,pool1->node_obj[i].name);
  if (hash_get1 == ((void *)0))
  {
   printf("Hash1 not added properly\n");
   exit(1);
  }
  for(j=0; j < pool1->node_obj[i].ne_node; j++)
  {
   printf("Name to find %s\n",pool1->node_obj[i].element_obj[j].name);
   hash_get2=hashlist_ops.hashlist_findhash(hashlist1,pool1->node_obj[i].element_obj[j].name);
   if (hash_get2 == ((void *)0))
   {
    printf("Hash2 not added properly\n");
    continue;
   }
         printf("Not NULL\n");
          printf("\tName   :- %s\n",hash_get1->key_name);
      printf("\tCoords :- %d %d %d\n",hash_get1->x,hash_get1->y,hash_get1->z);
          printf("\tName   :- %s\n",hash_get2->key_name);
      printf("\tCoords :- %d %d %d\n",hash_get2->x,hash_get2->y,hash_get2->z);
   printf("\tElement Name :- %s\n",pool1->node_obj[i].element_obj[j].name);
   line_ops.line_add(line_obj,hash_get1->x,hash_get1->y,hash_get1->z,hash_get2->x,hash_get2->y,hash_get2->z);
  }
 }
 line_ops.line_display(line_obj);
}

canonical_original_code:
void setdata(struct pool_t *pool1, struct hashlist_t *hashlist1, struct line_t *line_obj)
{
     system("rm tmp/* -rf");
 int i; int j;
 char *cwd = gnu_getcwd();
 strcat(cwd,"/");
 struct Wrapper *wrapper1 = (Wrapper*)malloc(sizeof(Wrapper));
 printf("ADDING FILES to WRAPPER\n");
 listfiles(wrapper1,cwd);
 printf("FILES ADDED TO WRAPPER\n");
 create_pool(pool1);
 struct Filelist *list1 = wrapper1->filelist1;
 struct node *node1;
 printf("$$$$$$$$$ Traversing Wrapper object starts\n\n");
 while(list1 != ((void *)0))
 {
  if (!strlen(list1->path)) continue;
  printf("------------%s-----------\n",list1->path);
  pool_ops.create_node(pool1,list1->path);
  node1=pool_ops.get_node(pool1,list1->path);
  if (node1!=((void *)0))
   regexfile(node1,list1->path);
  list1=list1->next;
 }
 printf("$$$$$$$$$ Traversing Wrapper object Ends\n\n");
 pool_ops.display_nodes(pool1);
 for(i=0; i< pool1->ne_pool; i++)
 {
  printf("NODE NO:- %d\n",i);
  node_ops.display_element(&pool1->node_obj[i]);
 }
 hashlist_ops.hashlist_initialize(hashlist1);
 find_community(pool1,hashlist1);
 hashlist_ops.hashlist_display(hashlist1);
 struct hash_t *hash_get1;
 struct hash_t *hash_get2;
 create_line(line_obj);
 for(i=0; i < pool1->ne_pool; i++)
 {
  printf("NODE NAME :- %s\n",pool1->node_obj[i].name);
  hash_get1=hashlist_ops.hashlist_findhash(hashlist1,pool1->node_obj[i].name);
  if (hash_get1 == ((void *)0))
  {
   printf("Hash1 not added properly\n");
   exit(1);
  }
  for(j=0; j < pool1->node_obj[i].ne_node; j++)
  {
   printf("Name to find %s\n",pool1->node_obj[i].element_obj[j].name);
   hash_get2=hashlist_ops.hashlist_findhash(hashlist1,pool1->node_obj[i].element_obj[j].name);
   if (hash_get2 == ((void *)0))
   {
    printf("Hash2 not added properly\n");
    continue;
   }
         printf("Not NULL\n");
          printf("\tName   :- %s\n",hash_get1->key_name);
      printf("\tCoords :- %d %d %d\n",hash_get1->x,hash_get1->y,hash_get1->z);
          printf("\tName   :- %s\n",hash_get2->key_name);
      printf("\tCoords :- %d %d %d\n",hash_get2->x,hash_get2->y,hash_get2->z);
   printf("\tElement Name :- %s\n",pool1->node_obj[i].element_obj[j].name);
   line_ops.line_add(line_obj,hash_get1->x,hash_get1->y,hash_get1->z,hash_get2->x,hash_get2->y,hash_get2->z);
  }
 }
 line_ops.line_display(line_obj);
}

variable_types: struct pool_t { struct node { char *name; int sno_node; int ne_node; int alloted; struct element_t { char *name; int extra; int sno_elem; } *element_obj; } *node_obj; int ne_pool; int alloted; } *

variable_types: struct hashlist_t { int size; int alloted; struct hash_t { char *key_name; int x; int y; int z; int valid; } *Hash; } *

variable_types: struct line_t { struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; } *coords_obj; int ne; int alloted; } *

variable_types: i int

variable_types: j int

variable_types:
cwd
char *

variable_types: struct Wrapper { struct Filelist { struct Filelist *next; char *path; } *filelist1; int initialized; } *

user_defined_types: struct pool_t { struct node *node_obj; int ne_pool; int alloted; }

user_defined_types: struct Wrapper { struct Filelist *filelist1; int initialized; }

user_defined_types: struct node { char *name; int sno_node; int ne_node; int alloted; struct element_t *element_obj; }


main

canonical_name: main

repo: panticz/lyc

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

result = 1;
if ( argc != 1 )
{
fd = open_port(argc, argv, envp);
if ( fd == -1 )
{
puts("Error opening serial port");
result = 0;
}
else if ( (unsigned int)init_port() == -1 )
{
sleep(0);
puts("Error initializing serial port");
close(fd);
result = 0;
}
else
{
sleep(0);
init_cmd();
sleep(0);
if ( (unsigned int)run_cmd((char *)argv[1], (void *)argv[2]) == 1 )
puts("Command not found");
sleep(0);
close(fd);
result = 0;
}
}
return result;
}

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

result = 1;
if ( argc != 1 )
{
fd = func10(argc, argv, envp);
if ( fd == -1 )
{
puts("Error opening serial port");
result = 0;
}
else if ( (unsigned int)func7() == -1 )
{
sleep(0);
puts("Error initializing serial port");
close(fd);
result = 0;
}
else
{
sleep(0);
func9();
sleep(0);
if ( (unsigned int)func11((char *)argv[1], (void *)argv[2]) == 1 )
puts("Command not found");
sleep(0);
close(fd);
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char **argv) {
    if(argc == 1) {
        return 1;
    }
    fd = open_port();
    if(fd == -1) {
        printf("Error opening serial port\n");
    } else {
        if(init_port() == -1) {
            sleep(.5);
            printf("Error initializing serial port\n");
            close(fd);
            return 0;
        }
        sleep(.5);
        init_cmd();
        sleep(.5);
        if(run_cmd(argv[1], argv[2]) == 1) {
            printf("Command not found\n");
        }
        sleep(.5);
        close(fd);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 init_port()
{
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

tcgetattr(fd, &termios_p);
cfsetispeed(&termios_p, 0xDu);
cfsetospeed(&termios_p, 0xDu);
termios_p.c_iflag &= 0xFFFFE3FF;
termios_p.c_cflag = termios_p.c_cflag & 0x7FFFFE8F | 0x8B0;
*(_WORD *)&termios_p.c_cc[5] = 0;
tcflush(fd, 0);
if ( tcsetattr(fd, 0, &termios_p) != -1 )
return 1LL;
perror("On tcsetattr:");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func7()
{
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

tcgetattr(fd, &termios_p);
cfsetispeed(&termios_p, 0xDu);
cfsetospeed(&termios_p, 0xDu);
termios_p.c_iflag &= 0xFFFFE3FF;
termios_p.c_cflag = termios_p.c_cflag & 0x7FFFFE8F | 0x8B0;
*(_WORD *)&termios_p.c_cc[5] = 0;
tcflush(fd, 0);
if ( tcsetattr(fd, 0, &termios_p) != -1 )
return 1LL;
perror("On tcsetattr:");
return 0xFFFFFFFFLL;
}

original_code:
int init_port()
{
    int portstatus = 0;
    struct termios options;
    tcgetattr(fd, &options);
    cfsetispeed(&options, 0000015);
    cfsetospeed(&options, 0000015);
    options.c_cflag |= (0004000 | 0000200);
    options.c_cflag &= ~0000400;
    options.c_cflag &= ~0000100;
    options.c_cflag &= ~0000060;
    options.c_cflag |= 0000060;
    options.c_cflag &= ~020000000000;
    options.c_iflag &= ~(0002000 | 0010000 | 0004000);
    options.c_cc[6] = 0;
    options.c_cc[5] = 0;
    tcflush(fd, 0);
    if (tcsetattr(fd, 0, &options)==-1)
    {
        perror("On tcsetattr:");
        portstatus = -1;
    }
    else
        portstatus = 1;
    return portstatus;
}

variable_types: portstatus int

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


decompiled_code:
ssize_t __fastcall send_cmd(const char *a1)
{
size_t v1; // rcx
size_t v2; // rdx
void *v3; // rsp
size_t i; // rax
char v6[8]; // [rsp+0h] [rbp-10h] BYREF

v1 = strlen(a1);
v2 = (int)v1 + 2;
v3 = alloca(v2);
v6[0] = 2;
v6[(int)v1 + 1] = 3;
for ( i = 0LL; v1 > i; ++i )
v6[i + 1] = a1[i];
return write(fd, v6, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func8(const char *a1)
{
size_t v1; // rcx
size_t v2; // rdx
void *v3; // rsp
size_t i; // rax
char v6[8]; // [rsp+0h] [rbp-10h] BYREF

v1 = strlen(a1);
v2 = (int)v1 + 2;
v3 = alloca(v2);
v6[0] = 2;
v6[(int)v1 + 1] = 3;
for ( i = 0LL; v1 > i; ++i )
v6[i + 1] = a1[i];
return write(fd, v6, v2);
}

original_code:
void send_cmd(const char *n) {
    int len = strlen(n);
    char cmd[len + 2];
    cmd[0]=0x02;
    cmd[len + 1]=0x03;
    int i;
    for (i = 0; i < strlen(n); i++) {
        cmd[i + 1] = n[i];
    }
    write(fd, cmd, sizeof(cmd));
}

canonical_original_code:
void send_cmd(char *n) {
    int len = strlen(n);
    char cmd[-1];
    cmd[0]=0x02;
    cmd[len + 1]=0x03;
    int i;
    for (i = 0; i < strlen(n); i++) {
        cmd[i + 1] = n[i];
    }
    write(fd, cmd, sizeof(cmd));
}

variable_types:
n
char *

variable_types: len int

variable_types:
cmd
char [-1]


decompiled_code:
ssize_t init_cmd()
{
int buf; // [rsp+Bh] [rbp-Dh] BYREF
char v2; // [rsp+Fh] [rbp-9h]

buf = 16777233;
v2 = 3;
return write(fd, &buf, 5uLL);
}

canonical_decompiled_code:
ssize_t func9()
{
int buf; // [rsp+Bh] [rbp-Dh] BYREF
char v2; // [rsp+Fh] [rbp-9h]

buf = 16777233;
v2 = 3;
return write(fd, &buf, 5uLL);
}

variable_types:
b
char [5]

variable_types: n int


decompiled_code:
__int64 open_port()
{
int v0; // eax
unsigned int v1; // er12

v0 = open("/dev/ttyUSB0", 2306);
v1 = v0;
if ( v0 == -1 )
perror("open_port: Unable to open /dev/ttyUSB0 --- \n");
else
fcntl(v0, 4, 0LL);
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
unsigned int v1; // er12

v0 = open("/dev/ttyUSB0", 2306);
v1 = v0;
if ( v0 == -1 )
perror("open_port: Unable to open /dev/ttyUSB0 --- \n");
else
fcntl(v0, 4, 0LL);
return v1;
}

original_code:
int open_port(void)
{
    int fd;
    fd = open("/dev/ttyUSB0", 02 | 0400 | 04000);
    if (fd == -1) {
        perror("open_port: Unable to open /dev/ttyUSB0 --- \n");
    } else {
        fcntl(fd, 4, 0);
    }
    return (fd);
}

canonical_original_code:
int open_port()
{
    int fd;
    fd = open("/dev/ttyUSB0", 02 | 0400 | 04000);
    if (fd == -1) {
        perror("open_port: Unable to open /dev/ttyUSB0 --- \n");
    } else {
        fcntl(fd, 4, 0);
    }
    return (fd);
}

variable_types: fd int


decompiled_code:
__int64 __fastcall run_cmd(char *src, void *a2)
{
int v2; // ebx
size_t v3; // r15
void *v4; // rsp
char *v5; // rax
__int64 v6; // rbx
unsigned int v7; // er12
const char *v8; // r13
size_t v9; // rdx
void *v10; // rsp
char *i; // rdi
void *v13; // rsp
char v14[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = 0;
if ( src )
v2 = strlen(src);
if ( a2 )
{
v3 = strlen((const char *)a2);
v4 = alloca(v2 + (int)v3 + 2);
v5 = stpcpy(v14, src);
*v5 = 32;
memcpy(v5 + 1, a2, v3 + 1);
}
else
{
v13 = alloca(v2 + 2);
strcpy(v14, src);
}
v6 = 0LL;
while ( 1 )
{
v7 = strcmp(v14, cmd[2 * v6]);
if ( !v7 )
break;
if ( ++v6 == 53 )
return 1;
}
v8 = off_4040E8[2 * (int)v6];
v9 = strlen(v8) + 1;
v10 = alloca(v9);
memcpy(v14, v8, v9);
for ( i = strtok(v14, " "); i; i = strtok(0LL, " ") )
send_cmd(i);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *src, void *a2)
{
int v2; // ebx
size_t v3; // r15
void *v4; // rsp
char *v5; // rax
__int64 v6; // rbx
unsigned int v7; // er12
const char *v8; // r13
size_t v9; // rdx
void *v10; // rsp
char *i; // rdi
void *v13; // rsp
char v14[48]; // [rsp+0h] [rbp-30h] BYREF

v2 = 0;
if ( src )
v2 = strlen(src);
if ( a2 )
{
v3 = strlen((const char *)a2);
v4 = alloca(v2 + (int)v3 + 2);
v5 = stpcpy(v14, src);
*v5 = 32;
memcpy(v5 + 1, a2, v3 + 1);
}
else
{
v13 = alloca(v2 + 2);
strcpy(v14, src);
}
v6 = 0LL;
while ( 1 )
{
v7 = strcmp(v14, cmd[2 * v6]);
if ( !v7 )
break;
if ( ++v6 == 53 )
return 1;
}
v8 = off_4040E8[2 * (int)v6];
v9 = strlen(v8) + 1;
v10 = alloca(v9);
memcpy(v14, v8, v9);
for ( i = strtok(v14, " "); i; i = strtok(0LL, " ") )
func8(i);
return v7;
}

original_code:
int run_cmd(char *cmd1, char *cmd2) {
    int l = 0;
    if(cmd1 != ((void *)0)) {
        l += strlen(cmd1);
    }
    if(cmd2 != ((void *)0)) {
        l += strlen(cmd2);
    }
    char c[l + 2];
    strcpy(c, cmd1);
    if(cmd2 != ((void *)0)) {
        strcat(c, " ");
        strcat(c, cmd2);
    }
    int i;
    int size = (int)(sizeof(cmd) / sizeof(*cmd));
    for(i = 0; i < size; i++) {
        if(strcmp(c, cmd[i][0]) == 0) {
            char code[strlen(cmd[i][1]) + 1];
            strcpy(code, cmd[i][1]);
            char *pch;
            pch = strtok(code, " ");
            while (pch != ((void *)0)) {
                send_cmd(pch);
                pch = strtok(((void *)0), " ");
            }
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int run_cmd(char *cmd1, char *cmd2) {
    int l = 0;
    if(cmd1 != ((void *)0)) {
        l += strlen(cmd1);
    }
    if(cmd2 != ((void *)0)) {
        l += strlen(cmd2);
    }
    char c[-1];
    strcpy(c, cmd1);
    if(cmd2 != ((void *)0)) {
        strcat(c, " ");
        strcat(c, cmd2);
    }
    int i;
    int size = (int)(sizeof(cmd) / sizeof(*cmd));
    for(i = 0; i < size; i++) {
        if(strcmp(c, cmd[i][0]) == 0) {
            char code[-1];
            strcpy(code, cmd[i][1]);
            char *pch;
            pch = strtok(code, " ");
            while (pch != ((void *)0)) {
                send_cmd(pch);
                pch = strtok(((void *)0), " ");
            }
            return 0;
        }
    }
    return 1;
}

variable_types: l int

variable_types:
c
char [-1]

variable_types: size int

variable_types:
code
char [-1]

variable_types:
pch
char *


repo: panzi/lslinks

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rbp
int v5; // ebx
const char **v6; // r12
char *v7; // r14
int result; // eax
const char *v9; // rsi

if ( argc <= 1 )
{
v9 = "joinurl";
if ( argc == 1 )
v9 = *argv;
printf(
"joinurl - build an abosulute url from a base url and an relative url\nUsage: %s BASE-URL [RELATIVE-URL]...\n",
v9);
result = 1;
}
else
{
if ( (unsigned __int8)lslinks_is_absurl(argv[1]) )
{
v4 = 0LL;
v5 = 1;
}
else
{
v4 = (char *)lslinks_path_to_url(argv[1]);
if ( !v4 )
{
perror(argv[1]);
return 1;
}
v5 = 2;
if ( argc == 2 )
{
LABEL_13:
puts(v4);
free(v4);
return 0;
}
}
v6 = &argv[v5];
while ( 1 )
{
v7 = v4;
v4 = (char *)lslinks_absurl(*v6, v4);
if ( !v4 )
break;
++v5;
++v6;
free(v7);
if ( argc <= v5 )
goto LABEL_13;
}
perror(*v6);
free(v7);
result = 1;
}
return result;
}

original_code:
int main (int argc, char *argv[]) {
 if (argc <= 1) {
  printf(
   "joinurl - build an abosulute url from a base url and an relative url\n"
   "Usage: %s BASE-URL [RELATIVE-URL]...\n",
   argc > 0 ? argv[0] : "joinurl");
  return 1;
 }
 int i = 1;
 char *url = ((void *)0);
 if (!lslinks_is_absurl(argv[1])) {
  i = 2;
  url = lslinks_path_to_url(argv[1]);
  if (!url) {
   perror(argv[1]);
   return 1;
  }
 }
 for (; i < argc; ++ i) {
  char *newurl = lslinks_absurl(argv[i], url);
  if (!newurl) {
   perror(argv[i]);
   free(url);
   return 1;
  }
  free(url);
  url = newurl;
 }
 puts(url);
 free(url);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc <= 1) {
  printf(
   "joinurl - build an abosulute url from a base url and an relative url\n"
   "Usage: %s BASE-URL [RELATIVE-URL]...\n",
   argc > 0 ? argv[0] : "joinurl");
  return 1;
 }
 int i = 1;
 char *url = ((void *)0);
 if (!lslinks_is_absurl(argv[1])) {
  i = 2;
  url = lslinks_path_to_url(argv[1]);
  if (!url) {
   perror(argv[1]);
   return 1;
  }
 }
 for (; i < argc; ++ i) {
  char *newurl = lslinks_absurl(argv[i], url);
  if (!newurl) {
   perror(argv[i]);
   free(url);
   return 1;
  }
  free(url);
  url = newurl;
 }
 puts(url);
 free(url);
 return 0;
}

variable_types:
argv
char *[]

variable_types: i int

variable_types:
url
char *

variable_types:
newurl
char *


decompiled_code:
__int64 __fastcall lslinks_bytes_init2(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( a2 )
{
*a1 = 0LL;
result = 1LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = a2;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

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

if ( a2 )
{
*a1 = 0LL;
result = 1LL;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = a2;
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
_Bool lslinks_bytes_init2(struct lslinks_bytes *bytes, size_t increment) {
 if (increment == 0) {
  (*__errno_location ()) = 22;
  return 0;
 }
 bytes->data = ((void *)0);
 bytes->size = 0;
 bytes->capacity = 0;
 bytes->increment = increment;
 return 1;
}

canonical_original_code:
_Bool lslinks_bytes_init2(struct lslinks_bytes *bytes, unsigned long increment) {
 if (increment == 0) {
  (*__errno_location ()) = 22;
  return 0;
 }
 bytes->data = ((void *)0);
 bytes->size = 0;
 bytes->capacity = 0;
 bytes->increment = increment;
 return 1;
}

variable_types: struct lslinks_bytes { char *data; unsigned long size; unsigned long capacity; unsigned long increment; } *

variable_types:
increment
unsigned long


decompiled_code:
void __fastcall lslinks_bytes_cleanup(__int64 a1)
{
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void lslinks_bytes_cleanup(struct lslinks_bytes *bytes) {
 free(bytes->data);
 bytes->data = ((void *)0);
 bytes->size = 0;
 bytes->capacity = 0;
}

user_defined_types: struct lslinks_bytes { char *data; unsigned long size; unsigned long capacity; unsigned long increment; }


original_code:
_Bool lslinks_bytes_ensure(struct lslinks_bytes *bytes, size_t size) {
 size_t new_size = bytes->size + size;
 if (new_size > bytes->capacity) {
  size_t rem = new_size % bytes->increment;
  size_t new_cap = new_size;
  if (rem) {
   new_cap += bytes->increment - rem;
  }
  char *ptr = realloc(bytes->data, new_cap);
  if (!ptr) return 0;
  bytes->data = ptr;
  bytes->capacity = new_cap;
 }
 return 1;
}

canonical_original_code:
_Bool lslinks_bytes_ensure(struct lslinks_bytes *bytes, unsigned long size) {
 unsigned long new_size = bytes->size + size;
 if (new_size > bytes->capacity) {
  unsigned long rem = new_size % bytes->increment;
  unsigned long new_cap = new_size;
  if (rem) {
   new_cap += bytes->increment - rem;
  }
  char *ptr = realloc(bytes->data, new_cap);
  if (!ptr) return 0;
  bytes->data = ptr;
  bytes->capacity = new_cap;
 }
 return 1;
}

variable_types:
size
unsigned long

variable_types:
rem
unsigned long

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall lslinks_bytes_append(_QWORD *a1, const void *a2, size_t a3)
{
unsigned int v4; // er12

v4 = lslinks_bytes_ensure((__int64)a1, a3);
if ( (_BYTE)v4 )
{
memcpy((void *)(*a1 + a1[1]), a2, a3);
a1[1] += a3;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, const void *a2, size_t a3)
{
unsigned int v4; // er12

v4 = func3((__int64)a1, a3);
if ( (_BYTE)v4 )
{
memcpy((void *)(*a1 + a1[1]), a2, a3);
a1[1] += a3;
}
return v4;
}

original_code:
_Bool lslinks_bytes_append(struct lslinks_bytes *bytes, const void *data, size_t size) {
 if (!lslinks_bytes_ensure(bytes, size)) {
  return 0;
 }
 memcpy(bytes->data + bytes->size, data, size);
 bytes->size += size;
 return 1;
}

canonical_original_code:
_Bool lslinks_bytes_append(struct lslinks_bytes *bytes, void *data, unsigned long size) {
 if (!lslinks_bytes_ensure(bytes, size)) {
  return 0;
 }
 memcpy(bytes->data + bytes->size, data, size);
 bytes->size += size;
 return 1;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall lslinks_bytes_append_str(_QWORD *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return lslinks_bytes_append(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func4(a1, a2, v2);
}

original_code:
_Bool lslinks_bytes_append_str(struct lslinks_bytes *bytes, const char *str) {
 return lslinks_bytes_append(bytes, str, strlen(str));
}

canonical_original_code:
_Bool lslinks_bytes_append_str(struct lslinks_bytes *bytes, char *str) {
 return lslinks_bytes_append(bytes, str, strlen(str));
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall lslinks_bytes_append_char(_QWORD *a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return lslinks_bytes_append(a1, v3, 1uLL);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, char a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a2;
return func4(a1, v3, 1uLL);
}

original_code:
_Bool lslinks_bytes_append_char(struct lslinks_bytes *bytes, char ch) {
 return lslinks_bytes_append(bytes, &ch, 1);
}

variable_types: ch char


decompiled_code:
__int64 __fastcall lslinks_bytes_append_nil(_QWORD *a1)
{
return lslinks_bytes_append(a1, &unk_38F, 1uLL);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
return func4(a1, &unk_38F, 1uLL);
}

original_code:
_Bool lslinks_bytes_append_nil(struct lslinks_bytes *bytes) {
 return lslinks_bytes_append(bytes, "", 1);
}


decompiled_code:
char *__fastcall lslinks_strcat(void *src, char *s)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // r12

v2 = strlen((const char *)src);
v3 = strlen(s);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
memcpy(v4, src, v2);
memcpy(&v5[v2], s, v3 + 1);
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func10(void *src, char *s)
{
size_t v2; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // r12

v2 = strlen((const char *)src);
v3 = strlen(s);
v4 = (char *)malloc(v2 + v3 + 1);
v5 = v4;
if ( v4 )
{
memcpy(v4, src, v2);
memcpy(&v5[v2], s, v3 + 1);
}
return v5;
}

original_code:
char *lslinks_strcat(const char *str1, const char *str2) {
 size_t len1 = strlen(str1);
 size_t len2 = strlen(str2);
 size_t size = len1 + len2 + 1;
 char *str = malloc(size);
 if (!str) {
  return ((void *)0);
 }
 memcpy(str, str1, len1);
 memcpy(str + len1, str2, len2 + 1);
 return str;
}

canonical_original_code:
char *lslinks_strcat(char *str1, char *str2) {
 unsigned long len1 = strlen(str1);
 unsigned long len2 = strlen(str2);
 unsigned long size = len1 + len2 + 1;
 char *str = malloc(size);
 if (!str) {
  return ((void *)0);
 }
 memcpy(str, str1, len1);
 memcpy(str + len1, str2, len2 + 1);
 return str;
}


decompiled_code:
bool __fastcall lslinks_is_absurl(char *a1)
{
const unsigned __int16 *v1; // rsi
bool result; // al
char *i; // rax
__int64 v4; // rcx
char v5; // dl

v1 = *_ctype_b_loc();
result = 0;
if ( (v1[*a1] & 0x400) != 0 )
{
for ( i = a1 + 1; ; ++i )
{
v4 = *i;
v5 = *i;
if ( (v1[v4] & 8) == 0 && (unsigned __int8)(v4 - 45) > 1u && v5 != 43 )
break;
}
result = v5 == 58;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(char *a1)
{
const unsigned __int16 *v1; // rsi
bool result; // al
char *i; // rax
__int64 v4; // rcx
char v5; // dl

v1 = *_ctype_b_loc();
result = 0;
if ( (v1[*a1] & 0x400) != 0 )
{
for ( i = a1 + 1; ; ++i )
{
v4 = *i;
v5 = *i;
if ( (v1[v4] & 8) == 0 && (unsigned __int8)(v4 - 45) > 1u && v5 != 43 )
break;
}
result = v5 == 58;
}
return result;
}

original_code:
_Bool lslinks_is_absurl(const char *url) {
 const char *ptr = url;
 if (!((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISalpha)) {
  return 0;
 }
 for (++ ptr;; ++ ptr) {
  char ch = *ptr;
  if (!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalnum) && ch != '-' && ch != '+' && ch != '.') {
   break;
  }
 }
 return *ptr == ':';
}

canonical_original_code:
_Bool lslinks_is_absurl(char *url) {
 char *ptr = url;
 if (!((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISalpha)) {
  return 0;
 }
 for (++ ptr;; ++ ptr) {
  char ch = *ptr;
  if (!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalnum) && ch != '-' && ch != '+' && ch != '.') {
   break;
  }
 }
 return *ptr == ':';
}


decompiled_code:
bool __fastcall lslinks_is_fileurl(char *s2)
{
return strncasecmp("file:", s2, 5uLL) == 0;
}

canonical_decompiled_code:
bool __fastcall func1(char *s2)
{
return strncasecmp("file:", s2, 5uLL) == 0;
}

original_code:
_Bool lslinks_is_fileurl(const char *url) {
 return (strncasecmp("file:",(url),5) == 0);
}

canonical_original_code:
_Bool lslinks_is_fileurl(char *url) {
 return (strncasecmp("file:",(url),5) == 0);
}


decompiled_code:
char *__fastcall lslinks_url_path(char *s)
{
char *v2; // rax
char *v3; // r12
const char *i; // rdi

v2 = strchr(s, 58);
v3 = v2;
if ( !v2 )
{
*_errno_location() = 22;
return v3;
}
for ( i = v2 + 1; *i == 47; ++i )
;
v3 = strchr(i, 47);
if ( v3 )
return v3;
return &s[strlen(s)];
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
char *v2; // rax
char *v3; // r12
const char *i; // rdi

v2 = strchr(s, 58);
v3 = v2;
if ( !v2 )
{
*_errno_location() = 22;
return v3;
}
for ( i = v2 + 1; *i == 47; ++i )
;
v3 = strchr(i, 47);
if ( v3 )
return v3;
return &s[strlen(s)];
}

original_code:
const char *lslinks_url_path(const char *absurl) {
 const char *ptr = strchr(absurl, ':');
 if (!ptr) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 ++ ptr;
 while (*ptr == '/') ++ ptr;
 ptr = strchr(ptr, '/');
 if (!ptr) {
  return absurl + strlen(absurl);
 }
 return ptr;
}

canonical_original_code:
char *lslinks_url_path(char *absurl) {
 char *ptr = strchr(absurl, ':');
 if (!ptr) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 ++ ptr;
 while (*ptr == '/') ++ ptr;
 ptr = strchr(ptr, '/');
 if (!ptr) {
  return absurl + strlen(absurl);
 }
 return ptr;
}

variable_types:
absurl
char *


decompiled_code:
char *__fastcall lslinks_url_path_leaf(char *s)
{
char v1; // dl
char *v2; // r8
char *v3; // rax
char *v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rcx
unsigned __int64 v8; // rcx

if ( !strncasecmp("file:", s, 5uLL) )
{
v1 = s[5];
v2 = s + 5;
if ( v1 )
{
v3 = s + 5;
do
{
if ( v1 == 47 )
v2 = v3;
v1 = *++v3;
}
while ( v1 );
}
return v2;
}
v5 = lslinks_url_path(s);
if ( !v5 )
return 0LL;
v6 = (unsigned __int8)*v5;
v2 = v5;
if ( (unsigned __int8)v6 <= 0x3Fu )
{
v8 = 0x8000000800000001LL;
if ( _bittest64((const __int64 *)&v8, v6) )
return v2;
}
v7 = 0x8000000800000001LL;
do
{
if ( (_BYTE)v6 == 47 )
v2 = v5;
v6 = (unsigned __int8)*++v5;
}
while ( (unsigned __int8)v6 > 0x3Fu || !_bittest64((const __int64 *)&v7, v6) );
return v2;
}

canonical_decompiled_code:
char *__fastcall func3(char *s)
{
char v1; // dl
char *v2; // r8
char *v3; // rax
char *v5; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rcx
unsigned __int64 v8; // rcx

if ( !strncasecmp("file:", s, 5uLL) )
{
v1 = s[5];
v2 = s + 5;
if ( v1 )
{
v3 = s + 5;
do
{
if ( v1 == 47 )
v2 = v3;
v1 = *++v3;
}
while ( v1 );
}
return v2;
}
v5 = func2(s);
if ( !v5 )
return 0LL;
v6 = (unsigned __int8)*v5;
v2 = v5;
if ( (unsigned __int8)v6 <= 0x3Fu )
{
v8 = 0x8000000800000001LL;
if ( _bittest64((const __int64 *)&v8, v6) )
return v2;
}
v7 = 0x8000000800000001LL;
do
{
if ( (_BYTE)v6 == 47 )
v2 = v5;
v6 = (unsigned __int8)*++v5;
}
while ( (unsigned __int8)v6 > 0x3Fu || !_bittest64((const __int64 *)&v7, v6) );
return v2;
}

original_code:
const char *lslinks_url_path_leaf(const char *absurl) {
 const char *ptr, *last;
 if ((strncasecmp("file:",(absurl),5) == 0)) {
  last = ptr = absurl + 5;
  while (*ptr) {
   if (*ptr == '/') last = ptr;
   ++ ptr;
  }
 }
 else {
  last = ptr = lslinks_url_path(absurl);
  if (!ptr) return ((void *)0);
  while (*ptr && *ptr != '#' && *ptr != '?') {
   if (*ptr == '/') last = ptr;
   ++ ptr;
  }
 }
 return last;
}

canonical_original_code:
char *lslinks_url_path_leaf(char *absurl) {
 char *ptr; char *last;
 if ((strncasecmp("file:",(absurl),5) == 0)) {
  last = ptr = absurl + 5;
  while (*ptr) {
   if (*ptr == '/') last = ptr;
   ++ ptr;
  }
 }
 else {
  last = ptr = lslinks_url_path(absurl);
  if (!ptr) return ((void *)0);
  while (*ptr && *ptr != '#' && *ptr != '?') {
   if (*ptr == '/') last = ptr;
   ++ ptr;
  }
 }
 return last;
}

variable_types:
last
char *


decompiled_code:
__int64 __fastcall lslinks_absurl_bytes(char *s, char *a2, __int64 a3)
{
char *v4; // r13
const unsigned __int16 *v6; // r12
__int64 v7; // rax
char v8; // bl
char *i; // rax
signed __int64 v10; // r12
char *v11; // rax
unsigned __int64 v13; // rax
char *v14; // rdx
unsigned __int64 v15; // rcx
unsigned __int64 v16; // rcx
unsigned __int64 v17; // rax
__int64 v18; // rdx
char *v19; // rsi
char *v20; // rax
char *v21; // rax

v4 = a2;
v6 = *_ctype_b_loc();
while ( 1 )
{
v7 = *s;
v8 = *s;
if ( (v6[v7] & 0x2000) == 0 )
break;
++s;
}
if ( !(_BYTE)v7 )
return lslinks_bytes_append_str(a3, a2);
for ( i = &s[strlen(s)]; s < i && (v6[*(i - 1)] & 0x2000) != 0; --i )
;
v10 = i - s;
if ( lslinks_is_absurl(s) )
return lslinks_bytes_append(a3, s, v10);
switch ( v8 )
{
case '/':
if ( s[1] == 47 )
{
v20 = strchr(a2, 58);
if ( !v20 )
{
*_errno_location() = 22;
return 0LL;
}
v18 = v20 - a2 + 1;
}
else
{
if ( !strncasecmp("file:", a2, 5uLL) )
{
if ( (unsigned __int8)lslinks_bytes_append_str(a3, "file://") )
return lslinks_bytes_append(a3, s, v10);
return 0LL;
}
v21 = lslinks_url_path(a2);
if ( !v21 )
return 0LL;
v18 = v21 - a2;
}
LABEL_22:
if ( (unsigned __int8)lslinks_bytes_append(a3, a2, v18) )
return lslinks_bytes_append(a3, s, v10);
return 0LL;
case '?':
v13 = (unsigned __int8)*a2;
v14 = a2;
if ( (unsigned __int8)v13 <= 0x3Fu && (v15 = 0x8000000800000001LL, _bittest64((const __int64 *)&v15, v13)) )
{
v18 = 0LL;
}
else
{
v16 = 0x8000000800000001LL;
do
{
do
v17 = (unsigned __int8)*++v14;
while ( (unsigned __int8)v17 > 0x3Fu );
}
while ( !_bittest64((const __int64 *)&v16, v17) );
v18 = v14 - a2;
}
goto LABEL_22;
case '#':
v19 = strchr(a2, 35);
if ( !v19 )
v19 = v4;
if ( !(unsigned __int8)lslinks_bytes_append_str(a3, v19) )
return 0LL;
return lslinks_bytes_append(a3, s, v10);
}
v11 = lslinks_url_path_leaf(a2);
if ( !v11
|| !(unsigned __int8)lslinks_bytes_append(a3, a2, v11 - a2)
|| !(unsigned __int8)lslinks_bytes_append_str(a3, "/")
|| !(unsigned __int8)lslinks_bytes_append(a3, s, v10) )
{
return 0LL;
}
return lslinks_bytes_append_nil(a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, char *a2, __int64 a3)
{
char *v4; // r13
const unsigned __int16 *v6; // r12
__int64 v7; // rax
char v8; // bl
char *i; // rax
signed __int64 v10; // r12
char *v11; // rax
unsigned __int64 v13; // rax
char *v14; // rdx
unsigned __int64 v15; // rcx
unsigned __int64 v16; // rcx
unsigned __int64 v17; // rax
__int64 v18; // rdx
char *v19; // rsi
char *v20; // rax
char *v21; // rax

v4 = a2;
v6 = *_ctype_b_loc();
while ( 1 )
{
v7 = *s;
v8 = *s;
if ( (v6[v7] & 0x2000) == 0 )
break;
++s;
}
if ( !(_BYTE)v7 )
return lslinks_bytes_append_str(a3, a2);
for ( i = &s[strlen(s)]; s < i && (v6[*(i - 1)] & 0x2000) != 0; --i )
;
v10 = i - s;
if ( func0(s) )
return lslinks_bytes_append(a3, s, v10);
switch ( v8 )
{
case '/':
if ( s[1] == 47 )
{
v20 = strchr(a2, 58);
if ( !v20 )
{
*_errno_location() = 22;
return 0LL;
}
v18 = v20 - a2 + 1;
}
else
{
if ( !strncasecmp("file:", a2, 5uLL) )
{
if ( (unsigned __int8)lslinks_bytes_append_str(a3, "file://") )
return lslinks_bytes_append(a3, s, v10);
return 0LL;
}
v21 = func2(a2);
if ( !v21 )
return 0LL;
v18 = v21 - a2;
}
LABEL_22:
if ( (unsigned __int8)lslinks_bytes_append(a3, a2, v18) )
return lslinks_bytes_append(a3, s, v10);
return 0LL;
case '?':
v13 = (unsigned __int8)*a2;
v14 = a2;
if ( (unsigned __int8)v13 <= 0x3Fu && (v15 = 0x8000000800000001LL, _bittest64((const __int64 *)&v15, v13)) )
{
v18 = 0LL;
}
else
{
v16 = 0x8000000800000001LL;
do
{
do
v17 = (unsigned __int8)*++v14;
while ( (unsigned __int8)v17 > 0x3Fu );
}
while ( !_bittest64((const __int64 *)&v16, v17) );
v18 = v14 - a2;
}
goto LABEL_22;
case '#':
v19 = strchr(a2, 35);
if ( !v19 )
v19 = v4;
if ( !(unsigned __int8)lslinks_bytes_append_str(a3, v19) )
return 0LL;
return lslinks_bytes_append(a3, s, v10);
}
v11 = func3(a2);
if ( !v11
|| !(unsigned __int8)lslinks_bytes_append(a3, a2, v11 - a2)
|| !(unsigned __int8)lslinks_bytes_append_str(a3, "/")
|| !(unsigned __int8)lslinks_bytes_append(a3, s, v10) )
{
return 0LL;
}
return lslinks_bytes_append_nil(a3);
}

original_code:
_Bool lslinks_absurl_bytes(const char *url, const char *base, struct lslinks_bytes *bytes) {
 const char *ptr;
 size_t urllen;
 while (((*__ctype_b_loc ())[(int) ((*url))] & (unsigned short int) _ISspace)) ++ url;
 if (*url) {
  const char *urlend = url + strlen(url);
  while (urlend > url) {
   const char *next = urlend - 1;
   if (!((*__ctype_b_loc ())[(int) ((*next))] & (unsigned short int) _ISspace)) break;
   urlend = next;
  }
  urllen = urlend - url;
 }
 else {
  return lslinks_bytes_append_str(bytes, base);
 }
 if (lslinks_is_absurl(url)) {
  return lslinks_bytes_append(bytes, url, urllen);
 }
 switch (url[0]) {
  case '/':
   if (url[1] == '/') {
    ptr = strchr(base, ':');
    if (!ptr) {
     (*__errno_location ()) = 22;
     return 0;
    }
    return
     lslinks_bytes_append(bytes, base, ptr - base + 1) &&
     lslinks_bytes_append(bytes, url, urllen);
   }
   else if ((strncasecmp("file:",(base),5) == 0)) {
    return
     lslinks_bytes_append_str(bytes, "file://") &&
     lslinks_bytes_append(bytes, url, urllen);
   }
   else {
    ptr = lslinks_url_path(base);
    return ptr &&
     lslinks_bytes_append(bytes, base, ptr - base) &&
     lslinks_bytes_append(bytes, url, urllen);
   }
  case '#':
   ptr = strchr(base, '#');
   if (!ptr) {
    ptr = base;
   }
   return
    lslinks_bytes_append_str(bytes, ptr) &&
    lslinks_bytes_append(bytes, url, urllen);
  case '?':
   ptr = base;
   while (*ptr && *ptr != '?' && *ptr != '#') ++ ptr;
   return
    lslinks_bytes_append(bytes, base, ptr - base) &&
    lslinks_bytes_append(bytes, url, urllen);
  default:
   ptr = lslinks_url_path_leaf(base);
   return ptr &&
    lslinks_bytes_append(bytes, base, ptr - base) &&
    lslinks_bytes_append_str(bytes, "/") &&
    lslinks_bytes_append(bytes, url, urllen) &&
    lslinks_bytes_append_nil(bytes);
 }
}

canonical_original_code:
_Bool lslinks_absurl_bytes(char *url, char *base, struct lslinks_bytes *bytes) {
 char *ptr;
 unsigned long urllen;
 while (((*__ctype_b_loc ())[(int) ((*url))] & (unsigned short) _ISspace)) ++ url;
 if (*url) {
  char *urlend = url + strlen(url);
  while (urlend > url) {
   char *next = urlend - 1;
   if (!((*__ctype_b_loc ())[(int) ((*next))] & (unsigned short) _ISspace)) break;
   urlend = next;
  }
  urllen = urlend - url;
 }
 else {
  return lslinks_bytes_append_str(bytes, base);
 }
 if (lslinks_is_absurl(url)) {
  return lslinks_bytes_append(bytes, url, urllen);
 }
 switch (url[0]) {
  case '/':
   if (url[1] == '/') {
    ptr = strchr(base, ':');
    if (!ptr) {
     (*__errno_location ()) = 22;
     return 0;
    }
    return
     lslinks_bytes_append(bytes, base, ptr - base + 1) &&
     lslinks_bytes_append(bytes, url, urllen);
   }
   else if ((strncasecmp("file:",(base),5) == 0)) {
    return
     lslinks_bytes_append_str(bytes, "file://") &&
     lslinks_bytes_append(bytes, url, urllen);
   }
   else {
    ptr = lslinks_url_path(base);
    return ptr &&
     lslinks_bytes_append(bytes, base, ptr - base) &&
     lslinks_bytes_append(bytes, url, urllen);
   }
  case '#':
   ptr = strchr(base, '#');
   if (!ptr) {
    ptr = base;
   }
   return
    lslinks_bytes_append_str(bytes, ptr) &&
    lslinks_bytes_append(bytes, url, urllen);
  case '?':
   ptr = base;
   while (*ptr && *ptr != '?' && *ptr != '#') ++ ptr;
   return
    lslinks_bytes_append(bytes, base, ptr - base) &&
    lslinks_bytes_append(bytes, url, urllen);
  default:
   ptr = lslinks_url_path_leaf(base);
   return ptr &&
    lslinks_bytes_append(bytes, base, ptr - base) &&
    lslinks_bytes_append_str(bytes, "/") &&
    lslinks_bytes_append(bytes, url, urllen) &&
    lslinks_bytes_append_nil(bytes);
 }
}

variable_types:
base
char *

variable_types:
urllen
unsigned long

variable_types:
urlend
char *

variable_types:
next
char *


decompiled_code:
__int64 __fastcall lslinks_absurl(char *s, char *a2)
{
char v2; // r8
__int64 result; // rax
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = lslinks_bytes_init2(v4, 64LL);
result = 0LL;
if ( v2 )
{
if ( (unsigned __int8)lslinks_absurl_bytes(s, a2, (__int64)v4) && (unsigned __int8)lslinks_bytes_append_nil(v4) )
{
result = v4[0];
}
else
{
lslinks_bytes_cleanup(v4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, char *a2)
{
char v2; // r8
__int64 result; // rax
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = lslinks_bytes_init2(v4, 64LL);
result = 0LL;
if ( v2 )
{
if ( (unsigned __int8)func4(s, a2, (__int64)v4) && (unsigned __int8)lslinks_bytes_append_nil(v4) )
{
result = v4[0];
}
else
{
lslinks_bytes_cleanup(v4);
result = 0LL;
}
}
return result;
}

original_code:
char *lslinks_absurl(const char *url, const char *base) {
 struct lslinks_bytes bytes;
 if (!lslinks_bytes_init2(&bytes, 64)) {
  return ((void *)0);
 }
 if (!lslinks_absurl_bytes(url, base, &bytes) ||
     !lslinks_bytes_append_nil(&bytes)) {
  lslinks_bytes_cleanup(&bytes);
  return ((void *)0);
 }
 return bytes.data;
}

canonical_original_code:
char *lslinks_absurl(char *url, char *base) {
 struct lslinks_bytes bytes;
 if (!lslinks_bytes_init2(&bytes, 64)) {
  return ((void *)0);
 }
 if (!lslinks_absurl_bytes(url, base, &bytes) ||
     !lslinks_bytes_append_nil(&bytes)) {
  lslinks_bytes_cleanup(&bytes);
  return ((void *)0);
 }
 return bytes.data;
}

variable_types: struct lslinks_bytes { char *data; unsigned long size; unsigned long capacity; unsigned long increment; }


decompiled_code:
__int64 __fastcall lslinks_encode_uri_bytes(const char *a1, __int64 a2)
{
const char *v2; // r14
size_t v3; // rax
unsigned int v4; // eax
unsigned int v5; // er15
__int64 v6; // r12
__int64 v7; // r13
const char *i; // rbx
unsigned __int64 v9; // rax
char v10; // dl
char v11; // cl
char v12; // al
__int16 v14; // [rsp+Dh] [rbp-3Bh] BYREF
char v15; // [rsp+Fh] [rbp-39h]

v2 = a1;
v3 = strlen(a1);
v4 = lslinks_bytes_ensure(a2, v3);
if ( !(_BYTE)v4 )
return 0;
v5 = v4;
v15 = 0;
v6 = 0x5A00000000LL;
v7 = 0x87FFFFFFAFFFFFLL;
v14 = 37;
while ( 2 )
{
for ( i = v2; ; ++i )
{
v9 = *(unsigned __int8 *)i;
if ( (unsigned __int8)v9 <= 0x26u )
break;
if ( (unsigned __int8)(v9 - 40) > 0x37u )
goto LABEL_9;
if ( !_bittest64(&v7, (unsigned int)(v9 - 40)) )
goto LABEL_11;
LABEL_6:
;
}
if ( _bittest64(&v6, v9) )
goto LABEL_6;
LABEL_9:
if ( (unsigned __int8)(v9 - 97) <= 0x19u || (_BYTE)v9 == 126 )
goto LABEL_6;
LABEL_11:
if ( v2 == i )
goto LABEL_14;
if ( !(unsigned __int8)lslinks_bytes_append(a2, v2, i - v2) )
return 0;
LOBYTE(v9) = *i;
LABEL_14:
if ( (_BYTE)v9 )
{
v10 = v9 & 0xF;
v11 = (v9 & 0xF) + 55;
HIBYTE(v14) = ((char)v9 >> 4) + 48;
v12 = (v9 & 0xF) + 48;
if ( v10 >= 10 )
v12 = v11;
v15 = v12;
if ( (unsigned __int8)lslinks_bytes_append(a2, &v14, 3LL) )
{
v2 = i + 1;
continue;
}
return 0;
}
return v5;
}
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
const char *v2; // r14
size_t v3; // rax
unsigned int v4; // eax
unsigned int v5; // er15
__int64 v6; // r12
__int64 v7; // r13
const char *i; // rbx
unsigned __int64 v9; // rax
char v10; // dl
char v11; // cl
char v12; // al
__int16 v14; // [rsp+Dh] [rbp-3Bh] BYREF
char v15; // [rsp+Fh] [rbp-39h]

v2 = a1;
v3 = strlen(a1);
v4 = lslinks_bytes_ensure(a2, v3);
if ( !(_BYTE)v4 )
return 0;
v5 = v4;
v15 = 0;
v6 = 0x5A00000000LL;
v7 = 0x87FFFFFFAFFFFFLL;
v14 = 37;
while ( 2 )
{
for ( i = v2; ; ++i )
{
v9 = *(unsigned __int8 *)i;
if ( (unsigned __int8)v9 <= 0x26u )
break;
if ( (unsigned __int8)(v9 - 40) > 0x37u )
goto LABEL_9;
if ( !_bittest64(&v7, (unsigned int)(v9 - 40)) )
goto LABEL_11;
LABEL_6:
;
}
if ( _bittest64(&v6, v9) )
goto LABEL_6;
LABEL_9:
if ( (unsigned __int8)(v9 - 97) <= 0x19u || (_BYTE)v9 == 126 )
goto LABEL_6;
LABEL_11:
if ( v2 == i )
goto LABEL_14;
if ( !(unsigned __int8)lslinks_bytes_append(a2, v2, i - v2) )
return 0;
LOBYTE(v9) = *i;
LABEL_14:
if ( (_BYTE)v9 )
{
v10 = v9 & 0xF;
v11 = (v9 & 0xF) + 55;
HIBYTE(v14) = ((char)v9 >> 4) + 48;
v12 = (v9 & 0xF) + 48;
if ( v10 >= 10 )
v12 = v11;
v15 = v12;
if ( (unsigned __int8)lslinks_bytes_append(a2, &v14, 3LL) )
{
v2 = i + 1;
continue;
}
return 0;
}
return v5;
}
}

original_code:
_Bool lslinks_encode_uri_bytes(const char *s, struct lslinks_bytes *bytes) {
 if (!lslinks_bytes_ensure(bytes, strlen(s))) {
  return 0;
 }
 char buf[3] = "%\0\0";
 for (const char *ptr = s;; ++ ptr) {
  const char *last = ptr;
  for (;; ++ ptr) {
   char ch = *ptr;
   if (ch != '!' && ch != '#' && ch != '$' && ch != '&' &&
       (ch < '(' || ch > ';') && ch != '=' && (ch < '?' || ch > 'Z') &&
       ch != '_' && (ch < 'a' || ch > 'z') && ch != '~') {
    break;
   }
  }
  if (ptr != last && !lslinks_bytes_append(bytes, last, ptr - last)) {
   return 0;
  }
  if (!*ptr) {
   break;
  }
  int hi = *ptr >> 4;
  int lo = *ptr & 0xf;
  buf[1] = hi > 9 ? 'A' + hi - 10 : '0' + hi;
  buf[2] = lo > 9 ? 'A' + lo - 10 : '0' + lo;
  if (!lslinks_bytes_append(bytes, buf, sizeof(buf))) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool lslinks_encode_uri_bytes(char *s, struct lslinks_bytes *bytes) {
 if (!lslinks_bytes_ensure(bytes, strlen(s))) {
  return 0;
 }
 char buf[3] = "%\0\0";
 for (char *ptr = s;; ++ ptr) {
  char *last = ptr;
  for (;; ++ ptr) {
   char ch = *ptr;
   if (ch != '!' && ch != '#' && ch != '$' && ch != '&' &&
       (ch < '(' || ch > ';') && ch != '=' && (ch < '?' || ch > 'Z') &&
       ch != '_' && (ch < 'a' || ch > 'z') && ch != '~') {
    break;
   }
  }
  if (ptr != last && !lslinks_bytes_append(bytes, last, ptr - last)) {
   return 0;
  }
  if (!*ptr) {
   break;
  }
  int hi = *ptr >> 4;
  int lo = *ptr & 0xf;
  buf[1] = hi > 9 ? 'A' + hi - 10 : '0' + hi;
  buf[2] = lo > 9 ? 'A' + lo - 10 : '0' + lo;
  if (!lslinks_bytes_append(bytes, buf, sizeof(buf))) {
   return 0;
  }
 }
 return 1;
}

variable_types:
s
char *

variable_types:
buf
char [3]

variable_types: hi int

variable_types: lo int


decompiled_code:
__int64 __fastcall lslinks_decode_uri_bytes(const char *a1, __int64 a2)
{
const char *v3; // r12
size_t v4; // rax
unsigned int v5; // eax
unsigned int v6; // er14
char v7; // al
const char *v8; // rbx
const char *v9; // rbp
const unsigned __int16 **v10; // rax
const unsigned __int16 *v11; // rcx
__int64 v12; // rdx
__int64 v13; // rax
int v14; // ecx
char v15; // dl
char v16; // cl
char v18; // si
char v19[41]; // [rsp+Fh] [rbp-29h] BYREF

v3 = a1;
v4 = strlen(a1);
v5 = lslinks_bytes_ensure(a2, v4);
if ( !(_BYTE)v5 )
return 0;
v6 = v5;
while ( 1 )
{
v7 = *v3;
v8 = v3;
if ( *v3 != 37 && v7 )
{
do
{
v9 = v8;
v7 = *++v8;
}
while ( v7 && v7 != 37 );
if ( v3 != v8 )
{
if ( !(unsigned __int8)lslinks_bytes_append(a2, v3, v8 - v3) )
return 0;
v7 = v9[1];
}
}
if ( !v7 )
break;
v10 = _ctype_b_loc();
v11 = *v10;
v12 = v8[1];
if ( ((*v10)[v12] & 0x1000) != 0 && (v13 = v8[2], (v11[v13] & 0x1000) != 0) )
{
v14 = (char)v12;
if ( (char)v12 <= 96 )
{
v18 = v12 - 55;
v15 = v12 - 48;
if ( v14 >= 65 )
v15 = v18;
}
else
{
v15 = v12 - 87;
}
v16 = v13 - 87;
if ( (int)v13 <= 96 )
{
v16 = v13 - 48;
if ( (int)v13 >= 65 )
v16 = v13 - 55;
}
v19[0] = v16 | (16 * v15);
if ( !(unsigned __int8)lslinks_bytes_append(a2, v19, 1LL) )
return 0;
v8 += 2;
}
else if ( !(unsigned __int8)lslinks_bytes_append(a2, v8, 1LL) )
{
return 0;
}
v3 = v8 + 1;
}
return v6;
}

original_code:
_Bool lslinks_decode_uri_bytes(const char *s, struct lslinks_bytes *bytes) {
 if (!lslinks_bytes_ensure(bytes, strlen(s))) {
  return 0;
 }
 for (const char *ptr = s;; ++ ptr) {
  const char *last = ptr;
  while (*ptr && *ptr != '%') ++ ptr;
  if (ptr != last && !lslinks_bytes_append(bytes, last, ptr - last)) {
   return 0;
  }
  if (!*ptr) {
   break;
  }
  if (((*__ctype_b_loc ())[(int) ((ptr[1]))] & (unsigned short int) _ISxdigit) && ((*__ctype_b_loc ())[(int) ((ptr[2]))] & (unsigned short int) _ISxdigit)) {
   int hi = ptr[1];
   int lo = ptr[2];
   if (hi >= 'a') hi -= 'a' - 10;
   else if (hi >= 'A') hi -= 'A' - 10;
   else hi -= '0';
   if (lo >= 'a') lo -= 'a' - 10;
   else if (lo >= 'A') lo -= 'A' - 10;
   else lo -= '0';
   char ch = (hi << 4) | lo;
   if (!lslinks_bytes_append(bytes, &ch, 1)) {
    return 0;
   }
   ptr += 2;
  }
  else if (!lslinks_bytes_append(bytes, ptr, 1)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool lslinks_decode_uri_bytes(char *s, struct lslinks_bytes *bytes) {
 if (!lslinks_bytes_ensure(bytes, strlen(s))) {
  return 0;
 }
 for (char *ptr = s;; ++ ptr) {
  char *last = ptr;
  while (*ptr && *ptr != '%') ++ ptr;
  if (ptr != last && !lslinks_bytes_append(bytes, last, ptr - last)) {
   return 0;
  }
  if (!*ptr) {
   break;
  }
  if (((*__ctype_b_loc ())[(int) ((ptr[1]))] & (unsigned short) _ISxdigit) && ((*__ctype_b_loc ())[(int) ((ptr[2]))] & (unsigned short) _ISxdigit)) {
   int hi = ptr[1];
   int lo = ptr[2];
   if (hi >= 'a') hi -= 'a' - 10;
   else if (hi >= 'A') hi -= 'A' - 10;
   else hi -= '0';
   if (lo >= 'a') lo -= 'a' - 10;
   else if (lo >= 'A') lo -= 'A' - 10;
   else lo -= '0';
   char ch = (hi << 4) | lo;
   if (!lslinks_bytes_append(bytes, &ch, 1)) {
    return 0;
   }
   ptr += 2;
  }
  else if (!lslinks_bytes_append(bytes, ptr, 1)) {
   return 0;
  }
 }
 return 1;
}

variable_types: struct lslinks_bytes { char *data; unsigned long size; unsigned long capacity; unsigned long increment; } *


decompiled_code:
__int64 __fastcall lslinks_encode_uri(const char *a1)
{
char v1; // r8
__int64 result; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v1 = lslinks_bytes_init2(v3, 32LL);
result = 0LL;
if ( v1 )
{
if ( (unsigned __int8)lslinks_encode_uri_bytes(a1, (__int64)v3) && (unsigned __int8)lslinks_bytes_append_nil(v3) )
{
result = v3[0];
}
else
{
lslinks_bytes_cleanup(v3);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
char v1; // r8
__int64 result; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v1 = lslinks_bytes_init2(v3, 32LL);
result = 0LL;
if ( v1 )
{
if ( (unsigned __int8)func6(a1, (__int64)v3) && (unsigned __int8)lslinks_bytes_append_nil(v3) )
{
result = v3[0];
}
else
{
lslinks_bytes_cleanup(v3);
result = 0LL;
}
}
return result;
}

original_code:
char *lslinks_encode_uri(const char *s) {
 struct lslinks_bytes bytes;
 if (!lslinks_bytes_init2(&bytes, 32)) {
  return ((void *)0);
 }
 if (!lslinks_encode_uri_bytes(s, &bytes) ||
     !lslinks_bytes_append_nil(&bytes)) {
  lslinks_bytes_cleanup(&bytes);
  return ((void *)0);
 }
 return bytes.data;
}

canonical_original_code:
char *lslinks_encode_uri(char *s) {
 struct lslinks_bytes bytes;
 if (!lslinks_bytes_init2(&bytes, 32)) {
  return ((void *)0);
 }
 if (!lslinks_encode_uri_bytes(s, &bytes) ||
     !lslinks_bytes_append_nil(&bytes)) {
  lslinks_bytes_cleanup(&bytes);
  return ((void *)0);
 }
 return bytes.data;
}


decompiled_code:
__int64 __fastcall lslinks_path_to_url(const char *a1)
{
char *v1; // rax
char *v2; // r12
char *v3; // r13
char *v4; // rax
char *v5; // rbp
__int64 v6; // r12
__int64 v8; // rax
void *v9; // rbp
__int64 v10; // r12
char v11[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( *a1 != 47 )
{
if ( realpath(".", v11) )
{
*(_WORD *)&v11[strlen(v11)] = 47;
v1 = (char *)lslinks_encode_uri(v11);
v2 = v1;
if ( v1 )
{
v3 = (char *)lslinks_absurl(v1, "file:///");
free(v2);
if ( v3 )
{
v4 = (char *)lslinks_encode_uri(a1);
v5 = v4;
if ( v4 )
{
v6 = lslinks_absurl(v4, v3);
free(v5);
free(v3);
return v6;
}
free(v3);
}
}
}
return 0LL;
}
v8 = lslinks_encode_uri(a1);
v9 = (void *)v8;
if ( !v8 )
return 0LL;
v10 = lslinks_strcat("file://", v8);
free(v9);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
char *v1; // rax
char *v2; // r12
char *v3; // r13
char *v4; // rax
char *v5; // rbp
__int64 v6; // r12
__int64 v8; // rax
void *v9; // rbp
__int64 v10; // r12
char v11[4136]; // [rsp+0h] [rbp-1028h] BYREF

if ( *a1 != 47 )
{
if ( realpath(".", v11) )
{
*(_WORD *)&v11[strlen(v11)] = 47;
v1 = (char *)func8(v11);
v2 = v1;
if ( v1 )
{
v3 = (char *)func5(v1, "file:///");
free(v2);
if ( v3 )
{
v4 = (char *)func8(a1);
v5 = v4;
if ( v4 )
{
v6 = func5(v4, v3);
free(v5);
free(v3);
return v6;
}
free(v3);
}
}
}
return 0LL;
}
v8 = func8(a1);
v9 = (void *)v8;
if ( !v8 )
return 0LL;
v10 = lslinks_strcat("file://", v8);
free(v9);
return v10;
}

original_code:
char *lslinks_path_to_url(const char *path) {
 if (path[0] == '/') {
  char *encoded = lslinks_encode_uri(path);
  if (!encoded) {
   return ((void *)0);
  }
  char *url = lslinks_strcat("file://",encoded);
  free(encoded);
  return url;
 }
 char pwd[4096 + 2];
 if (!realpath(".", pwd)) {
  return ((void *)0);
 }
 strncat(pwd, "/", 4096 + 2);
 char *encoded = lslinks_encode_uri(pwd);
 if (!encoded) {
  return ((void *)0);
 }
 char *base = lslinks_absurl(encoded, "file:///");
 free(encoded);
 if (!base) {
  return ((void *)0);
 }
 encoded = lslinks_encode_uri(path);
 if (!encoded) {
  free(base);
  return ((void *)0);
 }
 char *url = lslinks_absurl(encoded, base);
 free(encoded);
 free(base);
 return url;
}

canonical_original_code:
char *lslinks_path_to_url(char *path) {
 if (path[0] == '/') {
  char *encoded = lslinks_encode_uri(path);
  if (!encoded) {
   return ((void *)0);
  }
  char *url = lslinks_strcat("file://",encoded);
  free(encoded);
  return url;
 }
 char pwd[-1];
 if (!realpath(".", pwd)) {
  return ((void *)0);
 }
 strncat(pwd, "/", 4096 + 2);
 char *encoded = lslinks_encode_uri(pwd);
 if (!encoded) {
  return ((void *)0);
 }
 char *base = lslinks_absurl(encoded, "file:///");
 free(encoded);
 if (!base) {
  return ((void *)0);
 }
 encoded = lslinks_encode_uri(path);
 if (!encoded) {
  free(base);
  return ((void *)0);
 }
 char *url = lslinks_absurl(encoded, base);
 free(encoded);
 free(base);
 return url;
}

variable_types:
path
char *

variable_types:
encoded
char *

variable_types:
url
char *

variable_types:
pwd
char [-1]


decompiled_code:
__int64 __fastcall lslinks_decode_uri(const char *a1)
{
char v1; // r8
__int64 result; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v1 = lslinks_bytes_init2(v3, 32LL);
result = 0LL;
if ( v1 )
{
if ( (unsigned __int8)lslinks_decode_uri_bytes(a1, (__int64)v3) && (unsigned __int8)lslinks_bytes_append_nil(v3) )
{
result = v3[0];
}
else
{
lslinks_bytes_cleanup(v3);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
char v1; // r8
__int64 result; // rax
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v1 = lslinks_bytes_init2(v3, 32LL);
result = 0LL;
if ( v1 )
{
if ( (unsigned __int8)func7(a1, (__int64)v3) && (unsigned __int8)lslinks_bytes_append_nil(v3) )
{
result = v3[0];
}
else
{
lslinks_bytes_cleanup(v3);
result = 0LL;
}
}
return result;
}

original_code:
char *lslinks_decode_uri(const char *s) {
 struct lslinks_bytes bytes;
 if (!lslinks_bytes_init2(&bytes, 32)) {
  return ((void *)0);
 }
 if (!lslinks_decode_uri_bytes(s, &bytes) ||
     !lslinks_bytes_append_nil(&bytes)) {
  lslinks_bytes_cleanup(&bytes);
  return ((void *)0);
 }
 return bytes.data;
}

canonical_original_code:
char *lslinks_decode_uri(char *s) {
 struct lslinks_bytes bytes;
 if (!lslinks_bytes_init2(&bytes, 32)) {
  return ((void *)0);
 }
 if (!lslinks_decode_uri_bytes(s, &bytes) ||
     !lslinks_bytes_append_nil(&bytes)) {
  lslinks_bytes_cleanup(&bytes);
  return ((void *)0);
 }
 return bytes.data;
}


decompiled_code:
__int64 __fastcall lslinks_url_to_path(char *s2)
{
const char *v2; // rdi
__int64 result; // rax

if ( !strncasecmp("file:", s2, 5uLL) )
{
v2 = s2 + 5;
if ( s2[5] == 47 && s2[6] == 47 && (v2 = s2 + 7, s2[7] != 47) )
result = lslinks_decode_uri(s2 + 6);
else
result = lslinks_decode_uri(v2);
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s2)
{
const char *v2; // rdi
__int64 result; // rax

if ( !strncasecmp("file:", s2, 5uLL) )
{
v2 = s2 + 5;
if ( s2[5] == 47 && s2[6] == 47 && (v2 = s2 + 7, s2[7] != 47) )
result = func10(s2 + 6);
else
result = func10(v2);
}
else
{
*_errno_location() = 22;
result = 0LL;
}
return result;
}

original_code:
char *lslinks_url_to_path(const char *absurl) {
 if (!(strncasecmp("file:",(absurl),5) == 0)) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 const char *ptr = absurl + 5;
 if (ptr[0] == '/' && ptr[1] == '/') {
  ++ ptr;
  if (ptr[1] == '/') {
   ++ ptr;
  }
 }
 return lslinks_decode_uri(ptr);
}

canonical_original_code:
char *lslinks_url_to_path(char *absurl) {
 if (!(strncasecmp("file:",(absurl),5) == 0)) {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 char *ptr = absurl + 5;
 if (ptr[0] == '/' && ptr[1] == '/') {
  ++ ptr;
  if (ptr[1] == '/') {
   ++ ptr;
  }
 }
 return lslinks_decode_uri(ptr);
}

variable_types:
ptr
char *


intcompar

repo: papazoga/randpass

decompiled_code:
__int64 __fastcall intcompar(const void *a1, const void *a2)
{
return (unsigned int)(*(char *)a1 - *(char *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)(*(char *)a1 - *(char *)a2);
}

original_code:
int intcompar(const void *x, const void *y)
{
    return *(char *)x-*(char *)y;
}

canonical_original_code:
int intcompar(void *x, void *y)
{
    return *(char *)x-*(char *)y;
}

variable_types:
x
void *

variable_types:
y
void *


decompiled_code:
int __fastcall append_single(char a1)
{
__int64 v1; // rax

LODWORD(v1) = isprint(a1);
if ( (_DWORD)v1 )
{
LODWORD(v1) = isspace(a1);
if ( !(_DWORD)v1 )
{
v1 = charlen++;
charclass[v1] = a1;
}
}
return v1;
}

canonical_decompiled_code:
int __fastcall func8(char a1)
{
__int64 v1; // rax

LODWORD(v1) = isprint(a1);
if ( (_DWORD)v1 )
{
LODWORD(v1) = isspace(a1);
if ( !(_DWORD)v1 )
{
v1 = charlen++;
charclass[v1] = a1;
}
}
return v1;
}

original_code:
void append_single(int c)
{
    if (isprint(c) && !isspace(c))
 charclass[charlen++] = c;
}

variable_types: c int


decompiled_code:
int __fastcall append_range(unsigned int a1, signed int a2)
{
int v2; // er12
char v3; // di
int result; // eax

v2 = a1;
if ( (int)a1 > a2 )
{
fprintf(stderr, "bad range %c-%c\n", a1, (unsigned int)a2);
exit(1);
}
do
{
v3 = v2++;
result = append_single(v3);
}
while ( a2 >= v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1, signed int a2)
{
int v2; // er12
char v3; // di
int result; // eax

v2 = a1;
if ( (int)a1 > a2 )
{
fprintf(stderr, "bad range %c-%c\n", a1, (unsigned int)a2);
exit(1);
}
do
{
v3 = v2++;
result = func8(v3);
}
while ( a2 >= v2 );
return result;
}

original_code:
void append_range(int first, int last)
{
    if (first > last) {
 fprintf(stderr, "bad range %c-%c\n", first, last);
 exit(1);
    }
    while (first<=last)
 append_single(first++);
}

variable_types: first int

variable_types: last int