decompiled_code:
__int64 ojr_close_all()
{
_QWORD *v0; // rbx
unsigned int v1; // ebp
void *v2; // rdi
void *v3; // rdi

v0 = (_QWORD *)ojr_genlist_head;
if ( !ojr_genlist_head )
return 0;
v1 = 0;
do
{
ojr_genlist_head = v0[6];
v2 = (void *)v0[3];
if ( v2 )
free(v2);
v3 = (void *)v0[4];
if ( v3 )
free(v3);
free(v0);
v0 = (_QWORD *)ojr_genlist_head;
++v1;
}
while ( ojr_genlist_head );
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rbx
unsigned int v1; // ebp
void *v2; // rdi
void *v3; // rdi

v0 = (_QWORD *)ojr_genlist_head;
if ( !ojr_genlist_head )
return 0;
v1 = 0;
do
{
ojr_genlist_head = v0[6];
v2 = (void *)v0[3];
if ( v2 )
free(v2);
v3 = (void *)v0[4];
if ( v3 )
free(v3);
free(v0);
v0 = (_QWORD *)ojr_genlist_head;
++v1;
}
while ( ojr_genlist_head );
return v1;
}

original_code:
int ojr_close_all(void) {
    int c = 0;
    ojr_generator *g = ojr_genlist_head;
    while (g) {
        ojr_genlist_head = g->next;
        if (g->state) free(g->state);
        if (g->buf) free(g->buf);
        free(g);
        g = ojr_genlist_head;
        ++c;
    }
    return c;
}

canonical_original_code:
int ojr_close_all() {
    int c = 0;
    struct _ojr_generator *g = ojr_genlist_head;
    while (g) {
        ojr_genlist_head = g->next;
        if (g->state) free(g->state);
        if (g->buf) free(g->buf);
        free(g);
        g = ojr_genlist_head;
        ++c;
    }
    return c;
}

variable_types: c int

variable_types: struct _ojr_generator { int init; int leftover; int flags; int algorithm; int statesize; int bufsize; unsigned int *state; unsigned int *buf; unsigned int *bptr; struct _ojr_generator *next; void *extra; void *padding[4]; } *


repo: lcrocker/ojrandlib

decompiled_code:
__int64 ojr_library_shutdown()
{
int v0; // eax
const char *v1; // rcx

if ( ojr_library_initialized != 1592598101 )
_assert_fail(
"0x5eed1e55 == _ojr_library_initialized",
"/usr/src/repo/source/library/init.c",
0x3Du,
"ojr_library_shutdown");
v0 = ojr_close_all();
if ( v0 )
{
v1 = "s";
if ( v0 <= 1 )
v1 = (const char *)&LC5;
fprintf(stderr, "ojrandlib: %d generator object%s not freed.\n", (unsigned int)v0, v1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
const char *v1; // rcx

if ( ojr_library_initialized != 1592598101 )
_assert_fail(
"0x5eed1e55 == _ojr_library_initialized",
"/usr/src/repo/source/library/init.c",
0x3Du,
"ojr_library_shutdown");
v0 = func1();
if ( v0 )
{
v1 = "s";
if ( v0 <= 1 )
v1 = (const char *)&LC5;
fprintf(stderr, "ojrandlib: %d generator object%s not freed.\n", (unsigned int)v0, v1);
}
return 0LL;
}

original_code:
int ojr_library_shutdown(void) {
    ((0x5eed1e55 == _ojr_library_initialized) ? (void) (0) : __assert_fail ("0x5eed1e55 == _ojr_library_initialized", "/usr/src/repo/source/library/init.c", 61, __extension__ __PRETTY_FUNCTION__));
    int c = ojr_close_all();
    if (c) {
        fprintf(stderr, "ojrandlib: %d generator object%s not freed.\n",
            c, (c > 1) ? "s" : "");
    }
    return 0;
}

canonical_original_code:
int ojr_library_shutdown() {
    ((0x5eed1e55 == _ojr_library_initialized) ? (void) (0) : __assert_fail ("0x5eed1e55 == _ojr_library_initialized", "/usr/src/repo/source/library/init.c", 61, __extension__ __PRETTY_FUNCTION__));
    int c = ojr_close_all();
    if (c) {
        fprintf(stderr, "ojrandlib: %d generator object%s not freed.\n",
            c, (c > 1) ? "s" : "");
    }
    return 0;
}

return_type: int


compare

decompiled_code:
__int64 __fastcall compare(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
static int compare(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

canonical_original_code:
static int compare(void *a, void *b) {
    return *(int *)a - *(int *)b;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
void __fastcall ojr_close(void *ptr)
{
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *v3; // rdx

if ( *(_DWORD *)ptr != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0x37u, "ojr_close");
if ( !*((_QWORD *)ptr + 3) || !*((_QWORD *)ptr + 4) )
_assert_fail("g->state && g->buf", "/usr/src/repo/source/library/capi.c", 0x38u, "ojr_close");
if ( !ojr_genlist_head )
_assert_fail("NULL != ojr_genlist_head", "/usr/src/repo/source/library/capi.c", 0x39u, "ojr_close");
ojr_call_close();
v1 = (_QWORD *)ojr_genlist_head;
if ( ptr == (void *)ojr_genlist_head )
{
v3 = &ojr_genlist_head;
}
else
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[6];
}
while ( ptr != v1 );
v3 = v2 + 6;
}
*v3 = *((_QWORD *)ptr + 6);
free(*((void **)ptr + 4));
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *v3; // rdx

if ( *(_DWORD *)ptr != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0x37u, "ojr_close");
if ( !*((_QWORD *)ptr + 3) || !*((_QWORD *)ptr + 4) )
_assert_fail("g->state && g->buf", "/usr/src/repo/source/library/capi.c", 0x38u, "ojr_close");
if ( !ojr_genlist_head )
_assert_fail("NULL != ojr_genlist_head", "/usr/src/repo/source/library/capi.c", 0x39u, "ojr_close");
ojr_call_close();
v1 = (_QWORD *)ojr_genlist_head;
if ( ptr == (void *)ojr_genlist_head )
{
v3 = &ojr_genlist_head;
}
else
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[6];
}
while ( ptr != v1 );
v3 = v2 + 6;
}
*v3 = *((_QWORD *)ptr + 6);
free(*((void **)ptr + 4));
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void ojr_close(ojr_generator *g) {
    ojr_generator **p;
    ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 55, __extension__ __PRETTY_FUNCTION__));
    ((g->state && g->buf) ? (void) (0) : __assert_fail ("g->state && g->buf", "/usr/src/repo/source/library/capi.c", 56, __extension__ __PRETTY_FUNCTION__));
    ((((void *)0) != ojr_genlist_head) ? (void) (0) : __assert_fail ("NULL != ojr_genlist_head", "/usr/src/repo/source/library/capi.c", 57, __extension__ __PRETTY_FUNCTION__));
    ojr_call_close(g);
    p = &ojr_genlist_head;
    while (*p != g) p = &((*p)->next);
    *p = g->next;
    free(g->buf);
    free(g->state);
    free(g);
}

canonical_original_code:
void ojr_close(struct _ojr_generator *g) {
    struct _ojr_generator **p;
    ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 55, __extension__ __PRETTY_FUNCTION__));
    ((g->state && g->buf) ? (void) (0) : __assert_fail ("g->state && g->buf", "/usr/src/repo/source/library/capi.c", 56, __extension__ __PRETTY_FUNCTION__));
    ((((void *)0) != ojr_genlist_head) ? (void) (0) : __assert_fail ("NULL != ojr_genlist_head", "/usr/src/repo/source/library/capi.c", 57, __extension__ __PRETTY_FUNCTION__));
    ojr_call_close(g);
    p = &ojr_genlist_head;
    while (*p != g) p = &((*p)->next);
    *p = g->next;
    free(g->buf);
    free(g->state);
    free(g);
}

variable_types: struct _ojr_generator { int init; int leftover; int flags; int algorithm; int statesize; int bufsize; unsigned int *state; unsigned int *buf; unsigned int *bptr; struct _ojr_generator *next; void *extra; void *padding[4]; } **

return_type: void


decompiled_code:
__int64 __fastcall ojr_array_seed(__int64 a1)
{
if ( *(_DWORD *)a1 != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0x47u, "ojr_array_seed");
*(_QWORD *)(a1 + 40) = *(_QWORD *)(a1 + 32);
ojr_call_seed();
return ojr_set_seeded(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( *(_DWORD *)a1 != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0x47u, "ojr_array_seed");
*(_QWORD *)(a1 + 40) = *(_QWORD *)(a1 + 32);
ojr_call_seed();
return ojr_set_seeded(a1, 1LL);
}

original_code:
void ojr_array_seed(ojr_generator *g, uint32_t *seed, int size) {
    ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 71, __extension__ __PRETTY_FUNCTION__));
    g->bptr = g->buf;
    ojr_call_seed(g, seed, size);
    ojr_set_seeded(g, 1);
}

canonical_original_code:
void ojr_array_seed(struct _ojr_generator *g, unsigned int *seed, int size) {
    ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 71, __extension__ __PRETTY_FUNCTION__));
    g->bptr = g->buf;
    ojr_call_seed(g, seed, size);
    ojr_set_seeded(g, 1);
}

variable_types:
seed
unsigned int *

variable_types: size int

user_defined_types: struct _ojr_generator { int init; int leftover; int flags; int algorithm; int statesize; int bufsize; unsigned int *state; unsigned int *buf; unsigned int *bptr; struct _ojr_generator *next; void *extra; void *padding[4]; }


decompiled_code:
__int64 __fastcall ojr_int_seed(__int64 a1)
{
return ojr_array_seed(a1);
}

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

original_code:
void ojr_int_seed(ojr_generator *g, int value) {
    ojr_array_seed(g, (uint32_t *)(&value), 1);
}

canonical_original_code:
void ojr_int_seed(struct _ojr_generator *g, int value) {
    ojr_array_seed(g, (unsigned int *)(&value), 1);
}

variable_types: value int


decompiled_code:
void __fastcall ojr_system_seed(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
void *v3; // rax
void *v4; // rbx

v1 = ojr_get_algorithm();
v2 = ojr_algorithm_seedsize(v1);
v3 = malloc((int)(4 * v2));
if ( v3 )
{
v4 = v3;
ojr_get_system_entropy(v3, v2);
ojr_array_seed(a1);
free(v4);
}
}

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

v1 = ojr_get_algorithm();
v2 = ojr_algorithm_seedsize(v1);
v3 = malloc((int)(4 * v2));
if ( v3 )
{
v4 = v3;
ojr_get_system_entropy(v3, v2);
func2(a1);
free(v4);
}
}

original_code:
void ojr_system_seed(ojr_generator *g) {
    uint32_t *seed;
    int id = ojr_get_algorithm(g);
    int size = ojr_algorithm_seedsize(id);
    if (! (seed = malloc(4 * size))) return;
    ojr_get_system_entropy(seed, size);
    ojr_array_seed(g, seed, size);
    free(seed);
}

canonical_original_code:
void ojr_system_seed(struct _ojr_generator *g) {
    unsigned int *seed;
    int id = ojr_get_algorithm(g);
    int size = ojr_algorithm_seedsize(id);
    if (! (seed = malloc(4 * size))) return;
    ojr_get_system_entropy(seed, size);
    ojr_array_seed(g, seed, size);
    free(seed);
}

variable_types: id int


decompiled_code:
void __fastcall ojr_network_seed(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
void *v3; // rax
void *v4; // rbx

v1 = ojr_get_algorithm();
v2 = ojr_algorithm_seedsize(v1);
v3 = malloc((int)(4 * v2));
if ( v3 )
{
v4 = v3;
ojr_get_random_org(v3, v2);
ojr_array_seed(a1);
free(v4);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
void *v3; // rax
void *v4; // rbx

v1 = ojr_get_algorithm();
v2 = ojr_algorithm_seedsize(v1);
v3 = malloc((int)(4 * v2));
if ( v3 )
{
v4 = v3;
ojr_get_random_org(v3, v2);
func2(a1);
free(v4);
}
}

original_code:
void ojr_network_seed(ojr_generator *g) {
    uint32_t *seed;
    int id = ojr_get_algorithm(g);
    int size = ojr_algorithm_seedsize(id);
    if (! (seed = malloc(4 * size))) return;
    ojr_get_random_org(seed, size);
    ojr_array_seed(g, seed, size);
    free(seed);
}

canonical_original_code:
void ojr_network_seed(struct _ojr_generator *g) {
    unsigned int *seed;
    int id = ojr_get_algorithm(g);
    int size = ojr_algorithm_seedsize(id);
    if (! (seed = malloc(4 * size))) return;
    ojr_get_random_org(seed, size);
    ojr_array_seed(g, seed, size);
    free(seed);
}


decompiled_code:
__int64 __fastcall ojr_reseed(_DWORD *a1, __int64 a2, unsigned int a3)
{
if ( *a1 != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0x6Bu, "ojr_reseed");
if ( !(unsigned int)ojr_get_seeded() )
_assert_fail("ojr_get_seeded(g)", "/usr/src/repo/source/library/capi.c", 0x6Cu, "ojr_reseed");
return ojr_call_reseed(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, __int64 a2, unsigned int a3)
{
if ( *a1 != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0x6Bu, "ojr_reseed");
if ( !(unsigned int)ojr_get_seeded() )
_assert_fail("ojr_get_seeded(g)", "/usr/src/repo/source/library/capi.c", 0x6Cu, "ojr_reseed");
return ojr_call_reseed(a1, a2, a3);
}

original_code:
void ojr_reseed(ojr_generator *g, uint32_t *seed, int size) {
    ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 107, __extension__ __PRETTY_FUNCTION__));
    ((ojr_get_seeded(g)) ? (void) (0) : __assert_fail ("ojr_get_seeded(g)", "/usr/src/repo/source/library/capi.c", 108, __extension__ __PRETTY_FUNCTION__));
    ojr_call_reseed(g, seed, size);
}

canonical_original_code:
void ojr_reseed(struct _ojr_generator *g, unsigned int *seed, int size) {
    ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 107, __extension__ __PRETTY_FUNCTION__));
    ((ojr_get_seeded(g)) ? (void) (0) : __assert_fail ("ojr_get_seeded(g)", "/usr/src/repo/source/library/capi.c", 108, __extension__ __PRETTY_FUNCTION__));
    ojr_call_reseed(g, seed, size);
}


original_code:
uint32_t ojr_next32(ojr_generator *g) {
    ((0x5eed1e55 == g->init && (g->flags & 0x01)) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init && (g->flags & OJRF_SEEDED)", "/usr/src/repo/source/library/capi.c", 117, __extension__ __PRETTY_FUNCTION__));
    if (g->bptr == g->buf) {
        ojr_call_refill(g);
        g->bptr = g->buf + g->bufsize;
    }
    return *--g->bptr;
}

canonical_original_code:
unsigned int ojr_next32(struct _ojr_generator *g) {
    ((0x5eed1e55 == g->init && (g->flags & 0x01)) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init && (g->flags & OJRF_SEEDED)", "/usr/src/repo/source/library/capi.c", 117, __extension__ __PRETTY_FUNCTION__));
    if (g->bptr == g->buf) {
        ojr_call_refill(g);
        g->bptr = g->buf + g->bufsize;
    }
    return *--g->bptr;
}

return_type: unsigned int


original_code:
uint16_t ojr_next16(ojr_generator *g) {
    uint16_t r16;
    ((0x5eed1e55 == g->init && (g->flags & 0x01)) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init && (g->flags & OJRF_SEEDED)", "/usr/src/repo/source/library/capi.c", 128, __extension__ __PRETTY_FUNCTION__));
    if (g->leftover) {
        r16 = g->leftover & 0xFFFF;
        g->leftover = 0;
        return r16;
    }
    if (g->bptr == g->buf) {
        ojr_call_refill(g);
        g->bptr = g->buf + g->bufsize;
    }
    --g->bptr;
    g->leftover = 0x10000 | *((uint16_t *)(g->bptr) + 1);
    return *((uint16_t *)(g->bptr));
}

canonical_original_code:
unsigned short ojr_next16(struct _ojr_generator *g) {
    unsigned short r16;
    ((0x5eed1e55 == g->init && (g->flags & 0x01)) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init && (g->flags & OJRF_SEEDED)", "/usr/src/repo/source/library/capi.c", 128, __extension__ __PRETTY_FUNCTION__));
    if (g->leftover) {
        r16 = g->leftover & 0xFFFF;
        g->leftover = 0;
        return r16;
    }
    if (g->bptr == g->buf) {
        ojr_call_refill(g);
        g->bptr = g->buf + g->bufsize;
    }
    --g->bptr;
    g->leftover = 0x10000 | *((unsigned short *)(g->bptr) + 1);
    return *((unsigned short *)(g->bptr));
}

return_type: unsigned short


original_code:
uint64_t ojr_next64(ojr_generator *g) {
    uint64_t r;
    if ((g->bptr - g->buf) >= 2) {
        g->bptr -= 2;
        return *(uint64_t *)(g->bptr);
    }
    r = (uint64_t)(((((g)->bptr == (g)->buf) ? ( ojr_call_refill(g), (g)->bptr = (g)->buf + (g)->bufsize ) : 0), *--(g)->bptr));
    return (r << 32) | ((((g)->bptr == (g)->buf) ? ( ojr_call_refill(g), (g)->bptr = (g)->buf + (g)->bufsize ) : 0), *--(g)->bptr);
}

canonical_original_code:
unsigned long ojr_next64(struct _ojr_generator *g) {
    unsigned long r;
    if ((g->bptr - g->buf) >= 2) {
        g->bptr -= 2;
        return *(unsigned long *)(g->bptr);
    }
    r = (unsigned long)(((((g)->bptr == (g)->buf) ? ( ojr_call_refill(g), (g)->bptr = (g)->buf + (g)->bufsize ) : 0), *--(g)->bptr));
    return (r << 32) | ((((g)->bptr == (g)->buf) ? ( ojr_call_refill(g), (g)->bptr = (g)->buf + (g)->bufsize ) : 0), *--(g)->bptr);
}

variable_types:
r
unsigned long

return_type: unsigned long


decompiled_code:
double __fastcall ojr_next_double(__int64 a1)
{
__int64 v1; // rdx
__int64 v2; // xmm0_8
__int64 v4; // rbx

v1 = *(_QWORD *)(a1 + 40);
if ( v1 - *(_QWORD *)(a1 + 32) <= 4 )
{
v4 = (unsigned int)ojr_next32(a1);
v2 = ((unsigned int)ojr_next32(a1) | (unsigned __int64)(v4 << 32)) & 0xFFFFFFFFFFFFFLL | 0x3FF0000000000000LL;
}
else
{
*(_QWORD *)(a1 + 40) = v1 - 8;
v2 = *(_QWORD *)(v1 - 8) & 0xFFFFFFFFFFFFFLL | 0x3FF0000000000000LL;
}
return *(double *)&v2 - 1.0;
}

original_code:
double ojr_next_double(ojr_generator *g) {
    uint64_t r = (((((g)->bptr - (g)->buf) >= 2) ? ((g)->bptr -= 2, *(uint64_t *)((g)->bptr)) : (((uint64_t)(ojr_next32(g)) << 32) | ojr_next32(g))) & 0xFFFFFFFFFFFFFull) | 0x3FF0000000000000ull;
    return *(double *)(&r) - 1.0;
}

canonical_original_code:
double ojr_next_double(struct _ojr_generator *g) {
    unsigned long r = (((((g)->bptr - (g)->buf) >= 2) ? ((g)->bptr -= 2, *(uint64_t *)((g)->bptr)) : (((uint64_t)(ojr_next32(g)) << 32) | ojr_next32(g))) & 0xFFFFFFFFFFFFFull) | 0x3FF0000000000000ull;
    return *(double *)(&r) - 1.0;
}

return_type: double


decompiled_code:
double __fastcall ojr_next_signed_double(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
int v3; // eax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rdx
double result; // xmm0_8

do
{
v4 = *(_QWORD *)(a1 + 40);
if ( v4 - *(_QWORD *)(a1 + 32) > 4 )
{
*(_QWORD *)(a1 + 40) = v4 - 8;
v1 = *(_QWORD *)(v4 - 8);
}
else
{
v5 = (unsigned int)ojr_next32(a1);
v1 = (unsigned int)ojr_next32(a1) | (unsigned __int64)(v5 << 32);
}
v2 = v1 >> 12;
v3 = v1 & 1;
}
while ( v3 && !v2 );
v6 = v2 | 0x3FF0000000000000LL;
if ( v3 )
result = 1.0 - *(double *)&v6;
else
result = *(double *)&v6 - 1.0;
return result;
}

canonical_decompiled_code:
double __fastcall func12(__int64 a1)
{
unsigned __int64 v1; // rax
unsigned __int64 v2; // rdx
int v3; // eax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rdx
double result; // xmm0_8

do
{
v4 = *(_QWORD *)(a1 + 40);
if ( v4 - *(_QWORD *)(a1 + 32) > 4 )
{
*(_QWORD *)(a1 + 40) = v4 - 8;
v1 = *(_QWORD *)(v4 - 8);
}
else
{
v5 = (unsigned int)func8(a1);
v1 = (unsigned int)func8(a1) | (unsigned __int64)(v5 << 32);
}
v2 = v1 >> 12;
v3 = v1 & 1;
}
while ( v3 && !v2 );
v6 = v2 | 0x3FF0000000000000LL;
if ( v3 )
result = 1.0 - *(double *)&v6;
else
result = *(double *)&v6 - 1.0;
return result;
}

canonical_original_code:
double ojr_next_signed_double(struct _ojr_generator *g) {
    int sign;
    unsigned long r64;
    do {
        r64 = ((((g)->bptr - (g)->buf) >= 2) ? ((g)->bptr -= 2, *(unsigned long *)((g)->bptr)) : (((unsigned long)(ojr_next32(g)) << 32) | ojr_next32(g)));
        sign = (int)r64 & 1;
        r64 >>= 12;
    } while (sign && 0LL == r64);
    r64 |= 0x3FF0000000000000;
    if (sign) return 1.0 - *(double *)(&r64);
    else return *(double *)(&r64) - 1.0;
}

variable_types: sign int


original_code:
int ojr_rand(ojr_generator *g, int limit) {
    int v, m = limit - 1;
    ((limit > 0 && limit <= 0x80000) ? (void) (0) : __assert_fail ("limit > 0 && limit <= 0x80000", "/usr/src/repo/source/library/capi.c", 185, __extension__ __PRETTY_FUNCTION__));
    m |= m >> 1;
    m |= m >> 2;
    m |= m >> 4;
    m |= m >> 8;
    do {
        if (g->leftover) {
            v = g->leftover & m;
            g->leftover = 0;
        } else {
            if (g->bptr == g->buf) {
                ojr_call_refill(g);
                g->bptr = g->buf + g->bufsize;
            }
            --g->bptr;
            v = *((uint16_t *)(g->bptr)) & m;
            g->leftover = 0x10000 | *((uint16_t *)(g->bptr) + 1);
        }
    } while (v >= limit);
    return v;
}

canonical_original_code:
int ojr_rand(struct _ojr_generator *g, int limit) {
    int v; int m = limit - 1;
    ((limit > 0 && limit <= 0x80000) ? (void) (0) : __assert_fail ("limit > 0 && limit <= 0x80000", "/usr/src/repo/source/library/capi.c", 185, __extension__ __PRETTY_FUNCTION__));
    m |= m >> 1;
    m |= m >> 2;
    m |= m >> 4;
    m |= m >> 8;
    do {
        if (g->leftover) {
            v = g->leftover & m;
            g->leftover = 0;
        } else {
            if (g->bptr == g->buf) {
                ojr_call_refill(g);
                g->bptr = g->buf + g->bufsize;
            }
            --g->bptr;
            v = *((unsigned short *)(g->bptr)) & m;
            g->leftover = 0x10000 | *((unsigned short *)(g->bptr) + 1);
        }
    } while (v >= limit);
    return v;
}

variable_types: limit int

variable_types: v int

variable_types: m int


decompiled_code:
__int64 __fastcall ojr_discard(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 result; // rax
int v5; // ebx

v2 = *(_QWORD *)(a1 + 40);
v3 = *(_QWORD *)(a1 + 32);
result = (v2 - v3) >> 2;
if ( *(_DWORD *)a1 != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0xD8u, "ojr_discard");
*(_DWORD *)(a1 + 4) = 0;
if ( (int)result >= a2 )
{
*(_QWORD *)(a1 + 40) = v2 - 4LL * a2;
}
else
{
v5 = a2 - result;
*(_QWORD *)(a1 + 40) = v3 + 4LL * *(int *)(a1 + 20);
while ( 1 )
{
ojr_call_refill(a1);
result = *(unsigned int *)(a1 + 20);
if ( (int)result >= v5 )
break;
v5 -= result;
}
*(_QWORD *)(a1 + 40) -= 4LL * v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 result; // rax
int v5; // ebx

v2 = *(_QWORD *)(a1 + 40);
v3 = *(_QWORD *)(a1 + 32);
result = (v2 - v3) >> 2;
if ( *(_DWORD *)a1 != 1592598101 )
_assert_fail("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 0xD8u, "ojr_discard");
*(_DWORD *)(a1 + 4) = 0;
if ( (int)result >= a2 )
{
*(_QWORD *)(a1 + 40) = v2 - 4LL * a2;
}
else
{
v5 = a2 - result;
*(_QWORD *)(a1 + 40) = v3 + 4LL * *(int *)(a1 + 20);
while ( 1 )
{
ojr_call_refill(a1);
result = *(unsigned int *)(a1 + 20);
if ( (int)result >= v5 )
break;
v5 -= result;
}
*(_QWORD *)(a1 + 40) -= 4LL * v5;
}
return result;
}

original_code:
void ojr_discard(ojr_generator *g, int count) {
    int inbuf = g->bptr - g->buf;
    if (((void *)0) == g) g = &ojr_default_generator;
    else { ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 216, __extension__ __PRETTY_FUNCTION__)); }
    g->leftover = 0;
    if (count <= inbuf) {
        g->bptr -= count;
        return;
    }
    count -= inbuf;
    g->bptr = g->buf + g->bufsize;
    do {
        ojr_call_refill(g);
        if (count <= g->bufsize) {
            g->bptr -= count;
            count = 0;
        } else {
            count -= g->bufsize;
        }
    } while (count);
}

canonical_original_code:
void ojr_discard(struct _ojr_generator *g, int count) {
    int inbuf = g->bptr - g->buf;
    if (((void *)0) == g) g = &ojr_default_generator;
    else { ((0x5eed1e55 == g->init) ? (void) (0) : __assert_fail ("0x5eed1e55 == g->init", "/usr/src/repo/source/library/capi.c", 216, __extension__ __PRETTY_FUNCTION__)); }
    g->leftover = 0;
    if (count <= inbuf) {
        g->bptr -= count;
        return;
    }
    count -= inbuf;
    g->bptr = g->buf + g->bufsize;
    do {
        ojr_call_refill(g);
        if (count <= g->bufsize) {
            g->bptr -= count;
            count = 0;
        } else {
            count -= g->bufsize;
        }
    } while (count);
}

variable_types: count int

variable_types: inbuf int


decompiled_code:
char *__fastcall ojr_array_with_sum(__int64 a1, char *a2, int a3, int a4)
{
int v4; // er15
char *v5; // rbx
int v6; // er12
char *result; // rax
char *v8; // rcx
__int64 v11; // [rsp+8h] [rbp-40h]

v4 = a3 - 1;
if ( a3 - 1 <= 0 )
{
qsort(a2, v4, 4uLL, (__compar_fn_t)compare);
result = (char *)a3;
*(_DWORD *)&a2[4 * a3 - 4] = a4;
}
else
{
v11 = 4LL * (unsigned int)(a3 - 2);
v5 = a2;
v6 = a4 + 1;
do
{
*(_DWORD *)v5 = ojr_rand(a1, v6);
v5 += 4;
}
while ( v5 != &a2[v11 + 4] );
qsort(a2, v4, 4uLL, (__compar_fn_t)compare);
*(_DWORD *)&a2[4 * a3 - 4] = a4;
result = &a2[4 * v4];
v8 = &result[-v11 - 4];
do
{
*(_DWORD *)result -= *((_DWORD *)result - 1);
result -= 4;
}
while ( result != v8 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func15(__int64 a1, char *a2, int a3, int a4)
{
int v4; // er15
char *v5; // rbx
int v6; // er12
char *result; // rax
char *v8; // rcx
__int64 v11; // [rsp+8h] [rbp-40h]

v4 = a3 - 1;
if ( a3 - 1 <= 0 )
{
qsort(a2, v4, 4uLL, (__compar_fn_t)compare);
result = (char *)a3;
*(_DWORD *)&a2[4 * a3 - 4] = a4;
}
else
{
v11 = 4LL * (unsigned int)(a3 - 2);
v5 = a2;
v6 = a4 + 1;
do
{
*(_DWORD *)v5 = func13(a1, v6);
v5 += 4;
}
while ( v5 != &a2[v11 + 4] );
qsort(a2, v4, 4uLL, (__compar_fn_t)compare);
*(_DWORD *)&a2[4 * a3 - 4] = a4;
result = &a2[4 * v4];
v8 = &result[-v11 - 4];
do
{
*(_DWORD *)result -= *((_DWORD *)result - 1);
result -= 4;
}
while ( result != v8 );
}
return result;
}

original_code:
void ojr_array_with_sum(ojr_generator *g, int *a, int count, int sum) {
    int i;
    for (i = 0; i < count-1; ++i) { a[i] = ojr_rand(g, sum+1); }
    qsort(a, count-1, sizeof(int), compare);
    a[count-1] = sum;
    for (i = count-1; i > 0; --i) { a[i] -= a[i-1]; }
}

canonical_original_code:
void ojr_array_with_sum(struct _ojr_generator *g, int *a, int count, int sum) {
    int i;
    for (i = 0; i < count-1; ++i) { a[i] = ojr_rand(g, sum+1); }
    qsort(a, count-1, sizeof(int), compare);
    a[count-1] = sum;
    for (i = count-1; i > 0; --i) { a[i] -= a[i-1]; }
}

variable_types:
a
int *

variable_types: sum int

variable_types: i int


refill

variable_types: r int

variable_types: c int

variable_types:
buf
char [4096]

variable_types:
a
unsigned int [32]

variable_types: j int


decompiled_code:
__int64 __fastcall ojr_get_random_org(_DWORD *a1, int a2)
{
unsigned int v3; // ebp

if ( a2 > 0 )
{
v3 = 0;
while ( 1 )
{
if ( bptr == &buffer )
{
if ( (unsigned int)refill() != 400 )
return v3;
bptr = (char *)&buffer + 1600;
}
bptr = (char *)bptr - 4;
*a1 = *(_DWORD *)bptr;
++v3;
++a1;
if ( a2 == v3 )
return v3;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, int a2)
{
unsigned int v3; // ebp

if ( a2 > 0 )
{
v3 = 0;
while ( 1 )
{
if ( bptr == &buffer )
{
if ( (unsigned int)func2() != 400 )
return v3;
bptr = (char *)&buffer + 1600;
}
bptr = (char *)bptr - 4;
*a1 = *(_DWORD *)bptr;
++v3;
++a1;
if ( a2 == v3 )
return v3;
}
}
return 0;
}

original_code:
int ojr_get_random_org(uint32_t *buf, int size) {
    int c = 0;
    for (int i = 0; i < size; ++i) {
        if (bptr == buffer) {
            if (400 != refill()) return c;
            bptr = buffer + 400;
        }
        buf[i] = *--bptr;
        ++c;
    }
    return c;
}

canonical_original_code:
int ojr_get_random_org(unsigned int *buf, int size) {
    int c = 0;
    for (int i = 0; i < size; ++i) {
        if (bptr == buffer) {
            if (400 != refill()) return c;
            bptr = buffer + 400;
        }
        buf[i] = *--bptr;
        ++c;
    }
    return c;
}

variable_types:
buf
unsigned int *

variable_types: size int


decompiled_code:
__int64 ojr_algorithm_count()
{
void **v0; // rax
int v1; // edx
int v2; // ecx

if ( !ojr_algorithm_count )
{
v0 = &ojr_algorithms;
if ( ojr_algorithms )
{
v1 = 1;
do
{
++v0;
v2 = v1++;
}
while ( *v0 );
ojr_algorithm_count = v2;
}
}
return (unsigned int)ojr_algorithm_count;
}

canonical_decompiled_code:
__int64 func0()
{
void **v0; // rax
int v1; // edx
int v2; // ecx

if ( !ojr_algorithm_count )
{
v0 = &ojr_algorithms;
if ( ojr_algorithms )
{
v1 = 1;
do
{
++v0;
v2 = v1++;
}
while ( *v0 );
ojr_algorithm_count = v2;
}
}
return (unsigned int)ojr_algorithm_count;
}

original_code:
int ojr_algorithm_count(void) {
    if (0 == _ojr_algorithm_count) {
        ojr_algorithm **aap = ojr_algorithms;
        while (((void *)0) != *aap) { ++aap; ++_ojr_algorithm_count; }
    }
    return _ojr_algorithm_count;
}

canonical_original_code:
int ojr_algorithm_count() {
    if (0 == _ojr_algorithm_count) {
        struct _ojr_algorithm **aap = ojr_algorithms;
        while (((void *)0) != *aap) { ++aap; ++_ojr_algorithm_count; }
    }
    return _ojr_algorithm_count;
}

variable_types: struct _ojr_algorithm { char *name; int seedsize; int statesize; int bufsize; void (*open)(struct _ojr_generator { int init; int leftover; int flags; int algorithm; int statesize; int bufsize; unsigned int *state; unsigned int *buf; unsigned int *bptr; struct _ojr_generator *next; void *extra; void *padding[4]; } *); void (*close)(struct _ojr_generator *); void (*seed)(struct _ojr_generator *, unsigned int *, int); void (*reseed)(struct _ojr_generator *, unsigned int *, int); void (*refill)(struct _ojr_generator *); void *extra; void *padding[4]; } **

user_defined_types: struct _ojr_algorithm { char *name; int seedsize; int statesize; int bufsize; void (*open)(struct _ojr_generator *); void (*close)(struct _ojr_generator *); void (*seed)(struct _ojr_generator *, unsigned int *, int); void (*reseed)(struct _ojr_generator *, unsigned int *, int); void (*refill)(struct _ojr_generator *); void *extra; void *padding[4]; }


decompiled_code:
__int64 __fastcall ojr_algorithm_name(int a1)
{
__int64 result; // rax
int v2; // ebx

result = 0LL;
if ( a1 >= 0 )
{
v2 = a1;
if ( (int)ojr_algorithm_count() < a1 )
{
result = 0LL;
}
else
{
if ( !a1 )
v2 = 1;
result = *(_QWORD *)*(&ojr_algorithms + v2 - 1);
}
}
return result;
}

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

result = 0LL;
if ( a1 >= 0 )
{
v2 = a1;
if ( (int)func0() < a1 )
{
result = 0LL;
}
else
{
if ( !a1 )
v2 = 1;
result = *(_QWORD *)*(&ojr_algorithms + v2 - 1);
}
}
return result;
}

original_code:
char *ojr_algorithm_name(int id) {
    if (id < 0 || id > ojr_algorithm_count()) return ((void *)0);
    if (0 == id) id = 1;
    return (ojr_algorithms[id - 1])->name;
}

variable_types: id int

return_type: char *


decompiled_code:
__int64 __fastcall ojr_algorithm_id(char *s1)
{
int v1; // eax
int v2; // er12
__int64 v3; // rbx

v1 = ojr_algorithm_count();
if ( !s1 )
return 0LL;
v2 = v1;
if ( v1 <= 0 )
return 0LL;
v3 = 0LL;
while ( strcmp(s1, *(const char **)*(&ojr_algorithms + v3)) )
{
if ( v2 <= (int)++v3 )
return 0LL;
}
return (unsigned int)(v3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
int v1; // eax
int v2; // er12
__int64 v3; // rbx

v1 = func0();
if ( !s1 )
return 0LL;
v2 = v1;
if ( v1 <= 0 )
return 0LL;
v3 = 0LL;
while ( strcmp(s1, *(const char **)*(&ojr_algorithms + v3)) )
{
if ( v2 <= (int)++v3 )
return 0LL;
}
return (unsigned int)(v3 + 1);
}

original_code:
int ojr_algorithm_id(const char *name) {
    int i, c = ojr_algorithm_count();
    if (((void *)0) == name) return 0;
    for (i = 0; i < c; ++i) {
        if (0 == strcmp(name, (ojr_algorithms[i])->name)) {
            return i + 1;
        }
    }
    return 0;
}

canonical_original_code:
int ojr_algorithm_id(char *name) {
    int i; int c = ojr_algorithm_count();
    if (((void *)0) == name) return 0;
    for (i = 0; i < c; ++i) {
        if (0 == strcmp(name, (ojr_algorithms[i])->name)) {
            return i + 1;
        }
    }
    return 0;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall ojr_algorithm_seedsize(int a1)
{
int v1; // ebx

if ( a1 < 0 || (v1 = a1, (int)ojr_algorithm_count() < a1) )
_assert_fail(
"id >= 0 && id <= ojr_algorithm_count()",
"/usr/src/repo/source/library/algorithms.c",
0x3Eu,
"ojr_algorithm_seedsize");
if ( !a1 )
v1 = 1;
return *((unsigned int *)*(&ojr_algorithms + v1 - 1) + 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebx

if ( a1 < 0 || (v1 = a1, (int)func0() < a1) )
_assert_fail(
"id >= 0 && id <= ojr_algorithm_count()",
"/usr/src/repo/source/library/algorithms.c",
0x3Eu,
"ojr_algorithm_seedsize");
if ( !a1 )
v1 = 1;
return *((unsigned int *)*(&ojr_algorithms + v1 - 1) + 2);
}

original_code:
int ojr_algorithm_seedsize(int id) {
    ((id >= 0 && id <= ojr_algorithm_count()) ? (void) (0) : __assert_fail ("id >= 0 && id <= ojr_algorithm_count()", "/usr/src/repo/source/library/algorithms.c", 62, __extension__ __PRETTY_FUNCTION__));
    if (0 == id) id = 1;
    return (ojr_algorithms[id - 1])->seedsize;
}


decompiled_code:
__int64 __fastcall ojr_algorithm_statesize(int a1)
{
int v1; // ebx

if ( a1 < 0 || (v1 = a1, (int)ojr_algorithm_count() < a1) )
_assert_fail(
"id >= 0 && id <= ojr_algorithm_count()",
"/usr/src/repo/source/library/algorithms.c",
0x44u,
"ojr_algorithm_statesize");
if ( !a1 )
v1 = 1;
return *((unsigned int *)*(&ojr_algorithms + v1 - 1) + 3);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // ebx

if ( a1 < 0 || (v1 = a1, (int)func0() < a1) )
_assert_fail(
"id >= 0 && id <= ojr_algorithm_count()",
"/usr/src/repo/source/library/algorithms.c",
0x44u,
"ojr_algorithm_statesize");
if ( !a1 )
v1 = 1;
return *((unsigned int *)*(&ojr_algorithms + v1 - 1) + 3);
}

original_code:
int ojr_algorithm_statesize(int id) {
    ((id >= 0 && id <= ojr_algorithm_count()) ? (void) (0) : __assert_fail ("id >= 0 && id <= ojr_algorithm_count()", "/usr/src/repo/source/library/algorithms.c", 68, __extension__ __PRETTY_FUNCTION__));
    if (0 == id) id = 1;
    return (ojr_algorithms[id - 1])->statesize;
}


decompiled_code:
__int64 __fastcall ojr_algorithm_bufsize(int a1)
{
int v1; // ebx

if ( a1 < 0 || (v1 = a1, (int)ojr_algorithm_count() < a1) )
_assert_fail(
"id >= 0 && id <= ojr_algorithm_count()",
"/usr/src/repo/source/library/algorithms.c",
0x4Au,
"ojr_algorithm_bufsize");
if ( !a1 )
v1 = 1;
return *((unsigned int *)*(&ojr_algorithms + v1 - 1) + 4);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebx

if ( a1 < 0 || (v1 = a1, (int)func0() < a1) )
_assert_fail(
"id >= 0 && id <= ojr_algorithm_count()",
"/usr/src/repo/source/library/algorithms.c",
0x4Au,
"ojr_algorithm_bufsize");
if ( !a1 )
v1 = 1;
return *((unsigned int *)*(&ojr_algorithms + v1 - 1) + 4);
}

original_code:
int ojr_algorithm_bufsize(int id) {
    ((id >= 0 && id <= ojr_algorithm_count()) ? (void) (0) : __assert_fail ("id >= 0 && id <= ojr_algorithm_count()", "/usr/src/repo/source/library/algorithms.c", 74, __extension__ __PRETTY_FUNCTION__));
    if (0 == id) id = 1;
    return (ojr_algorithms[id - 1])->bufsize;
}


decompiled_code:
int __fastcall ojr_get_system_entropy(void *buf, int a2)
{
int v2; // eax
int v3; // ebx
int v4; // ebp

v2 = open("/dev/urandom", 0);
if ( v2 == -1 )
{
fwrite("ojrandlib: Can't open /dev/urandom.\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v3 = v2;
v4 = 4 * a2;
if ( v4 != read(v2, buf, v4) )
{
fprintf(stderr, "ojrandlib: Failed to read %d bytes from /dev/urandom.\n", (unsigned int)v4);
exit(1);
}
return close(v3);
}

canonical_decompiled_code:
int __fastcall func0(void *buf, int a2)
{
int v2; // eax
int v3; // ebx
int v4; // ebp

v2 = open("/dev/urandom", 0);
if ( v2 == -1 )
{
fwrite("ojrandlib: Can't open /dev/urandom.\n", 1uLL, 0x24uLL, stderr);
exit(1);
}
v3 = v2;
v4 = 4 * a2;
if ( v4 != read(v2, buf, v4) )
{
fprintf(stderr, "ojrandlib: Failed to read %d bytes from /dev/urandom.\n", (unsigned int)v4);
exit(1);
}
return close(v3);
}

original_code:
extern void ojr_get_system_entropy(uint32_t *dest, int dsize) {
    int fn;
    fn = open("/dev/urandom", 00);
    if (-1 == fn) {
        fprintf(stderr, "ojrandlib: Can't open /dev/urandom.\n");
        exit(1);
    }
    if (4 * dsize != read(fn, (char *)dest, 4 * dsize)) {
        fprintf(stderr,
            "ojrandlib: Failed to read %d bytes from /dev/urandom.\n",
            4 * dsize);
        exit(1);
    }
    close(fn);
    return;
}

canonical_original_code:
extern void ojr_get_system_entropy(unsigned int *dest, int dsize) {
    int fn;
    fn = open("/dev/urandom", 00);
    if (-1 == fn) {
        fprintf(stderr, "ojrandlib: Can't open /dev/urandom.\n");
        exit(1);
    }
    if (4 * dsize != read(fn, (char *)dest, 4 * dsize)) {
        fprintf(stderr,
            "ojrandlib: Failed to read %d bytes from /dev/urandom.\n",
            4 * dsize);
        exit(1);
    }
    close(fn);
    return;
}

variable_types:
dest
unsigned int *

variable_types: dsize int

variable_types: fn int


decompiled_code:
double __fastcall ojr_next_exponential(__int64 a1)
{
__int64 v1; // rbx
unsigned __int64 v2; // rdx
int v3; // ebx
unsigned __int64 v4; // rax
double v5; // xmm1_8
__int64 v6; // rax
double v8; // xmm0_8
double v9; // [rsp+8h] [rbp-50h]
double v10; // [rsp+10h] [rbp-48h]
double v11; // [rsp+18h] [rbp-40h]

while ( 1 )
{
v6 = *(_QWORD *)(a1 + 40);
if ( v6 - *(_QWORD *)(a1 + 32) <= 4 )
{
v1 = (unsigned int)ojr_next32(a1);
v2 = (v1 << 32) | (unsigned int)ojr_next32(a1);
}
else
{
*(_QWORD *)(a1 + 40) = v6 - 8;
v2 = *(_QWORD *)(v6 - 8);
}
v3 = (unsigned __int8)v2;
v4 = (v2 >> 8) & 0xFFFFFFFFFFFFFLL;
if ( v4 < zeri[(unsigned __int8)v2] )
return (COERCE_DOUBLE(v4 | 0x3FF0000000000000LL) - 1.0) * zex[(unsigned __int8)v2];
if ( !(_BYTE)v2 )
break;
v5 = zex[(unsigned __int8)v2];
v9 = (COERCE_DOUBLE(v4 | 0x3FF0000000000000LL) - 1.0) * v5;
v10 = exp(v9 - v5);
v11 = exp(v9 - zex[v3 + 1]);
if ( (v10 - v11) * ojr_next_double(a1) + v11 < 1.0 )
return v9;
}
v8 = ojr_next_double(a1);
return 7.69711747013105 - log(v8);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
unsigned __int64 v2; // rdx
int v3; // ebx
unsigned __int64 v4; // rax
double v5; // xmm1_8
__int64 v6; // rax
double v8; // xmm0_8
double v9; // [rsp+8h] [rbp-50h]
double v10; // [rsp+10h] [rbp-48h]
double v11; // [rsp+18h] [rbp-40h]

while ( 1 )
{
v6 = *(_QWORD *)(a1 + 40);
if ( v6 - *(_QWORD *)(a1 + 32) <= 4 )
{
v1 = (unsigned int)ojr_next32(a1);
v2 = (v1 << 32) | (unsigned int)ojr_next32(a1);
}
else
{
*(_QWORD *)(a1 + 40) = v6 - 8;
v2 = *(_QWORD *)(v6 - 8);
}
v3 = (unsigned __int8)v2;
v4 = (v2 >> 8) & 0xFFFFFFFFFFFFFLL;
if ( v4 < zeri[(unsigned __int8)v2] )
return (COERCE_DOUBLE(v4 | 0x3FF0000000000000LL) - 1.0) * zex[(unsigned __int8)v2];
if ( !(_BYTE)v2 )
break;
v5 = zex[(unsigned __int8)v2];
v9 = (COERCE_DOUBLE(v4 | 0x3FF0000000000000LL) - 1.0) * v5;
v10 = exp(v9 - v5);
v11 = exp(v9 - zex[v3 + 1]);
if ( (v10 - v11) * ojr_next_double(a1) + v11 < 1.0 )
return v9;
}
v8 = ojr_next_double(a1);
return 7.69711747013105 - log(v8);
}

canonical_original_code:
double ojr_next_exponential(struct _ojr_generator *g) {
    unsigned long r;
    int i;
    double x; double u0; double f0; double f1;
    while (1) {
        r = ((((g)->bptr - (g)->buf) >= 2) ? ((g)->bptr -= 2, *(unsigned long *)((g)->bptr)) : (((unsigned long)(ojr_next32(g)) << 32) | ojr_next32(g)));
        i = r & 0xFF;
        r = (r >> 8) & 0xFFFFFFFFFFFFFULL;
        if (r < zeri[i]) {
            r |= 0x3FF0000000000000ULL;
            u0 = *(double *)(&r) - 1.0;
            return u0 * zex[i];
        }
        if (0 == i) return 7.6971174701310497140 - log(ojr_next_double(g));
        r |= 0x3FF0000000000000ULL;
        u0 = *(double *)(&r) - 1.0;
        x = u0 * zex[i];
        f0 = exp(x - zex[i]);
        f1 = exp(x - zex[i+1]);
        if (f1 + ojr_next_double(g) * (f0 - f1) < 1.0) return x;
    }
}

variable_types: struct _ojr_generator { int init; int leftover; int flags; int algorithm; int statesize; int bufsize; unsigned int *state; unsigned int *buf; unsigned int *bptr; struct _ojr_generator *next; void *extra; void *padding[4]; } *

variable_types:
r
unsigned long

variable_types: x double


canonical_original_code:
double ojr_next_normal(struct _ojr_generator *g) {
    unsigned long r;
    int i; int sign;
    double x; double y; double a; double u0; double f0; double f1;
    while (1) {
        do {
            r = ((((g)->bptr - (g)->buf) >= 2) ? ((g)->bptr -= 2, *(unsigned long *)((g)->bptr)) : (((unsigned long)(ojr_next32(g)) << 32) | ojr_next32(g)));
            sign = (int)r & 1;
            i = (r >> 1) & 0x7F;
            r >>= 12;
        } while (sign && 0LL == r);
        if (r < znri[i]) {
            r |= 0x3FF0000000000000ULL;
            a = *(double *)(&r) - 1.0;
            return znx[i] * (sign ? -a : a);
        }
        if (0 == i) {
            do {
                x = log(ojr_next_double(g)) / 3.4426198558966521214;
                y = log(ojr_next_double(g));
            } while (-2.0 * y < x * x);
            return sign ? x - 3.4426198558966521214 : 3.4426198558966521214 - x;
        }
        r |= 0x3FF0000000000000ULL;
        a = *(double *)(&r) - 1.0;
        x = znx[i] * (sign ? -a : a);
        f0 = exp(-0.5 * (znx[i] * znx[i] - x * x));
        f1 = exp(-0.5 * (znx[i+1] * znx[i+1] - x * x));
        if (f1 + ojr_next_double(g) * (f0 - f1) < 1.0) return x;
    }
}

variable_types: i int

variable_types: sign int

variable_types: y double

variable_types: a double


repo: ldipenti/GNOME-War-Pad

decompiled_code:
__int64 gtk_sdl_get_type()
{
__int64 v1; // rax

if ( !sdl_type_6 )
{
v1 = gtk_widget_get_type();
sdl_type_6 = gtk_type_unique(v1, &sdl_info_5);
}
return sdl_type_6;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v1; // rax

if ( !sdl_type_6 )
{
v1 = gtk_widget_get_type();
sdl_type_6 = gtk_type_unique(v1, &sdl_info_5);
}
return sdl_type_6;
}

original_code:
GtkType gtk_sdl_get_type (void)
{
  static GtkType sdl_type = 0;
 if (!sdl_type)
 {
  static const GtkTypeInfo sdl_info =
  {
   "GtkSDL",
   sizeof (GtkSDL),
   sizeof (GtkSDLClass),
   (GtkClassInitFunc) gtk_sdl_class_init,
   (GtkObjectInitFunc) gtk_sdl_init,
                    ((void *)0),
                    ((void *)0),
   (GtkClassInitFunc) ((void *)0),
  };
  sdl_type = gtk_type_unique ((gtk_widget_get_type ()), &sdl_info);
 }
 return sdl_type;
}

canonical_original_code:
unsigned long gtk_sdl_get_type()
{
  static unsigned long sdl_type = 0;
 if (!sdl_type)
 {
  static struct _GtkTypeInfo sdl_info = {
   "GtkSDL",
   sizeof (GtkSDL),
   sizeof (GtkSDLClass),
   (GtkClassInitFunc) gtk_sdl_class_init,
   (GtkObjectInitFunc) gtk_sdl_init,
                    ((void *)0),
                    ((void *)0),
   (GtkClassInitFunc) ((void *)0),
  };
  sdl_type = gtk_type_unique ((gtk_widget_get_type ()), &sdl_info);
 }
 return sdl_type;
}

variable_types: struct _GtkTypeInfo { char *type_name; unsigned int object_size; unsigned int class_size; void (*class_init_func)(void *g_class); void (*object_init_func)(struct _GTypeInstance { struct _GTypeClass { unsigned long g_type; } *g_class; } *instance, void *g_class); void *reserved_1; void *reserved_2; void (*base_class_init_func)(void *g_class); }

user_defined_types: struct _GtkTypeInfo { char *type_name; unsigned int object_size; unsigned int class_size; void (*class_init_func)(void *g_class); void (*object_init_func)(struct _GTypeInstance *instance, void *g_class); void *reserved_1; void *reserved_2; void (*base_class_init_func)(void *g_class); }

user_defined_types: struct _GTypeInstance { struct _GTypeClass *g_class; }


distance

decompiled_code:
float __fastcall distance(float a1, float a2, float a3, float a4)
{
float v4; // xmm0_4
float result; // xmm0_4

v4 = (float)((float)(a1 - a2) * (float)(a1 - a2)) + (float)((float)(a3 - a4) * (float)(a3 - a4));
if ( v4 < 0.0 )
result = sqrtf(v4);
else
result = fsqrt(v4);
return result;
}

canonical_decompiled_code:
float __fastcall func7(float a1, float a2, float a3, float a4)
{
float v4; // xmm0_4
float result; // xmm0_4

v4 = (float)((float)(a1 - a2) * (float)(a1 - a2)) + (float)((float)(a3 - a4) * (float)(a3 - a4));
if ( v4 < 0.0 )
result = sqrtf(v4);
else
result = fsqrt(v4);
return result;
}

original_code:
float distance (float x1, float x2, float y1, float y2)
{
 x1 = x1-x2;
 x1 = x1*x1;
 y1 = y1-y2;
 y1 = y1*y1;
 float result = sqrt(x1+y1);
 return result;
}

canonical_original_code:
float distance(float x1, float x2, float y1, float y2)
{
 x1 = x1-x2;
 x1 = x1*x1;
 y1 = y1-y2;
 y1 = y1*y1;
 float result = sqrt(x1+y1);
 return result;
}

variable_types: result float

return_type: float


decompiled_code:
__int64 __fastcall initialize_particle(__int64 a1, int a2)
{
__m128i v2; // xmm0
int v3; // ebp
int v4; // eax
char v5; // dl
__int64 result; // rax

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)((float)(2 * rand()) * 4.6566129e-10) * *(float *)&grid_size;
v3 = _mm_cvtsi128_si32(v2);
v4 = rand();
v5 = v4;
result = (unsigned int)(v4 % 4);
if ( (_DWORD)result == 2 )
{
result = dimensions * a2;
*(_DWORD *)(a1 + 4 * result) = v3;
*(float *)(a1 + 4LL * dimensions * a2 + 4) = -*(float *)&grid_size;
}
else if ( (int)result > 2 )
{
result = dimensions * a2;
*(_DWORD *)(a1 + 4 * result) = v3;
*(_DWORD *)(a1 + 4LL * dimensions * a2 + 4) = grid_size;
}
else if ( (v5 & 3) != 0 )
{
if ( (_DWORD)result == 1 )
{
result = dimensions * a2;
*(_DWORD *)(a1 + 4 * result) = grid_size;
*(_DWORD *)(a1 + 4LL * dimensions * a2 + 4) = v3;
}
}
else
{
result = dimensions * a2;
*(float *)(a1 + 4 * result) = -*(float *)&grid_size;
*(_DWORD *)(a1 + 4LL * dimensions * a2 + 4) = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__m128i v2; // xmm0
int v3; // ebp
int v4; // eax
char v5; // dl
__int64 result; // rax

v2 = 0LL;
*(float *)v2.m128i_i32 = (float)((float)(2 * rand()) * 4.6566129e-10) * *(float *)&grid_size;
v3 = _mm_cvtsi128_si32(v2);
v4 = rand();
v5 = v4;
result = (unsigned int)(v4 % 4);
if ( (_DWORD)result == 2 )
{
result = dimensions * a2;
*(_DWORD *)(a1 + 4 * result) = v3;
*(float *)(a1 + 4LL * dimensions * a2 + 4) = -*(float *)&grid_size;
}
else if ( (int)result > 2 )
{
result = dimensions * a2;
*(_DWORD *)(a1 + 4 * result) = v3;
*(_DWORD *)(a1 + 4LL * dimensions * a2 + 4) = grid_size;
}
else if ( (v5 & 3) != 0 )
{
if ( (_DWORD)result == 1 )
{
result = dimensions * a2;
*(_DWORD *)(a1 + 4 * result) = grid_size;
*(_DWORD *)(a1 + 4LL * dimensions * a2 + 4) = v3;
}
}
else
{
result = dimensions * a2;
*(float *)(a1 + 4 * result) = -*(float *)&grid_size;
*(_DWORD *)(a1 + 4LL * dimensions * a2 + 4) = v3;
}
return result;
}

original_code:
void initialize_particle(float* particles, int i)
{
 float random_position = grid_size*(2*rand()/(float)2147483647);
 switch( rand() % 4)
 {
  case 0:
   particles[dimensions*i] = -grid_size;
   particles[dimensions*i+1] = random_position;
   break;
  case 1:
   particles[dimensions*i] = grid_size;
   particles[dimensions*i+1] = random_position;
   break;
  case 2:
   particles[dimensions*i] = random_position;
   particles[dimensions*i+1] = -grid_size;
   break;
  case 3:
   particles[dimensions*i] = random_position;
   particles[dimensions*i+1] = grid_size;
   break;
 }
}

canonical_original_code:
void initialize_particle(float *particles, int i)
{
 float random_position = grid_size*(2*rand()/(float)2147483647);
 switch( rand() % 4)
 {
  case 0:
   particles[dimensions*i] = -grid_size;
   particles[dimensions*i+1] = random_position;
   break;
  case 1:
   particles[dimensions*i] = grid_size;
   particles[dimensions*i+1] = random_position;
   break;
  case 2:
   particles[dimensions*i] = random_position;
   particles[dimensions*i+1] = -grid_size;
   break;
  case 3:
   particles[dimensions*i] = random_position;
   particles[dimensions*i+1] = grid_size;
   break;
 }
}

variable_types:
particles
float *


decompiled_code:
__int64 __fastcall move_particle(__int64 a1, int a2)
{
float v2; // xmm3_4
float v3; // xmm0_4
float *v4; // rax
float v5; // xmm0_4
float *v6; // rax
float v7; // xmm0_4
__int64 result; // rax
float v9; // xmm1_4
float v10; // xmm1_4
float v11; // [rsp+8h] [rbp-20h]
float v12; // [rsp+Ch] [rbp-1Ch]

v2 = (float)((float)rand() * *(float *)&radius) * 4.6566129e-10;
v11 = (float)((float)rand() * v2) * 4.6566129e-10;
v3 = (float)(v2 * v2) - (float)(v11 * v11);
if ( v3 < 0.0 )
v12 = sqrtf(v3);
else
v12 = fsqrt(v3);
if ( rand() % 2 <= 0 )
{
v4 = (float *)(a1 + 4LL * dimensions * a2);
v5 = *v4 - v11;
}
else
{
v4 = (float *)(a1 + 4LL * dimensions * a2);
v5 = v11 + *v4;
}
*v4 = v5;
if ( rand() % 2 <= 0 )
{
v6 = (float *)(a1 + 4LL * dimensions * a2 + 4);
v7 = *v6 - v12;
}
else
{
v6 = (float *)(a1 + 4LL * dimensions * a2 + 4);
v7 = v12 + *v6;
}
*v6 = v7;
result = dimensions * a2;
v9 = *(float *)(a1 + 4 * result);
if ( v9 > *(float *)&grid_size
|| (float)-*(float *)&grid_size > v9
|| (v10 = *(float *)(a1 + 4 * result + 4), v10 > *(float *)&grid_size)
|| (float)-*(float *)&grid_size > v10 )
{
result = initialize_particle(a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
float v2; // xmm3_4
float v3; // xmm0_4
float *v4; // rax
float v5; // xmm0_4
float *v6; // rax
float v7; // xmm0_4
__int64 result; // rax
float v9; // xmm1_4
float v10; // xmm1_4
float v11; // [rsp+8h] [rbp-20h]
float v12; // [rsp+Ch] [rbp-1Ch]

v2 = (float)((float)rand() * *(float *)&radius) * 4.6566129e-10;
v11 = (float)((float)rand() * v2) * 4.6566129e-10;
v3 = (float)(v2 * v2) - (float)(v11 * v11);
if ( v3 < 0.0 )
v12 = sqrtf(v3);
else
v12 = fsqrt(v3);
if ( rand() % 2 <= 0 )
{
v4 = (float *)(a1 + 4LL * dimensions * a2);
v5 = *v4 - v11;
}
else
{
v4 = (float *)(a1 + 4LL * dimensions * a2);
v5 = v11 + *v4;
}
*v4 = v5;
if ( rand() % 2 <= 0 )
{
v6 = (float *)(a1 + 4LL * dimensions * a2 + 4);
v7 = *v6 - v12;
}
else
{
v6 = (float *)(a1 + 4LL * dimensions * a2 + 4);
v7 = v12 + *v6;
}
*v6 = v7;
result = dimensions * a2;
v9 = *(float *)(a1 + 4 * result);
if ( v9 > *(float *)&grid_size
|| (float)-*(float *)&grid_size > v9
|| (v10 = *(float *)(a1 + 4 * result + 4), v10 > *(float *)&grid_size)
|| (float)-*(float *)&grid_size > v10 )
{
result = func8(a1, a2);
}
return result;
}

original_code:
void move_particle(float* particles, int i)
{
 float velocity = radius*rand()/(float)2147483647;
 float x_value = velocity*rand()/(float)2147483647;
 float y_squared = velocity*velocity-x_value*x_value;
 float y_value = sqrt(y_squared);
 if ((rand()%2) < 1)
  particles[dimensions*i] = particles[dimensions*i]-x_value;
 else
  particles[dimensions*i] = particles[dimensions*i]+x_value;
 if ((rand()%2) < 1)
  particles[dimensions*i+1] = particles[dimensions*i+1]-y_value;
 else
  particles[dimensions*i+1] = particles[dimensions*i+1]+y_value;
 if (particles[dimensions*i] > grid_size || particles[dimensions*i] < -grid_size || particles[dimensions*i+1] > grid_size || particles[dimensions*i+1] < -grid_size)
  initialize_particle(particles, i);
}

canonical_original_code:
void move_particle(float *particles, int i)
{
 float velocity = radius*rand()/(float)2147483647;
 float x_value = velocity*rand()/(float)2147483647;
 float y_squared = velocity*velocity-x_value*x_value;
 float y_value = sqrt(y_squared);
 if ((rand()%2) < 1)
  particles[dimensions*i] = particles[dimensions*i]-x_value;
 else
  particles[dimensions*i] = particles[dimensions*i]+x_value;
 if ((rand()%2) < 1)
  particles[dimensions*i+1] = particles[dimensions*i+1]-y_value;
 else
  particles[dimensions*i+1] = particles[dimensions*i+1]+y_value;
 if (particles[dimensions*i] > grid_size || particles[dimensions*i] < -grid_size || particles[dimensions*i+1] > grid_size || particles[dimensions*i+1] < -grid_size)
  initialize_particle(particles, i);
}

variable_types: velocity float


decompiled_code:
__int64 __fastcall check_for_collision(__int64 a1, int a2)
{
int v2; // ebp

if ( a2 <= 0 )
return 0LL;
v2 = 0;
while ( (float)(*(float *)&radius + *(float *)&radius) <= distance(
*(float *)(a1 + 4 * (a2 * dimensions + 1LL) - 4),
*(float *)(a1 + 4 * (v2 * dimensions + 1LL) - 4),
*(float *)(a1 + 4 * (a2 * dimensions + 1LL)),
*(float *)(a1 + 4 * (v2 * dimensions + 1LL))) )
{
if ( a2 == ++v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
int v2; // ebp

if ( a2 <= 0 )
return 0LL;
v2 = 0;
while ( (float)(*(float *)&radius + *(float *)&radius) <= func7(
*(float *)(a1 + 4 * (a2 * dimensions + 1LL) - 4),
*(float *)(a1 + 4 * (v2 * dimensions + 1LL) - 4),
*(float *)(a1 + 4 * (a2 * dimensions + 1LL)),
*(float *)(a1 + 4 * (v2 * dimensions + 1LL))) )
{
if ( a2 == ++v2 )
return 0LL;
}
return 1LL;
}

original_code:
int check_for_collision(float* particles, int i)
{
 int ctr;
 for (ctr = 0; ctr < i; ctr++)
 {
  float distance_to_particle = distance(particles[dimensions*i],particles[dimensions*ctr],particles[dimensions*i+1],particles[dimensions*ctr+1]);
  if (distance_to_particle< (2*radius))
  {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int check_for_collision(float *particles, int i)
{
 int ctr;
 for (ctr = 0; ctr < i; ctr++)
 {
  float distance_to_particle = distance(particles[dimensions*i],particles[dimensions*ctr],particles[dimensions*i+1],particles[dimensions*ctr+1]);
  if (distance_to_particle< (2*radius))
  {
   return 1;
  }
 }
 return 0;
}

variable_types: ctr int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
_DWORD *v5; // r12
int v6; // ebx
unsigned int v7; // er13
int v8; // ebp
float v9; // xmm1_4
double v11; // [rsp+18h] [rbp-40h] BYREF
char v12[56]; // [rsp+20h] [rbp-38h] BYREF

if ( argc <= 2 )
{
puts("./dla seed number_of_particles");
}
else
{
v3 = atoi(argv[1]);
seed = v3;
n_of_particles = atoi(argv[2]);
grid_size = global_grid_size;
radius = global_radius;
srand(v3);
dtimer(&v11, v12, 0xFFFFFFFFLL);
v4 = n_of_particles;
v5 = malloc(4LL * dimensions * n_of_particles);
*v5 = 0;
v5[1] = 0;
if ( v4 <= 1 )
{
v7 = 0;
}
else
{
v6 = 1;
v7 = 0;
do
{
initialize_particle((__int64)v5, v6);
v8 = 0;
do
{
move_particle((__int64)v5, v6);
++v8;
}
while ( !(unsigned int)check_for_collision((__int64)v5, v6) );
v7 += v8;
++v6;
}
while ( n_of_particles > v6 );
}
dtimer(&v11, v12, 1LL);
v9 = v11;
free(v5);
printf("TOTAL NUMBER OF STEPS: %i : %f\n", v7, v9);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
_DWORD *v5; // r12
int v6; // ebx
unsigned int v7; // er13
int v8; // ebp
float v9; // xmm1_4
double v11; // [rsp+18h] [rbp-40h] BYREF
char v12[56]; // [rsp+20h] [rbp-38h] BYREF

if ( argc <= 2 )
{
puts("./dla seed number_of_particles");
}
else
{
v3 = atoi(argv[1]);
seed = v3;
n_of_particles = atoi(argv[2]);
grid_size = global_grid_size;
radius = global_radius;
srand(v3);
func11(&v11, v12, 0xFFFFFFFFLL);
v4 = n_of_particles;
v5 = malloc(4LL * dimensions * n_of_particles);
*v5 = 0;
v5[1] = 0;
if ( v4 <= 1 )
{
v7 = 0;
}
else
{
v6 = 1;
v7 = 0;
do
{
func8((__int64)v5, v6);
v8 = 0;
do
{
func9((__int64)v5, v6);
++v8;
}
while ( !(unsigned int)func10((__int64)v5, v6) );
v7 += v8;
++v6;
}
while ( n_of_particles > v6 );
}
func11(&v11, v12, 1LL);
v9 = v11;
free(v5);
printf("TOTAL NUMBER OF STEPS: %i : %f\n", v7, v9);
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 if (argc < 3)
 {
  printf("./dla seed number_of_particles\n");
  return 0;
 }
 seed = atoi(argv[1]);
 n_of_particles = atoi(argv[2]);
 grid_size = global_grid_size;
 radius = global_radius;
 srand(seed);
 float time;
 struct timeval itime;
 double dtime;
 dtimer(&dtime,&itime,-1);
 float* particles = (float*) malloc (dimensions * n_of_particles * sizeof(float));
 particles[0] = 0.00;
 particles[1] = 0.00;
 int total_step =0;
 int particle_index;
 for (particle_index = 1; particle_index < n_of_particles; particle_index++)
 {
  initialize_particle(particles, particle_index);
  int collision = 0;
  int step_ctr=0;
  while (!collision)
  {
   move_particle(particles, particle_index);
   collision = check_for_collision(particles, particle_index);
   step_ctr++;
  }
  total_step += step_ctr;
 }
 dtimer(&dtime,&itime,1);
 time = (float) dtime;
 free(particles);
 printf("TOTAL NUMBER OF STEPS: %i : %f\n",total_step,time);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if (argc < 3)
 {
  printf("./dla seed number_of_particles\n");
  return 0;
 }
 seed = atoi(argv[1]);
 n_of_particles = atoi(argv[2]);
 grid_size = global_grid_size;
 radius = global_radius;
 srand(seed);
 float time;
 struct timeval itime;
 double dtime;
 dtimer(&dtime,&itime,-1);
 float *particles = (float*) malloc (dimensions * n_of_particles * sizeof(float));
 particles[0] = 0.00;
 particles[1] = 0.00;
 int total_step = 0;
 int particle_index;
 for (particle_index = 1; particle_index < n_of_particles; particle_index++)
 {
  initialize_particle(particles, particle_index);
  int collision = 0;
  int step_ctr = 0;
  while (!collision)
  {
   move_particle(particles, particle_index);
   collision = check_for_collision(particles, particle_index);
   step_ctr++;
  }
  total_step += step_ctr;
 }
 dtimer(&dtime,&itime,1);
 time = (float) dtime;
 free(particles);
 printf("TOTAL NUMBER OF STEPS: %i : %f\n",total_step,time);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: time float

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

variable_types: dtime double

variable_types: collision int


dtimer

decompiled_code:
int __fastcall dtimer(double *a1, __m128i *a2, int a3)
{
int result; // eax
struct timeval v4; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

if ( a3 )
{
if ( a3 == 1 )
{
gettimeofday(&v4, 0LL);
tv = (struct timeval)_mm_loadu_si128(a2);
result = LODWORD(v4.tv_sec) - LODWORD(tv.tv_sec);
*a1 = (double)(LODWORD(v4.tv_usec) - LODWORD(tv.tv_usec)) * 0.000001
+ (double)(LODWORD(v4.tv_sec) - LODWORD(tv.tv_sec));
}
else
{
result = gettimeofday(&tv, 0LL);
*a2 = _mm_loadu_si128((const __m128i *)&tv);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(double *a1, __m128i *a2, int a3)
{
int result; // eax
struct timeval v4; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

if ( a3 )
{
if ( a3 == 1 )
{
gettimeofday(&v4, 0LL);
tv = (struct timeval)_mm_loadu_si128(a2);
result = LODWORD(v4.tv_sec) - LODWORD(tv.tv_sec);
*a1 = (double)(LODWORD(v4.tv_usec) - LODWORD(tv.tv_usec)) * 0.000001
+ (double)(LODWORD(v4.tv_sec) - LODWORD(tv.tv_sec));
}
else
{
result = gettimeofday(&tv, 0LL);
*a2 = _mm_loadu_si128((const __m128i *)&tv);
}
}
return result;
}

original_code:
void dtimer(double *time, struct timeval *itime, int icntrl) {
   long oss, usec;
   const double tick = 1.0/1000000.0;
   struct timeval jclock, nclock;
   if (!(icntrl))
      return;
   if (icntrl==1)
      goto L10;
   oss = gettimeofday(&jclock,((void *)0));
   *itime = jclock;
   return;
L10: oss = gettimeofday(&nclock,((void *)0));
   jclock = *itime;
   usec = nclock.tv_usec - jclock.tv_usec;
   *time = (nclock.tv_sec - jclock.tv_sec) + usec*tick;
   return;
}

canonical_original_code:
void dtimer(double *time, struct timeval *itime, int icntrl) {
   long oss; long usec;
   double tick = 1.0/1000000.0;
   struct timeval jclock; struct timeval nclock;
   if (!(icntrl))
      return;
   if (icntrl==1)
      goto L10;
   oss = gettimeofday(&jclock,((void *)0));
   *itime = jclock;
   return;
L10: oss = gettimeofday(&nclock,((void *)0));
   jclock = *itime;
   usec = nclock.tv_usec - jclock.tv_usec;
   *time = (nclock.tv_sec - jclock.tv_sec) + usec*tick;
   return;
}

variable_types:
time
double *

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

variable_types: icntrl int

variable_types: oss long

variable_types: usec long

variable_types: tick double


decompiled_code:
int __fastcall dtimer_(double *a1, __m128i *a2, int *a3)
{
return dtimer(a1, a2, *a3);
}

canonical_decompiled_code:
int __fastcall func12(double *a1, __m128i *a2, int *a3)
{
return func11(a1, a2, *a3);
}

original_code:
void dtimer_(double *time, unsigned long *itime, int *icntrl) {
   dtimer(time,(struct timeval *)itime,*icntrl);
   return;
}

variable_types:
itime
unsigned long *

variable_types:
icntrl
int *

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


repo: leasim/scramble

decompiled_code:
void *__fastcall clean_keys(void *s, void **a2)
{
int v2; // ebx

v2 = strlen((const char *)s);
memset(s, 0, v2);
return memset(*a2, 0, v2 / 2);
}

canonical_decompiled_code:
void *__fastcall func7(void *s, void **a2)
{
int v2; // ebx

v2 = strlen((const char *)s);
memset(s, 0, v2);
return memset(*a2, 0, v2 / 2);
}

original_code:
void clean_keys(char usrKey[], unsigned char ** keys)
{
 unsigned char * k;
 int i, size;
 size = strlen(usrKey);
 memset((void *)usrKey, '\0', size);
 memset((void *)*keys, '\0', size / 2);
}

canonical_original_code:
void clean_keys(char usrKey[], unsigned char **keys)
{
 unsigned char *k;
 int i; int size;
 size = strlen(usrKey);
 memset((void *)usrKey, '\0', size);
 memset((void *)*keys, '\0', size / 2);
}

variable_types:
usrKey
char []

variable_types:
keys
unsigned char **

variable_types:
k
unsigned char *

variable_types: i int

variable_types: size int


getKey

original_code:
int getKey(char usrKey[], unsigned char ** keys)
{
 int size = strlen(usrKey);
 int numKeys = size / 2;
 int i = 0, tmp = 0;
 unsigned char * tkp;
 if(size % 2 == 1 || size == 0)
 {
  keys = ((void *)0);
  return -1;
 }
 *keys = (unsigned char *)malloc(sizeof(unsigned char) * numKeys);
 if(*keys != ((void *)0))
  tkp = *keys;
 while(usrKey[i] != '\0')
 {
  switch(usrKey[i])
  {
   case '0':
    break;
   case '1':
    if(i % 2 == 0)
     tmp |= 0x10;
    else
     tmp |= 0x01;
    break;
   case '2':
    if(i % 2 == 0)
     tmp |= 0x20;
    else
     tmp |= 0x02;
    break;
   case '3':
    if(i % 2 == 0)
     tmp |= 0x30;
    else
     tmp |= 0x03;
    break;
   case '4':
    if(i % 2 == 0)
     tmp |= 0x40;
    else
     tmp |= 0x04;
    break;
   case '5':
    if(i % 2 == 0)
     tmp |= 0x50;
    else
     tmp |= 0x05;
    break;
   case '6':
    if(i % 2 == 0)
     tmp |= 0x60;
    else
     tmp |= 0x06;
    break;
   case '7':
    if(i % 2 == 0)
     tmp |= 0x70;
    else
     tmp |= 0x07;
    break;
   case '8':
    if(i % 2 == 0)
     tmp |= 0x80;
    else
     tmp |= 0x08;
    break;
   case '9':
    if(i % 2 == 0)
     tmp |= 0x90;
    else
     tmp |= 0x09;
    break;
   case 'a':
   case 'A':
    if(i % 2 == 0)
     tmp |= 0xa0;
    else
     tmp |= 0x0a;
    break;
   case 'b':
   case 'B':
    if(i % 2 == 0)
     tmp |= 0xb0;
    else
     tmp |= 0x0b;
    break;
   case 'c':
   case 'C':
    if(i % 2 == 0)
     tmp |= 0xc0;
    else
     tmp |= 0x0c;
    break;
   case 'd':
   case 'D':
    if(i % 2 == 0)
     tmp |= 0xd0;
    else
     tmp |= 0x0d;
    break;
   case 'e':
   case 'E':
    if(i % 2 == 0)
     tmp |= 0xe0;
    else
     tmp |= 0x0e;
    break;
   case 'f':
   case 'F':
    if(i % 2 == 0)
     tmp |= 0xf0;
    else
     tmp |= 0x0f;
    break;
   default:
    free(*keys);
    return -1;
  }
  if(i % 2 == 1)
  {
   *tkp++ = (unsigned char)tmp;
   tmp = 0;
  }
  i++;
 }
 return numKeys;
}

canonical_original_code:
int getKey(char usrKey[], unsigned char **keys)
{
 int size = strlen(usrKey);
 int numKeys = size / 2;
 int i = 0; int tmp = 0;
 unsigned char *tkp;
 if(size % 2 == 1 || size == 0)
 {
  keys = ((void *)0);
  return -1;
 }
 *keys = (unsigned char *)malloc(sizeof(unsigned char) * numKeys);
 if(*keys != ((void *)0))
  tkp = *keys;
 while(usrKey[i] != '\0')
 {
  switch(usrKey[i])
  {
   case '0':
    break;
   case '1':
    if(i % 2 == 0)
     tmp |= 0x10;
    else
     tmp |= 0x01;
    break;
   case '2':
    if(i % 2 == 0)
     tmp |= 0x20;
    else
     tmp |= 0x02;
    break;
   case '3':
    if(i % 2 == 0)
     tmp |= 0x30;
    else
     tmp |= 0x03;
    break;
   case '4':
    if(i % 2 == 0)
     tmp |= 0x40;
    else
     tmp |= 0x04;
    break;
   case '5':
    if(i % 2 == 0)
     tmp |= 0x50;
    else
     tmp |= 0x05;
    break;
   case '6':
    if(i % 2 == 0)
     tmp |= 0x60;
    else
     tmp |= 0x06;
    break;
   case '7':
    if(i % 2 == 0)
     tmp |= 0x70;
    else
     tmp |= 0x07;
    break;
   case '8':
    if(i % 2 == 0)
     tmp |= 0x80;
    else
     tmp |= 0x08;
    break;
   case '9':
    if(i % 2 == 0)
     tmp |= 0x90;
    else
     tmp |= 0x09;
    break;
   case 'a':
   case 'A':
    if(i % 2 == 0)
     tmp |= 0xa0;
    else
     tmp |= 0x0a;
    break;
   case 'b':
   case 'B':
    if(i % 2 == 0)
     tmp |= 0xb0;
    else
     tmp |= 0x0b;
    break;
   case 'c':
   case 'C':
    if(i % 2 == 0)
     tmp |= 0xc0;
    else
     tmp |= 0x0c;
    break;
   case 'd':
   case 'D':
    if(i % 2 == 0)
     tmp |= 0xd0;
    else
     tmp |= 0x0d;
    break;
   case 'e':
   case 'E':
    if(i % 2 == 0)
     tmp |= 0xe0;
    else
     tmp |= 0x0e;
    break;
   case 'f':
   case 'F':
    if(i % 2 == 0)
     tmp |= 0xf0;
    else
     tmp |= 0x0f;
    break;
   default:
    free(*keys);
    return -1;
  }
  if(i % 2 == 1)
  {
   *tkp++ = (unsigned char)tmp;
   tmp = 0;
  }
  i++;
 }
 return numKeys;
}

variable_types: numKeys int

variable_types: tmp int

variable_types:
tkp
unsigned char *


repo: lecram/bbking

decompiled_code:
void bb_clean(void)
{
endwin();
}

canonical_decompiled_code:
void func0(void)
{
endwin();
}

original_code:
void
bb_clean()
{
    endwin();
}

canonical_original_code:
void bb_clean()
{
    endwin();
}


decompiled_code:
int bb_init()
{
setlocale(6, &locale);
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
curs_set(0);
if ( has_colors() )
{
start_color();
init_pair(1, 1, 0);
init_pair(2, 2, 0);
init_pair(3, 3, 0);
init_pair(4, 4, 0);
init_pair(5, 6, 0);
init_pair(6, 5, 0);
init_pair(7, 7, 0);
}
return atexit(bb_clean);
}

canonical_decompiled_code:
int func1()
{
setlocale(6, &locale);
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
curs_set(0);
if ( has_colors() )
{
start_color();
init_pair(1, 1, 0);
init_pair(2, 2, 0);
init_pair(3, 3, 0);
init_pair(4, 4, 0);
init_pair(5, 6, 0);
init_pair(6, 5, 0);
init_pair(7, 7, 0);
}
return atexit(bb_clean);
}

original_code:
void
bb_init()
{
    setlocale(6, "");
    initscr();
    cbreak();
    noecho();
    nonl();
    intrflush(stdscr, 0);
    keypad(stdscr, 1);
    curs_set(0);
    if (has_colors()) {
        start_color();
        init_pair(RED, 1, 0);
        init_pair(GREEN, 2, 0);
        init_pair(YELLOW, 3, 0);
        init_pair(BLUE, 4, 0);
        init_pair(CYAN, 6, 0);
        init_pair(MAGENTA, 5, 0);
        init_pair(WHITE, 7, 0);
    }
    atexit(bb_clean);
}


input

decompiled_code:
int __fastcall input(char *a1, int a2)
{
int v2; // ebx

nocbreak();
echo();
curs_set(1);
if ( wmove(stdscr, LINES - 2, 0) != -1 )
wgetnstr(stdscr, a1, a2 - 1);
if ( COLS > 0 )
{
v2 = 0;
do
{
if ( wmove(stdscr, LINES - 2, v2) != -1 )
waddch(stdscr, 0x20uLL);
++v2;
}
while ( COLS > v2 );
}
cbreak();
noecho();
return curs_set(0);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, int a2)
{
int v2; // ebx

nocbreak();
echo();
curs_set(1);
if ( wmove(stdscr, LINES - 2, 0) != -1 )
wgetnstr(stdscr, a1, a2 - 1);
if ( COLS > 0 )
{
v2 = 0;
do
{
if ( wmove(stdscr, LINES - 2, v2) != -1 )
waddch(stdscr, 0x20uLL);
++v2;
}
while ( COLS > v2 );
}
cbreak();
noecho();
return curs_set(0);
}

original_code:
void
input(char buffer[], int maxlen)
{
    int i;
    nocbreak();
    echo();
    curs_set(1);
    (wmove((stdscr),((LINES - 2)),((0))) == (-1) ? (-1) : wgetnstr((stdscr),((buffer)),((maxlen - 1))));
    for (i = 0; i < COLS; i++)
        (wmove((stdscr),((LINES - 2)),((i))) == (-1) ? (-1) : waddch((stdscr),((' '))));
    cbreak();
    noecho();
    curs_set(0);
}

variable_types:
buffer
char []

variable_types: maxlen int


interactive

repo: lecram/kibibeat

original_code:
void
interactive(KReport *kreport)
{
    char line[256];
    char token[32];
    char *c;
    int i;
    KRuntime *kruntime;
    KBuffer *kbuffer;
    kruntime = newruntime();
    kbuffer = newbuffer();
    while (1) {
        printf("> ");
        if (fgets(line, 256, stdin) == ((void *)0))
            break;
        if (strcmp(line, "exit\n") == 0)
            break;
        else {
            kreport->token_id = 0;
            c = line;
            while (1) {
                while (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace) && *c != '\n')
                    c++;
                if (*c == '\n')
                    break;
                kreport->token_id++;
                for (i = 0; !((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace); i++, c++)
                    token[i] = *c;
                token[i] = '\0';
                kreport->error = kprocess(kruntime, token);
                if (kreport->error != E_OK) {
                    delruntime(&kruntime);
                    delbuffer(&kbuffer);
                    return;
                }
            }
            repstack(kruntime->stack, kbuffer);
            printf("%s\n", kbuffer->buffer);
            repnable(kruntime->nable, kbuffer);
            printf("%s\n", kbuffer->buffer);
        }
    }
    delruntime(&kruntime);
    delbuffer(&kbuffer);
}

canonical_original_code:
void interactive(struct KReport *kreport)
{
    char line[256];
    char token[32];
    char *c;
    int i;
    struct KRuntime *kruntime;
    struct KBuffer *kbuffer;
    kruntime = newruntime();
    kbuffer = newbuffer();
    while (1) {
        printf("> ");
        if (fgets(line, 256, stdin) == ((void *)0))
            break;
        if (strcmp(line, "exit\n") == 0)
            break;
        else {
            kreport->token_id = 0;
            c = line;
            while (1) {
                while (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace) && *c != '\n')
                    c++;
                if (*c == '\n')
                    break;
                kreport->token_id++;
                for (i = 0; !((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace); i++, c++)
                    token[i] = *c;
                token[i] = '\0';
                kreport->error = kprocess(kruntime, token);
                if (kreport->error != E_OK) {
                    delruntime(&kruntime);
                    delbuffer(&kbuffer);
                    return;
                }
            }
            repstack(kruntime->stack, kbuffer);
            printf("%s\n", kbuffer->buffer);
            repnable(kruntime->nable, kbuffer);
            printf("%s\n", kbuffer->buffer);
        }
    }
    delruntime(&kruntime);
    delbuffer(&kbuffer);
}

variable_types: struct KReport { enum Error { E_OK=0, E_TYPE=1, E_ARITY=2, E_NAME=3, E_SYNTAX=4, E_FILE=5 } error; char *filename; unsigned int line_id; unsigned int token_id; } *

variable_types:
line
char [256]

variable_types:
token
char [32]

variable_types:
c
char *

variable_types: struct KRuntime { struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *stack; struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } *nable; struct KTrack { struct KEvent { unsigned int delta; char note; char volume; } *event; struct KTrack *next; } *track; int comment; } *

variable_types: struct KBuffer { unsigned long size; char *buffer; } *

user_defined_types: struct KReport { enum Error error; char *filename; unsigned int line_id; unsigned int token_id; }

user_defined_types: struct KRuntime { struct KStack *stack; struct KNable *nable; struct KTrack *track; int comment; }

user_defined_types: struct KStack { enum Kob *kob; struct KStack *next; }

user_defined_types: struct KNable { int level; struct KEntry *header; }

user_defined_types: struct KTrack { struct KEvent *event; struct KTrack *next; }

user_defined_types: struct KEntry { char *name; enum Kob *value; struct KEntry **next; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
const char *v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

LODWORD(v4) = 0;
v5 = (const char *)&unk_3DA;
v6 = 0x100000001LL;
if ( argc == 1 )
{
interactive(&v4);
}
else
{
result = 0;
if ( argc != 2 )
return result;
v5 = argv[1];
run((__int64)&v4);
}
result = 0;
if ( (_DWORD)v4 )
{
printreport(&v4, argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
const char *v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

LODWORD(v4) = 0;
v5 = (const char *)&unk_3DA;
v6 = 0x100000001LL;
if ( argc == 1 )
{
func0(&v4);
}
else
{
result = 0;
if ( argc != 2 )
return result;
v5 = argv[1];
func1((__int64)&v4);
}
result = 0;
if ( (_DWORD)v4 )
{
printreport(&v4, argv);
result = 1;
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
    KReport kreport;
    kreport.error = E_OK;
    kreport.filename = "";
    kreport.line_id = 1;
    kreport.token_id = 1;
    if (argc == 1)
        interactive(&kreport);
    else if (argc == 2) {
        kreport.filename = argv[1];
        run(&kreport);
    }
    if (kreport.error != E_OK) {
        printreport(kreport);
        return 1;
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct KReport kreport;
    kreport.error = E_OK;
    kreport.filename = "";
    kreport.line_id = 1;
    kreport.token_id = 1;
    if (argc == 1)
        interactive(&kreport);
    else if (argc == 2) {
        kreport.filename = argv[1];
        run(&kreport);
    }
    if (kreport.error != E_OK) {
        printreport(kreport);
        return 1;
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct KReport { enum Error { E_OK=0, E_TYPE=1, E_ARITY=2, E_NAME=3, E_SYNTAX=4, E_FILE=5 } error; char *filename; unsigned int line_id; unsigned int token_id; }


krandom

decompiled_code:
double krandom()
{
return (double)rand() * 4.656612873077393e-10;
}

original_code:
double
krandom()
{
    return rand() / ((double) 2147483647 + 1);
}


trndlevel

decompiled_code:
__int64 __fastcall trndlevel(_DWORD *a1)
{
int v1; // ebp
int i; // ebx
double v3; // xmm0_8

v1 = (*a1 != 9) + *a1;
for ( i = 0; ; ++i )
{
v3 = krandom();
if ( i >= v1 || v3 >= 0.5 )
break;
}
return (unsigned int)i;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
int v1; // ebp
int i; // ebx
double v3; // xmm0_8

v1 = (*a1 != 9) + *a1;
for ( i = 0; ; ++i )
{
v3 = func0();
if ( i >= v1 || v3 >= 0.5 )
break;
}
return (unsigned int)i;
}

original_code:
int
trndlevel(KNable *knable)
{
    int level = 0;
    int max;
    if (knable->level == 10 - 1)
        max = 10 - 1;
    else
        max = knable->level + 1;
    while (krandom() < 0.5 && level < max)
        level++;
    return level;
}

canonical_original_code:
int trndlevel(struct KNable *knable)
{
    int level = 0;
    int max;
    if (knable->level == 10 - 1)
        max = 10 - 1;
    else
        max = knable->level + 1;
    while (krandom() < 0.5 && level < max)
        level++;
    return level;
}

variable_types: struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } *

variable_types: level int

variable_types: max int


delentry

decompiled_code:
void __fastcall delentry(void ***a1)
{
free(**a1);
free((*a1)[2]);
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(void ***a1)
{
free(**a1);
free((*a1)[2]);
free(*a1);
*a1 = 0LL;
}

original_code:
void
delentry(KEntry **kentry)
{
    free((*kentry)->name);
    free((*kentry)->next);
    free(*kentry);
    *kentry = ((void *)0);
}

canonical_original_code:
void delentry(struct KEntry **kentry)
{
    free((*kentry)->name);
    free((*kentry)->next);
    free(*kentry);
    *kentry = ((void *)0);
}

variable_types: struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } **


repsizeentry

decompiled_code:
size_t __fastcall repsizeentry(__int64 a1)
{
__int64 v1; // rbp

v1 = repsizekob(*(_QWORD *)(a1 + 8));
return v1 + strlen(*(const char **)a1) + 3;
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1)
{
__int64 v1; // rbp

v1 = repsizekob(*(_QWORD *)(a1 + 8));
return v1 + strlen(*(const char **)a1) + 3;
}

original_code:
size_t
repsizeentry(KEntry *kentry)
{
    return repsizekob(kentry->value) + strlen(kentry->name) + 3;
}

canonical_original_code:
unsigned long repsizeentry(struct KEntry *kentry)
{
    return repsizekob(kentry->value) + strlen(kentry->name) + 3;
}

variable_types: struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *


repentry

decompiled_code:
__int64 __fastcall repentry(__int64 a1, _BYTE *a2)
{
size_t v2; // rax

*a2 = 36;
strcpy(a2 + 1, *(const char **)a1);
v2 = strlen(*(const char **)a1);
strcpy(&a2[v2 + 1], ": ");
return repkob(*(_QWORD *)(a1 + 8), &a2[v2 + 3]);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2)
{
size_t v2; // rax

*a2 = 36;
strcpy(a2 + 1, *(const char **)a1);
v2 = strlen(*(const char **)a1);
strcpy(&a2[v2 + 1], ": ");
return repkob(*(_QWORD *)(a1 + 8), &a2[v2 + 3]);
}

original_code:
void
repentry(KEntry *kentry, char *buffer)
{
    char *brep = buffer;
    *brep = '$';
    brep++;
    strcpy(brep, kentry->name);
    brep += strlen(kentry->name);
    strcpy(brep, ": ");
    brep += 2;
    repkob(kentry->value, brep);
}

canonical_original_code:
void repentry(struct KEntry *kentry, char *buffer)
{
    char *brep = buffer;
    *brep = '$';
    brep++;
    strcpy(brep, kentry->name);
    brep += strlen(kentry->name);
    strcpy(brep, ": ");
    brep += 2;
    repkob(kentry->value, brep);
}

variable_types:
buffer
char *

variable_types:
brep
char *

user_defined_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 }


newnable

decompiled_code:
_QWORD *newnable()
{
unsigned int v0; // eax
_QWORD *v1; // rbx

v0 = time(0LL);
srand(v0);
v1 = malloc(0x10uLL);
*(_DWORD *)v1 = 0;
v1[1] = newentry(9, (const char *)&unk_73A, 0LL);
return v1;
}

canonical_decompiled_code:
_QWORD *func5()
{
unsigned int v0; // eax
_QWORD *v1; // rbx

v0 = time(0LL);
srand(v0);
v1 = malloc(0x10uLL);
*(_DWORD *)v1 = 0;
v1[1] = newentry(9, (const char *)&unk_73A, 0LL);
return v1;
}

original_code:
KNable *
newnable()
{
    KNable *knable;
    srand(time(((void *)0)));
    knable = (KNable *) malloc(sizeof(KNable));
    knable->level = 0;
    knable->header = newentry(10 - 1, "", ((void *)0));
    return knable;
}

canonical_original_code:
struct KNable *newnable()
{
    struct KNable *knable;
    srand(time(((void *)0)));
    knable = (struct KNable *) malloc(sizeof(KNable));
    knable->level = 0;
    knable->header = newentry(10 - 1, "", ((void *)0));
    return knable;
}

return_type: struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } *


delnable

decompiled_code:
void __fastcall delnable(void **a1)
{
void **v1; // rbx
void **v2; // [rsp+8h] [rbp-20h] BYREF

v2 = (void **)*((_QWORD *)*a1 + 1);
do
{
v1 = *(void ***)v2[2];
delentry(&v2);
v2 = v1;
}
while ( v1 );
free(*a1);
*a1 = 0LL;
}

original_code:
void
delnable(KNable **knable)
{
    KEntry *a, *b;
    a = (*knable)->header;
    do {
        b = a->next[0];
        delentry(&a);
        a = b;
    } while (a != ((void *)0));
    free(*knable);
    *knable = ((void *)0);
}

canonical_original_code:
void delnable(struct KNable **knable)
{
    struct KEntry *a; struct KEntry *b;
    a = (*knable)->header;
    do {
        b = a->next[0];
        delentry(&a);
        a = b;
    } while (a != ((void *)0));
    free(*knable);
    *knable = ((void *)0);
}

variable_types: struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } **


repsizenable

decompiled_code:
__int64 __fastcall repsizenable(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // r12
__int64 result; // rax

v1 = **(_QWORD **)(*(_QWORD *)(a1 + 8) + 16LL);
if ( !v1 )
return 2LL;
v2 = 0;
v3 = 0LL;
do
{
v3 += repsizeentry(v1);
++v2;
v1 = **(_QWORD **)(v1 + 16);
}
while ( v1 );
if ( v2 )
result = v3 + (unsigned int)(2 * v2);
else
result = 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // r12
__int64 result; // rax

v1 = **(_QWORD **)(*(_QWORD *)(a1 + 8) + 16LL);
if ( !v1 )
return 2LL;
v2 = 0;
v3 = 0LL;
do
{
v3 += func3(v1);
++v2;
v1 = **(_QWORD **)(v1 + 16);
}
while ( v1 );
if ( v2 )
result = v3 + (unsigned int)(2 * v2);
else
result = 2LL;
return result;
}

original_code:
size_t
repsizenable(KNable *knable)
{
    KEntry *kentry;
    size_t size = 0;
    unsigned int len = 0;
    kentry = knable->header->next[0];
    while (kentry != ((void *)0)) {
        size += repsizeentry(kentry);
        len++;
        kentry = kentry->next[0];
    }
    if (len == 0)
        return 2;
    return size + len * 2;
}

canonical_original_code:
unsigned long repsizenable(struct KNable *knable)
{
    struct KEntry *kentry;
    unsigned long size = 0;
    unsigned int len = 0;
    kentry = knable->header->next[0];
    while (kentry != ((void *)0)) {
        size += repsizeentry(kentry);
        len++;
        kentry = kentry->next[0];
    }
    if (len == 0)
        return 2;
    return size + len * 2;
}

variable_types:
size
unsigned long

variable_types:
len
unsigned int


tget

decompiled_code:
__int64 __fastcall tget(__int64 a1, const char *a2, _QWORD *a3)
{
__int64 v4; // r12
int v5; // eax
__int64 v6; // rbp
unsigned __int64 v7; // r14
__int64 v8; // rbx
__int64 v9; // rbx
__int64 result; // rax
int v11; // edx

v4 = *(_QWORD *)(a1 + 8);
v5 = *(_DWORD *)a1;
if ( *(int *)a1 >= 0 )
{
v6 = 8LL * v5;
v7 = 8 * (v5 - (unsigned __int64)(unsigned int)v5);
while ( 1 )
{
v8 = v4;
do
{
v4 = v8;
v8 = *(_QWORD *)(*(_QWORD *)(v8 + 16) + v6);
}
while ( v8 && strcmp(*(const char **)v8, a2) < 0 );
if ( v6 == v7 )
break;
v6 -= 8LL;
}
}
v9 = **(_QWORD **)(v4 + 16);
result = 0LL;
if ( v9 )
{
v11 = strcmp(*(const char **)v9, a2);
result = 0LL;
if ( !v11 )
{
*a3 = *(_QWORD *)(v9 + 8);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, _QWORD *a3)
{
__int64 v4; // r12
int v5; // eax
__int64 v6; // rbp
unsigned __int64 v7; // r14
__int64 v8; // rbx
__int64 v9; // rbx
__int64 result; // rax
int v11; // edx

v4 = *(_QWORD *)(a1 + 8);
v5 = *(_DWORD *)a1;
if ( *(int *)a1 >= 0 )
{
v6 = 8LL * v5;
v7 = 8 * (v5 - (unsigned __int64)(unsigned int)v5);
while ( 1 )
{
v8 = v4;
do
{
v4 = v8;
v8 = *(_QWORD *)(*(_QWORD *)(v8 + 16) + v6);
}
while ( v8 && strcmp(*(const char **)v8, a2) < 0 );
if ( v6 == v7 )
break;
v6 -= 8LL;
}
}
v9 = **(_QWORD **)(v4 + 16);
result = 0LL;
if ( v9 )
{
v11 = strcmp(*(const char **)v9, a2);
result = 0LL;
if ( !v11 )
{
*a3 = *(_QWORD *)(v9 + 8);
result = 1LL;
}
}
return result;
}

original_code:
int
tget(KNable *knable, char *name, Kob **value)
{
    KEntry *kentry;
    int found, i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        *value = kentry->value;
        return 1;
    }
    return 0;
}

canonical_original_code:
int tget(struct KNable *knable, char *name, enum Kob **value)
{
    struct KEntry *kentry;
    int found; int i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        *value = kentry->value;
        return 1;
    }
    return 0;
}

variable_types:
name
char *

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } **

variable_types: found int

variable_types: i int


tremove

original_code:
int
tremove(KNable *knable, char *name)
{
    KEntry *kentry;
    KEntry *update[10];
    int found, i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
        update[i] = kentry;
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        for (i = 0; i <= knable->level; i++) {
            if (update[i]->next[i] != kentry)
                break;
            update[i]->next[i] = kentry->next[i];
        }
        delentry(&kentry);
        while (knable->level > 0 &&
               knable->header->next[knable->level] == ((void *)0))
            knable->level--;
        return 1;
    }
    return 0;
}

canonical_original_code:
int tremove(struct KNable *knable, char *name)
{
    struct KEntry *kentry;
    struct KEntry *update[10];
    int found; int i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
        update[i] = kentry;
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        for (i = 0; i <= knable->level; i++) {
            if (update[i]->next[i] != kentry)
                break;
            update[i]->next[i] = kentry->next[i];
        }
        delentry(&kentry);
        while (knable->level > 0 &&
               knable->header->next[knable->level] == ((void *)0))
            knable->level--;
        return 1;
    }
    return 0;
}

variable_types: struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *[10]


newstack

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

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

original_code:
KStack *
newstack()
{
    return ((void *)0);
}

canonical_original_code:
struct KStack *newstack()
{
    return ((void *)0);
}

return_type: struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *


repsizestack

decompiled_code:
__int64 __fastcall repsizestack(_QWORD *a1)
{
__int64 v1; // rbp
_QWORD *i; // rbx

v1 = 1LL;
if ( a1 )
{
v1 = repsizekob(*a1);
for ( i = (_QWORD *)a1[1]; i; i = (_QWORD *)i[1] )
v1 += repsizekob(*i) + 1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 v1; // rbp
_QWORD *i; // rbx

v1 = 1LL;
if ( a1 )
{
v1 = repsizekob(*a1);
for ( i = (_QWORD *)a1[1]; i; i = (_QWORD *)i[1] )
v1 += repsizekob(*i) + 1;
}
return v1;
}

original_code:
size_t
repsizestack(KStack *kstack)
{
    size_t size;
    if (kstack == ((void *)0))
        return 1;
    size = repsizekob(kstack->kob);
    kstack = kstack->next;
    while (kstack != ((void *)0)) {
        size += 1 + repsizekob(kstack->kob);
        kstack = kstack->next;
    }
    return size;
}

canonical_original_code:
unsigned long repsizestack(struct KStack *kstack)
{
    unsigned long size;
    if (kstack == ((void *)0))
        return 1;
    size = repsizekob(kstack->kob);
    kstack = kstack->next;
    while (kstack != ((void *)0)) {
        size += 1 + repsizekob(kstack->kob);
        kstack = kstack->next;
    }
    return size;
}

variable_types: struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *


slength

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
unsigned int
slength(KStack *kstack)
{
    unsigned int length = 0;
    while (kstack != ((void *)0)) {
        length++;
        kstack = kstack->next;
    }
    return length;
}

canonical_original_code:
unsigned int slength(struct KStack *kstack)
{
    unsigned int length = 0;
    while (kstack != ((void *)0)) {
        length++;
        kstack = kstack->next;
    }
    return length;
}

variable_types:
length
unsigned int


spop

original_code:
Kob *
spop(KStack **kstack)
{
    KStack *poped;
    Kob* kob;
    poped = *kstack;
    *kstack = poped->next;
    kob = poped->kob;
    free(poped);
    return kob;
}

canonical_original_code:
enum Kob *spop(struct KStack **kstack)
{
    struct KStack *poped;
    enum Kob *kob;
    poped = *kstack;
    *kstack = poped->next;
    kob = poped->kob;
    free(poped);
    return kob;
}

variable_types: struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } **


newblist

decompiled_code:
_DWORD *newblist()
{
_DWORD *result; // rax

result = malloc(0x18uLL);
*result = 3;
result[1] = 0;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 1) = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*result = 3;
result[1] = 0;
*((_QWORD *)result + 2) = 0LL;
*((_QWORD *)result + 1) = 0LL;
return result;
}

original_code:
KBlist *
newblist()
{
    KBlist *kblist;
    kblist = (KBlist *) malloc(sizeof(KBlist));
    kblist->type = T_BLIST;
    kblist->length = 0U;
    kblist->first = kblist->last = ((void *)0);
    return kblist;
}

canonical_original_code:
struct KBlist *newblist()
{
    struct KBlist *kblist;
    kblist = (struct KBlist *) malloc(sizeof(KBlist));
    kblist->type = T_BLIST;
    kblist->length = 0U;
    kblist->first = kblist->last = ((void *)0);
    return kblist;
}

variable_types: struct KBlist { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int length; struct KBnode { int beat; struct KBnode *next; } *first; struct KBnode *last; } *

user_defined_types: struct KBlist { enum Kob type; unsigned int length; struct KBnode *first; struct KBnode *last; }


newname

decompiled_code:
char *__fastcall newname(char *src)
{
char *v1; // rbx

v1 = (char *)malloc(0x24uLL);
*(_DWORD *)v1 = 4;
strncpy(v1 + 4, src, 0x20uLL);
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
char *v1; // rbx

v1 = (char *)malloc(0x24uLL);
*(_DWORD *)v1 = 4;
strncpy(v1 + 4, src, 0x20uLL);
return v1;
}

original_code:
KName *
newname(char *name)
{
    KName *kname;
    kname = (KName *) malloc(sizeof(KName));
    kname->type = T_NAME;
    strncpy(kname->name, name, 32);
    return kname;
}

canonical_original_code:
struct KName *newname(char *name)
{
    struct KName *kname;
    kname = (struct KName *) malloc(sizeof(KName));
    kname->type = T_NAME;
    strncpy(kname->name, name, 32);
    return kname;
}

variable_types: struct KName { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; char name[32]; } *

user_defined_types: struct KName { enum Kob type; char name[32]; }


delnumber

decompiled_code:
void __fastcall delnumber(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void
delnumber(KNumber **knumber)
{
    free(*knumber);
    *knumber = ((void *)0);
}

canonical_original_code:
void delnumber(struct KNumber **knumber)
{
    free(*knumber);
    *knumber = ((void *)0);
}

variable_types: struct KNumber { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int value; } **

user_defined_types: struct KNumber { enum Kob type; unsigned int value; }


delbeat

decompiled_code:
void __fastcall delbeat(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func3(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void
delbeat(KBeat **kbeat)
{
    free(*kbeat);
    *kbeat = ((void *)0);
}

canonical_original_code:
void delbeat(struct KBeat **kbeat)
{
    free(*kbeat);
    *kbeat = ((void *)0);
}

variable_types: struct KBeat { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; int value; } **

user_defined_types: struct KBeat { enum Kob type; int value; }


delbnode

decompiled_code:
void __fastcall delbnode(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void
delbnode(KBnode **kbnode)
{
    free(*kbnode);
    *kbnode = ((void *)0);
}

canonical_original_code:
void delbnode(struct KBnode **kbnode)
{
    free(*kbnode);
    *kbnode = ((void *)0);
}

variable_types: struct KBnode { int beat; struct KBnode *next; } **


delblist

original_code:
void
delblist(KBlist **kblist)
{
    KBnode *second;
    while ((*kblist)->length > 1U) {
        second = (*kblist)->first->next;
        delbnode(&(*kblist)->first);
        (*kblist)->first = second;
        (*kblist)->length--;
    }
    delbnode(&(*kblist)->first);
    free(*kblist);
    *kblist = ((void *)0);
}

canonical_original_code:
void delblist(struct KBlist **kblist)
{
    struct KBnode *second;
    while ((*kblist)->length > 1U) {
        second = (*kblist)->first->next;
        delbnode(&(*kblist)->first);
        (*kblist)->first = second;
        (*kblist)->length--;
    }
    delbnode(&(*kblist)->first);
    free(*kblist);
    *kblist = ((void *)0);
}

variable_types: struct KBlist { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int length; struct KBnode { int beat; struct KBnode *next; } *first; struct KBnode *last; } **


delname

decompiled_code:
void __fastcall delname(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func6(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void
delname(KName **kname)
{
    free(*kname);
    *kname = ((void *)0);
}

canonical_original_code:
void delname(struct KName **kname)
{
    free(*kname);
    *kname = ((void *)0);
}

variable_types: struct KName { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; char name[32]; } **


delkob

decompiled_code:
void __fastcall delkob(void **a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)*a1;
if ( v1 == 3 )
{
delblist(a1);
}
else if ( v1 > 3 )
{
if ( v1 == 4 )
delname(a1);
}
else if ( v1 == 1 )
{
delnumber(a1);
}
else if ( v1 == 2 )
{
delbeat(a1);
}
}

canonical_decompiled_code:
void __fastcall func7(void **a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)*a1;
if ( v1 == 3 )
{
func5(a1);
}
else if ( v1 > 3 )
{
if ( v1 == 4 )
func6(a1);
}
else if ( v1 == 1 )
{
func2(a1);
}
else if ( v1 == 2 )
{
func3(a1);
}
}

original_code:
void
delkob(Kob **kob)
{
    switch(**kob) {
        case EMPTY:
            return;
        case T_NUMBER:
            delnumber((KNumber **) kob);
            break;
        case T_BEAT:
            delbeat((KBeat **) kob);
            break;
        case T_BLIST:
            delblist((KBlist **) kob);
            break;
        case T_NAME:
            delname((KName **) kob);
            break;
    }
}

canonical_original_code:
void delkob(enum Kob **kob)
{
    switch(**kob) {
        case EMPTY:
            return;
        case T_NUMBER:
            delnumber((struct KNumber **) kob);
            break;
        case T_BEAT:
            delbeat((struct KBeat **) kob);
            break;
        case T_BLIST:
            delblist((struct KBlist **) kob);
            break;
        case T_NAME:
            delname((struct KName **) kob);
            break;
    }
}

user_defined_types: struct KBnode { int beat; struct KBnode *next; }


newbuffer

decompiled_code:
_QWORD *newbuffer()
{
_QWORD *v0; // rbx

v0 = malloc(0x10uLL);
*v0 = 1LL;
v0[1] = malloc(1uLL);
return v0;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rbx

v0 = malloc(0x10uLL);
*v0 = 1LL;
v0[1] = malloc(1uLL);
return v0;
}

original_code:
KBuffer *
newbuffer()
{
    KBuffer *kbuffer;
    kbuffer = (KBuffer *) malloc(sizeof(KBuffer));
    kbuffer->size = 1;
    kbuffer->buffer = (char *) malloc(sizeof(char));
    return kbuffer;
}

canonical_original_code:
struct KBuffer *newbuffer()
{
    struct KBuffer *kbuffer;
    kbuffer = (struct KBuffer *) malloc(sizeof(KBuffer));
    kbuffer->size = 1;
    kbuffer->buffer = (char *) malloc(sizeof(char));
    return kbuffer;
}

variable_types: struct KBuffer { unsigned long size; char *buffer; } *


setupbuffer

decompiled_code:
size_t __fastcall setupbuffer(__int64 a1, size_t a2)
{
size_t v2; // rax
size_t v3; // rbp

v2 = *(_QWORD *)a1;
if ( a2 >= *(_QWORD *)a1 )
{
do
v2 *= 2LL;
while ( v2 <= a2 );
*(_QWORD *)a1 = v2;
}
free(*(void **)(a1 + 8));
v3 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = malloc(*(_QWORD *)a1);
return v3;
}

canonical_decompiled_code:
size_t __fastcall func9(__int64 a1, size_t a2)
{
size_t v2; // rax
size_t v3; // rbp

v2 = *(_QWORD *)a1;
if ( a2 >= *(_QWORD *)a1 )
{
do
v2 *= 2LL;
while ( v2 <= a2 );
*(_QWORD *)a1 = v2;
}
free(*(void **)(a1 + 8));
v3 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = malloc(*(_QWORD *)a1);
return v3;
}

original_code:
size_t
setupbuffer(KBuffer *kbuffer, size_t size)
{
    while (size >= kbuffer->size)
        kbuffer->size *= 2;
    free(kbuffer->buffer);
    kbuffer->buffer = (char *) malloc(sizeof(char) * kbuffer->size);
    return kbuffer->size;
}

canonical_original_code:
unsigned long setupbuffer(struct KBuffer *kbuffer, unsigned long size)
{
    while (size >= kbuffer->size)
        kbuffer->size *= 2;
    free(kbuffer->buffer);
    kbuffer->buffer = (char *) malloc(sizeof(char) * kbuffer->size);
    return kbuffer->size;
}

variable_types:
size
unsigned long

user_defined_types: struct KBuffer { unsigned long size; char *buffer; }


delbuffer

decompiled_code:
void __fastcall delbuffer(void **a1)
{
free(*((void **)*a1 + 1));
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
free(*((void **)*a1 + 1));
free(*a1);
*a1 = 0LL;
}

original_code:
void
delbuffer(KBuffer **kbuffer)
{
    free((*kbuffer)->buffer);
    free(*kbuffer);
    *kbuffer = ((void *)0);
}

canonical_original_code:
void delbuffer(struct KBuffer **kbuffer)
{
    free((*kbuffer)->buffer);
    free(*kbuffer);
    *kbuffer = ((void *)0);
}

variable_types: struct KBuffer { unsigned long size; char *buffer; } **


repsizenumber

original_code:
size_t
repsizenumber(KNumber *knumber)
{
    return (size_t) log10((double) knumber->value) + 1;
}

canonical_original_code:
unsigned long repsizenumber(struct KNumber *knumber)
{
    return (unsigned long) log10((double) knumber->value) + 1;
}

variable_types: struct KNumber { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int value; } *