decompiled_code:
int test_parallel_add()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 v2; // rbx
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rax
unsigned __int64 v5; // rdx

printf("test parallel add, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 0LL;
do
{
pthread_create((pthread_t *)(ts + 8 * v0), 0LL, add_thread, (void *)v0);
++v0;
}
while ( nthreads > v0 );
if ( nthreads > 0 )
{
v1 = 0LL;
do
pthread_join(*(_QWORD *)(ts + 8 * v1++), 0LL);
while ( nthreads > v1 );
if ( nthreads > 0 )
{
v2 = 0LL;
v3 = 0LL;
do
{
v4 = deletemin(pq);
v5 = v3;
v3 = v4;
if ( v4 <= v5 )
_assert_fail("old < new", "unittests.c", 0x34u, "test_parallel_add");
++v2;
}
while ( 30 * nthreads > v2 );
}
}
}
return puts("OK.");
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbx
__int64 v1; // rbx
__int64 v2; // rbx
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rax
unsigned __int64 v5; // rdx

printf("test parallel add, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 0LL;
do
{
pthread_create((pthread_t *)(ts + 8 * v0), 0LL, add_thread, (void *)v0);
++v0;
}
while ( nthreads > v0 );
if ( nthreads > 0 )
{
v1 = 0LL;
do
pthread_join(*(_QWORD *)(ts + 8 * v1++), 0LL);
while ( nthreads > v1 );
if ( nthreads > 0 )
{
v2 = 0LL;
v3 = 0LL;
do
{
v4 = deletemin(pq);
v5 = v3;
v3 = v4;
if ( v4 <= v5 )
_assert_fail("old < new", "unittests.c", 0x34u, "test_parallel_add");
++v2;
}
while ( 30 * nthreads > v2 );
}
}
}
return puts("OK.");
}

original_code:
void
test_parallel_add()
{
    printf("test parallel add, %d threads\n", nthreads);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), add_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    unsigned long new, old = 0;
    for (long i = 0; i < nthreads * 30; i++) {
 new = (long)deletemin(pq);
 ((old < new) ? (void) (0) : __assert_fail ("old < new", "unittests.c", 52, __extension__ __PRETTY_FUNCTION__));
 old = new;
    }
    printf("OK.\n");
}

canonical_original_code:
void test_parallel_add()
{
    printf("test parallel add, %d threads\n", nthreads);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), add_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    unsigned long new; unsigned long old = 0;
    for (long i = 0; i < nthreads * 30; i++) {
 new = (long)deletemin(pq);
 ((old < new) ? (void) (0) : __assert_fail ("old < new", "unittests.c", 52, __extension__ __PRETTY_FUNCTION__));
 old = new;
    }
    printf("OK.\n");
}

variable_types: i long

variable_types:
new
unsigned long

variable_types:
old
unsigned long


repo: jonatanlinden/PR

decompiled_code:
int test_parallel_del()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rbx
__int64 v3; // rbx

printf("test parallel del, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 1LL;
do
{
insert(pq, v0, v0);
v1 = v0++;
}
while ( 30 * nthreads > v1 );
if ( nthreads > 0 )
{
v2 = 0LL;
do
{
pthread_create((pthread_t *)(ts + 8 * v2), 0LL, removemin_thread, (void *)v2);
++v2;
}
while ( nthreads > v2 );
if ( nthreads > 0 )
{
v3 = 0LL;
do
pthread_join(*(_QWORD *)(ts + 8 * v3++), 0LL);
while ( nthreads > v3 );
}
}
}
return puts("OK.");
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rbx
__int64 v3; // rbx

printf("test parallel del, %d threads\n", (unsigned int)nthreads);
if ( nthreads > 0 )
{
v0 = 1LL;
do
{
insert(pq, v0, v0);
v1 = v0++;
}
while ( 30 * nthreads > v1 );
if ( nthreads > 0 )
{
v2 = 0LL;
do
{
pthread_create((pthread_t *)(ts + 8 * v2), 0LL, removemin_thread, (void *)v2);
++v2;
}
while ( nthreads > v2 );
if ( nthreads > 0 )
{
v3 = 0LL;
do
pthread_join(*(_QWORD *)(ts + 8 * v3++), 0LL);
while ( nthreads > v3 );
}
}
}
return puts("OK.");
}

original_code:
void
test_parallel_del()
{
    printf("test parallel del, %d threads\n", nthreads);
    for (long i = 0; i < nthreads * 30; i++)
 insert(pq, i+1, (pval_t)i+1);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), removemin_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    printf("OK.\n");
}

canonical_original_code:
void test_parallel_del()
{
    printf("test parallel del, %d threads\n", nthreads);
    for (long i = 0; i < nthreads * 30; i++)
 insert(pq, i+1, (void *)i+1);
    for (long i = 0; i < nthreads; i ++)
        pthread_create (&ts[i], ((void *)0), removemin_thread, (void *)i);
    for (long i = 0; i < nthreads; i ++)
 (void)pthread_join (ts[i], ((void *)0));
    printf("OK.\n");
}

return_type: void


decompiled_code:
void *__fastcall add_thread(void *a1)
{
__int64 v1; // rbx

v1 = 30LL * (_QWORD)a1 + 1;
do
{
insert(pq, v1, v1);
++v1;
}
while ( v1 != 30LL * (_QWORD)a1 + 31 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1)
{
__int64 v1; // rbx

v1 = 30LL * (_QWORD)a1 + 1;
do
{
insert(pq, v1, v1);
++v1;
}
while ( v1 != 30LL * (_QWORD)a1 + 31 );
return 0LL;
}

original_code:
void *
add_thread(void *id)
{
    long base = 30 * (long)id;
    for(int i = 0; i < 30; i++)
 insert(pq, base+i+1, (pval_t) base+i+1);
    return ((void *)0);
}

canonical_original_code:
void *add_thread(void *id)
{
    long base = 30 * (long)id;
    for(int i = 0; i < 30; i++)
 insert(pq, base+i+1, (void *) base+i+1);
    return ((void *)0);
}

variable_types:
id
void *

variable_types: base long

variable_types: i int

return_type: void *


decompiled_code:
void *__fastcall invariant_thread(void *a1)
{
unsigned __int16 *v1; // rbx
__int64 v2; // rax

rng_init((char *)&rng + __readfsqword(0));
if ( !abort_loop )
{
v1 = (unsigned __int16 *)((char *)&rng + __readfsqword(0));
do
{
if ( halt )
{
_InterlockedAdd(&stop, 1u);
while ( halt )
_mm_lfence();
}
if ( erand48(v1) >= 0.5 )
{
deletemin(pq);
}
else
{
v2 = nrand48(v1);
insert(pq, v2 + 1, v2 + 1);
}
}
while ( !abort_loop );
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
unsigned __int16 *v1; // rbx
__int64 v2; // rax

rng_init((char *)&rng + __readfsqword(0));
if ( !abort_loop )
{
v1 = (unsigned __int16 *)((char *)&rng + __readfsqword(0));
do
{
if ( halt )
{
_InterlockedAdd(&stop, 1u);
while ( halt )
_mm_lfence();
}
if ( erand48(v1) >= 0.5 )
{
deletemin(pq);
}
else
{
v2 = nrand48(v1);
insert(pq, v2 + 1, v2 + 1);
}
}
while ( !abort_loop );
}
return 0LL;
}

original_code:
void *
invariant_thread(void *_args)
{
    unsigned long id = (unsigned long)_args;
    unsigned long elem;
    int cnt = 0;
    rng_init(rng);
    while(!abort_loop) {
 if (halt) {
     __sync_fetch_and_add(&stop, 1);
     while(halt)
  __asm__ __volatile__("lfence":::"memory");
 }
 if (erand48(rng) < 0.5) {
     elem = nrand48(rng);
     insert(pq, elem+1, (pval_t)elem + 1);
 } else {
     deletemin(pq);
 }
 cnt++;
    }
    return ((void *)0);
}

canonical_original_code:
void *invariant_thread(void *_args)
{
    unsigned long id = (unsigned long)_args;
    unsigned long elem;
    int cnt = 0;
    rng_init(rng);
    while(!abort_loop) {
 if (halt) {
     __sync_fetch_and_add(&stop, 1);
     while(halt)
  __asm__ __volatile__("lfence":::"memory");
 }
 if (erand48(rng) < 0.5) {
     elem = nrand48(rng);
     insert(pq, elem+1, (void *)elem + 1);
 } else {
     deletemin(pq);
 }
 cnt++;
    }
    return ((void *)0);
}

variable_types:
id
unsigned long

variable_types:
elem
unsigned long

variable_types: cnt int


decompiled_code:
unsigned __int64 __fastcall check_invariants(__int64 a1)
{
__int64 v1; // r8
unsigned __int64 v2; // rdx
unsigned __int64 result; // rax
__int64 v4; // rcx
__int64 v5; // rdi
unsigned __int64 v6; // r9
int v7; // edx
_QWORD *v8; // rax
__int64 v9; // rsi
unsigned __int64 v10; // rdx

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(v1 + 24);
for ( result = v2; (result & 1) != 0; v2 = result )
result = *(_QWORD *)((result & 0xFFFFFFFFFFFFFFFELL) + 24);
v4 = *(_QWORD *)(v2 + 24);
v5 = *(_QWORD *)(a1 + 24);
if ( v4 == v5 )
{
v9 = 31LL;
}
else
{
v6 = *(_QWORD *)(v2 + 24) & 1LL;
if ( (v4 & 1) != 0 )
LABEL_5:
_assert_fail("!is_marked_ref(cur)", "unittests.c", 0x63u, "check_invariants");
while ( 1 )
{
v7 = *(_DWORD *)(v4 + 8);
if ( v7 > 1 )
{
v8 = (_QWORD *)(v4 + 32);
do
{
if ( !*v8 )
break;
if ( *(_QWORD *)v4 >= *(_QWORD *)*v8 )
_assert_fail("cur->k < cur->next[i]->k", "unittests.c", 0x67u, "check_invariants");
++v8;
}
while ( v8 != (_QWORD *)(v4 + 8LL * (unsigned int)(v7 - 2) + 40) );
}
result = *(_QWORD *)v4;
if ( *(_QWORD *)v4 <= v6 )
_assert_fail("cur->k > k", "unittests.c", 0x6Au, "check_invariants");
v4 = *(_QWORD *)(v4 + 24);
if ( v4 == v5 )
break;
if ( (v4 & 1) != 0 )
goto LABEL_5;
v6 = result;
}
v9 = 31LL;
}
do
{
v10 = *(_QWORD *)(v1 + 8 * v9 + 24) & 0xFFFFFFFFFFFFFFFELL;
if ( v10 != v5 )
{
do
{
result = *(_QWORD *)(v10 + 8 * ((int)v9 + 2LL) + 8) & 0xFFFFFFFFFFFFFFFELL;
v10 = result;
}
while ( result != v5 );
}
--v9;
}
while ( v9 );
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r8
unsigned __int64 v2; // rdx
unsigned __int64 result; // rax
__int64 v4; // rcx
__int64 v5; // rdi
unsigned __int64 v6; // r9
int v7; // edx
_QWORD *v8; // rax
__int64 v9; // rsi
unsigned __int64 v10; // rdx

v1 = *(_QWORD *)(a1 + 16);
v2 = *(_QWORD *)(v1 + 24);
for ( result = v2; (result & 1) != 0; v2 = result )
result = *(_QWORD *)((result & 0xFFFFFFFFFFFFFFFELL) + 24);
v4 = *(_QWORD *)(v2 + 24);
v5 = *(_QWORD *)(a1 + 24);
if ( v4 == v5 )
{
v9 = 31LL;
}
else
{
v6 = *(_QWORD *)(v2 + 24) & 1LL;
if ( (v4 & 1) != 0 )
LABEL_5:
_assert_fail("!is_marked_ref(cur)", "unittests.c", 0x63u, "check_invariants");
while ( 1 )
{
v7 = *(_DWORD *)(v4 + 8);
if ( v7 > 1 )
{
v8 = (_QWORD *)(v4 + 32);
do
{
if ( !*v8 )
break;
if ( *(_QWORD *)v4 >= *(_QWORD *)*v8 )
_assert_fail("cur->k < cur->next[i]->k", "unittests.c", 0x67u, "check_invariants");
++v8;
}
while ( v8 != (_QWORD *)(v4 + 8LL * (unsigned int)(v7 - 2) + 40) );
}
result = *(_QWORD *)v4;
if ( *(_QWORD *)v4 <= v6 )
_assert_fail("cur->k > k", "unittests.c", 0x6Au, "check_invariants");
v4 = *(_QWORD *)(v4 + 24);
if ( v4 == v5 )
break;
if ( (v4 & 1) != 0 )
goto LABEL_5;
v6 = result;
}
v9 = 31LL;
}
do
{
v10 = *(_QWORD *)(v1 + 8 * v9 + 24) & 0xFFFFFFFFFFFFFFFELL;
if ( v10 != v5 )
{
do
{
result = *(_QWORD *)(v10 + 8 * ((int)v9 + 2LL) + 8) & 0xFFFFFFFFFFFFFFFELL;
v10 = result;
}
while ( result != v5 );
}
--v9;
}
while ( v9 );
return result;
}

original_code:
void
check_invariants(pq_t *pq)
{
    node_t *cur, *pred;
    int cnt = 0;
    unsigned long long k = 0;
    int i = 0;
    cur = pq->head->next[0];
    while ((((uintptr_t)(cur)) & 1)) {
 pred = ((void *)(((uintptr_t)(cur)) & ~1));
 cur = pred->next[0];
 cnt++;
    }
    pred = cur;
    cur = pred->next[0];
    while (cur != pq->tail) {
 ((!(((uintptr_t)(cur)) & 1)) ? (void) (0) : __assert_fail ("!is_marked_ref(cur)", "unittests.c", 99, __extension__ __PRETTY_FUNCTION__));
 i = 1;
 while(i < cur->level && cur->next[i]) {
     ((cur->k < cur->next[i]->k) ? (void) (0) : __assert_fail ("cur->k < cur->next[i]->k", "unittests.c", 103, __extension__ __PRETTY_FUNCTION__));
     i++;
 }
 ((cur->k > k) ? (void) (0) : __assert_fail ("cur->k > k", "unittests.c", 106, __extension__ __PRETTY_FUNCTION__));
 k = cur->k;
 pred = cur;
 cur = pred->next[0];
 cnt++;
    }
    k = 0;
    for (int i = 31; i > 0; i--) {
 cur = ((void *)(((uintptr_t)(pq->head->next[i])) & ~1));
 while(cur != pq->tail) {
     cur = ((void *)(((uintptr_t)(cur->next[i])) & ~1));
 }
    }
}

canonical_original_code:
void check_invariants(struct pq_t *pq)
{
    struct node_s *cur; struct node_s *pred;
    int cnt = 0;
    unsigned long long k = 0;
    int i = 0;
    cur = pq->head->next[0];
    while ((((unsigned long)(cur)) & 1)) {
 pred = ((void *)(((unsigned long)(cur)) & ~1));
 cur = pred->next[0];
 cnt++;
    }
    pred = cur;
    cur = pred->next[0];
    while (cur != pq->tail) {
 ((!(((unsigned long)(cur)) & 1)) ? (void) (0) : __assert_fail ("!is_marked_ref(cur)", "unittests.c", 99, __extension__ __PRETTY_FUNCTION__));
 i = 1;
 while(i < cur->level && cur->next[i]) {
     ((cur->k < cur->next[i]->k) ? (void) (0) : __assert_fail ("cur->k < cur->next[i]->k", "unittests.c", 103, __extension__ __PRETTY_FUNCTION__));
     i++;
 }
 ((cur->k > k) ? (void) (0) : __assert_fail ("cur->k > k", "unittests.c", 106, __extension__ __PRETTY_FUNCTION__));
 k = cur->k;
 pred = cur;
 cur = pred->next[0];
 cnt++;
    }
    k = 0;
    for (int i = 31; i > 0; i--) {
 cur = ((void *)(((unsigned long)(pq->head->next[i])) & ~1));
 while(cur != pq->tail) {
     cur = ((void *)(((unsigned long)(cur->next[i])) & ~1));
 }
    }
}

variable_types: struct pq_t { int max_offset; int max_level; int nthreads; struct node_s { unsigned long k; int level; int inserting; void *v; struct node_s *next[1]; } *head; struct node_s *tail; char pad[128]; } *

variable_types:
k
unsigned long long

user_defined_types: struct pq_t { int max_offset; int max_level; int nthreads; struct node_s *head; struct node_s *tail; char pad[128]; }


setup

decompiled_code:
__int64 __fastcall setup(unsigned int a1)
{
__int64 result; // rax

init_gc_subsystem();
result = pq_init(a1);
pq = result;
return result;
}

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

init_gc_subsystem();
result = pq_init(a1);
pq = result;
return result;
}

original_code:
void
setup (int max_offset)
{
    _init_gc_subsystem();
    pq = pq_init(max_offset);
}

canonical_original_code:
void setup(int max_offset)
{
    _init_gc_subsystem();
    pq = pq_init(max_offset);
}


teardown

decompiled_code:
__int64 teardown()
{
pq_destroy(pq);
return destroy_gc_subsystem();
}

canonical_decompiled_code:
__int64 func8()
{
pq_destroy(pq);
return destroy_gc_subsystem();
}

original_code:
void
teardown ()
{
    pq_destroy(pq);
    _destroy_gc_subsystem();
}

canonical_original_code:
void teardown()
{
    pq_destroy(pq);
    _destroy_gc_subsystem();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 (__fastcall **v3)(); // rbx

nthreads = 8;
ts = (__int64)malloc(0x40uLL);
if ( !ts )
_assert_fail("ts", "unittests.c", 0xBAu, "main");
v3 = &tests;
if ( tests )
{
do
{
setup(0xAu);
((void (__fastcall *)(__int64, const char **))*v3)(10LL, argv);
teardown();
++v3;
}
while ( *v3 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 (__fastcall **v3)(); // rbx

nthreads = 8;
ts = (__int64)malloc(0x40uLL);
if ( !ts )
_assert_fail("ts", "unittests.c", 0xBAu, "main");
v3 = &tests;
if ( tests )
{
do
{
func7(0xAu);
((void (__fastcall *)(__int64, const char **))*v3)(10LL, argv);
func8();
++v3;
}
while ( *v3 );
}
return 0;
}

original_code:
int
main(int argc, char **argv)
{
    nthreads = 8;
    ts = malloc(nthreads * sizeof(pthread_t));
    ((ts) ? (void) (0) : __assert_fail ("ts", "unittests.c", 186, __extension__ __PRETTY_FUNCTION__));
    for(test_func_t *tf = tests; *tf; tf++) {
        setup(10);
        (*tf)();
        teardown();
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    nthreads = 8;
    ts = malloc(nthreads * sizeof(pthread_t));
    ((ts) ? (void) (0) : __assert_fail ("ts", "unittests.c", 186, __extension__ __PRETTY_FUNCTION__));
    for(void (**tf)() = tests; *tf; tf++) {
        setup(10);
        (*tf)();
        teardown();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
tf
void (**)()

return_type: int


repo: jonathanhefner/sxc

original_code:
static void* map_iter(SxcMap* map, void* state, SxcValue* return_key, SxcValue* return_value) {
  while ((state = (map->binding->iter)(map->underlying, state, return_key, return_value))) {
    switch (return_key->type) {
      case sxc_cint:
      case sxc_sstring:
        return state;
      case sxc_cdouble:
        if (return_key->data.cdouble == (double)(int)(return_key->data.cdouble)) {
          sxc_value_set(return_key, sxc_cint, (int)(return_key->data.cdouble));
          return state;
        }
      default:
        break;
    }
  }
  return ((void *)0);
}

canonical_original_code:
static void *map_iter(struct _SxcMap *map, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value) {
  while ((state = (map->binding->iter)(map->underlying, state, return_key, return_value))) {
    switch (return_key->type) {
      case sxc_cint:
      case sxc_sstring:
        return state;
      case sxc_cdouble:
        if (return_key->data.cdouble == (double)(int)(return_key->data.cdouble)) {
          sxc_value_set(return_key, sxc_cint, (int)(return_key->data.cdouble));
          return state;
        }
      default:
        break;
    }
  }
  return ((void *)0);
}

variable_types: struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *

variable_types:
state
void *

user_defined_types: struct _SxcMap { void *underlying; struct _SxcMapBinding *binding; struct _SxcContext *context; }

user_defined_types: struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); }

user_defined_types: struct _SxcValue { struct _SxcContext *context; enum _SxcDataType type; union _SxcData data; }

user_defined_types: union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString *string; struct _SxcMap *map; struct _SxcFunc *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; }

user_defined_types: struct _SxcContext { void *underlying; struct _SxcContextBinding *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk _firstchunk; char _firstdata[-1]; }

user_defined_types: struct _SxcString { void *underlying; struct _SxcStringBinding *binding; struct _SxcContext *context; char *data; int length; }

user_defined_types: struct _SxcFunc { void *underlying; struct _SxcFunctionBinding *binding; struct _SxcContext *context; }

user_defined_types: struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod *methods, struct _SxcLibProperty *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); }


original_code:
SxcMap* sxc_map_new(SxcContext* context, void* map_type) {
  SxcValue value;
  SxcMap* map;
  value.context = context;
  (context->binding->map_new)(map_type, &value);
  sxc_value_get(&value, sxc_map, &map);
  return map;
}

canonical_original_code:
struct _SxcMap *sxc_map_new(struct _SxcContext *context, void *map_type) {
  struct _SxcValue value;
  struct _SxcMap *map;
  value.context = context;
  (context->binding->map_new)(map_type, &value);
  sxc_value_get(&value, sxc_map, &map);
  return map;
}

variable_types:
context
struct _SxcContext *

variable_types: struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; }

return_type: struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *


original_code:
void* sxc_map_newtype(SxcContext* context, const char* name, SxcLibFunc* initialzier,
                      const SxcLibMethod* methods, const SxcLibProperty* properties) {
  const SxcLibMethod no_methods[] = { {0} };
  const SxcLibProperty no_properties[] = { {0} };
  return (context->binding->map_newtype)(context, name, initialzier,
    methods == ((void *)0) ? no_methods : methods, properties == ((void *)0) ? no_properties : properties);
}

canonical_original_code:
void *sxc_map_newtype(struct _SxcContext *context, char *name, void (*initialzier)(struct _SxcContext *context), struct _SxcLibMethod *methods, struct _SxcLibProperty *properties) {
  struct _SxcLibMethod no_methods[] = { {0} };
  struct _SxcLibProperty no_properties[] = { {0} };
  return (context->binding->map_newtype)(context, name, initialzier,
    methods == ((void *)0) ? no_methods : methods, properties == ((void *)0) ? no_properties : properties);
}

variable_types: struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *

variable_types:
name
char *

variable_types:
initialzier
void (*)(struct _SxcContext *context)

variable_types:
methods
struct _SxcLibMethod *

variable_types:
properties
struct _SxcLibProperty *

variable_types: struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context); } []

variable_types: struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context); void (*setter)(struct _SxcContext *context); } []


decompiled_code:
__int64 sxc_map_intget(__int64 a1, unsigned int a2, char a3, unsigned int a4, ...)
{
unsigned int v6; // er12
char *v8; // r14
__int64 v9[5]; // [rsp+0h] [rbp-118h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-F0h] BYREF

v9[0] = *(_QWORD *)(a1 + 16);
(**(void (__fastcall ***)(_QWORD, _QWORD, __int64 *))(a1 + 8))(*(_QWORD *)a1, a2, v9);
if ( a4 == -1 )
sxc_value_cnormalize(v9);
va_start(va, a4);
v6 = sxc_value_getv(v9, a4, va);
if ( v6 != 1 && a3 )
{
v8 = (char *)sxc_alloc(*(_QWORD *)(a1 + 16), 31LL);
sprintf(v8, "element %d", a2);
sxc_typeerror(*(_QWORD *)(a1 + 16), v8, a4, v9);
}
return v6;
}

canonical_decompiled_code:
__int64 func3(__int64 a1, unsigned int a2, char a3, unsigned int a4, ...)
{
unsigned int v6; // er12
char *v8; // r14
__int64 v9[5]; // [rsp+0h] [rbp-118h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-F0h] BYREF

v9[0] = *(_QWORD *)(a1 + 16);
(**(void (__fastcall ***)(_QWORD, _QWORD, __int64 *))(a1 + 8))(*(_QWORD *)a1, a2, v9);
if ( a4 == -1 )
sxc_value_cnormalize(v9);
va_start(va, a4);
v6 = sxc_value_getv(v9, a4, va);
if ( v6 != 1 && a3 )
{
v8 = (char *)sxc_alloc(*(_QWORD *)(a1 + 16), 31LL);
sprintf(v8, "element %d", a2);
sxc_typeerror(*(_QWORD *)(a1 + 16), v8, a4, v9);
}
return v6;
}

original_code:
int sxc_map_intget(SxcMap* map, int key, _Bool is_required, SxcDataType type, ...) {
  va_list varg;
  int retval;
  SxcValue value;
  const char* value_name_format = "element %d";
  char* value_name;
  value.context = map->context;
  (map->binding->intget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + 20 + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

canonical_original_code:
int sxc_map_intget(struct _SxcMap *map, int key, _Bool is_required, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  int retval;
  struct _SxcValue value;
  char *value_name_format = "element %d";
  char *value_name;
  value.context = map->context;
  (map->binding->intget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + 20 + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

variable_types: key int

variable_types: enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 }

variable_types: retval int

user_defined_types: struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; }

user_defined_types: struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; }

user_defined_types: struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); }

user_defined_types: struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); }

user_defined_types: struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); }


decompiled_code:
__int64 sxc_map_intset(_QWORD *a1, unsigned int a2, unsigned int a3, ...)
{
__int64 v4[5]; // [rsp+0h] [rbp-108h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-E0h] BYREF

va_start(va, a3);
v4[0] = a1[2];
sxc_value_setv(v4, a3, va);
sxc_value_snormalize(v4);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64 *))(a1[1] + 8LL))(*a1, a2, v4);
}

canonical_decompiled_code:
__int64 func4(_QWORD *a1, unsigned int a2, unsigned int a3, ...)
{
__int64 v4[5]; // [rsp+0h] [rbp-108h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-E0h] BYREF

va_start(va, a3);
v4[0] = a1[2];
sxc_value_setv(v4, a3, va);
sxc_value_snormalize(v4);
return (*(__int64 (__fastcall **)(_QWORD, _QWORD, __int64 *))(a1[1] + 8LL))(*a1, a2, v4);
}

original_code:
void sxc_map_intset(SxcMap* map, int key, SxcDataType type, ...) {
  va_list varg;
  SxcValue value;
  value.context = map->context;
  __builtin_va_start(varg,type);
  sxc_value_setv(&value, type, varg);
  __builtin_va_end(varg);
  sxc_value_snormalize(&value);
  (map->binding->intset)(map->underlying, key, &value);
}

canonical_original_code:
void sxc_map_intset(struct _SxcMap *map, int key, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  struct _SxcValue value;
  value.context = map->context;
  __builtin_va_start(varg,type);
  sxc_value_setv(&value, type, varg);
  __builtin_va_end(varg);
  sxc_value_snormalize(&value);
  (map->binding->intset)(map->underlying, key, &value);
}

user_defined_types: enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 }


decompiled_code:
__int64 sxc_map_strget(_QWORD *a1, const char *a2, char a3, unsigned int a4, ...)
{
unsigned int v6; // er12
int v8; // eax
char *v9; // r14
__int64 v10[5]; // [rsp+0h] [rbp-118h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-F0h] BYREF

v10[0] = a1[2];
(*(void (__fastcall **)(_QWORD, const char *, __int64 *))(a1[1] + 16LL))(*a1, a2, v10);
if ( a4 == -1 )
sxc_value_cnormalize(v10);
va_start(va, a4);
v6 = sxc_value_getv(v10, a4, va);
if ( v6 != 1 && a3 )
{
v8 = strlen(a2);
v9 = (char *)sxc_alloc(a1[2], (unsigned int)(v8 + 13));
sprintf(v9, "element \"%s\"", a2);
sxc_typeerror(a1[2], v9, a4, v10);
}
return v6;
}

canonical_decompiled_code:
__int64 func5(_QWORD *a1, const char *a2, char a3, unsigned int a4, ...)
{
unsigned int v6; // er12
int v8; // eax
char *v9; // r14
__int64 v10[5]; // [rsp+0h] [rbp-118h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-F0h] BYREF

v10[0] = a1[2];
(*(void (__fastcall **)(_QWORD, const char *, __int64 *))(a1[1] + 16LL))(*a1, a2, v10);
if ( a4 == -1 )
sxc_value_cnormalize(v10);
va_start(va, a4);
v6 = sxc_value_getv(v10, a4, va);
if ( v6 != 1 && a3 )
{
v8 = strlen(a2);
v9 = (char *)sxc_alloc(a1[2], (unsigned int)(v8 + 13));
sprintf(v9, "element \"%s\"", a2);
sxc_typeerror(a1[2], v9, a4, v10);
}
return v6;
}

original_code:
int sxc_map_strget(SxcMap* map, const char* key, _Bool is_required, SxcDataType type, ...) {
  va_list varg;
  int retval;
  SxcValue value;
  const char* value_name_format = "element \"%s\"";
  char* value_name;
  value.context = map->context;
  (map->binding->strget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + strlen(key) + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

canonical_original_code:
int sxc_map_strget(struct _SxcMap *map, char *key, _Bool is_required, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  int retval;
  struct _SxcValue value;
  char *value_name_format = "element \"%s\"";
  char *value_name;
  value.context = map->context;
  (map->binding->strget)(map->underlying, key, &value);
  if (type == (-1)) {
    sxc_value_cnormalize(&value);
  }
  __builtin_va_start(varg,type);
  retval = sxc_value_getv(&value, type, varg);
  __builtin_va_end(varg);
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(map->context, sizeof(char) * (strlen(value_name_format) + strlen(key) + 1));
    sprintf(value_name, value_name_format, key);
    sxc_typeerror(map->context, value_name, type, &value);
  }
  return retval;
}

variable_types:
key
char *


decompiled_code:
__int64 sxc_map_strset(_QWORD *a1, __int64 a2, unsigned int a3, ...)
{
__int64 v4[5]; // [rsp+0h] [rbp-108h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-E0h] BYREF

va_start(va, a3);
v4[0] = a1[2];
sxc_value_setv(v4, a3, va);
sxc_value_snormalize(v4);
return (*(__int64 (__fastcall **)(_QWORD, __int64, __int64 *))(a1[1] + 24LL))(*a1, a2, v4);
}

canonical_decompiled_code:
__int64 func6(_QWORD *a1, __int64 a2, unsigned int a3, ...)
{
__int64 v4[5]; // [rsp+0h] [rbp-108h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-E0h] BYREF

va_start(va, a3);
v4[0] = a1[2];
sxc_value_setv(v4, a3, va);
sxc_value_snormalize(v4);
return (*(__int64 (__fastcall **)(_QWORD, __int64, __int64 *))(a1[1] + 24LL))(*a1, a2, v4);
}

original_code:
void sxc_map_strset(SxcMap* map, const char* key, SxcDataType type, ...) {
  va_list varg;
  SxcValue value;
  value.context = map->context;
  __builtin_va_start(varg,type);
  sxc_value_setv(&value, type, varg);
  __builtin_va_end(varg);
  sxc_value_snormalize(&value);
  (map->binding->strset)(map->underlying, key, &value);
}

canonical_original_code:
void sxc_map_strset(struct _SxcMap *map, char *key, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  struct _SxcValue value;
  value.context = map->context;
  __builtin_va_start(varg,type);
  sxc_value_setv(&value, type, varg);
  __builtin_va_end(varg);
  sxc_value_snormalize(&value);
  (map->binding->strset)(map->underlying, key, &value);
}


decompiled_code:
__int64 __fastcall sxc_map_length(_QWORD *a1)
{
__int64 (__fastcall *v1)(_QWORD); // rax
__int64 result; // rax
int v3; // ebp
int v4; // er13
__int64 v5; // rsi
__int64 v6; // [rsp+0h] [rbp-68h] BYREF
int v7; // [rsp+8h] [rbp-60h]
__int64 v8; // [rsp+20h] [rbp-48h] BYREF
int v9; // [rsp+28h] [rbp-40h]
int v10; // [rsp+30h] [rbp-38h]

v1 = *(__int64 (__fastcall **)(_QWORD))(a1[1] + 32LL);
if ( v1 )
return v1(*a1);
v8 = a1[2];
v6 = v8;
v3 = -1;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v5 = map_iter(a1, v5, (__int64)&v8, (__int64)&v6);
if ( !v5 )
break;
if ( v9 == 7 )
{
if ( v7 != 9 )
return 0xFFFFFFFFLL;
}
else if ( v9 == 2 )
{
++v4;
if ( v3 < v10 )
v3 = v10;
}
}
result = (unsigned int)(v3 + 1);
if ( v3 - v4 >= 8 * v4 )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 (__fastcall *v1)(_QWORD); // rax
__int64 result; // rax
int v3; // ebp
int v4; // er13
__int64 v5; // rsi
__int64 v6; // [rsp+0h] [rbp-68h] BYREF
int v7; // [rsp+8h] [rbp-60h]
__int64 v8; // [rsp+20h] [rbp-48h] BYREF
int v9; // [rsp+28h] [rbp-40h]
int v10; // [rsp+30h] [rbp-38h]

v1 = *(__int64 (__fastcall **)(_QWORD))(a1[1] + 32LL);
if ( v1 )
return v1(*a1);
v8 = a1[2];
v6 = v8;
v3 = -1;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v5 = func0(a1, v5, (__int64)&v8, (__int64)&v6);
if ( !v5 )
break;
if ( v9 == 7 )
{
if ( v7 != 9 )
return 0xFFFFFFFFLL;
}
else if ( v9 == 2 )
{
++v4;
if ( v3 < v10 )
v3 = v10;
}
}
result = (unsigned int)(v3 + 1);
if ( v3 - v4 >= 8 * v4 )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int sxc_map_length(SxcMap* map) {
  void* iter = ((void *)0);
  SxcValue key;
  SxcValue val;
  int key_count = 0;
  int key_max = -1;
  if (map->binding->length != ((void *)0)) {
    return (map->binding->length)(map->underlying);
  }
  else {
    key.context = map->context;
    val.context = map->context;
    while ((iter = map_iter(map, iter, &key, &val))) {
      if (key.type == sxc_sstring && val.type != sxc_sfunc) {
        return -1;
      }
      if (key.type == sxc_cint) {
        key_count += 1;
        key_max = key.data.cint > key_max ? key.data.cint : key_max;
      }
    }
    return ((key_max - key_count) >= (8 * key_count)) ? -1 : (key_max + 1);
  }
}

canonical_original_code:
int sxc_map_length(struct _SxcMap *map) {
  void *iter = ((void *)0);
  struct _SxcValue key;
  struct _SxcValue val;
  int key_count = 0;
  int key_max = -1;
  if (map->binding->length != ((void *)0)) {
    return (map->binding->length)(map->underlying);
  }
  else {
    key.context = map->context;
    val.context = map->context;
    while ((iter = map_iter(map, iter, &key, &val))) {
      if (key.type == sxc_sstring && val.type != sxc_sfunc) {
        return -1;
      }
      if (key.type == sxc_cint) {
        key_count += 1;
        key_max = key.data.cint > key_max ? key.data.cint : key_max;
      }
    }
    return ((key_max - key_count) >= (8 * key_count)) ? -1 : (key_max + 1);
  }
}

variable_types:
iter
void *


decompiled_code:
__int64 __fastcall sxc_map_iter(_QWORD *a1, __int64 a2, _QWORD *a3, _QWORD *a4)
{
__int64 v6; // rax
__int64 v7; // r12

v6 = a1[2];
*a3 = v6;
*a4 = v6;
v7 = map_iter(a1, a2, (__int64)a3, (__int64)a4);
if ( v7 )
{
sxc_value_cnormalize(a3);
sxc_value_cnormalize(a4);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2, _QWORD *a3, _QWORD *a4)
{
__int64 v6; // rax
__int64 v7; // r12

v6 = a1[2];
*a3 = v6;
*a4 = v6;
v7 = func0(a1, a2, (__int64)a3, (__int64)a4);
if ( v7 )
{
sxc_value_cnormalize(a3);
sxc_value_cnormalize(a4);
}
return v7;
}

original_code:
void* sxc_map_iter(SxcMap* map, void* state, SxcValue* return_key, SxcValue* return_value) {
  return_key->context = map->context;
  return_value->context = map->context;
  state = map_iter(map, state, return_key, return_value);
  if (state != ((void *)0)) {
    sxc_value_cnormalize(return_key);
    sxc_value_cnormalize(return_value);
  }
  return state;
}

canonical_original_code:
void *sxc_map_iter(struct _SxcMap *map, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value) {
  return_key->context = map->context;
  return_value->context = map->context;
  state = map_iter(map, state, return_key, return_value);
  if (state != ((void *)0)) {
    sxc_value_cnormalize(return_key);
    sxc_value_cnormalize(return_value);
  }
  return state;
}


decompiled_code:
void __noreturn sxc_error(__int64 a1, const char *a2, ...)
{
__int64 v2; // r12
char *v3; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v2 = 8 * (unsigned int)strlen(a2);
v3 = (char *)sxc_alloc(a1, v2);
vsnprintf(v3, (int)v2, a2, arg);
if ( (int)v2 <= 0 )
{
v3 = (char *)sxc_alloc(a1, 1LL);
va_end(arg);
va_start(arg, a2);
vsnprintf(v3, 1uLL, a2, arg);
}
sxc_value_set(a1 + 24, 13LL, v3, 0LL);
*(_DWORD *)(a1 + 56) = 1;
siglongjmp(*(struct __jmp_buf_tag **)(a1 + 64), 1);
}

canonical_decompiled_code:
void __noreturn func0(__int64 a1, const char *a2, ...)
{
__int64 v2; // r12
char *v3; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v2 = 8 * (unsigned int)strlen(a2);
v3 = (char *)func1(a1, v2);
vsnprintf(v3, (int)v2, a2, arg);
if ( (int)v2 <= 0 )
{
v3 = (char *)func1(a1, 1LL);
va_end(arg);
va_start(arg, a2);
vsnprintf(v3, 1uLL, a2, arg);
}
sxc_value_set(a1 + 24, 13LL, v3, 0LL);
*(_DWORD *)(a1 + 56) = 1;
siglongjmp(*(struct __jmp_buf_tag **)(a1 + 64), 1);
}

original_code:
void* sxc_error(SxcContext* context, const char* message_format, ...) {
  va_list varg;
  char* buffer;
  int buffer_len;
  int actual_len;
    buffer_len = strlen(message_format) * 8;
    buffer = sxc_alloc(context, buffer_len);
    __builtin_va_start(varg,message_format);
    vsnprintf(buffer, buffer_len, message_format, varg);
    __builtin_va_end(varg);
    if ((actual_len + 1) > buffer_len) {
      buffer_len = actual_len + 1;
      buffer = sxc_alloc(context, buffer_len);
      __builtin_va_start(varg,message_format);
      vsnprintf(buffer, buffer_len, message_format, varg);
      __builtin_va_end(varg);
    } else {
      while (actual_len < 0) {
        buffer_len *= 4;
        buffer = sxc_alloc(context, buffer_len);
        __builtin_va_start(varg,message_format);
        actual_len = vsnprintf(buffer, buffer_len, message_format, varg);
        __builtin_va_end(varg);
      }
    }
  sxc_value_set(&context->return_value, sxc_cchars, buffer, actual_len);
  context->has_error = 1;
  (siglongjmp(*(sigjmp_buf*)(context->_jmpbuf), 1));
  return ((void *)0);
}

canonical_original_code:
void *sxc_error(struct _SxcContext *context, char *message_format, ...) {
  __builtin_va_list varg;
  char *buffer;
  int buffer_len;
  int actual_len;
    buffer_len = strlen(message_format) * 8;
    buffer = sxc_alloc(context, buffer_len);
    __builtin_va_start(varg,message_format);
    vsnprintf(buffer, buffer_len, message_format, varg);
    __builtin_va_end(varg);
    if ((actual_len + 1) > buffer_len) {
      buffer_len = actual_len + 1;
      buffer = sxc_alloc(context, buffer_len);
      __builtin_va_start(varg,message_format);
      vsnprintf(buffer, buffer_len, message_format, varg);
      __builtin_va_end(varg);
    } else {
      while (actual_len < 0) {
        buffer_len *= 4;
        buffer = sxc_alloc(context, buffer_len);
        __builtin_va_start(varg,message_format);
        actual_len = vsnprintf(buffer, buffer_len, message_format, varg);
        __builtin_va_end(varg);
      }
    }
  sxc_value_set(&context->return_value, sxc_cchars, buffer, actual_len);
  context->has_error = 1;
  (siglongjmp(*(struct __jmp_buf_tag (*)[1])(context->_jmpbuf), 1));
  return ((void *)0);
}

variable_types:
buffer
char *

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

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


decompiled_code:
__int64 __fastcall sxc_alloc(__int64 a1, __int64 a2)
{
int v2; // ebp
_DWORD *v3; // rbx
__int64 v4; // r12
int v5; // eax
int v6; // edx
int v7; // er12
_DWORD *v8; // rax
int v9; // eax
__int64 v10; // rsi

v2 = a2;
v3 = (_DWORD *)(a1 + 72);
printf("in sxc_context_alloc, size: %d, first chunk free: %d\n", a2, *(unsigned int *)(a1 + 72));
if ( (int)a2 <= 0 )
return 0LL;
while ( *v3 < (int)a2 )
{
if ( !*((_QWORD *)v3 + 1) )
{
puts("...allocating new node");
v5 = v3[4] + *v3;
do
{
v5 *= 2;
v6 = 0x3FFF;
if ( (int)a2 <= 0x3FFF )
v6 = a2;
}
while ( v5 <= v6 );
if ( (int)a2 >= v5 )
v5 = a2;
v7 = v5;
printf("...new node space: %d\n", (unsigned int)v5);
v8 = malloc(v7 + 23LL);
*((_QWORD *)v3 + 1) = v8;
if ( !v8 )
sxc_error(a1, "Error: out of memory");
*v8 = v7;
v8[4] = 0;
*((_QWORD *)v8 + 1) = 0LL;
v3 = v8;
break;
}
v3 = (_DWORD *)*((_QWORD *)v3 + 1);
}
v9 = v3[4];
v4 = (__int64)v3 + v9 + 20;
v10 = (unsigned int)(*v3 - a2);
*v3 = v10;
v3[4] = v2 + v9;
printf("...done sxc_context_alloc, free space: %d\n", v10);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // ebp
_DWORD *v3; // rbx
__int64 v4; // r12
int v5; // eax
int v6; // edx
int v7; // er12
_DWORD *v8; // rax
int v9; // eax
__int64 v10; // rsi

v2 = a2;
v3 = (_DWORD *)(a1 + 72);
printf("in sxc_context_alloc, size: %d, first chunk free: %d\n", a2, *(unsigned int *)(a1 + 72));
if ( (int)a2 <= 0 )
return 0LL;
while ( *v3 < (int)a2 )
{
if ( !*((_QWORD *)v3 + 1) )
{
puts("...allocating new node");
v5 = v3[4] + *v3;
do
{
v5 *= 2;
v6 = 0x3FFF;
if ( (int)a2 <= 0x3FFF )
v6 = a2;
}
while ( v5 <= v6 );
if ( (int)a2 >= v5 )
v5 = a2;
v7 = v5;
printf("...new node space: %d\n", (unsigned int)v5);
v8 = malloc(v7 + 23LL);
*((_QWORD *)v3 + 1) = v8;
if ( !v8 )
func0(a1, "Error: out of memory");
*v8 = v7;
v8[4] = 0;
*((_QWORD *)v8 + 1) = 0LL;
v3 = v8;
break;
}
v3 = (_DWORD *)*((_QWORD *)v3 + 1);
}
v9 = v3[4];
v4 = (__int64)v3 + v9 + 20;
v10 = (unsigned int)(*v3 - a2);
*v3 = v10;
v3[4] = v2 + v9;
printf("...done sxc_context_alloc, free space: %d\n", v10);
return v4;
}

original_code:
void* sxc_alloc(SxcContext* context, int size) {
  SxcMemoryChunk* walker = &(context->_firstchunk);
  void* retval;
  int new_free_space;
printf("in sxc_context_alloc, size: %d, first chunk free: %d\n", size, walker->free_space);
  if (size <= 0) return ((void *)0);
  while (walker->free_space < size && walker->next_chunk != ((void *)0)) {
    walker = walker->next_chunk;
  }
  if (walker->free_space < size) {
printf("...allocating new node\n");
    new_free_space = (walker->offset + walker->free_space);
    do {
      new_free_space *= 2;
    } while (new_free_space <= size && new_free_space < (1024 * 16));
    new_free_space = size > new_free_space ? size : new_free_space;
printf("...new node space: %d\n", new_free_space);
    walker->next_chunk = malloc(sizeof(SxcMemoryChunk) + new_free_space - 1 );
    if (walker->next_chunk == ((void *)0)) {
      return sxc_error(context, "Error: out of memory");
    }
    walker = walker->next_chunk;
    walker->free_space = new_free_space;
    walker->offset = 0;
    walker->next_chunk = ((void *)0);
  }
  retval = &(walker->data) + walker->offset;
  walker->free_space -= size;
  walker->offset += size;
printf("...done sxc_context_alloc, free space: %d\n", walker->free_space);
  return retval;
}

canonical_original_code:
void *sxc_alloc(struct _SxcContext *context, int size) {
  struct _SxcMemoryChunk *walker = &(context->_firstchunk);
  void *retval;
  int new_free_space;
printf("in sxc_context_alloc, size: %d, first chunk free: %d\n", size, walker->free_space);
  if (size <= 0) return ((void *)0);
  while (walker->free_space < size && walker->next_chunk != ((void *)0)) {
    walker = walker->next_chunk;
  }
  if (walker->free_space < size) {
printf("...allocating new node\n");
    new_free_space = (walker->offset + walker->free_space);
    do {
      new_free_space *= 2;
    } while (new_free_space <= size && new_free_space < (1024 * 16));
    new_free_space = size > new_free_space ? size : new_free_space;
printf("...new node space: %d\n", new_free_space);
    walker->next_chunk = malloc(sizeof(SxcMemoryChunk) + new_free_space - 1 );
    if (walker->next_chunk == ((void *)0)) {
      return sxc_error(context, "Error: out of memory");
    }
    walker = walker->next_chunk;
    walker->free_space = new_free_space;
    walker->offset = 0;
    walker->next_chunk = ((void *)0);
  }
  retval = &(walker->data) + walker->offset;
  walker->free_space -= size;
  walker->offset += size;
printf("...done sxc_context_alloc, free space: %d\n", walker->free_space);
  return retval;
}

variable_types: size int

variable_types: struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } *

variable_types:
retval
void *


decompiled_code:
void __fastcall __noreturn sxc_typeerror(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
unsigned int v4; // eax
const char *v5; // r8
__int64 v6[18]; // [rsp+0h] [rbp-148h]
__int64 v7[23]; // [rsp+90h] [rbp-B8h]

v7[0] = (__int64)"null";
v7[1] = (__int64)"a boolean";
v7[2] = (__int64)"an int";
v7[3] = (__int64)"a double";
v7[4] = (__int64)"a string";
v7[5] = (__int64)"a map";
v7[6] = (__int64)"a function";
v7[7] = (__int64)"a string";
v7[8] = (__int64)"a map";
v7[9] = (__int64)"a function";
v7[10] = (__int64)"a string";
v7[11] = (__int64)"a reference to a C struct";
v7[12] = (__int64)"a C function";
v7[13] = (__int64)"a string";
v7[14] = (__int64)"a list of booleans";
v7[15] = (__int64)"a list of ints";
v7[16] = (__int64)"a list of doubles";
v7[17] = (__int64)"a list of strings";
v6[0] = (__int64)"null";
v6[1] = (__int64)"a boolean";
v6[2] = (__int64)"an int";
v6[3] = (__int64)"a double";
v6[4] = (__int64)"a string";
v6[5] = (__int64)"a map";
v6[6] = (__int64)"a function";
v6[7] = (__int64)"a string";
v6[8] = (__int64)"a map";
v6[9] = (__int64)"a function";
v6[10] = (__int64)"a C string";
v6[11] = (__int64)"a C pointer";
v6[12] = (__int64)"a C function";
v6[13] = (__int64)"an array of chars";
v6[14] = (__int64)"an array of booleans";
v6[15] = (__int64)"an array of ints";
v6[16] = (__int64)"an array of doubles";
v6[17] = (__int64)"an array of strings";
if ( a3 )
{
if ( a3 <= 0x11 )
{
v4 = *(_DWORD *)(a4 + 8);
v5 = "of unknown type";
if ( v4 <= 0x11 )
v5 = (const char *)v6[v4];
sxc_error(a1, "Expected %s to be %s (or compatible). Actual value was %s.", a2, (const char *)v7[a3], v5);
}
sxc_error(a1, "Can not extract %s because destination type (%d) is unrecognized.", a2, a3);
}
sxc_error(a1, "Can not extract %s because destination type is sxc_null.", a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
unsigned int v4; // eax
const char *v5; // r8
__int64 v6[18]; // [rsp+0h] [rbp-148h]
__int64 v7[23]; // [rsp+90h] [rbp-B8h]

v7[0] = (__int64)"null";
v7[1] = (__int64)"a boolean";
v7[2] = (__int64)"an int";
v7[3] = (__int64)"a double";
v7[4] = (__int64)"a string";
v7[5] = (__int64)"a map";
v7[6] = (__int64)"a function";
v7[7] = (__int64)"a string";
v7[8] = (__int64)"a map";
v7[9] = (__int64)"a function";
v7[10] = (__int64)"a string";
v7[11] = (__int64)"a reference to a C struct";
v7[12] = (__int64)"a C function";
v7[13] = (__int64)"a string";
v7[14] = (__int64)"a list of booleans";
v7[15] = (__int64)"a list of ints";
v7[16] = (__int64)"a list of doubles";
v7[17] = (__int64)"a list of strings";
v6[0] = (__int64)"null";
v6[1] = (__int64)"a boolean";
v6[2] = (__int64)"an int";
v6[3] = (__int64)"a double";
v6[4] = (__int64)"a string";
v6[5] = (__int64)"a map";
v6[6] = (__int64)"a function";
v6[7] = (__int64)"a string";
v6[8] = (__int64)"a map";
v6[9] = (__int64)"a function";
v6[10] = (__int64)"a C string";
v6[11] = (__int64)"a C pointer";
v6[12] = (__int64)"a C function";
v6[13] = (__int64)"an array of chars";
v6[14] = (__int64)"an array of booleans";
v6[15] = (__int64)"an array of ints";
v6[16] = (__int64)"an array of doubles";
v6[17] = (__int64)"an array of strings";
if ( a3 )
{
if ( a3 <= 0x11 )
{
v4 = *(_DWORD *)(a4 + 8);
v5 = "of unknown type";
if ( v4 <= 0x11 )
v5 = (const char *)v6[v4];
func0(a1, "Expected %s to be %s (or compatible). Actual value was %s.", a2, (const char *)v7[a3], v5);
}
func0(a1, "Can not extract %s because destination type (%d) is unrecognized.", a2, a3);
}
func0(a1, "Can not extract %s because destination type is sxc_null.", a2);
}

original_code:
void sxc_typeerror(SxcContext* context, char* value_name, SxcDataType expected_type, SxcValue* actual_value) {
  const char* expected_types[] = {
                          "null",
                          "a boolean",
                          "an int",
                          "a double",
                          "a string",
                          "a map",
                          "a function",
                          "a string",
                          "a map",
                          "a function",
                          "a string",
                          "a reference to a C struct",
                          "a C function",
                          "a string",
                          "a list of booleans",
                          "a list of ints",
                          "a list of doubles",
                          "a list of strings"
    };
  const char* actual_types[] = {
                          "null",
                          "a boolean",
                          "an int",
                          "a double",
                          "a string",
                          "a map",
                          "a function",
                          "a string",
                          "a map",
                          "a function",
                          "a C string",
                          "a C pointer",
                          "a C function",
                          "an array of chars",
                          "an array of booleans",
                          "an array of ints",
                          "an array of doubles",
                          "an array of strings"
    };
  if (expected_type == sxc_null) {
    sxc_error(context, "Can not extract %s because destination type "
        "is sxc_null.", value_name);
  }
  else if (expected_type >= (sizeof(expected_types) / sizeof(expected_types[0]))) {
    sxc_error(context, "Can not extract %s because destination type "
        "(%d) is unrecognized.", value_name, expected_type);
  }
  else {
    sxc_error(context, "Expected %s to be %s (or compatible).  Actual value was %s.",
        value_name,
        expected_types[expected_type],
        actual_value->type >= (sizeof(actual_types) / sizeof(actual_types[0]))
          ? "of unknown type"
          : actual_types[actual_value->type]);
  }
}

canonical_original_code:
void sxc_typeerror(struct _SxcContext *context, char *value_name, enum _SxcDataType expected_type, struct _SxcValue *actual_value) {
  char *expected_types[] = {
                          "null",
                          "a boolean",
                          "an int",
                          "a double",
                          "a string",
                          "a map",
                          "a function",
                          "a string",
                          "a map",
                          "a function",
                          "a string",
                          "a reference to a C struct",
                          "a C function",
                          "a string",
                          "a list of booleans",
                          "a list of ints",
                          "a list of doubles",
                          "a list of strings"
    };
  char *actual_types[] = {
                          "null",
                          "a boolean",
                          "an int",
                          "a double",
                          "a string",
                          "a map",
                          "a function",
                          "a string",
                          "a map",
                          "a function",
                          "a C string",
                          "a C pointer",
                          "a C function",
                          "an array of chars",
                          "an array of booleans",
                          "an array of ints",
                          "an array of doubles",
                          "an array of strings"
    };
  if (expected_type == sxc_null) {
    sxc_error(context, "Can not extract %s because destination type "
        "is sxc_null.", value_name);
  }
  else if (expected_type >= (sizeof(expected_types) / sizeof(expected_types[0]))) {
    sxc_error(context, "Can not extract %s because destination type "
        "(%d) is unrecognized.", value_name, expected_type);
  }
  else {
    sxc_error(context, "Expected %s to be %s (or compatible).  Actual value was %s.",
        value_name,
        expected_types[expected_type],
        actual_value->type >= (sizeof(actual_types) / sizeof(actual_types[0]))
          ? "of unknown type"
          : actual_types[actual_value->type]);
  }
}


decompiled_code:
__int64 sxc_arg(__int64 a1, unsigned int a2, char a3, unsigned int a4, ...)
{
unsigned int v6; // er12
char *v8; // r14
__int64 v9[5]; // [rsp+0h] [rbp-118h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-F0h] BYREF

v6 = 0;
if ( *(_DWORD *)(a1 + 16) > (signed int)a2 )
{
v9[0] = a1;
(**(void (__fastcall ***)(__int64, _QWORD, __int64 *))(a1 + 8))(a1, a2, v9);
if ( a4 == -1 )
sxc_value_cnormalize(v9);
va_start(va, a4);
v6 = sxc_value_getv(v9, a4, va);
}
if ( v6 != 1 && a3 )
{
v8 = (char *)sxc_alloc(a1, 32LL);
sprintf(v8, "argument %d", a2 + 1);
sxc_typeerror(a1, v8, a4, (__int64)v9);
}
return v6;
}

canonical_decompiled_code:
__int64 func3(__int64 a1, unsigned int a2, char a3, unsigned int a4, ...)
{
unsigned int v6; // er12
char *v8; // r14
__int64 v9[5]; // [rsp+0h] [rbp-118h] BYREF
gcc_va_list va; // [rsp+28h] [rbp-F0h] BYREF

v6 = 0;
if ( *(_DWORD *)(a1 + 16) > (signed int)a2 )
{
v9[0] = a1;
(**(void (__fastcall ***)(__int64, _QWORD, __int64 *))(a1 + 8))(a1, a2, v9);
if ( a4 == -1 )
sxc_value_cnormalize(v9);
va_start(va, a4);
v6 = sxc_value_getv(v9, a4, va);
}
if ( v6 != 1 && a3 )
{
v8 = (char *)func1(a1, 32LL);
sprintf(v8, "argument %d", a2 + 1);
func2(a1, v8, a4, (__int64)v9);
}
return v6;
}

original_code:
int sxc_arg(SxcContext* context, int index, _Bool is_required, SxcDataType type, ...) {
  va_list varg;
  int retval = (0);
  SxcValue value;
  const char* value_name_format = "argument %d";
  char* value_name;
  if (index < context->argcount) {
    value.context = context;
    (context->binding->get_arg)(context, index, &value);
    if (type == (-1)) {
      sxc_value_cnormalize(&value);
    }
    __builtin_va_start(varg,type);
    retval = sxc_value_getv(&value, type, varg);
    __builtin_va_end(varg);
  }
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(context, sizeof(char) * (strlen(value_name_format) + 20 + 1));
    sprintf(value_name, value_name_format, index + 1 );
    sxc_typeerror(context, value_name, type, &value);
  }
  return retval;
}

canonical_original_code:
int sxc_arg(struct _SxcContext *context, int index, _Bool is_required, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  int retval = (0);
  struct _SxcValue value;
  char *value_name_format = "argument %d";
  char *value_name;
  if (index < context->argcount) {
    value.context = context;
    (context->binding->get_arg)(context, index, &value);
    if (type == (-1)) {
      sxc_value_cnormalize(&value);
    }
    __builtin_va_start(varg,type);
    retval = sxc_value_getv(&value, type, varg);
    __builtin_va_end(varg);
  }
  if (is_required && retval != (1)) {
    value_name = sxc_alloc(context, sizeof(char) * (strlen(value_name_format) + 20 + 1));
    sprintf(value_name, value_name_format, index + 1 );
    sxc_typeerror(context, value_name, type, &value);
  }
  return retval;
}

variable_types: index int

variable_types: struct _SxcValue { struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; }


decompiled_code:
__int64 sxc_return(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return sxc_value_setv(a1 + 24, a2, va);
}

canonical_decompiled_code:
__int64 func4(__int64 a1, __int64 a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return sxc_value_setv(a1 + 24, a2, va);
}

original_code:
void sxc_return(SxcContext* context, SxcDataType type, ...) {
  va_list varg;
  __builtin_va_start(varg,type);
  sxc_value_setv(&context->return_value, type, varg);
  __builtin_va_end(varg);
}

canonical_original_code:
void sxc_return(struct _SxcContext *context, enum _SxcDataType type, ...) {
  __builtin_va_list varg;
  __builtin_va_start(varg,type);
  sxc_value_setv(&context->return_value, type, varg);
  __builtin_va_end(varg);
}

variable_types: struct _SxcContext { void *underlying; struct _SxcContextBinding { void (*get_arg)(void *underlying, int index, struct _SxcValue { struct _SxcContext *context; enum _SxcDataType { sxc_null=0, sxc_cbool=1, sxc_cint=2, sxc_cdouble=3, sxc_string=4, sxc_map=5, sxc_func=6, sxc_sstring=7, sxc_smap=8, sxc_sfunc=9, sxc_cstring=10, sxc_cpointer=11, sxc_cfunc=12, sxc_cchars=13, sxc_cbools=14, sxc_cints=15, sxc_cdoubles=16, sxc_cstrings=17 } type; union _SxcData { _Bool cbool; int cint; double cdouble; void *_pointer_store; struct _SxcString { void *underlying; struct _SxcStringBinding { void (*to_cchars)(void *underlying, struct _SxcValue *return_value); int is_null_terminated; } *binding; struct _SxcContext *context; char *data; int length; } *string; struct _SxcMap { void *underlying; struct _SxcMapBinding { void (*intget)(void *underlying, int key, struct _SxcValue *return_value); void (*intset)(void *underlying, int key, struct _SxcValue *value); void (*strget)(void *underlying, char *key, struct _SxcValue *return_value); void (*strset)(void *underlying, char *key, struct _SxcValue *value); int (*length)(void *underlying); void *(*iter)(void *underlying, void *state, struct _SxcValue *return_key, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *map; struct _SxcFunc { void *underlying; struct _SxcFunctionBinding { void (*invoke)(void *underlying, struct _SxcValue **args, int argcount, struct _SxcValue *return_value); } *binding; struct _SxcContext *context; } *func; struct { void *underlying; void *binding; } _binding_store; struct { void *underlying; struct _SxcStringBinding *binding; } sstring; struct { void *underlying; struct _SxcMapBinding *binding; } smap; struct { void *underlying; struct _SxcFunctionBinding *binding; } sfunc; char *cstring; void (*cfunc)(struct _SxcContext *context); void *cpointer; struct { void *array; int length; } _array_store; struct { char *array; int length; } cchars; struct { _Bool *array; int length; } cbools; struct { int *array; int length; } cints; struct { double *array; int length; } cdoubles; struct { char **array; int length; } cstrings; } data; } *return_value); void (*to_sstring)(char *data, int length, struct _SxcValue *return_value); void (*map_new)(void *map_type, struct _SxcValue *return_value); void *(*map_newtype)(struct _SxcContext *context, char *name, void (*initializer)(struct _SxcContext *context), struct _SxcLibMethod { char *name; int is_static; void (*func)(struct _SxcContext *context); } *methods, struct _SxcLibProperty { char *name; int is_static; void (*getter)(struct _SxcContext *context); void (*setter)(struct _SxcContext *context); } *properties); void (*to_sfunc)(void (*func)(struct _SxcContext *context), struct _SxcValue *return_value); } *binding; int argcount; struct _SxcValue return_value; int has_error; void *_jmpbuf; struct _SxcMemoryChunk { int free_space; struct _SxcMemoryChunk *next_chunk; int offset; char data; } _firstchunk; char _firstdata[-1]; } *


original_code:
void sxc_try(SxcContext* context, void* underlying, SxcContextBinding* binding, int argcount, SxcLibFunc func) {
  sigjmp_buf jmpbuf;
  context->underlying = underlying;
  context->binding = binding;
  context->argcount = argcount;
  context->return_value = (SxcValue){context, sxc_null, {0}};
  context->_jmpbuf = &jmpbuf;
  context->_firstchunk = (SxcMemoryChunk){(1024 * 2), ((void *)0), 0, 0};
  if (!(context->has_error = (__sigsetjmp (jmpbuf, 0)))) {
    (func)(context);
  }
  sxc_value_snormalize(&context->return_value);
}

canonical_original_code:
void sxc_try(struct _SxcContext *context, void *underlying, struct _SxcContextBinding *binding, int argcount, void func(struct _SxcContext *context)) {
  struct __jmp_buf_tag jmpbuf[1];
  context->underlying = underlying;
  context->binding = binding;
  context->argcount = argcount;
  context->return_value = (struct _SxcValue){context, sxc_null, {0}};
  context->_jmpbuf = &jmpbuf;
  context->_firstchunk = (struct _SxcMemoryChunk){(1024 * 2), ((void *)0), 0, 0};
  if (!(context->has_error = (__sigsetjmp (jmpbuf, 0)))) {
    (func)(context);
  }
  sxc_value_snormalize(&context->return_value);
}

variable_types:
underlying
void *

variable_types:
binding
struct _SxcContextBinding *

variable_types: argcount int

variable_types:
func
void (struct _SxcContext *context)

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]