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

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

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

if ( !a1 )
return (unsigned int)-1;
if ( *a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( *(_QWORD *)(a1[2] + 8 * v2) == a2 )
break;
v3 = ++v2;
if ( *a1 == v2 )
goto LABEL_6;
}
}
else
{
v3 = 0;
LABEL_6:
if ( (int)func4(a1, a2) < 0 )
v3 = -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);
}


repo: danihegglin/ChronosAndroid

decompiled_code:
__int64 __fastcall ndn_indexbuf_remove_first_match(__int64 *a1, __int64 a2)
{
__int64 v2; // r8
_QWORD *v3; // rax
__int64 i; // rdx
unsigned int v5; // ebp

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
if ( (int)*a1 <= 0 )
return (unsigned int)-1;
v3 = (_QWORD *)a1[2];
for ( i = 0LL; ; ++i )
{
v5 = i;
if ( *v3 == a2 )
break;
++v3;
if ( i == (_DWORD)v2 - 1 )
return (unsigned int)-1;
}
if ( (int)i + 1 < (int)v2 )
memmove(v3, (const void *)(a1[2] + 8 * i + 8), 8LL * ((int)v2 - (int)i - 1));
--*a1;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, __int64 a2)
{
__int64 v2; // r8
_QWORD *v3; // rax
__int64 i; // rdx
unsigned int v5; // ebp

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
if ( (int)*a1 <= 0 )
return (unsigned int)-1;
v3 = (_QWORD *)a1[2];
for ( i = 0LL; ; ++i )
{
v5 = i;
if ( *v3 == a2 )
break;
++v3;
if ( i == (_DWORD)v2 - 1 )
return (unsigned int)-1;
}
if ( (int)i + 1 < (int)v2 )
memmove(v3, (const void *)(a1[2] + 8 * i + 8), 8LL * ((int)v2 - (int)i - 1));
--*a1;
return v5;
}

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: struct ndn_indexbuf { unsigned long n; unsigned long limit; unsigned long *buf; } *

variable_types:
val
unsigned long

variable_types: i int

variable_types: n int

return_type: 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;
        }
    }
}

return_type: void

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


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

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

if ( *a1 )
{
v2 = (void *)*((_QWORD *)*a1 + 1);
if ( v2 )
free(v2);
free(*a1);
*a1 = 0LL;
}
}

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

if ( *a1 )
{
v2 = (void *)*((_QWORD *)*a1 + 1);
if ( v2 )
free(v2);
free(*a1);
*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; }


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(_BYTE *a1, unsigned __int8 *a2, unsigned __int64 a3)
{
int v5; // er14
int v6; // ebp
int v7; // edi
unsigned __int8 *v8; // rbx
int v9; // ebx
int i; // er15
__int64 result; // rax

v5 = (unsigned __int8)a1[1];
v6 = ((unsigned __int16)(1 << *a1) - 1) & 0x1FFF;
v7 = bloom_seed((__int64)a1);
if ( a3 )
{
v8 = a2;
do
v7 = bloom_nexthash(v7, (unsigned int)*v8++ + 1);
while ( &a2[a3] != v8 );
v9 = a3;
}
else
{
v9 = 0;
}
if ( v5 <= 0 )
return 1LL;
for ( i = 0; i != v5; ++i )
{
v7 = bloom_nexthash(v7, 0);
if ( v9 >= a3 )
v9 = 0;
result = ((int)(unsigned __int8)a1[((v7 & v6) >> 3) + 8] >> (v7 & v6 & 7)) & 1;
if ( (((int)(unsigned __int8)a1[((v7 & v6) >> 3) + 8] >> (v7 & v6 & 7)) & 1) == 0 )
break;
}
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, unsigned __int64 a3)
{
return ndn_bloom_match_wire(*(_BYTE **)(a1 + 8), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int8 *a2, unsigned __int64 a3)
{
return func4(*(_BYTE **)(a1 + 8), a2, a3);
}

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 func6(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 func7(__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, size_t a3)
{
int v4; // eax

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

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

v4 = func7(a1);
if ( v4 < 0 )
return 0xFFFFFFFFLL;
if ( v4 != a3 )
return 0xFFFFFFFFLL;
memcpy(a2, *(const void **)(a1 + 8), a3);
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; // ebp

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; // ebp

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

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


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; }


decompiled_code:
void *__fastcall ndn_header_parse(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
void *result; // rax
int v4; // er12
int v5; // er12
int v6; // er12
_QWORD *v7; // r12
_QWORD *v8; // r12
__int64 v9; // [rsp+8h] [rbp-70h] BYREF
__int64 v10; // [rsp+10h] [rbp-68h] BYREF
void *ptr; // [rsp+18h] [rbp-60h] BYREF
char v12[88]; // [rsp+20h] [rbp-58h] BYREF

v2 = ndn_buf_decoder_start(v12, a1, a2);
result = calloc(1uLL, 0x30uLL);
ptr = result;
if ( result )
{
if ( (unsigned int)ndn_buf_match_dtag(v2, 25LL) )
{
ndn_buf_advance(v2);
v4 = ndn_parse_tagged_required_uintmax(v2, 38LL, (__int64)ptr);
v5 = ndn_parse_tagged_required_uintmax(v2, 24LL, (__int64)ptr + 8) | v4;
v6 = ndn_parse_tagged_required_uintmax(v2, 56LL, (__int64)ptr + 16) | v5;
if ( (unsigned int)ndn_parse_tagged_required_uintmax(v2, 30LL, (__int64)ptr + 24) | v6 )
{
free(ptr);
return 0LL;
}
if ( (unsigned int)ndn_buf_match_dtag(v2, 21LL) )
{
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, &v10, &v9) )
{
v7 = ptr;
v7[5] = ndn_charbuf_create();
ndn_charbuf_append(*((_QWORD *)ptr + 5), v10, v9);
ndn_buf_advance(v2);
}
ndn_buf_check_close(v2);
}
if ( (unsigned int)ndn_buf_match_dtag(v2, 36LL) )
{
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, &v10, &v9) )
{
v8 = ptr;
v8[4] = ndn_charbuf_create();
ndn_charbuf_append(*((_QWORD *)ptr + 4), v10, v9);
ndn_buf_advance(v2);
}
ndn_buf_check_close(v2);
}
ndn_buf_check_close(v2);
if ( *(_QWORD *)v2 == a2 && (*(_WORD *)(v2 + 8) & 0x7FFF) == 0 )
goto LABEL_5;
}
else
{
*(_DWORD *)(v2 + 8) = -96;
}
ndn_header_destroy(&ptr);
LABEL_5:
result = ptr;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
void *result; // rax
int v4; // er12
int v5; // er12
int v6; // er12
_QWORD *v7; // r12
_QWORD *v8; // r12
__int64 v9; // [rsp+8h] [rbp-70h] BYREF
__int64 v10; // [rsp+10h] [rbp-68h] BYREF
void *ptr; // [rsp+18h] [rbp-60h] BYREF
char v12[88]; // [rsp+20h] [rbp-58h] BYREF

v2 = ndn_buf_decoder_start(v12, a1, a2);
result = calloc(1uLL, 0x30uLL);
ptr = result;
if ( result )
{
if ( (unsigned int)ndn_buf_match_dtag(v2, 25LL) )
{
ndn_buf_advance(v2);
v4 = func0(v2, 38LL, (__int64)ptr);
v5 = func0(v2, 24LL, (__int64)ptr + 8) | v4;
v6 = func0(v2, 56LL, (__int64)ptr + 16) | v5;
if ( (unsigned int)func0(v2, 30LL, (__int64)ptr + 24) | v6 )
{
free(ptr);
return 0LL;
}
if ( (unsigned int)ndn_buf_match_dtag(v2, 21LL) )
{
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, &v10, &v9) )
{
v7 = ptr;
v7[5] = ndn_charbuf_create();
ndn_charbuf_append(*((_QWORD *)ptr + 5), v10, v9);
ndn_buf_advance(v2);
}
ndn_buf_check_close(v2);
}
if ( (unsigned int)ndn_buf_match_dtag(v2, 36LL) )
{
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, &v10, &v9) )
{
v8 = ptr;
v8[4] = ndn_charbuf_create();
ndn_charbuf_append(*((_QWORD *)ptr + 4), v10, v9);
ndn_buf_advance(v2);
}
ndn_buf_check_close(v2);
}
ndn_buf_check_close(v2);
if ( *(_QWORD *)v2 == a2 && (*(_WORD *)(v2 + 8) & 0x7FFF) == 0 )
goto LABEL_5;
}
else
{
*(_DWORD *)(v2 + 8) = -96;
}
func1(&ptr);
LABEL_5:
result = ptr;
}
return result;
}

original_code:
struct ndn_header *
ndn_header_parse(const unsigned char *p, size_t size)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, p, size);
    struct ndn_header *result;
    const unsigned char *blob;
    size_t blobsize;
    int res = 0;
    result = calloc(1, sizeof(*result));
    if (result == ((void *)0))
        return (((void *)0));
    if (ndn_buf_match_dtag(d, NDN_DTAG_Header)) {
        ndn_buf_advance(d);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_Start, &result->start);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_Count, &result->count);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_BlockSize, &result->block_size);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_Length, &result->length);
        if (res != 0) {
            free(result);
            return (((void *)0));
        }
        if (ndn_buf_match_dtag(d, NDN_DTAG_ContentDigest)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &blob, &blobsize)) {
                result->content_digest = ndn_charbuf_create();
                ndn_charbuf_append(result->content_digest, blob, blobsize);
                ndn_buf_advance(d);
            }
            ndn_buf_check_close(d);
        }
        if (ndn_buf_match_dtag(d, NDN_DTAG_RootDigest)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &blob, &blobsize)) {
                result->root_digest = ndn_charbuf_create();
                ndn_charbuf_append(result->root_digest, blob, blobsize);
                ndn_buf_advance(d);
            }
            ndn_buf_check_close(d);
        }
        ndn_buf_check_close(d);
    }
    else
        d->decoder.state = -96;
    if (d->decoder.index != size || !(((d->decoder.state) & ((1 << 15)-1)) == 0)) {
        ndn_header_destroy(&result);
    }
    return (result);
}

canonical_original_code:
struct ndn_header *ndn_header_parse(unsigned char *p, unsigned long size)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, p, size);
    struct ndn_header *result;
    unsigned char *blob;
    unsigned long blobsize;
    int res = 0;
    result = calloc(1, sizeof(*result));
    if (result == ((void *)0))
        return (((void *)0));
    if (ndn_buf_match_dtag(d, NDN_DTAG_Header)) {
        ndn_buf_advance(d);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_Start, &result->start);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_Count, &result->count);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_BlockSize, &result->block_size);
        res |= ndn_parse_tagged_required_uintmax(d, NDN_DTAG_Length, &result->length);
        if (res != 0) {
            free(result);
            return (((void *)0));
        }
        if (ndn_buf_match_dtag(d, NDN_DTAG_ContentDigest)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &blob, &blobsize)) {
                result->content_digest = ndn_charbuf_create();
                ndn_charbuf_append(result->content_digest, blob, blobsize);
                ndn_buf_advance(d);
            }
            ndn_buf_check_close(d);
        }
        if (ndn_buf_match_dtag(d, NDN_DTAG_RootDigest)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &blob, &blobsize)) {
                result->root_digest = ndn_charbuf_create();
                ndn_charbuf_append(result->root_digest, blob, blobsize);
                ndn_buf_advance(d);
            }
            ndn_buf_check_close(d);
        }
        ndn_buf_check_close(d);
    }
    else
        d->decoder.state = -96;
    if (d->decoder.index != size || !(((d->decoder.state) & ((1 << 15)-1)) == 0)) {
        ndn_header_destroy(&result);
    }
    return (result);
}

variable_types:
p
unsigned char *

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: 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; } *

variable_types:
blob
unsigned char *

variable_types:
blobsize
unsigned long


decompiled_code:
__int64 __fastcall ndnb_append_header(__int64 a1, _QWORD *a2)
{
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
_QWORD *v7; // rax
_QWORD *v8; // rax

v2 = ndnb_element_begin(a1, 25LL);
v3 = ndnb_tagged_putf(a1, 38LL, &LC0, *a2) | v2;
v4 = ndnb_tagged_putf(a1, 24LL, &LC0, a2[1]) | v3;
v5 = ndnb_tagged_putf(a1, 56LL, &LC0, a2[2]) | v4;
v6 = ndnb_tagged_putf(a1, 30LL, &LC0, a2[3]) | v5;
v7 = (_QWORD *)a2[5];
if ( v7 )
v6 |= ndnb_append_tagged_blob(a1, 21LL, v7[2], *v7);
v8 = (_QWORD *)a2[4];
if ( v8 )
v6 |= ndnb_append_tagged_blob(a1, 36LL, v8[2], *v8);
return v6 | (unsigned int)ndnb_element_end(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
int v2; // ebx
int v3; // ebx
int v4; // ebx
int v5; // ebx
int v6; // ebx
_QWORD *v7; // rax
_QWORD *v8; // rax

v2 = ndnb_element_begin(a1, 25LL);
v3 = ndnb_tagged_putf(a1, 38LL, &LC0, *a2) | v2;
v4 = ndnb_tagged_putf(a1, 24LL, &LC0, a2[1]) | v3;
v5 = ndnb_tagged_putf(a1, 56LL, &LC0, a2[2]) | v4;
v6 = ndnb_tagged_putf(a1, 30LL, &LC0, a2[3]) | v5;
v7 = (_QWORD *)a2[5];
if ( v7 )
v6 |= ndnb_append_tagged_blob(a1, 21LL, v7[2], *v7);
v8 = (_QWORD *)a2[4];
if ( v8 )
v6 |= ndnb_append_tagged_blob(a1, 36LL, v8[2], *v8);
return v6 | (unsigned int)ndnb_element_end(a1);
}

original_code:
int
ndnb_append_header(struct ndn_charbuf *c,
                   const struct ndn_header *h)
{
    int res;
    res = ndnb_element_begin(c, NDN_DTAG_Header);
    res |= ndnb_tagged_putf(c, NDN_DTAG_Start, "%u", h->start);
    res |= ndnb_tagged_putf(c, NDN_DTAG_Count, "%u", h->count);
    res |= ndnb_tagged_putf(c, NDN_DTAG_BlockSize, "%u", h->block_size);
    res |= ndnb_tagged_putf(c, NDN_DTAG_Length, "%u", h->length);
    if (h->content_digest != ((void *)0)) {
        res |= ndnb_append_tagged_blob(c, NDN_DTAG_ContentDigest,
                                       h->content_digest->buf, h->content_digest->length);
    }
    if (h->root_digest != ((void *)0)) {
        res |= ndnb_append_tagged_blob(c, NDN_DTAG_RootDigest,
                                       h->root_digest->buf, h->root_digest->length);
    }
    res |= ndnb_element_end(c);
    return (res);
}

canonical_original_code:
int ndnb_append_header(struct ndn_charbuf *c, struct ndn_header *h)
{
    int res;
    res = ndnb_element_begin(c, NDN_DTAG_Header);
    res |= ndnb_tagged_putf(c, NDN_DTAG_Start, "%u", h->start);
    res |= ndnb_tagged_putf(c, NDN_DTAG_Count, "%u", h->count);
    res |= ndnb_tagged_putf(c, NDN_DTAG_BlockSize, "%u", h->block_size);
    res |= ndnb_tagged_putf(c, NDN_DTAG_Length, "%u", h->length);
    if (h->content_digest != ((void *)0)) {
        res |= ndnb_append_tagged_blob(c, NDN_DTAG_ContentDigest,
                                       h->content_digest->buf, h->content_digest->length);
    }
    if (h->root_digest != ((void *)0)) {
        res |= ndnb_append_tagged_blob(c, NDN_DTAG_RootDigest,
                                       h->root_digest->buf, h->root_digest->length);
    }
    res |= ndnb_element_end(c);
    return (res);
}

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

variable_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; } *


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

*a1 = 0LL;
result = ndn_charbuf_append_tt(a1, 14LL, 2LL);
if ( (_DWORD)result != -1 )
result = ndn_charbuf_append_closer(a1);
return result;
}

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

*a1 = 0LL;
result = ndn_charbuf_append_tt(a1, 14LL, 2LL);
if ( (_DWORD)result != -1 )
result = ndn_charbuf_append_closer(a1);
return result;
}

original_code:
int
ndn_name_init(struct ndn_charbuf *c)
{
    int res;
    c->length = 0;
    res = ndn_charbuf_append_tt(c, NDN_DTAG_Name, NDN_DTAG);
    if (res == -1) return(res);
    res = ndn_charbuf_append_closer(c);
    return(res);
}

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


decompiled_code:
__int64 __fastcall ndn_name_append(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 result; // rax
__int16 v6[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v6[0] = 0;
v3 = *a1;
if ( (unsigned __int64)*a1 <= 1 )
return 0xFFFFFFFFLL;
if ( *(_BYTE *)(a1[2] + v3 - 1) )
return 0xFFFFFFFFLL;
*a1 = v3 - 1;
ndn_charbuf_reserve(a1, a3 + 8);
result = ndn_charbuf_append_tt(a1, 15LL, 2LL);
if ( (_DWORD)result != -1 )
{
result = ndn_charbuf_append_tt(a1, a3, 5LL);
if ( (_DWORD)result != -1 )
{
result = ndn_charbuf_append(a1, a2, a3);
if ( (_DWORD)result != -1 )
result = ndn_charbuf_append(a1, v6, 2LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax
__int64 result; // rax
__int16 v6[13]; // [rsp+Eh] [rbp-1Ah] BYREF

v6[0] = 0;
v3 = *a1;
if ( (unsigned __int64)*a1 <= 1 )
return 0xFFFFFFFFLL;
if ( *(_BYTE *)(a1[2] + v3 - 1) )
return 0xFFFFFFFFLL;
*a1 = v3 - 1;
ndn_charbuf_reserve(a1, a3 + 8);
result = ndn_charbuf_append_tt(a1, 15LL, 2LL);
if ( (_DWORD)result != -1 )
{
result = ndn_charbuf_append_tt(a1, a3, 5LL);
if ( (_DWORD)result != -1 )
{
result = ndn_charbuf_append(a1, a2, a3);
if ( (_DWORD)result != -1 )
result = ndn_charbuf_append(a1, v6, 2LL);
}
}
return result;
}

original_code:
int
ndn_name_append(struct ndn_charbuf *c, const void *component, size_t n)
{
    int res;
    const unsigned char closer[2] = {((unsigned char)(0)), ((unsigned char)(0))};
    if (c->length < 2 || c->buf[c->length-1] != closer[1])
        return(-1);
    c->length -= 1;
    ndn_charbuf_reserve(c, n + 8);
    res = ndn_charbuf_append_tt(c, NDN_DTAG_Component, NDN_DTAG);
    if (res == -1) return(res);
    res = ndn_charbuf_append_tt(c, n, NDN_BLOB);
    if (res == -1) return(res);
    res = ndn_charbuf_append(c, component, n);
    if (res == -1) return(res);
    res = ndn_charbuf_append(c, closer, sizeof(closer));
    return(res);
}

canonical_original_code:
int ndn_name_append(struct ndn_charbuf *c, void *component, unsigned long n)
{
    int res;
    unsigned char closer[2] = {((unsigned char)(0)), ((unsigned char)(0))};
    if (c->length < 2 || c->buf[c->length-1] != closer[1])
        return(-1);
    c->length -= 1;
    ndn_charbuf_reserve(c, n + 8);
    res = ndn_charbuf_append_tt(c, NDN_DTAG_Component, NDN_DTAG);
    if (res == -1) return(res);
    res = ndn_charbuf_append_tt(c, n, NDN_BLOB);
    if (res == -1) return(res);
    res = ndn_charbuf_append(c, component, n);
    if (res == -1) return(res);
    res = ndn_charbuf_append(c, closer, sizeof(closer));
    return(res);
}

variable_types:
component
void *

variable_types:
n
unsigned long

variable_types:
closer
unsigned char [2]


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

v2 = strlen(a2);
return ndn_name_append(a1, (__int64)a2, v2);
}

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

v2 = strlen(a2);
return func1(a1, (__int64)a2, v2);
}

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

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

variable_types:
s
char *


decompiled_code:
__int64 __fastcall ndn_name_append_numeric(__int64 *a1, int a2, unsigned __int64 a3)
{
__int64 v4; // rax
int v5; // edi
bool v6; // cl
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

if ( a3 )
{
v4 = 31LL;
do
{
v5 = v4;
v8[v4] = a3;
a3 >>= 8;
v6 = (int)v4-- > 0;
}
while ( v6 && a3 != 0 );
if ( v5 <= 0 )
return 0xFFFFFFFFLL;
}
else
{
v5 = 32;
}
if ( a2 >= 0 )
v8[--v5] = a2;
return ndn_name_append(a1, (__int64)&v8[v5], 32LL - v5);
}

original_code:
int
ndn_name_append_numeric(struct ndn_charbuf *c,
                        enum ndn_marker marker, uintmax_t value)
{
    uintmax_t v;
    int i;
    char b[32];
    for (v = value, i = sizeof(b); v != 0 && i > 0; i--, v >>= 8)
        b[i-1] = v & 0xff;
    if (i < 1)
        return(-1);
    if (marker >= 0)
        b[--i] = marker;
    return(ndn_name_append(c, b + i, sizeof(b) - i));
}

canonical_original_code:
int ndn_name_append_numeric(struct ndn_charbuf *c, enum ndn_marker marker, unsigned long value)
{
    unsigned long v;
    int i;
    char b[32];
    for (v = value, i = sizeof(b); v != 0 && i > 0; i--, v >>= 8)
        b[i-1] = v & 0xff;
    if (i < 1)
        return(-1);
    if (marker >= 0)
        b[--i] = marker;
    return(ndn_name_append(c, b + i, sizeof(b) - i));
}

variable_types: enum ndn_marker { NDN_MARKER_NONE=-1, NDN_MARKER_SEQNUM=0, NDN_MARKER_CONTROL=193, NDN_MARKER_OSEQNUM=248, NDN_MARKER_BLKID=251, NDN_MARKER_VERSION=253 }

variable_types:
value
unsigned long

variable_types:
v
unsigned long

variable_types: i int

variable_types:
b
char [32]


decompiled_code:
__int64 __fastcall ndn_name_append_nonce(__int64 *a1)
{
int v2; // [rsp+1h] [rbp-27h] BYREF
char v3[35]; // [rsp+5h] [rbp-23h] BYREF

v2 = 5123777;
ndn_random_bytes(v3, 11LL);
return ndn_name_append(a1, (__int64)&v2, 15LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
int v2; // [rsp+1h] [rbp-27h] BYREF
char v3[35]; // [rsp+5h] [rbp-23h] BYREF

v2 = 5123777;
ndn_random_bytes(v3, 11LL);
return func1(a1, (__int64)&v2, 15LL);
}

original_code:
int
ndn_name_append_nonce(struct ndn_charbuf *c)
{
    const unsigned char pre[4] = { NDN_MARKER_CONTROL, '.', 'N', 0 };
    unsigned char b[15];
    memcpy(b, pre, sizeof(pre));
    ndn_random_bytes(b + sizeof(pre), sizeof(b) - sizeof(pre));
    return(ndn_name_append(c, b, sizeof(b)));
}

canonical_original_code:
int ndn_name_append_nonce(struct ndn_charbuf *c)
{
    unsigned char pre[4] = { NDN_MARKER_CONTROL, '.', 'N', 0 };
    unsigned char b[15];
    memcpy(b, pre, sizeof(pre));
    ndn_random_bytes(b + sizeof(pre), sizeof(b) - sizeof(pre));
    return(ndn_name_append(c, b, sizeof(b)));
}

variable_types:
pre
unsigned char [4]

variable_types:
b
unsigned char [15]


decompiled_code:
__int64 __fastcall ndn_name_append_components(unsigned __int64 *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rax
unsigned __int64 v6; // rbx
__int64 result; // rax

v4 = *a1;
if ( a3 > a4 )
return 0xFFFFFFFFLL;
if ( v4 <= 1 )
return 0xFFFFFFFFLL;
*a1 = v4 - 1;
v6 = a4 - a3;
ndn_charbuf_reserve(a1, a4 - a3 + 1);
result = ndn_charbuf_append(a1, a2 + a3, v6);
if ( (_DWORD)result != -1 )
result = ndn_charbuf_append_closer(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 a4)
{
unsigned __int64 v4; // rax
unsigned __int64 v6; // rbx
__int64 result; // rax

v4 = *a1;
if ( a3 > a4 )
return 0xFFFFFFFFLL;
if ( v4 <= 1 )
return 0xFFFFFFFFLL;
*a1 = v4 - 1;
v6 = a4 - a3;
ndn_charbuf_reserve(a1, a4 - a3 + 1);
result = ndn_charbuf_append(a1, a2 + a3, v6);
if ( (_DWORD)result != -1 )
result = ndn_charbuf_append_closer(a1);
return result;
}

original_code:
int
ndn_name_append_components(struct ndn_charbuf *c,
                           const unsigned char *ndnb,
                           size_t start, size_t stop)
{
    int res;
    if (c->length < 2 || start > stop)
        return(-1);
    c->length -= 1;
    ndn_charbuf_reserve(c, stop - start + 1);
    res = ndn_charbuf_append(c, ndnb + start, stop - start);
    if (res == -1) return(res);
    res = ndn_charbuf_append_closer(c);
    return(res);
}

canonical_original_code:
int ndn_name_append_components(struct ndn_charbuf *c, unsigned char *ndnb, unsigned long start, unsigned long stop)
{
    int res;
    if (c->length < 2 || start > stop)
        return(-1);
    c->length -= 1;
    ndn_charbuf_reserve(c, stop - start + 1);
    res = ndn_charbuf_append(c, ndnb + start, stop - start);
    if (res == -1) return(res);
    res = ndn_charbuf_append_closer(c);
    return(res);
}

variable_types:
ndnb
unsigned char *

variable_types:
start
unsigned long

variable_types:
stop
unsigned long

variable_types: res int


decompiled_code:
__int64 __fastcall ndn_name_comp_get(__int64 a1, _QWORD *a2, unsigned int a3, _QWORD *a4, _QWORD *a5)
{
__int64 v7; // rbx
int v8; // edx
__int64 result; // rax
__int64 v10; // [rsp-58h] [rbp-58h] BYREF

if ( *a2 <= 1uLL )
return 0xFFFFFFFFLL;
if ( a3 > (unsigned __int64)(*a2 - 2LL) )
return 0xFFFFFFFFLL;
v7 = ndn_buf_decoder_start(
&v10,
a1 + *(_QWORD *)(a2[2] + 8LL * a3),
(int)(*(_QWORD *)(a2[2] + 8LL * (a3 + 1)) - *(_QWORD *)(a2[2] + 8LL * a3)));
if ( !(unsigned int)ndn_buf_match_dtag(v7, 15LL) )
return 0xFFFFFFFFLL;
ndn_buf_advance(v7);
v8 = ndn_buf_match_blob(v7, a4, a5);
result = 0LL;
if ( !v8 )
{
*a4 = *(_QWORD *)(v7 + 40) + *(_QWORD *)v7;
*a5 = 0LL;
ndn_buf_check_close(v7);
result = (unsigned int)(*(int *)(v7 + 8) >> 31);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _QWORD *a2, unsigned int a3, _QWORD *a4, _QWORD *a5)
{
__int64 v7; // rbx
int v8; // edx
__int64 result; // rax
__int64 v10; // [rsp-58h] [rbp-58h] BYREF

if ( *a2 <= 1uLL )
return 0xFFFFFFFFLL;
if ( a3 > (unsigned __int64)(*a2 - 2LL) )
return 0xFFFFFFFFLL;
v7 = ndn_buf_decoder_start(
&v10,
a1 + *(_QWORD *)(a2[2] + 8LL * a3),
(int)(*(_QWORD *)(a2[2] + 8LL * (a3 + 1)) - *(_QWORD *)(a2[2] + 8LL * a3)));
if ( !(unsigned int)ndn_buf_match_dtag(v7, 15LL) )
return 0xFFFFFFFFLL;
ndn_buf_advance(v7);
v8 = ndn_buf_match_blob(v7, a4, a5);
result = 0LL;
if ( !v8 )
{
*a4 = *(_QWORD *)(v7 + 40) + *(_QWORD *)v7;
*a5 = 0LL;
ndn_buf_check_close(v7);
result = (unsigned int)(*(int *)(v7 + 8) >> 31);
}
return result;
}

original_code:
int
ndn_name_comp_get(const unsigned char *data,
                  const struct ndn_indexbuf *indexbuf,
                  unsigned int i,
                  const unsigned char **comp, size_t *size)
{
    int len;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d;
    if (indexbuf->n < 2 || i > indexbuf->n - 2) {
 return(-1);
    }
    len = indexbuf->buf[i + 1]-indexbuf->buf[i];
    d = ndn_buf_decoder_start(&decoder, data + indexbuf->buf[i], len);
    if (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
 ndn_buf_advance(d);
 if (ndn_buf_match_blob(d, comp, size))
     return(0);
 *comp = d->buf + d->decoder.index;
        *size = 0;
        ndn_buf_check_close(d);
        if (d->decoder.state >= 0)
            return(0);
    }
    return(-1);
}

canonical_original_code:
int ndn_name_comp_get(unsigned char *data, struct ndn_indexbuf *indexbuf, unsigned int i, unsigned char **comp, unsigned long *size)
{
    int len;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d;
    if (indexbuf->n < 2 || i > indexbuf->n - 2) {
 return(-1);
    }
    len = indexbuf->buf[i + 1]-indexbuf->buf[i];
    d = ndn_buf_decoder_start(&decoder, data + indexbuf->buf[i], len);
    if (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
 ndn_buf_advance(d);
 if (ndn_buf_match_blob(d, comp, size))
     return(0);
 *comp = d->buf + d->decoder.index;
        *size = 0;
        ndn_buf_check_close(d);
        if (d->decoder.state >= 0)
            return(0);
    }
    return(-1);
}

variable_types:
data
unsigned char *

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

variable_types:
i
unsigned int

variable_types:
comp
unsigned char **

variable_types:
size
unsigned long *

variable_types: len int

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; } *


decompiled_code:
int __fastcall ndn_name_comp_strcmp(__int64 a1, _QWORD *a2, unsigned int a3, const char *a4)
{
int v5; // edx
int result; // eax
size_t n; // [rsp+0h] [rbp-18h] BYREF
char *s2; // [rsp+8h] [rbp-10h] BYREF

v5 = ndn_name_comp_get(a1, a2, a3, &s2, &n);
result = 1;
if ( !v5 )
result = strncmp(a4, s2, n);
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, _QWORD *a2, unsigned int a3, const char *a4)
{
int v5; // edx
int result; // eax
size_t n; // [rsp+0h] [rbp-18h] BYREF
char *s2; // [rsp+8h] [rbp-10h] BYREF

v5 = func6(a1, a2, a3, &s2, &n);
result = 1;
if ( !v5 )
result = strncmp(a4, s2, n);
return result;
}

original_code:
int
ndn_name_comp_strcmp(const unsigned char *data,
                     const struct ndn_indexbuf *indexbuf,
                     unsigned int i, const char *val)
{
    const unsigned char *comp_ptr;
    size_t comp_size;
    if (ndn_name_comp_get(data, indexbuf, i, &comp_ptr, &comp_size) == 0)
 return(strncmp(val, (const char *)comp_ptr, comp_size));
    return(1);
}

canonical_original_code:
int ndn_name_comp_strcmp(unsigned char *data, struct ndn_indexbuf *indexbuf, unsigned int i, char *val)
{
    unsigned char *comp_ptr;
    unsigned long comp_size;
    if (ndn_name_comp_get(data, indexbuf, i, &comp_ptr, &comp_size) == 0)
 return(strncmp(val, (char *)comp_ptr, comp_size));
    return(1);
}

variable_types:
val
char *


decompiled_code:
__int64 __fastcall ndn_name_split(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF

v2 = ndn_buf_decoder_start(&v4, a1[2], *a1);
return ndn_parse_Name(v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
__int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF

v2 = ndn_buf_decoder_start(&v4, a1[2], *a1);
return ndn_parse_Name(v2, a2);
}

original_code:
int
ndn_name_split(const struct ndn_charbuf *c, struct ndn_indexbuf *components)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d;
    d = ndn_buf_decoder_start(&decoder, c->buf, c->length);
    return(ndn_parse_Name(d, components));
}

canonical_original_code:
int ndn_name_split(struct ndn_charbuf *c, struct ndn_indexbuf *components)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d;
    d = ndn_buf_decoder_start(&decoder, c->buf, c->length);
    return(ndn_parse_Name(d, components));
}

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

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; }


decompiled_code:
__int64 __fastcall ndn_name_next_sibling(__int64 *a1)
{
_QWORD *v1; // rax
int v2; // eax
int v3; // ebx
__int64 v4; // rdx
char v5; // al
int v7; // er12
int v8; // ebx
int v9; // ebx
__int64 *v10; // [rsp+0h] [rbp-38h] BYREF
__int64 v11; // [rsp+8h] [rbp-30h] BYREF
__int64 v12; // [rsp+10h] [rbp-28h] BYREF
_QWORD *v13; // [rsp+18h] [rbp-20h] BYREF

v12 = 0LL;
v11 = 0LL;
v1 = (_QWORD *)ndn_indexbuf_create();
v13 = v1;
if ( v1 )
{
v2 = ndn_name_split(a1, (__int64)v1);
if ( v2 <= 0 )
{
v3 = -1;
}
else
{
v3 = ndn_ref_tagged_BLOB(
15LL,
a1[2],
*(_QWORD *)(v13[2] + 8LL * v2 - 8),
*(_QWORD *)(v13[2] + 8LL * v2),
&v12,
&v11);
if ( v3 >= 0 )
{
v4 = v11;
if ( v11 )
{
do
{
--v4;
v5 = *(_BYTE *)(v12 + v4) + 1;
*(_BYTE *)(v12 + v4) = v5;
}
while ( !v5 && v4 );
if ( v5 )
goto LABEL_8;
}
v10 = (__int64 *)ndn_charbuf_create();
v7 = ndn_charbuf_append_value(v10, 0LL, 1LL);
v8 = ndn_charbuf_append(v10, v12, v11) | v7 | v3;
v9 = ndn_name_chop_localalias(a1, v13, *(_DWORD *)v13 - 2) | v8;
v3 = ndn_name_append(a1, v10[2], *v10) | v9;
ndn_charbuf_destroy(&v10);
if ( v3 >= 0 )
LABEL_8:
v3 = *v13 - 1;
}
}
}
else
{
v3 = -1;
}
ndn_indexbuf_destroy(&v13);
return (unsigned int)v3;
}

original_code:
int
ndn_name_next_sibling(struct ndn_charbuf *c)
{
    int res = -1;
    struct ndn_indexbuf *ndx;
    unsigned char *lastcomp = ((void *)0);
    size_t lastcompsize = 0;
    size_t i;
    int carry;
    struct ndn_charbuf *newcomp;
    ndx = ndn_indexbuf_create();
    if (ndx == ((void *)0)) goto Finish;
    res = ndn_name_split(c, ndx);
    if (res <= 0) {
        res = -1;
        goto Finish;
    }
    res = ndn_ref_tagged_BLOB(NDN_DTAG_Component, c->buf,
        ndx->buf[res-1], ndx->buf[res],
        (const unsigned char **)&lastcomp,
        &lastcompsize);
    if (res < 0) goto Finish;
    for (carry = 1, i = lastcompsize; carry && i > 0; i--) {
        carry = (((++lastcomp[i-1]) & 0xFF) == 0x00);
    }
    if (carry) {
        newcomp = ndn_charbuf_create();
        res |= ndn_charbuf_append_value(newcomp, 0, 1);
        res |= ndn_charbuf_append(newcomp, lastcomp, lastcompsize);
        res |= ndn_name_chop(c, ndx, ndx->n - 2);
        res |= ndn_name_append(c, newcomp->buf, newcomp->length);
        ndn_charbuf_destroy(&newcomp);
        if (res < 0) goto Finish;
    }
    res = ndx->n - 1;
Finish:
    ndn_indexbuf_destroy(&ndx);
    return(res);
}

canonical_original_code:
int ndn_name_next_sibling(struct ndn_charbuf *c)
{
    int res = -1;
    struct ndn_indexbuf *ndx;
    unsigned char *lastcomp = ((void *)0);
    unsigned long lastcompsize = 0;
    unsigned long i;
    int carry;
    struct ndn_charbuf *newcomp;
    ndx = ndn_indexbuf_create();
    if (ndx == ((void *)0)) goto Finish;
    res = ndn_name_split(c, ndx);
    if (res <= 0) {
        res = -1;
        goto Finish;
    }
    res = ndn_ref_tagged_BLOB(NDN_DTAG_Component, c->buf,
        ndx->buf[res-1], ndx->buf[res],
        (unsigned char **)&lastcomp,
        &lastcompsize);
    if (res < 0) goto Finish;
    for (carry = 1, i = lastcompsize; carry && i > 0; i--) {
        carry = (((++lastcomp[i-1]) & 0xFF) == 0x00);
    }
    if (carry) {
        newcomp = ndn_charbuf_create();
        res |= ndn_charbuf_append_value(newcomp, 0, 1);
        res |= ndn_charbuf_append(newcomp, lastcomp, lastcompsize);
        res |= ndn_name_chop(c, ndx, ndx->n - 2);
        res |= ndn_name_append(c, newcomp->buf, newcomp->length);
        ndn_charbuf_destroy(&newcomp);
        if (res < 0) goto Finish;
    }
    res = ndx->n - 1;
Finish:
    ndn_indexbuf_destroy(&ndx);
    return(res);
}

variable_types:
lastcomp
unsigned char *

variable_types:
lastcompsize
unsigned long

variable_types:
i
unsigned long

variable_types: carry int


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

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

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

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

original_code:
void
ndn_forwarding_entry_destroy(struct ndn_forwarding_entry **pfe)
{
    if (*pfe == ((void *)0))
        return;
    ndn_charbuf_destroy(&(*pfe)->name_prefix);
    free(*pfe);
    *pfe = ((void *)0);
}

variable_types: struct ndn_forwarding_entry { char *action; struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *name_prefix; unsigned char *ndnd_id; unsigned long ndnd_id_size; unsigned int faceid; int flags; int lifetime; unsigned char store[48]; } **

user_defined_types: struct ndn_forwarding_entry { char *action; struct ndn_charbuf *name_prefix; unsigned char *ndnd_id; unsigned long ndnd_id_size; unsigned int faceid; int flags; int lifetime; unsigned char store[48]; }


decompiled_code:
const void **__fastcall ndn_forwarding_entry_parse(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
const void **v3; // rbx
int v5; // ebx
int v6; // er14
int v7; // eax
const void **v8; // r13
const void **v9; // r13
char **v10; // r12
char *v11; // rbp
char *v12; // rbp
char *v13; // rax
__int64 v14; // r14
char *v15; // [rsp+0h] [rbp-88h] BYREF
__int64 v16; // [rsp+8h] [rbp-80h] BYREF
const void **v17; // [rsp+10h] [rbp-78h] BYREF
const void **v18; // [rsp+18h] [rbp-70h] BYREF
char v19[104]; // [rsp+20h] [rbp-68h] BYREF

v2 = ndn_buf_decoder_start(v19, a1, a2);
v3 = (const void **)ndn_charbuf_create();
v18 = v3;
if ( v3 )
{
v3 = (const void **)calloc(1uLL, 0x60uLL);
v17 = v3;
if ( !v3 )
{
ndn_charbuf_destroy(&v18);
return v3;
}
if ( (unsigned int)ndn_buf_match_dtag(v2, 81LL) )
{
ndn_buf_advance(v2);
v5 = ndn_parse_tagged_string(v2, 73LL, v18);
if ( (unsigned int)ndn_buf_match_dtag(v2, 14LL) )
{
v17[1] = (const void *)ndn_charbuf_create();
v14 = *(_QWORD *)(v2 + 24);
ndn_parse_Name(v2, 0LL);
ndn_charbuf_append(v17[1], a1 + v14, *(_QWORD *)(v2 + 24) - v14);
}
else
{
v17[1] = 0LL;
}
v6 = -1;
if ( (unsigned int)ndn_buf_match_dtag(v2, 60LL) )
{
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, &v16, &v15) )
{
ndn_buf_advance(v2);
if ( v15 != (_BYTE *)&loc_1D + 3 )
*(_DWORD *)(v2 + 8) = -70;
}
ndn_buf_check_close(v2);
v6 = -1;
if ( *(int *)(v2 + 8) >= 0 )
{
v6 = *(_DWORD *)v18;
ndn_charbuf_append(v18, v16, v15);
v17[3] = v15;
}
}
v7 = ndn_parse_optional_tagged_nonNegativeInteger(v2, 74LL);
v8 = v17;
*((_DWORD *)v17 + 8) = v7;
*((_DWORD *)v8 + 9) = ndn_parse_optional_tagged_nonNegativeInteger(v2, 79LL);
v9 = v17;
*((_DWORD *)v9 + 10) = ndn_parse_optional_tagged_nonNegativeInteger(v2, 58LL);
ndn_buf_check_close(v2);
if ( *(_QWORD *)v2 == a2 && (*(_WORD *)(v2 + 8) & 0x7FFF) == 0 && (unsigned __int64)*v18 <= 0x30 )
{
v10 = (char **)v17;
v11 = (char *)v17 + 44;
memcpy((char *)v17 + 44, v18[2], (size_t)*v18);
v12 = &v11[v5];
v13 = 0LL;
if ( v5 == -1 )
v12 = 0LL;
*v10 = v12;
if ( v6 != -1 )
v13 = (char *)v17 + v6 + 44;
v17[2] = v13;
goto LABEL_6;
}
}
else
{
*(_DWORD *)(v2 + 8) = -85;
}
ndn_forwarding_entry_destroy((void **)&v17);
LABEL_6:
ndn_charbuf_destroy(&v18);
v3 = v17;
}
return v3;
}

canonical_decompiled_code:
const void **__fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
const void **v3; // rbx
int v5; // ebx
int v6; // er14
int v7; // eax
const void **v8; // r13
const void **v9; // r13
char **v10; // r12
char *v11; // rbp
char *v12; // rbp
char *v13; // rax
__int64 v14; // r14
char *v15; // [rsp+0h] [rbp-88h] BYREF
__int64 v16; // [rsp+8h] [rbp-80h] BYREF
const void **v17; // [rsp+10h] [rbp-78h] BYREF
const void **v18; // [rsp+18h] [rbp-70h] BYREF
char v19[104]; // [rsp+20h] [rbp-68h] BYREF

v2 = ndn_buf_decoder_start(v19, a1, a2);
v3 = (const void **)ndn_charbuf_create();
v18 = v3;
if ( v3 )
{
v3 = (const void **)calloc(1uLL, 0x60uLL);
v17 = v3;
if ( !v3 )
{
ndn_charbuf_destroy(&v18);
return v3;
}
if ( (unsigned int)ndn_buf_match_dtag(v2, 81LL) )
{
ndn_buf_advance(v2);
v5 = ndn_parse_tagged_string(v2, 73LL, v18);
if ( (unsigned int)ndn_buf_match_dtag(v2, 14LL) )
{
v17[1] = (const void *)ndn_charbuf_create();
v14 = *(_QWORD *)(v2 + 24);
ndn_parse_Name(v2, 0LL);
ndn_charbuf_append(v17[1], a1 + v14, *(_QWORD *)(v2 + 24) - v14);
}
else
{
v17[1] = 0LL;
}
v6 = -1;
if ( (unsigned int)ndn_buf_match_dtag(v2, 60LL) )
{
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, &v16, &v15) )
{
ndn_buf_advance(v2);
if ( v15 != (_BYTE *)&loc_1D + 3 )
*(_DWORD *)(v2 + 8) = -70;
}
ndn_buf_check_close(v2);
v6 = -1;
if ( *(int *)(v2 + 8) >= 0 )
{
v6 = *(_DWORD *)v18;
ndn_charbuf_append(v18, v16, v15);
v17[3] = v15;
}
}
v7 = ndn_parse_optional_tagged_nonNegativeInteger(v2, 74LL);
v8 = v17;
*((_DWORD *)v17 + 8) = v7;
*((_DWORD *)v8 + 9) = ndn_parse_optional_tagged_nonNegativeInteger(v2, 79LL);
v9 = v17;
*((_DWORD *)v9 + 10) = ndn_parse_optional_tagged_nonNegativeInteger(v2, 58LL);
ndn_buf_check_close(v2);
if ( *(_QWORD *)v2 == a2 && (*(_WORD *)(v2 + 8) & 0x7FFF) == 0 && (unsigned __int64)*v18 <= 0x30 )
{
v10 = (char **)v17;
v11 = (char *)v17 + 44;
memcpy((char *)v17 + 44, v18[2], (size_t)*v18);
v12 = &v11[v5];
v13 = 0LL;
if ( v5 == -1 )
v12 = 0LL;
*v10 = v12;
if ( v6 != -1 )
v13 = (char *)v17 + v6 + 44;
v17[2] = v13;
goto LABEL_6;
}
}
else
{
*(_DWORD *)(v2 + 8) = -85;
}
func0((void **)&v17);
LABEL_6:
ndn_charbuf_destroy(&v18);
v3 = v17;
}
return v3;
}

original_code:
struct ndn_forwarding_entry *
ndn_forwarding_entry_parse(const unsigned char *p, size_t size)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, p, size);
    struct ndn_charbuf *store = ndn_charbuf_create();
    struct ndn_forwarding_entry *result;
    const unsigned char *val;
    size_t sz;
    size_t start;
    size_t end;
    int action_off = -1;
    int ndnd_id_off = -1;
    if (store == ((void *)0))
        return(((void *)0));
    result = calloc(1, sizeof(*result));
    if (result == ((void *)0)) {
        ndn_charbuf_destroy(&store);
        return(((void *)0));
    }
    if (ndn_buf_match_dtag(d, NDN_DTAG_ForwardingEntry)) {
        ndn_buf_advance(d);
        action_off = ndn_parse_tagged_string(d, NDN_DTAG_Action, store);
        if (ndn_buf_match_dtag(d, NDN_DTAG_Name)) {
            result->name_prefix = ndn_charbuf_create();
            start = d->decoder.token_index;
            ndn_parse_Name(d, ((void *)0));
            end = d->decoder.token_index;
            ndn_charbuf_append(result->name_prefix, p + start, end - start);
        }
        else
            result->name_prefix = ((void *)0);
        if (ndn_buf_match_dtag(d, NDN_DTAG_PublisherPublicKeyDigest)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &val, &sz)) {
                ndn_buf_advance(d);
                if (sz != 32)
                    d->decoder.state = -70;
            }
            ndn_buf_check_close(d);
            if (d->decoder.state >= 0) {
                ndnd_id_off = store->length;
                ndn_charbuf_append(store, val, sz);
                result->ndnd_id_size = sz;
            }
        }
        result->faceid = ndn_parse_optional_tagged_nonNegativeInteger(d, NDN_DTAG_FaceID);
        result->flags = ndn_parse_optional_tagged_nonNegativeInteger(d, NDN_DTAG_ForwardingFlags);
        result->lifetime = ndn_parse_optional_tagged_nonNegativeInteger(d, NDN_DTAG_FreshnessSeconds);
        ndn_buf_check_close(d);
    }
    else
        d->decoder.state = -85;
    if (d->decoder.index != size || !(((d->decoder.state) & ((1 << 15)-1)) == 0) ||
        store->length > sizeof(result->store))
        ndn_forwarding_entry_destroy(&result);
    else {
        char *b = (char *)result->store;
        memcpy(b, store->buf, store->length);
        result->action = (action_off == -1) ? ((void *)0) : b + action_off;
        result->ndnd_id = (ndnd_id_off == -1) ? ((void *)0) : result->store + ndnd_id_off;
    }
    ndn_charbuf_destroy(&store);
    return(result);
}

canonical_original_code:
struct ndn_forwarding_entry *ndn_forwarding_entry_parse(unsigned char *p, unsigned long size)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, p, size);
    struct ndn_charbuf *store = ndn_charbuf_create();
    struct ndn_forwarding_entry *result;
    unsigned char *val;
    unsigned long sz;
    unsigned long start;
    unsigned long end;
    int action_off = -1;
    int ndnd_id_off = -1;
    if (store == ((void *)0))
        return(((void *)0));
    result = calloc(1, sizeof(*result));
    if (result == ((void *)0)) {
        ndn_charbuf_destroy(&store);
        return(((void *)0));
    }
    if (ndn_buf_match_dtag(d, NDN_DTAG_ForwardingEntry)) {
        ndn_buf_advance(d);
        action_off = ndn_parse_tagged_string(d, NDN_DTAG_Action, store);
        if (ndn_buf_match_dtag(d, NDN_DTAG_Name)) {
            result->name_prefix = ndn_charbuf_create();
            start = d->decoder.token_index;
            ndn_parse_Name(d, ((void *)0));
            end = d->decoder.token_index;
            ndn_charbuf_append(result->name_prefix, p + start, end - start);
        }
        else
            result->name_prefix = ((void *)0);
        if (ndn_buf_match_dtag(d, NDN_DTAG_PublisherPublicKeyDigest)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &val, &sz)) {
                ndn_buf_advance(d);
                if (sz != 32)
                    d->decoder.state = -70;
            }
            ndn_buf_check_close(d);
            if (d->decoder.state >= 0) {
                ndnd_id_off = store->length;
                ndn_charbuf_append(store, val, sz);
                result->ndnd_id_size = sz;
            }
        }
        result->faceid = ndn_parse_optional_tagged_nonNegativeInteger(d, NDN_DTAG_FaceID);
        result->flags = ndn_parse_optional_tagged_nonNegativeInteger(d, NDN_DTAG_ForwardingFlags);
        result->lifetime = ndn_parse_optional_tagged_nonNegativeInteger(d, NDN_DTAG_FreshnessSeconds);
        ndn_buf_check_close(d);
    }
    else
        d->decoder.state = -85;
    if (d->decoder.index != size || !(((d->decoder.state) & ((1 << 15)-1)) == 0) ||
        store->length > sizeof(result->store))
        ndn_forwarding_entry_destroy(&result);
    else {
        char *b = (char *)result->store;
        memcpy(b, store->buf, store->length);
        result->action = (action_off == -1) ? ((void *)0) : b + action_off;
        result->ndnd_id = (ndnd_id_off == -1) ? ((void *)0) : result->store + ndnd_id_off;
    }
    ndn_charbuf_destroy(&store);
    return(result);
}

variable_types:
p
unsigned char *

variable_types:
size
unsigned long

variable_types: struct ndn_forwarding_entry { char *action; struct ndn_charbuf { unsigned long length; unsigned long limit; unsigned char *buf; } *name_prefix; unsigned char *ndnd_id; unsigned long ndnd_id_size; unsigned int faceid; int flags; int lifetime; unsigned char store[48]; } *

variable_types:
val
unsigned char *

variable_types:
sz
unsigned long

variable_types:
start
unsigned long

variable_types:
end
unsigned long

variable_types:
b
char *

user_defined_types: struct ndn_skeleton_decoder { long index; int state; int nest; unsigned long numval; unsigned long token_index; unsigned long element_index; }


decompiled_code:
__int64 __fastcall ndnb_append_forwarding_entry(__int64 a1, __int64 a2)
{
int v2; // ebx
_QWORD *v3; // rax

v2 = ndnb_element_begin(a1, 81LL);
if ( *(_QWORD *)a2 )
v2 |= ndnb_tagged_putf(a1, 73LL, &LC0);
v3 = *(_QWORD **)(a2 + 8);
if ( v3 && *v3 )
v2 |= ndn_charbuf_append(a1, v3[2], *v3);
if ( *(_QWORD *)(a2 + 24) )
v2 |= ndnb_append_tagged_blob(a1, 60LL, *(_QWORD *)(a2 + 16));
if ( *(_DWORD *)(a2 + 32) != -1 )
v2 |= ndnb_tagged_putf(a1, 74LL, &LC1);
if ( *(int *)(a2 + 36) >= 0 )
v2 |= ndnb_tagged_putf(a1, 79LL, &LC2);
if ( *(int *)(a2 + 40) >= 0 )
v2 |= ndnb_tagged_putf(a1, 58LL, &LC2);
return v2 | (unsigned int)ndnb_element_end(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // ebx
_QWORD *v3; // rax

v2 = ndnb_element_begin(a1, 81LL);
if ( *(_QWORD *)a2 )
v2 |= ndnb_tagged_putf(a1, 73LL, &LC0);
v3 = *(_QWORD **)(a2 + 8);
if ( v3 && *v3 )
v2 |= ndn_charbuf_append(a1, v3[2], *v3);
if ( *(_QWORD *)(a2 + 24) )
v2 |= ndnb_append_tagged_blob(a1, 60LL, *(_QWORD *)(a2 + 16));
if ( *(_DWORD *)(a2 + 32) != -1 )
v2 |= ndnb_tagged_putf(a1, 74LL, &LC1);
if ( *(int *)(a2 + 36) >= 0 )
v2 |= ndnb_tagged_putf(a1, 79LL, &LC2);
if ( *(int *)(a2 + 40) >= 0 )
v2 |= ndnb_tagged_putf(a1, 58LL, &LC2);
return v2 | (unsigned int)ndnb_element_end(a1);
}

original_code:
int
ndnb_append_forwarding_entry(struct ndn_charbuf *c,
                             const struct ndn_forwarding_entry *fe)
{
    int res;
    res = ndnb_element_begin(c, NDN_DTAG_ForwardingEntry);
    if (fe->action != ((void *)0))
        res |= ndnb_tagged_putf(c, NDN_DTAG_Action, "%s",
                                   fe->action);
    if (fe->name_prefix != ((void *)0) && fe->name_prefix->length > 0)
        res |= ndn_charbuf_append(c, fe->name_prefix->buf,
                                     fe->name_prefix->length);
    if (fe->ndnd_id_size != 0)
        res |= ndnb_append_tagged_blob(c, NDN_DTAG_PublisherPublicKeyDigest,
                                          fe->ndnd_id, fe->ndnd_id_size);
    if (fe->faceid != ~0)
        res |= ndnb_tagged_putf(c, NDN_DTAG_FaceID, "%u",
                                   fe->faceid);
    if (fe->flags >= 0)
        res |= ndnb_tagged_putf(c, NDN_DTAG_ForwardingFlags, "%d",
                                   fe->flags);
    if (fe->lifetime >= 0)
        res |= ndnb_tagged_putf(c, NDN_DTAG_FreshnessSeconds, "%d",
                                   fe->lifetime);
    res |= ndnb_element_end(c);
    return(res);
}

canonical_original_code:
int ndnb_append_forwarding_entry(struct ndn_charbuf *c, struct ndn_forwarding_entry *fe)
{
    int res;
    res = ndnb_element_begin(c, NDN_DTAG_ForwardingEntry);
    if (fe->action != ((void *)0))
        res |= ndnb_tagged_putf(c, NDN_DTAG_Action, "%s",
                                   fe->action);
    if (fe->name_prefix != ((void *)0) && fe->name_prefix->length > 0)
        res |= ndn_charbuf_append(c, fe->name_prefix->buf,
                                     fe->name_prefix->length);
    if (fe->ndnd_id_size != 0)
        res |= ndnb_append_tagged_blob(c, NDN_DTAG_PublisherPublicKeyDigest,
                                          fe->ndnd_id, fe->ndnd_id_size);
    if (fe->faceid != ~0)
        res |= ndnb_tagged_putf(c, NDN_DTAG_FaceID, "%u",
                                   fe->faceid);
    if (fe->flags >= 0)
        res |= ndnb_tagged_putf(c, NDN_DTAG_ForwardingFlags, "%d",
                                   fe->flags);
    if (fe->lifetime >= 0)
        res |= ndnb_tagged_putf(c, NDN_DTAG_FreshnessSeconds, "%d",
                                   fe->lifetime);
    res |= ndnb_element_end(c);
    return(res);
}

variable_types: struct ndn_forwarding_entry { char *action; struct ndn_charbuf *name_prefix; unsigned char *ndnd_id; unsigned long ndnd_id_size; unsigned int faceid; int flags; int lifetime; unsigned char store[48]; } *

variable_types: res int


decompiled_code:
unsigned __int64 *__fastcall heap_insert(__int64 a1, unsigned __int64 a2, unsigned __int64 a3, int a4, int a5)
{
int i; // eax
unsigned __int64 *result; // rax
unsigned __int64 *v7; // rax
unsigned __int64 v8; // r9
unsigned __int64 v9; // r10

for ( i = a5 >> a4; a5 > a5 >> a4; i = a5 >> a4 )
{
v7 = (unsigned __int64 *)(a1 + 16LL * i - 16);
v8 = *v7;
if ( *v7 >= a2 )
{
v9 = v7[1];
v7[1] = a3;
*v7 = a2;
a3 = v9;
a2 = v8;
}
--a4;
}
result = (unsigned __int64 *)(a1 + 16LL * a5 - 16);
*result = a2;
result[1] = a3;
return result;
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func1(__int64 a1, unsigned __int64 a2, unsigned __int64 a3, int a4, int a5)
{
int i; // eax
unsigned __int64 *result; // rax
unsigned __int64 *v7; // rax
unsigned __int64 v8; // r9
unsigned __int64 v9; // r10

for ( i = a5 >> a4; a5 > a5 >> a4; i = a5 >> a4 )
{
v7 = (unsigned __int64 *)(a1 + 16LL * i - 16);
v8 = *v7;
if ( *v7 >= a2 )
{
v9 = v7[1];
v7[1] = a3;
*v7 = a2;
a3 = v9;
a2 = v8;
}
--a4;
}
result = (unsigned __int64 *)(a1 + 16LL * a5 - 16);
*result = a2;
result[1] = a3;
return result;
}

original_code:
static void
heap_insert(struct ndn_schedule_heap_item *heap, heapmicros micros,
            struct ndn_scheduled_event *ev, int h, int n)
{
    int i;
    for (i = (n >> h); i < n; i = (n >> --h)) {
        if (micros <= heap[i-1].event_time) {
            heapmicros d = heap[i-1].event_time;
            struct ndn_scheduled_event *e = heap[i-1].ev;
            heap[i-1].ev = ev;
            heap[i-1].event_time = micros;
            micros = d;
            ev = e;
        }
    }
    heap[n-1].event_time = micros;
    heap[n-1].ev = ev;
}

canonical_original_code:
static void heap_insert(struct ndn_schedule_heap_item *heap, unsigned long micros, struct ndn_scheduled_event *ev, int h, int n)
{
    int i;
    for (i = (n >> h); i < n; i = (n >> --h)) {
        if (micros <= heap[i-1].event_time) {
            unsigned long d = heap[i-1].event_time;
            struct ndn_scheduled_event *e = heap[i-1].ev;
            heap[i-1].ev = ev;
            heap[i-1].event_time = micros;
            micros = d;
            ev = e;
        }
    }
    heap[n-1].event_time = micros;
    heap[n-1].ev = ev;
}

variable_types: struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event { int (*action)(struct ndn_schedule { void *clienth; struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval { long s; unsigned int micros; } *); unsigned int micros_per_base; void *data; } *clock; struct ndn_schedule_heap_item *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; } *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; } *ev; } *

variable_types:
micros
unsigned long

variable_types:
ev
struct ndn_scheduled_event *

variable_types: h int

variable_types: n int

variable_types: i int

variable_types:
d
unsigned long

variable_types: struct ndn_scheduled_event { int (*action)(struct ndn_schedule { void *clienth; struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval { long s; unsigned int micros; } *); unsigned int micros_per_base; void *data; } *clock; struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event *ev; } *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; } *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; } *

user_defined_types: struct ndn_scheduled_event { int (*action)(struct ndn_schedule *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; }

user_defined_types: struct ndn_schedule { void *clienth; struct ndn_gettime *clock; struct ndn_schedule_heap_item *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; }

user_defined_types: struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval *); unsigned int micros_per_base; void *data; }


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

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

original_code:
static int
ndn_schedule_cancelled_event(struct ndn_schedule *sched, void *clienth,
                             struct ndn_scheduled_event *ev, int flags)
{
    return(0);
}

variable_types: struct ndn_schedule { void *clienth; struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval { long s; unsigned int micros; } *); unsigned int micros_per_base; void *data; } *clock; struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event { int (*action)(struct ndn_schedule *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; } *ev; } *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; } *

variable_types:
clienth
void *

variable_types: flags int

user_defined_types: struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event *ev; }


original_code:
static struct ndn_scheduled_event *
reschedule_event(
    struct ndn_schedule *sched,
    int micros,
    struct ndn_scheduled_event *ev)
{
    int lim;
    int n;
    int h;
    struct ndn_schedule_heap_item *heap;
    if (micros >= epochmax - sched->now)
        update_epoch(sched);
    heap = sched->heap;
    n = sched->heap_n + 1;
    if (n > sched->heap_limit) {
        lim = sched->heap_limit + n;
        heap = realloc(sched->heap, lim * sizeof(heap[0]));
        if (heap == ((void *)0)) return(((void *)0));
        memset(&(heap[sched->heap_limit]), 0, (lim - n) * sizeof(heap[0]));
        sched->heap_limit = lim;
        sched->heap = heap;
    }
    sched->heap_n = n;
    h = sched->heap_height;
    while ((n >> h) > 1)
        sched->heap_height = ++h;
    while ((n >> h) < 1)
        sched->heap_height = --h;
    heap_insert(heap, sched->now + micros, ev, h, n);
    return(ev);
}

canonical_original_code:
static struct ndn_scheduled_event *reschedule_event(struct ndn_schedule *sched, int micros, struct ndn_scheduled_event *ev)
{
    int lim;
    int n;
    int h;
    struct ndn_schedule_heap_item *heap;
    if (micros >= epochmax - sched->now)
        update_epoch(sched);
    heap = sched->heap;
    n = sched->heap_n + 1;
    if (n > sched->heap_limit) {
        lim = sched->heap_limit + n;
        heap = realloc(sched->heap, lim * sizeof(heap[0]));
        if (heap == ((void *)0)) return(((void *)0));
        memset(&(heap[sched->heap_limit]), 0, (lim - n) * sizeof(heap[0]));
        sched->heap_limit = lim;
        sched->heap = heap;
    }
    sched->heap_n = n;
    h = sched->heap_height;
    while ((n >> h) > 1)
        sched->heap_height = ++h;
    while ((n >> h) < 1)
        sched->heap_height = --h;
    heap_insert(heap, sched->now + micros, ev, h, n);
    return(ev);
}

variable_types:
sched
struct ndn_schedule *

variable_types: micros int

variable_types: lim int

return_type: struct ndn_scheduled_event { int (*action)(struct ndn_schedule { void *clienth; struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval { long s; unsigned int micros; } *); unsigned int micros_per_base; void *data; } *clock; struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event *ev; } *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; } *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; } *


original_code:
static void
ndn_schedule_run_next(struct ndn_schedule *sched)
{
    struct ndn_scheduled_event *ev;
    heapmicros late;
    int res;
    if (sched->heap_n == 0) return;
    ev = sched->heap[0].ev;
    sched->heap[0].ev = ((void *)0);
    late = sched->now - sched->heap[0].event_time;
    heap_sift(sched->heap, sched->heap_n--);
    res = (ev->action)(sched, sched->clienth, ev, 0);
    if (res <= 0) {
        free(ev);
        return;
    }
    if (late > res)
        res = 1;
    else if (late <= sched->clock->micros_per_base)
        res -= late;
    reschedule_event(sched, res, ev);
}

canonical_original_code:
static void ndn_schedule_run_next(struct ndn_schedule *sched)
{
    struct ndn_scheduled_event *ev;
    unsigned long late;
    int res;
    if (sched->heap_n == 0) return;
    ev = sched->heap[0].ev;
    sched->heap[0].ev = ((void *)0);
    late = sched->now - sched->heap[0].event_time;
    heap_sift(sched->heap, sched->heap_n--);
    res = (ev->action)(sched, sched->clienth, ev, 0);
    if (res <= 0) {
        free(ev);
        return;
    }
    if (late > res)
        res = 1;
    else if (late <= sched->clock->micros_per_base)
        res -= late;
    reschedule_event(sched, res, ev);
}

variable_types:
late
unsigned long

user_defined_types: struct ndn_timeval { long s; unsigned int micros; }


original_code:
void
ndn_schedule_destroy(struct ndn_schedule **schedp)
{
    struct ndn_schedule *sched;
    struct ndn_scheduled_event *ev;
    struct ndn_schedule_heap_item *heap;
    int n;
    int i;
    sched = *schedp;
    if (sched == ((void *)0))
        return;
    *schedp = ((void *)0);
    heap = sched->heap;
    if (heap != ((void *)0)) {
        n = sched->heap_n;
        sched->heap = ((void *)0);
        for (i = 0; i < n; i++) {
            ev = heap[i].ev;
            (ev->action)(sched, sched->clienth, ev, 0x10);
            free(ev);
        }
        free(heap);
    }
    free(sched);
}

variable_types: struct ndn_schedule { void *clienth; struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval { long s; unsigned int micros; } *); unsigned int micros_per_base; void *data; } *clock; struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event { int (*action)(struct ndn_schedule *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; } *ev; } *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; } **


decompiled_code:
__int64 __fastcall ndn_schedule_get_gettime(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
const struct ndn_gettime *
ndn_schedule_get_gettime(struct ndn_schedule *schedp) {
    return(schedp->clock);
}

canonical_original_code:
struct ndn_gettime *ndn_schedule_get_gettime(struct ndn_schedule *schedp) {
    return(schedp->clock);
}

variable_types: struct ndn_schedule { void *clienth; struct ndn_gettime *clock; struct ndn_schedule_heap_item { unsigned long event_time; struct ndn_scheduled_event { int (*action)(struct ndn_schedule *sched, void *clienth, struct ndn_scheduled_event *ev, int flags); void *evdata; long evint; } *ev; } *heap; int heap_n; int heap_limit; int heap_height; unsigned long now; struct ndn_timeval lasttime; int time_leap; int time_ran_backward; } *

return_type: struct ndn_gettime { char descr[8]; void (*gettime)(struct ndn_gettime *, struct ndn_timeval { long s; unsigned int micros; } *); unsigned int micros_per_base; void *data; } *


decompiled_code:
unsigned __int64 __fastcall ndn_schedule_event(__m128i *a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 v5; // rbx
_QWORD *v9; // rax

v5 = 0LL;
if ( a2 >= 0 )
{
v9 = calloc(1uLL, 0x18uLL);
v5 = (unsigned __int64)v9;
if ( v9 )
{
*v9 = a3;
v9[1] = a4;
v9[2] = a5;
update_time(a1);
v5 = reschedule_event((__int64)a1, a2, v5);
}
}
return v5;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__m128i *a1, int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned __int64 v5; // rbx
_QWORD *v9; // rax

v5 = 0LL;
if ( a2 >= 0 )
{
v9 = calloc(1uLL, 0x18uLL);
v5 = (unsigned __int64)v9;
if ( v9 )
{
*v9 = a3;
v9[1] = a4;
v9[2] = a5;
update_time(a1);
v5 = func4((__int64)a1, a2, v5);
}
}
return v5;
}

original_code:
struct ndn_scheduled_event *
ndn_schedule_event(
    struct ndn_schedule *sched,
    int micros,
    ndn_scheduled_action action,
    void *evdata,
    intptr_t evint)
{
    struct ndn_scheduled_event *ev;
    if (micros < 0)
        return(((void *)0));
    ev = calloc(1, sizeof(*ev));
    if (ev == ((void *)0)) return(((void *)0));
    ev->action = action;
    ev->evdata = evdata;
    ev->evint = evint;
    update_time(sched);
    return(reschedule_event(sched, micros, ev));
}

canonical_original_code:
struct ndn_scheduled_event *ndn_schedule_event(struct ndn_schedule *sched, int micros, int (*action)(struct ndn_schedule *sched, void *clienth, struct ndn_scheduled_event *ev, int flags), void *evdata, long evint)
{
    struct ndn_scheduled_event *ev;
    if (micros < 0)
        return(((void *)0));
    ev = calloc(1, sizeof(*ev));
    if (ev == ((void *)0)) return(((void *)0));
    ev->action = action;
    ev->evdata = evdata;
    ev->evint = evint;
    update_time(sched);
    return(reschedule_event(sched, micros, ev));
}

variable_types: int (*)(struct ndn_schedule *sched, void *clienth, struct ndn_scheduled_event *ev, int flags)

variable_types:
evdata
void *

variable_types: evint long


decompiled_code:
__int64 __fastcall ndn_schedule_cancel(_QWORD *a1, __int64 a2)
{
if ( !a2 )
return 0xFFFFFFFFLL;
if ( (*(int (__fastcall **)(_QWORD *, _QWORD, __int64, __int64))a2)(a1, *a1, a2, 16LL) > 0 )
abort();
*(_QWORD *)a2 = ndn_schedule_cancelled_event;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 a2)
{
if ( !a2 )
return 0xFFFFFFFFLL;
if ( (*(int (__fastcall **)(_QWORD *, _QWORD, __int64, __int64))a2)(a1, *a1, a2, 16LL) > 0 )
abort();
*(_QWORD *)a2 = ndn_schedule_cancelled_event;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
return 0LL;
}

original_code:
int
ndn_schedule_cancel(struct ndn_schedule *sched, struct ndn_scheduled_event *ev)
{
    int res;
    if (ev == ((void *)0))
        return(-1);
    res = (ev->action)(sched, sched->clienth, ev, 0x10);
    if (res > 0)
        abort();
    ev->action = &ndn_schedule_cancelled_event;
    ev->evdata = ((void *)0);
    ev->evint = 0;
    return(0);
}

variable_types:
ev
struct ndn_scheduled_event *

variable_types: res int


decompiled_code:
unsigned __int64 __fastcall ndn_schedule_run(__int64 a1)
{
int v1; // eax
unsigned __int64 result; // rax

while ( 1 )
{
while ( *(int *)(a1 + 24) > 0 )
{
if ( **(_QWORD **)(a1 + 16) > *(_QWORD *)(a1 + 40) )
break;
ndn_schedule_run_next(a1);
}
update_time((__m128i *)a1);
v1 = *(_DWORD *)(a1 + 24);
if ( v1 <= 0 )
break;
if ( **(_QWORD **)(a1 + 16) > *(_QWORD *)(a1 + 40) )
goto LABEL_9;
}
if ( !v1 )
return 0xFFFFFFFFLL;
LABEL_9:
result = **(_QWORD **)(a1 + 16) - *(_QWORD *)(a1 + 40);
if ( result > 0x7FFFFFFE )
result = 0x7FFFFFFFLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1)
{
int v1; // eax
unsigned __int64 result; // rax

while ( 1 )
{
while ( *(int *)(a1 + 24) > 0 )
{
if ( **(_QWORD **)(a1 + 16) > *(_QWORD *)(a1 + 40) )
break;
func5(a1);
}
update_time((__m128i *)a1);
v1 = *(_DWORD *)(a1 + 24);
if ( v1 <= 0 )
break;
if ( **(_QWORD **)(a1 + 16) > *(_QWORD *)(a1 + 40) )
goto LABEL_9;
}
if ( !v1 )
return 0xFFFFFFFFLL;
LABEL_9:
result = **(_QWORD **)(a1 + 16) - *(_QWORD *)(a1 + 40);
if ( result > 0x7FFFFFFE )
result = 0x7FFFFFFFLL;
return result;
}

original_code:
int
ndn_schedule_run(struct ndn_schedule *sched)
{
    heapmicros ans;
    do {
        while (sched->heap_n > 0 && sched->heap[0].event_time <= sched->now)
            ndn_schedule_run_next(sched);
        update_time(sched);
    } while (sched->heap_n > 0 && sched->heap[0].event_time <= sched->now);
    if (sched->heap_n == 0)
        return(-1);
    ans = sched->heap[0].event_time - sched->now;
    if (ans < 0x7fffffff)
        return(ans);
    return(0x7fffffff);
}

canonical_original_code:
int ndn_schedule_run(struct ndn_schedule *sched)
{
    unsigned long ans;
    do {
        while (sched->heap_n > 0 && sched->heap[0].event_time <= sched->now)
            ndn_schedule_run_next(sched);
        update_time(sched);
    } while (sched->heap_n > 0 && sched->heap[0].event_time <= sched->now);
    if (sched->heap_n == 0)
        return(-1);
    ans = sched->heap[0].event_time - sched->now;
    if (ans < 0x7fffffff)
        return(ans);
    return(0x7fffffff);
}

variable_types:
ans
unsigned long


decompiled_code:
unsigned __int64 __fastcall hashtb_hash(unsigned __int8 *a1, __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int8 *v3; // rcx
unsigned __int8 *v4; // rsi

result = a2 + 23;
if ( a2 )
{
v3 = a1;
v4 = &a1[a2];
do
result = *v3++ + ((result << 6) ^ (result >> 27));
while ( v3 != v4 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int8 *a1, __int64 a2)
{
unsigned __int64 result; // rax
unsigned __int8 *v3; // rcx
unsigned __int8 *v4; // rsi

result = a2 + 23;
if ( a2 )
{
v3 = a1;
v4 = &a1[a2];
do
result = *v3++ + ((result << 6) ^ (result >> 27));
while ( v3 != v4 );
}
return result;
}

original_code:
size_t
hashtb_hash(const unsigned char *key, size_t key_size)
{
    size_t h;
    size_t i;
    for (h = key_size + 23, i = 0; i < key_size; i++)
        h = ((h << 6) ^ (h >> 27)) + key[i];
    return(h);
}

canonical_original_code:
unsigned long hashtb_hash(unsigned char *key, unsigned long key_size)
{
    unsigned long h;
    unsigned long i;
    for (h = key_size + 23, i = 0; i < key_size; i++)
        h = ((h << 6) ^ (h >> 27)) + key[i];
    return(h);
}

variable_types:
key
unsigned char *

variable_types:
h
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


original_code:
void *
hashtb_get_param(struct hashtb *ht, struct hashtb_param *param)
{
    if (param != ((void *)0))
        *param = ht->param;
    return(ht->param.finalize_data);
}

canonical_original_code:
void *hashtb_get_param(struct hashtb *ht, struct hashtb_param *param)
{
    if (param != ((void *)0))
        *param = ht->param;
    return(ht->param.finalize_data);
}

variable_types: struct hashtb { struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } **bucket; unsigned long item_size; unsigned int n_buckets; int n; int refcount; struct node *deferred; struct hashtb_param { void (*finalize)(struct hashtb_enumerator { struct hashtb *ht; void *key; unsigned long keysize; unsigned long extsize; void *data; unsigned long datasize; void *priv[3]; } *); void *finalize_data; int orders; } param; } *

variable_types:
param
struct hashtb_param *

return_type: void *

user_defined_types: struct hashtb { struct node **bucket; unsigned long item_size; unsigned int n_buckets; int n; int refcount; struct node *deferred; struct hashtb_param param; }

user_defined_types: struct hashtb_param { void (*finalize)(struct hashtb_enumerator *); void *finalize_data; int orders; }


decompiled_code:
__int64 __fastcall hashtb_n(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int
hashtb_n(struct hashtb *ht)
{
    return(ht->n);
}

user_defined_types: struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; }

user_defined_types: struct hashtb_enumerator { struct hashtb *ht; void *key; unsigned long keysize; unsigned long extsize; void *data; unsigned long datasize; void *priv[3]; }


original_code:
void
hashtb_end(struct hashtb_enumerator *hte)
{
    struct hashtb *ht = hte->ht;
    struct node *p;
    hashtb_finalize_proc f;
    if (!((uintptr_t)((hte)->priv[1]) == ~(uintptr_t)(ht)) || ht->refcount <= 0) abort();
    if (ht->refcount == 1) {
        f = ht->param.finalize;
        while (ht->deferred != ((void *)0)) {
            setpos(hte, &(ht->deferred));
            if (f != ((void *)0))
                (*f)(hte);
            p = ht->deferred;
            ht->deferred = p->link;
            free(p);
        }
    }
    hte->priv[0] = 0;
    hte->priv[1] = 0;
    ht->refcount--;
}

canonical_original_code:
void hashtb_end(struct hashtb_enumerator *hte)
{
    struct hashtb *ht = hte->ht;
    struct node *p;
    void (*f)(struct hashtb_enumerator *);
    if (!((unsigned long)((hte)->priv[1]) == ~(unsigned long)(ht)) || ht->refcount <= 0) abort();
    if (ht->refcount == 1) {
        f = ht->param.finalize;
        while (ht->deferred != ((void *)0)) {
            setpos(hte, &(ht->deferred));
            if (f != ((void *)0))
                (*f)(hte);
            p = ht->deferred;
            ht->deferred = p->link;
            free(p);
        }
    }
    hte->priv[0] = 0;
    hte->priv[1] = 0;
    ht->refcount--;
}

variable_types: void (*)(struct hashtb_enumerator { struct hashtb { struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } **bucket; unsigned long item_size; unsigned int n_buckets; int n; int refcount; struct node *deferred; struct hashtb_param { void (*finalize)(struct hashtb_enumerator *); void *finalize_data; int orders; } param; } *ht; void *key; unsigned long keysize; unsigned long extsize; void *data; unsigned long datasize; void *priv[3]; } *)


original_code:
void
hashtb_delete(struct hashtb_enumerator *hte)
{
    struct hashtb *ht = hte->ht;
    struct node **pp = hte->priv[0];
    struct node *p = *pp;
    if ((p != ((void *)0)) && ((uintptr_t)((hte)->priv[1]) == ~(uintptr_t)(ht)) && ((unsigned char *)((p) + 1) + ht->item_size) == hte->key) {
        *pp = p->link;
        if (*pp == ((void *)0))
           pp = scan_buckets(hte->ht, (p->hash % hte->ht->n_buckets) + 1);
        hte->ht->n -= 1;
        if (ht->refcount == 1) {
            hashtb_finalize_proc f = ht->param.finalize;
            if (f != ((void *)0))
                (*f)(hte);
            free(p);
        }
        else {
            p->link = ht->deferred;
            ht->deferred = p;
        }
        setpos(hte, pp);
    }
}

canonical_original_code:
void hashtb_delete(struct hashtb_enumerator *hte)
{
    struct hashtb *ht = hte->ht;
    struct node **pp = hte->priv[0];
    struct node *p = *pp;
    if ((p != ((void *)0)) && ((unsigned long)((hte)->priv[1]) == ~(unsigned long)(ht)) && ((unsigned char *)((p) + 1) + ht->item_size) == hte->key) {
        *pp = p->link;
        if (*pp == ((void *)0))
           pp = scan_buckets(hte->ht, (p->hash % hte->ht->n_buckets) + 1);
        hte->ht->n -= 1;
        if (ht->refcount == 1) {
            void (*f)(struct hashtb_enumerator *) = ht->param.finalize;
            if (f != ((void *)0))
                (*f)(hte);
            free(p);
        }
        else {
            p->link = ht->deferred;
            ht->deferred = p;
        }
        setpos(hte, pp);
    }
}

variable_types: struct hashtb_enumerator { struct hashtb { struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } **bucket; unsigned long item_size; unsigned int n_buckets; int n; int refcount; struct node *deferred; struct hashtb_param { void (*finalize)(struct hashtb_enumerator *); void *finalize_data; int orders; } param; } *ht; void *key; unsigned long keysize; unsigned long extsize; void *data; unsigned long datasize; void *priv[3]; } *


decompiled_code:
void __fastcall hashtb_destroy(void ***a1)
{
__int64 v2; // rdi
__int64 *i; // rbx
__int64 v4[13]; // [rsp+0h] [rbp-68h] BYREF

v2 = (__int64)*a1;
if ( v2 )
{
for ( i = hashtb_start(v2, v4); i[1]; hashtb_delete(i) )
;
hashtb_end(v4);
if ( *((_DWORD *)*a1 + 6) )
abort();
free(**a1);
free(*a1);
*a1 = 0LL;
}
}

original_code:
void
hashtb_destroy(struct hashtb **htp)
{
    if (*htp != ((void *)0)) {
        struct hashtb_enumerator tmp;
        struct hashtb_enumerator *e = hashtb_start(*htp, &tmp);
        while (e->key != ((void *)0))
            hashtb_delete(e);
        hashtb_end(&tmp);
        if ((*htp)->refcount == 0) {
            free((*htp)->bucket);
            free(*htp);
            *htp = ((void *)0);
        }
        else
            abort();
    }
}

variable_types: struct hashtb { struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } **bucket; unsigned long item_size; unsigned int n_buckets; int n; int refcount; struct node *deferred; struct hashtb_param { void (*finalize)(struct hashtb_enumerator { struct hashtb *ht; void *key; unsigned long keysize; unsigned long extsize; void *data; unsigned long datasize; void *priv[3]; } *); void *finalize_data; int orders; } param; } **

variable_types: struct hashtb_enumerator { struct hashtb { struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } **bucket; unsigned long item_size; unsigned int n_buckets; int n; int refcount; struct node *deferred; struct hashtb_param { void (*finalize)(struct hashtb_enumerator *); void *finalize_data; int orders; } param; } *ht; void *key; unsigned long keysize; unsigned long extsize; void *data; unsigned long datasize; void *priv[3]; }


original_code:
void
hashtb_rehash(struct hashtb *ht, unsigned n_buckets)
{
    struct node **bucket = ((void *)0);
    struct node **pp;
    struct node *p;
    struct node *q;
    size_t h;
    unsigned i;
    unsigned b;
    if (ht->refcount != 0 || n_buckets < 1 || n_buckets == ht->n_buckets)
        return;
    bucket = calloc(n_buckets, sizeof(bucket[0]));
    if (bucket == ((void *)0)) return;
    for (i = 0; i < ht->n_buckets; i++) {
        for (p = ht->bucket[i]; p != ((void *)0); p = q) {
            q = p->link;
            h = p->hash;
            b = h % n_buckets;
            for (pp = &bucket[b]; *pp != ((void *)0) && ((*pp)->hash < h); pp = &((*pp)->link))
                continue;
            p->link = *pp;
            *pp = p;
        }
    }
    free(ht->bucket);
    ht->bucket = bucket;
    ht->n_buckets = n_buckets;
}

canonical_original_code:
void hashtb_rehash(struct hashtb *ht, unsigned int n_buckets)
{
    struct node **bucket = ((void *)0);
    struct node **pp;
    struct node *p;
    struct node *q;
    unsigned long h;
    unsigned int i;
    unsigned int b;
    if (ht->refcount != 0 || n_buckets < 1 || n_buckets == ht->n_buckets)
        return;
    bucket = calloc(n_buckets, sizeof(bucket[0]));
    if (bucket == ((void *)0)) return;
    for (i = 0; i < ht->n_buckets; i++) {
        for (p = ht->bucket[i]; p != ((void *)0); p = q) {
            q = p->link;
            h = p->hash;
            b = h % n_buckets;
            for (pp = &bucket[b]; *pp != ((void *)0) && ((*pp)->hash < h); pp = &((*pp)->link))
                continue;
            p->link = *pp;
            *pp = p;
        }
    }
    free(ht->bucket);
    ht->bucket = bucket;
    ht->n_buckets = n_buckets;
}

variable_types: struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } **

variable_types:
i
unsigned int

variable_types:
b
unsigned int


original_code:
int
hashtb_seek(struct hashtb_enumerator *hte, const void *key, size_t keysize, size_t extsize)
{
    struct node *p = ((void *)0);
    struct hashtb *ht = hte->ht;
    struct node **pp;
    size_t h;
    if (key == ((void *)0)) {
        setpos(hte, ((void *)0));
        return(-1);
    }
    if (ht->refcount == 1 && ht->n > ht->n_buckets * 3) {
        ht->refcount--;
        hashtb_rehash(ht, 2 * ht->n + 1);
        ht->refcount++;
    }
    h = hashtb_hash(key, keysize);
    pp = &(ht->bucket[h % ht->n_buckets]);
    for (p = *pp; p != ((void *)0); pp = &(p->link), p = p->link) {
        if (p->hash < h)
            continue;
        if (p->hash > h)
            break;
        if (keysize == p->keysize && 0 == memcmp(key, ((unsigned char *)((p) + 1) + ht->item_size), keysize)) {
            setpos(hte, pp);
            return(0);
        }
    }
    p = calloc(1, sizeof(*p) + ht->item_size + keysize + extsize);
    if (p == ((void *)0)) {
        setpos(hte, ((void *)0));
        return(-1);
    }
    memcpy(((unsigned char *)((p) + 1) + ht->item_size), key, keysize + extsize);
    p->hash = h;
    p->keysize = keysize;
    p->extsize = extsize;
    p->link = *pp;
    *pp = p;
    hte->ht->n += 1;
    setpos(hte, pp);
    return(1);
}

canonical_original_code:
int hashtb_seek(struct hashtb_enumerator *hte, void *key, unsigned long keysize, unsigned long extsize)
{
    struct node *p = ((void *)0);
    struct hashtb *ht = hte->ht;
    struct node **pp;
    unsigned long h;
    if (key == ((void *)0)) {
        setpos(hte, ((void *)0));
        return(-1);
    }
    if (ht->refcount == 1 && ht->n > ht->n_buckets * 3) {
        ht->refcount--;
        hashtb_rehash(ht, 2 * ht->n + 1);
        ht->refcount++;
    }
    h = hashtb_hash(key, keysize);
    pp = &(ht->bucket[h % ht->n_buckets]);
    for (p = *pp; p != ((void *)0); pp = &(p->link), p = p->link) {
        if (p->hash < h)
            continue;
        if (p->hash > h)
            break;
        if (keysize == p->keysize && 0 == memcmp(key, ((unsigned char *)((p) + 1) + ht->item_size), keysize)) {
            setpos(hte, pp);
            return(0);
        }
    }
    p = calloc(1, sizeof(*p) + ht->item_size + keysize + extsize);
    if (p == ((void *)0)) {
        setpos(hte, ((void *)0));
        return(-1);
    }
    memcpy(((unsigned char *)((p) + 1) + ht->item_size), key, keysize + extsize);
    p->hash = h;
    p->keysize = keysize;
    p->extsize = extsize;
    p->link = *pp;
    *pp = p;
    hte->ht->n += 1;
    setpos(hte, pp);
    return(1);
}

variable_types:
key
void *

variable_types:
keysize
unsigned long

variable_types:
extsize
unsigned long

variable_types: struct node { struct node *link; unsigned long hash; unsigned long keysize; unsigned long extsize; } *


decompiled_code:
_BOOL8 __fastcall is_uri_reserved(char a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u && (unsigned __int8)(a1 - 48) > 9u && (unsigned __int8)(a1 - 45) > 1u )
result = a1 != 126 && a1 != 95;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( (unsigned __int8)((a1 & 0xDF) - 65) > 0x19u && (unsigned __int8)(a1 - 48) > 9u && (unsigned __int8)(a1 - 45) > 1u )
result = a1 != 126 && a1 != 95;
return result;
}

variable_types:
ch
unsigned char


hexit

decompiled_code:
__int64 __fastcall hexit(int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 65) <= 5 )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
unsigned int v2; // eax
unsigned int v3; // edi
bool v4; // cf

result = (unsigned int)(a1 - 48);
if ( (unsigned int)result > 9 )
{
if ( (unsigned int)(a1 - 65) <= 5 )
{
result = (unsigned int)(a1 - 55);
}
else
{
v2 = a1 - 97;
v3 = a1 - 87;
v4 = v2 < 6;
result = 0xFFFFFFFFLL;
if ( v4 )
result = v3;
}
}
return result;
}

variable_types: c int