decompiled_code:
__int64 __fastcall random_syll(_BYTE *a1)
{
int v1; // eax

logger_log(0LL, "tools.c:25", "Entering %s", "random_syll");
*a1 = con_1[rand() % 0x14uLL];
a1[1] = vow_0[rand() & 3];
v1 = rand();
a1[3] = 0;
a1[2] = con_1[v1 % 0x14uLL];
return logger_log(0LL, "tools.c:36", "Leaving %s", "random_syll");
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax

logger_log(0LL, "tools.c:25", "Entering %s", "random_syll");
*a1 = con_1[rand() % 0x14uLL];
a1[1] = vow_0[rand() & 3];
v1 = rand();
a1[3] = 0;
a1[2] = con_1[v1 % 0x14uLL];
return logger_log(0LL, "tools.c:36", "Leaving %s", "random_syll");
}

original_code:
static void random_syll(char *syll)
{
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "25", "Entering %s", __func__);;
    static char con[] = "bcdfghjklmnpqrstvwxyz";
    static char vow[] = "aeiou";
    syll[0] = con[rand() % (sizeof(con) - 2)];
    syll[1] = vow[rand() % (sizeof(vow) - 2)];
    syll[2] = con[rand() % (sizeof(con) - 2)];
    syll[3] = '\0';
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "36", "Leaving %s", __func__);;
}

variable_types:
syll
char *

variable_types:
con
char []

variable_types:
vow
char []


repo: bmoscon/Rogue

decompiled_code:
__int64 __fastcall random_int(unsigned int a1, int a2)
{
unsigned int v2; // er12

v2 = a1;
logger_log(0LL, "tools.c:42", "Entering %s", "random_int");
if ( a1 != a2 )
{
logger_log(0LL, "tools.c:48", "Leaving %s", "random_int");
v2 = rand() % (int)(a2 - a1) + a1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
unsigned int v2; // er12

v2 = a1;
logger_log(0LL, "tools.c:42", "Entering %s", "random_int");
if ( a1 != a2 )
{
logger_log(0LL, "tools.c:48", "Leaving %s", "random_int");
v2 = rand() % (int)(a2 - a1) + a1;
}
return v2;
}

original_code:
int random_int(int min, int max)
{
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "42", "Entering %s", __func__);;
    if (min == max) {
 return (min);
    }
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "48", "Leaving %s", __func__);;
    return ((rand() % (max - min)) + min);
}

variable_types: min int

variable_types: max int

return_type: int


decompiled_code:
__int64 __fastcall random_shuffle(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // eax
int v4; // ecx
_DWORD *v5; // rax

logger_log(0LL, "tools.c:56", "Entering %s", "random_shuffle");
if ( a2 != 2 )
{
v2 = a2 - 1;
do
{
v3 = rand();
v4 = *(_DWORD *)(a1 + 4 * v2);
v5 = (_DWORD *)(a1 + 4LL * (v3 % (int)v2));
*(_DWORD *)(a1 + 4 * v2--) = *v5;
*v5 = v4;
}
while ( (_DWORD)v2 != 1 );
}
return logger_log(0LL, "tools.c:69", "Leaving %s", "random_shuffle");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // eax
int v4; // ecx
_DWORD *v5; // rax

logger_log(0LL, "tools.c:56", "Entering %s", "random_shuffle");
if ( a2 != 2 )
{
v2 = a2 - 1;
do
{
v3 = rand();
v4 = *(_DWORD *)(a1 + 4 * v2);
v5 = (_DWORD *)(a1 + 4LL * (v3 % (int)v2));
*(_DWORD *)(a1 + 4 * v2--) = *v5;
*v5 = v4;
}
while ( (_DWORD)v2 != 1 );
}
return logger_log(0LL, "tools.c:69", "Leaving %s", "random_shuffle");
}

original_code:
void random_shuffle(int *array, int upper)
{
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "56", "Entering %s", __func__);;
    int i;
    int j;
    int t;
    for (i = upper - 1; i != 1; --i) {
 j = rand() % i;
 t = array[i];
 array[i] = array[j];
 array[j] = t;
    }
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "69", "Leaving %s", __func__);;
}

variable_types:
array
int *

variable_types: upper int

variable_types: i int

variable_types: j int

variable_types: t int

return_type: void


decompiled_code:
__int64 __fastcall random_string(__int64 a1, size_t a2)
{
unsigned int v2; // ebx
char v4[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = 0;
logger_log(0LL, "tools.c:75", "Entering %s", "random_string");
while ( v2 < a2 )
{
random_syll(v4);
v2 += snprintf((char *)(a1 + v2), a2, "%s", v4);
if ( (unsigned int)(-1431655765 * rand() + 715827882) <= 0x55555554 )
v2 += snprintf((char *)(a1 + v2), a2, "%s", " ");
}
*(_BYTE *)(a1 + a2) = 0;
return logger_log(0LL, "tools.c:93", "Leaving %s", "random_string");
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, size_t a2)
{
unsigned int v2; // ebx
char v4[44]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = 0;
logger_log(0LL, "tools.c:75", "Entering %s", "random_string");
while ( v2 < a2 )
{
func0(v4);
v2 += snprintf((char *)(a1 + v2), a2, "%s", v4);
if ( (unsigned int)(-1431655765 * rand() + 715827882) <= 0x55555554 )
v2 += snprintf((char *)(a1 + v2), a2, "%s", " ");
}
*(_BYTE *)(a1 + a2) = 0;
return logger_log(0LL, "tools.c:93", "Leaving %s", "random_string");
}

original_code:
void random_string(char *str, size_t len)
{
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "75", "Entering %s", __func__);;
    uint32_t i = 0;
    char syll[4];
    while (i < len) {
 random_syll(syll);
 i += snprintf(&str[i], len, "%s", syll);
 if (!(rand() % 3)) {
     i += snprintf(&str[i], len, "%s", " ");
 }
    }
    str[len] = '\0';
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "93", "Leaving %s", __func__);;
}

canonical_original_code:
void random_string(char *str, unsigned long len)
{
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "75", "Entering %s", __func__);;
    unsigned int i = 0;
    char syll[4];
    while (i < len) {
 random_syll(syll);
 i += snprintf(&str[i], len, "%s", syll);
 if (!(rand() % 3)) {
     i += snprintf(&str[i], len, "%s", " ");
 }
    }
    str[len] = '\0';
    logger_log(LOGGER_LEVEL_VERBOSE, "tools.c" ":" "93", "Leaving %s", __func__);;
}

variable_types:
str
char *

variable_types:
len
unsigned long

variable_types:
i
unsigned int

variable_types:
syll
char [4]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax

setlocale(6, &locale);
v3 = time(0LL);
srand(v3);
initscr();
start_color();
init_pair(1, 3, 0);
init_pair(2, 2, 0);
v4 = generate_rooms();
if ( *(int *)(v4 + 8) > 0 )
{
v5 = 0LL;
do
{
v6 = v5++;
draw_room(*(_DWORD *)(*(_QWORD *)(v4 + 16) + (v6 << 6)));
}
while ( *(_DWORD *)(v4 + 8) > (int)v5 );
}
wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
endwin();
free(*(void **)(v4 + 16));
free((void *)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax

setlocale(6, &locale);
v3 = time(0LL);
srand(v3);
initscr();
start_color();
init_pair(1, 3, 0);
init_pair(2, 2, 0);
v4 = func7();
if ( *(int *)(v4 + 8) > 0 )
{
v5 = 0LL;
do
{
v6 = v5++;
func11(*(_DWORD *)(*(_QWORD *)(v4 + 16) + (v6 << 6)));
}
while ( *(_DWORD *)(v4 + 8) > (int)v5 );
}
wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
endwin();
free(*(void **)(v4 + 16));
free((void *)v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    setlocale(6, "");
    srand(time(((void *)0)));
    initscr();
    start_color();
    init_pair(1, 3, 0);
    init_pair(2, 2, 0);
    map_st *m = generate_rooms();
    for (int i = 0; i < m->num_rooms; ++i) {
 draw_room(m->rooms[i].pos.x, m->rooms[i].pos.y, m->rooms[i].y_len, m->rooms[i].x_len);
    }
    wgetch(stdscr);
    endwin();
    free(m->rooms);
    free(m);
    return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    setlocale(6, "");
    srand(time(((void *)0)));
    initscr();
    start_color();
    init_pair(1, 3, 0);
    init_pair(2, 2, 0);
    struct map_t *m = generate_rooms();
    for (int i = 0; i < m->num_rooms; ++i) {
 draw_room(m->rooms[i].pos.x, m->rooms[i].pos.y, m->rooms[i].y_len, m->rooms[i].x_len);
    }
    wgetch(stdscr);
    endwin();
    free(m->rooms);
    free(m);
    return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct map_t { struct coord_st { int x; int y; } stairs; int num_rooms; int num_tunnels; struct room_t { struct coord_st pos; int x_len; int y_len; struct door_t { struct coord_st pos; _Bool hidden; } doors[4]; } *rooms; struct tunnel_st { int len; struct coord_st pos; } *tunnels; } *

user_defined_types: struct map_t { struct coord_st stairs; int num_rooms; int num_tunnels; struct room_t *rooms; struct tunnel_st *tunnels; }

user_defined_types: struct room_t { struct coord_st pos; int x_len; int y_len; struct door_t doors[4]; }


original_code:
map_st* generate_rooms()
{
    int room_height_max;
    int room_width_max;
    int i;
    map_st *m = malloc(sizeof(map_st));
    if (!m) {
 return (((void *)0));
    }
    m->num_rooms = (rand() % (9 - 3)) + 3;
    m->rooms = (room_st *)malloc(sizeof(room_st) * m->num_rooms);
    if (!m->rooms) {
 free(m);
 return (((void *)0));
    }
    room_width_max = (80 / 3);
    if (m->num_rooms == 3) {
 room_height_max = 24 - 2;
    } else if (m->num_rooms <= 6) {
 room_height_max = 11;
    } else {
 room_height_max = 7;
    }
    for (i = 0; i < m->num_rooms; ++i) {
 int startx;
 int starty;
 m->rooms[i].y_len = (rand() % (room_height_max - 4)) + 4;
 m->rooms[i].x_len = (rand() % (room_width_max - 4)) + 4;
 startx = (80 / 3) * (i % 3);
 starty = room_height_max * (i / 3);
 startx += (rand() % (room_width_max - m->rooms[i].x_len));
 starty += (rand() % (room_height_max - m->rooms[i].y_len));
 m->rooms[i].pos.x = startx;
 m->rooms[i].pos.y = starty;
    }
    return (m);
}

canonical_original_code:
struct map_t *generate_rooms()
{
    int room_height_max;
    int room_width_max;
    int i;
    struct map_t *m = malloc(sizeof(map_st));
    if (!m) {
 return (((void *)0));
    }
    m->num_rooms = (rand() % (9 - 3)) + 3;
    m->rooms = (struct room_t *)malloc(sizeof(room_st) * m->num_rooms);
    if (!m->rooms) {
 free(m);
 return (((void *)0));
    }
    room_width_max = (80 / 3);
    if (m->num_rooms == 3) {
 room_height_max = 24 - 2;
    } else if (m->num_rooms <= 6) {
 room_height_max = 11;
    } else {
 room_height_max = 7;
    }
    for (i = 0; i < m->num_rooms; ++i) {
 int startx;
 int starty;
 m->rooms[i].y_len = (rand() % (room_height_max - 4)) + 4;
 m->rooms[i].x_len = (rand() % (room_width_max - 4)) + 4;
 startx = (80 / 3) * (i % 3);
 starty = room_height_max * (i / 3);
 startx += (rand() % (room_width_max - m->rooms[i].x_len));
 starty += (rand() % (room_height_max - m->rooms[i].y_len));
 m->rooms[i].pos.x = startx;
 m->rooms[i].pos.y = starty;
    }
    return (m);
}

variable_types: startx int

variable_types: starty int

return_type: struct map_t { struct coord_st { int x; int y; } stairs; int num_rooms; int num_tunnels; struct room_t { struct coord_st pos; int x_len; int y_len; struct door_t { struct coord_st pos; _Bool hidden; } doors[4]; } *rooms; struct tunnel_st { int len; struct coord_st pos; } *tunnels; } *


decompiled_code:
int __fastcall vert_line(int a1, int a2, int a3)
{
int v3; // ebp
int v4; // ebx
int v5; // esi
int result; // eax

if ( a3 > 0 )
{
v3 = a3 + a2;
v4 = a2;
do
{
v5 = v4++;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v5, a1);
result = waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402004, -1);
}
while ( v4 != v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2, int a3)
{
int v3; // ebp
int v4; // ebx
int v5; // esi
int result; // eax

if ( a3 > 0 )
{
v3 = a3 + a2;
v4 = a2;
do
{
v5 = v4++;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v5, a1);
result = waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402004, -1);
}
while ( v4 != v3 );
}
return result;
}

original_code:
static void vert_line(int x, int y, int len)
{
    int i;
    for (i = 0; i < len; ++i) {
 wmove(stdscr,(y+i),(x));
 waddnstr(stdscr,("\u2551"),-1);
    }
}

variable_types: x int

variable_types: y int

variable_types: len int


decompiled_code:
int __fastcall horiz_line(int a1, int a2, int a3)
{
int result; // eax
int v5; // ebx

result = wmove(stdscr__NCURSES6_TINFO_5_0_19991023, a2, a1);
if ( a3 > 0 )
{
v5 = 0;
do
{
++v5;
result = waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402008, -1);
}
while ( a3 != v5 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, int a3)
{
int result; // eax
int v5; // ebx

result = wmove(stdscr__NCURSES6_TINFO_5_0_19991023, a2, a1);
if ( a3 > 0 )
{
v5 = 0;
do
{
++v5;
result = waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402008, -1);
}
while ( a3 != v5 );
}
return result;
}

original_code:
static void horiz_line(int x, int y, int len)
{
    int i;
    wmove(stdscr,(y),(x));
    for(i = 0; i < len; ++i) {
 waddnstr(stdscr,("\u2550"),-1);
    }
}


decompiled_code:
int __fastcall draw_box(int a1, int a2, int a3, int a4)
{
int v5; // er15
int v7; // edx
int v8; // ebp
int v10; // [rsp+Ch] [rbp-3Ch]

v5 = a4 - 2;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, a2, a1);
waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_40200C, -1);
horiz_line(a1 + 1, a2, v5);
waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402010, -1);
v7 = a3 - 2;
v10 = a3 - 2;
v8 = a2 + a3 - 1;
vert_line(a1, a2 + 1, v7);
vert_line(a1 + a4 - 1, a2 + 1, v10);
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v8, a1);
waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402014, -1);
horiz_line(a1 + 1, v8, v5);
return waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, &byte_402018, -1);
}

original_code:
static void draw_box(int startx, int starty, int rows, int cols)
{
    wmove(stdscr,(starty),(startx));
    waddnstr(stdscr,("\u2554"),-1);
    horiz_line(startx+1, starty, cols-2);
    waddnstr(stdscr,("\u2557"),-1);
    vert_line(startx, starty+1, rows-2);
    vert_line(startx+cols-1, starty+1, rows-2);
    wmove(stdscr,(starty+rows-1),(startx));
    waddnstr(stdscr,("\u255A"),-1);
    horiz_line(startx+1, starty+rows-1, cols-2);
    waddnstr(stdscr,("\u255D"),-1);
}

variable_types: rows int

variable_types: cols int


decompiled_code:
int __fastcall draw_room(int a1, int a2, int a3, int a4)
{
int result; // eax
int v7; // ebp
int v8; // er15
int v9; // ebx
int v10; // edx

wattrset(stdscr__NCURSES6_TINFO_5_0_19991023, 256);
draw_box(a1, a2, a3, a4);
result = wattrset(stdscr__NCURSES6_TINFO_5_0_19991023, 512);
if ( a3 > 2 )
{
v7 = a2 + 1;
v8 = a2 + a3 - 1;
do
{
v9 = a1 + 1;
if ( a4 > 2 )
{
do
{
v10 = v9++;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v10);
result = waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, asc_40201C, -1);
}
while ( a1 + a4 - 1 != v9 );
}
++v7;
}
while ( v7 != v8 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(int a1, int a2, int a3, int a4)
{
int result; // eax
int v7; // ebp
int v8; // er15
int v9; // ebx
int v10; // edx

wattrset(stdscr__NCURSES6_TINFO_5_0_19991023, 256);
func10(a1, a2, a3, a4);
result = wattrset(stdscr__NCURSES6_TINFO_5_0_19991023, 512);
if ( a3 > 2 )
{
v7 = a2 + 1;
v8 = a2 + a3 - 1;
do
{
v9 = a1 + 1;
if ( a4 > 2 )
{
do
{
v10 = v9++;
wmove(stdscr__NCURSES6_TINFO_5_0_19991023, v7, v10);
result = waddnstr(stdscr__NCURSES6_TINFO_5_0_19991023, asc_40201C, -1);
}
while ( a1 + a4 - 1 != v9 );
}
++v7;
}
while ( v7 != v8 );
}
return result;
}

original_code:
static void draw_room(int startx, int starty, int rows, int cols)
{
    int i, j;
    wattrset(stdscr,((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
    draw_box(startx, starty, rows, cols);
    wattrset(stdscr,((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
    for (i = 1; i < rows - 1; ++i) {
 for (j = 1; j < cols - 1; ++j) {
     wmove(stdscr,(starty + i),(startx + j));
     waddnstr(stdscr,("\x2E"),-1);
 }
    }
}

canonical_original_code:
static void draw_room(int startx, int starty, int rows, int cols)
{
    int i; int j;
    wattrset(stdscr,((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
    draw_box(startx, starty, rows, cols);
    wattrset(stdscr,((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))));
    for (i = 1; i < rows - 1; ++i) {
 for (j = 1; j < cols - 1; ++j) {
     wmove(stdscr,(starty + i),(startx + j));
     waddnstr(stdscr,("\x2E"),-1);
 }
    }
}

variable_types: i int


decompiled_code:
__int64 __fastcall vert_line(int a1, int a2, int a3, WINDOW *a4)
{
int v6; // ebx
int v7; // er13
int v8; // esi

v6 = a2;
logger_log(0LL, "draw.c:57", "Entering %s", "vert_line");
if ( a3 > 0 )
{
v7 = a2 + a3;
do
{
v8 = v6++;
wmove(a4, v8, a1);
waddnstr(a4, &byte_C2F, -1);
}
while ( v6 != v7 );
}
return logger_log(0LL, "draw.c:66", "Leaving %s", "vert_line");
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, WINDOW *a4)
{
int v6; // ebx
int v7; // er13
int v8; // esi

v6 = a2;
logger_log(0LL, "draw.c:57", "Entering %s", "vert_line");
if ( a3 > 0 )
{
v7 = a2 + a3;
do
{
v8 = v6++;
wmove(a4, v8, a1);
waddnstr(a4, &byte_C2F, -1);
}
while ( v6 != v7 );
}
return logger_log(0LL, "draw.c:66", "Leaving %s", "vert_line");
}

canonical_original_code:
static void vert_line(int x, int y, int len)
{
    int i;
    for (i = 0; i < len; ++i) {
 wmove(stdscr,(y+i),(x));
 waddnstr(stdscr,("\u2551"),-1);
    }
}


decompiled_code:
__int64 __fastcall horiz_line(int a1, int a2, int a3, WINDOW *a4)
{
int v6; // ebx

logger_log(0LL, "draw.c:42", "Entering %s", "horiz_line");
wmove(a4, a2, a1);
if ( a3 > 0 )
{
v6 = 0;
do
{
++v6;
waddnstr(a4, &byte_C52, -1);
}
while ( a3 != v6 );
}
return logger_log(0LL, "draw.c:52", "Leaving %s", "horiz_line");
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, WINDOW *a4)
{
int v6; // ebx

logger_log(0LL, "draw.c:42", "Entering %s", "horiz_line");
wmove(a4, a2, a1);
if ( a3 > 0 )
{
v6 = 0;
do
{
++v6;
waddnstr(a4, &byte_C52, -1);
}
while ( a3 != v6 );
}
return logger_log(0LL, "draw.c:52", "Leaving %s", "horiz_line");
}

canonical_original_code:
static void horiz_line(int x, int y, int len)
{
    int i;
    wmove(stdscr,(y),(x));
    for(i = 0; i < len; ++i) {
 waddnstr(stdscr,("\u2550"),-1);
    }
}


decompiled_code:
__int64 __fastcall draw_box(int a1, int a2, int a3, int a4, WINDOW *a5)
{
int v8; // edx
int v9; // er13
int v11; // [rsp+8h] [rbp-40h]

logger_log(0LL, "draw.c:71", "Entering %s", "draw_box");
color_wall();
wmove(a5, a2, a1);
waddnstr(a5, &byte_C7E, -1);
horiz_line(a1 + 1, a2, a4 - 2, a5);
waddnstr(a5, &byte_C82, -1);
v8 = a3 - 2;
v11 = a3 - 2;
v9 = a2 + a3 - 1;
vert_line(a1, a2 + 1, v8, a5);
vert_line(a1 + a4 - 1, a2 + 1, v11, a5);
wmove(a5, v9, a1);
waddnstr(a5, &byte_C86, -1);
horiz_line(a1 + 1, v9, a4 - 2, a5);
waddnstr(a5, &byte_C8A, -1);
return logger_log(0LL, "draw.c:90", "Leaving %s", "draw_box");
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3, int a4, WINDOW *a5)
{
int v8; // edx
int v9; // er13
int v11; // [rsp+8h] [rbp-40h]

logger_log(0LL, "draw.c:71", "Entering %s", "draw_box");
color_wall();
wmove(a5, a2, a1);
waddnstr(a5, &byte_C7E, -1);
func1(a1 + 1, a2, a4 - 2, a5);
waddnstr(a5, &byte_C82, -1);
v8 = a3 - 2;
v11 = a3 - 2;
v9 = a2 + a3 - 1;
func0(a1, a2 + 1, v8, a5);
func0(a1 + a4 - 1, a2 + 1, v11, a5);
wmove(a5, v9, a1);
waddnstr(a5, &byte_C86, -1);
func1(a1 + 1, v9, a4 - 2, a5);
waddnstr(a5, &byte_C8A, -1);
return logger_log(0LL, "draw.c:90", "Leaving %s", "draw_box");
}

canonical_original_code:
static void draw_box(int startx, int starty, int rows, int cols)
{
    wmove(stdscr,(starty),(startx));
    waddnstr(stdscr,("\u2554"),-1);
    horiz_line(startx+1, starty, cols-2);
    waddnstr(stdscr,("\u2557"),-1);
    vert_line(startx, starty+1, rows-2);
    vert_line(startx+cols-1, starty+1, rows-2);
    wmove(stdscr,(starty+rows-1),(startx));
    waddnstr(stdscr,("\u255A"),-1);
    horiz_line(startx+1, starty+rows-1, cols-2);
    waddnstr(stdscr,("\u255D"),-1);
}


decompiled_code:
__int64 __fastcall draw_room(int a1, int a2, int a3, int a4, char a5, WINDOW *a6)
{
int v11; // ebp
int v12; // er15
int v13; // edx

logger_log(0LL, "draw.c:96", "Entering %s", "draw_room");
draw_box(a1, a2, a3, a4, a6);
if ( a5 )
{
color_floor();
if ( a3 > 2 )
{
v11 = a2 + 1;
do
{
v12 = a1 + 1;
if ( a4 > 2 )
{
do
{
v13 = v12++;
wmove(a6, v11, v13);
waddnstr(a6, ".", -1);
}
while ( v12 != a1 + a4 - 1 );
}
++v11;
}
while ( v11 != a2 + a3 - 1 );
}
}
return logger_log(0LL, "draw.c:117", "Leaving %s", "draw_room");
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, int a3, int a4, char a5, WINDOW *a6)
{
int v11; // ebp
int v12; // er15
int v13; // edx

logger_log(0LL, "draw.c:96", "Entering %s", "draw_room");
func3(a1, a2, a3, a4, a6);
if ( a5 )
{
color_floor();
if ( a3 > 2 )
{
v11 = a2 + 1;
do
{
v12 = a1 + 1;
if ( a4 > 2 )
{
do
{
v13 = v12++;
wmove(a6, v11, v13);
waddnstr(a6, ".", -1);
}
while ( v12 != a1 + a4 - 1 );
}
++v11;
}
while ( v11 != a2 + a3 - 1 );
}
}
return logger_log(0LL, "draw.c:117", "Leaving %s", "draw_room");
}

variable_types: j int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // edi
const char *v5; // r12
char _0[1064]; // [rsp+0h] [rbp+0h] BYREF

memset(_0, 0, 0x408uLL);
setlocale(6, &locale);
v4 = time(0LL);
srand(v4);
if ( argc > 1 )
{
v5 = argv[1];
if ( !strcmp(v5, "--debug") )
{
logger_set_level(1LL);
}
else if ( !strcmp(v5, "--verbose") )
{
logger_set_level(0LL);
}
else if ( !strcmp(v5, "--warn") )
{
logger_set_level(2LL);
}
else if ( !strcmp(v5, "--error") )
{
logger_set_level(3LL);
}
}
logger_init();
game_init((__int64)_0);
welcome(_0);
do
{
draw((__int64)_0);
input_handler(_0);
}
while ( _0[24] );
endwin();
free_state(_0);
logger_stop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // edi
const char *v5; // r12
char _0[1064]; // [rsp+0h] [rbp+0h] BYREF

memset(_0, 0, 0x408uLL);
setlocale(6, &locale);
v4 = time(0LL);
srand(v4);
if ( argc > 1 )
{
v5 = argv[1];
if ( !strcmp(v5, "--debug") )
{
logger_set_level(1LL);
}
else if ( !strcmp(v5, "--verbose") )
{
logger_set_level(0LL);
}
else if ( !strcmp(v5, "--warn") )
{
logger_set_level(2LL);
}
else if ( !strcmp(v5, "--error") )
{
logger_set_level(3LL);
}
}
logger_init();
func0((__int64)_0);
func1(_0);
do
{
func2((__int64)_0);
input_handler(_0);
}
while ( _0[24] );
endwin();
free_state(_0);
logger_stop();
return 0;
}

user_defined_types: struct tunnel_st { int len; struct coord_st pos; }

user_defined_types: struct door_t { struct coord_st pos; _Bool hidden; }


repo: boamaod/kanjipad

decompiled_code:
__int64 __fastcall pad_area_free_stroke(_QWORD *a1)
{
_QWORD *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
g_free(*v1);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
return g_list_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
_QWORD *v1; // rbx

if ( a1 )
{
v1 = a1;
do
{
g_free(*v1);
v1 = (_QWORD *)v1[1];
}
while ( v1 );
}
return g_list_free(a1);
}

original_code:
static void
pad_area_free_stroke (GList *stroke)
{
  GList *tmp_list = stroke;
  while (tmp_list)
    {
      g_free (tmp_list->data);
      tmp_list = tmp_list->next;
    }
  g_list_free (stroke);
  stroke = ((void *)0);
}

canonical_original_code:
static void pad_area_free_stroke(struct _GList *stroke)
{
  struct _GList *tmp_list = stroke;
  while (tmp_list)
    {
      g_free (tmp_list->data);
      tmp_list = tmp_list->next;
    }
  g_list_free (stroke);
  stroke = ((void *)0);
}

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


original_code:
void
sjis2jis(unsigned char *p1, unsigned char *p2)
{
  unsigned char c1 = *p1;
  unsigned char c2 = *p2;
  int adjust = c2 < 159;
  int rowOffset = c1 < 160 ? 112 : 176;
  int cellOffset = adjust ? (c2 > 127 ? 32 : 31) : 126;
  *p1 = ((c1 - rowOffset) << 1) - adjust;
  *p2 -= cellOffset;
}

variable_types: adjust int

variable_types: rowOffset int

variable_types: cellOffset int


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "Usage: %s [-f/--data-file FILE]\n", (const char *)progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
fprintf(stderr, "Usage: %s [-f/--data-file FILE]\n", (const char *)progname);
exit(1);
}

original_code:
void
usage ()
{
  fprintf(stderr, "Usage: %s [-f/--data-file FILE]\n", progname);
  exit (1);
}

canonical_original_code:
void usage()
{
  fprintf(stderr, "Usage: %s [-f/--data-file FILE]\n", progname);
  exit (1);
}


original_code:
int
real_main(int argc, char **argv)
{
  int i;
  char *p = progname = argv[0];
  while (*p)
    {
      if (*p == '/') progname = p+1;
      p++;
    }
  for (i=1; i<argc; i++)
    {
      if (!strcmp(argv[i], "--data-file") ||
   !strcmp(argv[i], "-f"))
 {
   i++;
   if (i < argc)
     data_file = argv[i];
   else
     usage();
 }
      else
 {
   usage();
 }
    }
  load_database();
  while (process_strokes (stdin))
    ;
  return 0;
}

variable_types:
argv
char **

variable_types:
p
char *


main

decompiled_code:
// attributes: thunk
int __cdecl main(int argc, const char **argv, const char **envp)
{
return real_main(argc, (char **)argv);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return func4(argc, (char **)argv);
}

original_code:
int
main(int argc, char **argv)
{
  return real_main (argc, argv);
}

variable_types: argc int


SqrtULong

decompiled_code:
unsigned __int64 __fastcall SqrtULong(unsigned __int64 a1)
{
unsigned __int64 result; // rax
__int64 v2; // rsi
unsigned __int64 v3; // rdx

result = 0LL;
if ( a1 )
{
result = 1LL;
if ( a1 != 1 )
{
result = 0xFFFFLL;
if ( a1 <= 0xFFFE0000 )
{
v2 = a1 >> 1;
if ( a1 > 0x1FFFF )
v2 = 0xFFFFLL;
result = 1LL;
while ( 1 )
{
v3 = result;
result = (v2 + result) >> 1;
if ( v3 >= result )
break;
if ( result * result > a1 )
{
v2 = result;
result = v3;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1)
{
unsigned __int64 result; // rax
__int64 v2; // rsi
unsigned __int64 v3; // rdx

result = 0LL;
if ( a1 )
{
result = 1LL;
if ( a1 != 1 )
{
result = 0xFFFFLL;
if ( a1 <= 0xFFFE0000 )
{
v2 = a1 >> 1;
if ( a1 > 0x1FFFF )
v2 = 0xFFFFLL;
result = 1LL;
while ( 1 )
{
v3 = result;
result = (v2 + result) >> 1;
if ( v3 >= result )
break;
if ( result * result > a1 )
{
v2 = result;
result = v3;
}
}
}
}
}
return result;
}

original_code:
ULong SqrtULong(ULong val) {
 ULong root, rootLo, rootHi;
 if (val == 0)
  return 0;
 else if (val == 1)
  return 1;
 else if (val >= (((ULong) 0xffff)*((ULong) 0xffff)))
  return ((ULong) 0xffff);
 rootLo = 1;
 rootHi = (val >> 1);
 if (rootHi > ((ULong) 0xffff))
  rootHi = ((ULong) 0xffff);
 while ((root = ((rootLo + rootHi) >> 1)) > rootLo) {
  if ((root * root) <= val) {
   rootLo = root;
  }
  else {
   rootHi = root;
  }
 }
 return root;
}

canonical_original_code:
unsigned long SqrtULong(unsigned long val) {
 unsigned long root; unsigned long rootLo; unsigned long rootHi;
 if (val == 0)
  return 0;
 else if (val == 1)
  return 1;
 else if (val >= (((unsigned long) 0xffff)*((unsigned long) 0xffff)))
  return ((unsigned long) 0xffff);
 rootLo = 1;
 rootHi = (val >> 1);
 if (rootHi > ((unsigned long) 0xffff))
  rootHi = ((unsigned long) 0xffff);
 while ((root = ((rootLo + rootHi) >> 1)) > rootLo) {
  if ((root * root) <= val) {
   rootLo = root;
  }
  else {
   rootHi = root;
  }
 }
 return root;
}

variable_types:
val
unsigned long

variable_types:
root
unsigned long

variable_types:
rootLo
unsigned long

variable_types:
rootHi
unsigned long

return_type: unsigned long


StrokeScorerDestroy

decompiled_code:
void __fastcall StrokeScorerDestroy(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 5));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 3));
free(*((void **)ptr + 5));
free(ptr);
}
}

original_code:
void StrokeScorerDestroy (StrokeScorer *pScorer) {
 if (pScorer) {
  free (pScorer->m_pScores);
  free (pScorer->m_cpPath);
  free (pScorer);
 }
}

canonical_original_code:
void StrokeScorerDestroy(struct StrokeScorerStruct *pScorer) {
 if (pScorer) {
  free (pScorer->m_pScores);
  free (pScorer->m_cpPath);
  free (pScorer);
 }
}

variable_types: struct StrokeScorerStruct { char *m_cpStrokeDic; struct RawStroke { unsigned int m_len; unsigned char m_x[256]; unsigned char m_y[256]; } *m_pRawStrokes; unsigned int m_iStrokeCnt; struct ScoreItemStruct { unsigned long m_iScore; char *m_cp; } *m_pScores; unsigned int m_iScoreLen; char *m_cpPath; } *

user_defined_types: struct StrokeScorerStruct { char *m_cpStrokeDic; struct RawStroke *m_pRawStrokes; unsigned int m_iStrokeCnt; struct ScoreItemStruct *m_pScores; unsigned int m_iScoreLen; char *m_cpPath; }


StrokeScorerTopPicks

original_code:
ListMem* StrokeScorerTopPicks (StrokeScorer *pScorer)
{
 ListMem* pListMem;
 UInt iTotStrLen, iListSize, iTotSize;
 CharPtr cpList;
 CharPtr* cppList;
 ScoreItemPtr pScore, pScoreBase;
 UInt sJisVal;
 char buf[10];
 if (!pScorer) {
  ErrBox("StrokeScorerTopPicks: pScorer == NULL.");
  return ((void *)0);
 }
 if (pScorer->m_iScoreLen <= 0)
  return AppEmptyList();
 pScoreBase = pScorer->m_pScores;
 iTotStrLen = pScorer->m_iScoreLen * ((2 + 2+2 + 9 + 1 + 10) + 1);
 iListSize = (pScorer->m_iScoreLen+1)*sizeof(CharPtr);
 iTotSize = sizeof(ListMem) + iListSize + iTotStrLen;
 if (!(cpList = malloc(iTotSize))) {
  ErrBox("ERROR: no mem in top picks");
  return ((void *)0);
 }
 pListMem = (ListMem *) cpList; cpList += sizeof(ListMem);
 cppList = (CharPtr *) cpList; cpList += iListSize;
 pListMem->m_argc = pScorer->m_iScoreLen;
 pListMem->m_argv = cppList;
 for (pScore = pScoreBase; pScore < (pScoreBase+pScorer->m_iScoreLen); pScore++) {
  *cppList++ = cpList;
  *cpList++ = pScore->m_cp[0];
  *cpList++ = pScore->m_cp[1];
  *cpList++ = ' ';
  *cpList++ = ' ';
  *cpList++ = 'S';
  *cpList++ = 'J';
  *cpList++ = 'I';
  *cpList++ = 'S';
  *cpList++ = ':';
  sJisVal = ((pScore->m_cp[0] & 0xff) << 8) + (pScore->m_cp[1] & 0xff);
  sprintf((buf),"%lx",(long)(sJisVal));
  *cpList++ = buf[4];
  *cpList++ = buf[5];
  *cpList++ = buf[6];
  *cpList++ = buf[7];
  *cpList++ = ' ';
  *cpList++ = ' ';
  *cpList++ = '#';
  sprintf((cpList),"%ld",(long)(pScore->m_iScore));
  cpList += strlen(cpList) + 1;
 }
 *cppList = ((void *)0);
 return pListMem;
}

canonical_original_code:
struct ListMem *StrokeScorerTopPicks(struct StrokeScorerStruct *pScorer)
{
 struct ListMem *pListMem;
 unsigned int iTotStrLen; unsigned int iListSize; unsigned int iTotSize;
 char *cpList;
 char **cppList;
 struct ScoreItemStruct *pScore; struct ScoreItemStruct *pScoreBase;
 unsigned int sJisVal;
 char buf[10];
 if (!pScorer) {
  ErrBox("StrokeScorerTopPicks: pScorer == NULL.");
  return ((void *)0);
 }
 if (pScorer->m_iScoreLen <= 0)
  return AppEmptyList();
 pScoreBase = pScorer->m_pScores;
 iTotStrLen = pScorer->m_iScoreLen * ((2 + 2+2 + 9 + 1 + 10) + 1);
 iListSize = (pScorer->m_iScoreLen+1)*sizeof(CharPtr);
 iTotSize = sizeof(ListMem) + iListSize + iTotStrLen;
 if (!(cpList = malloc(iTotSize))) {
  ErrBox("ERROR: no mem in top picks");
  return ((void *)0);
 }
 pListMem = (struct ListMem *) cpList; cpList += sizeof(ListMem);
 cppList = (char **) cpList; cpList += iListSize;
 pListMem->m_argc = pScorer->m_iScoreLen;
 pListMem->m_argv = cppList;
 for (pScore = pScoreBase; pScore < (pScoreBase+pScorer->m_iScoreLen); pScore++) {
  *cppList++ = cpList;
  *cpList++ = pScore->m_cp[0];
  *cpList++ = pScore->m_cp[1];
  *cpList++ = ' ';
  *cpList++ = ' ';
  *cpList++ = 'S';
  *cpList++ = 'J';
  *cpList++ = 'I';
  *cpList++ = 'S';
  *cpList++ = ':';
  sJisVal = ((pScore->m_cp[0] & 0xff) << 8) + (pScore->m_cp[1] & 0xff);
  sprintf((buf),"%lx",(long)(sJisVal));
  *cpList++ = buf[4];
  *cpList++ = buf[5];
  *cpList++ = buf[6];
  *cpList++ = buf[7];
  *cpList++ = ' ';
  *cpList++ = ' ';
  *cpList++ = '#';
  sprintf((cpList),"%ld",(long)(pScore->m_iScore));
  cpList += strlen(cpList) + 1;
 }
 *cppList = ((void *)0);
 return pListMem;
}

variable_types: struct ListMem { unsigned int m_argc; char **m_argv; } *

variable_types:
iTotStrLen
unsigned int

variable_types:
iListSize
unsigned int

variable_types:
iTotSize
unsigned int

variable_types:
cpList
char *

variable_types:
cppList
char **

variable_types: struct ScoreItemStruct { unsigned long m_iScore; char *m_cp; } *

variable_types:
sJisVal
unsigned int

variable_types:
buf
char [10]

user_defined_types: struct RawStroke { unsigned int m_len; unsigned char m_x[256]; unsigned char m_y[256]; }


StrokeDicScoreStroke

original_code:
ULong StrokeDicScoreStroke(Byte* bpX, Byte* bpY, UInt iLen,
         CharPtr cpPath, UInt iPathLen,
          UInt iDepth) {
 ULong iScore, iThisScore;
 Long iMid, iStep, iPathMid, iPathRest;
 Long iDifX, iDifY;
 UInt iAng32, iPath32, iDif32;
 if (iLen < 2 || iPathLen < 1)
  return (((((ULong)24)*98)+52)*100);
 if (iPathLen == 1) {
  iDifX = bpX[iLen-1] - bpX[0];
  iDifY = bpY[0] - bpY[iLen-1];
  if (iDifX == 0 && iDifY == 0)
   return (((((ULong)24)*98)+52)*100);
  if ((iDifX*iDifX + iDifY*iDifY) > (20*20) && iLen > 5 && iDepth < 4) {
   iMid = iLen >> 1;
   iScore = StrokeDicScoreStroke(bpX, bpY, iMid+1,
             cpPath, iPathLen, iDepth+1);
   iScore += StrokeDicScoreStroke(bpX+iMid, bpY+iMid, iLen-iMid,
             cpPath, iPathLen, iDepth+1);
   return (iScore >> 1);
  }
  iAng32 = Angle32(iDifX, iDifY);
  iPath32 = *cpPath;
  if (iAng32 >= iPath32)
   iDif32 = iAng32 - iPath32;
  else
   iDif32 = iPath32 - iAng32;
  return iDif32 * 98 + 52;
 }
 else {
  iScore = (((((ULong)24)*98)+52)*100) * iPathLen * 2;
  iPathMid = iPathLen >> 1;
  iPathRest = iPathLen - iPathMid;
  if (iLen < 20)
   iStep = 1;
  else
   iStep = iLen / 10;
  for (iMid = iPathMid; iMid < iLen - iPathRest; iMid += iStep) {
   iThisScore = StrokeDicScoreStroke(bpX, bpY, iMid+1,
              cpPath, iPathMid, iDepth+1);
   iThisScore += StrokeDicScoreStroke(bpX+iMid, bpY+iMid, iLen-iMid,
              cpPath+iPathMid, iPathRest,
              iDepth+1);
   iThisScore >>= 1;
   if (iThisScore < iScore)
    iScore = iThisScore;
  }
  return iScore;
 }
}

canonical_original_code:
unsigned long StrokeDicScoreStroke(unsigned char *bpX, unsigned char *bpY, unsigned int iLen, char *cpPath, unsigned int iPathLen, unsigned int iDepth) {
 unsigned long iScore; unsigned long iThisScore;
 long iMid; long iStep; long iPathMid; long iPathRest;
 long iDifX; long iDifY;
 unsigned int iAng32; unsigned int iPath32; unsigned int iDif32;
 if (iLen < 2 || iPathLen < 1)
  return (((((unsigned long)24)*98)+52)*100);
 if (iPathLen == 1) {
  iDifX = bpX[iLen-1] - bpX[0];
  iDifY = bpY[0] - bpY[iLen-1];
  if (iDifX == 0 && iDifY == 0)
   return (((((unsigned long)24)*98)+52)*100);
  if ((iDifX*iDifX + iDifY*iDifY) > (20*20) && iLen > 5 && iDepth < 4) {
   iMid = iLen >> 1;
   iScore = StrokeDicScoreStroke(bpX, bpY, iMid+1,
             cpPath, iPathLen, iDepth+1);
   iScore += StrokeDicScoreStroke(bpX+iMid, bpY+iMid, iLen-iMid,
             cpPath, iPathLen, iDepth+1);
   return (iScore >> 1);
  }
  iAng32 = Angle32(iDifX, iDifY);
  iPath32 = *cpPath;
  if (iAng32 >= iPath32)
   iDif32 = iAng32 - iPath32;
  else
   iDif32 = iPath32 - iAng32;
  return iDif32 * 98 + 52;
 }
 else {
  iScore = (((((unsigned long)24)*98)+52)*100) * iPathLen * 2;
  iPathMid = iPathLen >> 1;
  iPathRest = iPathLen - iPathMid;
  if (iLen < 20)
   iStep = 1;
  else
   iStep = iLen / 10;
  for (iMid = iPathMid; iMid < iLen - iPathRest; iMid += iStep) {
   iThisScore = StrokeDicScoreStroke(bpX, bpY, iMid+1,
              cpPath, iPathMid, iDepth+1);
   iThisScore += StrokeDicScoreStroke(bpX+iMid, bpY+iMid, iLen-iMid,
              cpPath+iPathMid, iPathRest,
              iDepth+1);
   iThisScore >>= 1;
   if (iThisScore < iScore)
    iScore = iThisScore;
  }
  return iScore;
 }
}

variable_types:
bpX
unsigned char *

variable_types:
bpY
unsigned char *

variable_types:
iLen
unsigned int

variable_types:
cpPath
char *

variable_types:
iPathLen
unsigned int

variable_types:
iDepth
unsigned int

variable_types:
iScore
unsigned long

variable_types:
iThisScore
unsigned long

variable_types: iMid long

variable_types: iStep long

variable_types: iPathMid long

variable_types: iPathRest long

variable_types: iDifX long

variable_types: iDifY long


StrokeScorerExtraEval

decompiled_code:
unsigned __int64 __fastcall StrokeScorerExtraEval(__int64 a1, char a2, int a3)
{
__int64 v3; // rdx
__int64 v4; // rdx
int v5; // eax
unsigned __int64 result; // rax
__int64 v7; // rcx
unsigned __int64 v8; // rax

v3 = (unsigned int)(a3 - 1);
if ( *(_DWORD *)(a1 + 16) <= (unsigned int)v3 )
return 0LL;
v4 = *(_QWORD *)(a1 + 8) + 516 * v3;
v5 = *(_DWORD *)v4;
switch ( a2 )
{
case 'a':
result = (*(unsigned __int8 *)(v4 + 4) + *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 4)) >> 1;
break;
case 'b':
result = (*(unsigned __int8 *)(v4 + 260) + *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 260)) >> 1;
break;
case 'i':
result = *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 4);
break;
case 'j':
result = *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 260);
break;
case 'l':
v7 = (unsigned int)(v5 - 1);
v8 = *(unsigned __int8 *)(v4 + 4) - (unsigned __int64)*(unsigned __int8 *)(v4 + v7 + 4);
result = SqrtULong(
v8 * v8
+ (*(unsigned __int8 *)(v4 + 260) - (unsigned __int64)*(unsigned __int8 *)(v4 + v7 + 260))
* (*(unsigned __int8 *)(v4 + 260) - (unsigned __int64)*(unsigned __int8 *)(v4 + v7 + 260)));
break;
case 'x':
result = *(unsigned __int8 *)(v4 + 4);
break;
case 'y':
result = *(unsigned __int8 *)(v4 + 260);
break;
default:
return 0LL;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1, char a2, int a3)
{
__int64 v3; // rdx
__int64 v4; // rdx
int v5; // eax
unsigned __int64 result; // rax
__int64 v7; // rcx
unsigned __int64 v8; // rax

v3 = (unsigned int)(a3 - 1);
if ( *(_DWORD *)(a1 + 16) <= (unsigned int)v3 )
return 0LL;
v4 = *(_QWORD *)(a1 + 8) + 516 * v3;
v5 = *(_DWORD *)v4;
switch ( a2 )
{
case 'a':
result = (*(unsigned __int8 *)(v4 + 4) + *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 4)) >> 1;
break;
case 'b':
result = (*(unsigned __int8 *)(v4 + 260) + *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 260)) >> 1;
break;
case 'i':
result = *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 4);
break;
case 'j':
result = *(unsigned __int8 *)(v4 + (unsigned int)(v5 - 1) + 260);
break;
case 'l':
v7 = (unsigned int)(v5 - 1);
v8 = *(unsigned __int8 *)(v4 + 4) - (unsigned __int64)*(unsigned __int8 *)(v4 + v7 + 4);
result = func0(
v8 * v8
+ (*(unsigned __int8 *)(v4 + 260) - (unsigned __int64)*(unsigned __int8 *)(v4 + v7 + 260))
* (*(unsigned __int8 *)(v4 + 260) - (unsigned __int64)*(unsigned __int8 *)(v4 + v7 + 260)));
break;
case 'x':
result = *(unsigned __int8 *)(v4 + 4);
break;
case 'y':
result = *(unsigned __int8 *)(v4 + 260);
break;
default:
return 0LL;
}
return result;
}

original_code:
Long StrokeScorerExtraEval(StrokeScorer *pScorer,
         char cArg, UInt iStroke) {
 Long iVal, iSquared;
 Byte* bpX;
 Byte* bpY;
 UInt iLen;
 RawStroke* rsp;
 iStroke--;
 if (iStroke >= pScorer->m_iStrokeCnt)
  return 0;
 rsp = pScorer->m_pRawStrokes + iStroke;
 iLen = rsp->m_len;
 bpX = rsp->m_x;
 bpY = rsp->m_y;
 switch(cArg) {
 case 'x':
  return bpX[0];
 case 'y':
  return bpY[0];
 case 'i':
  return bpX[iLen-1];
 case 'j':
  return bpY[iLen-1];
 case 'a':
  return ((bpX[0] + bpX[iLen-1]) >> 1);
 case 'b':
  return ((bpY[0] + bpY[iLen-1]) >> 1);
 case 'l':
  iSquared = (((Long) bpX[0]) - ((Long)bpX[iLen-1]));
  iVal = iSquared * iSquared;
  iSquared = (((Long) bpY[0]) - ((Long)bpY[iLen-1]));
  iVal += iSquared * iSquared;
  return (Long) SqrtULong((Long) iVal);
 }
 return 0;
}

canonical_original_code:
long StrokeScorerExtraEval(struct StrokeScorerStruct *pScorer, char cArg, unsigned int iStroke) {
 long iVal; long iSquared;
 unsigned char *bpX;
 unsigned char *bpY;
 unsigned int iLen;
 struct RawStroke *rsp;
 iStroke--;
 if (iStroke >= pScorer->m_iStrokeCnt)
  return 0;
 rsp = pScorer->m_pRawStrokes + iStroke;
 iLen = rsp->m_len;
 bpX = rsp->m_x;
 bpY = rsp->m_y;
 switch(cArg) {
 case 'x':
  return bpX[0];
 case 'y':
  return bpY[0];
 case 'i':
  return bpX[iLen-1];
 case 'j':
  return bpY[iLen-1];
 case 'a':
  return ((bpX[0] + bpX[iLen-1]) >> 1);
 case 'b':
  return ((bpY[0] + bpY[iLen-1]) >> 1);
 case 'l':
  iSquared = (((long) bpX[0]) - ((long)bpX[iLen-1]));
  iVal = iSquared * iSquared;
  iSquared = (((long) bpY[0]) - ((long)bpY[iLen-1]));
  iVal += iSquared * iSquared;
  return (long) SqrtULong((long) iVal);
 }
 return 0;
}

variable_types: struct StrokeScorerStruct { char *m_cpStrokeDic; struct RawStroke { unsigned int m_len; unsigned char m_x[256]; unsigned char m_y[256]; } *m_pRawStrokes; unsigned int m_iStrokeCnt; struct ScoreItemStruct { unsigned long m_iScore; char *m_cp; } *m_pScores; unsigned int m_iScoreLen; char *m_cpPath; } *

variable_types: cArg char

variable_types:
iStroke
unsigned int

variable_types: iVal long

variable_types: iSquared long

return_type: long


StrokeScorerExtraFilters

original_code:
CharPtr StrokeScorerExtraFilters(StrokeScorer *pScorer,
         CharPtr cp, ULong* ipScore ) {
 char c;
 char cArg[2];
 Byte iStroke[2];
 Long iDiff, iVal[2];
 UInt idx = 0;
 Boolean bMust = 0;
 ;
 cArg[0] = cArg[1] = 0;
 iStroke[0] = iStroke[1] = 0;
 for (c = *cp; 1; cp++, c = *cp) {
  switch (c) {
  case 'x':
  case 'y':
  case 'i':
  case 'j':
  case 'a':
  case 'b':
  case 'l':
   cArg[idx] = c;
   ;
   ;
   ;
   break;
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
   iStroke[idx] = iStroke[idx] * 10 + (c - '0');
   ;
   break;
  case '-':
   idx = 1;
   ;
   break;
  case '!':
   bMust = 1;
   ;
  case ' ':
  default:
   ;
   ;
   if (idx == 1) {
    iVal[0] = StrokeScorerExtraEval(pScorer, cArg[0], iStroke[0]);
    iVal[1] = StrokeScorerExtraEval(pScorer, cArg[1], iStroke[1]);
    iDiff = (iVal[0] - iVal[1]);
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    if (iDiff < 0) {
     iDiff = -iDiff;
     if (bMust)
      iDiff = 9999999;
     if (*ipScore < ((((ULong) 0xffff)*((ULong) 0xffff))-iDiff))
      *ipScore += iDiff;
     else
      *ipScore = (((ULong) 0xffff)*((ULong) 0xffff));
    }
    else {
     if (*ipScore > iDiff)
      *ipScore -= iDiff;
     else
      *ipScore = 0;
    }
    ;
    idx = 0;
    bMust = 0;
    cArg[0] = cArg[1] = 0;
    iStroke[0] = iStroke[1] = 0;
   }
   if ((c & 0x80) || (c == '\0'))
    goto ReturnNow;
  }
 }
ReturnNow:
 return cp;
}

canonical_original_code:
char *StrokeScorerExtraFilters(struct StrokeScorerStruct *pScorer, char *cp, unsigned long *ipScore) {
 char c;
 char cArg[2];
 unsigned char iStroke[2];
 long iDiff; long iVal[2];
 unsigned int idx = 0;
 int bMust = 0;
 ;
 cArg[0] = cArg[1] = 0;
 iStroke[0] = iStroke[1] = 0;
 for (c = *cp; 1; cp++, c = *cp) {
  switch (c) {
  case 'x':
  case 'y':
  case 'i':
  case 'j':
  case 'a':
  case 'b':
  case 'l':
   cArg[idx] = c;
   ;
   ;
   ;
   break;
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
   iStroke[idx] = iStroke[idx] * 10 + (c - '0');
   ;
   break;
  case '-':
   idx = 1;
   ;
   break;
  case '!':
   bMust = 1;
   ;
  case ' ':
  default:
   ;
   ;
   if (idx == 1) {
    iVal[0] = StrokeScorerExtraEval(pScorer, cArg[0], iStroke[0]);
    iVal[1] = StrokeScorerExtraEval(pScorer, cArg[1], iStroke[1]);
    iDiff = (iVal[0] - iVal[1]);
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    ;
    if (iDiff < 0) {
     iDiff = -iDiff;
     if (bMust)
      iDiff = 9999999;
     if (*ipScore < ((((unsigned long) 0xffff)*((unsigned long) 0xffff))-iDiff))
      *ipScore += iDiff;
     else
      *ipScore = (((unsigned long) 0xffff)*((unsigned long) 0xffff));
    }
    else {
     if (*ipScore > iDiff)
      *ipScore -= iDiff;
     else
      *ipScore = 0;
    }
    ;
    idx = 0;
    bMust = 0;
    cArg[0] = cArg[1] = 0;
    iStroke[0] = iStroke[1] = 0;
   }
   if ((c & 0x80) || (c == '\0'))
    goto ReturnNow;
  }
 }
ReturnNow:
 return cp;
}

variable_types:
cp
char *

variable_types:
ipScore
unsigned long *

variable_types: c char

variable_types:
cArg
char [2]

variable_types:
iStroke
unsigned char [2]

variable_types: iDiff long

variable_types:
iVal
long [2]

variable_types:
idx
unsigned int

variable_types: bMust int

return_type: char *

user_defined_types: struct ScoreItemStruct { unsigned long m_iScore; char *m_cp; }


StrokeScorerEvalItem

decompiled_code:
char *__fastcall StrokeScorerEvalItem(__int64 a1, char *a2, __int64 *a3)
{
char *v3; // r12
char *v4; // r13
unsigned int v5; // ebx
unsigned __int64 v6; // r15
_BYTE *v7; // r8
char v8; // al
unsigned __int8 v9; // al
__int64 v10; // rax
unsigned __int64 v11; // rax
unsigned __int64 v12; // rax

v3 = a2;
v4 = *(char **)(a1 + 40);
if ( *a2 )
{
if ( a2[1] )
v3 = a2 + 2;
else
v3 = a2 + 1;
}
v5 = *(_DWORD *)(a1 + 16);
v6 = 0LL;
if ( v5 )
{
v5 = 0;
while ( 2 )
{
switch ( *v3 )
{
case 'A':
*v4 = 20;
v7 = v4 + 1;
goto LABEL_8;
case 'B':
*v4 = 16;
v7 = v4 + 1;
goto LABEL_8;
case 'C':
*v4 = 12;
v7 = v4 + 1;
goto LABEL_8;
case 'D':
*v4 = 24;
v7 = v4 + 1;
goto LABEL_8;
case 'F':
*v4 = 8;
v7 = v4 + 1;
goto LABEL_8;
case 'G':
*v4 = 28;
v7 = v4 + 1;
goto LABEL_8;
case 'H':
*v4 = 0;
v7 = v4 + 1;
goto LABEL_8;
case 'I':
*v4 = 4;
v7 = v4 + 1;
goto LABEL_8;
case 'J':
v7 = v4 + 2;
*(_WORD *)v4 = 5136;
goto LABEL_8;
case 'K':
v7 = v4 + 2;
*(_WORD *)v4 = 3088;
goto LABEL_8;
case 'L':
v7 = v4 + 2;
*(_WORD *)v4 = 2064;
goto LABEL_8;
case 'M':
v7 = v4 + 2;
*(_WORD *)v4 = 4104;
LABEL_8:
while ( 2 )
{
v8 = *++v3;
v9 = v8 - 97;
LABEL_9:
switch ( v9 )
{
case 0u:
*v7++ = 20;
continue;
case 1u:
*v7++ = 16;
continue;
case 2u:
*v7++ = 12;
continue;
case 3u:
*v7++ = 24;
continue;
case 5u:
*v7++ = 8;
continue;
case 6u:
*v7++ = 28;
continue;
case 7u:
*v7++ = 0;
continue;
case 8u:
*v7++ = 4;
continue;
case 9u:
v7 += 2;
*((_WORD *)v7 - 1) = 5136;
continue;
case 0xAu:
v7 += 2;
*((_WORD *)v7 - 1) = 3088;
continue;
case 0xBu:
v7 += 2;
*((_WORD *)v7 - 1) = 2064;
continue;
case 0xCu:
++v3;
v7 += 2;
*((_WORD *)v7 - 1) = 4104;
v9 = *v3 - 97;
if ( v9 <= 0xCu )
goto LABEL_9;
break;
default:
goto LABEL_11;
}
break;
}
LABEL_11:
v10 = *(_QWORD *)(a1 + 8) + 516LL * v5;
v11 = StrokeDicScoreStroke(
(unsigned __int8 *)(v10 + 4),
(unsigned __int8 *)(v10 + 260),
*(_DWORD *)v10,
v4,
(unsigned int)((_DWORD)v7 - (_DWORD)v4),
0);
if ( v11 > 0xFFFE || (v12 = v11 * v11, 4294836225u - v12 <= v6) )
v6 = 4294836225LL;
else
v6 += v12;
if ( *(_DWORD *)(a1 + 16) <= ++v5 )
break;
continue;
default:
goto LABEL_15;
}
}
}
LABEL_15:
*a3 = SqrtULong(v6);
if ( *v3 == 124 )
v3 = StrokeScorerExtraFilters(a1, v3 + 1, a3);
if ( *(_DWORD *)(a1 + 16) != v5 )
ErrBox("JStrokeDic miscount");
if ( *v3 > 0 )
ErrBox("JStrokeDic leftovers");
return v3;
}

original_code:
CharPtr StrokeScorerEvalItem(StrokeScorer *pScorer, CharPtr cpEntry,
        ULong* ipScore ) {
 CharPtr cp = cpEntry;
 UInt iStroke;
 CharPtr cpPath = pScorer->m_cpPath;
 CharPtr cpPathEnd;
 RawStroke* rsp;
 ULong iThisScore;
 ULong iScore = 0;
 ;
 if (*cp) cp++;
 if (*cp) cp++;
 for (iStroke = 0; iStroke < pScorer->m_iStrokeCnt; iStroke++) {
  cpPathEnd = cpPath;
  switch (*cp) {
  case 'A':
   *cpPathEnd++ = 20; break;
  case 'B':
   *cpPathEnd++ = 16; break;
  case 'C':
   *cpPathEnd++ = 12; break;
  case 'D':
   *cpPathEnd++ = 24; break;
  case 'F':
   *cpPathEnd++ = 8; break;
  case 'G':
   *cpPathEnd++ = 28; break;
  case 'H':
   *cpPathEnd++ = 0; break;
  case 'I':
   *cpPathEnd++ = 4; break;
  case 'J':
   *cpPathEnd++ = 16; *cpPathEnd++ = 20; break;
  case 'K':
   *cpPathEnd++ = 16; *cpPathEnd++ = 12; break;
  case 'L':
   *cpPathEnd++ = 16; *cpPathEnd++ = 8; break;
  case 'M':
   *cpPathEnd++ = 8; *cpPathEnd++ = 16; break;
  default:
   goto NoMoreStrokes;
  }
  for (cp++; ; cp++) {
   switch (*cp) {
   case 'a':
    *cpPathEnd++ = 20; break;
   case 'b':
    *cpPathEnd++ = 16; break;
   case 'c':
    *cpPathEnd++ = 12; break;
   case 'd':
    *cpPathEnd++ = 24; break;
   case 'f':
    *cpPathEnd++ = 8; break;
   case 'g':
    *cpPathEnd++ = 28; break;
   case 'h':
    *cpPathEnd++ = 0; break;
   case 'i':
    *cpPathEnd++ = 4; break;
   case 'j':
    *cpPathEnd++ = 16; *cpPathEnd++ = 20; break;
   case 'k':
    *cpPathEnd++ = 16; *cpPathEnd++ = 12; break;
   case 'l':
    *cpPathEnd++ = 16; *cpPathEnd++ = 8; break;
   case 'm':
    *cpPathEnd++ = 8; *cpPathEnd++ = 16; break;
   default:
    goto ThisStrokeDone;
   }
  }
ThisStrokeDone:
  rsp = &(pScorer->m_pRawStrokes[iStroke]);
  iThisScore = StrokeDicScoreStroke(rsp->m_x, rsp->m_y, rsp->m_len,
            cpPath, (cpPathEnd - cpPath),
            0 );
  ;
  ;
  if (iThisScore >= ((ULong) 0xffff))
   iThisScore = (((ULong) 0xffff)*((ULong) 0xffff));
  else
   iThisScore = (iThisScore * iThisScore);
  if (iScore >= ((((ULong) 0xffff)*((ULong) 0xffff)) - iThisScore))
   iScore = (((ULong) 0xffff)*((ULong) 0xffff));
  else
   iScore += iThisScore;
 }
NoMoreStrokes:
 iScore = SqrtULong(iScore);
 *ipScore = iScore;
 ;
 if (*cp == '|') {
  cp = StrokeScorerExtraFilters(pScorer, cp+1, ipScore);
 }
 if (iStroke != pScorer->m_iStrokeCnt)
  ErrBox("JStrokeDic miscount");
 if (!(*cp & 0x80) && (*cp != '\0'))
  ErrBox("JStrokeDic leftovers");
 ;
 ;
 return cp;
}

canonical_original_code:
char *StrokeScorerEvalItem(struct StrokeScorerStruct *pScorer, char *cpEntry, unsigned long *ipScore) {
 char *cp = cpEntry;
 unsigned int iStroke;
 char *cpPath = pScorer->m_cpPath;
 char *cpPathEnd;
 struct RawStroke *rsp;
 unsigned long iThisScore;
 unsigned long iScore = 0;
 ;
 if (*cp) cp++;
 if (*cp) cp++;
 for (iStroke = 0; iStroke < pScorer->m_iStrokeCnt; iStroke++) {
  cpPathEnd = cpPath;
  switch (*cp) {
  case 'A':
   *cpPathEnd++ = 20; break;
  case 'B':
   *cpPathEnd++ = 16; break;
  case 'C':
   *cpPathEnd++ = 12; break;
  case 'D':
   *cpPathEnd++ = 24; break;
  case 'F':
   *cpPathEnd++ = 8; break;
  case 'G':
   *cpPathEnd++ = 28; break;
  case 'H':
   *cpPathEnd++ = 0; break;
  case 'I':
   *cpPathEnd++ = 4; break;
  case 'J':
   *cpPathEnd++ = 16; *cpPathEnd++ = 20; break;
  case 'K':
   *cpPathEnd++ = 16; *cpPathEnd++ = 12; break;
  case 'L':
   *cpPathEnd++ = 16; *cpPathEnd++ = 8; break;
  case 'M':
   *cpPathEnd++ = 8; *cpPathEnd++ = 16; break;
  default:
   goto NoMoreStrokes;
  }
  for (cp++; ; cp++) {
   switch (*cp) {
   case 'a':
    *cpPathEnd++ = 20; break;
   case 'b':
    *cpPathEnd++ = 16; break;
   case 'c':
    *cpPathEnd++ = 12; break;
   case 'd':
    *cpPathEnd++ = 24; break;
   case 'f':
    *cpPathEnd++ = 8; break;
   case 'g':
    *cpPathEnd++ = 28; break;
   case 'h':
    *cpPathEnd++ = 0; break;
   case 'i':
    *cpPathEnd++ = 4; break;
   case 'j':
    *cpPathEnd++ = 16; *cpPathEnd++ = 20; break;
   case 'k':
    *cpPathEnd++ = 16; *cpPathEnd++ = 12; break;
   case 'l':
    *cpPathEnd++ = 16; *cpPathEnd++ = 8; break;
   case 'm':
    *cpPathEnd++ = 8; *cpPathEnd++ = 16; break;
   default:
    goto ThisStrokeDone;
   }
  }
ThisStrokeDone:
  rsp = &(pScorer->m_pRawStrokes[iStroke]);
  iThisScore = StrokeDicScoreStroke(rsp->m_x, rsp->m_y, rsp->m_len,
            cpPath, (cpPathEnd - cpPath),
            0 );
  ;
  ;
  if (iThisScore >= ((unsigned long) 0xffff))
   iThisScore = (((unsigned long) 0xffff)*((unsigned long) 0xffff));
  else
   iThisScore = (iThisScore * iThisScore);
  if (iScore >= ((((unsigned long) 0xffff)*((unsigned long) 0xffff)) - iThisScore))
   iScore = (((unsigned long) 0xffff)*((unsigned long) 0xffff));
  else
   iScore += iThisScore;
 }
NoMoreStrokes:
 iScore = SqrtULong(iScore);
 *ipScore = iScore;
 ;
 if (*cp == '|') {
  cp = StrokeScorerExtraFilters(pScorer, cp+1, ipScore);
 }
 if (iStroke != pScorer->m_iStrokeCnt)
  ErrBox("JStrokeDic miscount");
 if (!(*cp & 0x80) && (*cp != '\0'))
  ErrBox("JStrokeDic leftovers");
 ;
 ;
 return cp;
}

variable_types:
cpEntry
char *

variable_types:
cpPath
char *

variable_types:
cpPathEnd
char *

variable_types: struct RawStroke { unsigned int m_len; unsigned char m_x[256]; unsigned char m_y[256]; } *

variable_types:
iThisScore
unsigned long

variable_types:
iScore
unsigned long


StrokeScorerProcess

original_code:
Long StrokeScorerProcess (StrokeScorer *pScorer, Long iMaxCnt) {
 CharPtr cp, cpNext;
 ULong iScore;
 Long iCnt;
 ScoreItemPtr pScore, pScoreBase, pSrc;
 if (!pScorer) {
  ErrBox("StrokeScorerProcess: pScorer == NULL.");
  return 0;
 }
 pScoreBase = pScorer->m_pScores;
 iCnt = 0;
 for (cp = pScorer->m_cpStrokeDic; *cp; cp = cpNext) {
  iCnt++;
  if (iMaxCnt >= 0 && iCnt > iMaxCnt)
   break;
  cpNext = StrokeScorerEvalItem(pScorer, cp, &iScore);
  for (pScore = pScoreBase+pScorer->m_iScoreLen-1;
    pScore>=pScoreBase; pScore--) {
   if (iScore >= pScore->m_iScore)
    break;
  }
  pScore++;
  if (pScore < (pScoreBase + 5)) {
   if (pScorer->m_iScoreLen < 5)
    pScorer->m_iScoreLen++;
   for (pSrc = pScoreBase+pScorer->m_iScoreLen-2; pSrc >= pScore; pSrc--) {
    pSrc[1].m_iScore = pSrc->m_iScore;
    pSrc[1].m_cp = pSrc->m_cp;
   }
   pScore->m_iScore = iScore;
   pScore->m_cp = cp;
  }
 }
 if (cp)
  return 1;
 else
  return 0;
}

canonical_original_code:
long StrokeScorerProcess(struct StrokeScorerStruct *pScorer, long iMaxCnt) {
 char *cp; char *cpNext;
 unsigned long iScore;
 long iCnt;
 struct ScoreItemStruct *pScore; struct ScoreItemStruct *pScoreBase; struct ScoreItemStruct *pSrc;
 if (!pScorer) {
  ErrBox("StrokeScorerProcess: pScorer == NULL.");
  return 0;
 }
 pScoreBase = pScorer->m_pScores;
 iCnt = 0;
 for (cp = pScorer->m_cpStrokeDic; *cp; cp = cpNext) {
  iCnt++;
  if (iMaxCnt >= 0 && iCnt > iMaxCnt)
   break;
  cpNext = StrokeScorerEvalItem(pScorer, cp, &iScore);
  for (pScore = pScoreBase+pScorer->m_iScoreLen-1;
    pScore>=pScoreBase; pScore--) {
   if (iScore >= pScore->m_iScore)
    break;
  }
  pScore++;
  if (pScore < (pScoreBase + 5)) {
   if (pScorer->m_iScoreLen < 5)
    pScorer->m_iScoreLen++;
   for (pSrc = pScoreBase+pScorer->m_iScoreLen-2; pSrc >= pScore; pSrc--) {
    pSrc[1].m_iScore = pSrc->m_iScore;
    pSrc[1].m_cp = pSrc->m_cp;
   }
   pScore->m_iScore = iScore;
   pScore->m_cp = cp;
  }
 }
 if (cp)
  return 1;
 else
  return 0;
}

variable_types: struct StrokeScorerStruct { char *m_cpStrokeDic; struct RawStroke { unsigned int m_len; unsigned char m_x[256]; unsigned char m_y[256]; } *m_pRawStrokes; unsigned int m_iStrokeCnt; struct ScoreItemStruct { unsigned long m_iScore; char *m_cp; } *m_pScores; unsigned int m_iScoreLen; char *m_cpPath; } *

variable_types: iMaxCnt long

variable_types:
cpNext
char *

variable_types: iCnt long


decompiled_code:
__int64 __fastcall Angle32(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
signed __int64 v3; // r8
signed __int64 v4; // rcx
__int64 result; // rax
__int64 v6; // rax
__int64 v7; // rcx

v2 = (double)(int)a2;
v3 = abs64(a1);
if ( (double)(int)a2 < -0.1 )
a2 = -a2;
if ( v3 <= a2 )
{
v4 = a2;
result = v3;
}
else
{
v4 = v3;
result = a2;
}
if ( result )
{
v6 = 100 * result / v4;
v7 = v6;
if ( v6 > 53 )
{
result = (v6 > 82) + 3LL;
}
else
{
result = 0LL;
if ( v7 > 9 )
result = (v7 > 30) + 1LL;
}
}
else if ( !v4 )
{
return 32LL;
}
if ( v3 > a2 )
result = 8 - result;
if ( v2 < -0.1 )
result = 16 - result;
if ( a1 < 0 )
result = -(int)result & 0x1F;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
signed __int64 v3; // r8
signed __int64 v4; // rcx
__int64 result; // rax
__int64 v6; // rax
__int64 v7; // rcx

v2 = (double)(int)a2;
v3 = abs64(a1);
if ( (double)(int)a2 < -0.1 )
a2 = -a2;
if ( v3 <= a2 )
{
v4 = a2;
result = v3;
}
else
{
v4 = v3;
result = a2;
}
if ( result )
{
v6 = 100 * result / v4;
v7 = v6;
if ( v6 > 53 )
{
result = (v6 > 82) + 3LL;
}
else
{
result = 0LL;
if ( v7 > 9 )
result = (v7 > 30) + 1LL;
}
}
else if ( !v4 )
{
return 32LL;
}
if ( v3 > a2 )
result = 8 - result;
if ( v2 < -0.1 )
result = 16 - result;
if ( a1 < 0 )
result = -(int)result & 0x1F;
return result;
}

original_code:
Long Angle32(Long xdif, Long ydif) {
 Boolean xneg, yneg, xyflip;
 Long i32nd, xtmp, islope;
    if ((xneg = (xdif < 0)))
  xdif = -xdif;
 if ((yneg = (ydif < -0.1)))
  ydif = -ydif;
 if ((xyflip = (ydif < xdif))) {
  xtmp = xdif; xdif = ydif; ydif = xtmp;
 }
    if (xdif == 0) {
  if (ydif == 0)
   return 32;
  else
   i32nd = 0;
 }
    else {
  islope = (100 * xdif) / ydif;
  if (islope < 54) {
   if (islope < 10)
    i32nd = 0;
   else if (islope < 31)
    i32nd = 1;
   else
    i32nd = 2;
  }
  else if (islope < 83)
   i32nd = 3;
  else
   i32nd = 4;
 }
 if (xyflip)
  i32nd = (8 - i32nd);
 if (yneg)
  i32nd = (16 - i32nd);
 if (xneg)
  i32nd = (32 - i32nd);
    return i32nd % 32;
}

canonical_original_code:
long Angle32(long xdif, long ydif) {
 int xneg; int yneg; int xyflip;
 long i32nd; long xtmp; long islope;
    if ((xneg = (xdif < 0)))
  xdif = -xdif;
 if ((yneg = (ydif < -0.1)))
  ydif = -ydif;
 if ((xyflip = (ydif < xdif))) {
  xtmp = xdif; xdif = ydif; ydif = xtmp;
 }
    if (xdif == 0) {
  if (ydif == 0)
   return 32;
  else
   i32nd = 0;
 }
    else {
  islope = (100 * xdif) / ydif;
  if (islope < 54) {
   if (islope < 10)
    i32nd = 0;
   else if (islope < 31)
    i32nd = 1;
   else
    i32nd = 2;
  }
  else if (islope < 83)
   i32nd = 3;
  else
   i32nd = 4;
 }
 if (xyflip)
  i32nd = (8 - i32nd);
 if (yneg)
  i32nd = (16 - i32nd);
 if (xneg)
  i32nd = (32 - i32nd);
    return i32nd % 32;
}

variable_types: xdif long

variable_types: ydif long

variable_types: xneg int

variable_types: yneg int

variable_types: xyflip int

variable_types: xtmp long

variable_types: islope long


ErrBox

decompiled_code:
int __fastcall ErrBox(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void ErrBox(CharPtr msg) {
 fprintf(stderr,"%s\n",msg);
}

canonical_original_code:
void ErrBox(char *msg) {
 fprintf(stderr,"%s\n",msg);
}

variable_types:
msg
char *


AppEmptyList

decompiled_code:
_QWORD *AppEmptyList()
{
_QWORD *result; // rax

result = malloc(0x21uLL);
if ( result )
{
*(_DWORD *)result = 1;
result[1] = result + 2;
result[2] = result + 4;
result[3] = 0LL;
*((_BYTE *)result + 32) = 0;
}
else
{
ErrBox("ERROR: no mem in top picks");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(0x21uLL);
if ( result )
{
*(_DWORD *)result = 1;
result[1] = result + 2;
result[2] = result + 4;
result[3] = 0LL;
*((_BYTE *)result + 32) = 0;
}
else
{
func1("ERROR: no mem in top picks");
result = 0LL;
}
return result;
}

original_code:
ListMem* AppEmptyList() {
 UInt iTotSize;
 ListMem* pListMem;
 CharPtr cpList;
 CharPtr* cppList;
 iTotSize = sizeof(ListMem) + 2 * sizeof(CharPtr) + 1;
 if (!(cpList = malloc(iTotSize))) {
  ErrBox("ERROR: no mem in top picks");
  return ((void *)0);
 }
 pListMem = (ListMem *) cpList;
 cpList += sizeof(ListMem);
 cppList = (CharPtr *) cpList;
 cpList += 2 * sizeof(CharPtr);
 pListMem->m_argc = 1;
 pListMem->m_argv = cppList;
 cppList[0] = cpList;
 cppList[1] = ((void *)0);
 *cpList = '\0';
 return pListMem;
}

canonical_original_code:
struct ListMem *AppEmptyList() {
 unsigned int iTotSize;
 struct ListMem *pListMem;
 char *cpList;
 char **cppList;
 iTotSize = sizeof(ListMem) + 2 * sizeof(CharPtr) + 1;
 if (!(cpList = malloc(iTotSize))) {
  ErrBox("ERROR: no mem in top picks");
  return ((void *)0);
 }
 pListMem = (struct ListMem *) cpList;
 cpList += sizeof(ListMem);
 cppList = (char **) cpList;
 cpList += 2 * sizeof(CharPtr);
 pListMem->m_argc = 1;
 pListMem->m_argv = cppList;
 cppList[0] = cpList;
 cppList[1] = ((void *)0);
 *cpList = '\0';
 return pListMem;
}

variable_types:
iTotSize
unsigned int

variable_types: struct ListMem { unsigned int m_argc; char **m_argv; } *

variable_types:
cpList
char *

variable_types:
cppList
char **


decompiled_code:
int __fastcall ErrBox2(const char *a1, const char *a2)
{
return fprintf(stderr, "%s\n%s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, const char *a2)
{
return fprintf(stderr, "%s\n%s\n", a1, a2);
}

original_code:
void ErrBox2(CharPtr msg1, CharPtr msg2) {
 fprintf(stderr,"%s\n%s\n",msg1,msg2);
}

canonical_original_code:
void ErrBox2(char *msg1, char *msg2) {
 fprintf(stderr,"%s\n%s\n",msg1,msg2);
}


repo: bobozhengsir/wordcount

decompiled_code:
void word_initialize()
{
word_header = 0LL;
}

canonical_decompiled_code:
void func8()
{
word_header = 0LL;
}

original_code:
void word_initialize(void)
{
 word_header = ((void *)0);
}

canonical_original_code:
void word_initialize()
{
 word_header = ((void *)0);
}


decompiled_code:
void *__fastcall my_strdup(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func9(void *src)
{
size_t v1; // r12
void *v2; // rax

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
return memcpy(v2, src, v1);
}

original_code:
static char *my_strdup(char *src)
{
 char *dest;
 dest = malloc(sizeof(char) * (strlen(src) + 1));
 strcpy(dest, src);
 return dest;
}

variable_types:
src
char *

variable_types:
dest
char *


decompiled_code:
void word_finalize()
{
void **i; // rbp
void *v1; // rdi

for ( i = (void **)word_header; word_header; i = (void **)word_header )
{
v1 = *i;
word_header = i[2];
free(v1);
free(i);
}
}

canonical_decompiled_code:
void func12()
{
void **i; // rbp
void *v1; // rdi

for ( i = (void **)word_header; word_header; i = (void **)word_header )
{
v1 = *i;
word_header = i[2];
free(v1);
free(i);
}
}

original_code:
void word_finalize(void)
{
 Word *temp;
 while (word_header != ((void *)0)) {
  temp = word_header;
  word_header = word_header->next;
  free(temp->name);
  free(temp);
 }
}

canonical_original_code:
void word_finalize()
{
 struct Word_tag *temp;
 while (word_header != ((void *)0)) {
  temp = word_header;
  word_header = word_header->next;
  free(temp->name);
  free(temp);
 }
}

variable_types: struct Word_tag { char *name; int count; struct Word_tag *next; } *


check

repo: bobrippling/cbin

decompiled_code:
void __fastcall check(int a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

if ( a1 < 0 )
{
v2 = __errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s(): %s\n", a2, v3);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1, const char *a2)
{
int *v2; // rax
char *v3; // rax

if ( a1 < 0 )
{
v2 = __errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s(): %s\n", a2, v3);
exit(1);
}
}

original_code:
void check(int ret, const char *cmd)
{
 if(ret >= 0)
  return;
 fprintf(stderr, "%s(): %s\n", cmd, strerror((*__errno_location ())));
 exit(1);
}

canonical_original_code:
void check(int ret, char *cmd)
{
 if(ret >= 0)
  return;
 fprintf(stderr, "%s(): %s\n", cmd, strerror((*__errno_location ())));
 exit(1);
}

variable_types: ret int

variable_types:
cmd
char *


writes

decompiled_code:
ssize_t __fastcall writes(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func8(int fd, void *buf)
{
size_t v2; // rax

v2 = strlen((const char *)buf);
return write(fd, buf, v2);
}

original_code:
void writes(int fd, const char *s)
{
 write(fd, s, strlen(s));
}

canonical_original_code:
void writes(int fd, char *s)
{
 write(fd, s, strlen(s));
}

variable_types: fd int

variable_types:
s
char *


decompiled_code:
int __fastcall read_and_print(int *a1, void *a2)
{
ssize_t v2; // r12
int result; // eax
_BYTE v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

writes(1, a2);
v2 = read(*a1, v4, 0x1000uLL);
check(v2, "read");
if ( v2 )
{
write(1, v4, v2);
result = writes(1, "\x1B[m");
}
else
{
result = close(*a1);
*a1 = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int *a1, void *a2)
{
ssize_t v2; // r12
int result; // eax
_BYTE v4[4120]; // [rsp+0h] [rbp-1018h] BYREF

func8(1, a2);
v2 = read(*a1, v4, 0x1000uLL);
func7(v2, "read");
if ( v2 )
{
write(1, v4, v2);
result = func8(1, "\x1B[m");
}
else
{
result = close(*a1);
*a1 = -1;
}
return result;
}

original_code:
void read_and_print(int *fd, const char *colour)
{
 writes(1, colour);
 char buf[4096];
 ssize_t n = read(*fd, buf, sizeof buf);
 check(n, "read");
 if(n == 0){
  close(*fd);
  *fd = -1;
  return;
 }
 write(1, buf, n);
 writes(1, "\x1b[m");
}

canonical_original_code:
void read_and_print(int *fd, char *colour)
{
 writes(1, colour);
 char buf[4096];
 long n = read(*fd, buf, sizeof buf);
 check(n, "read");
 if(n == 0){
  close(*fd);
  *fd = -1;
  return;
 }
 write(1, buf, n);
 writes(1, "\x1b[m");
}

variable_types:
fd
int *

variable_types:
colour
char *

variable_types:
buf
char [4096]

variable_types: n long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rbx
int v6; // edi
int v7; // eax
unsigned int v8; // eax
unsigned int v10; // eax
unsigned int v11; // eax
int v12; // [rsp+0h] [rbp-A8h] BYREF
int fd; // [rsp+4h] [rbp-A4h]
int pipedes[2]; // [rsp+8h] [rbp-A0h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

if ( argc != 1 )
{
v3 = pipe(&v12);
check(v3, "pipe");
v4 = pipe(pipedes);
check(v4, "pipe");
v5 = (unsigned int)fork();
check(v5, "fork");
if ( !(_DWORD)v5 )
{
close(pipedes[0]);
close(v12);
v10 = dup2(pipedes[1], 1);
check(v10, "dup2");
v11 = dup2(fd, 2);
check(v11, "dup2");
close(pipedes[1]);
close(fd);
execvp(argv[1], (char *const *)argv + 1);
check(0xFFFFFFFFLL, "exec");
}
close(fd);
close(pipedes[1]);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v6 = pipedes[0];
if ( pipedes[0] == -1 )
{
v7 = v12;
if ( v12 == -1 )
return 0;
v6 = 0;
}
else
{
readfds.fds_bits[pipedes[0] / 64] |= 1LL << (pipedes[0] % 64);
v7 = v12;
if ( v12 == -1 )
goto LABEL_9;
}
readfds.fds_bits[v7 / 64] |= 1LL << (v7 % 64);
if ( v6 < v7 )
v6 = v7;
LABEL_9:
v8 = select(v6 + 1, &readfds, 0LL, 0LL, 0LL);
check(v8, "select");
if ( (readfds.fds_bits[pipedes[0] / 64] & (1LL << (pipedes[0] % 64))) != 0 )
read_and_print(pipedes, "\x1B[1;34m");
if ( (readfds.fds_bits[v12 / 64] & (1LL << (v12 % 64))) != 0 )
read_and_print(&v12, "\x1B[1;35m");
}
}
fprintf(stderr, "Usage: %s command...\n", *argv);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rbx
int v6; // edi
int v7; // eax
unsigned int v8; // eax
unsigned int v10; // eax
unsigned int v11; // eax
int v12; // [rsp+0h] [rbp-A8h] BYREF
int fd; // [rsp+4h] [rbp-A4h]
int pipedes[2]; // [rsp+8h] [rbp-A0h] BYREF
fd_set readfds; // [rsp+10h] [rbp-98h] BYREF

if ( argc != 1 )
{
v3 = pipe(&v12);
func7(v3, "pipe");
v4 = pipe(pipedes);
func7(v4, "pipe");
v5 = (unsigned int)fork();
func7(v5, "fork");
if ( !(_DWORD)v5 )
{
close(pipedes[0]);
close(v12);
v10 = dup2(pipedes[1], 1);
func7(v10, "dup2");
v11 = dup2(fd, 2);
func7(v11, "dup2");
close(pipedes[1]);
close(fd);
execvp(argv[1], (char *const *)argv + 1);
func7(0xFFFFFFFFLL, "exec");
}
close(fd);
close(pipedes[1]);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v6 = pipedes[0];
if ( pipedes[0] == -1 )
{
v7 = v12;
if ( v12 == -1 )
return 0;
v6 = 0;
}
else
{
readfds.fds_bits[pipedes[0] / 64] |= 1LL << (pipedes[0] % 64);
v7 = v12;
if ( v12 == -1 )
goto LABEL_9;
}
readfds.fds_bits[v7 / 64] |= 1LL << (v7 % 64);
if ( v6 < v7 )
v6 = v7;
LABEL_9:
v8 = select(v6 + 1, &readfds, 0LL, 0LL, 0LL);
func7(v8, "select");
if ( (readfds.fds_bits[pipedes[0] / 64] & (1LL << (pipedes[0] % 64))) != 0 )
func9(pipedes, "\x1B[1;34m");
if ( (readfds.fds_bits[v12 / 64] & (1LL << (v12 % 64))) != 0 )
func9(&v12, "\x1B[1;35m");
}
}
fprintf(stderr, "Usage: %s command...\n", *argv);
return 1;
}

original_code:
int main(int argc, char *argv[])
{
 if(argc == 1){
  fprintf(stderr, "Usage: %s command...\n", *argv);
  return 1;
 }
 enum { read_i = 0, write_i = 1 };
 int child_err[2], child_out[2];
 check(pipe(child_err), "pipe");
 check(pipe(child_out), "pipe");
 long pid = fork();
 check(pid, "fork");
 if(pid == 0){
  close(child_out[read_i]);
  close(child_err[read_i]);
  check(dup2(child_out[write_i], 1), "dup2");
  check(dup2(child_err[write_i], 2), "dup2");
  close(child_out[write_i]);
  close(child_err[write_i]);
  execvp(argv[1], argv + 1);
  check(-1, "exec");
 }
 close(child_err[write_i]);
 close(child_out[write_i]);
 for(;;){
  fd_set fds;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  if(child_out[read_i] == -1
  && child_err[read_i] == -1)
  {
   break;
  }
  int maxfd = 0;
  if(child_out[read_i] != -1){
   ((void) (((&fds)->__fds_bits)[((child_out[read_i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((child_out[read_i]) % (8 * (int) sizeof (__fd_mask)))))));
   maxfd = child_out[read_i];
  }
  if(child_err[read_i] != -1){
   ((void) (((&fds)->__fds_bits)[((child_err[read_i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((child_err[read_i]) % (8 * (int) sizeof (__fd_mask)))))));
   if(child_err[read_i] > maxfd)
    maxfd = child_err[read_i];
  }
  check(select(maxfd + 1, &fds, ((void *)0), ((void *)0), ((void *)0)), "select");
  if(((((&fds)->__fds_bits)[((child_out[read_i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((child_out[read_i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
   read_and_print(&child_out[read_i], "\x1b[1;34m");
  }
  if(((((&fds)->__fds_bits)[((child_err[read_i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((child_err[read_i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
   read_and_print(&child_err[read_i], "\x1b[1;35m");
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(argc == 1){
  fprintf(stderr, "Usage: %s command...\n", *argv);
  return 1;
 }
 enum { read_i = 0, write_i = 1 };
 int child_err[2]; int child_out[2];
 check(pipe(child_err), "pipe");
 check(pipe(child_out), "pipe");
 long pid = fork();
 check(pid, "fork");
 if(pid == 0){
  close(child_out[read_i]);
  close(child_err[read_i]);
  check(dup2(child_out[write_i], 1), "dup2");
  check(dup2(child_err[write_i], 2), "dup2");
  close(child_out[write_i]);
  close(child_err[write_i]);
  execvp(argv[1], argv + 1);
  check(-1, "exec");
 }
 close(child_err[write_i]);
 close(child_out[write_i]);
 for(;;){
  struct fd_set fds;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  if(child_out[read_i] == -1
  && child_err[read_i] == -1)
  {
   break;
  }
  int maxfd = 0;
  if(child_out[read_i] != -1){
   ((void) (((&fds)->__fds_bits)[((child_out[read_i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((child_out[read_i]) % (8 * (int) sizeof (__fd_mask)))))));
   maxfd = child_out[read_i];
  }
  if(child_err[read_i] != -1){
   ((void) (((&fds)->__fds_bits)[((child_err[read_i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((child_err[read_i]) % (8 * (int) sizeof (__fd_mask)))))));
   if(child_err[read_i] > maxfd)
    maxfd = child_err[read_i];
  }
  check(select(maxfd + 1, &fds, ((void *)0), ((void *)0), ((void *)0)), "select");
  if(((((&fds)->__fds_bits)[((child_out[read_i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((child_out[read_i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
   read_and_print(&child_out[read_i], "\x1b[1;34m");
  }
  if(((((&fds)->__fds_bits)[((child_err[read_i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((child_err[read_i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)){
   read_and_print(&child_err[read_i], "\x1b[1;35m");
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: pid long

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

variable_types: maxfd int


decompiled_code:
size_t __fastcall rot13(char *s)
{
unsigned int v1; // ebx
size_t result; // rax
unsigned __int64 v3; // r13
int v4; // eax
char v5; // dl
const unsigned __int16 **v6; // rax
char *v7; // r12
__int64 v8; // rcx
const unsigned __int16 *v9; // rdx
unsigned __int16 v10; // dx

v1 = 0;
result = strlen(s);
v3 = result;
while ( v3 > v1 )
{
v6 = __ctype_b_loc();
v7 = &s[v1];
v8 = *v7;
v9 = *v6;
result = v8;
v10 = v9[v8];
if ( (v10 & 0x400) != 0 )
{
if ( (v10 & 0x100) != 0 )
{
v4 = ((int)v8 - 52) % 26;
v5 = 65;
}
else
{
v4 = ((int)v8 - 84) % 26;
v5 = 97;
}
*v7 = v5 + v4;
result = strlen(s);
v3 = result;
}
++v1;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(char *s)
{
unsigned int v1; // ebx
size_t result; // rax
unsigned __int64 v3; // r13
int v4; // eax
char v5; // dl
const unsigned __int16 **v6; // rax
char *v7; // r12
__int64 v8; // rcx
const unsigned __int16 *v9; // rdx
unsigned __int16 v10; // dx

v1 = 0;
result = strlen(s);
v3 = result;
while ( v3 > v1 )
{
v6 = __ctype_b_loc();
v7 = &s[v1];
v8 = *v7;
v9 = *v6;
result = v8;
v10 = v9[v8];
if ( (v10 & 0x400) != 0 )
{
if ( (v10 & 0x100) != 0 )
{
v4 = ((int)v8 - 52) % 26;
v5 = 65;
}
else
{
v4 = ((int)v8 - 84) % 26;
v5 = 97;
}
*v7 = v5 + v4;
result = strlen(s);
v3 = result;
}
++v1;
}
return result;
}

original_code:
void rot13(char *arg)
{
  unsigned int i;
  for(i = 0; i < strlen(arg); i++)
    if(((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short int) _ISalpha))
      arg[i] = (arg[i] - (((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short int) _ISupper) ? 'A' : 'a') + 13) % 26 + (((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short int) _ISupper) ? 'A' : 'a');
}

canonical_original_code:
void rot13(char *arg)
{
  unsigned int i;
  for(i = 0; i < strlen(arg); i++)
    if(((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short) _ISalpha))
      arg[i] = (arg[i] - (((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short) _ISupper) ? 'A' : 'a') + 13) % 26 + (((*__ctype_b_loc ())[(int) ((arg[i]))] & (unsigned short) _ISupper) ? 'A' : 'a');
}

variable_types:
arg
char *

variable_types:
i
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rbp
char *v5; // rdi
int result; // eax
char *s; // [rsp+0h] [rbp-28h] BYREF
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 1 )
{
for ( s = 0LL; (unsigned int)getline(&s, n, stdin) != -1; fputs(s, stdout) )
rot13(s);
result = ferror(stdin);
if ( result )
{
perror("stdin");
result = 1;
}
}
else
{
if ( argc > 1 )
{
v3 = (char **)(argv + 1);
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
rot13(v5);
printf("%s ", *(v3 - 1));
}
while ( v3 != (char **)v4 );
}
putchar(10);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rbp
char *v5; // rdi
int result; // eax
char *s; // [rsp+0h] [rbp-28h] BYREF
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc == 1 )
{
for ( s = 0LL; (unsigned int)getline(&s, n, stdin) != -1; fputs(s, stdout) )
func7(s);
result = ferror(stdin);
if ( result )
{
perror("stdin");
result = 1;
}
}
else
{
if ( argc > 1 )
{
v3 = (char **)(argv + 1);
v4 = &argv[(unsigned int)(argc - 2) + 2];
do
{
v5 = *v3++;
func7(v5);
printf("%s ", *(v3 - 1));
}
while ( v3 != (char **)v4 );
}
putchar(10);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
  int i, ret = 0;
  if(argc == 1){
    char *s = ((void *)0);
    size_t nread;
    while(getline(&s, &nread, stdin) != -1){
      rot13(s);
      fputs(s, stdout);
    }
    if(ferror(stdin)){
      perror("stdin");
      ret = 1;
    }
  }else{
    for(i = 1; i < argc; i++){
      rot13(argv[i]);
      printf("%s ", argv[i]);
    }
    putchar('\n');
  }
  return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i; int ret = 0;
  if(argc == 1){
    char *s = ((void *)0);
    unsigned long nread;
    while(getline(&s, &nread, stdin) != -1){
      rot13(s);
      fputs(s, stdout);
    }
    if(ferror(stdin)){
      perror("stdin");
      ret = 1;
    }
  }else{
    for(i = 1; i < argc; i++){
      rot13(argv[i]);
      printf("%s ", argv[i]);
    }
    putchar('\n');
  }
  return ret;
}

variable_types:
argv
char **

variable_types: i int

variable_types:
nread
unsigned long


winch

decompiled_code:
void winch()
{
gotwinch = 1;
__sysv_signal(28, winch);
}

canonical_decompiled_code:
void func7()
{
gotwinch = 1;
__sysv_signal(28, winch);
}

original_code:
void winch(int sig)
{
 (void)sig;
 gotwinch = 1;
 signal(28, winch);
}

variable_types: sig int


decompiled_code:
__int64 get_term_size()
{
__int64 result; // rax
char v1[2]; // [rsp+8h] [rbp-10h] BYREF
unsigned __int16 v2; // [rsp+Ah] [rbp-Eh]

if ( ioctl(term_fd, 0x5413uLL, v1) == -1 )
{
perror("ioctl");
result = 1LL;
}
else
{
max = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
char v1[2]; // [rsp+8h] [rbp-10h] BYREF
unsigned __int16 v2; // [rsp+Ah] [rbp-Eh]

if ( ioctl(term_fd, 0x5413uLL, v1) == -1 )
{
perror("ioctl");
result = 1LL;
}
else
{
max = v2;
result = 0LL;
}
return result;
}

original_code:
int get_term_size()
{
 struct winsize ts;
 if(ioctl(term_fd, 0x5413, &ts) == -1){
  perror("ioctl");
  return 1;
 }
 max = ts.ws_col;
 return 0;
}

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


getsinglechar

decompiled_code:
__int64 getsinglechar()
{
int v0; // eax
unsigned int v1; // er12

v0 = getchar();
v1 = v0;
do
{
if ( v0 == 10 )
break;
v0 = getchar();
}
while ( v0 != -1 );
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
unsigned int v1; // er12

v0 = getchar();
v1 = v0;
do
{
if ( v0 == 10 )
break;
v0 = getchar();
}
while ( v0 != -1 );
return v1;
}

original_code:
static int getsinglechar(void)
{
 int c = getchar();
 if(c != '\n'){
  int tmp;
  do
   tmp = getchar();
  while(tmp != (-1) && tmp != '\n');
 }
 return c;
}

canonical_original_code:
static int getsinglechar()
{
 int c = getchar();
 if(c != '\n'){
  int tmp;
  do
   tmp = getchar();
  while(tmp != (-1) && tmp != '\n');
 }
 return c;
}

variable_types: c int

variable_types: tmp int


yesno

decompiled_code:
_BOOL8 yesno()
{
char v0; // bl
_BOOL8 result; // rax

v0 = getsinglechar();
result = 1LL;
if ( v0 != 10 )
result = (*__ctype_tolower_loc())[v0] == 121;
return result;
}

canonical_decompiled_code:
_BOOL8 func8()
{
char v0; // bl
_BOOL8 result; // rax

v0 = func7();
result = 1LL;
if ( v0 != 10 )
result = (*__ctype_tolower_loc())[v0] == 121;
return result;
}

original_code:
static int yesno(void)
{
 char c = getsinglechar();
 if(c == '\n' || tolower(c) == 'y')
  return 1;
 return 0;
}

canonical_original_code:
static int yesno()
{
 char c = getsinglechar();
 if(c == '\n' || tolower(c) == 'y')
  return 1;
 return 0;
}

variable_types: c char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char *v4; // rcx
int v6; // eax
char v7; // r8
char v8; // r10
int v9; // er9
int v10; // edi
__int64 v11; // rbx
char *v12; // rdi

v3 = argv;
if ( argc <= 1 )
goto LABEL_35;
v4 = argv[1];
v6 = 1;
if ( *v4 != 45 )
goto LABEL_13;
argv += 2;
v7 = 0;
v8 = 0;
v6 = 1;
v9 = prompt;
v10 = append;
while ( 1 )
{
envp = (const char **)*((unsigned __int8 *)v4 + 1);
if ( (_BYTE)envp != 102 )
break;
if ( !v9 )
{
if ( v8 )
prompt = 0;
LABEL_33:
if ( v7 )
append = v10;
LABEL_35:
usage(*v3, argv, envp);
}
v8 = 1;
v9 = 0;
LABEL_26:
v4 = *argv;
++v6;
++argv;
v10 = 1;
v7 = 1;
if ( *v4 != 45 )
{
if ( v8 )
prompt = v9;
append = 1;
goto LABEL_12;
}
}
if ( (_BYTE)envp == 110 )
{
if ( v10 )
{
if ( v8 )
prompt = v9;
goto LABEL_33;
}
goto LABEL_26;
}
if ( (_BYTE)envp != 45 )
{
if ( v8 )
prompt = v9;
if ( v7 )
append = v10;
++v6;
goto LABEL_12;
}
if ( v8 )
prompt = v9;
if ( v7 )
append = v10;
if ( *v4 == 45 && v4[1] == 45 )
{
v6 += v4[2] == 0;
if ( argc <= v6 )
{
LABEL_23:
fwrite("No input files\n", 1uLL, 0xFuLL, stderr);
return 0;
}
}
else
{
LABEL_12:
if ( argc <= v6 )
goto LABEL_23;
}
LABEL_13:
v11 = v6;
do
{
v12 = (char *)v3[v11++];
checkfile(v12);
}
while ( argc > (int)v11 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r12
const char *v4; // rcx
int v6; // eax
char v7; // r8
char v8; // r10
int v9; // er9
int v10; // edi
__int64 v11; // rbx
char *v12; // rdi

v3 = argv;
if ( argc <= 1 )
goto LABEL_35;
v4 = argv[1];
v6 = 1;
if ( *v4 != 45 )
goto LABEL_13;
argv += 2;
v7 = 0;
v8 = 0;
v6 = 1;
v9 = prompt;
v10 = append;
while ( 1 )
{
envp = (const char **)*((unsigned __int8 *)v4 + 1);
if ( (_BYTE)envp != 102 )
break;
if ( !v9 )
{
if ( v8 )
prompt = 0;
LABEL_33:
if ( v7 )
append = v10;
LABEL_35:
func10(*v3, argv, envp);
}
v8 = 1;
v9 = 0;
LABEL_26:
v4 = *argv;
++v6;
++argv;
v10 = 1;
v7 = 1;
if ( *v4 != 45 )
{
if ( v8 )
prompt = v9;
append = 1;
goto LABEL_12;
}
}
if ( (_BYTE)envp == 110 )
{
if ( v10 )
{
if ( v8 )
prompt = v9;
goto LABEL_33;
}
goto LABEL_26;
}
if ( (_BYTE)envp != 45 )
{
if ( v8 )
prompt = v9;
if ( v7 )
append = v10;
++v6;
goto LABEL_12;
}
if ( v8 )
prompt = v9;
if ( v7 )
append = v10;
if ( *v4 == 45 && v4[1] == 45 )
{
v6 += v4[2] == 0;
if ( argc <= v6 )
{
LABEL_23:
fwrite("No input files\n", 1uLL, 0xFuLL, stderr);
return 0;
}
}
else
{
LABEL_12:
if ( argc <= v6 )
goto LABEL_23;
}
LABEL_13:
v11 = v6;
do
{
v12 = (char *)v3[v11++];
func9(v12);
}
while ( argc > (int)v11 );
return 0;
}

original_code:
int main(int argc, char **argv)
{
 if(argc > 1){
  int i = 1, processargs = 1;
  while(processargs && argv[i][0] == '-'){
   switch(argv[i][1]){
    case 'f':
     if(!prompt)
      usage(argv[0]);
     prompt = 0;
     append = 0;
    case 'n':
     if(append)
      usage(argv[0]);
     append = 1;
     break;
    case '-':
     if(strcmp(argv[i], "--"))
      i--;
    default:
     processargs = 0;
     break;
   }
   i++;
  }
  if(i >= argc)
   fputs("No input files\n", stderr);
  else
   while(i < argc)
    checkfile(argv[i++]);
 }else{
  usage(argv[0]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(argc > 1){
  int i = 1; int processargs = 1;
  while(processargs && argv[i][0] == '-'){
   switch(argv[i][1]){
    case 'f':
     if(!prompt)
      usage(argv[0]);
     prompt = 0;
     append = 0;
    case 'n':
     if(append)
      usage(argv[0]);
     append = 1;
     break;
    case '-':
     if(strcmp(argv[i], "--"))
      i--;
    default:
     processargs = 0;
     break;
   }
   i++;
  }
  if(i >= argc)
   fputs("No input files\n", stderr);
  else
   while(i < argc)
    checkfile(argv[i++]);
 }else{
  usage(argv[0]);
 }
 return 0;
}

variable_types: processargs int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [options] FILE(S)\n", a1);
fwrite("options can be:\n", 1uLL, 0x10uLL, stderr);
fwrite("\t-n: Ask to add a new line\n", 1uLL, 0x1BuLL, stderr);
fwrite("\t-f: Don't prompt - just add a newline\n", 1uLL, 0x27uLL, stderr);
fwrite("\t\t(Implies -n)\n", 1uLL, 0xFuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1)
{
fprintf(stderr, "Usage: %s [options] FILE(S)\n", a1);
fwrite("options can be:\n", 1uLL, 0x10uLL, stderr);
fwrite("\t-n: Ask to add a new line\n", 1uLL, 0x1BuLL, stderr);
fwrite("\t-f: Don't prompt - just add a newline\n", 1uLL, 0x27uLL, stderr);
fwrite("\t\t(Implies -n)\n", 1uLL, 0xFuLL, stderr);
exit(1);
}

original_code:
static void usage(char *progname)
{
 fprintf(stderr, "Usage: %s [options] FILE(S)\n", progname);
 fputs("options can be:\n", stderr);
 fputs("	-n: Ask to add a new line\n", stderr);
 fputs("	-f: Don't prompt - just add a newline\n", stderr);
 fputs("		(Implies -n)\n", stderr);
 exit(1);
}

variable_types:
progname
char *


strike

decompiled_code:
wint_t __fastcall strike(char a1)
{
wint_t result; // eax

if ( a1 == 10 )
result = putwchar(10);
else
result = printf("%lc%lc", a1, 822);
return result;
}

canonical_decompiled_code:
wint_t __fastcall func7(char a1)
{
wint_t result; // eax

if ( a1 == 10 )
result = putwchar(10);
else
result = printf("%lc%lc", a1, 822);
return result;
}

original_code:
void strike(char c)
{
 if(c == '\n')
  putwchar('\n');
 else
  printf("%lc%lc", (int16_t)c, (int16_t)0x336);
}

canonical_original_code:
void strike(char c)
{
 if(c == '\n')
  putwchar('\n');
 else
  printf("%lc%lc", (short)c, (short)0x336);
}


wide

decompiled_code:
int __fastcall wide(char a1)
{
int v2; // esi

if ( (unsigned __int8)(a1 - 33) <= 0x5Du )
return printf("%lc", a1 + 65248);
v2 = a1;
if ( a1 == 32 )
v2 = 12288;
return printf("%lc", v2);
}

canonical_decompiled_code:
int __fastcall func8(char a1)
{
int v2; // esi

if ( (unsigned __int8)(a1 - 33) <= 0x5Du )
return printf("%lc", a1 + 65248);
v2 = a1;
if ( a1 == 32 )
v2 = 12288;
return printf("%lc", v2);
}


flip

decompiled_code:
wint_t __fastcall flip(char a1)
{
wint_t result; // eax

switch ( a1 )
{
case '!':
goto LABEL_23;
case '\'':
goto LABEL_9;
case '(':
goto LABEL_3;
case ')':
putchar(40);
LABEL_3:
putchar(41);
goto LABEL_4;
case ',':
goto LABEL_8;
case '.':
goto LABEL_38;
case '6':
goto LABEL_11;
case '9':
goto LABEL_10;
case ';':
goto LABEL_40;
case '?':
goto LABEL_24;
case '[':
goto LABEL_5;
case ']':
LABEL_4:
putchar(91);
LABEL_5:
putchar(93);
goto LABEL_6;
case '_':
goto LABEL_42;
case 'a':
goto LABEL_27;
case 'b':
goto LABEL_18;
case 'c':
goto LABEL_28;
case 'd':
goto LABEL_17;
case 'e':
goto LABEL_26;
case 'f':
goto LABEL_29;
case 'g':
goto LABEL_12;
case 'h':
goto LABEL_30;
case 'i':
goto LABEL_25;
case 'j':
goto LABEL_41;
case 'k':
goto LABEL_37;
case 'l':
goto LABEL_39;
case 'm':
goto LABEL_31;
case 'n':
goto LABEL_20;
case 'o':
goto LABEL_16;
case 'p':
goto LABEL_14;
case 'q':
goto LABEL_13;
case 'r':
goto LABEL_32;
case 's':
goto LABEL_19;
case 't':
goto LABEL_33;
case 'u':
goto LABEL_15;
case 'v':
goto LABEL_34;
case 'w':
goto LABEL_35;
case 'x':
goto LABEL_21;
case 'y':
goto LABEL_36;
case 'z':
goto LABEL_22;
case '{':
goto LABEL_7;
case '}':
LABEL_6:
putchar(123);
LABEL_7:
putchar(125);
LABEL_8:
putchar(39);
LABEL_9:
putchar(44);
LABEL_10:
putchar(54);
LABEL_11:
putchar(57);
LABEL_12:
putchar(98);
LABEL_13:
putchar(98);
LABEL_14:
putchar(100);
LABEL_15:
putchar(110);
LABEL_16:
putchar(111);
LABEL_17:
putchar(112);
LABEL_18:
putchar(113);
LABEL_19:
putchar(115);
LABEL_20:
putchar(117);
LABEL_21:
putchar(120);
LABEL_22:
putchar(122);
putchar(63);
LABEL_23:
putwchar(161);
LABEL_24:
putwchar(191);
LABEL_25:
putwchar(305);
LABEL_26:
putwchar(477);
LABEL_27:
putwchar(592);
LABEL_28:
putwchar(596);
LABEL_29:
putwchar(607);
LABEL_30:
putwchar(613);
LABEL_31:
putwchar(623);
LABEL_32:
putwchar(633);
LABEL_33:
putwchar(647);
LABEL_34:
putwchar(652);
LABEL_35:
putwchar(653);
LABEL_36:
putwchar(654);
LABEL_37:
putwchar(670);
LABEL_38:
putwchar(729);
LABEL_39:
putwchar(1503);
LABEL_40:
putwchar(1563);
LABEL_41:
putwchar(1592);
LABEL_42:
result = putwchar(8254);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
wint_t __fastcall func9(char a1)
{
wint_t result; // eax

switch ( a1 )
{
case '!':
goto LABEL_23;
case '\'':
goto LABEL_9;
case '(':
goto LABEL_3;
case ')':
putchar(40);
LABEL_3:
putchar(41);
goto LABEL_4;
case ',':
goto LABEL_8;
case '.':
goto LABEL_38;
case '6':
goto LABEL_11;
case '9':
goto LABEL_10;
case ';':
goto LABEL_40;
case '?':
goto LABEL_24;
case '[':
goto LABEL_5;
case ']':
LABEL_4:
putchar(91);
LABEL_5:
putchar(93);
goto LABEL_6;
case '_':
goto LABEL_42;
case 'a':
goto LABEL_27;
case 'b':
goto LABEL_18;
case 'c':
goto LABEL_28;
case 'd':
goto LABEL_17;
case 'e':
goto LABEL_26;
case 'f':
goto LABEL_29;
case 'g':
goto LABEL_12;
case 'h':
goto LABEL_30;
case 'i':
goto LABEL_25;
case 'j':
goto LABEL_41;
case 'k':
goto LABEL_37;
case 'l':
goto LABEL_39;
case 'm':
goto LABEL_31;
case 'n':
goto LABEL_20;
case 'o':
goto LABEL_16;
case 'p':
goto LABEL_14;
case 'q':
goto LABEL_13;
case 'r':
goto LABEL_32;
case 's':
goto LABEL_19;
case 't':
goto LABEL_33;
case 'u':
goto LABEL_15;
case 'v':
goto LABEL_34;
case 'w':
goto LABEL_35;
case 'x':
goto LABEL_21;
case 'y':
goto LABEL_36;
case 'z':
goto LABEL_22;
case '{':
goto LABEL_7;
case '}':
LABEL_6:
putchar(123);
LABEL_7:
putchar(125);
LABEL_8:
putchar(39);
LABEL_9:
putchar(44);
LABEL_10:
putchar(54);
LABEL_11:
putchar(57);
LABEL_12:
putchar(98);
LABEL_13:
putchar(98);
LABEL_14:
putchar(100);
LABEL_15:
putchar(110);
LABEL_16:
putchar(111);
LABEL_17:
putchar(112);
LABEL_18:
putchar(113);
LABEL_19:
putchar(115);
LABEL_20:
putchar(117);
LABEL_21:
putchar(120);
LABEL_22:
putchar(122);
putchar(63);
LABEL_23:
putwchar(161);
LABEL_24:
putwchar(191);
LABEL_25:
putwchar(305);
LABEL_26:
putwchar(477);
LABEL_27:
putwchar(592);
LABEL_28:
putwchar(596);
LABEL_29:
putwchar(607);
LABEL_30:
putwchar(613);
LABEL_31:
putwchar(623);
LABEL_32:
putwchar(633);
LABEL_33:
putwchar(647);
LABEL_34:
putwchar(652);
LABEL_35:
putwchar(653);
LABEL_36:
putwchar(654);
LABEL_37:
putwchar(670);
LABEL_38:
putwchar(729);
LABEL_39:
putwchar(1503);
LABEL_40:
putwchar(1563);
LABEL_41:
putwchar(1592);
LABEL_42:
result = putwchar(8254);
break;
default:
return result;
}
return result;
}

original_code:
void flip(char c)
{
 switch((wchar_t)c){
  case ')': putchar('(');
  case '(': putchar(')');
  case ']': putchar('[');
  case '[': putchar(']');
  case '}': putchar('{');
  case '{': putchar('}');
  case ',': putchar('\'');
  case '\'': putchar(',');
  case '9': putchar('6');
  case '6': putchar('9');
  case 'g': putchar('b');
  case 'q': putchar('b');
  case 'p': putchar('d');
  case 'u': putchar('n');
  case 'o': putchar('o');
  case 'd': putchar('p');
  case 'b': putchar('q');
  case 's': putchar('s');
  case 'n': putchar('u');
  case 'x': putchar('x');
  case 'z': putchar('z');
  case L'\u00BF': putchar('?');
  case '!': putwchar(L'\u00A1');
  case '?': putwchar(L'\u00BF');
  case 'i': putwchar(L'\u0131' );
  case 'e': putwchar(L'\u01DD');
  case 'a': putwchar(L'\u0250');
  case 'c': putwchar(L'\u0254');
  case 'f': putwchar(L'\u025F');
  case 'h': putwchar(L'\u0265');
  case 'm': putwchar(L'\u026F');
  case 'r': putwchar(L'\u0279');
  case 't': putwchar(L'\u0287');
  case 'v': putwchar(L'\u028C');
  case 'w': putwchar(L'\u028D');
  case 'y': putwchar(L'\u028E');
  case 'k': putwchar(L'\u029E');
  case '.': putwchar(L'\u02D9');
  case 'l': putwchar(L'\u05DF');
  case ';': putwchar(L'\u061B');
  case 'j': putwchar(L'\u0638');
  case '_': putwchar(L'\u203E');
 }
}

canonical_original_code:
void flip(char c)
{
 switch((int)c){
  case ')': putchar('(');
  case '(': putchar(')');
  case ']': putchar('[');
  case '[': putchar(']');
  case '}': putchar('{');
  case '{': putchar('}');
  case ',': putchar('\'');
  case '\'': putchar(',');
  case '9': putchar('6');
  case '6': putchar('9');
  case 'g': putchar('b');
  case 'q': putchar('b');
  case 'p': putchar('d');
  case 'u': putchar('n');
  case 'o': putchar('o');
  case 'd': putchar('p');
  case 'b': putchar('q');
  case 's': putchar('s');
  case 'n': putchar('u');
  case 'x': putchar('x');
  case 'z': putchar('z');
  case L'\u00BF': putchar('?');
  case '!': putwchar(L'\u00A1');
  case '?': putwchar(L'\u00BF');
  case 'i': putwchar(L'\u0131' );
  case 'e': putwchar(L'\u01DD');
  case 'a': putwchar(L'\u0250');
  case 'c': putwchar(L'\u0254');
  case 'f': putwchar(L'\u025F');
  case 'h': putwchar(L'\u0265');
  case 'm': putwchar(L'\u026F');
  case 'r': putwchar(L'\u0279');
  case 't': putwchar(L'\u0287');
  case 'v': putwchar(L'\u028C');
  case 'w': putwchar(L'\u028D');
  case 'y': putwchar(L'\u028E');
  case 'k': putwchar(L'\u029E');
  case '.': putwchar(L'\u02D9');
  case 'l': putwchar(L'\u05DF');
  case ';': putwchar(L'\u061B');
  case 'j': putwchar(L'\u0638');
  case '_': putwchar(L'\u203E');
 }
}


perrorf

decompiled_code:
void perrorf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: ", (const char *)program_invocation_short_name);
vfprintf(stderr, format, arg);
fwrite(": ", 1uLL, 2uLL, stderr);
perror(0LL);
}

canonical_decompiled_code:
void func11(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: ", (const char *)program_invocation_short_name);
vfprintf(stderr, format, arg);
fwrite(": ", 1uLL, 2uLL, stderr);
perror(0LL);
}

original_code:
void perrorf(const char *fmt, ...)
{
 va_list l;
 extern const char *__progname;
 fprintf(stderr, "%s: ", __progname);
 __builtin_va_start(l,fmt);
 vfprintf(stderr, fmt, l);
 __builtin_va_end(l);
 fputs(": ", stderr);
 perror(((void *)0));
}

canonical_original_code:
void perrorf(char *fmt, ...)
{
 __builtin_va_list l;
 extern char *__progname;
 fprintf(stderr, "%s: ", __progname);
 __builtin_va_start(l,fmt);
 vfprintf(stderr, fmt, l);
 __builtin_va_end(l);
 fputs(": ", stderr);
 perror(((void *)0));
}

variable_types:
fmt
char *


randsaltchar

decompiled_code:
__int64 randsaltchar()
{
int v0; // eax

v0 = rand() % 64;
if ( v0 <= 25 )
return (unsigned int)(v0 + 97);
if ( v0 <= 51 )
return (unsigned int)(v0 + 65);
if ( v0 > 61 )
return 47 - (unsigned int)(v0 != 62);
return (unsigned int)(v0 + 48);
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax

v0 = rand() % 64;
if ( v0 <= 25 )
return (unsigned int)(v0 + 97);
if ( v0 <= 51 )
return (unsigned int)(v0 + 65);
if ( v0 > 61 )
return 47 - (unsigned int)(v0 != 62);
return (unsigned int)(v0 + 48);
}

original_code:
char randsaltchar(void)
{
 int r = rand() % (26 * 2 + 10 + 2);
 if(r < 26)
  return r + 'a';
 else if(r < 26 * 2)
  return r + 'A';
 else if(r < 26 * 2 + 10)
  return r + '0';
 else
  return r % 2 ? '.' : '/';
}

canonical_original_code:
char randsaltchar()
{
 int r = rand() % (26 * 2 + 10 + 2);
 if(r < 26)
  return r + 'a';
 else if(r < 26 * 2)
  return r + 'A';
 else if(r < 26 * 2 + 10)
  return r + '0';
 else
  return r % 2 ? '.' : '/';
}

variable_types: r int

return_type: char


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"Usage: %s [OPTIONS] [FILES...]\n",
"\n"
"Options:\n"
" -c: Verify entered password with entered crypt-string\n"
" Takes two lines - password, followed by crypt-string\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func10()
{
fprintf(
stderr,
"Usage: %s [OPTIONS] [FILES...]\n",
"\n"
"Options:\n"
" -c: Verify entered password with entered crypt-string\n"
" Takes two lines - password, followed by crypt-string\n");
exit(1);
}

original_code:
void usage(void)
{
 fprintf(stderr,
   "Usage: %s [OPTIONS] [FILES...]\n",
   "\n"
   "Options:\n"
   " -c: Verify entered password with entered crypt-string\n"
   "     Takes two lines - password, followed by crypt-string\n"
   , progname);
 exit(1);
}

canonical_original_code:
void usage()
{
 fprintf(stderr,
   "Usage: %s [OPTIONS] [FILES...]\n",
   "\n"
   "Options:\n"
   " -c: Verify entered password with entered crypt-string\n"
   "     Takes two lines - password, followed by crypt-string\n"
   , progname);
 exit(1);
}


fin

decompiled_code:
void __fastcall __noreturn fin(int a1)
{
if ( tcsetattr(0, 0, &origattr) )
perror("(restore) tcsetattr()");
exit(a1 + 128);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1)
{
if ( tcsetattr(0, 0, &origattr) )
perror("(restore) tcsetattr()");
exit(a1 + 128);
}

original_code:
void fin(int sig)
{
 if(tcsetattr(0, 0, &origattr))
  perror("(restore) tcsetattr()");
 exit(128 + sig);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct termios *v5; // rdi
__int64 v6; // rcx
struct termios *v7; // rsi
__int64 i; // r13
int v10; // er12
char buf; // [rsp+Fh] [rbp-69h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-68h] BYREF

if ( isatty(0) )
{
if ( tcgetattr(0, &termios_p) )
{
perror("tcgetattr()");
}
else
{
v5 = &origattr;
v6 = 15LL;
v7 = &termios_p;
while ( v6 )
{
v5->c_iflag = v7->c_iflag;
v7 = (struct termios *)((char *)v7 + 4);
v5 = (struct termios *)((char *)v5 + 4);
--v6;
}
__sysv_signal(2, fin);
__sysv_signal(1, fin);
__sysv_signal(15, fin);
__sysv_signal(3, fin);
termios_p.c_lflag &= 0xFFFFFFF7;
if ( !tcsetattr(0, 0, &termios_p) )
{
if ( argc == 1 )
{
while ( read(0, &buf, 1uLL) > 0 )
write(1, &buf, 1uLL);
}
else
{
for ( i = 1LL; argc > (int)i; ++i )
{
v10 = open(argv[i], 0);
if ( v10 == -1 )
{
perror(argv[i]);
}
else
{
while ( read(v10, &buf, 1uLL) > 0 )
write(1, &buf, 1uLL);
close(v10);
}
}
}
fin(-128);
}
perror("tcsetattr()");
}
}
else
{
fwrite("stdin not a tty\n", 1uLL, 0x10uLL, _bss_start);
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct termios *v5; // rdi
__int64 v6; // rcx
struct termios *v7; // rsi
__int64 i; // r13
int v10; // er12
char buf; // [rsp+Fh] [rbp-69h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-68h] BYREF

if ( isatty(0) )
{
if ( tcgetattr(0, &termios_p) )
{
perror("tcgetattr()");
}
else
{
v5 = &origattr;
v6 = 15LL;
v7 = &termios_p;
while ( v6 )
{
v5->c_iflag = v7->c_iflag;
v7 = (struct termios *)((char *)v7 + 4);
v5 = (struct termios *)((char *)v5 + 4);
--v6;
}
__sysv_signal(2, fin);
__sysv_signal(1, fin);
__sysv_signal(15, fin);
__sysv_signal(3, fin);
termios_p.c_lflag &= 0xFFFFFFF7;
if ( !tcsetattr(0, 0, &termios_p) )
{
if ( argc == 1 )
{
while ( read(0, &buf, 1uLL) > 0 )
write(1, &buf, 1uLL);
}
else
{
for ( i = 1LL; argc > (int)i; ++i )
{
v10 = open(argv[i], 0);
if ( v10 == -1 )
{
perror(argv[i]);
}
else
{
while ( read(v10, &buf, 1uLL) > 0 )
write(1, &buf, 1uLL);
close(v10);
}
}
}
func7(-128);
}
perror("tcsetattr()");
}
}
else
{
fwrite("stdin not a tty\n", 1uLL, 0x10uLL, _bss_start);
}
return 1;
}

original_code:
int main(int argc, char **argv)
{
 struct termios attr;
 int i;
 char buf;
 if(!isatty(0)){
  fputs("stdin not a tty\n", stderr);
  return 1;
 }
 if(tcgetattr(0, &attr)){
  perror("tcgetattr()");
  return 1;
 }
 memcpy(&origattr, &attr, sizeof attr);
 signal(2, fin);
 signal(1, fin);
 signal(15, fin);
 signal(3, fin);
 attr.c_lflag &= ~0000010;
 if(tcsetattr(0, 0, &attr)){
  perror("tcsetattr()");
  return 1;
 }
 if(argc == 1)
  while(read(0, &buf, sizeof buf) > 0) write(1, &buf, sizeof buf);
 else
  for(i = 1; i < argc; i++){
   int fd = open(argv[i], 00);
   if(fd == -1)
    perror(argv[i]);
   else{
    while(read(fd, &buf, sizeof buf) > 0) write(1, &buf, sizeof buf);
    close(fd);
   }
  }
 fin(-128);
 return 0;
}

variable_types: argc int

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

variable_types: buf char

variable_types: fd int