decompiled_code:
unsigned int __fastcall dec_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 F 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 func9(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 F 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 dec_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" " F 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 dec_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" " F HT %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_hashtable_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


repo: jvirkki/dupd

decompiled_code:
unsigned int __fastcall inc_stats_readlist(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_readlist_allocated += a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu A RL %u %lu\n", v1 - stats_main_start, a1, stats_size_readlist_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

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

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

original_code:
void inc_stats_readlist(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_readlist_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 RL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_readlist_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void inc_stats_readlist(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_readlist_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 RL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_readlist_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

variable_types:
bytes
unsigned int

variable_types:
line
char [80]

variable_types: n int

variable_types:
t
unsigned long

return_type: void


decompiled_code:
unsigned int __fastcall dec_stats_readlist(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_readlist_allocated -= a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu F RL %u %lu\n", v1 - stats_main_start, a1, stats_size_readlist_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

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

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

original_code:
void dec_stats_readlist(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_readlist_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 RL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_readlist_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void dec_stats_readlist(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_readlist_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 RL %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_readlist_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall inc_stats_dirbuf(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_dirbuf_allocated += a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu A DB %u %lu\n", v1 - stats_main_start, a1, stats_size_dirbuf_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

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

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

original_code:
void inc_stats_dirbuf(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_dirbuf_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 DB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_dirbuf_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void inc_stats_dirbuf(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_dirbuf_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 DB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_dirbuf_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall dec_stats_dirbuf(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_dirbuf_allocated -= a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu F DB %u %lu\n", v1 - stats_main_start, a1, stats_size_dirbuf_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

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

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

original_code:
void dec_stats_dirbuf(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_dirbuf_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 DB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_dirbuf_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void dec_stats_dirbuf(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_dirbuf_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 DB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_dirbuf_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall inc_stats_pblocks(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_pblocks_allocated += a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu A PB %u %lu\n", v1 - stats_main_start, a1, stats_size_pblocks_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

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

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

original_code:
void inc_stats_pblocks(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_pblocks_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 PB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_pblocks_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void inc_stats_pblocks(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_pblocks_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 PB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_pblocks_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall dec_stats_pblocks(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_pblocks_allocated -= a1;
if ( trace_file_fd > 0 )
{
v1 = get_current_time_millis();
v2 = snprintf(v4, 0x50uLL, "%lu F PB %u %lu\n", v1 - stats_main_start, a1, stats_size_pblocks_allocated);
write(trace_file_fd, v4, v2);
}
return d_mutex_unlock(&stats_lock);
}

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

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

original_code:
void dec_stats_pblocks(uint32_t bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_pblocks_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 PB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_pblocks_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}

canonical_original_code:
void dec_stats_pblocks(unsigned int bytes)
{
  d_mutex_lock(&stats_lock, "increasing buffers");
  stats_size_pblocks_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 PB %" "u" " %" "l" "u" "\n",
                 t, bytes, stats_size_pblocks_allocated);
    write(trace_file_fd, line, n);
  }
  d_mutex_unlock(&stats_lock);
}


decompiled_code:
unsigned int __fastcall increase_unique_counter(int a1)
{
d_mutex_lock(&counters_lock, "counters");
s_files_completed_unique += a1;
return d_mutex_unlock(&counters_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func16(int a1)
{
func0(&counters_lock, "counters");
s_files_completed_unique += a1;
return func1(&counters_lock);
}

original_code:
void increase_unique_counter(int n)
{
  d_mutex_lock(&counters_lock, "counters");
  s_files_completed_unique += n;
  d_mutex_unlock(&counters_lock);
}


decompiled_code:
unsigned int __fastcall increase_dup_counter(int a1)
{
d_mutex_lock(&counters_lock, "counters");
s_files_completed_dups += a1;
return d_mutex_unlock(&counters_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func17(int a1)
{
func0(&counters_lock, "counters");
s_files_completed_dups += a1;
return func1(&counters_lock);
}

original_code:
void increase_dup_counter(int n)
{
  d_mutex_lock(&counters_lock, "counters");
  s_files_completed_dups += n;
  d_mutex_unlock(&counters_lock);
}


decompiled_code:
unsigned int increase_sets_first_read()
{
d_mutex_lock(&counters_lock, "counters");
++count_sets_first_read;
return d_mutex_unlock(&counters_lock);
}

canonical_decompiled_code:
unsigned int func18()
{
func0(&counters_lock, "counters");
++count_sets_first_read;
return func1(&counters_lock);
}

original_code:
void increase_sets_first_read()
{
  d_mutex_lock(&counters_lock, "counters");
  count_sets_first_read++;
  d_mutex_unlock(&counters_lock);
}


decompiled_code:
unsigned int increase_sets_first_read_completed()
{
d_mutex_lock(&counters_lock, "counters");
++stats_sets_first_read_completed;
return d_mutex_unlock(&counters_lock);
}

canonical_decompiled_code:
unsigned int func19()
{
func0(&counters_lock, "counters");
++stats_sets_first_read_completed;
return func1(&counters_lock);
}

original_code:
void increase_sets_first_read_completed()
{
  d_mutex_lock(&counters_lock, "counters");
  stats_sets_first_read_completed++;
  d_mutex_unlock(&counters_lock);
}


decompiled_code:
unsigned int __fastcall update_open_files(int a1)
{
d_mutex_lock(&counters_lock, "counters");
current_open_files += a1;
return d_mutex_unlock(&counters_lock);
}

canonical_decompiled_code:
unsigned int __fastcall func20(int a1)
{
func0(&counters_lock, "counters");
current_open_files += a1;
return func1(&counters_lock);
}

original_code:
void update_open_files(int n)
{
  d_mutex_lock(&counters_lock, "counters");
  current_open_files += n;
  d_mutex_unlock(&counters_lock);
}


decompiled_code:
void __fastcall show_extents(const char *a1)
{
void *v1; // r12
__int64 v2; // rax
_QWORD v3[21]; // [rsp+0h] [rbp-A8h] BYREF

if ( (unsigned int)get_file_info(a1, v3) )
{
printf("error: unable to stat %s\n", a1);
}
else
{
v1 = (void *)fiemap_alloc();
v2 = get_block_info_from_path(a1, v3[1], v3[6], v1);
dump_block_list(&unk_B5, v2);
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func0(const char *a1)
{
void *v1; // r12
__int64 v2; // rax
_QWORD v3[21]; // [rsp+0h] [rbp-A8h] BYREF

if ( (unsigned int)get_file_info(a1, v3) )
{
printf("error: unable to stat %s\n", a1);
}
else
{
v1 = (void *)fiemap_alloc();
v2 = get_block_info_from_path(a1, v3[1], v3[6], v1);
dump_block_list(&unk_B5, v2);
free(v1);
}
}

original_code:
void show_extents(char * path)
{
  struct block_list * bl;
  struct stat finfo;
  if (get_file_info(path, &finfo)) {
    printf("error: unable to stat %s\n", path);
    return;
  }
  void * fmap = fiemap_alloc();
  bl = get_block_info_from_path(path, finfo.st_ino, finfo.st_size, fmap);
  dump_block_list("", bl);
  free(fmap);
}

canonical_original_code:
void show_extents(char *path)
{
  struct block_list *bl;
  struct stat finfo;
  if (get_file_info(path, &finfo)) {
    printf("error: unable to stat %s\n", path);
    return;
  }
  void *fmap = fiemap_alloc();
  bl = get_block_info_from_path(path, finfo.st_ino, finfo.st_size, fmap);
  dump_block_list("", bl);
  free(fmap);
}

variable_types:
path
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: 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:
fmap
void *

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

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


decompiled_code:
void operation_info()
{
if ( info_extents_path )
show_extents(info_extents_path);
}

canonical_decompiled_code:
void func1()
{
if ( info_extents_path )
func0(info_extents_path);
}

original_code:
void operation_info()
{
  if (info_extents_path != ((void *)0)) {
    show_extents(info_extents_path);
  }
}


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

result = a1 + 80;
if ( !a1 )
result = 0LL;
return result;
}

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

result = a1 + 80;
if ( !a1 )
result = 0LL;
return result;
}

original_code:
static inline char * pb_get_filename(struct path_list_entry * entry)
{
  if (entry == ((void *)0)) { return ((void *)0); }
  return (char *)((char *)entry + sizeof(struct path_list_entry));
}

canonical_original_code:
static inline char *pb_get_filename(struct path_list_entry *entry)
{
  if (entry == ((void *)0)) { return ((void *)0); }
  return (char *)((char *)entry + sizeof(struct path_list_entry));
}

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

return_type: char *

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


decompiled_code:
__int64 __fastcall dirbuf_alloc(unsigned int a1)
{
__int64 v1; // rbp
unsigned int v2; // eax
__int64 v3; // r8
__int64 result; // rax
unsigned int v5; // er13
_DWORD *v6; // rax
_DWORD *v7; // r12
void *v8; // rax

v1 = last_dirbuf;
v2 = *(_DWORD *)(last_dirbuf + 20);
if ( v2 < a1 )
{
v5 = 2 * *(_DWORD *)(last_dirbuf + 16);
v6 = malloc(0x20uLL);
*(_QWORD *)(v1 + 24) = v6;
v7 = v6;
last_dirbuf = (__int64)v6;
v8 = malloc(v5);
v7[4] = v5;
*(_QWORD *)v7 = v8;
*((_QWORD *)v7 + 1) = v8;
v7[5] = v5;
*((_QWORD *)v7 + 3) = 0LL;
inc_stats_dirbuf(v5);
v1 = last_dirbuf;
v2 = *(_DWORD *)(last_dirbuf + 20);
}
v3 = *(_QWORD *)(v1 + 8);
total_dirbufs += a1;
*(_DWORD *)(v1 + 20) = v2 - a1;
result = v3;
*(_QWORD *)(v1 + 8) = v3 + a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 v1; // rbp
unsigned int v2; // eax
__int64 v3; // r8
__int64 result; // rax
unsigned int v5; // er13
_DWORD *v6; // rax
_DWORD *v7; // r12
void *v8; // rax

v1 = last_dirbuf;
v2 = *(_DWORD *)(last_dirbuf + 20);
if ( v2 < a1 )
{
v5 = 2 * *(_DWORD *)(last_dirbuf + 16);
v6 = malloc(0x20uLL);
*(_QWORD *)(v1 + 24) = v6;
v7 = v6;
last_dirbuf = (__int64)v6;
v8 = malloc(v5);
v7[4] = v5;
*(_QWORD *)v7 = v8;
*((_QWORD *)v7 + 1) = v8;
v7[5] = v5;
*((_QWORD *)v7 + 3) = 0LL;
inc_stats_dirbuf(v5);
v1 = last_dirbuf;
v2 = *(_DWORD *)(last_dirbuf + 20);
}
v3 = *(_QWORD *)(v1 + 8);
total_dirbufs += a1;
*(_DWORD *)(v1 + 20) = v2 - a1;
result = v3;
*(_QWORD *)(v1 + 8) = v3 + a1;
return result;
}

original_code:
static inline char * dirbuf_alloc(uint32_t size)
{
  if (last_dirbuf->free < size) {
    uint32_t nextsize = last_dirbuf->size * 2;
    struct dirbuf_list * n;
    n = (struct dirbuf_list *)malloc(sizeof(struct dirbuf_list));
    last_dirbuf->next = n;
    last_dirbuf = n;
    last_dirbuf->ptr = (char *)malloc(nextsize);
    last_dirbuf->pos = last_dirbuf->ptr;
    last_dirbuf->size = nextsize;
    last_dirbuf->free = nextsize;
    last_dirbuf->next = ((void *)0);
    inc_stats_dirbuf(nextsize);
  }
  char * p = last_dirbuf->pos;
  last_dirbuf->pos += size;
  last_dirbuf->free -= size;
  total_dirbufs += size;
  return p;
}

canonical_original_code:
static inline char *dirbuf_alloc(unsigned int size)
{
  if (last_dirbuf->free < size) {
    unsigned int nextsize = last_dirbuf->size * 2;
    struct dirbuf_list *n;
    n = (struct dirbuf_list *)malloc(sizeof(struct dirbuf_list));
    last_dirbuf->next = n;
    last_dirbuf = n;
    last_dirbuf->ptr = (char *)malloc(nextsize);
    last_dirbuf->pos = last_dirbuf->ptr;
    last_dirbuf->size = nextsize;
    last_dirbuf->free = nextsize;
    last_dirbuf->next = ((void *)0);
    inc_stats_dirbuf(nextsize);
  }
  char *p = last_dirbuf->pos;
  last_dirbuf->pos += size;
  last_dirbuf->free -= size;
  total_dirbufs += size;
  return p;
}

variable_types:
size
unsigned int

variable_types:
nextsize
unsigned int

variable_types: struct dirbuf_list { char *ptr; char *pos; unsigned int size; unsigned int free; struct dirbuf_list *next; } *

variable_types:
p
char *


decompiled_code:
_DWORD *init_dirtree()
{
size_t v0; // rbp
unsigned int v1; // ebx
_DWORD *result; // rax
__int64 v3; // rdx

v0 = x_small_buffers == 0 ? 4096LL : 128LL;
v1 = x_small_buffers == 0 ? 4096 : 128;
first_dirbuf = malloc(0x20uLL);
*(_QWORD *)first_dirbuf = malloc(v0);
inc_stats_dirbuf(v1);
result = first_dirbuf;
v3 = *(_QWORD *)first_dirbuf;
*((_DWORD *)first_dirbuf + 4) = v1;
result[5] = v1;
*((_QWORD *)result + 1) = v3;
*((_QWORD *)result + 3) = 0LL;
last_dirbuf = (__int64)result;
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
size_t v0; // rbp
unsigned int v1; // ebx
_DWORD *result; // rax
__int64 v3; // rdx

v0 = x_small_buffers == 0 ? 4096LL : 128LL;
v1 = x_small_buffers == 0 ? 4096 : 128;
first_dirbuf = malloc(0x20uLL);
*(_QWORD *)first_dirbuf = malloc(v0);
inc_stats_dirbuf(v1);
result = first_dirbuf;
v3 = *(_QWORD *)first_dirbuf;
*((_DWORD *)first_dirbuf + 4) = v1;
result[5] = v1;
*((_QWORD *)result + 1) = v3;
*((_QWORD *)result + 3) = 0LL;
last_dirbuf = (__int64)result;
return result;
}

original_code:
void init_dirtree()
{
  uint32_t init_size = (1024 * 4);
  if (x_small_buffers) { init_size = 128; }
  first_dirbuf = (struct dirbuf_list *)malloc(sizeof(struct dirbuf_list));
  first_dirbuf->ptr = (char *)malloc(init_size);
  inc_stats_dirbuf(init_size);
  last_dirbuf = first_dirbuf;
  last_dirbuf->pos = last_dirbuf->ptr;
  last_dirbuf->size = init_size;
  last_dirbuf->free = init_size;
  last_dirbuf->next = ((void *)0);
}

canonical_original_code:
void init_dirtree()
{
  unsigned int init_size = (1024 * 4);
  if (x_small_buffers) { init_size = 128; }
  first_dirbuf = (struct dirbuf_list *)malloc(sizeof(struct dirbuf_list));
  first_dirbuf->ptr = (char *)malloc(init_size);
  inc_stats_dirbuf(init_size);
  last_dirbuf = first_dirbuf;
  last_dirbuf->pos = last_dirbuf->ptr;
  last_dirbuf->size = init_size;
  last_dirbuf->free = init_size;
  last_dirbuf->next = ((void *)0);
}

user_defined_types: struct dirbuf_list { char *ptr; char *pos; unsigned int size; unsigned int free; struct dirbuf_list *next; }


decompiled_code:
__int64 free_dirtree()
{
void **v0; // rbx
unsigned int v1; // ebp
int v2; // eax
void **v3; // rdi
__int64 v4; // rdi

v0 = (void **)first_dirbuf;
if ( first_dirbuf )
{
v1 = 0;
do
{
free(*v0);
v2 = *((_DWORD *)v0 + 4);
v3 = v0;
v0 = (void **)v0[3];
v1 += v2;
free(v3);
}
while ( v0 );
v4 = v1;
}
else
{
v4 = 0LL;
}
first_dirbuf = 0LL;
last_dirbuf = 0LL;
return dec_stats_dirbuf(v4);
}

canonical_decompiled_code:
__int64 func4()
{
void **v0; // rbx
unsigned int v1; // ebp
int v2; // eax
void **v3; // rdi
__int64 v4; // rdi

v0 = (void **)first_dirbuf;
if ( first_dirbuf )
{
v1 = 0;
do
{
free(*v0);
v2 = *((_DWORD *)v0 + 4);
v3 = v0;
v0 = (void **)v0[3];
v1 += v2;
free(v3);
}
while ( v0 );
v4 = v1;
}
else
{
v4 = 0LL;
}
first_dirbuf = 0LL;
last_dirbuf = 0LL;
return dec_stats_dirbuf(v4);
}

original_code:
void free_dirtree()
{
  struct dirbuf_list * p;
  struct dirbuf_list * prev;
  uint64_t total = 0;
  p = first_dirbuf;
  while(p != ((void *)0)) {
    free(p->ptr);
    total += p->size;
    prev = p;
    p = p->next;
    free(prev);
  }
  first_dirbuf = ((void *)0);
  last_dirbuf = ((void *)0);
  dec_stats_dirbuf(total);
}

canonical_original_code:
void free_dirtree()
{
  struct dirbuf_list *p;
  struct dirbuf_list *prev;
  unsigned long total = 0;
  p = first_dirbuf;
  while(p != ((void *)0)) {
    free(p->ptr);
    total += p->size;
    prev = p;
    p = p->next;
    free(prev);
  }
  first_dirbuf = ((void *)0);
  last_dirbuf = ((void *)0);
  dec_stats_dirbuf(total);
}

variable_types:
total
unsigned long


decompiled_code:
__int64 __fastcall new_child_dir(char *s, __int64 a2)
{
__int64 v2; // r12
unsigned __int8 v3; // al
__int16 v4; // bx
_DWORD *v5; // rax

v2 = dirbuf_alloc(0x18u);
v3 = strlen(s);
LOBYTE(v4) = v3;
if ( v3 == 1 && *s == 47 )
{
if ( a2 )
{
puts("error: new_child_dir: / has non-null parent");
exit(1);
}
*(_BYTE *)(v2 + 18) = 0;
v4 = 0;
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)v2 = 0LL;
}
else
{
*(_BYTE *)(v2 + 18) = v3;
v5 = (_DWORD *)dirbuf_alloc(v3);
*(_QWORD *)(v2 + 8) = v5;
if ( (unsigned __int8)v4 < 8u )
{
if ( (v4 & 4) != 0 )
{
*v5 = *(_DWORD *)s;
*(_DWORD *)((char *)v5 + (unsigned __int8)v4 - 4) = *(_DWORD *)&s[(unsigned __int8)v4 - 4];
}
else if ( (_BYTE)v4 )
{
*(_BYTE *)v5 = *s;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v5 + (unsigned __int8)v4 - 2) = *(_WORD *)&s[(unsigned __int8)v4 - 2];
}
}
else
{
*(_QWORD *)v5 = *(_QWORD *)s;
*(_QWORD *)((char *)v5 + (unsigned __int8)v4 - 8) = *(_QWORD *)&s[(unsigned __int8)v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(v5 + 2) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(s - ((char *)v5 - ((unsigned __int64)(v5 + 2) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + (unsigned __int8)v4) >> 3));
}
*(_QWORD *)v2 = a2;
v4 = (unsigned __int8)v4;
if ( a2 )
v4 = (unsigned __int8)v4 + *(_WORD *)(a2 + 16) + 1;
}
*(_WORD *)(v2 + 16) = v4;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, __int64 a2)
{
__int64 v2; // r12
unsigned __int8 v3; // al
__int16 v4; // bx
_DWORD *v5; // rax

v2 = func1(0x18u);
v3 = strlen(s);
LOBYTE(v4) = v3;
if ( v3 == 1 && *s == 47 )
{
if ( a2 )
{
puts("error: new_child_dir: / has non-null parent");
exit(1);
}
*(_BYTE *)(v2 + 18) = 0;
v4 = 0;
*(_QWORD *)(v2 + 8) = 0LL;
*(_QWORD *)v2 = 0LL;
}
else
{
*(_BYTE *)(v2 + 18) = v3;
v5 = (_DWORD *)func1(v3);
*(_QWORD *)(v2 + 8) = v5;
if ( (unsigned __int8)v4 < 8u )
{
if ( (v4 & 4) != 0 )
{
*v5 = *(_DWORD *)s;
*(_DWORD *)((char *)v5 + (unsigned __int8)v4 - 4) = *(_DWORD *)&s[(unsigned __int8)v4 - 4];
}
else if ( (_BYTE)v4 )
{
*(_BYTE *)v5 = *s;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v5 + (unsigned __int8)v4 - 2) = *(_WORD *)&s[(unsigned __int8)v4 - 2];
}
}
else
{
*(_QWORD *)v5 = *(_QWORD *)s;
*(_QWORD *)((char *)v5 + (unsigned __int8)v4 - 8) = *(_QWORD *)&s[(unsigned __int8)v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(v5 + 2) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(s - ((char *)v5 - ((unsigned __int64)(v5 + 2) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8) + (unsigned __int8)v4) >> 3));
}
*(_QWORD *)v2 = a2;
v4 = (unsigned __int8)v4;
if ( a2 )
v4 = (unsigned __int8)v4 + *(_WORD *)(a2 + 16) + 1;
}
*(_WORD *)(v2 + 16) = v4;
return v2;
}

original_code:
struct direntry * new_child_dir(char * name, struct direntry * parent)
{
  struct direntry * entry = (struct direntry *)dirbuf_alloc(direntry_size);
  uint8_t len = (uint8_t)strlen(name);
  if (len == 1 && name[0] == '/') {
    if (parent != ((void *)0)) {
      printf("error: new_child_dir: / has non-null parent\n");
      exit(1);
    }
    len = 0;
    entry->name_size = 0;
    entry->name = ((void *)0);
  } else {
    entry->name_size = len;
    entry->name = dirbuf_alloc(len);
    memcpy(entry->name, name, len);
  }
  entry->parent = parent;
  if (parent == ((void *)0)) {
    entry->total_size = len;
  } else {
    entry->total_size = len + 1 + parent->total_size;
  }
  return entry;
}

canonical_original_code:
struct direntry *new_child_dir(char *name, struct direntry *parent)
{
  struct direntry *entry = (struct direntry *)dirbuf_alloc(direntry_size);
  unsigned char len = (uint8_t)strlen(name);
  if (len == 1 && name[0] == '/') {
    if (parent != ((void *)0)) {
      printf("error: new_child_dir: / has non-null parent\n");
      exit(1);
    }
    len = 0;
    entry->name_size = 0;
    entry->name = ((void *)0);
  } else {
    entry->name_size = len;
    entry->name = dirbuf_alloc(len);
    memcpy(entry->name, name, len);
  }
  entry->parent = parent;
  if (parent == ((void *)0)) {
    entry->total_size = len;
  } else {
    entry->total_size = len + 1 + parent->total_size;
  }
  return entry;
}

variable_types:
name
char *

variable_types:
parent
struct direntry *

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

variable_types:
len
unsigned char


decompiled_code:
__int64 test_dirtree()
{
__int64 v0; // rax
const char *v2; // rax
__int64 v3; // [rsp+0h] [rbp-408h] BYREF
__int16 v4; // [rsp+8h] [rbp-400h]
char v5; // [rsp+Ah] [rbp-3FEh]

if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v2 = (const char *)get_thread_name();
printf("%s", v2);
puts("=== dirtree ===");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
init_path_block();
init_dirtree();
v0 = new_child_dir("/", 0LL);
build_path_from_string("something", v0, &v3);
if ( v3 != 0x696874656D6F732FLL || v4 != 26478 || v5 )
_assert_fail("!strcmp(\"/something\", buffer)", "src/testing.c", 0x2Du, "test_dirtree");
return free_dirtree();
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
const char *v2; // rax
__int64 v3; // [rsp+0h] [rbp-408h] BYREF
__int16 v4; // [rsp+8h] [rbp-400h]
char v5; // [rsp+Ah] [rbp-3FEh]

if ( log_level > 2 )
{
pthread_mutex_lock(&logger_lock);
v2 = (const char *)get_thread_name();
printf("%s", v2);
puts("=== dirtree ===");
fflush(stdout);
pthread_mutex_unlock(&logger_lock);
}
init_path_block();
init_dirtree();
v0 = new_child_dir("/", 0LL);
build_path_from_string("something", v0, &v3);
if ( v3 != 0x696874656D6F732FLL || v4 != 26478 || v5 )
_assert_fail("!strcmp(\"/something\", buffer)", "src/testing.c", 0x2Du, "test_dirtree");
return free_dirtree();
}

original_code:
static void test_dirtree()
{
  char buffer[1024];
  if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("=== dirtree ===\n"); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  init_path_block();
  init_dirtree();
  struct direntry * root = new_child_dir("/", ((void *)0));
  build_path_from_string("something", root, buffer);
  ((void) sizeof ((!strcmp("/something", buffer)) ? 1 : 0), __extension__ ({ if (!strcmp("/something", buffer)) ; else __assert_fail ("!strcmp(\"/something\", buffer)", "src/testing.c", 45, __extension__ __PRETTY_FUNCTION__); }));
  free_dirtree();
}

canonical_original_code:
static void test_dirtree()
{
  char buffer[1024];
  if (3 <= log_level) { pthread_mutex_lock(&logger_lock); printf("%s", get_thread_name()); printf("=== dirtree ===\n"); fflush(stdout); pthread_mutex_unlock(&logger_lock); };
  init_path_block();
  init_dirtree();
  struct direntry *root = new_child_dir("/", ((void *)0));
  build_path_from_string("something", root, buffer);
  ((void) sizeof ((!strcmp("/something", buffer)) ? 1 : 0), __extension__ ({ if (!strcmp("/something", buffer)) ; else __assert_fail ("!strcmp(\"/something\", buffer)", "src/testing.c", 45, __extension__ __PRETTY_FUNCTION__); }));
  free_dirtree();
}

variable_types:
buffer
char [1024]

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


testing

decompiled_code:
__int64 testing()
{
test_hash_table();
return test_dirtree();
}

canonical_decompiled_code:
__int64 func1()
{
test_hash_table();
return func0();
}

original_code:
void testing()
{
  test_hash_table();
  test_dirtree();
}


decompiled_code:
void *init_filecompare()
{
void *result; // rax

ptr = malloc(filecmp_block_size);
result = malloc(filecmp_block_size);
s2 = result;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

ptr = malloc(filecmp_block_size);
result = malloc(filecmp_block_size);
s2 = result;
return result;
}

original_code:
void init_filecompare()
{
  buffers[1] = (char *)malloc(filecmp_block_size);
  buffers[2] = (char *)malloc(filecmp_block_size);
}


decompiled_code:
void free_filecompare()
{
free(ptr);
free(s2);
}

canonical_decompiled_code:
void func3()
{
free(ptr);
free(s2);
}

original_code:
void free_filecompare()
{
  free(buffers[1]);
  free(buffers[2]);
}


repo: jvirkki/libbloom

decompiled_code:
__int64 __fastcall test_bit_set_bit(__int64 a1, unsigned __int64 a2, int a3)
{
unsigned int v3; // er8
_BYTE *v4; // rdi
int v5; // eax

v3 = 1;
v4 = (_BYTE *)((a2 >> 3) + a1);
v5 = 1 << (a2 & 7);
if ( ((unsigned __int8)v5 & *v4) == 0 )
{
v3 = 0;
if ( a3 )
*v4 |= v5;
}
return v3;
}

original_code:
inline static int test_bit_set_bit(unsigned char * buf,
                                   unsigned long int bit, int set_bit)
{
  unsigned long int byte = bit >> 3;
  unsigned char c = buf[byte];
  unsigned char mask = 1 << (bit % 8ul);
  if (c & mask) {
    return 1;
  } else {
    if (set_bit) {
      buf[byte] = c | mask;
    }
    return 0;
  }
}

canonical_original_code:
inline static int test_bit_set_bit(unsigned char *buf, unsigned long bit, int set_bit)
{
  unsigned long byte = bit >> 3;
  unsigned char c = buf[byte];
  unsigned char mask = 1 << (bit % 8ul);
  if (c & mask) {
    return 1;
  } else {
    if (set_bit) {
      buf[byte] = c | mask;
    }
    return 0;
  }
}

variable_types:
buf
unsigned char *

variable_types:
bit
unsigned long

variable_types:
byte
unsigned long

variable_types:
c
unsigned char

variable_types:
mask
unsigned char

return_type: int


decompiled_code:
__int64 __fastcall bloom_check_add(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
__int64 v6; // rbx
unsigned __int64 v7; // r9
unsigned __int8 v8; // bl
unsigned __int64 v9; // rdx
__int64 v10; // r9
__int64 v11; // r10
__int64 v12; // r11
__int64 result; // rax

if ( *(_BYTE *)(a1 + 40) )
{
v6 = (unsigned int)murmurhash2(a2, a3, 2538058380LL);
murmurhash2(a2, a3, v6);
if ( *(_BYTE *)(a1 + 24) )
{
v7 = (unsigned int)v6;
v8 = 0;
do
{
if ( (unsigned int)test_bit_set_bit(*(_QWORD *)(a1 + 56), v7 % *(_QWORD *)(a1 + 8), a4) )
{
++v8;
}
else if ( !a4 )
{
return 0LL;
}
v9 = *(unsigned __int8 *)(a1 + 24);
v7 = v12 + v10;
}
while ( v9 > v11 + 1 );
result = (_BYTE)v9 == v8;
}
else
{
result = 1LL;
}
}
else
{
printf("bloom at %p not initialized!\n", (const void *)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
__int64 v6; // rbx
unsigned __int64 v7; // r9
unsigned __int8 v8; // bl
unsigned __int64 v9; // rdx
__int64 v10; // r9
__int64 v11; // r10
__int64 v12; // r11
__int64 result; // rax

if ( *(_BYTE *)(a1 + 40) )
{
v6 = (unsigned int)func19(a2, a3, 2538058380LL);
func19(a2, a3, v6);
if ( *(_BYTE *)(a1 + 24) )
{
v7 = (unsigned int)v6;
v8 = 0;
do
{
if ( (unsigned int)func6(*(_QWORD *)(a1 + 56), v7 % *(_QWORD *)(a1 + 8), a4) )
{
++v8;
}
else if ( !a4 )
{
return 0LL;
}
v9 = *(unsigned __int8 *)(a1 + 24);
v7 = v12 + v10;
}
while ( v9 > v11 + 1 );
result = (_BYTE)v9 == v8;
}
else
{
result = 1LL;
}
}
else
{
printf("bloom at %p not initialized!\n", (const void *)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int bloom_check_add(struct bloom * bloom,
                           const void * buffer, int len, int add)
{
  if (bloom->ready == 0) {
    printf("bloom at %p not initialized!\n", (void *)bloom);
    return -1;
  }
  unsigned char hits = 0;
  unsigned int a = murmurhash2(buffer, len, 0x9747b28c);
  unsigned int b = murmurhash2(buffer, len, a);
  unsigned long int x;
  unsigned long int i;
  for (i = 0; i < bloom->hashes; i++) {
    x = (a + b*i) % bloom->bits;
    if (test_bit_set_bit(bloom->bf, x, add)) {
      hits++;
    } else if (!add) {
      return 0;
    }
  }
  if (hits == bloom->hashes) {
    return 1;
  }
  return 0;
}

canonical_original_code:
static int bloom_check_add(struct bloom *bloom, void *buffer, int len, int add)
{
  if (bloom->ready == 0) {
    printf("bloom at %p not initialized!\n", (void *)bloom);
    return -1;
  }
  unsigned char hits = 0;
  unsigned int a = murmurhash2(buffer, len, 0x9747b28c);
  unsigned int b = murmurhash2(buffer, len, a);
  unsigned long x;
  unsigned long i;
  for (i = 0; i < bloom->hashes; i++) {
    x = (a + b*i) % bloom->bits;
    if (test_bit_set_bit(bloom->bf, x, add)) {
      hits++;
    } else if (!add) {
      return 0;
    }
  }
  if (hits == bloom->hashes) {
    return 1;
  }
  return 0;
}

variable_types: struct bloom { unsigned int entries; unsigned long bits; unsigned long bytes; unsigned char hashes; double error; unsigned char ready; unsigned char major; unsigned char minor; double bpe; unsigned char *bf; } *

variable_types:
buffer
void *

variable_types: len int

variable_types: add int

variable_types:
hits
unsigned char

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
x
unsigned long

variable_types:
i
unsigned long


original_code:
int bloom_init2(struct bloom * bloom, unsigned int entries, double error)
{
  if (sizeof(unsigned long int) < 8) {
    printf("error: libbloom will not function correctly because\n");
    printf("sizeof(unsigned long int) == %ld\n", sizeof(unsigned long int));
    exit(1);
  }
  memset(bloom, 0, sizeof(struct bloom));
  if (entries < 1000 || error <= 0 || error >= 1) {
    return 1;
  }
  bloom->entries = entries;
  bloom->error = error;
  double num = -log(bloom->error);
  double denom = 0.480453013918201;
  bloom->bpe = (num / denom);
  long double dentries = (long double)entries;
  long double allbits = dentries * bloom->bpe;
  bloom->bits = (unsigned long int)allbits;
  if (bloom->bits % 8) {
    bloom->bytes = (bloom->bits / 8) + 1;
  } else {
    bloom->bytes = bloom->bits / 8;
  }
  bloom->hashes = (unsigned char)ceil(0.693147180559945 * bloom->bpe);
  bloom->bf = (unsigned char *)calloc(bloom->bytes, sizeof(unsigned char));
  if (bloom->bf == ((void *)0)) {
    return 1;
  }
  bloom->ready = 1;
  bloom->major = 2;
  bloom->minor = 0;
  return 0;
}

canonical_original_code:
int bloom_init2(struct bloom *bloom, unsigned int entries, double error)
{
  if (sizeof(unsigned long) < 8) {
    printf("error: libbloom will not function correctly because\n");
    printf("sizeof(unsigned long int) == %ld\n", sizeof(unsigned long));
    exit(1);
  }
  memset(bloom, 0, sizeof(struct bloom));
  if (entries < 1000 || error <= 0 || error >= 1) {
    return 1;
  }
  bloom->entries = entries;
  bloom->error = error;
  double num = -log(bloom->error);
  double denom = 0.480453013918201;
  bloom->bpe = (num / denom);
  long double dentries = (long double)entries;
  long double allbits = dentries * bloom->bpe;
  bloom->bits = (unsigned long)allbits;
  if (bloom->bits % 8) {
    bloom->bytes = (bloom->bits / 8) + 1;
  } else {
    bloom->bytes = bloom->bits / 8;
  }
  bloom->hashes = (unsigned char)ceil(0.693147180559945 * bloom->bpe);
  bloom->bf = (unsigned char *)calloc(bloom->bytes, sizeof(unsigned char));
  if (bloom->bf == ((void *)0)) {
    return 1;
  }
  bloom->ready = 1;
  bloom->major = 2;
  bloom->minor = 0;
  return 0;
}

variable_types:
entries
unsigned int

variable_types: error double

variable_types: num double

variable_types: denom double

variable_types:
dentries
long double

variable_types:
allbits
long double

user_defined_types: struct bloom { unsigned int entries; unsigned long bits; unsigned long bytes; unsigned char hashes; double error; unsigned char ready; unsigned char major; unsigned char minor; double bpe; unsigned char *bf; }


decompiled_code:
// attributes: thunk
__int64 bloom_init()
{
return bloom_init2();
}

canonical_decompiled_code:
__int64 func9()
{
return func8();
}

original_code:
int bloom_init(struct bloom * bloom, int entries, double error)
{
  return bloom_init2(bloom, (unsigned int)entries, error);
}

canonical_original_code:
int bloom_init(struct bloom *bloom, int entries, double error)
{
  return bloom_init2(bloom, (unsigned int)entries, error);
}

variable_types: entries int


decompiled_code:
__int64 __fastcall bloom_check(__int64 a1, __int64 a2, unsigned int a3)
{
return bloom_check_add(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, unsigned int a3)
{
return func7(a1, a2, a3, 0);
}

original_code:
int bloom_check(struct bloom * bloom, const void * buffer, int len)
{
  return bloom_check_add(bloom, buffer, len, 0);
}

canonical_original_code:
int bloom_check(struct bloom *bloom, void *buffer, int len)
{
  return bloom_check_add(bloom, buffer, len, 0);
}


decompiled_code:
__int64 __fastcall bloom_add(__int64 a1, __int64 a2, unsigned int a3)
{
return bloom_check_add(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, unsigned int a3)
{
return func7(a1, a2, a3, 1);
}

original_code:
int bloom_add(struct bloom * bloom, const void * buffer, int len)
{
  return bloom_check_add(bloom, buffer, len, 1);
}

canonical_original_code:
int bloom_add(struct bloom *bloom, void *buffer, int len)
{
  return bloom_check_add(bloom, buffer, len, 1);
}


decompiled_code:
int __fastcall bloom_print(unsigned int *a1)
{
printf("bloom at %p\n", a1);
if ( !*((_BYTE *)a1 + 40) )
puts(" *** NOT READY ***");
printf(" ->version = %d.%d\n", *((unsigned __int8 *)a1 + 41), *((unsigned __int8 *)a1 + 42));
printf(" ->entries = %u\n", *a1);
printf(" ->error = %f\n", *((double *)a1 + 4));
printf(" ->bits = %lu\n", *((_QWORD *)a1 + 1));
printf(" ->bits per elem = %f\n", *((double *)a1 + 6));
printf(" ->bytes = %lu", *((_QWORD *)a1 + 2));
printf(" (%u KB, %u MB)\n", *((_QWORD *)a1 + 2) >> 10, (unsigned int)(*((_QWORD *)a1 + 2) >> 10) >> 10);
return printf(" ->hash functions = %d\n", *((unsigned __int8 *)a1 + 24));
}

canonical_decompiled_code:
int __fastcall func12(unsigned int *a1)
{
printf("bloom at %p\n", a1);
if ( !*((_BYTE *)a1 + 40) )
puts(" *** NOT READY ***");
printf(" ->version = %d.%d\n", *((unsigned __int8 *)a1 + 41), *((unsigned __int8 *)a1 + 42));
printf(" ->entries = %u\n", *a1);
printf(" ->error = %f\n", *((double *)a1 + 4));
printf(" ->bits = %lu\n", *((_QWORD *)a1 + 1));
printf(" ->bits per elem = %f\n", *((double *)a1 + 6));
printf(" ->bytes = %lu", *((_QWORD *)a1 + 2));
printf(" (%u KB, %u MB)\n", *((_QWORD *)a1 + 2) >> 10, (unsigned int)(*((_QWORD *)a1 + 2) >> 10) >> 10);
return printf(" ->hash functions = %d\n", *((unsigned __int8 *)a1 + 24));
}

original_code:
void bloom_print(struct bloom * bloom)
{
  printf("bloom at %p\n", (void *)bloom);
  if (!bloom->ready) { printf(" *** NOT READY ***\n"); }
  printf(" ->version = %d.%d\n", bloom->major, bloom->minor);
  printf(" ->entries = %u\n", bloom->entries);
  printf(" ->error = %f\n", bloom->error);
  printf(" ->bits = %lu\n", bloom->bits);
  printf(" ->bits per elem = %f\n", bloom->bpe);
  printf(" ->bytes = %lu", bloom->bytes);
  unsigned int KB = bloom->bytes / 1024;
  unsigned int MB = KB / 1024;
  printf(" (%u KB, %u MB)\n", KB, MB);
  printf(" ->hash functions = %d\n", bloom->hashes);
}

canonical_original_code:
void bloom_print(struct bloom *bloom)
{
  printf("bloom at %p\n", (void *)bloom);
  if (!bloom->ready) { printf(" *** NOT READY ***\n"); }
  printf(" ->version = %d.%d\n", bloom->major, bloom->minor);
  printf(" ->entries = %u\n", bloom->entries);
  printf(" ->error = %f\n", bloom->error);
  printf(" ->bits = %lu\n", bloom->bits);
  printf(" ->bits per elem = %f\n", bloom->bpe);
  printf(" ->bytes = %lu", bloom->bytes);
  unsigned int KB = bloom->bytes / 1024;
  unsigned int MB = KB / 1024;
  printf(" (%u KB, %u MB)\n", KB, MB);
  printf(" ->hash functions = %d\n", bloom->hashes);
}

variable_types:
KB
unsigned int

variable_types:
MB
unsigned int


original_code:
void bloom_free(struct bloom * bloom)
{
  if (bloom->ready) {
    free(bloom->bf);
  }
  bloom->ready = 0;
}

canonical_original_code:
void bloom_free(struct bloom *bloom)
{
  if (bloom->ready) {
    free(bloom->bf);
  }
  bloom->ready = 0;
}

variable_types: struct bloom { unsigned int entries; unsigned long bits; unsigned long bytes; unsigned char hashes; double error; unsigned char ready; unsigned char major; unsigned char minor; double bpe; unsigned char *bf; } *


decompiled_code:
__int64 __fastcall bloom_reset(__int64 a1)
{
if ( !*(_BYTE *)(a1 + 40) )
return 1LL;
memset(*(void **)(a1 + 56), 0, *(_QWORD *)(a1 + 16));
return 0LL;
}

original_code:
int bloom_reset(struct bloom * bloom)
{
  if (!bloom->ready) return 1;
  memset(bloom->bf, 0, bloom->bytes);
  return 0;
}

canonical_original_code:
int bloom_reset(struct bloom *bloom)
{
  if (!bloom->ready) return 1;
  memset(bloom->bf, 0, bloom->bytes);
  return 0;
}


decompiled_code:
__int64 __fastcall bloom_save(void *buf, char *file)
{
int v3; // eax
int v4; // ebp
__int16 bufa[13]; // [rsp+0h] [rbp-1Ah] BYREF

if ( !file )
return 1LL;
if ( *file )
{
v3 = open(file, 65, 420LL);
v4 = v3;
if ( v3 >= 0 )
{
if ( write(v3, "libbloom2", 9uLL) == 9 )
{
bufa[0] = 64;
if ( write(v4, bufa, 2uLL) == 2
&& write(v4, buf, 0x40uLL) == 64
&& *((_QWORD *)buf + 2) == write(v4, *((const void **)buf + 7), *((_QWORD *)buf + 2)) )
{
close(v4);
return 0LL;
}
}
close(v4);
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(void *buf, char *file)
{
int v3; // eax
int v4; // ebp
__int16 bufa[13]; // [rsp+0h] [rbp-1Ah] BYREF

if ( !file )
return 1LL;
if ( *file )
{
v3 = open(file, 65, 420LL);
v4 = v3;
if ( v3 >= 0 )
{
if ( write(v3, "libbloom2", 9uLL) == 9 )
{
bufa[0] = 64;
if ( write(v4, bufa, 2uLL) == 2
&& write(v4, buf, 0x40uLL) == 64
&& *((_QWORD *)buf + 2) == write(v4, *((const void **)buf + 7), *((_QWORD *)buf + 2)) )
{
close(v4);
return 0LL;
}
}
close(v4);
}
}
return 1LL;
}

original_code:
int bloom_save(struct bloom * bloom, char * filename)
{
  if (filename == ((void *)0) || filename[0] == 0) {
    return 1;
  }
  int fd = open(filename, 01 | 0100, 0644);
  if (fd < 0) {
    return 1;
  }
  ssize_t out = write(fd, "libbloom2", strlen("libbloom2"));
  if (out != strlen("libbloom2")) { goto save_error; }
  uint16_t size = sizeof(struct bloom);
  out = write(fd, &size, sizeof(uint16_t));
  if (out != sizeof(uint16_t)) { goto save_error; }
  out = write(fd, bloom, sizeof(struct bloom));
  if (out != sizeof(struct bloom)) { goto save_error; }
  out = write(fd, bloom->bf, bloom->bytes);
  if (out != bloom->bytes) { goto save_error; }
  close(fd);
  return 0;
 save_error:
  close(fd);
  return 1;
}

canonical_original_code:
int bloom_save(struct bloom *bloom, char *filename)
{
  if (filename == ((void *)0) || filename[0] == 0) {
    return 1;
  }
  int fd = open(filename, 01 | 0100, 0644);
  if (fd < 0) {
    return 1;
  }
  long out = write(fd, "libbloom2", strlen("libbloom2"));
  if (out != strlen("libbloom2")) { goto save_error; }
  unsigned short size = sizeof(struct bloom);
  out = write(fd, &size, sizeof(unsigned short));
  if (out != sizeof(unsigned short)) { goto save_error; }
  out = write(fd, bloom, sizeof(struct bloom));
  if (out != sizeof(struct bloom)) { goto save_error; }
  out = write(fd, bloom->bf, bloom->bytes);
  if (out != bloom->bytes) { goto save_error; }
  close(fd);
  return 0;
 save_error:
  close(fd);
  return 1;
}

variable_types:
filename
char *

variable_types: fd int

variable_types: out long

variable_types:
size
unsigned short


original_code:
int bloom_load(struct bloom * bloom, char * filename)
{
  int rv = 0;
  if (filename == ((void *)0) || filename[0] == 0) { return 1; }
  if (bloom == ((void *)0)) { return 2; }
  memset(bloom, 0, sizeof(struct bloom));
  int fd = open(filename, 00);
  if (fd < 0) { return 3; }
  char line[30];
  memset(line, 0, 30);
  ssize_t in = read(fd, line, strlen("libbloom2"));
  if (in != strlen("libbloom2")) {
    rv = 4;
    goto load_error;
  }
  if (strncmp(line, "libbloom2", strlen("libbloom2"))) {
    rv = 5;
    goto load_error;
  }
  uint16_t size;
  in = read(fd, &size, sizeof(uint16_t));
  if (in != sizeof(uint16_t)) {
    rv = 6;
    goto load_error;
  }
  if (size != sizeof(struct bloom)) {
    rv = 7;
    goto load_error;
  }
  in = read(fd, bloom, sizeof(struct bloom));
  if (in != sizeof(struct bloom)) {
    rv = 8;
    goto load_error;
  }
  bloom->bf = ((void *)0);
  if (bloom->major != 2) {
    rv = 9;
    goto load_error;
  }
  bloom->bf = (unsigned char *)malloc(bloom->bytes);
  if (bloom->bf == ((void *)0)) { rv = 10; goto load_error; }
  in = read(fd, bloom->bf, bloom->bytes);
  if (in != bloom->bytes) {
    rv = 11;
    free(bloom->bf);
    bloom->bf = ((void *)0);
    goto load_error;
  }
  close(fd);
  return rv;
 load_error:
  close(fd);
  bloom->ready = 0;
  return rv;
}

canonical_original_code:
int bloom_load(struct bloom *bloom, char *filename)
{
  int rv = 0;
  if (filename == ((void *)0) || filename[0] == 0) { return 1; }
  if (bloom == ((void *)0)) { return 2; }
  memset(bloom, 0, sizeof(struct bloom));
  int fd = open(filename, 00);
  if (fd < 0) { return 3; }
  char line[30];
  memset(line, 0, 30);
  long in = read(fd, line, strlen("libbloom2"));
  if (in != strlen("libbloom2")) {
    rv = 4;
    goto load_error;
  }
  if (strncmp(line, "libbloom2", strlen("libbloom2"))) {
    rv = 5;
    goto load_error;
  }
  unsigned short size;
  in = read(fd, &size, sizeof(unsigned short));
  if (in != sizeof(unsigned short)) {
    rv = 6;
    goto load_error;
  }
  if (size != sizeof(struct bloom)) {
    rv = 7;
    goto load_error;
  }
  in = read(fd, bloom, sizeof(struct bloom));
  if (in != sizeof(struct bloom)) {
    rv = 8;
    goto load_error;
  }
  bloom->bf = ((void *)0);
  if (bloom->major != 2) {
    rv = 9;
    goto load_error;
  }
  bloom->bf = (unsigned char *)malloc(bloom->bytes);
  if (bloom->bf == ((void *)0)) { rv = 10; goto load_error; }
  in = read(fd, bloom->bf, bloom->bytes);
  if (in != bloom->bytes) {
    rv = 11;
    free(bloom->bf);
    bloom->bf = ((void *)0);
    goto load_error;
  }
  close(fd);
  return rv;
 load_error:
  close(fd);
  bloom->ready = 0;
  return rv;
}

variable_types: rv int

variable_types:
line
char [30]

variable_types: in long


decompiled_code:
__int64 __fastcall bloom_merge(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax
__int64 v3; // rdx
unsigned __int64 v4; // rax
_BYTE *v5; // rdx
char v6; // cl

if ( a1[40] )
{
if ( a2[40] )
{
result = 1LL;
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
{
if ( *((double *)a1 + 4) == *((double *)a2 + 4) )
{
if ( a1[41] == a2[41] && a1[42] == a2[42] )
{
v3 = *((_QWORD *)a1 + 2);
if ( v3 == *((_QWORD *)a2 + 2) )
{
v4 = 0LL;
if ( v3 )
{
do
{
v5 = (_BYTE *)(v4 + *((_QWORD *)a1 + 7));
v6 = *(_BYTE *)(*((_QWORD *)a2 + 7) + v4++);
*v5 |= v6;
}
while ( *((_QWORD *)a1 + 2) > v4 );
}
result = 0LL;
}
}
}
else
{
result = 1LL;
}
}
}
else
{
printf("bloom at %p not initialized!\n", a2);
result = 0xFFFFFFFFLL;
}
}
else
{
printf("bloom at %p not initialized!\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax
__int64 v3; // rdx
unsigned __int64 v4; // rax
_BYTE *v5; // rdx
char v6; // cl

if ( a1[40] )
{
if ( a2[40] )
{
result = 1LL;
if ( *(_DWORD *)a1 == *(_DWORD *)a2 )
{
if ( *((double *)a1 + 4) == *((double *)a2 + 4) )
{
if ( a1[41] == a2[41] && a1[42] == a2[42] )
{
v3 = *((_QWORD *)a1 + 2);
if ( v3 == *((_QWORD *)a2 + 2) )
{
v4 = 0LL;
if ( v3 )
{
do
{
v5 = (_BYTE *)(v4 + *((_QWORD *)a1 + 7));
v6 = *(_BYTE *)(*((_QWORD *)a2 + 7) + v4++);
*v5 |= v6;
}
while ( *((_QWORD *)a1 + 2) > v4 );
}
result = 0LL;
}
}
}
else
{
result = 1LL;
}
}
}
else
{
printf("bloom at %p not initialized!\n", a2);
result = 0xFFFFFFFFLL;
}
}
else
{
printf("bloom at %p not initialized!\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int bloom_merge(struct bloom * bloom_dest, struct bloom * bloom_src)
{
  if (bloom_dest->ready == 0) {
    printf("bloom at %p not initialized!\n", (void *)bloom_dest);
    return -1;
  }
  if (bloom_src->ready == 0) {
    printf("bloom at %p not initialized!\n", (void *)bloom_src);
    return -1;
  }
  if (bloom_dest->entries != bloom_src->entries) {
    return 1;
  }
  if (bloom_dest->error != bloom_src->error) {
    return 1;
  }
  if (bloom_dest->major != bloom_src->major) {
    return 1;
  }
  if (bloom_dest->minor != bloom_src->minor) {
    return 1;
  }
  if (bloom_dest->bytes != bloom_src->bytes) {
    return 1;
  }
  unsigned long int p;
  for (p = 0; p < bloom_dest->bytes; p++) {
    bloom_dest->bf[p] |= bloom_src->bf[p];
  }
  return 0;
}

canonical_original_code:
int bloom_merge(struct bloom *bloom_dest, struct bloom *bloom_src)
{
  if (bloom_dest->ready == 0) {
    printf("bloom at %p not initialized!\n", (void *)bloom_dest);
    return -1;
  }
  if (bloom_src->ready == 0) {
    printf("bloom at %p not initialized!\n", (void *)bloom_src);
    return -1;
  }
  if (bloom_dest->entries != bloom_src->entries) {
    return 1;
  }
  if (bloom_dest->error != bloom_src->error) {
    return 1;
  }
  if (bloom_dest->major != bloom_src->major) {
    return 1;
  }
  if (bloom_dest->minor != bloom_src->minor) {
    return 1;
  }
  if (bloom_dest->bytes != bloom_src->bytes) {
    return 1;
  }
  unsigned long p;
  for (p = 0; p < bloom_dest->bytes; p++) {
    bloom_dest->bf[p] |= bloom_src->bf[p];
  }
  return 0;
}

variable_types:
p
unsigned long


decompiled_code:
const char *bloom_version()
{
return "2.0";
}

canonical_decompiled_code:
const char *func18()
{
return "2.0";
}

original_code:
const char * bloom_version()
{
  return "2.0";
}

canonical_original_code:
char *bloom_version()
{
  return "2.0";
}


main

canonical_name: main

repo: jvonmitchell/AptProfile

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

v3 = 0;
while ( 1 )
{
v5 = (char *)stdin;
if ( feof(stdin) )
break;
argv = (const char **)1024;
v5 = buff;
if ( !fgets(buff, 1024, stdin) )
break;
gettimeofday(&tim_temp, 0LL);
if ( v3 )
printtimedif(&tim_temp, 0LL);
v3 = 1;
tim = (__int128)_mm_load_si128((const __m128i *)&tim_temp);
v4 = strlen(buff);
fwrite(buff, 1uLL, v4 - 1, _bss_start);
argv = (const char **)_bss_start;
fputc(9, _bss_start);
}
printtimedif(v5, argv);
return 0;
}

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

v3 = 0;
while ( 1 )
{
v5 = (char *)stdin;
if ( feof(stdin) )
break;
argv = (const char **)1024;
v5 = buff;
if ( !fgets(buff, 1024, stdin) )
break;
gettimeofday(&tim_temp, 0LL);
if ( v3 )
func7(&tim_temp, 0LL);
v3 = 1;
tim = (__int128)_mm_load_si128((const __m128i *)&tim_temp);
v4 = strlen(buff);
fwrite(buff, 1uLL, v4 - 1, _bss_start);
argv = (const char **)_bss_start;
fputc(9, _bss_start);
}
func7(v5, argv);
return 0;
}

original_code:
int main(int argc,char **argv) {
 int should_out=0;
 while(!feof(stdin) && fgets(buff,sizeof(buff),stdin)) {
  gettimeofday(&tim_temp,((void *)0));
  if(should_out) {
   printtimedif();
  }
  should_out=1;
  tim=tim_temp;
  fwrite(buff,1,strlen(buff)-1,stdout);
  fputc('\t',stdout);
 }
 printtimedif();
}

canonical_original_code:
int main(int argc, char **argv) {
 int should_out = 0;
 while(!feof(stdin) && fgets(buff,sizeof(buff),stdin)) {
  gettimeofday(&tim_temp,((void *)0));
  if(should_out) {
   printtimedif();
  }
  should_out=1;
  tim=tim_temp;
  fwrite(buff,1,strlen(buff)-1,stdout);
  fputc('\t',stdout);
 }
 printtimedif();
}

variable_types: argc int

variable_types:
argv
char **


printtimedif

decompiled_code:
int printtimedif()
{
__int64 v0; // rdx
__suseconds_t v1; // r8

v0 = tim_temp.tv_sec - tim;
v1 = tim_temp.tv_usec - *((_QWORD *)&tim + 1);
if ( tim_temp.tv_usec < *((__int64 *)&tim + 1) )
{
--v0;
v1 += 1000000LL;
}
return fprintf(_bss_start, "%ds:%du\n", v0, v1);
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rdx
__suseconds_t v1; // r8

v0 = tim_temp.tv_sec - tim;
v1 = tim_temp.tv_usec - *((_QWORD *)&tim + 1);
if ( tim_temp.tv_usec < *((__int64 *)&tim + 1) )
{
--v0;
v1 += 1000000LL;
}
return fprintf(_bss_start, "%ds:%du\n", v0, v1);
}

original_code:
void printtimedif() {
 suseconds_t usecdif;
 time_t secdif=tim_temp.tv_sec-tim.tv_sec;
 if(tim_temp.tv_usec<tim.tv_usec) {
  --secdif;
  usecdif=tim.tv_usec-tim_temp.tv_usec;
  usecdif=1000000-usecdif;
 }
 else {
  usecdif=tim_temp.tv_usec-tim.tv_usec;
 }
 fprintf(stdout,"%ds:%du\n",secdif,usecdif);
}

canonical_original_code:
void printtimedif() {
 long usecdif;
 long secdif = tim_temp.tv_sec-tim.tv_sec;
 if(tim_temp.tv_usec<tim.tv_usec) {
  --secdif;
  usecdif=tim.tv_usec-tim_temp.tv_usec;
  usecdif=1000000-usecdif;
 }
 else {
  usecdif=tim_temp.tv_usec-tim.tv_usec;
 }
 fprintf(stdout,"%ds:%du\n",secdif,usecdif);
}

variable_types: usecdif long

variable_types: secdif long


spawn

decompiled_code:
__pid_t __fastcall spawn(__int64 a1)
{
__pid_t result; // eax
int v2; // eax

result = fork();
if ( !result )
{
v2 = xcb_get_file_descriptor(dpy);
close(v2);
if ( *(_BYTE *)(a1 + 52) )
putenv((char *)(a1 + 52));
if ( termprog )
{
execl(shell, shell, &unk_AE0, termprog, 0LL);
fprintf(stderr, "9wm: exec %s", shell);
perror(" failed");
}
execlp("9term", "9term", "-9wm", 0LL);
execlp("xterm", "xterm", "-ut", 0LL);
perror("9wm: exec 9term/xterm failed");
exit(0);
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func0(__int64 a1)
{
__pid_t result; // eax
int v2; // eax

result = fork();
if ( !result )
{
v2 = xcb_get_file_descriptor(dpy);
close(v2);
if ( *(_BYTE *)(a1 + 52) )
putenv((char *)(a1 + 52));
if ( termprog )
{
execl(shell, shell, &unk_AE0, termprog, 0LL);
fprintf(stderr, "9wm: exec %s", shell);
perror(" failed");
}
execlp("9term", "9term", "-9wm", 0LL);
execlp("xterm", "xterm", "-ut", 0LL);
perror("9wm: exec 9term/xterm failed");
exit(0);
}
return result;
}

original_code:
void spawn(ScreenInfo *s)
{
    ;
    if (fork() == 0) {
        close(xcb_get_file_descriptor(dpy));
        if (s->display[0] != '\0')
            putenv(s->display);
        if (termprog != ((void *)0)) {
            execl(shell, shell, "-c", termprog, 0);
            fprintf(stderr, "9wm: exec %s", shell);
            perror(" failed");
        }
        execlp("9term", "9term", "-9wm", 0);
        execlp("xterm", "xterm", "-ut", 0);
        perror("9wm: exec 9term/xterm failed");
        exit(0);
    }
}

canonical_original_code:
void spawn(struct ScreenInfo *s)
{
    ;
    if (fork() == 0) {
        close(xcb_get_file_descriptor(dpy));
        if (s->display[0] != '\0')
            putenv(s->display);
        if (termprog != ((void *)0)) {
            execl(shell, shell, "-c", termprog, 0);
            fprintf(stderr, "9wm: exec %s", shell);
            perror(" failed");
        }
        execlp("9term", "9term", "-9wm", 0);
        execlp("xterm", "xterm", "-ut", 0);
        perror("9wm: exec 9term/xterm failed");
        exit(0);
    }
}

variable_types: struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; } *


reshape

decompiled_code:
void __fastcall reshape(unsigned int *a1)
{
unsigned int v1; // ebx
unsigned int v2; // er12
__int64 v3; // r8
__int64 v4; // r9

if ( a1 )
{
v1 = a1[10];
v2 = a1[11];
if ( (unsigned int)sweep() )
{
active(a1);
top(a1);
xraisewindow(dpy, a1[1]);
xmoveresizewindow(
dpy,
a1[1],
a1[8] - (unsigned int)border,
a1[9] - (unsigned int)border,
a1[10] + 2 * (_DWORD)border - 2,
2 * (_DWORD)border - 2 + a1[11]);
v3 = a1[10];
v4 = a1[11];
if ( __PAIR64__(v4, v3) == __PAIR64__(v2, v1) )
sendconfig(a1);
else
xmoveresizewindow(dpy, *a1, (unsigned int)((_DWORD)border - 1), (unsigned int)((_DWORD)border - 1), v3, v4);
}
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int *a1)
{
unsigned int v1; // ebx
unsigned int v2; // er12
__int64 v3; // r8
__int64 v4; // r9

if ( a1 )
{
v1 = a1[10];
v2 = a1[11];
if ( (unsigned int)sweep() )
{
active(a1);
top(a1);
xraisewindow(dpy, a1[1]);
xmoveresizewindow(
dpy,
a1[1],
a1[8] - (unsigned int)border,
a1[9] - (unsigned int)border,
a1[10] + 2 * (_DWORD)border - 2,
2 * (_DWORD)border - 2 + a1[11]);
v3 = a1[10];
v4 = a1[11];
if ( __PAIR64__(v4, v3) == __PAIR64__(v2, v1) )
sendconfig(a1);
else
xmoveresizewindow(dpy, *a1, (unsigned int)((_DWORD)border - 1), (unsigned int)((_DWORD)border - 1), v3, v4);
}
}
}

original_code:
void reshape(Client *c)
{
    int odx, ody;
    uint32_t values[2];
    if (c == 0)
        return;
    odx = c->dx;
    ody = c->dy;
    if (sweep(c) == 0)
        return;
    active(c);
    top(c);
    xraisewindow(dpy, c->parent);
    xmoveresizewindow(dpy, c->parent, c->x-_border, c->y-_border,
                    c->dx+2*(_border-1), c->dy+2*(_border-1));
    if (c->dx == odx && c->dy == ody)
        sendconfig(c);
    else
        xmoveresizewindow(dpy, c->window, _border-1, _border-1, c->dx, c->dy);
}

canonical_original_code:
void reshape(struct Client *c)
{
    int odx; int ody;
    unsigned int values[2];
    if (c == 0)
        return;
    odx = c->dx;
    ody = c->dy;
    if (sweep(c) == 0)
        return;
    active(c);
    top(c);
    xraisewindow(dpy, c->parent);
    xmoveresizewindow(dpy, c->parent, c->x-_border, c->y-_border,
                    c->dx+2*(_border-1), c->dy+2*(_border-1));
    if (c->dx == odx && c->dy == ody)
        sendconfig(c);
    else
        xmoveresizewindow(dpy, c->window, _border-1, _border-1, c->dx, c->dy);
}

variable_types: struct Client { unsigned int window; unsigned int parent; unsigned int trans; struct Client *next; struct Client *revert; int x; int y; int dx; int dy; int border; struct xcb_size_hints_t { unsigned int flags; int x; int width; int min_width; int max_width; int width_inc; int min_aspect_num; int max_aspect_num; int base_width; unsigned int win_gravity; } size; int min_dx; int min_dy; int state; int init; int reparenting; int is9term; int hold; int proto; char *label; char *instance; char *class; char *name; char *iconname; unsigned int cmap; int ncmapwins; unsigned int *cmapwins; unsigned int *wmcmaps; struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; } *screen; } *

variable_types: odx int

variable_types: ody int

variable_types:
values
unsigned int [2]

user_defined_types: struct Client { unsigned int window; unsigned int parent; unsigned int trans; struct Client *next; struct Client *revert; int x; int y; int dx; int dy; int border; struct xcb_size_hints_t size; int min_dx; int min_dy; int state; int init; int reparenting; int is9term; int hold; int proto; char *label; char *instance; char *class; char *name; char *iconname; unsigned int cmap; int ncmapwins; unsigned int *cmapwins; unsigned int *wmcmaps; struct ScreenInfo *screen; }


move

decompiled_code:
void __fastcall move(unsigned int *a1)
{
if ( a1 )
{
if ( (unsigned int)drag() )
{
active(a1);
top(a1);
xraisewindow(dpy, a1[1]);
xmovewindow(dpy, a1[1], a1[8] - (unsigned int)border, a1[9] - (unsigned int)border);
sendconfig(a1);
}
}
}

canonical_decompiled_code:
void __fastcall func2(unsigned int *a1)
{
if ( a1 )
{
if ( (unsigned int)drag() )
{
active(a1);
top(a1);
xraisewindow(dpy, a1[1]);
xmovewindow(dpy, a1[1], a1[8] - (unsigned int)border, a1[9] - (unsigned int)border);
sendconfig(a1);
}
}
}

original_code:
void move(Client *c)
{
    uint32_t values[2];
    if (c == 0)
        return;
    if (drag(c) == 0)
        return;
    active(c);
    top(c);
    xraisewindow(dpy, c->parent);
    xmovewindow(dpy, c->parent, c->x - _border, c->y - _border);
    sendconfig(c);
}

canonical_original_code:
void move(struct Client *c)
{
    unsigned int values[2];
    if (c == 0)
        return;
    if (drag(c) == 0)
        return;
    active(c);
    top(c);
    xraisewindow(dpy, c->parent);
    xmovewindow(dpy, c->parent, c->x - _border, c->y - _border);
    sendconfig(c);
}

user_defined_types: struct xcb_size_hints_t { unsigned int flags; int x; int width; int min_width; int max_width; int width_inc; int min_aspect_num; int max_aspect_num; int base_width; unsigned int win_gravity; }

user_defined_types: struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; }


delete

decompiled_code:
xcb_void_cookie_t __fastcall delete(__int64 a1, int a2)
{
uint32_t v2; // er8
xcb_void_cookie_t result; // eax

if ( a1 )
{
v2 = *(_DWORD *)a1;
if ( !a2 && (*(_BYTE *)(a1 + 152) & 1) != 0 )
result.sequence = sendcmessage(v2, wm_protocols, wm_delete, 0LL);
else
result.sequence = xcb_kill_client(dpy, v2).sequence;
}
return result;
}

canonical_decompiled_code:
xcb_void_cookie_t __fastcall func3(__int64 a1, int a2)
{
uint32_t v2; // er8
xcb_void_cookie_t result; // eax

if ( a1 )
{
v2 = *(_DWORD *)a1;
if ( !a2 && (*(_BYTE *)(a1 + 152) & 1) != 0 )
result.sequence = sendcmessage(v2, wm_protocols, wm_delete, 0LL);
else
result.sequence = xcb_kill_client(dpy, v2).sequence;
}
return result;
}

original_code:
void delete(Client *c, int shift)
{
    if (c == 0)
        return;
    if ((c->proto & 1) && !shift)
        sendcmessage(c->window, wm_protocols, wm_delete, 0);
    else
        xcb_kill_client(dpy, c->window);
}

canonical_original_code:
void delete(struct Client *c, int shift)
{
    if (c == 0)
        return;
    if ((c->proto & 1) && !shift)
        sendcmessage(c->window, wm_protocols, wm_delete, 0);
    else
        xcb_kill_client(dpy, c->window);
}

variable_types: shift int


hide

decompiled_code:
int __fastcall hide(__int64 a1)
{
int v1; // edx
char *v2; // rcx
int v3; // eax
int v4; // edx
__int64 v5; // rax

if ( a1 && numhidden != 32 )
{
if ( *(_DWORD *)(a1 + 132) == 3 )
{
LODWORD(v5) = fprintf(stderr, "9wm: already hidden: %s\n", *(const char **)(a1 + 160));
}
else
{
xcb_unmap_window(dpy, *(_DWORD *)(a1 + 4));
xcb_unmap_window(dpy, *(_DWORD *)a1);
set_state(a1, 3LL);
if ( current == a1 )
nofocus();
v1 = numhidden;
v2 = *(char **)(a1 + 160);
v3 = numhidden;
hiddenc[numhidden] = a1;
b3items[v1 + 5] = v2;
v4 = v3 + 1;
v5 = v3 + 6;
numhidden = v4;
b3items[v5] = 0LL;
}
}
return v5;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
int v1; // edx
char *v2; // rcx
int v3; // eax
int v4; // edx
__int64 v5; // rax

if ( a1 && numhidden != 32 )
{
if ( *(_DWORD *)(a1 + 132) == 3 )
{
LODWORD(v5) = fprintf(stderr, "9wm: already hidden: %s\n", *(const char **)(a1 + 160));
}
else
{
xcb_unmap_window(dpy, *(_DWORD *)(a1 + 4));
xcb_unmap_window(dpy, *(_DWORD *)a1);
set_state(a1, 3LL);
if ( current == a1 )
nofocus();
v1 = numhidden;
v2 = *(char **)(a1 + 160);
v3 = numhidden;
hiddenc[numhidden] = a1;
b3items[v1 + 5] = v2;
v4 = v3 + 1;
v5 = v3 + 6;
numhidden = v4;
b3items[v5] = 0LL;
}
}
return v5;
}

original_code:
void hide(Client *c)
{
    if (c == 0 || numhidden == 32)
        return;
    if (((c)->state == XCB_ICCCM_WM_STATE_ICONIC)) {
        fprintf(stderr, "9wm: already hidden: %s\n", c->label);
        return;
    }
    xcb_unmap_window(dpy, c->parent);
    xcb_unmap_window(dpy, c->window);
    set_state(c, XCB_ICCCM_WM_STATE_ICONIC);
    if (c == current)
        nofocus();
    hiddenc[numhidden] = c;
    b3items[5 +numhidden] = c->label;
    numhidden++;
    b3items[5 +numhidden] = 0;
}

canonical_original_code:
void hide(struct Client *c)
{
    if (c == 0 || numhidden == 32)
        return;
    if (((c)->state == XCB_ICCCM_WM_STATE_ICONIC)) {
        fprintf(stderr, "9wm: already hidden: %s\n", c->label);
        return;
    }
    xcb_unmap_window(dpy, c->parent);
    xcb_unmap_window(dpy, c->window);
    set_state(c, XCB_ICCCM_WM_STATE_ICONIC);
    if (c == current)
        nofocus();
    hiddenc[numhidden] = c;
    b3items[5 +numhidden] = c->label;
    numhidden++;
    b3items[5 +numhidden] = 0;
}


unhide

decompiled_code:
int __fastcall unhide(int a1, int a2)
{
int v2; // er12
unsigned int *v3; // rbp
int result; // eax
__int64 v5; // rbx

v2 = numhidden;
if ( numhidden <= a1 )
return fprintf(stderr, "9wm: unhide: n %d numhidden %d\n", (unsigned int)a1, (unsigned int)numhidden);
v3 = (unsigned int *)hiddenc[a1];
if ( v3[33] == 3 )
{
if ( a2 )
{
xcb_map_window(dpy, *v3);
xmapraised(dpy, v3[1]);
set_state(v3, 1LL);
active(v3);
top(v3);
v2 = numhidden;
result = numhidden - 1;
numhidden = result;
if ( result <= a1 )
goto LABEL_6;
}
else
{
result = --numhidden;
if ( v2 - 1 <= a1 )
{
LABEL_6:
b3items[v2 + 4] = 0LL;
return result;
}
}
v5 = a1;
memmove(&hiddenc[v5], &hiddenc[v5 + 1], 8LL * (unsigned int)(v2 - a1 - 2) + 8);
result = (unsigned int)memmove(&b3items[v5 + 5], &b3items[v5 + 6], 8LL * (unsigned int)(v2 - a1 - 2) + 8);
goto LABEL_6;
}
return fprintf(stderr, "9wm: unhide: not hidden: %s(0x%x)\n", *((const char **)v3 + 20), *v3);
}

canonical_decompiled_code:
int __fastcall func5(int a1, int a2)
{
int v2; // er12
unsigned int *v3; // rbp
int result; // eax
__int64 v5; // rbx

v2 = numhidden;
if ( numhidden <= a1 )
return fprintf(stderr, "9wm: unhide: n %d numhidden %d\n", (unsigned int)a1, (unsigned int)numhidden);
v3 = (unsigned int *)hiddenc[a1];
if ( v3[33] == 3 )
{
if ( a2 )
{
xcb_map_window(dpy, *v3);
xmapraised(dpy, v3[1]);
set_state(v3, 1LL);
active(v3);
top(v3);
v2 = numhidden;
result = numhidden - 1;
numhidden = result;
if ( result <= a1 )
goto LABEL_6;
}
else
{
result = --numhidden;
if ( v2 - 1 <= a1 )
{
LABEL_6:
b3items[v2 + 4] = 0LL;
return result;
}
}
v5 = a1;
memmove(&hiddenc[v5], &hiddenc[v5 + 1], 8LL * (unsigned int)(v2 - a1 - 2) + 8);
result = (unsigned int)memmove(&b3items[v5 + 5], &b3items[v5 + 6], 8LL * (unsigned int)(v2 - a1 - 2) + 8);
goto LABEL_6;
}
return fprintf(stderr, "9wm: unhide: not hidden: %s(0x%x)\n", *((const char **)v3 + 20), *v3);
}

original_code:
void unhide(int n, int map)
{
    Client *c;
    int i;
    uint32_t values[2];
    if (n >= numhidden) {
        fprintf(stderr, "9wm: unhide: n %d numhidden %d\n", n, numhidden);
        return;
    }
    c = hiddenc[n];
    if (!((c)->state == XCB_ICCCM_WM_STATE_ICONIC)) {
        fprintf(stderr, "9wm: unhide: not hidden: %s(0x%x)\n",
            c->label, c->window);
        return;
    }
    if (map) {
        xcb_map_window(dpy, c->window);
        xmapraised(dpy, c->parent);
        set_state(c, XCB_ICCCM_WM_STATE_NORMAL);
        active(c);
        top(c);
    }
    numhidden--;
    for (i = n; i < numhidden; i ++) {
        hiddenc[i] = hiddenc[i+1];
        b3items[5 +i] = b3items[5 +i+1];
    }
    b3items[5 +numhidden] = 0;
}

canonical_original_code:
void unhide(int n, int map)
{
    struct Client *c;
    int i;
    unsigned int values[2];
    if (n >= numhidden) {
        fprintf(stderr, "9wm: unhide: n %d numhidden %d\n", n, numhidden);
        return;
    }
    c = hiddenc[n];
    if (!((c)->state == XCB_ICCCM_WM_STATE_ICONIC)) {
        fprintf(stderr, "9wm: unhide: not hidden: %s(0x%x)\n",
            c->label, c->window);
        return;
    }
    if (map) {
        xcb_map_window(dpy, c->window);
        xmapraised(dpy, c->parent);
        set_state(c, XCB_ICCCM_WM_STATE_NORMAL);
        active(c);
        top(c);
    }
    numhidden--;
    for (i = n; i < numhidden; i ++) {
        hiddenc[i] = hiddenc[i+1];
        b3items[5 +i] = b3items[5 +i+1];
    }
    b3items[5 +numhidden] = 0;
}

variable_types: n int

variable_types: map int

variable_types: i int


button

decompiled_code:
void __fastcall button(__int64 a1)
{
int v2; // eax
__int64 v3; // rdi
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // r12
__int16 v7; // dx
char v8; // al
xcb_window_t v9; // esi
char v10; // al
int v11; // edi
xcb_translate_coordinates_cookie_t v12; // eax
xcb_translate_coordinates_reply_t *v13; // rax
__int64 v14; // rax
unsigned int *v15; // rax
unsigned int *v16; // rax
__int64 v17; // rax
int v18[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = *(_DWORD *)(a1 + 4);
v3 = *(unsigned int *)(a1 + 8);
curtime = v2;
v4 = getscreen(v3);
if ( !v4 )
{
fwrite("button: getscreen failed\n", 1uLL, 0x19uLL, stderr);
fprintf(
stderr,
" e->root=%d e->event=%d e->child=%d e->detail=%d\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 16),
*(unsigned __int8 *)(a1 + 1));
return;
}
v5 = v4;
v6 = getclient(*(unsigned int *)(a1 + 12), 0LL);
if ( v6 )
{
v7 = 1 - (_WORD)border + *(_WORD *)(v6 + 32);
*(_WORD *)(a1 + 26) += *(_WORD *)(v6 + 36) + 1 - (_WORD)border;
v8 = *(_BYTE *)(a1 + 1);
*(_WORD *)(a1 + 24) += v7;
if ( v8 != 2 )
{
if ( v8 != 3 )
{
if ( v8 == 1 )
{
xmapraised(dpy, *(unsigned int *)(v6 + 4));
top(v6);
active(v6);
}
return;
}
goto LABEL_10;
}
}
else
{
v9 = *(_DWORD *)(a1 + 12);
if ( v9 != *(_DWORD *)(a1 + 8) )
{
v12.sequence = xcb_translate_coordinates(dpy, v9, *(_DWORD *)(v5 + 4), *(_WORD *)(a1 + 24), *(_WORD *)(a1 + 26)).sequence;
v13 = xcb_translate_coordinates_reply(dpy, v12, 0LL);
if ( v13 )
{
*(_WORD *)(a1 + 24) = v13->dst_x;
*(_WORD *)(a1 + 26) = v13->dst_y;
free(v13);
}
else
{
fwrite("9wm: button: failed to translate coords\n", 1uLL, 0x28uLL, stderr);
fprintf(
stderr,
" window=%d root=%d child=%d\n",
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 16));
}
}
v10 = *(_BYTE *)(a1 + 1);
if ( v10 != 2 )
{
if ( v10 != 3 )
return;
LABEL_10:
if ( current && *(_QWORD *)(current + 224LL) == v5 )
cmapnofocus(v5);
v11 = menuhit(a1, &b3menu);
switch ( v11 )
{
case -1:
break;
case 0:
spawn(v5);
break;
case 1:
v15 = (unsigned int *)selectwin(1LL, 0LL, v5);
reshape(v15);
break;
case 2:
v16 = (unsigned int *)selectwin(0LL, 0LL, v5);
move(v16);
break;
case 3:
v18[0] = 0;
v17 = selectwin(1LL, v18, v5);
delete(v17, v18[0]);
break;
case 4:
v14 = selectwin(1LL, 0LL, v5);
hide(v14);
break;
default:
unhide(v11 - 5, 1);
break;
}
if ( current && *(_QWORD *)(current + 224LL) == v5 )
cmapfocus();
return;
}
}
if ( (*(_WORD *)(a1 + 28) & 5) == 5 )
menuhit(a1, &egg);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
int v2; // eax
__int64 v3; // rdi
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // r12
__int16 v7; // dx
char v8; // al
xcb_window_t v9; // esi
char v10; // al
int v11; // edi
xcb_translate_coordinates_cookie_t v12; // eax
xcb_translate_coordinates_reply_t *v13; // rax
__int64 v14; // rax
unsigned int *v15; // rax
unsigned int *v16; // rax
__int64 v17; // rax
int v18[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = *(_DWORD *)(a1 + 4);
v3 = *(unsigned int *)(a1 + 8);
curtime = v2;
v4 = getscreen(v3);
if ( !v4 )
{
fwrite("button: getscreen failed\n", 1uLL, 0x19uLL, stderr);
fprintf(
stderr,
" e->root=%d e->event=%d e->child=%d e->detail=%d\n",
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 16),
*(unsigned __int8 *)(a1 + 1));
return;
}
v5 = v4;
v6 = getclient(*(unsigned int *)(a1 + 12), 0LL);
if ( v6 )
{
v7 = 1 - (_WORD)border + *(_WORD *)(v6 + 32);
*(_WORD *)(a1 + 26) += *(_WORD *)(v6 + 36) + 1 - (_WORD)border;
v8 = *(_BYTE *)(a1 + 1);
*(_WORD *)(a1 + 24) += v7;
if ( v8 != 2 )
{
if ( v8 != 3 )
{
if ( v8 == 1 )
{
xmapraised(dpy, *(unsigned int *)(v6 + 4));
top(v6);
active(v6);
}
return;
}
goto LABEL_10;
}
}
else
{
v9 = *(_DWORD *)(a1 + 12);
if ( v9 != *(_DWORD *)(a1 + 8) )
{
v12.sequence = xcb_translate_coordinates(dpy, v9, *(_DWORD *)(v5 + 4), *(_WORD *)(a1 + 24), *(_WORD *)(a1 + 26)).sequence;
v13 = xcb_translate_coordinates_reply(dpy, v12, 0LL);
if ( v13 )
{
*(_WORD *)(a1 + 24) = v13->dst_x;
*(_WORD *)(a1 + 26) = v13->dst_y;
free(v13);
}
else
{
fwrite("9wm: button: failed to translate coords\n", 1uLL, 0x28uLL, stderr);
fprintf(
stderr,
" window=%d root=%d child=%d\n",
*(unsigned int *)(a1 + 12),
*(unsigned int *)(a1 + 8),
*(unsigned int *)(a1 + 16));
}
}
v10 = *(_BYTE *)(a1 + 1);
if ( v10 != 2 )
{
if ( v10 != 3 )
return;
LABEL_10:
if ( current && *(_QWORD *)(current + 224LL) == v5 )
cmapnofocus(v5);
v11 = menuhit(a1, &b3menu);
switch ( v11 )
{
case -1:
break;
case 0:
func0(v5);
break;
case 1:
v15 = (unsigned int *)selectwin(1LL, 0LL, v5);
func1(v15);
break;
case 2:
v16 = (unsigned int *)selectwin(0LL, 0LL, v5);
func2(v16);
break;
case 3:
v18[0] = 0;
v17 = selectwin(1LL, v18, v5);
func3(v17, v18[0]);
break;
case 4:
v14 = selectwin(1LL, 0LL, v5);
func4(v14);
break;
default:
func5(v11 - 5, 1);
break;
}
if ( current && *(_QWORD *)(current + 224LL) == v5 )
cmapfocus();
return;
}
}
if ( (*(_WORD *)(a1 + 28) & 5) == 5 )
menuhit(a1, &egg);
}

original_code:
void button(xcb_button_press_event_t *e)
{
    int n, shift;
    Client *c;
    xcb_window_t dw;
    ScreenInfo *s;
    uint32_t values[2];
    curtime = e->time;
    if (!(s = getscreen(e->root))) {
        fprintf(stderr, "button: getscreen failed\n");
        fprintf(stderr, " e->root=%d e->event=%d e->child=%d e->detail=%d\n",
                e->root, e->event, e->child, e->detail);
        return;
    }
    if (c = getclient(e->event, 0)) {
        e->event_x += c->x - _border + 1;
        e->event_y += c->y - _border + 1;
    }
    else if (e->event != e->root) {
        xcb_translate_coordinates_cookie_t xtrans_c;
        xcb_translate_coordinates_reply_t *xtrans_r;
        xtrans_c = xcb_translate_coordinates(dpy, e->event, s->root,
                                                            e->event_x, e->event_y);
        xtrans_r = xcb_translate_coordinates_reply(dpy, xtrans_c, ((void *)0));
        if (xtrans_r) {
            e->event_x = xtrans_r->dst_x;
            e->event_y = xtrans_r->dst_y;
            free(xtrans_r);
        }
        else {
            fprintf(stderr, "9wm: button: failed to translate coords\n");
            fprintf(stderr, " window=%d root=%d child=%d\n",
                        e->event, e->root, e->child);
        }
    }
    switch (e->detail) {
        case XCB_BUTTON_INDEX_1:
            if (c) {
                xmapraised(dpy, c->parent);
                top(c);
                active(c);
            }
            return;
        case XCB_BUTTON_INDEX_2:
            if ((e->state & (XCB_MOD_MASK_SHIFT|XCB_MOD_MASK_CONTROL)) ==
                    (XCB_MOD_MASK_SHIFT | XCB_MOD_MASK_CONTROL))
                menuhit(e, &egg);
            return;
        case XCB_BUTTON_INDEX_3:
            break;
        default:
            return;
    }
    if (current && current->screen == s)
        cmapnofocus(s);
    switch (n = menuhit(e, &b3menu)) {
        case 0:
            spawn(s);
            break;
        case 1:
            reshape(selectwin(1, 0, s));
            break;
        case 2:
            move(selectwin(0, 0, s));
            break;
        case 3:
            shift = 0;
            c = selectwin(1, &shift, s);
            delete(c, shift);
            break;
        case 4:
            hide(selectwin(1, 0, s));
            break;
        default:
            unhide(n - 5, 1);
            break;
        case -1:
            break;
    }
    if (current && current->screen == s)
        cmapfocus(current);
}

canonical_original_code:
void button(struct xcb_button_press_event_t *e)
{
    int n; int shift;
    struct Client *c;
    unsigned int dw;
    struct ScreenInfo *s;
    unsigned int values[2];
    curtime = e->time;
    if (!(s = getscreen(e->root))) {
        fprintf(stderr, "button: getscreen failed\n");
        fprintf(stderr, " e->root=%d e->event=%d e->child=%d e->detail=%d\n",
                e->root, e->event, e->child, e->detail);
        return;
    }
    if (c = getclient(e->event, 0)) {
        e->event_x += c->x - _border + 1;
        e->event_y += c->y - _border + 1;
    }
    else if (e->event != e->root) {
        struct xcb_translate_coordinates_cookie_t xtrans_c;
        struct xcb_translate_coordinates_reply_t *xtrans_r;
        xtrans_c = xcb_translate_coordinates(dpy, e->event, s->root,
                                                            e->event_x, e->event_y);
        xtrans_r = xcb_translate_coordinates_reply(dpy, xtrans_c, ((void *)0));
        if (xtrans_r) {
            e->event_x = xtrans_r->dst_x;
            e->event_y = xtrans_r->dst_y;
            free(xtrans_r);
        }
        else {
            fprintf(stderr, "9wm: button: failed to translate coords\n");
            fprintf(stderr, " window=%d root=%d child=%d\n",
                        e->event, e->root, e->child);
        }
    }
    switch (e->detail) {
        case XCB_BUTTON_INDEX_1:
            if (c) {
                xmapraised(dpy, c->parent);
                top(c);
                active(c);
            }
            return;
        case XCB_BUTTON_INDEX_2:
            if ((e->state & (XCB_MOD_MASK_SHIFT|XCB_MOD_MASK_CONTROL)) ==
                    (XCB_MOD_MASK_SHIFT | XCB_MOD_MASK_CONTROL))
                menuhit(e, &egg);
            return;
        case XCB_BUTTON_INDEX_3:
            break;
        default:
            return;
    }
    if (current && current->screen == s)
        cmapnofocus(s);
    switch (n = menuhit(e, &b3menu)) {
        case 0:
            spawn(s);
            break;
        case 1:
            reshape(selectwin(1, 0, s));
            break;
        case 2:
            move(selectwin(0, 0, s));
            break;
        case 3:
            shift = 0;
            c = selectwin(1, &shift, s);
            delete(c, shift);
            break;
        case 4:
            hide(selectwin(1, 0, s));
            break;
        default:
            unhide(n - 5, 1);
            break;
        case -1:
            break;
    }
    if (current && current->screen == s)
        cmapfocus(current);
}

variable_types: struct xcb_button_press_event_t { unsigned char response_type; unsigned char detail; unsigned short sequence; unsigned int time; unsigned int root; unsigned int event; unsigned int child; short root_x; short root_y; short event_x; short event_y; unsigned short state; unsigned char same_screen; unsigned char pad0; } *

variable_types:
dw
unsigned int

variable_types: struct xcb_translate_coordinates_cookie_t { unsigned int sequence; }

variable_types: struct xcb_translate_coordinates_reply_t { unsigned char response_type; unsigned char same_screen; unsigned short sequence; unsigned int length; unsigned int child; short dst_x; short dst_y; } *


unhidec

decompiled_code:
int __fastcall unhidec(unsigned int *a1, int a2)
{
__int64 v3; // rdi

if ( numhidden <= 0 )
return fprintf(stderr, "9wm: unhidec: not hidden: %s(0x%x)\n", *((const char **)a1 + 20), *a1);
v3 = 0LL;
while ( (unsigned int *)hiddenc[v3] != a1 )
{
if ( ++v3 == numhidden )
return fprintf(stderr, "9wm: unhidec: not hidden: %s(0x%x)\n", *((const char **)a1 + 20), *a1);
}
return unhide(v3, a2);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, int a2)
{
__int64 v3; // rdi

if ( numhidden <= 0 )
return fprintf(stderr, "9wm: unhidec: not hidden: %s(0x%x)\n", *((const char **)a1 + 20), *a1);
v3 = 0LL;
while ( (unsigned int *)hiddenc[v3] != a1 )
{
if ( ++v3 == numhidden )
return fprintf(stderr, "9wm: unhidec: not hidden: %s(0x%x)\n", *((const char **)a1 + 20), *a1);
}
return func5(v3, a2);
}

original_code:
void unhidec(Client *c, int map)
{
    int i;
    for (i = 0; i < numhidden; i++)
        if (c == hiddenc[i]) {
            unhide(i, map);
            return;
        }
    fprintf(stderr, "9wm: unhidec: not hidden: %s(0x%x)\n",
        c->label, c->window);
}

canonical_original_code:
void unhidec(struct Client *c, int map)
{
    int i;
    for (i = 0; i < numhidden; i++)
        if (c == hiddenc[i]) {
            unhide(i, map);
            return;
        }
    fprintf(stderr, "9wm: unhidec: not hidden: %s(0x%x)\n",
        c->label, c->window);
}


renamec

decompiled_code:
const char *__fastcall renamec(__int64 a1, char *a2)
{
const char *result; // rax
bool v3; // zf

result = "???";
if ( !a2 )
a2 = "???";
v3 = *(_DWORD *)(a1 + 132) == 3;
*(_QWORD *)(a1 + 160) = a2;
if ( v3 && numhidden > 0 )
{
result = 0LL;
while ( hiddenc[(_QWORD)result] != a1 )
{
if ( ++result == (const char *)numhidden )
return result;
}
b3items[(int)result + 5] = a2;
}
return result;
}

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

result = "???";
if ( !a2 )
a2 = "???";
v3 = *(_DWORD *)(a1 + 132) == 3;
*(_QWORD *)(a1 + 160) = a2;
if ( v3 && numhidden > 0 )
{
result = 0LL;
while ( hiddenc[(_QWORD)result] != a1 )
{
if ( ++result == (const char *)numhidden )
return result;
}
b3items[(int)result + 5] = a2;
}
return result;
}

original_code:
void renamec(Client *c, char *name)
{
    int i;
    if (name == 0)
        name = "???";
    c->label = name;
    if (!((c)->state == XCB_ICCCM_WM_STATE_ICONIC))
        return;
    for (i = 0; i < numhidden; i++)
        if (c == hiddenc[i]) {
            b3items[5 +i] = name;
            return;
        }
}

canonical_original_code:
void renamec(struct Client *c, char *name)
{
    int i;
    if (name == 0)
        name = "???";
    c->label = name;
    if (!((c)->state == XCB_ICCCM_WM_STATE_ICONIC))
        return;
    for (i = 0; i < numhidden; i++)
        if (c == hiddenc[i]) {
            b3items[5 +i] = name;
            return;
        }
}

variable_types:
name
char *


decompiled_code:
void __fastcall draw_border(__int64 a1, int a2)
{
__int64 v2; // rax
xcb_window_t v3; // er8
xcb_drawable_t v4; // esi
uint16_t v5; // dx
__int64 v6; // rax
uint32_t value_list; // [rsp+0h] [rbp-14h] BYREF
xcb_rectangle_t rectangles; // [rsp+4h] [rbp-10h] BYREF

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 224);
v3 = *(_DWORD *)(a1 + 4);
if ( a2 )
{
value_list = *(_DWORD *)(v2 + 20);
xcb_change_window_attributes(dpy, v3, 2u, &value_list);
xcb_clear_area(dpy, 0, *(_DWORD *)(a1 + 4), 0, 0, 0, 0);
if ( *(_DWORD *)(a1 + 148) )
{
v4 = *(_DWORD *)(a1 + 4);
rectangles.x = inset;
rectangles.y = inset;
v5 = (_WORD)border - inset + *(_WORD *)(a1 + 40);
rectangles.height = *(_WORD *)(a1 + 44) + (_WORD)border - inset;
v6 = *(_QWORD *)(a1 + 224);
rectangles.width = v5;
xcb_poly_rectangle(dpy, v4, *(_DWORD *)(v6 + 16), 1u, &rectangles);
}
}
else
{
value_list = *(_DWORD *)(v2 + 24);
xcb_change_window_attributes(dpy, v3, 2u, &value_list);
xcb_clear_area(dpy, 0, *(_DWORD *)(a1 + 4), 0, 0, 0, 0);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rax
xcb_window_t v3; // er8
xcb_drawable_t v4; // esi
uint16_t v5; // dx
__int64 v6; // rax
uint32_t value_list; // [rsp+0h] [rbp-14h] BYREF
xcb_rectangle_t rectangles; // [rsp+4h] [rbp-10h] BYREF

if ( a1 )
{
v2 = *(_QWORD *)(a1 + 224);
v3 = *(_DWORD *)(a1 + 4);
if ( a2 )
{
value_list = *(_DWORD *)(v2 + 20);
xcb_change_window_attributes(dpy, v3, 2u, &value_list);
xcb_clear_area(dpy, 0, *(_DWORD *)(a1 + 4), 0, 0, 0, 0);
if ( *(_DWORD *)(a1 + 148) )
{
v4 = *(_DWORD *)(a1 + 4);
rectangles.x = inset;
rectangles.y = inset;
v5 = (_WORD)border - inset + *(_WORD *)(a1 + 40);
rectangles.height = *(_WORD *)(a1 + 44) + (_WORD)border - inset;
v6 = *(_QWORD *)(a1 + 224);
rectangles.width = v5;
xcb_poly_rectangle(dpy, v4, *(_DWORD *)(v6 + 16), 1u, &rectangles);
}
}
else
{
value_list = *(_DWORD *)(v2 + 24);
xcb_change_window_attributes(dpy, v3, 2u, &value_list);
xcb_clear_area(dpy, 0, *(_DWORD *)(a1 + 4), 0, 0, 0, 0);
}
}
}

original_code:
void draw_border(Client *c, int active)
{
    xcb_rectangle_t rect;
    uint32_t value;
    if (!c) {
        ;
        return;
    }
    value = active ? c->screen->black : c->screen->white;
    xcb_change_window_attributes(dpy, c->parent, XCB_CW_BACK_PIXEL, &value);
    xcb_clear_area(dpy, 0, c->parent, 0, 0, 0, 0);
    if (c->hold && active) {
        rect.x = _inset;
        rect.y = _inset;
        rect.width = c->dx + _border - _inset;
        rect.height = c->dy + _border - _inset;
        xcb_poly_rectangle(dpy, c->parent, c->screen->gc, 1, &rect);
    }
}

canonical_original_code:
void draw_border(struct Client *c, int active)
{
    struct xcb_rectangle_t rect;
    unsigned int value;
    if (!c) {
        ;
        return;
    }
    value = active ? c->screen->black : c->screen->white;
    xcb_change_window_attributes(dpy, c->parent, XCB_CW_BACK_PIXEL, &value);
    xcb_clear_area(dpy, 0, c->parent, 0, 0, 0, 0);
    if (c->hold && active) {
        rect.x = _inset;
        rect.y = _inset;
        rect.width = c->dx + _border - _inset;
        rect.height = c->dy + _border - _inset;
        xcb_poly_rectangle(dpy, c->parent, c->screen->gc, 1, &rect);
    }
}

variable_types: active int

variable_types: struct xcb_rectangle_t { short x; short y; unsigned short width; unsigned short height; }

variable_types:
value
unsigned int


setactive

decompiled_code:
void __fastcall setactive(unsigned int *a1, int a2)
{
xcb_window_t v2; // edx
xcb_timestamp_t v3; // eax

if ( a1 )
{
v2 = a1[1];
if ( v2 == *(_DWORD *)(*((_QWORD *)a1 + 28) + 4LL) )
{
fwrite("9wm: bad parent in setactive; dumping core\n", 1uLL, 0x2BuLL, stderr);
abort();
}
if ( a2 )
{
xcb_ungrab_button(dpy, 0, v2, 0x8000u);
v3 = timestamp();
xcb_set_input_focus(dpy, 1u, *a1, v3);
if ( (a1[38] & 2) != 0 )
sendcmessage(*a1, wm_protocols, wm_take_focus, 0LL);
cmapfocus(a1);
}
else
{
xcb_grab_button(dpy, 0, v2, 0xCu, 1u, 0, 0, 0, 0, 0x8000u);
}
draw_border((__int64)a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int *a1, int a2)
{
xcb_window_t v2; // edx
xcb_timestamp_t v3; // eax

if ( a1 )
{
v2 = a1[1];
if ( v2 == *(_DWORD *)(*((_QWORD *)a1 + 28) + 4LL) )
{
fwrite("9wm: bad parent in setactive; dumping core\n", 1uLL, 0x2BuLL, stderr);
abort();
}
if ( a2 )
{
xcb_ungrab_button(dpy, 0, v2, 0x8000u);
v3 = timestamp();
xcb_set_input_focus(dpy, 1u, *a1, v3);
if ( (a1[38] & 2) != 0 )
sendcmessage(*a1, wm_protocols, wm_take_focus, 0LL);
cmapfocus(a1);
}
else
{
xcb_grab_button(dpy, 0, v2, 0xCu, 1u, 0, 0, 0, 0, 0x8000u);
}
func0((__int64)a1, a2);
}
}

original_code:
void setactive(Client *c, int on)
{
    if (!c) {
        ;
        return;
    }
    if (c->parent == c->screen->root) {
        fprintf(stderr, "9wm: bad parent in setactive; dumping core\n");
        abort();
    }
    if (on) {
        xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_ANY, c->parent,
                    XCB_BUTTON_MASK_ANY);
        xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT,
                    c->window, timestamp());
        if (c->proto & 2)
            sendcmessage(c->window, wm_protocols, wm_take_focus, 0);
        cmapfocus(c);
    }
    else {
        xcb_grab_button(dpy, 0, c->parent, (XCB_EVENT_MASK_BUTTON_PRESS |XCB_EVENT_MASK_BUTTON_RELEASE),
            XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC,
            0L, 0L, XCB_BUTTON_INDEX_ANY,
            XCB_MOD_MASK_ANY);
    }
    draw_border(c, on);
}

canonical_original_code:
void setactive(struct Client *c, int on)
{
    if (!c) {
        ;
        return;
    }
    if (c->parent == c->screen->root) {
        fprintf(stderr, "9wm: bad parent in setactive; dumping core\n");
        abort();
    }
    if (on) {
        xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_ANY, c->parent,
                    XCB_BUTTON_MASK_ANY);
        xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT,
                    c->window, timestamp());
        if (c->proto & 2)
            sendcmessage(c->window, wm_protocols, wm_take_focus, 0);
        cmapfocus(c);
    }
    else {
        xcb_grab_button(dpy, 0, c->parent, (XCB_EVENT_MASK_BUTTON_PRESS |XCB_EVENT_MASK_BUTTON_RELEASE),
            XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC,
            0L, 0L, XCB_BUTTON_INDEX_ANY,
            XCB_MOD_MASK_ANY);
    }
    draw_border(c, on);
}

variable_types: on int


active

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

if ( a1 && current != a1 )
{
if ( current )
{
setactive((unsigned int *)current, 0);
if ( *(_QWORD *)(current + 224) != *(_QWORD *)(a1 + 224) )
cmapnofocus();
}
setactive((unsigned int *)a1, 1);
for ( i = clients; i; i = *(_QWORD *)(i + 16) )
{
while ( *(_QWORD *)(i + 24) != a1 )
{
i = *(_QWORD *)(i + 16);
if ( !i )
goto LABEL_11;
}
*(_QWORD *)(i + 24) = *(_QWORD *)(a1 + 24);
}
LABEL_11:
v2 = current;
for ( *(_QWORD *)(a1 + 24) = current; v2; *(_QWORD *)(a1 + 24) = v2 )
{
if ( *(_DWORD *)(v2 + 132) == 1 )
break;
v2 = *(_QWORD *)(v2 + 24);
}
current = a1;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
__int64 i; // rax
__int64 v2; // rax

if ( a1 && current != a1 )
{
if ( current )
{
func1((unsigned int *)current, 0);
if ( *(_QWORD *)(current + 224) != *(_QWORD *)(a1 + 224) )
cmapnofocus();
}
func1((unsigned int *)a1, 1);
for ( i = clients; i; i = *(_QWORD *)(i + 16) )
{
while ( *(_QWORD *)(i + 24) != a1 )
{
i = *(_QWORD *)(i + 16);
if ( !i )
goto LABEL_11;
}
*(_QWORD *)(i + 24) = *(_QWORD *)(a1 + 24);
}
LABEL_11:
v2 = current;
for ( *(_QWORD *)(a1 + 24) = current; v2; *(_QWORD *)(a1 + 24) = v2 )
{
if ( *(_DWORD *)(v2 + 132) == 1 )
break;
v2 = *(_QWORD *)(v2 + 24);
}
current = a1;
}
}

original_code:
void active(Client *c)
{
    Client *cc;
    if (!c) {
        ;
        return;
    }
    if (c == current)
        return;
    if (current) {
        setactive(current, 0);
        if (current->screen != c->screen)
            cmapnofocus(current->screen);
    }
    setactive(c, 1);
    for (cc = clients; cc; cc = cc->next)
        if (cc->revert == c)
            cc->revert = c->revert;
    c->revert = current;
    while (c->revert && !((c->revert)->state == XCB_ICCCM_WM_STATE_NORMAL))
        c->revert = c->revert->revert;
    current = c;
}

canonical_original_code:
void active(struct Client *c)
{
    struct Client *cc;
    if (!c) {
        ;
        return;
    }
    if (c == current)
        return;
    if (current) {
        setactive(current, 0);
        if (current->screen != c->screen)
            cmapnofocus(current->screen);
    }
    setactive(c, 1);
    for (cc = clients; cc; cc = cc->next)
        if (cc->revert == c)
            cc->revert = c->revert;
    c->revert = current;
    while (c->revert && !((c->revert)->state == XCB_ICCCM_WM_STATE_NORMAL))
        c->revert = c->revert->revert;
    current = c;
}

variable_types: struct Client { unsigned int window; unsigned int parent; unsigned int trans; struct Client *next; struct Client *revert; int x; int y; int dx; int dy; int border; struct xcb_size_hints_t { unsigned int flags; int x; int width; int min_width; int max_width; int width_inc; int min_aspect_num; int max_aspect_num; int base_width; unsigned int win_gravity; } size; int min_dx; int min_dy; int state; int init; int reparenting; int is9term; int hold; int proto; char *label; char *instance; char *class; char *name; char *iconname; unsigned int cmap; int ncmapwins; unsigned int *cmapwins; unsigned int *wmcmaps; struct ScreenInfo { int num; unsigned int root; unsigned int menuwin; unsigned int def_cmap; unsigned int gc; unsigned int black; unsigned int white; int min_cmaps; unsigned int target; unsigned int sweep0; unsigned int boxcurs; unsigned int arrow; unsigned int root_pixmap; char display[256]; } *screen; } *