cmpkey

original_code:
static inline int
cmpkey(spcat *c, sppage *p, void *rkey, int size)
{
 register int l =
  c->cmp(p->min->key, p->min->size, rkey, size, c->cmparg);
 register int r =
  c->cmp(p->max->key, p->max->size, rkey, size, c->cmparg);
 if (l <= 0 && r >= 0)
  return 0;
 if (l == -1)
  return -1;
 ((void) (0));
 return 1;
}

canonical_original_code:
static inline int cmpkey(struct spcat *c, struct sppage *p, void *rkey, int size)
{
 register int l = c->cmp(p->min->key, p->min->size, rkey, size, c->cmparg);
 register int r = c->cmp(p->max->key, p->max->size, rkey, size, c->cmparg);
 if (l <= 0 && r >= 0)
  return 0;
 if (l == -1)
  return -1;
 ((void) (0));
 return 1;
}

variable_types: struct spcat { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; } *min; struct spv *max; struct splist { struct splist *next; } link; } **i; unsigned int count; unsigned int top; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; } *

variable_types:
p
struct sppage *

variable_types:
rkey
void *

variable_types: l int

variable_types: r int

user_defined_types: struct spcat { struct spa *a; struct sppage **i; unsigned int count; unsigned int top; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; }

user_defined_types: struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv *min; struct spv *max; struct splist link; }


repo: Peaker/bindings-sophia

decompiled_code:
__int64 __fastcall sp_catensure(__int64 a1)
{
unsigned int v1; // esi
__int64 v3; // rsi
void *v4; // rax

v1 = *(_DWORD *)(a1 + 20);
if ( *(_DWORD *)(a1 + 16) + 1 < v1 )
return 0LL;
v3 = 2 * v1;
*(_DWORD *)(a1 + 20) = v3;
v4 = realloc(*(void **)(a1 + 8), 8 * v3);
*(_QWORD *)(a1 + 8) = v4;
return (unsigned int)-(v4 == 0LL);
}

original_code:
static inline int sp_catensure(spcat *c) {
 if ((c->count + 1) < c->top)
  return 0;
 c->top *= 2;
 c->i = realloc(c->i, c->top * sizeof(sppage*));
 if (c->i == ((void *)0))
  return -1;
 return 0;
}

canonical_original_code:
static inline int sp_catensure(struct spcat *c) {
 if ((c->count + 1) < c->top)
  return 0;
 c->top *= 2;
 c->i = realloc(c->i, c->top * sizeof(struct sppage *));
 if (c->i == ((void *)0))
  return -1;
 return 0;
}

return_type: int

user_defined_types: struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; }

user_defined_types: struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; }


original_code:
static inline sppage*
sp_catsearch(spcat *c, sppage *v, uint32_t *index) {
 int min = 0;
 int max = c->count - 1;
 while (max >= min) {
  int mid = min + ((max - min) >> 1);
  switch (cmppage(c, c->i[mid], v)) {
  case -1: min = mid + 1;
   continue;
  case 1: max = mid - 1;
   continue;
  default:
   *index = mid;
   return c->i[mid];
  }
 }
 *index = min;
 return ((void *)0);
}

canonical_original_code:
static inline struct sppage *sp_catsearch(struct spcat *c, struct sppage *v, unsigned int *index) {
 int min = 0;
 int max = c->count - 1;
 while (max >= min) {
  int mid = min + ((max - min) >> 1);
  switch (cmppage(c, c->i[mid], v)) {
  case -1: min = mid + 1;
   continue;
  case 1: max = mid - 1;
   continue;
  default:
   *index = mid;
   return c->i[mid];
  }
 }
 *index = min;
 return ((void *)0);
}

variable_types: struct spcat { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; struct sppage **i; unsigned int count; unsigned int top; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; } *

variable_types:
v
struct sppage *

variable_types:
index
unsigned int *

variable_types: min int

variable_types: max int

variable_types: mid int

return_type: struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; } *min; struct spv *max; struct splist { struct splist *next; } link; } *


original_code:
int sp_catinit(spcat *c, spa *a, int top, spcmpf cmp, void *cmparg) {
 c->a = a;
 c->cmp = cmp;
 c->cmparg = cmparg;
 c->count = 0;
 c->top = top;
 c->i = sp_malloc(a, sizeof(sppage*) * top);
 if (__builtin_expect(!! (c->i == ((void *)0)), 0))
  return -1;
 return 0;
}

canonical_original_code:
int sp_catinit(struct spcat *c, struct spa *a, int top, int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg), void *cmparg) {
 c->a = a;
 c->cmp = cmp;
 c->cmparg = cmparg;
 c->count = 0;
 c->top = top;
 c->i = sp_malloc(a, sizeof(struct sppage *) * top);
 if (__builtin_expect(!! (c->i == ((void *)0)), 0))
  return -1;
 return 0;
}

variable_types:
a
struct spa *

variable_types: top int

variable_types: int (*)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg)

variable_types:
cmparg
void *


original_code:
void sp_catfree(spcat *c) {
 uint32_t p = 0;
 while (p < c->count) {
  sp_free(c->a, c->i[p]->min);
  sp_free(c->a, c->i[p]->max);
  sp_free(c->a, c->i[p]);
  p++;
 }
 sp_free(c->a, c->i);
}

canonical_original_code:
void sp_catfree(struct spcat *c) {
 unsigned int p = 0;
 while (p < c->count) {
  sp_free(c->a, c->i[p]->min);
  sp_free(c->a, c->i[p]->max);
  sp_free(c->a, c->i[p]);
  p++;
 }
 sp_free(c->a, c->i);
}

variable_types:
p
unsigned int

return_type: void


original_code:
int sp_catset(spcat *c, sppage *n, sppage **o)
{
 uint32_t i;
 sppage *p = sp_catsearch(c, n, &i);
 if (p) {
  *o = c->i[i];
  c->i[i] = p;
  return 0;
 }
 int rc = sp_catensure(c);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 memmove(&c->i[i + 1], &c->i[i], sizeof(sppage*) * (c->count - i));
 c->i[i] = n;
 c->count++;
 *o = ((void *)0);
 return 0;
}

canonical_original_code:
int sp_catset(struct spcat *c, struct sppage *n, struct sppage **o)
{
 unsigned int i;
 struct sppage *p = sp_catsearch(c, n, &i);
 if (p) {
  *o = c->i[i];
  c->i[i] = p;
  return 0;
 }
 int rc = sp_catensure(c);
 if (__builtin_expect(!! (rc == -1), 0))
  return -1;
 memmove(&c->i[i + 1], &c->i[i], sizeof(struct sppage *) * (c->count - i));
 c->i[i] = n;
 c->count++;
 *o = ((void *)0);
 return 0;
}

variable_types:
n
struct sppage *

variable_types:
o
struct sppage **

variable_types:
i
unsigned int

variable_types: struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; } *min; struct spv *max; struct splist { struct splist *next; } link; } *

variable_types: rc int


original_code:
int sp_catdel(spcat *c, uint32_t idx)
{
 ((void) (0));
 if (__builtin_expect(!! (idx != (uint32_t)(c->count-1)), 1))
  memmove(&c->i[idx], &c->i[idx + 1],
          sizeof(sppage*) * (c->count - idx - 1));
 c->count--;
 return 0;
}

canonical_original_code:
int sp_catdel(struct spcat *c, unsigned int idx)
{
 ((void) (0));
 if (__builtin_expect(!! (idx != (unsigned int)(c->count-1)), 1))
  memmove(&c->i[idx], &c->i[idx + 1],
          sizeof(struct sppage *) * (c->count - idx - 1));
 c->count--;
 return 0;
}

variable_types: struct spcat { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; } *min; struct spv *max; struct splist { struct splist *next; } link; } **i; unsigned int count; unsigned int top; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; } *

variable_types:
idx
unsigned int


original_code:
sppage*
sp_catfind(spcat *c, char *rkey, int size, uint32_t *index)
{
 register int min = 0;
 register int max = c->count - 1;
 while (max >= min) {
  register int mid = min + ((max - min) >> 1);
  switch (cmpkey(c, c->i[mid], rkey, size)) {
  case -1: min = mid + 1;
   continue;
  case 1: max = mid - 1;
   continue;
  default: *index = mid;
   return c->i[mid];
  }
 }
 *index = min;
 return ((void *)0);
}

canonical_original_code:
struct sppage *sp_catfind(struct spcat *c, char *rkey, int size, unsigned int *index)
{
 register int min = 0;
 register int max = c->count - 1;
 while (max >= min) {
  register int mid = min + ((max - min) >> 1);
  switch (cmpkey(c, c->i[mid], rkey, size)) {
  case -1: min = mid + 1;
   continue;
  case 1: max = mid - 1;
   continue;
  default: *index = mid;
   return c->i[mid];
  }
 }
 *index = min;
 return ((void *)0);
}

variable_types: struct spcat { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; struct sppage **i; unsigned int count; unsigned int top; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; } *

variable_types:
rkey
char *

variable_types: size int


original_code:
sppage *sp_catroute(spcat *c, char *rkey, int size, uint32_t *idx)
{
 if (__builtin_expect(!! (c->count == 1), 0))
  return c->i[0];
 uint32_t i;
 sppage *p = sp_catfind(c, rkey, size, &i);
 if (__builtin_expect(!! (p), 1)) {
  *idx = i;
  return p;
 }
 if (__builtin_expect(!! (i >= c->count), 0))
  i = c->count - 1;
 if (i > 0 && c->cmp(c->i[i]->min->key, c->i[i]->min->size,
                     rkey,
                     size, c->cmparg) == 1) {
  i = i - 1;
 }
 if (idx)
  *idx = i;
 return c->i[i];
}

canonical_original_code:
struct sppage *sp_catroute(struct spcat *c, char *rkey, int size, unsigned int *idx)
{
 if (__builtin_expect(!! (c->count == 1), 0))
  return c->i[0];
 unsigned int i;
 struct sppage *p = sp_catfind(c, rkey, size, &i);
 if (__builtin_expect(!! (p), 1)) {
  *idx = i;
  return p;
 }
 if (__builtin_expect(!! (i >= c->count), 0))
  i = c->count - 1;
 if (i > 0 && c->cmp(c->i[i]->min->key, c->i[i]->min->size,
                     rkey,
                     size, c->cmparg) == 1) {
  i = i - 1;
 }
 if (idx)
  *idx = i;
 return c->i[i];
}

variable_types:
idx
unsigned int *


decompiled_code:
__int64 __fastcall sp_catown(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // r13
__int64 result; // rax
__int64 v6; // rdx

v3 = a3 + 11;
result = cmpkey(a1, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2), a3 + 11, *(unsigned __int16 *)(a3 + 8));
if ( !(_DWORD)result )
return 1LL;
if ( (_DWORD)result == 1 )
{
if ( !a2 )
return result;
LABEL_4:
v6 = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (a2 + 1)) + 28LL);
return (*(unsigned int (__fastcall **)(__int64, _QWORD, __int64, _QWORD, _QWORD))(a1 + 24))(
v3,
*(unsigned __int16 *)(a3 + 8),
v6 + 11,
*(unsigned __int16 *)(v6 + 8),
*(_QWORD *)(a1 + 32)) == -1;
}
if ( (_DWORD)result != -1 )
goto LABEL_4;
result = 1LL;
if ( *(_DWORD *)(a1 + 16) - 1 != a2 )
goto LABEL_4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // r13
__int64 result; // rax
__int64 v6; // rdx

v3 = a3 + 11;
result = func0(a1, *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2), a3 + 11, *(unsigned __int16 *)(a3 + 8));
if ( !(_DWORD)result )
return 1LL;
if ( (_DWORD)result == 1 )
{
if ( !a2 )
return result;
LABEL_4:
v6 = *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (a2 + 1)) + 28LL);
return (*(unsigned int (__fastcall **)(__int64, _QWORD, __int64, _QWORD, _QWORD))(a1 + 24))(
v3,
*(unsigned __int16 *)(a3 + 8),
v6 + 11,
*(unsigned __int16 *)(v6 + 8),
*(_QWORD *)(a1 + 32)) == -1;
}
if ( (_DWORD)result != -1 )
goto LABEL_4;
result = 1LL;
if ( *(_DWORD *)(a1 + 16) - 1 != a2 )
goto LABEL_4;
return result;
}

original_code:
int sp_catown(spcat *c, uint32_t idx, spv *v)
{
 register sppage *p = c->i[idx];
 switch (cmpkey(c, p, v->key, v->size)) {
 case 0:
  return 1;
 case -1:
  if (idx == c->count-1)
   return 1;
  break;
 case 1:
  if (idx == 0)
   return 1;
  break;
 }
 if (c->cmp(v->key, v->size,
            c->i[idx + 1]->min->key,
            c->i[idx + 1]->min->size, c->cmparg) == -1)
  return 1;
 return 0;
}

canonical_original_code:
int sp_catown(struct spcat *c, unsigned int idx, struct spv *v)
{
 register struct sppage *p = c->i[idx];
 switch (cmpkey(c, p, v->key, v->size)) {
 case 0:
  return 1;
 case -1:
  if (idx == c->count-1)
   return 1;
  break;
 case 1:
  if (idx == 0)
   return 1;
  break;
 }
 if (c->cmp(v->key, v->size,
            c->i[idx + 1]->min->key,
            c->i[idx + 1]->min->size, c->cmparg) == -1)
  return 1;
 return 0;
}

variable_types:
v
struct spv *


decompiled_code:
__int64 __fastcall sp_listappend(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = *(_QWORD **)(a1 + 8);
*a2 = a1;
a2[1] = v2;
*v2 = a2;
result = *a2;
*(_QWORD *)(*a2 + 8LL) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax
__int64 result; // rax

v2 = *(_QWORD **)(a1 + 8);
*a2 = a1;
a2[1] = v2;
*v2 = a2;
result = *a2;
*(_QWORD *)(*a2 + 8LL) = a2;
return result;
}

original_code:
static inline void
sp_listappend(splist *h, splist *n) {
 n->next = h;
 n->prev = h->prev;
 n->prev->next = n;
 n->next->prev = n;
}

canonical_original_code:
static inline void sp_listappend(struct splist *h, struct splist *n) {
 n->next = h;
 n->prev = h->prev;
 n->prev->next = n;
 n->next->prev = n;
}

variable_types: struct splist { struct splist *next; } *

variable_types:
n
struct splist *


decompiled_code:
__int64 __fastcall sp_repcmp(const void *a1, const void *a2)
{
return **(_DWORD **)a2 < **(_DWORD **)a1 ? 1 : -1;
}

canonical_decompiled_code:
__int64 __fastcall func3(const void *a1, const void *a2)
{
return **(_DWORD **)a2 < **(_DWORD **)a1 ? 1 : -1;
}

original_code:
static inline int sp_repcmp(const void *p1, const void *p2) {
 register const spepoch *a = *(spepoch**)p1;
 register const spepoch *b = *(spepoch**)p2;
 ((void) (0));
 return (a->epoch > b->epoch)? 1: -1;
}

canonical_original_code:
static inline int sp_repcmp(void *p1, void *p2) {
 register struct spepoch *a = *(spepoch**)p1;
 register struct spepoch *b = *(spepoch**)p2;
 ((void) (0));
 return (a->epoch > b->epoch)? 1: -1;
}

variable_types: struct spepoch { unsigned int epoch; unsigned int n; unsigned int ngc; unsigned int nupdate; enum spepochtype { SPUNDEF=0, SPLIVE=1, SPXFER=2, SPDB=3 } type; unsigned int recover; struct spfile { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; } log; unsigned char lock; struct splist { struct splist *next; } pages; struct splist link; } *

user_defined_types: struct spepoch { unsigned int epoch; unsigned int n; unsigned int ngc; unsigned int nupdate; enum spepochtype type; unsigned int recover; struct spfile log; unsigned char lock; struct splist pages; struct splist link; }

user_defined_types: struct spfile { struct spa *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; }


original_code:
void sp_repinit(sprep *r, spa *a) {
 sp_listinit(&r->l);
 r->a = a;
 r->n = 0;
 r->ndb = 0;
 r->nxfer = 0;
 r->epoch = 0;
}

canonical_original_code:
void sp_repinit(struct sprep *r, struct spa *a) {
 sp_listinit(&r->l);
 r->a = a;
 r->n = 0;
 r->ndb = 0;
 r->nxfer = 0;
 r->epoch = 0;
}

variable_types: struct sprep { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; unsigned int epoch; struct splist { struct splist *next; } l; int n; int ndb; int nxfer; } *

variable_types:
a
struct spa *

user_defined_types: struct sprep { struct spa *a; unsigned int epoch; struct splist l; int n; int ndb; int nxfer; }


original_code:
int sp_repprepare(sprep *r) {
 spepoch **a = sp_malloc(r->a, sizeof(spepoch*) * r->n);
 if (__builtin_expect(!! (a == ((void *)0)), 0))
  return -1;
 uint32_t epoch = 0;
 int j = 0;
 splist *i;
 for (i = (&r->l)->next; i != &r->l; i = (i)->next) {
  a[j] = ((spepoch*)((char*)(i) - __builtin_offsetof(spepoch, link)));
  if (a[j]->epoch > epoch)
   epoch = a[j]->epoch;
  j++;
 }
 qsort(a, r->n, sizeof(spepoch*), sp_repcmp);
 sp_listinit(&r->l);
 j = 0;
 while (j < r->n) {
  sp_listinit(&a[j]->link);
  sp_listappend(&r->l, &a[j]->link);
  j++;
 }
 sp_free(r->a, a);
 r->epoch = epoch;
 return 0;
}

canonical_original_code:
int sp_repprepare(struct sprep *r) {
 struct spepoch **a = sp_malloc(r->a, sizeof(spepoch*) * r->n);
 if (__builtin_expect(!! (a == ((void *)0)), 0))
  return -1;
 unsigned int epoch = 0;
 int j = 0;
 struct splist *i;
 for (i = (&r->l)->next; i != &r->l; i = (i)->next) {
  a[j] = ((struct spepoch *)((char *)(i) - __builtin_offsetof(spepoch, link)));
  if (a[j]->epoch > epoch)
   epoch = a[j]->epoch;
  j++;
 }
 qsort(a, r->n, sizeof(struct spepoch *), sp_repcmp);
 sp_listinit(&r->l);
 j = 0;
 while (j < r->n) {
  sp_listinit(&a[j]->link);
  sp_listappend(&r->l, &a[j]->link);
  j++;
 }
 sp_free(r->a, a);
 r->epoch = epoch;
 return 0;
}

variable_types: struct spepoch { unsigned int epoch; unsigned int n; unsigned int ngc; unsigned int nupdate; enum spepochtype { SPUNDEF=0, SPLIVE=1, SPXFER=2, SPDB=3 } type; unsigned int recover; struct spfile { struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; } log; unsigned char lock; struct splist { struct splist *next; } pages; struct splist link; } **

variable_types:
epoch
unsigned int

variable_types: j int


decompiled_code:
__int64 __fastcall sp_repattach(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = sp_listappend(a1 + 16, (_QWORD *)(a2 + 176));
++*(_DWORD *)(v3 + 32);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = func2(a1 + 16, (_QWORD *)(a2 + 176));
++*(_DWORD *)(v3 + 32);
return result;
}

original_code:
void sp_repattach(sprep *r, spepoch *e) {
 sp_listappend(&r->l, &e->link);
 r->n++;
}

canonical_original_code:
void sp_repattach(struct sprep *r, struct spepoch *e) {
 sp_listappend(&r->l, &e->link);
 r->n++;
}

variable_types: struct spepoch { unsigned int epoch; unsigned int n; unsigned int ngc; unsigned int nupdate; enum spepochtype { SPUNDEF=0, SPLIVE=1, SPXFER=2, SPDB=3 } type; unsigned int recover; struct spfile { struct spa *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; } log; unsigned char lock; struct splist pages; struct splist link; } *


original_code:
void sp_repset(sprep *r, spepoch *e, spepochtype t) {
 switch (t) {
 case SPUNDEF:
  if (e->type == SPXFER)
   r->nxfer--;
  else
  if (e->type == SPDB)
   r->ndb--;
  break;
 case SPLIVE:
  ((void) (0));
  break;
 case SPXFER:
  ((void) (0));
  r->nxfer++;
  break;
 case SPDB:
  ((void) (0));
  if (e->type == SPXFER)
   r->nxfer--;
  r->ndb++;
  break;
 }
 e->type = t;
}

canonical_original_code:
void sp_repset(struct sprep *r, struct spepoch *e, enum spepochtype t) {
 switch (t) {
 case SPUNDEF:
  if (e->type == SPXFER)
   r->nxfer--;
  else
  if (e->type == SPDB)
   r->ndb--;
  break;
 case SPLIVE:
  ((void) (0));
  break;
 case SPXFER:
  ((void) (0));
  r->nxfer++;
  break;
 case SPDB:
  ((void) (0));
  if (e->type == SPXFER)
   r->nxfer--;
  r->ndb++;
  break;
 }
 e->type = t;
}

variable_types: enum spepochtype { SPUNDEF=0, SPLIVE=1, SPXFER=2, SPDB=3 }


original_code:
void sp_repdetach(sprep *r, spepoch *e) {
 sp_listunlink(&e->link);
 r->n--;
 sp_repset(r, e, SPUNDEF);
}

canonical_original_code:
void sp_repdetach(struct sprep *r, struct spepoch *e) {
 sp_listunlink(&e->link);
 r->n--;
 sp_repset(r, e, SPUNDEF);
}

user_defined_types: enum spepochtype { SPUNDEF=0, SPLIVE=1, SPXFER=2, SPDB=3 }


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

v2 = *(_QWORD **)(a1 + 8);
*a2 = a1;
a2[1] = v2;
*v2 = a2;
result = *a2;
*(_QWORD *)(*a2 + 8LL) = a2;
return result;
}


decompiled_code:
char __fastcall sp_lock(char *a1)
{
char result; // al
int v2; // ebx

result = *a1;
*a1 = 1;
if ( result )
{
v2 = 0;
while ( 1 )
{
_mm_pause();
if ( !*a1 )
{
result = *a1;
*a1 = 1;
if ( !result )
break;
}
if ( (unsigned int)++v2 > 0x64 )
usleep(0);
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func2(char *a1)
{
char result; // al
int v2; // ebx

result = *a1;
*a1 = 1;
if ( result )
{
v2 = 0;
while ( 1 )
{
_mm_pause();
if ( !*a1 )
{
result = *a1;
*a1 = 1;
if ( !result )
break;
}
if ( (unsigned int)++v2 > 0x64 )
usleep(0);
}
}
return result;
}

original_code:
static inline void
sp_lock(volatile spspinlock *l) {
 if (__sync_lock_test_and_set(l, 1) != 0) {
  unsigned int spin_count = 0U;
  for (;;) {
   __asm__ ("pause");
   if (*l == 0U && __sync_lock_test_and_set(l, 1) == 0)
    break;
   if (++spin_count > 100U)
    usleep(0);
  }
 }
}

canonical_original_code:
static inline void sp_lock(unsigned char *l) {
 if (__sync_lock_test_and_set(l, 1) != 0) {
  unsigned int spin_count = 0U;
  for (;;) {
   __asm__ ("pause");
   if (*l == 0U && __sync_lock_test_and_set(l, 1) == 0)
    break;
   if (++spin_count > 100U)
    usleep(0);
  }
 }
}

variable_types:
l
unsigned char *


original_code:
int sp_gc(sp *s, spepoch *x)
{
 for (;;)
 {
  sp_lock(&s->lockr);
  spepoch *g = sp_repgc(&s->rep, s->env->gcfactor);
  sp_unlock(&s->lockr);
  if (g == ((void *)0))
   break;
  int rc;
  splist *i, *n;
  for (i = (&g->pages)->next; i != &g->pages && (n = i->next); i = n) {
   sppage *p = ((sppage*)((char*)(i) - __builtin_offsetof(sppage, link)));
   sppageh *h = (sppageh*)(g->db.map + p->offset);
   sp_lock(&x->lock);
   rc = sp_mapensure(&x->db, sizeof(sppageh) + h->size, s->env->dbgrow);
   if (__builtin_expect(!! (rc == -1), 0)) {
    sp_unlock(&x->lock);
    return sp_em(s, 8|16, x->epoch, "failed to remap db file");
   }
   sp_unlock(&x->lock);
   memcpy(x->db.map + x->db.used, h, sizeof(sppageh) + h->size);
   sp_lock(&s->locks);
   sp_listunlink(&p->link);
   sp_listappend(&x->pages, &p->link);
   p->epoch = x;
   p->offset = x->db.used;
   sp_unlock(&s->locks);
   sp_mapuse(&x->db, sizeof(sppageh) + h->size);
  }
  rc = sp_mapunlink(&g->db);
  if (__builtin_expect(!! (rc == -1), 0))
   return sp_em(s, 8|16, g->epoch, "failed to unlink db file");
  rc = sp_mapclose(&g->db);
  if (__builtin_expect(!! (rc == -1), 0))
   return sp_em(s, 8|16, g->epoch, "failed to close db file");
  sp_lock(&s->lockr);
  sp_repdetach(&s->rep, g);
  sp_free(&s->a, g);
  sp_unlock(&s->lockr);
 }
 return 0;
}

canonical_original_code:
int sp_gc(struct sp *s, struct spepoch *x)
{
 for (;;)
 {
  sp_lock(&s->lockr);
  struct spepoch *g = sp_repgc(&s->rep, s->env->gcfactor);
  sp_unlock(&s->lockr);
  if (g == ((void *)0))
   break;
  int rc;
  struct splist *i; struct splist *n;
  for (i = (&g->pages)->next; i != &g->pages && (n = i->next); i = n) {
   struct sppage *p = ((sppage*)((char*)(i) - __builtin_offsetof(sppage, link)));
   struct sppageh *h = (sppageh*)(g->db.map + p->offset);
   sp_lock(&x->lock);
   rc = sp_mapensure(&x->db, sizeof(sppageh) + h->size, s->env->dbgrow);
   if (__builtin_expect(!! (rc == -1), 0)) {
    sp_unlock(&x->lock);
    return sp_em(s, 8|16, x->epoch, "failed to remap db file");
   }
   sp_unlock(&x->lock);
   memcpy(x->db.map + x->db.used, h, sizeof(sppageh) + h->size);
   sp_lock(&s->locks);
   sp_listunlink(&p->link);
   sp_listappend(&x->pages, &p->link);
   p->epoch = x;
   p->offset = x->db.used;
   sp_unlock(&s->locks);
   sp_mapuse(&x->db, sizeof(sppageh) + h->size);
  }
  rc = sp_mapunlink(&g->db);
  if (__builtin_expect(!! (rc == -1), 0))
   return sp_em(s, 8|16, g->epoch, "failed to unlink db file");
  rc = sp_mapclose(&g->db);
  if (__builtin_expect(!! (rc == -1), 0))
   return sp_em(s, 8|16, g->epoch, "failed to close db file");
  sp_lock(&s->lockr);
  sp_repdetach(&s->rep, g);
  sp_free(&s->a, g);
  sp_unlock(&s->lockr);
 }
 return 0;
}

variable_types: struct sp { enum spmagic { SPMCUR=357046582, SPMENV=102058036, SPMDB=16695550, SPMNONE=0 } m; struct spenv { enum spmagic { SPMCUR=357046582, SPMENV=102058036, SPMDB=16695550, SPMNONE=0 } m; struct spe { unsigned char lock; int type; int errno_; char e[256]; } e; int inuse; void *(*alloc)(void *ptr, unsigned long size, void *arg); void *allocarg; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; unsigned int flags; char *dir; int merge; unsigned int mergewm; unsigned int page; unsigned int dbnewsize; float dbgrow; int gc; float gcfactor; } *env; struct spa { void *(*alloc)(void *ptr, unsigned long size, void *arg); void *arg; } a; struct sprep { struct spa *a; unsigned int epoch; struct splist { struct splist *next; } l; int n; int ndb; int nxfer; } rep; enum sptxn { SPTSS=0, SPTMS=1 } txn; struct spi { struct spa *a; int pagesize; struct spipage { unsigned short count; struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; } *i[]; } **i; unsigned int itop; unsigned int icount; unsigned int count; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; } *i; struct spi itxn; int iskip; unsigned long psn; struct spcat { struct spa *a; struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv *min; struct spv *max; struct splist link; } **i; unsigned int count; unsigned int top; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; } s; struct spbatch { struct iovec { void *iov_base; unsigned long iov_len; } iov[1024]; int iovc; } lb; int stop; struct sptask { int run; void *arg; unsigned long id; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } l; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } c; } merger; struct sprefset { struct spref { unsigned char type; union { struct spvh { unsigned int crc; unsigned int size; unsigned int voffset; unsigned int vsize; unsigned char flags; char key[]; } *vh; struct spv *v; } v; } *r; int used; int max; } refs; struct spfile { struct spa *a; int creat; unsigned long used; unsigned long size; unsigned long svp; char *file; int fd; char *map; } lockdb; int lockc; unsigned char lockr; unsigned char locks; unsigned char locki; struct spe e; } *

variable_types: struct spepoch { unsigned int epoch; unsigned int n; unsigned int ngc; unsigned int nupdate; enum spepochtype { SPUNDEF=0, SPLIVE=1, SPXFER=2, SPDB=3 } type; unsigned int recover; struct spfile log; unsigned char lock; struct splist pages; struct splist link; } *

variable_types: rc int

variable_types: struct sppage { unsigned long id; unsigned long offset; void *epoch; unsigned int size; struct spv { unsigned int epoch; unsigned int crc; unsigned short size; unsigned char flags; char key[]; } *min; struct spv *max; struct splist { struct splist *next; } link; } *

variable_types: struct sppageh { unsigned int crc; unsigned long id; unsigned short count; unsigned int size; unsigned int bsize; } *

user_defined_types: struct sp { enum spmagic m; struct spenv *env; struct spa a; struct sprep rep; enum sptxn txn; struct spi *i; struct spi itxn; int iskip; unsigned long psn; struct spcat s; struct spbatch lb; int stop; struct sptask merger; struct sprefset refs; struct spfile lockdb; int lockc; unsigned char lockr; unsigned char locks; unsigned char locki; struct spe e; }

user_defined_types: struct spbatch { struct iovec iov[1024]; int iovc; }

user_defined_types: struct sptask { int run; void *arg; unsigned long id; union pthread_mutex_t l; union pthread_cond_t c; }

user_defined_types: struct sprefset { struct spref *r; int used; int max; }

user_defined_types: struct spenv { enum spmagic m; struct spe e; int inuse; void *(*alloc)(void *ptr, unsigned long size, void *arg); void *allocarg; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; unsigned int flags; char *dir; int merge; unsigned int mergewm; unsigned int page; unsigned int dbnewsize; float dbgrow; int gc; float gcfactor; }

user_defined_types: struct spi { struct spa *a; int pagesize; struct spipage **i; unsigned int itop; unsigned int icount; unsigned int count; int (*cmp)(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg); void *cmparg; }

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

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

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

user_defined_types: struct spref { unsigned char type; union { struct spvh *vh; struct spv *v; } v; }

user_defined_types: struct spipage { unsigned short count; struct spv *i[]; }


cmp

decompiled_code:
__int64 __fastcall cmp(_DWORD *a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a3 )
result = *a3 < *a1 ? 1 : -1;
return result;
}

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

result = 0LL;
if ( *a1 != *a3 )
result = *a3 < *a1 ? 1 : -1;
return result;
}

original_code:
static inline int
cmp(char *a, size_t asz, char *b, size_t bsz, void *arg) {
 register uint32_t av = *(uint32_t*)a;
 register uint32_t bv = *(uint32_t*)b;
 if (av == bv)
  return 0;
 return (av > bv) ? 1 : -1;
}

canonical_original_code:
static inline int cmp(char *a, unsigned long asz, char *b, unsigned long bsz, void *arg) {
 register unsigned int av = *(uint32_t*)a;
 register unsigned int bv = *(uint32_t*)b;
 if (av == bv)
  return 0;
 return (av > bv) ? 1 : -1;
}

variable_types:
a
char *

variable_types:
asz
unsigned long

variable_types:
b
char *

variable_types:
bsz
unsigned long

variable_types:
arg
void *

variable_types:
av
unsigned int

variable_types:
bv
unsigned int


decompiled_code:
__int64 limit_key()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12
const char *v5; // rcx
__int64 v6; // rdx
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = sp_env();
if ( !v0 )
{
v5 = "env != NULL";
v6 = 27LL;
goto LABEL_11;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v5 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v6 = 28LL;
LABEL_11:
printf("fail (%s:%d) %s\n", "limit.c", v6, v5);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v5 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v6 = 29LL;
goto LABEL_11;
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v5 = "db != NULL";
v6 = 31LL;
goto LABEL_11;
}
if ( (unsigned int)sp_set(v2, v7, 0x10000LL, v7, 1LL) != -1 )
{
v5 = "sp_set(db, buf, UINT16_MAX + 1, buf, sizeof(buf)) == -1";
v6 = 33LL;
goto LABEL_11;
}
if ( !sp_error(v3) )
{
printf("fail (%s:%d) %s\n", "limit.c", 34LL, "sp_error(db) != NULL");
fflush(0LL);
abort();
}
if ( (unsigned int)sp_destroy(v3) )
{
v5 = "sp_destroy(db) == 0";
v6 = 35LL;
goto LABEL_11;
}
if ( (unsigned int)sp_destroy(v1) )
{
v5 = "sp_destroy(env) == 0";
v6 = 36LL;
goto LABEL_11;
}
return rmrf("./rep");
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12
const char *v5; // rcx
__int64 v6; // rdx
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = sp_env();
if ( !v0 )
{
v5 = "env != NULL";
v6 = 27LL;
goto LABEL_11;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v5 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v6 = 28LL;
LABEL_11:
printf("fail (%s:%d) %s\n", "limit.c", v6, v5);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v5 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v6 = 29LL;
goto LABEL_11;
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v5 = "db != NULL";
v6 = 31LL;
goto LABEL_11;
}
if ( (unsigned int)sp_set(v2, v7, 0x10000LL, v7, 1LL) != -1 )
{
v5 = "sp_set(db, buf, UINT16_MAX + 1, buf, sizeof(buf)) == -1";
v6 = 33LL;
goto LABEL_11;
}
if ( !sp_error(v3) )
{
printf("fail (%s:%d) %s\n", "limit.c", 34LL, "sp_error(db) != NULL");
fflush(0LL);
abort();
}
if ( (unsigned int)sp_destroy(v3) )
{
v5 = "sp_destroy(db) == 0";
v6 = 35LL;
goto LABEL_11;
}
if ( (unsigned int)sp_destroy(v1) )
{
v5 = "sp_destroy(env) == 0";
v6 = 36LL;
goto LABEL_11;
}
return func1("./rep");
}

original_code:
static void
limit_key(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 27, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 28, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 29, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 31, "db != NULL"); fflush(((void *)0)); abort(); } });
 char buf[1];
 ({ if (! (sp_set(db, buf, (65535) + 1, buf, sizeof(buf)) == -1)) { printf("fail (%s:%d) %s\n", "limit.c", 33, "sp_set(db, buf, UINT16_MAX + 1, buf, sizeof(buf)) == -1"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 34, "sp_error(db) != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 35, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 36, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep);
}

canonical_original_code:
static void limit_key() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 27, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 28, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 29, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 31, "db != NULL"); fflush(((void *)0)); abort(); } });
 char buf[1];
 ({ if (! (sp_set(db, buf, (65535) + 1, buf, sizeof(buf)) == -1)) { printf("fail (%s:%d) %s\n", "limit.c", 33, "sp_set(db, buf, UINT16_MAX + 1, buf, sizeof(buf)) == -1"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 34, "sp_error(db) != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 35, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 36, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep);
}

variable_types:
env
void *

variable_types:
db
void *

variable_types:
buf
char [1]


decompiled_code:
__int64 limit_value()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12
const char *v5; // rcx
__int64 v6; // rdx
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = sp_env();
if ( !v0 )
{
v5 = "env != NULL";
v6 = 43LL;
goto LABEL_11;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v5 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v6 = 44LL;
LABEL_11:
printf("fail (%s:%d) %s\n", "limit.c", v6, v5);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v5 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v6 = 45LL;
goto LABEL_11;
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v5 = "db != NULL";
v6 = 47LL;
goto LABEL_11;
}
if ( (unsigned int)sp_set(v2, v7, 1LL, v7, 0x100000000LL) != -1 )
{
v5 = "sp_set(db, buf, sizeof(buf), buf, UINT32_MAX + 1ULL) == -1";
v6 = 49LL;
goto LABEL_11;
}
if ( !sp_error(v3) )
{
printf("fail (%s:%d) %s\n", "limit.c", 50LL, "sp_error(db) != NULL");
fflush(0LL);
abort();
}
if ( (unsigned int)sp_destroy(v3) )
{
v5 = "sp_destroy(db) == 0";
v6 = 51LL;
goto LABEL_11;
}
if ( (unsigned int)sp_destroy(v1) )
{
v5 = "sp_destroy(env) == 0";
v6 = 52LL;
goto LABEL_11;
}
return rmrf("./rep");
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // r12
const char *v5; // rcx
__int64 v6; // rdx
char v7[25]; // [rsp+Fh] [rbp-19h] BYREF

v0 = sp_env();
if ( !v0 )
{
v5 = "env != NULL";
v6 = 43LL;
goto LABEL_11;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v5 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v6 = 44LL;
LABEL_11:
printf("fail (%s:%d) %s\n", "limit.c", v6, v5);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v5 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v6 = 45LL;
goto LABEL_11;
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v5 = "db != NULL";
v6 = 47LL;
goto LABEL_11;
}
if ( (unsigned int)sp_set(v2, v7, 1LL, v7, 0x100000000LL) != -1 )
{
v5 = "sp_set(db, buf, sizeof(buf), buf, UINT32_MAX + 1ULL) == -1";
v6 = 49LL;
goto LABEL_11;
}
if ( !sp_error(v3) )
{
printf("fail (%s:%d) %s\n", "limit.c", 50LL, "sp_error(db) != NULL");
fflush(0LL);
abort();
}
if ( (unsigned int)sp_destroy(v3) )
{
v5 = "sp_destroy(db) == 0";
v6 = 51LL;
goto LABEL_11;
}
if ( (unsigned int)sp_destroy(v1) )
{
v5 = "sp_destroy(env) == 0";
v6 = 52LL;
goto LABEL_11;
}
return func1("./rep");
}

original_code:
static void
limit_value(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 43, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 44, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 45, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 47, "db != NULL"); fflush(((void *)0)); abort(); } });
 char buf[1];
 ({ if (! (sp_set(db, buf, sizeof(buf), buf, (4294967295U) + 1ULL) == -1)) { printf("fail (%s:%d) %s\n", "limit.c", 49, "sp_set(db, buf, sizeof(buf), buf, UINT32_MAX + 1ULL) == -1"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 50, "sp_error(db) != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 51, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 52, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep);
}

canonical_original_code:
static void limit_value() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 43, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 44, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 45, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 47, "db != NULL"); fflush(((void *)0)); abort(); } });
 char buf[1];
 ({ if (! (sp_set(db, buf, sizeof(buf), buf, (4294967295U) + 1ULL) == -1)) { printf("fail (%s:%d) %s\n", "limit.c", 49, "sp_set(db, buf, sizeof(buf), buf, UINT32_MAX + 1ULL) == -1"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 50, "sp_error(db) != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 51, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 52, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 rmrf(dbrep);
}


decompiled_code:
__int64 error_nonfatal()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rbp
__int64 result; // rax
const char *v5; // rcx
__int64 v6; // rdx
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = sp_env();
if ( !v0 )
{
v5 = "env != NULL";
v6 = 59LL;
goto LABEL_15;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v5 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v6 = 60LL;
LABEL_15:
printf("fail (%s:%d) %s\n", "limit.c", v6, v5);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v5 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v6 = 61LL;
goto LABEL_15;
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v5 = "db != NULL";
v6 = 63LL;
goto LABEL_15;
}
v7 = 1;
v8[0] = 1;
if ( (unsigned int)sp_set(v2, &v7, 4LL, v8, 4LL) )
{
v5 = "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0";
v6 = 65LL;
goto LABEL_15;
}
if ( (unsigned int)sp_set(v3, &v7, 0x10000LL, v8, 4LL) != -1 )
{
v5 = "sp_set(db, &k, UINT16_MAX + 1 , &v, sizeof(v)) == -1";
v6 = 66LL;
goto LABEL_15;
}
if ( !sp_error(v3) )
{
printf("fail (%s:%d) %s\n", "limit.c", 67LL, "sp_error(db) != NULL");
fflush(0LL);
abort();
}
if ( (unsigned int)sp_set(v3, &v7, 4LL, v8, 4LL) )
{
v5 = "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0";
v6 = 68LL;
goto LABEL_15;
}
if ( sp_error(v3) )
{
v5 = "sp_error(db) == NULL";
v6 = 69LL;
goto LABEL_15;
}
if ( (unsigned int)sp_destroy(v3) )
{
v5 = "sp_destroy(db) == 0";
v6 = 70LL;
goto LABEL_15;
}
if ( (unsigned int)sp_destroy(v1) )
{
v5 = "sp_destroy(env) == 0";
v6 = 71LL;
goto LABEL_15;
}
result = rmrf("./rep");
if ( (_DWORD)result )
{
v5 = "rmrf(dbrep) == 0";
v6 = 72LL;
goto LABEL_15;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rbp
__int64 result; // rax
const char *v5; // rcx
__int64 v6; // rdx
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = sp_env();
if ( !v0 )
{
v5 = "env != NULL";
v6 = 59LL;
goto LABEL_15;
}
v1 = v0;
if ( (unsigned int)sp_ctl(v0, 0LL, 6LL, "./rep") )
{
v5 = "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0";
v6 = 60LL;
LABEL_15:
printf("fail (%s:%d) %s\n", "limit.c", v6, v5);
fflush(0LL);
abort();
}
if ( (unsigned int)sp_ctl(v1, 2LL, cmp, 0LL) )
{
v5 = "sp_ctl(env, SPCMP, cmp, NULL) == 0";
v6 = 61LL;
goto LABEL_15;
}
v2 = sp_open(v1);
v3 = v2;
if ( !v2 )
{
v5 = "db != NULL";
v6 = 63LL;
goto LABEL_15;
}
v7 = 1;
v8[0] = 1;
if ( (unsigned int)sp_set(v2, &v7, 4LL, v8, 4LL) )
{
v5 = "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0";
v6 = 65LL;
goto LABEL_15;
}
if ( (unsigned int)sp_set(v3, &v7, 0x10000LL, v8, 4LL) != -1 )
{
v5 = "sp_set(db, &k, UINT16_MAX + 1 , &v, sizeof(v)) == -1";
v6 = 66LL;
goto LABEL_15;
}
if ( !sp_error(v3) )
{
printf("fail (%s:%d) %s\n", "limit.c", 67LL, "sp_error(db) != NULL");
fflush(0LL);
abort();
}
if ( (unsigned int)sp_set(v3, &v7, 4LL, v8, 4LL) )
{
v5 = "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0";
v6 = 68LL;
goto LABEL_15;
}
if ( sp_error(v3) )
{
v5 = "sp_error(db) == NULL";
v6 = 69LL;
goto LABEL_15;
}
if ( (unsigned int)sp_destroy(v3) )
{
v5 = "sp_destroy(db) == 0";
v6 = 70LL;
goto LABEL_15;
}
if ( (unsigned int)sp_destroy(v1) )
{
v5 = "sp_destroy(env) == 0";
v6 = 71LL;
goto LABEL_15;
}
result = func1("./rep");
if ( (_DWORD)result )
{
v5 = "rmrf(dbrep) == 0";
v6 = 72LL;
goto LABEL_15;
}
return result;
}

original_code:
static void
error_nonfatal(void) {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 59, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 60, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 61, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 63, "db != NULL"); fflush(((void *)0)); abort(); } });
 uint32_t k = 1, v = 1;
 ({ if (! (sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 65, "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_set(db, &k, (65535) + 1 , &v, sizeof(v)) == -1)) { printf("fail (%s:%d) %s\n", "limit.c", 66, "sp_set(db, &k, UINT16_MAX + 1 , &v, sizeof(v)) == -1"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 67, "sp_error(db) != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 68, "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) == ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 69, "sp_error(db) == NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 70, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 71, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 72, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

canonical_original_code:
static void error_nonfatal() {
 void *env = sp_env();
 ({ if (! (env != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 59, "env != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 60, "sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_ctl(env, SPCMP, cmp, ((void *)0)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 61, "sp_ctl(env, SPCMP, cmp, NULL) == 0"); fflush(((void *)0)); abort(); } });
 void *db = sp_open(env);
 ({ if (! (db != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 63, "db != NULL"); fflush(((void *)0)); abort(); } });
 unsigned int k = 1; unsigned int v = 1;
 ({ if (! (sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 65, "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_set(db, &k, (65535) + 1 , &v, sizeof(v)) == -1)) { printf("fail (%s:%d) %s\n", "limit.c", 66, "sp_set(db, &k, UINT16_MAX + 1 , &v, sizeof(v)) == -1"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) != ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 67, "sp_error(db) != NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 68, "sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_error(db) == ((void *)0))) { printf("fail (%s:%d) %s\n", "limit.c", 69, "sp_error(db) == NULL"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(db) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 70, "sp_destroy(db) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (sp_destroy(env) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 71, "sp_destroy(env) == 0"); fflush(((void *)0)); abort(); } });
 ({ if (! (rmrf(dbrep) == 0)) { printf("fail (%s:%d) %s\n", "limit.c", 72, "rmrf(dbrep) == 0"); fflush(((void *)0)); abort(); } });
}

variable_types:
k
unsigned int

variable_types:
v
unsigned int


decompiled_code:
__int64 __fastcall sp_crc32c(unsigned int a1, char *a2, int a3)
{
int v5; // er9
__int64 v6; // rdx
char v7; // di
int v8; // eax
char v9; // bl
int v10; // eax
char *v11; // r8
unsigned int v12; // edx
unsigned int v13; // ecx
char *v14; // rdx
char v15; // al

v5 = -(int)a2 & 3;
if ( v5 > a3 )
v5 = a3;
if ( v5 > 0 )
{
v6 = 0LL;
do
{
v7 = a2[v6++];
a1 = crc_tableil8_o32[(unsigned __int8)(a1 ^ v7)] ^ (a1 >> 8);
}
while ( v5 > (int)v6 );
a2 += v5;
}
v8 = a3 - v5;
v9 = v8;
v10 = v8 >> 3;
if ( v10 <= 0 )
{
v11 = a2;
}
else
{
v11 = &a2[8 * v10];
do
{
v12 = *((_DWORD *)a2 + 1);
v13 = *(_DWORD *)a2 ^ a1;
a2 += 8;
a1 = crc_tableil8_o80[BYTE1(v13)] ^ crc_tableil8_o40[BYTE2(v12)] ^ crc_tableil8_o48[BYTE1(v12)] ^ crc_tableil8_o64[HIBYTE(v13)] ^ crc_tableil8_o88[(unsigned __int8)v13] ^ crc_tableil8_o32[HIBYTE(v12)] ^ crc_tableil8_o56[(unsigned __int8)v12] ^ crc_tableil8_o72[BYTE2(v13)];
}
while ( a2 != v11 );
}
if ( (v9 & 7) != 0 )
{
v14 = &v11[v9 & 7];
do
{
v15 = *v11++;
a1 = crc_tableil8_o32[(unsigned __int8)(a1 ^ v15)] ^ (a1 >> 8);
}
while ( v11 != v14 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, char *a2, int a3)
{
int v5; // er9
__int64 v6; // rdx
char v7; // di
int v8; // eax
char v9; // bl
int v10; // eax
char *v11; // r8
unsigned int v12; // edx
unsigned int v13; // ecx
char *v14; // rdx
char v15; // al

v5 = -(int)a2 & 3;
if ( v5 > a3 )
v5 = a3;
if ( v5 > 0 )
{
v6 = 0LL;
do
{
v7 = a2[v6++];
a1 = crc_tableil8_o32[(unsigned __int8)(a1 ^ v7)] ^ (a1 >> 8);
}
while ( v5 > (int)v6 );
a2 += v5;
}
v8 = a3 - v5;
v9 = v8;
v10 = v8 >> 3;
if ( v10 <= 0 )
{
v11 = a2;
}
else
{
v11 = &a2[8 * v10];
do
{
v12 = *((_DWORD *)a2 + 1);
v13 = *(_DWORD *)a2 ^ a1;
a2 += 8;
a1 = crc_tableil8_o80[BYTE1(v13)] ^ crc_tableil8_o40[BYTE2(v12)] ^ crc_tableil8_o48[BYTE1(v12)] ^ crc_tableil8_o64[HIBYTE(v13)] ^ crc_tableil8_o88[(unsigned __int8)v13] ^ crc_tableil8_o32[HIBYTE(v12)] ^ crc_tableil8_o56[(unsigned __int8)v12] ^ crc_tableil8_o72[BYTE2(v13)];
}
while ( a2 != v11 );
}
if ( (v9 & 7) != 0 )
{
v14 = &v11[v9 & 7];
do
{
v15 = *v11++;
a1 = crc_tableil8_o32[(unsigned __int8)(a1 ^ v15)] ^ (a1 >> 8);
}
while ( v11 != v14 );
}
return a1;
}

original_code:
uint32_t sp_crc32c(uint32_t crc, const void *buf, int len)
{
 const char *p_buf = (const char*)buf;
 int initial_bytes = (sizeof(int32_t) - (intptr_t)p_buf) & (sizeof(int32_t) - 1);
 if (len < initial_bytes)
  initial_bytes = len;
 int li;
 for (li = 0; li < initial_bytes; li++)
  crc = crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^ (crc >> 8);
 len -= initial_bytes;
 int running_len = len & ~(sizeof(uint64_t) - 1);
 int end_bytes = len - running_len;
 for (li = 0; li < running_len / 8; li++) {
  crc ^= *(uint32_t*)p_buf;
  p_buf += 4;
  uint32_t term1 = crc_tableil8_o88[(crc) & 0x000000FF] ^
                   crc_tableil8_o80[(crc >> 8) & 0x000000FF];
  uint32_t term2 = crc >> 16;
  crc = term1 ^
        crc_tableil8_o72[term2 & 0x000000FF] ^
        crc_tableil8_o64[(term2 >> 8) & 0x000000FF];
  term1 = crc_tableil8_o56[(*(uint32_t*)p_buf) & 0x000000FF] ^
          crc_tableil8_o48[((*(uint32_t*)p_buf) >> 8) & 0x000000FF];
  term2 = (*(uint32_t*)p_buf) >> 16;
  crc = crc ^ term1 ^
        crc_tableil8_o40[term2 & 0x000000FF] ^
        crc_tableil8_o32[(term2 >> 8) & 0x000000FF];
  p_buf += 4;
 }
    for (li = 0; li < end_bytes; li++)
        crc = crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^ (crc >> 8);
    return crc;
}

canonical_original_code:
unsigned int sp_crc32c(unsigned int crc, void *buf, int len)
{
 char *p_buf = (const char*)buf;
 int initial_bytes = (sizeof(int32_t) - (intptr_t)p_buf) & (sizeof(int32_t) - 1);
 if (len < initial_bytes)
  initial_bytes = len;
 int li;
 for (li = 0; li < initial_bytes; li++)
  crc = crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^ (crc >> 8);
 len -= initial_bytes;
 int running_len = len & ~(sizeof(uint64_t) - 1);
 int end_bytes = len - running_len;
 for (li = 0; li < running_len / 8; li++) {
  crc ^= *(unsigned int *)p_buf;
  p_buf += 4;
  unsigned int term1 = crc_tableil8_o88[(crc) & 0x000000FF] ^
                   crc_tableil8_o80[(crc >> 8) & 0x000000FF];
  unsigned int term2 = crc >> 16;
  crc = term1 ^
        crc_tableil8_o72[term2 & 0x000000FF] ^
        crc_tableil8_o64[(term2 >> 8) & 0x000000FF];
  term1 = crc_tableil8_o56[(*(unsigned int *)p_buf) & 0x000000FF] ^
          crc_tableil8_o48[((*(unsigned int *)p_buf) >> 8) & 0x000000FF];
  term2 = (*(unsigned int *)p_buf) >> 16;
  crc = crc ^ term1 ^
        crc_tableil8_o40[term2 & 0x000000FF] ^
        crc_tableil8_o32[(term2 >> 8) & 0x000000FF];
  p_buf += 4;
 }
    for (li = 0; li < end_bytes; li++)
        crc = crc_tableil8_o32[(crc ^ *p_buf++) & 0x000000FF] ^ (crc >> 8);
    return crc;
}

variable_types:
crc
unsigned int

variable_types:
buf
void *

variable_types: len int

variable_types: li int

return_type: unsigned int


canonical_decompiled_code:
char __fastcall func0(char *a1)
{
char result; // al
int v2; // ebx

result = *a1;
*a1 = 1;
if ( result )
{
v2 = 0;
while ( 1 )
{
_mm_pause();
if ( !*a1 )
{
result = *a1;
*a1 = 1;
if ( !result )
break;
}
if ( (unsigned int)++v2 > 0x64 )
usleep(0);
}
}
return result;
}

variable_types:
l
unsigned char *


destroy

decompiled_code:
void destroy()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code: static void destroy(void *arg, small_hash__node *node) {}

canonical_original_code: static void destroy(void *arg, struct small_hash__node *node) {}

variable_types: struct small_hash__node { struct small_hash__node *prev; } *


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "Usage: %s <count>\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return fprintf(stderr, "Usage: %s <count>\n", a1);
}

original_code: static void usage(char *progname) { fprintf(stderr, "Usage: %s <count>\n", progname); }

variable_types:
progname
char *


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

if ( gettimeofday(&v1, 0LL) )
{
perror("gettimeofday");
abort();
}
return v1.tv_usec + 1000000 * v1.tv_sec;
}

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

if ( gettimeofday(&v1, 0LL) )
{
perror("gettimeofday");
abort();
}
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static inline uint64_t get_time_micros() {
    struct timeval tv;
    int rc = gettimeofday(&tv, ((void *)0));
    if(0 != rc) {
        perror("gettimeofday");
        abort();
    }
    return tv.tv_sec * 1000000 + tv.tv_usec;
}

canonical_original_code:
static inline unsigned long get_time_micros() {
    struct timeval tv;
    int rc = gettimeofday(&tv, ((void *)0));
    if(0 != rc) {
        perror("gettimeofday");
        abort();
    }
    return tv.tv_sec * 1000000 + tv.tv_usec;
}

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

variable_types: rc int

return_type: unsigned long


decompiled_code:
__int64 __fastcall by_name__hash_name(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 74565; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 33 * i;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 74565; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 33 * i;
}
return i;
}

original_code:
static small_hash__hash by_name__hash_name(const char *name)
{
    small_hash__hash result = 0x12345;
    const char *p;
    for(p = name; *p; p++) {
        result *= 33;
        result += *p;
    }
    return result;
}

canonical_original_code:
static unsigned int by_name__hash_name(char *name)
{
    unsigned int result = 0x12345;
    char *p;
    for(p = name; *p; p++) {
        result *= 33;
        result += *p;
    }
    return result;
}

variable_types:
name
char *

variable_types:
result
unsigned int

variable_types:
p
char *


decompiled_code:
__int64 __fastcall by_age__hash_age(unsigned int a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return a1;
}

original_code:
static small_hash__hash by_age__hash_age(unsigned age)
{
    return age;
}

canonical_original_code:
static unsigned int by_age__hash_age(unsigned int age)
{
    return age;
}

variable_types:
age
unsigned int


decompiled_code:
__int64 __fastcall users__init(__int64 a1)
{
small_hash__table__init_dynamic(a1, &by_name_funcs, 0LL, 2LL);
return small_hash__table__init_dynamic(a1 + 64, &by_age_funcs, 0LL, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
small_hash__table__init_dynamic(a1, &by_name_funcs, 0LL, 2LL);
return small_hash__table__init_dynamic(a1 + 64, &by_age_funcs, 0LL, 2LL);
}

original_code:
static void users__init(struct users *users)
{
    small_hash__table__init_dynamic(
        &users->by_name_table,
        &by_name_funcs, ((void *)0), 2);
    small_hash__table__init_dynamic(
        &users->by_age_table,
        &by_age_funcs, ((void *)0), 2);
}

variable_types: struct users { struct small_hash__table { struct small_hash__funcs { _Bool (*match_key)(void *user_arg, void *key, struct small_hash__node { struct small_hash__node *prev; } *); unsigned int (*get_hash)(void *user_arg, struct small_hash__node *); } *user_funcs; void *user_arg; unsigned int count; _Bool is_dynamic; unsigned int min_anchors_count; unsigned int low_watermark; unsigned int high_watermark; unsigned int expensive_lookup_count; unsigned int lookup_count; unsigned int anchors_count; struct small_hash__anchor { struct small_hash__node *first; } *anchors; unsigned int prevent_resizes_count; } by_name_table; struct small_hash__table by_age_table; } *

user_defined_types: struct users { struct small_hash__table by_name_table; struct small_hash__table by_age_table; }

user_defined_types: struct small_hash__table { struct small_hash__funcs *user_funcs; void *user_arg; unsigned int count; _Bool is_dynamic; unsigned int min_anchors_count; unsigned int low_watermark; unsigned int high_watermark; unsigned int expensive_lookup_count; unsigned int lookup_count; unsigned int anchors_count; struct small_hash__anchor *anchors; unsigned int prevent_resizes_count; }

user_defined_types: struct small_hash__funcs { _Bool (*match_key)(void *user_arg, void *key, struct small_hash__node *); unsigned int (*get_hash)(void *user_arg, struct small_hash__node *); }


decompiled_code:
__int64 __fastcall users__add(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
__int64 v4; // rdx

v2 = by_name__hash_name(*(_BYTE **)a2);
small_hash__table__add(a1, v2, a2 + 16);
v3 = by_age__hash_age(*(_DWORD *)(a2 + 8));
return small_hash__table__add(a1 + 64, v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
__int64 v4; // rdx

v2 = func0(*(_BYTE **)a2);
small_hash__table__add(a1, v2, a2 + 16);
v3 = func3(*(_DWORD *)(a2 + 8));
return small_hash__table__add(a1 + 64, v3, v4);
}

original_code:
static void users__add(struct users *users, struct user *u)
{
    small_hash__table__add(&users->by_name_table, by_name__hash_name(u->name), &u->by_name_node);
    small_hash__table__add(&users->by_age_table, by_age__hash_age(u->age), &u->by_age_node);
}

variable_types: struct user { char *name; unsigned int age; struct small_hash__node by_name_node; struct small_hash__node by_age_node; } *

user_defined_types: struct small_hash__anchor { struct small_hash__node *first; }

user_defined_types: struct small_hash__node { struct small_hash__node *prev; }


decompiled_code:
__int64 __fastcall users__del(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
__int64 v4; // rdx

v2 = by_name__hash_name(*(_BYTE **)a2);
small_hash__table__del(a1, v2, a2 + 16);
v3 = by_age__hash_age(*(_DWORD *)(a2 + 8));
return small_hash__table__del(a1 + 64, v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
unsigned int v3; // eax
__int64 v4; // rdx

v2 = func0(*(_BYTE **)a2);
small_hash__table__del(a1, v2, a2 + 16);
v3 = func3(*(_DWORD *)(a2 + 8));
return small_hash__table__del(a1 + 64, v3, v4);
}

original_code:
static void users__del(struct users *users, struct user *u)
{
    small_hash__table__del(&users->by_name_table, by_name__hash_name(u->name), &u->by_name_node);
    small_hash__table__del(&users->by_age_table, by_age__hash_age(u->age), &u->by_age_node);
}

user_defined_types: struct user { char *name; unsigned int age; struct small_hash__node by_name_node; struct small_hash__node by_age_node; }


decompiled_code:
__int64 __fastcall users__fini(__int64 a1)
{
((void (*)(void))small_hash__table__fini)();
return small_hash__table__fini(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
((void (*)(void))small_hash__table__fini)();
return small_hash__table__fini(a1 + 64);
}

original_code:
static void users__fini(struct users *users)
{
    small_hash__table__fini(&users->by_name_table);
    small_hash__table__fini(&users->by_age_table);
}


original_code:
static void init_internal(
    small_hash__table *table,
    struct small_hash__funcs *user_funcs, void *user_arg,
    unsigned anchors_count,
    small_hash__anchor anchors[],
    _Bool is_dynamic)
{
    table->user_funcs = user_funcs;
    table->user_arg = user_arg;
    table->is_dynamic = is_dynamic;
    table->anchors_count = anchors_count;
    table->anchors = anchors;
    table->count = 0;
    table->expensive_lookup_count = 0;
    table->lookup_count = 0;
    table->prevent_resizes_count = 0;
}

canonical_original_code:
static void init_internal(struct small_hash__table *table, struct small_hash__funcs *user_funcs, void *user_arg, unsigned int anchors_count, struct small_hash__anchor anchors[], _Bool is_dynamic)
{
    table->user_funcs = user_funcs;
    table->user_arg = user_arg;
    table->is_dynamic = is_dynamic;
    table->anchors_count = anchors_count;
    table->anchors = anchors;
    table->count = 0;
    table->expensive_lookup_count = 0;
    table->lookup_count = 0;
    table->prevent_resizes_count = 0;
}

variable_types: struct small_hash__table { struct small_hash__funcs { _Bool (*match_key)(void *user_arg, void *key, struct small_hash__node { struct small_hash__node *prev; } *); unsigned int (*get_hash)(void *user_arg, struct small_hash__node *); } *user_funcs; void *user_arg; unsigned int count; _Bool is_dynamic; unsigned int min_anchors_count; unsigned int low_watermark; unsigned int high_watermark; unsigned int expensive_lookup_count; unsigned int lookup_count; unsigned int anchors_count; struct small_hash__anchor { struct small_hash__node *first; } *anchors; unsigned int prevent_resizes_count; } *

variable_types:
anchors
struct small_hash__anchor []


decompiled_code:
void *__fastcall alloc_anchors(unsigned int a1)
{
return calloc(8LL * a1, 1uLL);
}

canonical_decompiled_code:
void *__fastcall func2(unsigned int a1)
{
return calloc(8LL * a1, 1uLL);
}

original_code:
static small_hash__anchor *alloc_anchors(unsigned count)
{
    small_hash__anchor *anchors = malloc(count * sizeof *anchors);
    memset(anchors, 0, count * sizeof *anchors);
    return anchors;
}

canonical_original_code:
static struct small_hash__anchor *alloc_anchors(unsigned int count)
{
    struct small_hash__anchor *anchors = malloc(count * sizeof *anchors);
    memset(anchors, 0, count * sizeof *anchors);
    return anchors;
}

variable_types:
count
unsigned int

variable_types: struct small_hash__anchor { struct small_hash__node { struct small_hash__node *prev; } *first; } *


decompiled_code:
void __fastcall report_lookup(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // edx

if ( *(_BYTE *)(a1 + 20) )
{
if ( !*(_DWORD *)(a1 + 56) )
{
v2 = *(_DWORD *)(a1 + 16);
if ( v2 > *(_DWORD *)(a1 + 32) && a2 > 6 )
{
v3 = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = v3;
if ( v3 > 1 )
{
if ( *(_DWORD *)(a1 + 24) >= v2 / 5 )
_assert_fail("new_anchors_count > table->min_anchors_count", "small_hash.c", 0xC5u, "report_lookup");
rehash((_DWORD *)a1, v2 / 5);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int v3; // edx

if ( *(_BYTE *)(a1 + 20) )
{
if ( !*(_DWORD *)(a1 + 56) )
{
v2 = *(_DWORD *)(a1 + 16);
if ( v2 > *(_DWORD *)(a1 + 32) && a2 > 6 )
{
v3 = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = v3;
if ( v3 > 1 )
{
if ( *(_DWORD *)(a1 + 24) >= v2 / 5 )
_assert_fail("new_anchors_count > table->min_anchors_count", "small_hash.c", 0xC5u, "report_lookup");
func3((_DWORD *)a1, v2 / 5);
}
}
}
}
}

original_code:
static inline void report_lookup(small_hash__table *table, unsigned lookup_cost)
{
    if(!table->is_dynamic || 0 != table->prevent_resizes_count) return;
    if(table->count <= table->high_watermark) return;
    if(lookup_cost < 7) return;
    table->expensive_lookup_count++;
    if(table->expensive_lookup_count < 2) return;
    unsigned new_anchors_count = table->count / 5;
    ((void) sizeof ((new_anchors_count > table->min_anchors_count) ? 1 : 0), __extension__ ({ if (new_anchors_count > table->min_anchors_count) ; else __assert_fail ("new_anchors_count > table->min_anchors_count", "small_hash.c", 197, __extension__ __PRETTY_FUNCTION__); }));
    rehash(table, new_anchors_count);
}

canonical_original_code:
static inline void report_lookup(struct small_hash__table *table, unsigned int lookup_cost)
{
    if(!table->is_dynamic || 0 != table->prevent_resizes_count) return;
    if(table->count <= table->high_watermark) return;
    if(lookup_cost < 7) return;
    table->expensive_lookup_count++;
    if(table->expensive_lookup_count < 2) return;
    unsigned int new_anchors_count = table->count / 5;
    ((void) sizeof ((new_anchors_count > table->min_anchors_count) ? 1 : 0), __extension__ ({ if (new_anchors_count > table->min_anchors_count) ; else __assert_fail ("new_anchors_count > table->min_anchors_count", "small_hash.c", 197, __extension__ __PRETTY_FUNCTION__); }));
    rehash(table, new_anchors_count);
}


decompiled_code:
__int64 __fastcall find_and_report(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // er13
__int64 i; // r12

v3 = 0;
for ( i = *(_QWORD *)anchor_of_hash_isra_0(*(_DWORD *)(a1 + 44), *(_QWORD *)(a1 + 48), a2); i; i = *(_QWORD *)(i + 8) )
{
++v3;
if ( (**(unsigned __int8 (__fastcall ***)(_QWORD, __int64, __int64))a1)(*(_QWORD *)(a1 + 8), a3, i) )
break;
}
report_lookup(a1, v3);
return i;
}

original_code:
static inline small_hash__node *find_and_report(
    small_hash__table *table,
    small_hash__hash hash, const void *key)
{
    small_hash__anchor *anchor = anchor_of_hash(table, hash);
    small_hash__node *node;
    unsigned lookup_cost = 0;
    for(node = anchor->first; node; node = node->next) {
        lookup_cost++;
        if(table->user_funcs->match_key(table->user_arg, key, node)) {
            break;
        }
    }
    report_lookup(table, lookup_cost);
    return node;
}

canonical_original_code:
static inline struct small_hash__node *find_and_report(struct small_hash__table *table, unsigned int hash, void *key)
{
    struct small_hash__anchor *anchor = anchor_of_hash(table, hash);
    struct small_hash__node *node;
    unsigned int lookup_cost = 0;
    for(node = anchor->first; node; node = node->next) {
        lookup_cost++;
        if(table->user_funcs->match_key(table->user_arg, key, node)) {
            break;
        }
    }
    report_lookup(table, lookup_cost);
    return node;
}

variable_types: struct small_hash__table { struct small_hash__funcs { _Bool (*match_key)(void *user_arg, void *key, struct small_hash__node *); unsigned int (*get_hash)(void *user_arg, struct small_hash__node *); } *user_funcs; void *user_arg; unsigned int count; _Bool is_dynamic; unsigned int min_anchors_count; unsigned int low_watermark; unsigned int high_watermark; unsigned int expensive_lookup_count; unsigned int lookup_count; unsigned int anchors_count; struct small_hash__anchor { struct small_hash__node *first; } *anchors; unsigned int prevent_resizes_count; } *

variable_types:
hash
unsigned int

variable_types:
key
void *

return_type: struct small_hash__node { struct small_hash__node *prev; } *


find

decompiled_code:
__int64 __fastcall find(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v4; // r12

v4 = *(_QWORD *)anchor_of_hash_isra_0(*(_DWORD *)(a1 + 44), *(_QWORD *)(a1 + 48), a2);
if ( !v4 )
return 0LL;
while ( !(**(unsigned __int8 (__fastcall ***)(_QWORD, __int64, __int64))a1)(*(_QWORD *)(a1 + 8), a3, v4) )
{
v4 = *(_QWORD *)(v4 + 8);
if ( !v4 )
return 0LL;
}
return v4;
}

original_code:
static inline small_hash__node *find(
    small_hash__table *table, small_hash__hash hash, const void *key)
{
    small_hash__anchor *anchor = anchor_of_hash(table, hash);
    small_hash__node *node;
    for(node = anchor->first; node; node = node->next) {
        if(table->user_funcs->match_key(table->user_arg, key, node)) {
            return node;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static inline struct small_hash__node *find(struct small_hash__table *table, unsigned int hash, void *key)
{
    struct small_hash__anchor *anchor = anchor_of_hash(table, hash);
    struct small_hash__node *node;
    for(node = anchor->first; node; node = node->next) {
        if(table->user_funcs->match_key(table->user_arg, key, node)) {
            return node;
        }
    }
    return ((void *)0);
}

variable_types: struct small_hash__node { struct small_hash__node *prev; } *


decompiled_code:
void __fastcall small_hash__table__fini(__int64 a1)
{
if ( *(_DWORD *)(a1 + 56) )
_assert_fail("0 == table->prevent_resizes_count", "small_hash.c", 0x52u, "small_hash__table__fini");
if ( *(_BYTE *)(a1 + 20) )
{
free(*(void **)(a1 + 48));
*(_QWORD *)(a1 + 48) = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
if ( *(_DWORD *)(a1 + 56) )
_assert_fail("0 == table->prevent_resizes_count", "small_hash.c", 0x52u, "small_hash__table__fini");
if ( *(_BYTE *)(a1 + 20) )
{
free(*(void **)(a1 + 48));
*(_QWORD *)(a1 + 48) = 0LL;
}
}

original_code:
void small_hash__table__fini(small_hash__table *table)
{
    ((void) sizeof ((0 == table->prevent_resizes_count) ? 1 : 0), __extension__ ({ if (0 == table->prevent_resizes_count) ; else __assert_fail ("0 == table->prevent_resizes_count", "small_hash.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    if(table->is_dynamic) {
        free(table->anchors);
        table->anchors = ((void *)0);
    }
}

canonical_original_code:
void small_hash__table__fini(struct small_hash__table *table)
{
    ((void) sizeof ((0 == table->prevent_resizes_count) ? 1 : 0), __extension__ ({ if (0 == table->prevent_resizes_count) ; else __assert_fail ("0 == table->prevent_resizes_count", "small_hash.c", 82, __extension__ __PRETTY_FUNCTION__); }));
    if(table->is_dynamic) {
        free(table->anchors);
        table->anchors = ((void *)0);
    }
}


decompiled_code:
void __fastcall small_hash__table__fini_destroy(__int64 a1, void (__fastcall *a2)(__int64), __int64 a3)
{
unsigned int v5; // ecx
unsigned int v6; // ebx
char v7; // di
__int64 v8; // rax

v5 = *(_DWORD *)(a1 + 44);
do
{
if ( !v5 )
break;
v6 = 0;
v7 = 1;
do
{
v8 = *(_QWORD *)(a1 + 48) + 8LL * v6;
if ( *(_QWORD *)v8 )
{
*(_QWORD *)v8 = *(_QWORD *)(*(_QWORD *)v8 + 8LL);
a2(a3);
v5 = *(_DWORD *)(a1 + 44);
v7 = 0;
}
++v6;
}
while ( v5 > v6 );
}
while ( !v7 );
small_hash__table__fini(a1);
}

original_code:
void small_hash__table__fini_destroy(
    small_hash__table *table,
    void (*free_node)(void *, small_hash__node *), void *arg)
{
    while(1) {
        _Bool empty = 1;
        unsigned i;
        for(i = 0; i < table->anchors_count; i++) {
            small_hash__node *first = table->anchors[i].first;
            if(!first) continue;
            empty = 0;
            table->anchors[i].first = first->next;
            free_node(arg, first);
        }
        if(empty) break;
    }
    small_hash__table__fini(table);
}

canonical_original_code:
void small_hash__table__fini_destroy(struct small_hash__table *table, void (*free_node)(void *, struct small_hash__node *), void *arg)
{
    while(1) {
        _Bool empty = 1;
        unsigned int i;
        for(i = 0; i < table->anchors_count; i++) {
            struct small_hash__node *first = table->anchors[i].first;
            if(!first) continue;
            empty = 0;
            table->anchors[i].first = first->next;
            free_node(arg, first);
        }
        if(empty) break;
    }
    small_hash__table__fini(table);
}

variable_types: void (*)(void *, struct small_hash__node *)

variable_types:
arg
void *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall small_hash__table__find(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // eax

if ( !*(_BYTE *)(a1 + 20) || *(_DWORD *)(a1 + 56) )
return find(a1, a2, a3);
v3 = *(_DWORD *)(a1 + 40) + 1;
if ( v3 <= 9 )
{
*(_DWORD *)(a1 + 40) = v3;
return find(a1, a2, a3);
}
*(_DWORD *)(a1 + 40) = 0;
return find_and_report(a1, a2, a3);
}

original_code:
small_hash__node *small_hash__table__find(
    small_hash__table *table,
    small_hash__hash hash, const void *key)
{
    if(table->is_dynamic && 0 == table->prevent_resizes_count &&
       ++table->lookup_count >= 10)
    {
        table->lookup_count = 0;
        return find_and_report(table, hash, key);
    }
    return find(table, hash, key);
}

canonical_original_code:
struct small_hash__node *small_hash__table__find(struct small_hash__table *table, unsigned int hash, void *key)
{
    if(table->is_dynamic && 0 == table->prevent_resizes_count &&
       ++table->lookup_count >= 10)
    {
        table->lookup_count = 0;
        return find_and_report(table, hash, key);
    }
    return find(table, hash, key);
}


original_code:
void small_hash__iter__init(small_hash__table *table, small_hash__iter *iter)
{
    table->prevent_resizes_count++;
    iter->next_anchor_index = 0;
    iter->next = ((void *)0);
}

canonical_original_code:
void small_hash__iter__init(struct small_hash__table *table, struct small_hash__iter *iter)
{
    table->prevent_resizes_count++;
    iter->next_anchor_index = 0;
    iter->next = ((void *)0);
}

variable_types: struct small_hash__iter { unsigned int next_anchor_index; struct small_hash__node *next; } *


decompiled_code:
__int64 __fastcall small_hash__iter__fini(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 56);
if ( !v1 )
_assert_fail("table->prevent_resizes_count > 0", "small_hash.c", 0x11Au, "small_hash__iter__fini");
result = (unsigned int)(v1 - 1);
*(_DWORD *)(a1 + 56) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 56);
if ( !v1 )
_assert_fail("table->prevent_resizes_count > 0", "small_hash.c", 0x11Au, "small_hash__iter__fini");
result = (unsigned int)(v1 - 1);
*(_DWORD *)(a1 + 56) = result;
return result;
}

original_code:
void small_hash__iter__fini(small_hash__table *table, small_hash__iter *iter)
{
    ((void) sizeof ((table->prevent_resizes_count > 0) ? 1 : 0), __extension__ ({ if (table->prevent_resizes_count > 0) ; else __assert_fail ("table->prevent_resizes_count > 0", "small_hash.c", 282, __extension__ __PRETTY_FUNCTION__); }));
    table->prevent_resizes_count--;
}

canonical_original_code:
void small_hash__iter__fini(struct small_hash__table *table, struct small_hash__iter *iter)
{
    ((void) sizeof ((table->prevent_resizes_count > 0) ? 1 : 0), __extension__ ({ if (table->prevent_resizes_count > 0) ; else __assert_fail ("table->prevent_resizes_count > 0", "small_hash.c", 282, __extension__ __PRETTY_FUNCTION__); }));
    table->prevent_resizes_count--;
}

user_defined_types: struct small_hash__iter { unsigned int next_anchor_index; struct small_hash__node *next; }


decompiled_code:
__int64 __fastcall small_hash__iter__next(__int64 a1, unsigned int *a2)
{
__int64 v2; // r12
__int64 result; // rax
unsigned int v4; // eax
unsigned int v6; // edi
__int64 *v7; // rdx
__int64 v8; // rcx

v2 = *((_QWORD *)a2 + 1);
if ( v2 )
{
*((_QWORD *)a2 + 1) = *(_QWORD *)(v2 + 8);
return v2;
}
v4 = *a2;
if ( *a2 == -1 )
return v2;
v6 = *(_DWORD *)(a1 + 44);
if ( v4 >= v6 )
{
LABEL_10:
*a2 = -1;
small_hash__iter__fini(a1);
result = 0LL;
}
else
{
v7 = (__int64 *)(*(_QWORD *)(a1 + 48) + 8LL * v4);
while ( 1 )
{
v8 = *v7;
++v4;
if ( *v7 )
break;
++v7;
if ( v6 == v4 )
goto LABEL_10;
}
*a2 = v4;
*((_QWORD *)a2 + 1) = *(_QWORD *)(v8 + 8);
result = v8;
}
return result;
}

original_code:
small_hash__node *small_hash__iter__next(small_hash__table *table, small_hash__iter *iter)
{
    small_hash__node *next = iter->next;
    if(next) {
        iter->next = next->next;
        return next;
    }
    if(-1U == iter->next_anchor_index) return ((void *)0);
    unsigned i;
    for(i = iter->next_anchor_index; i < table->anchors_count; i++) {
        small_hash__node *first = table->anchors[i].first;
        if(first) {
            iter->next_anchor_index = i+1;
            iter->next = first->next;
            return first;
        }
    }
    iter->next = ((void *)0);
    iter->next_anchor_index = -1U;
    small_hash__iter__fini(table, iter);
    return ((void *)0);
}

canonical_original_code:
struct small_hash__node *small_hash__iter__next(struct small_hash__table *table, struct small_hash__iter *iter)
{
    struct small_hash__node *next = iter->next;
    if(next) {
        iter->next = next->next;
        return next;
    }
    if(-1U == iter->next_anchor_index) return ((void *)0);
    unsigned int i;
    for(i = iter->next_anchor_index; i < table->anchors_count; i++) {
        struct small_hash__node *first = table->anchors[i].first;
        if(first) {
            iter->next_anchor_index = i+1;
            iter->next = first->next;
            return first;
        }
    }
    iter->next = ((void *)0);
    iter->next_anchor_index = -1U;
    small_hash__iter__fini(table, iter);
    return ((void *)0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
unsigned int v5; // [rsp+4h] [rbp-14h] BYREF
__int64 v6; // [rsp+8h] [rbp-10h] BYREF

v3 = argv[1];
v6 = 0LL;
v5 = 0;
lecture(v3, &v6, &v5);
printf("capacite : %i\n", v5);
return 0;
}

original_code:
int main (int argc, char *argv[]) {
objet *tabObjets = ((void *)0);
int capacite = 0;
char *filename = argv[1];
lecture(filename, &tabObjets, &capacite);
printf("capacite : %i\n", capacite);
}

canonical_original_code:
int main(int argc, char *argv[]) {
struct objet *tabObjets = ((void *)0);
int capacite = 0;
char *filename = argv[1];
lecture(filename, &tabObjets, &capacite);
printf("capacite : %i\n", capacite);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct objet { int numero; int poids; int gain; float ratio; } *

variable_types: capacite int

variable_types:
filename
char *


crosstrap

repo: PegasusEpsilon/complexfractals

original_code:
double crosstrap (COMPLEX *const z, COMPLEX *const c, void *data) {
 unsigned long long i, deadline;
 double d = (double)((unsigned long long)-1);
 COMPLEX z2, oz;
 TRAP *trap;
 trap = (TRAP *)data;
 for (
  i = 0, deadline = 1,
  oz.R = oz.I = 100;
  i != (unsigned long long)-1; i++
 ) {
  z2.R = z->R * z->R;
  z2.I = z->I * z->I;
  if (z2.R + z2.I > 16*16) break;
  z->I = 2 * z->R * z->I + c->I;
  z->R = z2.R - z2.I + c->R;
  if (i > trap->start) {
   double v, h, n;
   v = fabs(trap->sin * z->R + trap->cos * z->I);
   h = fabs(trap->cos * z->R - trap->sin * z->I);
   n = (h < v ? h : v) / trap->hyp;
   if (n < d) d = n;
  }
  if (oz.R == z->R && oz.I == z->I) return d / 2;
  if (i > deadline) { oz.R = z->R; oz.I = z->I; deadline <<= 1; }
 }
 maxiter = maxiter < i ? i : maxiter;
 return trap->dist < d ? -1 : trap->dist - d;
}

canonical_original_code:
double crosstrap(struct COMPLEX *z, struct COMPLEX *c, void *data) {
 unsigned long long i; unsigned long long deadline;
 double d = (double)((unsigned long long)-1);
 struct COMPLEX z2; struct COMPLEX oz;
 struct TRAP *trap;
 trap = (struct TRAP *)data;
 for (
  i = 0, deadline = 1,
  oz.R = oz.I = 100;
  i != (unsigned long long)-1; i++
 ) {
  z2.R = z->R * z->R;
  z2.I = z->I * z->I;
  if (z2.R + z2.I > 16*16) break;
  z->I = 2 * z->R * z->I + c->I;
  z->R = z2.R - z2.I + c->R;
  if (i > trap->start) {
   double v; double h; double n;
   v = fabs(trap->sin * z->R + trap->cos * z->I);
   h = fabs(trap->cos * z->R - trap->sin * z->I);
   n = (h < v ? h : v) / trap->hyp;
   if (n < d) d = n;
  }
  if (oz.R == z->R && oz.I == z->I) return d / 2;
  if (i > deadline) { oz.R = z->R; oz.I = z->I; deadline <<= 1; }
 }
 maxiter = maxiter < i ? i : maxiter;
 return trap->dist < d ? -1 : trap->dist - d;
}

variable_types: struct COMPLEX { double R; double I; } *

variable_types:
c
struct COMPLEX *

variable_types:
data
void *

variable_types:
i
unsigned long long

variable_types:
deadline
unsigned long long

variable_types: d double

variable_types:
oz
struct COMPLEX { double R; double I; }

variable_types: struct TRAP { double angle; unsigned int start; } *

variable_types: v double

variable_types: h double

variable_types: n double

return_type: double


renormalized

decompiled_code:
void __fastcall renormalized(double *a1, double *a2)
{
double v2; // xmm5_8
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rax
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm7_8
double v8; // xmm3_8
double v9; // xmm4_8
double v10; // xmm0_8

v2 = *(double *)&LC0;
v3 = 1LL;
v4 = 0LL;
v5 = *a1;
v6 = a1[1];
v7 = *(double *)&LC0;
do
{
v8 = v6 * v6;
v9 = v5 * v5 + v6 * v6;
if ( v9 > 256.0 )
break;
v6 = v6 * (v5 + v5) + a2[1];
v5 = *a2 + v5 * v5 - v8;
a1[1] = v6;
*a1 = v5;
if ( v6 == v2 && v5 == v7 )
return;
if ( v4 > v3 )
{
v3 *= 2LL;
v2 = v6;
v7 = v5;
}
++v4;
}
while ( v4 != -1LL );
if ( maxiter >= v4 )
v4 = maxiter;
maxiter = v4;
v10 = log(v9);
log2(v10 * 0.5);
}

canonical_decompiled_code:
void __fastcall func1(double *a1, double *a2)
{
double v2; // xmm5_8
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rax
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm7_8
double v8; // xmm3_8
double v9; // xmm4_8
double v10; // xmm0_8

v2 = *(double *)&LC0;
v3 = 1LL;
v4 = 0LL;
v5 = *a1;
v6 = a1[1];
v7 = *(double *)&LC0;
do
{
v8 = v6 * v6;
v9 = v5 * v5 + v6 * v6;
if ( v9 > 256.0 )
break;
v6 = v6 * (v5 + v5) + a2[1];
v5 = *a2 + v5 * v5 - v8;
a1[1] = v6;
*a1 = v5;
if ( v6 == v2 && v5 == v7 )
return;
if ( v4 > v3 )
{
v3 *= 2LL;
v2 = v6;
v7 = v5;
}
++v4;
}
while ( v4 != -1LL );
if ( maxiter >= v4 )
v4 = maxiter;
maxiter = v4;
v10 = log(v9);
log2(v10 * 0.5);
}

original_code:
double renormalized (COMPLEX *const z, COMPLEX *const c, void *data) {
 unsigned long long i, deadline;
 COMPLEX z2, oz;
 for (
  i = 0, deadline = 1,
  oz.R = oz.I = 100;
  i != (unsigned long long)-1; i++
 ) {
  z2.R = z->R * z->R;
  z2.I = z->I * z->I;
  if (z2.R + z2.I > 16*16) break;
  z->I = 2 * z->R * z->I + c->I;
  z->R = z2.R - z2.I + c->R;
  if (oz.R == z->R && oz.I == z->I) return -1;
  if (i > deadline) { oz.R = z->R; oz.I = z->I; deadline <<= 1; }
 }
 maxiter = maxiter < i ? i : maxiter;
 return (double)i - log2(log(z2.R + z2.I) / 2);
}

canonical_original_code:
double renormalized(struct COMPLEX *z, struct COMPLEX *c, void *data) {
 unsigned long long i; unsigned long long deadline;
 struct COMPLEX z2; struct COMPLEX oz;
 for (
  i = 0, deadline = 1,
  oz.R = oz.I = 100;
  i != (unsigned long long)-1; i++
 ) {
  z2.R = z->R * z->R;
  z2.I = z->I * z->I;
  if (z2.R + z2.I > 16*16) break;
  z->I = 2 * z->R * z->I + c->I;
  z->R = z2.R - z2.I + c->R;
  if (oz.R == z->R && oz.I == z->I) return -1;
  if (i > deadline) { oz.R = z->R; oz.I = z->I; deadline <<= 1; }
 }
 maxiter = maxiter < i ? i : maxiter;
 return (double)i - log2(log(z2.R + z2.I) / 2);
}


inset

variable_types: tmp double


trapcheck

original_code:
TRAP trapcheck (int *argc, char ***argv) {
 TRAP trap;
 if (3 < *argc) {
  if (!strcmp("--crosstrap", (*argv)[1])) {
   trap.angle = atof((*argv)[2]) * 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421 / 90;
   trap.dist = atof((*argv)[3]);
   trap.start = (uint32_t)atoi((*argv)[4]);
   trap.sin = sin(trap.angle);
   trap.cos = cos(trap.angle);
   trap.hyp = sqrt(trap.sin * trap.sin + trap.cos * trap.cos);
   (*argv)[4] = (*argv)[0]; *argc -= 4; *argv += 4;
   iterate = &crosstrap;
  } else trap.dist = 0;
 }
 return trap;
}

canonical_original_code:
struct TRAP trapcheck(int *argc, char ***argv) {
 struct TRAP trap;
 if (3 < *argc) {
  if (!strcmp("--crosstrap", (*argv)[1])) {
   trap.angle = atof((*argv)[2]) * 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421 / 90;
   trap.dist = atof((*argv)[3]);
   trap.start = (unsigned int)atoi((*argv)[4]);
   trap.sin = sin(trap.angle);
   trap.cos = cos(trap.angle);
   trap.hyp = sqrt(trap.sin * trap.sin + trap.cos * trap.cos);
   (*argv)[4] = (*argv)[0]; *argc -= 4; *argv += 4;
   iterate = &crosstrap;
  } else trap.dist = 0;
 }
 return trap;
}

variable_types:
argc
int *

variable_types:
argv
char ***

variable_types: struct TRAP { double angle; unsigned int start; }


decompiled_code:
double __fastcall pixel2vector_NOTHETA(int *a1, double *a2, double *a3)
{
return (double)*a1 * *a2 - a3[2] + *a3;
}

canonical_decompiled_code:
double __fastcall func0(int *a1, double *a2, double *a3)
{
return (double)*a1 * *a2 - a3[2] + *a3;
}

original_code:
COMPLEX pixel2vector_NOTHETA (
 const PIXEL *const in, const COMPLEX *const size,
 const REGION *const window, const double theta
) {
 COMPLEX out;
 out.R = window->center.R + (in->X * size->R - window->radius.R);
 out.I = -window->center.I + (in->Y * size->I - window->radius.I);
 return out;
}

canonical_original_code:
struct COMPLEX pixel2vector_NOTHETA(struct PIXEL *in, struct COMPLEX *size, struct REGION *window, double theta) {
 struct COMPLEX out;
 out.R = window->center.R + (in->X * size->R - window->radius.R);
 out.I = -window->center.I + (in->Y * size->I - window->radius.I);
 return out;
}

variable_types:
in
struct PIXEL { int X; int Y; } *

variable_types:
size
struct COMPLEX *

variable_types: struct REGION { struct COMPLEX center; struct COMPLEX radius; } *

variable_types: theta double

variable_types:
out
struct COMPLEX { double R; double I; }

return_type: struct COMPLEX { double R; double I; }


decompiled_code:
void __fastcall pixel2vector_START(int *a1, double *a2, double *a3, double a4)
{
if ( a4 == 0.0 )
{
pixel2vector = (__int64 (__fastcall *)())pixel2vector_NOTHETA;
pixel2vector_NOTHETA(a1, a2, a3);
}
else
{
pixel2vector = pixel2vector_THETA;
pixel2vector_THETA();
}
}

canonical_decompiled_code:
void __fastcall func1(int *a1, double *a2, double *a3, double a4)
{
if ( a4 == 0.0 )
{
pixel2vector = (__int64 (__fastcall *)())pixel2vector_NOTHETA;
func0(a1, a2, a3);
}
else
{
pixel2vector = pixel2vector_THETA;
func2();
}
}

original_code:
COMPLEX pixel2vector_START (
 const PIXEL *const in, const COMPLEX *const size,
 const REGION *const window, const double theta
) {
 pixel2vector = theta ? &pixel2vector_THETA : &pixel2vector_NOTHETA;
 return pixel2vector(in, size, window, theta);
}

canonical_original_code:
struct COMPLEX pixel2vector_START(struct PIXEL *in, struct COMPLEX *size, struct REGION *window, double theta) {
 pixel2vector = theta ? &pixel2vector_THETA : &pixel2vector_NOTHETA;
 return pixel2vector(in, size, window, theta);
}

user_defined_types: struct REGION { struct COMPLEX center; struct COMPLEX radius; }


decompiled_code:
double __fastcall pixel2vector_THETA(int *a1, double *a2, double *a3, double a4)
{
double v6; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a4, sinx, &v6);
return ((double)*a1 * *a2 - a3[2]) * v6 + *a3 - ((double)a1[1] * a2[1] - a3[3]) * sinx[0];
}

canonical_decompiled_code:
double __fastcall func2(int *a1, double *a2, double *a3, double a4)
{
double v6; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a4, sinx, &v6);
return ((double)*a1 * *a2 - a3[2]) * v6 + *a3 - ((double)a1[1] * a2[1] - a3[3]) * sinx[0];
}

original_code:
COMPLEX pixel2vector_THETA (
 const PIXEL *const in, const COMPLEX *const size,
 const REGION *const window, const double theta
) {
 COMPLEX out;
 out.R = window->center.R
  + (in->X * size->R - window->radius.R) * cos(theta)
  - (in->Y * size->I - window->radius.I) * sin(theta);
 out.I = -window->center.I
  + (in->X * size->R - window->radius.R) * sin(theta)
  + (in->Y * size->I - window->radius.I) * cos(theta);
 return out;
}

canonical_original_code:
struct COMPLEX pixel2vector_THETA(struct PIXEL *in, struct COMPLEX *size, struct REGION *window, double theta) {
 struct COMPLEX out;
 out.R = window->center.R
  + (in->X * size->R - window->radius.R) * cos(theta)
  - (in->Y * size->I - window->radius.I) * sin(theta);
 out.I = -window->center.I
  + (in->X * size->R - window->radius.R) * sin(theta)
  + (in->Y * size->I - window->radius.I) * cos(theta);
 return out;
}


pixelsize

decompiled_code:
double __fastcall pixelsize(_DWORD *a1, __int64 a2)
{
return (*(double *)(a2 + 16) + *(double *)(a2 + 16)) / (double)(*a1 - 1);
}

canonical_decompiled_code:
double __fastcall func3(_DWORD *a1, __int64 a2)
{
return (*(double *)(a2 + 16) + *(double *)(a2 + 16)) / (double)(*a1 - 1);
}

original_code:
COMPLEX pixelsize (const PIXEL *const img, const REGION *const window) {
 COMPLEX out;
 out.R = 2 * window->radius.R / (img->X - 1);
 out.I = 2 * window->radius.I / (img->Y - 1);
 return out;
}

canonical_original_code:
struct COMPLEX pixelsize(struct PIXEL *img, struct REGION *window) {
 struct COMPLEX out;
 out.R = 2 * window->radius.R / (img->X - 1);
 out.I = 2 * window->radius.I / (img->Y - 1);
 return out;
}

variable_types:
img
struct PIXEL { int X; int Y; } *


fail

decompiled_code:
void __fastcall __noreturn fail(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
__attribute__((noreturn))
void fail (const char *msg) {
 perror(msg);
 exit(1);
}

canonical_original_code:
void fail(char *msg) {
 perror(msg);
 exit(1);
}

variable_types:
msg
char *


die

decompiled_code:
void __noreturn die(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
puts(".");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
puts(".");
exit(1);
}

original_code:
__attribute__((noreturn))
void die (const char *fmt, ...) {
 va_list args;
 __builtin_va_start(args,fmt);
 vprintf(fmt, args);
 __builtin_va_end(args);
 puts(".");
 exit(1);
}

canonical_original_code:
void die(char *fmt, ...) {
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 vprintf(fmt, args);
 __builtin_va_end(args);
 puts(".");
 exit(1);
}

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall add_point(__int64 a1, double a2, double a3)
{
char *v3; // rax
__int64 v4; // rdx
double *v5; // rax
__int64 result; // rax

v3 = (char *)realloc(*(void **)a1, 16 * (*(_QWORD *)(a1 + 8) + 1LL));
if ( !v3 )
fail("failed to allocate memory");
v4 = *(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = v3;
v5 = (double *)&v3[16 * v4];
*v5 = a2;
v5[1] = a3;
result = a1;
*(_QWORD *)(a1 + 8) = v4 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, double a2, double a3)
{
char *v3; // rax
__int64 v4; // rdx
double *v5; // rax
__int64 result; // rax

v3 = (char *)realloc(*(void **)a1, 16 * (*(_QWORD *)(a1 + 8) + 1LL));
if ( !v3 )
func8("failed to allocate memory");
v4 = *(_QWORD *)(a1 + 8);
*(_QWORD *)a1 = v3;
v5 = (double *)&v3[16 * v4];
*v5 = a2;
v5[1] = a3;
result = a1;
*(_QWORD *)(a1 + 8) = v4 + 1;
return result;
}

original_code:
struct CHANNEL *add_point (struct CHANNEL *in, double x, double y) {
 struct POINT *new;
 new = realloc(in->points, (in->length + 1) * sizeof(*(in->points)));
 if (!new)
  fail("failed to allocate memory");
 in->points = new;
 in->points[in->length].x = x;
 in->points[in->length].y = y;
 in->length++;
 return in;
}

canonical_original_code:
struct CHANNEL *add_point(struct CHANNEL *in, double x, double y) {
 struct POINT *new;
 new = realloc(in->points, (in->length + 1) * sizeof(*(in->points)));
 if (!new)
  fail("failed to allocate memory");
 in->points = new;
 in->points[in->length].x = x;
 in->points[in->length].y = y;
 in->length++;
 return in;
}

variable_types:
in
struct CHANNEL *

variable_types: x double

variable_types: y double

variable_types:
new
struct POINT { double x; double y; } *

return_type: struct CHANNEL { struct POINT { double x; double y; } *points; unsigned long length; } *

user_defined_types: struct CHANNEL { struct POINT *points; unsigned long length; }


decompiled_code:
__int64 __fastcall add_syncpoint(__int64 a1, __int64 a2, _QWORD *a3, double a4)
{
__int64 v4; // r13
__int64 v7; // rbx
__int64 v8; // rdi
__int64 result; // rax
double v10; // [rsp+0h] [rbp-30h]

v4 = a1 + 48;
v7 = a1;
do
{
a2 += *a3;
__isoc99_sscanf();
debug(",%f", 4202699LL);
v8 = v7;
v7 += 16LL;
result = add_point(v8, a4, v10);
}
while ( v7 != v4 );
return result;
}

original_code:
void add_syncpoint (struct CHANNEL *channels, double x, char *line, off_t *off) {
 uint8_t c;
 double y;
 for (c = 0; c < 3; c++) {
  line += *off;
  sscanf(line, "%lf%jn", &y, off);
  debug(",%f", y);
  add_point(&(channels[c]), x, y);
 }
}

canonical_original_code:
void add_syncpoint(struct CHANNEL *channels, double x, char *line, long *off) {
 unsigned char c;
 double y;
 for (c = 0; c < 3; c++) {
  line += *off;
  sscanf(line, "%lf%jn", &y, off);
  debug(",%f", y);
  add_point(&(channels[c]), x, y);
 }
}

variable_types: struct CHANNEL { struct POINT { double x; double y; } *points; unsigned long length; } *

variable_types:
line
char *

variable_types:
off
long *

variable_types:
c
unsigned char


printparsed

decompiled_code:
int __fastcall printparsed(__int64 a1)
{
FILE **v1; // r12
unsigned __int64 *v2; // rbp
unsigned __int64 i; // rbx
__int64 v4; // rax
int result; // eax

v1 = (FILE **)&channel;
v2 = (unsigned __int64 *)(a1 + 8);
do
{
for ( i = 0LL;
*v2 > i;
result = printf(
"%s: %f/%f\n",
(const char *)*v1,
*(double *)(*(v2 - 1) + 16 * v4),
*(double *)(*(v2 - 1) + 16 * v4 + 8)) )
{
v4 = i++;
}
++v1;
v2 += 2;
}
while ( v1 != &_bss_start );
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
FILE **v1; // r12
unsigned __int64 *v2; // rbp
unsigned __int64 i; // rbx
__int64 v4; // rax
int result; // eax

v1 = (FILE **)&channel;
v2 = (unsigned __int64 *)(a1 + 8);
do
{
for ( i = 0LL;
*v2 > i;
result = printf(
"%s: %f/%f\n",
(const char *)*v1,
*(double *)(*(v2 - 1) + 16 * v4),
*(double *)(*(v2 - 1) + 16 * v4 + 8)) )
{
v4 = i++;
}
++v1;
v2 += 2;
}
while ( v1 != &_bss_start );
return result;
}

original_code:
void printparsed (struct CHANNEL *channels) {
 uint8_t c;
 size_t i;
 for (c = 0; c < 3; c++)
  for (i = 0; i < channels[c].length; i++)
   printf(
     "%s: %f/%f\n",
     channel[c],
     channels[c].points[i].x,
     channels[c].points[i].y
   );
}

canonical_original_code:
void printparsed(struct CHANNEL *channels) {
 unsigned char c;
 unsigned long i;
 for (c = 0; c < 3; c++)
  for (i = 0; i < channels[c].length; i++)
   printf(
     "%s: %f/%f\n",
     channel[c],
     channels[c].points[i].x,
     channels[c].points[i].y
   );
}

variable_types:
i
unsigned long


printoutput

decompiled_code:
int __fastcall printoutput(_QWORD *a1)
{
int result; // eax
__int64 v2; // rdx
unsigned __int64 i; // rbx
double v4; // xmm0_8
double v5; // xmm1_8
unsigned __int8 *v6; // rax

v2 = a1[1];
if ( v2 )
{
for ( i = 0LL; i < v2; ++i )
{
v6 = (unsigned __int8 *)(*a1 + 3 * i);
if ( (i & 0x8000000000000000LL) == 0LL )
{
v4 = (double)(int)i;
if ( v2 < 0 )
goto LABEL_8;
}
else
{
v4 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
if ( v2 < 0 )
{
LABEL_8:
v5 = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
goto LABEL_5;
}
}
v5 = (double)(int)v2;
LABEL_5:
result = printf("%lf: %d, %d, %d\n", v4 / v5, *v6, v6[1], v6[2]);
v2 = a1[1];
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(_QWORD *a1)
{
int result; // eax
__int64 v2; // rdx
unsigned __int64 i; // rbx
double v4; // xmm0_8
double v5; // xmm1_8
unsigned __int8 *v6; // rax

v2 = a1[1];
if ( v2 )
{
for ( i = 0LL; i < v2; ++i )
{
v6 = (unsigned __int8 *)(*a1 + 3 * i);
if ( (i & 0x8000000000000000LL) == 0LL )
{
v4 = (double)(int)i;
if ( v2 < 0 )
goto LABEL_8;
}
else
{
v4 = (double)(int)(i & 1 | (i >> 1)) + (double)(int)(i & 1 | (i >> 1));
if ( v2 < 0 )
{
LABEL_8:
v5 = (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1)) + (double)(int)(v2 & 1 | ((unsigned __int64)v2 >> 1));
goto LABEL_5;
}
}
v5 = (double)(int)v2;
LABEL_5:
result = printf("%lf: %d, %d, %d\n", v4 / v5, *v6, v6[1], v6[2]);
v2 = a1[1];
}
}
return result;
}

original_code:
void printoutput (struct GRADIENT *gradient) {
 size_t i;
 for (i = 0; i < gradient->length; i++)
  printf(
   "%lf: %d, %d, %d\n",
   (double)i / (double)gradient->length,
   gradient->x[i].y[0],
   gradient->x[i].y[1],
   gradient->x[i].y[2]
  );
}

canonical_original_code:
void printoutput(struct GRADIENT *gradient) {
 unsigned long i;
 for (i = 0; i < gradient->length; i++)
  printf(
   "%lf: %d, %d, %d\n",
   (double)i / (double)gradient->length,
   gradient->x[i].y[0],
   gradient->x[i].y[1],
   gradient->x[i].y[2]
  );
}

variable_types: struct GRADIENT { struct RGB24 { unsigned char y[3]; } *x; unsigned long length; } *

user_defined_types: struct GRADIENT { struct RGB24 *x; unsigned long length; }


fail

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
perror(a1);
exit(1);
}


die

canonical_decompiled_code:
void __noreturn func11(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
puts(".");
exit(1);
}


fail

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
perror(a1);
exit(1);
}