decompiled_code:
size_t __fastcall net_readn(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
if ( n )
{
v5 = n;
while ( 1 )
{
v6 = recv(fd, buf, v5, 0x4000);
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
v6 = 0LL;
}
else if ( !v6 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

canonical_decompiled_code:
size_t __fastcall func7(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t v6; // rax

v3 = n;
if ( n )
{
v5 = n;
while ( 1 )
{
v6 = recv(fd, buf, v5, 0x4000);
if ( v6 < 0 )
{
if ( *_errno_location() != 4 )
return -1LL;
v6 = 0LL;
}
else if ( !v6 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

original_code:
extern ssize_t
net_readn(FDType fd, void *vptr, size_t n)
{
  size_t nleft;
  ssize_t nread;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nread = recv(fd, ptr, nleft, MSG_NOSIGNAL)) < 0) {
      if ((*__errno_location ()) == 4)
 nread = 0;
      else
 return(-1);
    } else if (nread == 0)
      break;
    nleft -= nread;
    ptr += nread;
  }
  return(n - nleft);
}

canonical_original_code:
extern long net_readn(int fd, void *vptr, unsigned long n)
{
  unsigned long nleft;
  long nread;
  char *ptr;
  ptr = vptr;
  nleft = n;
  while (nleft > 0) {
    if ( (nread = recv(fd, ptr, nleft, MSG_NOSIGNAL)) < 0) {
      if ((*__errno_location ()) == 4)
 nread = 0;
      else
 return(-1);
    } else if (nread == 0)
      break;
    nleft -= nread;
    ptr += nread;
  }
  return(n - nleft);
}

variable_types: nread long


engineInit

repo: samirotiv/Tron

decompiled_code:
int engineInit()
{
__int16 v0; // bp
__int16 v1; // bx

initscr();
if ( !stdscr )
{
start_color();
goto LABEL_6;
}
v0 = stdscr->_maxy;
v1 = stdscr->_maxx;
start_color();
if ( v1 <= 78 || v0 <= 22 )
{
LABEL_6:
endwin();
printf(
"Your console screen is smaller than %d x %d\n"
"Please resize your window and try again\n"
"Please note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n",
80LL,
24LL);
exit(0);
}
raw();
noecho();
keypad(stdscr, 1);
curs_set(0);
nodelay(stdscr, 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
__int16 v0; // bp
__int16 v1; // bx

initscr();
if ( !stdscr )
{
start_color();
goto LABEL_6;
}
v0 = stdscr->_maxy;
v1 = stdscr->_maxx;
start_color();
if ( v1 <= 78 || v0 <= 22 )
{
LABEL_6:
endwin();
printf(
"Your console screen is smaller than %d x %d\n"
"Please resize your window and try again\n"
"Please note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n",
80LL,
24LL);
exit(0);
}
raw();
noecho();
keypad(stdscr, 1);
curs_set(0);
nodelay(stdscr, 1);
return wrefresh(stdscr);
}

original_code:
void engineInit(){
    (void) initscr();
    int current_height, current_width;
 (current_height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), current_width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 start_color();
 if ((current_width < 80) || (current_height < 24) || (24 < 24) || (80 < 80)){
        endwin();
        printf ("Your console screen is smaller than %d x %d\nPlease resize your window and try again\nPlease note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n", 80, 24);
        exit(0);
    }
    raw();
    noecho();
    keypad(stdscr, 1);
    curs_set(0);
    nodelay(stdscr, 1);
    wrefresh(stdscr);
}

canonical_original_code:
void engineInit(){
    (void) initscr();
    int current_height; int current_width;
 (current_height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), current_width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 start_color();
 if ((current_width < 80) || (current_height < 24) || (24 < 24) || (80 < 80)){
        endwin();
        printf ("Your console screen is smaller than %d x %d\nPlease resize your window and try again\nPlease note, the set SCREENWIDTH and SCREENHEIGHT in engine.h must be greater than 24x80\n", 80, 24);
        exit(0);
    }
    raw();
    noecho();
    keypad(stdscr, 1);
    curs_set(0);
    nodelay(stdscr, 1);
    wrefresh(stdscr);
}

return_type: void


engineStartMenuEnvironment

decompiled_code:
int engineStartMenuEnvironment()
{
nodelay(stdscr, 0);
werase(stdscr);
wrefresh(stdscr);
return flushinp();
}

canonical_decompiled_code:
int func1()
{
nodelay(stdscr, 0);
werase(stdscr);
wrefresh(stdscr);
return flushinp();
}

original_code:
void engineStartMenuEnvironment(){
    nodelay(stdscr, 0);
    werase(stdscr);
    wrefresh(stdscr);
    flushinp();
    return;
}


engineDrawWalls

decompiled_code:
int engineDrawWalls()
{
__int64 i; // rbx
unsigned __int64 v1; // rbp
int j; // ebx
int result; // eax

wattrset(stdscr, 1024);
werase(stdscr);
wbkgd(stdscr, 0x400uLL);
wattrset(stdscr, 768);
for ( i = 0LL; i != 24; ++i )
{
if ( wmove(stdscr, i, 0) != -1 )
waddch(stdscr, 0x20uLL);
game[i + 13] = 87;
if ( wmove(stdscr, i, 79) != -1 )
waddch(stdscr, 0x20uLL);
game[i + 1909] = 87;
}
v1 = (unsigned int)((_DWORD)game + 13);
for ( j = 0; j != 80; ++j )
{
if ( wmove(stdscr, 0, j) != -1 )
waddch(stdscr, 0x20uLL);
*(_BYTE *)v1 = 87;
result = wmove(stdscr, 23, j);
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
*(_BYTE *)(v1 + 23) = 87;
v1 += 24LL;
}
return result;
}

canonical_decompiled_code:
int func2()
{
__int64 i; // rbx
unsigned __int64 v1; // rbp
int j; // ebx
int result; // eax

wattrset(stdscr, 1024);
werase(stdscr);
wbkgd(stdscr, 0x400uLL);
wattrset(stdscr, 768);
for ( i = 0LL; i != 24; ++i )
{
if ( wmove(stdscr, i, 0) != -1 )
waddch(stdscr, 0x20uLL);
game[i + 13] = 87;
if ( wmove(stdscr, i, 79) != -1 )
waddch(stdscr, 0x20uLL);
game[i + 1909] = 87;
}
v1 = (unsigned int)((_DWORD)game + 13);
for ( j = 0; j != 80; ++j )
{
if ( wmove(stdscr, 0, j) != -1 )
waddch(stdscr, 0x20uLL);
*(_BYTE *)v1 = 87;
result = wmove(stdscr, 23, j);
if ( result != -1 )
result = waddch(stdscr, 0x20uLL);
*(_BYTE *)(v1 + 23) = 87;
v1 += 24LL;
}
return result;
}

variable_types: y int

variable_types: x int


engineClearMap

decompiled_code:
_BYTE *engineClearMap()
{
unsigned __int64 v0; // rdx
_BYTE *result; // rax

v0 = (unsigned int)((_DWORD)game + 37);
do
{
result = (_BYTE *)(v0 - 24);
do
*result++ = 0;
while ( result != (_BYTE *)v0 );
v0 += 24LL;
}
while ( v0 != (_DWORD)game + 1957 );
return result;
}

canonical_decompiled_code:
_BYTE *func3()
{
unsigned __int64 v0; // rdx
_BYTE *result; // rax

v0 = (unsigned int)((_DWORD)game + 37);
do
{
result = (_BYTE *)(v0 - 24);
do
*result++ = 0;
while ( result != (_BYTE *)v0 );
v0 += 24LL;
}
while ( v0 != (_DWORD)game + 1957 );
return result;
}

original_code:
void engineClearMap(){
    int i, j;
    for (i=0; i<80; i++){
        for (j=0; j<24; j++){
            game.map[i][j] = 0;
        }
    }
}

canonical_original_code:
void engineClearMap(){
    int i; int j;
    for (i=0; i<80; i++){
        for (j=0; j<24; j++){
            game.map[i][j] = 0;
        }
    }
}

variable_types: i int

variable_types: j int


engineStartGameEnvironment

decompiled_code:
int engineStartGameEnvironment()
{
nodelay(stdscr, 1);
engineClearMap();
engineDrawWalls();
snakeInit();
*(_DWORD *)&game[8] = *(_DWORD *)&game[4];
init_pair(1, 4, 4);
init_pair(2, 1, 1);
init_pair(5, 0, 0);
init_pair(6, 0, 0);
init_pair(3, 0, 0);
init_pair(4, 0, 7);
wrefresh(stdscr);
return flushinp();
}

canonical_decompiled_code:
int func4()
{
nodelay(stdscr, 1);
func3();
func2();
snakeInit();
*(_DWORD *)&game[8] = *(_DWORD *)&game[4];
init_pair(1, 4, 4);
init_pair(2, 1, 1);
init_pair(5, 0, 0);
init_pair(6, 0, 0);
init_pair(3, 0, 0);
init_pair(4, 0, 7);
wrefresh(stdscr);
return flushinp();
}

original_code:
void engineStartGameEnvironment(){
    nodelay(stdscr, 1);
    engineClearMap();
    engineDrawWalls();
    snakeInit();
    game.depth = game.difficulty;
    init_pair(1, 4, 4);
    init_pair(2, 1, 1);
    init_pair(5, 0, 0);
    init_pair(6, 0, 0);
    init_pair(3, 0, 0);
    init_pair(4, 0, 7);
    wrefresh(stdscr);
    flushinp();
    return;
}


engineProcessGameWinner

decompiled_code:
__int64 engineProcessGameWinner()
{
__int64 result; // rax

result = *((unsigned int *)&snake2 + 1);
if ( *((_DWORD *)&snake1 + 1) == (_DWORD)result )
{
result = *((unsigned int *)&snake2 + 2);
if ( *((_DWORD *)&snake1 + 2) == (_DWORD)result )
{
snake2 = 0;
snake1 = 0;
LABEL_6:
game[12] = 0;
return result;
}
}
if ( snake1 )
{
game[12] = 1;
return result;
}
if ( !snake2 )
goto LABEL_6;
game[12] = 2;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

result = *((unsigned int *)&snake2 + 1);
if ( *((_DWORD *)&snake1 + 1) == (_DWORD)result )
{
result = *((unsigned int *)&snake2 + 2);
if ( *((_DWORD *)&snake1 + 2) == (_DWORD)result )
{
snake2 = 0;
snake1 = 0;
LABEL_6:
game[12] = 0;
return result;
}
}
if ( snake1 )
{
game[12] = 1;
return result;
}
if ( !snake2 )
goto LABEL_6;
game[12] = 2;
return result;
}

original_code:
void engineProcessGameWinner(){
    if ((snake1.head.x == snake2.head.x) && (snake1.head.y == snake2.head.y)) snake1.alive = snake2.alive = 0;
    if (snake1.alive != 0) game.winner = 1;
    else if (snake2.alive != 0) game.winner = 2;
    else game.winner = 0;
}


engineSleepAndCallBot

decompiled_code:
__int64 __fastcall engineSleepAndCallBot(__int64 a1, __int64 a2, __useconds_t a3)
{
__int64 result; // rax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
void *thread_return; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

*(_DWORD *)(a1 + 24) = *(_DWORD *)(a1 + 12);
v5[0] = a1;
v5[1] = a2;
doneflag = 0;
pthread_create(newthread, 0LL, (void *(*)(void *))&aiProcessGame, v5);
usleep(a3);
pthread_cancel(newthread[0]);
pthread_join(newthread[0], &thread_return);
result = doneflag;
if ( doneflag == 1 )
{
if ( counter_0 <= 0 )
{
result = game[2];
if ( (int)result < (int)game[1] )
{
result = (unsigned int)(result + 1);
game[2] = result;
}
}
else
{
result = (unsigned int)--counter_0;
}
}
else if ( !doneflag )
{
counter_0 = 30;
--game[2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __useconds_t a3)
{
__int64 result; // rax
__int64 v5[2]; // [rsp+0h] [rbp-28h] BYREF
void *thread_return; // [rsp+10h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+18h] [rbp-10h] BYREF

*(_DWORD *)(a1 + 24) = *(_DWORD *)(a1 + 12);
v5[0] = a1;
v5[1] = a2;
doneflag = 0;
pthread_create(newthread, 0LL, (void *(*)(void *))&aiProcessGame, v5);
usleep(a3);
pthread_cancel(newthread[0]);
pthread_join(newthread[0], &thread_return);
result = doneflag;
if ( doneflag == 1 )
{
if ( counter_0 <= 0 )
{
result = game[2];
if ( (int)result < (int)game[1] )
{
result = (unsigned int)(result + 1);
game[2] = result;
}
}
else
{
result = (unsigned int)--counter_0;
}
}
else if ( !doneflag )
{
counter_0 = 30;
--game[2];
}
return result;
}

original_code:
void engineSleepAndCallBot(struct snakestructure* botsnakepointer, struct snakestructure* usrsnakepointer, long int usleeptime){
    struct timespec timeout;
    pthread_t aithread;
    int error = 0;
    void *exitstatus;
    static int counter;
    botsnakepointer->bot_newdirection = botsnakepointer->direction;
    struct snakestructure* snakes[] = {botsnakepointer, usrsnakepointer};
    doneflag = 0;
    pthread_create(&aithread, ((void *)0), aiProcessGame, snakes);
    usleep(usleeptime);
    error = pthread_cancel(aithread);
    error = pthread_join(aithread, &exitstatus);
    if (doneflag == 1) {
        if (counter > 0) counter--;
        else if (game.depth < game.difficulty) game.depth++;
    }
    if (doneflag == 0) {
        counter = 30;
        game.depth--;
    }
    return;
}

canonical_original_code:
void engineSleepAndCallBot(struct snakestructure *botsnakepointer, struct snakestructure *usrsnakepointer, long usleeptime){
    struct timespec timeout;
    unsigned long aithread;
    int error = 0;
    void *exitstatus;
    static int counter;
    botsnakepointer->bot_newdirection = botsnakepointer->direction;
    struct snakestructure *snakes[] = {botsnakepointer, usrsnakepointer};
    doneflag = 0;
    pthread_create(&aithread, ((void *)0), aiProcessGame, snakes);
    usleep(usleeptime);
    error = pthread_cancel(aithread);
    error = pthread_join(aithread, &exitstatus);
    if (doneflag == 1) {
        if (counter > 0) counter--;
        else if (game.depth < game.difficulty) game.depth++;
    }
    if (doneflag == 0) {
        counter = 30;
        game.depth--;
    }
    return;
}

variable_types:
usrsnakepointer
struct snakestructure *

variable_types: usleeptime long

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types:
aithread
unsigned long

variable_types: error int

variable_types:
exitstatus
void *

variable_types: counter int

variable_types: struct snakestructure { char alive; struct point { int x; int y; } head; int direction; int size; char marker; char colorcode; char headcolorcode; int bot_newdirection; } *[]

user_defined_types: struct snakestructure { char alive; struct point head; int direction; int size; char marker; char colorcode; char headcolorcode; int bot_newdirection; }


InitQueue

original_code:
void InitQueue (queue* q, int* array, int arraysize){
    q->size = q->front = q->behindback = 0;
    q->maxqueuesize = arraysize;
    if (array != ((void *)0)){
        q->data = array;
    }
    else{
        q->data = (int*) malloc ((q->maxqueuesize + 1) * sizeof(int));
    }
}

canonical_original_code:
void InitQueue(struct queue_ *q, int *array, int arraysize){
    q->size = q->front = q->behindback = 0;
    q->maxqueuesize = arraysize;
    if (array != ((void *)0)){
        q->data = array;
    }
    else{
        q->data = (int *) malloc ((q->maxqueuesize + 1) * sizeof(int));
    }
}

variable_types: struct queue_ { int *data; int maxqueuesize; int front; int behindback; int lastenqueued; int size; } *

variable_types:
array
int *

variable_types: arraysize int


enqueue

original_code:
void enqueue (queue* q, int val){
    if ((q->size == 0) || (q->behindback != q->front)){
        q->size++;
        q->data[q->behindback] = val;
        q->lastenqueued = val;
        q->behindback = (q->behindback + 1) % q->maxqueuesize;
    }
}

canonical_original_code:
void enqueue(struct queue_ *q, int val){
    if ((q->size == 0) || (q->behindback != q->front)){
        q->size++;
        q->data[q->behindback] = val;
        q->lastenqueued = val;
        q->behindback = (q->behindback + 1) % q->maxqueuesize;
    }
}

variable_types: val int

user_defined_types: struct queue_ { int *data; int maxqueuesize; int front; int behindback; int lastenqueued; int size; }


dequeue

original_code:
int dequeue (queue* q){
    if (q->size > 0){
        q->size--;
        int returnvalue = q->data[q->front];
        q->front = (q->front + 1) % q->maxqueuesize;
        return returnvalue;
    }
    else return 0;
}

canonical_original_code:
int dequeue(struct queue_ *q){
    if (q->size > 0){
        q->size--;
        int returnvalue = q->data[q->front];
        q->front = (q->front + 1) % q->maxqueuesize;
        return returnvalue;
    }
    else return 0;
}

variable_types: returnvalue int

return_type: int


FreeQueue

decompiled_code:
void __fastcall FreeQueue(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
free(*a1);
}

original_code:
void FreeQueue (queue* q){
    free(q->data);
}

canonical_original_code:
void FreeQueue(struct queue_ *q){
    free(q->data);
}


menuGetInput

original_code:
int menuGetInput(int* speed_cur_option, int* diff_cur_option)
{
 nodelay (stdscr, 0);
 int input = wgetch(stdscr);
 switch (input)
 {
 case 10: case ' ':
  return 0;
  break;
 case 'q': case 'Q':
  ExitGame();
  break;
 case 0403:
   gamemode = 1;
  break;
 case 0402:
   gamemode = 2;
  break;
 case 0404:
  if (*diff_cur_option > 1)
   (*diff_cur_option)--;
  break;
 case 0405:
  if (*diff_cur_option < 4)
   (*diff_cur_option)++;
  break;
 case '1': case '2': case '3': case '4':
  *speed_cur_option = (input - '0');
  break;
 default:
  break;
 }
 return 1;
}

canonical_original_code:
int menuGetInput(int *speed_cur_option, int *diff_cur_option)
{
 nodelay (stdscr, 0);
 int input = wgetch(stdscr);
 switch (input)
 {
 case 10: case ' ':
  return 0;
  break;
 case 'q': case 'Q':
  ExitGame();
  break;
 case 0403:
   gamemode = 1;
  break;
 case 0402:
   gamemode = 2;
  break;
 case 0404:
  if (*diff_cur_option > 1)
   (*diff_cur_option)--;
  break;
 case 0405:
  if (*diff_cur_option < 4)
   (*diff_cur_option)++;
  break;
 case '1': case '2': case '3': case '4':
  *speed_cur_option = (input - '0');
  break;
 default:
  break;
 }
 return 1;
}

variable_types: input int


menuMainMenu

variable_types:
difficultyoptionsarray
int []

variable_types: wait int

variable_types: y int

variable_types: x int


menuEndPrint

decompiled_code:
int __fastcall menuEndPrint(int a1)
{
int i; // ebx
__int64 j; // rbp
int v3; // ebx
int v4; // er13
char v5; // al
int v7; // [rsp+4h] [rbp-44h]
__int64 v8[8]; // [rsp+8h] [rbp-40h]

v8[1] = (__int64)"PLAY AGAIN.!";
v8[2] = (__int64)"BACK TO MENU";
v8[0] = 0xC0000000CLL;
if ( wmove(stdscr, 6, 25) != -1 )
waddnstr(stdscr, " ____________________________ ", -1);
for ( i = 7; i != 17; ++i )
{
if ( wmove(stdscr, i, 25) != -1 )
waddch(stdscr, 0x7CuLL);
if ( wmove(stdscr, i, 54) != -1 )
waddch(stdscr, 0x7CuLL);
}
if ( wmove(stdscr, 16, 25) != -1 )
waddnstr(stdscr, "|____________________________|", -1);
for ( j = 1LL; j != 3; ++j )
{
v3 = (30 - *(&v7 + j)) / 2 + 25;
v4 = j + 9;
if ( a1 == (_DWORD)j )
{
wattr_on(stdscr, 0x10000uLL, 0LL);
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v3, "%s", (const char *)v8[j]);
wattr_off(stdscr, 0x10000uLL, 0LL);
}
else
{
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v3, "%s", (const char *)v8[j]);
}
}
wattr_on(stdscr, 0x200000uLL, 0LL);
v5 = game[12];
if ( v5 == 1 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v5 == 2 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
else
{
mvprintw(15, 35, "DRAW GAME");
}
wattr_off(stdscr, 0x200000uLL, 0LL);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int i; // ebx
__int64 j; // rbp
int v3; // ebx
int v4; // er13
char v5; // al
int v7; // [rsp+4h] [rbp-44h]
__int64 v8[8]; // [rsp+8h] [rbp-40h]

v8[1] = (__int64)"PLAY AGAIN.!";
v8[2] = (__int64)"BACK TO MENU";
v8[0] = 0xC0000000CLL;
if ( wmove(stdscr, 6, 25) != -1 )
waddnstr(stdscr, " ____________________________ ", -1);
for ( i = 7; i != 17; ++i )
{
if ( wmove(stdscr, i, 25) != -1 )
waddch(stdscr, 0x7CuLL);
if ( wmove(stdscr, i, 54) != -1 )
waddch(stdscr, 0x7CuLL);
}
if ( wmove(stdscr, 16, 25) != -1 )
waddnstr(stdscr, "|____________________________|", -1);
for ( j = 1LL; j != 3; ++j )
{
v3 = (30 - *(&v7 + j)) / 2 + 25;
v4 = j + 9;
if ( a1 == (_DWORD)j )
{
wattr_on(stdscr, 0x10000uLL, 0LL);
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v3, "%s", (const char *)v8[j]);
wattr_off(stdscr, 0x10000uLL, 0LL);
}
else
{
wattr_on(stdscr, 0x200000uLL, 0LL);
mvprintw(v4, v3, "%s", (const char *)v8[j]);
}
}
wattr_on(stdscr, 0x200000uLL, 0LL);
v5 = game[12];
if ( v5 == 1 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v5 == 2 )
{
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
else
{
mvprintw(15, 35, "DRAW GAME");
}
wattr_off(stdscr, 0x200000uLL, 0LL);
return wrefresh(stdscr);
}

variable_types: highlight int

variable_types: i int

variable_types:
choices
char *[]


menuEndGame

decompiled_code:
int __fastcall menuEndGame(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // ebp
WINDOW *v4; // rdi
int v5; // eax
__int64 v6; // rdx

engineStartMenuEnvironment();
menuEndPrint(1);
v2 = 0;
v3 = 1;
do
{
wrefresh(stdscr);
v4 = stdscr;
v5 = wgetch(stdscr);
if ( v5 == 258 )
{
if ( v3 == 1 )
v3 = 2;
}
else if ( v5 > 258 )
{
if ( v5 == 259 && v3 == 2 )
v3 = 1;
}
else
{
if ( v5 == 81 )
goto LABEL_12;
if ( v5 > 81 )
{
if ( v5 != 113 )
goto LABEL_5;
LABEL_12:
ExitGame(v4, a2, v6);
goto LABEL_5;
}
if ( v5 == 10 )
{
v2 = v3;
}
else if ( v5 == 32 )
{
v2 = v3;
}
}
LABEL_5:
menuEndPrint(v3);
if ( v2 == 1 )
{
wattrset(stdscr, 0);
return wrefresh(stdscr);
}
}
while ( v2 != 2 );
game[0] = 4;
wattrset(stdscr, 0);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // ebp
WINDOW *v4; // rdi
int v5; // eax
__int64 v6; // rdx

engineStartMenuEnvironment();
func2(1);
v2 = 0;
v3 = 1;
do
{
wrefresh(stdscr);
v4 = stdscr;
v5 = wgetch(stdscr);
if ( v5 == 258 )
{
if ( v3 == 1 )
v3 = 2;
}
else if ( v5 > 258 )
{
if ( v5 == 259 && v3 == 2 )
v3 = 1;
}
else
{
if ( v5 == 81 )
goto LABEL_12;
if ( v5 > 81 )
{
if ( v5 != 113 )
goto LABEL_5;
LABEL_12:
ExitGame(v4, a2, v6);
goto LABEL_5;
}
if ( v5 == 10 )
{
v2 = v3;
}
else if ( v5 == 32 )
{
v2 = v3;
}
}
LABEL_5:
func2(v3);
if ( v2 == 1 )
{
wattrset(stdscr, 0);
return wrefresh(stdscr);
}
}
while ( v2 != 2 );
game[0] = 4;
wattrset(stdscr, 0);
return wrefresh(stdscr);
}

original_code:
void menuEndGame()
{
 int highlight = 1;
 int choice = 0;
 int c;
 engineStartMenuEnvironment();
 menuEndPrint(highlight);
 while(1)
 {
     wrefresh(stdscr);
     c = wgetch(stdscr);
  switch(c)
  {
      case 0403:
    if(highlight == 2)
     highlight = 1;
    break;
   case 0402:
    if(highlight == 1)
     highlight = 2;
    break;
   case 10: case ' ':
    choice = highlight;
    break;
   case 'q': case 'Q':
                    ExitGame();
                    break;
  }
  menuEndPrint(highlight);
  if(choice == 1){
   (wattrset(stdscr,(1U - 1U)));
   break;
     }
     else if(choice == 2){
         game.state = 4;
   (wattrset(stdscr,(1U - 1U)));
         break;
     }
 }
 wrefresh(stdscr);
 return;
}

variable_types: choice int

variable_types: c int


menuPrintWinner

decompiled_code:
int menuPrintWinner()
{
char v0; // al

init_pair(6, 1, 0);
init_pair(3, 4, 0);
v0 = game[12];
if ( v0 == 1 )
{
wattrset(stdscr, 768);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v0 == 2 )
{
wattrset(stdscr, 1536);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func4()
{
char v0; // al

init_pair(6, 1, 0);
init_pair(3, 4, 0);
v0 = game[12];
if ( v0 == 1 )
{
wattrset(stdscr, 768);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "BLUE SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 35, "YOU WON!!!");
}
}
else if ( v0 == 2 )
{
wattrset(stdscr, 1536);
wattr_on(stdscr, 0x200000uLL, 0LL);
if ( game[0] == 2 )
{
mvprintw(15, 31, "RED SNAKE WINS!!!");
}
else if ( game[0] == 1 )
{
mvprintw(15, 34, "YOU LOST :D");
}
}
return wrefresh(stdscr);
}


menuPauseGame

decompiled_code:
int menuPauseGame()
{
nodelay(stdscr, 0);
wgetch(stdscr);
return nodelay(stdscr, 1);
}

canonical_decompiled_code:
int func5()
{
nodelay(stdscr, 0);
wgetch(stdscr);
return nodelay(stdscr, 1);
}

original_code:
void menuPauseGame(){
    nodelay(stdscr, 0);
    wgetch(stdscr);
    nodelay(stdscr, 1);
}


snakeInit

original_code:
void snakeInit(){
    snake1.size = snake1.alive = snake2.size = snake2.alive = 1;
    snake1.head.x = 4; snake1.head.y = (24/2);
    snake2.head.x = (80 - 5); snake2.head.y = (24/2);
    snake1.marker = 1;
    snake2.marker = 2;
    snake1.colorcode = 1;
    snake2.colorcode = 2;
    snake1.headcolorcode = 5;
    snake2.headcolorcode = 6;
    game.map[snake1.head.x][snake1.head.y] = snake1.marker;
    game.map[snake2.head.x][snake2.head.y] = snake2.marker;
    snake1.direction = snake1.bot_newdirection = 1;
    snake2.direction = snake2.bot_newdirection = -1;
    (wmove((stdscr),((snake1.head.y)),((snake1.head.x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
    (wmove((stdscr),((snake2.head.y)),((snake2.head.x))) == (-1) ? (-1) : waddch((stdscr),((' '))));
}


repo: samm-git/atop-freebsd

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

result = socket(2, 3, 255);
netsock = result;
return result;
}

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

result = socket(2, 3, 255);
netsock = result;
return result;
}

original_code:
void
netatop_ipopen(void)
{
 netsock = socket(2, SOCK_RAW, IPPROTO_RAW);
}

canonical_original_code:
void netatop_ipopen()
{
 netsock = socket(2, SOCK_RAW, IPPROTO_RAW);
}


decompiled_code:
void netatop_probe()
{
int v0; // eax
int v1; // ebx
int v2; // eax
int v3; // ebp
unsigned int *v4; // rbx
struct stat v5; // [rsp+0h] [rbp-B8h] BYREF
socklen_t optlen; // [rsp+94h] [rbp-24h] BYREF
struct sembuf sops; // [rsp+9Ah] [rbp-1Eh] BYREF

sops.sem_num = 1;
sops.sem_op = -1;
sops.sem_flg = 4096;
optlen = 0;
if ( netsock != -1 )
{
if ( getsockopt(netsock, 0, 15661, 0LL, &optlen) )
{
supportflags &= 0xFFFFFFCF;
}
else
{
supportflags |= 0x10u;
if ( semid == -1 )
{
v0 = semget(1541961, 0, 0);
semid = v0;
if ( v0 == -1 || semop(v0, &sops, 1uLL) == -1 )
{
supportflags &= 0xFFFFFFDF;
return;
}
}
if ( semctl(semid, 0, 12, 0LL) != 1 )
{
supportflags &= 0xFFFFFFDF;
return;
}
v1 = netexitfd;
if ( netexitfd != -1 )
{
if ( !fstat(netexitfd, &v5) && v5.st_nlink )
{
supportflags |= 0x20u;
return;
}
close(v1);
if ( nahp )
munmap(nahp, 0x10uLL);
netexitfd = -1;
nahp = 0LL;
}
v2 = open("/var/run/netatop.log", 0, 0LL);
v3 = v2;
netexitfd = v2;
if ( v2 == -1 )
{
supportflags &= 0xFFFFFFDF;
}
else
{
v4 = (unsigned int *)mmap(0LL, 0x10uLL, 1, 1, v2, 0LL);
nahp = v4;
if ( v4 == (unsigned int *)-1LL )
{
close(v3);
netexitfd = -1;
nahp = 0LL;
supportflags &= 0xFFFFFFDF;
}
else
{
lseek(v3, 0LL, 2);
lastseq = v4[1];
supportflags |= 0x20u;
}
}
}
}
}

canonical_decompiled_code:
void func2()
{
int v0; // eax
int v1; // ebx
int v2; // eax
int v3; // ebp
unsigned int *v4; // rbx
struct stat v5; // [rsp+0h] [rbp-B8h] BYREF
socklen_t optlen; // [rsp+94h] [rbp-24h] BYREF
struct sembuf sops; // [rsp+9Ah] [rbp-1Eh] BYREF

sops.sem_num = 1;
sops.sem_op = -1;
sops.sem_flg = 4096;
optlen = 0;
if ( netsock != -1 )
{
if ( getsockopt(netsock, 0, 15661, 0LL, &optlen) )
{
supportflags &= 0xFFFFFFCF;
}
else
{
supportflags |= 0x10u;
if ( semid == -1 )
{
v0 = semget(1541961, 0, 0);
semid = v0;
if ( v0 == -1 || semop(v0, &sops, 1uLL) == -1 )
{
supportflags &= 0xFFFFFFDF;
return;
}
}
if ( semctl(semid, 0, 12, 0LL) != 1 )
{
supportflags &= 0xFFFFFFDF;
return;
}
v1 = netexitfd;
if ( netexitfd != -1 )
{
if ( !fstat(netexitfd, &v5) && v5.st_nlink )
{
supportflags |= 0x20u;
return;
}
close(v1);
if ( nahp )
munmap(nahp, 0x10uLL);
netexitfd = -1;
nahp = 0LL;
}
v2 = open("/var/run/netatop.log", 0, 0LL);
v3 = v2;
netexitfd = v2;
if ( v2 == -1 )
{
supportflags &= 0xFFFFFFDF;
}
else
{
v4 = (unsigned int *)mmap(0LL, 0x10uLL, 1, 1, v2, 0LL);
nahp = v4;
if ( v4 == (unsigned int *)-1LL )
{
close(v3);
netexitfd = -1;
nahp = 0LL;
supportflags &= 0xFFFFFFDF;
}
else
{
lseek(v3, 0LL, 2);
lastseq = v4[1];
supportflags |= 0x20u;
}
}
}
}
}

original_code:
void
netatop_probe(void)
{
 struct sembuf semdecr = {1, -1, 0x1000};
 socklen_t sl = 0;
 struct stat exstat;
 if (netsock == -1)
  return;
 if ( getsockopt(netsock, 0, (15661), ((void *)0), &sl) != 0)
 {
  supportflags &= ~0x00000010;
  supportflags &= ~0x00000020;
  return;
 }
 supportflags |= 0x00000010;
 if (semid == -1)
 {
  if ( (semid = semget(1541961, 0, 0)) == -1 ||
                       semop(semid, &semdecr, 1) == -1 )
  {
   supportflags &= ~0x00000020;
   return;
  }
 }
 if (semctl(semid, 0, 12, 0) != 1)
 {
  supportflags &= ~0x00000020;
  return;
 }
 if (netexitfd != -1)
 {
  if ( fstat(netexitfd, &exstat) == 0 &&
       exstat.st_nlink > 0 )
  {
   supportflags |= 0x00000020;
   return;
  }
  else
  {
   (void) close(netexitfd);
   if (nahp)
    munmap(nahp, sizeof *nahp);
   netexitfd = -1;
   nahp = ((void *)0);
  }
 }
 if (netexitfd == -1)
 {
  if ( (netexitfd = open("/var/run/netatop.log", 00, 0)) == -1)
  {
   supportflags &= ~0x00000020;
                 return;
  }
 }
 if ( (nahp = mmap((void *)0, sizeof *nahp, 0x1, 0x01,
      netexitfd, 0)) == (void *) -1)
 {
         (void) close(netexitfd);
  netexitfd = -1;
  nahp = ((void *)0);
  supportflags &= ~0x00000020;
  return;
 }
 (void) lseek(netexitfd, 0, 2);
 lastseq = nahp->curseq;
 supportflags |= 0x00000020;
}

canonical_original_code:
void netatop_probe()
{
 struct sembuf semdecr = {1, -1, 0x1000};
 unsigned int sl = 0;
 struct stat exstat;
 if (netsock == -1)
  return;
 if ( getsockopt(netsock, 0, (15661), ((void *)0), &sl) != 0)
 {
  supportflags &= ~0x00000010;
  supportflags &= ~0x00000020;
  return;
 }
 supportflags |= 0x00000010;
 if (semid == -1)
 {
  if ( (semid = semget(1541961, 0, 0)) == -1 ||
                       semop(semid, &semdecr, 1) == -1 )
  {
   supportflags &= ~0x00000020;
   return;
  }
 }
 if (semctl(semid, 0, 12, 0) != 1)
 {
  supportflags &= ~0x00000020;
  return;
 }
 if (netexitfd != -1)
 {
  if ( fstat(netexitfd, &exstat) == 0 &&
       exstat.st_nlink > 0 )
  {
   supportflags |= 0x00000020;
   return;
  }
  else
  {
   (void) close(netexitfd);
   if (nahp)
    munmap(nahp, sizeof *nahp);
   netexitfd = -1;
   nahp = ((void *)0);
  }
 }
 if (netexitfd == -1)
 {
  if ( (netexitfd = open("/var/run/netatop.log", 00, 0)) == -1)
  {
   supportflags &= ~0x00000020;
                 return;
  }
 }
 if ( (nahp = mmap((void *)0, sizeof *nahp, 0x1, 0x01,
      netexitfd, 0)) == (void *) -1)
 {
         (void) close(netexitfd);
  netexitfd = -1;
  nahp = ((void *)0);
  supportflags &= ~0x00000020;
  return;
 }
 (void) lseek(netexitfd, 0, 2);
 lastseq = nahp->curseq;
 supportflags |= 0x00000020;
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }

variable_types:
sl
unsigned int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void netatop_signoff()
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 1;
sops.sem_op = 1;
sops.sem_flg = 4096;
if ( netsock != -1 && nahp && (supportflags & 0x20) != 0 )
{
regainrootprivs();
semop(semid, &sops, 1uLL);
kill(*((_DWORD *)nahp + 3), 1);
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
munmap(nahp, 0x10uLL);
close(netexitfd);
}
}

canonical_decompiled_code:
void func3()
{
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = 1;
sops.sem_op = 1;
sops.sem_flg = 4096;
if ( netsock != -1 && nahp && (supportflags & 0x20) != 0 )
{
regainrootprivs();
semop(semid, &sops, 1uLL);
kill(*((_DWORD *)nahp + 3), 1);
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
munmap(nahp, 0x10uLL);
close(netexitfd);
}
}

original_code:
void
netatop_signoff(void)
{
 struct sembuf semincr = {1, +1, 0x1000};
 if (netsock == -1 || nahp == ((void *)0))
  return;
 if (supportflags & 0x00000020)
 {
         regainrootprivs();
         (void) semop(semid, &semincr, 1);
  kill(nahp->mypid, 1);
         if (! droprootprivs())
          cleanstop(42);
  (void) munmap(nahp, sizeof *nahp);
  (void) close(netexitfd);
 }
}

canonical_original_code:
void netatop_signoff()
{
 struct sembuf semincr = {1, +1, 0x1000};
 if (netsock == -1 || nahp == ((void *)0))
  return;
 if (supportflags & 0x00000020)
 {
         regainrootprivs();
         (void) semop(semid, &semincr, 1);
  kill(nahp->mypid, 1);
         if (! droprootprivs())
          cleanstop(42);
  (void) munmap(nahp, sizeof *nahp);
  (void) close(netexitfd);
 }
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall netatop_gettask(int a1, char a2, _QWORD *a3)
{
int result; // eax
socklen_t optlen; // [rsp+Ch] [rbp-7Ch] BYREF
int optval[8]; // [rsp+10h] [rbp-78h] BYREF
__int64 v7; // [rsp+30h] [rbp-58h]
__int64 v8; // [rsp+38h] [rbp-50h]
__int64 v9; // [rsp+40h] [rbp-48h]
__int64 v10; // [rsp+48h] [rbp-40h]
__int64 v11; // [rsp+50h] [rbp-38h]
__int64 v12; // [rsp+58h] [rbp-30h]
__int64 v13; // [rsp+60h] [rbp-28h]
__int64 v14; // [rsp+68h] [rbp-20h]

optlen = 96;
if ( (supportflags & 0x10) != 0 )
{
optval[0] = a1;
regainrootprivs();
if ( getsockopt(netsock, 0, (a2 != 103) + 15665, optval, &optlen) )
{
a3[78] = 0LL;
a3[91] = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
result = *_errno_location();
if ( result == 92 || result == 1 )
{
supportflags &= 0xFFFFFFCF;
result = close(netsock);
netsock = -1;
}
}
else
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
a3[78] = v7;
a3[80] = v9;
a3[79] = v8;
a3[81] = v10;
a3[82] = v11;
a3[84] = v13;
a3[83] = v12;
result = v14;
a3[85] = v14;
}
}
else
{
a3[78] = 0LL;
a3[91] = 0LL;
result = 0;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, char a2, _QWORD *a3)
{
int result; // eax
socklen_t optlen; // [rsp+Ch] [rbp-7Ch] BYREF
int optval[8]; // [rsp+10h] [rbp-78h] BYREF
__int64 v7; // [rsp+30h] [rbp-58h]
__int64 v8; // [rsp+38h] [rbp-50h]
__int64 v9; // [rsp+40h] [rbp-48h]
__int64 v10; // [rsp+48h] [rbp-40h]
__int64 v11; // [rsp+50h] [rbp-38h]
__int64 v12; // [rsp+58h] [rbp-30h]
__int64 v13; // [rsp+60h] [rbp-28h]
__int64 v14; // [rsp+68h] [rbp-20h]

optlen = 96;
if ( (supportflags & 0x10) != 0 )
{
optval[0] = a1;
regainrootprivs();
if ( getsockopt(netsock, 0, (a2 != 103) + 15665, optval, &optlen) )
{
a3[78] = 0LL;
a3[91] = 0LL;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
result = *_errno_location();
if ( result == 92 || result == 1 )
{
supportflags &= 0xFFFFFFCF;
result = close(netsock);
netsock = -1;
}
}
else
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
a3[78] = v7;
a3[80] = v9;
a3[79] = v8;
a3[81] = v10;
a3[82] = v11;
a3[84] = v13;
a3[83] = v12;
result = v14;
a3[85] = v14;
}
}
else
{
a3[78] = 0LL;
a3[91] = 0LL;
result = 0;
memset(
(void *)((unsigned __int64)(a3 + 79) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a3 - (((_DWORD)a3 + 632) & 0xFFFFFFF8) + 736) >> 3));
}
return result;
}

original_code:
void
netatop_gettask(pid_t id, char type, struct tstat *tp)
{
 struct netpertask npt;
 socklen_t socklen = sizeof npt;
 int cmd = (type == 'g' ?
        (15661 +4) : (15661 +5));
 if (!(supportflags & 0x00000010) ) {
  memset(&tp->net, 0, sizeof tp->net);
  return;
 }
 npt.id = id;
        regainrootprivs();
 if (getsockopt(netsock, 0, cmd, &npt, &socklen) != 0) {
  memset(&tp->net, 0, sizeof tp->net);
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return;
 }
        if (! droprootprivs())
         cleanstop(42);
 tp->net.tcpsnd = npt.tc.tcpsndpacks;
 tp->net.tcprcv = npt.tc.tcprcvpacks;
 tp->net.tcpssz = npt.tc.tcpsndbytes;
 tp->net.tcprsz = npt.tc.tcprcvbytes;
 tp->net.udpsnd = npt.tc.udpsndpacks;
 tp->net.udprcv = npt.tc.udprcvpacks;
 tp->net.udpssz = npt.tc.udpsndbytes;
 tp->net.udprsz = npt.tc.udprcvbytes;
}

canonical_original_code:
void netatop_gettask(int id, char type, struct tstat *tp)
{
 struct netpertask npt;
 unsigned int socklen = sizeof npt;
 int cmd = (type == 'g' ?
        (15661 +4) : (15661 +5));
 if (!(supportflags & 0x00000010) ) {
  memset(&tp->net, 0, sizeof tp->net);
  return;
 }
 npt.id = id;
        regainrootprivs();
 if (getsockopt(netsock, 0, cmd, &npt, &socklen) != 0) {
  memset(&tp->net, 0, sizeof tp->net);
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return;
 }
        if (! droprootprivs())
         cleanstop(42);
 tp->net.tcpsnd = npt.tc.tcpsndpacks;
 tp->net.tcprcv = npt.tc.tcprcvpacks;
 tp->net.tcpssz = npt.tc.tcpsndbytes;
 tp->net.tcprsz = npt.tc.tcprcvbytes;
 tp->net.udpsnd = npt.tc.udpsndpacks;
 tp->net.udprcv = npt.tc.udprcvpacks;
 tp->net.udpssz = npt.tc.udpsndbytes;
 tp->net.udprsz = npt.tc.udprcvbytes;
}

variable_types: id int

variable_types: type char

variable_types: struct tstat { struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; } gen; struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; } cpu; struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; } dsk; struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; } mem; struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; } net; } *

variable_types: struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; } tc; }

variable_types:
socklen
unsigned int

variable_types: cmd int

user_defined_types: struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount tc; }

user_defined_types: struct tstat { struct gen gen; struct cpu cpu; struct dsk dsk; struct mem mem; struct net net; }


decompiled_code:
__int64 __fastcall netatop_exitstore(__int64 a1)
{
unsigned __int16 v1; // cx
void *v2; // rsp
void *v3; // rsp
int v4; // ebx
unsigned int v5; // eax
__m128i *v6; // r12
unsigned int v7; // er13
__m128i *v8; // r12
int v9; // eax
int v11; // eax
unsigned int v12; // ebx
unsigned __int16 v13; // ax
__m128i v14; // [rsp+0h] [rbp-60h] BYREF
__m128i v15; // [rsp+10h] [rbp-50h] BYREF
__m128i v16; // [rsp+20h] [rbp-40h] BYREF
__m128i v17; // [rsp+30h] [rbp-30h] BYREF
__m128i v18; // [rsp+40h] [rbp-20h] BYREF
__m128i v19; // [rsp+50h] [rbp-10h] BYREF

v16.m128i_i32[3] = 0;
v1 = *((_WORD *)nahp + 5);
v2 = alloca(16 * (((unsigned __int64)v1 + 115) / 0x10));
v3 = alloca(16 * (((unsigned __int64)v1 + 15) / 0x10));
regainrootprivs(a1, 16LL, ((unsigned __int64)v1 + 15) % 0x10);
v4 = netsock;
if ( getsockopt(netsock, 0, 15662, 0LL, &v16.m128i_u32[3]) )
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v9 = *_errno_location();
if ( v9 != 92 )
{
v7 = 0;
if ( v9 != 1 )
return v7;
}
LABEL_17:
supportflags &= 0xFFFFFFCF;
close(netsock);
netsock = -1;
return 0;
}
if ( getsockopt(v4, 0, 15663, 0LL, &v16.m128i_u32[3]) )
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v11 = *_errno_location();
if ( v11 != 92 )
{
v7 = 0;
if ( v11 != 1 )
return v7;
}
goto LABEL_17;
}
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v5 = *((_DWORD *)nahp + 1);
v14.m128i_i32[3] = v5 - lastseq;
lastseq = v5;
exitall = malloc(112LL * v14.m128i_u32[3]);
ptrverify(exitall, "Malloc failed for %d exited netprocs\n", v14.m128i_u32[3]);
v6 = (__m128i *)exitall;
memset(exitall, 0, 112LL * v14.m128i_u32[3]);
v7 = 0;
v8 = v6 + 1;
if ( read(netexitfd, (char *)&v15.m128i_u64[1] + 7, 1uLL) == 1 )
{
while ( 1 )
{
v12 = read(netexitfd, &v14, v15.m128i_u8[15] + 1LL);
v14.m128i_i32[2] = v12;
if ( v15.m128i_u8[15] > v12 )
break;
v13 = *((_WORD *)nahp + 5);
v16.m128i_i64[0] = v13;
if ( v13 > 0x60u )
{
uncompress(&v14, &v16, &v14, v15.m128i_u8[15]);
*v8 = _mm_loadu_si128(&v14);
v8[1] = _mm_loadu_si128(&v15);
v8[2] = _mm_loadu_si128(&v16);
v8[3] = _mm_loadu_si128(&v17);
v8[4] = _mm_loadu_si128(&v18);
v8[5] = _mm_loadu_si128(&v19);
}
else
{
uncompress(v8, &v16, &v14, v15.m128i_u8[15]);
}
if ( v14.m128i_i32[3] == ++v7 )
{
if ( (unsigned int)v15.m128i_u8[15] < v14.m128i_i32[2] )
lseek(netexitfd, -1LL, 1);
break;
}
v8 += 7;
if ( v15.m128i_u8[15] >= v12 )
break;
v15.m128i_i8[15] = v14.m128i_i8[v15.m128i_u8[15]];
}
exitnum = v7;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned __int16 v1; // cx
void *v2; // rsp
void *v3; // rsp
int v4; // ebx
unsigned int v5; // eax
__m128i *v6; // r12
unsigned int v7; // er13
__m128i *v8; // r12
int v9; // eax
int v11; // eax
unsigned int v12; // ebx
unsigned __int16 v13; // ax
__m128i v14; // [rsp+0h] [rbp-60h] BYREF
__m128i v15; // [rsp+10h] [rbp-50h] BYREF
__m128i v16; // [rsp+20h] [rbp-40h] BYREF
__m128i v17; // [rsp+30h] [rbp-30h] BYREF
__m128i v18; // [rsp+40h] [rbp-20h] BYREF
__m128i v19; // [rsp+50h] [rbp-10h] BYREF

v16.m128i_i32[3] = 0;
v1 = *((_WORD *)nahp + 5);
v2 = alloca(16 * (((unsigned __int64)v1 + 115) / 0x10));
v3 = alloca(16 * (((unsigned __int64)v1 + 15) / 0x10));
regainrootprivs(a1, 16LL, ((unsigned __int64)v1 + 15) % 0x10);
v4 = netsock;
if ( getsockopt(netsock, 0, 15662, 0LL, &v16.m128i_u32[3]) )
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v9 = *_errno_location();
if ( v9 != 92 )
{
v7 = 0;
if ( v9 != 1 )
return v7;
}
LABEL_17:
supportflags &= 0xFFFFFFCF;
close(netsock);
netsock = -1;
return 0;
}
if ( getsockopt(v4, 0, 15663, 0LL, &v16.m128i_u32[3]) )
{
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v11 = *_errno_location();
if ( v11 != 92 )
{
v7 = 0;
if ( v11 != 1 )
return v7;
}
goto LABEL_17;
}
if ( !(unsigned int)droprootprivs() )
cleanstop(42LL);
v5 = *((_DWORD *)nahp + 1);
v14.m128i_i32[3] = v5 - lastseq;
lastseq = v5;
exitall = malloc(112LL * v14.m128i_u32[3]);
ptrverify(exitall, "Malloc failed for %d exited netprocs\n", v14.m128i_u32[3]);
v6 = (__m128i *)exitall;
memset(exitall, 0, 112LL * v14.m128i_u32[3]);
v7 = 0;
v8 = v6 + 1;
if ( read(netexitfd, (char *)&v15.m128i_u64[1] + 7, 1uLL) == 1 )
{
while ( 1 )
{
v12 = read(netexitfd, &v14, v15.m128i_u8[15] + 1LL);
v14.m128i_i32[2] = v12;
if ( v15.m128i_u8[15] > v12 )
break;
v13 = *((_WORD *)nahp + 5);
v16.m128i_i64[0] = v13;
if ( v13 > 0x60u )
{
uncompress(&v14, &v16, &v14, v15.m128i_u8[15]);
*v8 = _mm_loadu_si128(&v14);
v8[1] = _mm_loadu_si128(&v15);
v8[2] = _mm_loadu_si128(&v16);
v8[3] = _mm_loadu_si128(&v17);
v8[4] = _mm_loadu_si128(&v18);
v8[5] = _mm_loadu_si128(&v19);
}
else
{
uncompress(v8, &v16, &v14, v15.m128i_u8[15]);
}
if ( v14.m128i_i32[3] == ++v7 )
{
if ( (unsigned int)v15.m128i_u8[15] < v14.m128i_i32[2] )
lseek(netexitfd, -1LL, 1);
break;
}
v8 += 7;
if ( v15.m128i_u8[15] >= v12 )
break;
v15.m128i_i8[15] = v14.m128i_i8[v15.m128i_u8[15]];
}
exitnum = v7;
}
return v7;
}

original_code:
unsigned int
netatop_exitstore(void)
{
 socklen_t socklen = 0, nexitnet, sz, nr=0;
 unsigned long uncomplen;
 unsigned char nextsize;
 unsigned char readbuf[nahp->ntplen+100];
 unsigned char databuf[nahp->ntplen];
 struct netpertask *tmp = (struct netpertask *)databuf;
 struct exitstore *esp;
        regainrootprivs();
 if (getsockopt(netsock, 0, (15661 +1), ((void *)0), &socklen)!=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
 if (getsockopt(netsock, 0, (15661 +2), 0, &socklen) !=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
        if (! droprootprivs())
         cleanstop(42);
 nexitnet = nahp->curseq - lastseq;
 lastseq = nahp->curseq;
 exitall = malloc(nexitnet * sizeof(struct exitstore));
 ptrverify(exitall, "Malloc failed for %d exited netprocs\n", nexitnet);
 memset(exitall, 0, nexitnet * sizeof(struct exitstore));
 esp = exitall;
 if ( read(netexitfd, &nextsize, 1) != 1)
  return 0;
 while ( (sz = read(netexitfd, readbuf, nextsize+1)) >= nextsize)
 {
         uncomplen = nahp->ntplen;
  if (nahp->ntplen <= sizeof(struct netpertask))
  {
   (void) uncompress((Byte *)&(esp->npt), &uncomplen,
       readbuf, nextsize);
  }
  else
  {
   (void) uncompress((Byte *)databuf, &uncomplen,
       readbuf, nextsize);
   esp->npt = *tmp;
  }
  esp++;
  nr++;
  if (nr == nexitnet)
  {
   if (sz > nextsize)
    (void) lseek(netexitfd, -1, 1);
   break;
  }
  if (sz > nextsize)
   nextsize = readbuf[nextsize];
  else
   break;
 }
 exitnum = nr;
 return nr;
}

canonical_original_code:
unsigned int netatop_exitstore()
{
 unsigned int socklen = 0; unsigned int nexitnet; unsigned int sz; unsigned int nr = 0;
 unsigned long uncomplen;
 unsigned char nextsize;
 unsigned char readbuf[-1];
 unsigned char databuf[-1];
 struct netpertask *tmp = (struct netpertask *)databuf;
 struct exitstore *esp;
        regainrootprivs();
 if (getsockopt(netsock, 0, (15661 +1), ((void *)0), &socklen)!=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
 if (getsockopt(netsock, 0, (15661 +2), 0, &socklen) !=0) {
         if (! droprootprivs())
          cleanstop(42);
  if ((*__errno_location ()) == 92 || (*__errno_location ()) == 1)
  {
   supportflags &= ~0x00000010;
   supportflags &= ~0x00000020;
   close(netsock);
   netsock = -1;
  }
  return 0;
 }
        if (! droprootprivs())
         cleanstop(42);
 nexitnet = nahp->curseq - lastseq;
 lastseq = nahp->curseq;
 exitall = malloc(nexitnet * sizeof(struct exitstore));
 ptrverify(exitall, "Malloc failed for %d exited netprocs\n", nexitnet);
 memset(exitall, 0, nexitnet * sizeof(struct exitstore));
 esp = exitall;
 if ( read(netexitfd, &nextsize, 1) != 1)
  return 0;
 while ( (sz = read(netexitfd, readbuf, nextsize+1)) >= nextsize)
 {
         uncomplen = nahp->ntplen;
  if (nahp->ntplen <= sizeof(struct netpertask))
  {
   (void) uncompress((unsigned char *)&(esp->npt), &uncomplen,
       readbuf, nextsize);
  }
  else
  {
   (void) uncompress((unsigned char *)databuf, &uncomplen,
       readbuf, nextsize);
   esp->npt = *tmp;
  }
  esp++;
  nr++;
  if (nr == nexitnet)
  {
   if (sz > nextsize)
    (void) lseek(netexitfd, -1, 1);
   break;
  }
  if (sz > nextsize)
   nextsize = readbuf[nextsize];
  else
   break;
 }
 exitnum = nr;
 return nr;
}

variable_types:
nexitnet
unsigned int

variable_types:
sz
unsigned int

variable_types:
nr
unsigned int

variable_types:
uncomplen
unsigned long

variable_types:
nextsize
unsigned char

variable_types:
readbuf
unsigned char [-1]

variable_types:
databuf
unsigned char [-1]

variable_types: struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; } tc; } *

variable_types: struct exitstore { struct exitstore *next; unsigned char isused; struct netpertask { int id; unsigned long btime; char command[16]; struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; } tc; } npt; } *

return_type: unsigned int

user_defined_types: struct exitstore { struct exitstore *next; unsigned char isused; struct netpertask npt; }


decompiled_code:
__int64 netatop_exiterase()
{
__int64 result; // rax

free(exitall);
result = 0LL;
memset(&esbucket, 0, 0x2000uLL);
exitnum = 0;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

free(exitall);
result = 0LL;
memset(&esbucket, 0, 0x2000uLL);
exitnum = 0;
return result;
}

original_code:
void
netatop_exiterase(void)
{
 free(exitall);
 memset(esbucket, 0, sizeof esbucket);
 exitnum = 0;
}

canonical_original_code:
void netatop_exiterase()
{
 free(exitall);
 memset(esbucket, 0, sizeof esbucket);
 exitnum = 0;
}


decompiled_code:
__int64 __fastcall netatop_exithash(char a1)
{
char *v1; // rdx
__int64 result; // rax
char *v3; // rsi

v1 = (char *)exitall;
result = (unsigned int)exitnum;
if ( exitnum > 0 )
{
v3 = (char *)exitall + 112 * (unsigned int)exitnum;
do
{
if ( a1 == 112 )
LODWORD(result) = *((_DWORD *)v1 + 4) & 0x3FF;
else
LODWORD(result) = *((_DWORD *)v1 + 6) & 0x3FF;
result = (int)result;
*(_QWORD *)v1 = esbucket[(int)result];
esbucket[(int)result] = (__int64)v1;
v1 += 112;
}
while ( v1 != v3 );
}
exithash = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
char *v1; // rdx
__int64 result; // rax
char *v3; // rsi

v1 = (char *)exitall;
result = (unsigned int)exitnum;
if ( exitnum > 0 )
{
v3 = (char *)exitall + 112 * (unsigned int)exitnum;
do
{
if ( a1 == 112 )
LODWORD(result) = *((_DWORD *)v1 + 4) & 0x3FF;
else
LODWORD(result) = *((_DWORD *)v1 + 6) & 0x3FF;
result = (int)result;
*(_QWORD *)v1 = esbucket[(int)result];
esbucket[(int)result] = (__int64)v1;
v1 += 112;
}
while ( v1 != v3 );
}
exithash = a1;
return result;
}

original_code:
void
netatop_exithash(char hashtype)
{
 int i, h;
 struct exitstore *esp;
 for (i=0, esp=exitall; i < exitnum; i++, esp++)
 {
  if (hashtype == 'p')
   h = ((esp->npt.id)&(1024 -1));
  else
   h = ((esp->npt.btime)&(1024 -1));
  esp->next = esbucket[h];
  esbucket[h] = esp;
 }
 exithash = hashtype;
}

canonical_original_code:
void netatop_exithash(char hashtype)
{
 int i; int h;
 struct exitstore *esp;
 for (i=0, esp=exitall; i < exitnum; i++, esp++)
 {
  if (hashtype == 'p')
   h = ((esp->npt.id)&(1024 -1));
  else
   h = ((esp->npt.btime)&(1024 -1));
  esp->next = esbucket[h];
  esbucket[h] = esp;
 }
 exithash = hashtype;
}

variable_types: hashtype char

variable_types: i int

variable_types: h int

user_defined_types: struct taskcount { unsigned long long tcpsndpacks; unsigned long long tcpsndbytes; unsigned long long tcprcvpacks; unsigned long long tcprcvbytes; unsigned long long udpsndpacks; unsigned long long udpsndbytes; unsigned long long udprcvpacks; unsigned long long udprcvbytes; }


original_code:
void
netatop_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre)
{
 int h = ((key)&(1024 -1));
 struct exitstore *esp;
 if ( (esp = esbucket[h]) == ((void *)0))
  return;
 for (; esp; esp=esp->next)
 {
  switch (exithash)
  {
     case 'p':
   if (key != esp->npt.id)
    continue;
   fill_networkcnt(dev, pre, esp);
   break;
     case 'b':
   if (esp->isused)
    continue;
   if (key != esp->npt.btime)
    continue;
   if ( strcmp(esp->npt.command, pre->gen.name) != 0)
    continue;
   if (esp->npt.tc.tcpsndpacks < pre->net.tcpsnd ||
       esp->npt.tc.tcpsndbytes < pre->net.tcpssz ||
       esp->npt.tc.tcprcvpacks < pre->net.tcprcv ||
       esp->npt.tc.tcprcvbytes < pre->net.tcprsz ||
       esp->npt.tc.udpsndpacks < pre->net.udpsnd ||
       esp->npt.tc.udpsndbytes < pre->net.udpssz ||
       esp->npt.tc.udprcvpacks < pre->net.udprcv ||
       esp->npt.tc.udprcvbytes < pre->net.udprsz )
    continue;
   esp->isused = 1;
   fill_networkcnt(dev, pre, esp);
   break;
  }
 }
}

variable_types:
key
unsigned long

variable_types:
pre
struct tstat *

user_defined_types: struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; }

user_defined_types: struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; }

user_defined_types: struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; }

user_defined_types: struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; }

user_defined_types: struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; }


decompiled_code:
void getusr1()
{
awaittrigger = 0;
}

canonical_decompiled_code:
void func0()
{
awaittrigger = 0;
}

original_code:
void
getusr1(int sig)
{
 awaittrigger=0;
}

variable_types: sig int


decompiled_code:
__int64 getusr2()
{
__int64 result; // rax

awaittrigger = 0;
result = sampcnt;
nsamples = sampcnt;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

awaittrigger = 0;
result = sampcnt;
nsamples = sampcnt;
return result;
}

original_code:
void
getusr2(int sig)
{
 awaittrigger=0;
 nsamples = sampcnt;
}


getalarm

decompiled_code:
unsigned int getalarm()
{
unsigned int result; // eax

awaittrigger = 0;
if ( *(_QWORD *)&interval )
result = alarm(interval);
return result;
}

canonical_decompiled_code:
unsigned int func3()
{
unsigned int result; // eax

awaittrigger = 0;
if ( *(_QWORD *)&interval )
result = alarm(interval);
return result;
}

original_code:
void
getalarm(int sig)
{
 awaittrigger=0;
 if (interval > 0)
  alarm(interval);
}


decompiled_code:
__int64 do_interval()
{
__int64 result; // rax

result = (int)get_posval();
*(_QWORD *)&interval = (int)result;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

result = (int)get_posval();
*(_QWORD *)&interval = (int)result;
return result;
}

original_code:
void
do_interval(char *name, char *val)
{
 interval = get_posval(name, val);
}

variable_types:
name
char *

variable_types:
val
char *


decompiled_code:
__int64 do_linelength()
{
__int64 result; // rax

result = get_posval();
linelen = result;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

result = get_posval();
linelen = result;
return result;
}

original_code:
void
do_linelength(char *name, char *val)
{
 linelen = get_posval(name, val);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // r12
char *v5; // rax
int v6; // er12
char *v7; // rax
__int64 v8; // rdx
int v10; // eax
const char *v11; // rax
int v12; // eax
const char **v13; // rcx
int v14; // er12
__int64 v15; // r13
char v16[1024]; // [rsp+0h] [rbp-438h] BYREF
struct rlimit rlimits; // [rsp+400h] [rbp-38h] BYREF

if ( !(unsigned int)droprootprivs(argc, argv, envp) )
{
fwrite("not possible to drop root privs\n", 1uLL, 0x20uLL, stderr);
exit(42);
}
argvp = (__int64)argv;
readrc("/etc/atoprc");
v3 = getenv("HOME");
if ( v3 )
{
snprintf(v16, 0x400uLL, "%s/.atoprc", v3);
readrc(v16);
}
v4 = *argv;
v5 = strrchr(*argv, 47);
if ( v5 )
v4 = v5 + 1;
if ( !memcmp(v4, "atopsar", 7uLL) )
return atopsar((unsigned int)argc, argv);
v6 = 0;
if ( argc > 1 )
{
do
{
v10 = getopt(argc, (char *const *)argv, "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ");
if ( v10 == -1 )
break;
switch ( v10 )
{
case '?':
goto LABEL_17;
case 'L':
if ( !(unsigned int)numeric(optarg) )
prusage(*argv);
linelen = atoi(optarg);
break;
case 'P':
if ( !(unsigned int)parsedef(optarg) )
prusage(*argv);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&parseout;
break;
case 'S':
++midnightflag;
break;
case 'V':
v11 = (const char *)getstrvers();
puts(v11);
exit(0);
case 'a':
deviatonly = 0;
break;
case 'b':
if ( !(unsigned int)hhmm2secs(optarg, &begintime) )
goto LABEL_17;
break;
case 'e':
if ( !(unsigned int)hhmm2secs(optarg, &endtime) )
LABEL_17:
prusage(*argv);
break;
case 'r':
if ( optind < argc )
{
v13 = &argv[optind];
if ( **v13 != 45 )
{
++optind;
strncpy(rawname, *v13, 0xFFuLL);
}
}
++rawreadflag;
break;
case 'w':
if ( optind >= argc )
prusage(*argv);
v12 = optind++;
strncpy(rawname, argv[v12], 0xFFuLL);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&rawwrite;
break;
default:
flaglist[v6++] = v10;
break;
}
}
while ( v6 <= 62 );
if ( optind <= 63 && optind < argc )
{
if ( !(unsigned int)numeric(argv[optind]) )
prusage(*argv);
v14 = optind;
v15 = optind;
*(_QWORD *)&interval = atoi(argv[v15]);
optind = v14 + 1;
if ( v14 + 1 < argc )
{
if ( !(unsigned int)numeric(argv[v15 + 1]) )
prusage(*argv);
nsamples = atoi(argv[optind]);
if ( !nsamples )
prusage(*argv);
}
}
}
uname(&utsname);
v7 = strchr((const char *)(unsigned int)((_DWORD)&utsname + 65), 46);
if ( v7 )
*v7 = 0;
utsnodenamelen = strlen((const char *)(unsigned int)((_DWORD)&utsname + 65));
_isoc99_sscanf((unsigned int)((_DWORD)&utsname + 130), "%d.%d.%d", &osrel, &osvers, &ossub);
hertz = sysconf(2);
pagesize = sysconf(30);
if ( rawreadflag )
{
rawread();
cleanstop(0);
}
curtime = getboot() / (unsigned __int64)(unsigned __int16)hertz;
signal(1, (__sighandler_t)&cleanstop);
signal(15, (__sighandler_t)&cleanstop);
regainrootprivs();
rlimits.rlim_cur = -1LL;
rlimits.rlim_max = -1LL;
setrlimit(__RLIMIT_MEMLOCK, &rlimits);
mlockall(3);
nice(-20);
acctreason = acctswon();
initifprop();
netatop_ipopen();
if ( !(unsigned int)droprootprivs(4294967276LL, &rlimits, v8) )
cleanstop(42);
engine();
cleanstop(0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // r12
char *v5; // rax
int v6; // er12
char *v7; // rax
__int64 v8; // rdx
int v10; // eax
const char *v11; // rax
int v12; // eax
const char **v13; // rcx
int v14; // er12
__int64 v15; // r13
char v16[1024]; // [rsp+0h] [rbp-438h] BYREF
struct rlimit rlimits; // [rsp+400h] [rbp-38h] BYREF

if ( !(unsigned int)droprootprivs(argc, argv, envp) )
{
fwrite("not possible to drop root privs\n", 1uLL, 0x20uLL, stderr);
exit(42);
}
argvp = (__int64)argv;
func2("/etc/atoprc");
v3 = getenv("HOME");
if ( v3 )
{
snprintf(v16, 0x400uLL, "%s/.atoprc", v3);
func2(v16);
}
v4 = *argv;
v5 = strrchr(*argv, 47);
if ( v5 )
v4 = v5 + 1;
if ( !memcmp(v4, "atopsar", 7uLL) )
return atopsar((unsigned int)argc, argv);
v6 = 0;
if ( argc > 1 )
{
do
{
v10 = getopt(argc, (char *const *)argv, "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ");
if ( v10 == -1 )
break;
switch ( v10 )
{
case '?':
goto LABEL_17;
case 'L':
if ( !(unsigned int)numeric(optarg) )
prusage(*argv);
linelen = atoi(optarg);
break;
case 'P':
if ( !(unsigned int)parsedef(optarg) )
prusage(*argv);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&parseout;
break;
case 'S':
++midnightflag;
break;
case 'V':
v11 = (const char *)getstrvers();
puts(v11);
exit(0);
case 'a':
deviatonly = 0;
break;
case 'b':
if ( !(unsigned int)hhmm2secs(optarg, &begintime) )
goto LABEL_17;
break;
case 'e':
if ( !(unsigned int)hhmm2secs(optarg, &endtime) )
LABEL_17:
prusage(*argv);
break;
case 'r':
if ( optind < argc )
{
v13 = &argv[optind];
if ( **v13 != 45 )
{
++optind;
strncpy(rawname, *v13, 0xFFuLL);
}
}
++rawreadflag;
break;
case 'w':
if ( optind >= argc )
prusage(*argv);
v12 = optind++;
strncpy(rawname, argv[v12], 0xFFuLL);
vis = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))&rawwrite;
break;
default:
flaglist[v6++] = v10;
break;
}
}
while ( v6 <= 62 );
if ( optind <= 63 && optind < argc )
{
if ( !(unsigned int)numeric(argv[optind]) )
prusage(*argv);
v14 = optind;
v15 = optind;
*(_QWORD *)&interval = atoi(argv[v15]);
optind = v14 + 1;
if ( v14 + 1 < argc )
{
if ( !(unsigned int)numeric(argv[v15 + 1]) )
prusage(*argv);
nsamples = atoi(argv[optind]);
if ( !nsamples )
prusage(*argv);
}
}
}
uname(&utsname);
v7 = strchr((const char *)(unsigned int)((_DWORD)&utsname + 65), 46);
if ( v7 )
*v7 = 0;
utsnodenamelen = strlen((const char *)(unsigned int)((_DWORD)&utsname + 65));
_isoc99_sscanf((unsigned int)((_DWORD)&utsname + 130), "%d.%d.%d", &osrel, &osvers, &ossub);
hertz = sysconf(2);
pagesize = sysconf(30);
if ( rawreadflag )
{
rawread();
cleanstop(0);
}
curtime = getboot() / (unsigned __int64)(unsigned __int16)hertz;
signal(1, (__sighandler_t)&cleanstop);
signal(15, (__sighandler_t)&cleanstop);
regainrootprivs();
rlimits.rlim_cur = -1LL;
rlimits.rlim_max = -1LL;
setrlimit(__RLIMIT_MEMLOCK, &rlimits);
mlockall(3);
nice(-20);
acctreason = acctswon();
initifprop();
netatop_ipopen();
if ( !(unsigned int)droprootprivs(4294967276LL, &rlimits, v8) )
cleanstop(42);
func4();
cleanstop(0);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 register int i;
 int c;
 char *p;
 struct rlimit rlim;
        if (! droprootprivs() )
 {
  fprintf(stderr, "not possible to drop root privs\n");
                exit(42);
 }
 argvp = argv;
 readrc("/etc/atoprc");
 if ( (p = getenv("HOME")) )
 {
  char path[1024];
  snprintf(path, sizeof path, "%s/.atoprc", p);
  readrc(path);
 }
 if ( (p = strrchr(argv[0], '/')))
  p++;
 else
  p = argv[0];
 if ( memcmp(p, "atopsar", 7) == 0)
  return atopsar(argc, argv);
 if (argc > 1)
 {
  i = 0;
  while (i < 64 -1 && (c=getopt(argc, argv, "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ")) != (-1))
  {
   switch (c)
   {
      case '?':
    prusage(argv[0]);
    break;
      case 'V':
    printf("%s\n", getstrvers());
    exit(0);
      case 'w':
    if (optind >= argc)
     prusage(argv[0]);
    strncpy(rawname, argv[optind++], 256 -1);
    vis.show_samp = rawwrite;
    break;
      case 'r':
    if (optind < argc && *(argv[optind]) != '-')
     strncpy(rawname, argv[optind++],
       256 -1);
    rawreadflag++;
    break;
      case 'S':
    midnightflag++;
    break;
                           case 'a':
    deviatonly=0;
    break;
                           case 'b':
    if ( !hhmm2secs(optarg, &begintime) )
     prusage(argv[0]);
    break;
                           case 'e':
    if ( !hhmm2secs(optarg, &endtime) )
     prusage(argv[0]);
    break;
                           case 'P':
    if ( !parsedef(optarg) )
     prusage(argv[0]);
    vis.show_samp = parseout;
    break;
                           case 'L':
    if ( !numeric(optarg) )
     prusage(argv[0]);
    linelen = atoi(optarg);
    break;
      default:
    flaglist[i++] = c;
   }
  }
   if (optind < argc && optind < 64)
  {
   if (!numeric(argv[optind]))
    prusage(argv[0]);
   interval = atoi(argv[optind]);
   optind++;
   if (optind < argc)
   {
    if (!numeric(argv[optind]) )
     prusage(argv[0]);
    if ( (nsamples = atoi(argv[optind])) < 1)
     prusage(argv[0]);
   }
  }
 }
 (void) uname(&utsname);
 if ( (p = strchr(utsname.nodename, '.')) )
  *p = '\0';
 utsnodenamelen = strlen(utsname.nodename);
 sscanf(utsname.release, "%d.%d.%d", &osrel, &osvers, &ossub);
 hertz = sysconf(_SC_CLK_TCK);
 pagesize = sysconf(_SC_PAGESIZE);
 if (rawreadflag)
 {
  rawread();
  cleanstop(0);
 }
 curtime = getboot() / hertz;
 signal(1, cleanstop);
 signal(15, cleanstop);
 regainrootprivs();
 rlim.rlim_cur = ((__rlim_t) -1);
 rlim.rlim_max = ((__rlim_t) -1);
 (void) setrlimit(__RLIMIT_MEMLOCK, &rlim);
 (void) mlockall(1|2);
 if ( nice(-20) == -1)
  ;
 acctreason = acctswon();
 initifprop();
 netatop_ipopen();
        if (! droprootprivs() )
  cleanstop(42);
 engine();
 cleanstop(0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
p
char *

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types:
path
char [1024]


engine

decompiled_code:
int engine()
{
unsigned __int64 v0; // rax
struct tm *v1; // rax
int v2; // ebx
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // r13
unsigned int v6; // er14
char *v7; // r12
unsigned int v8; // er15
_QWORD *v9; // rbp
char *v10; // rax
int v11; // edx
__int64 v12; // rsi
char v13; // bl
void *v14; // rax
void *ptr; // [rsp+8h] [rbp-110h]
unsigned int v17; // [rsp+18h] [rbp-100h]
int v18; // [rsp+1Ch] [rbp-FCh]
time_t timer; // [rsp+20h] [rbp-F8h] BYREF
unsigned int v20; // [rsp+28h] [rbp-F0h] BYREF
unsigned int v21; // [rsp+2Ch] [rbp-ECh] BYREF
unsigned int v22; // [rsp+30h] [rbp-E8h] BYREF
unsigned int v23; // [rsp+34h] [rbp-E4h] BYREF
unsigned int v24; // [rsp+38h] [rbp-E0h] BYREF
unsigned int v25; // [rsp+3Ch] [rbp-DCh] BYREF
struct sigaction v26; // [rsp+40h] [rbp-D8h] BYREF

cursstat_6 = calloc(1uLL, 0x71538uLL);
presstat_5 = (__int64)calloc(1uLL, 0x71538uLL);
devsstat_4 = (__int64)calloc(1uLL, 0x71538uLL);
curplen_3 = (3 * (unsigned int)countprocs()) >> 1;
curpact_2 = calloc(curplen_3, 0x2E0uLL);
ptrverify(cursstat_6, "Malloc failed for current sysstats\n");
ptrverify(presstat_5, "Malloc failed for prev sysstats\n");
ptrverify(devsstat_4, "Malloc failed for deviate sysstats\n");
ptrverify(curpact_2, "Malloc failed for %d procstats\n", (unsigned int)curplen_3);
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_handler = (__sighandler_t)getusr1;
sigaction(10, &v26, 0LL);
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_handler = (__sighandler_t)getusr2;
sigaction(12, &v26, 0LL);
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_handler = (__sighandler_t)getalarm;
LODWORD(v0) = sigaction(14, &v26, 0LL);
if ( *(_QWORD *)&interval )
LODWORD(v0) = alarm(interval);
if ( midnightflag )
{
timer = time(0LL);
v1 = localtime(&timer);
v1->tm_hour = 23;
v1->tm_min = 59;
v1->tm_sec = 59;
v0 = mktime(v1);
timelimit_1 = v0;
}
sampcnt = 0LL;
if ( nsamples )
{
v0 = 0LL;
while ( 1 )
{
if ( midnightflag && curtime + *(_QWORD *)&interval > (unsigned __int64)timelimit_1 )
return v0;
if ( v0 && awaittrigger )
pause();
awaittrigger = 1;
pretime = curtime;
curtime = time(0LL);
v14 = cursstat_6;
cursstat_6 = (void *)presstat_5;
presstat_5 = (__int64)v14;
photosyst();
deviatsyst(cursstat_6, presstat_5, devsstat_4);
memset(curpact_2, 0, 736LL * curplen_3);
while ( 1 )
{
v3 = (unsigned int)photoproc(curpact_2, (unsigned int)curplen_3);
if ( (_DWORD)v3 != curplen_3 )
break;
v2 = curplen_3 + 100;
curplen_3 = v2;
curpact_2 = realloc(curpact_2, 736LL * v2);
ptrverify(curpact_2, "Realloc failed for %d tasks\n", (unsigned int)v2);
memset(curpact_2, 0, 736LL * curplen_3);
}
v4 = acctprocnt();
v5 = v4;
if ( v4 > 0x11642 )
break;
if ( v4 )
{
v6 = v4;
v5 = 0LL;
LABEL_11:
if ( (supportflags & 0x20) != 0 )
v18 = netatop_exitstore();
else
v18 = 0;
ptr = malloc(736LL * v6);
ptrverify(ptr, "Malloc failed for %d exited processes\n", v6);
memset(ptr, 0, 736LL * v6);
acctphotoproc(ptr, v6);
if ( (_DWORD)v5 )
acctrepos((unsigned int)v5);
goto LABEL_13;
}
v6 = 0;
v18 = 0;
ptr = 0LL;
LABEL_13:
v7 = (char *)malloc(736LL * ((unsigned int)v3 + v6));
ptrverify(v7, "Malloc failed for %d modified processes\n", (unsigned int)v3 + v6);
v8 = deviatproc(
curpact_2,
(unsigned int)v3,
ptr,
v6,
(unsigned int)deviatonly,
v7,
devsstat_4,
&v25,
&v24,
&v23,
&v22,
&v21,
&v20);
v17 = v25;
v9 = malloc(8LL * v25);
ptrverify(v9, "Malloc failed for %d process ptrs\n", v17);
if ( v8 )
{
v10 = v7;
v11 = 0;
do
{
if ( v10[64] )
v9[v11++] = v10;
v10 += 736;
}
while ( v10 != &v7[736 * v8] );
}
v12 = curtime - pretime;
if ( curtime - pretime <= 0 )
v12 = 1LL;
v13 = vis(curtime, v12, devsstat_4, v7, v9, v8, v3, v25, v24, v23, v22, v21, v20, v6, v5, sampcnt == 0);
if ( v6 )
free(ptr);
if ( v18 )
netatop_exiterase();
free(v7);
free(v9);
if ( v13 == 114 )
{
sampcnt = -1LL;
curtime = getboot() / (unsigned __int64)(unsigned __int16)hertz;
memset(cursstat_6, 0, 0x71538uLL);
memset(curpact_2, 0, 736LL * curplen_3);
pdb_makeresidue();
pdb_cleanresidue();
}
v0 = sampcnt + 1;
sampcnt = v0;
if ( v0 >= (unsigned int)nsamples )
return v0;
}
v5 = v4 - 71234;
v6 = 71234;
goto LABEL_11;
}
return v0;
}

canonical_decompiled_code:
int func4()
{
unsigned __int64 v0; // rax
struct tm *v1; // rax
int v2; // ebx
__int64 v3; // rbx
unsigned int v4; // eax
__int64 v5; // r13
unsigned int v6; // er14
char *v7; // r12
unsigned int v8; // er15
_QWORD *v9; // rbp
char *v10; // rax
int v11; // edx
__int64 v12; // rsi
char v13; // bl
void *v14; // rax
void *ptr; // [rsp+8h] [rbp-110h]
unsigned int v17; // [rsp+18h] [rbp-100h]
int v18; // [rsp+1Ch] [rbp-FCh]
time_t timer; // [rsp+20h] [rbp-F8h] BYREF
unsigned int v20; // [rsp+28h] [rbp-F0h] BYREF
unsigned int v21; // [rsp+2Ch] [rbp-ECh] BYREF
unsigned int v22; // [rsp+30h] [rbp-E8h] BYREF
unsigned int v23; // [rsp+34h] [rbp-E4h] BYREF
unsigned int v24; // [rsp+38h] [rbp-E0h] BYREF
unsigned int v25; // [rsp+3Ch] [rbp-DCh] BYREF
struct sigaction v26; // [rsp+40h] [rbp-D8h] BYREF

cursstat_6 = calloc(1uLL, 0x71538uLL);
presstat_5 = (__int64)calloc(1uLL, 0x71538uLL);
devsstat_4 = (__int64)calloc(1uLL, 0x71538uLL);
curplen_3 = (3 * (unsigned int)countprocs()) >> 1;
curpact_2 = calloc(curplen_3, 0x2E0uLL);
ptrverify(cursstat_6, "Malloc failed for current sysstats\n");
ptrverify(presstat_5, "Malloc failed for prev sysstats\n");
ptrverify(devsstat_4, "Malloc failed for deviate sysstats\n");
ptrverify(curpact_2, "Malloc failed for %d procstats\n", (unsigned int)curplen_3);
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_handler = (__sighandler_t)getusr1;
sigaction(10, &v26, 0LL);
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_handler = (__sighandler_t)getusr2;
sigaction(12, &v26, 0LL);
memset(&v26.sa_mask, 0, 0x90uLL);
v26.sa_handler = (__sighandler_t)getalarm;
LODWORD(v0) = sigaction(14, &v26, 0LL);
if ( *(_QWORD *)&interval )
LODWORD(v0) = alarm(interval);
if ( midnightflag )
{
timer = time(0LL);
v1 = localtime(&timer);
v1->tm_hour = 23;
v1->tm_min = 59;
v1->tm_sec = 59;
v0 = mktime(v1);
timelimit_1 = v0;
}
sampcnt = 0LL;
if ( nsamples )
{
v0 = 0LL;
while ( 1 )
{
if ( midnightflag && curtime + *(_QWORD *)&interval > (unsigned __int64)timelimit_1 )
return v0;
if ( v0 && awaittrigger )
pause();
awaittrigger = 1;
pretime = curtime;
curtime = time(0LL);
v14 = cursstat_6;
cursstat_6 = (void *)presstat_5;
presstat_5 = (__int64)v14;
photosyst();
deviatsyst(cursstat_6, presstat_5, devsstat_4);
memset(curpact_2, 0, 736LL * curplen_3);
while ( 1 )
{
v3 = (unsigned int)photoproc(curpact_2, (unsigned int)curplen_3);
if ( (_DWORD)v3 != curplen_3 )
break;
v2 = curplen_3 + 100;
curplen_3 = v2;
curpact_2 = realloc(curpact_2, 736LL * v2);
ptrverify(curpact_2, "Realloc failed for %d tasks\n", (unsigned int)v2);
memset(curpact_2, 0, 736LL * curplen_3);
}
v4 = acctprocnt();
v5 = v4;
if ( v4 > 0x11642 )
break;
if ( v4 )
{
v6 = v4;
v5 = 0LL;
LABEL_11:
if ( (supportflags & 0x20) != 0 )
v18 = netatop_exitstore();
else
v18 = 0;
ptr = malloc(736LL * v6);
ptrverify(ptr, "Malloc failed for %d exited processes\n", v6);
memset(ptr, 0, 736LL * v6);
acctphotoproc(ptr, v6);
if ( (_DWORD)v5 )
acctrepos((unsigned int)v5);
goto LABEL_13;
}
v6 = 0;
v18 = 0;
ptr = 0LL;
LABEL_13:
v7 = (char *)malloc(736LL * ((unsigned int)v3 + v6));
ptrverify(v7, "Malloc failed for %d modified processes\n", (unsigned int)v3 + v6);
v8 = deviatproc(
curpact_2,
(unsigned int)v3,
ptr,
v6,
(unsigned int)deviatonly,
v7,
devsstat_4,
&v25,
&v24,
&v23,
&v22,
&v21,
&v20);
v17 = v25;
v9 = malloc(8LL * v25);
ptrverify(v9, "Malloc failed for %d process ptrs\n", v17);
if ( v8 )
{
v10 = v7;
v11 = 0;
do
{
if ( v10[64] )
v9[v11++] = v10;
v10 += 736;
}
while ( v10 != &v7[736 * v8] );
}
v12 = curtime - pretime;
if ( curtime - pretime <= 0 )
v12 = 1LL;
v13 = vis(curtime, v12, devsstat_4, v7, v9, v8, v3, v25, v24, v23, v22, v21, v20, v6, v5, sampcnt == 0);
if ( v6 )
free(ptr);
if ( v18 )
netatop_exiterase();
free(v7);
free(v9);
if ( v13 == 114 )
{
sampcnt = -1LL;
curtime = getboot() / (unsigned __int64)(unsigned __int16)hertz;
memset(cursstat_6, 0, 0x71538uLL);
memset(curpact_2, 0, 736LL * curplen_3);
pdb_makeresidue();
pdb_cleanresidue();
}
v0 = sampcnt + 1;
sampcnt = v0;
if ( v0 >= (unsigned int)nsamples )
return v0;
}
v5 = v4 - 71234;
v6 = 71234;
goto LABEL_11;
}
return v0;
}

original_code:
static void
engine(void)
{
 int i, j;
 struct sigaction sigact;
 static time_t timelimit;
 void getusr1(int), getusr2(int);
 static struct sstat *cursstat;
 static struct sstat *presstat;
 static struct sstat *devsstat;
 static struct sstat *hlpsstat;
 static struct tstat *curpact;
 static int curplen;
 struct tstat *curpexit;
 struct tstat *devtstat;
 struct tstat **devpstat;
 unsigned int ntask, nexit, nexitnet;
 unsigned int noverflow, ndeviat, nactproc;
 int totproc, totrun, totslpi, totslpu, totzombie;
 cursstat = calloc(1, sizeof(struct sstat));
 presstat = calloc(1, sizeof(struct sstat));
 devsstat = calloc(1, sizeof(struct sstat));
 curplen = countprocs() * 3 / 2;
 curpact = calloc(curplen, sizeof(struct tstat));
 ptrverify(cursstat, "Malloc failed for current sysstats\n");
 ptrverify(presstat, "Malloc failed for prev    sysstats\n");
 ptrverify(devsstat, "Malloc failed for deviate sysstats\n");
 ptrverify(curpact, "Malloc failed for %d procstats\n", curplen);
 memset(&sigact, 0, sizeof sigact);
 sigact.__sigaction_handler.sa_handler = getusr1;
 sigaction(10, &sigact, (struct sigaction *)0);
 memset(&sigact, 0, sizeof sigact);
 sigact.__sigaction_handler.sa_handler = getusr2;
 sigaction(12, &sigact, (struct sigaction *)0);
 memset(&sigact, 0, sizeof sigact);
 sigact.__sigaction_handler.sa_handler = getalarm;
 sigaction(14, &sigact, (struct sigaction *)0);
 if (interval > 0)
  alarm(interval);
 if (midnightflag)
 {
  time_t timenow = time(0);
  struct tm *tp = localtime(&timenow);
  tp->tm_hour = 23;
  tp->tm_min = 59;
  tp->tm_sec = 59;
  timelimit = mktime(tp);
 }
 for (sampcnt=0; sampcnt < nsamples; sampcnt++)
 {
  char lastcmd;
  if (midnightflag && (curtime+interval) > timelimit)
   break;
  if (sampcnt > 0 && awaittrigger)
   pause();
  awaittrigger = 1;
  pretime = curtime;
  curtime = time(0);
  hlpsstat = cursstat;
  cursstat = presstat;
  presstat = hlpsstat;
  photosyst(cursstat);
  deviatsyst(cursstat, presstat, devsstat);
  memset(curpact, 0, curplen * sizeof(struct tstat));
  while ( (ntask = photoproc(curpact, curplen)) == curplen)
  {
   curplen += 100;
   curpact = realloc(curpact,
     curplen * sizeof(struct tstat));
   ptrverify(curpact,
             "Realloc failed for %d tasks\n", curplen);
   memset(curpact, 0, curplen * sizeof(struct tstat));
  }
  nexit = acctprocnt();
  if (nexit > (50*1024*1024/sizeof(struct tstat)))
  {
   noverflow = nexit - (50*1024*1024/sizeof(struct tstat));
   nexit = (50*1024*1024/sizeof(struct tstat));
  }
  else
   noverflow = 0;
  if (nexit > 0 && (supportflags & 0x00000020))
   nexitnet = netatop_exitstore();
  else
   nexitnet = 0;
  if (nexit > 0)
  {
   curpexit = malloc(nexit * sizeof(struct tstat));
   ptrverify(curpexit,
             "Malloc failed for %d exited processes\n",
             nexit);
   memset(curpexit, 0, nexit * sizeof(struct tstat));
   acctphotoproc(curpexit, nexit);
   if (noverflow)
    acctrepos(noverflow);
  }
  else
  {
   curpexit = ((void *)0);
  }
  devtstat = malloc((ntask+nexit) * sizeof(struct tstat));
  ptrverify(devtstat, "Malloc failed for %d modified processes\n",
                 ntask+nexit);
  ndeviat = deviatproc(curpact, ntask, curpexit, nexit,
    deviatonly, devtstat, devsstat, &nactproc,
    &totproc, &totrun, &totslpi, &totslpu,
                  &totzombie);
         devpstat = malloc(sizeof (struct tstat *) * nactproc);
  ptrverify(devpstat, "Malloc failed for %d process ptrs\n",
                 nactproc);
  for (i=0, j=0; i < ndeviat; i++)
  {
   if ( (devtstat+i)->gen.isproc)
    devpstat[j++] = devtstat+i;
  }
  lastcmd = (vis.show_samp)( curtime,
         curtime-pretime > 0 ? curtime-pretime : 1,
                   devsstat, devtstat, devpstat,
                       ndeviat, ntask, nactproc,
                       totproc, totrun, totslpi, totslpu,
                       totzombie, nexit, noverflow, sampcnt==0);
  if (nexit > 0)
   free(curpexit);
  if (nexitnet > 0)
   netatop_exiterase();
  free(devtstat);
  free(devpstat);
  if (lastcmd == 'r')
  {
   sampcnt = -1;
   curtime = getboot() / hertz;
   memset(cursstat, 0, sizeof(struct sstat));
   memset(curpact, 0, curplen * sizeof(struct tstat));
   pdb_makeresidue();
   pdb_cleanresidue();
  }
 }
}

canonical_original_code:
static void engine()
{
 int i; int j;
 struct sigaction sigact;
 static long timelimit;
 void getusr1(int); void getusr2(int);
 static struct sstat *cursstat;
 static struct sstat *presstat;
 static struct sstat *devsstat;
 static struct sstat *hlpsstat;
 static struct tstat *curpact;
 static int curplen;
 struct tstat *curpexit;
 struct tstat *devtstat;
 struct tstat **devpstat;
 unsigned int ntask; unsigned int nexit; unsigned int nexitnet;
 unsigned int noverflow; unsigned int ndeviat; unsigned int nactproc;
 int totproc; int totrun; int totslpi; int totslpu; int totzombie;
 cursstat = calloc(1, sizeof(struct sstat));
 presstat = calloc(1, sizeof(struct sstat));
 devsstat = calloc(1, sizeof(struct sstat));
 curplen = countprocs() * 3 / 2;
 curpact = calloc(curplen, sizeof(struct tstat));
 ptrverify(cursstat, "Malloc failed for current sysstats\n");
 ptrverify(presstat, "Malloc failed for prev    sysstats\n");
 ptrverify(devsstat, "Malloc failed for deviate sysstats\n");
 ptrverify(curpact, "Malloc failed for %d procstats\n", curplen);
 memset(&sigact, 0, sizeof sigact);
 sigact.__sigaction_handler.sa_handler = getusr1;
 sigaction(10, &sigact, (struct sigaction *)0);
 memset(&sigact, 0, sizeof sigact);
 sigact.__sigaction_handler.sa_handler = getusr2;
 sigaction(12, &sigact, (struct sigaction *)0);
 memset(&sigact, 0, sizeof sigact);
 sigact.__sigaction_handler.sa_handler = getalarm;
 sigaction(14, &sigact, (struct sigaction *)0);
 if (interval > 0)
  alarm(interval);
 if (midnightflag)
 {
  long timenow = time(0);
  struct tm *tp = localtime(&timenow);
  tp->tm_hour = 23;
  tp->tm_min = 59;
  tp->tm_sec = 59;
  timelimit = mktime(tp);
 }
 for (sampcnt=0; sampcnt < nsamples; sampcnt++)
 {
  char lastcmd;
  if (midnightflag && (curtime+interval) > timelimit)
   break;
  if (sampcnt > 0 && awaittrigger)
   pause();
  awaittrigger = 1;
  pretime = curtime;
  curtime = time(0);
  hlpsstat = cursstat;
  cursstat = presstat;
  presstat = hlpsstat;
  photosyst(cursstat);
  deviatsyst(cursstat, presstat, devsstat);
  memset(curpact, 0, curplen * sizeof(struct tstat));
  while ( (ntask = photoproc(curpact, curplen)) == curplen)
  {
   curplen += 100;
   curpact = realloc(curpact,
     curplen * sizeof(struct tstat));
   ptrverify(curpact,
             "Realloc failed for %d tasks\n", curplen);
   memset(curpact, 0, curplen * sizeof(struct tstat));
  }
  nexit = acctprocnt();
  if (nexit > (50*1024*1024/sizeof(struct tstat)))
  {
   noverflow = nexit - (50*1024*1024/sizeof(struct tstat));
   nexit = (50*1024*1024/sizeof(struct tstat));
  }
  else
   noverflow = 0;
  if (nexit > 0 && (supportflags & 0x00000020))
   nexitnet = netatop_exitstore();
  else
   nexitnet = 0;
  if (nexit > 0)
  {
   curpexit = malloc(nexit * sizeof(struct tstat));
   ptrverify(curpexit,
             "Malloc failed for %d exited processes\n",
             nexit);
   memset(curpexit, 0, nexit * sizeof(struct tstat));
   acctphotoproc(curpexit, nexit);
   if (noverflow)
    acctrepos(noverflow);
  }
  else
  {
   curpexit = ((void *)0);
  }
  devtstat = malloc((ntask+nexit) * sizeof(struct tstat));
  ptrverify(devtstat, "Malloc failed for %d modified processes\n",
                 ntask+nexit);
  ndeviat = deviatproc(curpact, ntask, curpexit, nexit,
    deviatonly, devtstat, devsstat, &nactproc,
    &totproc, &totrun, &totslpi, &totslpu,
                  &totzombie);
         devpstat = malloc(sizeof (struct tstat *) * nactproc);
  ptrverify(devpstat, "Malloc failed for %d process ptrs\n",
                 nactproc);
  for (i=0, j=0; i < ndeviat; i++)
  {
   if ( (devtstat+i)->gen.isproc)
    devpstat[j++] = devtstat+i;
  }
  lastcmd = (vis.show_samp)( curtime,
         curtime-pretime > 0 ? curtime-pretime : 1,
                   devsstat, devtstat, devpstat,
                       ndeviat, ntask, nactproc,
                       totproc, totrun, totslpi, totslpu,
                       totzombie, nexit, noverflow, sampcnt==0);
  if (nexit > 0)
   free(curpexit);
  if (nexitnet > 0)
   netatop_exiterase();
  free(devtstat);
  free(devpstat);
  if (lastcmd == 'r')
  {
   sampcnt = -1;
   curtime = getboot() / hertz;
   memset(cursstat, 0, sizeof(struct sstat));
   memset(curpact, 0, curplen * sizeof(struct tstat));
   pdb_makeresidue();
   pdb_cleanresidue();
  }
 }
}

variable_types: j int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: timelimit long

variable_types: struct sstat { struct cpustat { long long nrcpu; long long devint; long long csw; long long nprocs; float lavg1; float lavg5; float lavg15; long long cfuture[4]; struct percpu { int cpunr; long long stime; long long utime; long long ntime; long long itime; long long wtime; long long Itime; long long Stime; long long steal; long long guest; struct freqcnt { long long maxfreq; long long cnt; long long ticks; } freqcnt; long long cfuture[1]; } all; struct percpu cpu[2048]; } cpu; struct memstat { long long physmem; long long freemem; long long buffermem; long long slabmem; long long cachemem; long long cachedrt; long long totswap; long long freeswap; long long pgscans; long long pgsteal; long long allocstall; long long swouts; long long swins; long long commitlim; long long committed; long long shmem; long long shmrss; long long shmswp; long long slabreclaim; } mem; struct netstat { struct ipv4_stats { long long Forwarding; long long DefaultTTL; long long InReceives; long long InHdrErrors; long long InAddrErrors; long long ForwDatagrams; long long InUnknownProtos; long long InDiscards; long long InDelivers; long long OutRequests; long long OutDiscards; long long OutNoRoutes; long long ReasmTimeout; long long ReasmReqds; long long ReasmOKs; long long ReasmFails; long long FragOKs; long long FragFails; long long FragCreates; } ipv4; struct icmpv4_stats { long long InMsgs; long long InErrors; long long InDestUnreachs; long long InTimeExcds; long long InParmProbs; long long InSrcQuenchs; long long InRedirects; long long InEchos; long long InEchoReps; long long InTimestamps; long long InTimestampReps; long long InAddrMasks; long long InAddrMaskReps; long long OutMsgs; long long OutErrors; long long OutDestUnreachs; long long OutTimeExcds; long long OutParmProbs; long long OutSrcQuenchs; long long OutRedirects; long long OutEchos; long long OutEchoReps; long long OutTimestamps; long long OutTimestampReps; long long OutAddrMasks; long long OutAddrMaskReps; } icmpv4; struct udpv4_stats { long long InDatagrams; long long NoPorts; long long InErrors; long long OutDatagrams; } udpv4; struct ipv6_stats { long long Ip6InReceives; long long Ip6InHdrErrors; long long Ip6InTooBigErrors; long long Ip6InNoRoutes; long long Ip6InAddrErrors; long long Ip6InUnknownProtos; long long Ip6InTruncatedPkts; long long Ip6InDiscards; long long Ip6InDelivers; long long Ip6OutForwDatagrams; long long Ip6OutRequests; long long Ip6OutDiscards; long long Ip6OutNoRoutes; long long Ip6ReasmTimeout; long long Ip6ReasmReqds; long long Ip6ReasmOKs; long long Ip6ReasmFails; long long Ip6FragOKs; long long Ip6FragFails; long long Ip6FragCreates; long long Ip6InMcastPkts; long long Ip6OutMcastPkts; } ipv6; struct icmpv6_stats { long long Icmp6InMsgs; long long Icmp6InErrors; long long Icmp6InDestUnreachs; long long Icmp6InPktTooBigs; long long Icmp6InTimeExcds; long long Icmp6InParmProblems; long long Icmp6InEchos; long long Icmp6InEchoReplies; long long Icmp6InGroupMembQueries; long long Icmp6InGroupMembResponses; long long Icmp6InGroupMembReductions; long long Icmp6InRouterSolicits; long long Icmp6InRouterAdvertisements; long long Icmp6InNeighborSolicits; long long Icmp6InNeighborAdvertisements; long long Icmp6InRedirects; long long Icmp6OutMsgs; long long Icmp6OutDestUnreachs; long long Icmp6OutPktTooBigs; long long Icmp6OutTimeExcds; long long Icmp6OutParmProblems; long long Icmp6OutEchoReplies; long long Icmp6OutRouterSolicits; long long Icmp6OutNeighborSolicits; long long Icmp6OutNeighborAdvertisements; long long Icmp6OutRedirects; long long Icmp6OutGroupMembResponses; long long Icmp6OutGroupMembReductions; } icmpv6; struct udpv6_stats { long long Udp6InDatagrams; long long Udp6NoPorts; long long Udp6InErrors; long long Udp6OutDatagrams; } udpv6; struct tcp_stats { long long RtoAlgorithm; long long RtoMin; long long RtoMax; long long MaxConn; long long ActiveOpens; long long PassiveOpens; long long AttemptFails; long long EstabResets; long long CurrEstab; long long InSegs; long long OutSegs; long long RetransSegs; long long InErrs; long long OutRsts; } tcp; } net; struct intfstat { int nrintf; struct perintf { char name[16]; long long rbyte; long long rpack; long long rerrs; long long rdrop; long long rfifo; long long rframe; long long rcompr; long long rmultic; long long rfuture[4]; long long sbyte; long long spack; long long serrs; long long sdrop; long long sfifo; long long scollis; long long scarrier; long long scompr; long long sfuture[4]; long speed; char duplex; long long cfuture[4]; } intf[128]; } intf; struct dskstat { int ndsk; int nmdd; int nlvm; struct perdsk { char name[32]; long long nread; long long nrsect; long long nwrite; long long nwsect; long long io_ms; long long avque; long long cfuture[4]; } dsk[512]; struct perdsk mdd[256]; struct perdsk lvm[1024]; } dsk; struct wwwstat { long long accesses; long long totkbytes; long long uptime; int bworkers; int iworkers; } www; } *

variable_types: curplen int

variable_types: struct tstat { struct gen { int tgid; int pid; int ppid; int ruid; int euid; int suid; int fsuid; int rgid; int egid; int sgid; int fsgid; int nthr; char name[-1]; char isproc; char state; int excode; long btime; long elaps; char cmdline[-1]; int nthrslpi; int nthrslpu; int nthrrun; int ifuture[4]; } gen; struct cpu { long long utime; long long stime; int nice; int prio; int rtprio; int policy; int curcpu; int sleepavg; int ifuture[4]; long long cfuture[4]; } cpu; struct dsk { long long rio; long long rsz; long long wio; long long wsz; long long cwsz; long long cfuture[4]; } dsk; struct mem { long long minflt; long long majflt; long long vexec; long long vmem; long long rmem; long long vgrow; long long rgrow; long long vdata; long long vstack; long long vlibs; long long vswap; } mem; struct net { long long tcpsnd; long long tcpssz; long long tcprcv; long long tcprsz; long long udpsnd; long long udpssz; long long udprcv; long long udprsz; long long avail1; long long avail2; long long cfuture[4]; } net; } **

variable_types:
ntask
unsigned int

variable_types:
nexit
unsigned int

variable_types:
nexitnet
unsigned int

variable_types:
noverflow
unsigned int

variable_types:
ndeviat
unsigned int

variable_types:
nactproc
unsigned int

variable_types: totproc int

variable_types: totrun int

variable_types: totslpi int

variable_types: totslpu int

variable_types: totzombie int

variable_types: timenow long

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

variable_types: lastcmd char

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sstat { struct cpustat cpu; struct memstat mem; struct netstat net; struct intfstat intf; struct dskstat dsk; struct wwwstat www; }

user_defined_types: struct cpustat { long long nrcpu; long long devint; long long csw; long long nprocs; float lavg1; float lavg5; float lavg15; long long cfuture[4]; struct percpu all; struct percpu cpu[2048]; }

user_defined_types: struct netstat { struct ipv4_stats ipv4; struct icmpv4_stats icmpv4; struct udpv4_stats udpv4; struct ipv6_stats ipv6; struct icmpv6_stats icmpv6; struct udpv6_stats udpv6; struct tcp_stats tcp; }

user_defined_types: struct intfstat { int nrintf; struct perintf intf[128]; }

user_defined_types: struct dskstat { int ndsk; int nmdd; int nlvm; struct perdsk dsk[512]; struct perdsk mdd[256]; struct perdsk lvm[1024]; }

user_defined_types: struct percpu { int cpunr; long long stime; long long utime; long long ntime; long long itime; long long wtime; long long Itime; long long Stime; long long steal; long long guest; struct freqcnt freqcnt; long long cfuture[1]; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


convtime

decompiled_code:
char *__fastcall convtime(time_t a1, char *a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v2 = localtime(&timer);
sprintf(a2, "%02d:%02d:%02d", (unsigned int)v2->tm_hour, (unsigned int)v2->tm_min, (unsigned int)v2->tm_sec);
return a2;
}

canonical_decompiled_code:
char *__fastcall func0(time_t a1, char *a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v2 = localtime(&timer);
sprintf(a2, "%02d:%02d:%02d", (unsigned int)v2->tm_hour, (unsigned int)v2->tm_min, (unsigned int)v2->tm_sec);
return a2;
}

original_code:
char *
convtime(time_t utime, char *chartim)
{
 struct tm *tt;
 tt = localtime(&utime);
 sprintf(chartim, "%02d:%02d:%02d", tt->tm_hour, tt->tm_min, tt->tm_sec);
 return chartim;
}

canonical_original_code:
char *convtime(long utime, char *chartim)
{
 struct tm *tt;
 tt = localtime(&utime);
 sprintf(chartim, "%02d:%02d:%02d", tt->tm_hour, tt->tm_min, tt->tm_sec);
 return chartim;
}

variable_types: utime long

variable_types:
chartim
char *

return_type: char *

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


convdate

decompiled_code:
char *__fastcall convdate(time_t a1, char *a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v2 = localtime(&timer);
sprintf(
a2,
"%04d/%02d/%02d",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday);
return a2;
}

canonical_decompiled_code:
char *__fastcall func1(time_t a1, char *a2)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v2 = localtime(&timer);
sprintf(
a2,
"%04d/%02d/%02d",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday);
return a2;
}

original_code:
char *
convdate(time_t utime, char *chardat)
{
 struct tm *tt;
 tt = localtime(&utime);
 sprintf(chardat, "%04d/%02d/%02d",
  tt->tm_year+1900, tt->tm_mon+1, tt->tm_mday);
 return chardat;
}

canonical_original_code:
char *convdate(long utime, char *chardat)
{
 struct tm *tt;
 tt = localtime(&utime);
 sprintf(chardat, "%04d/%02d/%02d",
  tt->tm_year+1900, tt->tm_mon+1, tt->tm_mday);
 return chardat;
}

variable_types:
chardat
char *


decompiled_code:
__int64 __fastcall hhmm2secs(char *a1, _DWORD *a2)
{
char v2; // bl
const unsigned __int16 *v3; // rcx
char *v4; // rax
__int64 result; // rax
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = *a1;
if ( *a1 )
{
v3 = *_ctype_b_loc();
v4 = a1 + 1;
while ( (v3[v2] & 0x800) != 0 || v2 == 58 )
{
v2 = *v4++;
if ( !v2 )
goto LABEL_8;
}
result = 0LL;
}
else
{
LABEL_8:
_isoc99_sscanf(a1, "%d:%d", &v7, &v6);
result = 0LL;
if ( v7 <= 0x17 && v6 <= 0x3B )
{
*a2 = 60 * v6 + 3600 * v7;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, _DWORD *a2)
{
char v2; // bl
const unsigned __int16 *v3; // rcx
char *v4; // rax
__int64 result; // rax
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = *a1;
if ( *a1 )
{
v3 = *_ctype_b_loc();
v4 = a1 + 1;
while ( (v3[v2] & 0x800) != 0 || v2 == 58 )
{
v2 = *v4++;
if ( !v2 )
goto LABEL_8;
}
result = 0LL;
}
else
{
LABEL_8:
_isoc99_sscanf(a1, "%d:%d", &v7, &v6);
result = 0LL;
if ( v7 <= 0x17 && v6 <= 0x3B )
{
*a2 = 60 * v6 + 3600 * v7;
result = 1LL;
}
}
return result;
}

original_code:
int
hhmm2secs(char *itim, unsigned int *otim)
{
 register int i;
 int hours, minutes;
 for (i=0; *(itim+i); i++)
  if ( !((*__ctype_b_loc ())[(int) ((*(itim+i)))] & (unsigned short int) _ISdigit) && *(itim+i) != ':' )
   return(0);
 sscanf(itim, "%d:%d", &hours, &minutes);
 if ( hours < 0 || hours > 23 || minutes < 0 || minutes > 59 )
  return(0);
 *otim = (hours * 3600) + (minutes * 60);
 if (*otim >= 86400)
  *otim = 86400 -1;
 return(1);
}

canonical_original_code:
int hhmm2secs(char *itim, unsigned int *otim)
{
 register int i;
 int hours; int minutes;
 for (i=0; *(itim+i); i++)
  if ( !((*__ctype_b_loc ())[(int) ((*(itim+i)))] & (unsigned short) _ISdigit) && *(itim+i) != ':' )
   return(0);
 sscanf(itim, "%d:%d", &hours, &minutes);
 if ( hours < 0 || hours > 23 || minutes < 0 || minutes > 59 )
  return(0);
 *otim = (hours * 3600) + (minutes * 60);
 if (*otim >= 86400)
  *otim = 86400 -1;
 return(1);
}

variable_types:
itim
char *

variable_types:
otim
unsigned int *

variable_types: i int

variable_types: hours int

variable_types: minutes int


daysecs

decompiled_code:
__int64 __fastcall daysecs(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = localtime(&timer);
return (unsigned int)(3600 * v1->tm_hour + 60 * v1->tm_min);
}

canonical_decompiled_code:
__int64 __fastcall func3(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = localtime(&timer);
return (unsigned int)(3600 * v1->tm_hour + 60 * v1->tm_min);
}

original_code:
int
daysecs(time_t itime)
{
 struct tm *tt;
 tt = localtime(&itime);
 return( (tt->tm_hour*3600) + (tt->tm_min*60) );
}

canonical_original_code:
int daysecs(long itime)
{
 struct tm *tt;
 tt = localtime(&itime);
 return( (tt->tm_hour*3600) + (tt->tm_min*60) );
}

variable_types: itime long


original_code:
char *
val2valstr(count_t value, char *strvalue, int width, int avg, int nsecs)
{
 count_t maxval, remain = 0;
 int exp = 0;
 char *suffix = "";
 if (avg)
 {
  value = (value + (nsecs/2)) / nsecs;
  width = width - 2;
  suffix = "/s";
 }
 maxval = pow(10.0, width) - 1;
 if (value < maxval)
 {
  sprintf(strvalue, "%*lld%s", width, value, suffix);
 }
 else
 {
  if (width < 3)
  {
   sprintf(strvalue, "%lld%s", value, suffix);
  }
  else
  {
   width -= 2;
   maxval = pow(10.0, width) - 1;
   while (value > maxval)
   {
    exp++;
    remain = value % 10;
    value /= 10;
   }
   if (remain >= 5)
    value++;
   sprintf(strvalue, "%*llde%d%s",
     width, value, exp, suffix);
  }
 }
 return strvalue;
}

canonical_original_code:
char *val2valstr(long long value, char *strvalue, int width, int avg, int nsecs)
{
 long long maxval; long long remain = 0;
 int exp = 0;
 char *suffix = "";
 if (avg)
 {
  value = (value + (nsecs/2)) / nsecs;
  width = width - 2;
  suffix = "/s";
 }
 maxval = pow(10.0, width) - 1;
 if (value < maxval)
 {
  sprintf(strvalue, "%*lld%s", width, value, suffix);
 }
 else
 {
  if (width < 3)
  {
   sprintf(strvalue, "%lld%s", value, suffix);
  }
  else
  {
   width -= 2;
   maxval = pow(10.0, width) - 1;
   while (value > maxval)
   {
    exp++;
    remain = value % 10;
    value /= 10;
   }
   if (remain >= 5)
    value++;
   sprintf(strvalue, "%*llde%d%s",
     width, value, exp, suffix);
  }
 }
 return strvalue;
}

variable_types:
value
long long

variable_types:
strvalue
char *

variable_types: width int

variable_types: avg int

variable_types: nsecs int

variable_types:
maxval
long long

variable_types:
remain
long long

variable_types: exp int

variable_types:
suffix
char *