dividesegment

decompiled_code:
__int64 __fastcall dividesegment(unsigned int *a1)
{
__int64 result; // rax
__int64 v2; // rsi
const char *v3; // r12
unsigned int v4; // ebp
__int64 v5; // rdx
unsigned int v6; // er13
unsigned int v7; // eax

result = *a1;
if ( (_DWORD)result )
{
v2 = *((_QWORD *)a1 + 4);
if ( v2 )
{
switch ( (int)result )
{
case 0:
case 5:
v4 = 1;
v3 = (const char *)&unk_52C;
break;
case 1:
v7 = a1[1];
v4 = 1;
v3 = "~text";
if ( (v7 & 1) == 0 )
{
v3 = "~data";
if ( (v7 & 2) == 0 )
{
v3 = "~rodata";
if ( (v7 & 4) == 0 )
v3 = (const char *)&unk_52C;
}
}
break;
case 2:
v4 = 16;
v3 = "~dynamic";
break;
case 3:
v4 = 7;
v3 = "~interp";
break;
case 4:
v4 = 8;
v3 = "~note";
break;
case 6:
v4 = 18;
v3 = "~phdrs";
break;
default:
v3 = (const char *)&unk_52C;
if ( (_DWORD)result == 1685382480 )
v3 = "~eh_frame";
v4 = 3 * ((_DWORD)result == 1685382480) + 1;
break;
}
result = recordpiece(*((_QWORD *)a1 + 1), v2, v4, v3, a1[12]);
v5 = *((_QWORD *)a1 + 5);
v6 = result;
if ( v5 )
result = recordaddress(*((_QWORD *)a1 + 2), *((_QWORD *)a1 + 1), v5, v3);
if ( v4 == 16 )
result = hashdynamicsection(*((_QWORD *)a1 + 1), *((_QWORD *)a1 + 4), v6);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
__int64 result; // rax
__int64 v2; // rsi
const char *v3; // r12
unsigned int v4; // ebp
__int64 v5; // rdx
unsigned int v6; // er13
unsigned int v7; // eax

result = *a1;
if ( (_DWORD)result )
{
v2 = *((_QWORD *)a1 + 4);
if ( v2 )
{
switch ( (int)result )
{
case 0:
case 5:
v4 = 1;
v3 = (const char *)&unk_52C;
break;
case 1:
v7 = a1[1];
v4 = 1;
v3 = "~text";
if ( (v7 & 1) == 0 )
{
v3 = "~data";
if ( (v7 & 2) == 0 )
{
v3 = "~rodata";
if ( (v7 & 4) == 0 )
v3 = (const char *)&unk_52C;
}
}
break;
case 2:
v4 = 16;
v3 = "~dynamic";
break;
case 3:
v4 = 7;
v3 = "~interp";
break;
case 4:
v4 = 8;
v3 = "~note";
break;
case 6:
v4 = 18;
v3 = "~phdrs";
break;
default:
v3 = (const char *)&unk_52C;
if ( (_DWORD)result == 1685382480 )
v3 = "~eh_frame";
v4 = 3 * ((_DWORD)result == 1685382480) + 1;
break;
}
result = recordpiece(*((_QWORD *)a1 + 1), v2, v4, v3, a1[12]);
v5 = *((_QWORD *)a1 + 5);
v6 = result;
if ( v5 )
result = recordaddress(*((_QWORD *)a1 + 2), *((_QWORD *)a1 + 1), v5, v3);
if ( v4 == 16 )
result = hashdynamicsection(*((_QWORD *)a1 + 1), *((_QWORD *)a1 + 4), v6);
}
}
return result;
}

original_code:
static void dividesegment(Elf64_Phdr const *phdr)
{
    char const *str;
    int type, n;
    if (phdr->p_type == 0 || phdr->p_filesz == 0)
        return;
    switch (phdr->p_type) {
      case 6: type = P_PHDRTAB; str = "~phdrs"; break;
      case 2: type = P_DYNAMIC; str = "~dynamic"; break;
      case 3: type = P_STRINGS; str = "~interp"; break;
      case 4: type = P_NOTE; str = "~note"; break;
      case 0x6474e550: type = P_WORDS; str = "~eh_frame"; break;
      case 1:
        type = P_SECTION;
        if (phdr->p_type == 1) {
     if (phdr->p_flags & (1 << 0))
  str = "~text";
     else if (phdr->p_flags & (1 << 1))
  str = "~data";
     else if (phdr->p_flags & (1 << 2))
  str = "~rodata";
     else
  str = "";
        }
        break;
      default:
        type = P_SECTION;
        str = "";
        break;
    }
    n = recordpiece(phdr->p_offset, phdr->p_filesz, type, str, phdr->p_align);
    if (phdr->p_memsz && str)
        recordaddress(phdr->p_vaddr, phdr->p_offset, phdr->p_memsz, str);
    if (type == P_DYNAMIC)
 hashdynamicsection(phdr->p_offset, phdr->p_filesz, n);
}

canonical_original_code:
static void dividesegment(struct Elf64_Phdr *phdr)
{
    char *str;
    int type; int n;
    if (phdr->p_type == 0 || phdr->p_filesz == 0)
        return;
    switch (phdr->p_type) {
      case 6: type = P_PHDRTAB; str = "~phdrs"; break;
      case 2: type = P_DYNAMIC; str = "~dynamic"; break;
      case 3: type = P_STRINGS; str = "~interp"; break;
      case 4: type = P_NOTE; str = "~note"; break;
      case 0x6474e550: type = P_WORDS; str = "~eh_frame"; break;
      case 1:
        type = P_SECTION;
        if (phdr->p_type == 1) {
     if (phdr->p_flags & (1 << 0))
  str = "~text";
     else if (phdr->p_flags & (1 << 1))
  str = "~data";
     else if (phdr->p_flags & (1 << 2))
  str = "~rodata";
     else
  str = "";
        }
        break;
      default:
        type = P_SECTION;
        str = "";
        break;
    }
    n = recordpiece(phdr->p_offset, phdr->p_filesz, type, str, phdr->p_align);
    if (phdr->p_memsz && str)
        recordaddress(phdr->p_vaddr, phdr->p_offset, phdr->p_memsz, str);
    if (type == P_DYNAMIC)
 hashdynamicsection(phdr->p_offset, phdr->p_filesz, n);
}

variable_types: struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; } *

variable_types:
str
char *

variable_types: type int

variable_types: n int


dividesegments

original_code:
void dividesegments(long offset, int count, int entsize)
{
    Elf64_Phdr ph64;
    Elf32_Phdr ph32;
    void const *ptr;
    long size;
    int i;
    if (!offset || !count)
 return;
    if (!entsize) {
 warn("ignoring zero value for phentsize.");
 entsize = ((int)(iself64() ? sizeof(Elf64_Phdr) : sizeof(Elf32_Phdr)));
    } else if (entsize != ((int)(iself64() ? sizeof(Elf64_Phdr) : sizeof(Elf32_Phdr)))) {
 warn("program header table entry size: %d instead of %d.",
     entsize, ((int)(iself64() ? sizeof(Elf64_Phdr) : sizeof(Elf32_Phdr))));
    }
    size = count * entsize;
    ptr = getptrto(offset, &size);
    if (size != count * entsize) {
 if (size == 0) {
     warn("invalid program segment header table offset: %ld.", offset);
     return;
 }
 warn("program header table extends %ld bytes past EOF.",
      count * entsize - size);
    }
    recordpiece(offset, size, P_PHDRTAB, "phdrs", ((int)(iself64() ? sizeof(Elf64_Addr) : sizeof(Elf32_Addr))));
    count = size / entsize;
    if (!count)
 return;
    for (i = 0 ; i < count ; ++i) {
 if (iself64()) {
     if (entsize >= (int)sizeof(Elf64_Phdr)) {
  dividesegment((Elf64_Phdr const*)ptr + i);
     } else {
  memcpy(&ph64, (Elf64_Phdr const*)ptr + i, entsize);
  memset((char*)&ph64 + entsize, 0, sizeof ph64 - entsize);
  dividesegment(&ph64);
     }
 } else {
     if (entsize >= (int)sizeof(Elf32_Phdr)) {
  memcpy(&ph32, (char const*)ptr + i * entsize, sizeof ph32);
     } else {
  memcpy(&ph32, (char const*)ptr + i * entsize, entsize);
  memset((char*)&ph32 + entsize, 0, sizeof ph32 - entsize);
     }
     ph64.p_type = ph32.p_type;
     ph64.p_flags = ph32.p_flags;
     ph64.p_offset = ph32.p_offset;
     ph64.p_vaddr = ph32.p_vaddr;
     ph64.p_paddr = ph32.p_paddr;
     ph64.p_filesz = ph32.p_filesz;
     ph64.p_memsz = ph32.p_memsz;
     ph64.p_align = ph32.p_align;
     dividesegment(&ph64);
 }
    }
    dividedynsegments();
}

canonical_original_code:
void dividesegments(long offset, int count, int entsize)
{
    struct Elf64_Phdr ph64;
    struct Elf32_Phdr ph32;
    void *ptr;
    long size;
    int i;
    if (!offset || !count)
 return;
    if (!entsize) {
 warn("ignoring zero value for phentsize.");
 entsize = ((int)(iself64() ? sizeof(Elf64_Phdr) : sizeof(Elf32_Phdr)));
    } else if (entsize != ((int)(iself64() ? sizeof(Elf64_Phdr) : sizeof(Elf32_Phdr)))) {
 warn("program header table entry size: %d instead of %d.",
     entsize, ((int)(iself64() ? sizeof(Elf64_Phdr) : sizeof(Elf32_Phdr))));
    }
    size = count * entsize;
    ptr = getptrto(offset, &size);
    if (size != count * entsize) {
 if (size == 0) {
     warn("invalid program segment header table offset: %ld.", offset);
     return;
 }
 warn("program header table extends %ld bytes past EOF.",
      count * entsize - size);
    }
    recordpiece(offset, size, P_PHDRTAB, "phdrs", ((int)(iself64() ? sizeof(Elf64_Addr) : sizeof(Elf32_Addr))));
    count = size / entsize;
    if (!count)
 return;
    for (i = 0 ; i < count ; ++i) {
 if (iself64()) {
     if (entsize >= (int)sizeof(Elf64_Phdr)) {
  dividesegment((struct Elf64_Phdr *)ptr + i);
     } else {
  memcpy(&ph64, (struct Elf64_Phdr *)ptr + i, entsize);
  memset((char *)&ph64 + entsize, 0, sizeof ph64 - entsize);
  dividesegment(&ph64);
     }
 } else {
     if (entsize >= (int)sizeof(Elf32_Phdr)) {
  memcpy(&ph32, (char *)ptr + i * entsize, sizeof ph32);
     } else {
  memcpy(&ph32, (char *)ptr + i * entsize, entsize);
  memset((char *)&ph32 + entsize, 0, sizeof ph32 - entsize);
     }
     ph64.p_type = ph32.p_type;
     ph64.p_flags = ph32.p_flags;
     ph64.p_offset = ph32.p_offset;
     ph64.p_vaddr = ph32.p_vaddr;
     ph64.p_paddr = ph32.p_paddr;
     ph64.p_filesz = ph32.p_filesz;
     ph64.p_memsz = ph32.p_memsz;
     ph64.p_align = ph32.p_align;
     dividesegment(&ph64);
 }
    }
    dividedynsegments();
}

variable_types: offset long

variable_types: count int

variable_types: entsize int

variable_types: struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; }

variable_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; }

variable_types:
ptr
void *

variable_types: size long

variable_types: i int

return_type: void


decompiled_code:
__int16 __fastcall rev2(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static inline unsigned short rev2(unsigned short in)
{
    return ((in & 0x00FF) << 8) | ((in & 0xFF00) >> 8);
}

variable_types:
in
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall rev4(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return _byteswap_ulong(a1);
}

original_code:
static inline unsigned int rev4(unsigned int in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}

variable_types:
in
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall rev8(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

original_code:
static inline unsigned long long rev8(unsigned long long in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}

variable_types:
in
unsigned long long

return_type: unsigned long long


decompiled_code:
void __fastcall revinplc2(_WORD *a1)
{
*a1 = __ROL2__(*a1, 8);
}

canonical_decompiled_code:
void __fastcall func3(_WORD *a1)
{
*a1 = __ROL2__(*a1, 8);
}

original_code:
static inline void revinplc2(void *in)
{
    unsigned char tmp;
    tmp = ((unsigned char*)in)[0];
    ((unsigned char*)in)[0] = ((unsigned char*)in)[1];
    ((unsigned char*)in)[1] = tmp;
}

canonical_original_code:
static inline void revinplc2(void *in)
{
    unsigned char tmp;
    tmp = ((unsigned char *)in)[0];
    ((unsigned char *)in)[0] = ((unsigned char *)in)[1];
    ((unsigned char *)in)[1] = tmp;
}

variable_types:
in
void *

variable_types:
tmp
unsigned char


decompiled_code:
__int64 __fastcall revinplc4(unsigned int *a1)
{
__int64 result; // rax

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}

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

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}

original_code:
static inline void revinplc4(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned int*)in) : "0"(*(unsigned int*)in));
}

canonical_original_code:
static inline void revinplc4(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned int *)in) : "0"(*(unsigned int *)in));
}


decompiled_code:
unsigned __int64 __fastcall revinplc8(unsigned __int64 *a1)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a1 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned __int64 *a1)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a1 = result;
return result;
}

original_code:
static inline void revinplc8(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned long*)in) : "0"(*(unsigned long*)in));
}

canonical_original_code:
static inline void revinplc8(void *in)
{
    __asm__("bswap %0" : "=r"(*(unsigned long *)in) : "0"(*(unsigned long *)in));
}


canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return _byteswap_ulong(a1);
}

canonical_original_code:
static inline unsigned int rev4(unsigned int in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int64 a1)
{
return _byteswap_uint64(a1);
}

canonical_original_code:
static inline unsigned long long rev8(unsigned long long in)
{
    __asm__("bswap %0" : "=r"(in) : "0"(in));
    return in;
}


canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
__int64 result; // rax

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 *a1)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a1 = result;
return result;
}


canonical_original_code:
static inline unsigned short rev2(unsigned short in)
{
    return ((in & 0x00FF) << 8) | ((in & 0xFF00) >> 8);
}


canonical_decompiled_code:
void __fastcall func2(_WORD *a1)
{
*a1 = __ROL2__(*a1, 8);
}


canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
__int64 result; // rax

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}


canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 *a1)
{
unsigned __int64 result; // rax

result = _byteswap_uint64(*a1);
*a1 = result;
return result;
}


freegamestate

decompiled_code:
__int64 __fastcall freegamestate(__int64 a1)
{
destroymovelist(a1 + 24);
return destroymovelist(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
destroymovelist(a1 + 24);
return destroymovelist(a1 + 40);
}

original_code:
static void freegamestate(gamestate *s)
{
    destroymovelist(&s->undo);
    destroymovelist(&s->redo);
}

canonical_original_code:
static void freegamestate(struct gamestate *s)
{
    destroymovelist(&s->undo);
    destroymovelist(&s->redo);
}

variable_types: struct gamestate { struct gamesetup { short ysize; short xsize; short blockcount; int beststepcount; int beststepknown; struct actlist { int allocated; int count; struct action { int id; } *list; } answer; int level; char *seriesname; char name[64]; unsigned int map[-1]; unsigned int goal[-1]; unsigned char equivs[256]; char colors[256]; } *game; int level; short ycurrpos; short xcurrpos; short currblock; int movecount; int stepcount; struct actlist undo; struct actlist redo; unsigned int map[-1]; } *

user_defined_types: struct gamestate { struct gamesetup *game; int level; short ycurrpos; short xcurrpos; short currblock; int movecount; int stepcount; struct actlist undo; struct actlist redo; unsigned int map[-1]; }

user_defined_types: struct gamesetup { short ysize; short xsize; short blockcount; int beststepcount; int beststepknown; struct actlist answer; int level; char *seriesname; char name[64]; unsigned int map[-1]; unsigned int goal[-1]; unsigned char equivs[256]; char colors[256]; }

user_defined_types: struct actlist { int allocated; int count; struct action *list; }


selectgame

decompiled_code:
void __fastcall selectgame(__int64 a1, int a2)
{
state = a1;
dword_B28 = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
state = a1;
dword_B28 = a2;
}

original_code:
void selectgame(gamesetup *game, int level)
{
    state.game = game;
    state.level = level;
}

canonical_original_code:
void selectgame(struct gamesetup *game, int level)
{
    state.game = game;
    state.level = level;
}

variable_types: struct gamesetup { short ysize; short xsize; short blockcount; int beststepcount; int beststepknown; struct actlist { int allocated; int count; struct action { int id; } *list; } answer; int level; char *seriesname; char name[64]; unsigned int map[-1]; unsigned int goal[-1]; unsigned char equivs[256]; char colors[256]; } *

variable_types: level int


undomoves

decompiled_code:
__int64 __fastcall undomoves(int a1)
{
__int64 result; // rax

result = (unsigned int)dword_B3C;
if ( dword_B3C )
{
do
{
if ( !a1 )
break;
--a1;
}
while ( (unsigned int)undomove() );
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax

result = (unsigned int)dword_B3C;
if ( dword_B3C )
{
do
{
if ( !a1 )
break;
--a1;
}
while ( (unsigned int)func6() );
result = 1LL;
}
return result;
}

original_code:
int undomoves(int n)
{
    if (!state.undo.count)
 return 0;
    while (n-- && undomove()) ;
    return 1;
}

variable_types: n int

return_type: int


redomove

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

result = (unsigned int)dword_B4C;
if ( dword_B4C )
{
--dword_B4C;
domove(*(_DWORD *)(qword_B50 + 4LL * ((int)result - 1)));
result = 1LL;
}
return result;
}

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

result = (unsigned int)dword_B4C;
if ( dword_B4C )
{
--dword_B4C;
func0(*(_DWORD *)(qword_B50 + 4LL * ((int)result - 1)));
result = 1LL;
}
return result;
}

original_code:
int redomove(void)
{
    if (!state.redo.count)
 return 0;
    domove(state.redo.list[--state.redo.count]);
    return 1;
}

canonical_original_code:
int redomove()
{
    if (!state.redo.count)
 return 0;
    domove(state.redo.list[--state.redo.count]);
    return 1;
}


redomoves

decompiled_code:
__int64 __fastcall redomoves(int a1)
{
__int64 result; // rax

result = (unsigned int)dword_B4C;
if ( dword_B4C )
{
do
{
if ( !a1 )
break;
--a1;
}
while ( (unsigned int)redomove() );
result = 1LL;
}
return result;
}

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

result = (unsigned int)dword_B4C;
if ( dword_B4C )
{
do
{
if ( !a1 )
break;
--a1;
}
while ( (unsigned int)func8() );
result = 1LL;
}
return result;
}

original_code:
int redomoves(int n)
{
    if (!state.redo.count)
 return 0;
    while (n-- && redomove()) ;
    return 1;
}


setmacro

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

result = (unsigned int)recording;
if ( recording )
{
recording = 0;
}
else
{
macro = (__int64)&macros + 16 * word_B2C;
result = initmovelist(macro);
recording = 1;
}
return result;
}

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

result = (unsigned int)recording;
if ( recording )
{
recording = 0;
}
else
{
macro = (__int64)&macros + 16 * word_B2C;
result = initmovelist(macro);
recording = 1;
}
return result;
}

original_code:
void setmacro(void)
{
    if (recording) {
 recording = 0;
 return;
    }
    macro = &macros[state.player];
    initmovelist(macro);
    recording = 1;
}

canonical_original_code:
void setmacro()
{
    if (recording) {
 recording = 0;
 return;
    }
    macro = &macros[state.player];
    initmovelist(macro);
    recording = 1;
}


startmacro

decompiled_code:
__int64 startmacro()
{
unsigned int v0; // er8

v0 = dword_F84[4 * word_B2C];
if ( v0 )
{
if ( recording )
recording = 0;
v0 = 1;
macroplay = 0;
macro = (__int64)&macros + 16 * word_B2C;
}
return v0;
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v0; // er8

v0 = dword_F84[4 * word_B2C];
if ( v0 )
{
if ( recording )
recording = 0;
v0 = 1;
macroplay = 0;
macro = (__int64)&macros + 16 * word_B2C;
}
return v0;
}

original_code:
int startmacro(void)
{
    if (!macros[state.player].count)
 return 0;
    if (recording)
 recording = 0;
    macro = &macros[state.player];
    macroplay = 0;
    return 1;
}

canonical_original_code:
int startmacro()
{
    if (!macros[state.player].count)
 return 0;
    if (recording)
 recording = 0;
    macro = &macros[state.player];
    macroplay = 0;
    return 1;
}


macromove

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

result = 0LL;
if ( macroplay >= 0 )
{
if ( (unsigned int)newmove(
(unsigned int)((__int16)(4 * *(_WORD *)(*(_QWORD *)(macro + 8) + 4LL * macroplay)) >> 2),
a2)
&& (v3 = macroplay + 1, macroplay = v3, v3 < *(_DWORD *)(macro + 4)) )
{
result = v3 >= 0;
}
else
{
macroplay = -1;
result = 0LL;
}
}
return result;
}

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

result = 0LL;
if ( macroplay >= 0 )
{
if ( (unsigned int)func10(
(unsigned int)((__int16)(4 * *(_WORD *)(*(_QWORD *)(macro + 8) + 4LL * macroplay)) >> 2),
a2)
&& (v3 = macroplay + 1, macroplay = v3, v3 < *(_DWORD *)(macro + 4)) )
{
result = v3 >= 0;
}
else
{
macroplay = -1;
result = 0LL;
}
}
return result;
}

original_code:
int macromove(void)
{
    if (macroplay >= 0)
 if (!newmove(macro->list[macroplay].yx) || ++macroplay >= macro->count)
     macroplay = -1;
    return macroplay >= 0;
}

canonical_original_code:
int macromove()
{
    if (macroplay >= 0)
 if (!newmove(macro->list[macroplay].yx) || ++macroplay >= macro->count)
     macroplay = -1;
    return macroplay >= 0;
}


isplaying

decompiled_code:
_BOOL8 isplaying()
{
return macroplay >= 0;
}

canonical_decompiled_code:
_BOOL8 func15()
{
return macroplay >= 0;
}

original_code:
int isplaying(void)
{
    return macroplay >= 0;
}

canonical_original_code:
int isplaying()
{
    return macroplay >= 0;
}


savestate

decompiled_code:
void *savestate()
{
__int64 *v0; // rbx
void *result; // rax

v0 = (__int64 *)malloc(0x440uLL);
if ( !v0 )
die("out of memory");
copygamestate_constprop_0(v0 + 1);
result = stack;
stack = v0;
*v0 = (__int64)result;
return result;
}

canonical_decompiled_code:
void *func16()
{
__int64 *v0; // rbx
void *result; // rax

v0 = (__int64 *)malloc(0x440uLL);
if ( !v0 )
die("out of memory");
func3(v0 + 1);
result = stack;
stack = v0;
*v0 = (__int64)result;
return result;
}

original_code:
void savestate(void)
{
    gamestack *save;
    if (!(save = malloc(sizeof *save)))
 (die("out of memory"));
    copygamestate(&save->state, &state);
    save->next = stack;
    stack = save;
}

canonical_original_code:
void savestate()
{
    struct gamestack *save;
    if (!(save = malloc(sizeof *save)))
 (die("out of memory"));
    copygamestate(&save->state, &state);
    save->next = stack;
    stack = save;
}

variable_types: struct gamestack { struct gamestack *next; struct gamestate { struct gamesetup { short ysize; short xsize; short blockcount; int beststepcount; int beststepknown; struct actlist { int allocated; int count; struct action { int id; } *list; } answer; int level; char *seriesname; char name[64]; unsigned int map[-1]; unsigned int goal[-1]; unsigned char equivs[256]; char colors[256]; } *game; int level; short ycurrpos; short xcurrpos; short currblock; int movecount; int stepcount; struct actlist undo; struct actlist redo; unsigned int map[-1]; } state; } *

user_defined_types: struct gamestack { struct gamestack *next; struct gamestate state; }


restorestate

decompiled_code:
__int64 restorestate()
{
void *v0; // rbx

if ( !stack )
return 0LL;
freegamestate((__int64)&state);
v0 = *(void **)stack;
qmemcpy(&state, (char *)stack + 8, 0x438uLL);
free(stack);
stack = v0;
return 1LL;
}

canonical_decompiled_code:
__int64 func17()
{
void *v0; // rbx

if ( !stack )
return 0LL;
func1((__int64)&state);
v0 = *(void **)stack;
qmemcpy(&state, (char *)stack + 8, 0x438uLL);
free(stack);
stack = v0;
return 1LL;
}

original_code:
int restorestate(void)
{
    gamestack *next;
    if (!stack)
 return 0;
    freegamestate(&state);
    state = stack->state;
    next = stack->next;
    free(stack);
    stack = next;
    return 1;
}

canonical_original_code:
int restorestate()
{
    struct gamestack *next;
    if (!stack)
 return 0;
    freegamestate(&state);
    state = stack->state;
    next = stack->next;
    free(stack);
    stack = next;
    return 1;
}


freesavedstates

decompiled_code:
void freesavedstates()
{
void *i; // rbx

for ( i = stack; i; stack = i )
{
freegamestate((__int64)i + 8);
i = *(void **)stack;
free(stack);
}
}

canonical_decompiled_code:
void func18()
{
void *i; // rbx

for ( i = stack; i; stack = i )
{
func1((__int64)i + 8);
i = *(void **)stack;
free(stack);
}
}

original_code:
void freesavedstates(void)
{
    gamestack *next;
    while (stack) {
 freegamestate(&stack->state);
 next = stack->next;
 free(stack);
 stack = next;
    }
}

canonical_original_code:
void freesavedstates()
{
    struct gamestack *next;
    while (stack) {
 freegamestate(&stack->state);
 next = stack->next;
 free(stack);
 stack = next;
    }
}


replaceanswers

decompiled_code:
__int64 __fastcall replaceanswers(int a1)
{
_DWORD *v2; // rdi
__int64 result; // rax
int v4; // edx
__int64 v5; // rbx
unsigned __int64 v6; // r12
__int64 v7; // rsi
int v8; // er12
int v9; // eax
int v10; // edx
__int64 v11; // rbx
unsigned __int64 v12; // r13
__int64 v13; // rsi
__int64 v14; // rax

v2 = (_DWORD *)state;
result = *(unsigned int *)(state + 12);
if ( !a1 )
{
if ( (_DWORD)result )
{
if ( *(int *)((char *)&qword_B2E + 2) >= (int)result )
{
v8 = 0;
if ( *(_DWORD *)((char *)&qword_B2E + 2) != (_DWORD)result
|| *(int *)((char *)&qword_B2E + 6) >= *(_DWORD *)(state + 20) )
{
LABEL_10:
v9 = v2[4];
if ( !v9
|| v9 > *(int *)((char *)&qword_B2E + 6)
|| v9 == *(_DWORD *)((char *)&qword_B2E + 6) && *(int *)((char *)&qword_B2E + 2) < v2[6] )
{
initmovelist(v2 + 12);
v10 = dword_B3C - 1;
if ( dword_B3C )
{
v11 = 4LL * v10;
v12 = 4 * (dword_B3C - (unsigned __int64)(unsigned int)v10) - 8;
do
{
v13 = *(unsigned int *)(qword_B40 + v11);
v11 -= 4LL;
addtomovelist(state + 48, v13);
}
while ( v12 != v11 );
}
v14 = state;
*(_DWORD *)(state + 16) = *(_DWORD *)((char *)&qword_B2E + 6);
if ( !a1 )
*(_DWORD *)(v14 + 24) = *(_DWORD *)((char *)&qword_B2E + 2);
++v8;
}
return v8 > 0;
}
}
}
LABEL_4:
initmovelist(state + 32);
v4 = dword_B3C - 1;
if ( dword_B3C )
{
v5 = 4LL * v4;
v6 = 4 * (dword_B3C - (unsigned __int64)(unsigned int)v4) - 8;
do
{
v7 = *(unsigned int *)(qword_B40 + v5);
v5 -= 4LL;
addtomovelist(state + 32, v7);
}
while ( v6 != v5 );
}
v2 = (_DWORD *)state;
if ( !a1 )
*(_DWORD *)(state + 12) = *(_DWORD *)((char *)&qword_B2E + 2);
v8 = 1;
v2[5] = *(_DWORD *)((char *)&qword_B2E + 6);
goto LABEL_10;
}
if ( (_DWORD)result )
return 0LL;
if ( !*(_DWORD *)(state + 16) )
goto LABEL_4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
_DWORD *v2; // rdi
__int64 result; // rax
int v4; // edx
__int64 v5; // rbx
unsigned __int64 v6; // r12
__int64 v7; // rsi
int v8; // er12
int v9; // eax
int v10; // edx
__int64 v11; // rbx
unsigned __int64 v12; // r13
__int64 v13; // rsi
__int64 v14; // rax

v2 = (_DWORD *)state;
result = *(unsigned int *)(state + 12);
if ( !a1 )
{
if ( (_DWORD)result )
{
if ( *(int *)((char *)&qword_B2E + 2) >= (int)result )
{
v8 = 0;
if ( *(_DWORD *)((char *)&qword_B2E + 2) != (_DWORD)result
|| *(int *)((char *)&qword_B2E + 6) >= *(_DWORD *)(state + 20) )
{
LABEL_10:
v9 = v2[4];
if ( !v9
|| v9 > *(int *)((char *)&qword_B2E + 6)
|| v9 == *(_DWORD *)((char *)&qword_B2E + 6) && *(int *)((char *)&qword_B2E + 2) < v2[6] )
{
initmovelist(v2 + 12);
v10 = dword_B3C - 1;
if ( dword_B3C )
{
v11 = 4LL * v10;
v12 = 4 * (dword_B3C - (unsigned __int64)(unsigned int)v10) - 8;
do
{
v13 = *(unsigned int *)(qword_B40 + v11);
v11 -= 4LL;
addtomovelist(state + 48, v13);
}
while ( v12 != v11 );
}
v14 = state;
*(_DWORD *)(state + 16) = *(_DWORD *)((char *)&qword_B2E + 6);
if ( !a1 )
*(_DWORD *)(v14 + 24) = *(_DWORD *)((char *)&qword_B2E + 2);
++v8;
}
return v8 > 0;
}
}
}
LABEL_4:
initmovelist(state + 32);
v4 = dword_B3C - 1;
if ( dword_B3C )
{
v5 = 4LL * v4;
v6 = 4 * (dword_B3C - (unsigned __int64)(unsigned int)v4) - 8;
do
{
v7 = *(unsigned int *)(qword_B40 + v5);
v5 -= 4LL;
addtomovelist(state + 32, v7);
}
while ( v6 != v5 );
}
v2 = (_DWORD *)state;
if ( !a1 )
*(_DWORD *)(state + 12) = *(_DWORD *)((char *)&qword_B2E + 2);
v8 = 1;
v2[5] = *(_DWORD *)((char *)&qword_B2E + 6);
goto LABEL_10;
}
if ( (_DWORD)result )
return 0LL;
if ( !*(_DWORD *)(state + 16) )
goto LABEL_4;
return result;
}

original_code:
int replaceanswers(int saveinc)
{
    int i, n;
    if (saveinc && (state.game->movebestcount || state.game->pushbestcount))
 return 0;
    n = 0;
    if (!state.game->movebestcount
  || state.movecount < state.game->movebestcount
  || (state.movecount == state.game->movebestcount
   && state.pushcount < state.game->movebestpushcount)) {
 initmovelist(&state.game->moveanswer);
 i = state.undo.count;
 while (i--)
     addtomovelist(&state.game->moveanswer, state.undo.list[i]);
 if (!saveinc)
     state.game->movebestcount = state.movecount;
 state.game->movebestpushcount = state.pushcount;
 ++n;
    }
    if (!state.game->pushbestcount
  || state.pushcount < state.game->pushbestcount
  || (state.pushcount == state.game->pushbestcount
   && state.movecount < state.game->pushbestmovecount)) {
 initmovelist(&state.game->pushanswer);
 i = state.undo.count;
 while (i--)
     addtomovelist(&state.game->pushanswer, state.undo.list[i]);
 state.game->pushbestcount = state.pushcount;
 if (!saveinc)
     state.game->pushbestmovecount = state.movecount;
 ++n;
    }
    return n > 0;
}

canonical_original_code:
int replaceanswers(int saveinc)
{
    int i; int n;
    if (saveinc && (state.game->movebestcount || state.game->pushbestcount))
 return 0;
    n = 0;
    if (!state.game->movebestcount
  || state.movecount < state.game->movebestcount
  || (state.movecount == state.game->movebestcount
   && state.pushcount < state.game->movebestpushcount)) {
 initmovelist(&state.game->moveanswer);
 i = state.undo.count;
 while (i--)
     addtomovelist(&state.game->moveanswer, state.undo.list[i]);
 if (!saveinc)
     state.game->movebestcount = state.movecount;
 state.game->movebestpushcount = state.pushcount;
 ++n;
    }
    if (!state.game->pushbestcount
  || state.pushcount < state.game->pushbestcount
  || (state.pushcount == state.game->pushbestcount
   && state.movecount < state.game->pushbestmovecount)) {
 initmovelist(&state.game->pushanswer);
 i = state.undo.count;
 while (i--)
     addtomovelist(&state.game->pushanswer, state.undo.list[i]);
 state.game->pushbestcount = state.pushcount;
 if (!saveinc)
     state.game->pushbestmovecount = state.movecount;
 ++n;
    }
    return n > 0;
}

variable_types: saveinc int


getpathbufferlength

decompiled_code:
__int64 getpathbufferlength()
{
return 4097LL;
}

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

original_code:
int getpathbufferlength(void)
{
    return 4096 + 1;
}

canonical_original_code:
int getpathbufferlength()
{
    return 4096 + 1;
}


getpathbuffer

decompiled_code:
void *getpathbuffer()
{
void *v0; // r12

v0 = malloc(0x1001uLL);
if ( !v0 )
die("out of memory");
return v0;
}

canonical_decompiled_code:
void *func1()
{
void *v0; // r12

v0 = malloc(0x1001uLL);
if ( !v0 )
die("out of memory");
return v0;
}

original_code:
char *getpathbuffer(void)
{
    char *buf;
    if (!(buf = malloc(4096 + 1)))
 (die("out of memory"));
    return buf;
}

canonical_original_code:
char *getpathbuffer()
{
    char *buf;
    if (!(buf = malloc(4096 + 1)))
 (die("out of memory"));
    return buf;
}

variable_types:
buf
char *

return_type: char *


copypath

decompiled_code:
__int64 __fastcall copypath(_QWORD *a1, const char *a2)
{
int v2; // eax
unsigned __int64 v4; // rax

v2 = strlen(a2);
if ( v2 > 4096 )
return 0LL;
v4 = v2 + 1;
if ( v4 >= 8 )
{
*a1 = *(_QWORD *)a2;
*(_QWORD *)((char *)a1 + v4 - 8) = *(_QWORD *)&a2[v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a2 - ((const char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8 * (((unsigned __int64)a1 + v4 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL)) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
*(_DWORD *)((char *)a1 + v4 - 4) = *(_DWORD *)&a2[v4 - 4];
}
else if ( v4 )
{
*(_BYTE *)a1 = *a2;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)a1 + v4 - 2) = *(_WORD *)&a2[v4 - 2];
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, const char *a2)
{
int v2; // eax
unsigned __int64 v4; // rax

v2 = strlen(a2);
if ( v2 > 4096 )
return 0LL;
v4 = v2 + 1;
if ( v4 >= 8 )
{
*a1 = *(_QWORD *)a2;
*(_QWORD *)((char *)a1 + v4 - 8) = *(_QWORD *)&a2[v4 - 8];
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a2 - ((const char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8 * (((unsigned __int64)a1 + v4 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL)) >> 3));
}
else if ( (v4 & 4) != 0 )
{
*(_DWORD *)a1 = *(_DWORD *)a2;
*(_DWORD *)((char *)a1 + v4 - 4) = *(_DWORD *)&a2[v4 - 4];
}
else if ( v4 )
{
*(_BYTE *)a1 = *a2;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)a1 + v4 - 2) = *(_WORD *)&a2[v4 - 2];
}
return 1LL;
}

original_code:
int copypath(char *to, char const *from)
{
    int n;
    n = strlen(from);
    if (n > 4096)
 return 0;
    memcpy(to, from, n + 1);
    return 1;
}

canonical_original_code:
int copypath(char *to, char *from)
{
    int n;
    n = strlen(from);
    if (n > 4096)
 return 0;
    memcpy(to, from, n + 1);
    return 1;
}

variable_types:
to
char *

variable_types:
from
char *


isfilename

decompiled_code:
_BOOL8 __fastcall isfilename(char *file)
{
char *v1; // r8
_BOOL8 result; // rax
int v3; // er8
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = strchr(file, 47);
result = 1LL;
if ( !v1 )
{
v3 = stat(file, &v4);
result = 0LL;
if ( !v3 )
result = (v4.st_mode & 0xF000) != 0x4000;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *file)
{
char *v1; // r8
_BOOL8 result; // rax
int v3; // er8
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = strchr(file, 47);
result = 1LL;
if ( !v1 )
{
v3 = stat(file, &v4);
result = 0LL;
if ( !v3 )
result = (v4.st_mode & 0xF000) != 0x4000;
}
return result;
}

original_code:
int isfilename(char const *name)
{
    struct stat st;
    if (strchr(name, '/'))
 return 1;
    if (!stat(name, &st) && !((((st.st_mode)) & 0170000) == (0040000)))
 return 1;
    return 0;
}

canonical_original_code:
int isfilename(char *name)
{
    struct stat st;
    if (strchr(name, '/'))
 return 1;
    if (!stat(name, &st) && !((((st.st_mode)) & 0170000) == (0040000)))
 return 1;
    return 0;
}

variable_types:
name
char *

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

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


finddir

decompiled_code:
_BOOL8 __fastcall finddir(char *path)
{
_BOOL8 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(path, &v2) )
result = mkdir(path, 0x1EDu) == 0;
else
result = (v2.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *path)
{
_BOOL8 result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(path, &v2) )
result = mkdir(path, 0x1EDu) == 0;
else
result = (v2.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
int finddir(char const *dir)
{
    struct stat st;
    return stat(dir, &st) ? mkdir(dir, 0755) == 0 : ((((st.st_mode)) & 0170000) == (0040000));
}

canonical_original_code:
int finddir(char *dir)
{
    struct stat st;
    return stat(dir, &st) ? mkdir(dir, 0755) == 0 : ((((st.st_mode)) & 0170000) == (0040000));
}

variable_types:
dir
char *

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


pullflooring

decompiled_code:
__int64 __fastcall pullflooring(__int64 a1, __int16 a2)
{
_BYTE *v2; // rdx
__int64 result; // rax

while ( 1 )
{
v2 = (_BYTE *)(a1 + a2);
result = (unsigned __int8)*v2;
if ( (result & 8) != 0 )
return result;
*v2 = result & 0xDF;
if ( a2 <= 31 )
goto LABEL_3;
if ( (*(_BYTE *)(a1 + a2 - 32) & 0x28) == 32 )
pullflooring(a1, (unsigned __int16)(a2 - 32));
if ( a2 <= 992 )
{
LABEL_3:
if ( (*(_BYTE *)(a1 + a2 + 32) & 0x28) == 32 )
pullflooring(a1, (unsigned int)(__int16)(a2 + 32));
}
if ( a2 % 32 > 0 )
{
result = *(_BYTE *)(a1 + a2 - 1) & 0x28;
if ( (_BYTE)result == 32 )
result = pullflooring(a1, (unsigned int)(__int16)(a2 - 1));
if ( a2 % 32 == 31 )
return result;
}
result = *(_BYTE *)(a1 + a2 + 1) & 0x28;
if ( (_BYTE)result != 32 )
return result;
++a2;
}
}

original_code:
static void pullflooring(cell *map, yx pos)
{
    if (map[pos] & 0x08)
 return;
    map[pos] &= ~0x20;
    if (pos >= 32 && (map[pos - 32] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos - 32);
    if (pos <= 32 * 32 - 32 &&
   (map[pos + 32] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos + 32);
    if (pos % 32 > 0 && (map[pos - 1] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos - 1);
    if (pos % 32 < 32 - 1 && (map[pos + 1] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos + 1);
}

canonical_original_code:
static void pullflooring(unsigned char *map, short pos)
{
    if (map[pos] & 0x08)
 return;
    map[pos] &= ~0x20;
    if (pos >= 32 && (map[pos - 32] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos - 32);
    if (pos <= 32 * 32 - 32 &&
   (map[pos + 32] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos + 32);
    if (pos % 32 > 0 && (map[pos - 1] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos - 1);
    if (pos % 32 < 32 - 1 && (map[pos + 1] & (0x08 | 0x20)) == 0x20)
 pullflooring(map, pos + 1);
}

variable_types:
map
unsigned char *

variable_types: pos short


improvemap

original_code:
static int improvemap(gamesetup *game)
{
    cell *map;
    yx initpos;
    int y, x;
    initpos = 0;
    map = game->map;
    for (y = 0 ; y < game->ysize ; ++y, map += 32) {
 for (x = 0 ; x < game->xsize ; ++x) {
     if (map[x] & 0x08)
  continue;
     map[x] |= 0x20;
     if (map[x] & 0x02) {
  if (initpos)
      return fileerr("multiple players in map");
  initpos = &map[x] - game->map;
     }
 }
    }
    if (!initpos)
 return fileerr("no player in map");
    pullflooring(game->map, 0);
    map = game->map;
    for (y = 1, map += 32 ; y < game->ysize - 1 ; ++y, map += 32) {
 for (x = 1 ; x < game->xsize - 1 ; ++x) {
     if (!(map[x] & 0x08))
  continue;
     if (map[x + 32] & 0x08)
  map[x + 32] |= 0x10;
     if (map[x - 32] & 0x08)
  map[x - 32] |= 0x20;
     if (map[x + 1] & 0x08)
  map[x + 1] |= 0x40;
     if (map[x - 1] & 0x08)
  map[x - 1] |= 0x80;
 }
    }
    map = game->map;
    memset(map, 0x08, game->xsize);
    for (y = 1, map += 32 ; y < game->ysize - 1 ; ++y, map += 32)
 map[0] = map[game->xsize - 1] = 0x08;
    memset(map, 0x08, game->xsize);
    return 1;
}

canonical_original_code:
static int improvemap(struct gamesetup *game)
{
    unsigned char *map;
    short initpos;
    int y; int x;
    initpos = 0;
    map = game->map;
    for (y = 0 ; y < game->ysize ; ++y, map += 32) {
 for (x = 0 ; x < game->xsize ; ++x) {
     if (map[x] & 0x08)
  continue;
     map[x] |= 0x20;
     if (map[x] & 0x02) {
  if (initpos)
      return fileerr("multiple players in map");
  initpos = &map[x] - game->map;
     }
 }
    }
    if (!initpos)
 return fileerr("no player in map");
    pullflooring(game->map, 0);
    map = game->map;
    for (y = 1, map += 32 ; y < game->ysize - 1 ; ++y, map += 32) {
 for (x = 1 ; x < game->xsize - 1 ; ++x) {
     if (!(map[x] & 0x08))
  continue;
     if (map[x + 32] & 0x08)
  map[x + 32] |= 0x10;
     if (map[x - 32] & 0x08)
  map[x - 32] |= 0x20;
     if (map[x + 1] & 0x08)
  map[x + 1] |= 0x40;
     if (map[x - 1] & 0x08)
  map[x - 1] |= 0x80;
 }
    }
    map = game->map;
    memset(map, 0x08, game->xsize);
    for (y = 1, map += 32 ; y < game->ysize - 1 ; ++y, map += 32)
 map[0] = map[game->xsize - 1] = 0x08;
    memset(map, 0x08, game->xsize);
    return 1;
}

variable_types: struct gamesetup { short ysize; short xsize; short boxcount; short goalcount; short storecount; short start; int movebestcount; int pushbestcount; int movebestpushcount; int pushbestmovecount; struct dyxlist { int allocated; int count; struct dyx { int yx; } *list; } moveanswer; struct dyxlist pushanswer; int level; char *seriesname; char name[64]; unsigned char map[-1]; } *

variable_types: initpos short

variable_types: y int

variable_types: x int

user_defined_types: struct gamesetup { short ysize; short xsize; short boxcount; short goalcount; short storecount; short start; int movebestcount; int pushbestcount; int movebestpushcount; int pushbestmovecount; struct dyxlist moveanswer; struct dyxlist pushanswer; int level; char *seriesname; char name[64]; unsigned char map[-1]; }

user_defined_types: struct dyxlist { int allocated; int count; struct dyx *list; }


drawgoalscreen

decompiled_code:
__int64 drawgoalscreen()
{
displaygoal();
return input();
}

canonical_decompiled_code:
__int64 func3()
{
displaygoal();
return input();
}

original_code:
static void drawgoalscreen(void)
{
    displaygoal();
    input();
}

canonical_original_code:
static void drawgoalscreen()
{
    displaygoal();
    input();
}


readlevel

decompiled_code:
__int64 readlevel()
{
__int64 v0; // rsi
__int64 v1; // rax
int v2; // ebx
char v3; // di
__int64 v4; // rcx
int v5; // edx
int v7; // eax
__int64 v8; // rdx
int v9; // ecx

v0 = serieslist;
v1 = currentseries;
v2 = currentgame;
if ( currentgame >= 0 )
goto LABEL_10;
v3 = 0;
v4 = serieslist + 120LL * currentseries;
do
{
if ( !(_DWORD)v1 )
{
if ( v3 )
currentseries = 0;
return 0LL;
}
v5 = *(_DWORD *)(v4 - 116);
LODWORD(v1) = v1 - 1;
v4 -= 120LL;
v3 = 1;
v2 += v5;
}
while ( v2 < 0 );
currentseries = v1;
v1 = (int)v1;
while ( v2 >= v5 )
{
v7 = readlevelinseries(v0 + 120 * v1, (unsigned int)v2);
v0 = serieslist;
if ( v7 )
{
v1 = currentseries;
LABEL_10:
v5 = *(_DWORD *)(v0 + 120 * v1 + 4);
}
else
{
v8 = 120LL * currentseries;
v9 = *(_DWORD *)(serieslist + v8 + 4);
if ( v2 < v9 )
return 0LL;
LODWORD(v1) = currentseries + 1;
if ( currentseries + 1 >= seriescount )
return 0LL;
++currentseries;
v5 = *(_DWORD *)(serieslist + v8 + 124);
v2 -= v9;
v1 = (int)v1;
}
}
currentgame = v2;
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rsi
__int64 v1; // rax
int v2; // ebx
char v3; // di
__int64 v4; // rcx
int v5; // edx
int v7; // eax
__int64 v8; // rdx
int v9; // ecx

v0 = serieslist;
v1 = currentseries;
v2 = currentgame;
if ( currentgame >= 0 )
goto LABEL_10;
v3 = 0;
v4 = serieslist + 120LL * currentseries;
do
{
if ( !(_DWORD)v1 )
{
if ( v3 )
currentseries = 0;
return 0LL;
}
v5 = *(_DWORD *)(v4 - 116);
LODWORD(v1) = v1 - 1;
v4 -= 120LL;
v3 = 1;
v2 += v5;
}
while ( v2 < 0 );
currentseries = v1;
v1 = (int)v1;
while ( v2 >= v5 )
{
v7 = readlevelinseries(v0 + 120 * v1, (unsigned int)v2);
v0 = serieslist;
if ( v7 )
{
v1 = currentseries;
LABEL_10:
v5 = *(_DWORD *)(v0 + 120 * v1 + 4);
}
else
{
v8 = 120LL * currentseries;
v9 = *(_DWORD *)(serieslist + v8 + 4);
if ( v2 < v9 )
return 0LL;
LODWORD(v1) = currentseries + 1;
if ( currentseries + 1 >= seriescount )
return 0LL;
++currentseries;
v5 = *(_DWORD *)(serieslist + v8 + 124);
v2 -= v9;
v1 = (int)v1;
}
}
currentgame = v2;
return 1LL;
}

original_code:
int readlevel(void)
{
    int level = currentgame;
    while (level < 0) {
 if (!currentseries)
     return 0;
 --currentseries;
 level += serieslist[currentseries].count;
    }
    while (level >= serieslist[currentseries].count) {
 if (!readlevelinseries(serieslist + currentseries, level)) {
     if (level < serieslist[currentseries].count)
  return 0;
     if (currentseries + 1 >= seriescount)
  return 0;
     level -= serieslist[currentseries].count;
     ++currentseries;
 }
    }
    currentgame = level;
    return 1;
}

canonical_original_code:
int readlevel()
{
    int level = currentgame;
    while (level < 0) {
 if (!currentseries)
     return 0;
 --currentseries;
 level += serieslist[currentseries].count;
    }
    while (level >= serieslist[currentseries].count) {
 if (!readlevelinseries(serieslist + currentseries, level)) {
     if (level < serieslist[currentseries].count)
  return 0;
     if (currentseries + 1 >= seriescount)
  return 0;
     level -= serieslist[currentseries].count;
     ++currentseries;
 }
    }
    currentgame = level;
    return 1;
}


queueinputevent

decompiled_code:
__int64 __fastcall queueinputevent(int a1)
{
__int64 result; // rax

result = (unsigned int)eventqueuesize;
if ( (unsigned int)eventqueuesize <= 7 )
{
eventqueue[eventqueuesize] = a1;
eventqueuesize = result + 1;
}
return result;
}

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

result = (unsigned int)eventqueuesize;
if ( (unsigned int)eventqueuesize <= 7 )
{
eventqueue[eventqueuesize] = a1;
eventqueuesize = result + 1;
}
return result;
}

original_code:
static void queueinputevent(int control)
{
    if (eventqueuesize < sizeof eventqueue / sizeof *eventqueue)
 eventqueue[eventqueuesize++] = control;
}

variable_types: control int


unqueueinputevent

decompiled_code:
__int64 __fastcall unqueueinputevent(_DWORD *a1)
{
__int64 v2; // rdx

if ( !eventqueuesize )
return 0LL;
v2 = (unsigned int)--eventqueuesize;
*a1 = eventqueue[0];
memmove(eventqueue, &unk_864, 4 * v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
__int64 v2; // rdx

if ( !eventqueuesize )
return 0LL;
v2 = (unsigned int)--eventqueuesize;
*a1 = eventqueue[0];
memmove(eventqueue, &unk_864, 4 * v2);
return 1LL;
}

original_code:
static int unqueueinputevent(int *control)
{
    if (eventqueuesize == 0)
 return 0;
    *control = eventqueue[0];
    --eventqueuesize;
    memmove(eventqueue, eventqueue + 1, eventqueuesize * sizeof *eventqueue);
    return 1;
}

variable_types:
control
int *


showscoresheet

decompiled_code:
int showscoresheet()
{
const char *v0; // rdx
const char *v1; // r12
__int64 i; // rbx
int result; // eax
__int64 v4; // rsi
__int64 v5; // rsi

v0 = "Ones ";
v1 = "Three of a Kind ";
for ( i = 0LL; ; v1 = off_BE0[i] )
{
v4 = *((unsigned __int8 *)&controls + 4 * i + 26);
if ( (_BYTE)v4 )
printf("%c: %s", v4, v0);
else
printf(" %s", v0);
if ( *((__int16 *)&controls + 2 * i + 12) >= 0 && (*((_BYTE *)&controls + 4 * i + 27) & 3) != 0 )
printf("%4d . ", (unsigned int)*((__int16 *)&controls + 2 * i + 12));
else
printf(" . ");
v5 = *((unsigned __int8 *)&controls + 4 * i + 58);
if ( (_BYTE)v5 )
printf("%c: %s", v5, v1);
else
printf(" %s", v1);
if ( *((__int16 *)&controls + 2 * i + 28) >= 0 && (*((_BYTE *)&controls + 4 * i + 59) & 3) != 0 )
printf("%4d", (unsigned int)*((__int16 *)&controls + 2 * i + 28));
++i;
result = putchar(10);
if ( i == 8 )
break;
v0 = slotnames[i];
}
displayscore = 0;
return result;
}

canonical_decompiled_code:
int func2()
{
const char *v0; // rdx
const char *v1; // r12
__int64 i; // rbx
int result; // eax
__int64 v4; // rsi
__int64 v5; // rsi

v0 = "Ones ";
v1 = "Three of a Kind ";
for ( i = 0LL; ; v1 = off_BE0[i] )
{
v4 = *((unsigned __int8 *)&controls + 4 * i + 26);
if ( (_BYTE)v4 )
printf("%c: %s", v4, v0);
else
printf(" %s", v0);
if ( *((__int16 *)&controls + 2 * i + 12) >= 0 && (*((_BYTE *)&controls + 4 * i + 27) & 3) != 0 )
printf("%4d . ", (unsigned int)*((__int16 *)&controls + 2 * i + 12));
else
printf(" . ");
v5 = *((unsigned __int8 *)&controls + 4 * i + 58);
if ( (_BYTE)v5 )
printf("%c: %s", v5, v1);
else
printf(" %s", v1);
if ( *((__int16 *)&controls + 2 * i + 28) >= 0 && (*((_BYTE *)&controls + 4 * i + 59) & 3) != 0 )
printf("%4d", (unsigned int)*((__int16 *)&controls + 2 * i + 28));
++i;
result = putchar(10);
if ( i == 8 )
break;
v0 = slotnames[i];
}
displayscore = 0;
return result;
}

original_code:
static void showscoresheet(void)
{
    int i, m, n;
    m = 16 / 2;
    for (n = 0 ; n < m ; ++n) {
 i = ((((0) + 5)) + 1) + n;
 if (controls[i].key)
     printf("%c: %s", controls[i].key, slotnames[n]);
 else
     printf("   %s", slotnames[n]);
 if (controls[i].value >= 0 &&
   (((controls[i]).flags & 0x02) || ((controls[i]).flags & 0x01)))
     printf("%4d  .  ", controls[i].value);
 else
     printf("      .  ");
 i += m;
 if (controls[i].key)
     printf("%c: %s", controls[i].key, slotnames[m + n]);
 else
     printf("   %s", slotnames[m + n]);
 if (controls[i].value >= 0 &&
   (((controls[i]).flags & 0x02) || ((controls[i]).flags & 0x01)))
     printf("%4d", controls[i].value);
 putchar('\n');
    }
    displayscore = 0;
}

canonical_original_code:
static void showscoresheet()
{
    int i; int m; int n;
    m = 16 / 2;
    for (n = 0 ; n < m ; ++n) {
 i = ((((0) + 5)) + 1) + n;
 if (controls[i].key)
     printf("%c: %s", controls[i].key, slotnames[n]);
 else
     printf("   %s", slotnames[n]);
 if (controls[i].value >= 0 &&
   (((controls[i]).flags & 0x02) || ((controls[i]).flags & 0x01)))
     printf("%4d  .  ", controls[i].value);
 else
     printf("      .  ");
 i += m;
 if (controls[i].key)
     printf("%c: %s", controls[i].key, slotnames[m + n]);
 else
     printf("   %s", slotnames[m + n]);
 if (controls[i].value >= 0 &&
   (((controls[i]).flags & 0x02) || ((controls[i]).flags & 0x01)))
     printf("%4d", controls[i].value);
 putchar('\n');
    }
    displayscore = 0;
}

variable_types: i int

variable_types: m int

variable_types: n int


showdice

decompiled_code:
int showdice()
{
__int16 *v0; // rbx
int v1; // esi
int result; // eax

v0 = (__int16 *)&controls;
printf("(%c)", (unsigned int)(controls + 49));
do
{
v1 = v0[2];
v0 += 2;
printf(" (%c)", (unsigned int)(v1 + 49));
}
while ( v0 != (__int16 *)((char *)&controls + 16) );
result = putchar(10);
displaydice = 0;
return result;
}

canonical_decompiled_code:
int func3()
{
__int16 *v0; // rbx
int v1; // esi
int result; // eax

v0 = (__int16 *)&controls;
printf("(%c)", (unsigned int)(controls + 49));
do
{
v1 = v0[2];
v0 += 2;
printf(" (%c)", (unsigned int)(v1 + 49));
}
while ( v0 != (__int16 *)((char *)&controls + 16) );
result = putchar(10);
displaydice = 0;
return result;
}

original_code:
static void showdice(void)
{
    int i;
    printf("(%c)", '1' + controls[(0)].value);
    for (i = (0) + 1 ; i < ((0) + 5) ; ++i)
 printf("  (%c)", '1' + controls[i].value);
    printf("\n");
    displaydice = 0;
}

canonical_original_code:
static void showdice()
{
    int i;
    printf("(%c)", '1' + controls[(0)].value);
    for (i = (0) + 1 ; i < ((0) + 5) ; ++i)
 printf("  (%c)", '1' + controls[i].value);
    printf("\n");
    displaydice = 0;
}


showprompt

decompiled_code:
int showprompt()
{
int v0; // esi
__int64 v1; // rax
char v2; // cl
char v3; // dl
__int16 v4; // ax
unsigned __int64 v5; // rbx
int v6; // edi
int result; // eax

v0 = displaydice;
v1 = 0LL;
v2 = 0;
do
{
v3 = *((_BYTE *)&controls + v1 + 3);
if ( (v3 & 4) != 0 )
{
v2 = 1;
v0 = 1;
*((_BYTE *)&controls + v1 + 3) = v3 & 0xFB;
}
v1 += 4LL;
}
while ( v1 != 20 );
if ( v2 )
displaydice = v0;
if ( *((_WORD *)&controls + 10) == 2 )
{
if ( displaydice )
showdice();
if ( displayscore )
showscoresheet();
result = puts("Another game (RET) or Quit (q):");
}
else
{
if ( displayscore )
showscoresheet();
if ( displaydice )
showdice();
v4 = *((_WORD *)&controls + 10);
if ( v4 == 1 )
{
if ( (*((_BYTE *)&controls + 23) & 2) == 0 )
return puts("Confirm (RET):");
}
else if ( !v4 )
{
printf("Roll (abcde) or ");
}
v5 = (unsigned int)((_DWORD)&controls + 26);
printf("Score (");
do
{
while ( (*(_BYTE *)(v5 + 1) & 2) != 0 )
{
v5 += 4LL;
if ( (_UNKNOWN *)v5 == (_UNKNOWN *)((char *)&controls + 90) )
goto LABEL_19;
}
v6 = *(unsigned __int8 *)v5;
v5 += 4LL;
putchar(v6);
}
while ( (_UNKNOWN *)v5 != (_UNKNOWN *)((char *)&controls + 90) );
LABEL_19:
result = puts("):");
}
return result;
}

canonical_decompiled_code:
int func4()
{
int v0; // esi
__int64 v1; // rax
char v2; // cl
char v3; // dl
__int16 v4; // ax
unsigned __int64 v5; // rbx
int v6; // edi
int result; // eax

v0 = displaydice;
v1 = 0LL;
v2 = 0;
do
{
v3 = *((_BYTE *)&controls + v1 + 3);
if ( (v3 & 4) != 0 )
{
v2 = 1;
v0 = 1;
*((_BYTE *)&controls + v1 + 3) = v3 & 0xFB;
}
v1 += 4LL;
}
while ( v1 != 20 );
if ( v2 )
displaydice = v0;
if ( *((_WORD *)&controls + 10) == 2 )
{
if ( displaydice )
func3();
if ( displayscore )
func2();
result = puts("Another game (RET) or Quit (q):");
}
else
{
if ( displayscore )
func2();
if ( displaydice )
func3();
v4 = *((_WORD *)&controls + 10);
if ( v4 == 1 )
{
if ( (*((_BYTE *)&controls + 23) & 2) == 0 )
return puts("Confirm (RET):");
}
else if ( !v4 )
{
printf("Roll (abcde) or ");
}
v5 = (unsigned int)((_DWORD)&controls + 26);
printf("Score (");
do
{
while ( (*(_BYTE *)(v5 + 1) & 2) != 0 )
{
v5 += 4LL;
if ( (_UNKNOWN *)v5 == (_UNKNOWN *)((char *)&controls + 90) )
goto LABEL_19;
}
v6 = *(unsigned __int8 *)v5;
v5 += 4LL;
putchar(v6);
}
while ( (_UNKNOWN *)v5 != (_UNKNOWN *)((char *)&controls + 90) );
LABEL_19:
result = puts("):");
}
return result;
}

original_code:
static void showprompt(void)
{
    int i;
    for (i = (0) ; i < ((0) + 5) ; ++i) {
 if (((controls[i]).flags & 0x04)) {
     ((controls[i]).flags &= ~0x04);
     displaydice = 1;
 }
    }
    if (controls[(((0) + 5))].value == 2) {
 if (displaydice)
     showdice();
 if (displayscore)
     showscoresheet();
 printf("Another game (RET) or Quit (q):\n");
 return;
    }
    if (displayscore)
 showscoresheet();
    if (displaydice)
 showdice();
    if (controls[(((0) + 5))].value == 1 &&
   !((controls[(((0) + 5))]).flags & 0x02)) {
 printf("Confirm (RET):\n");
 return;
    }
    if (controls[(((0) + 5))].value == 0)
 printf("Roll (abcde) or ");
    printf("Score (");
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i)
 if (!((controls[i]).flags & 0x02))
     putchar(controls[i].key);
    printf("):\n");
}

canonical_original_code:
static void showprompt()
{
    int i;
    for (i = (0) ; i < ((0) + 5) ; ++i) {
 if (((controls[i]).flags & 0x04)) {
     ((controls[i]).flags &= ~0x04);
     displaydice = 1;
 }
    }
    if (controls[(((0) + 5))].value == 2) {
 if (displaydice)
     showdice();
 if (displayscore)
     showscoresheet();
 printf("Another game (RET) or Quit (q):\n");
 return;
    }
    if (displayscore)
 showscoresheet();
    if (displaydice)
 showdice();
    if (controls[(((0) + 5))].value == 1 &&
   !((controls[(((0) + 5))]).flags & 0x02)) {
 printf("Confirm (RET):\n");
 return;
    }
    if (controls[(((0) + 5))].value == 0)
 printf("Roll (abcde) or ");
    printf("Score (");
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i)
 if (!((controls[i]).flags & 0x02))
     putchar(controls[i].key);
    printf("):\n");
}


showhelp

decompiled_code:
int showhelp()
{
const char *v0; // rax
const char **v1; // rbp
int v2; // eax
__int64 v3; // rbx
const char *i; // [rsp+8h] [rbp-20h] BYREF

v0 = (const char *)rulesinfo;
if ( rulesinfo )
{
v1 = (const char **)(unsigned int)((_DWORD)&rulesinfo + 8);
do
{
for ( i = v0; *i; i += v3 )
{
v2 = textbreak(&i, 72LL);
v3 = v2;
printf("%.*s\n", v2, i);
}
v0 = *v1++;
}
while ( v0 );
}
return printf(
"\n%s",
"At any time you can type (q) to exit the program, (.) to\n"
"re-display the game state, (v) to see the version and license\n"
"information, or (?) to view this help text again.\n");
}

canonical_decompiled_code:
int func5()
{
const char *v0; // rax
const char **v1; // rbp
int v2; // eax
__int64 v3; // rbx
const char *i; // [rsp+8h] [rbp-20h] BYREF

v0 = (const char *)rulesinfo;
if ( rulesinfo )
{
v1 = (const char **)(unsigned int)((_DWORD)&rulesinfo + 8);
do
{
for ( i = v0; *i; i += v3 )
{
v2 = textbreak(&i, 72LL);
v3 = v2;
printf("%.*s\n", v2, i);
}
v0 = *v1++;
}
while ( v0 );
}
return printf(
"\n%s",
"At any time you can type (q) to exit the program, (.) to\n"
"re-display the game state, (v) to see the version and license\n"
"information, or (?) to view this help text again.\n");
}

original_code:
static void showhelp(void)
{
    char const *line;
    int i, n;
    for (i = 0 ; rulesinfo[i] ; ++i) {
 line = rulesinfo[i];
 while (*line) {
     n = textbreak(&line, 72);
     printf("%.*s\n", n, line);
     line += n;
 }
    }
    printf("\n%s",
    "At any time you can type (q) to exit the program, (.) to\n"
    "re-display the game state, (v) to see the version and license\n"
    "information, or (?) to view this help text again.\n");
}

canonical_original_code:
static void showhelp()
{
    char *line;
    int i; int n;
    for (i = 0 ; rulesinfo[i] ; ++i) {
 line = rulesinfo[i];
 while (*line) {
     n = textbreak(&line, 72);
     printf("%.*s\n", n, line);
     line += n;
 }
    }
    printf("\n%s",
    "At any time you can type (q) to exit the program, (.) to\n"
    "re-display the game state, (v) to see the version and license\n"
    "information, or (?) to view this help text again.\n");
}

variable_types:
line
char *


showversion

decompiled_code:
const char *showversion()
{
const char *result; // rax
const char **v1; // rbp
int v2; // eax
__int64 v3; // rbx
const char *i; // [rsp+0h] [rbp-20h] BYREF

result = (const char *)licenseinfo;
if ( licenseinfo )
{
v1 = (const char **)(unsigned int)((_DWORD)&licenseinfo + 8);
do
{
for ( i = result; *i; i += v3 )
{
v2 = textbreak(&i, 64LL);
v3 = v2;
printf("%.*s\n", v2, i);
}
result = *v1++;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
const char *func6()
{
const char *result; // rax
const char **v1; // rbp
int v2; // eax
__int64 v3; // rbx
const char *i; // [rsp+0h] [rbp-20h] BYREF

result = (const char *)licenseinfo;
if ( licenseinfo )
{
v1 = (const char **)(unsigned int)((_DWORD)&licenseinfo + 8);
do
{
for ( i = result; *i; i += v3 )
{
v2 = textbreak(&i, 64LL);
v3 = v2;
printf("%.*s\n", v2, i);
}
result = *v1++;
}
while ( result );
}
return result;
}

original_code:
static void showversion(void)
{
    char const *line;
    int i, n;
    for (i = 0 ; licenseinfo[i] ; ++i) {
 line = licenseinfo[i];
 while (*line) {
     n = textbreak(&line, 64);
     printf("%.*s\n", n, line);
     line += n;
 }
    }
}

canonical_original_code:
static void showversion()
{
    char *line;
    int i; int n;
    for (i = 0 ; licenseinfo[i] ; ++i) {
 line = licenseinfo[i];
 while (*line) {
     n = textbreak(&line, 64);
     printf("%.*s\n", n, line);
     line += n;
 }
    }
}


processinput

decompiled_code:
__int64 __fastcall processinput(char *a1, int a2)
{
__int64 result; // rax
__int64 v3; // r12
char *v4; // rbx
const __int32_t *v6; // rdi
__int64 v7; // rax
int v8; // er8
__int32_t v9; // ecx
__int64 v10; // rax
__int64 v11; // rsi
__int64 v12; // rcx
__int32_t v13; // ecx
__int64 v14; // rdi
int v15; // [rsp+Bh] [rbp-1Dh]
char v16; // [rsp+Fh] [rbp-19h]

if ( !a2 )
{
if ( (*((_BYTE *)&controls + 23) & 2) != 0 )
{
puts("Enter (?) for help.");
return 0LL;
}
goto LABEL_3;
}
result = 0LL;
if ( *((_WORD *)&controls + 10) != 2 )
{
v3 = *a1;
v4 = a1;
v16 = 0;
v15 = 0;
v6 = *_ctype_tolower_loc();
if ( (_BYTE)v3 )
{
v7 = (char)v3;
v8 = 0;
LABEL_9:
while ( 2 )
{
v9 = v6[v7];
v10 = 0LL;
while ( 1 )
{
v11 = (int)v10;
if ( *((unsigned __int8 *)&controls + 4 * v10 + 2) == v9 )
break;
if ( ++v10 == 5 )
{
v7 = *++v4;
if ( (_BYTE)v7 )
goto LABEL_9;
goto LABEL_13;
}
}
if ( (*((_BYTE *)&controls + 4 * (int)v10 + 3) & 2) != 0 )
{
puts("Cannot roll dice.");
return 0LL;
}
v7 = *++v4;
*((_BYTE *)&v15 + v11) = 1;
++v8;
if ( (_BYTE)v7 )
continue;
break;
}
LABEL_13:
if ( !v8 )
goto LABEL_22;
if ( a2 != v8 )
{
puts("Please specify either dice or a single scoring slot.");
return 0LL;
}
v12 = 0LL;
if ( (_BYTE)v15 )
goto LABEL_18;
while ( ++v12 != 5 )
{
if ( *((_BYTE *)&v15 + v12) )
LABEL_18:
queueinputevent(v12);
}
LABEL_3:
queueinputevent(5);
return 1LL;
}
LABEL_22:
v13 = v6[v3];
v14 = 6LL;
while ( v13 != *((unsigned __int8 *)&controls + 4 * v14 + 2) )
{
if ( ++v14 == 22 )
{
puts("Invalid input. Enter (?) for help.");
return 0LL;
}
}
if ( (*((_BYTE *)&controls + 4 * (int)v14 + 3) & 2) != 0 )
{
puts("Slot not available.");
result = 0LL;
}
else
{
queueinputevent(v14);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, int a2)
{
__int64 result; // rax
__int64 v3; // r12
char *v4; // rbx
const __int32_t *v6; // rdi
__int64 v7; // rax
int v8; // er8
__int32_t v9; // ecx
__int64 v10; // rax
__int64 v11; // rsi
__int64 v12; // rcx
__int32_t v13; // ecx
__int64 v14; // rdi
int v15; // [rsp+Bh] [rbp-1Dh]
char v16; // [rsp+Fh] [rbp-19h]

if ( !a2 )
{
if ( (*((_BYTE *)&controls + 23) & 2) != 0 )
{
puts("Enter (?) for help.");
return 0LL;
}
goto LABEL_3;
}
result = 0LL;
if ( *((_WORD *)&controls + 10) != 2 )
{
v3 = *a1;
v4 = a1;
v16 = 0;
v15 = 0;
v6 = *_ctype_tolower_loc();
if ( (_BYTE)v3 )
{
v7 = (char)v3;
v8 = 0;
LABEL_9:
while ( 2 )
{
v9 = v6[v7];
v10 = 0LL;
while ( 1 )
{
v11 = (int)v10;
if ( *((unsigned __int8 *)&controls + 4 * v10 + 2) == v9 )
break;
if ( ++v10 == 5 )
{
v7 = *++v4;
if ( (_BYTE)v7 )
goto LABEL_9;
goto LABEL_13;
}
}
if ( (*((_BYTE *)&controls + 4 * (int)v10 + 3) & 2) != 0 )
{
puts("Cannot roll dice.");
return 0LL;
}
v7 = *++v4;
*((_BYTE *)&v15 + v11) = 1;
++v8;
if ( (_BYTE)v7 )
continue;
break;
}
LABEL_13:
if ( !v8 )
goto LABEL_22;
if ( a2 != v8 )
{
puts("Please specify either dice or a single scoring slot.");
return 0LL;
}
v12 = 0LL;
if ( (_BYTE)v15 )
goto LABEL_18;
while ( ++v12 != 5 )
{
if ( *((_BYTE *)&v15 + v12) )
LABEL_18:
func0(v12);
}
LABEL_3:
func0(5);
return 1LL;
}
LABEL_22:
v13 = v6[v3];
v14 = 6LL;
while ( v13 != *((unsigned __int8 *)&controls + 4 * v14 + 2) )
{
if ( ++v14 == 22 )
{
puts("Invalid input. Enter (?) for help.");
return 0LL;
}
}
if ( (*((_BYTE *)&controls + 4 * (int)v14 + 3) & 2) != 0 )
{
puts("Slot not available.");
result = 0LL;
}
else
{
func0(v14);
result = 1LL;
}
}
return result;
}

original_code:
static int processinput(char const *str, int length)
{
    char dice[5];
    char const *p;
    int i, n;
    if (length == 0) {
 if (((controls[(((0) + 5))]).flags & 0x02)) {
     printf("Enter (?) for help.\n");
     return 0;
 }
 queueinputevent((((0) + 5)));
 return 1;
    }
    if (controls[(((0) + 5))].value == 2)
 return 0;
    n = 0;
    memset(dice, 0, sizeof dice);
    for (p = str ; *p ; ++p) {
 for (i = (0) ; i < ((0) + 5) ; ++i) {
     if (controls[i].key == tolower(*p)) {
  if (((controls[i]).flags & 0x02)) {
      printf("Cannot roll dice.\n");
      return 0;
  }
  dice[i - (0)] = 1;
  ++n;
  break;
     }
 }
    }
    if (n) {
 if (n == length) {
     for (i = 0 ; i < 5 ; ++i)
  if (dice[i])
      queueinputevent((0) + i);
     queueinputevent((((0) + 5)));
     return 1;
 } else {
     printf("Please specify either dice or a single scoring slot.\n");
     return 0;
 }
    }
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i) {
 if (controls[i].key == tolower(*str)) {
     if (((controls[i]).flags & 0x02)) {
  printf("Slot not available.\n");
  return 0;
     }
     if (n > 1) {
  printf("Extra characters after input: \"%s\".\n", str + 1);
  return 0;
     }
     queueinputevent(i);
     return 1;
 }
    }
    printf("Invalid input. Enter (?) for help.\n");
    return 0;
}

canonical_original_code:
static int processinput(char *str, int length)
{
    char dice[5];
    char *p;
    int i; int n;
    if (length == 0) {
 if (((controls[(((0) + 5))]).flags & 0x02)) {
     printf("Enter (?) for help.\n");
     return 0;
 }
 queueinputevent((((0) + 5)));
 return 1;
    }
    if (controls[(((0) + 5))].value == 2)
 return 0;
    n = 0;
    memset(dice, 0, sizeof dice);
    for (p = str ; *p ; ++p) {
 for (i = (0) ; i < ((0) + 5) ; ++i) {
     if (controls[i].key == tolower(*p)) {
  if (((controls[i]).flags & 0x02)) {
      printf("Cannot roll dice.\n");
      return 0;
  }
  dice[i - (0)] = 1;
  ++n;
  break;
     }
 }
    }
    if (n) {
 if (n == length) {
     for (i = 0 ; i < 5 ; ++i)
  if (dice[i])
      queueinputevent((0) + i);
     queueinputevent((((0) + 5)));
     return 1;
 } else {
     printf("Please specify either dice or a single scoring slot.\n");
     return 0;
 }
    }
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i) {
 if (controls[i].key == tolower(*str)) {
     if (((controls[i]).flags & 0x02)) {
  printf("Slot not available.\n");
  return 0;
     }
     if (n > 1) {
  printf("Extra characters after input: \"%s\".\n", str + 1);
  return 0;
     }
     queueinputevent(i);
     return 1;
 }
    }
    printf("Invalid input. Enter (?) for help.\n");
    return 0;
}

variable_types:
str
char *

variable_types: length int

variable_types:
dice
char [5]

variable_types:
p
char *


decompiled_code:
__int64 text_initializeio()
{
__int64 i; // rax
int v1; // edx
__int64 result; // rax

puts("\nY a h t z e e\n");
for ( i = 6LL; i != 22; dword_87C[i] = v1 )
{
v1 = *(__int16 *)((char *)&controls + i * 4);
++i;
}
displayscore = 0;
result = 1LL;
displaydice = 0;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 i; // rax
int v1; // edx
__int64 result; // rax

puts("\nY a h t z e e\n");
for ( i = 6LL; i != 22; dword_87C[i] = v1 )
{
v1 = *(__int16 *)((char *)&controls + i * 4);
++i;
}
displayscore = 0;
result = 1LL;
displaydice = 0;
return result;
}

original_code:
int text_initializeio(void)
{
    int i;
    printf("\nY a h t z e e\n\n");
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i)
 lastvalues[i] = controls[i].value;
    displayscore = 0;
    displaydice = 0;
    return 1;
}

canonical_original_code:
int text_initializeio()
{
    int i;
    printf("\nY a h t z e e\n\n");
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i)
 lastvalues[i] = controls[i].value;
    displayscore = 0;
    displaydice = 0;
    return 1;
}


decompiled_code:
__int64 __fastcall text_runio(_DWORD *a1)
{
unsigned int v1; // er12
int v2; // esi
__int64 v3; // rax
char v4; // cl
int v5; // edx
size_t v6; // r13
const __int32_t **v7; // r14
int v8; // esi
__int64 v9; // rax
int i; // eax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

LABEL_1:
v1 = unqueueinputevent(a1);
if ( v1 )
return 1;
while ( 1 )
{
v2 = displayscore;
v3 = 0LL;
v4 = 0;
do
{
v5 = (controls[v3 * 4 + 27] & 3) != 0;
if ( dword_898[v3] != v5 )
{
dword_898[v3] = v5;
v4 = 1;
v2 = 1;
}
++v3;
}
while ( v3 != 16 );
if ( v4 )
displayscore = v2;
showprompt();
if ( !fgets(s, 8, stdin) )
break;
v6 = strlen(s);
if ( !v6 )
return v1;
v7 = _ctype_tolower_loc();
if ( (*v7)[s[0]] == 113 )
return v1;
if ( v6 != 7 || s[6] == 10 )
{
v8 = v6 - 1;
s[(int)v6 - 1] = 0;
v9 = s[0];
if ( s[0] == 46 )
goto LABEL_24;
}
else
{
for ( i = getchar(); i != 10; i = getchar() )
{
if ( i == -1 )
break;
}
v9 = s[0];
v8 = 7;
if ( s[0] == 46 )
{
LABEL_24:
displayscore = 1;
displaydice = 1;
goto LABEL_1;
}
}
if ( (_BYTE)v9 == 63 )
{
showhelp();
displayscore = 0;
displaydice = 0;
goto LABEL_1;
}
if ( (*v7)[v9] == 118 )
{
showversion();
displayscore = 0;
displaydice = 0;
goto LABEL_1;
}
if ( (unsigned int)processinput(s, v8) )
goto LABEL_1;
fputc(7, stderr);
v1 = unqueueinputevent(a1);
if ( v1 )
return 1;
}
if ( ferror(stdin) )
exit(1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
unsigned int v1; // er12
int v2; // esi
__int64 v3; // rax
char v4; // cl
int v5; // edx
size_t v6; // r13
const __int32_t **v7; // r14
int v8; // esi
__int64 v9; // rax
int i; // eax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

LABEL_1:
v1 = func1(a1);
if ( v1 )
return 1;
while ( 1 )
{
v2 = displayscore;
v3 = 0LL;
v4 = 0;
do
{
v5 = (controls[v3 * 4 + 27] & 3) != 0;
if ( dword_898[v3] != v5 )
{
dword_898[v3] = v5;
v4 = 1;
v2 = 1;
}
++v3;
}
while ( v3 != 16 );
if ( v4 )
displayscore = v2;
func4();
if ( !fgets(s, 8, stdin) )
break;
v6 = strlen(s);
if ( !v6 )
return v1;
v7 = _ctype_tolower_loc();
if ( (*v7)[s[0]] == 113 )
return v1;
if ( v6 != 7 || s[6] == 10 )
{
v8 = v6 - 1;
s[(int)v6 - 1] = 0;
v9 = s[0];
if ( s[0] == 46 )
goto LABEL_24;
}
else
{
for ( i = getchar(); i != 10; i = getchar() )
{
if ( i == -1 )
break;
}
v9 = s[0];
v8 = 7;
if ( s[0] == 46 )
{
LABEL_24:
displayscore = 1;
displaydice = 1;
goto LABEL_1;
}
}
if ( (_BYTE)v9 == 63 )
{
func5();
displayscore = 0;
displaydice = 0;
goto LABEL_1;
}
if ( (*v7)[v9] == 118 )
{
func6();
displayscore = 0;
displaydice = 0;
goto LABEL_1;
}
if ( (unsigned int)func7(s, v8) )
goto LABEL_1;
fputc(7, stderr);
v1 = func1(a1);
if ( v1 )
return 1;
}
if ( ferror(stdin) )
exit(1);
return v1;
}

original_code:
int text_runio(int *control)
{
    char buf[8];
    int ch, i, n;
    for (;;) {
 if (unqueueinputevent(control))
     return 1;
 for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i) {
     n = ((controls[i]).flags & 0x02) || ((controls[i]).flags & 0x01);
     if (lastvalues[i] != n) {
  lastvalues[i] = n;
  displayscore = 1;
     }
 }
 showprompt();
 if (!fgets(buf, sizeof buf, stdin)) {
     if (ferror(stdin))
  exit(1);
     return 0;
 }
 n = strlen(buf);
 if (n == 0 || tolower(*buf) == 'q')
     return 0;
 if (n == sizeof buf - 1 && buf[n - 1] != '\n')
     for (ch = getchar() ; ch != '\n' && ch != (-1) ; ch = getchar()) ;
 else
     buf[--n] = '\0';
 if (*buf == '.') {
     displayscore = 1;
     displaydice = 1;
     continue;
 }
 if (*buf == '?') {
     showhelp();
     displayscore = 0;
     displaydice = 0;
     continue;
 }
 if (tolower(*buf) == 'v') {
     showversion();
     displayscore = 0;
     displaydice = 0;
     continue;
 }
 if (!processinput(buf, n))
     fputc('\a', stderr);
    }
}

canonical_original_code:
int text_runio(int *control)
{
    char buf[8];
    int ch; int i; int n;
    for (;;) {
 if (unqueueinputevent(control))
     return 1;
 for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i) {
     n = ((controls[i]).flags & 0x02) || ((controls[i]).flags & 0x01);
     if (lastvalues[i] != n) {
  lastvalues[i] = n;
  displayscore = 1;
     }
 }
 showprompt();
 if (!fgets(buf, sizeof buf, stdin)) {
     if (ferror(stdin))
  exit(1);
     return 0;
 }
 n = strlen(buf);
 if (n == 0 || tolower(*buf) == 'q')
     return 0;
 if (n == sizeof buf - 1 && buf[n - 1] != '\n')
     for (ch = getchar() ; ch != '\n' && ch != (-1) ; ch = getchar()) ;
 else
     buf[--n] = '\0';
 if (*buf == '.') {
     displayscore = 1;
     displaydice = 1;
     continue;
 }
 if (*buf == '?') {
     showhelp();
     displayscore = 0;
     displaydice = 0;
     continue;
 }
 if (tolower(*buf) == 'v') {
     showversion();
     displayscore = 0;
     displaydice = 0;
     continue;
 }
 if (!processinput(buf, n))
     fputc('\a', stderr);
    }
}

variable_types:
buf
char [8]

variable_types: ch int


ones

decompiled_code:
__int64 __fastcall ones(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return *a1;
}

original_code: static int ones(int values[6]) { return 1 * values[0]; }

variable_types:
values
int [6]


twos

decompiled_code:
__int64 __fastcall twos(__int64 a1)
{
return (unsigned int)(2 * *(_DWORD *)(a1 + 4));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return (unsigned int)(2 * *(_DWORD *)(a1 + 4));
}

original_code: static int twos(int values[6]) { return 2 * values[1]; }


threes

decompiled_code:
__int64 __fastcall threes(__int64 a1)
{
return (unsigned int)(3 * *(_DWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return (unsigned int)(3 * *(_DWORD *)(a1 + 8));
}

original_code: static int threes(int values[6]) { return 3 * values[2]; }


fours

decompiled_code:
__int64 __fastcall fours(__int64 a1)
{
return (unsigned int)(4 * *(_DWORD *)(a1 + 12));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)(4 * *(_DWORD *)(a1 + 12));
}

original_code: static int fours(int values[6]) { return 4 * values[3]; }


fives

decompiled_code:
__int64 __fastcall fives(__int64 a1)
{
return (unsigned int)(5 * *(_DWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return (unsigned int)(5 * *(_DWORD *)(a1 + 16));
}

original_code: static int fives(int values[6]) { return 5 * values[4]; }


sixes

decompiled_code:
__int64 __fastcall sixes(__int64 a1)
{
return (unsigned int)(6 * *(_DWORD *)(a1 + 20));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return (unsigned int)(6 * *(_DWORD *)(a1 + 20));
}

original_code: static int sixes(int values[6]) { return 6 * values[5]; }


chance

decompiled_code:
__int64 __fastcall chance(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8
int v3; // edx

v1 = 1LL;
v2 = 0;
do
{
v3 = v1 * *(_DWORD *)(a1 + 4 * v1 - 4);
++v1;
v2 += v3;
}
while ( v1 != 7 );
return v2;
}

original_code:
static int chance(int values[6])
{
    int total, i;
    total = 0;
    for (i = 0 ; i < 6 ; ++i)
 total += (i + 1) * values[i];
    return total;
}

canonical_original_code:
static int chance(int values[6])
{
    int total; int i;
    total = 0;
    for (i = 0 ; i < 6 ; ++i)
 total += (i + 1) * values[i];
    return total;
}

variable_types: total int


threeofakind

decompiled_code:
__int64 __fastcall threeofakind(__int64 a1)
{
int *v1; // rax

v1 = (int *)a1;
while ( *v1 <= 2 )
{
if ( ++v1 == (int *)(a1 + 24) )
return 0LL;
}
return chance(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int *v1; // rax

v1 = (int *)a1;
while ( *v1 <= 2 )
{
if ( ++v1 == (int *)(a1 + 24) )
return 0LL;
}
return func6(a1);
}

original_code:
static int threeofakind(int values[6])
{
    int i;
    for (i = 0 ; i < 6 ; ++i)
 if (values[i] >= 3)
     return chance(values);
    return 0;
}


fourofakind

decompiled_code:
__int64 __fastcall fourofakind(__int64 a1)
{
int *v1; // rax

v1 = (int *)a1;
while ( *v1 <= 3 )
{
if ( ++v1 == (int *)(a1 + 24) )
return 0LL;
}
return chance(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int *v1; // rax

v1 = (int *)a1;
while ( *v1 <= 3 )
{
if ( ++v1 == (int *)(a1 + 24) )
return 0LL;
}
return func6(a1);
}

original_code:
static int fourofakind(int values[6])
{
    int i;
    for (i = 0 ; i < 6 ; ++i)
 if (values[i] >= 4)
     return chance(values);
    return 0;
}


yahtzee

decompiled_code:
__int64 __fastcall yahtzee(_DWORD *a1)
{
_DWORD *v1; // rax

v1 = a1 + 6;
while ( *a1 != 5 )
{
if ( ++a1 == v1 )
return 0LL;
}
return 50LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
_DWORD *v1; // rax

v1 = a1 + 6;
while ( *a1 != 5 )
{
if ( ++a1 == v1 )
return 0LL;
}
return 50LL;
}

original_code:
static int yahtzee(int values[6])
{
    int i;
    for (i = 0 ; i < 6 ; ++i)
 if (values[i] == 5)
     return 50;
    return 0;
}


fullhouse

decompiled_code:
__int64 __fastcall fullhouse(int *a1)
{
int *v1; // rcx
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = a1 + 6;
v2 = 0;
do
{
v3 = *a1;
if ( *a1 == 4 )
return 0LL;
if ( v3 > 4 )
{
if ( v3 == 5 )
return 25LL;
}
else
{
if ( !v3 )
goto LABEL_5;
if ( v3 == 1 )
return 0LL;
}
v2 += v3;
LABEL_5:
++a1;
}
while ( a1 != v1 );
result = 25LL;
if ( v2 != 5 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1)
{
int *v1; // rcx
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = a1 + 6;
v2 = 0;
do
{
v3 = *a1;
if ( *a1 == 4 )
return 0LL;
if ( v3 > 4 )
{
if ( v3 == 5 )
return 25LL;
}
else
{
if ( !v3 )
goto LABEL_5;
if ( v3 == 1 )
return 0LL;
}
v2 += v3;
LABEL_5:
++a1;
}
while ( a1 != v1 );
result = 25LL;
if ( v2 != 5 )
result = 0LL;
return result;
}

original_code:
static int fullhouse(int values[6])
{
    int count, i;
    count = 0;
    for (i = 0 ; i < 6 ; ++i) {
 switch (values[i]) {
   case 0: continue;
   case 1: return 0;
   case 4: return 0;
   case 5: return 25;
   default: count += values[i];
 }
    }
    return count == 5 ? 25 : 0;
}

canonical_original_code:
static int fullhouse(int values[6])
{
    int count; int i;
    count = 0;
    for (i = 0 ; i < 6 ; ++i) {
 switch (values[i]) {
   case 0: continue;
   case 1: return 0;
   case 4: return 0;
   case 5: return 25;
   default: count += values[i];
 }
    }
    return count == 5 ? 25 : 0;
}

variable_types: count int


smallstraight

decompiled_code:
__int64 __fastcall smallstraight(_DWORD *a1)
{
__int64 result; // rax
int v2; // edx

result = (unsigned int)a1[2];
if ( (_DWORD)result )
{
result = (unsigned int)a1[3];
if ( (_DWORD)result )
{
v2 = a1[1];
if ( *a1 )
{
result = 30LL;
if ( v2 )
return result;
result = (unsigned int)a1[4];
}
else
{
result = (unsigned int)a1[4];
if ( v2 )
{
LABEL_9:
if ( (_DWORD)result )
result = 30LL;
return result;
}
}
if ( !(_DWORD)result )
return result;
result = (unsigned int)a1[5];
goto LABEL_9;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
__int64 result; // rax
int v2; // edx

result = (unsigned int)a1[2];
if ( (_DWORD)result )
{
result = (unsigned int)a1[3];
if ( (_DWORD)result )
{
v2 = a1[1];
if ( *a1 )
{
result = 30LL;
if ( v2 )
return result;
result = (unsigned int)a1[4];
}
else
{
result = (unsigned int)a1[4];
if ( v2 )
{
LABEL_9:
if ( (_DWORD)result )
result = 30LL;
return result;
}
}
if ( !(_DWORD)result )
return result;
result = (unsigned int)a1[5];
goto LABEL_9;
}
}
return result;
}

original_code:
static int smallstraight(int values[6])
{
    if (values[2] && values[3])
 if ((values[0] && values[1]) || (values[1] && values[4])
         || (values[4] && values[5]))
     return 30;
    return 0;
}


largestraight

decompiled_code:
__int64 __fastcall largestraight(_DWORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1[1] == 1 && a1[2] == 1 && a1[3] == 1 && a1[4] == 1 )
result = 40LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1[1] == 1 && a1[2] == 1 && a1[3] == 1 && a1[4] == 1 )
result = 40LL;
return result;
}

original_code:
static int largestraight(int values[6])
{
    if (values[1] == 1 && values[2] == 1 && values[3] == 1 && values[4] == 1)
 return 40;
    return 0;
}


updateopenslots

decompiled_code:
__int64 updateopenslots()
{
__int64 result; // rax
__int64 v1; // rdx
__int64 i; // rbx
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
do
{
v1 = *((__int16 *)&controls + 2 * result++);
++*((_DWORD *)v3 + v1);
}
while ( result != 5 );
for ( i = 6LL; i != 22; ++i )
{
if ( (*((_BYTE *)&controls + 4 * i + 3) & 2) == 0 )
{
result = ((__int64 (__fastcall *)(__int64 *))slotevalfunctions[i])(v3);
*((_WORD *)&controls + 2 * i) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
__int64 v1; // rdx
__int64 i; // rbx
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
do
{
v1 = *((__int16 *)&controls + 2 * result++);
++*((_DWORD *)v3 + v1);
}
while ( result != 5 );
for ( i = 6LL; i != 22; ++i )
{
if ( (*((_BYTE *)&controls + 4 * i + 3) & 2) == 0 )
{
result = ((__int64 (__fastcall *)(__int64 *))slotevalfunctions[i])(v3);
*((_WORD *)&controls + 2 * i) = result;
}
}
return result;
}

original_code:
void updateopenslots(void)
{
    int values[6] = { 0, 0, 0, 0, 0, 0 };
    int i;
    for (i = (0) ; i < ((0) + 5) ; ++i)
 ++values[controls[i].value];
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i)
 if (!((controls[i]).flags & 0x02))
     controls[i].value = slotevalfunctions[i](values);
}

canonical_original_code:
void updateopenslots()
{
    int values[6] = { 0, 0, 0, 0, 0, 0 };
    int i;
    for (i = (0) ; i < ((0) + 5) ; ++i)
 ++values[controls[i].value];
    for (i = ((((0) + 5)) + 1) ; i < (((((0) + 5)) + 1) + 16) ; ++i)
 if (!((controls[i]).flags & 0x02))
     controls[i].value = slotevalfunctions[i](values);
}


updatescores

decompiled_code:
__int64 updatescores()
{
unsigned __int64 v0; // rax
int v1; // ecx
int v2; // edx
__int64 v3; // rax
__int64 result; // rax

v0 = (unsigned int)((_DWORD)controls + 24);
v1 = 0;
v2 = 0;
do
{
if ( (*(_BYTE *)(v0 + 3) & 3) != 0 )
{
++v1;
v2 += *(__int16 *)v0;
}
v0 += 4LL;
}
while ( (_WORD *)v0 != &controls[24] );
if ( v1 )
{
controls[24] = v2;
if ( v2 <= 62 )
{
controls[26] = -(v1 != 6);
}
else
{
LOWORD(v2) = v2 + 35;
controls[26] = 35;
}
}
else
{
controls[24] = -1;
controls[26] = -1;
}
v3 = (unsigned int)((_DWORD)controls + 56);
do
{
if ( (*(_BYTE *)(v3 + 3) & 3) != 0 )
{
++v1;
LOWORD(v2) = *(_WORD *)v3 + v2;
}
v3 += 4LL;
}
while ( (_WORD *)v3 != &controls[42] );
result = 0xFFFFFFFFLL;
if ( !v1 )
LOWORD(v2) = -1;
controls[42] = v2;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
unsigned __int64 v0; // rax
int v1; // ecx
int v2; // edx
__int64 v3; // rax
__int64 result; // rax

v0 = (unsigned int)((_DWORD)controls + 24);
v1 = 0;
v2 = 0;
do
{
if ( (*(_BYTE *)(v0 + 3) & 3) != 0 )
{
++v1;
v2 += *(__int16 *)v0;
}
v0 += 4LL;
}
while ( (_WORD *)v0 != &controls[24] );
if ( v1 )
{
controls[24] = v2;
if ( v2 <= 62 )
{
controls[26] = -(v1 != 6);
}
else
{
LOWORD(v2) = v2 + 35;
controls[26] = 35;
}
}
else
{
controls[24] = -1;
controls[26] = -1;
}
v3 = (unsigned int)((_DWORD)controls + 56);
do
{
if ( (*(_BYTE *)(v3 + 3) & 3) != 0 )
{
++v1;
LOWORD(v2) = *(_WORD *)v3 + v2;
}
v3 += 4LL;
}
while ( (_WORD *)v3 != &controls[42] );
result = 0xFFFFFFFFLL;
if ( !v1 )
LOWORD(v2) = -1;
controls[42] = v2;
return result;
}

variable_types: setcount int


showlicense

decompiled_code:
_BOOL8 showlicense()
{
unsigned int v0; // eax
int v1; // eax
const char *v2; // rsi
int v3; // edx
__int64 v4; // rbx
__int16 v5; // ax

initfont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", (unsigned int)(3 * sdl_scalingunit));
v0 = SDL_MapRGB(*(_QWORD *)(sdl_screen + 8LL), 0LL, 32LL, 80LL);
SDL_FillRect(sdl_screen, 0LL, v0);
v1 = TTF_FontLineSkip(font);
v2 = (const char *)licenseinfo;
v3 = v1 / 2;
if ( licenseinfo )
{
v4 = (unsigned int)((_DWORD)&licenseinfo + 8);
do
{
v4 += 8LL;
v5 = writetext(sdl_screen, v2, v3);
v2 = *(const char **)(v4 - 8);
LOWORD(v3) = v5;
}
while ( v2 );
}
SDL_UpdateRect(sdl_screen, 0LL, 0LL, 0LL, 0LL);
TTF_CloseFont(font);
font = 0LL;
return getkey();
}

canonical_decompiled_code:
_BOOL8 func6()
{
unsigned int v0; // eax
int v1; // eax
const char *v2; // rsi
int v3; // edx
__int64 v4; // rbx
__int16 v5; // ax

func0("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", (unsigned int)(3 * sdl_scalingunit));
v0 = SDL_MapRGB(*(_QWORD *)(sdl_screen + 8LL), 0LL, 32LL, 80LL);
SDL_FillRect(sdl_screen, 0LL, v0);
v1 = TTF_FontLineSkip(font);
v2 = (const char *)licenseinfo;
v3 = v1 / 2;
if ( licenseinfo )
{
v4 = (unsigned int)((_DWORD)&licenseinfo + 8);
do
{
v4 += 8LL;
v5 = func1(sdl_screen, v2, v3);
v2 = *(const char **)(v4 - 8);
LOWORD(v3) = v5;
}
while ( v2 );
}
SDL_UpdateRect(sdl_screen, 0LL, 0LL, 0LL, 0LL);
TTF_CloseFont(font);
font = 0LL;
return func2();
}

original_code:
int showlicense(void)
{
    int i, y;
    initfont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", sdl_scalingunit * 3);
    SDL_FillRect(sdl_screen, ((void *)0),
   SDL_MapRGB(sdl_screen->format,
       bkgndcolor.r, bkgndcolor.g, bkgndcolor.b));
    y = TTF_FontLineSkip(font) / 2;
    for (i = 0 ; licenseinfo[i] ; ++i)
 y = writetext(sdl_screen, licenseinfo[i], y);
    SDL_UpdateRect(sdl_screen, 0, 0, 0, 0);
    TTF_CloseFont(font);
    font = ((void *)0);
    return getkey();
}

canonical_original_code:
int showlicense()
{
    int i; int y;
    initfont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", sdl_scalingunit * 3);
    SDL_FillRect(sdl_screen, ((void *)0),
   SDL_MapRGB(sdl_screen->format,
       bkgndcolor.r, bkgndcolor.g, bkgndcolor.b));
    y = TTF_FontLineSkip(font) / 2;
    for (i = 0 ; licenseinfo[i] ; ++i)
 y = writetext(sdl_screen, licenseinfo[i], y);
    SDL_UpdateRect(sdl_screen, 0, 0, 0, 0);
    TTF_CloseFont(font);
    font = ((void *)0);
    return getkey();
}

variable_types: y int


initfont

decompiled_code:
__int64 initfont()
{
__int64 v0; // rdi
int v1; // eax
int v2; // edx
__int64 result; // rax
const char *v4; // rax

font = TTF_OpenFont();
v0 = font;
if ( !font )
{
v4 = (const char *)SDL_GetError();
croak("%s\nUnable to load font.", v4);
v0 = font;
}
v1 = TTF_FontLineSkip(v0);
v2 = v1 + 2;
result = (unsigned int)(v1 + 4);
keyheight = v2;
keywidth = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdi
int v1; // eax
int v2; // edx
__int64 result; // rax
const char *v4; // rax

font = TTF_OpenFont();
v0 = font;
if ( !font )
{
v4 = (const char *)SDL_GetError();
croak("%s\nUnable to load font.", v4);
v0 = font;
}
v1 = TTF_FontLineSkip(v0);
v2 = v1 + 2;
result = (unsigned int)(v1 + 4);
keyheight = v2;
keywidth = result;
return result;
}

original_code:
static void initfont(char const *path, int fontheight)
{
    font = TTF_OpenFont(path, fontheight);
    if (!font)
 croak("%s\nUnable to load font.", SDL_GetError());
    keyheight = TTF_FontLineSkip(font) + 2;
    keywidth = keyheight + 2;
}

canonical_original_code:
static void initfont(char *path, int fontheight)
{
    font = TTF_OpenFont(path, fontheight);
    if (!font)
 croak("%s\nUnable to load font.", SDL_GetError());
    keyheight = TTF_FontLineSkip(font) + 2;
    keywidth = keyheight + 2;
}

variable_types:
path
char *

variable_types: fontheight int


runhelp

decompiled_code:
_BOOL8 runhelp()
{
unsigned int v0; // eax
int v1; // eax
const char *v2; // rsi
int v3; // edx
__int64 v4; // rbx
__int16 v5; // ax
char **v6; // rbx
const char *v7; // rsi
__int16 v8; // dx
__int16 v9; // ax

initfont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", (unsigned int)(3 * sdl_scalingunit));
v0 = SDL_MapRGB(*(_QWORD *)(sdl_screen + 8LL), 0LL, 32LL, 80LL);
SDL_FillRect(sdl_screen, 0LL, v0);
v1 = TTF_FontLineSkip(font);
v2 = (const char *)rulesinfo;
v3 = v1 / 2;
if ( rulesinfo )
{
v4 = (unsigned int)((_DWORD)&rulesinfo + 8);
do
{
v4 += 8LL;
v5 = writetext(sdl_screen, v2, v3);
v2 = *(const char **)(v4 - 8);
LOWORD(v3) = v5;
}
while ( v2 );
}
v6 = off_8C8;
v7 = "Press Ctrl-+ and Ctrl-– to resize the window.";
v8 = TTF_FontLineSkip(font) + v3;
do
{
++v6;
v9 = writetext(sdl_screen, v7, v8);
v7 = *(v6 - 1);
v8 = v9;
}
while ( v7 );
SDL_UpdateRect(sdl_screen, 0LL, 0LL, 0LL, 0LL);
TTF_CloseFont(font);
font = 0LL;
return getkey();
}

canonical_decompiled_code:
_BOOL8 func5()
{
unsigned int v0; // eax
int v1; // eax
const char *v2; // rsi
int v3; // edx
__int64 v4; // rbx
__int16 v5; // ax
char **v6; // rbx
const char *v7; // rsi
__int16 v8; // dx
__int16 v9; // ax

func0("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", (unsigned int)(3 * sdl_scalingunit));
v0 = SDL_MapRGB(*(_QWORD *)(sdl_screen + 8LL), 0LL, 32LL, 80LL);
SDL_FillRect(sdl_screen, 0LL, v0);
v1 = TTF_FontLineSkip(font);
v2 = (const char *)rulesinfo;
v3 = v1 / 2;
if ( rulesinfo )
{
v4 = (unsigned int)((_DWORD)&rulesinfo + 8);
do
{
v4 += 8LL;
v5 = func1(sdl_screen, v2, v3);
v2 = *(const char **)(v4 - 8);
LOWORD(v3) = v5;
}
while ( v2 );
}
v6 = off_8C8;
v7 = "Press Ctrl-+ and Ctrl-– to resize the window.";
v8 = TTF_FontLineSkip(font) + v3;
do
{
++v6;
v9 = func1(sdl_screen, v7, v8);
v7 = *(v6 - 1);
v8 = v9;
}
while ( v7 );
SDL_UpdateRect(sdl_screen, 0LL, 0LL, 0LL, 0LL);
TTF_CloseFont(font);
font = 0LL;
return func2();
}

original_code:
int runhelp(void)
{
    static char const *helptext[] = {
 "Press Ctrl-+ and Ctrl-\xE2\x80\x93 to resize the window.",
 "Press ? or F1 to view this help text again.",
 "Press Ctrl-K to view the keyboard shortcuts.",
 "Press Ctrl-V to view the version and license information.",
 "Press Ctrl-X to exit the program.",
 ((void *)0)
    };
    int i, y;
    initfont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", sdl_scalingunit * 3);
    SDL_FillRect(sdl_screen, ((void *)0),
   SDL_MapRGB(sdl_screen->format,
       bkgndcolor.r, bkgndcolor.g, bkgndcolor.b));
    y = TTF_FontLineSkip(font) / 2;
    for (i = 0 ; rulesinfo[i] ; ++i)
 y = writetext(sdl_screen, rulesinfo[i], y);
    y += TTF_FontLineSkip(font);
    for (i = 0 ; helptext[i] ; ++i)
 y = writetext(sdl_screen, helptext[i], y);
    SDL_UpdateRect(sdl_screen, 0, 0, 0, 0);
    TTF_CloseFont(font);
    font = ((void *)0);
    return getkey();
    return displaytext(helptext);
}

canonical_original_code:
int runhelp()
{
    static char *helptext[] = {
 "Press Ctrl-+ and Ctrl-\xE2\x80\x93 to resize the window.",
 "Press ? or F1 to view this help text again.",
 "Press Ctrl-K to view the keyboard shortcuts.",
 "Press Ctrl-V to view the version and license information.",
 "Press Ctrl-X to exit the program.",
 ((void *)0)
    };
    int i; int y;
    initfont("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", sdl_scalingunit * 3);
    SDL_FillRect(sdl_screen, ((void *)0),
   SDL_MapRGB(sdl_screen->format,
       bkgndcolor.r, bkgndcolor.g, bkgndcolor.b));
    y = TTF_FontLineSkip(font) / 2;
    for (i = 0 ; rulesinfo[i] ; ++i)
 y = writetext(sdl_screen, rulesinfo[i], y);
    y += TTF_FontLineSkip(font);
    for (i = 0 ; helptext[i] ; ++i)
 y = writetext(sdl_screen, helptext[i], y);
    SDL_UpdateRect(sdl_screen, 0, 0, 0, 0);
    TTF_CloseFont(font);
    font = ((void *)0);
    return getkey();
    return displaytext(helptext);
}

variable_types:
helptext
char *[]

variable_types: i int


topolar

decompiled_code:
void __fastcall topolar(int a1, int a2, float *a3, float *a4)
{
float v5; // xmm0_4
float v6; // xmm0_4
float *v7; // [rsp+8h] [rbp-10h]

v5 = (float)(a2 * a2 + a1 * a1);
if ( v5 < 0.0 )
{
v7 = a3;
v6 = sqrtf(v5);
a3 = v7;
}
else
{
v6 = fsqrt(v5);
}
*a3 = v6;
*a4 = atanf((float)a2 / (float)a1);
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2, float *a3, float *a4)
{
float v5; // xmm0_4
float v6; // xmm0_4
float *v7; // [rsp+8h] [rbp-10h]

v5 = (float)(a2 * a2 + a1 * a1);
if ( v5 < 0.0 )
{
v7 = a3;
v6 = sqrtf(v5);
a3 = v7;
}
else
{
v6 = fsqrt(v5);
}
*a3 = v6;
*a4 = atanf((float)a2 / (float)a1);
}

original_code:
static void topolar(int x, int y, float *r, float *t)
{
    *r = sqrtf(x * x + y * y);
    *t = atanf((float)y / x);
}

variable_types: x int

variable_types:
r
float *

variable_types:
t
float *


makepip

original_code:
static Uint8 *makepip(int width, int height, int radius)
{
    Uint8 *pixels, *p;
    float r, t, c;
    int xcenter, ycenter;
    int x, y;
    xcenter = width / 2;
    ycenter = height / 2;
    p = pixels = allocate(width * height);
    for (y = 0 ; y < height ; ++y) {
 for (x = 0 ; x < width ; ++x) {
     topolar(x - xcenter, ycenter - y, &r, &t);
     if (r - 0.5 > radius) {
  *p++ = 255;
  continue;
     }
     c = 0.0;
     if (t < 0 && x > xcenter && y > ycenter) {
  c += 64.0 * sinf(-t * 2);
  if (r < 4.0)
      c *= r / 4.0;
     }
     if (r + 0.5 > radius)
  c += (240.0 - c) * (r + 0.5 - radius);
     *p++ = (int)c & 255;
 }
    }
    return pixels;
}

canonical_original_code:
static unsigned char *makepip(int width, int height, int radius)
{
    unsigned char *pixels; unsigned char *p;
    float r; float t; float c;
    int xcenter; int ycenter;
    int x; int y;
    xcenter = width / 2;
    ycenter = height / 2;
    p = pixels = allocate(width * height);
    for (y = 0 ; y < height ; ++y) {
 for (x = 0 ; x < width ; ++x) {
     topolar(x - xcenter, ycenter - y, &r, &t);
     if (r - 0.5 > radius) {
  *p++ = 255;
  continue;
     }
     c = 0.0;
     if (t < 0 && x > xcenter && y > ycenter) {
  c += 64.0 * sinf(-t * 2);
  if (r < 4.0)
      c *= r / 4.0;
     }
     if (r + 0.5 > radius)
  c += (240.0 - c) * (r + 0.5 - radius);
     *p++ = (int)c & 255;
 }
    }
    return pixels;
}

variable_types: width int

variable_types: height int

variable_types: radius int

variable_types:
pixels
unsigned char *

variable_types:
p
unsigned char *

variable_types: r float

variable_types: t float

variable_types: c float

variable_types: xcenter int

variable_types: ycenter int

return_type: unsigned char *


initializeio

decompiled_code:
__int64 __fastcall initializeio(int a1)
{
__int64 result; // rax

if ( a1 == 1 )
{
runio = (__int64)&curses_runio;
result = curses_initializeio();
}
else if ( a1 == 2 )
{
runio = (__int64)&sdl_runio;
result = sdl_initializeio();
}
else if ( a1 )
{
result = 0LL;
}
else
{
runio = (__int64)&text_runio;
result = text_initializeio();
}
return result;
}

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

if ( a1 == 1 )
{
runio = (__int64)&curses_runio;
result = curses_initializeio();
}
else if ( a1 == 2 )
{
runio = (__int64)&sdl_runio;
result = sdl_initializeio();
}
else if ( a1 )
{
result = 0LL;
}
else
{
runio = (__int64)&text_runio;
result = text_initializeio();
}
return result;
}

original_code:
int initializeio(int iomode)
{
    switch (iomode) {
      case io_text:
 runio = text_runio;
 return text_initializeio();
      case io_curses:
 runio = curses_runio;
 return curses_initializeio();
      case io_sdl:
 runio = sdl_runio;
 return sdl_initializeio();
    }
    return 0;
}

variable_types: iomode int


croak

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

va_start(arg, format);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

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

va_start(arg, format);
vfprintf(stderr, format, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void croak(char const *fmt, ...)
{
    va_list args;
    __builtin_va_start(args,fmt);
    vfprintf(stderr, fmt, args);
    fputc('\n', stderr);
    __builtin_va_end(args);
    exit(1);
}

canonical_original_code:
void croak(char *fmt, ...)
{
    __builtin_va_list args;
    __builtin_va_start(args,fmt);
    vfprintf(stderr, fmt, args);
    fputc('\n', stderr);
    __builtin_va_end(args);
    exit(1);
}

variable_types:
fmt
char *


allocate

decompiled_code:
void *__fastcall allocate(size_t size)
{
void *result; // rax

result = malloc((unsigned int)size);
if ( !result )
{
fwrite("memory allocation failed\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t size)
{
void *result; // rax

result = malloc((unsigned int)size);
if ( !result )
{
fwrite("memory allocation failed\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
void *allocate(unsigned int size)
{
    void *p;
    p = malloc(size);
    if (!p) {
 fputs("memory allocation failed\n", stderr);
 exit(1);
    }
    return p;
}

variable_types:
size
unsigned int

variable_types:
p
void *

return_type: void *


textbreak

original_code:
int textbreak(char const **pstr, int width)
{
    char const *str;
    int brk, n;
    while (**pstr == ' ')
 ++*pstr;
    str = *pstr;
    if (*str == '\0')
 return 0;
    brk = 0;
    for (n = 1 ; n < width ; ++n) {
 if (str[n] == '\0')
     return n;
 else if (str[n] == ' ' && str[n - 1] != ' ')
     brk = n;
    }
    return brk ? brk : width;
}

canonical_original_code:
int textbreak(char **pstr, int width)
{
    char *str;
    int brk; int n;
    while (**pstr == ' ')
 ++*pstr;
    str = *pstr;
    if (*str == '\0')
 return 0;
    brk = 0;
    for (n = 1 ; n < width ; ++n) {
 if (str[n] == '\0')
     return n;
 else if (str[n] == ' ' && str[n - 1] != ' ')
     brk = n;
    }
    return brk ? brk : width;
}

variable_types:
pstr
char **

variable_types:
str
char *

variable_types: brk int

variable_types: n int


changediechars

decompiled_code:
__int64 __fastcall changediechars(int a1)
{
__int64 result; // rax

result = (unsigned int)((which_2 + a1) % 3);
which_2 = result;
switch ( (_DWORD)result )
{
case 1:
LODWORD(qword_D70) = acs_map[54];
diechars = 0x6F00000020LL;
goto LABEL_6;
case 2:
LODWORD(diechars) = 32;
LODWORD(qword_D70) = acs_map[54];
HIDWORD(diechars) = acs_map[63];
LABEL_6:
HIDWORD(qword_D70) = HIDWORD(acs_map[53]);
LODWORD(qword_D68) = HIDWORD(acs_map[56]);
LODWORD(qword_D78) = HIDWORD(acs_map[54]);
HIDWORD(qword_D68) = acs_map[60];
result = LODWORD(acs_map[53]);
HIDWORD(qword_D78) = acs_map[53];
return result;
case 0:
diechars = 0x6F00000020LL;
qword_D68 = 0x7C0000002DLL;
result = 0x2000000020LL;
qword_D70 = 0x2000000020LL;
qword_D78 = 0x2000000020LL;
break;
}
return result;
}

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

result = (unsigned int)((which_2 + a1) % 3);
which_2 = result;
switch ( (_DWORD)result )
{
case 1:
LODWORD(qword_D70) = acs_map[54];
diechars = 0x6F00000020LL;
goto LABEL_6;
case 2:
LODWORD(diechars) = 32;
LODWORD(qword_D70) = acs_map[54];
HIDWORD(diechars) = acs_map[63];
LABEL_6:
HIDWORD(qword_D70) = HIDWORD(acs_map[53]);
LODWORD(qword_D68) = HIDWORD(acs_map[56]);
LODWORD(qword_D78) = HIDWORD(acs_map[54]);
HIDWORD(qword_D68) = acs_map[60];
result = LODWORD(acs_map[53]);
HIDWORD(qword_D78) = acs_map[53];
return result;
case 0:
diechars = 0x6F00000020LL;
qword_D68 = 0x7C0000002DLL;
result = 0x2000000020LL;
qword_D70 = 0x2000000020LL;
qword_D78 = 0x2000000020LL;
break;
}
return result;
}

original_code:
static void changediechars(int advance)
{
    static int which = 0;
    which = (which + advance) % 3;
    switch (which) {
      case 0:
 diechars[0] = ' '; diechars[4] = ' ';
 diechars[1] = 'o'; diechars[5] = ' ';
 diechars[2] = '-'; diechars[6] = ' ';
 diechars[3] = '|'; diechars[7] = ' ';
 break;
      case 1:
 diechars[0] = ' '; diechars[4] = (acs_map[(unsigned char)(('l'))]);
 diechars[1] = 'o'; diechars[5] = (acs_map[(unsigned char)(('k'))]);
 diechars[2] = (acs_map[(unsigned char)(('q'))]); diechars[6] = (acs_map[(unsigned char)(('m'))]);
 diechars[3] = (acs_map[(unsigned char)(('x'))]); diechars[7] = (acs_map[(unsigned char)(('j'))]);
 break;
      case 2:
 diechars[0] = ' '; diechars[4] = (acs_map[(unsigned char)(('l'))]);
 diechars[1] = (acs_map[(unsigned char)(('~'))]); diechars[5] = (acs_map[(unsigned char)(('k'))]);
 diechars[2] = (acs_map[(unsigned char)(('q'))]); diechars[6] = (acs_map[(unsigned char)(('m'))]);
 diechars[3] = (acs_map[(unsigned char)(('x'))]); diechars[7] = (acs_map[(unsigned char)(('j'))]);
 break;
    }
}

variable_types: advance int

variable_types: which int


drawacsdie

decompiled_code:
int __fastcall drawacsdie(int a1, int a2, int a3)
{
__int64 v3; // r12
__int64 v4; // rbp
const char *i; // rbx
char *v6; // r14
char *v7; // rbx
int v8; // eax
int result; // eax

v3 = 9 * a3;
v4 = 0LL;
for ( i = "422222225422222225422222225422222225422222225422222225"; ; i = diepatterns[v4] )
{
v6 = (char *)&i[v3];
v7 = (char *)&i[v3 + 9];
wmove(stdscr, a1 + v4, a2);
do
{
v8 = *v6++;
result = waddch(stdscr, *((unsigned int *)&diechars + v8 - 48));
}
while ( v6 != v7 );
if ( ++v4 == 5 )
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, int a2, int a3)
{
__int64 v3; // r12
__int64 v4; // rbp
const char *i; // rbx
char *v6; // r14
char *v7; // rbx
int v8; // eax
int result; // eax

v3 = 9 * a3;
v4 = 0LL;
for ( i = "422222225422222225422222225422222225422222225422222225"; ; i = diepatterns[v4] )
{
v6 = (char *)&i[v3];
v7 = (char *)&i[v3 + 9];
wmove(stdscr, a1 + v4, a2);
do
{
v8 = *v6++;
result = waddch(stdscr, *((unsigned int *)&diechars + v8 - 48));
}
while ( v6 != v7 );
if ( ++v4 == 5 )
break;
}
return result;
}

original_code:
static void drawacsdie(int y, int x, int v)
{
    int i, j;
    for (j = 0 ; j < cyDie ; ++j) {
 wmove(stdscr,(y + j),(x));
 for (i = 0 ; i < cxDie ; ++i)
     waddch(stdscr,(diechars[diepatterns[j][v * cxDie + i] - '0']));
    }
}

canonical_original_code:
static void drawacsdie(int y, int x, int v)
{
    int i; int j;
    for (j = 0 ; j < cyDie ; ++j) {
 wmove(stdscr,(y + j),(x));
 for (i = 0 ; i < cxDie ; ++i)
     waddch(stdscr,(diechars[diepatterns[j][v * cxDie + i] - '0']));
    }
}

variable_types: y int

variable_types: x int

variable_types: v int

variable_types: i int

variable_types: j int