decompiled_code:
__int64 __fastcall ftp_connect(__int64 a1)
{
unsigned int v1; // eax

v1 = socket_create_tcp();
*(_DWORD *)(a1 + 132) = v1;
socket_set_nonblock(v1);
if ( (unsigned int)socket_connect(*(unsigned int *)(a1 + 132), a1, *(unsigned __int16 *)(a1 + 128)) )
return 0xFFFFFFFFLL;
socket_set_block(*(unsigned int *)(a1 + 132));
if ( ftp_get_response(a1) != 220 )
return 0xFFFFFFFFLL;
socket_clear_recv_buffer(*(unsigned int *)(a1 + 132));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v1; // eax

v1 = socket_create_tcp();
*(_DWORD *)(a1 + 132) = v1;
socket_set_nonblock(v1);
if ( (unsigned int)socket_connect(*(unsigned int *)(a1 + 132), a1, *(unsigned __int16 *)(a1 + 128)) )
return 0xFFFFFFFFLL;
socket_set_block(*(unsigned int *)(a1 + 132));
if ( func1(a1) != 220 )
return 0xFFFFFFFFLL;
socket_clear_recv_buffer(*(unsigned int *)(a1 + 132));
return 0LL;
}

original_code:
static int ftp_connect(struct ftp_connect *ftp_client)
{
        int ret = -1;
        ftp_client->control_fd = socket_create_tcp();
        socket_set_nonblock(ftp_client->control_fd);
        ret = socket_connect(ftp_client->control_fd, ftp_client->hostname,
                                ftp_client->control_port);
        if (ret) {
                return -1;
        }
        socket_set_block(ftp_client->control_fd);
        if (ftp_get_response(ftp_client) == RES_CONNECT_SUCCESS) {
                socket_clear_recv_buffer(ftp_client->control_fd);
                return 0;
        }
        return -1;
}


processSignal

decompiled_code:
void __fastcall processSignal(unsigned int a1)
{
printf("signal %d\n", a1);
signal(a1, processSignal);
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1)
{
printf("signal %d\n", a1);
signal(a1, processSignal);
}

original_code:
static void processSignal(int signo)
{
        printf("signal %d\n", signo);
        signal(signo, processSignal);
}

variable_types: signo int

return_type: void


original_code:
static void ftp_cmd_init(void)
{
        int size = sizeof(struct _ftp_cmd) * MaxIndex;
        ftp_cmd = (struct _ftp_cmd *)malloc(size);
        bzero(ftp_cmd, size);
        ftp_cmd[0].cmd = "USER";
        ftp_cmd[0].response_code = RES_REQUIRE_PASSWORD;
        ftp_cmd[1].cmd = "PASS";
        ftp_cmd[1].response_code = RES_LOGIN_PASS;
        ftp_cmd[2].cmd = "QUIT";
        ftp_cmd[2].response_code = RES_QUIT_SUCCESS;
        ftp_cmd[3].cmd = "PWD";
        ftp_cmd[3].response_code = RES_PWD;
        ftp_cmd[4].cmd = "MKD";
        ftp_cmd[4].response_code = RES_MKDIR;
        ftp_cmd[5].cmd = "CWD";
        ftp_cmd[5].response_code = RES_CHANGE_DIR;
        ftp_cmd[6].cmd = "STOR";
        ftp_cmd[6].response_code = RES_UPLOAD;
        ftp_cmd[7].cmd = "TYPE I";
        ftp_cmd[7].response_code = RES_EXCUTE_SUCCESS;
        ftp_cmd[8].cmd = "PASV";
        ftp_cmd[8].response_code = RES_PASSIVE;
        ftp_cmd[9].cmd = "PORT";
        ftp_cmd[9].response_code = RES_EXCUTE_SUCCESS;
        ftp_cmd[10].cmd = "SIZE";
        ftp_cmd[10].response_code = RES_UPLOADED_SIZE;
        ftp_cmd[11].cmd = "REST";
        ftp_cmd[11].response_code = RES_REST_POSITION;
        kInit = 1;
}

canonical_original_code:
static void ftp_cmd_init()
{
        int size = sizeof(struct _ftp_cmd) * MaxIndex;
        ftp_cmd = (struct _ftp_cmd *)malloc(size);
        bzero(ftp_cmd, size);
        ftp_cmd[0].cmd = "USER";
        ftp_cmd[0].response_code = RES_REQUIRE_PASSWORD;
        ftp_cmd[1].cmd = "PASS";
        ftp_cmd[1].response_code = RES_LOGIN_PASS;
        ftp_cmd[2].cmd = "QUIT";
        ftp_cmd[2].response_code = RES_QUIT_SUCCESS;
        ftp_cmd[3].cmd = "PWD";
        ftp_cmd[3].response_code = RES_PWD;
        ftp_cmd[4].cmd = "MKD";
        ftp_cmd[4].response_code = RES_MKDIR;
        ftp_cmd[5].cmd = "CWD";
        ftp_cmd[5].response_code = RES_CHANGE_DIR;
        ftp_cmd[6].cmd = "STOR";
        ftp_cmd[6].response_code = RES_UPLOAD;
        ftp_cmd[7].cmd = "TYPE I";
        ftp_cmd[7].response_code = RES_EXCUTE_SUCCESS;
        ftp_cmd[8].cmd = "PASV";
        ftp_cmd[8].response_code = RES_PASSIVE;
        ftp_cmd[9].cmd = "PORT";
        ftp_cmd[9].response_code = RES_EXCUTE_SUCCESS;
        ftp_cmd[10].cmd = "SIZE";
        ftp_cmd[10].response_code = RES_UPLOADED_SIZE;
        ftp_cmd[11].cmd = "REST";
        ftp_cmd[11].response_code = RES_REST_POSITION;
        kInit = 1;
}

variable_types: size int

user_defined_types: struct _ftp_cmd { char *cmd; unsigned int response_code; }


decompiled_code:
__int64 __fastcall ftp_put_file_pasv(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // eax
int v4; // er12
unsigned int v5; // [rsp+Ch] [rbp-6Ch] BYREF
char v6[64]; // [rsp+10h] [rbp-68h] BYREF
unsigned int v7; // [rsp+50h] [rbp-28h]

v5 = 0;
result = ftp_get_file_size_constprop_0(a1, a2, (int *)&v5);
if ( (_DWORD)result != -1 )
{
result = 0LL;
if ( *(_DWORD *)(a2 + 520) > v5 )
{
ftp_get_passive_isra_0(a1, (__int64)v6);
v3 = socket_create_tcp();
*(_DWORD *)(a1 + 136) = v3;
socket_set_nonblock(v3);
v4 = socket_connect(*(unsigned int *)(a1 + 136), v6, v7);
socket_set_block(*(unsigned int *)(a1 + 136));
if ( v4 )
{
socket_close(*(unsigned int *)(a1 + 136));
puts("connect failed");
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)ftp_send_cmd(6, (const char *)(a2 + 256), a1) )
{
puts("send command failed");
result = 0xFFFFFFFFLL;
}
else
{
socket_write(*(unsigned int *)(a1 + 136), *(_QWORD *)(a2 + 512) + (int)v5, *(_DWORD *)(a2 + 520) - v5, 2000LL);
socket_close(*(unsigned int *)(a1 + 136));
result = (unsigned int)-(ftp_get_response(a1) != 226);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned int v3; // eax
int v4; // er12
unsigned int v5; // [rsp+Ch] [rbp-6Ch] BYREF
char v6[64]; // [rsp+10h] [rbp-68h] BYREF
unsigned int v7; // [rsp+50h] [rbp-28h]

v5 = 0;
result = func11(a1, a2, (int *)&v5);
if ( (_DWORD)result != -1 )
{
result = 0LL;
if ( *(_DWORD *)(a2 + 520) > v5 )
{
func12(a1, (__int64)v6);
v3 = socket_create_tcp();
*(_DWORD *)(a1 + 136) = v3;
socket_set_nonblock(v3);
v4 = socket_connect(*(unsigned int *)(a1 + 136), v6, v7);
socket_set_block(*(unsigned int *)(a1 + 136));
if ( v4 )
{
socket_close(*(unsigned int *)(a1 + 136));
puts("connect failed");
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)func2(6, (const char *)(a2 + 256), a1) )
{
puts("send command failed");
result = 0xFFFFFFFFLL;
}
else
{
socket_write(*(unsigned int *)(a1 + 136), *(_QWORD *)(a2 + 512) + (int)v5, *(_DWORD *)(a2 + 520) - v5, 2000LL);
socket_close(*(unsigned int *)(a1 + 136));
result = (unsigned int)-(func1(a1) != 226);
}
}
}
return result;
}

original_code:
static int ftp_put_file_pasv(struct ftp_connect *client,
                                struct file_description *file)
{
        int exist_size = 0;
        int ret = ftp_get_file_size(client, file, &exist_size);
        if (ret == -1) {
                return -1;
        }
        if (exist_size >= file->file_size) {
                return 0;
        }
        struct _data_connect data_connect;
        ftp_get_passive(client, &data_connect);
        client->data_fd = socket_create_tcp();
        socket_set_nonblock(client->data_fd);
        ret = socket_connect(client->data_fd, data_connect.addr,
                                        data_connect.port);
        socket_set_block(client->data_fd);
        if (ret) {
                socket_close(client->data_fd);
                printf("connect failed\n");
                return -1;
        }
        ret = ftp_send_cmd(Upload, file->file_name, client);
        if (ret) {
                printf("send command failed\n");
                return -1;
        }
        ret = socket_write(client->data_fd, file->file_buffer + exist_size,
                                file->file_size - exist_size, kSocketTimeout);
        socket_close(client->data_fd);
        int response_code = ftp_get_response(client);
        if (response_code == RES_TRANSFER_OK) {
                return 0;
        } else {
                return -1;
        }
}

variable_types: struct ftp_connect { char hostname[64]; char username[32]; char password[32]; unsigned short control_port; int control_fd; int data_fd; int mode; } *

variable_types: struct file_description { char remote_dir[256]; char file_name[256]; char *file_buffer; unsigned int file_size; } *

variable_types: ret int

variable_types: struct _data_connect { char addr[64]; unsigned int port; }

return_type: int


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

result = ftp_send_cmd(7, 0LL, a1);
if ( (unsigned int)(result + 2) > 1 )
{
if ( *(_DWORD *)(a1 + 140) )
result = ftp_put_file_port(a1, a2);
else
result = ftp_put_file_pasv(a1, a2);
}
return result;
}

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

result = func2(7, 0LL, a1);
if ( (unsigned int)(result + 2) > 1 )
{
if ( *(_DWORD *)(a1 + 140) )
result = func0(a1, a2);
else
result = func13(a1, a2);
}
return result;
}

original_code:
static int ftp_put_file(struct ftp_connect *client,
                                struct file_description *file)
{
        int ret = ftp_send_cmd(FileType, ((void *)0), client);
        if (ret == -1 ||
                ret == -2) {
                return ret;
        }
        if (client->mode) {
                ret = ftp_put_file_port(client, file);
        } else {
                ret = ftp_put_file_pasv(client, file);
        }
        return ret;
}

user_defined_types: struct ftp_connect { char hostname[64]; char username[32]; char password[32]; unsigned short control_port; int control_fd; int data_fd; int mode; }

user_defined_types: struct file_description { char remote_dir[256]; char file_name[256]; char *file_buffer; unsigned int file_size; }


decompiled_code:
__int64 __fastcall ftp_upload(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

if ( (unsigned int)ftp_change_dir(a1, a2) )
result = 0xFFFFFFFFLL;
else
result = ftp_put_file(a1, (__int64)a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

if ( (unsigned int)func6(a1, a2) )
result = 0xFFFFFFFFLL;
else
result = func14(a1, (__int64)a2);
return result;
}

original_code:
int ftp_upload(struct ftp_connect *client, struct file_description *file)
{
        int ret = ftp_change_dir(client, file->remote_dir);
        if (ret) {
                return -1;
        }
        return ftp_put_file(client, file);
}


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

if ( (unsigned int)ftp_connect(a1) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-((unsigned int)ftp_login(a1) != 0);
return result;
}

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

if ( (unsigned int)func8(a1) )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-((unsigned int)func7(a1) != 0);
return result;
}

original_code:
int ftp_open(struct ftp_connect *client)
{
        int ret = ftp_connect(client);
        if (ret) {
                return -1;
        }
        ret = ftp_login(client);
        if (ret) {
                return -1;
        }
        return 0;
}


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

if ( !a1 )
return 0xFFFFFFFFLL;
socket_close(*(unsigned int *)(a1 + 132));
socket_close(*(unsigned int *)(a1 + 136));
result = 0LL;
*(_QWORD *)(a1 + 132) = -1LL;
return result;
}

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

if ( !a1 )
return 0xFFFFFFFFLL;
socket_close(*(unsigned int *)(a1 + 132));
socket_close(*(unsigned int *)(a1 + 136));
result = 0LL;
*(_QWORD *)(a1 + 132) = -1LL;
return result;
}

original_code:
int ftp_close(struct ftp_connect *client)
{
        if (client == ((void *)0)) {
                return -1;
        }
        socket_close(client->control_fd);
        socket_close(client->data_fd);
        client->control_fd = -1;
        client->data_fd = -1;
        return 0;
}


decompiled_code:
__sighandler_t ftp_init()
{
ftp_cmd_init();
return signal(13, (__sighandler_t)processSignal);
}

canonical_decompiled_code:
__sighandler_t func18()
{
func10();
return signal(13, (__sighandler_t)processSignal);
}

original_code:
void ftp_init(void)
{
        ftp_cmd_init();
        signal(13, processSignal);
}

canonical_original_code:
void ftp_init()
{
        ftp_cmd_init();
        signal(13, processSignal);
}


decompiled_code:
void ftp_release()
{
free(ftp_cmd);
ftp_cmd = 0LL;
}

canonical_decompiled_code:
void func19()
{
free(ftp_cmd);
ftp_cmd = 0LL;
}

original_code:
void ftp_release(void)
{
        free(ftp_cmd);
        ftp_cmd = ((void *)0);
}

canonical_original_code:
void ftp_release()
{
        free(ftp_cmd);
        ftp_cmd = ((void *)0);
}


repo: bedops/bedops

decompiled_code:
int *get_crc_table()
{
return crc_table;
}

canonical_decompiled_code:
int *func4()
{
return crc_table;
}

original_code:
const z_crc_t * get_crc_table()
{
    return (const z_crc_t *)crc_table;
}

canonical_original_code:
unsigned int *get_crc_table()
{
    return (unsigned int *)crc_table;
}

return_type: unsigned int *


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
fprintf(stderr, "%s: %s\n", (const char *)prog, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s: %s\n", (const char *)prog, a1);
exit(1);
}

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

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

variable_types:
msg
char *


original_code:
void BZ2_hbMakeCodeLengths ( UChar *len,
                             Int32 *freq,
                             Int32 alphaSize,
                             Int32 maxLen )
{
   Int32 nNodes, nHeap, n1, n2, i, j, k;
   Bool tooLong;
   Int32 heap [ 258 + 2 ];
   Int32 weight [ 258 * 2 ];
   Int32 parent [ 258 * 2 ];
   for (i = 0; i < alphaSize; i++)
      weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
   while (((Bool)1)) {
      nNodes = alphaSize;
      nHeap = 0;
      heap[0] = 0;
      weight[0] = 0;
      parent[0] = -2;
      for (i = 1; i <= alphaSize; i++) {
         parent[i] = -1;
         nHeap++;
         heap[nHeap] = i;
         { Int32 zz, tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) { heap[zz] = heap[zz >> 1]; zz >>= 1; } heap[zz] = tmp; };
      }
      { if (!(nHeap < (258 +2))) BZ2_bz__AssertH__fail ( 2001 ); };
      while (nHeap > 1) {
         n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; { Int32 zz, yy, tmp; zz = 1; tmp = heap[zz]; while (((Bool)1)) { yy = zz << 1; if (yy > nHeap) break; if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) yy++; if (weight[tmp] < weight[heap[yy]]) break; heap[zz] = heap[yy]; zz = yy; } heap[zz] = tmp; };
         n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; { Int32 zz, yy, tmp; zz = 1; tmp = heap[zz]; while (((Bool)1)) { yy = zz << 1; if (yy > nHeap) break; if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) yy++; if (weight[tmp] < weight[heap[yy]]) break; heap[zz] = heap[yy]; zz = yy; } heap[zz] = tmp; };
         nNodes++;
         parent[n1] = parent[n2] = nNodes;
         weight[nNodes] = (((weight[n1]) & 0xffffff00)+((weight[n2]) & 0xffffff00)) | (1 + ((((weight[n1]) & 0x000000ff)) > (((weight[n2]) & 0x000000ff)) ? (((weight[n1]) & 0x000000ff)) : (((weight[n2]) & 0x000000ff))));
         parent[nNodes] = -1;
         nHeap++;
         heap[nHeap] = nNodes;
         { Int32 zz, tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) { heap[zz] = heap[zz >> 1]; zz >>= 1; } heap[zz] = tmp; };
      }
      { if (!(nNodes < (258 * 2))) BZ2_bz__AssertH__fail ( 2002 ); };
      tooLong = ((Bool)0);
      for (i = 1; i <= alphaSize; i++) {
         j = 0;
         k = i;
         while (parent[k] >= 0) { k = parent[k]; j++; }
         len[i-1] = j;
         if (j > maxLen) tooLong = ((Bool)1);
      }
      if (! tooLong) break;
      for (i = 1; i <= alphaSize; i++) {
         j = weight[i] >> 8;
         j = 1 + (j / 2);
         weight[i] = j << 8;
      }
   }
}

canonical_original_code:
void BZ2_hbMakeCodeLengths(unsigned char *len, int *freq, int alphaSize, int maxLen)
{
   int nNodes; int nHeap; int n1; int n2; int i; int j; int k;
   unsigned char tooLong;
   int heap[-1];
   int weight[-1];
   int parent[-1];
   for (i = 0; i < alphaSize; i++)
      weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
   while (((unsigned char)1)) {
      nNodes = alphaSize;
      nHeap = 0;
      heap[0] = 0;
      weight[0] = 0;
      parent[0] = -2;
      for (i = 1; i <= alphaSize; i++) {
         parent[i] = -1;
         nHeap++;
         heap[nHeap] = i;
         { int zz; int tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) { heap[zz] = heap[zz >> 1]; zz >>= 1; } heap[zz] = tmp; };
      }
      { if (!(nHeap < (258 +2))) BZ2_bz__AssertH__fail ( 2001 ); };
      while (nHeap > 1) {
         n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; { int zz; int yy; int tmp; zz = 1; tmp = heap[zz]; while (((unsigned char)1)) { yy = zz << 1; if (yy > nHeap) break; if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) yy++; if (weight[tmp] < weight[heap[yy]]) break; heap[zz] = heap[yy]; zz = yy; } heap[zz] = tmp; };
         n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; { int zz; int yy; int tmp; zz = 1; tmp = heap[zz]; while (((unsigned char)1)) { yy = zz << 1; if (yy > nHeap) break; if (yy < nHeap && weight[heap[yy+1]] < weight[heap[yy]]) yy++; if (weight[tmp] < weight[heap[yy]]) break; heap[zz] = heap[yy]; zz = yy; } heap[zz] = tmp; };
         nNodes++;
         parent[n1] = parent[n2] = nNodes;
         weight[nNodes] = (((weight[n1]) & 0xffffff00)+((weight[n2]) & 0xffffff00)) | (1 + ((((weight[n1]) & 0x000000ff)) > (((weight[n2]) & 0x000000ff)) ? (((weight[n1]) & 0x000000ff)) : (((weight[n2]) & 0x000000ff))));
         parent[nNodes] = -1;
         nHeap++;
         heap[nHeap] = nNodes;
         { int zz; int tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) { heap[zz] = heap[zz >> 1]; zz >>= 1; } heap[zz] = tmp; };
      }
      { if (!(nNodes < (258 * 2))) BZ2_bz__AssertH__fail ( 2002 ); };
      tooLong = ((unsigned char)0);
      for (i = 1; i <= alphaSize; i++) {
         j = 0;
         k = i;
         while (parent[k] >= 0) { k = parent[k]; j++; }
         len[i-1] = j;
         if (j > maxLen) tooLong = ((unsigned char)1);
      }
      if (! tooLong) break;
      for (i = 1; i <= alphaSize; i++) {
         j = weight[i] >> 8;
         j = 1 + (j / 2);
         weight[i] = j << 8;
      }
   }
}

variable_types:
len
unsigned char *

variable_types:
freq
int *

variable_types: alphaSize int

variable_types: maxLen int

variable_types: nNodes int

variable_types: nHeap int

variable_types: i int

variable_types: j int

variable_types: k int

variable_types:
tooLong
unsigned char

variable_types:
heap
int [-1]

variable_types:
weight
int [-1]

variable_types:
parent
int [-1]

variable_types: zz int

variable_types: tmp int

variable_types: yy int


original_code:
void BZ2_hbAssignCodes ( Int32 *code,
                         UChar *length,
                         Int32 minLen,
                         Int32 maxLen,
                         Int32 alphaSize )
{
   Int32 n, vec, i;
   vec = 0;
   for (n = minLen; n <= maxLen; n++) {
      for (i = 0; i < alphaSize; i++)
         if (length[i] == n) { code[i] = vec; vec++; };
      vec <<= 1;
   }
}

canonical_original_code:
void BZ2_hbAssignCodes(int *code, unsigned char *length, int minLen, int maxLen, int alphaSize)
{
   int n; int vec; int i;
   vec = 0;
   for (n = minLen; n <= maxLen; n++) {
      for (i = 0; i < alphaSize; i++)
         if (length[i] == n) { code[i] = vec; vec++; };
      vec <<= 1;
   }
}

variable_types:
code
int *

variable_types:
length
unsigned char *

variable_types: minLen int

variable_types: n int

variable_types: vec int


original_code:
void BZ2_hbCreateDecodeTables ( Int32 *limit,
                                Int32 *base,
                                Int32 *perm,
                                UChar *length,
                                Int32 minLen,
                                Int32 maxLen,
                                Int32 alphaSize )
{
   Int32 pp, i, j, vec;
   pp = 0;
   for (i = minLen; i <= maxLen; i++)
      for (j = 0; j < alphaSize; j++)
         if (length[j] == i) { perm[pp] = j; pp++; };
   for (i = 0; i < 23; i++) base[i] = 0;
   for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
   for (i = 1; i < 23; i++) base[i] += base[i-1];
   for (i = 0; i < 23; i++) limit[i] = 0;
   vec = 0;
   for (i = minLen; i <= maxLen; i++) {
      vec += (base[i+1] - base[i]);
      limit[i] = vec-1;
      vec <<= 1;
   }
   for (i = minLen + 1; i <= maxLen; i++)
      base[i] = ((limit[i-1] + 1) << 1) - base[i];
}

canonical_original_code:
void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *length, int minLen, int maxLen, int alphaSize)
{
   int pp; int i; int j; int vec;
   pp = 0;
   for (i = minLen; i <= maxLen; i++)
      for (j = 0; j < alphaSize; j++)
         if (length[j] == i) { perm[pp] = j; pp++; };
   for (i = 0; i < 23; i++) base[i] = 0;
   for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
   for (i = 1; i < 23; i++) base[i] += base[i-1];
   for (i = 0; i < 23; i++) limit[i] = 0;
   vec = 0;
   for (i = minLen; i <= maxLen; i++) {
      vec += (base[i+1] - base[i]);
      limit[i] = vec-1;
      vec <<= 1;
   }
   for (i = minLen + 1; i <= maxLen; i++)
      base[i] = ((limit[i-1] + 1) << 1) - base[i];
}

variable_types:
limit
int *

variable_types:
base
int *

variable_types:
perm
int *

variable_types: maxLen int

variable_types: alphaSize int

variable_types: pp int


gzprintf

decompiled_code:
int gzprintf(__int64 a1, const char *a2, ...)
{
size_t v3; // rbp
char *v4; // rdi
int result; // eax
__int64 v6; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

if ( !a1 )
return -1;
if ( *(_DWORD *)(a1 + 24) != 31153
|| *(_DWORD *)(a1 + 108)
|| !*(_DWORD *)(a1 + 40) && (unsigned int)gz_init(a1) == -1 )
{
return 0;
}
if ( *(_DWORD *)(a1 + 104) )
{
*(_DWORD *)(a1 + 104) = 0;
if ( (unsigned int)gz_zero(a1, *(_QWORD *)(a1 + 96)) == -1 )
return 0;
}
if ( *(_DWORD *)(a1 + 128) && (unsigned int)gz_comp(a1, 0) == -1 )
return 0;
v3 = *(int *)(a1 + 40);
*(_BYTE *)(*(_QWORD *)(a1 + 48) + v3 - 1) = 0;
v4 = *(char **)(a1 + 48);
va_start(arg, a2);
result = vsnprintf(v4, v3, a2, arg);
if ( result <= 0 )
return 0;
if ( (int)v3 <= result )
return 0;
v6 = *(_QWORD *)(a1 + 48);
if ( *(_BYTE *)(v6 + v3 - 1) )
return 0;
*(_QWORD *)(a1 + 120) = v6;
*(_QWORD *)(a1 + 16) += result;
*(_DWORD *)(a1 + 128) = result;
return result;
}

original_code:
int gzprintf (gzFile file, const char *format, ...)
{
    int size, len;
    gz_statep state;
    z_streamp strm;
    va_list va;
    if (file == ((void *)0))
        return -1;
    state = (gz_statep)file;
    strm = &(state->strm);
    if (state->mode != 31153 || state->err != 0)
        return 0;
    if (state->size == 0 && gz_init(state) == -1)
        return 0;
    if (state->seek) {
        state->seek = 0;
        if (gz_zero(state, state->skip) == -1)
            return 0;
    }
    if (strm->avail_in && gz_comp(state, 0) == -1)
        return 0;
    size = (int)(state->size);
    state->in[size - 1] = 0;
    __builtin_va_start(va,format);
    len = vsnprintf((char *)(state->in), size, format, va);
    __builtin_va_end(va);
    if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
        return 0;
    strm->avail_in = (unsigned)len;
    strm->next_in = state->in;
    state->x.pos += len;
    return len;
}

canonical_original_code:
int gzprintf(struct gzFile_s *file, char *format, ...)
{
    int size; int len;
    struct gz_state *state;
    struct z_stream_s *strm;
    __builtin_va_list va;
    if (file == ((void *)0))
        return -1;
    state = (struct gz_state *)file;
    strm = &(state->strm);
    if (state->mode != 31153 || state->err != 0)
        return 0;
    if (state->size == 0 && gz_init(state) == -1)
        return 0;
    if (state->seek) {
        state->seek = 0;
        if (gz_zero(state, state->skip) == -1)
            return 0;
    }
    if (strm->avail_in && gz_comp(state, 0) == -1)
        return 0;
    size = (int)(state->size);
    state->in[size - 1] = 0;
    __builtin_va_start(va,format);
    len = vsnprintf((char *)(state->in), size, format, va);
    __builtin_va_end(va);
    if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
        return 0;
    strm->avail_in = (unsigned int)len;
    strm->next_in = state->in;
    state->x.pos += len;
    return len;
}

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *

variable_types:
format
char *

variable_types: size int

variable_types: len int

variable_types: struct gz_state { struct gzFile_s { unsigned int have; unsigned char *next; long pos; } x; int mode; int fd; char *path; unsigned int size; unsigned int want; unsigned char *in; unsigned char *out; int direct; int how; long start; int eof; int past; int level; int strategy; long skip; int seek; int err; char *msg; struct z_stream_s { unsigned char *next_in; unsigned int avail_in; unsigned long total_in; unsigned char *next_out; unsigned int avail_out; unsigned long total_out; char *msg; struct internal_state { int dummy; } *state; void *(*zalloc)(void *opaque, unsigned int items, unsigned int size); void (*zfree)(void *opaque, void *address); void *opaque; int data_type; unsigned long adler; unsigned long reserved; } strm; } *

variable_types: struct z_stream_s { unsigned char *next_in; unsigned int avail_in; unsigned long total_in; unsigned char *next_out; unsigned int avail_out; unsigned long total_out; char *msg; struct internal_state { int dummy; } *state; void *(*zalloc)(void *opaque, unsigned int items, unsigned int size); void (*zfree)(void *opaque, void *address); void *opaque; int data_type; unsigned long adler; unsigned long reserved; } *

user_defined_types: struct gz_state { struct gzFile_s x; int mode; int fd; char *path; unsigned int size; unsigned int want; unsigned char *in; unsigned char *out; int direct; int how; long start; int eof; int past; int level; int strategy; long skip; int seek; int err; char *msg; struct z_stream_s strm; }

user_defined_types: struct z_stream_s { unsigned char *next_in; unsigned int avail_in; unsigned long total_in; unsigned char *next_out; unsigned int avail_out; unsigned long total_out; char *msg; struct internal_state *state; void *(*zalloc)(void *opaque, unsigned int items, unsigned int size); void (*zfree)(void *opaque, void *address); void *opaque; int data_type; unsigned long adler; unsigned long reserved; }


zlibVersion

decompiled_code:
const char *zlibVersion()
{
return "1.2.7";
}

canonical_decompiled_code:
const char *func0()
{
return "1.2.7";
}

original_code:
const char * zlibVersion()
{
    return "1.2.7";
}

canonical_original_code:
char *zlibVersion()
{
    return "1.2.7";
}

return_type: char *


zlibCompileFlags

decompiled_code:
__int64 zlibCompileFlags()
{
return 169LL;
}

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

original_code:
uLong zlibCompileFlags()
{
    uLong flags;
    flags = 0;
    switch ((int)(sizeof(uInt))) {
    case 2: break;
    case 4: flags += 1; break;
    case 8: flags += 2; break;
    default: flags += 3;
    }
    switch ((int)(sizeof(uLong))) {
    case 2: break;
    case 4: flags += 1 << 2; break;
    case 8: flags += 2 << 2; break;
    default: flags += 3 << 2;
    }
    switch ((int)(sizeof(voidpf))) {
    case 2: break;
    case 4: flags += 1 << 4; break;
    case 8: flags += 2 << 4; break;
    default: flags += 3 << 4;
    }
    switch ((int)(sizeof(off_t))) {
    case 2: break;
    case 4: flags += 1 << 6; break;
    case 8: flags += 2 << 6; break;
    default: flags += 3 << 6;
    }
    return flags;
}

canonical_original_code:
unsigned long zlibCompileFlags()
{
    unsigned long flags;
    flags = 0;
    switch ((int)(sizeof(uInt))) {
    case 2: break;
    case 4: flags += 1; break;
    case 8: flags += 2; break;
    default: flags += 3;
    }
    switch ((int)(sizeof(uLong))) {
    case 2: break;
    case 4: flags += 1 << 2; break;
    case 8: flags += 2 << 2; break;
    default: flags += 3 << 2;
    }
    switch ((int)(sizeof(voidpf))) {
    case 2: break;
    case 4: flags += 1 << 4; break;
    case 8: flags += 2 << 4; break;
    default: flags += 3 << 4;
    }
    switch ((int)(sizeof(off_t))) {
    case 2: break;
    case 4: flags += 1 << 6; break;
    case 8: flags += 2 << 6; break;
    default: flags += 3 << 6;
    }
    return flags;
}

variable_types:
flags
unsigned long

return_type: unsigned long


repo: kebrister/lscat-blcontrols

decompiled_code:
int __fastcall service_timers()
{
__syscall_slong_t v0; // r12
__time_t v1; // r13
__int64 v2; // rax
__int64 v3; // rsi
__int64 v4; // rbp
struct timespec *v5; // rbx
int v6; // er15
int v7; // er14
signed __int64 v8; // rcx
__syscall_slong_t v9; // rdx
int v10; // eax
int v11; // eax
__syscall_slong_t v12; // rdx
unsigned __int64 v13; // rdi
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
struct itimerspec value; // [rsp+20h] [rbp-58h] BYREF

clock_gettime(0, &tp);
v2 = ((__int64)&unk_186A0 + tp.tv_nsec) >> 63;
v3 = ((__int64)&unk_186A0 + tp.tv_nsec) / 1000000000 + tp.tv_sec;
v4 = ((__int64)&unk_186A0 + tp.tv_nsec) % 1000000000;
if ( lstimer_active_timers > 0 )
{
v5 = (struct timespec *)s2;
v6 = 0;
v7 = 0;
while ( 1 )
{
while ( !LODWORD(v5[-1].tv_sec) )
{
LODWORD(v2) = lstimer_active_timers;
LABEL_4:
++v7;
v5 += 21;
if ( v7 >= (int)v2 )
goto LABEL_12;
}
v8 = v5[16].tv_sec;
++v6;
if ( v3 <= v8 && (v3 != v8 || v4 < v5[16].tv_nsec) )
goto LABEL_8;
lsevents_send_event(v5);
v9 = v5[-1].tv_nsec;
v5[18] = tp;
v5[-1].tv_nsec = v9 + 1;
v10 = v5[-1].tv_sec;
if ( v10 == -1 )
break;
v11 = v10 - 1;
LODWORD(v5[-1].tv_sec) = v11;
if ( v11 )
break;
v8 = v5[16].tv_sec;
LODWORD(v2) = --lstimer_active_timers;
if ( v6 == 1 )
{
LABEL_18:
v1 = v5[16].tv_sec;
v0 = v5[16].tv_nsec;
goto LABEL_4;
}
LABEL_9:
if ( v8 >= v1 )
{
if ( v8 != v1 || v5[16].tv_nsec >= v0 )
goto LABEL_4;
v0 = v5[16].tv_nsec;
}
else
{
v0 = v5[16].tv_nsec;
}
++v7;
v1 = v8;
v5 += 21;
if ( v7 >= (int)v2 )
goto LABEL_12;
}
v12 = v9 + 2;
v13 = v5[19].tv_nsec + v12 * v5[17].tv_nsec;
v8 = v13 / 0x3B9ACA00 + v5[17].tv_sec * v12 + v5[19].tv_sec;
v5[16].tv_sec = v8;
v5[16].tv_nsec = v13 % 0x3B9ACA00;
LABEL_8:
LODWORD(v2) = lstimer_active_timers;
if ( v6 == 1 )
goto LABEL_18;
goto LABEL_9;
}
LABEL_12:
if ( v1 )
{
value.it_value.tv_sec = v1;
value.it_value.tv_nsec = v0;
value.it_interval.tv_sec = 0LL;
value.it_interval.tv_nsec = 0LL;
LODWORD(v2) = timer_settime(lstimer_timerid, 1, &value, 0LL);
}
return v2;
}

canonical_decompiled_code:
int __fastcall func0()
{
__syscall_slong_t v0; // r12
__time_t v1; // r13
__int64 v2; // rax
__int64 v3; // rsi
__int64 v4; // rbp
struct timespec *v5; // rbx
int v6; // er15
int v7; // er14
signed __int64 v8; // rcx
__syscall_slong_t v9; // rdx
int v10; // eax
int v11; // eax
__syscall_slong_t v12; // rdx
unsigned __int64 v13; // rdi
struct timespec tp; // [rsp+10h] [rbp-68h] BYREF
struct itimerspec value; // [rsp+20h] [rbp-58h] BYREF

clock_gettime(0, &tp);
v2 = ((__int64)&unk_186A0 + tp.tv_nsec) >> 63;
v3 = ((__int64)&unk_186A0 + tp.tv_nsec) / 1000000000 + tp.tv_sec;
v4 = ((__int64)&unk_186A0 + tp.tv_nsec) % 1000000000;
if ( lstimer_active_timers > 0 )
{
v5 = (struct timespec *)s2;
v6 = 0;
v7 = 0;
while ( 1 )
{
while ( !LODWORD(v5[-1].tv_sec) )
{
LODWORD(v2) = lstimer_active_timers;
LABEL_4:
++v7;
v5 += 21;
if ( v7 >= (int)v2 )
goto LABEL_12;
}
v8 = v5[16].tv_sec;
++v6;
if ( v3 <= v8 && (v3 != v8 || v4 < v5[16].tv_nsec) )
goto LABEL_8;
lsevents_send_event(v5);
v9 = v5[-1].tv_nsec;
v5[18] = tp;
v5[-1].tv_nsec = v9 + 1;
v10 = v5[-1].tv_sec;
if ( v10 == -1 )
break;
v11 = v10 - 1;
LODWORD(v5[-1].tv_sec) = v11;
if ( v11 )
break;
v8 = v5[16].tv_sec;
LODWORD(v2) = --lstimer_active_timers;
if ( v6 == 1 )
{
LABEL_18:
v1 = v5[16].tv_sec;
v0 = v5[16].tv_nsec;
goto LABEL_4;
}
LABEL_9:
if ( v8 >= v1 )
{
if ( v8 != v1 || v5[16].tv_nsec >= v0 )
goto LABEL_4;
v0 = v5[16].tv_nsec;
}
else
{
v0 = v5[16].tv_nsec;
}
++v7;
v1 = v8;
v5 += 21;
if ( v7 >= (int)v2 )
goto LABEL_12;
}
v12 = v9 + 2;
v13 = v5[19].tv_nsec + v12 * v5[17].tv_nsec;
v8 = v13 / 0x3B9ACA00 + v5[17].tv_sec * v12 + v5[19].tv_sec;
v5[16].tv_sec = v8;
v5[16].tv_nsec = v13 % 0x3B9ACA00;
LABEL_8:
LODWORD(v2) = lstimer_active_timers;
if ( v6 == 1 )
goto LABEL_18;
goto LABEL_9;
}
LABEL_12:
if ( v1 )
{
value.it_value.tv_sec = v1;
value.it_value.tv_nsec = v0;
value.it_interval.tv_sec = 0LL;
value.it_interval.tv_nsec = 0LL;
LODWORD(v2) = timer_settime(lstimer_timerid, 1, &value, 0LL);
}
return v2;
}

original_code:
static void service_timers() {
  int
    i,
    found_active;
  lstimer_list_t *p;
  struct timespec now, then, soonest;
  struct itimerspec its;
  clock_gettime( 0, &now);
  then.tv_sec = now.tv_sec + (now.tv_nsec + 100000) / 1000000000;
  then.tv_nsec = (now.tv_nsec + 100000) % 1000000000;
  found_active = 0;
  for( i=0; i<lstimer_active_timers; i++) {
    p = &(lstimer_list[i]);
    if( p->shots != 0) {
      found_active++;
      if( p->next_secs < then.tv_sec || (p->next_secs == then.tv_sec && p->next_nsecs <= then.tv_nsec)) {
 lsevents_send_event( p->event);
 p->last_secs = now.tv_sec;
 p->last_nsecs = now.tv_nsec;
 p->ncalls++;
 if( p->shots != -1)
   p->shots--;
 if( p->shots == 0) {
   lstimer_active_timers--;
 } else {
   p->next_secs = p->init_secs + (p->ncalls+1) * p->delay_secs + (p->init_nsecs + (p->ncalls+1)*p->delay_nsecs)/1000000000;
   p->next_nsecs = (p->init_nsecs + (p->ncalls+1)*p->delay_nsecs) % 1000000000;
 }
      }
      if( found_active == 1) {
 soonest.tv_sec = p->next_secs;
 soonest.tv_nsec = p->next_nsecs;
      } else {
 if( soonest.tv_sec > p->next_secs || (soonest.tv_sec == p->next_secs && soonest.tv_nsec > p->next_nsecs)) {
   soonest.tv_sec = p->next_secs;
   soonest.tv_nsec = p->next_nsecs;
 }
      }
    }
  }
  if( soonest.tv_sec != 0) {
    its.it_value.tv_sec = soonest.tv_sec;
    its.it_value.tv_nsec = soonest.tv_nsec;
    its.it_interval.tv_sec = 0;
    its.it_interval.tv_nsec = 0;
    timer_settime( lstimer_timerid, 1, &its, ((void *)0));
  }
}

canonical_original_code:
static void service_timers() {
  int i; int found_active;
  struct lstimer_list_struct *p;
  struct timespec now; struct timespec then; struct timespec soonest;
  struct itimerspec its;
  clock_gettime( 0, &now);
  then.tv_sec = now.tv_sec + (now.tv_nsec + 100000) / 1000000000;
  then.tv_nsec = (now.tv_nsec + 100000) % 1000000000;
  found_active = 0;
  for( i=0; i<lstimer_active_timers; i++) {
    p = &(lstimer_list[i]);
    if( p->shots != 0) {
      found_active++;
      if( p->next_secs < then.tv_sec || (p->next_secs == then.tv_sec && p->next_nsecs <= then.tv_nsec)) {
 lsevents_send_event( p->event);
 p->last_secs = now.tv_sec;
 p->last_nsecs = now.tv_nsec;
 p->ncalls++;
 if( p->shots != -1)
   p->shots--;
 if( p->shots == 0) {
   lstimer_active_timers--;
 } else {
   p->next_secs = p->init_secs + (p->ncalls+1) * p->delay_secs + (p->init_nsecs + (p->ncalls+1)*p->delay_nsecs)/1000000000;
   p->next_nsecs = (p->init_nsecs + (p->ncalls+1)*p->delay_nsecs) % 1000000000;
 }
      }
      if( found_active == 1) {
 soonest.tv_sec = p->next_secs;
 soonest.tv_nsec = p->next_nsecs;
      } else {
 if( soonest.tv_sec > p->next_secs || (soonest.tv_sec == p->next_secs && soonest.tv_nsec > p->next_nsecs)) {
   soonest.tv_sec = p->next_secs;
   soonest.tv_nsec = p->next_nsecs;
 }
      }
    }
  }
  if( soonest.tv_sec != 0) {
    its.it_value.tv_sec = soonest.tv_sec;
    its.it_value.tv_nsec = soonest.tv_nsec;
    its.it_interval.tv_sec = 0;
    its.it_interval.tv_nsec = 0;
    timer_settime( lstimer_timerid, 1, &its, ((void *)0));
  }
}

variable_types: i int

variable_types: struct lstimer_list_struct { int shots; unsigned long ncalls; char event[256]; long next_secs; long next_nsecs; long delay_secs; long delay_nsecs; long last_secs; long last_nsecs; long init_secs; long init_nsecs; } *

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }


decompiled_code:
void __fastcall __noreturn lstimer_worker(void *a1)
{
int v1; // eax
int v2; // eax
struct sigevent v3; // [rsp+0h] [rbp-168h] BYREF
sigset_t v4; // [rsp+40h] [rbp-128h] BYREF
struct sigaction v5; // [rsp+C0h] [rbp-A8h] BYREF

v5.sa_flags = 4;
v5.sa_handler = (__sighandler_t)handler;
sigemptyset(&v5.sa_mask);
v1 = _libc_current_sigrtmin();
if ( sigaction(v1, &v5, 0LL) != -1 )
{
v3.sigev_notify = 0;
v3.sigev_signo = _libc_current_sigrtmin();
v3.sigev_value.sival_ptr = &lstimer_timerid;
timer_create(0, &v3, &lstimer_timerid);
sigemptyset(&v4);
v2 = _libc_current_sigrtmin();
sigaddset(&v4, v2);
while ( 1 )
{
pthread_mutex_lock(&lstimer_mutex);
while ( !new_timer )
pthread_cond_wait(&lstimer_cond, &lstimer_mutex);
sigprocmask(2, &v4, 0LL);
service_timers();
new_timer = 0;
pthread_mutex_unlock(&lstimer_mutex);
sigprocmask(1, &v4, 0LL);
}
}
lslogging_log_message("lstimer_worker: sigaction failed");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
int v1; // eax
int v2; // eax
struct sigevent v3; // [rsp+0h] [rbp-168h] BYREF
sigset_t v4; // [rsp+40h] [rbp-128h] BYREF
struct sigaction v5; // [rsp+C0h] [rbp-A8h] BYREF

v5.sa_flags = 4;
v5.sa_handler = (__sighandler_t)handler;
sigemptyset(&v5.sa_mask);
v1 = _libc_current_sigrtmin();
if ( sigaction(v1, &v5, 0LL) != -1 )
{
v3.sigev_notify = 0;
v3.sigev_signo = _libc_current_sigrtmin();
v3.sigev_value.sival_ptr = &lstimer_timerid;
timer_create(0, &v3, &lstimer_timerid);
sigemptyset(&v4);
v2 = _libc_current_sigrtmin();
sigaddset(&v4, v2);
while ( 1 )
{
pthread_mutex_lock(&lstimer_mutex);
while ( !new_timer )
pthread_cond_wait(&lstimer_cond, &lstimer_mutex);
sigprocmask(2, &v4, 0LL);
func0();
new_timer = 0;
pthread_mutex_unlock(&lstimer_mutex);
sigprocmask(1, &v4, 0LL);
}
}
lslogging_log_message("lstimer_worker: sigaction failed");
exit(-1);
}

original_code:
static void *lstimer_worker(
       void *dummy
       ) {
  struct sigevent sev;
  struct sigaction sa;
  sigset_t mask;
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = handler;
  sigemptyset(&sa.sa_mask);
  if (sigaction((__libc_current_sigrtmin ()), &sa, ((void *)0)) == -1) {
    lslogging_log_message( "lstimer_worker: sigaction failed");
    exit( -1);
  }
  sev.sigev_notify = SIGEV_SIGNAL;
  sev.sigev_signo = (__libc_current_sigrtmin ());
  sev.sigev_value.sival_ptr = &lstimer_timerid;
  timer_create( 0, &sev, &lstimer_timerid);
  sigemptyset( &mask);
  sigaddset( &mask, (__libc_current_sigrtmin ()));
  while( 1) {
    pthread_mutex_lock( &lstimer_mutex);
    while( new_timer == 0)
      pthread_cond_wait( &lstimer_cond, &lstimer_mutex);
    sigprocmask( 2, &mask, ((void *)0));
    service_timers();
    new_timer = 0;
    pthread_mutex_unlock( &lstimer_mutex);
    sigprocmask( 1, &mask, ((void *)0));
  }
}

canonical_original_code:
static void *lstimer_worker(void *dummy) {
  struct sigevent sev;
  struct sigaction sa;
  struct __sigset_t mask;
  sa.sa_flags = 4;
  sa.__sigaction_handler.sa_sigaction = handler;
  sigemptyset(&sa.sa_mask);
  if (sigaction((__libc_current_sigrtmin ()), &sa, ((void *)0)) == -1) {
    lslogging_log_message( "lstimer_worker: sigaction failed");
    exit( -1);
  }
  sev.sigev_notify = SIGEV_SIGNAL;
  sev.sigev_signo = (__libc_current_sigrtmin ());
  sev.sigev_value.sival_ptr = &lstimer_timerid;
  timer_create( 0, &sev, &lstimer_timerid);
  sigemptyset( &mask);
  sigaddset( &mask, (__libc_current_sigrtmin ()));
  while( 1) {
    pthread_mutex_lock( &lstimer_mutex);
    while( new_timer == 0)
      pthread_cond_wait( &lstimer_cond, &lstimer_mutex);
    sigprocmask( 2, &mask, ((void *)0));
    service_timers();
    new_timer = 0;
    pthread_mutex_unlock( &lstimer_mutex);
    sigprocmask( 1, &mask, ((void *)0));
  }
}

variable_types:
dummy
void *

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

return_type: void *

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


handler

decompiled_code:
int handler()
{
pthread_mutex_lock(&lstimer_mutex);
service_timers();
return pthread_mutex_unlock(&lstimer_mutex);
}

canonical_decompiled_code:
int func2()
{
pthread_mutex_lock(&lstimer_mutex);
func0();
return pthread_mutex_unlock(&lstimer_mutex);
}

original_code:
static void handler( int sig, siginfo_t *si, void *dummy) {
  pthread_mutex_lock( &lstimer_mutex);
  service_timers();
  pthread_mutex_unlock( &lstimer_mutex);
}

canonical_original_code:
static void handler(int sig, struct siginfo_t *si, void *dummy) {
  pthread_mutex_lock( &lstimer_mutex);
  service_timers();
  pthread_mutex_unlock( &lstimer_mutex);
}

variable_types: sig int

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *


decompiled_code:
int __fastcall lstimer_unset_timer(char *s1)
{
const char *v1; // rbx
int result; // eax

v1 = s2;
do
{
result = strcmp(s1, v1);
if ( !result )
*((_DWORD *)v1 - 4) = 0;
v1 += 336;
}
while ( v1 != "worker: sigaction failed" );
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *s1)
{
const char *v1; // rbx
int result; // eax

v1 = s2;
do
{
result = strcmp(s1, v1);
if ( !result )
*((_DWORD *)v1 - 4) = 0;
v1 += 336;
}
while ( v1 != "worker: sigaction failed" );
return result;
}

original_code:
void lstimer_unset_timer( char *event) {
  int i;
  for( i=0; i<1024; i++) {
    if( strcmp( event, lstimer_list[i].event) == 0) {
      lstimer_list[i].shots = 0;
    }
  }
}

canonical_original_code:
void lstimer_unset_timer(char *event) {
  int i;
  for( i=0; i<1024; i++) {
    if( strcmp( event, lstimer_list[i].event) == 0) {
      lstimer_list[i].shots = 0;
    }
  }
}

variable_types:
event
char *


decompiled_code:
int __fastcall lstimer_set_timer(char *src, unsigned int a2, __int64 a3, __int64 a4)
{
int *v6; // rdx
int v7; // eax
unsigned __int64 v8; // r14
__syscall_slong_t v9; // rcx
__time_t v10; // rdi
unsigned __int64 v11; // rbx
struct timespec v13; // [rsp+0h] [rbp-38h] BYREF

clock_gettime(0, &v13);
lsevents_preregister_event(src);
pthread_mutex_lock(&lstimer_mutex);
v6 = lstimer_list;
v7 = 0;
while ( *v6 )
{
++v7;
v6 += 84;
if ( v7 == 1024 )
{
pthread_mutex_unlock(&lstimer_mutex);
return lslogging_log_message(
"lstimer_set_timer: out of timers for event: %s, shots: %d, secs: %u, nsecs: %u",
src,
a2,
a3,
a4);
}
}
v8 = 336LL * v7;
strncpy(&s2[v8], src, 0xFFuLL);
v9 = v13.tv_nsec;
v10 = v13.tv_sec;
qword_788[v8 / 8] = a4;
qword_780[v8 / 8] = a3;
v11 = v9 + a4;
byte_76F[v8] = 0;
lstimer_list[v8 / 4] = a2;
qword_790[v8 / 8] = 0LL;
qword_7A0[v8 / 8] = v10;
qword_7A8[v8 / 8] = v9;
qword_798[v8 / 8] = 0LL;
qword_668[v8 / 8] = 0LL;
qword_770[v8 / 8] = v11 / 0x3B9ACA00 + v10 + a3;
qword_778[v8 / 8] = v11 % 0x3B9ACA00;
if ( a2 )
{
++lstimer_active_timers;
++new_timer;
}
pthread_cond_signal(&lstimer_cond);
return pthread_mutex_unlock(&lstimer_mutex);
}

canonical_decompiled_code:
int __fastcall func4(char *src, unsigned int a2, __int64 a3, __int64 a4)
{
int *v6; // rdx
int v7; // eax
unsigned __int64 v8; // r14
__syscall_slong_t v9; // rcx
__time_t v10; // rdi
unsigned __int64 v11; // rbx
struct timespec v13; // [rsp+0h] [rbp-38h] BYREF

clock_gettime(0, &v13);
lsevents_preregister_event(src);
pthread_mutex_lock(&lstimer_mutex);
v6 = lstimer_list;
v7 = 0;
while ( *v6 )
{
++v7;
v6 += 84;
if ( v7 == 1024 )
{
pthread_mutex_unlock(&lstimer_mutex);
return lslogging_log_message(
"lstimer_set_timer: out of timers for event: %s, shots: %d, secs: %u, nsecs: %u",
src,
a2,
a3,
a4);
}
}
v8 = 336LL * v7;
strncpy(&s2[v8], src, 0xFFuLL);
v9 = v13.tv_nsec;
v10 = v13.tv_sec;
qword_788[v8 / 8] = a4;
qword_780[v8 / 8] = a3;
v11 = v9 + a4;
byte_76F[v8] = 0;
lstimer_list[v8 / 4] = a2;
qword_790[v8 / 8] = 0LL;
qword_7A0[v8 / 8] = v10;
qword_7A8[v8 / 8] = v9;
qword_798[v8 / 8] = 0LL;
qword_668[v8 / 8] = 0LL;
qword_770[v8 / 8] = v11 / 0x3B9ACA00 + v10 + a3;
qword_778[v8 / 8] = v11 % 0x3B9ACA00;
if ( a2 )
{
++lstimer_active_timers;
++new_timer;
}
pthread_cond_signal(&lstimer_cond);
return pthread_mutex_unlock(&lstimer_mutex);
}

original_code:
void lstimer_set_timer( char *event, int shots, unsigned long int secs, unsigned long int nsecs) {
  int i;
  struct timespec now;
  clock_gettime( 0, &now);
  lsevents_preregister_event( event);
  pthread_mutex_lock( &lstimer_mutex);
  for( i=0; i<1024; i++) {
    if( lstimer_list[i].shots == 0)
      break;
  }
  if( i == 1024) {
    pthread_mutex_unlock( &lstimer_mutex);
    lslogging_log_message( "lstimer_set_timer: out of timers for event: %s, shots: %d,  secs: %u, nsecs: %u",
     event, shots, secs, nsecs);
    return;
  }
  strncpy( lstimer_list[i].event, event, 256 - 1);
  lstimer_list[i].event[256 - 1] = 0;
  lstimer_list[i].shots = shots;
  lstimer_list[i].delay_secs = secs;
  lstimer_list[i].delay_nsecs = nsecs;
  lstimer_list[i].next_secs = secs + now.tv_sec + (now.tv_nsec + nsecs) / 1000000000;
  lstimer_list[i].next_nsecs = (now.tv_nsec + nsecs) % 1000000000;
  lstimer_list[i].last_secs = 0;
  lstimer_list[i].last_nsecs = 0;
  lstimer_list[i].ncalls = 0;
  lstimer_list[i].init_secs = now.tv_sec;
  lstimer_list[i].init_nsecs = now.tv_nsec;
  if( shots != 0) {
    lstimer_active_timers++;
    new_timer++;
  }
  pthread_cond_signal( &lstimer_cond);
  pthread_mutex_unlock( &lstimer_mutex);
}

canonical_original_code:
void lstimer_set_timer(char *event, int shots, unsigned long secs, unsigned long nsecs) {
  int i;
  struct timespec now;
  clock_gettime( 0, &now);
  lsevents_preregister_event( event);
  pthread_mutex_lock( &lstimer_mutex);
  for( i=0; i<1024; i++) {
    if( lstimer_list[i].shots == 0)
      break;
  }
  if( i == 1024) {
    pthread_mutex_unlock( &lstimer_mutex);
    lslogging_log_message( "lstimer_set_timer: out of timers for event: %s, shots: %d,  secs: %u, nsecs: %u",
     event, shots, secs, nsecs);
    return;
  }
  strncpy( lstimer_list[i].event, event, 256 - 1);
  lstimer_list[i].event[256 - 1] = 0;
  lstimer_list[i].shots = shots;
  lstimer_list[i].delay_secs = secs;
  lstimer_list[i].delay_nsecs = nsecs;
  lstimer_list[i].next_secs = secs + now.tv_sec + (now.tv_nsec + nsecs) / 1000000000;
  lstimer_list[i].next_nsecs = (now.tv_nsec + nsecs) % 1000000000;
  lstimer_list[i].last_secs = 0;
  lstimer_list[i].last_nsecs = 0;
  lstimer_list[i].ncalls = 0;
  lstimer_list[i].init_secs = now.tv_sec;
  lstimer_list[i].init_nsecs = now.tv_nsec;
  if( shots != 0) {
    lstimer_active_timers++;
    new_timer++;
  }
  pthread_cond_signal( &lstimer_cond);
  pthread_mutex_unlock( &lstimer_mutex);
}

variable_types: shots int

variable_types:
secs
unsigned long

variable_types:
nsecs
unsigned long

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int lstimer_init()
{
int *v0; // rax

v0 = lstimer_list;
do
{
*v0 = 0;
v0 += 84;
}
while ( v0 != &lstimer_active_timers );
pthread_mutex_init(&lstimer_mutex, 0LL);
return pthread_cond_init(&lstimer_cond, 0LL);
}

canonical_decompiled_code:
int func5()
{
int *v0; // rax

v0 = lstimer_list;
do
{
*v0 = 0;
v0 += 84;
}
while ( v0 != &lstimer_active_timers );
pthread_mutex_init(&lstimer_mutex, 0LL);
return pthread_cond_init(&lstimer_cond, 0LL);
}

original_code:
void lstimer_init() {
  int i;
  for( i=0; i<1024; i++) {
    lstimer_list[i].shots = 0;
  }
  pthread_mutex_init( &lstimer_mutex, ((void *)0));
  pthread_cond_init( &lstimer_cond, ((void *)0));
}


decompiled_code:
int lstimer_run()
{
return pthread_create(&lstimer_thread, 0LL, (void *(*)(void *))lstimer_worker, 0LL);
}

canonical_decompiled_code:
int func6()
{
return pthread_create(&lstimer_thread, 0LL, (void *(*)(void *))lstimer_worker, 0LL);
}

original_code:
void lstimer_run() {
  pthread_create( &lstimer_thread, ((void *)0), lstimer_worker, ((void *)0));
}


decompiled_code:
__int64 lstest_lspmac_est_move_time()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
__int64 result; // rax
unsigned int v9; // [rsp+4h] [rbp-14h] BYREF
__int64 v10[2]; // [rsp+8h] [rbp-10h] BYREF

v9 = 0;
v0 = lspmac_est_move_time(v10, &v9, omega, 0LL, 0LL, 0LL, 360.0);
lslogging_log_message("lstest_lspmac_est_move_time: omega 360 move_time=%f err=%d", v0, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v1 = lspmac_est_move_time(v10, &v9, aperz, 0LL, "Cover", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: aperz Cover move_time=%f err=%d", v1, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v2 = lspmac_est_move_time(v10, &v9, aperz, 0LL, "In", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: aperz In move_time=%f err=%d", v2, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v3 = lspmac_est_move_time(v10, &v9, capz, 0LL, "Cover", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: capz Cover move_time=%f err=%d", v3, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v4 = lspmac_est_move_time(v10, &v9, capz, 0LL, "In", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: capz In move_time=%f err=%d", v4, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v5 = lspmac_est_move_time(v10, &v9, apery, 0LL, "In", aperz, 0.0);
lslogging_log_message(
"lstest_lspmac_est_move_time: apery In aperz In capy In capz In scint Scintillator move_time=%f err=%d",
v5,
*(double *)v10,
0.0,
0.0,
0.0);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v6 = lspmac_est_move_time(v10, &v9, apery, 0LL, "In", aperz, 0.0);
lslogging_log_message(
"lstest_lspmac_est_move_time: apery Cover aperz Cover capy Cover capz Cover scint Cover move_time=%f err=%d",
v6,
*(double *)v10,
0.0,
0.0,
0.0);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v7 = lspmac_est_move_time(v10, &v9, apery, 1LL, "In", aperz, 0.0);
lslogging_log_message(
"lstest_lspmac_est_move_time: apery In aperz In capy In capz In scint Scintillator omega manualMount kappa Manualmoun"
"t move_time=%f err=%d",
v7,
*(double *)v10,
0.0,
0.0,
0.0);
result = lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0);
if ( (_DWORD)result )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
__int64 result; // rax
unsigned int v9; // [rsp+4h] [rbp-14h] BYREF
__int64 v10[2]; // [rsp+8h] [rbp-10h] BYREF

v9 = 0;
v0 = lspmac_est_move_time(v10, &v9, omega, 0LL, 0LL, 0LL, 360.0);
lslogging_log_message("lstest_lspmac_est_move_time: omega 360 move_time=%f err=%d", v0, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v1 = lspmac_est_move_time(v10, &v9, aperz, 0LL, "Cover", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: aperz Cover move_time=%f err=%d", v1, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v2 = lspmac_est_move_time(v10, &v9, aperz, 0LL, "In", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: aperz In move_time=%f err=%d", v2, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v3 = lspmac_est_move_time(v10, &v9, capz, 0LL, "Cover", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: capz Cover move_time=%f err=%d", v3, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v4 = lspmac_est_move_time(v10, &v9, capz, 0LL, "In", 0LL, 0.0);
lslogging_log_message("lstest_lspmac_est_move_time: capz In move_time=%f err=%d", v4, *(double *)v10);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v5 = lspmac_est_move_time(v10, &v9, apery, 0LL, "In", aperz, 0.0);
lslogging_log_message(
"lstest_lspmac_est_move_time: apery In aperz In capy In capz In scint Scintillator move_time=%f err=%d",
v5,
*(double *)v10,
0.0,
0.0,
0.0);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v6 = lspmac_est_move_time(v10, &v9, apery, 0LL, "In", aperz, 0.0);
lslogging_log_message(
"lstest_lspmac_est_move_time: apery Cover aperz Cover capy Cover capz Cover scint Cover move_time=%f err=%d",
v6,
*(double *)v10,
0.0,
0.0,
0.0);
if ( (unsigned int)lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0) )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
v7 = lspmac_est_move_time(v10, &v9, apery, 1LL, "In", aperz, 0.0);
lslogging_log_message(
"lstest_lspmac_est_move_time: apery In aperz In capy In capz In scint Scintillator omega manualMount kappa Manualmoun"
"t move_time=%f err=%d",
v7,
*(double *)v10,
0.0,
0.0,
0.0);
result = lspmac_est_move_time_wait(v9, 0LL, *(double *)v10 + 2.0);
if ( (_DWORD)result )
return lslogging_log_message("lstest_lspmac_est_move_time: timed out");
return result;
}

original_code:
void lstest_lspmac_est_move_time() {
  int err;
  double move_time;
  double fudge;
  int mmask;
  fudge = 2.0;
  mmask = 0;
  err = lspmac_est_move_time( &move_time, &mmask, omega, 0, ((void *)0), 360., ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: omega 360  move_time=%f  err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, aperz, 0, "Cover", 0., ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: aperz Cover move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, aperz, 0, "In", 0., ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: aperz In    move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, capz, 0, "Cover", 0., ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: capz Cover  move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, capz, 0, "In", 0., ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: capz In     move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, apery, 0, "In", 0.0, aperz, 0, "In", 0.0, capy, 0, "In", 0.0, capz, 0, "In", 0.0, scint, 0, "Scintillator", 0.0, ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: apery In aperz In capy In capz In scint Scintillator move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, apery, 0, "In", 0.0, aperz, 0, "Cover", 0.0, capy, 0, "In", 0.0, capz, 0, "Cover", 0.0, scint, 0, "Cover", 0.0, ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: apery Cover aperz Cover capy Cover capz Cover scint Cover move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
  err = lspmac_est_move_time( &move_time, &mmask, apery, 1, "In", 0.0, aperz, 1, "In", 0.0, capy, 1, "In", 0.0, capz, 1, "In", 0.0, scint, 1, "Scintillator", 0.0,
         omega, 0, "manualMount", 0.0, kappa, 0, "manualMount", 0.0, ((void *)0));
  lslogging_log_message( "lstest_lspmac_est_move_time: apery In aperz In capy In capz In scint Scintillator omega manualMount kappa Manualmount move_time=%f err=%d", move_time, err);
  if( lspmac_est_move_time_wait( move_time + fudge, mmask, ((void *)0))) {
    lslogging_log_message( "lstest_lspmac_est_move_time: timed out");
    return;
  }
}

variable_types: err int

variable_types: fudge double

variable_types: mmask int


decompiled_code:
__int64 lstest_main()
{
return lstest_lspmac_est_move_time();
}

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

original_code:
void lstest_main() {
  lstest_lspmac_est_move_time();
}


original_code:
int verif_key(char *buff)
{
 int i;
 t_term *term;
 i = 0;
 term = recup_term();
 while (term->key[i] && ft_strcmp(term->key[i], buff))
  i++;
 if (term->key[i])
  return (i);
 return (-1);
}

canonical_original_code:
int verif_key(char *buff)
{
 int i;
 struct s_term *term;
 i = 0;
 term = recup_term();
 while (term->key[i] && ft_strcmp(term->key[i], buff))
  i++;
 if (term->key[i])
  return (i);
 return (-1);
}

variable_types:
buff
char *

variable_types: struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; } *hist; } *

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist *hist; }


original_code:
void ft_add_char(char *buff, t_term *term)
{
 if (buff[0] >= 32 && buff[0] <= 126 && buff[1] == 0)
 {
  if (term->hist->len == term->hist->pose_cursor)
  {
   term->hist->buff[term->hist->pose_cursor] = buff[0];
   term->hist->buff[term->hist->pose_cursor + 1] = '\0';
   term->hist->len++;
   term->hist->pose_cursor++;
   if (term->hist->next == ((void *)0))
    ft_strcpy(term->hist->value, term->hist->buff);
   ft_putstr(buff);
  }
  else
   put_stradd(term, buff);
 }
}

canonical_original_code:
void ft_add_char(char *buff, struct s_term *term)
{
 if (buff[0] >= 32 && buff[0] <= 126 && buff[1] == 0)
 {
  if (term->hist->len == term->hist->pose_cursor)
  {
   term->hist->buff[term->hist->pose_cursor] = buff[0];
   term->hist->buff[term->hist->pose_cursor + 1] = '\0';
   term->hist->len++;
   term->hist->pose_cursor++;
   if (term->hist->next == ((void *)0))
    ft_strcpy(term->hist->value, term->hist->buff);
   ft_putstr(buff);
  }
  else
   put_stradd(term, buff);
 }
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

user_defined_types: struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; }


decompiled_code:
__int64 __fastcall ft_break_read(_DWORD *a1)
{
__int64 result; // rax

ft_putchar(10LL);
if ( a1[34] == 1 )
{
if ( a1[35] != 1 )
{
ft_putstr("quote>");
goto LABEL_6;
}
}
else if ( a1[35] != 1 )
{
a1[36] = 0;
return 0LL;
}
ft_putstr("dquote>");
LABEL_6:
ft_add_char("\n", (__int64)a1);
result = 1LL;
a1[36] = 1;
return result;
}

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

ft_putchar(10LL);
if ( a1[34] == 1 )
{
if ( a1[35] != 1 )
{
ft_putstr("quote>");
goto LABEL_6;
}
}
else if ( a1[35] != 1 )
{
a1[36] = 0;
return 0LL;
}
ft_putstr("dquote>");
LABEL_6:
func1("\n", (__int64)a1);
result = 1LL;
a1[36] = 1;
return result;
}

original_code:
int ft_break_read(t_term *term)
{
 ft_putchar('\n');
 if (term->quote == 1 || term->dquote == 1)
 {
  if (term->dquote == 1)
   ft_putstr("dquote>");
  else if (term->quote == 1)
   ft_putstr("quote>");
  ft_add_char("\n", term);
  term->wait_fermeture = 1;
  return (1);
 }
 term->wait_fermeture = 0;
 return (0);
}

canonical_original_code:
int ft_break_read(struct s_term *term)
{
 ft_putchar('\n');
 if (term->quote == 1 || term->dquote == 1)
 {
  if (term->dquote == 1)
   ft_putstr("dquote>");
  else if (term->quote == 1)
   ft_putstr("quote>");
  ft_add_char("\n", term);
  term->wait_fermeture = 1;
  return (1);
 }
 term->wait_fermeture = 0;
 return (0);
}


decompiled_code:
__int64 __fastcall ft_stomp(unsigned __int8 *a1, _DWORD *a2)
{
int v2; // eax
unsigned __int8 v3; // al
__int64 result; // rax

if ( *a1 == 10 )
return ft_break_read(a2);
v2 = verif_key((__int64)a1);
if ( v2 == -1 )
{
v3 = *a1;
if ( *a1 == 39 )
{
press_quote(a2);
v3 = *a1;
}
if ( v3 == 34 )
press_dquote(a2);
ft_add_char(a1, (__int64)a2);
result = 1LL;
}
else
{
(*(&act + v2))(a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1, _DWORD *a2)
{
int v2; // eax
unsigned __int8 v3; // al
__int64 result; // rax

if ( *a1 == 10 )
return func2(a2);
v2 = func0((__int64)a1);
if ( v2 == -1 )
{
v3 = *a1;
if ( *a1 == 39 )
{
press_quote(a2);
v3 = *a1;
}
if ( v3 == 34 )
press_dquote(a2);
func1(a1, (__int64)a2);
result = 1LL;
}
else
{
(*(&act + v2))(a2);
result = 1LL;
}
return result;
}

original_code:
int ft_stomp(char *buff, t_term *term)
{
 int i;
 i = 0;
 if (buff[0] == '\n')
 {
  return (ft_break_read(term));
 }
 else if ((i = verif_key(buff)) != -1)
 {
  act[i](term);
  return (1);
 }
 else
 {
  if (buff[0] == 39)
   press_quote(term);
  if (buff[0] == 34)
   press_dquote(term);
  ft_add_char(buff, term);
 }
 return (1);
}

canonical_original_code:
int ft_stomp(char *buff, struct s_term *term)
{
 int i;
 i = 0;
 if (buff[0] == '\n')
 {
  return (ft_break_read(term));
 }
 else if ((i = verif_key(buff)) != -1)
 {
  act[i](term);
  return (1);
 }
 else
 {
  if (buff[0] == 39)
   press_quote(term);
  if (buff[0] == 34)
   press_dquote(term);
  ft_add_char(buff, term);
 }
 return (1);
}

variable_types: i int


decompiled_code:
int __fastcall ft_close_pipe(_DWORD *a1)
{
int v2; // edi
int v3; // edi
int v4; // edi
int result; // eax

v2 = a1[2];
if ( v2 )
result = close(v2);
v3 = a1[4];
if ( v3 != 2 )
result = close(v3);
v4 = a1[3];
if ( v4 != 1 )
result = close(v4);
return result;
}

canonical_decompiled_code:
int __fastcall func0(_DWORD *a1)
{
int v2; // edi
int v3; // edi
int v4; // edi
int result; // eax

v2 = a1[2];
if ( v2 )
result = close(v2);
v3 = a1[4];
if ( v3 != 2 )
result = close(v3);
v4 = a1[3];
if ( v4 != 1 )
result = close(v4);
return result;
}

original_code:
void ft_close_pipe(t_process *p)
{
 if (0 != p->fd[0])
  close(p->fd[0]);
 if (2 != p->fd[2])
  close(p->fd[2]);
 if (1 != p->fd[1])
  close(p->fd[1]);
}

canonical_original_code:
void ft_close_pipe(struct s_process *p)
{
 if (0 != p->fd[0])
  close(p->fd[0]);
 if (2 != p->fd[2])
  close(p->fd[2]);
 if (1 != p->fd[1])
  close(p->fd[1]);
}

variable_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *


original_code:
t_hist *creat_new_hist(void)
{
 t_hist *tmp;
 if (!(tmp = (t_hist *)malloc(sizeof(*tmp))))
  return (((void *)0));
 tmp->pose_buff = 0;
 tmp->len = 0;
 tmp->modif = 0;
 ft_memset(tmp->value, 0, 4096);
 ft_memset(tmp->buff, 0, 4096);
 tmp->next = ((void *)0);
 tmp->prev = ((void *)0);
 tmp->number = 1;
 return (tmp);
}

canonical_original_code:
struct s_hist *creat_new_hist()
{
 struct s_hist *tmp;
 if (!(tmp = (struct s_hist *)malloc(sizeof(*tmp))))
  return (((void *)0));
 tmp->pose_buff = 0;
 tmp->len = 0;
 tmp->modif = 0;
 ft_memset(tmp->value, 0, 4096);
 ft_memset(tmp->buff, 0, 4096);
 tmp->next = ((void *)0);
 tmp->prev = ((void *)0);
 tmp->number = 1;
 return (tmp);
}

variable_types: struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *


original_code:
void hist_cp_cmd(t_hist *hist)
{
 t_hist *exec;
 exec = hist;
 while (hist->next)
  hist = hist->next;
 ft_memcpy(hist->value, exec->buff, 4096);
}

canonical_original_code:
void hist_cp_cmd(struct s_hist *hist)
{
 struct s_hist *exec;
 exec = hist;
 while (hist->next)
  hist = hist->next;
 ft_memcpy(hist->value, exec->buff, 4096);
}

user_defined_types: struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; }


original_code:
t_hist *save_hist(t_hist *hist)
{
 hist_cp_cmd(hist);
 while (hist->prev)
  hist = hist->prev;
 while (hist->next)
 {
  if (hist->modif)
   restor_hist(hist);
  hist = hist->next;
 }
 restor_hist(hist);
 return (hist);
}

canonical_original_code:
struct s_hist *save_hist(struct s_hist *hist)
{
 hist_cp_cmd(hist);
 while (hist->prev)
  hist = hist->prev;
 while (hist->next)
 {
  if (hist->modif)
   restor_hist(hist);
  hist = hist->next;
 }
 restor_hist(hist);
 return (hist);
}

variable_types:
hist
struct s_hist *

return_type: struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *


decompiled_code:
void __fastcall job_lst_free(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
process_lst_free(v2[2]);
v2[2] = 0LL;
token_lst_free(v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
process_lst_free(v2[2]);
v2[2] = 0LL;
token_lst_free(v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void job_lst_free(t_job *job_lst)
{
 t_job *curr;
 t_job *to_free;
 curr = job_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  process_lst_free(to_free->first_process);
  to_free->first_process = ((void *)0);
  token_lst_free(&(to_free->token_lst));
  to_free->need_success = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 job_lst = ((void *)0);
}

canonical_original_code:
void job_lst_free(struct s_job *job_lst)
{
 struct s_job *curr;
 struct s_job *to_free;
 curr = job_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  process_lst_free(to_free->first_process);
  to_free->first_process = ((void *)0);
  token_lst_free(&(to_free->token_lst));
  to_free->need_success = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 job_lst = ((void *)0);
}

variable_types: struct s_job { struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *

user_defined_types: struct s_job { struct s_token *token_lst; char need_success; struct s_process *first_process; struct s_job *next; struct s_job *prev; }

user_defined_types: struct s_token { enum e_sym type; char *str; struct s_token *next; struct s_token *prev; }


decompiled_code:
void __fastcall ft_sig_segv(int a1)
{
__int64 v1; // rbx

v1 = return_env();
if ( a1 == 11 )
ft_putstr("ft_sh : segmentation fault\n");
if ( *(int *)(v1 + 4136) > 0 )
exit(0);
start();
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
__int64 v1; // rbx

v1 = return_env();
if ( a1 == 11 )
ft_putstr("ft_sh : segmentation fault\n");
if ( *(int *)(v1 + 4136) > 0 )
exit(0);
start();
}

original_code:
void ft_sig_segv(int x)
{
 t_env *env;
 env = return_env();
 if (x == 11)
  ft_putstr("ft_sh : segmentation fault\n");
 if (env->pid > 0)
  exit (0);
 start();
}

canonical_original_code:
void ft_sig_segv(int x)
{
 struct s_env *env;
 env = return_env();
 if (x == 11)
  ft_putstr("ft_sh : segmentation fault\n");
 if (env->pid > 0)
  exit (0);
 start();
}

variable_types: x int

variable_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; } *


decompiled_code:
void ft_sig_int()
{
ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
}

canonical_decompiled_code:
void func0()
{
ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
}

original_code:
void ft_sig_int(int x)
{
 x = x;
 ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void ft_sig_int(int x)
{
 x = x;
 ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

user_defined_types: struct termtype { char *term_names; char *str_table; char *Booleans; short *Numbers; char **Strings; char *ext_str_table; char **ext_Names; unsigned short num_Booleans; unsigned short num_Numbers; unsigned short num_Strings; unsigned short ext_Booleans; unsigned short ext_Numbers; unsigned short ext_Strings; }


decompiled_code:
void ft_sig_tstp()
{
if ( *(int *)(return_env() + 4136) > 0 )
start();
}

canonical_decompiled_code:
void func1()
{
if ( *(int *)(return_env() + 4136) > 0 )
start();
}

original_code:
void ft_sig_tstp(int x)
{
 t_env *env;
 env = return_env();
 (void)x;
 if (env->pid > 0)
 {
  start();
 }
}

canonical_original_code:
void ft_sig_tstp(int x)
{
 struct s_env *env;
 env = return_env();
 (void)x;
 if (env->pid > 0)
 {
  start();
 }
}

user_defined_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; }


decompiled_code:
__sighandler_t ft_init_signal()
{
signal(2, (__sighandler_t)ft_sig_int);
signal(20, (__sighandler_t)ft_sig_tstp);
return signal(11, ft_sig_segv);
}

canonical_decompiled_code:
__sighandler_t func3()
{
signal(2, (__sighandler_t)ft_sig_int);
signal(20, (__sighandler_t)ft_sig_tstp);
return signal(11, ft_sig_segv);
}

original_code:
void ft_init_signal(void)
{
 signal(2, &ft_sig_int);
 signal(20, ft_sig_tstp);
 signal(11, ft_sig_segv);
}

canonical_original_code:
void ft_init_signal()
{
 signal(2, &ft_sig_int);
 signal(20, ft_sig_tstp);
 signal(11, ft_sig_segv);
}


original_code:
int check_col(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x][y + 1] == 1 &&
    game->grid[x][y + 2] == 1 &&
    game->grid[x][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x][y + 1] == 2 &&
     game->grid[x][y + 2] == 2 &&
     game->grid[x][y + 3] == 2)
    return (2);
   y++;
  }
  y = 0;
  x++;
 }
 return (0);
}

canonical_original_code:
int check_col(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x][y + 1] == 1 &&
    game->grid[x][y + 2] == 1 &&
    game->grid[x][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x][y + 1] == 2 &&
     game->grid[x][y + 2] == 2 &&
     game->grid[x][y + 3] == 2)
    return (2);
   y++;
  }
  y = 0;
  x++;
 }
 return (0);
}

variable_types: struct s_game { int **grid; int max_x; int max_y; int ia_lvl; int player[2]; int player_in; } *

variable_types: y int


original_code:
int check_line(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y] == 1 &&
    game->grid[x + 2][y] == 1 &&
    game->grid[x + 3][y] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y] == 2 &&
     game->grid[x + 2][y] == 2 &&
     game->grid[x + 3][y] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}

canonical_original_code:
int check_line(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y] == 1 &&
    game->grid[x + 2][y] == 1 &&
    game->grid[x + 3][y] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y] == 2 &&
     game->grid[x + 2][y] == 2 &&
     game->grid[x + 3][y] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}

user_defined_types: struct s_game { int **grid; int max_x; int max_y; int ia_lvl; int player[2]; int player_in; }


original_code:
int check_null(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y < game->max_y)
  {
   if (game->grid[x][y] == 0)
    return (0);
   y++;
  }
  y = 0;
  x++;
 }
 return (100);
}

canonical_original_code:
int check_null(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y < game->max_y)
  {
   if (game->grid[x][y] == 0)
    return (0);
   y++;
  }
  y = 0;
  x++;
 }
 return (100);
}


original_code:
int check_diag(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y + 3 < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y + 1] == 1 &&
    game->grid[x + 2][y + 2] == 1 &&
    game->grid[x + 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y + 1] == 2 &&
     game->grid[x + 2][y + 2] == 2 &&
     game->grid[x + 3][y + 3] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}

canonical_original_code:
int check_diag(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y + 3 < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y + 1] == 1 &&
    game->grid[x + 2][y + 2] == 1 &&
    game->grid[x + 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y + 1] == 2 &&
     game->grid[x + 2][y + 2] == 2 &&
     game->grid[x + 3][y + 3] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}


original_code:
int check_diag_inv(t_game *game)
{
 int x;
 int y;
 x = 0;
 while (x + 3 < game->max_x)
 {
  y = game->max_y - 1;
  while (y - 3 > 0)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y - 1] == 1 &&
    game->grid[x + 2][y - 2] == 1 &&
    game->grid[x + 3][y - 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y - 1] == 2 &&
     game->grid[x + 2][y - 2] == 2 &&
     game->grid[x + 3][y - 3] == 2)
    return (2);
   y--;
  }
  x++;
 }
 return (0);
}

canonical_original_code:
int check_diag_inv(struct s_game *game)
{
 int x;
 int y;
 x = 0;
 while (x + 3 < game->max_x)
 {
  y = game->max_y - 1;
  while (y - 3 > 0)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y - 1] == 1 &&
    game->grid[x + 2][y - 2] == 1 &&
    game->grid[x + 3][y - 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y - 1] == 2 &&
     game->grid[x + 2][y - 2] == 2 &&
     game->grid[x + 3][y - 3] == 2)
    return (2);
   y--;
  }
  x++;
 }
 return (0);
}


original_code:
int check_diag_dbinv(t_game *game)
{
 int x;
 int y;
 x = game->max_x - 1;
 while (x - 3 >= 0)
 {
  y = 0;
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x - 1][y + 1] == 1 &&
    game->grid[x - 2][y + 2] == 1 &&
    game->grid[x - 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x - 1][y + 1] == 2 &&
     game->grid[x - 2][y + 2] == 2 &&
     game->grid[x - 3][y + 3] == 2)
    return (2);
   y++;
  }
  x--;
 }
 return (0);
}

canonical_original_code:
int check_diag_dbinv(struct s_game *game)
{
 int x;
 int y;
 x = game->max_x - 1;
 while (x - 3 >= 0)
 {
  y = 0;
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x - 1][y + 1] == 1 &&
    game->grid[x - 2][y + 2] == 1 &&
    game->grid[x - 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x - 1][y + 1] == 2 &&
     game->grid[x - 2][y + 2] == 2 &&
     game->grid[x - 3][y + 3] == 2)
    return (2);
   y++;
  }
  x--;
 }
 return (0);
}


decompiled_code:
__int64 check_winner()
{
__int64 v0; // rdi
int v1; // ebx
__int64 result; // rax

v0 = init_game();
v1 = check_null(v0);
result = 100LL;
if ( !v1 )
{
result = check_col(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = check_line(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = check_diag(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = check_diag_inv(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = check_diag_dbinv(v0);
if ( (unsigned int)(result - 1) >= 2 )
result = 0LL;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdi
int v1; // ebx
__int64 result; // rax

v0 = init_game();
v1 = func2(v0);
result = 100LL;
if ( !v1 )
{
result = func0(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = func1(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = func3(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = func4(v0);
if ( (_DWORD)result != 2 && (_DWORD)result != 1 )
{
result = func5(v0);
if ( (unsigned int)(result - 1) >= 2 )
result = 0LL;
}
}
}
}
}
return result;
}

original_code:
int check_winner()
{
 int ret;
 t_game *game;
 game = init_game();
 ret = 0;
 if (check_null(game))
  return (100);
 else if ((ret = check_col(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_line(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_inv(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_dbinv(game)) == 2 || ret == 1)
  return (ret);
 return (0);
}

canonical_original_code:
int check_winner()
{
 int ret;
 struct s_game *game;
 game = init_game();
 ret = 0;
 if (check_null(game))
  return (100);
 else if ((ret = check_col(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_line(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_inv(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_dbinv(game)) == 2 || ret == 1)
  return (ret);
 return (0);
}

variable_types: ret int


decompiled_code:
__int64 __fastcall say_started(__int64 a1)
{
unsigned int v1; // ebp
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("Script started, output file is ", 1LL);
ft_putstr_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("\n", 1LL);
ft_putstr_fd("Script started on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebp
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("Script started, output file is ", 1LL);
ft_putstr_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("\n", 1LL);
ft_putstr_fd("Script started on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

original_code:
void say_started(t_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("Script started, output file is ", 1);
 ft_putstr_fd(opt->file_name, 1);
 ft_putstr_fd("\n", 1);
 ft_putstr_fd("Script started on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

canonical_original_code:
void say_started(struct s_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("Script started, output file is ", 1);
 ft_putstr_fd(opt->file_name, 1);
 ft_putstr_fd("\n", 1);
 ft_putstr_fd("Script started on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

variable_types: struct s_opt { char **env; int opt_a; int opt_q; char *file_name; int fd_file; char *cmd[4096]; char cmd_av[4096]; char *shell; int fd_slave; char *fds_name[32]; int fd_master; char *fdm_name[32]; struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } orig; struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; } winsize; int pid_c; } *

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

user_defined_types: struct s_opt { char **env; int opt_a; int opt_q; char *file_name; int fd_file; char *cmd[4096]; char cmd_av[4096]; char *shell; int fd_slave; char *fds_name[32]; int fd_master; char *fdm_name[32]; struct termios orig; struct winsize winsize; int pid_c; }


decompiled_code:
__int64 __fastcall say_stop(__int64 a1)
{
unsigned int v1; // ebp
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("\nScript done, output file is ", 1LL);
ft_putendl_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("Script done on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("\nScript done, output file is ", 1LL);
ft_putendl_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("Script done on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

original_code:
void say_stop(t_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("\nScript done, output file is ", 1);
 ft_putendl_fd(opt->file_name, 1);
 ft_putstr_fd("Script done on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

canonical_original_code:
void say_stop(struct s_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("\nScript done, output file is ", 1);
 ft_putendl_fd(opt->file_name, 1);
 ft_putstr_fd("Script done on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

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

user_defined_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
ssize_t __fastcall wait_fd(__int64 a1)
{
int v2; // edi
int v3; // edi
int v4; // eax
ssize_t result; // rax
int v6; // er12
int v7; // er12
fd_set v8; // [rsp+0h] [rbp-1098h] BYREF
char buf[4120]; // [rsp+80h] [rbp-1018h] BYREF

v2 = *(_DWORD *)(a1 + 37168);
v8.fds_bits[0] |= 1uLL;
v8.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
if ( select(v2 + 1, &v8, 0LL, 0LL, 0LL) == -1 )
ft_errorexit("select");
if ( (v8.fds_bits[0] & 1) != 0 )
{
v6 = read(0, buf, 0xFFFuLL);
if ( v6 <= 0 )
reset_exit(a1);
write(*(_DWORD *)(a1 + 37168), buf, v6);
}
v3 = *(_DWORD *)(a1 + 37168);
v4 = v3 + 63;
if ( v3 >= 0 )
v4 = *(_DWORD *)(a1 + 37168);
result = v4 >> 6;
if ( (v8.fds_bits[result] & (1LL << (*(_DWORD *)(a1 + 37168) % 64))) != 0 )
{
v7 = read(v3, buf, 0xFFFuLL);
if ( v7 <= 0 )
reset_exit(a1);
write(1, buf, v7);
result = write(*(_DWORD *)(a1 + 24), buf, v7);
}
return result;
}

original_code:
void wait_fd(t_opt *opt)
{
 char buff[4096];
 int nb_read;
 fd_set fd;
 ((void) (((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))));
 if (select(opt->fd_master + 1, &fd, ((void *)0), ((void *)0), ((void *)0)) == -1)
  ft_errorexit("select");
 if (((((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(0, buff, 4095)) <= 0)
   reset_exit(opt);
  write(opt->fd_master, buff, nb_read);
 }
 if (((((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(opt->fd_master, buff, 4095)) <= 0)
   reset_exit(opt);
  write(1, buff, nb_read);
  write(opt->fd_file, buff, nb_read);
 }
}

canonical_original_code:
void wait_fd(struct s_opt *opt)
{
 char buff[4096];
 int nb_read;
 struct fd_set fd;
 ((void) (((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))));
 if (select(opt->fd_master + 1, &fd, ((void *)0), ((void *)0), ((void *)0)) == -1)
  ft_errorexit("select");
 if (((((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(0, buff, 4095)) <= 0)
   reset_exit(opt);
  write(opt->fd_master, buff, nb_read);
 }
 if (((((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(opt->fd_master, buff, 4095)) <= 0)
   reset_exit(opt);
  write(1, buff, nb_read);
  write(opt->fd_file, buff, nb_read);
 }
}

variable_types:
buff
char [4096]

variable_types:
fd
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
__int64 __fastcall concat_str(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 || !a2 )
return 0LL;
v4[0] = ft_strjoin(a1, &unk_188);
v2 = ft_strjoin(v4[0], a2);
ft_strdel(v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !a1 || !a2 )
return 0LL;
v4[0] = ft_strjoin(a1, &unk_188);
v2 = ft_strjoin(v4[0], a2);
ft_strdel(v4);
return v2;
}

original_code:
static char *concat_str(char *s1, char *s2)
{
 char *new_str;
 char *tmp;
 if (s1 && s2)
 {
  new_str = ft_strjoin(s1, " ");
  tmp = new_str;
  new_str = ft_strjoin(new_str, s2);
  ft_strdel(&tmp);
  return (new_str);
 }
 return (((void *)0));
}

variable_types:
tmp
char *


original_code:
t_token *token_lst_add(t_token *new_token, t_token *token_list)
{
 t_token *curr;
 char *tmp;
 if (!token_list)
  return (new_token);
 if (!new_token)
  return (token_list);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 if (curr->type == word && new_token->type == word && (tmp = curr->str))
 {
  curr->str = concat_str(curr->str, new_token->str);
  token_free(&new_token);
  ft_strdel(&tmp);
 }
 else
 {
  curr->next = new_token;
  new_token->prev = curr;
  if (curr->type != pipes && is_redir_operator(curr->str) != unknown
    && new_token->type == word)
   new_token->type = redir_dest;
 }
 return (token_list);
}

canonical_original_code:
struct s_token *token_lst_add(struct s_token *new_token, struct s_token *token_list)
{
 struct s_token *curr;
 char *tmp;
 if (!token_list)
  return (new_token);
 if (!new_token)
  return (token_list);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 if (curr->type == word && new_token->type == word && (tmp = curr->str))
 {
  curr->str = concat_str(curr->str, new_token->str);
  token_free(&new_token);
  ft_strdel(&tmp);
 }
 else
 {
  curr->next = new_token;
  new_token->prev = curr;
  if (curr->type != pipes && is_redir_operator(curr->str) != unknown
    && new_token->type == word)
   new_token->type = redir_dest;
 }
 return (token_list);
}

variable_types: struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *


original_code:
t_token *token_add(char *str, t_sym type, t_token *token_list)
{
 t_token *curr;
 t_token *new;
 if (!(new = create_token()))
  return (((void *)0));
 new->str = ft_strdup(str);
 new->type = type;
 if (!token_list)
  return (new);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 curr->next = new;
 new->prev = curr;
 return (token_list);
}

canonical_original_code:
struct s_token *token_add(char *str, enum e_sym type, struct s_token *token_list)
{
 struct s_token *curr;
 struct s_token *new;
 if (!(new = create_token()))
  return (((void *)0));
 new->str = ft_strdup(str);
 new->type = type;
 if (!token_list)
  return (new);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 curr->next = new;
 new->prev = curr;
 return (token_list);
}

variable_types:
str
char *

return_type: struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *


decompiled_code:
__int64 __fastcall ft_joinfree(void *ptr, void *a2, int a3)
{
__int64 v4; // r13

v4 = ft_strjoin((char *)ptr, (char *)a2);
if ( (a3 & 0xFFFFFFFD) == 1 && ptr )
free(ptr);
if ( (unsigned int)(a3 - 2) > 1 || !a2 )
return v4;
free(a2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, void *a2, int a3)
{
__int64 v4; // r13

v4 = func0((char *)ptr, (char *)a2);
if ( (a3 & 0xFFFFFFFD) == 1 && ptr )
free(ptr);
if ( (unsigned int)(a3 - 2) > 1 || !a2 )
return v4;
free(a2);
return v4;
}

original_code:
char *ft_joinfree(char *s1, char *s2, int free_str)
{
 char *ret;
 ret = ((void *)0);
 if (!s1 || !s2)
  return (((void *)0));
 ret = ft_strjoin(s1, s2);
 if (free_str == 1 || free_str == 3)
  free(s1);
 if (free_str == 2 || free_str == 3)
  free(s2);
 return(ret);
}

variable_types:
ret
char *


original_code:
char *ft_strjoin(char const *s1, char const *s2)
{
 int i;
 char *ret;
 if (!s1 || !s2)
  return (((void *)0));
 if ((ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) == ((void *)0))
  return (((void *)0));
 i = 0;
 while (*s1)
  ret[i++] = *(s1++);
 while (*s2)
  ret[i++] = *(s2++);
 return (ret);
}

canonical_original_code:
char *ft_strjoin(char *s1, char *s2)
{
 int i;
 char *ret;
 if (!s1 || !s2)
  return (((void *)0));
 if ((ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) == ((void *)0))
  return (((void *)0));
 i = 0;
 while (*s1)
  ret[i++] = *(s1++);
 while (*s2)
  ret[i++] = *(s2++);
 return (ret);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ft_putstr_c(__int64 a1, int a2)
{
ft_putstr("\x1B[0m");
switch ( a2 )
{
case 1:
ft_putstr("\x1B[31m");
break;
case 2:
ft_putstr("\x1B[32m");
break;
case 3:
ft_putstr("\x1B[33m");
break;
case 4:
ft_putstr("\x1B[34m");
break;
case 5:
ft_putstr("\x1B[35m");
break;
case 6:
ft_putstr("\x1B[36m");
break;
case 7:
ft_putstr("\x1B[37m");
break;
}
ft_putstr(a1);
return ft_putstr("\x1B[0m");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
ft_putstr("\x1B[0m");
switch ( a2 )
{
case 1:
ft_putstr("\x1B[31m");
break;
case 2:
ft_putstr("\x1B[32m");
break;
case 3:
ft_putstr("\x1B[33m");
break;
case 4:
ft_putstr("\x1B[34m");
break;
case 5:
ft_putstr("\x1B[35m");
break;
case 6:
ft_putstr("\x1B[36m");
break;
case 7:
ft_putstr("\x1B[37m");
break;
}
ft_putstr(a1);
return ft_putstr("\x1B[0m");
}

variable_types:
s
char *

variable_types: c int


original_code:
int search_endstr(t_cmd *start, int i)
{
 t_cmd *tmp;
 t_cmd *tmp2;
 char *str_tmp;
 tmp = start;
 while (tmp->value[i] != '"' || tmp->value[i - 1] == '\\')
 {
  if (tmp->value[i++] == '\0')
  {
   if (tmp->next == ((void *)0))
    return (-1);
   str_tmp = ft_strjoin(tmp->value, ";");
   free(tmp->value);
   tmp->value = str_tmp;
   str_tmp = ft_strjoin(tmp->value, tmp->next->value);
   free(tmp->value);
   tmp->value = str_tmp;
   tmp2 = tmp->next;
   tmp->next = tmp2->next;
   if (tmp2->next == ((void *)0))
    tmp->next = ((void *)0);
   free(tmp2);
  }
 }
 return (i + 1);
}

canonical_original_code:
int search_endstr(struct s_cmd *start, int i)
{
 struct s_cmd *tmp;
 struct s_cmd *tmp2;
 char *str_tmp;
 tmp = start;
 while (tmp->value[i] != '"' || tmp->value[i - 1] == '\\')
 {
  if (tmp->value[i++] == '\0')
  {
   if (tmp->next == ((void *)0))
    return (-1);
   str_tmp = ft_strjoin(tmp->value, ";");
   free(tmp->value);
   tmp->value = str_tmp;
   str_tmp = ft_strjoin(tmp->value, tmp->next->value);
   free(tmp->value);
   tmp->value = str_tmp;
   tmp2 = tmp->next;
   tmp->next = tmp2->next;
   if (tmp2->next == ((void *)0))
    tmp->next = ((void *)0);
   free(tmp2);
  }
 }
 return (i + 1);
}

variable_types: struct s_cmd { char *name; char *value; char *file; int sfd; struct s_cmd *next; } *


original_code:
t_cmd *clean_cmd(t_cmd *start)
{
 t_cmd *tmp;
 char *cmd;
 int i;
 i = 0;
 tmp = start;
 while (tmp)
 {
  i = 0;
  while (tmp->value[i])
  {
   if (tmp->value[i] == '"' && tmp->value[i - 1] != '\\')
   {
    if ((i = search_endstr(tmp, i + 1)) == -1)
     return (((void *)0));
   }
   i++;
  }
  cmd = ft_strtrim(tmp->value);
  free(tmp->value);
  tmp->value = ft_strdelc(cmd, '"');
  free(cmd);
  tmp = tmp->next;
 }
 return (start);
}

canonical_original_code:
struct s_cmd *clean_cmd(struct s_cmd *start)
{
 struct s_cmd *tmp;
 char *cmd;
 int i;
 i = 0;
 tmp = start;
 while (tmp)
 {
  i = 0;
  while (tmp->value[i])
  {
   if (tmp->value[i] == '"' && tmp->value[i - 1] != '\\')
   {
    if ((i = search_endstr(tmp, i + 1)) == -1)
     return (((void *)0));
   }
   i++;
  }
  cmd = ft_strtrim(tmp->value);
  free(tmp->value);
  tmp->value = ft_strdelc(cmd, '"');
  free(cmd);
  tmp = tmp->next;
 }
 return (start);
}

variable_types:
start
struct s_cmd *

variable_types:
cmd
char *

return_type: struct s_cmd { char *name; char *value; char *file; int sfd; struct s_cmd *next; } *


decompiled_code:
void __fastcall parse_name(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

if ( a1 )
{
v1 = a1;
do
{
v2 = (_QWORD *)ft_strsplit(v1[1], 32LL);
*v1 = *v2;
v1 = (_QWORD *)v1[4];
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

if ( a1 )
{
v1 = a1;
do
{
v2 = (_QWORD *)ft_strsplit(v1[1], 32LL);
*v1 = *v2;
v1 = (_QWORD *)v1[4];
free(v2);
}
while ( v1 );
}
}

original_code:
void parse_name(t_cmd *cmd)
{
 char **tmp;
 while (cmd)
 {
  tmp = ft_strsplit(cmd->value, ' ');
  cmd->name = tmp[0];
  cmd = cmd->next;
  free(tmp);
 }
}

canonical_original_code:
void parse_name(struct s_cmd *cmd)
{
 char **tmp;
 while (cmd)
 {
  tmp = ft_strsplit(cmd->value, ' ');
  cmd->name = tmp[0];
  cmd = cmd->next;
  free(tmp);
 }
}

variable_types:
tmp
char **

user_defined_types: struct s_cmd { char *name; char *value; char *file; int sfd; struct s_cmd *next; }