decompiled_code:
__int64 __fastcall netdev_listener(unsigned int a1)
{
int v1; // eax
int v2; // er12
socklen_t v3; // edx
int v4; // ebp
unsigned __int16 v5; // ax
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v9; // [rsp+20h] [rbp-38h] BYREF
char buf[40]; // [rsp+30h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("netdev_listener: failed to create socket");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
*(_QWORD *)&v9.sa_data[6] = 0LL;
v9.sa_family = 2;
*(_QWORD *)&v9.sa_data[2] = (unsigned int)_bswap_32_constprop_0((unsigned __int16)a1, &v9, 16LL);
*(_WORD *)v9.sa_data = _bswap_16(a1);
if ( bind(v2, &v9, v3) < 0 )
{
perror("netdev_listener: failed to bind to address");
result = 0xFFFFFFFFLL;
}
else
{
if ( listen(v2, 1024) >= 0 )
{
addr_len = 16;
printf("netdev_listener: starting listener at port: %d\n", a1);
while ( 1 )
{
v4 = accept(v2, &addr, &addr_len);
if ( v4 >= 0 )
goto LABEL_6;
if ( *_errno_location() != 4 )
{
perror("netdev_listener: accept error");
LABEL_6:
if ( inet_ntop(addr.sa_family, &addr.sa_data[2], buf, 0x10u) )
{
v5 = _bswap_16(*(__int16 *)addr.sa_data);
printf("netdev_listener: new connection from %s:%d\n", buf, v5);
}
if ( !fork() )
{
close(v2);
proxy_server((unsigned int)v4);
exit(0);
}
close(v4);
}
}
}
perror("netdev_listener: failed to listen");
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
int v1; // eax
int v2; // er12
socklen_t v3; // edx
int v4; // ebp
unsigned __int16 v5; // ax
__int64 result; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-48h] BYREF
struct sockaddr v9; // [rsp+20h] [rbp-38h] BYREF
char buf[40]; // [rsp+30h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("netdev_listener: failed to create socket");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
*(_QWORD *)&v9.sa_data[6] = 0LL;
v9.sa_family = 2;
*(_QWORD *)&v9.sa_data[2] = (unsigned int)func2((unsigned __int16)a1, &v9, 16LL);
*(_WORD *)v9.sa_data = func1(a1);
if ( bind(v2, &v9, v3) < 0 )
{
perror("netdev_listener: failed to bind to address");
result = 0xFFFFFFFFLL;
}
else
{
if ( listen(v2, 1024) >= 0 )
{
addr_len = 16;
printf("netdev_listener: starting listener at port: %d\n", a1);
while ( 1 )
{
v4 = accept(v2, &addr, &addr_len);
if ( v4 >= 0 )
goto LABEL_6;
if ( *_errno_location() != 4 )
{
perror("netdev_listener: accept error");
LABEL_6:
if ( inet_ntop(addr.sa_family, &addr.sa_data[2], buf, 0x10u) )
{
v5 = func1(*(__int16 *)addr.sa_data);
printf("netdev_listener: new connection from %s:%d\n", buf, v5);
}
if ( !fork() )
{
close(v2);
proxy_server((unsigned int)v4);
exit(0);
}
close(v4);
}
}
}
perror("netdev_listener: failed to listen");
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int netdev_listener(
    int port)
{
    int listenfd, connfd;
    int rvalue;
    pid_t childpid;
    socklen_t clilen;
    struct sockaddr_in cliaddr, servaddr;
    char str[16];
    void *ptr;
    listenfd = socket(2, SOCK_STREAM, 0);
    if ( listenfd < 0 ) {
        perror("netdev_listener: failed to create socket");
        return -1;
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    servaddr.sin_port = htons(port);
    rvalue = bind(listenfd,
                (struct sockaddr*)&servaddr,
                sizeof(servaddr));
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to bind to address");
        return -1;
    }
    rvalue = listen(listenfd, 1024);
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to listen");
        return -1;
    }
    clilen = sizeof(cliaddr);
    printf("netdev_listener: starting listener at port: %d\n", port);
    while (1) {
        connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen);
        if (connfd < 0) {
            if ((*__errno_location ()) == 4) {
                continue;
            } else {
                perror("netdev_listener: accept error");
            }
        }
        ptr = (char *)inet_ntop(cliaddr.sin_family ,
                                &cliaddr.sin_addr,
                                str,
                                sizeof(str));
        if ( ptr != ((void *)0) ) {
            printf("netdev_listener: new connection from %s:%d\n",
                    str,
                    ntohs(cliaddr.sin_port));
        }
        if ( (childpid = fork()) ==0 ) {
            close(listenfd);
            proxy_server(connfd);
            exit(0);
        }
        close(connfd);
    }
    return 0;
}

canonical_original_code:
int netdev_listener(int port)
{
    int listenfd; int connfd;
    int rvalue;
    int childpid;
    unsigned int clilen;
    struct sockaddr_in cliaddr; struct sockaddr_in servaddr;
    char str[16];
    void *ptr;
    listenfd = socket(2, SOCK_STREAM, 0);
    if ( listenfd < 0 ) {
        perror("netdev_listener: failed to create socket");
        return -1;
    }
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = 2;
    servaddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    servaddr.sin_port = htons(port);
    rvalue = bind(listenfd,
                (struct sockaddr *)&servaddr,
                sizeof(servaddr));
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to bind to address");
        return -1;
    }
    rvalue = listen(listenfd, 1024);
    if ( rvalue < 0 ) {
        perror("netdev_listener: failed to listen");
        return -1;
    }
    clilen = sizeof(cliaddr);
    printf("netdev_listener: starting listener at port: %d\n", port);
    while (1) {
        connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen);
        if (connfd < 0) {
            if ((*__errno_location ()) == 4) {
                continue;
            } else {
                perror("netdev_listener: accept error");
            }
        }
        ptr = (char *)inet_ntop(cliaddr.sin_family ,
                                &cliaddr.sin_addr,
                                str,
                                sizeof(str));
        if ( ptr != ((void *)0) ) {
            printf("netdev_listener: new connection from %s:%d\n",
                    str,
                    ntohs(cliaddr.sin_port));
        }
        if ( (childpid = fork()) ==0 ) {
            close(listenfd);
            proxy_server(connfd);
            exit(0);
        }
        close(connfd);
    }
    return 0;
}

variable_types: port int

variable_types: listenfd int

variable_types: connfd int

variable_types: rvalue int

variable_types: childpid int

variable_types:
clilen
unsigned int

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

variable_types:
str
char [16]

variable_types:
ptr
void *

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

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


repo: PonderingGrower/netdev

decompiled_code:
void proxy_sig_hup()
{
unsigned int v0; // eax

v0 = getpid();
printf("sig_hup: received signal in process: %d\n", v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = getpid();
printf("sig_hup: received signal in process: %d\n", v0);
}

original_code:
void proxy_sig_hup(int signo)
{
    printf("sig_hup: received signal in process: %d\n", getpid());
    return;
}

variable_types: signo int

return_type: void


decompiled_code:
__sighandler_t proxy_setup_signals()
{
prctl(1, 1LL);
signal(1, (__sighandler_t)proxy_sig_hup);
return signal(2, (__sighandler_t)((char *)proxy_sig_hup + 1));
}

canonical_decompiled_code:
__sighandler_t func1()
{
prctl(1, 1LL);
signal(1, (__sighandler_t)proxy_sig_hup);
return signal(2, (__sighandler_t)((char *)proxy_sig_hup + 1));
}

original_code:
void proxy_setup_signals()
{
    prctl(1, 1);
    signal(1, proxy_sig_hup);
    signal(2, ((__sighandler_t) 1));
}

canonical_original_code:
void proxy_setup_signals()
{
    prctl(1, 1);
    signal(1, proxy_sig_hup);
    signal(2, ((void (*)(int)) 1));
}


recvall

decompiled_code:
__int64 __fastcall recvall(int fd, struct msghdr *message, int a3)
{
int v3; // er12
iovec *v5; // rdx
int v6; // eax

v3 = 0;
while ( 1 )
{
v6 = recvmsg(fd, message, message->msg_flags);
if ( v6 == -1 )
{
v3 = -1;
perror("recvall(recvmsg)");
return (unsigned int)v3;
}
if ( !v6 )
break;
v5 = message->msg_iov;
v3 += v6;
v5->iov_base = (char *)v5->iov_base + v6;
v5->iov_len = v3;
if ( v3 >= a3 )
return (unsigned int)v3;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, struct msghdr *message, int a3)
{
int v3; // er12
iovec *v5; // rdx
int v6; // eax

v3 = 0;
while ( 1 )
{
v6 = recvmsg(fd, message, message->msg_flags);
if ( v6 == -1 )
{
v3 = -1;
perror("recvall(recvmsg)");
return (unsigned int)v3;
}
if ( !v6 )
break;
v5 = message->msg_iov;
v3 += v6;
v5->iov_base = (char *)v5->iov_base + v6;
v5->iov_len = v3;
if ( v3 >= a3 )
return (unsigned int)v3;
}
return 0xFFFFFFFFLL;
}

original_code:
int recvall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0, bytes = 0;
    do {
        rvalue = recvmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("recvall(recvmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return bytes;
}

canonical_original_code:
int recvall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0; int bytes = 0;
    do {
        rvalue = recvmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("recvall(recvmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return bytes;
}

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; } *

variable_types: size int

variable_types: bytes int

return_type: int

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


sendall

decompiled_code:
__int64 __fastcall sendall(int fd, struct msghdr *message, int a3)
{
int v4; // ebx
iovec *v5; // rdx
int v6; // eax

v4 = 0;
do
{
v6 = sendmsg(fd, message, message->msg_flags);
if ( v6 == -1 )
{
perror("sendmsg(sendmsg)");
return 0xFFFFFFFFLL;
}
if ( !v6 )
return 0xFFFFFFFFLL;
v5 = message->msg_iov;
v4 += v6;
v5->iov_base = (char *)v5->iov_base + v6;
v5->iov_len = v4;
}
while ( v4 < a3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, struct msghdr *message, int a3)
{
int v4; // ebx
iovec *v5; // rdx
int v6; // eax

v4 = 0;
do
{
v6 = sendmsg(fd, message, message->msg_flags);
if ( v6 == -1 )
{
perror("sendmsg(sendmsg)");
return 0xFFFFFFFFLL;
}
if ( !v6 )
return 0xFFFFFFFFLL;
v5 = message->msg_iov;
v4 += v6;
v5->iov_base = (char *)v5->iov_base + v6;
v5->iov_len = v4;
}
while ( v4 < a3 );
return 0LL;
}

original_code:
int sendall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0, bytes = 0;
    do {
        rvalue = sendmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("sendmsg(sendmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return 0;
}

canonical_original_code:
int sendall(int conn_fd, struct msghdr *msgh, int size) {
    int rvalue = 0; int bytes = 0;
    do {
        rvalue = sendmsg(conn_fd, msgh, msgh->msg_flags);
        if (rvalue == -1) {
            perror("sendmsg(sendmsg)");
            return -1;
        } else if (rvalue == 0 ) {
            return -1;
        }
        bytes += rvalue;
        msgh->msg_iov->iov_base += rvalue;
        msgh->msg_iov->iov_len = bytes;
    } while (bytes < size);
    return 0;
}

user_defined_types: struct iovec { void *iov_base; unsigned long iov_len; }


signal

decompiled_code:
__int64 __fastcall signal(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = (sig == 14) << 28;
v2 = sigaction(sig, &v4, &v5) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v5.sa_handler;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int sig, void (*a2)(int))
{
bool v2; // sf
__int64 result; // rax
struct sigaction v4; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+A0h] [rbp-A8h] BYREF

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = (sig == 14) << 28;
v2 = sigaction(sig, &v4, &v5) < 0;
result = -1LL;
if ( !v2 )
result = (__int64)v5.sa_handler;
return result;
}

original_code:
Sigfunc * signal(int signo, Sigfunc *func) {
    struct sigaction act, oact;
    act.__sigaction_handler.sa_handler = func;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    if (signo == 14) {
        act.sa_flags |= 0x10000000;
    }
    if (sigaction(signo, &act, &oact) < 0)
        return ((__sighandler_t) -1);
    return oact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*signal(int signo, void (*func)(int)))(int) {
    struct sigaction act; struct sigaction oact;
    act.__sigaction_handler.sa_handler = func;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    if (signo == 14) {
        act.sa_flags |= 0x10000000;
    }
    if (sigaction(signo, &act, &oact) < 0)
        return ((__sighandler_t) -1);
    return oact.__sigaction_handler.sa_handler;
}

variable_types:
func
void (*)(int)

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

return_type: void (*)(int)

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

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


main

canonical_name: main

repo: Potent-Code/testytest

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rsi
char **v4; // rbx
unsigned int v5; // er13
unsigned int v6; // er12
unsigned int v7; // ebp
int v8; // eax

v3 = Tests;
if ( Tests )
{
v4 = &Tests;
v5 = 0;
v6 = 0;
v7 = 0;
do
{
while ( 1 )
{
++v7;
printf("Running test %s\n", v3);
v8 = ((__int64 (*)(void))v4[2])();
if ( !v8 )
break;
v3 = v4[3];
v4 += 3;
v5 += v8 == 1;
if ( !v3 )
goto LABEL_6;
}
v3 = v4[3];
v4 += 3;
++v6;
}
while ( v3 );
}
else
{
v5 = 0;
v6 = 0;
v7 = 0;
}
LABEL_6:
printf("Ran %d tests, %d passed and %d failed\n", v7, v6, v5);
return 0;
}

original_code:
int main()
{
 test_result cur_result;
 int test_count = 0;
 int tests_passed = 0;
 int tests_failed = 0;
 test_case *i;
 test_result (*test_function)(void);
 for(i = Tests; i->name; i++)
 {
  test_count++;
  printf("Running test %s\n", i->name);
  test_function = i->function;
  cur_result = test_function();
  switch(cur_result)
  {
   case TEST_PASS:
    tests_passed++;
    break;
   case TEST_FAIL:
    tests_failed++;
    break;
  }
 }
 printf("Ran %d tests, %d passed and %d failed\n", test_count, tests_passed, tests_failed);
 return 0;
}

canonical_original_code:
int main()
{
 enum test_result cur_result;
 int test_count = 0;
 int tests_passed = 0;
 int tests_failed = 0;
 struct test_case *i;
 test_result (*test_function)(void);
 for(i = Tests; i->name; i++)
 {
  test_count++;
  printf("Running test %s\n", i->name);
  test_function = i->function;
  cur_result = test_function();
  switch(cur_result)
  {
   case TEST_PASS:
    tests_passed++;
    break;
   case TEST_FAIL:
    tests_failed++;
    break;
  }
 }
 printf("Ran %d tests, %d passed and %d failed\n", test_count, tests_passed, tests_failed);
 return 0;
}

variable_types: enum test_result { TEST_PASS=0, TEST_FAIL=1 }

variable_types: struct test_case { char *name; char *description; void *function; } *


decompiled_code:
__int64 basic_test()
{
puts("This is my test!");
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
puts("This is my test!");
return 0LL;
}

canonical_original_code:
enum test_result basic_test()
{
 printf("This is my test!\n");
 return TEST_PASS;
}

return_type: enum test_result { TEST_PASS=0, TEST_FAIL=1 }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

v3 = function2(argc, argv, envp);
printf("%d \n", v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

v3 = func8(argc, argv, envp);
printf("%d \n", v3);
return 0;
}

original_code:
int main(){
int x;
x = function2();
printf("%d \n",x);
return 0;
}

variable_types: x int


decompiled_code:
__int64 function1()
{
return 10LL;
}

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

original_code:
int function1(){
   return 10;
}

canonical_original_code:
int function1(){
   return 10;
}


decompiled_code:
__int64 __fastcall function2(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = (unsigned int)function1("%d \n", a2);
printf("%d \n", v2);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // r12

v2 = (unsigned int)func7("%d \n", a2);
printf("%d \n", v2);
return (unsigned int)v2;
}

original_code:
int function2(){
   int x;
   x = function1();
   printf("%d \n",x);
   return function1();
}


repo: PradheepShrinivasan/MyExploration

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
const char *v4; // rax
const char *v5; // rax
unsigned int v6; // eax
char v8[20]; // [rsp+4h] [rbp-14h] BYREF

v3 = (const char *)mystrcpy("helloworld", v8, envp);
printf("strcpy of helloworld %s \n", v3);
v4 = (const char *)mystrncpy("helloworld", v8, 1LL);
printf("%s \n", v4);
v5 = (const char *)mystrncpy("helloworld", v8, 0LL);
printf("%s \n", v5);
v6 = mystrlen("helloworld");
printf("length of helloworld = %d", v6);
return 0;
}

original_code:
int main()
{
 char *current = "helloworld";
 char destination [12];
 printf ("strcpy of helloworld %s \n", mystrcpy (current, destination));
 printf ("%s \n", mystrncpy (current, destination, 1));
 printf ("%s \n", mystrncpy (current, destination, 0));
 printf ("length of helloworld = %d", mystrlen ("helloworld"));
 return 0;
}

canonical_original_code:
int main()
{
 char *current = "helloworld";
 char destination[12];
 printf ("strcpy of helloworld %s \n", mystrcpy (current, destination));
 printf ("%s \n", mystrncpy (current, destination, 1));
 printf ("%s \n", mystrncpy (current, destination, 0));
 printf ("length of helloworld = %d", mystrlen ("helloworld"));
 return 0;
}

variable_types:
current
char *

variable_types:
destination
char [12]


mystrlen

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

if ( !*a1 )
return 0LL;
v1 = 1 - (_DWORD)a1;
do
v2 = v1 + (_DWORD)a1++;
while ( *a1 );
return v2;
}

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

if ( !*a1 )
return 0LL;
v1 = 1 - (_DWORD)a1;
do
v2 = v1 + (_DWORD)a1++;
while ( *a1 );
return v2;
}

original_code:
int mystrlen (const char* src)
{
 int length = 0;
 while (*src)
 {
  ++length;
  ++src;
 }
 return length;
}

canonical_original_code:
int mystrlen(char *src)
{
 int length = 0;
 while (*src)
 {
  ++length;
  ++src;
 }
 return length;
}

variable_types:
src
char *

variable_types: length int


repo: PredragWang/RPC-Examples

decompiled_code:
bool_t __fastcall xdr_dir(XDR *a1, char *a2)
{
char *cpp; // [rsp+8h] [rbp-10h] BYREF

cpp = a2;
return xdr_string(a1, &cpp, 0x2000u);
}

canonical_decompiled_code:
bool_t __fastcall func0(XDR *a1, char *a2)
{
char *cpp; // [rsp+8h] [rbp-10h] BYREF

cpp = a2;
return xdr_string(a1, &cpp, 0x2000u);
}

original_code:
bool_t xdr_dir(XDR *xdrs, char *objp){
 return (xdr_string(xdrs, &objp, 8192));
}

canonical_original_code:
int xdr_dir(struct XDR *xdrs, char *objp){
 return (xdr_string(xdrs, &objp, 8192));
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types:
objp
char *

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
__int64 __fastcall get_file_rpc(char *msg, char *s)
{
size_t v2; // rax
__int64 v3; // rbp
unsigned int *v4; // rax
unsigned int *v5; // rbx
unsigned int v6; // eax
_DWORD v8[256]; // [rsp+0h] [rbp-438h] BYREF
__int64 v9; // [rsp+400h] [rbp-38h]

init_fp(s);
init_clnt(msg);
memset(v8, 0, sizeof(v8));
v2 = strlen(s);
if ( v2 > 0x400 )
LODWORD(v2) = 1024;
if ( (unsigned int)v2 >= 8 )
{
*(_QWORD *)((char *)&v8[-2] + (unsigned int)v2) = *(_QWORD *)&s[(unsigned int)v2 - 8];
qmemcpy(v8, s, 8LL * ((unsigned int)(v2 - 1) >> 3));
}
else if ( (v2 & 4) != 0 )
{
v8[0] = *(_DWORD *)s;
*(_DWORD *)((char *)&v8[-1] + (unsigned int)v2) = *(_DWORD *)&s[(unsigned int)v2 - 4];
}
else if ( (_DWORD)v2 )
{
LOBYTE(v8[0]) = *s;
if ( (v2 & 2) != 0 )
*(_WORD *)((char *)v8 + (unsigned int)v2 - 2) = *(_WORD *)&s[(unsigned int)v2 - 2];
}
v3 = 0LL;
do
{
while ( 1 )
{
v9 = v3;
v4 = (unsigned int *)get_file_1(v8, clnt);
v5 = v4;
if ( !v4 )
{
clnt_perror(clnt, msg);
fclose(fp);
exit(1);
}
v6 = *v4;
if ( v6 )
{
__writefsdword((unsigned int)&errno, v6);
perror(s);
fclose(fp);
exit(1);
}
if ( *((_QWORD *)v5 + 513) == v3 )
break;
if ( v5[1030] )
goto LABEL_14;
}
puts("Write a chunk");
fwrite(v5 + 2, 1uLL, *((_QWORD *)v5 + 514), fp);
v3 += *((_QWORD *)v5 + 514);
}
while ( !v5[1030] );
LABEL_14:
fclose(fp);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *msg, char *s)
{
size_t v2; // rax
__int64 v3; // rbp
unsigned int *v4; // rax
unsigned int *v5; // rbx
unsigned int v6; // eax
_DWORD v8[256]; // [rsp+0h] [rbp-438h] BYREF
__int64 v9; // [rsp+400h] [rbp-38h]

init_fp(s);
init_clnt(msg);
memset(v8, 0, sizeof(v8));
v2 = strlen(s);
if ( v2 > 0x400 )
LODWORD(v2) = 1024;
if ( (unsigned int)v2 >= 8 )
{
*(_QWORD *)((char *)&v8[-2] + (unsigned int)v2) = *(_QWORD *)&s[(unsigned int)v2 - 8];
qmemcpy(v8, s, 8LL * ((unsigned int)(v2 - 1) >> 3));
}
else if ( (v2 & 4) != 0 )
{
v8[0] = *(_DWORD *)s;
*(_DWORD *)((char *)&v8[-1] + (unsigned int)v2) = *(_DWORD *)&s[(unsigned int)v2 - 4];
}
else if ( (_DWORD)v2 )
{
LOBYTE(v8[0]) = *s;
if ( (v2 & 2) != 0 )
*(_WORD *)((char *)v8 + (unsigned int)v2 - 2) = *(_WORD *)&s[(unsigned int)v2 - 2];
}
v3 = 0LL;
do
{
while ( 1 )
{
v9 = v3;
v4 = (unsigned int *)get_file_1(v8, clnt);
v5 = v4;
if ( !v4 )
{
clnt_perror(clnt, msg);
fclose(fp);
exit(1);
}
v6 = *v4;
if ( v6 )
{
__writefsdword((unsigned int)&errno, v6);
perror(s);
fclose(fp);
exit(1);
}
if ( *((_QWORD *)v5 + 513) == v3 )
break;
if ( v5[1030] )
goto LABEL_14;
}
puts("Write a chunk");
fwrite(v5 + 2, 1uLL, *((_QWORD *)v5 + 514), fp);
v3 += *((_QWORD *)v5 + 514);
}
while ( !v5[1030] );
LABEL_14:
fclose(fp);
return 0LL;
}

original_code:
int get_file_rpc(char *host, char *f_name) {
    init_fp(f_name);
    init_clnt(host);
    size_t offset = 0;
    size_t written = 0;
    get_file_ret *ret;
    request req;
    memset(req.f_name, 0, 1024);
    memcpy(req.f_name, f_name, (strlen(f_name) <= 1024 ? strlen(f_name): 1024));
    while (1) {
        req.offset = offset;
        ret = get_file_1(&req, clnt);
        if (ret == ((void *)0)) {
            clnt_perror(clnt, host);
            fclose(fp);
            exit(1);
        }
        if (ret->errno != 0) {
            errno = ret->errno;
            perror(f_name);
            fclose(fp);
            exit(1);
        }
        if (ret->get_file_ret_u.f_chunk.offset == offset) {
            printf("Write a chunk\n");
            written = fwrite(ret->get_file_ret_u.f_chunk.data, 1,
                        ret->get_file_ret_u.f_chunk.bytes, fp);
            if (written < 0) {
                perror("Error in writing\n");
                exit(1);
            }
            offset += ret->get_file_ret_u.f_chunk.bytes;
        }
        if (ret->get_file_ret_u.f_chunk.end) break;
    }
    fclose(fp);
    return 0;
}

canonical_original_code:
int get_file_rpc(char *host, char *f_name) {
    init_fp(f_name);
    init_clnt(host);
    unsigned long offset = 0;
    unsigned long written = 0;
    struct get_file_ret *ret;
    struct request req;
    memset(req.f_name, 0, 1024);
    memcpy(req.f_name, f_name, (strlen(f_name) <= 1024 ? strlen(f_name): 1024));
    while (1) {
        req.offset = offset;
        ret = get_file_1(&req, clnt);
        if (ret == ((void *)0)) {
            clnt_perror(clnt, host);
            fclose(fp);
            exit(1);
        }
        if (ret->errno != 0) {
            errno = ret->errno;
            perror(f_name);
            fclose(fp);
            exit(1);
        }
        if (ret->get_file_ret_u.f_chunk.offset == offset) {
            printf("Write a chunk\n");
            written = fwrite(ret->get_file_ret_u.f_chunk.data, 1,
                        ret->get_file_ret_u.f_chunk.bytes, fp);
            if (written < 0) {
                perror("Error in writing\n");
                exit(1);
            }
            offset += ret->get_file_ret_u.f_chunk.bytes;
        }
        if (ret->get_file_ret_u.f_chunk.end) break;
    }
    fclose(fp);
    return 0;
}

variable_types:
host
char *

variable_types:
offset
unsigned long

variable_types:
written
unsigned long

variable_types: struct get_file_ret { int errno; union { struct filechunk { char data[4096]; unsigned long offset; unsigned long bytes; int end; } f_chunk; } get_file_ret_u; } *

variable_types: struct request { char f_name[1024]; unsigned long offset; }

user_defined_types: struct get_file_ret { int errno; union { struct filechunk f_chunk; } get_file_ret_u; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax

if ( argc != 3 )
{
puts("Usage: ./rpc_ft_client <host> <file>");
exit(1);
}
v3 = argv[2];
v4 = strlen(v3);
printf("%s : %lu\n", v3, v4);
get_file_rpc((char *)argv[1], (char *)argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
size_t v4; // rax

if ( argc != 3 )
{
puts("Usage: ./rpc_ft_client <host> <file>");
exit(1);
}
v3 = argv[2];
v4 = strlen(v3);
printf("%s : %lu\n", v3, v4);
func0((char *)argv[1], (char *)argv[2]);
return 0;
}

original_code:
int main(int argc, char **argv) {
    if (argc != 3) {
        printf("Usage: ./rpc_ft_client <host> <file>\n");
        exit(1);
    }
    printf("%s : %lu\n", argv[2], strlen(argv[2]));
    get_file_rpc(argv[1], argv[2]);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


strrev

decompiled_code:
const char *__fastcall strrev(const char *a1)
{
const char *v1; // rax
const char *v2; // rdx
char v3; // cl
char v4; // si

v1 = &a1[strlen(a1) - 1];
if ( a1 < v1 )
{
v2 = a1;
do
{
v3 = *v2;
v4 = *v1;
++v2;
--v1;
*((_BYTE *)v2 - 1) = v4;
*((_BYTE *)v1 + 1) = v3;
}
while ( v2 < v1 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
const char *v1; // rax
const char *v2; // rdx
char v3; // cl
char v4; // si

v1 = &a1[strlen(a1) - 1];
if ( a1 < v1 )
{
v2 = a1;
do
{
v3 = *v2;
v4 = *v1;
++v2;
--v1;
*((_BYTE *)v2 - 1) = v4;
*((_BYTE *)v1 + 1) = v3;
}
while ( v2 < v1 );
}
return a1;
}

original_code:
char *strrev(char *str)
{
 char *ptr = str;
 char *end = str + strlen(str)-1;
 char tmp;
 while (end > str) {
  tmp = *str;
  *str = *end;
  *end = tmp;
  ++str;
  --end;
 }
 return ptr;
}

variable_types:
str
char *

variable_types:
ptr
char *

variable_types:
end
char *

variable_types: tmp char

return_type: char *


decompiled_code:
char *__fastcall get_word(const char *a1, char **a2)
{
char *v2; // rax
char *v3; // r12
const unsigned __int16 *v4; // rdi
char *i; // rax
char *v6; // rdx
__int64 v7; // rcx

v2 = strdup(a1);
*a2 = 0LL;
v3 = v2;
v4 = *_ctype_b_loc();
for ( i = v3; ; ++i )
{
v7 = *i;
if ( (v4[v7] & 8) == 0 && (_BYTE)v7 != 95 )
break;
v6 = &i[1LL - (_QWORD)v3];
*a2 = v6;
}
*i = 0;
return v3;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, char **a2)
{
char *v2; // rax
char *v3; // r12
const unsigned __int16 *v4; // rdi
char *i; // rax
char *v6; // rdx
__int64 v7; // rcx

v2 = strdup(a1);
*a2 = 0LL;
v3 = v2;
v4 = *_ctype_b_loc();
for ( i = v3; ; ++i )
{
v7 = *i;
if ( (v4[v7] & 8) == 0 && (_BYTE)v7 != 95 )
break;
v6 = &i[1LL - (_QWORD)v3];
*a2 = v6;
}
*i = 0;
return v3;
}

original_code:
char *get_word(const char *str, size_t *len)
{
 char *cpy = strdup(str);
 for (*len=0; ((*__ctype_b_loc ())[(int) ((cpy[*len]))] & (unsigned short int) _ISalnum) || cpy[*len] == '_'; ++*len)
  ;
 cpy[*len] = '\0';
 return cpy;
}

canonical_original_code:
char *get_word(char *str, unsigned long *len)
{
 char *cpy = strdup(str);
 for (*len=0; ((*__ctype_b_loc ())[(int) ((cpy[*len]))] & (unsigned short) _ISalnum) || cpy[*len] == '_'; ++*len)
  ;
 cpy[*len] = '\0';
 return cpy;
}

variable_types:
len
unsigned long *

variable_types:
cpy
char *


decompiled_code:
int __fastcall var_compare_by_name(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int var_compare_by_name(const void *v1, const void *v2) {
 return strcmp(((variable *)v1)->name, ((variable *)v2)->name);
}

canonical_original_code:
static int var_compare_by_name(void *v1, void *v2) {
 return strcmp(((struct variable *)v1)->name, ((struct variable *)v2)->name);
}

user_defined_types: struct variable { char *name; double val; int destroy; }


decompiled_code:
__int64 variables_init()
{
char **v0; // rbx
const char **v1; // rdi
__int64 result; // rax

v0 = &default_vars;
do
{
v1 = (const char **)v0;
v0 += 3;
result = _variable_save(v1);
}
while ( v0 != (char **)&unk_298 );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char **v0; // rbx
const char **v1; // rdi
__int64 result; // rax

v0 = &default_vars;
do
{
v1 = (const char **)v0;
v0 += 3;
result = func0(v1);
}
while ( v0 != (char **)&unk_298 );
return result;
}

original_code:
void variables_init(void) {
 const variable *v = &default_vars[0];
 size_t len = sizeof(default_vars) / sizeof(default_vars[0]);
 for (; len > 0; --len, ++v)
  __variable_save(v);
}

canonical_original_code:
void variables_init() {
 struct variable *v = &default_vars[0];
 unsigned long len = sizeof(default_vars) / sizeof(default_vars[0]);
 for (; len > 0; --len, ++v)
  __variable_save(v);
}

variable_types: struct variable { char *name; double val; int destroy; } *

variable_types:
len
unsigned long


decompiled_code:
__int64 __fastcall variable_save(char *s, double a2)
{
double *v2; // rax
double *v3; // rbp
char *v4; // rax

v2 = (double *)malloc(0x18uLL);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = strdup(s);
v3[1] = a2;
*(_QWORD *)v3 = v4;
*((_DWORD *)v3 + 4) = 1;
return _variable_save((const char **)v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, double a2)
{
double *v2; // rax
double *v3; // rbp
char *v4; // rax

v2 = (double *)malloc(0x18uLL);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = strdup(s);
v3[1] = a2;
*(_QWORD *)v3 = v4;
*((_DWORD *)v3 + 4) = 1;
return func0((const char **)v3);
}

original_code:
int variable_save(const char *name, double val) {
 variable *v;
 if ((v = malloc(sizeof(*v))) == ((void *)0))
  return 0;
 v->name = strdup(name);
 v->val = val;
 v->destroy = 1;
 return __variable_save(v);
}

canonical_original_code:
int variable_save(char *name, double val) {
 struct variable *v;
 if ((v = malloc(sizeof(*v))) == ((void *)0))
  return 0;
 v->name = strdup(name);
 v->val = val;
 v->destroy = 1;
 return __variable_save(v);
}

variable_types:
name
char *

variable_types: val double


decompiled_code:
__int64 __fastcall variable_value(const char *a1, _QWORD *a2)
{
char *v2; // rbp
void *v3; // rbx
__int64 result; // rax
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h]

v2 = strdup(a1);
v5[0] = (__int64)v2;
v5[1] = 0LL;
v6 = 0;
v3 = tfind(v5, &defined_vars, var_compare_by_name);
free(v2);
result = 0LL;
if ( v3 )
{
result = 1LL;
*a2 = *(_QWORD *)(*(_QWORD *)v3 + 8LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, _QWORD *a2)
{
char *v2; // rbp
void *v3; // rbx
__int64 result; // rax
__int64 v5[2]; // [rsp+0h] [rbp-38h] BYREF
int v6; // [rsp+10h] [rbp-28h]

v2 = strdup(a1);
v5[0] = (__int64)v2;
v5[1] = 0LL;
v6 = 0;
v3 = tfind(v5, &defined_vars, var_compare_by_name);
free(v2);
result = 0LL;
if ( v3 )
{
result = 1LL;
*a2 = *(_QWORD *)(*(_QWORD *)v3 + 8LL);
}
return result;
}

original_code:
int variable_value(const char *name, double *valptr) {
 char *name2 = strdup(name);
 void *found;
 variable var = { name2, 0, 0 };
 found = tfind(&var, &defined_vars, var_compare_by_name);
 free(name2);
 if (found != ((void *)0)) {
  *valptr = (*(variable **) found)->val;
  return 1;
 }
 return 0;
}

canonical_original_code:
int variable_value(char *name, double *valptr) {
 char *name2 = strdup(name);
 void *found;
 struct variable var = { name2, 0, 0 };
 found = tfind(&var, &defined_vars, var_compare_by_name);
 free(name2);
 if (found != ((void *)0)) {
  *valptr = (*(struct variable **) found)->val;
  return 1;
 }
 return 0;
}

variable_types:
valptr
double *

variable_types:
found
void *

variable_types: struct variable { char *name; double val; int destroy; }


decompiled_code:
__int64 __fastcall variable_value_c(char a1, _QWORD *a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = a1;
v3[1] = 0;
return variable_value(v3, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, _QWORD *a2)
{
char v3[10]; // [rsp+Eh] [rbp-Ah] BYREF

v3[0] = a1;
v3[1] = 0;
return func4(v3, a2);
}

original_code:
int variable_value_c(char c, double *valptr) {
 char buf[2];
 buf[0] = c;
 buf[1] = '\0';
 return variable_value(buf, valptr);
}

variable_types: c char

variable_types:
buf
char [2]


decompiled_code:
const void **variables_uninit()
{
const void **result; // rax
void **v1; // rbp

for ( result = (const void **)defined_vars; defined_vars; result = (const void **)defined_vars )
{
while ( 1 )
{
v1 = (void **)*result;
tdelete(*result, &defined_vars, (__compar_fn_t)&compare_ptr);
if ( *((_DWORD *)v1 + 4) )
break;
result = (const void **)defined_vars;
if ( !defined_vars )
return result;
}
free(*v1);
free(v1);
}
return result;
}

canonical_decompiled_code:
const void **func6()
{
const void **result; // rax
void **v1; // rbp

for ( result = (const void **)defined_vars; defined_vars; result = (const void **)defined_vars )
{
while ( 1 )
{
v1 = (void **)*result;
tdelete(*result, &defined_vars, (__compar_fn_t)&compare_ptr);
if ( *((_DWORD *)v1 + 4) )
break;
result = (const void **)defined_vars;
if ( !defined_vars )
return result;
}
free(*v1);
free(v1);
}
return result;
}

original_code:
void variables_uninit(void) {
 variable *v;
 while (defined_vars != ((void *)0)) {
  v = *(variable **) defined_vars;
  tdelete(v, &defined_vars, compare_ptr);
  if (v->destroy) {
   free(v->name);
   free(v);
  }
 }
}

canonical_original_code:
void variables_uninit() {
 struct variable *v;
 while (defined_vars != ((void *)0)) {
  v = *(struct variable **) defined_vars;
  tdelete(v, &defined_vars, compare_ptr);
  if (v->destroy) {
   free(v->name);
   free(v);
  }
 }
}


decompiled_code:
int commands_init()
{
const char **v0; // rbx
const char ***v1; // rax

v0 = (const char **)&default_cmds;
do
{
v1 = (const char ***)tsearch(v0, &command_list, cmd_compare_by_name);
if ( *v1 != v0 )
LODWORD(v1) = fprintf(stderr, "%s: could not insert %s\n", "commands_init", *v0);
v0 += 5;
}
while ( v0 != (const char **)&unk_B98 );
return (int)v1;
}

canonical_decompiled_code:
int func1()
{
const char **v0; // rbx
const char ***v1; // rax

v0 = (const char **)&default_cmds;
do
{
v1 = (const char ***)tsearch(v0, &command_list, cmd_compare_by_name);
if ( *v1 != v0 )
LODWORD(v1) = fprintf(stderr, "%s: could not insert %s\n", "commands_init", *v0);
v0 += 5;
}
while ( v0 != (const char **)&unk_B98 );
return (int)v1;
}

original_code:
static void commands_init(void) {
 const command *c = &default_cmds[0];
 void *cval;
 size_t len = num_cmds;
 for (; len > 0; --len, ++c) {
  cval = tsearch(c, &command_list, cmd_compare_by_name);
  if ((*(command **)cval) != c)
   fprintf(stderr, "%s: could not insert %s\n",
    __func__, *(char **)c);
 }
}

canonical_original_code:
static void commands_init() {
 struct command *c = &default_cmds[0];
 void *cval;
 unsigned long len = num_cmds;
 for (; len > 0; --len, ++c) {
  cval = tsearch(c, &command_list, cmd_compare_by_name);
  if ((*(struct command **)cval) != c)
   fprintf(stderr, "%s: could not insert %s\n",
    __func__, *(char **)c);
 }
}

variable_types: struct command { char *name; unsigned long nargs; void (*exec)(struct command *, void *[]); char *syntax; char *info; } *

variable_types:
cval
void *


decompiled_code:
int __fastcall cmd_compare_by_name(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int cmd_compare_by_name(const void *c1, const void *c2) {
 return strcmp(((command *)c1)->name, ((command *)c2)->name);
}

canonical_original_code:
static int cmd_compare_by_name(void *c1, void *c2) {
 return strcmp(((struct command *)c1)->name, ((struct command *)c2)->name);
}

user_defined_types: struct command { char *name; unsigned long nargs; void (*exec)(struct command *, void *[]); char *syntax; char *info; }


decompiled_code:
int __fastcall command_display(const char **a1)
{
return printf(" usage: %s %s - %s\n", *a1, a1[3], a1[4]);
}

canonical_decompiled_code:
int __fastcall func3(const char **a1)
{
return printf(" usage: %s %s - %s\n", *a1, a1[3], a1[4]);
}

original_code:
static void command_display(const command *c) {
 printf(" usage: %s %s - %s\n", c->name, c->syntax, c->info);
}

canonical_original_code:
static void command_display(struct command *c) {
 printf(" usage: %s %s - %s\n", c->name, c->syntax, c->info);
}


decompiled_code:
const void **commands_uninit()
{
const void **result; // rax

for ( result = (const void **)command_list; command_list; result = (const void **)command_list )
tdelete(*result, &command_list, (__compar_fn_t)&compare_ptr);
return result;
}

canonical_decompiled_code:
const void **func11()
{
const void **result; // rax

for ( result = (const void **)command_list; command_list; result = (const void **)command_list )
tdelete(*result, &command_list, (__compar_fn_t)&compare_ptr);
return result;
}

original_code:
static void commands_uninit(void) {
 const command *c;
 while (command_list != ((void *)0)) {
  c = *(const command **) command_list;
  tdelete(c, &command_list, compare_ptr);
 }
}

canonical_original_code:
static void commands_uninit() {
 struct command *c;
 while (command_list != ((void *)0)) {
  c = *(struct command **) command_list;
  tdelete(c, &command_list, compare_ptr);
 }
}


decompiled_code:
int repl_init()
{
int result; // eax

result = repl_initialized;
if ( !repl_initialized )
{
variables_init();
functions_init();
using_history();
result = commands_init();
repl_initialized = 1;
}
return result;
}

canonical_decompiled_code:
int func12()
{
int result; // eax

result = repl_initialized;
if ( !repl_initialized )
{
variables_init();
functions_init();
using_history();
result = func1();
repl_initialized = 1;
}
return result;
}

original_code:
void repl_init(void) {
 if (!repl_initialized) {
  variables_init();
  functions_init();
  using_history();
  commands_init();
  repl_initialized = 1;
 }
}

canonical_original_code:
void repl_init() {
 if (!repl_initialized) {
  variables_init();
  functions_init();
  using_history();
  commands_init();
  repl_initialized = 1;
 }
}


decompiled_code:
void __fastcall repl_prompt(const char *a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 v3; // rax
_BYTE *v4; // rbp
const char *v5; // rax
char *v6; // r12
void *ptr; // [rsp+0h] [rbp-A8h] BYREF
__int64 v8; // [rsp+8h] [rbp-A0h] BYREF
__int64 v9[19]; // [rsp+10h] [rbp-98h] BYREF

ptr = 0LL;
printf("Starting %s v\x1B[31m%s\x1B[0m...\n", "gPlotter", "0.1-alpha");
if ( asprintf((char **)&ptr, "%s%s%s %%%s ", "\x1B[34m", a1, "\x1B[32m", "\x1B[0m") == -1 )
{
fprintf(stderr, "%s: could not allocate prefix\n", "repl_prompt");
}
else
{
while ( repl != 2 )
{
v3 = readline(ptr);
v4 = (_BYTE *)v3;
if ( !v3 )
break;
v5 = (const char *)get_word(v3, &v8);
v6 = (char *)v5;
if ( v5 )
{
v1 = commands_find(v5);
if ( v1 )
{
v9[1] = 0LL;
v2 = 0LL;
if ( v4[v8] )
v2 = (__int64)&v4[v8 + 1];
v9[0] = v2;
((void (__fastcall *)(_QWORD *, __int64 *))v1[2])(v1, v9);
}
else if ( *v6 )
{
fprintf(stderr, " '%s' - not a command\n", v6);
}
free(v6);
}
else
{
fwrite("unknown command\n", 1uLL, 0x10uLL, stderr);
}
free(v4);
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func13(const char *a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 v3; // rax
_BYTE *v4; // rbp
const char *v5; // rax
char *v6; // r12
void *ptr; // [rsp+0h] [rbp-A8h] BYREF
__int64 v8; // [rsp+8h] [rbp-A0h] BYREF
__int64 v9[19]; // [rsp+10h] [rbp-98h] BYREF

ptr = 0LL;
printf("Starting %s v\x1B[31m%s\x1B[0m...\n", "gPlotter", "0.1-alpha");
if ( asprintf((char **)&ptr, "%s%s%s %%%s ", "\x1B[34m", a1, "\x1B[32m", "\x1B[0m") == -1 )
{
fprintf(stderr, "%s: could not allocate prefix\n", "repl_prompt");
}
else
{
while ( repl != 2 )
{
v3 = readline(ptr);
v4 = (_BYTE *)v3;
if ( !v3 )
break;
v5 = (const char *)get_word(v3, &v8);
v6 = (char *)v5;
if ( v5 )
{
v1 = commands_find(v5);
if ( v1 )
{
v9[1] = 0LL;
v2 = 0LL;
if ( v4[v8] )
v2 = (__int64)&v4[v8 + 1];
v9[0] = v2;
((void (__fastcall *)(_QWORD *, __int64 *))v1[2])(v1, v9);
}
else if ( *v6 )
{
fprintf(stderr, " '%s' - not a command\n", v6);
}
free(v6);
}
else
{
fwrite("unknown command\n", 1uLL, 0x10uLL, stderr);
}
free(v4);
}
}
free(ptr);
}

original_code:
void repl_prompt(const char *pre) {
 char *input;
 char *prefix = ((void *)0);
 char *cmd_word;
 const command *c;
 size_t wordlen;
 void *argv[16];
 printf("Starting %s v""\x1B[31m""%s""\x1B[0m""...\n", "gPlotter", "0.1-alpha");
 if (asprintf(&prefix, "%s%s%s %%%s ", "\x1B[34m", pre, "\x1B[32m", "\x1B[0m") == -1)
  fprintf(stderr, "%s: could not allocate prefix\n", __func__);
 else
  while (repl.state != EXIT && (input = readline(prefix)) != ((void *)0)) {
   if ((cmd_word = get_word(input, &wordlen)) != ((void *)0)) {
    if ((c = commands_find(cmd_word)) != ((void *)0)) {
     argv[1] = ((void *)0);
     argv[0] = input[wordlen] ?
        input + wordlen+1 : ((void *)0);
     c->exec(c, argv);
    } else if (*cmd_word) {
     fprintf(stderr,
      " '%s' - not a command\n",
      cmd_word);
    }
    free(cmd_word);
   } else {
    fprintf(stderr, "unknown command\n");
   }
   free(input);
  }
 free(prefix);
}

canonical_original_code:
void repl_prompt(char *pre) {
 char *input;
 char *prefix = ((void *)0);
 char *cmd_word;
 struct command *c;
 unsigned long wordlen;
 void *argv[16];
 printf("Starting %s v""\x1B[31m""%s""\x1B[0m""...\n", "gPlotter", "0.1-alpha");
 if (asprintf(&prefix, "%s%s%s %%%s ", "\x1B[34m", pre, "\x1B[32m", "\x1B[0m") == -1)
  fprintf(stderr, "%s: could not allocate prefix\n", __func__);
 else
  while (repl.state != EXIT && (input = readline(prefix)) != ((void *)0)) {
   if ((cmd_word = get_word(input, &wordlen)) != ((void *)0)) {
    if ((c = commands_find(cmd_word)) != ((void *)0)) {
     argv[1] = ((void *)0);
     argv[0] = input[wordlen] ?
        input + wordlen+1 : ((void *)0);
     c->exec(c, argv);
    } else if (*cmd_word) {
     fprintf(stderr,
      " '%s' - not a command\n",
      cmd_word);
    }
    free(cmd_word);
   } else {
    fprintf(stderr, "unknown command\n");
   }
   free(input);
  }
 free(prefix);
}

variable_types:
pre
char *

variable_types:
input
char *

variable_types:
prefix
char *

variable_types:
wordlen
unsigned long

variable_types:
argv
void *[16]


decompiled_code:
__int64 __fastcall repl_prompt_eval(__int64 a1, double a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r12
__int64 result; // rax
void *v6; // [rsp+0h] [rbp-28h] BYREF
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v6 = 0LL;
ptr = 0LL;
asprintf((char **)&v6, "eval[%d]: ", a1);
v2 = readline(v6);
if ( v2 )
{
v3 = (void *)v2;
asprintf(&ptr, "f%d", a1);
v4 = function_new(ptr, 0LL, v3);
function_eval(v4, 0LL);
printf("result: %lf\n", a2);
add_history(v3);
function_destroy(v4);
free(v3);
free(v6);
free(ptr);
result = 0LL;
}
else
{
free(v6);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, double a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r12
__int64 result; // rax
void *v6; // [rsp+0h] [rbp-28h] BYREF
char *ptr; // [rsp+8h] [rbp-20h] BYREF

v6 = 0LL;
ptr = 0LL;
asprintf((char **)&v6, "eval[%d]: ", a1);
v2 = readline(v6);
if ( v2 )
{
v3 = (void *)v2;
asprintf(&ptr, "f%d", a1);
v4 = function_new(ptr, 0LL, v3);
function_eval(v4, 0LL);
printf("result: %lf\n", a2);
add_history(v3);
function_destroy(v4);
free(v3);
free(v6);
free(ptr);
result = 0LL;
}
else
{
free(v6);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int repl_prompt_eval(long nl) {
 char *input;
 double val;
 char *prefix = ((void *)0), *temp = ((void *)0);
 function *func;
 asprintf(&prefix, "eval[%d]: ", nl);
 if ((input = readline(prefix)) != ((void *)0)) {
  asprintf(&temp, "f%d", nl);
  func = function_new(temp, ((void *)0), input);
  val = function_eval(func, ((void *)0));
  printf("result: %lf\n", val);
  add_history(input);
  function_destroy(func);
  free(input);
  free(prefix);
  free(temp);
 } else
  free(prefix);
 return input != ((void *)0) ? 0 : -1;
}

canonical_original_code:
int repl_prompt_eval(long nl) {
 char *input;
 double val;
 char *prefix = ((void *)0); char *temp = ((void *)0);
 struct function *func;
 asprintf(&prefix, "eval[%d]: ", nl);
 if ((input = readline(prefix)) != ((void *)0)) {
  asprintf(&temp, "f%d", nl);
  func = function_new(temp, ((void *)0), input);
  val = function_eval(func, ((void *)0));
  printf("result: %lf\n", val);
  add_history(input);
  function_destroy(func);
  free(input);
  free(prefix);
  free(temp);
 } else
  free(prefix);
 return input != ((void *)0) ? 0 : -1;
}

variable_types: nl long

variable_types:
temp
char *

variable_types: struct function { char *name; char *vars; unsigned long nvars; char *descr; unsigned long len; enum function_type { USER=0, NATIVE=1, ANY=2 } type; void *native_fptr; int destroy; } *

user_defined_types: struct function { char *name; char *vars; unsigned long nvars; char *descr; unsigned long len; enum function_type type; void *native_fptr; int destroy; }


decompiled_code:
const void **repl_uninit()
{
const void **result; // rax

result = (const void **)(unsigned int)repl_initialized;
if ( repl_initialized )
{
functions_uninit();
variables_uninit();
clear_history();
result = commands_uninit();
repl_initialized = 0;
}
return result;
}

canonical_decompiled_code:
const void **func16()
{
const void **result; // rax

result = (const void **)(unsigned int)repl_initialized;
if ( repl_initialized )
{
functions_uninit();
variables_uninit();
clear_history();
result = func11();
repl_initialized = 0;
}
return result;
}

original_code:
void repl_uninit(void) {
 if (repl_initialized) {
  functions_uninit();
  variables_uninit();
  clear_history();
  commands_uninit();
  repl_initialized = 0;
 }
}

canonical_original_code:
void repl_uninit() {
 if (repl_initialized) {
  functions_uninit();
  variables_uninit();
  clear_history();
  commands_uninit();
  repl_initialized = 0;
 }
}


romberg

repo: ProfessorBrunner/tpacf

decompiled_code:
__int64 __fastcall romberg(double a1)
{
__int64 v1; // r12
int v2; // ebp
__int64 v3; // rbx
double v4; // xmm1_8
int j; // er13
double v6; // xmm0_8
__int64 result; // rax
int v8; // edx
double v9; // xmm1_8
double v10; // xmm0_8
__int64 v11; // xmm6_8
double v12; // xmm3_8
unsigned __int64 v13; // rax
__int64 v14; // xmm7_8
double v15; // [rsp+0h] [rbp-1A8h]
double v16; // [rsp+0h] [rbp-1A8h]
double i; // [rsp+18h] [rbp-190h]
__int64 v19[49]; // [rsp+20h] [rbp-188h]

v1 = 16LL;
v2 = 1;
v3 = 1LL;
v15 = COERCE_DOUBLE(oneOverE(0.0));
v16 = (COERCE_DOUBLE(oneOverE(a1)) + v15) * (0.5 * a1);
*(double *)v19 = v16;
for ( i = v16; ; i = *(double *)&v14 )
{
v4 = 0.0;
if ( v2 > 0 )
{
for ( j = 1; j <= v2; ++j )
{
v6 = ((double)j - 0.5) * a1;
v4 = v4 + COERCE_DOUBLE(oneOverE(v6));
}
}
v2 *= 2;
result = 1LL;
v8 = 4;
v9 = (v4 * a1 + v16) * 0.5;
v10 = v9;
while ( 1 )
{
v12 = (double)v8 - 1.0;
v8 *= 4;
v10 = v10 + (v10 - v16) / v12;
*(double *)&v19[result + 22] = v10;
if ( v3 == result )
break;
v11 = v19[result++];
v16 = *(double *)&v11;
}
if ( 0.0000001 * i > COERCE_DOUBLE(COERCE_UNSIGNED_INT64(v10 - i) & LC5) )
break;
if ( v3 == 20 )
{
fwrite("Maximum refinement reached in romberg...ABORTING\n", 1uLL, 0x31uLL, stderr);
exit(1);
}
v13 = 0LL;
a1 = 0.5 * a1;
while ( 1 )
{
*(double *)&v19[v13 / 8] = v9;
v13 += 8LL;
if ( v1 == v13 )
break;
v9 = *(double *)&v19[v13 / 8 + 22];
}
v1 += 8LL;
v16 = *(double *)v19;
v14 = v19[v3++];
}
return result;
}

original_code:
static double romberg(double z){
 int i,j,steps,denom;
 double h,r1[20 +1],r2[20 +1],sum;
 h = z;
 r1[0] = oneOverE(0.);
 r1[0] += oneOverE(z);
 r1[0] *= 0.5*h;
 i = 1;
 steps = 1;
 denom = 4.;
 for( ; ; ){
  sum = 0.;
  for(j=1;j<=steps;j++){
   sum += oneOverE(((double)j-0.5)*h);
  }
  steps = steps << 1;
  r2[0] = .5*(r1[0] + h*sum);
  denom = 4;
  for(j=0;j<i;j++){
   r2[j+1] = r2[j] + (r2[j]-r1[j])/((double)denom-1.);
   denom = denom << 2;
  }
  if(fabs(r2[i] - r1[i-1]) < 1.e-7*r1[i-1]){
   return r2[i];
  }else if(i == 20){
   fprintf(stderr,"Maximum refinement reached in romberg...ABORTING\n");
   exit(1);
  }
  h = h/2.;
  i++;
  for(j=0;j<i;j++){
   r1[j] = r2[j];
  }
 }
}

canonical_original_code:
static double romberg(double z){
 int i; int j; int steps; int denom;
 double h; double r1[-1]; double r2[-1]; double sum;
 h = z;
 r1[0] = oneOverE(0.);
 r1[0] += oneOverE(z);
 r1[0] *= 0.5*h;
 i = 1;
 steps = 1;
 denom = 4.;
 for( ; ; ){
  sum = 0.;
  for(j=1;j<=steps;j++){
   sum += oneOverE(((double)j-0.5)*h);
  }
  steps = steps << 1;
  r2[0] = .5*(r1[0] + h*sum);
  denom = 4;
  for(j=0;j<i;j++){
   r2[j+1] = r2[j] + (r2[j]-r1[j])/((double)denom-1.);
   denom = denom << 2;
  }
  if(fabs(r2[i] - r1[i-1]) < 1.e-7*r1[i-1]){
   return r2[i];
  }else if(i == 20){
   fprintf(stderr,"Maximum refinement reached in romberg...ABORTING\n");
   exit(1);
  }
  h = h/2.;
  i++;
  for(j=0;j<i;j++){
   r1[j] = r2[j];
  }
 }
}

variable_types: z double

variable_types: i int

variable_types: j int

variable_types: steps int

variable_types: denom int

variable_types: h double

variable_types: sum double

return_type: double


dm

decompiled_code:
double __fastcall dm(double a1)
{
romberg(a1);
return a1 * 3000.0;
}

canonical_decompiled_code:
double __fastcall func2(double a1)
{
func1(a1);
return a1 * 3000.0;
}

original_code:
static double dm(double z){
 return 3000.*romberg(z);
}


binBuildSpatial

decompiled_code:
double *__fastcall binBuildSpatial(double a1, double a2)
{
double *v2; // r12
int v3; // eax
double *v4; // rbx
int v5; // ebp
double v6; // r14
double v7; // xmm0_8
size_t v8; // rdi
void *v9; // rax
int v10; // er13
double *v11; // rbx
double v12; // rdi

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( !v2 )
{
puts("Failed to allocate memory in binBuild");
return v2;
}
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = v2;
v5 = 0;
v6 = a1 / a2;
while ( 1 )
{
*v4 = pow(v6, ((double)v5 + (double)v5) / (double)v3) * (a2 * a2);
v7 = pow(v6, ((double)v5 - 0.5) / (double)NumBins);
v8 = 8LL * (NumSamples + 1);
v4[2] = v7 * a2;
v9 = malloc(v8);
*((_QWORD *)v4 + 1) = v9;
if ( !v9 )
break;
v10 = NumSamples;
if ( NumSamples >= 0 )
memset(v9, 0, 8LL * NumSamples + 8);
v3 = NumBins;
++v5;
v4 += 3;
if ( NumBins < v5 )
goto LABEL_8;
}
LABEL_13:
v2 = 0LL;
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return v2;
}
v10 = NumSamples;
LABEL_8:
v11 = &v2[3 * v3 + 3];
*v11 = 0.0;
*((_QWORD *)v11 + 1) = malloc(8LL * (v10 + 1));
v12 = v2[3 * NumBins + 4];
if ( v12 == 0.0 )
goto LABEL_13;
if ( NumSamples >= 0 )
memset(*(void **)&v12, 0, 8LL * NumSamples + 8);
return v2;
}

canonical_decompiled_code:
double *__fastcall func0(double a1, double a2)
{
double *v2; // r12
int v3; // eax
double *v4; // rbx
int v5; // ebp
double v6; // r14
double v7; // xmm0_8
size_t v8; // rdi
void *v9; // rax
int v10; // er13
double *v11; // rbx
double v12; // rdi

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( !v2 )
{
puts("Failed to allocate memory in binBuild");
return v2;
}
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = v2;
v5 = 0;
v6 = a1 / a2;
while ( 1 )
{
*v4 = pow(v6, ((double)v5 + (double)v5) / (double)v3) * (a2 * a2);
v7 = pow(v6, ((double)v5 - 0.5) / (double)NumBins);
v8 = 8LL * (NumSamples + 1);
v4[2] = v7 * a2;
v9 = malloc(v8);
*((_QWORD *)v4 + 1) = v9;
if ( !v9 )
break;
v10 = NumSamples;
if ( NumSamples >= 0 )
memset(v9, 0, 8LL * NumSamples + 8);
v3 = NumBins;
++v5;
v4 += 3;
if ( NumBins < v5 )
goto LABEL_8;
}
LABEL_13:
v2 = 0LL;
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return v2;
}
v10 = NumSamples;
LABEL_8:
v11 = &v2[3 * v3 + 3];
*v11 = 0.0;
*((_QWORD *)v11 + 1) = malloc(8LL * (v10 + 1));
v12 = v2[3 * NumBins + 4];
if ( v12 == 0.0 )
goto LABEL_13;
if ( NumSamples >= 0 )
memset(*(void **)&v12, 0, 8LL * NumSamples + 8);
return v2;
}

original_code:
bin *binBuildSpatial(double minDist,double maxDist){
 int i,j;
 bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = maxDist*maxDist*pow(minDist/maxDist,(2.*(double)i)/((double)NumBins));
  bins[i].center = maxDist*pow(minDist/maxDist,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 0.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

canonical_original_code:
struct _bin *binBuildSpatial(double minDist, double maxDist){
 int i; int j;
 struct _bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = maxDist*maxDist*pow(minDist/maxDist,(2.*(double)i)/((double)NumBins));
  bins[i].center = maxDist*pow(minDist/maxDist,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 0.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

variable_types: minDist double

variable_types: maxDist double

variable_types: struct _bin { double limit; unsigned long long *Cnt; double center; } *


binBuildAngular

decompiled_code:
double *__fastcall binBuildAngular(double a1, double a2)
{
double *v2; // r12
int v3; // eax
double *v4; // rbx
double v5; // r14
int v6; // ebp
double v7; // xmm0_8
double v8; // xmm1_8
size_t v9; // rdi
void *v10; // rax
int v11; // er13
double *v12; // rbx
double v13; // rdi

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( !v2 )
{
puts("Failed to allocate memory in buildbins");
return v2;
}
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = v2;
v5 = a1 / a2;
v6 = 0;
while ( 1 )
{
v7 = pow(v5, (double)v6 / (double)v3);
*v4 = cos(v7 * a2);
v8 = pow(v5, ((double)v6 - 0.5) / (double)NumBins);
v9 = 8LL * (NumSamples + 1);
v4[2] = 57.29577951308232 * a2 * v8;
v10 = malloc(v9);
*((_QWORD *)v4 + 1) = v10;
if ( !v10 )
break;
v11 = NumSamples;
if ( NumSamples >= 0 )
memset(v10, 0, 8LL * NumSamples + 8);
v3 = NumBins;
++v6;
v4 += 3;
if ( NumBins < v6 )
goto LABEL_8;
}
LABEL_13:
v2 = 0LL;
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return v2;
}
v11 = NumSamples;
LABEL_8:
v12 = &v2[3 * v3 + 3];
*(_QWORD *)v12 = LC6;
*((_QWORD *)v12 + 1) = malloc(8LL * (v11 + 1));
v13 = v2[3 * NumBins + 4];
if ( v13 == 0.0 )
goto LABEL_13;
if ( NumSamples >= 0 )
memset(*(void **)&v13, 0, 8LL * NumSamples + 8);
return v2;
}

canonical_decompiled_code:
double *__fastcall func1(double a1, double a2)
{
double *v2; // r12
int v3; // eax
double *v4; // rbx
double v5; // r14
int v6; // ebp
double v7; // xmm0_8
double v8; // xmm1_8
size_t v9; // rdi
void *v10; // rax
int v11; // er13
double *v12; // rbx
double v13; // rdi

v2 = (double *)malloc(24LL * (NumBins + 2));
if ( !v2 )
{
puts("Failed to allocate memory in buildbins");
return v2;
}
v3 = NumBins;
if ( NumBins >= 0 )
{
v4 = v2;
v5 = a1 / a2;
v6 = 0;
while ( 1 )
{
v7 = pow(v5, (double)v6 / (double)v3);
*v4 = cos(v7 * a2);
v8 = pow(v5, ((double)v6 - 0.5) / (double)NumBins);
v9 = 8LL * (NumSamples + 1);
v4[2] = 57.29577951308232 * a2 * v8;
v10 = malloc(v9);
*((_QWORD *)v4 + 1) = v10;
if ( !v10 )
break;
v11 = NumSamples;
if ( NumSamples >= 0 )
memset(v10, 0, 8LL * NumSamples + 8);
v3 = NumBins;
++v6;
v4 += 3;
if ( NumBins < v6 )
goto LABEL_8;
}
LABEL_13:
v2 = 0LL;
fwrite("Failed to allocate sample space in binBuild\n", 1uLL, 0x2CuLL, stderr);
return v2;
}
v11 = NumSamples;
LABEL_8:
v12 = &v2[3 * v3 + 3];
*(_QWORD *)v12 = LC6;
*((_QWORD *)v12 + 1) = malloc(8LL * (v11 + 1));
v13 = v2[3 * NumBins + 4];
if ( v13 == 0.0 )
goto LABEL_13;
if ( NumSamples >= 0 )
memset(*(void **)&v13, 0, 8LL * NumSamples + 8);
return v2;
}

original_code:
bin *binBuildAngular(double minAngle,double maxAngle){
 int i,j;
 bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in buildbins\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = cos(maxAngle*pow(minAngle/maxAngle,((double)i)/((double)NumBins)));
  bins[i].center = 180./3.14159265358979323846*maxAngle*pow(minAngle/maxAngle,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 2.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long int));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

canonical_original_code:
struct _bin *binBuildAngular(double minAngle, double maxAngle){
 int i; int j;
 struct _bin *bins;
 ;
 bins = malloc((NumBins+2)*sizeof(bin));
 if(bins == ((void *)0)){
  printf("Failed to allocate memory in buildbins\n");
  return ((void *)0);
 }
 for(i=0;i<=NumBins;i++){
  bins[i].limit = cos(maxAngle*pow(minAngle/maxAngle,((double)i)/((double)NumBins)));
  bins[i].center = 180./3.14159265358979323846*maxAngle*pow(minAngle/maxAngle,((double)i-0.5)/((double)NumBins));
  bins[i].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
  if(bins[i].Cnt == ((void *)0)){
   fprintf(stderr,"Failed to allocate sample space in binBuild\n");
   return ((void *)0);
  }
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 bins[NumBins+1].limit = 2.;
 bins[NumBins+1].Cnt = malloc((NumSamples+1)*sizeof(unsigned long long));
 if(bins[NumBins+1].Cnt == ((void *)0)){
  fprintf(stderr,"Failed to allocate sample space in binBuild\n");
  return ((void *)0);
 }
 for(i=0;i<=NumSamples;i++){
  bins[NumBins+1].Cnt[i] = 0;
 }
 ;
 return bins;
}

variable_types: minAngle double

variable_types: maxAngle double

return_type: struct _bin { double limit; unsigned long long *Cnt; double center; } *


binClear

decompiled_code:
void *__fastcall binClear(__int64 a1)
{
void *result; // rax
__int64 v2; // r12
void **v3; // rbx
int v4; // ebp
size_t v5; // r13

result = (void *)NumBins;
if ( NumBins >= -1 )
{
v2 = a1 + 24LL * (unsigned int)(NumBins + 1) + 32;
v3 = (void **)(a1 + 8);
v4 = NumSamples;
result = (void *)NumSamples;
v5 = 8LL * NumSamples + 8;
do
{
if ( v4 >= 0 )
result = memset(*v3, 0, v5);
v3 += 3;
}
while ( (void **)v2 != v3 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1)
{
void *result; // rax
__int64 v2; // r12
void **v3; // rbx
int v4; // ebp
size_t v5; // r13

result = (void *)NumBins;
if ( NumBins >= -1 )
{
v2 = a1 + 24LL * (unsigned int)(NumBins + 1) + 32;
v3 = (void **)(a1 + 8);
v4 = NumSamples;
result = (void *)NumSamples;
v5 = 8LL * NumSamples + 8;
do
{
if ( v4 >= 0 )
result = memset(*v3, 0, v5);
v3 += 3;
}
while ( (void **)v2 != v3 );
}
return result;
}

original_code:
void binClear(bin bins[]){
 int i,j;
 for(i=0;i<=NumBins+1;i++){
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 return;
}

canonical_original_code:
void binClear(struct _bin bins[]){
 int i; int j;
 for(i=0;i<=NumBins+1;i++){
  for(j=0;j<=NumSamples;j++){
   bins[i].Cnt[j] = 0;
  }
 }
 return;
}

variable_types: struct _bin { double limit; unsigned long long *Cnt; double center; } []


binFree

decompiled_code:
void __fastcall binFree(void *ptr)
{
void **v2; // rbp
int v3; // ebx
void *v4; // rdi
int v5; // eax

if ( NumBins >= -1 )
{
v2 = (void **)((char *)ptr + 8);
v3 = 0;
do
{
v4 = *v2;
v2 += 3;
free(v4);
v5 = v3++;
}
while ( NumBins >= v5 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void **v2; // rbp
int v3; // ebx
void *v4; // rdi
int v5; // eax

if ( NumBins >= -1 )
{
v2 = (void **)((char *)ptr + 8);
v3 = 0;
do
{
v4 = *v2;
v2 += 3;
free(v4);
v5 = v3++;
}
while ( NumBins >= v5 );
}
free(ptr);
}

original_code:
void binFree(bin *bins){
 int i;
 for(i=0;i<=NumBins+1;i++){
  free(bins[i].Cnt);
 }
 free(bins);
 return;
}

canonical_original_code:
void binFree(struct _bin *bins){
 int i;
 for(i=0;i<=NumBins+1;i++){
  free(bins[i].Cnt);
 }
 free(bins);
 return;
}

user_defined_types: struct _bin { double limit; unsigned long long *Cnt; double center; }


spaTreeFill

decompiled_code:
__int64 __fastcall spaTreeFill(__int64 a1)
{
__int64 v1; // r12
__int64 result; // rax
__int64 v3; // rax

v1 = a1 + 80LL * NodePos;
if ( *(_DWORD *)(v1 + 64) == 1 )
{
++NodePos;
v3 = ((__int64 (*)(void))spaTreeFill)();
++NodePos;
*(_QWORD *)(v1 + 64) = v3;
*(_QWORD *)(v1 + 72) = spaTreeFill(a1);
result = v1;
}
else
{
*(_QWORD *)(v1 + 64) = 0LL;
result = v1;
*(_QWORD *)(v1 + 72) = 0LL;
}
return result;
}

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

v1 = a1 + 80LL * NodePos;
if ( *(_DWORD *)(v1 + 64) == 1 )
{
++NodePos;
v3 = ((__int64 (*)(void))spaTreeFill)();
++NodePos;
*(_QWORD *)(v1 + 64) = v3;
*(_QWORD *)(v1 + 72) = func0(a1);
result = v1;
}
else
{
*(_QWORD *)(v1 + 64) = 0LL;
result = v1;
*(_QWORD *)(v1 + 72) = 0LL;
}
return result;
}

original_code:
static spaTreeNode *spaTreeFill(spaTreeNode *root){
 spaTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = spaTreeFill(root);
  NodePos++;
  node->rptr = spaTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

canonical_original_code:
static struct _spaTreeNode *spaTreeFill(struct _spaTreeNode *root){
 struct _spaTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = spaTreeFill(root);
  NodePos++;
  node->rptr = spaTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

variable_types:
root
struct _spaTreeNode *

variable_types: struct _spaTreeNode { int Sample; int Cnt; int Start; int End; double xmin; struct _spaTreeNode *lptr; struct _spaTreeNode *rptr; } *


angTreeFill

decompiled_code:
__int64 __fastcall angTreeFill(__int64 a1)
{
__int64 v1; // r12
__int64 result; // rax
__int64 v3; // rax

v1 = a1 + 80LL * NodePos;
if ( *(_DWORD *)(v1 + 64) == 1 )
{
++NodePos;
v3 = ((__int64 (*)(void))angTreeFill)();
++NodePos;
*(_QWORD *)(v1 + 64) = v3;
*(_QWORD *)(v1 + 72) = angTreeFill(a1);
result = v1;
}
else
{
*(_QWORD *)(v1 + 64) = 0LL;
result = v1;
*(_QWORD *)(v1 + 72) = 0LL;
}
return result;
}

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

v1 = a1 + 80LL * NodePos;
if ( *(_DWORD *)(v1 + 64) == 1 )
{
++NodePos;
v3 = ((__int64 (*)(void))angTreeFill)();
++NodePos;
*(_QWORD *)(v1 + 64) = v3;
*(_QWORD *)(v1 + 72) = func1(a1);
result = v1;
}
else
{
*(_QWORD *)(v1 + 64) = 0LL;
result = v1;
*(_QWORD *)(v1 + 72) = 0LL;
}
return result;
}

original_code:
static angTreeNode *angTreeFill(angTreeNode *root){
 angTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = angTreeFill(root);
  NodePos++;
  node->rptr = angTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

canonical_original_code:
static struct _angTreeNode *angTreeFill(struct _angTreeNode *root){
 struct _angTreeNode *node;
 node = root+NodePos;
 if((int)node->lptr == 1){
  NodePos++;
  node->lptr = angTreeFill(root);
  NodePos++;
  node->rptr = angTreeFill(root);
 }else{
  node->lptr = ((void *)0);
  node->rptr = ((void *)0);
 }
 return node;
}

variable_types:
root
struct _angTreeNode *

variable_types: struct _angTreeNode { int Sample; int Cnt; int Start; int End; double x; double clowbound; struct _angTreeNode *lptr; struct _angTreeNode *rptr; } *


treeGetMemory

decompiled_code:
void *__fastcall treeGetMemory(void **a1, _QWORD *a2, const char *a3)
{
size_t v3; // rbp
void *result; // rax

v3 = (int)(80 * getMaxTreesize(a3));
*a1 = malloc(v3);
result = malloc(v3);
*a2 = result;
if ( !*a1 || !result )
{
fwrite("Failed to allocate tree space\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void **a1, _QWORD *a2, const char *a3)
{
size_t v3; // rbp
void *result; // rax

v3 = (int)(80 * func2(a3));
*a1 = malloc(v3);
result = malloc(v3);
*a2 = result;
if ( !*a1 || !result )
{
fwrite("Failed to allocate tree space\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
return result;
}

original_code:
void treeGetMemory(void **block1, void **block2, char *filelist){
 int max,nodesize;
 max = getMaxTreesize(filelist);
 if(AngOrSpa == 0){
  nodesize = sizeof(angTreeNode);
 }else{
  nodesize = sizeof(spaTreeNode);
 }
 *block1 = malloc(max*nodesize);
 *block2 = malloc(max*nodesize);
 if(*block1 == ((void *)0) || *block2 == ((void *)0)){
  fprintf(stderr,"Failed to allocate tree space\n");
  exit(1);
 }
 return;
}

canonical_original_code:
void treeGetMemory(void **block1, void **block2, char *filelist){
 int max; int nodesize;
 max = getMaxTreesize(filelist);
 if(AngOrSpa == 0){
  nodesize = sizeof(angTreeNode);
 }else{
  nodesize = sizeof(spaTreeNode);
 }
 *block1 = malloc(max*nodesize);
 *block2 = malloc(max*nodesize);
 if(*block1 == ((void *)0) || *block2 == ((void *)0)){
  fprintf(stderr,"Failed to allocate tree space\n");
  exit(1);
 }
 return;
}

variable_types:
filelist
char *

variable_types: max int

variable_types: nodesize int


reportTimings

decompiled_code:
int reportTimings()
{
fprintf(stdout, "Total Walltime (s):\t%f\n\n", *(double *)&wallTimeTotal);
fprintf(stdout, "\tAC - %f\t\t%f\n", *(double *)&wallTimeAC, *(double *)&wallTimeAC / *(double *)&wallTimeTotal);
fprintf(stdout, "\tCC - %f\t\t%f\n", *(double *)&wallTimeCC, *(double *)&wallTimeCC / *(double *)&wallTimeTotal);
fprintf(
stdout,
"\tData Read - %f\t%f\n",
*(double *)&wallDataRead,
*(double *)&wallDataRead / *(double *)&wallTimeTotal);
return fprintf(
stdout,
"\tTree Read - %f\t%f\n",
*(double *)&wallTreeRead,
*(double *)&wallTreeRead / *(double *)&wallTimeTotal);
}

canonical_decompiled_code:
int func1()
{
fprintf(stdout, "Total Walltime (s):\t%f\n\n", *(double *)&wallTimeTotal);
fprintf(stdout, "\tAC - %f\t\t%f\n", *(double *)&wallTimeAC, *(double *)&wallTimeAC / *(double *)&wallTimeTotal);
fprintf(stdout, "\tCC - %f\t\t%f\n", *(double *)&wallTimeCC, *(double *)&wallTimeCC / *(double *)&wallTimeTotal);
fprintf(
stdout,
"\tData Read - %f\t%f\n",
*(double *)&wallDataRead,
*(double *)&wallDataRead / *(double *)&wallTimeTotal);
return fprintf(
stdout,
"\tTree Read - %f\t%f\n",
*(double *)&wallTreeRead,
*(double *)&wallTreeRead / *(double *)&wallTimeTotal);
}

original_code:
void reportTimings(){
  fprintf(stdout,"Total Walltime (s):\t%f\n\n",wallTimeTotal);
  fprintf(stdout,"\tAC - %f\t\t%f\n",wallTimeAC,wallTimeAC/wallTimeTotal);
  fprintf(stdout,"\tCC - %f\t\t%f\n",wallTimeCC,wallTimeCC/wallTimeTotal);
  fprintf(stdout,"\tData Read - %f\t%f\n",wallDataRead,wallDataRead/wallTimeTotal);
  fprintf(stdout,"\tTree Read - %f\t%f\n",wallTreeRead,wallTreeRead/wallTimeTotal);
 return;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r14
int v5; // eax
void *v6; // rsp
__int64 **v7; // r15
__int64 **v8; // rbx
char *v9; // rax
const char *v10; // rsi
char *v11; // rdi
double v12; // xmm0_8
__int64 v13; // rax
int v14; // eax
int v15; // er13
__int64 v16; // xmm1_8
__int64 v17; // r8
__int64 v18; // r8
double v19; // xmm0_8
int v20; // edi
unsigned int v21; // edx
int v22; // ecx
double *v23; // rax
char v24; // r9
double v25; // xmm0_8
int v26; // er15
void *v27; // rsp
__int64 **v28; // r14
void *v29; // rsp
double v30; // xmm0_8
__int64 *v31; // rdi
__int64 **v32; // rdi
int result; // eax
void *v34; // rsp
void *v35; // rsp
void *v36; // rax
double v37; // xmm2_8
double v38; // xmm0_8
__int64 **i; // rax
double v40; // xmm1_8
void *v41; // rdi
size_t v42; // rsi
void *v43; // rax
char *v44; // rsi
__int64 v45; // r13
const char *v46; // rsi
void *v47; // rax
char *v48; // r14
const char *v49; // rsi
char *v50; // rcx
int v51; // eax
double v52; // xmm2_8
char *v53; // rdx
double v54; // xmm0_8
__int64 *v55; // [rsp+0h] [rbp-60h] BYREF
unsigned int v56; // [rsp+Ch] [rbp-54h]
__int64 **v57; // [rsp+10h] [rbp-50h]
__int64 **v58; // [rsp+18h] [rbp-48h]
double v59; // [rsp+20h] [rbp-40h]
double v60; // [rsp+28h] [rbp-38h]

LOBYTE(v57) = argc <= 4 || (argc & 1) == 0;
if ( (_BYTE)v57 || !strcmp(argv[1], "-?") )
{
puts(
"Insufficient number of arguments! (or -?)\n"
"Enter at least two pairs of a name followed by a number.\n"
"E.g.:\n"
" $ split foo 2.30 bar 4.20");
result = 1;
}
else
{
*(_QWORD *)&v60 = 1LL;
v4 = 3LL;
::i = 0;
v5 = (argc - 1) >> 1;
perscount = v5;
v58 = (__int64 **)(unsigned int)(v5 + 1);
j = 1;
v6 = alloca(24LL * v5);
v7 = &v55;
v59 = COERCE_DOUBLE(&v55);
v8 = &v55;
do
{
strcpy(floatbuffer, argv[v4 - 1]);
v9 = floatbuffer;
do
{
if ( *v9 == 44 )
*v9 = 46;
++v9;
}
while ( &unk_4040AA != (_UNKNOWN *)v9 );
v10 = argv[v4 - 2];
v11 = (char *)v7;
k = 6;
v7 += 3;
strcpy(v11, v10);
v12 = atof(floatbuffer);
v13 = *(_QWORD *)&v60;
j = v4;
v4 += 2LL;
*((double *)v7 - 1) = v12;
::i = v13;
*(_QWORD *)&v60 = v13 + 1;
}
while ( v58 != (__int64 **)(v13 + 1) );
::i = 0;
v14 = 0;
do
{
printf("\n%6.2f %s", *(double *)(*(_QWORD *)&v59 + 24LL * v14 + 16), (const char *)(*(_QWORD *)&v59 + 24LL * v14));
v15 = perscount;
v14 = ::i + 1;
::i = v14;
}
while ( v14 < perscount );
*(double *)&v16 = avg(*(_QWORD *)&v59, perscount);
average = v16;
v19 = calctotal(v17, *(double *)&v16, *(double *)&v16);
v20 = givecount;
v21 = getcount;
::i = 0;
total = *(_QWORD *)&v19;
v56 = getcount;
v22 = givecount;
if ( v15 > 0 )
{
v23 = (double *)(v18 + 16);
v24 = 0;
do
{
v25 = *v23;
if ( *v23 > *(double *)&v16 )
{
LOBYTE(v57) = 1;
++v21;
}
if ( *(double *)&v16 > v25 )
{
++v22;
v24 = 1;
}
v23 += 3;
}
while ( (double *)(v18 + 24LL * (unsigned int)(v15 - 1) + 40) != v23 );
if ( (_BYTE)v57 )
{
getcount = v21;
v56 = v21;
}
if ( v24 )
{
givecount = v22;
v20 = v22;
}
v55 = (__int64 *)&v55;
v26 = 1;
givei = v20;
::i = 0;
geti = v56;
v27 = alloca(24LL * (int)v56);
v28 = &v55;
v58 = &v55;
v29 = alloca(24LL * v20);
v57 = &v55;
while ( 1 )
{
v30 = *((double *)v8 + 2);
if ( v30 <= *(double *)&v16 )
{
if ( *(double *)&v16 <= v30 )
goto LABEL_24;
}
else
{
v59 = *(double *)&v16;
v60 = v30;
v31 = (__int64 *)&v58[3 * --geti];
*((double *)v31 + 2) = v30;
strcpy((char *)v31, (const char *)v8);
*(double *)&v16 = v59;
v30 = v60;
if ( v59 <= v60 )
goto LABEL_24;
}
v60 = *(double *)&v16;
v32 = &v57[3 * --givei];
*((double *)v32 + 2) = v30;
strcpy((char *)v32, (const char *)v8);
*(double *)&v16 = v60;
LABEL_24:
::i = v26;
v8 += 3;
if ( v26 == v15 )
goto LABEL_31;
++v26;
}
}
v55 = (__int64 *)&v55;
givei = givecount;
geti = v56;
v34 = alloca(24LL * (int)v56);
v28 = &v55;
v35 = alloca(24LL * givecount);
LABEL_31:
calcdiff(&v55, v56, *(double *)&v16);
calcdiff(&v55, (unsigned int)givecount, *(double *)&average);
sortdesc(&v55, getcount);
sortdesc(&v55, givecount);
v36 = malloc(0LL);
giveptr = (char *)&v55;
v37 = 0.0;
transact = v36;
getptr = (char *)&v55;
for ( ::i = 0; ::i < getcount; ++::i )
{
v38 = *((double *)v28 + 2);
for ( i = &v55; ; i = (__int64 **)giveptr )
{
v40 = *((double *)i + 2);
if ( v40 == v37 )
{
giveptr = (char *)(i + 3);
}
else
{
v41 = transact;
v60 = v37;
v42 = 32LL * ++transactcount;
if ( v38 <= v40 )
{
*((double *)i + 2) = v40 - v38;
v47 = realloc(v41, v42);
v48 = getptr;
v49 = giveptr;
transact = v47;
v45 = (__int64)v47 + 32 * transactcount - 32;
*(_QWORD *)(v45 + 24) = *((_QWORD *)getptr + 2);
*((_QWORD *)v48 + 2) = 0LL;
transactptr = v45;
strcpy((char *)(v45 + 11), v49);
v46 = v48;
}
else
{
*((double *)v28 + 2) = v38 - v40;
v43 = realloc(v41, v42);
v44 = giveptr;
transact = v43;
v45 = (__int64)v43 + 32 * transactcount - 32;
*(_QWORD *)(v45 + 24) = *((_QWORD *)giveptr + 2);
*((_QWORD *)v44 + 2) = 0LL;
transactptr = v45;
strcpy((char *)(v45 + 11), v44);
v46 = getptr;
}
strcpy((char *)v45, v46);
v28 = (__int64 **)getptr;
v37 = v60;
v38 = *((double *)getptr + 2);
}
if ( v38 == v37 )
break;
}
v28 += 3;
giveptr = (char *)&v55;
getptr = (char *)v28;
}
printf("\n\nTotal: %6.2f\nAverage: %6.2f\n\nResult:\n", *(double *)&total, *(double *)&average);
::i = 0;
if ( transactcount > 0 )
{
v50 = (char *)transact;
v51 = 0;
v52 = 0.0;
do
{
v53 = &v50[32 * v51];
v54 = *((double *)v53 + 3);
if ( v54 != v52 )
{
v60 = v52;
printf("%s > %.2f > %s\n", v53 + 11, v54, v53);
v50 = (char *)transact;
v52 = v60;
}
v51 = ++::i;
}
while ( ::i < transactcount );
}
free(transact);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r14
int v5; // eax
void *v6; // rsp
__int64 **v7; // r15
__int64 **v8; // rbx
char *v9; // rax
const char *v10; // rsi
char *v11; // rdi
double v12; // xmm0_8
__int64 v13; // rax
int v14; // eax
int v15; // er13
__int64 v16; // xmm1_8
__int64 v17; // r8
__int64 v18; // r8
double v19; // xmm0_8
int v20; // edi
unsigned int v21; // edx
int v22; // ecx
double *v23; // rax
char v24; // r9
double v25; // xmm0_8
int v26; // er15
void *v27; // rsp
__int64 **v28; // r14
void *v29; // rsp
double v30; // xmm0_8
__int64 *v31; // rdi
__int64 **v32; // rdi
int result; // eax
void *v34; // rsp
void *v35; // rsp
void *v36; // rax
double v37; // xmm2_8
double v38; // xmm0_8
__int64 **i; // rax
double v40; // xmm1_8
void *v41; // rdi
size_t v42; // rsi
void *v43; // rax
char *v44; // rsi
__int64 v45; // r13
const char *v46; // rsi
void *v47; // rax
char *v48; // r14
const char *v49; // rsi
char *v50; // rcx
int v51; // eax
double v52; // xmm2_8
char *v53; // rdx
double v54; // xmm0_8
__int64 *v55; // [rsp+0h] [rbp-60h] BYREF
unsigned int v56; // [rsp+Ch] [rbp-54h]
__int64 **v57; // [rsp+10h] [rbp-50h]
__int64 **v58; // [rsp+18h] [rbp-48h]
double v59; // [rsp+20h] [rbp-40h]
double v60; // [rsp+28h] [rbp-38h]

LOBYTE(v57) = argc <= 4 || (argc & 1) == 0;
if ( (_BYTE)v57 || !strcmp(argv[1], "-?") )
{
puts(
"Insufficient number of arguments! (or -?)\n"
"Enter at least two pairs of a name followed by a number.\n"
"E.g.:\n"
" $ split foo 2.30 bar 4.20");
result = 1;
}
else
{
*(_QWORD *)&v60 = 1LL;
v4 = 3LL;
::i = 0;
v5 = (argc - 1) >> 1;
perscount = v5;
v58 = (__int64 **)(unsigned int)(v5 + 1);
j = 1;
v6 = alloca(24LL * v5);
v7 = &v55;
v59 = COERCE_DOUBLE(&v55);
v8 = &v55;
do
{
strcpy(floatbuffer, argv[v4 - 1]);
v9 = floatbuffer;
do
{
if ( *v9 == 44 )
*v9 = 46;
++v9;
}
while ( &unk_4040AA != (_UNKNOWN *)v9 );
v10 = argv[v4 - 2];
v11 = (char *)v7;
k = 6;
v7 += 3;
strcpy(v11, v10);
v12 = atof(floatbuffer);
v13 = *(_QWORD *)&v60;
j = v4;
v4 += 2LL;
*((double *)v7 - 1) = v12;
::i = v13;
*(_QWORD *)&v60 = v13 + 1;
}
while ( v58 != (__int64 **)(v13 + 1) );
::i = 0;
v14 = 0;
do
{
printf("\n%6.2f %s", *(double *)(*(_QWORD *)&v59 + 24LL * v14 + 16), (const char *)(*(_QWORD *)&v59 + 24LL * v14));
v15 = perscount;
v14 = ::i + 1;
::i = v14;
}
while ( v14 < perscount );
*(double *)&v16 = func7(*(_QWORD *)&v59, perscount);
average = v16;
v19 = func8(v17, *(double *)&v16, *(double *)&v16);
v20 = givecount;
v21 = getcount;
::i = 0;
total = *(_QWORD *)&v19;
v56 = getcount;
v22 = givecount;
if ( v15 > 0 )
{
v23 = (double *)(v18 + 16);
v24 = 0;
do
{
v25 = *v23;
if ( *v23 > *(double *)&v16 )
{
LOBYTE(v57) = 1;
++v21;
}
if ( *(double *)&v16 > v25 )
{
++v22;
v24 = 1;
}
v23 += 3;
}
while ( (double *)(v18 + 24LL * (unsigned int)(v15 - 1) + 40) != v23 );
if ( (_BYTE)v57 )
{
getcount = v21;
v56 = v21;
}
if ( v24 )
{
givecount = v22;
v20 = v22;
}
v55 = (__int64 *)&v55;
v26 = 1;
givei = v20;
::i = 0;
geti = v56;
v27 = alloca(24LL * (int)v56);
v28 = &v55;
v58 = &v55;
v29 = alloca(24LL * v20);
v57 = &v55;
while ( 1 )
{
v30 = *((double *)v8 + 2);
if ( v30 <= *(double *)&v16 )
{
if ( *(double *)&v16 <= v30 )
goto LABEL_24;
}
else
{
v59 = *(double *)&v16;
v60 = v30;
v31 = (__int64 *)&v58[3 * --geti];
*((double *)v31 + 2) = v30;
strcpy((char *)v31, (const char *)v8);
*(double *)&v16 = v59;
v30 = v60;
if ( v59 <= v60 )
goto LABEL_24;
}
v60 = *(double *)&v16;
v32 = &v57[3 * --givei];
*((double *)v32 + 2) = v30;
strcpy((char *)v32, (const char *)v8);
*(double *)&v16 = v60;
LABEL_24:
::i = v26;
v8 += 3;
if ( v26 == v15 )
goto LABEL_31;
++v26;
}
}
v55 = (__int64 *)&v55;
givei = givecount;
geti = v56;
v34 = alloca(24LL * (int)v56);
v28 = &v55;
v35 = alloca(24LL * givecount);
LABEL_31:
func9(&v55, v56, *(double *)&v16);
func9(&v55, (unsigned int)givecount, *(double *)&average);
func10(&v55, getcount);
func10(&v55, givecount);
v36 = malloc(0LL);
giveptr = (char *)&v55;
v37 = 0.0;
transact = v36;
getptr = (char *)&v55;
for ( ::i = 0; ::i < getcount; ++::i )
{
v38 = *((double *)v28 + 2);
for ( i = &v55; ; i = (__int64 **)giveptr )
{
v40 = *((double *)i + 2);
if ( v40 == v37 )
{
giveptr = (char *)(i + 3);
}
else
{
v41 = transact;
v60 = v37;
v42 = 32LL * ++transactcount;
if ( v38 <= v40 )
{
*((double *)i + 2) = v40 - v38;
v47 = realloc(v41, v42);
v48 = getptr;
v49 = giveptr;
transact = v47;
v45 = (__int64)v47 + 32 * transactcount - 32;
*(_QWORD *)(v45 + 24) = *((_QWORD *)getptr + 2);
*((_QWORD *)v48 + 2) = 0LL;
transactptr = v45;
strcpy((char *)(v45 + 11), v49);
v46 = v48;
}
else
{
*((double *)v28 + 2) = v38 - v40;
v43 = realloc(v41, v42);
v44 = giveptr;
transact = v43;
v45 = (__int64)v43 + 32 * transactcount - 32;
*(_QWORD *)(v45 + 24) = *((_QWORD *)giveptr + 2);
*((_QWORD *)v44 + 2) = 0LL;
transactptr = v45;
strcpy((char *)(v45 + 11), v44);
v46 = getptr;
}
strcpy((char *)v45, v46);
v28 = (__int64 **)getptr;
v37 = v60;
v38 = *((double *)getptr + 2);
}
if ( v38 == v37 )
break;
}
v28 += 3;
giveptr = (char *)&v55;
getptr = (char *)v28;
}
printf("\n\nTotal: %6.2f\nAverage: %6.2f\n\nResult:\n", *(double *)&total, *(double *)&average);
::i = 0;
if ( transactcount > 0 )
{
v50 = (char *)transact;
v51 = 0;
v52 = 0.0;
do
{
v53 = &v50[32 * v51];
v54 = *((double *)v53 + 3);
if ( v54 != v52 )
{
v60 = v52;
printf("%s > %.2f > %s\n", v53 + 11, v54, v53);
v50 = (char *)transact;
v52 = v60;
}
v51 = ++::i;
}
while ( ::i < transactcount );
}
free(transact);
result = 0;
}
return result;
}

original_code:
int main(int argc, char * argv[]){
 if(argc%2 == 0 || argc < 5 || !strcmp(argv[1], "-?")){
  puts("Insufficient number of arguments! (or -?)\nEnter at least two pairs of a name followed by a number.\nE.g.:\n $ split foo 2.30 bar 4.20");
  return 1;
 }
 perscount = (argc-1)/2;
 struct person data[perscount];
 for(i=0, j=1;i < perscount;i++, j+=2){
  strcpy(floatbuffer, argv[j+1]);
  for(k=0;k < 6;k++)
   if(floatbuffer[k] == ',')
    floatbuffer[k] = '.';
  strcpy(data[i].name, argv[j]);
  data[i].amount = atof(floatbuffer);
 }
 for(i=0;i<perscount;i++)
  printf("\n%" "6.2" "f %s", data[i].amount, data[i].name);
 average = avg(data, perscount);
 total = calctotal(data,perscount);
 for(i=0;i<perscount;i++){
  if(data[i].amount > average)
   getcount++;
  if(data[i].amount < average)
   givecount++;
 }
 struct person get[getcount];
 struct person give[givecount];
 geti = getcount; givei = givecount;
 for(i=0;i<perscount;i++){
  if(data[i].amount > average){
   geti--;
   get[geti].amount = data[i].amount;
   strcpy(get[geti].name, data[i].name);
  }
  if(data[i].amount < average){
   givei--;
   give[givei].amount = data[i].amount;
   strcpy(give[givei].name, data[i].name);
  }
 }
 calcdiff(get, getcount, average);
 calcdiff(give, givecount, average);
 sortdesc(get, getcount);
 sortdesc(give, givecount);
 transact = (struct transaction *) malloc(0);
 giveptr = give;
 getptr = get;
 for(i = 0; i < getcount; i++, getptr++, giveptr = give){
  do{
   if(!giveptr->amount)
    giveptr++;
   else if(getptr->amount > giveptr->amount){
    getptr->amount -= giveptr->amount;
    transact = (struct transaction *) realloc(transact, ++transactcount * sizeof(struct transaction));
    transactptr = transact + (transactcount - 1);
    transactptr->amount = giveptr->amount;
    giveptr->amount = 0;
    strcpy(transactptr->give, giveptr->name);
    strcpy(transactptr->get, getptr->name);
   }
   else{
    giveptr->amount -= getptr->amount;
    transact = (struct transaction *) realloc(transact, ++transactcount * sizeof(struct transaction));
    transactptr = transact + (transactcount - 1);
    transactptr->amount = getptr->amount;
    getptr->amount = 0;
    strcpy(transactptr->give, giveptr->name);
    strcpy(transactptr->get, getptr->name);
   }
  } while (getptr->amount);
 }
 printf("\n\nTotal:   %" "6.2" "f\nAverage: %" "6.2" "f\n\nResult:\n", total, average);
 for(i=0;i<transactcount;i++)
  if(transact[i].amount)
   printf("%s > %.2f > %s\n",transact[i].give, transact[i].amount, transact[i].get);
 free(transact);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 if(argc%2 == 0 || argc < 5 || !strcmp(argv[1], "-?")){
  puts("Insufficient number of arguments! (or -?)\nEnter at least two pairs of a name followed by a number.\nE.g.:\n $ split foo 2.30 bar 4.20");
  return 1;
 }
 perscount = (argc-1)/2;
 struct person data[-1];
 for(i=0, j=1;i < perscount;i++, j+=2){
  strcpy(floatbuffer, argv[j+1]);
  for(k=0;k < 6;k++)
   if(floatbuffer[k] == ',')
    floatbuffer[k] = '.';
  strcpy(data[i].name, argv[j]);
  data[i].amount = atof(floatbuffer);
 }
 for(i=0;i<perscount;i++)
  printf("\n%" "6.2" "f %s", data[i].amount, data[i].name);
 average = avg(data, perscount);
 total = calctotal(data,perscount);
 for(i=0;i<perscount;i++){
  if(data[i].amount > average)
   getcount++;
  if(data[i].amount < average)
   givecount++;
 }
 struct person get[-1];
 struct person give[-1];
 geti = getcount; givei = givecount;
 for(i=0;i<perscount;i++){
  if(data[i].amount > average){
   geti--;
   get[geti].amount = data[i].amount;
   strcpy(get[geti].name, data[i].name);
  }
  if(data[i].amount < average){
   givei--;
   give[givei].amount = data[i].amount;
   strcpy(give[givei].name, data[i].name);
  }
 }
 calcdiff(get, getcount, average);
 calcdiff(give, givecount, average);
 sortdesc(get, getcount);
 sortdesc(give, givecount);
 transact = (struct transaction *) malloc(0);
 giveptr = give;
 getptr = get;
 for(i = 0; i < getcount; i++, getptr++, giveptr = give){
  do{
   if(!giveptr->amount)
    giveptr++;
   else if(getptr->amount > giveptr->amount){
    getptr->amount -= giveptr->amount;
    transact = (struct transaction *) realloc(transact, ++transactcount * sizeof(struct transaction));
    transactptr = transact + (transactcount - 1);
    transactptr->amount = giveptr->amount;
    giveptr->amount = 0;
    strcpy(transactptr->give, giveptr->name);
    strcpy(transactptr->get, getptr->name);
   }
   else{
    giveptr->amount -= getptr->amount;
    transact = (struct transaction *) realloc(transact, ++transactcount * sizeof(struct transaction));
    transactptr = transact + (transactcount - 1);
    transactptr->amount = getptr->amount;
    getptr->amount = 0;
    strcpy(transactptr->give, giveptr->name);
    strcpy(transactptr->get, getptr->name);
   }
  } while (getptr->amount);
 }
 printf("\n\nTotal:   %" "6.2" "f\nAverage: %" "6.2" "f\n\nResult:\n", total, average);
 for(i=0;i<transactcount;i++)
  if(transact[i].amount)
   printf("%s > %.2f > %s\n",transact[i].give, transact[i].amount, transact[i].get);
 free(transact);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct person { char name[11]; double amount; } [-1]

user_defined_types: struct transaction { char get[11]; char give[11]; double amount; }


avg

original_code:
double avg(struct person * data, size_t size){
 int count = 0;
 double total = 0;
 for(;size > 0;size--, data++){
  total += data->amount;
  count++;
 }
 return total/count;
}

canonical_original_code:
double avg(struct person *data, unsigned long size){
 int count = 0;
 double total = 0;
 for(;size > 0;size--, data++){
  total += data->amount;
  count++;
 }
 return total/count;
}

variable_types: struct person { char name[11]; double amount; } *

variable_types:
size
unsigned long

variable_types: count int

variable_types: total double


calctotal

decompiled_code:
void __fastcall calctotal(__int64 a1, __int64 a2)
{
double i; // xmm0_8

for ( i = 0.0; a2; --a2 )
{
i = i + *(double *)(a1 + 16);
a1 += 24LL;
}
}

original_code:
double calctotal(struct person * data, size_t size){
 double total = 0;
 for(;size > 0;size--, data++)
  total += data->amount;
 return total;
}

canonical_original_code:
double calctotal(struct person *data, unsigned long size){
 double total = 0;
 for(;size > 0;size--, data++)
  total += data->amount;
 return total;
}

user_defined_types: struct person { char name[11]; double amount; }


calcdiff

original_code:
void calcdiff(struct person *data, int size, double average){
 for(;size > 0;size--, data++){
  if(data->amount < average)
   data->amount = average - data->amount;
  else
   data->amount = data->amount - average;
 }
}

variable_types: size int

variable_types: average double


sortdesc

decompiled_code:
void __fastcall sortdesc(__int64 a1, __int64 a2)
{
__int64 v2; // r15
__int64 v3; // rbp
int v4; // eax
__int64 v5; // rbx
double v6; // xmm0_8
double v7; // xmm1_8
char *v8; // rax
char *v9; // rdi
char *v10; // r13
char dest[67]; // [rsp+15h] [rbp-43h] BYREF

v2 = a2 - 1;
do
{
if ( a2 == 1 )
break;
v3 = a1;
v4 = 0;
v5 = 0LL;
do
{
while ( 1 )
{
v6 = *(double *)(v3 + 16);
v7 = *(double *)(v3 + 40);
if ( v7 > v6 )
break;
++v5;
v3 += 24LL;
if ( v2 == v5 )
goto LABEL_7;
}
*(double *)(v3 + 16) = v7;
*(double *)(v3 + 40) = v6;
++v5;
v8 = stpcpy(dest, (const char *)v3);
v9 = (char *)v3;
v3 += 24LL;
v10 = v8;
strcpy(v9, (const char *)v3);
memcpy((void *)v3, dest, v10 - dest + 1);
v4 = 1;
}
while ( v2 != v5 );
LABEL_7:
;
}
while ( v4 );
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // r15
__int64 v3; // rbp
int v4; // eax
__int64 v5; // rbx
double v6; // xmm0_8
double v7; // xmm1_8
char *v8; // rax
char *v9; // rdi
char *v10; // r13
char dest[67]; // [rsp+15h] [rbp-43h] BYREF

v2 = a2 - 1;
do
{
if ( a2 == 1 )
break;
v3 = a1;
v4 = 0;
v5 = 0LL;
do
{
while ( 1 )
{
v6 = *(double *)(v3 + 16);
v7 = *(double *)(v3 + 40);
if ( v7 > v6 )
break;
++v5;
v3 += 24LL;
if ( v2 == v5 )
goto LABEL_7;
}
*(double *)(v3 + 16) = v7;
*(double *)(v3 + 40) = v6;
++v5;
v8 = stpcpy(dest, (const char *)v3);
v9 = (char *)v3;
v3 += 24LL;
v10 = v8;
strcpy(v9, (const char *)v3);
memcpy((void *)v3, dest, v10 - dest + 1);
v4 = 1;
}
while ( v2 != v5 );
LABEL_7:
;
}
while ( v4 );
}

original_code:
void sortdesc(struct person * data, size_t size){
 size_t i;
 int swapped;
 struct person * dataptr;
 double amountbuffer;
 char namebuffer[11];
 do{
  swapped = 0;
  for(i = 0, dataptr = data; i < size - 1; i++, dataptr++){
   if(dataptr->amount < (dataptr+1)->amount){
    amountbuffer = dataptr->amount;
    dataptr->amount = (dataptr+1)->amount;
    (dataptr+1)->amount = amountbuffer;
    strcpy(namebuffer, dataptr->name);
    strcpy(dataptr->name, (dataptr+1)->name);
    strcpy((dataptr+1)->name, namebuffer);
    swapped = 1;
   }
  }
 } while (swapped);
}

canonical_original_code:
void sortdesc(struct person *data, unsigned long size){
 unsigned long i;
 int swapped;
 struct person *dataptr;
 double amountbuffer;
 char namebuffer[11];
 do{
  swapped = 0;
  for(i = 0, dataptr = data; i < size - 1; i++, dataptr++){
   if(dataptr->amount < (dataptr+1)->amount){
    amountbuffer = dataptr->amount;
    dataptr->amount = (dataptr+1)->amount;
    (dataptr+1)->amount = amountbuffer;
    strcpy(namebuffer, dataptr->name);
    strcpy(dataptr->name, (dataptr+1)->name);
    strcpy((dataptr+1)->name, namebuffer);
    swapped = 1;
   }
  }
 } while (swapped);
}

variable_types:
i
unsigned long

variable_types: swapped int

variable_types: amountbuffer double

variable_types:
namebuffer
char [11]


treatment

repo: Pupilo/CubiX

decompiled_code:
__int64 __fastcall treatment(int a1)
{
if ( a1 != 3 )
{
puts("\nCubiX usage: ./main [-c | -d] filename\n-h help");
exit(0);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( a1 != 3 )
{
puts("\nCubiX usage: ./main [-c | -d] filename\n-h help");
exit(0);
}
return 1LL;
}

original_code:
int treatment(int argc, char **argv){
    if(argc == 3){
        return 1;
    }
    else
    {
       printf("\nCubiX usage: ./main [-c | -d] filename\n-h help\n");
       exit(0);
    }
}

variable_types:
argv
char **


decompiled_code:
__off_t __fastcall file_size(const char *a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) )
{
perror("Opening the file");
result = 0LL;
}
else
{
printf("O arquivo %s possui %ld bytes\n", a1, v2.st_size);
result = v2.st_size;
}
return result;
}

canonical_decompiled_code:
__off_t __fastcall func1(const char *a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) )
{
perror("Opening the file");
result = 0LL;
}
else
{
printf("O arquivo %s possui %ld bytes\n", a1, v2.st_size);
result = v2.st_size;
}
return result;
}

original_code:
long file_size(char *argv){
    struct stat st;
    if (stat(argv, &st)) {
        perror("Opening the file");
        return 0;
    }
    printf ("O arquivo %s possui %ld bytes\n", argv, st.st_size);
    return st.st_size;
}

variable_types:
argv
char *

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

return_type: long

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


decompiled_code:
__int64 __fastcall calculate_matrix(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 result; // rax
__int64 v4; // rbp
double v5; // xmm0_8
double v6; // xmm0_8
int v7; // er12
double x; // [rsp+0h] [rbp-38h]
double v9; // [rsp+8h] [rbp-30h]
double iptr[4]; // [rsp+18h] [rbp-20h] BYREF

printf("1. (Qtd / 6)= %f\n", (double)((int)a1 / 6));
v1 = (double)((int)a1 / 6);
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
printf(a2SqrtQtdRaiz);
v9 = modf(v2, iptr);
printf("3. Fracionario: %f\n", v9);
x = iptr[0];
printf("4. Inteiro: %f\n", iptr[0]);
if ( v9 == 0.0 )
{
printf("5. Valor de Qtd: %f\n", x);
result = (unsigned int)(int)x;
}
else
{
printf("5. Resultado final: %d\n", (unsigned int)(int)(x + 1.0));
v4 = (unsigned int)(int)((double)(int)(x + 1.0) * (double)(int)(x + 1.0) * 6.0);
printf("6. Resultado final^2 * 6: %d\n", v4);
printf("7. Quantidade de bytes lixos inseridos:%ld\n", (int)v4 - a1);
v5 = (double)((unsigned int)v4 / 6);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = (int)v6;
printf("8. Ordem da matriz: %d X %d\n", (unsigned int)(int)v6, (unsigned int)(int)v6);
printf("9. Valor total em MB: %d\n", (unsigned int)((6 * v7 * v7) >> 10));
printf("10. Valor total de bytes para matriz: %d bytes", (unsigned int)(6 * v7 * v7));
result = (unsigned int)(int)v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 result; // rax
__int64 v4; // rbp
double v5; // xmm0_8
double v6; // xmm0_8
int v7; // er12
double x; // [rsp+0h] [rbp-38h]
double v9; // [rsp+8h] [rbp-30h]
double iptr[4]; // [rsp+18h] [rbp-20h] BYREF

printf("1. (Qtd / 6)= %f\n", (double)((int)a1 / 6));
v1 = (double)((int)a1 / 6);
if ( v1 < 0.0 )
v2 = sqrt(v1);
else
v2 = sqrt(v1);
printf(a2SqrtQtdRaiz);
v9 = modf(v2, iptr);
printf("3. Fracionario: %f\n", v9);
x = iptr[0];
printf("4. Inteiro: %f\n", iptr[0]);
if ( v9 == 0.0 )
{
printf("5. Valor de Qtd: %f\n", x);
result = (unsigned int)(int)x;
}
else
{
printf("5. Resultado final: %d\n", (unsigned int)(int)(x + 1.0));
v4 = (unsigned int)(int)((double)(int)(x + 1.0) * (double)(int)(x + 1.0) * 6.0);
printf("6. Resultado final^2 * 6: %d\n", v4);
printf("7. Quantidade de bytes lixos inseridos:%ld\n", (int)v4 - a1);
v5 = (double)((unsigned int)v4 / 6);
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
v7 = (int)v6;
printf("8. Ordem da matriz: %d X %d\n", (unsigned int)(int)v6, (unsigned int)(int)v6);
printf("9. Valor total em MB: %d\n", (unsigned int)((6 * v7 * v7) >> 10));
printf("10. Valor total de bytes para matriz: %d bytes", (unsigned int)(6 * v7 * v7));
result = (unsigned int)(int)v6;
}
return result;
}

original_code:
int calculate_matrix(long valor){
    double Qtd;
    double inteiro;
    double fracionario;
    int resultado;
    long final;
    Qtd = valor / 6;
    printf("1. (Qtd / 6)= %f\n", Qtd);
    Qtd = sqrt(Qtd);
    printf("2. (sqrt(Qtd)) Raiz²= %f\n", Qtd);
    fracionario = modf(Qtd, &inteiro);
    printf("3. Fracionario: %f\n", fracionario);
    printf("4. Inteiro: %f\n", inteiro);
    if (fracionario != 0){
        resultado = inteiro + 1;
        printf("5. Resultado final: %d\n",resultado);
        resultado = pow(resultado,2) * 6;
        printf("6. Resultado final^2 * 6: %d\n", resultado);
        final = resultado - valor;
        printf("7. Quantidade de bytes lixos inseridos:%ld\n",final);
        resultado = sqrt(resultado/6);
        printf("8. Ordem da matriz: %d X %d\n",resultado,resultado);
        printf("9. Valor total em MB: %d\n",( ( (resultado * resultado) *6) / 1024 ) );
        printf("10. Valor total de bytes para matriz: %d bytes", ( (resultado * resultado) *6) );
        return resultado;
    }
    printf("5. Valor de Qtd: %f\n", inteiro);
        inteiro = (int)inteiro;
        return inteiro;
}

variable_types: valor long

variable_types: Qtd double

variable_types: inteiro double

variable_types: fracionario double

variable_types: resultado int

variable_types: final long