original_code:
int shared_memory_close(struct shared_memory *shmem, int *did_destroy)
{
    struct shmid_ds ds;
    int destroy_mode;
    int destroy = 0;
    char path[255];
    if (shmem == ((void *)0) || shmem->magic != 'shmm')
        return ((int)(0x80000000 | 0x00010000 | 0x0001));
    destroy_mode = shmem->flags & 0x0000030;
    if (shmem->ptr)
    {
        shmdt(shmem->ptr);
        shmem->ptr = ((void *)0);
    }
    if (shmem->shmid != -1)
    {
        if (destroy_mode == 0x0000020)
        {
            if (shmctl(shmem->shmid, 2, &ds) == 0)
            {
                if (ds.shm_nattch == 0)
                    destroy = 1;
            }
        }
        if (destroy_mode == 0x0000010)
            destroy = 1;
        if (destroy)
        {
            if (0) printf("Destroying shared memory %s 0x%08x (%d).\n", shmem->name, shmem->shmkey, shmem->shmid);
            shmctl(shmem->shmid, 0, ((void *)0));
            sprintf(path, "%s/%s", "/tmp", shmem->name);
            unlink(path);
            if (did_destroy != ((void *)0))
                *did_destroy = 1;
        }
        else
        {
            if (did_destroy != ((void *)0))
                *did_destroy = 0;
        }
        shmem->shmid = -1;
    }
    shmem->shmkey = -1;
    return 0x00000000;
}

variable_types: destroy int


repo: pearsonalan/stats

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

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

original_code:
void shared_memory_free(struct shared_memory *shmem)
{
    free(shmem);
}

variable_types: struct shared_memory { int magic; int flags; int size; char name[-1]; int shmkey; int shmid; short created; void *ptr; } *

return_type: void


decompiled_code:
const char *__fastcall error_message(int a1)
{
const char *result; // rax

if ( a1 >= -2147352564 )
{
if ( a1 >= -2147287029 )
{
result = "ERROR_STATS_KEY_TOO_LONG";
if ( a1 != -2147221502 )
{
if ( a1 )
{
result = "UNKNOWN_ERROR";
if ( a1 == -2147221503 )
result = "ERROR_STATS_CANNOT_ALLOCATE_COUNTER";
}
else
{
result = "S_OK";
}
}
}
else if ( a1 < -2147287039 )
{
LABEL_20:
result = "UNKNOWN_ERROR";
}
else
{
switch ( a1 )
{
case -2147287039:
result = "ERROR_SEMAPHORE_NAME_TOO_LONG";
break;
case -2147287038:
result = "ERROR_SEMAPHORE_CANNOT_CREATE_DIRECTORY";
break;
case -2147287037:
result = "ERROR_SEMAPHORE_PATH_NOT_DIRECTORY";
break;
case -2147287036:
result = "ERROR_SEMAPHORE_CANNOT_CREATE_PATH";
break;
case -2147287035:
result = "ERROR_SEMAPHORE_CANNOT_CREATE_IPC_TOKEN";
break;
case -2147287034:
result = "ERROR_SEMAPHORE_ALREADY_EXISTS";
break;
case -2147287033:
result = "ERROR_SEMAPHORE_DOES_NOT_EXIST";
break;
case -2147287032:
result = "ERROR_SEMAPHORE_INVALID_SIZE";
break;
case -2147287030:
result = "ERROR_SEMAPHORE_CANNOT_OPEN";
break;
default:
goto LABEL_20;
}
}
}
else if ( a1 >= -2147352575 )
{
result = "ERROR_SHARED_MEM_NAME_TOO_LONG";
switch ( a1 )
{
case -2147352574:
result = "ERROR_SHARED_MEM_CANNOT_CREATE_DIRECTORY";
break;
case -2147352573:
result = "ERROR_SHARED_MEM_PATH_NOT_DIRECTORY";
break;
case -2147352572:
result = "ERROR_SHARED_MEM_CANNOT_CREATE_PATH";
break;
case -2147352571:
result = "ERROR_SHARED_MEM_CANNOT_CREATE_IPC_TOKEN";
break;
case -2147352570:
result = "ERROR_SHARED_MEM_ALREADY_EXISTS";
break;
case -2147352569:
result = "ERROR_SHARED_MEM_DOES_NOT_EXIST";
break;
case -2147352568:
result = "ERROR_SHARED_MEM_INVALID_SIZE";
break;
case -2147352567:
result = "ERROR_SHARED_MEM_CANNOT_STAT";
break;
case -2147352566:
result = "ERROR_SHARED_MEM_CANNOT_OPEN";
break;
case -2147352565:
result = "ERROR_SHARED_MEM_CANNOT_ATTACH";
break;
default:
return result;
}
}
else
{
result = "ERROR_INVALID_PARAMETERS";
if ( a1 != -2147418111 )
{
if ( a1 == -2147418110 )
{
result = "ERROR_MEMORY";
}
else
{
result = "UNKNOWN_ERROR";
if ( a1 == -2147418112 )
result = "ERRROR_FAIL";
}
}
}
return result;
}

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

if ( a1 >= -2147352564 )
{
if ( a1 >= -2147287029 )
{
result = "ERROR_STATS_KEY_TOO_LONG";
if ( a1 != -2147221502 )
{
if ( a1 )
{
result = "UNKNOWN_ERROR";
if ( a1 == -2147221503 )
result = "ERROR_STATS_CANNOT_ALLOCATE_COUNTER";
}
else
{
result = "S_OK";
}
}
}
else if ( a1 < -2147287039 )
{
LABEL_20:
result = "UNKNOWN_ERROR";
}
else
{
switch ( a1 )
{
case -2147287039:
result = "ERROR_SEMAPHORE_NAME_TOO_LONG";
break;
case -2147287038:
result = "ERROR_SEMAPHORE_CANNOT_CREATE_DIRECTORY";
break;
case -2147287037:
result = "ERROR_SEMAPHORE_PATH_NOT_DIRECTORY";
break;
case -2147287036:
result = "ERROR_SEMAPHORE_CANNOT_CREATE_PATH";
break;
case -2147287035:
result = "ERROR_SEMAPHORE_CANNOT_CREATE_IPC_TOKEN";
break;
case -2147287034:
result = "ERROR_SEMAPHORE_ALREADY_EXISTS";
break;
case -2147287033:
result = "ERROR_SEMAPHORE_DOES_NOT_EXIST";
break;
case -2147287032:
result = "ERROR_SEMAPHORE_INVALID_SIZE";
break;
case -2147287030:
result = "ERROR_SEMAPHORE_CANNOT_OPEN";
break;
default:
goto LABEL_20;
}
}
}
else if ( a1 >= -2147352575 )
{
result = "ERROR_SHARED_MEM_NAME_TOO_LONG";
switch ( a1 )
{
case -2147352574:
result = "ERROR_SHARED_MEM_CANNOT_CREATE_DIRECTORY";
break;
case -2147352573:
result = "ERROR_SHARED_MEM_PATH_NOT_DIRECTORY";
break;
case -2147352572:
result = "ERROR_SHARED_MEM_CANNOT_CREATE_PATH";
break;
case -2147352571:
result = "ERROR_SHARED_MEM_CANNOT_CREATE_IPC_TOKEN";
break;
case -2147352570:
result = "ERROR_SHARED_MEM_ALREADY_EXISTS";
break;
case -2147352569:
result = "ERROR_SHARED_MEM_DOES_NOT_EXIST";
break;
case -2147352568:
result = "ERROR_SHARED_MEM_INVALID_SIZE";
break;
case -2147352567:
result = "ERROR_SHARED_MEM_CANNOT_STAT";
break;
case -2147352566:
result = "ERROR_SHARED_MEM_CANNOT_OPEN";
break;
case -2147352565:
result = "ERROR_SHARED_MEM_CANNOT_ATTACH";
break;
default:
return result;
}
}
else
{
result = "ERROR_INVALID_PARAMETERS";
if ( a1 != -2147418111 )
{
if ( a1 == -2147418110 )
{
result = "ERROR_MEMORY";
}
else
{
result = "UNKNOWN_ERROR";
if ( a1 == -2147418112 )
result = "ERRROR_FAIL";
}
}
}
return result;
}

original_code:
const char * error_message(int code)
{
    switch (code)
    {
    case S_OK:                                      return "S_OK";

    case ERROR_FAIL:                                return "ERRROR_FAIL";
    case ERROR_INVALID_PARAMETERS:                  return "ERROR_INVALID_PARAMETERS";
    case ERROR_MEMORY:                              return "ERROR_MEMORY";

    case ERROR_SHARED_MEM_NAME_TOO_LONG:            return "ERROR_SHARED_MEM_NAME_TOO_LONG";
    case ERROR_SHARED_MEM_CANNOT_CREATE_DIRECTORY:  return "ERROR_SHARED_MEM_CANNOT_CREATE_DIRECTORY";
    case ERROR_SHARED_MEM_PATH_NOT_DIRECTORY:       return "ERROR_SHARED_MEM_PATH_NOT_DIRECTORY";
    case ERROR_SHARED_MEM_CANNOT_CREATE_PATH:       return "ERROR_SHARED_MEM_CANNOT_CREATE_PATH";
    case ERROR_SHARED_MEM_CANNOT_CREATE_IPC_TOKEN:  return "ERROR_SHARED_MEM_CANNOT_CREATE_IPC_TOKEN";
    case ERROR_SHARED_MEM_ALREADY_EXISTS:           return "ERROR_SHARED_MEM_ALREADY_EXISTS";
    case ERROR_SHARED_MEM_DOES_NOT_EXIST:           return "ERROR_SHARED_MEM_DOES_NOT_EXIST";
    case ERROR_SHARED_MEM_INVALID_SIZE:             return "ERROR_SHARED_MEM_INVALID_SIZE";
    case ERROR_SHARED_MEM_CANNOT_STAT:              return "ERROR_SHARED_MEM_CANNOT_STAT";
    case ERROR_SHARED_MEM_CANNOT_OPEN:              return "ERROR_SHARED_MEM_CANNOT_OPEN";
    case ERROR_SHARED_MEM_CANNOT_ATTACH:            return "ERROR_SHARED_MEM_CANNOT_ATTACH";

    case ERROR_SEMAPHORE_NAME_TOO_LONG:             return "ERROR_SEMAPHORE_NAME_TOO_LONG";
    case ERROR_SEMAPHORE_CANNOT_CREATE_DIRECTORY:   return "ERROR_SEMAPHORE_CANNOT_CREATE_DIRECTORY";
    case ERROR_SEMAPHORE_PATH_NOT_DIRECTORY:        return "ERROR_SEMAPHORE_PATH_NOT_DIRECTORY";
    case ERROR_SEMAPHORE_CANNOT_CREATE_PATH:        return "ERROR_SEMAPHORE_CANNOT_CREATE_PATH";
    case ERROR_SEMAPHORE_CANNOT_CREATE_IPC_TOKEN:   return "ERROR_SEMAPHORE_CANNOT_CREATE_IPC_TOKEN";
    case ERROR_SEMAPHORE_ALREADY_EXISTS:            return "ERROR_SEMAPHORE_ALREADY_EXISTS";
    case ERROR_SEMAPHORE_DOES_NOT_EXIST:            return "ERROR_SEMAPHORE_DOES_NOT_EXIST";
    case ERROR_SEMAPHORE_INVALID_SIZE:              return "ERROR_SEMAPHORE_INVALID_SIZE";
    case ERROR_SEMAPHORE_CANNOT_OPEN:               return "ERROR_SEMAPHORE_CANNOT_OPEN";

    case ERROR_STATS_CANNOT_ALLOCATE_COUNTER:       return "ERROR_STATS_CANNOT_ALLOCATE_COUNTER";
    case ERROR_STATS_KEY_TOO_LONG:                  return "ERROR_STATS_KEY_TOO_LONG";

    }
    return "UNKNOWN_ERROR";
}

canonical_original_code:
char *error_message(int code)
{
    switch (code)
    {
    case S_OK:                                      return "S_OK";

    case ERROR_FAIL:                                return "ERRROR_FAIL";
    case ERROR_INVALID_PARAMETERS:                  return "ERROR_INVALID_PARAMETERS";
    case ERROR_MEMORY:                              return "ERROR_MEMORY";

    case ERROR_SHARED_MEM_NAME_TOO_LONG:            return "ERROR_SHARED_MEM_NAME_TOO_LONG";
    case ERROR_SHARED_MEM_CANNOT_CREATE_DIRECTORY:  return "ERROR_SHARED_MEM_CANNOT_CREATE_DIRECTORY";
    case ERROR_SHARED_MEM_PATH_NOT_DIRECTORY:       return "ERROR_SHARED_MEM_PATH_NOT_DIRECTORY";
    case ERROR_SHARED_MEM_CANNOT_CREATE_PATH:       return "ERROR_SHARED_MEM_CANNOT_CREATE_PATH";
    case ERROR_SHARED_MEM_CANNOT_CREATE_IPC_TOKEN:  return "ERROR_SHARED_MEM_CANNOT_CREATE_IPC_TOKEN";
    case ERROR_SHARED_MEM_ALREADY_EXISTS:           return "ERROR_SHARED_MEM_ALREADY_EXISTS";
    case ERROR_SHARED_MEM_DOES_NOT_EXIST:           return "ERROR_SHARED_MEM_DOES_NOT_EXIST";
    case ERROR_SHARED_MEM_INVALID_SIZE:             return "ERROR_SHARED_MEM_INVALID_SIZE";
    case ERROR_SHARED_MEM_CANNOT_STAT:              return "ERROR_SHARED_MEM_CANNOT_STAT";
    case ERROR_SHARED_MEM_CANNOT_OPEN:              return "ERROR_SHARED_MEM_CANNOT_OPEN";
    case ERROR_SHARED_MEM_CANNOT_ATTACH:            return "ERROR_SHARED_MEM_CANNOT_ATTACH";

    case ERROR_SEMAPHORE_NAME_TOO_LONG:             return "ERROR_SEMAPHORE_NAME_TOO_LONG";
    case ERROR_SEMAPHORE_CANNOT_CREATE_DIRECTORY:   return "ERROR_SEMAPHORE_CANNOT_CREATE_DIRECTORY";
    case ERROR_SEMAPHORE_PATH_NOT_DIRECTORY:        return "ERROR_SEMAPHORE_PATH_NOT_DIRECTORY";
    case ERROR_SEMAPHORE_CANNOT_CREATE_PATH:        return "ERROR_SEMAPHORE_CANNOT_CREATE_PATH";
    case ERROR_SEMAPHORE_CANNOT_CREATE_IPC_TOKEN:   return "ERROR_SEMAPHORE_CANNOT_CREATE_IPC_TOKEN";
    case ERROR_SEMAPHORE_ALREADY_EXISTS:            return "ERROR_SEMAPHORE_ALREADY_EXISTS";
    case ERROR_SEMAPHORE_DOES_NOT_EXIST:            return "ERROR_SEMAPHORE_DOES_NOT_EXIST";
    case ERROR_SEMAPHORE_INVALID_SIZE:              return "ERROR_SEMAPHORE_INVALID_SIZE";
    case ERROR_SEMAPHORE_CANNOT_OPEN:               return "ERROR_SEMAPHORE_CANNOT_OPEN";

    case ERROR_STATS_CANNOT_ALLOCATE_COUNTER:       return "ERROR_STATS_CANNOT_ALLOCATE_COUNTER";
    case ERROR_STATS_KEY_TOO_LONG:                  return "ERROR_STATS_KEY_TOO_LONG";

    }
    return "UNKNOWN_ERROR";
}

variable_types: code int

return_type: char *


decompiled_code:
__int64 __fastcall send_message(int a1, __int16 a2, char *a3, int a4)
{
int v6; // edx
int v7; // ebp
__int64 result; // rax
_DWORD *v9; // r12
int v10; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

*(_DWORD *)&addr.sa_data[2] = a1;
v10 = 0;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = _bswap_16(a2);
addr.sa_family = 2;
v7 = socket(2, 2, v6);
result = 1LL;
if ( v7 != -1 )
{
v9 = prepare_message(&v10, a3, a4);
if ( sendto(v7, v9, v10, 0, &addr, 0x10u) )
{
free(v9);
result = 0LL;
}
else
{
puts("sendto failed");
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, __int16 a2, char *a3, int a4)
{
int v6; // edx
int v7; // ebp
__int64 result; // rax
_DWORD *v9; // r12
int v10; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

*(_DWORD *)&addr.sa_data[2] = a1;
v10 = 0;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_WORD *)addr.sa_data = func8(a2);
addr.sa_family = 2;
v7 = socket(2, 2, v6);
result = 1LL;
if ( v7 != -1 )
{
v9 = prepare_message(&v10, a3, a4);
if ( sendto(v7, v9, v10, 0, &addr, 0x10u) )
{
free(v9);
result = 0LL;
}
else
{
puts("sendto failed");
result = 2LL;
}
}
return result;
}

original_code:
int send_message(struct in_addr inaddr, int port, char *metric_name, int metric_value)
{
    struct sockaddr_in addr;
    char *buffer;
    int len = 0, s;
    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_addr = inaddr;
    addr.sin_port = htons(port);
    addr.sin_family = 2;
    s = socket(2,SOCK_DGRAM,0);
    if (s == -1)
    {
        return 1;
    }
    buffer = prepare_message(&len, metric_name, metric_value);
    if (sendto(s, buffer, len, 0, (const struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == 0)
    {
        printf("sendto failed\n");
        return 2;
    }
    free(buffer);
    return 0;
}

canonical_original_code:
int send_message(struct in_addr inaddr, int port, char *metric_name, int metric_value)
{
    struct sockaddr_in addr;
    char *buffer;
    int len = 0; int s;
    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_addr = inaddr;
    addr.sin_port = htons(port);
    addr.sin_family = 2;
    s = socket(2,SOCK_DGRAM,0);
    if (s == -1)
    {
        return 1;
    }
    buffer = prepare_message(&len, metric_name, metric_value);
    if (sendto(s, buffer, len, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == 0)
    {
        printf("sendto failed\n");
        return 2;
    }
    free(buffer);
    return 0;
}

variable_types:
inaddr
struct in_addr { unsigned int s_addr; }

variable_types: port int

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

variable_types:
buffer
char *

variable_types: len int

variable_types: s int

return_type: int

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

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
struct hostent *v5; // rax
struct hostent *v6; // r14
struct in_addr *v7; // rax
__int64 v8; // r13
__int64 v9; // r12
char *v10; // rax
unsigned int v11; // eax

if ( argc == 4 )
{
v5 = gethostbyname(argv[1]);
v6 = v5;
if ( v5 )
{
printf("sending to %s\n", v5->h_name);
v7 = (struct in_addr *)*v6->h_addr_list;
if ( v7 )
{
LODWORD(v8) = 0;
v9 = 0LL;
while ( 1 )
{
v10 = inet_ntoa((struct in_addr)v7->s_addr);
printf("trying %s\n", v10);
v11 = atoi(argv[3]);
v3 = send_message(*(unsigned int *)v6->h_addr_list[v9], 7010LL, argv[2], v11);
if ( !v3 )
break;
v8 = (unsigned int)(v8 + 1);
v9 = v8;
v7 = (struct in_addr *)v6->h_addr_list[v8];
if ( !v7 )
goto LABEL_11;
}
puts("ok");
}
else
{
LABEL_11:
v3 = 0;
}
}
else
{
v3 = 0;
puts("gethostbyname() failed");
}
}
else
{
v3 = 1;
puts("usage: histd_client addr metric_name metric_value");
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
struct hostent *v5; // rax
struct hostent *v6; // r14
struct in_addr *v7; // rax
__int64 v8; // r13
__int64 v9; // r12
char *v10; // rax
unsigned int v11; // eax

if ( argc == 4 )
{
v5 = gethostbyname(argv[1]);
v6 = v5;
if ( v5 )
{
printf("sending to %s\n", v5->h_name);
v7 = (struct in_addr *)*v6->h_addr_list;
if ( v7 )
{
LODWORD(v8) = 0;
v9 = 0LL;
while ( 1 )
{
v10 = inet_ntoa((struct in_addr)v7->s_addr);
printf("trying %s\n", v10);
v11 = atoi(argv[3]);
v3 = func11(*(unsigned int *)v6->h_addr_list[v9], 7010LL, argv[2], v11);
if ( !v3 )
break;
v8 = (unsigned int)(v8 + 1);
v9 = v8;
v7 = (struct in_addr *)v6->h_addr_list[v8];
if ( !v7 )
goto LABEL_11;
}
puts("ok");
}
else
{
LABEL_11:
v3 = 0;
}
}
else
{
v3 = 0;
puts("gethostbyname() failed");
}
}
else
{
v3 = 1;
puts("usage: histd_client addr metric_name metric_value");
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
    struct hostent * h;
    unsigned int i;
    int port = 7010;
    if (argc != 4)
    {
        printf("usage: histd_client addr metric_name metric_value\n");
        return 1;
    }
    h = gethostbyname(argv[1]);
    if (h == ((void *)0))
    {
        printf("gethostbyname() failed\n");
    }
    else
    {
        printf("sending to %s\n", h->h_name);
        for (i = 0; h->h_addr_list[i] != ((void *)0); i++)
        {
            printf( "trying %s\n", inet_ntoa(*(struct in_addr *)(h->h_addr_list[i])));
            if (send_message(*(struct in_addr *)(h->h_addr_list[i]),port,argv[2],atoi(argv[3])) == 0)
            {
                printf("ok\n");
                break;
            }
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct hostent *h;
    unsigned int i;
    int port = 7010;
    if (argc != 4)
    {
        printf("usage: histd_client addr metric_name metric_value\n");
        return 1;
    }
    h = gethostbyname(argv[1]);
    if (h == ((void *)0))
    {
        printf("gethostbyname() failed\n");
    }
    else
    {
        printf("sending to %s\n", h->h_name);
        for (i = 0; h->h_addr_list[i] != ((void *)0); i++)
        {
            printf( "trying %s\n", inet_ntoa(*(struct in_addr *)(h->h_addr_list[i])));
            if (send_message(*(struct in_addr *)(h->h_addr_list[i]),port,argv[2],atoi(argv[3])) == 0)
            {
                printf("ok\n");
                break;
            }
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
i
unsigned int


decompiled_code:
size_t __fastcall json_encode_variable_name(char *dest, char *src)
{
size_t v2; // rax
size_t result; // rax

*(_WORD *)&dest[strlen(dest)] = 34;
v2 = strlen(src);
strncat(dest, src, v2);
result = strlen(dest);
strcpy(&dest[result], "\":");
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *dest, char *src)
{
size_t v2; // rax
size_t result; // rax

*(_WORD *)&dest[strlen(dest)] = 34;
v2 = strlen(src);
strncat(dest, src, v2);
result = strlen(dest);
strcpy(&dest[result], "\":");
return result;
}

original_code:
static void json_encode_variable_name(char *sStr, char *sName)
{
    strncat(sStr, "\"", 1);
    strncat(sStr, sName, strlen(sName));
    strncat(sStr, "\":", 2);
}

variable_types:
sStr
char *

variable_types:
sName
char *


decompiled_code:
char *__fastcall json_encode_string(char *dest, char *a2, const char *a3)
{
size_t v4; // rax

json_encode_variable_name(dest, a2);
v4 = strlen(a3);
return strncat(dest, a3, v4);
}

canonical_decompiled_code:
char *__fastcall func1(char *dest, char *a2, const char *a3)
{
size_t v4; // rax

func0(dest, a2);
v4 = strlen(a3);
return strncat(dest, a3, v4);
}

original_code:
void json_encode_string(char *str, char *name, char *value)
{
    json_encode_variable_name(str, name);
    strncat(str, value, strlen(value));
}

variable_types:
str
char *

variable_types:
name
char *

variable_types:
value
char *


decompiled_code:
char *__fastcall json_encode_integer(char *dest, char *a2, unsigned int a3)
{
size_t v4; // rax
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

json_encode_variable_name(dest, a2);
sprintf(v6, "%d", a3);
v4 = strlen(v6);
return strncat(dest, v6, v4);
}

canonical_decompiled_code:
char *__fastcall func2(char *dest, char *a2, unsigned int a3)
{
size_t v4; // rax
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

func0(dest, a2);
sprintf(v6, "%d", a3);
v4 = strlen(v6);
return strncat(dest, v6, v4);
}

original_code:
void json_encode_integer(char *str, char *name, int value)
{
    char int_str[(100)];
    json_encode_variable_name(str, name);
    sprintf(int_str, "%d", value);
    strncat(str, int_str, strlen(int_str));
}

canonical_original_code:
void json_encode_integer(char *str, char *name, int value)
{
    char int_str[-1];
    json_encode_variable_name(str, name);
    sprintf(int_str, "%d", value);
    strncat(str, int_str, strlen(int_str));
}

variable_types: value int


decompiled_code:
char *__fastcall json_encode_real32(char *dest, char *a2, float a3)
{
size_t v3; // rax
char s[120]; // [rsp+10h] [rbp-78h] BYREF

json_encode_variable_name(dest, a2);
sprintf(s, "%.1f", a3);
v3 = strlen(s);
return strncat(dest, s, v3);
}

canonical_decompiled_code:
char *__fastcall func3(char *dest, char *a2, float a3)
{
size_t v3; // rax
char s[120]; // [rsp+10h] [rbp-78h] BYREF

func0(dest, a2);
sprintf(s, "%.1f", a3);
v3 = strlen(s);
return strncat(dest, s, v3);
}

original_code:
void json_encode_real32(char *str, char *name, real32 value)
{
    char real32_str[(100)];
    json_encode_variable_name(str, name);
    sprintf(real32_str, "%.1f", value);
    strncat(str, real32_str, strlen(real32_str));
}

canonical_original_code:
void json_encode_real32(char *str, char *name, float value)
{
    char real32_str[-1];
    json_encode_variable_name(str, name);
    sprintf(real32_str, "%.1f", value);
    strncat(str, real32_str, strlen(real32_str));
}

variable_types: value float


decompiled_code:
size_t __fastcall json_encode_object(char *dest, char *a2, const char *a3)
{
size_t v4; // rax
size_t result; // rax

json_encode_variable_name(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 123;
v4 = strlen(a3);
strncat(dest, a3, v4);
result = strlen(dest);
*(_WORD *)&dest[result] = 125;
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(char *dest, char *a2, const char *a3)
{
size_t v4; // rax
size_t result; // rax

func0(dest, a2);
*(_WORD *)&dest[strlen(dest)] = 123;
v4 = strlen(a3);
strncat(dest, a3, v4);
result = strlen(dest);
*(_WORD *)&dest[result] = 125;
return result;
}

original_code:
void json_encode_object(char *str, char *name, char *value)
{
    json_encode_variable_name(str, name);
    strncat(str, "{", 1);
    strncat(str, value, strlen(value));
    strncat(str, "}", 1);
}


decompiled_code:
char *__fastcall json_decode_variable_name(__int64 a1, char *a2)
{
char *v2; // rax

v2 = strtok((char *)(a1 + 1), "\"");
if ( v2 )
return strcpy(a2, v2);
strcpy(a2, "name_not_found");
return (char *)25710;
}

canonical_decompiled_code:
char *__fastcall func5(__int64 a1, char *a2)
{
char *v2; // rax

v2 = strtok((char *)(a1 + 1), "\"");
if ( v2 )
return strcpy(a2, v2);
strcpy(a2, "name_not_found");
return (char *)25710;
}

original_code:
void json_decode_variable_name(char *str, char *name)
{
    char *sub_str;
    str = &str[1];
    sub_str = strtok(str, "\"");
    if (sub_str != ((void *)0))
    {
        strcpy(name, sub_str);
    }
    else
    {
        strcpy(name, "name_not_found");
    }
}


original_code:
uint32 u32_json_decode_message(uint32 u32MsgLen, char *sMesg)
{
    int id;
    jsmn_parser parser;
    jsmntok_t tokens[(128)];
    char tokenStr[(100)];
    jsmn_init(&parser);
    jsmn_parse(&parser, sMesg, strlen(sMesg), tokens, (128));
    get_json_token_str(2, sMesg, tokens, tokenStr);
    id = atoi(tokenStr);
    get_json_token_str(3, sMesg, tokens, tokenStr);
    if (!strcmp(tokenStr, "get"))
    {
        get_json_token_str(4, sMesg, tokens, tokenStr);
        if (!strcmp(tokenStr, "digit_vars"))
        {
            digit_json_encode_vars(sMesg);
        }
        else if (!strcmp(tokenStr, "control_vars"))
        {
            ctrl_json_encode(sMesg);
        }
        else if (!strcmp(tokenStr, "ds18b20_vars"))
        {
            DS18B20_json_encode_vars(sMesg);
        }
    }
    else if (!strcmp(tokenStr, "set"))
    {
        get_json_token_str(5, sMesg, tokens, tokenStr);
        if (!strcmp(tokenStr, "digit_var"))
        {
            char sName[(100)], sValue[(100)];
            get_json_token_str(7, sMesg, tokens, sName);
            get_json_token_str(8, sMesg, tokens, sValue);
            digit_set_var_by_name(sName, sValue, sMesg);
        }
        else if (!strcmp(tokenStr, "control_var"))
        {
            char sName[(100)], sValue[(100)];
            get_json_token_str(7, sMesg, tokens, sName);
            get_json_token_str(8, sMesg, tokens, sValue);
            ctrl_set_var_by_name(sName, sValue, sMesg);
        }
    }
    else
    {
    }
    return strlen(sMesg);
}

canonical_original_code:
unsigned int u32_json_decode_message(unsigned int u32MsgLen, char *sMesg)
{
    int id;
    struct jsmn_parser parser;
    struct jsmntok_t tokens[-1];
    char tokenStr[-1];
    jsmn_init(&parser);
    jsmn_parse(&parser, sMesg, strlen(sMesg), tokens, (128));
    get_json_token_str(2, sMesg, tokens, tokenStr);
    id = atoi(tokenStr);
    get_json_token_str(3, sMesg, tokens, tokenStr);
    if (!strcmp(tokenStr, "get"))
    {
        get_json_token_str(4, sMesg, tokens, tokenStr);
        if (!strcmp(tokenStr, "digit_vars"))
        {
            digit_json_encode_vars(sMesg);
        }
        else if (!strcmp(tokenStr, "control_vars"))
        {
            ctrl_json_encode(sMesg);
        }
        else if (!strcmp(tokenStr, "ds18b20_vars"))
        {
            DS18B20_json_encode_vars(sMesg);
        }
    }
    else if (!strcmp(tokenStr, "set"))
    {
        get_json_token_str(5, sMesg, tokens, tokenStr);
        if (!strcmp(tokenStr, "digit_var"))
        {
            char sName[-1]; char sValue[-1];
            get_json_token_str(7, sMesg, tokens, sName);
            get_json_token_str(8, sMesg, tokens, sValue);
            digit_set_var_by_name(sName, sValue, sMesg);
        }
        else if (!strcmp(tokenStr, "control_var"))
        {
            char sName[-1]; char sValue[-1];
            get_json_token_str(7, sMesg, tokens, sName);
            get_json_token_str(8, sMesg, tokens, sValue);
            ctrl_set_var_by_name(sName, sValue, sMesg);
        }
    }
    else
    {
    }
    return strlen(sMesg);
}

variable_types:
sMesg
char *

variable_types: id int

variable_types: struct jsmn_parser { unsigned int pos; unsigned int toknext; int toksuper; }

variable_types: struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; } [-1]

variable_types:
tokenStr
char [-1]

variable_types:
sName
char [-1]

variable_types:
sValue
char [-1]

return_type: unsigned int

user_defined_types: struct jsmntok_t { enum jsmntype_t type; int start; int end; int size; }


decompiled_code:
int pre_heating_resistor_init()
{
relay_control_init(17LL);
return read_on_time_from_file();
}

canonical_decompiled_code:
int func2()
{
relay_control_init(17LL);
return func0();
}

original_code:
void pre_heating_resistor_init(void)
{
    relay_control_init(17);
    read_on_time_from_file();
}

canonical_original_code:
void pre_heating_resistor_init()
{
    relay_control_init(17);
    read_on_time_from_file();
}


decompiled_code:
time_t pre_heating_resistor_start()
{
time_t result; // rax

result = (unsigned int)g_u32StartTime;
if ( !g_u32StartTime )
{
relay_control_set_on(17LL);
result = time(0LL);
g_u32StartTime = result;
}
return result;
}

canonical_decompiled_code:
time_t func3()
{
time_t result; // rax

result = (unsigned int)g_u32StartTime;
if ( !g_u32StartTime )
{
relay_control_set_on(17LL);
result = time(0LL);
g_u32StartTime = result;
}
return result;
}

original_code:
void pre_heating_resistor_start(void)
{
    if (!g_u32StartTime)
    {
        relay_control_set_on(17);
        g_u32StartTime = time(((void *)0));
    }
}

canonical_original_code:
void pre_heating_resistor_start()
{
    if (!g_u32StartTime)
    {
        relay_control_set_on(17);
        g_u32StartTime = time(((void *)0));
    }
}


decompiled_code:
unsigned int pre_heating_resistor_counter_update()
{
unsigned int result; // eax

++g_u32CheckCallCnt;
result = __ROR4__(-1527099483 * g_u32CheckCallCnt, 4);
if ( result <= 0x123456 )
result = save_on_time_to_file();
return result;
}

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

++g_u32CheckCallCnt;
result = __ROR4__(-1527099483 * g_u32CheckCallCnt, 4);
if ( result <= 0x123456 )
result = func1();
return result;
}

original_code:
void pre_heating_resistor_counter_update(void)
{
    g_u32CheckCallCnt++;
    if ( (g_u32CheckCallCnt * (5)) %
         (60*60) == 0)
    {
        save_on_time_to_file();
    }
}

canonical_original_code:
void pre_heating_resistor_counter_update()
{
    g_u32CheckCallCnt++;
    if ( (g_u32CheckCallCnt * (5)) %
         (60*60) == 0)
    {
        save_on_time_to_file();
    }
}


decompiled_code:
__int64 u32_pre_heating_resistor_get_on_time()
{
int v0; // er12
__int64 result; // rax

v0 = g_u32StartTime;
if ( g_u32StartTime )
result = (unsigned int)time(0LL) - v0;
else
result = (unsigned int)g_u32StartTime;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // er12
__int64 result; // rax

v0 = g_u32StartTime;
if ( g_u32StartTime )
result = (unsigned int)time(0LL) - v0;
else
result = (unsigned int)g_u32StartTime;
return result;
}

original_code:
uint32 u32_pre_heating_resistor_get_on_time()
{
    if (g_u32StartTime)
    {
        return time(((void *)0)) - g_u32StartTime;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
unsigned int u32_pre_heating_resistor_get_on_time()
{
    if (g_u32StartTime)
    {
        return time(((void *)0)) - g_u32StartTime;
    }
    else
    {
        return 0;
    }
}


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

result = (unsigned int)g_u32StartTime;
if ( g_u32StartTime )
{
relay_control_set_off(17LL);
result = u32_pre_heating_resistor_get_on_time();
g_u32OnTimeTotal += result;
g_u32StartTime = 0;
}
return result;
}

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

result = (unsigned int)g_u32StartTime;
if ( g_u32StartTime )
{
relay_control_set_off(17LL);
result = func5();
g_u32OnTimeTotal += result;
g_u32StartTime = 0;
}
return result;
}

original_code:
void pre_heating_resistor_stop(void)
{
    if (g_u32StartTime)
    {
        relay_control_set_off(17);
        g_u32OnTimeTotal += u32_pre_heating_resistor_get_on_time();
        g_u32StartTime = 0;
    }
}

canonical_original_code:
void pre_heating_resistor_stop()
{
    if (g_u32StartTime)
    {
        relay_control_set_off(17);
        g_u32OnTimeTotal += u32_pre_heating_resistor_get_on_time();
        g_u32StartTime = 0;
    }
}


decompiled_code:
bool pre_heating_resistor_get_status()
{
return g_u32StartTime != 0;
}

canonical_decompiled_code:
bool func7()
{
return g_u32StartTime != 0;
}

original_code:
_Bool pre_heating_resistor_get_status()
{
    if (g_u32StartTime)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 u32_pre_heating_resistor_get_on_time_total()
{
return (unsigned int)g_u32OnTimeTotal;
}

canonical_decompiled_code:
__int64 func8()
{
return (unsigned int)g_u32OnTimeTotal;
}

original_code:
uint32 u32_pre_heating_resistor_get_on_time_total()
{
    return g_u32OnTimeTotal;
}

canonical_original_code:
unsigned int u32_pre_heating_resistor_get_on_time_total()
{
    return g_u32OnTimeTotal;
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
pthread_t th; // [rsp+10h] [rbp-28h] BYREF
pthread_t v5; // [rsp+18h] [rbp-20h] BYREF
pthread_t v6; // [rsp+20h] [rbp-18h] BYREF
pthread_t v7[2]; // [rsp+28h] [rbp-10h] BYREF

pthread_create(&newthread, 0LL, (void *(*)(void *))&DS18B20_thread, "Thread: DS18B20");
pthread_create(&th, 0LL, (void *(*)(void *))&digit_receive_thread, "Thread: digit receive");
pthread_create(&v6, 0LL, (void *(*)(void *))&digit_update_thread, "Thread: digit update");
pthread_create(&v5, 0LL, (void *(*)(void *))&udp_server_thread, "Thread: udp-server");
pthread_create(v7, 0LL, (void *(*)(void *))&ctrl_logic_thread, "Thread: ctrl logic");
pthread_join(newthread, 0LL);
pthread_join(th, 0LL);
pthread_join(v5, 0LL);
pthread_join(v6, 0LL);
pthread_join(v7[0], 0LL);
exit(0);
}

original_code:
int main(int argc, char *argv[])
{
    pthread_t thread1, thread2, thread3, thread4, thread5;
    char *message1 = "Thread: DS18B20";
    char *message2 = "Thread: digit receive";
    char *message3 = "Thread: digit update";
    char *message4 = "Thread: udp-server";
    char *message5 = "Thread: ctrl logic";
    pthread_create( &thread1, ((void *)0), DS18B20_thread, (void*) message1);
    pthread_create( &thread2, ((void *)0), digit_receive_thread, (void*) message2);
    pthread_create( &thread4, ((void *)0), digit_update_thread, (void*) message3);
    pthread_create( &thread3, ((void *)0), udp_server_thread, (void*) message4);
    pthread_create( &thread5, ((void *)0), ctrl_logic_thread, (void*) message5);
    pthread_join( thread1, ((void *)0));
    pthread_join( thread2, ((void *)0));
    pthread_join( thread3, ((void *)0));
    pthread_join( thread4, ((void *)0));
    pthread_join( thread5, ((void *)0));
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    unsigned long thread1; unsigned long thread2; unsigned long thread3; unsigned long thread4; unsigned long thread5;
    char *message1 = "Thread: DS18B20";
    char *message2 = "Thread: digit receive";
    char *message3 = "Thread: digit update";
    char *message4 = "Thread: udp-server";
    char *message5 = "Thread: ctrl logic";
    pthread_create( &thread1, ((void *)0), DS18B20_thread, (void *) message1);
    pthread_create( &thread2, ((void *)0), digit_receive_thread, (void *) message2);
    pthread_create( &thread4, ((void *)0), digit_update_thread, (void *) message3);
    pthread_create( &thread3, ((void *)0), udp_server_thread, (void *) message4);
    pthread_create( &thread5, ((void *)0), ctrl_logic_thread, (void *) message5);
    pthread_join( thread1, ((void *)0));
    pthread_join( thread2, ((void *)0));
    pthread_join( thread3, ((void *)0));
    pthread_join( thread4, ((void *)0));
    pthread_join( thread5, ((void *)0));
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int defrost_resistor_init()
{
relay_control_init(22LL);
return read_on_time_from_file();
}

canonical_decompiled_code:
int func2()
{
relay_control_init(22LL);
return func0();
}

original_code:
void defrost_resistor_init(void)
{
    relay_control_init(22);
    read_on_time_from_file();
}

canonical_original_code:
void defrost_resistor_init()
{
    relay_control_init(22);
    read_on_time_from_file();
}


decompiled_code:
time_t defrost_resistor_start()
{
time_t result; // rax

result = (unsigned int)g_u32StartTime;
if ( !g_u32StartTime )
{
relay_control_set_on(22LL);
result = time(0LL);
g_u32StartTime = result;
}
return result;
}

canonical_decompiled_code:
time_t func3()
{
time_t result; // rax

result = (unsigned int)g_u32StartTime;
if ( !g_u32StartTime )
{
relay_control_set_on(22LL);
result = time(0LL);
g_u32StartTime = result;
}
return result;
}

original_code:
void defrost_resistor_start(void)
{
    if (!g_u32StartTime)
    {
        relay_control_set_on(22);
        g_u32StartTime = time(((void *)0));
    }
}

canonical_original_code:
void defrost_resistor_start()
{
    if (!g_u32StartTime)
    {
        relay_control_set_on(22);
        g_u32StartTime = time(((void *)0));
    }
}


decompiled_code:
unsigned int defrost_resistor_counter_update()
{
unsigned int result; // eax

++g_u32CheckCallCnt;
result = __ROR4__(-1527099483 * g_u32CheckCallCnt, 4);
if ( result <= 0x123456 )
result = save_on_time_to_file();
return result;
}

original_code:
void defrost_resistor_counter_update(void)
{
    g_u32CheckCallCnt++;
    if ( (g_u32CheckCallCnt * (5)) %
         (60*60) == 0)
    {
        save_on_time_to_file();
    }
}

canonical_original_code:
void defrost_resistor_counter_update()
{
    g_u32CheckCallCnt++;
    if ( (g_u32CheckCallCnt * (5)) %
         (60*60) == 0)
    {
        save_on_time_to_file();
    }
}


decompiled_code:
__int64 u32_defrost_resistor_get_on_time()
{
int v0; // er12
__int64 result; // rax

v0 = g_u32StartTime;
if ( g_u32StartTime )
result = (unsigned int)time(0LL) - v0;
else
result = (unsigned int)g_u32StartTime;
return result;
}

original_code:
uint32 u32_defrost_resistor_get_on_time()
{
    if (g_u32StartTime)
    {
        return time(((void *)0)) - g_u32StartTime;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
unsigned int u32_defrost_resistor_get_on_time()
{
    if (g_u32StartTime)
    {
        return time(((void *)0)) - g_u32StartTime;
    }
    else
    {
        return 0;
    }
}


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

result = (unsigned int)g_u32StartTime;
if ( g_u32StartTime )
{
relay_control_set_off(22LL);
result = u32_defrost_resistor_get_on_time();
g_u32OnTimeTotal += result;
g_u32StartTime = 0;
}
return result;
}

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

result = (unsigned int)g_u32StartTime;
if ( g_u32StartTime )
{
relay_control_set_off(22LL);
result = func5();
g_u32OnTimeTotal += result;
g_u32StartTime = 0;
}
return result;
}

original_code:
void defrost_resistor_stop(void)
{
    if (g_u32StartTime)
    {
        relay_control_set_off(22);
        g_u32OnTimeTotal += u32_defrost_resistor_get_on_time();
        g_u32StartTime = 0;
    }
}

canonical_original_code:
void defrost_resistor_stop()
{
    if (g_u32StartTime)
    {
        relay_control_set_off(22);
        g_u32OnTimeTotal += u32_defrost_resistor_get_on_time();
        g_u32StartTime = 0;
    }
}


decompiled_code:
bool defrost_resistor_get_status()
{
return g_u32StartTime != 0;
}

original_code:
_Bool defrost_resistor_get_status()
{
    if (g_u32StartTime)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
__int64 u32_defrost_resistor_get_on_time_total()
{
return (unsigned int)g_u32OnTimeTotal;
}

original_code:
uint32 u32_defrost_resistor_get_on_time_total()
{
    return g_u32OnTimeTotal;
}

canonical_original_code:
unsigned int u32_defrost_resistor_get_on_time_total()
{
    return g_u32OnTimeTotal;
}


decompiled_code:
void __noreturn DS18B20_thread()
{
while ( 1 )
{
read_DS18B20_sensors();
sleep(5u);
}
}

canonical_decompiled_code:
void __noreturn func2()
{
while ( 1 )
{
func1();
sleep(5u);
}
}

original_code:
void *DS18B20_thread( void *ptr )
{
    while(1)
    {
      read_DS18B20_sensors();
      sleep(5);
    }
    return ((void *)0);
}

canonical_original_code:
void *DS18B20_thread(void *ptr)
{
    while(1)
    {
      read_DS18B20_sensors();
      sleep(5);
    }
    return ((void *)0);
}

variable_types:
ptr
void *

return_type: void *


decompiled_code:
__int64 DS18B20_vars_ok()
{
time_t v0; // rax
unsigned int v1; // er8

v0 = time(0LL);
v1 = 0;
if ( v0 - g_DS18B20_timestamp_s1 <= 100 && v0 - g_DS18B20_timestamp_s2 <= 100 )
LOBYTE(v1) = v0 - g_DS18B20_timestamp_s3 <= 100;
return v1;
}

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

v0 = time(0LL);
v1 = 0;
if ( v0 - g_DS18B20_timestamp_s1 <= 100 && v0 - g_DS18B20_timestamp_s2 <= 100 )
LOBYTE(v1) = v0 - g_DS18B20_timestamp_s3 <= 100;
return v1;
}

original_code:
_Bool DS18B20_vars_ok()
{
    time_t current_time = time(((void *)0));
    if (current_time - g_DS18B20_timestamp_s1 > 100 ||
        current_time - g_DS18B20_timestamp_s2 > 100 ||
        current_time - g_DS18B20_timestamp_s3 > 100)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

canonical_original_code:
_Bool DS18B20_vars_ok()
{
    long current_time = time(((void *)0));
    if (current_time - g_DS18B20_timestamp_s1 > 100 ||
        current_time - g_DS18B20_timestamp_s2 > 100 ||
        current_time - g_DS18B20_timestamp_s3 > 100)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}


decompiled_code:
float r32_DS18B20_outside_temp()
{
return *(float *)&g_r32DS18B20_temp_s1;
}

canonical_decompiled_code:
float func4()
{
return *(float *)&g_r32DS18B20_temp_s1;
}

original_code:
real32 r32_DS18B20_outside_temp()
{
    return g_r32DS18B20_temp_s1;
}

canonical_original_code:
float r32_DS18B20_outside_temp()
{
    return g_r32DS18B20_temp_s1;
}

return_type: float


decompiled_code:
float r32_DS18B20_exhaust_temp()
{
return *(float *)&g_r32DS18B20_temp_s2;
}

canonical_decompiled_code:
float func5()
{
return *(float *)&g_r32DS18B20_temp_s2;
}

original_code:
real32 r32_DS18B20_exhaust_temp()
{
    return g_r32DS18B20_temp_s2;
}

canonical_original_code:
float r32_DS18B20_exhaust_temp()
{
    return g_r32DS18B20_temp_s2;
}


decompiled_code:
float r32_DS18B20_incoming_temp()
{
return *(float *)&g_r32DS18B20_temp_s3;
}

canonical_decompiled_code:
float func6()
{
return *(float *)&g_r32DS18B20_temp_s3;
}

original_code:
real32 r32_DS18B20_incoming_temp()
{
    return g_r32DS18B20_temp_s3;
}

canonical_original_code:
float r32_DS18B20_incoming_temp()
{
    return g_r32DS18B20_temp_s3;
}


decompiled_code:
__int64 tDS18B20_outside_temp_ts()
{
return g_DS18B20_timestamp_s1;
}

canonical_decompiled_code:
__int64 func7()
{
return g_DS18B20_timestamp_s1;
}

original_code:
time_t tDS18B20_outside_temp_ts()
{
    return g_DS18B20_timestamp_s1;
}

canonical_original_code:
long tDS18B20_outside_temp_ts()
{
    return g_DS18B20_timestamp_s1;
}

return_type: long


decompiled_code:
__int64 tDS18B20_exhaust_temp_ts()
{
return g_DS18B20_timestamp_s2;
}

canonical_decompiled_code:
__int64 func8()
{
return g_DS18B20_timestamp_s2;
}

original_code:
time_t tDS18B20_exhaust_temp_ts()
{
    return g_DS18B20_timestamp_s2;
}

canonical_original_code:
long tDS18B20_exhaust_temp_ts()
{
    return g_DS18B20_timestamp_s2;
}


decompiled_code:
__int64 tDS18B20_incoming_temp_ts()
{
return g_DS18B20_timestamp_s3;
}

canonical_decompiled_code:
__int64 func9()
{
return g_DS18B20_timestamp_s3;
}

original_code:
time_t tDS18B20_incoming_temp_ts()
{
    return g_DS18B20_timestamp_s3;
}

canonical_original_code:
long tDS18B20_incoming_temp_ts()
{
    return g_DS18B20_timestamp_s3;
}


decompiled_code:
size_t __fastcall DS18B20_json_encode_vars(char *s)
{
float v1; // xmm0_4
__int64 v2; // rax
float v3; // xmm0_4
__int64 v4; // rax
size_t v5; // rax
float v6; // xmm0_4
__int64 v7; // rax
size_t result; // rax
char v9[1008]; // [rsp+0h] [rbp-7E8h] BYREF
char sa[2]; // [rsp+3F0h] [rbp-3F8h] BYREF

*(_WORD *)s = 123;
v9[0] = 0;
sa[0] = 0;
v1 = r32_DS18B20_outside_temp();
json_encode_real32(sa, "value", v1);
*(_WORD *)&sa[strlen(sa)] = 44;
v2 = tDS18B20_outside_temp_ts(sa, "ts");
json_encode_integer(sa, "ts", v2);
json_encode_object(v9, "ds_outside_temp", sa);
*(_WORD *)&v9[strlen(v9)] = 44;
sa[0] = 0;
v3 = r32_DS18B20_exhaust_temp();
json_encode_real32(sa, "value", v3);
*(_WORD *)&sa[strlen(sa)] = 44;
v4 = tDS18B20_exhaust_temp_ts(sa, "ts");
json_encode_integer(sa, "ts", v4);
json_encode_object(v9, "ds_exhaust_temp", sa);
v5 = strlen(v9);
sa[0] = 0;
*(_WORD *)&v9[v5] = 44;
v6 = r32_DS18B20_incoming_temp();
json_encode_real32(sa, "value", v6);
*(_WORD *)&sa[strlen(sa)] = 44;
v7 = tDS18B20_incoming_temp_ts(sa, "ts");
json_encode_integer(sa, "ts", v7);
json_encode_object(v9, "ds_incoming_temp", sa);
json_encode_object(s, "ds18b20_vars", v9);
result = strlen(s);
*(_WORD *)&s[result] = 125;
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(char *s)
{
float v1; // xmm0_4
__int64 v2; // rax
float v3; // xmm0_4
__int64 v4; // rax
size_t v5; // rax
float v6; // xmm0_4
__int64 v7; // rax
size_t result; // rax
char v9[1008]; // [rsp+0h] [rbp-7E8h] BYREF
char sa[2]; // [rsp+3F0h] [rbp-3F8h] BYREF

*(_WORD *)s = 123;
v9[0] = 0;
sa[0] = 0;
v1 = func4();
json_encode_real32(sa, "value", v1);
*(_WORD *)&sa[strlen(sa)] = 44;
v2 = func7(sa, "ts");
json_encode_integer(sa, "ts", v2);
json_encode_object(v9, "ds_outside_temp", sa);
*(_WORD *)&v9[strlen(v9)] = 44;
sa[0] = 0;
v3 = func5();
json_encode_real32(sa, "value", v3);
*(_WORD *)&sa[strlen(sa)] = 44;
v4 = func8(sa, "ts");
json_encode_integer(sa, "ts", v4);
json_encode_object(v9, "ds_exhaust_temp", sa);
v5 = strlen(v9);
sa[0] = 0;
*(_WORD *)&v9[v5] = 44;
v6 = func6();
json_encode_real32(sa, "value", v6);
*(_WORD *)&sa[strlen(sa)] = 44;
v7 = func9(sa, "ts");
json_encode_integer(sa, "ts", v7);
json_encode_object(v9, "ds_incoming_temp", sa);
json_encode_object(s, "ds18b20_vars", v9);
result = strlen(s);
*(_WORD *)&s[result] = 125;
return result;
}

original_code:
void DS18B20_json_encode_vars(char *mesg)
{
    char sub_str1[1000];
    char sub_str2[1000];
    strcpy(mesg, "{");
    strcpy(sub_str1, "");
    strcpy(sub_str2, "");
    json_encode_real32(sub_str2,
                      "value",
                      r32_DS18B20_outside_temp());
    strncat(sub_str2, ",", 1);
    json_encode_integer(sub_str2,
                        "ts",
                        tDS18B20_outside_temp_ts());
    json_encode_object(sub_str1,
                       "ds_outside_temp",
                       sub_str2);
    strncat(sub_str1, ",", 1);
    strcpy(sub_str2, "");
    json_encode_real32(sub_str2,
                      "value",
                      r32_DS18B20_exhaust_temp());
    strncat(sub_str2, ",", 1);
    json_encode_integer(sub_str2,
                        "ts",
                        tDS18B20_exhaust_temp_ts());
    json_encode_object(sub_str1,
                       "ds_exhaust_temp",
                       sub_str2);
    strncat(sub_str1, ",", 1);
    strcpy(sub_str2, "");
    json_encode_real32(sub_str2,
                      "value",
                      r32_DS18B20_incoming_temp());
    strncat(sub_str2, ",", 1);
    json_encode_integer(sub_str2,
                        "ts",
                        tDS18B20_incoming_temp_ts());
    json_encode_object(sub_str1,
                       "ds_incoming_temp",
                       sub_str2);
    json_encode_object(mesg,
                       "ds18b20_vars",
                       sub_str1);
    strncat(mesg, "}", 1);
}

variable_types:
mesg
char *


decompiled_code:
int __fastcall rs485_open(const char *a1)
{
int v1; // eax
int v2; // ebp
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

v1 = open(a1, 2306);
g_i32RS485_port = v1;
if ( v1 < 0 )
perror("open_port: Unable to open port");
else
fcntl(v1, 4, 0LL);
fsync(g_i32RS485_port);
v2 = g_i32RS485_port;
tcgetattr(g_i32RS485_port, &v4);
cfsetispeed(&v4, 0xDu);
cfsetospeed(&v4, 0xDu);
*(_WORD *)&v4.c_cc[5] = 1541;
v4.c_iflag &= 0xFFFFE214;
v4.c_lflag = 0;
v4.c_oflag = 0;
v4.c_cflag = v4.c_cflag & 0x7FFFFC8F | 0x880;
tcsetattr(v2, 0, &v4);
return tcgetattr(v2, &v4);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int v1; // eax
int v2; // ebp
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

v1 = open(a1, 2306);
g_i32RS485_port = v1;
if ( v1 < 0 )
perror("open_port: Unable to open port");
else
fcntl(v1, 4, 0LL);
fsync(g_i32RS485_port);
v2 = g_i32RS485_port;
tcgetattr(g_i32RS485_port, &v4);
cfsetispeed(&v4, 0xDu);
cfsetospeed(&v4, 0xDu);
*(_WORD *)&v4.c_cc[5] = 1541;
v4.c_iflag &= 0xFFFFE214;
v4.c_lflag = 0;
v4.c_oflag = 0;
v4.c_cflag = v4.c_cflag & 0x7FFFFC8F | 0x880;
tcsetattr(v2, 0, &v4);
return tcgetattr(v2, &v4);
}

variable_types:
sFile
char *

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


decompiled_code:
int rs485_close()
{
return close(g_i32RS485_port);
}

canonical_decompiled_code:
int func1()
{
return close(g_i32RS485_port);
}

original_code:
void rs485_close()
{
    close(g_i32RS485_port);
}


decompiled_code:
__int64 __fastcall rs485_recv_msg(int a1, void *a2, int a3)
{
int v3; // ebx
int v4; // eax

if ( a3 <= 0 )
return 0LL;
v3 = a3;
while ( 1 )
{
v4 = read(g_i32RS485_port, &g_au8RecvBuf, 0x64uLL);
if ( v4 < 0 )
{
printf("ERROR: reading rs485 port, read_bytes = %d\n", (unsigned int)v4);
return 0LL;
}
if ( v4 == a1 )
break;
if ( !--v3 )
return 0LL;
}
memcpy(a2, &g_au8RecvBuf, a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, void *a2, int a3)
{
int v3; // ebx
int v4; // eax

if ( a3 <= 0 )
return 0LL;
v3 = a3;
while ( 1 )
{
v4 = read(g_i32RS485_port, &g_au8RecvBuf, 0x64uLL);
if ( v4 < 0 )
{
printf("ERROR: reading rs485 port, read_bytes = %d\n", (unsigned int)v4);
return 0LL;
}
if ( v4 == a1 )
break;
if ( !--v3 )
return 0LL;
}
memcpy(a2, &g_au8RecvBuf, a1);
return 1LL;
}

original_code:
_Bool rs485_recv_msg(int32 i32MsgLen, uint8 *au8Msg, int32 i32ReadAttempts)
{
    int32 i32ReadCnt = i32ReadAttempts;
    int32 i32ReadBytes;
    while(i32ReadCnt > 0)
    {
        i32ReadBytes = read(g_i32RS485_port, g_au8RecvBuf, 100);
        if (i32ReadBytes < 0)
        {
            printf("ERROR: reading rs485 port, read_bytes = %d\n",
                   i32ReadBytes);
            return 0;
        }
        else if (i32ReadBytes == i32MsgLen)
        {
            memcpy(au8Msg, g_au8RecvBuf, i32MsgLen);
            return 1;
        }
        i32ReadCnt--;
    }
    return 0;
}

canonical_original_code:
_Bool rs485_recv_msg(int i32MsgLen, unsigned char *au8Msg, int i32ReadAttempts)
{
    int i32ReadCnt = i32ReadAttempts;
    int i32ReadBytes;
    while(i32ReadCnt > 0)
    {
        i32ReadBytes = read(g_i32RS485_port, g_au8RecvBuf, 100);
        if (i32ReadBytes < 0)
        {
            printf("ERROR: reading rs485 port, read_bytes = %d\n",
                   i32ReadBytes);
            return 0;
        }
        else if (i32ReadBytes == i32MsgLen)
        {
            memcpy(au8Msg, g_au8RecvBuf, i32MsgLen);
            return 1;
        }
        i32ReadCnt--;
    }
    return 0;
}


decompiled_code:
bool __fastcall rs485_send_msg(int a1, const void *a2)
{
return write(g_i32RS485_port, a2, a1) > 0;
}

canonical_decompiled_code:
bool __fastcall func3(int a1, const void *a2)
{
return write(g_i32RS485_port, a2, a1) > 0;
}

original_code:
_Bool rs485_send_msg(int32 i32MsgLen, uint8 *au8SendMsg)
{
    if (write(g_i32RS485_port, au8SendMsg, i32MsgLen) > 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
_Bool rs485_send_msg(int i32MsgLen, unsigned char *au8SendMsg)
{
    if (write(g_i32RS485_port, au8SendMsg, i32MsgLen) > 0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
ssize_t udp_server_thread()
{
__int64 v0; // rbx
socklen_t v1; // edx
size_t v2; // rax
ssize_t result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1F7Ch] BYREF
struct sockaddr v5; // [rsp+10h] [rbp-1F78h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-1F68h] BYREF
char s[8024]; // [rsp+30h] [rbp-1F58h] BYREF

addr_len = 16;
*(_QWORD *)&v5.sa_data[6] = 0LL;
v0 = (unsigned int)socket(2, 2, 0);
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)_bswap_32_constprop_0(v0, &v5, 16LL);
*(_WORD *)v5.sa_data = _bswap_16_constprop_0();
bind(v0, &v5, v1);
while ( 1 )
{
result = recvfrom(v0, s, 0x1F40uLL, 0, &addr, &addr_len);
if ( !(_DWORD)result )
break;
u32_json_decode_message((unsigned int)result, s);
v2 = strlen(s);
sendto(v0, s, v2, 0, &addr, 0x10u);
memset(s, 0, 0x1F40uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t func2()
{
__int64 v0; // rbx
socklen_t v1; // edx
size_t v2; // rax
ssize_t result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-1F7Ch] BYREF
struct sockaddr v5; // [rsp+10h] [rbp-1F78h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-1F68h] BYREF
char s[8024]; // [rsp+30h] [rbp-1F58h] BYREF

addr_len = 16;
*(_QWORD *)&v5.sa_data[6] = 0LL;
v0 = (unsigned int)socket(2, 2, 0);
v5.sa_family = 2;
*(_QWORD *)&v5.sa_data[2] = (unsigned int)func0(v0, &v5, 16LL);
*(_WORD *)v5.sa_data = func1();
bind(v0, &v5, v1);
while ( 1 )
{
result = recvfrom(v0, s, 0x1F40uLL, 0, &addr, &addr_len);
if ( !(_DWORD)result )
break;
u32_json_decode_message((unsigned int)result, s);
v2 = strlen(s);
sendto(v0, s, v2, 0, &addr, 0x10u);
memset(s, 0, 0x1F40uLL);
}
return result;
}

original_code:
void *udp_server_thread(void *ptr)
{
    char sMesg[8000];
    int32 i32ConnSocket, i32MsgLen;
    struct sockaddr_in servaddr,cliaddr;
    socklen_t clilen = sizeof(cliaddr);
    i32ConnSocket=socket(2,SOCK_DGRAM,0);
    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr=htonl(((in_addr_t) 0x00000000));
    servaddr.sin_port=htons(8056);
    bind(i32ConnSocket,(struct sockaddr *)&servaddr,sizeof(servaddr));
    while(1)
    {
        i32MsgLen = recvfrom(i32ConnSocket, sMesg, 8000, 0,
                            (struct sockaddr *)&cliaddr, &clilen);
        if (i32MsgLen == 0)
        {
           break;
        }
        u32_json_decode_message(i32MsgLen, sMesg);
        sendto(i32ConnSocket, sMesg, strlen(sMesg), 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
        memset(sMesg, 0, 8000);
    }
}

canonical_original_code:
void *udp_server_thread(void *ptr)
{
    char sMesg[8000];
    int i32ConnSocket; int i32MsgLen;
    struct sockaddr_in servaddr; struct sockaddr_in cliaddr;
    unsigned int clilen = sizeof(cliaddr);
    i32ConnSocket=socket(2,SOCK_DGRAM,0);
    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr=htonl(((unsigned int) 0x00000000));
    servaddr.sin_port=htons(8056);
    bind(i32ConnSocket,(struct sockaddr *)&servaddr,sizeof(servaddr));
    while(1)
    {
        i32MsgLen = recvfrom(i32ConnSocket, sMesg, 8000, 0,
                            (struct sockaddr *)&cliaddr, &clilen);
        if (i32MsgLen == 0)
        {
           break;
        }
        u32_json_decode_message(i32MsgLen, sMesg);
        sendto(i32ConnSocket, sMesg, strlen(sMesg), 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
        memset(sMesg, 0, 8000);
    }
}

variable_types:
sMesg
char [8000]

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

variable_types:
clilen
unsigned int


decompiled_code:
__int64 __fastcall map_peripheral(__int64 a1)
{
int v1; // eax
void *v2; // rax
__int64 result; // rax

v1 = open("/dev/mem", 1052674);
*(_DWORD *)(a1 + 8) = v1;
if ( v1 < 0 )
{
puts("Failed to open /dev/mem, try checking permissions.");
result = 0xFFFFFFFFLL;
}
else
{
v2 = mmap(0LL, 0x1000uLL, 3, 1, v1, *(_QWORD *)a1);
*(_QWORD *)(a1 + 16) = v2;
if ( v2 == (void *)-1LL )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1 + 24) = v2;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
void *v2; // rax
__int64 result; // rax

v1 = open("/dev/mem", 1052674);
*(_DWORD *)(a1 + 8) = v1;
if ( v1 < 0 )
{
puts("Failed to open /dev/mem, try checking permissions.");
result = 0xFFFFFFFFLL;
}
else
{
v2 = mmap(0LL, 0x1000uLL, 3, 1, v1, *(_QWORD *)a1);
*(_QWORD *)(a1 + 16) = v2;
if ( v2 == (void *)-1LL )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1 + 24) = v2;
result = 0LL;
}
}
return result;
}

original_code:
int map_peripheral(struct bcm2835_peripheral *p)
{
   if ((p->mem_fd = open("/dev/mem", 02|04010000) ) < 0)
   {
      printf("Failed to open /dev/mem, try checking permissions.\n");
      return -1;
   }
   p->map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      p->mem_fd,
      p->addr_p
   );
   if (p->map == ((void *) -1))
   {
        perror("mmap");
        return -1;
   }
   p->addr = (volatile unsigned int *)p->map;
   return 0;
}

canonical_original_code:
int map_peripheral(struct bcm2835_peripheral *p)
{
   if ((p->mem_fd = open("/dev/mem", 02|04010000) ) < 0)
   {
      printf("Failed to open /dev/mem, try checking permissions.\n");
      return -1;
   }
   p->map = mmap(
      ((void *)0),
      (4*1024),
      0x1|0x2,
      0x01,
      p->mem_fd,
      p->addr_p
   );
   if (p->map == ((void *) -1))
   {
        perror("mmap");
        return -1;
   }
   p->addr = (unsigned int *)p->map;
   return 0;
}

variable_types: struct bcm2835_peripheral { unsigned long addr_p; int mem_fd; void *map; unsigned int *addr; } *


decompiled_code:
int __fastcall unmap_peripheral(__int64 a1)
{
munmap(*(void **)(a1 + 16), 0x1000uLL);
return close(*(_DWORD *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
munmap(*(void **)(a1 + 16), 0x1000uLL);
return close(*(_DWORD *)(a1 + 8));
}

original_code:
void unmap_peripheral(struct bcm2835_peripheral *p)
{
    munmap(p->map, (4*1024));
    close(p->mem_fd);
}

user_defined_types: struct bcm2835_peripheral { unsigned long addr_p; int mem_fd; void *map; unsigned int *addr; }


decompiled_code:
void __fastcall jsmn_parse_primitive(unsigned int *a1, __int64 a2, unsigned __int64 a3, __int64 a4, unsigned __int64 a5)
{
unsigned __int64 v8; // rdx
unsigned int v10; // er10
unsigned int v11; // eax
char v12; // cl
_DWORD *v13; // rdi
int *v14; // r9
int v15; // er10
_DWORD *v16; // r9

v8 = *a1;
v10 = *a1;
v11 = *a1;
if ( a3 > v8 )
{
while ( 1 )
{
v12 = *(_BYTE *)(a2 + v8);
if ( !v12 )
goto LABEL_9;
if ( v12 > 58 )
break;
if ( v12 <= 8 )
goto LABEL_4;
if ( ((1LL << v12) & 0x400100100002600LL) != 0 )
goto LABEL_9;
if ( (unsigned __int8)(v12 - 32) > 0x5Eu )
{
LABEL_14:
*a1 = v10;
return;
}
LABEL_5:
v8 = v11 + 1;
*a1 = v8;
++v11;
if ( v8 >= a3 )
goto LABEL_9;
}
if ( (v12 & 0xDF) == 93 )
goto LABEL_9;
LABEL_4:
if ( (unsigned __int8)(v12 - 32) > 0x5Eu )
goto LABEL_14;
goto LABEL_5;
}
LABEL_9:
if ( a4 )
{
v13 = (_DWORD *)jsmn_alloc_token((__int64)a1, a4, a5);
if ( v13 )
{
jsmn_fill_token(v13, 0, v15, *v14);
--*v16;
}
else
{
*v14 = v15;
}
}
else
{
*a1 = v11 - 1;
}
}

original_code:
static jsmnerr_t jsmn_parse_primitive(jsmn_parser *parser, const char *js,
        size_t len, jsmntok_t *tokens, size_t num_tokens) {
    jsmntok_t *token;
    int start;
    start = parser->pos;
    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
        switch (js[parser->pos]) {
            case ':':
            case '\t' : case '\r' : case '\n' : case ' ' :
            case ',' : case ']' : case '}' :
                goto found;
        }
        if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
            parser->pos = start;
            return JSMN_ERROR_INVAL;
        }
    }
found:
    if (tokens == ((void *)0)) {
        parser->pos--;
        return 0;
    }
    token = jsmn_alloc_token(parser, tokens, num_tokens);
    if (token == ((void *)0)) {
        parser->pos = start;
        return JSMN_ERROR_NOMEM;
    }
    jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
    parser->pos--;
    return 0;
}

canonical_original_code:
static enum jsmnerr_t jsmn_parse_primitive(struct jsmn_parser *parser, char *js, unsigned long len, struct jsmntok_t *tokens, unsigned long num_tokens) {
    struct jsmntok_t *token;
    int start;
    start = parser->pos;
    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
        switch (js[parser->pos]) {
            case ':':
            case '\t' : case '\r' : case '\n' : case ' ' :
            case ',' : case ']' : case '}' :
                goto found;
        }
        if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
            parser->pos = start;
            return JSMN_ERROR_INVAL;
        }
    }
found:
    if (tokens == ((void *)0)) {
        parser->pos--;
        return 0;
    }
    token = jsmn_alloc_token(parser, tokens, num_tokens);
    if (token == ((void *)0)) {
        parser->pos = start;
        return JSMN_ERROR_NOMEM;
    }
    jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
    parser->pos--;
    return 0;
}

variable_types: struct jsmn_parser { unsigned int pos; unsigned int toknext; int toksuper; } *

variable_types:
js
char *

variable_types:
len
unsigned long

variable_types: struct jsmntok_t { enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 } type; int start; int end; int size; } *

variable_types: start int

return_type: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3 }


original_code:
static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js,
        size_t len, jsmntok_t *tokens, size_t num_tokens) {
    jsmntok_t *token;
    int start = parser->pos;
    parser->pos++;
    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
        char c = js[parser->pos];
        if (c == '\"') {
            if (tokens == ((void *)0)) {
                return 0;
            }
            token = jsmn_alloc_token(parser, tokens, num_tokens);
            if (token == ((void *)0)) {
                parser->pos = start;
                return JSMN_ERROR_NOMEM;
            }
            jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
            return 0;
        }
        if (c == '\\') {
            parser->pos++;
            switch (js[parser->pos]) {
                case '\"': case '/' : case '\\' : case 'b' :
                case 'f' : case 'r' : case 'n' : case 't' :
                    break;
                case 'u':
                    parser->pos++;
                    int i = 0;
                    for(; i < 4 && js[parser->pos] != '\0'; i++) {
                        if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) ||
                                    (js[parser->pos] >= 65 && js[parser->pos] <= 70) ||
                                    (js[parser->pos] >= 97 && js[parser->pos] <= 102))) {
                            parser->pos = start;
                            return JSMN_ERROR_INVAL;
                        }
                        parser->pos++;
                    }
                    parser->pos--;
                    break;
                default:
                    parser->pos = start;
                    return JSMN_ERROR_INVAL;
            }
        }
    }
    parser->pos = start;
    return JSMN_ERROR_PART;
}

canonical_original_code:
static enum jsmnerr_t jsmn_parse_string(struct jsmn_parser *parser, char *js, unsigned long len, struct jsmntok_t *tokens, unsigned long num_tokens) {
    struct jsmntok_t *token;
    int start = parser->pos;
    parser->pos++;
    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
        char c = js[parser->pos];
        if (c == '\"') {
            if (tokens == ((void *)0)) {
                return 0;
            }
            token = jsmn_alloc_token(parser, tokens, num_tokens);
            if (token == ((void *)0)) {
                parser->pos = start;
                return JSMN_ERROR_NOMEM;
            }
            jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
            return 0;
        }
        if (c == '\\') {
            parser->pos++;
            switch (js[parser->pos]) {
                case '\"': case '/' : case '\\' : case 'b' :
                case 'f' : case 'r' : case 'n' : case 't' :
                    break;
                case 'u':
                    parser->pos++;
                    int i = 0;
                    for(; i < 4 && js[parser->pos] != '\0'; i++) {
                        if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) ||
                                    (js[parser->pos] >= 65 && js[parser->pos] <= 70) ||
                                    (js[parser->pos] >= 97 && js[parser->pos] <= 102))) {
                            parser->pos = start;
                            return JSMN_ERROR_INVAL;
                        }
                        parser->pos++;
                    }
                    parser->pos--;
                    break;
                default:
                    parser->pos = start;
                    return JSMN_ERROR_INVAL;
            }
        }
    }
    parser->pos = start;
    return JSMN_ERROR_PART;
}

variable_types: c char

variable_types: i int

user_defined_types: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3 }

user_defined_types: struct jsmn_parser { unsigned int pos; unsigned int toknext; int toksuper; }

user_defined_types: enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 }


original_code:
jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
        jsmntok_t *tokens, unsigned int num_tokens) {
    jsmnerr_t r;
    int i;
    jsmntok_t *token;
    int count = 0;
    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
        char c;
        jsmntype_t type;
        c = js[parser->pos];
        switch (c) {
            case '{': case '[':
                count++;
                if (tokens == ((void *)0)) {
                    break;
                }
                token = jsmn_alloc_token(parser, tokens, num_tokens);
                if (token == ((void *)0))
                    return JSMN_ERROR_NOMEM;
                if (parser->toksuper != -1) {
                    tokens[parser->toksuper].size++;
                }
                token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
                token->start = parser->pos;
                parser->toksuper = parser->toknext - 1;
                break;
            case '}': case ']':
                if (tokens == ((void *)0))
                    break;
                type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
                for (i = parser->toknext - 1; i >= 0; i--) {
                    token = &tokens[i];
                    if (token->start != -1 && token->end == -1) {
                        if (token->type != type) {
                            return JSMN_ERROR_INVAL;
                        }
                        parser->toksuper = -1;
                        token->end = parser->pos + 1;
                        break;
                    }
                }
                if (i == -1) return JSMN_ERROR_INVAL;
                for (; i >= 0; i--) {
                    token = &tokens[i];
                    if (token->start != -1 && token->end == -1) {
                        parser->toksuper = i;
                        break;
                    }
                }
                break;
            case '\"':
                r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
                if (r < 0) return r;
                count++;
                if (parser->toksuper != -1 && tokens != ((void *)0))
                    tokens[parser->toksuper].size++;
                break;
            case '\t' : case '\r' : case '\n' : case ':' : case ',': case ' ':
                break;
            default:
                r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
                if (r < 0) return r;
                count++;
                if (parser->toksuper != -1 && tokens != ((void *)0))
                    tokens[parser->toksuper].size++;
                break;
        }
    }
    for (i = parser->toknext - 1; i >= 0; i--) {
        if (tokens[i].start != -1 && tokens[i].end == -1) {
            return JSMN_ERROR_PART;
        }
    }
    return count;
}

canonical_original_code:
enum jsmnerr_t jsmn_parse(struct jsmn_parser *parser, char *js, unsigned long len, struct jsmntok_t *tokens, unsigned int num_tokens) {
    enum jsmnerr_t r;
    int i;
    struct jsmntok_t *token;
    int count = 0;
    for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
        char c;
        enum jsmntype_t type;
        c = js[parser->pos];
        switch (c) {
            case '{': case '[':
                count++;
                if (tokens == ((void *)0)) {
                    break;
                }
                token = jsmn_alloc_token(parser, tokens, num_tokens);
                if (token == ((void *)0))
                    return JSMN_ERROR_NOMEM;
                if (parser->toksuper != -1) {
                    tokens[parser->toksuper].size++;
                }
                token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
                token->start = parser->pos;
                parser->toksuper = parser->toknext - 1;
                break;
            case '}': case ']':
                if (tokens == ((void *)0))
                    break;
                type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
                for (i = parser->toknext - 1; i >= 0; i--) {
                    token = &tokens[i];
                    if (token->start != -1 && token->end == -1) {
                        if (token->type != type) {
                            return JSMN_ERROR_INVAL;
                        }
                        parser->toksuper = -1;
                        token->end = parser->pos + 1;
                        break;
                    }
                }
                if (i == -1) return JSMN_ERROR_INVAL;
                for (; i >= 0; i--) {
                    token = &tokens[i];
                    if (token->start != -1 && token->end == -1) {
                        parser->toksuper = i;
                        break;
                    }
                }
                break;
            case '\"':
                r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
                if (r < 0) return r;
                count++;
                if (parser->toksuper != -1 && tokens != ((void *)0))
                    tokens[parser->toksuper].size++;
                break;
            case '\t' : case '\r' : case '\n' : case ':' : case ',': case ' ':
                break;
            default:
                r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
                if (r < 0) return r;
                count++;
                if (parser->toksuper != -1 && tokens != ((void *)0))
                    tokens[parser->toksuper].size++;
                break;
        }
    }
    for (i = parser->toknext - 1; i >= 0; i--) {
        if (tokens[i].start != -1 && tokens[i].end == -1) {
            return JSMN_ERROR_PART;
        }
    }
    return count;
}

variable_types: enum jsmnerr_t { JSMN_ERROR_NOMEM=-1, JSMN_ERROR_INVAL=-2, JSMN_ERROR_PART=-3 }

variable_types: count int

variable_types: enum jsmntype_t { JSMN_PRIMITIVE=0, JSMN_OBJECT=1, JSMN_ARRAY=2, JSMN_STRING=3 }


decompiled_code:
int post_heating_counter_init()
{
return read_on_time_from_file();
}

canonical_decompiled_code:
int func2()
{
return func0();
}

original_code:
void post_heating_counter_init()
{
    read_on_time_from_file();
}


decompiled_code:
char post_heating_counter_update()
{
float v0; // xmm0_4
int v1; // ebx
unsigned int v2; // eax
int v3; // edx

v0 = r32_digit_post_heating_on_cnt();
v1 = (int)v0;
r32_digit_post_heating_off_cnt();
++g_u32UpdateCallCnt;
v2 = __ROR4__(-1527099483 * g_u32UpdateCallCnt, 4);
if ( v2 <= 0x123456 )
LOBYTE(v2) = save_on_time_to_file();
if ( g_bPostHeatingStarted )
{
if ( (_BYTE)v1 )
return v2;
goto LABEL_9;
}
if ( !(_BYTE)v1 )
{
LABEL_9:
g_bPostHeatingStarted = 0;
return v2;
}
v3 = (int)v0;
LOBYTE(v2) = __ROR1__(-51 * (int)v0, 1);
if ( (unsigned __int8)v2 <= 0x19u )
{
g_bPostHeatingStarted = 1;
LOBYTE(v2) = g_u32OnTimeTotal + 100 - v3;
g_u32OnTimeTotal = g_u32OnTimeTotal + 100 - (unsigned __int8)v3;
}
return v2;
}

canonical_decompiled_code:
char func3()
{
float v0; // xmm0_4
int v1; // ebx
unsigned int v2; // eax
int v3; // edx

v0 = r32_digit_post_heating_on_cnt();
v1 = (int)v0;
r32_digit_post_heating_off_cnt();
++g_u32UpdateCallCnt;
v2 = __ROR4__(-1527099483 * g_u32UpdateCallCnt, 4);
if ( v2 <= 0x123456 )
LOBYTE(v2) = func1();
if ( g_bPostHeatingStarted )
{
if ( (_BYTE)v1 )
return v2;
goto LABEL_9;
}
if ( !(_BYTE)v1 )
{
LABEL_9:
g_bPostHeatingStarted = 0;
return v2;
}
v3 = (int)v0;
LOBYTE(v2) = __ROR1__(-51 * (int)v0, 1);
if ( (unsigned __int8)v2 <= 0x19u )
{
g_bPostHeatingStarted = 1;
LOBYTE(v2) = g_u32OnTimeTotal + 100 - v3;
g_u32OnTimeTotal = g_u32OnTimeTotal + 100 - (unsigned __int8)v3;
}
return v2;
}

original_code:
void post_heating_counter_update()
{
    uint8 u8OnCnt = (uint8) r32_digit_post_heating_on_cnt();
    uint8 u8OffCnt = (uint8) r32_digit_post_heating_off_cnt();
    g_u32UpdateCallCnt++;
    if ( (g_u32UpdateCallCnt * (5)) %
         (60*60) == 0)
    {
        save_on_time_to_file();
    }
    if ( g_bPostHeatingStarted == 0 &&
         u8OnCnt > 0 &&
         !(u8OffCnt % 10) )
    {
        g_bPostHeatingStarted = 1;
        g_u32OnTimeTotal += (100 - u8OffCnt);
    }
    else if (u8OnCnt == 0)
    {
        g_bPostHeatingStarted = 0;
    }
}

canonical_original_code:
void post_heating_counter_update()
{
    unsigned char u8OnCnt = (uint8) r32_digit_post_heating_on_cnt();
    unsigned char u8OffCnt = (uint8) r32_digit_post_heating_off_cnt();
    g_u32UpdateCallCnt++;
    if ( (g_u32UpdateCallCnt * (5)) %
         (60*60) == 0)
    {
        save_on_time_to_file();
    }
    if ( g_bPostHeatingStarted == 0 &&
         u8OnCnt > 0 &&
         !(u8OffCnt % 10) )
    {
        g_bPostHeatingStarted = 1;
        g_u32OnTimeTotal += (100 - u8OffCnt);
    }
    else if (u8OnCnt == 0)
    {
        g_bPostHeatingStarted = 0;
    }
}


decompiled_code:
__int64 u32_post_heating_counter_get_on_time_total()
{
return (unsigned int)g_u32OnTimeTotal;
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)g_u32OnTimeTotal;
}

original_code:
uint32 u32_post_heating_counter_get_on_time_total()
{
    return g_u32OnTimeTotal;
}

canonical_original_code:
unsigned int u32_post_heating_counter_get_on_time_total()
{
    return g_u32OnTimeTotal;
}


decompiled_code:
float __fastcall r32_NTC_to_celsius(unsigned __int16 a1)
{
return c_NTC_temperature_conversion_table[a1];
}

canonical_decompiled_code:
float __fastcall func0(unsigned __int16 a1)
{
return c_NTC_temperature_conversion_table[a1];
}

original_code:
real32 r32_NTC_to_celsius(uint16 u16Ntc)
{
    return c_NTC_temperature_conversion_table[u16Ntc];
}

canonical_original_code:
float r32_NTC_to_celsius(unsigned short u16Ntc)
{
    return c_NTC_temperature_conversion_table[u16Ntc];
}


decompiled_code:
__int64 __fastcall u16_celsius_to_NTC(float a1)
{
__int64 result; // rax
float i; // xmm0_4

result = 0LL;
for ( i = *(float *)&LC0;
a1 < i || c_NTC_temperature_conversion_table[result + 1] < a1;
i = c_NTC_temperature_conversion_table[result] )
{
if ( ++result == 255 )
return 0LL;
}
return result;
}

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

result = 0LL;
for ( i = *(float *)&LC0;
a1 < i || c_NTC_temperature_conversion_table[result + 1] < a1;
i = c_NTC_temperature_conversion_table[result] )
{
if ( ++result == 255 )
return 0LL;
}
return result;
}

original_code:
uint16 u16_celsius_to_NTC(real32 r32Celcius)
{
    for (int i = 0; i < 255; i++)
    {
        if (c_NTC_temperature_conversion_table[i] <= r32Celcius &&
            r32Celcius <= c_NTC_temperature_conversion_table[i+1])
        {
            return i;
        }
    }
    return 0;
}

canonical_original_code:
unsigned short u16_celsius_to_NTC(float r32Celcius)
{
    for (int i = 0; i < 255; i++)
    {
        if (c_NTC_temperature_conversion_table[i] <= r32Celcius &&
            r32Celcius <= c_NTC_temperature_conversion_table[i+1])
        {
            return i;
        }
    }
    return 0;
}

return_type: unsigned short


initPilha

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

v2 = malloc(a2);
if ( !v2 )
return 0LL;
*(_DWORD *)a1 = -1;
*(_DWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

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

v2 = malloc(a2);
if ( !v2 )
return 0LL;
*(_DWORD *)a1 = -1;
*(_DWORD *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

original_code:
_Bool initPilha(pilha * pil, int tm){
    char * p;
    p = (char *) malloc(tm * sizeof(char));
    if(p == ((void *)0))
        return 0;
    pil->topo = -1;
    pil->p = p;
    pil->tm = tm;
    return 1;
}

canonical_original_code:
_Bool initPilha(struct tPilha *pil, int tm){
    char *p;
    p = (char *) malloc(tm * sizeof(char));
    if(p == ((void *)0))
        return 0;
    pil->topo = -1;
    pil->p = p;
    pil->tm = tm;
    return 1;
}

variable_types: struct tPilha { int topo; char *p; int tm; } *

variable_types: tm int

variable_types:
p
char *


isCheia

decompiled_code:
bool __fastcall isCheia(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9)
{
return a9 - 1 == a7;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9)
{
return a9 - 1 == a7;
}

original_code:
_Bool isCheia(pilha pil){
    if(pil.topo == pil.tm -1)
        return 1;
    return 0;
}

canonical_original_code:
_Bool isCheia(struct tPilha pil){
    if(pil.topo == pil.tm -1)
        return 1;
    return 0;
}

variable_types: struct tPilha { int topo; char *p; int tm; }


push

original_code:
_Bool push(pilha * pil, char value){
    if(isCheia(*pil))
        return 0;
    pil->p[pil->topo++] = value;
    return 1;
}

canonical_original_code:
_Bool push(struct tPilha *pil, char value){
    if(isCheia(*pil))
        return 0;
    pil->p[pil->topo++] = value;
    return 1;
}

variable_types: value char

user_defined_types: struct tPilha { int topo; char *p; int tm; }


pop

original_code:
_Bool pop(pilha * pil, char * value){
    if(pil->topo == -1)
        return 0;
    * value = pil->p[--pil->topo];
    return 1;
}

canonical_original_code:
_Bool pop(struct tPilha *pil, char *value){
    if(pil->topo == -1)
        return 0;
    * value = pil->p[--pil->topo];
    return 1;
}

variable_types:
value
char *


freePilha

decompiled_code:
__int64 __fastcall freePilha(void *a1)
{
free(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1)
{
free(a1);
return 1LL;
}

original_code:
_Bool freePilha(pilha * pil){
    free(pil);
    return 1;
}

canonical_original_code:
_Bool freePilha(struct tPilha *pil){
    free(pil);
    return 1;
}


main

original_code:
int main(){
    char strPadrao1[] = "ana maria";
    string str1, str2, str3;
    initString(&str1);
    printf("INIT: inicio[%p] Fim[%p] len[%d]\n", str1.inicio, str1.ultimo, str1.len);
    initString(&str2);
    printf("INIT: inicio[%p] Fim[%p] len[%d]\n", str2.inicio, str2.ultimo, str2.len);
    initString(&str3);
    printf("INIT: inicio[%p] Fim[%p] len[%d]\n", str3.inicio, str3.ultimo, str3.len);
    printf("\n\n<<<-----------createString---------------->>>\n");
    createString(&str1, strPadrao1);
    printStringFrente(str1);
    printf("\n\n<<<-----------copyString---------------->>>\n");
    copyString(&str1, &str2);
    printStringFrente(str2);
    printf("\n\n<<<-----------equalString---------------->>>\n");
    if(equalString(str1, str2))
        printf("String 1 igual a String 2");
    else
        printf("Strings diferentes ");
    printf("\n\n<<<-----------lenPalavras---------------->>>\n");
    printf("QTD: [%d] ",lenPalavras(str1));
    printf("\n\n<<<-----------concat--------------------->>>\n");
    concat(str1, str2, &str3);
    printStringFrente(str3);
    printf("\n\n<<<-----------inverterLetras------------->>>\n");
    inverterLetras(&str1);
    printStringFrente(str1);
    printf("\n\n<<<----------inverterPalavras------------>>>\n");
    inverterPalavras(&str1);
    printStringFrente(str1);
    printf("\n\n<<<--------inverterLetrasPalavras-------->>>\n");
    inverterLetrasPalavras(&str1);
    printStringFrente(str1);
    createString(&str1, "introducao a logica matematica");
    createString(&str2, "estruturas de dados");
    printf("\n\n<<<--------intercarlarPalavras----------->>>\n");
    printf("String 1 ....: ");
    printStringFrente(str1);
    printf("\nString 2 ....: ");
    printStringFrente(str2);
    printf("\n");
    intercarlarPalavras(str1, str2, &str3);
    printf("\n");
    printStringFrente(str3);
    printf("\n");
    return 0;
}

canonical_original_code:
int main(){
    char strPadrao1[] = "ana maria";
    struct tString str1; struct tString str2; struct tString str3;
    initString(&str1);
    printf("INIT: inicio[%p] Fim[%p] len[%d]\n", str1.inicio, str1.ultimo, str1.len);
    initString(&str2);
    printf("INIT: inicio[%p] Fim[%p] len[%d]\n", str2.inicio, str2.ultimo, str2.len);
    initString(&str3);
    printf("INIT: inicio[%p] Fim[%p] len[%d]\n", str3.inicio, str3.ultimo, str3.len);
    printf("\n\n<<<-----------createString---------------->>>\n");
    createString(&str1, strPadrao1);
    printStringFrente(str1);
    printf("\n\n<<<-----------copyString---------------->>>\n");
    copyString(&str1, &str2);
    printStringFrente(str2);
    printf("\n\n<<<-----------equalString---------------->>>\n");
    if(equalString(str1, str2))
        printf("String 1 igual a String 2");
    else
        printf("Strings diferentes ");
    printf("\n\n<<<-----------lenPalavras---------------->>>\n");
    printf("QTD: [%d] ",lenPalavras(str1));
    printf("\n\n<<<-----------concat--------------------->>>\n");
    concat(str1, str2, &str3);
    printStringFrente(str3);
    printf("\n\n<<<-----------inverterLetras------------->>>\n");
    inverterLetras(&str1);
    printStringFrente(str1);
    printf("\n\n<<<----------inverterPalavras------------>>>\n");
    inverterPalavras(&str1);
    printStringFrente(str1);
    printf("\n\n<<<--------inverterLetrasPalavras-------->>>\n");
    inverterLetrasPalavras(&str1);
    printStringFrente(str1);
    createString(&str1, "introducao a logica matematica");
    createString(&str2, "estruturas de dados");
    printf("\n\n<<<--------intercarlarPalavras----------->>>\n");
    printf("String 1 ....: ");
    printStringFrente(str1);
    printf("\nString 2 ....: ");
    printStringFrente(str2);
    printf("\n");
    intercarlarPalavras(str1, str2, &str3);
    printf("\n");
    printStringFrente(str3);
    printf("\n");
    return 0;
}

variable_types: struct tString { struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; } *inicio; struct tCaracter *ultimo; int len; }

user_defined_types: struct tString { struct tCaracter *inicio; struct tCaracter *ultimo; int len; }


initString

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

*(_QWORD *)a1 = 0LL;
result = 1LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

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

*(_QWORD *)a1 = 0LL;
result = 1LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
return result;
}

original_code:
_Bool initString(string * str){
    str->inicio = ((void *)0);
    str->ultimo = ((void *)0);
    str->len = 0;
    return 1;
}

canonical_original_code:
_Bool initString(struct tString *str){
    str->inicio = ((void *)0);
    str->ultimo = ((void *)0);
    str->len = 0;
    return 1;
}

variable_types: struct tString { struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; } *inicio; struct tCaracter *ultimo; int len; } *


equalString

original_code:
_Bool equalString(string str1, string str2){
    caracter * pos1, * pos2;
    if(str1.len != str2.len)
        return 0;
    pos1 = str1.inicio;
    pos2 = str2.inicio;
    while(pos1 != ((void *)0) && pos2 != ((void *)0)){
        if(pos1->value != pos2->value)
            return 0;
        pos1 = pos1->prox;
        pos2 = pos2->prox;
    }
    return 1;
}

canonical_original_code:
_Bool equalString(struct tString str1, struct tString str2){
    struct tCaracter *pos1; struct tCaracter *pos2;
    if(str1.len != str2.len)
        return 0;
    pos1 = str1.inicio;
    pos2 = str2.inicio;
    while(pos1 != ((void *)0) && pos2 != ((void *)0)){
        if(pos1->value != pos2->value)
            return 0;
        pos1 = pos1->prox;
        pos2 = pos2->prox;
    }
    return 1;
}

variable_types: struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; } *


lenPalavras

original_code:
int lenPalavras(string str){
    caracter * pos;
    int len = 1;
    if(str.len == 0)
        return 0;
    pos = str.inicio;
    while(pos != ((void *)0)){
        if(pos->value == ' ')
            len++;
        pos = pos->prox;
    }
    return len;
}

canonical_original_code:
int lenPalavras(struct tString str){
    struct tCaracter *pos;
    int len = 1;
    if(str.len == 0)
        return 0;
    pos = str.inicio;
    while(pos != ((void *)0)){
        if(pos->value == ' ')
            len++;
        pos = pos->prox;
    }
    return len;
}

variable_types: len int

user_defined_types: struct tCaracter { char value; struct tCaracter *prox; struct tCaracter *ante; }


inserirChar

decompiled_code:
__int64 __fastcall inserirChar(__int64 a1, char a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx
bool v4; // zf
__int64 result; // rax

v2 = malloc(0x18uLL);
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_QWORD *)a1 == 0LL;
*(_BYTE *)v2 = a2;
v2[2] = v3;
v2[1] = 0LL;
if ( v4 )
*(_QWORD *)a1 = v2;
else
*(_QWORD *)(v3 + 8) = v2;
*(_QWORD *)(a1 + 8) = v2;
result = 1LL;
++*(_DWORD *)(a1 + 16);
return result;
}

original_code:
_Bool inserirChar(string *str, char value){
    caracter * novo = (caracter *) malloc(sizeof(caracter));
    novo->value = value;
    novo->ante = str->ultimo;
    novo->prox = ((void *)0);
    if(novo == ((void *)0))
        return 0;
    if(str->inicio == ((void *)0)){
        str->inicio = novo;
    }else{
        str->ultimo->prox = novo;
    }
    str->ultimo = novo;
    str->len++;
    return 1;
}

canonical_original_code:
_Bool inserirChar(struct tString *str, char value){
    struct tCaracter *novo = (caracter *) malloc(sizeof(caracter));
    novo->value = value;
    novo->ante = str->ultimo;
    novo->prox = ((void *)0);
    if(novo == ((void *)0))
        return 0;
    if(str->inicio == ((void *)0)){
        str->inicio = novo;
    }else{
        str->ultimo->prox = novo;
    }
    str->ultimo = novo;
    str->len++;
    return 1;
}


copyString

decompiled_code:
__int64 __fastcall copyString(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = *a1;
if ( !*a1 )
return 1LL;
while ( 1 )
{
result = inserirChar(a2, *(_BYTE *)v2);
if ( !(_BYTE)result )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = *a1;
if ( !*a1 )
return 1LL;
while ( 1 )
{
result = func3(a2, *(_BYTE *)v2);
if ( !(_BYTE)result )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 1LL;
}
return result;
}

original_code:
_Bool copyString(string * str1, string * str2){
    caracter * pos;
    pos = str1->inicio;
    while(pos != ((void *)0)){
        if(!inserirChar(str2, pos->value))
            return 0;
        pos = pos->prox;
    }
    return 1;
}

canonical_original_code:
_Bool copyString(struct tString *str1, struct tString *str2){
    struct tCaracter *pos;
    pos = str1->inicio;
    while(pos != ((void *)0)){
        if(!inserirChar(str2, pos->value))
            return 0;
        pos = pos->prox;
    }
    return 1;
}


concat

decompiled_code:
__int64 __fastcall concat(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, __int64 a10)
{
__int64 result; // rax

result = copyString(&a7, a1);
if ( (_BYTE)result )
result = copyString(&a10, a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, __int64 a10)
{
__int64 result; // rax

result = func4(&a7, a1);
if ( (_BYTE)result )
result = func4(&a10, a1);
return result;
}

original_code:
_Bool concat(string str1, string str2, string * novaString){
    if(!copyString(&str1, novaString))
        return 0;
    if(!copyString(&str2, novaString))
        return 0;
    return 1;
}

canonical_original_code:
_Bool concat(struct tString str1, struct tString str2, struct tString *novaString){
    if(!copyString(&str1, novaString))
        return 0;
    if(!copyString(&str2, novaString))
        return 0;
    return 1;
}

variable_types:
novaString
struct tString *


intercarlarPalavras

decompiled_code:
__int64 __fastcall intercarlarPalavras(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, int a8, int a9, __int64 a10)
{
unsigned int v10; // er13
__int64 v12; // rbp
__int64 v14[9]; // [rsp+0h] [rbp-48h] BYREF

if ( !(unsigned __int8)initString((__int64)v14) )
return 0;
v10 = initString(a1);
if ( !(_BYTE)v10 )
return 0;
v12 = a7;
if ( a7 )
{
do
{
if ( *(_BYTE *)v12 == 32 )
{
inserirChar((__int64)v14, 32);
copyString(v14, a1);
if ( !(unsigned __int8)initString((__int64)v14) )
return 0;
if ( a10 )
{
while ( *(_BYTE *)a10 != 32 )
{
inserirChar((__int64)v14, *(_BYTE *)a10);
a10 = *(_QWORD *)(a10 + 8);
if ( !a10 )
goto LABEL_8;
}
copyString(v14, a1);
inserirChar(a1, 32);
if ( !(unsigned __int8)initString((__int64)v14) )
return 0;
a10 = *(_QWORD *)(a10 + 8);
}
}
else
{
inserirChar((__int64)v14, *(_BYTE *)v12);
}
LABEL_8:
v12 = *(_QWORD *)(v12 + 8);
}
while ( v12 );
copyString(v14, a1);
}
if ( !a10 )
return v10;
do
{
inserirChar(a1, *(_BYTE *)a10);
a10 = *(_QWORD *)(a10 + 8);
}
while ( a10 );
return v10;
}

original_code:
_Bool intercarlarPalavras(string str1, string str2, string * novaString){
    caracter * pos, * pos2, * aux;
    string strAux;
    _Bool palavraInserida = 0;
    if(!initString(&strAux))
        return 0;
    if(!initString(novaString))
        return 0;
    pos = str1.inicio;
    pos2 = str2.inicio;
    while(pos != ((void *)0)){
        if(pos->value != ' '){
            inserirChar(&strAux, pos->value);
        }else{
            inserirChar(&strAux, ' ');
            copyString(&strAux, novaString);
            palavraInserida = 0;
            if(!initString(&strAux))
                return 0;
            while(pos2 != ((void *)0) && !palavraInserida){
                if(pos2->value != ' '){
                    inserirChar(&strAux, pos2->value);
                }else{
                    copyString(&strAux, novaString);
                    inserirChar(novaString, ' ');
                    if(!initString(&strAux))
                        return 0;
                    palavraInserida = 1;
                }
                pos2 = pos2->prox;
            }
        }
        aux = pos;
        pos = pos->prox;
        if(pos == ((void *)0))
            copyString(&strAux, novaString);
    }
    while(pos2 != ((void *)0)){
        inserirChar(novaString, pos2->value);
        pos2 = pos2->prox;
    }
    return 1;
}

canonical_original_code:
_Bool intercarlarPalavras(struct tString str1, struct tString str2, struct tString *novaString){
    struct tCaracter *pos; struct tCaracter *pos2; struct tCaracter *aux;
    struct tString strAux;
    _Bool palavraInserida = 0;
    if(!initString(&strAux))
        return 0;
    if(!initString(novaString))
        return 0;
    pos = str1.inicio;
    pos2 = str2.inicio;
    while(pos != ((void *)0)){
        if(pos->value != ' '){
            inserirChar(&strAux, pos->value);
        }else{
            inserirChar(&strAux, ' ');
            copyString(&strAux, novaString);
            palavraInserida = 0;
            if(!initString(&strAux))
                return 0;
            while(pos2 != ((void *)0) && !palavraInserida){
                if(pos2->value != ' '){
                    inserirChar(&strAux, pos2->value);
                }else{
                    copyString(&strAux, novaString);
                    inserirChar(novaString, ' ');
                    if(!initString(&strAux))
                        return 0;
                    palavraInserida = 1;
                }
                pos2 = pos2->prox;
            }
        }
        aux = pos;
        pos = pos->prox;
        if(pos == ((void *)0))
            copyString(&strAux, novaString);
    }
    while(pos2 != ((void *)0)){
        inserirChar(novaString, pos2->value);
        pos2 = pos2->prox;
    }
    return 1;
}


clearString

decompiled_code:
__int64 __fastcall clearString(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free(v2);
}
while ( v1 );
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free(v2);
}
while ( v1 );
}
return 1LL;
}

original_code:
_Bool clearString(string * str){
    caracter * pos, * aux;
    pos = str->inicio;
    while(pos != ((void *)0)){
        aux = pos;
        pos = pos->prox;
        free(aux);
    }
    return 1;
}

canonical_original_code:
_Bool clearString(struct tString *str){
    struct tCaracter *pos; struct tCaracter *aux;
    pos = str->inicio;
    while(pos != ((void *)0)){
        aux = pos;
        pos = pos->prox;
        free(aux);
    }
    return 1;
}


createString

decompiled_code:
__int64 __fastcall createString(_QWORD *a1, char *a2)
{
char v3; // si
char *i; // rbx
__int64 result; // rax

clearString(a1);
initString((__int64)a1);
v3 = *a2;
if ( !*a2 )
return 1LL;
for ( i = a2 + 1; ; ++i )
{
result = inserirChar((__int64)a1, v3);
if ( !(_BYTE)result )
break;
v3 = *i;
if ( !v3 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, char *a2)
{
char v3; // si
char *i; // rbx
__int64 result; // rax

func7(a1);
func0((__int64)a1);
v3 = *a2;
if ( !*a2 )
return 1LL;
for ( i = a2 + 1; ; ++i )
{
result = func3((__int64)a1, v3);
if ( !(_BYTE)result )
break;
v3 = *i;
if ( !v3 )
return 1LL;
}
return result;
}

original_code:
_Bool createString(string * str, const char* strPadrao){
    clearString(str);
    initString(str);
    int len;
    for(len = 0; strPadrao[len] != 0; len++){
        if(!inserirChar(str, strPadrao[len]))
            return 0;
    }
    return 1;
}

canonical_original_code:
_Bool createString(struct tString *str, char *strPadrao){
    clearString(str);
    initString(str);
    int len;
    for(len = 0; strPadrao[len] != 0; len++){
        if(!inserirChar(str, strPadrao[len]))
            return 0;
    }
    return 1;
}

variable_types:
strPadrao
char *


inserirStringEmPilha

decompiled_code:
__int64 __fastcall inserirStringEmPilha(__int64 a1, int a2, int a3, int a4, int a5, int a6, void *ptr)
{
_QWORD *v7; // rbp
_QWORD *v8; // rbx
__int64 result; // rax

v7 = ptr;
if ( !ptr )
return 1LL;
while ( 1 )
{
result = push(a1, (unsigned int)*(char *)v7);
if ( !(_BYTE)result )
break;
v8 = (_QWORD *)v7[1];
free(v7);
if ( !v8 )
return 1LL;
v7 = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3, int a4, int a5, int a6, void *ptr)
{
_QWORD *v7; // rbp
_QWORD *v8; // rbx
__int64 result; // rax

v7 = ptr;
if ( !ptr )
return 1LL;
while ( 1 )
{
result = push(a1, (unsigned int)*(char *)v7);
if ( !(_BYTE)result )
break;
v8 = (_QWORD *)v7[1];
free(v7);
if ( !v8 )
return 1LL;
v7 = v8;
}
return result;
}

original_code:
_Bool inserirStringEmPilha(string str, pilha * pil){
    caracter * pos, * aux;
    pos = str.inicio;
    while(pos != ((void *)0)){
        if(!push(pil, pos->value))
            return 0;
        aux = pos;
        pos = pos->prox;
        free(aux);
    }
    return 1;
}

canonical_original_code:
_Bool inserirStringEmPilha(struct tString str, struct tPilha *pil){
    struct tCaracter *pos; struct tCaracter *aux;
    pos = str.inicio;
    while(pos != ((void *)0)){
        if(!push(pil, pos->value))
            return 0;
        aux = pos;
        pos = pos->prox;
        free(aux);
    }
    return 1;
}


inserirPilhaEmString

decompiled_code:
__int64 __fastcall inserirPilhaEmString(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

while ( (unsigned __int8)pop(a1, v3) )
{
result = inserirChar(a2, v3[0]);
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3[25]; // [rsp+Fh] [rbp-19h] BYREF

while ( (unsigned __int8)pop(a1, v3) )
{
result = func3(a2, v3[0]);
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

original_code:
_Bool inserirPilhaEmString(pilha * pil, string * str){
    char ch;
    while(pop(pil, &ch)){
        if(!inserirChar(str, ch))
            return 0;
    }
    return 1;
}

canonical_original_code:
_Bool inserirPilhaEmString(struct tPilha *pil, struct tString *str){
    char ch;
    while(pop(pil, &ch)){
        if(!inserirChar(str, ch))
            return 0;
    }
    return 1;
}

variable_types: ch char


inverterLetras

decompiled_code:
__int64 __fastcall inverterLetras(__int64 a1)
{
char *v2; // rbx
void *v3; // rdi
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

initPilha(v5, *(unsigned int *)(a1 + 16));
v2 = *(char **)a1;
if ( *(_QWORD *)a1 )
{
do
{
push(v5, (unsigned int)*v2);
v3 = v2;
v2 = (char *)*((_QWORD *)v2 + 1);
free(v3);
}
while ( v2 );
}
initString(a1);
inserirPilhaEmString((__int64)v5, a1);
freePilha(v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
char *v2; // rbx
void *v3; // rdi
_BYTE v5[56]; // [rsp+0h] [rbp-38h] BYREF

initPilha(v5, *(unsigned int *)(a1 + 16));
v2 = *(char **)a1;
if ( *(_QWORD *)a1 )
{
do
{
push(v5, (unsigned int)*v2);
v3 = v2;
v2 = (char *)*((_QWORD *)v2 + 1);
free(v3);
}
while ( v2 );
}
func0(a1);
func10((__int64)v5, a1);
freePilha(v5);
return 1LL;
}

original_code:
_Bool inverterLetras(string * str){
    caracter * pos, * aux;
    pilha pil;
    initPilha(&pil, str->len);
    pos = str->inicio;
    while(pos != ((void *)0)){
        push(&pil, pos->value);
        aux = pos;
        pos = pos->prox;
        free(aux);
    }
    initString(str);
    inserirPilhaEmString(&pil, str);
    freePilha(&pil);
    return 1;
}

canonical_original_code:
_Bool inverterLetras(struct tString *str){
    struct tCaracter *pos; struct tCaracter *aux;
    struct tPilha pil;
    initPilha(&pil, str->len);
    pos = str->inicio;
    while(pos != ((void *)0)){
        push(&pil, pos->value);
        aux = pos;
        pos = pos->prox;
        free(aux);
    }
    initString(str);
    inserirPilhaEmString(&pil, str);
    freePilha(&pil);
    return 1;
}