decompiled_code:
__int64 __fastcall ndn_digest_size(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

original_code:
size_t
ndn_digest_size(struct ndn_digest *d)
{
    return(d->sz);
}

canonical_original_code:
unsigned long ndn_digest_size(struct ndn_digest *d)
{
    return(d->sz);
}

user_defined_types: enum ndn_digest_id { NDN_DIGEST_DEFAULT=0, NDN_DIGEST_SHA1=1, NDN_DIGEST_SHA224=2, NDN_DIGEST_SHA256=3, NDN_DIGEST_SHA384=4, NDN_DIGEST_SHA512=5 }

user_defined_types: struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; }


repo: danihegglin/ChronosAndroid

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

SHA256_Init(a1 + 8);
result = 1LL;
*(_WORD *)(a1 + 6) = 1;
return result;
}

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

SHA256_Init(a1 + 8);
result = 1LL;
*(_WORD *)(a1 + 6) = 1;
return result;
}

original_code:
void
ndn_digest_init(struct ndn_digest *d)
{
    SHA256_Init(&d->sha256_ctx);
    d->ready = 1;
}

variable_types: struct ndn_digest { enum ndn_digest_id { NDN_DIGEST_DEFAULT=0, NDN_DIGEST_SHA1=1, NDN_DIGEST_SHA224=2, NDN_DIGEST_SHA256=3, NDN_DIGEST_SHA384=4, NDN_DIGEST_SHA512=5 } id; unsigned short sz; short ready; struct SHA256state_st { unsigned int h[8]; unsigned int Nl; unsigned int data[16]; unsigned int num; } sha256_ctx; } *

return_type: void

user_defined_types: struct ndn_digest { enum ndn_digest_id id; unsigned short sz; short ready; struct SHA256state_st sha256_ctx; }


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

if ( *(_WORD *)(a1 + 6) == 1 )
result = (unsigned int)-((unsigned int)SHA256_Update(a1 + 8) != 1);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( *(_WORD *)(a1 + 6) == 1 )
result = (unsigned int)-((unsigned int)SHA256_Update(a1 + 8) != 1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
ndn_digest_update(struct ndn_digest *d, const void *data, size_t size)
{
    int res;
    if (d->ready != 1)
        return(-1);
    res = SHA256_Update(&d->sha256_ctx, data, size);
    return((res == 1) ? 0 : -1);
}

canonical_original_code:
int ndn_digest_update(struct ndn_digest *d, void *data, unsigned long size)
{
    int res;
    if (d->ready != 1)
        return(-1);
    res = SHA256_Update(&d->sha256_ctx, data, size);
    return((res == 1) ? 0 : -1);
}

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types: res int

return_type: int


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

if ( *(unsigned __int16 *)(a1 + 4) != a3 || *(_WORD *)(a1 + 6) != 1 )
return 0xFFFFFFFFLL;
v3 = SHA256_Final(a2, a1 + 8);
*(_WORD *)(a1 + 6) = 0;
return (unsigned int)-(v3 != 1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax

if ( *(unsigned __int16 *)(a1 + 4) != a3 || *(_WORD *)(a1 + 6) != 1 )
return 0xFFFFFFFFLL;
v3 = SHA256_Final(a2, a1 + 8);
*(_WORD *)(a1 + 6) = 0;
return (unsigned int)-(v3 != 1);
}

original_code:
int
ndn_digest_final(struct ndn_digest *d, unsigned char *result, size_t digest_size)
{
    int res;
    if (digest_size != d->sz) return(-1);
    if (d->ready != 1)
        return(-1);
    res = SHA256_Final(result, &d->sha256_ctx);
    d->ready = 0;
    return((res == 1) ? 0 : -1);
}

canonical_original_code:
int ndn_digest_final(struct ndn_digest *d, unsigned char *result, unsigned long digest_size)
{
    int res;
    if (digest_size != d->sz) return(-1);
    if (d->ready != 1)
        return(-1);
    res = SHA256_Final(result, &d->sha256_ctx);
    d->ready = 0;
    return((res == 1) ? 0 : -1);
}

variable_types:
result
unsigned char *


decompiled_code:
void *ndn_charbuf_create()
{
return calloc(1uLL, 0x18uLL);
}

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

original_code:
struct ndn_charbuf *
ndn_charbuf_create(void)
{
    struct ndn_charbuf *c;
    c = calloc(1, sizeof(*c));
    return(c);
}

canonical_original_code:
struct ndn_charbuf *ndn_charbuf_create()
{
    struct ndn_charbuf *c;
    c = calloc(1, sizeof(*c));
    return(c);
}

variable_types: struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *


decompiled_code:
void __fastcall ndn_charbuf_destroy(_QWORD **a1)
{
_QWORD *v1; // rbp
void *v3; // rdi

v1 = *a1;
if ( *a1 )
{
v3 = (void *)v1[2];
if ( v3 )
free(v3);
free(v1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD **a1)
{
_QWORD *v1; // rbp
void *v3; // rdi

v1 = *a1;
if ( *a1 )
{
v3 = (void *)v1[2];
if ( v3 )
free(v3);
free(v1);
*a1 = 0LL;
}
}

original_code:
void
ndn_charbuf_destroy(struct ndn_charbuf **cbp)
{
    struct ndn_charbuf *c = *cbp;
    if (c != ((void *)0)) {
        if (c->buf != ((void *)0))
            free(c->buf);
        free(c);
        *cbp = ((void *)0);
    }
}

variable_types: struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } **


original_code:
unsigned char *
ndn_charbuf_reserve(struct ndn_charbuf *c, size_t n)
{
    size_t newsz = n + c->length;
    unsigned char *buf = c->buf;
    if (newsz < n)
        return(((void *)0));
    if (newsz > c->limit) {
        if (2 * c->limit > newsz)
            newsz = 2 * c->limit;
        buf = realloc(c->buf, newsz);
        if (buf == ((void *)0))
            return(((void *)0));
        memset(buf + c->limit, 0, newsz - c->limit);
        c->buf = buf;
        c->limit = newsz;
    }
    buf += c->length;
    return(buf);
}

canonical_original_code:
unsigned char *ndn_charbuf_reserve(struct ndn_charbuf *c, unsigned long n)
{
    unsigned long newsz = n + c->length;
    unsigned char *buf = c->buf;
    if (newsz < n)
        return(((void *)0));
    if (newsz > c->limit) {
        if (2 * c->limit > newsz)
            newsz = 2 * c->limit;
        buf = realloc(c->buf, newsz);
        if (buf == ((void *)0))
            return(((void *)0));
        memset(buf + c->limit, 0, newsz - c->limit);
        c->buf = buf;
        c->limit = newsz;
    }
    buf += c->length;
    return(buf);
}

variable_types:
n
unsigned long

variable_types:
newsz
unsigned long

variable_types:
buf
unsigned char *

return_type: unsigned char *

user_defined_types: struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; }


decompiled_code:
__int64 __fastcall ndn_charbuf_append(_QWORD *a1, const void *a2, size_t a3)
{
char *v4; // rax

v4 = ndn_charbuf_reserve(a1, a3);
if ( !v4 )
return 0xFFFFFFFFLL;
memcpy(v4, a2, a3);
*a1 += a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, const void *a2, size_t a3)
{
char *v4; // rax

v4 = func2(a1, a3);
if ( !v4 )
return 0xFFFFFFFFLL;
memcpy(v4, a2, a3);
*a1 += a3;
return 0LL;
}

original_code:
int
ndn_charbuf_append(struct ndn_charbuf *c, const void *p, size_t n)
{
    unsigned char *dst = ndn_charbuf_reserve(c, n);
    if (dst == ((void *)0))
        return(-1);
    memcpy(dst, p, n);
    c->length += n;
    return(0);
}

canonical_original_code:
int ndn_charbuf_append(struct ndn_charbuf *c, void *p, unsigned long n)
{
    unsigned char *dst = ndn_charbuf_reserve(c, n);
    if (dst == ((void *)0))
        return(-1);
    memcpy(dst, p, n);
    c->length += n;
    return(0);
}

variable_types:
p
void *

variable_types:
dst
unsigned char *


decompiled_code:
__int64 __fastcall ndn_charbuf_append_value(_QWORD *a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // r13
char *v5; // rax
int v6; // ecx
unsigned int v7; // edx

if ( a3 > 4 )
return 0xFFFFFFFFLL;
v3 = a3;
v5 = ndn_charbuf_reserve(a1, a3);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = 8 * a3 - 8;
if ( a3 )
{
do
{
++v5;
v7 = a2 >> v6;
v6 -= 8;
*(v5 - 1) = v7;
}
while ( v6 != -8 );
}
*a1 += v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // r13
char *v5; // rax
int v6; // ecx
unsigned int v7; // edx

if ( a3 > 4 )
return 0xFFFFFFFFLL;
v3 = a3;
v5 = func2(a1, a3);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = 8 * a3 - 8;
if ( a3 )
{
do
{
++v5;
v7 = a2 >> v6;
v6 -= 8;
*(v5 - 1) = v7;
}
while ( v6 != -8 );
}
*a1 += v3;
return 0LL;
}

original_code:
int
ndn_charbuf_append_value(struct ndn_charbuf *c, unsigned val, unsigned n)
{
    unsigned char *dst;
    unsigned i;
    if (n > sizeof(val))
        return(-1);
    dst = ndn_charbuf_reserve(c, n);
    if (dst == ((void *)0))
        return(-1);
    for (i = 0; i < n; i++)
        dst[i] = (unsigned char)(val >> (8 * (n-1-i)));
    c->length += n;
    return(0);
}

canonical_original_code:
int ndn_charbuf_append_value(struct ndn_charbuf *c, unsigned int val, unsigned int n)
{
    unsigned char *dst;
    unsigned int i;
    if (n > sizeof(val))
        return(-1);
    dst = ndn_charbuf_reserve(c, n);
    if (dst == ((void *)0))
        return(-1);
    for (i = 0; i < n; i++)
        dst[i] = (unsigned char)(val >> (8 * (n-1-i)));
    c->length += n;
    return(0);
}

variable_types:
val
unsigned int

variable_types:
n
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall ndn_charbuf_append_charbuf(_QWORD *a1, __int64 a2)
{
return ndn_charbuf_append(a1, *(const void **)(a2 + 16), *(_QWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
return func4(a1, *(const void **)(a2 + 16), *(_QWORD *)a2);
}

original_code:
int
ndn_charbuf_append_charbuf(struct ndn_charbuf *c, const struct ndn_charbuf *in)
{
  return(ndn_charbuf_append(c, in->buf, in->length));
}

canonical_original_code:
int ndn_charbuf_append_charbuf(struct ndn_charbuf *c, struct ndn_charbuf *in)
{
  return(ndn_charbuf_append(c, in->buf, in->length));
}

variable_types:
in
struct ndn_charbuf *


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

v2 = strlen(a2);
return ndn_charbuf_append(a1, a2, v2);
}

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

v2 = strlen(a2);
return func4(a1, a2, v2);
}

original_code:
int
ndn_charbuf_append_string(struct ndn_charbuf *c, const char *s)
{
  return(ndn_charbuf_append(c, s, strlen(s)));
}

canonical_original_code:
int ndn_charbuf_append_string(struct ndn_charbuf *c, char *s)
{
  return(ndn_charbuf_append(c, s, strlen(s)));
}

variable_types:
s
char *


decompiled_code:
int ndn_charbuf_putf(unsigned __int64 *a1, const char *a2, ...)
{
size_t v4; // rax
char *v5; // rdi
unsigned __int64 v6; // rsi
int result; // eax
unsigned __int64 v8; // rdx
char *v9; // rdi
size_t v10; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v4 = strlen(a2);
v5 = ndn_charbuf_reserve(a1, v4 + 10);
if ( !v5 )
return -1;
v6 = a1[1];
va_start(arg, a2);
result = vsnprintf(v5, v6 - *a1, a2, arg);
if ( result >= 0 )
{
v8 = *a1 + result;
if ( v8 >= a1[1] )
{
v9 = ndn_charbuf_reserve(a1, result + 1);
if ( !v9 )
return -1;
v10 = a1[1] - *a1;
va_end(arg);
va_start(arg, a2);
result = vsnprintf(v9, v10, a2, arg);
v8 = *a1 + result;
if ( v8 >= a1[1] )
return -1;
}
*a1 = v8;
}
return result;
}

canonical_decompiled_code:
int func8(unsigned __int64 *a1, const char *a2, ...)
{
size_t v4; // rax
char *v5; // rdi
unsigned __int64 v6; // rsi
int result; // eax
unsigned __int64 v8; // rdx
char *v9; // rdi
size_t v10; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v4 = strlen(a2);
v5 = func2(a1, v4 + 10);
if ( !v5 )
return -1;
v6 = a1[1];
va_start(arg, a2);
result = vsnprintf(v5, v6 - *a1, a2, arg);
if ( result >= 0 )
{
v8 = *a1 + result;
if ( v8 >= a1[1] )
{
v9 = func2(a1, result + 1);
if ( !v9 )
return -1;
v10 = a1[1] - *a1;
va_end(arg);
va_start(arg, a2);
result = vsnprintf(v9, v10, a2, arg);
v8 = *a1 + result;
if ( v8 >= a1[1] )
return -1;
}
*a1 = v8;
}
return result;
}

original_code:
int
ndn_charbuf_putf(struct ndn_charbuf *c, const char *fmt, ...)
{
    int sz;
    va_list ap;
    char *buf;
    buf = (char *)ndn_charbuf_reserve(c, strlen(fmt) + 10);
    if (buf == ((void *)0)) return(-1);
    __builtin_va_start(ap,fmt);
    sz = vsnprintf(buf, c->limit - c->length, fmt, ap);
    __builtin_va_end(ap);
    if (sz < 0)
        return(sz);
    if (c->length + sz < c->limit) {
        c->length += sz;
        return(sz);
    }
    buf = (char *)ndn_charbuf_reserve(c, sz + 1);
    if (buf == ((void *)0)) return(-1);
    __builtin_va_start(ap,fmt);
    sz = vsnprintf(buf, c->limit - c->length, fmt, ap);
    __builtin_va_end(ap);
    if (c->length + sz < c->limit) {
        c->length += sz;
        return(sz);
    }
    return(-1);
}

canonical_original_code:
int ndn_charbuf_putf(struct ndn_charbuf *c, char *fmt, ...)
{
    int sz;
    __builtin_va_list ap;
    char *buf;
    buf = (char *)ndn_charbuf_reserve(c, strlen(fmt) + 10);
    if (buf == ((void *)0)) return(-1);
    __builtin_va_start(ap,fmt);
    sz = vsnprintf(buf, c->limit - c->length, fmt, ap);
    __builtin_va_end(ap);
    if (sz < 0)
        return(sz);
    if (c->length + sz < c->limit) {
        c->length += sz;
        return(sz);
    }
    buf = (char *)ndn_charbuf_reserve(c, sz + 1);
    if (buf == ((void *)0)) return(-1);
    __builtin_va_start(ap,fmt);
    sz = vsnprintf(buf, c->limit - c->length, fmt, ap);
    __builtin_va_end(ap);
    if (c->length + sz < c->limit) {
        c->length += sz;
        return(sz);
    }
    return(-1);
}

variable_types:
fmt
char *

variable_types: sz int

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall ndn_charbuf_append_datetime(_QWORD *a1, time_t a2, unsigned int a3)
{
struct tm *v4; // rax
unsigned int v5; // eax
unsigned int v6; // edx
unsigned int v7; // ebx
__int64 v8; // rax
time_t timer; // [rsp+8h] [rbp-90h] BYREF
char s[32]; // [rsp+10h] [rbp-88h] BYREF
struct tm tp; // [rsp+30h] [rbp-68h] BYREF

timer = a2;
v4 = gmtime_r(&timer, &tp);
v5 = strftime(s, 0x20uLL, "%FT%T", v4);
if ( v5 <= 0x1F )
{
v6 = v5;
if ( !a3 )
{
LABEL_7:
s[v6] = 90;
return ndn_charbuf_append(a1, s, (int)(v6 + 1));
}
if ( a3 <= 0x3B9AC9FF )
{
v7 = v5;
snprintf(&s[v5], 32LL - (int)v5, ".%09d", a3);
LODWORD(v8) = v7 + 10;
if ( v7 + 10 <= 0x1F )
{
v8 = (int)v8;
do
v6 = v8--;
while ( s[v8] == 48 );
goto LABEL_7;
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, time_t a2, unsigned int a3)
{
struct tm *v4; // rax
unsigned int v5; // eax
unsigned int v6; // edx
unsigned int v7; // ebx
__int64 v8; // rax
time_t timer; // [rsp+8h] [rbp-90h] BYREF
char s[32]; // [rsp+10h] [rbp-88h] BYREF
struct tm tp; // [rsp+30h] [rbp-68h] BYREF

timer = a2;
v4 = gmtime_r(&timer, &tp);
v5 = strftime(s, 0x20uLL, "%FT%T", v4);
if ( v5 <= 0x1F )
{
v6 = v5;
if ( !a3 )
{
LABEL_7:
s[v6] = 90;
return func4(a1, s, (int)(v6 + 1));
}
if ( a3 <= 0x3B9AC9FF )
{
v7 = v5;
snprintf(&s[v5], 32LL - (int)v5, ".%09d", a3);
LODWORD(v8) = v7 + 10;
if ( v7 + 10 <= 0x1F )
{
v8 = (int)v8;
do
v6 = v8--;
while ( s[v8] == 48 );
goto LABEL_7;
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int
ndn_charbuf_append_datetime(struct ndn_charbuf *c, time_t secs, int nsecs)
{
    char timestring[32];
    int timelen;
    struct tm time_tm;
    int res;
    timelen = strftime(timestring, sizeof(timestring),
                       "%FT%T", gmtime_r(&secs, &time_tm));
    if (timelen >= sizeof(timestring))
        return(-1);
    if (nsecs != 0) {
        if (nsecs < 0 || nsecs >= 1000000000)
            return(-1);
        timelen += snprintf(&timestring[timelen], sizeof(timestring) - timelen,
                            ".%09d", nsecs);
        if (timelen >= sizeof(timestring))
            return(-1);
        while (timestring[timelen - 1] == '0') timelen--;
    }
    timestring[timelen++] = 'Z';
    res = ndn_charbuf_append(c, timestring, timelen);
    return (res);
}

canonical_original_code:
int ndn_charbuf_append_datetime(struct ndn_charbuf *c, long secs, int nsecs)
{
    char timestring[32];
    int timelen;
    struct tm time_tm;
    int res;
    timelen = strftime(timestring, sizeof(timestring),
                       "%FT%T", gmtime_r(&secs, &time_tm));
    if (timelen >= sizeof(timestring))
        return(-1);
    if (nsecs != 0) {
        if (nsecs < 0 || nsecs >= 1000000000)
            return(-1);
        timelen += snprintf(&timestring[timelen], sizeof(timestring) - timelen,
                            ".%09d", nsecs);
        if (timelen >= sizeof(timestring))
            return(-1);
        while (timestring[timelen - 1] == '0') timelen--;
    }
    timestring[timelen++] = 'Z';
    res = ndn_charbuf_append(c, timestring, timelen);
    return (res);
}

variable_types: secs long

variable_types: nsecs int

variable_types:
timestring
char [32]

variable_types: timelen int

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: res int


decompiled_code:
char *__fastcall ndn_charbuf_as_string(_QWORD *a1)
{
char *result; // rax

result = ndn_charbuf_reserve(a1, 1LL);
if ( result )
{
*result = 0;
result = (char *)a1[2];
}
return result;
}

canonical_decompiled_code:
char *__fastcall func10(_QWORD *a1)
{
char *result; // rax

result = func2(a1, 1LL);
if ( result )
{
*result = 0;
result = (char *)a1[2];
}
return result;
}

original_code:
char *
ndn_charbuf_as_string(struct ndn_charbuf *c)
{
    unsigned char *r;
    r = ndn_charbuf_reserve(c, 1);
    if (r == ((void *)0))
        return(((void *)0));
    r[0] = 0;
    return((char *)c->buf);
}

canonical_original_code:
char *ndn_charbuf_as_string(struct ndn_charbuf *c)
{
    unsigned char *r;
    r = ndn_charbuf_reserve(c, 1);
    if (r == ((void *)0))
        return(((void *)0));
    r[0] = 0;
    return((char *)c->buf);
}

variable_types: struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *

variable_types:
r
unsigned char *

return_type: char *


decompiled_code:
__int64 __fastcall qsort_compare_dict_indices(const void *a1, const void *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = *((_QWORD *)a2 + 1);
if ( !*((_QWORD *)a1 + 1) )
return v2 != 0;
if ( !v2 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
result = 2 * (unsigned int)(*(_DWORD *)a1 >= *(_DWORD *)a2) - 1;
return result;
}

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

v2 = *((_QWORD *)a2 + 1);
if ( !*((_QWORD *)a1 + 1) )
return v2 != 0;
if ( !v2 )
return 0xFFFFFFFFLL;
result = 0LL;
if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
result = 2 * (unsigned int)(*(_DWORD *)a1 >= *(_DWORD *)a2) - 1;
return result;
}

original_code:
static int
qsort_compare_dict_indices(const void *x, const void *y)
{
    const struct ndn_dict_entry *ex = x;
    const struct ndn_dict_entry *ey = y;
    if (ex->name == ((void *)0))
        return ((ey->name == ((void *)0)) ? 0 : 1);
    if (ey->name == ((void *)0)) return (-1);
    if (ex->index == ey->index) return (0);
    return ((ex->index < ey->index) ? -1 : 1);
}

canonical_original_code:
static int qsort_compare_dict_indices(void *x, void *y)
{
    struct ndn_dict_entry *ex = x;
    struct ndn_dict_entry *ey = y;
    if (ex->name == ((void *)0))
        return ((ey->name == ((void *)0)) ? 0 : 1);
    if (ey->name == ((void *)0)) return (-1);
    if (ex->index == ey->index) return (0);
    return ((ex->index < ey->index) ? -1 : 1);
}

variable_types:
x
void *

variable_types:
y
void *

variable_types: struct ndn_dict_entry { int index; char *name; } *


decompiled_code:
int __fastcall qsort_compare_dict_names(const void *a1, const void *a2)
{
return strcmp(*((const char **)a1 + 1), *((const char **)a2 + 1));
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2)
{
return strcmp(*((const char **)a1 + 1), *((const char **)a2 + 1));
}

original_code:
static int
qsort_compare_dict_names(const void *x, const void *y)
{
    const struct ndn_dict_entry *ex = x;
    const struct ndn_dict_entry *ey = y;
    return (strcmp(ex->name, ey->name));
}

canonical_original_code:
static int qsort_compare_dict_names(void *x, void *y)
{
    struct ndn_dict_entry *ex = x;
    struct ndn_dict_entry *ey = y;
    return (strcmp(ex->name, ey->name));
}

user_defined_types: struct ndn_dict_entry { int index; char *name; }


original_code:
void
ndn_destroy_dict(struct ndn_dict **dp)
{
    struct ndn_dict *d = *dp;
    int i;
    if (d != ((void *)0)) {
        for (i = 0; i < d->count; i++) {
            if (d->dict[i].name != ((void *)0))
                free((void *)d->dict[i].name);
        }
        free(d);
    }
    *dp = ((void *)0);
}

variable_types: struct ndn_dict { int count; struct ndn_dict_entry { int index; char *name; } *dict; } **

variable_types: i int

user_defined_types: struct ndn_dict { int count; struct ndn_dict_entry *dict; }


decompiled_code:
int __fastcall ndn_setup_sockaddr_un(char *nptr, __int64 a2)
{
const char *v2; // r12
char *v3; // rbp
char *v4; // rax
int v5; // er13
int result; // eax

v2 = "/tmp/.ndnd.sock";
v3 = nptr;
v4 = getenv("NDN_LOCAL_SOCKNAME");
if ( v4 )
{
v2 = v4;
if ( !*v4 )
v2 = "/tmp/.ndnd.sock";
}
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 102) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 110) >> 3));
*(_WORD *)a2 = 1;
if ( (nptr && *nptr || (v3 = getenv("NDN_LOCAL_PORT")) != 0LL) && (v5 = atoi(v3), v5 > 0) && v5 != atoi("6363") )
result = snprintf((char *)(a2 + 2), 0x6CuLL, "%s.%s", v2, v3);
else
result = snprintf((char *)(a2 + 2), 0x6CuLL, "%s", v2);
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *nptr, __int64 a2)
{
const char *v2; // r12
char *v3; // rbp
char *v4; // rax
int v5; // er13
int result; // eax

v2 = "/tmp/.ndnd.sock";
v3 = nptr;
v4 = getenv("NDN_LOCAL_SOCKNAME");
if ( v4 )
{
v2 = v4;
if ( !*v4 )
v2 = "/tmp/.ndnd.sock";
}
*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 102) = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 110) >> 3));
*(_WORD *)a2 = 1;
if ( (nptr && *nptr || (v3 = getenv("NDN_LOCAL_PORT")) != 0LL) && (v5 = atoi(v3), v5 > 0) && v5 != atoi("6363") )
result = snprintf((char *)(a2 + 2), 0x6CuLL, "%s.%s", v2, v3);
else
result = snprintf((char *)(a2 + 2), 0x6CuLL, "%s", v2);
return result;
}

original_code:
void
ndn_setup_sockaddr_un(const char *portstr, struct sockaddr_un *result)
{
    struct sockaddr_un *sa = result;
    const char *sockname = getenv("NDN_LOCAL_SOCKNAME");
    if (sockname == ((void *)0) || sockname[0] == 0)
        sockname = "/tmp/.ndnd.sock";
    memset(sa, 0, sizeof(*sa));
    sa->sun_family = 1;
    if (portstr == ((void *)0) || portstr[0] == 0)
        portstr = getenv("NDN_LOCAL_PORT");
    if (portstr != ((void *)0) && atoi(portstr) > 0 &&
          atoi(portstr) != atoi("6363"))
        snprintf(sa->sun_path, sizeof(sa->sun_path), "%s.%s",
                 sockname, portstr);
    else
        snprintf(sa->sun_path, sizeof(sa->sun_path), "%s",
                 sockname);
}

canonical_original_code:
void ndn_setup_sockaddr_un(char *portstr, struct sockaddr_un *result)
{
    struct sockaddr_un *sa = result;
    char *sockname = getenv("NDN_LOCAL_SOCKNAME");
    if (sockname == ((void *)0) || sockname[0] == 0)
        sockname = "/tmp/.ndnd.sock";
    memset(sa, 0, sizeof(*sa));
    sa->sun_family = 1;
    if (portstr == ((void *)0) || portstr[0] == 0)
        portstr = getenv("NDN_LOCAL_PORT");
    if (portstr != ((void *)0) && atoi(portstr) > 0 &&
          atoi(portstr) != atoi("6363"))
        snprintf(sa->sun_path, sizeof(sa->sun_path), "%s.%s",
                 sockname, portstr);
    else
        snprintf(sa->sun_path, sizeof(sa->sun_path), "%s",
                 sockname);
}

variable_types:
portstr
char *

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

variable_types:
sockname
char *


decompiled_code:
__int64 __fastcall ndn_setup_sockaddr_in(const char *a1, void *a2, unsigned int a3)
{
char *v4; // r12
char *v5; // rax
bool v6; // zf
const char *v7; // rbp
int v8; // eax
struct addrinfo *v9; // rbp
unsigned int v10; // er14
size_t v11; // rdx
char *v13; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-58h] BYREF

pai = 0LL;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v4 = strdup(a1);
v5 = strchr(v4, 58);
if ( !v5 || (v6 = v5[1] == 0, *v5 = 0, v7 = v5 + 1, v6) )
{
v13 = getenv("NDN_LOCAL_PORT");
v7 = v13;
if ( v13 )
{
if ( !*v13 )
v7 = "6363";
}
else
{
v7 = "6363";
}
}
memset(a2, 0, (int)a3);
req.ai_family = 0;
if ( !strcasecmp(v4, "tcp6") )
req.ai_family = 10;
if ( !strcasecmp(v4, "tcp4") )
req.ai_family = 2;
req.ai_flags = 32;
*(_QWORD *)&req.ai_socktype = 1LL;
v8 = getaddrinfo(0LL, v7, &req, &pai);
v9 = pai;
v10 = v8;
if ( v8 || (v11 = pai->ai_addrlen, (unsigned int)v11 > a3) )
v10 = -1;
else
memcpy(a2, pai->ai_addr, v11);
free(v4);
freeaddrinfo(v9);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, void *a2, unsigned int a3)
{
char *v4; // r12
char *v5; // rax
bool v6; // zf
const char *v7; // rbp
int v8; // eax
struct addrinfo *v9; // rbp
unsigned int v10; // er14
size_t v11; // rdx
char *v13; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-58h] BYREF

pai = 0LL;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v4 = strdup(a1);
v5 = strchr(v4, 58);
if ( !v5 || (v6 = v5[1] == 0, *v5 = 0, v7 = v5 + 1, v6) )
{
v13 = getenv("NDN_LOCAL_PORT");
v7 = v13;
if ( v13 )
{
if ( !*v13 )
v7 = "6363";
}
else
{
v7 = "6363";
}
}
memset(a2, 0, (int)a3);
req.ai_family = 0;
if ( !strcasecmp(v4, "tcp6") )
req.ai_family = 10;
if ( !strcasecmp(v4, "tcp4") )
req.ai_family = 2;
req.ai_flags = 32;
*(_QWORD *)&req.ai_socktype = 1LL;
v8 = getaddrinfo(0LL, v7, &req, &pai);
v9 = pai;
v10 = v8;
if ( v8 || (v11 = pai->ai_addrlen, (unsigned int)v11 > a3) )
v10 = -1;
else
memcpy(a2, pai->ai_addr, v11);
free(v4);
freeaddrinfo(v9);
return v10;
}

original_code:
int
ndn_setup_sockaddr_in(const char *name, struct sockaddr *result, int length)
{
    struct addrinfo hints = {0};
    struct addrinfo *ai = ((void *)0);
    char *port;
    char *nameonly = strdup(name);
    int ans = -1;
    int res;
    port = strchr(nameonly, ':');
    if (port)
        *port++ = 0;
    if (port == ((void *)0) || port[0] == 0)
        port = getenv("NDN_LOCAL_PORT");
    if (port == ((void *)0) || port[0] == 0)
        port = "6363";
    memset(result, 0, length);
    hints.ai_family = 0;
    if (strcasecmp(nameonly, "tcp6") == 0) hints.ai_family = 10;
    if (strcasecmp(nameonly, "tcp4") == 0) hints.ai_family = 2;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0020;
    hints.ai_protocol = 0;
    res = getaddrinfo(((void *)0), port, &hints, &ai);
    if (res != 0 || ai->ai_addrlen > length)
        goto Bail;
    memcpy(result, ai->ai_addr, ai->ai_addrlen);
    ans = 0;
Bail:
    free(nameonly);
    freeaddrinfo(ai);
    return (ans);
}

canonical_original_code:
int ndn_setup_sockaddr_in(char *name, struct sockaddr *result, int length)
{
    struct addrinfo hints = {0};
    struct addrinfo *ai = ((void *)0);
    char *port;
    char *nameonly = strdup(name);
    int ans = -1;
    int res;
    port = strchr(nameonly, ':');
    if (port)
        *port++ = 0;
    if (port == ((void *)0) || port[0] == 0)
        port = getenv("NDN_LOCAL_PORT");
    if (port == ((void *)0) || port[0] == 0)
        port = "6363";
    memset(result, 0, length);
    hints.ai_family = 0;
    if (strcasecmp(nameonly, "tcp6") == 0) hints.ai_family = 10;
    if (strcasecmp(nameonly, "tcp4") == 0) hints.ai_family = 2;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0020;
    hints.ai_protocol = 0;
    res = getaddrinfo(((void *)0), port, &hints, &ai);
    if (res != 0 || ai->ai_addrlen > length)
        goto Bail;
    memcpy(result, ai->ai_addr, ai->ai_addrlen);
    ans = 0;
Bail:
    free(nameonly);
    freeaddrinfo(ai);
    return (ans);
}

variable_types:
name
char *

variable_types: length int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
port
char *

variable_types:
nameonly
char *

variable_types: ans int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall ndn_btree_content_cobid(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = ndn_btree_node_getentry(64LL, a1, a2);
if ( v2 )
result = ndn_btree_fetchval64_constprop_0((unsigned __int8 *)(v2 + 24));
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = ndn_btree_node_getentry(64LL, a1, a2);
if ( v2 )
result = func0((unsigned __int8 *)(v2 + 24));
else
result = 0LL;
return result;
}

original_code:
uint_least64_t
ndn_btree_content_cobid(struct ndn_btree_node *node, int ndx)
{
    struct ndn_btree_content_payload *e = ((void *)0);
    uint_least64_t ans = 0;
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e != ((void *)0))
        ans = ndn_btree_fetchval64(&((e)->cobid[0]), sizeof((e)->cobid));
    return(ans);
}

canonical_original_code:
unsigned long ndn_btree_content_cobid(struct ndn_btree_node *node, int ndx)
{
    struct ndn_btree_content_payload *e = ((void *)0);
    unsigned long ans = 0;
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e != ((void *)0))
        ans = ndn_btree_fetchval64(&((e)->cobid[0]), sizeof((e)->cobid));
    return(ans);
}

variable_types: struct ndn_btree_node { unsigned int nodeid; struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *buf; void *iodata; unsigned int parent; unsigned int clean; unsigned int freelow; unsigned int corrupt; unsigned int activity; } *

variable_types: ndx int

variable_types: struct ndn_btree_content_payload { unsigned char magic[1]; unsigned char ctype[3]; unsigned char cobsz[4]; unsigned char ncomp[2]; unsigned char flags[1]; unsigned char ttpad[1]; unsigned char timex[6]; unsigned char actim[6]; unsigned char cobid[8]; unsigned char ppkdg[32]; } *

variable_types:
ans
unsigned long

return_type: unsigned long

user_defined_types: struct ndn_btree_node { unsigned int nodeid; struct ndn_charbuf *buf; void *iodata; unsigned int parent; unsigned int clean; unsigned int freelow; unsigned int corrupt; unsigned int activity; }


decompiled_code:
__int64 __fastcall ndn_btree_content_set_cobid(__int64 a1, unsigned int a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // er8
__int64 v6; // rcx
__int64 v7; // rcx

v4 = ndn_btree_node_getentry(64LL, a1, a2);
if ( !v4 )
return (unsigned int)-1;
ndn_btree_storeval64_constprop_0((_BYTE *)(v4 + 24), a3);
v7 = v6 - *(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL);
if ( v7 >= 0 && *(unsigned int *)(a1 + 28) > v7 )
*(_DWORD *)(a1 + 28) = v7;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned int v5; // er8
__int64 v6; // rcx
__int64 v7; // rcx

v4 = ndn_btree_node_getentry(64LL, a1, a2);
if ( !v4 )
return (unsigned int)-1;
ndn_btree_storeval64_constprop_0((_BYTE *)(v4 + 24), a3);
v7 = v6 - *(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL);
if ( v7 >= 0 && *(unsigned int *)(a1 + 28) > v7 )
*(_DWORD *)(a1 + 28) = v7;
return v5;
}

original_code:
int
ndn_btree_content_set_cobid(struct ndn_btree_node *node, int ndx,
                            uint_least64_t cobid)
{
    struct ndn_btree_content_payload *e = ((void *)0);
    ptrdiff_t dirty;
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e == ((void *)0))
        return(-1);
    ndn_btree_storeval64(&((e)->cobid[0]), sizeof((e)->cobid), (cobid));
    dirty = (((unsigned char *)e) - node->buf->buf);
    if (dirty >= 0 && dirty < node->clean)
        node->clean = dirty;
    return(0);
}

canonical_original_code:
int ndn_btree_content_set_cobid(struct ndn_btree_node *node, int ndx, unsigned long cobid)
{
    struct ndn_btree_content_payload *e = ((void *)0);
    long dirty;
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e == ((void *)0))
        return(-1);
    ndn_btree_storeval64(&((e)->cobid[0]), sizeof((e)->cobid), (cobid));
    dirty = (((unsigned char *)e) - node->buf->buf);
    if (dirty >= 0 && dirty < node->clean)
        node->clean = dirty;
    return(0);
}

variable_types:
cobid
unsigned long

variable_types: dirty long

user_defined_types: struct ndn_btree_content_payload { unsigned char magic[1]; unsigned char ctype[3]; unsigned char cobsz[4]; unsigned char ncomp[2]; unsigned char flags[1]; unsigned char ttpad[1]; unsigned char timex[6]; unsigned char actim[6]; unsigned char cobid[8]; unsigned char ppkdg[32]; }


decompiled_code:
__int64 __fastcall ndn_btree_content_cobsz(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = ndn_btree_node_getentry(64LL, a1, a2);
if ( v2 )
result = ndn_btree_fetchval(v2 + 4, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v2 = ndn_btree_node_getentry(64LL, a1, a2);
if ( v2 )
result = ndn_btree_fetchval(v2 + 4, 4LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
ndn_btree_content_cobsz(struct ndn_btree_node *node, int ndx)
{
    struct ndn_btree_content_payload *e = ((void *)0);
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e != ((void *)0))
        return(ndn_btree_fetchval(&((e)->cobsz[0]), sizeof((e)->cobsz)));
    return(-1);
}


decompiled_code:
int __fastcall ndn_flatname_compare(const void *a1, size_t a2, const void *a3, size_t a4)
{
size_t v7; // rdx
int result; // eax

v7 = a2;
if ( a4 <= a2 )
v7 = a4;
result = memcmp(a1, a3, v7);
if ( !result )
{
if ( a4 > a2 )
{
result = -9999;
}
else if ( a4 != a2 )
{
result = 9999;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(const void *a1, size_t a2, const void *a3, size_t a4)
{
size_t v7; // rdx
int result; // eax

v7 = a2;
if ( a4 <= a2 )
v7 = a4;
result = memcmp(a1, a3, v7);
if ( !result )
{
if ( a4 > a2 )
{
result = -9999;
}
else if ( a4 != a2 )
{
result = 9999;
}
}
return result;
}

original_code:
int
ndn_flatname_compare(const unsigned char *a, size_t al, const unsigned char *b, size_t bl)
{
    int res;
    res = memcmp(a, b, al < bl ? al : bl);
    if (res != 0)
        return(res);
    if (al < bl)
        return(-9999);
    else if (al == bl)
        return(0);
    else
        return(9999);
}

canonical_original_code:
int ndn_flatname_compare(unsigned char *a, unsigned long al, unsigned char *b, unsigned long bl)
{
    int res;
    res = memcmp(a, b, al < bl ? al : bl);
    if (res != 0)
        return(res);
    if (al < bl)
        return(-9999);
    else if (al == bl)
        return(0);
    else
        return(9999);
}

variable_types:
a
unsigned char *

variable_types:
al
unsigned long

variable_types:
b
unsigned char *

variable_types:
bl
unsigned long

variable_types: res int


decompiled_code:
int __fastcall ndn_flatname_charbuf_compare(__int64 a1, __int64 a2)
{
return ndn_flatname_compare(*(const void **)(a1 + 16), *(_QWORD *)a1, *(const void **)(a2 + 16), *(_QWORD *)a2);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
return func4(*(const void **)(a1 + 16), *(_QWORD *)a1, *(const void **)(a2 + 16), *(_QWORD *)a2);
}

original_code:
int
ndn_flatname_charbuf_compare(struct ndn_charbuf *a, struct ndn_charbuf *b)
{
    return(ndn_flatname_compare(a->buf, a->length, b->buf, b->length));
}

variable_types: struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *

variable_types:
b
struct ndn_charbuf *


decompiled_code:
__int64 __fastcall ndn_flatname_append_component(__int64 *a1, __int64 a2, unsigned __int64 a3)
{
int v3; // er15
__int64 v6; // r14
int v7; // ebx
unsigned __int64 v8; // rsi
int v9; // ebx
__int64 result; // rax

if ( a3 > 0x1FFFFF )
return 0xFFFFFFFFLL;
v3 = 0;
v6 = *a1;
while ( 1 << (v3 + 7) <= a3 )
v3 += 7;
v7 = 0;
if ( v3 )
{
do
{
v8 = a3 >> v3;
v3 -= 7;
v7 |= ndn_charbuf_append_value(a1, (unsigned __int8)v8 | 0x80u, 1LL);
}
while ( v3 > 0 );
}
v9 = ndn_charbuf_append_value(a1, a3 & 0x7F, 1LL) | v7;
result = v9 | (unsigned int)ndn_charbuf_append(a1, a2, a3);
if ( (int)result < 0 )
*a1 = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 a2, unsigned __int64 a3)
{
int v3; // er15
__int64 v6; // r14
int v7; // ebx
unsigned __int64 v8; // rsi
int v9; // ebx
__int64 result; // rax

if ( a3 > 0x1FFFFF )
return 0xFFFFFFFFLL;
v3 = 0;
v6 = *a1;
while ( 1 << (v3 + 7) <= a3 )
v3 += 7;
v7 = 0;
if ( v3 )
{
do
{
v8 = a3 >> v3;
v3 -= 7;
v7 |= ndn_charbuf_append_value(a1, (unsigned __int8)v8 | 0x80u, 1LL);
}
while ( v3 > 0 );
}
v9 = ndn_charbuf_append_value(a1, a3 & 0x7F, 1LL) | v7;
result = v9 | (unsigned int)ndn_charbuf_append(a1, a2, a3);
if ( (int)result < 0 )
*a1 = v6;
return result;
}

original_code:
int
ndn_flatname_append_component(struct ndn_charbuf *dst,
                              const unsigned char *comp, size_t size)
{
    int res;
    int s;
    size_t save;
    if (size >= (1 << 21))
        return(-1);
    save = dst->length;
    res = 0;
    for (s = 0; size >= (1 << (s + 7)); s += 7)
        continue;
    for (; s > 0; s -= 7)
        res |= ndn_charbuf_append_value(dst, (((size >> s) & 0x7F) | 0x80), 1);
    res |= ndn_charbuf_append_value(dst, (size & 0x7F), 1);
    res |= ndn_charbuf_append(dst, comp, size);
    if (res < 0)
        dst->length = save;
    return(res);
}

canonical_original_code:
int ndn_flatname_append_component(struct ndn_charbuf *dst, unsigned char *comp, unsigned long size)
{
    int res;
    int s;
    unsigned long save;
    if (size >= (1 << 21))
        return(-1);
    save = dst->length;
    res = 0;
    for (s = 0; size >= (1 << (s + 7)); s += 7)
        continue;
    for (; s > 0; s -= 7)
        res |= ndn_charbuf_append_value(dst, (((size >> s) & 0x7F) | 0x80), 1);
    res |= ndn_charbuf_append_value(dst, (size & 0x7F), 1);
    res |= ndn_charbuf_append(dst, comp, size);
    if (res < 0)
        dst->length = save;
    return(res);
}

variable_types:
comp
unsigned char *

variable_types:
size
unsigned long

variable_types: s int

variable_types:
save
unsigned long


decompiled_code:
__int64 __fastcall ndn_flatname_append_from_ndnb(__int64 *a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v7; // rbx
int v8; // ebp
unsigned int v9; // er12
int v11; // [rsp+Ch] [rbp-8Ch]
__int64 v12; // [rsp+10h] [rbp-88h] BYREF
unsigned __int64 v13; // [rsp+18h] [rbp-80h] BYREF
char v14[120]; // [rsp+20h] [rbp-78h] BYREF

v12 = 0LL;
v13 = 0LL;
v7 = ndn_buf_decoder_start(v14);
if ( (unsigned int)ndn_buf_match_dtag(v7, 26LL) || (unsigned int)ndn_buf_match_dtag(v7, 64LL) )
{
ndn_buf_advance(v7);
if ( (unsigned int)ndn_buf_match_dtag(v7, 37LL) )
ndn_buf_advance_past_element(v7);
}
if ( (unsigned int)ndn_buf_match_dtag(v7, 14LL) || (v11 = ndn_buf_match_dtag(v7, 105LL)) != 0 )
{
ndn_buf_advance(v7);
v11 = 1;
}
else
{
a5 = a5 != 0;
}
v8 = 0;
v9 = 0;
while ( (unsigned int)ndn_buf_match_dtag(v7, 15LL) )
{
if ( v9 == a5 )
return v9;
ndn_buf_advance(v7);
v13 = 0LL;
if ( (unsigned int)ndn_buf_match_blob(v7, &v12, &v13) )
{
ndn_buf_advance(v7);
ndn_buf_check_close(v7);
if ( *(int *)(v7 + 8) < 0 )
return -1;
}
else
{
ndn_buf_check_close(v7);
if ( *(int *)(v7 + 8) < 0 )
return -1;
}
if ( ++v8 > a4 )
{
if ( (int)ndn_flatname_append_component(a1, v12, v13) < 0 )
return -1;
++v9;
}
}
if ( v11 )
ndn_buf_check_close(v7);
if ( *(int *)(v7 + 8) < 0 )
return -1;
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v7; // rbx
int v8; // ebp
unsigned int v9; // er12
int v11; // [rsp+Ch] [rbp-8Ch]
__int64 v12; // [rsp+10h] [rbp-88h] BYREF
unsigned __int64 v13; // [rsp+18h] [rbp-80h] BYREF
char v14[120]; // [rsp+20h] [rbp-78h] BYREF

v12 = 0LL;
v13 = 0LL;
v7 = ndn_buf_decoder_start(v14);
if ( (unsigned int)ndn_buf_match_dtag(v7, 26LL) || (unsigned int)ndn_buf_match_dtag(v7, 64LL) )
{
ndn_buf_advance(v7);
if ( (unsigned int)ndn_buf_match_dtag(v7, 37LL) )
ndn_buf_advance_past_element(v7);
}
if ( (unsigned int)ndn_buf_match_dtag(v7, 14LL) || (v11 = ndn_buf_match_dtag(v7, 105LL)) != 0 )
{
ndn_buf_advance(v7);
v11 = 1;
}
else
{
a5 = a5 != 0;
}
v8 = 0;
v9 = 0;
while ( (unsigned int)ndn_buf_match_dtag(v7, 15LL) )
{
if ( v9 == a5 )
return v9;
ndn_buf_advance(v7);
v13 = 0LL;
if ( (unsigned int)ndn_buf_match_blob(v7, &v12, &v13) )
{
ndn_buf_advance(v7);
ndn_buf_check_close(v7);
if ( *(int *)(v7 + 8) < 0 )
return -1;
}
else
{
ndn_buf_check_close(v7);
if ( *(int *)(v7 + 8) < 0 )
return -1;
}
if ( ++v8 > a4 )
{
if ( (int)func6(a1, v12, v13) < 0 )
return -1;
++v9;
}
}
if ( v11 )
ndn_buf_check_close(v7);
if ( *(int *)(v7 + 8) < 0 )
return -1;
return v9;
}

original_code:
int
ndn_flatname_append_from_ndnb(struct ndn_charbuf *dst,
                              const unsigned char *ndnb, size_t size,
                              int skip, int count)
{
    int ans = 0;
    int ncomp = 0;
    const unsigned char *comp = ((void *)0);
    size_t compsize = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, ndnb, size);
    int checkclose = 0;
    int res;
    if (ndn_buf_match_dtag(d, NDN_DTAG_Interest) ||
        ndn_buf_match_dtag(d, NDN_DTAG_ContentObject)) {
        ndn_buf_advance(d);
        if (ndn_buf_match_dtag(d, NDN_DTAG_Signature))
            ndn_buf_advance_past_element(d);
    }
    if ((ndn_buf_match_dtag(d, NDN_DTAG_Name) ||
         ndn_buf_match_dtag(d, NDN_DTAG_Prefix))) {
        checkclose = 1;
        ndn_buf_advance(d);
    }
    else if (count != 0)
        count = 1;
    while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
        if (ans == count)
            return(ans);
        ndn_buf_advance(d);
        compsize = 0;
        if (ndn_buf_match_blob(d, &comp, &compsize))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
        if (d->decoder.state < 0)
            return(-1);
        ncomp += 1;
        if (ncomp > skip) {
            res = ndn_flatname_append_component(dst, comp, compsize);
            if (res < 0)
                return(-1);
            ans++;
        }
    }
    if (checkclose)
        ndn_buf_check_close(d);
    if (d->decoder.state < 0)
        return (-1);
    return(ans);
}

canonical_original_code:
int ndn_flatname_append_from_ndnb(struct ndn_charbuf *dst, unsigned char *ndnb, unsigned long size, int skip, int count)
{
    int ans = 0;
    int ncomp = 0;
    unsigned char *comp = ((void *)0);
    unsigned long compsize = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, ndnb, size);
    int checkclose = 0;
    int res;
    if (ndn_buf_match_dtag(d, NDN_DTAG_Interest) ||
        ndn_buf_match_dtag(d, NDN_DTAG_ContentObject)) {
        ndn_buf_advance(d);
        if (ndn_buf_match_dtag(d, NDN_DTAG_Signature))
            ndn_buf_advance_past_element(d);
    }
    if ((ndn_buf_match_dtag(d, NDN_DTAG_Name) ||
         ndn_buf_match_dtag(d, NDN_DTAG_Prefix))) {
        checkclose = 1;
        ndn_buf_advance(d);
    }
    else if (count != 0)
        count = 1;
    while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
        if (ans == count)
            return(ans);
        ndn_buf_advance(d);
        compsize = 0;
        if (ndn_buf_match_blob(d, &comp, &compsize))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
        if (d->decoder.state < 0)
            return(-1);
        ncomp += 1;
        if (ncomp > skip) {
            res = ndn_flatname_append_component(dst, comp, compsize);
            if (res < 0)
                return(-1);
            ans++;
        }
    }
    if (checkclose)
        ndn_buf_check_close(d);
    if (d->decoder.state < 0)
        return (-1);
    return(ans);
}

variable_types:
ndnb
unsigned char *

variable_types: skip int

variable_types: count int

variable_types: ans int

variable_types: ncomp int

variable_types:
compsize
unsigned long

variable_types: struct ndn_buf_decoder { struct ndn_skeleton_decoder { long index; int state; int nest; unsigned long numval; unsigned long token_index; unsigned long element_index; } decoder; unsigned char *buf; unsigned long size; } *

variable_types: checkclose int

user_defined_types: struct ndn_buf_decoder { struct ndn_skeleton_decoder decoder; unsigned char *buf; unsigned long size; }


decompiled_code:
__int64 __fastcall ndn_flatname_from_ndnb(__int64 *a1, __int64 a2, __int64 a3)
{
*a1 = 0LL;
return ndn_flatname_append_from_ndnb(a1, a2, a3, 0, -1);
}

original_code:
int
ndn_flatname_from_ndnb(struct ndn_charbuf *dst,
                       const unsigned char *ndnb, size_t size)
{
    dst->length = 0;
    return(ndn_flatname_append_from_ndnb(dst, ndnb, size, 0, -1));
}

canonical_original_code:
int ndn_flatname_from_ndnb(struct ndn_charbuf *dst, unsigned char *ndnb, unsigned long size)
{
    dst->length = 0;
    return(ndn_flatname_append_from_ndnb(dst, ndnb, size, 0, -1));
}


decompiled_code:
__int64 __fastcall ndn_flatname_next_comp(char *a1, unsigned __int64 a2)
{
__int64 result; // rax
char v4; // al
unsigned int v5; // edx
char *v6; // rdi
int v7; // ecx
unsigned int v8; // esi
int v9; // eax

result = 0LL;
if ( a2 )
{
v4 = *a1;
if ( *a1 == (char)0x80 )
goto LABEL_9;
v5 = 3;
if ( a2 <= 3 )
v5 = a2;
v6 = a1 + 1;
v7 = 0;
v8 = 0;
while ( 1 )
{
++v8;
if ( v4 >= 0 )
break;
v7 = (v7 | v4 & 0x7F) << 7;
if ( v5 <= v8 )
goto LABEL_9;
v4 = *v6++;
}
v9 = v7 | (unsigned __int8)v4;
if ( v9 + v8 > a2 )
LABEL_9:
result = 0xFFFFFFFFLL;
else
result = v8 + 4 * v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, unsigned __int64 a2)
{
__int64 result; // rax
char v4; // al
unsigned int v5; // edx
char *v6; // rdi
int v7; // ecx
unsigned int v8; // esi
int v9; // eax

result = 0LL;
if ( a2 )
{
v4 = *a1;
if ( *a1 == (char)0x80 )
goto LABEL_9;
v5 = 3;
if ( a2 <= 3 )
v5 = a2;
v6 = a1 + 1;
v7 = 0;
v8 = 0;
while ( 1 )
{
++v8;
if ( v4 >= 0 )
break;
v7 = (v7 | v4 & 0x7F) << 7;
if ( v5 <= v8 )
goto LABEL_9;
v4 = *v6++;
}
v9 = v7 | (unsigned __int8)v4;
if ( v9 + v8 > a2 )
LABEL_9:
result = 0xFFFFFFFFLL;
else
result = v8 + 4 * v9;
}
return result;
}

original_code:
int
ndn_flatname_next_comp(const unsigned char *flatname, size_t size)
{
    unsigned i, l, m;
    if (size == 0)
        return(0);
    if (flatname[0] == 0x80)
        return(-1);
    m = (size < 3) ? size : 3;
    for (i = 0, l = 0; i < m && (flatname[i] & 0x80) != 0; i++)
        l = (l | (flatname[i] & 0x7F)) << 7;
    if (i >= m)
        return(-1);
    l |= flatname[i++];
    if (i + l > size)
        return(-1);
    return(l * 4 + i);
}

canonical_original_code:
int ndn_flatname_next_comp(unsigned char *flatname, unsigned long size)
{
    unsigned int i; unsigned int l; unsigned int m;
    if (size == 0)
        return(0);
    if (flatname[0] == 0x80)
        return(-1);
    m = (size < 3) ? size : 3;
    for (i = 0, l = 0; i < m && (flatname[i] & 0x80) != 0; i++)
        l = (l | (flatname[i] & 0x7F)) << 7;
    if (i >= m)
        return(-1);
    l |= flatname[i++];
    if (i + l > size)
        return(-1);
    return(l * 4 + i);
}

variable_types:
flatname
unsigned char *

variable_types:
i
unsigned int

variable_types:
l
unsigned int

variable_types:
m
unsigned int


original_code:
int
ndn_btree_match_interest(struct ndn_btree_node *node, int ndx,
                         const unsigned char *interest_msg,
                         const struct ndn_parsed_interest *pi,
                         struct ndn_charbuf *scratch)
{
    const unsigned char *blob = ((void *)0);
    const unsigned char *nextcomp = ((void *)0);
    int i;
    int n;
    int ncomps;
    int pubidend;
    int pubidstart;
    int res;
    int rnc;
    size_t blob_size = 0;
    size_t nextcomp_size = 0;
    size_t size;
    struct ndn_btree_content_payload *e = ((void *)0);
    unsigned char *flatname = ((void *)0);
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e == ((void *)0) || e->magic[0] != 0xC0)
        return(-1);
    ncomps = ndn_btree_fetchval(&((e)->ncomp[0]), sizeof((e)->ncomp));
    if (ncomps < pi->prefix_comps + pi->min_suffix_comps)
        return(0);
    if (ncomps > pi->prefix_comps + pi->max_suffix_comps)
        return(0);
    pubidstart = pi->offset[NDN_PI_B_PublisherID];
    pubidend = pi->offset[NDN_PI_E_PublisherID];
    if (pubidstart < pubidend) {
        blob_size = 0;
        ndn_ref_tagged_BLOB(NDN_DTAG_PublisherPublicKeyDigest,
                            interest_msg,
                            pubidstart, pubidend,
                            &blob, &blob_size);
        if (blob_size != sizeof(e->ppkdg))
            return(0);
        if (0 != memcmp(blob, e->ppkdg, blob_size))
            return(0);
    }
    if (pi->offset[NDN_PI_E_Exclude] > pi->offset[NDN_PI_B_Exclude]) {
        res = ndn_btree_key_fetch(scratch, node, ndx);
        if (res < 0)
            return(-1);
        flatname = scratch->buf;
        size = scratch->length;
        nextcomp = ((void *)0);
        nextcomp_size = 0;
        for (i = 0, n = 0; i < size; i += (((rnc) & 3) + ((rnc) >> 2)), n++) {
            rnc = ndn_flatname_next_comp(flatname + i, size - i);
            if (rnc <= 0)
                return(-1);
            if (n == pi->prefix_comps) {
                nextcomp = flatname + i + ((rnc) & 3);
                nextcomp_size = ((rnc) >> 2);
                break;
            }
        }
        if (nextcomp == ((void *)0))
            return(0);
        if (ndn_excluded(interest_msg + pi->offset[NDN_PI_B_Exclude],
                         (pi->offset[NDN_PI_E_Exclude] -
                          pi->offset[NDN_PI_B_Exclude]),
                         nextcomp,
                         nextcomp_size))
            return(0);
    }
    return(1);
}

canonical_original_code:
int ndn_btree_match_interest(struct ndn_btree_node *node, int ndx, unsigned char *interest_msg, struct ndn_parsed_interest *pi, struct ndn_charbuf *scratch)
{
    unsigned char *blob = ((void *)0);
    unsigned char *nextcomp = ((void *)0);
    int i;
    int n;
    int ncomps;
    int pubidend;
    int pubidstart;
    int res;
    int rnc;
    unsigned long blob_size = 0;
    unsigned long nextcomp_size = 0;
    unsigned long size;
    struct ndn_btree_content_payload *e = ((void *)0);
    unsigned char *flatname = ((void *)0);
    e = ndn_btree_node_getentry(sizeof(*e), node, ndx);
    if (e == ((void *)0) || e->magic[0] != 0xC0)
        return(-1);
    ncomps = ndn_btree_fetchval(&((e)->ncomp[0]), sizeof((e)->ncomp));
    if (ncomps < pi->prefix_comps + pi->min_suffix_comps)
        return(0);
    if (ncomps > pi->prefix_comps + pi->max_suffix_comps)
        return(0);
    pubidstart = pi->offset[NDN_PI_B_PublisherID];
    pubidend = pi->offset[NDN_PI_E_PublisherID];
    if (pubidstart < pubidend) {
        blob_size = 0;
        ndn_ref_tagged_BLOB(NDN_DTAG_PublisherPublicKeyDigest,
                            interest_msg,
                            pubidstart, pubidend,
                            &blob, &blob_size);
        if (blob_size != sizeof(e->ppkdg))
            return(0);
        if (0 != memcmp(blob, e->ppkdg, blob_size))
            return(0);
    }
    if (pi->offset[NDN_PI_E_Exclude] > pi->offset[NDN_PI_B_Exclude]) {
        res = ndn_btree_key_fetch(scratch, node, ndx);
        if (res < 0)
            return(-1);
        flatname = scratch->buf;
        size = scratch->length;
        nextcomp = ((void *)0);
        nextcomp_size = 0;
        for (i = 0, n = 0; i < size; i += (((rnc) & 3) + ((rnc) >> 2)), n++) {
            rnc = ndn_flatname_next_comp(flatname + i, size - i);
            if (rnc <= 0)
                return(-1);
            if (n == pi->prefix_comps) {
                nextcomp = flatname + i + ((rnc) & 3);
                nextcomp_size = ((rnc) >> 2);
                break;
            }
        }
        if (nextcomp == ((void *)0))
            return(0);
        if (ndn_excluded(interest_msg + pi->offset[NDN_PI_B_Exclude],
                         (pi->offset[NDN_PI_E_Exclude] -
                          pi->offset[NDN_PI_B_Exclude]),
                         nextcomp,
                         nextcomp_size))
            return(0);
    }
    return(1);
}

variable_types: struct ndn_btree_node { unsigned int nodeid; struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *buf; void *iodata; unsigned int parent; unsigned int clean; unsigned int freelow; unsigned int corrupt; unsigned int activity; } *

variable_types: ndx int

variable_types: struct ndn_parsed_interest { int magic; int prefix_comps; int min_suffix_comps; int max_suffix_comps; int orderpref; int answerfrom; int scope; unsigned short offset[-1]; } *

variable_types:
scratch
struct ndn_charbuf *

variable_types:
blob
unsigned char *

variable_types:
nextcomp
unsigned char *

variable_types: i int

variable_types: n int

variable_types: ncomps int

variable_types: pubidend int

variable_types: pubidstart int

variable_types: res int

variable_types: rnc int

variable_types: struct ndn_btree_content_payload { unsigned char magic[1]; unsigned char ctype[3]; unsigned char cobsz[4]; unsigned char ncomp[2]; unsigned char flags[1]; unsigned char ttpad[1]; unsigned char timex[6]; unsigned char actim[6]; unsigned char cobid[8]; unsigned char ppkdg[32]; } *


original_code:
int
ndn_name_append_flatname(struct ndn_charbuf *dst,
                         const unsigned char *flatname, size_t size,
                         int skip, int count)
{
    int ans;
    int compnum;
    int i;
    int rnc;
    int res;
    const unsigned char *cp;
    size_t cs;
    if (skip < 0)
        return(-1);
    ans = 0;
    compnum = 0;
    for (i = 0; i < size; i += (((rnc) & 3) + ((rnc) >> 2))) {
        if (ans == count)
            return(ans);
        rnc = ndn_flatname_next_comp(flatname + i, size - i);
        if (rnc <= 0)
            return(-1);
        cp = flatname + i + ((rnc) & 3);
        cs = ((rnc) >> 2);
        if (compnum >= skip) {
            res = ndn_name_append(dst, cp, cs);
            if (res < 0)
                return(-1);
            ans++;
        }
        compnum++;
    }
    return(ans);
}

canonical_original_code:
int ndn_name_append_flatname(struct ndn_charbuf *dst, unsigned char *flatname, unsigned long size, int skip, int count)
{
    int ans;
    int compnum;
    int i;
    int rnc;
    int res;
    unsigned char *cp;
    unsigned long cs;
    if (skip < 0)
        return(-1);
    ans = 0;
    compnum = 0;
    for (i = 0; i < size; i += (((rnc) & 3) + ((rnc) >> 2))) {
        if (ans == count)
            return(ans);
        rnc = ndn_flatname_next_comp(flatname + i, size - i);
        if (rnc <= 0)
            return(-1);
        cp = flatname + i + ((rnc) & 3);
        cs = ((rnc) >> 2);
        if (compnum >= skip) {
            res = ndn_name_append(dst, cp, cs);
            if (res < 0)
                return(-1);
            ans++;
        }
        compnum++;
    }
    return(ans);
}

variable_types: struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *

variable_types:
flatname
unsigned char *

variable_types:
size
unsigned long

variable_types: skip int

variable_types: count int

variable_types: ans int

variable_types: compnum int

variable_types:
cp
unsigned char *

variable_types:
cs
unsigned long


decompiled_code:
__int64 __fastcall ndn_uri_append_flatname(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned int a4)
{
_QWORD *v6; // rax
int v7; // er12
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v6 = (_QWORD *)ndn_charbuf_create();
v9[0] = (__int64)v6;
if ( v6 )
{
v7 = ndn_name_init(v6);
if ( v7 >= 0 )
{
v7 = ndn_name_append_flatname(v9[0], a2, a3, 0, -1);
if ( v7 >= 0 )
v7 = ndn_uri_append(a1, *(_QWORD *)(v9[0] + 16), *(_QWORD *)v9[0], a4);
}
ndn_charbuf_destroy(v9);
}
else
{
v7 = -1;
}
return (unsigned int)v7;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, unsigned __int64 a3, unsigned int a4)
{
_QWORD *v6; // rax
int v7; // er12
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v6 = (_QWORD *)ndn_charbuf_create();
v9[0] = (__int64)v6;
if ( v6 )
{
v7 = ndn_name_init(v6);
if ( v7 >= 0 )
{
v7 = func11(v9[0], a2, a3, 0, -1);
if ( v7 >= 0 )
v7 = ndn_uri_append(a1, *(_QWORD *)(v9[0] + 16), *(_QWORD *)v9[0], a4);
}
ndn_charbuf_destroy(v9);
}
else
{
v7 = -1;
}
return (unsigned int)v7;
}

original_code:
int
ndn_uri_append_flatname(struct ndn_charbuf *uri,
                             const unsigned char *flatname, size_t size,
                             int includescheme)
{
    struct ndn_charbuf *ndnb = ((void *)0);
    int res;
    ndnb = ndn_charbuf_create();
    if (ndnb == ((void *)0))
        return(-1);
    res = ndn_name_init(ndnb);
    if (res < 0)
        goto Bail;
    res = ndn_name_append_flatname(ndnb, flatname, size, 0, -1);
    if (res < 0)
        goto Bail;
    res = ndn_uri_append(uri, ndnb->buf, ndnb->length, includescheme);
Bail:
    ndn_charbuf_destroy(&ndnb);
    return(res);
}

canonical_original_code:
int ndn_uri_append_flatname(struct ndn_charbuf *uri, unsigned char *flatname, unsigned long size, int includescheme)
{
    struct ndn_charbuf *ndnb = ((void *)0);
    int res;
    ndnb = ndn_charbuf_create();
    if (ndnb == ((void *)0))
        return(-1);
    res = ndn_name_init(ndnb);
    if (res < 0)
        goto Bail;
    res = ndn_name_append_flatname(ndnb, flatname, size, 0, -1);
    if (res < 0)
        goto Bail;
    res = ndn_uri_append(uri, ndnb->buf, ndnb->length, includescheme);
Bail:
    ndn_charbuf_destroy(&ndnb);
    return(res);
}

variable_types: includescheme int


decompiled_code:
__int64 __fastcall ndn_flatname_ncomps(__int64 a1, unsigned __int64 a2)
{
int v3; // er13
unsigned int v4; // er12
__int64 v5; // rdi
int v6; // eax

if ( !a2 )
return 0;
v3 = 0;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = ndn_flatname_next_comp((char *)(a1 + v5), a2 - v5);
if ( v6 <= 0 )
break;
++v4;
v3 += (v6 & 3) + (v6 >> 2);
v5 = v3;
if ( v3 >= a2 )
return v4;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int64 a2)
{
int v3; // er13
unsigned int v4; // er12
__int64 v5; // rdi
int v6; // eax

if ( !a2 )
return 0;
v3 = 0;
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v6 = func9((char *)(a1 + v5), a2 - v5);
if ( v6 <= 0 )
break;
++v4;
v3 += (v6 & 3) + (v6 >> 2);
v5 = v3;
if ( v3 >= a2 )
return v4;
}
return (unsigned int)-1;
}

original_code:
int
ndn_flatname_ncomps(const unsigned char *flatname, size_t size)
{
    int ans;
    int i;
    int rnc;
    ans = 0;
    for (i = 0; i < size; i += (((rnc) & 3) + ((rnc) >> 2))) {
        rnc = ndn_flatname_next_comp(flatname + i, size - i);
        if (rnc <= 0)
            return(-1);
        ans++;
    }
    return(ans);
}

canonical_original_code:
int ndn_flatname_ncomps(unsigned char *flatname, unsigned long size)
{
    int ans;
    int i;
    int rnc;
    ans = 0;
    for (i = 0; i < size; i += (((rnc) & 3) + ((rnc) >> 2))) {
        rnc = ndn_flatname_next_comp(flatname + i, size - i);
        if (rnc <= 0)
            return(-1);
        ans++;
    }
    return(ans);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ndn_btree_insert_content(__int64 a1, unsigned int a2, unsigned __int64 a3, __int64 a4, __int64 a5, unsigned __int64 *a6)
{
unsigned int v9; // er13
__int64 v10; // rdi
unsigned __int64 v11; // rsi
int v12; // eax
unsigned int v13; // er14
__int64 v14; // r8
unsigned __int64 v15; // rdx
unsigned __int64 v16; // rcx
void *src; // [rsp+20h] [rbp-88h] BYREF
size_t n; // [rsp+28h] [rbp-80h] BYREF
__m128i v23; // [rsp+30h] [rbp-78h] BYREF
__m128i v24; // [rsp+40h] [rbp-68h] BYREF
__m128i v25; // [rsp+50h] [rbp-58h]
__m128i v26; // [rsp+60h] [rbp-48h]

v9 = *(unsigned __int16 *)(a5 + 84);
v10 = a6[2];
v11 = *a6;
src = 0LL;
n = 0LL;
v12 = ndn_flatname_ncomps(v10, v11);
v13 = *(_DWORD *)(a5 + 8) + 1;
if ( v13 != v12 )
return 0xFFFFFFFFLL;
v23 = _mm_load_si128((const __m128i *)&LC0);
v24 = v23;
v25 = v23;
v26 = v23;
ndn_btree_storeval(&v23, 1LL, 192LL);
ndn_btree_storeval(&v23.m128i_i8[1], 3LL, *(unsigned int *)(a5 + 4));
ndn_btree_storeval((char *)v23.m128i_i64 + 4, 4LL, v9);
ndn_btree_storeval(&v23.m128i_u64[1], 2LL, v13);
ndn_btree_storeval((char *)&v23.m128i_u64[1] + 2, 1LL, 0LL);
ndn_btree_storeval((char *)&v23.m128i_u64[1] + 3, 1LL, 0LL);
ndn_btree_storeval((char *)&v23.m128i_u64[1] + 4, 6LL, 0LL);
if ( (int)ndn_ref_tagged_BLOB(39LL, a4, *(unsigned __int16 *)(a5 + 42), *(unsigned __int16 *)(a5 + 44), &src, &n) < 0 )
return 0xFFFFFFFFLL;
if ( n > 6 )
return 0xFFFFFFFFLL;
memcpy((char *)&v23 - n + 18, src, n);
ndn_btree_storeval64_constprop_0(&v24.m128i_i8[8], a3);
if ( (int)ndn_ref_tagged_BLOB(60LL, a4, *(unsigned __int16 *)(a5 + 38), *(unsigned __int16 *)(a5 + 40), v14, &n) < 0
|| n != 32 )
{
return 0xFFFFFFFFLL;
}
v15 = a6[2];
v16 = *a6;
v25 = _mm_loadu_si128((const __m128i *)src);
v26 = _mm_loadu_si128((const __m128i *)src + 1);
return ndn_btree_insert_entry(a1, a2, v15, v16, &v23, 64LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2, unsigned __int64 a3, __int64 a4, __int64 a5, unsigned __int64 *a6)
{
unsigned int v9; // er13
__int64 v10; // rdi
unsigned __int64 v11; // rsi
int v12; // eax
unsigned int v13; // er14
__int64 v14; // r8
unsigned __int64 v15; // rdx
unsigned __int64 v16; // rcx
void *src; // [rsp+20h] [rbp-88h] BYREF
size_t n; // [rsp+28h] [rbp-80h] BYREF
__m128i v23; // [rsp+30h] [rbp-78h] BYREF
__m128i v24; // [rsp+40h] [rbp-68h] BYREF
__m128i v25; // [rsp+50h] [rbp-58h]
__m128i v26; // [rsp+60h] [rbp-48h]

v9 = *(unsigned __int16 *)(a5 + 84);
v10 = a6[2];
v11 = *a6;
src = 0LL;
n = 0LL;
v12 = func13(v10, v11);
v13 = *(_DWORD *)(a5 + 8) + 1;
if ( v13 != v12 )
return 0xFFFFFFFFLL;
v23 = _mm_load_si128((const __m128i *)&LC0);
v24 = v23;
v25 = v23;
v26 = v23;
ndn_btree_storeval(&v23, 1LL, 192LL);
ndn_btree_storeval(&v23.m128i_i8[1], 3LL, *(unsigned int *)(a5 + 4));
ndn_btree_storeval((char *)v23.m128i_i64 + 4, 4LL, v9);
ndn_btree_storeval(&v23.m128i_u64[1], 2LL, v13);
ndn_btree_storeval((char *)&v23.m128i_u64[1] + 2, 1LL, 0LL);
ndn_btree_storeval((char *)&v23.m128i_u64[1] + 3, 1LL, 0LL);
ndn_btree_storeval((char *)&v23.m128i_u64[1] + 4, 6LL, 0LL);
if ( (int)ndn_ref_tagged_BLOB(39LL, a4, *(unsigned __int16 *)(a5 + 42), *(unsigned __int16 *)(a5 + 44), &src, &n) < 0 )
return 0xFFFFFFFFLL;
if ( n > 6 )
return 0xFFFFFFFFLL;
memcpy((char *)&v23 - n + 18, src, n);
ndn_btree_storeval64_constprop_0(&v24.m128i_i8[8], a3);
if ( (int)ndn_ref_tagged_BLOB(60LL, a4, *(unsigned __int16 *)(a5 + 38), *(unsigned __int16 *)(a5 + 40), v14, &n) < 0
|| n != 32 )
{
return 0xFFFFFFFFLL;
}
v15 = a6[2];
v16 = *a6;
v25 = _mm_loadu_si128((const __m128i *)src);
v26 = _mm_loadu_si128((const __m128i *)src + 1);
return ndn_btree_insert_entry(a1, a2, v15, v16, &v23, 64LL);
}

original_code:
int
ndn_btree_insert_content(struct ndn_btree_node *node, int ndx,
                         uint_least64_t cobid,
                         const unsigned char *content_object,
                         struct ndn_parsed_ContentObject *pc,
                         struct ndn_charbuf *flatname)
{
    struct ndn_btree_content_payload payload;
    struct ndn_btree_content_payload *e = &payload;
    int ncomp;
    int res;
    unsigned size;
    unsigned flags = 0;
    const unsigned char *blob = ((void *)0);
    size_t blob_size = 0;
    size = pc->offset[NDN_PCO_E];
    ncomp = ndn_flatname_ncomps(flatname->buf, flatname->length);
    if (ncomp != pc->name_ncomps + 1)
        return(-1);
    memset(e, 'U', sizeof(*e));
    ndn_btree_storeval(&((e)->magic[0]), sizeof((e)->magic), (0xC0));
    ndn_btree_storeval(&((e)->ctype[0]), sizeof((e)->ctype), (pc->type));
    ndn_btree_storeval(&((e)->cobsz[0]), sizeof((e)->cobsz), (size));
    ndn_btree_storeval(&((e)->ncomp[0]), sizeof((e)->ncomp), (ncomp));
    ndn_btree_storeval(&((e)->flags[0]), sizeof((e)->flags), (flags));
    ndn_btree_storeval(&((e)->ttpad[0]), sizeof((e)->ttpad), (0));
    ndn_btree_storeval(&((e)->timex[0]), sizeof((e)->timex), (0));
    res = ndn_ref_tagged_BLOB(NDN_DTAG_Timestamp, content_object,
                              pc->offset[NDN_PCO_B_Timestamp],
                              pc->offset[NDN_PCO_E_Timestamp],
                              &blob, &blob_size);
    if (res < 0 || blob_size > sizeof(e->timex))
        return(-1);
    memcpy(e->timex + sizeof(e->timex) - blob_size, blob, blob_size);
    ndn_btree_storeval64(&((e)->cobid[0]), sizeof((e)->cobid), (cobid));
    res = ndn_ref_tagged_BLOB(NDN_DTAG_PublisherPublicKeyDigest, content_object,
                              pc->offset[NDN_PCO_B_PublisherPublicKeyDigest],
                              pc->offset[NDN_PCO_E_PublisherPublicKeyDigest],
                              &blob, &blob_size);
    if (res < 0 || blob_size != sizeof(e->ppkdg))
        return(-1);
    memcpy(e->ppkdg, blob, sizeof(e->ppkdg));
    res = ndn_btree_insert_entry(node, ndx,
                                 flatname->buf, flatname->length,
                                 e, sizeof(*e));
    return(res);
}

canonical_original_code:
int ndn_btree_insert_content(struct ndn_btree_node *node, int ndx, unsigned long cobid, unsigned char *content_object, struct ndn_parsed_ContentObject *pc, struct ndn_charbuf *flatname)
{
    struct ndn_btree_content_payload payload;
    struct ndn_btree_content_payload *e = &payload;
    int ncomp;
    int res;
    unsigned int size;
    unsigned int flags = 0;
    unsigned char *blob = ((void *)0);
    unsigned long blob_size = 0;
    size = pc->offset[NDN_PCO_E];
    ncomp = ndn_flatname_ncomps(flatname->buf, flatname->length);
    if (ncomp != pc->name_ncomps + 1)
        return(-1);
    memset(e, 'U', sizeof(*e));
    ndn_btree_storeval(&((e)->magic[0]), sizeof((e)->magic), (0xC0));
    ndn_btree_storeval(&((e)->ctype[0]), sizeof((e)->ctype), (pc->type));
    ndn_btree_storeval(&((e)->cobsz[0]), sizeof((e)->cobsz), (size));
    ndn_btree_storeval(&((e)->ncomp[0]), sizeof((e)->ncomp), (ncomp));
    ndn_btree_storeval(&((e)->flags[0]), sizeof((e)->flags), (flags));
    ndn_btree_storeval(&((e)->ttpad[0]), sizeof((e)->ttpad), (0));
    ndn_btree_storeval(&((e)->timex[0]), sizeof((e)->timex), (0));
    res = ndn_ref_tagged_BLOB(NDN_DTAG_Timestamp, content_object,
                              pc->offset[NDN_PCO_B_Timestamp],
                              pc->offset[NDN_PCO_E_Timestamp],
                              &blob, &blob_size);
    if (res < 0 || blob_size > sizeof(e->timex))
        return(-1);
    memcpy(e->timex + sizeof(e->timex) - blob_size, blob, blob_size);
    ndn_btree_storeval64(&((e)->cobid[0]), sizeof((e)->cobid), (cobid));
    res = ndn_ref_tagged_BLOB(NDN_DTAG_PublisherPublicKeyDigest, content_object,
                              pc->offset[NDN_PCO_B_PublisherPublicKeyDigest],
                              pc->offset[NDN_PCO_E_PublisherPublicKeyDigest],
                              &blob, &blob_size);
    if (res < 0 || blob_size != sizeof(e->ppkdg))
        return(-1);
    memcpy(e->ppkdg, blob, sizeof(e->ppkdg));
    res = ndn_btree_insert_entry(node, ndx,
                                 flatname->buf, flatname->length,
                                 e, sizeof(*e));
    return(res);
}

variable_types: struct ndn_btree_node { unsigned int nodeid; struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *buf; void *iodata; unsigned int parent; unsigned int clean; unsigned int freelow; unsigned int corrupt; unsigned int activity; } *

variable_types: ndx int

variable_types:
cobid
unsigned long

variable_types: struct ndn_parsed_ContentObject { int magic; enum ndn_content_type { NDN_CONTENT_DATA=787648, NDN_CONTENT_ENCR=1101969, NDN_CONTENT_GONE=1631044, NDN_CONTENT_KEY=2639423, NDN_CONTENT_LINK=2917194, NDN_CONTENT_NACK=3408010 } type; int name_ncomps; unsigned short offset[-1]; unsigned char digest[32]; int digest_bytes; } *

variable_types:
flatname
struct ndn_charbuf *

variable_types: struct ndn_btree_content_payload { unsigned char magic[1]; unsigned char ctype[3]; unsigned char cobsz[4]; unsigned char ncomp[2]; unsigned char flags[1]; unsigned char ttpad[1]; unsigned char timex[6]; unsigned char actim[6]; unsigned char cobid[8]; unsigned char ppkdg[32]; }

variable_types: ncomp int

variable_types:
size
unsigned int

variable_types:
flags
unsigned int

variable_types:
blob
unsigned char *

user_defined_types: struct ndn_parsed_ContentObject { int magic; enum ndn_content_type type; int name_ncomps; unsigned short offset[-1]; unsigned char digest[32]; int digest_bytes; }


decompiled_code:
void *ndn_indexbuf_create()
{
return calloc(1uLL, 0x18uLL);
}

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

original_code:
struct ndn_indexbuf *
ndn_indexbuf_create(void)
{
    struct ndn_indexbuf *c;
    c = calloc(1, sizeof(*c));
    return(c);
}

canonical_original_code:
struct ndn_indexbuf *ndn_indexbuf_create()
{
    struct ndn_indexbuf *c;
    c = calloc(1, sizeof(*c));
    return(c);
}

variable_types: struct ndn_indexbuf { unsigned long n; unsigned long limit; unsigned long *buf; } *


decompiled_code:
void __fastcall ndn_indexbuf_destroy(_QWORD **a1)
{
_QWORD *v1; // rbp
void *v3; // rdi

v1 = *a1;
if ( *a1 )
{
v3 = (void *)v1[2];
if ( v3 )
free(v3);
free(v1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD **a1)
{
_QWORD *v1; // rbp
void *v3; // rdi

v1 = *a1;
if ( *a1 )
{
v3 = (void *)v1[2];
if ( v3 )
free(v3);
free(v1);
*a1 = 0LL;
}
}

original_code:
void
ndn_indexbuf_destroy(struct ndn_indexbuf **cbp)
{
    struct ndn_indexbuf *c = *cbp;
    if (c != ((void *)0)) {
        if (c->buf != ((void *)0)) {
            free(c->buf);
        }
        free(c);
        *cbp = ((void *)0);
    }
}

variable_types: struct ndn_indexbuf { unsigned long n; unsigned long limit; unsigned long *buf; } **


original_code:
size_t *
ndn_indexbuf_reserve(struct ndn_indexbuf *c, size_t n)
{
    size_t newlim = n + c->n;
    size_t oldlim = c->limit;
    size_t *buf = c->buf;
    if (newlim < n)
        return(((void *)0));
    if (newlim > oldlim) {
        if (2 * oldlim > newlim)
            newlim = 2 * oldlim;
        buf = realloc(c->buf, newlim * sizeof(size_t));
        if (buf == ((void *)0))
            return(((void *)0));
        memset(buf + oldlim, 0, (newlim - oldlim) * sizeof(size_t));
        c->buf = buf;
        c->limit = newlim;
    }
    buf += c->n;
    return(buf);
}

canonical_original_code:
unsigned long *ndn_indexbuf_reserve(struct ndn_indexbuf *c, unsigned long n)
{
    unsigned long newlim = n + c->n;
    unsigned long oldlim = c->limit;
    unsigned long *buf = c->buf;
    if (newlim < n)
        return(((void *)0));
    if (newlim > oldlim) {
        if (2 * oldlim > newlim)
            newlim = 2 * oldlim;
        buf = realloc(c->buf, newlim * sizeof(unsigned long));
        if (buf == ((void *)0))
            return(((void *)0));
        memset(buf + oldlim, 0, (newlim - oldlim) * sizeof(unsigned long));
        c->buf = buf;
        c->limit = newlim;
    }
    buf += c->n;
    return(buf);
}

variable_types:
n
unsigned long

variable_types:
newlim
unsigned long

variable_types:
oldlim
unsigned long

variable_types:
buf
unsigned long *

return_type: unsigned long *

user_defined_types: struct ndn_indexbuf { unsigned long n; unsigned long limit; unsigned long *buf; }


decompiled_code:
__int64 __fastcall ndn_indexbuf_append(_QWORD *a1, const void *a2, __int64 a3)
{
char *v4; // rax

v4 = ndn_indexbuf_reserve(a1, a3);
if ( !v4 )
return 0xFFFFFFFFLL;
memcpy(v4, a2, 8 * a3);
*a1 += a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, const void *a2, __int64 a3)
{
char *v4; // rax

v4 = func2(a1, a3);
if ( !v4 )
return 0xFFFFFFFFLL;
memcpy(v4, a2, 8 * a3);
*a1 += a3;
return 0LL;
}

original_code:
int
ndn_indexbuf_append(struct ndn_indexbuf *c, const size_t *p, size_t n)
{
    size_t *dst = ndn_indexbuf_reserve(c, n);
    if (dst == ((void *)0))
        return(-1);
    memcpy(dst, p, n * sizeof(size_t));
    c->n += n;
    return(0);
}

canonical_original_code:
int ndn_indexbuf_append(struct ndn_indexbuf *c, unsigned long *p, unsigned long n)
{
    unsigned long *dst = ndn_indexbuf_reserve(c, n);
    if (dst == ((void *)0))
        return(-1);
    memcpy(dst, p, n * sizeof(unsigned long));
    c->n += n;
    return(0);
}

variable_types:
p
unsigned long *

variable_types:
dst
unsigned long *


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

v2 = ndn_indexbuf_reserve(a1, 1LL);
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)v2 = a2;
result = 0LL;
++*a1;
return result;
}

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

v2 = func2(a1, 1LL);
if ( !v2 )
return 0xFFFFFFFFLL;
*(_QWORD *)v2 = a2;
result = 0LL;
++*a1;
return result;
}

original_code:
int
ndn_indexbuf_append_element(struct ndn_indexbuf *c, size_t v)
{
    size_t *dst = ndn_indexbuf_reserve(c, 1);
    if (dst == ((void *)0))
        return(-1);
    *dst = v;
    c->n += 1;
    return(0);
}

canonical_original_code:
int ndn_indexbuf_append_element(struct ndn_indexbuf *c, unsigned long v)
{
    unsigned long *dst = ndn_indexbuf_reserve(c, 1);
    if (dst == ((void *)0))
        return(-1);
    *dst = v;
    c->n += 1;
    return(0);
}

variable_types:
v
unsigned long


decompiled_code:
__int64 __fastcall ndn_indexbuf_member(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
LODWORD(result) = *(_DWORD *)a1 - 1;
if ( (int)result < 0 )
return 0xFFFFFFFFLL;
result = (int)result;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * result) != a2 )
{
if ( (int)--result < 0 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
LODWORD(result) = *(_DWORD *)a1 - 1;
if ( (int)result < 0 )
return 0xFFFFFFFFLL;
result = (int)result;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * result) != a2 )
{
if ( (int)--result < 0 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int
ndn_indexbuf_member(struct ndn_indexbuf *x, size_t val)
{
    int i;
    if (x == ((void *)0))
        return (-1);
    for (i = x->n - 1; i >= 0; i--)
        if (x->buf[i] == val)
            return(i);
    return(-1);
}

canonical_original_code:
int ndn_indexbuf_member(struct ndn_indexbuf *x, unsigned long val)
{
    int i;
    if (x == ((void *)0))
        return (-1);
    for (i = x->n - 1; i >= 0; i--)
        if (x->buf[i] == val)
            return(i);
    return(-1);
}

variable_types:
val
unsigned long

variable_types: i int


original_code:
void
ndn_indexbuf_remove_element(struct ndn_indexbuf *x, size_t val)
{
    int i;
    if (x == ((void *)0)) return;
    for (i = x->n - 1; i >= 0; i--)
        if (x->buf[i] == val) {
            x->buf[i] = x->buf[--x->n];
            return;
        }
}

canonical_original_code:
void ndn_indexbuf_remove_element(struct ndn_indexbuf *x, unsigned long val)
{
    int i;
    if (x == ((void *)0)) return;
    for (i = x->n - 1; i >= 0; i--)
        if (x->buf[i] == val) {
            x->buf[i] = x->buf[--x->n];
            return;
        }
}


decompiled_code:
__int64 __fastcall ndn_indexbuf_set_insert(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

if ( !a1 )
return -1;
if ( *a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( *(_QWORD *)(a1[2] + 8 * v2) == a2 )
return v3;
v3 = ++v2;
if ( *a1 == v2 )
goto LABEL_8;
}
}
v3 = 0;
LABEL_8:
if ( (int)ndn_indexbuf_append_element(a1, a2) < 0 )
return -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // er12

if ( !a1 )
return -1;
if ( *a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( *(_QWORD *)(a1[2] + 8 * v2) == a2 )
return v3;
v3 = ++v2;
if ( *a1 == v2 )
goto LABEL_8;
}
}
v3 = 0;
LABEL_8:
if ( (int)func4(a1, a2) < 0 )
return -1;
return v3;
}

original_code:
int
ndn_indexbuf_set_insert(struct ndn_indexbuf *x, size_t val)
{
    int i;
    if (x == ((void *)0))
        return (-1);
    for (i = 0; i < x->n; i++)
        if (x->buf[i] == val)
            return(i);
    if (ndn_indexbuf_append_element(x, val) < 0)
        return(-1);
    return(i);
}

canonical_original_code:
int ndn_indexbuf_set_insert(struct ndn_indexbuf *x, unsigned long val)
{
    int i;
    if (x == ((void *)0))
        return (-1);
    for (i = 0; i < x->n; i++)
        if (x->buf[i] == val)
            return(i);
    if (ndn_indexbuf_append_element(x, val) < 0)
        return(-1);
    return(i);
}


decompiled_code:
__int64 __fastcall ndn_indexbuf_remove_first_match(__int64 *a1, __int64 a2)
{
__int64 v2; // r8
int v4; // er9
_QWORD *v5; // r10
__int64 v6; // rax
_QWORD *i; // rdi
unsigned int v8; // er12
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v4 = *a1;
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v5 = (_QWORD *)a1[2];
v6 = 0LL;
for ( i = v5; ; ++i )
{
v8 = v6;
if ( *i == a2 )
break;
if ( v6 == (_DWORD)v2 - 1 )
return 0xFFFFFFFFLL;
++v6;
}
if ( v4 > (int)v6 + 1 )
{
memmove(i, &v5[v6 + 1], 8LL * (v4 - (int)v6 - 1));
v2 = *a1;
}
result = v8;
*a1 = v2 - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, __int64 a2)
{
__int64 v2; // r8
int v4; // er9
_QWORD *v5; // r10
__int64 v6; // rax
_QWORD *i; // rdi
unsigned int v8; // er12
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
v4 = *a1;
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v5 = (_QWORD *)a1[2];
v6 = 0LL;
for ( i = v5; ; ++i )
{
v8 = v6;
if ( *i == a2 )
break;
if ( v6 == (_DWORD)v2 - 1 )
return 0xFFFFFFFFLL;
++v6;
}
if ( v4 > (int)v6 + 1 )
{
memmove(i, &v5[v6 + 1], 8LL * (v4 - (int)v6 - 1));
v2 = *a1;
}
result = v8;
*a1 = v2 - 1;
return result;
}

original_code:
int
ndn_indexbuf_remove_first_match(struct ndn_indexbuf *x, size_t val)
{
    int i;
    int n;
    if (x == ((void *)0))
        return (-1);
    for (i = 0, n = x->n; i < n; i++) {
        if (x->buf[i] == val) {
            if (i + 1 < n)
                memmove(&(x->buf[i]),
                        &(x->buf[i + 1]),
                        sizeof(x->buf[i]) * (n - i - 1));
            x->n--;
            return(i);
        }
    }
    return(-1);
}

canonical_original_code:
int ndn_indexbuf_remove_first_match(struct ndn_indexbuf *x, unsigned long val)
{
    int i;
    int n;
    if (x == ((void *)0))
        return (-1);
    for (i = 0, n = x->n; i < n; i++) {
        if (x->buf[i] == val) {
            if (i + 1 < n)
                memmove(&(x->buf[i]),
                        &(x->buf[i + 1]),
                        sizeof(x->buf[i]) * (n - i - 1));
            x->n--;
            return(i);
        }
    }
    return(-1);
}

variable_types: n int


original_code:
void
ndn_indexbuf_move_to_end(struct ndn_indexbuf *x, size_t val)
{
    int i;
    int n;
    if (x == ((void *)0))
        return;
    for (i = 0, n = x->n; i + 1 < n; i++) {
        if (x->buf[i] == val) {
            memmove(&(x->buf[i]),
                    &(x->buf[i + 1]),
                    sizeof(x->buf[i]) * (n - i - 1));
            x->buf[n - 1] = val;
            return;
        }
    }
}

canonical_original_code:
void ndn_indexbuf_move_to_end(struct ndn_indexbuf *x, unsigned long val)
{
    int i;
    int n;
    if (x == ((void *)0))
        return;
    for (i = 0, n = x->n; i + 1 < n; i++) {
        if (x->buf[i] == val) {
            memmove(&(x->buf[i]),
                    &(x->buf[i + 1]),
                    sizeof(x->buf[i]) * (n - i - 1));
            x->buf[n - 1] = val;
            return;
        }
    }
}


decompiled_code:
void __fastcall ndn_indexbuf_move_to_front(_QWORD *a1, __int64 a2)
{
size_t v3; // rdx
__int64 v4; // rsi

if ( a1 && (int)*a1 > 0 )
{
v3 = 0LL;
v4 = a1[2];
while ( *(_QWORD *)(v4 + v3) != a2 )
{
v3 += 8LL;
if ( v3 == 8LL * ((unsigned int)*a1 - 1) + 8 )
return;
}
memmove((void *)(v4 + 8), (const void *)v4, v3);
*(_QWORD *)a1[2] = a2;
}
}

original_code:
void
ndn_indexbuf_move_to_front(struct ndn_indexbuf *x, size_t val)
{
    int i;
    int n;
    if (x == ((void *)0))
        return;
    for (i = 0, n = x->n; i < n; i++) {
        if (x->buf[i] == val) {
            memmove(&(x->buf[1]),
                    &(x->buf[0]),
                    sizeof(x->buf[i]) * i);
            x->buf[0] = val;
            return;
        }
    }
}

canonical_original_code:
void ndn_indexbuf_move_to_front(struct ndn_indexbuf *x, unsigned long val)
{
    int i;
    int n;
    if (x == ((void *)0))
        return;
    for (i = 0, n = x->n; i < n; i++) {
        if (x->buf[i] == val) {
            memmove(&(x->buf[1]),
                    &(x->buf[0]),
                    sizeof(x->buf[i]) * i);
            x->buf[0] = val;
            return;
        }
    }
}


decompiled_code:
__int64 __fastcall bloom_seed(__int64 a1)
{
return _byteswap_ulong(*(_DWORD *)(a1 + 4)) & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return _byteswap_ulong(*(_DWORD *)(a1 + 4)) & 0x7FFFFFFF;
}

original_code:
static int
bloom_seed(const struct ndn_bloom_wire *f)
{
    unsigned u;
    const unsigned char *s = f->seed;
    u = ((s[0]) << 24) |
        ((s[1]) << 16) |
        ((s[2]) << 8) |
        (s[3]);
    return(u & 0x7FFFFFFF);
}

canonical_original_code:
static int bloom_seed(struct ndn_bloom_wire *f)
{
    unsigned int u;
    unsigned char *s = f->seed;
    u = ((s[0]) << 24) |
        ((s[1]) << 16) |
        ((s[2]) << 8) |
        (s[3]);
    return(u & 0x7FFFFFFF);
}

variable_types: struct ndn_bloom_wire { unsigned char lg_bits; unsigned char n_hash; unsigned char method; unsigned char reserved; unsigned char seed[4]; unsigned char bloom[1024]; } *

variable_types:
u
unsigned int

variable_types:
s
unsigned char *


decompiled_code:
__int64 __fastcall bloom_nexthash(int a1, int a2)
{
return ((((a1 & 0x1FFF) << 18) ^ a1 & 0x1FFF ^ (a1 >> 13)) + a2) & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return ((((a1 & 0x1FFF) << 18) ^ a1 & 0x1FFF ^ (a1 >> 13)) + a2) & 0x7FFFFFFF;
}

original_code:
static int
bloom_nexthash(int s, int u)
{
    const int k = 13;
    int b = s & ((1 << k) - 1);
    s = ((s >> k) ^ (b << (31 - k)) ^ (b << (13 - k))) + u;
    return(s & 0x7FFFFFFF);
}

canonical_original_code:
static int bloom_nexthash(int s, int u)
{
    int k = 13;
    int b = s & ((1 << k) - 1);
    s = ((s >> k) ^ (b << (31 - k)) ^ (b << (13 - k))) + u;
    return(s & 0x7FFFFFFF);
}

variable_types: s int

variable_types: u int

variable_types: k int

variable_types: b int


decompiled_code:
void __fastcall ndn_bloom_destroy(void ***a1)
{
void **v2; // rdi

v2 = *a1;
if ( v2 )
{
if ( v2[1] )
{
free(v2[1]);
v2 = *a1;
}
free(v2);
*a1 = 0LL;
}
}

original_code:
void
ndn_bloom_destroy(struct ndn_bloom **bp)
{
    if (*bp != ((void *)0)) {
        if ((*bp)->wire != ((void *)0))
            free((*bp)->wire);
        free(*bp);
        *bp = ((void *)0);
    }
}

variable_types: struct ndn_bloom { int n; struct ndn_bloom_wire { unsigned char lg_bits; unsigned char n_hash; unsigned char method; unsigned char reserved; unsigned char seed[4]; unsigned char bloom[1024]; } *wire; } **

user_defined_types: struct ndn_bloom { int n; struct ndn_bloom_wire *wire; }


decompiled_code:
__int64 __fastcall ndn_bloom_insert(__int64 a1, unsigned __int8 *a2)
{
int v3; // edi
int v4; // er11
__int64 v5; // rdx
unsigned __int8 *v7; // r9
int i; // er12
int v9; // ecx
int v10; // edx
__int64 v11; // rdx
__int64 v12; // r8
int v13; // eax
int v14; // er9
unsigned int v15; // er9
int v16; // er11
__int64 result; // rax

v3 = bloom_seed(*(_QWORD *)(a1 + 8));
if ( v5 )
{
do
v3 = bloom_nexthash(v3, (unsigned int)*a2 + 1);
while ( v7 != a2 );
}
if ( v4 )
{
for ( i = 0; i != v16; ++i )
{
v3 = bloom_nexthash(v3, 0);
v10 = v3 & v9;
LOBYTE(v9) = v3 & v9 & 7;
v11 = v10 >> 3;
v13 = *(unsigned __int8 *)(v12 + v11 + 8);
*(_BYTE *)(v12 + v11 + 8) = v13 | (1 << v9);
v15 = (((v13 >> v9) & 1) == 0) + v14;
}
++*(_DWORD *)a1;
result = v15;
}
else
{
++*(_DWORD *)a1;
result = 0LL;
}
return result;
}

original_code:
int
ndn_bloom_insert(struct ndn_bloom *b, const void *key, size_t size)
{
    int d = 0;
    struct ndn_bloom_wire *f = b->wire;
    int h, i, k, m, n, s;
    const unsigned char *hb = (const unsigned char *)key;
    n = f->n_hash;
    m = (8*sizeof(f->bloom) - 1) & ((1 << f->lg_bits) - 1);
    s = bloom_seed(f);
    for (k = 0; k < size; k++)
        s = bloom_nexthash(s, hb[k] + 1);
    for (i = 0; i < n; i++) {
        s = bloom_nexthash(s, 0);
        h = s & m;
        if (0 == (f->bloom[h >> 3] & (1 << (h & 7)))) {
            f->bloom[h >> 3] |= (1 << (h & 7));
            d++;
        }
        f->bloom[h >> 3] |= (1 << (h & 7));
    }
    b->n += 1;
    return(d);
}

canonical_original_code:
int ndn_bloom_insert(struct ndn_bloom *b, void *key, unsigned long size)
{
    int d = 0;
    struct ndn_bloom_wire *f = b->wire;
    int h; int i; int k; int m; int n; int s;
    unsigned char *hb = (const unsigned char *)key;
    n = f->n_hash;
    m = (8*sizeof(f->bloom) - 1) & ((1 << f->lg_bits) - 1);
    s = bloom_seed(f);
    for (k = 0; k < size; k++)
        s = bloom_nexthash(s, hb[k] + 1);
    for (i = 0; i < n; i++) {
        s = bloom_nexthash(s, 0);
        h = s & m;
        if (0 == (f->bloom[h >> 3] & (1 << (h & 7)))) {
            f->bloom[h >> 3] |= (1 << (h & 7));
            d++;
        }
        f->bloom[h >> 3] |= (1 << (h & 7));
    }
    b->n += 1;
    return(d);
}

variable_types: struct ndn_bloom { int n; struct ndn_bloom_wire { unsigned char lg_bits; unsigned char n_hash; unsigned char method; unsigned char reserved; unsigned char seed[4]; unsigned char bloom[1024]; } *wire; } *

variable_types:
key
void *

variable_types:
size
unsigned long

variable_types: d int

variable_types: h int

variable_types: m int

variable_types:
hb
unsigned char *


decompiled_code:
__int64 __fastcall ndn_bloom_match_wire(__int64 a1, unsigned __int8 *a2)
{
int v2; // eax
int v3; // er10
int v4; // edi
__int64 v5; // rdx
unsigned __int8 *v7; // r11
int v8; // er10
int v9; // er11
int v10; // ecx
__int64 v11; // r9
__int64 result; // rax

v2 = bloom_seed(a1);
v3 = *(unsigned __int8 *)(a1 + 1);
v4 = v2;
if ( v5 )
{
do
v4 = bloom_nexthash(v4, (unsigned int)*a2 + 1);
while ( v7 != a2 );
}
if ( !v3 )
return 1LL;
do
{
v4 = bloom_nexthash(v4, 0);
result = ((int)*(unsigned __int8 *)(v11 + ((v4 & v10) >> 3) + 8) >> (v4 & v10 & 7)) & 1;
}
while ( (_DWORD)result && v8 != v9 + 1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int8 *a2)
{
int v2; // eax
int v3; // er10
int v4; // edi
__int64 v5; // rdx
unsigned __int8 *v7; // r11
int v8; // er10
int v9; // er11
int v10; // ecx
__int64 v11; // r9
__int64 result; // rax

v2 = func0(a1);
v3 = *(unsigned __int8 *)(a1 + 1);
v4 = v2;
if ( v5 )
{
do
v4 = func1(v4, (unsigned int)*a2 + 1);
while ( v7 != a2 );
}
if ( !v3 )
return 1LL;
do
{
v4 = func1(v4, 0);
result = ((int)*(unsigned __int8 *)(v11 + ((v4 & v10) >> 3) + 8) >> (v4 & v10 & 7)) & 1;
}
while ( (_DWORD)result && v8 != v9 + 1 );
return result;
}

original_code:
int
ndn_bloom_match_wire(const struct ndn_bloom_wire *f, const void *key, size_t size)
{
    int h, i, k, m, n, s;
    const unsigned char *hb = (const unsigned char *)key;
    n = f->n_hash;
    m = (8*sizeof(f->bloom) - 1) & ((1 << f->lg_bits) - 1);
    s = bloom_seed(f);
    for (k = 0; k < size; k++)
        s = bloom_nexthash(s, hb[k] + 1);
    for (i = 0; i < n; i++) {
        s = bloom_nexthash(s, 0);
        if (k >= size)
            k = 0;
        h = s & m;
        if (0 == (f->bloom[h >> 3] & (1 << (h & 7))))
            return(0);
    }
    return(1);
}

canonical_original_code:
int ndn_bloom_match_wire(struct ndn_bloom_wire *f, void *key, unsigned long size)
{
    int h; int i; int k; int m; int n; int s;
    unsigned char *hb = (const unsigned char *)key;
    n = f->n_hash;
    m = (8*sizeof(f->bloom) - 1) & ((1 << f->lg_bits) - 1);
    s = bloom_seed(f);
    for (k = 0; k < size; k++)
        s = bloom_nexthash(s, hb[k] + 1);
    for (i = 0; i < n; i++) {
        s = bloom_nexthash(s, 0);
        if (k >= size)
            k = 0;
        h = s & m;
        if (0 == (f->bloom[h >> 3] & (1 << (h & 7))))
            return(0);
    }
    return(1);
}

variable_types: i int

user_defined_types: struct ndn_bloom_wire { unsigned char lg_bits; unsigned char n_hash; unsigned char method; unsigned char reserved; unsigned char seed[4]; unsigned char bloom[1024]; }


decompiled_code:
__int64 __fastcall ndn_bloom_match(__int64 a1, unsigned __int8 *a2)
{
return ndn_bloom_match_wire(*(_QWORD *)(a1 + 8), a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned __int8 *a2)
{
return func6(*(_QWORD *)(a1 + 8), a2);
}

original_code:
int
ndn_bloom_match(struct ndn_bloom *b, const void *key, size_t size)
{
    return(ndn_bloom_match_wire(b->wire, key, size));
}

canonical_original_code:
int ndn_bloom_match(struct ndn_bloom *b, void *key, unsigned long size)
{
    return(ndn_bloom_match_wire(b->wire, key, size));
}


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

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

original_code:
int
ndn_bloom_n(struct ndn_bloom *b)
{
    return(b->n);
}


decompiled_code:
__int64 __fastcall ndn_bloom_wiresize(__int64 a1)
{
_BYTE *v1; // rax
__int64 result; // rax

v1 = *(_BYTE **)(a1 + 8);
if ( v1 )
result = (unsigned int)((1 << (*v1 - 3)) + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
_BYTE *v1; // rax
__int64 result; // rax

v1 = *(_BYTE **)(a1 + 8);
if ( v1 )
result = (unsigned int)((1 << (*v1 - 3)) + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
ndn_bloom_wiresize(struct ndn_bloom *b)
{
    const struct ndn_bloom_wire *f = (b->wire);
    if (f == ((void *)0))
        return(-1);
    return((sizeof(*f) - sizeof(f->bloom)) + (1 << (f->lg_bits - 3)));
}

canonical_original_code:
int ndn_bloom_wiresize(struct ndn_bloom *b)
{
    struct ndn_bloom_wire *f = (b->wire);
    if (f == ((void *)0))
        return(-1);
    return((sizeof(*f) - sizeof(f->bloom)) + (1 << (f->lg_bits - 3)));
}


decompiled_code:
__int64 __fastcall ndn_bloom_store_wire(__int64 a1, void *a2, __int64 a3)
{
int v4; // eax

v4 = ndn_bloom_wiresize(a1);
if ( v4 < 0 || v4 != a3 )
return 0xFFFFFFFFLL;
memcpy(a2, *(const void **)(a1 + 8), v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, void *a2, __int64 a3)
{
int v4; // eax

v4 = func9(a1);
if ( v4 < 0 || v4 != a3 )
return 0xFFFFFFFFLL;
memcpy(a2, *(const void **)(a1 + 8), v4);
return 0LL;
}

original_code:
int
ndn_bloom_store_wire(struct ndn_bloom *b, unsigned char *dest, size_t destsize)
{
    int wiresize = ndn_bloom_wiresize(b);
    if (wiresize < 0 || destsize != wiresize)
        return(-1);
    memcpy(dest, b->wire, destsize);
    return(0);
}

canonical_original_code:
int ndn_bloom_store_wire(struct ndn_bloom *b, unsigned char *dest, unsigned long destsize)
{
    int wiresize = ndn_bloom_wiresize(b);
    if (wiresize < 0 || destsize != wiresize)
        return(-1);
    memcpy(dest, b->wire, destsize);
    return(0);
}

variable_types:
dest
unsigned char *

variable_types:
destsize
unsigned long

variable_types: wiresize int


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

if ( (unsigned int)ndn_buf_match_dtag() )
{
ndn_buf_advance(a1);
v4 = ndn_parse_uintmax(a1, a3);
ndn_buf_check_close(a1);
}
else
{
*(_DWORD *)(a1 + 8) = -45;
v4 = -45;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12

if ( (unsigned int)ndn_buf_match_dtag() )
{
ndn_buf_advance(a1);
v4 = ndn_parse_uintmax(a1, a3);
ndn_buf_check_close(a1);
}
else
{
*(_DWORD *)(a1 + 8) = -45;
v4 = -45;
}
return v4;
}

original_code:
int
ndn_parse_tagged_required_uintmax(struct ndn_buf_decoder *d, enum ndn_dtag dtag, uintmax_t *result)
{
    int res = -1;
    if (ndn_buf_match_dtag(d, dtag)) {
        ndn_buf_advance(d);
        res = ndn_parse_uintmax(d, result);
        ndn_buf_check_close(d);
    } else {
        return (d->decoder.state = -45);
    }
    return (res);
}

canonical_original_code:
int ndn_parse_tagged_required_uintmax(struct ndn_buf_decoder *d, enum ndn_dtag dtag, unsigned long *result)
{
    int res = -1;
    if (ndn_buf_match_dtag(d, dtag)) {
        ndn_buf_advance(d);
        res = ndn_parse_uintmax(d, result);
        ndn_buf_check_close(d);
    } else {
        return (d->decoder.state = -45);
    }
    return (res);
}

variable_types: struct ndn_buf_decoder { struct ndn_skeleton_decoder { long index; int state; int nest; unsigned long numval; unsigned long token_index; unsigned long element_index; } decoder; unsigned char *buf; unsigned long size; } *

variable_types: enum ndn_dtag { NDN_DTAG_Any=13, NDN_DTAG_Name=14, NDN_DTAG_Component=15, NDN_DTAG_Certificate=16, NDN_DTAG_Collection=17, NDN_DTAG_CompleteName=18, NDN_DTAG_Content=19, NDN_DTAG_SignedInfo=20, NDN_DTAG_ContentDigest=21, NDN_DTAG_ContentHash=22, NDN_DTAG_Count=24, NDN_DTAG_Header=25, NDN_DTAG_Interest=26, NDN_DTAG_Key=27, NDN_DTAG_KeyLocator=28, NDN_DTAG_KeyName=29, NDN_DTAG_Length=30, NDN_DTAG_Link=31, NDN_DTAG_LinkAuthenticator=32, NDN_DTAG_NameComponentCount=33, NDN_DTAG_ExtOpt=34, NDN_DTAG_RootDigest=36, NDN_DTAG_Signature=37, NDN_DTAG_Start=38, NDN_DTAG_Timestamp=39, NDN_DTAG_Type=40, NDN_DTAG_Nonce=41, NDN_DTAG_Scope=42, NDN_DTAG_Exclude=43, NDN_DTAG_Bloom=44, NDN_DTAG_BloomSeed=45, NDN_DTAG_AnswerOriginKind=47, NDN_DTAG_InterestLifetime=48, NDN_DTAG_Witness=53, NDN_DTAG_SignatureBits=54, NDN_DTAG_DigestAlgorithm=55, NDN_DTAG_BlockSize=56, NDN_DTAG_FreshnessSeconds=58, NDN_DTAG_FinalBlockID=59, NDN_DTAG_PublisherPublicKeyDigest=60, NDN_DTAG_PublisherCertificateDigest=61, NDN_DTAG_PublisherIssuerKeyDigest=62, NDN_DTAG_PublisherIssuerCertificateDigest=63, NDN_DTAG_ContentObject=64, NDN_DTAG_WrappedKey=65, NDN_DTAG_WrappingKeyIdentifier=66, NDN_DTAG_WrapAlgorithm=67, NDN_DTAG_KeyAlgorithm=68, NDN_DTAG_Label=69, NDN_DTAG_EncryptedKey=70, NDN_DTAG_EncryptedNonceKey=71, NDN_DTAG_WrappingKeyName=72, NDN_DTAG_Action=73, NDN_DTAG_FaceID=74, NDN_DTAG_IPProto=75, NDN_DTAG_Host=76, NDN_DTAG_Port=77, NDN_DTAG_MulticastInterface=78, NDN_DTAG_ForwardingFlags=79, NDN_DTAG_FaceInstance=80, NDN_DTAG_ForwardingEntry=81, NDN_DTAG_MulticastTTL=82, NDN_DTAG_MinSuffixComponents=83, NDN_DTAG_MaxSuffixComponents=84, NDN_DTAG_ChildSelector=85, NDN_DTAG_RepositoryInfo=86, NDN_DTAG_Version=87, NDN_DTAG_RepositoryVersion=88, NDN_DTAG_GlobalPrefix=89, NDN_DTAG_LocalName=90, NDN_DTAG_Policy=91, NDN_DTAG_Namespace=92, NDN_DTAG_GlobalPrefixName=93, NDN_DTAG_PolicyVersion=94, NDN_DTAG_KeyValueSet=95, NDN_DTAG_KeyValuePair=96, NDN_DTAG_IntegerValue=97, NDN_DTAG_DecimalValue=98, NDN_DTAG_StringValue=99, NDN_DTAG_BinaryValue=100, NDN_DTAG_NameValue=101, NDN_DTAG_Entry=102, NDN_DTAG_ACL=103, NDN_DTAG_ParameterizedName=104, NDN_DTAG_Prefix=105, NDN_DTAG_Suffix=106, NDN_DTAG_Root=107, NDN_DTAG_ProfileName=108, NDN_DTAG_Parameters=109, NDN_DTAG_InfoString=110, NDN_DTAG_StatusResponse=112, NDN_DTAG_StatusCode=113, NDN_DTAG_StatusText=114, NDN_DTAG_SyncNode=115, NDN_DTAG_SyncNodeKind=116, NDN_DTAG_SyncNodeElement=117, NDN_DTAG_SyncVersion=118, NDN_DTAG_SyncNodeElements=119, NDN_DTAG_SyncContentHash=120, NDN_DTAG_SyncLeafCount=121, NDN_DTAG_SyncTreeDepth=122, NDN_DTAG_SyncByteCount=123, NDN_DTAG_SyncConfigSlice=124, NDN_DTAG_SyncConfigSliceList=125, NDN_DTAG_SyncConfigSliceOp=126, NDN_DTAG_SyncNodeDeltas=127, NDN_DTAG_SequenceNumber=256, NDN_DTAG_NDNProtocolDataUnit=20587744 }

variable_types:
result
unsigned long *

variable_types: res int


decompiled_code:
void __fastcall ndn_header_destroy(void **a1)
{
char *v2; // rdi

v2 = (char *)*a1;
if ( v2 )
{
ndn_charbuf_destroy(v2 + 32);
ndn_charbuf_destroy((char *)*a1 + 40);
free(*a1);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
char *v2; // rdi

v2 = (char *)*a1;
if ( v2 )
{
ndn_charbuf_destroy(v2 + 32);
ndn_charbuf_destroy((char *)*a1 + 40);
free(*a1);
*a1 = 0LL;
}
}

original_code:
void
ndn_header_destroy(struct ndn_header **ph)
{
    if (*ph == ((void *)0))
        return;
    ndn_charbuf_destroy(&(*ph)->root_digest);
    ndn_charbuf_destroy(&(*ph)->content_digest);
    free(*ph);
    *ph = ((void *)0);
}

variable_types: struct ndn_header { unsigned long start; unsigned long count; unsigned long block_size; unsigned long length; struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *root_digest; struct ndn_charbuf *content_digest; } **

user_defined_types: struct ndn_header { unsigned long start; unsigned long count; unsigned long block_size; unsigned long length; struct ndn_charbuf *root_digest; struct ndn_charbuf *content_digest; }