decompiled_code:
void __fastcall lirc_client_parse(__int64 a1, __int64 a2, int a3, char *a4)
{
char *v4; // r12
int v5; // ebx
char *v6; // rax
char *v7; // rbp
char *v8; // rax
size_t v9; // rax
char *v10; // r15
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
size_t v14; // rax
__int64 v15; // [rsp+0h] [rbp-258h]
int fd[3]; // [rsp+Ch] [rbp-24Ch] BYREF
char *save_ptr; // [rsp+18h] [rbp-240h] BYREF
char s[568]; // [rsp+20h] [rbp-238h] BYREF

v4 = a4;
v5 = 0;
fd[0] = a3;
v6 = strtok_r(a4, " ", &save_ptr);
v7 = v6;
if ( v6 )
{
v4 = (char *)safe_strdup(v6);
v8 = strtok_r(0LL, " ", &save_ptr);
v7 = v8;
v5 = 1;
if ( v8 )
{
v7 = (char *)safe_strdup(v8);
printf("Command string = %s\n", v4);
printf("Command args = %s\n", v7);
}
else
{
printf("Command string = %s\n", v4);
}
}
if ( !strcmp(v4, "PRIVMSG") )
{
v15 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
memset(s, 0, 0x200uLL);
while ( 1 )
{
v10 = strtok_r(0LL, " ", &save_ptr);
if ( !v10 )
break;
v9 = strlen(s);
*(_WORD *)stpcpy(&s[v9], v10) = 32;
}
lirc_channel_message(a1, v15, v7, s);
}
else if ( !strcmp(v4, "NICK") )
{
if ( find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp) )
{
lirc_client_setnick(a1, fd[0], (__int64)v7);
if ( !v5 )
return;
LABEL_15:
free(v4);
free(v7);
return;
}
lirc_client_connect(a1, a2, fd[0], v7);
}
else if ( !strcmp(v4, "JOIN") )
{
v12 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
lirc_channel_join(a1, v12, v7);
}
else if ( !strcmp(v4, "PART") )
{
v13 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
lirc_channel_leave(a1, v13, v7);
}
else if ( !strcmp(v4, "WHO") )
{
v11 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
lirc_channel_who(a1, v11, v7);
}
else if ( !strcmp(v4, "PING") )
{
sprintf(s, ":lirc.org PONG lirc.org :%s\r\n", v7);
v14 = strlen(s);
send(fd[0], s, v14, 0);
}
else if ( !strcmp(v4, "QUIT") )
{
lirc_client_disconnect(a1, fd[0]);
}
if ( v5 )
goto LABEL_15;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, int a3, char *a4)
{
char *v4; // r12
int v5; // ebx
char *v6; // rax
char *v7; // rbp
char *v8; // rax
size_t v9; // rax
char *v10; // r15
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
size_t v14; // rax
__int64 v15; // [rsp+0h] [rbp-258h]
int fd[3]; // [rsp+Ch] [rbp-24Ch] BYREF
char *save_ptr; // [rsp+18h] [rbp-240h] BYREF
char s[568]; // [rsp+20h] [rbp-238h] BYREF

v4 = a4;
v5 = 0;
fd[0] = a3;
v6 = strtok_r(a4, " ", &save_ptr);
v7 = v6;
if ( v6 )
{
v4 = (char *)safe_strdup(v6);
v8 = strtok_r(0LL, " ", &save_ptr);
v7 = v8;
v5 = 1;
if ( v8 )
{
v7 = (char *)safe_strdup(v8);
printf("Command string = %s\n", v4);
printf("Command args = %s\n", v7);
}
else
{
printf("Command string = %s\n", v4);
}
}
if ( !strcmp(v4, "PRIVMSG") )
{
v15 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
memset(s, 0, 0x200uLL);
while ( 1 )
{
v10 = strtok_r(0LL, " ", &save_ptr);
if ( !v10 )
break;
v9 = strlen(s);
*(_WORD *)stpcpy(&s[v9], v10) = 32;
}
lirc_channel_message(a1, v15, v7, s);
}
else if ( !strcmp(v4, "NICK") )
{
if ( find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp) )
{
func3(a1, fd[0], (__int64)v7);
if ( !v5 )
return;
LABEL_15:
free(v4);
free(v7);
return;
}
func2(a1, a2, fd[0], v7);
}
else if ( !strcmp(v4, "JOIN") )
{
v12 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
lirc_channel_join(a1, v12, v7);
}
else if ( !strcmp(v4, "PART") )
{
v13 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
lirc_channel_leave(a1, v13, v7);
}
else if ( !strcmp(v4, "WHO") )
{
v11 = find_element(*(_QWORD *)(a1 + 24), fd, lirc_client_cmp);
lirc_channel_who(a1, v11, v7);
}
else if ( !strcmp(v4, "PING") )
{
sprintf(s, ":lirc.org PONG lirc.org :%s\r\n", v7);
v14 = strlen(s);
send(fd[0], s, v14, 0);
}
else if ( !strcmp(v4, "QUIT") )
{
func4(a1, fd[0]);
}
if ( v5 )
goto LABEL_15;
}

original_code:
void lirc_client_parse(struct LIRCServer_struct* server,
                       LIRCSettings* settings, int socket, char* command)
{
  char* saveptr;
  char* c_str;
  BOOL args = FALSE;
  char* command_string = ((void *)0);
  char* command_args = ((void *)0);
  c_str = strtok_r(command, " ", &saveptr);
  if (c_str)
  {
    args = TRUE;
    command_string = safe_strdup(c_str);
    c_str = strtok_r(((void *)0), " ", &saveptr);
    if (c_str != ((void *)0))
      command_args = safe_strdup(c_str);
    printf("Command string = %s\n", command_string);
    if (c_str != ((void *)0))
      printf("Command args = %s\n", command_args);
  }
  else
  {
    command_string = command;
  }
  if (!strcmp(command_string, "PRIVMSG"))
  {
    char message[512];
    char* message_tmp;
    struct LIRCClientData_struct* client =
      (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    memset(message, '\0', 512);
    while ((message_tmp = strtok_r(((void *)0), " ", &saveptr)) != ((void *)0))
    {
      strcat(message, message_tmp);
      strcat(message, " ");
    }
    lirc_channel_message(server, client, command_args, message);
  }
  else if (!strcmp(command_string, "NICK"))
  {
    if (find_element(server->client_list, &socket, lirc_client_cmp) == ((void *)0))
      lirc_client_connect(server, settings, socket, command_args);
    else
      lirc_client_setnick(server, socket, command_args);
  }
  else if (!strcmp(command_string, "JOIN"))
  {
    struct LIRCClientData_struct* client =
      (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    lirc_channel_join(server, client, command_args);
  }
  else if (!strcmp(command_string, "PART"))
  {
    struct LIRCClientData_struct* client =
      (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    lirc_channel_leave(server, client, command_args);
  }
  else if (!strcmp(command_string, "WHO"))
  {
    struct LIRCClientData_struct* client =
      (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    lirc_channel_who(server, client, command_args);
  }
  else if (!strcmp(command_string, "PING"))
  {
    char temp[512];
    sprintf(temp, ":lirc.org PONG lirc.org :%s\r\n", command_args);
    send(socket, temp, strlen(temp), 0);
  }
  else if (!strcmp(command_string, "QUIT"))
  {
    lirc_client_disconnect(server, socket);
  }
  else
  {
  }
  if (args)
  {
    free(command_string);
    free(command_args);
  }
}

canonical_original_code:
void lirc_client_parse(struct LIRCServer_struct *server, struct LIRCSettings_struct *settings, int socket, char *command)
{
  char *saveptr;
  char *c_str;
  enum BOOL args = FALSE;
  char *command_string = ((void *)0);
  char *command_args = ((void *)0);
  c_str = strtok_r(command, " ", &saveptr);
  if (c_str)
  {
    args = TRUE;
    command_string = safe_strdup(c_str);
    c_str = strtok_r(((void *)0), " ", &saveptr);
    if (c_str != ((void *)0))
      command_args = safe_strdup(c_str);
    printf("Command string = %s\n", command_string);
    if (c_str != ((void *)0))
      printf("Command args = %s\n", command_args);
  }
  else
  {
    command_string = command;
  }
  if (!strcmp(command_string, "PRIVMSG"))
  {
    char message[512];
    char *message_tmp;
    struct LIRCClientData_struct *client = (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    memset(message, '\0', 512);
    while ((message_tmp = strtok_r(((void *)0), " ", &saveptr)) != ((void *)0))
    {
      strcat(message, message_tmp);
      strcat(message, " ");
    }
    lirc_channel_message(server, client, command_args, message);
  }
  else if (!strcmp(command_string, "NICK"))
  {
    if (find_element(server->client_list, &socket, lirc_client_cmp) == ((void *)0))
      lirc_client_connect(server, settings, socket, command_args);
    else
      lirc_client_setnick(server, socket, command_args);
  }
  else if (!strcmp(command_string, "JOIN"))
  {
    struct LIRCClientData_struct *client = (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    lirc_channel_join(server, client, command_args);
  }
  else if (!strcmp(command_string, "PART"))
  {
    struct LIRCClientData_struct *client = (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    lirc_channel_leave(server, client, command_args);
  }
  else if (!strcmp(command_string, "WHO"))
  {
    struct LIRCClientData_struct *client = (struct LIRCClientData_struct*)find_element(server->client_list,
                                                  &socket,
                                                  lirc_client_cmp);
    lirc_channel_who(server, client, command_args);
  }
  else if (!strcmp(command_string, "PING"))
  {
    char temp[512];
    sprintf(temp, ":lirc.org PONG lirc.org :%s\r\n", command_args);
    send(socket, temp, strlen(temp), 0);
  }
  else if (!strcmp(command_string, "QUIT"))
  {
    lirc_client_disconnect(server, socket);
  }
  else
  {
  }
  if (args)
  {
    free(command_string);
    free(command_args);
  }
}

variable_types:
args
enum BOOL { FALSE=0, TRUE=1 }

variable_types:
message
char [512]


repo: TripleChocPi/LIRC

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

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

original_code:
LIRCClientData* lirc_client_search(struct LIRCServer_struct* server,
                                   int socket)
{
  return ((void *)0);
}

canonical_original_code:
struct LIRCClientData_struct *lirc_client_search(struct LIRCServer_struct *server, int socket)
{
  return ((void *)0);
}

variable_types: struct LIRCServer_struct { int epoll; int l_socket; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } l_socket_addr; struct dlist_t *client_list; struct dlist_t *channel_list; } *

variable_types: socket int

return_type: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *channel_list; } *

user_defined_types: struct LIRCServer_struct { int epoll; int l_socket; struct sockaddr_in l_socket_addr; struct dlist_t *client_list; struct dlist_t *channel_list; }

user_defined_types: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t *channel_list; }

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

user_defined_types: struct dlist_t { struct dlnode *head; struct dlnode *foot; int list_len; int size; }


decompiled_code:
__int64 __fastcall lirc_client_cmp(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)-(*a1 != *a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)-(*a1 != *a2);
}

original_code:
static int lirc_client_cmp(const void *client, const void *socket)
{
  LIRCClientData* client_data = (LIRCClientData*)client;
  int s = *((int *)socket);
  if (client_data->socket == s)
    return 0;
  else
    return -1;
}

canonical_original_code:
static int lirc_client_cmp(void *client, void *socket)
{
  struct LIRCClientData_struct *client_data = (LIRCClientData*)client;
  int s = *((int *)socket);
  if (client_data->socket == s)
    return 0;
  else
    return -1;
}

variable_types:
client
void *

variable_types:
socket
void *

variable_types: struct LIRCClientData_struct { int socket; char *nick; struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *channel_list; } *

variable_types: s int

return_type: int


decompiled_code:
void *__fastcall safe_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
perror("Attempt to alloc memory failed (malloc)");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
perror("Attempt to alloc memory failed (malloc)");
exit(1);
}
return result;
}

original_code:
void *
safe_malloc (size_t size)
{
  void * ptr = malloc(size);
  if (ptr == ((void *)0))
  {
    perror("Attempt to alloc memory failed (malloc)");
    exit(1);
  }
  return ptr;
}

canonical_original_code:
void *safe_malloc(unsigned long size)
{
  void *ptr = malloc(size);
  if (ptr == ((void *)0))
  {
    perror("Attempt to alloc memory failed (malloc)");
    exit(1);
  }
  return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


decompiled_code:
void *__fastcall safe_realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("Attempt to alloc memory failed (realloc)");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("Attempt to alloc memory failed (realloc)");
exit(1);
}
return result;
}

original_code:
void *
safe_realloc (void *old_mem, size_t new_size)
{
  void * ptr = realloc(old_mem, new_size);
  if (ptr == ((void *)0))
  {
    perror("Attempt to alloc memory failed (realloc)");
    exit(1);
  }
  return ptr;
}

canonical_original_code:
void *safe_realloc(void *old_mem, unsigned long new_size)
{
  void *ptr = realloc(old_mem, new_size);
  if (ptr == ((void *)0))
  {
    perror("Attempt to alloc memory failed (realloc)");
    exit(1);
  }
  return ptr;
}


decompiled_code:
void *__fastcall safe_strdup(void *src)
{
size_t v1; // rax
void *v2; // r12
size_t v3; // rax

if ( !src )
{
perror("Attempt to duplicate string failed (strdup)");
exit(1);
}
v1 = strlen((const char *)src);
v2 = safe_malloc(v1 + 1);
v3 = strlen((const char *)src);
return memcpy(v2, src, v3 + 1);
}

canonical_decompiled_code:
void *__fastcall func2(void *src)
{
size_t v1; // rax
void *v2; // r12
size_t v3; // rax

if ( !src )
{
perror("Attempt to duplicate string failed (strdup)");
exit(1);
}
v1 = strlen((const char *)src);
v2 = func0(v1 + 1);
v3 = strlen((const char *)src);
return memcpy(v2, src, v3 + 1);
}

original_code:
char *
safe_strdup (const char *str)
{
  char *ptr = ((void *)0);
  if (str == ((void *)0))
  {
    perror("Attempt to duplicate string failed (strdup)");
    exit(1);
  }
  ptr = safe_malloc((strlen(str) + 1) * sizeof(char));
  memcpy(ptr, str, (strlen(str) + 1) * sizeof(char));
  return ptr;
}

canonical_original_code:
char *safe_strdup(char *str)
{
  char *ptr = ((void *)0);
  if (str == ((void *)0))
  {
    perror("Attempt to duplicate string failed (strdup)");
    exit(1);
  }
  ptr = safe_malloc((strlen(str) + 1) * sizeof(char));
  memcpy(ptr, str, (strlen(str) + 1) * sizeof(char));
  return ptr;
}

variable_types:
str
char *

variable_types:
ptr
char *

return_type: char *


decompiled_code:
int __fastcall make_socket_non_blocking(int fd)
{
unsigned int v1; // eax
int result; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 == -1 )
{
perror("FCNTL flag retreval error");
exit(1);
}
BYTE1(v1) |= 8u;
result = fcntl(fd, 4, v1);
if ( result == -1 )
{
perror("FCNTL set non-blocking error");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int fd)
{
unsigned int v1; // eax
int result; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 == -1 )
{
perror("FCNTL flag retreval error");
exit(1);
}
BYTE1(v1) |= 8u;
result = fcntl(fd, 4, v1);
if ( result == -1 )
{
perror("FCNTL set non-blocking error");
exit(1);
}
return result;
}

original_code:
void
make_socket_non_blocking (int socket)
{
  int flags, s;
  flags = fcntl(socket, 3, 0);
  if (flags == -1)
  {
    perror("FCNTL flag retreval error");
    exit(1);
  }
  flags |= 04000;
  s = fcntl(socket, 4, flags);
  if (s == -1)
  {
    perror("FCNTL set non-blocking error");
    exit(1);
  }
}

canonical_original_code:
void make_socket_non_blocking(int socket)
{
  int flags; int s;
  flags = fcntl(socket, 3, 0);
  if (flags == -1)
  {
    perror("FCNTL flag retreval error");
    exit(1);
  }
  flags |= 04000;
  s = fcntl(socket, 4, flags);
  if (s == -1)
  {
    perror("FCNTL set non-blocking error");
    exit(1);
  }
}

variable_types: flags int

return_type: void


decompiled_code:
_QWORD *make_empty_list()
{
_QWORD *result; // rax

result = (_QWORD *)safe_malloc(24LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0x1800000000LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = (_QWORD *)safe_malloc(24LL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0x1800000000LL;
return result;
}

original_code:
dlist_t *
make_empty_list (void)
{
  dlist_t * empty_list = safe_malloc(sizeof(dlist_t));
  empty_list->head = ((void *)0);
  empty_list->foot = ((void *)0);
  empty_list->list_len = 0;
  empty_list->size = sizeof(dlist_t);
  return empty_list;
}

canonical_original_code:
struct dlist_t *make_empty_list()
{
  struct dlist_t *empty_list = safe_malloc(sizeof(dlist_t));
  empty_list->head = ((void *)0);
  empty_list->foot = ((void *)0);
  empty_list->list_len = 0;
  empty_list->size = sizeof(dlist_t);
  return empty_list;
}

variable_types: struct dlist_t { struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *head; struct dlnode *foot; int list_len; int size; } *


original_code:
void
delete_list (dlist_t *list, void (*destroy_fptr)(void *))
{
  int i;
  dlnode_t * current = list->head;
  dlnode_t * next = ((void *)0);
  for (i = 0; i < list->list_len; i++)
  {
    next = current->next;
    destroy_fptr(current->data);
    destroy_fptr(current);
    current = next;
  }
  destroy_fptr(list);
}

canonical_original_code:
void delete_list(struct dlist_t *list, void (*destroy_fptr)(void *))
{
  int i;
  struct dlnode *current = list->head;
  struct dlnode *next = ((void *)0);
  for (i = 0; i < list->list_len; i++)
  {
    next = current->next;
    destroy_fptr(current->data);
    destroy_fptr(current);
    current = next;
  }
  destroy_fptr(list);
}

variable_types: i int

variable_types: struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; } *


original_code:
void *
find_element (dlist_t *list, void *value,
              int (*cmp_fptr) (const void*, const void*))
{
  dlnode_t * current = list->head;
  while (current != ((void *)0))
  {
    if (cmp_fptr(current->data, value) == 0)
      return current->data;
    current = current->next;
  }
  return 0;
}

canonical_original_code:
void *find_element(struct dlist_t *list, void *value, int (*cmp_fptr)(void *, void *))
{
  struct dlnode *current = list->head;
  while (current != ((void *)0))
  {
    if (cmp_fptr(current->data, value) == 0)
      return current->data;
    current = current->next;
  }
  return 0;
}

variable_types:
value
void *

user_defined_types: struct dlnode { int size; void *data; struct dlnode *next; struct dlnode *prev; }


original_code:
void*
remove_element(dlist_t* list,void* val,
               int (*cmp_fptr)(const void*,const void*))
{
  dlnode_t *curr = ((void *)0), *prev = ((void *)0);
  void* item;
  curr = list->head;
  while( curr != ((void *)0) && cmp_fptr (curr->data,val)!=0 )
  {
    prev = curr;
    curr = curr->next;
  }
  if(curr==((void *)0)) return ((void *)0);
  list->size -= curr->size;
  list->size -= sizeof(dlnode_t);
  if(prev==((void *)0))
  {
    list->head = curr->next;
    if(list->head) list->head->prev = ((void *)0);
    item = curr->data;
    free(curr);
    if(list->head == ((void *)0)) list->foot = ((void *)0);
  }
  else
  {
    item = curr->data;
    prev->next = curr->next;
    if(curr->next==((void *)0)) list->foot = prev;
    else
    {
      prev->next->prev = prev;
    }
    free(curr);
  }
  list->list_len--;
  return item;
}

canonical_original_code:
void *remove_element(struct dlist_t *list, void *val, int (*cmp_fptr)(void *, void *))
{
  struct dlnode *curr = ((void *)0); struct dlnode *prev = ((void *)0);
  void *item;
  curr = list->head;
  while( curr != ((void *)0) && cmp_fptr (curr->data,val)!=0 )
  {
    prev = curr;
    curr = curr->next;
  }
  if(curr==((void *)0)) return ((void *)0);
  list->size -= curr->size;
  list->size -= sizeof(dlnode_t);
  if(prev==((void *)0))
  {
    list->head = curr->next;
    if(list->head) list->head->prev = ((void *)0);
    item = curr->data;
    free(curr);
    if(list->head == ((void *)0)) list->foot = ((void *)0);
  }
  else
  {
    item = curr->data;
    prev->next = curr->next;
    if(curr->next==((void *)0)) list->foot = prev;
    else
    {
      prev->next->prev = prev;
    }
    free(curr);
  }
  list->list_len--;
  return item;
}

variable_types:
val
void *

variable_types:
item
void *


decompiled_code:
void __fastcall lirc_settings_destroy(__int64 a1)
{
free(*(void **)(a1 + 8));
free(*(void **)(a1 + 16));
}

original_code:
void
lirc_settings_destroy(LIRCSettings* settings)
{
  free(settings->server_name);
  free(settings->motd);
}

canonical_original_code:
void lirc_settings_destroy(struct LIRCSettings_struct *settings)
{
  free(settings->server_name);
  free(settings->motd);
}

variable_types: struct LIRCSettings_struct { int port; char *server_name; char *motd; } *


help

repo: TripleSpeeder/LTWheelConf

decompiled_code:
int help()
{
return puts(
"\n"
"ltwheelconf 0.2.7 - Configure Logitech Driving Force Pro, G25, G27 wheels\n"
" \n"
" ltwheelconf Copyright (C) 2011 Michael Bauer\n"
" This program comes with ABSOLUTELY NO WARRANTY.\n"
" \n"
" General Options: \n"
" -h, --help This help text\n"
" -v, --verbose Verbose output\n"
" Use -vv to get debug messages from libusb\n"
" -l, --list List all found/supported devices\n"
" \n"
" Wheel configuration: \n"
" -w, --wheel=shortname Which wheel is connected. Supported values:\n"
" -> 'DF' (Driving Force)\n"
" -> 'MR' (Momo Racing)\n"
" -> 'MF' (Momo Force)\n"
" -> 'DFP' (Driving Force Pro)\n"
" -> 'DFGT' (Driving Force GT)\n"
" -> 'G25' (G25)\n"
" -> 'G27' (G27)\n"
" -n, --nativemode Set wheel to native mode (separate axes, full wheel range, clutch pedal, H-sh"
"ifter)\n"
" -x, --reset Reset the wheel. This is basically the same like unplugging & replugging it.\n"
" Note:\n"
" -> Requires wheel to be in native (-n) mode!\n"
" -r, --range=degrees Set wheel rotation range (up to 900 degrees).\n"
" Note:\n"
" -> Requires wheel to be in native (-n) mode!\n"
" -a, --autocenter=value Set autocenter bypassing hid driver. Value should be between 0 and 255 (0 -> "
"no autocenter, 255 -> max autocenter force). \n"
" Together with the rampspeed setting this allows much finer control of the aut"
"ocenter behaviour as using the generic input interface.\n"
" Note: \n"
" -> Requires parameter '--rampspeed'\n"
" -s, --rampspeed Use in conjuntion with the --autocenter parameter. Specify how fast the autoc"
"enter force should increase when rotating wheel.\n"
" Value should be between 0 and 7\n"
" Low value means the centering force is increasing only slightly when turning "
"the wheel.\n"
" High value means the centering force is increasing very fast when turning the"
" wheel.\n"
" -b, --altautocenter=value Set autocenter force using generic input interface. Value should be between 0"
" and 100 (0 -> no autocenter, 100 -> max autocenter force). \n"
" Use this if --autocenter does not work for your device.\n"
" Note: \n"
" -> Requires parameter '--device' to specify the input device\n"
" -> Only works with kernel >= 2.6.39\n"
" -> The rampspeed can not be influenced using this method\n"
" -g, --gain=value Set forcefeedback gain. Value should be between 0 and 100 (0 -> no gain, 100 "
"-> max gain). \n"
" Note: \n"
" -> Requires parameter '--device' to specify the input device\n"
" -d, --device=inputdevice Specify inputdevice for force-feedback related configuration (--gain and --al"
"tautocenter)\n"
" \n"
" Note: You can freely combine all configuration options.\n"
" \n"
" Examples:\n"
" Put wheel into native mode:\n"
" $ sudo ltwheelconf --wheel G25 --nativemode\n"
" Set wheel rotation range to 900 degree:\n"
" $ sudo ltwheelconf --wheel G27 --range 900 \n"
" Set moderate autocenter:\n"
" $ sudo ltwheelconf --wheel DFP --autocenter 100 --rampspeed 1\n"
" Disable autocenter completely:\n"
" $ sudo ltwheelconf --wheel G25 --autocenter 0 --rampspeed 0\n"
" Set native mode, disable autocenter and set wheel rotation range of 540 degrees in one call:\n"
" $ sudo ltwheelconf --wheel G25 --nativemode --range 540 --autocenter 0 --rampspeed 0\n"
" \n"
" Contact: michael@m-bauer.org\n"
" ");
}

canonical_decompiled_code:
int func0()
{
return puts(
"\n"
"ltwheelconf 0.2.7 - Configure Logitech Driving Force Pro, G25, G27 wheels\n"
" \n"
" ltwheelconf Copyright (C) 2011 Michael Bauer\n"
" This program comes with ABSOLUTELY NO WARRANTY.\n"
" \n"
" General Options: \n"
" -h, --help This help text\n"
" -v, --verbose Verbose output\n"
" Use -vv to get debug messages from libusb\n"
" -l, --list List all found/supported devices\n"
" \n"
" Wheel configuration: \n"
" -w, --wheel=shortname Which wheel is connected. Supported values:\n"
" -> 'DF' (Driving Force)\n"
" -> 'MR' (Momo Racing)\n"
" -> 'MF' (Momo Force)\n"
" -> 'DFP' (Driving Force Pro)\n"
" -> 'DFGT' (Driving Force GT)\n"
" -> 'G25' (G25)\n"
" -> 'G27' (G27)\n"
" -n, --nativemode Set wheel to native mode (separate axes, full wheel range, clutch pedal, H-sh"
"ifter)\n"
" -x, --reset Reset the wheel. This is basically the same like unplugging & replugging it.\n"
" Note:\n"
" -> Requires wheel to be in native (-n) mode!\n"
" -r, --range=degrees Set wheel rotation range (up to 900 degrees).\n"
" Note:\n"
" -> Requires wheel to be in native (-n) mode!\n"
" -a, --autocenter=value Set autocenter bypassing hid driver. Value should be between 0 and 255 (0 -> "
"no autocenter, 255 -> max autocenter force). \n"
" Together with the rampspeed setting this allows much finer control of the aut"
"ocenter behaviour as using the generic input interface.\n"
" Note: \n"
" -> Requires parameter '--rampspeed'\n"
" -s, --rampspeed Use in conjuntion with the --autocenter parameter. Specify how fast the autoc"
"enter force should increase when rotating wheel.\n"
" Value should be between 0 and 7\n"
" Low value means the centering force is increasing only slightly when turning "
"the wheel.\n"
" High value means the centering force is increasing very fast when turning the"
" wheel.\n"
" -b, --altautocenter=value Set autocenter force using generic input interface. Value should be between 0"
" and 100 (0 -> no autocenter, 100 -> max autocenter force). \n"
" Use this if --autocenter does not work for your device.\n"
" Note: \n"
" -> Requires parameter '--device' to specify the input device\n"
" -> Only works with kernel >= 2.6.39\n"
" -> The rampspeed can not be influenced using this method\n"
" -g, --gain=value Set forcefeedback gain. Value should be between 0 and 100 (0 -> no gain, 100 "
"-> max gain). \n"
" Note: \n"
" -> Requires parameter '--device' to specify the input device\n"
" -d, --device=inputdevice Specify inputdevice for force-feedback related configuration (--gain and --al"
"tautocenter)\n"
" \n"
" Note: You can freely combine all configuration options.\n"
" \n"
" Examples:\n"
" Put wheel into native mode:\n"
" $ sudo ltwheelconf --wheel G25 --nativemode\n"
" Set wheel rotation range to 900 degree:\n"
" $ sudo ltwheelconf --wheel G27 --range 900 \n"
" Set moderate autocenter:\n"
" $ sudo ltwheelconf --wheel DFP --autocenter 100 --rampspeed 1\n"
" Disable autocenter completely:\n"
" $ sudo ltwheelconf --wheel G25 --autocenter 0 --rampspeed 0\n"
" Set native mode, disable autocenter and set wheel rotation range of 540 degrees in one call:\n"
" $ sudo ltwheelconf --wheel G25 --nativemode --range 540 --autocenter 0 --rampspeed 0\n"
" \n"
" Contact: michael@m-bauer.org\n"
" ");
}

original_code:
void help() {
    printf ( "%s","\nltwheelconf " "0.2.7" " - Configure Logitech Driving Force Pro, G25, G27 wheels\n    \n    ltwheelconf Copyright (C) 2011 Michael Bauer\n    This program comes with ABSOLUTELY NO WARRANTY.\n    \n    General Options: \n    -h, --help                  This help text\n    -v, --verbose               Verbose output\n                                Use -vv to get debug messages from libusb\n    -l, --list                  List all found/supported devices\n    \n    Wheel configuration: \n    -w, --wheel=shortname       Which wheel is connected. Supported values:\n        -> 'DF'   (Driving Force)\n        -> 'MR'   (Momo Racing)\n        -> 'MF'   (Momo Force)\n        -> 'DFP'  (Driving Force Pro)\n        -> 'DFGT' (Driving Force GT)\n        -> 'G25'  (G25)\n        -> 'G27'  (G27)\n    -n, --nativemode            Set wheel to native mode (separate axes, full wheel range, clutch pedal, H-shifter)\n    -x, --reset                 Reset the wheel. This is basically the same like unplugging & replugging it.\n                                Note:\n                                    -> Requires wheel to be in native (-n) mode!\n    -r, --range=degrees         Set wheel rotation range (up to 900 degrees).\n                                Note:\n                                    -> Requires wheel to be in native (-n) mode!\n    -a, --autocenter=value      Set autocenter bypassing hid driver. Value should be between 0 and 255 (0 -> no autocenter, 255 -> max autocenter force). \n                                Together with the rampspeed setting this allows much finer control of the autocenter behaviour as using the generic input interface.\n                                Note: \n                                    -> Requires parameter '--rampspeed'\n    -s, --rampspeed             Use in conjuntion with the --autocenter parameter. Specify how fast the autocenter force should increase when rotating wheel.\n                                Value should be between 0 and 7\n                                Low value means the centering force is increasing only slightly when turning the wheel.\n                                High value means the centering force is increasing very fast when turning the wheel.\n    -b, --altautocenter=value   Set autocenter force using generic input interface. Value should be between 0 and 100 (0 -> no autocenter, 100 -> max autocenter force). \n                                Use this if --autocenter does not work for your device.\n                                Note: \n                                    -> Requires parameter '--device' to specify the input device\n                                    -> Only works with kernel >= 2.6.39\n                                    -> The rampspeed can not be influenced using this method\n    -g, --gain=value            Set forcefeedback gain. Value should be between 0 and 100 (0 -> no gain, 100 -> max gain). \n                                Note: \n                                    -> Requires parameter '--device' to specify the input device\n    -d, --device=inputdevice    Specify inputdevice for force-feedback related configuration (--gain and --altautocenter)\n    \n    Note: You can freely combine all configuration options.\n    \n    Examples:\n    Put wheel into native mode:\n    $ sudo ltwheelconf --wheel G25 --nativemode\n    Set wheel rotation range to 900 degree:\n    $ sudo ltwheelconf --wheel G27 --range 900 \n    Set moderate autocenter:\n    $ sudo ltwheelconf --wheel DFP --autocenter 100 --rampspeed 1\n    Disable autocenter completely:\n    $ sudo ltwheelconf --wheel G25 --autocenter 0 --rampspeed 0\n    Set native mode, disable autocenter and set wheel rotation range of 540 degrees in one call:\n    $ sudo ltwheelconf --wheel G25 --nativemode --range 540 --autocenter 0 --rampspeed 0\n    \n    Contact: michael@m-bauer.org\n    \n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
unsigned int v4; // er14
unsigned __int16 v5; // r12
int v6; // eax
__int64 v7; // rdx
const char *v8; // rbp
unsigned __int16 v9; // ax
int v11; // [rsp+Ch] [rbp-1ECh]
int v12; // [rsp+10h] [rbp-1E8h]
int v13; // [rsp+14h] [rbp-1E4h]
int v14; // [rsp+18h] [rbp-1E0h]
int v15; // [rsp+1Ch] [rbp-1DCh]
unsigned int v16; // [rsp+20h] [rbp-1D8h]
unsigned __int16 v17; // [rsp+24h] [rbp-1D4h]
unsigned __int16 v18; // [rsp+26h] [rbp-1D2h]
int v19; // [rsp+28h] [rbp-1D0h]
int v20; // [rsp+2Ch] [rbp-1CCh]
int longind; // [rsp+3Ch] [rbp-1BCh] BYREF
char v22[128]; // [rsp+40h] [rbp-1B8h] BYREF
char dest[312]; // [rsp+C0h] [rbp-138h] BYREF

verbose_flag = 0;
memset(v22, 0, sizeof(v22));
if ( optind >= argc )
{
v15 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v11 = 0;
v16 = -1;
v19 = 0;
v14 = 0;
v13 = 0;
v20 = 0;
v12 = 0;
v18 = 0;
v17 = 0;
}
else
{
v15 = 0;
v11 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v16 = -1;
v19 = 0;
v14 = 0;
v13 = 0;
v20 = 0;
v12 = 0;
v18 = 0;
v17 = 0;
do
{
longind = -1;
v6 = getopt_long(argc, (char *const *)argv, "vhlw:nr:a:g:d:s:b:x", &long_options_0, &longind);
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'a':
v3 = 0;
v4 = 1;
v5 = atoi(optarg);
break;
case 'b':
v3 = 1;
v4 = 0;
v5 = atoi(optarg);
break;
case 'd':
strncpy(v22, optarg, 0x80uLL);
break;
case 'g':
v14 = 1;
v18 = atoi(optarg);
break;
case 'l':
v19 = 1;
break;
case 'n':
v20 = 1;
break;
case 'r':
v13 = 1;
v17 = atoi(optarg);
break;
case 's':
v16 = atoi(optarg);
break;
case 'v':
++verbose_flag;
break;
case 'w':
strncpy(dest, optarg, 0xFFuLL);
v12 = 1;
break;
case 'x':
v15 = 1;
break;
default:
v11 = 1;
break;
}
}
while ( optind < argc );
}
if ( argc <= 1 )
{
help();
goto LABEL_35;
}
libusb_init(0LL);
if ( verbose_flag > 1 )
libusb_set_debug(0LL, 3LL);
if ( v11 )
{
help();
goto LABEL_37;
}
if ( v19 )
{
list_devices();
goto LABEL_37;
}
if ( !v12 )
goto LABEL_13;
v8 = "DF";
while ( strncasecmp(v8, dest, 0xFFuLL) )
{
v8 += 560;
if ( &unk_2730 == (_UNKNOWN *)v8 )
{
printf("Wheel \"%s\" not supported. Did you spell the shortname correctly?\n", dest);
LABEL_13:
if ( v15 )
{
puts("Please provide --wheel parameter!");
if ( v20 )
goto LABEL_63;
LABEL_15:
if ( !v13 )
{
if ( v4 )
goto LABEL_60;
goto LABEL_17;
}
}
else
{
if ( !v20 )
goto LABEL_15;
LABEL_63:
puts("Please provide --wheel parameter!");
if ( !v13 )
{
if ( v4 )
LABEL_60:
puts("Please provide --wheel parameter!");
LABEL_61:
v4 = 0;
LABEL_17:
if ( v3 )
{
if ( v22[0] )
{
v7 = v4;
v4 = 0;
alt_set_autocenter(v5, v22, v7);
}
else
{
puts(
"Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /"
"dev/input/event0')");
}
}
if ( v14 )
{
if ( v22[0] )
set_gain(v18, v22, v4);
else
puts(
"Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /"
"dev/input/event0')");
}
LABEL_37:
libusb_exit(0LL);
LABEL_35:
exit(0);
}
}
puts("Please provide --wheel parameter!");
if ( v4 )
goto LABEL_60;
goto LABEL_61;
}
}
if ( v15 )
{
reset_wheel(v8);
if ( !v20 )
goto LABEL_45;
}
else if ( !v20 )
{
if ( !v13 )
{
if ( !v4 )
goto LABEL_17;
v4 = 0;
LABEL_47:
if ( !v5 )
{
set_autocenter(v8, 0LL, 0LL);
v4 = v12;
goto LABEL_17;
}
if ( v16 == -1 )
{
puts("Please provide '--rampspeed' parameter");
goto LABEL_17;
}
set_autocenter(v8, v5, v16);
LABEL_50:
v4 = v12;
goto LABEL_17;
}
LABEL_53:
v9 = clamprange(v8, v17);
set_range(v8, v9);
if ( !v4 )
goto LABEL_50;
goto LABEL_47;
}
set_native_mode(v8);
LABEL_45:
if ( !v13 )
{
if ( !v4 )
goto LABEL_50;
goto LABEL_47;
}
goto LABEL_53;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er15
unsigned int v4; // er14
unsigned __int16 v5; // r12
int v6; // eax
__int64 v7; // rdx
const char *v8; // rbp
unsigned __int16 v9; // ax
int v11; // [rsp+Ch] [rbp-1ECh]
int v12; // [rsp+10h] [rbp-1E8h]
int v13; // [rsp+14h] [rbp-1E4h]
int v14; // [rsp+18h] [rbp-1E0h]
int v15; // [rsp+1Ch] [rbp-1DCh]
unsigned int v16; // [rsp+20h] [rbp-1D8h]
unsigned __int16 v17; // [rsp+24h] [rbp-1D4h]
unsigned __int16 v18; // [rsp+26h] [rbp-1D2h]
int v19; // [rsp+28h] [rbp-1D0h]
int v20; // [rsp+2Ch] [rbp-1CCh]
int longind; // [rsp+3Ch] [rbp-1BCh] BYREF
char v22[128]; // [rsp+40h] [rbp-1B8h] BYREF
char dest[312]; // [rsp+C0h] [rbp-138h] BYREF

verbose_flag = 0;
memset(v22, 0, sizeof(v22));
if ( optind >= argc )
{
v15 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v11 = 0;
v16 = -1;
v19 = 0;
v14 = 0;
v13 = 0;
v20 = 0;
v12 = 0;
v18 = 0;
v17 = 0;
}
else
{
v15 = 0;
v11 = 0;
v3 = 0;
v4 = 0;
v5 = 0;
v16 = -1;
v19 = 0;
v14 = 0;
v13 = 0;
v20 = 0;
v12 = 0;
v18 = 0;
v17 = 0;
do
{
longind = -1;
v6 = getopt_long(argc, (char *const *)argv, "vhlw:nr:a:g:d:s:b:x", &long_options_0, &longind);
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'a':
v3 = 0;
v4 = 1;
v5 = atoi(optarg);
break;
case 'b':
v3 = 1;
v4 = 0;
v5 = atoi(optarg);
break;
case 'd':
strncpy(v22, optarg, 0x80uLL);
break;
case 'g':
v14 = 1;
v18 = atoi(optarg);
break;
case 'l':
v19 = 1;
break;
case 'n':
v20 = 1;
break;
case 'r':
v13 = 1;
v17 = atoi(optarg);
break;
case 's':
v16 = atoi(optarg);
break;
case 'v':
++verbose_flag;
break;
case 'w':
strncpy(dest, optarg, 0xFFuLL);
v12 = 1;
break;
case 'x':
v15 = 1;
break;
default:
v11 = 1;
break;
}
}
while ( optind < argc );
}
if ( argc <= 1 )
{
func0();
goto LABEL_35;
}
libusb_init(0LL);
if ( verbose_flag > 1 )
libusb_set_debug(0LL, 3LL);
if ( v11 )
{
func0();
goto LABEL_37;
}
if ( v19 )
{
list_devices();
goto LABEL_37;
}
if ( !v12 )
goto LABEL_13;
v8 = "DF";
while ( strncasecmp(v8, dest, 0xFFuLL) )
{
v8 += 560;
if ( &unk_2730 == (_UNKNOWN *)v8 )
{
printf("Wheel \"%s\" not supported. Did you spell the shortname correctly?\n", dest);
LABEL_13:
if ( v15 )
{
puts("Please provide --wheel parameter!");
if ( v20 )
goto LABEL_63;
LABEL_15:
if ( !v13 )
{
if ( v4 )
goto LABEL_60;
goto LABEL_17;
}
}
else
{
if ( !v20 )
goto LABEL_15;
LABEL_63:
puts("Please provide --wheel parameter!");
if ( !v13 )
{
if ( v4 )
LABEL_60:
puts("Please provide --wheel parameter!");
LABEL_61:
v4 = 0;
LABEL_17:
if ( v3 )
{
if ( v22[0] )
{
v7 = v4;
v4 = 0;
alt_set_autocenter(v5, v22, v7);
}
else
{
puts(
"Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /"
"dev/input/event0')");
}
}
if ( v14 )
{
if ( v22[0] )
set_gain(v18, v22, v4);
else
puts(
"Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /"
"dev/input/event0')");
}
LABEL_37:
libusb_exit(0LL);
LABEL_35:
exit(0);
}
}
puts("Please provide --wheel parameter!");
if ( v4 )
goto LABEL_60;
goto LABEL_61;
}
}
if ( v15 )
{
reset_wheel(v8);
if ( !v20 )
goto LABEL_45;
}
else if ( !v20 )
{
if ( !v13 )
{
if ( !v4 )
goto LABEL_17;
v4 = 0;
LABEL_47:
if ( !v5 )
{
set_autocenter(v8, 0LL, 0LL);
v4 = v12;
goto LABEL_17;
}
if ( v16 == -1 )
{
puts("Please provide '--rampspeed' parameter");
goto LABEL_17;
}
set_autocenter(v8, v5, v16);
LABEL_50:
v4 = v12;
goto LABEL_17;
}
LABEL_53:
v9 = clamprange(v8, v17);
set_range(v8, v9);
if ( !v4 )
goto LABEL_50;
goto LABEL_47;
}
set_native_mode(v8);
LABEL_45:
if ( !v13 )
{
if ( !v4 )
goto LABEL_50;
goto LABEL_47;
}
goto LABEL_53;
}

original_code:
int main (int argc, char **argv)
{
    unsigned short int range = 0;
    unsigned short int centerforce = 0;
    unsigned short int gain = 0;
    int do_validate_wheel = 0;
    int do_native = 0;
    int do_range = 0;
    int do_autocenter = 0;
    int do_alt_autocenter = 0;
    int do_gain = 0;
    int do_list = 0;
    int rampspeed = -1;
    int do_help = 0;
    int do_reset = 0;
    char device_file_name[128];
    char shortname[255];
    memset(device_file_name, 0, sizeof(device_file_name));
    verbose_flag = 0;
    static struct option long_options[] =
    {
        {"verbose", 0, 0, 'v'},
        {"help", 0, 0, 'h'},
        {"list", 0, 0, 'l'},
        {"wheel", 1, 0, 'w'},
        {"nativemode", 0, 0, 'n'},
        {"range", 1, 0, 'r'},
        {"altautocenter", 1, 0, 'b'},
        {"autocenter", 1, 0, 'a'},
        {"rampspeed", 1, 0, 's'},
        {"gain", 1, 0, 'g'},
        {"device", 1, 0, 'd'},
        {"reset", 0, 0, 'x'},
        {0, 0, 0, 0 }
    };
    while (optind < argc) {
        int index = -1;
        int result = getopt_long (argc, argv, "vhlw:nr:a:g:d:s:b:x",
                                  long_options, &index);
        if (result == -1)
            break;
            switch (result) {
                case 'v':
                    verbose_flag++;
                    break;
                case 'n':
                    do_native = 1;
                    break;
                case 'r':
                    range = atoi(optarg);
                    do_range = 1;
                    break;
                case 'a':
                    centerforce = atoi(optarg);
                    do_autocenter = 1;
                    do_alt_autocenter = 0;
                    break;
                case 'b':
                    centerforce = atoi(optarg);
                    do_autocenter = 0;
                    do_alt_autocenter = 1;
                    break;
                case 's':
                    rampspeed = atoi(optarg);
                    break;
                case 'g':
                    gain = atoi(optarg);
                    do_gain = 1;
                    break;
                case 'd':
                    strncpy(device_file_name, optarg, 128);
                    break;
                case 'l':
                    do_list = 1;
                    break;
                case 'w':
                    strncpy(shortname, optarg, 255);
                    do_validate_wheel = 1;
                    break;
                case 'x':
                    do_reset = 1;
                    break;
                case '?':
                default:
                    do_help = 1;
                    break;
            }
    }
    if (argc > 1)
    {
        libusb_init(((void *)0));
        if (verbose_flag > 1)
            libusb_set_debug(0, 3);
        int wait_for_udev = 0;
        wheelstruct* wheel = 0;
        if (do_help) {
            help();
        } else if (do_list) {
            list_devices();
        } else {
            if (do_validate_wheel) {
                int numWheels = sizeof(wheels)/sizeof(wheelstruct);
                int i = 0;
                for (i=0; i < numWheels; i++) {
                    if (strncasecmp(wheels[i].shortname, shortname, 255) == 0) {
                        wheel = &(wheels[i]);
                        break;
                    }
                }
                if (!wheel) {
                    printf("Wheel \"%s\" not supported. Did you spell the shortname correctly?\n", shortname);
                }
            }
            if (do_reset) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    reset_wheel(wheel);
                    wait_for_udev = 1;
                }
            }
            if (do_native) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    set_native_mode(wheel);
                    wait_for_udev = 1;
                }
            }
            if (do_range) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    set_range(wheel, clamprange(wheel, range));
                    wait_for_udev = 1;
                }
            }
            if (do_autocenter) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    if (centerforce == 0) {
                        set_autocenter(wheel, centerforce, 0);
                        wait_for_udev = 1;
                    } else if (rampspeed == -1) {
                        printf("Please provide '--rampspeed' parameter\n");
                    } else {
                        set_autocenter(wheel, centerforce, rampspeed);
                        wait_for_udev = 1;
                    }
                }
            }
            if (do_alt_autocenter) {
                if (strlen(device_file_name)) {
                    alt_set_autocenter(centerforce, device_file_name, wait_for_udev);
                    wait_for_udev = 0;
                } else {
                    printf("Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /dev/input/event0')\n");
                }
            }
            if (do_gain) {
                if (strlen(device_file_name)) {
                    set_gain(gain, device_file_name, wait_for_udev);
                    wait_for_udev = 0;
                } else {
                    printf("Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /dev/input/event0')\n");
                }
            }
        }
        libusb_exit(((void *)0));
    } else {
        help();
    }
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned short range = 0;
    unsigned short centerforce = 0;
    unsigned short gain = 0;
    int do_validate_wheel = 0;
    int do_native = 0;
    int do_range = 0;
    int do_autocenter = 0;
    int do_alt_autocenter = 0;
    int do_gain = 0;
    int do_list = 0;
    int rampspeed = -1;
    int do_help = 0;
    int do_reset = 0;
    char device_file_name[128];
    char shortname[255];
    memset(device_file_name, 0, sizeof(device_file_name));
    verbose_flag = 0;
    static struct option long_options[] = {
        {"verbose", 0, 0, 'v'},
        {"help", 0, 0, 'h'},
        {"list", 0, 0, 'l'},
        {"wheel", 1, 0, 'w'},
        {"nativemode", 0, 0, 'n'},
        {"range", 1, 0, 'r'},
        {"altautocenter", 1, 0, 'b'},
        {"autocenter", 1, 0, 'a'},
        {"rampspeed", 1, 0, 's'},
        {"gain", 1, 0, 'g'},
        {"device", 1, 0, 'd'},
        {"reset", 0, 0, 'x'},
        {0, 0, 0, 0 }
    };
    while (optind < argc) {
        int index = -1;
        int result = getopt_long (argc, argv, "vhlw:nr:a:g:d:s:b:x",
                                  long_options, &index);
        if (result == -1)
            break;
            switch (result) {
                case 'v':
                    verbose_flag++;
                    break;
                case 'n':
                    do_native = 1;
                    break;
                case 'r':
                    range = atoi(optarg);
                    do_range = 1;
                    break;
                case 'a':
                    centerforce = atoi(optarg);
                    do_autocenter = 1;
                    do_alt_autocenter = 0;
                    break;
                case 'b':
                    centerforce = atoi(optarg);
                    do_autocenter = 0;
                    do_alt_autocenter = 1;
                    break;
                case 's':
                    rampspeed = atoi(optarg);
                    break;
                case 'g':
                    gain = atoi(optarg);
                    do_gain = 1;
                    break;
                case 'd':
                    strncpy(device_file_name, optarg, 128);
                    break;
                case 'l':
                    do_list = 1;
                    break;
                case 'w':
                    strncpy(shortname, optarg, 255);
                    do_validate_wheel = 1;
                    break;
                case 'x':
                    do_reset = 1;
                    break;
                case '?':
                default:
                    do_help = 1;
                    break;
            }
    }
    if (argc > 1)
    {
        libusb_init(((void *)0));
        if (verbose_flag > 1)
            libusb_set_debug(0, 3);
        int wait_for_udev = 0;
        struct wheelstruct *wheel = 0;
        if (do_help) {
            help();
        } else if (do_list) {
            list_devices();
        } else {
            if (do_validate_wheel) {
                int numWheels = sizeof(wheels)/sizeof(wheelstruct);
                int i = 0;
                for (i=0; i < numWheels; i++) {
                    if (strncasecmp(wheels[i].shortname, shortname, 255) == 0) {
                        wheel = &(wheels[i]);
                        break;
                    }
                }
                if (!wheel) {
                    printf("Wheel \"%s\" not supported. Did you spell the shortname correctly?\n", shortname);
                }
            }
            if (do_reset) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    reset_wheel(wheel);
                    wait_for_udev = 1;
                }
            }
            if (do_native) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    set_native_mode(wheel);
                    wait_for_udev = 1;
                }
            }
            if (do_range) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    set_range(wheel, clamprange(wheel, range));
                    wait_for_udev = 1;
                }
            }
            if (do_autocenter) {
                if (!wheel) {
                    printf("Please provide --wheel parameter!\n");
                } else {
                    if (centerforce == 0) {
                        set_autocenter(wheel, centerforce, 0);
                        wait_for_udev = 1;
                    } else if (rampspeed == -1) {
                        printf("Please provide '--rampspeed' parameter\n");
                    } else {
                        set_autocenter(wheel, centerforce, rampspeed);
                        wait_for_udev = 1;
                    }
                }
            }
            if (do_alt_autocenter) {
                if (strlen(device_file_name)) {
                    alt_set_autocenter(centerforce, device_file_name, wait_for_udev);
                    wait_for_udev = 0;
                } else {
                    printf("Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /dev/input/event0')\n");
                }
            }
            if (do_gain) {
                if (strlen(device_file_name)) {
                    set_gain(gain, device_file_name, wait_for_udev);
                    wait_for_udev = 0;
                } else {
                    printf("Please provide the according event interface for your wheel using '--device' parameter (E.g. '--device /dev/input/event0')\n");
                }
            }
        }
        libusb_exit(((void *)0));
    } else {
        help();
    }
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
range
unsigned short

variable_types:
centerforce
unsigned short

variable_types:
gain
unsigned short

variable_types: rampspeed int

variable_types:
shortname
char [255]

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: index int

variable_types: result int

variable_types: struct wheelstruct { char shortname[255]; char name[255]; unsigned int restricted_pid; unsigned int native_pid; unsigned int min_rotation; unsigned int max_rotation; unsigned int revision; int (*get_nativemode_cmd)(struct cmdstruct { unsigned char cmds[4][8]; unsigned int numCmds; } *c); int (*get_range_cmd)(struct cmdstruct *c, int range); int (*get_autocenter_cmd)(struct cmdstruct *c, int centerforce, int rampspeed); } *

variable_types: numWheels int

user_defined_types: struct wheelstruct { char shortname[255]; char name[255]; unsigned int restricted_pid; unsigned int native_pid; unsigned int min_rotation; unsigned int max_rotation; unsigned int revision; int (*get_nativemode_cmd)(struct cmdstruct *c); int (*get_range_cmd)(struct cmdstruct *c, int range); int (*get_autocenter_cmd)(struct cmdstruct *c, int centerforce, int rampspeed); }


original_code:
void print_cmd(char *result, unsigned char cmd[8]) {
    sprintf(result, "%02X %02X %02X %02X %02X %02X %02X %02X", cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7]);
}

variable_types:
result
char *

variable_types:
cmd
unsigned char [8]


clamprange

decompiled_code:
__int64 __fastcall clamprange(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v6; // er12

v2 = a2;
v3 = *(unsigned int *)(a1 + 520);
if ( (unsigned __int16)a2 < (unsigned int)v3 )
{
printf("Minimum range for %s is %d degrees.\n", (const char *)(a1 + 255), v3);
v4 = *(unsigned int *)(a1 + 524);
v2 = *(_DWORD *)(a1 + 520);
if ( (unsigned int)v4 >= (unsigned __int16)v2 )
return v2;
}
else
{
v4 = *(unsigned int *)(a1 + 524);
if ( (unsigned int)v4 >= (unsigned __int16)a2 )
return v2;
}
v6 = v4;
printf("Maximum range for %s is %d degrees.\n", (const char *)(a1 + 255), v4);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v6; // er12

v2 = a2;
v3 = *(unsigned int *)(a1 + 520);
if ( (unsigned __int16)a2 < (unsigned int)v3 )
{
printf("Minimum range for %s is %d degrees.\n", (const char *)(a1 + 255), v3);
v4 = *(unsigned int *)(a1 + 524);
v2 = *(_DWORD *)(a1 + 520);
if ( (unsigned int)v4 >= (unsigned __int16)v2 )
return v2;
}
else
{
v4 = *(unsigned int *)(a1 + 524);
if ( (unsigned int)v4 >= (unsigned __int16)a2 )
return v2;
}
v6 = v4;
printf("Maximum range for %s is %d degrees.\n", (const char *)(a1 + 255), v4);
return v6;
}

original_code:
short unsigned int clamprange(wheelstruct* w, short unsigned int range)
{
    if (range < w->min_rotation) {
        printf("Minimum range for %s is %d degrees.\n", w->name, w->min_rotation);
        range = w->min_rotation;
    }
    if (range > w->max_rotation) {
        range = w->max_rotation;
        printf("Maximum range for %s is %d degrees.\n", w->name, w->max_rotation);
    }
    return range;
}

canonical_original_code:
unsigned short clamprange(struct wheelstruct *w, unsigned short range)
{
    if (range < w->min_rotation) {
        printf("Minimum range for %s is %d degrees.\n", w->name, w->min_rotation);
        range = w->min_rotation;
    }
    if (range > w->max_rotation) {
        range = w->max_rotation;
        printf("Maximum range for %s is %d degrees.\n", w->name, w->max_rotation);
    }
    return range;
}

return_type: unsigned short

user_defined_types: struct cmdstruct { unsigned char cmds[4][8]; unsigned int numCmds; }


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

*(_QWORD *)a1 = 504LL;
result = 0LL;
*(_DWORD *)(a1 + 32) = 1;
return result;
}

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

*(_QWORD *)a1 = 504LL;
result = 0LL;
*(_DWORD *)(a1 + 32) = 1;
return result;
}

variable_types: struct cmdstruct { unsigned char cmds[4][8]; unsigned int numCmds; } *


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

*(_QWORD *)a1 = 2808LL;
result = 0LL;
*(_QWORD *)(a1 + 8) = 16976376LL;
*(_DWORD *)(a1 + 32) = 2;
return result;
}

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

*(_QWORD *)a1 = 2808LL;
result = 0LL;
*(_QWORD *)(a1 + 8) = 16976376LL;
*(_DWORD *)(a1 + 32) = 2;
return result;
}


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

*(_QWORD *)a1 = 4344LL;
result = 0LL;
*(_DWORD *)(a1 + 32) = 1;
return result;
}

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

*(_QWORD *)a1 = 4344LL;
result = 0LL;
*(_DWORD *)(a1 + 32) = 1;
return result;
}


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

*(_QWORD *)a1 = 2808LL;
result = 0LL;
*(_QWORD *)(a1 + 8) = 17041912LL;
*(_DWORD *)(a1 + 32) = 2;
return result;
}

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

*(_QWORD *)a1 = 2808LL;
result = 0LL;
*(_QWORD *)(a1 + 8) = 17041912LL;
*(_DWORD *)(a1 + 32) = 2;
return result;
}


variable_types: range int


canonical_original_code:
int get_range_cmd2(struct cmdstruct *c, int range)
{
    c->cmds[0][0] = 0xf8;
    c->cmds[0][1] = 0x00;
    c->cmds[0][2] = 0x00;
    c->cmds[0][3] = 0x00;
    c->cmds[0][4] = 0x00;
    c->cmds[0][5] = 0x00;
    c->cmds[0][6] = 0x00;
    c->cmds[0][7] = 0x00;
    c->cmds[1][0] = 0x81;
    c->cmds[1][1] = 0x0b;
    c->cmds[1][2] = 0x00;
    c->cmds[1][3] = 0x00;
    c->cmds[1][4] = 0x00;
    c->cmds[1][5] = 0x00;
    c->cmds[1][6] = 0x00;
    c->cmds[1][7] = 0x00;
    c->numCmds = 2;
    int rampLeft; int rampRight; int fullRange;
    if (range > 200) {
        c->cmds[0][1] = 0x03;
        if (range == 900)
            return 0;
        else
            fullRange = 900;
    } else {
        c->cmds[0][1] = 0x02;
        if (range == 200)
            return 0;
        else
            fullRange = 200;
    }
    rampLeft = (((fullRange - range + 1) * 2047) / fullRange);
    rampRight = 0xfff - rampLeft;
    c->cmds[1][2] = rampLeft >> 4;
    c->cmds[1][3] = rampRight >> 4;
    c->cmds[1][4] = 0xff;
    c->cmds[1][5] = (rampRight & 0xe) << 4 | (rampLeft & 0xe);
    c->cmds[1][6] = 0xff;
    return 0;
}

variable_types: rampLeft int

variable_types: rampRight int

variable_types: fullRange int


original_code:
int get_autocenter_cmd(cmdstruct *c, int centerforce, int rampspeed)
{
    c->cmds[0][0] = 0xfe;
    c->cmds[0][1] = 0x0d;
    c->cmds[0][2] = rampspeed & 0x0f;
    c->cmds[0][3] = rampspeed & 0x0f;
    c->cmds[0][4] = centerforce & 0xff;
    c->cmds[0][5] = 0x00;
    c->cmds[0][6] = 0x00;
    c->cmds[0][7] = 0x00;
    c->numCmds = 1;
    return 0;
}

canonical_original_code:
int get_autocenter_cmd(struct cmdstruct *c, int centerforce, int rampspeed)
{
    c->cmds[0][0] = 0xfe;
    c->cmds[0][1] = 0x0d;
    c->cmds[0][2] = rampspeed & 0x0f;
    c->cmds[0][3] = rampspeed & 0x0f;
    c->cmds[0][4] = centerforce & 0xff;
    c->cmds[0][5] = 0x00;
    c->cmds[0][6] = 0x00;
    c->cmds[0][7] = 0x00;
    c->numCmds = 1;
    return 0;
}

variable_types: centerforce int


repo: Trippley/Battleships

decompiled_code:
__int64 __fastcall natalie_init(int a1)
{
if ( (unsigned int)(a1 - 13) > 0x57 )
return 0xFFFFFFFFLL;
if ( natalie )
return 4294967294LL;
natalie = (__int64)malloc(4 * a1 * (__int64)a1);
if ( !natalie )
return 4294967293LL;
counter = a1 * a1;
memset((void *)natalie, 0, 4LL * a1 * a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( (unsigned int)(a1 - 13) > 0x57 )
return 0xFFFFFFFFLL;
if ( natalie )
return 4294967294LL;
natalie = (__int64)malloc(4 * a1 * (__int64)a1);
if ( !natalie )
return 4294967293LL;
counter = a1 * a1;
memset((void *)natalie, 0, 4LL * a1 * a1);
return 0LL;
}

original_code:
int natalie_init(int size){
 int i;
 if((size < 13) || (size > 100)) return -1;
 if(natalie != ((void *)0)) return -2;
 natalie = malloc(sizeof(int)*size*size);
 if(natalie == ((void *)0)) return -3;
 counter = size*size;
 for(i=0; i<counter; i++) natalie[i] = 0;
 return 0;
}

variable_types: size int

variable_types: i int


decompiled_code:
__int64 __fastcall field_init(int a1)
{
void *v1; // r13
void *v2; // rbp
__int64 v3; // rbx

if ( (unsigned int)(a1 - 13) > 0x57 )
return 0xFFFFFFFFLL;
if ( field1 || field2 )
return 4294967294LL;
field1 = malloc(4 * a1 * (__int64)a1);
v1 = field1;
field2 = malloc(4 * a1 * (__int64)a1);
v2 = field2;
if ( !field2 || !v1 )
return 4294967293LL;
counter = a1 * a1;
v3 = a1 * a1;
memset(v1, 0, 4 * v3);
memset(v2, 0, 4 * v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
void *v1; // r13
void *v2; // rbp
__int64 v3; // rbx

if ( (unsigned int)(a1 - 13) > 0x57 )
return 0xFFFFFFFFLL;
if ( field1 || field2 )
return 4294967294LL;
field1 = malloc(4 * a1 * (__int64)a1);
v1 = field1;
field2 = malloc(4 * a1 * (__int64)a1);
v2 = field2;
if ( !field2 || !v1 )
return 4294967293LL;
counter = a1 * a1;
v3 = a1 * a1;
memset(v1, 0, 4 * v3);
memset(v2, 0, 4 * v3);
return 0LL;
}

original_code:
int field_init(int size){
 int i;
 if((size < 13) || (size > 100)) return -1;
 if((field1 != ((void *)0)) || (field2 != ((void *)0))) return -2;
 field1 = malloc(sizeof(int)*size*size);
 field2 = malloc(sizeof(int)*size*size);
 if((field1 == ((void *)0)) || (field2 == ((void *)0))) return -3;
 counter = size*size;
 for(i=0; i<counter; i++) field1[i] = 0;
 for(i=0; i<counter; i++) field2[i] = 0;
 return 0;
}


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

if ( !field1 && !field2 )
return 0xFFFFFFFFLL;
free(field1);
free(field2);
result = 0LL;
counter = 0;
return result;
}

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

if ( !field1 && !field2 )
return 0xFFFFFFFFLL;
free(field1);
free(field2);
result = 0LL;
counter = 0;
return result;
}

original_code:
int field_delete(){
 if((field1 == ((void *)0)) && (field2 == ((void *)0))) return -1;
 free(field1);
 free(field2);
 counter = 0;
 return 0;
}


decompiled_code:
__int64 field_counter()
{
return (unsigned int)counter;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)counter;
}

original_code:
int field_counter(){
 return counter;
}

canonical_original_code:
int field_counter(){
 return counter;
}


decompiled_code:
__int64 __fastcall field_state(int a1, int a2)
{
if ( (unsigned int)(a1 - 1) > 1 )
return 0xFFFFFFFFLL;
if ( a2 < 0 || counter <= a2 )
return 4294967294LL;
if ( !field1 || !field2 )
return 4294967293LL;
if ( a1 == 1 )
return *((unsigned int *)field1 + a2);
return *((unsigned int *)field2 + a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
if ( (unsigned int)(a1 - 1) > 1 )
return 0xFFFFFFFFLL;
if ( a2 < 0 || counter <= a2 )
return 4294967294LL;
if ( !field1 || !field2 )
return 4294967293LL;
if ( a1 == 1 )
return *((unsigned int *)field1 + a2);
return *((unsigned int *)field2 + a2);
}

original_code:
int field_state(int field, int element){
 if((field != 1) && (field != 2)) return -1;
 if((element < 0) || (element > (counter-1))) return -2;
 if((field1 == ((void *)0)) || (field2 == ((void *)0))) return -3;
 if(field == 1) return field1[element];
 if(field == 2) return field2[element];
 return -4;
}

variable_types: field int

variable_types: element int


decompiled_code:
__int64 __fastcall field_set(int a1, int a2, int a3)
{
if ( (unsigned int)(a1 - 1) > 1 )
return 0xFFFFFFFFLL;
if ( a2 < 0 || counter <= a2 )
return 4294967294LL;
if ( !field1 || !field2 )
return 4294967293LL;
if ( a3 < 0 )
return 4294967292LL;
if ( a1 == 1 )
*((_DWORD *)field1 + a2) = a3;
else
*((_DWORD *)field2 + a2) = a3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, int a3)
{
if ( (unsigned int)(a1 - 1) > 1 )
return 0xFFFFFFFFLL;
if ( a2 < 0 || counter <= a2 )
return 4294967294LL;
if ( !field1 || !field2 )
return 4294967293LL;
if ( a3 < 0 )
return 4294967292LL;
if ( a1 == 1 )
*((_DWORD *)field1 + a2) = a3;
else
*((_DWORD *)field2 + a2) = a3;
return 0LL;
}

original_code:
int field_set(int field, int element, int state){
 if((field != 1) && (field != 2)) return -1;
 if((element < 0) || (element > (counter-1))) return -2;
 if((field1 == ((void *)0)) || (field2 == ((void *)0))) return -3;
 if(state < 0) return -4;
 if(field == 1) field1[element] = state;
 if(field == 2) field2[element] = state;
 return 0;
}

variable_types: state int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int64 v6; // rdx
unsigned int v7; // ebx
unsigned int v8; // er13
unsigned int v9; // er12
unsigned int v10; // eax
unsigned int v11; // eax

v3 = (unsigned int)field_init(&unk_D);
printf("%d\n", v3);
v4 = ship_init();
printf("%d\n", v4);
v5 = ship_set(10LL, 39LL, 110LL);
printf("%d\n", v5);
v7 = field_state(1LL, "%d\n", v6);
v8 = field_state(1LL, &byte_1D[2]);
v9 = field_state(1LL, &byte_1D[1]);
v10 = field_state(1LL, byte_1D);
printf("Koordinaten: %d, %d, %d, %d\n", v10, v9, v8, v7);
v11 = ship_state(10LL, 0LL);
printf("%d\n", v11);
return 0;
}

original_code:
int main(void){
 printf("%d\n", field_init(13));
 printf("%d\n", ship_init());
 printf("%d\n", ship_set(10, 39, 'n'));
 printf("Koordinaten: %d, %d, %d, %d\n", field_state(1, 29), field_state(1, 30), field_state(1, 31), field_state(1, 32));
 printf("%d\n", ship_state(10, 0));
 return 0;
}

canonical_original_code:
int main(){
 printf("%d\n", field_init(13));
 printf("%d\n", ship_init());
 printf("%d\n", ship_set(10, 39, 'n'));
 printf("Koordinaten: %d, %d, %d, %d\n", field_state(1, 29), field_state(1, 30), field_state(1, 31), field_state(1, 32));
 printf("%d\n", ship_state(10, 0));
 return 0;
}


decompiled_code:
__int64 ship_init()
{
__int64 v0; // r15
unsigned int v1; // ebx
int v2; // ebp
int v3; // eax
unsigned int v4; // ebp
int v5; // er12
unsigned int v6; // edi
__int16 v7; // r14
unsigned int v8; // esi
int v9; // ecx
unsigned int v10; // ebp
void *v11; // rax
__int16 v12; // si
int v14; // [rsp+Ch] [rbp-4Ch]
unsigned int v15; // [rsp+Ch] [rbp-4Ch]
unsigned int v16; // [rsp+14h] [rbp-44h]
unsigned int v17; // [rsp+18h] [rbp-40h]
unsigned int v18; // [rsp+1Ch] [rbp-3Ch]

v0 = ship_list;
if ( !(unsigned int)field_counter() )
return 0xFFFFFFFFLL;
v1 = (int)field_counter() / 169;
v2 = (int)(2 * field_counter()) / 169;
v14 = (int)(3 * field_counter()) / 169;
v3 = (int)(4 * field_counter()) / 169;
if ( ship_list )
return 4294967294LL;
v4 = v1 + v2;
v5 = 2 * (v3 + v14 + v4);
if ( v5 )
{
v6 = 2 * (v14 + v4);
v7 = ship_id;
v8 = v1 + v4;
v9 = 2 * v4 + v14;
v15 = 2 * v4;
v10 = 0;
v16 = v8;
v17 = v9;
v18 = v6 + v3;
while ( 1 )
{
if ( v0 )
{
v11 = malloc(0x20uLL);
*(_QWORD *)(v0 + 24) = v11;
v0 = (__int64)v11;
}
else
{
ship_list = (__int64)malloc(0x20uLL);
v0 = ship_list;
}
*(_WORD *)v0 = v7;
ship_id = v7 + 1;
*(_WORD *)(v0 + 4) = 0;
*(_BYTE *)(v0 + 8) = 0;
*(_QWORD *)(v0 + 16) = 0LL;
*(_QWORD *)(v0 + 24) = 0LL;
if ( 2 * v1 > v10 )
break;
if ( v15 <= v10 )
*(_WORD *)(v0 + 6) = (v6 > v10) + 1;
else
*(_WORD *)(v0 + 6) = 3;
if ( v1 > v10 || v16 > v10 )
goto LABEL_21;
if ( v15 > v10 )
goto LABEL_6;
if ( v17 > v10 )
goto LABEL_21;
if ( v6 > v10 )
goto LABEL_6;
v12 = v18 <= v10++;
*(_WORD *)(v0 + 2) = v12 + 1;
if ( v10 == v5 )
return 0LL;
LABEL_8:
++v7;
}
*(_WORD *)(v0 + 6) = 4;
if ( v1 > v10 )
LABEL_21:
*(_WORD *)(v0 + 2) = 1;
else
LABEL_6:
*(_WORD *)(v0 + 2) = 2;
if ( ++v10 == v5 )
return 0LL;
goto LABEL_8;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r15
unsigned int v1; // ebx
int v2; // ebp
int v3; // eax
unsigned int v4; // ebp
int v5; // er12
unsigned int v6; // edi
__int16 v7; // r14
unsigned int v8; // esi
int v9; // ecx
unsigned int v10; // ebp
void *v11; // rax
__int16 v12; // si
int v14; // [rsp+Ch] [rbp-4Ch]
unsigned int v15; // [rsp+Ch] [rbp-4Ch]
unsigned int v16; // [rsp+14h] [rbp-44h]
unsigned int v17; // [rsp+18h] [rbp-40h]
unsigned int v18; // [rsp+1Ch] [rbp-3Ch]

v0 = ship_list;
if ( !(unsigned int)field_counter() )
return 0xFFFFFFFFLL;
v1 = (int)field_counter() / 169;
v2 = (int)(2 * field_counter()) / 169;
v14 = (int)(3 * field_counter()) / 169;
v3 = (int)(4 * field_counter()) / 169;
if ( ship_list )
return 4294967294LL;
v4 = v1 + v2;
v5 = 2 * (v3 + v14 + v4);
if ( v5 )
{
v6 = 2 * (v14 + v4);
v7 = ship_id;
v8 = v1 + v4;
v9 = 2 * v4 + v14;
v15 = 2 * v4;
v10 = 0;
v16 = v8;
v17 = v9;
v18 = v6 + v3;
while ( 1 )
{
if ( v0 )
{
v11 = malloc(0x20uLL);
*(_QWORD *)(v0 + 24) = v11;
v0 = (__int64)v11;
}
else
{
ship_list = (__int64)malloc(0x20uLL);
v0 = ship_list;
}
*(_WORD *)v0 = v7;
ship_id = v7 + 1;
*(_WORD *)(v0 + 4) = 0;
*(_BYTE *)(v0 + 8) = 0;
*(_QWORD *)(v0 + 16) = 0LL;
*(_QWORD *)(v0 + 24) = 0LL;
if ( 2 * v1 > v10 )
break;
if ( v15 <= v10 )
*(_WORD *)(v0 + 6) = (v6 > v10) + 1;
else
*(_WORD *)(v0 + 6) = 3;
if ( v1 > v10 || v16 > v10 )
goto LABEL_21;
if ( v15 > v10 )
goto LABEL_6;
if ( v17 > v10 )
goto LABEL_21;
if ( v6 > v10 )
goto LABEL_6;
v12 = v18 <= v10++;
*(_WORD *)(v0 + 2) = v12 + 1;
if ( v10 == v5 )
return 0LL;
LABEL_8:
++v7;
}
*(_WORD *)(v0 + 6) = 4;
if ( v1 > v10 )
LABEL_21:
*(_WORD *)(v0 + 2) = 1;
else
LABEL_6:
*(_WORD *)(v0 + 2) = 2;
if ( ++v10 == v5 )
return 0LL;
goto LABEL_8;
}
return 0LL;
}

original_code:
int ship_init(){
 unsigned int fours = 0, threes = 0, twos = 0, ones = 0;
 unsigned int i;
 SHIP *tmp_ship = ship_list;
 if(!field_counter()) return -1;
 fours = 1*field_counter()/169;
 threes = 2*field_counter()/169;
 twos = 3*field_counter()/169;
 ones = 4*field_counter()/169;
 if(ship_list != ((void *)0)) return -2;
 for(i=0; i<(fours+threes+twos+ones)*2; i++) {
  if(tmp_ship == ((void *)0)) {
   ship_list = malloc(sizeof(SHIP));
   tmp_ship = ship_list;
  } else {
   tmp_ship->next = malloc(sizeof(SHIP));
   tmp_ship = tmp_ship->next;
  }
  tmp_ship->ship_id = ship_id++;
  tmp_ship->active = 0;
  tmp_ship->direction = 0;
  tmp_ship->coordinates = ((void *)0);
  tmp_ship->next = ((void *)0);
  if(i<fours*2) {tmp_ship->elements = 4;}
  else if (i<fours*2+threes*2) {tmp_ship->elements = 3;}
  else if (i<fours*2+threes*2+twos*2) {tmp_ship->elements = 2;}
  else if (i<fours*2+threes*2+twos*2+ones*2) {tmp_ship->elements = 1; }
  if(i<fours) {tmp_ship->owner = 1;}
  else if (i<fours*2) {tmp_ship->owner = 2;}
  else if (i<fours*2+threes) {tmp_ship->owner = 1;}
  else if (i<fours*2+threes*2) {tmp_ship->owner = 2;}
  else if (i<fours*2+threes*2+twos) {tmp_ship->owner = 1;}
  else if (i<fours*2+threes*2+twos*2) {tmp_ship->owner = 2;}
  else if (i<fours*2+threes*2+twos*2+ones) {tmp_ship->owner = 1;}
  else if (i<fours*2+threes*2+twos*2+ones*2) {tmp_ship->owner = 2;}
 }
 return 0;
}

canonical_original_code:
int ship_init(){
 unsigned int fours = 0; unsigned int threes = 0; unsigned int twos = 0; unsigned int ones = 0;
 unsigned int i;
 struct _ship *tmp_ship = ship_list;
 if(!field_counter()) return -1;
 fours = 1*field_counter()/169;
 threes = 2*field_counter()/169;
 twos = 3*field_counter()/169;
 ones = 4*field_counter()/169;
 if(ship_list != ((void *)0)) return -2;
 for(i=0; i<(fours+threes+twos+ones)*2; i++) {
  if(tmp_ship == ((void *)0)) {
   ship_list = malloc(sizeof(SHIP));
   tmp_ship = ship_list;
  } else {
   tmp_ship->next = malloc(sizeof(SHIP));
   tmp_ship = tmp_ship->next;
  }
  tmp_ship->ship_id = ship_id++;
  tmp_ship->active = 0;
  tmp_ship->direction = 0;
  tmp_ship->coordinates = ((void *)0);
  tmp_ship->next = ((void *)0);
  if(i<fours*2) {tmp_ship->elements = 4;}
  else if (i<fours*2+threes*2) {tmp_ship->elements = 3;}
  else if (i<fours*2+threes*2+twos*2) {tmp_ship->elements = 2;}
  else if (i<fours*2+threes*2+twos*2+ones*2) {tmp_ship->elements = 1; }
  if(i<fours) {tmp_ship->owner = 1;}
  else if (i<fours*2) {tmp_ship->owner = 2;}
  else if (i<fours*2+threes) {tmp_ship->owner = 1;}
  else if (i<fours*2+threes*2) {tmp_ship->owner = 2;}
  else if (i<fours*2+threes*2+twos) {tmp_ship->owner = 1;}
  else if (i<fours*2+threes*2+twos*2) {tmp_ship->owner = 2;}
  else if (i<fours*2+threes*2+twos*2+ones) {tmp_ship->owner = 1;}
  else if (i<fours*2+threes*2+twos*2+ones*2) {tmp_ship->owner = 2;}
 }
 return 0;
}

variable_types:
fours
unsigned int

variable_types:
threes
unsigned int

variable_types:
twos
unsigned int

variable_types:
ones
unsigned int

variable_types:
i
unsigned int

variable_types: struct _ship { unsigned short ship_id; unsigned short owner; unsigned short active; unsigned short elements; char direction; struct _ship_coordinates { unsigned short coordinate; int state; struct _ship_coordinates *next; } *coordinates; struct _ship *next; } *

user_defined_types: struct _ship { unsigned short ship_id; unsigned short owner; unsigned short active; unsigned short elements; char direction; struct _ship_coordinates *coordinates; struct _ship *next; }


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

for ( result = ship_list; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_WORD *)result == a1 )
break;
}
return result;
}

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

for ( result = ship_list; result; result = *(_QWORD *)(result + 24) )
{
if ( *(_WORD *)result == a1 )
break;
}
return result;
}

original_code:
SHIP *ship_address(unsigned short ship_id){
 SHIP *tmp_ship = ship_list;
 while(tmp_ship != ((void *)0)){
  if(tmp_ship->ship_id == ship_id) {
   return tmp_ship;
  }
  tmp_ship = tmp_ship->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct _ship *ship_address(unsigned short ship_id){
 struct _ship *tmp_ship = ship_list;
 while(tmp_ship != ((void *)0)){
  if(tmp_ship->ship_id == ship_id) {
   return tmp_ship;
  }
  tmp_ship = tmp_ship->next;
 }
 return ((void *)0);
}

return_type: struct _ship { unsigned short ship_id; unsigned short owner; unsigned short active; unsigned short elements; char direction; struct _ship_coordinates { unsigned short coordinate; int state; struct _ship_coordinates *next; } *coordinates; struct _ship *next; } *


decompiled_code:
__int64 __fastcall ship_direction(__int16 a1)
{
__int64 v1; // rax
__int64 result; // rax

v1 = ship_address(a1);
if ( v1 )
result = *(unsigned __int8 *)(v1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v1 = func1(a1);
if ( v1 )
result = *(unsigned __int8 *)(v1 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
char ship_direction(unsigned short ship_id){
 SHIP *tmp_ship = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship != ((void *)0)) return tmp_ship->direction;
 return -1;
}

canonical_original_code:
char ship_direction(unsigned short ship_id){
 struct _ship *tmp_ship = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship != ((void *)0)) return tmp_ship->direction;
 return -1;
}

return_type: char

user_defined_types: struct _ship_coordinates { unsigned short coordinate; int state; struct _ship_coordinates *next; }


decompiled_code:
__int64 ship_counter()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = ship_list;
for ( i = 0; v0; ++i )
v0 = *(_QWORD *)(v0 + 24);
return i;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
unsigned int i; // er8

v0 = ship_list;
for ( i = 0; v0; ++i )
v0 = *(_QWORD *)(v0 + 24);
return i;
}

original_code:
unsigned short ship_counter(){
 SHIP *tmp_ship = ship_list;
 unsigned short i = 0;
 while(tmp_ship != ((void *)0)){
  tmp_ship = tmp_ship->next;
  i++;
 }
 return i;
}

canonical_original_code:
unsigned short ship_counter(){
 struct _ship *tmp_ship = ship_list;
 unsigned short i = 0;
 while(tmp_ship != ((void *)0)){
  tmp_ship = tmp_ship->next;
  i++;
 }
 return i;
}

variable_types:
i
unsigned short


decompiled_code:
__int64 __fastcall ship_set(unsigned __int16 a1, unsigned __int16 a2, char a3)
{
__int64 v3; // rax
int v4; // edx
__int64 v5; // rbp
int v6; // er15
char v7; // bl
__int64 result; // rax
__int64 v9; // rcx
int v10; // eax
int v11; // er13
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // xmm0_8
unsigned int v18; // er14
int v19; // er13
_QWORD *v20; // r15
_QWORD *v21; // rax
int v22; // eax
_QWORD *v23; // rax
double v24; // xmm0_8
double v25; // xmm0_8
double v26; // xmm0_8
double v27; // xmm0_8
double v28; // xmm0_8
double v29; // xmm0_8
double v30; // xmm0_8
double v31; // xmm0_8
double v32; // r15
double v33; // xmm0_8
double v34; // xmm0_8
double v35; // xmm0_8
double v36; // xmm0_8
double v37; // xmm0_8
double v38; // xmm0_8
double v39; // xmm0_8
double v40; // xmm0_8
double v41; // [rsp+0h] [rbp-58h]
unsigned int v42; // [rsp+0h] [rbp-58h]
double v43; // [rsp+0h] [rbp-58h]
double v44; // [rsp+8h] [rbp-50h]
double v45; // [rsp+8h] [rbp-50h]
double v46; // [rsp+8h] [rbp-50h]
double v47; // [rsp+10h] [rbp-48h]

v3 = ship_address(a1);
if ( !v3 )
return 0xFFFFFFFFLL;
v5 = v3;
v6 = v4;
v7 = v4;
if ( (int)field_counter() <= a2 )
return 4294967294LL;
result = 4294967293LL;
if ( (unsigned __int8)(v6 - 101) <= 0x12u )
{
v9 = 279041LL;
if ( _bittest64(&v9, (unsigned int)(v6 - 101)) )
{
if ( *(_WORD *)(v5 + 4) )
return 4294967292LL;
v10 = *(unsigned __int16 *)(v5 + 6);
if ( !*(_WORD *)(v5 + 6) )
goto LABEL_57;
v11 = 0;
do
{
while ( 1 )
{
if ( v7 == 110 )
{
v41 = (double)(v10 - 1);
v14 = (double)(int)field_counter();
if ( v14 < 0.0 )
v15 = sqrt(v14);
else
v15 = sqrt(v14);
if ( (double)a2 - v15 * v41 < 0.0 )
return 4294967291LL;
v16 = (double)(int)field_counter();
if ( v16 < 0.0 )
v17 = sqrt(v16);
else
v17 = sqrt(v16);
if ( (unsigned int)field_state(
*(unsigned __int16 *)(v5 + 2),
(unsigned int)(int)((double)a2 - v17 * (double)v11)) )
return 4294967290LL;
goto LABEL_15;
}
if ( v7 == 101 )
break;
if ( v7 != 115 )
{
if ( v7 == 119 )
{
v12 = (double)(int)field_counter();
if ( v12 < 0.0 )
v13 = sqrt(v12);
else
v13 = sqrt(v12);
if ( a2 % (int)v13 - (*(unsigned __int16 *)(v5 + 6) - 1) < 0 )
return 4294967291LL;
if ( (unsigned int)field_state(*(unsigned __int16 *)(v5 + 2), (unsigned int)a2 - v11) )
return 4294967290LL;
}
goto LABEL_15;
}
v43 = (double)a2;
v45 = (double)(*(unsigned __int16 *)(v5 + 6) - 1);
v35 = (double)(int)field_counter();
if ( v35 < 0.0 )
v36 = sqrt(v35);
else
v36 = sqrt(v35);
if ( v36 * v45 + v43 >= (double)(int)field_counter() )
return 4294967291LL;
v28 = (double)(int)field_counter();
if ( v28 < 0.0 )
v29 = sqrt(v28);
else
v29 = sqrt(v28);
if ( (unsigned int)field_state(*(unsigned __int16 *)(v5 + 2), (unsigned int)(int)(v29 * (double)v11 + v43)) )
return 4294967290LL;
LABEL_15:
v10 = *(unsigned __int16 *)(v5 + 6);
if ( v10 <= ++v11 )
goto LABEL_28;
}
v30 = (double)(int)field_counter();
if ( v30 < 0.0 )
v31 = sqrt(v30);
else
v31 = sqrt(v30);
v32 = (double)(a2 % (int)v31 + *(unsigned __int16 *)(v5 + 6) - 1);
v33 = (double)(int)field_counter();
if ( v33 < 0.0 )
v34 = sqrt(v33);
else
v34 = sqrt(v33);
if ( v32 >= v34 )
return 4294967291LL;
if ( (unsigned int)field_state(*(unsigned __int16 *)(v5 + 2), v11 + (unsigned int)a2) )
return 4294967290LL;
v10 = *(unsigned __int16 *)(v5 + 6);
++v11;
}
while ( v10 > v11 );
LABEL_28:
if ( !(_WORD)v10 )
{
LABEL_57:
*(_WORD *)(v5 + 4) = 1;
*(_BYTE *)(v5 + 8) = a3;
return 0LL;
}
v42 = a2;
v18 = a2;
v19 = 0;
v20 = 0LL;
while ( 1 )
{
if ( v20 )
{
v21 = malloc(0x10uLL);
v20[1] = v21;
v20 = v21;
if ( v7 != 110 )
goto LABEL_31;
}
else
{
v23 = malloc(0x10uLL);
*(_QWORD *)(v5 + 16) = v23;
v20 = v23;
if ( v7 != 110 )
{
LABEL_31:
switch ( v7 )
{
case 'e':
field_set(*(unsigned __int16 *)(v5 + 2), v18, a1);
*(_WORD *)v20 = v18;
break;
case 's':
v46 = (double)a2;
v47 = (double)v19;
v37 = (double)(int)field_counter();
if ( v37 < 0.0 )
v38 = sqrt(v37);
else
v38 = sqrt(v37);
field_set(*(unsigned __int16 *)(v5 + 2), (unsigned int)(int)(v38 * v47 + v46), a1);
v39 = (double)(int)field_counter();
if ( v39 < 0.0 )
v40 = sqrt(v39);
else
v40 = sqrt(v39);
*(_WORD *)v20 = (int)(v40 * v47 + v46);
break;
case 'w':
field_set(*(unsigned __int16 *)(v5 + 2), v42, a1);
*(_WORD *)v20 = v42;
break;
}
goto LABEL_35;
}
}
v44 = (double)v19;
v24 = (double)(int)field_counter();
if ( v24 < 0.0 )
v25 = sqrt(v24);
else
v25 = sqrt(v24);
field_set(*(unsigned __int16 *)(v5 + 2), (unsigned int)(int)((double)a2 - v25 * v44), a1);
v26 = (double)(int)field_counter();
if ( v26 < 0.0 )
v27 = sqrt(v26);
else
v27 = sqrt(v26);
*(_WORD *)v20 = (int)((double)a2 - v27 * v44);
LABEL_35:
v22 = *(unsigned __int16 *)(v5 + 6);
++v19;
--v42;
++v18;
*((_DWORD *)v20 + 1) = 1;
v20[1] = 0LL;
if ( v22 <= v19 )
goto LABEL_57;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 a1, unsigned __int16 a2, char a3)
{
__int64 v3; // rax
int v4; // edx
__int64 v5; // rbp
int v6; // er15
char v7; // bl
__int64 result; // rax
__int64 v9; // rcx
int v10; // eax
int v11; // er13
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // xmm0_8
unsigned int v18; // er14
int v19; // er13
_QWORD *v20; // r15
_QWORD *v21; // rax
int v22; // eax
_QWORD *v23; // rax
double v24; // xmm0_8
double v25; // xmm0_8
double v26; // xmm0_8
double v27; // xmm0_8
double v28; // xmm0_8
double v29; // xmm0_8
double v30; // xmm0_8
double v31; // xmm0_8
double v32; // r15
double v33; // xmm0_8
double v34; // xmm0_8
double v35; // xmm0_8
double v36; // xmm0_8
double v37; // xmm0_8
double v38; // xmm0_8
double v39; // xmm0_8
double v40; // xmm0_8
double v41; // [rsp+0h] [rbp-58h]
unsigned int v42; // [rsp+0h] [rbp-58h]
double v43; // [rsp+0h] [rbp-58h]
double v44; // [rsp+8h] [rbp-50h]
double v45; // [rsp+8h] [rbp-50h]
double v46; // [rsp+8h] [rbp-50h]
double v47; // [rsp+10h] [rbp-48h]

v3 = func1(a1);
if ( !v3 )
return 0xFFFFFFFFLL;
v5 = v3;
v6 = v4;
v7 = v4;
if ( (int)field_counter() <= a2 )
return 4294967294LL;
result = 4294967293LL;
if ( (unsigned __int8)(v6 - 101) <= 0x12u )
{
v9 = 279041LL;
if ( _bittest64(&v9, (unsigned int)(v6 - 101)) )
{
if ( *(_WORD *)(v5 + 4) )
return 4294967292LL;
v10 = *(unsigned __int16 *)(v5 + 6);
if ( !*(_WORD *)(v5 + 6) )
goto LABEL_57;
v11 = 0;
do
{
while ( 1 )
{
if ( v7 == 110 )
{
v41 = (double)(v10 - 1);
v14 = (double)(int)field_counter();
if ( v14 < 0.0 )
v15 = sqrt(v14);
else
v15 = sqrt(v14);
if ( (double)a2 - v15 * v41 < 0.0 )
return 4294967291LL;
v16 = (double)(int)field_counter();
if ( v16 < 0.0 )
v17 = sqrt(v16);
else
v17 = sqrt(v16);
if ( (unsigned int)field_state(
*(unsigned __int16 *)(v5 + 2),
(unsigned int)(int)((double)a2 - v17 * (double)v11)) )
return 4294967290LL;
goto LABEL_15;
}
if ( v7 == 101 )
break;
if ( v7 != 115 )
{
if ( v7 == 119 )
{
v12 = (double)(int)field_counter();
if ( v12 < 0.0 )
v13 = sqrt(v12);
else
v13 = sqrt(v12);
if ( a2 % (int)v13 - (*(unsigned __int16 *)(v5 + 6) - 1) < 0 )
return 4294967291LL;
if ( (unsigned int)field_state(*(unsigned __int16 *)(v5 + 2), (unsigned int)a2 - v11) )
return 4294967290LL;
}
goto LABEL_15;
}
v43 = (double)a2;
v45 = (double)(*(unsigned __int16 *)(v5 + 6) - 1);
v35 = (double)(int)field_counter();
if ( v35 < 0.0 )
v36 = sqrt(v35);
else
v36 = sqrt(v35);
if ( v36 * v45 + v43 >= (double)(int)field_counter() )
return 4294967291LL;
v28 = (double)(int)field_counter();
if ( v28 < 0.0 )
v29 = sqrt(v28);
else
v29 = sqrt(v28);
if ( (unsigned int)field_state(*(unsigned __int16 *)(v5 + 2), (unsigned int)(int)(v29 * (double)v11 + v43)) )
return 4294967290LL;
LABEL_15:
v10 = *(unsigned __int16 *)(v5 + 6);
if ( v10 <= ++v11 )
goto LABEL_28;
}
v30 = (double)(int)field_counter();
if ( v30 < 0.0 )
v31 = sqrt(v30);
else
v31 = sqrt(v30);
v32 = (double)(a2 % (int)v31 + *(unsigned __int16 *)(v5 + 6) - 1);
v33 = (double)(int)field_counter();
if ( v33 < 0.0 )
v34 = sqrt(v33);
else
v34 = sqrt(v33);
if ( v32 >= v34 )
return 4294967291LL;
if ( (unsigned int)field_state(*(unsigned __int16 *)(v5 + 2), v11 + (unsigned int)a2) )
return 4294967290LL;
v10 = *(unsigned __int16 *)(v5 + 6);
++v11;
}
while ( v10 > v11 );
LABEL_28:
if ( !(_WORD)v10 )
{
LABEL_57:
*(_WORD *)(v5 + 4) = 1;
*(_BYTE *)(v5 + 8) = a3;
return 0LL;
}
v42 = a2;
v18 = a2;
v19 = 0;
v20 = 0LL;
while ( 1 )
{
if ( v20 )
{
v21 = malloc(0x10uLL);
v20[1] = v21;
v20 = v21;
if ( v7 != 110 )
goto LABEL_31;
}
else
{
v23 = malloc(0x10uLL);
*(_QWORD *)(v5 + 16) = v23;
v20 = v23;
if ( v7 != 110 )
{
LABEL_31:
switch ( v7 )
{
case 'e':
field_set(*(unsigned __int16 *)(v5 + 2), v18, a1);
*(_WORD *)v20 = v18;
break;
case 's':
v46 = (double)a2;
v47 = (double)v19;
v37 = (double)(int)field_counter();
if ( v37 < 0.0 )
v38 = sqrt(v37);
else
v38 = sqrt(v37);
field_set(*(unsigned __int16 *)(v5 + 2), (unsigned int)(int)(v38 * v47 + v46), a1);
v39 = (double)(int)field_counter();
if ( v39 < 0.0 )
v40 = sqrt(v39);
else
v40 = sqrt(v39);
*(_WORD *)v20 = (int)(v40 * v47 + v46);
break;
case 'w':
field_set(*(unsigned __int16 *)(v5 + 2), v42, a1);
*(_WORD *)v20 = v42;
break;
}
goto LABEL_35;
}
}
v44 = (double)v19;
v24 = (double)(int)field_counter();
if ( v24 < 0.0 )
v25 = sqrt(v24);
else
v25 = sqrt(v24);
field_set(*(unsigned __int16 *)(v5 + 2), (unsigned int)(int)((double)a2 - v25 * v44), a1);
v26 = (double)(int)field_counter();
if ( v26 < 0.0 )
v27 = sqrt(v26);
else
v27 = sqrt(v26);
*(_WORD *)v20 = (int)((double)a2 - v27 * v44);
LABEL_35:
v22 = *(unsigned __int16 *)(v5 + 6);
++v19;
--v42;
++v18;
*((_DWORD *)v20 + 1) = 1;
v20[1] = 0LL;
if ( v22 <= v19 )
goto LABEL_57;
}
}
}
return result;
}

original_code:
int ship_set(unsigned short ship_id, unsigned short coordinate, char direction){
 SHIP *tmp_ship = ((void *)0);
 SHIP_COORDINATES *tmp_coordinate = ((void *)0);
 int i;
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if((coordinate > (field_counter()-1))) return -2;
 if((direction != 'n') && (direction != 'e') && (direction != 's') && (direction != 'w')) return -3;
 if(tmp_ship->active != 0) return -4;
 for(i=0;i<(tmp_ship->elements);i++) {
  if((direction == 'n') && ((coordinate-((tmp_ship->elements)-1)*sqrt(field_counter())) < 0)) {return -5;}
  else if((direction == 'e') && (((coordinate%(int)sqrt(field_counter())) + ((tmp_ship->elements)-1)) >= sqrt(field_counter()))) {return -5;}
  else if((direction == 's') && ((coordinate+((tmp_ship->elements)-1)*sqrt(field_counter())) >= field_counter())) {return -5;}
  else if((direction == 'w') && (((coordinate%(int)sqrt(field_counter())) - ((tmp_ship->elements)-1)) < 0)) {return -5;}
  if((direction == 'n') && (field_state(tmp_ship->owner, coordinate-i*sqrt(field_counter())) != 0)) {return -6;}
  else if((direction == 'e') && (field_state(tmp_ship->owner, coordinate+i) != 0)) {return -6;}
  else if((direction == 's') && (field_state(tmp_ship->owner, coordinate+i*sqrt(field_counter())) != 0)) {return -6;}
  else if((direction == 'w') && (field_state(tmp_ship->owner, coordinate-i) != 0)) {return -6;}
 }
 for(i=0;i<(tmp_ship->elements);i++){
  if(tmp_coordinate == ((void *)0)) {
   tmp_coordinate = malloc(sizeof(SHIP_COORDINATES));
   tmp_ship->coordinates = tmp_coordinate;
  } else {
   tmp_coordinate->next = malloc(sizeof(SHIP_COORDINATES));
   tmp_coordinate = tmp_coordinate->next;
  }
  if(direction == 'n') {
   field_set(tmp_ship->owner, coordinate-i*sqrt(field_counter()), ship_id);
   tmp_coordinate->coordinate = coordinate-i*sqrt(field_counter());
  } else if(direction == 'e') {
   field_set(tmp_ship->owner, coordinate+i, ship_id);
   tmp_coordinate->coordinate = coordinate+i;
  } else if(direction == 's') {
   field_set(tmp_ship->owner, coordinate+i*sqrt(field_counter()), ship_id);
   tmp_coordinate->coordinate = coordinate+i*sqrt(field_counter());
  } else if(direction == 'w') {
   field_set(tmp_ship->owner, coordinate-i, ship_id);
   tmp_coordinate->coordinate = coordinate-i;
  }
  tmp_coordinate->state = 1;
  tmp_coordinate->next = ((void *)0);
 }
 tmp_ship->active = 1;
 tmp_ship->direction = direction;
 return 0;
}

canonical_original_code:
int ship_set(unsigned short ship_id, unsigned short coordinate, char direction){
 struct _ship *tmp_ship = ((void *)0);
 struct _ship_coordinates *tmp_coordinate = ((void *)0);
 int i;
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if((coordinate > (field_counter()-1))) return -2;
 if((direction != 'n') && (direction != 'e') && (direction != 's') && (direction != 'w')) return -3;
 if(tmp_ship->active != 0) return -4;
 for(i=0;i<(tmp_ship->elements);i++) {
  if((direction == 'n') && ((coordinate-((tmp_ship->elements)-1)*sqrt(field_counter())) < 0)) {return -5;}
  else if((direction == 'e') && (((coordinate%(int)sqrt(field_counter())) + ((tmp_ship->elements)-1)) >= sqrt(field_counter()))) {return -5;}
  else if((direction == 's') && ((coordinate+((tmp_ship->elements)-1)*sqrt(field_counter())) >= field_counter())) {return -5;}
  else if((direction == 'w') && (((coordinate%(int)sqrt(field_counter())) - ((tmp_ship->elements)-1)) < 0)) {return -5;}
  if((direction == 'n') && (field_state(tmp_ship->owner, coordinate-i*sqrt(field_counter())) != 0)) {return -6;}
  else if((direction == 'e') && (field_state(tmp_ship->owner, coordinate+i) != 0)) {return -6;}
  else if((direction == 's') && (field_state(tmp_ship->owner, coordinate+i*sqrt(field_counter())) != 0)) {return -6;}
  else if((direction == 'w') && (field_state(tmp_ship->owner, coordinate-i) != 0)) {return -6;}
 }
 for(i=0;i<(tmp_ship->elements);i++){
  if(tmp_coordinate == ((void *)0)) {
   tmp_coordinate = malloc(sizeof(SHIP_COORDINATES));
   tmp_ship->coordinates = tmp_coordinate;
  } else {
   tmp_coordinate->next = malloc(sizeof(SHIP_COORDINATES));
   tmp_coordinate = tmp_coordinate->next;
  }
  if(direction == 'n') {
   field_set(tmp_ship->owner, coordinate-i*sqrt(field_counter()), ship_id);
   tmp_coordinate->coordinate = coordinate-i*sqrt(field_counter());
  } else if(direction == 'e') {
   field_set(tmp_ship->owner, coordinate+i, ship_id);
   tmp_coordinate->coordinate = coordinate+i;
  } else if(direction == 's') {
   field_set(tmp_ship->owner, coordinate+i*sqrt(field_counter()), ship_id);
   tmp_coordinate->coordinate = coordinate+i*sqrt(field_counter());
  } else if(direction == 'w') {
   field_set(tmp_ship->owner, coordinate-i, ship_id);
   tmp_coordinate->coordinate = coordinate-i;
  }
  tmp_coordinate->state = 1;
  tmp_coordinate->next = ((void *)0);
 }
 tmp_ship->active = 1;
 tmp_ship->direction = direction;
 return 0;
}

variable_types:
coordinate
unsigned short

variable_types: direction char

variable_types: struct _ship_coordinates { unsigned short coordinate; int state; struct _ship_coordinates *next; } *


decompiled_code:
__int64 __fastcall ship_start(__int16 a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = ship_address(a1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = -2;
if ( *(_WORD *)(v1 + 4) )
v2 = **(unsigned __int16 **)(v1 + 16);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = func1(a1);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = -2;
if ( *(_WORD *)(v1 + 4) )
v2 = **(unsigned __int16 **)(v1 + 16);
return v2;
}

original_code:
unsigned short ship_start(unsigned short ship_id){
 SHIP *tmp_ship = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return -2;
 return tmp_ship->coordinates->coordinate;
}

canonical_original_code:
unsigned short ship_start(unsigned short ship_id){
 struct _ship *tmp_ship = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return -2;
 return tmp_ship->coordinates->coordinate;
}


decompiled_code:
__int64 __fastcall ship_state(__int16 a1, __int16 a2)
{
__int64 v2; // rax
unsigned int v3; // er8
__int64 v4; // rax

v2 = ship_address(a1);
if ( !v2 )
return (unsigned int)-1;
v3 = 0;
if ( !*(_WORD *)(v2 + 4) )
return v3;
v4 = *(_QWORD *)(v2 + 16);
if ( v4 )
{
while ( *(_WORD *)v4 != a2 )
{
v4 = *(_QWORD *)(v4 + 8);
if ( !v4 )
return 4294967294LL;
}
return *(unsigned int *)(v4 + 4);
}
return 4294967294LL;
}

original_code:
int ship_state(unsigned short ship_id, unsigned short coordinate){
 SHIP *tmp_ship = ((void *)0);
 SHIP_COORDINATES *tmp_coordinate = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return 0;
 tmp_coordinate = tmp_ship->coordinates;
 while(tmp_coordinate != ((void *)0)) {
  if(tmp_coordinate->coordinate == coordinate) return tmp_coordinate->state;
  tmp_coordinate = tmp_coordinate->next;
 }
 return -2;
}

canonical_original_code:
int ship_state(unsigned short ship_id, unsigned short coordinate){
 struct _ship *tmp_ship = ((void *)0);
 struct _ship_coordinates *tmp_coordinate = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return 0;
 tmp_coordinate = tmp_ship->coordinates;
 while(tmp_coordinate != ((void *)0)) {
  if(tmp_coordinate->coordinate == coordinate) return tmp_coordinate->state;
  tmp_coordinate = tmp_coordinate->next;
 }
 return -2;
}


original_code:
int ship_change(unsigned short ship_id, unsigned short coordinate, int state){
 SHIP *tmp_ship = ((void *)0);
 SHIP_COORDINATES *tmp_coordinate = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return -2;
 if((state != 2) && (state != 3)) return -3;
 tmp_coordinate = tmp_ship->coordinates;
 while(tmp_coordinate != ((void *)0)) {
  if(tmp_coordinate->coordinate == coordinate) {
   tmp_coordinate->state = state;
   return 0;
  }
  tmp_coordinate = tmp_coordinate->next;
 }
 return -4;
}

canonical_original_code:
int ship_change(unsigned short ship_id, unsigned short coordinate, int state){
 struct _ship *tmp_ship = ((void *)0);
 struct _ship_coordinates *tmp_coordinate = ((void *)0);
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return -2;
 if((state != 2) && (state != 3)) return -3;
 tmp_coordinate = tmp_ship->coordinates;
 while(tmp_coordinate != ((void *)0)) {
  if(tmp_coordinate->coordinate == coordinate) {
   tmp_coordinate->state = state;
   return 0;
  }
  tmp_coordinate = tmp_coordinate->next;
 }
 return -4;
}


original_code:
int ship_sunk(unsigned short ship_id) {
 SHIP *tmp_ship = ((void *)0);
 SHIP_COORDINATES *tmp_coordinate = ((void *)0);
 int i=0;
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return -2;
 tmp_coordinate = tmp_ship->coordinates;
 while(tmp_coordinate != ((void *)0)) {
  if(tmp_coordinate->state == 2) i++;
  tmp_coordinate = tmp_coordinate->next;
 }
 if(tmp_ship->elements == i) {
  tmp_coordinate = tmp_ship->coordinates;
  for(i=0; i<tmp_ship->elements; i++) {
   tmp_coordinate->state = 3;
   tmp_coordinate = tmp_coordinate->next;
  }
  return 0;
 }
 return -3;
}

canonical_original_code:
int ship_sunk(unsigned short ship_id) {
 struct _ship *tmp_ship = ((void *)0);
 struct _ship_coordinates *tmp_coordinate = ((void *)0);
 int i = 0;
 tmp_ship = ship_address(ship_id);
 if(tmp_ship == ((void *)0)) return -1;
 if(tmp_ship->active == 0) return -2;
 tmp_coordinate = tmp_ship->coordinates;
 while(tmp_coordinate != ((void *)0)) {
  if(tmp_coordinate->state == 2) i++;
  tmp_coordinate = tmp_coordinate->next;
 }
 if(tmp_ship->elements == i) {
  tmp_coordinate = tmp_ship->coordinates;
  for(i=0; i<tmp_ship->elements; i++) {
   tmp_coordinate->state = 3;
   tmp_coordinate = tmp_coordinate->next;
  }
  return 0;
 }
 return -3;
}


shoot

decompiled_code:
__int64 __fastcall shoot(__int64 a1, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er13
int v4; // er12
__int64 result; // rax

v2 = field_state(a1, a2);
v3 = (unsigned __int16)v2;
v4 = v2;
if ( (int)ship_state((unsigned __int16)v2, a2) <= 0 )
return (unsigned int)-1;
if ( (unsigned int)ship_state(v3, a2) == 2 )
return (unsigned int)-2;
if ( (unsigned int)ship_state(v3, a2) == 3 )
return (unsigned int)-3;
if ( v4 )
{
if ( v4 == 1 )
return (unsigned int)-4;
if ( v4 <= 9 )
return 0;
ship_change(v3, a2, 2LL);
ship_sunk(v3);
result = 0LL;
}
else
{
field_set((unsigned int)a1, a2, 1LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int16 a2)
{
int v2; // eax
unsigned int v3; // er13
int v4; // er12
__int64 result; // rax

v2 = field_state(a1, a2);
v3 = (unsigned __int16)v2;
v4 = v2;
if ( (int)ship_state((unsigned __int16)v2, a2) <= 0 )
return (unsigned int)-1;
if ( (unsigned int)ship_state(v3, a2) == 2 )
return (unsigned int)-2;
if ( (unsigned int)ship_state(v3, a2) == 3 )
return (unsigned int)-3;
if ( v4 )
{
if ( v4 == 1 )
return (unsigned int)-4;
if ( v4 <= 9 )
return 0;
ship_change(v3, a2, 2LL);
ship_sunk(v3);
result = 0LL;
}
else
{
field_set((unsigned int)a1, a2, 1LL);
result = 0LL;
}
return result;
}

original_code:
int shoot(int field, unsigned short coordinate) {
 int f_state;
 f_state = field_state(field, coordinate);
 if(ship_state(f_state, coordinate) <= 0) {return -1;}
 else if(ship_state(f_state, coordinate) == 2) {return -2;}
 else if(ship_state(f_state, coordinate) == 3) {return -3;}
 if(f_state == 0) {
  field_set(field, coordinate, 1);
 } else if(f_state == 1) {
  return -4;
 } else if(f_state >= 10) {
  ship_change(f_state, coordinate, 2);
  ship_sunk(f_state);
 }
 return 0;
}