decompiled_code:
void *__fastcall uniquify_name(char *s, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
size_t v7; // rbx
int v8; // er14
char *v9; // rbx
char *v10; // r13
unsigned int v11; // ebx
__int64 v12; // r8
void *v13; // rsp
char v15[8]; // [rsp+0h] [rbp-70h] BYREF
unsigned __int64 v16; // [rsp+8h] [rbp-68h]
void *ptr; // [rsp+10h] [rbp-60h] BYREF
__int16 v18; // [rsp+18h] [rbp-58h] BYREF
unsigned int v19; // [rsp+1Ah] [rbp-56h]
__int16 v20; // [rsp+1Eh] [rbp-52h]
void **v21; // [rsp+20h] [rbp-50h]
int v22; // [rsp+28h] [rbp-48h]
char *v23; // [rsp+38h] [rbp-38h]

v23 = &a7;
v18 = -17599;
v19 = (unsigned int)globally_unique_0;
v20 = -17847;
v21 = &ptr;
v22 = -1864106167;
ptr = strdup(s);
v7 = strlen(s);
v8 = v7;
v9 = &s[v7];
v10 = strrchr(s, 46);
if ( !v10 )
v10 = v9;
v11 = 2;
v16 = (unsigned __int64)(v8 + 10 + 15LL) >> 4;
while ( (unsigned int)map_leaf_entries(a2, &v18) )
{
v12 = v11++;
v13 = alloca(16 * v16);
sprintf(v15, "%.*s %d%s", (_DWORD)v10 - (_DWORD)s, s, v12, v10);
free(ptr);
ptr = strdup(v15);
}
return ptr;
}

canonical_decompiled_code:
void *__fastcall func9(char *s, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
size_t v7; // rbx
int v8; // er14
char *v9; // rbx
char *v10; // r13
unsigned int v11; // ebx
__int64 v12; // r8
void *v13; // rsp
char v15[8]; // [rsp+0h] [rbp-70h] BYREF
unsigned __int64 v16; // [rsp+8h] [rbp-68h]
void *ptr; // [rsp+10h] [rbp-60h] BYREF
__int16 v18; // [rsp+18h] [rbp-58h] BYREF
unsigned int v19; // [rsp+1Ah] [rbp-56h]
__int16 v20; // [rsp+1Eh] [rbp-52h]
void **v21; // [rsp+20h] [rbp-50h]
int v22; // [rsp+28h] [rbp-48h]
char *v23; // [rsp+38h] [rbp-38h]

v23 = &a7;
v18 = -17599;
v19 = (unsigned int)globally_unique_0;
v20 = -17847;
v21 = &ptr;
v22 = -1864106167;
ptr = strdup(s);
v7 = strlen(s);
v8 = v7;
v9 = &s[v7];
v10 = strrchr(s, 46);
if ( !v10 )
v10 = v9;
v11 = 2;
v16 = (unsigned __int64)(v8 + 10 + 15LL) >> 4;
while ( (unsigned int)map_leaf_entries(a2, &v18) )
{
v12 = v11++;
v13 = alloca(16 * v16);
sprintf(v15, "%.*s %d%s", (_DWORD)v10 - (_DWORD)s, s, v12, v10);
free(ptr);
ptr = strdup(v15);
}
return ptr;
}

original_code:
char *uniquify_name (char *name, struct atrfs_entry *root)
{
 char *uniq = strdup (name);
 int globally_unique (struct atrfs_entry *ent)
 {
  if (strcmp (uniq, ent->name) == 0)
   return 1;
  return 0;
 }
 int len = strlen (name);
 char *ext = strrchr (name, '.');
 if (! ext)
  ext = name + strlen (name);
 int i;
 for (i = 2;; i++)
 {
  if (map_leaf_entries (root, globally_unique) == 0)
  {
   return uniq;
  } else {
   char buf[len + 10];
   sprintf (buf, "%.*s %d%s", (int)(ext - name), name, i, ext);
   free (uniq);
   uniq = strdup (buf);
  }
 }
}

canonical_original_code:
char *uniquify_name(char *name, struct atrfs_entry *root)
{
 char *uniq = strdup (name);
 int globally_unique (struct atrfs_entry *ent)
 {
  if (strcmp (uniq, ent->name) == 0)
   return 1;
  return 0;
 }
 int len = strlen (name);
 char *ext = strrchr (name, '.');
 if (! ext)
  ext = name + strlen (name);
 int i;
 for (i = 2;; i++)
 {
  if (map_leaf_entries (root, globally_unique) == 0)
  {
   return uniq;
  } else {
   char buf[-1];
   sprintf (buf, "%.*s %d%s", (int)(ext - name), name, i, ext);
   free (uniq);
   uniq = strdup (buf);
  }
 }
}

variable_types:
name
char *

variable_types:
uniq
char *

variable_types:
ext
char *

variable_types:
buf
char [-1]


repo: terrop/atrfs

decompiled_code:
char *__fastcall get_related_name(const char *a1, const char *a2, const char *a3)
{
char *v4; // rax
char *v5; // r12
char *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
v4 = strrchr(a1, 46);
v5 = v4;
if ( !v4 )
return v5;
if ( strcmp(v4, a2) )
return 0LL;
asprintf(&ptr, "%.*s%s", (_DWORD)v5 - (_DWORD)a1, a1, a3);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func10(const char *a1, const char *a2, const char *a3)
{
char *v4; // rax
char *v5; // r12
char *ptr; // [rsp+8h] [rbp-30h] BYREF

ptr = 0LL;
v4 = strrchr(a1, 46);
v5 = v4;
if ( !v4 )
return v5;
if ( strcmp(v4, a2) )
return 0LL;
asprintf(&ptr, "%.*s%s", (_DWORD)v5 - (_DWORD)a1, a1, a3);
return ptr;
}

original_code:
char *get_related_name (char *filename, char *old_ext, char *new_ext)
{
 char *srtname = ((void *)0);
 char *ext = strrchr (filename, '.');
 if (ext && !strcmp (ext, old_ext))
  asprintf (&srtname, "%.*s%s", (int)(ext - filename), filename, new_ext);
 return srtname;
}

canonical_original_code:
char *get_related_name(char *filename, char *old_ext, char *new_ext)
{
 char *srtname = ((void *)0);
 char *ext = strrchr (filename, '.');
 if (ext && !strcmp (ext, old_ext))
  asprintf (&srtname, "%.*s%s", (int)(ext - filename), filename, new_ext);
 return srtname;
}

variable_types:
filename
char *

variable_types:
srtname
char *

return_type: char *


decompiled_code:
char *__fastcall secs_to_timestr(double a1)
{
count_4 = (count_4 + 1) % 2;
sprintf(&buf_3[10 * count_4], "%02d:%02d", (unsigned int)((int)a1 / 60), (unsigned int)((int)a1 % 60));
return &buf_3[10 * count_4];
}

canonical_decompiled_code:
char *__fastcall func12(double a1)
{
count_4 = (count_4 + 1) % 2;
sprintf(&buf_3[10 * count_4], "%02d:%02d", (unsigned int)((int)a1 / 60), (unsigned int)((int)a1 % 60));
return &buf_3[10 * count_4];
}

original_code:
char *secs_to_timestr (double secs)
{
 static int count;
 static char buf[2][10];
 int min = (int)secs / 60;
 int sec = (int)secs % 60;
 count = (count + 1) % 2;
 sprintf (buf[count], "%02d:%02d", min, sec);
 return buf[count];
}

canonical_original_code:
char *secs_to_timestr(double secs)
{
 static int count;
 static char buf[2][10];
 int min = (int)secs / 60;
 int sec = (int)secs % 60;
 count = (count + 1) % 2;
 sprintf (buf[count], "%02d:%02d", min, sec);
 return buf[count];
}

variable_types: secs double

variable_types: count int

variable_types:
buf
char [2][10]

variable_types: min int

variable_types: sec int


decompiled_code:
char __fastcall add_file_when_supported(char *s)
{
char *v1; // rax
bool v2; // zf
__int64 v3; // r12
char *v4; // rax
void *v5; // r13
__int64 v6; // r12
const char *v7; // rbp
char *v8; // rax

v1 = strrchr(s, 46);
if ( v1 )
{
if ( !strcmp(v1, ".flv") || (v2 = strcmp(v1, ".webm") == 0, LOBYTE(v1) = !v2, v2) )
{
v3 = root;
v4 = basename(s);
v5 = (void *)uniquify_name(v4, v3);
v6 = create_entry(0LL);
attach_entry(root, v6, v5);
*(_QWORD *)(v6 + 48) = strdup(s);
free(v5);
v7 = (const char *)get_sha1_fast(*(_QWORD *)(v6 + 48));
entrydb_ensure_exists(v7);
v8 = strdup(v7);
LOBYTE(v1) = g_hash_table_replace(sha1_to_entry_map, v8, v6);
}
}
return (char)v1;
}

canonical_decompiled_code:
char __fastcall func0(char *s)
{
char *v1; // rax
bool v2; // zf
__int64 v3; // r12
char *v4; // rax
void *v5; // r13
__int64 v6; // r12
const char *v7; // rbp
char *v8; // rax

v1 = strrchr(s, 46);
if ( v1 )
{
if ( !strcmp(v1, ".flv") || (v2 = strcmp(v1, ".webm") == 0, LOBYTE(v1) = !v2, v2) )
{
v3 = root;
v4 = basename(s);
v5 = (void *)uniquify_name(v4, v3);
v6 = create_entry(0LL);
attach_entry(root, v6, v5);
*(_QWORD *)(v6 + 48) = strdup(s);
free(v5);
v7 = (const char *)get_sha1_fast(*(_QWORD *)(v6 + 48));
entrydb_ensure_exists(v7);
v8 = strdup(v7);
LOBYTE(v1) = g_hash_table_replace(sha1_to_entry_map, v8, v6);
}
}
return (char)v1;
}

original_code:
static void add_file_when_supported(const char *filename)
{
 struct atrfs_entry *ent;
 char *uniq_name;
 char *ext = strrchr (filename, '.');
 if (!ext)
  return;
 if (strcmp (ext, ".flv") && strcmp(ext, ".webm"))
  return;
 uniq_name = uniquify_name(basename(filename), root);
 ent = create_entry (ATRFS_FILE_ENTRY);
 attach_entry (root, ent, uniq_name);
 (((struct atrfs_file_entry *)(ent))->real_path) = strdup(filename);
 free(uniq_name);
 char *sha1 = get_sha1_fast ((((struct atrfs_file_entry *)(ent))->real_path));
 entrydb_ensure_exists (sha1);
 g_hash_table_replace (sha1_to_entry_map, strdup(sha1), ent);
}

canonical_original_code:
static void add_file_when_supported(char *filename)
{
 struct atrfs_entry *ent;
 char *uniq_name;
 char *ext = strrchr (filename, '.');
 if (!ext)
  return;
 if (strcmp (ext, ".flv") && strcmp(ext, ".webm"))
  return;
 uniq_name = uniquify_name(basename(filename), root);
 ent = create_entry (ATRFS_FILE_ENTRY);
 attach_entry (root, ent, uniq_name);
 (((struct atrfs_file_entry *)(ent))->real_path) = strdup(filename);
 free(uniq_name);
 char *sha1 = get_sha1_fast ((((struct atrfs_file_entry *)(ent))->real_path));
 entrydb_ensure_exists (sha1);
 g_hash_table_replace (sha1_to_entry_map, strdup(sha1), ent);
}

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

return_type: void

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_file_entry { struct atrfs_entry entry; int fd; char *real_path; double start_time; struct atrfs_entry *subtitles; }

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:
__int64 __fastcall populate_stat_dir(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rsi
const __m128i *v4; // rax
__m128i v5; // xmm1
__int64 v6; // rax
__int64 v7; // rsi
const __m128i *v8; // rax
__m128i v9; // xmm3

v1 = create_entry(2LL);
attach_entry(a1, v1, "top-list");
v2 = create_entry(2LL);
attach_entry(a1, v2, "last-list");
v3 = create_entry(2LL);
v4 = *(const __m128i **)(v3 + 32);
statcount_ops_2 = (__int128)_mm_loadu_si128(v4);
v5 = _mm_loadu_si128(v4 + 1);
*((_QWORD *)&statcount_ops_2 + 1) = &write_statcount;
xmmword_590 = (__int128)v5;
*(_QWORD *)(v3 + 32) = &statcount_ops_2;
attach_entry(a1, v3, "stat-count");
v6 = create_entry(2LL);
attach_entry(a1, v6, "recent");
v7 = create_entry(2LL);
v8 = *(const __m128i **)(v7 + 32);
language_ops_1 = (__int128)_mm_loadu_si128(v8);
v9 = _mm_loadu_si128(v8 + 1);
*((_QWORD *)&language_ops_1 + 1) = &write_language;
xmmword_570 = (__int128)v9;
*(_QWORD *)(v7 + 32) = &language_ops_1;
attach_entry(a1, v7, "language");
return update_stats();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rsi
const __m128i *v4; // rax
__m128i v5; // xmm1
__int64 v6; // rax
__int64 v7; // rsi
const __m128i *v8; // rax
__m128i v9; // xmm3

v1 = create_entry(2LL);
attach_entry(a1, v1, "top-list");
v2 = create_entry(2LL);
attach_entry(a1, v2, "last-list");
v3 = create_entry(2LL);
v4 = *(const __m128i **)(v3 + 32);
statcount_ops_2 = (__int128)_mm_loadu_si128(v4);
v5 = _mm_loadu_si128(v4 + 1);
*((_QWORD *)&statcount_ops_2 + 1) = &write_statcount;
xmmword_590 = (__int128)v5;
*(_QWORD *)(v3 + 32) = &statcount_ops_2;
attach_entry(a1, v3, "stat-count");
v6 = create_entry(2LL);
attach_entry(a1, v6, "recent");
v7 = create_entry(2LL);
v8 = *(const __m128i **)(v7 + 32);
language_ops_1 = (__int128)_mm_loadu_si128(v8);
v9 = _mm_loadu_si128(v8 + 1);
*((_QWORD *)&language_ops_1 + 1) = &write_language;
xmmword_570 = (__int128)v9;
*(_QWORD *)(v7 + 32) = &language_ops_1;
attach_entry(a1, v7, "language");
return update_stats();
}

original_code:
static void populate_stat_dir(struct atrfs_entry *statroot)
{
 static struct atrfs_entry_ops statcount_ops;
 static struct atrfs_entry_ops language_ops;
 struct atrfs_entry *ent;
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 attach_entry (statroot, ent, "top-list");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 attach_entry (statroot, ent, "last-list");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 statcount_ops = *ent->ops;
 statcount_ops.write = write_statcount;
 ent->ops = &statcount_ops;
 attach_entry (statroot, ent, "stat-count");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 attach_entry (statroot, ent, "recent");
 ent = create_entry (ATRFS_VIRTUAL_FILE_ENTRY);
 language_ops = *ent->ops;
 language_ops.write = write_language;
 ent->ops = &language_ops;
 attach_entry (statroot, ent, "language");
 update_stats();
}

variable_types: struct atrfs_entry_ops { long (*read)(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 *ops; } *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); }


decompiled_code:
char *__fastcall write_language(__int64 a1, const char *a2, size_t a3)
{
char *result; // rax

free(language_list);
result = strndup(a2, a3);
language_list = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, const char *a2, size_t a3)
{
char *result; // rax

free(language_list);
result = strndup(a2, a3);
language_list = result;
return result;
}

original_code:
static void write_language(struct atrfs_entry *ent, const char *buf, size_t size)
{
 free(language_list);
 language_list = strndup(buf, size);
}

canonical_original_code:
static void write_language(struct atrfs_entry *ent, char *buf, unsigned long size)
{
 free(language_list);
 language_list = strndup(buf, size);
}

variable_types:
buf
char *

variable_types:
size
unsigned long

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:
int __fastcall write_statcount(__int64 a1, const char *a2)
{
int result; // eax

result = atoi(a2);
stat_count = result;
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, const char *a2)
{
int result; // eax

result = atoi(a2);
stat_count = result;
return result;
}

original_code:
static void write_statcount(struct atrfs_entry *ent, const char *buf, size_t size)
{
 stat_count = atoi(buf);
}

canonical_original_code:
static void write_statcount(struct atrfs_entry *ent, char *buf, unsigned long size)
{
 stat_count = atoi(buf);
}


decompiled_code:
__int64 __fastcall add_notify(char *name, uint32_t mask)
{
int v3; // edi

v3 = notify_fd;
if ( notify_fd < 0 )
{
notify_fd = inotify_init1(2048);
v3 = notify_fd;
*((_DWORD *)&pfd + 2) = notify_fd;
*((_WORD *)&pfd + 6) = 1;
}
inotify_add_watch(v3, name, mask);
return tmplog("Watching '%s'\n", name);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name, uint32_t mask)
{
int v3; // edi

v3 = notify_fd;
if ( notify_fd < 0 )
{
notify_fd = inotify_init1(2048);
v3 = notify_fd;
*((_DWORD *)&pfd + 2) = notify_fd;
*((_WORD *)&pfd + 6) = 1;
}
inotify_add_watch(v3, name, mask);
return tmplog("Watching '%s'\n", name);
}

original_code:
void add_notify(const char *dirname, uint32_t mask)
{
 if (notify_fd < 0)
 {
  notify_fd = inotify_init1(IN_NONBLOCK);
  pfd[1].fd = notify_fd;
  pfd[1].events = 0x001;
 }
 inotify_add_watch(notify_fd, dirname, mask);
 tmplog("Watching '%s'\n", dirname);
}

canonical_original_code:
void add_notify(char *dirname, unsigned int mask)
{
 if (notify_fd < 0)
 {
  notify_fd = inotify_init1(IN_NONBLOCK);
  pfd[1].fd = notify_fd;
  pfd[1].events = 0x001;
 }
 inotify_add_watch(notify_fd, dirname, mask);
 tmplog("Watching '%s'\n", dirname);
}

variable_types:
dirname
char *

variable_types:
mask
unsigned int


original_code:
void handle_notify(void)
{
 char ibuf[256];
 int i = 0;
 int len = read(notify_fd, ibuf, sizeof(ibuf));
 while (i < len)
 {
  struct inotify_event *ie = (struct inotify_event *)&ibuf[i];
  i += sizeof(struct inotify_event) + ie->len;
  if (!ie->len)
   continue;
  tmplog("'%s': %s", ie->name, ie->mask & 0x40000000 ? "dir" : "file");
  if (ie->mask & 0x00004000)
   tmplog(", Q_OVERFLOW");
  if (ie->mask & 0x00002000)
   tmplog(", UNMOUNT");
  if (ie->mask & 0x00008000)
   tmplog(", IGNORED");
  if (ie->mask & 0x00000001)
   tmplog(", ACCESS");
  if (ie->mask & 0x00000004)
   tmplog(", ATTRIB");
  if (ie->mask & 0x00000008)
   tmplog(", CLOSE_WRITE");
  if (ie->mask & 0x00000010)
   tmplog(", CLOSE_NOWRITE");
  if (ie->mask & 0x00000100)
   tmplog(", CREATE");
  if (ie->mask & 0x00000200)
   tmplog(", DELETE");
  if (ie->mask & 0x00000400)
   tmplog(", DELETE_SELF");
  if (ie->mask & 0x00000002)
   tmplog(", MODIFY");
  if (ie->mask & 0x00000800)
   tmplog(", MOVE_SELF");
  if (ie->mask & 0x00000040)
   tmplog(", MOVED_FROM (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000080)
   tmplog(", MOVED_TO (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000020)
   tmplog(", OPEN");
  tmplog("\n");
 }
}

canonical_original_code:
void handle_notify()
{
 char ibuf[256];
 int i = 0;
 int len = read(notify_fd, ibuf, sizeof(ibuf));
 while (i < len)
 {
  struct inotify_event *ie = (struct inotify_event *)&ibuf[i];
  i += sizeof(struct inotify_event) + ie->len;
  if (!ie->len)
   continue;
  tmplog("'%s': %s", ie->name, ie->mask & 0x40000000 ? "dir" : "file");
  if (ie->mask & 0x00004000)
   tmplog(", Q_OVERFLOW");
  if (ie->mask & 0x00002000)
   tmplog(", UNMOUNT");
  if (ie->mask & 0x00008000)
   tmplog(", IGNORED");
  if (ie->mask & 0x00000001)
   tmplog(", ACCESS");
  if (ie->mask & 0x00000004)
   tmplog(", ATTRIB");
  if (ie->mask & 0x00000008)
   tmplog(", CLOSE_WRITE");
  if (ie->mask & 0x00000010)
   tmplog(", CLOSE_NOWRITE");
  if (ie->mask & 0x00000100)
   tmplog(", CREATE");
  if (ie->mask & 0x00000200)
   tmplog(", DELETE");
  if (ie->mask & 0x00000400)
   tmplog(", DELETE_SELF");
  if (ie->mask & 0x00000002)
   tmplog(", MODIFY");
  if (ie->mask & 0x00000800)
   tmplog(", MOVE_SELF");
  if (ie->mask & 0x00000040)
   tmplog(", MOVED_FROM (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000080)
   tmplog(", MOVED_TO (cookie=%d)", ie->cookie);
  if (ie->mask & 0x00000020)
   tmplog(", OPEN");
  tmplog("\n");
 }
}

variable_types:
ibuf
char [256]

variable_types: i int

variable_types: len int

variable_types: struct inotify_event { int wd; unsigned int mask; unsigned int cookie; unsigned int len; char name[]; } *


decompiled_code:
void __fastcall set_virtual_contents(__int64 a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a1 + 40) = a2;
*(_QWORD *)(a1 + 48) = a3;
}

original_code:
static void set_virtual_contents(struct atrfs_entry *ent, char *str, size_t sz)
{
 ((struct atrfs_virtual_entry*)(ent))->m_data = str;
 ((struct atrfs_virtual_entry*)(ent))->m_size = sz;
}

canonical_original_code:
static void set_virtual_contents(struct atrfs_entry *ent, char *str, unsigned long sz)
{
 ((struct atrfs_virtual_entry *)(ent))->m_data = str;
 ((struct atrfs_virtual_entry *)(ent))->m_size = sz;
}

variable_types:
str
char *

variable_types:
sz
unsigned long

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


original_code:
static int virtual_stat (struct atrfs_entry *ent, struct stat *st)
{
 st->st_ino = (ino_t)(unsigned long)ent;
 st->st_nlink = 1;
 st->st_size = ((struct atrfs_virtual_entry*)(ent))->m_size;
 st->st_mode = 0100000 | 0400;
 st->st_uid = getuid();
 st->st_gid = getgid();
 st->st_atim.tv_sec =
 st->st_mtim.tv_sec =
 st->st_ctim.tv_sec = time (((void *)0));
 return 0;
}

canonical_original_code:
static int virtual_stat(struct atrfs_entry *ent, struct stat *st)
{
 st->st_ino = (unsigned long)(unsigned long)ent;
 st->st_nlink = 1;
 st->st_size = ((struct atrfs_virtual_entry *)(ent))->m_size;
 st->st_mode = 0100000 | 0400;
 st->st_uid = getuid();
 st->st_gid = getgid();
 st->st_atim.tv_sec =
 st->st_mtim.tv_sec =
 st->st_ctim.tv_sec = time (((void *)0));
 return 0;
}

variable_types:
st
struct stat *

return_type: int


decompiled_code:
size_t __fastcall virtual_read(__int64 a1, void *a2, size_t a3, __int64 a4)
{
size_t v4; // r12
size_t v5; // r12

v4 = *(_QWORD *)(a1 + 48);
if ( v4 < a4 + a3 )
{
v5 = v4 - a4;
a3 = v5;
}
else
{
v5 = a3;
}
memcpy(a2, (const void *)(a4 + *(_QWORD *)(a1 + 40)), a3);
return v5;
}

original_code:
static ssize_t virtual_read (struct atrfs_entry *ent, char *buf, size_t size, off_t offset)
{
 ssize_t count = ((struct atrfs_virtual_entry*)(ent))->m_size;
 if (offset + size > count)
  size = count - offset;
 memcpy (buf, ((struct atrfs_virtual_entry*)(ent))->m_data + offset, size);
 return size;
}

canonical_original_code:
static long virtual_read(struct atrfs_entry *ent, char *buf, unsigned long size, long offset)
{
 long count = ((struct atrfs_virtual_entry*)(ent))->m_size;
 if (offset + size > count)
  size = count - offset;
 memcpy (buf, ((struct atrfs_virtual_entry *)(ent))->m_data + offset, size);
 return size;
}

variable_types: offset long

variable_types: count long

return_type: long


decompiled_code:
__int64 __fastcall file_read(__int64 a1, void *a2, size_t a3, __off64_t a4)
{
return (int)pread64(*(_DWORD *)(a1 + 40), a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, void *a2, size_t a3, __off64_t a4)
{
return (int)pread64(*(_DWORD *)(a1 + 40), a2, a3, a4);
}

original_code:
static ssize_t file_read (struct atrfs_entry *ent, char *buf, size_t size, off_t offset)
{
 int ret = pread (((struct atrfs_file_entry *)(ent))->fd, buf, size, offset);
 return ret;
}

canonical_original_code:
static long file_read(struct atrfs_entry *ent, char *buf, unsigned long size, long offset)
{
 int ret = pread (((struct atrfs_file_entry *)(ent))->fd, buf, size, offset);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall ino_to_entry(__int64 a1)
{
__int64 v1; // r12

v1 = a1;
if ( a1 == 1 )
v1 = root;
if ( (*(_BYTE *)(v1 + 24) & 2) != 0 )
tmplog("Warning: deleted entry accessed\n");
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r12

v1 = a1;
if ( a1 == 1 )
v1 = root;
if ( (*(_BYTE *)(v1 + 24) & 2) != 0 )
tmplog("Warning: deleted entry accessed\n");
return v1;
}

original_code:
struct atrfs_entry *ino_to_entry(fuse_ino_t ino)
{
 struct atrfs_entry *ent = (struct atrfs_entry *)ino;
 if (ino == 1)
  ent = root;
 if (ent->flags & ENTRY_DELETED)
  tmplog("Warning: deleted entry accessed\n");
 return ent;
}

canonical_original_code:
struct atrfs_entry *ino_to_entry(unsigned long ino)
{
 struct atrfs_entry *ent = (struct atrfs_entry *)ino;
 if (ino == 1)
  ent = root;
 if (ent->flags & ENTRY_DELETED)
  tmplog("Warning: deleted entry accessed\n");
 return ent;
}

variable_types:
ino
unsigned long

return_type: 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; } *


decompiled_code:
__int64 __fastcall get_watchcount(__int64 a1)
{
return get_ivalue(a1, "count", 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return get_ivalue(a1, "count", 0LL);
}

original_code:
int get_watchcount(struct atrfs_entry *ent)
{
 return get_ivalue (ent, "count", 0);
}

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


decompiled_code:
__int64 __fastcall get_watchtime(__int64 a1)
{
return get_dvalue(a1, "watchtime", 0.0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return get_dvalue(a1, "watchtime", 0.0);
}

original_code:
double get_watchtime(struct atrfs_entry *ent)
{
 return get_dvalue (ent, "watchtime", 0.0);
}

return_type: double


decompiled_code:
__int64 __fastcall file_stat(__int64 a1, struct stat64 *a2, double a3)
{
if ( stat64(*(const char **)(a1 + 48), a2) < 0 )
return (unsigned int)*_errno_location();
a2->st_nlink = (int)get_watchcount(a1);
get_watchtime(a1);
a2->st_ino = a1;
a2->st_mtim.tv_sec = (unsigned int)(int)(a3 + 946677600.0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, struct stat64 *a2, double a3)
{
if ( stat64(*(const char **)(a1 + 48), a2) < 0 )
return (unsigned int)*_errno_location();
a2->st_nlink = (int)func7(a1);
func8(a1);
a2->st_ino = a1;
a2->st_mtim.tv_sec = (unsigned int)(int)(a3 + 946677600.0);
return 0LL;
}

original_code:
static int file_stat (struct atrfs_entry *ent, struct stat *st)
{
 char *filename = (((struct atrfs_file_entry *)(ent))->real_path);
 if (stat (filename, st) < 0)
  return (*__errno_location ());
 st->st_nlink = get_watchcount (ent);
 st->st_mtim.tv_sec = (time_t)(get_watchtime (ent) + 946677600.0);
 st->st_ino = (ino_t)(unsigned long)ent;
 return 0;
}

canonical_original_code:
static int file_stat(struct atrfs_entry *ent, struct stat *st)
{
 char *filename = (((struct atrfs_file_entry *)(ent))->real_path);
 if (stat (filename, st) < 0)
  return (*__errno_location ());
 st->st_nlink = get_watchcount (ent);
 st->st_mtim.tv_sec = (time_t)(get_watchtime (ent) + 946677600.0);
 st->st_ino = (unsigned long)(unsigned long)ent;
 return 0;
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall lookup_entry_by_name(__int64 a1)
{
if ( !a1 || *(_DWORD *)a1 != 1 )
lookup_entry_by_name_cold();
return (*(__int64 (**)(void))(*(_QWORD *)(a1 + 32) + 24LL))();
}

original_code:
struct atrfs_entry *lookup_entry_by_name (struct atrfs_entry *dir, const char *name)
{
 do { if (!(dir) || (dir)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 return dir->ops->lookup_entry_by_name (dir, name);
}

canonical_original_code:
struct atrfs_entry *lookup_entry_by_name(struct atrfs_entry *dir, char *name)
{
 do { if (!(dir) || (dir)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 return dir->ops->lookup_entry_by_name (dir, name);
}

variable_types:
dir
struct atrfs_entry *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall map_leaf_entries(__int64 a1, __int64 (*a2)(void))
{
__int64 v2; // rax
__int64 v3; // r13
int **v4; // rbx
unsigned int v5; // eax
int v6; // eax
unsigned int v8; // [rsp+Ch] [rbp-1Ch]

if ( !a1 || *(_DWORD *)a1 != 1 )
map_leaf_entries_cold();
v2 = g_hash_table_get_values(*(_QWORD *)(a1 + 40));
v3 = v2;
if ( v2 )
{
v4 = (int **)v2;
do
{
v6 = **v4;
if ( v6 == 1 )
{
v5 = map_leaf_entries(*v4, a2);
if ( v5 )
goto LABEL_11;
}
else
{
if ( (v6 & 0xFFFFFFFD) != 0 )
abort();
v5 = a2();
if ( v5 )
goto LABEL_11;
}
v4 = (int **)v4[1];
}
while ( v4 );
}
v5 = 0;
LABEL_11:
v8 = v5;
g_list_free(v3);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 (*a2)(void))
{
__int64 v2; // rax
__int64 v3; // r13
int **v4; // rbx
unsigned int v5; // eax
int v6; // eax
unsigned int v8; // [rsp+Ch] [rbp-1Ch]

if ( !a1 || *(_DWORD *)a1 != 1 )
func23();
v2 = g_hash_table_get_values(*(_QWORD *)(a1 + 40));
v3 = v2;
if ( v2 )
{
v4 = (int **)v2;
do
{
v6 = **v4;
if ( v6 == 1 )
{
v5 = func16(*v4, a2);
if ( v5 )
goto LABEL_11;
}
else
{
if ( (v6 & 0xFFFFFFFD) != 0 )
abort();
v5 = a2();
if ( v5 )
goto LABEL_11;
}
v4 = (int **)v4[1];
}
while ( v4 );
}
v5 = 0;
LABEL_11:
v8 = v5;
g_list_free(v3);
return v8;
}

original_code:
int map_leaf_entries (struct atrfs_entry *root, int (*fn) (struct atrfs_entry *ent))
{
 do { if (!(root) || (root)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 int ret = 0;
 GList *p, *entries = g_hash_table_get_values (((struct atrfs_directory_entry *)(root))->contents);
 struct atrfs_entry *ent;
 for (p = entries; p; p = p->next)
 {
  ent = p->data;
  switch (ent->e_type)
  {
  default:
   abort ();
  case ATRFS_DIRECTORY_ENTRY:
   ret = map_leaf_entries (ent, fn);
   if (ret)
    goto out;
   break;
  case ATRFS_VIRTUAL_FILE_ENTRY:
  case ATRFS_FILE_ENTRY:
   ret = fn (ent);
   if (ret)
    goto out;
   break;
  }
 }
out:
 g_list_free (entries);
 return ret;
}

canonical_original_code:
int map_leaf_entries(struct atrfs_entry *root, int (*fn)(struct atrfs_entry *ent))
{
 do { if (!(root) || (root)->e_type != (ATRFS_DIRECTORY_ENTRY)) abort ();} while(0);
 int ret = 0;
 struct _GList *p; struct _GList *entries = g_hash_table_get_values (((struct atrfs_directory_entry *)(root))->contents);
 struct atrfs_entry *ent;
 for (p = entries; p; p = p->next)
 {
  ent = p->data;
  switch (ent->e_type)
  {
  default:
   abort ();
  case ATRFS_DIRECTORY_ENTRY:
   ret = map_leaf_entries (ent, fn);
   if (ret)
    goto out;
   break;
  case ATRFS_VIRTUAL_FILE_ENTRY:
  case ATRFS_FILE_ENTRY:
   ret = fn (ent);
   if (ret)
    goto out;
   break;
  }
 }
out:
 g_list_free (entries);
 return ret;
}

variable_types:
fn
int (*)(struct atrfs_entry *ent)

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


decompiled_code:
__int64 __fastcall get_realname(__int64 a1)
{
return *(_QWORD *)(a1 + 48);
}

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

original_code:
static char *get_realname(struct atrfs_entry *ent)
{
 return (((struct atrfs_file_entry *)(ent))->real_path);
}


decompiled_code:
char *get_countstr()
{
unsigned int v0; // eax

v0 = get_watchcount();
sprintf(buf_1, "%d", v0);
return buf_1;
}

canonical_decompiled_code:
char *func1()
{
unsigned int v0; // eax

v0 = get_watchcount();
sprintf(buf_1, "%d", v0);
return buf_1;
}

original_code:
static char *get_countstr(struct atrfs_entry *ent)
{
 static char buf[10];
 sprintf(buf, "%d", get_watchcount (ent));
 return buf;
}

variable_types:
buf
char [10]


decompiled_code:
__int64 get_watchtimestr()
{
get_watchtime();
return secs_to_timestr();
}

canonical_decompiled_code:
__int64 func2()
{
get_watchtime();
return secs_to_timestr();
}

original_code:
static char *get_watchtimestr(struct atrfs_entry *ent)
{
 return secs_to_timestr (get_watchtime (ent));
}


decompiled_code:
__int64 get_lengthstr()
{
get_length();
return secs_to_timestr();
}

canonical_decompiled_code:
__int64 func3()
{
get_length();
return secs_to_timestr();
}

original_code:
static char *get_lengthstr(struct atrfs_entry *ent)
{
 return secs_to_timestr (get_length (ent));
}


decompiled_code:
void atrfs_init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void atrfs_init(void *userdata, struct fuse_conn_info *conn)
{
}

variable_types:
userdata
void *

variable_types: struct fuse_conn_info { unsigned int proto_major; unsigned int proto_minor; unsigned int async_read; unsigned int max_write; unsigned int max_readahead; unsigned int capable; unsigned int want; unsigned int max_background; unsigned int congestion_threshold; unsigned int reserved[23]; } *


decompiled_code:
__int64 atrfs_destroy()
{
tmplog("destroy()\n");
return close_entrydb();
}

canonical_decompiled_code:
__int64 func1()
{
tmplog("destroy()\n");
return close_entrydb();
}

original_code:
void atrfs_destroy(void *userdata)
{
 tmplog("destroy()\n");
 close_entrydb ();
}


decompiled_code:
void *__fastcall get_sha1_fast(char *path)
{
int v1; // eax
unsigned int v2; // er12
void *result; // rax
const char *v4; // r13
size_t v5; // rax

v1 = getxattr(path, "user.sha1", 0LL, 0LL);
sha1_2 = 0LL;
v2 = v1;
if ( v1 > 0 )
goto LABEL_2;
v4 = (const char *)get_sha1(path);
sha1_2 = (__int64)v4;
v5 = strlen(v4);
if ( setxattr(path, "user.sha1", v4, v5 + 1, 0) )
perror("Can't set SHA1");
result = (void *)sha1_2;
if ( !sha1_2 )
{
LABEL_2:
getxattr(path, "user.sha1", &buf_1, v2);
result = &buf_1;
sha1_2 = (__int64)&buf_1;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(char *path)
{
int v1; // eax
unsigned int v2; // er12
void *result; // rax
const char *v4; // r13
size_t v5; // rax

v1 = getxattr(path, "user.sha1", 0LL, 0LL);
sha1_2 = 0LL;
v2 = v1;
if ( v1 > 0 )
goto LABEL_2;
v4 = (const char *)get_sha1(path);
sha1_2 = (__int64)v4;
v5 = strlen(v4);
if ( setxattr(path, "user.sha1", v4, v5 + 1, 0) )
perror("Can't set SHA1");
result = (void *)sha1_2;
if ( !sha1_2 )
{
LABEL_2:
getxattr(path, "user.sha1", &buf_1, v2);
result = &buf_1;
sha1_2 = (__int64)&buf_1;
}
return result;
}

original_code:
char *get_sha1_fast (char *filename)
{
 int len = getxattr (filename, "user.sha1", ((void *)0), 0);
 static char *sha1;
 static char buf[32];
 sha1 = ((void *)0);
 if (len <= 0)
 {
  sha1 = get_sha1 (filename);
  if (setxattr (filename, "user.sha1", sha1, strlen (sha1) + 1, 0))
   perror ("Can't set SHA1");
 }
 if (! sha1)
 {
  getxattr (filename, "user.sha1", buf, len);
  sha1 = buf;
 }
 return sha1;
}

canonical_original_code:
char *get_sha1_fast(char *filename)
{
 int len = getxattr (filename, "user.sha1", ((void *)0), 0);
 static char *sha1;
 static char buf[32];
 sha1 = ((void *)0);
 if (len <= 0)
 {
  sha1 = get_sha1 (filename);
  if (setxattr (filename, "user.sha1", sha1, strlen (sha1) + 1, 0))
   perror ("Can't set SHA1");
 }
 if (! sha1)
 {
  getxattr (filename, "user.sha1", buf, len);
  sha1 = buf;
 }
 return sha1;
}

variable_types: len int

variable_types:
buf
char [32]


decompiled_code:
__int64 entrydb_exec(__int64 a1, const char *a2, ...)
{
unsigned int v2; // er12
char *ptr; // [rsp+8h] [rbp-E0h] BYREF
const char *v5; // [rsp+10h] [rbp-D8h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-D0h] BYREF

va_start(arg, a2);
ptr = 0LL;
v5 = 0LL;
vasprintf(&ptr, a2, arg);
v2 = 1;
sqlite3_exec(entrydb, ptr, a1, 0LL, &v5);
if ( v5 )
{
v2 = 0;
tmplog("%s while executing: \"%s\"\n", v5, ptr);
sqlite3_free(v5);
}
free(ptr);
return v2;
}

canonical_decompiled_code:
__int64 func2(__int64 a1, const char *a2, ...)
{
unsigned int v2; // er12
char *ptr; // [rsp+8h] [rbp-E0h] BYREF
const char *v5; // [rsp+10h] [rbp-D8h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-D0h] BYREF

va_start(arg, a2);
ptr = 0LL;
v5 = 0LL;
vasprintf(&ptr, a2, arg);
v2 = 1;
sqlite3_exec(entrydb, ptr, a1, 0LL, &v5);
if ( v5 )
{
v2 = 0;
tmplog("%s while executing: \"%s\"\n", v5, ptr);
sqlite3_free(v5);
}
free(ptr);
return v2;
}

original_code:
_Bool entrydb_exec (int (*callback)(void *data, int ncols, char **values, char **names), char *cmdfmt, ...)
{
 char *cmd = ((void *)0), *err = ((void *)0);
 _Bool ret = 1;
 va_list list;
 __builtin_va_start(list,cmdfmt);
 vasprintf (&cmd, cmdfmt, list);
 sqlite3_exec (entrydb, cmd, callback, ((void *)0), &err);
 __builtin_va_end(list);
 if (err)
 {
  tmplog ("%s while executing: \"%s\"\n", err, cmd);
  sqlite3_free (err);
  ret = 0;
 }
 free (cmd);
 return ret;
}

canonical_original_code:
_Bool entrydb_exec(int (*callback)(void *data, int ncols, char **values, char **names), char *cmdfmt, ...)
{
 char *cmd = ((void *)0); char *err = ((void *)0);
 _Bool ret = 1;
 __builtin_va_list list;
 __builtin_va_start(list,cmdfmt);
 vasprintf (&cmd, cmdfmt, list);
 sqlite3_exec (entrydb, cmd, callback, ((void *)0), &err);
 __builtin_va_end(list);
 if (err)
 {
  tmplog ("%s while executing: \"%s\"\n", err, cmd);
  sqlite3_free (err);
  ret = 0;
 }
 free (cmd);
 return ret;
}

variable_types: int (*)(void *data, int ncols, char **values, char **names)

variable_types:
cmdfmt
char *

variable_types:
cmd
char *

variable_types:
err
char *


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


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

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

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

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

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 *


decompiled_code:
__int64 __fastcall entrydb_get(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v7; // rdx
__int64 v8; // rcx
const char *v9; // rdi
__int64 v10; // r8
__int64 v11; // r9

if ( !entrydb )
return 0LL;
v9 = (const char *)get_sha1_fast(*(char **)(a1 + 48));
if ( !v9 )
entrydb_get_cold();
return database_get_constprop_0(v9, a2, v7, v8, v10, v11, a7);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
__int64 v7; // rdx
__int64 v8; // rcx
const char *v9; // rdi
__int64 v10; // r8
__int64 v11; // r9

if ( !entrydb )
return 0LL;
v9 = (const char *)func1(*(char **)(a1 + 48));
if ( !v9 )
func9();
return func3(v9, a2, v7, v8, v10, v11, a7);
}

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:
attr
char *


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

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


decompiled_code:
void __fastcall attach_subtitles(__int64 a1)
{
char *v2; // r12
char *v3; // rax
char *v4; // rbp
unsigned int v5; // er13
char *i; // r14
__int64 v7; // rax
void *v8; // r15
void *v9; // rbp
char *v10; // r12
char *v11; // rax
size_t v12; // rsi
char *v13; // r13
const char *v14; // r12
__int64 v15; // r13
size_t v16; // rax
__int64 v17; // rdi
const char *v18; // r14
size_t v19; // rax
__int64 v20; // rdi
double v21; // [rsp+8h] [rbp-90h]
double v22; // [rsp+10h] [rbp-88h]
__int64 v23; // [rsp+18h] [rbp-80h]
char *save_ptr; // [rsp+28h] [rbp-70h] BYREF
char s[104]; // [rsp+30h] [rbp-68h] BYREF

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

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
char *v2; // r12
char *v3; // rax
char *v4; // rbp
unsigned int v5; // er13
char *i; // r14
__int64 v7; // rax
void *v8; // r15
void *v9; // rbp
char *v10; // r12
char *v11; // rax
size_t v12; // rsi
char *v13; // r13
const char *v14; // r12
__int64 v15; // r13
size_t v16; // rax
__int64 v17; // rdi
const char *v18; // r14
size_t v19; // rax
__int64 v20; // rdi
double v21; // [rsp+8h] [rbp-90h]
double v22; // [rsp+10h] [rbp-88h]
__int64 v23; // [rsp+18h] [rbp-80h]
char *save_ptr; // [rsp+28h] [rbp-70h] BYREF
char s[104]; // [rsp+30h] [rbp-68h] BYREF

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

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 *


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 v1; // er13
void *v2; // r13
__int64 v3; // rsi
const char *v4; // r14
void *v5; // rsp
__int64 v6; // r15
__int64 v7; // r14
void *v8; // r14
int v9; // er13
__int64 v10; // r14
char v11[48]; // [rsp+0h] [rbp-30h] BYREF

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

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v1; // er13
void *v2; // r13
__int64 v3; // rsi
const char *v4; // r14
void *v5; // rsp
__int64 v6; // r15
__int64 v7; // r14
void *v8; // r14
int v9; // er13
__int64 v10; // r14
char v11[48]; // [rsp+0h] [rbp-30h] BYREF

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

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]

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

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
__int64 v6; // rcx
const char *v7; // rdi
const char *v10; // r12
const char *v11; // rsi
char v12; // dl
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
int result; // eax
int v18; // eax
double v19; // xmm0_8

v6 = 8LL;
v7 = "mplayer";
v10 = *(const char **)(a2 + 48);
v11 = a1;
do
{
if ( !v6 )
break;
v3 = *v11 < (unsigned int)*v7;
v4 = *v11++ == *v7++;
--v6;
}
while ( v4 );
v12 = (!v3 && !v4) - v3;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
goto LABEL_11;
v11 = a1;
v15 = "totem";
v16 = 6LL;
do
{
if ( !v16 )
break;
v13 = *v11 < (unsigned int)*v15;
v14 = *v11++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
LABEL_11:
v18 = get_watchcount(a2, v11);
set_ivalue(a2, "count", (unsigned int)(v18 + 1));
attach_subtitles(a2);
v19 = doubletime();
result = *(_DWORD *)(a2 + 40);
*(double *)(a2 + 56) = v19;
if ( result >= 0 )
return result;
}
else
{
result = *(_DWORD *)(a2 + 40);
if ( result >= 0 )
return result;
}
result = open64(v10, a3);
if ( result < 0 )
return -*_errno_location();
*(_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
__int64 v6; // rcx
const char *v7; // rdi
const char *v10; // r12
const char *v11; // rsi
char v12; // dl
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
int result; // eax
int v18; // eax
double v19; // xmm0_8

v6 = 8LL;
v7 = "mplayer";
v10 = *(const char **)(a2 + 48);
v11 = a1;
do
{
if ( !v6 )
break;
v3 = *v11 < (unsigned int)*v7;
v4 = *v11++ == *v7++;
--v6;
}
while ( v4 );
v12 = (!v3 && !v4) - v3;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
goto LABEL_11;
v11 = a1;
v15 = "totem";
v16 = 6LL;
do
{
if ( !v16 )
break;
v13 = *v11 < (unsigned int)*v15;
v14 = *v11++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
LABEL_11:
v18 = get_watchcount(a2, v11);
set_ivalue(a2, "count", (unsigned int)(v18 + 1));
attach_subtitles(a2);
v19 = doubletime();
result = *(_DWORD *)(a2 + 40);
*(double *)(a2 + 56) = v19;
if ( result >= 0 )
return result;
}
else
{
result = *(_DWORD *)(a2 + 40);
if ( result >= 0 )
return result;
}
result = open64(v10, a3);
if ( result < 0 )
return -*_errno_location();
*(_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


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)
{
double v4; // xmm0_8
__int64 v5; // rcx
unsigned int v6; // er12
int v7; // ebx
const char *v8; // r14
int v9; // eax
const char *v10; // rbp
const char *v11; // rax
char *result; // rax
double v13; // [rsp+0h] [rbp-50h]
char *ptr; // [rsp+10h] [rbp-40h] BYREF
char *v15; // [rsp+18h] [rbp-38h] BYREF
char *v16; // [rsp+20h] [rbp-30h] BYREF

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

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, double a2, double a3)
{
double v4; // xmm0_8
__int64 v5; // rcx
unsigned int v6; // er12
int v7; // ebx
const char *v8; // r14
int v9; // eax
const char *v10; // rbp
const char *v11; // rax
char *result; // rax
double v13; // [rsp+0h] [rbp-50h]
char *ptr; // [rsp+10h] [rbp-40h] BYREF
char *v15; // [rsp+18h] [rbp-38h] BYREF
char *v16; // [rsp+20h] [rbp-30h] BYREF

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

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
unsigned __int64 v7; // r8
unsigned __int64 v8; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3, int a4)
{
int v4; // edx
__int64 result; // rax
int v6; // edx
unsigned __int64 v7; // r8
unsigned __int64 v8; // rsi

v4 = 2 * a3;
result = (unsigned int)(v4 + 1);
v6 = v4 + 2;
if ( v6 < a2 )
{
v7 = *(_QWORD *)(a1 + 16LL * (int)result);
v8 = *(_QWORD *)(a1 + 16LL * v6);
if ( a4 )
{
if ( v7 >= v8 )
result = (unsigned int)v6;
}
else if ( v7 <= v8 )
{
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:
__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 )
{
*(_DWORD *)(a1 + 8) = v4;
*(_QWORD *)a1 = v5;
result = 0LL;
}
else
{
printf("Allocate memory %lu failed when append heap ...", 16LL * v4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__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 )
{
*(_DWORD *)(a1 + 8) = v4;
*(_QWORD *)a1 = v5;
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;
}

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

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


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 )
{
*(_DWORD *)(a1 + 8) = v1;
*(_QWORD *)a1 = v2;
}
else
{
LODWORD(v2) = printf("Allocate memory %lu failed when append heap ...", 16LL * v1);
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func2(__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 )
{
*(_DWORD *)(a1 + 8) = v1;
*(_QWORD *)a1 = v2;
}
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;
}

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


decompiled_code:
void __fastcall adjust_heap_caused_by_modify(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, unsigned __int64 a4)
{
int v4; // er10
int v5; // er8

v4 = *(_DWORD *)(a1 + 20);
if ( v4 )
v5 = a4 >= a3;
else
v5 = a4 <= a3;
*a2 = a4;
adjust_heap_isra_0(*(_QWORD *)a1, *(_DWORD *)(a1 + 12), v4, (__int64)a2, v5);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned __int64 *a2, unsigned __int64 a3, unsigned __int64 a4)
{
int v4; // er10
int v5; // er8

v4 = *(_DWORD *)(a1 + 20);
if ( v4 )
v5 = a4 >= a3;
else
v5 = a4 <= a3;
*a2 = a4;
func3(*(_QWORD *)a1, *(_DWORD *)(a1 + 12), v4, (__int64)a2, v5);
}

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:
item
struct item *

variable_types:
weight
unsigned long long

variable_types: direction int


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)
{
int v5; // esi
__int64 v7; // rcx
int v8; // esi
int v9; // edx
_QWORD *v10; // rcx
__int64 v11; // rdi
__int64 result; // rax

if ( a1 )
{
v5 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) != v5 )
{
LABEL_3:
v7 = v5;
v8 = v5 + 1;
v9 = *(_DWORD *)(a1 + 20);
v10 = (_QWORD *)(*(_QWORD *)a1 + 16 * v7);
v10[1] = a3;
v11 = *(_QWORD *)a1;
*v10 = a2;
*(_DWORD *)(a1 + 12) = v8;
adjust_heap_isra_0(v11, v8, v9, (__int64)v10, 0);
return 0LL;
}
if ( (int)append_heap(a1) >= 0 )
{
v5 = *(_DWORD *)(a1 + 12);
goto LABEL_3;
}
printf("Append array in heap failed , current size %d...", *(unsigned int *)(a1 + 8));
result = 0xFFFFFFFFLL;
}
else
{
printf("Cannot insert to a NULL heap...");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // esi
__int64 v7; // rcx
int v8; // esi
int v9; // edx
_QWORD *v10; // rcx
__int64 v11; // rdi
__int64 result; // rax

if ( a1 )
{
v5 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) != v5 )
{
LABEL_3:
v7 = v5;
v8 = v5 + 1;
v9 = *(_DWORD *)(a1 + 20);
v10 = (_QWORD *)(*(_QWORD *)a1 + 16 * v7);
v10[1] = a3;
v11 = *(_QWORD *)a1;
*v10 = a2;
*(_DWORD *)(a1 + 12) = v8;
func3(v11, v8, v9, (__int64)v10, 0);
return 0LL;
}
if ( (int)func1(a1) >= 0 )
{
v5 = *(_DWORD *)(a1 + 12);
goto LABEL_3;
}
printf("Append array in heap failed , current size %d...", *(unsigned int *)(a1 + 8));
result = 0xFFFFFFFFLL;
}
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
__int64 v4; // r8
int result; // eax

if ( !a1 )
return printf("Cannot free from a NULL heap ...");
v3 = find_value_isra_0(*(_QWORD **)a1, *(_DWORD *)(a1 + 12), a2, a3);
if ( v3 )
result = free_the_value(v4, v3);
else
result = puts("Can not find value ...");
return result;
}

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

if ( !a1 )
return printf("Cannot free from a NULL heap ...");
v3 = find_value_isra_0(*(_QWORD **)a1, *(_DWORD *)(a1 + 12), a2, a3);
if ( v3 )
result = func5(v4, 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, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 *v4; // rax
unsigned __int64 v5; // r8
__int64 v6; // r9
unsigned __int64 v7; // r10
unsigned __int64 v8; // r11

if ( a1 )
{
if ( a4 != a2 )
{
v4 = find_value_isra_0(*(_QWORD **)a1, *(_DWORD *)(a1 + 12), a2, a3);
if ( v4 )
{
v4[1] = v5;
adjust_heap_caused_by_modify(v6, v4, v7, v8);
}
else
{
puts("Can not find value ...");
}
}
}
else
{
printf("Cannot modify on NULL heap ...");
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int64 *v4; // rax
unsigned __int64 v5; // r8
__int64 v6; // r9
unsigned __int64 v7; // r10
unsigned __int64 v8; // r11

if ( a1 )
{
if ( a4 != a2 )
{
v4 = find_value_isra_0(*(_QWORD **)a1, *(_DWORD *)(a1 + 12), a2, a3);
if ( v4 )
{
v4[1] = v5;
func4(v6, v4, v7, v8);
}
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:
void __fastcall modify_heap_root(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 *v4; // rsi

if ( a1 )
{
v4 = *a1;
v4[1] = a3;
adjust_heap_caused_by_modify((__int64)a1, v4, *v4, a2);
}
else
{
printf("Cannot modify root on NULL heap ...");
}
}

canonical_decompiled_code:
void __fastcall func10(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 *v4; // rsi

if ( a1 )
{
v4 = *a1;
v4[1] = a3;
func4((__int64)a1, v4, *v4, a2);
}
else
{
printf("Cannot modify root on NULL heap ...");
}
}

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 func11(_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; // r12

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

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

if ( a1 )
{
v1 = 0LL;
if ( *(_DWORD *)(a1 + 12) )
{
v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
func5(a1, *(unsigned __int64 **)a1);
}
}
else
{
v1 = 0LL;
printf("Cannot get root value from a NULL heap ...");
}
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 func13(unsigned __int64 **a1)
{
int result; // eax

if ( a1 )
result = func5((__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 v1; // rsi
void *v3; // rdi

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

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
__int64 v1; // rsi
void *v3; // rdi

if ( ptr )
{
v1 = *((unsigned int *)ptr + 3);
if ( (_DWORD)v1 )
printf("There are %d items when destory heap ...\n", v1);
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)
{
if ( !a1 )
BUG();
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
if ( !a1 )
BUG();
return *(unsigned int *)(a1 + 20);
}

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(__int64 a1)
{
const char *v1; // rdx
__int64 v2; // rbx
__int64 v3; // rax

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

canonical_decompiled_code:
int __fastcall func16(__int64 a1)
{
const char *v1; // rdx
__int64 v2; // rbx
__int64 v3; // rax

v1 = "MAX";
if ( *(_DWORD *)(a1 + 20) )
v1 = "MIN";
printf("Heap %p is a %s heap : \n", a1, v1);
printf("Heap current size : %d\n", *(unsigned int *)(a1 + 8));
printf("Heap current length : %d\n", *(unsigned int *)(a1 + 12));
puts("All elements weight displays : ");
if ( *(int *)(a1 + 12) > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
printf("%llu ", *(_QWORD *)(*(_QWORD *)a1 + 16 * v3));
}
while ( *(_DWORD *)(a1 + 12) > (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;
++*(_DWORD *)(a1 + 16);
}
else
{
++*(_DWORD *)(a1 + 16);
*(_QWORD *)a1 = a2;
}
*(_QWORD *)(a1 + 8) = a2;
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; }