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

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

original_code:
static void haptic_sink_os_clean(struct haptic_sink_state * state) {
    free(state);
}

canonical_original_code:
static void haptic_sink_os_clean(struct haptic_sink_state *state) {
    free(state);
}


repo: matlo/GIMX

decompiled_code:
__int64 haptic_sink_os_constructor()
{
return haptic_sink_register(&sink_os);
}

canonical_decompiled_code:
__int64 func4()
{
return haptic_sink_register(&sink_os);
}

original_code:
void haptic_sink_os_constructor(void) {
    haptic_sink_register(&sink_os);
}

canonical_original_code:
void haptic_sink_os_constructor() {
    haptic_sink_register(&sink_os);
}

return_type: void


decompiled_code:
int __fastcall dump_event(unsigned __int8 *a1)
{
int result; // eax
int v2; // edx

result = *a1;
v2 = gimx_params[13];
if ( (_BYTE)result == 12 )
{
if ( v2 )
{
printf(
"< SPRING, saturation: %u %u, coefficient: %u %u, center: %d, deadband: %u\n",
*((unsigned __int16 *)a1 + 1),
*((unsigned __int16 *)a1 + 2),
(unsigned int)*((__int16 *)a1 + 3),
(unsigned int)*((__int16 *)a1 + 4),
(unsigned int)*((__int16 *)a1 + 5),
*((unsigned __int16 *)a1 + 6));
result = fflush(stdout);
}
}
else if ( (unsigned __int8)result > 0xCu )
{
if ( (_BYTE)result != 13 )
{
LABEL_10:
if ( v2 )
{
puts("< UNKNOWN");
result = fflush(stdout);
}
return result;
}
if ( v2 )
{
printf(
"< DAMPER, saturation: %u %u, coefficient: %d %d\n",
*((unsigned __int16 *)a1 + 1),
*((unsigned __int16 *)a1 + 2),
(unsigned int)*((__int16 *)a1 + 3),
(unsigned int)*((__int16 *)a1 + 4));
result = fflush(stdout);
}
}
else
{
if ( (_BYTE)result != 10 )
{
if ( (_BYTE)result == 11 )
{
if ( v2 )
{
printf("< CONSTANT, level: %d\n", (unsigned int)*((__int16 *)a1 + 1));
result = fflush(stdout);
}
return result;
}
goto LABEL_10;
}
if ( v2 )
{
printf("< RUMBLE, weak=%hu, strong=%hu\n", *((unsigned __int16 *)a1 + 1), *((unsigned __int16 *)a1 + 2));
result = fflush(stdout);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int8 *a1)
{
int result; // eax
int v2; // edx

result = *a1;
v2 = gimx_params[13];
if ( (_BYTE)result == 12 )
{
if ( v2 )
{
printf(
"< SPRING, saturation: %u %u, coefficient: %u %u, center: %d, deadband: %u\n",
*((unsigned __int16 *)a1 + 1),
*((unsigned __int16 *)a1 + 2),
(unsigned int)*((__int16 *)a1 + 3),
(unsigned int)*((__int16 *)a1 + 4),
(unsigned int)*((__int16 *)a1 + 5),
*((unsigned __int16 *)a1 + 6));
result = fflush(stdout);
}
}
else if ( (unsigned __int8)result > 0xCu )
{
if ( (_BYTE)result != 13 )
{
LABEL_10:
if ( v2 )
{
puts("< UNKNOWN");
result = fflush(stdout);
}
return result;
}
if ( v2 )
{
printf(
"< DAMPER, saturation: %u %u, coefficient: %d %d\n",
*((unsigned __int16 *)a1 + 1),
*((unsigned __int16 *)a1 + 2),
(unsigned int)*((__int16 *)a1 + 3),
(unsigned int)*((__int16 *)a1 + 4));
result = fflush(stdout);
}
}
else
{
if ( (_BYTE)result != 10 )
{
if ( (_BYTE)result == 11 )
{
if ( v2 )
{
printf("< CONSTANT, level: %d\n", (unsigned int)*((__int16 *)a1 + 1));
result = fflush(stdout);
}
return result;
}
goto LABEL_10;
}
if ( v2 )
{
printf("< RUMBLE, weak=%hu, strong=%hu\n", *((unsigned __int16 *)a1 + 1), *((unsigned __int16 *)a1 + 2));
result = fflush(stdout);
}
}
return result;
}

original_code:
static void dump_event(const GE_Event * event) {
    switch (event->type) {
    case GE_JOYRUMBLE:
        do { if(gimx_params.debug.haptic) { printf("< RUMBLE, weak=%hu, strong=%hu\n", event->jrumble.weak, event->jrumble.strong); fflush(stdout); } } while (0);
        break;
    case GE_JOYCONSTANTFORCE:
        do { if(gimx_params.debug.haptic) { printf("< CONSTANT, level: %d\n", event->jconstant.level); fflush(stdout); } } while (0);
        break;
    case GE_JOYSPRINGFORCE:
        do { if(gimx_params.debug.haptic) { printf("< SPRING, saturation: %u %u, coefficient: %u %u, center: %d, deadband: %u\n", event->jcondition.saturation.left, event->jcondition.saturation.right, event->jcondition.coefficient.left, event->jcondition.coefficient.right, event->jcondition.center, event->jcondition.deadband); fflush(stdout); } } while (0);
        break;
    case GE_JOYDAMPERFORCE:
        do { if(gimx_params.debug.haptic) { printf("< DAMPER, saturation: %u %u, coefficient: %d %d\n", event->jcondition.saturation.left, event->jcondition.saturation.right, event->jcondition.coefficient.left, event->jcondition.coefficient.right); fflush(stdout); } } while (0);
        break;
    default:
        do { if(gimx_params.debug.haptic) { printf("< UNKNOWN\n"); fflush(stdout); } } while (0);
        break;
    }
}

canonical_original_code:
static void dump_event(union GE_Event *event) {
    switch (event->type) {
    case GE_JOYRUMBLE:
        do { if(gimx_params.debug.haptic) { printf("< RUMBLE, weak=%hu, strong=%hu\n", event->jrumble.weak, event->jrumble.strong); fflush(stdout); } } while (0);
        break;
    case GE_JOYCONSTANTFORCE:
        do { if(gimx_params.debug.haptic) { printf("< CONSTANT, level: %d\n", event->jconstant.level); fflush(stdout); } } while (0);
        break;
    case GE_JOYSPRINGFORCE:
        do { if(gimx_params.debug.haptic) { printf("< SPRING, saturation: %u %u, coefficient: %u %u, center: %d, deadband: %u\n", event->jcondition.saturation.left, event->jcondition.saturation.right, event->jcondition.coefficient.left, event->jcondition.coefficient.right, event->jcondition.center, event->jcondition.deadband); fflush(stdout); } } while (0);
        break;
    case GE_JOYDAMPERFORCE:
        do { if(gimx_params.debug.haptic) { printf("< DAMPER, saturation: %u %u, coefficient: %d %d\n", event->jcondition.saturation.left, event->jcondition.saturation.right, event->jcondition.coefficient.left, event->jcondition.coefficient.right); fflush(stdout); } } while (0);
        break;
    default:
        do { if(gimx_params.debug.haptic) { printf("< UNKNOWN\n"); fflush(stdout); } } while (0);
        break;
    }
}

variable_types: union GE_Event { struct { unsigned char type; unsigned char which; }; struct GE_KeyboardEvent { unsigned char type; unsigned char which; unsigned short keysym; } key; struct GE_MouseMotionEvent { unsigned char type; unsigned char which; short xrel; short yrel; } motion; struct GE_MouseButtonEvent { unsigned char type; unsigned char which; unsigned char button; } button; struct GE_JoyAxisEvent { unsigned char type; unsigned char which; unsigned char axis; short value; } jaxis; struct GE_JoyHatEvent { unsigned char type; unsigned char which; unsigned char hat; unsigned char value; } jhat; struct GE_JoyButtonEvent { unsigned char type; unsigned char which; unsigned char button; unsigned char state; } jbutton; struct GE_JoyRumbleEvent { unsigned char type; unsigned char which; unsigned short weak; unsigned short strong; } jrumble; struct GE_JoyConstantForceEvent { unsigned char type; unsigned char which; short level; } jconstant; struct GE_JoyConditionForceEvent { unsigned char type; unsigned char which; struct { unsigned short left; unsigned short right; } saturation; struct { short left; short right; } coefficient; short center; unsigned short deadband; } jcondition; struct GE_JoyPeriodicForceEvent { unsigned char type; unsigned char which; struct { int direction; unsigned short period; short magnitude; short offset; } sine; } jperiodic; } *

user_defined_types: union GE_Event { struct { unsigned char type; unsigned char which; }; struct GE_KeyboardEvent key; struct GE_MouseMotionEvent motion; struct GE_MouseButtonEvent button; struct GE_JoyAxisEvent jaxis; struct GE_JoyHatEvent jhat; struct GE_JoyButtonEvent jbutton; struct GE_JoyRumbleEvent jrumble; struct GE_JoyConstantForceEvent jconstant; struct GE_JoyConditionForceEvent jcondition; struct GE_JoyPeriodicForceEvent jperiodic; }


decompiled_code:
__int64 bt_device_btstack_device_init()
{
return btstack_common_init();
}

canonical_decompiled_code:
__int64 func0()
{
return btstack_common_init();
}

original_code:
int bt_device_btstack_device_init()
{
  return btstack_common_init();
}

return_type: int


decompiled_code:
__int64 __fastcall bt_device_btstack_get_device_bdaddr(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int16 v3; // bx
__int64 i; // rdx

result = btstack_common_send_cmd(&btstack_hci_read_bd_addr);
if ( (int)result >= 0 )
{
v3 = btstack_hci_read_bd_addr;
do
{
while ( 1 )
{
result = btstack_common_recv_packet(&recv_data);
if ( (int)result > 0 )
break;
if ( (_DWORD)result )
return result;
}
}
while ( recv_data != 4 || byte_126 != 14 || v3 != word_129 );
for ( i = 0LL; i != 6; ++i )
*(_BYTE *)(a2 + i) = byte_12C[i];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int16 v3; // bx
__int64 i; // rdx

result = btstack_common_send_cmd(&btstack_hci_read_bd_addr);
if ( (int)result >= 0 )
{
v3 = btstack_hci_read_bd_addr;
do
{
while ( 1 )
{
result = btstack_common_recv_packet(&recv_data);
if ( (int)result > 0 )
break;
if ( (_DWORD)result )
return result;
}
}
while ( recv_data != 4 || byte_126 != 14 || v3 != word_129 );
for ( i = 0LL; i != 6; ++i )
*(_BYTE *)(a2 + i) = byte_12C[i];
}
return result;
}

original_code:
int bt_device_btstack_get_device_bdaddr(int ignored __attribute__((unused)), bdaddr_t* bdaddr)
{
  int ret;
  ret = btstack_common_send_cmd(&btstack_hci_read_bd_addr);
  while(ret >= 0)
  {
    ret = btstack_common_recv_packet(&recv_data);
    if(ret > 0)
    {
      int type = ( ((uint16_t) recv_data.buffer[0]) | (((uint16_t)recv_data.buffer[0 +1]) << 8));
      unsigned char* packet = recv_data.buffer+sizeof(packet_header_t);
      if(type == 0x04)
      {
        if (( packet[0] == 0x0E && ( ((uint16_t) packet[3]) | (((uint16_t)packet[3 +1]) << 8)) == btstack_hci_read_bd_addr.opcode))
        {
          unsigned int i;
          for(i=0; i<sizeof(bdaddr->b); ++i)
          {
            bdaddr->b[i] = packet[5 + 1 + i];
          }
          break;
        }
      }
    }
  }
  return ret;
}

canonical_original_code:
int bt_device_btstack_get_device_bdaddr(int ignored, struct bdaddr_t *bdaddr)
{
  int ret;
  ret = btstack_common_send_cmd(&btstack_hci_read_bd_addr);
  while(ret >= 0)
  {
    ret = btstack_common_recv_packet(&recv_data);
    if(ret > 0)
    {
      int type = ( ((uint16_t) recv_data.buffer[0]) | (((uint16_t)recv_data.buffer[0 +1]) << 8));
      unsigned char *packet = recv_data.buffer+sizeof(packet_header_t);
      if(type == 0x04)
      {
        if (( packet[0] == 0x0E && ( ((unsigned short) packet[3]) | (((unsigned short)packet[3 +1]) << 8)) == btstack_hci_read_bd_addr.opcode))
        {
          unsigned int i;
          for(i=0; i<sizeof(bdaddr->b); ++i)
          {
            bdaddr->b[i] = packet[5 + 1 + i];
          }
          break;
        }
      }
    }
  }
  return ret;
}

variable_types: ignored int

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

variable_types: ret int

variable_types: type int

variable_types:
packet
unsigned char *

variable_types:
i
unsigned int


decompiled_code:
__int64 bt_device_btstack_write_device_class()
{
__int64 result; // rax
__int16 v1; // bx

result = btstack_common_send_cmd(&btstack_hci_write_class_of_device);
if ( (int)result >= 0 )
{
v1 = btstack_hci_write_class_of_device;
do
{
while ( 1 )
{
result = btstack_common_recv_packet(&recv_data);
if ( (int)result > 0 )
break;
if ( (_DWORD)result )
return result;
}
}
while ( recv_data != 4 || byte_126 != 14 || v1 != word_129 );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
__int16 v1; // bx

result = btstack_common_send_cmd(&btstack_hci_write_class_of_device);
if ( (int)result >= 0 )
{
v1 = btstack_hci_write_class_of_device;
do
{
while ( 1 )
{
result = btstack_common_recv_packet(&recv_data);
if ( (int)result > 0 )
break;
if ( (_DWORD)result )
return result;
}
}
while ( recv_data != 4 || byte_126 != 14 || v1 != word_129 );
}
return result;
}

original_code:
int bt_device_btstack_write_device_class(int ignored __attribute__((unused)), uint32_t devclass)
{
  int ret = btstack_common_send_cmd(&btstack_hci_write_class_of_device, devclass);
  while(ret >= 0)
  {
    ret = btstack_common_recv_packet(&recv_data);
    if(ret > 0)
    {
      int type = ( ((uint16_t) recv_data.buffer[0]) | (((uint16_t)recv_data.buffer[0 +1]) << 8));
      unsigned char* packet = recv_data.buffer+sizeof(packet_header_t);
      if(type == 0x04)
      {
        if ( ( packet[0] == 0x0E && ( ((uint16_t) packet[3]) | (((uint16_t)packet[3 +1]) << 8)) == btstack_hci_write_class_of_device.opcode) ) {
          break;
        }
      }
    }
  }
  return ret;
}

canonical_original_code:
int bt_device_btstack_write_device_class(int ignored, unsigned int devclass)
{
  int ret = btstack_common_send_cmd(&btstack_hci_write_class_of_device, devclass);
  while(ret >= 0)
  {
    ret = btstack_common_recv_packet(&recv_data);
    if(ret > 0)
    {
      int type = ( ((uint16_t) recv_data.buffer[0]) | (((uint16_t)recv_data.buffer[0 +1]) << 8));
      unsigned char *packet = recv_data.buffer+sizeof(packet_header_t);
      if(type == 0x04)
      {
        if ( ( packet[0] == 0x0E && ( ((unsigned short) packet[3]) | (((unsigned short)packet[3 +1]) << 8)) == btstack_hci_write_class_of_device.opcode) ) {
          break;
        }
      }
    }
  }
  return ret;
}

variable_types:
devclass
unsigned int


decompiled_code:
__int64 bt_device_btstack_init()
{
return bt_device_abs_register(0LL, &bt_device_btstack);
}

canonical_decompiled_code:
__int64 func3()
{
return bt_device_abs_register(0LL, &bt_device_btstack);
}

original_code:
void bt_device_btstack_init(void)
{
  bt_device_abs_register(E_BT_ABS_BTSTACK, &bt_device_btstack);
}

canonical_original_code:
void bt_device_btstack_init()
{
  bt_device_abs_register(E_BT_ABS_BTSTACK, &bt_device_btstack);
}


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

result = &channels[14 * a1];
*((_QWORD *)result + 1) = a2;
*((_QWORD *)result + 6) = a4;
return result;
}

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

result = &channels[14 * a1];
*((_QWORD *)result + 1) = a2;
*((_QWORD *)result + 6) = a4;
return result;
}

original_code:
static void l2cap_btstack_add_source(int channel, void * user,
    L2CAP_ABS_READ_CALLBACK read_callback __attribute__((unused)), L2CAP_ABS_PACKET_CALLBACK packet_callback, L2CAP_ABS_CLOSE_CALLBACK close_callback __attribute__((unused)))
{
  channels.entries[channel].user = user;
  channels.entries[channel].packet_callback = packet_callback;
}

canonical_original_code:
static void l2cap_btstack_add_source(int channel, void *user, int (*read_callback)(void *user), int (*packet_callback)(void *user, int psm, unsigned char *buf, int len), int (*close_callback)(void *user))
{
  channels.entries[channel].user = user;
  channels.entries[channel].packet_callback = packet_callback;
}

variable_types: channel int

variable_types:
user
void *

variable_types: int (*)(void *user, int psm, unsigned char *buf, int len)


decompiled_code:
__int64 l2cap_btstack_close()
{
fwrite("btstack_close is not implemented yet\n", 1uLL, 0x25uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
fwrite("btstack_close is not implemented yet\n", 1uLL, 0x25uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int l2cap_btstack_close(int channel __attribute__((unused)))
{
  fprintf(stderr, "btstack_close is not implemented yet\n");
  return -1;
}

canonical_original_code:
static int l2cap_btstack_close(int channel)
{
  fprintf(stderr, "btstack_close is not implemented yet\n");
  return -1;
}


decompiled_code:
__int64 l2cap_btstack_recv()
{
fwrite("btstack uses packet callbacks!\n", 1uLL, 0x1FuLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2()
{
fwrite("btstack uses packet callbacks!\n", 1uLL, 0x1FuLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
static int l2cap_btstack_recv (int channel __attribute__((unused)), unsigned char* buf __attribute__((unused)), int len __attribute__((unused)))
{
  fprintf(stderr, "btstack uses packet callbacks!\n");
  return -1;
}

canonical_original_code:
static int l2cap_btstack_recv(int channel, unsigned char *buf, int len)
{
  fprintf(stderr, "btstack uses packet callbacks!\n");
  return -1;
}

variable_types:
buf
unsigned char *

variable_types: len int


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

canonical_decompiled_code:
__int64 func3()
{
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

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

canonical_decompiled_code:
int __fastcall func4(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));
}


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

v5 = channels[0];
v14[0] = a1;
if ( !channels[0] )
return 0xFFFFFFFFLL;
v8 = &unk_950;
v9 = 0;
while ( bacmp(v8, v14) || v8[3] != a2 )
{
++v9;
v8 += 28;
if ( v9 == v5 )
return 0xFFFFFFFFLL;
}
v11 = &channels[14 * v9];
v12 = *((_QWORD *)v11 + 1);
if ( a5 )
{
(*((void (__fastcall **)(__int64))v11 + 7))(v12);
result = 0xFFFFFFFFLL;
}
else
{
result = (*((__int64 (__fastcall **)(__int64))v11 + 4))(v12);
if ( !(_DWORD)result )
{
*((_WORD *)v11 + 12) = a3;
*((_WORD *)v11 + 14) = 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


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 func6(__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: struct bdaddr_t { unsigned char b[6]; } *

variable_types:
src
struct bdaddr_t *


decompiled_code:
__int64 __fastcall l2cap_btstack_connect(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v10; // eax
unsigned int v11; // er8
__int64 v12; // rdx
char v14[6]; // [rsp+4h] [rbp-44h] BYREF
char v15[6]; // [rsp+Ah] [rbp-3Eh] BYREF
__int64 v16[7]; // [rsp+10h] [rbp-38h] BYREF

str2ba(a2, v14);
baswap(v15, v14);
if ( (int)btstack_common_send_cmd(&btstack_l2cap_create_channel_mtu, v15, a3, 1024LL) < 0 )
return (unsigned int)-1;
v16[0] = (__int64)packet_handler;
v16[1] = 0LL;
v16[2] = (__int64)packet_handler;
v10 = btstack_common_getfd();
gpoll_register_fd(v10, 0LL, v16);
bacpy((__int64)&unk_950 + 56 * channels[0], (__int64)v14);
*(__int16 *)((char *)&word_956 + v12) = a3;
*(__int64 *)((char *)&qword_948 + v12) = a5;
*(__int64 *)((char *)&qword_960 + v12) = a6;
++channels[0];
*(_QWORD *)((char *)&channels[14] + v12) = a7;
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned __int16 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
unsigned int v10; // eax
unsigned int v11; // er8
__int64 v12; // rdx
char v14[6]; // [rsp+4h] [rbp-44h] BYREF
char v15[6]; // [rsp+Ah] [rbp-3Eh] BYREF
__int64 v16[7]; // [rsp+10h] [rbp-38h] BYREF

str2ba(a2, v14);
baswap(v15, v14);
if ( (int)btstack_common_send_cmd(&btstack_l2cap_create_channel_mtu, v15, a3, 1024LL) < 0 )
return (unsigned int)-1;
v16[0] = (__int64)packet_handler;
v16[1] = 0LL;
v16[2] = (__int64)packet_handler;
v10 = btstack_common_getfd();
gpoll_register_fd(v10, 0LL, v16);
func6((__int64)&unk_950 + 56 * channels[0], (__int64)v14);
*(__int16 *)((char *)&word_956 + v12) = a3;
*(__int64 *)((char *)&qword_948 + v12) = a5;
*(__int64 *)((char *)&qword_960 + v12) = a6;
++channels[0];
*(_QWORD *)((char *)&channels[14] + v12) = a7;
return v11;
}

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


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

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

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

variable_types: channel int


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

v4 = (unsigned __int16)word_958[28 * a1];
if ( (_WORD)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 func9(int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rsi

v4 = (unsigned __int16)word_958[28 * a1];
if ( (_WORD)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: ignored int


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

v0 = btstack_common_recv(&recv_data_0);
if ( v0 != 1 )
{
v1 = v0;
if ( v0 < 0 )
v1 = 1;
return v1;
}
if ( recv_data_0 != 4 )
{
v1 = 0;
if ( recv_data_0 == 6 )
{
v1 = l2cap_btstack_process_packet_constprop_0(word_522, (unsigned __int16)word_524);
if ( v1 == -1 )
fwrite("error processing data\n", 1uLL, 0x16uLL, stderr);
}
return v1;
}
if ( byte_526 == 112 )
{
v6 = dword_529;
v7 = word_52D;
ba2str(&v6, v8);
v3 = (unsigned __int16)word_52F;
v4 = (unsigned __int16)word_533;
v5 = (unsigned __int16)word_531;
if ( (unsigned int)l2cap_btstack_connect_channel(
v6 | ((unsigned __int64)v7 << 32),
word_531,
word_533,
word_52F,
byte_528) )
printf("L2CAP connection to device %s failed. status code %u\n", v8, (unsigned __int8)byte_528);
else
printf(
"Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
v8,
v3,
v5,
v4,
(unsigned __int16)word_535);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax
unsigned int v1; // er12
unsigned int v3; // er12
unsigned int v4; // ebx
unsigned int v5; // er13
unsigned int v6; // [rsp+Ah] [rbp-3Eh] BYREF
unsigned __int16 v7; // [rsp+Eh] [rbp-3Ah]
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

v0 = btstack_common_recv(&recv_data_0);
if ( v0 != 1 )
{
v1 = v0;
if ( v0 < 0 )
v1 = 1;
return v1;
}
if ( recv_data_0 != 4 )
{
v1 = 0;
if ( recv_data_0 == 6 )
{
v1 = func10(word_522, (unsigned __int16)word_524);
if ( v1 == -1 )
fwrite("error processing data\n", 1uLL, 0x16uLL, stderr);
}
return v1;
}
if ( byte_526 == 112 )
{
v6 = dword_529;
v7 = word_52D;
ba2str(&v6, v8);
v3 = (unsigned __int16)word_52F;
v4 = (unsigned __int16)word_533;
v5 = (unsigned __int16)word_531;
if ( (unsigned int)func5(
v6 | ((unsigned __int64)v7 << 32),
word_531,
word_533,
word_52F,
byte_528) )
printf("L2CAP connection to device %s failed. status code %u\n", v8, (unsigned __int8)byte_528);
else
printf(
"Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
v8,
v3,
v5,
v4,
(unsigned __int16)word_535);
}
return 0LL;
}

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:
bdaddr
char [18]


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)
{
int v3; // er12
__int64 i; // rbx
unsigned int v5; // ebp
const char *v6; // rax
int v7; // ebx
__int64 v8; // rax
int v9; // eax
double v10; // xmm0_8
__int64 v11; // rax
int v12; // esi
__int64 v13; // rax
double v14; // xmm1_8
double v15; // xmm0_8
__int64 v16; // rax
int v17; // esi
double v19; // [rsp+8h] [rbp-50h]
double v20; // [rsp+8h] [rbp-50h]
char s[16]; // [rsp+10h] [rbp-48h] BYREF
char v22[8]; // [rsp+20h] [rbp-38h] BYREF

v3 = 0;
for ( i = 4LL; i != 40; ++i )
{
v5 = a2[i];
if ( v5 )
{
++v3;
v6 = (const char *)controller_get_axis_name(a1, (unsigned int)i);
snprintf(s, 0x17uLL, "%15s: %5d", v6, v5);
if ( wmove(wbuttons, v3, 1) != -1 )
waddnstr(wbuttons, s, -1);
if ( v3 == 8 )
break;
}
}
strcpy(v22, " ");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC6);
if ( v3 < last_button_nb )
{
v7 = v3;
do
{
if ( wmove(wbuttons, ++v7, 1) != -1 )
waddnstr(wbuttons, s, -1);
}
while ( v7 < last_button_nb );
}
last_button_nb = v3;
wnoutrefresh(wbuttons);
if ( wmove(lstick, dword_1554, cross) != -1 )
waddch(lstick, 0x20uLL);
v19 = (double)*a2;
v8 = adapter_get(0LL);
v9 = controller_get_max_signed(*(unsigned int *)(v8 + 736), 0LL);
v10 = (double)a2[1];
cross = (int)(v19 / (double)v9 * 9.0 + 10.0);
v11 = adapter_get(0LL);
v12 = (int)(v10 / (double)(int)controller_get_max_signed(*(unsigned int *)(v11 + 736), 1LL) * 4.0 + 5.0);
dword_1554 = v12;
if ( (unsigned int)(cross - 1) <= 0x12 && (unsigned int)(v12 - 1) <= 8 )
{
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_155C, dword_1558) != -1 )
waddch(rstick, 0x20uLL);
v20 = (double)a2[2];
v13 = adapter_get(0LL);
v14 = (double)(int)controller_get_max_signed(*(unsigned int *)(v13 + 736), 2LL);
v15 = (double)a2[3];
dword_1558 = (int)(v20 / v14 * 9.0 + 10.0);
v16 = adapter_get(0LL);
v17 = (int)(v15 / (double)(int)controller_get_max_signed(*(unsigned int *)(v16 + 736), 3LL) * 4.0 + 5.0);
dword_155C = v17;
if ( (unsigned int)(v17 - 1) <= 8 && (unsigned int)(dword_1558 - 1) <= 0x12 )
{
if ( wmove(rstick, v17, dword_1558) != -1 )
waddch(rstick, 0x2AuLL);
}
else if ( wmove(rstick, v17, dword_1558) != -1 )
{
waddch(rstick, 0x32AuLL);
}
return wnoutrefresh(rstick);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, int *a2)
{
int v3; // er12
__int64 i; // rbx
unsigned int v5; // ebp
const char *v6; // rax
int v7; // ebx
__int64 v8; // rax
int v9; // eax
double v10; // xmm0_8
__int64 v11; // rax
int v12; // esi
__int64 v13; // rax
double v14; // xmm1_8
double v15; // xmm0_8
__int64 v16; // rax
int v17; // esi
double v19; // [rsp+8h] [rbp-50h]
double v20; // [rsp+8h] [rbp-50h]
char s[16]; // [rsp+10h] [rbp-48h] BYREF
char v22[8]; // [rsp+20h] [rbp-38h] BYREF

v3 = 0;
for ( i = 4LL; i != 40; ++i )
{
v5 = a2[i];
if ( v5 )
{
++v3;
v6 = (const char *)controller_get_axis_name(a1, (unsigned int)i);
snprintf(s, 0x17uLL, "%15s: %5d", v6, v5);
if ( wmove(wbuttons, v3, 1) != -1 )
waddnstr(wbuttons, s, -1);
if ( v3 == 8 )
break;
}
}
strcpy(v22, " ");
*(__m128i *)s = _mm_load_si128((const __m128i *)&LC6);
if ( v3 < last_button_nb )
{
v7 = v3;
do
{
if ( wmove(wbuttons, ++v7, 1) != -1 )
waddnstr(wbuttons, s, -1);
}
while ( v7 < last_button_nb );
}
last_button_nb = v3;
wnoutrefresh(wbuttons);
if ( wmove(lstick, dword_1554, cross) != -1 )
waddch(lstick, 0x20uLL);
v19 = (double)*a2;
v8 = adapter_get(0LL);
v9 = controller_get_max_signed(*(unsigned int *)(v8 + 736), 0LL);
v10 = (double)a2[1];
cross = (int)(v19 / (double)v9 * 9.0 + 10.0);
v11 = adapter_get(0LL);
v12 = (int)(v10 / (double)(int)controller_get_max_signed(*(unsigned int *)(v11 + 736), 1LL) * 4.0 + 5.0);
dword_1554 = v12;
if ( (unsigned int)(cross - 1) <= 0x12 && (unsigned int)(v12 - 1) <= 8 )
{
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_155C, dword_1558) != -1 )
waddch(rstick, 0x20uLL);
v20 = (double)a2[2];
v13 = adapter_get(0LL);
v14 = (double)(int)controller_get_max_signed(*(unsigned int *)(v13 + 736), 2LL);
v15 = (double)a2[3];
dword_1558 = (int)(v20 / v14 * 9.0 + 10.0);
v16 = adapter_get(0LL);
v17 = (int)(v15 / (double)(int)controller_get_max_signed(*(unsigned int *)(v16 + 736), 3LL) * 4.0 + 5.0);
dword_155C = v17;
if ( (unsigned int)(v17 - 1) <= 8 && (unsigned int)(dword_1558 - 1) <= 0x12 )
{
if ( wmove(rstick, v17, dword_1558) != -1 )
waddch(rstick, 0x2AuLL);
}
else if ( wmove(rstick, v17, dword_1558) != -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; // rbx
char *v2; // rax
char *v3; // rax
unsigned int *v4; // rax
int v5; // eax
unsigned int *v6; // rax
char *v7; // rax
_DWORD *v8; // rax
const char *v9; // rsi
WINDOW *v10; // r13
char *v11; // rax
char *v12; // rax
char *v13; // rax
double *v14; // rax
int v15; // eax
double *v16; // rax
char *v17; // rax
char *v18; // rax
unsigned int v19; // er13
char *v20; // rax
unsigned int v21; // er13
char *v22; // rax
int v23; // eax
char *v24; // rax
double *v25; // rdx
char *v26; // rax
const char *v28; // rsi
char *v29; // rax
const char *v30; // rsi
unsigned int v31; // eax
char *v32; // rax
char *v33; // rax
char *v34; // rax
char *v35; // rax
char *v36; // rax
char *v37; // rax
char v38[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 )
goto LABEL_3;
v28 = "Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)";
}
else
{
if ( wmove(stdscr, 13, 3) == -1 )
goto LABEL_3;
v28 = "Mouse calibration (Ctrl+F1 to edit)";
}
v29 = dcgettext(0LL, v28, 5);
waddnstr(stdscr, v29, -1);
LABEL_3:
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);
v30 = (const char *)ginput_mouse_name(current_mouse);
waddnstr(wcal, v30, -1);
v31 = ginput_mouse_virtual_id(current_mouse);
snprintf(v38, COLS, " (%d) (F1) ", v31);
waddnstr(wcal, v38, -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(v38, COLS, " %d (F2)", (unsigned int)(current_conf + 1));
waddnstr(wcal, v38, -1);
if ( current_cal == 2 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 2, 1) != -1 )
{
v3 = dcgettext(0LL, "Dead zone:", 5);
waddnstr(wcal, v3, -1);
}
if ( current_cal == 5 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " x=", -1);
v4 = *(unsigned int **)(v1 + 40);
if ( v4 )
{
snprintf(v38, COLS, "%d", *v4);
waddnstr(wcal, v38, -1);
}
else
{
v35 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v35, -1);
}
waddnstr(wcal, " (F3)", -1);
v5 = current_cal;
if ( current_cal == 5 )
{
wattr_on(wcal, 0x100uLL, 0LL);
v5 = current_cal;
}
if ( v5 == 6 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v6 = *(unsigned int **)(v1 + 48);
if ( v6 )
{
snprintf(v38, COLS, "%d", *v6);
waddnstr(wcal, v38, -1);
}
else
{
v36 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v36, -1);
}
waddnstr(wcal, " (F4)", -1);
if ( current_cal == 6 )
{
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal != 7 )
goto LABEL_22;
}
else if ( current_cal != 7 )
{
goto LABEL_22;
}
wattr_on(wcal, 0x400uLL, 0LL);
LABEL_22:
v7 = dcgettext(0LL, " shape=", 5);
waddnstr(wcal, v7, -1);
v8 = *(_DWORD **)(v1 + 56);
if ( v8 )
{
v9 = "circle";
v10 = wcal;
if ( *v8 )
v9 = "rectangle";
v11 = dcgettext(0LL, v9, 5);
waddnstr(v10, v11, -1);
}
else
{
v37 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v37, -1);
}
waddnstr(wcal, " (F5)", -1);
if ( current_cal == 7 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 3, 1) != -1 )
{
v12 = dcgettext(0LL, "Acceleration:", 5);
waddnstr(wcal, v12, -1);
}
if ( current_cal == 12 )
wattr_on(wcal, 0x400uLL, 0LL);
v13 = dcgettext(0LL, " test (F6)", 5);
waddnstr(wcal, v13, -1);
if ( current_cal == 12 )
{
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal != 10 )
goto LABEL_34;
}
else if ( current_cal != 10 )
{
goto LABEL_34;
}
wattr_on(wcal, 0x400uLL, 0LL);
LABEL_34:
waddnstr(wcal, " x=", -1);
v14 = *(double **)(v1 + 16);
if ( v14 )
{
snprintf(v38, COLS, "%.2f", *v14);
waddnstr(wcal, v38, -1);
}
else
{
v34 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v34, -1);
}
waddnstr(wcal, " (F7)", -1);
v15 = current_cal;
if ( current_cal == 10 )
{
wattr_on(wcal, 0x100uLL, 0LL);
v15 = current_cal;
}
if ( v15 == 11 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v16 = *(double **)(v1 + 24);
if ( v16 )
{
snprintf(v38, COLS, "%.2f", *v16);
waddnstr(wcal, v38, -1);
}
else
{
v33 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v33, -1);
}
waddnstr(wcal, " (F8)", -1);
if ( current_cal == 11 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 4, 1) != -1 )
{
v17 = dcgettext(0LL, "Sensitivity:", 5);
waddnstr(wcal, v17, -1);
}
if ( current_cal == 3 )
wattr_on(wcal, 0x400uLL, 0LL);
if ( *(_QWORD *)v1 )
{
snprintf(v38, COLS, " %.2f", **(double **)v1);
waddnstr(wcal, v38, -1);
}
else
{
v32 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v32, -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);
v18 = dcgettext(0LL, " circle test", 5);
waddnstr(wcal, v18, -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);
v19 = *(_DWORD *)(v1 + 32);
v20 = dcgettext(0LL, "radius=%d (F10)", 5);
snprintf(v38, COLS, v20, v19);
waddnstr(wcal, v38, -1);
if ( current_cal == 8 )
wattr_on(wcal, 0x100uLL, 0LL);
waddnstr(wcal, ", ", -1);
if ( current_cal == 9 )
wattr_on(wcal, 0x400uLL, 0LL);
v21 = *(_DWORD *)(v1 + 36);
v22 = dcgettext(0LL, "velocity=%d (F11)", 5);
snprintf(v38, COLS, v22, v21);
waddnstr(wcal, v38, -1);
v23 = current_cal;
if ( current_cal == 9 )
{
wattr_on(wcal, 0x100uLL, 0LL);
v23 = current_cal;
}
if ( v23 == 4 )
wattr_on(wcal, 0x400uLL, 0LL);
v24 = dcgettext(0LL, " ratio=", 5);
waddnstr(wcal, v24, -1);
if ( *(_QWORD *)v1 && (v25 = *(double **)(v1 + 8)) != 0LL )
{
snprintf(v38, COLS, "%.2f", *v25 / **(double **)v1);
waddnstr(wcal, v38, -1);
}
else
{
v26 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v26, -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; // rbx
char *v2; // rax
char *v3; // rax
unsigned int *v4; // rax
int v5; // eax
unsigned int *v6; // rax
char *v7; // rax
_DWORD *v8; // rax
const char *v9; // rsi
WINDOW *v10; // r13
char *v11; // rax
char *v12; // rax
char *v13; // rax
double *v14; // rax
int v15; // eax
double *v16; // rax
char *v17; // rax
char *v18; // rax
unsigned int v19; // er13
char *v20; // rax
unsigned int v21; // er13
char *v22; // rax
int v23; // eax
char *v24; // rax
double *v25; // rdx
char *v26; // rax
const char *v28; // rsi
char *v29; // rax
const char *v30; // rsi
unsigned int v31; // eax
char *v32; // rax
char *v33; // rax
char *v34; // rax
char *v35; // rax
char *v36; // rax
char *v37; // rax
char v38[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 )
goto LABEL_3;
v28 = "Mouse calibration (Ctrl+F1 to save)(mouse wheel to change values)";
}
else
{
if ( wmove(stdscr, 13, 3) == -1 )
goto LABEL_3;
v28 = "Mouse calibration (Ctrl+F1 to edit)";
}
v29 = dcgettext(0LL, v28, 5);
waddnstr(stdscr, v29, -1);
LABEL_3:
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);
v30 = (const char *)ginput_mouse_name(current_mouse);
waddnstr(wcal, v30, -1);
v31 = ginput_mouse_virtual_id(current_mouse);
snprintf(v38, COLS, " (%d) (F1) ", v31);
waddnstr(wcal, v38, -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(v38, COLS, " %d (F2)", (unsigned int)(current_conf + 1));
waddnstr(wcal, v38, -1);
if ( current_cal == 2 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 2, 1) != -1 )
{
v3 = dcgettext(0LL, "Dead zone:", 5);
waddnstr(wcal, v3, -1);
}
if ( current_cal == 5 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " x=", -1);
v4 = *(unsigned int **)(v1 + 40);
if ( v4 )
{
snprintf(v38, COLS, "%d", *v4);
waddnstr(wcal, v38, -1);
}
else
{
v35 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v35, -1);
}
waddnstr(wcal, " (F3)", -1);
v5 = current_cal;
if ( current_cal == 5 )
{
wattr_on(wcal, 0x100uLL, 0LL);
v5 = current_cal;
}
if ( v5 == 6 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v6 = *(unsigned int **)(v1 + 48);
if ( v6 )
{
snprintf(v38, COLS, "%d", *v6);
waddnstr(wcal, v38, -1);
}
else
{
v36 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v36, -1);
}
waddnstr(wcal, " (F4)", -1);
if ( current_cal == 6 )
{
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal != 7 )
goto LABEL_22;
}
else if ( current_cal != 7 )
{
goto LABEL_22;
}
wattr_on(wcal, 0x400uLL, 0LL);
LABEL_22:
v7 = dcgettext(0LL, " shape=", 5);
waddnstr(wcal, v7, -1);
v8 = *(_DWORD **)(v1 + 56);
if ( v8 )
{
v9 = "circle";
v10 = wcal;
if ( *v8 )
v9 = "rectangle";
v11 = dcgettext(0LL, v9, 5);
waddnstr(v10, v11, -1);
}
else
{
v37 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v37, -1);
}
waddnstr(wcal, " (F5)", -1);
if ( current_cal == 7 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 3, 1) != -1 )
{
v12 = dcgettext(0LL, "Acceleration:", 5);
waddnstr(wcal, v12, -1);
}
if ( current_cal == 12 )
wattr_on(wcal, 0x400uLL, 0LL);
v13 = dcgettext(0LL, " test (F6)", 5);
waddnstr(wcal, v13, -1);
if ( current_cal == 12 )
{
wattr_on(wcal, 0x100uLL, 0LL);
if ( current_cal != 10 )
goto LABEL_34;
}
else if ( current_cal != 10 )
{
goto LABEL_34;
}
wattr_on(wcal, 0x400uLL, 0LL);
LABEL_34:
waddnstr(wcal, " x=", -1);
v14 = *(double **)(v1 + 16);
if ( v14 )
{
snprintf(v38, COLS, "%.2f", *v14);
waddnstr(wcal, v38, -1);
}
else
{
v34 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v34, -1);
}
waddnstr(wcal, " (F7)", -1);
v15 = current_cal;
if ( current_cal == 10 )
{
wattr_on(wcal, 0x100uLL, 0LL);
v15 = current_cal;
}
if ( v15 == 11 )
wattr_on(wcal, 0x400uLL, 0LL);
waddnstr(wcal, " y=", -1);
v16 = *(double **)(v1 + 24);
if ( v16 )
{
snprintf(v38, COLS, "%.2f", *v16);
waddnstr(wcal, v38, -1);
}
else
{
v33 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v33, -1);
}
waddnstr(wcal, " (F8)", -1);
if ( current_cal == 11 )
wattr_on(wcal, 0x100uLL, 0LL);
wclrtoeol(wcal);
if ( wmove(wcal, 4, 1) != -1 )
{
v17 = dcgettext(0LL, "Sensitivity:", 5);
waddnstr(wcal, v17, -1);
}
if ( current_cal == 3 )
wattr_on(wcal, 0x400uLL, 0LL);
if ( *(_QWORD *)v1 )
{
snprintf(v38, COLS, " %.2f", **(double **)v1);
waddnstr(wcal, v38, -1);
}
else
{
v32 = dcgettext(0LL, " N/A", 5);
waddnstr(wcal, v32, -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);
v18 = dcgettext(0LL, " circle test", 5);
waddnstr(wcal, v18, -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);
v19 = *(_DWORD *)(v1 + 32);
v20 = dcgettext(0LL, "radius=%d (F10)", 5);
snprintf(v38, COLS, v20, v19);
waddnstr(wcal, v38, -1);
if ( current_cal == 8 )
wattr_on(wcal, 0x100uLL, 0LL);
waddnstr(wcal, ", ", -1);
if ( current_cal == 9 )
wattr_on(wcal, 0x400uLL, 0LL);
v21 = *(_DWORD *)(v1 + 36);
v22 = dcgettext(0LL, "velocity=%d (F11)", 5);
snprintf(v38, COLS, v22, v21);
waddnstr(wcal, v38, -1);
v23 = current_cal;
if ( current_cal == 9 )
{
wattr_on(wcal, 0x100uLL, 0LL);
v23 = current_cal;
}
if ( v23 == 4 )
wattr_on(wcal, 0x400uLL, 0LL);
v24 = dcgettext(0LL, " ratio=", 5);
waddnstr(wcal, v24, -1);
if ( *(_QWORD *)v1 && (v25 = *(double **)(v1 + 8)) != 0LL )
{
snprintf(v38, COLS, "%.2f", *v25 / **(double **)v1);
waddnstr(wcal, v38, -1);
}
else
{
v26 = dcgettext(0LL, "N/A", 5);
waddnstr(wcal, v26, -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()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
int v5; // ebx
char *v6; // rax
int v7; // eax
char *v8; // 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 )
{
v0 = dcgettext(0LL, "Left stick", 5);
waddnstr(stdscr, v0, -1);
}
if ( wmove(stdscr, 1, 25) != -1 )
{
v1 = dcgettext(0LL, "Right stick", 5);
waddnstr(stdscr, v1, -1);
}
if ( wmove(stdscr, 1, 47) != -1 )
{
v2 = dcgettext(0LL, "Buttons", 5);
waddnstr(stdscr, v2, -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 )
{
v3 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to edit)", 5);
waddnstr(stdscr, v3, -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 )
{
v4 = dcgettext(0LL, "Refresh rate:", 5);
waddnstr(stdscr, v4, -1);
}
v5 = COLS;
v6 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
v7 = strlen(v6);
if ( wmove(stdscr, LINES - 1, v5 - v7) != -1 )
{
v8 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
waddnstr(stdscr, v8, -1);
}
wnoutrefresh(stdscr);
return doupdate();
}

canonical_decompiled_code:
int func3()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
int v5; // ebx
char *v6; // rax
int v7; // eax
char *v8; // 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 )
{
v0 = dcgettext(0LL, "Left stick", 5);
waddnstr(stdscr, v0, -1);
}
if ( wmove(stdscr, 1, 25) != -1 )
{
v1 = dcgettext(0LL, "Right stick", 5);
waddnstr(stdscr, v1, -1);
}
if ( wmove(stdscr, 1, 47) != -1 )
{
v2 = dcgettext(0LL, "Buttons", 5);
waddnstr(stdscr, v2, -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 )
{
v3 = dcgettext(0LL, "Mouse calibration (Ctrl+F1 to edit)", 5);
waddnstr(stdscr, v3, -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 )
{
v4 = dcgettext(0LL, "Refresh rate:", 5);
waddnstr(stdscr, v4, -1);
}
v5 = COLS;
v6 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
v7 = strlen(v6);
if ( wmove(stdscr, LINES - 1, v5 - v7) != -1 )
{
v8 = dcgettext(0LL, "Press Shift+Esc to exit.", 5);
waddnstr(stdscr, v8, -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
__int16 v3; // ax

result = *(unsigned int *)(a1 + 4);
if ( (_DWORD)result )
{
v3 = *(_WORD *)(a1 + 8);
*(_DWORD *)a2 = 1;
*(_WORD *)(a2 + 6) = v3;
*(_WORD *)(a2 + 8) = *(_WORD *)(a1 + 10);
result = 1LL;
*(_DWORD *)(a1 + 4) = 0;
}
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; }; } *

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)
{
__int64 v3; // rax
char v5; // dl
unsigned __int8 *v6; // r8
int v7; // esi
int v8; // edx

v3 = *a1;
v5 = byte_364[10 * v3];
if ( !v5 || *a3 == v5 )
{
v6 = (unsigned __int8 *)&props + 10 * v3;
v7 = 0xFFFF * (unsigned __int8)a3[v6[5]] / v6[6];
LODWORD(v3) = 0xFFFF * (unsigned __int8)a3[v6[7]] / v6[8];
if ( a1[2] != __PAIR32__(v3, v7) )
{
v8 = gimx_params[13];
a1[1] = 1;
*((_WORD *)a1 + 4) = v7;
*((_WORD *)a1 + 5) = v3;
if ( v8 )
{
printf("> RUMBLE, weak=%hu, strong=%hu\n", (unsigned __int16)v7, (unsigned __int16)v3);
LODWORD(v3) = fflush(stdout);
}
}
}
return v3;
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1, __int64 a2, _BYTE *a3)
{
__int64 v3; // rax
char v5; // dl
unsigned __int8 *v6; // r8
int v7; // esi
int v8; // edx

v3 = *a1;
v5 = byte_364[10 * v3];
if ( !v5 || *a3 == v5 )
{
v6 = (unsigned __int8 *)&props + 10 * v3;
v7 = 0xFFFF * (unsigned __int8)a3[v6[5]] / v6[6];
LODWORD(v3) = 0xFFFF * (unsigned __int8)a3[v6[7]] / v6[8];
if ( a1[2] != __PAIR32__(v3, v7) )
{
v8 = gimx_params[13];
a1[1] = 1;
*((_WORD *)a1 + 4) = v7;
*((_WORD *)a1 + 5) = v3;
if ( v8 )
{
printf("> RUMBLE, weak=%hu, strong=%hu\n", (unsigned __int16)v7, (unsigned __int16)v3);
LODWORD(v3) = fflush(stdout);
}
}
}
return v3;
}

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:
// attributes: thunk
void haptic_source_rumble_clean(void *ptr)
{
free(ptr);
}

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

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 func0()
{
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 func1(__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 v2; // [rsp+0h] [rbp-38h] BYREF

if ( (unsigned __int8)gppcprog_connect() != 1 )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)gpppcprog_input(a1, &v2, 1000LL) != 1 )
{
gppcprog_disconnect(a1);
return 0xFFFFFFFFLL;
}
if ( (unsigned __int8)(BYTE1(v2) - 1) > 3u )
return 0xFFFFFFFFLL;
return (unsigned int)CSWTCH_11[(unsigned __int8)(BYTE1(v2) - 1)];
}

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

if ( (unsigned __int8)gppcprog_connect() != 1 )
return 0xFFFFFFFFLL;
if ( (unsigned __int8)gpppcprog_input(a1, &v2, 1000LL) != 1 )
{
gppcprog_disconnect(a1);
return 0xFFFFFFFFLL;
}
if ( (unsigned __int8)(BYTE1(v2) - 1) > 3u )
return 0xFFFFFFFFLL;
return (unsigned int)CSWTCH_11[(unsigned __int8)(BYTE1(v2) - 1)];
}

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: ret int

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:
// attributes: thunk
__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:
// attributes: thunk
__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 func0(__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 func1()
{
return printf("%s", "\x1B[0m");
}


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

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

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

v2 = dest;
v3 = 0LL;
while ( *(_BYTE *)v2 )
{
if ( func0(*v2, a2) )
{
if ( !gimx_params[13] )
{
LABEL_7:
memmove(v2, (char *)dest + 2 * (int)v3 + 2, 2LL * (3 - (int)v3));
*((_WORD *)dest + 4 - v3 - 1) = 0;
return;
}
printf("> remove %02x", (unsigned __int8)a2);
fflush(stdout);
v4 = gimx_params[13];
if ( (_BYTE)a2 == 0xF8 )
{
if ( !v4 )
goto LABEL_7;
printf(" %02x", HIBYTE(a2));
fflush(stdout);
v4 = gimx_params[13];
}
if ( v4 )
{
putchar(10);
fflush(stdout);
}
goto LABEL_7;
}
++v3;
++v2;
if ( v3 == 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

variable_types: i int


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

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

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

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

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