decompiled_code:
void g2dVectorDivide()
{
g2dVectorNew();
}

canonical_decompiled_code:
void func5()
{
func1();
}

original_code:
Vector2D g2dVectorDivide(Vector2D v, double r)
{
    return g2dVectorNew(v.x / r, v.y / r);
}

canonical_original_code:
struct Vector2D g2dVectorDivide(struct Vector2D v, double r)
{
    return g2dVectorNew(v.x / r, v.y / r);
}


repo: jaccovanschaik/libjvs

decompiled_code:
// attributes: thunk
double g2dVectorLength(double x, double y)
{
return hypot(x, y);
}

canonical_decompiled_code:
double func6(double x, double y)
{
return hypot(x, y);
}

original_code:
double g2dVectorLength(Vector2D v)
{
    return hypot(v.x, v.y);
}

canonical_original_code:
double g2dVectorLength(struct Vector2D v)
{
    return hypot(v.x, v.y);
}

variable_types:
v
struct Vector2D { double x; }

return_type: double


decompiled_code:
void __fastcall g2dVectorNormalize(double a1, double a2)
{
g2dVectorLength(a1, a2);
g2dVectorDivide();
}

canonical_decompiled_code:
void __fastcall func7(double a1, double a2)
{
func6(a1, a2);
func5();
}

original_code:
Vector2D g2dVectorNormalize(Vector2D v)
{
    double len = g2dVectorLength(v);
    return g2dVectorDivide(v, len);
}

canonical_original_code:
struct Vector2D g2dVectorNormalize(struct Vector2D v)
{
    double len = g2dVectorLength(v);
    return g2dVectorDivide(v, len);
}

variable_types:
v
struct Vector2D

variable_types: len double

return_type: struct Vector2D { double x; }


decompiled_code:
_BOOL8 __fastcall g2dLineLineIntersect(double *a1, double *a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15, double a16, double a17, double a18)
{
double v14; // xmm0_8
double v15; // xmm1_8
_BOOL8 result; // rax

v14 = ((a11 - a15) * a18 - (a12 - a16) * a17) / (a14 * a17 - a13 * a18);
if ( a17 == 0.0 )
v15 = (a14 * v14 + a12 - a16) / a18;
else
v15 = (a13 * v14 + a11 - a15) / a17;
if ( a1 )
*a1 = v14;
if ( a2 )
*a2 = v15;
result = 0LL;
if ( COERCE_DOUBLE(*(_QWORD *)&v14 & LC1) <= 1.797693134862316e308 )
result = COERCE_DOUBLE(*(_QWORD *)&v15 & LC1) <= 1.797693134862316e308;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(double *a1, double *a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15, double a16, double a17, double a18)
{
double v14; // xmm0_8
double v15; // xmm1_8
_BOOL8 result; // rax

v14 = ((a11 - a15) * a18 - (a12 - a16) * a17) / (a14 * a17 - a13 * a18);
if ( a17 == 0.0 )
v15 = (a14 * v14 + a12 - a16) / a18;
else
v15 = (a13 * v14 + a11 - a15) / a17;
if ( a1 )
*a1 = v14;
if ( a2 )
*a2 = v15;
result = 0LL;
if ( COERCE_DOUBLE(*(_QWORD *)&v14 & LC1) <= 1.797693134862316e308 )
result = COERCE_DOUBLE(*(_QWORD *)&v15 & LC1) <= 1.797693134862316e308;
return result;
}

original_code:
int g2dLineLineIntersect(Line2D l1, Line2D l2, double *r1, double *r2)
{
    double p, q;
    double num = (l2.dv.y * (l1.pv.x - l2.pv.x) - l2.dv.x * (l1.pv.y - l2.pv.y));
    double den = (l2.dv.x * l1.dv.y - l1.dv.x * l2.dv.y);
    p = num / den;
    if (l2.dv.x != 0) {
        q = (l1.pv.x + p * l1.dv.x - l2.pv.x) / l2.dv.x;
    }
    else {
        q = (l1.pv.y + p * l1.dv.y - l2.pv.y) / l2.dv.y;
    }
    if (r1) *r1 = p;
    if (r2) *r2 = q;
    return (__builtin_isfinite (p) && __builtin_isfinite (q));
}

canonical_original_code:
int g2dLineLineIntersect(struct Line2D l1, struct Line2D l2, double *r1, double *r2)
{
    double p; double q;
    double num = (l2.dv.y * (l1.pv.x - l2.pv.x) - l2.dv.x * (l1.pv.y - l2.pv.y));
    double den = (l2.dv.x * l1.dv.y - l1.dv.x * l2.dv.y);
    p = num / den;
    if (l2.dv.x != 0) {
        q = (l1.pv.x + p * l1.dv.x - l2.pv.x) / l2.dv.x;
    }
    else {
        q = (l1.pv.y + p * l1.dv.y - l2.pv.y) / l2.dv.y;
    }
    if (r1) *r1 = p;
    if (r2) *r2 = q;
    return (__builtin_isfinite (p) && __builtin_isfinite (q));
}

variable_types: struct Line2D { struct Vector2D { double x; } pv; struct Vector2D dv; }

variable_types: p double

variable_types: q double

variable_types: num double

variable_types: den double

return_type: int

user_defined_types: struct Line2D { struct Vector2D pv; struct Vector2D dv; }


decompiled_code:
void __fastcall g2dLineLineIntersection(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15, double a16)
{
double v22[2]; // [rsp+8h] [rbp-10h] BYREF

g2dLineLineIntersect(v22, 0LL, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16);
g2dVectorMultiply();
g2dVectorAdd();
}

canonical_decompiled_code:
void __fastcall func11(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, double a15, double a16)
{
double v22[2]; // [rsp+8h] [rbp-10h] BYREF

func10(v22, 0LL, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16);
func4();
func2();
}

original_code:
Vector2D g2dLineLineIntersection(Line2D l1, Line2D l2)
{
    double r;
    g2dLineLineIntersect(l1, l2, &r, ((void *)0));
    return g2dVectorAdd(l1.pv, g2dVectorMultiply(l1.dv, r));
}

canonical_original_code:
struct Vector2D g2dLineLineIntersection(struct Line2D l1, struct Line2D l2)
{
    double r;
    g2dLineLineIntersect(l1, l2, &r, ((void *)0));
    return g2dVectorAdd(l1.pv, g2dVectorMultiply(l1.dv, r));
}

variable_types: struct Line2D { struct Vector2D pv; struct Vector2D dv; }

variable_types: r double


decompiled_code:
double *__fastcall g2dCircleNew(double *a1, double a2, double a3, double a4)
{
double *result; // rax

result = a1;
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
return result;
}

canonical_decompiled_code:
double *__fastcall func12(double *a1, double a2, double a3, double a4)
{
double *result; // rax

result = a1;
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
return result;
}

original_code:
Circle2D g2dCircleNew(Vector2D center, double radius)
{
    Circle2D circle = {
        .c = center,
        .r = radius
    };
    return circle;
}

canonical_original_code:
struct Circle2D g2dCircleNew(struct Vector2D center, double radius)
{
    struct Circle2D circle = {
        .c = center,
        .r = radius
    };
    return circle;
}

variable_types:
center
struct Vector2D

variable_types: radius double

variable_types: struct Circle2D { struct Vector2D { double x; } c; double r; }

user_defined_types: struct Circle2D { struct Vector2D c; double r; }


original_code:
int g2dCircleLineIntersect(Circle2D c, Line2D l, double *r1, double *r2)
{
    l.pv.x -= c.c.x;
    l.pv.y -= c.c.y;
    const double A = sqr(l.dv.x) + sqr(l.dv.y);
    const double B = 2 * (l.pv.x * l.dv.x + l.pv.y * l.dv.y);
    const double C = sqr(l.pv.x) + sqr(l.pv.y) - sqr(c.r);
    const double discr = sqr(B) - 4 * A * C;
    if (discr > 0) {
        if (r1) *r1 = (-B - sqrt(discr)) / (2 * A);
        if (r2) *r2 = (-B + sqrt(discr)) / (2 * A);
        return 2;
    }
    else if (discr == 0) {
        if (r1) *r1 = -B / (2 * A);
        if (r2) *r2 = -B / (2 * A);
        return 1;
    }
    else {
        return 0;
    }
}

canonical_original_code:
int g2dCircleLineIntersect(struct Circle2D c, struct Line2D l, double *r1, double *r2)
{
    l.pv.x -= c.c.x;
    l.pv.y -= c.c.y;
    double A = sqr(l.dv.x) + sqr(l.dv.y);
    double B = 2 * (l.pv.x * l.dv.x + l.pv.y * l.dv.y);
    double C = sqr(l.pv.x) + sqr(l.pv.y) - sqr(c.r);
    double discr = sqr(B) - 4 * A * C;
    if (discr > 0) {
        if (r1) *r1 = (-B - sqrt(discr)) / (2 * A);
        if (r2) *r2 = (-B + sqrt(discr)) / (2 * A);
        return 2;
    }
    else if (discr == 0) {
        if (r1) *r1 = -B / (2 * A);
        if (r2) *r2 = -B / (2 * A);
        return 1;
    }
    else {
        return 0;
    }
}

variable_types: A double

variable_types: B double

variable_types: C double

variable_types: discr double


decompiled_code:
__int64 __fastcall g2dCircleLineIntersections(double *a1, double *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, __int64 a15, double a16, double a17, __int64 a18, double a19, double a20)
{
int v20; // er12
double v22; // [rsp+8h] [rbp-28h] BYREF
double v23[4]; // [rsp+10h] [rbp-20h] BYREF

v20 = g2dCircleLineIntersect(
&v22,
v23,
a3,
a4,
a5,
a6,
a7,
a8,
a9,
a10,
a11,
a12,
a13,
a14,
a15,
a16,
a17,
a18,
a19,
a20);
if ( v20 >= 0 )
{
if ( a1 )
{
g2dVectorMultiply();
g2dVectorAdd();
*(_QWORD *)a1 = a18;
a1[1] = a19;
}
if ( a2 )
{
g2dVectorMultiply();
g2dVectorAdd();
*(_QWORD *)a2 = a18;
a2[1] = a19;
}
}
return (unsigned int)v20;
}

canonical_decompiled_code:
__int64 __fastcall func14(double *a1, double *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, __int64 a15, double a16, double a17, __int64 a18, double a19, double a20)
{
int v20; // er12
double v22; // [rsp+8h] [rbp-28h] BYREF
double v23[4]; // [rsp+10h] [rbp-20h] BYREF

v20 = func13(
&v22,
v23,
a3,
a4,
a5,
a6,
a7,
a8,
a9,
a10,
a11,
a12,
a13,
a14,
a15,
a16,
a17,
a18,
a19,
a20);
if ( v20 >= 0 )
{
if ( a1 )
{
func4();
func2();
*(_QWORD *)a1 = a18;
a1[1] = a19;
}
if ( a2 )
{
func4();
func2();
*(_QWORD *)a2 = a18;
a2[1] = a19;
}
}
return (unsigned int)v20;
}

original_code:
int g2dCircleLineIntersections(Circle2D c, Line2D l, Vector2D *p1, Vector2D *p2)
{
    double r1, r2;
    const int r = g2dCircleLineIntersect(c, l, &r1, &r2);
    if (r >= 0) {
        if (p1) *p1 = g2dVectorAdd(l.pv, g2dVectorMultiply(l.dv, r));
        if (p2) *p2 = g2dVectorAdd(l.pv, g2dVectorMultiply(l.dv, r));
    }
    return r;
}

canonical_original_code:
int g2dCircleLineIntersections(struct Circle2D c, struct Line2D l, struct Vector2D *p1, struct Vector2D *p2)
{
    double r1; double r2;
    int r = g2dCircleLineIntersect(c, l, &r1, &r2);
    if (r >= 0) {
        if (p1) *p1 = g2dVectorAdd(l.pv, g2dVectorMultiply(l.dv, r));
        if (p2) *p2 = g2dVectorAdd(l.pv, g2dVectorMultiply(l.dv, r));
    }
    return r;
}

variable_types: r int


decompiled_code:
double __fastcall g2dNormalizeAngle(double result)
{
if ( result >= 0.0 )
goto LABEL_5;
do
result = result + 6.283185307179586;
while ( result < 0.0 );
while ( result >= 6.283185307179586 )
{
result = result - 6.283185307179586;
LABEL_5:
;
}
return result;
}

canonical_decompiled_code:
double __fastcall func15(double result)
{
if ( result >= 0.0 )
goto LABEL_5;
do
result = result + 6.283185307179586;
while ( result < 0.0 );
while ( result >= 6.283185307179586 )
{
result = result - 6.283185307179586;
LABEL_5:
;
}
return result;
}

variable_types: angle double


decompiled_code:
double __fastcall g2dRadial(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

v4 = atan2(a3 - a1, a4 - a2);
return g2dNormalizeAngle(v4);
}

canonical_decompiled_code:
double __fastcall func16(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

v4 = atan2(a3 - a1, a4 - a2);
return func15(v4);
}

original_code:
double g2dRadial(Vector2D p1, Vector2D p2)
{
    return g2dNormalizeAngle(atan2(p2.x - p1.x, p2.y - p1.y));
}

canonical_original_code:
double g2dRadial(struct Vector2D p1, struct Vector2D p2)
{
    return g2dNormalizeAngle(atan2(p2.x - p1.x, p2.y - p1.y));
}


variable_types: sweep double

variable_types: clockwise int


decompiled_code:
__int64 __fastcall g2dMatrixScale(__int64 a1, double a2, double a3)
{
__int64 result; // rax

*(_QWORD *)(a1 + 8) = 0LL;
result = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)a1 = a2;
*(double *)(a1 + 24) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, double a2, double a3)
{
__int64 result; // rax

*(_QWORD *)(a1 + 8) = 0LL;
result = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)a1 = a2;
*(double *)(a1 + 24) = a3;
return result;
}

original_code:
Matrix2x2 g2dMatrixScale(double x_factor, double y_factor)
{
    Matrix2x2 m;
    m.c[0].x = x_factor; m.c[1].x = 0;
    m.c[0].y = 0; m.c[1].y = y_factor;
    return m;
}

canonical_original_code:
struct Matrix2x2 g2dMatrixScale(double x_factor, double y_factor)
{
    struct Matrix2x2 m;
    m.c[0].x = x_factor; m.c[1].x = 0;
    m.c[0].y = 0; m.c[1].y = y_factor;
    return m;
}

variable_types: struct Matrix2x2 { struct Vector2D { double x; } c[2]; }

user_defined_types: struct Matrix2x2 { struct Vector2D c[2]; }


hash

original_code:
static HashKey hash(const char *key, int key_len)
{
    int i;
    HashKey hash_key = 1;
    for (i = 0; i < key_len; i++) {
        hash_key = hash_key * 317 + (unsigned char) key[i];
    }
    return hash_key & ((1 << (12)) - 1);
}

canonical_original_code:
static unsigned short hash(char *key, int key_len)
{
    int i;
    unsigned short hash_key = 1;
    for (i = 0; i < key_len; i++) {
        hash_key = hash_key * 317 + (unsigned char) key[i];
    }
    return hash_key & ((1 << (12)) - 1);
}

variable_types:
key
char *

variable_types: i int

return_type: unsigned short


decompiled_code:
__int64 __fastcall find_entry_in_bucket(__int64 a1, const void *a2, int a3)
{
__int64 v4; // rax
__int64 v5; // rbp

v4 = listHead();
if ( !v4 )
return 0LL;
v5 = v4;
while ( *(_DWORD *)(v5 + 40) != a3 || memcmp(*(const void **)(v5 + 32), a2, a3) )
{
v5 = listNext(v5);
if ( !v5 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const void *a2, int a3)
{
__int64 v4; // rax
__int64 v5; // rbp

v4 = listHead();
if ( !v4 )
return 0LL;
v5 = v4;
while ( *(_DWORD *)(v5 + 40) != a3 || memcmp(*(const void **)(v5 + 32), a2, a3) )
{
v5 = listNext(v5);
if ( !v5 )
return 0LL;
}
return v5;
}

original_code:
static HashEntry *find_entry_in_bucket(const List *bucket, const char *key, int key_len)
{
    HashEntry *entry;
    for (entry = listHead(bucket); entry; entry = _listNext(&(entry)->_node)) {
        if (entry->key_len == key_len && memcmp(entry->key, key, key_len) == 0) return entry;
    }
    return ((void *)0);
}

canonical_original_code:
static struct HashEntry *find_entry_in_bucket(struct List *bucket, char *key, int key_len)
{
    struct HashEntry *entry;
    for (entry = listHead(bucket); entry; entry = _listNext(&(entry)->_node)) {
        if (entry->key_len == key_len && memcmp(entry->key, key, key_len) == 0) return entry;
    }
    return ((void *)0);
}

variable_types:
bucket
struct List *

variable_types: struct HashEntry { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List { struct ListNode *head; struct ListNode *tail; int length; } *list; } _node; void *data; void *key; int key_len; } *

user_defined_types: struct HashEntry { struct ListNode _node; void *data; void *key; int key_len; }

user_defined_types: struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; }


hashInitTable

decompiled_code:
void *__fastcall hashInitTable(void *a1)
{
return memset(a1, 0, 0x18000uLL);
}

canonical_decompiled_code:
void *__fastcall func2(void *a1)
{
return memset(a1, 0, 0x18000uLL);
}

original_code:
void hashInitTable(HashTable *table)
{
    memset(table, 0, sizeof(HashTable));
}

canonical_original_code:
void hashInitTable(struct HashTable *table)
{
    memset(table, 0, sizeof(HashTable));
}

variable_types: struct HashTable { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } bucket[-1]; } *

return_type: void

user_defined_types: struct HashTable { struct List bucket[-1]; }

user_defined_types: struct List { struct ListNode *head; struct ListNode *tail; int length; }


hashCreateTable

decompiled_code:
void *hashCreateTable()
{
return calloc(1uLL, 0x18000uLL);
}

canonical_decompiled_code:
void *func3()
{
return calloc(1uLL, 0x18000uLL);
}

original_code:
HashTable *hashCreateTable(void)
{
    return calloc(1, sizeof(HashTable));
}

canonical_original_code:
struct HashTable *hashCreateTable()
{
    return calloc(1, sizeof(HashTable));
}

return_type: struct HashTable { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } bucket[-1]; } *


hashClear

decompiled_code:
__int64 __fastcall hashClear(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
void *v3; // rbp

v1 = a1;
do
{
while ( 1 )
{
result = listRemoveHead(v1);
v3 = (void *)result;
if ( !result )
break;
free(*(void **)(result + 32));
free(v3);
}
v1 += 24LL;
}
while ( v1 != a1 + 98304 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
void *v3; // rbp

v1 = a1;
do
{
while ( 1 )
{
result = listRemoveHead(v1);
v3 = (void *)result;
if ( !result )
break;
free(*(void **)(result + 32));
free(v3);
}
v1 += 24LL;
}
while ( v1 != a1 + 98304 );
return result;
}

original_code:
void hashClear(HashTable *tbl)
{
    int i;
    HashEntry *entry;
    for (i = 0; i < (1 << (12)); i++) {
        while ((entry = listRemoveHead(&tbl->bucket[i])) != ((void *)0)) {
            free(entry->key);
            free(entry);
        }
    }
}

canonical_original_code:
void hashClear(struct HashTable *tbl)
{
    int i;
    struct HashEntry *entry;
    for (i = 0; i < (1 << (12)); i++) {
        while ((entry = listRemoveHead(&tbl->bucket[i])) != ((void *)0)) {
            free(entry->key);
            free(entry);
        }
    }
}


hashDestroy

decompiled_code:
void __fastcall hashDestroy(void *ptr)
{
hashClear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func4((__int64)ptr);
free(ptr);
}

original_code:
void hashDestroy(HashTable *tbl)
{
    hashClear(tbl);
    free(tbl);
}

canonical_original_code:
void hashDestroy(struct HashTable *tbl)
{
    hashClear(tbl);
    free(tbl);
}


hashAdd

decompiled_code:
__int64 __fastcall hashAdd(__int64 a1, __int64 a2, unsigned __int8 *a3, int a4)
{
_BOOL4 v6; // er15
__int64 v7; // r15
_QWORD *v8; // rax
_QWORD *v9; // r12
void *v10; // rax

v6 = a3 != 0LL;
dbgAssert(stderr, a3 != 0LL, "hash.c", 137LL, "hashAdd", "Key pointer is NULL");
dbgAssert(stderr, v6, "hash.c", 138LL, "hashAdd", "Key length <= 0");
v7 = a1 + 24LL * (unsigned __int16)hash(a3, a4);
if ( find_entry_in_bucket(v7, a3, a4) )
{
dbgPrint(stderr, "hash.c", 144LL, "hashAdd", "hashAdd for an existing key:\n");
ihexdump(stderr, 0LL, a3, a4);
abort();
}
v8 = calloc(1uLL, 0x30uLL);
v8[3] = a2;
v9 = v8;
v10 = malloc(a4);
*((_DWORD *)v9 + 10) = a4;
v9[4] = v10;
memcpy(v10, a3, a4);
return listAppendTail(v7, v9);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, unsigned __int8 *a3, int a4)
{
_BOOL4 v6; // er15
__int64 v7; // r15
_QWORD *v8; // rax
_QWORD *v9; // r12
void *v10; // rax

v6 = a3 != 0LL;
dbgAssert(stderr, a3 != 0LL, "hash.c", 137LL, "hashAdd", "Key pointer is NULL");
dbgAssert(stderr, v6, "hash.c", 138LL, "hashAdd", "Key length <= 0");
v7 = a1 + 24LL * (unsigned __int16)func0(a3, a4);
if ( func1(v7, a3, a4) )
{
dbgPrint(stderr, "hash.c", 144LL, "hashAdd", "hashAdd for an existing key:\n");
ihexdump(stderr, 0LL, a3, a4);
abort();
}
v8 = calloc(1uLL, 0x30uLL);
v8[3] = a2;
v9 = v8;
v10 = malloc(a4);
*((_DWORD *)v9 + 10) = a4;
v9[4] = v10;
memcpy(v10, a3, a4);
return listAppendTail(v7, v9);
}

original_code:
void hashAdd(HashTable *tbl, const void *data, const void *key, int key_len)
{
    HashEntry *entry;
    HashKey hash_key;
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 137, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 138, __func__, "Key length <= 0");
    hash_key = hash(key, key_len);
    if (find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len) != ((void *)0)) {
        _dbgPrint(stderr, "hash.c", 144, __func__, "hashAdd for an existing key:\n");
        ihexdump(stderr, 0, key, key_len);
        abort();
    }
    entry = calloc(1, sizeof(HashEntry));
    entry->data = data;
    entry->key = malloc(key_len);
    entry->key_len = key_len;
    memcpy(entry->key, key, key_len);
    _listAppendTail((&tbl->bucket[hash_key]), &(entry)->_node);
}

canonical_original_code:
void hashAdd(struct HashTable *tbl, void *data, void *key, int key_len)
{
    struct HashEntry *entry;
    unsigned short hash_key;
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 137, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 138, __func__, "Key length <= 0");
    hash_key = hash(key, key_len);
    if (find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len) != ((void *)0)) {
        _dbgPrint(stderr, "hash.c", 144, __func__, "hashAdd for an existing key:\n");
        ihexdump(stderr, 0, key, key_len);
        abort();
    }
    entry = calloc(1, sizeof(HashEntry));
    entry->data = data;
    entry->key = malloc(key_len);
    entry->key_len = key_len;
    memcpy(entry->key, key, key_len);
    _listAppendTail((&tbl->bucket[hash_key]), &(entry)->_node);
}

variable_types:
data
void *

variable_types:
key
void *


hashSet

decompiled_code:
__int64 __fastcall hashSet(__int64 a1, __int64 a2, unsigned __int8 *a3, int a4)
{
_BOOL4 v6; // er15
unsigned __int16 v7; // ax
__int64 result; // rax

v6 = a3 != 0LL;
dbgAssert(stderr, a3 != 0LL, "hash.c", 170LL, "hashSet", "Key pointer is NULL");
dbgAssert(stderr, v6, "hash.c", 171LL, "hashSet", "Key length <= 0");
v7 = hash(a3, a4);
result = find_entry_in_bucket(a1 + 24LL * v7, a3, a4);
if ( !result )
{
dbgPrint(stderr, "hash.c", 177LL, "hashSet", "hashSet for a non-existing key:\n");
ihexdump(stderr, 0LL, a3, a4);
abort();
}
*(_QWORD *)(result + 24) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned __int8 *a3, int a4)
{
_BOOL4 v6; // er15
unsigned __int16 v7; // ax
__int64 result; // rax

v6 = a3 != 0LL;
dbgAssert(stderr, a3 != 0LL, "hash.c", 170LL, "hashSet", "Key pointer is NULL");
dbgAssert(stderr, v6, "hash.c", 171LL, "hashSet", "Key length <= 0");
v7 = func0(a3, a4);
result = func1(a1 + 24LL * v7, a3, a4);
if ( !result )
{
dbgPrint(stderr, "hash.c", 177LL, "hashSet", "hashSet for a non-existing key:\n");
ihexdump(stderr, 0LL, a3, a4);
abort();
}
*(_QWORD *)(result + 24) = a2;
return result;
}

original_code:
void hashSet(HashTable *tbl, const void *data, const void *key, int key_len)
{
    HashEntry *entry;
    HashKey hash_key;
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 170, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 171, __func__, "Key length <= 0");
    hash_key = hash(key, key_len);
    if (!(entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len))) {
        _dbgPrint(stderr, "hash.c", 177, __func__, "hashSet for a non-existing key:\n");
        ihexdump(stderr, 0, key, key_len);
        abort();
    }
    entry->data = data;
}

canonical_original_code:
void hashSet(struct HashTable *tbl, void *data, void *key, int key_len)
{
    struct HashEntry *entry;
    unsigned short hash_key;
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 170, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 171, __func__, "Key length <= 0");
    hash_key = hash(key, key_len);
    if (!(entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len))) {
        _dbgPrint(stderr, "hash.c", 177, __func__, "hashSet for a non-existing key:\n");
        ihexdump(stderr, 0, key, key_len);
        abort();
    }
    entry->data = data;
}


hashContains

decompiled_code:
_BOOL8 __fastcall hashContains(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int16 v4; // bx
__int64 v5; // r8
__int64 v6; // r9

v4 = hash(a2, a3);
dbgAssert(stderr, a1 != 0, "hash.c", 195LL, v5, v6);
dbgAssert(stderr, a2 != 0LL, "hash.c", 196LL, "hashContains", "Key pointer is NULL");
dbgAssert(stderr, a2 != 0LL, "hash.c", 197LL, "hashContains", "Key length <= 0");
return find_entry_in_bucket(a1 + 24LL * v4, a2, a3) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int16 v4; // bx
__int64 v5; // r8
__int64 v6; // r9

v4 = func0(a2, a3);
dbgAssert(stderr, a1 != 0, "hash.c", 195LL, v5, v6);
dbgAssert(stderr, a2 != 0LL, "hash.c", 196LL, "hashContains", "Key pointer is NULL");
dbgAssert(stderr, a2 != 0LL, "hash.c", 197LL, "hashContains", "Key length <= 0");
return func1(a1 + 24LL * v4, a2, a3) != 0;
}

original_code:
int hashContains(const HashTable *tbl, const void *key, int key_len)
{
    HashEntry *entry;
    HashKey hash_key = hash(key, key_len);
    _dbgAssert(stderr, tbl != ((void *)0), "hash.c", 195, __func__, "Table pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 196, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 197, __func__, "Key length <= 0");
    entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len);
    return (entry != ((void *)0));
}

canonical_original_code:
int hashContains(struct HashTable *tbl, void *key, int key_len)
{
    struct HashEntry *entry;
    unsigned short hash_key = hash(key, key_len);
    _dbgAssert(stderr, tbl != ((void *)0), "hash.c", 195, __func__, "Table pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 196, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 197, __func__, "Key length <= 0");
    entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len);
    return (entry != ((void *)0));
}


hashGet

decompiled_code:
__int64 __fastcall hashGet(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int16 v4; // bx
__int64 v5; // r8
__int64 v6; // r9
__int64 result; // rax

v4 = hash(a2, a3);
dbgAssert(stderr, a1 != 0, "hash.c", 214LL, v5, v6);
dbgAssert(stderr, a2 != 0LL, "hash.c", 215LL, "hashGet", "Key pointer is NULL");
dbgAssert(stderr, a2 != 0LL, "hash.c", 216LL, "hashGet", "Key length <= 0");
result = find_entry_in_bucket(a1 + 24LL * v4, a2, a3);
if ( result )
result = *(_QWORD *)(result + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int16 v4; // bx
__int64 v5; // r8
__int64 v6; // r9
__int64 result; // rax

v4 = func0(a2, a3);
dbgAssert(stderr, a1 != 0, "hash.c", 214LL, v5, v6);
dbgAssert(stderr, a2 != 0LL, "hash.c", 215LL, "hashGet", "Key pointer is NULL");
dbgAssert(stderr, a2 != 0LL, "hash.c", 216LL, "hashGet", "Key length <= 0");
result = func1(a1 + 24LL * v4, a2, a3);
if ( result )
result = *(_QWORD *)(result + 24);
return result;
}

original_code:
void *hashGet(const HashTable *tbl, const void *key, int key_len)
{
    HashEntry *entry;
    HashKey hash_key = hash(key, key_len);
    _dbgAssert(stderr, tbl != ((void *)0), "hash.c", 214, __func__, "Table pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 215, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 216, __func__, "Key length <= 0");
    entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len);
    return entry ? (void *) entry->data : ((void *)0);
}

canonical_original_code:
void *hashGet(struct HashTable *tbl, void *key, int key_len)
{
    struct HashEntry *entry;
    unsigned short hash_key = hash(key, key_len);
    _dbgAssert(stderr, tbl != ((void *)0), "hash.c", 214, __func__, "Table pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 215, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 216, __func__, "Key length <= 0");
    entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len);
    return entry ? (void *) entry->data : ((void *)0);
}

return_type: void *


hashDrop

decompiled_code:
void __fastcall hashDrop(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int16 v4; // bp
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // r14
__int64 v8; // rax
void **v9; // rbp

v4 = hash(a2, a3);
dbgAssert(stderr, a1 != 0, "hash.c", 233LL, v5, v6);
dbgAssert(stderr, a2 != 0LL, "hash.c", 234LL, "hashDrop", "Key pointer is NULL");
dbgAssert(stderr, a2 != 0LL, "hash.c", 235LL, "hashDrop", "Key length <= 0");
v7 = a1 + 24LL * v4;
v8 = find_entry_in_bucket(v7, a2, a3);
if ( !v8 )
_assert_fail("entry", "hash.c", 0xEFu, "hashDrop");
v9 = (void **)v8;
listRemove(v7, v8);
free(v9[4]);
free(v9);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, unsigned __int8 *a2, int a3)
{
unsigned __int16 v4; // bp
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // r14
__int64 v8; // rax
void **v9; // rbp

v4 = func0(a2, a3);
dbgAssert(stderr, a1 != 0, "hash.c", 233LL, v5, v6);
dbgAssert(stderr, a2 != 0LL, "hash.c", 234LL, "hashDrop", "Key pointer is NULL");
dbgAssert(stderr, a2 != 0LL, "hash.c", 235LL, "hashDrop", "Key length <= 0");
v7 = a1 + 24LL * v4;
v8 = func1(v7, a2, a3);
if ( !v8 )
_assert_fail("entry", "hash.c", 0xEFu, "hashDrop");
v9 = (void **)v8;
listRemove(v7, v8);
free(v9[4]);
free(v9);
}

original_code:
void hashDrop(HashTable *tbl, const void *key, int key_len)
{
    HashEntry *entry;
    HashKey hash_key = hash(key, key_len);
    _dbgAssert(stderr, tbl != ((void *)0), "hash.c", 233, __func__, "Table pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 234, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 235, __func__, "Key length <= 0");
    entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len);
    ((void) sizeof ((entry) ? 1 : 0), __extension__ ({ if (entry) ; else __assert_fail ("entry", "hash.c", 239, __extension__ __PRETTY_FUNCTION__); }));
    _listRemove((&tbl->bucket[hash_key]), &(entry)->_node);
    free(entry->key);
    free(entry);
}

canonical_original_code:
void hashDrop(struct HashTable *tbl, void *key, int key_len)
{
    struct HashEntry *entry;
    unsigned short hash_key = hash(key, key_len);
    _dbgAssert(stderr, tbl != ((void *)0), "hash.c", 233, __func__, "Table pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 234, __func__, "Key pointer is NULL");
    _dbgAssert(stderr, key != ((void *)0), "hash.c", 235, __func__, "Key length <= 0");
    entry = find_entry_in_bucket(&tbl->bucket[hash_key], key, key_len);
    ((void) sizeof ((entry) ? 1 : 0), __extension__ ({ if (entry) ; else __assert_fail ("entry", "hash.c", 239, __extension__ __PRETTY_FUNCTION__); }));
    _listRemove((&tbl->bucket[hash_key]), &(entry)->_node);
    free(entry->key);
    free(entry);
}


hashStats

decompiled_code:
void *__fastcall hashStats(__int64 a1)
{
__int64 v1; // r14
__int64 v2; // r13
void *v3; // r12
__int64 v4; // rbp
_DWORD *v5; // rax
_DWORD *v7; // [rsp+8h] [rbp-30h]

v1 = a1;
v2 = a1 + 98304;
v3 = calloc(1uLL, 0x10uLL);
do
{
while ( 1 )
{
v4 = (unsigned int)listLength(v1);
v5 = (_DWORD *)paGet(v3, v4);
if ( !v5 )
break;
v1 += 24LL;
++*v5;
if ( v1 == v2 )
return v3;
}
v1 += 24LL;
v7 = calloc(1uLL, 4uLL);
paSet(v3, (unsigned int)v4, v7);
++*v7;
}
while ( v1 != v2 );
return v3;
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1)
{
__int64 v1; // r14
__int64 v2; // r13
void *v3; // r12
__int64 v4; // rbp
_DWORD *v5; // rax
_DWORD *v7; // [rsp+8h] [rbp-30h]

v1 = a1;
v2 = a1 + 98304;
v3 = calloc(1uLL, 0x10uLL);
do
{
while ( 1 )
{
v4 = (unsigned int)listLength(v1);
v5 = (_DWORD *)paGet(v3, v4);
if ( !v5 )
break;
v1 += 24LL;
++*v5;
if ( v1 == v2 )
return v3;
}
v1 += 24LL;
v7 = calloc(1uLL, 4uLL);
paSet(v3, (unsigned int)v4, v7);
++*v7;
}
while ( v1 != v2 );
return v3;
}

original_code:
PointerArray *hashStats(HashTable *tbl)
{
    int i;
    PointerArray *stats = calloc(1, sizeof(PointerArray));
    for (i = 0; i < (1 << (12)); i++) {
        List *bucket = tbl->bucket + i;
        int n = listLength(bucket);
        int *counter_p = paGet(stats, n);
        if (counter_p == ((void *)0)) {
            counter_p = calloc(1, sizeof(int));
            paSet(stats, n, counter_p);
        }
        (*counter_p)++;
    }
    return stats;
}

canonical_original_code:
struct PointerArray *hashStats(struct HashTable *tbl)
{
    int i;
    struct PointerArray *stats = calloc(1, sizeof(PointerArray));
    for (i = 0; i < (1 << (12)); i++) {
        struct List *bucket = tbl->bucket + i;
        int n = listLength(bucket);
        int *counter_p = paGet(stats, n);
        if (counter_p == ((void *)0)) {
            counter_p = calloc(1, sizeof(int));
            paSet(stats, n, counter_p);
        }
        (*counter_p)++;
    }
    return stats;
}

variable_types: struct PointerArray { int num_ptrs; void **ptr; } *

variable_types: struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } *

variable_types: n int


hashFreeStats

decompiled_code:
__int64 __fastcall hashFreeStats(__int64 a1)
{
int i; // ebx
void *v3; // rdi

for ( i = 0; (int)paCount(a1) > i; ++i )
{
v3 = (void *)paGet(a1, (unsigned int)i);
if ( v3 )
free(v3);
}
return paDestroy(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int i; // ebx
void *v3; // rdi

for ( i = 0; (int)paCount(a1) > i; ++i )
{
v3 = (void *)paGet(a1, (unsigned int)i);
if ( v3 )
free(v3);
}
return paDestroy(a1);
}

original_code:
void hashFreeStats(PointerArray *stats)
{
    int i;
    for (i = 0; i < paCount(stats); i++) {
        int *p;
        if ((p = paGet(stats, i)) != ((void *)0)) free(p);
    }
    paDestroy(stats);
}

canonical_original_code:
void hashFreeStats(struct PointerArray *stats)
{
    int i;
    for (i = 0; i < paCount(stats); i++) {
        int *p;
        if ((p = paGet(stats, i)) != ((void *)0)) free(p);
    }
    paDestroy(stats);
}

variable_types:
p
int *

user_defined_types: struct PointerArray { int num_ptrs; void **ptr; }


vDel

decompiled_code:
void __fastcall vDel(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void vDel(Vector *v)
{
   free(v->row);
   free(v);
}

canonical_original_code:
void vDel(struct Vector *v)
{
   free(v->row);
   free(v);
}

variable_types: struct Vector { int n_rows; double *row; } *


vLen

original_code:
double vLen(Vector *v)
{
   int i;
   double sum = 0;
   for (i = 0; i < v->n_rows; i++) {
      sum += ((v->row[i]) * (v->row[i]));
   }
   return sqrt(sum);
}

canonical_original_code:
double vLen(struct Vector *v)
{
   int i;
   double sum = 0;
   for (i = 0; i < v->n_rows; i++) {
      sum += ((v->row[i]) * (v->row[i]));
   }
   return sqrt(sum);
}

variable_types: sum double

user_defined_types: struct Vector { int n_rows; double *row; }


vSet

decompiled_code:
_QWORD *vSet(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
_QWORD *result; // rax
_QWORD *v7; // rsi
__int64 v8; // rdx
unsigned int v9; // ecx
_QWORD *v10; // rdi
__int64 v11; // r8
__int64 v12; // rdx
_QWORD *v13; // rdx
gcc_va_list va; // [rsp+18h] [rbp-A0h] BYREF

va_start(va, a6);
result = (_QWORD *)*a1;
if ( (int)result > 0 )
{
v7 = (_QWORD *)*((_QWORD *)a1 + 1);
v8 = (unsigned int)((_DWORD)result - 1);
v9 = 48;
v10 = va[0].overflow_arg_area;
result = v7 + 1;
v11 = (__int64)&v7[v8 + 1];
while ( 1 )
{
if ( v9 <= 0xAF )
{
v12 = v9;
v9 += 16;
*v7 = *(_QWORD *)((char *)va[0].reg_save_area + v12);
v7 = result;
if ( result == (_QWORD *)v11 )
return result;
}
else
{
v13 = v10++;
*v7 = *v13;
v7 = result;
if ( result == (_QWORD *)v11 )
return result;
}
++result;
}
}
return result;
}

canonical_decompiled_code:
_QWORD *func2(unsigned int *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
_QWORD *result; // rax
_QWORD *v7; // rsi
__int64 v8; // rdx
unsigned int v9; // ecx
_QWORD *v10; // rdi
__int64 v11; // r8
__int64 v12; // rdx
_QWORD *v13; // rdx
gcc_va_list va; // [rsp+18h] [rbp-A0h] BYREF

va_start(va, a6);
result = (_QWORD *)*a1;
if ( (int)result > 0 )
{
v7 = (_QWORD *)*((_QWORD *)a1 + 1);
v8 = (unsigned int)((_DWORD)result - 1);
v9 = 48;
v10 = va[0].overflow_arg_area;
result = v7 + 1;
v11 = (__int64)&v7[v8 + 1];
while ( 1 )
{
if ( v9 <= 0xAF )
{
v12 = v9;
v9 += 16;
*v7 = *(_QWORD *)((char *)va[0].reg_save_area + v12);
v7 = result;
if ( result == (_QWORD *)v11 )
return result;
}
else
{
v13 = v10++;
*v7 = *v13;
v7 = result;
if ( result == (_QWORD *)v11 )
return result;
}
++result;
}
}
return result;
}

original_code:
void vSet(Vector *v, ...)
{
   int i;
   va_list ap;
   __builtin_va_start(ap,v);
   for (i = 0; i < v->n_rows; i++) {
      v->row[i] = __builtin_va_arg(ap,double);
   }
   __builtin_va_end(ap);
}

canonical_original_code:
void vSet(struct Vector *v, ...)
{
   int i;
   __builtin_va_list ap;
   __builtin_va_start(ap,v);
   for (i = 0; i < v->n_rows; i++) {
      v->row[i] = __builtin_va_arg(ap,double);
   }
   __builtin_va_end(ap);
}


vSetRow

decompiled_code:
__int64 __fastcall vSetRow(__int64 a1, int a2, double a3)
{
__int64 result; // rax

if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
_assert_fail("row >= 0 && row < v->n_rows", "vector.c", 0x56u, "vSetRow");
result = *(_QWORD *)(a1 + 8);
*(double *)(result + 8LL * a2) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, double a3)
{
__int64 result; // rax

if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
_assert_fail("row >= 0 && row < v->n_rows", "vector.c", 0x56u, "vSetRow");
result = *(_QWORD *)(a1 + 8);
*(double *)(result + 8LL * a2) = a3;
return result;
}

original_code:
void vSetRow(Vector *v, int row, double value)
{
   ((void) sizeof ((row >= 0 && row < v->n_rows) ? 1 : 0), __extension__ ({ if (row >= 0 && row < v->n_rows) ; else __assert_fail ("row >= 0 && row < v->n_rows", "vector.c", 86, __extension__ __PRETTY_FUNCTION__); }));
   v->row[row] = value;
}

canonical_original_code:
void vSetRow(struct Vector *v, int row, double value)
{
   ((void) sizeof ((row >= 0 && row < v->n_rows) ? 1 : 0), __extension__ ({ if (row >= 0 && row < v->n_rows) ; else __assert_fail ("row >= 0 && row < v->n_rows", "vector.c", 86, __extension__ __PRETTY_FUNCTION__); }));
   v->row[row] = value;
}

variable_types: row int

variable_types: value double


vGetRow

decompiled_code:
double __fastcall vGetRow(__int64 a1, int a2)
{
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
_assert_fail("row >= 0 && row < v->n_rows", "vector.c", 0x60u, "vGetRow");
return *(double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, int a2)
{
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
_assert_fail("row >= 0 && row < v->n_rows", "vector.c", 0x60u, "vGetRow");
return *(double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
}

original_code:
double vGetRow(Vector *v, int row)
{
   ((void) sizeof ((row >= 0 && row < v->n_rows) ? 1 : 0), __extension__ ({ if (row >= 0 && row < v->n_rows) ; else __assert_fail ("row >= 0 && row < v->n_rows", "vector.c", 96, __extension__ __PRETTY_FUNCTION__); }));
   return v->row[row];
}

canonical_original_code:
double vGetRow(struct Vector *v, int row)
{
   ((void) sizeof ((row >= 0 && row < v->n_rows) ? 1 : 0), __extension__ ({ if (row >= 0 && row < v->n_rows) ; else __assert_fail ("row >= 0 && row < v->n_rows", "vector.c", 96, __extension__ __PRETTY_FUNCTION__); }));
   return v->row[row];
}


vAdd

decompiled_code:
__int64 __fastcall vAdd(__int64 a1, int *a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 v7; // rdi
__int64 v8; // rsi
__int64 v9; // rcx

v5 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v5 || (_DWORD)v5 != *(_DWORD *)a3 )
_assert_fail("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 0x6Cu, "vAdd");
if ( (int)v5 > 0 )
{
v7 = *((_QWORD *)a2 + 1);
v8 = *(_QWORD *)(a3 + 8);
v9 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v5; ++result )
*(double *)(v9 + 8 * result) = *(double *)(v7 + 8 * result) + *(double *)(v8 + 8 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int *a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 v7; // rdi
__int64 v8; // rsi
__int64 v9; // rcx

v5 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v5 || (_DWORD)v5 != *(_DWORD *)a3 )
_assert_fail("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 0x6Cu, "vAdd");
if ( (int)v5 > 0 )
{
v7 = *((_QWORD *)a2 + 1);
v8 = *(_QWORD *)(a3 + 8);
v9 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v5; ++result )
*(double *)(v9 + 8 * result) = *(double *)(v7 + 8 * result) + *(double *)(v8 + 8 * result);
}
return result;
}

original_code:
void vAdd(Vector *v_out, Vector *v1, Vector *v2)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ; else __assert_fail ("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 108, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v1->n_rows; i++) {
      v_out->row[i] = v1->row[i] + v2->row[i];
   }
}

canonical_original_code:
void vAdd(struct Vector *v_out, struct Vector *v1, struct Vector *v2)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ; else __assert_fail ("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 108, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v1->n_rows; i++) {
      v_out->row[i] = v1->row[i] + v2->row[i];
   }
}


vSub

decompiled_code:
__int64 __fastcall vSub(__int64 a1, int *a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 v7; // rdi
__int64 v8; // rsi
__int64 v9; // rcx

v5 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v5 || (_DWORD)v5 != *(_DWORD *)a3 )
_assert_fail("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 0x7Au, "vSub");
if ( (int)v5 > 0 )
{
v7 = *((_QWORD *)a2 + 1);
v8 = *(_QWORD *)(a3 + 8);
v9 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v5; ++result )
*(double *)(v9 + 8 * result) = *(double *)(v7 + 8 * result) - *(double *)(v8 + 8 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int *a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 v7; // rdi
__int64 v8; // rsi
__int64 v9; // rcx

v5 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v5 || (_DWORD)v5 != *(_DWORD *)a3 )
_assert_fail("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 0x7Au, "vSub");
if ( (int)v5 > 0 )
{
v7 = *((_QWORD *)a2 + 1);
v8 = *(_QWORD *)(a3 + 8);
v9 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v5; ++result )
*(double *)(v9 + 8 * result) = *(double *)(v7 + 8 * result) - *(double *)(v8 + 8 * result);
}
return result;
}

original_code:
void vSub(Vector *v_out, Vector *v1, Vector *v2)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ; else __assert_fail ("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 122, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v1->n_rows; i++) {
      v_out->row[i] = v1->row[i] - v2->row[i];
   }
}

canonical_original_code:
void vSub(struct Vector *v_out, struct Vector *v1, struct Vector *v2)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows) ; else __assert_fail ("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows", "vector.c", 122, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v1->n_rows; i++) {
      v_out->row[i] = v1->row[i] - v2->row[i];
   }
}


vCopy

decompiled_code:
__int64 __fastcall vCopy(__int64 a1, int *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rsi
__int64 v5; // rcx

v3 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v3 )
_assert_fail("v_out->n_rows == v_in->n_rows", "vector.c", 0x89u, "vCopy");
if ( (int)v3 > 0 )
{
v4 = *((_QWORD *)a2 + 1);
v5 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v3; ++result )
*(_QWORD *)(v5 + 8 * result) = *(_QWORD *)(v4 + 8 * result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rsi
__int64 v5; // rcx

v3 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v3 )
_assert_fail("v_out->n_rows == v_in->n_rows", "vector.c", 0x89u, "vCopy");
if ( (int)v3 > 0 )
{
v4 = *((_QWORD *)a2 + 1);
v5 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v3; ++result )
*(_QWORD *)(v5 + 8 * result) = *(_QWORD *)(v4 + 8 * result);
}
return result;
}

original_code:
void vCopy(Vector *v_out, Vector *v_in)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v_in->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v_in->n_rows) ; else __assert_fail ("v_out->n_rows == v_in->n_rows", "vector.c", 137, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v_in->n_rows; i++) {
      v_out->row[i] = v_in->row[i];
   }
}

canonical_original_code:
void vCopy(struct Vector *v_out, struct Vector *v_in)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v_in->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v_in->n_rows) ; else __assert_fail ("v_out->n_rows == v_in->n_rows", "vector.c", 137, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v_in->n_rows; i++) {
      v_out->row[i] = v_in->row[i];
   }
}


vScale

decompiled_code:
__int64 __fastcall vScale(__int64 a1, int *a2, double a3)
{
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rsi
__int64 v6; // rcx

v4 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v4 )
_assert_fail("v_out->n_rows == v_in->n_rows", "vector.c", 0xA3u, "vScale");
if ( (int)v4 > 0 )
{
v5 = *((_QWORD *)a2 + 1);
v6 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v4; ++result )
*(double *)(v6 + 8 * result) = *(double *)(v5 + 8 * result) * a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int *a2, double a3)
{
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rsi
__int64 v6; // rcx

v4 = *a2;
if ( *(_DWORD *)a1 != (_DWORD)v4 )
_assert_fail("v_out->n_rows == v_in->n_rows", "vector.c", 0xA3u, "vScale");
if ( (int)v4 > 0 )
{
v5 = *((_QWORD *)a2 + 1);
v6 = *(_QWORD *)(a1 + 8);
for ( result = 0LL; result != v4; ++result )
*(double *)(v6 + 8 * result) = *(double *)(v5 + 8 * result) * a3;
}
return result;
}

original_code:
void vScale(Vector *v_out, Vector *v_in, double factor)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v_in->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v_in->n_rows) ; else __assert_fail ("v_out->n_rows == v_in->n_rows", "vector.c", 163, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v_in->n_rows; i++) {
      v_out->row[i] = v_in->row[i] * factor;
   }
}

canonical_original_code:
void vScale(struct Vector *v_out, struct Vector *v_in, double factor)
{
   int i;
   ((void) sizeof ((v_out->n_rows == v_in->n_rows) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v_in->n_rows) ; else __assert_fail ("v_out->n_rows == v_in->n_rows", "vector.c", 163, __extension__ __PRETTY_FUNCTION__); }));
   for (i = 0; i < v_in->n_rows; i++) {
      v_out->row[i] = v_in->row[i] * factor;
   }
}

variable_types: factor double


vNorm

decompiled_code:
__int64 __fastcall vNorm(__int64 a1, int *a2, double a3)
{
vLen((__int64)a2);
return vScale(a1, a2, 1.0 / a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int *a2, double a3)
{
func1((__int64)a2);
return func8(a1, a2, 1.0 / a3);
}

original_code:
void vNorm(Vector *v_out, Vector *v_in)
{
   double len = vLen(v_in);
   vScale(v_out, v_in, 1 / len);
}

canonical_original_code:
void vNorm(struct Vector *v_out, struct Vector *v_in)
{
   double len = vLen(v_in);
   vScale(v_out, v_in, 1 / len);
}

variable_types: len double


vCrossP

original_code:
void vCrossP(Vector *v_out, Vector *v1, Vector *v2)
{
   Vector *v_tmp;
   ((void) sizeof ((v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3) ; else __assert_fail ("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3", "vector.c", 207, __extension__ __PRETTY_FUNCTION__); }));
   v_tmp = vNew(v_out->n_rows);
   v_tmp->row[0] = v1->row[1] * v2->row[2] + v1->row[2] * v2->row[1];
   v_tmp->row[1] = v1->row[2] * v2->row[0] + v1->row[0] * v2->row[2];
   v_tmp->row[2] = v1->row[0] * v2->row[1] + v1->row[1] * v2->row[0];
   vCopy(v_out, v_tmp);
   vDel(v_tmp);
}

canonical_original_code:
void vCrossP(struct Vector *v_out, struct Vector *v1, struct Vector *v2)
{
   struct Vector *v_tmp;
   ((void) sizeof ((v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3) ? 1 : 0), __extension__ ({ if (v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3) ; else __assert_fail ("v_out->n_rows == v1->n_rows && v1->n_rows == v2->n_rows && v2->n_rows == 3", "vector.c", 207, __extension__ __PRETTY_FUNCTION__); }));
   v_tmp = vNew(v_out->n_rows);
   v_tmp->row[0] = v1->row[1] * v2->row[2] + v1->row[2] * v2->row[1];
   v_tmp->row[1] = v1->row[2] * v2->row[0] + v1->row[0] * v2->row[2];
   v_tmp->row[2] = v1->row[0] * v2->row[1] + v1->row[1] * v2->row[0];
   vCopy(v_out, v_tmp);
   vDel(v_tmp);
}


decompiled_code:
__int64 __fastcall opt_find_short(__int64 a1, char a2)
{
int i; // ebx
__int64 result; // rax

for ( i = 0; (int)paCount(a1) > i; ++i )
{
result = paGet(a1, (unsigned int)i);
if ( *(_BYTE *)(result + 8) == a2 )
return result;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
int i; // ebx
__int64 result; // rax

for ( i = 0; (int)paCount(a1) > i; ++i )
{
result = paGet(a1, (unsigned int)i);
if ( *(_BYTE *)(result + 8) == a2 )
return result;
}
return 0LL;
}

original_code:
static Option *opt_find_short(Options *options, char short_name)
{
    int i;
    for (i = 0; i < paCount(&options->options); i++) {
        Option *opt = paGet(&options->options, i);
        if (opt->short_name == short_name) return opt;
    }
    return ((void *)0);
}

canonical_original_code:
static struct Option *opt_find_short(struct Options *options, char short_name)
{
    int i;
    for (i = 0; i < paCount(&options->options); i++) {
        struct Option *opt = paGet(&options->options, i);
        if (opt->short_name == short_name) return opt;
    }
    return ((void *)0);
}

variable_types: struct Options { struct PointerArray { int num_ptrs; void **ptr; } options; struct HashList { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } list; struct HashTable { struct List bucket[-1]; } hash; } results; int err; struct Buffer { char *data; unsigned long used; unsigned long size; } errors; } *

variable_types: struct Option { char *long_name; char short_name; enum OPT_Argument { ARG_NONE=0, ARG_OPTIONAL=1, ARG_REQUIRED=2 } argument; } *

user_defined_types: struct Options { struct PointerArray options; struct HashList results; int err; struct Buffer errors; }

user_defined_types: struct Option { char *long_name; char short_name; enum OPT_Argument argument; }

user_defined_types: struct HashList { struct List list; struct HashTable hash; }


decompiled_code:
const char **__fastcall opt_find_long(__int64 a1, const char *a2)
{
int i; // ebx
const char **v3; // r12

for ( i = 0; (int)paCount(a1) > i; ++i )
{
v3 = (const char **)paGet(a1, (unsigned int)i);
if ( !strcmp(*v3, a2) )
return v3;
}
return 0LL;
}

canonical_decompiled_code:
const char **__fastcall func1(__int64 a1, const char *a2)
{
int i; // ebx
const char **v3; // r12

for ( i = 0; (int)paCount(a1) > i; ++i )
{
v3 = (const char **)paGet(a1, (unsigned int)i);
if ( !strcmp(*v3, a2) )
return v3;
}
return 0LL;
}

original_code:
static Option *opt_find_long(Options *options, const char *long_name)
{
    int i;
    for (i = 0; i < paCount(&options->options); i++) {
        Option *opt = paGet(&options->options, i);
        if (strcmp(opt->long_name, long_name) == 0) return opt;
    }
    return ((void *)0);
}

canonical_original_code:
static struct Option *opt_find_long(struct Options *options, char *long_name)
{
    int i;
    for (i = 0; i < paCount(&options->options); i++) {
        struct Option *opt = paGet(&options->options, i);
        if (strcmp(opt->long_name, long_name) == 0) return opt;
    }
    return ((void *)0);
}

variable_types: i int

return_type: struct Option { char *long_name; char short_name; enum OPT_Argument { ARG_NONE=0, ARG_OPTIONAL=1, ARG_REQUIRED=2 } argument; } *

user_defined_types: struct Buffer { char *data; unsigned long used; unsigned long size; }


decompiled_code:
__int64 __fastcall opt_add_result(__int64 a1, const char **a2, char *a3)
{
const char *v4; // r14
size_t v5; // rax
_QWORD *v6; // r12
char *v7; // rax
char *v8; // r14
size_t v9; // rax
__int64 result; // rax

v4 = *a2;
v5 = strlen(*a2);
if ( (unsigned int)hlContains(a1 + 16, v4, v5) )
{
bufAddF(a1 + 98352, "Option '--%s' ", *a2);
if ( *((_BYTE *)a2 + 8) )
bufAddF(a1 + 98352, "or '-%c' ", (unsigned int)*((char *)a2 + 8));
result = bufAddF(a1 + 98352, "given more than once.\n");
*(_DWORD *)(a1 + 98344) = -4;
}
else
{
v6 = calloc(1uLL, 0x28uLL);
if ( a3 )
a3 = strdup(a3);
v6[4] = a3;
v7 = strdup(*a2);
v6[3] = v7;
v8 = v7;
v9 = strlen(v7);
result = hlAdd(a1 + 16, v6, v8, v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char **a2, char *a3)
{
const char *v4; // r14
size_t v5; // rax
_QWORD *v6; // r12
char *v7; // rax
char *v8; // r14
size_t v9; // rax
__int64 result; // rax

v4 = *a2;
v5 = strlen(*a2);
if ( (unsigned int)hlContains(a1 + 16, v4, v5) )
{
bufAddF(a1 + 98352, "Option '--%s' ", *a2);
if ( *((_BYTE *)a2 + 8) )
bufAddF(a1 + 98352, "or '-%c' ", (unsigned int)*((char *)a2 + 8));
result = bufAddF(a1 + 98352, "given more than once.\n");
*(_DWORD *)(a1 + 98344) = -4;
}
else
{
v6 = calloc(1uLL, 0x28uLL);
if ( a3 )
a3 = strdup(a3);
v6[4] = a3;
v7 = strdup(*a2);
v6[3] = v7;
v8 = v7;
v9 = strlen(v7);
result = hlAdd(a1 + 16, v6, v8, v9);
}
return result;
}

original_code:
static void opt_add_result(Options *options,
        const Option *opt, const char *arg)
{
    if (hlContains(&options->results, opt->long_name, strlen(opt->long_name))) {
        bufAddF(&options->errors, "Option '--%s' ", opt->long_name);
        if (opt->short_name != 0) {
            bufAddF(&options->errors, "or '-%c' ", opt->short_name);
        }
        bufAddF(&options->errors, "given more than once.\n");
        options->err = -4;
        return;
    }
    OptionResult *result = calloc(1, sizeof(*result));
    result->arg = arg ? strdup(arg) : ((void *)0);
    result->opt = strdup(opt->long_name);
    _hlAdd((&options->results), &(result)->_node, result->opt, strlen(result->opt));
}

canonical_original_code:
static void opt_add_result(struct Options *options, struct Option *opt, char *arg)
{
    if (hlContains(&options->results, opt->long_name, strlen(opt->long_name))) {
        bufAddF(&options->errors, "Option '--%s' ", opt->long_name);
        if (opt->short_name != 0) {
            bufAddF(&options->errors, "or '-%c' ", opt->short_name);
        }
        bufAddF(&options->errors, "given more than once.\n");
        options->err = -4;
        return;
    }
    struct OptionResult *result = calloc(1, sizeof(*result));
    result->arg = arg ? strdup(arg) : ((void *)0);
    result->opt = strdup(opt->long_name);
    _hlAdd((&options->results), &(result)->_node, result->opt, strlen(result->opt));
}

variable_types:
arg
char *

variable_types: struct OptionResult { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List { struct ListNode *head; struct ListNode *tail; int length; } *list; } _node; char *opt; char *arg; } *

user_defined_types: struct OptionResult { struct ListNode _node; char *opt; char *arg; }

user_defined_types: enum OPT_Argument { ARG_NONE=0, ARG_OPTIONAL=1, ARG_REQUIRED=2 }


optCreate

decompiled_code:
void *optCreate()
{
return calloc(1uLL, 0x18048uLL);
}

canonical_decompiled_code:
void *func3()
{
return calloc(1uLL, 0x18048uLL);
}

original_code:
Options *optCreate(void)
{
    return calloc(1, sizeof(Options));
}

canonical_original_code:
struct Options *optCreate()
{
    return calloc(1, sizeof(Options));
}

return_type: struct Options { struct PointerArray { int num_ptrs; void **ptr; } options; struct HashList { struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } list; struct HashTable { struct List bucket[-1]; } hash; } results; int err; struct Buffer { char *data; unsigned long used; unsigned long size; } errors; } *


optAdd

decompiled_code:
__int64 __fastcall optAdd(__int64 a1, const char *a2, char a3, int a4)
{
__int64 result; // rax
_BYTE *v7; // rax
_BYTE *v8; // r14
unsigned int v9; // eax

if ( opt_find_long(a1, a2) )
{
result = bufAddF(a1 + 98352, "Option '--%s' specified more than once.\n", a2);
*(_DWORD *)(a1 + 98344) = -3;
if ( !a3 )
return result;
goto LABEL_5;
}
if ( a3 )
{
LABEL_5:
if ( opt_find_short(a1, a3) )
{
result = bufAddF(a1 + 98352, "Option '-%c' specified more than once.\n", (unsigned int)a3);
*(_DWORD *)(a1 + 98344) = -3;
return result;
}
}
result = *(unsigned int *)(a1 + 98344);
if ( !(_DWORD)result )
{
v7 = calloc(1uLL, 0x10uLL);
*(_QWORD *)v7 = a2;
v8 = v7;
v7[8] = a3;
*((_DWORD *)v7 + 3) = a4;
v9 = paCount(a1);
result = paSet(a1, v9, v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, char a3, int a4)
{
__int64 result; // rax
_BYTE *v7; // rax
_BYTE *v8; // r14
unsigned int v9; // eax

if ( func1(a1, a2) )
{
result = bufAddF(a1 + 98352, "Option '--%s' specified more than once.\n", a2);
*(_DWORD *)(a1 + 98344) = -3;
if ( !a3 )
return result;
goto LABEL_5;
}
if ( a3 )
{
LABEL_5:
if ( func0(a1, a3) )
{
result = bufAddF(a1 + 98352, "Option '-%c' specified more than once.\n", (unsigned int)a3);
*(_DWORD *)(a1 + 98344) = -3;
return result;
}
}
result = *(unsigned int *)(a1 + 98344);
if ( !(_DWORD)result )
{
v7 = calloc(1uLL, 0x10uLL);
*(_QWORD *)v7 = a2;
v8 = v7;
v7[8] = a3;
*((_DWORD *)v7 + 3) = a4;
v9 = paCount(a1);
result = paSet(a1, v9, v8);
}
return result;
}

original_code:
void optAdd(Options *options,
        const char *long_name, char short_name, OPT_Argument argument)
{
    if (opt_find_long(options, long_name) != ((void *)0)) {
        bufAddF(&options->errors, "Option '--%s' specified more than once.\n",
                long_name);
        options->err = -3;
    }
    if (short_name != 0 && opt_find_short(options, short_name) != ((void *)0)) {
        bufAddF(&options->errors, "Option '-%c' specified more than once.\n",
                short_name);
        options->err = -3;
    }
    if (options->err != 0) return;
    Option *option = calloc(1, sizeof(Option));
    option->long_name = long_name;
    option->short_name = short_name;
    option->argument = argument;
    paSet(&options->options, paCount(&options->options), option);
}

canonical_original_code:
void optAdd(struct Options *options, char *long_name, char short_name, enum OPT_Argument argument)
{
    if (opt_find_long(options, long_name) != ((void *)0)) {
        bufAddF(&options->errors, "Option '--%s' specified more than once.\n",
                long_name);
        options->err = -3;
    }
    if (short_name != 0 && opt_find_short(options, short_name) != ((void *)0)) {
        bufAddF(&options->errors, "Option '-%c' specified more than once.\n",
                short_name);
        options->err = -3;
    }
    if (options->err != 0) return;
    struct Option *option = calloc(1, sizeof(Option));
    option->long_name = long_name;
    option->short_name = short_name;
    option->argument = argument;
    paSet(&options->options, paCount(&options->options), option);
}

variable_types: enum OPT_Argument { ARG_NONE=0, ARG_OPTIONAL=1, ARG_REQUIRED=2 }


optParse

decompiled_code:
__int64 __fastcall optParse(__int64 a1, int a2, char *const *a3)
{
unsigned int v3; // er15
int v6; // eax
struct option *v7; // r13
struct option *v8; // rbx
__int64 v9; // rdx
const char *v10; // rax
__int64 v11; // rsi
int v12; // eax
const char **v13; // rax
const char *v14; // rax
int v15; // eax
__int64 v16; // [rsp+0h] [rbp-78h]
int longind; // [rsp+1Ch] [rbp-5Ch] BYREF
__int128 v19; // [rsp+20h] [rbp-58h] BYREF
__int64 v20; // [rsp+30h] [rbp-48h]

v3 = *(_DWORD *)(a1 + 98344);
v20 = 0LL;
v19 = 0LL;
if ( !v3 )
{
v6 = paCount(a1);
v7 = (struct option *)calloc(v6 + 1, 0x20uLL);
bufAddC(&v19, 58LL);
v8 = v7;
while ( (int)paCount(a1) > (int)v3 )
{
v9 = paGet(a1, v3);
v10 = *(const char **)v9;
v8->flag = 0LL;
v16 = v9;
v8->name = v10;
v11 = (unsigned int)*(char *)(v9 + 8);
v8->val = v11;
bufAddC(&v19, v11);
v12 = *(_DWORD *)(v16 + 12);
if ( v12 )
{
if ( v12 == 2 )
{
v8->has_arg = 1;
bufAddS(&v19, ":");
}
else if ( v12 == 1 )
{
v8->has_arg = 2;
bufAddS(&v19, "::");
}
}
else
{
v8->has_arg = 0;
}
++v3;
++v8;
}
optind = 1;
while ( 1 )
{
longind = 0;
v14 = (const char *)bufGet(&v19);
v15 = getopt_long(a2, a3, v14, v7, &longind);
if ( v15 == -1 )
break;
if ( v15 == 63 )
{
bufAddF(a1 + 98352, "Unknown option or argument in \"%s\".\n", a3[optind - 1]);
bufClear(&v19);
free(v7);
v3 = *(_DWORD *)(a1 + 98344);
if ( !v3 )
v3 = -1;
return v3;
}
if ( v15 == 58 )
{
bufAddF(a1 + 98352, "Missing argument for \"%s\".\n", a3[optind - 1]);
bufClear(&v19);
free(v7);
v3 = *(_DWORD *)(a1 + 98344);
if ( !v3 )
v3 = -2;
return v3;
}
if ( v15 )
v13 = (const char **)opt_find_short(a1, v15);
else
v13 = opt_find_long(a1, v7[longind].name);
opt_add_result(a1, v13, optarg);
}
bufClear(&v19);
free(v7);
v3 = *(_DWORD *)(a1 + 98344);
if ( !v3 )
v3 = optind;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2, char *const *a3)
{
unsigned int v3; // er15
int v6; // eax
struct option *v7; // r13
struct option *v8; // rbx
__int64 v9; // rdx
const char *v10; // rax
__int64 v11; // rsi
int v12; // eax
const char **v13; // rax
const char *v14; // rax
int v15; // eax
__int64 v16; // [rsp+0h] [rbp-78h]
int longind; // [rsp+1Ch] [rbp-5Ch] BYREF
__int128 v19; // [rsp+20h] [rbp-58h] BYREF
__int64 v20; // [rsp+30h] [rbp-48h]

v3 = *(_DWORD *)(a1 + 98344);
v20 = 0LL;
v19 = 0LL;
if ( !v3 )
{
v6 = paCount(a1);
v7 = (struct option *)calloc(v6 + 1, 0x20uLL);
bufAddC(&v19, 58LL);
v8 = v7;
while ( (int)paCount(a1) > (int)v3 )
{
v9 = paGet(a1, v3);
v10 = *(const char **)v9;
v8->flag = 0LL;
v16 = v9;
v8->name = v10;
v11 = (unsigned int)*(char *)(v9 + 8);
v8->val = v11;
bufAddC(&v19, v11);
v12 = *(_DWORD *)(v16 + 12);
if ( v12 )
{
if ( v12 == 2 )
{
v8->has_arg = 1;
bufAddS(&v19, ":");
}
else if ( v12 == 1 )
{
v8->has_arg = 2;
bufAddS(&v19, "::");
}
}
else
{
v8->has_arg = 0;
}
++v3;
++v8;
}
optind = 1;
while ( 1 )
{
longind = 0;
v14 = (const char *)bufGet(&v19);
v15 = getopt_long(a2, a3, v14, v7, &longind);
if ( v15 == -1 )
break;
if ( v15 == 63 )
{
bufAddF(a1 + 98352, "Unknown option or argument in \"%s\".\n", a3[optind - 1]);
bufClear(&v19);
free(v7);
v3 = *(_DWORD *)(a1 + 98344);
if ( !v3 )
v3 = -1;
return v3;
}
if ( v15 == 58 )
{
bufAddF(a1 + 98352, "Missing argument for \"%s\".\n", a3[optind - 1]);
bufClear(&v19);
free(v7);
v3 = *(_DWORD *)(a1 + 98344);
if ( !v3 )
v3 = -2;
return v3;
}
if ( v15 )
v13 = (const char **)func0(a1, v15);
else
v13 = func1(a1, v7[longind].name);
func2(a1, v13, optarg);
}
bufClear(&v19);
free(v7);
v3 = *(_DWORD *)(a1 + 98344);
if ( !v3 )
v3 = optind;
}
return v3;
}

original_code:
int optParse(Options *options, int argc, char *argv[])
{
    Buffer opt_string = { 0 };
    int i, c;
    if (options->err != 0) return options->err;
    struct option *long_options =
        calloc(paCount(&options->options) + 1, sizeof(struct option));
    bufAddC(&opt_string, ':');
    for (i = 0; i < paCount(&options->options); i++ ) {
        Option *opt = paGet(&options->options, i);
        long_options[i].name = opt->long_name;
        long_options[i].flag = ((void *)0);
        long_options[i].val = opt->short_name;
        bufAddC(&opt_string, opt->short_name);
        if (opt->argument == ARG_NONE) {
            long_options[i].has_arg = 0;
        }
        else if (opt->argument == ARG_REQUIRED) {
            long_options[i].has_arg = 1;
            bufAddS(&opt_string, ":");
        }
        else if (opt->argument == ARG_OPTIONAL) {
            long_options[i].has_arg = 2;
            bufAddS(&opt_string, "::");
        }
    }
    optind = 1;
    while (1) {
        Option *opt;
        int option_index = 0;
        c = getopt_long(argc, argv, bufGet(&opt_string),
                long_options, &option_index);
        if (c == -1) {
            break;
        }
        else if (c == '?') {
            bufAddF(&options->errors,
                    "Unknown option or argument in \"%s\".\n",
                    argv[optind - 1]);
            break;
        }
        else if (c == ':') {
            bufAddF(&options->errors,
                    "Missing argument for \"%s\".\n", argv[optind - 1]);
            break;
        }
        else if (c == 0) {
            opt = opt_find_long(options, long_options[option_index].name);
            opt_add_result(options, opt, optarg);
        }
        else {
            opt = opt_find_short(options, c);
            opt_add_result(options, opt, optarg);
        }
    }
    bufClear(&opt_string);
    free(long_options);
    if (options->err != 0) {
        return options->err;
    }
    else if (c == -1)
        return optind;
    else if (c == '?')
        return -1;
    else if (c == ':')
        return -2;
    else
        _dbgAbort(stderr, "options.c", 247, __func__, "Unexpected return value for getopt_long.\n");
}

canonical_original_code:
int optParse(struct Options *options, int argc, char *argv[])
{
    struct Buffer opt_string = { 0 };
    int i; int c;
    if (options->err != 0) return options->err;
    struct option *long_options = calloc(paCount(&options->options) + 1, sizeof(struct option));
    bufAddC(&opt_string, ':');
    for (i = 0; i < paCount(&options->options); i++ ) {
        struct Option *opt = paGet(&options->options, i);
        long_options[i].name = opt->long_name;
        long_options[i].flag = ((void *)0);
        long_options[i].val = opt->short_name;
        bufAddC(&opt_string, opt->short_name);
        if (opt->argument == ARG_NONE) {
            long_options[i].has_arg = 0;
        }
        else if (opt->argument == ARG_REQUIRED) {
            long_options[i].has_arg = 1;
            bufAddS(&opt_string, ":");
        }
        else if (opt->argument == ARG_OPTIONAL) {
            long_options[i].has_arg = 2;
            bufAddS(&opt_string, "::");
        }
    }
    optind = 1;
    while (1) {
        struct Option *opt;
        int option_index = 0;
        c = getopt_long(argc, argv, bufGet(&opt_string),
                long_options, &option_index);
        if (c == -1) {
            break;
        }
        else if (c == '?') {
            bufAddF(&options->errors,
                    "Unknown option or argument in \"%s\".\n",
                    argv[optind - 1]);
            break;
        }
        else if (c == ':') {
            bufAddF(&options->errors,
                    "Missing argument for \"%s\".\n", argv[optind - 1]);
            break;
        }
        else if (c == 0) {
            opt = opt_find_long(options, long_options[option_index].name);
            opt_add_result(options, opt, optarg);
        }
        else {
            opt = opt_find_short(options, c);
            opt_add_result(options, opt, optarg);
        }
    }
    bufClear(&opt_string);
    free(long_options);
    if (options->err != 0) {
        return options->err;
    }
    else if (c == -1)
        return optind;
    else if (c == '?')
        return -1;
    else if (c == ':')
        return -2;
    else
        _dbgAbort(stderr, "options.c", 247, __func__, "Unexpected return value for getopt_long.\n");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct Buffer { char *data; unsigned long used; unsigned long size; }

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *


optErrors

decompiled_code:
__int64 __fastcall optErrors(__int64 a1)
{
return bufGet(a1 + 98352);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return bufGet(a1 + 98352);
}

original_code:
const char *optErrors(const Options *options)
{
    return bufGet(&options->errors);
}

canonical_original_code:
char *optErrors(struct Options *options)
{
    return bufGet(&options->errors);
}

return_type: char *


optIsSet

decompiled_code:
__int64 __fastcall optIsSet(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return hlContains(a1 + 16, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return hlContains(a1 + 16, a2, v2);
}

original_code:
int optIsSet(const Options *options, const char *long_name)
{
    return hlContains(&options->results, long_name, strlen(long_name));
}

canonical_original_code:
int optIsSet(struct Options *options, char *long_name)
{
    return hlContains(&options->results, long_name, strlen(long_name));
}


optArg

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

v4 = strlen(a2);
v5 = hlGet(a1 + 16, a2, v4);
result = a3;
if ( v5 )
{
result = *(_QWORD *)(v5 + 32);
if ( !result )
result = a3;
}
return result;
}

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

v4 = strlen(a2);
v5 = hlGet(a1 + 16, a2, v4);
result = a3;
if ( v5 )
{
result = *(_QWORD *)(v5 + 32);
if ( !result )
result = a3;
}
return result;
}

original_code:
const char *optArg(Options *options, const char *long_name,
        const char *fallback)
{
    OptionResult *result = hlGet(&options->results, long_name, strlen(long_name));
    return (result && result->arg) ? result->arg : fallback;
}

canonical_original_code:
char *optArg(struct Options *options, char *long_name, char *fallback)
{
    struct OptionResult *result = hlGet(&options->results, long_name, strlen(long_name));
    return (result && result->arg) ? result->arg : fallback;
}

variable_types:
fallback
char *


optClear

decompiled_code:
__int64 __fastcall optClear(__int64 a1)
{
int i; // ebx
__int64 v2; // rsi
void *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // r14
size_t v8; // rax

for ( i = 0; (int)paCount(a1) > i; ++i )
{
v2 = (unsigned int)i;
v3 = (void *)paGet(a1, v2);
free(v3);
}
v4 = hlHead(a1 + 16);
while ( v4 )
{
v5 = v4;
v6 = hlNext(v4);
v7 = *(_QWORD *)(v4 + 24);
v4 = v6;
v8 = strlen(*(const char **)(v5 + 24));
hlDel(a1 + 16, v7, v8);
free(*(void **)(v5 + 32));
free(*(void **)(v5 + 24));
free((void *)v5);
}
return paClear(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int i; // ebx
__int64 v2; // rsi
void *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rax
__int64 v7; // r14
size_t v8; // rax

for ( i = 0; (int)paCount(a1) > i; ++i )
{
v2 = (unsigned int)i;
v3 = (void *)paGet(a1, v2);
free(v3);
}
v4 = hlHead(a1 + 16);
while ( v4 )
{
v5 = v4;
v6 = hlNext(v4);
v7 = *(_QWORD *)(v4 + 24);
v4 = v6;
v8 = strlen(*(const char **)(v5 + 24));
hlDel(a1 + 16, v7, v8);
free(*(void **)(v5 + 32));
free(*(void **)(v5 + 24));
free((void *)v5);
}
return paClear(a1);
}

original_code:
void optClear(Options *options)
{
    int i;
    OptionResult *result, *next;
    for (i = 0; i < paCount(&options->options); i++) {
        Option *opt = paGet(&options->options, i);
        free(opt);
    }
    for (result = hlHead(&options->results); result; result = next) {
        next = _hlNext(&(result)->_node);
        hlDel(&options->results, result->opt, strlen(result->opt));
        free(result->arg);
        free(result->opt);
        free(result);
    }
    paClear(&options->options);
}

canonical_original_code:
void optClear(struct Options *options)
{
    int i;
    struct OptionResult *result; struct OptionResult *next;
    for (i = 0; i < paCount(&options->options); i++) {
        struct Option *opt = paGet(&options->options, i);
        free(opt);
    }
    for (result = hlHead(&options->results); result; result = next) {
        next = _hlNext(&(result)->_node);
        hlDel(&options->results, result->opt, strlen(result->opt));
        free(result->arg);
        free(result->opt);
        free(result);
    }
    paClear(&options->options);
}


optDestroy

decompiled_code:
void __fastcall optDestroy(void *ptr)
{
optClear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
func9((__int64)ptr);
free(ptr);
}

original_code:
void optDestroy(Options *options)
{
    optClear(options);
    free(options);
}

canonical_original_code:
void optDestroy(struct Options *options)
{
    optClear(options);
    free(options);
}


netHost

decompiled_code:
char *__fastcall netHost(unsigned int a1)
{
struct hostent *v1; // rax
char *result; // rax
unsigned int addr; // [rsp+Ch] [rbp-Ch] BYREF

addr = a1;
if ( a1 )
{
v1 = gethostbyaddr(&addr, 4u, 2);
if ( v1 )
{
result = v1->h_name;
}
else
{
snprintf(text_buffer_0, 0x10uLL, "%d.%d.%d.%d", HIBYTE(addr), BYTE2(addr), BYTE1(addr), (unsigned __int8)addr);
result = text_buffer_0;
}
}
else
{
strcpy(text_buffer_0, "0.0.0.0");
result = text_buffer_0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1)
{
struct hostent *v1; // rax
char *result; // rax
unsigned int addr; // [rsp+Ch] [rbp-Ch] BYREF

addr = a1;
if ( a1 )
{
v1 = gethostbyaddr(&addr, 4u, 2);
if ( v1 )
{
result = v1->h_name;
}
else
{
snprintf(text_buffer_0, 0x10uLL, "%d.%d.%d.%d", HIBYTE(addr), BYTE2(addr), BYTE1(addr), (unsigned __int8)addr);
result = text_buffer_0;
}
}
else
{
strcpy(text_buffer_0, "0.0.0.0");
result = text_buffer_0;
}
return result;
}

original_code:
const char *netHost(uint32_t big_endian_ip)
{
    static char text_buffer[16];
    struct hostent *ent;
    if (big_endian_ip == 0) {
        snprintf(text_buffer, sizeof(text_buffer), "0.0.0.0");
        return text_buffer;
    }
    else if ((ent = gethostbyaddr((char *) &big_endian_ip,
                    sizeof(big_endian_ip), 2)) == ((void *)0))
    {
        snprintf(text_buffer, sizeof(text_buffer), "%d.%d.%d.%d",
                 (big_endian_ip & 0xFF000000) >> 24,
                 (big_endian_ip & 0x00FF0000) >> 16,
                 (big_endian_ip & 0x0000FF00) >> 8,
                 (big_endian_ip & 0x000000FF));
        return text_buffer;
    }
    else {
        return ent->h_name;
    }
}

canonical_original_code:
char *netHost(unsigned int big_endian_ip)
{
    static char text_buffer[16];
    struct hostent *ent;
    if (big_endian_ip == 0) {
        snprintf(text_buffer, sizeof(text_buffer), "0.0.0.0");
        return text_buffer;
    }
    else if ((ent = gethostbyaddr((char *) &big_endian_ip,
                    sizeof(big_endian_ip), 2)) == ((void *)0))
    {
        snprintf(text_buffer, sizeof(text_buffer), "%d.%d.%d.%d",
                 (big_endian_ip & 0xFF000000) >> 24,
                 (big_endian_ip & 0x00FF0000) >> 16,
                 (big_endian_ip & 0x0000FF00) >> 8,
                 (big_endian_ip & 0x000000FF));
        return text_buffer;
    }
    else {
        return ent->h_name;
    }
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


netPort

decompiled_code:
__int64 __fastcall netPort(const char *a1, const char *a2)
{
struct servent *v2; // rax
__int64 result; // rax

v2 = getservbyname(a1, a2);
if ( v2 )
result = LOWORD(v2->s_port);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
struct servent *v2; // rax
__int64 result; // rax

v2 = getservbyname(a1, a2);
if ( v2 )
result = LOWORD(v2->s_port);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
uint16_t netPort(const char *service, const char *protocol)
{
    struct servent *serv_ptr;
    serv_ptr = getservbyname(service, protocol);
    if (serv_ptr == ((void *)0)) {
        if (0) _dbgError(stderr, "net.c", 63, __func__, "getservbyname(%s) failed", service);
        return -1;
    }
    return serv_ptr->s_port;
}

canonical_original_code:
unsigned short netPort(char *service, char *protocol)
{
    struct servent *serv_ptr;
    serv_ptr = getservbyname(service, protocol);
    if (serv_ptr == ((void *)0)) {
        if (0) _dbgError(stderr, "net.c", 63, __func__, "getservbyname(%s) failed", service);
        return -1;
    }
    return serv_ptr->s_port;
}

variable_types:
service
char *

variable_types:
protocol
char *

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *


netPeerHost

decompiled_code:
char *__fastcall netPeerHost(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getpeername(a1, &addr, &len);
return netHost(*(unsigned int *)&addr.sa_data[2]);
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getpeername(a1, &addr, &len);
return func1(*(unsigned int *)&addr.sa_data[2]);
}

original_code:
const char *netPeerHost(int sd)
{
    struct sockaddr_in peeraddr;
    socklen_t len = sizeof(struct sockaddr_in);
    getpeername(sd, (struct sockaddr *) &peeraddr, &len);
    return netHost(peeraddr.sin_addr.s_addr);
}

canonical_original_code:
char *netPeerHost(int sd)
{
    struct sockaddr_in peeraddr;
    unsigned int len = sizeof(struct sockaddr_in);
    getpeername(sd, (struct sockaddr *) &peeraddr, &len);
    return netHost(peeraddr.sin_addr.s_addr);
}

variable_types: sd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
len
unsigned int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


netPeerPort

decompiled_code:
__int64 __fastcall netPeerPort(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getpeername(a1, &addr, &len);
return *(unsigned __int16 *)addr.sa_data;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getpeername(a1, &addr, &len);
return *(unsigned __int16 *)addr.sa_data;
}

original_code:
uint16_t netPeerPort(int sd)
{
    struct sockaddr_in peeraddr;
    socklen_t len = sizeof(struct sockaddr_in);
    getpeername(sd, (struct sockaddr *) &peeraddr, &len);
    return peeraddr.sin_port;
}

canonical_original_code:
unsigned short netPeerPort(int sd)
{
    struct sockaddr_in peeraddr;
    unsigned int len = sizeof(struct sockaddr_in);
    getpeername(sd, (struct sockaddr *) &peeraddr, &len);
    return peeraddr.sin_port;
}


netLocalHost

decompiled_code:
char *__fastcall netLocalHost(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(a1, &addr, &len);
return netHost(*(unsigned int *)&addr.sa_data[2]);
}

canonical_decompiled_code:
char *__fastcall func5(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(a1, &addr, &len);
return func1(*(unsigned int *)&addr.sa_data[2]);
}

original_code:
const char *netLocalHost(int sd)
{
    struct sockaddr_in sockaddr;
    socklen_t len = sizeof(struct sockaddr_in);
    getsockname(sd, (struct sockaddr *) &sockaddr, &len);
    return netHost(sockaddr.sin_addr.s_addr);
}

canonical_original_code:
char *netLocalHost(int sd)
{
    struct sockaddr_in sockaddr;
    unsigned int len = sizeof(struct sockaddr_in);
    getsockname(sd, (struct sockaddr *) &sockaddr, &len);
    return netHost(sockaddr.sin_addr.s_addr);
}


netLocalPort

decompiled_code:
__int16 __fastcall netLocalPort(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(a1, &addr, &len);
return _bswap_16(*(__int16 *)addr.sa_data);
}

canonical_decompiled_code:
__int16 __fastcall func6(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
getsockname(a1, &addr, &len);
return func0(*(__int16 *)addr.sa_data);
}

original_code:
uint16_t netLocalPort(int sd)
{
    struct sockaddr_in peeraddr;
    socklen_t len = sizeof(struct sockaddr_in);
    getsockname(sd, (struct sockaddr *) &peeraddr, &len);
    return ntohs(peeraddr.sin_port);
}

canonical_original_code:
unsigned short netLocalPort(int sd)
{
    struct sockaddr_in peeraddr;
    unsigned int len = sizeof(struct sockaddr_in);
    getsockname(sd, (struct sockaddr *) &peeraddr, &len);
    return ntohs(peeraddr.sin_port);
}


disCreate

decompiled_code:
void *disCreate()
{
return calloc(1uLL, 0x38uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x38uLL);
}

original_code:
Dispatcher *disCreate(void)
{
    return calloc(1, sizeof(Dispatcher));
}

canonical_original_code:
struct Dispatcher *disCreate()
{
    return calloc(1, sizeof(Dispatcher));
}

return_type: struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } *

user_defined_types: struct Dispatcher { struct PointerArray files; struct List timers; struct timeval tv; }


disInit

original_code:
void disInit(Dispatcher *dis)
{
    memset(dis, 0, sizeof(Dispatcher));
}

canonical_original_code:
void disInit(struct Dispatcher *dis)
{
    memset(dis, 0, sizeof(Dispatcher));
}

variable_types: struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } *


disDropData

decompiled_code:
__int64 __fastcall disDropData(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 89LL, "disDropData", "unknown file descriptor: %d\n", (unsigned int)a2);
return paDrop(a1, (unsigned int)a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = paGet(a1, a2);
dbgAssert(stderr, v2 != 0, "dis.c", 89LL, "disDropData", "unknown file descriptor: %d\n", (unsigned int)a2);
return paDrop(a1, (unsigned int)a2);
}

original_code:
void disDropData(Dispatcher *dis, int fd)
{
    DIS_File *file = paGet(&dis->files, fd);
    if (0) _dbgPrint(stderr, "dis.c", 87, __func__, "Dropping fd %d\n", fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 89, __func__, "unknown file descriptor: %d\n", fd);
    paDrop(&dis->files, fd);
}

canonical_original_code:
void disDropData(struct Dispatcher *dis, int fd)
{
    struct DIS_File *file = paGet(&dis->files, fd);
    if (0) _dbgPrint(stderr, "dis.c", 87, __func__, "Dropping fd %d\n", fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 89, __func__, "unknown file descriptor: %d\n", fd);
    paDrop(&dis->files, fd);
}

variable_types: fd int

variable_types: struct DIS_File { struct Buffer { char *data; unsigned long used; unsigned long size; } outgoing; void (*cb)(struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } *dis, int fd, void *udata); void *udata; } *

user_defined_types: struct DIS_File { struct Buffer outgoing; void (*cb)(struct Dispatcher *dis, int fd, void *udata); void *udata; }


disWrite

decompiled_code:
__int64 __fastcall disWrite(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbp

v6 = paGet(a1, a2);
dbgAssert(stderr, v6 != 0, "dis.c", 105LL, "disWrite", "unknown file descriptor: %d\n", (unsigned int)a2);
return bufAdd(v6, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rbp

v6 = paGet(a1, a2);
dbgAssert(stderr, v6 != 0, "dis.c", 105LL, "disWrite", "unknown file descriptor: %d\n", (unsigned int)a2);
return bufAdd(v6, a3, a4);
}

original_code:
void disWrite(Dispatcher *dis, int fd, const char *data, size_t size)
{
    DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 105, __func__, "unknown file descriptor: %d\n", fd);
    bufAdd(&file->outgoing, data, size);
}

canonical_original_code:
void disWrite(struct Dispatcher *dis, int fd, char *data, unsigned long size)
{
    struct DIS_File *file = paGet(&dis->files, fd);
    _dbgAssert(stderr, file != ((void *)0), "dis.c", 105, __func__, "unknown file descriptor: %d\n", fd);
    bufAdd(&file->outgoing, data, size);
}

variable_types:
data
char *

variable_types:
size
unsigned long

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


disVaPack

decompiled_code:
void __fastcall disVaPack(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = vastrpack(&ptr, a3);
disWrite(a1, a2, (__int64)ptr, v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
int v3; // eax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = vastrpack(&ptr, a3);
func4(a1, a2, (__int64)ptr, v3);
free(ptr);
}

original_code:
void disVaPack(Dispatcher *dis, int fd, va_list ap)
{
    char *str;
    int n = vastrpack(&str, ap);
    disWrite(dis, fd, str, n);
    free(str);
}

canonical_original_code:
void disVaPack(struct Dispatcher *dis, int fd, __builtin_va_list ap)
{
    char *str;
    int n = vastrpack(&str, ap);
    disWrite(dis, fd, str, n);
    free(str);
}

variable_types:
str
char *

variable_types: n int


disPack

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

va_start(va, a2);
disVaPack(a1, a2, (__int64)va);
}

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

va_start(va, a2);
func5(a1, a2, (__int64)va);
}

original_code:
void disPack(Dispatcher *dis, int fd, ...)
{
    va_list ap;
    __builtin_va_start(ap,fd);
    disVaPack(dis, fd, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void disPack(struct Dispatcher *dis, int fd, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fd);
    disVaPack(dis, fd, ap);
    __builtin_va_end(ap);
}


disOnTime

decompiled_code:
__int64 __fastcall disOnTime(__int64 a1, __int64 a2, __int64 a3, double a4)
{
__int64 v4; // r12
double *v6; // rax
double *v7; // rbp
__int64 v8; // rdi

v4 = a1 + 16;
v6 = (double *)calloc(1uLL, 0x30uLL);
*((_QWORD *)v6 + 4) = a2;
v7 = v6;
*((_QWORD *)v6 + 5) = a3;
v6[3] = a4;
v8 = listHead(a1 + 16);
if ( v8 )
{
while ( *(double *)(v8 + 24) <= v7[3] )
{
v8 = listNext();
if ( !v8 )
goto LABEL_6;
}
}
else
{
LABEL_6:
v8 = 0LL;
}
return listInsert(v4, v7, v8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, double a4)
{
__int64 v4; // r12
double *v6; // rax
double *v7; // rbp
__int64 v8; // rdi

v4 = a1 + 16;
v6 = (double *)calloc(1uLL, 0x30uLL);
*((_QWORD *)v6 + 4) = a2;
v7 = v6;
*((_QWORD *)v6 + 5) = a3;
v6[3] = a4;
v8 = listHead(a1 + 16);
if ( v8 )
{
while ( *(double *)(v8 + 24) <= v7[3] )
{
v8 = listNext();
if ( !v8 )
goto LABEL_6;
}
}
else
{
LABEL_6:
v8 = 0LL;
}
return listInsert(v4, v7, v8);
}

original_code:
void disOnTime(Dispatcher *dis, double t, void (*cb)(Dispatcher *dis, double t, void *udata), const void *udata)
{
    DIS_Timer *next_timer, *new_timer = calloc(1, sizeof(DIS_Timer));
    new_timer->t = t;
    new_timer->cb = cb;
    new_timer->udata = udata;
    for (next_timer = listHead(&dis->timers); next_timer;
         next_timer = _listNext(&(next_timer)->_node))
    {
        if (next_timer->t > new_timer->t) break;
    }
    _listInsert((&dis->timers), &(new_timer)->_node, &(next_timer)->_node);
}

canonical_original_code:
void disOnTime(struct Dispatcher *dis, double t, void (*cb)(struct Dispatcher *dis, double t, void *udata), void *udata)
{
    struct DIS_Timer *next_timer; struct DIS_Timer *new_timer = calloc(1, sizeof(DIS_Timer));
    new_timer->t = t;
    new_timer->cb = cb;
    new_timer->udata = udata;
    for (next_timer = listHead(&dis->timers); next_timer;
         next_timer = _listNext(&(next_timer)->_node))
    {
        if (next_timer->t > new_timer->t) break;
    }
    _listInsert((&dis->timers), &(new_timer)->_node, &(next_timer)->_node);
}

variable_types: t double

variable_types: void (*)(struct Dispatcher *dis, double t, void *udata)

variable_types:
udata
void *

variable_types: struct DIS_Timer { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List { struct ListNode *head; struct ListNode *tail; int length; } *list; } _node; double t; void (*cb)(struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List timers; struct timeval { long tv_sec; long tv_usec; } tv; } *dis, double t, void *udata); void *udata; } *

user_defined_types: struct DIS_Timer { struct ListNode _node; double t; void (*cb)(struct Dispatcher *dis, double t, void *udata); void *udata; }


disDropTime

decompiled_code:
void __fastcall disDropTime(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rax
__int64 v4; // rbp

v3 = listHead(a1 + 16);
if ( v3 )
{
v4 = v3;
while ( a3 != *(double *)(v4 + 24) || *(_QWORD *)(v4 + 32) != a2 )
{
v4 = listNext(v4);
if ( !v4 )
goto LABEL_7;
}
listRemove(a1 + 16, v4, a3, a3);
free((void *)v4);
}
else
{
LABEL_7:
dbgAbort(stderr, "dis.c", 177LL, "disDropTime", "no such timer\n");
disFdCount();
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // rax
__int64 v4; // rbp

v3 = listHead(a1 + 16);
if ( v3 )
{
v4 = v3;
while ( a3 != *(double *)(v4 + 24) || *(_QWORD *)(v4 + 32) != a2 )
{
v4 = listNext(v4);
if ( !v4 )
goto LABEL_7;
}
listRemove(a1 + 16, v4, a3, a3);
free((void *)v4);
}
else
{
LABEL_7:
dbgAbort(stderr, "dis.c", 177LL, "disDropTime", "no such timer\n");
func9();
}
}

original_code:
void disDropTime(Dispatcher *dis, double t,
        void (*cb)(Dispatcher *dis, double t, void *udata))
{
    DIS_Timer *timer;
    for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        if (timer->t == t && timer->cb == cb) {
            _listRemove((&dis->timers), &(timer)->_node);
            free(timer);
            return;
        }
    }
    _dbgAbort(stderr, "dis.c", 177, __func__, "no such timer\n");
}

canonical_original_code:
void disDropTime(struct Dispatcher *dis, double t, void (*cb)(struct Dispatcher *dis, double t, void *udata))
{
    struct DIS_Timer *timer;
    for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        if (timer->t == t && timer->cb == cb) {
            _listRemove((&dis->timers), &(timer)->_node);
            free(timer);
            return;
        }
    }
    _dbgAbort(stderr, "dis.c", 177, __func__, "no such timer\n");
}

user_defined_types: struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; }


disFdCount

decompiled_code:
// attributes: thunk
__int64 disFdCount(void)
{
return paCount();
}

canonical_decompiled_code:
__int64 func9(void)
{
return paCount();
}

original_code:
int disFdCount(Dispatcher *dis)
{
    return paCount(&dis->files);
}

canonical_original_code:
int disFdCount(struct Dispatcher *dis)
{
    return paCount(&dis->files);
}


disOwnsFd

decompiled_code:
_BOOL8 __fastcall disOwnsFd(__int64 a1, __int64 a2)
{
return paGet(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, __int64 a2)
{
return paGet(a1, a2) != 0;
}

original_code:
int disOwnsFd(Dispatcher *dis, int fd)
{
    return (paGet(&dis->files, fd) != ((void *)0));
}

canonical_original_code:
int disOwnsFd(struct Dispatcher *dis, int fd)
{
    return (paGet(&dis->files, fd) != ((void *)0));
}


disPrepareSelect

original_code:
int disPrepareSelect(Dispatcher *dis, int *nfds, fd_set *rfds, fd_set *wfds,
        struct timeval **tv)
{
    int fd;
    double delta_t;
    DIS_Timer *timer;
    *nfds = paCount(&dis->files);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((rfds)->fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wfds)->fds_bits)[0]) : "memory"); } while (0);
    if (0) _dbgPrint(stderr, "dis.c", 220, __func__, "File descriptors:");
    for (fd = 0; fd < *nfds; fd++) {
        DIS_File *file = paGet(&dis->files, fd);
        if (file == ((void *)0)) continue;
        if (0) fprintf(stderr, " %d", fd);
        ((void) (((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (bufLen(&file->outgoing) > 0) ((void) (((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (0) {
            fprintf(stderr, " (%s%s)",
                    ((((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "r" : "",
                    ((((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "w" : "");
        }
    }
    if (0) fprintf(stderr, "\n");
    if (0) _dbgPrint(stderr, "dis.c", 242, __func__, "%d pending timers:\n", listLength(&dis->timers));
    if (0) for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        fprintf(stderr, "\t%f seconds\n", timer->t - dnow());
    }
    if ((timer = listHead(&dis->timers)) == ((void *)0)) {
        *tv = ((void *)0);
    }
    else if ((delta_t = timer->t - dnow()) < 0) {
        dis->tv.tv_sec = 0;
        dis->tv.tv_usec = 0;
        *tv = &dis->tv;
    }
    else {
        if (0) _dbgPrint(stderr, "dis.c", 263, __func__, "First timer in %f seconds.\n", delta_t);
        dis->tv.tv_sec = (int) delta_t;
        dis->tv.tv_usec = 1000000 * fmod(delta_t, 1.0);
        *tv = &dis->tv;
    }
    return 0;
}

canonical_original_code:
int disPrepareSelect(struct Dispatcher *dis, int *nfds, struct fd_set *rfds, struct fd_set *wfds, struct timeval **tv)
{
    int fd;
    double delta_t;
    struct DIS_Timer *timer;
    *nfds = paCount(&dis->files);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((rfds)->fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((wfds)->fds_bits)[0]) : "memory"); } while (0);
    if (0) _dbgPrint(stderr, "dis.c", 220, __func__, "File descriptors:");
    for (fd = 0; fd < *nfds; fd++) {
        struct DIS_File *file = paGet(&dis->files, fd);
        if (file == ((void *)0)) continue;
        if (0) fprintf(stderr, " %d", fd);
        ((void) (((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (bufLen(&file->outgoing) > 0) ((void) (((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))));
        if (0) {
            fprintf(stderr, " (%s%s)",
                    ((((rfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "r" : "",
                    ((((wfds)->fds_bits)[((fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fd) % (8 * (int) sizeof (__fd_mask)))))) != 0) ? "w" : "");
        }
    }
    if (0) fprintf(stderr, "\n");
    if (0) _dbgPrint(stderr, "dis.c", 242, __func__, "%d pending timers:\n", listLength(&dis->timers));
    if (0) for (timer = listHead(&dis->timers); timer; timer = _listNext(&(timer)->_node)) {
        fprintf(stderr, "\t%f seconds\n", timer->t - dnow());
    }
    if ((timer = listHead(&dis->timers)) == ((void *)0)) {
        *tv = ((void *)0);
    }
    else if ((delta_t = timer->t - dnow()) < 0) {
        dis->tv.tv_sec = 0;
        dis->tv.tv_usec = 0;
        *tv = &dis->tv;
    }
    else {
        if (0) _dbgPrint(stderr, "dis.c", 263, __func__, "First timer in %f seconds.\n", delta_t);
        dis->tv.tv_sec = (int) delta_t;
        dis->tv.tv_usec = 1000000 * fmod(delta_t, 1.0);
        *tv = &dis->tv;
    }
    return 0;
}

variable_types:
nfds
int *

variable_types:
rfds
struct fd_set { long fds_bits[-1]; } *

variable_types:
wfds
struct fd_set *

variable_types:
tv
struct timeval **


disHandleTimer

decompiled_code:
void __fastcall disHandleTimer(__int64 a1)
{
__int64 v1; // rbp

v1 = listRemoveHead(a1 + 16);
dbgAssert(stderr, v1 != 0, "dis.c", 281LL, "disHandleTimer", "no pending timer.\n");
(*(void (__fastcall **)(__int64, _QWORD, double))(v1 + 32))(a1, *(_QWORD *)(v1 + 40), *(double *)(v1 + 24));
free((void *)v1);
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
__int64 v1; // rbp

v1 = listRemoveHead(a1 + 16);
dbgAssert(stderr, v1 != 0, "dis.c", 281LL, "disHandleTimer", "no pending timer.\n");
(*(void (__fastcall **)(__int64, _QWORD, double))(v1 + 32))(a1, *(_QWORD *)(v1 + 40), *(double *)(v1 + 24));
free((void *)v1);
}

original_code:
void disHandleTimer(Dispatcher *dis)
{
    DIS_Timer *timer = listRemoveHead(&dis->timers);
    _dbgAssert(stderr, timer != ((void *)0), "dis.c", 281, __func__, "no pending timer.\n");
    timer->cb(dis, timer->t, (void *) timer->udata);
    free(timer);
}

canonical_original_code:
void disHandleTimer(struct Dispatcher *dis)
{
    struct DIS_Timer *timer = listRemoveHead(&dis->timers);
    _dbgAssert(stderr, timer != ((void *)0), "dis.c", 281, __func__, "no pending timer.\n");
    timer->cb(dis, timer->t, (void *) timer->udata);
    free(timer);
}