decompiled_code:
__int64 __fastcall ndn_append_uri_component(unsigned __int64 *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v4; // r12
int v5; // er15
unsigned int v6; // er13
unsigned __int64 v7; // rbx
int v8; // edx
int v9; // edx
char v10; // di
unsigned __int64 v11; // rdx
unsigned __int64 v12; // rax
int v15; // [rsp+Ch] [rbp-5Ch]
int v16; // [rsp+Ch] [rbp-5Ch]
unsigned __int64 v17; // [rsp+10h] [rbp-58h]
char v19[57]; // [rsp+2Fh] [rbp-39h] BYREF

v4 = a3;
v17 = *a1;
if ( !a3 )
goto LABEL_41;
v5 = 0;
v6 = 0;
v7 = 0LL;
while ( 2 )
{
v10 = *(_BYTE *)(a2 + v7);
v19[0] = v10;
switch ( v10 )
{
case 0:
case 35:
case 47:
case 63:
v4 = v7;
goto LABEL_17;
case 33:
case 36:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 58:
case 59:
case 64:
case 91:
case 93:
++v6;
goto LABEL_12;
case 37:
if ( v5 )
return (unsigned int)-3;
if ( v7 + 3 > v4 )
return (unsigned int)-3;
v15 = hexit(*(char *)(a2 + v7 + 1));
if ( v15 < 0 )
return (unsigned int)-3;
v7 += 2LL;
v8 = hexit(*(char *)(a2 + v7));
if ( v8 < 0 )
return (unsigned int)-3;
v19[0] = v8 + 16 * v15;
ndn_charbuf_append(a1, v19, 1LL);
goto LABEL_17;
case 61:
if ( v5 )
return (unsigned int)-3;
if ( v7 + 3 > v4 )
return (unsigned int)-3;
v5 = 1;
LABEL_17:
if ( v4 > ++v7 )
continue;
v11 = *a1;
v12 = v17;
if ( v17 >= *a1 )
{
if ( v17 == v11 )
goto LABEL_41;
}
else
{
while ( *(_BYTE *)(a1[2] + v12) == 46 )
{
if ( ++v12 == v11 )
{
v12 = *a1;
goto LABEL_28;
}
}
if ( v11 != v12 )
goto LABEL_23;
LABEL_28:
if ( v12 - v17 > 1 )
{
if ( v12 - v17 == 2 )
{
*a1 = v17;
v6 = -1;
}
else
{
*a1 = v12 - 3;
}
goto LABEL_23;
}
LABEL_41:
*a1 = v17;
v6 = -2;
}
LABEL_23:
if ( a4 )
*a4 = v4;
return v6;
default:
LABEL_12:
v6 -= ((unsigned __int8)(v10 - 33) < 0x5Eu) - 1;
if ( !v5 )
goto LABEL_16;
v16 = hexit(v10);
if ( v16 < 0 )
return (unsigned int)-3;
++v7;
v9 = hexit(*(char *)(a2 + v7));
if ( v9 < 0 )
return (unsigned int)-3;
v19[0] = v9 + 16 * v16;
LABEL_16:
ndn_charbuf_append(a1, v19, 1LL);
goto LABEL_17;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 *a1, __int64 a2, unsigned __int64 a3, unsigned __int64 *a4)
{
unsigned __int64 v4; // r12
int v5; // er15
unsigned int v6; // er13
unsigned __int64 v7; // rbx
int v8; // edx
int v9; // edx
char v10; // di
unsigned __int64 v11; // rdx
unsigned __int64 v12; // rax
int v15; // [rsp+Ch] [rbp-5Ch]
int v16; // [rsp+Ch] [rbp-5Ch]
unsigned __int64 v17; // [rsp+10h] [rbp-58h]
char v19[57]; // [rsp+2Fh] [rbp-39h] BYREF

v4 = a3;
v17 = *a1;
if ( !a3 )
goto LABEL_41;
v5 = 0;
v6 = 0;
v7 = 0LL;
while ( 2 )
{
v10 = *(_BYTE *)(a2 + v7);
v19[0] = v10;
switch ( v10 )
{
case 0:
case 35:
case 47:
case 63:
v4 = v7;
goto LABEL_17;
case 33:
case 36:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 58:
case 59:
case 64:
case 91:
case 93:
++v6;
goto LABEL_12;
case 37:
if ( v5 )
return (unsigned int)-3;
if ( v7 + 3 > v4 )
return (unsigned int)-3;
v15 = func1(*(char *)(a2 + v7 + 1));
if ( v15 < 0 )
return (unsigned int)-3;
v7 += 2LL;
v8 = func1(*(char *)(a2 + v7));
if ( v8 < 0 )
return (unsigned int)-3;
v19[0] = v8 + 16 * v15;
ndn_charbuf_append(a1, v19, 1LL);
goto LABEL_17;
case 61:
if ( v5 )
return (unsigned int)-3;
if ( v7 + 3 > v4 )
return (unsigned int)-3;
v5 = 1;
LABEL_17:
if ( v4 > ++v7 )
continue;
v11 = *a1;
v12 = v17;
if ( v17 >= *a1 )
{
if ( v17 == v11 )
goto LABEL_41;
}
else
{
while ( *(_BYTE *)(a1[2] + v12) == 46 )
{
if ( ++v12 == v11 )
{
v12 = *a1;
goto LABEL_28;
}
}
if ( v11 != v12 )
goto LABEL_23;
LABEL_28:
if ( v12 - v17 > 1 )
{
if ( v12 - v17 == 2 )
{
*a1 = v17;
v6 = -1;
}
else
{
*a1 = v12 - 3;
}
goto LABEL_23;
}
LABEL_41:
*a1 = v17;
v6 = -2;
}
LABEL_23:
if ( a4 )
*a4 = v4;
return v6;
default:
LABEL_12:
v6 -= ((unsigned __int8)(v10 - 33) < 0x5Eu) - 1;
if ( !v5 )
goto LABEL_16;
v16 = func1(v10);
if ( v16 < 0 )
return (unsigned int)-3;
++v7;
v9 = func1(*(char *)(a2 + v7));
if ( v9 < 0 )
return (unsigned int)-3;
v19[0] = v9 + 16 * v16;
LABEL_16:
ndn_charbuf_append(a1, v19, 1LL);
goto LABEL_17;
}
}
}

original_code:
static int
ndn_append_uri_component(struct ndn_charbuf *c, const char *s, size_t limit, size_t *cont)
{
    size_t start = c->length;
    size_t i;
    int err = 0;
    int hex = 0;
    int d1, d2;
    unsigned char ch;
    for (i = 0; i < limit; i++) {
        ch = s[i];
        switch (ch) {
            case 0:
            case '/':
            case '?':
            case '#':
                limit = i;
                break;
            case '=':
                if (hex || i + 3 > limit) {
                    return(-3);
                }
                hex = 1;
                break;
            case '%':
                if (hex || i + 3 > limit || (d1 = hexit(s[i+1])) < 0 ||
                    (d2 = hexit(s[i+2])) < 0 ) {
                    return(-3);
                }
                ch = d1 * 16 + d2;
                i += 2;
                ndn_charbuf_append(c, &ch, 1);
                break;
            case ':': case '[': case ']': case '@':
            case '!': case '$': case '&': case '\'': case '(': case ')':
            case '*': case '+': case ',': case ';':
                err++;
            default:
                if (ch <= ' ' || ch > '~')
                    err++;
                if (hex) {
                    if ((d1 = hexit(s[i])) < 0 || (d2 = hexit(s[i+1])) < 0) {
                        return(-3);
                    }
                    ch = d1 * 16 + d2;
                    i++;
                }
                ndn_charbuf_append(c, &ch, 1);
                break;
        }
    }
    for (i = start; i < c->length && c->buf[i] == '.'; i++)
        continue;
    if (i == c->length) {
        i -= start;
        if (i <= 1) {
            c->length = start;
            err = -2;
        }
        else if (i == 2) {
            c->length = start;
            err = -1;
        }
        else
            c->length -= 3;
    }
    if (cont != ((void *)0))
        *cont = limit;
    return(err);
}

canonical_original_code:
static int ndn_append_uri_component(struct ndn_charbuf *c, char *s, unsigned long limit, unsigned long *cont)
{
    unsigned long start = c->length;
    unsigned long i;
    int err = 0;
    int hex = 0;
    int d1; int d2;
    unsigned char ch;
    for (i = 0; i < limit; i++) {
        ch = s[i];
        switch (ch) {
            case 0:
            case '/':
            case '?':
            case '#':
                limit = i;
                break;
            case '=':
                if (hex || i + 3 > limit) {
                    return(-3);
                }
                hex = 1;
                break;
            case '%':
                if (hex || i + 3 > limit || (d1 = hexit(s[i+1])) < 0 ||
                    (d2 = hexit(s[i+2])) < 0 ) {
                    return(-3);
                }
                ch = d1 * 16 + d2;
                i += 2;
                ndn_charbuf_append(c, &ch, 1);
                break;
            case ':': case '[': case ']': case '@':
            case '!': case '$': case '&': case '\'': case '(': case ')':
            case '*': case '+': case ',': case ';':
                err++;
            default:
                if (ch <= ' ' || ch > '~')
                    err++;
                if (hex) {
                    if ((d1 = hexit(s[i])) < 0 || (d2 = hexit(s[i+1])) < 0) {
                        return(-3);
                    }
                    ch = d1 * 16 + d2;
                    i++;
                }
                ndn_charbuf_append(c, &ch, 1);
                break;
        }
    }
    for (i = start; i < c->length && c->buf[i] == '.'; i++)
        continue;
    if (i == c->length) {
        i -= start;
        if (i <= 1) {
            c->length = start;
            err = -2;
        }
        else if (i == 2) {
            c->length = start;
            err = -1;
        }
        else
            c->length -= 3;
    }
    if (cont != ((void *)0))
        *cont = limit;
    return(err);
}

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

variable_types:
s
char *

variable_types:
limit
unsigned long

variable_types:
cont
unsigned long *

variable_types:
start
unsigned long

variable_types: err int

variable_types: hex int


repo: danihegglin/ChronosAndroid

decompiled_code:
__int64 __fastcall ndn_name_last_component_offset(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
__int64 v5; // [rsp+0h] [rbp-58h] BYREF

v2 = ndn_buf_decoder_start(&v5, a1, a2);
v3 = -1;
if ( (unsigned int)ndn_buf_match_dtag(v2, 14LL) )
{
ndn_buf_advance(v2);
v3 = *(_DWORD *)(v2 + 24);
while ( (unsigned int)ndn_buf_match_dtag(v2, 15LL) )
{
v3 = *(_DWORD *)(v2 + 24);
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, 0LL, 0LL) )
ndn_buf_advance(v2);
ndn_buf_check_close(v2);
}
ndn_buf_check_close(v2);
}
if ( *(int *)(v2 + 8) < 0 )
v3 = -1;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
__int64 v5; // [rsp+0h] [rbp-58h] BYREF

v2 = ndn_buf_decoder_start(&v5, a1, a2);
v3 = -1;
if ( (unsigned int)ndn_buf_match_dtag(v2, 14LL) )
{
ndn_buf_advance(v2);
v3 = *(_DWORD *)(v2 + 24);
while ( (unsigned int)ndn_buf_match_dtag(v2, 15LL) )
{
v3 = *(_DWORD *)(v2 + 24);
ndn_buf_advance(v2);
if ( (unsigned int)ndn_buf_match_blob(v2, 0LL, 0LL) )
ndn_buf_advance(v2);
ndn_buf_check_close(v2);
}
ndn_buf_check_close(v2);
}
if ( *(int *)(v2 + 8) < 0 )
v3 = -1;
return v3;
}

original_code:
static int
ndn_name_last_component_offset(const unsigned char *ndnb, size_t size)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, ndnb, size);
    int res = -1;
    if (ndn_buf_match_dtag(d, NDN_DTAG_Name)) {
        ndn_buf_advance(d);
        res = d->decoder.token_index;
        while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
            res = d->decoder.token_index;
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, ((void *)0), ((void *)0)))
                ndn_buf_advance(d);
            ndn_buf_check_close(d);
        }
        ndn_buf_check_close(d);
    }
    return ((d->decoder.state >= 0) ? res : -1);
}

canonical_original_code:
static int ndn_name_last_component_offset(unsigned char *ndnb, unsigned long size)
{
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, ndnb, size);
    int res = -1;
    if (ndn_buf_match_dtag(d, NDN_DTAG_Name)) {
        ndn_buf_advance(d);
        res = d->decoder.token_index;
        while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
            res = d->decoder.token_index;
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, ((void *)0), ((void *)0)))
                ndn_buf_advance(d);
            ndn_buf_check_close(d);
        }
        ndn_buf_check_close(d);
    }
    return ((d->decoder.state >= 0) ? res : -1);
}

variable_types:
ndnb
unsigned char *

variable_types:
size
unsigned long

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

variable_types: res int

return_type: int

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


decompiled_code:
__int64 __fastcall ndn_uri_append_percentescaped(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rbp
__int64 result; // rax
unsigned __int8 v7; // bl
char v8[57]; // [rsp+Fh] [rbp-39h] BYREF

v4 = 0LL;
if ( !a3 )
return ndn_charbuf_append(a1, "...", 3LL);
while ( *(_BYTE *)(a2 + v4) == 46 )
{
if ( a3 == ++v4 )
goto LABEL_6;
}
if ( a3 != v4 )
goto LABEL_4;
LABEL_6:
ndn_charbuf_append(a1, "...", 3LL);
LABEL_4:
v5 = 0LL;
do
{
v7 = *(_BYTE *)(a2 + v5);
v8[0] = v7;
if ( is_uri_reserved(v7) )
result = ndn_charbuf_putf(a1, "%%%02X", v7);
else
result = ndn_charbuf_append(a1, v8, 1LL);
++v5;
}
while ( a3 > v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rbp
__int64 result; // rax
unsigned __int8 v7; // bl
char v8[57]; // [rsp+Fh] [rbp-39h] BYREF

v4 = 0LL;
if ( !a3 )
return ndn_charbuf_append(a1, "...", 3LL);
while ( *(_BYTE *)(a2 + v4) == 46 )
{
if ( a3 == ++v4 )
goto LABEL_6;
}
if ( a3 != v4 )
goto LABEL_4;
LABEL_6:
ndn_charbuf_append(a1, "...", 3LL);
LABEL_4:
v5 = 0LL;
do
{
v7 = *(_BYTE *)(a2 + v5);
v8[0] = v7;
if ( func0(v7) )
result = ndn_charbuf_putf(a1, "%%%02X", v7);
else
result = ndn_charbuf_append(a1, v8, 1LL);
++v5;
}
while ( a3 > v5 );
return result;
}

original_code:
void
ndn_uri_append_percentescaped(struct ndn_charbuf *c,
                              const unsigned char *data, size_t size)
{
    size_t i;
    unsigned char ch;
    for (i = 0; i < size && data[i] == '.'; i++)
        continue;
    if (i == size)
        ndn_charbuf_append(c, "...", 3);
    for (i = 0; i < size; i++) {
        ch = data[i];
        if (is_uri_reserved(ch))
            ndn_charbuf_putf(c, "%%%02X", (unsigned)ch);
        else
            ndn_charbuf_append(c, &ch, 1);
    }
}

canonical_original_code:
void ndn_uri_append_percentescaped(struct ndn_charbuf *c, unsigned char *data, unsigned long size)
{
    unsigned long i;
    unsigned char ch;
    for (i = 0; i < size && data[i] == '.'; i++)
        continue;
    if (i == size)
        ndn_charbuf_append(c, "...", 3);
    for (i = 0; i < size; i++) {
        ch = data[i];
        if (is_uri_reserved(ch))
            ndn_charbuf_putf(c, "%%%02X", (unsigned int)ch);
        else
            ndn_charbuf_append(c, &ch, 1);
    }
}

variable_types:
data
unsigned char *

variable_types:
i
unsigned long

variable_types:
ch
unsigned char

return_type: void

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


decompiled_code:
__int64 __fastcall ndn_uri_append_mixedescaped(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
__int64 v4; // rax
int v5; // er15
unsigned __int64 v6; // rbp
__int64 result; // rax
unsigned __int8 v8; // bl
char v9[57]; // [rsp+1Fh] [rbp-39h] BYREF

v4 = 0LL;
if ( !a3 )
return ndn_charbuf_append(a1, "...", 3LL);
while ( a2[v4] == 46 )
{
if ( a3 == ++v4 )
goto LABEL_8;
}
if ( a3 != v4 )
goto LABEL_4;
LABEL_8:
ndn_charbuf_append(a1, "...", 3LL);
LABEL_4:
if ( !*a2 || (v5 = 0, *a2 == 0xFD) )
{
ndn_charbuf_append(a1, "=", 1LL);
v5 = 1;
}
v6 = 0LL;
do
{
v8 = a2[v6];
v9[0] = v8;
if ( v5 )
{
result = ndn_charbuf_putf(a1, "%02X", v8);
}
else if ( is_uri_reserved(v8) )
{
if ( v8 && (v6 + 1 == a3 || !is_uri_reserved(a2[v6 + 1])) )
{
result = ndn_charbuf_putf(a1, "%%%02X", v8);
}
else
{
result = ndn_charbuf_putf(a1, "=%02X", v8);
v5 = 1;
}
}
else
{
result = ndn_charbuf_append(a1, v9, 1LL);
v5 = 0;
}
++v6;
}
while ( a3 > v6 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _BYTE *a2, unsigned __int64 a3)
{
__int64 v4; // rax
int v5; // er15
unsigned __int64 v6; // rbp
__int64 result; // rax
unsigned __int8 v8; // bl
char v9[57]; // [rsp+1Fh] [rbp-39h] BYREF

v4 = 0LL;
if ( !a3 )
return ndn_charbuf_append(a1, "...", 3LL);
while ( a2[v4] == 46 )
{
if ( a3 == ++v4 )
goto LABEL_8;
}
if ( a3 != v4 )
goto LABEL_4;
LABEL_8:
ndn_charbuf_append(a1, "...", 3LL);
LABEL_4:
if ( !*a2 || (v5 = 0, *a2 == 0xFD) )
{
ndn_charbuf_append(a1, "=", 1LL);
v5 = 1;
}
v6 = 0LL;
do
{
v8 = a2[v6];
v9[0] = v8;
if ( v5 )
{
result = ndn_charbuf_putf(a1, "%02X", v8);
}
else if ( func0(v8) )
{
if ( v8 && (v6 + 1 == a3 || !func0(a2[v6 + 1])) )
{
result = ndn_charbuf_putf(a1, "%%%02X", v8);
}
else
{
result = ndn_charbuf_putf(a1, "=%02X", v8);
v5 = 1;
}
}
else
{
result = ndn_charbuf_append(a1, v9, 1LL);
v5 = 0;
}
++v6;
}
while ( a3 > v6 );
return result;
}

original_code:
void
ndn_uri_append_mixedescaped(struct ndn_charbuf *c,
                              const unsigned char *data, size_t size)
{
    size_t i;
    unsigned char ch;
    int hexmode = 0;
    for (i = 0; i < size && data[i] == '.'; i++)
        continue;
    if (i == size)
        ndn_charbuf_append(c, "...", 3);
    if (size == 0)
        return;
    if (data[0] == '\0' || data[0] == (unsigned char)'\xFD') {
        hexmode = 1;
        ndn_charbuf_append(c, "=", 1);
    }
    for (i = 0; i < size; i++) {
        ch = data[i];
        if (hexmode)
            ndn_charbuf_putf(c, "%02X", (unsigned)ch);
        else if (!is_uri_reserved(ch))
            ndn_charbuf_append(c, &ch, 1);
        else {
            if (ch > 0 && (i + 1 == size || !is_uri_reserved(data[i + 1])))
                ndn_charbuf_putf(c, "%%%02X", (unsigned)ch);
            else {
                hexmode = 1;
                ndn_charbuf_putf(c, "=%02X", (unsigned)ch);
            }
        }
    }
}

canonical_original_code:
void ndn_uri_append_mixedescaped(struct ndn_charbuf *c, unsigned char *data, unsigned long size)
{
    unsigned long i;
    unsigned char ch;
    int hexmode = 0;
    for (i = 0; i < size && data[i] == '.'; i++)
        continue;
    if (i == size)
        ndn_charbuf_append(c, "...", 3);
    if (size == 0)
        return;
    if (data[0] == '\0' || data[0] == (unsigned char)'\xFD') {
        hexmode = 1;
        ndn_charbuf_append(c, "=", 1);
    }
    for (i = 0; i < size; i++) {
        ch = data[i];
        if (hexmode)
            ndn_charbuf_putf(c, "%02X", (unsigned int)ch);
        else if (!is_uri_reserved(ch))
            ndn_charbuf_append(c, &ch, 1);
        else {
            if (ch > 0 && (i + 1 == size || !is_uri_reserved(data[i + 1])))
                ndn_charbuf_putf(c, "%%%02X", (unsigned int)ch);
            else {
                hexmode = 1;
                ndn_charbuf_putf(c, "=%02X", (unsigned int)ch);
            }
        }
    }
}

variable_types: hexmode int


decompiled_code:
__int64 __fastcall ndn_uri_append(__int64 a1, __int64 a2, __int64 a3, char a4)
{
__int64 v5; // rbx
unsigned int v6; // er12
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-78h] BYREF
unsigned __int64 v9; // [rsp+40h] [rbp-38h] BYREF
_BYTE *v10; // [rsp+48h] [rbp-30h] BYREF

v10 = 0LL;
v9 = 0LL;
v5 = ndn_buf_decoder_start(&v8, a2, a3);
if ( (unsigned int)ndn_buf_match_dtag(v5, 26LL) || (unsigned int)ndn_buf_match_dtag(v5, 64LL) )
{
ndn_buf_advance(v5);
if ( (unsigned int)ndn_buf_match_dtag(v5, 37LL) )
ndn_buf_advance_past_element(v5);
}
if ( !(unsigned int)ndn_buf_match_dtag(v5, 14LL) )
return 0xFFFFFFFFLL;
if ( (a4 & 1) != 0 )
ndn_charbuf_append_string(a1, "ndn:");
ndn_buf_advance(v5);
v6 = 0;
while ( (unsigned int)ndn_buf_match_dtag(v5, 15LL) )
{
ndn_buf_advance(v5);
v9 = 0LL;
if ( (unsigned int)ndn_buf_match_blob(v5, &v10, &v9) )
ndn_buf_advance(v5);
ndn_buf_check_close(v5);
result = *(unsigned int *)(v5 + 8);
if ( (int)result < 0 )
return result;
++v6;
ndn_charbuf_append(a1, "/", 1LL);
if ( (a4 & 6) == 0 )
a4 |= 4u;
if ( (a4 & 2) != 0 )
{
ndn_uri_append_mixedescaped(a1, v10, v9);
}
else if ( (a4 & 4) != 0 )
{
ndn_uri_append_percentescaped(a1, (__int64)v10, v9);
}
}
ndn_buf_check_close(v5);
result = *(unsigned int *)(v5 + 8);
if ( (int)result >= 0 )
{
result = v6;
if ( !v6 )
{
ndn_charbuf_append(a1, "/", 1LL);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, char a4)
{
__int64 v5; // rbx
unsigned int v6; // er12
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-78h] BYREF
unsigned __int64 v9; // [rsp+40h] [rbp-38h] BYREF
_BYTE *v10; // [rsp+48h] [rbp-30h] BYREF

v10 = 0LL;
v9 = 0LL;
v5 = ndn_buf_decoder_start(&v8, a2, a3);
if ( (unsigned int)ndn_buf_match_dtag(v5, 26LL) || (unsigned int)ndn_buf_match_dtag(v5, 64LL) )
{
ndn_buf_advance(v5);
if ( (unsigned int)ndn_buf_match_dtag(v5, 37LL) )
ndn_buf_advance_past_element(v5);
}
if ( !(unsigned int)ndn_buf_match_dtag(v5, 14LL) )
return 0xFFFFFFFFLL;
if ( (a4 & 1) != 0 )
ndn_charbuf_append_string(a1, "ndn:");
ndn_buf_advance(v5);
v6 = 0;
while ( (unsigned int)ndn_buf_match_dtag(v5, 15LL) )
{
ndn_buf_advance(v5);
v9 = 0LL;
if ( (unsigned int)ndn_buf_match_blob(v5, &v10, &v9) )
ndn_buf_advance(v5);
ndn_buf_check_close(v5);
result = *(unsigned int *)(v5 + 8);
if ( (int)result < 0 )
return result;
++v6;
ndn_charbuf_append(a1, "/", 1LL);
if ( (a4 & 6) == 0 )
a4 |= 4u;
if ( (a4 & 2) != 0 )
{
func5(a1, v10, v9);
}
else if ( (a4 & 4) != 0 )
{
func4(a1, (__int64)v10, v9);
}
}
ndn_buf_check_close(v5);
result = *(unsigned int *)(v5 + 8);
if ( (int)result >= 0 )
{
result = v6;
if ( !v6 )
{
ndn_charbuf_append(a1, "/", 1LL);
result = 0LL;
}
}
return result;
}

original_code:
int
ndn_uri_append(struct ndn_charbuf *c,
               const unsigned char *ndnb,
               size_t size,
               int flags)
{
    int ncomp = 0;
    const unsigned char *comp = ((void *)0);
    size_t compsize = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, ndnb, size);
    if (ndn_buf_match_dtag(d, NDN_DTAG_Interest) ||
        ndn_buf_match_dtag(d, NDN_DTAG_ContentObject)) {
        ndn_buf_advance(d);
        if (ndn_buf_match_dtag(d, NDN_DTAG_Signature))
            ndn_buf_advance_past_element(d);
    }
    if (!ndn_buf_match_dtag(d, NDN_DTAG_Name))
        return(-1);
    if (flags & 1)
        ndn_charbuf_append_string(c, "ndn:");
    ndn_buf_advance(d);
    while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
        ndn_buf_advance(d);
        compsize = 0;
        if (ndn_buf_match_blob(d, &comp, &compsize))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
        if (d->decoder.state < 0)
            return(d->decoder.state);
        ncomp += 1;
        ndn_charbuf_append(c, "/", 1);
        if ((flags & (2|4)) == 0)
            flags |= 4;
        if (flags & 2) {
            ndn_uri_append_mixedescaped(c, comp, compsize);
        } else if (flags & 4)
            ndn_uri_append_percentescaped(c, comp, compsize);
    }
    ndn_buf_check_close(d);
    if (d->decoder.state < 0)
        return (d->decoder.state);
    if (ncomp == 0)
        ndn_charbuf_append(c, "/", 1);
    return(ncomp);
}

canonical_original_code:
int ndn_uri_append(struct ndn_charbuf *c, unsigned char *ndnb, unsigned long size, int flags)
{
    int ncomp = 0;
    unsigned char *comp = ((void *)0);
    unsigned long compsize = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, ndnb, size);
    if (ndn_buf_match_dtag(d, NDN_DTAG_Interest) ||
        ndn_buf_match_dtag(d, NDN_DTAG_ContentObject)) {
        ndn_buf_advance(d);
        if (ndn_buf_match_dtag(d, NDN_DTAG_Signature))
            ndn_buf_advance_past_element(d);
    }
    if (!ndn_buf_match_dtag(d, NDN_DTAG_Name))
        return(-1);
    if (flags & 1)
        ndn_charbuf_append_string(c, "ndn:");
    ndn_buf_advance(d);
    while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
        ndn_buf_advance(d);
        compsize = 0;
        if (ndn_buf_match_blob(d, &comp, &compsize))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
        if (d->decoder.state < 0)
            return(d->decoder.state);
        ncomp += 1;
        ndn_charbuf_append(c, "/", 1);
        if ((flags & (2|4)) == 0)
            flags |= 4;
        if (flags & 2) {
            ndn_uri_append_mixedescaped(c, comp, compsize);
        } else if (flags & 4)
            ndn_uri_append_percentescaped(c, comp, compsize);
    }
    ndn_buf_check_close(d);
    if (d->decoder.state < 0)
        return (d->decoder.state);
    if (ncomp == 0)
        ndn_charbuf_append(c, "/", 1);
    return(ncomp);
}

variable_types: flags int

variable_types: ncomp int

variable_types:
comp
unsigned char *

variable_types:
compsize
unsigned long

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


decompiled_code:
__int64 __fastcall ndn_name_from_uri(__int64 *a1, const char *a2)
{
int v2; // er13
unsigned __int64 v3; // rbx
const char *v4; // r15
unsigned __int64 *v5; // rax
const char *v6; // rbx
int v7; // ebp
__int64 v8; // rbx
int v9; // eax
unsigned __int64 v11; // r14
unsigned __int64 v12; // rax
unsigned __int64 v13; // rdx
__int64 v14; // rsi
int v15; // eax
unsigned __int64 v16; // rcx
int v17; // eax
unsigned __int64 v18; // [rsp+0h] [rbp-48h] BYREF
unsigned __int64 *v19[8]; // [rsp+8h] [rbp-40h] BYREF

v2 = (int)a2;
v3 = strlen(a2);
v4 = &a2[v3];
v18 = 0LL;
v5 = (unsigned __int64 *)ndn_charbuf_create();
v19[0] = v5;
if ( !v5 )
return 0xFFFFFFFFLL;
if ( *a2 == 47 )
{
v6 = a2;
v7 = 0;
LABEL_4:
ndn_name_init(a1);
if ( v6[1] == 47 )
{
v8 = (__int64)(v6 + 2);
*v19[0] = 0LL;
v9 = ndn_append_uri_component(v19[0], v8, (unsigned __int64)&v4[-v8], &v18);
v7 = v9;
if ( v9 < 0 && v9 != -2 )
{
LABEL_28:
ndn_charbuf_destroy(v19);
return 0xFFFFFFFFLL;
}
v6 = (const char *)(v18 + v8);
v18 = 0LL;
}
LABEL_15:
v12 = *(unsigned __int8 *)v6;
if ( (unsigned __int8)v12 > 0x3Fu || (v13 = 0x8000000800000001LL, !_bittest64((const __int64 *)&v13, v12)) )
{
while ( 1 )
{
*v19[0] = 0LL;
v14 = (__int64)&v6[(_BYTE)v12 == 47];
v15 = ndn_append_uri_component(v19[0], v14, (unsigned __int64)&v4[-v14], &v18);
v6 = (const char *)(v18 + v14);
v18 = 0LL;
if ( v15 < -2 )
goto LABEL_28;
if ( v15 == -2 )
{
v7 = 0;
}
else if ( v15 == -1 )
{
v17 = ndn_name_last_component_offset(a1[2], *a1);
v7 = v17;
if ( v17 < 0 )
goto LABEL_28;
*a1 = v17;
ndn_charbuf_append_closer(a1);
}
else
{
v7 = ndn_name_append(a1, v19[0][2], *v19[0]);
if ( v7 < 0 )
goto LABEL_28;
}
v12 = *(unsigned __int8 *)v6;
if ( (unsigned __int8)v12 <= 0x3Fu )
{
v16 = 0x8000000800000001LL;
if ( _bittest64((const __int64 *)&v16, v12) )
goto LABEL_9;
}
}
}
goto LABEL_9;
}
v7 = ndn_append_uri_component(v5, (__int64)a2, v3, &v18);
v6 = a2;
if ( v7 >= -2 )
{
*(_BYTE *)ndn_charbuf_reserve(v19[0], 1LL) = 0;
v11 = v18;
if ( a2[v18 - 1] == 58 )
{
if ( strcasecmp(*((const char **)v19[0] + 2), "ndn:") )
return 0xFFFFFFFFLL;
v6 = &a2[v11];
v18 = 0LL;
}
if ( *v6 != 47 )
goto LABEL_15;
goto LABEL_4;
}
LABEL_9:
ndn_charbuf_destroy(v19);
if ( v7 < 0 )
return 0xFFFFFFFFLL;
if ( (unsigned __int64)*a1 <= 1 )
return 0xFFFFFFFFLL;
if ( *(_BYTE *)(a1[2] + *a1 - 1) )
return 0xFFFFFFFFLL;
return (unsigned int)((_DWORD)v6 - v2);
}

original_code:
int
ndn_name_from_uri(struct ndn_charbuf *c, const char *uri)
{
    int res = 0;
    struct ndn_charbuf *compbuf = ((void *)0);
    const char *stop = uri + strlen(uri);
    const char *s = uri;
    size_t cont = 0;
    compbuf = ndn_charbuf_create();
    if (compbuf == ((void *)0)) return(-1);
    if (s[0] != '/') {
        res = ndn_append_uri_component(compbuf, s, stop - s, &cont);
        if (res < -2)
            goto Done;
        ndn_charbuf_reserve(compbuf, 1)[0] = 0;
        if (s[cont-1] == ':') {
            if ((0 == strcasecmp((const char *)(compbuf->buf), "ndn:") ||
                 0 == strcasecmp((const char *)(compbuf->buf), "ndn:"))) {
                s += cont;
                cont = 0;
            } else
                return (-1);
        }
    }
    if (s[0] == '/') {
        ndn_name_init(c);
        if (s[1] == '/') {
            s += 2;
            compbuf->length = 0;
            res = ndn_append_uri_component(compbuf, s, stop - s, &cont);
            if (res < 0 && res != -2)
                goto Done;
            s += cont; cont = 0;
        }
    }
    while (s[0] != 0 && s[0] != '?' && s[0] != '#') {
        if (s[0] == '/')
            s++;
        compbuf->length = 0;
        res = ndn_append_uri_component(compbuf, s, stop - s, &cont);
        s += cont; cont = 0;
        if (res < -2)
            goto Done;
        if (res == -2) {
            res = 0;
            continue;
        }
        if (res == -1) {
            res = ndn_name_last_component_offset(c->buf, c->length);
            if (res < 0)
                goto Done;
            c->length = res;
            ndn_charbuf_append_closer(c);
            continue;
        }
        res = ndn_name_append(c, compbuf->buf, compbuf->length);
        if (res < 0)
            goto Done;
    }
Done:
    ndn_charbuf_destroy(&compbuf);
    if (res < 0)
        return(-1);
    if (c->length < 2 || c->buf[c->length-1] != ((unsigned char)(0)))
        return(-1);
    return(s - uri);
}

canonical_original_code:
int ndn_name_from_uri(struct ndn_charbuf *c, char *uri)
{
    int res = 0;
    struct ndn_charbuf *compbuf = ((void *)0);
    char *stop = uri + strlen(uri);
    char *s = uri;
    unsigned long cont = 0;
    compbuf = ndn_charbuf_create();
    if (compbuf == ((void *)0)) return(-1);
    if (s[0] != '/') {
        res = ndn_append_uri_component(compbuf, s, stop - s, &cont);
        if (res < -2)
            goto Done;
        ndn_charbuf_reserve(compbuf, 1)[0] = 0;
        if (s[cont-1] == ':') {
            if ((0 == strcasecmp((char *)(compbuf->buf), "ndn:") ||
                 0 == strcasecmp((char *)(compbuf->buf), "ndn:"))) {
                s += cont;
                cont = 0;
            } else
                return (-1);
        }
    }
    if (s[0] == '/') {
        ndn_name_init(c);
        if (s[1] == '/') {
            s += 2;
            compbuf->length = 0;
            res = ndn_append_uri_component(compbuf, s, stop - s, &cont);
            if (res < 0 && res != -2)
                goto Done;
            s += cont; cont = 0;
        }
    }
    while (s[0] != 0 && s[0] != '?' && s[0] != '#') {
        if (s[0] == '/')
            s++;
        compbuf->length = 0;
        res = ndn_append_uri_component(compbuf, s, stop - s, &cont);
        s += cont; cont = 0;
        if (res < -2)
            goto Done;
        if (res == -2) {
            res = 0;
            continue;
        }
        if (res == -1) {
            res = ndn_name_last_component_offset(c->buf, c->length);
            if (res < 0)
                goto Done;
            c->length = res;
            ndn_charbuf_append_closer(c);
            continue;
        }
        res = ndn_name_append(c, compbuf->buf, compbuf->length);
        if (res < 0)
            goto Done;
    }
Done:
    ndn_charbuf_destroy(&compbuf);
    if (res < 0)
        return(-1);
    if (c->length < 2 || c->buf[c->length-1] != ((unsigned char)(0)))
        return(-1);
    return(s - uri);
}

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

variable_types:
uri
char *

variable_types:
stop
char *

variable_types:
s
char *

variable_types:
cont
unsigned long


takedown

decompiled_code:
__int64 __fastcall takedown(signed int a1, signed int a2)
{
if ( a2 > 0 )
{
fillout(0x20u, a2);
fillout(8u, a2);
}
if ( a1 > 0 )
{
fillout(8u, a1);
fillout(0x20u, a1);
fillout(8u, a1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(signed int a1, signed int a2)
{
if ( a2 > 0 )
{
func0(0x20u, a2);
func0(8u, a2);
}
if ( a1 > 0 )
{
func0(8u, a1);
func0(0x20u, a1);
func0(8u, a1);
}
return 0LL;
}

original_code:
static int
takedown(int n, int r)
{
    if (r > 0) {
        fillout(' ', r);
        fillout('\b', r);
    }
    if (n > 0) {
        fillout('\b', n);
        fillout(' ', n);
        fillout('\b', n);
    }
    return(0);
}

variable_types: n int

variable_types: r int


decompiled_code:
__int64 __fastcall lned_run(unsigned int a1, __int64 a2, const char *a3, __int64 (__fastcall *a4)(_QWORD, __int64))
{
struct termios *v6; // rbx
int i; // ebp
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-13Ch] BYREF
int v10; // [rsp+14h] [rbp-134h]
char buf[8]; // [rsp+18h] [rbp-130h] BYREF
struct termios termios_p[4]; // [rsp+20h] [rbp-128h] BYREF

HIDWORD(stat_loc.__iptr) = -1;
v10 = -1;
v6 = termios_p;
memset(termios_p, 0, sizeof(termios_p));
for ( i = 0; i != 3; ++i )
{
if ( tcgetattr(i, v6) < 0 && i <= 1 )
return a4(a1, a2);
++v6;
}
if ( socketpair(1, 1, 0, (int *)&stat_loc.__iptr + 1) < 0 )
return a4(a1, a2);
*(__m128i *)&termios_p[3].c_iflag = _mm_loadu_si128((const __m128i *)termios_p);
*(__m128i *)&termios_p[3].c_line = _mm_loadu_si128((const __m128i *)&termios_p[0].c_line);
*(__m128i *)&termios_p[3].c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p[0].c_cc[15]);
*(_QWORD *)&termios_p[3].c_cc[31] = *(_QWORD *)&termios_p[0].c_cc[31];
termios_p[3].c_ospeed = termios_p[0].c_ospeed;
termios_p[3].c_lflag &= 0xFFFFFFF5;
termios_p[3].c_cc[6] = 1;
termios_p[3].c_cc[5] = 0;
if ( tcsetattr(0, 0, &termios_p[3]) < 0 )
return a4(a1, a2);
if ( !fork() )
{
dup2(v10, 0);
dup2(v10, 1);
if ( isatty(2) )
dup2(v10, 2);
close(SHIDWORD(stat_loc.__iptr));
close(v10);
return a4(a1, a2);
}
close(v10);
dup2(1, 2);
shuttle(SHIDWORD(stat_loc.__iptr), a3);
shutdown(SHIDWORD(stat_loc.__iptr), 1);
while ( read(SHIDWORD(stat_loc.__iptr), buf, 1uLL) == 1 )
write(1, buf, 1uLL);
wait((__WAIT_STATUS)&stat_loc);
tcsetattr(0, 0, termios_p);
return LODWORD(stat_loc.__uptr);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 a2, const char *a3, __int64 (__fastcall *a4)(_QWORD, __int64))
{
struct termios *v6; // rbx
int i; // ebp
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-13Ch] BYREF
int v10; // [rsp+14h] [rbp-134h]
char buf[8]; // [rsp+18h] [rbp-130h] BYREF
struct termios termios_p[4]; // [rsp+20h] [rbp-128h] BYREF

HIDWORD(stat_loc.__iptr) = -1;
v10 = -1;
v6 = termios_p;
memset(termios_p, 0, sizeof(termios_p));
for ( i = 0; i != 3; ++i )
{
if ( tcgetattr(i, v6) < 0 && i <= 1 )
return a4(a1, a2);
++v6;
}
if ( socketpair(1, 1, 0, (int *)&stat_loc.__iptr + 1) < 0 )
return a4(a1, a2);
*(__m128i *)&termios_p[3].c_iflag = _mm_loadu_si128((const __m128i *)termios_p);
*(__m128i *)&termios_p[3].c_line = _mm_loadu_si128((const __m128i *)&termios_p[0].c_line);
*(__m128i *)&termios_p[3].c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p[0].c_cc[15]);
*(_QWORD *)&termios_p[3].c_cc[31] = *(_QWORD *)&termios_p[0].c_cc[31];
termios_p[3].c_ospeed = termios_p[0].c_ospeed;
termios_p[3].c_lflag &= 0xFFFFFFF5;
termios_p[3].c_cc[6] = 1;
termios_p[3].c_cc[5] = 0;
if ( tcsetattr(0, 0, &termios_p[3]) < 0 )
return a4(a1, a2);
if ( !fork() )
{
dup2(v10, 0);
dup2(v10, 1);
if ( isatty(2) )
dup2(v10, 2);
close(SHIDWORD(stat_loc.__iptr));
close(v10);
return a4(a1, a2);
}
close(v10);
dup2(1, 2);
func3(SHIDWORD(stat_loc.__iptr), a3);
shutdown(SHIDWORD(stat_loc.__iptr), 1);
while ( read(SHIDWORD(stat_loc.__iptr), buf, 1uLL) == 1 )
write(1, buf, 1uLL);
wait((__WAIT_STATUS)&stat_loc);
tcsetattr(0, 0, termios_p);
return LODWORD(stat_loc.__uptr);
}

original_code:
int
lned_run(int argc, char** argv, const char *prompt, int (*worker)(int, char**))
{
    struct termios tc[4];
    struct termios *t;
    char cb[8];
    int sp[2] = {-1, -1};
    int i;
    int res;
    int st;
    pid_t pid;
    memset(tc, 0, sizeof(tc));
    for (i = 0; i < 3; i++) {
        res = tcgetattr(i, &(tc[i]));
        if (res < 0 && i < 2)
            goto Direct;
    }
    res = socketpair(1, SOCK_STREAM, 0, sp);
    if (res < 0) goto Direct;
    t = &(tc[3]);
    *t = tc[0];
    t->c_lflag &= ~(0000010 | 0000002);
    t->c_cc[6] = 1;
    t->c_cc[5] = 0;
    res = tcsetattr(0, 0, t);
    if (res < 0) goto Direct;
    pid = fork();
    if (pid == 0) {
        dup2(sp[1], 0);
        dup2(sp[1], 1);
        if (isatty(2))
            dup2(sp[1], 2);
        close(sp[0]);
        close(sp[1]);
        goto Direct;
    }
    close(sp[1]);
    dup2(1, 2);
    shuttle(sp[0], prompt);
    shutdown(sp[0], SHUT_WR);
    while (read(sp[0], cb, 1) == 1)
        write(1, cb, 1);
    wait(&st);
    tcsetattr(0, 0, &(tc[0]));
    return(st);
Direct:
    return(worker(argc, argv));
}

canonical_original_code:
int lned_run(int argc, char **argv, char *prompt, int (*worker)(int, char **))
{
    struct termios tc[4];
    struct termios *t;
    char cb[8];
    int sp[2] = {-1, -1};
    int i;
    int res;
    int st;
    int pid;
    memset(tc, 0, sizeof(tc));
    for (i = 0; i < 3; i++) {
        res = tcgetattr(i, &(tc[i]));
        if (res < 0 && i < 2)
            goto Direct;
    }
    res = socketpair(1, SOCK_STREAM, 0, sp);
    if (res < 0) goto Direct;
    t = &(tc[3]);
    *t = tc[0];
    t->c_lflag &= ~(0000010 | 0000002);
    t->c_cc[6] = 1;
    t->c_cc[5] = 0;
    res = tcsetattr(0, 0, t);
    if (res < 0) goto Direct;
    pid = fork();
    if (pid == 0) {
        dup2(sp[1], 0);
        dup2(sp[1], 1);
        if (isatty(2))
            dup2(sp[1], 2);
        close(sp[0]);
        close(sp[1]);
        goto Direct;
    }
    close(sp[1]);
    dup2(1, 2);
    shuttle(sp[0], prompt);
    shutdown(sp[0], SHUT_WR);
    while (read(sp[0], cb, 1) == 1)
        write(1, cb, 1);
    wait(&st);
    tcsetattr(0, 0, &(tc[0]));
    return(st);
Direct:
    return(worker(argc, argv));
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
prompt
char *

variable_types:
worker
int (*)(int, char **)

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } [4]

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } *

variable_types:
cb
char [8]

variable_types:
sp
int [2]

variable_types: i int

variable_types: res int

variable_types: st int

variable_types: pid int


decompiled_code:
_BOOL8 __fastcall ndn_excluded(__int64 a1, __int64 a2, const void *a3, size_t a4)
{
__int64 v6; // rbx
int v7; // eax
_BOOL8 result; // rax
__int64 v9; // rdi
unsigned __int64 v10; // [rsp+0h] [rbp-88h] BYREF
void *s1; // [rsp+8h] [rbp-80h] BYREF
char v12[56]; // [rsp+10h] [rbp-78h] BYREF
__int64 v13; // [rsp+48h] [rbp-40h] BYREF
__int16 *v14; // [rsp+50h] [rbp-38h] BYREF
__int16 v15[21]; // [rsp+5Eh] [rbp-2Ah] BYREF

v15[0] = 45;
v14 = 0LL;
v13 = 0LL;
v6 = ndn_buf_decoder_start(v12, a1, a2);
s1 = 0LL;
v10 = 0LL;
if ( !(unsigned int)ndn_buf_match_dtag(v6, 43LL) )
abort();
ndn_buf_advance(v6);
if ( (unsigned int)ndn_buf_match_dtag(v6, 13LL) )
{
ndn_buf_advance(v6);
v14 = v15;
ndn_buf_check_close(v6);
}
else if ( (unsigned int)ndn_buf_match_dtag(v6, 44LL) )
{
ndn_buf_advance(v6);
if ( (unsigned int)ndn_buf_match_blob(v6, &v14, &v13) )
ndn_buf_advance(v6);
ndn_buf_check_close(v6);
}
while ( (unsigned int)ndn_buf_match_dtag(v6, 15LL) )
{
ndn_buf_advance(v6);
v10 = 0LL;
if ( (unsigned int)ndn_buf_match_blob(v6, &s1, &v10) )
ndn_buf_advance(v6);
ndn_buf_check_close(v6);
if ( v10 > a4 )
break;
if ( v10 == a4 )
{
v7 = memcmp(s1, a3, a4);
if ( !v7 )
return 1LL;
if ( v7 > 0 )
break;
}
v14 = 0LL;
v13 = 0LL;
if ( (unsigned int)ndn_buf_match_dtag(v6, 13LL) )
{
ndn_buf_advance(v6);
v14 = v15;
ndn_buf_check_close(v6);
}
else if ( (unsigned int)ndn_buf_match_dtag(v6, 44LL) )
{
ndn_buf_advance(v6);
if ( (unsigned int)ndn_buf_match_blob(v6, &v14, &v13) )
ndn_buf_advance(v6);
ndn_buf_check_close(v6);
}
}
if ( v14 == v15 )
return 1LL;
result = 0LL;
if ( v13 )
{
v9 = ndn_bloom_validate_wire();
result = 1LL;
if ( v9 )
result = (unsigned int)ndn_bloom_match_wire(v9, a3, a4) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2, const void *a3, size_t a4)
{
__int64 v6; // rbx
int v7; // eax
_BOOL8 result; // rax
__int64 v9; // rdi
unsigned __int64 v10; // [rsp+0h] [rbp-88h] BYREF
void *s1; // [rsp+8h] [rbp-80h] BYREF
char v12[56]; // [rsp+10h] [rbp-78h] BYREF
__int64 v13; // [rsp+48h] [rbp-40h] BYREF
__int16 *v14; // [rsp+50h] [rbp-38h] BYREF
__int16 v15[21]; // [rsp+5Eh] [rbp-2Ah] BYREF

v15[0] = 45;
v14 = 0LL;
v13 = 0LL;
v6 = ndn_buf_decoder_start(v12, a1, a2);
s1 = 0LL;
v10 = 0LL;
if ( !(unsigned int)ndn_buf_match_dtag(v6, 43LL) )
abort();
ndn_buf_advance(v6);
if ( (unsigned int)ndn_buf_match_dtag(v6, 13LL) )
{
ndn_buf_advance(v6);
v14 = v15;
ndn_buf_check_close(v6);
}
else if ( (unsigned int)ndn_buf_match_dtag(v6, 44LL) )
{
ndn_buf_advance(v6);
if ( (unsigned int)ndn_buf_match_blob(v6, &v14, &v13) )
ndn_buf_advance(v6);
ndn_buf_check_close(v6);
}
while ( (unsigned int)ndn_buf_match_dtag(v6, 15LL) )
{
ndn_buf_advance(v6);
v10 = 0LL;
if ( (unsigned int)ndn_buf_match_blob(v6, &s1, &v10) )
ndn_buf_advance(v6);
ndn_buf_check_close(v6);
if ( v10 > a4 )
break;
if ( v10 == a4 )
{
v7 = memcmp(s1, a3, a4);
if ( !v7 )
return 1LL;
if ( v7 > 0 )
break;
}
v14 = 0LL;
v13 = 0LL;
if ( (unsigned int)ndn_buf_match_dtag(v6, 13LL) )
{
ndn_buf_advance(v6);
v14 = v15;
ndn_buf_check_close(v6);
}
else if ( (unsigned int)ndn_buf_match_dtag(v6, 44LL) )
{
ndn_buf_advance(v6);
if ( (unsigned int)ndn_buf_match_blob(v6, &v14, &v13) )
ndn_buf_advance(v6);
ndn_buf_check_close(v6);
}
}
if ( v14 == v15 )
return 1LL;
result = 0LL;
if ( v13 )
{
v9 = ndn_bloom_validate_wire();
result = 1LL;
if ( v9 )
result = (unsigned int)ndn_bloom_match_wire(v9, a3, a4) != 0;
}
return result;
}

original_code:
int
ndn_excluded(const unsigned char *excl,
             size_t excl_size,
             const unsigned char *nextcomp,
             size_t nextcomp_size)
{
    unsigned char match_any[2] = "-";
    const unsigned char *bloom = ((void *)0);
    size_t bloom_size = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, excl, excl_size);
    const unsigned char *comp = ((void *)0);
    size_t comp_size = 0;
    const int excluded = 1;
    if (!ndn_buf_match_dtag(d, NDN_DTAG_Exclude))
        abort();
    ndn_buf_advance(d);
    if (ndn_buf_match_dtag(d, NDN_DTAG_Any)) {
        ndn_buf_advance(d);
        bloom = match_any;
        ndn_buf_check_close(d);
    }
    else if (ndn_buf_match_dtag(d, NDN_DTAG_Bloom)) {
        ndn_buf_advance(d);
        if (ndn_buf_match_blob(d, &bloom, &bloom_size))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
    }
    while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
        ndn_buf_advance(d);
        comp_size = 0;
        if (ndn_buf_match_blob(d, &comp, &comp_size))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
        if (comp_size > nextcomp_size)
            break;
        if (comp_size == nextcomp_size) {
            int res = memcmp(comp, nextcomp, comp_size);
            if (res == 0)
                return(excluded);
            if (res > 0)
                break;
        }
        bloom = ((void *)0);
        bloom_size = 0;
        if (ndn_buf_match_dtag(d, NDN_DTAG_Any)) {
            ndn_buf_advance(d);
            bloom = match_any;
            ndn_buf_check_close(d);
        }
        else if (ndn_buf_match_dtag(d, NDN_DTAG_Bloom)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &bloom, &bloom_size))
                ndn_buf_advance(d);
            ndn_buf_check_close(d);
        }
    }
    if (bloom == match_any)
        return(excluded);
    else if (bloom_size != 0) {
        const struct ndn_bloom_wire *f = ndn_bloom_validate_wire(bloom, bloom_size);
        if (f == ((void *)0))
            return(excluded);
        if (ndn_bloom_match_wire(f, nextcomp, nextcomp_size))
            return(excluded);
    }
    return(!excluded);
}

canonical_original_code:
int ndn_excluded(unsigned char *excl, unsigned long excl_size, unsigned char *nextcomp, unsigned long nextcomp_size)
{
    unsigned char match_any[2] = "-";
    unsigned char *bloom = ((void *)0);
    unsigned long bloom_size = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d = ndn_buf_decoder_start(&decoder, excl, excl_size);
    unsigned char *comp = ((void *)0);
    unsigned long comp_size = 0;
    int excluded = 1;
    if (!ndn_buf_match_dtag(d, NDN_DTAG_Exclude))
        abort();
    ndn_buf_advance(d);
    if (ndn_buf_match_dtag(d, NDN_DTAG_Any)) {
        ndn_buf_advance(d);
        bloom = match_any;
        ndn_buf_check_close(d);
    }
    else if (ndn_buf_match_dtag(d, NDN_DTAG_Bloom)) {
        ndn_buf_advance(d);
        if (ndn_buf_match_blob(d, &bloom, &bloom_size))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
    }
    while (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
        ndn_buf_advance(d);
        comp_size = 0;
        if (ndn_buf_match_blob(d, &comp, &comp_size))
            ndn_buf_advance(d);
        ndn_buf_check_close(d);
        if (comp_size > nextcomp_size)
            break;
        if (comp_size == nextcomp_size) {
            int res = memcmp(comp, nextcomp, comp_size);
            if (res == 0)
                return(excluded);
            if (res > 0)
                break;
        }
        bloom = ((void *)0);
        bloom_size = 0;
        if (ndn_buf_match_dtag(d, NDN_DTAG_Any)) {
            ndn_buf_advance(d);
            bloom = match_any;
            ndn_buf_check_close(d);
        }
        else if (ndn_buf_match_dtag(d, NDN_DTAG_Bloom)) {
            ndn_buf_advance(d);
            if (ndn_buf_match_blob(d, &bloom, &bloom_size))
                ndn_buf_advance(d);
            ndn_buf_check_close(d);
        }
    }
    if (bloom == match_any)
        return(excluded);
    else if (bloom_size != 0) {
        struct ndn_bloom_wire *f = ndn_bloom_validate_wire(bloom, bloom_size);
        if (f == ((void *)0))
            return(excluded);
        if (ndn_bloom_match_wire(f, nextcomp, nextcomp_size))
            return(excluded);
    }
    return(!excluded);
}

variable_types:
excl
unsigned char *

variable_types:
nextcomp
unsigned char *

variable_types:
bloom
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:
comp
unsigned char *

variable_types: excluded int

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


decompiled_code:
__int64 __fastcall ndn_content_matches_interest(__int64 a1, __int64 a2, int a3, char *a4, __int64 a5, __int64 a6, char *a7)
{
char *v9; // rbx
char *v12; // rbp
__int64 result; // rax
int v14; // eax
unsigned __int16 v15; // di
int v16; // er15
unsigned __int16 v17; // si
int v18; // er10
__int64 v19; // rbx
__int64 v20; // rbp
int v21; // [rsp+4h] [rbp-184h]
int v22; // [rsp+8h] [rbp-180h]
size_t n; // [rsp+10h] [rbp-178h] BYREF
void *s1; // [rsp+18h] [rbp-170h] BYREF
size_t v25; // [rsp+20h] [rbp-168h] BYREF
const void *v26; // [rsp+28h] [rbp-160h] BYREF
char v27[64]; // [rsp+30h] [rbp-158h] BYREF
char v28[96]; // [rsp+70h] [rbp-118h] BYREF
char v29[184]; // [rsp+D0h] [rbp-B8h] BYREF

v9 = a4;
v12 = a7;
v25 = 0LL;
s1 = 0LL;
n = 0LL;
if ( !a4 )
{
if ( (int)ndn_parse_ContentObject(a1, a2, v29, 0LL) < 0 )
return 0LL;
v9 = v29;
}
if ( !a7 )
{
if ( (int)ndn_parse_interest(a5, a6, v28, 0LL) < 0 )
return 0LL;
v12 = v28;
}
result = ndn_pubid_matches(a1, (__int64)v9, a5, (__int64)v12);
if ( (_DWORD)result )
{
v14 = *((_DWORD *)v9 + 2) + (a3 != 0);
if ( *((_DWORD *)v12 + 2) + *((_DWORD *)v12 + 1) > v14 )
{
result = 0LL;
}
else
{
if ( *((_DWORD *)v12 + 3) + *((_DWORD *)v12 + 1) < v14 )
return 0LL;
v15 = *((_WORD *)v12 + 15);
v16 = *((unsigned __int16 *)v12 + 17) - v15;
v17 = *((_WORD *)v9 + 15);
v22 = *((unsigned __int16 *)v9 + 16);
v18 = v22 - v17;
v21 = v18;
if ( v16 <= v18 )
{
if ( memcmp((const void *)(a5 + v15), (const void *)(a1 + v17), v16) )
return 0LL;
if ( *((_WORD *)v12 + 28) <= *((_WORD *)v12 + 27) )
return 1LL;
if ( v16 < v21 )
{
v19 = ndn_buf_decoder_start(v27, a1 + v17 + v16, v22 - (v17 + v16));
result = ndn_buf_match_dtag(v19, 15LL);
if ( !(_DWORD)result )
return result;
ndn_buf_advance(v19);
ndn_buf_match_blob(v19, &v26, &v25);
}
else
{
if ( !a3 )
return 1LL;
if ( v16 != v21 )
abort();
ndn_digest_ContentObject(a1, (__int64)v9);
v25 = *((int *)v9 + 30);
v26 = v9 + 86;
}
return !ndn_excluded(
a5 + *((unsigned __int16 *)v12 + 27),
*((unsigned __int16 *)v12 + 28) - *((unsigned __int16 *)v12 + 27),
v26,
v25);
}
if ( a3 )
{
if ( *((unsigned __int16 *)v12 + 16) - v15 == v18 )
{
if ( *((unsigned __int16 *)v12 + 17) - *((unsigned __int16 *)v12 + 16) == 36 )
{
if ( !memcmp((const void *)(a5 + v15), (const void *)(a1 + v17), v18) )
{
ndn_digest_ContentObject(a1, (__int64)v9);
v20 = ndn_buf_decoder_start(
v27,
a5 + *((unsigned __int16 *)v12 + 16),
*((unsigned __int16 *)v12 + 17) - *((unsigned __int16 *)v12 + 16));
n = 0LL;
if ( (unsigned int)ndn_buf_match_dtag(v20, 15LL) )
{
ndn_buf_advance(v20);
ndn_buf_match_blob(v20, &s1, &n);
}
if ( *((_DWORD *)v9 + 30) != n )
abort();
result = memcmp(s1, v9 + 86, n) == 0;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
}
return result;
}

original_code:
int
ndn_content_matches_interest(const unsigned char *content_object,
                             size_t content_object_size,
                             int implicit_content_digest,
                             struct ndn_parsed_ContentObject *pc,
                             const unsigned char *interest_msg,
                             size_t interest_msg_size,
                             const struct ndn_parsed_interest *pi)
{
    struct ndn_parsed_ContentObject pc_store;
    struct ndn_parsed_interest pi_store;
    int res;
    int ncomps;
    int prefixstart;
    int prefixbytes;
    int namecompstart;
    int namecompbytes;
    int checkdigest = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d;
    const unsigned char *nextcomp;
    size_t nextcomp_size = 0;
    const unsigned char *comp = ((void *)0);
    size_t comp_size = 0;
    if (pc == ((void *)0)) {
        res = ndn_parse_ContentObject(content_object, content_object_size,
                                      &pc_store, ((void *)0));
        if (res < 0) return(0);
        pc = &pc_store;
    }
    if (pi == ((void *)0)) {
        res = ndn_parse_interest(interest_msg, interest_msg_size,
                                 &pi_store, ((void *)0));
        if (res < 0) return(0);
        pi = &pi_store;
    }
    if (!ndn_pubid_matches(content_object, pc, interest_msg, pi))
        return(0);
    ncomps = pc->name_ncomps + (implicit_content_digest ? 1 : 0);
    if (ncomps < pi->prefix_comps + pi->min_suffix_comps)
        return(0);
    if (ncomps > pi->prefix_comps + pi->max_suffix_comps)
        return(0);
    prefixstart = pi->offset[NDN_PI_B_Component0];
    prefixbytes = pi->offset[NDN_PI_E_LastPrefixComponent] - prefixstart;
    namecompstart = pc->offset[NDN_PCO_B_Component0];
    namecompbytes = pc->offset[NDN_PCO_E_ComponentLast] - namecompstart;
    if (prefixbytes > namecompbytes) {
        if (implicit_content_digest &&
            pi->offset[NDN_PI_B_LastPrefixComponent] - prefixstart == namecompbytes &&
            (pi->offset[NDN_PI_E_LastPrefixComponent] -
             pi->offset[NDN_PI_B_LastPrefixComponent]) == 1 + 2 + 32 + 1) {
            prefixbytes = namecompbytes;
            checkdigest = 1;
        }
        else
            return(0);
    }
    if (0 != memcmp(interest_msg + prefixstart,
                    content_object + namecompstart,
                    prefixbytes))
        return(0);
    if (checkdigest) {
        ndn_digest_ContentObject(content_object, pc);
        d = ndn_buf_decoder_start(&decoder,
                        interest_msg + pi->offset[NDN_PI_B_LastPrefixComponent],
                        (pi->offset[NDN_PI_E_LastPrefixComponent] -
                         pi->offset[NDN_PI_B_LastPrefixComponent]));
        comp_size = 0;
        if (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
                ndn_buf_advance(d);
                ndn_buf_match_blob(d, &comp, &comp_size);
            }
        if (comp_size != pc->digest_bytes) abort();
        if (0 != memcmp(comp, pc->digest, comp_size))
            return(0);
    }
    else if (pi->offset[NDN_PI_E_Exclude] > pi->offset[NDN_PI_B_Exclude]) {
        if (prefixbytes < namecompbytes) {
            d = ndn_buf_decoder_start(&decoder,
                                      content_object +
                                        (namecompstart + prefixbytes),
                                      pc->offset[NDN_PCO_E_ComponentLast] -
                                        (namecompstart + prefixbytes));
            if (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
                ndn_buf_advance(d);
                ndn_buf_match_blob(d, &nextcomp, &nextcomp_size);
            }
            else
                return(0);
        }
        else if (!implicit_content_digest)
            goto exclude_checked;
        else if (prefixbytes == namecompbytes) {
            ndn_digest_ContentObject(content_object, pc);
            nextcomp_size = pc->digest_bytes;
            nextcomp = pc->digest;
        }
        else abort();
        if (ndn_excluded(interest_msg + pi->offset[NDN_PI_B_Exclude],
                         (pi->offset[NDN_PI_E_Exclude] -
                          pi->offset[NDN_PI_B_Exclude]),
                         nextcomp,
                         nextcomp_size))
            return(0);
    exclude_checked: {}
    }
    return(1);
}

canonical_original_code:
int ndn_content_matches_interest(unsigned char *content_object, unsigned long content_object_size, int implicit_content_digest, struct ndn_parsed_ContentObject *pc, unsigned char *interest_msg, unsigned long interest_msg_size, struct ndn_parsed_interest *pi)
{
    struct ndn_parsed_ContentObject pc_store;
    struct ndn_parsed_interest pi_store;
    int res;
    int ncomps;
    int prefixstart;
    int prefixbytes;
    int namecompstart;
    int namecompbytes;
    int checkdigest = 0;
    struct ndn_buf_decoder decoder;
    struct ndn_buf_decoder *d;
    unsigned char *nextcomp;
    unsigned long nextcomp_size = 0;
    unsigned char *comp = ((void *)0);
    unsigned long comp_size = 0;
    if (pc == ((void *)0)) {
        res = ndn_parse_ContentObject(content_object, content_object_size,
                                      &pc_store, ((void *)0));
        if (res < 0) return(0);
        pc = &pc_store;
    }
    if (pi == ((void *)0)) {
        res = ndn_parse_interest(interest_msg, interest_msg_size,
                                 &pi_store, ((void *)0));
        if (res < 0) return(0);
        pi = &pi_store;
    }
    if (!ndn_pubid_matches(content_object, pc, interest_msg, pi))
        return(0);
    ncomps = pc->name_ncomps + (implicit_content_digest ? 1 : 0);
    if (ncomps < pi->prefix_comps + pi->min_suffix_comps)
        return(0);
    if (ncomps > pi->prefix_comps + pi->max_suffix_comps)
        return(0);
    prefixstart = pi->offset[NDN_PI_B_Component0];
    prefixbytes = pi->offset[NDN_PI_E_LastPrefixComponent] - prefixstart;
    namecompstart = pc->offset[NDN_PCO_B_Component0];
    namecompbytes = pc->offset[NDN_PCO_E_ComponentLast] - namecompstart;
    if (prefixbytes > namecompbytes) {
        if (implicit_content_digest &&
            pi->offset[NDN_PI_B_LastPrefixComponent] - prefixstart == namecompbytes &&
            (pi->offset[NDN_PI_E_LastPrefixComponent] -
             pi->offset[NDN_PI_B_LastPrefixComponent]) == 1 + 2 + 32 + 1) {
            prefixbytes = namecompbytes;
            checkdigest = 1;
        }
        else
            return(0);
    }
    if (0 != memcmp(interest_msg + prefixstart,
                    content_object + namecompstart,
                    prefixbytes))
        return(0);
    if (checkdigest) {
        ndn_digest_ContentObject(content_object, pc);
        d = ndn_buf_decoder_start(&decoder,
                        interest_msg + pi->offset[NDN_PI_B_LastPrefixComponent],
                        (pi->offset[NDN_PI_E_LastPrefixComponent] -
                         pi->offset[NDN_PI_B_LastPrefixComponent]));
        comp_size = 0;
        if (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
                ndn_buf_advance(d);
                ndn_buf_match_blob(d, &comp, &comp_size);
            }
        if (comp_size != pc->digest_bytes) abort();
        if (0 != memcmp(comp, pc->digest, comp_size))
            return(0);
    }
    else if (pi->offset[NDN_PI_E_Exclude] > pi->offset[NDN_PI_B_Exclude]) {
        if (prefixbytes < namecompbytes) {
            d = ndn_buf_decoder_start(&decoder,
                                      content_object +
                                        (namecompstart + prefixbytes),
                                      pc->offset[NDN_PCO_E_ComponentLast] -
                                        (namecompstart + prefixbytes));
            if (ndn_buf_match_dtag(d, NDN_DTAG_Component)) {
                ndn_buf_advance(d);
                ndn_buf_match_blob(d, &nextcomp, &nextcomp_size);
            }
            else
                return(0);
        }
        else if (!implicit_content_digest)
            goto exclude_checked;
        else if (prefixbytes == namecompbytes) {
            ndn_digest_ContentObject(content_object, pc);
            nextcomp_size = pc->digest_bytes;
            nextcomp = pc->digest;
        }
        else abort();
        if (ndn_excluded(interest_msg + pi->offset[NDN_PI_B_Exclude],
                         (pi->offset[NDN_PI_E_Exclude] -
                          pi->offset[NDN_PI_B_Exclude]),
                         nextcomp,
                         nextcomp_size))
            return(0);
    exclude_checked: {}
    }
    return(1);
}

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

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

variable_types: ncomps int

variable_types: prefixstart int

variable_types: prefixbytes int

variable_types: namecompstart int

variable_types: namecompbytes int

variable_types: checkdigest 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; }

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


decompiled_code:
__int64 __fastcall ms_to_tu(int a1)
{
return (unsigned int)((a1 << 12) / 1000);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)((a1 << 12) / 1000);
}

original_code:
static int
ms_to_tu(int m)
{
    return ((m * 4096) / 1000);
}

variable_types: m int


decompiled_code:
__int64 __fastcall append_future_vcomp(__int64 a1)
{
int v2; // [rsp+9h] [rbp-Fh] BYREF
__int16 v3; // [rsp+Dh] [rbp-Bh]
char v4; // [rsp+Fh] [rbp-9h]

v2 = 254;
v3 = 0;
v4 = 0;
ndn_charbuf_append_tt(a1, 15LL, 2LL);
ndn_charbuf_append_tt(a1, 7LL, 5LL);
ndn_charbuf_append(a1, &v2, 7LL);
return ndn_charbuf_append_closer(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v2; // [rsp+9h] [rbp-Fh] BYREF
__int16 v3; // [rsp+Dh] [rbp-Bh]
char v4; // [rsp+Fh] [rbp-9h]

v2 = 254;
v3 = 0;
v4 = 0;
ndn_charbuf_append_tt(a1, 15LL, 2LL);
ndn_charbuf_append_tt(a1, 7LL, 5LL);
ndn_charbuf_append(a1, &v2, 7LL);
return ndn_charbuf_append_closer(a1);
}

original_code:
static void
append_future_vcomp(struct ndn_charbuf *templ)
{
    unsigned char b[7] = {NDN_MARKER_VERSION + 1, 0, 0, 0, 0, 0, 0};
    ndn_charbuf_append_tt(templ, NDN_DTAG_Component, NDN_DTAG);
    ndn_charbuf_append_tt(templ, sizeof(b), NDN_BLOB);
    ndn_charbuf_append(templ, b, sizeof(b));
    ndn_charbuf_append_closer(templ);
}

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

variable_types:
b
unsigned char [7]


decompiled_code:
__int64 __fastcall append_filter_all(__int64 a1)
{
ndn_charbuf_append_tt(a1, 13LL, 2LL);
return ndn_charbuf_append_closer(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
ndn_charbuf_append_tt(a1, 13LL, 2LL);
return ndn_charbuf_append_closer(a1);
}

original_code:
static void
append_filter_all(struct ndn_charbuf *c)
{
    ndn_charbuf_append_tt(c, NDN_DTAG_Any, NDN_DTAG);
    ndn_charbuf_append_closer(c);
}


decompiled_code:
__int64 __fastcall answer_highest(__int64 a1)
{
return ndnb_tagged_putf(a1, 85LL, &LC0);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return ndnb_tagged_putf(a1, 85LL, &LC0);
}

original_code:
static void
answer_highest(struct ndn_charbuf *templ)
{
    ndnb_tagged_putf(templ, NDN_DTAG_ChildSelector, "1");
}


decompiled_code:
__int64 __fastcall answer_passive(__int64 a1)
{
ndn_charbuf_append_tt(a1, 47LL, 2LL);
ndn_charbuf_append_tt(a1, 1LL, 6LL);
ndn_charbuf_append(a1, &LC0, 1LL);
return ndn_charbuf_append_closer(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
ndn_charbuf_append_tt(a1, 47LL, 2LL);
ndn_charbuf_append_tt(a1, 1LL, 6LL);
ndn_charbuf_append(a1, &LC0, 1LL);
return ndn_charbuf_append_closer(a1);
}

original_code:
static void
answer_passive(struct ndn_charbuf *templ)
{
    ndn_charbuf_append_tt(templ, NDN_DTAG_AnswerOriginKind, NDN_DTAG);
    ndn_charbuf_append_tt(templ, 1, NDN_UDATA);
    ndn_charbuf_append(templ, "1", 1);
    ndn_charbuf_append_closer(templ);
}


original_code:
static int
set_multicast_socket_options(int socket_r, int socket_w,
                             struct addrinfo *ai,
                             struct addrinfo *localif_for_mcast_addrinfo,
                             int multicastttl,
                             int ifindex,
                             void (*logger)(void *, const char *, ...),
                             void *logdat)
{
    struct addrinfo hints;
    struct ip_mreq mreq;
    struct ipv6_mreq mreq6;
    unsigned char csockopt;
    unsigned int isockopt;
    int res;
    memset((void *)&hints, 0, sizeof(hints));
    memset((void *)&mreq, 0, sizeof(mreq));
    memset((void *)&mreq6, 0, sizeof(mreq6));
    if (ai->ai_family == 2 && ((((in_addr_t)(ntohl(((struct sockaddr_in *)(ai->ai_addr))->sin_addr.s_addr))) & 0xf0000000) == 0xe0000000)) {
        if (logger) (*logger)(logdat, "IPv4 multicast");
        memcpy((void *)&mreq.imr_multiaddr, &((struct sockaddr_in *)ai->ai_addr)->sin_addr, sizeof(mreq.imr_multiaddr));
        if (localif_for_mcast_addrinfo != ((void *)0)) {
            memcpy((void *)&mreq.imr_interface.s_addr, &((struct sockaddr_in *)localif_for_mcast_addrinfo->ai_addr)->sin_addr, sizeof(mreq.imr_interface.s_addr));
        }
        res = setsockopt(socket_r, IPPROTO_IP, 35, &mreq, sizeof(mreq));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IP_ADD_MEMBERSHIP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        csockopt = 0;
        res = setsockopt(socket_w, IPPROTO_IP, 34, &csockopt, sizeof(csockopt));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IP_MULTICAST_LOOP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        if (multicastttl > 0) {
            csockopt = multicastttl;
            res = setsockopt(socket_w, IPPROTO_IP, 33, &csockopt, sizeof(csockopt));
            if (res == -1) {
                if (logger) (*logger)(logdat, "setsockopt(..., IP_MULTICAST_TTL, ...): %s", strerror((*__errno_location ())));
                return(-1);
            }
        }
        if (localif_for_mcast_addrinfo != ((void *)0)) {
            struct in_addr ifaddr = { 0 };
            ifaddr = ((struct sockaddr_in *)localif_for_mcast_addrinfo->ai_addr)->sin_addr;
            res = setsockopt(socket_w, IPPROTO_IP, 32, &ifaddr, sizeof(ifaddr));
            if (res == -1) {
                if (logger) (*logger)(logdat, "setsockopt(..., IP_MULTICAST_IF, ...): %s", strerror((*__errno_location ())));
                return(-1);
            }
        }
    } else if (ai->ai_family == 10 && (((const uint8_t *) ((&((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr)))[0] == 0xff)) {
        if (logger) (*logger)(logdat, "IPv6 multicast");
        memcpy((void *)&mreq6.ipv6mr_multiaddr, &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr, sizeof(mreq6.ipv6mr_multiaddr));
        if (ifindex > 0) {
            mreq6.ipv6mr_interface = ifindex;
        }
        res = setsockopt(socket_r, IPPROTO_IPV6, 20, &mreq6, sizeof(mreq6));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IPV6_JOIN_GROUP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        isockopt = 0;
        res = setsockopt(socket_w, IPPROTO_IPV6, 19, &isockopt, sizeof(isockopt));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IPV6_MULTICAST_LOOP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        if (multicastttl > 0) {
            isockopt = multicastttl;
            res = setsockopt(socket_w, IPPROTO_IPV6, 18, &isockopt, sizeof(isockopt));
            if (res == -1) {
                if (logger) (*logger)(logdat, "setsockopt(..., IPV6_MULTICAST_LOOP, ...): %s", strerror((*__errno_location ())));
                return(-1);
            }
        }
    }
    return(0);
}

canonical_original_code:
static int set_multicast_socket_options(int socket_r, int socket_w, struct addrinfo *ai, struct addrinfo *localif_for_mcast_addrinfo, int multicastttl, int ifindex, void (*logger)(void *, char *, ...), void *logdat)
{
    struct addrinfo hints;
    struct ip_mreq mreq;
    struct ipv6_mreq mreq6;
    unsigned char csockopt;
    unsigned int isockopt;
    int res;
    memset((void *)&hints, 0, sizeof(hints));
    memset((void *)&mreq, 0, sizeof(mreq));
    memset((void *)&mreq6, 0, sizeof(mreq6));
    if (ai->ai_family == 2 && ((((in_addr_t)(ntohl(((struct sockaddr_in *)(ai->ai_addr))->sin_addr.s_addr))) & 0xf0000000) == 0xe0000000)) {
        if (logger) (*logger)(logdat, "IPv4 multicast");
        memcpy((void *)&mreq.imr_multiaddr, &((struct sockaddr_in *)ai->ai_addr)->sin_addr, sizeof(mreq.imr_multiaddr));
        if (localif_for_mcast_addrinfo != ((void *)0)) {
            memcpy((void *)&mreq.imr_interface.s_addr, &((struct sockaddr_in *)localif_for_mcast_addrinfo->ai_addr)->sin_addr, sizeof(mreq.imr_interface.s_addr));
        }
        res = setsockopt(socket_r, IPPROTO_IP, 35, &mreq, sizeof(mreq));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IP_ADD_MEMBERSHIP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        csockopt = 0;
        res = setsockopt(socket_w, IPPROTO_IP, 34, &csockopt, sizeof(csockopt));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IP_MULTICAST_LOOP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        if (multicastttl > 0) {
            csockopt = multicastttl;
            res = setsockopt(socket_w, IPPROTO_IP, 33, &csockopt, sizeof(csockopt));
            if (res == -1) {
                if (logger) (*logger)(logdat, "setsockopt(..., IP_MULTICAST_TTL, ...): %s", strerror((*__errno_location ())));
                return(-1);
            }
        }
        if (localif_for_mcast_addrinfo != ((void *)0)) {
            struct in_addr ifaddr = { 0 };
            ifaddr = ((struct sockaddr_in *)localif_for_mcast_addrinfo->ai_addr)->sin_addr;
            res = setsockopt(socket_w, IPPROTO_IP, 32, &ifaddr, sizeof(ifaddr));
            if (res == -1) {
                if (logger) (*logger)(logdat, "setsockopt(..., IP_MULTICAST_IF, ...): %s", strerror((*__errno_location ())));
                return(-1);
            }
        }
    } else if (ai->ai_family == 10 && (((unsigned char *) ((&((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr)))[0] == 0xff)) {
        if (logger) (*logger)(logdat, "IPv6 multicast");
        memcpy((void *)&mreq6.ipv6mr_multiaddr, &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr, sizeof(mreq6.ipv6mr_multiaddr));
        if (ifindex > 0) {
            mreq6.ipv6mr_interface = ifindex;
        }
        res = setsockopt(socket_r, IPPROTO_IPV6, 20, &mreq6, sizeof(mreq6));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IPV6_JOIN_GROUP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        isockopt = 0;
        res = setsockopt(socket_w, IPPROTO_IPV6, 19, &isockopt, sizeof(isockopt));
        if (res == -1) {
            if (logger) (*logger)(logdat, "setsockopt(..., IPV6_MULTICAST_LOOP, ...): %s", strerror((*__errno_location ())));
            return(-1);
        }
        if (multicastttl > 0) {
            isockopt = multicastttl;
            res = setsockopt(socket_w, IPPROTO_IPV6, 18, &isockopt, sizeof(isockopt));
            if (res == -1) {
                if (logger) (*logger)(logdat, "setsockopt(..., IPV6_MULTICAST_LOOP, ...): %s", strerror((*__errno_location ())));
                return(-1);
            }
        }
    }
    return(0);
}

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

variable_types: multicastttl int

variable_types: ifindex int

variable_types:
logger
void (*)(void *, char *, ...)

variable_types:
logdat
void *

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

variable_types: struct ipv6_mreq { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipv6mr_multiaddr; unsigned int ipv6mr_interface; }

variable_types:
csockopt
unsigned char

variable_types:
isockopt
unsigned int

variable_types: res int

variable_types:
ifaddr
struct in_addr { unsigned int s_addr; }

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

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }

user_defined_types: struct ipv6_mreq { struct in6_addr ipv6mr_multiaddr; unsigned int ipv6mr_interface; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }