setdata

decompiled_code:
__int64 __fastcall setdata(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // rbx
_QWORD *v4; // rbp
_QWORD *v5; // rbx
const char *v6; // rsi
__int64 v7; // rax
__int64 v8; // rax
__int64 i; // r12
__int64 v10; // rbx
__int64 v11; // r15
__int64 v12; // rbp
__int64 v16; // [rsp+18h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
const char *v3; // rbx
_QWORD *v4; // rbp
_QWORD *v5; // rbx
const char *v6; // rsi
__int64 v7; // rax
__int64 v8; // rax
__int64 i; // r12
__int64 v10; // rbx
__int64 v11; // r15
__int64 v12; // rbp
__int64 v16; // [rsp+18h] [rbp-40h]

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


repo: panticz/lyc

decompiled_code:
__int64 init_port()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(fd, &v2);
cfsetispeed(&v2, 0xDu);
cfsetospeed(&v2, 0xDu);
v2.c_cflag = v2.c_cflag & 0x7FFFFE8F | 0x8B0;
v2.c_iflag &= 0xFFFFE3FF;
v2.c_cc[6] = 0;
v2.c_cc[5] = 0;
tcflush(fd, 0);
v0 = 1;
if ( tcsetattr(fd, 0, &v2) == -1 )
{
v0 = -1;
perror("On tcsetattr:");
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebx
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(fd, &v2);
cfsetispeed(&v2, 0xDu);
cfsetospeed(&v2, 0xDu);
v2.c_cflag = v2.c_cflag & 0x7FFFFE8F | 0x8B0;
v2.c_iflag &= 0xFFFFE3FF;
v2.c_cc[6] = 0;
v2.c_cc[5] = 0;
tcflush(fd, 0);
v0 = 1;
if ( tcsetattr(fd, 0, &v2) == -1 )
{
v0 = -1;
perror("On tcsetattr:");
}
return v0;
}

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

return_type: int


decompiled_code:
ssize_t __fastcall send_cmd(char *s)
{
int v1; // eax
size_t v2; // r14
void *v3; // rsp
size_t i; // rbx
char v6[32]; // [rsp+0h] [rbp-20h] BYREF

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

canonical_decompiled_code:
ssize_t __fastcall func8(char *s)
{
int v1; // eax
size_t v2; // r14
void *v3; // rsp
size_t i; // rbx
char v6[32]; // [rsp+0h] [rbp-20h] BYREF

v1 = strlen(s);
v2 = v1 + 2;
v3 = alloca(v2);
v6[0] = 2;
v6[v1 + 1] = 3;
for ( i = 0LL; strlen(s) > i; ++i )
v6[i + 1] = s[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]

return_type: void


decompiled_code:
ssize_t init_cmd()
{
char buf[13]; // [rsp+Bh] [rbp-Dh] BYREF

buf[0] = 17;
buf[1] = 0;
buf[2] = 0;
buf[3] = 1;
buf[4] = 3;
return write(fd, buf, 5uLL);
}

canonical_decompiled_code:
ssize_t func9()
{
char buf[13]; // [rsp+Bh] [rbp-Dh] BYREF

buf[0] = 17;
buf[1] = 0;
buf[2] = 0;
buf[3] = 1;
buf[4] = 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; // ebx

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; // ebx

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, char *a2)
{
int v2; // ebx
void *v3; // rsp
__int64 v4; // rbx
unsigned int v5; // er12
const char *v6; // r13
void *v7; // rsp
char *i; // rdi
void *v10; // rsp
char v11[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = 0;
if ( src )
v2 = strlen(src);
if ( a2 )
{
v3 = alloca((int)(v2 + strlen(a2) + 2));
strcpy(v11, src);
*(_WORD *)&v11[strlen(v11)] = 32;
strcat(v11, a2);
}
else
{
v10 = alloca(v2 + 2);
strcpy(v11, src);
}
v4 = 0LL;
while ( 1 )
{
v5 = strcmp(v11, cmd[2 * v4]);
if ( !v5 )
break;
if ( ++v4 == 53 )
return 1;
}
v6 = off_4040C8[2 * (int)v4];
v7 = alloca(strlen(v6) + 1);
strcpy(v11, v6);
for ( i = strtok(v11, " "); i; i = strtok(0LL, " ") )
send_cmd(i);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *src, char *a2)
{
int v2; // ebx
void *v3; // rsp
__int64 v4; // rbx
unsigned int v5; // er12
const char *v6; // r13
void *v7; // rsp
char *i; // rdi
void *v10; // rsp
char v11[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = 0;
if ( src )
v2 = strlen(src);
if ( a2 )
{
v3 = alloca((int)(v2 + strlen(a2) + 2));
strcpy(v11, src);
*(_WORD *)&v11[strlen(v11)] = 32;
strcat(v11, a2);
}
else
{
v10 = alloca(v2 + 2);
strcpy(v11, src);
}
v4 = 0LL;
while ( 1 )
{
v5 = strcmp(v11, cmd[2 * v4]);
if ( !v5 )
break;
if ( ++v4 == 53 )
return 1;
}
v6 = off_4040C8[2 * (int)v4];
v7 = alloca(strlen(v6) + 1);
strcpy(v11, v6);
for ( i = strtok(v11, " "); i; i = strtok(0LL, " ") )
func8(i);
return v5;
}

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 *


main

canonical_name: main

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

result = argc;
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], (char *)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 = argc;
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], (char *)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 **


repo: panzi/lslinks

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rbx
int v5; // er12
const char **v6; // rbp
char *v7; // r13
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_7:
puts(v4);
free(v4);
return 0;
}
}
v6 = &argv[v5];
while ( 1 )
{
v7 = v4;
v4 = (char *)lslinks_absurl(*v6, v4);
if ( !v4 )
break;
free(v7);
++v5;
++v6;
if ( argc <= v5 )
goto LABEL_7;
}
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;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = a2;
result = 1LL;
}
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;
a1[1] = 0LL;
a1[2] = 0LL;
a1[3] = a2;
result = 1LL;
}
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; }


decompiled_code:
__int64 __fastcall lslinks_bytes_ensure(__int64 a1, __int64 a2)
{
size_t v2; // rsi
__int64 result; // rax
size_t v4; // rbx
unsigned __int64 v5; // rcx
size_t v6; // rdx
size_t v7; // rcx
void *v8; // rax

v2 = *(_QWORD *)(a1 + 8) + a2;
result = 1LL;
if ( *(_QWORD *)(a1 + 16) < v2 )
{
v4 = v2;
v5 = *(_QWORD *)(a1 + 24);
v6 = v2 % v5;
v7 = v2 + v5 - v2 % v5;
if ( v6 )
v4 = v7;
v8 = realloc(*(void **)a1, v4);
if ( v8 )
{
*(_QWORD *)a1 = v8;
*(_QWORD *)(a1 + 16) = v4;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
size_t v2; // rsi
__int64 result; // rax
size_t v4; // rbx
unsigned __int64 v5; // rcx
size_t v6; // rdx
size_t v7; // rcx
void *v8; // rax

v2 = *(_QWORD *)(a1 + 8) + a2;
result = 1LL;
if ( *(_QWORD *)(a1 + 16) < v2 )
{
v4 = v2;
v5 = *(_QWORD *)(a1 + 24);
v6 = v2 % v5;
v7 = v2 + v5 - v2 % v5;
if ( v6 )
v4 = v7;
v8 = realloc(*(void **)a1, v4);
if ( v8 )
{
*(_QWORD *)a1 = v8;
*(_QWORD *)(a1 + 16) = v4;
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

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; // ebp

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; // ebp

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_363, 1uLL);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
return func4(a1, &unk_363, 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; // r12
char *v4; // rax
char *v5; // rbp

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; // r12
char *v4; // rax
char *v5; // rbp

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

return_type: char *


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

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

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

v1 = *_ctype_b_loc();
result = 0;
if ( (v1[*a1] & 0x400) != 0 )
{
for ( i = a1 + 1; ; ++i )
{
v4 = *i;
if ( (v1[*i] & 8) == 0 && (unsigned __int8)(v4 - 45) > 1u && v4 != 43 )
break;
}
result = v4 == 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; // rbx
const char *i; // rdi

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

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

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

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; // rax
char v2; // cl
char *v3; // rdx
char *v5; // rax
unsigned __int64 v6; // rcx
unsigned __int64 v7; // rsi
unsigned __int64 v8; // rsi

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

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

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

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
char v7; // bp
char *i; // rax
signed __int64 v9; // r12
unsigned int v10; // eax
unsigned int v11; // er15
char *v12; // rax
char v13; // r15
unsigned __int64 v15; // rax
char *v16; // rdx
unsigned __int64 v17; // rcx
int v18; // eax
char v19; // r15
char *v20; // rax
char v21; // r15
char *v22; // rax
char v23; // r15
char *v24; // rsi
char v25; // r15
unsigned __int64 v26; // rcx
unsigned __int64 v27; // rax
char v28; // r15

v4 = a2;
v6 = *_ctype_b_loc();
while ( 1 )
{
v7 = *s;
if ( (v6[*s] & 0x2000) == 0 )
break;
++s;
}
if ( !v7 )
return (unsigned int)lslinks_bytes_append_str(a3, a2);
for ( i = &s[strlen(s)]; s < i && (v6[*(i - 1)] & 0x2000) != 0; --i )
;
v9 = i - s;
LOBYTE(v10) = lslinks_is_absurl(s);
v11 = v10;
if ( (_BYTE)v10 )
return (unsigned int)lslinks_bytes_append(a3, s, v9);
if ( v7 != 47 )
{
if ( v7 != 63 )
{
if ( v7 == 35 )
{
v24 = strchr(a2, 35);
if ( !v24 )
v24 = v4;
v25 = 0;
if ( (unsigned __int8)lslinks_bytes_append_str(a3, v24) )
v25 = lslinks_bytes_append(a3, s, v9);
v11 = v25 & 1;
}
else
{
v12 = lslinks_url_path_leaf(a2);
v13 = 0;
if ( v12
&& (unsigned __int8)lslinks_bytes_append(a3, a2, v12 - a2)
&& (unsigned __int8)lslinks_bytes_append_str(a3, "/")
&& (unsigned __int8)lslinks_bytes_append(a3, s, v9) )
{
v13 = lslinks_bytes_append_nil(a3);
}
v11 = v13 & 1;
}
return v11;
}
v15 = (unsigned __int8)*a2;
if ( (unsigned __int8)v15 > 0x3Fu )
{
v16 = a2;
}
else
{
v16 = a2;
v17 = 0x8000000800000001LL;
if ( _bittest64((const __int64 *)&v17, v15) )
{
LABEL_45:
v28 = 0;
if ( (unsigned __int8)lslinks_bytes_append(a3, a2, v16 - a2) )
v28 = lslinks_bytes_append(a3, s, v9);
return v28 & 1;
}
}
v26 = 0x8000000800000001LL;
do
{
do
v27 = (unsigned __int8)*++v16;
while ( (unsigned __int8)v27 > 0x3Fu );
}
while ( !_bittest64((const __int64 *)&v26, v27) );
goto LABEL_45;
}
if ( s[1] == 47 )
{
v20 = strchr(a2, 58);
if ( v20 )
{
v21 = 0;
if ( (unsigned __int8)lslinks_bytes_append(a3, a2, v20 - a2 + 1) )
v21 = lslinks_bytes_append(a3, s, v9);
v11 = v21 & 1;
}
else
{
*_errno_location() = 22;
}
}
else
{
v18 = strncasecmp("file:", a2, 5uLL);
v19 = v18;
if ( v18 )
{
v22 = lslinks_url_path(a2);
v23 = 0;
if ( v22 && (unsigned __int8)lslinks_bytes_append(a3, a2, v22 - a2) )
v23 = lslinks_bytes_append(a3, s, v9);
v11 = v23 & 1;
}
else
{
if ( (unsigned __int8)lslinks_bytes_append_str(a3, "file://") )
v19 = lslinks_bytes_append(a3, s, v9);
v11 = v19 & 1;
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, char *a2, __int64 a3)
{
char *v4; // r13
const unsigned __int16 *v6; // r12
char v7; // bp
char *i; // rax
signed __int64 v9; // r12
unsigned int v10; // eax
unsigned int v11; // er15
char *v12; // rax
char v13; // r15
unsigned __int64 v15; // rax
char *v16; // rdx
unsigned __int64 v17; // rcx
int v18; // eax
char v19; // r15
char *v20; // rax
char v21; // r15
char *v22; // rax
char v23; // r15
char *v24; // rsi
char v25; // r15
unsigned __int64 v26; // rcx
unsigned __int64 v27; // rax
char v28; // r15

v4 = a2;
v6 = *_ctype_b_loc();
while ( 1 )
{
v7 = *s;
if ( (v6[*s] & 0x2000) == 0 )
break;
++s;
}
if ( !v7 )
return (unsigned int)lslinks_bytes_append_str(a3, a2);
for ( i = &s[strlen(s)]; s < i && (v6[*(i - 1)] & 0x2000) != 0; --i )
;
v9 = i - s;
LOBYTE(v10) = func0(s);
v11 = v10;
if ( (_BYTE)v10 )
return (unsigned int)lslinks_bytes_append(a3, s, v9);
if ( v7 != 47 )
{
if ( v7 != 63 )
{
if ( v7 == 35 )
{
v24 = strchr(a2, 35);
if ( !v24 )
v24 = v4;
v25 = 0;
if ( (unsigned __int8)lslinks_bytes_append_str(a3, v24) )
v25 = lslinks_bytes_append(a3, s, v9);
v11 = v25 & 1;
}
else
{
v12 = func3(a2);
v13 = 0;
if ( v12
&& (unsigned __int8)lslinks_bytes_append(a3, a2, v12 - a2)
&& (unsigned __int8)lslinks_bytes_append_str(a3, "/")
&& (unsigned __int8)lslinks_bytes_append(a3, s, v9) )
{
v13 = lslinks_bytes_append_nil(a3);
}
v11 = v13 & 1;
}
return v11;
}
v15 = (unsigned __int8)*a2;
if ( (unsigned __int8)v15 > 0x3Fu )
{
v16 = a2;
}
else
{
v16 = a2;
v17 = 0x8000000800000001LL;
if ( _bittest64((const __int64 *)&v17, v15) )
{
LABEL_45:
v28 = 0;
if ( (unsigned __int8)lslinks_bytes_append(a3, a2, v16 - a2) )
v28 = lslinks_bytes_append(a3, s, v9);
return v28 & 1;
}
}
v26 = 0x8000000800000001LL;
do
{
do
v27 = (unsigned __int8)*++v16;
while ( (unsigned __int8)v27 > 0x3Fu );
}
while ( !_bittest64((const __int64 *)&v26, v27) );
goto LABEL_45;
}
if ( s[1] == 47 )
{
v20 = strchr(a2, 58);
if ( v20 )
{
v21 = 0;
if ( (unsigned __int8)lslinks_bytes_append(a3, a2, v20 - a2 + 1) )
v21 = lslinks_bytes_append(a3, s, v9);
v11 = v21 & 1;
}
else
{
*_errno_location() = 22;
}
}
else
{
v18 = strncasecmp("file:", a2, 5uLL);
v19 = v18;
if ( v18 )
{
v22 = func2(a2);
v23 = 0;
if ( v22 && (unsigned __int8)lslinks_bytes_append(a3, a2, v22 - a2) )
v23 = lslinks_bytes_append(a3, s, v9);
v11 = v23 & 1;
}
else
{
if ( (unsigned __int8)lslinks_bytes_append_str(a3, "file://") )
v19 = lslinks_bytes_append(a3, s, v9);
v11 = v19 & 1;
}
}
return v11;
}

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; // dl
__int64 result; // rax
char v4; // dl
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

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

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

v2 = lslinks_bytes_init2(v5, 64LL);
result = 0LL;
if ( v2 )
{
if ( !(unsigned __int8)func4(s, a2, (__int64)v5)
|| (v4 = lslinks_bytes_append_nil(v5), result = v5[0], !v4) )
{
lslinks_bytes_cleanup(v5);
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)
{
char *v2; // r13
size_t v3; // rax
unsigned int v4; // er14
__int64 v5; // r12
__int64 v6; // rbp
char *i; // rbx
unsigned __int64 v8; // rax
unsigned int v10; // eax
char v11; // al
char v12; // dl
char v13; // cl
char v14; // al
unsigned int v15; // eax
__int16 v16; // [rsp+Dh] [rbp-3Bh] BYREF
char v17; // [rsp+Fh] [rbp-39h]

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

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

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

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 *v2; // rbp
size_t v4; // rax
unsigned int v5; // er13
const char *v7; // rbx
char v8; // si
char v9; // dl
unsigned int v10; // eax
unsigned int v11; // eax
const unsigned __int16 **v12; // rax
const unsigned __int16 *v13; // rcx
char v14; // dl
char v15; // al
int v16; // ecx
char v17; // cl
unsigned int v18; // eax
char v19[41]; // [rsp+Fh] [rbp-29h] BYREF

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

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; // dl
__int64 result; // rax
char v3; // dl
__int64 v4[5]; // [rsp+0h] [rbp-28h] BYREF

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

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

v1 = lslinks_bytes_init2(v4, 32LL);
result = 0LL;
if ( v1 )
{
if ( !(unsigned __int8)func6(a1, (__int64)v4)
|| (v3 = lslinks_bytes_append_nil(v4), result = v4[0], !v3) )
{
lslinks_bytes_cleanup(v4);
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:
char *__fastcall lslinks_path_to_url(const char *a1)
{
char *v1; // rbx
char *v2; // rax
char *v3; // r12
char *v4; // rax
char *v5; // rbp
__int64 v7; // rax
void *v8; // rbp
char v9[4136]; // [rsp+0h] [rbp-1028h] BYREF

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

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

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

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; // dl
__int64 result; // rax
char v3; // dl
__int64 v4[5]; // [rsp+0h] [rbp-28h] BYREF

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

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

v1 = lslinks_bytes_init2(v4, 32LL);
result = 0LL;
if ( v1 )
{
if ( !(unsigned __int8)func7(a1, (__int64)v4)
|| (v3 = lslinks_bytes_append_nil(v4), result = v4[0], !v3) )
{
lslinks_bytes_cleanup(v4);
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;
if ( s2[7] != 47 )
v2 = s2 + 6;
}
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;
if ( s2[7] != 47 )
v2 = s2 + 6;
}
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)
{
int result; // eax

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

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

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

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; // ebx
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; // ebx
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


uniq

original_code:
void uniq(char *str)
{
    char *p = str;
    char c;
    c = *p++;
    while (*str) {
 if (*str != c) {
     c = *str;
     *p++ = c;
 }
 str++;
    }
    *p=0;
}

variable_types:
str
char *

variable_types:
p
char *

variable_types: c char


decompiled_code:
int __fastcall construct_charclass(const char *a1)
{
int v1; // er13
int v2; // ebp
const char *v3; // rbx
int result; // eax
__int64 v5; // rax
char v6; // dl

v1 = strlen(a1);
charclass = (char *)malloc(0x80uLL);
charlen = 0;
v2 = 0;
if ( v1 > 0 )
{
while ( 1 )
{
v5 = v2;
v6 = a1[v2];
if ( !v6 )
break;
if ( v6 == 45 )
{
append_range(a1[v2 - 1], a1[v2 + 1]);
v2 += 2;
}
else
{
++v2;
append_single(a1[v5 - 1]);
}
if ( v2 >= v1 )
goto LABEL_2;
}
result = append_single(a1[v2 - 1]);
}
else
{
LABEL_2:
charclass[charlen] = 0;
qsort(charclass, charlen, 1uLL, (__compar_fn_t)intcompar);
uniq(charclass);
v3 = charclass;
result = strlen(charclass);
charlen = result;
if ( verbose )
result = printf("Character class: '%s'\n", v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
int v1; // er13
int v2; // ebp
const char *v3; // rbx
int result; // eax
__int64 v5; // rax
char v6; // dl

v1 = strlen(a1);
charclass = (char *)malloc(0x80uLL);
charlen = 0;
v2 = 0;
if ( v1 > 0 )
{
while ( 1 )
{
v5 = v2;
v6 = a1[v2];
if ( !v6 )
break;
if ( v6 == 45 )
{
func9(a1[v2 - 1], a1[v2 + 1]);
v2 += 2;
}
else
{
++v2;
func8(a1[v5 - 1]);
}
if ( v2 >= v1 )
goto LABEL_2;
}
result = func8(a1[v2 - 1]);
}
else
{
LABEL_2:
charclass[charlen] = 0;
qsort(charclass, charlen, 1uLL, (__compar_fn_t)intcompar);
func10(charclass);
v3 = charclass;
result = strlen(charclass);
charlen = result;
if ( verbose )
result = printf("Character class: '%s'\n", v3);
}
return result;
}

original_code:
void construct_charclass(char *cc)
{
    int i,j,k;
    int len = strlen(cc);
    charclass = malloc(128);
    charlen = 0;
    while (i<len) {
 switch(cc[i]) {
 case '-':
     append_range(cc[i-1], cc[i+1]);
     i+=2;
     break;
 case 0:
     append_single(cc[i-1]);
     return;
 default:
     append_single(cc[i++ - 1]);
 }
    }
    charclass[charlen] = 0;
    qsort(charclass, charlen, sizeof(char), intcompar);
    uniq(charclass);
    charlen = strlen(charclass);
    if (verbose)
 printf ("Character class: '%s'\n", charclass);
}

canonical_original_code:
void construct_charclass(char *cc)
{
    int i; int j; int k;
    int len = strlen(cc);
    charclass = malloc(128);
    charlen = 0;
    while (i<len) {
 switch(cc[i]) {
 case '-':
     append_range(cc[i-1], cc[i+1]);
     i+=2;
     break;
 case 0:
     append_single(cc[i-1]);
     return;
 default:
     append_single(cc[i++ - 1]);
 }
    }
    charclass[charlen] = 0;
    qsort(charclass, charlen, sizeof(char), intcompar);
    uniq(charclass);
    charlen = strlen(charclass);
    if (verbose)
 printf ("Character class: '%s'\n", charclass);
}

variable_types:
cc
char *

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: len int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"usage: %s [-l length] [-c charclass]\n"
"where:\n"
" length is the length of desired password (0<length<256)\n"
" charclass is character class, e.g. acg-kz => acghijkz\n",
progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func12()
{
fprintf(
stderr,
"usage: %s [-l length] [-c charclass]\n"
"where:\n"
" length is the length of desired password (0<length<256)\n"
" charclass is character class, e.g. acg-kz => acghijkz\n",
progname);
exit(1);
}

original_code:
void usage()
{
    fprintf (stderr, "usage: %s [-l length] [-c charclass]\n"
      "where:\n"
      "  length is the length of desired password (0<length<256)\n"
      "  charclass is character class, e.g. acg-kz => acghijkz\n", progname);
    exit(1);
}


calculateIndex

decompiled_code:
unsigned __int64 __fastcall calculateIndex(__int64 a1, int a2)
{
return a2 & (unsigned __int64)(a1 - 1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, int a2)
{
return a2 & (unsigned __int64)(a1 - 1);
}

original_code:
static inline size_t calculateIndex(size_t bucketCount, int hash) {
    return ((size_t) hash) & (bucketCount - 1);
}

canonical_original_code:
static inline unsigned long calculateIndex(unsigned long bucketCount, int hash) {
    return ((unsigned long) hash) & (bucketCount - 1);
}

variable_types:
bucketCount
unsigned long

variable_types: hash int

return_type: unsigned long


equalKeys

decompiled_code:
__int64 __fastcall equalKeys(__int64 a1, int a2, __int64 a3, int a4, __int64 (__fastcall *a5)(__int64, __int64, _QWORD))
{
unsigned int v7; // edx

if ( a1 == a3 )
return 1;
v7 = 0;
if ( a2 == a4 )
return a5(a1, a3, 0LL);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3, int a4, __int64 (__fastcall *a5)(__int64, __int64, _QWORD))
{
unsigned int v7; // edx

if ( a1 == a3 )
return 1;
v7 = 0;
if ( a2 == a4 )
return a5(a1, a3, 0LL);
return v7;
}

original_code:
static inline _Bool equalKeys(void* keyA, int hashA, void* keyB, int hashB,
        _Bool (*equals)(void*, void*)) {
    if (keyA == keyB) {
        return 1;
    }
    if (hashA != hashB) {
        return 0;
    }
    return equals(keyA, keyB);
}

canonical_original_code:
static inline _Bool equalKeys(void *keyA, int hashA, void *keyB, int hashB, _Bool (*equals)(void *, void *)) {
    if (keyA == keyB) {
        return 1;
    }
    if (hashA != hashB) {
        return 0;
    }
    return equals(keyA, keyB);
}

variable_types:
keyA
void *

variable_types: hashA int

variable_types:
keyB
void *

variable_types: hashB int

variable_types:
equals
_Bool (*)(void *, void *)


expandIfNecessary

original_code:
static void expandIfNecessary(Hashmap* map) {
    if (map->size > (map->bucketCount * 3 / 4)) {
        size_t newBucketCount = map->bucketCount << 1;
        Entry** newBuckets = calloc(newBucketCount, sizeof(Entry*));
        if (newBuckets == ((void *)0)) {
            return;
        }
        size_t i;
        for (i = 0; i < map->bucketCount; i++) {
            Entry* entry = map->buckets[i];
            while (entry != ((void *)0)) {
                Entry* next = entry->next;
                size_t index = calculateIndex(newBucketCount, entry->hash);
                entry->next = newBuckets[index];
                newBuckets[index] = entry;
                entry = next;
            }
        }
        free(map->buckets);
        map->buckets = newBuckets;
        map->bucketCount = newBucketCount;
    }
}

canonical_original_code:
static void expandIfNecessary(struct _Hashmap *map) {
    if (map->size > (map->bucketCount * 3 / 4)) {
        unsigned long newBucketCount = map->bucketCount << 1;
        struct _Entry **newBuckets = calloc(newBucketCount, sizeof(Entry*));
        if (newBuckets == ((void *)0)) {
            return;
        }
        unsigned long i;
        for (i = 0; i < map->bucketCount; i++) {
            struct _Entry *entry = map->buckets[i];
            while (entry != ((void *)0)) {
                struct _Entry *next = entry->next;
                unsigned long index = calculateIndex(newBucketCount, entry->hash);
                entry->next = newBuckets[index];
                newBuckets[index] = entry;
                entry = next;
            }
        }
        free(map->buckets);
        map->buckets = newBuckets;
        map->bucketCount = newBucketCount;
    }
}

variable_types: struct _Hashmap { struct _Entry { void *key; int hash; void *value; struct _Entry *next; } **buckets; unsigned long bucketCount; int (*hash)(void *key); _Bool (*equals)(void *keyA, void *keyB); unsigned long size; } *

variable_types:
newBucketCount
unsigned long

variable_types:
i
unsigned long

variable_types:
index
unsigned long

user_defined_types: struct _Hashmap { struct _Entry **buckets; unsigned long bucketCount; int (*hash)(void *key); _Bool (*equals)(void *keyA, void *keyB); unsigned long size; }


hashmapSize

decompiled_code:
__int64 __fastcall hashmapSize(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
size_t hashmapSize(Hashmap* map) {
    return map->size;
}

canonical_original_code:
unsigned long hashmapSize(struct _Hashmap *map) {
    return map->size;
}

user_defined_types: struct _Entry { void *key; int hash; void *value; struct _Entry *next; }


hashmapLock

decompiled_code:
void hashmapLock()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void hashmapLock(Hashmap* map) {
}

canonical_original_code:
void hashmapLock(struct _Hashmap *map) {
}


hashmapUnlock

decompiled_code:
void hashmapUnlock()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void hashmapUnlock(Hashmap* map) {
}

canonical_original_code:
void hashmapUnlock(struct _Hashmap *map) {
}


hashmapFree

decompiled_code:
void __fastcall hashmapFree(void *ptr)
{
unsigned __int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[3];
free(v4);
}
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
unsigned __int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)ptr + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[3];
free(v4);
}
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}

original_code:
void hashmapFree(Hashmap* map) {
    size_t i;
    for (i = 0; i < map->bucketCount; i++) {
        Entry* entry = map->buckets[i];
        while (entry != ((void *)0)) {
            Entry* next = entry->next;
            free(entry);
            entry = next;
        }
    }
    free(map->buckets);
    free(map);
}

canonical_original_code:
void hashmapFree(struct _Hashmap *map) {
    unsigned long i;
    for (i = 0; i < map->bucketCount; i++) {
        struct _Entry *entry = map->buckets[i];
        while (entry != ((void *)0)) {
            struct _Entry *next = entry->next;
            free(entry);
            entry = next;
        }
    }
    free(map->buckets);
    free(map);
}

variable_types: struct _Entry { void *key; int hash; void *value; struct _Entry *next; } *


hashmapHash

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

result = (unsigned int)a2;
if ( a2 )
{
v3 = &a1[a2];
do
result = (unsigned int)(31 * result + *a1++);
while ( v3 != a1 );
}
return result;
}

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

result = (unsigned int)a2;
if ( a2 )
{
v3 = &a1[a2];
do
result = (unsigned int)(31 * result + *a1++);
while ( v3 != a1 );
}
return result;
}

original_code:
int hashmapHash(void* key, size_t keySize) {
    int h = keySize;
    char* data = (char*) key;
    size_t i;
    for (i = 0; i < keySize; i++) {
        h = h * 31 + *data;
        data++;
    }
    return h;
}

canonical_original_code:
int hashmapHash(void *key, unsigned long keySize) {
    int h = keySize;
    char *data = (char*) key;
    unsigned long i;
    for (i = 0; i < keySize; i++) {
        h = h * 31 + *data;
        data++;
    }
    return h;
}

variable_types:
key
void *

variable_types:
keySize
unsigned long

variable_types: h int

variable_types:
data
char *


hashmapGet

original_code:
void* hashmapGet(Hashmap* map, void* key) {
    int hash = hashKey(map, key);
    size_t index = calculateIndex(map->bucketCount, hash);
    Entry* entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return entry->value;
        }
        entry = entry->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashmapGet(struct _Hashmap *map, void *key) {
    int hash = hashKey(map, key);
    unsigned long index = calculateIndex(map->bucketCount, hash);
    struct _Entry *entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return entry->value;
        }
        entry = entry->next;
    }
    return ((void *)0);
}

return_type: void *


hashmapContainsKey

decompiled_code:
__int64 __fastcall hashmapContainsKey(__int64 a1, __int64 a2)
{
int v2; // er12
__int64 v3; // rbx
__int64 result; // rax

v2 = hashKey(a1, a2);
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * calculateIndex(*(_QWORD *)(a1 + 8), v2));
if ( !v3 )
return 0LL;
do
{
result = equalKeys(
*(_QWORD *)v3,
*(_DWORD *)(v3 + 8),
a2,
v2,
*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24));
if ( (_BYTE)result )
break;
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // er12
__int64 v3; // rbx
__int64 result; // rax

v2 = func0(a1, a2);
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * func1(*(_QWORD *)(a1 + 8), v2));
if ( !v3 )
return 0LL;
do
{
result = func2(
*(_QWORD *)v3,
*(_DWORD *)(v3 + 8),
a2,
v2,
*(__int64 (__fastcall **)(__int64, __int64, _QWORD))(a1 + 24));
if ( (_BYTE)result )
break;
v3 = *(_QWORD *)(v3 + 24);
}
while ( v3 );
return result;
}

original_code:
_Bool hashmapContainsKey(Hashmap* map, void* key) {
    int hash = hashKey(map, key);
    size_t index = calculateIndex(map->bucketCount, hash);
    Entry* entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return 1;
        }
        entry = entry->next;
    }
    return 0;
}

canonical_original_code:
_Bool hashmapContainsKey(struct _Hashmap *map, void *key) {
    int hash = hashKey(map, key);
    unsigned long index = calculateIndex(map->bucketCount, hash);
    struct _Entry *entry = map->buckets[index];
    while (entry != ((void *)0)) {
        if (equalKeys(entry->key, entry->hash, key, hash, map->equals)) {
            return 1;
        }
        entry = entry->next;
    }
    return 0;
}


hashmapRemove

original_code:
void* hashmapRemove(Hashmap* map, void* key) {
    int hash = hashKey(map, key);
    size_t index = calculateIndex(map->bucketCount, hash);
    Entry** p = &(map->buckets[index]);
    Entry* current;
    while ((current = *p) != ((void *)0)) {
        if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
            void* value = current->value;
            *p = current->next;
            free(current);
            map->size--;
            return value;
        }
        p = &current->next;
    }
    return ((void *)0);
}

canonical_original_code:
void *hashmapRemove(struct _Hashmap *map, void *key) {
    int hash = hashKey(map, key);
    unsigned long index = calculateIndex(map->bucketCount, hash);
    struct _Entry **p = &(map->buckets[index]);
    struct _Entry *current;
    while ((current = *p) != ((void *)0)) {
        if (equalKeys(current->key, current->hash, key, hash, map->equals)) {
            void *value = current->value;
            *p = current->next;
            free(current);
            map->size--;
            return value;
        }
        p = &current->next;
    }
    return ((void *)0);
}

variable_types: struct _Entry { void *key; int hash; void *value; struct _Entry *next; } **

variable_types:
value
void *


hashmapForEach

decompiled_code:
void __fastcall hashmapForEach(_QWORD *a1, unsigned __int8 (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 v4; // r14
_QWORD *v5; // rbx

if ( a1[1] )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*a1 + 8 * v4);
if ( v5 )
break;
LABEL_6:
if ( a1[1] <= (unsigned __int64)++v4 )
return;
}
while ( a2(*v5, v5[2], a3) )
{
v5 = (_QWORD *)v5[3];
if ( !v5 )
goto LABEL_6;
}
}
}

canonical_decompiled_code:
void __fastcall func12(_QWORD *a1, unsigned __int8 (__fastcall *a2)(_QWORD, _QWORD, __int64), __int64 a3)
{
__int64 v4; // r14
_QWORD *v5; // rbx

if ( a1[1] )
{
v4 = 0LL;
while ( 1 )
{
v5 = *(_QWORD **)(*a1 + 8 * v4);
if ( v5 )
break;
LABEL_6:
if ( a1[1] <= (unsigned __int64)++v4 )
return;
}
while ( a2(*v5, v5[2], a3) )
{
v5 = (_QWORD *)v5[3];
if ( !v5 )
goto LABEL_6;
}
}
}

original_code:
void hashmapForEach(Hashmap* map,
        _Bool (*callback)(void* key, void* value, void* context),
        void* context) {
    size_t i;
    for (i = 0; i < map->bucketCount; i++) {
        Entry* entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (!callback(entry->key, entry->value, context)) {
                return;
            }
            entry = entry->next;
        }
    }
}

canonical_original_code:
void hashmapForEach(struct _Hashmap *map, _Bool (*callback)(void *key, void *value, void *context), void *context) {
    unsigned long i;
    for (i = 0; i < map->bucketCount; i++) {
        struct _Entry *entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (!callback(entry->key, entry->value, context)) {
                return;
            }
            entry = entry->next;
        }
    }
}

variable_types: _Bool (*)(void *key, void *value, void *context)

variable_types:
context
void *


hashmapCurrentCapacity

decompiled_code:
unsigned __int64 __fastcall hashmapCurrentCapacity(__int64 a1)
{
return (unsigned __int64)(3LL * *(_QWORD *)(a1 + 8)) >> 2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(__int64 a1)
{
return (unsigned __int64)(3LL * *(_QWORD *)(a1 + 8)) >> 2;
}

original_code:
size_t hashmapCurrentCapacity(Hashmap* map) {
    size_t bucketCount = map->bucketCount;
    return bucketCount * 3 / 4;
}

canonical_original_code:
unsigned long hashmapCurrentCapacity(struct _Hashmap *map) {
    unsigned long bucketCount = map->bucketCount;
    return bucketCount * 3 / 4;
}

variable_types:
bucketCount
unsigned long


hashmapCountCollisions

original_code:
size_t hashmapCountCollisions(Hashmap* map) {
    size_t collisions = 0;
    size_t i;
    for (i = 0; i < map->bucketCount; i++) {
        Entry* entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (entry->next != ((void *)0)) {
                collisions++;
            }
            entry = entry->next;
        }
    }
    return collisions;
}

canonical_original_code:
unsigned long hashmapCountCollisions(struct _Hashmap *map) {
    unsigned long collisions = 0;
    unsigned long i;
    for (i = 0; i < map->bucketCount; i++) {
        struct _Entry *entry = map->buckets[i];
        while (entry != ((void *)0)) {
            if (entry->next != ((void *)0)) {
                collisions++;
            }
            entry = entry->next;
        }
    }
    return collisions;
}

variable_types:
collisions
unsigned long


hashmapIntHash

decompiled_code:
__int64 __fastcall hashmapIntHash(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int *a1)
{
return *a1;
}

original_code:
int hashmapIntHash(void* key) {
    return *((int*) key);
}

canonical_original_code:
int hashmapIntHash(void *key) {
    return *((int *) key);
}


hashmapIntEquals

decompiled_code:
bool __fastcall hashmapIntEquals(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
bool __fastcall func16(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
_Bool hashmapIntEquals(void* keyA, void* keyB) {
    int a = *((int*) keyA);
    int b = *((int*) keyB);
    return a == b;
}

canonical_original_code:
_Bool hashmapIntEquals(void *keyA, void *keyB) {
    int a = *((int*) keyA);
    int b = *((int*) keyB);
    return a == b;
}

variable_types:
keyA
void *

variable_types:
keyB
void *

variable_types: a int

variable_types: b int


push

decompiled_code:
__int64 __fastcall push(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
__int64 v5; // rax
__int64 v6; // r12
_QWORD *v8; // rax

v5 = hash_lookup(a1 + 1);
if ( v5 )
{
v6 = v5;
v3 = compute_distance(*a1, a3);
rbtree_rm(a1, *(_QWORD *)(v6 + 8));
*(_QWORD *)(v6 + 8) = a3;
}
else
{
v8 = malloc(0x18uLL);
*v8 = a2;
v8[1] = a3;
hash_add(a1 + 1, v8);
}
rbtree_add(a1, a3);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r14
__int64 v5; // rax
__int64 v6; // r12
_QWORD *v8; // rax

v5 = hash_lookup(a1 + 1);
if ( v5 )
{
v6 = v5;
v3 = compute_distance(*a1, a3);
rbtree_rm(a1, *(_QWORD *)(v6 + 8));
*(_QWORD *)(v6 + 8) = a3;
}
else
{
v8 = malloc(0x18uLL);
*v8 = a2;
v8[1] = a3;
hash_add(a1 + 1, v8);
}
rbtree_add(a1, a3);
return v3;
}

original_code:
ref_num_t push (lru_stack_t *stack, cbn_t cbn, ref_num_t ref_num) {
    ht_entry_t *res = hash_lookup(stack->ht, cbn);
    ref_num_t dist;
    if (res) {
        dist = compute_distance(stack->tree, ref_num);
        rbtree_rm(&stack->tree, res->ref_num);
        res->ref_num = ref_num;
    } else {
        ht_entry_t *entry = malloc(sizeof(ht_entry_t));
        entry->cbn = cbn;
        entry->ref_num = ref_num;
        hash_add(stack->ht, entry);
    }
    rbtree_add(&stack->tree, ref_num);
    return dist;
}

canonical_original_code:
unsigned long push(struct lru_stack_s *stack, unsigned long cbn, unsigned long ref_num) {
    struct ht_entry_s *res = hash_lookup(stack->ht, cbn);
    unsigned long dist;
    if (res) {
        dist = compute_distance(stack->tree, ref_num);
        rbtree_rm(&stack->tree, res->ref_num);
        res->ref_num = ref_num;
    } else {
        struct ht_entry_s *entry = malloc(sizeof(ht_entry_t));
        entry->cbn = cbn;
        entry->ref_num = ref_num;
        hash_add(stack->ht, entry);
    }
    rbtree_add(&stack->tree, ref_num);
    return dist;
}

variable_types: struct lru_stack_s { struct rbtree { unsigned long ref_num; char color_field; struct rbtree *left; struct rbtree *right; } *tree; struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *ht[512]; } *

variable_types:
cbn
unsigned long

variable_types:
dist
unsigned long

user_defined_types: struct lru_stack_s { struct rbtree *tree; struct ht_entry_s *ht[512]; }


decompiled_code:
__int64 __fastcall init_lru_stack(__int64 a1)
{
return init_ht(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return init_ht(a1 + 8);
}

original_code:
void init_lru_stack (lru_stack_t *stack) {
    init_ht(stack->ht);
}

canonical_original_code:
void init_lru_stack(struct lru_stack_s *stack) {
    init_ht(stack->ht);
}

user_defined_types: struct rbtree { unsigned long ref_num; char color_field; struct rbtree *left; struct rbtree *right; }

user_defined_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; }


decompiled_code:
__int64 __fastcall delete_lru_stack(_QWORD *a1)
{
delete_ht(a1 + 1);
return delete_rbtree(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
delete_ht(a1 + 1);
return delete_rbtree(*a1);
}

original_code:
void delete_lru_stack (lru_stack_t *stack) {
    delete_ht(stack->ht);
    delete_rbtree(stack->tree);
}

canonical_original_code:
void delete_lru_stack(struct lru_stack_s *stack) {
    delete_ht(stack->ht);
    delete_rbtree(stack->tree);
}


decompiled_code:
__int64 __fastcall ht_entry_hash_function(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
uint64_t ht_entry_hash_function(ht_entry_t *e) {
    return(e->cbn);
}

canonical_original_code:
unsigned long ht_entry_hash_function(struct ht_entry_s *e) {
    return(e->cbn);
}

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_is_member(__int64 a1, __int64 a2)
{
__int64 result; // rax

for ( LOBYTE(result) = a1 != 0; a2 != a1 && a1; LOBYTE(result) = a1 != 0 )
a1 = *(_QWORD *)(a1 + 16);
return (unsigned __int8)result;
}

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

for ( LOBYTE(result) = a1 != 0; a2 != a1 && a1; LOBYTE(result) = a1 != 0 )
a1 = *(_QWORD *)(a1 + 16);
return (unsigned __int8)result;
}

original_code: int sglib_ht_entry_t_is_member(ht_entry_t *list, ht_entry_t *elem) { int result; { ht_entry_t *_p_; for(_p_ = (list); _p_!=((void *)0) && _p_ != (elem); _p_= _p_->next) ; (result) = (_p_!=((void *)0));}; return(result); }

canonical_original_code: int sglib_ht_entry_t_is_member(struct ht_entry_s *list, struct ht_entry_s *elem) { int result; { struct ht_entry_s *_p_; for(_p_ = (list); _p_!=((void *)0) && _p_ != (elem); _p_= _p_->next) ; (result) = (_p_!=((void *)0));}; return(result); }

variable_types:
elem
struct ht_entry_s *

variable_types: result int


decompiled_code:
_BOOL8 __fastcall sglib_ht_entry_t_add_if_not_member(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_4;
}
*a3 = v3;
}
else
{
LABEL_4:
*a3 = 0LL;
a2[2] = *a1;
*a1 = a2;
}
return *a3 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_4;
}
*a3 = v3;
}
else
{
LABEL_4:
*a3 = 0LL;
a2[2] = *a1;
*a1 = a2;
}
return *a3 == 0LL;
}

original_code: int sglib_ht_entry_t_add_if_not_member(ht_entry_t **list, ht_entry_t *elem, ht_entry_t **member) { { ht_entry_t *_p_; for(_p_ = (*list); _p_!=((void *)0) && (_p_->cbn - (elem)->cbn) != 0; _p_= _p_->next) ; (*member) = _p_; if (_p_ == ((void *)0)) { { (elem)->next = (*list); (*list) = (elem);}; }}; return(*member==((void *)0)); }

canonical_original_code: int sglib_ht_entry_t_add_if_not_member(struct ht_entry_s **list, struct ht_entry_s *elem, struct ht_entry_s **member) { { struct ht_entry_s *_p_; for(_p_ = (*list); _p_!=((void *)0) && (_p_->cbn - (elem)->cbn) != 0; _p_= _p_->next) ; (*member) = _p_; if (_p_ == ((void *)0)) { { (elem)->next = (*list); (*list) = (elem);}; }}; return(*member==((void *)0)); }

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } **

variable_types:
member
struct ht_entry_s **


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_delete(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 result; // rax

v2 = *a1;
if ( a2 != *a1 && v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 != a2 && v2 );
a1 = (__int64 *)(v3 + 16);
}
if ( !v2 )
_assert_fail(
"*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL",
"hash_table.c",
0x16u,
"sglib_ht_entry_t_delete");
result = *(_QWORD *)(v2 + 16);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 result; // rax

v2 = *a1;
if ( a2 != *a1 && v2 )
{
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 16);
}
while ( v2 != a2 && v2 );
a1 = (__int64 *)(v3 + 16);
}
if ( !v2 )
_assert_fail(
"*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL",
"hash_table.c",
0x16u,
"sglib_ht_entry_t_delete");
result = *(_QWORD *)(v2 + 16);
*a1 = result;
return result;
}

original_code: void sglib_ht_entry_t_delete(ht_entry_t **list, ht_entry_t *elem) { { ht_entry_t **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && *_p_!=(elem); _p_= &(*_p_)->next) ; ((void) sizeof ((*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ? 1 : 0), __extension__ ({ if (*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ; else __assert_fail ("*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL", "hash_table.c", 22, __extension__ __PRETTY_FUNCTION__); })); *_p_ = (*_p_)->next;}; }

canonical_original_code: void sglib_ht_entry_t_delete(struct ht_entry_s **list, struct ht_entry_s *elem) { { struct ht_entry_s **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && *_p_!=(elem); _p_= &(*_p_)->next) ; ((void) sizeof ((*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ? 1 : 0), __extension__ ({ if (*_p_!=((void *)0) && "element is not member of the container, use DELETE_IF_MEMBER instead"!=((void *)0)) ; else __assert_fail ("*_p_!=NULL && \"element is not member of the container, use DELETE_IF_MEMBER instead\"!=NULL", "hash_table.c", 22, __extension__ __PRETTY_FUNCTION__); })); *_p_ = (*_p_)->next;}; }


decompiled_code:
_BOOL8 __fastcall sglib_ht_entry_t_delete_if_member(_QWORD **a1, _QWORD *a2, _QWORD *a3)
{
_QWORD *v3; // rax

v3 = *a1;
if ( *a1 )
{
while ( *v3 != *a2 )
{
a1 = (_QWORD **)(v3 + 2);
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_4;
}
*a3 = v3;
*a1 = (_QWORD *)v3[2];
}
else
{
LABEL_4:
*a3 = 0LL;
}
return *a3 != 0LL;
}

original_code: int sglib_ht_entry_t_delete_if_member(ht_entry_t **list, ht_entry_t *elem, ht_entry_t **member) { { ht_entry_t **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && ((*_p_)->cbn - (elem)->cbn) != 0; _p_= &(*_p_)->next) ; (*member) = *_p_; if (*_p_ != ((void *)0)) { *_p_ = (*_p_)->next; }}; return(*member!=((void *)0)); }

canonical_original_code: int sglib_ht_entry_t_delete_if_member(struct ht_entry_s **list, struct ht_entry_s *elem, struct ht_entry_s **member) { { struct ht_entry_s **_p_; for(_p_ = &(*list); *_p_!=((void *)0) && ((*_p_)->cbn - (elem)->cbn) != 0; _p_= &(*_p_)->next) ; (*member) = *_p_; if (*_p_ != ((void *)0)) { *_p_ = (*_p_)->next; }}; return(*member!=((void *)0)); }


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = *(_QWORD *)(a1 + 16);
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = *(_QWORD *)(a1 + 16);
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

original_code: int sglib_ht_entry_t_len(ht_entry_t *list) { int res; { ht_entry_t *_ce_; (res) = 0; { ht_entry_t *_ne_; ht_entry_t *_ce_; (_ce_) = (list); while ((_ce_)!=((void *)0)) { _ne_ = (_ce_)->next; {(res)++;}; (_ce_) = _ne_; }};}; return(res); }

canonical_original_code: int sglib_ht_entry_t_len(struct ht_entry_s *list) { int res; { struct ht_entry_s *_ce_; (res) = 0; { struct ht_entry_s *_ne_; struct ht_entry_s *_ce_; (_ce_) = (list); while ((_ce_)!=((void *)0)) { _ne_ = (_ce_)->next; {(res)++;}; (_ce_) = _ne_; }};}; return(res); }

variable_types: res int


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_current(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code: ht_entry_t *sglib_ht_entry_t_it_current(struct sglib_ht_entry_t_iterator *it) { return(it->currentelem); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_current(struct sglib_ht_entry_t_iterator *it) { return(it->currentelem); }

variable_types: struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; } *

return_type: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *


original_code: ht_entry_t *sglib_ht_entry_t_it_next(struct sglib_ht_entry_t_iterator *it) { ht_entry_t *ce, *eq; int (*scp)(ht_entry_t *, ht_entry_t *); ce = it->nextelem; it->nextelem = ((void *)0); if (it->subcomparator != ((void *)0)) { eq = it->equalto; scp = it->subcomparator; while (ce!=((void *)0) && scp(ce, eq)!=0) ce = ce->next; } it->currentelem = ce; if (ce != ((void *)0)) it->nextelem = ce->next; return(ce); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_next(struct sglib_ht_entry_t_iterator *it) { struct ht_entry_s *ce; struct ht_entry_s *eq; int (*scp)(struct ht_entry_s *, struct ht_entry_s *); ce = it->nextelem; it->nextelem = ((void *)0); if (it->subcomparator != ((void *)0)) { eq = it->equalto; scp = it->subcomparator; while (ce!=((void *)0) && scp(ce, eq)!=0) ce = ce->next; } it->currentelem = ce; if (ce != ((void *)0)) it->nextelem = ce->next; return(ce); }

variable_types: int (*)(struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *, struct ht_entry_s *)

user_defined_types: struct sglib_ht_entry_t_iterator { struct ht_entry_s *currentelem; struct ht_entry_s *nextelem; int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *); struct ht_entry_s *equalto; }


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_init_on_equal(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
a1[2] = a3;
a1[3] = a4;
a1[1] = a2;
return sglib_ht_entry_t_it_next(a1);
}

original_code: ht_entry_t *sglib_ht_entry_t_it_init_on_equal(struct sglib_ht_entry_t_iterator *it, ht_entry_t *list, int (*subcomparator)(ht_entry_t *, ht_entry_t *), ht_entry_t *equalto) { it->subcomparator = subcomparator; it->equalto = equalto; it->nextelem = list; return(sglib_ht_entry_t_it_next(it)); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_init_on_equal(struct sglib_ht_entry_t_iterator *it, struct ht_entry_s *list, int (*subcomparator)(struct ht_entry_s *, struct ht_entry_s *), struct ht_entry_s *equalto) { it->subcomparator = subcomparator; it->equalto = equalto; it->nextelem = list; return(sglib_ht_entry_t_it_next(it)); }

variable_types:
list
struct ht_entry_s *

variable_types: int (*)(struct ht_entry_s *, struct ht_entry_s *)

variable_types:
equalto
struct ht_entry_s *


decompiled_code:
__int64 __fastcall sglib_ht_entry_t_it_init(_QWORD *a1, __int64 a2)
{
return sglib_ht_entry_t_it_init_on_equal(a1, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, __int64 a2)
{
return func12(a1, a2, 0LL, 0LL);
}

original_code: ht_entry_t *sglib_ht_entry_t_it_init(struct sglib_ht_entry_t_iterator *it, ht_entry_t *list) { return(sglib_ht_entry_t_it_init_on_equal(it, list, ((void *)0), ((void *)0))); }

canonical_original_code: struct ht_entry_s *sglib_ht_entry_t_it_init(struct sglib_ht_entry_t_iterator *it, struct ht_entry_s *list) { return(sglib_ht_entry_t_it_init_on_equal(it, list, ((void *)0), ((void *)0))); }


decompiled_code:
_BOOL8 __fastcall sglib_hashed_ht_entry_t_add_if_not_member(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int16 v4; // ax

v4 = ht_entry_hash_function((__int64)a2);
return sglib_ht_entry_t_add_if_not_member((_QWORD **)(a1 + 8LL * (v4 & 0x1FF)), a2, a3);
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1, _QWORD *a2, _QWORD *a3)
{
__int16 v4; // ax

v4 = func0((__int64)a2);
return func2((_QWORD **)(a1 + 8LL * (v4 & 0x1FF)), a2, a3);
}

original_code: int sglib_hashed_ht_entry_t_add_if_not_member(ht_entry_t *table[512], ht_entry_t *elem, ht_entry_t **member) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_add_if_not_member(&(table)[i], elem, member)); }

canonical_original_code: int sglib_hashed_ht_entry_t_add_if_not_member(struct ht_entry_s *table[512], struct ht_entry_s *elem, struct ht_entry_s **member) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); return(sglib_ht_entry_t_add_if_not_member(&(table)[i], elem, member)); }

variable_types: struct ht_entry_s { unsigned long cbn; unsigned long ref_num; struct ht_entry_s *next; } *[512]

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall sglib_hashed_ht_entry_t_delete(__int64 a1, __int64 a2)
{
__int16 v2; // ax

v2 = ht_entry_hash_function(a2);
return sglib_ht_entry_t_delete((__int64 *)(a1 + 8LL * (v2 & 0x1FF)), a2);
}

original_code: void sglib_hashed_ht_entry_t_delete(ht_entry_t *table[512], ht_entry_t *elem) { unsigned i; i = ((unsigned)ht_entry_hash_function(elem)) % (512); sglib_ht_entry_t_delete(&(table)[i], elem); }

canonical_original_code: void sglib_hashed_ht_entry_t_delete(struct ht_entry_s *table[512], struct ht_entry_s *elem) { unsigned int i; i = ((unsigned int)ht_entry_hash_function(elem)) % (512); sglib_ht_entry_t_delete(&(table)[i], elem); }