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

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

original_code:
int is_big_endian()
{
    union A k;
    k.n[0]=0;
    k.n[1]=1;
    return (k.m==1)?1:0;
}

variable_types:
k
union A { short m; char n[2]; }


decompiled_code:
char __fastcall reverse4x(__int64 a1)
{
_BYTE *v1; // r8
_BYTE *v2; // rsi
_BYTE *v3; // rcx
char result; // al
__int64 v5; // r8
int v6; // er9
int v7; // edx

v1 = (_BYTE *)(a1 + 1);
do
{
v2 = v1 + 3;
v3 = v1;
do
{
result = swap(v3, v2);
v2 += 4;
}
while ( v7 != 4 );
v1 = (_BYTE *)(v5 + 5);
}
while ( v6 != 3 );
return result;
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1)
{
_BYTE *v1; // r8
_BYTE *v2; // rsi
_BYTE *v3; // rcx
char result; // al
__int64 v5; // r8
int v6; // er9
int v7; // edx

v1 = (_BYTE *)(a1 + 1);
do
{
v2 = v1 + 3;
v3 = v1;
do
{
result = func1(v3, v2);
v2 += 4;
}
while ( v7 != 4 );
v1 = (_BYTE *)(v5 + 5);
}
while ( v6 != 3 );
return result;
}

original_code:
void reverse4x(byte_t * box)
{
    int i,j;
    for(i=0;i<3;i++)
        for(j=i+1;j<4;j++)
            swap(&box[4*i+j],&box[4*j+i]);
}

canonical_original_code:
void reverse4x(unsigned char *box)
{
    int i; int j;
    for(i=0;i<3;i++)
        for(j=i+1;j<4;j++)
            swap(&box[4*i+j],&box[4*j+i]);
}

variable_types:
box
unsigned char *

variable_types: i int

variable_types: j int

return_type: void


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

result = 0LL;
if ( a2 > 0 )
{
do
{
result[a4] = result[a1];
++result;
}
while ( (char *)a2 != result );
}
if ( a2 < a3 )
result = (char *)memset((void *)(a4 + a2), (unsigned __int8)(a3 - a2 % a3), (unsigned int)(a3 - 1 - a2) + 1LL);
return result;
}

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

result = 0LL;
if ( a2 > 0 )
{
do
{
result[a4] = result[a1];
++result;
}
while ( (char *)a2 != result );
}
if ( a2 < a3 )
result = (char *)memset((void *)(a4 + a2), (unsigned __int8)(a3 - a2 % a3), (unsigned int)(a3 - 1 - a2) + 1LL);
return result;
}

original_code:
void PKCS7_Pad(byte_t * buf,int buflen,int blocksize,byte_t * paddingBuf)
{
    int i;
    int p=blocksize-buflen%blocksize;
    for(i=0;i<buflen;i++)
        paddingBuf[i]=buf[i];
    for(i=buflen;i<blocksize;i++)
        paddingBuf[i]=p;
}

canonical_original_code:
void PKCS7_Pad(unsigned char *buf, int buflen, int blocksize, unsigned char *paddingBuf)
{
    int i;
    int p = blocksize-buflen%blocksize;
    for(i=0;i<buflen;i++)
        paddingBuf[i]=buf[i];
    for(i=buflen;i<blocksize;i++)
        paddingBuf[i]=p;
}

variable_types:
buf
unsigned char *

variable_types: buflen int

variable_types: blocksize int

variable_types:
paddingBuf
unsigned char *

variable_types: p int


decompiled_code:
__int64 __fastcall PKCS7_UnPad(__int64 a1, __int64 a2, int a3, _DWORD *a4)
{
int v4; // er8
unsigned __int8 v5; // dl
_BYTE *v6; // rdi
int v7; // eax
__int64 result; // rax

v4 = 0;
v5 = *(_BYTE *)(a1 + a3 - 1);
if ( (unsigned __int8)(v5 - 1) <= 0xEu )
{
v4 = v5;
v6 = (_BYTE *)(16 - v5 + a1);
v7 = 0;
while ( v5 == *v6 )
{
++v7;
++v6;
if ( v7 == v5 )
goto LABEL_5;
}
v4 = v7;
}
LABEL_5:
result = (unsigned int)(16 - v4);
if ( v4 != v5 )
result = 16LL;
*a4 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int a3, _DWORD *a4)
{
int v4; // er8
unsigned __int8 v5; // dl
_BYTE *v6; // rdi
int v7; // eax
__int64 result; // rax

v4 = 0;
v5 = *(_BYTE *)(a1 + a3 - 1);
if ( (unsigned __int8)(v5 - 1) <= 0xEu )
{
v4 = v5;
v6 = (_BYTE *)(16 - v5 + a1);
v7 = 0;
while ( v5 == *v6 )
{
++v7;
++v6;
if ( v7 == v5 )
goto LABEL_5;
}
v4 = v7;
}
LABEL_5:
result = (unsigned int)(16 - v4);
if ( v4 != v5 )
result = 16LL;
*a4 = result;
return result;
}

original_code:
void PKCS7_UnPad(byte_t * buf,int buflen,int blocksize,int * orilen)
{
    int i,j=0;
    int pn=buf[blocksize-1];
    if(pn<16 && pn!=0){
        for(i=16-pn;i<16;i++){
            if(buf[i]!=pn)
                break;
            j++;
        }
    }
    *orilen = (j==pn)?16-pn:16;
}

canonical_original_code:
void PKCS7_UnPad(unsigned char *buf, int buflen, int blocksize, int *orilen)
{
    int i; int j = 0;
    int pn = buf[blocksize-1];
    if(pn<16 && pn!=0){
        for(i=16-pn;i<16;i++){
            if(buf[i]!=pn)
                break;
            j++;
        }
    }
    *orilen = (j==pn)?16-pn:16;
}

variable_types:
orilen
int *

variable_types: pn int


decompiled_code:
void __fastcall tcp_send(__int64 a1)
{
__int64 v1; // rsi
int v2; // ebp
int v3; // ebx
int v4; // eax
int *v5; // rax
int v6; // eax
const char *v7; // rdx

v1 = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)(a1 + 8) - (int)v1 > 0 )
{
v2 = *(_DWORD *)(a1 + 8) - v1;
v3 = 0;
while ( 1 )
{
v4 = send(sock, (const void *)(v3 + v1), v2 - v3, 0);
if ( v4 <= 0 )
break;
v3 += v4;
if ( v2 <= v3 )
return;
v1 = *(_QWORD *)(a1 + 16);
}
v5 = _errno_location();
v6 = (unsigned int)strerror(*v5);
error((int)"send: %s\n", v6, v7);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 v1; // rsi
int v2; // ebp
int v3; // ebx
int v4; // eax
int *v5; // rax
int v6; // eax
const char *v7; // rdx

v1 = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)(a1 + 8) - (int)v1 > 0 )
{
v2 = *(_DWORD *)(a1 + 8) - v1;
v3 = 0;
while ( 1 )
{
v4 = send(sock, (const void *)(v3 + v1), v2 - v3, 0);
if ( v4 <= 0 )
break;
v3 += v4;
if ( v2 <= v3 )
return;
v1 = *(_QWORD *)(a1 + 16);
}
v5 = _errno_location();
v6 = (unsigned int)strerror(*v5);
error((int)"send: %s\n", v6, v7);
}
}

original_code:
void
tcp_send(STREAM s)
{
 int length = s->end - s->data;
 int sent, total = 0;
 while (total < length)
 {
  sent = send(sock, s->data + total, length - total, 0);
  if (sent <= 0)
  {
   error("send: %s\n", strerror((*__errno_location ())));
   return;
  }
  total += sent;
 }
}

canonical_original_code:
void tcp_send(struct stream *s)
{
 int length = s->end - s->data;
 int sent; int total = 0;
 while (total < length)
 {
  sent = send(sock, s->data + total, length - total, 0);
  if (sent <= 0)
  {
   error("send: %s\n", strerror((*__errno_location ())));
   return;
  }
  total += sent;
 }
}

variable_types: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; } *

variable_types: length int

variable_types: sent int

variable_types: total int


decompiled_code:
__int64 __fastcall tcp_connect(char *cp)
{
struct hostent *v1; // rax
socklen_t v2; // edx
int v3; // er8
__int64 v4; // rax
__int64 result; // rax
int *v6; // rax
int v7; // eax
const char *v8; // rdx
int *v9; // rax
int v10; // eax
const char *v11; // rdx
const char *v12; // rdx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v14; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
v1 = gethostbyname(cp);
if ( v1 )
{
*(_DWORD *)&v14.sa_data[2] = **(_DWORD **)v1->h_addr_list;
}
else
{
*(_DWORD *)&v14.sa_data[2] = inet_addr(cp);
if ( *(_DWORD *)&v14.sa_data[2] == -1 )
{
error((int)"%s: unable to resolve host\n", (int)cp, v12);
return 0LL;
}
}
sock = socket(2, 1, 0);
if ( sock < 0 )
{
v6 = _errno_location();
v7 = (unsigned int)strerror(*v6);
error((int)"socket: %s\n", v7, v8);
result = 0LL;
}
else
{
v14.sa_family = 2;
*(_WORD *)v14.sa_data = _bswap_16(tcp_port_rdp);
if ( connect(v3, &v14, v2) < 0 )
{
v9 = _errno_location();
v10 = (unsigned int)strerror(*v9);
error((int)"connect: %s\n", v10, v11);
close(sock);
result = 0LL;
}
else
{
setsockopt(sock, 6, 1, &optval, 4u);
dword_378 = 4096;
v4 = xmalloc(4096LL);
dword_338 = 4096;
qword_370 = v4;
qword_330 = xmalloc(4096LL);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *cp)
{
struct hostent *v1; // rax
socklen_t v2; // edx
int v3; // er8
__int64 v4; // rax
__int64 result; // rax
int *v6; // rax
int v7; // eax
const char *v8; // rdx
int *v9; // rax
int v10; // eax
const char *v11; // rdx
const char *v12; // rdx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v14; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
v1 = gethostbyname(cp);
if ( v1 )
{
*(_DWORD *)&v14.sa_data[2] = **(_DWORD **)v1->h_addr_list;
}
else
{
*(_DWORD *)&v14.sa_data[2] = inet_addr(cp);
if ( *(_DWORD *)&v14.sa_data[2] == -1 )
{
error((int)"%s: unable to resolve host\n", (int)cp, v12);
return 0LL;
}
}
sock = socket(2, 1, 0);
if ( sock < 0 )
{
v6 = _errno_location();
v7 = (unsigned int)strerror(*v6);
error((int)"socket: %s\n", v7, v8);
result = 0LL;
}
else
{
v14.sa_family = 2;
*(_WORD *)v14.sa_data = func0(tcp_port_rdp);
if ( connect(v3, &v14, v2) < 0 )
{
v9 = _errno_location();
v10 = (unsigned int)strerror(*v9);
error((int)"connect: %s\n", v10, v11);
close(sock);
result = 0LL;
}
else
{
setsockopt(sock, 6, 1, &optval, 4u);
dword_378 = 4096;
v4 = xmalloc(4096LL);
dword_338 = 4096;
qword_370 = v4;
qword_330 = xmalloc(4096LL);
result = 1LL;
}
}
return result;
}

original_code:
BOOL
tcp_connect(char *server)
{
 struct hostent *nslookup;
 struct sockaddr_in servaddr;
 int true = 1;
 if ((nslookup = gethostbyname(server)) != ((void *)0))
 {
  memcpy(&servaddr.sin_addr, nslookup->h_addr_list[0], sizeof(servaddr.sin_addr));
 }
 else if ((servaddr.sin_addr.s_addr = inet_addr(server)) == ((in_addr_t) 0xffffffff))
 {
  error("%s: unable to resolve host\n", server);
  return (0);
 }
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
 {
  error("socket: %s\n", strerror((*__errno_location ())));
  return (0);
 }
 servaddr.sin_family = 2;
 servaddr.sin_port = htons(tcp_port_rdp);
 if (connect(sock, (struct sockaddr *) &servaddr, sizeof(struct sockaddr)) < 0)
 {
  error("connect: %s\n", strerror((*__errno_location ())));
  close(sock);
  return (0);
 }
 setsockopt(sock, IPPROTO_TCP, 1, (void *) &true, sizeof(true));
 in.size = 4096;
 in.data = xmalloc(in.size);
 out.size = 4096;
 out.data = xmalloc(out.size);
 return (1);
}

canonical_original_code:
int tcp_connect(char *server)
{
 struct hostent *nslookup;
 struct sockaddr_in servaddr;
 int true = 1;
 if ((nslookup = gethostbyname(server)) != ((void *)0))
 {
  memcpy(&servaddr.sin_addr, nslookup->h_addr_list[0], sizeof(servaddr.sin_addr));
 }
 else if ((servaddr.sin_addr.s_addr = inet_addr(server)) == ((unsigned int) 0xffffffff))
 {
  error("%s: unable to resolve host\n", server);
  return (0);
 }
 if ((sock = socket(2, SOCK_STREAM, 0)) < 0)
 {
  error("socket: %s\n", strerror((*__errno_location ())));
  return (0);
 }
 servaddr.sin_family = 2;
 servaddr.sin_port = htons(tcp_port_rdp);
 if (connect(sock, (struct sockaddr *) &servaddr, sizeof(struct sockaddr)) < 0)
 {
  error("connect: %s\n", strerror((*__errno_location ())));
  close(sock);
  return (0);
 }
 setsockopt(sock, IPPROTO_TCP, 1, (void *) &true, sizeof(true));
 in.size = 4096;
 in.data = xmalloc(in.size);
 out.size = 4096;
 out.data = xmalloc(out.size);
 return (1);
}

variable_types:
server
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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

variable_types: true int

return_type: int

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

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


decompiled_code:
int tcp_disconnect()
{
return close(sock);
}

canonical_decompiled_code:
int func3()
{
return close(sock);
}

original_code:
void
tcp_disconnect(void)
{
 close(sock);
}

canonical_original_code:
void tcp_disconnect()
{
 close(sock);
}


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fwrite("rdesktop: A Remote Desktop Protocol client.\n", 1uLL, 0x2CuLL, stderr);
fwrite("Version 1.2.0. Copyright (C) 1999-2003 Matt Chapman.\n", 1uLL, 0x35uLL, stderr);
fwrite("See http://www.rdesktop.org/ for more information.\n\n", 1uLL, 0x34uLL, stderr);
fprintf(stderr, "Usage: %s [options] server[:port]\n", a1);
fwrite(" -u: user name\n", 1uLL, 0x11uLL, stderr);
fwrite(" -d: domain\n", 1uLL, 0xEuLL, stderr);
fwrite(" -s: shell\n", 1uLL, 0xDuLL, stderr);
fwrite(" -c: working directory\n", 1uLL, 0x19uLL, stderr);
fwrite(" -p: password (- to prompt)\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -n: client hostname\n", 1uLL, 0x17uLL, stderr);
fwrite(" -k: keyboard layout on terminal server (us,sv,gr,etc.)\n", 1uLL, 0x3AuLL, stderr);
fwrite(" -g: desktop geometry (WxH)\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -f: full-screen mode\n", 1uLL, 0x18uLL, stderr);
fwrite(" -b: force bitmap updates\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -e: disable encryption (French TS)\n", 1uLL, 0x26uLL, stderr);
fwrite(" -m: do not send motion events\n", 1uLL, 0x21uLL, stderr);
fwrite(" -C: use private colour map\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -K: keep window manager key bindings\n", 1uLL, 0x28uLL, stderr);
fwrite(" -T: window title\n", 1uLL, 0x14uLL, stderr);
return fwrite(" -D: hide window manager decorations\n", 1uLL, 0x27uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fwrite("rdesktop: A Remote Desktop Protocol client.\n", 1uLL, 0x2CuLL, stderr);
fwrite("Version 1.2.0. Copyright (C) 1999-2003 Matt Chapman.\n", 1uLL, 0x35uLL, stderr);
fwrite("See http://www.rdesktop.org/ for more information.\n\n", 1uLL, 0x34uLL, stderr);
fprintf(stderr, "Usage: %s [options] server[:port]\n", a1);
fwrite(" -u: user name\n", 1uLL, 0x11uLL, stderr);
fwrite(" -d: domain\n", 1uLL, 0xEuLL, stderr);
fwrite(" -s: shell\n", 1uLL, 0xDuLL, stderr);
fwrite(" -c: working directory\n", 1uLL, 0x19uLL, stderr);
fwrite(" -p: password (- to prompt)\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -n: client hostname\n", 1uLL, 0x17uLL, stderr);
fwrite(" -k: keyboard layout on terminal server (us,sv,gr,etc.)\n", 1uLL, 0x3AuLL, stderr);
fwrite(" -g: desktop geometry (WxH)\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -f: full-screen mode\n", 1uLL, 0x18uLL, stderr);
fwrite(" -b: force bitmap updates\n", 1uLL, 0x1CuLL, stderr);
fwrite(" -e: disable encryption (French TS)\n", 1uLL, 0x26uLL, stderr);
fwrite(" -m: do not send motion events\n", 1uLL, 0x21uLL, stderr);
fwrite(" -C: use private colour map\n", 1uLL, 0x1EuLL, stderr);
fwrite(" -K: keep window manager key bindings\n", 1uLL, 0x28uLL, stderr);
fwrite(" -T: window title\n", 1uLL, 0x14uLL, stderr);
return fwrite(" -D: hide window manager decorations\n", 1uLL, 0x27uLL, stderr);
}

original_code:
static void
usage(char *program)
{
 fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
 fprintf(stderr, "Version " "1.2.0" ". Copyright (C) 1999-2003 Matt Chapman.\n");
 fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
 fprintf(stderr, "Usage: %s [options] server[:port]\n", program);
 fprintf(stderr, "   -u: user name\n");
 fprintf(stderr, "   -d: domain\n");
 fprintf(stderr, "   -s: shell\n");
 fprintf(stderr, "   -c: working directory\n");
 fprintf(stderr, "   -p: password (- to prompt)\n");
 fprintf(stderr, "   -n: client hostname\n");
 fprintf(stderr, "   -k: keyboard layout on terminal server (us,sv,gr,etc.)\n");
 fprintf(stderr, "   -g: desktop geometry (WxH)\n");
 fprintf(stderr, "   -f: full-screen mode\n");
 fprintf(stderr, "   -b: force bitmap updates\n");
 fprintf(stderr, "   -e: disable encryption (French TS)\n");
 fprintf(stderr, "   -m: do not send motion events\n");
 fprintf(stderr, "   -C: use private colour map\n");
 fprintf(stderr, "   -K: keep window manager key bindings\n");
 fprintf(stderr, "   -T: window title\n");
 fprintf(stderr, "   -D: hide window manager decorations\n");
}

variable_types:
program
char *


decompiled_code:
int __fastcall generate_random(void *buf)
{
int v1; // ebp
int v2; // er12
int result; // eax
__pid_t v4; // ebp
__uid_t v5; // ebp
struct tms v6; // [rsp+0h] [rbp-128h] BYREF
char v7[96]; // [rsp+20h] [rbp-108h] BYREF
struct stat v8; // [rsp+80h] [rbp-A8h] BYREF

v1 = open("/dev/urandom", 0);
if ( v1 == -1 && (v1 = open("/dev/random", 0), v1 == -1)
|| (v2 = read(v1, buf, 0x20uLL), result = close(v1), v2 != 32) )
{
v4 = getpid();
*(_DWORD *)buf = v4 | (getppid() << 16);
v5 = getuid();
*((_DWORD *)buf + 1) = v5 | (getgid() << 16);
*((_DWORD *)buf + 2) = times(&v6);
gettimeofday((struct timeval *)((char *)buf + 12), 0LL);
stat("/tmp", &v8);
*((_DWORD *)buf + 5) = v8.st_atim.tv_sec;
*((_DWORD *)buf + 6) = v8.st_mtim.tv_sec;
*((_DWORD *)buf + 7) = v8.st_ctim.tv_sec;
MD5_Init(v7);
MD5_Update(v7, buf, 16LL);
MD5_Final(buf, v7);
MD5_Update(v7, (char *)buf + 16, 16LL);
result = MD5_Final((char *)buf + 16, v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(void *buf)
{
int v1; // ebp
int v2; // er12
int result; // eax
__pid_t v4; // ebp
__uid_t v5; // ebp
struct tms v6; // [rsp+0h] [rbp-128h] BYREF
char v7[96]; // [rsp+20h] [rbp-108h] BYREF
struct stat v8; // [rsp+80h] [rbp-A8h] BYREF

v1 = open("/dev/urandom", 0);
if ( v1 == -1 && (v1 = open("/dev/random", 0), v1 == -1)
|| (v2 = read(v1, buf, 0x20uLL), result = close(v1), v2 != 32) )
{
v4 = getpid();
*(_DWORD *)buf = v4 | (getppid() << 16);
v5 = getuid();
*((_DWORD *)buf + 1) = v5 | (getgid() << 16);
*((_DWORD *)buf + 2) = times(&v6);
gettimeofday((struct timeval *)((char *)buf + 12), 0LL);
stat("/tmp", &v8);
*((_DWORD *)buf + 5) = v8.st_atim.tv_sec;
*((_DWORD *)buf + 6) = v8.st_mtim.tv_sec;
*((_DWORD *)buf + 7) = v8.st_ctim.tv_sec;
MD5_Init(v7);
MD5_Update(v7, buf, 16LL);
MD5_Final(buf, v7);
MD5_Update(v7, (char *)buf + 16, 16LL);
result = MD5_Final((char *)buf + 16, v7);
}
return result;
}

original_code:
void
generate_random(uint8 * random)
{
 struct stat st;
 struct tms tmsbuf;
 MD5_CTX md5;
 uint32 *r;
 int fd, n;
 if (((fd = open("/dev/urandom", 00)) != -1)
     || ((fd = open("/dev/random", 00)) != -1))
 {
  n = read(fd, random, 32);
  close(fd);
  if (n == 32)
   return;
 }
 r = (uint32 *) random;
 r[0] = (getpid()) | (getppid() << 16);
 r[1] = (getuid()) | (getgid() << 16);
 r[2] = times(&tmsbuf);
 gettimeofday((struct timeval *) &r[3], ((void *)0));
 stat("/tmp", &st);
 r[5] = st.st_atim.tv_sec;
 r[6] = st.st_mtim.tv_sec;
 r[7] = st.st_ctim.tv_sec;
 MD5_Init(&md5);
 MD5_Update(&md5, random, 16);
 MD5_Final(random, &md5);
 MD5_Update(&md5, random + 16, 16);
 MD5_Final(random + 16, &md5);
}

canonical_original_code:
void generate_random(unsigned char *random)
{
 struct stat st;
 struct tms tmsbuf;
 struct MD5state_st md5;
 unsigned int *r;
 int fd; int n;
 if (((fd = open("/dev/urandom", 00)) != -1)
     || ((fd = open("/dev/random", 00)) != -1))
 {
  n = read(fd, random, 32);
  close(fd);
  if (n == 32)
   return;
 }
 r = (unsigned int *) random;
 r[0] = (getpid()) | (getppid() << 16);
 r[1] = (getuid()) | (getgid() << 16);
 r[2] = times(&tmsbuf);
 gettimeofday((struct timeval *) &r[3], ((void *)0));
 stat("/tmp", &st);
 r[5] = st.st_atim.tv_sec;
 r[6] = st.st_mtim.tv_sec;
 r[7] = st.st_ctim.tv_sec;
 MD5_Init(&md5);
 MD5_Update(&md5, random, 16);
 MD5_Final(random, &md5);
 MD5_Update(&md5, random + 16, 16);
 MD5_Final(random + 16, &md5);
}

variable_types:
random
unsigned char *

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

variable_types: struct tms { long tms_utime; long tms_stime; long tms_cutime; long tms_cstime; }

variable_types: struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }

variable_types:
r
unsigned int *

variable_types: fd int

variable_types: n int

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

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


xfree

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

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

original_code:
void
xfree(void *mem)
{
 free(mem);
}

canonical_original_code:
void xfree(void *mem)
{
 free(mem);
}

variable_types:
mem
void *


error

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

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
return vfprintf(stderr, format, arg);
}

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

va_start(arg, format);
fwrite("ERROR: ", 1uLL, 7uLL, stderr);
return vfprintf(stderr, format, arg);
}

original_code:
void
error(char *format, ...)
{
 va_list ap;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void error(char *format, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "ERROR: ");
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
}

variable_types:
format
char *


xmalloc

decompiled_code:
void *__fastcall xmalloc(unsigned int a1)
{
void *result; // rax

result = malloc((int)a1);
if ( !result )
{
error("xmalloc %d\n", a1);
exit(1);
}
return result;
}

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

result = malloc((int)a1);
if ( !result )
{
func4("xmalloc %d\n", a1);
exit(1);
}
return result;
}

original_code:
void *
xmalloc(int size)
{
 void *mem = malloc(size);
 if (mem == ((void *)0))
 {
  error("xmalloc %d\n", size);
  exit(1);
 }
 return mem;
}

canonical_original_code:
void *xmalloc(int size)
{
 void *mem = malloc(size);
 if (mem == ((void *)0))
 {
  error("xmalloc %d\n", size);
  exit(1);
 }
 return mem;
}

variable_types: size int

return_type: void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, unsigned int a2)
{
void *result; // rax

result = realloc(a1, (int)a2);
if ( !result )
{
error("xrealloc %d\n", a2);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1, unsigned int a2)
{
void *result; // rax

result = realloc(a1, (int)a2);
if ( !result )
{
func4("xrealloc %d\n", a2);
exit(1);
}
return result;
}

original_code:
void *
xrealloc(void *oldmem, int size)
{
 void *mem = realloc(oldmem, size);
 if (mem == ((void *)0))
 {
  error("xrealloc %d\n", size);
  exit(1);
 }
 return mem;
}

canonical_original_code:
void *xrealloc(void *oldmem, int size)
{
 void *mem = realloc(oldmem, size);
 if (mem == ((void *)0))
 {
  error("xrealloc %d\n", size);
  exit(1);
 }
 return mem;
}

variable_types:
oldmem
void *


warning

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

va_start(arg, format);
fwrite("WARNING: ", 1uLL, 9uLL, stderr);
return vfprintf(stderr, format, arg);
}

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

va_start(arg, format);
fwrite("WARNING: ", 1uLL, 9uLL, stderr);
return vfprintf(stderr, format, arg);
}

original_code:
void
warning(char *format, ...)
{
 va_list ap;
 fprintf(stderr, "WARNING: ");
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void warning(char *format, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "WARNING: ");
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
}


unimpl

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

va_start(arg, format);
fwrite("NOT IMPLEMENTED: ", 1uLL, 0x11uLL, stderr);
return vfprintf(stderr, format, arg);
}

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

va_start(arg, format);
fwrite("NOT IMPLEMENTED: ", 1uLL, 0x11uLL, stderr);
return vfprintf(stderr, format, arg);
}

original_code:
void
unimpl(char *format, ...)
{
 va_list ap;
 fprintf(stderr, "NOT IMPLEMENTED: ");
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void unimpl(char *format, ...)
{
 __builtin_va_list ap;
 fprintf(stderr, "NOT IMPLEMENTED: ");
 __builtin_va_start(ap,format);
 vfprintf(stderr, format, ap);
 __builtin_va_end(ap);
}


hexdump

decompiled_code:
int __fastcall hexdump(unsigned __int8 *a1, unsigned int a2)
{
unsigned int v3; // er13
unsigned int v4; // er14
unsigned __int8 *v5; // r15
unsigned __int8 *v6; // rbp
__int64 v7; // rsi
unsigned int v8; // er15
int v9; // edi
int result; // eax

if ( a2 )
{
v3 = 0;
do
{
v4 = 16;
printf("%04x ", v3);
v5 = a1;
if ( a2 - v3 <= 0x10 )
v4 = a2 - v3;
v6 = &a1[v4];
do
{
v7 = *v5++;
printf("%02x ", v7);
}
while ( v6 != v5 );
v8 = v4;
if ( a2 - v3 <= 0xF )
{
do
{
++v8;
printf(" ");
}
while ( v8 != 16 );
}
do
{
v9 = *a1;
if ( (unsigned __int8)(v9 - 32) >= 0x5Fu )
v9 = 46;
++a1;
putchar(v9);
}
while ( v6 != a1 );
v3 += v4;
a1 = v6;
result = putchar(10);
}
while ( a2 > v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned __int8 *a1, unsigned int a2)
{
unsigned int v3; // er13
unsigned int v4; // er14
unsigned __int8 *v5; // r15
unsigned __int8 *v6; // rbp
__int64 v7; // rsi
unsigned int v8; // er15
int v9; // edi
int result; // eax

if ( a2 )
{
v3 = 0;
do
{
v4 = 16;
printf("%04x ", v3);
v5 = a1;
if ( a2 - v3 <= 0x10 )
v4 = a2 - v3;
v6 = &a1[v4];
do
{
v7 = *v5++;
printf("%02x ", v7);
}
while ( v6 != v5 );
v8 = v4;
if ( a2 - v3 <= 0xF )
{
do
{
++v8;
printf(" ");
}
while ( v8 != 16 );
}
do
{
v9 = *a1;
if ( (unsigned __int8)(v9 - 32) >= 0x5Fu )
v9 = 46;
++a1;
putchar(v9);
}
while ( v6 != a1 );
v3 += v4;
a1 = v6;
result = putchar(10);
}
while ( a2 > v3 );
}
return result;
}

original_code:
void
hexdump(unsigned char *p, unsigned int len)
{
 unsigned char *line = p;
 unsigned int thisline, offset = 0;
 int i;
 while (offset < len)
 {
  printf("%04x ", offset);
  thisline = len - offset;
  if (thisline > 16)
   thisline = 16;
  for (i = 0; i < thisline; i++)
   printf("%02x ", line[i]);
  for (; i < 16; i++)
   printf("   ");
  for (i = 0; i < thisline; i++)
   printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
  printf("\n");
  offset += thisline;
  line += thisline;
 }
}

canonical_original_code:
void hexdump(unsigned char *p, unsigned int len)
{
 unsigned char *line = p;
 unsigned int thisline; unsigned int offset = 0;
 int i;
 while (offset < len)
 {
  printf("%04x ", offset);
  thisline = len - offset;
  if (thisline > 16)
   thisline = 16;
  for (i = 0; i < thisline; i++)
   printf("%02x ", line[i]);
  for (; i < 16; i++)
   printf("   ");
  for (i = 0; i < thisline; i++)
   printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
  printf("\n");
  offset += thisline;
  line += thisline;
 }
}

variable_types:
p
unsigned char *

variable_types:
len
unsigned int

variable_types:
line
unsigned char *

variable_types:
thisline
unsigned int

variable_types:
offset
unsigned int

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // er13
int v5; // er12
int v6; // eax
char *v8; // r15
char *v9; // rax
__uid_t v10; // eax
struct passwd *v11; // rax
char *v12; // rax
char *endptr; // [rsp+8h] [rbp-180h] BYREF
char v14[16]; // [rsp+10h] [rbp-178h] BYREF
char v15[16]; // [rsp+20h] [rbp-168h] BYREF
char v16[32]; // [rsp+30h] [rbp-158h] BYREF
char s[64]; // [rsp+50h] [rbp-138h] BYREF
char name[64]; // [rsp+90h] [rbp-F8h] BYREF
char dest[184]; // [rsp+D0h] [rbp-B8h] BYREF

v3 = 51;
v4 = 0;
v5 = 0;
*(_WORD *)&keymapname[4] = 115;
v16[0] = 0;
dest[0] = 0;
v15[0] = 0;
v14[0] = 0;
*(_DWORD *)keymapname = 1965911653;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "u:d:s:c:p:n:k:g:fbemCKT:Dh?");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'C':
owncolmap = 1;
continue;
case 'D':
hide_decorations = 1;
continue;
case 'K':
grab_keyboard = 0;
continue;
case 'T':
strncpy(title, optarg, 0x1FuLL);
title[31] = 0;
continue;
case 'b':
orders = 0;
continue;
case 'c':
strncpy(v16, optarg, 0x1FuLL);
v16[31] = 0;
continue;
case 'd':
strncpy(v14, optarg, 0xFuLL);
v14[15] = 0;
continue;
case 'e':
encryption = 0;
continue;
case 'f':
fullscreen = 1;
continue;
case 'g':
if ( !strcmp(optarg, "workarea") )
{
height = 0;
width = 0;
}
else
{
width = strtol(optarg, &endptr, 10);
if ( *endptr == 120 )
height = strtol(endptr + 1, 0LL, 10);
if ( !width || !height )
{
error("invalid geometry\n");
return 1;
}
}
break;
case 'k':
strncpy(keymapname, optarg, 0xFuLL);
keymapname[15] = 0;
continue;
case 'm':
sendmotion = 0;
continue;
case 'n':
strncpy(&hostname, optarg, 0xFuLL);
*(&hostname + 15) = 0;
continue;
case 'p':
v8 = optarg;
if ( *optarg != 45 || optarg[1] )
{
strncpy(v15, optarg, 0xFuLL);
v15[15] = 0;
for ( endptr = v8; *endptr; v8 = endptr )
{
endptr = v8 + 1;
*v8 = 88;
}
v3 = 59;
}
else
{
v4 = 1;
}
continue;
case 's':
strncpy(dest, optarg, 0x7FuLL);
dest[127] = 0;
continue;
case 'u':
v5 = 1;
strncpy(username, optarg, 0xFuLL);
username[15] = 0;
continue;
default:
goto LABEL_4;
}
}
if ( argc - optind <= 0 )
{
LABEL_4:
usage(*argv);
return 1;
}
strncpy(s, argv[optind], 0x3FuLL);
s[63] = 0;
v9 = strchr(s, 58);
endptr = v9;
if ( v9 )
{
tcp_port_rdp = strtol(v9 + 1, 0LL, 10);
*endptr = 0;
}
if ( !v5 )
{
v10 = getuid();
v11 = getpwuid(v10);
if ( !v11 || !v11->pw_name )
{
error("could not determine username, use -u\n");
return 1;
}
strncpy(username, v11->pw_name, 0xFuLL);
username[15] = 0;
}
if ( !hostname )
{
if ( gethostname(name, 0x40uLL) == -1 )
{
error("could not determine local hostname, use -n\n");
return 1;
}
v12 = strchr(name, 46);
endptr = v12;
if ( v12 )
*v12 = 0;
strncpy(&hostname, name, 0xFuLL);
*(&hostname + 15) = 0;
}
if ( v4 && (unsigned int)read_password_constprop_0(v15) )
v3 = 59;
if ( !title[0] )
{
strcpy(title, "rdesktop - ");
strncat(title, s, 0x14uLL);
}
if ( !(unsigned int)ui_init() || !(unsigned int)rdp_connect(s, v3, v14, v15, dest, v16) )
return 1;
*(_OWORD *)v15 = 0LL;
if ( (unsigned int)ui_create_window() )
{
rdp_main_loop();
ui_destroy_window();
}
rdp_disconnect();
ui_deinit();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
int v4; // er13
int v5; // er12
int v6; // eax
char *v8; // r15
char *v9; // rax
__uid_t v10; // eax
struct passwd *v11; // rax
char *v12; // rax
char *endptr; // [rsp+8h] [rbp-180h] BYREF
char v14[16]; // [rsp+10h] [rbp-178h] BYREF
char v15[16]; // [rsp+20h] [rbp-168h] BYREF
char v16[32]; // [rsp+30h] [rbp-158h] BYREF
char s[64]; // [rsp+50h] [rbp-138h] BYREF
char name[64]; // [rsp+90h] [rbp-F8h] BYREF
char dest[184]; // [rsp+D0h] [rbp-B8h] BYREF

v3 = 51;
v4 = 0;
v5 = 0;
*(_WORD *)&keymapname[4] = 115;
v16[0] = 0;
dest[0] = 0;
v15[0] = 0;
v14[0] = 0;
*(_DWORD *)keymapname = 1965911653;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "u:d:s:c:p:n:k:g:fbemCKT:Dh?");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'C':
owncolmap = 1;
continue;
case 'D':
hide_decorations = 1;
continue;
case 'K':
grab_keyboard = 0;
continue;
case 'T':
strncpy(title, optarg, 0x1FuLL);
title[31] = 0;
continue;
case 'b':
orders = 0;
continue;
case 'c':
strncpy(v16, optarg, 0x1FuLL);
v16[31] = 0;
continue;
case 'd':
strncpy(v14, optarg, 0xFuLL);
v14[15] = 0;
continue;
case 'e':
encryption = 0;
continue;
case 'f':
fullscreen = 1;
continue;
case 'g':
if ( !strcmp(optarg, "workarea") )
{
height = 0;
width = 0;
}
else
{
width = strtol(optarg, &endptr, 10);
if ( *endptr == 120 )
height = strtol(endptr + 1, 0LL, 10);
if ( !width || !height )
{
func4("invalid geometry\n");
return 1;
}
}
break;
case 'k':
strncpy(keymapname, optarg, 0xFuLL);
keymapname[15] = 0;
continue;
case 'm':
sendmotion = 0;
continue;
case 'n':
strncpy(&hostname, optarg, 0xFuLL);
*(&hostname + 15) = 0;
continue;
case 'p':
v8 = optarg;
if ( *optarg != 45 || optarg[1] )
{
strncpy(v15, optarg, 0xFuLL);
v15[15] = 0;
for ( endptr = v8; *endptr; v8 = endptr )
{
endptr = v8 + 1;
*v8 = 88;
}
v3 = 59;
}
else
{
v4 = 1;
}
continue;
case 's':
strncpy(dest, optarg, 0x7FuLL);
dest[127] = 0;
continue;
case 'u':
v5 = 1;
strncpy(username, optarg, 0xFuLL);
username[15] = 0;
continue;
default:
goto LABEL_4;
}
}
if ( argc - optind <= 0 )
{
LABEL_4:
func0(*argv);
return 1;
}
strncpy(s, argv[optind], 0x3FuLL);
s[63] = 0;
v9 = strchr(s, 58);
endptr = v9;
if ( v9 )
{
tcp_port_rdp = strtol(v9 + 1, 0LL, 10);
*endptr = 0;
}
if ( !v5 )
{
v10 = getuid();
v11 = getpwuid(v10);
if ( !v11 || !v11->pw_name )
{
func4("could not determine username, use -u\n");
return 1;
}
strncpy(username, v11->pw_name, 0xFuLL);
username[15] = 0;
}
if ( !hostname )
{
if ( gethostname(name, 0x40uLL) == -1 )
{
func4("could not determine local hostname, use -n\n");
return 1;
}
v12 = strchr(name, 46);
endptr = v12;
if ( v12 )
*v12 = 0;
strncpy(&hostname, name, 0xFuLL);
*(&hostname + 15) = 0;
}
if ( v4 && (unsigned int)func1(v15) )
v3 = 59;
if ( !title[0] )
{
strcpy(title, "rdesktop - ");
strncat(title, s, 0x14uLL);
}
if ( !(unsigned int)ui_init() || !(unsigned int)rdp_connect(s, v3, v14, v15, dest, v16) )
return 1;
*(_OWORD *)v15 = 0LL;
if ( (unsigned int)ui_create_window() )
{
rdp_main_loop();
ui_destroy_window();
}
rdp_disconnect();
ui_deinit();
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 char server[64];
 char fullhostname[64];
 char domain[16];
 char password[16];
 char shell[128];
 char directory[32];
 BOOL prompt_password;
 struct passwd *pw;
 uint32 flags;
 char *p;
 int c;
 int username_option = 0;
 flags = 0x33;
 prompt_password = (0);
 domain[0] = password[0] = shell[0] = directory[0] = 0;
 strcpy(keymapname, "en-us");
 while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemCKT:Dh?")) != -1)
 {
  switch (c)
  {
   case 'u':
    { strncpy(username,optarg,sizeof(username)-1); username[sizeof(username)-1] = 0; };
    username_option = 1;
    break;
   case 'd':
    { strncpy(domain,optarg,sizeof(domain)-1); domain[sizeof(domain)-1] = 0; };
    break;
   case 's':
    { strncpy(shell,optarg,sizeof(shell)-1); shell[sizeof(shell)-1] = 0; };
    break;
   case 'c':
    { strncpy(directory,optarg,sizeof(directory)-1); directory[sizeof(directory)-1] = 0; };
    break;
   case 'p':
    if ((optarg[0] == '-') && (optarg[1] == 0))
    {
     prompt_password = (1);
     break;
    }
    { strncpy(password,optarg,sizeof(password)-1); password[sizeof(password)-1] = 0; };
    flags |= 0x8;
    p = optarg;
    while (*p)
     *(p++) = 'X';
    break;
   case 'n':
    { strncpy(hostname,optarg,sizeof(hostname)-1); hostname[sizeof(hostname)-1] = 0; };
    break;
   case 'k':
    { strncpy(keymapname,optarg,sizeof(keymapname)-1); keymapname[sizeof(keymapname)-1] = 0; };
    break;
   case 'g':
    if (!strcmp(optarg, "workarea"))
    {
     width = height = 0;
     break;
    }
    width = strtol(optarg, &p, 10);
    if (*p == 'x')
     height = strtol(p + 1, ((void *)0), 10);
    if ((width == 0) || (height == 0))
    {
     error("invalid geometry\n");
     return 1;
    }
    break;
   case 'f':
    fullscreen = (1);
    break;
   case 'b':
    orders = (0);
    break;
   case 'e':
    encryption = (0);
    break;
   case 'm':
    sendmotion = (0);
    break;
   case 'C':
    owncolmap = (1);
    break;
   case 'K':
    grab_keyboard = (0);
    break;
   case 'T':
    { strncpy(title,optarg,sizeof(title)-1); title[sizeof(title)-1] = 0; };
    break;
   case 'D':
    hide_decorations = (1);
    break;
   case 'h':
   case '?':
   default:
    usage(argv[0]);
    return 1;
  }
 }
 if (argc - optind < 1)
 {
  usage(argv[0]);
  return 1;
 }
 { strncpy(server,argv[optind],sizeof(server)-1); server[sizeof(server)-1] = 0; };
 p = strchr(server, ':');
 if (p != ((void *)0))
 {
  tcp_port_rdp = strtol(p + 1, ((void *)0), 10);
  *p = 0;
 }
 if (!username_option)
 {
  pw = getpwuid(getuid());
  if ((pw == ((void *)0)) || (pw->pw_name == ((void *)0)))
  {
   error("could not determine username, use -u\n");
   return 1;
  }
  { strncpy(username,pw->pw_name,sizeof(username)-1); username[sizeof(username)-1] = 0; };
 }
 if (hostname[0] == 0)
 {
  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
  {
   error("could not determine local hostname, use -n\n");
   return 1;
  }
  p = strchr(fullhostname, '.');
  if (p != ((void *)0))
   *p = 0;
  { strncpy(hostname,fullhostname,sizeof(hostname)-1); hostname[sizeof(hostname)-1] = 0; };
 }
 if (prompt_password && read_password(password, sizeof(password)))
  flags |= 0x8;
 if (title[0] == 0)
 {
  strcpy(title, "rdesktop - ");
  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));
 }
 if (!ui_init())
  return 1;
 if (!rdp_connect(server, flags, domain, password, shell, directory))
  return 1;
 ;
 memset(password, 0, sizeof(password));
 if (ui_create_window())
 {
  rdp_main_loop();
  ui_destroy_window();
 }
 ;
 rdp_disconnect();
 ui_deinit();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char server[64];
 char fullhostname[64];
 char domain[16];
 char password[16];
 char shell[128];
 char directory[32];
 int prompt_password;
 struct passwd *pw;
 unsigned int flags;
 char *p;
 int c;
 int username_option = 0;
 flags = 0x33;
 prompt_password = (0);
 domain[0] = password[0] = shell[0] = directory[0] = 0;
 strcpy(keymapname, "en-us");
 while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemCKT:Dh?")) != -1)
 {
  switch (c)
  {
   case 'u':
    { strncpy(username,optarg,sizeof(username)-1); username[sizeof(username)-1] = 0; };
    username_option = 1;
    break;
   case 'd':
    { strncpy(domain,optarg,sizeof(domain)-1); domain[sizeof(domain)-1] = 0; };
    break;
   case 's':
    { strncpy(shell,optarg,sizeof(shell)-1); shell[sizeof(shell)-1] = 0; };
    break;
   case 'c':
    { strncpy(directory,optarg,sizeof(directory)-1); directory[sizeof(directory)-1] = 0; };
    break;
   case 'p':
    if ((optarg[0] == '-') && (optarg[1] == 0))
    {
     prompt_password = (1);
     break;
    }
    { strncpy(password,optarg,sizeof(password)-1); password[sizeof(password)-1] = 0; };
    flags |= 0x8;
    p = optarg;
    while (*p)
     *(p++) = 'X';
    break;
   case 'n':
    { strncpy(hostname,optarg,sizeof(hostname)-1); hostname[sizeof(hostname)-1] = 0; };
    break;
   case 'k':
    { strncpy(keymapname,optarg,sizeof(keymapname)-1); keymapname[sizeof(keymapname)-1] = 0; };
    break;
   case 'g':
    if (!strcmp(optarg, "workarea"))
    {
     width = height = 0;
     break;
    }
    width = strtol(optarg, &p, 10);
    if (*p == 'x')
     height = strtol(p + 1, ((void *)0), 10);
    if ((width == 0) || (height == 0))
    {
     error("invalid geometry\n");
     return 1;
    }
    break;
   case 'f':
    fullscreen = (1);
    break;
   case 'b':
    orders = (0);
    break;
   case 'e':
    encryption = (0);
    break;
   case 'm':
    sendmotion = (0);
    break;
   case 'C':
    owncolmap = (1);
    break;
   case 'K':
    grab_keyboard = (0);
    break;
   case 'T':
    { strncpy(title,optarg,sizeof(title)-1); title[sizeof(title)-1] = 0; };
    break;
   case 'D':
    hide_decorations = (1);
    break;
   case 'h':
   case '?':
   default:
    usage(argv[0]);
    return 1;
  }
 }
 if (argc - optind < 1)
 {
  usage(argv[0]);
  return 1;
 }
 { strncpy(server,argv[optind],sizeof(server)-1); server[sizeof(server)-1] = 0; };
 p = strchr(server, ':');
 if (p != ((void *)0))
 {
  tcp_port_rdp = strtol(p + 1, ((void *)0), 10);
  *p = 0;
 }
 if (!username_option)
 {
  pw = getpwuid(getuid());
  if ((pw == ((void *)0)) || (pw->pw_name == ((void *)0)))
  {
   error("could not determine username, use -u\n");
   return 1;
  }
  { strncpy(username,pw->pw_name,sizeof(username)-1); username[sizeof(username)-1] = 0; };
 }
 if (hostname[0] == 0)
 {
  if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
  {
   error("could not determine local hostname, use -n\n");
   return 1;
  }
  p = strchr(fullhostname, '.');
  if (p != ((void *)0))
   *p = 0;
  { strncpy(hostname,fullhostname,sizeof(hostname)-1); hostname[sizeof(hostname)-1] = 0; };
 }
 if (prompt_password && read_password(password, sizeof(password)))
  flags |= 0x8;
 if (title[0] == 0)
 {
  strcpy(title, "rdesktop - ");
  strncat(title, server, sizeof(title) - sizeof("rdesktop - "));
 }
 if (!ui_init())
  return 1;
 if (!rdp_connect(server, flags, domain, password, shell, directory))
  return 1;
 ;
 memset(password, 0, sizeof(password));
 if (ui_create_window())
 {
  rdp_main_loop();
  ui_destroy_window();
 }
 ;
 rdp_disconnect();
 ui_deinit();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
server
char [64]

variable_types:
fullhostname
char [64]

variable_types:
domain
char [16]

variable_types:
password
char [16]

variable_types:
shell
char [128]

variable_types:
directory
char [32]

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *

variable_types:
flags
unsigned int

variable_types:
p
char *

variable_types: c int


variable_types: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; } *


decompiled_code:
__int64 mcs_send_aurq()
{
_QWORD *v0; // rdi
_BYTE *v1; // rax

v0 = (_QWORD *)iso_init(1LL);
v1 = (_BYTE *)(*v0)++;
*v1 = 40;
v0[1] = *v0;
return iso_send();
}

original_code:
static void
mcs_send_aurq(void)
{
 STREAM s;
 s = iso_init(1);
 *((s)->p++) = (MCS_AURQ << 2);;
 (s)->end = (s)->p;;
 iso_send(s);
}

canonical_original_code:
static void mcs_send_aurq()
{
 struct stream *s;
 s = iso_init(1);
 *((s)->p++) = (MCS_AURQ << 2);;
 (s)->end = (s)->p;;
 iso_send(s);
}

user_defined_types: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; }


decompiled_code:
__int64 __fastcall mcs_send_cjrq(__int16 a1)
{
_QWORD *v2; // rdi
_BYTE *v3; // rax
_BYTE *v4; // rax
char v5; // dl
_BYTE *v6; // rax
char v7; // dl
_BYTE *v8; // rax
_BYTE *v9; // rax

v2 = (_QWORD *)iso_init(5LL);
v3 = (_BYTE *)(*v2)++;
*v3 = 56;
v4 = (_BYTE *)*v2;
v5 = HIBYTE(mcs_userid);
++*v2;
*v4 = v5;
v6 = (_BYTE *)*v2;
v7 = mcs_userid;
++*v2;
*v6 = v7;
v8 = (_BYTE *)(*v2)++;
*v8 = HIBYTE(a1);
v9 = (_BYTE *)(*v2)++;
*v9 = a1;
v2[1] = *v2;
return iso_send();
}

canonical_original_code:
static void mcs_send_cjrq(unsigned short chanid)
{
 struct stream *s;
 s = iso_init(5);
 *((s)->p++) = (MCS_CJRQ << 2);;
 { *((s)->p++) = ((mcs_userid) >> 8) & 0xff; *((s)->p++) = (mcs_userid) & 0xff; };
 { *((s)->p++) = ((chanid) >> 8) & 0xff; *((s)->p++) = (chanid) & 0xff; };
 (s)->end = (s)->p;;
 iso_send(s);
}

variable_types:
chanid
unsigned short


decompiled_code:
_BOOL8 mcs_recv_cjcf()
{
unsigned __int8 **v0; // rax
const char *v1; // rdx
int v2; // esi
unsigned __int8 v3; // cl
unsigned __int8 *v4; // rdx
_BOOL8 result; // rax

v0 = (unsigned __int8 **)iso_recv();
if ( !v0 )
return 0LL;
v1 = (const char *)(*v0)++;
v2 = *(unsigned __int8 *)v1;
if ( (unsigned __int8)*v1 >> 2 == 15 )
{
*v0 = (unsigned __int8 *)(v1 + 2);
v3 = v1[1];
if ( v3 )
{
error((int)"CJrq: %d\n", v3, v1);
result = 0LL;
}
else
{
if ( (v2 & 2) != 0 )
v4 = (unsigned __int8 *)(v1 + 8);
else
v4 = (unsigned __int8 *)(v1 + 6);
*v0 = v4;
result = v0[1] == v4;
}
}
else
{
error((int)"expected CJcf, got %d\n", v2, v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 func3()
{
unsigned __int8 **v0; // rax
const char *v1; // rdx
int v2; // esi
unsigned __int8 v3; // cl
unsigned __int8 *v4; // rdx
_BOOL8 result; // rax

v0 = (unsigned __int8 **)iso_recv();
if ( !v0 )
return 0LL;
v1 = (const char *)(*v0)++;
v2 = *(unsigned __int8 *)v1;
if ( (unsigned __int8)*v1 >> 2 == 15 )
{
*v0 = (unsigned __int8 *)(v1 + 2);
v3 = v1[1];
if ( v3 )
{
error((int)"CJrq: %d\n", v3, v1);
result = 0LL;
}
else
{
if ( (v2 & 2) != 0 )
v4 = (unsigned __int8 *)(v1 + 8);
else
v4 = (unsigned __int8 *)(v1 + 6);
*v0 = v4;
result = v0[1] == v4;
}
}
else
{
error((int)"expected CJcf, got %d\n", v2, v1);
result = 0LL;
}
return result;
}

original_code:
static BOOL
mcs_recv_cjcf(void)
{
 uint8 opcode, result;
 STREAM s;
 s = iso_recv();
 if (s == ((void *)0))
  return (0);
 opcode = *((s)->p++);;
 if ((opcode >> 2) != MCS_CJCF)
 {
  error("expected CJcf, got %d\n", opcode);
  return (0);
 }
 result = *((s)->p++);;
 if (result != 0)
 {
  error("CJrq: %d\n", result);
  return (0);
 }
 (s)->p += 4;;
 if (opcode & 2)
  (s)->p += 2;;
 return ((s)->p == (s)->end);
}

canonical_original_code:
static int mcs_recv_cjcf()
{
 unsigned char opcode; unsigned char result;
 struct stream *s;
 s = iso_recv();
 if (s == ((void *)0))
  return (0);
 opcode = *((s)->p++);;
 if ((opcode >> 2) != MCS_CJCF)
 {
  error("expected CJcf, got %d\n", opcode);
  return (0);
 }
 result = *((s)->p++);;
 if (result != 0)
 {
  error("CJrq: %d\n", result);
  return (0);
 }
 (s)->p += 4;;
 if (opcode & 2)
  (s)->p += 2;;
 return ((s)->p == (s)->end);
}

variable_types:
opcode
unsigned char

variable_types:
result
unsigned char


decompiled_code:
__int64 __fastcall mcs_send_connect_initial(__int64 a1)
{
__int64 v1; // rbx
void **v2; // rbp
int v3; // edx
_BYTE *v4; // rax
char *v5; // rbx

v1 = *(_QWORD *)(a1 + 8) - *(_QWORD *)(a1 + 16);
v2 = (void **)iso_init((unsigned int)(v1 + 118));
ber_out_header(v2, 32613, v1 + 113);
ber_out_header(v2, 4, 0);
ber_out_header(v2, 4, v3);
ber_out_header(v2, 1, 1);
v4 = *v2;
*v2 = (char *)*v2 + 1;
*v4 = -1;
mcs_out_domain_params(v2);
mcs_out_domain_params(v2);
mcs_out_domain_params(v2);
ber_out_header(v2, 4, v1);
memcpy(*v2, *(const void **)(a1 + 16), (int)v1);
v5 = (char *)*v2 + (int)v1;
*v2 = v5;
v2[1] = v5;
return iso_send(v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
void **v2; // rbp
int v3; // edx
_BYTE *v4; // rax
char *v5; // rbx

v1 = *(_QWORD *)(a1 + 8) - *(_QWORD *)(a1 + 16);
v2 = (void **)iso_init((unsigned int)(v1 + 118));
ber_out_header(v2, 32613, v1 + 113);
ber_out_header(v2, 4, 0);
ber_out_header(v2, 4, v3);
ber_out_header(v2, 1, 1);
v4 = *v2;
*v2 = (char *)*v2 + 1;
*v4 = -1;
mcs_out_domain_params(v2);
mcs_out_domain_params(v2);
mcs_out_domain_params(v2);
ber_out_header(v2, 4, v1);
memcpy(*v2, *(const void **)(a1 + 16), (int)v1);
v5 = (char *)*v2 + (int)v1;
*v2 = v5;
v2[1] = v5;
return iso_send(v2);
}

original_code:
static void
mcs_send_connect_initial(STREAM mcs_data)
{
 int datalen = mcs_data->end - mcs_data->data;
 int length = 7 + 3 * 34 + 4 + datalen;
 STREAM s;
 s = iso_init(length + 5);
 ber_out_header(s, 0x7f65, length);
 ber_out_header(s, 4, 0);
 ber_out_header(s, 4, 0);
 ber_out_header(s, 1, 1);
 *((s)->p++) = 0xff;;
 mcs_out_domain_params(s, 2, 2, 0, 0xffff);
 mcs_out_domain_params(s, 1, 1, 1, 0x420);
 mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff);
 ber_out_header(s, 4, datalen);
 { memcpy((s)->p,mcs_data->data,datalen); (s)->p += datalen; };
 (s)->end = (s)->p;;
 iso_send(s);
}

canonical_original_code:
static void mcs_send_connect_initial(struct stream *mcs_data)
{
 int datalen = mcs_data->end - mcs_data->data;
 int length = 7 + 3 * 34 + 4 + datalen;
 struct stream *s;
 s = iso_init(length + 5);
 ber_out_header(s, 0x7f65, length);
 ber_out_header(s, 4, 0);
 ber_out_header(s, 4, 0);
 ber_out_header(s, 1, 1);
 *((s)->p++) = 0xff;;
 mcs_out_domain_params(s, 2, 2, 0, 0xffff);
 mcs_out_domain_params(s, 1, 1, 1, 0x420);
 mcs_out_domain_params(s, 0xffff, 0xfc17, 0xffff, 0xffff);
 ber_out_header(s, 4, datalen);
 { memcpy((s)->p,mcs_data->data,datalen); (s)->p += datalen; };
 (s)->end = (s)->p;;
 iso_send(s);
}

variable_types: datalen int

variable_types: length int


decompiled_code:
__int64 __fastcall mcs_recv_connect_response(__int64 a1)
{
unsigned int v1; // er12
unsigned __int8 **v2; // rax
unsigned __int8 **v3; // rbx
unsigned __int8 *v4; // rax
const char *v5; // rdx
int v6; // esi
const char *v7; // rdx
int v8; // esi
__int64 v9; // rdx
__int64 v10; // rax
int errnum[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 0;
v2 = (unsigned __int8 **)iso_recv();
if ( !v2 )
return v1;
v3 = v2;
ber_parse_header_isra_0(v2, 32614, errnum);
ber_parse_header_isra_0(v3, 10, errnum);
v4 = *v3;
v5 = (const char *)(*v3 + 1);
*v3 = (unsigned __int8 *)v5;
v6 = *v4;
if ( !(_BYTE)v6 )
{
ber_parse_header_isra_0(v3, 2, errnum);
*v3 += errnum[0];
mcs_parse_domain_params_isra_0(v3);
ber_parse_header_isra_0(v3, 4, errnum);
v8 = errnum[0];
if ( *(_DWORD *)(a1 + 24) < errnum[0] )
{
error((int)"MCS data length %d\n", errnum[0], v7);
v8 = *(_DWORD *)(a1 + 24);
errnum[0] = v8;
}
memcpy(*(void **)(a1 + 16), *v3, v8);
v9 = errnum[0];
v10 = *(_QWORD *)(a1 + 16);
*v3 += errnum[0];
*(_QWORD *)a1 = v10;
*(_QWORD *)(a1 + 8) = v9 + v10;
return *v3 == v3[1];
}
error((int)"MCS connect: %d\n", v6, v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v1; // er12
unsigned __int8 **v2; // rax
unsigned __int8 **v3; // rbx
unsigned __int8 *v4; // rax
const char *v5; // rdx
int v6; // esi
const char *v7; // rdx
int v8; // esi
__int64 v9; // rdx
__int64 v10; // rax
int errnum[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = 0;
v2 = (unsigned __int8 **)iso_recv();
if ( !v2 )
return v1;
v3 = v2;
func6(v2, 32614, errnum);
func6(v3, 10, errnum);
v4 = *v3;
v5 = (const char *)(*v3 + 1);
*v3 = (unsigned __int8 *)v5;
v6 = *v4;
if ( !(_BYTE)v6 )
{
func6(v3, 2, errnum);
*v3 += errnum[0];
func7(v3);
func6(v3, 4, errnum);
v8 = errnum[0];
if ( *(_DWORD *)(a1 + 24) < errnum[0] )
{
error((int)"MCS data length %d\n", errnum[0], v7);
v8 = *(_DWORD *)(a1 + 24);
errnum[0] = v8;
}
memcpy(*(void **)(a1 + 16), *v3, v8);
v9 = errnum[0];
v10 = *(_QWORD *)(a1 + 16);
*v3 += errnum[0];
*(_QWORD *)a1 = v10;
*(_QWORD *)(a1 + 8) = v9 + v10;
return *v3 == v3[1];
}
error((int)"MCS connect: %d\n", v6, v5);
return 0LL;
}

original_code:
static BOOL
mcs_recv_connect_response(STREAM mcs_data)
{
 uint8 result;
 int length;
 STREAM s;
 s = iso_recv();
 if (s == ((void *)0))
  return (0);
 ber_parse_header(s, 0x7f66, &length);
 ber_parse_header(s, 10, &length);
 result = *((s)->p++);;
 if (result != 0)
 {
  error("MCS connect: %d\n", result);
  return (0);
 }
 ber_parse_header(s, 2, &length);
 (s)->p += length;;
 mcs_parse_domain_params(s);
 ber_parse_header(s, 4, &length);
 if (length > mcs_data->size)
 {
  error("MCS data length %d\n", length);
  length = mcs_data->size;
 }
 { memcpy(mcs_data->data,(s)->p,length); (s)->p += length; };
 mcs_data->p = mcs_data->data;
 mcs_data->end = mcs_data->data + length;
 return ((s)->p == (s)->end);
}

canonical_original_code:
static int mcs_recv_connect_response(struct stream *mcs_data)
{
 unsigned char result;
 int length;
 struct stream *s;
 s = iso_recv();
 if (s == ((void *)0))
  return (0);
 ber_parse_header(s, 0x7f66, &length);
 ber_parse_header(s, 10, &length);
 result = *((s)->p++);;
 if (result != 0)
 {
  error("MCS connect: %d\n", result);
  return (0);
 }
 ber_parse_header(s, 2, &length);
 (s)->p += length;;
 mcs_parse_domain_params(s);
 ber_parse_header(s, 4, &length);
 if (length > mcs_data->size)
 {
  error("MCS data length %d\n", length);
  length = mcs_data->size;
 }
 { memcpy(mcs_data->data,(s)->p,length); (s)->p += length; };
 mcs_data->p = mcs_data->data;
 mcs_data->end = mcs_data->data + length;
 return ((s)->p == (s)->end);
}


variable_types:
length
unsigned short


decompiled_code:
_QWORD *mcs_recv()
{
_QWORD *result; // rax
const char *v1; // rdx
char v2; // cl

result = (_QWORD *)iso_recv();
if ( !result )
return 0LL;
v1 = (const char *)(*result)++;
v2 = (unsigned __int8)*v1 >> 2;
if ( v2 != 26 )
{
if ( v2 != 8 )
{
error((int)"expected data, got %d\n", *(unsigned __int8 *)v1, v1);
return 0LL;
}
return 0LL;
}
*result = v1 + 7;
if ( v1[6] < 0 )
*result = v1 + 8;
return result;
}

canonical_decompiled_code:
_QWORD *func10()
{
_QWORD *result; // rax
const char *v1; // rdx
char v2; // cl

result = (_QWORD *)iso_recv();
if ( !result )
return 0LL;
v1 = (const char *)(*result)++;
v2 = (unsigned __int8)*v1 >> 2;
if ( v2 != 26 )
{
if ( v2 != 8 )
{
error((int)"expected data, got %d\n", *(unsigned __int8 *)v1, v1);
return 0LL;
}
return 0LL;
}
*result = v1 + 7;
if ( v1[6] < 0 )
*result = v1 + 8;
return result;
}

original_code:
STREAM
mcs_recv(void)
{
 uint8 opcode, appid, length;
 STREAM s;
 s = iso_recv();
 if (s == ((void *)0))
  return ((void *)0);
 opcode = *((s)->p++);;
 appid = opcode >> 2;
 if (appid != MCS_SDIN)
 {
  if (appid != MCS_DPUM)
  {
   error("expected data, got %d\n", opcode);
  }
  return ((void *)0);
 }
 (s)->p += 5;;
 length = *((s)->p++);;
 if (length & 0x80)
  (s)->p += 1;;
 return s;
}

canonical_original_code:
struct stream *mcs_recv()
{
 unsigned char opcode; unsigned char appid; unsigned char length;
 struct stream *s;
 s = iso_recv();
 if (s == ((void *)0))
  return ((void *)0);
 opcode = *((s)->p++);;
 appid = opcode >> 2;
 if (appid != MCS_SDIN)
 {
  if (appid != MCS_DPUM)
  {
   error("expected data, got %d\n", opcode);
  }
  return ((void *)0);
 }
 (s)->p += 5;;
 length = *((s)->p++);;
 if (length & 0x80)
  (s)->p += 1;;
 return s;
}

variable_types:
appid
unsigned char

variable_types:
length
unsigned char

return_type: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; } *


decompiled_code:
__int64 __fastcall mcs_connect(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = iso_connect();
if ( (_DWORD)result )
{
mcs_send_connect_initial(a2);
if ( (unsigned int)mcs_recv_connect_response(a2)
&& (mcs_send_edrq(), mcs_send_aurq(), mcs_recv_aucf_constprop_0())
&& (mcs_send_cjrq(mcs_userid + 1001), mcs_recv_cjcf())
&& (mcs_send_cjrq(1003), mcs_recv_cjcf()) )
{
result = 1LL;
}
else
{
iso_disconnect();
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = iso_connect();
if ( (_DWORD)result )
{
func4(a2);
if ( (unsigned int)func8(a2)
&& (func0(), func1(), func5())
&& (func2(mcs_userid + 1001), func3())
&& (func2(1003), func3()) )
{
result = 1LL;
}
else
{
iso_disconnect();
result = 0LL;
}
}
return result;
}

original_code:
BOOL
mcs_connect(char *server, STREAM mcs_data)
{
 if (!iso_connect(server))
  return (0);
 mcs_send_connect_initial(mcs_data);
 if (!mcs_recv_connect_response(mcs_data))
  goto error;
 mcs_send_edrq();
 mcs_send_aurq();
 if (!mcs_recv_aucf(&mcs_userid))
  goto error;
 mcs_send_cjrq(mcs_userid + 1001);
 if (!mcs_recv_cjcf())
  goto error;
 mcs_send_cjrq(1003);
 if (!mcs_recv_cjcf())
  goto error;
 return (1);
      error:
 iso_disconnect();
 return (0);
}

canonical_original_code:
int mcs_connect(char *server, struct stream *mcs_data)
{
 if (!iso_connect(server))
  return (0);
 mcs_send_connect_initial(mcs_data);
 if (!mcs_recv_connect_response(mcs_data))
  goto error;
 mcs_send_edrq();
 mcs_send_aurq();
 if (!mcs_recv_aucf(&mcs_userid))
  goto error;
 mcs_send_cjrq(mcs_userid + 1001);
 if (!mcs_recv_cjcf())
  goto error;
 mcs_send_cjrq(1003);
 if (!mcs_recv_cjcf())
  goto error;
 return (1);
      error:
 iso_disconnect();
 return (0);
}

variable_types:
server
char *


decompiled_code:
// attributes: thunk
__int64 mcs_disconnect()
{
return iso_disconnect();
}

canonical_decompiled_code:
__int64 func12()
{
return iso_disconnect();
}

original_code:
void
mcs_disconnect(void)
{
 iso_disconnect();
}

canonical_original_code:
void mcs_disconnect()
{
 iso_disconnect();
}


decompiled_code:
__int64 __fastcall licence_generate_keys(__int64 a1, __int64 a2, __int64 a3)
{
__m128i v4; // [rsp+0h] [rbp-78h] BYREF
char v5[32]; // [rsp+10h] [rbp-68h] BYREF
char v6[72]; // [rsp+30h] [rbp-48h] BYREF

sec_hash_48(v6, a3, a1, a2, 65LL);
sec_hash_48(&v4, v6, a2, a1, 65LL);
licence_sign_key = (__int128)_mm_loadu_si128(&v4);
return sec_hash_16(&licence_key, v5, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__m128i v4; // [rsp+0h] [rbp-78h] BYREF
char v5[32]; // [rsp+10h] [rbp-68h] BYREF
char v6[72]; // [rsp+30h] [rbp-48h] BYREF

sec_hash_48(v6, a3, a1, a2, 65LL);
sec_hash_48(&v4, v6, a2, a1, 65LL);
licence_sign_key = (__int128)_mm_loadu_si128(&v4);
return sec_hash_16(&licence_key, v5, a1, a2);
}

original_code:
static void
licence_generate_keys(uint8 * client_key, uint8 * server_key, uint8 * client_rsa)
{
 uint8 session_key[48];
 uint8 temp_hash[48];
 sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65);
 sec_hash_48(session_key, temp_hash, server_key, client_key, 65);
 memcpy(licence_sign_key, session_key, 16);
 sec_hash_16(licence_key, &session_key[16], client_key, server_key);
}

canonical_original_code:
static void licence_generate_keys(unsigned char *client_key, unsigned char *server_key, unsigned char *client_rsa)
{
 unsigned char session_key[48];
 unsigned char temp_hash[48];
 sec_hash_48(temp_hash, client_rsa, client_key, server_key, 65);
 sec_hash_48(session_key, temp_hash, server_key, client_key, 65);
 memcpy(licence_sign_key, session_key, 16);
 sec_hash_16(licence_key, &session_key[16], client_key, server_key);
}


variable_types:
token
unsigned char *

variable_types:
signature
unsigned char *


decompiled_code:
unsigned __int64 __fastcall licence_process_issue(__int64 *a1)
{
__int64 v1; // rdx
int v2; // ecx
__int64 v3; // rbp
unsigned __int64 result; // rax
unsigned __int8 *v5; // rax
__int64 v6; // rcx
__int16 v7; // dx
_BYTE v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v1 = *a1;
*a1 += 3LL;
v2 = *(unsigned __int8 *)(v1 + 2);
*a1 = v1 + 4;
v3 = v2 + (*(unsigned __int8 *)(v1 + 3) << 8);
result = v3 + v1 + 4;
if ( a1[1] >= result )
{
RC4_set_key(v8, 16LL, &licence_key);
RC4(v8, v3, *a1, *a1);
v5 = (unsigned __int8 *)*a1;
v6 = *a1 + 2;
++*a1;
v7 = *v5;
*a1 = v6;
result = v5[1] << 8;
if ( !((_WORD)result + v7) )
licence_issued = 1;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 *a1)
{
__int64 v1; // rdx
int v2; // ecx
__int64 v3; // rbp
unsigned __int64 result; // rax
unsigned __int8 *v5; // rax
__int64 v6; // rcx
__int16 v7; // dx
_BYTE v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v1 = *a1;
*a1 += 3LL;
v2 = *(unsigned __int8 *)(v1 + 2);
*a1 = v1 + 4;
v3 = v2 + (*(unsigned __int8 *)(v1 + 3) << 8);
result = v3 + v1 + 4;
if ( a1[1] >= result )
{
RC4_set_key(v8, 16LL, &licence_key);
RC4(v8, v3, *a1, *a1);
v5 = (unsigned __int8 *)*a1;
v6 = *a1 + 2;
++*a1;
v7 = *v5;
*a1 = v6;
result = v5[1] << 8;
if ( !((_WORD)result + v7) )
licence_issued = 1;
}
return result;
}

original_code:
static void
licence_process_issue(STREAM s)
{
 RC4_KEY crypt_key;
 uint32 length;
 uint16 check;
 (s)->p += 2;;
 { length = *((s)->p++); length += *((s)->p++) << 8; };
 if (!((s)->p + length <= (s)->end))
  return;
 RC4_set_key(&crypt_key, 16, licence_key);
 RC4(&crypt_key, length, s->p, s->p);
 { check = *((s)->p++); check += *((s)->p++) << 8; };
 if (check != 0)
  return;
 licence_issued = (1);
}

canonical_original_code:
static void licence_process_issue(struct stream *s)
{
 struct rc4_key_st crypt_key;
 unsigned int length;
 unsigned short check;
 (s)->p += 2;;
 { length = *((s)->p++); length += *((s)->p++) << 8; };
 if (!((s)->p + length <= (s)->end))
  return;
 RC4_set_key(&crypt_key, 16, licence_key);
 RC4(&crypt_key, length, s->p, s->p);
 { check = *((s)->p++); check += *((s)->p++) << 8; };
 if (check != 0)
  return;
 licence_issued = (1);
}

variable_types: struct rc4_key_st { unsigned int x; unsigned int data[256]; }

variable_types:
length
unsigned int

variable_types:
check
unsigned short


decompiled_code:
char *__fastcall licence_generate_hwid(__int64 a1)
{
buf_out_uint32(a1, 2LL);
return strncpy((char *)(a1 + 4), &hostname, 0x10uLL);
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1)
{
buf_out_uint32(a1, 2LL);
return strncpy((char *)(a1 + 4), &hostname, 0x10uLL);
}

original_code:
static void
licence_generate_hwid(uint8 * hwid)
{
 buf_out_uint32(hwid, 2);
 strncpy((char *) (hwid + 4), hostname, 20 - 4);
}

canonical_original_code:
static void licence_generate_hwid(unsigned char *hwid)
{
 buf_out_uint32(hwid, 2);
 strncpy((char *) (hwid + 4), hostname, 20 - 4);
}

variable_types:
hwid
unsigned char *


decompiled_code:
__int64 __fastcall licence_process_demand(__int64 *a1)
{
__int64 v1; // rsi
__m128i v3[4]; // [rsp+0h] [rbp-48h] BYREF

v1 = *a1;
v3[0] = 0LL;
v3[1] = 0LL;
*a1 = v1 + 32;
v3[2] = 0LL;
v3[3] = 0LL;
licence_generate_keys((__int64)v3, v1, (__int64)v3);
return licence_send_request_constprop_0(v3, v3);
}

original_code:
static void
licence_process_demand(STREAM s)
{
 uint8 null_data[64];
 uint8 *server_random;
 { server_random = (s)->p; (s)->p += 32; };
 memset(null_data, 0, sizeof(null_data));
 licence_generate_keys(null_data, server_random, null_data);
 licence_send_request(null_data, null_data, username, hostname);
}

canonical_original_code:
static void licence_process_demand(struct stream *s)
{
 unsigned char null_data[64];
 unsigned char *server_random;
 { server_random = (s)->p; (s)->p += 32; };
 memset(null_data, 0, sizeof(null_data));
 licence_generate_keys(null_data, server_random, null_data);
 licence_send_request(null_data, null_data, username, hostname);
}


original_code:
static void
licence_process_authreq(STREAM s)
{
 uint8 *in_token, *in_sig;
 uint8 out_token[10], decrypt_token[10];
 uint8 hwid[20], crypt_hwid[20];
 uint8 sealed_buffer[10 + 20];
 uint8 out_sig[16];
 RC4_KEY crypt_key;
 licence_parse_authreq(s, &in_token, &in_sig);
 memcpy(out_token, in_token, 10);
 RC4_set_key(&crypt_key, 16, licence_key);
 RC4(&crypt_key, 10, in_token, decrypt_token);
 licence_generate_hwid(hwid);
 memcpy(sealed_buffer, decrypt_token, 10);
 memcpy(sealed_buffer + 10, hwid, 20);
 sec_sign(out_sig, 16, licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer));
 RC4_set_key(&crypt_key, 16, licence_key);
 RC4(&crypt_key, 20, hwid, crypt_hwid);
 licence_send_authresp(out_token, crypt_hwid, out_sig);
}

canonical_original_code:
static void licence_process_authreq(struct stream *s)
{
 unsigned char *in_token; unsigned char *in_sig;
 unsigned char out_token[10]; unsigned char decrypt_token[10];
 unsigned char hwid[20]; unsigned char crypt_hwid[20];
 unsigned char sealed_buffer[-1];
 unsigned char out_sig[16];
 struct rc4_key_st crypt_key;
 licence_parse_authreq(s, &in_token, &in_sig);
 memcpy(out_token, in_token, 10);
 RC4_set_key(&crypt_key, 16, licence_key);
 RC4(&crypt_key, 10, in_token, decrypt_token);
 licence_generate_hwid(hwid);
 memcpy(sealed_buffer, decrypt_token, 10);
 memcpy(sealed_buffer + 10, hwid, 20);
 sec_sign(out_sig, 16, licence_sign_key, 16, sealed_buffer, sizeof(sealed_buffer));
 RC4_set_key(&crypt_key, 16, licence_key);
 RC4(&crypt_key, 20, hwid, crypt_hwid);
 licence_send_authresp(out_token, crypt_hwid, out_sig);
}

variable_types:
hwid
unsigned char [20]

user_defined_types: struct rc4_key_st { unsigned int x; unsigned int data[256]; }


decompiled_code:
unsigned __int64 __fastcall licence_process(__int64 *a1)
{
__int64 v1; // rcx
__int64 v2; // rdx
unsigned __int64 result; // rax
__int16 v4; // si
unsigned __int16 v5; // si

v1 = *a1 + 2;
v2 = *a1 + 4;
++*a1;
result = *(unsigned __int8 *)(v2 - 4);
*a1 = v1;
v4 = *(unsigned __int8 *)(v2 - 3);
*a1 = v2;
v5 = result + (v4 << 8);
if ( v5 == 515 )
return licence_process_issue(a1);
if ( v5 > 0x203u )
{
if ( v5 != 516 && v5 != 767 )
return unimpl("licence tag 0x%x\n", v5);
}
else
{
if ( v5 != 513 )
{
if ( v5 == 514 )
return licence_process_authreq(a1);
return unimpl("licence tag 0x%x\n", v5);
}
result = licence_process_demand(a1);
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 *a1)
{
__int64 v1; // rcx
__int64 v2; // rdx
unsigned __int64 result; // rax
__int16 v4; // si
unsigned __int16 v5; // si

v1 = *a1 + 2;
v2 = *a1 + 4;
++*a1;
result = *(unsigned __int8 *)(v2 - 4);
*a1 = v1;
v4 = *(unsigned __int8 *)(v2 - 3);
*a1 = v2;
v5 = result + (v4 << 8);
if ( v5 == 515 )
return func2(a1);
if ( v5 > 0x203u )
{
if ( v5 != 516 && v5 != 767 )
return unimpl("licence tag 0x%x\n", v5);
}
else
{
if ( v5 != 513 )
{
if ( v5 == 514 )
return func7(a1);
return unimpl("licence tag 0x%x\n", v5);
}
result = func5(a1);
}
return result;
}

original_code:
void
licence_process(STREAM s)
{
 uint16 tag;
 { tag = *((s)->p++); tag += *((s)->p++) << 8; };
 (s)->p += 2;;
 switch (tag)
 {
  case 0x0201:
   licence_process_demand(s);
   break;
  case 0x0202:
   licence_process_authreq(s);
   break;
  case 0x0203:
   licence_process_issue(s);
   break;
  case 0x0204:
   break;
  case 0x02ff:
   break;
  default:
   unimpl("licence tag 0x%x\n", tag);
 }
}

canonical_original_code:
void licence_process(struct stream *s)
{
 unsigned short tag;
 { tag = *((s)->p++); tag += *((s)->p++) << 8; };
 (s)->p += 2;;
 switch (tag)
 {
  case 0x0201:
   licence_process_demand(s);
   break;
  case 0x0202:
   licence_process_authreq(s);
   break;
  case 0x0203:
   licence_process_issue(s);
   break;
  case 0x0204:
   break;
  case 0x02ff:
   break;
  default:
   unimpl("licence tag 0x%x\n", tag);
 }
}

variable_types: struct stream { unsigned char *p; unsigned char *end; unsigned char *data; unsigned int size; unsigned char *iso_hdr; unsigned char *mcs_hdr; unsigned char *sec_hdr; unsigned char *rdp_hdr; } *

variable_types:
tag
unsigned short


decompiled_code:
void __fastcall update_modifier_state(unsigned __int8 a1, int a2)
{
__int16 v2; // dx
__int16 v3; // dx
__int16 v4; // dx
__int16 v5; // dx
__int16 v6; // dx
__int16 v7; // cx
__int16 v8; // ax
__int16 v9; // ax
__int16 v10; // dx
__int16 v11; // dx

if ( a1 == 69 )
{
if ( a2 )
{
LOBYTE(v8) = remote_modifier_state;
LOBYTE(v7) = remote_modifier_state;
HIBYTE(v8) = HIBYTE(remote_modifier_state) & 0xFE;
if ( (remote_modifier_state & 0x100) == 0 )
{
HIBYTE(v7) = HIBYTE(remote_modifier_state) | 1;
v8 = v7;
}
remote_modifier_state = v8;
}
}
else if ( a1 <= 0x45u )
{
if ( a1 == 54 )
{
remote_modifier_state = remote_modifier_state & 0xFFFE | a2;
}
else if ( a1 <= 0x36u )
{
if ( a1 == 29 )
{
v6 = remote_modifier_state & 0xFFDF;
if ( a2 )
v6 = remote_modifier_state | 0x20;
remote_modifier_state = v6;
}
else if ( a1 == 42 )
{
v5 = remote_modifier_state & 0xFFFD;
if ( a2 )
v5 = remote_modifier_state | 2;
remote_modifier_state = v5;
}
}
else if ( a1 == 56 )
{
v3 = remote_modifier_state & 0xFFF7;
if ( a2 )
v3 = remote_modifier_state | 8;
remote_modifier_state = v3;
}
}
else if ( a1 == 0xDB )
{
HIBYTE(v9) = HIBYTE(remote_modifier_state);
HIBYTE(v10) = HIBYTE(remote_modifier_state);
LOBYTE(v10) = remote_modifier_state & 0x7F;
if ( a2 )
{
LOBYTE(v9) = remote_modifier_state | 0x80;
v10 = v9;
}
remote_modifier_state = v10;
}
else if ( a1 <= 0xDBu )
{
if ( a1 == 0x9D )
{
v11 = remote_modifier_state & 0xFFEF;
if ( a2 )
v11 = remote_modifier_state | 0x10;
remote_modifier_state = v11;
}
else if ( a1 == 0xB8 )
{
v4 = remote_modifier_state & 0xFFFB;
if ( a2 )
v4 = remote_modifier_state | 4;
remote_modifier_state = v4;
}
}
else if ( a1 == 0xDC )
{
v2 = remote_modifier_state & 0xFFBF;
if ( a2 )
v2 = remote_modifier_state | 0x40;
remote_modifier_state = v2;
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int8 a1, int a2)
{
__int16 v2; // dx
__int16 v3; // dx
__int16 v4; // dx
__int16 v5; // dx
__int16 v6; // dx
__int16 v7; // cx
__int16 v8; // ax
__int16 v9; // ax
__int16 v10; // dx
__int16 v11; // dx

if ( a1 == 69 )
{
if ( a2 )
{
LOBYTE(v8) = remote_modifier_state;
LOBYTE(v7) = remote_modifier_state;
HIBYTE(v8) = HIBYTE(remote_modifier_state) & 0xFE;
if ( (remote_modifier_state & 0x100) == 0 )
{
HIBYTE(v7) = HIBYTE(remote_modifier_state) | 1;
v8 = v7;
}
remote_modifier_state = v8;
}
}
else if ( a1 <= 0x45u )
{
if ( a1 == 54 )
{
remote_modifier_state = remote_modifier_state & 0xFFFE | a2;
}
else if ( a1 <= 0x36u )
{
if ( a1 == 29 )
{
v6 = remote_modifier_state & 0xFFDF;
if ( a2 )
v6 = remote_modifier_state | 0x20;
remote_modifier_state = v6;
}
else if ( a1 == 42 )
{
v5 = remote_modifier_state & 0xFFFD;
if ( a2 )
v5 = remote_modifier_state | 2;
remote_modifier_state = v5;
}
}
else if ( a1 == 56 )
{
v3 = remote_modifier_state & 0xFFF7;
if ( a2 )
v3 = remote_modifier_state | 8;
remote_modifier_state = v3;
}
}
else if ( a1 == 0xDB )
{
HIBYTE(v9) = HIBYTE(remote_modifier_state);
HIBYTE(v10) = HIBYTE(remote_modifier_state);
LOBYTE(v10) = remote_modifier_state & 0x7F;
if ( a2 )
{
LOBYTE(v9) = remote_modifier_state | 0x80;
v10 = v9;
}
remote_modifier_state = v10;
}
else if ( a1 <= 0xDBu )
{
if ( a1 == 0x9D )
{
v11 = remote_modifier_state & 0xFFEF;
if ( a2 )
v11 = remote_modifier_state | 0x10;
remote_modifier_state = v11;
}
else if ( a1 == 0xB8 )
{
v4 = remote_modifier_state & 0xFFFB;
if ( a2 )
v4 = remote_modifier_state | 4;
remote_modifier_state = v4;
}
}
else if ( a1 == 0xDC )
{
v2 = remote_modifier_state & 0xFFBF;
if ( a2 )
v2 = remote_modifier_state | 0x40;
remote_modifier_state = v2;
}
}

original_code:
static void
update_modifier_state(uint8 scancode, BOOL pressed)
{
 switch (scancode)
 {
  case 0x2a:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<1)) | (pressed ? (1<<1) : 0)));
   break;
  case 0x36:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<0)) | (pressed ? (1<<0) : 0)));
   break;
  case 0x1d:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<5)) | (pressed ? (1<<5) : 0)));
   break;
  case (0x80 | 0x1d):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<4)) | (pressed ? (1<<4) : 0)));
   break;
  case 0x38:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<3)) | (pressed ? (1<<3) : 0)));
   break;
  case (0x80 | 0x38):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<2)) | (pressed ? (1<<2) : 0)));
   break;
  case (0x80 | 0x5b):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<7)) | (pressed ? (1<<7) : 0)));
   break;
  case (0x80 | 0x5c):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<6)) | (pressed ? (1<<6) : 0)));
   break;
  case 0x45:
   if (pressed)
   {
    BOOL newNumLockState;
    newNumLockState =
     (((remote_modifier_state & (1<<8))>0) == 0);
    (remote_modifier_state = ((remote_modifier_state & ~(1<<8)) | (newNumLockState ? (1<<8) : 0)));
   }
   break;
 }
}

canonical_original_code:
static void update_modifier_state(unsigned char scancode, int pressed)
{
 switch (scancode)
 {
  case 0x2a:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<1)) | (pressed ? (1<<1) : 0)));
   break;
  case 0x36:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<0)) | (pressed ? (1<<0) : 0)));
   break;
  case 0x1d:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<5)) | (pressed ? (1<<5) : 0)));
   break;
  case (0x80 | 0x1d):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<4)) | (pressed ? (1<<4) : 0)));
   break;
  case 0x38:
   (remote_modifier_state = ((remote_modifier_state & ~(1<<3)) | (pressed ? (1<<3) : 0)));
   break;
  case (0x80 | 0x38):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<2)) | (pressed ? (1<<2) : 0)));
   break;
  case (0x80 | 0x5b):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<7)) | (pressed ? (1<<7) : 0)));
   break;
  case (0x80 | 0x5c):
   (remote_modifier_state = ((remote_modifier_state & ~(1<<6)) | (pressed ? (1<<6) : 0)));
   break;
  case 0x45:
   if (pressed)
   {
    int newNumLockState;
    newNumLockState =
     (((remote_modifier_state & (1<<8))>0) == 0);
    (remote_modifier_state = ((remote_modifier_state & ~(1<<8)) | (newNumLockState ? (1<<8) : 0)));
   }
   break;
 }
}

variable_types:
scancode
unsigned char

variable_types: pressed int

variable_types: newNumLockState int


decompiled_code:
KeySym __fastcall add_to_keymap(const char *a1, char a2, __int16 a3, const char *a4)
{
KeySym result; // rax

result = XStringToKeysym(a1);
if ( !result )
return warning("Bad keysym %s in keymap %s\n", a1, a4);
result = (unsigned __int16)result;
keymap[4 * (unsigned __int16)result] = a2;
word_D42[2 * (unsigned __int16)result] = a3;
return result;
}

canonical_decompiled_code:
KeySym __fastcall func1(const char *a1, char a2, __int16 a3, const char *a4)
{
KeySym result; // rax

result = XStringToKeysym(a1);
if ( !result )
return warning("Bad keysym %s in keymap %s\n", a1, a4);
result = (unsigned __int16)result;
keymap[4 * (unsigned __int16)result] = a2;
word_D42[2 * (unsigned __int16)result] = a3;
return result;
}

original_code:
static void
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname)
{
 KeySym keysym;
 keysym = XStringToKeysym(keyname);
 if (keysym == 0L)
 {
  warning("Bad keysym %s in keymap %s\n", keyname, mapname);
  return;
 }
 ;
 keymap[keysym & 0xffff].scancode = scancode;
 keymap[keysym & 0xffff].modifiers = modifiers;
 return;
}

canonical_original_code:
static void add_to_keymap(char *keyname, unsigned char scancode, unsigned short modifiers, char *mapname)
{
 unsigned long keysym;
 keysym = XStringToKeysym(keyname);
 if (keysym == 0L)
 {
  warning("Bad keysym %s in keymap %s\n", keyname, mapname);
  return;
 }
 ;
 keymap[keysym & 0xffff].scancode = scancode;
 keymap[keysym & 0xffff].modifiers = modifiers;
 return;
}

variable_types:
keyname
char *

variable_types:
modifiers
unsigned short

variable_types:
mapname
char *

variable_types:
keysym
unsigned long


decompiled_code:
int xkeymap_init()
{
int v0; // edi
_BYTE *v1; // rbx
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = keymapname;
if ( keymapname )
{
v1 = &keymapname;
do
{
*v1++ = tolower(v0);
v0 = (char)*v1;
}
while ( *v1 );
}
if ( keymapname != 1701736302 || *((_BYTE *)&keymapname + 4) )
{
if ( (unsigned int)xkeymap_read((const char *)&keymapname) )
keymap_loaded = 1;
}
return XDisplayKeycodes(display, &min_keycode, v3);
}

canonical_decompiled_code:
int func3()
{
int v0; // edi
_BYTE *v1; // rbx
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = keymapname;
if ( keymapname )
{
v1 = &keymapname;
do
{
*v1++ = tolower(v0);
v0 = (char)*v1;
}
while ( *v1 );
}
if ( keymapname != 1701736302 || *((_BYTE *)&keymapname + 4) )
{
if ( (unsigned int)func2((const char *)&keymapname) )
keymap_loaded = 1;
}
return XDisplayKeycodes(display, &min_keycode, v3);
}

original_code:
void
xkeymap_init(void)
{
 unsigned int max_keycode;
 char *mapname_ptr;
 mapname_ptr = keymapname;
 while (*mapname_ptr)
 {
  *mapname_ptr = tolower((int)*mapname_ptr);
  mapname_ptr++;
 }
 if (strcmp(keymapname, "none"))
 {
  if (xkeymap_read(keymapname))
   keymap_loaded = 1;
 }
 XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode);
}

canonical_original_code:
void xkeymap_init()
{
 unsigned int max_keycode;
 char *mapname_ptr;
 mapname_ptr = keymapname;
 while (*mapname_ptr)
 {
  *mapname_ptr = tolower((int)*mapname_ptr);
  mapname_ptr++;
 }
 if (strcmp(keymapname, "none"))
 {
  if (xkeymap_read(keymapname))
   keymap_loaded = 1;
 }
 XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode);
}


decompiled_code:
__int64 __fastcall xkeymap_translate_button(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 1);
result = 0LL;
if ( (unsigned int)v1 <= 4 )
result = (unsigned __int16)CSWTCH_58[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 1);
result = 0LL;
if ( (unsigned int)v1 <= 4 )
result = (unsigned __int16)CSWTCH_58[v1];
return result;
}

original_code:
uint16
xkeymap_translate_button(unsigned int button)
{
 switch (button)
 {
  case 1:
   return 0x1000;
  case 2:
   return 0x4000;
  case 3:
   return 0x2000;
  case 4:
   return 0x0280;
  case 5:
   return 0x0380;
 }
 return 0;
}

canonical_original_code:
unsigned short xkeymap_translate_button(unsigned int button)
{
 switch (button)
 {
  case 1:
   return 0x1000;
  case 2:
   return 0x4000;
  case 3:
   return 0x2000;
  case 4:
   return 0x0280;
  case 5:
   return 0x0380;
 }
 return 0;
}

variable_types:
button
unsigned int

return_type: unsigned short


decompiled_code:
char *__fastcall get_ksname(unsigned int a1)
{
char *result; // rax

if ( !a1 )
return "NoSymbol";
result = XKeysymToString(a1);
if ( !result )
result = "(no name)";
return result;
}

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

if ( !a1 )
return "NoSymbol";
result = XKeysymToString(a1);
if ( !result )
result = "(no name)";
return result;
}

original_code:
char *
get_ksname(uint32 keysym)
{
 char *ksname = ((void *)0);
 if (keysym == 0L)
  ksname = "NoSymbol";
 else if (!(ksname = XKeysymToString(keysym)))
  ksname = "(no name)";
 return ksname;
}

canonical_original_code:
char *get_ksname(unsigned int keysym)
{
 char *ksname = ((void *)0);
 if (keysym == 0L)
  ksname = "NoSymbol";
 else if (!(ksname = XKeysymToString(keysym)))
  ksname = "(no name)";
 return ksname;
}

variable_types:
keysym
unsigned int

variable_types:
ksname
char *

return_type: char *


decompiled_code:
__int64 __fastcall xkeymap_translate_key(unsigned int a1, unsigned int a2, char a3)
{
int v3; // ebx
unsigned __int8 v5; // bp
char *v7; // rax

v3 = (unsigned __int16)word_D42[2 * (unsigned __int16)a1];
if ( (v3 & 0x800) != 0 )
return (unsigned int)(v3 << 16);
if ( (v3 & 0x400) != 0 && (a3 & 1) != 0 )
v3 = 2;
v5 = keymap[4 * (unsigned __int16)a1];
if ( !v5 )
{
if ( keymap_loaded )
{
v7 = get_ksname(a1);
warning("No translation for (keysym 0x%lx, %s)\n", a1, v7);
}
if ( min_keycode <= a2 && a2 <= 0x60 )
{
v5 = a2 - min_keycode;
if ( (a3 & 1) != 0 )
v3 = 2;
}
}
return (v3 << 16) | (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2, char a3)
{
int v3; // ebx
unsigned __int8 v5; // bp
char *v7; // rax

v3 = (unsigned __int16)word_D42[2 * (unsigned __int16)a1];
if ( (v3 & 0x800) != 0 )
return (unsigned int)(v3 << 16);
if ( (v3 & 0x400) != 0 && (a3 & 1) != 0 )
v3 = 2;
v5 = keymap[4 * (unsigned __int16)a1];
if ( !v5 )
{
if ( keymap_loaded )
{
v7 = func5(a1);
warning("No translation for (keysym 0x%lx, %s)\n", a1, v7);
}
if ( min_keycode <= a2 && a2 <= 0x60 )
{
v5 = a2 - min_keycode;
if ( (a3 & 1) != 0 )
v3 = 2;
}
}
return (v3 << 16) | (unsigned int)v5;
}

original_code:
key_translation
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state)
{
 key_translation tr = { 0, 0 };
 tr = keymap[keysym & 0xffff];
 if (tr.modifiers & (1<<11))
 {
  ;
  tr.scancode = 0;
  return tr;
 }
 if (tr.modifiers & (1<<10))
 {
  if (state & (1<<0))
  {
   tr.modifiers = (1<<1);
  }
 }
 if (tr.scancode != 0)
 {
  ;
  return tr;
 }
 if (keymap_loaded)
  warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));
 if ((keycode >= min_keycode) && (keycode <= 0x60))
 {
  tr.scancode = keycode - min_keycode;
  if (state & (1<<0))
  {
   tr.modifiers = (1<<1);
  }
  ;
 }
 else
 {
  ;
 }
 return tr;
}

canonical_original_code:
struct _key_translation xkeymap_translate_key(unsigned int keysym, unsigned int keycode, unsigned int state)
{
 struct _key_translation tr = { 0, 0 };
 tr = keymap[keysym & 0xffff];
 if (tr.modifiers & (1<<11))
 {
  ;
  tr.scancode = 0;
  return tr;
 }
 if (tr.modifiers & (1<<10))
 {
  if (state & (1<<0))
  {
   tr.modifiers = (1<<1);
  }
 }
 if (tr.scancode != 0)
 {
  ;
  return tr;
 }
 if (keymap_loaded)
  warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym));
 if ((keycode >= min_keycode) && (keycode <= 0x60))
 {
  tr.scancode = keycode - min_keycode;
  if (state & (1<<0))
  {
   tr.modifiers = (1<<1);
  }
  ;
 }
 else
 {
  ;
 }
 return tr;
}

variable_types:
keycode
unsigned int

variable_types:
state
unsigned int

variable_types: struct _key_translation { unsigned char scancode; unsigned short modifiers; }


decompiled_code:
__int64 __fastcall rdp_send_scancode(__int64 a1, __int16 a2, unsigned __int8 a3)
{
unsigned __int16 v3; // r8
unsigned int v4; // er10
unsigned int v5; // er11
char v6; // r9
__int64 result; // rax

update_modifier_state(a3, (a2 & 0xC000) == 0);
if ( v6 < 0 )
result = rdp_send_input(v4, 4LL, v3 | 0x100u, (unsigned __int16)v5 & 0xFF7F, 0LL);
else
result = rdp_send_input(v4, 4LL, v3, v5, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int16 a2, unsigned __int8 a3)
{
unsigned __int16 v3; // r8
unsigned int v4; // er10
unsigned int v5; // er11
char v6; // r9
__int64 result; // rax

func0(a3, (a2 & 0xC000) == 0);
if ( v6 < 0 )
result = rdp_send_input(v4, 4LL, v3 | 0x100u, (unsigned __int16)v5 & 0xFF7F, 0LL);
else
result = rdp_send_input(v4, 4LL, v3, v5, 0LL);
return result;
}

original_code:
void
rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode)
{
 update_modifier_state(scancode, !(flags & (0x4000 | 0x8000)));
 if (scancode & 0x80)
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags | 0x0100,
          scancode & ~0x80, 0);
 }
 else
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
 }
}

canonical_original_code:
void rdp_send_scancode(unsigned int time, unsigned short flags, unsigned char scancode)
{
 update_modifier_state(scancode, !(flags & (0x4000 | 0x8000)));
 if (scancode & 0x80)
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags | 0x0100,
          scancode & ~0x80, 0);
 }
 else
 {
  ;
  rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0);
 }
}

variable_types:
time
unsigned int

variable_types:
flags
unsigned short


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

if ( a1 == 65387 )
{
if ( a4 )
{
rdp_send_scancode(a3, 0, 0xC6u);
rdp_send_scancode(a3, 0, 0xC6u);
return 1LL;
}
return 1LL;
}
if ( a1 <= 0xFF6B )
{
if ( a1 != 65293 )
{
if ( a1 == 65299 )
{
if ( a4 )
{
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 29LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 69LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 157LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 197LL, 0LL);
}
else
{
rdp_send_input(a3, 4LL, 49152LL, 29LL, 0LL);
}
return 1LL;
}
return 0LL;
}
if ( !(unsigned int)get_key_state(a2, 65513LL) && !(unsigned int)get_key_state(a2, 65514LL)
|| !(unsigned int)get_key_state(a2, 65507LL) && !(unsigned int)get_key_state(a2, 65508LL) )
{
return 0LL;
}
if ( a4 )
{
xwin_toggle_fullscreen();
return 1LL;
}
return 1LL;
}
if ( a1 <= 0xFFE8 )
{
if ( a1 <= 0xFFE6 )
return 0LL;
}
else
{
result = 0LL;
if ( a1 - 65515 > 3 )
return result;
}
if ( a4 )
{
rdp_send_scancode(a3, 0, 0x1Du);
rdp_send_scancode(a3, 0, 1u);
}
else
{
rdp_send_scancode(a3, 49152, 1u);
rdp_send_scancode(a3, 49152, 0x1Du);
}
return 1LL;
}

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

if ( a1 == 65387 )
{
if ( a4 )
{
func7(a3, 0, 0xC6u);
func7(a3, 0, 0xC6u);
return 1LL;
}
return 1LL;
}
if ( a1 <= 0xFF6B )
{
if ( a1 != 65293 )
{
if ( a1 == 65299 )
{
if ( a4 )
{
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 29LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 69LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 225LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 157LL, 0LL);
rdp_send_input(a3, 4LL, 0LL, 197LL, 0LL);
}
else
{
rdp_send_input(a3, 4LL, 49152LL, 29LL, 0LL);
}
return 1LL;
}
return 0LL;
}
if ( !(unsigned int)get_key_state(a2, 65513LL) && !(unsigned int)get_key_state(a2, 65514LL)
|| !(unsigned int)get_key_state(a2, 65507LL) && !(unsigned int)get_key_state(a2, 65508LL) )
{
return 0LL;
}
if ( a4 )
{
xwin_toggle_fullscreen();
return 1LL;
}
return 1LL;
}
if ( a1 <= 0xFFE8 )
{
if ( a1 <= 0xFFE6 )
return 0LL;
}
else
{
result = 0LL;
if ( a1 - 65515 > 3 )
return result;
}
if ( a4 )
{
func7(a3, 0, 0x1Du);
func7(a3, 0, 1u);
}
else
{
func7(a3, 49152, 1u);
func7(a3, 49152, 0x1Du);
}
return 1LL;
}

original_code:
BOOL
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed)
{
 switch (keysym)
 {
  case 0xff0d:
   if ((get_key_state(state, 0xffe9) || get_key_state(state, 0xffea))
       && (get_key_state(state, 0xffe3)
    || get_key_state(state, 0xffe4)))
   {
    if (pressed)
     xwin_toggle_fullscreen();
    return 1;
   }
   break;
  case 0xff6b:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0x46));
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0xc6));
   }
   return 1;
  case 0xff13:
   if (pressed)
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x1d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x9d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xc5, 0);
   }
   else
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, (0x4000 | 0x8000),
            0x1d, 0);
   }
   return 1;
  case 0xffe7:
  case 0xffeb:
  case 0xffed:
  case 0xffe8:
  case 0xffec:
  case 0xffee:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0, 0x1d);
    rdp_send_scancode(ev_time, 0, 0x1);
   }
   else
   {
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1);
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
   }
   return 1;
 }
 return 0;
}

canonical_original_code:
int handle_special_keys(unsigned int keysym, unsigned int state, unsigned int ev_time, int pressed)
{
 switch (keysym)
 {
  case 0xff0d:
   if ((get_key_state(state, 0xffe9) || get_key_state(state, 0xffea))
       && (get_key_state(state, 0xffe3)
    || get_key_state(state, 0xffe4)))
   {
    if (pressed)
     xwin_toggle_fullscreen();
    return 1;
   }
   break;
  case 0xff6b:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0x46));
    rdp_send_scancode(ev_time, 0,
        (0x80 | 0xc6));
   }
   return 1;
  case 0xff13:
   if (pressed)
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x1d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x45, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xe1, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0x9d, 0);
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, 0xc5, 0);
   }
   else
   {
    rdp_send_input(ev_time, RDP_INPUT_SCANCODE, (0x4000 | 0x8000),
            0x1d, 0);
   }
   return 1;
  case 0xffe7:
  case 0xffeb:
  case 0xffed:
  case 0xffe8:
  case 0xffec:
  case 0xffee:
   if (pressed)
   {
    rdp_send_scancode(ev_time, 0, 0x1d);
    rdp_send_scancode(ev_time, 0, 0x1);
   }
   else
   {
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1);
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
   }
   return 1;
 }
 return 0;
}


decompiled_code:
void __fastcall ensure_remote_modifiers(unsigned int a1, int a2)
{
__int16 v2; // ax
__int64 v3; // rdx

if ( (unsigned __int8)a2 > 0x45u )
{
if ( (_BYTE)a2 == 0xB8 )
return;
if ( (unsigned __int8)a2 <= 0xB8u )
{
if ( (_BYTE)a2 == 0x9D )
return;
}
else if ( (unsigned __int8)(a2 + 37) <= 1u )
{
return;
}
}
else if ( (unsigned __int8)a2 > 0x1Cu )
{
v3 = 0x1000A002001LL;
if ( _bittest64(&v3, (unsigned int)(a2 - 29)) )
return;
}
v2 = remote_modifier_state;
if ( ((a2 & 0x30000) != 0) != ((remote_modifier_state & 3) != 0) )
{
if ( (a2 & 0x20000) != 0 )
{
rdp_send_scancode(a1, 0, 0x2Au);
v2 = remote_modifier_state;
}
else if ( (a2 & 0x10000) != 0 )
{
rdp_send_scancode(a1, 0, 0x36u);
v2 = remote_modifier_state;
}
else
{
if ( (remote_modifier_state & 2) != 0 )
rdp_send_scancode(a1, 49152, 0x2Au);
else
rdp_send_scancode(a1, 49152, 0x36u);
v2 = remote_modifier_state;
}
}
if ( ((a2 & 0x40000) != 0) != ((v2 & 4) != 0) )
{
if ( (a2 & 0x40000) != 0 )
rdp_send_scancode(a1, 0, 0xB8u);
else
rdp_send_scancode(a1, 49152, 0xB8u);
HIBYTE(v2) = HIBYTE(remote_modifier_state);
}
if ( ((a2 & 0x1000000) != 0) != (HIBYTE(v2) & 1) )
{
rdp_send_input(0LL, 0LL, 0LL, 2 * (unsigned int)((a2 & 0x1000000) != 0), 0LL);
update_modifier_state(0x45u, 1);
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1, int a2)
{
__int16 v2; // ax
__int64 v3; // rdx

if ( (unsigned __int8)a2 > 0x45u )
{
if ( (_BYTE)a2 == 0xB8 )
return;
if ( (unsigned __int8)a2 <= 0xB8u )
{
if ( (_BYTE)a2 == 0x9D )
return;
}
else if ( (unsigned __int8)(a2 + 37) <= 1u )
{
return;
}
}
else if ( (unsigned __int8)a2 > 0x1Cu )
{
v3 = 0x1000A002001LL;
if ( _bittest64(&v3, (unsigned int)(a2 - 29)) )
return;
}
v2 = remote_modifier_state;
if ( ((a2 & 0x30000) != 0) != ((remote_modifier_state & 3) != 0) )
{
if ( (a2 & 0x20000) != 0 )
{
func7(a1, 0, 0x2Au);
v2 = remote_modifier_state;
}
else if ( (a2 & 0x10000) != 0 )
{
func7(a1, 0, 0x36u);
v2 = remote_modifier_state;
}
else
{
if ( (remote_modifier_state & 2) != 0 )
func7(a1, 49152, 0x2Au);
else
func7(a1, 49152, 0x36u);
v2 = remote_modifier_state;
}
}
if ( ((a2 & 0x40000) != 0) != ((v2 & 4) != 0) )
{
if ( (a2 & 0x40000) != 0 )
func7(a1, 0, 0xB8u);
else
func7(a1, 49152, 0xB8u);
HIBYTE(v2) = HIBYTE(remote_modifier_state);
}
if ( ((a2 & 0x1000000) != 0) != (HIBYTE(v2) & 1) )
{
rdp_send_input(0LL, 0LL, 0LL, 2 * (unsigned int)((a2 & 0x1000000) != 0), 0LL);
func0(0x45u, 1);
}
}

original_code:
void
ensure_remote_modifiers(uint32 ev_time, key_translation tr)
{
 switch (tr.scancode)
 {
  case 0x2a:
  case 0x36:
  case 0x1d:
  case (0x80 | 0x1d):
  case 0x38:
  case (0x80 | 0x38):
  case (0x80 | 0x5b):
  case (0x80 | 0x5c):
  case 0x45:
   return;
  default:
   break;
 }
 if (((tr.modifiers & ((1<<0) | (1<<1)))>0)
     != ((remote_modifier_state & ((1<<0) | (1<<1)))>0))
 {
  if (((tr.modifiers & (1<<1))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x2a);
  }
  else if (((tr.modifiers & (1<<0))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x36);
  }
  else
  {
   if (((remote_modifier_state & (1<<1))>0))
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
   else
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
  }
 }
 if (((tr.modifiers & (1<<2))>0)
     != ((remote_modifier_state & (1<<2))>0))
 {
  if (((tr.modifiers & (1<<2))>0))
  {
   rdp_send_scancode(ev_time, 0, (0x80 | 0x38));
  }
  else
  {
   rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
  }
 }
 if (((tr.modifiers & (1<<8))>0)
     != ((remote_modifier_state & (1<<8))>0))
 {
  uint16 new_remote_state = 0;
  if (((tr.modifiers & (1<<8))>0))
  {
   ;
   new_remote_state |= 0x0002;
  }
  else
  {
   ;
  }
  rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
  update_modifier_state(0x45, 1);
 }
}

canonical_original_code:
void ensure_remote_modifiers(unsigned int ev_time, struct _key_translation tr)
{
 switch (tr.scancode)
 {
  case 0x2a:
  case 0x36:
  case 0x1d:
  case (0x80 | 0x1d):
  case 0x38:
  case (0x80 | 0x38):
  case (0x80 | 0x5b):
  case (0x80 | 0x5c):
  case 0x45:
   return;
  default:
   break;
 }
 if (((tr.modifiers & ((1<<0) | (1<<1)))>0)
     != ((remote_modifier_state & ((1<<0) | (1<<1)))>0))
 {
  if (((tr.modifiers & (1<<1))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x2a);
  }
  else if (((tr.modifiers & (1<<0))>0))
  {
   rdp_send_scancode(ev_time, 0, 0x36);
  }
  else
  {
   if (((remote_modifier_state & (1<<1))>0))
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
   else
    rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
  }
 }
 if (((tr.modifiers & (1<<2))>0)
     != ((remote_modifier_state & (1<<2))>0))
 {
  if (((tr.modifiers & (1<<2))>0))
  {
   rdp_send_scancode(ev_time, 0, (0x80 | 0x38));
  }
  else
  {
   rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
  }
 }
 if (((tr.modifiers & (1<<8))>0)
     != ((remote_modifier_state & (1<<8))>0))
 {
  unsigned short new_remote_state = 0;
  if (((tr.modifiers & (1<<8))>0))
  {
   ;
   new_remote_state |= 0x0002;
  }
  else
  {
   ;
  }
  rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0);
  update_modifier_state(0x45, 1);
 }
}

user_defined_types: struct _key_translation { unsigned char scancode; unsigned short modifiers; }


decompiled_code:
__int64 __fastcall reset_modifier_keys(unsigned int a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = time(0LL);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 2) != 0 )
{
if ( !(unsigned int)get_key_state(a1, 65505LL) )
rdp_send_scancode(v1, 49152, 0x2Au);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 1) == 0 )
{
LABEL_3:
if ( (result & 0x20) == 0 )
goto LABEL_4;
goto LABEL_14;
}
}
else if ( (remote_modifier_state & 1) == 0 )
{
goto LABEL_3;
}
if ( !(unsigned int)get_key_state(a1, 65506LL) )
rdp_send_scancode(v1, 49152, 0x36u);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 0x20) == 0 )
{
LABEL_4:
if ( (result & 0x10) == 0 )
goto LABEL_5;
goto LABEL_17;
}
LABEL_14:
if ( !(unsigned int)get_key_state(a1, 65507LL) )
rdp_send_scancode(v1, 49152, 0x1Du);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 0x10) == 0 )
{
LABEL_5:
if ( (result & 8) == 0 )
goto LABEL_6;
goto LABEL_20;
}
LABEL_17:
if ( !(unsigned int)get_key_state(a1, 65508LL) )
rdp_send_scancode(v1, 49152, 0x9Du);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 8) == 0 )
{
LABEL_6:
if ( (result & 4) == 0 )
return result;
goto LABEL_23;
}
LABEL_20:
if ( !(unsigned int)get_key_state(a1, 65513LL) )
rdp_send_scancode(v1, 49152, 0x38u);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 4) != 0 )
{
LABEL_23:
result = get_key_state(a1, 65514LL);
if ( !(_DWORD)result )
{
result = get_key_state(a1, 65406LL);
if ( !(_DWORD)result )
result = rdp_send_scancode(v1, 49152, 0xB8u);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = time(0LL);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 2) != 0 )
{
if ( !(unsigned int)get_key_state(a1, 65505LL) )
func7(v1, 49152, 0x2Au);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 1) == 0 )
{
LABEL_3:
if ( (result & 0x20) == 0 )
goto LABEL_4;
goto LABEL_14;
}
}
else if ( (remote_modifier_state & 1) == 0 )
{
goto LABEL_3;
}
if ( !(unsigned int)get_key_state(a1, 65506LL) )
func7(v1, 49152, 0x36u);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 0x20) == 0 )
{
LABEL_4:
if ( (result & 0x10) == 0 )
goto LABEL_5;
goto LABEL_17;
}
LABEL_14:
if ( !(unsigned int)get_key_state(a1, 65507LL) )
func7(v1, 49152, 0x1Du);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 0x10) == 0 )
{
LABEL_5:
if ( (result & 8) == 0 )
goto LABEL_6;
goto LABEL_20;
}
LABEL_17:
if ( !(unsigned int)get_key_state(a1, 65508LL) )
func7(v1, 49152, 0x9Du);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 8) == 0 )
{
LABEL_6:
if ( (result & 4) == 0 )
return result;
goto LABEL_23;
}
LABEL_20:
if ( !(unsigned int)get_key_state(a1, 65513LL) )
func7(v1, 49152, 0x38u);
result = (unsigned __int16)remote_modifier_state;
if ( (remote_modifier_state & 4) != 0 )
{
LABEL_23:
result = get_key_state(a1, 65514LL);
if ( !(_DWORD)result )
{
result = get_key_state(a1, 65406LL);
if ( !(_DWORD)result )
result = func7(v1, 49152, 0xB8u);
}
}
return result;
}

original_code:
void
reset_modifier_keys(unsigned int state)
{
 uint32 ev_time;
 ev_time = time(((void *)0));
 if (((remote_modifier_state & (1<<1))>0)
     && !get_key_state(state, 0xffe1))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
 if (((remote_modifier_state & (1<<0))>0)
     && !get_key_state(state, 0xffe2))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
 if (((remote_modifier_state & (1<<5))>0)
     && !get_key_state(state, 0xffe3))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
 if (((remote_modifier_state & (1<<4))>0)
     && !get_key_state(state, 0xffe4))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x1d));
 if (((remote_modifier_state & (1<<3))>0) && !get_key_state(state, 0xffe9))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x38);
 if (((remote_modifier_state & (1<<2))>0) &&
     !get_key_state(state, 0xffea) && !get_key_state(state, 0xff7e))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
}

canonical_original_code:
void reset_modifier_keys(unsigned int state)
{
 unsigned int ev_time;
 ev_time = time(((void *)0));
 if (((remote_modifier_state & (1<<1))>0)
     && !get_key_state(state, 0xffe1))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x2a);
 if (((remote_modifier_state & (1<<0))>0)
     && !get_key_state(state, 0xffe2))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x36);
 if (((remote_modifier_state & (1<<5))>0)
     && !get_key_state(state, 0xffe3))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x1d);
 if (((remote_modifier_state & (1<<4))>0)
     && !get_key_state(state, 0xffe4))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x1d));
 if (((remote_modifier_state & (1<<3))>0) && !get_key_state(state, 0xffe9))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), 0x38);
 if (((remote_modifier_state & (1<<2))>0) &&
     !get_key_state(state, 0xffea) && !get_key_state(state, 0xff7e))
  rdp_send_scancode(ev_time, (0x4000 | 0x8000), (0x80 | 0x38));
}


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

if ( a1 > 2u || a2 > 0x257u || (result = bmpcache[600 * a1 + a2]) == 0 )
{
error((int)"get bitmap %d:%d\n", a1, (const char *)a2);
result = 0LL;
}
return result;
}

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

if ( a1 > 2u || a2 > 0x257u || (result = bmpcache[600 * a1 + a2]) == 0 )
{
error((int)"get bitmap %d:%d\n", a1, (const char *)a2);
result = 0LL;
}
return result;
}

original_code:
HBITMAP
cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
{
 HBITMAP bitmap;
 if ((cache_id < (sizeof(bmpcache) / sizeof(bmpcache[0]))) && (cache_idx < (sizeof(bmpcache[0]) / sizeof(bmpcache[0][0]))))
 {
  bitmap = bmpcache[cache_id][cache_idx];
  if (bitmap != ((void *)0))
   return bitmap;
 }
 error("get bitmap %d:%d\n", cache_id, cache_idx);
 return ((void *)0);
}

canonical_original_code:
void *cache_get_bitmap(unsigned char cache_id, unsigned short cache_idx)
{
 void *bitmap;
 if ((cache_id < (sizeof(bmpcache) / sizeof(bmpcache[0]))) && (cache_idx < (sizeof(bmpcache[0]) / sizeof(bmpcache[0][0]))))
 {
  bitmap = bmpcache[cache_id][cache_idx];
  if (bitmap != ((void *)0))
   return bitmap;
 }
 error("get bitmap %d:%d\n", cache_id, cache_idx);
 return ((void *)0);
}

variable_types:
bitmap
void *