decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rsi
__int64 v5; // rdi
__int16 v6; // bx
int v7; // eax
int v8; // edx
__int64 v9; // rdi

v3 = time(0LL);
srand(v3);
init_map((__int64)&map, 0x14u, 0x14u);
generate_map((__int64)&map, 1);
SDL_Init();
v4 = 20 * (unsigned int)(unsigned __int8)byte_404148;
v5 = 20 * (unsigned int)(unsigned __int8)byte_404149;
screen = SDL_SetVideoMode();
load_images(v5, v4);
do
{
v6 = 0;
while ( 1 )
{
v7 = SDL_PollEvent();
if ( !v7 )
break;
if ( event == 12 )
{
v6 = 1;
}
else if ( dword_4040B8 == 13 || dword_4040B8 == 27 )
{
v6 = 1;
}
}
v8 = *((unsigned __int8 *)&map + 8) * *((unsigned __int8 *)&map + 9);
if ( v8 > 0 )
{
do
++v7;
while ( v7 != v8 );
}
image_draw_test(&event);
v9 = screen;
SDL_Flip();
}
while ( !v6 );
free_images(v9);
free_map((void **)&map);
SDL_Quit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rsi
__int64 v5; // rdi
__int16 v6; // bx
int v7; // eax
int v8; // edx
__int64 v9; // rdi

v3 = time(0LL);
srand(v3);
func9((__int64)&map, 0x14u, 0x14u);
func16((__int64)&map, 1);
SDL_Init();
v4 = 20 * (unsigned int)(unsigned __int8)byte_404148;
v5 = 20 * (unsigned int)(unsigned __int8)byte_404149;
screen = SDL_SetVideoMode();
func17(v5, v4);
do
{
v6 = 0;
while ( 1 )
{
v7 = SDL_PollEvent();
if ( !v7 )
break;
if ( event == 12 )
{
v6 = 1;
}
else if ( dword_4040B8 == 13 || dword_4040B8 == 27 )
{
v6 = 1;
}
}
v8 = *((unsigned __int8 *)&map + 8) * *((unsigned __int8 *)&map + 9);
if ( v8 > 0 )
{
do
++v7;
while ( v7 != v8 );
}
func19(&event);
v9 = screen;
SDL_Flip();
}
while ( !v6 );
func18(v9);
func7((void **)&map);
SDL_Quit();
return 0;
}

original_code:
int main(int argc, char* args[]) {
 srand(time(((void *)0)));
 init_map(&map, 20, 20);
 generate_map(&map, 1);
 SDL_Init(0x0000FFFF);
 screen = SDL_SetVideoMode(20 * map.width, 20 * map.height, 32, 0x00000000);
 load_images();
 short quit = 0;
 while (!quit) {
  while (SDL_PollEvent(&event)) {
   if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN) {
    quit = 1;
   }
  }
  for (int i = 0; i < map.width * map.height; i++) {
  }
  image_draw_test();
  SDL_Flip(screen);
 }
 free_images();
 free_map(&map);
 SDL_Quit();
 return 0;
}

canonical_original_code:
int main(int argc, char *args[]) {
 srand(time(((void *)0)));
 init_map(&map, 20, 20);
 generate_map(&map, 1);
 SDL_Init(0x0000FFFF);
 screen = SDL_SetVideoMode(20 * map.width, 20 * map.height, 32, 0x00000000);
 load_images();
 short quit = 0;
 while (!quit) {
  while (SDL_PollEvent(&event)) {
   if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN) {
    quit = 1;
   }
  }
  for (int i = 0; i < map.width * map.height; i++) {
  }
  image_draw_test();
  SDL_Flip(screen);
 }
 free_images();
 free_map(&map);
 SDL_Quit();
 return 0;
}

variable_types: argc int

variable_types:
args
char *[]

variable_types: quit short

variable_types: i int


decompiled_code:
__int64 __fastcall draw_tile(__int64 a1)
{
__int16 v1; // dx
__int64 result; // rax

v1 = *(_WORD *)(a1 + 4);
result = *(unsigned __int16 *)(a1 + 2);
switch ( *(_WORD *)(a1 + 2) )
{
case 1:
result = SDL_UpperBlit();
break;
case 2:
if ( (v1 & 0xC) != 0 || (v1 & 3) != 0 )
goto LABEL_20;
break;
case 3:
if ( (v1 & 8) != 0 || (v1 & 1) != 0 || (v1 & 4) != 0 || (v1 & 2) != 0 )
goto LABEL_20;
break;
case 4:
if ( (v1 & 8) != 0 || (v1 & 1) != 0 || (v1 & 4) != 0 || (v1 & 2) != 0 )
goto LABEL_20;
break;
default:
LABEL_20:
result = SDL_UpperBlit();
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
__int16 v1; // dx
__int64 result; // rax

v1 = *(_WORD *)(a1 + 4);
result = *(unsigned __int16 *)(a1 + 2);
switch ( *(_WORD *)(a1 + 2) )
{
case 1:
result = SDL_UpperBlit();
break;
case 2:
if ( (v1 & 0xC) != 0 || (v1 & 3) != 0 )
goto LABEL_20;
break;
case 3:
if ( (v1 & 8) != 0 || (v1 & 1) != 0 || (v1 & 4) != 0 || (v1 & 2) != 0 )
goto LABEL_20;
break;
case 4:
if ( (v1 & 8) != 0 || (v1 & 1) != 0 || (v1 & 4) != 0 || (v1 & 2) != 0 )
goto LABEL_20;
break;
default:
LABEL_20:
result = SDL_UpperBlit();
break;
}
return result;
}

original_code:
void draw_tile(struct Tile* tile) {
 SDL_Rect tmprect = {tile->x*20, tile->y*20, 20, 20};
 int dir = tile->direction;
 switch (tile->type) {
  case START:
   SDL_UpperBlit(tileStart, ((void *)0), screen, &tmprect);
  break;
  case END:
   SDL_UpperBlit(tileEnd, ((void *)0), screen, &tmprect);
  break;
  case PIPE_STRAIGHT:
   if (dir & (RIGHT | LEFT)) {
    SDL_UpperBlit(tileHorizontal, ((void *)0), screen, &tmprect);
   } else if (dir & (UP | DOWN)) {
    SDL_UpperBlit(tileVertical, ((void *)0), screen, &tmprect);
   }
  break;
  case PIPE_TURN:
   if (dir & RIGHT) {
    SDL_UpperBlit(tileTurnDownRight, ((void *)0), screen, &tmprect);
   } else if (dir & UP) {
    SDL_UpperBlit(tileTurnUpRight, ((void *)0), screen, &tmprect);
   } else if (dir & LEFT) {
    SDL_UpperBlit(tileTurnUpLeft, ((void *)0), screen, &tmprect);
   } else if (dir & DOWN) {
    SDL_UpperBlit(tileTurnDownLeft, ((void *)0), screen, &tmprect);
   }
  break;
  case PIPE_CROSS:
   SDL_UpperBlit(tileCross, ((void *)0), screen, &tmprect);
  break;
  case PIPE_INTERSECT:
   if (dir & RIGHT) {
    SDL_UpperBlit(tileIntersectRight, ((void *)0), screen, &tmprect);
   } else if (dir & UP) {
    SDL_UpperBlit(tileIntersectUp, ((void *)0), screen, &tmprect);
   } else if (dir & LEFT) {
    SDL_UpperBlit(tileIntersectLeft, ((void *)0), screen, &tmprect);
   } else if (dir & DOWN) {
    SDL_UpperBlit(tileIntersectDown, ((void *)0), screen, &tmprect);
   }
  break;
  default:
   SDL_UpperBlit(tileBlank, ((void *)0), screen, &tmprect);
  break;
 }
}

canonical_original_code:
void draw_tile(struct Tile *tile) {
 struct SDL_Rect tmprect = {tile->x*20, tile->y*20, 20, 20};
 int dir = tile->direction;
 switch (tile->type) {
  case START:
   SDL_UpperBlit(tileStart, ((void *)0), screen, &tmprect);
  break;
  case END:
   SDL_UpperBlit(tileEnd, ((void *)0), screen, &tmprect);
  break;
  case PIPE_STRAIGHT:
   if (dir & (RIGHT | LEFT)) {
    SDL_UpperBlit(tileHorizontal, ((void *)0), screen, &tmprect);
   } else if (dir & (UP | DOWN)) {
    SDL_UpperBlit(tileVertical, ((void *)0), screen, &tmprect);
   }
  break;
  case PIPE_TURN:
   if (dir & RIGHT) {
    SDL_UpperBlit(tileTurnDownRight, ((void *)0), screen, &tmprect);
   } else if (dir & UP) {
    SDL_UpperBlit(tileTurnUpRight, ((void *)0), screen, &tmprect);
   } else if (dir & LEFT) {
    SDL_UpperBlit(tileTurnUpLeft, ((void *)0), screen, &tmprect);
   } else if (dir & DOWN) {
    SDL_UpperBlit(tileTurnDownLeft, ((void *)0), screen, &tmprect);
   }
  break;
  case PIPE_CROSS:
   SDL_UpperBlit(tileCross, ((void *)0), screen, &tmprect);
  break;
  case PIPE_INTERSECT:
   if (dir & RIGHT) {
    SDL_UpperBlit(tileIntersectRight, ((void *)0), screen, &tmprect);
   } else if (dir & UP) {
    SDL_UpperBlit(tileIntersectUp, ((void *)0), screen, &tmprect);
   } else if (dir & LEFT) {
    SDL_UpperBlit(tileIntersectLeft, ((void *)0), screen, &tmprect);
   } else if (dir & DOWN) {
    SDL_UpperBlit(tileIntersectDown, ((void *)0), screen, &tmprect);
   }
  break;
  default:
   SDL_UpperBlit(tileBlank, ((void *)0), screen, &tmprect);
  break;
 }
}

variable_types: struct Tile { unsigned char x; unsigned char y; short type; short direction; } *

variable_types: struct SDL_Rect { short x; unsigned short w; }

variable_types: dir int

return_type: void


repo: elionne/lutopia

original_code:
dmx_handler dmx_open(struct dmx_controler* dmx, unsigned char* name)
{return dmx->dmx_open(name);}

canonical_original_code:
void *dmx_open(struct dmx_controler *dmx, unsigned char *name)
{return dmx->dmx_open(name);}

variable_types: struct dmx_controler { char *name; void *(*dmx_open)(unsigned char *); int (*dmx_send)(void *, unsigned char *); int (*dmx_close)(void *); } *

variable_types:
name
unsigned char *

return_type: void *


original_code:
int dmx_send(struct dmx_controler *dmx, dmx_handler handler, unsigned char *data)
{return dmx->dmx_send(handler, data);}

canonical_original_code:
int dmx_send(struct dmx_controler *dmx, void *handler, unsigned char *data)
{return dmx->dmx_send(handler, data);}

variable_types:
handler
void *

variable_types:
data
unsigned char *

return_type: int

user_defined_types: struct dmx_controler { char *name; void *(*dmx_open)(unsigned char *); int (*dmx_send)(void *, unsigned char *); int (*dmx_close)(void *); }


original_code:
int dmx_close(struct dmx_controler *dmx, dmx_handler handler)
{return dmx->dmx_close(handler);}

canonical_original_code:
int dmx_close(struct dmx_controler *dmx, void *handler)
{return dmx->dmx_close(handler);}


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

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

original_code:
int wake_up_task(char* function)
{
    return 0;
}

canonical_original_code:
int wake_up_task(char *function)
{
    return 0;
}

variable_types:
function
char *


gcd

decompiled_code:
__int64 __fastcall gcd(int a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = a2;
if ( a1 )
{
while ( 1 )
{
v3 = v2 % a1;
v2 = a1;
if ( !v3 )
break;
a1 = v3;
}
}
else
{
a1 = a2;
}
return (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
int v2; // eax
int v3; // edx

v2 = a2;
if ( a1 )
{
while ( 1 )
{
v3 = v2 % a1;
v2 = a1;
if ( !v3 )
break;
a1 = v3;
}
}
else
{
a1 = a2;
}
return (unsigned int)a1;
}

original_code:
int gcd(int a, int b) {
    while(a != 0) {
        int c = a;
        a = b % a;
        b = c;
    }
    return b;
}

variable_types: a int

variable_types: b int

variable_types: c int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
__int64 v5; // r15
int v6; // er14
__int64 v7; // r13
int v8; // ebp
unsigned int v9; // eax
int *v10; // rax
char *v11; // rax
int *v13; // rax
char *v14; // rax
int v15; // ebp
__time_t v16; // rsi
__suseconds_t v17; // rdx
__time_t v18; // rcx
__suseconds_t v19; // rax
unsigned int v20; // [rsp+8h] [rbp-320h]
struct timeval tv; // [rsp+10h] [rbp-318h] BYREF
struct timeval v22; // [rsp+20h] [rbp-308h] BYREF
struct timeval timeout; // [rsp+30h] [rbp-2F8h] BYREF
struct timeval v24; // [rsp+40h] [rbp-2E8h] BYREF
fd_set readfds; // [rsp+50h] [rbp-2D8h] BYREF
char buf[528]; // [rsp+D0h] [rbp-258h] BYREF
struct sockaddr addr; // [rsp+2E0h] [rbp-48h] BYREF

v3 = socket(2, 2, 0);
if ( v3 <= 0 )
{
v10 = __errno_location();
v11 = strerror(*v10);
printf("Error while opening socket, abort. %s\n", v11);
}
else
{
v4 = v3;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = _bswap_16(21812);
addr.sa_family = 2;
if ( bind(v4, &addr, 0x10u) < 0 )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("Could not bind the socket. %s\n", v14);
}
else
{
v5 = dmx_open((__int64)dmx_drv_list, 0LL);
if ( v5 )
{
v6 = v4 / 64;
v7 = 1LL << (v4 % 64);
while ( 1 )
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 24000LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v6] |= v7;
gettimeofday(&tv, 0LL);
v8 = select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
gettimeofday(&v22, 0LL);
if ( v8 > 0 )
{
v24.tv_sec = 0LL;
v24.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v6] |= v7;
v15 = 0;
do
{
v20 = recv(v4, buf, 0x201uLL, 0);
++v15;
}
while ( select(v4 + 1, &readfds, 0LL, 0LL, &v24) > 0 );
if ( v20 <= 0x200 )
puts("corrupted data receive");
if ( v15 > 1 )
printf("multiple data received %i\n", (unsigned int)v15);
v16 = v22.tv_sec - tv.tv_sec;
v17 = v22.tv_usec - tv.tv_usec;
if ( v22.tv_usec - tv.tv_usec < 0 )
{
--v16;
v17 += 1000000LL;
}
v18 = timeout.tv_sec - v16;
timeout.tv_sec -= v16;
v19 = timeout.tv_usec - v17;
timeout.tv_usec -= v17;
if ( timeout.tv_usec < 0 )
{
timeout.tv_sec = v18 - 1;
timeout.tv_usec = v19 + 1000000;
}
}
buf[0] = 0;
v9 = dmx_send((__int64)dmx_drv_list, v5, (__int64)buf);
if ( v9 != 513 )
printf("send %i bytes to dmx\r", v9);
}
}
}
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // er12
__int64 v5; // r15
int v6; // er14
__int64 v7; // r13
int v8; // ebp
unsigned int v9; // eax
int *v10; // rax
char *v11; // rax
int *v13; // rax
char *v14; // rax
int v15; // ebp
__time_t v16; // rsi
__suseconds_t v17; // rdx
__time_t v18; // rcx
__suseconds_t v19; // rax
unsigned int v20; // [rsp+8h] [rbp-320h]
struct timeval tv; // [rsp+10h] [rbp-318h] BYREF
struct timeval v22; // [rsp+20h] [rbp-308h] BYREF
struct timeval timeout; // [rsp+30h] [rbp-2F8h] BYREF
struct timeval v24; // [rsp+40h] [rbp-2E8h] BYREF
fd_set readfds; // [rsp+50h] [rbp-2D8h] BYREF
char buf[528]; // [rsp+D0h] [rbp-258h] BYREF
struct sockaddr addr; // [rsp+2E0h] [rbp-48h] BYREF

v3 = socket(2, 2, 0);
if ( v3 <= 0 )
{
v10 = __errno_location();
v11 = strerror(*v10);
printf("Error while opening socket, abort. %s\n", v11);
}
else
{
v4 = v3;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = func7(21812);
addr.sa_family = 2;
if ( bind(v4, &addr, 0x10u) < 0 )
{
v13 = __errno_location();
v14 = strerror(*v13);
printf("Could not bind the socket. %s\n", v14);
}
else
{
v5 = func8((__int64)dmx_drv_list, 0LL);
if ( v5 )
{
v6 = v4 / 64;
v7 = 1LL << (v4 % 64);
while ( 1 )
{
timeout.tv_sec = 0LL;
timeout.tv_usec = 24000LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v6] |= v7;
gettimeofday(&tv, 0LL);
v8 = select(v4 + 1, &readfds, 0LL, 0LL, &timeout);
gettimeofday(&v22, 0LL);
if ( v8 > 0 )
{
v24.tv_sec = 0LL;
v24.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v6] |= v7;
v15 = 0;
do
{
v20 = recv(v4, buf, 0x201uLL, 0);
++v15;
}
while ( select(v4 + 1, &readfds, 0LL, 0LL, &v24) > 0 );
if ( v20 <= 0x200 )
puts("corrupted data receive");
if ( v15 > 1 )
printf("multiple data received %i\n", (unsigned int)v15);
v16 = v22.tv_sec - tv.tv_sec;
v17 = v22.tv_usec - tv.tv_usec;
if ( v22.tv_usec - tv.tv_usec < 0 )
{
--v16;
v17 += 1000000LL;
}
v18 = timeout.tv_sec - v16;
timeout.tv_sec -= v16;
v19 = timeout.tv_usec - v17;
timeout.tv_usec -= v17;
if ( timeout.tv_usec < 0 )
{
timeout.tv_sec = v18 - 1;
timeout.tv_usec = v19 + 1000000;
}
}
buf[0] = 0;
v9 = func9((__int64)dmx_drv_list, v5, (__int64)buf);
if ( v9 != 513 )
printf("send %i bytes to dmx\r", v9);
}
}
}
}
return 1;
}

original_code:
int main(int argc, char* argv[])
{
    dmx_handler h;
    int s = socket(2, SOCK_DGRAM, 0);
    if(s <= 0 ){
        printf("Error while opening socket, abort. %s\n", strerror((*__errno_location ())));
        return 1;
    }
    struct sockaddr_in in;
    in.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    in.sin_port = htons(21812);
    in.sin_family = 2;
    if( bind(s, (struct sockaddr*)&in, sizeof(in)) < 0 ){
        printf("Could not bind the socket. %s\n", strerror((*__errno_location ())));
        return 1;
    }
    h = dmx_open(dmx_drv_list[0], 0);
    if(!h)
      return 1;
    do{
        struct timeval before, after, timeout = { 0, 24e3 };
        unsigned char dmx_data[513];
        int len = 0;
        fd_set fd;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fd)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        gettimeofday(&before, 0);
        int error = select(s+1, &fd, 0, 0, &timeout);
        gettimeofday(&after, 0);
        if( error == 0 )
            wake_up_task("popo");
        else if( error > 0 )
        {
            int count = 0;
            struct timeval flush = { 0, 0};
            do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd)->__fds_bits)[0]) : "memory"); } while (0);
            ((void) (((&fd)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
            do{
                len = recv(s, dmx_data, sizeof(dmx_data), 0);
                count++;
            }while( select(s+1, &fd, 0, 0, &flush ) > 0 );
            if( len < sizeof(dmx_data) )
                printf("corrupted data receive\n");
            if( count > 1 )
                printf("multiple data received %i\n", count);
            struct timeval timediff;
            do { (&timediff)->tv_sec = (&after)->tv_sec - (&before)->tv_sec; (&timediff)->tv_usec = (&after)->tv_usec - (&before)->tv_usec; if ((&timediff)->tv_usec < 0) { --(&timediff)->tv_sec; (&timediff)->tv_usec += 1000000; } } while (0);
            do { (&timeout)->tv_sec = (&timeout)->tv_sec - (&timediff)->tv_sec; (&timeout)->tv_usec = (&timeout)->tv_usec - (&timediff)->tv_usec; if ((&timeout)->tv_usec < 0) { --(&timeout)->tv_sec; (&timeout)->tv_usec += 1000000; } } while (0);
        }
        dmx_data[0] = 0;
        len = dmx_send(dmx_drv_list[0], h, dmx_data);
        if( len != 513)
            printf("send %i bytes to dmx\r", len);
    }while(1);
    dmx_close(dmx_drv_list[0], h);
    close(s);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    void *h;
    int s = socket(2, SOCK_DGRAM, 0);
    if(s <= 0 ){
        printf("Error while opening socket, abort. %s\n", strerror((*__errno_location ())));
        return 1;
    }
    struct sockaddr_in in;
    in.sin_addr.s_addr = ((unsigned int) 0x00000000);
    in.sin_port = htons(21812);
    in.sin_family = 2;
    if( bind(s, (struct sockaddr *)&in, sizeof(in)) < 0 ){
        printf("Could not bind the socket. %s\n", strerror((*__errno_location ())));
        return 1;
    }
    h = dmx_open(dmx_drv_list[0], 0);
    if(!h)
      return 1;
    do{
        struct timeval before; struct timeval after; struct timeval timeout = { 0, 24e3 };
        unsigned char dmx_data[513];
        int len = 0;
        struct fd_set fd;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fd)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
        gettimeofday(&before, 0);
        int error = select(s+1, &fd, 0, 0, &timeout);
        gettimeofday(&after, 0);
        if( error == 0 )
            wake_up_task("popo");
        else if( error > 0 )
        {
            int count = 0;
            struct timeval flush = { 0, 0};
            do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd)->__fds_bits)[0]) : "memory"); } while (0);
            ((void) (((&fd)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
            do{
                len = recv(s, dmx_data, sizeof(dmx_data), 0);
                count++;
            }while( select(s+1, &fd, 0, 0, &flush ) > 0 );
            if( len < sizeof(dmx_data) )
                printf("corrupted data receive\n");
            if( count > 1 )
                printf("multiple data received %i\n", count);
            struct timeval timediff;
            do { (&timediff)->tv_sec = (&after)->tv_sec - (&before)->tv_sec; (&timediff)->tv_usec = (&after)->tv_usec - (&before)->tv_usec; if ((&timediff)->tv_usec < 0) { --(&timediff)->tv_sec; (&timediff)->tv_usec += 1000000; } } while (0);
            do { (&timeout)->tv_sec = (&timeout)->tv_sec - (&timediff)->tv_sec; (&timeout)->tv_usec = (&timeout)->tv_usec - (&timediff)->tv_usec; if ((&timeout)->tv_usec < 0) { --(&timeout)->tv_sec; (&timeout)->tv_usec += 1000000; } } while (0);
        }
        dmx_data[0] = 0;
        len = dmx_send(dmx_drv_list[0], h, dmx_data);
        if( len != 513)
            printf("send %i bytes to dmx\r", len);
    }while(1);
    dmx_close(dmx_drv_list[0], h);
    close(s);
    return 0;
}

variable_types:
argv
char *[]

variable_types:
h
void *

variable_types: s int

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

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types: len int

variable_types:
fd
struct fd_set { long __fds_bits[-1]; }

variable_types: error int

variable_types: count int

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

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


repo: ellexus/tcshparser

decompiled_code:
char *__fastcall append_dup_string(void *ptr, char *src)
{
size_t v2; // r12
size_t v3; // rax
char *v4; // rax

v2 = strlen((const char *)ptr);
v3 = strlen(src);
v4 = (char *)realloc(ptr, v2 + v3 + 1);
return strcat(v4, src);
}

canonical_decompiled_code:
char *__fastcall func0(void *ptr, char *src)
{
size_t v2; // r12
size_t v3; // rax
char *v4; // rax

v2 = strlen((const char *)ptr);
v3 = strlen(src);
v4 = (char *)realloc(ptr, v2 + v3 + 1);
return strcat(v4, src);
}

original_code:
char *append_dup_string( char *s, char *suffix )
{
    s = realloc( s, (strlen(s) + strlen(suffix) + 1) );
    strcat( s, suffix );
    return s;
}

canonical_original_code:
char *append_dup_string(char *s, char *suffix)
{
    s = realloc( s, (strlen(s) + strlen(suffix) + 1) );
    strcat( s, suffix );
    return s;
}

variable_types:
s
char *

variable_types:
suffix
char *

return_type: char *


slice

decompiled_code:
char *__fastcall slice(const char *a1, int a2, int a3)
{
int v3; // ebx
int v5; // eax
int v6; // esi
char *result; // rax

v3 = a2;
v5 = strlen(a1);
if ( a2 >= 0 || (v3 = v5 + a2, v5 + a2 >= 0) )
{
if ( v5 <= v3 )
v3 = v5;
}
else
{
v3 = 0;
}
if ( a3 <= 0 )
a3 += v5;
v6 = 0;
if ( a3 >= 0 )
{
v6 = v5;
if ( a3 <= v5 )
v6 = a3;
}
if ( v3 >= v6 )
result = strdup(&s);
else
result = strndup(&a1[v3], v6 - v3);
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, int a2, int a3)
{
int v3; // ebx
int v5; // eax
int v6; // esi
char *result; // rax

v3 = a2;
v5 = strlen(a1);
if ( a2 >= 0 || (v3 = v5 + a2, v5 + a2 >= 0) )
{
if ( v5 <= v3 )
v3 = v5;
}
else
{
v3 = 0;
}
if ( a3 <= 0 )
a3 += v5;
v6 = 0;
if ( a3 >= 0 )
{
v6 = v5;
if ( a3 <= v5 )
v6 = a3;
}
if ( v3 >= v6 )
result = strdup(&s);
else
result = strndup(&a1[v3], v6 - v3);
return result;
}

original_code:
char *slice( char *s, int relative_begin, int relative_end )
{
    int length = strlen( s );
    int absolute_begin;
    int absolute_end;
    char *result;
    if ( relative_begin >= 0 ) {
        absolute_begin = relative_begin;
    } else {
        absolute_begin = length + relative_begin;
    }
    if ( absolute_begin < 0 ) {
        absolute_begin = 0;
    } else if ( absolute_begin > length ) {
        absolute_begin = length;
    }
    if ( relative_end > 0 ) {
        absolute_end = relative_end;
    } else {
        absolute_end = length + relative_end;
    }
    if ( absolute_end < 0 ) {
        absolute_end = 0;
    } else if ( absolute_end > length ) {
        absolute_end = length;
    }
    if ( absolute_begin < absolute_end ) {
        result = strndup( &(s[absolute_begin]), absolute_end - absolute_begin );
    } else {
        result = strdup( "" );
    }
    return result;
}

canonical_original_code:
char *slice(char *s, int relative_begin, int relative_end)
{
    int length = strlen( s );
    int absolute_begin;
    int absolute_end;
    char *result;
    if ( relative_begin >= 0 ) {
        absolute_begin = relative_begin;
    } else {
        absolute_begin = length + relative_begin;
    }
    if ( absolute_begin < 0 ) {
        absolute_begin = 0;
    } else if ( absolute_begin > length ) {
        absolute_begin = length;
    }
    if ( relative_end > 0 ) {
        absolute_end = relative_end;
    } else {
        absolute_end = length + relative_end;
    }
    if ( absolute_end < 0 ) {
        absolute_end = 0;
    } else if ( absolute_end > length ) {
        absolute_end = length;
    }
    if ( absolute_begin < absolute_end ) {
        result = strndup( &(s[absolute_begin]), absolute_end - absolute_begin );
    } else {
        result = strdup( "" );
    }
    return result;
}

variable_types: length int

variable_types:
result
char *


decompiled_code:
void *__fastcall get_enclosed_string(void *ptr, char a2, char a3)
{
void *v3; // rbx
char *v5; // rbp

v3 = ptr;
if ( *(_BYTE *)ptr == a2 && *((char *)ptr + strlen((const char *)ptr) - 1) == a3 )
{
v5 = slice((const char *)ptr, 1, -1);
free(ptr);
v3 = v5;
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func2(void *ptr, char a2, char a3)
{
void *v3; // rbx
char *v5; // rbp

v3 = ptr;
if ( *(_BYTE *)ptr == a2 && *((char *)ptr + strlen((const char *)ptr) - 1) == a3 )
{
v5 = func1((const char *)ptr, 1, -1);
free(ptr);
v3 = v5;
}
return v3;
}

original_code:
static char *get_enclosed_string( char *s, char left, char right )
{
    size_t length;
    char *result;
    length = strlen( s );
    if ( (s[0] == left) && (s[length-1] == right) ) {
        result = slice( s, 1, -1 );
        free( s );
    } else {
        result = s;
    }
    return result;
}

canonical_original_code:
static char *get_enclosed_string(char *s, char left, char right)
{
    unsigned long length;
    char *result;
    length = strlen( s );
    if ( (s[0] == left) && (s[length-1] == right) ) {
        result = slice( s, 1, -1 );
        free( s );
    } else {
        result = s;
    }
    return result;
}

variable_types: left char

variable_types: right char

variable_types:
length
unsigned long


decompiled_code:
__int64 __fastcall split_after_first_word(const char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rdx
char *v3; // rax
int v4; // ebp
char *v5; // rax
__int64 v6; // r13
char v7; // bl
const unsigned __int16 *v8; // rdx
const char *v9; // rax
char *v10; // rax

v1 = *a1;
if ( *a1 )
{
v2 = *_ctype_b_loc();
v3 = (char *)(a1 + 1);
v4 = 0;
do
{
if ( (v2[v1] & 0x2000) != 0 )
break;
++v4;
v1 = *v3++;
}
while ( v1 );
}
else
{
v4 = 0;
}
v5 = slice(a1, 0, v4);
v6 = append_to_list(0LL, v5);
v7 = a1[v4];
if ( v7 )
{
v8 = *_ctype_b_loc();
v9 = &a1[v4 + 1];
do
{
if ( (v8[v7] & 0x2000) == 0 )
break;
++v4;
v7 = *v9++;
}
while ( v7 );
}
v10 = slice(a1, v4, 0);
return append_to_list(v6, v10);
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char v1; // bl
const unsigned __int16 *v2; // rdx
char *v3; // rax
int v4; // ebp
char *v5; // rax
__int64 v6; // r13
char v7; // bl
const unsigned __int16 *v8; // rdx
const char *v9; // rax
char *v10; // rax

v1 = *a1;
if ( *a1 )
{
v2 = *_ctype_b_loc();
v3 = (char *)(a1 + 1);
v4 = 0;
do
{
if ( (v2[v1] & 0x2000) != 0 )
break;
++v4;
v1 = *v3++;
}
while ( v1 );
}
else
{
v4 = 0;
}
v5 = func1(a1, 0, v4);
v6 = append_to_list(0LL, v5);
v7 = a1[v4];
if ( v7 )
{
v8 = *_ctype_b_loc();
v9 = &a1[v4 + 1];
do
{
if ( (v8[v7] & 0x2000) == 0 )
break;
++v4;
v7 = *v9++;
}
while ( v7 );
}
v10 = func1(a1, v4, 0);
return append_to_list(v6, v10);
}

original_code:
List *split_after_first_word( char *text )
{
    int i = 0;
    List *result = ((void *)0);
    while ( (text[i] != '\0') && !((*__ctype_b_loc ())[(int) ((text[i]))] & (unsigned short int) _ISspace) ) {
        i++;
    }
    result = append_to_list( result, slice( text, 0, i ) );
    while ( (text[i] != '\0') && ((*__ctype_b_loc ())[(int) ((text[i]))] & (unsigned short int) _ISspace) ) {
        i++;
    }
    result = append_to_list( result, slice( text, i, 0 ) );
    return result;
}

canonical_original_code:
struct list *split_after_first_word(char *text)
{
    int i = 0;
    struct list *result = ((void *)0);
    while ( (text[i] != '\0') && !((*__ctype_b_loc ())[(int) ((text[i]))] & (unsigned short) _ISspace) ) {
        i++;
    }
    result = append_to_list( result, slice( text, 0, i ) );
    while ( (text[i] != '\0') && ((*__ctype_b_loc ())[(int) ((text[i]))] & (unsigned short) _ISspace) ) {
        i++;
    }
    result = append_to_list( result, slice( text, i, 0 ) );
    return result;
}

variable_types:
text
char *

variable_types: i int

variable_types: struct list { struct list *next; char *contents; } *


split

original_code:
List *split( char *text, char *delimiters )
{
    int length = strlen(text);
    int in_quote = 0;
    int i;
    List *result = ((void *)0);
    char *buffer;
    char *p;
    buffer = malloc( length + 1 );
    p = buffer;
    for ( i = 0; i < length; i++ ) {
        if ( text[i] == '"' ) {
            in_quote = !in_quote;
        } else if ( in_quote || (strchr(delimiters, text[i]) == ((void *)0)) ) {
            *p++ = text[i];
        } else if ( p != buffer ) {
            *p = '\0';
            result = append_to_list( result, strdup( buffer ) );
            p = buffer;
        }
    }
    if ( p != buffer ) {
        *p = '\0';
        result = append_to_list( result, strdup( buffer ) );
    }
    free( buffer );
    return result;
}

canonical_original_code:
struct list *split(char *text, char *delimiters)
{
    int length = strlen(text);
    int in_quote = 0;
    int i;
    struct list *result = ((void *)0);
    char *buffer;
    char *p;
    buffer = malloc( length + 1 );
    p = buffer;
    for ( i = 0; i < length; i++ ) {
        if ( text[i] == '"' ) {
            in_quote = !in_quote;
        } else if ( in_quote || (strchr(delimiters, text[i]) == ((void *)0)) ) {
            *p++ = text[i];
        } else if ( p != buffer ) {
            *p = '\0';
            result = append_to_list( result, strdup( buffer ) );
            p = buffer;
        }
    }
    if ( p != buffer ) {
        *p = '\0';
        result = append_to_list( result, strdup( buffer ) );
    }
    free( buffer );
    return result;
}

variable_types:
delimiters
char *

variable_types:
buffer
char *

variable_types:
p
char *

return_type: struct list { struct list *next; char *contents; } *


trim

decompiled_code:
char *__fastcall trim(void *ptr)
{
int v1; // ebx
const unsigned __int16 *v2; // rdx
char *v3; // rax
int v4; // esi
char *v5; // rax
char *v6; // rbx

v1 = strlen((const char *)ptr) - 1;
if ( v1 <= 0 )
{
v4 = 0;
}
else
{
v2 = *_ctype_b_loc();
v3 = (char *)ptr;
v4 = 0;
while ( (v2[*v3] & 0x2000) != 0 )
{
++v4;
++v3;
if ( v1 == v4 )
goto LABEL_10;
}
if ( v1 > v4 )
{
v5 = (char *)ptr + v1;
do
{
if ( (v2[*v5] & 0x2000) == 0 )
break;
--v1;
--v5;
}
while ( v1 > v4 );
}
}
LABEL_10:
v6 = slice((const char *)ptr, v4, v1 + 1);
free(ptr);
return v6;
}

canonical_decompiled_code:
char *__fastcall func5(void *ptr)
{
int v1; // ebx
const unsigned __int16 *v2; // rdx
char *v3; // rax
int v4; // esi
char *v5; // rax
char *v6; // rbx

v1 = strlen((const char *)ptr) - 1;
if ( v1 <= 0 )
{
v4 = 0;
}
else
{
v2 = *_ctype_b_loc();
v3 = (char *)ptr;
v4 = 0;
while ( (v2[*v3] & 0x2000) != 0 )
{
++v4;
++v3;
if ( v1 == v4 )
goto LABEL_10;
}
if ( v1 > v4 )
{
v5 = (char *)ptr + v1;
do
{
if ( (v2[*v5] & 0x2000) == 0 )
break;
--v1;
--v5;
}
while ( v1 > v4 );
}
}
LABEL_10:
v6 = func1((const char *)ptr, v4, v1 + 1);
free(ptr);
return v6;
}

original_code:
char *trim( char *s )
{
    int begin = 0;
    int end = strlen(s) - 1;
    char *result;
    while ( (begin < end) && ((*__ctype_b_loc ())[(int) ((s[begin]))] & (unsigned short int) _ISspace) ) {
        begin++;
    }
    while ( (end > begin) && ((*__ctype_b_loc ())[(int) ((s[end]))] & (unsigned short int) _ISspace) ) {
        end--;
    }
    result = slice( s, begin, (end+1) );
    free( s );
    return ( result );
}

canonical_original_code:
char *trim(char *s)
{
    int begin = 0;
    int end = strlen(s) - 1;
    char *result;
    while ( (begin < end) && ((*__ctype_b_loc ())[(int) ((s[begin]))] & (unsigned short) _ISspace) ) {
        begin++;
    }
    while ( (end > begin) && ((*__ctype_b_loc ())[(int) ((s[end]))] & (unsigned short) _ISspace) ) {
        end--;
    }
    result = slice( s, begin, (end+1) );
    free( s );
    return ( result );
}

variable_types: begin int

variable_types: end int


decompiled_code:
void *__fastcall get_string_in_brackets(void *a1)
{
return get_enclosed_string(a1, 40, 41);
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
return func2(a1, 40, 41);
}

original_code:
char *get_string_in_brackets( char *string )
{
    return get_enclosed_string( string, '(', ')' );
}

canonical_original_code:
char *get_string_in_brackets(char *string)
{
    return get_enclosed_string( string, '(', ')' );
}

variable_types:
string
char *


decompiled_code:
void *__fastcall get_string_in_quotes(void *a1)
{
return get_enclosed_string(a1, 34, 34);
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
return func2(a1, 34, 34);
}

original_code:
char *get_string_in_quotes( char *string )
{
    return get_enclosed_string( string, '"', '"' );
}

canonical_original_code:
char *get_string_in_quotes(char *string)
{
    return get_enclosed_string( string, '"', '"' );
}


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = (_QWORD *)*a1;
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
a1 = (_QWORD *)*a1;
result = (unsigned int)(result + 1);
}
while ( a1 );
return result;
}

original_code:
int list_length( List *list )
{
    int result = 0;
    while ( list != ((void *)0) ) {
        list = list->next;
        result++;
    }
    return result;
}

canonical_original_code:
int list_length(struct list *list)
{
    int result = 0;
    while ( list != ((void *)0) ) {
        list = list->next;
        result++;
    }
    return result;
}

variable_types: result int

user_defined_types: struct list { struct list *next; char *contents; }


decompiled_code:
char *__fastcall get_nth_word(_QWORD *a1, int a2)
{
const char *v2; // rax

for ( ; a2 > 0 && a1; a1 = (_QWORD *)*a1 )
--a2;
v2 = &s;
if ( a1 )
v2 = (const char *)a1[1];
return strdup(v2);
}

canonical_decompiled_code:
char *__fastcall func1(_QWORD *a1, int a2)
{
const char *v2; // rax

for ( ; a2 > 0 && a1; a1 = (_QWORD *)*a1 )
--a2;
v2 = &s;
if ( a1 )
v2 = (const char *)a1[1];
return strdup(v2);
}

original_code:
char *get_nth_word( List *list, int n )
{
    char *word;
    while ( (n > 0) && (list != ((void *)0)) ) {
        n--;
        list = list->next;
    }
    if ( list != ((void *)0) ) {
        word = list->contents;
    } else {
        word = "";
    }
    return strdup( word );
}

canonical_original_code:
char *get_nth_word(struct list *list, int n)
{
    char *word;
    while ( (n > 0) && (list != ((void *)0)) ) {
        n--;
        list = list->next;
    }
    if ( list != ((void *)0) ) {
        word = list->contents;
    } else {
        word = "";
    }
    return strdup( word );
}

variable_types: n int

variable_types:
word
char *


decompiled_code:
void __fastcall free_list(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

v1 = ptr;
if ( ptr )
{
while ( 1 )
{
v3 = (void *)v1[1];
if ( v3 )
free(v3);
v2 = (_QWORD *)*v1;
free(v1);
if ( !v2 )
break;
v1 = v2;
}
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

v1 = ptr;
if ( ptr )
{
while ( 1 )
{
v3 = (void *)v1[1];
if ( v3 )
free(v3);
v2 = (_QWORD *)*v1;
free(v1);
if ( !v2 )
break;
v1 = v2;
}
}
}

original_code:
void free_list( List *list )
{
    List *entry;
    while ( list != ((void *)0) ) {
        if ( list->contents != ((void *)0) ) {
            free( list->contents );
        }
        entry = list;
        list = list->next;
        free( entry );
    }
}

canonical_original_code:
void free_list(struct list *list)
{
    struct list *entry;
    while ( list != ((void *)0) ) {
        if ( list->contents != ((void *)0) ) {
            free( list->contents );
        }
        entry = list;
        list = list->next;
        free( entry );
    }
}


decompiled_code:
char *__fastcall lookup_alias(char *s1, char *a2)
{
char *v2; // rbx
char *result; // rax

v2 = a2;
result = a2;
if ( a2 )
{
while ( strcmp(s1, *((const char **)v2 + 1)) )
{
v2 = *(char **)v2;
if ( !v2 )
return 0LL;
}
result = strdup(*((const char **)v2 + 2));
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *s1, char *a2)
{
char *v2; // rbx
char *result; // rax

v2 = a2;
result = a2;
if ( a2 )
{
while ( strcmp(s1, *((const char **)v2 + 1)) )
{
v2 = *(char **)v2;
if ( !v2 )
return 0LL;
}
result = strdup(*((const char **)v2 + 2));
}
return result;
}

original_code:
char *lookup_alias( char *cmd, Alias *a )
{
    while ( (a != ((void *)0)) && (strcmp( cmd, a->lhs ) != 0) ) {
        a = a->next;
    }
    if ( a != ((void *)0) ) {
        return strdup( a->rhs );
    } else {
        return ((void *)0);
    }
}

canonical_original_code:
char *lookup_alias(char *cmd, struct alias *a)
{
    while ( (a != ((void *)0)) && (strcmp( cmd, a->lhs ) != 0) ) {
        a = a->next;
    }
    if ( a != ((void *)0) ) {
        return strdup( a->rhs );
    } else {
        return ((void *)0);
    }
}

variable_types:
cmd
char *

variable_types: struct alias { struct alias *next; char *lhs; char *rhs; } *


repo: ellysh/pci-dask

decompiled_code:
int __fastcall sig3_handler(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 60 )
++int3_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 2LL, &v2);
return printf("INT3 count = %d, COS Data: %x. \n", (unsigned int)int3_count, v2);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 60 )
++int3_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 2LL, &v2);
return printf("INT3 count = %d, COS Data: %x. \n", (unsigned int)int3_count, v2);
}

original_code:
void sig3_handler(int signo)
{
    U32 CosData = 0;
    switch(signo){
        case 60:
            int3_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 2, &CosData);
    printf("INT3 count = %d, COS Data: %x. \n", int3_count, CosData);
    return;
}

canonical_original_code:
void sig3_handler(int signo)
{
    unsigned long CosData = 0;
    switch(signo){
        case 60:
            int3_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 2, &CosData);
    printf("INT3 count = %d, COS Data: %x. \n", int3_count, CosData);
    return;
}

variable_types: signo int

variable_types:
CosData
unsigned long


decompiled_code:
int __fastcall sig4_handler(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 59 )
++int4_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 3LL, &v2);
return printf("INT4 count = %d, COS Data: %x. \n", (unsigned int)int4_count, v2);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 59 )
++int4_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 3LL, &v2);
return printf("INT4 count = %d, COS Data: %x. \n", (unsigned int)int4_count, v2);
}

original_code:
void sig4_handler(int signo)
{
    U32 CosData = 0;
    switch(signo){
        case 59:
            int4_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 3, &CosData);
    printf("INT4 count = %d, COS Data: %x. \n", int4_count, CosData);
    return;
}

canonical_original_code:
void sig4_handler(int signo)
{
    unsigned long CosData = 0;
    switch(signo){
        case 59:
            int4_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 3, &CosData);
    printf("INT4 count = %d, COS Data: %x. \n", int4_count, CosData);
    return;
}


decompiled_code:
int __fastcall sig1_handler(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 61 )
++int_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 0LL, &v2);
return printf("INT1 count = %d, COS Data: %x. \n", (unsigned int)int_count, v2);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 61 )
++int_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 0LL, &v2);
return printf("INT1 count = %d, COS Data: %x. \n", (unsigned int)int_count, v2);
}

original_code:
void sig1_handler(int signo)
{
    U32 CosData = 0;
    switch(signo){
        case 61:
            int_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 0, &CosData);
    printf("INT1 count = %d, COS Data: %x. \n", int_count, CosData);
    return;
}

canonical_original_code:
void sig1_handler(int signo)
{
    unsigned long CosData = 0;
    switch(signo){
        case 61:
            int_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 0, &CosData);
    printf("INT1 count = %d, COS Data: %x. \n", int_count, CosData);
    return;
}


decompiled_code:
int __fastcall sig2_handler(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 62 )
++int2_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 1LL, &v2);
return printf("INT2 count = %d, COS Data: %x. \n", (unsigned int)int2_count, v2);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 == 62 )
++int2_count;
DIO_GetCOSLatchDataInt32((unsigned __int16)card, 1LL, &v2);
return printf("INT2 count = %d, COS Data: %x. \n", (unsigned int)int2_count, v2);
}

original_code:
void sig2_handler(int signo)
{
    U32 CosData = 0;
    switch(signo){
        case 62:
            int2_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 1, &CosData);
    printf("INT2 count = %d, COS Data: %x. \n", int2_count, CosData);
    return;
}

canonical_original_code:
void sig2_handler(int signo)
{
    unsigned long CosData = 0;
    switch(signo){
        case 62:
            int2_count ++;
            break;
    }
    DIO_GetCOSLatchDataInt32(card, 1, &CosData);
    printf("INT2 count = %d, COS Data: %x. \n", int2_count, CosData);
    return;
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
__int16 v4; // ax
__int64 v5; // rsi
__int16 v6; // ax
__int16 v7; // ax
__int16 v8; // ax

setbuf(stdout, 0LL);
puts("\nPCI-7443 Dual Interrupt Sample");
puts("\nThis program shows the number of occurrence of interrupt");
puts("for COS0, COS1, COS2 and COS3 interrupt lines.");
printf("\nPlease input a card number: ");
_isoc99_scanf(" %hd", &card_number);
v3 = Register_Card(38LL, (unsigned __int16)card_number);
card = v3;
if ( v3 >= 0 )
{
usleep(0x3E8u);
v4 = DIO_SetCOSInterrupt32((unsigned __int16)card, 0LL, 1LL, sig1_handler);
v5 = (unsigned int)v4;
if ( v4
|| (v6 = DIO_SetCOSInterrupt32((unsigned __int16)card, 1LL, 1LL, sig2_handler), v5 = (unsigned int)v6, v6)
|| (v7 = DIO_SetCOSInterrupt32((unsigned __int16)card, 2LL, 1LL, sig3_handler), v5 = (unsigned int)v7, v7)
|| (v8 = DIO_SetCOSInterrupt32((unsigned __int16)card, 3LL, 1LL, sig4_handler), v5 = (unsigned int)v8, v8) )
{
printf(" error from DIO_SetCOSInterrupt32 : %d \n", v5);
}
else
{
puts("\nPress any key to exit...");
getch();
DIO_SetCOSInterrupt32((unsigned __int16)card, 0LL, 0LL, 0LL);
DIO_SetCOSInterrupt32((unsigned __int16)card, 1LL, 0LL, 0LL);
DIO_SetCOSInterrupt32((unsigned __int16)card, 2LL, 0LL, 0LL);
DIO_SetCOSInterrupt32((unsigned __int16)card, 3LL, 0LL, 0LL);
}
if ( card >= 0 )
Release_Card((unsigned __int16)card);
exit(0);
}
printf("Register_Card Error = %d\n", (unsigned int)v3);
exit(0);
}

original_code:
int main(void)
{
    int err;
    char temp_char;
    setbuf( stdout, ((void *)0) );
    printf("\nPCI-7443 Dual Interrupt Sample\n" );
    printf("\nThis program shows the number of occurrence of interrupt\n" );
    printf("for COS0, COS1, COS2 and COS3 interrupt lines.\n" );
    printf("\nPlease input a card number: ");
    scanf(" %hd", &card_number);
    if((card=Register_Card(38, card_number))<0){
        printf("Register_Card Error = %d\n", card);
        exit(0);
    }
    usleep(1000);
    err = DIO_SetCOSInterrupt32(card, 0, 0x1, sig1_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, 1, 0x1, sig2_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, 2, 0x1, sig3_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, 3, 0x1, sig4_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    printf("\nPress any key to exit...\n" );
    temp_char = getch();
    DIO_SetCOSInterrupt32(card, 0, 0, ((void *)0));
    DIO_SetCOSInterrupt32(card, 1, 0, ((void *)0));
    DIO_SetCOSInterrupt32(card, 2, 0, ((void *)0));
    DIO_SetCOSInterrupt32(card, 3, 0, ((void *)0));
exit_after_error:
    if(card>=0)
        Release_Card(card);
    exit(0);
}

canonical_original_code:
int main()
{
    int err;
    char temp_char;
    setbuf( stdout, ((void *)0) );
    printf("\nPCI-7443 Dual Interrupt Sample\n" );
    printf("\nThis program shows the number of occurrence of interrupt\n" );
    printf("for COS0, COS1, COS2 and COS3 interrupt lines.\n" );
    printf("\nPlease input a card number: ");
    scanf(" %hd", &card_number);
    if((card=Register_Card(38, card_number))<0){
        printf("Register_Card Error = %d\n", card);
        exit(0);
    }
    usleep(1000);
    err = DIO_SetCOSInterrupt32(card, 0, 0x1, sig1_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, 1, 0x1, sig2_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, 2, 0x1, sig3_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    err = DIO_SetCOSInterrupt32(card, 3, 0x1, sig4_handler);
    if(err!=0){
        printf(" error from DIO_SetCOSInterrupt32 : %d \n" , err );
        goto exit_after_error;
    }
    printf("\nPress any key to exit...\n" );
    temp_char = getch();
    DIO_SetCOSInterrupt32(card, 0, 0, ((void *)0));
    DIO_SetCOSInterrupt32(card, 1, 0, ((void *)0));
    DIO_SetCOSInterrupt32(card, 2, 0, ((void *)0));
    DIO_SetCOSInterrupt32(card, 3, 0, ((void *)0));
exit_after_error:
    if(card>=0)
        Release_Card(card);
    exit(0);
}

variable_types: err int


original_code:
void exch_data(unsigned short * tbuf, U32 cnt)
{
    unsigned short temp;
    int i;
    for (i=0;i<cnt;i++) {
        if (!(i%2)) {
            temp = tbuf[i];
            tbuf[i] = tbuf[i+1];
            tbuf[i+1] = temp;
        }
    }
}

canonical_original_code:
void exch_data(unsigned short *tbuf, unsigned long cnt)
{
    unsigned short temp;
    int i;
    for (i=0;i<cnt;i++) {
        if (!(i%2)) {
            temp = tbuf[i];
            tbuf[i] = tbuf[i+1];
            tbuf[i+1] = temp;
        }
    }
}

variable_types:
tbuf
unsigned short *

variable_types:
cnt
unsigned long

variable_types:
temp
unsigned short


restore

decompiled_code:
int __fastcall restore(__int64 a1)
{
int result; // eax

result = ioctl(0, 0x5408uLL, a1);
if ( result == -1 )
{
perror("ioctl");
exit(5);
}
return result;
}

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

result = ioctl(0, 0x5408uLL, a1);
if ( result == -1 )
{
perror("ioctl");
exit(5);
}
return result;
}

original_code:
void restore(struct termio *tty_save)
{
    if(ioctl(0, 0x5408, tty_save)==-1){
        perror("ioctl");
        exit(5);
    }
    return;
}

variable_types: struct termio { unsigned short c_iflag; unsigned short c_oflag; unsigned short c_cflag; unsigned short c_lflag; unsigned char c_line; unsigned char c_cc[8]; } *


getch

decompiled_code:
__int64 getch()
{
int v0; // eax
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__int16 v3; // [rsp+10h] [rbp-18h]
char buf[9]; // [rsp+1Fh] [rbp-9h] BYREF

if ( ioctl(0, 0x5405uLL, &v2) == -1 )
{
perror("ioctl");
exit(1);
}
ttysave_1 = (__int128)_mm_loadu_si128(&v2);
word_2D0 = v3;
v2.m128i_i16[3] &= 0xFFF4u;
v2.m128i_i16[7] = 256;
if ( ioctl(0, 0x5408uLL, &v2) == -1 )
{
restore((__int64)&ttysave_1);
perror("ioctl");
exit(2);
}
v0 = read(0, buf, 1uLL);
if ( v0 == -1 )
{
restore((__int64)&ttysave_1);
perror("read");
exit(3);
}
if ( !v0 )
{
restore((__int64)&ttysave_1);
fwrite("EOF error!", 1uLL, 0xAuLL, stderr);
exit(4);
}
restore((__int64)&ttysave_1);
return (unsigned __int8)buf[0];
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__int16 v3; // [rsp+10h] [rbp-18h]
char buf[9]; // [rsp+1Fh] [rbp-9h] BYREF

if ( ioctl(0, 0x5405uLL, &v2) == -1 )
{
perror("ioctl");
exit(1);
}
ttysave_1 = (__int128)_mm_loadu_si128(&v2);
word_2D0 = v3;
v2.m128i_i16[3] &= 0xFFF4u;
v2.m128i_i16[7] = 256;
if ( ioctl(0, 0x5408uLL, &v2) == -1 )
{
func0((__int64)&ttysave_1);
perror("ioctl");
exit(2);
}
v0 = read(0, buf, 1uLL);
if ( v0 == -1 )
{
func0((__int64)&ttysave_1);
perror("read");
exit(3);
}
if ( !v0 )
{
func0((__int64)&ttysave_1);
fwrite("EOF error!", 1uLL, 0xAuLL, stderr);
exit(4);
}
func0((__int64)&ttysave_1);
return (unsigned __int8)buf[0];
}

original_code:
char getch(void)
{
    char ch;
    int total, flag = 1;
    static struct termio ttysave;
    struct termio tty;
    if(flag){
        flag = 0;
        if(ioctl(0, 0x5405, &tty)==-1){
            perror("ioctl");
            exit(1);
        }
        ttysave = tty;
        tty.c_lflag &= ~(0000002|0000010|0000001);
        tty.c_cc[6] = 1;
        tty.c_cc[5] = 0;
        if(ioctl(0, 0x5408, &tty)==-1){
            restore(&ttysave);
            perror("ioctl");
            exit(2);
        }
    }
    switch(total = read(0, &ch, 1)){
        case -1:
            restore(&ttysave);
            perror("read");
            exit(3);
        case 0:
            restore(&ttysave);
            fputs("EOF error!", stderr );
            exit(4);
        default:
            ;
    }
    restore(&ttysave);
    return ch;
}

canonical_original_code:
char getch()
{
    char ch;
    int total; int flag = 1;
    static struct termio ttysave;
    struct termio tty;
    if(flag){
        flag = 0;
        if(ioctl(0, 0x5405, &tty)==-1){
            perror("ioctl");
            exit(1);
        }
        ttysave = tty;
        tty.c_lflag &= ~(0000002|0000010|0000001);
        tty.c_cc[6] = 1;
        tty.c_cc[5] = 0;
        if(ioctl(0, 0x5408, &tty)==-1){
            restore(&ttysave);
            perror("ioctl");
            exit(2);
        }
    }
    switch(total = read(0, &ch, 1)){
        case -1:
            restore(&ttysave);
            perror("read");
            exit(3);
        case 0:
            restore(&ttysave);
            fputs("EOF error!", stderr );
            exit(4);
        default:
            ;
    }
    restore(&ttysave);
    return ch;
}

variable_types: ch char

variable_types: total int

variable_types: flag int

variable_types: struct termio { unsigned short c_iflag; unsigned short c_oflag; unsigned short c_cflag; unsigned short c_lflag; unsigned char c_line; unsigned char c_cc[8]; }

return_type: char


decompiled_code:
bool kb_hit()
{
int v0; // ebx
__m128i v2; // [rsp+0h] [rbp-28h] BYREF
__int16 v3; // [rsp+10h] [rbp-18h]
char buf[9]; // [rsp+1Fh] [rbp-9h] BYREF

if ( ioctl(0, 0x5405uLL, &v2) == -1 )
{
perror("ioctl");
exit(1);
}
ttysave_0 = (__int128)_mm_loadu_si128(&v2);
word_2B0 = v3;
v2.m128i_i16[3] &= 0xFFF4u;
v2.m128i_i16[7] = 1;
if ( ioctl(0, 0x5408uLL, &v2) == -1 )
{
restore((__int64)&ttysave_0);
perror("ioctl");
exit(2);
}
v0 = read(0, buf, 1uLL);
if ( v0 == -1 )
{
restore((__int64)&ttysave_0);
perror("read");
exit(3);
}
restore((__int64)&ttysave_0);
return v0 != 0;
}

original_code:
char kb_hit(void)
{
    int total, flag = 1;
    char result = 0x00;
    char temp_char;
    static struct termio ttysave;
    struct termio tty;
    if(flag){
        flag = 0;
        if(ioctl(0, 0x5405, &tty)==-1){
            perror("ioctl");
            exit(1);
        }
        ttysave = tty;
        tty.c_lflag &= ~(0000002|0000010|0000001);
        tty.c_cc[6] =0;
        tty.c_cc[5] =1;
        if(ioctl(0, 0x5408, &tty)==-1){
            restore(&ttysave);
            perror("ioctl");
            exit(2);
        }
    }
    switch(total = read(0, &temp_char, 1)){
        case -1:
            restore(&ttysave);
            perror("read");
            exit(3);
        case 0:
            result = 0x00;
            break;
        default:
            result = 0x01;
            break;
    }
    restore(&ttysave);
    return result;
}

canonical_original_code:
char kb_hit()
{
    int total; int flag = 1;
    char result = 0x00;
    char temp_char;
    static struct termio ttysave;
    struct termio tty;
    if(flag){
        flag = 0;
        if(ioctl(0, 0x5405, &tty)==-1){
            perror("ioctl");
            exit(1);
        }
        ttysave = tty;
        tty.c_lflag &= ~(0000002|0000010|0000001);
        tty.c_cc[6] =0;
        tty.c_cc[5] =1;
        if(ioctl(0, 0x5408, &tty)==-1){
            restore(&ttysave);
            perror("ioctl");
            exit(2);
        }
    }
    switch(total = read(0, &temp_char, 1)){
        case -1:
            restore(&ttysave);
            perror("read");
            exit(3);
        case 0:
            result = 0x00;
            break;
        default:
            result = 0x01;
            break;
    }
    restore(&ttysave);
    return result;
}

variable_types: result char

user_defined_types: struct termio { unsigned short c_iflag; unsigned short c_oflag; unsigned short c_cflag; unsigned short c_lflag; unsigned char c_line; unsigned char c_cc[8]; }


kbhit

decompiled_code:
__int64 kbhit()
{
fd_set v1; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&v1, 0, sizeof(v1));
v1.fds_bits[0] |= 1uLL;
select(1, &v1, 0LL, 0LL, &timeout);
return v1.fds_bits[0] & 1;
}

canonical_decompiled_code:
__int64 func3()
{
fd_set v1; // [rsp+0h] [rbp-98h] BYREF
struct timeval timeout; // [rsp+80h] [rbp-18h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 0LL;
memset(&v1, 0, sizeof(v1));
v1.fds_bits[0] |= 1uLL;
select(1, &v1, 0LL, 0LL, &timeout);
return v1.fds_bits[0] & 1;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
rdfs
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
__int64 wait_pulse_start()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

do
{
CTR_Read((unsigned __int16)card, 1LL, v2);
CTR_Read((unsigned __int16)card, 1LL, &v1);
}
while ( v1 != v2[0] );
do
{
CTR_Read((unsigned __int16)card, 1LL, v2);
CTR_Read((unsigned __int16)card, 1LL, &v1);
result = v2[0];
}
while ( v1 == v2[0] );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
__int64 v2[2]; // [rsp+8h] [rbp-10h] BYREF

do
{
CTR_Read((unsigned __int16)card, 1LL, v2);
CTR_Read((unsigned __int16)card, 1LL, &v1);
}
while ( v1 != v2[0] );
do
{
CTR_Read((unsigned __int16)card, 1LL, v2);
CTR_Read((unsigned __int16)card, 1LL, &v1);
result = v2[0];
}
while ( v1 == v2[0] );
return result;
}

original_code:
void wait_pulse_start(void)
{
    U32 oldvalue,newvalue;
    do
    {
        CTR_Read( card, 1, &oldvalue );
        CTR_Read( card, 1, &newvalue );
    } while( newvalue != oldvalue );
    do
    {
        CTR_Read( card, 1, &oldvalue );
        CTR_Read( card, 1, &newvalue );
    } while( newvalue == oldvalue );
}

canonical_original_code:
void wait_pulse_start()
{
    unsigned long oldvalue; unsigned long newvalue;
    do
    {
        CTR_Read( card, 1, &oldvalue );
        CTR_Read( card, 1, &newvalue );
    } while( newvalue != oldvalue );
    do
    {
        CTR_Read( card, 1, &oldvalue );
        CTR_Read( card, 1, &newvalue );
    } while( newvalue == oldvalue );
}

variable_types:
oldvalue
unsigned long

variable_types:
newvalue
unsigned long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
float v4; // xmm0_4
char v5; // al
int v6; // er13
double v7; // xmm0_8
unsigned __int64 v8; // rdx
__int64 v9; // r13
double v10; // xmm0_8
float v11; // xmm0_4
unsigned __int64 v13; // [rsp+8h] [rbp-40h] BYREF
unsigned __int64 v14; // [rsp+10h] [rbp-38h] BYREF
__int64 v15[6]; // [rsp+18h] [rbp-30h] BYREF

setbuf(stdout, 0LL);
v3 = Register_Card(19LL, 0LL);
card = v3;
if ( v3 < 0 )
{
printf("Register_Card Error = %d\n", (unsigned int)v3);
exit(-1);
}
status[0] = 0;
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
printf("\x1B[H\x1B[J");
if ( status[0] )
{
puts("\n");
printf(status);
puts("\n\n\n\n\n\n");
}
puts(
" Please select the function for PCI8554 or Esc for quit:\n"
" (0) Square Wave\n"
" (1) Pluse Generator\n"
" (2) Measure Pulse Width\n"
" (3) Measure Frequency");
v5 = getch();
if ( v5 != 50 )
break;
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 2LL);
CTR_Setup((unsigned __int16)card, 1LL, 2LL, 0LL, 0LL);
wait_pulse_start();
time(&time1);
CTR_Read((unsigned __int16)card, 1LL, &v14);
v6 = 0;
while ( 1 )
{
CTR_Read((unsigned __int16)card, 1LL, &v13);
time(&time2);
v7 = difftime(time2, time1);
v8 = v14;
if ( v13 == v14 )
break;
if ( v7 > 5.0 )
{
v8 = v13;
break;
}
LOWORD(v6) = (v14 < v13) + (_WORD)v6;
v14 = v13;
}
if ( v7 >= 5.0 )
{
strcpy(status, "*** Measure inappropriate pulse width ***\n");
}
else
{
v9 = (v6 << 16) - v8 + 65537;
if ( v9 < 0 )
v10 = (double)(int)(v9 & 1 | ((unsigned __int64)v9 >> 1))
+ (double)(int)(v9 & 1 | ((unsigned __int64)v9 >> 1));
else
v10 = (double)(int)v9;
v11 = v10 * 0.125;
sprintf(status, "*** High level pulse width = %f micro-second ***\n", v11);
}
}
if ( v5 <= 50 )
break;
if ( v5 == 51 )
{
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 0LL);
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 2LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 3LL, 1LL);
CTR_Setup((unsigned __int16)card, 1LL, 2LL, 0xFFFFLL, 0LL);
CTR_Setup((unsigned __int16)card, 2LL, 2LL, 4LL, 0LL);
CTR_Setup((unsigned __int16)card, 3LL, 0LL, 0xFFFFLL, 0LL);
usleep(0xF4240u);
CTR_Read((unsigned __int16)card, 1LL, v15);
v4 = (double)(unsigned __int16)~LOWORD(v15[0]) * 2000000.0 / 65535.0;
sprintf(status, "Measured Signal Frequency = %f Hz.\n", v4);
}
else
{
strcpy(status, " Unknown choice , please select again \n");
}
}
if ( v5 != 48 )
break;
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 2LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 3LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 4LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 5LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 6LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 7LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 8LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 9LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 10LL, 2LL);
CTR_Setup((unsigned __int16)card, 1LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 2LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 3LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 4LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 5LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 6LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 7LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 8LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 9LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 10LL, 3LL, 32LL, 0LL);
strcpy(status, "*** 250 KHz square wave is ready on the COUT1 ~ 11 ***\n");
}
if ( v5 != 49 )
break;
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 2LL, 1LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 3LL, 1LL);
CTR_Setup((unsigned __int16)card, 1LL, 3LL, 200LL, 0LL);
CTR_Setup((unsigned __int16)card, 2LL, 3LL, 200LL, 0LL);
CTR_Setup((unsigned __int16)card, 3LL, 3LL, 200LL, 0LL);
strcpy(status, " *** A pulse per second is ready on the COUT3 ***\n");
}
strcpy(status, " Unknown choice , please select again \n");
}
while ( v5 != 27 );
if ( card >= 0 )
Release_Card((unsigned __int16)card);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
float v4; // xmm0_4
char v5; // al
int v6; // er13
double v7; // xmm0_8
unsigned __int64 v8; // rdx
__int64 v9; // r13
double v10; // xmm0_8
float v11; // xmm0_4
unsigned __int64 v13; // [rsp+8h] [rbp-40h] BYREF
unsigned __int64 v14; // [rsp+10h] [rbp-38h] BYREF
__int64 v15[6]; // [rsp+18h] [rbp-30h] BYREF

setbuf(stdout, 0LL);
v3 = Register_Card(19LL, 0LL);
card = v3;
if ( v3 < 0 )
{
printf("Register_Card Error = %d\n", (unsigned int)v3);
exit(-1);
}
status[0] = 0;
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
printf("\x1B[H\x1B[J");
if ( status[0] )
{
puts("\n");
printf(status);
puts("\n\n\n\n\n\n");
}
puts(
" Please select the function for PCI8554 or Esc for quit:\n"
" (0) Square Wave\n"
" (1) Pluse Generator\n"
" (2) Measure Pulse Width\n"
" (3) Measure Frequency");
v5 = getch();
if ( v5 != 50 )
break;
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 2LL);
CTR_Setup((unsigned __int16)card, 1LL, 2LL, 0LL, 0LL);
func0();
time(&time1);
CTR_Read((unsigned __int16)card, 1LL, &v14);
v6 = 0;
while ( 1 )
{
CTR_Read((unsigned __int16)card, 1LL, &v13);
time(&time2);
v7 = difftime(time2, time1);
v8 = v14;
if ( v13 == v14 )
break;
if ( v7 > 5.0 )
{
v8 = v13;
break;
}
LOWORD(v6) = (v14 < v13) + (_WORD)v6;
v14 = v13;
}
if ( v7 >= 5.0 )
{
strcpy(status, "*** Measure inappropriate pulse width ***\n");
}
else
{
v9 = (v6 << 16) - v8 + 65537;
if ( v9 < 0 )
v10 = (double)(int)(v9 & 1 | ((unsigned __int64)v9 >> 1))
+ (double)(int)(v9 & 1 | ((unsigned __int64)v9 >> 1));
else
v10 = (double)(int)v9;
v11 = v10 * 0.125;
sprintf(status, "*** High level pulse width = %f micro-second ***\n", v11);
}
}
if ( v5 <= 50 )
break;
if ( v5 == 51 )
{
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 0LL);
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 2LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 3LL, 1LL);
CTR_Setup((unsigned __int16)card, 1LL, 2LL, 0xFFFFLL, 0LL);
CTR_Setup((unsigned __int16)card, 2LL, 2LL, 4LL, 0LL);
CTR_Setup((unsigned __int16)card, 3LL, 0LL, 0xFFFFLL, 0LL);
usleep(0xF4240u);
CTR_Read((unsigned __int16)card, 1LL, v15);
v4 = (double)(unsigned __int16)~LOWORD(v15[0]) * 2000000.0 / 65535.0;
sprintf(status, "Measured Signal Frequency = %f Hz.\n", v4);
}
else
{
strcpy(status, " Unknown choice , please select again \n");
}
}
if ( v5 != 48 )
break;
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 2LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 3LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 4LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 5LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 6LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 7LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 8LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 9LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 10LL, 2LL);
CTR_Setup((unsigned __int16)card, 1LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 2LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 3LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 4LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 5LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 6LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 7LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 8LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 9LL, 3LL, 32LL, 0LL);
CTR_Setup((unsigned __int16)card, 10LL, 3LL, 32LL, 0LL);
strcpy(status, "*** 250 KHz square wave is ready on the COUT1 ~ 11 ***\n");
}
if ( v5 != 49 )
break;
CTR_8554_CK1_Config((unsigned __int16)card, 0LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 1LL, 2LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 2LL, 1LL);
CTR_8554_ClkSrc_Config((unsigned __int16)card, 3LL, 1LL);
CTR_Setup((unsigned __int16)card, 1LL, 3LL, 200LL, 0LL);
CTR_Setup((unsigned __int16)card, 2LL, 3LL, 200LL, 0LL);
CTR_Setup((unsigned __int16)card, 3LL, 3LL, 200LL, 0LL);
strcpy(status, " *** A pulse per second is ready on the COUT3 ***\n");
}
strcpy(status, " Unknown choice , please select again \n");
}
while ( v5 != 27 );
if ( card >= 0 )
Release_Card((unsigned __int16)card);
return 0;
}

original_code:
int main(void)
{
    char func=0x00;
    U32 value;
    U16 under_flow;
    U32 old_value, new_value;
    float pulse_width, frequency;
    double period;
    setbuf( stdout, ((void *)0) );
    if ((card=Register_Card(19, 0)) < 0) {
        printf("Register_Card Error = %d\n", card);
        exit(-1);
    }
    status[0]=0x00;
    do{
        printf("\033[H\033[J");
        if( status[0] != 0x00 ){
            printf("\n\n");
            printf( status );
            printf("\n\n\n\n\n\n\n");
        }
        printf(" Please select the function for PCI8554 or Esc for quit:\n  (0) Square Wave\n  (1) Pluse Generator\n  (2) Measure Pulse Width\n  (3) Measure Frequency\n");
        func = getch();
        switch (func) {
            case 0x30:
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 1, 2);
                CTR_8554_ClkSrc_Config(card, 2, 2);
                CTR_8554_ClkSrc_Config(card, 3, 2);
                CTR_8554_ClkSrc_Config(card, 4, 2);
                CTR_8554_ClkSrc_Config(card, 5, 2);
                CTR_8554_ClkSrc_Config(card, 6, 2);
                CTR_8554_ClkSrc_Config(card, 7, 2);
                CTR_8554_ClkSrc_Config(card, 8, 2);
                CTR_8554_ClkSrc_Config(card, 9, 2);
                CTR_8554_ClkSrc_Config(card, 10, 2);
                CTR_Setup(card, 1, 3, 32, 0);
                CTR_Setup(card, 2, 3, 32, 0);
                CTR_Setup(card, 3, 3, 32, 0);
                CTR_Setup(card, 4, 3, 32, 0);
                CTR_Setup(card, 5, 3, 32, 0);
                CTR_Setup(card, 6, 3, 32, 0);
                CTR_Setup(card, 7, 3, 32, 0);
                CTR_Setup(card, 8, 3, 32, 0);
                CTR_Setup(card, 9, 3, 32, 0);
                CTR_Setup(card, 10, 3, 32, 0);
                sprintf( status, "*** 250 KHz square wave is ready on the COUT1 ~ 11 ***\n");
                break;
            case 0x31:
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 1, 2);
                CTR_8554_ClkSrc_Config(card, 2, 1);
                CTR_8554_ClkSrc_Config(card, 3, 1);
                CTR_Setup(card, 1, 3, 200, 0);
                CTR_Setup(card, 2, 3, 200, 0);
                CTR_Setup(card, 3, 3, 200, 0);
                sprintf( status, " *** A pulse per second is ready on the COUT3 ***\n");
                break;
            case 0x32:
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 1, 2);
                CTR_Setup(card, 1, 2, 0, 0);
                under_flow = 0;
                wait_pulse_start();
                time(&time1);
                CTR_Read(card, 1, &old_value);
                while (1) {
                    CTR_Read(card, 1, &new_value);
                    time(&time2);
                    period = difftime(time2,time1);
                    if ((new_value == old_value)||(period > 5))
                        break;
                    if ( old_value < new_value )
                        under_flow++;
                    old_value=new_value;
                }
                if (period < 5) {
                    pulse_width = (65536 - new_value + under_flow * 65536 + 1) * 0.125;
                    sprintf( status, "*** High level pulse width = %f micro-second ***\n", pulse_width);
                }
                else
                    sprintf( status, "*** Measure inappropriate pulse width ***\n");
                break;
            case 0x33:
                CTR_8554_ClkSrc_Config(card, 1, 0);
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 2, 2);
                CTR_8554_ClkSrc_Config(card, 3, 1);
                CTR_Setup(card, 1, 2, 65535, 0);
                CTR_Setup(card, 2, 2, 4, 0);
                CTR_Setup(card, 3, 0, 65535, 0);
                usleep(1000000);
                CTR_Read(card, 1, &value);
                period = 65535 - (value&0xffff);
                frequency = period * 2000000 / 65535;
                sprintf( status, "Measured Signal Frequency = %f Hz.\n",frequency);
                break;
            default:
                sprintf( status, " Unknown choice , please select again \n" );
                break;
        }
    }while( func != 0x1b );
    if (card>=0)
        Release_Card(card);
    return 0;
}

canonical_original_code:
int main()
{
    char func = 0x00;
    unsigned long value;
    unsigned short under_flow;
    unsigned long old_value; unsigned long new_value;
    float pulse_width; float frequency;
    double period;
    setbuf( stdout, ((void *)0) );
    if ((card=Register_Card(19, 0)) < 0) {
        printf("Register_Card Error = %d\n", card);
        exit(-1);
    }
    status[0]=0x00;
    do{
        printf("\033[H\033[J");
        if( status[0] != 0x00 ){
            printf("\n\n");
            printf( status );
            printf("\n\n\n\n\n\n\n");
        }
        printf(" Please select the function for PCI8554 or Esc for quit:\n  (0) Square Wave\n  (1) Pluse Generator\n  (2) Measure Pulse Width\n  (3) Measure Frequency\n");
        func = getch();
        switch (func) {
            case 0x30:
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 1, 2);
                CTR_8554_ClkSrc_Config(card, 2, 2);
                CTR_8554_ClkSrc_Config(card, 3, 2);
                CTR_8554_ClkSrc_Config(card, 4, 2);
                CTR_8554_ClkSrc_Config(card, 5, 2);
                CTR_8554_ClkSrc_Config(card, 6, 2);
                CTR_8554_ClkSrc_Config(card, 7, 2);
                CTR_8554_ClkSrc_Config(card, 8, 2);
                CTR_8554_ClkSrc_Config(card, 9, 2);
                CTR_8554_ClkSrc_Config(card, 10, 2);
                CTR_Setup(card, 1, 3, 32, 0);
                CTR_Setup(card, 2, 3, 32, 0);
                CTR_Setup(card, 3, 3, 32, 0);
                CTR_Setup(card, 4, 3, 32, 0);
                CTR_Setup(card, 5, 3, 32, 0);
                CTR_Setup(card, 6, 3, 32, 0);
                CTR_Setup(card, 7, 3, 32, 0);
                CTR_Setup(card, 8, 3, 32, 0);
                CTR_Setup(card, 9, 3, 32, 0);
                CTR_Setup(card, 10, 3, 32, 0);
                sprintf( status, "*** 250 KHz square wave is ready on the COUT1 ~ 11 ***\n");
                break;
            case 0x31:
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 1, 2);
                CTR_8554_ClkSrc_Config(card, 2, 1);
                CTR_8554_ClkSrc_Config(card, 3, 1);
                CTR_Setup(card, 1, 3, 200, 0);
                CTR_Setup(card, 2, 3, 200, 0);
                CTR_Setup(card, 3, 3, 200, 0);
                sprintf( status, " *** A pulse per second is ready on the COUT3 ***\n");
                break;
            case 0x32:
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 1, 2);
                CTR_Setup(card, 1, 2, 0, 0);
                under_flow = 0;
                wait_pulse_start();
                time(&time1);
                CTR_Read(card, 1, &old_value);
                while (1) {
                    CTR_Read(card, 1, &new_value);
                    time(&time2);
                    period = difftime(time2,time1);
                    if ((new_value == old_value)||(period > 5))
                        break;
                    if ( old_value < new_value )
                        under_flow++;
                    old_value=new_value;
                }
                if (period < 5) {
                    pulse_width = (65536 - new_value + under_flow * 65536 + 1) * 0.125;
                    sprintf( status, "*** High level pulse width = %f micro-second ***\n", pulse_width);
                }
                else
                    sprintf( status, "*** Measure inappropriate pulse width ***\n");
                break;
            case 0x33:
                CTR_8554_ClkSrc_Config(card, 1, 0);
                CTR_8554_CK1_Config(card, 0);
                CTR_8554_ClkSrc_Config(card, 2, 2);
                CTR_8554_ClkSrc_Config(card, 3, 1);
                CTR_Setup(card, 1, 2, 65535, 0);
                CTR_Setup(card, 2, 2, 4, 0);
                CTR_Setup(card, 3, 0, 65535, 0);
                usleep(1000000);
                CTR_Read(card, 1, &value);
                period = 65535 - (value&0xffff);
                frequency = period * 2000000 / 65535;
                sprintf( status, "Measured Signal Frequency = %f Hz.\n",frequency);
                break;
            default:
                sprintf( status, " Unknown choice , please select again \n" );
                break;
        }
    }while( func != 0x1b );
    if (card>=0)
        Release_Card(card);
    return 0;
}

variable_types: func char

variable_types:
value
unsigned long

variable_types: frequency float

variable_types: period double


decompiled_code:
int signal_handler2()
{
return puts("\nfinish");
}

canonical_decompiled_code:
int func0()
{
return puts("\nfinish");
}

original_code:
void signal_handler2(int sig_no)
{
     printf("\nfinish\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
char *v4; // rax
__int16 v5; // ax
__int16 v6; // ax
__int16 v7; // ax
__int16 v8; // ax
char v10[2]; // [rsp+6h] [rbp-12h] BYREF
void *v11; // [rsp+8h] [rbp-10h] BYREF

setbuf(stdout, 0LL);
printf("\x1B[H\x1B[J");
puts(" ========================================================================");
puts(" == 7300 SAMPLE : PCI-7300 Multiple Buffered DMA ==");
puts(" ========================================================================\n\n");
printf(
" The output data is a sine wave and store data to file '%s'. It will not stop until you press a key.\n"
"\n"
"Press any key to start the operation.\n",
file_name);
getch();
v3 = Register_Card(15LL, (unsigned __int16)card_number);
card = v3;
if ( v3 < 0 )
{
printf("Register_Card error=%d\n", (unsigned int)v3);
exit(1);
}
fp = fopen(file_name, "w+b");
v4 = 0LL;
if ( fp )
{
do
{
*(__int16 *)((char *)in_buf + (_QWORD)v4) = 0;
*(__int16 *)((char *)in_buf2 + (_QWORD)v4) = 0;
v4 += 2;
}
while ( v4 != (char *)&unk_30D40 );
v11 = &unk_186A0;
v5 = DI_7300B_Config((unsigned __int16)card, 16LL, 4LL, 0LL, 1LL, 0LL, 1LL, 1LL);
if ( !v5 )
{
DI_EventCallBack((unsigned __int16)card, 1LL, 1LL, signal_handler);
DI_EventCallBack((unsigned __int16)card, 1LL, 0LL, signal_handler2);
v6 = DI_ContMultiBufferSetup((unsigned __int16)card, in_buf, data_size, v10);
if ( v6 >= 0 )
{
v7 = DI_ContMultiBufferSetup((unsigned __int16)card, in_buf2, data_size, v10);
if ( v7 >= 0 )
{
v8 = DI_ContMultiBufferStart((unsigned __int16)card, 0LL, 1.0);
if ( v8 >= 0 )
{
printf("\n\nPress any key to stop input operation.");
puts("\n\nData count : ");
getch();
if ( (unsigned __int16)DI_AsyncClear((unsigned __int16)card, &count) )
{
puts("D2K_AI_AsyncClear Failed !!!, Ready to system hang !!!");
getch();
}
DI_EventCallBack((unsigned __int16)card, 0LL, 1LL, 0LL);
DI_EventCallBack((unsigned __int16)card, 0LL, 0LL, 0LL);
Release_Card((unsigned __int16)card);
fclose(fp);
exit(1);
}
printf("DI_ContMultiBufferStart error=%d", (unsigned int)v8);
DO_AsyncClear((unsigned __int16)card, &v11);
Release_Card((unsigned __int16)card);
exit(1);
}
printf("DI_ContMultiBufferSetup Error=%d\n", (unsigned int)v7);
Release_Card((unsigned __int16)card);
exit(1);
}
printf("DI_ContMultiBufferSetup Error=%d\n", (unsigned int)v6);
Release_Card((unsigned __int16)card);
exit(1);
}
printf("DI_7300B_Config error=%d\n", (unsigned int)v5);
Release_Card((unsigned __int16)card);
exit(1);
}
return -10;
}

original_code:
int main(void)
{
    I16 err;
    U32 i;
    U16 BufferId;
    setbuf( stdout, ((void *)0) );
    printf("\033[H\033[J");
    printf(" ========================================================================\n");
    printf(" ==           7300 SAMPLE : PCI-7300 Multiple Buffered DMA             ==\n");
    printf(" ========================================================================\n\n\n");
    printf(" The output data is a sine wave and store data to file '%s'. It will not stop until you press a key.\n\nPress any key to start the operation.\n", file_name );
    getch();
    if ((card=Register_Card(15, card_number)) < 0) {
        printf("Register_Card error=%d\n", card);
        exit(1);
    }
    if( (fp = fopen( file_name, "w+b" ) ) == ((void *)0) )
        return -10;
    for (i=0; i<100000; i++) {
        in_buf[i] = (U16)(0);
        in_buf2[i] = (U16)(0);
    }
    err=DI_7300B_Config(card, 16, 4, 0, 1, 0, 1, 1);
    if (err !=0) {
        printf("DI_7300B_Config error=%d\n", err);
        Release_Card( card );
        exit(1);
    }
    DI_EventCallBack (card, 1, 1, signal_handler);
    DI_EventCallBack (card, 1, 0, signal_handler2);
    err = DI_ContMultiBufferSetup (card, in_buf, data_size, &BufferId);
    if (err < 0) {
        printf("DI_ContMultiBufferSetup Error=%d\n", err);
        Release_Card( card );
        exit(1);
    }
    err = DI_ContMultiBufferSetup (card, in_buf2, data_size, &BufferId);
    if (err < 0) {
        printf("DI_ContMultiBufferSetup Error=%d\n", err);
        Release_Card( card );
        exit(1);
    }
    err = DI_ContMultiBufferStart (card, 0, 1);
    if (err < 0) {
        printf("DI_ContMultiBufferStart error=%d", err);
        DO_AsyncClear(card, &i);
        Release_Card( card );
        exit(1);
    }
    printf("\n\nPress any key to stop input operation.");
    printf("\n\nData count : \n");
    getch();
    err = DI_AsyncClear(card, &count);
    if( err != 0 ){
        printf("D2K_AI_AsyncClear Failed !!!, Ready to system hang !!!\n" );
        getch();
    }
    DI_EventCallBack(card, 0, 1, ((void *)0));
    DI_EventCallBack(card, 0, 0, ((void *)0));
    Release_Card(card);
    fclose(fp);
    exit(1);
}

canonical_original_code:
int main()
{
    short err;
    unsigned long i;
    unsigned short BufferId;
    setbuf( stdout, ((void *)0) );
    printf("\033[H\033[J");
    printf(" ========================================================================\n");
    printf(" ==           7300 SAMPLE : PCI-7300 Multiple Buffered DMA             ==\n");
    printf(" ========================================================================\n\n\n");
    printf(" The output data is a sine wave and store data to file '%s'. It will not stop until you press a key.\n\nPress any key to start the operation.\n", file_name );
    getch();
    if ((card=Register_Card(15, card_number)) < 0) {
        printf("Register_Card error=%d\n", card);
        exit(1);
    }
    if( (fp = fopen( file_name, "w+b" ) ) == ((void *)0) )
        return -10;
    for (i=0; i<100000; i++) {
        in_buf[i] = (U16)(0);
        in_buf2[i] = (U16)(0);
    }
    err=DI_7300B_Config(card, 16, 4, 0, 1, 0, 1, 1);
    if (err !=0) {
        printf("DI_7300B_Config error=%d\n", err);
        Release_Card( card );
        exit(1);
    }
    DI_EventCallBack (card, 1, 1, signal_handler);
    DI_EventCallBack (card, 1, 0, signal_handler2);
    err = DI_ContMultiBufferSetup (card, in_buf, data_size, &BufferId);
    if (err < 0) {
        printf("DI_ContMultiBufferSetup Error=%d\n", err);
        Release_Card( card );
        exit(1);
    }
    err = DI_ContMultiBufferSetup (card, in_buf2, data_size, &BufferId);
    if (err < 0) {
        printf("DI_ContMultiBufferSetup Error=%d\n", err);
        Release_Card( card );
        exit(1);
    }
    err = DI_ContMultiBufferStart (card, 0, 1);
    if (err < 0) {
        printf("DI_ContMultiBufferStart error=%d", err);
        DO_AsyncClear(card, &i);
        Release_Card( card );
        exit(1);
    }
    printf("\n\nPress any key to stop input operation.");
    printf("\n\nData count : \n");
    getch();
    err = DI_AsyncClear(card, &count);
    if( err != 0 ){
        printf("D2K_AI_AsyncClear Failed !!!, Ready to system hang !!!\n" );
        getch();
    }
    DI_EventCallBack(card, 0, 1, ((void *)0));
    DI_EventCallBack(card, 0, 0, ((void *)0));
    Release_Card(card);
    fclose(fp);
    exit(1);
}

variable_types: err short

variable_types:
i
unsigned long

variable_types:
BufferId
unsigned short


decompiled_code:
__int64 __fastcall write_to_file(const void *a1)
{
fwrite(a1, 2uLL, data_size, fp);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1)
{
fwrite(a1, 2uLL, data_size, fp);
return 1LL;
}

original_code:
BOOLEAN write_to_file(U16 *buf)
{
    fwrite(buf, sizeof(U16), data_size, fp);
    return TRUE;
}

canonical_original_code:
enum BOOLEAN write_to_file(unsigned short *buf)
{
    fwrite(buf, sizeof(U16), data_size, fp);
    return TRUE;
}

variable_types:
buf
unsigned short *

return_type: enum BOOLEAN { FALSE=0, TRUE=1 }


decompiled_code:
int signal_handler()
{
__int16 v0; // ax
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
DI_AsyncMultiBufferNextReady((unsigned __int16)card, v2, &viewidx[j % 0x2710uLL]);
v0 = viewidx[j % 0x2710uLL];
if ( v0 )
{
if ( v0 == 1 )
write_to_file(in_buf2);
}
else
{
write_to_file(in_buf);
}
DI_AsyncDblBufferTransfer((unsigned __int16)card, 0LL);
DI_AsyncDblBufferOverrun((unsigned __int16)card, 0LL, &sts);
if ( sts == 1 )
{
++t;
DI_AsyncDblBufferOverrun((unsigned __int16)card, 1LL, &sts);
}
result = printf("\roverrun:%d cb:%d", t, j);
++j;
return result;
}

canonical_decompiled_code:
int func2()
{
__int16 v0; // ax
int result; // eax
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
DI_AsyncMultiBufferNextReady((unsigned __int16)card, v2, &viewidx[j % 0x2710uLL]);
v0 = viewidx[j % 0x2710uLL];
if ( v0 )
{
if ( v0 == 1 )
func1(in_buf2);
}
else
{
func1(in_buf);
}
DI_AsyncDblBufferTransfer((unsigned __int16)card, 0LL);
DI_AsyncDblBufferOverrun((unsigned __int16)card, 0LL, &sts);
if ( sts == 1 )
{
++t;
DI_AsyncDblBufferOverrun((unsigned __int16)card, 1LL, &sts);
}
result = printf("\roverrun:%d cb:%d", t, j);
++j;
return result;
}

original_code:
void signal_handler(int sig_no)
{
    BOOLEAN HalfReady;
    HalfReady=0;
    DI_AsyncMultiBufferNextReady(card, &HalfReady, &viewidx[j%10000]);
    switch(viewidx[j%10000]) {
        case 0:
            write_to_file( in_buf );
            break;
        case 1:
            write_to_file( in_buf2 );
            break;
    }
    DI_AsyncDblBufferTransfer(card, ((void *)0));
    DI_AsyncDblBufferOverrun(card, 0, &sts);
    if(sts==1) {
        t++;
        DI_AsyncDblBufferOverrun(card, 1, &sts);
    }
    printf("\roverrun:%d cb:%d", t, j);
    j++;
}

canonical_original_code:
void signal_handler(int sig_no)
{
    enum BOOLEAN HalfReady;
    HalfReady=0;
    DI_AsyncMultiBufferNextReady(card, &HalfReady, &viewidx[j%10000]);
    switch(viewidx[j%10000]) {
        case 0:
            write_to_file( in_buf );
            break;
        case 1:
            write_to_file( in_buf2 );
            break;
    }
    DI_AsyncDblBufferTransfer(card, ((void *)0));
    DI_AsyncDblBufferOverrun(card, 0, &sts);
    if(sts==1) {
        t++;
        DI_AsyncDblBufferOverrun(card, 1, &sts);
    }
    printf("\roverrun:%d cb:%d", t, j);
    j++;
}

variable_types:
HalfReady
enum BOOLEAN { FALSE=0, TRUE=1 }


lowerCase

decompiled_code:
char *__fastcall lowerCase(char *a1)
{
char v1; // bl
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( *a1 )
{
v2 = _ctype_tolower_loc();
v3 = a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( *v3 );
}
return a1;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
char v1; // bl
const __int32_t **v2; // rcx
char *v3; // rax

v1 = *a1;
if ( *a1 )
{
v2 = _ctype_tolower_loc();
v3 = a1;
do
{
*v3++ = (*v2)[v1];
v1 = *v3;
}
while ( *v3 );
}
return a1;
}

original_code:
char* lowerCase(char *palavra)
{
 int i;
 for (i = 0; palavra[i] != '\0'; i++)
  palavra[i] = tolower(palavra[i]);
 return palavra;
}

canonical_original_code:
char *lowerCase(char *palavra)
{
 int i;
 for (i = 0; palavra[i] != '\0'; i++)
  palavra[i] = tolower(palavra[i]);
 return palavra;
}

variable_types:
palavra
char *

variable_types: i int


comparaString

decompiled_code:
int __fastcall comparaString(const char **a1, const char **a2)
{
const char *v2; // r13
size_t v3; // rax
char *v4; // rbx
const char *v5; // r12
size_t v6; // rax
char *v7; // rbp
char *v8; // rbp
char *v9; // rax

v2 = *a1;
v3 = strlen(*a1);
v4 = (char *)malloc(8 * v3 + 8);
v5 = *a2;
v6 = strlen(*a2);
v7 = (char *)malloc(8 * v6 + 8);
strcpy(v4, v2);
strcpy(v7, v5);
v8 = lowerCase(v7);
v9 = lowerCase(v4);
return strcmp(v9, v8);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char **a2)
{
const char *v2; // r13
size_t v3; // rax
char *v4; // rbx
const char *v5; // r12
size_t v6; // rax
char *v7; // rbp
char *v8; // rbp
char *v9; // rax

v2 = *a1;
v3 = strlen(*a1);
v4 = (char *)malloc(8 * v3 + 8);
v5 = *a2;
v6 = strlen(*a2);
v7 = (char *)malloc(8 * v6 + 8);
strcpy(v4, v2);
strcpy(v7, v5);
v8 = func0(v7);
v9 = func0(v4);
return strcmp(v9, v8);
}

original_code:
int comparaString(const void *stringA, const void *stringB)
{
 char *A = malloc((strlen(*(char**)stringA)+1) * sizeof(char*));
 char *B = malloc((strlen(*(char**)stringB)+1) * sizeof(char*));
 strcpy(A, *(char**)stringA);
 strcpy(B, *(char**)stringB);
 return strcmp(lowerCase(A), lowerCase(B));
}

canonical_original_code:
int comparaString(void *stringA, void *stringB)
{
 char *A = malloc((strlen(*(char**)stringA)+1) * sizeof(char*));
 char *B = malloc((strlen(*(char**)stringB)+1) * sizeof(char*));
 strcpy(A, *(char **)stringA);
 strcpy(B, *(char **)stringB);
 return strcmp(lowerCase(A), lowerCase(B));
}

variable_types:
stringA
void *

variable_types:
stringB
void *

variable_types:
A
char *

variable_types:
B
char *


hashOption

decompiled_code:
__int64 __fastcall hashOption(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // edx

v1 = *a1;
if ( !*a1 )
return 1;
v2 = a1 + 1;
v3 = 1;
do
{
switch ( v1 )
{
case '-':
v3 *= 2;
break;
case 'F':
v3 *= 13;
break;
case 'L':
v3 *= 29;
break;
case 'V':
v3 *= 11;
break;
case 'a':
v3 *= 5;
break;
case 'd':
v3 *= 19;
break;
case 'e':
v3 *= 3;
break;
case 'l':
v3 *= 23;
break;
case 's':
v3 *= 31;
break;
case 't':
v3 *= 17;
break;
case 'v':
v3 *= 7;
break;
default:
v3 = 0;
break;
}
v1 = *v2++;
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // edx

v1 = *a1;
if ( !*a1 )
return 1;
v2 = a1 + 1;
v3 = 1;
do
{
switch ( v1 )
{
case '-':
v3 *= 2;
break;
case 'F':
v3 *= 13;
break;
case 'L':
v3 *= 29;
break;
case 'V':
v3 *= 11;
break;
case 'a':
v3 *= 5;
break;
case 'd':
v3 *= 19;
break;
case 'e':
v3 *= 3;
break;
case 'l':
v3 *= 23;
break;
case 's':
v3 *= 31;
break;
case 't':
v3 *= 17;
break;
case 'v':
v3 *= 7;
break;
default:
v3 = 0;
break;
}
v1 = *v2++;
}
while ( v1 );
return v3;
}

original_code:
int hashOption(char *opcao)
{
 int i = 0, codigo = 1;
 char c = opcao[i];
 while (c != '\0')
 {
  switch(c)
  {
   case '-': codigo *= 2; break;
   case 'e': codigo *= 3; break;
   case 'a': codigo *= 5; break;
   case 'v': codigo *= 7; break;
   case 'V': codigo *= 11; break;
   case 'F': codigo *= 13; break;
   case 't': codigo *= 17; break;
   case 'd': codigo *= 19; break;
   case 'l': codigo *= 23; break;
   case 'L': codigo *= 29; break;
   case 's': codigo *= 31; break;
   default: codigo = 0; break;
  }
  c = opcao[++i];
 }
 return codigo;
}

canonical_original_code:
int hashOption(char *opcao)
{
 int i = 0; int codigo = 1;
 char c = opcao[i];
 while (c != '\0')
 {
  switch(c)
  {
   case '-': codigo *= 2; break;
   case 'e': codigo *= 3; break;
   case 'a': codigo *= 5; break;
   case 'v': codigo *= 7; break;
   case 'V': codigo *= 11; break;
   case 'F': codigo *= 13; break;
   case 't': codigo *= 17; break;
   case 'd': codigo *= 19; break;
   case 'l': codigo *= 23; break;
   case 'L': codigo *= 29; break;
   case 's': codigo *= 31; break;
   default: codigo = 0; break;
  }
  c = opcao[++i];
 }
 return codigo;
}

variable_types:
opcao
char *

variable_types: codigo int

variable_types: c char


hash

decompiled_code:
__int64 __fastcall hash(char *a1, int a2)
{
char v2; // cl
unsigned int v3; // edx

v2 = *a1;
if ( !*a1 )
return 0;
v3 = 0;
do
{
v3 = (int)(v2 + 127 * v3) % a2;
v2 = *++a1;
}
while ( *a1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2)
{
char v2; // cl
unsigned int v3; // edx

v2 = *a1;
if ( !*a1 )
return 0;
v3 = 0;
do
{
v3 = (int)(v2 + 127 * v3) % a2;
v2 = *++a1;
}
while ( *a1 );
return v3;
}

original_code:
int hash(char *palavra, int tableSize)
{
 int h = 0, a = 127;
 while (*palavra != '\0')
 {
  h = (a * h + *palavra)%tableSize;
  palavra++;
 }
 return h;
}

canonical_original_code:
int hash(char *palavra, int tableSize)
{
 int h = 0; int a = 127;
 while (*palavra != '\0')
 {
  h = (a * h + *palavra)%tableSize;
  palavra++;
 }
 return h;
}

variable_types: tableSize int

variable_types: h int

variable_types: a int


initSentence

decompiled_code:
void *__fastcall initSentence(int a1)
{
void *result; // rax

result = malloc(24LL * a1);
sentences = (__int64)result;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1)
{
void *result; // rax

result = malloc(24LL * a1);
sentences = (__int64)result;
return result;
}

original_code:
void initSentence(int slots)
{
 sentences = malloc(slots * sizeof(Sentenca));
}

variable_types: slots int


insertVal

original_code:
static Valor* insertVal(Valor *ini, Valor *novo)
{
 Valor *p;
 if (ini == ((void *)0))
  return ini = novo;
 p = ini->ant;
 p->prox = novo;
 ini->ant = novo;
 novo->prox = ini;
 novo->ant = p;
 return ini;
}

canonical_original_code:
static struct valor *insertVal(struct valor *ini, struct valor *novo)
{
 struct valor *p;
 if (ini == ((void *)0))
  return ini = novo;
 p = ini->ant;
 p->prox = novo;
 ini->ant = novo;
 novo->prox = ini;
 novo->ant = p;
 return ini;
}

variable_types:
ini
struct valor *

variable_types:
novo
struct valor *

variable_types: struct valor { char *palavra; char *lema; int sentenca; struct valor *ant; struct valor *prox; } *


original_code:
void ST_t2_insert(Valor *val)
{
 int i;
 Node *p;
 if (N > M-1)
  remapeiaTabela();
 i = hash(val->lema, M);
 p = t2enc_head[i];
 while (p != ((void *)0) && p->valor != ((void *)0))
 {
  if (strcmp(p->valor->lema, val->lema) == 0)
  {
   p->valor = insertVal(p->valor, val);
   break;
  }
  p = p->prox;
 }
 if (p == ((void *)0))
 {
  t2enc_head[i] = newNode(val, t2enc_head[i]);
  if (((*__ctype_b_loc ())[(int) ((val->lema[0]))] & (unsigned short int) _ISalpha))
   L++;
 }
 N++;
}

canonical_original_code:
void ST_t2_insert(struct valor *val)
{
 int i;
 struct node *p;
 if (N > M-1)
  remapeiaTabela();
 i = hash(val->lema, M);
 p = t2enc_head[i];
 while (p != ((void *)0) && p->valor != ((void *)0))
 {
  if (strcmp(p->valor->lema, val->lema) == 0)
  {
   p->valor = insertVal(p->valor, val);
   break;
  }
  p = p->prox;
 }
 if (p == ((void *)0))
 {
  t2enc_head[i] = newNode(val, t2enc_head[i]);
  if (((*__ctype_b_loc ())[(int) ((val->lema[0]))] & (unsigned short) _ISalpha))
   L++;
 }
 N++;
}

variable_types: struct node { struct valor { char *palavra; char *lema; int sentenca; struct valor *ant; struct valor *prox; } *valor; struct node *prox; } *

user_defined_types: struct node { struct valor *valor; struct node *prox; }


decompiled_code:
__int64 __fastcall ST_t2_search(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
__int64 v3; // rbp
int v4; // eax

v1 = a1;
v2 = ST_t1_search();
if ( v2 )
{
v1 = *(const char **)(v2 + 8);
v3 = t2enc_head;
v4 = hash(v1, (unsigned int)M);
}
else
{
v3 = t2enc_head;
v4 = hash(a1, (unsigned int)M);
}
return searchRec(*(__int64 **)(v3 + 8LL * v4), v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
const char *v1; // rbx
__int64 v2; // rax
__int64 v3; // rbp
int v4; // eax

v1 = a1;
v2 = ST_t1_search();
if ( v2 )
{
v1 = *(const char **)(v2 + 8);
v3 = t2enc_head;
v4 = hash(v1, (unsigned int)M);
}
else
{
v3 = t2enc_head;
v4 = hash(a1, (unsigned int)M);
}
return func1(*(__int64 **)(v3 + 8LL * v4), v1);
}

original_code:
Valor* ST_t2_search(char *chave)
{
 Valor *temp = ST_t1_search(chave);
 if (temp != ((void *)0))
  return searchRec(t2enc_head[hash(temp->lema, M)], temp->lema);
 return searchRec(t2enc_head[hash(chave, M)], chave);
}

canonical_original_code:
struct valor *ST_t2_search(char *chave)
{
 struct valor *temp = ST_t1_search(chave);
 if (temp != ((void *)0))
  return searchRec(t2enc_head[hash(temp->lema, M)], temp->lema);
 return searchRec(t2enc_head[hash(chave, M)], chave);
}

variable_types:
chave
char *

return_type: struct valor { char *palavra; char *lema; int sentenca; struct valor *ant; struct valor *prox; } *


decompiled_code:
void *ST_t2_init()
{
void *result; // rax

N = 0;
M = 193;
result = malloc(0xC10uLL);
t2enc_head = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func6()
{
void *result; // rax

N = 0;
M = 193;
result = malloc(0xC10uLL);
t2enc_head = (__int64)result;
return result;
}

original_code:
void ST_t2_init()
{
 N = 0;
 M = 193;
 t2enc_head = malloc(M * sizeof(Node));
}


decompiled_code:
void __fastcall ST_t2_list(int a1)
{
void *v2; // rbp
__int64 v3; // r12
__int64 v4; // rbx
_QWORD *v5; // rdi
__int64 v6; // rbx
__int64 v7; // rbx
const char *v8; // r12
__int64 v9; // r13
int v10; // eax
__int64 v11; // rax

cnt = 0;
v2 = malloc(8LL * N);
if ( M > 0 )
{
v3 = 8LL * (unsigned int)M;
v4 = 0LL;
do
{
v5 = *(_QWORD **)(t2enc_head + v4);
if ( v5 )
listRec(v5, (__int64)v2);
v4 += 8LL;
}
while ( v4 != v3 );
}
qsort(v2, cnt, 8uLL, (__compar_fn_t)&comparaString);
if ( a1 == 1 )
{
if ( cnt > 0 )
{
v7 = 0LL;
do
{
printf("%s ", *((const char **)v2 + v7));
v8 = (const char *)*((_QWORD *)v2 + v7);
v9 = t2enc_head;
v10 = hash(v8, (unsigned int)M);
v11 = searchRec(*(__int64 **)(v9 + 8LL * v10), v8);
printValor(v11, 0LL, 3LL);
++v7;
}
while ( cnt > (int)v7 );
}
}
else if ( !a1 && cnt > 0 )
{
v6 = 0LL;
do
puts(*((const char **)v2 + v6++));
while ( cnt > (int)v6 );
}
putchar(10);
free(v2);
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
void *v2; // rbp
__int64 v3; // r12
__int64 v4; // rbx
_QWORD *v5; // rdi
__int64 v6; // rbx
__int64 v7; // rbx
const char *v8; // r12
__int64 v9; // r13
int v10; // eax
__int64 v11; // rax

cnt = 0;
v2 = malloc(8LL * N);
if ( M > 0 )
{
v3 = 8LL * (unsigned int)M;
v4 = 0LL;
do
{
v5 = *(_QWORD **)(t2enc_head + v4);
if ( v5 )
func2(v5, (__int64)v2);
v4 += 8LL;
}
while ( v4 != v3 );
}
qsort(v2, cnt, 8uLL, (__compar_fn_t)&comparaString);
if ( a1 == 1 )
{
if ( cnt > 0 )
{
v7 = 0LL;
do
{
printf("%s ", *((const char **)v2 + v7));
v8 = (const char *)*((_QWORD *)v2 + v7);
v9 = t2enc_head;
v10 = hash(v8, (unsigned int)M);
v11 = func1(*(__int64 **)(v9 + 8LL * v10), v8);
printValor(v11, 0LL, 3LL);
++v7;
}
while ( cnt > (int)v7 );
}
}
else if ( !a1 && cnt > 0 )
{
v6 = 0LL;
do
puts(*((const char **)v2 + v6++));
while ( cnt > (int)v6 );
}
putchar(10);
free(v2);
}

original_code:
void ST_t2_list(int modo)
{
 char **tokens;
 int i;
 cnt = 0;
 tokens = malloc(N * sizeof(char*));
 for (i = 0; i < M; i++)
 {
  if(t2enc_head[i] != ((void *)0))
   listRec(t2enc_head[i], tokens);
 }
 qsort(tokens, cnt, sizeof(tokens[0]), comparaString);
 if (modo == 1)
 {
  for (i = 0; i < cnt; i++)
  {
   printf("%s ", tokens[i]);
   printValor(searchRec(t2enc_head[hash(tokens[i], M)], tokens[i]), ((void *)0), 3);
  }
 }
 else if (modo == 0)
 {
  for (i = 0; i < cnt; i++)
   printf("%s\n", tokens[i]);
 }
 printf("\n");
 free(tokens);
}

canonical_original_code:
void ST_t2_list(int modo)
{
 char **tokens;
 int i;
 cnt = 0;
 tokens = malloc(N * sizeof(char *));
 for (i = 0; i < M; i++)
 {
  if(t2enc_head[i] != ((void *)0))
   listRec(t2enc_head[i], tokens);
 }
 qsort(tokens, cnt, sizeof(tokens[0]), comparaString);
 if (modo == 1)
 {
  for (i = 0; i < cnt; i++)
  {
   printf("%s ", tokens[i]);
   printValor(searchRec(t2enc_head[hash(tokens[i], M)], tokens[i]), ((void *)0), 3);
  }
 }
 else if (modo == 0)
 {
  for (i = 0; i < cnt; i++)
   printf("%s\n", tokens[i]);
 }
 printf("\n");
 free(tokens);
}

variable_types: modo int

variable_types:
tokens
char **

variable_types: i int


decompiled_code:
__int64 ST_t2_count()
{
return (unsigned int)L;
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)L;
}

original_code:
int ST_t2_count()
{
 return L;
}

canonical_original_code:
int ST_t2_count()
{
 return L;
}


user_defined_types: struct valor { char *palavra; char *lema; int sentenca; struct valor *ant; struct valor *prox; }