decompiled_code:
__int64 show_about()
{
wclear(stdscr);
wattr_on(stdscr, 0x100uLL, 0LL);
mvprintw(0, 0, "%s", doge_img);
wattr_off(stdscr, 0x100uLL, 0LL);
wattr_on(stdscr, 0x200100uLL, 0LL);
mvprintw(3, 70, "about");
wattr_off(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
mvprintw(5, 64, "made by Joe Jevnik");
mvprintw(6, 64, "2013, this program is");
mvprintw(7, 64, "free software, see");
mvprintw(8, 64, "LICENSE for more info");
mvprintw(0, mc - 28, "Press any key to continue...");
mvprintw(mr - 1, mc - 13, "by Joe Jevnik");
wrefresh(stdscr);
wgetch(stdscr);
return show_menu();
}

canonical_decompiled_code:
__int64 func3()
{
wclear(stdscr);
wattr_on(stdscr, 0x100uLL, 0LL);
mvprintw(0, 0, "%s", doge_img);
wattr_off(stdscr, 0x100uLL, 0LL);
wattr_on(stdscr, 0x200100uLL, 0LL);
mvprintw(3, 70, "about");
wattr_off(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x100uLL, 0LL);
mvprintw(5, 64, "made by Joe Jevnik");
mvprintw(6, 64, "2013, this program is");
mvprintw(7, 64, "free software, see");
mvprintw(8, 64, "LICENSE for more info");
mvprintw(0, mc - 28, "Press any key to continue...");
mvprintw(mr - 1, mc - 13, "by Joe Jevnik");
wrefresh(stdscr);
wgetch(stdscr);
return func0();
}


repo: llllllllll/dogeteachestyping

decompiled_code:
void __noreturn print_time()
{
int v0; // ebx
int v1; // ebp

while ( 1 )
{
if ( stdscr )
{
v0 = stdscr->_cury;
v1 = stdscr->_curx;
}
else
{
v0 = -1;
v1 = -1;
}
time(&time_ctr);
show_time();
wmove(stdscr, v0, v1);
wrefresh(stdscr);
sleep(1u);
}
}

canonical_decompiled_code:
void __noreturn func4()
{
int v0; // ebx
int v1; // ebp

while ( 1 )
{
if ( stdscr )
{
v0 = stdscr->_cury;
v1 = stdscr->_curx;
}
else
{
v0 = -1;
v1 = -1;
}
time(&time_ctr);
show_time();
wmove(stdscr, v0, v1);
wrefresh(stdscr);
sleep(1u);
}
}

original_code:
void print_time(void *id){
    int r,c;
    while (1){
 (r = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), c = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 time(&time_ctr);
        show_time();
 wmove(stdscr,(r),(c));
 wrefresh(stdscr);
 sleep(1);
    }
}

canonical_original_code:
void print_time(void *id){
    int r; int c;
    while (1){
 (r = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), c = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
 time(&time_ctr);
        show_time();
 wmove(stdscr,(r),(c));
 wrefresh(stdscr);
 sleep(1);
    }
}

variable_types:
id
void *

variable_types: r int

variable_types: c int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_create(&time_thread, 0LL, (void *(*)(void *))&print_time, 0LL);
init_menu();
return 0;
}

original_code:
int main(){
    pthread_create(&time_thread,((void *)0),print_time,((void *)0));
    init_menu();
    return 0;
}

return_type: int


decompiled_code:
char *get_corr_phrase()
{
return CORR_PHRASES[rand() % 11];
}

canonical_decompiled_code:
char *func0()
{
return CORR_PHRASES[rand() % 11];
}

original_code:
char *get_corr_phrase(){
    return CORR_PHRASES[rand() % 11];
}

return_type: char *


decompiled_code:
char *get_incorr_phrase()
{
return INCORR_PHRASES[rand() % 9];
}

canonical_decompiled_code:
char *func1()
{
return INCORR_PHRASES[rand() % 9];
}

original_code:
char *get_incorr_phrase(){
    return INCORR_PHRASES[rand() % 9];
}


decompiled_code:
__int64 play_word()
{
_QWORD *v0; // rbx
const char *v1; // r12
int v2; // ebp
int v4; // edi
int v5; // esi
int v6; // edx
__int64 v7; // rbx
int v8; // edx
char *v9; // rax
int v10; // eax
unsigned int v11; // ebx
char *v12; // rax

wmove(stdscr, 3, 60);
wclrtoeol(stdscr);
wmove(stdscr, 5, 60);
wclrtoeol(stdscr);
wmove(stdscr, 6, 60);
wclrtoeol(stdscr);
wmove(stdscr, 7, 60);
wclrtoeol(stdscr);
wmove(stdscr, 8, 60);
wclrtoeol(stdscr);
wmove(stdscr, 9, 60);
wclrtoeol(stdscr);
v0 = wordv;
v1 = (const char *)v0[rand() % wordc];
c = 0;
wattr_on(stdscr, 0x100uLL, 0LL);
mvprintw(mr - 1, mc - 13, "by Joe Jevnik");
mvprintw(7, 69, "words: %i", (unsigned int)sc);
mvprintw(8, 69, "errors: %i", (unsigned int)mis);
mvprintw(9, 69, "wps: %f", (double)sc / (double)((int)time_ctr - (int)s));
mvprintw(10, 69, "time: %i", time_ctr - s);
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(3, 69, "%s", v1);
mvprintw(5, 67, "> ");
wattr_off(stdscr, 0x200000uLL, 0LL);
curs_set(1);
if ( v1[c] != 10 )
{
v2 = 0;
while ( 1 )
{
v10 = wgetch(stdscr);
v11 = v10;
if ( v10 <= 19 )
{
if ( v10 > 1 )
{
switch ( v10 )
{
case 2:
goto LABEL_15;
case 3:
if ( wordc > 0 )
{
v7 = 0LL;
do
free(*((void **)wordv + v7++));
while ( wordc > (int)v7 );
}
free(wordv);
pthread_cancel(time_thread);
endwin();
exit(0);
case 6:
goto LABEL_29;
case 10:
goto LABEL_37;
case 19:
play_word();
goto LABEL_40;
default:
goto LABEL_40;
}
}
goto LABEL_40;
}
if ( v10 == 261 )
{
LABEL_29:
v8 = 0;
if ( stdscr )
v8 = stdscr->_curx + 1;
wmove(stdscr, 5, v8);
++v2;
goto LABEL_37;
}
if ( v10 > 261 )
break;
if ( v10 > 259 )
{
LABEL_15:
if ( v2 )
{
v6 = -2;
if ( stdscr )
v6 = stdscr->_curx - 1;
wmove(stdscr, 5, v6);
--v2;
}
goto LABEL_37;
}
if ( v10 <= 257 )
{
if ( v10 == 127 )
goto LABEL_22;
LABEL_40:
printw("%c", v11);
if ( v1[c] == v11 && c == v2 )
{
++c;
if ( (rand() & 1) != 0 )
{
mvprintw(20, 62, "________________");
mvprintw(21, 61, "/ \\");
mvprintw(22, 60, "< ");
wattr_on(stdscr, 0x200000uLL, 0LL);
v12 = get_corr_phrase();
printw("%-15s", v12);
wattr_off(stdscr, 0x200000uLL, 0LL);
printw(" |");
mvprintw(23, 61, "\\_________________/");
wmove(stdscr, 5, v2 + 70);
wrefresh(stdscr);
}
LABEL_36:
++v2;
goto LABEL_37;
}
LABEL_34:
mvprintw(8, 69, "errors: %i", (unsigned int)++mis);
wmove(stdscr, 5, v2 + 70);
if ( (rand() & 1) != 0 )
{
mvprintw(20, 62, "________________");
mvprintw(21, 61, "/ \\");
mvprintw(22, 60, "< ");
wattr_on(stdscr, 0x200000uLL, 0LL);
v9 = get_incorr_phrase();
printw("%-15s", v9);
wattr_off(stdscr, 0x200000uLL, 0LL);
printw(" |");
mvprintw(23, 61, "\\_________________/");
wmove(stdscr, 5, v2 + 70);
wrefresh(stdscr);
}
goto LABEL_36;
}
LABEL_37:
if ( v1[c] == 10 )
goto LABEL_3;
}
if ( v10 == 410 )
{
wmove(stdscr, mr - 1, mc - 13);
wclrtoeol(stdscr);
endwin();
if ( stdscr )
{
v4 = stdscr->_maxy + 1;
mr = v4;
v5 = stdscr->_maxx + 1;
}
else
{
mr = -1;
v4 = -1;
v5 = -1;
}
mc = v5;
mvprintw(v4 - 1, v5 - 13, "by Joe Jevnik");
wmove(stdscr, 5, 69);
wrefresh(stdscr);
goto LABEL_37;
}
if ( v10 <= 410 && (v10 == 263 || v10 == 330) )
{
LABEL_22:
if ( v2 )
{
--v2;
printw("\b \b");
}
goto LABEL_37;
}
printw("%c", (unsigned int)v10);
goto LABEL_34;
}
LABEL_3:
++sc;
return play_word();
}

canonical_decompiled_code:
__int64 func2()
{
_QWORD *v0; // rbx
const char *v1; // r12
int v2; // ebp
int v4; // edi
int v5; // esi
int v6; // edx
__int64 v7; // rbx
int v8; // edx
char *v9; // rax
int v10; // eax
unsigned int v11; // ebx
char *v12; // rax

wmove(stdscr, 3, 60);
wclrtoeol(stdscr);
wmove(stdscr, 5, 60);
wclrtoeol(stdscr);
wmove(stdscr, 6, 60);
wclrtoeol(stdscr);
wmove(stdscr, 7, 60);
wclrtoeol(stdscr);
wmove(stdscr, 8, 60);
wclrtoeol(stdscr);
wmove(stdscr, 9, 60);
wclrtoeol(stdscr);
v0 = wordv;
v1 = (const char *)v0[rand() % wordc];
c = 0;
wattr_on(stdscr, 0x100uLL, 0LL);
mvprintw(mr - 1, mc - 13, "by Joe Jevnik");
mvprintw(7, 69, "words: %i", (unsigned int)sc);
mvprintw(8, 69, "errors: %i", (unsigned int)mis);
mvprintw(9, 69, "wps: %f", (double)sc / (double)((int)time_ctr - (int)s));
mvprintw(10, 69, "time: %i", time_ctr - s);
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(3, 69, "%s", v1);
mvprintw(5, 67, "> ");
wattr_off(stdscr, 0x200000uLL, 0LL);
curs_set(1);
if ( v1[c] != 10 )
{
v2 = 0;
while ( 1 )
{
v10 = wgetch(stdscr);
v11 = v10;
if ( v10 <= 19 )
{
if ( v10 > 1 )
{
switch ( v10 )
{
case 2:
goto LABEL_15;
case 3:
if ( wordc > 0 )
{
v7 = 0LL;
do
free(*((void **)wordv + v7++));
while ( wordc > (int)v7 );
}
free(wordv);
pthread_cancel(time_thread);
endwin();
exit(0);
case 6:
goto LABEL_29;
case 10:
goto LABEL_37;
case 19:
func2();
goto LABEL_40;
default:
goto LABEL_40;
}
}
goto LABEL_40;
}
if ( v10 == 261 )
{
LABEL_29:
v8 = 0;
if ( stdscr )
v8 = stdscr->_curx + 1;
wmove(stdscr, 5, v8);
++v2;
goto LABEL_37;
}
if ( v10 > 261 )
break;
if ( v10 > 259 )
{
LABEL_15:
if ( v2 )
{
v6 = -2;
if ( stdscr )
v6 = stdscr->_curx - 1;
wmove(stdscr, 5, v6);
--v2;
}
goto LABEL_37;
}
if ( v10 <= 257 )
{
if ( v10 == 127 )
goto LABEL_22;
LABEL_40:
printw("%c", v11);
if ( v1[c] == v11 && c == v2 )
{
++c;
if ( (rand() & 1) != 0 )
{
mvprintw(20, 62, "________________");
mvprintw(21, 61, "/ \\");
mvprintw(22, 60, "< ");
wattr_on(stdscr, 0x200000uLL, 0LL);
v12 = func0();
printw("%-15s", v12);
wattr_off(stdscr, 0x200000uLL, 0LL);
printw(" |");
mvprintw(23, 61, "\\_________________/");
wmove(stdscr, 5, v2 + 70);
wrefresh(stdscr);
}
LABEL_36:
++v2;
goto LABEL_37;
}
LABEL_34:
mvprintw(8, 69, "errors: %i", (unsigned int)++mis);
wmove(stdscr, 5, v2 + 70);
if ( (rand() & 1) != 0 )
{
mvprintw(20, 62, "________________");
mvprintw(21, 61, "/ \\");
mvprintw(22, 60, "< ");
wattr_on(stdscr, 0x200000uLL, 0LL);
v9 = func1();
printw("%-15s", v9);
wattr_off(stdscr, 0x200000uLL, 0LL);
printw(" |");
mvprintw(23, 61, "\\_________________/");
wmove(stdscr, 5, v2 + 70);
wrefresh(stdscr);
}
goto LABEL_36;
}
LABEL_37:
if ( v1[c] == 10 )
goto LABEL_3;
}
if ( v10 == 410 )
{
wmove(stdscr, mr - 1, mc - 13);
wclrtoeol(stdscr);
endwin();
if ( stdscr )
{
v4 = stdscr->_maxy + 1;
mr = v4;
v5 = stdscr->_maxx + 1;
}
else
{
mr = -1;
v4 = -1;
v5 = -1;
}
mc = v5;
mvprintw(v4 - 1, v5 - 13, "by Joe Jevnik");
wmove(stdscr, 5, 69);
wrefresh(stdscr);
goto LABEL_37;
}
if ( v10 <= 410 && (v10 == 263 || v10 == 330) )
{
LABEL_22:
if ( v2 )
{
--v2;
printw("\b \b");
}
goto LABEL_37;
}
printw("%c", (unsigned int)v10);
goto LABEL_34;
}
LABEL_3:
++sc;
return func2();
}

original_code:
void play_word(){
    wmove(stdscr,(3),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(5),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(6),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(7),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(8),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(9),(60));
    wclrtoeol(stdscr);
    int in,col = 0;
    char *word = wordv[rand() % wordc];
    c = 0;
    wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    mvprintw(mr-1,mc-13,"by Joe Jevnik");
    mvprintw(7,69,"words:  %i",sc);
    mvprintw(8,69,"errors: %i",mis);
    mvprintw(9,69,"wps:    %f", (double) sc / (time_ctr - s));
    mvprintw(10,69,"time:   %i",time_ctr - s);
    wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
    mvprintw(3,69,"%s",word);
    mvprintw(5,67,"> ");
    wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
    curs_set(1);
    while(1){
 if (word[c] == '\n'){
     ++sc;
     play_word();
     break;
 }
 in = wgetch(stdscr);
 switch(in){
 case 3:
   for (int n = 0;n < wordc;n++){
       free(wordv[n]);
   }
   free(wordv);
   pthread_cancel(time_thread);
   endwin();
   exit(0);
   break;
 case 19:
   play_word();
   break;
 case 0632:
     wmove(stdscr,(mr-1),(mc-13));
     wclrtoeol(stdscr);
     endwin();
     (mr = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mc = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
     mvprintw(mr-1,mc-13,"by Joe Jevnik");
     wmove(stdscr,(5),(69));
     wrefresh(stdscr);
     continue;
     break;
 case 0403:
 case 0402:
 case 10:
     continue;
     break;
 case 0407:
 case 330:
 case 127:
     if (col == 0){
  continue;
     }
     --col;
     printw("\b \b");
     continue;
     break;
 case 6:
 case 0405:
     wmove(stdscr,(5),(((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1))+1));
     ++col;
     continue;
     break;
 case 2:
 case 0404:
     if (col == 0){
  continue;
     }
     wmove(stdscr,(5),(((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1))-1));
     --col;
     continue;
     break;
 }
 printw("%c",in);
 if (in == word[c] && col == c){
     ++c;
     if (rand() % 2){
  mvprintw(20,62,"________________");
  mvprintw(21,61,"/                \\");
  mvprintw(22,60,"<  ");
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw("%-15s",get_corr_phrase());
  wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw(" |");
  mvprintw(23,61,"\\_________________/");
  wmove(stdscr,(5),(col+70));
  wrefresh(stdscr);
     }
 } else {
     mvprintw(8,69,"errors: %i",++mis);
     wmove(stdscr,(5),(col+70));
     if (rand() % 2){
  mvprintw(20,62,"________________");
  mvprintw(21,61,"/                \\");
  mvprintw(22,60,"<  ");
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw("%-15s",get_incorr_phrase());
  wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw(" |");
  mvprintw(23,61,"\\_________________/");
  wmove(stdscr,(5),(col+70));
  wrefresh(stdscr);
     }
 }
 ++col;
    }
}

canonical_original_code:
void play_word(){
    wmove(stdscr,(3),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(5),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(6),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(7),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(8),(60));
    wclrtoeol(stdscr);
    wmove(stdscr,(9),(60));
    wclrtoeol(stdscr);
    int in; int col = 0;
    char *word = wordv[rand() % wordc];
    c = 0;
    wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
    mvprintw(mr-1,mc-13,"by Joe Jevnik");
    mvprintw(7,69,"words:  %i",sc);
    mvprintw(8,69,"errors: %i",mis);
    mvprintw(9,69,"wps:    %f", (double) sc / (time_ctr - s));
    mvprintw(10,69,"time:   %i",time_ctr - s);
    wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
    mvprintw(3,69,"%s",word);
    mvprintw(5,67,"> ");
    wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
    curs_set(1);
    while(1){
 if (word[c] == '\n'){
     ++sc;
     play_word();
     break;
 }
 in = wgetch(stdscr);
 switch(in){
 case 3:
   for (int n = 0;n < wordc;n++){
       free(wordv[n]);
   }
   free(wordv);
   pthread_cancel(time_thread);
   endwin();
   exit(0);
   break;
 case 19:
   play_word();
   break;
 case 0632:
     wmove(stdscr,(mr-1),(mc-13));
     wclrtoeol(stdscr);
     endwin();
     (mr = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), mc = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
     mvprintw(mr-1,mc-13,"by Joe Jevnik");
     wmove(stdscr,(5),(69));
     wrefresh(stdscr);
     continue;
     break;
 case 0403:
 case 0402:
 case 10:
     continue;
     break;
 case 0407:
 case 330:
 case 127:
     if (col == 0){
  continue;
     }
     --col;
     printw("\b \b");
     continue;
     break;
 case 6:
 case 0405:
     wmove(stdscr,(5),(((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1))+1));
     ++col;
     continue;
     break;
 case 2:
 case 0404:
     if (col == 0){
  continue;
     }
     wmove(stdscr,(5),(((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1))-1));
     --col;
     continue;
     break;
 }
 printw("%c",in);
 if (in == word[c] && col == c){
     ++c;
     if (rand() % 2){
  mvprintw(20,62,"________________");
  mvprintw(21,61,"/                \\");
  mvprintw(22,60,"<  ");
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw("%-15s",get_corr_phrase());
  wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw(" |");
  mvprintw(23,61,"\\_________________/");
  wmove(stdscr,(5),(col+70));
  wrefresh(stdscr);
     }
 } else {
     mvprintw(8,69,"errors: %i",++mis);
     wmove(stdscr,(5),(col+70));
     if (rand() % 2){
  mvprintw(20,62,"________________");
  mvprintw(21,61,"/                \\");
  mvprintw(22,60,"<  ");
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw("%-15s",get_incorr_phrase());
  wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  printw(" |");
  mvprintw(23,61,"\\_________________/");
  wmove(stdscr,(5),(col+70));
  wrefresh(stdscr);
     }
 }
 ++col;
    }
}

variable_types: in int

variable_types: col int

variable_types:
word
char *

variable_types: n int


decompiled_code:
int show_time()
{
int result; // eax

if ( not_playing )
wattr_on(stdscr, 0x800000uLL, 0LL);
wmove(stdscr, 9, 69);
wclrtoeol(stdscr);
wmove(stdscr, 10, 69);
wclrtoeol(stdscr);
mvprintw(9, 69, "wps: %f", (double)sc / (double)((int)time_ctr - (int)s));
result = mvprintw(10, 69, "time: %i", time_ctr - s);
if ( not_playing )
result = wattr_off(stdscr, 0x800000uLL, 0LL);
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

if ( not_playing )
wattr_on(stdscr, 0x800000uLL, 0LL);
wmove(stdscr, 9, 69);
wclrtoeol(stdscr);
wmove(stdscr, 10, 69);
wclrtoeol(stdscr);
mvprintw(9, 69, "wps: %f", (double)sc / (double)((int)time_ctr - (int)s));
result = mvprintw(10, 69, "time: %i", time_ctr - s);
if ( not_playing )
result = wattr_off(stdscr, 0x800000uLL, 0LL);
return result;
}

original_code:
void show_time(){
    if (not_playing){
 wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((15) + 8)))), ((void *)0));
    }
    wmove(stdscr,(9),(69));
    wclrtoeol(stdscr);
    wmove(stdscr,(10),(69));
    wclrtoeol(stdscr);
    mvprintw(9,69,"wps:    %f", (double) sc / (time_ctr - s));
    mvprintw(10,69,"time:   %i",time_ctr - s);
    if (not_playing){
 wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((15) + 8)))), ((void *)0));
    }
}


repo: llongi/rig

decompiled_code:
int constructor1()
{
return puts("constructor 1 called!");
}

canonical_decompiled_code:
int func6()
{
return puts("constructor 1 called!");
}

original_code:
static void constructor1(void) {
 printf("constructor 1 called!\n");
}

canonical_original_code:
static void constructor1() {
 printf("constructor 1 called!\n");
}


decompiled_code:
int destructor1()
{
return puts("destructor 1 called!");
}

canonical_decompiled_code:
int func7()
{
return puts("destructor 1 called!");
}

original_code:
static void destructor1(void) {
 printf("destructor 1 called!\n");
}

canonical_original_code:
static void destructor1() {
 printf("destructor 1 called!\n");
}


decompiled_code:
int constructor2()
{
return puts("constructor 2 called!");
}

canonical_decompiled_code:
int func8()
{
return puts("constructor 2 called!");
}

original_code:
static void constructor2(void) {
 printf("constructor 2 called!\n");
}

canonical_original_code:
static void constructor2() {
 printf("constructor 2 called!\n");
}


decompiled_code:
int destructor2()
{
return puts("destructor 2 called!");
}

canonical_decompiled_code:
int func9()
{
return puts("destructor 2 called!");
}

original_code:
static void destructor2(void) {
 printf("destructor 2 called!\n");
}

canonical_original_code:
static void destructor2() {
 printf("destructor 2 called!\n");
}


foo

decompiled_code:
__int64 foo()
{
puts("foo was called!");
return 1234LL;
}

canonical_decompiled_code:
__int64 func10()
{
puts("foo was called!");
return 1234LL;
}

original_code:
int foo(void) {
 printf("foo was called!\n");
 return (1234);
}

canonical_original_code:
int foo() {
 printf("foo was called!\n");
 return (1234);
}


decompiled_code:
void *__fastcall thr_func(void *a1)
{
unsigned int v1; // eax

v1 = rand() % 1000;
__writefsdword(0xFFFFFFFC, v1);
printf("thi is in thread: %i\n", v1);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
unsigned int v1; // eax

v1 = rand() % 1000;
__writefsdword(0xFFFFFFFC, v1);
printf("thi is in thread: %i\n", v1);
return 0LL;
}

original_code:
void *thr_func(void *arg) {
 thi = rand() % 1000;
 printf("thi is in thread: %i\n", thi);
 return (((void *)0));
}

variable_types:
arg
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
pthread_t *v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-38h] BYREF
char v7[24]; // [rsp+20h] [rbp-18h] BYREF

LODWORD(argv) = __readfsdword(0xFFFFFFFC);
printf("thi is in main: %i\n", argv);
v3 = (pthread_t *)v6;
v4 = (pthread_t *)v6;
do
pthread_create(v4++, 0LL, thr_func, 0LL);
while ( v4 != (pthread_t *)v7 );
do
pthread_join(*v3++, 0LL);
while ( v3 != (pthread_t *)v7 );
printf("thi is in main: %i\n", __readfsdword(0xFFFFFFFC));
return 0;
}

original_code:
int main(void) {
 printf("thi is in main: %i\n", thi);
 pthread_t threads[4];
 for (size_t i = 0; i < 4; i++)
  pthread_create(&threads[i], ((void *)0), &thr_func, ((void *)0));
 for (size_t i = 0; i < 4; i++)
  pthread_join(threads[i], ((void *)0));
 printf("thi is in main: %i\n", thi);
 return (0);
}

canonical_original_code:
int main() {
 printf("thi is in main: %i\n", thi);
 unsigned long threads[4];
 for (unsigned long i = 0; i < 4; i++)
  pthread_create(&threads[i], ((void *)0), &thr_func, ((void *)0));
 for (unsigned long i = 0; i < 4; i++)
  pthread_join(threads[i], ((void *)0));
 printf("thi is in main: %i\n", thi);
 return (0);
}

variable_types:
threads
unsigned long [4]

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall tts_comparer(const void *a1, const void *a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
__int64 result; // rax

v2 = *(double *)(tts_ptr + 8LL * *(_QWORD *)a1);
v3 = *(double *)(tts_ptr + 8LL * *(_QWORD *)a2);
result = 1LL;
if ( v2 <= v3 )
result = (unsigned int)-(v3 > v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
double v2; // xmm0_8
double v3; // xmm1_8
__int64 result; // rax

v2 = *(double *)(tts_ptr + 8LL * *(_QWORD *)a1);
v3 = *(double *)(tts_ptr + 8LL * *(_QWORD *)a2);
result = 1LL;
if ( v2 <= v3 )
result = (unsigned int)-(v3 > v2);
return result;
}

original_code:
static int tts_comparer(const void *a, const void *b) {
 size_t ax = (*((size_t *)a));
 size_t bx = (*((size_t *)b));
 int ret;
 if (tts_ptr[ax] > tts_ptr[bx]) {
  ret = 1;
 }
 else if (tts_ptr[ax] < tts_ptr[bx]) {
  ret = -1;
 }
 else {
  ret = 0;
 }
 return (ret);
}

canonical_original_code:
static int tts_comparer(void *a, void *b) {
 unsigned long ax = (*((size_t *)a));
 unsigned long bx = (*((size_t *)b));
 int ret;
 if (tts_ptr[ax] > tts_ptr[bx]) {
  ret = 1;
 }
 else if (tts_ptr[ax] < tts_ptr[bx]) {
  ret = -1;
 }
 else {
  ret = 0;
 }
 return (ret);
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
ax
unsigned long

variable_types:
bx
unsigned long

variable_types: ret int


repo: llostris/mikro

original_code:
void parse_tcp(union ethframe* frame, struct tcp_header* hdr) {
 memcpy(hdr, frame->field.data + 40, 20);
 hdr->source_port = ( ((((unsigned short)(hdr->source_port) & 0xFF)) << 8) | (((unsigned short)(hdr->source_port) & 0xFF00) >> 8));
 hdr->destination_port = ( ((((unsigned short)(hdr->destination_port) & 0xFF)) << 8) | (((unsigned short)(hdr->destination_port) & 0xFF00) >> 8));
 hdr->sequence_number = ntohl(hdr->sequence_number);
 hdr->acknowledgement_number = ntohl(hdr->acknowledgement_number);
 hdr->window_size = ( ((((unsigned short)(hdr->window_size) & 0xFF)) << 8) | (((unsigned short)(hdr->window_size) & 0xFF00) >> 8));
 hdr->urgent_pointer = ( ((((unsigned short)(hdr->urgent_pointer) & 0xFF)) << 8) | (((unsigned short)(hdr->urgent_pointer) & 0xFF00) >> 8));
}

canonical_original_code:
void parse_tcp(union ethframe *frame, struct tcp_header *hdr) {
 memcpy(hdr, frame->field.data + 40, 20);
 hdr->source_port = ( ((((unsigned short)(hdr->source_port) & 0xFF)) << 8) | (((unsigned short)(hdr->source_port) & 0xFF00) >> 8));
 hdr->destination_port = ( ((((unsigned short)(hdr->destination_port) & 0xFF)) << 8) | (((unsigned short)(hdr->destination_port) & 0xFF00) >> 8));
 hdr->sequence_number = ntohl(hdr->sequence_number);
 hdr->acknowledgement_number = ntohl(hdr->acknowledgement_number);
 hdr->window_size = ( ((((unsigned short)(hdr->window_size) & 0xFF)) << 8) | (((unsigned short)(hdr->window_size) & 0xFF00) >> 8));
 hdr->urgent_pointer = ( ((((unsigned short)(hdr->urgent_pointer) & 0xFF)) << 8) | (((unsigned short)(hdr->urgent_pointer) & 0xFF00) >> 8));
}

variable_types: union ethframe { struct { struct ethhdr { unsigned char dest[6]; unsigned char src[6]; unsigned short proto; } header; unsigned char data[1500]; } field; unsigned char buffer[1514]; } *

variable_types: struct tcp_header { unsigned short source_port; unsigned short destination_port; unsigned int sequence_number; unsigned int acknowledgement_number; unsigned short reserved; unsigned short window_size; unsigned short checksum; unsigned short urgent_pointer; } *

user_defined_types: union ethframe { struct { struct ethhdr header; unsigned char data[1500]; } field; unsigned char buffer[1514]; }


original_code:
void create_tcp_hdr(struct tcp_header* hdr, int dest_port, int flags, int ack_num, int seq_num, int window_size, int data_offset) {
 hdr->source_port = ( ((((unsigned short)(80) & 0xFF)) << 8) | (((unsigned short)(80) & 0xFF00) >> 8));
 hdr->destination_port = ( ((((unsigned short)(dest_port) & 0xFF)) << 8) | (((unsigned short)(dest_port) & 0xFF00) >> 8));
 hdr->sequence_number = htonl(seq_num);
 hdr->acknowledgement_number = htonl(ack_num);
 hdr->data_offset = data_offset;
 hdr->reserved = 0;
 hdr->flags = flags;
 hdr->window_size = ( ((((unsigned short)(window_size) & 0xFF)) << 8) | (((unsigned short)(window_size) & 0xFF00) >> 8));
 hdr->checksum = 0;
 hdr->urgent_pointer = 0;
}

canonical_original_code:
void create_tcp_hdr(struct tcp_header *hdr, int dest_port, int flags, int ack_num, int seq_num, int window_size, int data_offset) {
 hdr->source_port = ( ((((unsigned short)(80) & 0xFF)) << 8) | (((unsigned short)(80) & 0xFF00) >> 8));
 hdr->destination_port = ( ((((unsigned short)(dest_port) & 0xFF)) << 8) | (((unsigned short)(dest_port) & 0xFF00) >> 8));
 hdr->sequence_number = htonl(seq_num);
 hdr->acknowledgement_number = htonl(ack_num);
 hdr->data_offset = data_offset;
 hdr->reserved = 0;
 hdr->flags = flags;
 hdr->window_size = ( ((((unsigned short)(window_size) & 0xFF)) << 8) | (((unsigned short)(window_size) & 0xFF00) >> 8));
 hdr->checksum = 0;
 hdr->urgent_pointer = 0;
}

variable_types: flags int

user_defined_types: struct tcp_header { unsigned short source_port; unsigned short destination_port; unsigned int sequence_number; unsigned int acknowledgement_number; unsigned short reserved; unsigned short window_size; unsigned short checksum; unsigned short urgent_pointer; }


original_code:
void reply_tcp(union ethframe* frame, struct tcp_header* tcphdr) {
 void* buffer = (void*) malloc(100);
 memcpy(buffer, frame->field.header.dest, 6);
 memcpy(frame->field.header.dest, frame->field.header.src, 6);
 memcpy(frame->field.header.src, buffer, 6);
 struct ip6_hdr* iphdr;
 iphdr = (struct ip6_hdr*) frame->field.data;
 memcpy(buffer, iphdr->destination_address, 2 * 8);
 memcpy(iphdr->destination_address, iphdr->source_address, 2 * 8);
 memcpy(iphdr->source_address, buffer, 2 * 8);
 memcpy(frame->field.data + 40, tcphdr, 20);
 tcphdr = (struct tcp_header*) (frame->field.data + 40);
 tcphdr->checksum = checksum_pseudo(tcphdr, iphdr->source_address, iphdr->destination_address, 6, ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
 free(buffer);
}

canonical_original_code:
void reply_tcp(union ethframe *frame, struct tcp_header *tcphdr) {
 void *buffer = (void*) malloc(100);
 memcpy(buffer, frame->field.header.dest, 6);
 memcpy(frame->field.header.dest, frame->field.header.src, 6);
 memcpy(frame->field.header.src, buffer, 6);
 struct ip6_hdr *iphdr;
 iphdr = (struct ip6_hdr *) frame->field.data;
 memcpy(buffer, iphdr->destination_address, 2 * 8);
 memcpy(iphdr->destination_address, iphdr->source_address, 2 * 8);
 memcpy(iphdr->source_address, buffer, 2 * 8);
 memcpy(frame->field.data + 40, tcphdr, 20);
 tcphdr = (struct tcp_header *) (frame->field.data + 40);
 tcphdr->checksum = checksum_pseudo(tcphdr, iphdr->source_address, iphdr->destination_address, 6, ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
 free(buffer);
}

variable_types:
buffer
void *

variable_types: struct ip6_hdr { unsigned int traffic_class1; unsigned short payload_len; unsigned char next_hdr; unsigned char hop_limit; unsigned short source_address[8]; unsigned short destination_address[8]; } *

user_defined_types: struct ethhdr { unsigned char dest[6]; unsigned char src[6]; unsigned short proto; }


decompiled_code:
char *__fastcall add_http(__int64 a1, const char *a2, int a3)
{
return strncpy((char *)(a1 + 74), a2, a3);
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, const char *a2, int a3)
{
return strncpy((char *)(a1 + 74), a2, a3);
}

original_code:
void add_http(union ethframe* frame, char* file, int file_len) {
 unsigned char* tmp;
 tmp = (unsigned char*) (frame->field.data + 40 + 20);
 strncpy(tmp, file, file_len);
}

canonical_original_code:
void add_http(union ethframe *frame, char *file, int file_len) {
 unsigned char *tmp;
 tmp = (unsigned char *) (frame->field.data + 40 + 20);
 strncpy(tmp, file, file_len);
}

variable_types:
file
char *

variable_types:
tmp
unsigned char *


decompiled_code:
void __fastcall tcp_actions(__int64 a1, __int64 a2)
{
unsigned int v2; // eax
char v3; // al
unsigned __int8 v4; // r12
__int16 v5; // r13
int v6; // eax
_DWORD *v7; // r13
void *v8; // r12
size_t v9; // rax
int v10; // eax
__m128i v11[4]; // [rsp+0h] [rbp-48h] BYREF

puts("\n****** TCP ACTIONS *******");
v2 = time(0LL);
srand(v2);
v3 = *(_BYTE *)(a2 + 13);
switch ( v3 )
{
case 2:
puts("\n---- SENDING TCP SYN-ACK ----");
v4 = *(_BYTE *)(a2 + 12) >> 4;
v5 = *(_WORD *)(a2 + 14);
v6 = rand();
create_tcp_hdr((__int64)v11, *(_WORD *)a2, 18, *(_DWORD *)(a2 + 4) + 1, 24000 * v6, v5, v4);
reply_tcp((int *)a1, v11);
send_frame(
a1,
((unsigned __int8)HIBYTE(*(_WORD *)(a1 + 18)) | (unsigned int)(unsigned __int16)(*(_WORD *)(a1 + 18) << 8)) + 54);
break;
case 24:
if ( (unsigned int)is_httpget(a1 + 74) != -1 )
{
puts("\n------ HTTP GET ------");
v7 = malloc(0x12CuLL);
v8 = malloc(0x190uLL);
memset(v7, 0, 0x128uLL);
v7[74] = 0;
memset(v8, 0, 0x190uLL);
choose_file(a1 + 74, v7);
v9 = strlen((const char *)v7);
sprintf(
(char *)v8,
"HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s",
v9,
(const char *)v7);
create_tcp_hdr(
(__int64)v11,
*(_WORD *)a2,
24,
*(_DWORD *)(a2 + 4) + 1,
*(_DWORD *)(a2 + 8),
*(_WORD *)(a2 + 14),
*(_BYTE *)(a2 + 12) >> 4);
*(_WORD *)(a1 + 18) = __ROL2__(strlen((const char *)v8) + 20, 8);
v10 = strlen((const char *)v8);
add_http(a1, (const char *)v8, v10);
reply_tcp((int *)a1, v11);
send_frame(
a1,
((unsigned __int8)HIBYTE(*(_WORD *)(a1 + 18)) | (unsigned int)(unsigned __int16)(*(_WORD *)(a1 + 18) << 8))
+ 54);
free(v7);
free(v8);
}
break;
case 1:
create_tcp_hdr(
a1 + 54,
*(_WORD *)(a1 + 54),
17,
*(_DWORD *)(a1 + 58) + 1,
*(_DWORD *)(a1 + 62),
*(_WORD *)(a1 + 68),
*(_BYTE *)(a1 + 66) >> 4);
reply_tcp((int *)a1, (const __m128i *)(a1 + 54));
send_frame(
a1,
((unsigned __int8)HIBYTE(*(_WORD *)(a1 + 18)) | (unsigned int)(unsigned __int16)(*(_WORD *)(a1 + 18) << 8)) + 54);
break;
}
}

original_code:
void tcp_actions(union ethframe* frame, struct tcp_header* hdr) {
 printf("\n****** TCP ACTIONS *******\n");
 srand(time(((void *)0)));
 switch ( hdr->flags ) {
  case 2 : {
   printf("\n---- SENDING TCP SYN-ACK ----\n");
   struct tcp_header response_tcp;
   create_tcp_hdr(&response_tcp, hdr->source_port, 2 + 16, hdr->sequence_number + 1, rand() * 24000, hdr->window_size, hdr->data_offset);
   reply_tcp(frame, &response_tcp);
   struct ip6_hdr* iphdr;
   iphdr = (struct ip6_hdr*) frame->field.data;
   hdr = (struct tcp_header*) (frame->field.data + 40);
   send_frame(frame, 14 + 40 + ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
   break;
  }
  case 24 : {
   unsigned char* request;
   request = (unsigned char*) (frame->field.data + 40 + 20);
   if ( is_httpget(request) == -1 )
    break;
   printf("\n------ HTTP GET ------\n");
   unsigned char* file = malloc(300);
   unsigned char* response = malloc(400);
   memset(file, 0, 300);
   memset(response, 0, 400);
   choose_file(request, file);
   sprintf(response, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s", strlen(file), file);
   struct tcp_header response_tcp;
   create_tcp_hdr(&response_tcp, hdr->source_port, 8 + 16, hdr->sequence_number + 1, hdr->acknowledgement_number, hdr->window_size, hdr->data_offset);
   struct ip6_hdr* iphdr;
   iphdr = (struct ip6_hdr*) frame->field.data;
   iphdr->payload_len = ( ((((unsigned short)(20 + strlen(response)) & 0xFF)) << 8) | (((unsigned short)(20 + strlen(response)) & 0xFF00) >> 8));
   add_http(frame, response, strlen(response));
   reply_tcp(frame, &response_tcp);
   send_frame(frame, 14 + 40 + ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
   free(file);
   free(response);
   break;
  }
  case 1 : {
   struct ip6_hdr* iphdr;
   iphdr = (struct ip6_hdr*) frame->field.data;
   iphdr->payload_len = iphdr->payload_len;
   struct tcp_header* hdr;
   hdr = (struct tcp_header*) (frame->field.data + 40);
   create_tcp_hdr(hdr, hdr->source_port, 1 + 16, hdr->sequence_number + 1, hdr->acknowledgement_number, hdr->window_size, hdr->data_offset);
   reply_tcp(frame, hdr);
   send_frame(frame, 14 + 40 + ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
  }
  default : break;
 }
}

canonical_original_code:
void tcp_actions(union ethframe *frame, struct tcp_header *hdr) {
 printf("\n****** TCP ACTIONS *******\n");
 srand(time(((void *)0)));
 switch ( hdr->flags ) {
  case 2 : {
   printf("\n---- SENDING TCP SYN-ACK ----\n");
   struct tcp_header response_tcp;
   create_tcp_hdr(&response_tcp, hdr->source_port, 2 + 16, hdr->sequence_number + 1, rand() * 24000, hdr->window_size, hdr->data_offset);
   reply_tcp(frame, &response_tcp);
   struct ip6_hdr *iphdr;
   iphdr = (struct ip6_hdr *) frame->field.data;
   hdr = (struct tcp_header *) (frame->field.data + 40);
   send_frame(frame, 14 + 40 + ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
   break;
  }
  case 24 : {
   unsigned char *request;
   request = (unsigned char *) (frame->field.data + 40 + 20);
   if ( is_httpget(request) == -1 )
    break;
   printf("\n------ HTTP GET ------\n");
   unsigned char *file = malloc(300);
   unsigned char *response = malloc(400);
   memset(file, 0, 300);
   memset(response, 0, 400);
   choose_file(request, file);
   sprintf(response, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n%s", strlen(file), file);
   struct tcp_header response_tcp;
   create_tcp_hdr(&response_tcp, hdr->source_port, 8 + 16, hdr->sequence_number + 1, hdr->acknowledgement_number, hdr->window_size, hdr->data_offset);
   struct ip6_hdr *iphdr;
   iphdr = (struct ip6_hdr *) frame->field.data;
   iphdr->payload_len = ( ((((unsigned short)(20 + strlen(response)) & 0xFF)) << 8) | (((unsigned short)(20 + strlen(response)) & 0xFF00) >> 8));
   add_http(frame, response, strlen(response));
   reply_tcp(frame, &response_tcp);
   send_frame(frame, 14 + 40 + ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
   free(file);
   free(response);
   break;
  }
  case 1 : {
   struct ip6_hdr *iphdr;
   iphdr = (struct ip6_hdr *) frame->field.data;
   iphdr->payload_len = iphdr->payload_len;
   struct tcp_header *hdr;
   hdr = (struct tcp_header *) (frame->field.data + 40);
   create_tcp_hdr(hdr, hdr->source_port, 1 + 16, hdr->sequence_number + 1, hdr->acknowledgement_number, hdr->window_size, hdr->data_offset);
   reply_tcp(frame, hdr);
   send_frame(frame, 14 + 40 + ( ((((unsigned short)(iphdr->payload_len) & 0xFF)) << 8) | (((unsigned short)(iphdr->payload_len) & 0xFF00) >> 8)));
  }
  default : break;
 }
}

variable_types: struct tcp_header { unsigned short source_port; unsigned short destination_port; unsigned int sequence_number; unsigned int acknowledgement_number; unsigned short reserved; unsigned short window_size; unsigned short checksum; unsigned short urgent_pointer; }

variable_types:
request
unsigned char *

variable_types:
file
unsigned char *

variable_types:
response
unsigned char *

user_defined_types: struct ip6_hdr { unsigned int traffic_class1; unsigned short payload_len; unsigned char next_hdr; unsigned char hop_limit; unsigned short source_address[8]; unsigned short destination_address[8]; }


finalize

original_code:
void finalize(union ethframe* frame) {
 struct ip6_hdr* iphdr;
 iphdr = (struct ip6_hdr*) frame->field.data;
 iphdr->payload_len = ( ((((unsigned short)(20) & 0xFF)) << 8) | (((unsigned short)(20) & 0xFF00) >> 8));
 struct tcp_header* oldtcp;
 oldtcp = (struct tcp_header*) (frame->field.data + 40);
 oldtcp->checksum = 0;
 oldtcp->flags = 1;
 oldtcp->acknowledgement_number = 0;
 oldtcp->checksum = checksum_pseudo(oldtcp, iphdr->source_address, iphdr->destination_address, 6, 20);
 send_frame(frame, 14 + 40 + 20);
}

canonical_original_code:
void finalize(union ethframe *frame) {
 struct ip6_hdr *iphdr;
 iphdr = (struct ip6_hdr *) frame->field.data;
 iphdr->payload_len = ( ((((unsigned short)(20) & 0xFF)) << 8) | (((unsigned short)(20) & 0xFF00) >> 8));
 struct tcp_header *oldtcp;
 oldtcp = (struct tcp_header *) (frame->field.data + 40);
 oldtcp->checksum = 0;
 oldtcp->flags = 1;
 oldtcp->acknowledgement_number = 0;
 oldtcp->checksum = checksum_pseudo(oldtcp, iphdr->source_address, iphdr->destination_address, 6, 20);
 send_frame(frame, 14 + 40 + 20);
}


decompiled_code:
__int64 parsed_ipv6()
{
return parse_ipv6();
}

canonical_decompiled_code:
__int64 func0()
{
return parse_ipv6();
}

original_code:
int parsed_ipv6(union ethframe* frame, struct ip6_hdr* iphdr) {
 parse_ipv6(frame, iphdr);
 struct ip6_hdr_be hdr;
 memcpy(&hdr, frame->field.data, 40);
}

canonical_original_code:
int parsed_ipv6(union ethframe *frame, struct ip6_hdr *iphdr) {
 parse_ipv6(frame, iphdr);
 struct ip6_hdr_be hdr;
 memcpy(&hdr, frame->field.data, 40);
}

variable_types: struct ip6_hdr_be { unsigned int version; unsigned short payload_len; unsigned char next_hdr; unsigned char hop_limit; unsigned short source_address[8]; unsigned short destination_address[8]; }


decompiled_code:
int __fastcall parsed_icmp(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
int result; // eax

parse_icmp();
printf("\nType: %d\n", *a2);
printf("Code: %d\n", a2[1]);
printf("Checksum: %x\n", *((unsigned __int16 *)a2 + 1));
printf("Reserved: %d\n", a2[4]);
printf("Address:");
v2 = a2 + 8;
do
result = printf("%x ", *v2++);
while ( v2 != a2 + 24 );
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
int result; // eax

parse_icmp();
printf("\nType: %d\n", *a2);
printf("Code: %d\n", a2[1]);
printf("Checksum: %x\n", *((unsigned __int16 *)a2 + 1));
printf("Reserved: %d\n", a2[4]);
printf("Address:");
v2 = a2 + 8;
do
result = printf("%x ", *v2++);
while ( v2 != a2 + 24 );
return result;
}

original_code:
int parsed_icmp(union ethframe* frame, struct icmp6_hdr* hdr) {
 parse_icmp(frame, hdr);
 printf("\nType: %d\n", hdr->type);
 printf("Code: %d\n", hdr->code);
 printf("Checksum: %x\n", hdr->checksum);
 printf("Reserved: %d\n", hdr->data[0]);
 printf("Address:");
 int ind;
 for ( ind = 4; ind < 4 + 16; ind++ )
  printf("%x ", hdr->data[ind]);
}

canonical_original_code:
int parsed_icmp(union ethframe *frame, struct icmp6_hdr *hdr) {
 parse_icmp(frame, hdr);
 printf("\nType: %d\n", hdr->type);
 printf("Code: %d\n", hdr->code);
 printf("Checksum: %x\n", hdr->checksum);
 printf("Reserved: %d\n", hdr->data[0]);
 printf("Address:");
 int ind;
 for ( ind = 4; ind < 4 + 16; ind++ )
  printf("%x ", hdr->data[ind]);
}

variable_types: struct icmp6_hdr { unsigned char type; unsigned char code; unsigned short checksum; unsigned char data[-1]; } *

variable_types: ind int


decompiled_code:
int __fastcall parsed_tcp(__int64 a1, unsigned __int16 *a2)
{
parse_tcp();
printf("\nSource port: %d\n", *a2);
printf("Destination port: %d\n", a2[1]);
printf("Sequence number: %u\n", *((unsigned int *)a2 + 1));
printf("Acknowledgement number: %u\n", *((unsigned int *)a2 + 2));
printf("Flags: %d\n", *((unsigned __int8 *)a2 + 13));
printf("Data offset: %d\n", *((_BYTE *)a2 + 12) >> 4);
printf("Window size: %d\n", a2[7]);
printf("Checksum: %x\n", a2[8]);
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, unsigned __int16 *a2)
{
parse_tcp();
printf("\nSource port: %d\n", *a2);
printf("Destination port: %d\n", a2[1]);
printf("Sequence number: %u\n", *((unsigned int *)a2 + 1));
printf("Acknowledgement number: %u\n", *((unsigned int *)a2 + 2));
printf("Flags: %d\n", *((unsigned __int8 *)a2 + 13));
printf("Data offset: %d\n", *((_BYTE *)a2 + 12) >> 4);
printf("Window size: %d\n", a2[7]);
printf("Checksum: %x\n", a2[8]);
return puts("\n");
}

original_code:
int parsed_tcp(union ethframe* frame, struct tcp_header* hdr) {
 parse_tcp(frame, hdr);
 printf("\nSource port: %d\n", hdr->source_port);
 printf("Destination port: %d\n", hdr->destination_port);
 printf("Sequence number: %u\n", hdr->sequence_number);
 printf("Acknowledgement number: %u\n", hdr->acknowledgement_number);
 printf("Flags: %d\n", hdr->flags);
 printf("Data offset: %d\n", hdr->data_offset);
 printf("Window size: %d\n", hdr->window_size);
 printf("Checksum: %x\n", hdr->checksum);
 printf("\n\n");
}

canonical_original_code:
int parsed_tcp(union ethframe *frame, struct tcp_header *hdr) {
 parse_tcp(frame, hdr);
 printf("\nSource port: %d\n", hdr->source_port);
 printf("Destination port: %d\n", hdr->destination_port);
 printf("Sequence number: %u\n", hdr->sequence_number);
 printf("Acknowledgement number: %u\n", hdr->acknowledgement_number);
 printf("Flags: %d\n", hdr->flags);
 printf("Data offset: %d\n", hdr->data_offset);
 printf("Window size: %d\n", hdr->window_size);
 printf("Checksum: %x\n", hdr->checksum);
 printf("\n\n");
}


checksum

original_code:
unsigned short checksum(void* data, unsigned short length) {
 unsigned short *dataptr = data;
 long sum = 0;
 while (length > 1) {
  sum += *dataptr++;
  length -= 2;
 }
 if (length == 1) {
  sum += *(unsigned char *)dataptr;
 }
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 sum = ~sum;
 return sum;
}

canonical_original_code:
unsigned short checksum(void *data, unsigned short length) {
 unsigned short *dataptr = data;
 long sum = 0;
 while (length > 1) {
  sum += *dataptr++;
  length -= 2;
 }
 if (length == 1) {
  sum += *(unsigned char *)dataptr;
 }
 sum = (sum >> 16) + (sum & 0xffff);
 sum += (sum >> 16);
 sum = ~sum;
 return sum;
}

variable_types:
data
void *

variable_types:
length
unsigned short

variable_types:
dataptr
unsigned short *

variable_types: sum long

return_type: unsigned short


decompiled_code:
__int64 __fastcall checksum_pseudo(__int64 a1, const __m128i *a2, const __m128i *a3, char a4, unsigned int a5)
{
unsigned __int16 v8; // r12
size_t v9; // rdx
void *v10; // rsp
_OWORD v12[2]; // [rsp+0h] [rbp-40h] BYREF
unsigned int v13; // [rsp+23h] [rbp-1Dh]
char v14; // [rsp+27h] [rbp-19h]
char dest[24]; // [rsp+28h] [rbp-18h] BYREF

*((_QWORD *)&v12[0] + 1) = a1;
v8 = a5 + 40;
v9 = (unsigned __int16)(a5 + 40);
v10 = alloca(((_DWORD)v9 + 15) & 0x1FFF0);
memset(v12, 0, v9);
v12[0] = _mm_loadu_si128(a2);
v12[1] = _mm_loadu_si128(a3);
v13 = a5;
v14 = a4;
memcpy(dest, *((const void **)&v12[0] + 1), a5);
return checksum((unsigned __int8 *)v12, v8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const __m128i *a2, const __m128i *a3, char a4, unsigned int a5)
{
unsigned __int16 v8; // r12
size_t v9; // rdx
void *v10; // rsp
_OWORD v12[2]; // [rsp+0h] [rbp-40h] BYREF
unsigned int v13; // [rsp+23h] [rbp-1Dh]
char v14; // [rsp+27h] [rbp-19h]
char dest[24]; // [rsp+28h] [rbp-18h] BYREF

*((_QWORD *)&v12[0] + 1) = a1;
v8 = a5 + 40;
v9 = (unsigned __int16)(a5 + 40);
v10 = alloca(((_DWORD)v9 + 15) & 0x1FFF0);
memset(v12, 0, v9);
v12[0] = _mm_loadu_si128(a2);
v12[1] = _mm_loadu_si128(a3);
v13 = a5;
v14 = a4;
memcpy(dest, *((const void **)&v12[0] + 1), a5);
return func0((unsigned __int8 *)v12, v8);
}

original_code:
unsigned short checksum_pseudo(void* data, unsigned short* src_addr, unsigned short* dest_addr, unsigned char next_hdr, unsigned int data_len) {
 unsigned short pseudo_hdr_len = 4 * 8 + 8 + data_len;
 unsigned char buf[pseudo_hdr_len];
 memset(buf, 0x0, pseudo_hdr_len);
 memcpy(buf, src_addr, 8 * 2);
 memcpy(buf + 2 * 8, dest_addr, 8 * 2);
 memcpy(buf + 4 * 8 + 3, &data_len, 4);
 memset(buf + 4 * 8 + 7, next_hdr, 1);
 memcpy(buf + 4 * 8 + 8, data, data_len);
 return checksum(&buf, pseudo_hdr_len);
}

canonical_original_code:
unsigned short checksum_pseudo(void *data, unsigned short *src_addr, unsigned short *dest_addr, unsigned char next_hdr, unsigned int data_len) {
 unsigned short pseudo_hdr_len = 4 * 8 + 8 + data_len;
 unsigned char buf[-1];
 memset(buf, 0x0, pseudo_hdr_len);
 memcpy(buf, src_addr, 8 * 2);
 memcpy(buf + 2 * 8, dest_addr, 8 * 2);
 memcpy(buf + 4 * 8 + 3, &data_len, 4);
 memset(buf + 4 * 8 + 7, next_hdr, 1);
 memcpy(buf + 4 * 8 + 8, data, data_len);
 return checksum(&buf, pseudo_hdr_len);
}

variable_types:
buf
unsigned char [-1]


original_code:
unsigned char ipv6_addr_compare(unsigned short* addr1, unsigned short* addr2) {
 unsigned char result = 1;
 unsigned char ind = 0;
 for ( ind = 0; ind < 8; ind++ )
  result = result && ( addr1[ind] == addr2[ind]);
 return result;
}

canonical_original_code:
unsigned char ipv6_addr_compare(unsigned short *addr1, unsigned short *addr2) {
 unsigned char result = 1;
 unsigned char ind = 0;
 for ( ind = 0; ind < 8; ind++ )
  result = result && ( addr1[ind] == addr2[ind]);
 return result;
}

variable_types:
result
unsigned char

variable_types:
ind
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall is_httpget(char *haystack)
{
const char *v1; // r12
size_t v2; // rax
char *v3; // rbp
size_t v4; // rax
__int64 result; // rax

v1 = get_msg;
v2 = strlen(get_msg);
v3 = (char *)malloc(v2 + 20);
v4 = strlen(v1);
strncpy(v3, haystack, v4 + 20);
if ( strstr(haystack, "GET") )
result = (unsigned int)-(strstr(v3, "Host: [fe80::a00:27ff:fe5c:2c17]") == 0LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *haystack)
{
const char *v1; // r12
size_t v2; // rax
char *v3; // rbp
size_t v4; // rax
__int64 result; // rax

v1 = get_msg;
v2 = strlen(get_msg);
v3 = (char *)malloc(v2 + 20);
v4 = strlen(v1);
strncpy(v3, haystack, v4 + 20);
if ( strstr(haystack, "GET") )
result = (unsigned int)-(strstr(v3, "Host: [fe80::a00:27ff:fe5c:2c17]") == 0LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int is_httpget(unsigned char* msg) {
 unsigned char* to_cmp;
 to_cmp = malloc(strlen(get_msg) + 20);
 strncpy(to_cmp, msg, strlen(get_msg) + 20);
 if (strstr( msg, "GET") == ((void *)0) )
  return -1;
 if ( strstr(to_cmp, "Host: [fe80::a00:27ff:fe5c:2c17]") == ((void *)0) )
  return -1;
 return 0;
}

canonical_original_code:
int is_httpget(unsigned char *msg) {
 unsigned char *to_cmp;
 to_cmp = malloc(strlen(get_msg) + 20);
 strncpy(to_cmp, msg, strlen(get_msg) + 20);
 if (strstr( msg, "GET") == ((void *)0) )
  return -1;
 if ( strstr(to_cmp, "Host: [fe80::a00:27ff:fe5c:2c17]") == ((void *)0) )
  return -1;
 return 0;
}

variable_types:
msg
unsigned char *


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

if ( strstr(a1, "link.html") )
result = parse_file2(a2, "link.html");
else
result = parse_file2(a2, "page.html");
return result;
}

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

if ( strstr(a1, "link.html") )
result = func2(a2, "link.html");
else
result = func2(a2, "page.html");
return result;
}

original_code:
int choose_file(unsigned char* req, unsigned char* buff) {
 unsigned char* to_cmp;
 to_cmp = malloc(300);
 strncpy(to_cmp, req, 300);
 int result;
 if ( strstr(req, "link.html") != ((void *)0) ) {
  free(to_cmp);
  return parse_file2(buff, "link.html");
 } else {
  free(to_cmp);
  return parse_file2(buff, "page.html");
 }
 return 0;
}

canonical_original_code:
int choose_file(unsigned char *req, unsigned char *buff) {
 unsigned char *to_cmp;
 to_cmp = malloc(300);
 strncpy(to_cmp, req, 300);
 int result;
 if ( strstr(req, "link.html") != ((void *)0) ) {
  free(to_cmp);
  return parse_file2(buff, "link.html");
 } else {
  free(to_cmp);
  return parse_file2(buff, "page.html");
 }
 return 0;
}

variable_types:
req
unsigned char *

variable_types:
buff
unsigned char *

variable_types: result int


decompiled_code:
__int64 __fastcall get_hardware_info(_DWORD *a1, __int64 a2, int a3)
{
int v4; // eax
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]
__int64 v9; // [rsp+20h] [rbp-28h]

*a1 = 0;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v6[0] = 812151909LL;
v6[1] = 0LL;
if ( ioctl(a3, 0x8933uLL, v6) < 0 )
{
puts("Error: could not get interface index.");
result = 0xFFFFFFFFLL;
}
else
{
*a1 = v7;
if ( ioctl(a3, 0x8927uLL, v6) < 0 )
{
puts("Error: could not get interface address");
close(a3);
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_DWORD *)((char *)&v7 + 2);
*(_DWORD *)a2 = *(_DWORD *)((char *)&v7 + 2);
*(_WORD *)(a2 + 4) = HIWORD(v7);
src_mac_address = v4;
*((_WORD *)&src_mac_address + 2) = *(_WORD *)(a2 + 4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, __int64 a2, int a3)
{
int v4; // eax
__int64 result; // rax
__int64 v6[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]
__int64 v9; // [rsp+20h] [rbp-28h]

*a1 = 0;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v6[0] = 812151909LL;
v6[1] = 0LL;
if ( ioctl(a3, 0x8933uLL, v6) < 0 )
{
puts("Error: could not get interface index.");
result = 0xFFFFFFFFLL;
}
else
{
*a1 = v7;
if ( ioctl(a3, 0x8927uLL, v6) < 0 )
{
puts("Error: could not get interface address");
close(a3);
result = 0xFFFFFFFFLL;
}
else
{
v4 = *(_DWORD *)((char *)&v7 + 2);
*(_DWORD *)a2 = *(_DWORD *)((char *)&v7 + 2);
*(_WORD *)(a2 + 4) = HIWORD(v7);
src_mac_address = v4;
*((_WORD *)&src_mac_address + 2) = *(_WORD *)(a2 + 4);
result = 0LL;
}
}
return result;
}

original_code:
int get_hardware_info(int* ifindex, unsigned char* hw_addr, int sockfd) {
 char *iface = "eth0";
 *ifindex = 0;
 struct ifreq buffer;
 memset(&buffer, 0x00, sizeof(buffer));
 strncpy(buffer.ifr_ifrn.ifrn_name, iface, 16);
 if ( ioctl(sockfd, 0x8933, &buffer) < 0 ) {
  printf("Error: could not get interface index.\n");
  return -1;
 }
 *ifindex = buffer.ifr_ifru.ifru_ivalue;
 if (ioctl(sockfd, 0x8927, &buffer) < 0) {
  printf("Error: could not get interface address\n");
   close(sockfd);
  return -1;
   }
 memcpy((void*)hw_addr, (void*)(buffer.ifr_ifru.ifru_hwaddr.sa_data), 6);
 memcpy(src_mac_address, hw_addr, 6);
 return 0;
}

canonical_original_code:
int get_hardware_info(int *ifindex, unsigned char *hw_addr, int sockfd) {
 char *iface = "eth0";
 *ifindex = 0;
 struct ifreq buffer;
 memset(&buffer, 0x00, sizeof(buffer));
 strncpy(buffer.ifr_ifrn.ifrn_name, iface, 16);
 if ( ioctl(sockfd, 0x8933, &buffer) < 0 ) {
  printf("Error: could not get interface index.\n");
  return -1;
 }
 *ifindex = buffer.ifr_ifru.ifru_ivalue;
 if (ioctl(sockfd, 0x8927, &buffer) < 0) {
  printf("Error: could not get interface address\n");
   close(sockfd);
  return -1;
   }
 memcpy((void *)hw_addr, (void *)(buffer.ifr_ifru.ifru_hwaddr.sa_data), 6);
 memcpy(src_mac_address, hw_addr, 6);
 return 0;
}

variable_types:
ifindex
int *

variable_types: sockfd int

variable_types:
iface
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
int __fastcall send_frame(void *buf, int a2)
{
int v2; // eax
int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-48h] BYREF
int v6; // [rsp+10h] [rbp-38h]
int v7; // [rsp+20h] [rbp-28h] BYREF
int v8; // [rsp+24h] [rbp-24h]
unsigned __int16 v9; // [rsp+28h] [rbp-20h]
int v10; // [rsp+2Ah] [rbp-1Eh] BYREF
__int16 v11; // [rsp+2Eh] [rbp-1Ah]

v8 = -1;
v9 = -1;
v2 = socket(17, 3, 255);
if ( v2 < 0 )
{
puts("Error: could not open a socket.");
}
else
{
v3 = v2;
v7 = 0;
if ( (int)get_hardware_info(&v7, (__int64)&v10, v2) < 0 )
{
perror("Error: could not get hardware's information\n");
}
else
{
*(_DWORD *)((char *)buf + 6) = v10;
*((_WORD *)buf + 5) = v11;
*(_DWORD *)&v5.sa_family = 17;
*(_DWORD *)&v5.sa_data[6] = 100663296;
*(_DWORD *)&v5.sa_data[2] = v7;
*(_DWORD *)&v5.sa_data[10] = v8;
v6 = v9;
if ( sendto(v3, buf, a2, 0, &v5, 0x14u) > 0 )
return close(v3);
perror("Error sending a frame");
}
}
return -1;
}

canonical_decompiled_code:
int __fastcall func3(void *buf, int a2)
{
int v2; // eax
int v3; // ebx
struct sockaddr v5; // [rsp+0h] [rbp-48h] BYREF
int v6; // [rsp+10h] [rbp-38h]
int v7; // [rsp+20h] [rbp-28h] BYREF
int v8; // [rsp+24h] [rbp-24h]
unsigned __int16 v9; // [rsp+28h] [rbp-20h]
int v10; // [rsp+2Ah] [rbp-1Eh] BYREF
__int16 v11; // [rsp+2Eh] [rbp-1Ah]

v8 = -1;
v9 = -1;
v2 = socket(17, 3, 255);
if ( v2 < 0 )
{
puts("Error: could not open a socket.");
}
else
{
v3 = v2;
v7 = 0;
if ( (int)func0(&v7, (__int64)&v10, v2) < 0 )
{
perror("Error: could not get hardware's information\n");
}
else
{
*(_DWORD *)((char *)buf + 6) = v10;
*((_WORD *)buf + 5) = v11;
*(_DWORD *)&v5.sa_family = 17;
*(_DWORD *)&v5.sa_data[6] = 100663296;
*(_DWORD *)&v5.sa_data[2] = v7;
*(_DWORD *)&v5.sa_data[10] = v8;
v6 = v9;
if ( sendto(v3, buf, a2, 0, &v5, 0x14u) > 0 )
return close(v3);
perror("Error sending a frame");
}
}
return -1;
}

original_code:
int send_frame(union ethframe* frame, int frame_len) {
 int proto = 0x86DD;
 unsigned char src_hw[6];
 unsigned char dest_hw[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 int sockfd;
 if ( (sockfd = socket(17, SOCK_RAW, IPPROTO_RAW)) < 0 ) {
  printf("Error: could not open a socket.\n");
  return -1;
 }
 int ifindex = 0;
 if ( get_hardware_info(&ifindex, src_hw , sockfd) < 0 ) {
  perror("Error: could not get hardware's information\n");
  return -1;
 }
 memcpy(frame->field.header.src, src_hw, 6);
 struct sockaddr_ll sockaddr;
 memset((void*)&sockaddr, 0, sizeof(sockaddr));
 sockaddr.sll_family = 17;
 sockaddr.sll_ifindex = ifindex;
 sockaddr.sll_halen = 6;
 memcpy((void*)sockaddr.sll_addr, (void*) dest_hw , 6);
 if ( sendto(sockfd, frame->buffer, frame_len, 0, (struct sockaddr*) &sockaddr, sizeof(sockaddr)) <= 0 ) {
  perror("Error sending a frame");
  return -1;
 }
 close(sockfd);
}

canonical_original_code:
int send_frame(union ethframe *frame, int frame_len) {
 int proto = 0x86DD;
 unsigned char src_hw[6];
 unsigned char dest_hw[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 int sockfd;
 if ( (sockfd = socket(17, SOCK_RAW, IPPROTO_RAW)) < 0 ) {
  printf("Error: could not open a socket.\n");
  return -1;
 }
 int ifindex = 0;
 if ( get_hardware_info(&ifindex, src_hw , sockfd) < 0 ) {
  perror("Error: could not get hardware's information\n");
  return -1;
 }
 memcpy(frame->field.header.src, src_hw, 6);
 struct sockaddr_ll sockaddr;
 memset((void *)&sockaddr, 0, sizeof(sockaddr));
 sockaddr.sll_family = 17;
 sockaddr.sll_ifindex = ifindex;
 sockaddr.sll_halen = 6;
 memcpy((void *)sockaddr.sll_addr, (void *) dest_hw , 6);
 if ( sendto(sockfd, frame->buffer, frame_len, 0, (struct sockaddr *) &sockaddr, sizeof(sockaddr)) <= 0 ) {
  perror("Error sending a frame");
  return -1;
 }
 close(sockfd);
}

variable_types: union ethframe { struct { struct ethhdr { unsigned char dest[6]; unsigned char src[6]; unsigned short proto; } header; unsigned char data[1500]; } field; unsigned char buffer[1514]; } *

variable_types: proto int

variable_types: ifindex int

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

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


decompiled_code:
_BOOL8 __fastcall mac_address_compare(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // cl
_BOOL4 v4; // edx

v2 = 0LL;
v3 = 1;
do
{
v4 = 0;
if ( v3 )
v4 = *(_BYTE *)(a1 + v2) == *(_BYTE *)(a2 + v2);
v3 = v4;
++v2;
}
while ( v2 != 6 );
return v4;
}

original_code:
int mac_address_compare(unsigned char* addr1, unsigned char* addr2) {
 unsigned char result = 1;
 unsigned char ind = 0;
 for ( ind = 0; ind < 6; ind++ )
  result = result && ( addr1[ind] == addr2[ind]);
 return result;
}

canonical_original_code:
int mac_address_compare(unsigned char *addr1, unsigned char *addr2) {
 unsigned char result = 1;
 unsigned char ind = 0;
 for ( ind = 0; ind < 6; ind++ )
  result = result && ( addr1[ind] == addr2[ind]);
 return result;
}


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

*a1 = *a2;
result = *(_QWORD *)((char *)a2 + 1506);
*(_QWORD *)((char *)a1 + 1506) = result;
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)a2 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1514) >> 3));
return result;
}

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

*a1 = *a2;
result = *(_QWORD *)((char *)a2 + 1506);
*(_QWORD *)((char *)a1 + 1506) = result;
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)a2 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1514) >> 3));
return result;
}

original_code:
int parse_eth_frame(union ethframe* frame, void* buffer) {
 memcpy(frame->buffer, buffer, 1514);
}

canonical_original_code:
int parse_eth_frame(union ethframe *frame, void *buffer) {
 memcpy(frame->buffer, buffer, 1514);
}

variable_types:
buffer
void *


repo: lmb/asinine

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

result = 46LL;
if ( (unsigned __int8)(a1 - 32) < 0x60u )
result = a1;
return result;
}

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

result = 46LL;
if ( (unsigned __int8)(a1 - 32) < 0x60u )
result = a1;
return result;
}

original_code:
static char
to_printable(uint8_t value) {
 return (32 <= value && value <= 127) ? (char)value : '.';
}

canonical_original_code:
static char to_printable(unsigned char value) {
 return (32 <= value && value <= 127) ? (char)value : '.';
}

variable_types:
value
unsigned char

return_type: char


hexdump

original_code:
void
hexdump(const uint8_t *buf, size_t num, int depth) {
 char printable[(12) + 1] = "";
 char hex[(3 * (12)) + 1] = "";
 if (buf == ((void *)0)) {
  return;
 }
 size_t i, j;
 for (i = 0, j = 0; i < num; ++i, j = (j + 1) % (12)) {
  if (j == 0 && i > 0) {
   printf("%*s", (depth * 2) + 2, "");
   printf("|%-*s| %s\n", (12), printable, hex);
   memset(printable, 0, sizeof printable);
   memset(hex, 0, sizeof hex);
  }
  printable[j] = to_printable(buf[i]);
  snprintf(hex + (j * 3), 4, "%02X ", buf[i]);
 }
 if (j > 0) {
  printf("%*s", (depth * 2) + 2, "");
  printf("|%-*s| %s\n", (12), printable, hex);
 }
}

canonical_original_code:
void hexdump(unsigned char *buf, unsigned long num, int depth) {
 char printable[-1] = "";
 char hex[-1] = "";
 if (buf == ((void *)0)) {
  return;
 }
 unsigned long i; unsigned long j;
 for (i = 0, j = 0; i < num; ++i, j = (j + 1) % (12)) {
  if (j == 0 && i > 0) {
   printf("%*s", (depth * 2) + 2, "");
   printf("|%-*s| %s\n", (12), printable, hex);
   memset(printable, 0, sizeof printable);
   memset(hex, 0, sizeof hex);
  }
  printable[j] = to_printable(buf[i]);
  snprintf(hex + (j * 3), 4, "%02X ", buf[i]);
 }
 if (j > 0) {
  printf("%*s", (depth * 2) + 2, "");
  printf("|%-*s| %s\n", (12), printable, hex);
 }
}

variable_types:
buf
unsigned char *

variable_types:
num
unsigned long

variable_types: depth int

variable_types:
printable
char [-1]

variable_types:
hex
char [-1]

variable_types:
i
unsigned long

variable_types:
j
unsigned long


decompiled_code:
__int64 __fastcall advance_pos(_QWORD *a1, unsigned __int64 a2)
{
unsigned int v2; // ecx

v2 = 0;
if ( a1[1] - *a1 > a2 )
{
*a1 += a2;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned __int64 a2)
{
unsigned int v2; // ecx

v2 = 0;
if ( a1[1] - *a1 > a2 )
{
*a1 += a2;
v2 = 1;
}
return v2;
}

original_code:
static inline _Bool
advance_pos(asn1_parser_t *parser, size_t num) {
 if ((size_t)((const uint8_t *)parser->end - parser->current) <= num) {
  return 0;
 }
 parser->current += num;
 return 1;
}

canonical_original_code:
static inline _Bool advance_pos(struct asn1_parser *parser, unsigned long num) {
 if ((unsigned long)((unsigned char *)parser->end - parser->current) <= num) {
  return 0;
 }
 parser->current += num;
 return 1;
}

variable_types: struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } token; } *

user_defined_types: struct asn1_parser { unsigned char *current; void *end; void *stack[-1]; unsigned char depth; struct asn1_token token; }

user_defined_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type type; }

user_defined_types: struct asn1_type { enum asn1_tag tag; enum asn1_class class; enum asn1_encoding encoding; }


decompiled_code:
bool __fastcall asn1_eof(_QWORD *a1)
{
return *a1 == a1[1];
}

canonical_decompiled_code:
bool __fastcall func3(_QWORD *a1)
{
return *a1 == a1[1];
}

original_code:
_Bool
asn1_eof(const asn1_parser_t *parser) {
 return parser->current == parser->end;
}

canonical_original_code:
_Bool asn1_eof(struct asn1_parser *parser) {
 return parser->current == parser->end;
}

user_defined_types: enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 }

user_defined_types: enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 }

user_defined_types: enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 }


decompiled_code:
_BOOL8 __fastcall asn1_end(__int64 a1)
{
bool v1; // dl
bool v2; // al

v1 = asn1_eof((_QWORD *)a1);
v2 = 0;
if ( v1 )
v2 = *(_BYTE *)(a1 + 112) == 0;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
bool v1; // dl
bool v2; // al

v1 = func3((_QWORD *)a1);
v2 = 0;
if ( v1 )
v2 = *(_BYTE *)(a1 + 112) == 0;
return v2;
}

original_code:
_Bool
asn1_end(const asn1_parser_t *parser) {
 return asn1_eof(parser) && parser->depth == 0;
}

canonical_original_code:
_Bool asn1_end(struct asn1_parser *parser) {
 return asn1_eof(parser) && parser->depth == 0;
}


original_code:
asinine_err_t
asn1_next(asn1_parser_t *parser) {
 asn1_token_t *const token = &parser->token;
 if (parser->current >= (const uint8_t *)parser->end) {
  return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "EOF" };
 }
 *token = (asn1_token_t){0};
 token->start = parser->current;
 token->type.class = (((*parser->current) & (3 << 6)) >> 6);
 token->type.encoding = (((*parser->current) & (1 << 5)) >> 5);
 token->type.tag = ((*parser->current) & ((1 << 5) - 1));
 if (token->type.tag == (31)) {
  size_t bits;
  bits = 0;
  token->type.tag = 0;
  do {
   if (!advance_pos(parser, 1)) {
    return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: tag: truncated" };
   }
   token->type.tag <<= (7);
   token->type.tag |= *parser->current & ((1 << 7) - 1);
   bits += (7);
   if (bits > (24)) {
    return (asinine_err_t) { .errno = ASININE_ERR_MEMORY, .reason = "token: tag: too large" };
   }
  } while (*parser->current & (1 << 7));
 }
 if (!advance_pos(parser, 1)) {
  return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: truncated header" };
 }
 if (((*parser->current)&(1 << 7))) {
  size_t i, num_bytes;
  num_bytes = *parser->current & ((1 << 7) - 1);
  if (num_bytes == ((1 << 7) - 1)) {
   return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: reserved" };
  } else if (num_bytes == 0) {
   return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: indefinite" };
  } else if (num_bytes > sizeof token->length) {
   return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "token: length: too long" };
  }
  for (i = 0; i < num_bytes; i++) {
   if (!advance_pos(parser, 1)) {
    return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: truncated" };
   }
   if (token->length == 0 && *parser->current == 0) {
    return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: lenght: leading zero" };
   }
   token->length = (token->length << 8) | *parser->current;
  }
  if (token->length < (128)) {
   return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: below long-form minimum" };
  }
 } else {
  token->length = *parser->current & ((1 << 7) - 1);
 }
 if (token->length > 0) {
  const uint8_t *data = parser->current + 1;
  if (!advance_pos(parser, token->length)) {
   return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "token: truncated content" };
  }
  token->data = data;
 }
 parser->current++;
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err asn1_next(struct asn1_parser *parser) {
 struct asn1_token *token = &parser->token;
 if (parser->current >= (unsigned char *)parser->end) {
  return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "EOF" };
 }
 *token = (struct asn1_token){0};
 token->start = parser->current;
 token->type.class = (((*parser->current) & (3 << 6)) >> 6);
 token->type.encoding = (((*parser->current) & (1 << 5)) >> 5);
 token->type.tag = ((*parser->current) & ((1 << 5) - 1));
 if (token->type.tag == (31)) {
  unsigned long bits;
  bits = 0;
  token->type.tag = 0;
  do {
   if (!advance_pos(parser, 1)) {
    return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: tag: truncated" };
   }
   token->type.tag <<= (7);
   token->type.tag |= *parser->current & ((1 << 7) - 1);
   bits += (7);
   if (bits > (24)) {
    return (struct asinine_err) { .errno = ASININE_ERR_MEMORY, .reason = "token: tag: too large" };
   }
  } while (*parser->current & (1 << 7));
 }
 if (!advance_pos(parser, 1)) {
  return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: truncated header" };
 }
 if (((*parser->current)&(1 << 7))) {
  unsigned long i; unsigned long num_bytes;
  num_bytes = *parser->current & ((1 << 7) - 1);
  if (num_bytes == ((1 << 7) - 1)) {
   return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: reserved" };
  } else if (num_bytes == 0) {
   return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: indefinite" };
  } else if (num_bytes > sizeof token->length) {
   return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "token: length: too long" };
  }
  for (i = 0; i < num_bytes; i++) {
   if (!advance_pos(parser, 1)) {
    return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: truncated" };
   }
   if (token->length == 0 && *parser->current == 0) {
    return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: lenght: leading zero" };
   }
   token->length = (token->length << 8) | *parser->current;
  }
  if (token->length < (128)) {
   return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: length: below long-form minimum" };
  }
 } else {
  token->length = *parser->current & ((1 << 7) - 1);
 }
 if (token->length > 0) {
  unsigned char *data = parser->current + 1;
  if (!advance_pos(parser, token->length)) {
   return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "token: truncated content" };
  }
  token->data = data;
 }
 parser->current++;
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types: struct asn1_token { void *start; unsigned char *data; unsigned long length; struct asn1_type { enum asn1_tag { ASN1_TAG_BOOL=1, ASN1_TAG_INT=2, ASN1_TAG_BITSTRING=3, ASN1_TAG_OCTETSTRING=4, ASN1_TAG_NULL=5, ASN1_TAG_OID=6, ASN1_TAG_UTF8STRING=12, ASN1_TAG_SEQUENCE=16, ASN1_TAG_SET=17, ASN1_TAG_PRINTABLESTRING=19, ASN1_TAG_T61STRING=20, ASN1_TAG_IA5STRING=22, ASN1_TAG_UTCTIME=23, ASN1_TAG_GENERALIZEDTIME=24, ASN1_TAG_VISIBLESTRING=26 } tag; enum asn1_class { ASN1_CLASS_UNIVERSAL=0, ASN1_CLASS_APPLICATION=1, ASN1_CLASS_CONTEXT=2, ASN1_CLASS_PRIVATE=3 } class; enum asn1_encoding { ASN1_ENCODING_PRIMITIVE=0, ASN1_ENCODING_CONSTRUCTED=1 } encoding; } type; } *

variable_types:
bits
unsigned long

variable_types:
data
unsigned char *

return_type: struct asinine_err { enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 } errno; char *reason; }

user_defined_types: struct asinine_err { enum asinine_errno errno; char *reason; }


original_code:
asinine_err_t
asn1_abort(asn1_parser_t *parser) {
 if (parser->depth == 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "abort: already at root" };
 }
 const uint8_t *end = parser->stack[0];
 const uint8_t *start = parser->end;
 if (parser->depth > 1) {
  start = parser->stack[1];
 }
 size_t length = (size_t)(end - start);
 asn1_init(parser, start, length);
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err asn1_abort(struct asn1_parser *parser) {
 if (parser->depth == 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "abort: already at root" };
 }
 unsigned char *end = parser->stack[0];
 unsigned char *start = parser->end;
 if (parser->depth > 1) {
  start = parser->stack[1];
 }
 unsigned long length = (size_t)(end - start);
 asn1_init(parser, start, length);
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types:
end
unsigned char *

variable_types:
start
unsigned char *

variable_types:
length
unsigned long

user_defined_types: enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 }


decompiled_code:
__int64 __fastcall asn1_force_push(__int64 a1)
{
unsigned __int8 v1; // al
__int64 result; // rax

v1 = *(_BYTE *)(a1 + 112);
if ( (unsigned int)v1 + 1 > 0xC )
return 12LL;
*(_QWORD *)(a1 + 8LL * v1 + 16) = *(_QWORD *)(a1 + 8);
*(_BYTE *)(a1 + 112) = v1 + 1;
if ( !*(_QWORD *)(a1 + 128) )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
return 0LL;
}
if ( !(unsigned __int8)asn1_is_bitstring(a1 + 120) )
{
*(_QWORD *)a1 = *(_QWORD *)(a1 + 128);
LABEL_5:
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 128) + *(_QWORD *)(a1 + 136);
return 0LL;
}
result = asn1_bitstring(a1 + 120, 0LL, 0LL);
if ( !(_DWORD)result )
{
*(_QWORD *)a1 = *(_QWORD *)(a1 + 128) + 1LL;
goto LABEL_5;
}
return result;
}

original_code:
asinine_err_t
asn1_force_push(asn1_parser_t *parser) {
 const asn1_token_t *token = &parser->token;
 if (parser->depth + 1 > (sizeof parser->stack / sizeof(parser->stack)[0])) {
  return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "push: nested too deep" };
 }
 parser->stack[parser->depth] = parser->end;
 parser->depth++;
 if (token->data == ((void *)0)) {
  parser->end = parser->current;
  return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
 }
 if (asn1_is_bitstring(token)) {
  do { asinine_err_t ret___LINE__ = asn1_bitstring(token, ((void *)0), 0); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  parser->current = token->data + 1;
 } else {
  parser->current = token->data;
 }
 parser->end = token->data + token->length;
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err asn1_force_push(struct asn1_parser *parser) {
 struct asn1_token *token = &parser->token;
 if (parser->depth + 1 > (sizeof parser->stack / sizeof(parser->stack)[0])) {
  return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "push: nested too deep" };
 }
 parser->stack[parser->depth] = parser->end;
 parser->depth++;
 if (token->data == ((void *)0)) {
  parser->end = parser->current;
  return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
 }
 if (asn1_is_bitstring(token)) {
  do { struct asinine_err ret___LINE__ = asn1_bitstring(token, ((void *)0), 0); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  parser->current = token->data + 1;
 } else {
  parser->current = token->data;
 }
 parser->end = token->data + token->length;
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types: struct asinine_err { enum asinine_errno { ASININE_OK=0, ASININE_ERR_MALFORMED=10, ASININE_ERR_MEMORY=11, ASININE_ERR_UNSUPPORTED=12, ASININE_ERR_INVALID=13, ASININE_ERR_EXPIRED=14, ASININE_ERR_UNTRUSTED=15, ASININE_ERR_DEPRECATED=16, ASININE_ERR_NOT_FOUND=17 } errno; char *reason; }


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

if ( (*(_BYTE *)(a1 + 147) & 4) != 0 )
result = asn1_force_push(a1);
else
result = 13LL;
return result;
}

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

if ( (*(_BYTE *)(a1 + 147) & 4) != 0 )
result = func7(a1);
else
result = 13LL;
return result;
}

original_code:
asinine_err_t
asn1_push(asn1_parser_t *parser) {
 if (parser->token.type.encoding != ASN1_ENCODING_CONSTRUCTED) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "push: not constructed" };
 }
 return asn1_force_push(parser);
}

canonical_original_code:
struct asinine_err asn1_push(struct asn1_parser *parser) {
 if (parser->token.type.encoding != ASN1_ENCODING_CONSTRUCTED) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "push: not constructed" };
 }
 return asn1_force_push(parser);
}


decompiled_code:
__int64 __fastcall asn1_pop(__int64 a1)
{
char v1; // bp
__int64 result; // rax
unsigned __int8 v3; // bp
__int64 v4; // rbp

v1 = *(_BYTE *)(a1 + 112);
result = 13LL;
if ( v1 )
{
if ( asn1_eof((_QWORD *)a1) )
{
v3 = v1 - 1;
*(_BYTE *)(a1 + 112) = v3;
v4 = v3 + 2LL;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 8 * v4);
*(_QWORD *)(a1 + 8 * v4) = 0LL;
result = 0LL;
}
else
{
result = 10LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
char v1; // bp
__int64 result; // rax
unsigned __int8 v3; // bp
__int64 v4; // rbp

v1 = *(_BYTE *)(a1 + 112);
result = 13LL;
if ( v1 )
{
if ( func3((_QWORD *)a1) )
{
v3 = v1 - 1;
*(_BYTE *)(a1 + 112) = v3;
v4 = v3 + 2LL;
*(_QWORD *)(a1 + 8) = *(_QWORD *)(a1 + 8 * v4);
*(_QWORD *)(a1 + 8 * v4) = 0LL;
result = 0LL;
}
else
{
result = 10LL;
}
}
return result;
}

original_code:
asinine_err_t
asn1_pop(asn1_parser_t *parser) {
 if (parser->depth == 0) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "pop: already at root" };
 }
 if (!asn1_eof(parser)) {
  return (asinine_err_t) { .errno = ASININE_ERR_MALFORMED, .reason = "pop: parent not fully parsed" };
 }
 parser->depth--;
 parser->end = parser->stack[parser->depth];
 parser->stack[parser->depth] = ((void *)0);
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err asn1_pop(struct asn1_parser *parser) {
 if (parser->depth == 0) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "pop: already at root" };
 }
 if (!asn1_eof(parser)) {
  return (struct asinine_err) { .errno = ASININE_ERR_MALFORMED, .reason = "pop: parent not fully parsed" };
 }
 parser->depth--;
 parser->end = parser->stack[parser->depth];
 parser->stack[parser->depth] = ((void *)0);
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}


decompiled_code:
__int64 __fastcall asn1_tokens(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, _QWORD, __int64))
{
__int64 result; // rax

while ( !asn1_end(a1) )
{
result = asn1_next((_BYTE **)a1);
if ( (_DWORD)result )
return result;
a3(a1 + 120, *(unsigned __int8 *)(a1 + 112), a2);
if ( (*(_BYTE *)(a1 + 147) & 4) != 0 )
{
result = asn1_push(a1);
if ( (_DWORD)result )
return result;
}
while ( asn1_eof((_QWORD *)a1) )
{
result = asn1_pop(a1);
if ( (_DWORD)result )
return result;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, void (__fastcall *a3)(__int64, _QWORD, __int64))
{
__int64 result; // rax

while ( !func4(a1) )
{
result = func5((_BYTE **)a1);
if ( (_DWORD)result )
return result;
a3(a1 + 120, *(unsigned __int8 *)(a1 + 112), a2);
if ( (*(_BYTE *)(a1 + 147) & 4) != 0 )
{
result = func8(a1);
if ( (_DWORD)result )
return result;
}
while ( func3((_QWORD *)a1) )
{
result = func9(a1);
if ( (_DWORD)result )
return result;
}
}
return 0LL;
}

original_code:
asinine_err_t
asn1_tokens(asn1_parser_t *parser, void *ctx,
    void (*fn)(const asn1_token_t *, uint8_t depth, void *ctx)) {
 while (!asn1_end(parser)) {
  do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  fn(&parser->token, parser->depth, ctx);
  if (parser->token.type.encoding == ASN1_ENCODING_CONSTRUCTED) {
   do { asinine_err_t ret___LINE__ = asn1_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  }
  while (asn1_eof(parser)) {
   do { asinine_err_t ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  }
 }
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
struct asinine_err asn1_tokens(struct asn1_parser *parser, void *ctx, void (*fn)(struct asn1_token *, unsigned char depth, void *ctx)) {
 while (!asn1_end(parser)) {
  do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  fn(&parser->token, parser->depth, ctx);
  if (parser->token.type.encoding == ASN1_ENCODING_CONSTRUCTED) {
   do { struct asinine_err ret___LINE__ = asn1_push(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  }
  while (asn1_eof(parser)) {
   do { struct asinine_err ret___LINE__ = asn1_pop(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
  }
 }
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types:
ctx
void *

variable_types: void (*)(struct asn1_token *, unsigned char depth, void *ctx)


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

result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_sequence(a1 + 15) )
result = asn1_push((__int64)a1);
else
result = 13LL;
}
return result;
}

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

result = func5(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_sequence(a1 + 15) )
result = func8((__int64)a1);
else
result = 13LL;
}
return result;
}

original_code:
asinine_err_t
asn1_push_seq(asn1_parser_t *parser) {
 do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_sequence(&parser->token)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "push: token not a sequence" };
 }
 return asn1_push(parser);
}

canonical_original_code:
struct asinine_err asn1_push_seq(struct asn1_parser *parser) {
 do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_sequence(&parser->token)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "push: token not a sequence" };
 }
 return asn1_push(parser);
}


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

result = 13LL;
if ( *(_QWORD *)(a1 + 136) > 1uLL )
{
*(_QWORD *)(a2 + 8) = *(_QWORD *)(a1 + 128) + 1LL;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(a1 + 136) - 1LL;
result = 0LL;
}
return result;
}

original_code:
static asinine_err_t
parse_ecdsa_pubkey(asn1_parser_t *parser, x509_pubkey_t *pubkey) {
 if (parser->token.length < 2) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "ecdsa pubkey: too short" };
 }
 pubkey->key.ecdsa.point = parser->token.data + 1;
 pubkey->key.ecdsa.point_num = parser->token.length - 1;
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
static struct asinine_err parse_ecdsa_pubkey(struct asn1_parser *parser, struct x509_pubkey *pubkey) {
 if (parser->token.length < 2) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "ecdsa pubkey: too short" };
 }
 pubkey->key.ecdsa.point = parser->token.data + 1;
 pubkey->key.ecdsa.point_num = parser->token.length - 1;
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types: struct x509_pubkey { enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 } algorithm; union { struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; } rsa; struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; } ecdsa; } key; } *

user_defined_types: struct x509_pubkey { enum x509_pubkey_algo algorithm; union { struct x509_pubkey_rsa rsa; struct x509_pubkey_ecdsa ecdsa; } key; }


decompiled_code:
__int64 __fastcall parse_ecdsa_params(__int64 a1, _DWORD *a2, _BYTE *a3)
{
__int64 result; // rax
__int64 v5; // r12
int v6; // eax
_BYTE v7[88]; // [rsp+0h] [rbp-58h] BYREF

result = asn1_next();
if ( !(_DWORD)result )
{
v5 = a1 + 120;
if ( (unsigned __int8)asn1_is_null(a1 + 120) )
{
result = asn1_null(v5);
}
else if ( (unsigned __int8)asn1_is_oid(v5) )
{
result = asn1_oid(v5, v7);
if ( !(_DWORD)result )
{
v6 = find_curve((__int64)v7);
if ( v6 )
{
*a3 = 1;
*a2 = v6;
result = 0LL;
}
else
{
result = 12LL;
}
}
}
else
{
result = 13LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2, _BYTE *a3)
{
__int64 result; // rax
__int64 v5; // r12
int v6; // eax
_BYTE v7[88]; // [rsp+0h] [rbp-58h] BYREF

result = asn1_next();
if ( !(_DWORD)result )
{
v5 = a1 + 120;
if ( (unsigned __int8)asn1_is_null(a1 + 120) )
{
result = asn1_null(v5);
}
else if ( (unsigned __int8)asn1_is_oid(v5) )
{
result = asn1_oid(v5, v7);
if ( !(_DWORD)result )
{
v6 = func2((__int64)v7);
if ( v6 )
{
*a3 = 1;
*a2 = v6;
result = 0LL;
}
else
{
result = 12LL;
}
}
}
else
{
result = 13LL;
}
}
return result;
}

original_code:
static asinine_err_t
parse_ecdsa_params(
    asn1_parser_t *parser, x509_pubkey_params_t *params, _Bool *has_params) {
 do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (asn1_is_null(&parser->token)) {
  return asn1_null(&parser->token);
 }
 if (!asn1_is_oid(&parser->token)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "ecdsa params: token isn't an OID" };
 }
 asn1_oid_t oid;
 do { asinine_err_t ret___LINE__ = asn1_oid(&parser->token, &oid); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 x509_ecdsa_curve_t curve = find_curve(&oid);
 if (curve == X509_ECDSA_CURVE_INVALID) {
  return (asinine_err_t) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "ecsda params: unkown algorithm" };
 }
 *has_params = 1;
 params->ecdsa_curve = curve;
 return (asinine_err_t) { .errno = ASININE_OK, .reason = ((void *)0) };
}

canonical_original_code:
static struct asinine_err parse_ecdsa_params(struct asn1_parser *parser, union x509_pubkey_params *params, _Bool *has_params) {
 do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (asn1_is_null(&parser->token)) {
  return asn1_null(&parser->token);
 }
 if (!asn1_is_oid(&parser->token)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "ecdsa params: token isn't an OID" };
 }
 struct asn1_oid oid;
 do { struct asinine_err ret___LINE__ = asn1_oid(&parser->token, &oid); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 enum x509_ecdsa_curve curve = find_curve(&oid);
 if (curve == X509_ECDSA_CURVE_INVALID) {
  return (struct asinine_err) { .errno = ASININE_ERR_UNSUPPORTED, .reason = "ecsda params: unkown algorithm" };
 }
 *has_params = 1;
 params->ecdsa_curve = curve;
 return (struct asinine_err) { .errno = ASININE_OK, .reason = ((void *)0) };
}

variable_types: union x509_pubkey_params { enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 } ecdsa_curve; } *

variable_types: struct asn1_oid { unsigned int arcs[-1]; unsigned long num; }

user_defined_types: union x509_pubkey_params { enum x509_ecdsa_curve ecdsa_curve; }


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

result = asn1_push_seq();
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_int(a1 + 120) )
{
result = asn1_uint_buf(a1 + 120, a2 + 8, a2 + 16);
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_int(a1 + 120) )
{
result = asn1_uint_buf(a1 + 120, a2 + 24, a2 + 32);
if ( !(_DWORD)result )
result = asn1_pop(a1);
}
else
{
result = 13LL;
}
}
}
}
else
{
result = 13LL;
}
}
}
return result;
}

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

result = asn1_push_seq();
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_int(a1 + 120) )
{
result = asn1_uint_buf(a1 + 120, a2 + 8, a2 + 16);
if ( !(_DWORD)result )
{
result = asn1_next(a1);
if ( !(_DWORD)result )
{
if ( (unsigned __int8)asn1_is_int(a1 + 120) )
{
result = asn1_uint_buf(a1 + 120, a2 + 24, a2 + 32);
if ( !(_DWORD)result )
result = asn1_pop(a1);
}
else
{
result = 13LL;
}
}
}
}
else
{
result = 13LL;
}
}
}
return result;
}

original_code:
static asinine_err_t
parse_rsa_pubkey(asn1_parser_t *parser, x509_pubkey_t *pubkey) {
 const asn1_token_t *token = &parser->token;
 do { asinine_err_t ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_int(token)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "rsa pubkey: token isn't an int" };
 }
 do { asinine_err_t ret___LINE__ = asn1_uint_buf(token, &pubkey->key.rsa.n, &pubkey->key.rsa.n_num); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { asinine_err_t ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_int(token)) {
  return (asinine_err_t) { .errno = ASININE_ERR_INVALID, .reason = "rsa pubkey: token isn't an int" };
 }
 do { asinine_err_t ret___LINE__ = asn1_uint_buf(token, &pubkey->key.rsa.e, &pubkey->key.rsa.e_num); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 return asn1_pop(parser);
}

canonical_original_code:
static struct asinine_err parse_rsa_pubkey(struct asn1_parser *parser, struct x509_pubkey *pubkey) {
 struct asn1_token *token = &parser->token;
 do { struct asinine_err ret___LINE__ = asn1_push_seq(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_int(token)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "rsa pubkey: token isn't an int" };
 }
 do { struct asinine_err ret___LINE__ = asn1_uint_buf(token, &pubkey->key.rsa.n, &pubkey->key.rsa.n_num); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 do { struct asinine_err ret___LINE__ = asn1_next(parser); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 if (!asn1_is_int(token)) {
  return (struct asinine_err) { .errno = ASININE_ERR_INVALID, .reason = "rsa pubkey: token isn't an int" };
 }
 do { struct asinine_err ret___LINE__ = asn1_uint_buf(token, &pubkey->key.rsa.e, &pubkey->key.rsa.e_num); if (ret___LINE__.errno != ASININE_OK) { return ret___LINE__; } } while (0);
 return asn1_pop(parser);
}

user_defined_types: enum x509_pubkey_algo { X509_PUBKEY_INVALID=0, X509_PUBKEY_RSA=1, X509_PUBKEY_ECDSA=2 }

user_defined_types: struct x509_pubkey_rsa { unsigned char *n; unsigned long n_num; unsigned char *e; unsigned long e_num; }

user_defined_types: struct x509_pubkey_ecdsa { unsigned char *point; unsigned long point_num; }


decompiled_code:
__int64 parse_null_or_empty_params()
{
return x509_parse_null_or_empty_args();
}

canonical_decompiled_code:
__int64 func5()
{
return x509_parse_null_or_empty_args();
}

original_code:
static asinine_err_t
parse_null_or_empty_params(
    asn1_parser_t *parser, x509_pubkey_params_t *params, _Bool *has_params) {
 (void)params;
 (void)has_params;
 return _x509_parse_null_or_empty_args(parser);
}

canonical_original_code:
static struct asinine_err parse_null_or_empty_params(struct asn1_parser *parser, union x509_pubkey_params *params, _Bool *has_params) {
 (void)params;
 (void)has_params;
 return _x509_parse_null_or_empty_args(parser);
}

user_defined_types: enum x509_ecdsa_curve { X509_ECDSA_CURVE_INVALID=0, X509_ECDSA_CURVE_SECP256R1=1, X509_ECDSA_CURVE_SECP384R1=2, X509_ECDSA_CURVE_SECP521R1=3 }