decompiled_code:
__int64 l2cap_btstack_listen()
{
fwrite("btstack_listen is not implemented yet\n", 1uLL, 0x26uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
fwrite("btstack_listen is not implemented yet\n", 1uLL, 0x26uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int l2cap_btstack_listen(void * user __attribute__((unused)), const char *bdaddr_adapter __attribute__((unused)), unsigned short psm __attribute__((unused)), int options __attribute__((unused)),
    L2CAP_ABS_LISTEN_ACCEPT_CALLBACK read_callback __attribute__((unused)), L2CAP_ABS_CLOSE_CALLBACK close_callback __attribute__((unused)))
{
  fprintf(stderr, "btstack_listen is not implemented yet\n");
  return -1;
}

canonical_original_code:
static int l2cap_btstack_listen(void *user, char *bdaddr_adapter, unsigned short psm, int options, int (*read_callback)(int channel, struct bdaddr_t *src), int (*close_callback)(void *user))
{
  fprintf(stderr, "btstack_listen is not implemented yet\n");
  return -1;
}

variable_types:
psm
unsigned short

variable_types: options int

variable_types: int (*)(int channel, struct bdaddr_t { unsigned char b[6]; } *src)


bacmp

repo: matlo/GIMX

decompiled_code:
int __fastcall bacmp(const void *a1, const void *a2)
{
return memcmp(a1, a2, 6uLL);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1, const void *a2)
{
return memcmp(a1, a2, 6uLL);
}

original_code:
static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
{
 return memcmp(ba1, ba2, sizeof(bdaddr_t));
}

canonical_original_code:
static inline int bacmp(struct bdaddr_t *ba1, struct bdaddr_t *ba2)
{
 return memcmp(ba1, ba2, sizeof(bdaddr_t));
}

variable_types: struct bdaddr_t { unsigned char b[6]; } *

return_type: int


decompiled_code:
__int64 __fastcall l2cap_btstack_connect_channel(__int64 a1, __int16 a2, __int16 a3, __int16 a4, char a5)
{
int v5; // er12
_WORD *v8; // rbx
unsigned int v9; // ebp
__int64 result; // rax
__int64 v12[8]; // [rsp+8h] [rbp-40h] BYREF

v12[0] = a1;
v5 = channels;
if ( !channels )
return 0xFFFFFFFFLL;
v8 = &unk_A10;
v9 = 0;
while ( bacmp(v8, v12) || v8[3] != a2 )
{
++v9;
v8 += 28;
if ( v9 == v5 )
return 0xFFFFFFFFLL;
}
if ( a5 )
{
((void (__fastcall *)(__int64))qword_A38[7 * v9])(qword_A08[7 * v9]);
result = 0xFFFFFFFFLL;
}
else
{
result = ((__int64 (__fastcall *)(__int64))qword_A20[7 * v9])(qword_A08[7 * v9]);
if ( !(_DWORD)result )
{
word_A18[28 * v9] = a3;
word_A1C[28 * v9] = a4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int16 a2, __int16 a3, __int16 a4, char a5)
{
int v5; // er12
_WORD *v8; // rbx
unsigned int v9; // ebp
__int64 result; // rax
__int64 v12[8]; // [rsp+8h] [rbp-40h] BYREF

v12[0] = a1;
v5 = channels;
if ( !channels )
return 0xFFFFFFFFLL;
v8 = &unk_A10;
v9 = 0;
while ( func5(v8, v12) || v8[3] != a2 )
{
++v9;
v8 += 28;
if ( v9 == v5 )
return 0xFFFFFFFFLL;
}
if ( a5 )
{
((void (__fastcall *)(__int64))qword_A38[7 * v9])(qword_A08[7 * v9]);
result = 0xFFFFFFFFLL;
}
else
{
result = ((__int64 (__fastcall *)(__int64))qword_A20[7 * v9])(qword_A08[7 * v9]);
if ( !(_DWORD)result )
{
word_A18[28 * v9] = a3;
word_A1C[28 * v9] = a4;
}
}
return result;
}

original_code:
static int l2cap_btstack_connect_channel(bdaddr_t event_addr, uint16_t psm, uint16_t cid, uint16_t handle, uint8_t status)
{
  int result = -1;
  unsigned int channel;
  for(channel = 0; channel < channels.nb; ++channel)
  {
    if(!bacmp(&channels.entries[channel].ba, &event_addr) && channels.entries[channel].psm == psm)
    {
      if(status == 0)
      {
        result = channels.entries[channel].connect_callback(channels.entries[channel].user);
        if(result == 0)
        {
          channels.entries[channel].cid = cid;
          channels.entries[channel].handle = handle;
        }
      }
      else
      {
        channels.entries[channel].close_callback(channels.entries[channel].user);
      }
      break;
    }
  }
  return result;
}

canonical_original_code:
static int l2cap_btstack_connect_channel(struct bdaddr_t event_addr, unsigned short psm, unsigned short cid, unsigned short handle, unsigned char status)
{
  int result = -1;
  unsigned int channel;
  for(channel = 0; channel < channels.nb; ++channel)
  {
    if(!bacmp(&channels.entries[channel].ba, &event_addr) && channels.entries[channel].psm == psm)
    {
      if(status == 0)
      {
        result = channels.entries[channel].connect_callback(channels.entries[channel].user);
        if(result == 0)
        {
          channels.entries[channel].cid = cid;
          channels.entries[channel].handle = handle;
        }
      }
      else
      {
        channels.entries[channel].close_callback(channels.entries[channel].user);
      }
      break;
    }
  }
  return result;
}

variable_types:
cid
unsigned short

variable_types:
handle
unsigned short

variable_types:
status
unsigned char

variable_types: result int

variable_types:
channel
unsigned int


decompiled_code:
__int64 packet_handler()
{
int v0; // eax
unsigned int v1; // ebx
unsigned int v3; // ebx
unsigned int v4; // er12
unsigned int v5; // ebp
char v6[26]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v7; // [rsp+1Ah] [rbp-1Eh] BYREF
unsigned __int16 v8; // [rsp+1Eh] [rbp-1Ah]

v0 = btstack_common_recv(&recv_data_0);
if ( v0 == 1 )
{
if ( recv_data_0 == 4 )
{
if ( byte_5E6 == 112 )
{
v7 = dword_5E9;
v8 = word_5ED;
ba2str(&v7, v6);
v3 = (unsigned __int16)word_5EF;
v4 = (unsigned __int16)word_5F3;
v5 = (unsigned __int16)word_5F1;
if ( (unsigned int)l2cap_btstack_connect_channel(
v7 | ((unsigned __int64)v8 << 32),
word_5F1,
word_5F3,
word_5EF,
byte_5E8) )
printf("L2CAP connection to device %s failed. status code %u\n", v6, (unsigned __int8)byte_5E8);
else
printf(
"Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
v6,
v3,
v5,
v4,
(unsigned __int16)word_5F5);
}
v1 = 0;
}
else
{
v1 = 0;
if ( recv_data_0 == 6 )
{
v1 = l2cap_btstack_process_packet(word_5E2, (__int64)&byte_5E6, (unsigned __int16)word_5E4);
if ( v1 == -1 )
fwrite("error processing data\n", 1uLL, 0x16uLL, stderr);
}
}
}
else
{
v1 = v0;
if ( v0 < 0 )
v1 = 1;
}
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
unsigned int v1; // ebx
unsigned int v3; // ebx
unsigned int v4; // er12
unsigned int v5; // ebp
char v6[26]; // [rsp+0h] [rbp-38h] BYREF
unsigned int v7; // [rsp+1Ah] [rbp-1Eh] BYREF
unsigned __int16 v8; // [rsp+1Eh] [rbp-1Ah]

v0 = btstack_common_recv(&recv_data_0);
if ( v0 == 1 )
{
if ( recv_data_0 == 4 )
{
if ( byte_5E6 == 112 )
{
v7 = dword_5E9;
v8 = word_5ED;
ba2str(&v7, v6);
v3 = (unsigned __int16)word_5EF;
v4 = (unsigned __int16)word_5F3;
v5 = (unsigned __int16)word_5F1;
if ( (unsigned int)func6(
v7 | ((unsigned __int64)v8 << 32),
word_5F1,
word_5F3,
word_5EF,
byte_5E8) )
printf("L2CAP connection to device %s failed. status code %u\n", v6, (unsigned __int8)byte_5E8);
else
printf(
"Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
v6,
v3,
v5,
v4,
(unsigned __int16)word_5F5);
}
v1 = 0;
}
else
{
v1 = 0;
if ( recv_data_0 == 6 )
{
v1 = func0(word_5E2, (__int64)&byte_5E6, (unsigned __int16)word_5E4);
if ( v1 == -1 )
fwrite("error processing data\n", 1uLL, 0x16uLL, stderr);
}
}
}
else
{
v1 = v0;
if ( v0 < 0 )
v1 = 1;
}
return v1;
}

original_code:
static int packet_handler(void * user __attribute__((unused)))
{
  static recv_data_t recv_data = { {}, 0, 0 };
  bdaddr_t event_addr;
  uint16_t psm = 0, cid, handle;
  int ret = btstack_common_recv(&recv_data);
  if(ret == 1)
  {
    ret = 0;
    uint16_t packet_type = ( ((uint16_t) recv_data.buffer[0]) | (((uint16_t)recv_data.buffer[0 +1]) << 8));
    cid = ( ((uint16_t) recv_data.buffer[2]) | (((uint16_t)recv_data.buffer[2 +1]) << 8));
    unsigned char* packet = recv_data.buffer+sizeof(packet_header_t);
    int len = ( ((uint16_t) recv_data.buffer[4]) | (((uint16_t)recv_data.buffer[4 +1]) << 8));
    switch(packet_type)
    {
    case 0x06:
      if ((ret = l2cap_btstack_process_packet(cid, packet, len)) == -1)
      {
        fprintf(stderr, "error processing data\n");
      }
      break;
    case 0x04:
      switch (packet[0])
      {
      case 0x70:
        memcpy(&event_addr, packet+3, sizeof(event_addr));
        char bdaddr[18];
        ba2str(&event_addr, bdaddr);
        psm = ( ((uint16_t) packet[11]) | (((uint16_t)packet[11 +1]) << 8));
        cid = ( ((uint16_t) packet[13]) | (((uint16_t)packet[13 +1]) << 8));
        handle = ( ((uint16_t) packet[9]) | (((uint16_t)packet[9 +1]) << 8));
        if(l2cap_btstack_connect_channel(event_addr, psm, cid, handle, packet[2]) == 0)
        {
          printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
              bdaddr, handle, psm, cid, ( ((uint16_t) packet[15]) | (((uint16_t)packet[15 +1]) << 8)));
        }
        else
        {
          printf("L2CAP connection to device %s failed. status code %u\n", bdaddr, packet[2]);
        }
        break;
      default:
        break;
      }
      break;
    default:
      break;
    }
  }
  else if(ret < 0)
  {
    ret = 1;
  }
  return ret;
}

canonical_original_code:
static int packet_handler(void *user)
{
  static struct recv_data_t recv_data = { {}, 0, 0 };
  struct bdaddr_t event_addr;
  unsigned short psm = 0; unsigned short cid; unsigned short handle;
  int ret = btstack_common_recv(&recv_data);
  if(ret == 1)
  {
    ret = 0;
    unsigned short packet_type = ( ((uint16_t) recv_data.buffer[0]) | (((uint16_t)recv_data.buffer[0 +1]) << 8));
    cid = ( ((unsigned short) recv_data.buffer[2]) | (((unsigned short)recv_data.buffer[2 +1]) << 8));
    unsigned char *packet = recv_data.buffer+sizeof(packet_header_t);
    int len = ( ((uint16_t) recv_data.buffer[4]) | (((uint16_t)recv_data.buffer[4 +1]) << 8));
    switch(packet_type)
    {
    case 0x06:
      if ((ret = l2cap_btstack_process_packet(cid, packet, len)) == -1)
      {
        fprintf(stderr, "error processing data\n");
      }
      break;
    case 0x04:
      switch (packet[0])
      {
      case 0x70:
        memcpy(&event_addr, packet+3, sizeof(event_addr));
        char bdaddr[18];
        ba2str(&event_addr, bdaddr);
        psm = ( ((unsigned short) packet[11]) | (((unsigned short)packet[11 +1]) << 8));
        cid = ( ((unsigned short) packet[13]) | (((unsigned short)packet[13 +1]) << 8));
        handle = ( ((unsigned short) packet[9]) | (((unsigned short)packet[9 +1]) << 8));
        if(l2cap_btstack_connect_channel(event_addr, psm, cid, handle, packet[2]) == 0)
        {
          printf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
              bdaddr, handle, psm, cid, ( ((unsigned short) packet[15]) | (((unsigned short)packet[15 +1]) << 8)));
        }
        else
        {
          printf("L2CAP connection to device %s failed. status code %u\n", bdaddr, packet[2]);
        }
        break;
      default:
        break;
      }
      break;
    default:
      break;
    }
  }
  else if(ret < 0)
  {
    ret = 1;
  }
  return ret;
}

variable_types:
user
void *

variable_types: struct recv_data_t { unsigned char buffer[-1]; unsigned short read; unsigned short remaining; }

variable_types: ret int

variable_types:
packet
unsigned char *

variable_types: len int

variable_types:
bdaddr
char [18]


bacpy

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

*(_DWORD *)a1 = *(_DWORD *)a2;
result = *(unsigned __int16 *)(a2 + 4);
*(_WORD *)(a1 + 4) = result;
return result;
}

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

*(_DWORD *)a1 = *(_DWORD *)a2;
result = *(unsigned __int16 *)(a2 + 4);
*(_WORD *)(a1 + 4) = result;
return result;
}

original_code:
static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
{
 memcpy(dst, src, sizeof(bdaddr_t));
}

canonical_original_code:
static inline void bacpy(struct bdaddr_t *dst, struct bdaddr_t *src)
{
 memcpy(dst, src, sizeof(bdaddr_t));
}

variable_types:
src
struct bdaddr_t *

return_type: void


decompiled_code:
__int64 __fastcall l2cap_btstack_connect(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // er14
__int64 v13; // rbp
__int64 v14; // rbx
__int64 v16[4]; // [rsp+0h] [rbp-68h] BYREF
char v17[6]; // [rsp+24h] [rbp-44h] BYREF
char v18[62]; // [rsp+2Ah] [rbp-3Eh] BYREF

str2ba(a2, v18);
baswap(v17, v18);
if ( (int)btstack_common_send_cmd(&btstack_l2cap_create_channel_mtu, v17, a3, 1024LL) < 0 )
return (unsigned int)-1;
v16[0] = (__int64)packet_handler;
v16[1] = 0LL;
v16[2] = (__int64)packet_handler;
v11 = btstack_common_getfd(&btstack_l2cap_create_channel_mtu, v17, v10);
gpoll_register_fd(v11, 0LL, v16);
v12 = channels;
v13 = channels;
v14 = 8LL * channels;
bacpy((__int64)&unk_A10 + 56 * channels, (__int64)v18);
word_A16[4 * (v14 - v13)] = a3;
qword_A08[v14 - v13] = a5;
qword_A20[v14 - v13] = a6;
qword_A38[v14 - v13] = a7;
++channels;
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // er14
__int64 v13; // rbp
__int64 v14; // rbx
__int64 v16[4]; // [rsp+0h] [rbp-68h] BYREF
char v17[6]; // [rsp+24h] [rbp-44h] BYREF
char v18[62]; // [rsp+2Ah] [rbp-3Eh] BYREF

str2ba(a2, v18);
baswap(v17, v18);
if ( (int)btstack_common_send_cmd(&btstack_l2cap_create_channel_mtu, v17, a3, 1024LL) < 0 )
return (unsigned int)-1;
v16[0] = (__int64)packet_handler;
v16[1] = 0LL;
v16[2] = (__int64)packet_handler;
v11 = btstack_common_getfd(&btstack_l2cap_create_channel_mtu, v17, v10);
gpoll_register_fd(v11, 0LL, v16);
v12 = channels;
v13 = channels;
v14 = 8LL * channels;
func8((__int64)&unk_A10 + 56 * channels, (__int64)v18);
word_A16[4 * (v14 - v13)] = a3;
qword_A08[v14 - v13] = a5;
qword_A20[v14 - v13] = a6;
qword_A38[v14 - v13] = a7;
++channels;
return v12;
}

original_code:
int l2cap_btstack_connect(const char * bdaddr_src __attribute__((unused)), const char * bdaddr_dest, unsigned short psm, int options __attribute__((unused)),
    void * user, L2CAP_ABS_CONNECT_CALLBACK connect_callback, L2CAP_ABS_CLOSE_CALLBACK close_callback)
{
  bdaddr_t dst;
  str2ba(bdaddr_dest, &dst);
  bdaddr_t dst_swapped;
  baswap(&dst_swapped, &dst);
  if( btstack_common_send_cmd(&btstack_l2cap_create_channel_mtu, dst_swapped.b, psm, 1024) < 0)
  {
    return -1;
  }
  GPOLL_CALLBACKS callbacks = {
          .fp_read = packet_handler,
          .fp_write = ((void *)0),
          .fp_close = packet_handler
  };
  gpoll_register_fd(btstack_common_getfd(), 0, &callbacks);
  int channel = channels.nb;
  bacpy(&channels.entries[channel].ba, &dst);
  channels.entries[channel].psm = psm;
  channels.entries[channel].user = user;
  channels.entries[channel].connect_callback = connect_callback;
  channels.entries[channel].close_callback = close_callback;
  ++channels.nb;
  return channel;
}

canonical_original_code:
int l2cap_btstack_connect(char *bdaddr_src, char *bdaddr_dest, unsigned short psm, int options, void *user, int (*connect_callback)(void *user), int (*close_callback)(void *user))
{
  struct bdaddr_t dst;
  str2ba(bdaddr_dest, &dst);
  struct bdaddr_t dst_swapped;
  baswap(&dst_swapped, &dst);
  if( btstack_common_send_cmd(&btstack_l2cap_create_channel_mtu, dst_swapped.b, psm, 1024) < 0)
  {
    return -1;
  }
  struct GPOLL_CALLBACKS callbacks = {
          .fp_read = packet_handler,
          .fp_write = ((void *)0),
          .fp_close = packet_handler
  };
  gpoll_register_fd(btstack_common_getfd(), 0, &callbacks);
  int channel = channels.nb;
  bacpy(&channels.entries[channel].ba, &dst);
  channels.entries[channel].psm = psm;
  channels.entries[channel].user = user;
  channels.entries[channel].connect_callback = connect_callback;
  channels.entries[channel].close_callback = close_callback;
  ++channels.nb;
  return channel;
}

variable_types:
dst
struct bdaddr_t { unsigned char b[6]; }

variable_types: struct GPOLL_CALLBACKS { int (*fp_read)(void *user); int (*fp_write)(void *user); int (*fp_close)(void *user); }

variable_types: channel int


decompiled_code:
__int64 __fastcall l2cap_btstack_disconnect(int a1)
{
return btstack_common_disconnect((unsigned __int16)word_A1C[28 * a1]);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return btstack_common_disconnect((unsigned __int16)word_A1C[28 * a1]);
}

original_code:
static int l2cap_btstack_disconnect(int channel)
{
  return btstack_common_disconnect(channels.entries[channel].handle);
}


decompiled_code:
__int64 __fastcall l2cap_btstack_send(int a1, __int64 a2, unsigned int a3)
{
unsigned __int16 v4; // si

v4 = word_A18[28 * a1];
if ( v4 )
return btstack_common_send_packet(6LL, v4, a2, a3);
fwrite("connection is still pending\n", 1uLL, 0x1CuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int64 a2, unsigned int a3)
{
unsigned __int16 v4; // si

v4 = word_A18[28 * a1];
if ( v4 )
return btstack_common_send_packet(6LL, v4, a2, a3);
fwrite("connection is still pending\n", 1uLL, 0x1CuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int l2cap_btstack_send(int channel, const unsigned char* buf, int len, int ignored __attribute__((unused)))
{
  if(!channels.entries[channel].cid)
  {
    fprintf(stderr, "connection is still pending\n");
    return -1;
  }
  return btstack_common_send_packet(0x06, channels.entries[channel].cid, buf, len);
}

canonical_original_code:
static int l2cap_btstack_send(int channel, unsigned char *buf, int len, int ignored)
{
  if(!channels.entries[channel].cid)
  {
    fprintf(stderr, "connection is still pending\n");
    return -1;
  }
  return btstack_common_send_packet(0x06, channels.entries[channel].cid, buf, len);
}

variable_types:
buf
unsigned char *

variable_types: ignored int


decompiled_code:
__int64 l2cap_btstack_init()
{
return l2cap_abs_register(0LL, &l2cap_btstack);
}

canonical_decompiled_code:
__int64 func12()
{
return l2cap_abs_register(0LL, &l2cap_btstack);
}

original_code:
void l2cap_btstack_init(void)
{
  l2cap_abs_register(E_BT_ABS_BTSTACK, &l2cap_btstack);
}

canonical_original_code:
void l2cap_btstack_init()
{
  l2cap_abs_register(E_BT_ABS_BTSTACK, &l2cap_btstack);
}


decompiled_code:
int __fastcall show_axes(unsigned int a1, int *a2)
{
__int64 v3; // rbx
int v4; // er12
unsigned int v5; // ebp
const char *v6; // rax
int v7; // ebx
double v8; // rbx
__int64 v9; // rax
double v10; // rbx
__int64 v11; // rax
int v12; // esi
double v13; // rbx
__int64 v14; // rax
double v15; // rbx
__int64 v16; // rax
int v17; // esi
char v19[72]; // [rsp+0h] [rbp-48h] BYREF

v3 = 4LL;
v4 = 0;
do
{
v5 = a2[v3];
if ( v5 )
{
v6 = (const char *)controller_get_axis_name(a1, (unsigned int)v3);
snprintf(v19, 0x17uLL, "%15s: %5d", v6, v5);
if ( wmove(wbuttons, ++v4, 1) != -1 )
waddnstr(wbuttons, v19, -1);
if ( v4 == 8 )
break;
}
++v3;
}
while ( v3 != 40 );
strcpy(v19, " ");
if ( v4 < last_button_nb )
{
v7 = v4;
do
{
if ( wmove(wbuttons, ++v7, 1) != -1 )
waddnstr(wbuttons, v19, -1);
}
while ( v7 < last_button_nb );
}
last_button_nb = v4;
wnoutrefresh(wbuttons);
if ( wmove(lstick, dword_1624, cross) != -1 )
waddch(lstick, 0x20uLL);
v8 = (double)*a2;
v9 = adapter_get(0LL);
cross = (int)(v8 / (double)(int)controller_get_max_signed(*(unsigned int *)(v9 + 736), 0LL) * 9.0 + 10.0);
v10 = (double)a2[1];
v11 = adapter_get(0LL);
v12 = (int)(v10 / (double)(int)controller_get_max_signed(*(unsigned int *)(v11 + 736), 1LL) * 4.0 + 5.0);
dword_1624 = v12;
if ( (unsigned int)(v12 - 1) <= 8 && (unsigned int)(cross - 1) <= 0x12 )
{
if ( wmove(lstick, v12, cross) != -1 )
waddch(lstick, 0x2AuLL);
}
else if ( wmove(lstick, v12, cross) != -1 )
{
waddch(lstick, 0x32AuLL);
}
wnoutrefresh(lstick);
if ( wmove(rstick, dword_162C, dword_1628) != -1 )
waddch(rstick, 0x20uLL);
v13 = (double)a2[2];
v14 = adapter_get(0LL);
dword_1628 = (int)(v13 / (double)(int)controller_get_max_signed(*(unsigned int *)(v14 + 736), 2LL) * 9.0 + 10.0);
v15 = (double)a2[3];
v16 = adapter_get(0LL);
v17 = (int)(v15 / (double)(int)controller_get_max_signed(*(unsigned int *)(v16 + 736), 3LL) * 4.0 + 5.0);
dword_162C = v17;
if ( (unsigned int)(v17 - 1) <= 8 && (unsigned int)(dword_1628 - 1) <= 0x12 )
{
if ( wmove(rstick, v17, dword_1628) != -1 )
waddch(rstick, 0x2AuLL);
}
else if ( wmove(rstick, v17, dword_1628) != -1 )
{
waddch(rstick, 0x32AuLL);
}
return wnoutrefresh(rstick);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, int *a2)
{
__int64 v3; // rbx
int v4; // er12
unsigned int v5; // ebp
const char *v6; // rax
int v7; // ebx
double v8; // rbx
__int64 v9; // rax
double v10; // rbx
__int64 v11; // rax
int v12; // esi
double v13; // rbx
__int64 v14; // rax
double v15; // rbx
__int64 v16; // rax
int v17; // esi
char v19[72]; // [rsp+0h] [rbp-48h] BYREF

v3 = 4LL;
v4 = 0;
do
{
v5 = a2[v3];
if ( v5 )
{
v6 = (const char *)controller_get_axis_name(a1, (unsigned int)v3);
snprintf(v19, 0x17uLL, "%15s: %5d", v6, v5);
if ( wmove(wbuttons, ++v4, 1) != -1 )
waddnstr(wbuttons, v19, -1);
if ( v4 == 8 )
break;
}
++v3;
}
while ( v3 != 40 );
strcpy(v19, " ");
if ( v4 < last_button_nb )
{
v7 = v4;
do
{
if ( wmove(wbuttons, ++v7, 1) != -1 )
waddnstr(wbuttons, v19, -1);
}
while ( v7 < last_button_nb );
}
last_button_nb = v4;
wnoutrefresh(wbuttons);
if ( wmove(lstick, dword_1624, cross) != -1 )
waddch(lstick, 0x20uLL);
v8 = (double)*a2;
v9 = adapter_get(0LL);
cross = (int)(v8 / (double)(int)controller_get_max_signed(*(unsigned int *)(v9 + 736), 0LL) * 9.0 + 10.0);
v10 = (double)a2[1];
v11 = adapter_get(0LL);
v12 = (int)(v10 / (double)(int)controller_get_max_signed(*(unsigned int *)(v11 + 736), 1LL) * 4.0 + 5.0);
dword_1624 = v12;
if ( (unsigned int)(v12 - 1) <= 8 && (unsigned int)(cross - 1) <= 0x12 )
{
if ( wmove(lstick, v12, cross) != -1 )
waddch(lstick, 0x2AuLL);
}
else if ( wmove(lstick, v12, cross) != -1 )
{
waddch(lstick, 0x32AuLL);
}
wnoutrefresh(lstick);
if ( wmove(rstick, dword_162C, dword_1628) != -1 )
waddch(rstick, 0x20uLL);
v13 = (double)a2[2];
v14 = adapter_get(0LL);
dword_1628 = (int)(v13 / (double)(int)controller_get_max_signed(*(unsigned int *)(v14 + 736), 2LL) * 9.0 + 10.0);
v15 = (double)a2[3];
v16 = adapter_get(0LL);
v17 = (int)(v15 / (double)(int)controller_get_max_signed(*(unsigned int *)(v16 + 736), 3LL) * 4.0 + 5.0);
dword_162C = v17;
if ( (unsigned int)(v17 - 1) <= 8 && (unsigned int)(dword_1628 - 1) <= 0x12 )
{
if ( wmove(rstick, v17, dword_1628) != -1 )
waddch(rstick, 0x2AuLL);
}
else if ( wmove(rstick, v17, dword_1628) != -1 )
{
waddch(rstick, 0x32AuLL);
}
return wnoutrefresh(rstick);
}

original_code:
static void show_axes(e_controller_type type, int axis[])
{
  char label[sizeof("shifter forward: 65535")];
  int d = 0;
  int i;
  for(i=rel_axis_rstick_y+1; i<AXIS_MAX; ++i)
  {
    if(axis[i])
    {
      snprintf(label, sizeof(label), "%15s: %5d", controller_get_axis_name(type, i), axis[i]);
      (wmove((wbuttons),(1 + d),(1)) == (-1) ? (-1) : waddnstr((wbuttons),(label),-1));
      d++;
      if(d == 11 - 3)
      {
        break;
      }
    }
  }
  memset(label, ' ', sizeof(label));
  label[sizeof(label)-1] = '\0';
  for(i=d; i<last_button_nb; ++i)
  {
    (wmove((wbuttons),(1 + i),(1)) == (-1) ? (-1) : waddnstr((wbuttons),(label),-1));
  }
  last_button_nb = d;
  wnoutrefresh(wbuttons);
  (wmove((lstick),(cross[0][1]),(cross[0][0])) == (-1) ? (-1) : waddch((lstick),(' ')));
  cross[0][0] = 21 / 2 + (double)axis[rel_axis_lstick_x] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_lstick_x) * (21 / 2 - 1);
  cross[0][1] = 11 / 2 + (double)axis[rel_axis_lstick_y] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_lstick_y) * (11 / 2 - 1);
  if(cross[0][0] <= 0 || cross[0][0] >= 21 -1 || cross[0][1] <= 0 || cross[0][1] >= 11 -1)
  {
    (wmove((lstick),(cross[0][1]),(cross[0][0])) == (-1) ? (-1) : waddch((lstick),('*' | (((chtype)(((3))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))));
  }
  else
  {
    (wmove((lstick),(cross[0][1]),(cross[0][0])) == (-1) ? (-1) : waddch((lstick),('*')));
  }
  wnoutrefresh(lstick);
  (wmove((rstick),(cross[1][1]),(cross[1][0])) == (-1) ? (-1) : waddch((rstick),(' ')));
  cross[1][0] = 21 / 2 + (double)axis[rel_axis_rstick_x] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_rstick_x) * (21 / 2 - 1);
  cross[1][1] = 11 / 2 + (double)axis[rel_axis_rstick_y] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_rstick_y) * (11 / 2 - 1);
  if(cross[1][0] <= 0 || cross[1][0] >= 21 -1 || cross[1][1] <= 0 || cross[1][1] >= 11 -1)
  {
    (wmove((rstick),(cross[1][1]),(cross[1][0])) == (-1) ? (-1) : waddch((rstick),('*' | (((chtype)(((3))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))));
  }
  else
  {
    (wmove((rstick),(cross[1][1]),(cross[1][0])) == (-1) ? (-1) : waddch((rstick),('*')));
  }
  wnoutrefresh(rstick);
}

canonical_original_code:
static void show_axes(enum e_controller_type type, int axis[])
{
  char label[-1];
  int d = 0;
  int i;
  for(i=rel_axis_rstick_y+1; i<AXIS_MAX; ++i)
  {
    if(axis[i])
    {
      snprintf(label, sizeof(label), "%15s: %5d", controller_get_axis_name(type, i), axis[i]);
      (wmove((wbuttons),(1 + d),(1)) == (-1) ? (-1) : waddnstr((wbuttons),(label),-1));
      d++;
      if(d == 11 - 3)
      {
        break;
      }
    }
  }
  memset(label, ' ', sizeof(label));
  label[sizeof(label)-1] = '\0';
  for(i=d; i<last_button_nb; ++i)
  {
    (wmove((wbuttons),(1 + i),(1)) == (-1) ? (-1) : waddnstr((wbuttons),(label),-1));
  }
  last_button_nb = d;
  wnoutrefresh(wbuttons);
  (wmove((lstick),(cross[0][1]),(cross[0][0])) == (-1) ? (-1) : waddch((lstick),(' ')));
  cross[0][0] = 21 / 2 + (double)axis[rel_axis_lstick_x] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_lstick_x) * (21 / 2 - 1);
  cross[0][1] = 11 / 2 + (double)axis[rel_axis_lstick_y] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_lstick_y) * (11 / 2 - 1);
  if(cross[0][0] <= 0 || cross[0][0] >= 21 -1 || cross[0][1] <= 0 || cross[0][1] >= 11 -1)
  {
    (wmove((lstick),(cross[0][1]),(cross[0][0])) == (-1) ? (-1) : waddch((lstick),('*' | (((chtype)(((3))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))));
  }
  else
  {
    (wmove((lstick),(cross[0][1]),(cross[0][0])) == (-1) ? (-1) : waddch((lstick),('*')));
  }
  wnoutrefresh(lstick);
  (wmove((rstick),(cross[1][1]),(cross[1][0])) == (-1) ? (-1) : waddch((rstick),(' ')));
  cross[1][0] = 21 / 2 + (double)axis[rel_axis_rstick_x] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_rstick_x) * (21 / 2 - 1);
  cross[1][1] = 11 / 2 + (double)axis[rel_axis_rstick_y] / controller_get_max_signed(adapter_get(0)->ctype, rel_axis_rstick_y) * (11 / 2 - 1);
  if(cross[1][0] <= 0 || cross[1][0] >= 21 -1 || cross[1][1] <= 0 || cross[1][1] >= 11 -1)
  {
    (wmove((rstick),(cross[1][1]),(cross[1][0])) == (-1) ? (-1) : waddch((rstick),('*' | (((chtype)(((3))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))));
  }
  else
  {
    (wmove((rstick),(cross[1][1]),(cross[1][0])) == (-1) ? (-1) : waddch((rstick),('*')));
  }
  wnoutrefresh(rstick);
}

variable_types: enum e_controller_type { C_TYPE_JOYSTICK=0, C_TYPE_360_PAD=1, C_TYPE_SIXAXIS=2, C_TYPE_PS2_PAD=3, C_TYPE_XBOX_PAD=4, C_TYPE_DS4=5, C_TYPE_XONE_PAD=6, C_TYPE_T300RS_PS4=7, C_TYPE_G27_PS3=8, C_TYPE_G29_PS4=9, C_TYPE_DF_PS2=10, C_TYPE_DFP_PS2=11, C_TYPE_GTF_PS2=12, C_TYPE_NONE=13, C_TYPE_MAX=expr }

variable_types:
axis
int []

variable_types:
label
char [-1]

variable_types: d int

variable_types: i int


decompiled_code:
int display_calibration()
{
void *v0; // rsp
__int64 v1; // r12
char *v2; // rax
unsigned int *v3; // rax
unsigned int *v4; // rax
char *v5; // rax
_DWORD *v6; // rax
char *v7; // rax
char *v8; // rax
double *v9; // rax
double *v10; // rax
char *v11; // rax
unsigned int v12; // er13
char *v13; // rax
unsigned int v14; // er13
char *v15; // rax
char *v16; // rax
double *v17; // rdx
char *v18; // rax
char *v19; // rax
const char *v20; // rsi
unsigned int v21; // eax
char *v22; // rax
char *v23; // rax
char *v24; // rax
char *v25; // rax
char *v26; // rax
char *v27; // rax
char *v28; // rax
char *v29; // rax
char *v30; // rax
char *v31; // rax
char v33[32]; // [rsp+0h] [rbp-20h] BYREF

v0 = alloca(COLS);
v1 = cal_get_mouse(current_mouse, current_conf);
if ( current_cal )
{
if ( wmove(stdscr, 13, 3) != -1 )
{
v19 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)", 5);
waddnstr(stdscr, v19, -1);
}
}
else if ( wmove(stdscr, 13, 3) != -1 )
{
v18 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to edit)", 5);
waddnstr(stdscr, v18, -1);
}
wclrtoeol(stdscr);
wmove(wcal, 1, 1);
if ( !(unsigned int)ginput_get_mk_mode() )
{
waddnstr(wcal, "Mouse: ", -1);
if ( current_cal == 1 )
wattr_on(wcal, 0x400uLL, 0LL);
v20 = (const char *)ginput_mouse_name(current_mouse);
waddnstr(wcal, v20, -1);
v21 = ginput_mouse_virtual_id(current_mouse);
snprintf(v33, COLS, " (%d) (F1) ", v21);
waddnstr(wcal, v33, -1);
if ( current_cal == 1 )
wattr_on(wcal, 0x100uLL, 0LL);
}
v2 = dcgettext(0LL, "Profile:", 5);
waddnstr(wcal, v2, -1);
if ( current_cal == 2 )
wattr_on(wcal, 0x400uLL, 0LL);
snprintf(v33, COLS, " %d (F2)", (unsigned int)(current_conf + 1));
waddnstr(wcal, v33, -1);
if ( current_cal == 2 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 2, 1) != -1 )
{
v22 = dcgettext(0LL, "Dead zone:", 5);
waddnstr(wcal, v22, -1);
}
if ( current_cal == 5 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " x=", -1);
v3 = *(unsigned int **)(v1 + 40);
if ( v3 )
{
snprintf(v33, COLS, "%d", *v3);
waddnstr(wcal, v33, -1);
}
else
{
v23 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v23, -1);
}
waddnstr(wcal, " (F3)", -1);
if ( current_cal == 5 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 6 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v4 = *(unsigned int **)(v1 + 48);
if ( v4 )
{
snprintf(v33, COLS, "%d", *v4);
waddnstr(wcal, v33, -1);
}
else
{
v24 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v24, -1);
}
waddnstr(wcal, " (F4)", -1);
if ( current_cal == 6 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 7 )
wattr_on(wcal, 0x400uLL, 0LL);
v5 = dcgettext(0LL, " shape=", 5);
waddnstr(wcal, v5, -1);
v6 = *(_DWORD **)(v1 + 56);
if ( v6 )
{
if ( *v6 )
v7 = dcgettext(0LL, "rectangle", 5);
else
v7 = dcgettext(0LL, "circle", 5);
waddnstr(wcal, v7, -1);
}
else
{
v25 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v25, -1);
}
waddnstr(wcal, " (F5)", -1);
if ( current_cal == 7 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 3, 1) != -1 )
{
v26 = dcgettext(0LL, "Acceleration:", 5);
waddnstr(wcal, v26, -1);
}
if ( current_cal == 12 )
wattr_on(wcal, 0x400uLL, 0LL);
v8 = dcgettext(0LL, " test (F6)", 5);
waddnstr(wcal, v8, -1);
if ( current_cal == 12 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 10 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " x=", -1);
v9 = *(double **)(v1 + 16);
if ( v9 )
{
snprintf(v33, COLS, "%.2f", *v9);
waddnstr(wcal, v33, -1);
}
else
{
v27 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v27, -1);
}
waddnstr(wcal, " (F7)", -1);
if ( current_cal == 10 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 11 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v10 = *(double **)(v1 + 24);
if ( v10 )
{
snprintf(v33, COLS, "%.2f", *v10);
waddnstr(wcal, v33, -1);
}
else
{
v28 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v28, -1);
}
waddnstr(wcal, " (F8)", -1);
if ( current_cal == 11 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 4, 1) != -1 )
{
v29 = dcgettext(0LL, "Sensitivity:", 5);
waddnstr(wcal, v29, -1);
}
if ( current_cal == 3 )
wattr_on(wcal, 0x400uLL, 0LL);
if ( *(_QWORD *)v1 )
{
snprintf(v33, COLS, " %.2f", **(double **)v1);
waddnstr(wcal, v33, -1);
}
else
{
v30 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v30, -1);
}
waddnstr(wcal, " (F9)", -1);
if ( current_cal == 3 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 5, 1) != -1 )
waddnstr(wcal, "X/Y:", -1);
if ( (unsigned int)(current_cal - 8) <= 1 )
wattr_on(wcal, 0x400uLL, 0LL);
v11 = dcgettext(0LL, " circle test", 5);
waddnstr(wcal, v11, -1);
if ( (unsigned int)(current_cal - 8) <= 1 )
wattr_on(wcal, 0x100uLL, 0LL);
waddnstr(wcal, ", ", -1);
if ( current_cal == 8 )
wattr_on(wcal, 0x400uLL, 0LL);
v12 = *(_DWORD *)(v1 + 32);
v13 = dcgettext(0LL, "radius=%d (F10)", 5);
snprintf(v33, COLS, v13, v12);
waddnstr(wcal, v33, -1);
if ( current_cal == 8 )
wattr_on(wcal, 0x100uLL, 0LL);
waddnstr(wcal, ", ", -1);
if ( current_cal == 9 )
wattr_on(wcal, 0x400uLL, 0LL);
v14 = *(_DWORD *)(v1 + 36);
v15 = dcgettext(0LL, "velocity=%d (F11)", 5);
snprintf(v33, COLS, v15, v14);
waddnstr(wcal, v33, -1);
if ( current_cal == 9 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 4 )
wattr_on(wcal, 0x400uLL, 0LL);
v16 = dcgettext(0LL, " ratio=", 5);
waddnstr(wcal, v16, -1);
if ( *(_QWORD *)v1 && (v17 = *(double **)(v1 + 8)) != 0LL )
{
snprintf(v33, COLS, "%.2f", *v17 / **(double **)v1);
waddnstr(wcal, v33, -1);
}
else
{
v31 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v31, -1);
}
waddnstr(wcal, " (F12)", -1);
if ( current_cal == 4 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
wborder(wcal, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(wcal);
return doupdate();
}

canonical_decompiled_code:
int func2()
{
void *v0; // rsp
__int64 v1; // r12
char *v2; // rax
unsigned int *v3; // rax
unsigned int *v4; // rax
char *v5; // rax
_DWORD *v6; // rax
char *v7; // rax
char *v8; // rax
double *v9; // rax
double *v10; // rax
char *v11; // rax
unsigned int v12; // er13
char *v13; // rax
unsigned int v14; // er13
char *v15; // rax
char *v16; // rax
double *v17; // rdx
char *v18; // rax
char *v19; // rax
const char *v20; // rsi
unsigned int v21; // eax
char *v22; // rax
char *v23; // rax
char *v24; // rax
char *v25; // rax
char *v26; // rax
char *v27; // rax
char *v28; // rax
char *v29; // rax
char *v30; // rax
char *v31; // rax
char v33[32]; // [rsp+0h] [rbp-20h] BYREF

v0 = alloca(COLS);
v1 = cal_get_mouse(current_mouse, current_conf);
if ( current_cal )
{
if ( wmove(stdscr, 13, 3) != -1 )
{
v19 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)", 5);
waddnstr(stdscr, v19, -1);
}
}
else if ( wmove(stdscr, 13, 3) != -1 )
{
v18 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to edit)", 5);
waddnstr(stdscr, v18, -1);
}
wclrtoeol(stdscr);
wmove(wcal, 1, 1);
if ( !(unsigned int)ginput_get_mk_mode() )
{
waddnstr(wcal, "Mouse: ", -1);
if ( current_cal == 1 )
wattr_on(wcal, 0x400uLL, 0LL);
v20 = (const char *)ginput_mouse_name(current_mouse);
waddnstr(wcal, v20, -1);
v21 = ginput_mouse_virtual_id(current_mouse);
snprintf(v33, COLS, " (%d) (F1) ", v21);
waddnstr(wcal, v33, -1);
if ( current_cal == 1 )
wattr_on(wcal, 0x100uLL, 0LL);
}
v2 = dcgettext(0LL, "Profile:", 5);
waddnstr(wcal, v2, -1);
if ( current_cal == 2 )
wattr_on(wcal, 0x400uLL, 0LL);
snprintf(v33, COLS, " %d (F2)", (unsigned int)(current_conf + 1));
waddnstr(wcal, v33, -1);
if ( current_cal == 2 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 2, 1) != -1 )
{
v22 = dcgettext(0LL, "Dead zone:", 5);
waddnstr(wcal, v22, -1);
}
if ( current_cal == 5 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " x=", -1);
v3 = *(unsigned int **)(v1 + 40);
if ( v3 )
{
snprintf(v33, COLS, "%d", *v3);
waddnstr(wcal, v33, -1);
}
else
{
v23 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v23, -1);
}
waddnstr(wcal, " (F3)", -1);
if ( current_cal == 5 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 6 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v4 = *(unsigned int **)(v1 + 48);
if ( v4 )
{
snprintf(v33, COLS, "%d", *v4);
waddnstr(wcal, v33, -1);
}
else
{
v24 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v24, -1);
}
waddnstr(wcal, " (F4)", -1);
if ( current_cal == 6 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 7 )
wattr_on(wcal, 0x400uLL, 0LL);
v5 = dcgettext(0LL, " shape=", 5);
waddnstr(wcal, v5, -1);
v6 = *(_DWORD **)(v1 + 56);
if ( v6 )
{
if ( *v6 )
v7 = dcgettext(0LL, "rectangle", 5);
else
v7 = dcgettext(0LL, "circle", 5);
waddnstr(wcal, v7, -1);
}
else
{
v25 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v25, -1);
}
waddnstr(wcal, " (F5)", -1);
if ( current_cal == 7 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 3, 1) != -1 )
{
v26 = dcgettext(0LL, "Acceleration:", 5);
waddnstr(wcal, v26, -1);
}
if ( current_cal == 12 )
wattr_on(wcal, 0x400uLL, 0LL);
v8 = dcgettext(0LL, " test (F6)", 5);
waddnstr(wcal, v8, -1);
if ( current_cal == 12 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 10 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " x=", -1);
v9 = *(double **)(v1 + 16);
if ( v9 )
{
snprintf(v33, COLS, "%.2f", *v9);
waddnstr(wcal, v33, -1);
}
else
{
v27 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v27, -1);
}
waddnstr(wcal, " (F7)", -1);
if ( current_cal == 10 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 11 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v10 = *(double **)(v1 + 24);
if ( v10 )
{
snprintf(v33, COLS, "%.2f", *v10);
waddnstr(wcal, v33, -1);
}
else
{
v28 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v28, -1);
}
waddnstr(wcal, " (F8)", -1);
if ( current_cal == 11 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 4, 1) != -1 )
{
v29 = dcgettext(0LL, "Sensitivity:", 5);
waddnstr(wcal, v29, -1);
}
if ( current_cal == 3 )
wattr_on(wcal, 0x400uLL, 0LL);
if ( *(_QWORD *)v1 )
{
snprintf(v33, COLS, " %.2f", **(double **)v1);
waddnstr(wcal, v33, -1);
}
else
{
v30 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v30, -1);
}
waddnstr(wcal, " (F9)", -1);
if ( current_cal == 3 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 5, 1) != -1 )
waddnstr(wcal, "X/Y:", -1);
if ( (unsigned int)(current_cal - 8) <= 1 )
wattr_on(wcal, 0x400uLL, 0LL);
v11 = dcgettext(0LL, " circle test", 5);
waddnstr(wcal, v11, -1);
if ( (unsigned int)(current_cal - 8) <= 1 )
wattr_on(wcal, 0x100uLL, 0LL);
waddnstr(wcal, ", ", -1);
if ( current_cal == 8 )
wattr_on(wcal, 0x400uLL, 0LL);
v12 = *(_DWORD *)(v1 + 32);
v13 = dcgettext(0LL, "radius=%d (F10)", 5);
snprintf(v33, COLS, v13, v12);
waddnstr(wcal, v33, -1);
if ( current_cal == 8 )
wattr_on(wcal, 0x100uLL, 0LL);
waddnstr(wcal, ", ", -1);
if ( current_cal == 9 )
wattr_on(wcal, 0x400uLL, 0LL);
v14 = *(_DWORD *)(v1 + 36);
v15 = dcgettext(0LL, "velocity=%d (F11)", 5);
snprintf(v33, COLS, v15, v14);
waddnstr(wcal, v33, -1);
if ( current_cal == 9 )
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal == 4 )
wattr_on(wcal, 0x400uLL, 0LL);
v16 = dcgettext(0LL, " ratio=", 5);
waddnstr(wcal, v16, -1);
if ( *(_QWORD *)v1 && (v17 = *(double **)(v1 + 8)) != 0LL )
{
snprintf(v33, COLS, "%.2f", *v17 / **(double **)v1);
waddnstr(wcal, v33, -1);
}
else
{
v31 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v31, -1);
}
waddnstr(wcal, " (F12)", -1);
if ( current_cal == 4 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
wborder(wcal, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(wcal);
return doupdate();
}

original_code:
void display_calibration()
{
  char line[COLS];
  s_mouse_cal* mcal = cal_get_mouse(current_mouse, current_conf);
  if(current_cal == NONE)
  {
    (wmove((stdscr),((2 + 11)),((2 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Mouse calibration (Ctrl+F1 to edit)"))),-1));
  }
  else
  {
    (wmove((stdscr),((2 + 11)),((2 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)"))),-1));
  }
  wclrtoeol(stdscr);
  wmove(wcal, 1, 1);
  if(ginput_get_mk_mode() == GE_MK_MODE_MULTIPLE_INPUTS)
  {
    waddnstr(wcal,"Mouse: ",-1);
    if(current_cal == MC)
    {
      wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    }
    waddnstr(wcal,ginput_mouse_name(current_mouse),-1);
    snprintf(line, COLS, " (%d) (F1) ", ginput_mouse_virtual_id(current_mouse));
    waddnstr(wcal,line,-1);
    if(current_cal == MC)
    {
      wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    }
  }
  waddnstr(wcal,gettext("Profile:"),-1);
  if(current_cal == CC)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  snprintf(line, COLS, " %d (F2)", current_conf + 1);
  waddnstr(wcal,line,-1);
  if(current_cal == CC)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(2),(1)) == (-1) ? (-1) : waddnstr((wcal),(gettext("Dead zone:")),-1));
  if(current_cal == DZX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," x=",-1);
  if(mcal->dzx)
  {
    snprintf(line, COLS, "%d", *mcal->dzx);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F3)",-1);
  if(current_cal == DZX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == DZY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," y=",-1);
  if(mcal->dzy)
  {
    snprintf(line, COLS, "%d", *mcal->dzy);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F4)",-1);
  if(current_cal == DZY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == DZS)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" shape="),-1);
  if(mcal->dzs)
  {
    if (*mcal->dzs == E_SHAPE_CIRCLE)
    {
      waddnstr(wcal,gettext("circle"),-1);
    }
    else
    {
      waddnstr(wcal,gettext("rectangle"),-1);
    }
  }
  else
  {
    waddnstr(wcal,gettext(" N/A"),-1);
  }
  waddnstr(wcal," (F5)",-1);
  if(current_cal == DZS)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(3),(1)) == (-1) ? (-1) : waddnstr((wcal),(gettext("Acceleration:")),-1));
  if(current_cal == TEST)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" test (F6)"),-1);
  if(current_cal == TEST)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == EX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," x=",-1);
  if(mcal->ex)
  {
    snprintf(line, COLS, "%.2f", *mcal->ex);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F7)",-1);
  if(current_cal == EX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == EY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," y=",-1);
  if(mcal->ey)
  {
    snprintf(line, COLS, "%.2f", *mcal->ey);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F8)",-1);
  if(current_cal == EY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(4),(1)) == (-1) ? (-1) : waddnstr((wcal),(gettext("Sensitivity:")),-1));
  if(current_cal == MX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(mcal->mx)
  {
    snprintf(line, COLS, " %.2f", *mcal->mx);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext(" N/A"),-1);
  }
  waddnstr(wcal," (F9)",-1);
  if(current_cal == MX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(5),(1)) == (-1) ? (-1) : waddnstr((wcal),("X/Y:"),-1));
  if(current_cal == RD || current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" circle test"),-1);
  if(current_cal == RD || current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,", ",-1);
  if(current_cal == RD)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  snprintf(line, COLS, gettext("radius=%d (F10)"), mcal->rd);
  waddnstr(wcal,line,-1);
  if(current_cal == RD)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,", ",-1);
  if(current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  snprintf(line, COLS, gettext("velocity=%d (F11)"), mcal->vel);
  waddnstr(wcal,line,-1);
  if(current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == MY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" ratio="),-1);
  if(mcal->mx && mcal->my)
  {
    snprintf(line, COLS, "%.2f", *mcal->my / *mcal->mx);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F12)",-1);
  if(current_cal == MY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  wborder(wcal, 0, 0, 0, 0, 0, 0, 0, 0);
  wnoutrefresh(wcal);
  doupdate();
}

canonical_original_code:
void display_calibration()
{
  char line[-1];
  struct s_mouse_cal *mcal = cal_get_mouse(current_mouse, current_conf);
  if(current_cal == NONE)
  {
    (wmove((stdscr),((2 + 11)),((2 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Mouse calibration (Ctrl+F1 to edit)"))),-1));
  }
  else
  {
    (wmove((stdscr),((2 + 11)),((2 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)"))),-1));
  }
  wclrtoeol(stdscr);
  wmove(wcal, 1, 1);
  if(ginput_get_mk_mode() == GE_MK_MODE_MULTIPLE_INPUTS)
  {
    waddnstr(wcal,"Mouse: ",-1);
    if(current_cal == MC)
    {
      wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    }
    waddnstr(wcal,ginput_mouse_name(current_mouse),-1);
    snprintf(line, COLS, " (%d) (F1) ", ginput_mouse_virtual_id(current_mouse));
    waddnstr(wcal,line,-1);
    if(current_cal == MC)
    {
      wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
    }
  }
  waddnstr(wcal,gettext("Profile:"),-1);
  if(current_cal == CC)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  snprintf(line, COLS, " %d (F2)", current_conf + 1);
  waddnstr(wcal,line,-1);
  if(current_cal == CC)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(2),(1)) == (-1) ? (-1) : waddnstr((wcal),(gettext("Dead zone:")),-1));
  if(current_cal == DZX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," x=",-1);
  if(mcal->dzx)
  {
    snprintf(line, COLS, "%d", *mcal->dzx);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F3)",-1);
  if(current_cal == DZX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == DZY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," y=",-1);
  if(mcal->dzy)
  {
    snprintf(line, COLS, "%d", *mcal->dzy);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F4)",-1);
  if(current_cal == DZY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == DZS)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" shape="),-1);
  if(mcal->dzs)
  {
    if (*mcal->dzs == E_SHAPE_CIRCLE)
    {
      waddnstr(wcal,gettext("circle"),-1);
    }
    else
    {
      waddnstr(wcal,gettext("rectangle"),-1);
    }
  }
  else
  {
    waddnstr(wcal,gettext(" N/A"),-1);
  }
  waddnstr(wcal," (F5)",-1);
  if(current_cal == DZS)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(3),(1)) == (-1) ? (-1) : waddnstr((wcal),(gettext("Acceleration:")),-1));
  if(current_cal == TEST)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" test (F6)"),-1);
  if(current_cal == TEST)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == EX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," x=",-1);
  if(mcal->ex)
  {
    snprintf(line, COLS, "%.2f", *mcal->ex);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F7)",-1);
  if(current_cal == EX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == EY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal," y=",-1);
  if(mcal->ey)
  {
    snprintf(line, COLS, "%.2f", *mcal->ey);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F8)",-1);
  if(current_cal == EY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(4),(1)) == (-1) ? (-1) : waddnstr((wcal),(gettext("Sensitivity:")),-1));
  if(current_cal == MX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(mcal->mx)
  {
    snprintf(line, COLS, " %.2f", *mcal->mx);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext(" N/A"),-1);
  }
  waddnstr(wcal," (F9)",-1);
  if(current_cal == MX)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  (wmove((wcal),(5),(1)) == (-1) ? (-1) : waddnstr((wcal),("X/Y:"),-1));
  if(current_cal == RD || current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" circle test"),-1);
  if(current_cal == RD || current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,", ",-1);
  if(current_cal == RD)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  snprintf(line, COLS, gettext("radius=%d (F10)"), mcal->rd);
  waddnstr(wcal,line,-1);
  if(current_cal == RD)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,", ",-1);
  if(current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  snprintf(line, COLS, gettext("velocity=%d (F11)"), mcal->vel);
  waddnstr(wcal,line,-1);
  if(current_cal == VEL)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  if(current_cal == MY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  waddnstr(wcal,gettext(" ratio="),-1);
  if(mcal->mx && mcal->my)
  {
    snprintf(line, COLS, "%.2f", *mcal->my / *mcal->mx);
    waddnstr(wcal,line,-1);
  }
  else
  {
    waddnstr(wcal,gettext("N/A"),-1);
  }
  waddnstr(wcal," (F12)",-1);
  if(current_cal == MY)
  {
    wattr_on(wcal, (attr_t)((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8)))), ((void *)0));
  }
  wclrtoeol(wcal);
  wborder(wcal, 0, 0, 0, 0, 0, 0, 0, 0);
  wnoutrefresh(wcal);
  doupdate();
}

variable_types:
line
char [-1]

variable_types: struct s_mouse_cal { double *mx; double *my; double *ex; double *ey; int rd; int vel; int *dzx; int *dzy; enum e_shape { E_SHAPE_CIRCLE=0, E_SHAPE_RECTANGLE=1 } *dzs; struct s_mouse_options { unsigned int buffer_size; double filter; enum e_mouse_mode { E_MOUSE_MODE_AIMING=0, E_MOUSE_MODE_DRIVING=1 } mode; } options; unsigned int dpi; } *

user_defined_types: struct s_mouse_cal { double *mx; double *my; double *ex; double *ey; int rd; int vel; int *dzx; int *dzy; enum e_shape *dzs; struct s_mouse_options options; unsigned int dpi; }

user_defined_types: struct s_mouse_options { unsigned int buffer_size; double filter; enum e_mouse_mode mode; }


decompiled_code:
int display_init()
{
int v0; // ebx
char *v1; // rax
int v2; // eax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax

initscr();
if ( !has_colors() )
{
endwin();
puts("Your terminal does not support color");
exit(1);
}
start_color();
init_pair(1, 7, 0);
init_pair(2, 7, 7);
init_pair(3, 0, 1);
init_pair(4, 1, 0);
wrefresh(stdscr);
if ( wmove(stdscr, 1, 3) != -1 )
{
v4 = dcgettext(0LL, "Left stick", 5);
waddnstr(stdscr, v4, -1);
}
if ( wmove(stdscr, 1, 25) != -1 )
{
v5 = dcgettext(0LL, "Right stick", 5);
waddnstr(stdscr, v5, -1);
}
if ( wmove(stdscr, 1, 47) != -1 )
{
v6 = dcgettext(0LL, "Buttons", 5);
waddnstr(stdscr, v6, -1);
}
lstick = newwin(11, 21, 2, 2);
wborder(lstick, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(lstick);
rstick = newwin(11, 21, 2, 24);
wborder(rstick, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(rstick);
wbuttons = newwin(11, 24, 2, 46);
wborder(wbuttons, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(wbuttons);
if ( wmove(stdscr, 13, 3) != -1 )
{
v7 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to edit)", 5);
waddnstr(stdscr, v7, -1);
}
wcal = newwin(7, COLS - 3, 14, 2);
wborder(wcal, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(wcal);
if ( wmove(stdscr, LINES - 1, 1) != -1 )
{
v8 = dcgettext(0LL, "Refresh rate:", 5);
waddnstr(stdscr, v8, -1);
}
v0 = COLS;
v1 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
v2 = strlen(v1);
if ( wmove(stdscr, LINES - 1, v0 - v2) != -1 )
{
v9 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
waddnstr(stdscr, v9, -1);
}
wnoutrefresh(stdscr);
return doupdate();
}

canonical_decompiled_code:
int func3()
{
int v0; // ebx
char *v1; // rax
int v2; // eax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax

initscr();
if ( !has_colors() )
{
endwin();
puts("Your terminal does not support color");
exit(1);
}
start_color();
init_pair(1, 7, 0);
init_pair(2, 7, 7);
init_pair(3, 0, 1);
init_pair(4, 1, 0);
wrefresh(stdscr);
if ( wmove(stdscr, 1, 3) != -1 )
{
v4 = dcgettext(0LL, "Left stick", 5);
waddnstr(stdscr, v4, -1);
}
if ( wmove(stdscr, 1, 25) != -1 )
{
v5 = dcgettext(0LL, "Right stick", 5);
waddnstr(stdscr, v5, -1);
}
if ( wmove(stdscr, 1, 47) != -1 )
{
v6 = dcgettext(0LL, "Buttons", 5);
waddnstr(stdscr, v6, -1);
}
lstick = newwin(11, 21, 2, 2);
wborder(lstick, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(lstick);
rstick = newwin(11, 21, 2, 24);
wborder(rstick, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(rstick);
wbuttons = newwin(11, 24, 2, 46);
wborder(wbuttons, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(wbuttons);
if ( wmove(stdscr, 13, 3) != -1 )
{
v7 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to edit)", 5);
waddnstr(stdscr, v7, -1);
}
wcal = newwin(7, COLS - 3, 14, 2);
wborder(wcal, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wnoutrefresh(wcal);
if ( wmove(stdscr, LINES - 1, 1) != -1 )
{
v8 = dcgettext(0LL, "Refresh rate:", 5);
waddnstr(stdscr, v8, -1);
}
v0 = COLS;
v1 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
v2 = strlen(v1);
if ( wmove(stdscr, LINES - 1, v0 - v2) != -1 )
{
v9 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
waddnstr(stdscr, v9, -1);
}
wnoutrefresh(stdscr);
return doupdate();
}

original_code:
void display_init()
{
  initscr();
  if(has_colors() == 0)
  {
    endwin();
    printf("Your terminal does not support color\n");
    exit(1);
  }
  start_color();
  init_pair(1, 7, 0);
  init_pair(2, 7, 7);
  init_pair(3, 0, 1);
  init_pair(4, 1, 0);
  wrefresh(stdscr);
  (wmove((stdscr),((1)),((2 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Left stick"))),-1));
  (wmove((stdscr),((1)),((2 + 21 + 1 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Right stick"))),-1));
  (wmove((stdscr),((1)),((2 + 21 + 1 + 21 + 1 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Buttons"))),-1));
  lstick = newwin(11, 21, 2, 2);
  wborder(lstick, 0, 0, 0, 0, 0, 0, 0, 0);
  wnoutrefresh(lstick);
  rstick = newwin(11, 21, 2, 2 + 21 + 1);
  wborder(rstick, 0, 0, 0, 0, 0, 0, 0, 0);
  wnoutrefresh(rstick);
  wbuttons = newwin(11, sizeof("shifter forward: 65535") + 1, 2, 2 + 21 + 1 + 21 + 1);
  wborder(wbuttons, 0, 0, 0, 0, 0, 0, 0, 0);
  wnoutrefresh(wbuttons);
  (wmove((stdscr),((2 + 11)),((2 + 1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Mouse calibration (Ctrl+F1 to edit)"))),-1));
  wcal = newwin(7, COLS-3, 2 + 11 + 1, 2);
  wborder(wcal, 0, 0, 0, 0, 0, 0, 0, 0);
  wnoutrefresh(wcal);
  (wmove((stdscr),((LINES-1)),((1))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Refresh rate:"))),-1));
  (wmove((stdscr),((LINES-1)),((COLS-strlen(gettext("Press Shift+Esc to exit."))))) == (-1) ? (-1) : waddnstr((stdscr),((gettext("Press Shift+Esc to exit."))),-1));
  wnoutrefresh(stdscr);
  doupdate();
}


decompiled_code:
int display_end()
{
int result; // eax

if ( wcal )
result = endwin();
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

if ( wcal )
result = endwin();
return result;
}

original_code:
void display_end()
{
  if(wcal)
  {
    endwin();
  }
}


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

result = *(unsigned int *)(a1 + 4);
if ( (_DWORD)result )
{
*(_DWORD *)a2 = 1;
*(_WORD *)(a2 + 6) = *(_WORD *)(a1 + 8);
*(_WORD *)(a2 + 8) = *(_WORD *)(a1 + 10);
*(_DWORD *)(a1 + 4) = 0;
result = 1LL;
}
return result;
}

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

result = *(unsigned int *)(a1 + 4);
if ( (_DWORD)result )
{
*(_DWORD *)a2 = 1;
*(_WORD *)(a2 + 6) = *(_WORD *)(a1 + 8);
*(_WORD *)(a2 + 8) = *(_WORD *)(a1 + 10);
*(_DWORD *)(a1 + 4) = 0;
result = 1LL;
}
return result;
}

original_code:
static int haptic_source_rumble_get(struct haptic_source_state * state, s_haptic_core_data * data) {
    int ret = 0;
    if (state->updated) {
        data->type = E_DATA_TYPE_RUMBLE;
        data->rumble.weak = state->weak;
        data->rumble.strong = state->strong;
        state->updated = 0;
        ret = 1;
    }
    return ret;
}

canonical_original_code:
static int haptic_source_rumble_get(struct haptic_source_state *state, struct s_haptic_core_data *data) {
    int ret = 0;
    if (state->updated) {
        data->type = E_DATA_TYPE_RUMBLE;
        data->rumble.weak = state->weak;
        data->rumble.strong = state->strong;
        state->updated = 0;
        ret = 1;
    }
    return ret;
}

variable_types: struct haptic_source_state { unsigned int props_index; int updated; unsigned short weak; unsigned short strong; } *

variable_types: struct s_haptic_core_data { enum e_haptic_core_data_type { E_DATA_TYPE_NONE=0, E_DATA_TYPE_RUMBLE=1, E_DATA_TYPE_CONSTANT=2, E_DATA_TYPE_SPRING=3, E_DATA_TYPE_DAMPER=4, E_DATA_TYPE_LEDS=5, E_DATA_TYPE_RANGE=6 } type; unsigned char playing; union { struct s_haptic_core_rumble { unsigned short weak; unsigned short strong; } rumble; struct s_haptic_core_constant { short level; } constant; struct s_haptic_core_condition { struct { unsigned short left; unsigned short right; } saturation; struct { short left; short right; } coefficient; short center; unsigned short deadband; } spring; struct s_haptic_core_condition damper; struct s_haptic_core_leds { unsigned char value; } leds; struct s_haptic_core_range { unsigned short value; } range; }; } *

variable_types: ret int

user_defined_types: struct s_haptic_core_data { enum e_haptic_core_data_type type; unsigned char playing; union { struct s_haptic_core_rumble rumble; struct s_haptic_core_constant constant; struct s_haptic_core_condition spring; struct s_haptic_core_condition damper; struct s_haptic_core_leds leds; struct s_haptic_core_range range; }; }


decompiled_code:
int __fastcall haptic_source_rumble_process(unsigned int *a1, __int64 a2, _BYTE *a3)
{
int v3; // ecx
int result; // eax
int v5; // esi

v3 = *a1;
result = (unsigned __int8)byte_364[10 * *a1];
if ( !(_BYTE)result || *a3 == (_BYTE)result )
{
v5 = 0xFFFF * (unsigned __int8)a3[(unsigned __int8)byte_365[10 * v3]] / (unsigned __int8)byte_366[10 * v3];
result = 0xFFFF * (unsigned __int8)a3[(unsigned __int8)byte_367[10 * v3]] / (unsigned __int8)byte_368[10 * v3];
if ( a1[2] != __PAIR32__(result, v5) )
{
a1[1] = 1;
*((_WORD *)a1 + 4) = v5;
*((_WORD *)a1 + 5) = result;
if ( gimx_params[13] )
{
printf("> RUMBLE, weak=%hu, strong=%hu\n", (unsigned __int16)v5, (unsigned __int16)result);
result = fflush(stdout);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1, __int64 a2, _BYTE *a3)
{
int v3; // ecx
int result; // eax
int v5; // esi

v3 = *a1;
result = (unsigned __int8)byte_364[10 * *a1];
if ( !(_BYTE)result || *a3 == (_BYTE)result )
{
v5 = 0xFFFF * (unsigned __int8)a3[(unsigned __int8)byte_365[10 * v3]] / (unsigned __int8)byte_366[10 * v3];
result = 0xFFFF * (unsigned __int8)a3[(unsigned __int8)byte_367[10 * v3]] / (unsigned __int8)byte_368[10 * v3];
if ( a1[2] != __PAIR32__(result, v5) )
{
a1[1] = 1;
*((_WORD *)a1 + 4) = v5;
*((_WORD *)a1 + 5) = result;
if ( gimx_params[13] )
{
printf("> RUMBLE, weak=%hu, strong=%hu\n", (unsigned __int16)v5, (unsigned __int16)result);
result = fflush(stdout);
}
}
}
return result;
}

original_code:
static void haptic_source_rumble_process(struct haptic_source_state * state, size_t size __attribute((unused)), const unsigned char * data) {
    uint8_t reportId = props[state->props_index].reportId;
    if (reportId != 0x00 && data[0] != reportId) {
        return;
    }
    uint16_t weak = data[props[state->props_index].weak.offset] * (0x7fff * 2 + 1) / props[state->props_index].weak.max;
    uint16_t strong = data[props[state->props_index].strong.offset] * (0x7fff * 2 + 1) / props[state->props_index].strong.max;
    if (weak != state->weak || strong != state->strong) {
        state->updated = 1;
        state->weak = weak;
        state->strong = strong;
        do { if(gimx_params.debug.haptic) { printf("> RUMBLE, weak=%hu, strong=%hu\n", weak, strong); fflush(stdout); } } while (0);
    }
}

canonical_original_code:
static void haptic_source_rumble_process(struct haptic_source_state *state, unsigned long size, unsigned char *data) {
    unsigned char reportId = props[state->props_index].reportId;
    if (reportId != 0x00 && data[0] != reportId) {
        return;
    }
    unsigned short weak = data[props[state->props_index].weak.offset] * (0x7fff * 2 + 1) / props[state->props_index].weak.max;
    unsigned short strong = data[props[state->props_index].strong.offset] * (0x7fff * 2 + 1) / props[state->props_index].strong.max;
    if (weak != state->weak || strong != state->strong) {
        state->updated = 1;
        state->weak = weak;
        state->strong = strong;
        do { if(gimx_params.debug.haptic) { printf("> RUMBLE, weak=%hu, strong=%hu\n", weak, strong); fflush(stdout); } } while (0);
    }
}

variable_types:
size
unsigned long

variable_types:
data
unsigned char *

variable_types:
reportId
unsigned char

variable_types:
weak
unsigned short

variable_types:
strong
unsigned short

user_defined_types: struct haptic_source_state { unsigned int props_index; int updated; unsigned short weak; unsigned short strong; }


decompiled_code:
void __fastcall haptic_source_rumble_clean(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func2(void *a1)
{
free(a1);
}

original_code:
static void haptic_source_rumble_clean(struct haptic_source_state * state) {
    free(state);
}

canonical_original_code:
static void haptic_source_rumble_clean(struct haptic_source_state *state) {
    free(state);
}


decompiled_code:
int haptic_source_rumble_constructor()
{
int result; // eax

result = haptic_source_register(&source_rumble);
if ( result == -1 )
result = fprintf(
stderr,
"%s:%d %s: %s\n",
"haptic/source/haptic_source_rumble.c",
128LL,
"haptic_source_rumble_constructor",
"failed to register source");
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

result = haptic_source_register(&source_rumble);
if ( result == -1 )
result = fprintf(
stderr,
"%s:%d %s: %s\n",
"haptic/source/haptic_source_rumble.c",
128LL,
"haptic_source_rumble_constructor",
"failed to register source");
return result;
}

original_code:
void haptic_source_rumble_constructor(void) {
    if (haptic_source_register(&source_rumble) == -1) {
        fprintf(stderr, "%s:%d %s: %s\n", "haptic/source/haptic_source_rumble.c", 128, __func__, "failed to register source");
    }
}

canonical_original_code:
void haptic_source_rumble_constructor() {
    if (haptic_source_register(&source_rumble) == -1) {
        fprintf(stderr, "%s:%d %s: %s\n", "haptic/source/haptic_source_rumble.c", 128, __func__, "failed to register source");
    }
}


resetColorStdout

decompiled_code:
int resetColorStdout()
{
return printf("%s", "\x1B[0m");
}

canonical_decompiled_code:
int func2()
{
return printf("%s", "\x1B[0m");
}

original_code:
static inline void resetColorStdout(void) {
    printf("%s", ANSI_ATTRIBUTE_RESET);
}

canonical_original_code:
static inline void resetColorStdout() {
    printf("%s", ANSI_ATTRIBUTE_RESET);
}


decompiled_code:
__int64 __fastcall scale_axis(__int64 a1, int a2, __int64 a3)
{
int v3; // ebx

v3 = 100 * *(_DWORD *)(a3 + 4LL * a2);
return (unsigned int)(v3 / (int)controller_get_max_signed());
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
int v3; // ebx

v3 = 100 * *(_DWORD *)(a3 + 4LL * a2);
return (unsigned int)(v3 / (int)controller_get_max_signed());
}

original_code:
static inline int scale_axis(e_controller_type type, int index, int axis[AXIS_MAX])
{
  return axis[index] * 100 / controller_get_max_signed(type, index);
}

canonical_original_code:
static inline int scale_axis(enum e_controller_type type, int index, int axis[-1])
{
  return axis[index] * 100 / controller_get_max_signed(type, index);
}

variable_types: index int

variable_types:
axis
int [-1]

user_defined_types: enum e_controller_type { C_TYPE_JOYSTICK=0, C_TYPE_360_PAD=1, C_TYPE_SIXAXIS=2, C_TYPE_PS2_PAD=3, C_TYPE_XBOX_PAD=4, C_TYPE_DS4=5, C_TYPE_XONE_PAD=6, C_TYPE_T300RS_PS4=7, C_TYPE_G27_PS3=8, C_TYPE_G29_PS4=9, C_TYPE_DF_PS2=10, C_TYPE_DFP_PS2=11, C_TYPE_GTF_PS2=12, C_TYPE_NONE=13, C_TYPE_MAX=expr }


decompiled_code:
__int64 __fastcall gpp_connect(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-38h] BYREF

if ( (unsigned __int8)gppcprog_connect() != 1 )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)gpppcprog_input(a1, &v2, 1000LL) == 1 )
{
if ( BYTE1(v2) == 3 )
{
result = 5LL;
}
else if ( BYTE1(v2) > 3u )
{
result = 0xFFFFFFFFLL;
if ( BYTE1(v2) == 4 )
result = 6LL;
}
else
{
result = 2LL;
if ( BYTE1(v2) != 1 )
result = 2 * (unsigned int)(BYTE1(v2) == 2) - 1;
}
}
else
{
gppcprog_disconnect(a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-38h] BYREF

if ( (unsigned __int8)gppcprog_connect() != 1 )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)gpppcprog_input(a1, &v2, 1000LL) == 1 )
{
if ( BYTE1(v2) == 3 )
{
result = 5LL;
}
else if ( BYTE1(v2) > 3u )
{
result = 0xFFFFFFFFLL;
if ( BYTE1(v2) == 4 )
result = 6LL;
}
else
{
result = 2LL;
if ( BYTE1(v2) != 1 )
result = 2 * (unsigned int)(BYTE1(v2) == 2) - 1;
}
}
else
{
gppcprog_disconnect(a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int gpp_connect(int id, const char* device)
{
  int ret = -1;
  GCAPI_REPORT report;
  if(gppcprog_connect(id, device) != 1)
  {
    return -1;
  }
  if(gpppcprog_input(id, &report, 1000) != 1)
  {
      gppcprog_disconnect(id);
      return -1;
  }
  switch(report.console)
  {
    case 0:
      ret = -1;
      break;
    case 1:
      ret = C_TYPE_SIXAXIS;
      break;
    case 2:
      ret = C_TYPE_360_PAD;
      break;
    case 3:
      ret = C_TYPE_DS4;
      break;
    case 4:
      ret = C_TYPE_XONE_PAD;
      break;
  }
  return ret;
}

canonical_original_code:
int gpp_connect(int id, char *device)
{
  int ret = -1;
  struct GCAPI_REPORT report;
  if(gppcprog_connect(id, device) != 1)
  {
    return -1;
  }
  if(gpppcprog_input(id, &report, 1000) != 1)
  {
      gppcprog_disconnect(id);
      return -1;
  }
  switch(report.console)
  {
    case 0:
      ret = -1;
      break;
    case 1:
      ret = C_TYPE_SIXAXIS;
      break;
    case 2:
      ret = C_TYPE_360_PAD;
      break;
    case 3:
      ret = C_TYPE_DS4;
      break;
    case 4:
      ret = C_TYPE_XONE_PAD;
      break;
  }
  return ret;
}

variable_types: id int

variable_types:
device
char *

variable_types: struct GCAPI_REPORT { unsigned char controller; unsigned char console; unsigned char led[4]; unsigned char rumble[2]; unsigned char battery_level; struct { char value; } input[30]; }


original_code:
int gpp_send(int id, e_controller_type type, int axis[AXIS_MAX])
{
  static int8_t output[7][30] = {};
  int axis_value;
  int ret = 0;
  output[id][13] = scale_axis(type, sa_up, axis);
  output[id][14] = scale_axis(type, sa_down, axis);
  output[id][15] = scale_axis(type, sa_left, axis);
  output[id][16] = scale_axis(type, sa_right, axis);
  output[id][2] = axis[sa_start] ? 100 : 0;
  output[id][1] = axis[sa_select] ? 100 : 0;
  output[id][8] = scale_axis(type, sa_l3, axis);
  output[id][5] = scale_axis(type, sa_r3, axis);
  output[id][6] = scale_axis(type, sa_l1, axis);
  output[id][3] = scale_axis(type, sa_r1, axis);
  output[id][0] = axis[sa_ps] ? 100 : 0;
  output[id][19] = scale_axis(type, sa_cross, axis);
  output[id][18] = scale_axis(type, sa_circle, axis);
  output[id][20] = scale_axis(type, sa_square, axis);
  output[id][17] = scale_axis(type, sa_triangle, axis);
  output[id][7] = scale_axis(type, sa_l2, axis);
  output[id][4] = scale_axis(type, sa_r2, axis);
  axis_value = scale_axis(type, sa_lstick_x, axis);
  output[id][11] = clamp(-100, axis_value, 100);
  axis_value = scale_axis(type, sa_lstick_y, axis);
  output[id][12] = clamp(-100, axis_value, 100);
  axis_value = scale_axis(type, sa_rstick_x, axis);
  output[id][9] = clamp(-100, axis_value, 100);
  axis_value = scale_axis(type, sa_rstick_y, axis);
  output[id][10] = clamp(-100, axis_value, 100);
  if(type == C_TYPE_SIXAXIS)
  {
    axis_value = scale_axis(type, sa_acc_x, axis);
    output[id][21] = clamp(-100, axis_value, 100);
    axis_value = scale_axis(type, sa_acc_y, axis);
    output[id][22] = clamp(-100, axis_value, 100);
    axis_value = scale_axis(type, sa_acc_z, axis);
    output[id][23] = clamp(-100, axis_value, 100);
    axis_value = scale_axis(type, sa_gyro, axis);
    output[id][24] = clamp(-100, axis_value, 100);
  }
  else if(type == C_TYPE_DS4)
  {
    output[id][27] = axis[ds4a_touchpad] ? 100 : 0;
    if(axis[ds4a_finger1])
    {
      axis_value = output[id][28] + scale_axis(type, ds4a_finger1_x, axis);
      output[id][28] = clamp(-100, axis_value, 100);
      axis_value = output[id][29] + scale_axis(type, ds4a_finger1_y, axis);
      output[id][29] = clamp(-100, axis_value, 100);
    }
    else
    {
      output[id][28] = 101;
      output[id][29] = 101;
    }
  }
  int res = gpppcprog_output(id, output[id]);
  if(res < 0)
  {
    ret = -1;
  }
  else if (res == 0)
  {
    do { if(!gimx_params.curses_status) { setColorStdout(YELLOW); printf("Warning: "); resetColorStdout(); printf("device is busy\n"); fflush(stdout); } } while (0);
  }
  return ret;
}

canonical_original_code:
int gpp_send(int id, enum e_controller_type type, int axis[-1])
{
  static char output[7][30] = {};
  int axis_value;
  int ret = 0;
  output[id][13] = scale_axis(type, sa_up, axis);
  output[id][14] = scale_axis(type, sa_down, axis);
  output[id][15] = scale_axis(type, sa_left, axis);
  output[id][16] = scale_axis(type, sa_right, axis);
  output[id][2] = axis[sa_start] ? 100 : 0;
  output[id][1] = axis[sa_select] ? 100 : 0;
  output[id][8] = scale_axis(type, sa_l3, axis);
  output[id][5] = scale_axis(type, sa_r3, axis);
  output[id][6] = scale_axis(type, sa_l1, axis);
  output[id][3] = scale_axis(type, sa_r1, axis);
  output[id][0] = axis[sa_ps] ? 100 : 0;
  output[id][19] = scale_axis(type, sa_cross, axis);
  output[id][18] = scale_axis(type, sa_circle, axis);
  output[id][20] = scale_axis(type, sa_square, axis);
  output[id][17] = scale_axis(type, sa_triangle, axis);
  output[id][7] = scale_axis(type, sa_l2, axis);
  output[id][4] = scale_axis(type, sa_r2, axis);
  axis_value = scale_axis(type, sa_lstick_x, axis);
  output[id][11] = clamp(-100, axis_value, 100);
  axis_value = scale_axis(type, sa_lstick_y, axis);
  output[id][12] = clamp(-100, axis_value, 100);
  axis_value = scale_axis(type, sa_rstick_x, axis);
  output[id][9] = clamp(-100, axis_value, 100);
  axis_value = scale_axis(type, sa_rstick_y, axis);
  output[id][10] = clamp(-100, axis_value, 100);
  if(type == C_TYPE_SIXAXIS)
  {
    axis_value = scale_axis(type, sa_acc_x, axis);
    output[id][21] = clamp(-100, axis_value, 100);
    axis_value = scale_axis(type, sa_acc_y, axis);
    output[id][22] = clamp(-100, axis_value, 100);
    axis_value = scale_axis(type, sa_acc_z, axis);
    output[id][23] = clamp(-100, axis_value, 100);
    axis_value = scale_axis(type, sa_gyro, axis);
    output[id][24] = clamp(-100, axis_value, 100);
  }
  else if(type == C_TYPE_DS4)
  {
    output[id][27] = axis[ds4a_touchpad] ? 100 : 0;
    if(axis[ds4a_finger1])
    {
      axis_value = output[id][28] + scale_axis(type, ds4a_finger1_x, axis);
      output[id][28] = clamp(-100, axis_value, 100);
      axis_value = output[id][29] + scale_axis(type, ds4a_finger1_y, axis);
      output[id][29] = clamp(-100, axis_value, 100);
    }
    else
    {
      output[id][28] = 101;
      output[id][29] = 101;
    }
  }
  int res = gpppcprog_output(id, output[id]);
  if(res < 0)
  {
    ret = -1;
  }
  else if (res == 0)
  {
    do { if(!gimx_params.curses_status) { setColorStdout(YELLOW); printf("Warning: "); resetColorStdout(); printf("device is busy\n"); fflush(stdout); } } while (0);
  }
  return ret;
}

variable_types: enum e_controller_type { C_TYPE_JOYSTICK=0, C_TYPE_360_PAD=1, C_TYPE_SIXAXIS=2, C_TYPE_PS2_PAD=3, C_TYPE_XBOX_PAD=4, C_TYPE_DS4=5, C_TYPE_XONE_PAD=6, C_TYPE_T300RS_PS4=7, C_TYPE_G27_PS3=8, C_TYPE_G29_PS4=9, C_TYPE_DF_PS2=10, C_TYPE_DFP_PS2=11, C_TYPE_GTF_PS2=12, C_TYPE_NONE=13, C_TYPE_MAX=expr }

variable_types:
output
char [7][30]

variable_types: res int


decompiled_code:
__int64 gpp_start_async()
{
return gpppcprog_start_async();
}

canonical_decompiled_code:
__int64 func6()
{
return gpppcprog_start_async();
}

original_code:
int8_t gpp_start_async(int id, const GHID_CALLBACKS * callbacks)
{
  return gpppcprog_start_async(id, callbacks);
}

canonical_original_code:
char gpp_start_async(int id, struct GHID_CALLBACKS *callbacks)
{
  return gpppcprog_start_async(id, callbacks);
}

variable_types: struct GHID_CALLBACKS { int (*fp_read)(void *user, void *buf, int status); int (*fp_write)(void *user, int status); int (*fp_close)(void *user); int (*fp_register)(int fd, void *user, struct GPOLL_CALLBACKS { int (*fp_read)(void *user); int (*fp_write)(void *user); int (*fp_close)(void *user); } *callbacks); int (*fp_remove)(int fd); } *

return_type: char

user_defined_types: struct GHID_CALLBACKS { int (*fp_read)(void *user, void *buf, int status); int (*fp_write)(void *user, int status); int (*fp_close)(void *user); int (*fp_register)(int fd, void *user, struct GPOLL_CALLBACKS *callbacks); int (*fp_remove)(int fd); }


decompiled_code:
__int64 __fastcall gpp_disconnect(__int64 a1)
{
return gppcprog_disconnect(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return gppcprog_disconnect(a1);
}

original_code:
void gpp_disconnect(int id)
{
  gppcprog_disconnect(id);
}


decompiled_code:
_BOOL8 __fastcall compare_cmd(__int16 a1, __int16 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_BYTE)a1 == (_BYTE)a2 )
{
result = 1LL;
if ( (_BYTE)a1 == 0xF8 )
result = HIBYTE(a1) == HIBYTE(a2);
}
return result;
}

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

result = 0LL;
if ( (_BYTE)a1 == (_BYTE)a2 )
{
result = 1LL;
if ( (_BYTE)a1 == 0xF8 )
result = HIBYTE(a1) == HIBYTE(a2);
}
return result;
}

original_code:
static inline int compare_cmd(s_cmd cmd1, s_cmd cmd2) {
    return cmd1.cmd == cmd2.cmd && (cmd1.cmd != 0xF8 || cmd1.ext == cmd2.ext);
}

canonical_original_code:
static inline int compare_cmd(struct s_cmd cmd1, struct s_cmd cmd2) {
    return cmd1.cmd == cmd2.cmd && (cmd1.cmd != 0xF8 || cmd1.ext == cmd2.ext);
}

variable_types: struct s_cmd { unsigned char cmd; unsigned char ext; }


canonical_decompiled_code:
int func3()
{
return printf("%s", "\x1B[0m");
}


original_code:
static void process_extended(struct haptic_source_state * state, const unsigned char data[7]) {
    s_cmd cmd = { 0xF8, data[1] };
    int i;
    for (i = 0; i < 16; ++i) {
        s_ext_cmd * ext_cmd = state->ext_cmds + i;
        if(!ext_cmd->cmd[0]) {
            memcpy(ext_cmd->cmd, data, sizeof(ext_cmd->cmd));
            ext_cmd->updated = 1;
            ff_lg_fifo_push(state->fifo, cmd, 1);
            break;
        } else if(ext_cmd->cmd[1] == data[1]) {
            if(memcmp(ext_cmd->cmd, data, sizeof(ext_cmd->cmd))) {
                memcpy(ext_cmd->cmd, data, sizeof(ext_cmd->cmd));
                ext_cmd->updated = 1;
                ff_lg_fifo_push(state->fifo, cmd, 1);
            } else {
                do { if(gimx_params.debug.haptic) { printf("> no change\n"); fflush(stdout); } } while (0);
            }
            break;
        }
    }
}

canonical_original_code:
static void process_extended(struct haptic_source_state *state, unsigned char data[7]) {
    struct s_cmd cmd = { 0xF8, data[1] };
    int i;
    for (i = 0; i < 16; ++i) {
        struct s_ext_cmd *ext_cmd = state->ext_cmds + i;
        if(!ext_cmd->cmd[0]) {
            memcpy(ext_cmd->cmd, data, sizeof(ext_cmd->cmd));
            ext_cmd->updated = 1;
            ff_lg_fifo_push(state->fifo, cmd, 1);
            break;
        } else if(ext_cmd->cmd[1] == data[1]) {
            if(memcmp(ext_cmd->cmd, data, sizeof(ext_cmd->cmd))) {
                memcpy(ext_cmd->cmd, data, sizeof(ext_cmd->cmd));
                ext_cmd->updated = 1;
                ff_lg_fifo_push(state->fifo, cmd, 1);
            } else {
                do { if(gimx_params.debug.haptic) { printf("> no change\n"); fflush(stdout); } } while (0);
            }
            break;
        }
    }
}

variable_types: struct haptic_source_state { unsigned char caps; unsigned char cmd_offset; unsigned short range; struct s_force { unsigned char mask; unsigned char playing; unsigned char updated; unsigned char parameters[-1]; } forces[4]; struct s_ext_cmd { unsigned char updated; unsigned char cmd[7]; } ext_cmds[16]; struct s_cmd { unsigned char cmd; unsigned char ext; } fifo[16]; } *

variable_types:
data
unsigned char [7]

variable_types: i int

variable_types: struct s_ext_cmd { unsigned char updated; unsigned char cmd[7]; } *

user_defined_types: struct haptic_source_state { unsigned char caps; unsigned char cmd_offset; unsigned short range; struct s_force forces[4]; struct s_ext_cmd ext_cmds[16]; struct s_cmd fifo[16]; }


original_code:
static void set_wheel_range(struct haptic_source_state * state, unsigned short range) {
    if (range == state->range) {
        return;
    }
    state->range = range;
    unsigned char change_wheel_range[7] = {
            0xF8,
            0x81,
            range & 0xFF,
            range >> 8
    };
    process_extended(state, change_wheel_range);
}

canonical_original_code:
static void set_wheel_range(struct haptic_source_state *state, unsigned short range) {
    if (range == state->range) {
        return;
    }
    state->range = range;
    unsigned char change_wheel_range[7] = {
            0xF8,
            0x81,
            range & 0xFF,
            range >> 8
    };
    process_extended(state, change_wheel_range);
}

variable_types:
range
unsigned short

user_defined_types: struct s_force { unsigned char mask; unsigned char playing; unsigned char updated; unsigned char parameters[-1]; }

user_defined_types: struct s_ext_cmd { unsigned char updated; unsigned char cmd[7]; }

user_defined_types: struct s_cmd { unsigned char cmd; unsigned char ext; }


decompiled_code:
void __fastcall ff_lg_fifo_remove(void *dest, __int16 a2)
{
__int16 v2; // r12
_WORD *v3; // rbx
__int64 v4; // rbp

HIBYTE(v2) = HIBYTE(a2);
v3 = dest;
v4 = 0LL;
while ( *(_BYTE *)v3 )
{
LOBYTE(v2) = a2;
if ( compare_cmd(*v3, v2) )
{
if ( gimx_params[13] )
{
printf("> remove %02x", (unsigned __int8)a2);
fflush(stdout);
if ( (_BYTE)a2 != 0xF8 )
goto LABEL_8;
if ( gimx_params[13] )
{
printf(" %02x", HIBYTE(a2));
fflush(stdout);
goto LABEL_8;
}
}
else if ( (_BYTE)a2 != 0xF8 )
{
LABEL_8:
if ( gimx_params[13] )
{
putchar(10);
fflush(stdout);
}
}
memmove(v3, (char *)dest + 2 * v4 + 2, 2LL * (3 - (int)v4));
*((_WORD *)dest + 4 - v4 - 1) = 0;
return;
}
++v4;
++v3;
if ( v4 == 16 )
return;
}
}

canonical_decompiled_code:
void __fastcall func9(void *dest, __int16 a2)
{
__int16 v2; // r12
_WORD *v3; // rbx
__int64 v4; // rbp

HIBYTE(v2) = HIBYTE(a2);
v3 = dest;
v4 = 0LL;
while ( *(_BYTE *)v3 )
{
LOBYTE(v2) = a2;
if ( func1(*v3, v2) )
{
if ( gimx_params[13] )
{
printf("> remove %02x", (unsigned __int8)a2);
fflush(stdout);
if ( (_BYTE)a2 != 0xF8 )
goto LABEL_8;
if ( gimx_params[13] )
{
printf(" %02x", HIBYTE(a2));
fflush(stdout);
goto LABEL_8;
}
}
else if ( (_BYTE)a2 != 0xF8 )
{
LABEL_8:
if ( gimx_params[13] )
{
putchar(10);
fflush(stdout);
}
}
memmove(v3, (char *)dest + 2 * v4 + 2, 2LL * (3 - (int)v4));
*((_WORD *)dest + 4 - v4 - 1) = 0;
return;
}
++v4;
++v3;
if ( v4 == 16 )
return;
}
}

original_code:
static inline void ff_lg_fifo_remove(s_cmd fifo[16], s_cmd cmd) {
    int i;
    for (i = 0; i < 16; ++i) {
        if (!fifo[i].cmd) {
            break;
        } else if (compare_cmd(fifo[i], cmd)) {
            do { if(gimx_params.debug.haptic) { printf("> remove %02x", cmd.cmd); fflush(stdout); } } while (0);
            if(cmd.cmd == 0xF8) {
                do { if(gimx_params.debug.haptic) { printf(" %02x", cmd.ext); fflush(stdout); } } while (0);
            }
            do { if(gimx_params.debug.haptic) { printf("\n"); fflush(stdout); } } while (0);
            memmove(fifo + i, fifo + i + 1, (4 - i - 1) * sizeof(*fifo));
            memset(fifo + 4 - i - 1, 0x00, sizeof(*fifo));
            break;
        }
    }
}

canonical_original_code:
static inline void ff_lg_fifo_remove(struct s_cmd fifo[16], struct s_cmd cmd) {
    int i;
    for (i = 0; i < 16; ++i) {
        if (!fifo[i].cmd) {
            break;
        } else if (compare_cmd(fifo[i], cmd)) {
            do { if(gimx_params.debug.haptic) { printf("> remove %02x", cmd.cmd); fflush(stdout); } } while (0);
            if(cmd.cmd == 0xF8) {
                do { if(gimx_params.debug.haptic) { printf(" %02x", cmd.ext); fflush(stdout); } } while (0);
            }
            do { if(gimx_params.debug.haptic) { printf("\n"); fflush(stdout); } } while (0);
            memmove(fifo + i, fifo + i + 1, (4 - i - 1) * sizeof(*fifo));
            memset(fifo + 4 - i - 1, 0x00, sizeof(*fifo));
            break;
        }
    }
}

variable_types: struct s_cmd { unsigned char cmd; unsigned char ext; } [16]

variable_types:
cmd
struct s_cmd


decompiled_code:
__int64 __fastcall haptic_source_lg_get(unsigned __int8 *a1, __int64 a2)
{
__int16 v2; // bx
__int64 result; // rax
unsigned __int8 v4; // al
__int64 v5; // rdx
unsigned __int8 *v6; // rax

v2 = ff_lg_fifo_peek(a1 + 168);
result = 0LL;
if ( (_BYTE)v2 )
{
ff_lg_fifo_remove(a1 + 168, v2);
if ( (_BYTE)v2 == 0xF8 )
{
v6 = a1 + 40;
while ( v6[2] != HIBYTE(v2) )
{
v6 += 8;
if ( v6 == a1 + 168 )
return 0LL;
}
*v6 = 0;
result = ff_lg_convert_extended(v6 + 2, a2);
}
else
{
result = 0LL;
if ( (v2 & 0xF) == 0 )
{
v4 = slot_index[(unsigned __int8)v2 >> 4];
v5 = 9LL * v4;
a1[v5 + 6] = 0;
result = ff_lg_convert_force(*a1, v4, &a1[v5 + 7], a1[v5 + 5], a2);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, __int64 a2)
{
__int16 v2; // bx
__int64 result; // rax
unsigned __int8 v4; // al
__int64 v5; // rdx
unsigned __int8 *v6; // rax

v2 = func8(a1 + 168);
result = 0LL;
if ( (_BYTE)v2 )
{
func9(a1 + 168, v2);
if ( (_BYTE)v2 == 0xF8 )
{
v6 = a1 + 40;
while ( v6[2] != HIBYTE(v2) )
{
v6 += 8;
if ( v6 == a1 + 168 )
return 0LL;
}
*v6 = 0;
result = ff_lg_convert_extended(v6 + 2, a2);
}
else
{
result = 0LL;
if ( (v2 & 0xF) == 0 )
{
v4 = slot_index[(unsigned __int8)v2 >> 4];
v5 = 9LL * v4;
a1[v5 + 6] = 0;
result = ff_lg_convert_force(*a1, v4, &a1[v5 + 7], a1[v5 + 5], a2);
}
}
}
return result;
}

original_code:
static int haptic_source_lg_get(struct haptic_source_state * state, s_haptic_core_data * data) {
    s_cmd cmd = ff_lg_fifo_peek(state->fifo);
    if (cmd.cmd) {
        ff_lg_fifo_remove(state->fifo, cmd);
        if(cmd.cmd != 0xF8) {
            if(cmd.cmd & 0x0f)
            {
                return 0;
            }
            else
            {
                unsigned char index = slot_index[cmd.cmd >> 4];
                s_force * force = state->forces + index;
                force->updated = 0;
                return ff_lg_convert_force(state->caps, index, (s_ff_lg_command *)state->forces[index].parameters, state->forces[index].playing, data);
            }
        }
        else {
            int i;
            for (i = 0; i < 16; ++i) {
                s_ext_cmd * ext_cmd = state->ext_cmds + i;
                if(ext_cmd->cmd[1] == cmd.ext) {
                    ext_cmd->updated = 0;
                    return ff_lg_convert_extended((s_ff_lg_command *)(ext_cmd->cmd + 1), data);
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
static int haptic_source_lg_get(struct haptic_source_state *state, struct s_haptic_core_data *data) {
    struct s_cmd cmd = ff_lg_fifo_peek(state->fifo);
    if (cmd.cmd) {
        ff_lg_fifo_remove(state->fifo, cmd);
        if(cmd.cmd != 0xF8) {
            if(cmd.cmd & 0x0f)
            {
                return 0;
            }
            else
            {
                unsigned char index = slot_index[cmd.cmd >> 4];
                struct s_force *force = state->forces + index;
                force->updated = 0;
                return ff_lg_convert_force(state->caps, index, (struct s_ff_lg_command *)state->forces[index].parameters, state->forces[index].playing, data);
            }
        }
        else {
            int i;
            for (i = 0; i < 16; ++i) {
                struct s_ext_cmd *ext_cmd = state->ext_cmds + i;
                if(ext_cmd->cmd[1] == cmd.ext) {
                    ext_cmd->updated = 0;
                    return ff_lg_convert_extended((struct s_ff_lg_command *)(ext_cmd->cmd + 1), data);
                }
            }
        }
    }
    return 0;
}

variable_types: struct s_haptic_core_data { enum e_haptic_core_data_type { E_DATA_TYPE_NONE=0, E_DATA_TYPE_RUMBLE=1, E_DATA_TYPE_CONSTANT=2, E_DATA_TYPE_SPRING=3, E_DATA_TYPE_DAMPER=4, E_DATA_TYPE_LEDS=5, E_DATA_TYPE_RANGE=6 } type; unsigned char playing; union { struct s_haptic_core_rumble { unsigned short weak; unsigned short strong; } rumble; struct s_haptic_core_constant { short level; } constant; struct s_haptic_core_condition { struct { unsigned short left; unsigned short right; } saturation; struct { short left; short right; } coefficient; short center; unsigned short deadband; } spring; struct s_haptic_core_condition damper; struct s_haptic_core_leds { unsigned char value; } leds; struct s_haptic_core_range { unsigned short value; } range; }; } *

variable_types:
index
unsigned char

variable_types: struct s_force { unsigned char mask; unsigned char playing; unsigned char updated; unsigned char parameters[-1]; } *

user_defined_types: struct s_ff_lg_command { union { unsigned char force_type; unsigned char cmd_param; }; unsigned char parameters[-1]; }


decompiled_code:
void __fastcall haptic_source_lg_clean(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func12(void *a1)
{
free(a1);
}

original_code:
static void haptic_source_lg_clean(struct haptic_source_state * state) {
    free(state);
}

canonical_original_code:
static void haptic_source_lg_clean(struct haptic_source_state *state) {
    free(state);
}


decompiled_code:
int haptic_source_lg_constructor()
{
int result; // eax

result = haptic_source_register(&source_lg);
if ( result == -1 )
result = fprintf(
stderr,
"%s:%d %s: %s\n",
"haptic/source/haptic_source_lg.c",
295LL,
"haptic_source_lg_constructor",
"failed to register source");
return result;
}

canonical_decompiled_code:
int func13()
{
int result; // eax

result = haptic_source_register(&source_lg);
if ( result == -1 )
result = fprintf(
stderr,
"%s:%d %s: %s\n",
"haptic/source/haptic_source_lg.c",
295LL,
"haptic_source_lg_constructor",
"failed to register source");
return result;
}

original_code:
void haptic_source_lg_constructor(void) {
    if (haptic_source_register(&source_lg) == -1) {
        fprintf(stderr, "%s:%d %s: %s\n", "haptic/source/haptic_source_lg.c", 295, __func__, "failed to register source");
    }
}

canonical_original_code:
void haptic_source_lg_constructor() {
    if (haptic_source_register(&source_lg) == -1) {
        fprintf(stderr, "%s:%d %s: %s\n", "haptic/source/haptic_source_lg.c", 295, __func__, "failed to register source");
    }
}


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

result = ghid_write(*(_QWORD *)a1, a1 + 16, 32LL);
if ( !(_DWORD)result )
*(_DWORD *)(a1 + 8) = 1;
return result;
}

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

result = ghid_write(*(_QWORD *)a1, a1 + 16, 32LL);
if ( !(_DWORD)result )
*(_DWORD *)(a1 + 8) = 1;
return result;
}

original_code:
static int send_report(int sixaxis_number, uint16_t psm, uint8_t type, uint8_t report, int blocking)
{
  uint8_t buf[128];
  int len = 0;
  int i;
  struct sixaxis_state* state = states + sixaxis_number;
  for (i = 0; sixaxis_assemble[i].func; i++)
  {
    if (sixaxis_assemble[i].type == type
        && sixaxis_assemble[i].report == report)
    {
      len = sixaxis_assemble[i].func(&buf[2], sizeof(buf) - 2, state);
      break;
    }
  }
  if (!sixaxis_assemble[i].func || len < 0)
  {
    do { if(!gimx_params.curses_status) { setColorStdout(YELLOW); printf("Warning: "); resetColorStdout(); printf("%s %s report 0x%02x, sending empty response\n", (len < 0) ? "Error assembling" : "Unknown", hid_report_name[type], report); fflush(stdout); } } while (0);
    len = 0;
  }
  buf[0] = 0xa0 | type;
  buf[1] = report;
  len += 2;
  if (gimx_params.debug.sixaxis)
  {
    gtime now = gtime_gettime();
    do { if(!gimx_params.curses_status) { printf("%lu.%06lu Sixaxis %-7s %02x:", ((gtimepart)((now) / 1000000000ULL)), (((gtimepart)((now) % 1000000000ULL)) / 1000UL), hid_report_name[type], report); fflush(stdout); } } while (0);
    for (i = 2; i < len; i++)
      do { if(!gimx_params.curses_status) { printf(" %02x", buf[i]); fflush(stdout); } } while (0);
    do { if(!gimx_params.curses_status) { printf("\n"); fflush(stdout); } } while (0);
  }
  return l2cap_abs_get()->send((psm == 0x11) ? state->channels.control.id : state->channels.interrupt.id, buf, len, blocking);
}

canonical_original_code:
static int send_report(int sixaxis_number, unsigned short psm, unsigned char type, unsigned char report, int blocking)
{
  unsigned char buf[128];
  int len = 0;
  int i;
  struct sixaxis_state *state = states + sixaxis_number;
  for (i = 0; sixaxis_assemble[i].func; i++)
  {
    if (sixaxis_assemble[i].type == type
        && sixaxis_assemble[i].report == report)
    {
      len = sixaxis_assemble[i].func(&buf[2], sizeof(buf) - 2, state);
      break;
    }
  }
  if (!sixaxis_assemble[i].func || len < 0)
  {
    do { if(!gimx_params.curses_status) { setColorStdout(YELLOW); printf("Warning: "); resetColorStdout(); printf("%s %s report 0x%02x, sending empty response\n", (len < 0) ? "Error assembling" : "Unknown", hid_report_name[type], report); fflush(stdout); } } while (0);
    len = 0;
  }
  buf[0] = 0xa0 | type;
  buf[1] = report;
  len += 2;
  if (gimx_params.debug.sixaxis)
  {
    unsigned long long now = gtime_gettime();
    do { if(!gimx_params.curses_status) { printf("%lu.%06lu Sixaxis %-7s %02x:", ((gtimepart)((now) / 1000000000ULL)), (((gtimepart)((now) % 1000000000ULL)) / 1000UL), hid_report_name[type], report); fflush(stdout); } } while (0);
    for (i = 2; i < len; i++)
      do { if(!gimx_params.curses_status) { printf(" %02x", buf[i]); fflush(stdout); } } while (0);
    do { if(!gimx_params.curses_status) { printf("\n"); fflush(stdout); } } while (0);
  }
  return l2cap_abs_get()->send((psm == 0x11) ? state->channels.control.id : state->channels.interrupt.id, buf, len, blocking);
}

variable_types:
psm
unsigned short

variable_types:
type
unsigned char

variable_types:
report
unsigned char

variable_types: blocking int

variable_types:
buf
unsigned char [128]

variable_types: len int

variable_types: struct sixaxis_state { struct { char str[18]; struct bdaddr_t { unsigned char b[6]; } ba; } bdaddr_src; char bdaddr_dst[18]; int dongle_index; int sixaxis_number; struct sixaxis_state_sys { int reporting_enabled; int shutdown; int feature_ef_byte_6; enum led_state_t { LED_OFF=0, LED_FLASH=1, LED_ON=2 } led[5]; unsigned char rumble[2]; } sys; struct s_report_ds3 { unsigned char report_id; unsigned char unused1; unsigned char buttons1; unsigned char buttons2; unsigned char buttons3; unsigned char unused2; char X; char Y; char Z; char Rz; unsigned char unknown1[4]; unsigned char up; unsigned char right; unsigned char down; unsigned char left; unsigned char l2; unsigned char r2; unsigned char l1; unsigned char r1; unsigned char triangle; unsigned char circle; unsigned char cross; unsigned char square; unsigned char unknown2[15]; unsigned char acc_x[2]; unsigned char acc_y[2]; unsigned char acc_z[2]; unsigned char gyro[2]; } user; struct { struct { int id; int pending; } control; struct { int id; int pending; } interrupt; } channels; } *

variable_types:
now
unsigned long long

user_defined_types: struct sixaxis_state { struct { char str[18]; struct bdaddr_t ba; } bdaddr_src; char bdaddr_dst[18]; int dongle_index; int sixaxis_number; struct sixaxis_state_sys sys; struct s_report_ds3 user; struct { struct { int id; int pending; } control; struct { int id; int pending; } interrupt; } channels; }

user_defined_types: struct sixaxis_state_sys { int reporting_enabled; int shutdown; int feature_ef_byte_6; enum led_state_t led[5]; unsigned char rumble[2]; }


decompiled_code:
__int64 haptic_sink_ds4_constructor()
{
return haptic_sink_register(&sink_ds4);
}

canonical_decompiled_code:
__int64 func7()
{
return haptic_sink_register(&sink_ds4);
}

original_code:
void haptic_sink_ds4_constructor(void) {
    haptic_sink_register(&sink_ds4);
}

canonical_original_code:
void haptic_sink_ds4_constructor() {
    haptic_sink_register(&sink_ds4);
}


decompiled_code:
void haptic_source_destructor()
{
free(sources);
nb_sources = 0;
}

canonical_decompiled_code:
void func0()
{
free(sources);
nb_sources = 0;
}

original_code:
void haptic_source_destructor(void) {
    free(sources);
    nb_sources = 0;
}


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

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

original_code:
static int clocked_timer_read(void * user __attribute__((unused)))
{
  return 1;
}

canonical_original_code:
static int clocked_timer_read(void *user)
{
  return 1;
}

variable_types:
user
void *


decompiled_code:
__int64 default_timer_read()
{
return (unsigned int)done;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)done;
}

original_code:
static int default_timer_read(void * user __attribute__((unused)))
{
  return done;
}

canonical_original_code:
static int default_timer_read(void *user)
{
  return done;
}


canonical_decompiled_code:
int func4()
{
return printf("%s", "\x1B[0m");
}

original_code:
static inline void resetColorStdout(void) {
    printf("%s", ANSI_ATTRIBUTE_RESET);
}


decompiled_code:
void set_done()
{
done = 1;
}

canonical_decompiled_code:
void func5()
{
done = 1;
}

original_code:
void set_done()
{
  done = 1;
}

canonical_original_code:
void set_done()
{
  done = 1;
}


decompiled_code:
__int64 timer_close()
{
set_done();
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
func5();
return 1LL;
}

original_code:
static int timer_close(void * user __attribute__((unused)))
{
  set_done();
  return 1;
}

canonical_original_code:
static int timer_close(void *user)
{
  set_done();
  return 1;
}


decompiled_code:
__int64 get_done()
{
return (unsigned int)done;
}

canonical_decompiled_code:
__int64 func7()
{
return (unsigned int)done;
}

original_code:
int get_done()
{
  return done;
}

canonical_original_code:
int get_done()
{
  return done;
}