decompiled_code:
__int64 __fastcall client_destroy(void *ptr)
{
unsigned int v1; // er12

v1 = client_remove_isra_0(*(_DWORD *)ptr);
free(ptr);
--current_clients;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
unsigned int v1; // er12

v1 = func1(*(_DWORD *)ptr);
free(ptr);
--current_clients;
return v1;
}

original_code:
int
client_destroy(client_t * client)
{
 int ret = client_remove(client);
 ((void) sizeof ((client != ((void *)0)) ? 1 : 0), __extension__ ({ if (client != ((void *)0)) ; else __assert_fail ("client != NULL", "./client/client.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 free(client);
 current_clients--;
 return ret;
}

canonical_original_code:
int client_destroy(struct client_t *client)
{
 int ret = client_remove(client);
 ((void) sizeof ((client != ((void *)0)) ? 1 : 0), __extension__ ({ if (client != ((void *)0)) ; else __assert_fail ("client != NULL", "./client/client.c", 135, __extension__ __PRETTY_FUNCTION__); }));
 free(client);
 current_clients--;
 return ret;
}


repo: agustingianni/StreamingProject

decompiled_code:
__int64 __fastcall stream_create(_QWORD *a1, const char *a2)
{
unsigned int v2; // er12
_QWORD *v3; // r14
void *v4; // rbx
char *v5; // rax
int v6; // edi
__off_t v7; // rax
int v9; // edi
int v10; // edi
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v2 = open(a2, 0);
if ( v2 == -1 )
{
perror("stream_create():");
}
else
{
v3 = malloc(0x20uLL);
if ( v3 )
{
if ( fstat(v2, &v11) == -1 || (v4 = mmap(0LL, v11.st_size, 1, 2, v2, 0LL), v4 == (void *)-1LL) )
{
perror("stream_create():");
free(v3);
*a1 = 0LL;
v9 = v2;
v2 = -1;
close(v9);
}
else
{
v5 = strdup(a2);
*a1 = v3;
v6 = v2;
v2 = 0;
*v3 = v5;
v7 = v11.st_size;
*((_DWORD *)v3 + 2) = 0;
v3[2] = v7;
v3[3] = v4;
close(v6);
}
}
else
{
perror("stream_create():");
*a1 = 0LL;
v10 = v2;
v2 = -1;
close(v10);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const char *a2)
{
unsigned int v2; // er12
_QWORD *v3; // r14
void *v4; // rbx
char *v5; // rax
int v6; // edi
__off_t v7; // rax
int v9; // edi
int v10; // edi
struct stat v11; // [rsp+0h] [rbp-B8h] BYREF

v2 = open(a2, 0);
if ( v2 == -1 )
{
perror("stream_create():");
}
else
{
v3 = malloc(0x20uLL);
if ( v3 )
{
if ( fstat(v2, &v11) == -1 || (v4 = mmap(0LL, v11.st_size, 1, 2, v2, 0LL), v4 == (void *)-1LL) )
{
perror("stream_create():");
free(v3);
*a1 = 0LL;
v9 = v2;
v2 = -1;
close(v9);
}
else
{
v5 = strdup(a2);
*a1 = v3;
v6 = v2;
v2 = 0;
*v3 = v5;
v7 = v11.st_size;
*((_DWORD *)v3 + 2) = 0;
v3[2] = v7;
v3[3] = v4;
close(v6);
}
}
else
{
perror("stream_create():");
*a1 = 0LL;
v10 = v2;
v2 = -1;
close(v10);
}
}
return v2;
}

original_code:
int
stream_create(stream_t **stream, const char *filename)
{
 int fd;
 stream_t *tmp;
 if((fd = open(filename, 00)) == -1)
 {
  perror("stream_create():");
  return -1;
 }
 tmp = (stream_t *) malloc(sizeof(stream_t));
 if(!tmp)
 {
  perror("stream_create():");
  *stream = ((void *)0);
  close(fd);
  return -1;
 }
 struct stat sb;
 if (fstat(fd, &sb) == -1)
 {
  perror("stream_create():");
  free(tmp);
  *stream = ((void *)0);
  close(fd);
  return -1;
 }
 void *addr;
 addr = mmap(((void *)0), sb.st_size, 0x1, 0x02, fd, 0);
 if(addr == ((void *) -1))
 {
  perror("stream_create():");
  free(tmp);
  *stream = ((void *)0);
  close(fd);
  return -1;
 }
 tmp->filename = strdup(filename);
 tmp->id = 0;
 tmp->size = sb.st_size;
 tmp->bytes = (char *) addr;
 *stream = tmp;
 close(fd);
 return 0;
}

canonical_original_code:
int stream_create(struct stream_t **stream, char *filename)
{
 int fd;
 struct stream_t *tmp;
 if((fd = open(filename, 00)) == -1)
 {
  perror("stream_create():");
  return -1;
 }
 tmp = (struct stream_t *) malloc(sizeof(stream_t));
 if(!tmp)
 {
  perror("stream_create():");
  *stream = ((void *)0);
  close(fd);
  return -1;
 }
 struct stat sb;
 if (fstat(fd, &sb) == -1)
 {
  perror("stream_create():");
  free(tmp);
  *stream = ((void *)0);
  close(fd);
  return -1;
 }
 void *addr;
 addr = mmap(((void *)0), sb.st_size, 0x1, 0x02, fd, 0);
 if(addr == ((void *) -1))
 {
  perror("stream_create():");
  free(tmp);
  *stream = ((void *)0);
  close(fd);
  return -1;
 }
 tmp->filename = strdup(filename);
 tmp->id = 0;
 tmp->size = sb.st_size;
 tmp->bytes = (char *) addr;
 *stream = tmp;
 close(fd);
 return 0;
}

variable_types: struct stream_t { char *filename; int id; unsigned long size; char *bytes; } **

variable_types:
filename
char *

variable_types: fd int

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

variable_types:
addr
void *

return_type: int

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


decompiled_code:
__int64 __fastcall stream_destroy(void *ptr)
{
__int64 result; // rax

if ( !ptr )
_assert_fail("stream != NULL", "./stream/stream.c", 0x4Fu, "stream_destroy");
if ( munmap(*((void **)ptr + 3), *((_QWORD *)ptr + 2)) == -1 )
{
perror("stream_destroy():");
result = 0xFFFFFFFFLL;
}
else
{
free(*(void **)ptr);
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
__int64 result; // rax

if ( !ptr )
_assert_fail("stream != NULL", "./stream/stream.c", 0x4Fu, "stream_destroy");
if ( munmap(*((void **)ptr + 3), *((_QWORD *)ptr + 2)) == -1 )
{
perror("stream_destroy():");
result = 0xFFFFFFFFLL;
}
else
{
free(*(void **)ptr);
free(ptr);
result = 0LL;
}
return result;
}

original_code:
int
stream_destroy(stream_t *stream)
{
 ((void) sizeof ((stream != ((void *)0)) ? 1 : 0), __extension__ ({ if (stream != ((void *)0)) ; else __assert_fail ("stream != NULL", "./stream/stream.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 if(munmap(stream->bytes, stream->size) == -1)
 {
  perror("stream_destroy():");
  return -1;
 }
 free(stream->filename);
 free(stream);
 return 0;
}

canonical_original_code:
int stream_destroy(struct stream_t *stream)
{
 ((void) sizeof ((stream != ((void *)0)) ? 1 : 0), __extension__ ({ if (stream != ((void *)0)) ; else __assert_fail ("stream != NULL", "./stream/stream.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 if(munmap(stream->bytes, stream->size) == -1)
 {
  perror("stream_destroy():");
  return -1;
 }
 free(stream->filename);
 free(stream);
 return 0;
}

variable_types: struct stream_t { char *filename; int id; unsigned long size; char *bytes; } *


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

if ( !a4 )
_assert_fail("buffer != NULL", "./stream/stream.c", 0x60u, "stream_read");
result = a3;
if ( !a3 )
_assert_fail("size != 0", "./stream/stream.c", 0x61u, "stream_read");
if ( (unsigned __int64)(a2 + a3) > *(_QWORD *)(a1 + 16) )
_assert_fail("offset+size <= stream->size", "./stream/stream.c", 0x62u, "stream_read");
*a4 = *(_QWORD *)(a1 + 24) + a2;
return result;
}

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

if ( !a4 )
_assert_fail("buffer != NULL", "./stream/stream.c", 0x60u, "stream_read");
result = a3;
if ( !a3 )
_assert_fail("size != 0", "./stream/stream.c", 0x61u, "stream_read");
if ( (unsigned __int64)(a2 + a3) > *(_QWORD *)(a1 + 16) )
_assert_fail("offset+size <= stream->size", "./stream/stream.c", 0x62u, "stream_read");
*a4 = *(_QWORD *)(a1 + 24) + a2;
return result;
}

original_code:
int
stream_read(stream_t *stream, off_t offset, size_t size, char **buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "./stream/stream.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "./stream/stream.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((offset+size <= stream->size) ? 1 : 0), __extension__ ({ if (offset+size <= stream->size) ; else __assert_fail ("offset+size <= stream->size", "./stream/stream.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 *buffer = stream->bytes + offset;
 return (offset + size <= stream->size) ? size : stream->size - offset;
}

canonical_original_code:
int stream_read(struct stream_t *stream, long offset, unsigned long size, char **buffer)
{
 ((void) sizeof ((buffer != ((void *)0)) ? 1 : 0), __extension__ ({ if (buffer != ((void *)0)) ; else __assert_fail ("buffer != NULL", "./stream/stream.c", 96, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((size != 0) ? 1 : 0), __extension__ ({ if (size != 0) ; else __assert_fail ("size != 0", "./stream/stream.c", 97, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((offset+size <= stream->size) ? 1 : 0), __extension__ ({ if (offset+size <= stream->size) ; else __assert_fail ("offset+size <= stream->size", "./stream/stream.c", 98, __extension__ __PRETTY_FUNCTION__); }));
 *buffer = stream->bytes + offset;
 return (offset + size <= stream->size) ? size : stream->size - offset;
}

variable_types: offset long

variable_types:
size
unsigned long

variable_types:
buffer
char **

user_defined_types: struct stream_t { char *filename; int id; unsigned long size; char *bytes; }


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

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

original_code:
int go_controller_init() {
  return 0;
}

canonical_original_code:
int go_controller_init() {
  return 0;
}


decompiled_code:
_DWORD *go_controller_launch_engine()
{
_DWORD *result; // rax
int *v1; // rbx
char *v2; // rax
int *v3; // rbx
char *v4; // rax
int v5; // [rsp+0h] [rbp-18h] BYREF
int fd; // [rsp+4h] [rbp-14h]
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pipe(&v5) || pipe(pipedes) )
{
v1 = __errno_location();
v2 = strerror(*v1);
printf("pipe() failed with error %i: %s\n", (unsigned int)*v1, v2);
result = 0LL;
}
else
{
if ( !fork() )
{
close(0);
close(1);
close(2);
dup2(pipedes[0], 0);
dup2(fd, 1);
dup2(fd, 2);
close(pipedes[1]);
close(pipedes[0]);
close(fd);
close(v5);
if ( execl("gnugo", "/usr/bin/gnugo", "--mode", "gtp", 0LL) == -1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("gnugo has finished with err: %i: %i: %s\n", 0xFFFFFFFFLL, (unsigned int)*v3, v4);
}
exit(1);
}
close(pipedes[0]);
close(fd);
result = malloc(8uLL);
*result = pipedes[1];
result[1] = v5;
}
return result;
}

canonical_decompiled_code:
_DWORD *func8()
{
_DWORD *result; // rax
int *v1; // rbx
char *v2; // rax
int *v3; // rbx
char *v4; // rax
int v5; // [rsp+0h] [rbp-18h] BYREF
int fd; // [rsp+4h] [rbp-14h]
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

if ( pipe(&v5) || pipe(pipedes) )
{
v1 = __errno_location();
v2 = strerror(*v1);
printf("pipe() failed with error %i: %s\n", (unsigned int)*v1, v2);
result = 0LL;
}
else
{
if ( !fork() )
{
close(0);
close(1);
close(2);
dup2(pipedes[0], 0);
dup2(fd, 1);
dup2(fd, 2);
close(pipedes[1]);
close(pipedes[0]);
close(fd);
close(v5);
if ( execl("gnugo", "/usr/bin/gnugo", "--mode", "gtp", 0LL) == -1 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("gnugo has finished with err: %i: %i: %s\n", 0xFFFFFFFFLL, (unsigned int)*v3, v4);
}
exit(1);
}
close(pipedes[0]);
close(fd);
result = malloc(8uLL);
*result = pipedes[1];
result[1] = v5;
}
return result;
}

original_code:
go_controller_context* go_controller_launch_engine(const go_controller_setup* const setup) {
  int r_pipes[2];
  int w_pipes[2];
  int err;
  pid_t pid;
  go_controller_context* context = ((void *)0);
  err = pipe(r_pipes);
  if (err != 0) {
    printf("pipe() failed with error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return ((void *)0);
  }
  err = pipe(w_pipes);
  if (err != 0) {
    printf("pipe() failed with error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return ((void *)0);
  }
  pid = fork();
  if (pid == 0) {
    close(0);
    close(1);
    close(2);
    dup2(w_pipes[0], 0);
    dup2(r_pipes[1], 1);
    dup2(r_pipes[1], 2);
    close(w_pipes[1]);
    close(w_pipes[0]);
    close(r_pipes[1]);
    close(r_pipes[0]);
    int err = execl("gnugo", "/usr/bin/gnugo", "--mode", "gtp", ((void *)0));
    if (err == -1)
      printf("gnugo has finished with err: %i: %i: %s\n", err, (*__errno_location ()), strerror((*__errno_location ())));
    exit(1);
  }
  close(w_pipes[0]);
  close(r_pipes[1]);
  context = malloc(sizeof(go_controller_context));
  context->input_handle = w_pipes[1];
  context->output_handle = r_pipes[0];
  return context;
}

canonical_original_code:
struct go_controller_context *go_controller_launch_engine(struct go_controller_setup *setup) {
  int r_pipes[2];
  int w_pipes[2];
  int err;
  int pid;
  struct go_controller_context *context = ((void *)0);
  err = pipe(r_pipes);
  if (err != 0) {
    printf("pipe() failed with error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return ((void *)0);
  }
  err = pipe(w_pipes);
  if (err != 0) {
    printf("pipe() failed with error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return ((void *)0);
  }
  pid = fork();
  if (pid == 0) {
    close(0);
    close(1);
    close(2);
    dup2(w_pipes[0], 0);
    dup2(r_pipes[1], 1);
    dup2(r_pipes[1], 2);
    close(w_pipes[1]);
    close(w_pipes[0]);
    close(r_pipes[1]);
    close(r_pipes[0]);
    int err = execl("gnugo", "/usr/bin/gnugo", "--mode", "gtp", ((void *)0));
    if (err == -1)
      printf("gnugo has finished with err: %i: %i: %s\n", err, (*__errno_location ()), strerror((*__errno_location ())));
    exit(1);
  }
  close(w_pipes[0]);
  close(r_pipes[1]);
  context = malloc(sizeof(go_controller_context));
  context->input_handle = w_pipes[1];
  context->output_handle = r_pipes[0];
  return context;
}

variable_types: struct go_controller_setup { int level; } *

variable_types: err int

variable_types: pid int

variable_types: struct go_controller_context { int input_handle; int output_handle; } *


decompiled_code:
__int64 go_controller_close()
{
return go_controller_init();
}

canonical_decompiled_code:
__int64 func9()
{
return func7();
}

original_code:
int go_controller_close() {
  return 0;
}

canonical_original_code:
int go_controller_close() {
  return 0;
}


decompiled_code:
__int64 __fastcall send_command(char *src, int *a2)
{
int v2; // eax
__int64 v3; // r14
__int64 v4; // rbx
void *v5; // rsp
size_t v6; // rax
ssize_t v7; // r8
__int64 result; // rax
int *v9; // rbx
char *v10; // rax
char v11[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = strlen(src);
v3 = v2;
v4 = v2 + 1;
v5 = alloca(v2 + 2);
strncpy(v11, src, v2);
v11[v3] = 10;
v11[v4] = 0;
v6 = strlen(v11);
v7 = write(*a2, v11, v6);
result = 0LL;
if ( v7 < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("write failed with %i: %s\n", (unsigned int)*v9, v10);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *src, int *a2)
{
int v2; // eax
__int64 v3; // r14
__int64 v4; // rbx
void *v5; // rsp
size_t v6; // rax
ssize_t v7; // r8
__int64 result; // rax
int *v9; // rbx
char *v10; // rax
char v11[32]; // [rsp+0h] [rbp-20h] BYREF

v2 = strlen(src);
v3 = v2;
v4 = v2 + 1;
v5 = alloca(v2 + 2);
strncpy(v11, src, v2);
v11[v3] = 10;
v11[v4] = 0;
v6 = strlen(v11);
v7 = write(*a2, v11, v6);
result = 0LL;
if ( v7 < 0 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf("write failed with %i: %s\n", (unsigned int)*v9, v10);
result = 1LL;
}
return result;
}

original_code:
int send_command(char* command, go_controller_context* context) {
  ssize_t wc;
  int len;
  len = strlen(command);
  char cmd[len + 2];
  strncpy(cmd, command, len);
  cmd[len] = '\n';
  cmd[len + 1] = '\0';
  wc = write(context->input_handle, cmd, strlen(cmd));
  if (wc < 0) {
    printf("write failed with %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return 1;
  }
  return 0;
}

canonical_original_code:
int send_command(char *command, struct go_controller_context *context) {
  long wc;
  int len;
  len = strlen(command);
  char cmd[-1];
  strncpy(cmd, command, len);
  cmd[len] = '\n';
  cmd[len + 1] = '\0';
  wc = write(context->input_handle, cmd, strlen(cmd));
  if (wc < 0) {
    printf("write failed with %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return 1;
  }
  return 0;
}

variable_types:
command
char *

variable_types: wc long

variable_types: len int

variable_types:
cmd
char [-1]

user_defined_types: struct go_controller_context { int input_handle; int output_handle; }


decompiled_code:
__int64 __fastcall go_controller_set_board_size(unsigned int a1, int *a2)
{
__int64 result; // rax
char v3[136]; // [rsp+0h] [rbp-88h] BYREF

if ( a1 - 3 > 0x16 )
{
printf("Invalid size. Must be between %i and %i\n", 3LL, 25LL);
result = 1LL;
}
else
{
sprintf(v3, "boardsize %i", a1);
result = send_command(v3, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, int *a2)
{
__int64 result; // rax
char v3[136]; // [rsp+0h] [rbp-88h] BYREF

if ( a1 - 3 > 0x16 )
{
printf("Invalid size. Must be between %i and %i\n", 3LL, 25LL);
result = 1LL;
}
else
{
sprintf(v3, "boardsize %i", a1);
result = func10(v3, a2);
}
return result;
}

original_code:
int go_controller_set_board_size(int size, go_controller_context* context) {
  const int min_size = 3;
  const int max_size = 25;
  const size_t buf_size = 128;
  char cmd[buf_size];
  int err;
  if (size < 3 || size > 25) {
    printf("Invalid size. Must be between %i and %i\n", min_size, max_size);
    return 1;
  }
  sprintf(cmd, "boardsize %i", size);
  err = send_command(cmd, context);
  return err;
}

canonical_original_code:
int go_controller_set_board_size(int size, struct go_controller_context *context) {
  int min_size = 3;
  int max_size = 25;
  unsigned long buf_size = 128;
  char cmd[-1];
  int err;
  if (size < 3 || size > 25) {
    printf("Invalid size. Must be between %i and %i\n", min_size, max_size);
    return 1;
  }
  sprintf(cmd, "boardsize %i", size);
  err = send_command(cmd, context);
  return err;
}

variable_types: size int


decompiled_code:
__int64 __fastcall go_controller_quit_engine(void *ptr)
{
unsigned int v1; // er12

v1 = send_command("quit", (int *)ptr);
close(*(_DWORD *)ptr);
close(*((_DWORD *)ptr + 1));
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(void *ptr)
{
unsigned int v1; // er12

v1 = func10("quit", (int *)ptr);
close(*(_DWORD *)ptr);
close(*((_DWORD *)ptr + 1));
free(ptr);
return v1;
}

original_code:
int go_controller_quit_engine(go_controller_context* context) {
  int err = send_command("quit", context);
  close(context->input_handle);
  close(context->output_handle);
  free(context);
  return err;
}

canonical_original_code:
int go_controller_quit_engine(struct go_controller_context *context) {
  int err = send_command("quit", context);
  close(context->input_handle);
  close(context->output_handle);
  free(context);
  return err;
}


decompiled_code:
__int64 __fastcall wait_for_activity(int a1)
{
int v1; // er12
int *v3; // rbx
char *v4; // rax
fd_set v5; // [rsp+0h] [rbp-98h] BYREF

memset(&v5, 0, sizeof(v5));
v5.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v1 = select(a1 + 1, &v5, 0LL, 0LL, 0LL);
if ( v1 < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("Error occurred: %i: %s\n", (unsigned int)*v3, v4);
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
int v1; // er12
int *v3; // rbx
char *v4; // rax
fd_set v5; // [rsp+0h] [rbp-98h] BYREF

memset(&v5, 0, sizeof(v5));
v5.fds_bits[a1 / 64] |= 1LL << (a1 % 64);
v1 = select(a1 + 1, &v5, 0LL, 0LL, 0LL);
if ( v1 < 0 )
{
v3 = __errno_location();
v4 = strerror(*v3);
printf("Error occurred: %i: %s\n", (unsigned int)*v3, v4);
}
return (unsigned int)v1;
}

original_code:
int wait_for_activity(int read_handle) {
  fd_set read_fds;
  int err;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((read_handle) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((read_handle) % (8 * (int) sizeof (__fd_mask)))))));
  err = select(read_handle + 1, &read_fds, ((void *)0), ((void *)0), ((void *)0));
  if (err < 0) {
    printf("Error occurred: %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  }
  return err;
}

canonical_original_code:
int wait_for_activity(int read_handle) {
  struct fd_set read_fds;
  int err;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((read_handle) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((read_handle) % (8 * (int) sizeof (__fd_mask)))))));
  err = select(read_handle + 1, &read_fds, ((void *)0), ((void *)0), ((void *)0));
  if (err < 0) {
    printf("Error occurred: %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  }
  return err;
}


decompiled_code:
__int64 __fastcall get_response(char *a1, char *a2, size_t a3, int *a4)
{
unsigned int v6; // er12
__int64 result; // rax
size_t v8; // rax
int *v9; // rbx
char *v10; // rax

v6 = send_command(a1, a4);
if ( v6 )
return v6;
LODWORD(result) = wait_for_activity(a4[1]);
if ( (int)result < 0LL )
return (unsigned int)result;
if ( (_DWORD)result )
{
memset(a2, 0, a3);
if ( read(a4[1], a2, a3) < 0 )
{
v6 = 1;
v9 = __errno_location();
v10 = strerror(*v9);
printf("read failed with %i: %s\n", (unsigned int)*v9, v10);
}
else if ( (*a2 & 0xFD) == 61 )
{
v8 = strlen(a2);
strncpy(a2, a2 + 2, v8);
}
return v6;
}
puts("wait_for_activity returned zero");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1, char *a2, size_t a3, int *a4)
{
unsigned int v6; // er12
__int64 result; // rax
size_t v8; // rax
int *v9; // rbx
char *v10; // rax

v6 = func10(a1, a4);
if ( v6 )
return v6;
LODWORD(result) = func13(a4[1]);
if ( (int)result < 0LL )
return (unsigned int)result;
if ( (_DWORD)result )
{
memset(a2, 0, a3);
if ( read(a4[1], a2, a3) < 0 )
{
v6 = 1;
v9 = __errno_location();
v10 = strerror(*v9);
printf("read failed with %i: %s\n", (unsigned int)*v9, v10);
}
else if ( (*a2 & 0xFD) == 61 )
{
v8 = strlen(a2);
strncpy(a2, a2 + 2, v8);
}
return v6;
}
puts("wait_for_activity returned zero");
return 0LL;
}

original_code:
int get_response(char* command, char* response, size_t response_buf_size, go_controller_context* context) {
  ssize_t rc;
  int err;
  err = send_command(command, context);
  if (err != 0)
    return err;
  rc = wait_for_activity(context->output_handle);
  if (rc < 0)
    return rc;
  else if (rc == 0) {
    printf("wait_for_activity returned zero\n");
  }
  else {
    memset(response, 0, response_buf_size);
    rc = read(context->output_handle, response, response_buf_size);
    if (rc < 0) {
      printf("read failed with %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
      return 1;
    }
    else {
      if (response[0] == '?') {
      }
      if (response[0] == '=' || response[0] == '?') {
        strncpy(response, &response[2], strlen(response));
      }
    }
  }
  return 0;
}

canonical_original_code:
int get_response(char *command, char *response, unsigned long response_buf_size, struct go_controller_context *context) {
  long rc;
  int err;
  err = send_command(command, context);
  if (err != 0)
    return err;
  rc = wait_for_activity(context->output_handle);
  if (rc < 0)
    return rc;
  else if (rc == 0) {
    printf("wait_for_activity returned zero\n");
  }
  else {
    memset(response, 0, response_buf_size);
    rc = read(context->output_handle, response, response_buf_size);
    if (rc < 0) {
      printf("read failed with %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
      return 1;
    }
    else {
      if (response[0] == '?') {
      }
      if (response[0] == '=' || response[0] == '?') {
        strncpy(response, &response[2], strlen(response));
      }
    }
  }
  return 0;
}

variable_types:
response
char *

variable_types: rc long


decompiled_code:
__int64 __fastcall go_controller_genmove(int a1, char *a2, size_t a3, int *a4)
{
if ( !a1 )
return get_response("genmove black", a2, a3, a4);
if ( a1 == 1 )
return get_response("genmove white", a2, a3, a4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, char *a2, size_t a3, int *a4)
{
if ( !a1 )
return func14("genmove black", a2, a3, a4);
if ( a1 == 1 )
return func14("genmove white", a2, a3, a4);
return 1LL;
}

original_code:
int go_controller_genmove(go_controller_colour colour, char* move, size_t move_size, go_controller_context* context) {
  char* command;
  int err;
  switch (colour) {
    case BLACK:
      command = "genmove black";
      break;
    case WHITE:
      command = "genmove white";
      break;
    default:
      return 1;
  }
  err = get_response(command, move, move_size, context);
  return err;
}

canonical_original_code:
int go_controller_genmove(enum go_controller_colour colour, char *move, unsigned long move_size, struct go_controller_context *context) {
  char *command;
  int err;
  switch (colour) {
    case BLACK:
      command = "genmove black";
      break;
    case WHITE:
      command = "genmove white";
      break;
    default:
      return 1;
  }
  err = get_response(command, move, move_size, context);
  return err;
}

variable_types: enum go_controller_colour { BLACK=0, WHITE=1 }

variable_types:
move
char *


decompiled_code:
__int64 __fastcall go_controller_play(int a1, const char *a2, int *a3)
{
char v5[128]; // [rsp+0h] [rbp-108h] BYREF
char dest[136]; // [rsp+80h] [rbp-88h] BYREF

if ( a1 )
{
if ( a1 == 1 )
strcpy(dest, "play white ");
}
else
{
strcpy(dest, "play black ");
}
strcat(dest, a2);
return get_response(dest, v5, 0x80uLL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, const char *a2, int *a3)
{
char v5[128]; // [rsp+0h] [rbp-108h] BYREF
char dest[136]; // [rsp+80h] [rbp-88h] BYREF

if ( a1 )
{
if ( a1 == 1 )
strcpy(dest, "play white ");
}
else
{
strcpy(dest, "play black ");
}
strcat(dest, a2);
return func14(dest, v5, 0x80uLL, a3);
}

original_code:
int go_controller_play(go_controller_colour colour, char* move, go_controller_context* context) {
  const size_t buf_size = 128;
  char response_buf[buf_size];
  char command[buf_size];
  int err;
  switch (colour) {
    case BLACK:
      strcpy(command, "play black ");
      break;
    case WHITE:
      strcpy(command, "play white ");
      break;
  }
  strcat(command, move);
  err = get_response(command, response_buf, buf_size, context);
  return err;
}

canonical_original_code:
int go_controller_play(enum go_controller_colour colour, char *move, struct go_controller_context *context) {
  unsigned long buf_size = 128;
  char response_buf[-1];
  char command[-1];
  int err;
  switch (colour) {
    case BLACK:
      strcpy(command, "play black ");
      break;
    case WHITE:
      strcpy(command, "play white ");
      break;
  }
  strcat(command, move);
  err = get_response(command, response_buf, buf_size, context);
  return err;
}

variable_types:
command
char [-1]

user_defined_types: enum go_controller_colour { BLACK=0, WHITE=1 }


decompiled_code:
__int64 __fastcall go_controller_undo(int *a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

return get_response("undo", v2, 0x80uLL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(int *a1)
{
char v2[136]; // [rsp+0h] [rbp-88h] BYREF

return func14("undo", v2, 0x80uLL, a1);
}

original_code:
int go_controller_undo(go_controller_context* context) {
  const size_t buf_size = 128;
  char response_buf[buf_size];
  int err;
  err = get_response("undo", response_buf, buf_size, context);
  return err;
}

canonical_original_code:
int go_controller_undo(struct go_controller_context *context) {
  unsigned long buf_size = 128;
  char response_buf[-1];
  int err;
  err = get_response("undo", response_buf, buf_size, context);
  return err;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // r13
int v5; // er15
int v6; // er14
int i; // er12
unsigned __int64 v8; // rdx
__int64 v9; // rbx
unsigned __int64 v10; // rbp
_BYTE *v11; // rbp
char v12; // si
std::ostream *v13; // rax
__int64 (__fastcall *v15)(); // rax
int v16; // eax
__int64 v17[11]; // [rsp+10h] [rbp-58h] BYREF

v3 = time(0LL);
srand(v3);
`anonymous namespace'::read_text((_anonymous_namespace_ *)v17, argv[1]);
if ( argc > 2 )
{
v16 = strtol(argv[2], 0LL, 10);
v5 = v16;
if ( argc == 3 )
{
v4 = v16;
v6 = 100;
}
else
{
v4 = v16;
v6 = strtol(argv[3], 0LL, 10);
if ( v6 <= 0 )
goto LABEL_11;
}
}
else
{
v4 = 5LL;
v5 = 5;
v6 = 100;
}
for ( i = 0; i < v6; ++i )
{
v8 = rand() % (unsigned __int64)(v17[1] - v4);
if ( (int)v8 < v5 + (int)v8 )
{
v9 = (int)v8;
v10 = (int)v8 + (unsigned __int64)(unsigned int)(~(_DWORD)v8 + v5 + v8) + 1;
do
{
std::__ostream_insert<char,std::char_traits<char>>();
++v9;
}
while ( v10 != v9 );
}
v11 = *(_BYTE **)((char *)&qword_4041F0 + *(_QWORD *)(std::cout[0] - 24LL));
if ( !v11 )
std::__throw_bad_cast();
if ( v11[56] )
{
v12 = v11[67];
}
else
{
std::ctype<char>::_M_widen_init();
v12 = 10;
v15 = *(__int64 (__fastcall **)())(*(_QWORD *)v11 + 48LL);
if ( v15 != std::ctype<char>::do_widen )
v12 = ((__int64 (__fastcall *)(_BYTE *, __int64))v15)(v11, 10LL);
}
v13 = (std::ostream *)std::ostream::put((std::ostream *)std::cout, v12);
std::ostream::flush(v13);
}
LABEL_11:
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::_M_dispose();
return 0;
}

original_code:
int main( int argc, char *argv[])
{
 int opt;
 double ps_bb[4];
 int got_bb;
 myname = argv[0];
 while ((opt = getopt( argc, argv, "vfi:c:w:m:p:s:o:")) != (-1))
 { switch( opt)
  { case 'v': verbose++; break;
    case 'f': manualfeed = 1; break;
    case 'i': imagespec = optarg; break;
    case 'c': cutmarginspec = optarg; break;
    case 'w': whitemarginspec = optarg; break;
    case 'm': mediaspec = optarg; break;
    case 'p': posterspec = optarg; break;
    case 's': scalespec = optarg; break;
    case 'o': filespec = optarg; break;
    default: usage(); break;
  }
 }
 if (scalespec && posterspec)
 { fprintf( stderr, "Please don't specify both -s and -o, ignoring -s!\n");
  scalespec = ((void *)0);
 }
 if (optind < argc)
  infile = argv[ optind];
 else
 { fprintf( stderr, "Filename argument missing!\n");
  usage();
 }
 if (!mediaspec)
 { mediaspec = "A4";
  if (verbose)
   fprintf( stderr,
    "Using default media of %s\n",
    mediaspec);
 }
 box_convert( mediaspec, mediasize);
 if (mediasize[3] < mediasize[2])
 { fprintf( stderr, "Media should always be specified in portrait format!\n");
  exit(1);
 }
 if (mediasize[2]-mediasize[0] <= 10.0 || mediasize[3]-mediasize[1] <= 10.0)
 { fprintf( stderr, "Media size is ridiculous!\n");
  exit(1);
 }
 if (!scalespec && !posterspec)
 {
  posterspec = mediaspec;
  if (verbose)
   fprintf( stderr,
    "Defaulting poster size to media size of %s\n",
    mediaspec);
 }
 if (!cutmarginspec)
 {
          cutmarginspec = "5%";
  if (verbose)
   fprintf( stderr,
    "Using default cutmargin of %s\n",
    cutmarginspec);
 }
 margin_convert( cutmarginspec, cutmargin);
 if (!whitemarginspec)
 { whitemarginspec = "0";
  if (verbose)
   fprintf( stderr,
    "Using default whitemargin of %s\n",
    whitemarginspec);
 }
 margin_convert( whitemarginspec, whitemargin);
 if (filespec)
 { if (!freopen( filespec, "w", stdout))
  { fprintf( stderr, "Cannot open '%s' for writing!\n",
     filespec);
   exit(1);
  } else if (verbose)
   fprintf( stderr, "Opened '%s' for writing\n",
     filespec);
 }
 dsc_head1();
 got_bb = dsc_infile( ps_bb);
 if (!got_bb && !imagespec)
 { imagespec = "A4";
  if (verbose)
   fprintf( stderr,
    "Using default input image of %s\n",
    imagespec);
 }
 if (imagespec)
  box_convert( imagespec, imagebb);
 else
 { int i;
  for (i=0; i<4; i++)
   imagebb[i] = ps_bb[i];
 }
 if (verbose > 1)
  fprintf( stderr, "   Input image is: [%g,%g,%g,%g]\n",
   imagebb[0], imagebb[1], imagebb[2], imagebb[3]);
 if (imagebb[2]-imagebb[0] <= 0.0 || imagebb[3]-imagebb[1] <= 0.0)
 { fprintf( stderr, "Input image should have positive size!\n");
  exit(1);
 }
 postersize( scalespec, posterspec);
 if (verbose > 1)
  fprintf( stderr, "   Output image is: [%g,%g,%g,%g]\n",
   posterbb[0], posterbb[1], posterbb[2], posterbb[3]);
 dsc_head2();
 printposter();
 exit (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int opt;
 double ps_bb[4];
 int got_bb;
 myname = argv[0];
 while ((opt = getopt( argc, argv, "vfi:c:w:m:p:s:o:")) != (-1))
 { switch( opt)
  { case 'v': verbose++; break;
    case 'f': manualfeed = 1; break;
    case 'i': imagespec = optarg; break;
    case 'c': cutmarginspec = optarg; break;
    case 'w': whitemarginspec = optarg; break;
    case 'm': mediaspec = optarg; break;
    case 'p': posterspec = optarg; break;
    case 's': scalespec = optarg; break;
    case 'o': filespec = optarg; break;
    default: usage(); break;
  }
 }
 if (scalespec && posterspec)
 { fprintf( stderr, "Please don't specify both -s and -o, ignoring -s!\n");
  scalespec = ((void *)0);
 }
 if (optind < argc)
  infile = argv[ optind];
 else
 { fprintf( stderr, "Filename argument missing!\n");
  usage();
 }
 if (!mediaspec)
 { mediaspec = "A4";
  if (verbose)
   fprintf( stderr,
    "Using default media of %s\n",
    mediaspec);
 }
 box_convert( mediaspec, mediasize);
 if (mediasize[3] < mediasize[2])
 { fprintf( stderr, "Media should always be specified in portrait format!\n");
  exit(1);
 }
 if (mediasize[2]-mediasize[0] <= 10.0 || mediasize[3]-mediasize[1] <= 10.0)
 { fprintf( stderr, "Media size is ridiculous!\n");
  exit(1);
 }
 if (!scalespec && !posterspec)
 {
  posterspec = mediaspec;
  if (verbose)
   fprintf( stderr,
    "Defaulting poster size to media size of %s\n",
    mediaspec);
 }
 if (!cutmarginspec)
 {
          cutmarginspec = "5%";
  if (verbose)
   fprintf( stderr,
    "Using default cutmargin of %s\n",
    cutmarginspec);
 }
 margin_convert( cutmarginspec, cutmargin);
 if (!whitemarginspec)
 { whitemarginspec = "0";
  if (verbose)
   fprintf( stderr,
    "Using default whitemargin of %s\n",
    whitemarginspec);
 }
 margin_convert( whitemarginspec, whitemargin);
 if (filespec)
 { if (!freopen( filespec, "w", stdout))
  { fprintf( stderr, "Cannot open '%s' for writing!\n",
     filespec);
   exit(1);
  } else if (verbose)
   fprintf( stderr, "Opened '%s' for writing\n",
     filespec);
 }
 dsc_head1();
 got_bb = dsc_infile( ps_bb);
 if (!got_bb && !imagespec)
 { imagespec = "A4";
  if (verbose)
   fprintf( stderr,
    "Using default input image of %s\n",
    imagespec);
 }
 if (imagespec)
  box_convert( imagespec, imagebb);
 else
 { int i;
  for (i=0; i<4; i++)
   imagebb[i] = ps_bb[i];
 }
 if (verbose > 1)
  fprintf( stderr, "   Input image is: [%g,%g,%g,%g]\n",
   imagebb[0], imagebb[1], imagebb[2], imagebb[3]);
 if (imagebb[2]-imagebb[0] <= 0.0 || imagebb[3]-imagebb[1] <= 0.0)
 { fprintf( stderr, "Input image should have positive size!\n");
  exit(1);
 }
 postersize( scalespec, posterspec);
 if (verbose > 1)
  fprintf( stderr, "   Output image is: [%g,%g,%g,%g]\n",
   posterbb[0], posterbb[1], posterbb[2], posterbb[3]);
 dsc_head2();
 printposter();
 exit (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: i int


cbFree

repo: ahmedlogic/vipcw-spectrogram

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

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void cbFree(CircularBuffer *cb) {
    free(cb->fbuffer); }

canonical_original_code:
void cbFree(struct CircularBuffer *cb) {
    free(cb->fbuffer); }

variable_types: struct CircularBuffer { int size; int start; int count; float *fbuffer; } *

return_type: void


cbInit

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

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(a2, 4uLL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(a2, 4uLL);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void cbInit(CircularBuffer *cb, int size) {
    cb->size = size;
    cb->start = 0;
    cb->count = 0;
    cb->fbuffer = (float*) calloc(cb->size, sizeof(float));
}

canonical_original_code:
void cbInit(struct CircularBuffer *cb, int size) {
    cb->size = size;
    cb->start = 0;
    cb->count = 0;
    cb->fbuffer = (float *) calloc(cb->size, sizeof(float));
}

user_defined_types: struct CircularBuffer { int size; int start; int count; float *fbuffer; }


cbIsFull

decompiled_code:
_BOOL8 __fastcall cbIsFull(_DWORD *a1)
{
return a1[2] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_DWORD *a1)
{
return a1[2] == *a1;
}

original_code:
int cbIsFull(CircularBuffer *cb) {
    return cb->count == cb->size; }

canonical_original_code:
int cbIsFull(struct CircularBuffer *cb) {
    return cb->count == cb->size; }


cbIsEmpty

decompiled_code:
_BOOL8 __fastcall cbIsEmpty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == 0;
}

original_code:
int cbIsEmpty(CircularBuffer *cb) {
    return cb->count == 0; }

canonical_original_code:
int cbIsEmpty(struct CircularBuffer *cb) {
    return cb->count == 0; }


cbWrite

decompiled_code:
__int64 __fastcall cbWrite(int *a1, _DWORD *a2)
{
int v2; // er8
int v3; // ecx
int v5; // esi
__int64 result; // rax

v2 = a1[1];
v3 = a1[2];
v5 = *a1;
result = *((_QWORD *)a1 + 2);
*(_DWORD *)(result + 4LL * ((v2 + v3) % v5)) = *a2;
if ( v3 == v5 )
{
result = (unsigned int)((v2 + 1) / v3);
a1[1] = (v2 + 1) % v3;
}
else
{
a1[2] = v3 + 1;
}
return result;
}

original_code:
void cbWrite(CircularBuffer *cb, float *elem) {
    int end = (cb->start + cb->count) % cb->size;
    cb->fbuffer[end] = *elem;
    if (cb->count == cb->size)
        cb->start = (cb->start + 1) % cb->size;
    else
        ++cb->count;
}

canonical_original_code:
void cbWrite(struct CircularBuffer *cb, float *elem) {
    int end = (cb->start + cb->count) % cb->size;
    cb->fbuffer[end] = *elem;
    if (cb->count == cb->size)
        cb->start = (cb->start + 1) % cb->size;
    else
        ++cb->count;
}

variable_types:
elem
float *

variable_types: end int


cbRead

original_code:
void cbRead(CircularBuffer *cb, float *elem) {
    *elem = cb->fbuffer[cb->start];
    cb->start = (cb->start + 1) % cb->size;
    --cb->count;
}

canonical_original_code:
void cbRead(struct CircularBuffer *cb, float *elem) {
    *elem = cb->fbuffer[cb->start];
    cb->start = (cb->start + 1) % cb->size;
    --cb->count;
}


decompiled_code:
__int64 empty_stdin()
{
__isoc99_scanf();
return __isoc99_scanf();
}

canonical_decompiled_code:
__int64 func13()
{
__isoc99_scanf();
return __isoc99_scanf();
}

original_code:
void empty_stdin(){
    char c;
    scanf("%c%*[^\n]", &c);
    scanf("%*c");
}

variable_types: c char


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // r12
int v4; // eax
ssize_t v5; // rax
char *v6; // r11
int v7; // er10
float v8; // [rsp+Ch] [rbp-FCh] BYREF
int v9[8]; // [rsp+10h] [rbp-F8h] BYREF
char buf[216]; // [rsp+30h] [rbp-D8h] BYREF

cbInit(v9, 20LL, envp);
while ( 1 )
{
LABEL_2:
empty_stdin();
sleep(1u);
v3 = v9[0];
v4 = fileno(stdin);
v5 = read(v4, buf, v3);
printf("No. of bytes read: %d\n", v5);
if ( v9[0] > 0 )
{
v6 = buf;
do
cbWrite(v9, v6);
while ( v9[0] > v7 );
}
while ( !(unsigned int)cbIsEmpty(v9) )
{
while ( 1 )
{
cbRead(v9, &v8);
printf("%f\t", v8);
if ( (unsigned int)(-858993459 * v9[2] + 429496729) > 0x33333332 )
break;
putchar(10);
if ( (unsigned int)cbIsEmpty(v9) )
goto LABEL_2;
}
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // r12
int v4; // eax
ssize_t v5; // rax
char *v6; // r11
int v7; // er10
float v8; // [rsp+Ch] [rbp-FCh] BYREF
int v9[8]; // [rsp+10h] [rbp-F8h] BYREF
char buf[216]; // [rsp+30h] [rbp-D8h] BYREF

func8(v9, 20LL, envp);
while ( 1 )
{
LABEL_2:
func13();
sleep(1u);
v3 = v9[0];
v4 = fileno(stdin);
v5 = read(v4, buf, v3);
printf("No. of bytes read: %d\n", v5);
if ( v9[0] > 0 )
{
v6 = buf;
do
func11(v9, v6);
while ( v9[0] > v7 );
}
while ( !(unsigned int)func10(v9) )
{
while ( 1 )
{
func12(v9, &v8);
printf("%f\t", v8);
if ( (unsigned int)(-858993459 * v9[2] + 429496729) > 0x33333332 )
break;
putchar(10);
if ( (unsigned int)func10(v9) )
goto LABEL_2;
}
}
}
}

original_code:
int main(){
    CircularBuffer cb;
    cbInit(&cb, 20);
    while(1){
        float buff[50];
        empty_stdin();
        sleep(1.5);
        int n = read(fileno(stdin), buff, cb.size);
        printf("No. of bytes read: %d\n", n);
        int i = 0;
        while(i < cb.size){
            cbWrite(&cb, &buff[i]);
            i++;
        }
        while(!cbIsEmpty(&cb)){
            float c;
            cbRead(&cb, &c);
            printf("%f\t", c);
            if(!(cb.count%5)) printf("\n");
        }
    }
}

canonical_original_code:
int main(){
    struct CircularBuffer cb;
    cbInit(&cb, 20);
    while(1){
        float buff[50];
        empty_stdin();
        sleep(1.5);
        int n = read(fileno(stdin), buff, cb.size);
        printf("No. of bytes read: %d\n", n);
        int i = 0;
        while(i < cb.size){
            cbWrite(&cb, &buff[i]);
            i++;
        }
        while(!cbIsEmpty(&cb)){
            float c;
            cbRead(&cb, &c);
            printf("%f\t", c);
            if(!(cb.count%5)) printf("\n");
        }
    }
}

variable_types: struct CircularBuffer { int size; int start; int count; float *fbuffer; }

variable_types:
buff
float [50]

variable_types: n int

variable_types: c float


decompiled_code:
void __fastcall __noreturn error1(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s: %s \n", a1, v2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
int *v1; // rax
char *v2; // rax

v1 = __errno_location();
v2 = strerror(*v1);
fprintf(stderr, "%s: %s \n", a1, v2);
exit(1);
}

original_code:
void error1(const char *msg)
{
    fprintf(stderr, "%s: %s \n", msg, strerror((*__errno_location ())));
    exit(1);
}

canonical_original_code:
void error1(char *msg)
{
    fprintf(stderr, "%s: %s \n", msg, strerror((*__errno_location ())));
    exit(1);
}

variable_types:
msg
char *


writeToClients

decompiled_code:
ssize_t writeToClients()
{
__int64 v0; // rbx
const char *v1; // rsi
ssize_t result; // rax

v0 = *(_QWORD *)list;
do
{
v1 = tempBuf;
result = write(*(_DWORD *)v0, tempBuf, length);
n = result;
if ( (int)result < 0 )
err((int)"ERROR writing to socket", v1);
v0 = *(_QWORD *)(v0 + 8);
}
while ( v0 );
return result;
}

canonical_decompiled_code:
ssize_t func9()
{
__int64 v0; // rbx
const char *v1; // rsi
ssize_t result; // rax

v0 = *(_QWORD *)list;
do
{
v1 = tempBuf;
result = write(*(_DWORD *)v0, tempBuf, length);
n = result;
if ( (int)result < 0 )
err((int)"ERROR writing to socket", v1);
v0 = *(_QWORD *)(v0 + 8);
}
while ( v0 );
return result;
}

original_code:
int writeToClients(){
 Node *ln = list->head;
 int x = ln->data;
 n = write(x, tempBuf, length);
 if (n < 0)
             err("ERROR writing to socket");
 while(ln->next != ((void *)0)){
  ln = ln->next;
  int x = ln->data;
  n = write(x, tempBuf, length);
  if (n < 0)
             err("ERROR writing to socket");
 }
}

canonical_original_code:
int writeToClients(){
 struct node *ln = list->head;
 int x = ln->data;
 n = write(x, tempBuf, length);
 if (n < 0)
             err("ERROR writing to socket");
 while(ln->next != ((void *)0)){
  ln = ln->next;
  int x = ln->data;
  n = write(x, tempBuf, length);
  if (n < 0)
             err("ERROR writing to socket");
 }
}

variable_types: struct node { int data; struct node *next; } *

variable_types: x int


emptylist

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

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

result = malloc(8uLL);
*result = 0LL;
return result;
}

original_code:
List * emptylist(){
  List * list = malloc(sizeof(List));
  list->head = ((void *)0);
  return list;
}

canonical_original_code:
struct list *emptylist(){
  struct list *list = malloc(sizeof(List));
  list->head = ((void *)0);
  return list;
}

variable_types: struct list { struct node { int data; struct node *next; } *head; } *


display

decompiled_code:
int __fastcall display(unsigned int **a1)
{
unsigned int *v1; // rbx
__int64 v2; // rsi
int result; // eax

v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
v2 = *v1;
if ( !*((_QWORD *)v1 + 1) )
break;
printf("%d,", v2);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
result = printf("%d\n", v2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int **a1)
{
unsigned int *v1; // rbx
__int64 v2; // rsi
int result; // eax

v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
v2 = *v1;
if ( !*((_QWORD *)v1 + 1) )
break;
printf("%d,", v2);
v1 = (unsigned int *)*((_QWORD *)v1 + 1);
}
result = printf("%d\n", v2);
}
return result;
}

original_code:
void display(List * list) {
  Node * current = list->head;
  if(list->head == ((void *)0))
    return;
  while(current->next != ((void *)0)){
    printf("%d,", current->data);
    current = current->next;
  }
  printf("%d\n", current->data);
}

canonical_original_code:
void display(struct list *list) {
  struct node *current = list->head;
  if(list->head == ((void *)0))
    return;
  while(current->next != ((void *)0)){
    printf("%d,", current->data);
    current = current->next;
  }
  printf("%d\n", current->data);
}

user_defined_types: struct node { int data; struct node *next; }


delete

decompiled_code:
void __fastcall delete(int a1, void **a2)
{
_QWORD *v3; // rsi
_QWORD *v5; // rcx
_QWORD *i; // rdi
void *v7; // rax

v3 = *a2;
if ( v3 )
{
v5 = v3;
for ( i = v3; ; i = (_QWORD *)i[1] )
{
v7 = (void *)i[1];
if ( *(_DWORD *)i == a1 )
break;
v5 = i;
if ( !v7 )
return;
}
v5[1] = v7;
if ( v3 == i )
*a2 = v7;
free(i);
}
}

canonical_decompiled_code:
void __fastcall func13(int a1, void **a2)
{
_QWORD *v3; // rsi
_QWORD *v5; // rcx
_QWORD *i; // rdi
void *v7; // rax

v3 = *a2;
if ( v3 )
{
v5 = v3;
for ( i = v3; ; i = (_QWORD *)i[1] )
{
v7 = (void *)i[1];
if ( *(_DWORD *)i == a1 )
break;
v5 = i;
if ( !v7 )
return;
}
v5[1] = v7;
if ( v3 == i )
*a2 = v7;
free(i);
}
}

original_code:
void delete(int data, List * list){
  Node * current = list->head;
  Node * previous = current;
  while(current != ((void *)0)){
    if(current->data == data){
      previous->next = current->next;
      if(current == list->head)
        list->head = current->next;
      free(current);
      return;
    }
    previous = current;
    current = current->next;
  }
}

canonical_original_code:
void delete(int data, struct list *list){
  struct node *current = list->head;
  struct node *previous = current;
  while(current != ((void *)0)){
    if(current->data == data){
      previous->next = current->next;
      if(current == list->head)
        list->head = current->next;
      free(current);
      return;
    }
    previous = current;
    current = current->next;
  }
}

variable_types: data int


destroy

decompiled_code:
void __fastcall destroy(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func15(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
void destroy(List * list){
  Node * current = list->head;
  Node * next = current;
  while(current != ((void *)0)){
    next = current->next;
    free(current);
    current = next;
  }
  free(list);
}

canonical_original_code:
void destroy(struct list *list){
  struct node *current = list->head;
  struct node *next = current;
  while(current != ((void *)0)){
    next = current->next;
    free(current);
    current = next;
  }
  free(list);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v5; // rsi

if ( argc <= 1 )
{
v5 = "-";
v3 = "-";
}
else
{
v3 = (char *)argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
usage(*argv, 0LL);
if ( argc == 2 )
{
v5 = "-";
}
else
{
v5 = (char *)argv[2];
if ( argc != 3 )
usage(*argv, 1LL);
}
}
mkcfile(v3, v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
char *v5; // rsi

if ( argc <= 1 )
{
v5 = "-";
v3 = "-";
}
else
{
v3 = (char *)argv[1];
if ( !strcmp(v3, "-h") || !strcmp(v3, "--help") )
func8(*argv, 0LL);
if ( argc == 2 )
{
v5 = "-";
}
else
{
v5 = (char *)argv[2];
if ( argc != 3 )
func8(*argv, 1LL);
}
}
func9(v3, v5);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 const char *fname="-", *outfname="-";
 if(argc>1) {
  if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) usage(argv[0], 0);
  fname=argv[1];
 }
 if(argc>2) outfname=argv[2];
 if(argc>3) usage(argv[0], 1);
 mkcfile(fname, outfname);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *fname = "-"; char *outfname = "-";
 if(argc>1) {
  if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) usage(argv[0], 0);
  fname=argv[1];
 }
 if(argc>2) outfname=argv[2];
 if(argc>3) usage(argv[0], 1);
 mkcfile(fname, outfname);
 return 0;
}

variable_types: argc int

variable_types:
fname
char *

variable_types:
outfname
char *


mystrdup

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

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

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

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
char *mystrdup(const char *s)
{
 char *ds;
 if(!(ds=(char *)malloc(strlen(s)+1))) return ((void *)0);
 strcpy(ds, s);
 return ds;
}

canonical_original_code:
char *mystrdup(char *s)
{
 char *ds;
 if(!(ds=(char *)malloc(strlen(s)+1))) return ((void *)0);
 strcpy(ds, s);
 return ds;
}

variable_types:
s
char *

variable_types:
ds
char *

return_type: char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1, int a2)
{
fprintf(stderr, "Usage: %s <file-name> <output-file-name>", a1);
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1, int a2)
{
fprintf(stderr, "Usage: %s <file-name> <output-file-name>", a1);
exit(a2);
}

original_code:
void usage(const char *cmd, int st)
{
 fprintf(stderr, "Usage: %s <file-name> <output-file-name>", cmd);
 exit(st);
}

canonical_original_code:
void usage(char *cmd, int st)
{
 fprintf(stderr, "Usage: %s <file-name> <output-file-name>", cmd);
 exit(st);
}

variable_types:
cmd
char *

variable_types: st int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
const char *v8; // rax
int v9; // eax
const char *v10; // rax
const char *v11; // rax
unsigned int v12; // [rsp+0h] [rbp-20h] BYREF
float v13; // [rsp+4h] [rbp-1Ch] BYREF
__int64 v14[3]; // [rsp+8h] [rbp-18h] BYREF

v12 = 0;
if ( argc == 1 )
goto LABEL_2;
v4 = litOpt(argc, argv, v14, &v12);
if ( v4 )
{
if ( v4 == 100 )
{
LABEL_2:
afficheHelp(*argv, 0LL);
return 0;
}
afficheHelp(*argv, argv[v12]);
result = 2;
}
else
{
v5 = tokenize(v14[0]);
if ( v5 )
{
v8 = (const char *)errorToStr(v5);
printf("\nErreur lors de l'analyse syntaxique : %s\n", v8);
v9 = lastToken();
showRef(v14[0], (unsigned int)tabOfToken[6 * v9 + 5]);
result = 1;
}
else
{
v6 = analyseGrammaire(&v12);
if ( v6 )
{
v10 = (const char *)errorToStr(v6);
printf("\nErreur lors de l'analyse grammaticale : %s\n", v10);
showRef(v14[0], (unsigned int)tabOfToken[6 * v12 + 5]);
result = 2;
}
else
{
v7 = calcul(&v13, &v12);
if ( v7 )
{
v11 = (const char *)errorToStr(v7);
printf("\nErreur lors du calcul : %s\n", v11);
showRef(v14[0], v12);
result = 3;
}
else
{
if ( !silent )
printf("Resultat : ");
printf("%.6G\n", v13);
result = 0;
}
}
}
}
return result;
}

original_code:
int main(int argc, char **argv) {
 errorHandler error;
 char *equ;
 int offset=0;
 float result;
 if (argc==1)
  error=100;
 else
  error=litOpt(argc,argv,&equ,&offset);
 if (error) {
  if (error==100) {
   afficheHelp(argv[0],((void *)0));
   return 0;
  }
  afficheHelp(argv[0],argv[offset]);
  return 2;
 }
 error=tokenize(equ);
 if (error!=0)
 {
  printf("\nErreur lors de l'analyse syntaxique : %s\n",errorToStr(error));
  showRef(equ,tabOfToken[lastToken()].offset);
  return 1;
 }
 error=analyseGrammaire(&offset);
 if (error)
 {
  printf("\nErreur lors de l'analyse grammaticale : %s\n",errorToStr(error));
  showRef(equ,tabOfToken[offset].offset);
  return 2;
 }
 error=calcul(&result,&offset);
 if (error)
 {
  printf("\nErreur lors du calcul : %s\n",errorToStr(error));
  showRef(equ,offset);
  return 3;
 }
 if (!silent)
  printf("Resultat : ");
 printf("%.6G\n",result);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 unsigned int error;
 char *equ;
 int offset = 0;
 float result;
 if (argc==1)
  error=100;
 else
  error=litOpt(argc,argv,&equ,&offset);
 if (error) {
  if (error==100) {
   afficheHelp(argv[0],((void *)0));
   return 0;
  }
  afficheHelp(argv[0],argv[offset]);
  return 2;
 }
 error=tokenize(equ);
 if (error!=0)
 {
  printf("\nErreur lors de l'analyse syntaxique : %s\n",errorToStr(error));
  showRef(equ,tabOfToken[lastToken()].offset);
  return 1;
 }
 error=analyseGrammaire(&offset);
 if (error)
 {
  printf("\nErreur lors de l'analyse grammaticale : %s\n",errorToStr(error));
  showRef(equ,tabOfToken[offset].offset);
  return 2;
 }
 error=calcul(&result,&offset);
 if (error)
 {
  printf("\nErreur lors du calcul : %s\n",errorToStr(error));
  showRef(equ,offset);
  return 3;
 }
 if (!silent)
  printf("Resultat : ");
 printf("%.6G\n",result);
 return 0;
}

variable_types:
argv
char **

variable_types:
error
unsigned int

variable_types:
equ
char *

variable_types: offset int

variable_types: result float


lastToken

decompiled_code:
__int64 lastToken()
{
_WORD *v0; // rdx
unsigned int i; // er8

v0 = &tabOfToken;
for ( i = 0; i != 150; ++i )
{
if ( *v0 == 10 )
break;
if ( !*v0 )
break;
v0 += 12;
}
return i;
}

canonical_decompiled_code:
__int64 func0()
{
_WORD *v0; // rdx
unsigned int i; // er8

v0 = &tabOfToken;
for ( i = 0; i != 150; ++i )
{
if ( *v0 == 10 )
break;
if ( !*v0 )
break;
v0 += 12;
}
return i;
}

original_code:
int lastToken() {
 int i=0;
 while ((i<150) && (tabOfToken[i].type!=0) && (tabOfToken[i].type!=10))
  i++;
 return i;
}

canonical_original_code:
int lastToken() {
 int i = 0;
 while ((i<150) && (tabOfToken[i].type!=0) && (tabOfToken[i].type!=10))
  i++;
 return i;
}

variable_types: i int


caractereType

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

result = 1LL;
if ( (unsigned __int8)(a1 - 65) > 0x39u )
{
result = 2LL;
if ( (unsigned __int8)(a1 - 42) > 1u && (a1 & 0xFD) != 45 )
{
if ( (unsigned __int8)(a1 - 48) <= 9u || a1 == 46 )
{
result = 3LL;
}
else if ( a1 == 40 )
{
result = 4LL;
}
else
{
result = 255LL;
if ( a1 == 41 )
result = 5LL;
}
}
}
return result;
}

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

result = 1LL;
if ( (unsigned __int8)(a1 - 65) > 0x39u )
{
result = 2LL;
if ( (unsigned __int8)(a1 - 42) > 1u && (a1 & 0xFD) != 45 )
{
if ( (unsigned __int8)(a1 - 48) <= 9u || a1 == 46 )
{
result = 3LL;
}
else if ( a1 == 40 )
{
result = 4LL;
}
else
{
result = 255LL;
if ( a1 == 41 )
result = 5LL;
}
}
}
return result;
}

original_code:
errorHandler caractereType(char cara) {
 if (cara<='z' && cara>='A')
  return 1;
 if (cara=='*' || cara=='/' || cara=='+' || cara=='-')
  return 2;
 if ((cara>='0' && cara <='9') || (cara=='.'))
  return 3;
 if (cara=='(')
  return 4;
 if (cara==')')
  return 5;
 return 255;
}

canonical_original_code:
unsigned int caractereType(char cara) {
 if (cara<='z' && cara>='A')
  return 1;
 if (cara=='*' || cara=='/' || cara=='+' || cara=='-')
  return 2;
 if ((cara>='0' && cara <='9') || (cara=='.'))
  return 3;
 if (cara=='(')
  return 4;
 if (cara==')')
  return 5;
 return 255;
}

variable_types: cara char

return_type: unsigned int


getOperator

original_code:
errorHandler getOperator(char *chaine, int *offset, token *newToken) {
 newToken->type=2;
 switch (chaine[*offset]) {
  case '*' : newToken->op=0;break;
  case '/' : newToken->op=1;break;
  case '+' : newToken->op=2;break;
  case '-' : newToken->op=3;break;
  default : newToken->op=255;
 }
 if (debug)
  printf("\t\tOPERATOR : %i\n",newToken->op);
 (*offset)++;
 return 0;
}

canonical_original_code:
unsigned int getOperator(char *chaine, int *offset, struct token *newToken) {
 newToken->type=2;
 switch (chaine[*offset]) {
  case '*' : newToken->op=0;break;
  case '/' : newToken->op=1;break;
  case '+' : newToken->op=2;break;
  case '-' : newToken->op=3;break;
  default : newToken->op=255;
 }
 if (debug)
  printf("\t\tOPERATOR : %i\n",newToken->op);
 (*offset)++;
 return 0;
}

variable_types:
chaine
char *

variable_types:
offset
int *

variable_types: struct token { unsigned short type; double valueReal; unsigned short function; unsigned short op; int offset; } *


getFunction

decompiled_code:
__int64 __fastcall getFunction(char *s, int *a2, _WORD *a3)
{
__int64 v3; // r12
size_t i; // rbx
char v6; // di
__int64 v7; // r14
const char *v8; // rsi
__int64 v9; // rbx
int v10; // ecx
char s1[80]; // [rsp+10h] [rbp-50h] BYREF

v3 = 0LL;
for ( i = *a2; ; s1[v3++] = s[i - 1] )
{
v7 = (int)v3;
if ( strlen(s) <= i )
break;
if ( v3 == 20 )
{
v7 = 20LL;
break;
}
v6 = s[i++];
if ( (unsigned int)caractereType(v6) != 1 )
break;
*a2 = i;
}
v8 = functionRef[0];
s1[v7] = 0;
v9 = 0LL;
if ( !v8 )
return 1LL;
while ( strcasecmp(s1, v8) )
{
v8 = functionRef[++v9];
if ( !v8 )
return 1LL;
}
v10 = debug;
*a3 = 1;
a3[8] = v9;
if ( v10 )
printf("\t\tFonction:%i\n", (unsigned int)v9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, int *a2, _WORD *a3)
{
__int64 v3; // r12
size_t i; // rbx
char v6; // di
__int64 v7; // r14
const char *v8; // rsi
__int64 v9; // rbx
int v10; // ecx
char s1[80]; // [rsp+10h] [rbp-50h] BYREF

v3 = 0LL;
for ( i = *a2; ; s1[v3++] = s[i - 1] )
{
v7 = (int)v3;
if ( strlen(s) <= i )
break;
if ( v3 == 20 )
{
v7 = 20LL;
break;
}
v6 = s[i++];
if ( (unsigned int)func1(v6) != 1 )
break;
*a2 = i;
}
v8 = functionRef[0];
s1[v7] = 0;
v9 = 0LL;
if ( !v8 )
return 1LL;
while ( strcasecmp(s1, v8) )
{
v8 = functionRef[++v9];
if ( !v8 )
return 1LL;
}
v10 = debug;
*a3 = 1;
a3[8] = v9;
if ( v10 )
printf("\t\tFonction:%i\n", (unsigned int)v9);
return 0LL;
}

original_code:
errorHandler getFunction(char *chaine,int *offset, token *newToken) {
 char buffer[20 +1];
 int i=0;
 while ((*offset<strlen(chaine)) && (i<20) && (caractereType(chaine[*offset])==1))
  buffer[i++]=chaine[(*offset)++];
 buffer[i]='\0';
 i=0;
 while ((functionRef[i]!=((void *)0)) && (strcasecmp(buffer,functionRef[i])!=0))
  i++;
 if(functionRef[i]==((void *)0))
  return 1;
 newToken->type=1;
 newToken->function=i;
 if(debug)
  printf("\t\tFonction:%i\n",newToken->function);
 return 0;
}

canonical_original_code:
unsigned int getFunction(char *chaine, int *offset, struct token *newToken) {
 char buffer[-1];
 int i = 0;
 while ((*offset<strlen(chaine)) && (i<20) && (caractereType(chaine[*offset])==1))
  buffer[i++]=chaine[(*offset)++];
 buffer[i]='\0';
 i=0;
 while ((functionRef[i]!=((void *)0)) && (strcasecmp(buffer,functionRef[i])!=0))
  i++;
 if(functionRef[i]==((void *)0))
  return 1;
 newToken->type=1;
 newToken->function=i;
 if(debug)
  printf("\t\tFonction:%i\n",newToken->function);
 return 0;
}

variable_types:
buffer
char [-1]

user_defined_types: struct token { unsigned short type; double valueReal; unsigned short function; unsigned short op; int offset; }


getNumber

decompiled_code:
__int64 __fastcall getNumber(char *s, int *a2, __int64 a3)
{
__int64 v3; // r12
size_t i; // rbx
char v6; // di
__int64 v7; // r13
double v8; // xmm0_8
int v9; // ecx
char *endptr; // [rsp+18h] [rbp-58h] BYREF
char nptr[80]; // [rsp+20h] [rbp-50h] BYREF

v3 = 0LL;
for ( i = *a2; ; nptr[v3++] = s[i - 1] )
{
v7 = (int)v3;
if ( strlen(s) <= i )
break;
if ( v3 == 20 )
{
v7 = 20LL;
break;
}
v6 = s[i++];
if ( (unsigned int)caractereType(v6) != 3 )
break;
*a2 = i;
}
nptr[v7] = 0;
v8 = strtod(nptr, &endptr);
v9 = debug;
*(_WORD *)a3 = 3;
*(double *)(a3 + 8) = v8;
if ( v9 )
printf("\t\tReal = %f \n", v8);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, int *a2, __int64 a3)
{
__int64 v3; // r12
size_t i; // rbx
char v6; // di
__int64 v7; // r13
double v8; // xmm0_8
int v9; // ecx
char *endptr; // [rsp+18h] [rbp-58h] BYREF
char nptr[80]; // [rsp+20h] [rbp-50h] BYREF

v3 = 0LL;
for ( i = *a2; ; nptr[v3++] = s[i - 1] )
{
v7 = (int)v3;
if ( strlen(s) <= i )
break;
if ( v3 == 20 )
{
v7 = 20LL;
break;
}
v6 = s[i++];
if ( (unsigned int)func1(v6) != 3 )
break;
*a2 = i;
}
nptr[v7] = 0;
v8 = strtod(nptr, &endptr);
v9 = debug;
*(_WORD *)a3 = 3;
*(double *)(a3 + 8) = v8;
if ( v9 )
printf("\t\tReal = %f \n", v8);
return 0LL;
}

original_code:
errorHandler getNumber(char *chaine,int *offset, token *newToken) {
 char buffer[20 +1];
 char *errorBuff;
 int i=0;
 while ((*offset<strlen(chaine)) && (i<20) && (caractereType(chaine[*offset])==3))
  buffer[i++]=chaine[(*offset)++];
 buffer[i]='\0';
 *offset++;
 newToken->valueReal=strtod(buffer,&errorBuff);
 newToken->type=3;
 if (debug)
  printf("\t\tReal = %f \n",newToken->valueReal);
 return 0;
}

canonical_original_code:
unsigned int getNumber(char *chaine, int *offset, struct token *newToken) {
 char buffer[-1];
 char *errorBuff;
 int i = 0;
 while ((*offset<strlen(chaine)) && (i<20) && (caractereType(chaine[*offset])==3))
  buffer[i++]=chaine[(*offset)++];
 buffer[i]='\0';
 *offset++;
 newToken->valueReal=strtod(buffer,&errorBuff);
 newToken->type=3;
 if (debug)
  printf("\t\tReal = %f \n",newToken->valueReal);
 return 0;
}

variable_types:
errorBuff
char *


nextToken

decompiled_code:
__int64 __fastcall nextToken(char *s, int *a2, __int64 a3)
{
int v5; // edx
int v6; // esi
int v7; // eax
char *v8; // rdx
char *v9; // rcx
unsigned int v10; // eax
unsigned int v11; // ebx
__int64 result; // rax

v5 = strlen(s);
v6 = v5;
v7 = *a2;
if ( v5 <= *a2 )
{
if ( v5 == v7 )
{
LABEL_16:
result = 9LL;
*(_WORD *)a3 = 0;
return result;
}
v9 = &s[v7];
}
else
{
v8 = &s[v7];
while ( 1 )
{
v9 = v8;
if ( *v8 != 32 )
break;
++v7;
++v8;
*a2 = v7;
if ( v7 == v6 )
goto LABEL_16;
}
}
*(_DWORD *)(a3 + 20) = v7;
v10 = caractereType(*v9);
v11 = v10;
if ( debug )
printf("\t\tTYPE : %i\n", v10);
switch ( v11 )
{
case 1u:
result = getFunction(s, a2, (_WORD *)a3);
break;
case 2u:
result = getOperator((__int64)s, a2, (_WORD *)a3);
break;
case 3u:
result = getNumber(s, a2, a3);
break;
case 4u:
result = 0LL;
*(_WORD *)a3 = 5;
++*a2;
break;
case 5u:
result = 0LL;
*(_WORD *)a3 = 6;
++*a2;
break;
default:
*(_WORD *)a3 = 10;
result = 10LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, int *a2, __int64 a3)
{
int v5; // edx
int v6; // esi
int v7; // eax
char *v8; // rdx
char *v9; // rcx
unsigned int v10; // eax
unsigned int v11; // ebx
__int64 result; // rax

v5 = strlen(s);
v6 = v5;
v7 = *a2;
if ( v5 <= *a2 )
{
if ( v5 == v7 )
{
LABEL_16:
result = 9LL;
*(_WORD *)a3 = 0;
return result;
}
v9 = &s[v7];
}
else
{
v8 = &s[v7];
while ( 1 )
{
v9 = v8;
if ( *v8 != 32 )
break;
++v7;
++v8;
*a2 = v7;
if ( v7 == v6 )
goto LABEL_16;
}
}
*(_DWORD *)(a3 + 20) = v7;
v10 = func1(*v9);
v11 = v10;
if ( debug )
printf("\t\tTYPE : %i\n", v10);
switch ( v11 )
{
case 1u:
result = func3(s, a2, (_WORD *)a3);
break;
case 2u:
result = func2((__int64)s, a2, (_WORD *)a3);
break;
case 3u:
result = func4(s, a2, a3);
break;
case 4u:
result = 0LL;
*(_WORD *)a3 = 5;
++*a2;
break;
case 5u:
result = 0LL;
*(_WORD *)a3 = 6;
++*a2;
break;
default:
*(_WORD *)a3 = 10;
result = 10LL;
break;
}
return result;
}

original_code:
errorHandler nextToken(char *chaine, int *offset,token *newToken){
 int lengthChaine;
 int type;
 lengthChaine=strlen(chaine);
 while((*offset<lengthChaine) && (chaine[*offset]==' '))
  (*offset)++;
 if (*offset==lengthChaine) {
  newToken->type=0;
  return 9;
 }
 newToken->offset=*offset;
 type=caractereType(chaine[*offset]);
 if (debug)
  printf("\t\tTYPE : %i\n",type);
 switch(type) {
  case 1 : return getFunction(chaine,offset,newToken);
  case 2 : return getOperator(chaine,offset,newToken);
  case 3 : return getNumber(chaine,offset,newToken);
  case 4 : newToken->type=5; (*offset)++;return 0;
  case 5 : newToken->type=6; (*offset)++;return 0;
  default : newToken->type=10;return 10;
 }
 return 10;
}

canonical_original_code:
unsigned int nextToken(char *chaine, int *offset, struct token *newToken){
 int lengthChaine;
 int type;
 lengthChaine=strlen(chaine);
 while((*offset<lengthChaine) && (chaine[*offset]==' '))
  (*offset)++;
 if (*offset==lengthChaine) {
  newToken->type=0;
  return 9;
 }
 newToken->offset=*offset;
 type=caractereType(chaine[*offset]);
 if (debug)
  printf("\t\tTYPE : %i\n",type);
 switch(type) {
  case 1 : return getFunction(chaine,offset,newToken);
  case 2 : return getOperator(chaine,offset,newToken);
  case 3 : return getNumber(chaine,offset,newToken);
  case 4 : newToken->type=5; (*offset)++;return 0;
  case 5 : newToken->type=6; (*offset)++;return 0;
  default : newToken->type=10;return 10;
 }
 return 10;
}

variable_types: lengthChaine int

variable_types: type int


pCos

decompiled_code:
__int64 __fastcall pCos(double *a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = cos(*a1);
result = 0LL;
*a1 = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = cos(*a1);
result = 0LL;
*a1 = v1;
return result;
}

original_code:
errorHandler pCos(double *real) {
 if (trigoDeg)
  ((*real)*0.0174532925);
 *real=cos(*real);
 return 0;
}

canonical_original_code:
unsigned int pCos(double *real) {
 if (trigoDeg)
  ((*real)*0.0174532925);
 *real=cos(*real);
 return 0;
}

variable_types:
real
double *


pSin

decompiled_code:
__int64 __fastcall pSin(double *a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = sin(*a1);
result = 0LL;
*a1 = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(double *a1)
{
double v1; // xmm0_8
__int64 result; // rax

v1 = sin(*a1);
result = 0LL;
*a1 = v1;
return result;
}

original_code:
errorHandler pSin(double *real) {
 if (trigoDeg)
  ((*real)*0.0174532925);
 *real=sin(*real);
 return 0;
}

canonical_original_code:
unsigned int pSin(double *real) {
 if (trigoDeg)
  ((*real)*0.0174532925);
 *real=sin(*real);
 return 0;
}


pTan

decompiled_code:
__int64 __fastcall pTan(double *a1)
{
__m128i v1; // xmm2
float v2; // er14
double v3; // xmm0_8
__int64 result; // rax

v1 = 0LL;
*(float *)v1.m128i_i32 = *a1;
v2 = COERCE_FLOAT(_mm_cvtsi128_si32(v1));
v3 = sin(*a1);
if ( v3 == 0.0 )
{
*a1 = v3;
result = 16LL;
}
else
{
result = 0LL;
*a1 = v2 / v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double *a1)
{
__m128i v1; // xmm2
float v2; // er14
double v3; // xmm0_8
__int64 result; // rax

v1 = 0LL;
*(float *)v1.m128i_i32 = *a1;
v2 = COERCE_FLOAT(_mm_cvtsi128_si32(v1));
v3 = sin(*a1);
if ( v3 == 0.0 )
{
*a1 = v3;
result = 16LL;
}
else
{
result = 0LL;
*a1 = v2 / v3;
}
return result;
}

original_code:
errorHandler pTan(double *real) {
 float tmp;
 tmp=*real;
 if (trigoDeg)
  ((*real)*0.0174532925);
 *real=sin(*real);
 if (*real==0)
  return 16;
 *real=tmp/(*real);
 return 0;
}

canonical_original_code:
unsigned int pTan(double *real) {
 float tmp;
 tmp=*real;
 if (trigoDeg)
  ((*real)*0.0174532925);
 *real=sin(*real);
 if (*real==0)
  return 16;
 *real=tmp/(*real);
 return 0;
}

variable_types: tmp float


doOperation

original_code:
errorHandler doOperation(int op) {
 token *tok1,*tok2;
 pop2(&tok1);
 pop2(&tok2);
 if ((tok1->type!=3) || (tok2->type!=3))
  return 11;
 switch (op) {
  case 0 : tok1->valueReal=tok2->valueReal*tok1->valueReal;
          push2(tok1);return 0;
  case 1 : if (tok1->valueReal==0)
     return 14;
    tok1->valueReal=tok2->valueReal/tok1->valueReal;
    push2(tok1);return 0;
  case 3 : tok1->valueReal=tok2->valueReal-tok1->valueReal;
        push2(tok1);return 0;
  case 2 : tok1->valueReal=tok2->valueReal+tok1->valueReal;
    push2(tok1);return 0;
 }
}

canonical_original_code:
unsigned int doOperation(int op) {
 struct token *tok1; struct token *tok2;
 pop2(&tok1);
 pop2(&tok2);
 if ((tok1->type!=3) || (tok2->type!=3))
  return 11;
 switch (op) {
  case 0 : tok1->valueReal=tok2->valueReal*tok1->valueReal;
          push2(tok1);return 0;
  case 1 : if (tok1->valueReal==0)
     return 14;
    tok1->valueReal=tok2->valueReal/tok1->valueReal;
    push2(tok1);return 0;
  case 3 : tok1->valueReal=tok2->valueReal-tok1->valueReal;
        push2(tok1);return 0;
  case 2 : tok1->valueReal=tok2->valueReal+tok1->valueReal;
    push2(tok1);return 0;
 }
}

variable_types: op int


doFunction

original_code:
errorHandler doFunction(int funct) {
 token *tok1;
 pop2(&tok1);
 errorHandler err;
 if (tok1->type!=3)
  return 11;
 switch(funct) {
  case 0 : tok1->valueReal*=tok1->valueReal;push2(tok1);return 0;
  case 1 : if (tok1->valueReal<0)
        return 15;
       tok1->valueReal=sqrt(tok1->valueReal);
       push2(tok1);
       return 0;
  case 2 : err=pCos(&tok1->valueReal);
      push2(tok1);
      return err;
  case 3 : err=pSin(&tok1->valueReal);
      push2(tok1);
      return err;
  case 4 : err=pTan(&tok1->valueReal);
      push2(tok1);
      return err;
  case 6 : tok1->valueReal=floor(tok1->valueReal);
      push2(tok1);
      return 0;
 }
 return 0;
}

canonical_original_code:
unsigned int doFunction(int funct) {
 struct token *tok1;
 pop2(&tok1);
 unsigned int err;
 if (tok1->type!=3)
  return 11;
 switch(funct) {
  case 0 : tok1->valueReal*=tok1->valueReal;push2(tok1);return 0;
  case 1 : if (tok1->valueReal<0)
        return 15;
       tok1->valueReal=sqrt(tok1->valueReal);
       push2(tok1);
       return 0;
  case 2 : err=pCos(&tok1->valueReal);
      push2(tok1);
      return err;
  case 3 : err=pSin(&tok1->valueReal);
      push2(tok1);
      return err;
  case 4 : err=pTan(&tok1->valueReal);
      push2(tok1);
      return err;
  case 6 : tok1->valueReal=floor(tok1->valueReal);
      push2(tok1);
      return 0;
 }
 return 0;
}

variable_types: funct int

variable_types:
err
unsigned int


calcul

decompiled_code:
__int64 __fastcall calcul(float *a1, _DWORD *a2)
{
__int16 v2; // ax
__int64 result; // rax
float v4; // xmm0_4
__int64 v5[3]; // [rsp+8h] [rbp-18h] BYREF

resetStack1();
LABEL_2:
while ( !(unsigned int)pop1(v5) )
{
while ( 1 )
{
v2 = *(_WORD *)v5[0];
if ( *(_WORD *)v5[0] == 2 )
{
result = doOperation(*(unsigned __int16 *)(v5[0] + 18));
goto LABEL_7;
}
if ( v2 != 3 )
break;
push2(v5[0]);
if ( (unsigned int)pop1(v5) )
goto LABEL_10;
}
if ( v2 != 1 )
goto LABEL_2;
result = doFunction(*(unsigned __int16 *)(v5[0] + 16));
LABEL_7:
if ( (_DWORD)result )
{
*a2 = *(_DWORD *)(v5[0] + 20);
return result;
}
}
LABEL_10:
pop2(v5);
v4 = *(double *)(v5[0] + 8);
*a1 = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(float *a1, _DWORD *a2)
{
__int16 v2; // ax
__int64 result; // rax
float v4; // xmm0_4
__int64 v5[3]; // [rsp+8h] [rbp-18h] BYREF

resetStack1();
LABEL_2:
while ( !(unsigned int)pop1(v5) )
{
while ( 1 )
{
v2 = *(_WORD *)v5[0];
if ( *(_WORD *)v5[0] == 2 )
{
result = func3(*(unsigned __int16 *)(v5[0] + 18));
goto LABEL_7;
}
if ( v2 != 3 )
break;
push2(v5[0]);
if ( (unsigned int)pop1(v5) )
goto LABEL_10;
}
if ( v2 != 1 )
goto LABEL_2;
result = func4(*(unsigned __int16 *)(v5[0] + 16));
LABEL_7:
if ( (_DWORD)result )
{
*a2 = *(_DWORD *)(v5[0] + 20);
return result;
}
}
LABEL_10:
pop2(v5);
v4 = *(double *)(v5[0] + 8);
*a1 = v4;
return 0LL;
}

original_code:
errorHandler calcul(float *result,int *offset) {
 errorHandler err=0,error=0;
 token *tok;
 resetStack1();
 err=pop1(&tok);
 while (!err)
 {
  switch (tok->type) {
   case 3 : push2(tok);break;
   case 2 :
           error=doOperation(tok->op);
          break;
   case 1 :
          error=doFunction(tok->function);
          break;
  }
  if (error) {
   *offset= tok->offset;
   return error;
  }
  err=pop1(&tok);
 }
 pop2(&tok);
 *result=tok->valueReal;
 return 0;
}

canonical_original_code:
unsigned int calcul(float *result, int *offset) {
 unsigned int err = 0; unsigned int error = 0;
 struct token *tok;
 resetStack1();
 err=pop1(&tok);
 while (!err)
 {
  switch (tok->type) {
   case 3 : push2(tok);break;
   case 2 :
           error=doOperation(tok->op);
          break;
   case 1 :
          error=doFunction(tok->function);
          break;
  }
  if (error) {
   *offset= tok->offset;
   return error;
  }
  err=pop1(&tok);
 }
 pop2(&tok);
 *result=tok->valueReal;
 return 0;
}

variable_types:
result
float *

variable_types:
error
unsigned int


decompiled_code:
__int64 __fastcall push1(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp1;
v2 = 4;
if ( sp1 <= 149 )
{
++bp1;
v2 = 0;
stack1[sp1] = a1;
sp1 = v1 + 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp1;
v2 = 4;
if ( sp1 <= 149 )
{
++bp1;
v2 = 0;
stack1[sp1] = a1;
sp1 = v1 + 1;
}
return v2;
}

original_code:
errorHandler push1(token *tok) {
 if (sp1<150)
 {
  stack1[sp1]=tok;
  sp1++;bp1++;
  return 0;
 }
 return 4;
}

canonical_original_code:
unsigned int push1(struct token *tok) {
 if (sp1<150)
 {
  stack1[sp1]=tok;
  sp1++;bp1++;
  return 0;
 }
 return 4;
}


decompiled_code:
__int64 __fastcall push2(__int64 a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp2;
v2 = 4;
if ( sp2 <= 149 )
{
v2 = 0;
stack2[sp2] = a1;
sp2 = v1 + 1;
}
return v2;
}

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

v1 = sp2;
v2 = 4;
if ( sp2 <= 149 )
{
v2 = 0;
stack2[sp2] = a1;
sp2 = v1 + 1;
}
return v2;
}

original_code:
errorHandler push2(token *tok){
 if (sp2<150){
  stack2[sp2]=tok;
  sp2++;
  return 0;
 }
 return 4;
}

canonical_original_code:
unsigned int push2(struct token *tok){
 if (sp2<150){
  stack2[sp2]=tok;
  sp2++;
  return 0;
 }
 return 4;
}


decompiled_code:
__int64 __fastcall pop2(_QWORD *a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp2;
v2 = 5;
if ( sp2 > 0 )
{
v2 = 0;
--sp2;
*a1 = stack2[v1 - 1];
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp2;
v2 = 5;
if ( sp2 > 0 )
{
v2 = 0;
--sp2;
*a1 = stack2[v1 - 1];
}
return v2;
}

original_code:
errorHandler pop2(token **tok) {
 if(sp2>0)
 {
  sp2--;
  (*tok)=stack2[sp2];
  return 0;
 }
 return 5;
}

canonical_original_code:
unsigned int pop2(struct token **tok) {
 if(sp2>0)
 {
  sp2--;
  (*tok)=stack2[sp2];
  return 0;
 }
 return 5;
}

variable_types: struct token { unsigned short type; double valueReal; unsigned short function; unsigned short op; int offset; } **


decompiled_code:
__int64 __fastcall pop1(_QWORD *a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp1;
v2 = 5;
if ( sp1 < bp1 )
{
v2 = 0;
*a1 = stack1[sp1];
sp1 = v1 + 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
int v1; // eax
unsigned int v2; // er8

v1 = sp1;
v2 = 5;
if ( sp1 < bp1 )
{
v2 = 0;
*a1 = stack1[sp1];
sp1 = v1 + 1;
}
return v2;
}

original_code:
errorHandler pop1(token **tok) {
 if(sp1<bp1)
 {
  (*tok)=stack1[sp1];
  sp1++;
  return 0;
 }
 return 5;
}

canonical_original_code:
unsigned int pop1(struct token **tok) {
 if(sp1<bp1)
 {
  (*tok)=stack1[sp1];
  sp1++;
  return 0;
 }
 return 5;
}


decompiled_code:
void resetStack1()
{
sp1 = 0;
}

canonical_decompiled_code:
void func4()
{
sp1 = 0;
}

original_code:
void resetStack1() {
 sp1=0;
}

canonical_original_code:
void resetStack1() {
 sp1=0;
}


decompiled_code:
void resetStack2()
{
sp2 = 0;
}

canonical_decompiled_code:
void func5()
{
sp2 = 0;
}

original_code:
void resetStack2() {
 sp2=0;
}

canonical_original_code:
void resetStack2() {
 sp2=0;
}


estPrioritaire

decompiled_code:
_BOOL8 __fastcall estPrioritaire(unsigned int a1)
{
return a1 <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
return a1 <= 1;
}

original_code:
int estPrioritaire(int op) {
 if ((op==0) || (op==1))
  return 1;
 return 0;
}


analyseOperation

decompiled_code:
__int64 __fastcall analyseOperation(int *a1, unsigned int a2, int a3)
{
__int64 result; // rax
int i; // er15
__int16 *v6; // r13

result = ((__int64 (*)(void))analyseExpression)();
if ( !(_DWORD)result )
{
for ( i = *a1; *a1 < (int)a2; i = *a1 )
{
v6 = &tabOfToken[12 * i];
if ( *v6 == 6 )
break;
if ( *v6 != 2 )
return 12LL;
if ( estPrioritaire((unsigned __int16)v6[9]) )
{
*a1 = i + 1;
result = analyseExpression(a1, a2);
if ( (_DWORD)result )
return result;
}
else
{
if ( a3 )
break;
*a1 = i + 1;
result = analyseOperation(a1, a2, 1LL);
if ( (_DWORD)result )
return result;
}
result = push1(v6);
if ( (_DWORD)result )
return result;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, unsigned int a2, int a3)
{
__int64 result; // rax
int i; // er15
__int16 *v6; // r13

result = ((__int64 (*)(void))analyseExpression)();
if ( !(_DWORD)result )
{
for ( i = *a1; *a1 < (int)a2; i = *a1 )
{
v6 = &tabOfToken[12 * i];
if ( *v6 == 6 )
break;
if ( *v6 != 2 )
return 12LL;
if ( func0((unsigned __int16)v6[9]) )
{
*a1 = i + 1;
result = func2(a1, a2);
if ( (_DWORD)result )
return result;
}
else
{
if ( a3 )
break;
*a1 = i + 1;
result = func1(a1, a2, 1LL);
if ( (_DWORD)result )
return result;
}
result = push1(v6);
if ( (_DWORD)result )
return result;
}
result = 0LL;
}
return result;
}

original_code:
errorHandler analyseOperation(int *offset,const int numberOfToken,int recursif) {
 token *tok;
 errorHandler error;
 error=analyseExpression(offset,numberOfToken);
 if (error)
  return error;
 while (*offset<numberOfToken) {
  tok=&tabOfToken[*offset];
  if (tok->type == 6) {
   return 0;
  }
  if(tok->type != 2)
   return 12;
  if(estPrioritaire(tok->op))
  {
   (*offset)++;
   error=analyseExpression(offset,numberOfToken);
   if (!error)
    error=push1(tok);
  } else {
   if(recursif)
    return 0;
   (*offset)++;
   error=analyseOperation(offset,numberOfToken,1);
   if (!error)
    error=push1(tok);
  }
  if(error)
   return error;
 }
 return 0;
}

canonical_original_code:
unsigned int analyseOperation(int *offset, int numberOfToken, int recursif) {
 struct token *tok;
 unsigned int error;
 error=analyseExpression(offset,numberOfToken);
 if (error)
  return error;
 while (*offset<numberOfToken) {
  tok=&tabOfToken[*offset];
  if (tok->type == 6) {
   return 0;
  }
  if(tok->type != 2)
   return 12;
  if(estPrioritaire(tok->op))
  {
   (*offset)++;
   error=analyseExpression(offset,numberOfToken);
   if (!error)
    error=push1(tok);
  } else {
   if(recursif)
    return 0;
   (*offset)++;
   error=analyseOperation(offset,numberOfToken,1);
   if (!error)
    error=push1(tok);
  }
  if(error)
   return error;
 }
 return 0;
}

variable_types: numberOfToken int

variable_types: recursif int


analyseExpression

decompiled_code:
__int64 __fastcall analyseExpression(int *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
__int16 v4; // dx
unsigned int v6; // er8
__int64 v7; // rdi
__int64 result; // rax
__int16 *v9; // rdi

v2 = *a1;
v3 = 12LL * *a1;
v4 = tabOfToken[v3];
if ( v4 != 3 )
{
if ( (unsigned __int16)v4 > 3u )
{
v6 = 11;
if ( v4 == 5 )
{
*a1 = v2 + 1;
LODWORD(result) = analyseOperation(a1, a2, 0);
++*a1;
return (unsigned int)result;
}
}
else
{
if ( v4 != 1 )
{
if ( v4 != 2 )
return 11;
v6 = 11;
v7 = 12LL * (v2 + 1);
if ( tabOfToken[v7] == 3 && tabOfToken[v3 + 9] == 3 )
{
v9 = &tabOfToken[v7];
*((_QWORD *)v9 + 1) ^= LC0;
push1(v9);
*a1 += 2;
v6 = 0;
}
return v6;
}
*a1 = v2 + 1;
v6 = analyseExpression(a1, a2);
if ( !v6 )
return push1(&tabOfToken[v3]);
}
return v6;
}
*a1 = v2 + 1;
push1(&tabOfToken[v3]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
__int16 v4; // dx
unsigned int v6; // er8
__int64 v7; // rdi
__int64 result; // rax
__int16 *v9; // rdi

v2 = *a1;
v3 = 12LL * *a1;
v4 = tabOfToken[v3];
if ( v4 != 3 )
{
if ( (unsigned __int16)v4 > 3u )
{
v6 = 11;
if ( v4 == 5 )
{
*a1 = v2 + 1;
LODWORD(result) = func1(a1, a2, 0);
++*a1;
return (unsigned int)result;
}
}
else
{
if ( v4 != 1 )
{
if ( v4 != 2 )
return 11;
v6 = 11;
v7 = 12LL * (v2 + 1);
if ( tabOfToken[v7] == 3 && tabOfToken[v3 + 9] == 3 )
{
v9 = &tabOfToken[v7];
*((_QWORD *)v9 + 1) ^= LC0;
push1(v9);
*a1 += 2;
v6 = 0;
}
return v6;
}
*a1 = v2 + 1;
v6 = func2(a1, a2);
if ( !v6 )
return push1(&tabOfToken[v3]);
}
return v6;
}
*a1 = v2 + 1;
push1(&tabOfToken[v3]);
return 0LL;
}

original_code:
errorHandler analyseExpression(int *offset,int numberOfToken) {
 int error=0;
 token *tok;
 switch (tabOfToken[(*offset)].type) {
  case 5 : (*offset)++;error=analyseOperation(offset,numberOfToken,0);(*offset)++;return error;
  case 3 : push1(&tabOfToken[(*offset)++]);return 0;
  case 1 : tok=&tabOfToken[(*offset)++];
    error=analyseExpression(offset,numberOfToken);
    if (error)
     return error;
    error=push1(tok);
    return error;
  case 2 : if ((tabOfToken[*offset+1].type==3) && (tabOfToken[*offset].op==3)) {
     tabOfToken[*offset+1].valueReal=-tabOfToken[*offset+1].valueReal;
     push1(&tabOfToken[*offset+1]);
     *offset+=2;
     return 0;
     }
 }
 return 11;
}

canonical_original_code:
unsigned int analyseExpression(int *offset, int numberOfToken) {
 int error = 0;
 struct token *tok;
 switch (tabOfToken[(*offset)].type) {
  case 5 : (*offset)++;error=analyseOperation(offset,numberOfToken,0);(*offset)++;return error;
  case 3 : push1(&tabOfToken[(*offset)++]);return 0;
  case 1 : tok=&tabOfToken[(*offset)++];
    error=analyseExpression(offset,numberOfToken);
    if (error)
     return error;
    error=push1(tok);
    return error;
  case 2 : if ((tabOfToken[*offset+1].type==3) && (tabOfToken[*offset].op==3)) {
     tabOfToken[*offset+1].valueReal=-tabOfToken[*offset+1].valueReal;
     push1(&tabOfToken[*offset+1]);
     *offset+=2;
     return 0;
     }
 }
 return 11;
}

variable_types: error int


printStack

decompiled_code:
__int64 printStack()
{
__int64 result; // rax
__int16 v1; // ax
unsigned __int16 v2; // ax
double *v3; // [rsp+8h] [rbp-8h] BYREF

resetStack1();
puts("\n\tEtat de la Pile");
LABEL_2:
while ( 1 )
{
result = pop1(&v3);
if ( (_DWORD)result )
return result;
while ( 1 )
{
v1 = *(_WORD *)v3;
if ( *(_WORD *)v3 == 2 )
break;
if ( v1 == 3 )
{
printf("\t\tREAL : %f\n", v3[1]);
goto LABEL_2;
}
if ( v1 != 1 )
goto LABEL_2;
printf("\t\tFunction : %i\n", *((unsigned __int16 *)v3 + 8));
result = pop1(&v3);
if ( (_DWORD)result )
return result;
}
printf("\t\tOPERATEUR : ");
v2 = *((_WORD *)v3 + 9);
if ( v2 == 2 )
{
puts("+");
}
else if ( v2 > 2u )
{
if ( v2 == 3 )
puts("-");
}
else if ( v2 )
{
puts("/");
}
else
{
puts("*");
}
}
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
__int16 v1; // ax
unsigned __int16 v2; // ax
double *v3; // [rsp+8h] [rbp-8h] BYREF

resetStack1();
puts("\n\tEtat de la Pile");
LABEL_2:
while ( 1 )
{
result = pop1(&v3);
if ( (_DWORD)result )
return result;
while ( 1 )
{
v1 = *(_WORD *)v3;
if ( *(_WORD *)v3 == 2 )
break;
if ( v1 == 3 )
{
printf("\t\tREAL : %f\n", v3[1]);
goto LABEL_2;
}
if ( v1 != 1 )
goto LABEL_2;
printf("\t\tFunction : %i\n", *((unsigned __int16 *)v3 + 8));
result = pop1(&v3);
if ( (_DWORD)result )
return result;
}
printf("\t\tOPERATEUR : ");
v2 = *((_WORD *)v3 + 9);
if ( v2 == 2 )
{
puts("+");
}
else if ( v2 > 2u )
{
if ( v2 == 3 )
puts("-");
}
else if ( v2 )
{
puts("/");
}
else
{
puts("*");
}
}
}

original_code:
void printStack() {
 int i=0;
 token *tok;
 resetStack1();
 printf("\n\tEtat de la Pile\n");
 i=pop1(&tok);
 while (i==0) {
  switch (tok->type) {
   case 2 : printf("\t\tOPERATEUR : ");
     switch (tok->op) {
      case 0 : printf("*\n");break;
      case 1 : printf("/\n");break;
      case 2 : printf("+\n");break;
      case 3 : printf("-\n");break;
     }
     break;
   case 3 : printf("\t\tREAL : %f\n",tok->valueReal);break;
   case 1 : printf("\t\tFunction : %i\n",tok->function);break;
  }
  i=pop1(&tok);
 }
}

canonical_original_code:
void printStack() {
 int i = 0;
 struct token *tok;
 resetStack1();
 printf("\n\tEtat de la Pile\n");
 i=pop1(&tok);
 while (i==0) {
  switch (tok->type) {
   case 2 : printf("\t\tOPERATEUR : ");
     switch (tok->op) {
      case 0 : printf("*\n");break;
      case 1 : printf("/\n");break;
      case 2 : printf("+\n");break;
      case 3 : printf("-\n");break;
     }
     break;
   case 3 : printf("\t\tREAL : %f\n",tok->valueReal);break;
   case 1 : printf("\t\tFunction : %i\n",tok->function);break;
  }
  i=pop1(&tok);
 }
}

variable_types: i int


analyseGrammaire

decompiled_code:
__int64 __fastcall analyseGrammaire(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
int v3; // ebx
unsigned int v4; // er12
int v5; // eax

if ( debug )
puts("\n############# Debut de l'analyse Grammaticale ##############");
*a1 = 0;
v1 = lastToken();
v2 = analyseOperation(a1, v1, 0);
v3 = *a1;
v4 = v2;
v5 = lastToken();
if ( !v4 && v3 < v5 )
v4 = 13;
if ( debug )
printStack();
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
int v3; // ebx
unsigned int v4; // er12
int v5; // eax

if ( debug )
puts("\n############# Debut de l'analyse Grammaticale ##############");
*a1 = 0;
v1 = lastToken();
v2 = func1(a1, v1, 0);
v3 = *a1;
v4 = v2;
v5 = lastToken();
if ( !v4 && v3 < v5 )
v4 = 13;
if ( debug )
func3();
return v4;
}

original_code:
errorHandler analyseGrammaire(int *offset){
 int error=0;
 if (debug)
  printf("\n############# Debut de l'analyse Grammaticale ##############\n");
 *offset=0;
 error=analyseOperation(offset,lastToken(),0);
 if (*offset<lastToken() && (!error))
  error=13;
 if (debug)
  printStack();
 return error;
}

canonical_original_code:
unsigned int analyseGrammaire(int *offset){
 int error = 0;
 if (debug)
  printf("\n############# Debut de l'analyse Grammaticale ##############\n");
 *offset=0;
 error=analyseOperation(offset,lastToken(),0);
 if (*offset<lastToken() && (!error))
  error=13;
 if (debug)
  printStack();
 return error;
}

variable_types:
offset
int *


litOpt

decompiled_code:
__int64 __fastcall litOpt(int argc, char **argv, _QWORD *a3, _DWORD *a4)
{
int v4; // ebx
int v7; // eax
__int64 result; // rax
int longind[13]; // [rsp+Ch] [rbp-34h] BYREF

v4 = 0;
silent = 0;
debug = 0;
longind[0] = 0;
*a4 = 0;
trigoDeg = 0;
while ( 1 )
{
while ( 1 )
{
++v4;
v7 = getopt_long(argc, argv, "dsht", &long_options_0, longind);
if ( v7 == 104 )
return 100LL;
if ( v7 <= 104 )
break;
if ( v7 == 115 )
{
silent = 1;
}
else
{
if ( v7 != 116 )
return 51LL;
trigoDeg = 1;
}
}
if ( v7 == -1 )
break;
if ( v7 != 100 )
return 51LL;
debug = 1;
}
if ( argc - 1 == v4 )
{
*a3 = argv[v4];
result = 0LL;
}
else
{
result = 101LL;
*a4 = v4 + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv, _QWORD *a3, _DWORD *a4)
{
int v4; // ebx
int v7; // eax
__int64 result; // rax
int longind[13]; // [rsp+Ch] [rbp-34h] BYREF

v4 = 0;
silent = 0;
debug = 0;
longind[0] = 0;
*a4 = 0;
trigoDeg = 0;
while ( 1 )
{
while ( 1 )
{
++v4;
v7 = getopt_long(argc, argv, "dsht", &long_options_0, longind);
if ( v7 == 104 )
return 100LL;
if ( v7 <= 104 )
break;
if ( v7 == 115 )
{
silent = 1;
}
else
{
if ( v7 != 116 )
return 51LL;
trigoDeg = 1;
}
}
if ( v7 == -1 )
break;
if ( v7 != 100 )
return 51LL;
debug = 1;
}
if ( argc - 1 == v4 )
{
*a3 = argv[v4];
result = 0LL;
}
else
{
result = 101LL;
*a4 = v4 + 1;
}
return result;
}

original_code:
errorHandler litOpt(int argc, char **argv,char **equ,int *ind) {
static struct option long_options[] =
{
 {"debug",0,0,'d'},
 {"silent",0,0,'s'},
 {"help",0,0,'h'},
 {"trigo-deg",0,0,'t'},
 {0,0,0,0}
};
 int opt,opt_index=0,option=0;
 debug=silent=0;
 *ind=0;
 option=0;
 trigoDeg=0;
 while (opt!=(-1))
 {
  opt = getopt_long(argc,argv,"dsht",long_options,&opt_index);
  option++;
  switch(opt) {
   case 'd' : debug=1;break;
   case 's' : silent=1;break;
   case 'h' : return 100;
   case 't' : trigoDeg=1; break;
   case (-1) : break;
   default : return 51;
  }
 }
 if((option==(argc-1)))
 {
  *equ=argv[option++];
  return 0;
 }
 *ind=option+1;
 return 101;
}

canonical_original_code:
unsigned int litOpt(int argc, char **argv, char **equ, int *ind) {
static struct option long_options[] = {
 {"debug",0,0,'d'},
 {"silent",0,0,'s'},
 {"help",0,0,'h'},
 {"trigo-deg",0,0,'t'},
 {0,0,0,0}
};
 int opt; int opt_index = 0; int option = 0;
 debug=silent=0;
 *ind=0;
 option=0;
 trigoDeg=0;
 while (opt!=(-1))
 {
  opt = getopt_long(argc,argv,"dsht",long_options,&opt_index);
  option++;
  switch(opt) {
   case 'd' : debug=1;break;
   case 's' : silent=1;break;
   case 'h' : return 100;
   case 't' : trigoDeg=1; break;
   case (-1) : break;
   default : return 51;
  }
 }
 if((option==(argc-1)))
 {
  *equ=argv[option++];
  return 0;
 }
 *ind=option+1;
 return 101;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
equ
char **

variable_types:
ind
int *

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

variable_types: opt int

variable_types: option int


errorToStr

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

result = messDefault;
if ( a1 <= 0x10 )
result = (char *)*(&messErreur + a1);
return result;
}

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

result = messDefault;
if ( a1 <= 0x10 )
result = (char *)*(&messErreur + a1);
return result;
}

original_code:
char *errorToStr(errorHandler error) {
 if ((error>=0) && (error<=16))
  return messErreur[error];
 return messDefault;
}

canonical_original_code:
char *errorToStr(unsigned int error) {
 if ((error>=0) && (error<=16))
  return messErreur[error];
 return messDefault;
}


showRef

decompiled_code:
int __fastcall showRef(const char *a1, int a2)
{
int v2; // ebx

puts(a1);
if ( a2 > 0 )
{
v2 = 1;
do
{
++v2;
putchar(32);
}
while ( v2 != a2 + 1 );
}
return puts("^");
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, int a2)
{
int v2; // ebx

puts(a1);
if ( a2 > 0 )
{
v2 = 1;
do
{
++v2;
putchar(32);
}
while ( v2 != a2 + 1 );
}
return puts("^");
}

original_code:
char *showRef(char *chaine, int offset) {
 int i=0;
 printf("%s\n",chaine);
 while (i++ < offset)
  printf(" ");
 printf("^\n");
}

canonical_original_code:
char *showRef(char *chaine, int offset) {
 int i = 0;
 printf("%s\n",chaine);
 while (i++ < offset)
  printf(" ");
 printf("^\n");
}

variable_types:
chaine
char *

variable_types: offset int


FatalError

decompiled_code:
void __fastcall __noreturn FatalError(const char *a1)
{
printf("Fatal Error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("Fatal Error: %s\n", a1);
exit(1);
}

original_code:
void FatalError(char *sb)
{
    int cc;
    cc = printf("Fatal Error: %s\n", sb);
    exit(1);
}

variable_types:
sb
char *

variable_types: cc int


decompiled_code:
int __fastcall yy_stack_print(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbx
__int64 v3; // rdx

v2 = a1;
fwrite("Stack now", 1uLL, 9uLL, stderr);
if ( (unsigned __int64)a1 <= a2 )
{
do
{
v3 = (unsigned int)*v2++;
fprintf(stderr, " %d", v3);
}
while ( a2 >= (unsigned __int64)v2 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func0(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbx
__int64 v3; // rdx

v2 = a1;
fwrite("Stack now", 1uLL, 9uLL, stderr);
if ( (unsigned __int64)a1 <= a2 )
{
do
{
v3 = (unsigned int)*v2++;
fprintf(stderr, " %d", v3);
}
while ( a2 >= (unsigned __int64)v2 );
}
return fputc(10, stderr);
}

original_code:
static void
yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
{
  fprintf (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      fprintf (stderr, " %d", yybot);
    }
  fprintf (stderr, "\n");
}

canonical_original_code:
static void yy_stack_print(short *yybottom, short *yytop)
{
  fprintf (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      fprintf (stderr, " %d", yybot);
    }
  fprintf (stderr, "\n");
}

variable_types:
yybottom
short *

variable_types:
yytop
short *

variable_types: yybot int