layoutInit

decompiled_code:
__int64 layoutInit()
{
int v0; // eax
WINDOW *v1; // rax
chtype v2; // rcx
chtype v3; // rsi
WINDOW *v4; // rax
chtype v5; // r8
chtype v6; // rsi
WINDOW *v7; // rax
chtype v8; // rsi
chtype v9; // r8
__int64 result; // rax

setlocale(6, &locale);
initscr();
cbreak();
keypad(stdscr, 1);
if ( stdscr )
{
v0 = stdscr->_maxx + 1;
max_row = stdscr->_maxy + 1;
}
else
{
max_row = -1;
v0 = -1;
}
max_col = v0;
noecho();
start_color();
wrefresh(stdscr);
v1 = newwin(3, max_col, 0, 0);
v2 = HIDWORD(acs_map[56]);
v3 = LODWORD(acs_map[60]);
inputBoxBorder = v1;
wborder(
v1,
v3,
(unsigned int)v3,
v2,
(unsigned int)v2,
LODWORD(acs_map[54]),
HIDWORD(acs_map[53]),
LODWORD(acs_map[58]),
HIDWORD(acs_map[58]));
wrefresh(inputBoxBorder);
inputBox = newwin(1, max_col - 2, 1, 1);
wrefresh(inputBox);
v4 = newwin(max_row - 3, 20, 3, 0);
v5 = HIDWORD(acs_map[56]);
v6 = LODWORD(acs_map[60]);
wordsListBorder = v4;
wborder(v4, v6, 0x20uLL, 0x20uLL, v5, (unsigned int)v6, 0x20uLL, HIDWORD(acs_map[54]), v5);
wrefresh(wordsListBorder);
wordsList = newwin(max_row - 4, 18, 3, 1);
wrefresh(wordsList);
v7 = newwin(max_row - 3, max_col - 20, 3, 20);
v8 = LODWORD(acs_map[60]);
v9 = HIDWORD(acs_map[56]);
wordDetailBorder = v7;
wborder(v7, v8, (unsigned int)v8, 0x20uLL, v9, (unsigned int)v8, v8, LODWORD(acs_map[59]), LODWORD(acs_map[53]));
wrefresh(wordDetailBorder);
wordDetail = newpad(2000, max_col - 22);
wrefresh(stdscr);
wmove(inputBox, 0, 0);
wrefresh(inputBox);
init_pair(1, 0, 7);
init_pair(2, 7, 0);
wattr_on(wordsList, 0x200uLL, 0LL);
wattr_on(inputBox, 0x200uLL, 0LL);
wattr_on(wordDetail, 0x200uLL, 0LL);
result = (unsigned int)(max_row - 4);
wordsNum = max_row - 4;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
WINDOW *v1; // rax
chtype v2; // rcx
chtype v3; // rsi
WINDOW *v4; // rax
chtype v5; // r8
chtype v6; // rsi
WINDOW *v7; // rax
chtype v8; // rsi
chtype v9; // r8
__int64 result; // rax

setlocale(6, &locale);
initscr();
cbreak();
keypad(stdscr, 1);
if ( stdscr )
{
v0 = stdscr->_maxx + 1;
max_row = stdscr->_maxy + 1;
}
else
{
max_row = -1;
v0 = -1;
}
max_col = v0;
noecho();
start_color();
wrefresh(stdscr);
v1 = newwin(3, max_col, 0, 0);
v2 = HIDWORD(acs_map[56]);
v3 = LODWORD(acs_map[60]);
inputBoxBorder = v1;
wborder(
v1,
v3,
(unsigned int)v3,
v2,
(unsigned int)v2,
LODWORD(acs_map[54]),
HIDWORD(acs_map[53]),
LODWORD(acs_map[58]),
HIDWORD(acs_map[58]));
wrefresh(inputBoxBorder);
inputBox = newwin(1, max_col - 2, 1, 1);
wrefresh(inputBox);
v4 = newwin(max_row - 3, 20, 3, 0);
v5 = HIDWORD(acs_map[56]);
v6 = LODWORD(acs_map[60]);
wordsListBorder = v4;
wborder(v4, v6, 0x20uLL, 0x20uLL, v5, (unsigned int)v6, 0x20uLL, HIDWORD(acs_map[54]), v5);
wrefresh(wordsListBorder);
wordsList = newwin(max_row - 4, 18, 3, 1);
wrefresh(wordsList);
v7 = newwin(max_row - 3, max_col - 20, 3, 20);
v8 = LODWORD(acs_map[60]);
v9 = HIDWORD(acs_map[56]);
wordDetailBorder = v7;
wborder(v7, v8, (unsigned int)v8, 0x20uLL, v9, (unsigned int)v8, v8, LODWORD(acs_map[59]), LODWORD(acs_map[53]));
wrefresh(wordDetailBorder);
wordDetail = newpad(2000, max_col - 22);
wrefresh(stdscr);
wmove(inputBox, 0, 0);
wrefresh(inputBox);
init_pair(1, 0, 7);
init_pair(2, 7, 0);
wattr_on(wordsList, 0x200uLL, 0LL);
wattr_on(inputBox, 0x200uLL, 0LL);
wattr_on(wordDetail, 0x200uLL, 0LL);
result = (unsigned int)(max_row - 4);
wordsNum = max_row - 4;
return result;
}

original_code:
void layoutInit() {
    setlocale(6,"");
    initscr();
    cbreak();
    keypad(stdscr, 1);
    (max_row = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), max_col = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    noecho();
    start_color();
    wrefresh(stdscr);
    inputBoxBorder = newwin(3,max_col,0,0);
    wborder(inputBoxBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('l'))]),(acs_map[(unsigned char)(('k'))]),(acs_map[(unsigned char)(('t'))]),(acs_map[(unsigned char)(('u'))]));
    wrefresh(inputBoxBorder);
    inputBox = newwin(1,max_col-2,1,1);
    wrefresh(inputBox);
    wordsListBorder = newwin(max_row-3,20,3,0);
    wborder(wordsListBorder,(acs_map[(unsigned char)(('x'))]),' ',' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('m'))]),(acs_map[(unsigned char)(('q'))]));
    wrefresh(wordsListBorder);
    wordsList = newwin(max_row-4,18,3,1);
    wrefresh(wordsList);
    wordDetailBorder = newwin(max_row-3,max_col-20,3,20);
    wborder(wordDetailBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('v'))]),(acs_map[(unsigned char)(('j'))]));
    wrefresh(wordDetailBorder);
    wordDetail = newpad(2000,max_col-22);
    wrefresh(stdscr);
    wmove(inputBox,0,0);
    wrefresh(inputBox);
    init_pair(1,0,7);
    init_pair(2,7,0);
    wattr_on(wordsList, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(inputBox, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(wordDetail, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wordsNum = max_row-4;
}

canonical_original_code:
void layoutInit() {
    setlocale(6,"");
    initscr();
    cbreak();
    keypad(stdscr, 1);
    (max_row = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), max_col = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    noecho();
    start_color();
    wrefresh(stdscr);
    inputBoxBorder = newwin(3,max_col,0,0);
    wborder(inputBoxBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('l'))]),(acs_map[(unsigned char)(('k'))]),(acs_map[(unsigned char)(('t'))]),(acs_map[(unsigned char)(('u'))]));
    wrefresh(inputBoxBorder);
    inputBox = newwin(1,max_col-2,1,1);
    wrefresh(inputBox);
    wordsListBorder = newwin(max_row-3,20,3,0);
    wborder(wordsListBorder,(acs_map[(unsigned char)(('x'))]),' ',' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('m'))]),(acs_map[(unsigned char)(('q'))]));
    wrefresh(wordsListBorder);
    wordsList = newwin(max_row-4,18,3,1);
    wrefresh(wordsList);
    wordDetailBorder = newwin(max_row-3,max_col-20,3,20);
    wborder(wordDetailBorder,(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),' ',(acs_map[(unsigned char)(('q'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('x'))]),(acs_map[(unsigned char)(('v'))]),(acs_map[(unsigned char)(('j'))]));
    wrefresh(wordDetailBorder);
    wordDetail = newpad(2000,max_col-22);
    wrefresh(stdscr);
    wmove(inputBox,0,0);
    wrefresh(inputBox);
    init_pair(1,0,7);
    init_pair(2,7,0);
    wattr_on(wordsList, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(inputBox, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wattr_on(wordDetail, (attr_t)((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    wordsNum = max_row-4;
}


printDetail

repo: pollow/Dict

decompiled_code:
int printDetail()
{
__int64 i; // rbx
unsigned __int8 *v1; // rax
int v2; // edx
__int64 v3; // rax

if ( expNodetop > 0 )
{
for ( i = 0LL; expNodetop > (int)i; ++i )
{
while ( 1 )
{
v1 = (unsigned __int8 *)*((_QWORD *)&expNodeList + i);
v2 = *v1;
if ( v2 == 68 && v1[1] == 67 && !v1[2] )
goto LABEL_5;
if ( v2 != 89 || v1[1] != 88 || v1[2] )
break;
wattrset(wordDetail, 0x10000);
v3 = *((_QWORD *)&expNodeList + i++);
wprintw(wordDetail, "\n%s\n\n", *(const char **)(v3 + 8));
wattrset(wordDetail, 0);
if ( expNodetop <= (int)i )
return wrefresh(wordDetail);
}
if ( v2 == 68 && v1[1] == 88 && !v1[2] )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_DBB);
}
else
{
if ( v2 == 74 && v1[1] == 88 && !v1[2] )
continue;
if ( v2 == 71 && v1[1] == 90 && !v1[2] )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, byte_DC8);
}
else
{
if ( v2 != 76 )
continue;
if ( v1[1] != 89 || v1[2] )
{
if ( v1[1] != 83 || v1[2] )
continue;
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, byte_DDA);
}
else
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, byte_DD1);
}
}
}
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + i) + 8LL));
LABEL_5:
;
}
}
return wrefresh(wordDetail);
}

canonical_decompiled_code:
int func1()
{
__int64 i; // rbx
unsigned __int8 *v1; // rax
int v2; // edx
__int64 v3; // rax

if ( expNodetop > 0 )
{
for ( i = 0LL; expNodetop > (int)i; ++i )
{
while ( 1 )
{
v1 = (unsigned __int8 *)*((_QWORD *)&expNodeList + i);
v2 = *v1;
if ( v2 == 68 && v1[1] == 67 && !v1[2] )
goto LABEL_5;
if ( v2 != 89 || v1[1] != 88 || v1[2] )
break;
wattrset(wordDetail, 0x10000);
v3 = *((_QWORD *)&expNodeList + i++);
wprintw(wordDetail, "\n%s\n\n", *(const char **)(v3 + 8));
wattrset(wordDetail, 0);
if ( expNodetop <= (int)i )
return wrefresh(wordDetail);
}
if ( v2 == 68 && v1[1] == 88 && !v1[2] )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, &byte_DBB);
}
else
{
if ( v2 == 74 && v1[1] == 88 && !v1[2] )
continue;
if ( v2 == 71 && v1[1] == 90 && !v1[2] )
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, byte_DC8);
}
else
{
if ( v2 != 76 )
continue;
if ( v1[1] != 89 || v1[2] )
{
if ( v1[1] != 83 || v1[2] )
continue;
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, byte_DDA);
}
else
{
wattrset(wordDetail, 0x200000);
wprintw(wordDetail, byte_DD1);
}
}
}
wattrset(wordDetail, 0);
wprintw(wordDetail, "%s\n", *(const char **)(*((_QWORD *)&expNodeList + i) + 8LL));
LABEL_5:
;
}
}
return wrefresh(wordDetail);
}

original_code:
void printDetail() {
    for(int i=0; i<expNodetop; i++) {
        if (strcmp(expNodeList[i]->name, "DC") == 0) {
        } else if (strcmp(expNodeList[i]->name, "YX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((8) + 8)));
            wprintw(wordDetail, "\n%s\n\n", expNodeList[i]->data);
            wattrset(wordDetail, (1U - 1U));
        } else if (strcmp(expNodeList[i]->name, "DX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "词性: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "JX") == 0) {
        } else if (strcmp(expNodeList[i]->name, "GZ") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "释义: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LY") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "例句: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LS") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "翻译: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        }
    }
    wrefresh(wordDetail);
}

canonical_original_code:
void printDetail() {
    for(int i = 0; i<expNodetop; i++) {
        if (strcmp(expNodeList[i]->name, "DC") == 0) {
        } else if (strcmp(expNodeList[i]->name, "YX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((8) + 8)));
            wprintw(wordDetail, "\n%s\n\n", expNodeList[i]->data);
            wattrset(wordDetail, (1U - 1U));
        } else if (strcmp(expNodeList[i]->name, "DX") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "词性: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "JX") == 0) {
        } else if (strcmp(expNodeList[i]->name, "GZ") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "释义: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LY") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "例句: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        } else if (strcmp(expNodeList[i]->name, "LS") == 0) {
            wattrset(wordDetail, ((chtype)((1U)) << ((13) + 8)));
            wprintw(wordDetail, "翻译: ");
            wattrset(wordDetail, (1U - 1U));
            wprintw(wordDetail, "%s\n", expNodeList[i]->data);
        }
    }
    wrefresh(wordDetail);
}

variable_types: i int

return_type: void


wordSelect

decompiled_code:
int wordSelect()
{
int **v0; // rax
__int64 v1; // rdx
int *v2; // rcx
int v3; // ebx
int v4; // ecx
int *v5; // rdx
__int64 v6; // rax
int v7; // edi
unsigned int v8; // ebp
__int64 v9; // rdi
int v10; // er12
int v11; // ebp
int v13[206]; // [rsp+0h] [rbp-338h] BYREF

memset(v13, 0, 0x320uLL);
v0 = (int **)trielist;
if ( trielist )
{
v1 = 0LL;
do
{
v2 = *v0;
v0 = (int **)v0[1];
v3 = v1;
v4 = *v2;
v13[v1++] = v4;
}
while ( v0 );
if ( v3 > 1 )
{
v5 = &v13[v3];
v6 = 0LL;
while ( 1 )
{
v7 = v13[v6];
v13[v6++] = v4;
--v5;
v5[1] = v7;
if ( v3 >> 1 <= (int)v6 )
break;
v4 = *v5;
}
}
v8 = v13[0];
}
else
{
v8 = 0;
v3 = -1;
}
curs_set(0);
if ( wmove(wordsList, 0, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
v9 = v8;
v10 = 0;
v11 = 0;
parserProcess(v9);
werase(wordDetail);
printDetail();
prefresh(wordDetail, 0, 0, 3, 21, max_row - 2, max_col - 1);
wrefresh(wordsList);
while ( 2 )
{
switch ( wgetch(stdscr) )
{
case 258:
if ( wmove(wordsList, v11, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v11 >= v3 )
return curs_set(1);
++v11;
v10 = 0;
goto LABEL_17;
case 259:
if ( wmove(wordsList, v11, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v11 )
{
--v11;
v10 = 0;
LABEL_17:
if ( wmove(wordsList, v11, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
wrefresh(wordsList);
parserProcess((unsigned int)v13[v11]);
werase(wordDetail);
printDetail();
LABEL_20:
prefresh(wordDetail, v10, 0, 3, 21, max_row - 2, max_col - 1);
continue;
}
return curs_set(1);
case 260:
--v10;
goto LABEL_20;
case 261:
++v10;
goto LABEL_20;
case 265:
endwin();
exit(0);
default:
goto LABEL_17;
}
}
}

canonical_decompiled_code:
int func2()
{
int **v0; // rax
__int64 v1; // rdx
int *v2; // rcx
int v3; // ebx
int v4; // ecx
int *v5; // rdx
__int64 v6; // rax
int v7; // edi
unsigned int v8; // ebp
__int64 v9; // rdi
int v10; // er12
int v11; // ebp
int v13[206]; // [rsp+0h] [rbp-338h] BYREF

memset(v13, 0, 0x320uLL);
v0 = (int **)trielist;
if ( trielist )
{
v1 = 0LL;
do
{
v2 = *v0;
v0 = (int **)v0[1];
v3 = v1;
v4 = *v2;
v13[v1++] = v4;
}
while ( v0 );
if ( v3 > 1 )
{
v5 = &v13[v3];
v6 = 0LL;
while ( 1 )
{
v7 = v13[v6];
v13[v6++] = v4;
--v5;
v5[1] = v7;
if ( v3 >> 1 <= (int)v6 )
break;
v4 = *v5;
}
}
v8 = v13[0];
}
else
{
v8 = 0;
v3 = -1;
}
curs_set(0);
if ( wmove(wordsList, 0, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
v9 = v8;
v10 = 0;
v11 = 0;
parserProcess(v9);
werase(wordDetail);
func1();
prefresh(wordDetail, 0, 0, 3, 21, max_row - 2, max_col - 1);
wrefresh(wordsList);
while ( 2 )
{
switch ( wgetch(stdscr) )
{
case 258:
if ( wmove(wordsList, v11, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v11 >= v3 )
return curs_set(1);
++v11;
v10 = 0;
goto LABEL_17;
case 259:
if ( wmove(wordsList, v11, 0) != -1 )
wchgat(wordsList, -1, 0LL, 2, 0LL);
if ( v11 )
{
--v11;
v10 = 0;
LABEL_17:
if ( wmove(wordsList, v11, 0) != -1 )
wchgat(wordsList, -1, 0LL, 1, 0LL);
wrefresh(wordsList);
parserProcess((unsigned int)v13[v11]);
werase(wordDetail);
func1();
LABEL_20:
prefresh(wordDetail, v10, 0, 3, 21, max_row - 2, max_col - 1);
continue;
}
return curs_set(1);
case 260:
--v10;
goto LABEL_20;
case 261:
++v10;
goto LABEL_20;
case 265:
endwin();
exit(0);
default:
goto LABEL_17;
}
}
}

original_code:
void wordSelect() {
    int item = 0,i = 0, listlen, py = 0;
    int indexs[200];
    memset(indexs,0,sizeof(indexs));
    struct trieList *p = trielist;
    while(p) {
        indexs[i] = (p->key)->index;
        p = p->next;
        i++;
    }
    listlen = --i;
    for(int j = 0; j < i/2 ; j++) {
        int tmp = indexs[j];
        indexs[j] = indexs[i-j];
        indexs[i-j] = tmp;
    }
    curs_set(0);
    (wmove((wordsList),(0),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
    parserProcess(indexs[item]);
    werase(wordDetail);
    printDetail();
    prefresh(wordDetail,0,0,3,21,max_row-2,max_col-1);
    wrefresh(wordsList);
    while(1) {
        int ch = wgetch(stdscr);
        _Bool flag = 0;
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                exit(0);
            case 0403 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item>0) item--;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0402 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item < listlen) item++;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0404 :
                py--;
                flag = 1;
                break;
            case 0405 :
                py++;
                flag = 1;
                break;
        }
        if(flag) {
            prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
            continue;
        }
        (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
        wrefresh(wordsList);
        parserProcess(indexs[item]);
        werase(wordDetail);
        printDetail();
        prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
    }
    curs_set(1);
}

canonical_original_code:
void wordSelect() {
    int item = 0; int i = 0; int listlen; int py = 0;
    int indexs[200];
    memset(indexs,0,sizeof(indexs));
    struct trieList *p = trielist;
    while(p) {
        indexs[i] = (p->key)->index;
        p = p->next;
        i++;
    }
    listlen = --i;
    for(int j = 0; j < i/2 ; j++) {
        int tmp = indexs[j];
        indexs[j] = indexs[i-j];
        indexs[i-j] = tmp;
    }
    curs_set(0);
    (wmove((wordsList),(0),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
    parserProcess(indexs[item]);
    werase(wordDetail);
    printDetail();
    prefresh(wordDetail,0,0,3,21,max_row-2,max_col-1);
    wrefresh(wordsList);
    while(1) {
        int ch = wgetch(stdscr);
        _Bool flag = 0;
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                exit(0);
            case 0403 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item>0) item--;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0402 :
                (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(2),(((void *)0))));
                if(item < listlen) item++;
                else {
                    curs_set(1);
                    return;
                }
                py = 0;
                break;
            case 0404 :
                py--;
                flag = 1;
                break;
            case 0405 :
                py++;
                flag = 1;
                break;
        }
        if(flag) {
            prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
            continue;
        }
        (wmove((wordsList),(item),(0)) == (-1) ? (-1) : wchgat((wordsList),(-1),((1U - 1U)),(1),(((void *)0))));
        wrefresh(wordsList);
        parserProcess(indexs[item]);
        werase(wordDetail);
        printDetail();
        prefresh(wordDetail,py,0,3,21,max_row-2,max_col-1);
    }
    curs_set(1);
}

variable_types: item int

variable_types: listlen int

variable_types: py int

variable_types:
indexs
int [200]

variable_types: struct trieList { struct trieNode { int index; char *word; struct trieNode *son[16]; } *key; struct trieList *next; } *

variable_types: j int

variable_types: tmp int

variable_types: ch int

user_defined_types: struct trieList { struct trieNode *key; struct trieList *next; }


printWords

decompiled_code:
int __fastcall printWords(_QWORD *a1)
{
int result; // eax

if ( a1 )
{
printWords(a1[1]);
result = mvwprintw(wordsList, printPos, 0, "%d %s", (unsigned int)printPos, *(const char **)(*a1 + 8LL));
++printPos;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1)
{
int result; // eax

if ( a1 )
{
func3(a1[1]);
result = mvwprintw(wordsList, printPos, 0, "%d %s", (unsigned int)printPos, *(const char **)(*a1 + 8LL));
++printPos;
}
return result;
}

original_code:
void printWords(struct trieList *tl) {
    if(tl==((void *)0)) {
        return;
    } else {
        printWords(tl->next);
        mvwprintw(wordsList,printPos,0,"%d %s",printPos,(tl->key)->word);
        printPos++;
    }
}

user_defined_types: struct trieNode { int index; char *word; struct trieNode *son[16]; }


layoutProcess

decompiled_code:
__int64 layoutProcess()
{
int v0; // er12
int v1; // ebp
int v2; // eax
char v3; // bl
__int64 v4; // rax
WINDOW *v5; // rdi

v0 = 0;
v1 = 0;
layoutInit();
memset(waitingWord, 0, sizeof(waitingWord));
while ( 1 )
{
v2 = wgetch(stdscr);
v3 = v2;
if ( v2 != 127 )
break;
LABEL_11:
if ( v1 > 0 )
{
if ( v0 > v1 - 1 )
memmove(&waitingWord[v1 - 1], &waitingWord[v1], (unsigned int)(v0 - v1) + 1LL);
v5 = inputBox;
--v0;
--v1;
waitingWord[v0] = 0;
wclear(v5);
wclear(wordsList);
}
LABEL_5:
mvwprintw(inputBox, 0, 0, waitingWord);
lookupProcess(waitingWord);
werase(wordsList);
printPos = 0;
printWords(trielist);
wrefresh(wordsList);
wmove(inputBox, 0, v1);
wrefresh(inputBox);
}
switch ( v2 )
{
case 258:
wordSelect();
goto LABEL_5;
case 259:
goto LABEL_5;
case 260:
v1 -= v1 > 0;
goto LABEL_5;
case 261:
v1 += v1 < v0;
goto LABEL_5;
case 263:
goto LABEL_11;
case 265:
endwin();
return 0LL;
default:
if ( ((*_ctype_b_loc())[v2] & 0x4000) != 0 )
{
if ( v1 < v0 )
memmove(
&waitingWord[v0 - (unsigned __int64)(unsigned int)(v0 - v1 - 1)],
&waitingWord[v0 - (unsigned __int64)(unsigned int)(v0 - v1 - 1) - 1],
(unsigned int)(v0 - v1 - 1) + 1LL);
v4 = v1;
++v0;
++v1;
waitingWord[v4] = v3;
}
goto LABEL_5;
}
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // er12
int v1; // ebp
int v2; // eax
char v3; // bl
__int64 v4; // rax
WINDOW *v5; // rdi

v0 = 0;
v1 = 0;
func0();
memset(waitingWord, 0, sizeof(waitingWord));
while ( 1 )
{
v2 = wgetch(stdscr);
v3 = v2;
if ( v2 != 127 )
break;
LABEL_11:
if ( v1 > 0 )
{
if ( v0 > v1 - 1 )
memmove(&waitingWord[v1 - 1], &waitingWord[v1], (unsigned int)(v0 - v1) + 1LL);
v5 = inputBox;
--v0;
--v1;
waitingWord[v0] = 0;
wclear(v5);
wclear(wordsList);
}
LABEL_5:
mvwprintw(inputBox, 0, 0, waitingWord);
lookupProcess(waitingWord);
werase(wordsList);
printPos = 0;
func3(trielist);
wrefresh(wordsList);
wmove(inputBox, 0, v1);
wrefresh(inputBox);
}
switch ( v2 )
{
case 258:
func2();
goto LABEL_5;
case 259:
goto LABEL_5;
case 260:
v1 -= v1 > 0;
goto LABEL_5;
case 261:
v1 += v1 < v0;
goto LABEL_5;
case 263:
goto LABEL_11;
case 265:
endwin();
return 0LL;
default:
if ( ((*_ctype_b_loc())[v2] & 0x4000) != 0 )
{
if ( v1 < v0 )
memmove(
&waitingWord[v0 - (unsigned __int64)(unsigned int)(v0 - v1 - 1)],
&waitingWord[v0 - (unsigned __int64)(unsigned int)(v0 - v1 - 1) - 1],
(unsigned int)(v0 - v1 - 1) + 1LL);
v4 = v1;
++v0;
++v1;
waitingWord[v4] = v3;
}
goto LABEL_5;
}
}

original_code:
int layoutProcess() {
    layoutInit();
    int ch,p=0,len=0;
    memset(waitingWord,0,sizeof(waitingWord));
    while(1) {
        ch = wgetch(stdscr);
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                return 0;
            case 0407 :
            case 127 :
                if(p>0) {
                    for(int i=p-1;i<len;i++) waitingWord[i]=waitingWord[i+1];
                    waitingWord[--len]='\0';
                    --p;
                    wclear(inputBox);
                    wclear(wordsList);
                }
                break;
            case 0404 :
                if(p>0) --p;
                break;
            case 0405 :
                if(p<len) ++p;
                break;
            case 0402 :
                wordSelect();
                break;
            case 0403 :
                break;
            default :
                if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISprint)) {
                    for(int i=len;i>p;i--) waitingWord[i]=waitingWord[i-1];
                    waitingWord[p]=ch;
                    len++;
                    p++;
                }
        }
        mvwprintw(inputBox,0,0,waitingWord);
        lookupProcess(waitingWord);
        werase(wordsList);
        printPos = 0;
        printWords(trielist);
        wrefresh(wordsList);
        wmove(inputBox,0,p);
        wrefresh(inputBox);
    }
    wgetch(stdscr);
    endwin();
    return 0;
}

canonical_original_code:
int layoutProcess() {
    layoutInit();
    int ch; int p = 0; int len = 0;
    memset(waitingWord,0,sizeof(waitingWord));
    while(1) {
        ch = wgetch(stdscr);
        switch(ch) {
            case (0410 +(1)) :
                endwin();
                return 0;
            case 0407 :
            case 127 :
                if(p>0) {
                    for(int i = p-1;i<len;i++) waitingWord[i]=waitingWord[i+1];
                    waitingWord[--len]='\0';
                    --p;
                    wclear(inputBox);
                    wclear(wordsList);
                }
                break;
            case 0404 :
                if(p>0) --p;
                break;
            case 0405 :
                if(p<len) ++p;
                break;
            case 0402 :
                wordSelect();
                break;
            case 0403 :
                break;
            default :
                if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISprint)) {
                    for(int i = len;i>p;i--) waitingWord[i]=waitingWord[i-1];
                    waitingWord[p]=ch;
                    len++;
                    p++;
                }
        }
        mvwprintw(inputBox,0,0,waitingWord);
        lookupProcess(waitingWord);
        werase(wordsList);
        printPos = 0;
        printWords(trielist);
        wrefresh(wordsList);
        wmove(inputBox,0,p);
        wrefresh(inputBox);
    }
    wgetch(stdscr);
    endwin();
    return 0;
}

variable_types: p int

variable_types: len int

return_type: int


parser

original_code:
int parser(char *str, int i) {
    while (i < (int) strlen(str)) {
        if(str[i]=='\\') i+=2;
        else if(str[i]=='<') {
            i++;
            if(str[i]=='/') {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->data = ((void *)0);
                node->name[0] = '/';node->name[1] = str[i+1];node->name[2] = str[i+2];node->name[3] = '\0';
                expNodeList[expNodetop++] = node;
                return i+3;
            } else {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->name[0] = str[i];node->name[1] = str[i+1];node->name[2] = '\0';
                node->data = ((void *)0);
                expNodeList[expNodetop++] = node;
                i+=3;
                if(str[i]=='<' && str[i+1]=='!') {
                    i++;
                    i+=8;
                    char *tmpHead = str+i,*tmpTail = str+i;
                    while(*tmpTail != '>') tmpTail++;
                    int len = tmpTail - tmpHead - 2;
                    node->data = (char *) malloc(sizeof(char)*len);
                    strncpy(node->data,tmpHead,len);
                    i+=len+7;
                } else {
                    i = parser(str,i);
                }
            }
        }
        i++;
    }
    return i;
}

canonical_original_code:
int parser(char *str, int i) {
    while (i < (int) strlen(str)) {
        if(str[i]=='\\') i+=2;
        else if(str[i]=='<') {
            i++;
            if(str[i]=='/') {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->data = ((void *)0);
                node->name[0] = '/';node->name[1] = str[i+1];node->name[2] = str[i+2];node->name[3] = '\0';
                expNodeList[expNodetop++] = node;
                return i+3;
            } else {
                struct expTreeNode *node = (struct expTreeNode *) malloc(sizeof(struct expTreeNode));
                node->name[0] = str[i];node->name[1] = str[i+1];node->name[2] = '\0';
                node->data = ((void *)0);
                expNodeList[expNodetop++] = node;
                i+=3;
                if(str[i]=='<' && str[i+1]=='!') {
                    i++;
                    i+=8;
                    char *tmpHead = str+i; char *tmpTail = str+i;
                    while(*tmpTail != '>') tmpTail++;
                    int len = tmpTail - tmpHead - 2;
                    node->data = (char *) malloc(sizeof(char)*len);
                    strncpy(node->data,tmpHead,len);
                    i+=len+7;
                } else {
                    i = parser(str,i);
                }
            }
        }
        i++;
    }
    return i;
}

variable_types:
str
char *

variable_types: struct expTreeNode { char name[4]; char *data; } *

variable_types:
tmpHead
char *

variable_types:
tmpTail
char *


repo: poltak/Coursework

decompiled_code:
char *__fastcall get_filename(char *s, _DWORD *a2)
{
char *v2; // r12
char *v3; // rbx
__int64 v4; // rdx
char *v5; // rbx
char *result; // rax

v2 = (char *)malloc(0x100uLL);
*(_WORD *)stpcpy(v2, s) = 45;
v3 = &v2[strlen(s) + 1];
v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
sprintf(v3, "%04u", v4);
v5 = &v3[strlen(v3)];
result = v2;
strcpy(v5, ".ppm");
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *s, _DWORD *a2)
{
char *v2; // r12
char *v3; // rbx
__int64 v4; // rdx
char *v5; // rbx
char *result; // rax

v2 = (char *)malloc(0x100uLL);
*(_WORD *)stpcpy(v2, s) = 45;
v3 = &v2[strlen(s) + 1];
v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
sprintf(v3, "%04u", v4);
v5 = &v3[strlen(v3)];
result = v2;
strcpy(v5, ".ppm");
return result;
}

original_code:
static char *get_filename(char *ppm_prefix, unsigned int *ppm_count)
{
 char *filename = (char *) malloc(255 +1);
 strcpy(filename, ppm_prefix);
 strcat(filename, "-");
 char *filename_end = &filename[strlen(ppm_prefix)] +1;
 sprintf(filename_end, "%04u", ++(*ppm_count));
 strcat(filename_end, ".ppm");
    return filename;
}

variable_types:
filename
char *

return_type: char *


decompiled_code:
void __fastcall free_channels(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

v2 = ptr;
if ( a2 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void free_channels(Uint8** channels, unsigned int num_of_channels)
{
 int i;
 for (i = 0; i < num_of_channels; i++)
  free(channels[i]);
 free(channels);
}

canonical_original_code:
void free_channels(unsigned char **channels, unsigned int num_of_channels)
{
 int i;
 for (i = 0; i < num_of_channels; i++)
  free(channels[i]);
 free(channels);
}

variable_types:
channels
unsigned char **


decompiled_code:
void __fastcall print_and_die(const char *a1, int a2)
{
switch ( a2 )
{
case 0:
fprintf(stderr, "Fatal IO error encountered:\n%s\n", a1);
break;
case 1:
fprintf(stderr, "Fatal memory error occurred:\n%s\n", a1);
break;
case 2:
fwrite("usage: dumbrletoppm <dumbrle file> <PPM output prefix>\n", 1uLL, 0x37uLL, stderr);
break;
case 3:
fwrite("usage: firstframeview <dumbrle file> <display time 0-*>\n", 1uLL, 0x38uLL, stderr);
break;
case 4:
fwrite("usage: dumbrleplayer <dumbrle file> <frame delay 0-*>\n", 1uLL, 0x36uLL, stderr);
break;
case 5:
fwrite(
"usage: smartrleplayer <dumbrle file> <frame delay 0-*> <brightness 0-100> <contrast 0-100> <saturation 0-100>\n",
1uLL,
0x6EuLL,
stderr);
break;
case 7:
fwrite("File is not a standard DUMBRLEv1 file.\n", 1uLL, 0x27uLL, stderr);
break;
case 8:
fprintf(stderr, "%s\n", a1);
break;
default:
break;
}
exit(1);
}

canonical_decompiled_code:
void __fastcall func13(const char *a1, int a2)
{
switch ( a2 )
{
case 0:
fprintf(stderr, "Fatal IO error encountered:\n%s\n", a1);
break;
case 1:
fprintf(stderr, "Fatal memory error occurred:\n%s\n", a1);
break;
case 2:
fwrite("usage: dumbrletoppm <dumbrle file> <PPM output prefix>\n", 1uLL, 0x37uLL, stderr);
break;
case 3:
fwrite("usage: firstframeview <dumbrle file> <display time 0-*>\n", 1uLL, 0x38uLL, stderr);
break;
case 4:
fwrite("usage: dumbrleplayer <dumbrle file> <frame delay 0-*>\n", 1uLL, 0x36uLL, stderr);
break;
case 5:
fwrite(
"usage: smartrleplayer <dumbrle file> <frame delay 0-*> <brightness 0-100> <contrast 0-100> <saturation 0-100>\n",
1uLL,
0x6EuLL,
stderr);
break;
case 7:
fwrite("File is not a standard DUMBRLEv1 file.\n", 1uLL, 0x27uLL, stderr);
break;
case 8:
fprintf(stderr, "%s\n", a1);
break;
default:
break;
}
exit(1);
}

original_code:
void print_and_die(char *message, Error_t type)
{
    switch (type)
    {
        case IO:
            fprintf(stderr, "Fatal IO error encountered:\n%s\n", message);
            break;
        case MEM:
            fprintf(stderr, "Fatal memory error occurred:\n%s\n", message);
            break;
        case NOT_DUMBRLE:
            fprintf(stderr, "File is not a standard DUMBRLEv1 file.\n");
            break;
        case USAGE_1:
            fprintf(stderr, "usage: dumbrletoppm <dumbrle file> <PPM output prefix>\n");
            break;
        case USAGE_2:
            fprintf(stderr, "usage: firstframeview <dumbrle file> <display time 0-*>\n");
            break;
        case USAGE_3:
            fprintf(stderr, "usage: dumbrleplayer <dumbrle file> <frame delay 0-*>\n");
            break;
        case USAGE_4:
            fprintf(stderr, "usage: smartrleplayer <dumbrle file> <frame delay 0-*> <brightness 0-100> <contrast 0-100> <saturation 0-100>\n");
            break;
        case BAD_HSV:
            fprintf(stderr, "%s\n", message);
            break;
        default:
            break;
    }
    exit(1);
}

canonical_original_code:
void print_and_die(char *message, enum Error_t type)
{
    switch (type)
    {
        case IO:
            fprintf(stderr, "Fatal IO error encountered:\n%s\n", message);
            break;
        case MEM:
            fprintf(stderr, "Fatal memory error occurred:\n%s\n", message);
            break;
        case NOT_DUMBRLE:
            fprintf(stderr, "File is not a standard DUMBRLEv1 file.\n");
            break;
        case USAGE_1:
            fprintf(stderr, "usage: dumbrletoppm <dumbrle file> <PPM output prefix>\n");
            break;
        case USAGE_2:
            fprintf(stderr, "usage: firstframeview <dumbrle file> <display time 0-*>\n");
            break;
        case USAGE_3:
            fprintf(stderr, "usage: dumbrleplayer <dumbrle file> <frame delay 0-*>\n");
            break;
        case USAGE_4:
            fprintf(stderr, "usage: smartrleplayer <dumbrle file> <frame delay 0-*> <brightness 0-100> <contrast 0-100> <saturation 0-100>\n");
            break;
        case BAD_HSV:
            fprintf(stderr, "%s\n", message);
            break;
        default:
            break;
    }
    exit(1);
}

variable_types:
message
char *

variable_types: enum Error_t { IO=0, MEM=1, USAGE_1=2, USAGE_2=3, USAGE_3=4, USAGE_4=5, USAGE_5=6, NOT_DUMBRLE=7, BAD_HSV=8 }


original_code:
Uint32 hsv_to_rgb(struct hsv pixel, SDL_PixelFormat *format)
{
    double R, G, B;
    if (pixel.s == 0)
        R = G = B = pixel.v;
    else
    {
        unsigned int sector_size = 60;
        unsigned int sector = (pixel.h / sector_size);
        double f = (pixel.h - sector * sector_size)/60;
        double m = (pixel.v * (1 - pixel.s));
        double n = (pixel.v * (1 - (pixel.s * f)));
        double k = (pixel.v * (1 - (pixel.s * (1 - f))));
        switch (sector)
        {
            case 0:
                R = pixel.v;
                G = k;
                B = m;
                break;
            case 1:
                R = n;
                G = pixel.v;
                B = m;
                break;
            case 2:
                R = m;
                G = pixel.v;
                B = k;
                break;
            case 3:
                R = m;
                G = n;
                B = pixel.v;
                break;
            case 4:
                R = k;
                G = m;
                B = pixel.v;
                break;
            case 5:
                R = pixel.v;
                G = m;
                B = n;
                break;
            default:
                print_and_die("Invalid H value passed to hsv_to_rgb", BAD_HSV);
        }
    }
    return SDL_MapRGB(format, (Uint8) (R * 255), (Uint8) (G * 255), (Uint8) (B * 255));
}

canonical_original_code:
unsigned int hsv_to_rgb(struct hsv pixel, struct SDL_PixelFormat *format)
{
    double R; double G; double B;
    if (pixel.s == 0)
        R = G = B = pixel.v;
    else
    {
        unsigned int sector_size = 60;
        unsigned int sector = (pixel.h / sector_size);
        double f = (pixel.h - sector * sector_size)/60;
        double m = (pixel.v * (1 - pixel.s));
        double n = (pixel.v * (1 - (pixel.s * f)));
        double k = (pixel.v * (1 - (pixel.s * (1 - f))));
        switch (sector)
        {
            case 0:
                R = pixel.v;
                G = k;
                B = m;
                break;
            case 1:
                R = n;
                G = pixel.v;
                B = m;
                break;
            case 2:
                R = m;
                G = pixel.v;
                B = k;
                break;
            case 3:
                R = m;
                G = n;
                B = pixel.v;
                break;
            case 4:
                R = k;
                G = m;
                B = pixel.v;
                break;
            case 5:
                R = pixel.v;
                G = m;
                B = n;
                break;
            default:
                print_and_die("Invalid H value passed to hsv_to_rgb", BAD_HSV);
        }
    }
    return SDL_MapRGB(format, (Uint8) (R * 255), (Uint8) (G * 255), (Uint8) (B * 255));
}

variable_types: struct hsv { double h; double s; double v; }

variable_types: struct SDL_PixelFormat { struct SDL_Palette { int ncolors; struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char unused; } *colors; } *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned int colorkey; unsigned char alpha; } *

variable_types: R double

variable_types: G double

variable_types: B double

variable_types:
sector
unsigned int

variable_types: f double

variable_types: m double

variable_types: n double

variable_types: k double

return_type: unsigned int

user_defined_types: struct SDL_PixelFormat { struct SDL_Palette *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned int colorkey; unsigned char alpha; }

user_defined_types: struct SDL_Palette { int ncolors; struct SDL_Color *colors; }


repo: polymorf/ipfw-user

original_code:
static void
altq_fetch(void)
{
 struct pfioc_altq pfioc;
 struct pf_altq *altq;
 int pffd;
 unsigned int mnr;
 static int altq_fetched = 0;
 if (altq_fetched)
  return;
 altq_fetched = 1;
 pffd = open("/dev/pf", 00);
 if (pffd == -1) {
  warn("altq support opening pf(4) control device");
  return;
 }
 bzero(&pfioc, sizeof(pfioc));
 if (ioctl(pffd, (((2U|1U) << (((0 +8)+8)+14)) | ((('D')) << (0 +8)) | (((47)) << 0) | ((((sizeof(struct pfioc_altq)))) << ((0 +8)+8))), &pfioc) != 0) {
  warn("altq support getting queue list");
  close(pffd);
  return;
 }
 mnr = pfioc.nr;
 for (pfioc.nr = 0; pfioc.nr < mnr; pfioc.nr++) {
  if (ioctl(pffd, (((2U|1U) << (((0 +8)+8)+14)) | ((('D')) << (0 +8)) | (((48)) << 0) | ((((sizeof(struct pfioc_altq)))) << ((0 +8)+8))), &pfioc) != 0) {
   if ((*__errno_location ()) == 16)
    break;
   warn("altq support getting queue list");
   close(pffd);
   return;
  }
  if (pfioc.altq.qid == 0)
   continue;
  altq = safe_calloc(1, sizeof(*altq));
  *altq = pfioc.altq;
  do { (altq)->entries.tqe_next = ((void *)0); (altq)->entries.tqe_prev = (&altq_entries)->tqh_last; *(&altq_entries)->tqh_last = (altq); (&altq_entries)->tqh_last = &(altq)->entries.tqe_next; } while ( 0);
 }
 close(pffd);
}

canonical_original_code:
static void altq_fetch()
{
 struct pfioc_altq pfioc;
 struct pf_altq *altq;
 int pffd;
 unsigned int mnr;
 static int altq_fetched = 0;
 if (altq_fetched)
  return;
 altq_fetched = 1;
 pffd = open("/dev/pf", 00);
 if (pffd == -1) {
  warn("altq support opening pf(4) control device");
  return;
 }
 bzero(&pfioc, sizeof(pfioc));
 if (ioctl(pffd, (((2U|1U) << (((0 +8)+8)+14)) | ((('D')) << (0 +8)) | (((47)) << 0) | ((((sizeof(struct pfioc_altq)))) << ((0 +8)+8))), &pfioc) != 0) {
  warn("altq support getting queue list");
  close(pffd);
  return;
 }
 mnr = pfioc.nr;
 for (pfioc.nr = 0; pfioc.nr < mnr; pfioc.nr++) {
  if (ioctl(pffd, (((2U|1U) << (((0 +8)+8)+14)) | ((('D')) << (0 +8)) | (((48)) << 0) | ((((sizeof(struct pfioc_altq)))) << ((0 +8)+8))), &pfioc) != 0) {
   if ((*__errno_location ()) == 16)
    break;
   warn("altq support getting queue list");
   close(pffd);
   return;
  }
  if (pfioc.altq.qid == 0)
   continue;
  altq = safe_calloc(1, sizeof(*altq));
  *altq = pfioc.altq;
  do { (altq)->entries.tqe_next = ((void *)0); (altq)->entries.tqe_prev = (&altq_entries)->tqh_last; *(&altq_entries)->tqh_last = (altq); (&altq_entries)->tqh_last = &(altq)->entries.tqe_next; } while ( 0);
 }
 close(pffd);
}

variable_types: struct pfioc_altq { unsigned int action; unsigned int ticket; unsigned int nr; struct pf_altq { struct { struct pf_altq *tqe_next; struct pf_altq **tqe_prev; } entries; unsigned int qid; char qname[64]; } altq; }

variable_types: struct pf_altq { struct { struct pf_altq *tqe_next; struct pf_altq **tqe_prev; } entries; unsigned int qid; char qname[64]; } *

variable_types: pffd int

variable_types:
mnr
unsigned int

user_defined_types: struct pfioc_altq { unsigned int action; unsigned int ticket; unsigned int nr; struct pf_altq altq; }


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

altq_fetch();
result = altq_entries;
if ( altq_entries )
{
while ( *(_DWORD *)(result + 16) != a1 )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
result += 20LL;
}
return result;
}

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

func0();
result = altq_entries;
if ( altq_entries )
{
while ( *(_DWORD *)(result + 16) != a1 )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
result += 20LL;
}
return result;
}

original_code:
static const char *
altq_qid_to_name(u_int32_t qid)
{
 struct pf_altq *altq;
 altq_fetch();
 for ((altq) = ((&altq_entries)->tqh_first); (altq); (altq) = ((altq)->entries.tqe_next))
  if (qid == altq->qid)
   break;
 if (altq == ((void *)0))
  return ((void *)0);
 return altq->qname;
}

canonical_original_code:
static char *altq_qid_to_name(unsigned int qid)
{
 struct pf_altq *altq;
 altq_fetch();
 for ((altq) = ((&altq_entries)->tqh_first); (altq); (altq) = ((altq)->entries.tqe_next))
  if (qid == altq->qid)
   break;
 if (altq == ((void *)0))
  return ((void *)0);
 return altq->qname;
}

variable_types:
qid
unsigned int

user_defined_types: struct pf_altq { struct { struct pf_altq *tqe_next; struct pf_altq **tqe_prev; } entries; unsigned int qid; char qname[64]; }


decompiled_code:
int __fastcall altq_set_enabled(int a1)
{
int v1; // eax
int v2; // ebp

v1 = open("/dev/pf", 2);
if ( v1 == -1 )
err(69, "altq support opening pf(4) control device");
v2 = v1;
if ( a1 )
{
if ( ioctl(v1, 0x442AuLL) && *_errno_location() != 17 )
err(69, "enabling altq");
}
else if ( ioctl(v1, 0x442BuLL) && *_errno_location() != 2 )
{
err(69, "disabling altq");
}
return close(v2);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int v1; // eax
int v2; // ebp

v1 = open("/dev/pf", 2);
if ( v1 == -1 )
err(69, "altq support opening pf(4) control device");
v2 = v1;
if ( a1 )
{
if ( ioctl(v1, 0x442AuLL) && *_errno_location() != 17 )
err(69, "enabling altq");
}
else if ( ioctl(v1, 0x442BuLL) && *_errno_location() != 2 )
{
err(69, "disabling altq");
}
return close(v2);
}

variable_types: enabled int


decompiled_code:
__int64 __fastcall altq_name_to_qid(char *s1)
{
__int64 v1; // rbx

altq_fetch();
v1 = altq_entries;
if ( !altq_entries )
LABEL_6:
errx(65, "altq has no queue named `%s'", s1);
while ( strcmp(s1, (const char *)(v1 + 20)) )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
goto LABEL_6;
}
return *(unsigned int *)(v1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
__int64 v1; // rbx

func0();
v1 = altq_entries;
if ( !altq_entries )
LABEL_6:
errx(65, "altq has no queue named `%s'", s1);
while ( strcmp(s1, (const char *)(v1 + 20)) )
{
v1 = *(_QWORD *)v1;
if ( !v1 )
goto LABEL_6;
}
return *(unsigned int *)(v1 + 16);
}

original_code:
u_int32_t
altq_name_to_qid(const char *name)
{
 struct pf_altq *altq;
 altq_fetch();
 for ((altq) = ((&altq_entries)->tqh_first); (altq); (altq) = ((altq)->entries.tqe_next))
  if (strcmp(name, altq->qname) == 0)
   break;
 if (altq == ((void *)0))
  errx(65, "altq has no queue named `%s'", name);
 return altq->qid;
}

canonical_original_code:
unsigned int altq_name_to_qid(char *name)
{
 struct pf_altq *altq;
 altq_fetch();
 for ((altq) = ((&altq_entries)->tqh_first); (altq); (altq) = ((altq)->entries.tqe_next))
  if (strcmp(name, altq->qname) == 0)
   break;
 if (altq == ((void *)0))
  errx(65, "altq has no queue named `%s'", name);
 return altq->qid;
}

variable_types:
name
char *


decompiled_code:
void __fastcall print_altq_cmd(__int64 a1)
{
const char *v1; // rsi

if ( a1 )
{
v1 = (const char *)altq_qid_to_name(*(_DWORD *)(a1 + 4));
if ( v1 )
printf(" altq %s", v1);
else
printf(" altq ?<%u>", *(unsigned int *)(a1 + 4));
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
const char *v1; // rsi

if ( a1 )
{
v1 = (const char *)func1(*(_DWORD *)(a1 + 4));
if ( v1 )
printf(" altq %s", v1);
else
printf(" altq ?<%u>", *(unsigned int *)(a1 + 4));
}
}

original_code:
void
print_altq_cmd(ipfw_insn_altq *altqptr)
{
 if (altqptr) {
  const char *qname;
  qname = altq_qid_to_name(altqptr->qid);
  if (qname == ((void *)0))
   printf(" altq ?<%u>", altqptr->qid);
  else
   printf(" altq %s", qname);
 }
}

canonical_original_code:
void print_altq_cmd(struct _ipfw_insn_altq *altqptr)
{
 if (altqptr) {
  char *qname;
  qname = altq_qid_to_name(altqptr->qid);
  if (qname == ((void *)0))
   printf(" altq ?<%u>", altqptr->qid);
  else
   printf(" altq %s", qname);
 }
}

variable_types: struct _ipfw_insn_altq { struct _ipfw_insn { unsigned int opcode; unsigned int len; unsigned int arg1; } o; unsigned int qid; } *

variable_types:
qname
char *

user_defined_types: struct _ipfw_insn_altq { struct _ipfw_insn o; unsigned int qid; }


decompiled_code:
__int64 __fastcall lookup_host6(char *name, void *buf)
{
unsigned int v2; // er12
__int64 result; // rax
struct hostent *v4; // rax
__m128i v5; // xmm0

v2 = 0;
if ( inet_pton(10, name, buf) )
return v2;
v4 = gethostbyname2(name, 10);
if ( !v4 )
return (unsigned int)-1;
v5 = _mm_loadu_si128((const __m128i *)*v4->h_addr_list);
result = 0LL;
*(__m128i *)buf = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name, void *buf)
{
unsigned int v2; // er12
__int64 result; // rax
struct hostent *v4; // rax
__m128i v5; // xmm0

v2 = 0;
if ( inet_pton(10, name, buf) )
return v2;
v4 = gethostbyname2(name, 10);
if ( !v4 )
return (unsigned int)-1;
v5 = _mm_loadu_si128((const __m128i *)*v4->h_addr_list);
result = 0LL;
*(__m128i *)buf = v5;
return result;
}

original_code:
static int
lookup_host6 (char *host, struct in6_addr *ip6addr)
{
 struct hostent *he;
 if (!inet_pton(10, host, ip6addr)) {
  if ((he = gethostbyname2(host, 10)) == ((void *)0))
   return(-1);
  memcpy(ip6addr, he->h_addr_list[0], sizeof( struct in6_addr));
 }
 return(0);
}

canonical_original_code:
static int lookup_host6(char *host, struct in6_addr *ip6addr)
{
 struct hostent *he;
 if (!inet_pton(10, host, ip6addr)) {
  if ((he = gethostbyname2(host, 10)) == ((void *)0))
   return(-1);
  memcpy(ip6addr, he->h_addr_list[0], sizeof( struct in6_addr));
 }
 return(0);
}

variable_types:
host
char *

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int u6_addr32[4]; } __in6_u; } *

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


decompiled_code:
int __fastcall print_unreach6_code(unsigned __int16 a1)
{
const char *v1; // rax
int result; // eax

v1 = (const char *)match_value(&icmp6codes, a1);
if ( v1 )
result = printf("unreach6 %s", v1);
else
result = printf("unreach6 %u", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int16 a1)
{
const char *v1; // rax
int result; // eax

v1 = (const char *)match_value(&icmp6codes, a1);
if ( v1 )
result = printf("unreach6 %s", v1);
else
result = printf("unreach6 %u", a1);
return result;
}

original_code:
void
print_unreach6_code(uint16_t code)
{
 char const *s = match_value(icmp6codes, code);
 if (s != ((void *)0))
  printf("unreach6 %s", s);
 else
  printf("unreach6 %u", code);
}

canonical_original_code:
void print_unreach6_code(unsigned short code)
{
 char *s = match_value(icmp6codes, code);
 if (s != ((void *)0))
  printf("unreach6 %s", s);
 else
  printf("unreach6 %u", code);
}

variable_types:
code
unsigned short

variable_types:
s
char *


decompiled_code:
int __fastcall print_ip6(unsigned __int8 *a1, __int64 a2)
{
const char *v3; // rsi
char v4; // bl
int result; // eax
char v6; // cl
int v7; // ebx
int v8; // edx
unsigned __int8 v9; // cl
int v10; // ebx
int v11; // ebx
char *v12; // rbp
struct hostent *v13; // r13
int v14; // eax
int v15; // er12
const char *v16; // rax
char v17[312]; // [rsp+0h] [rbp-138h] BYREF

v3 = (const char *)&unk_CA1;
v4 = a1[1];
if ( v4 < 0 )
v3 = " not";
printf("%s%s ", v3, a2);
result = *a1;
if ( (_BYTE)result == 67 || (_BYTE)result == 70 )
return printf("me6");
if ( (_BYTE)result == 75 )
return printf(" ip6");
v6 = v4;
v7 = v4 & 0x3F;
v8 = v7 + 2;
v9 = v6 & 0x3F;
v10 = v7 - 1;
if ( v10 < 0 )
v10 = v8;
v11 = v10 >> 2;
if ( v9 > 4u )
{
v12 = (char *)(a1 + 20);
v13 = 0LL;
while ( (_BYTE)result != 66 && (_BYTE)result != 69 )
{
v14 = contigmask(v12, 128LL);
v15 = v14;
if ( v14 == 128 )
{
if ( co[1] )
LABEL_24:
v13 = gethostbyaddr(v12 - 16, 0x10u, 10);
if ( v13 )
{
LABEL_22:
result = printf("%s", v13->h_name);
goto LABEL_18;
}
if ( !inet_ntop(10, v12 - 16, v17, 0xFFu) )
{
LABEL_27:
puts("Error ntop in print_ip6");
result = printf("%s", v17);
goto LABEL_18;
}
LABEL_29:
result = printf("%s", v17);
goto LABEL_18;
}
if ( v13 )
goto LABEL_22;
if ( v14 )
{
if ( !inet_ntop(10, v12 - 16, v17, 0xFFu) )
puts("Error ntop in print_ip6");
result = printf("%s", v17);
if ( v15 >= 0 )
{
if ( v15 <= 127 )
result = printf("/%d", (unsigned int)v15);
}
else
{
v16 = inet_ntop(10, v12, v17, 0xFFu);
result = printf(":%s", v16);
}
}
else
{
result = printf("any");
}
LABEL_18:
if ( v11 <= 2 )
{
if ( v11 - 2 <= 0 )
return result;
}
else
{
putchar(44);
}
LOBYTE(result) = *a1;
v12 += 32;
v11 -= 2;
}
if ( co[1] )
goto LABEL_24;
if ( v13 )
goto LABEL_22;
if ( !inet_ntop(10, v12 - 16, v17, 0xFFu) )
goto LABEL_27;
goto LABEL_29;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int8 *a1, __int64 a2)
{
const char *v3; // rsi
char v4; // bl
int result; // eax
char v6; // cl
int v7; // ebx
int v8; // edx
unsigned __int8 v9; // cl
int v10; // ebx
int v11; // ebx
char *v12; // rbp
struct hostent *v13; // r13
int v14; // eax
int v15; // er12
const char *v16; // rax
char v17[312]; // [rsp+0h] [rbp-138h] BYREF

v3 = (const char *)&unk_CA1;
v4 = a1[1];
if ( v4 < 0 )
v3 = " not";
printf("%s%s ", v3, a2);
result = *a1;
if ( (_BYTE)result == 67 || (_BYTE)result == 70 )
return printf("me6");
if ( (_BYTE)result == 75 )
return printf(" ip6");
v6 = v4;
v7 = v4 & 0x3F;
v8 = v7 + 2;
v9 = v6 & 0x3F;
v10 = v7 - 1;
if ( v10 < 0 )
v10 = v8;
v11 = v10 >> 2;
if ( v9 > 4u )
{
v12 = (char *)(a1 + 20);
v13 = 0LL;
while ( (_BYTE)result != 66 && (_BYTE)result != 69 )
{
v14 = contigmask(v12, 128LL);
v15 = v14;
if ( v14 == 128 )
{
if ( co[1] )
LABEL_24:
v13 = gethostbyaddr(v12 - 16, 0x10u, 10);
if ( v13 )
{
LABEL_22:
result = printf("%s", v13->h_name);
goto LABEL_18;
}
if ( !inet_ntop(10, v12 - 16, v17, 0xFFu) )
{
LABEL_27:
puts("Error ntop in print_ip6");
result = printf("%s", v17);
goto LABEL_18;
}
LABEL_29:
result = printf("%s", v17);
goto LABEL_18;
}
if ( v13 )
goto LABEL_22;
if ( v14 )
{
if ( !inet_ntop(10, v12 - 16, v17, 0xFFu) )
puts("Error ntop in print_ip6");
result = printf("%s", v17);
if ( v15 >= 0 )
{
if ( v15 <= 127 )
result = printf("/%d", (unsigned int)v15);
}
else
{
v16 = inet_ntop(10, v12, v17, 0xFFu);
result = printf(":%s", v16);
}
}
else
{
result = printf("any");
}
LABEL_18:
if ( v11 <= 2 )
{
if ( v11 - 2 <= 0 )
return result;
}
else
{
putchar(44);
}
LOBYTE(result) = *a1;
v12 += 32;
v11 -= 2;
}
if ( co[1] )
goto LABEL_24;
if ( v13 )
goto LABEL_22;
if ( !inet_ntop(10, v12 - 16, v17, 0xFFu) )
goto LABEL_27;
goto LABEL_29;
}
return result;
}

original_code:
void
print_ip6(ipfw_insn_ip6 *cmd, char const *s)
{
       struct hostent *he = ((void *)0);
       int len = (((ipfw_insn *) cmd)->len & 0x3f) - 1;
       struct in6_addr *a = &(cmd->addr6);
       char trad[255];
       printf("%s%s ", cmd->o.len & 0x80 ? " not": "", s);
       if (cmd->o.opcode == O_IP6_SRC_ME || cmd->o.opcode == O_IP6_DST_ME) {
        printf("me6");
        return;
       }
       if (cmd->o.opcode == O_IP6) {
        printf(" ip6");
        return;
       }
       for (len = len / 4; len > 0; len -= 2, a += 2) {
    int mb =
        (cmd->o.opcode == O_IP6_SRC || cmd->o.opcode == O_IP6_DST) ?
        128 : contigmask((uint8_t *)&(a[1]), 128);
    if (mb == 128 && co.do_resolv)
        he = gethostbyaddr((char *)a, sizeof(*a), 10);
    if (he != ((void *)0))
        printf("%s", he->h_name);
    else if (mb == 0)
        printf("any");
    else {
        if (inet_ntop(10, a, trad, sizeof( trad ) ) == ((void *)0))
     printf("Error ntop in print_ip6\n");
        printf("%s", trad );
        if (mb < 0)
     printf(":%s",
         inet_ntop(10, &a[1], trad, sizeof(trad)));
        else if (mb < 128)
     printf("/%d", mb);
    }
    if (len > 2)
        printf(",");
       }
}

canonical_original_code:
void print_ip6(struct _ipfw_insn_ip6 *cmd, char *s)
{
       struct hostent *he = ((void *)0);
       int len = (((ipfw_insn *) cmd)->len & 0x3f) - 1;
       struct in6_addr *a = &(cmd->addr6);
       char trad[255];
       printf("%s%s ", cmd->o.len & 0x80 ? " not": "", s);
       if (cmd->o.opcode == O_IP6_SRC_ME || cmd->o.opcode == O_IP6_DST_ME) {
        printf("me6");
        return;
       }
       if (cmd->o.opcode == O_IP6) {
        printf(" ip6");
        return;
       }
       for (len = len / 4; len > 0; len -= 2, a += 2) {
    int mb = (cmd->o.opcode == O_IP6_SRC || cmd->o.opcode == O_IP6_DST) ?
        128 : contigmask((uint8_t *)&(a[1]), 128);
    if (mb == 128 && co.do_resolv)
        he = gethostbyaddr((char *)a, sizeof(*a), 10);
    if (he != ((void *)0))
        printf("%s", he->h_name);
    else if (mb == 0)
        printf("any");
    else {
        if (inet_ntop(10, a, trad, sizeof( trad ) ) == ((void *)0))
     printf("Error ntop in print_ip6\n");
        printf("%s", trad );
        if (mb < 0)
     printf(":%s",
         inet_ntop(10, &a[1], trad, sizeof(trad)));
        else if (mb < 128)
     printf("/%d", mb);
    }
    if (len > 2)
        printf(",");
       }
}

variable_types: struct _ipfw_insn_ip6 { struct _ipfw_insn { unsigned int opcode; unsigned int len; unsigned int arg1; } o; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int u6_addr32[4]; } __in6_u; } addr6; struct in6_addr mask6; } *

variable_types: len int

variable_types:
trad
char [255]

variable_types: mb int

user_defined_types: struct _ipfw_insn_ip6 { struct _ipfw_insn o; struct in6_addr addr6; struct in6_addr mask6; }

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


decompiled_code:
int __fastcall print_icmp6types(__int64 a1)
{
_DWORD *v1; // r13
int v2; // er12
__int64 v3; // rsi
int i; // ebx
int result; // eax

v1 = (_DWORD *)(a1 + 4);
v2 = 0;
printf(" ip6 icmp6types");
v3 = 32LL;
do
{
for ( i = 0; i != 32; ++i )
{
result = *v1 & (1 << i);
if ( result )
{
result = printf("%c%d", v3, (unsigned int)(i + v2));
v3 = 44LL;
}
}
v2 += 32;
++v1;
}
while ( v2 != 224 );
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
_DWORD *v1; // r13
int v2; // er12
__int64 v3; // rsi
int i; // ebx
int result; // eax

v1 = (_DWORD *)(a1 + 4);
v2 = 0;
printf(" ip6 icmp6types");
v3 = 32LL;
do
{
for ( i = 0; i != 32; ++i )
{
result = *v1 & (1 << i);
if ( result )
{
result = printf("%c%d", v3, (unsigned int)(i + v2));
v3 = 44LL;
}
}
v2 += 32;
++v1;
}
while ( v2 != 224 );
return result;
}

original_code:
void
print_icmp6types(ipfw_insn_u32 *cmd)
{
       int i, j;
       char sep= ' ';
       printf(" ip6 icmp6types");
       for (i = 0; i < 7; i++)
        for (j=0; j < 32; ++j) {
         if ( (cmd->d[i] & (1 << (j))) == 0)
          continue;
         printf("%c%d", sep, (i*32 + j));
         sep = ',';
        }
}

canonical_original_code:
void print_icmp6types(struct _ipfw_insn_u32 *cmd)
{
       int i; int j;
       char sep = ' ';
       printf(" ip6 icmp6types");
       for (i = 0; i < 7; i++)
        for (j=0; j < 32; ++j) {
         if ( (cmd->d[i] & (1 << (j))) == 0)
          continue;
         printf("%c%d", sep, (i*32 + j));
         sep = ',';
        }
}

variable_types: struct _ipfw_insn_u32 { struct _ipfw_insn { unsigned int opcode; unsigned int len; unsigned int arg1; } o; unsigned int d[1]; } *

variable_types: i int

variable_types: j int

variable_types: sep char

user_defined_types: struct _ipfw_insn_u32 { struct _ipfw_insn o; unsigned int d[1]; }


decompiled_code:
int __fastcall print_flow6id(__int64 a1)
{
unsigned __int16 v1; // bp
int result; // eax
__int64 v3; // rbx
char v4; // r13
__int64 v5; // rdx
__int64 v6; // rsi

v1 = *(_WORD *)(a1 + 2);
result = printf(" flow-id ");
if ( v1 )
{
v3 = 0LL;
v4 = 44;
do
{
v5 = (unsigned int)v4;
if ( v1 - 1 == (_DWORD)v3 )
{
v5 = 32LL;
v4 = 32;
}
v6 = *(unsigned int *)(a1 + 4 * v3++ + 4);
result = printf("%d%c", v6, v5);
}
while ( v1 > (unsigned __int16)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
unsigned __int16 v1; // bp
int result; // eax
__int64 v3; // rbx
char v4; // r13
__int64 v5; // rdx
__int64 v6; // rsi

v1 = *(_WORD *)(a1 + 2);
result = printf(" flow-id ");
if ( v1 )
{
v3 = 0LL;
v4 = 44;
do
{
v5 = (unsigned int)v4;
if ( v1 - 1 == (_DWORD)v3 )
{
v5 = 32LL;
v4 = 32;
}
v6 = *(unsigned int *)(a1 + 4 * v3++ + 4);
result = printf("%d%c", v6, v5);
}
while ( v1 > (unsigned __int16)v3 );
}
return result;
}

original_code:
void
print_flow6id( ipfw_insn_u32 *cmd)
{
       uint16_t i, limit = cmd->o.arg1;
       char sep = ',';
       printf(" flow-id ");
       for( i=0; i < limit; ++i) {
        if (i == limit - 1)
         sep = ' ';
        printf("%d%c", cmd->d[i], sep);
       }
}

canonical_original_code:
void print_flow6id(struct _ipfw_insn_u32 *cmd)
{
       unsigned short i; unsigned short limit = cmd->o.arg1;
       char sep = ',';
       printf(" flow-id ");
       for( i=0; i < limit; ++i) {
        if (i == limit - 1)
         sep = ' ';
        printf("%d%c", cmd->d[i], sep);
       }
}

variable_types:
i
unsigned short

variable_types:
limit
unsigned short

user_defined_types: struct _ipfw_insn { unsigned int opcode; unsigned int len; unsigned int arg1; }


decompiled_code:
__int64 __fastcall fill_ext6hdr(__int64 a1, char *a2)
{
char *v2; // rax
int v3; // eax
__int64 result; // rax
char *stringp; // [rsp+8h] [rbp-10h] BYREF

*(_WORD *)(a1 + 2) = 0;
stringp = a2;
if ( !a2 )
return 0LL;
do
{
v2 = strsep(&stringp, ",");
v3 = match_token(&ext6hdrcodes, v2);
if ( v3 <= 32 )
{
if ( v3 > 0 )
{
switch ( v3 )
{
case 1:
*(_WORD *)(a1 + 2) |= 1u;
continue;
case 2:
*(_WORD *)(a1 + 2) |= 2u;
continue;
case 4:
*(_WORD *)(a1 + 2) |= 4u;
continue;
case 8:
*(_WORD *)(a1 + 2) |= 8u;
continue;
case 16:
*(_WORD *)(a1 + 2) |= 0x10u;
continue;
case 32:
*(_WORD *)(a1 + 2) |= 0x20u;
continue;
default:
break;
}
}
LABEL_19:
errx(65, "invalid option for ipv6 exten header");
}
if ( v3 == 64 )
{
*(_WORD *)(a1 + 2) |= 0x40u;
}
else
{
if ( v3 != 128 )
goto LABEL_19;
*(_WORD *)(a1 + 2) |= 0x80u;
}
}
while ( stringp );
if ( !*(_WORD *)(a1 + 2) )
return 0LL;
*(_BYTE *)(a1 + 1) |= 1u;
result = 1LL;
*(_BYTE *)a1 = 74;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
char *v2; // rax
int v3; // eax
__int64 result; // rax
char *stringp; // [rsp+8h] [rbp-10h] BYREF

*(_WORD *)(a1 + 2) = 0;
stringp = a2;
if ( !a2 )
return 0LL;
do
{
v2 = strsep(&stringp, ",");
v3 = match_token(&ext6hdrcodes, v2);
if ( v3 <= 32 )
{
if ( v3 > 0 )
{
switch ( v3 )
{
case 1:
*(_WORD *)(a1 + 2) |= 1u;
continue;
case 2:
*(_WORD *)(a1 + 2) |= 2u;
continue;
case 4:
*(_WORD *)(a1 + 2) |= 4u;
continue;
case 8:
*(_WORD *)(a1 + 2) |= 8u;
continue;
case 16:
*(_WORD *)(a1 + 2) |= 0x10u;
continue;
case 32:
*(_WORD *)(a1 + 2) |= 0x20u;
continue;
default:
break;
}
}
LABEL_19:
errx(65, "invalid option for ipv6 exten header");
}
if ( v3 == 64 )
{
*(_WORD *)(a1 + 2) |= 0x40u;
}
else
{
if ( v3 != 128 )
goto LABEL_19;
*(_WORD *)(a1 + 2) |= 0x80u;
}
}
while ( stringp );
if ( !*(_WORD *)(a1 + 2) )
return 0LL;
*(_BYTE *)(a1 + 1) |= 1u;
result = 1LL;
*(_BYTE *)a1 = 74;
return result;
}

original_code:
int
fill_ext6hdr( ipfw_insn *cmd, char *av)
{
       int tok;
       char *s = av;
       cmd->arg1 = 0;
       while(s) {
    av = strsep( &s, ",") ;
    tok = match_token(ext6hdrcodes, av);
    switch (tok) {
    case 0x1:
        cmd->arg1 |= 0x1;
        break;
    case 0x2:
        cmd->arg1 |= 0x2;
        break;
    case 0x4:
        cmd->arg1 |= 0x4;
        break;
    case 0x20:
        cmd->arg1 |= 0x20;
        break;
    case 0x8:
        cmd->arg1 |= 0x8;
        break;
    case 0x10:
        cmd->arg1 |= 0x10;
        break;
    case 0x40:
        cmd->arg1 |= 0x40;
        break;
    case 0x80:
        cmd->arg1 |= 0x80;
        break;
    default:
        errx( 65, "invalid option for ipv6 exten header" );
        break;
    }
       }
       if (cmd->arg1 == 0 )
    return 0;
       cmd->opcode = O_EXT_HDR;
       cmd->len |= ((sizeof (ipfw_insn))/sizeof(u_int32_t));
       return 1;
}

canonical_original_code:
int fill_ext6hdr(struct _ipfw_insn *cmd, char *av)
{
       int tok;
       char *s = av;
       cmd->arg1 = 0;
       while(s) {
    av = strsep( &s, ",") ;
    tok = match_token(ext6hdrcodes, av);
    switch (tok) {
    case 0x1:
        cmd->arg1 |= 0x1;
        break;
    case 0x2:
        cmd->arg1 |= 0x2;
        break;
    case 0x4:
        cmd->arg1 |= 0x4;
        break;
    case 0x20:
        cmd->arg1 |= 0x20;
        break;
    case 0x8:
        cmd->arg1 |= 0x8;
        break;
    case 0x10:
        cmd->arg1 |= 0x10;
        break;
    case 0x40:
        cmd->arg1 |= 0x40;
        break;
    case 0x80:
        cmd->arg1 |= 0x80;
        break;
    default:
        errx( 65, "invalid option for ipv6 exten header" );
        break;
    }
       }
       if (cmd->arg1 == 0 )
    return 0;
       cmd->opcode = O_EXT_HDR;
       cmd->len |= ((sizeof (ipfw_insn))/sizeof(u_int32_t));
       return 1;
}

variable_types: struct _ipfw_insn { unsigned int opcode; unsigned int len; unsigned int arg1; } *

variable_types:
av
char *

variable_types: tok int


decompiled_code:
int __fastcall print_ext6hdr(__int64 a1)
{
int result; // eax
__int64 v2; // rsi

printf(" extension header:");
result = *(unsigned __int16 *)(a1 + 2);
v2 = 32LL;
if ( (result & 1) != 0 )
{
printf("%cfragmentation", 32LL);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 2) == 0 )
{
LABEL_3:
if ( (result & 4) == 0 )
goto LABEL_4;
goto LABEL_12;
}
}
else if ( (result & 2) == 0 )
{
goto LABEL_3;
}
printf("%chop options", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 4) == 0 )
{
LABEL_4:
if ( (result & 0x40) == 0 )
goto LABEL_5;
goto LABEL_13;
}
LABEL_12:
printf("%crouting options", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x40) == 0 )
{
LABEL_5:
if ( (result & 0x80u) == 0 )
goto LABEL_6;
goto LABEL_14;
}
LABEL_13:
printf("%crthdr0", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x80u) == 0 )
{
LABEL_6:
if ( (result & 0x20) == 0 )
goto LABEL_7;
goto LABEL_15;
}
LABEL_14:
printf("%crthdr2", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x20) == 0 )
{
LABEL_7:
if ( (result & 8) == 0 )
goto LABEL_8;
goto LABEL_16;
}
LABEL_15:
printf("%cdestination options", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 8) == 0 )
{
LABEL_8:
if ( (result & 0x10) == 0 )
return result;
return printf("%cencapsulated security payload", v2);
}
LABEL_16:
printf("%cauthentication header", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x10) != 0 )
return printf("%cencapsulated security payload", v2);
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
int result; // eax
__int64 v2; // rsi

printf(" extension header:");
result = *(unsigned __int16 *)(a1 + 2);
v2 = 32LL;
if ( (result & 1) != 0 )
{
printf("%cfragmentation", 32LL);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 2) == 0 )
{
LABEL_3:
if ( (result & 4) == 0 )
goto LABEL_4;
goto LABEL_12;
}
}
else if ( (result & 2) == 0 )
{
goto LABEL_3;
}
printf("%chop options", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 4) == 0 )
{
LABEL_4:
if ( (result & 0x40) == 0 )
goto LABEL_5;
goto LABEL_13;
}
LABEL_12:
printf("%crouting options", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x40) == 0 )
{
LABEL_5:
if ( (result & 0x80u) == 0 )
goto LABEL_6;
goto LABEL_14;
}
LABEL_13:
printf("%crthdr0", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x80u) == 0 )
{
LABEL_6:
if ( (result & 0x20) == 0 )
goto LABEL_7;
goto LABEL_15;
}
LABEL_14:
printf("%crthdr2", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x20) == 0 )
{
LABEL_7:
if ( (result & 8) == 0 )
goto LABEL_8;
goto LABEL_16;
}
LABEL_15:
printf("%cdestination options", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 8) == 0 )
{
LABEL_8:
if ( (result & 0x10) == 0 )
return result;
return printf("%cencapsulated security payload", v2);
}
LABEL_16:
printf("%cauthentication header", v2);
result = *(unsigned __int16 *)(a1 + 2);
v2 = 44LL;
if ( (result & 0x10) != 0 )
return printf("%cencapsulated security payload", v2);
return result;
}

original_code:
void
print_ext6hdr( ipfw_insn *cmd )
{
       char sep = ' ';
       printf(" extension header:");
       if (cmd->arg1 & 0x1 ) {
    printf("%cfragmentation", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x2 ) {
    printf("%chop options", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x4 ) {
    printf("%crouting options", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x40 ) {
    printf("%crthdr0", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x80 ) {
    printf("%crthdr2", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x20 ) {
    printf("%cdestination options", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x8 ) {
    printf("%cauthentication header", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x10 ) {
    printf("%cencapsulated security payload", sep);
       }
}

canonical_original_code:
void print_ext6hdr(struct _ipfw_insn *cmd)
{
       char sep = ' ';
       printf(" extension header:");
       if (cmd->arg1 & 0x1 ) {
    printf("%cfragmentation", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x2 ) {
    printf("%chop options", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x4 ) {
    printf("%crouting options", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x40 ) {
    printf("%crthdr0", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x80 ) {
    printf("%crthdr2", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x20 ) {
    printf("%cdestination options", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x8 ) {
    printf("%cauthentication header", sep);
    sep = ',';
       }
       if (cmd->arg1 & 0x10 ) {
    printf("%cencapsulated security payload", sep);
       }
}


decompiled_code:
__int64 __fastcall fill_flow6(__int64 a1, char *a2)
{
int v2; // ebx
unsigned int v3; // eax
char *v4; // r8
__int64 v5; // rdx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF
char *stringp; // [rsp+18h] [rbp-20h] BYREF

*(_DWORD *)(a1 + 4) = 0;
endptr = a2;
stringp = a2;
if ( !a2 )
{
v4 = 0LL;
goto LABEL_10;
}
v2 = 0;
do
{
endptr = strsep(&stringp, ",");
v3 = strtoul(endptr, &endptr, 0);
v4 = endptr;
if ( *endptr != 44 && *endptr )
goto LABEL_10;
if ( v3 > 0xFFFFF )
errx(65, "flow number out of range %s", endptr);
v5 = (unsigned __int16)v2++;
*(_DWORD *)(a1 + 4 * v5 + 4) |= v3;
}
while ( stringp );
if ( !(_WORD)v2 )
LABEL_10:
errx(65, "invalid ipv6 flow number %s", v4);
*(_BYTE *)a1 = 72;
result = (unsigned int)(v2 + 2);
*(_WORD *)(a1 + 2) = v2;
*(_BYTE *)(a1 + 1) |= (_BYTE)v2 + 2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2)
{
int v2; // ebx
unsigned int v3; // eax
char *v4; // r8
__int64 v5; // rdx
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF
char *stringp; // [rsp+18h] [rbp-20h] BYREF

*(_DWORD *)(a1 + 4) = 0;
endptr = a2;
stringp = a2;
if ( !a2 )
{
v4 = 0LL;
goto LABEL_10;
}
v2 = 0;
do
{
endptr = strsep(&stringp, ",");
v3 = strtoul(endptr, &endptr, 0);
v4 = endptr;
if ( *endptr != 44 && *endptr )
goto LABEL_10;
if ( v3 > 0xFFFFF )
errx(65, "flow number out of range %s", endptr);
v5 = (unsigned __int16)v2++;
*(_DWORD *)(a1 + 4 * v5 + 4) |= v3;
}
while ( stringp );
if ( !(_WORD)v2 )
LABEL_10:
errx(65, "invalid ipv6 flow number %s", v4);
*(_BYTE *)a1 = 72;
result = (unsigned int)(v2 + 2);
*(_WORD *)(a1 + 2) = v2;
*(_BYTE *)(a1 + 1) |= (_BYTE)v2 + 2;
return result;
}

original_code:
void
fill_flow6( ipfw_insn_u32 *cmd, char *av )
{
 u_int32_t type;
 u_int16_t nflow = 0;
 char *s = av;
 cmd->d[0] = 0;
 while (s) {
  av = strsep( &s, ",") ;
  type = strtoul(av, &av, 0);
  if (*av != ',' && *av != '\0')
   errx(65, "invalid ipv6 flow number %s", av);
  if (type > 0xfffff)
   errx(65, "flow number out of range %s", av);
  cmd->d[nflow] |= type;
  nflow++;
 }
 if( nflow > 0 ) {
  cmd->o.opcode = O_FLOW6ID;
  cmd->o.len |= ((sizeof (ipfw_insn_u32))/sizeof(u_int32_t)) + nflow;
  cmd->o.arg1 = nflow;
 }
 else {
  errx(65, "invalid ipv6 flow number %s", av);
 }
}

canonical_original_code:
void fill_flow6(struct _ipfw_insn_u32 *cmd, char *av)
{
 unsigned int type;
 unsigned int nflow = 0;
 char *s = av;
 cmd->d[0] = 0;
 while (s) {
  av = strsep( &s, ",") ;
  type = strtoul(av, &av, 0);
  if (*av != ',' && *av != '\0')
   errx(65, "invalid ipv6 flow number %s", av);
  if (type > 0xfffff)
   errx(65, "flow number out of range %s", av);
  cmd->d[nflow] |= type;
  nflow++;
 }
 if( nflow > 0 ) {
  cmd->o.opcode = O_FLOW6ID;
  cmd->o.len |= ((sizeof (ipfw_insn_u32))/sizeof(u_int32_t)) + nflow;
  cmd->o.arg1 = nflow;
 }
 else {
  errx(65, "invalid ipv6 flow number %s", av);
 }
}

variable_types:
type
unsigned int

variable_types:
nflow
unsigned int


decompiled_code:
__int64 do_del()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
static int
do_del(void *obj, void *arg)
{
 return DNHT_SCAN_DEL;
}

variable_types:
obj
void *

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall heap_resize(unsigned int *a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // esi
unsigned int v4; // er12
void *v5; // rax
void *v6; // rbp
__int64 v7; // rdx

result = 0LL;
if ( *a1 < a2 )
{
v3 = a2 | (a2 >> 1) | ((a2 | (a2 >> 1)) >> 2);
v4 = (((v3 >> 4) | v3 | (((v3 >> 4) | v3) >> 8)) >> 16) | (v3 >> 4) | v3 | (((v3 >> 4) | v3) >> 8);
v5 = (void *)kern_malloc(16 * v4);
v6 = v5;
if ( v5 )
{
v7 = (int)*a1;
if ( (int)v7 > 0 )
{
memmove(v5, *((const void **)a1 + 2), 16 * v7);
kern_free(*((_QWORD *)a1 + 2));
}
*((_QWORD *)a1 + 2) = v6;
result = 0LL;
*a1 = v4;
}
else
{
printf("--- %s, resize %d failed\n", "heap_resize", v4);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // esi
unsigned int v4; // er12
void *v5; // rax
void *v6; // rbp
__int64 v7; // rdx

result = 0LL;
if ( *a1 < a2 )
{
v3 = a2 | (a2 >> 1) | ((a2 | (a2 >> 1)) >> 2);
v4 = (((v3 >> 4) | v3 | (((v3 >> 4) | v3) >> 8)) >> 16) | (v3 >> 4) | v3 | (((v3 >> 4) | v3) >> 8);
v5 = (void *)kern_malloc(16 * v4);
v6 = v5;
if ( v5 )
{
v7 = (int)*a1;
if ( (int)v7 > 0 )
{
memmove(v5, *((const void **)a1 + 2), 16 * v7);
kern_free(*((_QWORD *)a1 + 2));
}
*((_QWORD *)a1 + 2) = v6;
result = 0LL;
*a1 = v4;
}
else
{
printf("--- %s, resize %d failed\n", "heap_resize", v4);
result = 1LL;
}
}
return result;
}

original_code:
static int
heap_resize(struct dn_heap *h, unsigned int new_size)
{
 struct dn_heap_entry *p;
 if (h->size >= new_size )
  return 0;
 new_size |= new_size >> 1;
 new_size |= new_size >> 2;
 new_size |= new_size >> 4;
 new_size |= new_size >> 8;
 new_size |= new_size >> 16;
 p = kern_malloc(new_size * sizeof(*p));
 if (p == ((void *)0)) {
  printf("--- %s, resize %d failed\n", __func__, new_size );
  return 1;
 }
 if (h->size > 0) {
  bcopy(h->p, p, h->size * sizeof(*p) );
  kern_free(h->p);
 }
 h->p = p;
 h->size = new_size;
 return 0;
}

variable_types: struct dn_heap { int size; int elements; int ofs; struct dn_heap_entry { unsigned long key; void *object; } *p; } *

user_defined_types: struct dn_heap { int size; int elements; int ofs; struct dn_heap_entry *p; }


decompiled_code:
__int64 __fastcall heap_init(unsigned int *a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

result = heap_resize(a1, a2);
if ( (_DWORD)result )
return 1LL;
a1[2] = a3;
a1[1] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

result = func1(a1, a2);
if ( (_DWORD)result )
return 1LL;
a1[2] = a3;
a1[1] = 0;
return result;
}

original_code:
int
heap_init(struct dn_heap *h, int size, int ofs)
{
 if (heap_resize(h, size))
  return 1;
 h->elements = 0;
 h->ofs = ofs;
 return 0;
}

variable_types: size int

variable_types: ofs int

user_defined_types: struct dn_heap_entry { unsigned long key; void *object; }


original_code:
int
heap_insert(struct dn_heap *h, uint64_t key1, void *p)
{
 int son = h->elements;
 if (p == ((void *)0)) {
  son = key1;
 } else {
  son = h->elements;
  if (son == h->size)
   if (heap_resize(h, h->elements+16) )
    return 1;
  h->p[son].object = p;
  h->p[son].key = key1;
  h->elements++;
 }
 while (son > 0) {
  int father = ( ( (son) - 1 ) / 2 );
  struct dn_heap_entry tmp;
  if (((int64_t)((h->p[father].key)-(h->p[son].key)) < 0) )
   break;
  { tmp = h->p[son] ; h->p[son] = h->p[father] ; h->p[father] = tmp ; };
  do { if (h->ofs > 0) *((int32_t *)((char *)(h->p[son].object) + h->ofs)) = son; } while (0);
  son = father;
 }
 do { if (h->ofs > 0) *((int32_t *)((char *)(h->p[son].object) + h->ofs)) = son; } while (0);
 return 0;
}

canonical_original_code:
int heap_insert(struct dn_heap *h, unsigned long key1, void *p)
{
 int son = h->elements;
 if (p == ((void *)0)) {
  son = key1;
 } else {
  son = h->elements;
  if (son == h->size)
   if (heap_resize(h, h->elements+16) )
    return 1;
  h->p[son].object = p;
  h->p[son].key = key1;
  h->elements++;
 }
 while (son > 0) {
  int father = ( ( (son) - 1 ) / 2 );
  struct dn_heap_entry tmp;
  if (((long)((h->p[father].key)-(h->p[son].key)) < 0) )
   break;
  { tmp = h->p[son] ; h->p[son] = h->p[father] ; h->p[father] = tmp ; };
  do { if (h->ofs > 0) *((int *)((char *)(h->p[son].object) + h->ofs)) = son; } while (0);
  son = father;
 }
 do { if (h->ofs > 0) *((int *)((char *)(h->p[son].object) + h->ofs)) = son; } while (0);
 return 0;
}

variable_types:
p
void *

variable_types: son int

variable_types: father int

variable_types: struct dn_heap_entry { unsigned long key; void *object; }


heapify

decompiled_code:
__int64 __fastcall heapify(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rsi

result = *(unsigned int *)(a1 + 4);
if ( (int)result > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
result = heap_insert(a1, v3, 0LL);
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // rsi

result = *(unsigned int *)(a1 + 4);
if ( (int)result > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
result = func3(a1, v3, 0LL);
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
}
return result;
}

original_code:
static void
heapify(struct dn_heap *h)
{
 int i;
 for (i = 0; i < h->elements; i++ )
  heap_insert(h, i , ((void *)0));
}

variable_types: i int


original_code:
void
heap_extract(struct dn_heap *h, void *obj)
{
 int child, father, max = h->elements - 1;
 if (max < 0) {
  printf("--- %s: empty heap 0x%p\n", __FUNCTION__, h);
  return;
 }
 if (obj == ((void *)0))
  father = 0;
 else {
  if (h->ofs <= 0)
   panic("%s: extract from middle not set on %p\n",
    __FUNCTION__, h);
  father = *((int *)((char *)obj + h->ofs));
  if (father < 0 || father >= h->elements) {
   panic("%s: father %d out of bound 0..%d\n",
    __FUNCTION__, father, h->elements);
  }
 }
 do { if (h->ofs > 0) *((int32_t *)((char *)(h->p[father].object) + h->ofs)) = -16; } while (0);
 while ( (child = ( (father)+(father) + 1 )) <= max ) {
  if (child != max &&
      ((int64_t)((h->p[child+1].key)-(h->p[child].key)) < 0) )
   child++;
  h->p[father] = h->p[child];
  do { if (h->ofs > 0) *((int32_t *)((char *)(h->p[father].object) + h->ofs)) = father; } while (0);
  father = child;
 }
 h->elements--;
 if (father != max) {
  h->p[father] = h->p[max];
  heap_insert(h, father, ((void *)0));
 }
}

canonical_original_code:
void heap_extract(struct dn_heap *h, void *obj)
{
 int child; int father; int max = h->elements - 1;
 if (max < 0) {
  printf("--- %s: empty heap 0x%p\n", __FUNCTION__, h);
  return;
 }
 if (obj == ((void *)0))
  father = 0;
 else {
  if (h->ofs <= 0)
   panic("%s: extract from middle not set on %p\n",
    __FUNCTION__, h);
  father = *((int *)((char *)obj + h->ofs));
  if (father < 0 || father >= h->elements) {
   panic("%s: father %d out of bound 0..%d\n",
    __FUNCTION__, father, h->elements);
  }
 }
 do { if (h->ofs > 0) *((int *)((char *)(h->p[father].object) + h->ofs)) = -16; } while (0);
 while ( (child = ( (father)+(father) + 1 )) <= max ) {
  if (child != max &&
      ((long)((h->p[child+1].key)-(h->p[child].key)) < 0) )
   child++;
  h->p[father] = h->p[child];
  do { if (h->ofs > 0) *((int *)((char *)(h->p[father].object) + h->ofs)) = father; } while (0);
  father = child;
 }
 h->elements--;
 if (father != max) {
  h->p[father] = h->p[max];
  heap_insert(h, father, ((void *)0));
 }
}

variable_types: child int

variable_types: max int


original_code:
int
heap_scan(struct dn_heap *h, int (*fn)(void *, uintptr_t),
 uintptr_t arg)
{
 int i, ret, found;
 for (i = found = 0 ; i < h->elements ;) {
  ret = fn(h->p[i].object, arg);
  if (ret & HEAP_SCAN_DEL) {
   h->elements-- ;
   h->p[i] = h->p[h->elements] ;
   found++ ;
  } else
   i++ ;
  if (ret & HEAP_SCAN_END)
   break;
 }
 if (found)
  heapify(h);
 return found;
}

canonical_original_code:
int heap_scan(struct dn_heap *h, int (*fn)(void *, unsigned long), unsigned long arg)
{
 int i; int ret; int found;
 for (i = found = 0 ; i < h->elements ;) {
  ret = fn(h->p[i].object, arg);
  if (ret & HEAP_SCAN_DEL) {
   h->elements-- ;
   h->p[i] = h->p[h->elements] ;
   found++ ;
  } else
   i++ ;
  if (ret & HEAP_SCAN_END)
   break;
 }
 if (found)
  heapify(h);
 return found;
}

variable_types:
fn
int (*)(void *, unsigned long)

variable_types:
arg
unsigned long

variable_types: ret int

variable_types: found int


decompiled_code:
__int64 __fastcall heap_free(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (int)result > 0 )
result = kern_free(*((_QWORD *)a1 + 2));
*((_QWORD *)a1 + 2) = 0LL;
*(_OWORD *)a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
if ( (int)result > 0 )
result = kern_free(*((_QWORD *)a1 + 2));
*((_QWORD *)a1 + 2) = 0LL;
*(_OWORD *)a1 = 0LL;
return result;
}

original_code:
void
heap_free(struct dn_heap *h)
{
 if (h->size >0 )
  kern_free(h->p);
 bzero(h, sizeof(*h) );
}


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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 4);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 4);
return result;
}

original_code:
int
dn_ht_entries(struct dn_ht *ht)
{
 return ht ? ht->entries : 0;
}

variable_types: struct dn_ht { int buckets; int entries; int ofs; unsigned int (*hash)(unsigned long, int, void *arg); int (*match)(void *_el, unsigned long key, int, void *); void *(*newh)(unsigned long, int, void *); void **ht; } *


original_code:
void *
dn_ht_find(struct dn_ht *ht, uintptr_t key, int flags, void *arg)
{
 int i;
 void **pp, *p;
 if (ht == ((void *)0))
  return ((void *)0);
 i = (ht->buckets == 1) ? 0 :
  (ht->hash(key, flags, arg) & ht->buckets);
 for (pp = &ht->ht[i]; (p = *pp); pp = (void **)((char *)p + ht->ofs)) {
  if (flags & DNHT_MATCH_PTR) {
   if (key == (uintptr_t)p)
    break;
  } else if (ht->match(p, key, flags, arg))
   break;
 }
 if (p) {
  if (flags & DNHT_REMOVE) {
   *pp = *(void **)((char *)p + ht->ofs);
   *(void **)((char *)p + ht->ofs) = ((void *)0);
   ht->entries--;
  }
 } else if (flags & DNHT_INSERT) {
  p = ht->newh ? ht->newh(key, flags, arg) : (void *)key;
  if (p) {
   ht->entries++;
   *(void **)((char *)p + ht->ofs) = ht->ht[i];
   ht->ht[i] = p;
  }
 }
 return p;
}

canonical_original_code:
void *dn_ht_find(struct dn_ht *ht, unsigned long key, int flags, void *arg)
{
 int i;
 void **pp; void *p;
 if (ht == ((void *)0))
  return ((void *)0);
 i = (ht->buckets == 1) ? 0 :
  (ht->hash(key, flags, arg) & ht->buckets);
 for (pp = &ht->ht[i]; (p = *pp); pp = (void **)((char *)p + ht->ofs)) {
  if (flags & DNHT_MATCH_PTR) {
   if (key == (unsigned long)p)
    break;
  } else if (ht->match(p, key, flags, arg))
   break;
 }
 if (p) {
  if (flags & DNHT_REMOVE) {
   *pp = *(void **)((char *)p + ht->ofs);
   *(void **)((char *)p + ht->ofs) = ((void *)0);
   ht->entries--;
  }
 } else if (flags & DNHT_INSERT) {
  p = ht->newh ? ht->newh(key, flags, arg) : (void *)key;
  if (p) {
   ht->entries++;
   *(void **)((char *)p + ht->ofs) = ht->ht[i];
   ht->ht[i] = p;
  }
 }
 return p;
}

variable_types:
key
unsigned long

variable_types: flags int

variable_types:
pp
void **

return_type: void *

user_defined_types: struct dn_ht { int buckets; int entries; int ofs; unsigned int (*hash)(unsigned long, int, void *arg); int (*match)(void *_el, unsigned long key, int, void *); void *(*newh)(unsigned long, int, void *); void **ht; }


original_code:
int
dn_ht_scan(struct dn_ht *ht, int (*fn)(void *, void *), void *arg)
{
 int i, ret, found = 0;
 void **curp, *cur, *next;
 if (ht == ((void *)0) || fn == ((void *)0))
  return 0;
 for (i = 0; i <= ht->buckets; i++) {
  curp = &ht->ht[i];
  while ( (cur = *curp) != ((void *)0)) {
   next = *(void **)((char *)cur + ht->ofs);
   ret = fn(cur, arg);
   if (ret & DNHT_SCAN_DEL) {
    found++;
    ht->entries--;
    *curp = next;
   } else {
    curp = (void **)((char *)cur + ht->ofs);
   }
   if (ret & DNHT_SCAN_END)
    return found;
  }
 }
 return found;
}

canonical_original_code:
int dn_ht_scan(struct dn_ht *ht, int (*fn)(void *, void *), void *arg)
{
 int i; int ret; int found = 0;
 void **curp; void *cur; void *next;
 if (ht == ((void *)0) || fn == ((void *)0))
  return 0;
 for (i = 0; i <= ht->buckets; i++) {
  curp = &ht->ht[i];
  while ( (cur = *curp) != ((void *)0)) {
   next = *(void **)((char *)cur + ht->ofs);
   ret = fn(cur, arg);
   if (ret & DNHT_SCAN_DEL) {
    found++;
    ht->entries--;
    *curp = next;
   } else {
    curp = (void **)((char *)cur + ht->ofs);
   }
   if (ret & DNHT_SCAN_END)
    return found;
  }
 }
 return found;
}

variable_types:
fn
int (*)(void *, void *)

variable_types:
arg
void *

variable_types:
curp
void **

variable_types:
cur
void *

variable_types:
next
void *


decompiled_code:
__int64 __fastcall dn_ht_free(__int64 a1, char a2)
{
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( (a2 & 0x40) != 0 )
{
result = dn_ht_scan(a1, (__int64 (__fastcall *)(_QWORD, __int64))do_del, 0LL);
}
else
{
v3 = *(_QWORD *)(a1 + 40);
if ( v3 )
{
if ( v3 != a1 + 48 )
kern_free(v3);
}
result = kern_free(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, char a2)
{
__int64 v3; // rdi
__int64 result; // rax

if ( a1 )
{
if ( (a2 & 0x40) != 0 )
{
result = func11(a1, (__int64 (__fastcall *)(_QWORD, __int64))do_del, 0LL);
}
else
{
v3 = *(_QWORD *)(a1 + 40);
if ( v3 )
{
if ( v3 != a1 + 48 )
kern_free(v3);
}
result = kern_free(a1);
}
}
return result;
}

original_code:
void
dn_ht_free(struct dn_ht *ht, int flags)
{
 if (ht == ((void *)0))
  return;
 if (flags & DNHT_REMOVE) {
  (void)dn_ht_scan(ht, do_del, ((void *)0));
 } else {
  if (ht->ht && ht->ht != (void *)(ht + 1))
   kern_free(ht->ht);
  kern_free(ht);
 }
}


original_code:
int
dn_ht_scan_bucket(struct dn_ht *ht, int *bucket, int (*fn)(void *, void *),
   void *arg)
{
 int i, ret, found = 0;
 void **curp, *cur, *next;
 if (ht == ((void *)0) || fn == ((void *)0))
  return 0;
 if (*bucket > ht->buckets)
  *bucket = 0;
 i = *bucket;
 curp = &ht->ht[i];
 while ( (cur = *curp) != ((void *)0)) {
  next = *(void **)((char *)cur + ht->ofs);
  ret = fn(cur, arg);
  if (ret & DNHT_SCAN_DEL) {
   found++;
   ht->entries--;
   *curp = next;
  } else {
   curp = (void **)((char *)cur + ht->ofs);
  }
  if (ret & DNHT_SCAN_END)
   return found;
 }
 return found;
}

canonical_original_code:
int dn_ht_scan_bucket(struct dn_ht *ht, int *bucket, int (*fn)(void *, void *), void *arg)
{
 int i; int ret; int found = 0;
 void **curp; void *cur; void *next;
 if (ht == ((void *)0) || fn == ((void *)0))
  return 0;
 if (*bucket > ht->buckets)
  *bucket = 0;
 i = *bucket;
 curp = &ht->ht[i];
 while ( (cur = *curp) != ((void *)0)) {
  next = *(void **)((char *)cur + ht->ofs);
  ret = fn(cur, arg);
  if (ret & DNHT_SCAN_DEL) {
   found++;
   ht->entries--;
   *curp = next;
  } else {
   curp = (void **)((char *)cur + ht->ofs);
  }
  if (ret & DNHT_SCAN_END)
   return found;
 }
 return found;
}

variable_types:
bucket
int *


writen

decompiled_code:
__int64 __fastcall writen(int fd, void *buf, int a3)
{
int v4; // ebp
int v5; // ebx

if ( a3 <= 0 )
return 0LL;
v4 = a3;
do
{
v5 = write(fd, buf, v4);
if ( v5 < 0 && *_errno_location() != 11 )
return 0xFFFFFFFFLL;
v4 -= v5;
buf = (char *)buf + v5;
}
while ( v4 > 0 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, int a3)
{
int v4; // ebp
int v5; // ebx

if ( a3 <= 0 )
return 0LL;
v4 = a3;
do
{
v5 = write(fd, buf, v4);
if ( v5 < 0 && *_errno_location() != 11 )
return 0xFFFFFFFFLL;
v4 -= v5;
buf = (char *)buf + v5;
}
while ( v4 > 0 );
return 0LL;
}

original_code:
static int
writen(int fd, const char *buf, int len)
{
 int i;
 for (; len > 0; buf += i, len -= i) {
  i = write(fd, buf, len);
  do {} while (0);
  if (i < 0) {
   if ((*__errno_location ()) == 11)
    continue;
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
static int writen(int fd, char *buf, int len)
{
 int i;
 for (; len > 0; buf += i, len -= i) {
  i = write(fd, buf, len);
  do {} while (0);
  if (i < 0) {
   if ((*__errno_location ()) == 11)
    continue;
   return -1;
  }
 }
 return 0;
}

variable_types: fd int

variable_types:
buf
char *

variable_types: len int

variable_types: i int


readn

decompiled_code:
__int64 __fastcall readn(int fd, __int64 a2, int a3)
{
int i; // ebx
int v5; // ebp

if ( a3 <= 0 )
return 0LL;
for ( i = 0; i < a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( v5 < 0 && *_errno_location() != 11 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, __int64 a2, int a3)
{
int i; // ebx
int v5; // ebp

if ( a3 <= 0 )
return 0LL;
for ( i = 0; i < a3; i += v5 )
{
v5 = read(fd, (void *)(a2 + i), a3 - i);
if ( v5 < 0 && *_errno_location() != 11 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
static int
readn(int fd, char *buf, int len)
{
 int i, pos;
 for (pos = 0; pos < len; pos += i) {
  i = read(fd, buf + pos, len - pos);
  do {} while (0);
  if (i < 0) {
   if ((*__errno_location ()) == 11)
    continue;
   return -1;
  }
 }
 do {} while (0);
 return 0;
}

canonical_original_code:
static int readn(int fd, char *buf, int len)
{
 int i; int pos;
 for (pos = 0; pos < len; pos += i) {
  i = read(fd, buf + pos, len - pos);
  do {} while (0);
  if (i < 0) {
   if ((*__errno_location ()) == 11)
    continue;
   return -1;
  }
 }
 do {} while (0);
 return 0;
}

variable_types: pos int


decompiled_code:
int ipfw_show_nat()
{
char *v0; // rax

v0 = xyz_constprop_0();
return fprintf(stderr, "%s:%-10s [%d] unsupported\n", v0, "ipfw_show_nat", 22LL);
}

canonical_decompiled_code:
int func5()
{
char *v0; // rax

v0 = func4();
return fprintf(stderr, "%s:%-10s [%d] unsupported\n", v0, "ipfw_show_nat", 22LL);
}

original_code:
void
ipfw_show_nat(int ac, char **av)
{
        fprintf(stderr, "%s:%-10s [%d] " "unsupported" "\n", xyz("../extra/glue.c"), __FUNCTION__, 22);
}

variable_types: ac int

variable_types:
av
char **


decompiled_code:
int ipfw_config_nat()
{
char *v0; // rax

v0 = xyz_constprop_0();
return fprintf(stderr, "%s:%-10s [%d] unsupported\n", v0, "ipfw_config_nat", 28LL);
}

canonical_decompiled_code:
int func6()
{
char *v0; // rax

v0 = func4();
return fprintf(stderr, "%s:%-10s [%d] unsupported\n", v0, "ipfw_config_nat", 28LL);
}

original_code:
void
ipfw_config_nat(int ac, char **av)
{
        fprintf(stderr, "%s:%-10s [%d] " "unsupported" "\n", xyz("../extra/glue.c"), __FUNCTION__, 28);
}


strtonum

decompiled_code:
__int64 __fastcall strtonum(char *nptr, __int64 a2, __int64 a3, char **a4)
{
int *v5; // rax
int v6; // er13
int *v7; // rbx
__int64 result; // rax

v5 = _errno_location();
v6 = *v5;
*v5 = 0;
v7 = v5;
result = strtoll(nptr, a4, 0);
if ( *v7 || *a4 == nptr || **a4 )
{
*a4 = "invalid";
}
else
{
*a4 = 0LL;
*v7 = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *nptr, __int64 a2, __int64 a3, char **a4)
{
int *v5; // rax
int v6; // er13
int *v7; // rbx
__int64 result; // rax

v5 = _errno_location();
v6 = *v5;
*v5 = 0;
v7 = v5;
result = strtoll(nptr, a4, 0);
if ( *v7 || *a4 == nptr || **a4 )
{
*a4 = "invalid";
}
else
{
*a4 = 0LL;
*v7 = v6;
}
return result;
}

original_code:
long long int
strtonum(const char *nptr, long long minval, long long maxval,
         const char **errstr)
{
        long long ret;
        int errno_c = (*__errno_location ());
        (*__errno_location ()) = 0;
        ret = strtoll(nptr, (char **)errstr, 0);
        if ((*__errno_location ()) != 0 || nptr == *errstr || **errstr != '\0')
                *errstr = "invalid";
        else {
                *errstr = ((void *)0);
                (*__errno_location ()) = errno_c;
        }
        return ret;
}

canonical_original_code:
long long strtonum(char *nptr, long long minval, long long maxval, char **errstr)
{
        long long ret;
        int errno_c = (*__errno_location ());
        (*__errno_location ()) = 0;
        ret = strtoll(nptr, (char **)errstr, 0);
        if ((*__errno_location ()) != 0 || nptr == *errstr || **errstr != '\0')
                *errstr = "invalid";
        else {
                *errstr = ((void *)0);
                (*__errno_location ()) = errno_c;
        }
        return ret;
}

variable_types:
nptr
char *

variable_types:
minval
long long

variable_types:
maxval
long long

variable_types:
errstr
char **

variable_types:
ret
long long

return_type: long long


ishexnumber

decompiled_code:
_BOOL8 __fastcall ishexnumber(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)(a1 - 48) > 9 )
result = (a1 & 0xFFFFFFDF) - 65 <= 5;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)(a1 - 48) > 9 )
result = (a1 & 0xFFFFFFDF) - 65 <= 5;
return result;
}

variable_types: c int


strlcpy

decompiled_code:
__int64 __fastcall strlcpy(_BYTE *a1, char *a2, __int64 a3)
{
char *v5; // rax
unsigned __int64 v6; // rdx
char v7; // cl

v5 = a2;
if ( !a3 )
{
do
{
LABEL_9:
if ( !*v5++ )
break;
++v5;
}
while ( *(v5 - 1) );
return v5 - a2 - 1;
}
if ( a3 == 1 )
{
LABEL_8:
*a1 = 0;
goto LABEL_9;
}
v6 = (unsigned __int64)a1;
while ( 1 )
{
v7 = *v5++;
*(_BYTE *)v6++ = v7;
if ( !v7 )
return v5 - a2 - 1;
if ( !&a1[a3 + ~v6] )
{
a1 = (_BYTE *)v6;
goto LABEL_8;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1, char *a2, __int64 a3)
{
char *v5; // rax
unsigned __int64 v6; // rdx
char v7; // cl

v5 = a2;
if ( !a3 )
{
do
{
LABEL_9:
if ( !*v5++ )
break;
++v5;
}
while ( *(v5 - 1) );
return v5 - a2 - 1;
}
if ( a3 == 1 )
{
LABEL_8:
*a1 = 0;
goto LABEL_9;
}
v6 = (unsigned __int64)a1;
while ( 1 )
{
v7 = *v5++;
*(_BYTE *)v6++ = v7;
if ( !v7 )
return v5 - a2 - 1;
if ( !&a1[a3 + ~v6] )
{
a1 = (_BYTE *)v6;
goto LABEL_8;
}
}
}

original_code:
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
        char *d = dst;
        const char *s = src;
        size_t n = siz;
        if (n != 0 && --n != 0) {
                do {
                        if ((*d++ = *s++) == 0)
                                break;
                } while (--n != 0);
        }
        if (n == 0) {
                if (siz != 0)
                        *d = '\0';
                while (*s++)
                        ;
        }
        return(s - src - 1);
}

canonical_original_code:
unsigned long strlcpy(char *dst, char *src, unsigned long siz)
{
        char *d = dst;
        char *s = src;
        unsigned long n = siz;
        if (n != 0 && --n != 0) {
                do {
                        if ((*d++ = *s++) == 0)
                                break;
                } while (--n != 0);
        }
        if (n == 0) {
                if (siz != 0)
                        *d = '\0';
                while (*s++)
                        ;
        }
        return(s - src - 1);
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
siz
unsigned long

variable_types:
d
char *

variable_types:
s
char *

variable_types:
n
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall getsockopt2(int fd, unsigned int a2, __int64 a3, void *a4, unsigned int *a5)
{
return _sockopt2(fd, a2, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, unsigned int a2, __int64 a3, void *a4, unsigned int *a5)
{
return func11(fd, a2, a3, a4, a5);
}

original_code:
int
getsockopt2(int s, int level, int optname, void *optval,
 socklen_t *optlen)
{
 return __sockopt2(s, level, optname, optval, optlen, SOPT_GET);
}

canonical_original_code:
int getsockopt2(int s, int level, int optname, void *optval, unsigned int *optlen)
{
 return __sockopt2(s, level, optname, optval, optlen, SOPT_GET);
}

variable_types: s int

variable_types: level int

variable_types: optname int

variable_types:
optval
void *

variable_types:
optlen
unsigned int *


decompiled_code:
__int64 __fastcall setsockopt2(int a1, unsigned int a2, __int64 a3, void *a4, unsigned int a5)
{
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a5;
return _sockopt2(a1, a2, a3, a4, v6);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, unsigned int a2, __int64 a3, void *a4, unsigned int a5)
{
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = a5;
return func11(a1, a2, a3, a4, v6);
}

original_code:
int
setsockopt2(int s, int level, int optname, void *optval,
 socklen_t optlen)
{
 return __sockopt2(s, level, optname, optval, &optlen, SOPT_SET);
}

canonical_original_code:
int setsockopt2(int s, int level, int optname, void *optval, unsigned int optlen)
{
 return __sockopt2(s, level, optname, optval, &optlen, SOPT_SET);
}

variable_types:
optlen
unsigned int