SocketClose

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

result = close(a1);
if ( result )
result = -*_errno_location();
return result;
}

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

result = close(a1);
if ( result )
result = -*_errno_location();
return result;
}

original_code:
int SocketClose (int number)
{
    if ( close (number) != 0)
    {
 int errsv = (*__errno_location ());
 return -1*errsv;
    }
    else
    {
 return 0;
    }
}

canonical_original_code:
int SocketClose(int number)
{
    if ( close (number) != 0)
    {
 int errsv = (*__errno_location ());
 return -1*errsv;
    }
    else
    {
 return 0;
    }
}


initTimers

repo: NpoSaut/cSocketCanLib

original_code:
void initTimers (struct timeval *now, struct timeval *end, int timeoutMs)
{
    gettimeofday (now, ((void *)0));
    struct timeval timeout;
    timeout.tv_sec = timeoutMs / 1000;
    timeout.tv_usec = (timeoutMs % 1000) * 1000;
    do { (end)->tv_sec = (now)->tv_sec + (&timeout)->tv_sec; (end)->tv_usec = (now)->tv_usec + (&timeout)->tv_usec; if ((end)->tv_usec >= 1000000) { ++(end)->tv_sec; (end)->tv_usec -= 1000000; } } while (0);
}

canonical_original_code:
void initTimers(struct timeval *now, struct timeval *end, int timeoutMs)
{
    gettimeofday (now, ((void *)0));
    struct timeval timeout;
    timeout.tv_sec = timeoutMs / 1000;
    timeout.tv_usec = (timeoutMs % 1000) * 1000;
    do { (end)->tv_sec = (now)->tv_sec + (&timeout)->tv_sec; (end)->tv_usec = (now)->tv_usec + (&timeout)->tv_usec; if ((end)->tv_usec >= 1000000) { ++(end)->tv_sec; (end)->tv_usec -= 1000000; } } while (0);
}

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

variable_types:
end
struct timeval *

variable_types: timeoutMs int

return_type: void


SocketRead

decompiled_code:
__int64 __fastcall SocketRead(int fd, __int64 a2, unsigned int a3, int a4)
{
__int64 v5; // rcx
signed __int64 v8; // rdi
void *v9; // rsp
struct mmsghdr *v10; // rbx
void *v11; // rsp
struct mmsghdr *v12; // rdx
void *v13; // rsp
__int64 v14; // rsi
struct mmsghdr *v15; // rax
struct mmsghdr *v16; // rcx
struct mmsghdr *v17; // rdi
int v18; // eax
unsigned int v19; // er14
__int64 v21; // r12
struct mmsghdr *v22; // r13
struct cmsghdr *i; // rsi
int v24; // eax
__int64 v25; // rdx
struct mmsghdr v26; // [rsp+0h] [rbp-60h] BYREF

v5 = 7LL * a3;
v8 = (unsigned __int64)a3 << 6;
*(_QWORD *)&v26.msg_hdr.msg_namelen = a2;
v9 = alloca(v8);
v10 = &v26;
v11 = alloca(16LL * a3);
v12 = &v26;
v13 = alloca(8 * v5);
if ( a3 )
{
v14 = *(_QWORD *)&v26.msg_hdr.msg_namelen;
v15 = &v26;
v16 = &v26;
v17 = (struct mmsghdr *)((char *)&v26 + v8);
do
{
v15->msg_hdr.msg_iov = (struct iovec *)v12;
++v15;
v12 = (struct mmsghdr *)((char *)v12 + 16);
*(_QWORD *)&v12[-1].msg_hdr.msg_flags = v14;
v14 += 29LL;
v15[-1].msg_hdr.msg_control = v16;
v16 = (struct mmsghdr *)((char *)v16 + 56);
v15[-1].msg_hdr.msg_name = 0LL;
v15[-1].msg_hdr.msg_namelen = 0;
*(_QWORD *)&v12[-1].msg_len = 16LL;
v15[-1].msg_hdr.msg_iovlen = 1LL;
v15[-1].msg_hdr.msg_controllen = 56LL;
v15[-1].msg_hdr.msg_flags = 0;
}
while ( v15 != v17 );
}
initTimers((struct timeval *)&v26.msg_hdr.msg_iov, (__time_t *)&v26.msg_hdr.msg_control, a4);
while ( 1 )
{
if ( v26.msg_hdr.msg_iov == v26.msg_hdr.msg_control )
{
if ( (__int64)v26.msg_hdr.msg_iovlen >= (__int64)v26.msg_hdr.msg_controllen )
return 0;
}
else if ( (__int64)v26.msg_hdr.msg_iov >= (__int64)v26.msg_hdr.msg_control )
{
return 0;
}
v18 = recvmmsg(fd, &v26, a3, 64, 0LL);
v19 = v18;
if ( v18 >= 0 )
break;
v19 = *_errno_location();
if ( v19 != 11 )
return v19;
gettimeofday((struct timeval *)&v26.msg_hdr.msg_iov, 0LL);
}
if ( !v18 )
return 0;
v21 = *(_QWORD *)&v26.msg_hdr.msg_namelen + 16LL;
v22 = &v26 + (unsigned __int64)(unsigned int)(v18 - 1) + 1;
do
{
if ( v10->msg_hdr.msg_controllen > 0xF )
{
for ( i = (struct cmsghdr *)v10->msg_hdr.msg_control; i; i = _cmsg_nxthdr(&v10->msg_hdr, i) )
{
if ( i->cmsg_level != 1 )
break;
v24 = i->cmsg_type;
if ( v24 == 29 )
{
v25 = *(_QWORD *)i->__cmsg_data;
*(_DWORD *)(v21 + 4) = *(_QWORD *)&i->__cmsg_data[8];
*(_DWORD *)v21 = v25;
}
else if ( v24 == 40 )
{
*(_DWORD *)(v21 + 9) = *(_DWORD *)i->__cmsg_data;
}
}
}
if ( (v10->msg_hdr.msg_flags & 0x800) != 0 )
*(_BYTE *)(v21 + 8) |= 1u;
++v10;
v21 += 29LL;
}
while ( v22 != v10 );
return v19;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2, unsigned int a3, int a4)
{
__int64 v5; // rcx
signed __int64 v8; // rdi
void *v9; // rsp
struct mmsghdr *v10; // rbx
void *v11; // rsp
struct mmsghdr *v12; // rdx
void *v13; // rsp
__int64 v14; // rsi
struct mmsghdr *v15; // rax
struct mmsghdr *v16; // rcx
struct mmsghdr *v17; // rdi
int v18; // eax
unsigned int v19; // er14
__int64 v21; // r12
struct mmsghdr *v22; // r13
struct cmsghdr *i; // rsi
int v24; // eax
__int64 v25; // rdx
struct mmsghdr v26; // [rsp+0h] [rbp-60h] BYREF

v5 = 7LL * a3;
v8 = (unsigned __int64)a3 << 6;
*(_QWORD *)&v26.msg_hdr.msg_namelen = a2;
v9 = alloca(v8);
v10 = &v26;
v11 = alloca(16LL * a3);
v12 = &v26;
v13 = alloca(8 * v5);
if ( a3 )
{
v14 = *(_QWORD *)&v26.msg_hdr.msg_namelen;
v15 = &v26;
v16 = &v26;
v17 = (struct mmsghdr *)((char *)&v26 + v8);
do
{
v15->msg_hdr.msg_iov = (struct iovec *)v12;
++v15;
v12 = (struct mmsghdr *)((char *)v12 + 16);
*(_QWORD *)&v12[-1].msg_hdr.msg_flags = v14;
v14 += 29LL;
v15[-1].msg_hdr.msg_control = v16;
v16 = (struct mmsghdr *)((char *)v16 + 56);
v15[-1].msg_hdr.msg_name = 0LL;
v15[-1].msg_hdr.msg_namelen = 0;
*(_QWORD *)&v12[-1].msg_len = 16LL;
v15[-1].msg_hdr.msg_iovlen = 1LL;
v15[-1].msg_hdr.msg_controllen = 56LL;
v15[-1].msg_hdr.msg_flags = 0;
}
while ( v15 != v17 );
}
func2((struct timeval *)&v26.msg_hdr.msg_iov, (__time_t *)&v26.msg_hdr.msg_control, a4);
while ( 1 )
{
if ( v26.msg_hdr.msg_iov == v26.msg_hdr.msg_control )
{
if ( (__int64)v26.msg_hdr.msg_iovlen >= (__int64)v26.msg_hdr.msg_controllen )
return 0;
}
else if ( (__int64)v26.msg_hdr.msg_iov >= (__int64)v26.msg_hdr.msg_control )
{
return 0;
}
v18 = recvmmsg(fd, &v26, a3, 64, 0LL);
v19 = v18;
if ( v18 >= 0 )
break;
v19 = *_errno_location();
if ( v19 != 11 )
return v19;
gettimeofday((struct timeval *)&v26.msg_hdr.msg_iov, 0LL);
}
if ( !v18 )
return 0;
v21 = *(_QWORD *)&v26.msg_hdr.msg_namelen + 16LL;
v22 = &v26 + (unsigned __int64)(unsigned int)(v18 - 1) + 1;
do
{
if ( v10->msg_hdr.msg_controllen > 0xF )
{
for ( i = (struct cmsghdr *)v10->msg_hdr.msg_control; i; i = _cmsg_nxthdr(&v10->msg_hdr, i) )
{
if ( i->cmsg_level != 1 )
break;
v24 = i->cmsg_type;
if ( v24 == 29 )
{
v25 = *(_QWORD *)i->__cmsg_data;
*(_DWORD *)(v21 + 4) = *(_QWORD *)&i->__cmsg_data[8];
*(_DWORD *)v21 = v25;
}
else if ( v24 == 40 )
{
*(_DWORD *)(v21 + 9) = *(_DWORD *)i->__cmsg_data;
}
}
}
if ( (v10->msg_hdr.msg_flags & 0x800) != 0 )
*(_BYTE *)(v21 + 8) |= 1u;
++v10;
v21 += 29LL;
}
while ( v22 != v10 );
return v19;
}

original_code:
int SocketRead (int Socket, struct FrameBag *Bags, unsigned int BagsCount, int TimeoutMs)
{
    struct mmsghdr msgs[BagsCount];
    struct iovec iovs[BagsCount];
    char ctrlmsgs[BagsCount][(((((sizeof(struct timeval)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))) + ((((sizeof(__u32)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))))];
    unsigned int i;
    for (i = 0; i < BagsCount; i++)
    {
        msgs[i].msg_hdr.msg_name = ((void *)0);
        msgs[i].msg_hdr.msg_namelen = 0;
        iovs[i].iov_base = (void *) &Bags[i];
        iovs[i].iov_len = sizeof(struct can_frame);
        msgs[i].msg_hdr.msg_iov = &iovs[i];
        msgs[i].msg_hdr.msg_iovlen = 1;
        msgs[i].msg_hdr.msg_control = &ctrlmsgs[i];
        msgs[i].msg_hdr.msg_controllen = sizeof(ctrlmsgs[0]);
        msgs[i].msg_hdr.msg_flags = 0;
    }
    struct timeval tNow, tEnd;
    for ( initTimers(&tNow, &tEnd, TimeoutMs); (((&tNow)->tv_sec == (&tEnd)->tv_sec) ? ((&tNow)->tv_usec < (&tEnd)->tv_usec) : ((&tNow)->tv_sec < (&tEnd)->tv_sec)); gettimeofday (&tNow, ((void *)0)) )
    {
        int rcount;
        rcount = recvmmsg(Socket, msgs, BagsCount, MSG_DONTWAIT, ((void *)0));
        if (rcount >= 0)
        {
            for (i = 0; i < rcount; i ++)
            {
                struct timeval tv;
                struct cmsghdr *cmsg;
                for (cmsg = ((size_t) (&msgs[i].msg_hdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msgs[i].msg_hdr)->msg_control : (struct cmsghdr *) 0);
                    cmsg && (cmsg->cmsg_level == 1);
                    cmsg = __cmsg_nxthdr (&msgs[i].msg_hdr, cmsg))
                {
                    if (cmsg->cmsg_type == 29)
                    {
                      tv = *(struct timeval *)((cmsg)->__cmsg_data);
                      Bags[i].TimeStamp.seconds = tv.tv_sec;
                      Bags[i].TimeStamp.microseconds = tv.tv_usec;
                    }
                    else if (cmsg->cmsg_type == 40)
                      Bags[i].DroppedMessagesCount = *(__u32 *)((cmsg)->__cmsg_data);
                }
                if (msgs[i].msg_hdr.msg_flags & MSG_CONFIRM)
                    Bags[i].Flags |= (1 << 0);
            }
            return rcount;
        }
        else
        {
            int errsv = (*__errno_location ());
            if (errsv == 11)
                continue;
            else
                return errsv;
        }
    }
    return 0;
}

canonical_original_code:
int SocketRead(int Socket, struct FrameBag *Bags, unsigned int BagsCount, int TimeoutMs)
{
    struct mmsghdr msgs[-1];
    struct iovec iovs[-1];
    char ctrlmsgs[-1][-1];
    unsigned int i;
    for (i = 0; i < BagsCount; i++)
    {
        msgs[i].msg_hdr.msg_name = ((void *)0);
        msgs[i].msg_hdr.msg_namelen = 0;
        iovs[i].iov_base = (void *) &Bags[i];
        iovs[i].iov_len = sizeof(struct can_frame);
        msgs[i].msg_hdr.msg_iov = &iovs[i];
        msgs[i].msg_hdr.msg_iovlen = 1;
        msgs[i].msg_hdr.msg_control = &ctrlmsgs[i];
        msgs[i].msg_hdr.msg_controllen = sizeof(ctrlmsgs[0]);
        msgs[i].msg_hdr.msg_flags = 0;
    }
    struct timeval tNow; struct timeval tEnd;
    for ( initTimers(&tNow, &tEnd, TimeoutMs); (((&tNow)->tv_sec == (&tEnd)->tv_sec) ? ((&tNow)->tv_usec < (&tEnd)->tv_usec) : ((&tNow)->tv_sec < (&tEnd)->tv_sec)); gettimeofday (&tNow, ((void *)0)) )
    {
        int rcount;
        rcount = recvmmsg(Socket, msgs, BagsCount, MSG_DONTWAIT, ((void *)0));
        if (rcount >= 0)
        {
            for (i = 0; i < rcount; i ++)
            {
                struct timeval tv;
                struct cmsghdr *cmsg;
                for (cmsg = ((unsigned long) (&msgs[i].msg_hdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msgs[i].msg_hdr)->msg_control : (struct cmsghdr *) 0);
                    cmsg && (cmsg->cmsg_level == 1);
                    cmsg = __cmsg_nxthdr (&msgs[i].msg_hdr, cmsg))
                {
                    if (cmsg->cmsg_type == 29)
                    {
                      tv = *(struct timeval *)((cmsg)->__cmsg_data);
                      Bags[i].TimeStamp.seconds = tv.tv_sec;
                      Bags[i].TimeStamp.microseconds = tv.tv_usec;
                    }
                    else if (cmsg->cmsg_type == 40)
                      Bags[i].DroppedMessagesCount = *(unsigned int *)((cmsg)->__cmsg_data);
                }
                if (msgs[i].msg_hdr.msg_flags & MSG_CONFIRM)
                    Bags[i].Flags |= (1 << 0);
            }
            return rcount;
        }
        else
        {
            int errsv = (*__errno_location ());
            if (errsv == 11)
                continue;
            else
                return errsv;
        }
    }
    return 0;
}

variable_types: Socket int

variable_types: struct FrameBag { struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; } Frame; struct TimeVal { unsigned int seconds; unsigned int microseconds; } TimeStamp; unsigned char Flags; unsigned int DroppedMessagesCount; } *

variable_types:
BagsCount
unsigned int

variable_types: TimeoutMs int

variable_types: struct mmsghdr { struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } msg_hdr; unsigned int msg_len; } [-1]

variable_types: struct iovec { void *iov_base; unsigned long iov_len; } [-1]

variable_types:
ctrlmsgs
char [-1][-1]

variable_types:
i
unsigned int

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

variable_types: rcount int

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: errsv int

return_type: int

user_defined_types: struct FrameBag { struct can_frame Frame; struct TimeVal TimeStamp; unsigned char Flags; unsigned int DroppedMessagesCount; }

user_defined_types: struct mmsghdr { struct msghdr msg_hdr; unsigned int msg_len; }

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


SocketWrite

decompiled_code:
int __fastcall SocketWrite(int fd, __int64 a2, int a3)
{
__int64 v3; // r8
__int64 v4; // rdx
unsigned int v5; // er13
void *v6; // rsp
void *v7; // rsp
struct mmsghdr *v8; // rax
struct mmsghdr *v9; // rdx
int result; // eax
struct mmsghdr v11; // [rsp+0h] [rbp-40h] BYREF

v3 = a3;
v4 = (__int64)a3 << 6;
v5 = v3;
*(_QWORD *)&v11.msg_hdr.msg_namelen = 16 * v3;
v6 = alloca(v4);
v7 = alloca(16 * v3);
memset(&v11, 0, v4);
memset(&v11, 0, *(size_t *)&v11.msg_hdr.msg_namelen);
if ( v5 )
{
v8 = &v11;
v9 = &v11;
do
{
v8->msg_hdr.msg_iov = (struct iovec *)v9;
++v8;
v9 = (struct mmsghdr *)((char *)v9 + 16);
*(_QWORD *)&v9[-1].msg_hdr.msg_flags = a2;
a2 += 16LL;
v8[-1].msg_hdr.msg_name = 0LL;
v8[-1].msg_hdr.msg_namelen = 0;
*(_QWORD *)&v9[-1].msg_len = 16LL;
v8[-1].msg_hdr.msg_iovlen = 1LL;
}
while ( v8 != &v11 + v5 );
}
result = sendmmsg(fd, &v11, v5, 0);
if ( result < 0 )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int __fastcall func4(int fd, __int64 a2, int a3)
{
__int64 v3; // r8
__int64 v4; // rdx
unsigned int v5; // er13
void *v6; // rsp
void *v7; // rsp
struct mmsghdr *v8; // rax
struct mmsghdr *v9; // rdx
int result; // eax
struct mmsghdr v11; // [rsp+0h] [rbp-40h] BYREF

v3 = a3;
v4 = (__int64)a3 << 6;
v5 = v3;
*(_QWORD *)&v11.msg_hdr.msg_namelen = 16 * v3;
v6 = alloca(v4);
v7 = alloca(16 * v3);
memset(&v11, 0, v4);
memset(&v11, 0, *(size_t *)&v11.msg_hdr.msg_namelen);
if ( v5 )
{
v8 = &v11;
v9 = &v11;
do
{
v8->msg_hdr.msg_iov = (struct iovec *)v9;
++v8;
v9 = (struct mmsghdr *)((char *)v9 + 16);
*(_QWORD *)&v9[-1].msg_hdr.msg_flags = a2;
a2 += 16LL;
v8[-1].msg_hdr.msg_name = 0LL;
v8[-1].msg_hdr.msg_namelen = 0;
*(_QWORD *)&v9[-1].msg_len = 16LL;
v8[-1].msg_hdr.msg_iovlen = 1LL;
}
while ( v8 != &v11 + v5 );
}
result = sendmmsg(fd, &v11, v5, 0);
if ( result < 0 )
result = -*_errno_location();
return result;
}

original_code:
int SocketWrite (int Socket, struct can_frame *Frame, int FramesCount)
{
  struct mmsghdr msgs[FramesCount];
  struct iovec iovs[FramesCount];
  memset (msgs, 0, sizeof (msgs));
  memset (iovs, 0, sizeof (iovs));
  unsigned int i;
  for (i = 0; i < FramesCount; i++) {
    msgs[i].msg_hdr.msg_name = ((void *)0);;
    msgs[i].msg_hdr.msg_namelen = 0;
    iovs[i].iov_base = (void *) &Frame[i];
    iovs[i].iov_len = sizeof(struct can_frame);
    msgs[i].msg_hdr.msg_iov = &iovs[i];
    msgs[i].msg_hdr.msg_iovlen = 1;
  }
  int scount;
  scount = sendmmsg(Socket, msgs, FramesCount, 0);
  if ( scount < 0 )
  {
    int errsv = (*__errno_location ());
    return -errsv;
  }
  else
  {
    return scount;
  }
}

canonical_original_code:
int SocketWrite(int Socket, struct can_frame *Frame, int FramesCount)
{
  struct mmsghdr msgs[-1];
  struct iovec iovs[-1];
  memset (msgs, 0, sizeof (msgs));
  memset (iovs, 0, sizeof (iovs));
  unsigned int i;
  for (i = 0; i < FramesCount; i++) {
    msgs[i].msg_hdr.msg_name = ((void *)0);;
    msgs[i].msg_hdr.msg_namelen = 0;
    iovs[i].iov_base = (void *) &Frame[i];
    iovs[i].iov_len = sizeof(struct can_frame);
    msgs[i].msg_hdr.msg_iov = &iovs[i];
    msgs[i].msg_hdr.msg_iovlen = 1;
  }
  int scount;
  scount = sendmmsg(Socket, msgs, FramesCount, 0);
  if ( scount < 0 )
  {
    int errsv = (*__errno_location ());
    return -errsv;
  }
  else
  {
    return scount;
  }
}

variable_types: struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; } *

variable_types: FramesCount int

variable_types: scount int

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


SocketFlushInBuffer

decompiled_code:
__int64 __fastcall SocketFlushInBuffer(int fd)
{
__int64 result; // rax
_BYTE savedregs[328]; // [rsp+0h] [rbp+0h] BYREF

do
result = SocketRead(fd, (__int64)savedregs, 0xAu, 1);
while ( (int)result > 0 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
__int64 result; // rax
_BYTE savedregs[328]; // [rsp+0h] [rbp+0h] BYREF

do
result = func3(fd, (__int64)savedregs, 0xAu, 1);
while ( (int)result > 0 );
return result;
}

original_code:
int SocketFlushInBuffer (int Socket)
{
  struct FrameBag bags[10];
  int lost = 1;
  while (lost)
  {
    lost = SocketRead (Socket, bags, 10, 1);
    if (lost < 0)
      return lost;
  }
  return 0;
}

canonical_original_code:
int SocketFlushInBuffer(int Socket)
{
  struct FrameBag bags[10];
  int lost = 1;
  while (lost)
  {
    lost = SocketRead (Socket, bags, 10, 1);
    if (lost < 0)
      return lost;
  }
  return 0;
}

variable_types: struct FrameBag { struct can_frame { unsigned int can_id; unsigned char can_dlc; unsigned char __pad; unsigned char __res0; unsigned char __res1; unsigned char data[8]; } Frame; struct TimeVal { unsigned int seconds; unsigned int microseconds; } TimeStamp; unsigned char Flags; unsigned int DroppedMessagesCount; } [10]

variable_types: lost int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int v4; // [rsp+4h] [rbp-14h] BYREF
unsigned int v5; // [rsp+8h] [rbp-10h] BYREF
unsigned int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
{
while ( (unsigned int)getDate("Geben Sie bitte ein gueltiges Datum ein: ", &v4, &v5, v6) )
{
printf("Das Datum %02i.%02i.%04i ist gueltig!\n", v4, v5, v6[0]);
result = askAgain();
if ( !result )
return result;
}
puts("Das eingegebene Datum ist ungueltig!");
result = askAgain();
}
while ( result );
return result;
}

original_code:
int main()
{
 int D,M,Y;
 do
 {
  if (getDate("Geben Sie bitte ein gueltiges Datum ein: ", &D, &M, &Y))
   printf("Das Datum %02i.%02i.%04i ist gueltig!\n", D, M, Y);
  else
   printf("Das eingegebene Datum ist ungueltig!\n");
 } while (askAgain());
 return 0;
}

canonical_original_code:
int main()
{
 int D; int M; int Y;
 do
 {
  if (getDate("Geben Sie bitte ein gueltiges Datum ein: ", &D, &M, &Y))
   printf("Das Datum %02i.%02i.%04i ist gueltig!\n", D, M, Y);
  else
   printf("Das eingegebene Datum ist ungueltig!\n");
 } while (askAgain());
 return 0;
}

variable_types: D int

variable_types: M int

variable_types: Y int


clearBuffer

decompiled_code:
__int64 clearBuffer()
{
__int64 result; // rax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

do
result = _isoc99_scanf(&unk_B4, v1);
while ( v1[0] != 10 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
char v1[9]; // [rsp+Fh] [rbp-9h] BYREF

do
result = _isoc99_scanf(&unk_B4, v1);
while ( v1[0] != 10 );
return result;
}

original_code:
void clearBuffer()
{
 char Dummy;
 do
 {
  scanf("%c", &Dummy);
 } while (Dummy != '\n');
}

variable_types: Dummy char


askAgain

decompiled_code:
__int64 askAgain()
{
int v0; // eax
int v1; // ebx
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
while ( 1 )
{
while ( 1 )
{
printf(format);
v0 = _isoc99_scanf(&unk_B4, v3);
v1 = v0;
if ( v3[0] != 10 )
break;
if ( !v0 )
LABEL_11:
printf("Sie haben nicht j oder n eingegeben");
}
clearBuffer();
if ( !v1 )
goto LABEL_11;
if ( v3[0] == 78 )
return 0LL;
if ( v3[0] <= 78 )
break;
if ( v3[0] == 106 )
return 1LL;
if ( v3[0] == 110 )
return 0LL;
}
}
while ( v3[0] != 74 );
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax
int v1; // ebx
char v3[9]; // [rsp+Fh] [rbp-9h] BYREF

do
{
while ( 1 )
{
while ( 1 )
{
printf(format);
v0 = _isoc99_scanf(&unk_B4, v3);
v1 = v0;
if ( v3[0] != 10 )
break;
if ( !v0 )
LABEL_11:
printf("Sie haben nicht j oder n eingegeben");
}
func0();
if ( !v1 )
goto LABEL_11;
if ( v3[0] == 78 )
return 0LL;
if ( v3[0] <= 78 )
break;
if ( v3[0] == 106 )
return 1LL;
if ( v3[0] == 110 )
return 0LL;
}
}
while ( v3[0] != 74 );
return 1LL;
}

original_code:
int askAgain()
{
 int weiter;
 int auswahlGetroffen;
 char eingabe;
 do
 {
  printf("Möchten Sie noch einmal j/n ");
  auswahlGetroffen = scanf("%c", &eingabe);
  if( eingabe!='\n')
  {
   clearBuffer();
  }
  if(!auswahlGetroffen)
  {
   printf("Sie haben nicht j oder n eingegeben");
  }
  else
  {
   switch (eingabe)
   {
    case 'j':
    case 'J':
        weiter = 1; break;
    case 'n':
    case 'N':
        weiter = 0; break;
    default:
     auswahlGetroffen = 0;
   }
  }
 } while (!auswahlGetroffen);
 return weiter;
}

variable_types: weiter int

variable_types: auswahlGetroffen int

variable_types: eingabe char


decompiled_code:
void __fastcall read_from_file(int fd, void *buf, size_t nbytes, __off_t offset)
{
unsigned int v4; // ebx

if ( fd != -1 )
{
v4 = nbytes;
lseek(fd, (unsigned int)offset, 0);
if ( (unsigned int)read(fd, buf, v4) == -1 )
{
perror("READ");
exit(1);
}
}
}

canonical_decompiled_code:
void __fastcall func0(int fd, void *buf, size_t nbytes, __off_t offset)
{
unsigned int v4; // ebx

if ( fd != -1 )
{
v4 = nbytes;
lseek(fd, (unsigned int)offset, 0);
if ( (unsigned int)read(fd, buf, v4) == -1 )
{
perror("READ");
exit(1);
}
}
}

original_code:
void read_from_file(int fdes, unsigned char *buffer, unsigned int bytes_to_read, unsigned int start) {
 int nr=0;
 if(fdes!=-1) {
  lseek(fdes,start,0);
  if((nr = read(fdes,buffer,bytes_to_read))==-1) {
   perror("READ");
   exit(1);
  }
 }
}

canonical_original_code:
void read_from_file(int fdes, unsigned char *buffer, unsigned int bytes_to_read, unsigned int start) {
 int nr = 0;
 if(fdes!=-1) {
  lseek(fdes,start,0);
  if((nr = read(fdes,buffer,bytes_to_read))==-1) {
   perror("READ");
   exit(1);
  }
 }
}

variable_types: fdes int

variable_types:
buffer
unsigned char *

variable_types:
start
unsigned int

variable_types: nr int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebp
_DWORD v7[130]; // [rsp+0h] [rbp-208h] BYREF

v3 = "sd_128mb.img";
if ( argc > 1 )
v3 = argv[1];
printf("filename: %s\n", v3);
v4 = open(v3, 1052672);
v5 = v4;
if ( v4 == -1 )
{
perror("Open");
exit(1);
}
read_from_file(v4, v7, 0x10uLL, 446LL);
print_partition(v7);
read_from_file(v5, v7, 0x200uLL, (unsigned int)(v7[2] << 9));
puts("--- FAT ---");
dump_eboot_F32(v7);
if ( close(v5) == -1 )
{
perror("Close");
exit(1);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // ebp
_DWORD v7[130]; // [rsp+0h] [rbp-208h] BYREF

v3 = "sd_128mb.img";
if ( argc > 1 )
v3 = argv[1];
printf("filename: %s\n", v3);
v4 = open(v3, 1052672);
v5 = v4;
if ( v4 == -1 )
{
perror("Open");
exit(1);
}
func0(v4, v7, 0x10uLL, 446LL);
print_partition(v7);
func0(v5, v7, 0x200uLL, (unsigned int)(v7[2] << 9));
puts("--- FAT ---");
dump_eboot_F32(v7);
if ( close(v5) == -1 )
{
perror("Close");
exit(1);
}
return 0;
}

original_code:
int main(int argc, char** argv) {
 char* filename = "sd_128mb.img";
 unsigned char buffer[512];
 if(argc>=2) {
  filename=argv[1];
 }
 printf("filename: %s\n",filename);
 int ddes=-1, pos=-1, ret=0;
 if((ddes=open(filename, 00 | 04010000))==-1) {
  perror("Open");
  exit(1);
 }
 read_from_file(ddes,buffer,sizeof(struct partitionInfo_t),0x1be);
 struct partitionInfo_t* partition = (struct partitionInfo_t*)buffer;
 print_partition(partition);
 int relative_sector = ((partition->firstSector)*512);
 read_from_file(ddes,buffer,sizeof(struct eboot_param_block_F32_t),relative_sector);
 printf("--- FAT ---\n");
 struct eboot_param_block_F32_t* ebpb = (struct eboot_param_block_F32_t*)buffer;
 dump_eboot_F32(ebpb);
 ret=close(ddes);
 if(ret==-1) {
  perror("Close");
  exit(1);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 char *filename = "sd_128mb.img";
 unsigned char buffer[512];
 if(argc>=2) {
  filename=argv[1];
 }
 printf("filename: %s\n",filename);
 int ddes = -1; int pos = -1; int ret = 0;
 if((ddes=open(filename, 00 | 04010000))==-1) {
  perror("Open");
  exit(1);
 }
 read_from_file(ddes,buffer,sizeof(struct partitionInfo_t),0x1be);
 struct partitionInfo_t *partition = (struct partitionInfo_t*)buffer;
 print_partition(partition);
 int relative_sector = ((partition->firstSector)*512);
 read_from_file(ddes,buffer,sizeof(struct eboot_param_block_F32_t),relative_sector);
 printf("--- FAT ---\n");
 struct eboot_param_block_F32_t *ebpb = (struct eboot_param_block_F32_t*)buffer;
 dump_eboot_F32(ebpb);
 ret=close(ddes);
 if(ret==-1) {
  perror("Close");
  exit(1);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
filename
char *

variable_types:
buffer
unsigned char [512]

variable_types: ddes int

variable_types: pos int

variable_types: ret int

variable_types: struct partitionInfo_t { unsigned char status; unsigned char headStart; unsigned short cylSectStart; unsigned char type; unsigned char headEnd; unsigned short cylSectEnd; unsigned int firstSector; unsigned int sectorsTotal; } *

variable_types: struct eboot_param_block_F32_t { unsigned char jumpBoot[3]; char OEMName[8]; unsigned short bytesPerSector; unsigned char sectorPerCluster; unsigned short reservedSectorCount; unsigned char numberofFATs; unsigned short rootEntryCount; unsigned short totalSectors_F16; unsigned char mediaType; unsigned short FATsize_F16; short sectorsPerTrack; unsigned short numberofHeads; unsigned int hiddenSectors; unsigned int totalSectors_F32; unsigned int FATsize_F32; unsigned short extFlags; unsigned short FSversion; unsigned int rootCluster; unsigned short FSinfo; unsigned short BackupBootSector; unsigned char reserved[12]; unsigned char driveNumber; unsigned char reserved1; unsigned char bootSignature; unsigned int volumeID; char volumeLabel[11]; char fileSystemType[8]; unsigned char bootData[420]; unsigned short bootEndSignature; } *


decompiled_code:
int __fastcall print_hex_bytes(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
if ( (i & 0xF) == 0 )
printf("\n\t");
v4 = *(unsigned __int8 *)(a1 + i);
result = printf("%02x ", v4);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
if ( (i & 0xF) == 0 )
printf("\n\t");
v4 = *(unsigned __int8 *)(a1 + i);
result = printf("%02x ", v4);
}
}
return result;
}

original_code:
void print_hex_bytes(unsigned char* data,int numBytes) {
 int i=0;
 for(i=0; i<numBytes;i++) {
  if(i%16==0) printf("\n\t");
  printf("%02x ",data[i]);
 }
}

canonical_original_code:
void print_hex_bytes(unsigned char *data, int numBytes) {
 int i = 0;
 for(i=0; i<numBytes;i++) {
  if(i%16==0) printf("\n\t");
  printf("%02x ",data[i]);
 }
}

variable_types:
data
unsigned char *

variable_types: numBytes int

variable_types: i int


decompiled_code:
int __fastcall print_char_bytes(char *a1, int a2)
{
__int64 v2; // rbp
char *v3; // rbx
int v4; // edi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
putchar(v4);
}
while ( v3 != (char *)v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, int a2)
{
__int64 v2; // rbp
char *v3; // rbx
int v4; // edi

if ( a2 > 0 )
{
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = a1;
do
{
v4 = *v3++;
putchar(v4);
}
while ( v3 != (char *)v2 );
}
return putchar(10);
}

original_code:
void print_char_bytes(char* data, int numBytes) {
 int i=0;
 for(i=0; i<numBytes;i++) {
  printf("%c",(char)data[i]);
 }
 printf("\n");
}

canonical_original_code:
void print_char_bytes(char *data, int numBytes) {
 int i = 0;
 for(i=0; i<numBytes;i++) {
  printf("%c",(char)data[i]);
 }
 printf("\n");
}

variable_types:
data
char *


decompiled_code:
int __fastcall print_partition(__int64 a1)
{
const char *v1; // rsi
unsigned __int16 v2; // bp
unsigned __int16 v3; // bp

if ( !*(_DWORD *)(a1 + 12) || !*(_BYTE *)(a1 + 4) )
return puts("This is not an initialized partition");
v1 = "True";
if ( *(_BYTE *)a1 != 0x80 )
v1 = "False";
printf("Bootflag: %s\n", v1);
printf("Starting Head: %d\n", *(unsigned __int8 *)(a1 + 1));
v2 = *(_WORD *)(a1 + 2);
printf("Starting Sector: %d\n", v2 >> 10);
printf("Starting Cylinder: %d\n", v2 & 0x3FF);
printf("System ID: %02x\n", *(unsigned __int8 *)(a1 + 4));
printf("Ending Head: %d\n", *(unsigned __int8 *)(a1 + 5));
v3 = *(_WORD *)(a1 + 6);
printf("Ending Sector: %d\n", v3 >> 10);
printf("Ending Cylinder: %d\n", v3 & 0x3FF);
printf("Relative Sector: %d\n", *(unsigned int *)(a1 + 8));
return printf("Total sectors: %d\n", *(unsigned int *)(a1 + 12));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
const char *v1; // rsi
unsigned __int16 v2; // bp
unsigned __int16 v3; // bp

if ( !*(_DWORD *)(a1 + 12) || !*(_BYTE *)(a1 + 4) )
return puts("This is not an initialized partition");
v1 = "True";
if ( *(_BYTE *)a1 != 0x80 )
v1 = "False";
printf("Bootflag: %s\n", v1);
printf("Starting Head: %d\n", *(unsigned __int8 *)(a1 + 1));
v2 = *(_WORD *)(a1 + 2);
printf("Starting Sector: %d\n", v2 >> 10);
printf("Starting Cylinder: %d\n", v2 & 0x3FF);
printf("System ID: %02x\n", *(unsigned __int8 *)(a1 + 4));
printf("Ending Head: %d\n", *(unsigned __int8 *)(a1 + 5));
v3 = *(_WORD *)(a1 + 6);
printf("Ending Sector: %d\n", v3 >> 10);
printf("Ending Cylinder: %d\n", v3 & 0x3FF);
printf("Relative Sector: %d\n", *(unsigned int *)(a1 + 8));
return printf("Total sectors: %d\n", *(unsigned int *)(a1 + 12));
}

original_code:
void print_partition(struct partitionInfo_t* table) {
 if(table->sectorsTotal<=0 || table->type==0) {
  printf("This is not an initialized partition\n");
 } else {
  printf("Bootflag: %s\n",table->status==0x80?"True":"False");
  printf("Starting Head: %d\n",table->headStart);
  int start_sect = ((table->cylSectStart)>>10)&0x3F;
  int start_cyl = (table->cylSectStart)&0x3FF;
  printf("Starting Sector: %d\n",start_sect);
  printf("Starting Cylinder: %d\n",start_cyl);
  printf("System ID: %02x\n",table->type);
  printf("Ending Head: %d\n",table->headEnd);
  int end_sect = ((table->cylSectEnd)>>10)&0x3F;
  int end_cyl = (table->cylSectEnd)&0x3FF;
  printf("Ending Sector: %d\n",end_sect);
  printf("Ending Cylinder: %d\n",end_cyl);
  printf("Relative Sector: %d\n",table->firstSector);
  printf("Total sectors: %d\n",table->sectorsTotal);
 }
}

canonical_original_code:
void print_partition(struct partitionInfo_t *table) {
 if(table->sectorsTotal<=0 || table->type==0) {
  printf("This is not an initialized partition\n");
 } else {
  printf("Bootflag: %s\n",table->status==0x80?"True":"False");
  printf("Starting Head: %d\n",table->headStart);
  int start_sect = ((table->cylSectStart)>>10)&0x3F;
  int start_cyl = (table->cylSectStart)&0x3FF;
  printf("Starting Sector: %d\n",start_sect);
  printf("Starting Cylinder: %d\n",start_cyl);
  printf("System ID: %02x\n",table->type);
  printf("Ending Head: %d\n",table->headEnd);
  int end_sect = ((table->cylSectEnd)>>10)&0x3F;
  int end_cyl = (table->cylSectEnd)&0x3FF;
  printf("Ending Sector: %d\n",end_sect);
  printf("Ending Cylinder: %d\n",end_cyl);
  printf("Relative Sector: %d\n",table->firstSector);
  printf("Total sectors: %d\n",table->sectorsTotal);
 }
}

user_defined_types: struct partitionInfo_t { unsigned char status; unsigned char headStart; unsigned short cylSectStart; unsigned char type; unsigned char headEnd; unsigned short cylSectEnd; unsigned int firstSector; unsigned int sectorsTotal; }


decompiled_code:
int __fastcall dump_eboot_F16(__int64 a1)
{
printf("Jump Assembly: ");
print_hex_bytes(a1, 3);
putchar(10);
printf("OEM Identifier: %s\n", (const char *)(a1 + 3));
printf("Bytes per sector: %d\n", *(unsigned __int16 *)(a1 + 11));
printf("Sectors per cluster: %d\n", *(unsigned __int8 *)(a1 + 13));
printf("Reserved sectors: %d\n", *(unsigned __int16 *)(a1 + 14));
printf("Number of FAT tables: %d\n", *(unsigned __int8 *)(a1 + 16));
printf("Number of Directory entries: %d\n", *(unsigned __int16 *)(a1 + 17));
printf("Total sectors (F16): %d\n", *(unsigned __int16 *)(a1 + 19));
printf("Media Descriptor: %02x\n", *(unsigned __int8 *)(a1 + 21));
printf("Sectors per FAT (F16): %d\n", *(unsigned __int16 *)(a1 + 22));
printf("Sectors per track: %d\n", (unsigned int)*(__int16 *)(a1 + 24));
printf("Head count: %d\n", *(unsigned __int16 *)(a1 + 26));
printf("Hidden sectors: %d\n", *(unsigned int *)(a1 + 28));
printf("Total Sectors (F32): %d\n", *(unsigned int *)(a1 + 32));
printf("Drive Number: %d\n", *(unsigned __int8 *)(a1 + 36));
printf("Boot Signature: %02X\n", *(unsigned __int8 *)(a1 + 38));
printf("Volume ID: %d\n", *(unsigned int *)(a1 + 39));
printf("Volume Label: ");
print_char_bytes((char *)(a1 + 43), 11);
putchar(10);
printf("Filesystem Type: ");
print_char_bytes((char *)(a1 + 54), 8);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
printf("Jump Assembly: ");
func0(a1, 3);
putchar(10);
printf("OEM Identifier: %s\n", (const char *)(a1 + 3));
printf("Bytes per sector: %d\n", *(unsigned __int16 *)(a1 + 11));
printf("Sectors per cluster: %d\n", *(unsigned __int8 *)(a1 + 13));
printf("Reserved sectors: %d\n", *(unsigned __int16 *)(a1 + 14));
printf("Number of FAT tables: %d\n", *(unsigned __int8 *)(a1 + 16));
printf("Number of Directory entries: %d\n", *(unsigned __int16 *)(a1 + 17));
printf("Total sectors (F16): %d\n", *(unsigned __int16 *)(a1 + 19));
printf("Media Descriptor: %02x\n", *(unsigned __int8 *)(a1 + 21));
printf("Sectors per FAT (F16): %d\n", *(unsigned __int16 *)(a1 + 22));
printf("Sectors per track: %d\n", (unsigned int)*(__int16 *)(a1 + 24));
printf("Head count: %d\n", *(unsigned __int16 *)(a1 + 26));
printf("Hidden sectors: %d\n", *(unsigned int *)(a1 + 28));
printf("Total Sectors (F32): %d\n", *(unsigned int *)(a1 + 32));
printf("Drive Number: %d\n", *(unsigned __int8 *)(a1 + 36));
printf("Boot Signature: %02X\n", *(unsigned __int8 *)(a1 + 38));
printf("Volume ID: %d\n", *(unsigned int *)(a1 + 39));
printf("Volume Label: ");
func1((char *)(a1 + 43), 11);
putchar(10);
printf("Filesystem Type: ");
func1((char *)(a1 + 54), 8);
return putchar(10);
}

original_code:
void dump_eboot_F16(struct eboot_param_block_F16_t* block) {
 printf("Jump Assembly: ");
 print_hex_bytes(block->jumpBoot,3);
 printf("\n");
 printf("OEM Identifier: %s\n",block->OEMName);
 printf("Bytes per sector: %d\n",block->bytesPerSector);
 printf("Sectors per cluster: %d\n",block->sectorPerCluster);
 printf("Reserved sectors: %d\n",block->reservedSectorCount);
 printf("Number of FAT tables: %d\n",block->numberofFATs);
 printf("Number of Directory entries: %d\n",block->rootEntryCount);
 printf("Total sectors (F16): %d\n",block->totalSectors_F16);
 printf("Media Descriptor: %02x\n",block->mediaType);
 printf("Sectors per FAT (F16): %d\n",block->FATsize_F16);
 printf("Sectors per track: %d\n",block->sectorsPerTrack);
 printf("Head count: %d\n",block->numberofHeads);
 printf("Hidden sectors: %d\n", block->hiddenSectors);
 printf("Total Sectors (F32): %d\n", block->totalSectors_F32);
 printf("Drive Number: %d\n", block->driveNumber);
 printf("Boot Signature: %02X\n",block->bootSignature);
 printf("Volume ID: %d\n",block->volumeID);
 printf("Volume Label: ");
 print_char_bytes(block->volumeLabel,11);
 printf("\n");
 printf("Filesystem Type: ");
 print_char_bytes(block->fileSystemType,8);
 printf("\n");
}

canonical_original_code:
void dump_eboot_F16(struct eboot_param_block_F16_t *block) {
 printf("Jump Assembly: ");
 print_hex_bytes(block->jumpBoot,3);
 printf("\n");
 printf("OEM Identifier: %s\n",block->OEMName);
 printf("Bytes per sector: %d\n",block->bytesPerSector);
 printf("Sectors per cluster: %d\n",block->sectorPerCluster);
 printf("Reserved sectors: %d\n",block->reservedSectorCount);
 printf("Number of FAT tables: %d\n",block->numberofFATs);
 printf("Number of Directory entries: %d\n",block->rootEntryCount);
 printf("Total sectors (F16): %d\n",block->totalSectors_F16);
 printf("Media Descriptor: %02x\n",block->mediaType);
 printf("Sectors per FAT (F16): %d\n",block->FATsize_F16);
 printf("Sectors per track: %d\n",block->sectorsPerTrack);
 printf("Head count: %d\n",block->numberofHeads);
 printf("Hidden sectors: %d\n", block->hiddenSectors);
 printf("Total Sectors (F32): %d\n", block->totalSectors_F32);
 printf("Drive Number: %d\n", block->driveNumber);
 printf("Boot Signature: %02X\n",block->bootSignature);
 printf("Volume ID: %d\n",block->volumeID);
 printf("Volume Label: ");
 print_char_bytes(block->volumeLabel,11);
 printf("\n");
 printf("Filesystem Type: ");
 print_char_bytes(block->fileSystemType,8);
 printf("\n");
}

variable_types: struct eboot_param_block_F16_t { unsigned char jumpBoot[3]; char OEMName[8]; unsigned short bytesPerSector; unsigned char sectorPerCluster; unsigned short reservedSectorCount; unsigned char numberofFATs; unsigned short rootEntryCount; unsigned short totalSectors_F16; unsigned char mediaType; unsigned short FATsize_F16; short sectorsPerTrack; unsigned short numberofHeads; unsigned int hiddenSectors; unsigned int totalSectors_F32; unsigned char driveNumber; unsigned char reserved; unsigned char bootSignature; unsigned int volumeID; char volumeLabel[11]; char fileSystemType[8]; unsigned char bootData[448]; unsigned short bootEndSignature; } *


decompiled_code:
int __fastcall dump_eboot_F32(__int64 a1)
{
printf("Jump Assembly: ");
print_hex_bytes(a1, 3);
putchar(10);
printf("OEM Identifier: %s\n", (const char *)(a1 + 3));
printf("Bytes per sector: %d\n", *(unsigned __int16 *)(a1 + 11));
printf("Sectors per cluster: %d\n", *(unsigned __int8 *)(a1 + 13));
printf("Reserved sectors: %d\n", *(unsigned __int16 *)(a1 + 14));
printf("Number of FAT tables: %d\n", *(unsigned __int8 *)(a1 + 16));
printf("Number of Directory entries: %d\n", *(unsigned __int16 *)(a1 + 17));
printf("Total sectors (F16): %d\n", *(unsigned __int16 *)(a1 + 19));
printf("Media Descriptor: %02x\n", *(unsigned __int8 *)(a1 + 21));
printf("Sectors per FAT (F16): %d\n", *(unsigned __int16 *)(a1 + 22));
printf("Sectors per track: %d\n", (unsigned int)*(__int16 *)(a1 + 24));
printf("Head count: %d\n", *(unsigned __int16 *)(a1 + 26));
printf("Hidden sectors: %d\n", *(unsigned int *)(a1 + 28));
printf("Total Sectors (F32): %d\n", *(unsigned int *)(a1 + 32));
printf("Sectors per FAT (F32): %d\n", *(unsigned int *)(a1 + 36));
printf("Flags: %d\n", *(unsigned __int16 *)(a1 + 40));
printf("FAT Version Number: %d\n", *(unsigned __int16 *)(a1 + 42));
printf("Root directory cluster: %d\n", *(unsigned int *)(a1 + 44));
printf("FileSystem Info cluster: %d\n", *(unsigned __int16 *)(a1 + 48));
printf("Backup BootSector cluster: %d\n", *(unsigned __int16 *)(a1 + 50));
printf("Reserved: ");
print_hex_bytes(a1 + 52, 12);
putchar(10);
printf("Drive Number: %d\n", *(unsigned __int8 *)(a1 + 64));
printf("Reserved: %d\n", *(unsigned __int8 *)(a1 + 65));
printf("Boot Signature: %02X\n", *(unsigned __int8 *)(a1 + 66));
printf("Volume ID: %d\n", *(unsigned int *)(a1 + 67));
printf("Volume Label: ");
print_char_bytes((char *)(a1 + 71), 11);
printf("Filesystem Type: ");
return print_char_bytes((char *)(a1 + 82), 8);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
printf("Jump Assembly: ");
func0(a1, 3);
putchar(10);
printf("OEM Identifier: %s\n", (const char *)(a1 + 3));
printf("Bytes per sector: %d\n", *(unsigned __int16 *)(a1 + 11));
printf("Sectors per cluster: %d\n", *(unsigned __int8 *)(a1 + 13));
printf("Reserved sectors: %d\n", *(unsigned __int16 *)(a1 + 14));
printf("Number of FAT tables: %d\n", *(unsigned __int8 *)(a1 + 16));
printf("Number of Directory entries: %d\n", *(unsigned __int16 *)(a1 + 17));
printf("Total sectors (F16): %d\n", *(unsigned __int16 *)(a1 + 19));
printf("Media Descriptor: %02x\n", *(unsigned __int8 *)(a1 + 21));
printf("Sectors per FAT (F16): %d\n", *(unsigned __int16 *)(a1 + 22));
printf("Sectors per track: %d\n", (unsigned int)*(__int16 *)(a1 + 24));
printf("Head count: %d\n", *(unsigned __int16 *)(a1 + 26));
printf("Hidden sectors: %d\n", *(unsigned int *)(a1 + 28));
printf("Total Sectors (F32): %d\n", *(unsigned int *)(a1 + 32));
printf("Sectors per FAT (F32): %d\n", *(unsigned int *)(a1 + 36));
printf("Flags: %d\n", *(unsigned __int16 *)(a1 + 40));
printf("FAT Version Number: %d\n", *(unsigned __int16 *)(a1 + 42));
printf("Root directory cluster: %d\n", *(unsigned int *)(a1 + 44));
printf("FileSystem Info cluster: %d\n", *(unsigned __int16 *)(a1 + 48));
printf("Backup BootSector cluster: %d\n", *(unsigned __int16 *)(a1 + 50));
printf("Reserved: ");
func0(a1 + 52, 12);
putchar(10);
printf("Drive Number: %d\n", *(unsigned __int8 *)(a1 + 64));
printf("Reserved: %d\n", *(unsigned __int8 *)(a1 + 65));
printf("Boot Signature: %02X\n", *(unsigned __int8 *)(a1 + 66));
printf("Volume ID: %d\n", *(unsigned int *)(a1 + 67));
printf("Volume Label: ");
func1((char *)(a1 + 71), 11);
printf("Filesystem Type: ");
return func1((char *)(a1 + 82), 8);
}

original_code:
void dump_eboot_F32(struct eboot_param_block_F32_t* block) {
 printf("Jump Assembly: ");
 print_hex_bytes(block->jumpBoot,3);
 printf("\n");
 printf("OEM Identifier: %s\n",block->OEMName);
 printf("Bytes per sector: %d\n",block->bytesPerSector);
 printf("Sectors per cluster: %d\n",block->sectorPerCluster);
 printf("Reserved sectors: %d\n",block->reservedSectorCount);
 printf("Number of FAT tables: %d\n",block->numberofFATs);
 printf("Number of Directory entries: %d\n",block->rootEntryCount);
 printf("Total sectors (F16): %d\n",block->totalSectors_F16);
 printf("Media Descriptor: %02x\n",block->mediaType);
 printf("Sectors per FAT (F16): %d\n",block->FATsize_F16);
 printf("Sectors per track: %d\n",block->sectorsPerTrack);
 printf("Head count: %d\n",block->numberofHeads);
 printf("Hidden sectors: %d\n", block->hiddenSectors);
 printf("Total Sectors (F32): %d\n", block->totalSectors_F32);
 printf("Sectors per FAT (F32): %d\n", block->FATsize_F32);
 printf("Flags: %d\n", block->extFlags);
 printf("FAT Version Number: %d\n", block->FSversion);
 printf("Root directory cluster: %d\n",block->rootCluster);
 printf("FileSystem Info cluster: %d\n",block->FSinfo);
 printf("Backup BootSector cluster: %d\n",block->BackupBootSector);
 printf("Reserved: ");
 print_hex_bytes(block->reserved,12);
 printf("\n");
 printf("Drive Number: %d\n",block->driveNumber);
 printf("Reserved: %d\n", block->reserved1);
 printf("Boot Signature: %02X\n", block->bootSignature);
 printf("Volume ID: %d\n", block->volumeID);
 printf("Volume Label: ");
 print_char_bytes(block->volumeLabel,11);
 printf("Filesystem Type: ");
 print_char_bytes(block->fileSystemType,8);
}

canonical_original_code:
void dump_eboot_F32(struct eboot_param_block_F32_t *block) {
 printf("Jump Assembly: ");
 print_hex_bytes(block->jumpBoot,3);
 printf("\n");
 printf("OEM Identifier: %s\n",block->OEMName);
 printf("Bytes per sector: %d\n",block->bytesPerSector);
 printf("Sectors per cluster: %d\n",block->sectorPerCluster);
 printf("Reserved sectors: %d\n",block->reservedSectorCount);
 printf("Number of FAT tables: %d\n",block->numberofFATs);
 printf("Number of Directory entries: %d\n",block->rootEntryCount);
 printf("Total sectors (F16): %d\n",block->totalSectors_F16);
 printf("Media Descriptor: %02x\n",block->mediaType);
 printf("Sectors per FAT (F16): %d\n",block->FATsize_F16);
 printf("Sectors per track: %d\n",block->sectorsPerTrack);
 printf("Head count: %d\n",block->numberofHeads);
 printf("Hidden sectors: %d\n", block->hiddenSectors);
 printf("Total Sectors (F32): %d\n", block->totalSectors_F32);
 printf("Sectors per FAT (F32): %d\n", block->FATsize_F32);
 printf("Flags: %d\n", block->extFlags);
 printf("FAT Version Number: %d\n", block->FSversion);
 printf("Root directory cluster: %d\n",block->rootCluster);
 printf("FileSystem Info cluster: %d\n",block->FSinfo);
 printf("Backup BootSector cluster: %d\n",block->BackupBootSector);
 printf("Reserved: ");
 print_hex_bytes(block->reserved,12);
 printf("\n");
 printf("Drive Number: %d\n",block->driveNumber);
 printf("Reserved: %d\n", block->reserved1);
 printf("Boot Signature: %02X\n", block->bootSignature);
 printf("Volume ID: %d\n", block->volumeID);
 printf("Volume Label: ");
 print_char_bytes(block->volumeLabel,11);
 printf("Filesystem Type: ");
 print_char_bytes(block->fileSystemType,8);
}

user_defined_types: struct eboot_param_block_F32_t { unsigned char jumpBoot[3]; char OEMName[8]; unsigned short bytesPerSector; unsigned char sectorPerCluster; unsigned short reservedSectorCount; unsigned char numberofFATs; unsigned short rootEntryCount; unsigned short totalSectors_F16; unsigned char mediaType; unsigned short FATsize_F16; short sectorsPerTrack; unsigned short numberofHeads; unsigned int hiddenSectors; unsigned int totalSectors_F32; unsigned int FATsize_F32; unsigned short extFlags; unsigned short FSversion; unsigned int rootCluster; unsigned short FSinfo; unsigned short BackupBootSector; unsigned char reserved[12]; unsigned char driveNumber; unsigned char reserved1; unsigned char bootSignature; unsigned int volumeID; char volumeLabel[11]; char fileSystemType[8]; unsigned char bootData[420]; unsigned short bootEndSignature; }


repo: OHamm/IGOsat

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

v1 = 63;
do
result = printf("%d", (a1 >> v1) & 1);
while ( v1-- != 0 );
return result;
}

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

v1 = 63;
do
result = printf("%d", (a1 >> v1) & 1);
while ( v1-- != 0 );
return result;
}

original_code:
void print_long_long_int_bin(long long int n) {
 int i;
 for(i=0; i<64; i++)
  printf("%d", (int) (n >> (63 - i)) & 1);
}

canonical_original_code:
void print_long_long_int_bin(long long n) {
 int i;
 for(i=0; i<64; i++)
  printf("%d", (int) (n >> (63 - i)) & 1);
}

variable_types:
n
long long


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

v1 = 7;
do
result = printf("%d", (a1 >> v1) & 1);
while ( v1-- != 0 );
return result;
}

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

v1 = 7;
do
result = printf("%d", (a1 >> v1) & 1);
while ( v1-- != 0 );
return result;
}

original_code:
void print_char(char c) {
 int i;
 for(i=0; i<8; i++) printf("%d", (c >> (7-i)) & 1);
}

variable_types: c char


decompiled_code:
int __fastcall print_chars(__int64 a1, int a2)
{
char *v2; // rbx
__int64 v3; // rbp
char v4; // di
int result; // eax

if ( a2 > 0 )
{
v2 = (char *)(a1 + a2 - 1);
v3 = a1 + a2 - 2 - (unsigned int)(a2 - 1);
do
{
v4 = *v2--;
result = print_char(v4);
}
while ( v2 != (char *)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, int a2)
{
char *v2; // rbx
__int64 v3; // rbp
char v4; // di
int result; // eax

if ( a2 > 0 )
{
v2 = (char *)(a1 + a2 - 1);
v3 = a1 + a2 - 2 - (unsigned int)(a2 - 1);
do
{
v4 = *v2--;
result = func14(v4);
}
while ( v2 != (char *)v3 );
}
return result;
}

original_code:
void print_chars(char* str, int l) {
 int i;
 for(i=0; i<l; i++) print_char(str[l-1-i]);
}

canonical_original_code:
void print_chars(char *str, int l) {
 int i;
 for(i=0; i<l; i++) print_char(str[l-1-i]);
}

variable_types:
str
char *

variable_types: l int


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

switch ( a3 )
{
case 0:
result = a2;
break;
case 1:
result = a2 & 0x7F | a1 & 0xFFFFFF80;
break;
case 2:
result = a2 & 0x3F | a1 & 0xFFFFFFC0;
break;
case 3:
result = a2 & 0x1F | a1 & 0xFFFFFFE0;
break;
case 4:
result = a2 & 0xF | a1 & 0xFFFFFFF0;
break;
case 5:
result = a2 & 7 | a1 & 0xFFFFFFF8;
break;
case 6:
result = a2 & 3 | a1 & 0xFFFFFFFC;
break;
case 7:
result = a2 & 1 | a1 & 0xFFFFFFFE;
break;
case 8:
result = a1;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a3 )
{
case 0:
result = a2;
break;
case 1:
result = a2 & 0x7F | a1 & 0xFFFFFF80;
break;
case 2:
result = a2 & 0x3F | a1 & 0xFFFFFFC0;
break;
case 3:
result = a2 & 0x1F | a1 & 0xFFFFFFE0;
break;
case 4:
result = a2 & 0xF | a1 & 0xFFFFFFF0;
break;
case 5:
result = a2 & 7 | a1 & 0xFFFFFFF8;
break;
case 6:
result = a2 & 3 | a1 & 0xFFFFFFFC;
break;
case 7:
result = a2 & 1 | a1 & 0xFFFFFFFE;
break;
case 8:
result = a1;
break;
default:
result = 0LL;
break;
}
return result;
}

variable_types: first char

variable_types: second char

return_type: char


variable_types:
capteurs
int *

variable_types:
retour
int *


decompiled_code:
__int64 global_init()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 result; // rax

set_players();
v0 = ((__int64 (__fastcall *)(__int64))io_func[2])(7LL);
set_player_name(0LL, v0);
v1 = ((__int64 (__fastcall *)(__int64))io_func[2])(8LL);
set_player_name(1LL, v1);
result = io_func[0]();
if ( (_BYTE)result )
exit(2);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 result; // rax

set_players();
v0 = ((__int64 (__fastcall *)(__int64))io_func[2])(7LL);
set_player_name(0LL, v0);
v1 = ((__int64 (__fastcall *)(__int64))io_func[2])(8LL);
set_player_name(1LL, v1);
result = io_func[0]();
if ( (_BYTE)result )
exit(2);
return result;
}

original_code:
static void global_init() {
   set_players();
   set_player_name(0, io_func.get_code_str(DEFAULT_PLAYER_NAME1));
   set_player_name(1, io_func.get_code_str(DEFAULT_PLAYER_NAME2));
   if (io_func.init_io())
      exit(2);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
char *v4; // rax
_QWORD *v5; // r12
size_t v6; // r13
char *v7; // rbp
char *v8; // rbx
void (*v9)(void); // rax
void (*v10)(void); // rax
__int64 v11; // rbp
char v12; // bl
unsigned __int8 v13; // al
char v14; // al
bool v15; // bp
void (*v16)(void); // rax
void (*v17)(void); // rax
__int64 v18; // rbx
void *v19; // rdi
char v21; // bl
char v22; // al
const char *v23; // rdi
__int64 (*v24)(void); // rbx
__int64 v25; // rax
void (*v26)(void); // rax
void (*v27)(void); // rax
__int64 v28; // rsi
unsigned __int8 v29; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned __int8 v30; // [rsp+Dh] [rbp-2Bh]
char v31[42]; // [rsp+Eh] [rbp-2Ah] BYREF

global_init(argc, argv, envp);
if ( (unsigned __int8)is_error() )
exit(1);
if ( (unsigned __int8)show_start_menu() == 4 )
{
if ( !(unsigned __int8)is_error() )
goto LABEL_32;
v5 = 0LL;
}
else
{
((__int64 (__fastcall **)(unsigned __int8 *))rule_func)[0](&v29);
v3 = v30;
v4 = (char *)calloc(v30, 8uLL);
v5 = v4;
if ( (_BYTE)v3 )
{
v6 = v29;
v7 = v4;
v8 = &v4[8 * v3];
do
{
v7 += 8;
*((_QWORD *)v7 - 1) = calloc(v6, 1uLL);
}
while ( v8 != v7 );
}
while ( 1 )
{
((__int64 (__fastcall **)(_QWORD *))rule_func)[1](v5);
v9 = *(void (**)(void))*g_player;
if ( v9 )
v9();
v10 = (void (*)(void))***((_QWORD ***)&g_player + 1);
if ( v10 )
v10();
((void (__fastcall *)(_QWORD *, unsigned __int8 *))io_func[4])(v5, &v29);
v11 = g_player;
v12 = is_error();
if ( v12 )
break;
while ( 1 )
{
do
{
while ( !(*(unsigned int (__fastcall **)(char *, __int64))(*(_QWORD *)v11 + 8LL))(v31, v11) )
{
if ( (unsigned __int8)is_error() )
goto LABEL_27;
v14 = show_context_menu();
if ( v14 )
{
v12 = 1;
v15 = v14 != 2;
goto LABEL_19;
}
((void (__fastcall *)(_QWORD *, unsigned __int8 *))io_func[4])(v5, &v29);
}
}
while ( !((unsigned __int8 (__fastcall *)(bool, char *))rule_func[3])(g_player != v11, v31) );
((void (__fastcall *)(_QWORD *, unsigned __int8 *))io_func[4])(v5, &v29);
v13 = ((__int64 (*)(void))rule_func[4])();
if ( v13 != 3 )
break;
if ( (unsigned __int8)is_error() )
goto LABEL_27;
v11 = *((_QWORD *)&g_player + (g_player == v11));
}
v28 = v11;
v15 = 1;
((void (__fastcall *)(_QWORD, __int64))io_func[5])(v13, v28);
LABEL_19:
v16 = *(void (**)(void))(*g_player + 16LL);
if ( v16 )
v16();
v17 = *(void (**)(void))(**((_QWORD **)&g_player + 1) + 16LL);
if ( v17 )
v17();
if ( (unsigned __int8)is_error() )
break;
if ( !v12 )
{
v21 = show_finish_menu();
v22 = is_error();
if ( v21 == 4 || v22 )
break;
if ( v21 == 2 )
goto LABEL_26;
}
if ( !v15 )
{
LABEL_26:
if ( (unsigned __int8)show_start_menu() == 4 )
break;
}
}
LABEL_27:
if ( !(unsigned __int8)is_error() )
goto LABEL_28;
}
v23 = (const char *)get_error();
if ( !strncmp(v23, "quit", 5uLL) )
{
clear_error();
}
else
{
v24 = io_func[8];
v25 = get_error();
((void (__fastcall *)(__int64))v24)(v25);
}
v26 = *(void (**)(void))(*g_player + 16LL);
if ( v26 )
v26();
v27 = *(void (**)(void))(**((_QWORD **)&g_player + 1) + 16LL);
if ( v27 )
v27();
LABEL_28:
if ( v5 )
{
v18 = 0LL;
if ( v30 )
{
do
{
v19 = (void *)v5[v18++];
free(v19);
}
while ( v30 > (int)v18 );
}
free(v5);
}
LABEL_32:
io_func[1]();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r14
char *v4; // rax
_QWORD *v5; // r12
size_t v6; // r13
char *v7; // rbp
char *v8; // rbx
void (*v9)(void); // rax
void (*v10)(void); // rax
__int64 v11; // rbp
char v12; // bl
unsigned __int8 v13; // al
char v14; // al
bool v15; // bp
void (*v16)(void); // rax
void (*v17)(void); // rax
__int64 v18; // rbx
void *v19; // rdi
char v21; // bl
char v22; // al
const char *v23; // rdi
__int64 (*v24)(void); // rbx
__int64 v25; // rax
void (*v26)(void); // rax
void (*v27)(void); // rax
__int64 v28; // rsi
unsigned __int8 v29; // [rsp+Ch] [rbp-2Ch] BYREF
unsigned __int8 v30; // [rsp+Dh] [rbp-2Bh]
char v31[42]; // [rsp+Eh] [rbp-2Ah] BYREF

func0(argc, argv, envp);
if ( (unsigned __int8)is_error() )
exit(1);
if ( (unsigned __int8)show_start_menu() == 4 )
{
if ( !(unsigned __int8)is_error() )
goto LABEL_32;
v5 = 0LL;
}
else
{
((__int64 (__fastcall **)(unsigned __int8 *))rule_func)[0](&v29);
v3 = v30;
v4 = (char *)calloc(v30, 8uLL);
v5 = v4;
if ( (_BYTE)v3 )
{
v6 = v29;
v7 = v4;
v8 = &v4[8 * v3];
do
{
v7 += 8;
*((_QWORD *)v7 - 1) = calloc(v6, 1uLL);
}
while ( v8 != v7 );
}
while ( 1 )
{
((__int64 (__fastcall **)(_QWORD *))rule_func)[1](v5);
v9 = *(void (**)(void))*g_player;
if ( v9 )
v9();
v10 = (void (*)(void))***((_QWORD ***)&g_player + 1);
if ( v10 )
v10();
((void (__fastcall *)(_QWORD *, unsigned __int8 *))io_func[4])(v5, &v29);
v11 = g_player;
v12 = is_error();
if ( v12 )
break;
while ( 1 )
{
do
{
while ( !(*(unsigned int (__fastcall **)(char *, __int64))(*(_QWORD *)v11 + 8LL))(v31, v11) )
{
if ( (unsigned __int8)is_error() )
goto LABEL_27;
v14 = show_context_menu();
if ( v14 )
{
v12 = 1;
v15 = v14 != 2;
goto LABEL_19;
}
((void (__fastcall *)(_QWORD *, unsigned __int8 *))io_func[4])(v5, &v29);
}
}
while ( !((unsigned __int8 (__fastcall *)(bool, char *))rule_func[3])(g_player != v11, v31) );
((void (__fastcall *)(_QWORD *, unsigned __int8 *))io_func[4])(v5, &v29);
v13 = ((__int64 (*)(void))rule_func[4])();
if ( v13 != 3 )
break;
if ( (unsigned __int8)is_error() )
goto LABEL_27;
v11 = *((_QWORD *)&g_player + (g_player == v11));
}
v28 = v11;
v15 = 1;
((void (__fastcall *)(_QWORD, __int64))io_func[5])(v13, v28);
LABEL_19:
v16 = *(void (**)(void))(*g_player + 16LL);
if ( v16 )
v16();
v17 = *(void (**)(void))(**((_QWORD **)&g_player + 1) + 16LL);
if ( v17 )
v17();
if ( (unsigned __int8)is_error() )
break;
if ( !v12 )
{
v21 = show_finish_menu();
v22 = is_error();
if ( v21 == 4 || v22 )
break;
if ( v21 == 2 )
goto LABEL_26;
}
if ( !v15 )
{
LABEL_26:
if ( (unsigned __int8)show_start_menu() == 4 )
break;
}
}
LABEL_27:
if ( !(unsigned __int8)is_error() )
goto LABEL_28;
}
v23 = (const char *)get_error();
if ( !strncmp(v23, "quit", 5uLL) )
{
clear_error();
}
else
{
v24 = io_func[8];
v25 = get_error();
((void (__fastcall *)(__int64))v24)(v25);
}
v26 = *(void (**)(void))(*g_player + 16LL);
if ( v26 )
v26();
v27 = *(void (**)(void))(**((_QWORD **)&g_player + 1) + 16LL);
if ( v27 )
v27();
LABEL_28:
if ( v5 )
{
v18 = 0LL;
if ( v30 )
{
do
{
v19 = (void *)v5[v18++];
free(v19);
}
while ( v30 > (int)v18 );
}
free(v5);
}
LABEL_32:
io_func[1]();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
   uint8_t **field = ((void *)0);
   point_t field_size, input;
   uint8_t state;
   player_ent_t *cur_player;
   uint8_t skip_finish_menu = 0, skip_start_menu = 1;
   global_init();
   if (is_error())
      exit(1);
   if (show_start_menu() == MC_EXIT)
      goto exit;
   rule_func.get_field_size(&field_size);
   field = (uint8_t **) calloc(field_size.y, sizeof(uint8_t *));
   for (int i = 0; i < field_size.y; i++)
      field[i] = (uint8_t *) calloc(field_size.x, sizeof(uint8_t));
   while (1) {
      if (!skip_start_menu && show_start_menu() == MC_EXIT)
         break;
      skip_start_menu = 1;
      rule_func.fill_field(field);
      if (g_player[0]->func_list->init_player)
         g_player[0]->func_list->init_player(g_player[0]);
      if (g_player[1]->func_list->init_player)
         g_player[1]->func_list->init_player(g_player[1]);
      io_func.show_field(field, &field_size);
      cur_player = g_player[0];
      if (is_error())
         goto exit;
      while(1) {
         if (!cur_player->func_list->get_player_input(&input, cur_player)) {
            if (is_error())
               goto exit;
            uint8_t choice = show_context_menu();
            if (choice == MC_CONTINUE_GAME) {
               io_func.show_field(field, &field_size);
               continue;
            }
            else {
               skip_finish_menu = 1;
               if (choice == MC_MAIN_MENU)
                  skip_start_menu = 0;
               break;
            }
            if (is_error())
               goto exit;
         }
         if (!rule_func.check_and_apply_move((cur_player == g_player[0] ? 0 : 1),
            (void *) &input)) {
            continue;
         }
         io_func.show_field(field, &field_size);
         state = rule_func.check_end_conditions();
         if (state != GS_ONGOING) {
            io_func.show_result(state, cur_player);
            break;
         }
         if (is_error())
            goto exit;
         cur_player = g_player[(cur_player == g_player[0] ? 1 : 0)];
      }
      if (g_player[0]->func_list->clear_data)
         g_player[0]->func_list->clear_data(g_player[0]);
      if (g_player[1]->func_list->clear_data)
         g_player[1]->func_list->clear_data(g_player[1]);
      if (is_error())
         goto exit;
      if (!skip_finish_menu) {
         uint8_t choice = show_finish_menu();
         if (is_error())
            goto exit;
         if (choice == MC_EXIT)
            break;
         if (choice == MC_MAIN_MENU)
            skip_start_menu = 0;
      }
      else
         skip_finish_menu = 0;
   }
exit:
   if (is_error()) {
      if (!strncmp(get_error(), "quit", 5))
         clear_error();
      else
         io_func.show_error(get_error());
      if (g_player[0]->func_list->clear_data)
         g_player[0]->func_list->clear_data(g_player[0]);
      if (g_player[1]->func_list->clear_data)
         g_player[1]->func_list->clear_data(g_player[1]);
   }
   if (field) {
      for (int i = 0; i < field_size.y; i++)
         free(field[i]);
      free(field);
   }
   io_func.clear_io();
}

canonical_original_code:
int main(int argc, char *argv[]) {
   unsigned char **field = ((void *)0);
   struct point_t field_size; struct point_t input;
   unsigned char state;
   struct player_ent_t *cur_player;
   unsigned char skip_finish_menu = 0; unsigned char skip_start_menu = 1;
   global_init();
   if (is_error())
      exit(1);
   if (show_start_menu() == MC_EXIT)
      goto exit;
   rule_func.get_field_size(&field_size);
   field = (unsigned char **) calloc(field_size.y, sizeof(unsigned char *));
   for (int i = 0; i < field_size.y; i++)
      field[i] = (unsigned char *) calloc(field_size.x, sizeof(unsigned char));
   while (1) {
      if (!skip_start_menu && show_start_menu() == MC_EXIT)
         break;
      skip_start_menu = 1;
      rule_func.fill_field(field);
      if (g_player[0]->func_list->init_player)
         g_player[0]->func_list->init_player(g_player[0]);
      if (g_player[1]->func_list->init_player)
         g_player[1]->func_list->init_player(g_player[1]);
      io_func.show_field(field, &field_size);
      cur_player = g_player[0];
      if (is_error())
         goto exit;
      while(1) {
         if (!cur_player->func_list->get_player_input(&input, cur_player)) {
            if (is_error())
               goto exit;
            unsigned char choice = show_context_menu();
            if (choice == MC_CONTINUE_GAME) {
               io_func.show_field(field, &field_size);
               continue;
            }
            else {
               skip_finish_menu = 1;
               if (choice == MC_MAIN_MENU)
                  skip_start_menu = 0;
               break;
            }
            if (is_error())
               goto exit;
         }
         if (!rule_func.check_and_apply_move((cur_player == g_player[0] ? 0 : 1),
            (void *) &input)) {
            continue;
         }
         io_func.show_field(field, &field_size);
         state = rule_func.check_end_conditions();
         if (state != GS_ONGOING) {
            io_func.show_result(state, cur_player);
            break;
         }
         if (is_error())
            goto exit;
         cur_player = g_player[(cur_player == g_player[0] ? 1 : 0)];
      }
      if (g_player[0]->func_list->clear_data)
         g_player[0]->func_list->clear_data(g_player[0]);
      if (g_player[1]->func_list->clear_data)
         g_player[1]->func_list->clear_data(g_player[1]);
      if (is_error())
         goto exit;
      if (!skip_finish_menu) {
         unsigned char choice = show_finish_menu();
         if (is_error())
            goto exit;
         if (choice == MC_EXIT)
            break;
         if (choice == MC_MAIN_MENU)
            skip_start_menu = 0;
      }
      else
         skip_finish_menu = 0;
   }
exit:
   if (is_error()) {
      if (!strncmp(get_error(), "quit", 5))
         clear_error();
      else
         io_func.show_error(get_error());
      if (g_player[0]->func_list->clear_data)
         g_player[0]->func_list->clear_data(g_player[0]);
      if (g_player[1]->func_list->clear_data)
         g_player[1]->func_list->clear_data(g_player[1]);
   }
   if (field) {
      for (int i = 0; i < field_size.y; i++)
         free(field[i]);
      free(field);
   }
   io_func.clear_io();
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
field
unsigned char **

variable_types:
state
unsigned char

variable_types: struct player_ent_t { struct player_func_list { void (*init_player)(struct player_ent_t *); int (*get_player_input)(struct point_t { unsigned char x; unsigned char y; } *, struct player_ent_t *); void (*clear_data)(struct player_ent_t *); } *func_list; char name[256]; void *player_ctx; } *

variable_types:
choice
unsigned char

user_defined_types: struct player_ent_t { struct player_func_list *func_list; char name[256]; void *player_ctx; }

user_defined_types: struct player_func_list { void (*init_player)(struct player_ent_t *); int (*get_player_input)(struct point_t *, struct player_ent_t *); void (*clear_data)(struct player_ent_t *); }


decompiled_code:
__int64 __fastcall check_horizontal(unsigned __int8 a1)
{
unsigned int v1; // er8
_BYTE *v2; // rax

v1 = 0;
v2 = *(_BYTE **)(main_field + 8LL * a1);
if ( *v2 == v2[1] )
LOBYTE(v1) = v2[2] == *v2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
unsigned int v1; // er8
_BYTE *v2; // rax

v1 = 0;
v2 = *(_BYTE **)(main_field + 8LL * a1);
if ( *v2 == v2[1] )
LOBYTE(v1) = v2[2] == *v2;
return v1;
}

original_code:
static uint8_t check_horizontal(uint8_t line) {
   return main_field[line][0] == main_field[line][1] &&
      main_field[line][0] == main_field[line][2];
}

canonical_original_code:
static unsigned char check_horizontal(unsigned char line) {
   return main_field[line][0] == main_field[line][1] &&
      main_field[line][0] == main_field[line][2];
}

variable_types:
line
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall check_vertical(unsigned __int8 a1)
{
unsigned int v1; // er8
unsigned __int8 v2; // dl

v1 = 0;
v2 = *(_BYTE *)(*(_QWORD *)main_field + a1);
if ( v2 == *(_BYTE *)(*(_QWORD *)(main_field + 8) + a1) )
LOBYTE(v1) = *(_BYTE *)(*(_QWORD *)(main_field + 16) + a1) == v2;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
unsigned int v1; // er8
unsigned __int8 v2; // dl

v1 = 0;
v2 = *(_BYTE *)(*(_QWORD *)main_field + a1);
if ( v2 == *(_BYTE *)(*(_QWORD *)(main_field + 8) + a1) )
LOBYTE(v1) = *(_BYTE *)(*(_QWORD *)(main_field + 16) + a1) == v2;
return v1;
}

original_code:
static uint8_t check_vertical(uint8_t col) {
   return main_field[0][col] == main_field[1][col] &&
      main_field[0][col] == main_field[2][col];
}

canonical_original_code:
static unsigned char check_vertical(unsigned char col) {
   return main_field[0][col] == main_field[1][col] &&
      main_field[0][col] == main_field[2][col];
}

variable_types:
col
unsigned char


decompiled_code:
bool __fastcall check_diagonal(char a1)
{
unsigned __int8 *v1; // rdx
char v2; // cl
unsigned __int8 v3; // dl
bool result; // al
unsigned __int8 v5; // dl

v1 = *(unsigned __int8 **)main_field;
v2 = *(_BYTE *)(*(_QWORD *)(main_field + 8) + 1LL);
if ( a1 )
{
v3 = *v1;
if ( v2 != v3 )
return 0;
result = *(_BYTE *)(*(_QWORD *)(main_field + 16) + 2LL) == v3;
}
else
{
v5 = v1[2];
if ( v2 != v5 )
return 0;
result = **(_BYTE **)(main_field + 16) == v5;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(char a1)
{
unsigned __int8 *v1; // rdx
char v2; // cl
unsigned __int8 v3; // dl
bool result; // al
unsigned __int8 v5; // dl

v1 = *(unsigned __int8 **)main_field;
v2 = *(_BYTE *)(*(_QWORD *)(main_field + 8) + 1LL);
if ( a1 )
{
v3 = *v1;
if ( v2 != v3 )
return 0;
result = *(_BYTE *)(*(_QWORD *)(main_field + 16) + 2LL) == v3;
}
else
{
v5 = v1[2];
if ( v2 != v5 )
return 0;
result = **(_BYTE **)(main_field + 16) == v5;
}
return result;
}

original_code:
static uint8_t check_diagonal(uint8_t main_diag) {
   return main_field[0][main_diag ? 0 : 2] == main_field[1][1] &&
      main_field[0][main_diag ? 0 : 2] == main_field[2][main_diag ? 2 : 0];
}

canonical_original_code:
static unsigned char check_diagonal(unsigned char main_diag) {
   return main_field[0][main_diag ? 0 : 2] == main_field[1][1] &&
      main_field[0][main_diag ? 0 : 2] == main_field[2][main_diag ? 2 : 0];
}


decompiled_code:
__int64 get_field()
{
return main_field;
}

canonical_decompiled_code:
__int64 func4()
{
return main_field;
}

original_code:
uint8_t **get_field() {
   return main_field;
}

canonical_original_code:
unsigned char **get_field() {
   return main_field;
}

return_type: unsigned char **


decompiled_code:
__int64 __fastcall check_and_apply_move(char a1, unsigned __int8 *a2)
{
__int64 v2; // rax
unsigned int v3; // er8
__int64 v4; // rdx
_BYTE *v5; // rax

v2 = *a2;
v3 = 0;
if ( (unsigned __int8)v2 <= 2u )
{
v4 = a2[1];
if ( (unsigned __int8)v4 <= 2u )
{
v5 = (_BYTE *)(*(_QWORD *)(main_field + 8 * v4) + v2);
if ( !*v5 )
{
v3 = 1;
*v5 = 1 - ((a1 == 0) - 1);
}
}
}
return v3;
}

original_code:
uint8_t check_and_apply_move(uint8_t turn, void *data) {
   point_t *move = (point_t *) data;
   if (move->x >= 3 || move->y >= 3) {
      return 0;
   }
   if (main_field[move->y][move->x] != EMPTY) {
      return 0;
   }
   main_field[move->y][move->x] = (turn == 0 ? CROSS : NOUGHT);
   return 1;
}

canonical_original_code:
unsigned char check_and_apply_move(unsigned char turn, void *data) {
   struct point_t *move = (point_t *) data;
   if (move->x >= 3 || move->y >= 3) {
      return 0;
   }
   if (main_field[move->y][move->x] != EMPTY) {
      return 0;
   }
   main_field[move->y][move->x] = (turn == 0 ? CROSS : NOUGHT);
   return 1;
}

variable_types:
turn
unsigned char

variable_types:
data
void *

variable_types: struct point_t { unsigned char x; unsigned char y; } *


decompiled_code:
char check_end_conditions()
{
__int64 v0; // r15
char v1; // r13
__int64 v2; // rbx
int v3; // ebp
char v4; // si
__int64 v5; // r9
int v7; // er10

v0 = 0LL;
v1 = 0;
LABEL_2:
v2 = 0LL;
v3 = 1;
v4 = **(_BYTE **)(main_field + 8 * v0);
if ( !v4 )
{
LABEL_9:
v1 = 1;
if ( v3 == 3 )
goto LABEL_10;
goto LABEL_7;
}
while ( 1 )
{
if ( (unsigned __int8)(v4 - 1) > 1u )
{
set_error("rule error: wrong sign", 22LL);
goto LABEL_6;
}
if ( !v0 )
break;
if ( !v2 )
{
if ( (unsigned __int8)check_horizontal(v0) )
return v4 != 1;
goto LABEL_8;
}
LABEL_6:
if ( v3 == 3 )
{
LABEL_10:
if ( ++v0 == 3 )
return v1 + 2;
goto LABEL_2;
}
LABEL_7:
v5 = *(_QWORD *)(main_field + 8 * v0);
LABEL_8:
++v2;
++v3;
v4 = *(_BYTE *)(v5 + v2);
if ( !v4 )
goto LABEL_9;
}
if ( (unsigned __int8)check_vertical(v2) )
return v4 != 1;
if ( v2 )
{
if ( v7 == 2 )
{
if ( check_diagonal(0) )
return v4 != 1;
goto LABEL_10;
}
goto LABEL_6;
}
if ( !(unsigned __int8)check_horizontal(0) && !check_diagonal(1) )
goto LABEL_8;
return v4 != 1;
}

canonical_decompiled_code:
char func6()
{
__int64 v0; // r15
char v1; // r13
__int64 v2; // rbx
int v3; // ebp
char v4; // si
__int64 v5; // r9
int v7; // er10

v0 = 0LL;
v1 = 0;
LABEL_2:
v2 = 0LL;
v3 = 1;
v4 = **(_BYTE **)(main_field + 8 * v0);
if ( !v4 )
{
LABEL_9:
v1 = 1;
if ( v3 == 3 )
goto LABEL_10;
goto LABEL_7;
}
while ( 1 )
{
if ( (unsigned __int8)(v4 - 1) > 1u )
{
set_error("rule error: wrong sign", 22LL);
goto LABEL_6;
}
if ( !v0 )
break;
if ( !v2 )
{
if ( (unsigned __int8)func0(v0) )
return v4 != 1;
goto LABEL_8;
}
LABEL_6:
if ( v3 == 3 )
{
LABEL_10:
if ( ++v0 == 3 )
return v1 + 2;
goto LABEL_2;
}
LABEL_7:
v5 = *(_QWORD *)(main_field + 8 * v0);
LABEL_8:
++v2;
++v3;
v4 = *(_BYTE *)(v5 + v2);
if ( !v4 )
goto LABEL_9;
}
if ( (unsigned __int8)func1(v2) )
return v4 != 1;
if ( v2 )
{
if ( v7 == 2 )
{
if ( func2(0) )
return v4 != 1;
goto LABEL_10;
}
goto LABEL_6;
}
if ( !(unsigned __int8)func0(0) && !func2(1) )
goto LABEL_8;
return v4 != 1;
}

original_code:
uint8_t check_end_conditions() {
   uint8_t is_empty = 0;
   for (int i = 0; i < 3; i++) {
      for ( int j = 0; j < 3; j++) {
         switch (main_field[i][j]) {
         case EMPTY:
            is_empty = 1;
            break;
         case CROSS:
         case NOUGHT:
            if ((i == 0 && check_vertical(j)) || (j == 0 &&
               check_horizontal(i)) || (i == 0 && (j == 0 || j == 2)
               && check_diagonal((j == 0)))) {
               return main_field[i][j] == CROSS ? GS_PLAYER1_VICTORY :
                  GS_PLAYER2_VICTORY;
            }
            break;
         default: set_error("rule error: wrong sign",
            strlen("rule error: wrong sign"));
         }
      }
   }
   return is_empty ? GS_ONGOING : GS_DRAW;
}

canonical_original_code:
unsigned char check_end_conditions() {
   unsigned char is_empty = 0;
   for (int i = 0; i < 3; i++) {
      for ( int j = 0; j < 3; j++) {
         switch (main_field[i][j]) {
         case EMPTY:
            is_empty = 1;
            break;
         case CROSS:
         case NOUGHT:
            if ((i == 0 && check_vertical(j)) || (j == 0 &&
               check_horizontal(i)) || (i == 0 && (j == 0 || j == 2)
               && check_diagonal((j == 0)))) {
               return main_field[i][j] == CROSS ? GS_PLAYER1_VICTORY :
                  GS_PLAYER2_VICTORY;
            }
            break;
         default: set_error("rule error: wrong sign",
            strlen("rule error: wrong sign"));
         }
      }
   }
   return is_empty ? GS_ONGOING : GS_DRAW;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 get_winning_cond()
{
_DWORD *v0; // r9
int v1; // esi
_DWORD *v2; // r9
char v3; // al
_BYTE *v4; // r9
char v5; // cl
__int64 result; // rax
char v7; // cl
_BYTE *v8; // r9

if ( check_diagonal(1) )
{
*v0 = 50528513;
result = 1LL;
}
else
{
v1 = 0;
if ( check_diagonal(0) )
{
*v2 = 16974593;
result = 1LL;
}
else
{
while ( 1 )
{
v3 = check_vertical(v1);
v5 = v1 + 1;
if ( v3 )
{
*v4 = 1;
result = 1LL;
v4[1] = v5;
v4[2] = 3;
v4[3] = v5;
return result;
}
result = check_horizontal(v1);
if ( (_BYTE)result )
break;
if ( ++v1 == 3 )
return result;
}
*v8 = v7;
result = 1LL;
v8[1] = 1;
v8[2] = v7;
v8[3] = 3;
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
_DWORD *v0; // r9
int v1; // esi
_DWORD *v2; // r9
char v3; // al
_BYTE *v4; // r9
char v5; // cl
__int64 result; // rax
char v7; // cl
_BYTE *v8; // r9

if ( func2(1) )
{
*v0 = 50528513;
result = 1LL;
}
else
{
v1 = 0;
if ( func2(0) )
{
*v2 = 16974593;
result = 1LL;
}
else
{
while ( 1 )
{
v3 = func1(v1);
v5 = v1 + 1;
if ( v3 )
{
*v4 = 1;
result = 1LL;
v4[1] = v5;
v4[2] = 3;
v4[3] = v5;
return result;
}
result = func0(v1);
if ( (_BYTE)result )
break;
if ( ++v1 == 3 )
return result;
}
*v8 = v7;
result = 1LL;
v8[1] = 1;
v8[2] = v7;
v8[3] = 3;
}
}
return result;
}

original_code:
uint8_t get_winning_cond(void *data) {
   winning_data_t *winning_data = (winning_data_t *) data;
   if (check_diagonal(1)) {
      winning_data->start_point.x = 1;
      winning_data->start_point.y = 1;
      winning_data->end_point.x = 3;
      winning_data->end_point.y = 3;
      return 1;
   }
   else if (check_diagonal(0)) {
      winning_data->start_point.x = 1;
      winning_data->start_point.y = 3;
      winning_data->end_point.x = 3;
      winning_data->end_point.y = 1;
      return 1;
   }
   else {
      for (uint8_t i = 0; i < 3; i++) {
         if (check_vertical(i)) {
            winning_data->start_point.x = 1;
            winning_data->start_point.y = i + 1;
            winning_data->end_point.x = 3;
            winning_data->end_point.y = i + 1;
            return 1;
         }
         if (check_horizontal(i)) {
            winning_data->start_point.x = i + 1;
            winning_data->start_point.y = 1;
            winning_data->end_point.x = i + 1;
            winning_data->end_point.y = 3;
            return 1;
         }
      }
   }
   return 0;
}

canonical_original_code:
unsigned char get_winning_cond(void *data) {
   struct winning_data_t *winning_data = (winning_data_t *) data;
   if (check_diagonal(1)) {
      winning_data->start_point.x = 1;
      winning_data->start_point.y = 1;
      winning_data->end_point.x = 3;
      winning_data->end_point.y = 3;
      return 1;
   }
   else if (check_diagonal(0)) {
      winning_data->start_point.x = 1;
      winning_data->start_point.y = 3;
      winning_data->end_point.x = 3;
      winning_data->end_point.y = 1;
      return 1;
   }
   else {
      for (unsigned char i = 0; i < 3; i++) {
         if (check_vertical(i)) {
            winning_data->start_point.x = 1;
            winning_data->start_point.y = i + 1;
            winning_data->end_point.x = 3;
            winning_data->end_point.y = i + 1;
            return 1;
         }
         if (check_horizontal(i)) {
            winning_data->start_point.x = i + 1;
            winning_data->start_point.y = 1;
            winning_data->end_point.x = i + 1;
            winning_data->end_point.y = 3;
            return 1;
         }
      }
   }
   return 0;
}

variable_types: struct winning_data_t { struct point_t { unsigned char x; unsigned char y; } start_point; struct point_t end_point; } *

variable_types:
i
unsigned char

user_defined_types: struct winning_data_t { struct point_t start_point; struct point_t end_point; }


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

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

original_code:
uint8_t simple_start_game(menu_item_t const *ctx) {
   return MC_START_NEW_GAME;
}

canonical_original_code:
unsigned char simple_start_game(struct menu_item *ctx) {
   return MC_START_NEW_GAME;
}

variable_types: struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 } type; unsigned char (*action)(struct menu_item *); void *data; } *

user_defined_types: struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t type; unsigned char (*action)(struct menu_item *); void *data; }


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

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

original_code:
uint8_t continue_game(menu_item_t const *ctx) {
   return MC_CONTINUE_GAME;
}

canonical_original_code:
unsigned char continue_game(struct menu_item *ctx) {
   return MC_CONTINUE_GAME;
}

user_defined_types: enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 }


decompiled_code:
__int64 show_main_menu()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 2LL;
}

original_code:
uint8_t show_main_menu(menu_item_t const *ctx) {
   return MC_MAIN_MENU;
}

canonical_original_code:
unsigned char show_main_menu(struct menu_item *ctx) {
   return MC_MAIN_MENU;
}


decompiled_code:
__int64 __fastcall show_simple_menu(__int64 a1)
{
__int64 v1; // rbp
void (*v2)(void); // rdx
__int64 v3; // rbx
__int64 v4; // rdx
char v5; // al
__int64 (__fastcall *v6)(__int64); // rax
__int64 result; // rax
bool v8; // cf
bool v9; // zf
__int64 v10; // rax
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi

v1 = *(_QWORD *)(a1 + 32);
v2 = *(void (**)(void))(v1 + 8);
if ( v2 )
v2();
while ( 1 )
{
io_func[3](v1);
v3 = ((unsigned __int8 (__fastcall *)(__int64))io_func[6])(v1);
if ( (unsigned __int8)is_error() )
{
v10 = get_error();
v11 = "quit";
v12 = 5LL;
v13 = (const char *)v10;
do
{
if ( !v12 )
break;
v8 = *v13 < (unsigned int)*v11;
v9 = *v13++ == *v11++;
--v12;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
clear_error(v11, v13);
return 4LL;
}
}
v4 = v1 + 40LL * (unsigned __int8)v3;
v5 = *(_BYTE *)(v4 + 16);
if ( v5 == 1 )
return 3LL;
if ( !v5 )
break;
v6 = *(__int64 (__fastcall **)(__int64))(v4 + 40);
if ( v6 )
{
result = v6(v1 + 40 * v3 + 16);
if ( (_BYTE)result != 3 )
return result;
}
}
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
void (*v2)(void); // rdx
__int64 v3; // rbx
__int64 v4; // rdx
char v5; // al
__int64 (__fastcall *v6)(__int64); // rax
__int64 result; // rax
bool v8; // cf
bool v9; // zf
__int64 v10; // rax
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi

v1 = *(_QWORD *)(a1 + 32);
v2 = *(void (**)(void))(v1 + 8);
if ( v2 )
v2();
while ( 1 )
{
io_func[3](v1);
v3 = ((unsigned __int8 (__fastcall *)(__int64))io_func[6])(v1);
if ( (unsigned __int8)is_error() )
{
v10 = get_error();
v11 = "quit";
v12 = 5LL;
v13 = (const char *)v10;
do
{
if ( !v12 )
break;
v8 = *v13 < (unsigned int)*v11;
v9 = *v13++ == *v11++;
--v12;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
clear_error(v11, v13);
return 4LL;
}
}
v4 = v1 + 40LL * (unsigned __int8)v3;
v5 = *(_BYTE *)(v4 + 16);
if ( v5 == 1 )
return 3LL;
if ( !v5 )
break;
v6 = *(__int64 (__fastcall **)(__int64))(v4 + 40);
if ( v6 )
{
result = v6(v1 + 40 * v3 + 16);
if ( (_BYTE)result != 3 )
return result;
}
}
return 4LL;
}

original_code:
uint8_t show_simple_menu(menu_item_t const *ctx) {
   uint8_t input, choice;
   menu_list_t *menu = (menu_list_t*) ctx->data;
   if (menu->configure_settings)
      menu->configure_settings();
   while (1) {
      io_func.show_menu(menu);
      input = io_func.get_menu_input(menu);
      if (is_error() && !strncmp(get_error(), "quit", 5)) {
         clear_error();
         return MC_EXIT;
      }
      if (menu->menu[input].id == BACK)
         return MC_BACK;
      if (menu->menu[input].id == EXIT) {
         return MC_EXIT;
      }
      if (menu->menu[input].action)
         choice = menu->menu[input].action(&menu->menu[input]);
      if (choice != MC_BACK)
         return choice;
   }
}

canonical_original_code:
unsigned char show_simple_menu(struct menu_item *ctx) {
   unsigned char input; unsigned char choice;
   struct menu_list_t *menu = (menu_list_t*) ctx->data;
   if (menu->configure_settings)
      menu->configure_settings();
   while (1) {
      io_func.show_menu(menu);
      input = io_func.get_menu_input(menu);
      if (is_error() && !strncmp(get_error(), "quit", 5)) {
         clear_error();
         return MC_EXIT;
      }
      if (menu->menu[input].id == BACK)
         return MC_BACK;
      if (menu->menu[input].id == EXIT) {
         return MC_EXIT;
      }
      if (menu->menu[input].action)
         choice = menu->menu[input].action(&menu->menu[input]);
      if (choice != MC_BACK)
         return choice;
   }
}

variable_types:
input
unsigned char

variable_types: struct menu_list_t { unsigned char size; unsigned char action_item_num; void (*configure_settings)(); struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 } type; unsigned char (*action)(struct menu_item *); void *data; } menu[]; } *

user_defined_types: struct menu_list_t { unsigned char size; unsigned char action_item_num; void (*configure_settings)(); struct menu_item menu[]; }


decompiled_code:
__int64 switch_and_start_game()
{
switch_players();
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
switch_players();
return 1LL;
}

original_code:
uint8_t switch_and_start_game(menu_item_t const *ctx) {
   switch_players();
   return MC_START_NEW_GAME;
}

canonical_original_code:
unsigned char switch_and_start_game(struct menu_item *ctx) {
   switch_players();
   return MC_START_NEW_GAME;
}


decompiled_code:
__int64 __fastcall apply_player_name(__int64 a1)
{
__int64 v1; // rbx
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_QWORD *)(a1 + 32);
((void (__fastcall *)(__int64, _BYTE *))io_func[7])(a1, v3);
set_player_name((unsigned __int8)v1, v3);
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
_BYTE v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = *(_QWORD *)(a1 + 32);
((void (__fastcall *)(__int64, _BYTE *))io_func[7])(a1, v3);
set_player_name((unsigned __int8)v1, v3);
return 3LL;
}

original_code:
uint8_t apply_player_name(menu_item_t const *ctx) {
   uint64_t player_id = (uint64_t) ctx->data;
   char input[256];
   io_func.get_string_input(ctx, input);
   set_player_name(player_id, input);
   return MC_BACK;
}

canonical_original_code:
unsigned char apply_player_name(struct menu_item *ctx) {
   unsigned long player_id = (uint64_t) ctx->data;
   char input[256];
   io_func.get_string_input(ctx, input);
   set_player_name(player_id, input);
   return MC_BACK;
}

variable_types:
input
char [256]


decompiled_code:
__int64 get_player1_name()
{
return get_player_name(0LL);
}

canonical_decompiled_code:
__int64 func6()
{
return get_player_name(0LL);
}

original_code:
const char *get_player1_name() {
   return get_player_name(0);
}

return_type: char *


decompiled_code:
__int64 get_player2_name()
{
return get_player_name(1LL);
}

canonical_decompiled_code:
__int64 func7()
{
return get_player_name(1LL);
}

original_code:
const char *get_player2_name() {
   return get_player_name(1);
}


decompiled_code:
__int64 set_hot_seat_mode()
{
set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &player_callbacks);
return set_player_ctx(1LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &player_callbacks);
return set_player_ctx(1LL, 0LL);
}

original_code:
void set_hot_seat_mode() {
   set_players();
   set_player_func_list(0, &player_callbacks);
   set_player_ctx(0, ((void *)0));
   set_player_func_list(1, &player_callbacks);
   set_player_ctx(1, ((void *)0));
}


decompiled_code:
__int64 set_computer_oponent_mode()
{
__int64 v0; // rax

set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &ai_callbacks);
set_player_ctx(1LL, &g_ai_data);
v0 = ((__int64 (__fastcall *)(__int64))io_func[2])(9LL);
return set_player_name(1LL, v0);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax

set_players();
set_player_func_list(0LL, &player_callbacks);
set_player_ctx(0LL, 0LL);
set_player_func_list(1LL, &ai_callbacks);
set_player_ctx(1LL, &g_ai_data);
v0 = ((__int64 (__fastcall *)(__int64))io_func[2])(9LL);
return set_player_name(1LL, v0);
}

original_code:
void set_computer_oponent_mode() {
   set_players();
   set_player_func_list(0, &player_callbacks);
   set_player_ctx(0, ((void *)0));
   set_player_func_list(1, &ai_callbacks);
   set_player_ctx(1, (void *) &g_ai_data);
   set_player_name(1, io_func.get_code_str(DEFAULT_AI_NAME));
}


decompiled_code:
__int64 show_start_menu()
{
__int128 v1[2]; // [rsp+0h] [rbp-38h] BYREF
void **v2; // [rsp+20h] [rbp-18h]

v1[0] = 0LL;
v2 = &main_menu;
LOBYTE(v1[0]) = 18;
v1[1] = 0LL;
return show_simple_menu((__int64)v1);
}

original_code:
uint8_t show_start_menu() {
   menu_item_t main_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
      .data = (void *) &main_menu };
   return show_simple_menu(&main_item);
}

canonical_original_code:
unsigned char show_start_menu() {
   struct menu_item main_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
      .data = (void *) &main_menu };
   return show_simple_menu(&main_item);
}

variable_types: struct menu_item { unsigned char id; char *(*get_title)(); enum menu_item_type_t { MENU_ITEM_CLICKABLE=0, MENU_ITEM_EDITABLE=1, MENU_ITEM_TEXT=2 } type; unsigned char (*action)(struct menu_item *); void *data; }


decompiled_code:
__int64 show_finish_menu()
{
__int128 v1[2]; // [rsp+0h] [rbp-38h] BYREF
void **v2; // [rsp+20h] [rbp-18h]

v1[0] = 0LL;
v2 = &finish_menu;
LOBYTE(v1[0]) = 18;
v1[1] = 0LL;
return show_simple_menu((__int64)v1);
}

original_code:
uint8_t show_finish_menu() {
   menu_item_t finish_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &finish_menu };
   return show_simple_menu(&finish_item);
}

canonical_original_code:
unsigned char show_finish_menu() {
   struct menu_item finish_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &finish_menu };
   return show_simple_menu(&finish_item);
}


decompiled_code:
__int64 show_context_menu()
{
__int128 v1[2]; // [rsp+0h] [rbp-38h] BYREF
void **v2; // [rsp+20h] [rbp-18h]

v1[0] = 0LL;
v2 = &context_menu;
LOBYTE(v1[0]) = 18;
v1[1] = 0LL;
return show_simple_menu((__int64)v1);
}

original_code:
uint8_t show_context_menu() {
   menu_item_t context_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &context_menu };
   return show_simple_menu(&context_item);
}

canonical_original_code:
unsigned char show_context_menu() {
   struct menu_item context_item = { .id = NONE, .type = MENU_ITEM_CLICKABLE,
         .data = (void *) &context_menu };
   return show_simple_menu(&context_item);
}


decompiled_code:
__int64 __fastcall is_input_correct(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || (result = 1LL, *(_BYTE *)(a2 + 1) < a1) )
{
puts("Error in menu, item is unknown");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 || (result = 1LL, *(_BYTE *)(a2 + 1) < a1) )
{
puts("Error in menu, item is unknown");
result = 0LL;
}
return result;
}

original_code:
static uint8_t is_input_correct(uint8_t input, menu_list_t const *cur_menu) {
   if (input > 0 && input <= cur_menu->action_item_num)
      return 1;
   printf("Error in menu, item is unknown\n");
   return 0;
}

canonical_original_code:
static unsigned char is_input_correct(unsigned char input, struct menu_list_t *cur_menu) {
   if (input > 0 && input <= cur_menu->action_item_num)
      return 1;
   printf("Error in menu, item is unknown\n");
   return 0;
}


decompiled_code:
__int64 __fastcall choice2item(char a1, _BYTE *a2)
{
int v2; // ecx
char v3; // dl
_DWORD *v4; // rsi
int v5; // eax
unsigned int v6; // er12

v2 = (unsigned __int8)*a2;
v3 = a1;
if ( *a2 )
{
if ( !a1 )
return (unsigned int)-1;
v4 = a2 + 32;
v5 = 0;
while ( 1 )
{
while ( *v4 != 2 )
{
++v5;
--v3;
if ( v5 == v2 )
goto LABEL_11;
v4 += 10;
if ( !v3 )
return (unsigned int)(v5 - 1);
}
if ( v2 == ++v5 )
break;
v4 += 10;
}
LABEL_11:
v6 = v2 - 1;
}
else
{
v6 = -1;
}
if ( !v3 )
return v6;
set_error("menu items error", 16LL);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, _BYTE *a2)
{
int v2; // ecx
char v3; // dl
_DWORD *v4; // rsi
int v5; // eax
unsigned int v6; // er12

v2 = (unsigned __int8)*a2;
v3 = a1;
if ( *a2 )
{
if ( !a1 )
return (unsigned int)-1;
v4 = a2 + 32;
v5 = 0;
while ( 1 )
{
while ( *v4 != 2 )
{
++v5;
--v3;
if ( v5 == v2 )
goto LABEL_11;
v4 += 10;
if ( !v3 )
return (unsigned int)(v5 - 1);
}
if ( v2 == ++v5 )
break;
v4 += 10;
}
LABEL_11:
v6 = v2 - 1;
}
else
{
v6 = -1;
}
if ( !v3 )
return v6;
set_error("menu items error", 16LL);
return v6;
}

original_code:
static uint8_t choice2item(uint8_t choice, menu_list_t const *cur_menu) {
   int i;
   for (i = 0; i < cur_menu->size && choice; i++) {
      if (cur_menu->menu[i].type != MENU_ITEM_TEXT)
         choice--;
   }
   if (choice != 0)
      set_error("menu items error", strlen("menu items error"));
   return i - 1;
}

canonical_original_code:
static unsigned char choice2item(unsigned char choice, struct menu_list_t *cur_menu) {
   int i;
   for (i = 0; i < cur_menu->size && choice; i++) {
      if (cur_menu->menu[i].type != MENU_ITEM_TEXT)
         choice--;
   }
   if (choice != 0)
      set_error("menu items error", strlen("menu items error"));
   return i - 1;
}


decompiled_code:
__int64 get_ushort_from_input()
{
unsigned int i; // er12
int v1; // ebx

for ( i = 0; ; i = 0 )
{
v1 = getchar();
if ( (_BYTE)v1 == 10 )
return i;
while ( ((*_ctype_b_loc())[(unsigned __int8)v1] & 0x800) != 0 )
{
i = v1 + 10 * i - 48;
v1 = getchar();
if ( (_BYTE)v1 == 10 )
return i;
}
clear_input_constprop_0();
if ( (_BYTE)v1 == 27 )
break;
}
skip_sign = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int i; // er12
int v1; // ebx

for ( i = 0; ; i = 0 )
{
v1 = getchar();
if ( (_BYTE)v1 == 10 )
return i;
while ( ((*_ctype_b_loc())[(unsigned __int8)v1] & 0x800) != 0 )
{
i = v1 + 10 * i - 48;
v1 = getchar();
if ( (_BYTE)v1 == 10 )
return i;
}
func2();
if ( (_BYTE)v1 == 27 )
break;
}
skip_sign = 1;
return 0LL;
}

original_code:
static uint8_t get_ushort_from_input() {
   uint8_t choice = 0, ch;
   while ((ch = getchar()) != '\n') {
      if (!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISdigit)) {
         clear_input("Please enter only digit signs\n");
         choice = 0;
         if (ch == 27) {
            skip_sign = 1;
            return 0;
         }
         continue;
      }
      if (choice * 10 + (ch - 48) > (0x7fff * 2 + 1)) {
         clear_input("Entered choice is too long\n");
         choice = 0;
         continue;
      }
      choice = choice * 10 + (ch - 48);
   }
   return choice;
}

canonical_original_code:
static unsigned char get_ushort_from_input() {
   unsigned char choice = 0; unsigned char ch;
   while ((ch = getchar()) != '\n') {
      if (!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISdigit)) {
         clear_input("Please enter only digit signs\n");
         choice = 0;
         if (ch == 27) {
            skip_sign = 1;
            return 0;
         }
         continue;
      }
      if (choice * 10 + (ch - 48) > (0x7fff * 2 + 1)) {
         clear_input("Entered choice is too long\n");
         choice = 0;
         continue;
      }
      choice = choice * 10 + (ch - 48);
   }
   return choice;
}

variable_types:
ch
unsigned char


decompiled_code:
char *__fastcall get_code_str(unsigned __int8 a1)
{
return output_code_table[a1];
}

canonical_decompiled_code:
char *__fastcall func4(unsigned __int8 a1)
{
return output_code_table[a1];
}

original_code:
char const * get_code_str(uint8_t code) {
   return output_code_table[code];
}

canonical_original_code:
char *get_code_str(unsigned char code) {
   return output_code_table[code];
}

variable_types:
code
unsigned char


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

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

original_code: uint8_t init_io() { return 0; }

canonical_original_code: unsigned char init_io() { return 0; }


decompiled_code:
void clear_io()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code: void clear_io() { }

canonical_original_code: void clear_io() { }


decompiled_code:
int __fastcall show_menu(_BYTE *a1)
{
int result; // eax
unsigned __int8 *v2; // rbx
int v3; // ebp
int v4; // er12
const char *v5; // rcx
int v6; // eax
int v7; // er14
__int64 v8; // rax
__int64 v9; // rcx
const char *v10; // r8
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

result = system("clear");
if ( *a1 )
{
v2 = a1 + 16;
v3 = 0;
v4 = 1;
while ( 1 )
{
v6 = *((_DWORD *)v2 + 4);
if ( v6 == 1 )
break;
if ( v6 == 2 )
{
v5 = output_code_table[*v2];
}
else
{
v5 = "item not supported";
if ( !v6 )
{
v7 = v4 + 1;
v9 = (unsigned __int8)v4;
v10 = output_code_table[*v2];
goto LABEL_10;
}
}
snprintf(v11, 0x100uLL, "%s\n", v5);
LABEL_5:
++v3;
printf("%s", v11);
result = (unsigned __int8)*a1;
v2 += 40;
if ( result <= v3 )
return result;
}
v7 = v4 + 1;
v8 = (*((__int64 (**)(void))v2 + 1))();
v9 = (unsigned __int8)v4;
v10 = (const char *)v8;
LABEL_10:
snprintf(v11, 0x100uLL, "%d) %s\n", v9, v10);
v4 = v7;
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_BYTE *a1)
{
int result; // eax
unsigned __int8 *v2; // rbx
int v3; // ebp
int v4; // er12
const char *v5; // rcx
int v6; // eax
int v7; // er14
__int64 v8; // rax
__int64 v9; // rcx
const char *v10; // r8
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

result = system("clear");
if ( *a1 )
{
v2 = a1 + 16;
v3 = 0;
v4 = 1;
while ( 1 )
{
v6 = *((_DWORD *)v2 + 4);
if ( v6 == 1 )
break;
if ( v6 == 2 )
{
v5 = output_code_table[*v2];
}
else
{
v5 = "item not supported";
if ( !v6 )
{
v7 = v4 + 1;
v9 = (unsigned __int8)v4;
v10 = output_code_table[*v2];
goto LABEL_10;
}
}
snprintf(v11, 0x100uLL, "%s\n", v5);
LABEL_5:
++v3;
printf("%s", v11);
result = (unsigned __int8)*a1;
v2 += 40;
if ( result <= v3 )
return result;
}
v7 = v4 + 1;
v8 = (*((__int64 (**)(void))v2 + 1))();
v9 = (unsigned __int8)v4;
v10 = (const char *)v8;
LABEL_10:
snprintf(v11, 0x100uLL, "%d) %s\n", v9, v10);
v4 = v7;
goto LABEL_5;
}
return result;
}

original_code:
void show_menu(menu_list_t const *list) {
   uint8_t num = 1;
   char item_msg[256];
   system("clear");
   for (int ind = 0; ind < list->size; ind++) {
      switch (list->menu[ind].type) {
         case MENU_ITEM_CLICKABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               output_code_table[list->menu[ind].id]);
            break;
         case MENU_ITEM_EDITABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               list->menu[ind].get_title());
            break;
         case MENU_ITEM_TEXT:
            snprintf(item_msg, 256, "%s\n",
               output_code_table[list->menu[ind].id]);
            break;
         default:
            snprintf(item_msg, 256, "%s\n",
               "item not supported");
      }
      printf("%s", item_msg);
   }
}

canonical_original_code:
void show_menu(struct menu_list_t *list) {
   unsigned char num = 1;
   char item_msg[256];
   system("clear");
   for (int ind = 0; ind < list->size; ind++) {
      switch (list->menu[ind].type) {
         case MENU_ITEM_CLICKABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               output_code_table[list->menu[ind].id]);
            break;
         case MENU_ITEM_EDITABLE:
            snprintf(item_msg, 256, "%d) %s\n", num++,
               list->menu[ind].get_title());
            break;
         case MENU_ITEM_TEXT:
            snprintf(item_msg, 256, "%s\n",
               output_code_table[list->menu[ind].id]);
            break;
         default:
            snprintf(item_msg, 256, "%s\n",
               "item not supported");
      }
      printf("%s", item_msg);
   }
}

variable_types:
num
unsigned char

variable_types: ind int


original_code:
void show_field(uint8_t **field, point_t const *size) {
   char output[3];
   char *delimeter;
   int32_t i,j;
   delimeter = (char *) malloc(size->x * 2 * sizeof(char) + 2);
   for (i = 0; i < size->x * 2 - 1; i++)
      delimeter[i] = '-';
   delimeter[i] = '\n';
   delimeter[i + 1] = '\0';
   system("clear");
   for (i = 0; i < size->y; i++) {
      for (j = 0; j < size->x; j++) {
         snprintf(output, 3, "%s%c", ttt_code_table[field[i][j]],
            j == size->x - 1 ? '\n' : '|');
         printf("%s", output);
      }
      if (i != size->y - 1)
         printf("%s", delimeter);
   }
   free(delimeter);
}

canonical_original_code:
void show_field(unsigned char **field, struct point_t *size) {
   char output[3];
   char *delimeter;
   int i; int j;
   delimeter = (char *) malloc(size->x * 2 * sizeof(char) + 2);
   for (i = 0; i < size->x * 2 - 1; i++)
      delimeter[i] = '-';
   delimeter[i] = '\n';
   delimeter[i + 1] = '\0';
   system("clear");
   for (i = 0; i < size->y; i++) {
      for (j = 0; j < size->x; j++) {
         snprintf(output, 3, "%s%c", ttt_code_table[field[i][j]],
            j == size->x - 1 ? '\n' : '|');
         printf("%s", output);
      }
      if (i != size->y - 1)
         printf("%s", delimeter);
   }
   free(delimeter);
}

variable_types:
field
unsigned char **

variable_types:
output
char [3]

variable_types:
delimeter
char *

user_defined_types: struct point_t { unsigned char x; unsigned char y; }