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

result = 0LL;
if ( a1 )
result = (*a1 >> 4) & 1LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = (*a1 >> 4) & 1LL;
return result;
}

original_code:
static inline int is_bool(struct exp *var) {
 return (var && (var->tag & (1<<4)));
}

variable_types:
var
struct exp { unsigned long tag; } *


repo: xudifsd/libsi

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

result = 0LL;
if ( a1 )
result = *a1 & 1LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = *a1 & 1LL;
return result;
}

original_code:
static inline int is_number(struct exp *var) {
 return (var && (var->tag & (1<<0)));
}

return_type: int


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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 16) == 0;
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 16) == 0;
return result;
}

original_code:
static inline int is_long(struct number *num) {
 return (num && num->type == LONG);
}

variable_types: struct number { unsigned long tag; union { long l_value; double d_value; }; enum num_type { LONG=0, DOUBLE=1 } type; } *

user_defined_types: struct number { unsigned long tag; union { long l_value; double d_value; }; enum num_type type; }


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

result = 0LL;
if ( a1 )
result = (*a1 >> 1) & 1LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = (*a1 >> 1) & 1LL;
return result;
}

original_code:
static inline int is_symbol(struct exp *var) {
 return (var && (var->tag & (1<<1)));
}


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

result = 0LL;
if ( a1 )
result = (*a1 >> 3) & 1LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = (*a1 >> 3) & 1LL;
return result;
}

original_code:
static inline int is_callable(struct exp *var) {
 return (var && (var->tag & (1<<3)));
}


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

result = 0LL;
if ( a1 )
result = (*a1 >> 2) & 1LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = (*a1 >> 2) & 1LL;
return result;
}

original_code:
static inline int is_pair(struct exp *var) {
 return (var && (var->tag & (1<<2)));
}


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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 32) == 0;
return result;
}

original_code:
static inline int is_builtin_syntax(struct callable *var) {
 return (var && (var->type == BUILTIN_SYNTAX));
}

variable_types: struct callable { unsigned long tag; union { enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 } (*bp_value)(struct pair { unsigned long tag; struct exp { unsigned long tag; } *car; struct exp *cdr; } *args, struct exp **rtn); enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 } (*bs_value)(struct pair *args, struct exp **rtn, struct environ { struct environ *parent; struct tree_node { enum tree_color { BLACK=0, RED=1 } color; struct tree_node *parent; struct tree_node **pparent; struct tree_node *left; struct tree_node *right; struct symbol { unsigned long tag; char sym[70]; } *sym; struct exp *value; } *repo; } *env); struct user_defined_s { struct pair *pars; struct pair *body; struct environ *bind; } u_value; }; enum callable_type { BUILTIN_SYNTAX=0, BUILTIN_PRO=1, LAMBDA=2, MACRO=3 } type; } *

user_defined_types: struct callable { unsigned long tag; union { enum rtn_type (*bp_value)(struct pair *args, struct exp **rtn); enum rtn_type (*bs_value)(struct pair *args, struct exp **rtn, struct environ *env); struct user_defined_s u_value; }; enum callable_type type; }

user_defined_types: struct pair { unsigned long tag; struct exp *car; struct exp *cdr; }

user_defined_types: struct environ { struct environ *parent; struct tree_node *repo; }

user_defined_types: struct tree_node { enum tree_color color; struct tree_node *parent; struct tree_node **pparent; struct tree_node *left; struct tree_node *right; struct symbol *sym; struct exp *value; }


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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 32) == 1;
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 32) == 1;
return result;
}

original_code:
static inline int is_builtin_pro(struct callable *var) {
 return (var && (var->type == BUILTIN_PRO));
}

user_defined_types: enum callable_type { BUILTIN_SYNTAX=0, BUILTIN_PRO=1, LAMBDA=2, MACRO=3 }

user_defined_types: struct user_defined_s { struct pair *pars; struct pair *body; struct environ *bind; }

user_defined_types: enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 }

user_defined_types: struct symbol { unsigned long tag; char sym[70]; }


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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 32) == 2;
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_DWORD *)(a1 + 32) == 2;
return result;
}

original_code:
static inline int is_lambda(struct callable *var) {
 return (var && (var->type == LAMBDA));
}


map

decompiled_code:
__int64 __fastcall map(__int64 (__fastcall *a1)(__int64, __int64 *), __int64 a2, __int64 *a3)
{
__int64 v4; // rbx
__int64 *v5; // rbp
__int64 v6; // rax
_QWORD *v7; // rax
int v8; // eax
__int64 v9; // rdx
__int64 v10; // rax
__int64 result; // rax
__int64 v12; // [rsp+0h] [rbp-38h] BYREF
__int64 v13; // [rsp+8h] [rbp-30h] BYREF

v4 = a2;
v13 = 0LL;
if ( a2 )
{
v5 = &v13;
while ( 1 )
{
v7 = (_QWORD *)cdr_isra_0(*(_QWORD *)(v4 + 16));
v8 = is_pair(v7);
if ( v9 )
{
if ( !v8 )
break;
}
v10 = car_isra_0(*(_QWORD *)(v4 + 8));
result = a1(v10, &v12);
if ( (_DWORD)result )
{
*a3 = v12;
return result;
}
v6 = alloc_pair(v12, 0LL);
v4 = *(_QWORD *)(v4 + 16);
*v5 = v6;
v5 = (__int64 *)(v6 + 16);
if ( !v4 )
{
v4 = v13;
goto LABEL_9;
}
}
*a3 = alloc_err_msg("in map, args is not a list");
result = 2LL;
}
else
{
LABEL_9:
*a3 = v4;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 (__fastcall *a1)(__int64, __int64 *), __int64 a2, __int64 *a3)
{
__int64 v4; // rbx
__int64 *v5; // rbp
__int64 v6; // rax
_QWORD *v7; // rax
int v8; // eax
__int64 v9; // rdx
__int64 v10; // rax
__int64 result; // rax
__int64 v12; // [rsp+0h] [rbp-38h] BYREF
__int64 v13; // [rsp+8h] [rbp-30h] BYREF

v4 = a2;
v13 = 0LL;
if ( a2 )
{
v5 = &v13;
while ( 1 )
{
v7 = (_QWORD *)func9(*(_QWORD *)(v4 + 16));
v8 = func5(v7);
if ( v9 )
{
if ( !v8 )
break;
}
v10 = func10(*(_QWORD *)(v4 + 8));
result = a1(v10, &v12);
if ( (_DWORD)result )
{
*a3 = v12;
return result;
}
v6 = alloc_pair(v12, 0LL);
v4 = *(_QWORD *)(v4 + 16);
*v5 = v6;
v5 = (__int64 *)(v6 + 16);
if ( !v4 )
{
v4 = v13;
goto LABEL_9;
}
}
*a3 = alloc_err_msg("in map, args is not a list");
result = 2LL;
}
else
{
LABEL_9:
*a3 = v4;
result = 0LL;
}
return result;
}

original_code:
enum rtn_type map(map_f fun, struct pair *args, struct pair **rtn) {
 struct pair *p;
 struct pair *value;
 struct exp *e;
 struct pair *head = ((void *)0);
 struct pair **tail = &head;
 enum rtn_type r_type;
 for ((p) = (args); (p); (p) = (struct pair *)(p)->cdr) {
  if (!is_pair(cdr(p)) && cdr(p) != ((void *)0)) {
   *rtn = (struct pair *)alloc_err_msg("in map, args is not a list");
   return ERR_TYPE;
  }
  if ((r_type = fun(car(p), &e)) == SUCC) {
   value = alloc_pair(e, ((void *)0));
   *tail = value;
   tail = (struct pair **)&value->cdr;
  } else {
   *rtn = (struct pair *)e;
   return r_type;
  }
 }
 *rtn = head;
 return SUCC;
}

canonical_original_code:
enum rtn_type map(enum rtn_type (*fun)(struct exp *, struct exp **), struct pair *args, struct pair **rtn) {
 struct pair *p;
 struct pair *value;
 struct exp *e;
 struct pair *head = ((void *)0);
 struct pair **tail = &head;
 enum rtn_type r_type;
 for ((p) = (args); (p); (p) = (struct pair *)(p)->cdr) {
  if (!is_pair(cdr(p)) && cdr(p) != ((void *)0)) {
   *rtn = (struct pair *)alloc_err_msg("in map, args is not a list");
   return ERR_TYPE;
  }
  if ((r_type = fun(car(p), &e)) == SUCC) {
   value = alloc_pair(e, ((void *)0));
   *tail = value;
   tail = (struct pair **)&value->cdr;
  } else {
   *rtn = (struct pair *)e;
   return r_type;
  }
 }
 *rtn = head;
 return SUCC;
}

variable_types: enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 } (*)(struct exp { unsigned long tag; } *, struct exp **)

variable_types: struct pair { unsigned long tag; struct exp *car; struct exp *cdr; } *

variable_types:
rtn
struct pair **

variable_types:
e
struct exp { unsigned long tag; } *

variable_types: struct pair { unsigned long tag; struct exp { unsigned long tag; } *car; struct exp *cdr; } **


decompiled_code:
__int64 __fastcall check_args(__int64 a1, __int64 a2, int a3, _QWORD *a4)
{
_QWORD *v7; // rax
int v8; // eax
int v9; // er9
__int64 v10; // rdx
unsigned int v11; // er9

if ( !a1 )
{
v11 = 0;
LABEL_5:
if ( a3 )
{
if ( (unsigned int)a2 > v11 )
{
*a4 = alloc_err_msg("expect at least %d args, %d is given", a2, v11);
return 1LL;
}
}
else if ( (_DWORD)a2 != v11 )
{
*a4 = alloc_err_msg("expect %d args, %d is given", a2, v11);
return 1LL;
}
return 0LL;
}
while ( 1 )
{
v7 = (_QWORD *)cdr_isra_0(*(_QWORD *)(a1 + 16));
v8 = is_pair(v7);
if ( v10 )
{
if ( !v8 )
break;
}
v11 = v9 + 1;
if ( !a1 )
goto LABEL_5;
}
*a4 = alloc_err_msg("in check_args, args is not list");
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, int a3, _QWORD *a4)
{
_QWORD *v7; // rax
int v8; // eax
int v9; // er9
__int64 v10; // rdx
unsigned int v11; // er9

if ( !a1 )
{
v11 = 0;
LABEL_5:
if ( a3 )
{
if ( (unsigned int)a2 > v11 )
{
*a4 = alloc_err_msg("expect at least %d args, %d is given", a2, v11);
return 1LL;
}
}
else if ( (_DWORD)a2 != v11 )
{
*a4 = alloc_err_msg("expect %d args, %d is given", a2, v11);
return 1LL;
}
return 0LL;
}
while ( 1 )
{
v7 = (_QWORD *)func9(*(_QWORD *)(a1 + 16));
v8 = func5(v7);
if ( v10 )
{
if ( !v8 )
break;
}
v11 = v9 + 1;
if ( !a1 )
goto LABEL_5;
}
*a4 = alloc_err_msg("in check_args, args is not list");
return 2LL;
}

original_code:
enum rtn_type check_args(struct pair *args, unsigned int nr_arg, int at_least, struct exp **rtn) {
 unsigned int len = 0;
 struct pair *p;
 for ((p) = (args); (p); (p) = (struct pair *)(p)->cdr) {
  if (!is_pair(cdr(p)) && cdr(p) != ((void *)0)) {
   *rtn = (struct exp *)alloc_err_msg("in check_args, args is not list");
   return ERR_TYPE;
  }
  len++;
 }
 if (at_least && len < nr_arg) {
  *rtn = (struct exp *)alloc_err_msg("expect at least %d args, %d is given", nr_arg, len);
  return ERR_ARGC;
 } else if (!at_least && len != nr_arg) {
  *rtn = (struct exp *)alloc_err_msg("expect %d args, %d is given", nr_arg, len);
  return ERR_ARGC;
 } else
  return SUCC;
}

variable_types: struct pair { unsigned long tag; struct exp { unsigned long tag; } *car; struct exp *cdr; } *

variable_types:
rtn
struct exp **

variable_types:
len
unsigned int

return_type: enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 }


decompiled_code:
__int64 __fastcall last_element(__int64 a1, __int64 *a2)
{
__int64 v2; // rcx
__int64 v4; // rsi
_QWORD *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 result; // rax

v2 = a1;
if ( a1 )
{
while ( 1 )
{
v4 = *(_QWORD *)(v2 + 16);
v5 = (_QWORD *)cdr_isra_0(v4);
if ( !(unsigned int)is_pair(v5) )
break;
if ( !v6 )
goto LABEL_4;
v2 = v4;
if ( !v4 )
goto LABEL_7;
}
if ( v6 )
goto LABEL_7;
LABEL_4:
*a2 = car_isra_0(*(_QWORD *)(v7 + 8));
result = 0LL;
}
else
{
LABEL_7:
*a2 = alloc_err_msg("in last_element, not a list");
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 *a2)
{
__int64 v2; // rcx
__int64 v4; // rsi
_QWORD *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 result; // rax

v2 = a1;
if ( a1 )
{
while ( 1 )
{
v4 = *(_QWORD *)(v2 + 16);
v5 = (_QWORD *)func9(v4);
if ( !(unsigned int)func5(v5) )
break;
if ( !v6 )
goto LABEL_4;
v2 = v4;
if ( !v4 )
goto LABEL_7;
}
if ( v6 )
goto LABEL_7;
LABEL_4:
*a2 = func10(*(_QWORD *)(v7 + 8));
result = 0LL;
}
else
{
LABEL_7:
*a2 = alloc_err_msg("in last_element, not a list");
result = 2LL;
}
return result;
}

original_code:
enum rtn_type last_element(struct pair *head, struct exp **rtn) {
 struct pair *p;
 for ((p) = (head); (p); (p) = (struct pair *)(p)->cdr) {
  if (!is_pair(cdr(p)) && cdr(p) != ((void *)0)) {
   *rtn = (struct exp *)alloc_err_msg("in last_element, not a list");
   return ERR_TYPE;
  } if (cdr(p) == ((void *)0)) {
   *rtn = car(p);
   return SUCC;
  }
 }
 *rtn = (struct exp *)alloc_err_msg("in last_element, not a list");
 return ERR_TYPE;
}


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

if ( is_long(a1) )
result = *(_QWORD *)(a1 + 8) > 0LL;
else
result = *(double *)(a1 + 8) > 0.0;
return result;
}

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

if ( func2(a1) )
result = *(_QWORD *)(a1 + 8) > 0LL;
else
result = *(double *)(a1 + 8) > 0.0;
return result;
}

original_code:
int above_zero(struct number *num) {
 if (is_long(num))
  return (num->l_value > 0);
 else
  return (num->d_value > 0);
}


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

if ( is_long(a1) )
result = *(_QWORD *)(a1 + 8) >> 63;
else
result = *(double *)(a1 + 8) < 0.0;
return result;
}

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

if ( func2(a1) )
result = *(_QWORD *)(a1 + 8) >> 63;
else
result = *(double *)(a1 + 8) < 0.0;
return result;
}

original_code:
int below_zero(struct number *num) {
 if (is_long(num))
  return (num->l_value < 0);
 else
  return (num->d_value < 0);
}


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

result = is_long(a1);
if ( result )
return *(_QWORD *)(a1 + 8) == 0LL;
if ( *(double *)(a1 + 8) == 0.0 )
result = 1LL;
return result;
}

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

result = func2(a1);
if ( result )
return *(_QWORD *)(a1 + 8) == 0LL;
if ( *(double *)(a1 + 8) == 0.0 )
result = 1LL;
return result;
}

original_code:
int equal_zero(struct number *num) {
 if (is_long(num))
  return (num->l_value == 0);
 else
  return (num->d_value == 0);
}


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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void pop_stack_frame(struct stack_frame **f) {
 *f = (*f)->prev;
}

variable_types: struct stack_frame { int dot_list; struct stack_frame *prev; struct pair { unsigned long tag; struct exp { unsigned long tag; } *car; struct exp *cdr; } *head; struct pair **tail; } **

return_type: void

user_defined_types: struct stack_frame { int dot_list; struct stack_frame *prev; struct pair *head; struct pair **tail; }


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

v4 = a2;
if ( !*a3 )
{
v4 = alloc_pair(a2, 0LL);
LABEL_3:
**(_QWORD **)(a1 + 24) = v4;
result = 0LL;
*(_QWORD *)(a1 + 24) = v4 + 16;
return result;
}
result = 1LL;
if ( !*(_DWORD *)a1 )
{
*(_DWORD *)a1 = 1;
*a3 = 0;
goto LABEL_3;
}
return result;
}

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

v4 = a2;
if ( !*a3 )
{
v4 = alloc_pair(a2, 0LL);
LABEL_3:
**(_QWORD **)(a1 + 24) = v4;
result = 0LL;
*(_QWORD *)(a1 + 24) = v4 + 16;
return result;
}
result = 1LL;
if ( !*(_DWORD *)a1 )
{
*(_DWORD *)a1 = 1;
*a3 = 0;
goto LABEL_3;
}
return result;
}

original_code:
int append_stack(struct stack_frame *f, struct exp *p, int *dot) {
 struct pair *new;
 if (*dot && f->dot_list)
  return 1;
 else if (*dot) {
  new = (struct pair *)p;
  f->dot_list = 1;
  *dot = 0;
 } else
  new = alloc_pair(p, ((void *)0));
 *(f->tail) = new;
 f->tail = (struct pair **)&new->cdr;
 return 0;
}

variable_types: struct stack_frame { int dot_list; struct stack_frame *prev; struct pair { unsigned long tag; struct exp { unsigned long tag; } *car; struct exp *cdr; } *head; struct pair **tail; } *

variable_types:
p
struct exp *

variable_types:
dot
int *


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

result = alloc_quote_stack(*a1);
*a1 = result;
return result;
}

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

result = alloc_quote_stack(*a1);
*a1 = result;
return result;
}

original_code:
void push_quote_stack(struct quote_stack **top) {
 *top = alloc_quote_stack(*top);
}

variable_types: struct quote_stack { unsigned int nest; struct quote_stack *prev; } **


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

result = alloc_dot_stack(*a1);
*a1 = result;
return result;
}

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

result = alloc_dot_stack(*a1);
*a1 = result;
return result;
}

original_code:
void push_dot_stack(struct dot_stack **top) {
 *top = alloc_dot_stack(*top);
}

variable_types: struct dot_stack { int dot_nest; struct dot_stack *prev; } **


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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void pop_dot_stack(struct dot_stack **top) {
 *top = (*top)->prev;
}

user_defined_types: struct dot_stack { int dot_nest; struct dot_stack *prev; }


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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void pop_quote_stack(struct quote_stack **top) {
 *top = (*top)->prev;
}

user_defined_types: struct quote_stack { unsigned int nest; struct quote_stack *prev; }


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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

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

result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = result;
return result;
}

original_code:
void pop_stack(struct stack **f) {
 *f = (*f)->prev;
}

variable_types: struct stack { struct environ { struct environ *parent; struct tree_node { enum tree_color { BLACK=0, RED=1 } color; struct tree_node *parent; struct tree_node **pparent; struct tree_node *left; struct tree_node *right; struct symbol { unsigned long tag; char sym[70]; } *sym; struct exp { unsigned long tag; } *value; } *repo; } *env; struct stack *prev; } **

user_defined_types: struct stack { struct environ *env; struct stack *prev; }


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

result = 0LL;
if ( a1 )
result = (*a1 >> 1) & 1LL;
return result;
}

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

result = 0LL;
if ( a1 )
result = (*a1 >> 1) & 1LL;
return result;
}

original_code:
static inline int is_symbol(struct exp *var) {
 return (var && (var->tag & (1<<1)));
}

variable_types:
var
struct exp { unsigned long tag; } *


decompiled_code:
__int64 __fastcall define_in_env(__int64 a1, __int64 a2, __int64 a3)
{
return tree_insert(a1 + 8, a2, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
return tree_insert(a1 + 8, a2, a3, 0LL);
}

original_code:
int define_in_env(struct environ *env, struct symbol *sym, struct exp *value) {
 return tree_insert(&env->repo, sym, value, 0);
}

variable_types: struct environ { struct environ *parent; struct tree_node { enum tree_color { BLACK=0, RED=1 } color; struct tree_node *parent; struct tree_node **pparent; struct tree_node *left; struct tree_node *right; struct symbol { unsigned long tag; char sym[70]; } *sym; struct exp { unsigned long tag; } *value; } *repo; } *

variable_types:
sym
struct symbol *

variable_types:
value
struct exp *


decompiled_code:
__int64 __fastcall set_in_env(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 result; // rax

if ( !a1 )
return 1LL;
v4 = a1;
while ( 1 )
{
result = tree_insert(v4 + 1, a2, a3, 1LL);
if ( !(_DWORD)result )
break;
v4 = (_QWORD *)*v4;
if ( !v4 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 result; // rax

if ( !a1 )
return 1LL;
v4 = a1;
while ( 1 )
{
result = tree_insert(v4 + 1, a2, a3, 1LL);
if ( !(_DWORD)result )
break;
v4 = (_QWORD *)*v4;
if ( !v4 )
return 1LL;
}
return result;
}

original_code:
int set_in_env(struct environ *env, struct symbol *sym, struct exp *value) {
 struct environ *p;
 for (p = env; p; p = p->parent) {
  if (tree_insert(&p->repo, sym, value, 1))
   continue;
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall find_in_env(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx

if ( !a1 )
return 0LL;
v4 = a1;
do
{
if ( (unsigned int)tree_find(v4[1], a2 + 8, a3) )
return 1LL;
v4 = (_QWORD *)*v4;
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx

if ( !a1 )
return 0LL;
v4 = a1;
do
{
if ( (unsigned int)tree_find(v4[1], a2 + 8, a3) )
return 1LL;
v4 = (_QWORD *)*v4;
}
while ( v4 );
return 0LL;
}

original_code:
int find_in_env(struct environ *env, struct symbol *sym, struct exp **rtn) {
 struct environ *p;
 for (p = env; p; p = p->parent) {
  if (tree_find(p->repo, sym->sym, rtn))
   return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall extend_env(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx
__int64 v5; // r13
__int64 v6; // rsi
__int64 v7; // rax
_QWORD *v8; // rax
__int64 v9; // r8
__int64 v11; // rax
_QWORD *v12; // rsi
__int64 v13; // rdx

v4 = a1;
v5 = alloc_environ(a3);
if ( !a1 )
return v5;
while ( 1 )
{
v8 = (_QWORD *)car_isra_0(*(_QWORD *)(v4 + 8));
if ( !(unsigned int)is_symbol(v8) )
return 0LL;
if ( !strcmp((const char *)(v9 + 8), "#!rest") )
break;
if ( !a2 )
return 0LL;
v6 = v9;
v7 = car_isra_0(*(_QWORD *)(a2 + 8));
define_in_env(v5, v6, v7);
v4 = cdr_isra_0(*(_QWORD *)(v4 + 16));
a2 = cdr_isra_0(*(_QWORD *)(a2 + 16));
if ( !v4 )
return v5;
}
v11 = cdr_isra_0(*(_QWORD *)(v4 + 16));
v12 = (_QWORD *)car_isra_0(*(_QWORD *)(v11 + 8));
if ( !(unsigned int)is_symbol(v12) || cdr_isra_0(*(_QWORD *)(v13 + 16)) )
return 0LL;
define_in_env(v5, (__int64)v12, a2);
return v5;
}

original_code:
struct environ *extend_env(struct pair *pars, struct pair *args, struct environ *base) {
 struct pair *p1, *p2;
 struct exp *e1, *e2;
 struct environ *rtn;
 rtn = alloc_environ(base);
 for (p1 = pars, p2 = args;
   p1;
   p1 = (struct pair *)cdr(p1),
    p2 = (struct pair *)cdr(p2)) {
  e1 = car(p1);
  if (!is_symbol(e1))
   return ((void *)0);
  if (!strcmp(((struct symbol *)e1)->sym, "#!rest")) {
   p1 = (struct pair *)cdr(p1);
   e1 = car(p1);
   if (!is_symbol(e1) || cdr(p1) != ((void *)0))
    return ((void *)0);
   define_in_env(rtn, (struct symbol *)e1, (struct exp *)p2);
   break;
  }
  if (!p2)
   return ((void *)0);
  e2 = car(p2);
  define_in_env(rtn, (struct symbol *)e1, e2);
 }
 return rtn;
}

canonical_original_code:
struct environ *extend_env(struct pair *pars, struct pair *args, struct environ *base) {
 struct pair *p1; struct pair *p2;
 struct exp *e1; struct exp *e2;
 struct environ *rtn;
 rtn = alloc_environ(base);
 for (p1 = pars, p2 = args;
   p1;
   p1 = (struct pair *)cdr(p1),
    p2 = (struct pair *)cdr(p2)) {
  e1 = car(p1);
  if (!is_symbol(e1))
   return ((void *)0);
  if (!strcmp(((struct symbol *)e1)->sym, "#!rest")) {
   p1 = (struct pair *)cdr(p1);
   e1 = car(p1);
   if (!is_symbol(e1) || cdr(p1) != ((void *)0))
    return ((void *)0);
   define_in_env(rtn, (struct symbol *)e1, (struct exp *)p2);
   break;
  }
  if (!p2)
   return ((void *)0);
  e2 = car(p2);
  define_in_env(rtn, (struct symbol *)e1, e2);
 }
 return rtn;
}

variable_types: struct pair { unsigned long tag; struct exp *car; struct exp *cdr; } *

variable_types:
args
struct pair *

variable_types:
base
struct environ *

return_type: struct environ { struct environ *parent; struct tree_node { enum tree_color { BLACK=0, RED=1 } color; struct tree_node *parent; struct tree_node **pparent; struct tree_node *left; struct tree_node *right; struct symbol { unsigned long tag; char sym[70]; } *sym; struct exp { unsigned long tag; } *value; } *repo; } *


original_code:
struct environ *setup_builtin() {
 struct environ *base_env;
 struct symbol *s;
 struct callable *ca;
 base_env = alloc_environ(((void *)0));
 ca = alloc_builtin_pro(add);
 s = alloc_symbol("+");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(mul);
 s = alloc_symbol("*");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(length);
 s = alloc_symbol("length");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(list);
 s = alloc_symbol("list");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_log);
 s = alloc_symbol("log");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_sin);
 s = alloc_symbol("sin");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_cos);
 s = alloc_symbol("cos");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_tan);
 s = alloc_symbol("tan");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(cons);
 s = alloc_symbol("cons");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_car);
 s = alloc_symbol("car");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_cdr);
 s = alloc_symbol("cdr");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(min);
 s = alloc_symbol("min");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(max);
 s = alloc_symbol("max");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(apply);
 s = alloc_symbol("apply");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(sub);
 s = alloc_symbol("-");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(number_equal);
 s = alloc_symbol("=");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(more_than);
 s = alloc_symbol(">");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(less_than);
 s = alloc_symbol("<");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(more_equal);
 s = alloc_symbol(">=");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(less_equal);
 s = alloc_symbol("<=");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(null_p);
 s = alloc_symbol("null?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(number_p);
 s = alloc_symbol("number?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(symbol_p);
 s = alloc_symbol("symbol?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(pair_p);
 s = alloc_symbol("pair?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(procedure_p);
 s = alloc_symbol("procedure?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(bool_p);
 s = alloc_symbol("boolean?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(list_p);
 s = alloc_symbol("list?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(not);
 s = alloc_symbol("not");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(positive_p);
 s = alloc_symbol("positive?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(negative_p);
 s = alloc_symbol("negative?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(zero_p);
 s = alloc_symbol("zero?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(odd_p);
 s = alloc_symbol("odd?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(even_p);
 s = alloc_symbol("even?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(eq_p);
 s = alloc_symbol("eq?");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_read);
 s = alloc_symbol("read");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_print);
 s = alloc_symbol("print");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_abs);
 s = alloc_symbol("abs");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_floor);
 s = alloc_symbol("floor");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_ceil);
 s = alloc_symbol("ceiling");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(u_sqrt);
 s = alloc_symbol("sqrt");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_pro(append);
 s = alloc_symbol("append");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(user_eval);
 s = alloc_symbol("eval");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(u_if);
 s = alloc_symbol("if");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(define);
 s = alloc_symbol("define");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(set);
 s = alloc_symbol("set!");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(begin);
 s = alloc_symbol("begin");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(lambda);
 s = alloc_symbol("lambda");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(defmacro);
 s = alloc_symbol("defmacro");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(macroexpand);
 s = alloc_symbol("macroexpand");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(quote);
 s = alloc_symbol("quote");
 define_in_env(base_env, s, (struct exp *)ca);
 ca = alloc_builtin_syntax(backquote);
 s = alloc_symbol("backquote");
 define_in_env(base_env, s, (struct exp *)ca);
 return base_env;
}

variable_types: struct callable { unsigned long tag; union { enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 } (*bp_value)(struct pair { unsigned long tag; struct exp { unsigned long tag; } *car; struct exp *cdr; } *args, struct exp **rtn); enum rtn_type { SUCC=0, ERR_ARGC=1, ERR_TYPE=2, ERR_UNBOUND=3, ERR_MATH=4, ERR_ENV=5, ERR_MEM=6, ERR_USER_PRO=7, ERR_PARSE_RB=8, ERR_PARSE_DOT=9 } (*bs_value)(struct pair *args, struct exp **rtn, struct environ { struct environ *parent; struct tree_node { enum tree_color { BLACK=0, RED=1 } color; struct tree_node *parent; struct tree_node **pparent; struct tree_node *left; struct tree_node *right; struct symbol { unsigned long tag; char sym[70]; } *sym; struct exp *value; } *repo; } *env); struct user_defined_s { struct pair *pars; struct pair *body; struct environ *bind; } u_value; }; enum callable_type { BUILTIN_SYNTAX=0, BUILTIN_PRO=1, LAMBDA=2, MACRO=3 } type; } *


repo: xuzhezhaozhao/Cairo-Tutorial

decompiled_code:
__int64 create_surfaces()
{
__int64 result; // rax

surface1 = cairo_image_surface_create_from_png();
surface2 = cairo_image_surface_create_from_png();
surface3 = cairo_image_surface_create_from_png();
result = cairo_image_surface_create_from_png();
surface4 = result;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

surface1 = cairo_image_surface_create_from_png();
surface2 = cairo_image_surface_create_from_png();
surface3 = cairo_image_surface_create_from_png();
result = cairo_image_surface_create_from_png();
surface4 = result;
return result;
}

original_code:
static void create_surfaces() {
 surface1 = cairo_image_surface_create_from_png("blueweb.png");
 surface2 = cairo_image_surface_create_from_png("maple.png");
 surface3 = cairo_image_surface_create_from_png("crack.png");
 surface4 = cairo_image_surface_create_from_png("chocolate.png");
}


decompiled_code:
__int64 destroy_surfaces()
{
cairo_surface_destroy();
cairo_surface_destroy();
cairo_surface_destroy();
return cairo_surface_destroy();
}

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

original_code:
static void destroy_surfaces() {
 cairo_surface_destroy(surface1);
 cairo_surface_destroy(surface2);
 cairo_surface_destroy(surface3);
 cairo_surface_destroy(surface4);
}


repo: xvocker/Ring-Buffer

decompiled_code:
void __noreturn terminate_handler()
{
msgctl(msg_id, 0, 0LL);
shmctl(shm_id, 0, 0LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7()
{
msgctl(msg_id, 0, 0LL);
shmctl(shm_id, 0, 0LL);
exit(0);
}

original_code:
void terminate_handler()
{
 msgctl(msg_id,0,((void *)0));
 shmctl(shm_id,0,((void *)0));
 exit(0);
}


decompiled_code:
int initial_reader()
{
key_t v0; // ebx
key_t v1; // eax
key_t v2; // ebp
int result; // eax

v0 = ftok("/tmp/shm_queue", 66);
v1 = ftok("/tmp/msg_queue_signal", 66);
if ( v0 == -1 || (v2 = v1, v1 == -1) )
{
perror("ftok");
exit(0);
}
while ( 1 )
{
shm_id = shmget(v0, 0LL, 0);
if ( shm_id != -1 )
break;
sleep(1u);
}
while ( 1 )
{
result = msgget(v2, 0);
msg_id = result;
if ( result != -1 )
break;
sleep(1u);
}
return result;
}

canonical_decompiled_code:
int func8()
{
key_t v0; // ebx
key_t v1; // eax
key_t v2; // ebp
int result; // eax

v0 = ftok("/tmp/shm_queue", 66);
v1 = ftok("/tmp/msg_queue_signal", 66);
if ( v0 == -1 || (v2 = v1, v1 == -1) )
{
perror("ftok");
exit(0);
}
while ( 1 )
{
shm_id = shmget(v0, 0LL, 0);
if ( shm_id != -1 )
break;
sleep(1u);
}
while ( 1 )
{
result = msgget(v2, 0);
msg_id = result;
if ( result != -1 )
break;
sleep(1u);
}
return result;
}

original_code:
void initial_reader()
{
 key_t msg_key,shm_key;
 shm_key = ftok(fileshm,'B');
 msg_key = ftok(filemsg, 'B');
 if(shm_key == -1 || msg_key == -1)
 {
  perror("ftok");
  exit(0);
 }
 shm_id = shmget(shm_key, 0, 0);
 while(shm_id == -1)
 {
  sleep(1);
  shm_id = shmget(shm_key, 0, 0);
 }
 msg_id = msgget(msg_key, 0);
 while(msg_id == -1)
 {
  sleep(1);
  msg_id = msgget(msg_key, 0);
 }
}

canonical_original_code:
void initial_reader()
{
 int msg_key; int shm_key;
 shm_key = ftok(fileshm,'B');
 msg_key = ftok(filemsg, 'B');
 if(shm_key == -1 || msg_key == -1)
 {
  perror("ftok");
  exit(0);
 }
 shm_id = shmget(shm_key, 0, 0);
 while(shm_id == -1)
 {
  sleep(1);
  shm_id = shmget(shm_key, 0, 0);
 }
 msg_id = msgget(msg_key, 0);
 while(msg_id == -1)
 {
  sleep(1);
  msg_id = msgget(msg_key, 0);
 }
}


decompiled_code:
unsigned int __fastcall reader_function(unsigned int a1, int a2, __int64 a3)
{
char v3; // r13
char v7; // r14
unsigned int result; // eax
__int64 v9; // [rsp+0h] [rbp-38h] BYREF

v3 = 0;
while ( 1 )
{
v7 = v3 ^ 1;
if ( a2 != a1 )
goto LABEL_4;
a2 = *(_DWORD *)(a3 + 15984);
if ( (unsigned int)msgrcv(msg_id, &v9, 0x10uLL, 300LL, 2048) != -1 )
{
result = puts("terminate signal receive");
if ( a1 == a2 )
return result;
v7 = 0;
v3 = 1;
LABEL_4:
printf(
"%u 0x%x %u \n",
*(unsigned int *)(a3 + 16LL * a1 + 12),
*(unsigned int *)(a3 + 16LL * a1 + 4),
*(unsigned int *)(a3 + 16LL * a1));
result = (a1 + 1) % 0x3E6;
*(_DWORD *)(a3 + 15968) = result;
a1 = result;
if ( result == a2 && !v7 )
return result;
}
}
}

canonical_decompiled_code:
unsigned int __fastcall func9(unsigned int a1, int a2, __int64 a3)
{
char v3; // r13
char v7; // r14
unsigned int result; // eax
__int64 v9; // [rsp+0h] [rbp-38h] BYREF

v3 = 0;
while ( 1 )
{
v7 = v3 ^ 1;
if ( a2 != a1 )
goto LABEL_4;
a2 = *(_DWORD *)(a3 + 15984);
if ( (unsigned int)msgrcv(msg_id, &v9, 0x10uLL, 300LL, 2048) != -1 )
{
result = puts("terminate signal receive");
if ( a1 == a2 )
return result;
v7 = 0;
v3 = 1;
LABEL_4:
printf(
"%u 0x%x %u \n",
*(unsigned int *)(a3 + 16LL * a1 + 12),
*(unsigned int *)(a3 + 16LL * a1 + 4),
*(unsigned int *)(a3 + 16LL * a1));
result = (a1 + 1) % 0x3E6;
*(_DWORD *)(a3 + 15968) = result;
a1 = result;
if ( result == a2 && !v7 )
return result;
}
}
}

original_code:
void reader_function(uint32_t head, uint32_t tail, Data *p_map)
{
 int terminate = 0;
 Signal signal;
 while(!terminate || head != tail)
 {
  while( head == tail )
  {
   tail = (p_map + 1000 - 1)->index;
   int ret = msgrcv(msg_id, &signal, sizeof(signal), 300, 04000);
   if( ret != -1)
   {
    terminate = 1;
    printf("terminate signal receive\n");
    break;
   }
  }
  if(terminate == 1 && head == tail)
   break;
  printf("%u 0x%x %u \n", (*(p_map + head)).cpuid, (*(p_map + head)).addr, (*(p_map + head)).index);
  head = (head + 1)%(1000 - 2);
  (p_map + 1000 - 2)->index = head;
 }
}

canonical_original_code:
void reader_function(unsigned int head, unsigned int tail, struct _Data *p_map)
{
 int terminate = 0;
 struct _Signal signal;
 while(!terminate || head != tail)
 {
  while( head == tail )
  {
   tail = (p_map + 1000 - 1)->index;
   int ret = msgrcv(msg_id, &signal, sizeof(signal), 300, 04000);
   if( ret != -1)
   {
    terminate = 1;
    printf("terminate signal receive\n");
    break;
   }
  }
  if(terminate == 1 && head == tail)
   break;
  printf("%u 0x%x %u \n", (*(p_map + head)).cpuid, (*(p_map + head)).addr, (*(p_map + head)).index);
  head = (head + 1)%(1000 - 2);
  (p_map + 1000 - 2)->index = head;
 }
}

variable_types:
head
unsigned int

variable_types:
tail
unsigned int

variable_types: struct _Data { unsigned int index; unsigned int addr; unsigned int type; unsigned int cpuid; } *

variable_types: terminate int

variable_types: struct _Signal { long type; int signal; }

variable_types: ret int


canonical_original_code:
void terminate_handler()
{
 msgctl(msg_id,0,((void *)0));
 shmctl(shm_id,0,((void *)0));
 exit(0);
}


decompiled_code:
int initial_writer()
{
key_t v0; // ebp
key_t v1; // eax
key_t v2; // er12
int result; // eax

v0 = ftok("/tmp/shm_queue", 66);
v1 = ftok("/tmp/msg_queue_signal", 66);
if ( v0 == -1 || (v2 = v1, v1 == -1) )
{
perror("ftok");
exit(0);
}
shm_id = shmget(v0, 0x3E80uLL, 1920);
if ( shm_id == -1 )
{
perror("shmget error");
exit(0);
}
result = msgget(v2, 1920);
msg_id = result;
if ( result == -1 )
{
perror("msgget error");
exit(0);
}
return result;
}

canonical_decompiled_code:
int func8()
{
key_t v0; // ebp
key_t v1; // eax
key_t v2; // er12
int result; // eax

v0 = ftok("/tmp/shm_queue", 66);
v1 = ftok("/tmp/msg_queue_signal", 66);
if ( v0 == -1 || (v2 = v1, v1 == -1) )
{
perror("ftok");
exit(0);
}
shm_id = shmget(v0, 0x3E80uLL, 1920);
if ( shm_id == -1 )
{
perror("shmget error");
exit(0);
}
result = msgget(v2, 1920);
msg_id = result;
if ( result == -1 )
{
perror("msgget error");
exit(0);
}
return result;
}

original_code:
void initial_writer()
{
 key_t msg_key,shm_key;
 shm_key = ftok(fileshm, 'B');
 msg_key = ftok(filemsg, 'B');
 if(shm_key == -1 || msg_key == -1)
 {
  perror ("ftok");
  exit(0);
 }
 shm_id = shmget(shm_key, 1000 * (sizeof(Data)), 01000 | 02000 | 0600);
 if(shm_id == -1)
 {
  perror("shmget error");
  exit(0);
 }
 msg_id = msgget(msg_key, 01000 | 02000 | 0600);
 if(msg_id == -1)
 {
  perror("msgget error");
  exit(0);
 }
}

canonical_original_code:
void initial_writer()
{
 int msg_key; int shm_key;
 shm_key = ftok(fileshm, 'B');
 msg_key = ftok(filemsg, 'B');
 if(shm_key == -1 || msg_key == -1)
 {
  perror ("ftok");
  exit(0);
 }
 shm_id = shmget(shm_key, 1000 * (sizeof(Data)), 01000 | 02000 | 0600);
 if(shm_id == -1)
 {
  perror("shmget error");
  exit(0);
 }
 msg_id = msgget(msg_key, 01000 | 02000 | 0600);
 if(msg_id == -1)
 {
  perror("msgget error");
  exit(0);
 }
}


decompiled_code:
void __fastcall free_mem2D(void *ptr, __int64 a2, const char *a3)
{
void *v4; // rdi

if ( ptr )
{
v4 = *(void **)ptr;
if ( v4 )
free(v4);
else
error((int)"free_mem2D: trying to free unused memory", 100, a3);
free(ptr);
}
else
{
error((int)"free_mem2D: trying to free unused memory", 100, a3);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr, __int64 a2, const char *a3)
{
void *v4; // rdi

if ( ptr )
{
v4 = *(void **)ptr;
if ( v4 )
free(v4);
else
error((int)"free_mem2D: trying to free unused memory", 100, a3);
free(ptr);
}
else
{
error((int)"free_mem2D: trying to free unused memory", 100, a3);
}
}

original_code:
void free_mem2D(byte **array2D)
{
    if (array2D)
    {
        if (array2D[0])
            free (array2D[0]);
        else error ("free_mem2D: trying to free unused memory",100);
        free (array2D);
    }
    else
    {
        error ("free_mem2D: trying to free unused memory",100);
    }
}

canonical_original_code:
void free_mem2D(unsigned char **array2D)
{
    if (array2D)
    {
        if (array2D[0])
            free (array2D[0]);
        else error ("free_mem2D: trying to free unused memory",100);
        free (array2D);
    }
    else
    {
        error ("free_mem2D: trying to free unused memory",100);
    }
}


decompiled_code:
void __fastcall free_mem2Dint(void *ptr, __int64 a2, const char *a3)
{
void *v4; // rdi

if ( ptr )
{
v4 = *(void **)ptr;
if ( v4 )
free(v4);
else
error((int)"free_mem2D: trying to free unused memory", 100, a3);
free(ptr);
}
else
{
error((int)"free_mem2D: trying to free unused memory", 100, a3);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr, __int64 a2, const char *a3)
{
void *v4; // rdi

if ( ptr )
{
v4 = *(void **)ptr;
if ( v4 )
free(v4);
else
error((int)"free_mem2D: trying to free unused memory", 100, a3);
free(ptr);
}
else
{
error((int)"free_mem2D: trying to free unused memory", 100, a3);
}
}

original_code:
void free_mem2Dint(int **array2D)
{
    if (array2D)
    {
        if (array2D[0])
            free (array2D[0]);
        else error ("free_mem2D: trying to free unused memory",100);
        free (array2D);
    }
    else
    {
        error ("free_mem2D: trying to free unused memory",100);
    }
}


decompiled_code:
void __fastcall free_mem3D(void *ptr, __int64 a2, const char *a3)
{
void *v3; // r12
void **v4; // rbx
void **v5; // rbp
void *v6; // rdi

if ( ptr )
{
v3 = ptr;
if ( (int)a2 > 0 )
{
v4 = (void **)ptr;
v5 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v6 = *v4++;
free_mem2D(v6, a2, a3);
}
while ( v4 != v5 );
}
free(v3);
}
else
{
error((int)"free_mem3D: trying to free unused memory", 100, a3);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, __int64 a2, const char *a3)
{
void *v3; // r12
void **v4; // rbx
void **v5; // rbp
void *v6; // rdi

if ( ptr )
{
v3 = ptr;
if ( (int)a2 > 0 )
{
v4 = (void **)ptr;
v5 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v6 = *v4++;
func0(v6, a2, a3);
}
while ( v4 != v5 );
}
free(v3);
}
else
{
error((int)"free_mem3D: trying to free unused memory", 100, a3);
}
}

original_code:
void free_mem3D(byte ***array3D, int frames)
{
    int i;
    if (array3D)
    {
        for (i=0;i<frames;i++)
        {
            free_mem2D(array3D[i]);
        }
        free (array3D);
    }
    else
    {
        error ("free_mem3D: trying to free unused memory",100);
    }
}

canonical_original_code:
void free_mem3D(unsigned char ***array3D, int frames)
{
    int i;
    if (array3D)
    {
        for (i=0;i<frames;i++)
        {
            free_mem2D(array3D[i]);
        }
        free (array3D);
    }
    else
    {
        error ("free_mem3D: trying to free unused memory",100);
    }
}

variable_types: frames int

variable_types: i int


decompiled_code:
void __fastcall free_mem3Dint(void *ptr, __int64 a2, const char *a3)
{
void *v3; // r12
void **v4; // rbx
void **v5; // rbp
void *v6; // rdi

if ( ptr )
{
v3 = ptr;
if ( (int)a2 > 0 )
{
v4 = (void **)ptr;
v5 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v6 = *v4++;
free_mem2Dint(v6, a2, a3);
}
while ( v4 != v5 );
}
free(v3);
}
else
{
error((int)"free_mem3D: trying to free unused memory", 100, a3);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr, __int64 a2, const char *a3)
{
void *v3; // r12
void **v4; // rbx
void **v5; // rbp
void *v6; // rdi

if ( ptr )
{
v3 = ptr;
if ( (int)a2 > 0 )
{
v4 = (void **)ptr;
v5 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v6 = *v4++;
func1(v6, a2, a3);
}
while ( v4 != v5 );
}
free(v3);
}
else
{
error((int)"free_mem3D: trying to free unused memory", 100, a3);
}
}

original_code:
void free_mem3Dint(int ***array3D, int frames)
{
    int i;
    if (array3D)
    {
        for (i=0;i<frames;i++)
        {
            free_mem2Dint(array3D[i]);
        }
        free (array3D);
    }
    else
    {
        error ("free_mem3D: trying to free unused memory",100);
    }
}


decompiled_code:
void __fastcall free_mem4Dint(void *ptr, int a2, const char *a3)
{
void *v3; // r13
unsigned int v4; // ebp
void **v5; // rbx
void **v6; // r12
void *v7; // rdi

if ( ptr )
{
v3 = ptr;
if ( a2 > 0 )
{
v4 = (unsigned int)a3;
v5 = (void **)ptr;
v6 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v7 = *v5++;
free_mem3Dint(v7, v4, a3);
}
while ( v5 != v6 );
}
free(v3);
}
else
{
error((int)"free_mem4D: trying to free unused memory", 100, a3);
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr, int a2, const char *a3)
{
void *v3; // r13
unsigned int v4; // ebp
void **v5; // rbx
void **v6; // r12
void *v7; // rdi

if ( ptr )
{
v3 = ptr;
if ( a2 > 0 )
{
v4 = (unsigned int)a3;
v5 = (void **)ptr;
v6 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v7 = *v5++;
func3(v7, v4, a3);
}
while ( v5 != v6 );
}
free(v3);
}
else
{
error((int)"free_mem4D: trying to free unused memory", 100, a3);
}
}

original_code:
void free_mem4Dint(int ****array4D, int idx, int frames )
{
    int j;
    if (array4D)
    {
        for(j=0;j<idx;j++)
            free_mem3Dint( array4D[j], frames) ;
        free (array4D);
    }
    else
    {
        error ("free_mem4D: trying to free unused memory",100);
    }
}

canonical_original_code:
void free_mem4Dint(int ****array4D, int idx, int frames)
{
    int j;
    if (array4D)
    {
        for(j=0;j<idx;j++)
            free_mem3Dint( array4D[j], frames) ;
        free (array4D);
    }
    else
    {
        error ("free_mem4D: trying to free unused memory",100);
    }
}

variable_types: idx int

variable_types: j int


decompiled_code:
void __fastcall no_mem_exit(const char *a1)
{
const char *v1; // rdx

snprintf(errortext, 0x12CuLL, "Could not allocate memory: %s", a1);
error((int)errortext, 100, v1);
}

canonical_decompiled_code:
void __fastcall func5(const char *a1)
{
const char *v1; // rdx

snprintf(errortext, 0x12CuLL, "Could not allocate memory: %s", a1);
error((int)errortext, 100, v1);
}

original_code:
void no_mem_exit(char *where)
{
    snprintf(errortext, 300, "Could not allocate memory: %s",where);
    error (errortext, 100);
}

variable_types:
where
char *


decompiled_code:
__int64 __fastcall get_mem2D(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
void *v6; // rax
_QWORD *v7; // rdx
__int64 v8; // rax
__int64 v9; // rdi

v4 = calloc(a2, 8uLL);
*a1 = v4;
if ( v4 )
{
v5 = v4;
}
else
{
no_mem_exit("get_mem2D: array2D");
v5 = (_QWORD *)*a1;
}
v6 = calloc(a3 * a2, 1uLL);
*v5 = v6;
if ( !v6 )
no_mem_exit("get_mem2D: array2D");
if ( a2 > 1 )
{
v7 = (_QWORD *)*a1;
v8 = *a1 + 8LL;
v9 = v8 + 8LL * (unsigned int)(a2 - 2);
while ( 1 )
{
v7[1] = a3 + *v7;
v7 = (_QWORD *)v8;
if ( v8 == v9 )
break;
v8 += 8LL;
}
}
return (unsigned int)(a3 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
void *v6; // rax
_QWORD *v7; // rdx
__int64 v8; // rax
__int64 v9; // rdi

v4 = calloc(a2, 8uLL);
*a1 = v4;
if ( v4 )
{
v5 = v4;
}
else
{
func5("get_mem2D: array2D");
v5 = (_QWORD *)*a1;
}
v6 = calloc(a3 * a2, 1uLL);
*v5 = v6;
if ( !v6 )
func5("get_mem2D: array2D");
if ( a2 > 1 )
{
v7 = (_QWORD *)*a1;
v8 = *a1 + 8LL;
v9 = v8 + 8LL * (unsigned int)(a2 - 2);
while ( 1 )
{
v7[1] = a3 + *v7;
v7 = (_QWORD *)v8;
if ( v8 == v9 )
break;
v8 += 8LL;
}
}
return (unsigned int)(a3 * a2);
}

original_code:
int get_mem2D(byte ***array2D, int rows, int columns)
{
    int i;
    if((*array2D = (byte**)calloc(rows, sizeof(byte*))) == ((void *)0))
        no_mem_exit("get_mem2D: array2D");
    if(((*array2D)[0] = (byte* )calloc(columns*rows,sizeof(byte ))) == ((void *)0))
        no_mem_exit("get_mem2D: array2D");
    for(i=1;i<rows;i++)
        (*array2D)[i] = (*array2D)[i-1] + columns ;
    return rows*columns;
}

canonical_original_code:
int get_mem2D(unsigned char ***array2D, int rows, int columns)
{
    int i;
    if((*array2D = (unsigned char **)calloc(rows, sizeof(unsigned char *))) == ((void *)0))
        no_mem_exit("get_mem2D: array2D");
    if(((*array2D)[0] = (unsigned char * )calloc(columns*rows,sizeof(byte ))) == ((void *)0))
        no_mem_exit("get_mem2D: array2D");
    for(i=1;i<rows;i++)
        (*array2D)[i] = (*array2D)[i-1] + columns ;
    return rows*columns;
}

variable_types: rows int

variable_types: columns int


decompiled_code:
__int64 __fastcall get_mem2Dint(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
void *v6; // rax
_QWORD *v7; // rdx
__int64 v8; // rax
__int64 v9; // rdi

v4 = calloc(a2, 8uLL);
*a1 = v4;
if ( v4 )
{
v5 = v4;
}
else
{
no_mem_exit("get_mem2Dint: array2D");
v5 = (_QWORD *)*a1;
}
v6 = calloc(a3 * a2, 4uLL);
*v5 = v6;
if ( !v6 )
no_mem_exit("get_mem2Dint: array2D");
if ( a2 > 1 )
{
v7 = (_QWORD *)*a1;
v8 = *a1 + 8LL;
v9 = v8 + 8LL * (unsigned int)(a2 - 2);
while ( 1 )
{
v7[1] = 4LL * a3 + *v7;
v7 = (_QWORD *)v8;
if ( v8 == v9 )
break;
v8 += 8LL;
}
}
return (unsigned int)(4 * a3 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, int a2, int a3)
{
_QWORD *v4; // rax
_QWORD *v5; // r12
void *v6; // rax
_QWORD *v7; // rdx
__int64 v8; // rax
__int64 v9; // rdi

v4 = calloc(a2, 8uLL);
*a1 = v4;
if ( v4 )
{
v5 = v4;
}
else
{
func5("get_mem2Dint: array2D");
v5 = (_QWORD *)*a1;
}
v6 = calloc(a3 * a2, 4uLL);
*v5 = v6;
if ( !v6 )
func5("get_mem2Dint: array2D");
if ( a2 > 1 )
{
v7 = (_QWORD *)*a1;
v8 = *a1 + 8LL;
v9 = v8 + 8LL * (unsigned int)(a2 - 2);
while ( 1 )
{
v7[1] = 4LL * a3 + *v7;
v7 = (_QWORD *)v8;
if ( v8 == v9 )
break;
v8 += 8LL;
}
}
return (unsigned int)(4 * a3 * a2);
}

original_code:
int get_mem2Dint(int ***array2D, int rows, int columns)
{
    int i;
    if((*array2D = (int**)calloc(rows, sizeof(int*))) == ((void *)0))
        no_mem_exit("get_mem2Dint: array2D");
    if(((*array2D)[0] = (int* )calloc(rows*columns,sizeof(int ))) == ((void *)0))
        no_mem_exit("get_mem2Dint: array2D");
    for(i=1 ; i<rows ; i++)
        (*array2D)[i] = (*array2D)[i-1] + columns ;
    return rows*columns*sizeof(int);
}

canonical_original_code:
int get_mem2Dint(int ***array2D, int rows, int columns)
{
    int i;
    if((*array2D = (int **)calloc(rows, sizeof(int *))) == ((void *)0))
        no_mem_exit("get_mem2Dint: array2D");
    if(((*array2D)[0] = (int * )calloc(rows*columns,sizeof(int ))) == ((void *)0))
        no_mem_exit("get_mem2Dint: array2D");
    for(i=1 ; i<rows ; i++)
        (*array2D)[i] = (*array2D)[i-1] + columns ;
    return rows*columns*sizeof(int);
}


decompiled_code:
__int64 __fastcall get_mem3D(_QWORD *a1, int a2, int a3, int a4)
{
void *v7; // rax
__int64 v8; // rbx
_QWORD *v9; // rdi

v7 = calloc(a2, 8uLL);
*a1 = v7;
if ( !v7 )
no_mem_exit("get_mem3D: array3D");
if ( a2 > 0 )
{
v8 = 0LL;
do
{
v9 = (_QWORD *)(v8 + *a1);
v8 += 8LL;
get_mem2D(v9, a3, a4);
}
while ( 8LL * a2 != v8 );
}
return (unsigned int)(a4 * a3 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, int a3, int a4)
{
void *v7; // rax
__int64 v8; // rbx
_QWORD *v9; // rdi

v7 = calloc(a2, 8uLL);
*a1 = v7;
if ( !v7 )
func5("get_mem3D: array3D");
if ( a2 > 0 )
{
v8 = 0LL;
do
{
v9 = (_QWORD *)(v8 + *a1);
v8 += 8LL;
func6(v9, a3, a4);
}
while ( 8LL * a2 != v8 );
}
return (unsigned int)(a4 * a3 * a2);
}

original_code:
int get_mem3D(byte ****array3D, int frames, int rows, int columns)
{
    int j;
    if(((*array3D) = (byte***)calloc(frames,sizeof(byte**))) == ((void *)0))
        no_mem_exit("get_mem3D: array3D");
    for(j=0;j<frames;j++)
        get_mem2D( (*array3D)+j, rows, columns ) ;
    return frames*rows*columns;
}

canonical_original_code:
int get_mem3D(unsigned char ****array3D, int frames, int rows, int columns)
{
    int j;
    if(((*array3D) = (unsigned char ***)calloc(frames,sizeof(unsigned char **))) == ((void *)0))
        no_mem_exit("get_mem3D: array3D");
    for(j=0;j<frames;j++)
        get_mem2D( (*array3D)+j, rows, columns ) ;
    return frames*rows*columns;
}


decompiled_code:
__int64 __fastcall get_mem3Dint(_QWORD *a1, int a2, int a3, int a4)
{
void *v7; // rax
__int64 v8; // rbx
_QWORD *v9; // rdi

v7 = calloc(a2, 8uLL);
*a1 = v7;
if ( !v7 )
no_mem_exit("get_mem3Dint: array3D");
if ( a2 > 0 )
{
v8 = 0LL;
do
{
v9 = (_QWORD *)(v8 + *a1);
v8 += 8LL;
get_mem2Dint(v9, a3, a4);
}
while ( 8LL * a2 != v8 );
}
return (unsigned int)(4 * a3 * a2 * a4);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, int a2, int a3, int a4)
{
void *v7; // rax
__int64 v8; // rbx
_QWORD *v9; // rdi

v7 = calloc(a2, 8uLL);
*a1 = v7;
if ( !v7 )
func5("get_mem3Dint: array3D");
if ( a2 > 0 )
{
v8 = 0LL;
do
{
v9 = (_QWORD *)(v8 + *a1);
v8 += 8LL;
func7(v9, a3, a4);
}
while ( 8LL * a2 != v8 );
}
return (unsigned int)(4 * a3 * a2 * a4);
}

original_code:
int get_mem3Dint(int ****array3D, int frames, int rows, int columns)
{
    int j;
    if(((*array3D) = (int***)calloc(frames,sizeof(int**))) == ((void *)0))
        no_mem_exit("get_mem3Dint: array3D");
    for(j=0;j<frames;j++)
        get_mem2Dint( (*array3D)+j, rows, columns ) ;
    return frames*rows*columns*sizeof(int);
}

canonical_original_code:
int get_mem3Dint(int ****array3D, int frames, int rows, int columns)
{
    int j;
    if(((*array3D) = (int ***)calloc(frames,sizeof(int **))) == ((void *)0))
        no_mem_exit("get_mem3Dint: array3D");
    for(j=0;j<frames;j++)
        get_mem2Dint( (*array3D)+j, rows, columns ) ;
    return frames*rows*columns*sizeof(int);
}


decompiled_code:
__int64 __fastcall get_mem4Dint(_QWORD *a1, int a2, int a3, int a4, int a5)
{
void *v9; // rax
__int64 v10; // rbx
_QWORD *v11; // rdi

v9 = calloc(a2, 8uLL);
*a1 = v9;
if ( !v9 )
no_mem_exit("get_mem4Dint: array4D");
if ( a2 > 0 )
{
v10 = 0LL;
do
{
v11 = (_QWORD *)(v10 + *a1);
v10 += 8LL;
get_mem3Dint(v11, a3, a4, a5);
}
while ( 8LL * a2 != v10 );
}
return (unsigned int)(4 * a4 * a3 * a2 * a5);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, int a2, int a3, int a4, int a5)
{
void *v9; // rax
__int64 v10; // rbx
_QWORD *v11; // rdi

v9 = calloc(a2, 8uLL);
*a1 = v9;
if ( !v9 )
func5("get_mem4Dint: array4D");
if ( a2 > 0 )
{
v10 = 0LL;
do
{
v11 = (_QWORD *)(v10 + *a1);
v10 += 8LL;
func9(v11, a3, a4, a5);
}
while ( 8LL * a2 != v10 );
}
return (unsigned int)(4 * a4 * a3 * a2 * a5);
}

original_code:
int get_mem4Dint(int *****array4D, int idx, int frames, int rows, int columns )
{
    int j;
    if(((*array4D) = (int****)calloc(idx,sizeof(int**))) == ((void *)0))
        no_mem_exit("get_mem4Dint: array4D");
    for(j=0;j<idx;j++)
        get_mem3Dint( (*array4D)+j, frames, rows, columns ) ;
    return idx*frames*rows*columns*sizeof(int);
}

canonical_original_code:
int get_mem4Dint(int *****array4D, int idx, int frames, int rows, int columns)
{
    int j;
    if(((*array4D) = (int ****)calloc(idx,sizeof(int **))) == ((void *)0))
        no_mem_exit("get_mem4Dint: array4D");
    for(j=0;j<idx;j++)
        get_mem3Dint( (*array4D)+j, frames, rows, columns ) ;
    return idx*frames*rows*columns*sizeof(int);
}


CloseBitstreamFile

decompiled_code:
int CloseBitstreamFile()
{
return CloseIRABS((FILE **)pIRABS);
}

canonical_decompiled_code:
int func6()
{
return func1((FILE **)pIRABS);
}

original_code:
void CloseBitstreamFile()
{
    CloseIRABS(pIRABS);
}


IsEndOfBitstream

decompiled_code:
_BOOL8 IsEndOfBitstream()
{
return feof(*(FILE **)pIRABS) != 0;
}

canonical_decompiled_code:
_BOOL8 func7()
{
return feof(*(FILE **)pIRABS) != 0;
}

original_code:
int IsEndOfBitstream ()
{
    int ret=feof(pIRABS->f);
    return ((!ret)?(0):(1));
}

canonical_original_code:
int IsEndOfBitstream()
{
    int ret = feof(pIRABS->f);
    return ((!ret)?(0):(1));
}


checkstartcode

decompiled_code:
__int64 checkstartcode()
{
int v0; // eax
int v1; // edi
__int64 v2; // rdi
_BOOL4 v3; // er12
__int64 v5; // rdi

v0 = *(_DWORD *)(currStream + 8LL);
v1 = 8 * *(_DWORD *)(currStream + 12LL);
if ( v1 == v0 )
return 1LL;
if ( *(_DWORD *)(img + 4LL) )
goto LABEL_3;
v5 = (unsigned int)(v1 - v0);
if ( (unsigned int)(v5 - 1) > 7 || (get_uv(v5, "filling data"), !*(_DWORD *)(img + 4LL)) )
{
if ( (unsigned int)(StartCodePosition - 5) > 0xFFFF9 )
{
*(_DWORD *)(currStream + 8LL) = currentbitoffset;
return 0LL;
}
return 1LL;
}
v0 = *(_DWORD *)(currStream + 8LL);
v1 = 8 * *(_DWORD *)(currStream + 12LL);
LABEL_3:
v2 = (unsigned int)(v1 - v0);
if ( (unsigned int)(v2 - 1) <= 7 && 1 << (v2 - 1) == (unsigned int)get_uv(v2, "filling data") )
v3 = *(_DWORD *)(img + 6264LL) <= 0;
else
v3 = 0;
return v3;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v1; // edi
__int64 v2; // rdi
_BOOL4 v3; // er12
__int64 v5; // rdi

v0 = *(_DWORD *)(currStream + 8LL);
v1 = 8 * *(_DWORD *)(currStream + 12LL);
if ( v1 == v0 )
return 1LL;
if ( *(_DWORD *)(img + 4LL) )
goto LABEL_3;
v5 = (unsigned int)(v1 - v0);
if ( (unsigned int)(v5 - 1) > 7 || (get_uv(v5, "filling data"), !*(_DWORD *)(img + 4LL)) )
{
if ( (unsigned int)(StartCodePosition - 5) > 0xFFFF9 )
{
*(_DWORD *)(currStream + 8LL) = currentbitoffset;
return 0LL;
}
return 1LL;
}
v0 = *(_DWORD *)(currStream + 8LL);
v1 = 8 * *(_DWORD *)(currStream + 12LL);
LABEL_3:
v2 = (unsigned int)(v1 - v0);
if ( (unsigned int)(v2 - 1) <= 7 && 1 << (v2 - 1) == (unsigned int)get_uv(v2, "filling data") )
v3 = *(_DWORD *)(img + 6264LL) <= 0;
else
v3 = 0;
return v3;
}

original_code:
int checkstartcode()
{
    int temp_i, temp_val;
    if (currStream->bitstream_length*8 - currStream->frame_bitoffset == 0)
        return 1;
    if(img->current_mb_nr == 0)
    {
        if ( currStream->bitstream_length*8 - currStream->frame_bitoffset <=8
            && currStream->bitstream_length*8 - currStream->frame_bitoffset > 0 ){
                temp_i = currStream->bitstream_length*8 - currStream->frame_bitoffset;
                ((void) sizeof ((temp_i > 0) ? 1 : 0), __extension__ ({ if (temp_i > 0) ; else __assert_fail ("temp_i > 0", "src/bitstream.c", 301, __extension__ __PRETTY_FUNCTION__); }));
                temp_val = get_uv(temp_i, "filling data") ;
        }
    }
    if(img->current_mb_nr == 0)
    {
        if(StartCodePosition>4 && StartCodePosition<0x000fffff)
            return 1;
        else
        {
            currStream->frame_bitoffset = currentbitoffset;
            return 0;
        }
    }
    if(img->current_mb_nr != 0)
    {
        if (currStream->bitstream_length*8 - currStream->frame_bitoffset <= 8
            && currStream->bitstream_length*8 - currStream->frame_bitoffset >0){
                temp_i = currStream->bitstream_length*8 - currStream->frame_bitoffset;
                ((void) sizeof ((temp_i > 0) ? 1 : 0), __extension__ ({ if (temp_i > 0) ; else __assert_fail ("temp_i > 0", "src/bitstream.c", 335, __extension__ __PRETTY_FUNCTION__); }));
                temp_val = get_uv(temp_i, "filling data") ;
                if ( temp_val == (1 << (temp_i -1)) && img->cod_counter <= 0 )
                    return 1;
        }
        return 0;
    }
    return 1;
}

canonical_original_code:
int checkstartcode()
{
    int temp_i; int temp_val;
    if (currStream->bitstream_length*8 - currStream->frame_bitoffset == 0)
        return 1;
    if(img->current_mb_nr == 0)
    {
        if ( currStream->bitstream_length*8 - currStream->frame_bitoffset <=8
            && currStream->bitstream_length*8 - currStream->frame_bitoffset > 0 ){
                temp_i = currStream->bitstream_length*8 - currStream->frame_bitoffset;
                ((void) sizeof ((temp_i > 0) ? 1 : 0), __extension__ ({ if (temp_i > 0) ; else __assert_fail ("temp_i > 0", "src/bitstream.c", 301, __extension__ __PRETTY_FUNCTION__); }));
                temp_val = get_uv(temp_i, "filling data") ;
        }
    }
    if(img->current_mb_nr == 0)
    {
        if(StartCodePosition>4 && StartCodePosition<0x000fffff)
            return 1;
        else
        {
            currStream->frame_bitoffset = currentbitoffset;
            return 0;
        }
    }
    if(img->current_mb_nr != 0)
    {
        if (currStream->bitstream_length*8 - currStream->frame_bitoffset <= 8
            && currStream->bitstream_length*8 - currStream->frame_bitoffset >0){
                temp_i = currStream->bitstream_length*8 - currStream->frame_bitoffset;
                ((void) sizeof ((temp_i > 0) ? 1 : 0), __extension__ ({ if (temp_i > 0) ; else __assert_fail ("temp_i > 0", "src/bitstream.c", 335, __extension__ __PRETTY_FUNCTION__); }));
                temp_val = get_uv(temp_i, "filling data") ;
                if ( temp_val == (1 << (temp_i -1)) && img->cod_counter <= 0 )
                    return 1;
        }
        return 0;
    }
    return 1;
}


CheckType

decompiled_code:
__int64 __fastcall CheckType(unsigned __int8 a1)
{
__int64 result; // rax

demulate_enable = (unsigned int)a1 - 176 > 5 || (result = 1LL << (a1 + 80), (result & 0x25) == 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
__int64 result; // rax

demulate_enable = (unsigned int)a1 - 176 > 5 || (result = 1LL << (a1 + 80), (result & 0x25) == 0);
return result;
}

original_code:
void CheckType(int startcode){
    startcode = startcode&0x000000ff;
    switch(startcode)
    {
    case 0xb0:
    case 0xb2:
    case 0xb5:
        demulate_enable = 0;
        break;
    default:
        demulate_enable = 1;
        break;
    }
}

variable_types: startcode int


GetOneUnit

decompiled_code:
__int64 __fastcall GetOneUnit(__int64 a1, _DWORD *a2, unsigned int *a3)
{
int v5; // eax
_DWORD *v6; // rdi
__int64 v7; // rbx
unsigned int v8; // er12
int v9; // ebx
__int64 v11; // rdx
int v12; // er12
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = NextStartCode((__int64)pIRABS);
if ( v5 )
{
v12 = v5;
if ( v5 == -1 )
{
printf("\narrive at stream end and start code is not found!");
}
else if ( v5 == -2 )
{
printf("\np->iBytePosition error!");
}
exit(v12);
}
*(_BYTE *)(a1 + 2) = 1;
*(_WORD *)a1 = 0;
v6 = pIRABS;
*a2 = 3;
v7 = 4LL;
read_n_bit(v6, 8, v13);
LOBYTE(v6) = v13[0];
*(_BYTE *)(a1 + 3) = v13[0];
CheckType((unsigned __int8)v6);
while ( 1 )
{
v8 = v7;
if ( (int)read_n_bit(pIRABS, 8, v13) < 0 )
break;
*(_BYTE *)(a1 + v7++) = v13[0];
}
v9 = *((_DWORD *)pIRABS + 262);
if ( v9 > 0 )
{
read_n_bit(pIRABS, v9, v13);
if ( v13[0] )
{
v11 = (int)v8++;
*(_BYTE *)(a1 + v11) = v13[0] << (8 - v9);
}
}
*a3 = v8;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _DWORD *a2, unsigned int *a3)
{
int v5; // eax
_DWORD *v6; // rdi
__int64 v7; // rbx
unsigned int v8; // er12
int v9; // ebx
__int64 v11; // rdx
int v12; // er12
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = func2((__int64)pIRABS);
if ( v5 )
{
v12 = v5;
if ( v5 == -1 )
{
printf("\narrive at stream end and start code is not found!");
}
else if ( v5 == -2 )
{
printf("\np->iBytePosition error!");
}
exit(v12);
}
*(_BYTE *)(a1 + 2) = 1;
*(_WORD *)a1 = 0;
v6 = pIRABS;
*a2 = 3;
v7 = 4LL;
func4(v6, 8, v13);
LOBYTE(v6) = v13[0];
*(_BYTE *)(a1 + 3) = v13[0];
func9((unsigned __int8)v6);
while ( 1 )
{
v8 = v7;
if ( (int)func4(pIRABS, 8, v13) < 0 )
break;
*(_BYTE *)(a1 + v7++) = v13[0];
}
v9 = *((_DWORD *)pIRABS + 262);
if ( v9 > 0 )
{
func4(pIRABS, v9, v13);
if ( v13[0] )
{
v11 = (int)v8++;
*(_BYTE *)(a1 + v11) = v13[0] << (8 - v9);
}
}
*a3 = v8;
return v8;
}

original_code:
int GetOneUnit (char *buf,int *startcodepos,int *length)
{
    int i,j,k;
    i = NextStartCode(pIRABS);
    if(i!=0)
    {
        if(i==-1) printf("\narrive at stream end and start code is not found!");
        if(i==-2) printf("\np->iBytePosition error!");
        exit(i);
    }
    buf[0] = 0;
    buf[1] = 0;
    buf[2] = 1;
    *startcodepos = 3;
    i = read_n_bit(pIRABS,8,&j);
    buf[3] = (char)j;
    CheckType(buf[3]);
    if(buf[3]==0xB1)
    {
        *length = 4;
        return -1;
    }
    k = 4;
    while(1)
    {
        i = read_n_bit(pIRABS,8,&j);
        if(i<0) break;
        buf[k++] = (char)j;
    }
    if(pIRABS->iClearBitsNum>0)
    {
        int shift;
        shift = 8 - pIRABS->iClearBitsNum;
        i = read_n_bit(pIRABS,pIRABS->iClearBitsNum,&j);
        if(j!=0)
            buf[k++] = (char)(j<<shift);
    }
    *length = k;
    return k;
}

canonical_original_code:
int GetOneUnit(char *buf, int *startcodepos, int *length)
{
    int i; int j; int k;
    i = NextStartCode(pIRABS);
    if(i!=0)
    {
        if(i==-1) printf("\narrive at stream end and start code is not found!");
        if(i==-2) printf("\np->iBytePosition error!");
        exit(i);
    }
    buf[0] = 0;
    buf[1] = 0;
    buf[2] = 1;
    *startcodepos = 3;
    i = read_n_bit(pIRABS,8,&j);
    buf[3] = (char)j;
    CheckType(buf[3]);
    if(buf[3]==0xB1)
    {
        *length = 4;
        return -1;
    }
    k = 4;
    while(1)
    {
        i = read_n_bit(pIRABS,8,&j);
        if(i<0) break;
        buf[k++] = (char)j;
    }
    if(pIRABS->iClearBitsNum>0)
    {
        int shift;
        shift = 8 - pIRABS->iClearBitsNum;
        i = read_n_bit(pIRABS,pIRABS->iClearBitsNum,&j);
        if(j!=0)
            buf[k++] = (char)(j<<shift);
    }
    *length = k;
    return k;
}

variable_types:
buf
char *

variable_types:
startcodepos
int *

variable_types:
length
int *

variable_types: k int

variable_types: shift int


original_code:
void copy_Pframe(struct img_par *img)
{
    int i,j;
    for(i=0;i<img->height;i++)
        for(j=0;j<img->width;j++)
        {
            imgY_prev[i][j] = imgY[i][j];
        }
        for(i=0;i<img->height_cr;i++)
            for(j=0;j<img->width_cr;j++)
            {
                imgUV_prev[0][i][j] = imgUV[0][i][j];
            }
            for(i=0;i<img->height_cr;i++)
                for(j=0;j<img->width_cr;j++)
                {
                    imgUV_prev[1][i][j] = imgUV[1][i][j];
                }
}

canonical_original_code:
void copy_Pframe(struct img_par *img)
{
    int i; int j;
    for(i=0;i<img->height;i++)
        for(j=0;j<img->width;j++)
        {
            imgY_prev[i][j] = imgY[i][j];
        }
        for(i=0;i<img->height_cr;i++)
            for(j=0;j<img->width_cr;j++)
            {
                imgUV_prev[0][i][j] = imgUV[0][i][j];
            }
            for(i=0;i<img->height_cr;i++)
                for(j=0;j<img->width_cr;j++)
                {
                    imgUV_prev[1][i][j] = imgUV[1][i][j];
                }
}

variable_types: struct img_par { int number; int current_mb_nr; int max_mb_nr; int current_slice_nr; int **intra_block; int tr; int qp; int type; int width; int height; int width_cr; int height_cr; int mb_y; int mb_x; int block_y; int pix_y; int pix_x; int pix_c_y; int block_x; int pix_c_x; int ***mv; int mpr[16][16]; int m7[16][16]; int m8[4][8][8]; int cof[4][8][4][4]; int cofu[4]; int **ipredmode; int quad[256]; int cod_counter; int ***dfMV; int ***dbMV; int **fw_refFrArr; int **bw_refFrArr; int ***mv_frm; int **fw_refFrArr_frm; int **bw_refFrArr_frm; int imgtr_next_P; int imgtr_last_P; int tr_frm; int tr_fld; int imgtr_last_prev_P; int no_forward_reference; int seq_header_indicate; int B_discard_flag; int ***fw_mv; int ***bw_mv; int subblock_x; int subblock_y; int buf_cycle; int direct_type; int ***mv_top; int ***mv_bot; int **fw_refFrArr_top; int **bw_refFrArr_top; int **fw_refFrArr_bot; int **bw_refFrArr_bot; int **ipredmode_top; int **ipredmode_bot; int ***fw_mv_top; int ***fw_mv_bot; int ***bw_mv_top; int ***bw_mv_bot; int ***dfMV_top; int ***dbMV_top; int ***dfMV_bot; int ***dbMV_bot; int toppoc; int bottompoc; int framepoc; unsigned int frame_num; unsigned int pic_distance; int delta_pic_order_cnt_bottom; int PicDistanceMsb; unsigned int PrevPicDistanceLsb; int CurrPicDistanceMsb; unsigned int ThisPOC; int PicWidthInMbs; int PicHeightInMbs; int PicSizeInMbs; int block8_x; int structure; int pn; int buf_used; int buf_size; int picture_structure; int advanced_pred_mode_disable; int types; int current_mb_nr_fld; int slice_weighting_flag; int lum_scale[4]; int lum_shift[4]; int chroma_scale[4]; int chroma_shift[4]; int mb_weighting_flag; int weighting_prediction; int mpr_weight[16][16]; int top_bot; int Bframe_number; int auto_crop_right; int auto_crop_bottom; } *


original_code:
void init_macroblock_Bframe(struct img_par *img)
{
    int i,j,k;
    Macroblock *currMB = &mb_data[img->current_mb_nr];
    for (i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            img->dfMV [img->block_x+i+4][img->block_y+j][0]=img->dfMV[img->block_x+i+4][img->block_y+j][1]=0;
            img->dbMV [img->block_x+i+4][img->block_y+j][0]=img->dbMV[img->block_x+i+4][img->block_y+j][1]=0;
            img->fw_mv[img->block_x+i+4][img->block_y+j][0]=img->fw_mv[img->block_x+i+4][img->block_y+j][1]=0;
            img->bw_mv[img->block_x+i+4][img->block_y+j][0]=img->bw_mv[img->block_x+i+4][img->block_y+j][1]=0;
        }
    }
    for (i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            img->ipredmode[img->block_x+i+1][img->block_y+j+1] = -1;
        }
    }
    if (((currMB)->mb_type==9 || (currMB)->mb_type==10) || ((currMB)->mb_type==0 && (img-> type== B_IMG )))
    {
        for (j=0; j<2; j++)
            for (i=0; i<2; i++)
            {
                img->fw_refFrArr[img->block_y+j][img->block_x+i] = -1;
                img->bw_refFrArr[img->block_y+j][img->block_x+i] = -1;
            }
    }
    else
    {
        for(j=0;j<2;j++)
            for(i=0;i<2;i++)
            {
                k=2*j+i;
                img->fw_refFrArr[img->block_y+j][img->block_x+i] = ((currMB->b8pdir[k]==0||currMB->b8pdir[k]==2)&&currMB->b8mode[k]!=0?0:-1);
                img->bw_refFrArr[img->block_y+j][img->block_x+i] = ((currMB->b8pdir[k]==1||currMB->b8pdir[k]==2)&&currMB->b8mode[k]!=0?0:-1);
            }
    }
}

canonical_original_code:
void init_macroblock_Bframe(struct img_par *img)
{
    int i; int j; int k;
    struct macroblock *currMB = &mb_data[img->current_mb_nr];
    for (i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            img->dfMV [img->block_x+i+4][img->block_y+j][0]=img->dfMV[img->block_x+i+4][img->block_y+j][1]=0;
            img->dbMV [img->block_x+i+4][img->block_y+j][0]=img->dbMV[img->block_x+i+4][img->block_y+j][1]=0;
            img->fw_mv[img->block_x+i+4][img->block_y+j][0]=img->fw_mv[img->block_x+i+4][img->block_y+j][1]=0;
            img->bw_mv[img->block_x+i+4][img->block_y+j][0]=img->bw_mv[img->block_x+i+4][img->block_y+j][1]=0;
        }
    }
    for (i=0;i<2;i++)
    {
        for(j=0;j<2;j++)
        {
            img->ipredmode[img->block_x+i+1][img->block_y+j+1] = -1;
        }
    }
    if (((currMB)->mb_type==9 || (currMB)->mb_type==10) || ((currMB)->mb_type==0 && (img-> type== B_IMG )))
    {
        for (j=0; j<2; j++)
            for (i=0; i<2; i++)
            {
                img->fw_refFrArr[img->block_y+j][img->block_x+i] = -1;
                img->bw_refFrArr[img->block_y+j][img->block_x+i] = -1;
            }
    }
    else
    {
        for(j=0;j<2;j++)
            for(i=0;i<2;i++)
            {
                k=2*j+i;
                img->fw_refFrArr[img->block_y+j][img->block_x+i] = ((currMB->b8pdir[k]==0||currMB->b8pdir[k]==2)&&currMB->b8mode[k]!=0?0:-1);
                img->bw_refFrArr[img->block_y+j][img->block_x+i] = ((currMB->b8pdir[k]==1||currMB->b8pdir[k]==2)&&currMB->b8mode[k]!=0?0:-1);
            }
    }
}

variable_types: struct macroblock { int qp; int slice_nr; int delta_quant; struct macroblock *mb_available[3][3]; int mb_type; int mvd[2][-1][-1][2]; int cbp; unsigned long cbp_bits; int b8mode[4]; int b8pdir[4]; int mb_type_2; int c_ipred_mode_2; int dct_mode; int c_ipred_mode; int lf_disable; int lf_alpha_c0_offset; int lf_beta_offset; } *

user_defined_types: struct img_par { int number; int current_mb_nr; int max_mb_nr; int current_slice_nr; int **intra_block; int tr; int qp; int type; int width; int height; int width_cr; int height_cr; int mb_y; int mb_x; int block_y; int pix_y; int pix_x; int pix_c_y; int block_x; int pix_c_x; int ***mv; int mpr[16][16]; int m7[16][16]; int m8[4][8][8]; int cof[4][8][4][4]; int cofu[4]; int **ipredmode; int quad[256]; int cod_counter; int ***dfMV; int ***dbMV; int **fw_refFrArr; int **bw_refFrArr; int ***mv_frm; int **fw_refFrArr_frm; int **bw_refFrArr_frm; int imgtr_next_P; int imgtr_last_P; int tr_frm; int tr_fld; int imgtr_last_prev_P; int no_forward_reference; int seq_header_indicate; int B_discard_flag; int ***fw_mv; int ***bw_mv; int subblock_x; int subblock_y; int buf_cycle; int direct_type; int ***mv_top; int ***mv_bot; int **fw_refFrArr_top; int **bw_refFrArr_top; int **fw_refFrArr_bot; int **bw_refFrArr_bot; int **ipredmode_top; int **ipredmode_bot; int ***fw_mv_top; int ***fw_mv_bot; int ***bw_mv_top; int ***bw_mv_bot; int ***dfMV_top; int ***dbMV_top; int ***dfMV_bot; int ***dbMV_bot; int toppoc; int bottompoc; int framepoc; unsigned int frame_num; unsigned int pic_distance; int delta_pic_order_cnt_bottom; int PicDistanceMsb; unsigned int PrevPicDistanceLsb; int CurrPicDistanceMsb; unsigned int ThisPOC; int PicWidthInMbs; int PicHeightInMbs; int PicSizeInMbs; int block8_x; int structure; int pn; int buf_used; int buf_size; int picture_structure; int advanced_pred_mode_disable; int types; int current_mb_nr_fld; int slice_weighting_flag; int lum_scale[4]; int lum_shift[4]; int chroma_scale[4]; int chroma_shift[4]; int mb_weighting_flag; int weighting_prediction; int mpr_weight[16][16]; int top_bot; int Bframe_number; int auto_crop_right; int auto_crop_bottom; }


original_code:
unsigned int decode_golomb_word(const unsigned char **buffer,unsigned int *bitoff,unsigned int grad0,unsigned int max_levels)
{
    const unsigned char *rd;
    unsigned int bit,byte,level,databits,t,testbit;
    rd=*buffer;
    bit=*bitoff;
    byte=*rd;
    level=0UL;
    while( level<max_levels )
    {
        testbit=byte&(1UL<<bit);
        bit = (bit-1UL) & 7UL ;
        if(bit==7UL)byte=*(++rd);
        if( testbit )break;
        level++;
    }
    databits=0UL;
    for( t=0UL ; t<(grad0+level) ; t++ )
    {
        databits = (databits<<1UL) | ((byte>>bit)&1UL) ;
        bit = (bit-1UL) & 7UL ;
        if(bit==7UL)byte=*(++rd);
    }
    *buffer=rd;
    *bitoff=bit;
    return (((1UL<<level)-1UL)<<grad0)+databits;
}

canonical_original_code:
unsigned int decode_golomb_word(unsigned char **buffer, unsigned int *bitoff, unsigned int grad0, unsigned int max_levels)
{
    unsigned char *rd;
    unsigned int bit; unsigned int byte; unsigned int level; unsigned int databits; unsigned int t; unsigned int testbit;
    rd=*buffer;
    bit=*bitoff;
    byte=*rd;
    level=0UL;
    while( level<max_levels )
    {
        testbit=byte&(1UL<<bit);
        bit = (bit-1UL) & 7UL ;
        if(bit==7UL)byte=*(++rd);
        if( testbit )break;
        level++;
    }
    databits=0UL;
    for( t=0UL ; t<(grad0+level) ; t++ )
    {
        databits = (databits<<1UL) | ((byte>>bit)&1UL) ;
        bit = (bit-1UL) & 7UL ;
        if(bit==7UL)byte=*(++rd);
    }
    *buffer=rd;
    *bitoff=bit;
    return (((1UL<<level)-1UL)<<grad0)+databits;
}

variable_types:
buffer
unsigned char **

variable_types:
bitoff
unsigned int *

variable_types:
rd
unsigned char *

variable_types:
bit
unsigned int

variable_types:
byte
unsigned int

variable_types:
level
unsigned int

variable_types:
databits
unsigned int

variable_types:
t
unsigned int

variable_types:
testbit
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall decode_multilayer_golomb_word(unsigned __int8 **a1, int *a2, int *a3, int *a4)
{
unsigned int v6; // er12
unsigned int v7; // eax

v6 = 0;
while ( 1 )
{
v7 = decode_golomb_word(a1, a2, *a3, *a4);
v6 += v7;
if ( v7 < (unsigned __int64)((((1LL << *a4) - 1) << *a3) - 1) )
break;
++a3;
++a4;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 **a1, int *a2, int *a3, int *a4)
{
unsigned int v6; // er12
unsigned int v7; // eax

v6 = 0;
while ( 1 )
{
v7 = func0(a1, a2, *a3, *a4);
v6 += v7;
if ( v7 < (unsigned __int64)((((1LL << *a4) - 1) << *a3) - 1) )
break;
++a3;
++a4;
}
return v6;
}

original_code:
unsigned int decode_multilayer_golomb_word(const unsigned char **buffer,unsigned int *bitoff,const unsigned int *grad0,const unsigned int *max_levels)
{
    unsigned int symbol,partsymbol,tmp;
    symbol=0UL;
    while(1)
    {
        partsymbol=decode_golomb_word(buffer,bitoff,*grad0,*max_levels);
        symbol+=partsymbol;
        tmp=*max_levels;
        if( partsymbol < (((1UL<<tmp)-1UL)<<(*grad0))-1UL )
            break;
        grad0++;
        max_levels++;
    }
    return symbol;
}

canonical_original_code:
unsigned int decode_multilayer_golomb_word(unsigned char **buffer, unsigned int *bitoff, unsigned int *grad0, unsigned int *max_levels)
{
    unsigned int symbol; unsigned int partsymbol; unsigned int tmp;
    symbol=0UL;
    while(1)
    {
        partsymbol=decode_golomb_word(buffer,bitoff,*grad0,*max_levels);
        symbol+=partsymbol;
        tmp=*max_levels;
        if( partsymbol < (((1UL<<tmp)-1UL)<<(*grad0))-1UL )
            break;
        grad0++;
        max_levels++;
    }
    return symbol;
}

variable_types:
symbol
unsigned int

variable_types:
partsymbol
unsigned int

variable_types:
tmp
unsigned int


decompiled_code:
__int64 __fastcall readSyntaxElement_GOLOMB(_DWORD *a1)
{
int v1; // er8
int v2; // er9
int v3; // ebp
__int64 v4; // r12
unsigned __int64 v5; // rax
int v6; // edx
int v7; // eax
int v8; // edx
__int64 v9; // rax
int v11; // [rsp+4h] [rbp-44h] BYREF
unsigned __int8 *v12; // [rsp+8h] [rbp-40h] BYREF
int v13[4]; // [rsp+10h] [rbp-38h] BYREF
int v14[10]; // [rsp+20h] [rbp-28h] BYREF

v1 = a1[9];
v2 = a1[8];
v3 = *(_DWORD *)(currStream + 8LL);
v4 = *(_QWORD *)(currStream + 16LL);
v11 = ~(_BYTE)v3 & 7;
v12 = (unsigned __int8 *)(v4 + (v3 >> 3));
v5 = 0LL;
if ( (v1 & 0xFFFFFF00) != 0 )
{
do
{
v13[v5 / 4] = (unsigned __int8)(v2 >> (2 * v5));
v14[v5 / 4] = (unsigned __int8)(v1 >> (2 * v5));
v5 += 4LL;
}
while ( v5 != 16 );
a1[1] = decode_multilayer_golomb_word(&v12, &v11, v13, v14);
}
else
{
a1[1] = decode_golomb_word(&v12, &v11, v2, v1);
}
v6 = (int)v12;
v7 = 7 - v11;
a1[2] = 0;
v8 = v7 - v3 + 8 * (v6 - v4);
v9 = currStream;
a1[3] = v8;
*(_DWORD *)(v9 + 8) += v8;
return 1LL;
}

original_code:
int readSyntaxElement_GOLOMB(SyntaxElement *se, struct img_par *img, struct inp_par *inp)
{
    int frame_bitoffset;
    unsigned char *buf,*read;
    int BitstreamLengthInBytes;
    unsigned int bit,i;
    unsigned int grad[4],max_lev[4];
    frame_bitoffset = currStream->frame_bitoffset;
    buf = (unsigned char*)currStream->streamBuffer;
    BitstreamLengthInBytes = currStream->bitstream_length;
    bit=7UL-(frame_bitoffset&7);
    read=buf+(frame_bitoffset>>3);
    if(!( se->golomb_maxlevels&~0xFF ))
    {
        se->value1=decode_golomb_word(&read,&bit,se->golomb_grad,se->golomb_maxlevels);
    }
    else
    {
        for(i=0UL;i<4UL;i++)
        {
            grad[i]=(se->golomb_grad>>(i<<3))&0xFFUL;
            max_lev[i]=(se->golomb_maxlevels>>(i<<3))&0xFFUL;
        }
        se->value1=decode_multilayer_golomb_word(&read,&bit,grad,max_lev);
    }
    se->len=(((read-buf)<<3)+(7-bit))-frame_bitoffset;
    se->value2=0;
    currStream->frame_bitoffset += se->len;
    return 1;
}

canonical_original_code:
int readSyntaxElement_GOLOMB(struct syntaxelement *se, struct img_par *img, struct inp_par *inp)
{
    int frame_bitoffset;
    unsigned char *buf; unsigned char *read;
    int BitstreamLengthInBytes;
    unsigned int bit; unsigned int i;
    unsigned int grad[4]; unsigned int max_lev[4];
    frame_bitoffset = currStream->frame_bitoffset;
    buf = (unsigned char *)currStream->streamBuffer;
    BitstreamLengthInBytes = currStream->bitstream_length;
    bit=7UL-(frame_bitoffset&7);
    read=buf+(frame_bitoffset>>3);
    if(!( se->golomb_maxlevels&~0xFF ))
    {
        se->value1=decode_golomb_word(&read,&bit,se->golomb_grad,se->golomb_maxlevels);
    }
    else
    {
        for(i=0UL;i<4UL;i++)
        {
            grad[i]=(se->golomb_grad>>(i<<3))&0xFFUL;
            max_lev[i]=(se->golomb_maxlevels>>(i<<3))&0xFFUL;
        }
        se->value1=decode_multilayer_golomb_word(&read,&bit,grad,max_lev);
    }
    se->len=(((read-buf)<<3)+(7-bit))-frame_bitoffset;
    se->value2=0;
    currStream->frame_bitoffset += se->len;
    return 1;
}

variable_types: struct syntaxelement { int type; int value1; int value2; int len; int inf; unsigned int bitpattern; int context; int k; int golomb_grad; int golomb_maxlevels; void (*mapping)(int len, int info, int *value1, int *value2); } *

variable_types: struct inp_par { char infile[100]; char outfile[100]; char reffile[100]; int FileFormat; int buf_cycle; int LFParametersFlag; } *

variable_types:
buf
unsigned char *

variable_types:
read
unsigned char *

variable_types: BitstreamLengthInBytes int

variable_types:
i
unsigned int

variable_types:
grad
unsigned int [4]


TestSyckNodeAlloc

repo: xxx/mkrf

decompiled_code:
__int64 __fastcall TestSyckNodeAlloc(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax

v1 = syck_new_str("YAML", 5LL);
CuAssert(a1, "Allocated 'str' node reporting as 'seq'.", *(_DWORD *)(v1 + 8) != 1);
CuAssert(a1, "Allocated 'str' node reporting as 'map'.", *(_DWORD *)(v1 + 8) != 0);
CuAssert(a1, "Allocated 'str' not reporting as 'str'.", *(_DWORD *)(v1 + 8) == 2);
v2 = syck_str_read(v1);
CuAssertStrEquals(a1, "YAML", v2);
return syck_free_node(v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax

v1 = syck_new_str("YAML", 5LL);
CuAssert(a1, "Allocated 'str' node reporting as 'seq'.", *(_DWORD *)(v1 + 8) != 1);
CuAssert(a1, "Allocated 'str' node reporting as 'map'.", *(_DWORD *)(v1 + 8) != 0);
CuAssert(a1, "Allocated 'str' not reporting as 'str'.", *(_DWORD *)(v1 + 8) == 2);
v2 = syck_str_read(v1);
CuAssertStrEquals(a1, "YAML", v2);
return syck_free_node(v1);
}

original_code:
void
TestSyckNodeAlloc( CuTest *tc )
{
    SyckNode* n;
    n = syck_new_str( "YAML", scalar_plain );
    CuAssert( tc, "Allocated 'str' node reporting as 'seq'.", n->kind != syck_seq_kind );
    CuAssert( tc, "Allocated 'str' node reporting as 'map'.", n->kind != syck_map_kind );
    CuAssert( tc, "Allocated 'str' not reporting as 'str'.", n->kind == syck_str_kind );
    CuAssertStrEquals( tc, "YAML", syck_str_read( n ) );
    syck_free_node( n );
}

canonical_original_code:
void TestSyckNodeAlloc(struct CuTest *tc)
{
    struct _syck_node *n;
    n = syck_new_str( "YAML", scalar_plain );
    CuAssert( tc, "Allocated 'str' node reporting as 'seq'.", n->kind != syck_seq_kind );
    CuAssert( tc, "Allocated 'str' node reporting as 'map'.", n->kind != syck_map_kind );
    CuAssert( tc, "Allocated 'str' not reporting as 'str'.", n->kind == syck_str_kind );
    CuAssertStrEquals( tc, "YAML", syck_str_read( n ) );
    syck_free_node( n );
}

variable_types: struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } (*jumpBuf)[1]; } *

variable_types: struct _syck_node { unsigned long id; enum syck_kind_tag { syck_map_kind=0, syck_seq_kind=1, syck_str_kind=2 } kind; char *type_id; char *anchor; union { struct SyckMap { enum map_style { map_none=0, map_inline=1 } style; unsigned long *keys; unsigned long *values; long capa; long idx; } *pairs; struct SyckSeq { enum seq_style { seq_none=0, seq_inline=1 } style; unsigned long *items; long capa; long idx; } *list; struct SyckStr { enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 } style; char *ptr; long len; } *str; } data; void *shortcut; } *

user_defined_types: struct CuTest { char *name; void (*function)(struct CuTest *); int failed; int ran; char *message; struct __jmp_buf_tag (*jumpBuf)[1]; }

user_defined_types: struct _syck_node { unsigned long id; enum syck_kind_tag kind; char *type_id; char *anchor; union { struct SyckMap *pairs; struct SyckSeq *list; struct SyckStr *str; } data; void *shortcut; }

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }

user_defined_types: struct SyckMap { enum map_style style; unsigned long *keys; unsigned long *values; long capa; long idx; }

user_defined_types: struct SyckSeq { enum seq_style style; unsigned long *items; long capa; long idx; }

user_defined_types: struct SyckStr { enum scalar_style style; char *ptr; long len; }


TestSyckSeqAlloc

decompiled_code:
__int64 __fastcall TestSyckSeqAlloc(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rsi
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

v1 = 11001LL;
v2 = syck_new_seq(1LL);
do
{
v3 = v1;
v1 += 24LL;
syck_seq_add(v2, v3);
}
while ( v1 != 23001 );
v4 = syck_seq_read(v2, 0LL);
CuAssert(a1, "Invalid value at '0'", v4 == 1);
v5 = syck_seq_read(v2, 1LL);
CuAssert(a1, "Invalid value at '1'", v5 == 11001);
v6 = syck_seq_read(v2, 201LL);
CuAssert(a1, "Invalid value at '200'", v6 == 15801);
return syck_free_node(v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rsi
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

v1 = 11001LL;
v2 = syck_new_seq(1LL);
do
{
v3 = v1;
v1 += 24LL;
syck_seq_add(v2, v3);
}
while ( v1 != 23001 );
v4 = syck_seq_read(v2, 0LL);
CuAssert(a1, "Invalid value at '0'", v4 == 1);
v5 = syck_seq_read(v2, 1LL);
CuAssert(a1, "Invalid value at '1'", v5 == 11001);
v6 = syck_seq_read(v2, 201LL);
CuAssert(a1, "Invalid value at '200'", v6 == 15801);
return syck_free_node(v2);
}

original_code:
void
TestSyckSeqAlloc( CuTest *tc )
{
    SyckNode *n;
    unsigned long id;
    n = syck_new_seq( 1 );
    for ( id = 11001; id < 23000; id += 24 )
    {
        syck_seq_add( n, id );
    }
    CuAssert( tc, "Invalid value at '0'", 1 == syck_seq_read( n, 0 ) );
    CuAssert( tc, "Invalid value at '1'", 11001 == syck_seq_read( n, 1 ) );
    CuAssert( tc, "Invalid value at '200'", 15801 == syck_seq_read( n, 201 ) );
    syck_free_node( n );
}

canonical_original_code:
void TestSyckSeqAlloc(struct CuTest *tc)
{
    struct _syck_node *n;
    unsigned long id;
    n = syck_new_seq( 1 );
    for ( id = 11001; id < 23000; id += 24 )
    {
        syck_seq_add( n, id );
    }
    CuAssert( tc, "Invalid value at '0'", 1 == syck_seq_read( n, 0 ) );
    CuAssert( tc, "Invalid value at '1'", 11001 == syck_seq_read( n, 1 ) );
    CuAssert( tc, "Invalid value at '200'", 15801 == syck_seq_read( n, 201 ) );
    syck_free_node( n );
}

variable_types:
id
unsigned long

user_defined_types: enum syck_kind_tag { syck_map_kind=0, syck_seq_kind=1, syck_str_kind=2 }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: enum map_style { map_none=0, map_inline=1 }

user_defined_types: enum seq_style { seq_none=0, seq_inline=1 }

user_defined_types: enum scalar_style { scalar_none=0, scalar_1quote=1, scalar_2quote=2, scalar_fold=3, scalar_literal=4, scalar_plain=5 }


TestSyckMapAlloc

decompiled_code:
__int64 __fastcall TestSyckMapAlloc(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax

v1 = syck_new_map(24556LL, 24557LL);
syck_map_add(v1, 24558LL, 24559LL);
syck_map_add(v1, 24658LL, 24659LL);
syck_map_add(v1, 24758LL, 24759LL);
syck_map_add(v1, 24858LL, 24859LL);
syck_map_add(v1, 24958LL, 24959LL);
syck_map_add(v1, 24058LL, 24059LL);
syck_map_add(v1, 24158LL, 24159LL);
v2 = syck_map_read(v1, 0LL, 0LL);
CuAssert(a1, "Invalid key at '0'.", v2 == 24556);
v3 = syck_map_read(v1, 0LL, 1LL);
CuAssert(a1, "Invalid key at '1'.", v3 == 24558);
v4 = syck_map_read(v1, 0LL, 2LL);
CuAssert(a1, "Invalid key at '2'.", v4 == 24658);
v5 = syck_map_read(v1, 0LL, 3LL);
CuAssert(a1, "Invalid key at '3'.", v5 == 24758);
v6 = syck_map_read(v1, 0LL, 4LL);
CuAssert(a1, "Invalid key at '4'.", v6 == 24858);
v7 = syck_map_read(v1, 0LL, 5LL);
CuAssert(a1, "Invalid key at '5'.", v7 == 24958);
v8 = syck_map_read(v1, 0LL, 6LL);
CuAssert(a1, "Invalid key at '6'.", v8 == 24058);
v9 = syck_map_read(v1, 0LL, 7LL);
CuAssert(a1, "Invalid key at '7'.", v9 == 24158);
v10 = syck_map_read(v1, 1LL, 0LL);
CuAssert(a1, "Invalid value at '0'", v10 == 24557);
v11 = syck_map_read(v1, 1LL, 1LL);
CuAssert(a1, "Invalid value at '1'", v11 == 24559);
v12 = syck_map_read(v1, 1LL, 2LL);
CuAssert(a1, "Invalid value at '2'", v12 == 24659);
v13 = syck_map_read(v1, 1LL, 3LL);
CuAssert(a1, "Invalid value at '3'", v13 == 24759);
v14 = syck_map_read(v1, 1LL, 4LL);
CuAssert(a1, "Invalid value at '4'", v14 == 24859);
v15 = syck_map_read(v1, 1LL, 5LL);
CuAssert(a1, "Invalid value at '5'", v15 == 24959);
v16 = syck_map_read(v1, 1LL, 6LL);
CuAssert(a1, "Invalid value at '6'", v16 == 24059);
v17 = syck_map_read(v1, 1LL, 7LL);
CuAssert(a1, "Invalid value at '7'", v17 == 24159);
return syck_free_node(v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax

v1 = syck_new_map(24556LL, 24557LL);
syck_map_add(v1, 24558LL, 24559LL);
syck_map_add(v1, 24658LL, 24659LL);
syck_map_add(v1, 24758LL, 24759LL);
syck_map_add(v1, 24858LL, 24859LL);
syck_map_add(v1, 24958LL, 24959LL);
syck_map_add(v1, 24058LL, 24059LL);
syck_map_add(v1, 24158LL, 24159LL);
v2 = syck_map_read(v1, 0LL, 0LL);
CuAssert(a1, "Invalid key at '0'.", v2 == 24556);
v3 = syck_map_read(v1, 0LL, 1LL);
CuAssert(a1, "Invalid key at '1'.", v3 == 24558);
v4 = syck_map_read(v1, 0LL, 2LL);
CuAssert(a1, "Invalid key at '2'.", v4 == 24658);
v5 = syck_map_read(v1, 0LL, 3LL);
CuAssert(a1, "Invalid key at '3'.", v5 == 24758);
v6 = syck_map_read(v1, 0LL, 4LL);
CuAssert(a1, "Invalid key at '4'.", v6 == 24858);
v7 = syck_map_read(v1, 0LL, 5LL);
CuAssert(a1, "Invalid key at '5'.", v7 == 24958);
v8 = syck_map_read(v1, 0LL, 6LL);
CuAssert(a1, "Invalid key at '6'.", v8 == 24058);
v9 = syck_map_read(v1, 0LL, 7LL);
CuAssert(a1, "Invalid key at '7'.", v9 == 24158);
v10 = syck_map_read(v1, 1LL, 0LL);
CuAssert(a1, "Invalid value at '0'", v10 == 24557);
v11 = syck_map_read(v1, 1LL, 1LL);
CuAssert(a1, "Invalid value at '1'", v11 == 24559);
v12 = syck_map_read(v1, 1LL, 2LL);
CuAssert(a1, "Invalid value at '2'", v12 == 24659);
v13 = syck_map_read(v1, 1LL, 3LL);
CuAssert(a1, "Invalid value at '3'", v13 == 24759);
v14 = syck_map_read(v1, 1LL, 4LL);
CuAssert(a1, "Invalid value at '4'", v14 == 24859);
v15 = syck_map_read(v1, 1LL, 5LL);
CuAssert(a1, "Invalid value at '5'", v15 == 24959);
v16 = syck_map_read(v1, 1LL, 6LL);
CuAssert(a1, "Invalid value at '6'", v16 == 24059);
v17 = syck_map_read(v1, 1LL, 7LL);
CuAssert(a1, "Invalid value at '7'", v17 == 24159);
return syck_free_node(v1);
}

original_code:
void
TestSyckMapAlloc( CuTest *tc )
{
    SyckNode *n;
    n = syck_new_map( 24556, 24557 );
    syck_map_add( n, 24558, 24559 );
    syck_map_add( n, 24658, 24659 );
    syck_map_add( n, 24758, 24759 );
    syck_map_add( n, 24858, 24859 );
    syck_map_add( n, 24958, 24959 );
    syck_map_add( n, 24058, 24059 );
    syck_map_add( n, 24158, 24159 );
    CuAssert( tc, "Invalid key at '0'.", 24556 == syck_map_read( n, map_key, 0 ) );
    CuAssert( tc, "Invalid key at '1'.", 24558 == syck_map_read( n, map_key, 1 ) );
    CuAssert( tc, "Invalid key at '2'.", 24658 == syck_map_read( n, map_key, 2 ) );
    CuAssert( tc, "Invalid key at '3'.", 24758 == syck_map_read( n, map_key, 3 ) );
    CuAssert( tc, "Invalid key at '4'.", 24858 == syck_map_read( n, map_key, 4 ) );
    CuAssert( tc, "Invalid key at '5'.", 24958 == syck_map_read( n, map_key, 5 ) );
    CuAssert( tc, "Invalid key at '6'.", 24058 == syck_map_read( n, map_key, 6 ) );
    CuAssert( tc, "Invalid key at '7'.", 24158 == syck_map_read( n, map_key, 7 ) );
    CuAssert( tc, "Invalid value at '0'", 24557 == syck_map_read( n, map_value, 0 ) );
    CuAssert( tc, "Invalid value at '1'", 24559 == syck_map_read( n, map_value, 1 ) );
    CuAssert( tc, "Invalid value at '2'", 24659 == syck_map_read( n, map_value, 2 ) );
    CuAssert( tc, "Invalid value at '3'", 24759 == syck_map_read( n, map_value, 3 ) );
    CuAssert( tc, "Invalid value at '4'", 24859 == syck_map_read( n, map_value, 4 ) );
    CuAssert( tc, "Invalid value at '5'", 24959 == syck_map_read( n, map_value, 5 ) );
    CuAssert( tc, "Invalid value at '6'", 24059 == syck_map_read( n, map_value, 6 ) );
    CuAssert( tc, "Invalid value at '7'", 24159 == syck_map_read( n, map_value, 7 ) );
    syck_free_node( n );
}

canonical_original_code:
void TestSyckMapAlloc(struct CuTest *tc)
{
    struct _syck_node *n;
    n = syck_new_map( 24556, 24557 );
    syck_map_add( n, 24558, 24559 );
    syck_map_add( n, 24658, 24659 );
    syck_map_add( n, 24758, 24759 );
    syck_map_add( n, 24858, 24859 );
    syck_map_add( n, 24958, 24959 );
    syck_map_add( n, 24058, 24059 );
    syck_map_add( n, 24158, 24159 );
    CuAssert( tc, "Invalid key at '0'.", 24556 == syck_map_read( n, map_key, 0 ) );
    CuAssert( tc, "Invalid key at '1'.", 24558 == syck_map_read( n, map_key, 1 ) );
    CuAssert( tc, "Invalid key at '2'.", 24658 == syck_map_read( n, map_key, 2 ) );
    CuAssert( tc, "Invalid key at '3'.", 24758 == syck_map_read( n, map_key, 3 ) );
    CuAssert( tc, "Invalid key at '4'.", 24858 == syck_map_read( n, map_key, 4 ) );
    CuAssert( tc, "Invalid key at '5'.", 24958 == syck_map_read( n, map_key, 5 ) );
    CuAssert( tc, "Invalid key at '6'.", 24058 == syck_map_read( n, map_key, 6 ) );
    CuAssert( tc, "Invalid key at '7'.", 24158 == syck_map_read( n, map_key, 7 ) );
    CuAssert( tc, "Invalid value at '0'", 24557 == syck_map_read( n, map_value, 0 ) );
    CuAssert( tc, "Invalid value at '1'", 24559 == syck_map_read( n, map_value, 1 ) );
    CuAssert( tc, "Invalid value at '2'", 24659 == syck_map_read( n, map_value, 2 ) );
    CuAssert( tc, "Invalid value at '3'", 24759 == syck_map_read( n, map_value, 3 ) );
    CuAssert( tc, "Invalid value at '4'", 24859 == syck_map_read( n, map_value, 4 ) );
    CuAssert( tc, "Invalid value at '5'", 24959 == syck_map_read( n, map_value, 5 ) );
    CuAssert( tc, "Invalid value at '6'", 24059 == syck_map_read( n, map_value, 6 ) );
    CuAssert( tc, "Invalid value at '7'", 24159 == syck_map_read( n, map_value, 7 ) );
    syck_free_node( n );
}