decompiled_code:
int sort_read_list()
{
int v0; // ebx
void *v1; // r12
int v2; // ebx
void *v3; // rbp
__int64 *v4; // rbx
__int64 v5; // r14
__int64 v6; // r15
__int64 v7; // rax
__int64 *v8; // rbx
__int64 v9; // r14
__int64 v10; // r15
unsigned __int64 v11; // rax
__int64 *v12; // rbx
__int64 v13; // rdi
unsigned __int64 v14; // rax
__int64 *v15; // rbx
__int64 v16; // r14
__int64 v17; // r15
__int64 v18; // rax
__int64 *v19; // rbx
__int64 v20; // rdi
__int64 v21; // r14
const char *v22; // rax
signed int v23; // er12
int result; // eax
__int64 v25; // r14
const char *v26; // rax
const char *v27; // rax
size_t v28; // rbx
__int64 v29; // rcx
char *v30; // rsi
__int64 v31; // rbp
char *v32; // rdx
__int64 v33; // rdi
int v34; // er12
int v35; // eax
const char *v36; // rax
const char *v37; // rax
const char *v38; // rax
const char *v39; // rax
__int64 v40; // [rsp+8h] [rbp-1040h] BYREF
size_t v41[519]; // [rsp+10h] [rbp-1038h] BYREF

if ( hardlink_is_unique )
{
v28 = 0LL;
qsort(inode_read_list, inode_read_list_end, 0x28uLL, (__compar_fn_t)rl_compare_i);
v29 = 0LL;
v30 = (char *)inode_read_list;
if ( inode_read_list_end )
{
do
{
while ( 1 )
{
v31 = 40 * v28;
v32 = &v30[40 * v28];
if ( *((_QWORD *)v32 + 3) == v29 )
break;
++v28;
v29 = *((_QWORD *)v32 + 3);
if ( inode_read_list_end <= v28 )
goto LABEL_58;
}
build_path(*((_QWORD *)v32 + 1), v41);
if ( log_level > 7 )
{
pthread_mutex_lock(&logger_lock);
v39 = (const char *)get_thread_name();
printf("%s", v39);
printf("Skipping [%s] due to duplicate inode.\n", (const char *)v41);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
++v28;
v33 = *(_QWORD *)((char *)inode_read_list + v31);
v34 = *(_DWORD *)(v33 + 20);
v35 = mark_path_entry_ignore_hardlink(v33, *(_QWORD *)((char *)inode_read_list + v31 + 8));
v30 = (char *)inode_read_list;
s_files_hl_skip += v34 - v35;
v29 = *(_QWORD *)((char *)inode_read_list + v31 + 24);
}
while ( inode_read_list_end > v28 );
}
LABEL_58:
free_inode_read_list();
}
v0 = read_block_counter;
v1 = malloc(40 * read_block_counter);
inc_stats_readlist((unsigned int)(40 * v0));
v2 = read_block_counter;
v40 = 0LL;
v3 = malloc(40 * read_block_counter);
inc_stats_readlist((unsigned int)(40 * v2));
v4 = (__int64 *)size_list_head;
v41[0] = 0LL;
if ( size_list_head )
{
v5 = 0LL;
v6 = 0LL;
do
{
while ( v4[2] > (unsigned __int64)hash_one_block_size )
{
v4 = (__int64 *)v4[1];
if ( !v4 )
goto LABEL_7;
}
++v5;
v7 = add_all_blocks_from_group(*v4, (__int64)v3);
v4 = (__int64 *)v4[1];
v6 += v7;
}
while ( v4 );
LABEL_7:
sort_and_transfer(v3, v41, (__int64)v1, &v40);
if ( v5 && log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v37 = (const char *)get_thread_name();
printf("%s", v37);
printf("read_list: (#1 small files): SETS %lu, BLOCKS %lu\n", v5, v6);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
else
{
sort_and_transfer(v3, v41, (__int64)v1, &v40);
}
v41[0] = 0LL;
v8 = (__int64 *)size_list_head;
if ( size_list_head )
{
v9 = 0LL;
v10 = 0LL;
do
{
if ( *(_DWORD *)(*v8 + 20) <= 0x200u )
{
v11 = v8[2];
if ( v11 > hash_one_block_size && v11 <= round1_max_bytes )
{
++v9;
v10 += add_all_blocks_from_group(*v8, (__int64)v3);
}
}
v8 = (__int64 *)v8[1];
}
while ( v8 );
sort_and_transfer(v3, v41, (__int64)v1, &v40);
if ( v9 && log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v38 = (const char *)get_thread_name();
printf("%s", v38);
printf("read_list: (#2 medium files): SETS %lu, BLOCKS %lu\n", v9, v10);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
v12 = (__int64 *)size_list_head;
if ( size_list_head )
goto LABEL_20;
LABEL_60:
v41[0] = 0LL;
LABEL_61:
sort_and_transfer(v3, v41, (__int64)v1, &v40);
goto LABEL_33;
}
}
else
{
sort_and_transfer(v3, v41, (__int64)v1, &v40);
}
v12 = (__int64 *)size_list_head;
if ( !size_list_head )
goto LABEL_60;
do
{
LABEL_20:
v13 = *v12;
if ( *(_DWORD *)(*v12 + 20) > 0x200u )
{
v14 = v12[2];
if ( v14 > hash_one_block_size && v14 <= round1_max_bytes )
{
v41[0] = 0LL;
v25 = add_all_blocks_from_group(v13, (__int64)v3);
sort_and_transfer(v3, v41, (__int64)v1, &v40);
if ( log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v26 = (const char *)get_thread_name();
printf("%s", v26);
printf("read_list: (#3 large set, size: %lu): SETS 1, BLOCKS %lu\n", v12[2], v25);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
}
v12 = (__int64 *)v12[1];
}
while ( v12 );
v41[0] = 0LL;
v15 = (__int64 *)size_list_head;
if ( !size_list_head )
goto LABEL_61;
v16 = 0LL;
v17 = 0LL;
do
{
while ( *(_DWORD *)(*v15 + 20) > 8u || v15[2] <= (unsigned __int64)round1_max_bytes )
{
v15 = (__int64 *)v15[1];
if ( !v15 )
goto LABEL_30;
}
++v16;
v18 = add_all_blocks_from_group(*v15, (__int64)v3);
v15 = (__int64 *)v15[1];
v17 += v18;
}
while ( v15 );
LABEL_30:
sort_and_transfer(v3, v41, (__int64)v1, &v40);
if ( v16 && log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v36 = (const char *)get_thread_name();
printf("%s", v36);
printf("read_list: (#4 large files): SETS %lu, BLOCKS %lu\n", v16, v17);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
LABEL_33:
v41[0] = 0LL;
v19 = (__int64 *)size_list_head;
if ( size_list_head )
{
do
{
while ( 1 )
{
v20 = *v19;
if ( *(_DWORD *)(*v19 + 20) > 8u && v19[2] > (unsigned __int64)round1_max_bytes )
{
v41[0] = 0LL;
v21 = add_all_blocks_from_group(v20, (__int64)v3);
sort_and_transfer(v3, v41, (__int64)v1, &v40);
if ( log_level > 3 )
break;
}
v19 = (__int64 *)v19[1];
if ( !v19 )
goto LABEL_40;
}
pthread_mutex_lock(&logger_lock);
v22 = (const char *)get_thread_name();
printf("%s", v22);
printf("read_list: (#5 large set, size: %lu): SETS 1, BLOCKS %lu\n", v19[2], v21);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
v19 = (__int64 *)v19[1];
}
while ( v19 );
}
LABEL_40:
free(v3);
v41[0] = 0LL;
dec_stats_readlist((unsigned int)(40 * read_block_counter));
read_list = v1;
read_list_end = v40;
if ( using_fiemap )
{
v23 = (unsigned int)(100 * stats_fiemap_zero_blocks) / stats_fiemap_total_blocks;
result = log_level;
if ( v23 <= 5 || s_total_files_seen <= 0x64u )
goto LABEL_42;
using_fiemap = 0;
if ( log_level <= 2 )
return result;
pthread_mutex_lock(&logger_lock);
v27 = (const char *)get_thread_name();
printf("%s", v27);
printf("Turning off using_fiemap, %d%% zero blocks\n", (unsigned int)v23);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
result = log_level;
LABEL_42:
if ( result > 11 )
{
puts("read_list after final sort");
result = dump_read_list_constprop_0();
}
return result;
}

canonical_decompiled_code:
int func11()
{
int v0; // ebx
void *v1; // r12
int v2; // ebx
void *v3; // rbp
__int64 *v4; // rbx
__int64 v5; // r14
__int64 v6; // r15
__int64 v7; // rax
__int64 *v8; // rbx
__int64 v9; // r14
__int64 v10; // r15
unsigned __int64 v11; // rax
__int64 *v12; // rbx
__int64 v13; // rdi
unsigned __int64 v14; // rax
__int64 *v15; // rbx
__int64 v16; // r14
__int64 v17; // r15
__int64 v18; // rax
__int64 *v19; // rbx
__int64 v20; // rdi
__int64 v21; // r14
const char *v22; // rax
signed int v23; // er12
int result; // eax
__int64 v25; // r14
const char *v26; // rax
const char *v27; // rax
size_t v28; // rbx
__int64 v29; // rcx
char *v30; // rsi
__int64 v31; // rbp
char *v32; // rdx
__int64 v33; // rdi
int v34; // er12
int v35; // eax
const char *v36; // rax
const char *v37; // rax
const char *v38; // rax
const char *v39; // rax
__int64 v40; // [rsp+8h] [rbp-1040h] BYREF
size_t v41[519]; // [rsp+10h] [rbp-1038h] BYREF

if ( hardlink_is_unique )
{
v28 = 0LL;
qsort(inode_read_list, inode_read_list_end, 0x28uLL, (__compar_fn_t)rl_compare_i);
v29 = 0LL;
v30 = (char *)inode_read_list;
if ( inode_read_list_end )
{
do
{
while ( 1 )
{
v31 = 40 * v28;
v32 = &v30[40 * v28];
if ( *((_QWORD *)v32 + 3) == v29 )
break;
++v28;
v29 = *((_QWORD *)v32 + 3);
if ( inode_read_list_end <= v28 )
goto LABEL_58;
}
build_path(*((_QWORD *)v32 + 1), v41);
if ( log_level > 7 )
{
pthread_mutex_lock(&logger_lock);
v39 = (const char *)get_thread_name();
printf("%s", v39);
printf("Skipping [%s] due to duplicate inode.\n", (const char *)v41);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
++v28;
v33 = *(_QWORD *)((char *)inode_read_list + v31);
v34 = *(_DWORD *)(v33 + 20);
v35 = mark_path_entry_ignore_hardlink(v33, *(_QWORD *)((char *)inode_read_list + v31 + 8));
v30 = (char *)inode_read_list;
s_files_hl_skip += v34 - v35;
v29 = *(_QWORD *)((char *)inode_read_list + v31 + 24);
}
while ( inode_read_list_end > v28 );
}
LABEL_58:
func4();
}
v0 = read_block_counter;
v1 = malloc(40 * read_block_counter);
inc_stats_readlist((unsigned int)(40 * v0));
v2 = read_block_counter;
v40 = 0LL;
v3 = malloc(40 * read_block_counter);
inc_stats_readlist((unsigned int)(40 * v2));
v4 = (__int64 *)size_list_head;
v41[0] = 0LL;
if ( size_list_head )
{
v5 = 0LL;
v6 = 0LL;
do
{
while ( v4[2] > (unsigned __int64)hash_one_block_size )
{
v4 = (__int64 *)v4[1];
if ( !v4 )
goto LABEL_7;
}
++v5;
v7 = func3(*v4, (__int64)v3);
v4 = (__int64 *)v4[1];
v6 += v7;
}
while ( v4 );
LABEL_7:
func6(v3, v41, (__int64)v1, &v40);
if ( v5 && log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v37 = (const char *)get_thread_name();
printf("%s", v37);
printf("read_list: (#1 small files): SETS %lu, BLOCKS %lu\n", v5, v6);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
else
{
func6(v3, v41, (__int64)v1, &v40);
}
v41[0] = 0LL;
v8 = (__int64 *)size_list_head;
if ( size_list_head )
{
v9 = 0LL;
v10 = 0LL;
do
{
if ( *(_DWORD *)(*v8 + 20) <= 0x200u )
{
v11 = v8[2];
if ( v11 > hash_one_block_size && v11 <= round1_max_bytes )
{
++v9;
v10 += func3(*v8, (__int64)v3);
}
}
v8 = (__int64 *)v8[1];
}
while ( v8 );
func6(v3, v41, (__int64)v1, &v40);
if ( v9 && log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v38 = (const char *)get_thread_name();
printf("%s", v38);
printf("read_list: (#2 medium files): SETS %lu, BLOCKS %lu\n", v9, v10);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
v12 = (__int64 *)size_list_head;
if ( size_list_head )
goto LABEL_20;
LABEL_60:
v41[0] = 0LL;
LABEL_61:
func6(v3, v41, (__int64)v1, &v40);
goto LABEL_33;
}
}
else
{
func6(v3, v41, (__int64)v1, &v40);
}
v12 = (__int64 *)size_list_head;
if ( !size_list_head )
goto LABEL_60;
do
{
LABEL_20:
v13 = *v12;
if ( *(_DWORD *)(*v12 + 20) > 0x200u )
{
v14 = v12[2];
if ( v14 > hash_one_block_size && v14 <= round1_max_bytes )
{
v41[0] = 0LL;
v25 = func3(v13, (__int64)v3);
func6(v3, v41, (__int64)v1, &v40);
if ( log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v26 = (const char *)get_thread_name();
printf("%s", v26);
printf("read_list: (#3 large set, size: %lu): SETS 1, BLOCKS %lu\n", v12[2], v25);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
}
v12 = (__int64 *)v12[1];
}
while ( v12 );
v41[0] = 0LL;
v15 = (__int64 *)size_list_head;
if ( !size_list_head )
goto LABEL_61;
v16 = 0LL;
v17 = 0LL;
do
{
while ( *(_DWORD *)(*v15 + 20) > 8u || v15[2] <= (unsigned __int64)round1_max_bytes )
{
v15 = (__int64 *)v15[1];
if ( !v15 )
goto LABEL_30;
}
++v16;
v18 = func3(*v15, (__int64)v3);
v15 = (__int64 *)v15[1];
v17 += v18;
}
while ( v15 );
LABEL_30:
func6(v3, v41, (__int64)v1, &v40);
if ( v16 && log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v36 = (const char *)get_thread_name();
printf("%s", v36);
printf("read_list: (#4 large files): SETS %lu, BLOCKS %lu\n", v16, v17);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
LABEL_33:
v41[0] = 0LL;
v19 = (__int64 *)size_list_head;
if ( size_list_head )
{
do
{
while ( 1 )
{
v20 = *v19;
if ( *(_DWORD *)(*v19 + 20) > 8u && v19[2] > (unsigned __int64)round1_max_bytes )
{
v41[0] = 0LL;
v21 = func3(v20, (__int64)v3);
func6(v3, v41, (__int64)v1, &v40);
if ( log_level > 3 )
break;
}
v19 = (__int64 *)v19[1];
if ( !v19 )
goto LABEL_40;
}
pthread_mutex_lock(&logger_lock);
v22 = (const char *)get_thread_name();
printf("%s", v22);
printf("read_list: (#5 large set, size: %lu): SETS 1, BLOCKS %lu\n", v19[2], v21);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
v19 = (__int64 *)v19[1];
}
while ( v19 );
}
LABEL_40:
free(v3);
v41[0] = 0LL;
dec_stats_readlist((unsigned int)(40 * read_block_counter));
read_list = v1;
read_list_end = v40;
if ( using_fiemap )
{
v23 = (unsigned int)(100 * stats_fiemap_zero_blocks) / stats_fiemap_total_blocks;
result = log_level;
if ( v23 <= 5 || s_total_files_seen <= 0x64u )
goto LABEL_42;
using_fiemap = 0;
if ( log_level <= 2 )
return result;
pthread_mutex_lock(&logger_lock);
v27 = (const char *)get_thread_name();
printf("%s", v27);
printf("Turning off using_fiemap, %d%% zero blocks\n", (unsigned int)v23);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
result = log_level;
LABEL_42:
if ( result > 11 )
{
puts("read_list after final sort");
result = func7();
}
return result;
}

original_code:
void sort_read_list()
{
  if (hardlink_is_unique) {
    qsort(inode_read_list, inode_read_list_end,
          sizeof(struct read_list_entry), rl_compare_i);
    char path[4096];
    uint64_t i;
    ino_t p_inode = 0;
    for (i = 0; i < inode_read_list_end; i++) {
      if (inode_read_list[i].inode == p_inode) {
        build_path(inode_read_list[i].pathlist_self, path);
        if (8 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Skipping [%s] due to duplicate inode.\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
        int before = inode_read_list[i].pathlist_head->list_size;
        int after =
          mark_path_entry_ignore_hardlink(inode_read_list[i].pathlist_head,
                                          inode_read_list[i].pathlist_self);
        s_files_hl_skip += (before - after);
      }
      p_inode = inode_read_list[i].inode;
    }
    free_inode_read_list();
  }
  struct read_list_entry * the_read_list = (struct read_list_entry *)
    malloc(sizeof(struct read_list_entry) * read_block_counter);
  inc_stats_readlist(sizeof(struct read_list_entry) * read_block_counter);
  uint64_t read_list_index = 0;
  struct read_list_entry * tmp_read_list = (struct read_list_entry *)
    malloc(sizeof(struct read_list_entry) * read_block_counter);
  inc_stats_readlist(sizeof(struct read_list_entry) * read_block_counter);
  uint64_t tmp_index = 0;
  uint64_t block_counter = 0;
  uint64_t set_counter = 0;
  struct size_list * szl = ((void *)0);
  tmp_index = 0;
  block_counter = 0;
  set_counter = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->size <= hash_one_block_size) {
      block_counter +=
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      set_counter++;
    }
    szl = szl->next;
  }
  sort_and_transfer(tmp_read_list, &tmp_index,the_read_list, &read_list_index);
  if (set_counter > 0) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#1 small files): " "SETS %" "l" "u" ", BLOCKS %" "l" "u" "\n", set_counter, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  }
  tmp_index = 0;
  block_counter = 0;
  set_counter = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size <= 512 &&
        szl->size > hash_one_block_size && szl->size <= round1_max_bytes) {
      block_counter +=
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      set_counter++;
    }
    szl = szl->next;
  }
  sort_and_transfer(tmp_read_list, &tmp_index,the_read_list, &read_list_index);
  if (set_counter > 0) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#2 medium files): " "SETS %" "l" "u" ", BLOCKS %" "l" "u" "\n", set_counter, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  }
  tmp_index = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size > 512 &&
        szl->size > hash_one_block_size && szl->size <= round1_max_bytes) {
      tmp_index = 0;
      block_counter =
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      sort_and_transfer(tmp_read_list, &tmp_index,
                        the_read_list, &read_list_index);
      if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#3 large set, size: %" "l" "u" "): " "SETS 1, BLOCKS %" "l" "u" "\n", szl->size, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
    szl = szl->next;
  }
  tmp_index = 0;
  block_counter = 0;
  set_counter = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size <= 8 &&
        szl->size > round1_max_bytes) {
      block_counter +=
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      set_counter++;
    }
    szl = szl->next;
  }
  sort_and_transfer(tmp_read_list, &tmp_index,the_read_list, &read_list_index);
  if (set_counter > 0) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#4 large files): " "SETS %" "l" "u" ", BLOCKS %" "l" "u" "\n", set_counter, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  }
  tmp_index = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size > 8 &&
        szl->size > round1_max_bytes) {
      tmp_index = 0;
      block_counter =
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      sort_and_transfer(tmp_read_list, &tmp_index,
                        the_read_list, &read_list_index);
      if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#5 large set, size: %" "l" "u" "): " "SETS 1, BLOCKS %" "l" "u" "\n", szl->size, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
    szl = szl->next;
  }
  free(tmp_read_list);
  tmp_read_list = ((void *)0);
  tmp_index = 0;
  dec_stats_readlist(sizeof(struct read_list_entry) * read_block_counter);
  read_list = the_read_list;
  read_list_end = read_list_index;
  if (using_fiemap) {
    int zeropct = (100 * stats_fiemap_zero_blocks) / stats_fiemap_total_blocks;
    if (zeropct > 5 && s_total_files_seen > 100) {
      using_fiemap = 0;
      if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Turning off using_fiemap, %d%% zero blocks\n", zeropct); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
  }
  if (log_level >= 12) {
    printf("read_list after final sort\n");
    dump_read_list(0);
  }
}

canonical_original_code:
void sort_read_list()
{
  if (hardlink_is_unique) {
    qsort(inode_read_list, inode_read_list_end,
          sizeof(struct read_list_entry), rl_compare_i);
    char path[4096];
    unsigned long i;
    unsigned long p_inode = 0;
    for (i = 0; i < inode_read_list_end; i++) {
      if (inode_read_list[i].inode == p_inode) {
        build_path(inode_read_list[i].pathlist_self, path);
        if (8 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Skipping [%s] due to duplicate inode.\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
        int before = inode_read_list[i].pathlist_head->list_size;
        int after = mark_path_entry_ignore_hardlink(inode_read_list[i].pathlist_head,
                                          inode_read_list[i].pathlist_self);
        s_files_hl_skip += (before - after);
      }
      p_inode = inode_read_list[i].inode;
    }
    free_inode_read_list();
  }
  struct read_list_entry *the_read_list = (struct read_list_entry *)
    malloc(sizeof(struct read_list_entry) * read_block_counter);
  inc_stats_readlist(sizeof(struct read_list_entry) * read_block_counter);
  unsigned long read_list_index = 0;
  struct read_list_entry *tmp_read_list = (struct read_list_entry *)
    malloc(sizeof(struct read_list_entry) * read_block_counter);
  inc_stats_readlist(sizeof(struct read_list_entry) * read_block_counter);
  unsigned long tmp_index = 0;
  unsigned long block_counter = 0;
  unsigned long set_counter = 0;
  struct size_list *szl = ((void *)0);
  tmp_index = 0;
  block_counter = 0;
  set_counter = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->size <= hash_one_block_size) {
      block_counter +=
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      set_counter++;
    }
    szl = szl->next;
  }
  sort_and_transfer(tmp_read_list, &tmp_index,the_read_list, &read_list_index);
  if (set_counter > 0) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#1 small files): " "SETS %" "l" "u" ", BLOCKS %" "l" "u" "\n", set_counter, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  }
  tmp_index = 0;
  block_counter = 0;
  set_counter = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size <= 512 &&
        szl->size > hash_one_block_size && szl->size <= round1_max_bytes) {
      block_counter +=
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      set_counter++;
    }
    szl = szl->next;
  }
  sort_and_transfer(tmp_read_list, &tmp_index,the_read_list, &read_list_index);
  if (set_counter > 0) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#2 medium files): " "SETS %" "l" "u" ", BLOCKS %" "l" "u" "\n", set_counter, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  }
  tmp_index = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size > 512 &&
        szl->size > hash_one_block_size && szl->size <= round1_max_bytes) {
      tmp_index = 0;
      block_counter =
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      sort_and_transfer(tmp_read_list, &tmp_index,
                        the_read_list, &read_list_index);
      if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#3 large set, size: %" "l" "u" "): " "SETS 1, BLOCKS %" "l" "u" "\n", szl->size, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
    szl = szl->next;
  }
  tmp_index = 0;
  block_counter = 0;
  set_counter = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size <= 8 &&
        szl->size > round1_max_bytes) {
      block_counter +=
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      set_counter++;
    }
    szl = szl->next;
  }
  sort_and_transfer(tmp_read_list, &tmp_index,the_read_list, &read_list_index);
  if (set_counter > 0) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#4 large files): " "SETS %" "l" "u" ", BLOCKS %" "l" "u" "\n", set_counter, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  }
  tmp_index = 0;
  szl = size_list_head;
  while (szl != ((void *)0)) {
    if (szl->path_list->list_size > 8 &&
        szl->size > round1_max_bytes) {
      tmp_index = 0;
      block_counter =
        add_all_blocks_from_group(szl->path_list, tmp_read_list, &tmp_index);
      sort_and_transfer(tmp_read_list, &tmp_index,
                        the_read_list, &read_list_index);
      if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("read_list: (#5 large set, size: %" "l" "u" "): " "SETS 1, BLOCKS %" "l" "u" "\n", szl->size, block_counter); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
    szl = szl->next;
  }
  free(tmp_read_list);
  tmp_read_list = ((void *)0);
  tmp_index = 0;
  dec_stats_readlist(sizeof(struct read_list_entry) * read_block_counter);
  read_list = the_read_list;
  read_list_end = read_list_index;
  if (using_fiemap) {
    int zeropct = (100 * stats_fiemap_zero_blocks) / stats_fiemap_total_blocks;
    if (zeropct > 5 && s_total_files_seen > 100) {
      using_fiemap = 0;
      if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Turning off using_fiemap, %d%% zero blocks\n", zeropct); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
  }
  if (log_level >= 12) {
    printf("read_list after final sort\n");
    dump_read_list(0);
  }
}

variable_types:
path
char [4096]

variable_types:
i
unsigned long

variable_types: before int

variable_types: after int

variable_types: struct size_list { struct path_list_head { struct size_list *sizelist; struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } *last_entry; unsigned int wanted_bufsize; unsigned int list_size; unsigned int buffer_ready; unsigned char state; unsigned char hash_passes; unsigned char have_cached_hashes; } *path_list; struct size_list *next; unsigned long size; int fully_read; 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; } lock; } *

variable_types: zeropct int


repo: jvirkki/dupd

decompiled_code:
__int64 __fastcall pb_get_first_entry(__int64 a1)
{
return a1 + 32;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 + 32;
}

original_code:
static inline struct path_list_entry *
pb_get_first_entry(struct path_list_head * head)
{
  return (struct path_list_entry *)
    ((char *)head + sizeof(struct path_list_head));
}

canonical_original_code:
static inline struct path_list_entry *pb_get_first_entry(struct path_list_head *head)
{
  return (struct path_list_entry *)
    ((char *)head + sizeof(struct path_list_head));
}

variable_types: struct path_list_head { struct size_list { struct path_list_head *path_list; struct size_list *next; unsigned long size; int fully_read; 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; } lock; } *sizelist; struct path_list_entry *last_entry; unsigned int wanted_bufsize; unsigned int list_size; unsigned int buffer_ready; unsigned char state; unsigned char hash_passes; unsigned char have_cached_hashes; } *

return_type: struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } *

user_defined_types: struct path_list_head { struct size_list *sizelist; struct path_list_entry *last_entry; unsigned int wanted_bufsize; unsigned int list_size; unsigned int buffer_ready; unsigned char state; unsigned char hash_passes; unsigned char have_cached_hashes; }

user_defined_types: struct path_list_entry { struct path_list_entry *next; struct block_list *blocks; struct direntry *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; }

user_defined_types: struct size_list { struct path_list_head *path_list; struct size_list *next; unsigned long size; int fully_read; union pthread_mutex_t lock; }

user_defined_types: struct block_list { unsigned char count; struct block_list_entry entry[]; }

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

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


decompiled_code:
__int64 test_hash_table()
{
const char *v1; // rax

if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v1 = (const char *)get_thread_name();
printf("%s", v1);
puts("=== hash table ===");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
init_path_block();
init_dirtree();
test_hash_table_basics();
free_dirtree();
return free_path_block();
}

canonical_decompiled_code:
__int64 func2()
{
const char *v1; // rax

if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v1 = (const char *)get_thread_name();
printf("%s", v1);
puts("=== hash table ===");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
init_path_block();
init_dirtree();
func1();
free_dirtree();
return free_path_block();
}

original_code:
void test_hash_table()
{
  if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("=== hash table ===\n"); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  init_path_block();
  init_dirtree();
  test_hash_table_basics();
  free_dirtree();
  free_path_block();
}

return_type: void


decompiled_code:
__int64 __fastcall dupd_memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 0LL;
}
return 1LL;
}

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

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 0LL;
}
return 1LL;
}

original_code:
static inline int dupd_memcmp(const char * b1, const char * b2, size_t n)
{
  while (n) {
    if (*b1++ != *b2++) {
      return 1;
    }
    n--;
  }
  return 0;
}

canonical_original_code:
static inline int dupd_memcmp(char *b1, char *b2, unsigned long n)
{
  while (n) {
    if (*b1++ != *b2++) {
      return 1;
    }
    n--;
  }
  return 0;
}

variable_types:
n
unsigned long

return_type: int


original_code:
static void reset_hash_list_entry(struct hash_list * hl)
{
  if (hl == ((void *)0)) {
    return;
  }
  hl->hash_valid = 0;
  hl->hash[0] = 0;
  hl->next_index = 0;
}

canonical_original_code:
static void reset_hash_list_entry(struct hash_list *hl)
{
  if (hl == ((void *)0)) {
    return;
  }
  hl->hash_valid = 0;
  hl->hash[0] = 0;
  hl->next_index = 0;
}

variable_types: struct hash_list { int hash_valid; char hash[64]; struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } **entries; int capacity; int next_index; struct hash_list *next; } *

user_defined_types: struct hash_list { int hash_valid; char hash[64]; struct path_list_entry **entries; int capacity; int next_index; struct hash_list *next; }


decompiled_code:
_QWORD *new_hash_list_node()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x60uLL);
*(_DWORD *)v0 = 0;
v1 = v0;
*((_BYTE *)v0 + 4) = 0;
v2 = malloc(0x20uLL);
v1[10] = 4LL;
v1[9] = v2;
v1[11] = 0LL;
inc_stats_hashtable(128LL);
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x60uLL);
*(_DWORD *)v0 = 0;
v1 = v0;
*((_BYTE *)v0 + 4) = 0;
v2 = malloc(0x20uLL);
v1[10] = 4LL;
v1[9] = v2;
v1[11] = 0LL;
inc_stats_hashtable(128LL);
return v1;
}

original_code:
static struct hash_list * new_hash_list_node()
{
  uint32_t bytes = sizeof(struct hash_list);
  struct hash_list * hl = (struct hash_list *)malloc(sizeof(struct hash_list));
  hl->hash_valid = 0;
  hl->hash[0] = 0;
  hl->entries = (struct path_list_entry **)
    malloc(sizeof(struct path_list_entry *) * 4);
  bytes += sizeof(struct path_list_entry *) * 4;
  hl->capacity = 4;
  hl->next_index = 0;
  hl->next = ((void *)0);
  inc_stats_hashtable(bytes);
  return hl;
}

canonical_original_code:
static struct hash_list *new_hash_list_node()
{
  unsigned int bytes = sizeof(struct hash_list);
  struct hash_list *hl = (struct hash_list *)malloc(sizeof(struct hash_list));
  hl->hash_valid = 0;
  hl->hash[0] = 0;
  hl->entries = (struct path_list_entry **)
    malloc(sizeof(struct path_list_entry *) * 4);
  bytes += sizeof(struct path_list_entry *) * 4;
  hl->capacity = 4;
  hl->next_index = 0;
  hl->next = ((void *)0);
  inc_stats_hashtable(bytes);
  return hl;
}

variable_types:
bytes
unsigned int

return_type: struct hash_list { int hash_valid; char hash[64]; struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } **entries; int capacity; int next_index; struct hash_list *next; } *


decompiled_code:
void *get_path_buffer_info()
{
void *result; // rax
_DWORD *v1; // rax
_QWORD *v2; // r12
void *v3; // rax
pthread_key_t v4; // edi

result = pthread_getspecific(duplicate_path_buffer);
if ( !result )
{
v1 = malloc(0x10uLL);
*v1 = 0x4000;
v2 = v1;
v3 = malloc(0x4000uLL);
v4 = duplicate_path_buffer;
v2[1] = v3;
pthread_setspecific(v4, v2);
result = v2;
}
return result;
}

canonical_decompiled_code:
void *func3()
{
void *result; // rax
_DWORD *v1; // rax
_QWORD *v2; // r12
void *v3; // rax
pthread_key_t v4; // edi

result = pthread_getspecific(duplicate_path_buffer);
if ( !result )
{
v1 = malloc(0x10uLL);
*v1 = 0x4000;
v2 = v1;
v3 = malloc(0x4000uLL);
v4 = duplicate_path_buffer;
v2[1] = v3;
pthread_setspecific(v4, v2);
result = v2;
}
return result;
}

original_code:
static struct path_buffer_info * get_path_buffer_info()
{
  struct path_buffer_info * pbi = pthread_getspecific(duplicate_path_buffer);
  if (pbi == ((void *)0)) {
    pbi = (struct path_buffer_info *)malloc(sizeof(struct path_buffer_info));
    pbi->size = 4096 * 4;
    pbi->buf = (char *)malloc(pbi->size);
    pthread_setspecific(duplicate_path_buffer, pbi);
  }
  return pbi;
}

canonical_original_code:
static struct path_buffer_info *get_path_buffer_info()
{
  struct path_buffer_info *pbi = pthread_getspecific(duplicate_path_buffer);
  if (pbi == ((void *)0)) {
    pbi = (struct path_buffer_info *)malloc(sizeof(struct path_buffer_info));
    pbi->size = 4096 * 4;
    pbi->buf = (char *)malloc(pbi->size);
    pthread_setspecific(duplicate_path_buffer, pbi);
  }
  return pbi;
}

variable_types: struct path_buffer_info { int size; char *buf; } *


decompiled_code:
void __fastcall print_hash_list_entry(unsigned int a1, unsigned int *a2)
{
unsigned int *v2; // rbp
__int64 v3; // rbx
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
char v7[4120]; // [rsp-1018h] [rbp-1018h] BYREF

if ( a2 )
{
v2 = a2;
if ( *a2 )
{
if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v6 = (const char *)get_thread_name();
printf("%s", v6);
printf(" ---[ %d ]\n", a1);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
goto LABEL_11;
}
while ( 1 )
{
v3 = 0LL;
while ( (int)v2[21] > (int)v3 )
{
while ( 1 )
{
build_path(*(_QWORD *)(*((_QWORD *)v2 + 9) + 8 * v3), v7);
if ( log_level > 9 )
break;
if ( (int)v2[21] <= (int)++v3 )
goto LABEL_9;
}
++v3;
pthread_mutex_lock(&logger_lock);
v4 = (const char *)get_thread_name();
printf("%s", v4);
printf(" [%s]\n", v7);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
LABEL_9:
v2 = (unsigned int *)*((_QWORD *)v2 + 11);
if ( !v2 || !*v2 )
break;
LABEL_11:
if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v5 = (const char *)get_thread_name();
printf("%s", v5);
printf("hash_valid: %d, next_index: %d ", *v2, v2[21]);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
if ( log_level > 9 )
memdump("hash", v2 + 1, hash_bufsize);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1, unsigned int *a2)
{
unsigned int *v2; // rbp
__int64 v3; // rbx
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
char v7[4120]; // [rsp-1018h] [rbp-1018h] BYREF

if ( a2 )
{
v2 = a2;
if ( *a2 )
{
if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v6 = (const char *)get_thread_name();
printf("%s", v6);
printf(" ---[ %d ]\n", a1);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
goto LABEL_11;
}
while ( 1 )
{
v3 = 0LL;
while ( (int)v2[21] > (int)v3 )
{
while ( 1 )
{
build_path(*(_QWORD *)(*((_QWORD *)v2 + 9) + 8 * v3), v7);
if ( log_level > 9 )
break;
if ( (int)v2[21] <= (int)++v3 )
goto LABEL_9;
}
++v3;
pthread_mutex_lock(&logger_lock);
v4 = (const char *)get_thread_name();
printf("%s", v4);
printf(" [%s]\n", v7);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
LABEL_9:
v2 = (unsigned int *)*((_QWORD *)v2 + 11);
if ( !v2 || !*v2 )
break;
LABEL_11:
if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v5 = (const char *)get_thread_name();
printf("%s", v5);
printf("hash_valid: %d, next_index: %d ", *v2, v2[21]);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
if ( log_level > 9 )
memdump("hash", v2 + 1, hash_bufsize);
}
}
}
}
}

original_code:
static void print_hash_list_entry(int n, struct hash_list * src)
{
  char file[4096];
  struct path_list_entry * entry;
  struct hash_list * p = src;
  int header = 0;
  while (p != ((void *)0) && p->hash_valid) {
    if (!header) {
      if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("  ---[ %d ]\n", n); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
      header = 1;
    }
    if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("hash_valid: %d, next_index: %d   ", p->hash_valid, p->next_index); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    if (log_level >= 10) {
      memdump("hash", p->hash, hash_bufsize);
    }
    for (int j=0; j < p->next_index; j++) {
      entry = *(p->entries + j);
      build_path(entry, file);
      if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("  [%s]\n", file); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
    p = p->next;
  }
}

canonical_original_code:
static void print_hash_list_entry(int n, struct hash_list *src)
{
  char file[4096];
  struct path_list_entry *entry;
  struct hash_list *p = src;
  int header = 0;
  while (p != ((void *)0) && p->hash_valid) {
    if (!header) {
      if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("  ---[ %d ]\n", n); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
      header = 1;
    }
    if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("hash_valid: %d, next_index: %d   ", p->hash_valid, p->next_index); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    if (log_level >= 10) {
      memdump("hash", p->hash, hash_bufsize);
    }
    for (int j = 0; j < p->next_index; j++) {
      entry = *(p->entries + j);
      build_path(entry, file);
      if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("  [%s]\n", file); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    }
    p = p->next;
  }
}

variable_types: n int

variable_types:
file
char [4096]

variable_types: struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } *

variable_types: header int

variable_types: j int


decompiled_code:
_BYTE *init_hash_table()
{
_BYTE *v0; // rax
_BYTE *v1; // r12

v0 = malloc(0x10uLL);
v0[10] = 0;
v1 = v0;
*((_WORD *)v0 + 4) = 256;
*(_QWORD *)v0 = calloc(0x800uLL, 1uLL);
inc_stats_hashtable(2064LL);
return v1;
}

canonical_decompiled_code:
_BYTE *func7()
{
_BYTE *v0; // rax
_BYTE *v1; // r12

v0 = malloc(0x10uLL);
v0[10] = 0;
v1 = v0;
*((_WORD *)v0 + 4) = 256;
*(_QWORD *)v0 = calloc(0x800uLL, 1uLL);
inc_stats_hashtable(2064LL);
return v1;
}

original_code:
struct hash_table * init_hash_table()
{
  struct hash_table * hl = ((void *)0);
  uint32_t bytes = sizeof(struct hash_table);
  hl = (struct hash_table *)malloc(sizeof(struct hash_table));
  hl->has_dups = 0;
  hl->entries = 256;
  struct hash_list ** hll = malloc(256 * sizeof(struct hash_list *));
  bytes += 256 * sizeof(struct hash_list *);
  for (int n = 0; n <= 255; n++) {
    hll[n] = ((void *)0);
  }
  hl->table = hll;
  inc_stats_hashtable(bytes);
  return hl;
}

canonical_original_code:
struct hash_table *init_hash_table()
{
  struct hash_table *hl = ((void *)0);
  unsigned int bytes = sizeof(struct hash_table);
  hl = (struct hash_table *)malloc(sizeof(struct hash_table));
  hl->has_dups = 0;
  hl->entries = 256;
  struct hash_list **hll = malloc(256 * sizeof(struct hash_list *));
  bytes += 256 * sizeof(struct hash_list *);
  for (int n = 0; n <= 255; n++) {
    hll[n] = ((void *)0);
  }
  hl->table = hll;
  inc_stats_hashtable(bytes);
  return hl;
}

variable_types: struct hash_table { struct hash_list { int hash_valid; char hash[64]; struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } **entries; int capacity; int next_index; struct hash_list *next; } **table; unsigned short entries; unsigned char has_dups; } *

user_defined_types: struct hash_table { struct hash_list **table; unsigned short entries; unsigned char has_dups; }


decompiled_code:
void __fastcall reset_hash_table(__int64 a1)
{
__int64 i; // rax

if ( a1 )
{
*(_BYTE *)(a1 + 10) = 0;
for ( i = 0LL; i != 2048; reset_hash_list_entry(*(_QWORD *)(*(_QWORD *)a1 + i)) )
;
}
}

original_code:
void reset_hash_table(struct hash_table * hl)
{
  if (hl == ((void *)0)) {
    return;
  }
  hl->has_dups = 0;
  for (int n = 0; n <= 255; n++) {
    reset_hash_list_entry(hl->table[n]);
  }
}

canonical_original_code:
void reset_hash_table(struct hash_table *hl)
{
  if (hl == ((void *)0)) {
    return;
  }
  hl->has_dups = 0;
  for (int n = 0; n <= 255; n++) {
    reset_hash_list_entry(hl->table[n]);
  }
}

user_defined_types: struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; }

user_defined_types: struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; }


original_code:
void free_hash_table(struct hash_table * hl)
{
  struct hash_list * me;
  struct hash_list * p;
  uint32_t bytes = 0;
  for (int n = 0; n <= 255; n++) {
    p = hl->table[n];
    me = p;
    while (p != ((void *)0)) {
      p = p->next;
      free(me->entries);
      bytes += me->capacity * sizeof(struct path_list_entry *);
      free(me);
      bytes += sizeof(struct hash_list);
      me = p;
    }
    hl->table[n] = ((void *)0);
  }
  free(hl->table);
  bytes += 256 * sizeof(struct hash_list *);
  free(hl);
  bytes += sizeof(struct hash_table);
  dec_stats_hashtable(bytes);
}

canonical_original_code:
void free_hash_table(struct hash_table *hl)
{
  struct hash_list *me;
  struct hash_list *p;
  unsigned int bytes = 0;
  for (int n = 0; n <= 255; n++) {
    p = hl->table[n];
    me = p;
    while (p != ((void *)0)) {
      p = p->next;
      free(me->entries);
      bytes += me->capacity * sizeof(struct path_list_entry *);
      free(me);
      bytes += sizeof(struct hash_list);
      me = p;
    }
    hl->table[n] = ((void *)0);
  }
  free(hl->table);
  bytes += 256 * sizeof(struct hash_list *);
  free(hl);
  bytes += sizeof(struct hash_table);
  dec_stats_hashtable(bytes);
}


decompiled_code:
void __fastcall add_hash_table(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5)
{
const char *v8; // rax
char v9[64]; // [rsp+0h] [rbp-1068h] BYREF
char v10[4136]; // [rsp+40h] [rbp-1028h] BYREF

build_path(a2, v10);
if ( (unsigned int)hash_fn(v10, v9, a3, a4, a5) )
{
if ( log_level > 7 )
{
pthread_mutex_lock(&logger_lock);
v8 = (const char *)get_thread_name();
printf("%s", v8);
printf("SKIP [%s]: Unable to compute hash\n", v10);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
else
{
add_to_hash_table(a1, a2, v9);
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5)
{
const char *v8; // rax
char v9[64]; // [rsp+0h] [rbp-1068h] BYREF
char v10[4136]; // [rsp+40h] [rbp-1028h] BYREF

build_path(a2, v10);
if ( (unsigned int)hash_fn(v10, v9, a3, a4, a5) )
{
if ( log_level > 7 )
{
pthread_mutex_lock(&logger_lock);
v8 = (const char *)get_thread_name();
printf("%s", v8);
printf("SKIP [%s]: Unable to compute hash\n", v10);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
else
{
func6(a1, a2, v9);
}
}

original_code:
void add_hash_table(struct hash_table * hl, struct path_list_entry * file,
                    uint64_t blocks, int bsize, uint64_t skip)
{
  char hash_out[64];
  char path[4096];
  build_path(file, path);
  int rv = hash_fn(path, hash_out, blocks, bsize, skip);
  if (rv != 0) {
    if (8 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("SKIP [%s]: Unable to compute hash\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    return;
  }
  add_to_hash_table(hl, file, hash_out);
}

canonical_original_code:
void add_hash_table(struct hash_table *hl, struct path_list_entry *file, unsigned long blocks, int bsize, unsigned long skip)
{
  char hash_out[64];
  char path[4096];
  build_path(file, path);
  int rv = hash_fn(path, hash_out, blocks, bsize, skip);
  if (rv != 0) {
    if (8 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("SKIP [%s]: Unable to compute hash\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    return;
  }
  add_to_hash_table(hl, file, hash_out);
}

variable_types:
file
struct path_list_entry *

variable_types:
blocks
unsigned long

variable_types: bsize int

variable_types:
skip
unsigned long

variable_types:
path
char [4096]

variable_types: rv int


decompiled_code:
void free_path_buffer()
{
void **v0; // rax
void **v1; // rbp

v0 = (void **)pthread_getspecific(duplicate_path_buffer);
if ( v0 )
{
v1 = v0;
pthread_setspecific(duplicate_path_buffer, 0LL);
free(v1[1]);
free(v1);
}
}

canonical_decompiled_code:
void func12()
{
void **v0; // rax
void **v1; // rbp

v0 = (void **)pthread_getspecific(duplicate_path_buffer);
if ( v0 )
{
v1 = v0;
pthread_setspecific(duplicate_path_buffer, 0LL);
free(v1[1]);
free(v1);
}
}

original_code:
void free_path_buffer()
{
  struct path_buffer_info * pbi = pthread_getspecific(duplicate_path_buffer);
  if (pbi != ((void *)0)) {
    pthread_setspecific(duplicate_path_buffer, ((void *)0));
    free(pbi->buf);
    free(pbi);
  }
}

canonical_original_code:
void free_path_buffer()
{
  struct path_buffer_info *pbi = pthread_getspecific(duplicate_path_buffer);
  if (pbi != ((void *)0)) {
    pthread_setspecific(duplicate_path_buffer, ((void *)0));
    free(pbi->buf);
    free(pbi);
  }
}

user_defined_types: struct path_buffer_info { int size; char *buf; }


decompiled_code:
void __fastcall print_hash_table(unsigned __int8 *a1)
{
__int64 i; // rbx
unsigned int *v2; // rsi
const char *v3; // rax

if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v3 = (const char *)get_thread_name();
printf("%s", v3);
printf("=====hash_table at %p, has_dups: %d\n", a1, a1[10]);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
for ( i = 0LL; i != 256; ++i )
{
v2 = *(unsigned int **)(*(_QWORD *)a1 + 8 * i);
if ( v2 )
print_hash_list_entry(i, v2);
}
}

canonical_decompiled_code:
void __fastcall func14(unsigned __int8 *a1)
{
__int64 i; // rbx
unsigned int *v2; // rsi
const char *v3; // rax

if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v3 = (const char *)get_thread_name();
printf("%s", v3);
printf("=====hash_table at %p, has_dups: %d\n", a1, a1[10]);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
for ( i = 0LL; i != 256; ++i )
{
v2 = *(unsigned int **)(*(_QWORD *)a1 + 8 * i);
if ( v2 )
func4(i, v2);
}
}

original_code:
void print_hash_table(struct hash_table * src)
{
  if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("=====hash_table at %p, has_dups: %d\n", src, src->has_dups); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  for (int n = 0; n < 256; n++) {
    if (src->table[n] != ((void *)0)) {
      print_hash_list_entry(n, src->table[n]);
    }
  }
}

canonical_original_code:
void print_hash_table(struct hash_table *src)
{
  if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("=====hash_table at %p, has_dups: %d\n", src, src->has_dups); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  for (int n = 0; n < 256; n++) {
    if (src->table[n] != ((void *)0)) {
      print_hash_list_entry(n, src->table[n]);
    }
  }
}


decompiled_code:
__int64 __fastcall skim_uniques(__int64 a1, _QWORD *a2)
{
__int64 v3; // rsi
__int64 v4; // rbp
unsigned int v5; // er12
__int64 v6; // rbx
__int64 v8; // r15
__int64 v9; // rsi
const char *v10; // rax

v3 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
if ( v3 == debug_size )
dump_path_list("ENTER skim_uniques", v3, a1, 1LL);
v4 = 0LL;
v5 = 0;
do
{
while ( 1 )
{
v6 = *(_QWORD *)(*a2 + v4);
if ( v6 )
break;
v4 += 8LL;
if ( v4 == 2048 )
return v5;
}
do
{
if ( !*(_DWORD *)v6 )
break;
v9 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
if ( v9 == debug_size )
dump_path_list("skim_uniques", v9, a1, 1LL);
if ( *(_DWORD *)(v6 + 84) == 1 )
{
v8 = **(_QWORD **)(v6 + 72);
if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v10 = (const char *)get_thread_name();
printf("%s", v10);
puts("skim_uniques: marking a single entry list unique");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
++v5;
mark_path_entry_unique(a1, v8);
increase_unique_counter(1LL);
}
v6 = *(_QWORD *)(v6 + 88);
}
while ( v6 );
v4 += 8LL;
}
while ( v4 != 2048 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _QWORD *a2)
{
__int64 v3; // rsi
__int64 v4; // rbp
unsigned int v5; // er12
__int64 v6; // rbx
__int64 v8; // r15
__int64 v9; // rsi
const char *v10; // rax

v3 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
if ( v3 == debug_size )
dump_path_list("ENTER skim_uniques", v3, a1, 1LL);
v4 = 0LL;
v5 = 0;
do
{
while ( 1 )
{
v6 = *(_QWORD *)(*a2 + v4);
if ( v6 )
break;
v4 += 8LL;
if ( v4 == 2048 )
return v5;
}
do
{
if ( !*(_DWORD *)v6 )
break;
v9 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
if ( v9 == debug_size )
dump_path_list("skim_uniques", v9, a1, 1LL);
if ( *(_DWORD *)(v6 + 84) == 1 )
{
v8 = **(_QWORD **)(v6 + 72);
if ( log_level > 9 )
{
pthread_mutex_lock(&logger_lock);
v10 = (const char *)get_thread_name();
printf("%s", v10);
puts("skim_uniques: marking a single entry list unique");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
++v5;
mark_path_entry_unique(a1, v8);
increase_unique_counter(1LL);
}
v6 = *(_QWORD *)(v6 + 88);
}
while ( v6 );
v4 += 8LL;
}
while ( v4 != 2048 );
return v5;
}

original_code:
int skim_uniques(struct path_list_head * head, struct hash_table * src)
{
  struct path_list_entry * entry;
  int skimmed = 0;
  struct hash_list * p;
  if (debug_size == head->sizelist->size) {
    dump_path_list("ENTER skim_uniques", head->sizelist->size, head, 1);
  }
  for (int n = 0; n <= 255; n++) {
    if (src->table[n] != ((void *)0)) {
      p = src->table[n];
      while (p != ((void *)0) && p->hash_valid) {
        if (debug_size == head->sizelist->size) {
          dump_path_list("skim_uniques", head->sizelist->size, head, 1);
        }
        if (p->next_index == 1) {
          entry = *(p->entries);
          if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("skim_uniques: marking a single entry list unique\n"); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
          mark_path_entry_unique(head, entry);
          skimmed++;
          increase_unique_counter(1);
        }
        p = p->next;
      }
    }
  }
  return skimmed;
}

canonical_original_code:
int skim_uniques(struct path_list_head *head, struct hash_table *src)
{
  struct path_list_entry *entry;
  int skimmed = 0;
  struct hash_list *p;
  if (debug_size == head->sizelist->size) {
    dump_path_list("ENTER skim_uniques", head->sizelist->size, head, 1);
  }
  for (int n = 0; n <= 255; n++) {
    if (src->table[n] != ((void *)0)) {
      p = src->table[n];
      while (p != ((void *)0) && p->hash_valid) {
        if (debug_size == head->sizelist->size) {
          dump_path_list("skim_uniques", head->sizelist->size, head, 1);
        }
        if (p->next_index == 1) {
          entry = *(p->entries);
          if (10 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("skim_uniques: marking a single entry list unique\n"); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
          mark_path_entry_unique(head, entry);
          skimmed++;
          increase_unique_counter(1);
        }
        p = p->next;
      }
    }
  }
  return skimmed;
}

variable_types: struct path_list_head { struct size_list { struct path_list_head *path_list; struct size_list *next; unsigned long size; int fully_read; 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; } lock; } *sizelist; struct path_list_entry { struct path_list_entry *next; struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *blocks; struct direntry { struct direntry *parent; char *name; unsigned short total_size; unsigned char name_size; } *dir; char *buffer; void *hash_ctx; unsigned long file_pos; unsigned long next_read_byte; unsigned int next_buffer_pos; unsigned int bufsize; unsigned int data_in_buffer; int fd; unsigned char state; unsigned char filename_size; unsigned char next_read_block; } *last_entry; unsigned int wanted_bufsize; unsigned int list_size; unsigned int buffer_ready; unsigned char state; unsigned char hash_passes; unsigned char have_cached_hashes; } *

variable_types: struct hash_table { struct hash_list { int hash_valid; char hash[64]; struct path_list_entry **entries; int capacity; int next_index; struct hash_list *next; } **table; unsigned short entries; unsigned char has_dups; } *

variable_types: skimmed int


decompiled_code:
__int64 __fastcall hash_table_has_dups(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 10);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return *(unsigned __int8 *)(a1 + 10);
}

original_code:
inline int hash_table_has_dups(struct hash_table * hl)
{
  return hl->has_dups;
}

canonical_original_code:
inline int hash_table_has_dups(struct hash_table *hl)
{
  return hl->has_dups;
}


decompiled_code:
__time_t get_current_time_millis()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

canonical_decompiled_code:
__time_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 1000;
}

original_code:
uint64_t get_current_time_millis()
{
  struct timeval tp;
  gettimeofday(&tp, ((void *)0));
  return (tp.tv_sec * 1000L) + (tp.tv_usec / 1000L);
}

canonical_original_code:
unsigned long get_current_time_millis()
{
  struct timeval tp;
  gettimeofday(&tp, ((void *)0));
  return (tp.tv_sec * 1000L) + (tp.tv_usec / 1000L);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: unsigned long


decompiled_code:
int __fastcall time_string(char *a1, int a2, __int64 a3)
{
int result; // eax

if ( a2 <= 12 )
{
puts("error: time_string buffer too small");
exit(1);
}
if ( a3 <= 10000 )
result = snprintf(a1, a2, "%8ld ms", a3);
else
result = snprintf(a1, a2, "%9ld s", a3 / 1000);
return result;
}

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

if ( a2 <= 12 )
{
puts("error: time_string buffer too small");
exit(1);
}
if ( a3 <= 10000 )
result = snprintf(a1, a2, "%8ld ms", a3);
else
result = snprintf(a1, a2, "%9ld s", a3 / 1000);
return result;
}

original_code:
void time_string(char * out, int len, long ms)
{
  if (len < 13) {
    printf("error: time_string buffer too small\n");
    exit(1);
  }
  if (ms > 10000) {
    snprintf(out, len, "%9ld s", ms / 1000);
  } else {
    snprintf(out, len, "%8ld ms", ms);
  }
}

canonical_original_code:
void time_string(char *out, int len, long ms)
{
  if (len < 13) {
    printf("error: time_string buffer too small\n");
    exit(1);
  }
  if (ms > 10000) {
    snprintf(out, len, "%9ld s", ms / 1000);
  } else {
    snprintf(out, len, "%8ld ms", ms);
  }
}

variable_types:
out
char *

variable_types: len int

variable_types: ms long


decompiled_code:
__int64 __fastcall slow_down(int a1, int a2)
{
unsigned int v3; // eax
int v4; // edx
__int64 v5; // r12

if ( rand() % a1 )
return 0LL;
v3 = get_current_time_millis();
srand(v3);
v4 = rand() % a2 + 1;
v5 = v4;
usleep(1000 * v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
unsigned int v3; // eax
int v4; // edx
__int64 v5; // r12

if ( rand() % a1 )
return 0LL;
v3 = func0();
srand(v3);
v4 = rand() % a2 + 1;
v5 = v4;
usleep(1000 * v4);
return v5;
}

original_code:
long slow_down(int prob, int max_delay_ms)
{
  if (rand() % prob == 0) {
    srand((int)get_current_time_millis());
    long millis = 1 + (rand() % max_delay_ms);
    usleep(1000 * millis);
    return millis;
  }
  return 0;
}

variable_types: prob int

variable_types: millis long

return_type: long


decompiled_code:
__int64 cpu_cores()
{
return sysconf(84);
}

canonical_decompiled_code:
__int64 func3()
{
return sysconf(84);
}

original_code:
int cpu_cores()
{
  return sysconf(_SC_NPROCESSORS_ONLN);
}


decompiled_code:
__int64 total_ram()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = sysconf(85);
result = v0 * sysconf(30);
if ( !result )
result = 0x100000000LL;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = sysconf(85);
result = v0 * sysconf(30);
if ( !result )
result = 0x100000000LL;
return result;
}

original_code:
uint64_t total_ram()
{
  uint64_t ram = (uint64_t)sysconf(_SC_PHYS_PAGES) * (uint64_t)sysconf(_SC_PAGESIZE);
  if (ram == 0) { ram = 4UL * (1024 * 1024 * 1024); }
  return ram;
}

canonical_original_code:
unsigned long total_ram()
{
  unsigned long ram = (uint64_t)sysconf(_SC_PHYS_PAGES) * (uint64_t)sysconf(_SC_PAGESIZE);
  if (ram == 0) { ram = 4UL * (1024 * 1024 * 1024); }
  return ram;
}

variable_types:
ram
unsigned long


memdump

decompiled_code:
int __fastcall memdump(const char *a1, unsigned __int8 *a2, int a3)
{
__int64 v3; // rbp
unsigned __int8 *v4; // rbx
unsigned __int8 *v5; // rbp
__int64 v6; // rsi

v3 = a3;
v4 = a2;
if ( a1 )
printf("%s: ", a1);
if ( (int)v3 > 0 )
{
v5 = &a2[v3];
do
{
v6 = *v4++;
printf("%02x ", v6);
}
while ( v4 != v5 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1, unsigned __int8 *a2, int a3)
{
__int64 v3; // rbp
unsigned __int8 *v4; // rbx
unsigned __int8 *v5; // rbp
__int64 v6; // rsi

v3 = a3;
v4 = a2;
if ( a1 )
printf("%s: ", a1);
if ( (int)v3 > 0 )
{
v5 = &a2[v3];
do
{
v6 = *v4++;
printf("%02x ", v6);
}
while ( v4 != v5 );
}
return putchar(10);
}

original_code:
void memdump(char * text, char * ptr, int bytes)
{
  int i;
  unsigned char * p = (unsigned char *)ptr;
  if (text != ((void *)0)) {
    printf("%s: ", text);
  }
  for (i=0; i<bytes; i++) {
    printf("%02x ", *p++);
  }
  printf("\n");
}

canonical_original_code:
void memdump(char *text, char *ptr, int bytes)
{
  int i;
  unsigned char *p = (unsigned char *)ptr;
  if (text != ((void *)0)) {
    printf("%s: ", text);
  }
  for (i=0; i<bytes; i++) {
    printf("%02x ", *p++);
  }
  printf("\n");
}

variable_types:
text
char *

variable_types:
ptr
char *

variable_types: bytes int

variable_types: i int

variable_types:
p
unsigned char *


decompiled_code:
const char *get_thread_name()
{
const char *result; // rax

if ( log_level <= 6 )
return (const char *)&unk_CF5;
result = (const char *)pthread_getspecific(thread_name);
if ( !result )
result = "*** UNNAMED THREAD ***";
return result;
}

canonical_decompiled_code:
const char *func6()
{
const char *result; // rax

if ( log_level <= 6 )
return (const char *)&unk_CF5;
result = (const char *)pthread_getspecific(thread_name);
if ( !result )
result = "*** UNNAMED THREAD ***";
return result;
}

original_code:
char * get_thread_name()
{
  if (log_level >= 7) {
    char * name = pthread_getspecific(thread_name);
    if (name == ((void *)0)) {
      return "*** UNNAMED THREAD ***";
    } else {
      return name;
    }
  }
  return "";
}

canonical_original_code:
char *get_thread_name()
{
  if (log_level >= 7) {
    char *name = pthread_getspecific(thread_name);
    if (name == ((void *)0)) {
      return "*** UNNAMED THREAD ***";
    } else {
      return name;
    }
  }
  return "";
}

variable_types:
name
char *

return_type: char *


decompiled_code:
__int64 __fastcall get_file_info(const char *a1, struct stat64 *a2)
{
unsigned int v2; // er12
const char *v4; // rax

if ( !a1 || !*a1 )
{
puts("get_file_info called on null or empty path!");
exit(1);
}
v2 = lstat64(a1, a2);
if ( v2 )
return (unsigned int)-1;
if ( log_level <= 12 )
return v2;
pthread_mutex_lock(&logger_lock);
v4 = get_thread_name();
printf("%s", v4);
printf("stat: %s: size: %lu c_time: %lu\n", a1, a2->st_size, a2->st_ctim.tv_sec);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, struct stat64 *a2)
{
unsigned int v2; // er12
const char *v4; // rax

if ( !a1 || !*a1 )
{
puts("get_file_info called on null or empty path!");
exit(1);
}
v2 = lstat64(a1, a2);
if ( v2 )
return (unsigned int)-1;
if ( log_level <= 12 )
return v2;
pthread_mutex_lock(&logger_lock);
v4 = func6();
printf("%s", v4);
printf("stat: %s: size: %lu c_time: %lu\n", a1, a2->st_size, a2->st_ctim.tv_sec);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
return v2;
}

original_code:
int get_file_info(const char * path, struct stat * info)
{
  if (path == ((void *)0) || path[0] == 0) {
    printf("get_file_info called on null or empty path!\n");
    exit(1);
  }
  int rv = lstat(path, info);
  if (rv) {
    return -1;
  }
  if (13 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("stat: %s: size: %" "l" "u" " c_time: %" "l" "u" "\n", path, info->st_size, (uint64_t)info->st_ctim.tv_sec); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  return 0;
}

canonical_original_code:
int get_file_info(char *path, struct stat *info)
{
  if (path == ((void *)0) || path[0] == 0) {
    printf("get_file_info called on null or empty path!\n");
    exit(1);
  }
  int rv = lstat(path, info);
  if (rv) {
    return -1;
  }
  if (13 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("stat: %s: size: %" "l" "u" " c_time: %" "l" "u" "\n", path, info->st_size, (unsigned long)info->st_ctim.tv_sec); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  return 0;
}

variable_types:
path
char *

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

variable_types: rv int

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:
_BOOL8 __fastcall file_exists(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = get_file_info(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = func7(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = (v3.st_mode & 0xF000) == 0x8000;
return result;
}

original_code:
int file_exists(const char * path)
{
  struct stat pathinfo;
  int rv = get_file_info(path, &pathinfo);
  if (rv < 0) { return 0; }
  if (((((pathinfo.st_mode)) & 0170000) == (0100000))) {
    return 1;
  }
  return 0;
}

canonical_original_code:
int file_exists(char *path)
{
  struct stat pathinfo;
  int rv = get_file_info(path, &pathinfo);
  if (rv < 0) { return 0; }
  if (((((pathinfo.st_mode)) & 0170000) == (0100000))) {
    return 1;
  }
  return 0;
}

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


decompiled_code:
__int64 __fastcall read_file_bytes(const char *a1, void *a2, size_t a3, __off64_t a4, ssize_t *a5)
{
int v8; // eax
int v9; // ebp
ssize_t v10; // rax
unsigned int v11; // er12
const char *v13; // rax
const char *v14; // rax

*a5 = 0LL;
v8 = open64(a1, 0);
if ( v8 < 0 )
{
if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v13 = get_thread_name();
printf("%s", v13);
printf("Error opening [%s]\n", a1);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
++s_files_cant_read;
v11 = -1;
}
else
{
v9 = v8;
if ( a4 && a4 != lseek64(v8, a4, 0) )
{
if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v14 = get_thread_name();
printf("%s", v14);
printf("Error seeking [%s]\n", a1);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
LABEL_12:
exit(1);
}
if ( !a3 )
{
printf("error: requested zero bytes from [%s] (skip=%lu)\n", a1, a4);
goto LABEL_12;
}
v10 = read(v9, a2, a3);
if ( v10 < 0 )
{
++s_files_cant_read;
v11 = -1;
}
else
{
*a5 = v10;
v11 = 0;
stats_total_bytes_read += v10;
}
close(v9);
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, void *a2, size_t a3, __off64_t a4, ssize_t *a5)
{
int v8; // eax
int v9; // ebp
ssize_t v10; // rax
unsigned int v11; // er12
const char *v13; // rax
const char *v14; // rax

*a5 = 0LL;
v8 = open64(a1, 0);
if ( v8 < 0 )
{
if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v13 = func6();
printf("%s", v13);
printf("Error opening [%s]\n", a1);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
++s_files_cant_read;
v11 = -1;
}
else
{
v9 = v8;
if ( a4 && a4 != lseek64(v8, a4, 0) )
{
if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v14 = func6();
printf("%s", v14);
printf("Error seeking [%s]\n", a1);
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
LABEL_12:
exit(1);
}
if ( !a3 )
{
printf("error: requested zero bytes from [%s] (skip=%lu)\n", a1, a4);
goto LABEL_12;
}
v10 = read(v9, a2, a3);
if ( v10 < 0 )
{
++s_files_cant_read;
v11 = -1;
}
else
{
*a5 = v10;
v11 = 0;
stats_total_bytes_read += v10;
}
close(v9);
}
return v11;
}

original_code:
int read_file_bytes(char * path, char * output,
                    uint64_t bytes, uint64_t skip, uint64_t * bytes_read)
{
  *bytes_read = 0;
  int file = open(path, 00);
  if (file < 0) {
    if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Error opening [%s]\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    s_files_cant_read++;
    return(-1);
  }
  if (skip > 0) {
    uint64_t pos = lseek(file, skip, 0);
    if (pos != skip) {
      if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Error seeking [%s]\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
      exit(1);
    }
  }
  if (bytes == 0) {
    printf("error: requested zero bytes from [%s] (skip=%" "l" "u" ")\n",
           path, skip);
    exit(1);
  }
  int rv = 0;
  ssize_t got = read(file, output, bytes);
  if (got >= 0) {
    *bytes_read = got;
    stats_total_bytes_read += *bytes_read;
  } else {
    rv = -1;
    s_files_cant_read++;
  }
  close(file);
  return rv;
}

canonical_original_code:
int read_file_bytes(char *path, char *output, unsigned long bytes, unsigned long skip, unsigned long *bytes_read)
{
  *bytes_read = 0;
  int file = open(path, 00);
  if (file < 0) {
    if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Error opening [%s]\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    s_files_cant_read++;
    return(-1);
  }
  if (skip > 0) {
    unsigned long pos = lseek(file, skip, 0);
    if (pos != skip) {
      if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Error seeking [%s]\n", path); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
      exit(1);
    }
  }
  if (bytes == 0) {
    printf("error: requested zero bytes from [%s] (skip=%" "l" "u" ")\n",
           path, skip);
    exit(1);
  }
  int rv = 0;
  long got = read(file, output, bytes);
  if (got >= 0) {
    *bytes_read = got;
    stats_total_bytes_read += *bytes_read;
  } else {
    rv = -1;
    s_files_cant_read++;
  }
  close(file);
  return rv;
}

variable_types:
output
char *

variable_types:
bytes
unsigned long

variable_types:
skip
unsigned long

variable_types: file int

variable_types:
pos
unsigned long

variable_types: got long


decompiled_code:
size_t __fastcall linux_strlcpy(char *dest, char *src, size_t n)
{
size_t v4; // rax
size_t v5; // r12

v4 = strlen(src);
v5 = v4;
if ( v4 >= n )
{
printf("error: strlcpy: src too big: %d >= %d\n", (unsigned int)v4, (unsigned int)n);
exit(1);
}
strncpy(dest, src, n);
return v5;
}

canonical_decompiled_code:
size_t __fastcall func11(char *dest, char *src, size_t n)
{
size_t v4; // rax
size_t v5; // r12

v4 = strlen(src);
v5 = v4;
if ( v4 >= n )
{
printf("error: strlcpy: src too big: %d >= %d\n", (unsigned int)v4, (unsigned int)n);
exit(1);
}
strncpy(dest, src, n);
return v5;
}

original_code:
size_t linux_strlcpy(char *dst, const char *src, size_t dstsize)
{
  size_t n = strlen(src);
  if (n >= dstsize) {
    printf("error: strlcpy: src too big: %d >= %d\n", (int)n, (int)dstsize);
    exit(1);
  }
  strncpy(dst, src, dstsize);
  return n;
}

canonical_original_code:
unsigned long linux_strlcpy(char *dst, char *src, unsigned long dstsize)
{
  unsigned long n = strlen(src);
  if (n >= dstsize) {
    printf("error: strlcpy: src too big: %d >= %d\n", (int)n, (int)dstsize);
    exit(1);
  }
  strncpy(dst, src, dstsize);
  return n;
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
dstsize
unsigned long

variable_types:
n
unsigned long


decompiled_code:
int __fastcall dump_block_list(const char *a1, unsigned __int8 *a2)
{
int result; // eax
__int64 *v3; // rbx
int v4; // ebp
__int64 v5; // r9
__int64 v6; // r8
__int64 v7; // rdx
__int64 v8; // rcx

if ( a2 )
{
result = printf("%sBLOCK LIST: count=%d\n", a1, *a2);
if ( *a2 )
{
v3 = (__int64 *)(a2 + 8);
v4 = 0;
do
{
v5 = v3[2];
v6 = v3[1];
v7 = (unsigned int)v4;
v8 = *v3;
++v4;
v3 += 3;
printf("%s[%d] start_pos: %lu , len: %lu , block: %lu\n", a1, v7, v8, v6, v5);
result = *a2;
}
while ( result > v4 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, unsigned __int8 *a2)
{
int result; // eax
__int64 *v3; // rbx
int v4; // ebp
__int64 v5; // r9
__int64 v6; // r8
__int64 v7; // rdx
__int64 v8; // rcx

if ( a2 )
{
result = printf("%sBLOCK LIST: count=%d\n", a1, *a2);
if ( *a2 )
{
v3 = (__int64 *)(a2 + 8);
v4 = 0;
do
{
v5 = v3[2];
v6 = v3[1];
v7 = (unsigned int)v4;
v8 = *v3;
++v4;
v3 += 3;
printf("%s[%d] start_pos: %lu , len: %lu , block: %lu\n", a1, v7, v8, v6, v5);
result = *a2;
}
while ( result > v4 );
}
}
return result;
}

original_code:
void dump_block_list(const char * prefix, struct block_list * bl)
{
  if (bl == ((void *)0)) { return; }
  printf("%sBLOCK LIST: count=%d\n", prefix, bl->count);
  for (int n = 0; n < bl->count; n++) {
    printf("%s[%d] "
           "start_pos: %" "l" "u" " ,  len: %" "l" "u" " , block: %" "l" "u""\n",
           prefix, n,
           bl->entry[n].start_pos, bl->entry[n].len, bl->entry[n].block);
  }
}

canonical_original_code:
void dump_block_list(char *prefix, struct block_list *bl)
{
  if (bl == ((void *)0)) { return; }
  printf("%sBLOCK LIST: count=%d\n", prefix, bl->count);
  for (int n = 0; n < bl->count; n++) {
    printf("%s[%d] "
           "start_pos: %" "l" "u" " ,  len: %" "l" "u" " , block: %" "l" "u""\n",
           prefix, n,
           bl->entry[n].start_pos, bl->entry[n].len, bl->entry[n].block);
  }
}

variable_types:
prefix
char *

variable_types: struct block_list { unsigned char count; struct block_list_entry { unsigned long start_pos; unsigned long len; unsigned long block; } entry[]; } *

variable_types: n int


decompiled_code:
_DWORD *fiemap_alloc()
{
_DWORD *result; // rax

result = calloc(0x37E8uLL, 1uLL);
result[6] = 255;
return result;
}

canonical_decompiled_code:
_DWORD *func13()
{
_DWORD *result; // rax

result = calloc(0x37E8uLL, 1uLL);
result[6] = 255;
return result;
}

original_code:
void * fiemap_alloc()
{
  struct fiemap * fiemap;
  int fiesize = sizeof(struct fiemap) + 255 * sizeof(struct fiemap_extent);
  fiemap = (struct fiemap *)malloc(fiesize);
  memset(fiemap, 0, fiesize);
  fiemap->fm_start = 0;
  fiemap->fm_length = 0;
  fiemap->fm_flags = 0;
  fiemap->fm_extent_count = 255;
  fiemap->fm_mapped_extents = 0;
  return (void *)fiemap;
}

canonical_original_code:
void *fiemap_alloc()
{
  struct fiemap *fiemap;
  int fiesize = sizeof(struct fiemap) + 255 * sizeof(struct fiemap_extent);
  fiemap = (struct fiemap *)malloc(fiesize);
  memset(fiemap, 0, fiesize);
  fiemap->fm_start = 0;
  fiemap->fm_length = 0;
  fiemap->fm_flags = 0;
  fiemap->fm_extent_count = 255;
  fiemap->fm_mapped_extents = 0;
  return (void *)fiemap;
}

variable_types: struct fiemap { unsigned long long fm_start; unsigned long long fm_length; unsigned int fm_flags; unsigned int fm_mapped_extents; unsigned int fm_extent_count; unsigned int fm_reserved; struct fiemap_extent { unsigned long long fe_logical; unsigned long long fe_physical; unsigned long long fe_length; unsigned long long fe_reserved64[2]; unsigned int fe_flags; unsigned int fe_reserved[3]; } fm_extents[]; } *

variable_types: fiesize int

return_type: void *

user_defined_types: struct fiemap { unsigned long long fm_start; unsigned long long fm_length; unsigned int fm_flags; unsigned int fm_mapped_extents; unsigned int fm_extent_count; unsigned int fm_reserved; struct fiemap_extent fm_extents[]; }


decompiled_code:
__int64 get_file_limit()
{
unsigned int v0; // eax
unsigned int v1; // er12
const char *v3; // rax
struct rlimit64 v4; // [rsp+0h] [rbp-18h] BYREF

if ( getrlimit64(RLIMIT_NOFILE, &v4) )
{
v1 = 200;
if ( log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v3 = get_thread_name();
printf("%s", v3);
puts("Unable get file limit, guessing...");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
else
{
v0 = v4.rlim_cur;
if ( v4.rlim_cur < v4.rlim_max )
{
v4.rlim_cur = v4.rlim_max;
setrlimit64(RLIMIT_NOFILE, &v4);
getrlimit64(RLIMIT_NOFILE, &v4);
v0 = v4.rlim_cur;
}
v1 = v0;
}
return v1;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // eax
unsigned int v1; // er12
const char *v3; // rax
struct rlimit64 v4; // [rsp+0h] [rbp-18h] BYREF

if ( getrlimit64(RLIMIT_NOFILE, &v4) )
{
v1 = 200;
if ( log_level > 3 )
{
pthread_mutex_lock(&logger_lock);
v3 = func6();
printf("%s", v3);
puts("Unable get file limit, guessing...");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
}
else
{
v0 = v4.rlim_cur;
if ( v4.rlim_cur < v4.rlim_max )
{
v4.rlim_cur = v4.rlim_max;
setrlimit64(RLIMIT_NOFILE, &v4);
getrlimit64(RLIMIT_NOFILE, &v4);
v0 = v4.rlim_cur;
}
v1 = v0;
}
return v1;
}

original_code:
int get_file_limit()
{
  struct rlimit rlim;
  if (getrlimit(RLIMIT_NOFILE, &rlim)) {
    if (4 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("Unable get file limit, guessing...\n"); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
    return 200;
  }
  if (rlim.rlim_cur < rlim.rlim_max) {
    rlim.rlim_cur = rlim.rlim_max;
    setrlimit(RLIMIT_NOFILE, &rlim);
    getrlimit(RLIMIT_NOFILE, &rlim);
  }
  return rlim.rlim_cur;
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
unsigned int __fastcall d_mutex_lock(pthread_mutex_t *a1, const char *a2)
{
unsigned int result; // eax

result = pthread_mutex_lock(a1);
if ( result )
{
printf("error: %s: pthread_mutex_lock == %d\n", a2, result);
exit(1);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func0(pthread_mutex_t *a1, const char *a2)
{
unsigned int result; // eax

result = pthread_mutex_lock(a1);
if ( result )
{
printf("error: %s: pthread_mutex_lock == %d\n", a2, result);
exit(1);
}
return result;
}

original_code:
static inline void d_mutex_lock(pthread_mutex_t * mutex, char * line)
{
  int rv = pthread_mutex_lock(mutex);
  if (rv != 0) {
    printf("error: %s: pthread_mutex_lock == %d\n", line, rv);
    exit(1);
  }
}

canonical_original_code:
static inline void d_mutex_lock(union pthread_mutex_t *mutex, char *line)
{
  int rv = pthread_mutex_lock(mutex);
  if (rv != 0) {
    printf("error: %s: pthread_mutex_lock == %d\n", line, rv);
    exit(1);
  }
}

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

variable_types:
line
char *

variable_types: rv int


decompiled_code:
unsigned int __fastcall d_mutex_unlock(pthread_mutex_t *a1)
{
unsigned int result; // eax

result = pthread_mutex_unlock(a1);
if ( result )
{
printf("error: pthread_mutex_unlock == %d\n", result);
exit(1);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(pthread_mutex_t *a1)
{
unsigned int result; // eax

result = pthread_mutex_unlock(a1);
if ( result )
{
printf("error: pthread_mutex_unlock == %d\n", result);
exit(1);
}
return result;
}

original_code:
static inline void d_mutex_unlock(pthread_mutex_t * mutex)
{
  int rv = pthread_mutex_unlock(mutex);
  if (rv != 0) {
    printf("error: pthread_mutex_unlock == %d\n", rv);
    exit(1);
  }
}

canonical_original_code:
static inline void d_mutex_unlock(union pthread_mutex_t *mutex)
{
  int rv = pthread_mutex_unlock(mutex);
  if (rv != 0) {
    printf("error: pthread_mutex_unlock == %d\n", rv);
    exit(1);
  }
}

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


decompiled_code:
int report_stats()
{
int v0; // edx
int v1; // ecx
int result; // eax
int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // ebx
__int64 v6; // rax
int v7; // er12
char v8[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = log_level;
if ( log_level > 0 )
{
putchar(10);
v6 = get_current_time_millis();
time_string(v8, 20LL, v6 - stats_main_start);
printf(
"Total duplicates: %d files in %d groups in %s\n",
(unsigned int)s_files_completed_dups,
(unsigned int)stats_duplicate_groups,
v8);
if ( stats_duplicate_files > 0 )
puts("Run 'dupd report' to list duplicates.");
v0 = log_level;
}
v1 = s_files_hl_skip;
result = s_files_too_small + s_files_skip_notfile;
v3 = s_files_in_sizetree;
v4 = s_total_files_seen
- (s_files_too_small
+ s_files_skip_notfile)
- s_files_skip_error
- s_files_skip_badsep
- s_files_hl_skip;
if ( v0 > 1 )
{
v7 = s_files_processed;
putchar(10);
printf("Total files seen: %u\n", (unsigned int)s_total_files_seen);
printf(
" (too small: %u, not file: %u, errors: %u, skip: %u, hl_skip: %u)\n",
(unsigned int)s_files_too_small,
(unsigned int)s_files_skip_notfile,
(unsigned int)s_files_skip_error,
(unsigned int)s_files_skip_badsep,
(unsigned int)s_files_hl_skip);
printf("Files queued for processing: %u in %u sets\n", v4, (unsigned int)s_stats_size_list_count);
printf(" (files with unique size: %u)\n", (unsigned int)(v3 - v7));
printf("Total files to process: %u\n", (unsigned int)s_files_processed);
printf(" Duplicate files: %u\n", (unsigned int)s_files_completed_dups);
printf(" Unique files: %u\n", (unsigned int)s_files_completed_unique);
printf(" Unable to read: %u\n", (unsigned int)s_files_cant_read);
result = hardlink_is_unique;
if ( hardlink_is_unique )
result = printf(" Skipped hardlinks: %u\n", (unsigned int)s_files_hl_skip);
v3 = s_files_in_sizetree;
v1 = s_files_hl_skip;
}
v5 = v3 - v1;
if ( v5 != v4 )
{
printf("error: mismatch files_accepted: %u != files in sizetree: %u\n", v4, v5);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int v0; // edx
int v1; // ecx
int result; // eax
int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // ebx
__int64 v6; // rax
int v7; // er12
char v8[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = log_level;
if ( log_level > 0 )
{
putchar(10);
v6 = get_current_time_millis();
time_string(v8, 20LL, v6 - stats_main_start);
printf(
"Total duplicates: %d files in %d groups in %s\n",
(unsigned int)s_files_completed_dups,
(unsigned int)stats_duplicate_groups,
v8);
if ( stats_duplicate_files > 0 )
puts("Run 'dupd report' to list duplicates.");
v0 = log_level;
}
v1 = s_files_hl_skip;
result = s_files_too_small + s_files_skip_notfile;
v3 = s_files_in_sizetree;
v4 = s_total_files_seen
- (s_files_too_small
+ s_files_skip_notfile)
- s_files_skip_error
- s_files_skip_badsep
- s_files_hl_skip;
if ( v0 > 1 )
{
v7 = s_files_processed;
putchar(10);
printf("Total files seen: %u\n", (unsigned int)s_total_files_seen);
printf(
" (too small: %u, not file: %u, errors: %u, skip: %u, hl_skip: %u)\n",
(unsigned int)s_files_too_small,
(unsigned int)s_files_skip_notfile,
(unsigned int)s_files_skip_error,
(unsigned int)s_files_skip_badsep,
(unsigned int)s_files_hl_skip);
printf("Files queued for processing: %u in %u sets\n", v4, (unsigned int)s_stats_size_list_count);
printf(" (files with unique size: %u)\n", (unsigned int)(v3 - v7));
printf("Total files to process: %u\n", (unsigned int)s_files_processed);
printf(" Duplicate files: %u\n", (unsigned int)s_files_completed_dups);
printf(" Unique files: %u\n", (unsigned int)s_files_completed_unique);
printf(" Unable to read: %u\n", (unsigned int)s_files_cant_read);
result = hardlink_is_unique;
if ( hardlink_is_unique )
result = printf(" Skipped hardlinks: %u\n", (unsigned int)s_files_hl_skip);
v3 = s_files_in_sizetree;
v1 = s_files_hl_skip;
}
v5 = v3 - v1;
if ( v5 != v4 )
{
printf("error: mismatch files_accepted: %u != files in sizetree: %u\n", v4, v5);
exit(1);
}
return result;
}

original_code:
void report_stats()
{
  if (log_level >= 1) {
    printf("\n");
    char timebuf[20];
    time_string(timebuf, 20, get_current_time_millis() - stats_main_start);
    printf("Total duplicates: %d files in %d groups in %s\n",
           s_files_completed_dups, stats_duplicate_groups, timebuf);
    if (stats_duplicate_files > 0) {
      printf("Run 'dupd report' to list duplicates.\n");
    }
  }
  uint32_t files_accepted = s_total_files_seen - s_files_too_small -
    s_files_skip_notfile - s_files_skip_error - s_files_skip_badsep -
    s_files_hl_skip;
  uint32_t unique_files = s_files_in_sizetree - s_files_processed;
  if (log_level >= 2) {
    printf("\n");
    printf("Total files seen: %" "u" "\n", s_total_files_seen);
    printf(" (too small: %" "u" ", not file: %"
           "u" ", errors: %" "u" ", skip: %" "u" ", hl_skip: %"
           "u" ")\n",
           s_files_too_small, s_files_skip_notfile,
           s_files_skip_error, s_files_skip_badsep, s_files_hl_skip);
    printf("Files queued for processing: %" "u" " in %" "u" " sets\n",
           files_accepted, s_stats_size_list_count);
    printf(" (files with unique size: %" "u" ")\n", unique_files);
    printf("Total files to process: %" "u" "\n", s_files_processed);
    printf(" Duplicate files: %" "u" "\n", s_files_completed_dups);
    printf(" Unique files: %" "u" "\n", s_files_completed_unique);
    printf(" Unable to read: %" "u" "\n", s_files_cant_read);
    if (hardlink_is_unique) {
      printf(" Skipped hardlinks: %" "u" "\n", s_files_hl_skip);
    }
  }
  if (files_accepted != s_files_in_sizetree - s_files_hl_skip) {
    printf("error: mismatch files_accepted: %" "u"
           " != files in sizetree: %" "u" "\n",
           files_accepted, s_files_in_sizetree - s_files_hl_skip);
    exit(1);
  }
}

canonical_original_code:
void report_stats()
{
  if (log_level >= 1) {
    printf("\n");
    char timebuf[20];
    time_string(timebuf, 20, get_current_time_millis() - stats_main_start);
    printf("Total duplicates: %d files in %d groups in %s\n",
           s_files_completed_dups, stats_duplicate_groups, timebuf);
    if (stats_duplicate_files > 0) {
      printf("Run 'dupd report' to list duplicates.\n");
    }
  }
  unsigned int files_accepted = s_total_files_seen - s_files_too_small -
    s_files_skip_notfile - s_files_skip_error - s_files_skip_badsep -
    s_files_hl_skip;
  unsigned int unique_files = s_files_in_sizetree - s_files_processed;
  if (log_level >= 2) {
    printf("\n");
    printf("Total files seen: %" "u" "\n", s_total_files_seen);
    printf(" (too small: %" "u" ", not file: %"
           "u" ", errors: %" "u" ", skip: %" "u" ", hl_skip: %"
           "u" ")\n",
           s_files_too_small, s_files_skip_notfile,
           s_files_skip_error, s_files_skip_badsep, s_files_hl_skip);
    printf("Files queued for processing: %" "u" " in %" "u" " sets\n",
           files_accepted, s_stats_size_list_count);
    printf(" (files with unique size: %" "u" ")\n", unique_files);
    printf("Total files to process: %" "u" "\n", s_files_processed);
    printf(" Duplicate files: %" "u" "\n", s_files_completed_dups);
    printf(" Unique files: %" "u" "\n", s_files_completed_unique);
    printf(" Unable to read: %" "u" "\n", s_files_cant_read);
    if (hardlink_is_unique) {
      printf(" Skipped hardlinks: %" "u" "\n", s_files_hl_skip);
    }
  }
  if (files_accepted != s_files_in_sizetree - s_files_hl_skip) {
    printf("error: mismatch files_accepted: %" "u"
           " != files in sizetree: %" "u" "\n",
           files_accepted, s_files_in_sizetree - s_files_hl_skip);
    exit(1);
  }
}

variable_types:
timebuf
char [20]


decompiled_code:
unsigned int __fastcall inc_stats_read_buffers_allocated(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
int v5; // eax
char v7[88]; // [rsp+0h] [rbp-58h] BYREF

d_mutex_lock(&stats_lock, "increasing buffers");
stats_read_buffers_allocated += a3;
if ( trace_file_fd > 0 )
{
v4 = get_current_time_millis();
v5 = snprintf(v7, 0x50uLL, "%lu A RB %u %lu\n", v4 - stats_main_start, a3, stats_read_buffers_allocated);
write(trace_file_fd, v7, v5);
}
return d_mutex_unlock(&stats_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
int v5; // eax
char v7[88]; // [rsp+0h] [rbp-58h] BYREF

func0(&stats_lock, "increasing buffers");
stats_read_buffers_allocated += a3;
if ( trace_file_fd > 0 )
{
v4 = get_current_time_millis();
v5 = snprintf(v7, 0x50uLL, "%lu A RB %u %lu\n", v4 - stats_main_start, a3, stats_read_buffers_allocated);
write(trace_file_fd, v7, v5);
}
return func1(&stats_lock);
}

original_code:
void inc_stats_read_buffers_allocated(char * path,
                                      uint64_t size, uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_read_buffers_allocated += bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    uint64_t t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " A RB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_read_buffers_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void inc_stats_read_buffers_allocated(char *path, unsigned long size, unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_read_buffers_allocated += bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    unsigned long t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " A RB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_read_buffers_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

variable_types:
path
char *

variable_types:
size
unsigned long

variable_types:
bytes
unsigned int

variable_types:
line
char [80]

variable_types:
t
unsigned long


decompiled_code:
unsigned int __fastcall dec_stats_read_buffers_allocated(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
int v5; // eax
char v7[88]; // [rsp+0h] [rbp-58h] BYREF

d_mutex_lock(&stats_lock, "decreasing buffers");
stats_read_buffers_allocated -= a3;
if ( trace_file_fd > 0 )
{
v4 = get_current_time_millis();
v5 = snprintf(v7, 0x50uLL, "%lu F RB %u %lu\n", v4 - stats_main_start, a3, stats_read_buffers_allocated);
write(trace_file_fd, v7, v5);
}
return d_mutex_unlock(&stats_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rax
int v5; // eax
char v7[88]; // [rsp+0h] [rbp-58h] BYREF

func0(&stats_lock, "decreasing buffers");
stats_read_buffers_allocated -= a3;
if ( trace_file_fd > 0 )
{
v4 = get_current_time_millis();
v5 = snprintf(v7, 0x50uLL, "%lu F RB %u %lu\n", v4 - stats_main_start, a3, stats_read_buffers_allocated);
write(trace_file_fd, v7, v5);
}
return func1(&stats_lock);
}

original_code:
void dec_stats_read_buffers_allocated(char * path,
                                      uint64_t size, uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "decreasing buffers");
  stats_read_buffers_allocated -= bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    uint64_t t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " F RB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_read_buffers_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void dec_stats_read_buffers_allocated(char *path, unsigned long size, unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "decreasing buffers");
  stats_read_buffers_allocated -= bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    unsigned long t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " F RB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_read_buffers_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall inc_stats_size_list(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // eax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

d_mutex_lock(&stats_lock, "increasing buffers");
stats_size_list_allocated += a2;
if ( trace_file_fd > 0 )
{
v2 = get_current_time_millis();
v3 = snprintf(v5, 0x50uLL, "%lu A SL %u %lu\n", v2 - stats_main_start, a2, stats_size_list_allocated);
write(trace_file_fd, v5, v3);
}
return d_mutex_unlock(&stats_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // eax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

func0(&stats_lock, "increasing buffers");
stats_size_list_allocated += a2;
if ( trace_file_fd > 0 )
{
v2 = get_current_time_millis();
v3 = snprintf(v5, 0x50uLL, "%lu A SL %u %lu\n", v2 - stats_main_start, a2, stats_size_list_allocated);
write(trace_file_fd, v5, v3);
}
return func1(&stats_lock);
}

original_code:
void inc_stats_size_list(uint64_t size, uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_list_allocated += bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    uint64_t t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " A SL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_list_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void inc_stats_size_list(unsigned long size, unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_list_allocated += bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    unsigned long t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " A SL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_list_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall dec_stats_size_list(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // eax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

d_mutex_lock(&stats_lock, "decreasing buffers");
stats_size_list_allocated -= a2;
if ( trace_file_fd > 0 )
{
v2 = get_current_time_millis();
v3 = snprintf(v5, 0x50uLL, "%lu F SL %u %lu\n", v2 - stats_main_start, a2, stats_size_list_allocated);
write(trace_file_fd, v5, v3);
}
return d_mutex_unlock(&stats_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
int v3; // eax
char v5[88]; // [rsp+0h] [rbp-58h] BYREF

func0(&stats_lock, "decreasing buffers");
stats_size_list_allocated -= a2;
if ( trace_file_fd > 0 )
{
v2 = get_current_time_millis();
v3 = snprintf(v5, 0x50uLL, "%lu F SL %u %lu\n", v2 - stats_main_start, a2, stats_size_list_allocated);
write(trace_file_fd, v5, v3);
}
return func1(&stats_lock);
}

original_code:
void dec_stats_size_list(uint64_t size, uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "decreasing buffers");
  stats_size_list_allocated -= bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    uint64_t t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " F SL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_list_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void dec_stats_size_list(unsigned long size, unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "decreasing buffers");
  stats_size_list_allocated -= bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    unsigned long t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " F SL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_list_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall inc_stats_hashtable(unsigned int a1)
{
__int64 v1; // rax
int v2; // eax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

d_mutex_lock(&stats_lock, "increasing buffers");
stats_size_hashtable_allocated += a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu A HT %u %lu\n", v1 - stats_main_start, a1, stats_size_hashtable_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func8(unsigned int a1)
{
__int64 v1; // rax
int v2; // eax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

func0(&stats_lock, "increasing buffers");
stats_size_hashtable_allocated += a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu A HT %u %lu\n", v1 - stats_main_start, a1, stats_size_hashtable_allocated);
write(trace_file_fd, v4, v2);
}
return func1(&stats_lock);
}

original_code:
void inc_stats_hashtable(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_hashtable_allocated += bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    uint64_t t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " A HT %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_hashtable_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void inc_stats_hashtable(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_hashtable_allocated += bytes;
  ;
  if (trace_file_fd > 0) {
    char line[80];
    int n;
    unsigned long t = get_current_time_millis() - stats_main_start;
    n = snprintf(line, 80, "%" "l" "u" " A HT %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_hashtable_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}