main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
__int64 i; // rax
__int64 k; // rdi
int v8; // esi
int v9; // eax
__int64 j; // rdi
int v11; // esi
__int64 l; // r15
__int64 m; // r15
size_t v14; // rax
unsigned __int64 v15; // rax
int v16; // edi
int v17; // eax
ssize_t v18; // rax
_DWORD v19[102]; // [rsp-190h] [rbp-A80h]
void *buf; // [rsp+8h] [rbp-8E8h]
unsigned __int64 v21; // [rsp+10h] [rbp-8E0h]
int fd[2]; // [rsp+18h] [rbp-8D8h]
char v23[2048]; // [rsp+20h] [rbp-8D0h] BYREF
struct timeval timeout; // [rsp+820h] [rbp-D0h] BYREF
fd_set readfds; // [rsp+830h] [rbp-C0h] BYREF
int v26[15]; // [rsp+8B4h] [rbp-3Ch]

v26[0] = sb_bound_socket(22);
v26[1] = sb_bound_socket(222);
v26[2] = sb_bound_socket(2222);
if ( chroot("/var/empty") < 0 )
{
perror("[!] chroot() failed");
exit(1);
}
if ( setgid(0xFFFEu) < 0 )
{
perror("[!] Setting group id failed");
exit(1);
}
if ( setuid(0xFFFEu) < 0 )
{
perror("[!] Setting user id failed");
exit(1);
}
printf("[+] Listening on %zu sockets for maximum %zu clients.\n", 3uLL, 0x64uLL);
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
perror("[!] fork() failed");
exit(1);
}
if ( !v3 )
{
for ( i = 0LL; i != 100; ++i )
v19[i] = -1;
v21 = 0LL;
while ( 1 )
{
do
{
memset(&readfds, 0, sizeof(readfds));
for ( j = 0LL; j != 3; ++j )
{
v11 = v26[j];
readfds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
if ( v4 < v11 )
v4 = v11;
}
for ( k = 0LL; k != 100; ++k )
{
v8 = v19[k];
if ( v8 != -1 )
{
readfds.fds_bits[v8 / 64] |= 1LL << (v8 % 64);
if ( v4 < v8 )
v4 = v8;
}
}
++v4;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v9 = select(v4, &readfds, 0LL, 0LL, &timeout);
if ( v9 == -1 )
{
perror("[!] select() failed");
exit(1);
}
}
while ( !v9 );
for ( l = 0LL; l != 3; ++l )
{
if ( (readfds.fds_bits[v26[l] / 64] & (1LL << (v26[l] % 64))) != 0 )
{
fd[0] = sb_verbose_accept(v26[l]);
buf = (&off_402228)[2 * l];
v14 = strlen((const char *)buf);
if ( write(fd[0], buf, v14) < 0 )
{
perror("[!] Writing version to client failed");
close(fd[0]);
}
else
{
v15 = v21;
v19[v21] = fd[0];
v21 = (v15 + 1) % 0x64;
*(_QWORD *)fd = v21;
v16 = v19[v21];
if ( v16 != -1 )
{
close(v16);
v19[*(_QWORD *)fd] = -1;
}
}
}
}
for ( m = 0LL; m != 100; ++m )
{
v17 = v19[m];
fd[0] = v17;
if ( v17 != -1 && (readfds.fds_bits[v17 / 64] & (1LL << (v17 % 64))) != 0 )
{
while ( 1 )
{
v18 = read(fd[0], v23, 0x800uLL);
if ( v18 < 0 )
break;
if ( !v18 )
{
close(fd[0]);
v19[m] = -1;
goto LABEL_38;
}
if ( (unsigned __int64)v18 <= 0x7FF )
goto LABEL_38;
}
if ( *__errno_location() != 11 )
perror("[!] Read error");
}
LABEL_38:
;
}
}
}
printf("[+] Daemon is PID %d\n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
__int64 i; // rax
__int64 k; // rdi
int v8; // esi
int v9; // eax
__int64 j; // rdi
int v11; // esi
__int64 l; // r15
__int64 m; // r15
size_t v14; // rax
unsigned __int64 v15; // rax
int v16; // edi
int v17; // eax
ssize_t v18; // rax
_DWORD v19[102]; // [rsp-190h] [rbp-A80h]
void *buf; // [rsp+8h] [rbp-8E8h]
unsigned __int64 v21; // [rsp+10h] [rbp-8E0h]
int fd[2]; // [rsp+18h] [rbp-8D8h]
char v23[2048]; // [rsp+20h] [rbp-8D0h] BYREF
struct timeval timeout; // [rsp+820h] [rbp-D0h] BYREF
fd_set readfds; // [rsp+830h] [rbp-C0h] BYREF
int v26[15]; // [rsp+8B4h] [rbp-3Ch]

v26[0] = func8(22);
v26[1] = func8(222);
v26[2] = func8(2222);
if ( chroot("/var/empty") < 0 )
{
perror("[!] chroot() failed");
exit(1);
}
if ( setgid(0xFFFEu) < 0 )
{
perror("[!] Setting group id failed");
exit(1);
}
if ( setuid(0xFFFEu) < 0 )
{
perror("[!] Setting user id failed");
exit(1);
}
printf("[+] Listening on %zu sockets for maximum %zu clients.\n", 3uLL, 0x64uLL);
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
perror("[!] fork() failed");
exit(1);
}
if ( !v3 )
{
for ( i = 0LL; i != 100; ++i )
v19[i] = -1;
v21 = 0LL;
while ( 1 )
{
do
{
memset(&readfds, 0, sizeof(readfds));
for ( j = 0LL; j != 3; ++j )
{
v11 = v26[j];
readfds.fds_bits[v11 / 64] |= 1LL << (v11 % 64);
if ( v4 < v11 )
v4 = v11;
}
for ( k = 0LL; k != 100; ++k )
{
v8 = v19[k];
if ( v8 != -1 )
{
readfds.fds_bits[v8 / 64] |= 1LL << (v8 % 64);
if ( v4 < v8 )
v4 = v8;
}
}
++v4;
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v9 = select(v4, &readfds, 0LL, 0LL, &timeout);
if ( v9 == -1 )
{
perror("[!] select() failed");
exit(1);
}
}
while ( !v9 );
for ( l = 0LL; l != 3; ++l )
{
if ( (readfds.fds_bits[v26[l] / 64] & (1LL << (v26[l] % 64))) != 0 )
{
fd[0] = func9(v26[l]);
buf = (&off_402228)[2 * l];
v14 = strlen((const char *)buf);
if ( write(fd[0], buf, v14) < 0 )
{
perror("[!] Writing version to client failed");
close(fd[0]);
}
else
{
v15 = v21;
v19[v21] = fd[0];
v21 = (v15 + 1) % 0x64;
*(_QWORD *)fd = v21;
v16 = v19[v21];
if ( v16 != -1 )
{
close(v16);
v19[*(_QWORD *)fd] = -1;
}
}
}
}
for ( m = 0LL; m != 100; ++m )
{
v17 = v19[m];
fd[0] = v17;
if ( v17 != -1 && (readfds.fds_bits[v17 / 64] & (1LL << (v17 % 64))) != 0 )
{
while ( 1 )
{
v18 = read(fd[0], v23, 0x800uLL);
if ( v18 < 0 )
break;
if ( !v18 )
{
close(fd[0]);
v19[m] = -1;
goto LABEL_38;
}
if ( (unsigned __int64)v18 <= 0x7FF )
goto LABEL_38;
}
if ( *__errno_location() != 11 )
perror("[!] Read error");
}
LABEL_38:
;
}
}
}
printf("[+] Daemon is PID %d\n", v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    const size_t num_configs = sizeof(sb_listen_config) /
                               sizeof(struct sb_listen_config_t);
    const size_t max_num_clients = 1024 - num_configs;
    if(sb_num_clients > max_num_clients) {
        fprintf(stderr, "[!] Configured number of clients (%zu) is larger "
                        "than maximum available number of clients (%zu).\n",
                sb_num_clients, max_num_clients);
        return 1;
    }
    int listen_sockets[num_configs];
    for(size_t i = 0; i < num_configs; ++i)
        listen_sockets[i] = sb_bound_socket(sb_listen_config[i].port);
    if(chroot(sb_chroot) < 0)
        { perror("[!] ""chroot() failed"); exit(1); }
    if(setgid(sb_userid) < 0)
        { perror("[!] ""Setting group id failed"); exit(1); }
    if(setuid(sb_userid) < 0)
        { perror("[!] ""Setting user id failed"); exit(1); }
    printf("[+] Listening on %zu sockets for maximum %zu clients.\n",
           num_configs, sb_num_clients);
    pid_t daemon_pid = fork();
    switch(daemon_pid) {
        case -1:
            { perror("[!] ""fork() failed"); exit(1); }
        case 0:
            break;
        default:
            printf("[+] Daemon is PID %d\n", daemon_pid);
            return 0;
    }
    fd_set all_sockets;
    struct timeval tv;
    int ready_sockets;
    int max_fd = 0;
    int client_ring[sb_num_clients];
    for(size_t i = 0; i < sb_num_clients; ++i)
        client_ring[i] = -1;
    size_t next_free_client = 0;
    char nirvana[2048];
    for(;;) {
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&all_sockets)->__fds_bits)[0]) : "memory"); } while (0);
        for(size_t i = 0; i < num_configs; ++i) {
            ((void) (((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))));
            if(listen_sockets[i] > max_fd)
                max_fd = listen_sockets[i];
        }
        for(size_t i = 0; i < sb_num_clients; ++i) {
            int client = client_ring[i];
            if(client != -1) {
                ((void) (((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))));
                if(client > max_fd)
                    max_fd = client;
            }
        }
        ++max_fd;
        tv.tv_sec = 10;
        tv.tv_usec = 0;
        ready_sockets = select(max_fd, &all_sockets, ((void *)0), ((void *)0), &tv);
        if(ready_sockets == -1)
            { perror("[!] ""select() failed"); exit(1); }
        else if(ready_sockets) {
            for(size_t i = 0; i < num_configs; ++i) {
                if(((((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                    int client = sb_verbose_accept(listen_sockets[i]);
                    const char * version = sb_listen_config[i].version_string;
                    if(write(client, version, strlen(version)) < 0) {
                        perror("[!] Writing version to client failed");
                        close(client);
                    }
                    else {
                        client_ring[next_free_client] = client;
                        next_free_client = (next_free_client + 1) %
                                           sb_num_clients;
                        if(client_ring[next_free_client] != -1) {
                            close(client_ring[next_free_client]);
                            client_ring[next_free_client] = -1;
                        }
                    }
                }
            }
            for(size_t i = 0; i < sb_num_clients; ++i) {
                int client = client_ring[i];
                if(client != -1) {
                    if(((((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                        ssize_t did_read;
                        for(;;) {
                            did_read = read(client, nirvana, sizeof(nirvana));
                            if(did_read < 0) {
                                if((*__errno_location ()) == 11) {
                                    break;
                                }
                                perror("[!] Read error");
                                break;
                            }
                            else if(did_read == 0) {
                                close(client);
                                client_ring[i] = -1;
                                break;
                            }
                            else if(did_read < sizeof(nirvana)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    unsigned long num_configs = sizeof(sb_listen_config) /
                               sizeof(struct sb_listen_config_t);
    unsigned long max_num_clients = 1024 - num_configs;
    if(sb_num_clients > max_num_clients) {
        fprintf(stderr, "[!] Configured number of clients (%zu) is larger "
                        "than maximum available number of clients (%zu).\n",
                sb_num_clients, max_num_clients);
        return 1;
    }
    int listen_sockets[-1];
    for(unsigned long i = 0; i < num_configs; ++i)
        listen_sockets[i] = sb_bound_socket(sb_listen_config[i].port);
    if(chroot(sb_chroot) < 0)
        { perror("[!] ""chroot() failed"); exit(1); }
    if(setgid(sb_userid) < 0)
        { perror("[!] ""Setting group id failed"); exit(1); }
    if(setuid(sb_userid) < 0)
        { perror("[!] ""Setting user id failed"); exit(1); }
    printf("[+] Listening on %zu sockets for maximum %zu clients.\n",
           num_configs, sb_num_clients);
    int daemon_pid = fork();
    switch(daemon_pid) {
        case -1:
            { perror("[!] ""fork() failed"); exit(1); }
        case 0:
            break;
        default:
            printf("[+] Daemon is PID %d\n", daemon_pid);
            return 0;
    }
    struct fd_set all_sockets;
    struct timeval tv;
    int ready_sockets;
    int max_fd = 0;
    int client_ring[-1];
    for(unsigned long i = 0; i < sb_num_clients; ++i)
        client_ring[i] = -1;
    unsigned long next_free_client = 0;
    char nirvana[2048];
    for(;;) {
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&all_sockets)->__fds_bits)[0]) : "memory"); } while (0);
        for(unsigned long i = 0; i < num_configs; ++i) {
            ((void) (((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))));
            if(listen_sockets[i] > max_fd)
                max_fd = listen_sockets[i];
        }
        for(unsigned long i = 0; i < sb_num_clients; ++i) {
            int client = client_ring[i];
            if(client != -1) {
                ((void) (((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))));
                if(client > max_fd)
                    max_fd = client;
            }
        }
        ++max_fd;
        tv.tv_sec = 10;
        tv.tv_usec = 0;
        ready_sockets = select(max_fd, &all_sockets, ((void *)0), ((void *)0), &tv);
        if(ready_sockets == -1)
            { perror("[!] ""select() failed"); exit(1); }
        else if(ready_sockets) {
            for(unsigned long i = 0; i < num_configs; ++i) {
                if(((((&all_sockets)->__fds_bits)[((listen_sockets[i]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listen_sockets[i]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                    int client = sb_verbose_accept(listen_sockets[i]);
                    char *version = sb_listen_config[i].version_string;
                    if(write(client, version, strlen(version)) < 0) {
                        perror("[!] Writing version to client failed");
                        close(client);
                    }
                    else {
                        client_ring[next_free_client] = client;
                        next_free_client = (next_free_client + 1) %
                                           sb_num_clients;
                        if(client_ring[next_free_client] != -1) {
                            close(client_ring[next_free_client]);
                            client_ring[next_free_client] = -1;
                        }
                    }
                }
            }
            for(unsigned long i = 0; i < sb_num_clients; ++i) {
                int client = client_ring[i];
                if(client != -1) {
                    if(((((&all_sockets)->__fds_bits)[((client) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((client) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
                        long did_read;
                        for(;;) {
                            did_read = read(client, nirvana, sizeof(nirvana));
                            if(did_read < 0) {
                                if((*__errno_location ()) == 11) {
                                    break;
                                }
                                perror("[!] Read error");
                                break;
                            }
                            else if(did_read == 0) {
                                close(client);
                                client_ring[i] = -1;
                                break;
                            }
                            else if(did_read < sizeof(nirvana)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
i
unsigned long

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

variable_types:
nirvana
char [2048]

variable_types: client int

variable_types:
version
char *


Busca

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

if ( (int)a3 > a4 )
return 0xFFFFFFFFLL;
result = (unsigned int)a4;
if ( *(_DWORD *)(a2 + 4LL * a4) < (int)a1 )
result = Busca(a1, a2, a3, (unsigned int)(a4 - 1));
return result;
}

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

if ( (int)a3 > a4 )
return 0xFFFFFFFFLL;
result = (unsigned int)a4;
if ( *(_DWORD *)(a2 + 4LL * a4) < (int)a1 )
result = func7(a1, a2, a3, (unsigned int)(a4 - 1));
return result;
}

original_code:
int Busca(int x, int *v, int a, int b)
{
 if (a > b)
  return -1;
 if (x <= v[b])
  return b;
 return Busca(x, v, a, b - 1);
}

variable_types: x int

variable_types:
v
int *

variable_types: a int

variable_types: b int

return_type: int


Troca

decompiled_code:
__int64 __fastcall Troca(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int *v4; // rcx
int v5; // esi
int *v6; // rdx

result = a1;
v4 = (int *)(a1 + 4LL * a2);
v5 = *v4;
v6 = (int *)(a1 + 4LL * a3);
*v4 = *v6;
*v6 = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int *v4; // rcx
int v5; // esi
int *v6; // rdx

result = a1;
v4 = (int *)(a1 + 4LL * a2);
v5 = *v4;
v6 = (int *)(a1 + 4LL * a3);
*v4 = *v6;
*v6 = v5;
return result;
}

original_code:
int *Troca(int *v, int a, int b)
{
 int temp;
 temp = v[a];
 v[a]= v[b];
 v[b]= temp;
 return v;
}

variable_types: temp int

return_type: int *


Insere

decompiled_code:
__int64 __fastcall Insere(__int64 a1, unsigned int a2, int a3)
{
int v3; // ebx
int v4; // eax
int v5; // er12
int v6; // esi

v3 = a3;
v4 = Busca(*(unsigned int *)(a1 + 4LL * a3), a1, a2, a3 - 1);
if ( v4 >= 0 )
{
v5 = v4;
if ( v3 > v4 )
{
do
{
v6 = v3--;
Troca(a1, v6, v3);
}
while ( v3 != v5 );
}
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, int a3)
{
int v3; // ebx
int v4; // eax
int v5; // er12
int v6; // esi

v3 = a3;
v4 = func7(*(unsigned int *)(a1 + 4LL * a3), a1, a2, a3 - 1);
if ( v4 >= 0 )
{
v5 = v4;
if ( v3 > v4 )
{
do
{
v6 = v3--;
func8(a1, v6, v3);
}
while ( v3 != v5 );
}
}
return a1;
}

original_code:
int *Insere(int *v, int a, int b)
{
 int p, i;
 p = Busca(v[b], v, a, b - 1);
 i = b;
 if (p >= 0)
 {
  while (i >= (p + 1))
  {
   Troca(v, i, i - 1);
   i--;
  }
 }
 return v;
}

canonical_original_code:
int *Insere(int *v, int a, int b)
{
 int p; int i;
 p = Busca(v[b], v, a, b - 1);
 i = b;
 if (p >= 0)
 {
  while (i >= (p + 1))
  {
   Troca(v, i, i - 1);
   i--;
  }
 }
 return v;
}

variable_types: p int

variable_types: i int


Insertion

decompiled_code:
__int64 __fastcall Insertion(__int64 a1, __int64 a2, int a3)
{
if ( a3 > (int)a2 )
{
Insertion(a1, a2, (unsigned int)(a3 - 1));
Insere(a1, a2, a3);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
if ( a3 > (int)a2 )
{
func10(a1, a2, (unsigned int)(a3 - 1));
func9(a1, a2, a3);
}
return a1;
}

original_code:
int *Insertion(int *v, int a, int b)
{
 if (a > b - 1)
  return v;
 Insertion(v, a, b - 1);
 Insere(v, a, b);
 return v;
}


Particiona

decompiled_code:
__int64 __fastcall Particiona(__int64 a1, signed int a2, int a3)
{
unsigned int v3; // ebp
int v4; // er14
__int64 v5; // rbx

v3 = a2;
v4 = *(_DWORD *)(a1 + 4LL * a2);
LODWORD(v5) = a2 + 1;
if ( a2 + 1 <= a3 )
{
v5 = (int)v5;
do
{
if ( *(_DWORD *)(a1 + 4 * v5) < v4 )
Troca(a1, v3++, v5);
++v5;
}
while ( a3 >= (int)v5 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, signed int a2, int a3)
{
unsigned int v3; // ebp
int v4; // er14
__int64 v5; // rbx

v3 = a2;
v4 = *(_DWORD *)(a1 + 4LL * a2);
LODWORD(v5) = a2 + 1;
if ( a2 + 1 <= a3 )
{
v5 = (int)v5;
do
{
if ( *(_DWORD *)(a1 + 4 * v5) < v4 )
func8(a1, v3++, v5);
++v5;
}
while ( a3 >= (int)v5 );
}
return v3;
}

original_code:
int Particiona(int *v, int a, int b, int pivot)
{
 pivot = v[a];
 int iPivot = a;
 int j = a + 1, i;
 while (j <= b)
 {
  if (v[j] < pivot)
  {
   Troca(v, iPivot, j);
   iPivot = iPivot + 1;
  }
  j++;
 }
 return iPivot;
}

canonical_original_code:
int Particiona(int *v, int a, int b, int pivot)
{
 pivot = v[a];
 int iPivot = a;
 int j = a + 1; int i;
 while (j <= b)
 {
  if (v[j] < pivot)
  {
   Troca(v, iPivot, j);
   iPivot = iPivot + 1;
  }
  j++;
 }
 return iPivot;
}

variable_types: pivot int

variable_types: iPivot int

variable_types: j int


QuickInsert

decompiled_code:
__int64 __fastcall QuickInsert(__int64 a1, __int64 a2, int a3)
{
int v5; // eax
int v6; // eax

if ( a3 - (int)a2 <= 3 )
{
Insertion(a1, a2, a3);
}
else if ( a3 > (int)a2 )
{
v5 = Particiona(a1, a2, a3);
QuickInsert(a1, (unsigned int)a2, (unsigned int)(v5 - 1));
v6 = Particiona(a1, a2, a3);
QuickInsert(a1, (unsigned int)(v6 + 1), (unsigned int)a3);
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, int a3)
{
int v5; // eax
int v6; // eax

if ( a3 - (int)a2 <= 3 )
{
func10(a1, a2, a3);
}
else if ( a3 > (int)a2 )
{
v5 = func11(a1, a2, a3);
func12(a1, (unsigned int)a2, (unsigned int)(v5 - 1));
v6 = func11(a1, a2, a3);
func12(a1, (unsigned int)(v6 + 1), (unsigned int)a3);
}
return a1;
}

original_code:
int *QuickInsert(int *v, int a, int b)
{
 int m, q;
 int n = 0;
 int p = 0;
 if ((b - a + 1) < 5)
 {
  Insertion(v, a, b);
  return v;
 }
 if (a < b)
 {
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, a, m-1);
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, m+1, b);
 }
 return v;
}

canonical_original_code:
int *QuickInsert(int *v, int a, int b)
{
 int m; int q;
 int n = 0;
 int p = 0;
 if ((b - a + 1) < 5)
 {
  Insertion(v, a, b);
  return v;
 }
 if (a < b)
 {
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, a, m-1);
  m = Particiona(v, a, b, v[b]);
  QuickInsert(v, m+1, b);
 }
 return v;
}

variable_types: m int

variable_types: q int

variable_types: n int


objectcmp

decompiled_code:
__int64 __fastcall objectcmp(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 > *a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
result = *a1 > *a2;
return result;
}

original_code:
int objectcmp(object *o1, object *o2) {
  return *o1 < *o2 ? -1 : *o1 > *o2 ? 1 : 0;
}

canonical_original_code:
int objectcmp(int *o1, int *o2) {
  return *o1 < *o2 ? -1 : *o1 > *o2 ? 1 : 0;
}


modulo

decompiled_code:
__int64 __fastcall modulo(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return abs32(a1);
}

original_code:
int modulo(int n)
{
 if (n<0)
  return (-1)*n;
 return n;
}


decompiled_code:
int __fastcall print_tree(unsigned int **a1)
{
unsigned int *v2; // rdi

if ( !*a1 )
return 0;
putchar(40);
v2 = *a1;
if ( *((_QWORD *)*a1 + 1) )
print_tree(v2 + 2);
printf(") %d[%d] (", **a1, (unsigned int)*((char *)*a1 + 4));
if ( *((_QWORD *)*a1 + 2) )
print_tree(*a1 + 4);
return putchar(41);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int **a1)
{
unsigned int *v2; // rdi

if ( !*a1 )
return 0;
putchar(40);
v2 = *a1;
if ( *((_QWORD *)*a1 + 1) )
func3(v2 + 2);
printf(") %d[%d] (", **a1, (unsigned int)*((char *)*a1 + 4));
if ( *((_QWORD *)*a1 + 2) )
func3(*a1 + 4);
return putchar(41);
}

original_code:
int print_tree(node **n)
{
 if( ! *n )
  return 0;
 printf("(");
 if ((*n)->left)
  print_tree(&(*n)->left);
 printf(") %d[%d] (",(*n)->value,(*n)->balance);
 if ((*n)->right)
  print_tree(&(*n)->right);
 printf(")");
}

canonical_original_code:
int print_tree(struct node **n)
{
 if( ! *n )
  return 0;
 printf("(");
 if ((*n)->left)
  print_tree(&(*n)->left);
 printf(") %d[%d] (",(*n)->value,(*n)->balance);
 if ((*n)->right)
  print_tree(&(*n)->right);
 printf(")");
}

variable_types: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; } **


decompiled_code:
int __fastcall print_tree_border(unsigned int **a1)
{
putchar(40);
print_tree(a1);
return puts(")");
}

canonical_decompiled_code:
int __fastcall func4(unsigned int **a1)
{
putchar(40);
func3(a1);
return puts(")");
}

original_code:
int print_tree_border(node **n)
{
 printf("(");
 print_tree(n);
 printf(")\n");
}

canonical_original_code:
int print_tree_border(struct node **n)
{
 printf("(");
 print_tree(n);
 printf(")\n");
}

user_defined_types: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; }


original_code:
node* destroy_node(node **n) {
 if (*n) {
  (*n)->value = 0;
  (*n)->balance = 0;
  (*n)->left = ((void *)0);
  (*n)->right = ((void *)0);
  free(*n);
 }
 return ((void *)0);
}

canonical_original_code:
struct node *destroy_node(struct node **n) {
 if (*n) {
  (*n)->value = 0;
  (*n)->balance = 0;
  (*n)->left = ((void *)0);
  (*n)->right = ((void *)0);
  free(*n);
 }
 return ((void *)0);
}

variable_types:
n
struct node **

return_type: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; } *


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

result = *a1;
if ( *(_QWORD *)(*a1 + 8) )
result = lower_of_bigger(result + 8);
return result;
}

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

result = *a1;
if ( *(_QWORD *)(*a1 + 8) )
result = func7(result + 8);
return result;
}

original_code:
object* lower_of_bigger(node **n) {
 if ((*n)->left == ((void *)0))
  return (&((*n)->value));
  else
  return lower_of_bigger(&(*n)->left);
}

canonical_original_code:
int *lower_of_bigger(struct node **n) {
 if ((*n)->left == ((void *)0))
  return (&((*n)->value));
  else
  return lower_of_bigger(&(*n)->left);
}


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

result = *a1;
if ( *(_QWORD *)(*a1 + 16) )
result = bigger_of_lower(result + 16);
return result;
}

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

result = *a1;
if ( *(_QWORD *)(*a1 + 16) )
result = func8(result + 16);
return result;
}

original_code:
object* bigger_of_lower(node **n) {
 if ((*n)->right == ((void *)0))
  return (&((*n)->value));
  else
  return bigger_of_lower(&(*n)->right);
}

canonical_original_code:
int *bigger_of_lower(struct node **n) {
 if ((*n)->right == ((void *)0))
  return (&((*n)->value));
  else
  return bigger_of_lower(&(*n)->right);
}


original_code:
void rotation_left(node **n) {
 node *a = *n;
 node *b = (*n)->right;
 a->right = b->left;
 b->left = a;
 (*n) = b;
 (*n)->left->balance = ((*n)->left->balance*2 - (*n)->balance + modulo((*n)->balance) + 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->left->balance + modulo((*n)->left->balance) + 2)/2;
}

canonical_original_code:
void rotation_left(struct node **n) {
 struct node *a = *n;
 struct node *b = (*n)->right;
 a->right = b->left;
 b->left = a;
 (*n) = b;
 (*n)->left->balance = ((*n)->left->balance*2 - (*n)->balance + modulo((*n)->balance) + 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->left->balance + modulo((*n)->left->balance) + 2)/2;
}

variable_types: struct node { int value; char balance; char contanodo; struct node *left; struct node *right; } *

return_type: void


original_code:
void rotation_right(node **n) {
 node *a = *n;
 node *b = (*n)->left;
 a->left = b->right;
 b->right = a;
 (*n) = b;
 (*n)->right->balance = ((*n)->right->balance*2 - (*n)->balance - modulo((*n)->balance) - 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->right->balance - modulo((*n)->right->balance) - 2)/2;
}

canonical_original_code:
void rotation_right(struct node **n) {
 struct node *a = *n;
 struct node *b = (*n)->left;
 a->left = b->right;
 b->right = a;
 (*n) = b;
 (*n)->right->balance = ((*n)->right->balance*2 - (*n)->balance - modulo((*n)->balance) - 2)/2;
 (*n)->balance = ((*n)->balance*2 + (*n)->right->balance - modulo((*n)->right->balance) - 2)/2;
}


insereSemBal

original_code:
int insereSemBal(node **n, object *o) {
 node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insereSemBal(&(current->left), o) == 1){
   current->balance++;
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insereSemBal(&(current->right), o) == 1){
   current->balance--;
   return (current->balance < 0);
  }
 }
 return 0;
}

canonical_original_code:
int insereSemBal(struct node **n, int *o) {
 struct node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insereSemBal(&(current->left), o) == 1){
   current->balance++;
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insereSemBal(&(current->right), o) == 1){
   current->balance--;
   return (current->balance < 0);
  }
 }
 return 0;
}

variable_types:
o
int *


original_code:
int insert_node(node **n, object *o, int *num_rots) {
 node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insert_node(&(current->left), o, num_rots) == 1){
   current->balance++;
   if (current->balance == 2 ) {
    if ( (current->left)->balance == 1) {
     rotation_right(&current);
     *num_rots+=1;
    }
    else if ( (current->left)->balance == -1) {
                                        rotation_left(&(current->left));
                                        rotation_right(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insert_node(&(current->right), o, num_rots) == 1){
   current->balance--;
   if ( current->balance == -2 ) {
    if ( (current->right)->balance == -1) {
     rotation_left(&current);
     *num_rots+=1;
    }
    else if ( (current->right)->balance == 1) {
                                        rotation_right(&(current->right));
                                        rotation_left(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance < 0);
  }
 }
 return 0;
}

canonical_original_code:
int insert_node(struct node **n, int *o, int *num_rots) {
 struct node *current = *n;
 if( !current ) {
  if( !(current = create_node(&current)))
              return 0;
  current->value = *o;
  *n = current;
  return 1;
 } else if( objectcmp(o,&current->value) == -1 ) {
  if( insert_node(&(current->left), o, num_rots) == 1){
   current->balance++;
   if (current->balance == 2 ) {
    if ( (current->left)->balance == 1) {
     rotation_right(&current);
     *num_rots+=1;
    }
    else if ( (current->left)->balance == -1) {
                                        rotation_left(&(current->left));
                                        rotation_right(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance > 0);
  }
 } else if( objectcmp(o,&current->value) == 1 ) {
  if( insert_node(&(current->right), o, num_rots) == 1){
   current->balance--;
   if ( current->balance == -2 ) {
    if ( (current->right)->balance == -1) {
     rotation_left(&current);
     *num_rots+=1;
    }
    else if ( (current->right)->balance == 1) {
                                        rotation_right(&(current->right));
                                        rotation_left(&current);
     *num_rots+=2;
    }
    *n = current;
   }
   return (current->balance < 0);
  }
 }
 return 0;
}


removeSemBal

decompiled_code:
_BOOL8 __fastcall removeSemBal(_DWORD **a1, _DWORD *a2)
{
_QWORD *v2; // r12
int v3; // eax
_BOOL4 v4; // ebx
_DWORD *v5; // rax
_DWORD *v6; // rax
void *v8; // [rsp+8h] [rbp-30h] BYREF

v2 = *a1;
if ( !*a1 )
return 0;
v3 = objectcmp(a2, *a1);
v4 = v3;
if ( v3 == -1 )
{
v4 = 0;
if ( (unsigned int)removeSemBal(v2 + 1, a2) == 1 )
v4 = (char)--*((_BYTE *)*a1 + 4) >= 0;
}
else
{
if ( v3 != 1 )
{
if ( v3 )
return 0;
v5 = (_DWORD *)v2[1];
if ( v5 )
{
if ( v2[2] )
{
v6 = (_DWORD *)lower_of_bigger(v2 + 2);
*(_DWORD *)v2 = *v6;
if ( (unsigned int)removeSemBal(*a1 + 4, v6) == 1 )
v4 = ++*((_BYTE *)*a1 + 4) == 0;
return v4;
}
v8 = v2;
}
else
{
v8 = v2;
v5 = (_DWORD *)v2[2];
}
*a1 = v5;
destroy_node(&v8);
return 1;
}
v4 = 0;
if ( (unsigned int)removeSemBal(v2 + 2, a2) == 1 )
v4 = ++*((_BYTE *)*a1 + 4) <= 0;
}
return v4;
}

original_code:
int removeSemBal(node **n, object *o) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( removeSemBal(&((*n)->left), o) == 1){
   (*n)->balance -= 1;
   return ((*n)->balance >= 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( removeSemBal(&((*n)->right), o) == 1){
   (*n)->balance += 1;
   return ((*n)->balance <= 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   object* lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (removeSemBal(&((*n)->right), lower) == 1) {
   (*n)->balance += 1;
   return ((*n)->balance == 0);
   }
  }
  else {
   node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}

canonical_original_code:
int removeSemBal(struct node **n, int *o) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( removeSemBal(&((*n)->left), o) == 1){
   (*n)->balance -= 1;
   return ((*n)->balance >= 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( removeSemBal(&((*n)->right), o) == 1){
   (*n)->balance += 1;
   return ((*n)->balance <= 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   int *lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (removeSemBal(&((*n)->right), lower) == 1) {
   (*n)->balance += 1;
   return ((*n)->balance == 0);
   }
  }
  else {
   struct node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}

variable_types:
lower
int *


original_code:
int remove_node(node **n, object *o, int *num_rots) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( remove_node(&((*n)->left), o, num_rots) == 1){
   (*n)->balance -= 1;
   if ( (*n)->balance == -2 ) {
    if ( (*n)->right ){
     if ( ((*n)->right)->balance == 1) {
      rotation_right(&(*n)->right);
      rotation_left(n);
      *num_rots+=2;
     }
     else if ( ((*n)->right)->balance == 0) {
      rotation_left(n);
      *num_rots+=1;
     }
     else if ( ((*n)->right)->balance == -1) {
      rotation_left(n);
      *num_rots+=1;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( remove_node(&((*n)->right), o, num_rots) == 1){
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   object* lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (remove_node(&((*n)->right), lower, num_rots) == 1) {
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
   }
  }
  else {
   node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}

canonical_original_code:
int remove_node(struct node **n, int *o, int *num_rots) {
 if( ! *n )
  return 0;
 if( objectcmp(o,&((*n)->value)) == -1 ) {
  if( remove_node(&((*n)->left), o, num_rots) == 1){
   (*n)->balance -= 1;
   if ( (*n)->balance == -2 ) {
    if ( (*n)->right ){
     if ( ((*n)->right)->balance == 1) {
      rotation_right(&(*n)->right);
      rotation_left(n);
      *num_rots+=2;
     }
     else if ( ((*n)->right)->balance == 0) {
      rotation_left(n);
      *num_rots+=1;
     }
     else if ( ((*n)->right)->balance == -1) {
      rotation_left(n);
      *num_rots+=1;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
  else if( objectcmp(o,&((*n)->value)) == 1 ) {
  if( remove_node(&((*n)->right), o, num_rots) == 1){
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
  }
 }
 else if ( objectcmp(o, &((*n)->value)) == 0) {
  if ((*n)->left && (*n)->right) {
   int *lower = lower_of_bigger(&((*n)->right));
   (*n)->value = *lower;
   if (remove_node(&((*n)->right), lower, num_rots) == 1) {
   (*n)->balance += 1;
   if ( (*n)->balance == 2 ) {
    if ( (*n)->left ) {
     if ( ((*n)->left)->balance == 1 ) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == 0) {
      rotation_right(n);
      *num_rots+=1;
     }
     else if ( ((*n)->left)->balance == -1) {
      rotation_left(&(*n)->left);
      rotation_right(n);
      *num_rots+=2;
     }
    }
   }
   return ((*n)->balance == 0);
   }
  }
  else {
   struct node *m = *n;
   if ((*n)->left)
    *n = (*n)->left;
   else
    *n = (*n)->right;
   destroy_node(&m);
  return 1;
  }
}
 return 0;
}


decompiled_code:
__int64 __fastcall calcula_balanc(__int64 *a1)
{
__int64 v2; // rdi
int v3; // ebp
int v4; // eax

v2 = *a1;
if ( *(_QWORD *)(v2 + 8) )
{
v3 = calcula_balanc(v2 + 8);
v2 = *a1;
v4 = 0;
if ( !*(_QWORD *)(*a1 + 16) )
goto LABEL_4;
}
else
{
v3 = 0;
if ( !*(_QWORD *)(v2 + 16) )
{
*(_BYTE *)(v2 + 4) = 0;
v4 = 0;
return (unsigned int)(v4 + 1);
}
}
v4 = calcula_balanc(v2 + 16);
LABEL_4:
*(_BYTE *)(*a1 + 4) = v3 - v4;
if ( v4 < v3 )
return (unsigned int)(v3 + 1);
return (unsigned int)(v4 + 1);
}

original_code:
int calcula_balanc(node **n)
{
 int hesq=0, hdir=0;
 if ((*n)->left)
  hesq=calcula_balanc(&(*n)->left);
 if ((*n)->right)
  hdir=calcula_balanc(&(*n)->right);
 (*n)->balance=hesq-hdir;
 if (hesq>hdir)
  return hesq+1;
 else
  return hdir+1;
}

canonical_original_code:
int calcula_balanc(struct node **n)
{
 int hesq = 0; int hdir = 0;
 if ((*n)->left)
  hesq=calcula_balanc(&(*n)->left);
 if ((*n)->right)
  hdir=calcula_balanc(&(*n)->right);
 (*n)->balance=hesq-hdir;
 if (hesq>hdir)
  return hesq+1;
 else
  return hdir+1;
}

variable_types: hesq int

variable_types: hdir int


decompiled_code:
__int64 __fastcall calcula_contanodos(__int64 *a1)
{
__int64 v2; // rdi
char v3; // bp
char v4; // al

v2 = *a1;
v3 = 0;
if ( *(_QWORD *)(v2 + 8) )
v3 = calcula_contanodos(v2 + 8);
v4 = 0;
if ( *(_QWORD *)(*a1 + 16) )
v4 = calcula_contanodos(*a1 + 16);
*(_BYTE *)(*a1 + 5) = v3 + v4 + 1;
return (unsigned int)*(char *)(*a1 + 5);
}

original_code:
int calcula_contanodos(node **n)
{
 int pesq =0, pdir=0;
 if( (*n)->left )
  pesq = calcula_contanodos(&(*n)->left);
 if( (*n)->right )
  pdir = calcula_contanodos(&(*n)->right);
 (*n)->contanodo = pesq + pdir + 1;
 return (*n)->contanodo;
}

canonical_original_code:
int calcula_contanodos(struct node **n)
{
 int pesq = 0; int pdir = 0;
 if( (*n)->left )
  pesq = calcula_contanodos(&(*n)->left);
 if( (*n)->right )
  pdir = calcula_contanodos(&(*n)->right);
 (*n)->contanodo = pesq + pdir + 1;
 return (*n)->contanodo;
}

variable_types: pesq int

variable_types: pdir int


partPontoMed

original_code:
int partPontoMed(node **n, int *num_rots)
{
 calcula_contanodos(n);
 int metade=ceil((*n)->contanodo/2.0);
 particionar(n,metade, num_rots);
 if( (*n)->left )
  partPontoMed(&(*n)->left, num_rots);
 if( (*n)->right )
  partPontoMed(&(*n)->right, num_rots);
}

canonical_original_code:
int partPontoMed(struct node **n, int *num_rots)
{
 calcula_contanodos(n);
 int metade = ceil((*n)->contanodo/2.0);
 particionar(n,metade, num_rots);
 if( (*n)->left )
  partPontoMed(&(*n)->left, num_rots);
 if( (*n)->right )
  partPontoMed(&(*n)->right, num_rots);
}

variable_types: metade int


decompiled_code:
int __fastcall search_node(unsigned int **a1, _DWORD *a2)
{
unsigned int *v2; // rbx

v2 = *a1;
printf("%d", **a1);
do
{
if ( (unsigned int)objectcmp(a2, v2) == -1 )
v2 = (unsigned int *)*((_QWORD *)v2 + 1);
else
v2 = (unsigned int *)*((_QWORD *)v2 + 2);
printf(",%d", *v2);
}
while ( (unsigned int)objectcmp(a2, v2) );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func19(unsigned int **a1, _DWORD *a2)
{
unsigned int *v2; // rbx

v2 = *a1;
printf("%d", **a1);
do
{
if ( (unsigned int)func1(a2, v2) == -1 )
v2 = (unsigned int *)*((_QWORD *)v2 + 1);
else
v2 = (unsigned int *)*((_QWORD *)v2 + 2);
printf(",%d", *v2);
}
while ( (unsigned int)func1(a2, v2) );
return putchar(10);
}

original_code:
void search_node(node **n, object *o) {
 node *cptree = *n;
 printf("%d",cptree->value);
 do {
  if (objectcmp(o, &cptree->value) == -1 )
   cptree = cptree->left;
  else
   cptree = cptree->right;
  printf(",%d",cptree->value);
 } while ( objectcmp(o, &cptree->value) != 0 );
 printf("\n");
}

canonical_original_code:
void search_node(struct node **n, int *o) {
 struct node *cptree = *n;
 printf("%d",cptree->value);
 do {
  if (objectcmp(o, &cptree->value) == -1 )
   cptree = cptree->left;
  else
   cptree = cptree->right;
  printf(",%d",cptree->value);
 } while ( objectcmp(o, &cptree->value) != 0 );
 printf("\n");
}


buscaMenor

original_code:
int buscaMenor(tipoS dados, int aux)
{
 int i, indice = 0;
 int menor = dados.dist[0];
 for (i = 1; i < aux; i++)
  if (dados.dist[i] < menor)
  {
   menor = dados.dist[i];
   indice = i;
  }
 return indice;
}

canonical_original_code:
int buscaMenor(struct estrutura dados, int aux)
{
 int i; int indice = 0;
 int menor = dados.dist[0];
 for (i = 1; i < aux; i++)
  if (dados.dist[i] < menor)
  {
   menor = dados.dist[i];
   indice = i;
  }
 return indice;
}

variable_types: struct estrutura { int *cent; int *conta; int *soma; int *centaux; int *dist; }

variable_types: aux int

variable_types: i int

variable_types: indice int

variable_types: menor int


segmenta

original_code:
int segmenta(int *vetorIn, int *vetorOut, int linhas ,int colunas, int max, int aux)
{
 int tam = linhas * colunas;
 int i, j, indice;
 int mudou = 1;
 srand(time(((void *)0)));
 tipoS dados;
 dados.cent = (int *) malloc(sizeof(int) * aux);
 dados.conta = (int *) malloc(sizeof(int) * aux);
 dados.soma = (int *) malloc(sizeof(int) * aux);
 dados.centaux = (int *) malloc(sizeof(int) * aux);
 dados.dist = (int *) malloc(sizeof(int) * aux);
 if ((!dados.cent) || (!dados.conta) || (!dados.soma) || (!dados.centaux) || (!dados.dist))
  return 0;
 for (i = 0; i < aux; i++)
 {
  dados.cent[i] = rand () % max + 1;
  dados.centaux[i] = dados.cent[i];
 }
 while (mudou != 0)
 {
  mudou = 0;
  for (i = 0; i < aux; i++)
  {
   dados.conta[i] = 0;
   dados.soma[i] = 0;
  }
  for (i = 0; i < tam; i++)
  {
   for (j = 0; j < aux; j++)
   {
    dados.dist[j] = vetorIn[i] - dados.cent[j];
    if (dados.dist[j] < 0)
     dados.dist[j] = dados.dist[j] * -1;
   }
   indice = buscaMenor(dados, aux);
   vetorOut[i] = dados.cent[indice];
   dados.soma[indice] = dados.soma[indice] + vetorIn[i];
   dados.conta[indice]++;
  }
  for (i = 0; i < aux; i++)
  {
   if (dados.conta[i] != 0)
   {
    dados.cent[i] = dados.soma[i] / dados.conta[i];
   }
   if (dados.cent[i] != dados.centaux[i])
   {
    dados.centaux[i] = dados.cent[i];
    mudou = mudou + 1;
   }
  }
 }
 return 1;
}

canonical_original_code:
int segmenta(int *vetorIn, int *vetorOut, int linhas, int colunas, int max, int aux)
{
 int tam = linhas * colunas;
 int i; int j; int indice;
 int mudou = 1;
 srand(time(((void *)0)));
 struct estrutura dados;
 dados.cent = (int *) malloc(sizeof(int) * aux);
 dados.conta = (int *) malloc(sizeof(int) * aux);
 dados.soma = (int *) malloc(sizeof(int) * aux);
 dados.centaux = (int *) malloc(sizeof(int) * aux);
 dados.dist = (int *) malloc(sizeof(int) * aux);
 if ((!dados.cent) || (!dados.conta) || (!dados.soma) || (!dados.centaux) || (!dados.dist))
  return 0;
 for (i = 0; i < aux; i++)
 {
  dados.cent[i] = rand () % max + 1;
  dados.centaux[i] = dados.cent[i];
 }
 while (mudou != 0)
 {
  mudou = 0;
  for (i = 0; i < aux; i++)
  {
   dados.conta[i] = 0;
   dados.soma[i] = 0;
  }
  for (i = 0; i < tam; i++)
  {
   for (j = 0; j < aux; j++)
   {
    dados.dist[j] = vetorIn[i] - dados.cent[j];
    if (dados.dist[j] < 0)
     dados.dist[j] = dados.dist[j] * -1;
   }
   indice = buscaMenor(dados, aux);
   vetorOut[i] = dados.cent[indice];
   dados.soma[indice] = dados.soma[indice] + vetorIn[i];
   dados.conta[indice]++;
  }
  for (i = 0; i < aux; i++)
  {
   if (dados.conta[i] != 0)
   {
    dados.cent[i] = dados.soma[i] / dados.conta[i];
   }
   if (dados.cent[i] != dados.centaux[i])
   {
    dados.centaux[i] = dados.cent[i];
    mudou = mudou + 1;
   }
  }
 }
 return 1;
}

variable_types:
vetorIn
int *

variable_types:
vetorOut
int *

variable_types: linhas int

variable_types: colunas int

variable_types: max int

variable_types: tam int

variable_types: j int

variable_types: mudou int

user_defined_types: struct estrutura { int *cent; int *conta; int *soma; int *centaux; int *dist; }


repo: tospectre/mariokart

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

if ( a2 >= 0 )
{
v2 = 0LL;
do
{
my_putstr(*(_QWORD *)(a1 + 8 * v2));
result = my_putchar(10LL);
++v2;
}
while ( a2 >= (int)v2 );
}
return result;
}

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

if ( a2 >= 0 )
{
v2 = 0LL;
do
{
my_putstr(*(_QWORD *)(a1 + 8 * v2));
result = my_putchar(10LL);
++v2;
}
while ( a2 >= (int)v2 );
}
return result;
}

original_code:
void aff_map(char **map, int width)
{
  int x;
  x = 0;
  while(x <= width)
    {
      my_putstr(map[x]);
      my_putchar('\n');
      x++;
    }
}

variable_types:
map
char **

variable_types: width int

variable_types: x int


decompiled_code:
__int64 score_value()
{
my_putstr("Your Score = ");
my_put_nbr(15LL);
return my_putchar(10LL);
}

canonical_decompiled_code:
__int64 func1()
{
my_putstr("Your Score = ");
my_put_nbr(15LL);
return my_putchar(10LL);
}

original_code:
void score_value()
{
  int score;
  score = 15;
  my_putstr("Your Score = ");
  my_put_nbr(score);
  my_putchar('\n');
}

variable_types: score int


original_code:
void print_map(char **map, int width, int height)
{
  int x;
  int y;
  score_value();
  x = 0;
  while(x <= width)
    {
      y = 0;
      while(y <= height)
 {
   if (((y == 0) || (y == height)) || ((x == 0) || (x == width)))
     map[x][y] = '#';
   else
     map[x][y] = ' ';
   y++;
 }
      map[x][y] = '\0';
      x++;
    }
  map[x] = '\0';
  aff_map(map, width);
}

variable_types: height int

variable_types: y int


decompiled_code:
__int64 __fastcall set_map(int a1, int a2)
{
void *v2; // rax
__int64 v3; // r12
__int64 i; // rbx
void *v5; // rax

v2 = malloc(8LL * a1 + 1);
if ( !v2 )
{
my_putstr("[ERROR]: malloc failed\n");
exit(1);
}
v3 = (__int64)v2;
for ( i = 0LL; a1 >= (int)i; ++i )
{
v5 = malloc(a2 + 1LL);
*(_QWORD *)(v3 + 8 * i) = v5;
if ( !v5 )
{
my_putstr("[ERROR]: malloc failed\n");
exit(1);
}
}
return print_map(v3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
void *v2; // rax
__int64 v3; // r12
__int64 i; // rbx
void *v5; // rax

v2 = malloc(8LL * a1 + 1);
if ( !v2 )
{
my_putstr("[ERROR]: malloc failed\n");
exit(1);
}
v3 = (__int64)v2;
for ( i = 0LL; a1 >= (int)i; ++i )
{
v5 = malloc(a2 + 1LL);
*(_QWORD *)(v3 + 8 * i) = v5;
if ( !v5 )
{
my_putstr("[ERROR]: malloc failed\n");
exit(1);
}
}
return func2(v3, a1, a2);
}

original_code:
void set_map(int x, int y)
{
  char **map;
  int i;
  i = 0;
  if ((map = malloc(sizeof(char*) * x + 1)) == ((void *)0))
    {
      my_putstr("[ERROR]: malloc failed\n");
      exit(1);
    }
  while(i <= x)
    {
      if ((map[i] = malloc(sizeof(char) * y + 1)) == ((void *)0))
 {
   my_putstr("[ERROR]: malloc failed\n");
   exit(1);
 }
      i++;
    }
  print_map(map, x, y);
}

canonical_original_code:
void set_map(int x, int y)
{
  char **map;
  int i;
  i = 0;
  if ((map = malloc(sizeof(char *) * x + 1)) == ((void *)0))
    {
      my_putstr("[ERROR]: malloc failed\n");
      exit(1);
    }
  while(i <= x)
    {
      if ((map[i] = malloc(sizeof(char) * y + 1)) == ((void *)0))
 {
   my_putstr("[ERROR]: malloc failed\n");
   exit(1);
 }
      i++;
    }
  print_map(map, x, y);
}

variable_types: i int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
unsigned int v5; // ebp
__int64 v6; // rbx

if ( argc != 3 )
{
my_putstr("[USAGE] : ", argv, envp);
my_putstr(*argv, argv, v3);
my_putstr(": Enter HEIGHT and WIDTH !\n", argv, v4);
exit(1);
}
v5 = my_getnbr(argv[1]);
v6 = (unsigned int)my_getnbr(argv[2]);
check_param(v5, v6);
set_map(v5, (unsigned int)v6);
exit(0);
}

original_code:
int main(int argc, char **argv)
{
  int height;
  int width;
  if (argc != 3)
    {
      my_putstr("[USAGE] : ");
      my_putstr(argv[0]);
      my_putstr(":  Enter HEIGHT and WIDTH !\n");
      exit(1);
    }
  width = my_getnbr(argv[1]);
  height = my_getnbr(argv[2]);
  check_param(width, height);
  set_map(width, height);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void __fastcall check_param(int a1, int a2)
{
if ( a1 <= 0 || a2 <= 0 )
{
my_putstr("[ERROR] : You must put positive values.\n");
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2)
{
if ( a1 <= 0 || a2 <= 0 )
{
my_putstr("[ERROR] : You must put positive values.\n");
exit(1);
}
}

original_code:
void check_param(int width, int height)
{
  if ((width <= 0) || (height <= 0))
    {
      my_putstr("[ERROR] : You must put positive values.\n");
      exit(1);
    }
}


usage

repo: totomo/math

decompiled_code:
size_t usage()
{
fwrite("Usage: estpi ... NumberOfIteration\n", 1uLL, 0x23uLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
return fwrite("--help, -h: show the usage.\n", 1uLL, 0x1CuLL, stderr);
}

canonical_decompiled_code:
size_t func7()
{
fwrite("Usage: estpi ... NumberOfIteration\n", 1uLL, 0x23uLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
return fwrite("--help, -h: show the usage.\n", 1uLL, 0x1CuLL, stderr);
}

original_code:
void usage(){
 fprintf(stderr, "Usage: estpi ... NumberOfIteration\n");
 fprintf(stderr, "Options:\n");
 fprintf(stderr, "--help, -h: show the usage.\n");
}


isContainCircle

original_code:
char isContainCircle(coord p){
 p.x =(double) rand() / 2147483647;
 p.y =(double) rand() / 2147483647;
 if( pow(p.x, 2) + pow(p.y, 2) <= 1.0 ){
  return 1;
 }
 else {
  return 0;
 }
}

canonical_original_code:
char isContainCircle(struct coord p){
 p.x =(double) rand() / 2147483647;
 p.y =(double) rand() / 2147483647;
 if( pow(p.x, 2) + pow(p.y, 2) <= 1.0 ){
  return 1;
 }
 else {
  return 0;
 }
}

variable_types:
p
struct coord { double x; double y; }

return_type: char


extractFromArguments

decompiled_code:
void __fastcall extractFromArguments(__int64 a1)
{
const char *v1; // r8

v1 = *(const char **)(a1 + 8);
if ( v1 )
{
if ( !((strcmp(v1, "-h") != 0) * (strcmp(v1, "--help") != 0)) )
{
usage();
exit(1);
}
atoi(v1);
}
}

original_code:
long extractFromArguments(char **argv){
 int i=1;
 while( argv[i] != ((void *)0) ){
  if( strcmp(argv[i], "--help") * strcmp(argv[i], "-h") ==0 ){
   usage();
   exit(1);
  }
  else{
   return atoi(argv[i]);
  }
  i++;
 }
}

canonical_original_code:
long extractFromArguments(char **argv){
 int i = 1;
 while( argv[i] != ((void *)0) ){
  if( strcmp(argv[i], "--help") * strcmp(argv[i], "-h") ==0 ){
   usage();
   exit(1);
  }
  else{
   return atoi(argv[i]);
  }
  i++;
 }
}

return_type: long


verifyArguments

decompiled_code:
void __fastcall verifyArguments(int a1)
{
if ( (unsigned int)(a1 - 2) > 1 )
exit(1);
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
if ( (unsigned int)(a1 - 2) > 1 )
exit(1);
}

original_code:
void verifyArguments(int argc){
 if(argc!=2 && argc!=3){
  exit(1);
 }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rbx
int v6; // ebp

verifyArguments(argc);
extractFromArguments((__int64)argv);
v4 = v3;
if ( v3 <= 0 )
{
v6 = 0;
}
else
{
v5 = 0LL;
v6 = 0;
do
{
v6 += isContainCircle();
++v5;
}
while ( v5 != v4 );
}
fprintf(stdout, "result: %3.7f\n", (double)v6 / (double)(int)v4 * 4.0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rbx
int v6; // ebp

func10(argc);
func9((__int64)argv);
v4 = v3;
if ( v3 <= 0 )
{
v6 = 0;
}
else
{
v5 = 0LL;
v6 = 0;
do
{
v6 += func8();
++v5;
}
while ( v5 != v4 );
}
fprintf(stdout, "result: %3.7f\n", (double)v6 / (double)(int)v4 * 4.0);
return 0;
}

original_code:
int main(int argc, char **argv){
 coord p;
 long number;
 int i;
 int count = 0;
 verifyArguments(argc);
 number = extractFromArguments(argv);
 for( i=0; i<number; i++ ){
  count += isContainCircle(p);
 }
 fprintf(stdout, "result: %3.7f\n", (double)count / number * 4.0);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 struct coord p;
 long number;
 int i;
 int count = 0;
 verifyArguments(argc);
 number = extractFromArguments(argv);
 for( i=0; i<number; i++ ){
  count += isContainCircle(p);
 }
 fprintf(stdout, "result: %3.7f\n", (double)count / number * 4.0);
 return 0;
}

variable_types: number long

variable_types: count int


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

result = (unsigned int)(int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vsync_intr_base = result;
vsync_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vrtc_base = (int)((double)(int)result * 0.1066964285714286);
vrtc_timer = (int)((double)(int)result * 0.1066964285714286);
vrtc_base2 = (int)((double)(int)result * 0.8928571428571429);
rtc_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
rtc_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
state_of_vsync = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
state_of_cpu = 0;
if ( boost <= 0 )
boost = 1;
boost_cnt = 0;
return result;
}

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

result = (unsigned int)(int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vsync_intr_base = result;
vsync_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
vrtc_base = (int)((double)(int)result * 0.1066964285714286);
vrtc_timer = (int)((double)(int)result * 0.1066964285714286);
vrtc_base2 = (int)((double)(int)result * 0.8928571428571429);
rtc_intr_base = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
rtc_intr_timer = (int)(1000000.0 * *(double *)&cpu_clock_mhz / 600.0);
state_of_vsync = (int)(1000000.0 * *(double *)&cpu_clock_mhz / *(double *)&vsync_freq_hz);
state_of_cpu = 0;
if ( boost <= 0 )
boost = 1;
boost_cnt = 0;
return result;
}

original_code:
static void interval_work_init_generic( void )
{
  vsync_intr_timer = vsync_intr_base = (cpu_clock_mhz * 1000000) / vsync_freq_hz;
  vrtc_timer = vrtc_base = (vsync_intr_base * (( 47.8 ) /448.0));
                     vrtc_base2 = (vsync_intr_base * (( 400.0 ) /448.0));
  rtc_intr_timer = rtc_intr_base = (cpu_clock_mhz * 1000000) / (600);
  state_of_vsync = vsync_intr_base;
  state_of_cpu = 0;
  if( boost < 1 ) boost = 1;
  boost_cnt = 0;
}

canonical_original_code:
static void interval_work_init_generic()
{
  vsync_intr_timer = vsync_intr_base = (cpu_clock_mhz * 1000000) / vsync_freq_hz;
  vrtc_timer = vrtc_base = (vsync_intr_base * (( 47.8 ) /448.0));
                     vrtc_base2 = (vsync_intr_base * (( 400.0 ) /448.0));
  rtc_intr_timer = rtc_intr_base = (cpu_clock_mhz * 1000000) / (600);
  state_of_vsync = vsync_intr_base;
  state_of_cpu = 0;
  if( boost < 1 ) boost = 1;
  boost_cnt = 0;
}


decompiled_code:
__int64 check_sound_parm_update()
{
__int64 result; // rax
unsigned __int8 v1; // dl
char v2; // al

if ( sound_prescaler_update )
{
sd_A_intr_base = sd_A_intr_base * sound_prescaler_update / sound_prescaler;
sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update / sound_prescaler;
sd_B_intr_base = sd_B_intr_base * sound_prescaler_update / sound_prescaler;
sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update / sound_prescaler;
sound_prescaler = sound_prescaler_update;
sound_prescaler_update = 0;
}
result = (unsigned int)sound_flags_update;
switch ( sound_flags_update )
{
case 39:
v1 = sound_reg[39];
if ( !sound_LOAD_A && (v1 & 1) != 0 )
sd_A_intr_timer = sd_A_intr_base;
if ( !sound_LOAD_B && (v1 & 2) != 0 )
sd_B_intr_timer = sd_B_intr_base;
sound_LOAD_A = v1 & 1;
sound_LOAD_B = v1 & 2;
sound_ENABLE_A = ((int)v1 >> 2) & 1;
result = ((int)v1 >> 3) & 1;
sound_ENABLE_B = ((int)v1 >> 3) & 1;
if ( (v1 & 0x10) != 0 )
sound_FLAG_A = 0;
if ( (v1 & 0x20) != 0 )
sound_FLAG_B = 0;
break;
case 41:
if ( sound_board == 1 )
{
v2 = sound_reg[41];
sound2_EN_TA = v2 & 1;
sound2_EN_TB = v2 & 2;
sound2_EN_EOS = v2 & 4;
sound2_EN_BRDY = v2 & 8;
result = v2 & 0x10;
sound2_EN_ZERO = result;
}
break;
case 16:
result = sound2_reg[16];
if ( (result & 0x80u) != 0LL )
{
sound_FLAG_A = 0;
sound_FLAG_B = 0;
sound2_FLAG_EOS = 0;
sound2_FLAG_BRDY = 0;
sound2_FLAG_ZERO = 0;
}
else
{
sound2_MSK_TA = result & 1;
sound2_MSK_TB = result & 2;
sound2_MSK_EOS = result & 4;
sound2_MSK_BRDY = result & 8;
result &= 0x10u;
sound2_MSK_ZERO = result;
}
break;
}
sound_flags_update = 0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
unsigned __int8 v1; // dl
char v2; // al

if ( sound_prescaler_update )
{
sd_A_intr_base = sd_A_intr_base * sound_prescaler_update / sound_prescaler;
sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update / sound_prescaler;
sd_B_intr_base = sd_B_intr_base * sound_prescaler_update / sound_prescaler;
sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update / sound_prescaler;
sound_prescaler = sound_prescaler_update;
sound_prescaler_update = 0;
}
result = (unsigned int)sound_flags_update;
switch ( sound_flags_update )
{
case 39:
v1 = sound_reg[39];
if ( !sound_LOAD_A && (v1 & 1) != 0 )
sd_A_intr_timer = sd_A_intr_base;
if ( !sound_LOAD_B && (v1 & 2) != 0 )
sd_B_intr_timer = sd_B_intr_base;
sound_LOAD_A = v1 & 1;
sound_LOAD_B = v1 & 2;
sound_ENABLE_A = ((int)v1 >> 2) & 1;
result = ((int)v1 >> 3) & 1;
sound_ENABLE_B = ((int)v1 >> 3) & 1;
if ( (v1 & 0x10) != 0 )
sound_FLAG_A = 0;
if ( (v1 & 0x20) != 0 )
sound_FLAG_B = 0;
break;
case 41:
if ( sound_board == 1 )
{
v2 = sound_reg[41];
sound2_EN_TA = v2 & 1;
sound2_EN_TB = v2 & 2;
sound2_EN_EOS = v2 & 4;
sound2_EN_BRDY = v2 & 8;
result = v2 & 0x10;
sound2_EN_ZERO = result;
}
break;
case 16:
result = sound2_reg[16];
if ( (result & 0x80u) != 0LL )
{
sound_FLAG_A = 0;
sound_FLAG_B = 0;
sound2_FLAG_EOS = 0;
sound2_FLAG_BRDY = 0;
sound2_FLAG_ZERO = 0;
}
else
{
sound2_MSK_TA = result & 1;
sound2_MSK_TB = result & 2;
sound2_MSK_EOS = result & 4;
sound2_MSK_BRDY = result & 8;
result &= 0x10u;
sound2_MSK_ZERO = result;
}
break;
}
sound_flags_update = 0;
return result;
}

original_code:
static void check_sound_parm_update( void )
{
  byte data;
  if( sound_prescaler_update ){
    sd_A_intr_base = sd_A_intr_base * sound_prescaler_update/sound_prescaler;
    sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update/sound_prescaler;
    sd_B_intr_base = sd_B_intr_base * sound_prescaler_update/sound_prescaler;
    sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update/sound_prescaler;
    sound_prescaler = sound_prescaler_update;
    sound_prescaler_update = 0;
  }
  switch( sound_flags_update ){
  case 0x27:
    data = sound_reg[0x27];
    if( (sound_LOAD_A==0) && (data&0x01) ) sd_A_intr_timer = sd_A_intr_base;
    if( (sound_LOAD_B==0) && (data&0x02) ) sd_B_intr_timer = sd_B_intr_base;
    sound_LOAD_A = data & 0x01;
    sound_LOAD_B = data & 0x02;
    sound_ENABLE_A = ( data & 0x04 ) ? 1 : 0;
    sound_ENABLE_B = ( data & 0x08 ) ? 1 : 0;
    if( data & 0x10 ) sound_FLAG_A = 0;
    if( data & 0x20 ) sound_FLAG_B = 0;
    break;
  case 0x29:
    if( sound_board==SOUND_II ){
      data = sound_reg[0x29];
      sound2_EN_TA = data & 0x01;
      sound2_EN_TB = data & 0x02;
      sound2_EN_EOS = data & 0x04;
      sound2_EN_BRDY = data & 0x08;
      sound2_EN_ZERO = data & 0x10;
    }
    break;
  case 0x10:
    data = sound2_reg[0x10];
    if( data & 0x80 ){
      sound_FLAG_A = 0;
      sound_FLAG_B = 0;
      sound2_FLAG_EOS = 0;
      sound2_FLAG_BRDY = 0;
      sound2_FLAG_ZERO = 0;
    }else{
      sound2_MSK_TA = data & 0x01;
      sound2_MSK_TB = data & 0x02;
      sound2_MSK_EOS = data & 0x04;
      sound2_MSK_BRDY = data & 0x08;
      sound2_MSK_ZERO = data & 0x10;
    }
    break;
  }
  sound_flags_update = 0;
}

canonical_original_code:
static void check_sound_parm_update()
{
  unsigned char data;
  if( sound_prescaler_update ){
    sd_A_intr_base = sd_A_intr_base * sound_prescaler_update/sound_prescaler;
    sd_A_intr_timer = sd_A_intr_timer * sound_prescaler_update/sound_prescaler;
    sd_B_intr_base = sd_B_intr_base * sound_prescaler_update/sound_prescaler;
    sd_B_intr_timer = sd_B_intr_timer * sound_prescaler_update/sound_prescaler;
    sound_prescaler = sound_prescaler_update;
    sound_prescaler_update = 0;
  }
  switch( sound_flags_update ){
  case 0x27:
    data = sound_reg[0x27];
    if( (sound_LOAD_A==0) && (data&0x01) ) sd_A_intr_timer = sd_A_intr_base;
    if( (sound_LOAD_B==0) && (data&0x02) ) sd_B_intr_timer = sd_B_intr_base;
    sound_LOAD_A = data & 0x01;
    sound_LOAD_B = data & 0x02;
    sound_ENABLE_A = ( data & 0x04 ) ? 1 : 0;
    sound_ENABLE_B = ( data & 0x08 ) ? 1 : 0;
    if( data & 0x10 ) sound_FLAG_A = 0;
    if( data & 0x20 ) sound_FLAG_B = 0;
    break;
  case 0x29:
    if( sound_board==SOUND_II ){
      data = sound_reg[0x29];
      sound2_EN_TA = data & 0x01;
      sound2_EN_TB = data & 0x02;
      sound2_EN_EOS = data & 0x04;
      sound2_EN_BRDY = data & 0x08;
      sound2_EN_ZERO = data & 0x10;
    }
    break;
  case 0x10:
    data = sound2_reg[0x10];
    if( data & 0x80 ){
      sound_FLAG_A = 0;
      sound_FLAG_B = 0;
      sound2_FLAG_EOS = 0;
      sound2_FLAG_BRDY = 0;
      sound2_FLAG_ZERO = 0;
    }else{
      sound2_MSK_TA = data & 0x01;
      sound2_MSK_TB = data & 0x02;
      sound2_MSK_EOS = data & 0x04;
      sound2_MSK_BRDY = data & 0x08;
      sound2_MSK_ZERO = data & 0x10;
    }
    break;
  }
  sound_flags_update = 0;
}

variable_types:
data
unsigned char


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

result = (unsigned int)intr_level;
if ( intr_level )
{
if ( intr_level > 0 && RS232C_flag )
{
z80main_cpu[8] = 1;
}
else if ( intr_level > 1 && VSYNC_flag )
{
z80main_cpu[8] = 1;
}
else if ( intr_level > 2 && RTC_flag )
{
z80main_cpu[8] = 1;
}
else
{
z80main_cpu[8] = intr_level > 4 && SOUND_flag;
}
}
else
{
z80main_cpu[8] = 0;
}
return result;
}

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

result = (unsigned int)intr_level;
if ( intr_level )
{
if ( intr_level > 0 && RS232C_flag )
{
z80main_cpu[8] = 1;
}
else if ( intr_level > 1 && VSYNC_flag )
{
z80main_cpu[8] = 1;
}
else if ( intr_level > 2 && RTC_flag )
{
z80main_cpu[8] = 1;
}
else
{
z80main_cpu[8] = intr_level > 4 && SOUND_flag;
}
}
else
{
z80main_cpu[8] = 0;
}
return result;
}

original_code:
static __inline__ void set_INT_active( void )
{
  if( intr_level==0 ){
    z80main_cpu.INT_active = (0);
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    z80main_cpu.INT_active = (1);
  }
  else{
    z80main_cpu.INT_active = (0);
  }
}

canonical_original_code:
static __inline__ void set_INT_active()
{
  if( intr_level==0 ){
    z80main_cpu.INT_active = (0);
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    z80main_cpu.INT_active = (1);
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    z80main_cpu.INT_active = (1);
  }
  else{
    z80main_cpu.INT_active = (0);
  }
}


vsync

decompiled_code:
__int64 vsync()
{
int v0; // eax
__int64 result; // rax

v0 = boost_cnt + 1;
boost_cnt = v0;
if ( v0 < boost )
{
if ( v0 )
goto LABEL_7;
}
else
{
boost_cnt = 0;
}
xmame_sound_update();
if ( !no_wait )
wait_vsync();
xmame_update_video_and_audio();
event_handle();
scan_keyboard();
LABEL_7:
dma_wait_count = crtc_sz_lines * crtc_byte_per_line;
result = (unsigned int)state_of_vsync;
state_of_cpu -= state_of_vsync;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
__int64 result; // rax

v0 = boost_cnt + 1;
boost_cnt = v0;
if ( v0 < boost )
{
if ( v0 )
goto LABEL_7;
}
else
{
boost_cnt = 0;
}
xmame_sound_update();
if ( !no_wait )
wait_vsync();
xmame_update_video_and_audio();
event_handle();
scan_keyboard();
LABEL_7:
dma_wait_count = crtc_sz_lines * crtc_byte_per_line;
result = (unsigned int)state_of_vsync;
state_of_cpu -= state_of_vsync;
return result;
}

original_code:
static void vsync( void )
{
  if( ++ boost_cnt >= boost ){
    boost_cnt = 0;
  }
  if( boost_cnt == 0 ){
    xmame_sound_update();
    if( !no_wait ) wait_vsync();
    xmame_update_video_and_audio();
    event_handle();
    scan_keyboard();
  }
  dma_wait_count = crtc_byte_per_line * crtc_sz_lines;
  state_of_cpu -= state_of_vsync;
}

canonical_original_code:
static void vsync()
{
  if( ++ boost_cnt >= boost ){
    boost_cnt = 0;
  }
  if( boost_cnt == 0 ){
    xmame_sound_update();
    if( !no_wait ) wait_vsync();
    xmame_update_video_and_audio();
    event_handle();
    scan_keyboard();
  }
  dma_wait_count = crtc_byte_per_line * crtc_sz_lines;
  state_of_cpu -= state_of_vsync;
}


decompiled_code:
__int64 __fastcall interval_work_set_RS232C(int a1, int a2)
{
int v2; // eax
__int64 result; // rax

if ( a1 && a2 )
{
v2 = (int)(1000000.0 * *(double *)&cpu_clock_mhz / ((double)a1 / (double)a2));
if ( v2 < 100 )
v2 = 100;
rs232c_intr_base = v2;
}
else
{
rs232c_intr_base = 0x7FFFFFFF;
}
result = (unsigned int)rs232c_intr_base;
rs232c_intr_timer = rs232c_intr_base;
return result;
}

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

if ( a1 && a2 )
{
v2 = (int)(1000000.0 * *(double *)&cpu_clock_mhz / ((double)a1 / (double)a2));
if ( v2 < 100 )
v2 = 100;
rs232c_intr_base = v2;
}
else
{
rs232c_intr_base = 0x7FFFFFFF;
}
result = (unsigned int)rs232c_intr_base;
rs232c_intr_timer = rs232c_intr_base;
return result;
}

original_code:
void interval_work_set_RS232C( int bps, int framesize )
{
  if( bps == 0 || framesize == 0 ){
    rs232c_intr_base = 0x7fffffff;
  }else{
    rs232c_intr_base = (cpu_clock_mhz * 1000000) / ( (double)bps / (double)framesize );
    if( rs232c_intr_base < 100 ) rs232c_intr_base = 100;
  }
  rs232c_intr_timer = rs232c_intr_base;
}

canonical_original_code:
void interval_work_set_RS232C(int bps, int framesize)
{
  if( bps == 0 || framesize == 0 ){
    rs232c_intr_base = 0x7fffffff;
  }else{
    rs232c_intr_base = (cpu_clock_mhz * 1000000) / ( (double)bps / (double)framesize );
    if( rs232c_intr_base < 100 ) rs232c_intr_base = 100;
  }
  rs232c_intr_timer = rs232c_intr_base;
}

variable_types: bps int

variable_types: framesize int


decompiled_code:
__int64 interval_work_init_RS232C()
{
return interval_work_set_RS232C(0, 0);
}

canonical_decompiled_code:
__int64 func5()
{
return func4(0, 0);
}

original_code:
static void interval_work_init_RS232C( void )
{
  interval_work_set_RS232C( 0, 0 );
}

canonical_original_code:
static void interval_work_init_RS232C()
{
  interval_work_set_RS232C( 0, 0 );
}


decompiled_code:
__int64 __fastcall boost_change(int a1)
{
__int64 result; // rax
double v2; // xmm0_8
double v3; // xmm0_8

if ( a1 < 0 )
a1 = 1;
result = (unsigned int)boost;
if ( boost != a1 )
{
v2 = (double)a1 / (double)boost;
sd_A_intr_base = (int)((double)sd_A_intr_base * v2);
sd_A_intr_timer = (int)((double)sd_A_intr_timer * v2);
sd_B_intr_base = (int)((double)sd_B_intr_base * v2);
v3 = v2 * (double)sd_B_intr_timer;
result = (unsigned int)(int)v3;
sd_B_intr_timer = (int)v3;
boost = a1;
boost_cnt = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 result; // rax
double v2; // xmm0_8
double v3; // xmm0_8

if ( a1 < 0 )
a1 = 1;
result = (unsigned int)boost;
if ( boost != a1 )
{
v2 = (double)a1 / (double)boost;
sd_A_intr_base = (int)((double)sd_A_intr_base * v2);
sd_A_intr_timer = (int)((double)sd_A_intr_timer * v2);
sd_B_intr_base = (int)((double)sd_B_intr_base * v2);
v3 = v2 * (double)sd_B_intr_timer;
result = (unsigned int)(int)v3;
sd_B_intr_timer = (int)v3;
boost = a1;
boost_cnt = 0;
}
return result;
}

original_code:
void boost_change( int new_val )
{
  if( new_val < 0 ) new_val = 1;
  if( boost != new_val ){
    double rate = (double)new_val / boost;
    sd_A_intr_base *= rate;
    sd_A_intr_timer *= rate;
    sd_B_intr_base *= rate;
    sd_B_intr_timer *= rate;
    boost = new_val;
    boost_cnt = 0;
  }
}

canonical_original_code:
void boost_change(int new_val)
{
  if( new_val < 0 ) new_val = 1;
  if( boost != new_val ){
    double rate = (double)new_val / boost;
    sd_A_intr_base *= rate;
    sd_A_intr_timer *= rate;
    sd_B_intr_base *= rate;
    sd_B_intr_timer *= rate;
    boost = new_val;
    boost_cnt = 0;
  }
}

variable_types: rate double


decompiled_code:
__int64 interval_work_set_TIMER_A()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(12 * sound_prescaler * (1024 - sound_TIMER_A))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_A_intr_base = boost * (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(12 * sound_prescaler * (1024 - sound_TIMER_A))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_A_intr_base = boost * (int)v0;
return result;
}

original_code:
void interval_work_set_TIMER_A( void )
{
  sd_A_intr_base = (12) * sound_prescaler * (1024 - sound_TIMER_A)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_A_intr_base *= boost;
}

canonical_original_code:
void interval_work_set_TIMER_A()
{
  sd_A_intr_base = (12) * sound_prescaler * (1024 - sound_TIMER_A)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_A_intr_base *= boost;
}


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

interval_work_set_TIMER_A();
result = (unsigned int)sd_A_intr_base;
sd_A_intr_timer = sd_A_intr_base;
return result;
}

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

func7();
result = (unsigned int)sd_A_intr_base;
sd_A_intr_timer = sd_A_intr_base;
return result;
}

original_code:
static void interval_work_init_TIMER_A( void )
{
  interval_work_set_TIMER_A();
  sd_A_intr_timer = sd_A_intr_base;
}

canonical_original_code:
static void interval_work_init_TIMER_A()
{
  interval_work_set_TIMER_A();
  sd_A_intr_timer = sd_A_intr_base;
}


decompiled_code:
__int64 interval_work_set_TIMER_B()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(192 * sound_prescaler * (256 - sound_TIMER_B))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_B_intr_base = boost * (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(192 * sound_prescaler * (256 - sound_TIMER_B))
* (*(double *)&cpu_clock_mhz
/ *(double *)&sound_clock_mhz);
result = (unsigned int)(boost * (int)v0);
sd_B_intr_base = boost * (int)v0;
return result;
}

original_code:
void interval_work_set_TIMER_B( void )
{
  sd_B_intr_base = (192) * sound_prescaler * (256 - sound_TIMER_B)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_B_intr_base *= boost;
}

canonical_original_code:
void interval_work_set_TIMER_B()
{
  sd_B_intr_base = (192) * sound_prescaler * (256 - sound_TIMER_B)
     * ( cpu_clock_mhz / sound_clock_mhz );
  sd_B_intr_base *= boost;
}


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

interval_work_set_TIMER_B();
result = (unsigned int)sd_B_intr_base;
sd_B_intr_timer = sd_B_intr_base;
return result;
}

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

func9();
result = (unsigned int)sd_B_intr_base;
sd_B_intr_timer = sd_B_intr_base;
return result;
}

original_code:
static void interval_work_init_TIMER_B( void )
{
  interval_work_set_TIMER_B();
  sd_B_intr_timer = sd_B_intr_base;
}

canonical_original_code:
static void interval_work_init_TIMER_B()
{
  interval_work_set_TIMER_B();
  sd_B_intr_timer = sd_B_intr_base;
}


decompiled_code:
__int64 interval_work_init_all()
{
interval_work_init_generic();
interval_work_init_RS232C();
interval_work_init_TIMER_A();
return interval_work_init_TIMER_B();
}

canonical_decompiled_code:
__int64 func11()
{
func0();
func5();
func8();
return func10();
}

original_code:
void interval_work_init_all( void )
{
  interval_work_init_generic();
  interval_work_init_RS232C();
  interval_work_init_TIMER_A();
  interval_work_init_TIMER_B();
}

canonical_original_code:
void interval_work_init_all()
{
  interval_work_init_generic();
  interval_work_init_RS232C();
  interval_work_init_TIMER_A();
  interval_work_init_TIMER_B();
}


decompiled_code:
void __fastcall change_sound_flags(int a1)
{
sound_flags_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
}

canonical_decompiled_code:
void __fastcall func12(int a1)
{
sound_flags_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
}

original_code:
void change_sound_flags( int port )
{
  sound_flags_update = (int)port;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

canonical_original_code:
void change_sound_flags(int port)
{
  sound_flags_update = (int)port;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

variable_types: port int


decompiled_code:
void __fastcall change_sound_prescaler(int a1)
{
sound_prescaler_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
sound_prescaler_update = a1;
if ( !highspeed_flag )
z80_state_intchk = 0;
}

original_code:
void change_sound_prescaler( int new_prescaler )
{
  sound_prescaler_update = new_prescaler;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}

canonical_original_code:
void change_sound_prescaler(int new_prescaler)
{
  sound_prescaler_update = new_prescaler;
  if( highspeed_flag == (0) ) do{ z80_state_intchk = 0; }while(0);
}


decompiled_code:
__int64 interval_work_set_BDRY()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(2 * sound2_intr_base) * (0.25 * *(double *)&cpu_clock_mhz);
result = (unsigned int)(int)v0;
sd2_BRDY_intr_base = (int)v0;
sd2_BRDY_intr_timer = (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func14()
{
double v0; // xmm0_8
__int64 result; // rax

v0 = (double)(2 * sound2_intr_base) * (0.25 * *(double *)&cpu_clock_mhz);
result = (unsigned int)(int)v0;
sd2_BRDY_intr_base = (int)v0;
sd2_BRDY_intr_timer = (int)v0;
return result;
}

original_code:
void interval_work_set_BDRY( void )
{
  sd2_BRDY_intr_base = sound2_intr_base * 2 * ( cpu_clock_mhz / 4.0 );
  sd2_BRDY_intr_timer = sd2_BRDY_intr_base;
}

canonical_original_code:
void interval_work_set_BDRY()
{
  sd2_BRDY_intr_base = sound2_intr_base * 2 * ( cpu_clock_mhz / 4.0 );
  sd2_BRDY_intr_timer = sd2_BRDY_intr_base;
}


decompiled_code:
void __fastcall interval_work_set_EOS(int a1)
{
sd2_EOS_intr_base = sd2_BRDY_intr_base * a1;
sd2_EOS_intr_timer = sd2_BRDY_intr_base * a1;
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
sd2_EOS_intr_base = sd2_BRDY_intr_base * a1;
sd2_EOS_intr_timer = sd2_BRDY_intr_base * a1;
}

original_code:
void interval_work_set_EOS( int length )
{
  sd2_EOS_intr_base = sd2_BRDY_intr_base * length;
  sd2_EOS_intr_timer = sd2_EOS_intr_base;
}

canonical_original_code:
void interval_work_set_EOS(int length)
{
  sd2_EOS_intr_base = sd2_BRDY_intr_base * length;
  sd2_EOS_intr_timer = sd2_EOS_intr_base;
}

variable_types: length int


decompiled_code:
__int64 main_INT_update()
{
int v0; // ebp
int v1; // ebx
bool v2; // sf
int v3; // eax
int v4; // edx
int v5; // eax
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // ecx
int v10; // eax
int v11; // eax
int v12; // edx
__int64 result; // rax

v0 = SOUND_level;
v1 = rtc_intr_base;
v2 = rs232c_intr_timer - z80main_cpu[10] < 0;
v3 = rs232c_intr_timer - z80main_cpu[10];
rs232c_intr_timer = v3;
if ( v2 )
{
rs232c_intr_timer = rs232c_intr_base + v3;
if ( (unsigned int)sio_intr() )
{
if ( intr_sio_enable )
RS232C_flag = 1;
}
}
if ( rs232c_intr_timer <= v1 )
v1 = rs232c_intr_timer;
v4 = z80main_cpu[10];
state_of_cpu += v4;
v2 = vsync_intr_timer - v4 < 0;
v5 = vsync_intr_timer - v4;
vsync_intr_timer -= v4;
if ( v2 )
{
vsync_intr_timer = vsync_intr_base + v5;
vsync();
if ( intr_vsync_enable )
VSYNC_flag = 1;
ctrl_vrtc = 1;
vrtc_timer = z80main_cpu[10] + vrtc_base;
if ( vsync_intr_timer <= v1 )
v1 = vsync_intr_timer;
}
else
{
if ( v5 <= v1 )
v1 = v5;
if ( ctrl_vrtc != 1 )
{
if ( ctrl_vrtc != 2 )
goto LABEL_9;
vrtc_timer -= v4;
if ( vrtc_timer < 0 )
{
ctrl_vrtc = 3;
vrtc_timer = 0xFFFF;
goto LABEL_21;
}
goto LABEL_19;
}
}
v2 = vrtc_timer - z80main_cpu[10] < 0;
v6 = vrtc_timer - z80main_cpu[10];
vrtc_timer = v6;
if ( v2 )
{
ctrl_vrtc = 2;
vrtc_timer = vrtc_base2 + v6;
if ( !boost_cnt )
{
draw_screen();
LABEL_9:
if ( ctrl_vrtc > 2 )
goto LABEL_21;
goto LABEL_19;
}
}
LABEL_19:
if ( v1 > vrtc_timer )
v1 = vrtc_timer;
LABEL_21:
v7 = z80main_cpu[10];
v2 = rtc_intr_timer - v7 < 0;
v8 = rtc_intr_timer - v7;
rtc_intr_timer -= v7;
if ( v2 )
{
rtc_intr_timer = rtc_intr_base + v8;
if ( intr_rtc_enable )
RTC_flag = 1;
}
if ( rtc_intr_timer <= v1 )
v1 = rtc_intr_timer;
if ( sound_LOAD_A )
{
sd_A_intr_timer -= v7;
if ( sd_A_intr_timer < 0 )
{
xmame_sound_timer_over(0LL);
sd_A_intr_timer += sd_A_intr_base;
if ( sound_ENABLE_A )
sound_FLAG_A = sound2_MSK_TA == 0;
}
if ( v1 > sd_A_intr_timer )
v1 = sd_A_intr_timer;
}
if ( sound_LOAD_B )
{
sd_B_intr_timer -= z80main_cpu[10];
if ( sd_B_intr_timer < 0 )
{
xmame_sound_timer_over(1LL);
sd_B_intr_timer += sd_B_intr_base;
if ( sound_ENABLE_B )
sound_FLAG_B = sound2_MSK_TB == 0;
}
if ( v1 > sd_B_intr_timer )
v1 = sd_B_intr_timer;
}
if ( sound2_FLAG_PCMBSY )
{
v9 = z80main_cpu[10];
v2 = sd2_BRDY_intr_timer - v9 < 0;
v10 = sd2_BRDY_intr_timer - v9;
sd2_BRDY_intr_timer -= v9;
if ( v2 )
{
sd2_BRDY_intr_timer = sd2_BRDY_intr_base + v10;
sound2_FLAG_BRDY = sound2_MSK_BRDY == 0;
}
v11 = sd2_BRDY_intr_timer;
if ( sound2_notice_EOS )
{
v2 = sd2_EOS_intr_timer - v9 < 0;
v12 = sd2_EOS_intr_timer - v9;
sd2_EOS_intr_timer -= v9;
if ( v2 )
{
sd2_EOS_intr_timer = sd2_EOS_intr_base + v12;
sound2_FLAG_EOS = sound2_MSK_EOS == 0;
if ( !sound2_repeat )
sound2_FLAG_PCMBSY = 0;
sound2_notice_EOS = 0;
}
}
if ( sound2_notice_EOS <= sd2_BRDY_intr_timer )
v11 = sound2_notice_EOS;
if ( v1 > v11 )
v1 = v11;
}
check_sound_parm_update();
if ( (sound_FLAG_A && sound2_EN_TA
|| sound_FLAG_B && sound2_EN_TB
|| sound2_FLAG_BRDY && sound2_EN_BRDY
|| sound2_FLAG_EOS && sound2_EN_EOS)
&& intr_sound_enable )
{
SOUND_level = 1;
if ( !v0 )
SOUND_flag = 1;
}
else
{
SOUND_level = 0;
}
set_INT_active();
z80main_cpu[9] = v1;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
int v0; // ebp
int v1; // ebx
bool v2; // sf
int v3; // eax
int v4; // edx
int v5; // eax
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // ecx
int v10; // eax
int v11; // eax
int v12; // edx
__int64 result; // rax

v0 = SOUND_level;
v1 = rtc_intr_base;
v2 = rs232c_intr_timer - z80main_cpu[10] < 0;
v3 = rs232c_intr_timer - z80main_cpu[10];
rs232c_intr_timer = v3;
if ( v2 )
{
rs232c_intr_timer = rs232c_intr_base + v3;
if ( (unsigned int)sio_intr() )
{
if ( intr_sio_enable )
RS232C_flag = 1;
}
}
if ( rs232c_intr_timer <= v1 )
v1 = rs232c_intr_timer;
v4 = z80main_cpu[10];
state_of_cpu += v4;
v2 = vsync_intr_timer - v4 < 0;
v5 = vsync_intr_timer - v4;
vsync_intr_timer -= v4;
if ( v2 )
{
vsync_intr_timer = vsync_intr_base + v5;
func3();
if ( intr_vsync_enable )
VSYNC_flag = 1;
ctrl_vrtc = 1;
vrtc_timer = z80main_cpu[10] + vrtc_base;
if ( vsync_intr_timer <= v1 )
v1 = vsync_intr_timer;
}
else
{
if ( v5 <= v1 )
v1 = v5;
if ( ctrl_vrtc != 1 )
{
if ( ctrl_vrtc != 2 )
goto LABEL_9;
vrtc_timer -= v4;
if ( vrtc_timer < 0 )
{
ctrl_vrtc = 3;
vrtc_timer = 0xFFFF;
goto LABEL_21;
}
goto LABEL_19;
}
}
v2 = vrtc_timer - z80main_cpu[10] < 0;
v6 = vrtc_timer - z80main_cpu[10];
vrtc_timer = v6;
if ( v2 )
{
ctrl_vrtc = 2;
vrtc_timer = vrtc_base2 + v6;
if ( !boost_cnt )
{
draw_screen();
LABEL_9:
if ( ctrl_vrtc > 2 )
goto LABEL_21;
goto LABEL_19;
}
}
LABEL_19:
if ( v1 > vrtc_timer )
v1 = vrtc_timer;
LABEL_21:
v7 = z80main_cpu[10];
v2 = rtc_intr_timer - v7 < 0;
v8 = rtc_intr_timer - v7;
rtc_intr_timer -= v7;
if ( v2 )
{
rtc_intr_timer = rtc_intr_base + v8;
if ( intr_rtc_enable )
RTC_flag = 1;
}
if ( rtc_intr_timer <= v1 )
v1 = rtc_intr_timer;
if ( sound_LOAD_A )
{
sd_A_intr_timer -= v7;
if ( sd_A_intr_timer < 0 )
{
xmame_sound_timer_over(0LL);
sd_A_intr_timer += sd_A_intr_base;
if ( sound_ENABLE_A )
sound_FLAG_A = sound2_MSK_TA == 0;
}
if ( v1 > sd_A_intr_timer )
v1 = sd_A_intr_timer;
}
if ( sound_LOAD_B )
{
sd_B_intr_timer -= z80main_cpu[10];
if ( sd_B_intr_timer < 0 )
{
xmame_sound_timer_over(1LL);
sd_B_intr_timer += sd_B_intr_base;
if ( sound_ENABLE_B )
sound_FLAG_B = sound2_MSK_TB == 0;
}
if ( v1 > sd_B_intr_timer )
v1 = sd_B_intr_timer;
}
if ( sound2_FLAG_PCMBSY )
{
v9 = z80main_cpu[10];
v2 = sd2_BRDY_intr_timer - v9 < 0;
v10 = sd2_BRDY_intr_timer - v9;
sd2_BRDY_intr_timer -= v9;
if ( v2 )
{
sd2_BRDY_intr_timer = sd2_BRDY_intr_base + v10;
sound2_FLAG_BRDY = sound2_MSK_BRDY == 0;
}
v11 = sd2_BRDY_intr_timer;
if ( sound2_notice_EOS )
{
v2 = sd2_EOS_intr_timer - v9 < 0;
v12 = sd2_EOS_intr_timer - v9;
sd2_EOS_intr_timer -= v9;
if ( v2 )
{
sd2_EOS_intr_timer = sd2_EOS_intr_base + v12;
sound2_FLAG_EOS = sound2_MSK_EOS == 0;
if ( !sound2_repeat )
sound2_FLAG_PCMBSY = 0;
sound2_notice_EOS = 0;
}
}
if ( sound2_notice_EOS <= sd2_BRDY_intr_timer )
v11 = sound2_notice_EOS;
if ( v1 > v11 )
v1 = v11;
}
func1();
if ( (sound_FLAG_A && sound2_EN_TA
|| sound_FLAG_B && sound2_EN_TB
|| sound2_FLAG_BRDY && sound2_EN_BRDY
|| sound2_FLAG_EOS && sound2_EN_EOS)
&& intr_sound_enable )
{
SOUND_level = 1;
if ( !v0 )
SOUND_flag = 1;
}
else
{
SOUND_level = 0;
}
func2();
z80main_cpu[9] = v1;
result = next_emu_mode();
if ( (_DWORD)result )
{
z80_state_intchk = 0;
z80_state_goal = 1;
}
return result;
}

original_code:
void main_INT_update( void )
{
  int SOUND_level_old = SOUND_level;
  int icount = rtc_intr_base;
  rs232c_intr_timer -= z80main_cpu.state0;
  if( rs232c_intr_timer < 0 ){
    rs232c_intr_timer += rs232c_intr_base;
    if( sio_intr() ){
      if( intr_sio_enable )
 RS232C_flag = (1);
    }
  }
  icount = (((icount)<(rs232c_intr_timer))?(icount):(rs232c_intr_timer));
  state_of_cpu += z80main_cpu.state0;
  vsync_intr_timer -= z80main_cpu.state0;
  if( vsync_intr_timer < 0 ){
    vsync_intr_timer += vsync_intr_base;
    vsync();
    if( intr_vsync_enable )
      VSYNC_flag = (1);
    ctrl_vrtc = 1;
    vrtc_timer = vrtc_base + z80main_cpu.state0;
  }
  icount = (((icount)<(vsync_intr_timer))?(icount):(vsync_intr_timer));
  if( ctrl_vrtc == 1 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 2;
      vrtc_timer += vrtc_base2;
      if( boost_cnt == 0 ){
 draw_screen();
      }
    }
  }else if( ctrl_vrtc == 2 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 3;
      vrtc_timer = 0xffff;
    }
  }
  if( ctrl_vrtc < 3 ) icount = (((icount)<(vrtc_timer))?(icount):(vrtc_timer));
  rtc_intr_timer -= z80main_cpu.state0;
  if( rtc_intr_timer < 0 ){
    rtc_intr_timer += rtc_intr_base;
    if( intr_rtc_enable )
      RTC_flag = (1);
  }
  icount = (((icount)<(rtc_intr_timer))?(icount):(rtc_intr_timer));
  if( sound_LOAD_A ){
    sd_A_intr_timer -= z80main_cpu.state0;
    if( sd_A_intr_timer < 0 ){
      xmame_sound_timer_over(0);
      sd_A_intr_timer += sd_A_intr_base;
      if( sound_ENABLE_A ){
 if( sound2_MSK_TA ) sound_FLAG_A = 0;
 else sound_FLAG_A = 1;
      }
    }
    icount = (((icount)<(sd_A_intr_timer))?(icount):(sd_A_intr_timer));
  }
  if( sound_LOAD_B ){
    sd_B_intr_timer -= z80main_cpu.state0;
    if( sd_B_intr_timer < 0 ){
      xmame_sound_timer_over(1);
      sd_B_intr_timer += sd_B_intr_base;
      if( sound_ENABLE_B ){
 if( sound2_MSK_TB ) sound_FLAG_B = 0;
 else sound_FLAG_B = 1;
      }
    }
    icount = (((icount)<(sd_B_intr_timer))?(icount):(sd_B_intr_timer));
  }
  if( sound2_FLAG_PCMBSY ){
    sd2_BRDY_intr_timer -= z80main_cpu.state0;
    if( sd2_BRDY_intr_timer < 0 ){
      sd2_BRDY_intr_timer += sd2_BRDY_intr_base;
      {
 if( sound2_MSK_BRDY ) sound2_FLAG_BRDY = 0;
 else sound2_FLAG_BRDY = 1;
      }
    }
    icount = (((icount)<(sd2_BRDY_intr_timer))?(icount):(sd2_BRDY_intr_timer));
    if( sound2_notice_EOS ){
      sd2_EOS_intr_timer -= z80main_cpu.state0;
      if( sd2_EOS_intr_timer < 0 ){
 sd2_EOS_intr_timer += sd2_EOS_intr_base;
 if( sound2_MSK_EOS ) sound2_FLAG_EOS = 0;
 else sound2_FLAG_EOS = 1;
 if( !sound2_repeat ) sound2_FLAG_PCMBSY = 0;
 sound2_notice_EOS = (0);
      }
    }
    icount = (((icount)<(sound2_notice_EOS))?(icount):(sound2_notice_EOS));
  }
  check_sound_parm_update();
  if( ( ( sound_FLAG_A && sound2_EN_TA ) ||
 ( sound_FLAG_B && sound2_EN_TB ) ||
 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
 ( sound2_FLAG_EOS && sound2_EN_EOS ) ) && intr_sound_enable ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  if( (SOUND_level_old == (0)) && SOUND_level ){
    SOUND_flag = (1);
  }
  set_INT_active();
  z80main_cpu.icount = icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

canonical_original_code:
void main_INT_update()
{
  int SOUND_level_old = SOUND_level;
  int icount = rtc_intr_base;
  rs232c_intr_timer -= z80main_cpu.state0;
  if( rs232c_intr_timer < 0 ){
    rs232c_intr_timer += rs232c_intr_base;
    if( sio_intr() ){
      if( intr_sio_enable )
 RS232C_flag = (1);
    }
  }
  icount = (((icount)<(rs232c_intr_timer))?(icount):(rs232c_intr_timer));
  state_of_cpu += z80main_cpu.state0;
  vsync_intr_timer -= z80main_cpu.state0;
  if( vsync_intr_timer < 0 ){
    vsync_intr_timer += vsync_intr_base;
    vsync();
    if( intr_vsync_enable )
      VSYNC_flag = (1);
    ctrl_vrtc = 1;
    vrtc_timer = vrtc_base + z80main_cpu.state0;
  }
  icount = (((icount)<(vsync_intr_timer))?(icount):(vsync_intr_timer));
  if( ctrl_vrtc == 1 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 2;
      vrtc_timer += vrtc_base2;
      if( boost_cnt == 0 ){
 draw_screen();
      }
    }
  }else if( ctrl_vrtc == 2 ){
    vrtc_timer -= z80main_cpu.state0;
    if( vrtc_timer < 0 ){
      ctrl_vrtc = 3;
      vrtc_timer = 0xffff;
    }
  }
  if( ctrl_vrtc < 3 ) icount = (((icount)<(vrtc_timer))?(icount):(vrtc_timer));
  rtc_intr_timer -= z80main_cpu.state0;
  if( rtc_intr_timer < 0 ){
    rtc_intr_timer += rtc_intr_base;
    if( intr_rtc_enable )
      RTC_flag = (1);
  }
  icount = (((icount)<(rtc_intr_timer))?(icount):(rtc_intr_timer));
  if( sound_LOAD_A ){
    sd_A_intr_timer -= z80main_cpu.state0;
    if( sd_A_intr_timer < 0 ){
      xmame_sound_timer_over(0);
      sd_A_intr_timer += sd_A_intr_base;
      if( sound_ENABLE_A ){
 if( sound2_MSK_TA ) sound_FLAG_A = 0;
 else sound_FLAG_A = 1;
      }
    }
    icount = (((icount)<(sd_A_intr_timer))?(icount):(sd_A_intr_timer));
  }
  if( sound_LOAD_B ){
    sd_B_intr_timer -= z80main_cpu.state0;
    if( sd_B_intr_timer < 0 ){
      xmame_sound_timer_over(1);
      sd_B_intr_timer += sd_B_intr_base;
      if( sound_ENABLE_B ){
 if( sound2_MSK_TB ) sound_FLAG_B = 0;
 else sound_FLAG_B = 1;
      }
    }
    icount = (((icount)<(sd_B_intr_timer))?(icount):(sd_B_intr_timer));
  }
  if( sound2_FLAG_PCMBSY ){
    sd2_BRDY_intr_timer -= z80main_cpu.state0;
    if( sd2_BRDY_intr_timer < 0 ){
      sd2_BRDY_intr_timer += sd2_BRDY_intr_base;
      {
 if( sound2_MSK_BRDY ) sound2_FLAG_BRDY = 0;
 else sound2_FLAG_BRDY = 1;
      }
    }
    icount = (((icount)<(sd2_BRDY_intr_timer))?(icount):(sd2_BRDY_intr_timer));
    if( sound2_notice_EOS ){
      sd2_EOS_intr_timer -= z80main_cpu.state0;
      if( sd2_EOS_intr_timer < 0 ){
 sd2_EOS_intr_timer += sd2_EOS_intr_base;
 if( sound2_MSK_EOS ) sound2_FLAG_EOS = 0;
 else sound2_FLAG_EOS = 1;
 if( !sound2_repeat ) sound2_FLAG_PCMBSY = 0;
 sound2_notice_EOS = (0);
      }
    }
    icount = (((icount)<(sound2_notice_EOS))?(icount):(sound2_notice_EOS));
  }
  check_sound_parm_update();
  if( ( ( sound_FLAG_A && sound2_EN_TA ) ||
 ( sound_FLAG_B && sound2_EN_TB ) ||
 ( sound2_FLAG_BRDY && sound2_EN_BRDY ) ||
 ( sound2_FLAG_EOS && sound2_EN_EOS ) ) && intr_sound_enable ){
    SOUND_level = (1);
  }else{
    SOUND_level = (0);
  }
  if( (SOUND_level_old == (0)) && SOUND_level ){
    SOUND_flag = (1);
  }
  set_INT_active();
  z80main_cpu.icount = icount;
  if( next_emu_mode() != EXEC ) do{ z80_state_intchk = 0; z80_state_goal = 1; }while(0);
}

variable_types: icount int


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

RS232C_flag = 0;
VSYNC_flag = 0;
RTC_flag = 0;
SOUND_flag = 0;
SOUND_level = 0;
SOUND_edge = 0;
result = interval_work_init_all();
ctrl_vrtc = 1;
return result;
}

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

RS232C_flag = 0;
VSYNC_flag = 0;
RTC_flag = 0;
SOUND_flag = 0;
SOUND_level = 0;
SOUND_edge = 0;
result = func11();
ctrl_vrtc = 1;
return result;
}

original_code:
void main_INT_init( void )
{
  RS232C_flag = (0);
  VSYNC_flag = (0);
  RTC_flag = (0);
  SOUND_flag = (0);
  SOUND_level = (0);
  SOUND_edge = (0);
  interval_work_init_all();
  ctrl_vrtc = 1;
}

canonical_original_code:
void main_INT_init()
{
  RS232C_flag = (0);
  VSYNC_flag = (0);
  RTC_flag = (0);
  SOUND_flag = (0);
  SOUND_level = (0);
  SOUND_edge = (0);
  interval_work_init_all();
  ctrl_vrtc = 1;
}


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

if ( intr_level )
{
if ( intr_level > 0 && RS232C_flag )
{
RS232C_flag = 0;
set_INT_active();
result = 0LL;
goto LABEL_11;
}
if ( intr_level > 1 && VSYNC_flag )
{
VSYNC_flag = 0;
set_INT_active();
result = 1LL;
goto LABEL_11;
}
if ( intr_level > 2 && RTC_flag )
{
RTC_flag = 0;
set_INT_active();
result = 2LL;
goto LABEL_11;
}
if ( intr_level > 4 && SOUND_flag )
{
SOUND_flag = 0;
set_INT_active();
result = 4LL;
LABEL_11:
intr_level = 0;
return result;
}
}
set_INT_active();
return 0xFFFFFFFFLL;
}

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

if ( intr_level )
{
if ( intr_level > 0 && RS232C_flag )
{
RS232C_flag = 0;
func2();
result = 0LL;
goto LABEL_11;
}
if ( intr_level > 1 && VSYNC_flag )
{
VSYNC_flag = 0;
func2();
result = 1LL;
goto LABEL_11;
}
if ( intr_level > 2 && RTC_flag )
{
RTC_flag = 0;
func2();
result = 2LL;
goto LABEL_11;
}
if ( intr_level > 4 && SOUND_flag )
{
SOUND_flag = 0;
func2();
result = 4LL;
LABEL_11:
intr_level = 0;
return result;
}
}
func2();
return 0xFFFFFFFFLL;
}

original_code:
int main_INT_chk( void )
{
  int intr_no = -1;
  if( intr_level==0 ){
    {
      intr_no = -1;
    }
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    RS232C_flag = (0);
    intr_no = 0;
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    VSYNC_flag = (0);
    intr_no = 1;
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    RTC_flag = (0);
    intr_no = 2;
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    SOUND_flag = (0);
    intr_no = 4;
  }
  set_INT_active();
  if( intr_no >= 0 ){
    intr_level = 0;
    return intr_no;
  }else{
    return -1;
  }
}

canonical_original_code:
int main_INT_chk()
{
  int intr_no = -1;
  if( intr_level==0 ){
    {
      intr_no = -1;
    }
  }
  else if( intr_level>=1 &&
                         RS232C_flag ){
    RS232C_flag = (0);
    intr_no = 0;
  }
  else if( intr_level>=2 &&
                           VSYNC_flag ){
    VSYNC_flag = (0);
    intr_no = 1;
  }
  else if( intr_level>=3 &&
                         RTC_flag ){
    RTC_flag = (0);
    intr_no = 2;
  }
  else if( intr_level>=5 &&
                           SOUND_flag ){
    SOUND_flag = (0);
    intr_no = 4;
  }
  set_INT_active();
  if( intr_no >= 0 ){
    intr_level = 0;
    return intr_no;
  }else{
    return -1;
  }
}


decompiled_code:
_BOOL8 statesave_intr()
{
_BOOL4 v0; // ebx

v0 = 0;
if ( !(unsigned int)statesave_table("INTR", &suspend_intr_work) )
{
v0 = 0;
if ( !(unsigned int)statesave_table("INT2", &suspend_intr_work2) )
{
v0 = 0;
if ( !(unsigned int)statesave_table("INT3", &suspend_intr_work3) )
v0 = statesave_table("INT4", &suspend_intr_work4) == 0;
}
}
return v0;
}

canonical_decompiled_code:
_BOOL8 func19()
{
_BOOL4 v0; // ebx

v0 = 0;
if ( !(unsigned int)statesave_table("INTR", &suspend_intr_work) )
{
v0 = 0;
if ( !(unsigned int)statesave_table("INT2", &suspend_intr_work2) )
{
v0 = 0;
if ( !(unsigned int)statesave_table("INT3", &suspend_intr_work3) )
v0 = statesave_table("INT4", &suspend_intr_work4) == 0;
}
}
return v0;
}

original_code:
int statesave_intr( void )
{
  if( statesave_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( statesave_table( "INT2", suspend_intr_work2 ) != (0) ) return (0);
  if( statesave_table( "INT3", suspend_intr_work3 ) != (0) ) return (0);
  if( statesave_table( "INT4", suspend_intr_work4 ) != (0) ) return (0);
  return (1);
}

canonical_original_code:
int statesave_intr()
{
  if( statesave_table( "INTR", suspend_intr_work ) != (0) ) return (0);
  if( statesave_table( "INT2", suspend_intr_work2 ) != (0) ) return (0);
  if( statesave_table( "INT3", suspend_intr_work3 ) != (0) ) return (0);
  if( statesave_table( "INT4", suspend_intr_work4 ) != (0) ) return (0);
  return (1);
}