original_code:
char *apply_subs(const char *p) {
  int i;
  char *q[2];
  q[0] = str_replace(p, rep.d[0][0], rep.d[0][1]);
  for(i=1;i<rep.l;i++)
    q[i%2] = str_replace(q[(i+1)%2], rep.d[i][0], rep.d[i][1]);
  return q[(i+1)%2];
}

canonical_original_code:
char *apply_subs(char *p) {
  int i;
  char *q[2];
  q[0] = str_replace(p, rep.d[0][0], rep.d[0][1]);
  for(i=1;i<rep.l;i++)
    q[i%2] = str_replace(q[(i+1)%2], rep.d[i][0], rep.d[i][1]);
  return q[(i+1)%2];
}

variable_types:
p
char *

variable_types: i int

variable_types:
q
char *[2]


main

canonical_name: main

repo: boopathi/cps

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // r14
size_t v5; // rax
char *v6; // rbp
size_t i; // rbx
char v8; // al
_BYTE *v9; // rdx
char *v10; // rcx
char v11; // al
_BYTE *v12; // rdx
int v13; // eax
int v14; // edx
int v15; // eax
int v16; // edx
char *v17; // rdi
int v18; // edx
int *v20; // rax
int v21; // edx

dword_484120 = 0;
args = 0;
dword_484144 = 0;
dword_484148 = 0;
while ( 1 )
{
v13 = getopt(argc, (char *const *)argv, "akvs:");
if ( v13 == -1 )
break;
if ( v13 == 115 )
goto LABEL_4;
if ( v13 > 115 )
{
if ( v13 != 118 )
goto LABEL_25;
dword_484148 = 1;
LABEL_4:
v4 = argv[optind - 1];
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
for ( i = 0LL; strlen(v4) > i; ++i )
v6[i] = v4[i];
v8 = *v6;
if ( *v6 != 47 && v8 )
{
v9 = (_BYTE *)(((__int64)dword_484120 << 9) + 4210976);
do
{
++v6;
*v9 = v8;
v8 = *v6;
++v9;
}
while ( *v6 != 47 && v8 );
}
v10 = v6 + 1;
v11 = v6[1];
if ( v11 != 47 && v11 )
{
v12 = (_BYTE *)(((__int64)dword_484120 << 9) + 4211232);
do
{
++v10;
*v12 = v11;
v11 = *v10;
++v12;
}
while ( *v10 != 47 && v11 );
}
++dword_484120;
*v10 = 0;
}
else if ( v13 == 97 )
{
args = 1;
}
else
{
if ( v13 != 107 )
{
LABEL_25:
print_help();
abort();
}
dword_484144 = 1;
}
}
v15 = optind;
if ( optind >= argc )
print_error(1, "Source Directory/filename not specified", v14);
v16 = ++optind;
v17 = (char *)argv[v15];
qword_484150 = (__int64)v17;
if ( v15 + 1 >= argc )
print_error(2, "Target linkname not specified", v16);
optind = v15 + 2;
filename = (char *)argv[v15 + 1];
if ( (unsigned int)stat(v17, &stat_buf) )
{
v20 = __errno_location();
print_error(*v20, "No such file/directory specified as SOURCE", v21);
}
if ( !(unsigned int)stat(filename, &unk_4841F0) )
print_error(17, "TARGET already exists.", v18);
make_tree((char *)qword_484150, filename);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // r14
size_t v5; // rax
char *v6; // rbp
size_t i; // rbx
char v8; // al
_BYTE *v9; // rdx
char *v10; // rcx
char v11; // al
_BYTE *v12; // rdx
int v13; // eax
int v14; // edx
int v15; // eax
int v16; // edx
char *v17; // rdi
int v18; // edx
int *v20; // rax
int v21; // edx

dword_484120 = 0;
args = 0;
dword_484144 = 0;
dword_484148 = 0;
while ( 1 )
{
v13 = getopt(argc, (char *const *)argv, "akvs:");
if ( v13 == -1 )
break;
if ( v13 == 115 )
goto LABEL_4;
if ( v13 > 115 )
{
if ( v13 != 118 )
goto LABEL_25;
dword_484148 = 1;
LABEL_4:
v4 = argv[optind - 1];
v5 = strlen(v4);
v6 = (char *)malloc(v5 + 1);
for ( i = 0LL; strlen(v4) > i; ++i )
v6[i] = v4[i];
v8 = *v6;
if ( *v6 != 47 && v8 )
{
v9 = (_BYTE *)(((__int64)dword_484120 << 9) + 4210976);
do
{
++v6;
*v9 = v8;
v8 = *v6;
++v9;
}
while ( *v6 != 47 && v8 );
}
v10 = v6 + 1;
v11 = v6[1];
if ( v11 != 47 && v11 )
{
v12 = (_BYTE *)(((__int64)dword_484120 << 9) + 4211232);
do
{
++v10;
*v12 = v11;
v11 = *v10;
++v12;
}
while ( *v10 != 47 && v11 );
}
++dword_484120;
*v10 = 0;
}
else if ( v13 == 97 )
{
args = 1;
}
else
{
if ( v13 != 107 )
{
LABEL_25:
func7();
abort();
}
dword_484144 = 1;
}
}
v15 = optind;
if ( optind >= argc )
func8(1, "Source Directory/filename not specified", v14);
v16 = ++optind;
v17 = (char *)argv[v15];
qword_484150 = (__int64)v17;
if ( v15 + 1 >= argc )
func8(2, "Target linkname not specified", v16);
optind = v15 + 2;
filename = (char *)argv[v15 + 1];
if ( (unsigned int)func14(v17, &stat_buf) )
{
v20 = __errno_location();
func8(*v20, "No such file/directory specified as SOURCE", v21);
}
if ( !(unsigned int)func14(filename, &unk_4841F0) )
func8(17, "TARGET already exists.", v18);
func11((char *)qword_484150, filename);
return 0;
}

original_code:
int main(int argc, char **argv) {
  int c,i;
  char *s, *where, *tmp;
  rep.l = 0;
  args.absolute = 0;
  args.skip = 0;
  args.verbose = 0;
  while( (c = getopt(argc, argv, "akvs:")) != -1) {
    switch(c) {
    case 'a':
      args.absolute = 1;
      break;
    case 'k':
      args.skip = 1;
      break;
    case 'v':
      args.verbose = 1;
    case 's':
      optind--;
      tmp = argv[optind++];
      s = malloc(strlen(tmp) + 1);
      for(i=0;i<strlen(tmp);i++) s[i] = tmp[i];
      i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][0][i++] = *s++;
      s++; i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][1][i++] = *s++;
      rep.l++;
      *s = 0;
      break;
    default:
      print_help();
      abort();
    }
  }
  if(optind < argc) args.source = argv[optind++];
  else print_error(1,"Source Directory/filename not specified");
  if(optind < argc) args.target = argv[optind++];
  else print_error(2,"Target linkname not specified");
  if(stat(args.source, &(args.sstat)) != 0) print_error((*__errno_location ()), "No such file/directory specified as SOURCE");
  if(stat(args.target, &(args.tstat)) != 0)
    make_tree(args.source, args.target);
  else print_error(17, "TARGET already exists.");
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  int c; int i;
  char *s; char *where; char *tmp;
  rep.l = 0;
  args.absolute = 0;
  args.skip = 0;
  args.verbose = 0;
  while( (c = getopt(argc, argv, "akvs:")) != -1) {
    switch(c) {
    case 'a':
      args.absolute = 1;
      break;
    case 'k':
      args.skip = 1;
      break;
    case 'v':
      args.verbose = 1;
    case 's':
      optind--;
      tmp = argv[optind++];
      s = malloc(strlen(tmp) + 1);
      for(i=0;i<strlen(tmp);i++) s[i] = tmp[i];
      i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][0][i++] = *s++;
      s++; i=0;
      while(*s != '/' && *s != '\0') rep.d[rep.l][1][i++] = *s++;
      rep.l++;
      *s = 0;
      break;
    default:
      print_help();
      abort();
    }
  }
  if(optind < argc) args.source = argv[optind++];
  else print_error(1,"Source Directory/filename not specified");
  if(optind < argc) args.target = argv[optind++];
  else print_error(2,"Target linkname not specified");
  if(stat(args.source, &(args.sstat)) != 0) print_error((*__errno_location ()), "No such file/directory specified as SOURCE");
  if(stat(args.target, &(args.tstat)) != 0)
    make_tree(args.source, args.target);
  else print_error(17, "TARGET already exists.");
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types:
s
char *

variable_types:
where
char *

variable_types:
tmp
char *

return_type: int


decompiled_code:
int __fastcall show_last_move(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("%s", a1);
}

original_code:
static void show_last_move(const char *move)
{
    printf("%s", move);
}

canonical_original_code:
static void show_last_move(char *move)
{
    printf("%s", move);
}

variable_types:
move
char *

return_type: void


decompiled_code:
__int64 __fastcall str_to_bool(const char *a1)
{
return (strcmp(a1, "Y") == 0) | (unsigned __int8)(strcmp(a1, "y") == 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
return (strcmp(a1, "Y") == 0) | (unsigned __int8)(strcmp(a1, "y") == 0);
}

original_code:
static int str_to_bool(char *choice)
{
    return ((strcmp(choice, "y") == 0) | (strcmp(choice, "Y") == 0));
}

variable_types:
choice
char *


decompiled_code:
int __fastcall parse_choice(char *a1, __int64 a2, _DWORD *a3)
{
char *v4; // rdi
int result; // eax
int v6; // edx

v4 = strtok(a1, ",");
if ( !v4 )
return 1;
while ( 1 )
{
result = atoi(v4);
if ( !result )
break;
v6 = (*a3)++;
*(_DWORD *)(a2 + 4LL * v6) = result - 1;
v4 = strtok(0LL, ",");
if ( !v4 )
return 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *a1, __int64 a2, _DWORD *a3)
{
char *v4; // rdi
int result; // eax
int v6; // edx

v4 = strtok(a1, ",");
if ( !v4 )
return 1;
while ( 1 )
{
result = atoi(v4);
if ( !result )
break;
v6 = (*a3)++;
*(_DWORD *)(a2 + 4LL * v6) = result - 1;
v4 = strtok(0LL, ",");
if ( !v4 )
return 1;
}
return result;
}

original_code:
static int parse_choice(char choice[], int card_choices[], int *num_choices)
{
    char *result = ((void *)0);
    int to_int;
    result = strtok(choice, "," );
    while( result != ((void *)0) ) {
        to_int = atoi(result);
        if (to_int == 0) {
            return 0;
        }
        else {
            card_choices[(*num_choices)++] = to_int-1;
            result = strtok( ((void *)0), "," );
        }
    }
    return 1;
}

variable_types:
choice
char []

variable_types:
result
char *


newline

decompiled_code:
int newline()
{
return putchar(10);
}

canonical_decompiled_code:
int func3()
{
return putchar(10);
}

original_code:
void newline()
{
    printf("\n");
}

canonical_original_code:
void newline()
{
    printf("\n");
}


decompiled_code:
void __fastcall show_cards(__int64 a1, int a2)
{
int v3; // ebx
const char *v4; // r12
const char *v5; // rax

if ( a2 > 0 )
{
v3 = 1;
do
{
v4 = (const char *)show_suit(a1);
v5 = (const char *)show_rank(a1);
printf("(%d)%s of %s", (unsigned int)v3, v5, v4);
if ( a2 <= v3 )
newline();
else
printf(", ");
++v3;
a1 += 8LL;
}
while ( v3 != a2 + 1 );
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
int v3; // ebx
const char *v4; // r12
const char *v5; // rax

if ( a2 > 0 )
{
v3 = 1;
do
{
v4 = (const char *)show_suit(a1);
v5 = (const char *)show_rank(a1);
printf("(%d)%s of %s", (unsigned int)v3, v5, v4);
if ( a2 <= v3 )
func3();
else
printf(", ");
++v3;
a1 += 8LL;
}
while ( v3 != a2 + 1 );
}
}

original_code:
static void show_cards(const struct card_t *cards, const int num_cards)
{
    int i;
    int j = 1;
    for (i = 0 ; i< num_cards ; i++) {
        printf("(%d)%s of %s", j, show_rank(&cards[i]), show_suit(&cards[i]));
        if (j <= (num_cards - 1))
            printf(", ");
        else
            newline();
        j++;
    }
}

canonical_original_code:
static void show_cards(struct card_t *cards, int num_cards)
{
    int i;
    int j = 1;
    for (i = 0 ; i< num_cards ; i++) {
        printf("(%d)%s of %s", j, show_rank(&cards[i]), show_suit(&cards[i]));
        if (j <= (num_cards - 1))
            printf(", ");
        else
            newline();
        j++;
    }
}

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; } *

variable_types: j int

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


decompiled_code:
int __fastcall hide_cards(int a1)
{
int v1; // ebx
int result; // eax

if ( a1 > 0 )
{
v1 = 1;
do
{
printf("(%d)****", (unsigned int)v1);
if ( a1 <= v1 )
result = newline();
else
result = printf(", ");
++v1;
}
while ( a1 + 1 != v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int v1; // ebx
int result; // eax

if ( a1 > 0 )
{
v1 = 1;
do
{
printf("(%d)****", (unsigned int)v1);
if ( a1 <= v1 )
result = func3();
else
result = printf(", ");
++v1;
}
while ( a1 + 1 != v1 );
}
return result;
}

original_code:
static void hide_cards(const int num_cards)
{
    int i;
    int j = 1;
    for (i = 0 ; i< num_cards ; i++) {
        printf("(%d)****", j);
        if (j <= (num_cards - 1))
            printf(", ");
        else
            newline();
        j++;
    }
}

canonical_original_code:
static void hide_cards(int num_cards)
{
    int i;
    int j = 1;
    for (i = 0 ; i< num_cards ; i++) {
        printf("(%d)****", j);
        if (j <= (num_cards - 1))
            printf(", ");
        else
            newline();
        j++;
    }
}


decompiled_code:
int __fastcall show_pile(__int64 a1, __int64 a2)
{
int v2; // er13
__int64 v3; // rbp
int v4; // ebx
const char *v5; // r12
const char *v6; // rax

printf("%d on pile:", a2);
newline();
v2 = a2 - 1;
if ( (int)a2 - 1 >= 0 )
{
v3 = a1 + 8LL * v2;
v4 = a2 - 1;
do
{
putchar(9);
if ( v2 == v4 )
printf("(*)");
v5 = (const char *)show_suit(v3);
v6 = (const char *)show_rank(v3);
printf("%s of %s", v6, v5);
newline();
--v4;
v3 -= 8LL;
}
while ( v4 != -1 );
}
return newline();
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // er13
__int64 v3; // rbp
int v4; // ebx
const char *v5; // r12
const char *v6; // rax

printf("%d on pile:", a2);
func3();
v2 = a2 - 1;
if ( (int)a2 - 1 >= 0 )
{
v3 = a1 + 8LL * v2;
v4 = a2 - 1;
do
{
putchar(9);
if ( v2 == v4 )
printf("(*)");
v5 = (const char *)show_suit(v3);
v6 = (const char *)show_rank(v3);
printf("%s of %s", v6, v5);
func3();
--v4;
v3 -= 8LL;
}
while ( v4 != -1 );
}
return func3();
}

original_code:
static void show_pile(const struct card_t *cards, const int num_cards)
{
    int i;
    int j = 1;
    printf("%d on pile:", num_cards);
    newline();
    for (i = (num_cards-1) ; i >= 0 ; i--) {
        printf("\t");
        if (i == (num_cards-1))
            printf("(*)");
        printf("%s of %s", show_rank(&cards[i]), show_suit(&cards[i]));
        newline();
        j++;
    }
    newline();
}

canonical_original_code:
static void show_pile(struct card_t *cards, int num_cards)
{
    int i;
    int j = 1;
    printf("%d on pile:", num_cards);
    newline();
    for (i = (num_cards-1) ; i >= 0 ; i--) {
        printf("\t");
        if (i == (num_cards-1))
            printf("(*)");
        printf("%s of %s", show_rank(&cards[i]), show_suit(&cards[i]));
        newline();
        j++;
    }
    newline();
}

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 }


newlines

decompiled_code:
int __fastcall newlines(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = newline();
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = func3();
}
return result;
}

original_code:
void newlines(const int num)
{
    int i;
    for (i = 0 ; i < num ; i++)
        newline();
}

canonical_original_code:
void newlines(int num)
{
    int i;
    for (i = 0 ; i < num ; i++)
        newline();
}

variable_types: num int


decompiled_code:
int __fastcall show_deck(unsigned int a1)
{
printf("%d left on deck", a1);
return newlines(2);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
printf("%d left on deck", a1);
return func7(2);
}

original_code:
static void show_deck(const int num_cards)
{
    printf("%d left on deck", num_cards);
    newlines(2);
}

canonical_original_code:
static void show_deck(int num_cards)
{
    printf("%d left on deck", num_cards);
    newlines(2);
}


decompiled_code:
int __fastcall show_burnt(unsigned int a1)
{
printf("%d burnt", a1);
return newlines(2);
}

canonical_decompiled_code:
int __fastcall func9(unsigned int a1)
{
printf("%d burnt", a1);
return func7(2);
}

original_code:
static void show_burnt(const int num_cards)
{
    printf("%d burnt", num_cards);
    newlines(2);
}

canonical_original_code:
static void show_burnt(int num_cards)
{
    printf("%d burnt", num_cards);
    newlines(2);
}


decompiled_code:
int show_welcome_msg()
{
printf("Welcome to C-Head!");
return newlines(2);
}

canonical_decompiled_code:
int func10()
{
printf("Welcome to C-Head!");
return func7(2);
}

original_code:
void show_welcome_msg()
{
    printf("Welcome to C-Head!");
    newlines(2);
}


decompiled_code:
void __fastcall show_player(__int64 a1)
{
printf("Player name : %s", (const char *)a1);
newline();
if ( *(int *)(a1 + 976) > 0 )
{
printf("HAND : ");
show_cards(a1 + 16, *(_DWORD *)(a1 + 976));
}
if ( *(int *)(a1 + 980) > 0 )
{
printf("FACE UP : ");
show_cards(a1 + 816, *(_DWORD *)(a1 + 980));
}
if ( *(int *)(a1 + 984) > 0 )
{
printf("FACE DOWN: ");
hide_cards(*(_DWORD *)(a1 + 984));
}
}

original_code:
void show_player(const struct player_t *player)
{
    printf("Player name : %s", player->name);
    newline();
    if (player->hand_size > 0) {
        printf("HAND     : ");
        show_cards(player->hand, player->hand_size);
    }
    if (player->face_up_size > 0) {
        printf("FACE UP  : ");
        show_cards(player->face_up, player->face_up_size);
    }
    if (player->face_down_size > 0) {
        printf("FACE DOWN: ");
        hide_cards(player->face_down_size);
    }
}

canonical_original_code:
void show_player(struct player_t *player)
{
    printf("Player name : %s", player->name);
    newline();
    if (player->hand_size > 0) {
        printf("HAND     : ");
        show_cards(player->hand, player->hand_size);
    }
    if (player->face_up_size > 0) {
        printf("FACE UP  : ");
        show_cards(player->face_up, player->face_up_size);
    }
    if (player->face_down_size > 0) {
        printf("FACE DOWN: ");
        hide_cards(player->face_down_size);
    }
}

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)(); } *

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)(); }


decompiled_code:
int __fastcall show_players(__int64 a1, int a2)
{
__int64 v2; // rbx
int result; // eax

if ( a2 > 0 )
{
v2 = a1;
do
{
show_player(v2);
result = newline();
v2 += 1024LL;
}
while ( v2 != a1 + ((unsigned __int64)(unsigned int)(a2 - 1) << 10) + 1024 );
}
return result;
}

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

if ( a2 > 0 )
{
v2 = a1;
do
{
func11(v2);
result = func3();
v2 += 1024LL;
}
while ( v2 != a1 + ((unsigned __int64)(unsigned int)(a2 - 1) << 10) + 1024 );
}
return result;
}

original_code:
static void show_players(const struct player_t *players, const int num_players)
{
    int i;
    for (i = 0 ; i < num_players ; i++) {
        show_player(&players[i]);
        newline();
    }
}

canonical_original_code:
static void show_players(struct player_t *players, int num_players)
{
    int i;
    for (i = 0 ; i < num_players ; i++) {
        show_player(&players[i]);
        newline();
    }
}

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; }


clearscreen

decompiled_code:
int clearscreen()
{
return newlines(100);
}

canonical_decompiled_code:
int func13()
{
return func7(100);
}

original_code:
void clearscreen()
{
    newlines(100);
}

canonical_original_code:
void clearscreen()
{
    newlines(100);
}


decompiled_code:
__int64 request_num_players()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Enter number of players : ");
_isoc99_scanf("%d", v1);
return v1[0];
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Enter number of players : ");
_isoc99_scanf("%d", v1);
return v1[0];
}

original_code:
int request_num_players()
{
    int result;
    printf("Enter number of players : ");
    scanf("%d", &result);
    return result;
}

variable_types: result int


decompiled_code:
__int64 request_num_cards_each()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Enter number of cards each : ");
_isoc99_scanf("%d", v1);
return v1[0];
}

canonical_decompiled_code:
__int64 func15()
{
unsigned int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Enter number of cards each : ");
_isoc99_scanf("%d", v1);
return v1[0];
}

original_code:
int request_num_cards_each()
{
    int result;
    printf("Enter number of cards each : ");
    scanf("%d", &result);
    return result;
}


decompiled_code:
int __fastcall request_player_details(char *dest, __int64 a2, int a3)
{
char *v5; // r13
_BYTE *v6; // r12
__int64 v7; // r15
__int64 v8; // rbx

v5 = (char *)malloc(0xAuLL);
v6 = malloc(2uLL);
if ( a3 > 0 )
{
v7 = (unsigned int)(a3 + 1);
v8 = 1LL;
do
{
newline();
printf("Enter name for player %d : ", (unsigned int)v8);
_isoc99_scanf("%s", v5);
strcpy(dest, v5);
printf("Enter player type (h/l/r/p) : ");
_isoc99_scanf("%s", v6);
*(_BYTE *)(a2 + v8++ - 1) = *v6;
dest += 10;
}
while ( v8 != v7 );
}
free(v5);
free(v6);
return newline();
}

canonical_decompiled_code:
int __fastcall func16(char *dest, __int64 a2, int a3)
{
char *v5; // r13
_BYTE *v6; // r12
__int64 v7; // r15
__int64 v8; // rbx

v5 = (char *)malloc(0xAuLL);
v6 = malloc(2uLL);
if ( a3 > 0 )
{
v7 = (unsigned int)(a3 + 1);
v8 = 1LL;
do
{
func3();
printf("Enter name for player %d : ", (unsigned int)v8);
_isoc99_scanf("%s", v5);
strcpy(dest, v5);
printf("Enter player type (h/l/r/p) : ");
_isoc99_scanf("%s", v6);
*(_BYTE *)(a2 + v8++ - 1) = *v6;
dest += 10;
}
while ( v8 != v7 );
}
free(v5);
free(v6);
return func3();
}

original_code:
void request_player_details(char names[][10], char types[], const int num_players)
{
    char *name = malloc(sizeof(char) * 10);
    char *type = malloc(sizeof(char) * 2);
    int i;
    for (i = 0 ; i < num_players ; i++) {
        newline();
        printf("Enter name for player %d : ", i+1);
        scanf("%s", name);
        strcpy(names[i], name);
        printf("Enter player type (h/l/r/p) : ");
        scanf("%s", type);
        types[i] = type[0];
    }
    free(name);
    free(type);
    newline();
}

canonical_original_code:
void request_player_details(char names[][10], char types[], int num_players)
{
    char *name = malloc(sizeof(char) * 10);
    char *type = malloc(sizeof(char) * 2);
    int i;
    for (i = 0 ; i < num_players ; i++) {
        newline();
        printf("Enter name for player %d : ", i+1);
        scanf("%s", name);
        strcpy(names[i], name);
        printf("Enter player type (h/l/r/p) : ");
        scanf("%s", type);
        types[i] = type[0];
    }
    free(name);
    free(type);
    newline();
}

variable_types:
names
char [][10]

variable_types:
types
char []

variable_types:
name
char *

variable_types:
type
char *

variable_types: i int


decompiled_code:
__int64 __fastcall request_swap_cards(const char *a1)
{
char *v1; // rbx
unsigned int v2; // ebp

v1 = (char *)malloc(2uLL);
newline();
printf("%s, would you like to swap cards (y/n) : ", a1);
_isoc99_scanf("%s", v1);
v2 = str_to_bool(v1);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1)
{
char *v1; // rbx
unsigned int v2; // ebp

v1 = (char *)malloc(2uLL);
func3();
printf("%s, would you like to swap cards (y/n) : ", a1);
_isoc99_scanf("%s", v1);
v2 = func1(v1);
free(v1);
return v2;
}

original_code:
int request_swap_cards(const char *name)
{
    int result;
    char *choice = malloc(sizeof(char) * 2);
    newline();
    printf("%s, would you like to swap cards (y/n) : ", name);
    scanf("%s", choice);
    result = str_to_bool(choice);
    free(choice);
    return result;
}

canonical_original_code:
int request_swap_cards(char *name)
{
    int result;
    char *choice = malloc(sizeof(char) * 2);
    newline();
    printf("%s, would you like to swap cards (y/n) : ", name);
    scanf("%s", choice);
    result = str_to_bool(choice);
    free(choice);
    return result;
}


decompiled_code:
__int64 __fastcall request_swap_more(const char *a1)
{
char *v1; // rbx
unsigned int v2; // ebp

v1 = (char *)malloc(2uLL);
newline();
printf("%s, swap more (y/n) : ", a1);
_isoc99_scanf("%s", v1);
v2 = str_to_bool(v1);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func18(const char *a1)
{
char *v1; // rbx
unsigned int v2; // ebp

v1 = (char *)malloc(2uLL);
func3();
printf("%s, swap more (y/n) : ", a1);
_isoc99_scanf("%s", v1);
v2 = func1(v1);
free(v1);
return v2;
}

original_code:
int request_swap_more(const char *name)
{
    int result = 0;
    char *choice = malloc(sizeof(char) * 2);
    newline();
    printf("%s, swap more (y/n) : ", name);
    scanf("%s", choice);
    result = str_to_bool(choice);
    free(choice);
    return result;
}

canonical_original_code:
int request_swap_more(char *name)
{
    int result = 0;
    char *choice = malloc(sizeof(char) * 2);
    newline();
    printf("%s, swap more (y/n) : ", name);
    scanf("%s", choice);
    result = str_to_bool(choice);
    free(choice);
    return result;
}


decompiled_code:
__int64 __fastcall request_hand_swap(unsigned int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Hand card to swap (1-%d): ", a1);
_isoc99_scanf("%d", v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Hand card to swap (1-%d): ", a1);
_isoc99_scanf("%d", v2);
return v2[0];
}

original_code:
int request_hand_swap(const int size)
{
    int choice;
    printf("Hand card to swap (1-%d): ", size);
    scanf("%d", &choice);
    return choice;
}

canonical_original_code:
int request_hand_swap(int size)
{
    int choice;
    printf("Hand card to swap (1-%d): ", size);
    scanf("%d", &choice);
    return choice;
}

variable_types: size int

variable_types: choice int


decompiled_code:
__int64 __fastcall request_face_down_move(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

newline();
printf("%s, pick a card to play (1-%d): ", (const char *)a1, *(unsigned int *)(a1 + 984));
_isoc99_scanf("%d", v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

func3();
printf("%s, pick a card to play (1-%d): ", (const char *)a1, *(unsigned int *)(a1 + 984));
_isoc99_scanf("%d", v2);
return v2[0];
}

original_code:
int request_face_down_move(const struct player_t *player)
{
    int choice;
    newline();
    printf("%s, pick a card to play (1-%d): ", player->name, player->face_down_size);
    scanf("%d", &choice);
    return choice;
}

canonical_original_code:
int request_face_down_move(struct player_t *player)
{
    int choice;
    newline();
    printf("%s, pick a card to play (1-%d): ", player->name, player->face_down_size);
    scanf("%d", &choice);
    return choice;
}


decompiled_code:
__int64 __fastcall request_faceup_swap(unsigned int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Face up card to swap (1-%d): ", a1);
_isoc99_scanf("%d", v2);
return v2[0];
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1)
{
unsigned int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("Face up card to swap (1-%d): ", a1);
_isoc99_scanf("%d", v2);
return v2[0];
}

original_code:
int request_faceup_swap(const int size)
{
    int choice;
    printf("Face up card to swap (1-%d): ", size);
    scanf("%d", &choice);
    return choice;
}

canonical_original_code:
int request_faceup_swap(int size)
{
    int choice;
    printf("Face up card to swap (1-%d): ", size);
    scanf("%d", &choice);
    return choice;
}


decompiled_code:
int __fastcall request_move(const char *a1, __int64 a2, _DWORD *a3)
{
int result; // eax
char v5[34]; // [rsp+6h] [rbp-22h] BYREF

printf("%s, choose cards to lay: ", a1);
_isoc99_scanf("%s", v5);
while ( 1 )
{
result = parse_choice(v5, a2, a3);
if ( result )
break;
*a3 = 0;
newline();
printf("Enter card choices seperated by commas.");
newlines(2);
printf("%s, choose cards to lay: ", a1);
_isoc99_scanf("%s", v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func22(const char *a1, __int64 a2, _DWORD *a3)
{
int result; // eax
char v5[34]; // [rsp+6h] [rbp-22h] BYREF

printf("%s, choose cards to lay: ", a1);
_isoc99_scanf("%s", v5);
while ( 1 )
{
result = func2(v5, a2, a3);
if ( result )
break;
*a3 = 0;
func3();
printf("Enter card choices seperated by commas.");
func7(2);
printf("%s, choose cards to lay: ", a1);
_isoc99_scanf("%s", v5);
}
return result;
}

original_code:
void request_move(const struct player_t *player, int card_choices[], int *num_choices)
{
    char entered[10];
    printf("%s, choose cards to lay: ", player->name);
    scanf("%s", entered);
    while (!parse_choice(entered, card_choices, num_choices)) {
        *num_choices = 0;
        newline();
        printf("Enter card choices seperated by commas.");
        newlines(2);
        printf("%s, choose cards to lay: ", player->name);
        scanf("%s", entered);
    }
}

canonical_original_code:
void request_move(struct player_t *player, int card_choices[], int *num_choices)
{
    char entered[10];
    printf("%s, choose cards to lay: ", player->name);
    scanf("%s", entered);
    while (!parse_choice(entered, card_choices, num_choices)) {
        *num_choices = 0;
        newline();
        printf("Enter card choices seperated by commas.");
        newlines(2);
        printf("%s, choose cards to lay: ", player->name);
        scanf("%s", entered);
    }
}

variable_types:
entered
char [10]


decompiled_code:
int __fastcall show_shithead(const char *a1)
{
newline();
printf("!!!! GAME OVER !!!!");
newlines(2);
printf("SHITHEAD == %s", a1);
return newlines(2);
}

canonical_decompiled_code:
int __fastcall func23(const char *a1)
{
func3();
printf("!!!! GAME OVER !!!!");
func7(2);
printf("SHITHEAD == %s", a1);
return func7(2);
}

original_code:
void show_shithead(char *player)
{
    newline();
    printf("!!!! GAME OVER !!!!");
    newlines(2);
    printf("SHITHEAD == %s", player);
    newlines(2);
}

variable_types:
player
char *


decompiled_code:
int wait_user()
{
int v0; // eax

printf("Press ENTER to continue.");
do
v0 = fgetc(stdin);
while ( v0 != -1 && v0 != 10 );
clearerr(stdin);
fflush(stdout);
return getchar();
}

canonical_decompiled_code:
int func24()
{
int v0; // eax

printf("Press ENTER to continue.");
do
v0 = fgetc(stdin);
while ( v0 != -1 && v0 != 10 );
clearerr(stdin);
fflush(stdout);
return getchar();
}

original_code:
void wait_user()
{
    printf("Press ENTER to continue.");
    int ch;
    do
        ch = fgetc(stdin);
    while (ch != (-1) && ch != '\n');
    clearerr(stdin);
    fflush(stdout);
    getchar();
}

variable_types: ch int


decompiled_code:
int __fastcall show_game_summary(__int64 a1)
{
show_pile(a1 + 22588, *(unsigned int *)(a1 + 12));
show_deck(*(_DWORD *)(a1 + 8));
show_burnt(*(_DWORD *)(a1 + 16));
show_players(a1 + 24, *(_DWORD *)a1);
show_last_move((const char *)(a1 + 24668));
return wait_user();
}

original_code:
void show_game_summary(const struct game_t *game)
{
    show_pile(game->pile, game->pile_size);
    show_deck(game->deck_size);
    show_burnt(game->burnt);
    show_players(game->players, game->num_players);
    show_last_move(game->last_move);
    wait_user();
}

canonical_original_code:
void show_game_summary(struct game_t *game)
{
    show_pile(game->pile, game->pile_size);
    show_deck(game->deck_size);
    show_burnt(game->burnt);
    show_players(game->players, game->num_players);
    show_last_move(game->last_move);
    wait_user();
}

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; } *

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:
int show_bad_move()
{
newline();
printf("You can't do that, try again");
newline();
return wait_user();
}

canonical_decompiled_code:
int func26()
{
func3();
printf("You can't do that, try again");
func3();
return func24();
}

original_code:
void show_bad_move(void)
{
    newline();
    printf("You can't do that, try again");
    newline();
    wait_user();
}

canonical_original_code:
void show_bad_move()
{
    newline();
    printf("You can't do that, try again");
    newline();
    wait_user();
}


decompiled_code:
int __fastcall show_pickup(const char *a1)
{
newline();
printf("Oh dear, %s, you must pick up, press enter.", a1);
return newline();
}

canonical_decompiled_code:
int __fastcall func27(const char *a1)
{
func3();
printf("Oh dear, %s, you must pick up, press enter.", a1);
return func3();
}

original_code:
void show_pickup(const char *name)
{
    newline();
    printf("Oh dear, %s, you must pick up, press enter.", name);
    newline();
}

canonical_original_code:
void show_pickup(char *name)
{
    newline();
    printf("Oh dear, %s, you must pick up, press enter.", name);
    newline();
}


decompiled_code:
int __fastcall show_pickup_from_face_down(__int64 a1)
{
const char *v1; // rbp
const char *v2; // rax

newline();
v1 = (const char *)show_suit(a1);
v2 = (const char *)show_rank(a1);
printf("Oh no, you picked the %s of %s, you must pickup, press enter.", v2, v1);
return newline();
}

canonical_decompiled_code:
int __fastcall func28(__int64 a1)
{
const char *v1; // rbp
const char *v2; // rax

func3();
v1 = (const char *)show_suit(a1);
v2 = (const char *)show_rank(a1);
printf("Oh no, you picked the %s of %s, you must pickup, press enter.", v2, v1);
return func3();
}

original_code:
void show_pickup_from_face_down(const struct card_t *card)
{
    newline();
    printf("Oh no, you picked the %s of %s, you must pickup, press enter.",
        show_rank(card), show_suit(card));
    newline();
}

canonical_original_code:
void show_pickup_from_face_down(struct card_t *card)
{
    newline();
    printf("Oh no, you picked the %s of %s, you must pickup, press enter.",
        show_rank(card), show_suit(card));
    newline();
}


decompiled_code:
int __fastcall show_can_move_from_face_down(__int64 a1)
{
const char *v1; // rbp
const char *v2; // rax

newline();
v1 = (const char *)show_suit(a1);
v2 = (const char *)show_rank(a1);
printf("Whew! you picked the %s of %s, press enter.", v2, v1);
return newline();
}

canonical_decompiled_code:
int __fastcall func29(__int64 a1)
{
const char *v1; // rbp
const char *v2; // rax

func3();
v1 = (const char *)show_suit(a1);
v2 = (const char *)show_rank(a1);
printf("Whew! you picked the %s of %s, press enter.", v2, v1);
return func3();
}

original_code:
void show_can_move_from_face_down(const struct card_t *card)
{
    newline();
    printf("Whew! you picked the %s of %s, press enter.", show_rank(card), show_suit(card));
    newline();
}

canonical_original_code:
void show_can_move_from_face_down(struct card_t *card)
{
    newline();
    printf("Whew! you picked the %s of %s, press enter.", show_rank(card), show_suit(card));
    newline();
}


decompiled_code:
_BOOL8 __fastcall burn_cards_laid(__int64 a1, int a2)
{
_BOOL8 result; // rax
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a2 > 0 )
{
v3 = a2;
result = 1LL;
if ( *(_DWORD *)(a1 + 8LL * a2 - 8) != 10 )
{
v4 = 0LL;
v5 = 0LL;
v6 = (unsigned int)(a2 - 1);
do
{
if ( a2 > (int)v4 )
{
v3 = *(_QWORD *)(a1 + 8LL * ((int)v6 - (int)v4));
v7[v4] = v3;
v5 = (unsigned int)(v5 + 1);
}
++v4;
}
while ( v4 != 4 );
result = 0LL;
if ( (_DWORD)v5 == 4 )
result = (unsigned int)all_ranks_equal(v7, 4LL, v3, v5, v6) != 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, int a2)
{
_BOOL8 result; // rax
__int64 v3; // rdx
__int64 v4; // rax
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7[5]; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a2 > 0 )
{
v3 = a2;
result = 1LL;
if ( *(_DWORD *)(a1 + 8LL * a2 - 8) != 10 )
{
v4 = 0LL;
v5 = 0LL;
v6 = (unsigned int)(a2 - 1);
do
{
if ( a2 > (int)v4 )
{
v3 = *(_QWORD *)(a1 + 8LL * ((int)v6 - (int)v4));
v7[v4] = v3;
v5 = (unsigned int)(v5 + 1);
}
++v4;
}
while ( v4 != 4 );
result = 0LL;
if ( (_DWORD)v5 == 4 )
result = (unsigned int)all_ranks_equal(v7, 4LL, v3, v5, v6) != 0;
}
}
return result;
}

original_code:
int burn_cards_laid(const struct card_t *pile, const int pile_size)
{
    struct card_t cards_on_pile[4];
    int num_cards = 0;
    int i;
    if (pile_size > 0) {
        if (pile[pile_size-1].rank == 10)
            return 1;
        for (i = 0; i < 4; i++)
            if (pile_size > i) {
                cards_on_pile[i] = pile[pile_size-(i+1)];
                num_cards++;
            }
        if (num_cards == 4 && all_ranks_equal(cards_on_pile, num_cards))
            return 1;
    }
    return 0;
}

canonical_original_code:
int burn_cards_laid(struct card_t *pile, int pile_size)
{
    struct card_t cards_on_pile[4];
    int num_cards = 0;
    int i;
    if (pile_size > 0) {
        if (pile[pile_size-1].rank == 10)
            return 1;
        for (i = 0; i < 4; i++)
            if (pile_size > i) {
                cards_on_pile[i] = pile[pile_size-(i+1)];
                num_cards++;
            }
        if (num_cards == 4 && all_ranks_equal(cards_on_pile, num_cards))
            return 1;
    }
    return 0;
}

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; } [4]


decompiled_code:
_BOOL8 __fastcall miss_a_go_card_laid(__int64 a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 > 0 )
result = *(_DWORD *)(a1 + 8LL * a2 - 8) == 8;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 > 0 )
result = *(_DWORD *)(a1 + 8LL * a2 - 8) == 8;
return result;
}

original_code:
int miss_a_go_card_laid(const struct card_t *pile, const int pile_size)
{
    if (pile_size > 0)
        if (pile[pile_size-1].rank == 8)
            return 1;
    return 0;
}

canonical_original_code:
int miss_a_go_card_laid(struct card_t *pile, int pile_size)
{
    if (pile_size > 0)
        if (pile[pile_size-1].rank == 8)
            return 1;
    return 0;
}

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:
__int64 __fastcall add_to_pile(__int64 a1, _DWORD *a2, __int64 a3)
{
__int64 result; // rax

LODWORD(result) = (*a2)++;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result) = a3;
return result;
}

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

LODWORD(result) = (*a2)++;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result) = a3;
return result;
}

original_code:
void add_to_pile(struct card_t pile[], int *pile_size, const struct card_t card)
{
    pile[(*pile_size)++] = card;
}

canonical_original_code:
void add_to_pile(struct card_t pile[], int *pile_size, struct card_t card)
{
    pile[(*pile_size)++] = card;
}

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; } []

variable_types:
card
struct card_t


decompiled_code:
__int64 __fastcall choice_not_in_cards(int a1, _DWORD *a2, int a3)
{
_DWORD *v3; // rax

if ( a1 <= 0 )
return 0LL;
v3 = a2;
while ( *v3 < a3 )
{
if ( ++v3 == &a2[a1 - 1 + 1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, _DWORD *a2, int a3)
{
_DWORD *v3; // rax

if ( a1 <= 0 )
return 0LL;
v3 = a2;
while ( *v3 < a3 )
{
if ( ++v3 == &a2[a1 - 1 + 1] )
return 0LL;
}
return 1LL;
}

original_code:
static int choice_not_in_cards(const int num_choices, const int card_choices[],
    const int cards_size)
{
    int i;
    for (i = 0 ; i < num_choices ; i++)
        if (card_choices[i] >= cards_size)
            return 1;
    return 0;
}

canonical_original_code:
static int choice_not_in_cards(int num_choices, int card_choices[], int cards_size)
{
    int i;
    for (i = 0 ; i < num_choices ; i++)
        if (card_choices[i] >= cards_size)
            return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall empty_pile(int a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(int a1)
{
return a1 == 0;
}

original_code:
static int empty_pile(const int pile_size)
{
    return (pile_size == 0);
}

canonical_original_code:
static int empty_pile(int pile_size)
{
    return (pile_size == 0);
}


decompiled_code:
_BOOL8 __fastcall two_on_pile(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 8LL * a2 - 8) == 2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 8LL * a2 - 8) == 2;
}

original_code:
static int two_on_pile(const struct card_t *pile, const int pile_size)
{
    return (pile[pile_size-1].rank == TWO);
}

canonical_original_code:
static int two_on_pile(struct card_t *pile, int pile_size)
{
    return (pile[pile_size-1].rank == TWO);
}


decompiled_code:
_BOOL8 __fastcall seven_on_pile(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 8LL * a2 - 8) == 7;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, int a2)
{
return *(_DWORD *)(a1 + 8LL * a2 - 8) == 7;
}

original_code:
static int seven_on_pile(const struct card_t *pile, const int pile_size)
{
    return (pile[pile_size-1].rank == SEVEN);
}

canonical_original_code:
static int seven_on_pile(struct card_t *pile, int pile_size)
{
    return (pile[pile_size-1].rank == SEVEN);
}


decompiled_code:
_BOOL8 __fastcall card_higher_than_pile(__int64 a1, __int64 a2, int a3)
{
return (unsigned int)card_cmp(a1, a2 + 8LL * a3 - 8) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2, int a3)
{
return (unsigned int)card_cmp(a1, a2 + 8LL * a3 - 8) == 1;
}

original_code:
static int card_higher_than_pile(const struct card_t *card,
    const struct card_t *pile, const int pile_size)
{
    return (card_cmp(card, &pile[pile_size-1]) == 1);
}

canonical_original_code:
static int card_higher_than_pile(struct card_t *card, struct card_t *pile, int pile_size)
{
    return (card_cmp(card, &pile[pile_size-1]) == 1);
}

variable_types:
pile
struct card_t *


decompiled_code:
__int64 __fastcall can_lay(__int64 a1, __int64 a2, int a3)
{
_BOOL4 v4; // edx
__int64 result; // rax
int v6; // edx
_BOOL4 v7; // edx
int v8; // edx
_BOOL4 v9; // edx

v4 = empty_pile(a3);
result = 1LL;
if ( !v4 )
{
v6 = special_card(a1);
result = 1LL;
if ( !v6 )
{
v7 = two_on_pile(a2, a3);
result = 1LL;
if ( !v7 )
{
v8 = ranks_equal(a1, a2 + 8LL * a3 - 8);
result = 1LL;
if ( !v8 )
{
v9 = card_higher_than_pile(a1, a2, a3);
result = 1LL;
if ( !v9 )
{
result = seven_on_pile(a2, a3);
if ( (_DWORD)result )
result = can_lay(a1, a2, (unsigned int)(a3 - 1));
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
_BOOL4 v4; // edx
__int64 result; // rax
int v6; // edx
_BOOL4 v7; // edx
int v8; // edx
_BOOL4 v9; // edx

v4 = func1(a3);
result = 1LL;
if ( !v4 )
{
v6 = special_card(a1);
result = 1LL;
if ( !v6 )
{
v7 = func2(a2, a3);
result = 1LL;
if ( !v7 )
{
v8 = ranks_equal(a1, a2 + 8LL * a3 - 8);
result = 1LL;
if ( !v8 )
{
v9 = func4(a1, a2, a3);
result = 1LL;
if ( !v9 )
{
result = func3(a2, a3);
if ( (_DWORD)result )
result = func5(a1, a2, (unsigned int)(a3 - 1));
}
}
}
}
}
return result;
}

original_code:
int can_lay(const struct card_t *card, const struct card_t *pile, const int pile_size)
{
    if ((empty_pile(pile_size)) || (special_card(card)) ||
            (two_on_pile(pile, pile_size)) || (ranks_equal(card, &pile[pile_size-1])) ||
            (card_higher_than_pile(card, pile, pile_size)))
        return 1;
    else if (seven_on_pile(pile, pile_size))
        return can_lay(card, pile, pile_size-1);
    else
        return 0;
}

canonical_original_code:
int can_lay(struct card_t *card, struct card_t *pile, int pile_size)
{
    if ((empty_pile(pile_size)) || (special_card(card)) ||
            (two_on_pile(pile, pile_size)) || (ranks_equal(card, &pile[pile_size-1])) ||
            (card_higher_than_pile(card, pile, pile_size)))
        return 1;
    else if (seven_on_pile(pile, pile_size))
        return can_lay(card, pile, pile_size-1);
    else
        return 0;
}


decompiled_code:
__int64 __fastcall valid_move_with_given_hand(__int64 a1, int *a2, int a3, __int64 a4, int a5)
{
__int64 result; // rax
int v6; // er12
int v8; // edx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11[55]; // [rsp+0h] [rbp-1B8h] BYREF

result = 0LL;
if ( a3 <= a5 )
{
v6 = a3;
v8 = choice_not_in_cards(a3, a2, a5);
result = 0LL;
if ( !v8 )
{
if ( v6 <= 0 )
{
v6 = 0;
}
else
{
v9 = 0LL;
do
{
v11[v9] = *(_QWORD *)(a4 + 8LL * a2[v9]);
v10 = v9++;
}
while ( v6 - 1 != v10 );
}
result = all_ranks_equal(v11, (unsigned int)v6);
if ( (_DWORD)result )
result = !cannot_lay_first_card(a4, a2, a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int *a2, int a3, __int64 a4, int a5)
{
__int64 result; // rax
int v6; // er12
int v8; // edx
__int64 v9; // rax
__int64 v10; // rdx
__int64 v11[55]; // [rsp+0h] [rbp-1B8h] BYREF

result = 0LL;
if ( a3 <= a5 )
{
v6 = a3;
v8 = func0(a3, a2, a5);
result = 0LL;
if ( !v8 )
{
if ( v6 <= 0 )
{
v6 = 0;
}
else
{
v9 = 0LL;
do
{
v11[v9] = *(_QWORD *)(a4 + 8LL * a2[v9]);
v10 = v9++;
}
while ( v6 - 1 != v10 );
}
result = all_ranks_equal(v11, (unsigned int)v6);
if ( (_DWORD)result )
result = !func6(a4, a2, a1);
}
}
return result;
}

original_code:
static int valid_move_with_given_hand(const struct game_t *game,
    const int card_choices[], const int num_choices, const struct card_t *cards,
    const int cards_size)
{
    struct card_t to_lay[50];
    int num_to_lay = 0;
    int i = 0;
    if ((num_choices > cards_size) ||
                (choice_not_in_cards(num_choices, card_choices, cards_size)))
        return 0;
    for (i = 0 ; i < num_choices ; i++)
        to_lay[num_to_lay++] = cards[card_choices[i]];
    if ((!all_ranks_equal(to_lay, num_to_lay)) ||
            (cannot_lay_first_card(cards, card_choices, game)))
        return 0;
    return 1;
}

canonical_original_code:
static int valid_move_with_given_hand(struct game_t *game, int card_choices[], int num_choices, struct card_t *cards, int cards_size)
{
    struct card_t to_lay[50];
    int num_to_lay = 0;
    int i = 0;
    if ((num_choices > cards_size) ||
                (choice_not_in_cards(num_choices, card_choices, cards_size)))
        return 0;
    for (i = 0 ; i < num_choices ; i++)
        to_lay[num_to_lay++] = cards[card_choices[i]];
    if ((!all_ranks_equal(to_lay, num_to_lay)) ||
            (cannot_lay_first_card(cards, card_choices, game)))
        return 0;
    return 1;
}

variable_types:
cards
struct card_t *

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; } [50]


decompiled_code:
__int64 __fastcall can_move_with_hand(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( *(int *)(a1 + 976) <= 0 )
return 0LL;
v4 = a1 + 16;
v5 = 0;
while ( 1 )
{
result = can_lay(v4, a2, a3);
if ( (_DWORD)result )
break;
++v5;
v4 += 8LL;
if ( *(_DWORD *)(a1 + 976) <= v5 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( *(int *)(a1 + 976) <= 0 )
return 0LL;
v4 = a1 + 16;
v5 = 0;
while ( 1 )
{
result = func5(v4, a2, a3);
if ( (_DWORD)result )
break;
++v5;
v4 += 8LL;
if ( *(_DWORD *)(a1 + 976) <= v5 )
return result;
}
return 1LL;
}

original_code:
static int can_move_with_hand(const struct player_t *player, const struct card_t *pile,
    const int pile_size)
{
    int i;
    for (i = 0 ; i < player->hand_size ; i++)
        if (can_lay(&player->hand[i], pile, pile_size))
            return 1;
    return 0;
}

canonical_original_code:
static int can_move_with_hand(struct player_t *player, struct card_t *pile, int pile_size)
{
    int i;
    for (i = 0 ; i < player->hand_size ; i++)
        if (can_lay(&player->hand[i], pile, pile_size))
            return 1;
    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 __fastcall can_move_with_face_up(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( *(int *)(a1 + 980) <= 0 )
return 0LL;
v4 = a1 + 816;
v5 = 0;
while ( 1 )
{
result = can_lay(v4, a2, a3);
if ( (_DWORD)result )
break;
++v5;
v4 += 8LL;
if ( *(_DWORD *)(a1 + 980) <= v5 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
int v5; // ebp
__int64 result; // rax

if ( *(int *)(a1 + 980) <= 0 )
return 0LL;
v4 = a1 + 816;
v5 = 0;
while ( 1 )
{
result = func5(v4, a2, a3);
if ( (_DWORD)result )
break;
++v5;
v4 += 8LL;
if ( *(_DWORD *)(a1 + 980) <= v5 )
return result;
}
return 1LL;
}

original_code:
static int can_move_with_face_up(const struct player_t *player, const struct card_t *pile,
    const int pile_size)
{
    int i;
    for (i = 0 ; i < player->face_up_size ; i++)
        if (can_lay(&player->face_up[i], pile, pile_size))
            return 1;
    return 0;
}

canonical_original_code:
static int can_move_with_face_up(struct player_t *player, struct card_t *pile, int pile_size)
{
    int i;
    for (i = 0 ; i < player->face_up_size ; i++)
        if (can_lay(&player->face_up[i], pile, pile_size))
            return 1;
    return 0;
}


original_code:
int valid_move(const struct game_t *game, const int card_choices[], const int num_choices)
{
    const struct player_t *player = &game->players[game->current_player];
    if (player->hand_size > 0)
        return valid_move_with_given_hand(game, card_choices, num_choices,
            player->hand, player->hand_size);
    else if (player->face_up_size > 0)
        return valid_move_with_given_hand(game, card_choices, num_choices,
            player->face_up, player->face_up_size);
    else
        return 0;
}

canonical_original_code:
int valid_move(struct game_t *game, int card_choices[], int num_choices)
{
    struct player_t *player = &game->players[game->current_player];
    if (player->hand_size > 0)
        return valid_move_with_given_hand(game, card_choices, num_choices,
            player->hand, player->hand_size);
    else if (player->face_up_size > 0)
        return valid_move_with_given_hand(game, card_choices, num_choices,
            player->face_up, player->face_up_size);
    else
        return 0;
}


original_code:
int can_move(const struct game_t *game)
{
    const struct player_t *player = &game->players[game->current_player];
    if (player->hand_size > 0)
        return can_move_with_hand(player, game->pile, game->pile_size);
    else if (player->face_up_size > 0)
        return can_move_with_face_up(player, game->pile, game->pile_size);
    else
        return 0;
}

canonical_original_code:
int can_move(struct game_t *game)
{
    struct player_t *player = &game->players[game->current_player];
    if (player->hand_size > 0)
        return can_move_with_hand(player, game->pile, game->pile_size);
    else if (player->face_up_size > 0)
        return can_move_with_face_up(player, game->pile, game->pile_size);
    else
        return 0;
}


original_code:
int can_lay_from_face_down(const struct game_t *game, const int choice)
{
    const struct player_t *player = &game->players[game->current_player];
    return can_lay(&player->face_down[choice], game->pile, game->pile_size);
}

canonical_original_code:
int can_lay_from_face_down(struct game_t *game, int choice)
{
    struct player_t *player = &game->players[game->current_player];
    return can_lay(&player->face_down[choice], game->pile, game->pile_size);
}


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

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

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

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


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

original_code:
struct swap_choice_t randomcardplayer_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 randomcardplayer_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 randomcardplayer_ask_move(__int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax

*a4 = 0;
if ( (unsigned int)has_cards_in_hand() )
result = choose_random_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
else
result = choose_random_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_random_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
else
result = choose_random_from_unsorted(a1 + 816, *(unsigned int *)(a1 + 980), a2, a3, a4);
return result;
}

original_code:
void randomcardplayer_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_random_from_sorted(player->hand, player->hand_size, helper,
            card_choices, nchoices);
    } else {
        choose_random_from_unsorted(player->face_up, player->face_up_size, helper,
            card_choices, nchoices);
    }
}

canonical_original_code:
void randomcardplayer_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_random_from_sorted(player->hand, player->hand_size, helper,
            card_choices, nchoices);
    } else {
        choose_random_from_unsorted(player->face_up, player->face_up_size, helper,
            card_choices, nchoices);
    }
}

variable_types:
helper
struct player_helper_t *

variable_types:
nchoices
int *


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

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

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

canonical_original_code:
int randomcardplayer_ask_face_down_move()
{
    return 1;
}


decompiled_code:
__int64 __fastcall make_card(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
struct card_t make_card(const enum cardrank rank, const enum cardsuit suit)
{
    struct card_t card;
    card.rank = rank;
    card.suit = suit;
    return card;
}

canonical_original_code:
struct card_t make_card(enum cardrank rank, enum cardsuit suit)
{
    struct card_t card;
    card.rank = rank;
    card.suit = suit;
    return card;
}

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:
_BOOL8 __fastcall special_card(_DWORD *a1)
{
_BOOL8 result; // rax

if ( *a1 > 0xAu )
result = 0LL;
else
result = ((1LL << *a1) & 0x484) != 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1)
{
_BOOL8 result; // rax

if ( *a1 > 0xAu )
result = 0LL;
else
result = ((1LL << *a1) & 0x484) != 0;
return result;
}

original_code:
int special_card(const struct card_t *card)
{
    switch(card->rank) {
    case TWO: return 1;
    case SEVEN: return 1;
    case TEN: return 1;
    default: return 0;
    }
}

canonical_original_code:
int special_card(struct card_t *card)
{
    switch(card->rank) {
    case TWO: return 1;
    case SEVEN: return 1;
    case TEN: return 1;
    default: return 0;
    }
}


decompiled_code:
__int64 __fastcall card_cmp(const void *a1, const void *a2)
{
_BOOL4 v2; // edx
__int64 result; // rax

if ( special_card(a1) )
{
v2 = special_card(a2);
result = 1LL;
if ( v2 )
result = *(_DWORD *)a1 < *(_DWORD *)a2;
}
else
{
result = special_card(a2);
if ( (_DWORD)result )
{
result = 0xFFFFFFFFLL;
}
else if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
{
result = *(_DWORD *)a1 < *(_DWORD *)a2 ? -1 : 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1, const void *a2)
{
_BOOL4 v2; // edx
__int64 result; // rax

if ( func1(a1) )
{
v2 = func1(a2);
result = 1LL;
if ( v2 )
result = *(_DWORD *)a1 < *(_DWORD *)a2;
}
else
{
result = func1(a2);
if ( (_DWORD)result )
{
result = 0xFFFFFFFFLL;
}
else if ( *(_DWORD *)a1 != *(_DWORD *)a2 )
{
result = *(_DWORD *)a1 < *(_DWORD *)a2 ? -1 : 1;
}
}
return result;
}

original_code:
int card_cmp(const void *card1, const void *card2)
{
    const struct card_t *icard1 = (const struct card_t *) card1;
    const struct card_t *icard2 = (const struct card_t *) card2;
    if (special_card(icard1) && special_card(icard2))
        return icard1->rank < icard2->rank;
    else if (special_card(icard1) && !special_card(icard2))
        return 1;
    else if (special_card(icard2))
        return -1;
    else if (icard1->rank == icard2->rank)
        return 0;
    else if (icard1->rank < icard2->rank)
        return -1;
    else
        return 1 ;
}

canonical_original_code:
int card_cmp(void *card1, void *card2)
{
    struct card_t *icard1 = (const struct card_t *) card1;
    struct card_t *icard2 = (const struct card_t *) card2;
    if (special_card(icard1) && special_card(icard2))
        return icard1->rank < icard2->rank;
    else if (special_card(icard1) && !special_card(icard2))
        return 1;
    else if (special_card(icard2))
        return -1;
    else if (icard1->rank == icard2->rank)
        return 0;
    else if (icard1->rank < icard2->rank)
        return -1;
    else
        return 1 ;
}


original_code:
struct card_t find_lowest_card(const struct card_t *cards, const int num_cards)
{
    struct card_t lowest = cards[0];
    int i ;
    for (i = 1; i < num_cards; i++)
        if (card_cmp(&cards[i], &lowest) < 0)
            lowest = cards[i];
    return lowest;
}

canonical_original_code:
struct card_t find_lowest_card(struct card_t *cards, int num_cards)
{
    struct card_t lowest = cards[0];
    int i;
    for (i = 1; i < num_cards; i++)
        if (card_cmp(&cards[i], &lowest) < 0)
            lowest = cards[i];
    return lowest;
}

variable_types: i int

return_type: 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:
_BOOL8 __fastcall cards_equal(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 )
result = a1[1] == a2[1];
return result;
}

original_code:
int cards_equal(const struct card_t *card1, const struct card_t *card2)
{
    return ((card1->rank == card2->rank) && (card1->suit == card2->suit));
}

canonical_original_code:
int cards_equal(struct card_t *card1, struct card_t *card2)
{
    return ((card1->rank == card2->rank) && (card1->suit == card2->suit));
}


decompiled_code:
_BOOL8 __fastcall ranks_equal(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
int ranks_equal(const struct card_t *card1, const struct card_t *card2)
{
    return ((card1->rank == card2->rank));
}

canonical_original_code:
int ranks_equal(struct card_t *card1, struct card_t *card2)
{
    return ((card1->rank == card2->rank));
}


decompiled_code:
_BOOL8 __fastcall all_ranks_equal(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
_BOOL8 result; // rax

if ( a2 <= 1 )
return 1LL;
v2 = a1 + 2;
while ( 1 )
{
result = ranks_equal(v2, a1);
if ( !result )
break;
v2 += 2;
if ( v2 == &a1[2 * (a2 - 2) + 4] )
return 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1, int a2)
{
_DWORD *v2; // rbx
_BOOL8 result; // rax

if ( a2 <= 1 )
return 1LL;
v2 = a1 + 2;
while ( 1 )
{
result = func5(v2, a1);
if ( !result )
break;
v2 += 2;
if ( v2 == &a1[2 * (a2 - 2) + 4] )
return 1LL;
}
return result;
}

original_code:
int all_ranks_equal(const struct card_t *cards, const int num_cards)
{
    int i = 0;
    for (i = 1; i < num_cards; i++)
        if (!ranks_equal(&cards[i], &cards[0]))
            return 0;
    return 1 ;
}

canonical_original_code:
int all_ranks_equal(struct card_t *cards, int num_cards)
{
    int i = 0;
    for (i = 1; i < num_cards; i++)
        if (!ranks_equal(&cards[i], &cards[0]))
            return 0;
    return 1 ;
}


decompiled_code:
const char *__fastcall show_rank(_DWORD *a1)
{
const char *result; // rax

switch ( *a1 )
{
case 2:
result = "TWO";
break;
case 3:
result = "THREE";
break;
case 4:
result = "FOUR";
break;
case 5:
result = "FIVE";
break;
case 6:
result = "SIX";
break;
case 7:
result = "SEVEN";
break;
case 8:
result = "EIGHT";
break;
case 9:
result = "NINE";
break;
case 0xA:
result = "TEN";
break;
case 0xB:
result = "JACK";
break;
case 0xC:
result = "QUEEN";
break;
case 0xD:
result = "KING";
break;
case 0xE:
result = "ACE";
break;
default:
result = "ERROR!!!";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(_DWORD *a1)
{
const char *result; // rax

switch ( *a1 )
{
case 2:
result = "TWO";
break;
case 3:
result = "THREE";
break;
case 4:
result = "FOUR";
break;
case 5:
result = "FIVE";
break;
case 6:
result = "SIX";
break;
case 7:
result = "SEVEN";
break;
case 8:
result = "EIGHT";
break;
case 9:
result = "NINE";
break;
case 0xA:
result = "TEN";
break;
case 0xB:
result = "JACK";
break;
case 0xC:
result = "QUEEN";
break;
case 0xD:
result = "KING";
break;
case 0xE:
result = "ACE";
break;
default:
result = "ERROR!!!";
break;
}
return result;
}

original_code:
char* show_rank(const struct card_t *card)
{
    switch(card->rank) {
    case TWO: return "TWO";
    case THREE: return "THREE";
    case FOUR: return "FOUR";
    case FIVE: return "FIVE";
    case SIX: return "SIX";
    case SEVEN: return "SEVEN";
    case EIGHT: return "EIGHT";
    case NINE: return "NINE";
    case TEN: return "TEN";
    case JACK: return "JACK";
    case QUEEN: return "QUEEN";
    case KING: return "KING";
    case ACE: return "ACE";
    default: return "ERROR!!!";
    }
}

canonical_original_code:
char *show_rank(struct card_t *card)
{
    switch(card->rank) {
    case TWO: return "TWO";
    case THREE: return "THREE";
    case FOUR: return "FOUR";
    case FIVE: return "FIVE";
    case SIX: return "SIX";
    case SEVEN: return "SEVEN";
    case EIGHT: return "EIGHT";
    case NINE: return "NINE";
    case TEN: return "TEN";
    case JACK: return "JACK";
    case QUEEN: return "QUEEN";
    case KING: return "KING";
    case ACE: return "ACE";
    default: return "ERROR!!!";
    }
}

return_type: char *


decompiled_code:
const char *__fastcall show_suit(__int64 a1)
{
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v1 = *(_DWORD *)(a1 + 4);
if ( v1 == 2 )
return "DIAMONDS";
if ( v1 > 2 )
{
v2 = v1 == 3;
result = "ERROR!!!!";
if ( v2 )
result = "CLUBS";
}
else
{
v2 = v1 == 0;
result = "SPADES";
if ( v2 )
result = "HEARTS";
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func8(__int64 a1)
{
unsigned int v1; // eax
bool v2; // zf
const char *result; // rax

v1 = *(_DWORD *)(a1 + 4);
if ( v1 == 2 )
return "DIAMONDS";
if ( v1 > 2 )
{
v2 = v1 == 3;
result = "ERROR!!!!";
if ( v2 )
result = "CLUBS";
}
else
{
v2 = v1 == 0;
result = "SPADES";
if ( v2 )
result = "HEARTS";
}
return result;
}

original_code:
char* show_suit(const struct card_t *card)
{
    switch(card->suit) {
    case HEARTS: return "HEARTS";
    case DIAMONDS: return "DIAMONDS";
    case CLUBS: return "CLUBS";
    case SPADES: return "SPADES";
    default: return "ERROR!!!!";
    }
}

canonical_original_code:
char *show_suit(struct card_t *card)
{
    switch(card->suit) {
    case HEARTS: return "HEARTS";
    case DIAMONDS: return "DIAMONDS";
    case CLUBS: return "CLUBS";
    case SPADES: return "SPADES";
    default: return "ERROR!!!!";
    }
}


decompiled_code:
__int64 __fastcall add_card_to_cards(__int64 a1, int *a2, __int64 a3)
{
__int64 result; // rax

result = *a2;
*(_QWORD *)(a1 + 8 * result) = a3;
++*a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int *a2, __int64 a3)
{
__int64 result; // rax

result = *a2;
*(_QWORD *)(a1 + 8 * result) = a3;
++*a2;
return result;
}

original_code:
void add_card_to_cards(struct card_t cards[], int *num_cards,
    const struct card_t card)
{
    cards[*num_cards] = card;
    (*num_cards)++;
}

canonical_original_code:
void add_card_to_cards(struct card_t cards[], int *num_cards, struct card_t card)
{
    cards[*num_cards] = card;
    (*num_cards)++;
}


decompiled_code:
void __fastcall sort_cards(void *a1, int a2)
{
qsort(a1, a2, 8uLL, (__compar_fn_t)card_cmp);
}

canonical_decompiled_code:
void __fastcall func11(void *a1, int a2)
{
qsort(a1, a2, 8uLL, (__compar_fn_t)card_cmp);
}

original_code:
void sort_cards(struct card_t *cards, const int num_cards) {
    qsort(cards, num_cards, sizeof(struct card_t), card_cmp);
}

canonical_original_code:
void sort_cards(struct card_t *cards, int num_cards) {
    qsort(cards, num_cards, sizeof(struct card_t), card_cmp);
}


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

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

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


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

original_code:
struct swap_choice_t pyromaniac_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 pyromaniac_ask_swap_choice(struct player_t *player)
{
    struct swap_choice_t choice;
    choice.hand_choice = 1;
    choice.faceup_choice = 1;
    return choice;
}

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


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

*a4 = 0;
if ( (unsigned int)has_cards_in_hand() )
{
result = choose_burn_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
if ( !*a4 )
result = choose_lowest_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
}
else
{
result = choose_burn_from_unsorted(a1 + 816, *(unsigned int *)(a1 + 980), a2, a3, a4);
if ( !*a4 )
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_burn_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
if ( !*a4 )
result = choose_lowest_from_sorted(a1 + 16, *(unsigned int *)(a1 + 976), a2, a3, a4);
}
else
{
result = choose_burn_from_unsorted(a1 + 816, *(unsigned int *)(a1 + 980), a2, a3, a4);
if ( !*a4 )
result = choose_lowest_from_unsorted(a1 + 816, *(unsigned int *)(a1 + 980), a2, a3, a4);
}
return result;
}

original_code:
void pyromaniac_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_burn_from_sorted(player->hand, player->hand_size, helper,
            card_choices, nchoices);
        if (*nchoices == 0) {
            choose_lowest_from_sorted(player->hand, player->hand_size, helper,
                card_choices, nchoices);
        }
    } else {
        choose_burn_from_unsorted(player->face_up, player->face_up_size, helper,
            card_choices, nchoices);
        if (*nchoices == 0) {
            choose_lowest_from_unsorted(player->face_up, player->face_up_size,
                helper, card_choices, nchoices);
        }
    }
}

canonical_original_code:
void pyromaniac_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_burn_from_sorted(player->hand, player->hand_size, helper,
            card_choices, nchoices);
        if (*nchoices == 0) {
            choose_lowest_from_sorted(player->hand, player->hand_size, helper,
                card_choices, nchoices);
        }
    } else {
        choose_burn_from_unsorted(player->face_up, player->face_up_size, helper,
            card_choices, nchoices);
        if (*nchoices == 0) {
            choose_lowest_from_unsorted(player->face_up, player->face_up_size,
                helper, card_choices, nchoices);
        }
    }
}


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

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

canonical_original_code:
int pyromaniac_ask_face_down_move()
{
    return 1;
}


decompiled_code:
void *__fastcall make_player(void *a1, const char *a2, char a3)
{
_QWORD v5[128]; // [rsp+0h] [rbp-418h] BYREF

strcpy((char *)v5, a2);
HIDWORD(v5[1]) = a3 != 104;
v5[122] = 0LL;
LODWORD(v5[123]) = 0;
if ( a3 == 112 )
{
v5[124] = &pyromaniac_ask_swap_cards;
v5[125] = &pyromaniac_ask_swap_choice;
v5[126] = &pyromaniac_ask_move;
v5[127] = &pyromaniac_ask_face_down_move;
goto LABEL_8;
}
if ( a3 > 112 )
{
if ( a3 == 114 )
{
v5[124] = &randomcardplayer_ask_swap_cards;
v5[125] = &randomcardplayer_ask_swap_choice;
v5[126] = &randomcardplayer_ask_move;
v5[127] = &randomcardplayer_ask_face_down_move;
goto LABEL_8;
}
LABEL_11:
v5[124] = 0LL;
v5[125] = 0LL;
v5[126] = 0LL;
v5[127] = 0LL;
goto LABEL_8;
}
if ( a3 == 104 )
{
v5[124] = &human_ask_swap_cards;
v5[125] = &human_ask_swap_choice;
v5[126] = &human_ask_move;
v5[127] = &human_ask_face_down_move;
goto LABEL_8;
}
if ( a3 != 108 )
goto LABEL_11;
v5[124] = &lowcardplayer_ask_swap_cards;
v5[125] = &lowcardplayer_ask_swap_choice;
v5[126] = &lowcardplayer_ask_move;
v5[127] = &lowcardplayer_ask_face_down_move;
LABEL_8:
qmemcpy(a1, v5, 0x400uLL);
return a1;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, const char *a2, char a3)
{
_QWORD v5[128]; // [rsp+0h] [rbp-418h] BYREF

strcpy((char *)v5, a2);
HIDWORD(v5[1]) = a3 != 104;
v5[122] = 0LL;
LODWORD(v5[123]) = 0;
if ( a3 == 112 )
{
v5[124] = &pyromaniac_ask_swap_cards;
v5[125] = &pyromaniac_ask_swap_choice;
v5[126] = &pyromaniac_ask_move;
v5[127] = &pyromaniac_ask_face_down_move;
goto LABEL_8;
}
if ( a3 > 112 )
{
if ( a3 == 114 )
{
v5[124] = &randomcardplayer_ask_swap_cards;
v5[125] = &randomcardplayer_ask_swap_choice;
v5[126] = &randomcardplayer_ask_move;
v5[127] = &randomcardplayer_ask_face_down_move;
goto LABEL_8;
}
LABEL_11:
v5[124] = 0LL;
v5[125] = 0LL;
v5[126] = 0LL;
v5[127] = 0LL;
goto LABEL_8;
}
if ( a3 == 104 )
{
v5[124] = &human_ask_swap_cards;
v5[125] = &human_ask_swap_choice;
v5[126] = &human_ask_move;
v5[127] = &human_ask_face_down_move;
goto LABEL_8;
}
if ( a3 != 108 )
goto LABEL_11;
v5[124] = &lowcardplayer_ask_swap_cards;
v5[125] = &lowcardplayer_ask_swap_choice;
v5[126] = &lowcardplayer_ask_move;
v5[127] = &lowcardplayer_ask_face_down_move;
LABEL_8:
qmemcpy(a1, v5, 0x400uLL);
return a1;
}

original_code:
struct player_t make_player(const char *name, const char type)
{
    struct player_t player;
    strcpy(player.name, name);
    if (type == 'h')
        player.is_computer = 0;
    else
        player.is_computer = 1;
    player.hand_size = 0;
    player.face_up_size = 0;
    player.face_down_size = 0;
    switch(type) {
    case 'r':
        player.ask_swap_cards = randomcardplayer_ask_swap_cards;
        player.ask_swap_choice = randomcardplayer_ask_swap_choice;
        player.ask_move = randomcardplayer_ask_move;
        player.ask_face_down_move = randomcardplayer_ask_face_down_move;
        break;
    case 'l':
        player.ask_swap_cards = lowcardplayer_ask_swap_cards;
        player.ask_swap_choice = lowcardplayer_ask_swap_choice;
        player.ask_move = lowcardplayer_ask_move;
        player.ask_face_down_move = lowcardplayer_ask_face_down_move;
        break;
    case 'h':
        player.ask_swap_cards = human_ask_swap_cards;
        player.ask_swap_choice = human_ask_swap_choice;
        player.ask_move = human_ask_move;
        player.ask_face_down_move = human_ask_face_down_move;
        break;
    case 'p':
        player.ask_swap_cards = pyromaniac_ask_swap_cards;
        player.ask_swap_choice = pyromaniac_ask_swap_choice;
        player.ask_move = pyromaniac_ask_move;
        player.ask_face_down_move = pyromaniac_ask_face_down_move;
        break;
    default:
        player.ask_swap_cards = ((void *)0);
        player.ask_swap_choice = ((void *)0);
        player.ask_move = ((void *)0);
        player.ask_face_down_move = ((void *)0);
    }
    return player;
}

canonical_original_code:
struct player_t make_player(char *name, char type)
{
    struct player_t player;
    strcpy(player.name, name);
    if (type == 'h')
        player.is_computer = 0;
    else
        player.is_computer = 1;
    player.hand_size = 0;
    player.face_up_size = 0;
    player.face_down_size = 0;
    switch(type) {
    case 'r':
        player.ask_swap_cards = randomcardplayer_ask_swap_cards;
        player.ask_swap_choice = randomcardplayer_ask_swap_choice;
        player.ask_move = randomcardplayer_ask_move;
        player.ask_face_down_move = randomcardplayer_ask_face_down_move;
        break;
    case 'l':
        player.ask_swap_cards = lowcardplayer_ask_swap_cards;
        player.ask_swap_choice = lowcardplayer_ask_swap_choice;
        player.ask_move = lowcardplayer_ask_move;
        player.ask_face_down_move = lowcardplayer_ask_face_down_move;
        break;
    case 'h':
        player.ask_swap_cards = human_ask_swap_cards;
        player.ask_swap_choice = human_ask_swap_choice;
        player.ask_move = human_ask_move;
        player.ask_face_down_move = human_ask_face_down_move;
        break;
    case 'p':
        player.ask_swap_cards = pyromaniac_ask_swap_cards;
        player.ask_swap_choice = pyromaniac_ask_swap_choice;
        player.ask_move = pyromaniac_ask_move;
        player.ask_face_down_move = pyromaniac_ask_face_down_move;
        break;
    default:
        player.ask_swap_cards = ((void *)0);
        player.ask_swap_choice = ((void *)0);
        player.ask_move = ((void *)0);
        player.ask_face_down_move = ((void *)0);
    }
    return player;
}

variable_types:
name
char *

variable_types: type char

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 __fastcall deal_to_hand(__int64 a1, __int64 a2)
{
return add_card_to_cards(a1 + 16, a1 + 976, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return add_card_to_cards(a1 + 16, a1 + 976, a2);
}

original_code:
void deal_to_hand(struct player_t *player, const struct card_t card)
{
    add_card_to_cards(player->hand, &player->hand_size, card);
}

canonical_original_code:
void deal_to_hand(struct player_t *player, struct card_t card)
{
    add_card_to_cards(player->hand, &player->hand_size, card);
}


decompiled_code:
__int64 __fastcall deal_to_face_up(__int64 a1, __int64 a2)
{
return add_card_to_cards(a1 + 816, a1 + 980, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return add_card_to_cards(a1 + 816, a1 + 980, a2);
}

original_code:
void deal_to_face_up(struct player_t *player, const struct card_t card)
{
    add_card_to_cards(player->face_up, &player->face_up_size, card);
}

canonical_original_code:
void deal_to_face_up(struct player_t *player, struct card_t card)
{
    add_card_to_cards(player->face_up, &player->face_up_size, card);
}


decompiled_code:
__int64 __fastcall deal_to_face_down(__int64 a1, __int64 a2)
{
return add_card_to_cards(a1 + 896, a1 + 984, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return add_card_to_cards(a1 + 896, a1 + 984, a2);
}

original_code:
void deal_to_face_down(struct player_t *player, const struct card_t card)
{
    add_card_to_cards(player->face_down, &player->face_down_size, card);
}

canonical_original_code:
void deal_to_face_down(struct player_t *player, struct card_t card)
{
    add_card_to_cards(player->face_down, &player->face_down_size, card);
}


decompiled_code:
__int64 __fastcall remove_from_hand(__int64 a1, __int64 a2)
{
return remove_card_from_cards(a1 + 16, a1 + 976, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return remove_card_from_cards(a1 + 16, a1 + 976, a2);
}

original_code:
void remove_from_hand(struct player_t *player, const struct card_t *card)
{
    remove_card_from_cards(player->hand, &player->hand_size, card);
}

canonical_original_code:
void remove_from_hand(struct player_t *player, struct card_t *card)
{
    remove_card_from_cards(player->hand, &player->hand_size, card);
}

variable_types:
card
struct card_t *


decompiled_code:
__int64 __fastcall remove_from_face_up(__int64 a1, __int64 a2)
{
return remove_card_from_cards(a1 + 816, a1 + 980, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return remove_card_from_cards(a1 + 816, a1 + 980, a2);
}

original_code:
void remove_from_face_up(struct player_t *player, const struct card_t *card)
{
    remove_card_from_cards(player->face_up, &player->face_up_size, card);
}

canonical_original_code:
void remove_from_face_up(struct player_t *player, struct card_t *card)
{
    remove_card_from_cards(player->face_up, &player->face_up_size, card);
}


decompiled_code:
__int64 __fastcall remove_from_face_down(__int64 a1, __int64 a2)
{
return remove_card_from_cards(a1 + 896, a1 + 984, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
return remove_card_from_cards(a1 + 896, a1 + 984, a2);
}

original_code:
void remove_from_face_down(struct player_t *player, const struct card_t *card)
{
    remove_card_from_cards(player->face_down, &player->face_down_size, card);
}

canonical_original_code:
void remove_from_face_down(struct player_t *player, struct card_t *card)
{
    remove_card_from_cards(player->face_down, &player->face_down_size, card);
}


decompiled_code:
void __fastcall find_lowest_card_by_player(__int64 a1, int a2, _QWORD *a3)
{
__int64 v4; // rbx

if ( a2 > 0 )
{
v4 = a1 + 16;
do
{
*a3++ = find_lowest_card(v4, *(unsigned int *)(v4 + 960));
v4 += 1024LL;
}
while ( v4 != a1 + ((unsigned __int64)(unsigned int)(a2 - 1) << 10) + 1040 );
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, _QWORD *a3)
{
__int64 v4; // rbx

if ( a2 > 0 )
{
v4 = a1 + 16;
do
{
*a3++ = find_lowest_card(v4, *(unsigned int *)(v4 + 960));
v4 += 1024LL;
}
while ( v4 != a1 + ((unsigned __int64)(unsigned int)(a2 - 1) << 10) + 1040 );
}
}

original_code:
void find_lowest_card_by_player(const struct player_t *players,
    const int num_players, struct card_t *cards)
{
    int i;
    for (i = 0 ; i < num_players ; i++)
        cards[i] = find_lowest_card(players[i].hand, players[i].hand_size);
}

canonical_original_code:
void find_lowest_card_by_player(struct player_t *players, int num_players, struct card_t *cards)
{
    int i;
    for (i = 0 ; i < num_players ; i++)
        cards[i] = find_lowest_card(players[i].hand, players[i].hand_size);
}


swap

original_code:
void swap(struct player_t *player, const struct swap_choice_t *choice)
{
    struct card_t temp;
    temp = player->hand[choice->hand_choice-1];
    player->hand[choice->hand_choice-1] = player->face_up[choice->faceup_choice-1];
    player->face_up[choice->faceup_choice-1] = temp;
    sort_cards(player->hand, player->hand_size);
}

canonical_original_code:
void swap(struct player_t *player, struct swap_choice_t *choice)
{
    struct card_t temp;
    temp = player->hand[choice->hand_choice-1];
    player->hand[choice->hand_choice-1] = player->face_up[choice->faceup_choice-1];
    player->face_up[choice->faceup_choice-1] = temp;
    sort_cards(player->hand, player->hand_size);
}

variable_types:
choice
struct swap_choice_t *


decompiled_code:
_BOOL8 __fastcall has_cards(int *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1[244] <= 0 && a1[245] <= 0 )
result = a1[246] > 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int *a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1[244] <= 0 && a1[245] <= 0 )
result = a1[246] > 0;
return result;
}

original_code:
int has_cards(const struct player_t *player)
{
    if (player->hand_size > 0)
        return 1;
    if (player->face_up_size > 0)
        return 1;
    if (player->face_down_size > 0)
        return 1;
    return 0;
}

canonical_original_code:
int has_cards(struct player_t *player)
{
    if (player->hand_size > 0)
        return 1;
    if (player->face_up_size > 0)
        return 1;
    if (player->face_down_size > 0)
        return 1;
    return 0;
}


decompiled_code:
_BOOL8 __fastcall has_cards_in_hand(__int64 a1)
{
return *(_DWORD *)(a1 + 976) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
return *(_DWORD *)(a1 + 976) > 0;
}

original_code:
int has_cards_in_hand(const struct player_t *player)
{
    return player->hand_size > 0;
}

canonical_original_code:
int has_cards_in_hand(struct player_t *player)
{
    return player->hand_size > 0;
}


original_code:
int ask_swap_cards(const struct player_t *player)
{
    return player->ask_swap_cards(player);
}

canonical_original_code:
int ask_swap_cards(struct player_t *player)
{
    return player->ask_swap_cards(player);
}


original_code:
struct swap_choice_t ask_swap_choice(const struct player_t *player)
{
    return player->ask_swap_choice(player);
}

canonical_original_code:
struct swap_choice_t ask_swap_choice(struct player_t *player)
{
    return player->ask_swap_choice(player);
}


original_code:
void ask_move(const struct player_t *player, const struct player_helper_t *helper,
    int card_choices[], int *nchoices)
{
    return player->ask_move(player, helper, card_choices, nchoices);
}

canonical_original_code:
void ask_move(struct player_t *player, struct player_helper_t *helper, int card_choices[], int *nchoices)
{
    return player->ask_move(player, helper, card_choices, nchoices);
}


decompiled_code:
__int64 __fastcall ask_face_down_move(__int64 a1)
{
return (*(__int64 (**)(void))(a1 + 1016))();
}

original_code:
int ask_face_down_move(const struct player_t *player)
{
    return player->ask_face_down_move();
}

canonical_original_code:
int ask_face_down_move(struct player_t *player)
{
    return player->ask_face_down_move();
}


decompiled_code:
__int64 __fastcall choose_first_playable_from(__int64 a1, int a2, __int64 a3)
{
unsigned int v5; // ebp

if ( a2 <= 0 )
return (unsigned int)-1;
v5 = 0;
while ( !(unsigned int)can_lay(a1, a3, *(unsigned int *)(a3 + 2080)) )
{
++v5;
a1 += 8LL;
if ( a2 == v5 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3)
{
unsigned int v5; // ebp

if ( a2 <= 0 )
return (unsigned int)-1;
v5 = 0;
while ( !(unsigned int)can_lay(a1, a3, *(unsigned int *)(a3 + 2080)) )
{
++v5;
a1 += 8LL;
if ( a2 == v5 )
return (unsigned int)-1;
}
return v5;
}

original_code:
static int choose_first_playable_from(const struct card_t cards[],
    const int ncards, const struct player_helper_t *helper)
{
    int i;
    for (i = 0; i < ncards; i++)
        if (can_lay(&cards[i], helper->pile, helper->pile_size))
            return i;
    return -1;
}

canonical_original_code:
static int choose_first_playable_from(struct card_t cards[], int ncards, struct player_helper_t *helper)
{
    int i;
    for (i = 0; i < ncards; i++)
        if (can_lay(&cards[i], helper->pile, helper->pile_size))
            return i;
    return -1;
}

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; } []

variable_types: ncards int

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


decompiled_code:
void __fastcall add_similar_from_sorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v8; // er15
int i; // ebx

if ( a2 > 0 )
{
v8 = 0;
for ( i = 0; i != a2; ++i )
{
if ( (unsigned int)ranks_equal(a1, a3) )
{
*(_DWORD *)(a4 + 4LL * (int)(*a5)++) = i;
v8 = 1;
}
else if ( v8 )
{
return;
}
a1 += 8LL;
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v8; // er15
int i; // ebx

if ( a2 > 0 )
{
v8 = 0;
for ( i = 0; i != a2; ++i )
{
if ( (unsigned int)ranks_equal(a1, a3) )
{
*(_DWORD *)(a4 + 4LL * (int)(*a5)++) = i;
v8 = 1;
}
else if ( v8 )
{
return;
}
a1 += 8LL;
}
}
}

original_code:
static void add_similar_from_sorted(const struct card_t cards[], const int ncards,
    const struct card_t *first, int choices[], int *nchoices)
{
    int i;
    int found = 0;
    for (i = 0; i < ncards; i++) {
        if (ranks_equal(&cards[i], first)) {
            choices[*nchoices] = i;
            (*nchoices)++;
            found = 1;
        } else if (found) {
            break;
        }
    }
}

canonical_original_code:
static void add_similar_from_sorted(struct card_t cards[], int ncards, struct card_t *first, int choices[], int *nchoices)
{
    int i;
    int found = 0;
    for (i = 0; i < ncards; i++) {
        if (ranks_equal(&cards[i], first)) {
            choices[*nchoices] = i;
            (*nchoices)++;
            found = 1;
        } else if (found) {
            break;
        }
    }
}

variable_types:
first
struct card_t *

variable_types:
choices
int []

variable_types: found int


decompiled_code:
void __fastcall add_similar_from_unsorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( (unsigned int)ranks_equal(a1, a3) )
*(_DWORD *)(a4 + 4LL * (int)(*a5)++) = i;
a1 += 8LL;
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int i; // ebx

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
if ( (unsigned int)ranks_equal(a1, a3) )
*(_DWORD *)(a4 + 4LL * (int)(*a5)++) = i;
a1 += 8LL;
}
}
}

original_code:
static void add_similar_from_unsorted(const struct card_t cards[], const int ncards,
    const struct card_t *first, int choices[], int *nchoices)
{
    int i;
    for (i = 0; i < ncards; i++) {
        if (ranks_equal(&cards[i], first)) {
            choices[*nchoices] = i;
            (*nchoices)++;
        }
    }
}

canonical_original_code:
static void add_similar_from_unsorted(struct card_t cards[], int ncards, struct card_t *first, int choices[], int *nchoices)
{
    int i;
    for (i = 0; i < ncards; i++) {
        if (ranks_equal(&cards[i], first)) {
            choices[*nchoices] = i;
            (*nchoices)++;
        }
    }
}


decompiled_code:
void __fastcall choose_lowest_from_sorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v7; // eax

v7 = choose_first_playable_from(a1, a2, a3);
add_similar_from_sorted(a1, a2, a1 + 8LL * v7, a4, a5);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v7; // eax

v7 = func0(a1, a2, a3);
func1(a1, a2, a1 + 8LL * v7, a4, a5);
}

original_code:
void choose_lowest_from_sorted(const struct card_t cards[], const int ncards,
    const struct player_helper_t *helper, int choices[], int *nchoices)
{
    int first = choose_first_playable_from(cards, ncards, helper);
    add_similar_from_sorted(cards, ncards, &cards[first], choices, nchoices);
}

canonical_original_code:
void choose_lowest_from_sorted(struct card_t cards[], int ncards, struct player_helper_t *helper, int choices[], int *nchoices)
{
    int first = choose_first_playable_from(cards, ncards, helper);
    add_similar_from_sorted(cards, ncards, &cards[first], choices, nchoices);
}

variable_types: first int


decompiled_code:
void __fastcall choose_lowest_from_unsorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
void *v7; // rsp
__int64 i; // rax
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-40h] BYREF
__int64 v11; // [rsp+8h] [rbp-38h]

v11 = a4;
v7 = alloca(8LL * a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
*(&v10 + i) = *(_QWORD *)(a1 + 8 * i);
}
sort_cards(&v10, (unsigned int)a2);
v9 = choose_first_playable_from((__int64)&v10, a2, a3);
add_similar_from_unsorted(a1, a2, (__int64)(&v10 + v9), v11, a5);
}

original_code:
void choose_lowest_from_unsorted(const struct card_t cards[], const int ncards,
    const struct player_helper_t *helper, int choices[], int *nchoices)
{
    struct card_t sorted[ncards];
    int i;
    for (i = 0; i<ncards; i++)
        sorted[i] = cards[i];
    sort_cards(sorted, ncards);
    int first = choose_first_playable_from(sorted, ncards, helper);
    add_similar_from_unsorted(cards, ncards, &sorted[first], choices, nchoices);
}

canonical_original_code:
void choose_lowest_from_unsorted(struct card_t cards[], int ncards, struct player_helper_t *helper, int choices[], int *nchoices)
{
    struct card_t sorted[-1];
    int i;
    for (i = 0; i<ncards; i++)
        sorted[i] = cards[i];
    sort_cards(sorted, ncards);
    int first = choose_first_playable_from(sorted, ncards, helper);
    add_similar_from_unsorted(cards, ncards, &sorted[first], choices, nchoices);
}

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; } [-1]


original_code:
void choose_random_from_sorted(const struct card_t cards[], const int ncards,
    const struct player_helper_t *helper, int choices[], int *nchoices)
{
    int i;
    int possible_choices[ncards];
    for (i = 0; i < ncards; i++) {
        possible_choices[i] = i;
    }
    shuffle(possible_choices, ncards);
    int first = 0;
    for (i = 0; i < ncards; i++) {
        if (can_lay(&cards[possible_choices[i]], helper->pile, helper->pile_size)) {
            first = possible_choices[i];
            break;
        }
    }
    add_similar_from_sorted(cards, ncards, &cards[first], choices, nchoices);
}

canonical_original_code:
void choose_random_from_sorted(struct card_t cards[], int ncards, struct player_helper_t *helper, int choices[], int *nchoices)
{
    int i;
    int possible_choices[-1];
    for (i = 0; i < ncards; i++) {
        possible_choices[i] = i;
    }
    shuffle(possible_choices, ncards);
    int first = 0;
    for (i = 0; i < ncards; i++) {
        if (can_lay(&cards[possible_choices[i]], helper->pile, helper->pile_size)) {
            first = possible_choices[i];
            break;
        }
    }
    add_similar_from_sorted(cards, ncards, &cards[first], choices, nchoices);
}


decompiled_code:
void __fastcall choose_random_from_unsorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v7; // eax

v7 = choose_first_playable_from(a1, a2, a3);
add_similar_from_unsorted(a1, a2, a1 + 8LL * v7, a4, a5);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v7; // eax

v7 = func0(a1, a2, a3);
func2(a1, a2, a1 + 8LL * v7, a4, a5);
}

original_code:
void choose_random_from_unsorted(const struct card_t cards[], const int ncards,
    const struct player_helper_t *helper, int choices[], int *nchoices)
{
    int first = choose_first_playable_from(cards, ncards, helper);
    add_similar_from_unsorted(cards, ncards, &cards[first], choices, nchoices);
}

canonical_original_code:
void choose_random_from_unsorted(struct card_t cards[], int ncards, struct player_helper_t *helper, int choices[], int *nchoices)
{
    int first = choose_first_playable_from(cards, ncards, helper);
    add_similar_from_unsorted(cards, ncards, &cards[first], choices, nchoices);
}


decompiled_code:
void __fastcall choose_burn_from_sorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
int v5; // ebp
_DWORD *v8; // rbx

v5 = a2 - 1;
if ( a2 - 1 >= 0 )
{
v8 = (_DWORD *)(a1 + 8LL * a2 - 8);
do
{
if ( *v8 == 10 )
{
*(_DWORD *)(a4 + 4LL * (int)(*a5)++) = v5;
}
else if ( !(unsigned int)special_card(v8) )
{
return;
}
--v5;
v8 -= 2;
}
while ( v5 != -1 );
}
}

original_code:
void choose_burn_from_sorted(const struct card_t cards[], const int ncards,
    const struct player_helper_t *helper, int choices[], int *nchoices)
{
    int i;
    for (i = ncards-1; i>=0 ; i--) {
        if (cards[i].rank == 10) {
            choices[*nchoices] = i;
            (*nchoices)++;
        } else if (!special_card(&cards[i])) {
            break;
        }
    }
}

canonical_original_code:
void choose_burn_from_sorted(struct card_t cards[], int ncards, struct player_helper_t *helper, int choices[], int *nchoices)
{
    int i;
    for (i = ncards-1; i>=0 ; i--) {
        if (cards[i].rank == 10) {
            choices[*nchoices] = i;
            (*nchoices)++;
        } else if (!special_card(&cards[i])) {
            break;
        }
    }
}


decompiled_code:
void __fastcall choose_burn_from_unsorted(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5)
{
__int64 i; // rax

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
if ( *(_DWORD *)(a1 + 8 * i) == 10 )
*(_DWORD *)(a4 + 4LL * (int)(*a5)++) = i;
}
}
}

original_code:
void choose_burn_from_unsorted(const struct card_t cards[], const int ncards,
    const struct player_helper_t *helper, int choices[], int *nchoices)
{
    int i;
    for (i = 0; i < ncards; i++) {
        if (cards[i].rank == 10) {
            choices[*nchoices] = i;
            (*nchoices)++;
        }
    }
}

canonical_original_code:
void choose_burn_from_unsorted(struct card_t cards[], int ncards, struct player_helper_t *helper, int choices[], int *nchoices)
{
    int i;
    for (i = 0; i < ncards; i++) {
        if (cards[i].rank == 10) {
            choices[*nchoices] = i;
            (*nchoices)++;
        }
    }
}


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