decompiled_code:
__int64 close_entrydb()
{
__int64 result; // rax

result = sqlite3_close(entrydb);
entrydb = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

result = sqlite3_close(entrydb);
entrydb = 0LL;
return result;
}

original_code:
void close_entrydb (void)
{
 sqlite3_close (entrydb);
 entrydb = ((void *)0);
}

canonical_original_code:
void close_entrydb()
{
 sqlite3_close (entrydb);
 entrydb = ((void *)0);
}


repo: terrop/atrfs

decompiled_code:
void __fastcall entrydb_ensure_exists(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
void *v6; // rbx
char v7; // [rsp+0h] [rbp-18h]

v6 = (void *)database_get(entrydb, a1, "sha1", a4, a5, a6, v7);
if ( !v6 )
entrydb_exec(0LL, "INSERT INTO Files (sha1) VALUES (\"%s\");", a1);
free(v6);
}

canonical_decompiled_code:
void __fastcall func6(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
void *v6; // rbx
char v7; // [rsp+0h] [rbp-18h]

v6 = (void *)func3(entrydb, a1, "sha1", a4, a5, a6, v7);
if ( !v6 )
func2(0LL, "INSERT INTO Files (sha1) VALUES (\"%s\");", a1);
free(v6);
}

original_code:
void entrydb_ensure_exists (char *sha1)
{
 char *val = database_get (entrydb, sha1, "sha1");
 if (! val)
 {
  entrydb_exec (((void *)0), "INSERT INTO Files (sha1) VALUES (\"%s\");", sha1);
 }
 free (val);
}

canonical_original_code:
void entrydb_ensure_exists(char *sha1)
{
 char *val = database_get (entrydb, sha1, "sha1");
 if (! val)
 {
  entrydb_exec (((void *)0), "INSERT INTO Files (sha1) VALUES (\"%s\");", sha1);
 }
 free (val);
}

variable_types:
val
char *

return_type: void


decompiled_code:
__int64 __fastcall entrydb_get(__int64 a1, const char *a2)
{
char v2; // bl
__int64 result; // rax
__int64 v5; // rcx
const char *v6; // rsi
__int64 v7; // r8
__int64 v8; // r9
char v9; // [rsp-8h] [rbp-8h]

result = entrydb;
if ( entrydb )
{
v9 = v2;
v6 = (const char *)get_sha1_fast(*(char **)(a1 + 48));
if ( !v6 )
abort();
result = database_get(entrydb, v6, a2, v5, v7, v8, v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
char v2; // bl
__int64 result; // rax
__int64 v5; // rcx
const char *v6; // rsi
__int64 v7; // r8
__int64 v8; // r9
char v9; // [rsp-8h] [rbp-8h]

result = entrydb;
if ( entrydb )
{
v9 = v2;
v6 = (const char *)func1(*(char **)(a1 + 48));
if ( !v6 )
abort();
result = func3(entrydb, v6, a2, v5, v7, v8, v9);
}
return result;
}

original_code:
char *entrydb_get (struct atrfs_entry *ent, char *attr)
{
 char *val = ((void *)0);
 if (entrydb)
 {
  char *sha1 = get_sha1_fast ((((struct atrfs_file_entry *)(ent))->real_path));
  if (! sha1)
   abort ();
  val = database_get (entrydb, sha1, attr);
 }
 return val;
}

canonical_original_code:
char *entrydb_get(struct atrfs_entry *ent, char *attr)
{
 char *val = ((void *)0);
 if (entrydb)
 {
  char *sha1 = get_sha1_fast ((((struct atrfs_file_entry *)(ent))->real_path));
  if (! sha1)
   abort ();
  val = database_get (entrydb, sha1, attr);
 }
 return val;
}

variable_types: struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); } *ops; } *

variable_types:
attr
char *

return_type: char *

user_defined_types: struct atrfs_entry { enum atrfs_entry_type e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops *ops; }

user_defined_types: struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); }

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


decompiled_code:
void __fastcall entrydb_put(__int64 a1, const char *a2, const char *a3)
{
const char *v4; // rax

if ( entrydb )
{
v4 = (const char *)get_sha1(*(_QWORD *)(a1 + 48));
entrydb_exec(0LL, "UPDATE Files SET %s = \"%s\" WHERE sha1=\"%s\";", a2, a3, v4);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, const char *a2, const char *a3)
{
const char *v4; // rax

if ( entrydb )
{
v4 = (const char *)get_sha1(*(_QWORD *)(a1 + 48));
func2(0LL, "UPDATE Files SET %s = \"%s\" WHERE sha1=\"%s\";", a2, a3, v4);
}
}

original_code:
void entrydb_put (struct atrfs_entry *ent, char *attr, char *val)
{
 if (entrydb)
 {
  char *sha1 = get_sha1 ((((struct atrfs_file_entry *)(ent))->real_path));
  entrydb_exec (((void *)0), "UPDATE Files SET %s = \"%s\" WHERE sha1=\"%s\";", attr, val, sha1);
 }
}

canonical_original_code:
void entrydb_put(struct atrfs_entry *ent, char *attr, char *val)
{
 if (entrydb)
 {
  char *sha1 = get_sha1 ((((struct atrfs_file_entry *)(ent))->real_path));
  entrydb_exec (((void *)0), "UPDATE Files SET %s = \"%s\" WHERE sha1=\"%s\";", attr, val, sha1);
 }
}

user_defined_types: enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void __fastcall attach_subtitles(__int64 a1)
{
char *v1; // rbx
char *v2; // rax
char *v3; // r12
char *v4; // r14
unsigned int v5; // er13
__int64 v6; // rax
void *v7; // rbx
const char *v8; // r14
__int64 v9; // r15
size_t v10; // rax
void *v11; // rbx
char *v12; // r12
char *v13; // rax
size_t v14; // rsi
char *v15; // r13
const char *v16; // r12
__int64 v17; // r13
size_t v18; // rax
double v19; // [rsp+0h] [rbp-78h]
double v20; // [rsp+8h] [rbp-70h]
char s[40]; // [rsp+10h] [rbp-68h] BYREF
char *save_ptr[8]; // [rsp+38h] [rbp-40h] BYREF

v1 = strdup(language_list);
v19 = get_watchtime(a1);
v20 = get_length(a1);
v2 = strrchr(*(const char **)(a1 + 16), 46);
if ( v2 )
{
v3 = v2;
v4 = strtok_r(v1, ", \n", save_ptr);
if ( v4 )
{
v5 = 1;
do
{
snprintf(s, 0x28uLL, "_%d.%s.srt", v5, v4);
v6 = get_related_name(*(_QWORD *)(a1 + 16), v3, s);
v7 = (void *)v6;
if ( v6 )
{
if ( !lookup_entry_by_name(*(_QWORD *)(a1 + 8), v6) )
{
v8 = (const char *)get_real_srt(*(_QWORD *)(a1 + 48), v4, v19, v20);
if ( v8 )
{
v9 = create_entry(2LL);
v10 = strlen(v8);
(*(void (__fastcall **)(__int64, const char *, size_t))(v9 + 64))(v9, v8, v10);
*(_QWORD *)(v9 + 56) = *(_QWORD *)(a1 + 64);
*(_QWORD *)(a1 + 64) = v9;
attach_entry(*(_QWORD *)(a1 + 8), v9, v7);
++v5;
}
}
}
free(v7);
v4 = strtok_r(0LL, ", \n", save_ptr);
}
while ( v4 );
}
else
{
v5 = 1;
}
snprintf(s, 0x28uLL, "_%d.virt.srt", v5);
v11 = (void *)get_related_name(*(_QWORD *)(a1 + 16), v3, s);
if ( v11 )
{
v12 = basename(*(const char **)(a1 + 48));
v13 = strrchr(v12, 46);
if ( v13 )
v14 = v13 - v12;
else
v14 = strlen(v12);
v15 = strndup(v12, v14);
v16 = (const char *)get_virtual_srt(v15, 0LL, v19, v20);
free(v15);
if ( v16 )
{
v17 = create_entry(2LL);
v18 = strlen(v16);
(*(void (__fastcall **)(__int64, const char *, size_t))(v17 + 64))(v17, v16, v18);
*(_QWORD *)(v17 + 56) = *(_QWORD *)(a1 + 64);
*(_QWORD *)(a1 + 64) = v17;
attach_entry(*(_QWORD *)(a1 + 8), v17, v11);
}
free(v11);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
char *v1; // rbx
char *v2; // rax
char *v3; // r12
char *v4; // r14
unsigned int v5; // er13
__int64 v6; // rax
void *v7; // rbx
const char *v8; // r14
__int64 v9; // r15
size_t v10; // rax
void *v11; // rbx
char *v12; // r12
char *v13; // rax
size_t v14; // rsi
char *v15; // r13
const char *v16; // r12
__int64 v17; // r13
size_t v18; // rax
double v19; // [rsp+0h] [rbp-78h]
double v20; // [rsp+8h] [rbp-70h]
char s[40]; // [rsp+10h] [rbp-68h] BYREF
char *save_ptr[8]; // [rsp+38h] [rbp-40h] BYREF

v1 = strdup(language_list);
v19 = get_watchtime(a1);
v20 = get_length(a1);
v2 = strrchr(*(const char **)(a1 + 16), 46);
if ( v2 )
{
v3 = v2;
v4 = strtok_r(v1, ", \n", save_ptr);
if ( v4 )
{
v5 = 1;
do
{
snprintf(s, 0x28uLL, "_%d.%s.srt", v5, v4);
v6 = get_related_name(*(_QWORD *)(a1 + 16), v3, s);
v7 = (void *)v6;
if ( v6 )
{
if ( !lookup_entry_by_name(*(_QWORD *)(a1 + 8), v6) )
{
v8 = (const char *)get_real_srt(*(_QWORD *)(a1 + 48), v4, v19, v20);
if ( v8 )
{
v9 = create_entry(2LL);
v10 = strlen(v8);
(*(void (__fastcall **)(__int64, const char *, size_t))(v9 + 64))(v9, v8, v10);
*(_QWORD *)(v9 + 56) = *(_QWORD *)(a1 + 64);
*(_QWORD *)(a1 + 64) = v9;
attach_entry(*(_QWORD *)(a1 + 8), v9, v7);
++v5;
}
}
}
free(v7);
v4 = strtok_r(0LL, ", \n", save_ptr);
}
while ( v4 );
}
else
{
v5 = 1;
}
snprintf(s, 0x28uLL, "_%d.virt.srt", v5);
v11 = (void *)get_related_name(*(_QWORD *)(a1 + 16), v3, s);
if ( v11 )
{
v12 = basename(*(const char **)(a1 + 48));
v13 = strrchr(v12, 46);
if ( v13 )
v14 = v13 - v12;
else
v14 = strlen(v12);
v15 = strndup(v12, v14);
v16 = (const char *)get_virtual_srt(v15, 0LL, v19, v20);
free(v15);
if ( v16 )
{
v17 = create_entry(2LL);
v18 = strlen(v16);
(*(void (__fastcall **)(__int64, const char *, size_t))(v17 + 64))(v17, v16, v18);
*(_QWORD *)(v17 + 56) = *(_QWORD *)(a1 + 64);
*(_QWORD *)(a1 + 64) = v17;
attach_entry(*(_QWORD *)(a1 + 8), v17, v11);
}
free(v11);
}
}
}

original_code:
void attach_subtitles (struct atrfs_entry *ent)
{
 char *lng = strdup (language_list);
 char *ext, *s, *saved;
 double watchtime = get_watchtime (ent);
 double length = get_length (ent);
 char *srtname, *data;
 int num = 1;
 char buf[40];
 ext = strrchr (ent->name, '.');
 if (! ext)
  return;
 for (s = strtok_r (lng, ", \n", &saved); s; s = strtok_r (((void *)0), ", \n", &saved))
 {
  snprintf(buf, sizeof(buf), "_%d.%s.srt", num, s);
  char *srtname = get_related_name (ent->name, ext, buf);
  if (srtname && ! lookup_entry_by_name (ent->parent, srtname))
  {
   data = get_real_srt((((struct atrfs_file_entry *)(ent))->real_path), watchtime, length, s);
   if (data)
   {
    struct atrfs_entry *srt = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
    ((struct atrfs_virtual_entry*)(srt))->set_contents (srt, data, strlen (data));
    ((struct atrfs_virtual_entry*)(srt))->next = ((struct atrfs_file_entry *)(ent))->subtitles;
    ((struct atrfs_file_entry *)(ent))->subtitles = srt;
    attach_entry (ent->parent, srt, srtname);
    num++;
   }
  }
  free (srtname);
 }
 snprintf(buf, sizeof(buf), "_%d.virt.srt", num);
 srtname = get_related_name (ent->name, ext, buf);
 if (srtname)
 {
  char *base = basename ((((struct atrfs_file_entry *)(ent))->real_path));
  char *ext = strrchr (base, '.');
  char *title = strndup (base, ext ? ext - base : strlen (base));
  data = get_virtual_srt(title, watchtime, length, ((void *)0));
  free (title);
  if (data)
  {
   struct atrfs_entry *srt = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
   ((struct atrfs_virtual_entry*)(srt))->set_contents (srt, data, strlen (data));
   ((struct atrfs_virtual_entry*)(srt))->next = ((struct atrfs_file_entry *)(ent))->subtitles;
   ((struct atrfs_file_entry *)(ent))->subtitles = srt;
   attach_entry (ent->parent, srt, srtname);
  }
  free (srtname);
 }
}

canonical_original_code:
void attach_subtitles(struct atrfs_entry *ent)
{
 char *lng = strdup (language_list);
 char *ext; char *s; char *saved;
 double watchtime = get_watchtime (ent);
 double length = get_length (ent);
 char *srtname; char *data;
 int num = 1;
 char buf[40];
 ext = strrchr (ent->name, '.');
 if (! ext)
  return;
 for (s = strtok_r (lng, ", \n", &saved); s; s = strtok_r (((void *)0), ", \n", &saved))
 {
  snprintf(buf, sizeof(buf), "_%d.%s.srt", num, s);
  char *srtname = get_related_name (ent->name, ext, buf);
  if (srtname && ! lookup_entry_by_name (ent->parent, srtname))
  {
   data = get_real_srt((((struct atrfs_file_entry *)(ent))->real_path), watchtime, length, s);
   if (data)
   {
    struct atrfs_entry *srt = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
    ((struct atrfs_virtual_entry *)(srt))->set_contents (srt, data, strlen (data));
    ((struct atrfs_virtual_entry *)(srt))->next = ((struct atrfs_file_entry *)(ent))->subtitles;
    ((struct atrfs_file_entry *)(ent))->subtitles = srt;
    attach_entry (ent->parent, srt, srtname);
    num++;
   }
  }
  free (srtname);
 }
 snprintf(buf, sizeof(buf), "_%d.virt.srt", num);
 srtname = get_related_name (ent->name, ext, buf);
 if (srtname)
 {
  char *base = basename ((((struct atrfs_file_entry *)(ent))->real_path));
  char *ext = strrchr (base, '.');
  char *title = strndup (base, ext ? ext - base : strlen (base));
  data = get_virtual_srt(title, watchtime, length, ((void *)0));
  free (title);
  if (data)
  {
   struct atrfs_entry *srt = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
   ((struct atrfs_virtual_entry *)(srt))->set_contents (srt, data, strlen (data));
   ((struct atrfs_virtual_entry *)(srt))->next = ((struct atrfs_file_entry *)(ent))->subtitles;
   ((struct atrfs_file_entry *)(ent))->subtitles = srt;
   attach_entry (ent->parent, srt, srtname);
  }
  free (srtname);
 }
}

variable_types:
lng
char *

variable_types:
ext
char *

variable_types:
s
char *

variable_types:
saved
char *

variable_types: watchtime double

variable_types: length double

variable_types:
srtname
char *

variable_types:
data
char *

variable_types: num int

variable_types:
buf
char [40]

variable_types:
base
char *

variable_types:
title
char *

user_defined_types: struct atrfs_file_entry { struct atrfs_entry entry; int fd; char *real_path; double start_time; struct atrfs_entry *subtitles; }

user_defined_types: struct atrfs_virtual_entry { struct atrfs_entry entry; char *m_data; unsigned long m_size; struct atrfs_entry *next; void (*set_contents)(struct atrfs_entry *vent, char *str, unsigned long sz); }


decompiled_code:
__int64 __fastcall detach_subtitles(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rbp
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 64); i; result = destroy_entry(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 56);
detach_entry(v2);
free(*(void **)(v2 + 40));
}
*(_QWORD *)(a1 + 64) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rbp
__int64 result; // rax

for ( i = *(_QWORD *)(a1 + 64); i; result = destroy_entry(v2) )
{
v2 = i;
i = *(_QWORD *)(i + 56);
detach_entry(v2);
free(*(void **)(v2 + 40));
}
*(_QWORD *)(a1 + 64) = 0LL;
return result;
}

original_code:
void detach_subtitles (struct atrfs_entry *ent)
{
 struct atrfs_entry *tmp, *srt = ((struct atrfs_file_entry *)(ent))->subtitles;
 while (srt)
 {
  tmp = ((struct atrfs_virtual_entry*)(srt))->next;
  detach_entry (srt);
  free (((struct atrfs_virtual_entry*)(srt))->m_data);
  destroy_entry (srt);
  srt = tmp;
 }
 ((struct atrfs_file_entry *)(ent))->subtitles = ((void *)0);
}

canonical_original_code:
void detach_subtitles(struct atrfs_entry *ent)
{
 struct atrfs_entry *tmp; struct atrfs_entry *srt = ((struct atrfs_file_entry *)(ent))->subtitles;
 while (srt)
 {
  tmp = ((struct atrfs_virtual_entry *)(srt))->next;
  detach_entry (srt);
  free (((struct atrfs_virtual_entry *)(srt))->m_data);
  destroy_entry (srt);
  srt = tmp;
 }
 ((struct atrfs_file_entry *)(ent))->subtitles = ((void *)0);
}


decompiled_code:
void __fastcall categorize_file_entry(__int64 a1)
{
int v2; // er13
void *v3; // r13
__int64 v4; // rax
__int64 v5; // r12
const char *v6; // r12
void *v7; // rsp
__int64 v8; // rax
__int64 v9; // r14
char *v10; // rax
const char *v11; // rdi
int v12; // er13
char v13[8]; // [rsp+0h] [rbp-40h] BYREF
char *v14; // [rsp+8h] [rbp-38h]

if ( !a1 || *(_DWORD *)a1 )
abort();
v2 = getxattr(*(const char **)(a1 + 48), "user.mpconf", 0LL, 0LL);
if ( v2 > 0 )
{
v6 = *(const char **)(a1 + 16);
v7 = alloca(strlen(v6) + 6);
sprintf(v13, "%s.conf", v6);
v5 = lookup_entry_by_name(*(_QWORD *)(a1 + 8), v13);
if ( !v5 )
{
v5 = create_entry(2LL);
v10 = (char *)malloc(v2);
v11 = *(const char **)(a1 + 48);
v14 = v10;
v12 = getxattr(v11, "user.mpconf", v10, (unsigned int)v2);
tmplog("Data: '%s'\n", v14);
(*(void (__fastcall **)(__int64, char *, _QWORD))(v5 + 64))(v5, v14, v12);
attach_entry(*(_QWORD *)(a1 + 8), v5, v13);
}
v3 = (void *)get_category(a1);
v8 = lookup_entry_by_name(root, v3);
v9 = v8;
if ( v8 )
{
move_entry(a1, v8);
LABEL_11:
move_entry(v5, v9);
goto LABEL_12;
}
LABEL_13:
v9 = create_entry(1LL);
attach_entry(root, v9, v3);
move_entry(a1, v9);
if ( !v5 )
goto LABEL_12;
goto LABEL_11;
}
v3 = (void *)get_category(a1);
v4 = lookup_entry_by_name(root, v3);
v5 = v4;
if ( !v4 )
goto LABEL_13;
move_entry(a1, v4);
LABEL_12:
free(v3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v2; // er13
void *v3; // r13
__int64 v4; // rax
__int64 v5; // r12
const char *v6; // r12
void *v7; // rsp
__int64 v8; // rax
__int64 v9; // r14
char *v10; // rax
const char *v11; // rdi
int v12; // er13
char v13[8]; // [rsp+0h] [rbp-40h] BYREF
char *v14; // [rsp+8h] [rbp-38h]

if ( !a1 || *(_DWORD *)a1 )
abort();
v2 = getxattr(*(const char **)(a1 + 48), "user.mpconf", 0LL, 0LL);
if ( v2 > 0 )
{
v6 = *(const char **)(a1 + 16);
v7 = alloca(strlen(v6) + 6);
sprintf(v13, "%s.conf", v6);
v5 = lookup_entry_by_name(*(_QWORD *)(a1 + 8), v13);
if ( !v5 )
{
v5 = create_entry(2LL);
v10 = (char *)malloc(v2);
v11 = *(const char **)(a1 + 48);
v14 = v10;
v12 = getxattr(v11, "user.mpconf", v10, (unsigned int)v2);
tmplog("Data: '%s'\n", v14);
(*(void (__fastcall **)(__int64, char *, _QWORD))(v5 + 64))(v5, v14, v12);
attach_entry(*(_QWORD *)(a1 + 8), v5, v13);
}
v3 = (void *)get_category(a1);
v8 = lookup_entry_by_name(root, v3);
v9 = v8;
if ( v8 )
{
move_entry(a1, v8);
LABEL_11:
move_entry(v5, v9);
goto LABEL_12;
}
LABEL_13:
v9 = create_entry(1LL);
attach_entry(root, v9, v3);
move_entry(a1, v9);
if ( !v5 )
goto LABEL_12;
goto LABEL_11;
}
v3 = (void *)get_category(a1);
v4 = lookup_entry_by_name(root, v3);
v5 = v4;
if ( !v4 )
goto LABEL_13;
move_entry(a1, v4);
LABEL_12:
free(v3);
}

original_code:
void categorize_file_entry (struct atrfs_entry *ent)
{
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 struct atrfs_entry *conf = ((void *)0);
 int size = getxattr((((struct atrfs_file_entry *)(ent))->real_path), "user.mpconf", ((void *)0), 0);
 if (size > 0)
 {
  char cfgname[strlen (ent->name) + 6];
  sprintf (cfgname, "%s.conf", ent->name);
  conf = lookup_entry_by_name (ent->parent, cfgname);
  if (! conf)
  {
   char *data;
   size_t sz;
   conf = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
   data = malloc (size);
   sz = getxattr((((struct atrfs_file_entry *)(ent))->real_path), "user.mpconf", data, size);
   tmplog("Data: '%s'\n", data);
   ((struct atrfs_virtual_entry*)(conf))->set_contents(conf, data, sz);
   attach_entry (ent->parent, conf, cfgname);
  }
 }
 char *dirname = get_category (ent);
 struct atrfs_entry *dir = lookup_entry_by_name (root, dirname);
 if (! dir)
 {
  dir = create_entry (ATRFS_DIRECTORY_ENTRY);
  attach_entry (root, dir, dirname);
 }
 move_entry (ent, dir);
 if (conf)
  move_entry (conf, dir);
 free (dirname);
}

canonical_original_code:
void categorize_file_entry(struct atrfs_entry *ent)
{
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 struct atrfs_entry *conf = ((void *)0);
 int size = getxattr((((struct atrfs_file_entry *)(ent))->real_path), "user.mpconf", ((void *)0), 0);
 if (size > 0)
 {
  char cfgname[-1];
  sprintf (cfgname, "%s.conf", ent->name);
  conf = lookup_entry_by_name (ent->parent, cfgname);
  if (! conf)
  {
   char *data;
   unsigned long sz;
   conf = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
   data = malloc (size);
   sz = getxattr((((struct atrfs_file_entry *)(ent))->real_path), "user.mpconf", data, size);
   tmplog("Data: '%s'\n", data);
   ((struct atrfs_virtual_entry *)(conf))->set_contents(conf, data, sz);
   attach_entry (ent->parent, conf, cfgname);
  }
 }
 char *dirname = get_category (ent);
 struct atrfs_entry *dir = lookup_entry_by_name (root, dirname);
 if (! dir)
 {
  dir = create_entry (ATRFS_DIRECTORY_ENTRY);
  attach_entry (root, dir, dirname);
 }
 move_entry (ent, dir);
 if (conf)
  move_entry (conf, dir);
 free (dirname);
}

variable_types: size int

variable_types:
cfgname
char [-1]

variable_types:
sz
unsigned long

variable_types:
dirname
char *


decompiled_code:
char *__fastcall get_category(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
const char *v7; // rax
_QWORD *v8; // rbx
char *result; // rax
__int64 v10[2]; // [rsp+0h] [rbp-48h] BYREF
__int16 v11; // [rsp+10h] [rbp-38h] BYREF
unsigned int v12; // [rsp+12h] [rbp-36h]
__int16 v13; // [rsp+16h] [rbp-32h]
__int64 *v14; // [rsp+18h] [rbp-30h]
int v15; // [rsp+20h] [rbp-28h]
char *v16; // [rsp+30h] [rbp-18h]

v16 = &a7;
v10[1] = (__int64)a1;
v11 = -17599;
v12 = (unsigned int)filter_cb_0;
v13 = -17847;
v14 = v10;
v15 = -1864106167;
v10[0] = 0LL;
if ( !a1 || *a1 )
abort();
v7 = (const char *)get_catfile((__int64)a1);
v10[0] = (__int64)v7;
if ( v7 )
return strdup(v7);
v8 = (_QWORD *)filters;
if ( !filters )
return (char *)filters;
do
{
if ( (unsigned int)entrydb_exec(&v11, *v8) )
{
result = (char *)v10[0];
if ( v10[0] )
break;
}
v8 = (_QWORD *)v8[1];
result = (char *)v10[0];
if ( !v8 )
break;
}
while ( !v10[0] );
return result;
}

canonical_decompiled_code:
char *__fastcall func2(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
const char *v7; // rax
_QWORD *v8; // rbx
char *result; // rax
__int64 v10[2]; // [rsp+0h] [rbp-48h] BYREF
__int16 v11; // [rsp+10h] [rbp-38h] BYREF
unsigned int v12; // [rsp+12h] [rbp-36h]
__int16 v13; // [rsp+16h] [rbp-32h]
__int64 *v14; // [rsp+18h] [rbp-30h]
int v15; // [rsp+20h] [rbp-28h]
char *v16; // [rsp+30h] [rbp-18h]

v16 = &a7;
v10[1] = (__int64)a1;
v11 = -17599;
v12 = (unsigned int)filter_cb_0;
v13 = -17847;
v14 = v10;
v15 = -1864106167;
v10[0] = 0LL;
if ( !a1 || *a1 )
abort();
v7 = (const char *)func1((__int64)a1);
v10[0] = (__int64)v7;
if ( v7 )
return strdup(v7);
v8 = (_QWORD *)filters;
if ( !filters )
return (char *)filters;
do
{
if ( (unsigned int)entrydb_exec(&v11, *v8) )
{
result = (char *)v10[0];
if ( v10[0] )
break;
}
v8 = (_QWORD *)v8[1];
result = (char *)v10[0];
if ( !v8 )
break;
}
while ( !v10[0] );
return result;
}

original_code:
char *get_category (struct atrfs_entry *ent)
{
 struct filter *filt;
 char *cat = ((void *)0);
 int filter_cb (void *data, int ncols, char **values, char **names)
 {
  if (ncols != 2)
   tmplog ("get_category: ncols != 2\n");
  char *c = values[0];
  struct atrfs_entry *e = g_hash_table_lookup (sha1_to_entry_map, values[1]);
  if (ent == e)
   cat = strdup (c);
  return 0;
 }
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 cat = get_catfile (ent);
 if (cat)
  return strdup (cat);
 for (filt = filters; !cat && filt; filt = filt->next)
 {
  if (entrydb_exec (filter_cb, filt->str) && cat)
   return cat;
 }
 return cat;
}

canonical_original_code:
char *get_category(struct atrfs_entry *ent)
{
 struct filter *filt;
 char *cat = ((void *)0);
 int filter_cb (void *data, int ncols, char **values, char **names)
 {
  if (ncols != 2)
   tmplog ("get_category: ncols != 2\n");
  char *c = values[0];
  struct atrfs_entry *e = g_hash_table_lookup (sha1_to_entry_map, values[1]);
  if (ent == e)
   cat = strdup (c);
  return 0;
 }
 do { if (!(ent) || (ent)->e_type != (ATRFS_FILE_ENTRY)) abort ();} while(0);
 cat = get_catfile (ent);
 if (cat)
  return strdup (cat);
 for (filt = filters; !cat && filt; filt = filt->next)
 {
  if (entrydb_exec (filter_cb, filt->str) && cat)
   return cat;
 }
 return cat;
}

variable_types: struct atrfs_entry { enum atrfs_entry_type { ATRFS_FILE_ENTRY=0, ATRFS_DIRECTORY_ENTRY=1, ATRFS_VIRTUAL_FILE_ENTRY=2 } e_type; struct atrfs_entry *parent; char *name; unsigned char flags; struct atrfs_entry_ops { long (*read)(struct atrfs_entry *ent, char *buf, unsigned long size, long offset); void (*write)(struct atrfs_entry *ent, char *buf, unsigned long size); int (*stat)(struct atrfs_entry *ent, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *st); struct atrfs_entry *(*lookup_entry_by_name)(struct atrfs_entry *dir, char *name); } *ops; } *

variable_types: struct filter { char *str; struct filter *next; } *

variable_types:
cat
char *

variable_types:
c
char *


decompiled_code:
void __fastcall set_data(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
static void set_data(struct fuse_file_info *fi, struct directory_data *data)
{
 fi->fh = (unsigned long)data;
}

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: struct directory_data { struct _GList { void *data; struct _GList *next; struct _GList *prev; } *files; struct _GList *cur; } *

user_defined_types: struct directory_data { struct _GList *files; struct _GList *cur; }


decompiled_code:
int __fastcall open_file(const char *a1, __int64 a2, int a3)
{
bool v3; // cf
bool v4; // zf
const char *v8; // r12
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
char v12; // dl
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
int v17; // eax
int result; // eax

v8 = *(const char **)(a2 + 48);
v9 = "mplayer";
v10 = 8LL;
v11 = a1;
do
{
if ( !v10 )
break;
v3 = *v11 < (unsigned int)*v9;
v4 = *v11++ == *v9++;
--v10;
}
while ( v4 );
v12 = (!v3 && !v4) - v3;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
goto LABEL_9;
v15 = "totem";
v16 = 6LL;
v11 = a1;
do
{
if ( !v16 )
break;
v13 = *v11 < (unsigned int)*v15;
v14 = *v11++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
LABEL_9:
v17 = get_watchcount(a2, v11);
set_ivalue(a2, "count", (unsigned int)(v17 + 1));
attach_subtitles(a2);
*(double *)(a2 + 56) = doubletime();
}
result = *(_DWORD *)(a2 + 40);
if ( result < 0 )
{
result = open64(v8, a3);
if ( result < 0 )
result = -*_errno_location();
else
*(_DWORD *)(a2 + 40) = result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(const char *a1, __int64 a2, int a3)
{
bool v3; // cf
bool v4; // zf
const char *v8; // r12
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
char v12; // dl
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
int v17; // eax
int result; // eax

v8 = *(const char **)(a2 + 48);
v9 = "mplayer";
v10 = 8LL;
v11 = a1;
do
{
if ( !v10 )
break;
v3 = *v11 < (unsigned int)*v9;
v4 = *v11++ == *v9++;
--v10;
}
while ( v4 );
v12 = (!v3 && !v4) - v3;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
goto LABEL_9;
v15 = "totem";
v16 = 6LL;
v11 = a1;
do
{
if ( !v16 )
break;
v13 = *v11 < (unsigned int)*v15;
v14 = *v11++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
LABEL_9:
v17 = get_watchcount(a2, v11);
set_ivalue(a2, "count", (unsigned int)(v17 + 1));
attach_subtitles(a2);
*(double *)(a2 + 56) = doubletime();
}
result = *(_DWORD *)(a2 + 40);
if ( result < 0 )
{
result = open64(v8, a3);
if ( result < 0 )
result = -*_errno_location();
else
*(_DWORD *)(a2 + 40) = result;
}
return result;
}

original_code:
static int open_file(char *cmd, struct atrfs_entry *ent, int flags)
{
 char *filename = (((struct atrfs_file_entry *)(ent))->real_path);
 if (!strcmp(cmd, "mplayer") || !strcmp(cmd, "totem"))
 {
  int count = get_watchcount(ent) + 1;
  set_ivalue (ent, "count", count);
  attach_subtitles (ent);
  ((struct atrfs_file_entry *)(ent))->start_time = doubletime ();
 }
 int fd = ((struct atrfs_file_entry *)(ent))->fd;
 if (fd < 0)
 {
  fd = open(filename, flags);
  if (fd < 0)
   fd = -(*__errno_location ());
  else
   ((struct atrfs_file_entry *)(ent))->fd = fd;
 }
 return fd;
}

variable_types:
cmd
char *

variable_types: flags int

variable_types:
filename
char *

variable_types: count int

variable_types: fd int

return_type: int


original_code:
char *get_sha1(char *filename)
{
 SHA_CTX context;
 unsigned char buf[20] = {0};
 static unsigned char ret[2*20 + 1];
 int i;
 int fd;
 fd = open(filename, 00);
 if (fd >= 0)
 {
  unsigned char buf2[1024];
  int len;
  SHA1_Init(&context);
  while ((len = read(fd, buf2, sizeof(buf2))) == sizeof(buf2))
   SHA1_Update(&context, buf2, sizeof(buf2));
  if (len)
   SHA1_Update(&context, buf2, len);
  SHA1_Final(buf, &context);
  close(fd);
 }
out:
 for (i = 0; i < 20; i++)
  sprintf(&ret[2*i], "%2.2x", buf[i]);
 ret[2*20] = '\0';
 return ret;
}

canonical_original_code:
char *get_sha1(char *filename)
{
 struct SHAstate_st context;
 unsigned char buf[20] = {0};
 static unsigned char ret[-1];
 int i;
 int fd;
 fd = open(filename, 00);
 if (fd >= 0)
 {
  unsigned char buf2[1024];
  int len;
  SHA1_Init(&context);
  while ((len = read(fd, buf2, sizeof(buf2))) == sizeof(buf2))
   SHA1_Update(&context, buf2, sizeof(buf2));
  if (len)
   SHA1_Update(&context, buf2, len);
  SHA1_Final(buf, &context);
  close(fd);
 }
out:
 for (i = 0; i < 20; i++)
  sprintf(&ret[2*i], "%2.2x", buf[i]);
 ret[2*20] = '\0';
 return ret;
}

variable_types: struct SHAstate_st { unsigned int h0; unsigned int Nl; unsigned int data[16]; unsigned int num; }

variable_types:
buf
unsigned char [20]

variable_types:
ret
unsigned char [-1]

variable_types: i int

variable_types: len int


decompiled_code:
char *__fastcall get_virtual_srt(__int64 a1, double a2, double a3)
{
__int64 v4; // rcx
double v5; // xmm0_8
unsigned int v6; // er13
int v7; // ebx
const char *v8; // r12
const char *v9; // rbp
const char *v10; // rax
__int64 v11; // rdx
char *v13; // [rsp+18h] [rbp-50h] BYREF
char *v14; // [rsp+20h] [rbp-48h] BYREF
char *ptr; // [rsp+28h] [rbp-40h] BYREF

ptr = 0LL;
v4 = secs_to_timestr(a3);
v5 = 0.0;
if ( a3 >= 1.0 )
v5 = a2 / a3;
asprintf(&ptr, fmt, a1, v4, v5);
if ( (int)a3 > 15 )
{
v6 = 2;
v7 = 15;
do
{
v13 = 0LL;
v14 = 0LL;
v8 = (const char *)secs_to_timestr((double)v7);
v9 = (const char *)secs_to_timestr((double)(v7 + 1));
v10 = (const char *)secs_to_timestr((double)v7);
v11 = v6++;
asprintf(&v14, "%d\n00:%s.00 --> 00:%s,00\n%s\n\n", v11, v10, v9, v8);
asprintf(&v13, "%s%s", ptr, v14);
free(ptr);
ptr = v13;
v7 += 15;
}
while ( v7 < (int)a3 );
}
return ptr;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, double a2, double a3)
{
__int64 v4; // rcx
double v5; // xmm0_8
unsigned int v6; // er13
int v7; // ebx
const char *v8; // r12
const char *v9; // rbp
const char *v10; // rax
__int64 v11; // rdx
char *v13; // [rsp+18h] [rbp-50h] BYREF
char *v14; // [rsp+20h] [rbp-48h] BYREF
char *ptr; // [rsp+28h] [rbp-40h] BYREF

ptr = 0LL;
v4 = secs_to_timestr(a3);
v5 = 0.0;
if ( a3 >= 1.0 )
v5 = a2 / a3;
asprintf(&ptr, fmt, a1, v4, v5);
if ( (int)a3 > 15 )
{
v6 = 2;
v7 = 15;
do
{
v13 = 0LL;
v14 = 0LL;
v8 = (const char *)secs_to_timestr((double)v7);
v9 = (const char *)secs_to_timestr((double)(v7 + 1));
v10 = (const char *)secs_to_timestr((double)v7);
v11 = v6++;
asprintf(&v14, "%d\n00:%s.00 --> 00:%s,00\n%s\n\n", v11, v10, v9, v8);
asprintf(&v13, "%s%s", ptr, v14);
free(ptr);
ptr = v13;
v7 += 15;
}
while ( v7 < (int)a3 );
}
return ptr;
}

original_code:
char *get_virtual_srt(char *title, double watchtime, double length, char *lang)
{
 char *ret = ((void *)0);
 int i, linenum;
 asprintf (&ret,
    "1\n00:00:00,00 --> 00:00:05,00\n"
    "%s\n%.2lf × %s\n\n",
    title, length >= 1.0 ? 1.0 * watchtime / length : 0,
    secs_to_timestr (length));
 linenum = 2;
 for (i = 15; i < (int)length; i += 15)
 {
  char *tmp = ((void *)0);
  char *line = ((void *)0);
  asprintf (&line,
   "%d\n00:%s.00 --> 00:%s,00\n%s\n\n",
   linenum++,
   secs_to_timestr (i),
   secs_to_timestr (i+1),
   secs_to_timestr (i));
  asprintf (&tmp, "%s%s", ret, line);
  free (ret);
  ret = tmp;
 }
 return ret;
}

canonical_original_code:
char *get_virtual_srt(char *title, double watchtime, double length, char *lang)
{
 char *ret = ((void *)0);
 int i; int linenum;
 asprintf (&ret,
    "1\n00:00:00,00 --> 00:00:05,00\n"
    "%s\n%.2lf × %s\n\n",
    title, length >= 1.0 ? 1.0 * watchtime / length : 0,
    secs_to_timestr (length));
 linenum = 2;
 for (i = 15; i < (int)length; i += 15)
 {
  char *tmp = ((void *)0);
  char *line = ((void *)0);
  asprintf (&line,
   "%d\n00:%s.00 --> 00:%s,00\n%s\n\n",
   linenum++,
   secs_to_timestr (i),
   secs_to_timestr (i+1),
   secs_to_timestr (i));
  asprintf (&tmp, "%s%s", ret, line);
  free (ret);
  ret = tmp;
 }
 return ret;
}

variable_types:
title
char *

variable_types: watchtime double

variable_types: length double

variable_types:
lang
char *

variable_types:
ret
char *

variable_types: linenum int

variable_types:
tmp
char *

variable_types:
line
char *


repo: terry-chelsea/shlowRun

decompiled_code:
__int64 __fastcall next_index(__int64 a1, int a2, int a3, int a4)
{
int v4; // edx
__int64 result; // rax
int v6; // edx

v4 = 2 * a3;
result = (unsigned int)(v4 + 1);
v6 = v4 + 2;
if ( v6 < a2 )
{
if ( a4 )
{
if ( *(_QWORD *)(a1 + 16LL * (int)result) >= *(_QWORD *)(a1 + 16LL * v6) )
result = (unsigned int)v6;
}
else if ( *(_QWORD *)(a1 + 16LL * (int)result) <= *(_QWORD *)(a1 + 16LL * v6) )
{
result = (unsigned int)v6;
}
}
else if ( (int)result > a2 )
{
result = (unsigned int)a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3, int a4)
{
int v4; // edx
__int64 result; // rax
int v6; // edx

v4 = 2 * a3;
result = (unsigned int)(v4 + 1);
v6 = v4 + 2;
if ( v6 < a2 )
{
if ( a4 )
{
if ( *(_QWORD *)(a1 + 16LL * (int)result) >= *(_QWORD *)(a1 + 16LL * v6) )
result = (unsigned int)v6;
}
else if ( *(_QWORD *)(a1 + 16LL * (int)result) <= *(_QWORD *)(a1 + 16LL * v6) )
{
result = (unsigned int)v6;
}
}
else if ( (int)result > a2 )
{
result = (unsigned int)a2;
}
return result;
}

original_code:
static int next_index(Item *head , int max_index , int cur_index , int type)
{
    int index = 0;
    int left_child = (2 * cur_index + 1);
    int right_child = (2 * cur_index + 2);
    if(right_child >= max_index)
    {
        if(left_child >= max_index)
            index = max_index;
        else
            index = left_child;
    }
    else
    {
        if(0 == type)
        {
            if(head[left_child].weight > head[right_child].weight)
                index = left_child;
            else
                index = right_child;
        }
        else
        {
            if(head[left_child].weight < head[right_child].weight)
                index = left_child;
            else
                index = right_child;
        }
    }
    return index;
}

canonical_original_code:
static int next_index(struct item *head, int max_index, int cur_index, int type)
{
    int index = 0;
    int left_child = (2 * cur_index + 1);
    int right_child = (2 * cur_index + 2);
    if(right_child >= max_index)
    {
        if(left_child >= max_index)
            index = max_index;
        else
            index = left_child;
    }
    else
    {
        if(0 == type)
        {
            if(head[left_child].weight > head[right_child].weight)
                index = left_child;
            else
                index = right_child;
        }
        else
        {
            if(head[left_child].weight < head[right_child].weight)
                index = left_child;
            else
                index = right_child;
        }
    }
    return index;
}

variable_types: struct item { unsigned long long weight; void *value; } *

variable_types: type int

variable_types: index int


decompiled_code:
char __fastcall adjust_heap_caused_by_modify(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, unsigned __int64 a4)
{
int v4; // edx

if ( *(_DWORD *)(a1 + 20) )
v4 = a4 >= a3;
else
v4 = a4 <= a3;
*a2 = a4;
return adjust_heap(a1, (__int64)a2, v4);
}

canonical_decompiled_code:
char __fastcall func9(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, unsigned __int64 a4)
{
int v4; // edx

if ( *(_DWORD *)(a1 + 20) )
v4 = a4 >= a3;
else
v4 = a4 <= a3;
*a2 = a4;
return func8(a1, (__int64)a2, v4);
}

original_code:
static void adjust_heap_caused_by_modify(Heap *hp , Item *item , UINT64 weight , UINT64 new_weight)
{
    int direction = 0;
    if(0 == hp->type)
    {
        if(new_weight > weight)
            direction = 0;
        else
            direction = 1;
    }
    else
    {
        if(new_weight < weight)
            direction = 0;
        else
            direction = 1;
    }
    item->weight = new_weight;
    adjust_heap(hp , item , direction);
}

canonical_original_code:
static void adjust_heap_caused_by_modify(struct heap *hp, struct item *item, unsigned long long weight, unsigned long long new_weight)
{
    int direction = 0;
    if(0 == hp->type)
    {
        if(new_weight > weight)
            direction = 0;
        else
            direction = 1;
    }
    else
    {
        if(new_weight < weight)
            direction = 0;
        else
            direction = 1;
    }
    item->weight = new_weight;
    adjust_heap(hp , item , direction);
}

variable_types: struct heap { struct item { unsigned long long weight; void *value; } *array; int size; int length; int free_counter; int type; } *

variable_types:
item
struct item *

variable_types:
weight
unsigned long long

variable_types: direction int

user_defined_types: struct heap { struct item *array; int size; int length; int free_counter; int type; }


decompiled_code:
__int64 __fastcall append_heap(__int64 a1)
{
void *v2; // rdi
int v3; // eax
int v4; // ebp
void *v5; // rax
__int64 result; // rax

v2 = *(void **)a1;
v3 = *(_DWORD *)(a1 + 8);
v4 = 2 * v3;
if ( v3 >= 4096 )
v4 = v3 + 256;
v5 = realloc(v2, 16LL * v4);
if ( v5 )
{
*(_QWORD *)a1 = v5;
*(_DWORD *)(a1 + 8) = v4;
result = 0LL;
}
else
{
printf("Allocate memory %lu failed when append heap ...", 16LL * v4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
void *v2; // rdi
int v3; // eax
int v4; // ebp
void *v5; // rax
__int64 result; // rax

v2 = *(void **)a1;
v3 = *(_DWORD *)(a1 + 8);
v4 = 2 * v3;
if ( v3 >= 4096 )
v4 = v3 + 256;
v5 = realloc(v2, 16LL * v4);
if ( v5 )
{
*(_QWORD *)a1 = v5;
*(_DWORD *)(a1 + 8) = v4;
result = 0LL;
}
else
{
printf("Allocate memory %lu failed when append heap ...", 16LL * v4);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int append_heap(Heap *hp)
{
    Item *start = hp->array;
    int cur_size = hp->size;
    int new_size = ((cur_size >= 4096) ? (cur_size + 256)
            : (cur_size << 1));
    Item *new_start = realloc(start , new_size * sizeof(Item));
    if(((void *)0) == new_start)
    {
        printf("Allocate memory %lu failed when append heap ..." , new_size * sizeof(Item));
        return -1;
    }
    hp->array = new_start;
    hp->size = new_size;
    return 0;
}

canonical_original_code:
static int append_heap(struct heap *hp)
{
    struct item *start = hp->array;
    int cur_size = hp->size;
    int new_size = ((cur_size >= 4096) ? (cur_size + 256)
            : (cur_size << 1));
    struct item *new_start = realloc(start , new_size * sizeof(Item));
    if(((void *)0) == new_start)
    {
        printf("Allocate memory %lu failed when append heap ..." , new_size * sizeof(Item));
        return -1;
    }
    hp->array = new_start;
    hp->size = new_size;
    return 0;
}

user_defined_types: struct item { unsigned long long weight; void *value; }


decompiled_code:
int __fastcall shrink_heap(__int64 a1)
{
int v1; // ebx
void *v2; // rax

v1 = *(_DWORD *)(a1 + 12) + ((*(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 12)) >> 1);
v2 = realloc(*(void **)a1, 16LL * v1);
if ( v2 )
{
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 8) = v1;
}
else
{
LODWORD(v2) = printf("Allocate memory %lu failed when append heap ...", 16LL * v1);
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int v1; // ebx
void *v2; // rax

v1 = *(_DWORD *)(a1 + 12) + ((*(_DWORD *)(a1 + 8) - *(_DWORD *)(a1 + 12)) >> 1);
v2 = realloc(*(void **)a1, 16LL * v1);
if ( v2 )
{
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 8) = v1;
}
else
{
LODWORD(v2) = printf("Allocate memory %lu failed when append heap ...", 16LL * v1);
}
return (int)v2;
}

original_code:
static void shrink_heap(Heap *hp)
{
    Item *start = hp->array;
    int empty_size = hp->size - hp->length;
    int new_size = hp->length + (empty_size >> 1);
    Item *new_start = realloc(start , new_size * sizeof(Item));
    if(((void *)0) == new_start)
    {
        printf("Allocate memory %lu failed when append heap ..." , new_size * sizeof(Item));
        return ;
    }
    hp->array = new_start;
    hp->size = new_size;
}

canonical_original_code:
static void shrink_heap(struct heap *hp)
{
    struct item *start = hp->array;
    int empty_size = hp->size - hp->length;
    int new_size = hp->length + (empty_size >> 1);
    struct item *new_start = realloc(start , new_size * sizeof(Item));
    if(((void *)0) == new_start)
    {
        printf("Allocate memory %lu failed when append heap ..." , new_size * sizeof(Item));
        return ;
    }
    hp->array = new_start;
    hp->size = new_size;
}


original_code:
static void free_the_value(Heap *hp , Item *item)
{
    UINT64 old_weight = 0;
    int flag = 0;
    if(item != hp->array)
    {
        flag = 1;
        old_weight = item->weight;
    }
    item->weight = 0;
    item->value = ((void *)0);
    do{ Item tmp = {(item)->weight , (item)->value}; (item)->weight = (hp->array + hp->length - 1)->weight; (item)->value = (hp->array + hp->length - 1)->value; (hp->array + hp->length - 1)->weight = tmp.weight; (hp->array + hp->length - 1)->value = tmp.value; }while(0);
    -- hp->length;
    if(!flag)
        adjust_heap(hp , item , 1);
    else
        adjust_heap_caused_by_modify(hp , item , old_weight , item->weight);
    hp->free_counter ++;
    if((hp->free_counter > 64) &&
            (hp->size - hp->length > 256) &&
            (hp->size >= 64))
    {
        shrink_heap(hp);
        hp->free_counter = 0;
    }
}

canonical_original_code:
static void free_the_value(struct heap *hp, struct item *item)
{
    unsigned long long old_weight = 0;
    int flag = 0;
    if(item != hp->array)
    {
        flag = 1;
        old_weight = item->weight;
    }
    item->weight = 0;
    item->value = ((void *)0);
    do{ struct item tmp = {(item)->weight , (item)->value}; (item)->weight = (hp->array + hp->length - 1)->weight; (item)->value = (hp->array + hp->length - 1)->value; (hp->array + hp->length - 1)->weight = tmp.weight; (hp->array + hp->length - 1)->value = tmp.value; }while(0);
    -- hp->length;
    if(!flag)
        adjust_heap(hp , item , 1);
    else
        adjust_heap_caused_by_modify(hp , item , old_weight , item->weight);
    hp->free_counter ++;
    if((hp->free_counter > 64) &&
            (hp->size - hp->length > 256) &&
            (hp->size >= 64))
    {
        shrink_heap(hp);
        hp->free_counter = 0;
    }
}

variable_types: flag int

variable_types: struct item { unsigned long long weight; void *value; }


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

if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 12) && (int)append_heap(a1) < 0 )
{
printf("Append array in heap failed , current size %d...", *(unsigned int *)(a1 + 8));
result = 0xFFFFFFFFLL;
}
else
{
v4 = (_QWORD *)(*(_QWORD *)a1 + 16LL * *(int *)(a1 + 12));
*v4 = a2;
v4[1] = a3;
LODWORD(v4) = *(_DWORD *)(a1 + 12) + 1;
*(_DWORD *)(a1 + 12) = (_DWORD)v4;
adjust_heap(a1, *(_QWORD *)a1 + 16LL * (int)v4 - 16, 0);
result = 0LL;
}
}
else
{
printf("Cannot insert to a NULL heap...");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 12) && (int)func10(a1) < 0 )
{
printf("Append array in heap failed , current size %d...", *(unsigned int *)(a1 + 8));
result = 0xFFFFFFFFLL;
}
else
{
v4 = (_QWORD *)(*(_QWORD *)a1 + 16LL * *(int *)(a1 + 12));
*v4 = a2;
v4[1] = a3;
LODWORD(v4) = *(_DWORD *)(a1 + 12) + 1;
*(_DWORD *)(a1 + 12) = (_DWORD)v4;
func8(a1, *(_QWORD *)a1 + 16LL * (int)v4 - 16, 0);
result = 0LL;
}
}
else
{
printf("Cannot insert to a NULL heap...");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int insert_to_heap(Heap *hp , UINT64 weight , void *value)
{
    if(hp == ((void *)0))
    {
        printf("Cannot insert to a NULL heap...");
        return -1;
    }
    if(hp->size == hp->length)
    {
        if(append_heap(hp) < 0)
        {
            printf("Append array in heap failed  , current size %d..." , hp->size);
            return -1;
        }
    }
    Item *item = hp->array + hp->length;
    item->weight = weight;
    item->value = value;
    ++ hp->length;
    adjust_heap(hp , hp->array + hp->length - 1 , 0);
    return 0;
}

canonical_original_code:
int insert_to_heap(struct heap *hp, unsigned long long weight, void *value)
{
    if(hp == ((void *)0))
    {
        printf("Cannot insert to a NULL heap...");
        return -1;
    }
    if(hp->size == hp->length)
    {
        if(append_heap(hp) < 0)
        {
            printf("Append array in heap failed  , current size %d..." , hp->size);
            return -1;
        }
    }
    struct item *item = hp->array + hp->length;
    item->weight = weight;
    item->value = value;
    ++ hp->length;
    adjust_heap(hp , hp->array + hp->length - 1 , 0);
    return 0;
}

variable_types:
value
void *


decompiled_code:
int __fastcall free_from_heap(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 *v3; // rsi
int result; // eax

if ( !a1 )
return printf("Cannot free from a NULL heap ...");
v3 = find_value(a1, a2, a3);
if ( v3 )
result = free_the_value(a1, v3);
else
result = puts("Can not find value ...");
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 *v3; // rsi
int result; // eax

if ( !a1 )
return printf("Cannot free from a NULL heap ...");
v3 = find_value(a1, a2, a3);
if ( v3 )
result = func12(a1, v3);
else
result = puts("Can not find value ...");
return result;
}

original_code:
void free_from_heap(Heap *hp , UINT64 weight , void *value)
{
    if(((void *)0) == hp)
    {
        printf("Cannot free from a NULL heap ...");
        return ;
    }
    Item *item = find_value(hp , weight , value);
    if(((void *)0) == item)
    {
        printf("Can not find value ...\n");
        return ;
    }
    free_the_value(hp , item);
}

canonical_original_code:
void free_from_heap(struct heap *hp, unsigned long long weight, void *value)
{
    if(((void *)0) == hp)
    {
        printf("Cannot free from a NULL heap ...");
        return ;
    }
    struct item *item = find_value(hp , weight , value);
    if(((void *)0) == item)
    {
        printf("Can not find value ...\n");
        return ;
    }
    free_the_value(hp , item);
}


decompiled_code:
void __fastcall modify_on_heap(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
unsigned __int64 *v7; // rax

if ( a1 )
{
if ( a4 != a2 )
{
v7 = find_value(a1, a2, a3);
if ( v7 )
{
v7[1] = a5;
adjust_heap_caused_by_modify(a1, v7, a2, a4);
}
else
{
puts("Can not find value ...");
}
}
}
else
{
printf("Cannot modify on NULL heap ...");
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, unsigned __int64 a2, __int64 a3, unsigned __int64 a4, unsigned __int64 a5)
{
unsigned __int64 *v7; // rax

if ( a1 )
{
if ( a4 != a2 )
{
v7 = find_value(a1, a2, a3);
if ( v7 )
{
v7[1] = a5;
func9(a1, v7, a2, a4);
}
else
{
puts("Can not find value ...");
}
}
}
else
{
printf("Cannot modify on NULL heap ...");
}
}

original_code:
void modify_on_heap(Heap *hp , UINT64 weight , void *value , UINT64 new_weight , void *new_value)
{
    if(((void *)0) == hp)
    {
        printf("Cannot modify on NULL heap ...");
        return ;
    }
    if(new_weight == weight)
        return ;
    Item *item = find_value(hp , weight , value);
    if(((void *)0) == item)
    {
        printf("Can not find value ...\n");
        return ;
    }
    item->value = new_value;
    adjust_heap_caused_by_modify(hp , item , weight , new_weight);
}

canonical_original_code:
void modify_on_heap(struct heap *hp, unsigned long long weight, void *value, unsigned long long new_weight, void *new_value)
{
    if(((void *)0) == hp)
    {
        printf("Cannot modify on NULL heap ...");
        return ;
    }
    if(new_weight == weight)
        return ;
    struct item *item = find_value(hp , weight , value);
    if(((void *)0) == item)
    {
        printf("Can not find value ...\n");
        return ;
    }
    item->value = new_value;
    adjust_heap_caused_by_modify(hp , item , weight , new_weight);
}


decompiled_code:
char __fastcall modify_heap_root(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int64 a3)
{
if ( !a1 )
return printf("Cannot modify root on NULL heap ...");
(*a1)[1] = a3;
return adjust_heap_caused_by_modify((__int64)a1, *a1, **a1, a2);
}

canonical_decompiled_code:
char __fastcall func16(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int64 a3)
{
if ( !a1 )
return printf("Cannot modify root on NULL heap ...");
(*a1)[1] = a3;
return func9((__int64)a1, *a1, **a1, a2);
}

original_code:
void modify_heap_root(Heap *hp , UINT64 new_weight , void *value)
{
    if(((void *)0) == hp)
    {
        printf("Cannot modify root on NULL heap ...");
        return ;
    }
    hp->array->value = value;
    adjust_heap_caused_by_modify(hp , hp->array , hp->array->weight , new_weight);
}

canonical_original_code:
void modify_heap_root(struct heap *hp, unsigned long long new_weight, void *value)
{
    if(((void *)0) == hp)
    {
        printf("Cannot modify root on NULL heap ...");
        return ;
    }
    hp->array->value = value;
    adjust_heap_caused_by_modify(hp , hp->array , hp->array->weight , new_weight);
}


decompiled_code:
__int64 __fastcall get_root_value(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
if ( a1[3] )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
else
result = 0LL;
}
else
{
printf("Cannot get root value from a NULL heap ...");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
if ( a1[3] )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
else
result = 0LL;
}
else
{
printf("Cannot get root value from a NULL heap ...");
result = 0LL;
}
return result;
}

original_code:
void *get_root_value(Heap *hp)
{
    if(((void *)0) == hp)
    {
        printf("Cannot get root value from a NULL heap ...");
        return ((void *)0);
    }
    if(0 == hp->length)
        return ((void *)0);
    return (hp->array[0]).value;
}

canonical_original_code:
void *get_root_value(struct heap *hp)
{
    if(((void *)0) == hp)
    {
        printf("Cannot get root value from a NULL heap ...");
        return ((void *)0);
    }
    if(0 == hp->length)
        return ((void *)0);
    return (hp->array[0]).value;
}

return_type: void *


decompiled_code:
__int64 __fastcall get_and_remove_root(__int64 a1)
{
__int64 v1; // rbp

if ( a1 )
{
v1 = 0LL;
if ( *(_DWORD *)(a1 + 12) )
{
v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
free_the_value(a1, *(unsigned __int64 **)a1);
}
}
else
{
printf("Cannot get root value from a NULL heap ...");
v1 = 0LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
__int64 v1; // rbp

if ( a1 )
{
v1 = 0LL;
if ( *(_DWORD *)(a1 + 12) )
{
v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
func12(a1, *(unsigned __int64 **)a1);
}
}
else
{
printf("Cannot get root value from a NULL heap ...");
v1 = 0LL;
}
return v1;
}

original_code:
void *get_and_remove_root(Heap *hp)
{
    if(((void *)0) == hp)
    {
        printf("Cannot get root value from a NULL heap ...");
        return ((void *)0);
    }
    if(0 == hp->length)
        return ((void *)0);
    void *value = (hp->array[0]).value;
    free_the_value(hp , hp->array);
    return value;
}

canonical_original_code:
void *get_and_remove_root(struct heap *hp)
{
    if(((void *)0) == hp)
    {
        printf("Cannot get root value from a NULL heap ...");
        return ((void *)0);
    }
    if(0 == hp->length)
        return ((void *)0);
    void *value = (hp->array[0]).value;
    free_the_value(hp , hp->array);
    return value;
}


decompiled_code:
int __fastcall free_heap_root(unsigned __int64 **a1)
{
int result; // eax

if ( a1 )
result = free_the_value((__int64)a1, *a1);
else
result = printf("Cannot free root from a NULL heap ...");
return result;
}

canonical_decompiled_code:
int __fastcall func19(unsigned __int64 **a1)
{
int result; // eax

if ( a1 )
result = func12((__int64)a1, *a1);
else
result = printf("Cannot free root from a NULL heap ...");
return result;
}

original_code:
void free_heap_root(Heap *hp)
{
    if(((void *)0) == hp)
    {
        printf("Cannot free root from a NULL heap ...");
        return ;
    }
    free_the_value(hp , hp->array);
}

canonical_original_code:
void free_heap_root(struct heap *hp)
{
    if(((void *)0) == hp)
    {
        printf("Cannot free root from a NULL heap ...");
        return ;
    }
    free_the_value(hp , hp->array);
}


decompiled_code:
void __fastcall destory_heap(void *ptr)
{
__int64 v2; // rsi
void *v3; // rdi

if ( ptr )
{
v2 = *((unsigned int *)ptr + 3);
if ( (_DWORD)v2 )
printf("There are %d items when destory heap ...\n", v2);
v3 = *(void **)ptr;
if ( *(_QWORD *)ptr )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func20(void *ptr)
{
__int64 v2; // rsi
void *v3; // rdi

if ( ptr )
{
v2 = *((unsigned int *)ptr + 3);
if ( (_DWORD)v2 )
printf("There are %d items when destory heap ...\n", v2);
v3 = *(void **)ptr;
if ( *(_QWORD *)ptr )
free(v3);
free(ptr);
}
}

original_code:
void destory_heap(Heap *hp)
{
    if(((void *)0) == hp)
        return ;
    if(hp->length != 0)
        printf("There are %d items when destory heap ...\n" , hp->length);
    if(hp->array != ((void *)0))
    {
        free(hp->array);
        hp->array = ((void *)0);
    }
    free(hp);
    hp = ((void *)0);
}

canonical_original_code:
void destory_heap(struct heap *hp)
{
    if(((void *)0) == hp)
        return ;
    if(hp->length != 0)
        printf("There are %d items when destory heap ...\n" , hp->length);
    if(hp->array != ((void *)0))
    {
        free(hp->array);
        hp->array = ((void *)0);
    }
    free(hp);
    hp = ((void *)0);
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = MEMORY[0x14];
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = MEMORY[0x14];
return result;
}

original_code:
int get_heap_type(Heap *hp)
{
    if(hp != ((void *)0))
        return hp->type;
    return hp->type;
}

canonical_original_code:
int get_heap_type(struct heap *hp)
{
    if(hp != ((void *)0))
        return hp->type;
    return hp->type;
}


decompiled_code:
int __fastcall display_heap(unsigned int *a1)
{
const char *v1; // rdx
__int64 v2; // rbx

v1 = "MAX";
if ( a1[5] )
v1 = "MIN";
printf("Heap %p is a %s heap : \n", a1, v1);
printf("Heap current size : %d\n", a1[2]);
printf("Heap current length : %d\n", a1[3]);
puts("All elements weight displays : ");
if ( (int)a1[3] > 0 )
{
v2 = 0LL;
do
printf("%llu ", *(_QWORD *)(*(_QWORD *)a1 + 16 * v2++));
while ( (int)a1[3] > (int)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func22(unsigned int *a1)
{
const char *v1; // rdx
__int64 v2; // rbx

v1 = "MAX";
if ( a1[5] )
v1 = "MIN";
printf("Heap %p is a %s heap : \n", a1, v1);
printf("Heap current size : %d\n", a1[2]);
printf("Heap current length : %d\n", a1[3]);
puts("All elements weight displays : ");
if ( (int)a1[3] > 0 )
{
v2 = 0LL;
do
printf("%llu ", *(_QWORD *)(*(_QWORD *)a1 + 16 * v2++));
while ( (int)a1[3] > (int)v2 );
}
return putchar(10);
}

original_code:
void display_heap(Heap *hp)
{
    printf("Heap %p is a %s heap : \n" , hp , ((0 == hp->type) ? "MAX" : "MIN"));
    printf("Heap current size : %d\n" , hp->size);
    printf("Heap current length : %d\n" , hp->length);
    printf("All elements weight displays : \n");
    int i = 0;
    for(i = 0 ; i < hp->length ; ++ i)
        printf("%llu  " , (hp->array[i]).weight);
    printf("\n");
}

canonical_original_code:
void display_heap(struct heap *hp)
{
    printf("Heap %p is a %s heap : \n" , hp , ((0 == hp->type) ? "MAX" : "MIN"));
    printf("Heap current size : %d\n" , hp->size);
    printf("Heap current length : %d\n" , hp->length);
    printf("All elements weight displays : \n");
    int i = 0;
    for(i = 0 ; i < hp->length ; ++ i)
        printf("%llu  " , (hp->array[i]).weight);
    printf("\n");
}

variable_types: i int


original_code:
void do_heap_sort(Heap *hp)
{
    Item *head = hp->array;
    int cur_length = hp->length;
    int i = 0;
    for(i = 0 ; i < cur_length ; ++ i)
    {
        do{ Item tmp = {(head)->weight , (head)->value}; (head)->weight = (head + hp->length - 1)->weight; (head)->value = (head + hp->length - 1)->value; (head + hp->length - 1)->weight = tmp.weight; (head + hp->length - 1)->value = tmp.value; }while(0);
        -- hp->length;
        adjust_heap(hp , head , 1);
    }
    hp->length = cur_length;
}

canonical_original_code:
void do_heap_sort(struct heap *hp)
{
    struct item *head = hp->array;
    int cur_length = hp->length;
    int i = 0;
    for(i = 0 ; i < cur_length ; ++ i)
    {
        do{ struct item tmp = {(head)->weight , (head)->value}; (head)->weight = (head + hp->length - 1)->weight; (head)->value = (head + hp->length - 1)->value; (head + hp->length - 1)->weight = tmp.weight; (head + hp->length - 1)->value = tmp.value; }while(0);
        -- hp->length;
        adjust_heap(hp , head , 1);
    }
    hp->length = cur_length;
}


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

if ( *(_QWORD *)a1 )
{
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = a2;
}
else
{
*(_QWORD *)a1 = a2;
}
*(_QWORD *)(a1 + 8) = a2;
++*(_DWORD *)(a1 + 16);
return result;
}

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

if ( *(_QWORD *)a1 )
{
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = a2;
}
else
{
*(_QWORD *)a1 = a2;
}
*(_QWORD *)(a1 + 8) = a2;
++*(_DWORD *)(a1 + 16);
return result;
}

original_code:
static void add_to_list_tail(QUEUE *lst , NODE *node)
{
    if(((void *)0) == lst->head)
    {
        lst->head = node;
        lst->tail = node;
    }
    else
    {
        lst->tail->next = node;
        lst->tail = node;
    }
    lst->elems ++;
}

canonical_original_code:
static void add_to_list_tail(struct list *lst, struct node *node)
{
    if(((void *)0) == lst->head)
    {
        lst->head = node;
        lst->tail = node;
    }
    else
    {
        lst->tail->next = node;
        lst->tail = node;
    }
    lst->elems ++;
}

variable_types: struct list { struct node { void *value; struct node *next; } *head; struct node *tail; int elems; unsigned char need_lock; unsigned char waiting; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lmutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } lcond; } *

variable_types:
node
struct node *

user_defined_types: struct list { struct node *head; struct node *tail; int elems; unsigned char need_lock; unsigned char waiting; union pthread_mutex_t lmutex; union pthread_cond_t lcond; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


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

result = *a1;
if ( *a1 )
{
if ( result == a1[1] )
{
*a1 = 0LL;
a1[1] = 0LL;
}
else
{
*a1 = *(_QWORD *)(result + 8);
}
--*((_DWORD *)a1 + 4);
}
return result;
}

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

result = *a1;
if ( *a1 )
{
if ( result == a1[1] )
{
*a1 = 0LL;
a1[1] = 0LL;
}
else
{
*a1 = *(_QWORD *)(result + 8);
}
--*((_DWORD *)a1 + 4);
}
return result;
}

original_code:
static NODE *del_from_list_head(QUEUE *lst)
{
    NODE *node = ((void *)0);
    if(((void *)0) == lst->head)
        return ((void *)0);
    if(lst->head == lst->tail)
    {
        node = lst->head;
        lst->head = ((void *)0);
        lst->tail = ((void *)0);
    }
    else
    {
        node = lst->head;
        lst->head = node->next;
    }
    lst->elems --;
    return node;
}

canonical_original_code:
static struct node *del_from_list_head(struct list *lst)
{
    struct node *node = ((void *)0);
    if(((void *)0) == lst->head)
        return ((void *)0);
    if(lst->head == lst->tail)
    {
        node = lst->head;
        lst->head = ((void *)0);
        lst->tail = ((void *)0);
    }
    else
    {
        node = lst->head;
        lst->head = node->next;
    }
    lst->elems --;
    return node;
}

variable_types: struct list { struct node *head; struct node *tail; int elems; unsigned char need_lock; unsigned char waiting; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lmutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } lcond; } *

variable_types: struct node { void *value; struct node *next; } *


decompiled_code:
__int64 __fastcall get_remove_node_lock(__int64 a1, int a2)
{
pthread_mutex_t *v2; // r12
__int64 v3; // rbx

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = del_from_list_head((__int64 *)a1);
if ( !v3 && a2 )
{
do
{
++*(_BYTE *)(a1 + 21);
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v2);
v3 = del_from_list_head((__int64 *)a1);
}
while ( !v3 );
}
pthread_mutex_unlock(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
pthread_mutex_t *v2; // r12
__int64 v3; // rbx

v2 = (pthread_mutex_t *)(a1 + 24);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v3 = func1((__int64 *)a1);
if ( !v3 && a2 )
{
do
{
++*(_BYTE *)(a1 + 21);
pthread_cond_wait((pthread_cond_t *)(a1 + 64), v2);
v3 = func1((__int64 *)a1);
}
while ( !v3 );
}
pthread_mutex_unlock(v2);
return v3;
}

original_code:
static NODE *get_remove_node_lock(QUEUE *lst , int flag)
{
    pthread_mutex_lock(&(lst->lmutex));
    NODE *node = del_from_list_head(lst);
    while(((void *)0) == node)
    {
        if(!flag)
        {
            pthread_mutex_unlock(&(lst->lmutex));
            return ((void *)0);
        }
        lst->waiting ++ ;
        pthread_cond_wait(&(lst->lcond) , &(lst->lmutex));
        node = del_from_list_head(lst);
    }
    pthread_mutex_unlock(&(lst->lmutex));
    return node;
}

canonical_original_code:
static struct node *get_remove_node_lock(struct list *lst, int flag)
{
    pthread_mutex_lock(&(lst->lmutex));
    struct node *node = del_from_list_head(lst);
    while(((void *)0) == node)
    {
        if(!flag)
        {
            pthread_mutex_unlock(&(lst->lmutex));
            return ((void *)0);
        }
        lst->waiting ++ ;
        pthread_cond_wait(&(lst->lcond) , &(lst->lmutex));
        node = del_from_list_head(lst);
    }
    pthread_mutex_unlock(&(lst->lmutex));
    return node;
}

return_type: struct node { void *value; struct node *next; } *

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall queue_get_inside(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rdi
__int64 result; // rax

if ( *(_BYTE *)(a1 + 20) )
{
v3 = (_QWORD *)get_remove_node_lock(a1, a3);
if ( v3 )
{
LABEL_3:
*a2 = *v3;
free(v3);
return 0LL;
}
fwrite("ERROR:CAN not happen when remove a node return NULL with blocking...\n", 1uLL, 0x45uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = (_QWORD *)del_from_list_head((__int64 *)a1);
if ( v3 )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *v3; // rdi
__int64 result; // rax

if ( *(_BYTE *)(a1 + 20) )
{
v3 = (_QWORD *)func3(a1, a3);
if ( v3 )
{
LABEL_3:
*a2 = *v3;
free(v3);
return 0LL;
}
fwrite("ERROR:CAN not happen when remove a node return NULL with blocking...\n", 1uLL, 0x45uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
v3 = (_QWORD *)func1((__int64 *)a1);
if ( v3 )
goto LABEL_3;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int queue_get_inside(QUEUE *queue , ElemType *val , int flag)
{
    NODE *node = ((void *)0);
    if(queue->need_lock)
    {
        node = get_remove_node_lock(queue , flag);
        if(node == ((void *)0))
        {
            fprintf(stderr , "ERROR:CAN not happen when remove a node return NULL with blocking...\n");
            return -1;
        }
    }
    else
    {
        node = del_from_list_head(queue);
        if(((void *)0) == node)
            return -1;
    }
    *val = node->value;
    free(node);
    return 0;
}

canonical_original_code:
static int queue_get_inside(struct list *queue, void **val, int flag)
{
    struct node *node = ((void *)0);
    if(queue->need_lock)
    {
        node = get_remove_node_lock(queue , flag);
        if(node == ((void *)0))
        {
            fprintf(stderr , "ERROR:CAN not happen when remove a node return NULL with blocking...\n");
            return -1;
        }
    }
    else
    {
        node = del_from_list_head(queue);
        if(((void *)0) == node)
            return -1;
    }
    *val = node->value;
    free(node);
    return 0;
}

variable_types:
val
void **

user_defined_types: struct node { void *value; struct node *next; }


decompiled_code:
__int64 __fastcall queue_put(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rbp
char v4; // al
__int64 result; // rax

if ( a1 )
{
v2 = malloc(0x10uLL);
v3 = (__int64)v2;
if ( v2 )
{
*v2 = a2;
v2[1] = 0LL;
if ( *(_BYTE *)(a1 + 20) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
add_to_list_tail(a1, v3);
v4 = *(_BYTE *)(a1 + 21);
if ( v4 )
{
*(_BYTE *)(a1 + 21) = v4 - 1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
result = 0LL;
}
else
{
add_to_list_tail(a1, (__int64)v2);
result = 0LL;
}
}
else
{
fprintf(stderr, "Allocate memory size %lu failed when put to queue...\n", 16LL);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("WARNING : Put a value to NULL queue ...\n", 1uLL, 0x28uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rbp
char v4; // al
__int64 result; // rax

if ( a1 )
{
v2 = malloc(0x10uLL);
v3 = (__int64)v2;
if ( v2 )
{
*v2 = a2;
v2[1] = 0LL;
if ( *(_BYTE *)(a1 + 20) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
func0(a1, v3);
v4 = *(_BYTE *)(a1 + 21);
if ( v4 )
{
*(_BYTE *)(a1 + 21) = v4 - 1;
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
pthread_cond_signal((pthread_cond_t *)(a1 + 64));
}
else
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
result = 0LL;
}
else
{
func0(a1, (__int64)v2);
result = 0LL;
}
}
else
{
fprintf(stderr, "Allocate memory size %lu failed when put to queue...\n", 16LL);
result = 0xFFFFFFFFLL;
}
}
else
{
fwrite("WARNING : Put a value to NULL queue ...\n", 1uLL, 0x28uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int queue_put(QUEUE *queue , ElemType value)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : Put a value to NULL queue ...\n");
        return -1;
    }
    NODE *node = (NODE *)malloc(sizeof(NODE));
    if(((void *)0) == node)
    {
        fprintf(stderr , "Allocate memory size %lu failed when put to queue...\n" , sizeof(NODE));
        return -1;
    }
    node->value = value;
    node->next = ((void *)0);
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        add_to_list_tail(queue , node);
        int flag = 0;
        if(queue->waiting > 0)
        {
            flag = 1;
            queue->waiting --;
        }
        pthread_mutex_unlock(&(queue->lmutex));
        if(flag)
            pthread_cond_signal(&(queue->lcond));
    }
    else
    {
        add_to_list_tail(queue , node);
    }
    return 0;
}

canonical_original_code:
int queue_put(struct list *queue, void *value)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : Put a value to NULL queue ...\n");
        return -1;
    }
    struct node *node = (NODE *)malloc(sizeof(NODE));
    if(((void *)0) == node)
    {
        fprintf(stderr , "Allocate memory size %lu failed when put to queue...\n" , sizeof(NODE));
        return -1;
    }
    node->value = value;
    node->next = ((void *)0);
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        add_to_list_tail(queue , node);
        int flag = 0;
        if(queue->waiting > 0)
        {
            flag = 1;
            queue->waiting --;
        }
        pthread_mutex_unlock(&(queue->lmutex));
        if(flag)
            pthread_cond_signal(&(queue->lcond));
    }
    else
    {
        add_to_list_tail(queue , node);
    }
    return 0;
}


decompiled_code:
__int64 __fastcall queue_get(__int64 a1, _QWORD *a2)
{
if ( a1 )
return queue_get_inside(a1, a2, 1);
fwrite("WARNING : get value from a NULL queue ...\n", 1uLL, 0x2AuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2)
{
if ( a1 )
return func4(a1, a2, 1);
fwrite("WARNING : get value from a NULL queue ...\n", 1uLL, 0x2AuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int queue_get(QUEUE *queue , ElemType *val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 1);
}

canonical_original_code:
int queue_get(struct list *queue, void **val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 1);
}


decompiled_code:
__int64 __fastcall queue_get_nonblocking(__int64 a1, _QWORD *a2)
{
if ( a1 )
return queue_get_inside(a1, a2, 0);
fwrite("WARNING : nonblocking get value from a NULL queue ...\n", 1uLL, 0x36uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2)
{
if ( a1 )
return func4(a1, a2, 0);
fwrite("WARNING : nonblocking get value from a NULL queue ...\n", 1uLL, 0x36uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int queue_get_nonblocking(QUEUE *queue , ElemType *val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : nonblocking get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 0);
}

canonical_original_code:
int queue_get_nonblocking(struct list *queue, void **val)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : nonblocking get value from a NULL queue ...\n");
        return -1;
    }
    return queue_get_inside(queue , val , 0);
}


decompiled_code:
__int64 __fastcall queue_size(__int64 a1)
{
unsigned int v1; // ebx

if ( a1 )
{
if ( *(_BYTE *)(a1 + 20) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = list_size_inside((__int64 *)a1);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
else
{
v1 = list_size_inside((__int64 *)a1);
}
}
else
{
fwrite("WARNING : get size from a NULL queue ...\n", 1uLL, 0x29uLL, stderr);
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
unsigned int v1; // ebx

if ( a1 )
{
if ( *(_BYTE *)(a1 + 20) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = func2((__int64 *)a1);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
else
{
v1 = func2((__int64 *)a1);
}
}
else
{
fwrite("WARNING : get size from a NULL queue ...\n", 1uLL, 0x29uLL, stderr);
v1 = -1;
}
return v1;
}

original_code:
int queue_size(QUEUE *queue)
{
    if(((void *)0) == queue)
    {
        fprintf(stderr , "WARNING : get size from a NULL queue ...\n");
        return -1;
    }
    int size = 0;
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        size = list_size_inside(queue);
        pthread_mutex_unlock(&(queue->lmutex));
    }
    else
        size = list_size_inside(queue);
    return size;
}

canonical_original_code:
int queue_size(struct list *queue)
{
    if(((void *)0) == queue)
    {
        fprintf(stderr , "WARNING : get size from a NULL queue ...\n");
        return -1;
    }
    int size = 0;
    if(queue->need_lock)
    {
        pthread_mutex_lock(&(queue->lmutex));
        size = list_size_inside(queue);
        pthread_mutex_unlock(&(queue->lmutex));
    }
    else
        size = list_size_inside(queue);
    return size;
}

variable_types: size int


decompiled_code:
int __fastcall queue_info(__int64 a1)
{
const char *v1; // rsi
unsigned int v2; // eax

if ( !a1 )
return fwrite("WARNING : get queue info with a NULL queue ...\n", 1uLL, 0x2FuLL, stderr);
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
puts("Statics : ");
printf("sum elements counter : %d\n", *(unsigned int *)(a1 + 16));
v1 = "Yes";
if ( !*(_BYTE *)(a1 + 20) )
v1 = "No";
printf("With lock : %s and current waiting threads : %d\n", v1, *(unsigned __int8 *)(a1 + 21));
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
v2 = queue_size(a1);
return printf("Elements in the list : %d\n", v2);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
const char *v1; // rsi
unsigned int v2; // eax

if ( !a1 )
return fwrite("WARNING : get queue info with a NULL queue ...\n", 1uLL, 0x2FuLL, stderr);
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
puts("Statics : ");
printf("sum elements counter : %d\n", *(unsigned int *)(a1 + 16));
v1 = "Yes";
if ( !*(_BYTE *)(a1 + 20) )
v1 = "No";
printf("With lock : %s and current waiting threads : %d\n", v1, *(unsigned __int8 *)(a1 + 21));
if ( *(_BYTE *)(a1 + 20) )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
v2 = func9(a1);
return printf("Elements in the list : %d\n", v2);
}

original_code:
void queue_info(QUEUE *queue)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get queue info with a NULL queue ...\n");
        return ;
    }
    if(queue->need_lock)
        pthread_mutex_lock(&(queue->lmutex));
    printf("Statics : \n");
    printf("sum elements counter : %d\n" , queue->elems);
    printf("With lock : %s and current waiting threads : %d\n" ,
            queue->need_lock ? "Yes" : "No" , queue->waiting);
    if(queue->need_lock)
        pthread_mutex_unlock(&(queue->lmutex));
    printf("Elements in the list : %d\n" , queue_size(queue));
}

canonical_original_code:
void queue_info(struct list *queue)
{
    if(queue == ((void *)0))
    {
        fprintf(stderr , "WARNING : get queue info with a NULL queue ...\n");
        return ;
    }
    if(queue->need_lock)
        pthread_mutex_lock(&(queue->lmutex));
    printf("Statics : \n");
    printf("sum elements counter : %d\n" , queue->elems);
    printf("With lock : %s and current waiting threads : %d\n" ,
            queue->need_lock ? "Yes" : "No" , queue->waiting);
    if(queue->need_lock)
        pthread_mutex_unlock(&(queue->lmutex));
    printf("Elements in the list : %d\n" , queue_size(queue));
}


decompiled_code:
__int64 __fastcall queue_get_tail(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
if ( a1 )
{
if ( *(_BYTE *)(a1 + 20) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
else
{
v1 = *(_QWORD *)(a1 + 8);
}
}
else
{
fwrite("get tail from NULL queue ...\n", 1uLL, 0x1DuLL, stderr);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
if ( a1 )
{
if ( *(_BYTE *)(a1 + 20) )
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 24));
v1 = *(_QWORD *)(a1 + 8);
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 24));
}
else
{
v1 = *(_QWORD *)(a1 + 8);
}
}
else
{
fwrite("get tail from NULL queue ...\n", 1uLL, 0x1DuLL, stderr);
}
return v1;
}

original_code:
NODE *queue_get_tail(QUEUE *lst)
{
    if(((void *)0) == lst)
    {
        fprintf(stderr , "get tail from NULL queue ...\n");
        return ((void *)0);
    }
    NODE *node = ((void *)0);
    if(lst->need_lock)
    {
        pthread_mutex_lock(&(lst->lmutex));
        node = lst->tail;
        pthread_mutex_unlock(&(lst->lmutex));
    }
    else
        node = lst->tail;
    return node;
}

canonical_original_code:
struct node *queue_get_tail(struct list *lst)
{
    if(((void *)0) == lst)
    {
        fprintf(stderr , "get tail from NULL queue ...\n");
        return ((void *)0);
    }
    struct node *node = ((void *)0);
    if(lst->need_lock)
    {
        pthread_mutex_lock(&(lst->lmutex));
        node = lst->tail;
        pthread_mutex_unlock(&(lst->lmutex));
    }
    else
        node = lst->tail;
    return node;
}


decompiled_code:
int screen_savePic()
{
puts("save_savePic");
pthread_create(&talk_savePic_threadId, 0LL, savePic_thread, 0LL);
return pthread_join(talk_savePic_threadId, 0LL);
}

canonical_decompiled_code:
int func0()
{
puts("save_savePic");
pthread_create(&talk_savePic_threadId, 0LL, savePic_thread, 0LL);
return pthread_join(talk_savePic_threadId, 0LL);
}

original_code:
void screen_savePic()
{
printf("save_savePic\n");
    pthread_create(&talk_savePic_threadId, ((void *)0), (void *)savePic_thread, ((void *)0));
   pthread_join(talk_savePic_threadId,((void *)0));
}


decompiled_code:
__int64 fb_init()
{
unsigned int v0; // ebp
size_t v1; // rbx
int v3; // [rsp+0h] [rbp-108h] BYREF
int v4; // [rsp+4h] [rbp-104h]
unsigned int v5; // [rsp+18h] [rbp-F0h]
char v6[104]; // [rsp+A0h] [rbp-68h] BYREF

fb_dev_fd = open("/dev/fb0", 2);
printf("fb %d", (unsigned int)fb_dev_fd);
if ( !fb_dev_fd )
{
puts("Fail!");
exit(1);
}
v0 = ioctl(fb_dev_fd, 0x4600uLL, &v3);
if ( v0 )
{
printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", "fb_init");
v0 = -1;
}
else
{
ioctl(fb_dev_fd, 0x4602uLL, v6);
fb_Depth = v5 >> 3;
fb_Width = v3;
fb_Height = v4;
v1 = (int)((v5 >> 3) * v4 * v3);
framebuffer_data = malloc(v1);
read(fb_dev_fd, framebuffer_data, v1);
puts("\nclose fb");
close(fb_dev_fd);
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebp
size_t v1; // rbx
int v3; // [rsp+0h] [rbp-108h] BYREF
int v4; // [rsp+4h] [rbp-104h]
unsigned int v5; // [rsp+18h] [rbp-F0h]
char v6[104]; // [rsp+A0h] [rbp-68h] BYREF

fb_dev_fd = open("/dev/fb0", 2);
printf("fb %d", (unsigned int)fb_dev_fd);
if ( !fb_dev_fd )
{
puts("Fail!");
exit(1);
}
v0 = ioctl(fb_dev_fd, 0x4600uLL, &v3);
if ( v0 )
{
printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", "fb_init");
v0 = -1;
}
else
{
ioctl(fb_dev_fd, 0x4602uLL, v6);
fb_Depth = v5 >> 3;
fb_Width = v3;
fb_Height = v4;
v1 = (int)((v5 >> 3) * v4 * v3);
framebuffer_data = malloc(v1);
read(fb_dev_fd, framebuffer_data, v1);
puts("\nclose fb");
close(fb_dev_fd);
}
return v0;
}

original_code:
int fb_init(void){
 struct fb_fix_screeninfo fb_fix_info;
    struct fb_var_screeninfo fb_var_info;
    fb_dev_fd = open("/dev/fb0", 02);
printf("fb %d",fb_dev_fd);
 if(!fb_dev_fd){
 printf("Fail!\n");
 exit(1);
 }
    if (ioctl(fb_dev_fd, 0x4600, &fb_var_info) ) {
        printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", __FUNCTION__);
        return -1;
    }
    ioctl(fb_dev_fd,0x4602,&fb_fix_info);
    fb_Depth = fb_var_info.bits_per_pixel / 8;
    fb_Width = fb_var_info.xres;
    fb_Height = fb_var_info.yres;
    int data_size = fb_Width * fb_Height * fb_Depth;
    int len, i;
    framebuffer_data = (char *)malloc(data_size);
    len=read(fb_dev_fd, framebuffer_data, data_size);
printf("\nclose fb\n");
 close(fb_dev_fd);
 return 0;
}

canonical_original_code:
int fb_init(){
 struct fb_fix_screeninfo fb_fix_info;
    struct fb_var_screeninfo fb_var_info;
    fb_dev_fd = open("/dev/fb0", 02);
printf("fb %d",fb_dev_fd);
 if(!fb_dev_fd){
 printf("Fail!\n");
 exit(1);
 }
    if (ioctl(fb_dev_fd, 0x4600, &fb_var_info) ) {
        printf("%s : Can't ioctl FBIOGET_VSCREENINFO\n", __FUNCTION__);
        return -1;
    }
    ioctl(fb_dev_fd,0x4602,&fb_fix_info);
    fb_Depth = fb_var_info.bits_per_pixel / 8;
    fb_Width = fb_var_info.xres;
    fb_Height = fb_var_info.yres;
    int data_size = fb_Width * fb_Height * fb_Depth;
    int len; int i;
    framebuffer_data = (char *)malloc(data_size);
    len=read(fb_dev_fd, framebuffer_data, data_size);
printf("\nclose fb\n");
 close(fb_dev_fd);
 return 0;
}

variable_types: struct fb_fix_screeninfo { char id[16]; unsigned long smem_start; unsigned int smem_len; unsigned int type; unsigned int type_aux; unsigned int visual; unsigned short xpanstep; unsigned short ypanstep; unsigned short ywrapstep; unsigned int line_length; unsigned long mmio_start; unsigned int mmio_len; unsigned int accel; unsigned short capabilities; unsigned short reserved[2]; }

variable_types: struct fb_var_screeninfo { unsigned int xres; unsigned int yres; unsigned int xres_virtual; unsigned int yres_virtual; unsigned int xoffset; unsigned int yoffset; unsigned int bits_per_pixel; unsigned int grayscale; struct fb_bitfield { unsigned int offset; unsigned int length; unsigned int msb_right; } red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; unsigned int nonstd; unsigned int activate; unsigned int height; unsigned int width; unsigned int accel_flags; unsigned int pixclock; unsigned int left_margin; unsigned int right_margin; unsigned int upper_margin; unsigned int lower_margin; unsigned int hsync_len; unsigned int vsync_len; unsigned int sync; unsigned int vmode; unsigned int rotate; unsigned int colorspace; unsigned int reserved[4]; }

variable_types: len int

user_defined_types: struct fb_var_screeninfo { unsigned int xres; unsigned int yres; unsigned int xres_virtual; unsigned int yres_virtual; unsigned int xoffset; unsigned int yoffset; unsigned int bits_per_pixel; unsigned int grayscale; struct fb_bitfield red; struct fb_bitfield green; struct fb_bitfield blue; struct fb_bitfield transp; unsigned int nonstd; unsigned int activate; unsigned int height; unsigned int width; unsigned int accel_flags; unsigned int pixclock; unsigned int left_margin; unsigned int right_margin; unsigned int upper_margin; unsigned int lower_margin; unsigned int hsync_len; unsigned int vsync_len; unsigned int sync; unsigned int vmode; unsigned int rotate; unsigned int colorspace; unsigned int reserved[4]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)fb_init(argc, argv, envp) )
{
puts("framebuffer init fail!");
exit(1);
}
puts("Capture the screen..");
if ( argc == 1 )
{
if ( !getcwd(work_dir, 0x64uLL) )
{
puts("can't get present work directory");
exit(1);
}
*(_QWORD *)work_dir = 0x6E6565726373LL;
screen_savePic();
}
else if ( argc != 2 )
{
exit(1);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func1(argc, argv, envp) )
{
puts("framebuffer init fail!");
exit(1);
}
puts("Capture the screen..");
if ( argc == 1 )
{
if ( !getcwd(work_dir, 0x64uLL) )
{
puts("can't get present work directory");
exit(1);
}
*(_QWORD *)work_dir = 0x6E6565726373LL;
func0();
}
else if ( argc != 2 )
{
exit(1);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
if( fb_init() == 0){
    printf("Capture the screen..\n");
 if(argc == 1){
  if ( getcwd(work_dir, sizeof(work_dir)) != ((void *)0))
  {
   char* tmp = "screen";
   strncpy(work_dir,tmp,sizeof(tmp));
   screen_savePic();
  }else{
   printf("can't get present work directory\n");
   exit(1);
  }
 }else if( argc == 2){
 }else{
 exit(1);
 }
return 0;
}else{
 printf("framebuffer init fail!\n");
 exit(1);
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
if( fb_init() == 0){
    printf("Capture the screen..\n");
 if(argc == 1){
  if ( getcwd(work_dir, sizeof(work_dir)) != ((void *)0))
  {
   char *tmp = "screen";
   strncpy(work_dir,tmp,sizeof(tmp));
   screen_savePic();
  }else{
   printf("can't get present work directory\n");
   exit(1);
  }
 }else if( argc == 2){
 }else{
 exit(1);
 }
return 0;
}else{
 printf("framebuffer init fail!\n");
 exit(1);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
tmp
char *


freePic

decompiled_code:
void freePic()
{
if ( framebuffer_data )
{
free(framebuffer_data);
framebuffer_data = 0LL;
}
}

canonical_decompiled_code:
void func2()
{
if ( framebuffer_data )
{
free(framebuffer_data);
framebuffer_data = 0LL;
}
}

original_code:
void freePic()
{
    if(((void *)0) != framebuffer_data) {
        free(framebuffer_data);
        framebuffer_data = ((void *)0);
    }
}


decompiled_code:
void *__fastcall savePic_thread(void *a1)
{
puts("savePic_thread");
if ( framebuffer_data
&& !(unsigned int)rawData2Jpg((__int64)framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth) )
{
freePic();
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
puts("savePic_thread");
if ( framebuffer_data
&& !(unsigned int)func3((__int64)framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth) )
{
func2();
}
return 0LL;
}

original_code:
void* savePic_thread (void* unused)
{
  printf("savePic_thread\n");
    if (((void *)0) != framebuffer_data) {
        if (0 == rawData2Jpg(framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth)) {
            freePic();
        }
    }
    return ((void *)0);
}

canonical_original_code:
void *savePic_thread(void *unused)
{
  printf("savePic_thread\n");
    if (((void *)0) != framebuffer_data) {
        if (0 == rawData2Jpg(framebuffer_data, work_dir, fb_Width, fb_Height, fb_Depth)) {
            freePic();
        }
    }
    return ((void *)0);
}

variable_types:
unused
void *


fred

decompiled_code:
int __fastcall fred(unsigned int a1)
{
return printf("frex: we passed %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("frex: we passed %d\n", a1);
}

original_code:
void fred( int arg){
 printf("frex: we passed %d\n", arg);
}

canonical_original_code:
void fred(int arg){
 printf("frex: we passed %d\n", arg);
}

variable_types: arg int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bill("Hello World\n", argv, envp);
exit(0);
}

original_code:
int main(){
 bill("Hello World\n");
 exit(0);
}


bill

decompiled_code:
int __fastcall bill(const char *a1)
{
return printf("Bill: we passed!%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("Bill: we passed!%s\n", a1);
}

original_code:
void bill( char *arg){
 printf("Bill: we passed!%s\n",arg);
}

canonical_original_code:
void bill(char *arg){
 printf("Bill: we passed!%s\n",arg);
}

variable_types:
arg
char *


main

repo: tetsuok/conllx-to-tikz-dep

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebx

if ( argc == 1 )
{
v3 = (_BYTE *)(delim + 2);
}
else
{
if ( argc != 2 )
{
fprintf(stderr, "Usage: %s filename\n", *argv);
return -1;
}
v3 = (char *)argv[1];
}
latex_print_header(argc, argv, envp);
v4 = open_conllx(v3);
if ( v4 )
{
fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
v4 = -1;
}
else
{
latex_print_footer();
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebx

if ( argc == 1 )
{
v3 = (_BYTE *)(delim + 2);
}
else
{
if ( argc != 2 )
{
fprintf(stderr, "Usage: %s filename\n", *argv);
return -1;
}
v3 = (char *)argv[1];
}
func11(argc, argv, envp);
v4 = func8(v3);
if ( v4 )
{
fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
v4 = -1;
}
else
{
func12();
}
return v4;
}

original_code:
int main(int argc, char** argv)
{
    const char* filename = ((void *)0);
    if (argc == 1) {
        filename = "-";
    } else if (argc == 2) {
        filename = argv[1];
    } else {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        return -1;
    }
    latex_print_header();
    if (open_conllx(filename) != 0) {
        fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
        return -1;
    }
    latex_print_footer();
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *filename = ((void *)0);
    if (argc == 1) {
        filename = "-";
    } else if (argc == 2) {
        filename = argv[1];
    } else {
        fprintf(stderr, "Usage: %s filename\n", argv[0]);
        return -1;
    }
    latex_print_header();
    if (open_conllx(filename) != 0) {
        fprintf(stderr, "ERROR: failed to open %s\n", argv[1]);
        return -1;
    }
    latex_print_footer();
    return 0;
}

variable_types:
argv
char **

variable_types:
filename
char *


decompiled_code:
int __fastcall latex_print_deptext(__int64 a1)
{
__int64 v1; // rbx

puts("\\begin{deptext}[column sep=1em]");
v1 = 0LL;
if ( *(int *)a1 > 0 )
{
while ( 1 )
{
printf("%s", *(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1) + 8LL));
if ( *(_DWORD *)a1 <= (int)v1 + 1 )
break;
if ( (int)v1 + 1 > 0 )
printf(" \\& ");
++v1;
}
}
puts(" \\\\");
return puts("\\end{deptext}");
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
__int64 v1; // rbx

puts("\\begin{deptext}[column sep=1em]");
v1 = 0LL;
if ( *(int *)a1 > 0 )
{
while ( 1 )
{
printf("%s", *(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v1) + 8LL));
if ( *(_DWORD *)a1 <= (int)v1 + 1 )
break;
if ( (int)v1 + 1 > 0 )
printf(" \\& ");
++v1;
}
}
puts(" \\\\");
return puts("\\end{deptext}");
}

original_code:
void latex_print_deptext(const struct sentence* s)
{
    int i;
    printf("\\begin{deptext}[column sep=1em]\n");
    for (i = 0; i < s->length; i++) {
        if (i > 0) printf(" \\& ");
        printf("%s", s->tokens[i]->form);
    }
    puts(" \\\\");
    puts("\\end{deptext}");
}

canonical_original_code:
void latex_print_deptext(struct sentence *s)
{
    int i;
    printf("\\begin{deptext}[column sep=1em]\n");
    for (i = 0; i < s->length; i++) {
        if (i > 0) printf(" \\& ");
        printf("%s", s->tokens[i]->form);
    }
    puts(" \\\\");
    puts("\\end{deptext}");
}

variable_types: struct sentence { int length; int cap; struct token { int id; int head; char *form; char *lemma; char *cpos; char *pos; char *feat; char *deprel; char *phead; char *pdeprel; } **tokens; } *

variable_types: i int

user_defined_types: struct sentence { int length; int cap; struct token **tokens; }


decompiled_code:
int __fastcall latex_print_depedge(unsigned int a1, unsigned int a2)
{
return printf("\\depedge{%d}{%d}{}\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, unsigned int a2)
{
return printf("\\depedge{%d}{%d}{}\n", a1, a2);
}

original_code:
void latex_print_depedge(int h, int m)
{
    printf("\\depedge{%d}{%d}{}\n", h, m);
}

variable_types: h int

variable_types: m int


decompiled_code:
int latex_print_header()
{
puts("\\documentclass{standalone}");
puts("\\usepackage{tikz-dependency}");
puts("\\begin{document}");
return puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}

canonical_decompiled_code:
int func11()
{
puts("\\documentclass{standalone}");
puts("\\usepackage{tikz-dependency}");
puts("\\begin{document}");
return puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}

original_code:
void latex_print_header(void)
{
    puts("\\documentclass{standalone}");
    puts("\\usepackage{tikz-dependency}");
    puts("\\begin{document}");
    puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}

canonical_original_code:
void latex_print_header()
{
    puts("\\documentclass{standalone}");
    puts("\\usepackage{tikz-dependency}");
    puts("\\begin{document}");
    puts("\\begin{dependency}[theme = simple, edge style={<-}]");
}


decompiled_code:
int latex_print_footer()
{
puts("\\end{dependency}");
return puts("\\end{document}");
}

canonical_decompiled_code:
int func12()
{
puts("\\end{dependency}");
return puts("\\end{document}");
}

original_code:
void latex_print_footer(void)
{
    puts("\\end{dependency}");
    puts("\\end{document}");
}

canonical_original_code:
void latex_print_footer()
{
    puts("\\end{dependency}");
    puts("\\end{document}");
}


decompiled_code:
int __fastcall latex_print_dep_tree(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
unsigned int *v3; // rax

result = latex_print_deptext(a1);
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
result = is_root(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( !result )
{
v3 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 8 * v2);
result = latex_print_depedge(v3[1], *v3);
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
unsigned int *v3; // rax

result = func9(a1);
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
result = func16(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2));
if ( !result )
{
v3 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 8 * v2);
result = func10(v3[1], *v3);
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return result;
}

original_code:
void latex_print_dep_tree(const struct sentence* s)
{
    int i;
    latex_print_deptext(s);
    for (i = 0; i < s->length; i++) {
        if (is_root(s->tokens[i])) continue;
        latex_print_depedge(s->tokens[i]->head, s->tokens[i]->id);
    }
}

canonical_original_code:
void latex_print_dep_tree(struct sentence *s)
{
    int i;
    latex_print_deptext(s);
    for (i = 0; i < s->length; i++) {
        if (is_root(s->tokens[i])) continue;
        latex_print_depedge(s->tokens[i]->head, s->tokens[i]->id);
    }
}

user_defined_types: struct token { int id; int head; char *form; char *lemma; char *cpos; char *pos; char *feat; char *deprel; char *phead; char *pdeprel; }