shuffle

original_code:
static void shuffle(int *choices, int nchoices)
{
    int i, j, t;
    if (nchoices > 1) {
        for (i = 0; i < nchoices; i++) {
            j = rand() / (2147483647 / nchoices + 1);
            t = choices[j];
            choices[j] = choices[i];
            choices[i] = t;
        }
    }
}

canonical_original_code:
static void shuffle(int *choices, int nchoices)
{
    int i; int j; int t;
    if (nchoices > 1) {
        for (i = 0; i < nchoices; i++) {
            j = rand() / (2147483647 / nchoices + 1);
            t = choices[j];
            choices[j] = choices[i];
            choices[i] = t;
        }
    }
}

variable_types:
choices
int *

variable_types: nchoices int

variable_types: j int

variable_types: t int


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

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

original_code:
int lowcardplayer_ask_swap_cards(const struct player_t *player)
{
    return 0;
}

canonical_original_code:
int lowcardplayer_ask_swap_cards(struct player_t *player)
{
    return 0;
}

variable_types: struct player_t { char name[10]; int is_computer; struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t { int hand_choice; int faceup_choice; } (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t { struct card_t pile[260]; int pile_size; } *, int [], int *); int (*ask_face_down_move)(); } *

return_type: int

user_defined_types: struct player_t { char name[10]; int is_computer; struct card_t hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t *, int [], int *); int (*ask_face_down_move)(); }

user_defined_types: struct card_t { enum cardrank rank; enum cardsuit suit; }


decompiled_code:
__int64 lowcardplayer_ask_swap_choice()
{
return 0x100000001LL;
}

original_code:
struct swap_choice_t lowcardplayer_ask_swap_choice(const struct player_t *player)
{
    struct swap_choice_t choice;
    choice.hand_choice = 1;
    choice.faceup_choice = 1;
    return choice;
}

canonical_original_code:
struct swap_choice_t lowcardplayer_ask_swap_choice(struct player_t *player)
{
    struct swap_choice_t choice;
    choice.hand_choice = 1;
    choice.faceup_choice = 1;
    return choice;
}

variable_types: struct player_t { char name[10]; int is_computer; struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t { struct card_t pile[260]; int pile_size; } *, int [], int *); int (*ask_face_down_move)(); } *

variable_types: struct swap_choice_t { int hand_choice; int faceup_choice; }


decompiled_code:
__int64 __fastcall lowcardplayer_ask_move(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax

*a4 = 0;
if ( (unsigned int)has_cards_in_hand() )
result = choose_lowest_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
else
result = choose_lowest_from_unsorted(a1 + 816, *(unsigned int *)(a1 + 980), a2, a3, a4);
return result;
}

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

*a4 = 0;
if ( (unsigned int)has_cards_in_hand() )
result = choose_lowest_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
else
result = choose_lowest_from_unsorted(a1 + 816, *(unsigned int *)(a1 + 980), a2, a3, a4);
return result;
}

original_code:
void lowcardplayer_ask_move(const struct player_t *player,
    const struct player_helper_t *helper, int card_choices[], int *nchoices)
{
    *nchoices = 0;
    if (has_cards_in_hand(player))
        choose_lowest_from_sorted(player->hand, player->hand_size, helper,
            card_choices, nchoices);
    else
        choose_lowest_from_unsorted(player->face_up, player->face_up_size, helper,
            card_choices, nchoices);
}

canonical_original_code:
void lowcardplayer_ask_move(struct player_t *player, struct player_helper_t *helper, int card_choices[], int *nchoices)
{
    *nchoices = 0;
    if (has_cards_in_hand(player))
        choose_lowest_from_sorted(player->hand, player->hand_size, helper,
            card_choices, nchoices);
    else
        choose_lowest_from_unsorted(player->face_up, player->face_up_size, helper,
            card_choices, nchoices);
}

variable_types:
helper
struct player_helper_t *

variable_types:
nchoices
int *

return_type: void

user_defined_types: enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 }

user_defined_types: enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 }

user_defined_types: struct swap_choice_t { int hand_choice; int faceup_choice; }

user_defined_types: struct player_helper_t { struct card_t pile[260]; int pile_size; }


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

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

original_code:
int lowcardplayer_ask_face_down_move(void)
{
    return 1;
}

canonical_original_code:
int lowcardplayer_ask_face_down_move()
{
    return 1;
}


decompiled_code:
void __fastcall perform_swap(int *a1)
{
int v1; // er12
_DWORD *v2; // rbx
unsigned int v3; // ebp
__int64 v4[6]; // [rsp+0h] [rbp-30h] BYREF

if ( *a1 > 0 )
{
v1 = 0;
v2 = a1 + 6;
do
{
if ( v2[3] )
{
while ( (unsigned int)ask_swap_cards(v2) )
{
v4[0] = ask_swap_choice(v2);
swap(v2, v4);
}
}
else
{
clearscreen();
show_player(v2);
if ( (unsigned int)request_swap_cards(v2) )
{
do
{
clearscreen();
show_player(v2);
newline();
v3 = request_hand_swap((unsigned int)v2[244]);
v4[0] = __PAIR64__(request_faceup_swap((unsigned int)v2[245]), v3);
swap(v2, v4);
clearscreen();
show_player(v2);
newline();
}
while ( (unsigned int)request_swap_more(v2) );
}
}
++v1;
v2 += 256;
}
while ( *a1 > v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(int *a1)
{
int v1; // er12
_DWORD *v2; // rbx
unsigned int v3; // ebp
__int64 v4[6]; // [rsp+0h] [rbp-30h] BYREF

if ( *a1 > 0 )
{
v1 = 0;
v2 = a1 + 6;
do
{
if ( v2[3] )
{
while ( (unsigned int)ask_swap_cards(v2) )
{
v4[0] = ask_swap_choice(v2);
swap(v2, v4);
}
}
else
{
clearscreen();
show_player(v2);
if ( (unsigned int)request_swap_cards(v2) )
{
do
{
clearscreen();
show_player(v2);
newline();
v3 = request_hand_swap((unsigned int)v2[244]);
v4[0] = __PAIR64__(request_faceup_swap((unsigned int)v2[245]), v3);
swap(v2, v4);
clearscreen();
show_player(v2);
newline();
}
while ( (unsigned int)request_swap_more(v2) );
}
}
++v1;
v2 += 256;
}
while ( *a1 > v1 );
}
}

original_code:
void perform_swap(struct game_t *game)
{
    struct swap_choice_t choice;
    int i, do_swap, hand_choice, face_up_choice;
    struct player_t *player;
    for (i = 0; i < game->num_players; i++) {
        player = &game->players[i];
        if (player->is_computer) {
            do_swap = ask_swap_cards(player);
            while (do_swap) {
                choice = ask_swap_choice(player);
                swap(player, &choice);
                do_swap = ask_swap_cards(player);
            }
        }
        else {
            clearscreen();
            show_player(player);
            do_swap = request_swap_cards(player->name);
            while (do_swap) {
                clearscreen();
                show_player(player);
                newline();
                hand_choice = request_hand_swap(player->hand_size);
                face_up_choice = request_faceup_swap(player->face_up_size);
                choice.hand_choice = hand_choice;
                choice.faceup_choice = face_up_choice;
                swap(player, &choice);
                clearscreen();
                show_player(player);
                newline();
                do_swap = request_swap_more(player->name);
           }
        }
    }
}

canonical_original_code:
void perform_swap(struct game_t *game)
{
    struct swap_choice_t choice;
    int i; int do_swap; int hand_choice; int face_up_choice;
    struct player_t *player;
    for (i = 0; i < game->num_players; i++) {
        player = &game->players[i];
        if (player->is_computer) {
            do_swap = ask_swap_cards(player);
            while (do_swap) {
                choice = ask_swap_choice(player);
                swap(player, &choice);
                do_swap = ask_swap_cards(player);
            }
        }
        else {
            clearscreen();
            show_player(player);
            do_swap = request_swap_cards(player->name);
            while (do_swap) {
                clearscreen();
                show_player(player);
                newline();
                hand_choice = request_hand_swap(player->hand_size);
                face_up_choice = request_faceup_swap(player->face_up_size);
                choice.hand_choice = hand_choice;
                choice.faceup_choice = face_up_choice;
                swap(player, &choice);
                clearscreen();
                show_player(player);
                newline();
                do_swap = request_swap_more(player->name);
           }
        }
    }
}

variable_types: struct game_t { int num_players; int num_cards_each; int deck_size; int pile_size; int burnt; struct player_t { char name[10]; int is_computer; struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t { int hand_choice; int faceup_choice; } (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t { struct card_t pile[260]; int pile_size; } *, int [], int *); int (*ask_face_down_move)(); } players[20]; int current_player; struct card_t deck[260]; struct card_t pile[260]; char last_move[100]; int miss_a_go; } *

variable_types: i int

user_defined_types: struct game_t { int num_players; int num_cards_each; int deck_size; int pile_size; int burnt; struct player_t players[20]; int current_player; struct card_t deck[260]; struct card_t pile[260]; char last_move[100]; int miss_a_go; }


decompiled_code:
__int64 __fastcall perform_move(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // r12
__int64 result; // rax
unsigned int v5; // [rsp+Ch] [rbp-89Ch] BYREF
char v6[80]; // [rsp+10h] [rbp-898h] BYREF
char v7[2120]; // [rsp+60h] [rbp-848h] BYREF

v1 = *(int *)(a1 + 20504);
v5 = 0;
v2 = v1 << 10;
v3 = a1 + v2 + 24;
if ( (unsigned int)can_move() )
{
if ( *(_DWORD *)(a1 + v2 + 36) )
{
get_player_helper(v7, a1);
ask_move(v3, v7, v6, &v5);
if ( !(unsigned int)valid_move(a1, v6, v5) )
{
printf("BAD COMP MOVE");
exit(1);
}
}
else
{
newline();
request_move(a1 + v2 + 24, v6, &v5);
while ( !(unsigned int)valid_move(a1, v6, v5) )
{
v5 = 0;
show_bad_move();
request_move(v3, v6, &v5);
}
}
make_move(a1, v6, v5);
v5 = 0;
result = move_to_next_player(a1);
}
else
{
if ( !*(_DWORD *)(a1 + v2 + 36) )
{
show_pickup(a1 + v2 + 24);
wait_user();
}
pick_up_pile(a1);
v5 = 0;
result = move_to_next_player(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // r12
__int64 result; // rax
unsigned int v5; // [rsp+Ch] [rbp-89Ch] BYREF
char v6[80]; // [rsp+10h] [rbp-898h] BYREF
char v7[2120]; // [rsp+60h] [rbp-848h] BYREF

v1 = *(int *)(a1 + 20504);
v5 = 0;
v2 = v1 << 10;
v3 = a1 + v2 + 24;
if ( (unsigned int)can_move() )
{
if ( *(_DWORD *)(a1 + v2 + 36) )
{
get_player_helper(v7, a1);
ask_move(v3, v7, v6, &v5);
if ( !(unsigned int)valid_move(a1, v6, v5) )
{
printf("BAD COMP MOVE");
exit(1);
}
}
else
{
newline();
request_move(a1 + v2 + 24, v6, &v5);
while ( !(unsigned int)valid_move(a1, v6, v5) )
{
v5 = 0;
show_bad_move();
request_move(v3, v6, &v5);
}
}
make_move(a1, v6, v5);
v5 = 0;
result = move_to_next_player(a1);
}
else
{
if ( !*(_DWORD *)(a1 + v2 + 36) )
{
show_pickup(a1 + v2 + 24);
wait_user();
}
pick_up_pile(a1);
v5 = 0;
result = move_to_next_player(a1);
}
return result;
}

original_code:
void perform_move(struct game_t *game)
{
    int card_choices[20];
    int num_choices = 0;
    struct player_t *player = &game->players[game->current_player];
    if (can_move(game)) {
        if (player->is_computer) {
            struct player_helper_t helper = get_player_helper(game);
            ask_move(player, &helper, card_choices, &num_choices);
            if (valid_move(game, card_choices, num_choices)) {
                make_move(game, card_choices, num_choices);
                num_choices = 0;
                move_to_next_player(game);
            } else {
                printf("BAD COMP MOVE");
                exit(1);
            }
        } else {
            newline();
            request_move(player, card_choices, &num_choices);
            while(!valid_move(game, card_choices, num_choices)) {
                num_choices = 0;
                show_bad_move();
                request_move(player, card_choices, &num_choices);
            }
            make_move(game, card_choices, num_choices);
            num_choices = 0;
            move_to_next_player(game);
        }
    } else {
        if (player->is_computer) {
            pick_up_pile(game);
            num_choices = 0;
            move_to_next_player(game);
        } else {
            show_pickup(player->name);
            wait_user();
            pick_up_pile(game);
            num_choices = 0;
            move_to_next_player(game);
        }
    }
}

variable_types: struct player_helper_t { struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } pile[260]; int pile_size; }


decompiled_code:
__int64 __fastcall perform_last_cards_move(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 v4; // r12
__int64 v5; // rsi
__int64 v6; // rdi
__int64 v8; // r12
__int64 v9; // rdi

v2 = *(int *)(a1 + 20504);
v3 = a1 + (v2 << 10) + 24;
if ( *(_DWORD *)(a1 + (v2 << 10) + 36) )
{
v4 = (unsigned int)ask_face_down_move(v3) - 1;
v5 = (unsigned int)v4;
v6 = a1;
if ( !(unsigned int)can_lay_from_face_down(a1, v4) )
{
LABEL_3:
pick_up_pile_and_face_down(v6, v5);
return move_to_next_player(a1);
}
}
else
{
v8 = (unsigned int)request_face_down_move(v3) - 1;
v9 = a1 + 8 * ((v2 << 7) + (int)v8 + 115);
if ( !(unsigned int)can_lay_from_face_down(a1, v8) )
{
show_pickup_from_face_down(v9);
wait_user();
v5 = (unsigned int)v8;
v6 = a1;
goto LABEL_3;
}
show_can_move_from_face_down(v9);
wait_user();
v5 = (unsigned int)v8;
v6 = a1;
}
make_move_from_face_down(v6, v5);
return move_to_next_player(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 v4; // r12
__int64 v5; // rsi
__int64 v6; // rdi
__int64 v8; // r12
__int64 v9; // rdi

v2 = *(int *)(a1 + 20504);
v3 = a1 + (v2 << 10) + 24;
if ( *(_DWORD *)(a1 + (v2 << 10) + 36) )
{
v4 = (unsigned int)ask_face_down_move(v3) - 1;
v5 = (unsigned int)v4;
v6 = a1;
if ( !(unsigned int)can_lay_from_face_down(a1, v4) )
{
LABEL_3:
pick_up_pile_and_face_down(v6, v5);
return move_to_next_player(a1);
}
}
else
{
v8 = (unsigned int)request_face_down_move(v3) - 1;
v9 = a1 + 8 * ((v2 << 7) + (int)v8 + 115);
if ( !(unsigned int)can_lay_from_face_down(a1, v8) )
{
show_pickup_from_face_down(v9);
wait_user();
v5 = (unsigned int)v8;
v6 = a1;
goto LABEL_3;
}
show_can_move_from_face_down(v9);
wait_user();
v5 = (unsigned int)v8;
v6 = a1;
}
make_move_from_face_down(v6, v5);
return move_to_next_player(a1);
}

original_code:
void perform_last_cards_move(struct game_t *game)
{
    int face_down_choice;
    struct player_t *player = &game->players[game->current_player];
    if (player->is_computer) {
        face_down_choice = ask_face_down_move(player);
        if (can_lay_from_face_down(game, face_down_choice-1)) {
            make_move_from_face_down(game, face_down_choice-1);
            move_to_next_player(game);
        } else {
            pick_up_pile_and_face_down(game, face_down_choice-1);
            move_to_next_player(game);
        }
    } else {
        face_down_choice = request_face_down_move(player);
        if (can_lay_from_face_down(game, face_down_choice-1)) {
            show_can_move_from_face_down(&player->face_down[face_down_choice-1]);
            wait_user();
            make_move_from_face_down(game, face_down_choice-1);
            move_to_next_player(game);
        } else {
            show_pickup_from_face_down(&player->face_down[face_down_choice-1]);
            wait_user();
            pick_up_pile_and_face_down(game, face_down_choice-1);
            move_to_next_player(game);
        }
    }
}


original_code:
static void init_sh_counts(struct player_type_t ptypes[], struct sh_count_t counts[])
{
    struct sh_count_t random;
    random.player = ptypes[0];
    random.count = 0;
    counts[0] = random;
    struct sh_count_t low;
    low.player = ptypes[1];
    low.count = 0;
    counts[1] = low;
    struct sh_count_t pyro;
    pyro.player = ptypes[2];
    pyro.count = 0;
    counts[2] = pyro;
}

variable_types: struct player_type_t { char type; char name[10]; } []

variable_types: struct sh_count_t { struct player_type_t player; int count; } []

variable_types: struct sh_count_t { struct player_type_t { char type; char name[10]; } player; int count; }


decompiled_code:
_BOOL8 __fastcall score_order(const void *a1, const void *a2)
{
return *((_DWORD *)a1 + 3) > *((_DWORD *)a2 + 3);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const void *a1, const void *a2)
{
return *((_DWORD *)a1 + 3) > *((_DWORD *)a2 + 3);
}

original_code:
static int score_order(const void *count1, const void *count2)
{
    const struct sh_count_t *icount1 = (const struct sh_count_t *) count1;
    const struct sh_count_t *icount2 = (const struct sh_count_t *) count2;
    return icount1->count > icount2->count;
}

canonical_original_code:
static int score_order(void *count1, void *count2)
{
    struct sh_count_t *icount1 = (const struct sh_count_t *) count1;
    struct sh_count_t *icount2 = (const struct sh_count_t *) count2;
    return icount1->count > icount2->count;
}

variable_types: struct sh_count_t { struct player_type_t { char type; char name[10]; } player; int count; } *

user_defined_types: struct sh_count_t { struct player_type_t player; int count; }


decompiled_code:
int __fastcall show_counts(char *a1, int a2)
{
char *v2; // rbp
__int64 v3; // rdx
const char *v4; // rsi
float v5; // xmm0_4
int result; // eax
double v7; // [rsp+8h] [rbp-20h]

qsort(a1, 3uLL, 0x10uLL, (__compar_fn_t)score_order);
v2 = a1 + 1;
v7 = (double)a2;
do
{
v3 = *(unsigned int *)(v2 + 11);
v4 = v2;
v2 += 16;
v5 = (double)(int)v3 / v7 * 100.0;
result = printf("%-20s%-10d%.0f%%\n", v4, v3, v5);
}
while ( a1 + 49 != v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *a1, int a2)
{
char *v2; // rbp
__int64 v3; // rdx
const char *v4; // rsi
float v5; // xmm0_4
int result; // eax
double v7; // [rsp+8h] [rbp-20h]

qsort(a1, 3uLL, 0x10uLL, (__compar_fn_t)score_order);
v2 = a1 + 1;
v7 = (double)a2;
do
{
v3 = *(unsigned int *)(v2 + 11);
v4 = v2;
v2 += 16;
v5 = (double)(int)v3 / v7 * 100.0;
result = printf("%-20s%-10d%.0f%%\n", v4, v3, v5);
}
while ( a1 + 49 != v2 );
return result;
}

original_code:
static void show_counts(struct sh_count_t counts[], int ngames)
{
    float percent;
    qsort(counts, 3, sizeof(struct sh_count_t), score_order);
    int i;
    for (i = 0; i < 3; i++) {
        percent = (double)counts[i].count / (double)ngames * 100.0;
        printf("%-20s%-10d%.0f%%\n", counts[i].player.name, counts[i].count, percent);
    }
}

variable_types: struct sh_count_t { struct player_type_t { char type; char name[10]; } player; int count; } []

variable_types: ngames int

variable_types: percent float


decompiled_code:
size_t __fastcall set_last_move(char *s, const char *a2, __int64 a3, int a4)
{
__int64 v7; // r12
const char *v8; // r13
size_t v9; // rax
__int64 v10; // rdi
const char *v11; // r13
size_t v12; // rax
size_t result; // rax

*(_QWORD *)stpcpy(s, a2) = 0x203A6469616C20LL;
if ( a4 > 0 )
{
v7 = a3 + 8LL * (unsigned int)(a4 - 1) + 8;
do
{
v8 = (const char *)show_rank(a3);
v9 = strlen(s);
v10 = a3;
a3 += 8LL;
strcpy(stpcpy(&s[v9], v8), " of ");
v11 = (const char *)show_suit(v10);
v12 = strlen(s);
strcpy(stpcpy(&s[v12], v11), ", ");
}
while ( a3 != v7 );
}
result = strlen(s);
*(_WORD *)&s[result] = 10;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *s, const char *a2, __int64 a3, int a4)
{
__int64 v7; // r12
const char *v8; // r13
size_t v9; // rax
__int64 v10; // rdi
const char *v11; // r13
size_t v12; // rax
size_t result; // rax

*(_QWORD *)stpcpy(s, a2) = 0x203A6469616C20LL;
if ( a4 > 0 )
{
v7 = a3 + 8LL * (unsigned int)(a4 - 1) + 8;
do
{
v8 = (const char *)show_rank(a3);
v9 = strlen(s);
v10 = a3;
a3 += 8LL;
strcpy(stpcpy(&s[v9], v8), " of ");
v11 = (const char *)show_suit(v10);
v12 = strlen(s);
strcpy(stpcpy(&s[v12], v11), ", ");
}
while ( a3 != v7 );
}
result = strlen(s);
*(_WORD *)&s[result] = 10;
return result;
}

original_code:
void set_last_move(char *last_move, const char *name, const struct card_t *cards,
    const int num_cards)
{
    int i;
    strcpy(last_move, "");
    strcat(last_move, name);
    strcat(last_move, " laid: ");
    for (i = 0; i < num_cards; i++) {
        strcat(last_move, show_rank(&cards[i]));
        strcat(last_move, " of ");
        strcat(last_move, show_suit(&cards[i]));
        strcat(last_move, ", ");
    }
    strcat(last_move, "\n");
}

canonical_original_code:
void set_last_move(char *last_move, char *name, struct card_t *cards, int num_cards)
{
    int i;
    strcpy(last_move, "");
    strcat(last_move, name);
    strcat(last_move, " laid: ");
    for (i = 0; i < num_cards; i++) {
        strcat(last_move, show_rank(&cards[i]));
        strcat(last_move, " of ");
        strcat(last_move, show_suit(&cards[i]));
        strcat(last_move, ", ");
    }
    strcat(last_move, "\n");
}

variable_types:
name
char *

variable_types: struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } *


decompiled_code:
char *__fastcall set_last_move_was_burn(char *a1, const char *a2)
{
char *result; // rax
__m128i v3; // xmm0

result = stpcpy(a1, a2);
v3 = _mm_load_si128((const __m128i *)&LC0);
result[16] = 0;
*(__m128i *)result = v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, const char *a2)
{
char *result; // rax
__m128i v3; // xmm0

result = stpcpy(a1, a2);
v3 = _mm_load_si128((const __m128i *)&LC0);
result[16] = 0;
*(__m128i *)result = v3;
return result;
}

original_code:
void set_last_move_was_burn(char *last_move, const char *name)
{
    strcpy(last_move, "");
    strcat(last_move, name);
    strcat(last_move, " burnt the deck\n");
}

canonical_original_code:
void set_last_move_was_burn(char *last_move, char *name)
{
    strcpy(last_move, "");
    strcat(last_move, name);
    strcat(last_move, " burnt the deck\n");
}


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

result = stpcpy(a1, a2);
strcpy(result, " picked up\n");
return result;
}

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

result = stpcpy(a1, a2);
strcpy(result, " picked up\n");
return result;
}

original_code:
void set_last_move_pickup(char *last_move, const char *name)
{
    strcpy(last_move, "");
    strcat(last_move, name);
    strcat(last_move, " picked up\n");
}

canonical_original_code:
void set_last_move_pickup(char *last_move, char *name)
{
    strcpy(last_move, "");
    strcat(last_move, name);
    strcat(last_move, " picked up\n");
}


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

original_code:
int human_ask_swap_cards(const struct player_t *player)
{
    return 0;
}

canonical_original_code:
int human_ask_swap_cards(struct player_t *player)
{
    return 0;
}

variable_types: struct player_t { char name[10]; int is_computer; struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t { int hand_choice; int faceup_choice; } (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t { struct card_t pile[260]; int pile_size; } *, int [], int *); int (*ask_face_down_move)(); } *


decompiled_code:
__int64 human_ask_swap_choice()
{
return 0x100000001LL;
}

original_code:
struct swap_choice_t human_ask_swap_choice(const struct player_t *player)
{
    struct swap_choice_t choice;
    choice.hand_choice = 1;
    choice.faceup_choice = 1;
    return choice;
}

canonical_original_code:
struct swap_choice_t human_ask_swap_choice(struct player_t *player)
{
    struct swap_choice_t choice;
    choice.hand_choice = 1;
    choice.faceup_choice = 1;
    return choice;
}

variable_types: struct player_t { char name[10]; int is_computer; struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t { struct card_t pile[260]; int pile_size; } *, int [], int *); int (*ask_face_down_move)(); } *

return_type: struct swap_choice_t { int hand_choice; int faceup_choice; }


decompiled_code:
void human_ask_move()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void human_ask_move(const struct player_t *player, const struct player_helper_t *helper,
    int card_choices[], int *nchoices)
{
}

canonical_original_code:
void human_ask_move(struct player_t *player, struct player_helper_t *helper, int card_choices[], int *nchoices)
{
}


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

original_code:
int human_ask_face_down_move(void)
{
    return 1;
}

canonical_original_code:
int human_ask_face_down_move()
{
    return 1;
}


decompiled_code:
__int64 run_cli_engine()
{
unsigned int v0; // ebp
unsigned int v1; // ebx
_BYTE v3[24790]; // [rsp+0h] [rbp-C2B8h] BYREF
char v4[10]; // [rsp+60D6h] [rbp-61E2h] BYREF
char v5[32]; // [rsp+60E0h] [rbp-61D8h] BYREF
char v6[208]; // [rsp+6100h] [rbp-61B8h] BYREF
char dest[24808]; // [rsp+61D0h] [rbp-60E8h] BYREF

clearscreen();
show_welcome_msg();
v0 = request_num_players();
v1 = request_num_cards_each();
request_player_details(v6, v5, v0);
make_game(v3, v0, v6, v5, v1);
memcpy(dest, v3, 0x60C8uLL);
init_game(dest);
perform_swap(dest);
first_move(dest);
while ( (unsigned int)continue_play(dest) )
{
clearscreen();
show_game_summary(dest);
if ( (unsigned int)player_on_last_cards(dest) )
perform_last_cards_move(dest);
else
perform_move(dest);
}
get_shithead(dest, v4);
return show_shithead(v4);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebp
unsigned int v1; // ebx
_BYTE v3[24790]; // [rsp+0h] [rbp-C2B8h] BYREF
char v4[10]; // [rsp+60D6h] [rbp-61E2h] BYREF
char v5[32]; // [rsp+60E0h] [rbp-61D8h] BYREF
char v6[208]; // [rsp+6100h] [rbp-61B8h] BYREF
char dest[24808]; // [rsp+61D0h] [rbp-60E8h] BYREF

clearscreen();
show_welcome_msg();
v0 = request_num_players();
v1 = request_num_cards_each();
request_player_details(v6, v5, v0);
make_game(v3, v0, v6, v5, v1);
memcpy(dest, v3, 0x60C8uLL);
init_game(dest);
perform_swap(dest);
first_move(dest);
while ( (unsigned int)continue_play(dest) )
{
clearscreen();
show_game_summary(dest);
if ( (unsigned int)player_on_last_cards(dest) )
perform_last_cards_move(dest);
else
perform_move(dest);
}
get_shithead(dest, v4);
return show_shithead(v4);
}

original_code:
void run_cli_engine()
{
    struct game_t game;
    int nplayers, ncards;
    char names[20][10];
    char types[20];
    char shithead[10];
    clearscreen();
    show_welcome_msg();
    nplayers = request_num_players();
    ncards = request_num_cards_each();
    request_player_details(names, types, nplayers);
    game = make_game(nplayers, names, types, ncards);
    init_game(&game);
    perform_swap(&game);
    first_move(&game);
    while (continue_play(&game)) {
        clearscreen();
        show_game_summary(&game);
        if (player_on_last_cards(&game))
            perform_last_cards_move(&game);
        else
            perform_move(&game);
    }
    get_shithead(&game, shithead);
    show_shithead(shithead);
}

canonical_original_code:
void run_cli_engine()
{
    struct game_t game;
    int nplayers; int ncards;
    char names[20][10];
    char types[20];
    char shithead[10];
    clearscreen();
    show_welcome_msg();
    nplayers = request_num_players();
    ncards = request_num_cards_each();
    request_player_details(names, types, nplayers);
    game = make_game(nplayers, names, types, ncards);
    init_game(&game);
    perform_swap(&game);
    first_move(&game);
    while (continue_play(&game)) {
        clearscreen();
        show_game_summary(&game);
        if (player_on_last_cards(&game))
            perform_last_cards_move(&game);
        else
            perform_move(&game);
    }
    get_shithead(&game, shithead);
    show_shithead(shithead);
}

variable_types: struct game_t { int num_players; int num_cards_each; int deck_size; int pile_size; int burnt; struct player_t { char name[10]; int is_computer; struct card_t { enum cardrank { TWO=2, THREE=3, FOUR=4, FIVE=5, SIX=6, SEVEN=7, EIGHT=8, NINE=9, TEN=10, JACK=11, QUEEN=12, KING=13, ACE=14 } rank; enum cardsuit { HEARTS=0, SPADES=1, DIAMONDS=2, CLUBS=3 } suit; } hand[100]; struct card_t face_up[10]; struct card_t face_down[10]; int hand_size; int face_up_size; int face_down_size; int (*ask_swap_cards)(struct player_t *); struct swap_choice_t { int hand_choice; int faceup_choice; } (*ask_swap_choice)(struct player_t *); void (*ask_move)(struct player_t *, struct player_helper_t { struct card_t pile[260]; int pile_size; } *, int [], int *); int (*ask_face_down_move)(); } players[20]; int current_player; struct card_t deck[260]; struct card_t pile[260]; char last_move[100]; int miss_a_go; }

variable_types: nplayers int

variable_types: ncards int

variable_types:
names
char [20][10]

variable_types:
types
char [20]

variable_types:
shithead
char [10]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // edi
int result; // eax
unsigned int v6; // eax

v4 = time(0LL);
srand(v4);
if ( argc == 1 )
{
run_cli_engine();
result = 0;
}
else if ( argc == 2 )
{
v6 = atoi(argv[1]);
run_battle_engine(v6);
result = 0;
}
else
{
puts("Usage: c-head <num_games>");
puts(" Omit num_games for interactive mode.");
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    srand(time(((void *)0)));
    if (argc == 1) {
        run_cli_engine();
        return 0;
    }
    else if (argc == 2) {
        int ngames = atoi(argv[1]);
        run_battle_engine(ngames);
        return 0;
    } else {
        printf("Usage: c-head <num_games>\n");
        printf("    Omit num_games for interactive mode.\n");
        return 1;
    }
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall format_millis(char *a1, double a2)
{
if ( a2 > 60000.0 )
return sprintf(
a1,
"%d minutes, %d seconds",
(unsigned int)(int)(a2 / 60000.0),
(unsigned int)(int)((a2 - (double)(60000 * (int)(a2 / 60000.0))) / 1000.0));
if ( a2 < 1000.0 )
return sprintf(a1, "%.2f milliseconds", a2);
return sprintf(a1, "%d seconds", (unsigned int)(int)(a2 / 1000.0));
}

canonical_decompiled_code:
int __fastcall func0(char *a1, double a2)
{
if ( a2 > 60000.0 )
return sprintf(
a1,
"%d minutes, %d seconds",
(unsigned int)(int)(a2 / 60000.0),
(unsigned int)(int)((a2 - (double)(60000 * (int)(a2 / 60000.0))) / 1000.0));
if ( a2 < 1000.0 )
return sprintf(a1, "%.2f milliseconds", a2);
return sprintf(a1, "%d seconds", (unsigned int)(int)(a2 / 1000.0));
}

original_code:
void format_millis(const double ms, char *result)
{
    if (ms > 60000) {
        int minutes = ms / 60000;
        int seconds = (ms - (minutes * 60000)) / 1000;
        sprintf(result, "%d minutes, %d seconds", minutes, seconds);
    } else if (ms >= 1000) {
        int seconds = ms / 1000;
        sprintf(result, "%d seconds", seconds);
    } else {
        sprintf(result, "%.2f milliseconds", ms);
    }
}

canonical_original_code:
void format_millis(double ms, char *result)
{
    if (ms > 60000) {
        int minutes = ms / 60000;
        int seconds = (ms - (minutes * 60000)) / 1000;
        sprintf(result, "%d minutes, %d seconds", minutes, seconds);
    } else if (ms >= 1000) {
        int seconds = ms / 1000;
        sprintf(result, "%d seconds", seconds);
    } else {
        sprintf(result, "%.2f milliseconds", ms);
    }
}

variable_types: ms double

variable_types:
result
char *

variable_types: minutes int

variable_types: seconds int


cmpid

repo: border/zkwatcher

decompiled_code:
int __fastcall cmpid(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int
cmpid(const void *p1, const void *p2)
{
    return strcmp(* (char * const *) p1, * (char * const *) p2);
}

canonical_original_code:
static int cmpid(void *p1, void *p2)
{
    return strcmp(* (char **) p1, * (char **) p2);
}


zooEvent

decompiled_code:
int __fastcall zooEvent(unsigned int a1)
{
int result; // eax

if ( ZOO_CREATED_EVENT == a1 )
return printf("zoo create event, type[%d]\n", a1);
if ( ZOO_DELETED_EVENT == a1 )
return printf("zoo deleted event, type[%d]\n", a1);
if ( ZOO_CHANGED_EVENT == a1 )
return printf("zoo changed event, type[%d]\n", a1);
if ( ZOO_CHILD_EVENT == a1 )
return printf("zoo child event, type[%d]\n", a1);
if ( ZOO_SESSION_EVENT == a1 )
return printf("zoo session event, type[%d]\n", a1);
if ( ZOO_NOTWATCHING_EVENT == a1 )
result = printf("zoo notwatching event, type[%d]\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
int result; // eax

if ( ZOO_CREATED_EVENT == a1 )
return printf("zoo create event, type[%d]\n", a1);
if ( ZOO_DELETED_EVENT == a1 )
return printf("zoo deleted event, type[%d]\n", a1);
if ( ZOO_CHANGED_EVENT == a1 )
return printf("zoo changed event, type[%d]\n", a1);
if ( ZOO_CHILD_EVENT == a1 )
return printf("zoo child event, type[%d]\n", a1);
if ( ZOO_SESSION_EVENT == a1 )
return printf("zoo session event, type[%d]\n", a1);
if ( ZOO_NOTWATCHING_EVENT == a1 )
result = printf("zoo notwatching event, type[%d]\n", a1);
return result;
}

original_code:
void zooEvent(int type) {
    if (type == ZOO_CREATED_EVENT) {
        printf("zoo create event, type[%d]\n", type);
    } else if (type == ZOO_DELETED_EVENT) {
        printf("zoo deleted event, type[%d]\n", type);
    } else if (type == ZOO_CHANGED_EVENT) {
        printf("zoo changed event, type[%d]\n", type);
    } else if (type == ZOO_CHILD_EVENT) {
        printf("zoo child event, type[%d]\n", type);
    } else if (type == ZOO_SESSION_EVENT) {
        printf("zoo session event, type[%d]\n", type);
    } else if (type == ZOO_NOTWATCHING_EVENT) {
        printf("zoo notwatching event, type[%d]\n", type);
    }
}

variable_types: type int


repo: borders/modviz

decompiled_code:
// attributes: thunk
void draw_destroy(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func0(void *ptr)
{
free(ptr);
}

original_code:
void draw_destroy(void *dp) {
 free(dp);
}

variable_types:
dp
void *


yyerror

repo: borer/miniC

decompiled_code:
int __fastcall yyerror(const char *a1)
{
++numErrores;
return fprintf(stdout, "Error at line %d: %s\n", yylineno, a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
++numErrores;
return fprintf(stdout, "Error at line %d: %s\n", yylineno, a1);
}

original_code:
void yyerror(const char * msg)
{
  numErrores++;
  fprintf(stdout, "Error at line %d: %s\n", yylineno, msg);
}

canonical_original_code:
void yyerror(char *msg)
{
  numErrores++;
  fprintf(stdout, "Error at line %d: %s\n", yylineno, msg);
}

variable_types:
msg
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r8
const char **v4; // rax
int v5; // ecx
__int64 v6; // rdi
const char **v7; // rsi
const char *v8; // rdx
const char **v10; // rbx

v3 = argv;
if ( argc <= 0 )
{
v5 = 0;
LODWORD(v6) = argc - 1;
}
else
{
v4 = argv;
v5 = 0;
v6 = (unsigned int)(argc - 1);
v7 = &argv[v6 + 1];
do
{
v8 = *v4;
if ( **v4 == 45 && v8[1] == 118 && !v8[2] )
{
verbosidad = 1;
++v5;
}
++v4;
}
while ( v4 != v7 );
}
if ( (_DWORD)v6 == v5 + 1 )
{
v10 = &v3[(int)v6];
yyin = fopen(*v10, "r");
if ( yyin )
{
if ( verbosidad == 1 )
fprintf(stdout, "%3d.- ", yylineno);
yyparse();
if ( numErrores > 0 )
fprintf(stdout, "\nNumero de errores: %d\n", (unsigned int)numErrores);
}
else
{
fprintf(stderr, "Fichero no valido %s\n", *v10);
}
}
else
{
fwrite("Uso: cmc [-v] fichero\n", 1uLL, 0x16uLL, stderr);
}
return 0;
}

original_code:
int main (int argc, char **argv)
{ int i, n = 0;
  for (i=0; i<argc; ++i) {
    if (strcmp(argv[i], "-v")==0) { verbosidad = 1; n++; }
  }
  --argc; n++;
  if (argc == n) {
    if ((yyin = fopen (argv[argc], "r")) == ((void *)0))
      fprintf (stderr, "Fichero no valido %s\n", argv[argc]);
    else {
      if (verbosidad == 1) fprintf(stdout,"%3d.- ", yylineno);
      yyparse ();
      if (numErrores > 0)
        fprintf(stdout,"\nNumero de errores:      %d\n", numErrores);
    }
  }
  else fprintf (stderr, "Uso: cmc [-v] fichero\n");
}

canonical_original_code:
int main(int argc, char **argv)
{ int i; int n = 0;
  for (i=0; i<argc; ++i) {
    if (strcmp(argv[i], "-v")==0) { verbosidad = 1; n++; }
  }
  --argc; n++;
  if (argc == n) {
    if ((yyin = fopen (argv[argc], "r")) == ((void *)0))
      fprintf (stderr, "Fichero no valido %s\n", argv[argc]);
    else {
      if (verbosidad == 1) fprintf(stdout,"%3d.- ", yylineno);
      yyparse ();
      if (numErrores > 0)
        fprintf(stdout,"\nNumero de errores:      %d\n", numErrores);
    }
  }
  else fprintf (stderr, "Uso: cmc [-v] fichero\n");
}

variable_types:
argv
char **

variable_types: i int

variable_types: n int


repo: boris-il-forte/project-fantasy

decompiled_code:
double __fastcall f_int(_DWORD *a1, int a2)
{
double result; // xmm0_8

result = 0.0;
if ( *a1 == 2 )
{
if ( a1[1] >= a2 || a1[2] <= a2 )
result = 0.0;
else
result = *(double *)&LC1;
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(_DWORD *a1, int a2)
{
double result; // xmm0_8

result = 0.0;
if ( *a1 == 2 )
{
if ( a1[1] >= a2 || a1[2] <= a2 )
result = 0.0;
else
result = *(double *)&LC1;
}
return result;
}

original_code:
double f_int(t_paramlist* parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 if(value > a && value < b)
  return 1.0;
 else
  return 0;
}

canonical_original_code:
double f_int(struct s_paramlist *parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 if(value > a && value < b)
  return 1.0;
 else
  return 0;
}

variable_types: struct s_paramlist { int paramNumber; int param[4]; } *

variable_types: value int

variable_types: a int

variable_types: b int

return_type: double


decompiled_code:
double __fastcall f_sgt(_DWORD *a1, int a2)
{
double result; // xmm0_8

result = 0.0;
if ( *a1 == 2 && a1[1] == a2 )
result = *(double *)&LC1;
return result;
}

canonical_decompiled_code:
double __fastcall func1(_DWORD *a1, int a2)
{
double result; // xmm0_8

result = 0.0;
if ( *a1 == 2 && a1[1] == a2 )
result = *(double *)&LC1;
return result;
}

original_code:
double f_sgt(t_paramlist* parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 if(value == a)
  return 1.0;
 else
  return 0;
}

canonical_original_code:
double f_sgt(struct s_paramlist *parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 if(value == a)
  return 1.0;
 else
  return 0;
}

user_defined_types: struct s_paramlist { int paramNumber; int param[4]; }


matchCrispData

decompiled_code:
__int64 __fastcall matchCrispData(__int64 a1, __int64 a2)
{
const char *v2; // rbp
__int64 v3; // rbx

v2 = *(const char **)(a1 + 32);
if ( !a2 )
return 0LL;
v3 = a2;
while ( strcmp(*(const char **)v3, v2) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0LL;
}
*(_QWORD *)(a1 + 24) = *(_QWORD *)(v3 + 8);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
const char *v2; // rbp
__int64 v3; // rbx

v2 = *(const char **)(a1 + 32);
if ( !a2 )
return 0LL;
v3 = a2;
while ( strcmp(*(const char **)v3, v2) )
{
v3 = *(_QWORD *)(v3 + 16);
if ( !v3 )
return 0LL;
}
*(_QWORD *)(a1 + 24) = *(_QWORD *)(v3 + 8);
return 1LL;
}

original_code:
static int matchCrispData(t_rule* nodo, struct s_crispdata* crispData)
{
 int found = 0;
 char* label = nodo->nome;
 struct s_crispdata* data = crispData;
 while(data != ((void *)0) && !found)
 {
  if(strcmp(data->label, label) == 0)
  {
   nodo->dati = data->var;
   found = 1;
  }
  data = data->next;
 }
 return found;
}

canonical_original_code:
static int matchCrispData(struct s_rule *nodo, struct s_crispdata *crispData)
{
 int found = 0;
 char *label = nodo->nome;
 struct s_crispdata *data = crispData;
 while(data != ((void *)0) && !found)
 {
  if(strcmp(data->label, label) == 0)
  {
   nodo->dati = data->var;
   found = 1;
  }
  data = data->next;
 }
 return found;
}

variable_types: struct s_rule { enum e_nodo { AND_N=0, OR_N=1, NOT_N=2, IS_N=3, ID_N=4 } tipo; struct s_rule *destro; struct s_rule *sinistro; void *dati; char *nome; } *

variable_types: struct s_crispdata { char *label; int *var; struct s_crispdata *next; } *

variable_types: found int

variable_types:
label
char *

user_defined_types: struct s_rule { enum e_nodo tipo; struct s_rule *destro; struct s_rule *sinistro; void *dati; char *nome; }


addCrispData

decompiled_code:
__int64 __fastcall addCrispData(char *s, __int64 a2, __int64 *a3)
{
__int64 v3; // rbx
_QWORD *v4; // rbp
char *v5; // rax
__int64 result; // rax

v3 = *a3;
v4 = malloc(0x18uLL);
v5 = strdup(s);
v4[1] = a2;
*v4 = v5;
v4[2] = 0LL;
if ( !v3 )
addCrispData_cold();
do
{
result = v3;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
*(_QWORD *)(result + 16) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, __int64 a2, __int64 *a3)
{
__int64 v3; // rbx
_QWORD *v4; // rbp
char *v5; // rax
__int64 result; // rax

v3 = *a3;
v4 = malloc(0x18uLL);
v5 = strdup(s);
v4[1] = a2;
*v4 = v5;
v4[2] = 0LL;
if ( !v3 )
func23();
do
{
result = v3;
v3 = *(_QWORD *)(v3 + 16);
}
while ( v3 );
*(_QWORD *)(result + 16) = v4;
return result;
}

original_code:
static void addCrispData(const char* label, int* var, struct s_crispdata** crispDataList)
{
 struct s_crispdata* data = *crispDataList;
 struct s_crispdata* pData = ((void *)0);
 struct s_crispdata* newData = (struct s_crispdata*) malloc(sizeof(struct s_crispdata));
 newData->label = strdup(label);
 newData->var = var;
 newData->next = ((void *)0);
 if(*crispDataList == ((void *)0))
 {
  *crispDataList = newData;
 }
 while(data != ((void *)0))
 {
  pData = data;
  data = data->next;
 }
 pData->next = newData;
}

canonical_original_code:
static void addCrispData(char *label, int *var, struct s_crispdata **crispDataList)
{
 struct s_crispdata *data = *crispDataList;
 struct s_crispdata *pData = ((void *)0);
 struct s_crispdata *newData = (struct s_crispdata*) malloc(sizeof(struct s_crispdata));
 newData->label = strdup(label);
 newData->var = var;
 newData->next = ((void *)0);
 if(*crispDataList == ((void *)0))
 {
  *crispDataList = newData;
 }
 while(data != ((void *)0))
 {
  pData = data;
  data = data->next;
 }
 pData->next = newData;
}

variable_types:
var
int *

variable_types: struct s_crispdata { char *label; int *var; struct s_crispdata *next; } **


retta

decompiled_code:
double __fastcall retta(int a1, int a2, int a3, double a4, double a5)
{
return (double)(a3 - a1) * ((a5 - a4) / (double)(a2 - a1)) + a4;
}

canonical_decompiled_code:
double __fastcall func8(int a1, int a2, int a3, double a4, double a5)
{
return (double)(a3 - a1) * ((a5 - a4) / (double)(a2 - a1)) + a4;
}

original_code:
double retta(int x1, double y1, int x2, double y2, int x)
{
 double m = (y2 - y1) / (x2 - x1);
 return m*(x - x1) + y1;
}

variable_types: x int

variable_types: m double


decompiled_code:
double __fastcall f_tol(_DWORD *a1, int a2)
{
int v2; // er8
int v3; // er9

if ( *a1 != 2 )
return 0.0;
v2 = a1[1];
v3 = a1[2];
if ( v2 > a2 )
return *(double *)&LC1;
if ( v3 < a2 )
return 0.0;
return retta(v2, v3, a2, 1.0, 0.0);
}

canonical_decompiled_code:
double __fastcall func9(_DWORD *a1, int a2)
{
int v2; // er8
int v3; // er9

if ( *a1 != 2 )
return 0.0;
v2 = a1[1];
v3 = a1[2];
if ( v2 > a2 )
return *(double *)&LC1;
if ( v3 < a2 )
return 0.0;
return func8(v2, v3, a2, 1.0, 0.0);
}

original_code:
double f_tol(t_paramlist* parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 if(value < a)
  return 1.0;
 else if(value > b)
  return 0;
 else
  return retta(a, 1.0, b, 0, value);
}

canonical_original_code:
double f_tol(struct s_paramlist *parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 if(value < a)
  return 1.0;
 else if(value > b)
  return 0;
 else
  return retta(a, 1.0, b, 0, value);
}


decompiled_code:
double __fastcall f_tor(_DWORD *a1, int a2)
{
int v2; // er8
int v3; // er9

if ( *a1 != 2 )
return 0.0;
v2 = a1[2];
v3 = a1[1];
if ( v2 < a2 )
return *(double *)&LC1;
if ( v3 > a2 )
return 0.0;
return retta(v3, v2, a2, 0.0, 1.0);
}

canonical_decompiled_code:
double __fastcall func10(_DWORD *a1, int a2)
{
int v2; // er8
int v3; // er9

if ( *a1 != 2 )
return 0.0;
v2 = a1[2];
v3 = a1[1];
if ( v2 < a2 )
return *(double *)&LC1;
if ( v3 > a2 )
return 0.0;
return func8(v3, v2, a2, 0.0, 1.0);
}

original_code:
double f_tor(t_paramlist* parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 if(value > b)
  return 1.0;
 else if(value < a)
  return 0;
 else
  return retta(a, 0, b, 1.0, value);
}

canonical_original_code:
double f_tor(struct s_paramlist *parameters, int value)
{
 if(parameters->paramNumber != 2) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 if(value > b)
  return 1.0;
 else if(value < a)
  return 0;
 else
  return retta(a, 0, b, 1.0, value);
}


decompiled_code:
double __fastcall f_tri(_DWORD *a1, int a2)
{
int v2; // er8
int v3; // er9
double result; // xmm0_8

if ( *a1 != 3 )
return 0.0;
v2 = a1[1];
v3 = a1[2];
if ( a1[3] > a2 )
return retta(v2, v3, a2, 0.0, 1.0);
result = *(double *)&LC1;
if ( a1[3] < a2 )
result = retta(v2, v3, a2, 1.0, 0.0);
return result;
}

canonical_decompiled_code:
double __fastcall func11(_DWORD *a1, int a2)
{
int v2; // er8
int v3; // er9
double result; // xmm0_8

if ( *a1 != 3 )
return 0.0;
v2 = a1[1];
v3 = a1[2];
if ( a1[3] > a2 )
return func8(v2, v3, a2, 0.0, 1.0);
result = *(double *)&LC1;
if ( a1[3] < a2 )
result = func8(v2, v3, a2, 1.0, 0.0);
return result;
}

original_code:
double f_tri(t_paramlist* parameters, int value)
{
 if(parameters->paramNumber != 3) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 int c = parameters->param[2];
 if(value < c)
  return retta(a, 0, b, 1.0, value);
 else if(value > c)
  return retta(a, 1.0, b, 0, value);
 else
  return 1.0;
}

canonical_original_code:
double f_tri(struct s_paramlist *parameters, int value)
{
 if(parameters->paramNumber != 3) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 int c = parameters->param[2];
 if(value < c)
  return retta(a, 0, b, 1.0, value);
 else if(value > c)
  return retta(a, 1.0, b, 0, value);
 else
  return 1.0;
}

variable_types: c int


original_code:
double f_tra(t_paramlist* parameters, int value)
{
 if(parameters->paramNumber != 4) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 int c = parameters->param[2];
 int d = parameters->param[3];
 if(value < a || value > d)
  return 0;
 else if(value > a && value < b)
  return retta(a, 0, b, 1.0, value);
 else if(value > c && value < d)
  return retta(c, 1.0, d, 0, value);
 else
  return 1.0;
}

canonical_original_code:
double f_tra(struct s_paramlist *parameters, int value)
{
 if(parameters->paramNumber != 4) return 0;
 int a = parameters->param[0];
 int b = parameters->param[1];
 int c = parameters->param[2];
 int d = parameters->param[3];
 if(value < a || value > d)
  return 0;
 else if(value > a && value < b)
  return retta(a, 0, b, 1.0, value);
 else if(value > c && value < d)
  return retta(c, 1.0, d, 0, value);
 else
  return 1.0;
}

variable_types: d int


matchFuzzySet

decompiled_code:
__int64 __fastcall matchFuzzySet(__int64 a1, __int64 a2)
{
const char *v2; // rbp
__int64 v3; // rbx

v2 = *(const char **)(a2 + 32);
if ( !a1 )
return 0LL;
v3 = a1;
while ( strcmp(*(const char **)v3, v2) )
{
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return 0LL;
}
*(_QWORD *)(a2 + 24) = v3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
const char *v2; // rbp
__int64 v3; // rbx

v2 = *(const char **)(a2 + 32);
if ( !a1 )
return 0LL;
v3 = a1;
while ( strcmp(*(const char **)v3, v2) )
{
v3 = *(_QWORD *)(v3 + 24);
if ( !v3 )
return 0LL;
}
*(_QWORD *)(a2 + 24) = v3;
return 1LL;
}

original_code:
int matchFuzzySet(t_fuzzyset* fuzzysetRoot, t_rule* nodo)
{
 int found = 0;
 t_fuzzyset* fuzzySet = fuzzysetRoot;
 char* label = nodo->nome;
 while(fuzzySet != ((void *)0) && !found)
 {
  if(strcmp(fuzzySet->label, label) == 0)
  {
   nodo->dati = fuzzySet;
   found = 1;
  }
  fuzzySet = fuzzySet->next;
 }
 return found;
}

canonical_original_code:
int matchFuzzySet(struct s_fuzzyset *fuzzysetRoot, struct s_rule *nodo)
{
 int found = 0;
 struct s_fuzzyset *fuzzySet = fuzzysetRoot;
 char *label = nodo->nome;
 while(fuzzySet != ((void *)0) && !found)
 {
  if(strcmp(fuzzySet->label, label) == 0)
  {
   nodo->dati = fuzzySet;
   found = 1;
  }
  fuzzySet = fuzzySet->next;
 }
 return found;
}

variable_types: struct s_fuzzyset { char *label; struct s_paramlist { int paramNumber; int param[4]; } *parameters; double (*mfunction)(struct s_paramlist *parameters, int value); struct s_fuzzyset *next; } *

user_defined_types: struct s_fuzzyset { char *label; struct s_paramlist *parameters; double (*mfunction)(struct s_paramlist *parameters, int value); struct s_fuzzyset *next; }

user_defined_types: enum e_nodo { AND_N=0, OR_N=1, NOT_N=2, IS_N=3, ID_N=4 }


addCrispInput

decompiled_code:
__int64 __fastcall addCrispInput(char *a1, __int64 a2)
{
return addCrispData(a1, a2, &crispInput);
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, __int64 a2)
{
return func3(a1, a2, &crispInput);
}

original_code:
void addCrispInput(const char* label, int* var)
{
 addCrispData(label, var, &crispInput);
}

canonical_original_code:
void addCrispInput(char *label, int *var)
{
 addCrispData(label, var, &crispInput);
}


addCrispOutput

decompiled_code:
__int64 __fastcall addCrispOutput(char *a1, __int64 a2)
{
return addCrispData(a1, a2, &crispOutput);
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, __int64 a2)
{
return func3(a1, a2, &crispOutput);
}

original_code:
void addCrispOutput(const char* label, int* var)
{
 addCrispData(label, var, &crispOutput);
}

canonical_original_code:
void addCrispOutput(char *label, int *var)
{
 addCrispData(label, var, &crispOutput);
}


matchVariables

decompiled_code:
__int64 __fastcall matchVariables(__int64 a1)
{
return matchCrispData(a1, crispInput);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func2(a1, crispInput);
}

original_code:
int matchVariables(t_rule* nodo)
{
 return matchCrispData(nodo, crispInput);
}

canonical_original_code:
int matchVariables(struct s_rule *nodo)
{
 return matchCrispData(nodo, crispInput);
}


matchOutputs

decompiled_code:
__int64 __fastcall matchOutputs(__int64 a1)
{
return matchCrispData(a1, crispOutput);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return func2(a1, crispOutput);
}

original_code:
int matchOutputs(t_rule* nodo)
{
 return matchCrispData(nodo, crispOutput);
}

canonical_original_code:
int matchOutputs(struct s_rule *nodo)
{
 return matchCrispData(nodo, crispOutput);
}


notSingletonAssignment

decompiled_code:
_BOOL8 __fastcall notSingletonAssignment(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL) + 16LL) != (_QWORD)f_sgt;
}

canonical_decompiled_code:
_BOOL8 __fastcall func19(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL) + 16LL) != (_QWORD)f_sgt;
}

original_code:
int notSingletonAssignment(t_rule* assignment)
{
 t_fuzzyset* fuzzySet = (t_fuzzyset*)assignment->destro->dati;
 if(fuzzySet->mfunction != f_sgt)
  return 1;
 else
  return 0;
}

canonical_original_code:
int notSingletonAssignment(struct s_rule *assignment)
{
 struct s_fuzzyset *fuzzySet = (t_fuzzyset*)assignment->destro->dati;
 if(fuzzySet->mfunction != f_sgt)
  return 1;
 else
  return 0;
}


visitaAlbero

decompiled_code:
void __fastcall visitaAlbero(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rsi

if ( a1 )
{
v1 = *(_DWORD *)a1;
v2 = *(_QWORD *)(a1 + 8);
if ( *(_DWORD *)a1 == 2 )
{
fuzzy_not(*(_QWORD *)(a1 + 8));
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
fuzzy_is_isra_0(*(unsigned int **)(*(_QWORD *)(a1 + 16) + 24LL), *(_QWORD *)(v2 + 24));
}
else if ( v1 )
{
fuzzy_or(*(_QWORD *)(a1 + 16), v2);
}
else
{
fuzzy_and(*(_QWORD *)(a1 + 16), v2);
}
}
}

original_code:
double visitaAlbero(t_rule* radice)
{
 t_rule* destro;
 t_rule* sinistro;
 if(radice == ((void *)0)) return 0;
 destro = radice->destro;
 sinistro = radice->sinistro;
 switch(radice->tipo)
 {
  case AND_N:
   return fuzzy_and(sinistro, destro);
  case OR_N:
   return fuzzy_or(sinistro, destro);
  case NOT_N:
   return fuzzy_not(destro);
  case IS_N:
   return fuzzy_is(sinistro, destro);
  default:
   return 0;
 }
}

canonical_original_code:
double visitaAlbero(struct s_rule *radice)
{
 struct s_rule *destro;
 struct s_rule *sinistro;
 if(radice == ((void *)0)) return 0;
 destro = radice->destro;
 sinistro = radice->sinistro;
 switch(radice->tipo)
 {
  case AND_N:
   return fuzzy_and(sinistro, destro);
  case OR_N:
   return fuzzy_or(sinistro, destro);
  case NOT_N:
   return fuzzy_not(destro);
  case IS_N:
   return fuzzy_is(sinistro, destro);
  default:
   return 0;
 }
}


decompiled_code:
double __fastcall fuzzy_not(__int64 a1, double a2)
{
visitaAlbero(a1);
return 1.0 - a2;
}

canonical_decompiled_code:
double __fastcall func21(__int64 a1, double a2)
{
func20(a1);
return 1.0 - a2;
}

original_code:
static double fuzzy_not(t_rule* destro)
{
 return (1- visitaAlbero(destro));
}

canonical_original_code:
static double fuzzy_not(struct s_rule *destro)
{
 return (1- visitaAlbero(destro));
}


setFuzzyOutPuts

original_code:
void setFuzzyOutPuts(t_rulebase* testa)
{
 struct s_assignment
 {
  char* label;
  int value;
  double weight;
  struct s_assignment* next;
 } *assignments = ((void *)0), *currentAssignment, *assignmentToDel;
 t_rulebase* testaCorrente = testa;
 char* label;
 int value;
 double num, den;
 double weight;
 while(testaCorrente != ((void *)0))
 {
  label = getTargetLabel(testaCorrente->target);
  value = getTargetValue(testaCorrente->target);
  weight = visitaAlbero(testaCorrente->rule);
  currentAssignment = (struct s_assignment*) malloc(sizeof(struct s_assignment));
  currentAssignment->label = label;
  currentAssignment->value = value;
  currentAssignment->weight = weight;
  currentAssignment->next = assignments;
  assignments = currentAssignment;
  testaCorrente = testaCorrente->nextRule;
 }
 struct s_crispdata* outputs = crispOutput;
 while(outputs != ((void *)0))
 {
  currentAssignment = assignments;
  num = 0;
  den = 0;
  while(currentAssignment != ((void *)0))
  {
   if(strcmp(currentAssignment->label, outputs->label) == 0)
   {
    num += currentAssignment->value * currentAssignment->weight;
    den += currentAssignment->weight;
    if(currentAssignment == assignments)
    {
     assignments = currentAssignment->next;
    }
    assignmentToDel = currentAssignment;
    currentAssignment = currentAssignment->next;
    free(assignmentToDel);
   }
   else
    currentAssignment = currentAssignment->next;
  }
  *outputs->var = num / den;
 }
 while(assignments != ((void *)0))
 {
  assignmentToDel = assignments;
  assignments = assignments->next;
  free(assignmentToDel);
 }
}

canonical_original_code:
void setFuzzyOutPuts(struct s_rulebase *testa)
{
 struct s_assignment *assignments = ((void *)0); struct s_assignment *currentAssignment; struct s_assignment *assignmentToDel;
 struct s_rulebase *testaCorrente = testa;
 char *label;
 int value;
 double num; double den;
 double weight;
 while(testaCorrente != ((void *)0))
 {
  label = getTargetLabel(testaCorrente->target);
  value = getTargetValue(testaCorrente->target);
  weight = visitaAlbero(testaCorrente->rule);
  currentAssignment = (struct s_assignment *) malloc(sizeof(struct s_assignment));
  currentAssignment->label = label;
  currentAssignment->value = value;
  currentAssignment->weight = weight;
  currentAssignment->next = assignments;
  assignments = currentAssignment;
  testaCorrente = testaCorrente->nextRule;
 }
 struct s_crispdata *outputs = crispOutput;
 while(outputs != ((void *)0))
 {
  currentAssignment = assignments;
  num = 0;
  den = 0;
  while(currentAssignment != ((void *)0))
  {
   if(strcmp(currentAssignment->label, outputs->label) == 0)
   {
    num += currentAssignment->value * currentAssignment->weight;
    den += currentAssignment->weight;
    if(currentAssignment == assignments)
    {
     assignments = currentAssignment->next;
    }
    assignmentToDel = currentAssignment;
    currentAssignment = currentAssignment->next;
    free(assignmentToDel);
   }
   else
    currentAssignment = currentAssignment->next;
  }
  *outputs->var = num / den;
 }
 while(assignments != ((void *)0))
 {
  assignmentToDel = assignments;
  assignments = assignments->next;
  free(assignmentToDel);
 }
}

variable_types: struct s_rulebase { struct s_rule { enum e_nodo { AND_N=0, OR_N=1, NOT_N=2, IS_N=3, ID_N=4 } tipo; struct s_rule *destro; struct s_rule *sinistro; void *dati; char *nome; } *rule; struct s_rule *target; struct s_rulebase *nextRule; } *

variable_types: struct s_assignment { char *label; int value; double weight; struct s_assignment *next; } *

variable_types: num double

variable_types: den double

variable_types: weight double

user_defined_types: struct s_rulebase { struct s_rule *rule; struct s_rule *target; struct s_rulebase *nextRule; }

user_defined_types: struct s_crispdata { char *label; int *var; struct s_crispdata *next; }


yyparse

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 5)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-7))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 270 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 34 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 3:
    {
    (yyval.fset) = ((void *)0);
   }
    break;
  case 4:
    {
    (yyval.fset) = creaFuzzySet((yyvsp[-5].str), (yyvsp[-3].str), (yyvsp[-2].fshape), (yyvsp[0].fset));
    if((yyval.fset) = ((void *)0)) goto yyabortlab;
    fuzzysetRoot = (yyval.fset);
   }
    break;
  case 5:
    {
    (yyval.fshape) = (yyvsp[-1].fshape);
   }
    break;
  case 6:
    {
    (yyval.fshape) = creaParametri(((void *)0),(yyvsp[0].integer));
   }
    break;
  case 7:
    {
    (yyval.fshape) = creaParametri((yyvsp[0].fshape),(yyvsp[-2].integer));
   }
    break;
  case 8:
    {
    (yyval.regola) = ((void *)0);
   }
    break;
  case 9:
    {
    if(notSingletonAssignment((yyvsp[-2].nodo))) goto yyabortlab;
    (yyval.regola) = aggiungiAllaLista((yyvsp[0].regola), (yyvsp[-4].nodo), (yyvsp[-2].nodo)); rulebaseRoot = (yyval.regola);
   }
    break;
  case 10:
    {
    (yyval.nodo) = (yyvsp[0].nodo);
   }
    break;
  case 11:
    {
    (yyval.nodo) = (yyvsp[-1].nodo);
   }
    break;
  case 12:
    {
    (yyval.nodo) = creaNodo(NOT_N, ((void *)0), (yyvsp[0].nodo), "");
   }
    break;
  case 13:
    {
    (yyval.nodo) = creaNodo(OR_N, (yyvsp[-2].nodo), (yyvsp[0].nodo), "");
   }
    break;
  case 14:
    {
    (yyval.nodo) = creaNodo(AND_N, (yyvsp[-2].nodo), (yyvsp[0].nodo), "");
   }
    break;
  case 15:
    {
    t_rule* sinistro = creaNodo(ID_N, ((void *)0), ((void *)0), (yyvsp[-3].str));
    t_rule* destro = creaNodo(ID_N, ((void *)0), ((void *)0), (yyvsp[-1].str));
    (yyval.nodo) = creaNodo(IS_N, sinistro, destro, "");
    if(!matchVariables(sinistro) || !matchOutputs(sinistro)) goto yyabortlab;
    if(!matchFuzzySet(fuzzysetRoot, destro)) goto yyabortlab;
   }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 16;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 34 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 270 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-7))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 34 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 270 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 5)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-7))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 270 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 34 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 3:
    {
    (yyval.fset) = ((void *)0);
   }
    break;
  case 4:
    {
    (yyval.fset) = creaFuzzySet((yyvsp[-5].str), (yyvsp[-3].str), (yyvsp[-2].fshape), (yyvsp[0].fset));
    if((yyval.fset) = ((void *)0)) goto yyabortlab;
    fuzzysetRoot = (yyval.fset);
   }
    break;
  case 5:
    {
    (yyval.fshape) = (yyvsp[-1].fshape);
   }
    break;
  case 6:
    {
    (yyval.fshape) = creaParametri(((void *)0),(yyvsp[0].integer));
   }
    break;
  case 7:
    {
    (yyval.fshape) = creaParametri((yyvsp[0].fshape),(yyvsp[-2].integer));
   }
    break;
  case 8:
    {
    (yyval.regola) = ((void *)0);
   }
    break;
  case 9:
    {
    if(notSingletonAssignment((yyvsp[-2].nodo))) goto yyabortlab;
    (yyval.regola) = aggiungiAllaLista((yyvsp[0].regola), (yyvsp[-4].nodo), (yyvsp[-2].nodo)); rulebaseRoot = (yyval.regola);
   }
    break;
  case 10:
    {
    (yyval.nodo) = (yyvsp[0].nodo);
   }
    break;
  case 11:
    {
    (yyval.nodo) = (yyvsp[-1].nodo);
   }
    break;
  case 12:
    {
    (yyval.nodo) = creaNodo(NOT_N, ((void *)0), (yyvsp[0].nodo), "");
   }
    break;
  case 13:
    {
    (yyval.nodo) = creaNodo(OR_N, (yyvsp[-2].nodo), (yyvsp[0].nodo), "");
   }
    break;
  case 14:
    {
    (yyval.nodo) = creaNodo(AND_N, (yyvsp[-2].nodo), (yyvsp[0].nodo), "");
   }
    break;
  case 15:
    {
    struct s_rule *sinistro = creaNodo(ID_N, ((void *)0), ((void *)0), (yyvsp[-3].str));
    struct s_rule *destro = creaNodo(ID_N, ((void *)0), ((void *)0), (yyvsp[-1].str));
    (yyval.nodo) = creaNodo(IS_N, sinistro, destro, "");
    if(!matchVariables(sinistro) || !matchOutputs(sinistro)) goto yyabortlab;
    if(!matchFuzzySet(fuzzysetRoot, destro)) goto yyabortlab;
   }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 16;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 34 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 270 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-7))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 34 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 270 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { int integer; char *str; struct s_rule { enum e_nodo { AND_N=0, OR_N=1, NOT_N=2, IS_N=3, ID_N=4 } tipo; struct s_rule *destro; struct s_rule *sinistro; void *dati; char *nome; } *nodo; struct s_rulebase { struct s_rule *rule; struct s_rule *target; struct s_rulebase *nextRule; } *regola; struct s_fuzzyset { char *label; struct s_paramlist { int paramNumber; int param[4]; } *parameters; double (*mfunction)(struct s_paramlist *parameters, int value); struct s_fuzzyset *next; } *fset; struct s_paramlist *fshape; } [200]

variable_types: union YYSTYPE { int integer; char *str; struct s_rule { enum e_nodo { AND_N=0, OR_N=1, NOT_N=2, IS_N=3, ID_N=4 } tipo; struct s_rule *destro; struct s_rule *sinistro; void *dati; char *nome; } *nodo; struct s_rulebase { struct s_rule *rule; struct s_rule *target; struct s_rulebase *nextRule; } *regola; struct s_fuzzyset { char *label; struct s_paramlist { int paramNumber; int param[4]; } *parameters; double (*mfunction)(struct s_paramlist *parameters, int value); struct s_fuzzyset *next; } *fset; struct s_paramlist *fshape; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { int integer; char *str; struct s_rule { enum e_nodo { AND_N=0, OR_N=1, NOT_N=2, IS_N=3, ID_N=4 } tipo; struct s_rule *destro; struct s_rule *sinistro; void *dati; char *nome; } *nodo; struct s_rulebase { struct s_rule *rule; struct s_rule *target; struct s_rulebase *nextRule; } *regola; struct s_fuzzyset { char *label; struct s_paramlist { int paramNumber; int param[4]; } *parameters; double (*mfunction)(struct s_paramlist *parameters, int value); struct s_fuzzyset *next; } *fset; struct s_paramlist *fshape; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union YYSTYPE { int integer; char *str; struct s_rule *nodo; struct s_rulebase *regola; struct s_fuzzyset *fset; struct s_paramlist *fshape; }

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }


yyerror

decompiled_code:
__int64 __fastcall yyerror(const char *a1)
{
puts(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
puts(a1);
return 0LL;
}

original_code:
int yyerror(char * msg)
{
 printf("%s\n", msg);
 return 0;
}

canonical_original_code:
int yyerror(char *msg)
{
 printf("%s\n", msg);
 return 0;
}

variable_types:
msg
char *


repo: boutrosc/CS-Projects

decompiled_code:
int __fastcall lizard_sleep(unsigned int a1)
{
unsigned int v1; // ebp
int result; // eax

v1 = (int)((double)(int)random() / 2147483647.0 * 3.0) + 1;
if ( debug )
{
printf("[%2d] sleeping for %d seconds\n", a1, v1);
fflush(_bss_start);
}
sleep(v1);
result = debug;
if ( debug )
{
printf("[%2d] awake\n", a1);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
unsigned int v1; // ebp
int result; // eax

v1 = (int)((double)(int)random() / 2147483647.0 * 3.0) + 1;
if ( debug )
{
printf("[%2d] sleeping for %d seconds\n", a1, v1);
fflush(_bss_start);
}
sleep(v1);
result = debug;
if ( debug )
{
printf("[%2d] awake\n", a1);
result = fflush(_bss_start);
}
return result;
}

original_code:
void lizard_sleep(int num) {
 int sleepSeconds;
 sleepSeconds = 1 + (int) (random() / (double) 2147483647 * 3);
 if (debug) {
  printf("[%2d] sleeping for %d seconds\n", num, sleepSeconds);
  fflush( stdout);
 }
 sleep(sleepSeconds);
 if (debug) {
  printf("[%2d] awake\n", num);
  fflush( stdout);
 }
}

variable_types: num int

variable_types: sleepSeconds int


decompiled_code:
int __fastcall sago_2_monkeyGrass_is_safe(unsigned int a1)
{
int result; // eax

if ( debug )
{
printf("[%2d] checking sago -> monkey grass\n", a1);
fflush(_bss_start);
}
sem_wait(&empty);
pthread_mutex_lock(&mutex);
++numCrossingSago2MonkeyGrass;
pthread_mutex_unlock(&mutex);
sem_post(&full);
result = debug;
if ( debug )
{
printf("[%2d] thinks sago -> monkey grass is safe\n", a1);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
int result; // eax

if ( debug )
{
printf("[%2d] checking sago -> monkey grass\n", a1);
fflush(_bss_start);
}
sem_wait(&empty);
pthread_mutex_lock(&mutex);
++numCrossingSago2MonkeyGrass;
pthread_mutex_unlock(&mutex);
sem_post(&full);
result = debug;
if ( debug )
{
printf("[%2d] thinks sago -> monkey grass is safe\n", a1);
result = fflush(_bss_start);
}
return result;
}

original_code:
void sago_2_monkeyGrass_is_safe(int num) {
 if (debug) {
  printf("[%2d] checking  sago -> monkey grass\n", num);
  fflush( stdout);
 }
 sem_wait(&empty);
 pthread_mutex_lock(&mutex);
 numCrossingSago2MonkeyGrass++;
 pthread_mutex_unlock(&mutex);
 sem_post(&full);
 if (debug) {
  printf("[%2d] thinks  sago -> monkey grass  is safe\n", num);
  fflush( stdout);
 }
}


decompiled_code:
int __fastcall cross_sago_2_monkeyGrass(unsigned int a1)
{
if ( debug )
{
printf("[%2d] crossing sago -> monkey grass\n", a1);
fflush(_bss_start);
}
if ( numCrossingSago2MonkeyGrass + numCrossingMonkeyGrass2Sago > 4 )
{
puts("\tThe cats are happy - they have toys.");
printf("\t%d crossing sago -> monkey grass\n", (unsigned int)numCrossingSago2MonkeyGrass);
exit(-1);
}
sleep(2u);
sem_wait(&full);
pthread_mutex_lock(&mutex);
--numCrossingSago2MonkeyGrass;
pthread_mutex_unlock(&mutex);
return sem_post(&empty);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
if ( debug )
{
printf("[%2d] crossing sago -> monkey grass\n", a1);
fflush(_bss_start);
}
if ( numCrossingSago2MonkeyGrass + numCrossingMonkeyGrass2Sago > 4 )
{
puts("\tThe cats are happy - they have toys.");
printf("\t%d crossing sago -> monkey grass\n", (unsigned int)numCrossingSago2MonkeyGrass);
exit(-1);
}
sleep(2u);
sem_wait(&full);
pthread_mutex_lock(&mutex);
--numCrossingSago2MonkeyGrass;
pthread_mutex_unlock(&mutex);
return sem_post(&empty);
}

original_code:
void cross_sago_2_monkeyGrass(int num) {
 if (debug) {
  printf("[%2d] crossing  sago -> monkey grass\n", num);
  fflush( stdout);
 }
 if (numCrossingSago2MonkeyGrass
   + numCrossingMonkeyGrass2Sago> 4) {
  printf("\tThe cats are happy - they have toys.\n");
  printf("\t%d crossing sago -> monkey grass\n",
    numCrossingSago2MonkeyGrass);
  exit(-1);
 }
 if (numCrossingMonkeyGrass2Sago && 0) {
  printf("\tCrash!  We have a pile-up on the concrete.\n");
  printf("\t%d crossing sago -> monkey grass\n",
    numCrossingSago2MonkeyGrass);
  printf("\t%d crossing monkey grass -> sago\n",
    numCrossingMonkeyGrass2Sago);
  exit(-1);
 }
 sleep( 2);
 sem_wait(&full);
 pthread_mutex_lock(&mutex);
 numCrossingSago2MonkeyGrass--;
 pthread_mutex_unlock(&mutex);
 sem_post(&empty);
}


decompiled_code:
int __fastcall made_it_2_monkeyGrass(unsigned int a1)
{
int result; // eax

result = debug;
if ( debug )
{
printf("[%2d] made the sago -> monkey grass crossing\n", a1);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
int result; // eax

result = debug;
if ( debug )
{
printf("[%2d] made the sago -> monkey grass crossing\n", a1);
result = fflush(_bss_start);
}
return result;
}

original_code:
void made_it_2_monkeyGrass(int num) {
 if (debug) {
  printf("[%2d] made the  sago -> monkey grass  crossing\n", num);
  fflush( stdout);
 }
}


decompiled_code:
int __fastcall lizard_eat(unsigned int a1)
{
unsigned int v1; // ebp
int result; // eax

v1 = (int)((double)(int)random() / 2147483647.0 * 5.0) + 1;
if ( debug )
{
printf("[%2d] eating for %d seconds\n", a1, v1);
fflush(_bss_start);
}
sleep(v1);
result = debug;
if ( debug )
{
printf("[%2d] finished eating\n", a1);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(unsigned int a1)
{
unsigned int v1; // ebp
int result; // eax

v1 = (int)((double)(int)random() / 2147483647.0 * 5.0) + 1;
if ( debug )
{
printf("[%2d] eating for %d seconds\n", a1, v1);
fflush(_bss_start);
}
sleep(v1);
result = debug;
if ( debug )
{
printf("[%2d] finished eating\n", a1);
result = fflush(_bss_start);
}
return result;
}

original_code:
void lizard_eat(int num) {
 int eatSeconds;
 eatSeconds = 1 + (int) (random() / (double) 2147483647 * 5);
 if (debug) {
  printf("[%2d] eating for %d seconds\n", num, eatSeconds);
  fflush( stdout);
 }
 sleep(eatSeconds);
 if (debug) {
  printf("[%2d] finished eating\n", num);
  fflush( stdout);
 }
}

variable_types: eatSeconds int


decompiled_code:
int __fastcall monkeyGrass_2_sago_is_safe(unsigned int a1)
{
int result; // eax

if ( debug )
{
printf("[%2d] checking monkey grass -> sago\n", a1);
fflush(_bss_start);
}
sem_wait(&empty);
pthread_mutex_lock(&mutex);
++numCrossingMonkeyGrass2Sago;
pthread_mutex_unlock(&mutex);
sem_post(&full);
result = debug;
if ( debug )
{
printf("[%2d] thinks monkey grass -> sago is safe\n", a1);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1)
{
int result; // eax

if ( debug )
{
printf("[%2d] checking monkey grass -> sago\n", a1);
fflush(_bss_start);
}
sem_wait(&empty);
pthread_mutex_lock(&mutex);
++numCrossingMonkeyGrass2Sago;
pthread_mutex_unlock(&mutex);
sem_post(&full);
result = debug;
if ( debug )
{
printf("[%2d] thinks monkey grass -> sago is safe\n", a1);
result = fflush(_bss_start);
}
return result;
}

original_code:
void monkeyGrass_2_sago_is_safe(int num) {
 if (debug) {
  printf("[%2d] checking  monkey grass -> sago\n", num);
  fflush( stdout);
 }
 sem_wait(&empty);
 pthread_mutex_lock(&mutex);
 numCrossingMonkeyGrass2Sago++;
 pthread_mutex_unlock(&mutex);
 sem_post(&full);
 if (debug) {
  printf("[%2d] thinks  monkey grass -> sago  is safe\n", num);
  fflush( stdout);
 }
}


decompiled_code:
int __fastcall cross_monkeyGrass_2_sago(unsigned int a1)
{
if ( debug )
{
printf("[%2d] crossing monkey grass -> sago\n", a1);
fflush(_bss_start);
}
if ( numCrossingMonkeyGrass2Sago + numCrossingSago2MonkeyGrass > 4 )
{
puts("\tThe cats say yum! - they love lizards.");
printf("\t%d crossing monkey grass -> sago\n", (unsigned int)numCrossingMonkeyGrass2Sago);
exit(-1);
}
sleep(2u);
sem_wait(&full);
pthread_mutex_lock(&mutex);
--numCrossingMonkeyGrass2Sago;
pthread_mutex_unlock(&mutex);
return sem_post(&empty);
}

canonical_decompiled_code:
int __fastcall func13(unsigned int a1)
{
if ( debug )
{
printf("[%2d] crossing monkey grass -> sago\n", a1);
fflush(_bss_start);
}
if ( numCrossingMonkeyGrass2Sago + numCrossingSago2MonkeyGrass > 4 )
{
puts("\tThe cats say yum! - they love lizards.");
printf("\t%d crossing monkey grass -> sago\n", (unsigned int)numCrossingMonkeyGrass2Sago);
exit(-1);
}
sleep(2u);
sem_wait(&full);
pthread_mutex_lock(&mutex);
--numCrossingMonkeyGrass2Sago;
pthread_mutex_unlock(&mutex);
return sem_post(&empty);
}

original_code:
void cross_monkeyGrass_2_sago(int num) {
 if (debug) {
  printf("[%2d] crossing  monkey grass -> sago\n", num);
  fflush( stdout);
 }
 if (numCrossingMonkeyGrass2Sago
   + numCrossingSago2MonkeyGrass> 4) {
  printf("\tThe cats say yum! - they love lizards.\n");
  printf("\t%d crossing monkey grass -> sago\n",
    numCrossingMonkeyGrass2Sago);
  exit(-1);
 }
 if (numCrossingSago2MonkeyGrass && 0) {
  printf("\tOh No!, the lizards have cats all over them.\n");
  printf("\t%d crossing sago -> monkey grass\n",
    numCrossingSago2MonkeyGrass);
  printf("\t%d crossing monkey grass -> sago\n",
    numCrossingMonkeyGrass2Sago);
  exit(-1);
 }
 sleep( 2);
 sem_wait(&full);
 pthread_mutex_lock(&mutex);
 numCrossingMonkeyGrass2Sago--;
 pthread_mutex_unlock(&mutex);
 sem_post(&empty);
}


decompiled_code:
int __fastcall made_it_2_sago(unsigned int a1)
{
int result; // eax

result = debug;
if ( debug )
{
printf("[%2d] made the monkey grass -> sago crossing\n", a1);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(unsigned int a1)
{
int result; // eax

result = debug;
if ( debug )
{
printf("[%2d] made the monkey grass -> sago crossing\n", a1);
result = fflush(_bss_start);
}
return result;
}

original_code:
void made_it_2_sago(int num) {
 if (debug) {
  printf("[%2d] made the  monkey grass -> sago  crossing\n", num);
  fflush( stdout);
 }
}


lizardThread

decompiled_code:
void __fastcall __noreturn lizardThread(void *a1)
{
if ( debug )
{
printf("[%2d] lizard is alive\n", (unsigned int)a1);
fflush(_bss_start);
}
while ( running )
{
lizard_sleep((unsigned int)a1);
sago_2_monkeyGrass_is_safe((unsigned int)a1);
cross_sago_2_monkeyGrass((unsigned int)a1);
made_it_2_monkeyGrass((unsigned int)a1);
lizard_eat((unsigned int)a1);
monkeyGrass_2_sago_is_safe((unsigned int)a1);
cross_monkeyGrass_2_sago((unsigned int)a1);
made_it_2_sago((unsigned int)a1);
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func15(void *a1)
{
if ( debug )
{
printf("[%2d] lizard is alive\n", (unsigned int)a1);
fflush(_bss_start);
}
while ( running )
{
func7((unsigned int)a1);
func8((unsigned int)a1);
func9((unsigned int)a1);
func10((unsigned int)a1);
func11((unsigned int)a1);
func12((unsigned int)a1);
func13((unsigned int)a1);
func14((unsigned int)a1);
}
pthread_exit(0LL);
}

original_code:
void * lizardThread(void * param) {
 int num = (int) (intptr_t) param;
 if (debug) {
  printf("[%2d] lizard is alive\n", num);
  fflush(stdout);
 }
    while(running){
        lizard_sleep(num);
        sago_2_monkeyGrass_is_safe(num);
        cross_sago_2_monkeyGrass(num);
        made_it_2_monkeyGrass(num);
        lizard_eat(num);
        monkeyGrass_2_sago_is_safe(num);
        cross_monkeyGrass_2_sago(num);
        made_it_2_sago(num);
    }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *lizardThread(void *param) {
 int num = (int) (intptr_t) param;
 if (debug) {
  printf("[%2d] lizard is alive\n", num);
  fflush(stdout);
 }
    while(running){
        lizard_sleep(num);
        sago_2_monkeyGrass_is_safe(num);
        cross_sago_2_monkeyGrass(num);
        made_it_2_monkeyGrass(num);
        lizard_eat(num);
        monkeyGrass_2_sago_is_safe(num);
        cross_monkeyGrass_2_sago(num);
        made_it_2_sago(num);
    }
 pthread_exit(((void *)0));
}

variable_types:
param
void *

return_type: void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
char *v4; // rbp
pthread_t *v5; // r12
unsigned int v6; // eax
pthread_t v7; // rdi
_BYTE v9[160]; // [rsp+0h] [rbp-B8h] BYREF
__int64 v10; // [rsp+A0h] [rbp-18h] BYREF

debug = 0;
if ( argc > 1 && !strncmp(argv[1], "-d", 2uLL) )
debug = 1;
v3 = (pthread_t *)v9;
v4 = 0LL;
numCrossingSago2MonkeyGrass = 0;
numCrossingMonkeyGrass2Sago = 0;
v5 = (pthread_t *)v9;
running = 1;
v6 = time(0LL);
srandom(v6);
sem_init(&empty, 0, 4u);
sem_init(&full, 0, 0);
do
pthread_create(v5++, 0LL, lizardThread, v4++);
while ( v4 != (char *)20 );
sleep(0x1Eu);
running = 0;
do
{
v7 = *v3++;
pthread_join(v7, 0LL);
}
while ( &v10 != (__int64 *)v3 );
pthread_mutex_destroy(&mutex);
sem_destroy(&empty);
sem_destroy(&full);
return 0;
}

original_code:
int main(int argc, char **argv) {
 int i;
 pthread_t threads[20];
 debug = 0;
 if (argc > 1)
  if (strncmp(argv[1], "-d", 2) == 0)
   debug = 1;
 numCrossingSago2MonkeyGrass = 0;
 numCrossingMonkeyGrass2Sago = 0;
 running = 1;
 srandom((unsigned int) time(((void *)0)));
 sem_init(&empty, 0, 4);
 sem_init(&full, 0, 0);
 for (i = 0; i < 20; i++)
  pthread_create(&threads[i], ((void *)0), lizardThread, (void*) (intptr_t) i);
 sleep( 30);
 running = 0;
 for (i = 0; i < 20; i++)
  pthread_join(threads[i], ((void *)0));
 pthread_mutex_destroy(&mutex);
 sem_destroy(&empty);
 sem_destroy(&full);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int i;
 unsigned long threads[20];
 debug = 0;
 if (argc > 1)
  if (strncmp(argv[1], "-d", 2) == 0)
   debug = 1;
 numCrossingSago2MonkeyGrass = 0;
 numCrossingMonkeyGrass2Sago = 0;
 running = 1;
 srandom((unsigned int) time(((void *)0)));
 sem_init(&empty, 0, 4);
 sem_init(&full, 0, 0);
 for (i = 0; i < 20; i++)
  pthread_create(&threads[i], ((void *)0), lizardThread, (void *) (long) i);
 sleep( 30);
 running = 0;
 for (i = 0; i < 20; i++)
  pthread_join(threads[i], ((void *)0));
 pthread_mutex_destroy(&mutex);
 sem_destroy(&empty);
 sem_destroy(&full);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types:
threads
unsigned long [20]


input

decompiled_code:
__int64 __fastcall input(__int64 a1, char *a2)
{
reset(a1);
printf("$ ");
fgets(a2, 150, stdin);
return parse(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, char *a2)
{
func13(a1);
printf("$ ");
fgets(a2, 150, stdin);
return func18(a1, a2);
}

original_code:
void input() {
    int itemNum, itemMin, itemMax, binNum, binMin, binMax;
    char fname[20];
    printf("Name output file : \n");
    scanf("%s", fname);
    printf("Number of items : \n");
    scanf("%i", &itemNum);
    printf("Min range of item weight : \n");
    scanf("%i", &itemMin);
    printf("Max range of item weight : \n");
    scanf("%i", &itemMax);
    printf("Number of bins : \n");
    scanf("%i", &binNum);
    printf("Min range of bin weight : \n");
    scanf("%i", &binMin);
    printf("Max range of bin weight : \n");
    scanf("%i", &binMax);
    process(fname, itemNum, itemMin, itemMax, binNum, binMin, binMax);
}

canonical_original_code:
void input() {
    int itemNum; int itemMin; int itemMax; int binNum; int binMin; int binMax;
    char fname[20];
    printf("Name output file : \n");
    scanf("%s", fname);
    printf("Number of items : \n");
    scanf("%i", &itemNum);
    printf("Min range of item weight : \n");
    scanf("%i", &itemMin);
    printf("Max range of item weight : \n");
    scanf("%i", &itemMax);
    printf("Number of bins : \n");
    scanf("%i", &binNum);
    printf("Min range of bin weight : \n");
    scanf("%i", &binMin);
    printf("Max range of bin weight : \n");
    scanf("%i", &binMax);
    process(fname, itemNum, itemMin, itemMax, binNum, binMin, binMax);
}

variable_types: itemNum int

variable_types: itemMin int

variable_types: itemMax int

variable_types: binNum int

variable_types: binMin int

variable_types: binMax int

variable_types:
fname
char [20]


parse

decompiled_code:
void __fastcall parse(__int64 a1, char *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rbp
int v4; // eax

handleBlank(a1, a2);
v2 = strtok(a2, " \t\n");
if ( v2 )
{
v3 = (unsigned __int8 *)v2;
do
{
while ( (*v3 & 0xFD) == 60 )
{
handleSpace(a1, v3, a2);
handleInRedir((char **)a1, (char *)v3);
v3 = (unsigned __int8 *)strtok(0LL, " \t\n");
if ( !v3 )
goto LABEL_6;
}
v4 = *(_DWORD *)(a1 + 20);
*(_QWORD *)(a1 + 8LL * v4 + 24) = v3;
*(_DWORD *)(a1 + 20) = v4 + 1;
v3 = (unsigned __int8 *)strtok(0LL, " \t\n");
}
while ( v3 );
}
LABEL_6:
handleAmpersand(a1, a2);
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1, char *a2)
{
char *v2; // rax
unsigned __int8 *v3; // rbp
int v4; // eax

func15(a1, a2);
v2 = strtok(a2, " \t\n");
if ( v2 )
{
v3 = (unsigned __int8 *)v2;
do
{
while ( (*v3 & 0xFD) == 60 )
{
func16(a1, v3, a2);
func12((char **)a1, (char *)v3);
v3 = (unsigned __int8 *)strtok(0LL, " \t\n");
if ( !v3 )
goto LABEL_6;
}
v4 = *(_DWORD *)(a1 + 20);
*(_QWORD *)(a1 + 8LL * v4 + 24) = v3;
*(_DWORD *)(a1 + 20) = v4 + 1;
v3 = (unsigned __int8 *)strtok(0LL, " \t\n");
}
while ( v3 );
}
LABEL_6:
func17(a1, a2);
}

original_code:
void* parse(void* conn) {
 char buffer[256], *temp;
 bzero(buffer, 256);
 int connection = *((int*) conn);
 recv(connection, buffer, sizeof(buffer), 0);
 if (debug)
  fprintf(stdout, "Request: %s", buffer);
 if (strncmp(buffer, "<", 1) != 0)
  error(&connection);
 else if (parseEcho(&connection, buffer, &temp) == -1)
  parseLoadAvg(&connection, &temp);
 pthread_exit(((void *)0));
 return ((void *)0);
}

canonical_original_code:
void *parse(void *conn) {
 char buffer[256]; char *temp;
 bzero(buffer, 256);
 int connection = *((int*) conn);
 recv(connection, buffer, sizeof(buffer), 0);
 if (debug)
  fprintf(stdout, "Request: %s", buffer);
 if (strncmp(buffer, "<", 1) != 0)
  error(&connection);
 else if (parseEcho(&connection, buffer, &temp) == -1)
  parseLoadAvg(&connection, &temp);
 pthread_exit(((void *)0));
 return ((void *)0);
}

variable_types:
conn
void *

variable_types:
buffer
char [256]

variable_types:
temp
char *

variable_types: connection int


handleInput

decompiled_code:
void __fastcall handleInput(int a1)
{
if ( a1 != 3 )
{
fwrite("Invalid Arguements\n", 1uLL, 0x13uLL, stderr);
fwrite("Usage: <hostname> <portnum>\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( a1 != 3 )
{
fwrite("Invalid Arguements\n", 1uLL, 0x13uLL, stderr);
fwrite("Usage: <hostname> <portnum>\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
}

original_code:
void handleInput(int argc) {
 if (argc != 3) {
  fprintf(stderr, "Usage : <maxNumbers> <numberOfThreads>\n");
  exit(1);
 }
}


createSocket

decompiled_code:
__int64 __fastcall createSocket(const char *a1, __int16 a2, __m128i *a3)
{
unsigned int v4; // er12
void *v5; // rdx
__m128i v7; // [rsp+0h] [rbp-38h] BYREF

a3->m128i_i64[0] = 0LL;
v4 = socket(2, 1, 0);
if ( v4 == -1 )
{
perror("Socket error");
}
else
{
a3->m128i_i16[0] = 2;
a3->m128i_i16[1] = _bswap_16(a2);
if ( inet_pton(2, a1, v5) <= 0 )
{
v4 = -1;
perror("inet_pton error");
}
else
{
v7 = _mm_loadu_si128(a3);
if ( connect(v4, (const struct sockaddr *)&v7, 0x10u) < 0 )
{
v4 = -1;
perror("Socket connection error");
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int16 a2, __m128i *a3)
{
unsigned int v4; // er12
void *v5; // rdx
__m128i v7; // [rsp+0h] [rbp-38h] BYREF

a3->m128i_i64[0] = 0LL;
v4 = socket(2, 1, 0);
if ( v4 == -1 )
{
perror("Socket error");
}
else
{
a3->m128i_i16[0] = 2;
a3->m128i_i16[1] = func9(a2);
if ( inet_pton(2, a1, v5) <= 0 )
{
v4 = -1;
perror("inet_pton error");
}
else
{
v7 = _mm_loadu_si128(a3);
if ( connect(v4, (const struct sockaddr *)&v7, 0x10u) < 0 )
{
v4 = -1;
perror("Socket connection error");
}
}
}
return v4;
}

original_code:
int createSocket(struct sockaddr_in *servaddr, int port) {
 int sockfd;
 sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP);
 if (sockfd < 0) {
  return -1;
 }
 bzero(servaddr, sizeof(struct sockaddr_in *));
 servaddr->sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 servaddr->sin_port = htons(port);
 struct sockaddr_in serv_addr = *servaddr;
 if (bind(sockfd, (struct sockaddr *) &serv_addr,
   (socklen_t) sizeof(serv_addr)) == -1) {
  perror("Bind error");
  exit(0);
 }
 struct sockaddr_in boundAddr;
 socklen_t sizeAddr = sizeof(boundAddr);
 getsockname(sockfd, (struct sockaddr *) &boundAddr, &sizeAddr);
 printf("Port: %d\n\n", ntohs(servaddr->sin_port));
 return sockfd;
}

canonical_original_code:
int createSocket(struct sockaddr_in *servaddr, int port) {
 int sockfd;
 sockfd = socket(2, SOCK_DGRAM, IPPROTO_UDP);
 if (sockfd < 0) {
  return -1;
 }
 bzero(servaddr, sizeof(struct sockaddr_in *));
 servaddr->sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 servaddr->sin_port = htons(port);
 struct sockaddr_in serv_addr = *servaddr;
 if (bind(sockfd, (struct sockaddr *) &serv_addr,
   (unsigned int) sizeof(serv_addr)) == -1) {
  perror("Bind error");
  exit(0);
 }
 struct sockaddr_in boundAddr;
 unsigned int sizeAddr = sizeof(boundAddr);
 getsockname(sockfd, (struct sockaddr *) &boundAddr, &sizeAddr);
 printf("Port: %d\n\n", ntohs(servaddr->sin_port));
 return sockfd;
}

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

variable_types: port int

variable_types: sockfd int

variable_types:
sizeAddr
unsigned int

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

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