main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
unsigned int v5; // er12
int v7; // eax
int v8; // er12
char *v10; // rdx
char v11; // cl
char *v12; // rax
struct rlimit64 *v13; // rsi
__int64 v14; // rdx
__int64 v15; // rcx
rlim64_t v16; // r8
__int64 v17; // r12
bool v18; // cf
int v19; // er14
int v20; // er15
unsigned int v21; // eax
rlim64_t v22; // [rsp+8h] [rbp-50h]
struct rlimit64 rlimits; // [rsp+10h] [rbp-48h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
while ( 2 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "BHLSb:hps:vx");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'B':
v4 = 3;
continue;
case 'H':
v5 |= 9u;
v4 = 1;
continue;
case 'L':
v4 = 0;
continue;
case 'S':
v4 = 2;
continue;
case 'b':
v10 = optarg;
v11 = *optarg;
if ( *optarg )
{
LABEL_10:
switch ( v11 )
{
case 'c':
v5 |= 2u;
goto LABEL_15;
case 'd':
v5 |= 8u;
goto LABEL_15;
case 'g':
v5 |= 0x40u;
goto LABEL_15;
case 'l':
v5 |= 1u;
goto LABEL_15;
case 'm':
v5 |= 4u;
goto LABEL_15;
case 'p':
v5 |= 0x10u;
goto LABEL_15;
case 'u':
v5 |= 0x20u;
LABEL_15:
v12 = v10++;
optarg = v10;
v11 = v12[1];
if ( !v11 )
continue;
goto LABEL_10;
default:
v8 = 2;
fprintf(stderr, "Unknown specifier %c to -b\n", (unsigned int)v11);
return v8;
}
}
continue;
case 'p':
continue;
case 's':
if ( (unsigned int)parse_bounds_constprop_0(optarg) )
goto LABEL_5;
continue;
case 'v':
verbose = 1;
continue;
case 'x':
v3 = 1;
continue;
default:
goto LABEL_5;
}
}
break;
}
if ( optind >= argc )
{
LABEL_5:
v8 = 2;
help(*argv);
return v8;
}
v13 = &rlimits;
matcher = new_matcher(v5);
getrlimit64(RLIMIT_NOFILE, &rlimits);
v16 = rlimits.rlim_cur - 8;
if ( verbose )
{
v13 = (struct rlimit64 *)(adjust_suffix + 1);
v22 = rlimits.rlim_cur - 8;
fwrite("Scanning file system...\n", 1uLL, 0x18uLL, stderr);
v17 = optind;
v16 = v22;
if ( argc <= optind )
{
LABEL_33:
if ( verbose )
{
v13 = (struct rlimit64 *)(adjust_suffix + 1);
fwrite("\nLooking for duplicates...\n", 1uLL, 0x1BuLL, stderr);
}
goto LABEL_35;
}
LABEL_28:
v18 = v3 == 0;
v19 = v16;
v20 = v18 ? 1 : 3;
do
{
v13 = (struct rlimit64 *)walker;
if ( nftw64(argv[v17], (__nftw64_func_t)walker, v19, v20) == -1 )
{
v13 = (struct rlimit64 *)"\nError processing argument %s: ";
fprintf(stderr, "\nError processing argument %s: ", argv[v17]);
perror(0LL);
}
++v17;
}
while ( argc > (int)v17 );
goto LABEL_33;
}
v17 = optind;
if ( optind < argc )
goto LABEL_28;
LABEL_35:
v8 = finalize_matcher(matcher, v13, v14, v15, v16);
if ( v8 )
return 1;
if ( v4 == 2 )
{
v21 = make_links(matcher, 0LL, &symlink, "symlink");
}
else if ( v4 == 3 )
{
v21 = make_links(matcher, 0LL, &btrfs_clone, "clone");
}
else
{
v21 = v4 == 1 ? (unsigned int)make_links(matcher, 0LL, &link, "hardlink") : (unsigned int)print_dups(matcher);
}
if ( !v21 )
return 1;
free_matcher(matcher);
return v8;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
unsigned int v5; // er12
int v7; // eax
int v8; // er12
char *v10; // rdx
char v11; // cl
char *v12; // rax
struct rlimit64 *v13; // rsi
__int64 v14; // rdx
__int64 v15; // rcx
rlim64_t v16; // r8
__int64 v17; // r12
bool v18; // cf
int v19; // er14
int v20; // er15
unsigned int v21; // eax
rlim64_t v22; // [rsp+8h] [rbp-50h]
struct rlimit64 rlimits; // [rsp+10h] [rbp-48h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
while ( 2 )
{
v7 = _posix_getopt((unsigned int)argc, argv, "BHLSb:hps:vx");
if ( v7 != -1 )
{
switch ( v7 )
{
case 'B':
v4 = 3;
continue;
case 'H':
v5 |= 9u;
v4 = 1;
continue;
case 'L':
v4 = 0;
continue;
case 'S':
v4 = 2;
continue;
case 'b':
v10 = optarg;
v11 = *optarg;
if ( *optarg )
{
LABEL_10:
switch ( v11 )
{
case 'c':
v5 |= 2u;
goto LABEL_15;
case 'd':
v5 |= 8u;
goto LABEL_15;
case 'g':
v5 |= 0x40u;
goto LABEL_15;
case 'l':
v5 |= 1u;
goto LABEL_15;
case 'm':
v5 |= 4u;
goto LABEL_15;
case 'p':
v5 |= 0x10u;
goto LABEL_15;
case 'u':
v5 |= 0x20u;
LABEL_15:
v12 = v10++;
optarg = v10;
v11 = v12[1];
if ( !v11 )
continue;
goto LABEL_10;
default:
v8 = 2;
fprintf(stderr, "Unknown specifier %c to -b\n", (unsigned int)v11);
return v8;
}
}
continue;
case 'p':
continue;
case 's':
if ( (unsigned int)func3(optarg) )
goto LABEL_5;
continue;
case 'v':
verbose = 1;
continue;
case 'x':
v3 = 1;
continue;
default:
goto LABEL_5;
}
}
break;
}
if ( optind >= argc )
{
LABEL_5:
v8 = 2;
func2(*argv);
return v8;
}
v13 = &rlimits;
matcher = new_matcher(v5);
getrlimit64(RLIMIT_NOFILE, &rlimits);
v16 = rlimits.rlim_cur - 8;
if ( verbose )
{
v13 = (struct rlimit64 *)(adjust_suffix + 1);
v22 = rlimits.rlim_cur - 8;
fwrite("Scanning file system...\n", 1uLL, 0x18uLL, stderr);
v17 = optind;
v16 = v22;
if ( argc <= optind )
{
LABEL_33:
if ( verbose )
{
v13 = (struct rlimit64 *)(adjust_suffix + 1);
fwrite("\nLooking for duplicates...\n", 1uLL, 0x1BuLL, stderr);
}
goto LABEL_35;
}
LABEL_28:
v18 = v3 == 0;
v19 = v16;
v20 = v18 ? 1 : 3;
do
{
v13 = (struct rlimit64 *)walker;
if ( nftw64(argv[v17], (__nftw64_func_t)walker, v19, v20) == -1 )
{
v13 = (struct rlimit64 *)"\nError processing argument %s: ";
fprintf(stderr, "\nError processing argument %s: ", argv[v17]);
perror(0LL);
}
++v17;
}
while ( argc > (int)v17 );
goto LABEL_33;
}
v17 = optind;
if ( optind < argc )
goto LABEL_28;
LABEL_35:
v8 = finalize_matcher(matcher, v13, v14, v15, v16);
if ( v8 )
return 1;
if ( v4 == 2 )
{
v21 = make_links(matcher, 0LL, &symlink, "symlink");
}
else if ( v4 == 3 )
{
v21 = make_links(matcher, 0LL, &btrfs_clone, "clone");
}
else
{
v21 = v4 == 1 ? (unsigned int)make_links(matcher, 0LL, &link, "hardlink") : (unsigned int)print_dups(matcher);
}
if ( !v21 )
return 1;
free_matcher(matcher);
return v8;
}

original_code:
int main(int argc, char *argv[]) {
 int ok = 1, i, opt, xdev = 0;
 rlim_t maxfiles;
 struct rlimit limit;
 matcher_flags flags = 0;
 link_flags lf = 0;
 enum {
  LIST_DUPS_MODE,
  HARD_LINK_MODE,
  SOFT_LINK_MODE,
  BTRFS_COPY_MODE
 } mode = LIST_DUPS_MODE;
 while ((opt = getopt(argc,argv,"BHLSb:hps:vx")) != -1) {
  switch(opt) {
  case 'B':
   mode = BTRFS_COPY_MODE;
   break;
  case 'H':
   mode = HARD_LINK_MODE;
   flags |= M_DEV|M_LINK;
   break;
  case 'L':
   mode = LIST_DUPS_MODE;
   break;
  case 'S':
   mode = SOFT_LINK_MODE;
   break;
  case 'b':
   optarg--;
   while (*++optarg != '\0') switch (*optarg) {
   case 'c': flags |= M_CTIME; break;
   case 'd': flags |= M_DEV; break;
   case 'g': flags |= M_GID; break;
   case 'l': flags |= M_LINK; break;
   case 'm': flags |= M_MTIME; break;
   case 'p': flags |= M_MODE; break;
   case 'u': flags |= M_UID; break;
   default:
    fprintf(stderr,"Unknown specifier %c to -b\n",*optarg);
    return 2;
   }
   break;
  case 'p':
   lf &= LINKS_PRESERVE;
   break;
  case 's':
   if (parse_bounds(&bounds,optarg)) {
    help(argv[0]);
    return 2;
   }
   break;
  case 'v':
   verbose = 1;
   lf &= LINKS_VERBOSE;
   break;
  case 'x':
   xdev = 1;
   break;
  case 'h':
  default:
   help(argv[0]);
   return 2;
  }
 }
 if (optind >= argc) {
  help(argv[0]);
  return 2;
 }
 matcher = new_matcher(flags);
 getrlimit(RLIMIT_NOFILE,&limit);
 maxfiles = limit.rlim_cur - 8;
 if (verbose) fputs("Scanning file system...\n",stderr);
 for (i = optind; i < argc; i++) {
  ok = nftw(argv[i],walker,maxfiles,FTW_PHYS|(xdev?FTW_MOUNT:0));
  if (ok == -1) {
   fprintf(stderr,"\nError processing argument %s: ",argv[i]);
   perror(((void *)0));
  }
 }
 if (verbose) fputs("\nLooking for duplicates...\n",stderr);
 if (finalize_matcher(matcher)) return 1;
 switch (mode) {
 case LIST_DUPS_MODE: ok = print_dups(matcher); break;
 case HARD_LINK_MODE: ok = make_links(matcher,lf,link,"hardlink"); break;
 case SOFT_LINK_MODE: ok = make_links(matcher,lf,symlink,"symlink"); break;
 case BTRFS_COPY_MODE: ok = make_links(matcher,lf,btrfs_clone,"clone"); break;
 }
 if (!ok) return 1;
 free_matcher(matcher);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int ok = 1; int i; int opt; int xdev = 0;
 unsigned long maxfiles;
 struct rlimit limit;
 enum matcher_flags flags = 0;
 enum link_flags lf = 0;
 enum { LIST_DUPS_MODE=0, HARD_LINK_MODE=1, SOFT_LINK_MODE=2, BTRFS_COPY_MODE=3 } mode = LIST_DUPS_MODE;
 while ((opt = getopt(argc,argv,"BHLSb:hps:vx")) != -1) {
  switch(opt) {
  case 'B':
   mode = BTRFS_COPY_MODE;
   break;
  case 'H':
   mode = HARD_LINK_MODE;
   flags |= M_DEV|M_LINK;
   break;
  case 'L':
   mode = LIST_DUPS_MODE;
   break;
  case 'S':
   mode = SOFT_LINK_MODE;
   break;
  case 'b':
   optarg--;
   while (*++optarg != '\0') switch (*optarg) {
   case 'c': flags |= M_CTIME; break;
   case 'd': flags |= M_DEV; break;
   case 'g': flags |= M_GID; break;
   case 'l': flags |= M_LINK; break;
   case 'm': flags |= M_MTIME; break;
   case 'p': flags |= M_MODE; break;
   case 'u': flags |= M_UID; break;
   default:
    fprintf(stderr,"Unknown specifier %c to -b\n",*optarg);
    return 2;
   }
   break;
  case 'p':
   lf &= LINKS_PRESERVE;
   break;
  case 's':
   if (parse_bounds(&bounds,optarg)) {
    help(argv[0]);
    return 2;
   }
   break;
  case 'v':
   verbose = 1;
   lf &= LINKS_VERBOSE;
   break;
  case 'x':
   xdev = 1;
   break;
  case 'h':
  default:
   help(argv[0]);
   return 2;
  }
 }
 if (optind >= argc) {
  help(argv[0]);
  return 2;
 }
 matcher = new_matcher(flags);
 getrlimit(RLIMIT_NOFILE,&limit);
 maxfiles = limit.rlim_cur - 8;
 if (verbose) fputs("Scanning file system...\n",stderr);
 for (i = optind; i < argc; i++) {
  ok = nftw(argv[i],walker,maxfiles,FTW_PHYS|(xdev?FTW_MOUNT:0));
  if (ok == -1) {
   fprintf(stderr,"\nError processing argument %s: ",argv[i]);
   perror(((void *)0));
  }
 }
 if (verbose) fputs("\nLooking for duplicates...\n",stderr);
 if (finalize_matcher(matcher)) return 1;
 switch (mode) {
 case LIST_DUPS_MODE: ok = print_dups(matcher); break;
 case HARD_LINK_MODE: ok = make_links(matcher,lf,link,"hardlink"); break;
 case SOFT_LINK_MODE: ok = make_links(matcher,lf,symlink,"symlink"); break;
 case BTRFS_COPY_MODE: ok = make_links(matcher,lf,btrfs_clone,"clone"); break;
 }
 if (!ok) return 1;
 free_matcher(matcher);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ok int

variable_types: i int

variable_types: opt int

variable_types: xdev int

variable_types:
maxfiles
unsigned long

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

variable_types: enum matcher_flags { M_LINK=1, M_CTIME=2, M_MTIME=4, M_DEV=8, M_MODE=16, M_UID=32, M_GID=64 }

variable_types: enum link_flags { LINKS_PRESERVE=1, LINKS_VERBOSE=2 }


repo: fuzxxl/fdup

original_code:
static int cmp_fileinfo(struct fileinfo *a,struct fileinfo *b) {
 matcher_flags f = cmp_matcher->flags;
 const char *names = cmp_matcher->name_map;
 int cmp;
 if (a == b) return 0;
 if (a->stat.st_size != b->stat.st_size) return a->stat.st_size - b->stat.st_size;
 if (f & M_DEV) if (a->stat.st_dev != b->stat.st_dev) return a->stat.st_dev - b->stat.st_dev;
 if (a->stat.st_dev == b->stat.st_dev && a->stat.st_ino == b->stat.st_ino)
  return (f & M_LINK) ? strcmp(names+a->path, names+b->path) : 0;
 if (f & M_MODE) if (a->stat.st_mode != b->stat.st_mode) return a->stat.st_mode - b->stat.st_mode;
 if (f & M_UID) if (a->stat.st_uid != b->stat.st_uid) return a->stat.st_uid - b->stat.st_uid;
 if (f & M_GID) if (a->stat.st_gid != b->stat.st_gid) return a->stat.st_gid - b->stat.st_gid;
 if (f & M_MTIME) if (a->stat.st_mtim.tv_sec != b->stat.st_mtim.tv_sec) return a->stat.st_mtim.tv_sec - b->stat.st_mtim.tv_sec;
 if (f & M_CTIME) if (a->stat.st_ctim.tv_sec != b->stat.st_ctim.tv_sec) return a->stat.st_ctim.tv_sec - b->stat.st_ctim.tv_sec;
 if (~a->hashed & HAS_SHORT_HASH) {
  file_sha1(a->short_hash,names+a->path,SHORT_HASH_SIZE);
  a->hashed |= HAS_SHORT_HASH;
 }
 if (~b->hashed & HAS_SHORT_HASH) {
  file_sha1(b->short_hash,names+b->path,SHORT_HASH_SIZE);
  b->hashed |= HAS_SHORT_HASH;
 }
 cmp = memcmp(a->short_hash,b->short_hash,20);
 if (cmp != 0) return cmp;
 if (~a->hashed & HAS_FULL_HASH) {
  file_sha1(a->hash,names+a->path,a->stat.st_size);
  a->hashed |= HAS_FULL_HASH;
 }
 if (~b->hashed & HAS_FULL_HASH) {
  file_sha1(b->hash,names+b->path,b->stat.st_size);
  b->hashed |= HAS_FULL_HASH;
 }
 return memcmp(a->hash,b->hash,20);
}

canonical_original_code:
static int cmp_fileinfo(struct fileinfo *a, struct fileinfo *b) {
 enum matcher_flags f = cmp_matcher->flags;
 char *names = cmp_matcher->name_map;
 int cmp;
 if (a == b) return 0;
 if (a->stat.st_size != b->stat.st_size) return a->stat.st_size - b->stat.st_size;
 if (f & M_DEV) if (a->stat.st_dev != b->stat.st_dev) return a->stat.st_dev - b->stat.st_dev;
 if (a->stat.st_dev == b->stat.st_dev && a->stat.st_ino == b->stat.st_ino)
  return (f & M_LINK) ? strcmp(names+a->path, names+b->path) : 0;
 if (f & M_MODE) if (a->stat.st_mode != b->stat.st_mode) return a->stat.st_mode - b->stat.st_mode;
 if (f & M_UID) if (a->stat.st_uid != b->stat.st_uid) return a->stat.st_uid - b->stat.st_uid;
 if (f & M_GID) if (a->stat.st_gid != b->stat.st_gid) return a->stat.st_gid - b->stat.st_gid;
 if (f & M_MTIME) if (a->stat.st_mtim.tv_sec != b->stat.st_mtim.tv_sec) return a->stat.st_mtim.tv_sec - b->stat.st_mtim.tv_sec;
 if (f & M_CTIME) if (a->stat.st_ctim.tv_sec != b->stat.st_ctim.tv_sec) return a->stat.st_ctim.tv_sec - b->stat.st_ctim.tv_sec;
 if (~a->hashed & HAS_SHORT_HASH) {
  file_sha1(a->short_hash,names+a->path,SHORT_HASH_SIZE);
  a->hashed |= HAS_SHORT_HASH;
 }
 if (~b->hashed & HAS_SHORT_HASH) {
  file_sha1(b->short_hash,names+b->path,SHORT_HASH_SIZE);
  b->hashed |= HAS_SHORT_HASH;
 }
 cmp = memcmp(a->short_hash,b->short_hash,20);
 if (cmp != 0) return cmp;
 if (~a->hashed & HAS_FULL_HASH) {
  file_sha1(a->hash,names+a->path,a->stat.st_size);
  a->hashed |= HAS_FULL_HASH;
 }
 if (~b->hashed & HAS_FULL_HASH) {
  file_sha1(b->hash,names+b->path,b->stat.st_size);
  b->hashed |= HAS_FULL_HASH;
 }
 return memcmp(a->hash,b->hash,20);
}

variable_types: struct fileinfo { 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]; } stat; long path; int hashed; unsigned char hash[20]; unsigned char short_hash[20]; } *

variable_types:
b
struct fileinfo *

variable_types:
names
char *

variable_types: cmp int

return_type: int

user_defined_types: enum matcher_flags { M_LINK=1, M_CTIME=2, M_MTIME=4, M_DEV=8, M_MODE=16, M_UID=32, M_GID=64 }

user_defined_types: struct fileinfo { struct stat stat; long path; int hashed; unsigned char hash[20]; unsigned char short_hash[20]; }

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


hello

repo: gabrield/stk

decompiled_code:
int __fastcall hello(const char *a1)
{
return printf("Hello %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("Hello %s\n", a1);
}

original_code:
void hello(void *string)
{
    char *str = (char*)string;
    printf("Hello %s\n", str);
}

variable_types:
string
void *

variable_types:
str
char *

return_type: void


decompiled_code:
Display *stk_init()
{
Display *result; // rax

list = 0LL;
result = XOpenDisplay(0LL);
display = result;
return result;
}

canonical_decompiled_code:
Display *func0()
{
Display *result; // rax

list = 0LL;
result = XOpenDisplay(0LL);
display = result;
return result;
}

original_code:
void stk_init()
{
    list = ((void *)0);
    display = XOpenDisplay(0);
}


decompiled_code:
__int64 __fastcall stk_widget_insert(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = list;
*v1 = a1;
v1[1] = 0LL;
v1[2] = v2;
if ( v2 )
*(_QWORD *)(v2 + 8) = v1;
list = (__int64)v1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx

v1 = malloc(0x18uLL);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = list;
*v1 = a1;
v1[1] = 0LL;
v1[2] = v2;
if ( v2 )
*(_QWORD *)(v2 + 8) = v1;
list = (__int64)v1;
return 0LL;
}

original_code:
int stk_widget_insert(void *widget)
{
    widget_list *new_widget = (widget_list *)malloc(sizeof(widget_list));
    if(new_widget)
    {
        new_widget->this = widget;
        new_widget->prev = ((void *)0);
        new_widget->next = list;
        if(list != ((void *)0))
            list->prev = new_widget;
        list = new_widget;
        return 0;
    }
    return -1;
}

canonical_original_code:
int stk_widget_insert(void *widget)
{
    struct widget_ptr *new_widget = (widget_list *)malloc(sizeof(widget_list));
    if(new_widget)
    {
        new_widget->this = widget;
        new_widget->prev = ((void *)0);
        new_widget->next = list;
        if(list != ((void *)0))
            list->prev = new_widget;
        list = new_widget;
        return 0;
    }
    return -1;
}

variable_types:
widget
void *

variable_types: struct widget_ptr { void *this; struct widget_ptr *prev; } *


decompiled_code:
__int64 stk_widget_delete()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
int stk_widget_delete(void *widget)
{
    return 0;
}


decompiled_code:
_BOOL8 __fastcall file_exists(char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return (unsigned int)stat(a1, &v2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return (unsigned int)func20(a1, &v2) == 0;
}

original_code:
static int file_exists(char* file_name)
{
 struct stat buffer;
 return (stat(file_name, &buffer) == 0);
}

canonical_original_code:
static int file_exists(char *file_name)
{
 struct stat buffer;
 return (stat(file_name, &buffer) == 0);
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


terminate

decompiled_code:
void __fastcall __noreturn terminate(int a1)
{
exit(a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(int a1)
{
exit(a1);
}

original_code:
void terminate(int code)
{
 if(code == 0)
  ;
 else
  ;
 exit(code);
}

variable_types: code int


decompiled_code:
void __noreturn show_help()
{
puts(
"Usage: m00conv [OPTION]... INPUT OUTPUT\n"
"Convert INPUT and save it to OUTPUT\n"
"\n"
"Mandatory arguments to long options are mandatory for short options too.\n"
" -h, --help\tdisplay this help and exit");
terminate(0);
}

canonical_decompiled_code:
void __noreturn func9()
{
puts(
"Usage: m00conv [OPTION]... INPUT OUTPUT\n"
"Convert INPUT and save it to OUTPUT\n"
"\n"
"Mandatory arguments to long options are mandatory for short options too.\n"
" -h, --help\tdisplay this help and exit");
func8(0);
}

original_code:
static void show_help()
{
 printf(
  "Usage: m00conv [OPTION]... INPUT OUTPUT\n"
  "Convert INPUT and save it to OUTPUT\n"
  "\n"
  "Mandatory arguments to long options are mandatory for short options too.\n"
  "  -h, --help\tdisplay this help and exit\n"
  );
 terminate(0);
}


decompiled_code:
char *__fastcall strip_spaces(char *s)
{
const unsigned __int16 *v2; // rbx
__int64 v3; // rdx
char *v4; // rax

v2 = *__ctype_b_loc();
while ( 1 )
{
v3 = *s;
if ( (v2[v3] & 0x2000) == 0 )
break;
++s;
}
if ( (_BYTE)v3 )
{
v4 = &s[strlen(s) - 1];
if ( s < v4 )
{
do
{
if ( (v2[*v4] & 0x2000) == 0 )
break;
--v4;
}
while ( s != v4 );
}
v4[1] = 0;
}
return s;
}

original_code:
char* strip_spaces(char* line)
{
 while(((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short int) _ISspace)) line++;
 if(*line == 0) return line;
 char* end;
 end = line + strlen(line) - 1;
 while(end > line && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short int) _ISspace)) end--;
 *(end + 1) = 0;
 return line;
}

canonical_original_code:
char *strip_spaces(char *line)
{
 while(((*__ctype_b_loc ())[(int) ((*line))] & (unsigned short) _ISspace)) line++;
 if(*line == 0) return line;
 char *end;
 end = line + strlen(line) - 1;
 while(end > line && ((*__ctype_b_loc ())[(int) ((*end))] & (unsigned short) _ISspace)) end--;
 *(end + 1) = 0;
 return line;
}

variable_types:
line
char *

variable_types:
end
char *

return_type: char *


decompiled_code:
const char *__fastcall strip_comments(const char *a1)
{
size_t v1; // r8
const char *i; // rax

v1 = strlen(a1);
for ( i = a1; i != &a1[v1]; ++i )
{
if ( *i == 40 && i[1] == 42 )
{
*i = 0;
return a1;
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func12(const char *a1)
{
size_t v1; // r8
const char *i; // rax

v1 = strlen(a1);
for ( i = a1; i != &a1[v1]; ++i )
{
if ( *i == 40 && i[1] == 42 )
{
*i = 0;
return a1;
}
}
return a1;
}

original_code:
char* strip_comments(char* line)
{
 for(int i = 0; i < strlen(line); i++)
 {
  if(line[i] == '(' && line[i+1] == '*')
  {
   line[i] = 0;
   break;
  }
 }
 return line;
}

canonical_original_code:
char *strip_comments(char *line)
{
 for(int i = 0; i < strlen(line); i++)
 {
  if(line[i] == '(' && line[i+1] == '*')
  {
   line[i] = 0;
   break;
  }
 }
 return line;
}

variable_types: i int


decompiled_code:
bool __fastcall is_blank(_BYTE *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
bool __fastcall func13(_BYTE *a1)
{
return *a1 == 0;
}

original_code:
_Bool is_blank(char* line)
{
 if(!strlen(line))
  return 1;
 return 0;
}

canonical_original_code:
_Bool is_blank(char *line)
{
 if(!strlen(line))
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall parse_line(void *src, int *a2, _DWORD *a3, _DWORD *a4)
{
size_t v6; // rbx
void *v7; // r15
unsigned int v8; // er12
char *v9; // rdi
const __int32_t **v10; // rbx
__int64 v11; // rdx
const char *v12; // rdi
__int32_t v13; // eax
int v14; // eax
char *v16; // [rsp+8h] [rbp-40h]

v6 = strlen((const char *)src) + 1;
v7 = calloc(v6, 1uLL);
memcpy(v7, src, v6);
v16 = strtok((char *)v7, " ");
if ( v16 )
{
v8 = 0;
v9 = v16;
v10 = __ctype_tolower_loc();
while ( 1 )
{
v11 = *v9;
v12 = v9 + 1;
v13 = (*v10)[v11];
switch ( (_BYTE)v13 )
{
case 'x':
v8 = 1;
*a3 = (int)(atof(v12) * 100.0);
break;
case 'z':
v8 = 1;
*a4 = (int)(atof(v12) * 100.0);
break;
case 'g':
v14 = atoi(v12);
if ( v14 > 3 )
{
v8 = 0;
free(v7);
return v8;
}
*a2 = v14;
v8 = 1;
break;
}
v9 = strtok(0LL, " ");
if ( !v9 )
goto LABEL_12;
}
}
v8 = 0;
LABEL_12:
free(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func14(void *src, int *a2, _DWORD *a3, _DWORD *a4)
{
size_t v6; // rbx
void *v7; // r15
unsigned int v8; // er12
char *v9; // rdi
const __int32_t **v10; // rbx
__int64 v11; // rdx
const char *v12; // rdi
__int32_t v13; // eax
int v14; // eax
char *v16; // [rsp+8h] [rbp-40h]

v6 = strlen((const char *)src) + 1;
v7 = calloc(v6, 1uLL);
memcpy(v7, src, v6);
v16 = strtok((char *)v7, " ");
if ( v16 )
{
v8 = 0;
v9 = v16;
v10 = __ctype_tolower_loc();
while ( 1 )
{
v11 = *v9;
v12 = v9 + 1;
v13 = (*v10)[v11];
switch ( (_BYTE)v13 )
{
case 'x':
v8 = 1;
*a3 = (int)(atof(v12) * 100.0);
break;
case 'z':
v8 = 1;
*a4 = (int)(atof(v12) * 100.0);
break;
case 'g':
v14 = atoi(v12);
if ( v14 > 3 )
{
v8 = 0;
free(v7);
return v8;
}
*a2 = v14;
v8 = 1;
break;
}
v9 = strtok(0LL, " ");
if ( !v9 )
goto LABEL_12;
}
}
v8 = 0;
LABEL_12:
free(v7);
return v8;
}

original_code:
static _Bool parse_line(char* line, int* g, int* x, int* z)
{
 char* work_line = calloc(strlen(line)+1, 1);
 strcpy(work_line, line);
 char* token = strtok(work_line, " ");
 _Bool found = 0;
 int temp_g;
 while(token != ((void *)0))
 {
  char initial = tolower(token[0]);
  token++;
  switch(initial)
  {
   case 'g':
    temp_g = atoi(token);
    if(temp_g > 3) {
     free(work_line);
     return 0;
    }
    *g = temp_g;
    found = 1;
    break;
   case 'x':
    *x = (int)(atof(token) * 100);
    found = 1;
    break;
   case 'z':
    *z = (int)(atof(token) * 100);
    found = 1;
  }
  token = strtok(((void *)0), " ");
 }
 free(work_line);
 return found;
}

canonical_original_code:
static _Bool parse_line(char *line, int *g, int *x, int *z)
{
 char *work_line = calloc(strlen(line)+1, 1);
 strcpy(work_line, line);
 char *token = strtok(work_line, " ");
 _Bool found = 0;
 int temp_g;
 while(token != ((void *)0))
 {
  char initial = tolower(token[0]);
  token++;
  switch(initial)
  {
   case 'g':
    temp_g = atoi(token);
    if(temp_g > 3) {
     free(work_line);
     return 0;
    }
    *g = temp_g;
    found = 1;
    break;
   case 'x':
    *x = (int)(atof(token) * 100);
    found = 1;
    break;
   case 'z':
    *z = (int)(atof(token) * 100);
    found = 1;
  }
  token = strtok(((void *)0), " ");
 }
 free(work_line);
 return found;
}

variable_types:
g
int *

variable_types:
x
int *

variable_types:
z
int *

variable_types:
token
char *

variable_types: initial char


repo: gabrielmagno/BigGraph

original_code:
void Graph_calculate_WeaklyConnectedComponents(Graph * graph, unsigned int ** weakly_connected_components)
{
    Vertex_id vertex, actual_vertex;
    Vertex_id * queue, * predecessors, * successors;
    unsigned int i, group_id = 0, n_predecessors, n_successors, queue_i, queue_j;
    queue = (Vertex_id *) malloc(((*graph).n_vertexes)*sizeof(Vertex_id));
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        (*weakly_connected_components)[vertex] = 0;
    }
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        if ((*weakly_connected_components)[vertex] == 0) {
            queue_i = queue_j = 0;
            queue[queue_j++] = vertex;
            (*weakly_connected_components)[vertex] = ++group_id;
            while (queue_i < queue_j) {
                actual_vertex = queue[queue_i++];
                Graph_vertex_successors(graph, actual_vertex, &successors, &n_successors);
                Graph_vertex_predecessors(graph, actual_vertex, &predecessors, &n_predecessors);
                for (i = 0; i < n_successors; i++) {
                    if ((*weakly_connected_components)[successors[i]] == 0) {
                        (*weakly_connected_components)[successors[i]] = group_id;
                        queue[queue_j++] = successors[i];
                    }
                }
                for (i = 0; i < n_predecessors; i++) {
                    if ((*weakly_connected_components)[predecessors[i]] == 0) {
                        (*weakly_connected_components)[predecessors[i]] = group_id;
                        queue[queue_j++] = predecessors[i];
                    }
                }
            }
        }
    }
    free(queue);
}

canonical_original_code:
void Graph_calculate_WeaklyConnectedComponents(struct Graph *graph, unsigned int **weakly_connected_components)
{
    unsigned int vertex; unsigned int actual_vertex;
    unsigned int *queue; unsigned int *predecessors; unsigned int *successors;
    unsigned int i; unsigned int group_id = 0; unsigned int n_predecessors; unsigned int n_successors; unsigned int queue_i; unsigned int queue_j;
    queue = (unsigned int *) malloc(((*graph).n_vertexes)*sizeof(Vertex_id));
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        (*weakly_connected_components)[vertex] = 0;
    }
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        if ((*weakly_connected_components)[vertex] == 0) {
            queue_i = queue_j = 0;
            queue[queue_j++] = vertex;
            (*weakly_connected_components)[vertex] = ++group_id;
            while (queue_i < queue_j) {
                actual_vertex = queue[queue_i++];
                Graph_vertex_successors(graph, actual_vertex, &successors, &n_successors);
                Graph_vertex_predecessors(graph, actual_vertex, &predecessors, &n_predecessors);
                for (i = 0; i < n_successors; i++) {
                    if ((*weakly_connected_components)[successors[i]] == 0) {
                        (*weakly_connected_components)[successors[i]] = group_id;
                        queue[queue_j++] = successors[i];
                    }
                }
                for (i = 0; i < n_predecessors; i++) {
                    if ((*weakly_connected_components)[predecessors[i]] == 0) {
                        (*weakly_connected_components)[predecessors[i]] = group_id;
                        queue[queue_j++] = predecessors[i];
                    }
                }
            }
        }
    }
    free(queue);
}

variable_types: struct Graph { unsigned int n_vertexes; unsigned int n_edges; struct Vertex { unsigned int out_edges_pos; unsigned int out_degree; unsigned int in_edges_pos; unsigned int in_degree; } *vertexes; unsigned int *out_edges; unsigned int *in_edges; } *

variable_types:
vertex
unsigned int

variable_types:
queue
unsigned int *

variable_types:
predecessors
unsigned int *

variable_types:
successors
unsigned int *

variable_types:
i
unsigned int

user_defined_types: struct Graph { unsigned int n_vertexes; unsigned int n_edges; struct Vertex *vertexes; unsigned int *out_edges; unsigned int *in_edges; }


decompiled_code:
int __fastcall time_start(const char *a1, struct timeval *a2)
{
fprintf(stderr, "+ %s... ", a1);
return gettimeofday(a2, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, struct timeval *a2)
{
fprintf(stderr, "+ %s... ", a1);
return gettimeofday(a2, 0LL);
}

original_code:
void time_start(char * message, time_measure * time)
{
    fprintf(stderr, "+ %s... ", message);
    gettimeofday(&((*time).start), ((void *)0));
}

canonical_original_code:
void time_start(char *message, struct time_measure *time)
{
    fprintf(stderr, "+ %s... ", message);
    gettimeofday(&((*time).start), ((void *)0));
}

variable_types:
message
char *

variable_types: struct time_measure { struct timeval { long tv_sec; long tv_usec; } start; struct timeval stop; float total; } *

user_defined_types: struct time_measure { struct timeval start; struct timeval stop; float total; }


decompiled_code:
int __fastcall time_stop(__int64 a1)
{
FILE *v2; // rdi
int v3; // edx

gettimeofday((struct timeval *)(a1 + 16), 0LL);
v2 = stderr;
v3 = (*(_DWORD *)(a1 + 24) + 1000000 * (*(_DWORD *)(a1 + 16) - *(_DWORD *)a1) - *(_DWORD *)(a1 + 8)) / 1000000;
*(float *)(a1 + 32) = (float)v3;
return fprintf(v2, "OK [%.2f s]\n", (float)v3);
}

original_code:
void time_stop(time_measure * time)
{
    gettimeofday(&((*time).stop), ((void *)0));
    (*time).total = ((((*time).stop.tv_sec - (*time).start.tv_sec)*1000000) + ((*time).stop.tv_usec - (*time).start.tv_usec))/1000000;
    fprintf(stderr, "OK [%.2f s]\n", (*time).total);
}

canonical_original_code:
void time_stop(struct time_measure *time)
{
    gettimeofday(&((*time).stop), ((void *)0));
    (*time).total = ((((*time).stop.tv_sec - (*time).start.tv_sec)*1000000) + ((*time).stop.tv_usec - (*time).start.tv_usec))/1000000;
    fprintf(stderr, "OK [%.2f s]\n", (*time).total);
}

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
size_t v4; // r13
FILE *v5; // r13
unsigned int i; // ebx
__int64 v7; // r9
__int64 v8; // rdx
double v9; // xmm2_8
__int64 v10; // r8
double v11; // xmm1_8
double v12; // xmm0_8
__int64 v13; // rcx
__int64 v14; // rax
__int64 v15; // rdx
FILE *v17; // r13
void *ptr; // [rsp+8h] [rbp-A0h] BYREF
void *v19; // [rsp+10h] [rbp-98h] BYREF
void *v20; // [rsp+18h] [rbp-90h] BYREF
void *v21; // [rsp+20h] [rbp-88h] BYREF
void *v22; // [rsp+28h] [rbp-80h] BYREF
unsigned int v23; // [rsp+30h] [rbp-78h] BYREF
__int64 v24; // [rsp+38h] [rbp-70h]
struct timeval v25[5]; // [rsp+50h] [rbp-58h] BYREF

time_start("Reading graph", v25);
if ( argc > 1 )
{
v17 = fopen(argv[1], "r");
Graph_open(&v23, v17);
fclose(v17);
}
else
{
Graph_open(&v23, stdin);
}
time_stop((__int64)v25);
time_start("Allocating structures", v25);
v3 = v23;
v4 = 8LL * v23;
ptr = malloc(v4);
v19 = malloc(v4);
v20 = malloc(v4);
v21 = malloc(4 * v3);
v22 = malloc(4 * v3);
time_stop((__int64)v25);
time_start("Calculating Reciprocity", v25);
Graph_calculate_Reciprocity(&v23, &ptr);
time_stop((__int64)v25);
time_start("Calculating Clustering Coef", v25);
Graph_calculate_ClusteringCoefficient(&v23, &v19);
time_stop((__int64)v25);
time_start("Calculating PageRank", v25);
Graph_calculate_PageRank(&v23, 1LL, &v20);
time_stop((__int64)v25);
time_start("Calculating Weakly CC", v25);
Graph_calculate_WeaklyConnectedComponents(&v23, &v21);
time_stop((__int64)v25);
time_start("Calculating Strongly CC", v25);
Graph_calculate_StronglyConnectedComponents(&v23, &v22);
time_stop((__int64)v25);
time_start("Writing results", v25);
v5 = stdout;
if ( argc > 2 )
v5 = fopen(argv[2], "w");
if ( v23 )
{
for ( i = 0; i < v23; ++i )
{
v7 = *((unsigned int *)v21 + i);
v8 = v24 + 16LL * i;
v9 = *((double *)v20 + i);
v10 = *(unsigned int *)(v8 + 4);
v11 = *((double *)v19 + i);
v12 = *((double *)ptr + i);
v13 = *(unsigned int *)(v8 + 12);
v14 = *((unsigned int *)v22 + i);
v15 = i;
fprintf(v5, "%d %d %d %.12lf %.12lf %.12lf %d %d\n", v15, v13, v10, v12, v11, v9, v7, v14);
}
}
if ( argc > 2 )
fclose(v5);
time_stop((__int64)v25);
time_start("Deallocating graph", v25);
Graph_close(&v23);
time_stop((__int64)v25);
time_start("Deallocating structures", v25);
free(ptr);
free(v19);
free(v20);
free(v21);
free(v22);
time_stop((__int64)v25);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
size_t v4; // r13
FILE *v5; // r13
unsigned int i; // ebx
__int64 v7; // r9
__int64 v8; // rdx
double v9; // xmm2_8
__int64 v10; // r8
double v11; // xmm1_8
double v12; // xmm0_8
__int64 v13; // rcx
__int64 v14; // rax
__int64 v15; // rdx
FILE *v17; // r13
void *ptr; // [rsp+8h] [rbp-A0h] BYREF
void *v19; // [rsp+10h] [rbp-98h] BYREF
void *v20; // [rsp+18h] [rbp-90h] BYREF
void *v21; // [rsp+20h] [rbp-88h] BYREF
void *v22; // [rsp+28h] [rbp-80h] BYREF
unsigned int v23; // [rsp+30h] [rbp-78h] BYREF
__int64 v24; // [rsp+38h] [rbp-70h]
struct timeval v25[5]; // [rsp+50h] [rbp-58h] BYREF

func0("Reading graph", v25);
if ( argc > 1 )
{
v17 = fopen(argv[1], "r");
Graph_open(&v23, v17);
fclose(v17);
}
else
{
Graph_open(&v23, stdin);
}
func1((__int64)v25);
func0("Allocating structures", v25);
v3 = v23;
v4 = 8LL * v23;
ptr = malloc(v4);
v19 = malloc(v4);
v20 = malloc(v4);
v21 = malloc(4 * v3);
v22 = malloc(4 * v3);
func1((__int64)v25);
func0("Calculating Reciprocity", v25);
Graph_calculate_Reciprocity(&v23, &ptr);
func1((__int64)v25);
func0("Calculating Clustering Coef", v25);
Graph_calculate_ClusteringCoefficient(&v23, &v19);
func1((__int64)v25);
func0("Calculating PageRank", v25);
Graph_calculate_PageRank(&v23, 1LL, &v20);
func1((__int64)v25);
func0("Calculating Weakly CC", v25);
Graph_calculate_WeaklyConnectedComponents(&v23, &v21);
func1((__int64)v25);
func0("Calculating Strongly CC", v25);
Graph_calculate_StronglyConnectedComponents(&v23, &v22);
func1((__int64)v25);
func0("Writing results", v25);
v5 = stdout;
if ( argc > 2 )
v5 = fopen(argv[2], "w");
if ( v23 )
{
for ( i = 0; i < v23; ++i )
{
v7 = *((unsigned int *)v21 + i);
v8 = v24 + 16LL * i;
v9 = *((double *)v20 + i);
v10 = *(unsigned int *)(v8 + 4);
v11 = *((double *)v19 + i);
v12 = *((double *)ptr + i);
v13 = *(unsigned int *)(v8 + 12);
v14 = *((unsigned int *)v22 + i);
v15 = i;
fprintf(v5, "%d %d %d %.12lf %.12lf %.12lf %d %d\n", v15, v13, v10, v12, v11, v9, v7, v14);
}
}
if ( argc > 2 )
fclose(v5);
func1((__int64)v25);
func0("Deallocating graph", v25);
Graph_close(&v23);
func1((__int64)v25);
func0("Deallocating structures", v25);
free(ptr);
free(v19);
free(v20);
free(v21);
free(v22);
func1((__int64)v25);
return 0;
}

original_code:
int main(int argc, char * argv[])
{
    unsigned long long int n_vertexes, n_edges, size_graph;
    double n_bytes;
    char s_bytes;
    scanf("%lld", &n_vertexes);
    scanf("%lld", &n_edges);
    size_graph = n_vertexes*sizeof(Vertex) + n_edges*sizeof(Vertex_id) + n_edges*sizeof(Vertex_id);
    printf("---------- System ----------\n");
    printf("* int = %lu\n", ((unsigned long) sizeof(int)));
    printf("* unsigned int = %lu\n", ((unsigned long) sizeof(unsigned int)));
    printf("* float = %lu\n", ((unsigned long) sizeof(float)));
    printf("* long long int = %lu\n", ((unsigned long) sizeof(long long int)));
    printf("* double = %lu\n", ((unsigned long) sizeof(double)));
    printf("---------- Graph ----------\n");
    printf("* Vertexes: %'lld\n", n_vertexes);
    printf("* Edges: %'lld\n", n_edges);
    bytes_readable(size_graph, &n_bytes, &s_bytes);
    printf("    - Graph in memory: %lld B (%.1f %cB)\n", size_graph, n_bytes, s_bytes);
    bytes_readable(n_vertexes, &n_bytes, &s_bytes);
    printf("    - Additional vertex information: %lld / B (%.1f %cB)\n", n_vertexes, n_bytes, s_bytes);
    bytes_readable(n_edges, &n_bytes, &s_bytes);
    printf("    - Additional edge information: %lld / B (%.1f %cB)\n", n_edges, n_bytes, s_bytes);
    printf("------------------------------\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long long n_vertexes; unsigned long long n_edges; unsigned long long size_graph;
    double n_bytes;
    char s_bytes;
    scanf("%lld", &n_vertexes);
    scanf("%lld", &n_edges);
    size_graph = n_vertexes*sizeof(Vertex) + n_edges*sizeof(Vertex_id) + n_edges*sizeof(Vertex_id);
    printf("---------- System ----------\n");
    printf("* int = %lu\n", ((unsigned long) sizeof(int)));
    printf("* unsigned int = %lu\n", ((unsigned long) sizeof(unsigned int)));
    printf("* float = %lu\n", ((unsigned long) sizeof(float)));
    printf("* long long int = %lu\n", ((unsigned long) sizeof(long long)));
    printf("* double = %lu\n", ((unsigned long) sizeof(double)));
    printf("---------- Graph ----------\n");
    printf("* Vertexes: %'lld\n", n_vertexes);
    printf("* Edges: %'lld\n", n_edges);
    bytes_readable(size_graph, &n_bytes, &s_bytes);
    printf("    - Graph in memory: %lld B (%.1f %cB)\n", size_graph, n_bytes, s_bytes);
    bytes_readable(n_vertexes, &n_bytes, &s_bytes);
    printf("    - Additional vertex information: %lld / B (%.1f %cB)\n", n_vertexes, n_bytes, s_bytes);
    bytes_readable(n_edges, &n_bytes, &s_bytes);
    printf("    - Additional edge information: %lld / B (%.1f %cB)\n", n_edges, n_bytes, s_bytes);
    printf("------------------------------\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void __fastcall Graph_calculate_StronglyConnectedComponents(unsigned int *a1, __int64 *a2)
{
size_t v2; // r13
_DWORD *v3; // rbp
_BYTE *v4; // r15
__int64 v5; // rcx
unsigned int v6; // eax
__int64 v7; // rdx
size_t v8; // rdx
_BYTE *v9; // rax
unsigned int v10; // er14
unsigned int *v11; // r13
unsigned int v12; // er12
unsigned int *v13; // rdx
__int64 v14; // rcx
__int64 v15; // rax
int v16; // eax
__int64 v17; // rdx
unsigned int v18; // er14
unsigned int *v19; // r13
unsigned int v20; // er12
unsigned int *v21; // rdx
__int64 v22; // rcx
__int64 v23; // rax
unsigned int *i; // [rsp+0h] [rbp-68h]
unsigned int v25; // [rsp+8h] [rbp-60h]
int v26; // [rsp+Ch] [rbp-5Ch]
int v27; // [rsp+Ch] [rbp-5Ch]
unsigned int *ptr; // [rsp+10h] [rbp-58h]
int v29; // [rsp+24h] [rbp-44h] BYREF
__int64 v30[8]; // [rsp+28h] [rbp-40h] BYREF

v2 = *a1;
ptr = (unsigned int *)malloc(4LL * (unsigned int)(100 * v2));
v3 = malloc(4 * v2);
v4 = malloc(v2);
if ( (_DWORD)v2 )
{
v5 = *a2;
v6 = 0;
do
{
v7 = v6++;
*(_DWORD *)(v5 + 4 * v7) = 0;
v4[v7] = 0;
v8 = *a1;
}
while ( (unsigned int)v8 > v6 );
if ( (_DWORD)v8 )
{
v26 = 0;
v25 = 0;
do
{
while ( 1 )
{
v9 = &v4[v25];
if ( !*v9 )
break;
if ( (unsigned int)v8 <= ++v25 )
goto LABEL_16;
}
*v9 = 1;
v10 = 1;
*v3 = v25;
while ( 1 )
{
v11 = &v3[v10 - 1];
if ( !v10 )
break;
while ( 1 )
{
v12 = *v11;
Graph_vertex_successors(a1, *v11, v30, &v29);
if ( !v29 )
break;
v13 = (unsigned int *)v30[0];
while ( 1 )
{
v14 = *v13;
if ( !v4[v14] )
break;
if ( ++v13 == (unsigned int *)(v30[0] + 4LL * (unsigned int)(v29 - 1) + 4) )
goto LABEL_31;
}
v4[v14] = 1;
v15 = v10++;
++v11;
v3[v15] = v14;
if ( !v10 )
goto LABEL_15;
}
LABEL_31:
--v10;
v4[v12] = 2;
ptr[v26++] = v12;
}
LABEL_15:
++v25;
v8 = *a1;
}
while ( (unsigned int)v8 > v25 );
LABEL_16:
if ( (_DWORD)v8 )
memset(v4, 0, v8);
if ( v26 )
{
v16 = v26;
v27 = 0;
for ( i = &ptr[v16 - 1]; ; --i )
{
v17 = *i;
if ( !v4[v17] )
{
++v27;
v18 = 1;
v4[v17] = 1;
*v3 = v17;
LABEL_24:
v19 = &v3[v18 - 1];
while ( v18 )
{
v20 = *v19;
Graph_vertex_predecessors(a1, *v19, v30, &v29);
if ( !v29 )
{
LABEL_33:
v4[v20] = 2;
--v18;
*(_DWORD *)(*a2 + 4LL * v20) = v27;
goto LABEL_24;
}
v21 = (unsigned int *)v30[0];
while ( 1 )
{
v22 = *v21;
if ( !v4[v22] )
break;
if ( (unsigned int *)(v30[0] + 4LL * (unsigned int)(v29 - 1) + 4) == ++v21 )
goto LABEL_33;
}
v4[v22] = 1;
v23 = v18;
++v19;
++v18;
v3[v23] = v22;
}
}
if ( ptr == i )
break;
}
}
}
}
free(ptr);
free(v3);
free(v4);
}

canonical_decompiled_code:
void __fastcall func0(unsigned int *a1, __int64 *a2)
{
size_t v2; // r13
_DWORD *v3; // rbp
_BYTE *v4; // r15
__int64 v5; // rcx
unsigned int v6; // eax
__int64 v7; // rdx
size_t v8; // rdx
_BYTE *v9; // rax
unsigned int v10; // er14
unsigned int *v11; // r13
unsigned int v12; // er12
unsigned int *v13; // rdx
__int64 v14; // rcx
__int64 v15; // rax
int v16; // eax
__int64 v17; // rdx
unsigned int v18; // er14
unsigned int *v19; // r13
unsigned int v20; // er12
unsigned int *v21; // rdx
__int64 v22; // rcx
__int64 v23; // rax
unsigned int *i; // [rsp+0h] [rbp-68h]
unsigned int v25; // [rsp+8h] [rbp-60h]
int v26; // [rsp+Ch] [rbp-5Ch]
int v27; // [rsp+Ch] [rbp-5Ch]
unsigned int *ptr; // [rsp+10h] [rbp-58h]
int v29; // [rsp+24h] [rbp-44h] BYREF
__int64 v30[8]; // [rsp+28h] [rbp-40h] BYREF

v2 = *a1;
ptr = (unsigned int *)malloc(4LL * (unsigned int)(100 * v2));
v3 = malloc(4 * v2);
v4 = malloc(v2);
if ( (_DWORD)v2 )
{
v5 = *a2;
v6 = 0;
do
{
v7 = v6++;
*(_DWORD *)(v5 + 4 * v7) = 0;
v4[v7] = 0;
v8 = *a1;
}
while ( (unsigned int)v8 > v6 );
if ( (_DWORD)v8 )
{
v26 = 0;
v25 = 0;
do
{
while ( 1 )
{
v9 = &v4[v25];
if ( !*v9 )
break;
if ( (unsigned int)v8 <= ++v25 )
goto LABEL_16;
}
*v9 = 1;
v10 = 1;
*v3 = v25;
while ( 1 )
{
v11 = &v3[v10 - 1];
if ( !v10 )
break;
while ( 1 )
{
v12 = *v11;
Graph_vertex_successors(a1, *v11, v30, &v29);
if ( !v29 )
break;
v13 = (unsigned int *)v30[0];
while ( 1 )
{
v14 = *v13;
if ( !v4[v14] )
break;
if ( ++v13 == (unsigned int *)(v30[0] + 4LL * (unsigned int)(v29 - 1) + 4) )
goto LABEL_31;
}
v4[v14] = 1;
v15 = v10++;
++v11;
v3[v15] = v14;
if ( !v10 )
goto LABEL_15;
}
LABEL_31:
--v10;
v4[v12] = 2;
ptr[v26++] = v12;
}
LABEL_15:
++v25;
v8 = *a1;
}
while ( (unsigned int)v8 > v25 );
LABEL_16:
if ( (_DWORD)v8 )
memset(v4, 0, v8);
if ( v26 )
{
v16 = v26;
v27 = 0;
for ( i = &ptr[v16 - 1]; ; --i )
{
v17 = *i;
if ( !v4[v17] )
{
++v27;
v18 = 1;
v4[v17] = 1;
*v3 = v17;
LABEL_24:
v19 = &v3[v18 - 1];
while ( v18 )
{
v20 = *v19;
Graph_vertex_predecessors(a1, *v19, v30, &v29);
if ( !v29 )
{
LABEL_33:
v4[v20] = 2;
--v18;
*(_DWORD *)(*a2 + 4LL * v20) = v27;
goto LABEL_24;
}
v21 = (unsigned int *)v30[0];
while ( 1 )
{
v22 = *v21;
if ( !v4[v22] )
break;
if ( (unsigned int *)(v30[0] + 4LL * (unsigned int)(v29 - 1) + 4) == ++v21 )
goto LABEL_33;
}
v4[v22] = 1;
v23 = v18;
++v19;
++v18;
v3[v23] = v22;
}
}
if ( ptr == i )
break;
}
}
}
}
free(ptr);
free(v3);
free(v4);
}

original_code:
void Graph_calculate_StronglyConnectedComponents(Graph * graph, unsigned int ** strongly_connected_components)
{
    Vertex_id vertex, actual_vertex;
    Vertex_id * adjacents, * stack_global, * stack_DFS;
    unsigned int i, n_adjacents, stack_global_i = 0, stack_DFS_i, group_id = 0, stack_DFS_i_aux;
    char * labels_DFS;
    stack_global = (Vertex_id *) malloc((100*(*graph).n_vertexes)*sizeof(Vertex_id));
    stack_DFS = (Vertex_id *) malloc(((*graph).n_vertexes)*sizeof(Vertex_id));
    labels_DFS = (char *) malloc(((*graph).n_vertexes)*sizeof(char));
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        (*strongly_connected_components)[vertex] = 0;
        labels_DFS[vertex] = 0;
    }
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        if (labels_DFS[vertex] == 0) {
            labels_DFS[vertex] = 1;
            stack_DFS_i = 0;
            stack_DFS[stack_DFS_i++] = vertex;
            while (stack_DFS_i > 0) {
                actual_vertex = stack_DFS[stack_DFS_i-1];
                stack_DFS_i_aux = stack_DFS_i;
                Graph_vertex_successors(graph, actual_vertex, &adjacents, &n_adjacents);
                for (i = 0; i < n_adjacents; i++) {
                    if (labels_DFS[adjacents[i]] == 0) {
                        labels_DFS[adjacents[i]] = 1;
                        stack_DFS[stack_DFS_i++] = adjacents[i];
                        break;
                    }
                }
                if (stack_DFS_i_aux != stack_DFS_i) {
                    continue;
                }
                labels_DFS[actual_vertex] = 2;
                --stack_DFS_i;
                stack_global[stack_global_i++] = actual_vertex;
            }
        }
    }
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        labels_DFS[vertex] = 0;
    }
    while (stack_global_i > 0) {
        vertex = stack_global[--stack_global_i];
        if (labels_DFS[vertex] == 0) {
            group_id++;
            labels_DFS[vertex] = 1;
            stack_DFS_i = 0;
            stack_DFS[stack_DFS_i++] = vertex;
            while (stack_DFS_i > 0) {
                actual_vertex = stack_DFS[stack_DFS_i-1];
                stack_DFS_i_aux = stack_DFS_i;
                Graph_vertex_predecessors(graph, actual_vertex, &adjacents, &n_adjacents);
                for (i = 0; i < n_adjacents; i++) {
                    if (labels_DFS[adjacents[i]] == 0) {
                        labels_DFS[adjacents[i]] = 1;
                        stack_DFS[stack_DFS_i++] = adjacents[i];
                        break;
                    }
                }
                if (stack_DFS_i_aux != stack_DFS_i) {
                    continue;
                }
                labels_DFS[actual_vertex] = 2;
                --stack_DFS_i;
                (*strongly_connected_components)[actual_vertex] = group_id;
            }
        }
    }
    free(stack_global);
    free(stack_DFS);
    free(labels_DFS);
}

canonical_original_code:
void Graph_calculate_StronglyConnectedComponents(struct Graph *graph, unsigned int **strongly_connected_components)
{
    unsigned int vertex; unsigned int actual_vertex;
    unsigned int *adjacents; unsigned int *stack_global; unsigned int *stack_DFS;
    unsigned int i; unsigned int n_adjacents; unsigned int stack_global_i = 0; unsigned int stack_DFS_i; unsigned int group_id = 0; unsigned int stack_DFS_i_aux;
    char *labels_DFS;
    stack_global = (unsigned int *) malloc((100*(*graph).n_vertexes)*sizeof(Vertex_id));
    stack_DFS = (unsigned int *) malloc(((*graph).n_vertexes)*sizeof(Vertex_id));
    labels_DFS = (char *) malloc(((*graph).n_vertexes)*sizeof(char));
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        (*strongly_connected_components)[vertex] = 0;
        labels_DFS[vertex] = 0;
    }
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        if (labels_DFS[vertex] == 0) {
            labels_DFS[vertex] = 1;
            stack_DFS_i = 0;
            stack_DFS[stack_DFS_i++] = vertex;
            while (stack_DFS_i > 0) {
                actual_vertex = stack_DFS[stack_DFS_i-1];
                stack_DFS_i_aux = stack_DFS_i;
                Graph_vertex_successors(graph, actual_vertex, &adjacents, &n_adjacents);
                for (i = 0; i < n_adjacents; i++) {
                    if (labels_DFS[adjacents[i]] == 0) {
                        labels_DFS[adjacents[i]] = 1;
                        stack_DFS[stack_DFS_i++] = adjacents[i];
                        break;
                    }
                }
                if (stack_DFS_i_aux != stack_DFS_i) {
                    continue;
                }
                labels_DFS[actual_vertex] = 2;
                --stack_DFS_i;
                stack_global[stack_global_i++] = actual_vertex;
            }
        }
    }
    for (vertex = 0; vertex < ((*graph).n_vertexes); vertex++) {
        labels_DFS[vertex] = 0;
    }
    while (stack_global_i > 0) {
        vertex = stack_global[--stack_global_i];
        if (labels_DFS[vertex] == 0) {
            group_id++;
            labels_DFS[vertex] = 1;
            stack_DFS_i = 0;
            stack_DFS[stack_DFS_i++] = vertex;
            while (stack_DFS_i > 0) {
                actual_vertex = stack_DFS[stack_DFS_i-1];
                stack_DFS_i_aux = stack_DFS_i;
                Graph_vertex_predecessors(graph, actual_vertex, &adjacents, &n_adjacents);
                for (i = 0; i < n_adjacents; i++) {
                    if (labels_DFS[adjacents[i]] == 0) {
                        labels_DFS[adjacents[i]] = 1;
                        stack_DFS[stack_DFS_i++] = adjacents[i];
                        break;
                    }
                }
                if (stack_DFS_i_aux != stack_DFS_i) {
                    continue;
                }
                labels_DFS[actual_vertex] = 2;
                --stack_DFS_i;
                (*strongly_connected_components)[actual_vertex] = group_id;
            }
        }
    }
    free(stack_global);
    free(stack_DFS);
    free(labels_DFS);
}

variable_types:
adjacents
unsigned int *

user_defined_types: struct Vertex { unsigned int out_edges_pos; unsigned int out_degree; unsigned int in_edges_pos; unsigned int in_degree; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
char v5; // [rsp+7h] [rbp-21h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h] BYREF
__int64 v7; // [rsp+10h] [rbp-18h] BYREF
__int64 v8[2]; // [rsp+18h] [rbp-10h] BYREF

_isoc99_scanf("%lld", &v6);
_isoc99_scanf("%lld", &v7);
v3 = 2 * v7 + 4 * v6;
puts("---------- System ----------");
v3 *= 4LL;
printf("* int = %lu\n", 4LL);
printf("* unsigned int = %lu\n", 4LL);
printf("* float = %lu\n", 4LL);
printf("* long long int = %lu\n", 8LL);
printf("* double = %lu\n", 8LL);
puts("---------- Graph ----------");
printf("* Vertexes: %'lld\n", v6);
printf("* Edges: %'lld\n", v7);
bytes_readable(v3, (double *)v8, &v5);
printf(" - Graph in memory: %lld B (%.1f %cB)\n", v3, *(double *)v8, (unsigned int)v5);
bytes_readable(v6, (double *)v8, &v5);
printf(" - Additional vertex information: %lld / B (%.1f %cB)\n", v6, *(double *)v8, (unsigned int)v5);
bytes_readable(v7, (double *)v8, &v5);
printf(" - Additional edge information: %lld / B (%.1f %cB)\n", v7, *(double *)v8, (unsigned int)v5);
puts("------------------------------");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
char v5; // [rsp+7h] [rbp-21h] BYREF
__int64 v6; // [rsp+8h] [rbp-20h] BYREF
__int64 v7; // [rsp+10h] [rbp-18h] BYREF
__int64 v8[2]; // [rsp+18h] [rbp-10h] BYREF

_isoc99_scanf("%lld", &v6);
_isoc99_scanf("%lld", &v7);
v3 = 2 * v7 + 4 * v6;
puts("---------- System ----------");
v3 *= 4LL;
printf("* int = %lu\n", 4LL);
printf("* unsigned int = %lu\n", 4LL);
printf("* float = %lu\n", 4LL);
printf("* long long int = %lu\n", 8LL);
printf("* double = %lu\n", 8LL);
puts("---------- Graph ----------");
printf("* Vertexes: %'lld\n", v6);
printf("* Edges: %'lld\n", v7);
func0(v3, (double *)v8, &v5);
printf(" - Graph in memory: %lld B (%.1f %cB)\n", v3, *(double *)v8, (unsigned int)v5);
func0(v6, (double *)v8, &v5);
printf(" - Additional vertex information: %lld / B (%.1f %cB)\n", v6, *(double *)v8, (unsigned int)v5);
func0(v7, (double *)v8, &v5);
printf(" - Additional edge information: %lld / B (%.1f %cB)\n", v7, *(double *)v8, (unsigned int)v5);
puts("------------------------------");
return 0;
}


repo: gabrielrussell/euler-c

decompiled_code:
__int64 __fastcall dar_push_atoi(__int64 a1, const char *a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = atoi(a2);
dar_push(a1, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = atoi(a2);
dar_push(a1, v3);
return 0LL;
}

original_code:
int dar_push_atoi ( void * d, char * c, int l ) {
    int i;
    i = atoi(c);
    dar_push((dar_t *)d,&i);
    return 0;
}

canonical_original_code:
int dar_push_atoi(void *d, char *c, int l) {
    int i;
    i = atoi(c);
    dar_push((struct dar *)d,&i);
    return 0;
}

variable_types:
d
void *

variable_types:
c
char *

variable_types: l int

variable_types: i int

user_defined_types: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; }


original_code:
int tri_max( itr_t * itr ) {
    char * line=((void *)0);
    size_t line_size=0;
    dar_t * values = dar_new(sizeof(dar_t*),8);
    while (itr->next(itr,&line,&line_size)) {
        dar_t * vr = dar_new(sizeof(int),1);
        split(line,line_size,' ',dar_push_atoi,vr);
        dar_push(values,&vr);
    }
    int i,j;
    for ( i = values->element_count - 2; i>=0; i-- ) {
        dar_t * thisrow;
        dar_t * lowerrow;
        dar_fetch(values,&thisrow,i);
        dar_fetch(values,&lowerrow,i+1);
        for ( j = 0; j < thisrow->element_count; j++ ) {
            int this, left, right;
            dar_fetch(thisrow,&this,j);
            dar_fetch(lowerrow,&left,j);
            dar_fetch(lowerrow,&right,j+1);
            if ( left > right ) {
                this += left;
            } else {
                this += right;
            }
            dar_store(thisrow,&this,j);
        }
    }
    dar_t * toprow;
    int r;
    dar_fetch(values,&toprow,0);
    dar_fetch(toprow,&r,0);
    itr->destructor(itr);
    return r;
}

canonical_original_code:
int tri_max(struct itr *itr) {
    char *line = ((void *)0);
    unsigned long line_size = 0;
    struct dar *values = dar_new(sizeof(dar_t*),8);
    while (itr->next(itr,&line,&line_size)) {
        struct dar *vr = dar_new(sizeof(int),1);
        split(line,line_size,' ',dar_push_atoi,vr);
        dar_push(values,&vr);
    }
    int i; int j;
    for ( i = values->element_count - 2; i>=0; i-- ) {
        struct dar *thisrow;
        struct dar *lowerrow;
        dar_fetch(values,&thisrow,i);
        dar_fetch(values,&lowerrow,i+1);
        for ( j = 0; j < thisrow->element_count; j++ ) {
            int this; int left; int right;
            dar_fetch(thisrow,&this,j);
            dar_fetch(lowerrow,&left,j);
            dar_fetch(lowerrow,&right,j+1);
            if ( left > right ) {
                this += left;
            } else {
                this += right;
            }
            dar_store(thisrow,&this,j);
        }
    }
    struct dar *toprow;
    int r;
    dar_fetch(values,&toprow,0);
    dar_fetch(toprow,&r,0);
    itr->destructor(itr);
    return r;
}

variable_types: struct itr { void *context; void (*destructor)(struct itr *); int (*next)(struct itr *, char **, unsigned long *); } *

variable_types:
line
char *

variable_types: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *

variable_types: j int

variable_types: this int

variable_types: left int

variable_types: right int

variable_types: r int


decompiled_code:
_QWORD *bn_new()
{
_QWORD *v0; // r12

v0 = calloc(0x10uLL, 1uLL);
*v0 = dar_new(4LL, 1LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = calloc(0x10uLL, 1uLL);
*v0 = dar_new(4LL, 1LL);
return v0;
}

original_code:
bn_t * bn_new(void) {
    bn_t * r = calloc(sizeof(*r),1);
    r->dar = dar_new( 4, 1 );
    return r;
}

canonical_original_code:
struct bn *bn_new() {
    struct bn *r = calloc(sizeof(*r),1);
    r->dar = dar_new( 4, 1 );
    return r;
}

variable_types: struct bn { struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *dar; int negative; } *

user_defined_types: struct bn { struct dar *dar; int negative; }


decompiled_code:
void __fastcall bn_destroy(void *ptr)
{
dar_destroy(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
dar_destroy(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void bn_destroy(bn_t * n) {
    dar_destroy(n->dar);
    free(n);
}

canonical_original_code:
void bn_destroy(struct bn *n) {
    dar_destroy(n->dar);
    free(n);
}


original_code:
void bn_iadd( bn_t * r,uint32_t i, int shift) {
    int offset = shift / 32;
    shift = shift % 32;
    if (shift) {
        int small_part = i << shift;
        int large_part = i >> ( 32 - shift );
        bn_iadd(r,small_part, offset * 32);
        bn_iadd(r,large_part,( offset + 1 ) * 32);
    } else {
        uint32_t zero = 0;
        uint32_t w;
        int overflow = 0;
        int o = offset;
        do {
            while ( r->dar->element_count < o + 1 ) dar_push(r->dar, &zero );
            (void)dar_fetch(r->dar,&w,o);
            overflow = (w + i < w);
            w += i;
            dar_store(r->dar,&w,o);
            i = overflow;
            o++;
        } while (i);
    }
}

canonical_original_code:
void bn_iadd(struct bn *r, unsigned int i, int shift) {
    int offset = shift / 32;
    shift = shift % 32;
    if (shift) {
        int small_part = i << shift;
        int large_part = i >> ( 32 - shift );
        bn_iadd(r,small_part, offset * 32);
        bn_iadd(r,large_part,( offset + 1 ) * 32);
    } else {
        unsigned int zero = 0;
        unsigned int w;
        int overflow = 0;
        int o = offset;
        do {
            while ( r->dar->element_count < o + 1 ) dar_push(r->dar, &zero );
            (void)dar_fetch(r->dar,&w,o);
            overflow = (w + i < w);
            w += i;
            dar_store(r->dar,&w,o);
            i = overflow;
            o++;
        } while (i);
    }
}

variable_types:
i
unsigned int

variable_types: shift int

variable_types: offset int

variable_types:
zero
unsigned int

variable_types:
w
unsigned int

variable_types: overflow int

variable_types: o int


decompiled_code:
_BOOL8 __fastcall bn_isub(__int64 *a1, unsigned int a2, int a3, __int64 a4)
{
int v4; // eax
unsigned int v6; // ebp
int v7; // eax
__int64 v8; // rdi
unsigned int v9; // ebx
unsigned int v10; // er12
__int64 v11; // rdi
__int64 v12; // rdx
_BOOL8 result; // rax
int v14; // ebx
int v15; // edx
unsigned int v16; // er12
int v17[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a3 + 31;
v6 = a2;
if ( a3 >= 0 )
v4 = a3;
v7 = v4 >> 5;
if ( (a3 & 0x1F) != 0 )
{
v14 = 32 * v7;
v15 = a3 % 32;
v16 = a2 >> (32 - v15);
bn_isub(a1, a2 << v15, (unsigned int)(32 * v7));
bn_isub(a1, v16, (unsigned int)(v14 + 32));
result = 0LL;
}
else
{
v8 = *a1;
v9 = v7;
while ( 1 )
{
dar_fetch(v8, v17, v9, a4);
v10 = v17[0];
v11 = *a1;
v12 = v9++;
v17[0] -= v6;
dar_store(v11, v17, v12);
if ( v10 >= v6 )
break;
v8 = *a1;
if ( *(_DWORD *)(*a1 + 12) <= (signed int)v9 )
break;
v6 = 1;
}
result = v10 < v6;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 *a1, unsigned int a2, int a3, __int64 a4)
{
int v4; // eax
unsigned int v6; // ebp
int v7; // eax
__int64 v8; // rdi
unsigned int v9; // ebx
unsigned int v10; // er12
__int64 v11; // rdi
__int64 v12; // rdx
_BOOL8 result; // rax
int v14; // ebx
int v15; // edx
unsigned int v16; // er12
int v17[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a3 + 31;
v6 = a2;
if ( a3 >= 0 )
v4 = a3;
v7 = v4 >> 5;
if ( (a3 & 0x1F) != 0 )
{
v14 = 32 * v7;
v15 = a3 % 32;
v16 = a2 >> (32 - v15);
func3(a1, a2 << v15, (unsigned int)(32 * v7));
func3(a1, v16, (unsigned int)(v14 + 32));
result = 0LL;
}
else
{
v8 = *a1;
v9 = v7;
while ( 1 )
{
dar_fetch(v8, v17, v9, a4);
v10 = v17[0];
v11 = *a1;
v12 = v9++;
v17[0] -= v6;
dar_store(v11, v17, v12);
if ( v10 >= v6 )
break;
v8 = *a1;
if ( *(_DWORD *)(*a1 + 12) <= (signed int)v9 )
break;
v6 = 1;
}
result = v10 < v6;
}
return result;
}

original_code:
int bn_isub( bn_t * r, uint32_t i, int shift ) {
    int offset = shift / 32;
    shift = shift % 32;
    int underflow = 0;
    if ( shift ) {
        int small_part = i << shift;
        int large_part = i >> ( 32 - shift );
        bn_isub(r,small_part, offset * 32);
        bn_isub(r,large_part,( offset + 1 ) * 32);
    } else {
        uint32_t w;
        int o = offset;
        do {
            (void)dar_fetch(r->dar,&w,o);
            underflow = (w - i > w);
            w -= i;
            dar_store(r->dar,&w,o);
            i = underflow;
            o++;
        } while ( i && r->dar->element_count > o );
    }
    return underflow;
}

canonical_original_code:
int bn_isub(struct bn *r, unsigned int i, int shift) {
    int offset = shift / 32;
    shift = shift % 32;
    int underflow = 0;
    if ( shift ) {
        int small_part = i << shift;
        int large_part = i >> ( 32 - shift );
        bn_isub(r,small_part, offset * 32);
        bn_isub(r,large_part,( offset + 1 ) * 32);
    } else {
        unsigned int w;
        int o = offset;
        do {
            (void)dar_fetch(r->dar,&w,o);
            underflow = (w - i > w);
            w -= i;
            dar_store(r->dar,&w,o);
            i = underflow;
            o++;
        } while ( i && r->dar->element_count > o );
    }
    return underflow;
}

variable_types: underflow int


decompiled_code:
_BOOL8 __fastcall bn_sub(__int64 *a1, __int64 *a2, int a3, __int64 a4)
{
__int64 v5; // rdi
unsigned int v7; // ebx
__int64 v8; // rcx
_BOOL8 result; // rax
unsigned int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = *a2;
if ( *(int *)(*a2 + 12) <= 0 )
return 0LL;
v7 = 0;
while ( 1 )
{
dar_fetch(v5, v10, v7, a4);
result = bn_isub(a1, v10[0], a3, v8);
if ( result )
break;
v5 = *a2;
++v7;
a3 += 32;
if ( *(_DWORD *)(*a2 + 12) <= (signed int)v7 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 *a1, __int64 *a2, int a3, __int64 a4)
{
__int64 v5; // rdi
unsigned int v7; // ebx
__int64 v8; // rcx
_BOOL8 result; // rax
unsigned int v10[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = *a2;
if ( *(int *)(*a2 + 12) <= 0 )
return 0LL;
v7 = 0;
while ( 1 )
{
dar_fetch(v5, v10, v7, a4);
result = func3(a1, v10[0], a3, v8);
if ( result )
break;
v5 = *a2;
++v7;
a3 += 32;
if ( *(_DWORD *)(*a2 + 12) <= (signed int)v7 )
return 0LL;
}
return result;
}

original_code:
int bn_sub( bn_t * r, bn_t * n, int shift ) {
    int i;
    uint32_t x;
    int underflow;
    for (i=0;i<n->dar->element_count;i++) {
        (void)dar_fetch(n->dar,&x,i);
        if ((underflow = bn_isub(r,x,shift + i * 32 ))) return underflow;
    }
    return 0;
}

canonical_original_code:
int bn_sub(struct bn *r, struct bn *n, int shift) {
    int i;
    unsigned int x;
    int underflow;
    for (i=0;i<n->dar->element_count;i++) {
        (void)dar_fetch(n->dar,&x,i);
        if ((underflow = bn_isub(r,x,shift + i * 32 ))) return underflow;
    }
    return 0;
}

variable_types:
n
struct bn *

variable_types: i int

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall bn_add(__int64 *a1, __int64 *a2, int a3, __int64 a4)
{
__int64 v5; // rdi
__int64 result; // rax
unsigned int v8; // ebx
__int64 v9; // rdx
int v10; // edx
unsigned int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = *a2;
result = *(unsigned int *)(*a2 + 12);
if ( (int)result > 0 )
{
v8 = 0;
do
{
v9 = v8++;
dar_fetch(v5, v11, v9, a4);
v10 = a3;
a3 += 32;
result = bn_iadd(a1, v11[0], v10);
v5 = *a2;
}
while ( *(_DWORD *)(*a2 + 12) > (signed int)v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 *a2, int a3, __int64 a4)
{
__int64 v5; // rdi
__int64 result; // rax
unsigned int v8; // ebx
__int64 v9; // rdx
int v10; // edx
unsigned int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = *a2;
result = *(unsigned int *)(*a2 + 12);
if ( (int)result > 0 )
{
v8 = 0;
do
{
v9 = v8++;
dar_fetch(v5, v11, v9, a4);
v10 = a3;
a3 += 32;
result = func2(a1, v11[0], v10);
v5 = *a2;
}
while ( *(_DWORD *)(*a2 + 12) > (signed int)v8 );
}
return result;
}

original_code:
void bn_add( bn_t * r, bn_t * n, int shift ) {
    int i;
    uint32_t x;
    for (i=0;i<n->dar->element_count;i++) {
        (void)dar_fetch(n->dar,&x,i);
        bn_iadd(r,x,shift + i * 32 );
    }
}

canonical_original_code:
void bn_add(struct bn *r, struct bn *n, int shift) {
    int i;
    unsigned int x;
    for (i=0;i<n->dar->element_count;i++) {
        (void)dar_fetch(n->dar,&x,i);
        bn_iadd(r,x,shift + i * 32 );
    }
}


decompiled_code:
// attributes: thunk
_QWORD *bn_multi()
{
return bn_new();
}

canonical_decompiled_code:
_QWORD *func6()
{
return func0();
}

original_code:
bn_t * bn_multi(bn_t * n, bn_t * m) {
    bn_t * r = bn_new();
    return(r);
}

canonical_original_code:
struct bn *bn_multi(struct bn *n, struct bn *m) {
    struct bn *r = bn_new();
    return(r);
}

variable_types:
m
struct bn *

return_type: struct bn { struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *dar; int negative; } *


decompiled_code:
__int64 __fastcall bn_imulti(__int64 *a1, __int64 *a2, unsigned int a3, __int64 a4)
{
int v4; // ebp
unsigned int v5; // ebx
int v6; // edx
__int64 result; // rax

if ( a3 )
{
v4 = 0;
v5 = a3;
do
{
while ( (v5 & 1) == 0 )
{
++v4;
v5 >>= 1;
if ( !v5 )
return result;
}
v6 = v4++;
result = bn_add(a1, a2, v6, a4);
v5 >>= 1;
}
while ( v5 );
}
return result;
}

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

if ( a3 )
{
v4 = 0;
v5 = a3;
do
{
while ( (v5 & 1) == 0 )
{
++v4;
v5 >>= 1;
if ( !v5 )
return result;
}
v6 = v4++;
result = func5(a1, a2, v6, a4);
v5 >>= 1;
}
while ( v5 );
}
return result;
}

original_code:
void bn_imulti( bn_t * r, bn_t * n, uint32_t i ) {
    int j = 0;
    while( i ) {
        if ( i & 1 ) {
            bn_add( r, n, j );
        }
        j++;
        i>>=1;
    }
}

canonical_original_code:
void bn_imulti(struct bn *r, struct bn *n, unsigned int i) {
    int j = 0;
    while( i ) {
        if ( i & 1 ) {
            bn_add( r, n, j );
        }
        j++;
        i>>=1;
    }
}

variable_types: j int


decompiled_code:
__int64 __fastcall bn_to_uint32(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

dar_fetch(*a1, v5, 0LL, a4);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

dar_fetch(*a1, v5, 0LL, a4);
return v5[0];
}

original_code:
uint32_t bn_to_uint32(bn_t * n) {
    uint32_t v;
    dar_fetch(n->dar,&v,0);
    return v;
}

canonical_original_code:
unsigned int bn_to_uint32(struct bn *n) {
    unsigned int v;
    dar_fetch(n->dar,&v,0);
    return v;
}

variable_types:
v
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall bn_to_uint64(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r12
__int64 v6; // rdi
__int64 v8; // rcx
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = 0LL;
v6 = *a1;
if ( *(int *)(v6 + 12) <= 0 )
return v4;
dar_fetch(v6, v9, 0LL, a4);
v4 = (unsigned int)v9[0];
if ( *(int *)(*a1 + 12LL) <= 1 )
return v4;
dar_fetch(*a1, v9, 1LL, v8);
return ((unsigned __int64)(unsigned int)v9[0] << 32) + v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r12
__int64 v6; // rdi
__int64 v8; // rcx
int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = 0LL;
v6 = *a1;
if ( *(int *)(v6 + 12) <= 0 )
return v4;
dar_fetch(v6, v9, 0LL, a4);
v4 = (unsigned int)v9[0];
if ( *(int *)(*a1 + 12LL) <= 1 )
return v4;
dar_fetch(*a1, v9, 1LL, v8);
return ((unsigned __int64)(unsigned int)v9[0] << 32) + v4;
}

original_code:
uint64_t bn_to_uint64(bn_t * n) {
    uint64_t r = 0;
    uint32_t v;
    if (n->dar->element_count > 0) {
        dar_fetch(n->dar,&v,0);
        r += v;
    }
    if (n->dar->element_count > 1) {
        dar_fetch(n->dar,&v,1);
        r += (uint64_t)v << 32;
    }
    return r;
}

canonical_original_code:
unsigned long bn_to_uint64(struct bn *n) {
    unsigned long r = 0;
    unsigned int v;
    if (n->dar->element_count > 0) {
        dar_fetch(n->dar,&v,0);
        r += v;
    }
    if (n->dar->element_count > 1) {
        dar_fetch(n->dar,&v,1);
        r += (unsigned long)v << 32;
    }
    return r;
}

variable_types:
r
unsigned long

return_type: unsigned long


original_code:
void bn_trim( bn_t * a ) {
    int r;
    uint32_t w;
    while( a->dar->element_count ) {
        r = dar_fetch( a->dar, &w, a->dar->element_count - 1 );
        ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "bn.c", 175, __extension__ __PRETTY_FUNCTION__); }));
        if ( !w ) {
     a->dar->element_count--;
     a->dar->element_free++;
        } else {
            return;
        }
    }
}

canonical_original_code:
void bn_trim(struct bn *a) {
    int r;
    unsigned int w;
    while( a->dar->element_count ) {
        r = dar_fetch( a->dar, &w, a->dar->element_count - 1 );
        ((void) sizeof ((r) ? 1 : 0), __extension__ ({ if (r) ; else __assert_fail ("r", "bn.c", 175, __extension__ __PRETTY_FUNCTION__); }));
        if ( !w ) {
     a->dar->element_count--;
     a->dar->element_free++;
        } else {
            return;
        }
    }
}

variable_types: r int


original_code:
int bn_equal(bn_t * a, bn_t * b) {
    int i;
    bn_trim(a);
    bn_trim(b);
    uint32_t aw, bw;
    if ( a->dar->element_count != b->dar->element_count ) return(0);
    for (i=0;i<a->dar->element_count;i++) {
        (void)dar_fetch(a->dar,&aw,i);
        (void)dar_fetch(b->dar,&bw,i);
        if (aw != bw) return(0);
    }
    return(1);
}

canonical_original_code:
int bn_equal(struct bn *a, struct bn *b) {
    int i;
    bn_trim(a);
    bn_trim(b);
    unsigned int aw; unsigned int bw;
    if ( a->dar->element_count != b->dar->element_count ) return(0);
    for (i=0;i<a->dar->element_count;i++) {
        (void)dar_fetch(a->dar,&aw,i);
        (void)dar_fetch(b->dar,&bw,i);
        if (aw != bw) return(0);
    }
    return(1);
}

variable_types: struct bn { struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *dar; int negative; } *

variable_types:
b
struct bn *

variable_types:
aw
unsigned int

variable_types:
bw
unsigned int


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

result = *a1;
*(_DWORD *)(*a1 + 12) = 0;
return result;
}

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

result = *a1;
*(_DWORD *)(*a1 + 12) = 0;
return result;
}

original_code:
void bn_clear(bn_t * n) {
    n->dar->element_count = 0;
}

canonical_original_code:
void bn_clear(struct bn *n) {
    n->dar->element_count = 0;
}


decompiled_code:
__int64 __fastcall bn_icmp(__int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v5; // ebp
int v6; // ebx
__int64 v7; // rcx
int v8; // er13
__int64 v9; // rdx
int v10; // ebx
unsigned int v11; // ebp
__int64 v12; // rdi
int v13; // eax
__int64 v14; // rcx
__int64 v15; // rdi
int v16; // eax
__int64 v18; // rcx
int v19; // er13
int v21[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = a2;
v6 = a3;
bn_trim(a1, a2, a3, a4);
v8 = v6 / 32;
v9 = (unsigned int)(v6 / 32 + 1);
if ( (v6 & 0x1F) == 0 )
{
LABEL_11:
v15 = *a1;
v16 = *(_DWORD *)(*a1 + 12);
if ( v16 <= (int)v9 )
goto LABEL_8;
return 1LL;
}
v10 = v6 % 32;
v7 = (unsigned int)(32 - v10);
v11 = (unsigned int)a2 >> (32 - v10);
if ( !v11 )
{
v5 = (_DWORD)a2 << v10;
goto LABEL_11;
}
v12 = *a1;
v13 = *(_DWORD *)(*a1 + 12);
if ( (int)v9 >= v13 )
return 0xFFFFFFFFLL;
v14 = (unsigned int)(v8 + 2);
if ( (int)v14 < v13 )
return 1LL;
dar_fetch(v12, v21, v9, v14);
if ( v21[0] < v11 )
return 0xFFFFFFFFLL;
if ( v21[0] > v11 )
return 1LL;
v15 = *a1;
v5 = (_DWORD)a2 << v10;
v16 = *(_DWORD *)(*a1 + 12);
LABEL_8:
if ( v8 >= v16 )
return 0xFFFFFFFFLL;
dar_fetch(v15, v21, (unsigned int)v8, v7);
if ( v21[0] < v5 )
return 0xFFFFFFFFLL;
if ( v21[0] > v5 )
return 1LL;
v19 = v8 - 1;
if ( v19 >= 0 )
{
while ( 1 )
{
dar_fetch(*a1, v21, (unsigned int)v19, v18);
if ( v21[0] )
break;
if ( v19-- == 0 )
return 0LL;
}
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 *a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v5; // ebp
int v6; // ebx
__int64 v7; // rcx
int v8; // er13
__int64 v9; // rdx
int v10; // ebx
unsigned int v11; // ebp
__int64 v12; // rdi
int v13; // eax
__int64 v14; // rcx
__int64 v15; // rdi
int v16; // eax
__int64 v18; // rcx
int v19; // er13
int v21[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = a2;
v6 = a3;
func10(a1, a2, a3, a4);
v8 = v6 / 32;
v9 = (unsigned int)(v6 / 32 + 1);
if ( (v6 & 0x1F) == 0 )
{
LABEL_11:
v15 = *a1;
v16 = *(_DWORD *)(*a1 + 12);
if ( v16 <= (int)v9 )
goto LABEL_8;
return 1LL;
}
v10 = v6 % 32;
v7 = (unsigned int)(32 - v10);
v11 = (unsigned int)a2 >> (32 - v10);
if ( !v11 )
{
v5 = (_DWORD)a2 << v10;
goto LABEL_11;
}
v12 = *a1;
v13 = *(_DWORD *)(*a1 + 12);
if ( (int)v9 >= v13 )
return 0xFFFFFFFFLL;
v14 = (unsigned int)(v8 + 2);
if ( (int)v14 < v13 )
return 1LL;
dar_fetch(v12, v21, v9, v14);
if ( v21[0] < v11 )
return 0xFFFFFFFFLL;
if ( v21[0] > v11 )
return 1LL;
v15 = *a1;
v5 = (_DWORD)a2 << v10;
v16 = *(_DWORD *)(*a1 + 12);
LABEL_8:
if ( v8 >= v16 )
return 0xFFFFFFFFLL;
dar_fetch(v15, v21, (unsigned int)v8, v7);
if ( v21[0] < v5 )
return 0xFFFFFFFFLL;
if ( v21[0] > v5 )
return 1LL;
v19 = v8 - 1;
if ( v19 >= 0 )
{
while ( 1 )
{
dar_fetch(*a1, v21, (unsigned int)v19, v18);
if ( v21[0] )
break;
if ( v19-- == 0 )
return 0LL;
}
return 1LL;
}
return 0LL;
}

original_code:
int bn_icmp(bn_t * a, uint32_t i, int shift) {
    uint32_t w;
    int o;
    uint32_t small_part;
    uint32_t large_part;
    bn_trim(a);
    int offset = shift / 32;
    shift = shift % 32;
    if (shift) {
        small_part = i << shift;
        large_part = i >> ( 32 - shift );
    } else {
        small_part = i;
        large_part = 0;
    }
    if ( large_part ) {
        if ( offset + 1 + 1 > a->dar->element_count ) return -1;
        if ( offset + 1 + 1 < a->dar->element_count ) return 1;
        (void)dar_fetch(a->dar,&w,offset + 1);
        if ( large_part > w ) return -1;
        if ( large_part < w ) return 1;
    } else {
        if ( offset + 1 < a->dar->element_count ) return 1;
    }
    if ( offset + 1 > a->dar->element_count ) return -1;
    (void)dar_fetch(a->dar,&w,offset);
    if ( small_part > w ) return -1;
    if ( small_part < w ) return 1;
    for (o = offset - 1; o >= 0; o-- ) {
        (void)dar_fetch(a->dar,&w,o);
        if (w) return 1;
    }
    return 0;
}

canonical_original_code:
int bn_icmp(struct bn *a, unsigned int i, int shift) {
    unsigned int w;
    int o;
    unsigned int small_part;
    unsigned int large_part;
    bn_trim(a);
    int offset = shift / 32;
    shift = shift % 32;
    if (shift) {
        small_part = i << shift;
        large_part = i >> ( 32 - shift );
    } else {
        small_part = i;
        large_part = 0;
    }
    if ( large_part ) {
        if ( offset + 1 + 1 > a->dar->element_count ) return -1;
        if ( offset + 1 + 1 < a->dar->element_count ) return 1;
        (void)dar_fetch(a->dar,&w,offset + 1);
        if ( large_part > w ) return -1;
        if ( large_part < w ) return 1;
    } else {
        if ( offset + 1 < a->dar->element_count ) return 1;
    }
    if ( offset + 1 > a->dar->element_count ) return -1;
    (void)dar_fetch(a->dar,&w,offset);
    if ( small_part > w ) return -1;
    if ( small_part < w ) return 1;
    for (o = offset - 1; o >= 0; o-- ) {
        (void)dar_fetch(a->dar,&w,o);
        if (w) return 1;
    }
    return 0;
}

variable_types:
i
unsigned int

variable_types: shift int

variable_types: offset int


original_code:
dar_t * bn_format(bn_t * a) {
    uint32_t r;
    bn_trim(a);
    dar_t * digits = dar_new( 1, 8 );
    bn_t * b = bn_copy( a );
    bn_t * c;
    while ( b->dar->element_count ) {
        c = bn_idiv( b, 10, &r );
        r += '0';
        dar_push( digits, &r );
        bn_destroy( b );
        b = c;
    }
    dar_t * rdigits = dar_reverse( digits );
    bn_destroy( b );
    dar_destroy( digits );
    return(rdigits);
}

canonical_original_code:
struct dar *bn_format(struct bn *a) {
    unsigned int r;
    bn_trim(a);
    struct dar *digits = dar_new( 1, 8 );
    struct bn *b = bn_copy( a );
    struct bn *c;
    while ( b->dar->element_count ) {
        c = bn_idiv( b, 10, &r );
        r += '0';
        dar_push( digits, &r );
        bn_destroy( b );
        b = c;
    }
    struct dar *rdigits = dar_reverse( digits );
    bn_destroy( b );
    dar_destroy( digits );
    return(rdigits);
}

variable_types: struct bn { struct dar *dar; int negative; } *

variable_types:
r
unsigned int

variable_types: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *


original_code:
uint64_t bn_sum_digits(bn_t * n) {
    uint64_t r = 0;
    dar_t * s = bn_format(n);
    int i; char j;
    for ( i = 0; i < s->element_count; i++ ) {
        dar_fetch(s,&j,i);
        r += ( j - '0' );
    }
    dar_destroy(s);
    return r;
}

canonical_original_code:
unsigned long bn_sum_digits(struct bn *n) {
    unsigned long r = 0;
    struct dar *s = bn_format(n);
    int i; char j;
    for ( i = 0; i < s->element_count; i++ ) {
        dar_fetch(s,&j,i);
        r += ( j - '0' );
    }
    dar_destroy(s);
    return r;
}

variable_types: i int

variable_types: j char


original_code:
void dar_readyplus(dar_t * a, int more) {
 if (more > a->element_free) {
                int total = a->element_free + a->element_count;
                if ( more < total / 2 ) more = total / 2;
                more = ( more | 0x00000F ) + 1;
                a->data_size += more * a->element_size ;
  a->data = realloc(a->data, a->data_size );
  a->element_free += more;
 }
}

canonical_original_code:
void dar_readyplus(struct dar *a, int more) {
 if (more > a->element_free) {
                int total = a->element_free + a->element_count;
                if ( more < total / 2 ) more = total / 2;
                more = ( more | 0x00000F ) + 1;
                a->data_size += more * a->element_size ;
  a->data = realloc(a->data, a->data_size );
  a->element_free += more;
 }
}

variable_types: more int

variable_types: total int


decompiled_code:
_BOOL8 __fastcall dar_eq(__int64 a1, __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax
int v4; // ecx

v2 = *(_DWORD *)(a2 + 12);
result = 0LL;
if ( *(_DWORD *)(a1 + 12) == v2 )
{
v4 = *(_DWORD *)(a2 + 16);
if ( *(_DWORD *)(a1 + 16) == v4 )
result = memcmp(*(const void **)a1, *(const void **)a2, v4 * v2) == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // edx
_BOOL8 result; // rax
int v4; // ecx

v2 = *(_DWORD *)(a2 + 12);
result = 0LL;
if ( *(_DWORD *)(a1 + 12) == v2 )
{
v4 = *(_DWORD *)(a2 + 16);
if ( *(_DWORD *)(a1 + 16) == v4 )
result = memcmp(*(const void **)a1, *(const void **)a2, v4 * v2) == 0;
}
return result;
}

original_code:
int dar_eq(dar_t * a, dar_t * b) {
    if ( a->element_count != b->element_count ) return 0;
    if ( a->element_size != b->element_size ) return 0;
    return ! memcmp(a->data,b->data,b->element_size * b->element_count);
}

canonical_original_code:
int dar_eq(struct dar *a, struct dar *b) {
    if ( a->element_count != b->element_count ) return 0;
    if ( a->element_size != b->element_size ) return 0;
    return ! memcmp(a->data,b->data,b->element_size * b->element_count);
}

variable_types:
b
struct dar *


decompiled_code:
void __fastcall dar_ready(__int64 a1, int a2)
{
int v2; // eax

v2 = *(_DWORD *)(a1 + 20) + *(_DWORD *)(a1 + 12);
if ( v2 < a2 )
dar_readyplus(a1, a2 - v2);
}

original_code:
void dar_ready(dar_t * a, int size) {
    if ( size > a->element_free + a->element_count ) dar_readyplus( a, size - ( a->element_free + a->element_count ) );
}

canonical_original_code:
void dar_ready(struct dar *a, int size) {
    if ( size > a->element_free + a->element_count ) dar_readyplus( a, size - ( a->element_free + a->element_count ) );
}

variable_types: size int


decompiled_code:
void __fastcall dar_destroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void dar_destroy( dar_t * a ) {
    free(a->data);
    free(a);
}

canonical_original_code:
void dar_destroy(struct dar *a) {
    free(a->data);
    free(a);
}


original_code:
void dar_init(dar_t * a, int element_size, int initial_size) {
        initial_size = ( initial_size | 0x00000F ) + 1;
 a->data_size = element_size * initial_size;
 a->element_size = element_size;
        a->element_free = 0;
        a->data = 0;
 a->element_count = 0;
 dar_ready(a,initial_size);
}

canonical_original_code:
void dar_init(struct dar *a, int element_size, int initial_size) {
        initial_size = ( initial_size | 0x00000F ) + 1;
 a->data_size = element_size * initial_size;
 a->element_size = element_size;
        a->element_free = 0;
        a->data = 0;
 a->element_count = 0;
 dar_ready(a,initial_size);
}


decompiled_code:
void *__fastcall dar_new(int a1, int a2)
{
void *v2; // r12

v2 = malloc(0x18uLL);
dar_init((__int64)v2, a1, a2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func5(int a1, int a2)
{
void *v2; // r12

v2 = malloc(0x18uLL);
func4((__int64)v2, a1, a2);
return v2;
}

original_code:
dar_t * dar_new(int element_size, int initial_size) {
 dar_t * a;
 a = malloc(sizeof(*a));
        dar_init(a,element_size, initial_size);
        return(a);
}

canonical_original_code:
struct dar *dar_new(int element_size, int initial_size) {
 struct dar *a;
 a = malloc(sizeof(*a));
        dar_init(a,element_size, initial_size);
        return(a);
}

return_type: struct dar { void *data; int data_size; int element_count; int element_size; int element_free; } *


decompiled_code:
void **__fastcall dar_new_from_bytes(int a1, const void *a2, int a3)
{
void **v3; // r12
int v5; // er13

v3 = 0LL;
if ( !(a3 % a1) )
{
v5 = a3 / a1;
v3 = (void **)dar_new(a1, a3 / a1);
memcpy(*v3, a2, a3);
*((_DWORD *)v3 + 3) += v5;
*((_DWORD *)v3 + 5) -= v5;
}
return v3;
}

original_code:
dar_t * dar_new_from_bytes(int element_size, void * b, int len) {
    if ( len % element_size ) return ((void *)0);
    dar_t * r = dar_new(element_size, len / element_size);
    memcpy(r->data,b,len);
    r->element_count += len / element_size;
    r->element_free -= len / element_size;
    return r;
}

canonical_original_code:
struct dar *dar_new_from_bytes(int element_size, void *b, int len) {
    if ( len % element_size ) return ((void *)0);
    struct dar *r = dar_new(element_size, len / element_size);
    memcpy(r->data,b,len);
    r->element_count += len / element_size;
    r->element_free -= len / element_size;
    return r;
}

variable_types:
b
void *

variable_types: len int


decompiled_code:
void *__fastcall dar_store(__int64 a1, const void *a2, int a3)
{
return memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * a3), a2, *(int *)(a1 + 16));
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, const void *a2, int a3)
{
return memcpy((void *)(*(_QWORD *)a1 + *(_DWORD *)(a1 + 16) * a3), a2, *(int *)(a1 + 16));
}

original_code:
void dar_store(dar_t * a, void * e, int i) {
    memcpy(a->data + ( i * a->element_size), e, a->element_size);
}

canonical_original_code:
void dar_store(struct dar *a, void *e, int i) {
    memcpy(a->data + ( i * a->element_size), e, a->element_size);
}

variable_types:
e
void *


decompiled_code:
void *__fastcall dar_push(__int64 a1, const void *a2)
{
void *result; // rax

dar_readyplus(a1, 1);
result = dar_store(a1, a2, *(_DWORD *)(a1 + 12));
++*(_DWORD *)(a1 + 12);
--*(_DWORD *)(a1 + 20);
return result;
}

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

func0(a1, 1);
result = func7(a1, a2, *(_DWORD *)(a1 + 12));
++*(_DWORD *)(a1 + 12);
--*(_DWORD *)(a1 + 20);
return result;
}

original_code:
void dar_push(dar_t * a, void * e) {
 dar_readyplus(a,1);
 dar_store(a,e,a->element_count);
 a->element_count++;
 a->element_free--;
}

canonical_original_code:
void dar_push(struct dar *a, void *e) {
 dar_readyplus(a,1);
 dar_store(a,e,a->element_count);
 a->element_count++;
 a->element_free--;
}


decompiled_code:
__int64 __fastcall dar_index(__int64 a1, int a2)
{
return *(_QWORD *)a1 + a2 * *(_DWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
return *(_QWORD *)a1 + a2 * *(_DWORD *)(a1 + 16);
}

original_code:
void * dar_index( dar_t * a, int i ) {
    return a->data + a->element_size * i;
}

canonical_original_code:
void *dar_index(struct dar *a, int i) {
    return a->data + a->element_size * i;
}

return_type: void *


decompiled_code:
__int64 __fastcall dar_fetch(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // er12
const void *v4; // rax
void *v5; // r8

if ( *(_DWORD *)(a1 + 12) <= a3 || a3 < 0 )
return 0;
v3 = 1;
if ( a2 )
{
v4 = (const void *)dar_index(a1, a3);
memcpy(v5, v4, *(int *)(a1 + 16));
return 1LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // er12
const void *v4; // rax
void *v5; // r8

if ( *(_DWORD *)(a1 + 12) <= a3 || a3 < 0 )
return 0;
v3 = 1;
if ( a2 )
{
v4 = (const void *)func9(a1, a3);
memcpy(v5, v4, *(int *)(a1 + 16));
return 1LL;
}
return v3;
}

original_code:
int dar_fetch(dar_t * a, void * e, int i) {
    if ( i > a->element_count - 1 ) return(0);
    if ( i < 0 ) return(0);
    if (e) memcpy(e, dar_index( a, i ), a->element_size);
    return(1);
}

canonical_original_code:
int dar_fetch(struct dar *a, void *e, int i) {
    if ( i > a->element_count - 1 ) return(0);
    if ( i < 0 ) return(0);
    if (e) memcpy(e, dar_index( a, i ), a->element_size);
    return(1);
}


decompiled_code:
__int64 __fastcall dar_pop(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( !v2 )
return 0LL;
if ( !a2 )
{
LABEL_5:
++*(_DWORD *)(a1 + 20);
result = 1LL;
*(_DWORD *)(a1 + 12) = v2 - 1;
return result;
}
if ( (unsigned int)dar_fetch(a1, a2, v2 - 1) )
{
v2 = *(_DWORD *)(a1 + 12);
goto LABEL_5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( !v2 )
return 0LL;
if ( !a2 )
{
LABEL_5:
++*(_DWORD *)(a1 + 20);
result = 1LL;
*(_DWORD *)(a1 + 12) = v2 - 1;
return result;
}
if ( (unsigned int)func10(a1, a2, v2 - 1) )
{
v2 = *(_DWORD *)(a1 + 12);
goto LABEL_5;
}
return 0LL;
}

original_code:
int dar_pop(dar_t * a,void *e ) {
        if ( ! a->element_count ) return(0);
 if (e) {
            if (!dar_fetch(a,e,a->element_count - 1 ))
                return(0);
        }
 a->element_count--;
 a->element_free++;
        return(1);
}

canonical_original_code:
int dar_pop(struct dar *a, void *e) {
        if ( ! a->element_count ) return(0);
 if (e) {
            if (!dar_fetch(a,e,a->element_count - 1 ))
                return(0);
        }
 a->element_count--;
 a->element_free++;
        return(1);
}


decompiled_code:
void *__fastcall dar_reverse(__int64 a1)
{
void *v1; // r12
int v2; // ebx
const void *v3; // rax

v1 = dar_new(*(_DWORD *)(a1 + 16), *(_DWORD *)(a1 + 12));
v2 = *(_DWORD *)(a1 + 12) - 1;
if ( v2 >= 0 )
{
do
{
v3 = (const void *)dar_index(a1, v2);
dar_push((__int64)v1, v3);
}
while ( v2-- != 0 );
}
return v1;
}

original_code:
dar_t * dar_reverse( dar_t * a ) {
    int i;
    dar_t * r = dar_new(a->element_size,a->element_count);
    for ( i=a->element_count-1; i>=0; i-- ) dar_push(r, dar_index( a , i) );
    return r;
}

canonical_original_code:
struct dar *dar_reverse(struct dar *a) {
    int i;
    struct dar *r = dar_new(a->element_size,a->element_count);
    for ( i=a->element_count-1; i>=0; i-- ) dar_push(r, dar_index( a , i) );
    return r;
}

variable_types:
a
struct dar *


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

result = *(unsigned int *)(a1 + 12);
if ( (int)result > a2 )
{
result = (unsigned int)(result - a2);
*(_DWORD *)(a1 + 20) += result;
*(_DWORD *)(a1 + 12) = a2;
}
return result;
}

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

result = *(unsigned int *)(a1 + 12);
if ( (int)result > a2 )
{
result = (unsigned int)(result - a2);
*(_DWORD *)(a1 + 20) += result;
*(_DWORD *)(a1 + 12) = a2;
}
return result;
}

original_code:
void dar_trim( dar_t * a, int i ) {
    int d;
    if ( a->element_count > i ) {
        d = a->element_count - i;
        a->element_count -= d;
        a->element_free += d;
    }
}

canonical_original_code:
void dar_trim(struct dar *a, int i) {
    int d;
    if ( a->element_count > i ) {
        d = a->element_count - i;
        a->element_count -= d;
        a->element_free += d;
    }
}

variable_types: d int


decompiled_code:
__int64 __fastcall string_array_itr_next(__int64 *a1, const char **a2, size_t *a3)
{
__int64 v4; // rdx
__int64 v5; // rax
const char *v6; // rdi

v4 = *a1;
v5 = *(int *)(*a1 + 8);
v6 = *(const char **)(*(_QWORD *)*a1 + 8 * v5);
if ( !v6 )
return 0LL;
*(_DWORD *)(v4 + 8) = v5 + 1;
*a2 = v6;
*a3 = strlen(v6);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, const char **a2, size_t *a3)
{
__int64 v4; // rdx
__int64 v5; // rax
const char *v6; // rdi

v4 = *a1;
v5 = *(int *)(*a1 + 8);
v6 = *(const char **)(*(_QWORD *)*a1 + 8 * v5);
if ( !v6 )
return 0LL;
*(_DWORD *)(v4 + 8) = v5 + 1;
*a2 = v6;
*a3 = strlen(v6);
return 1LL;
}

original_code:
int string_array_itr_next ( itr_t * i, char **lineptr, size_t *n ) {
    string_array_itr_t *sai = i->context;
    if (!sai->array[sai->position]) return 0;
    *lineptr = sai->array[sai->position++];
    *n = strlen( *lineptr );
    return(1);
}

canonical_original_code:
int string_array_itr_next(struct itr *i, char **lineptr, unsigned long *n) {
    struct string_array_itr *sai = i->context;
    if (!sai->array[sai->position]) return 0;
    *lineptr = sai->array[sai->position++];
    *n = strlen( *lineptr );
    return(1);
}

variable_types: struct itr { void *context; void (*destructor)(struct itr *); int (*next)(struct itr *, char **, unsigned long *); } *

variable_types:
lineptr
char **

variable_types:
n
unsigned long *

variable_types: struct string_array_itr { char **array; int position; } *


decompiled_code:
void __fastcall string_array_itr_destroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void string_array_itr_destroy( itr_t * i ) {
    free(i->context);
    free(i);
}

canonical_original_code:
void string_array_itr_destroy(struct itr *i) {
    free(i->context);
    free(i);
}

user_defined_types: struct itr { void *context; void (*destructor)(struct itr *); int (*next)(struct itr *, char **, unsigned long *); }


decompiled_code:
__int64 __fastcall mdjb_hash(__int64 a1, int a2)
{
unsigned int v2; // eax
char *v3; // rdx
__int64 v4; // rsi
__int64 result; // rax

v2 = a2 - 1;
if ( a2 - 1 < 0 )
return 0LL;
v3 = (char *)(a1 + (int)v2);
v4 = a1 + a2 - 2 - v2;
LODWORD(result) = 0;
do
result = *v3-- ^ (unsigned int)(33 * result);
while ( v3 != (char *)v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
unsigned int v2; // eax
char *v3; // rdx
__int64 v4; // rsi
__int64 result; // rax

v2 = a2 - 1;
if ( a2 - 1 < 0 )
return 0LL;
v3 = (char *)(a1 + (int)v2);
v4 = a1 + a2 - 2 - v2;
LODWORD(result) = 0;
do
result = *v3-- ^ (unsigned int)(33 * result);
while ( v3 != (char *)v4 );
return result;
}

original_code:
uint32_t mdjb_hash ( char * key, int l ) {
    uint32_t h = 0;
    while ( --l >= 0 ) h = 33 * h ^ key[l];
    return h;
}

canonical_original_code:
unsigned int mdjb_hash(char *key, int l) {
    unsigned int h = 0;
    while ( --l >= 0 ) h = 33 * h ^ key[l];
    return h;
}

variable_types:
key
char *

variable_types: l int

variable_types:
h
unsigned int


decompiled_code:
__int64 __fastcall ht_make_entry(void *src, int a2, const void *a3, int a4)
{
size_t v4; // r14
void *v5; // rax
__int64 v6; // r12
int v7; // eax
void *v8; // rdi
__int64 result; // rax
int *v10; // rax

v4 = a4;
v5 = calloc(1uLL, a2 + (__int64)a4 + 42);
if ( v5 )
{
v6 = (__int64)v5;
v7 = mdjb_hash((__int64)src, a2);
*(_QWORD *)(v6 + 8) = v6 + 40;
*(_DWORD *)(v6 + 16) = a2;
*(_DWORD *)v6 = v7;
memcpy((void *)(v6 + 40), src, a2);
v8 = (void *)(v6 + a2 + 41);
*(_BYTE *)(v6 + a2 + 40) = 0;
*(_DWORD *)(v6 + 32) = v4;
*(_QWORD *)(v6 + 24) = v8;
memcpy(v8, a3, v4);
*(_BYTE *)(*(_QWORD *)(v6 + 24) + v4) = 0;
result = v6;
}
else
{
v10 = _errno_location();
error(1, *v10, "failure to calloc ht_entry_t");
result = ht_insert_entry();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *src, int a2, const void *a3, int a4)
{
size_t v4; // r14
void *v5; // rax
__int64 v6; // r12
int v7; // eax
void *v8; // rdi
__int64 result; // rax
int *v10; // rax

v4 = a4;
v5 = calloc(1uLL, a2 + (__int64)a4 + 42);
if ( v5 )
{
v6 = (__int64)v5;
v7 = func0((__int64)src, a2);
*(_QWORD *)(v6 + 8) = v6 + 40;
*(_DWORD *)(v6 + 16) = a2;
*(_DWORD *)v6 = v7;
memcpy((void *)(v6 + 40), src, a2);
v8 = (void *)(v6 + a2 + 41);
*(_BYTE *)(v6 + a2 + 40) = 0;
*(_DWORD *)(v6 + 32) = v4;
*(_QWORD *)(v6 + 24) = v8;
memcpy(v8, a3, v4);
*(_BYTE *)(*(_QWORD *)(v6 + 24) + v4) = 0;
result = v6;
}
else
{
v10 = _errno_location();
error(1, *v10, "failure to calloc ht_entry_t");
result = ht_insert_entry();
}
return result;
}

original_code:
ht_entry_t * ht_make_entry( char * key, int key_length, char * value, int value_length ) {
    ht_entry_t * e = calloc( 1, sizeof(ht_entry_t) + key_length + 1 + value_length + 1 );
    if ( e == ((void *)0) ) error(1,(*__errno_location ()),"failure to calloc  ht_entry_t");
    e->hash = mdjb_hash( key, key_length );
    e->key = (char *) e + sizeof(ht_entry_t);
    e->key_length = key_length;
    memcpy(e->key, key, key_length);
    e->key[key_length] = 0;
    e->value = (char *) e + sizeof(ht_entry_t) + key_length + 1;
    e->value_length = value_length;
    memcpy(e->value, value, value_length);
    e->value[value_length] = 0;
    return e;
}

canonical_original_code:
struct ht_entry *ht_make_entry(char *key, int key_length, char *value, int value_length) {
    struct ht_entry *e = calloc( 1, sizeof(ht_entry_t) + key_length + 1 + value_length + 1 );
    if ( e == ((void *)0) ) error(1,(*__errno_location ()),"failure to calloc  ht_entry_t");
    e->hash = mdjb_hash( key, key_length );
    e->key = (char *) e + sizeof(ht_entry_t);
    e->key_length = key_length;
    memcpy(e->key, key, key_length);
    e->key[key_length] = 0;
    e->value = (char *) e + sizeof(ht_entry_t) + key_length + 1;
    e->value_length = value_length;
    memcpy(e->value, value, value_length);
    e->value[value_length] = 0;
    return e;
}

variable_types:
value
char *

variable_types: struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; } *


original_code:
void ht_grow(ht_t * ht) {
    ht_t ht_orig = *ht;
    ht->size = ht->size ? ht->size * 2 : 32;
    ht->table = calloc( 1, sizeof(ht_entry_t *) * ht->size );
    ht->num = 0;
    ht->free = ht->size / 2;
    int i;
    for ( i=0; i < ht_orig.size; i++ ) {
        if ( ht_orig.table[i] ) {
            ht_insert_entry(ht,ht_orig.table[i]);
        }
    }
    free(ht_orig.table);
}

canonical_original_code:
void ht_grow(struct ht *ht) {
    struct ht ht_orig = *ht;
    ht->size = ht->size ? ht->size * 2 : 32;
    ht->table = calloc( 1, sizeof(struct ht_entry *) * ht->size );
    ht->num = 0;
    ht->free = ht->size / 2;
    int i;
    for ( i=0; i < ht_orig.size; i++ ) {
        if ( ht_orig.table[i] ) {
            ht_insert_entry(ht,ht_orig.table[i]);
        }
    }
    free(ht_orig.table);
}

variable_types: struct ht { struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; } **table; int size; int num; int free; } *

variable_types: i int

user_defined_types: struct ht { struct ht_entry **table; int size; int num; int free; }


original_code:
int ht_fetch( ht_t * ht, void * key, int key_length, void ** value, int * value_length ) {
    uint32_t hash = mdjb_hash( key, key_length );
    if (!ht->size) return(0);
    int hunt = hash % ht->size ;
    while ( ht->table[hunt] != ((void *)0) ) {
        if (ht->table[hunt]->hash == hash && ht->table[hunt]->key_length == key_length && memcmp(ht->table[hunt]->key,key,key_length) == 0 ) {
            *value = ht->table[hunt]->value;
            *value_length = ht->table[hunt]->value_length;
            return(1);
        }
        hunt = ( hunt + 1 ) % ht->size;
    }
    return(0);
}

canonical_original_code:
int ht_fetch(struct ht *ht, void *key, int key_length, void **value, int *value_length) {
    unsigned int hash = mdjb_hash( key, key_length );
    if (!ht->size) return(0);
    int hunt = hash % ht->size;
    while ( ht->table[hunt] != ((void *)0) ) {
        if (ht->table[hunt]->hash == hash && ht->table[hunt]->key_length == key_length && memcmp(ht->table[hunt]->key,key,key_length) == 0 ) {
            *value = ht->table[hunt]->value;
            *value_length = ht->table[hunt]->value_length;
            return(1);
        }
        hunt = ( hunt + 1 ) % ht->size;
    }
    return(0);
}

variable_types:
key
void *

variable_types:
value
void **

variable_types:
hash
unsigned int

variable_types: hunt int

user_defined_types: struct ht_entry { unsigned int hash; char *key; int key_length; char *value; int value_length; }


decompiled_code:
void __fastcall ht_destroy(void *ptr)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

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

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

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

original_code:
void ht_destroy(ht_t * ht) {
    int i;
    for ( i = 0; i < ht->size ; i++ ) {
        if (ht->table[i]) {
            free(ht->table[i]);
            ht->table[i]=0;
        }
    }
    free(ht->table);
    free(ht);
}

canonical_original_code:
void ht_destroy(struct ht *ht) {
    int i;
    for ( i = 0; i < ht->size ; i++ ) {
        if (ht->table[i]) {
            free(ht->table[i]);
            ht->table[i]=0;
        }
    }
    free(ht->table);
    free(ht);
}