decompiled_code:
int __fastcall mu_report_test_suite_report(const char *a1, _QWORD *a2, unsigned int a3, unsigned int a4)
{
int result; // eax
_QWORD *v7; // rbx

printf("%s", "Suite ");
printf("%s", a1);
printf("%s", ": ");
printf("%d", a3);
putchar(47);
printf("%d", a4);
result = putchar(10);
if ( a3 != a4 )
{
result = puts("\tFailing tests:");
if ( *a2 )
{
v7 = a2 + 3;
do
{
result = *((_DWORD *)v7 - 1);
if ( !result || result != *((_DWORD *)v7 - 2) )
{
printf("%s", "\t\t");
printf("%s", (const char *)*(v7 - 2));
printf("%s", ": ");
if ( *((_DWORD *)v7 - 1) )
{
printf("%d", *((unsigned int *)v7 - 2));
putchar(47);
printf("%d", *((unsigned int *)v7 - 1));
printf("%s", " passed");
result = putchar(10);
}
else
{
result = puts("no test performed");
}
}
v7 += 3;
}
while ( *(v7 - 3) );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func21(const char *a1, _QWORD *a2, unsigned int a3, unsigned int a4)
{
int result; // eax
_QWORD *v7; // rbx

printf("%s", "Suite ");
printf("%s", a1);
printf("%s", ": ");
printf("%d", a3);
putchar(47);
printf("%d", a4);
result = putchar(10);
if ( a3 != a4 )
{
result = puts("\tFailing tests:");
if ( *a2 )
{
v7 = a2 + 3;
do
{
result = *((_DWORD *)v7 - 1);
if ( !result || result != *((_DWORD *)v7 - 2) )
{
printf("%s", "\t\t");
printf("%s", (const char *)*(v7 - 2));
printf("%s", ": ");
if ( *((_DWORD *)v7 - 1) )
{
printf("%d", *((unsigned int *)v7 - 2));
putchar(47);
printf("%d", *((unsigned int *)v7 - 1));
printf("%s", " passed");
result = putchar(10);
}
else
{
result = puts("no test performed");
}
}
v7 += 3;
}
while ( *(v7 - 3) );
}
}
return result;
}

original_code:
static __inline__ void mu_report_test_suite_report(const char *suite_name, struct mu_test_desc *tests_array, int success, int total)
    {
 printf("%s", ("Suite "));
 printf("%s", (suite_name));
 printf("%s", (": "));
 printf("%d", (success));
 printf("%c", ('/'));
 printf("%d", (total));
 printf("%c", ('\n'));
 if (success != total)
 {
     int i;
     printf("%s", ("\tFailing tests:\n"));
     for (i = 0 ; tests_array[i].test != ((void *)0) ; ++i)
     {
  struct mu_test_desc *desc = &tests_array[i];
  if (!((desc)->performed != 0 && ((desc)->success == (desc)->performed)))
  {
      printf("%s", ("\t\t"));
      printf("%s", (desc->test_name));
      printf("%s", (": "));
      if (desc->performed != 0)
      {
   printf("%d", (desc->success));
   printf("%c", ('/'));
   printf("%d", (desc->performed));
   printf("%s", (" passed"));
   printf("%s", ("\n")) ;
      }
      else
      {
   printf("%s", ("no test performed\n"));
      }
  }
     }
 }
    }

canonical_original_code:
static __inline__ void mu_report_test_suite_report(char *suite_name, struct mu_test_desc *tests_array, int success, int total)
    {
 printf("%s", ("Suite "));
 printf("%s", (suite_name));
 printf("%s", (": "));
 printf("%d", (success));
 printf("%c", ('/'));
 printf("%d", (total));
 printf("%c", ('\n'));
 if (success != total)
 {
     int i;
     printf("%s", ("\tFailing tests:\n"));
     for (i = 0 ; tests_array[i].test != ((void *)0) ; ++i)
     {
  struct mu_test_desc *desc = &tests_array[i];
  if (!((desc)->performed != 0 && ((desc)->success == (desc)->performed)))
  {
      printf("%s", ("\t\t"));
      printf("%s", (desc->test_name));
      printf("%s", (": "));
      if (desc->performed != 0)
      {
   printf("%d", (desc->success));
   printf("%c", ('/'));
   printf("%d", (desc->performed));
   printf("%s", (" passed"));
   printf("%s", ("\n")) ;
      }
      else
      {
   printf("%s", ("no test performed\n"));
      }
  }
     }
 }
    }


repo: hauspie/minunit

decompiled_code:
void test_assertions_tear_down()
{
;
}

canonical_decompiled_code:
void func23()
{
;
}

original_code: void test_assertions_tear_down(struct mu_test_desc *desc) {}

variable_types: struct mu_test_desc { void (*test)(struct mu_test_desc *desc); char *test_name; int success; int performed; } *

return_type: void


decompiled_code:
void test_assertions_setup()
{
;
}

canonical_decompiled_code:
void func24()
{
;
}

original_code: void test_assertions_setup(struct mu_test_desc *desc) {}

user_defined_types: struct mu_test_desc { void (*test)(struct mu_test_desc *desc); char *test_name; int success; int performed; }


decompiled_code:
void test_half_tear_down()
{
;
}

canonical_decompiled_code:
void func25()
{
;
}

original_code: void test_half_tear_down(struct mu_test_desc *desc) {}


decompiled_code:
void test_half_setup()
{
;
}

canonical_decompiled_code:
void func26()
{
;
}

original_code: void test_half_setup(struct mu_test_desc *desc) {}


decompiled_code:
void half_success_tear_down()
{
;
}

canonical_decompiled_code:
void func27()
{
;
}

original_code: void half_success_tear_down(struct mu_test_desc *desc) {}


main

canonical_name: main

repo: hazybluedot/fdtrace

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // edi
__pid_t v5; // eax
unsigned int v6; // er12
int *v7; // rax
__int64 v8; // rbp
__int64 v9; // rbx
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
usage(argc, argv, envp);
exit(1);
}
for ( i = 3; i != 9; ++i )
{
v4 = i;
close(v4);
}
v5 = fork();
v6 = v5;
if ( v5 < 0 )
{
perror("fork");
}
else if ( v5 )
{
if ( f_debug )
fprintf(stderr, "setting pid %jd as head\n", v5);
v7 = (int *)alloc_pib(v6);
head = (__int64)v7;
if ( f_debug )
fprintf(stderr, "head (%p) ->pid is %jd\n", v7, v7[4]);
while ( 1 )
{
while ( 1 )
{
v8 = (unsigned int)wait((__WAIT_STATUS)&stat_loc);
v9 = pid2pib(v8);
if ( v9 )
break;
fprintf(stderr, "Untracked pid: %jd\n", (int)v8);
}
if ( ((__int64)stat_loc.__uptr & 0x7F) == 0 )
break;
*(_QWORD *)(v9 + 24) = ptrace(PTRACE_PEEKUSER, v6, 120LL, 0LL);
if ( (*(_DWORD *)v9 & 8) != 0 )
{
*(_DWORD *)v9 &= 0xFFFFFFF7;
}
else
{
enter_syscall(v9);
*(_DWORD *)v9 |= 8u;
}
ptrace(PTRACE_SYSCALL, v6, 0LL, 0LL);
}
}
else
{
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
if ( execvp(argv[1], (char *const *)argv + 1) == -1 )
{
perror("execv");
exit(1);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // edi
__pid_t v5; // eax
unsigned int v6; // er12
int *v7; // rax
__int64 v8; // rbp
__int64 v9; // rbx
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 1 )
{
func9(argc, argv, envp);
exit(1);
}
for ( i = 3; i != 9; ++i )
{
v4 = i;
close(v4);
}
v5 = fork();
v6 = v5;
if ( v5 < 0 )
{
perror("fork");
}
else if ( v5 )
{
if ( f_debug )
fprintf(stderr, "setting pid %jd as head\n", v5);
v7 = (int *)alloc_pib(v6);
head = (__int64)v7;
if ( f_debug )
fprintf(stderr, "head (%p) ->pid is %jd\n", v7, v7[4]);
while ( 1 )
{
while ( 1 )
{
v8 = (unsigned int)wait((__WAIT_STATUS)&stat_loc);
v9 = func8(v8);
if ( v9 )
break;
fprintf(stderr, "Untracked pid: %jd\n", (int)v8);
}
if ( ((__int64)stat_loc.__uptr & 0x7F) == 0 )
break;
*(_QWORD *)(v9 + 24) = ptrace(PTRACE_PEEKUSER, v6, 120LL, 0LL);
if ( (*(_DWORD *)v9 & 8) != 0 )
{
*(_DWORD *)v9 &= 0xFFFFFFF7;
}
else
{
func13(v9);
*(_DWORD *)v9 |= 8u;
}
ptrace(PTRACE_SYSCALL, v6, 0LL, 0LL);
}
}
else
{
ptrace(PTRACE_TRACEME, 0LL, 0LL, 0LL);
if ( execvp(argv[1], (char *const *)argv + 1) == -1 )
{
perror("execv");
exit(1);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
    pid_t pid;
    int status;
    if (argc < 2) {
        usage();
        exit(1);
    }
    for(unsigned int i=3; i<9; i++)
        close(i);
    if ((pid = fork()) < 0) {
        perror("fork");
    } else if (pid == 0) {
        ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
        if (-1 == execvp(argv[1], &argv[1]) ) {
            perror("execv");
            exit(1);
        }
    } else {
        if (f_debug)
            fprintf(stderr, "setting pid %jd as head\n", (intmax_t)pid);
        head = alloc_pib(pid);
        if (f_debug)
            fprintf(stderr, "head (%p) ->pid is %jd\n", head, (intmax_t)head->pid);
        while(1) {
            pid_t ppid = wait(&status);
            struct pib *pip = pid2pib(ppid);
            if (!pip) {
                fprintf(stderr, "Untracked pid: %jd\n", (intmax_t)ppid);
            } else {
                if((((status) & 0x7f) == 0))
                    break;
                pip->syscall = ptrace(PTRACE_PEEKUSER,
                                      pid, 8 * 15, ((void *)0));
                if (pip->flags & 00010) {
                    exit_syscall(pip);
                    pip->flags &= ~00010;
                } else {
                    enter_syscall(pip);
                    pip->flags |= 00010;
                }
                ptrace(PTRACE_SYSCALL,
                       pid, ((void *)0), ((void *)0));
            }
        }
    }
}

canonical_original_code:
int main(int argc, char *argv[]) {
    int pid;
    int status;
    if (argc < 2) {
        usage();
        exit(1);
    }
    for(unsigned int i = 3; i<9; i++)
        close(i);
    if ((pid = fork()) < 0) {
        perror("fork");
    } else if (pid == 0) {
        ptrace(PTRACE_TRACEME, 0, ((void *)0), ((void *)0));
        if (-1 == execvp(argv[1], &argv[1]) ) {
            perror("execv");
            exit(1);
        }
    } else {
        if (f_debug)
            fprintf(stderr, "setting pid %jd as head\n", (long)pid);
        head = alloc_pib(pid);
        if (f_debug)
            fprintf(stderr, "head (%p) ->pid is %jd\n", head, (long)head->pid);
        while(1) {
            int ppid = wait(&status);
            struct pib *pip = pid2pib(ppid);
            if (!pip) {
                fprintf(stderr, "Untracked pid: %jd\n", (long)ppid);
            } else {
                if((((status) & 0x7f) == 0))
                    break;
                pip->syscall = ptrace(PTRACE_PEEKUSER,
                                      pid, 8 * 15, ((void *)0));
                if (pip->flags & 00010) {
                    exit_syscall(pip);
                    pip->flags &= ~00010;
                } else {
                    enter_syscall(pip);
                    pip->flags |= 00010;
                }
                ptrace(PTRACE_SYSCALL,
                       pid, ((void *)0), ((void *)0));
            }
        }
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: pid int

variable_types: status int

variable_types:
i
unsigned int

variable_types: ppid int

variable_types: struct pib { int flags; struct pib *next; int pid; long syscall; long long params[3]; long rval; struct pib *children; } *

return_type: int


decompiled_code:
__int64 __fastcall pid2pib_helper(int a1, __int64 a2)
{
__int64 v2; // rbx

if ( !a2 )
return 0LL;
v2 = a2;
do
{
if ( f_debug > 1 )
fprintf(stderr, "checking if %jd == %jd\n", *(int *)(v2 + 16), a1);
if ( *(_DWORD *)(v2 + 16) == a1 )
return v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, __int64 a2)
{
__int64 v2; // rbx

if ( !a2 )
return 0LL;
v2 = a2;
do
{
if ( f_debug > 1 )
fprintf(stderr, "checking if %jd == %jd\n", *(int *)(v2 + 16), a1);
if ( *(_DWORD *)(v2 + 16) == a1 )
return v2;
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
return 0LL;
}

original_code:
static struct pib*
pid2pib_helper(pid_t pid, struct pib *start) {
    struct pib *cur = start;
    while(cur != ((void *)0)) {
        if (f_debug > 1)
            fprintf(stderr, "checking if %jd == %jd\n", (intmax_t)cur->pid, (intmax_t)pid);
        if (cur->pid == pid)
            return cur;
        cur = cur->next;
    }
    return ((void *)0);
}

canonical_original_code:
static struct pib *pid2pib_helper(int pid, struct pib *start) {
    struct pib *cur = start;
    while(cur != ((void *)0)) {
        if (f_debug > 1)
            fprintf(stderr, "checking if %jd == %jd\n", (long)cur->pid, (long)pid);
        if (cur->pid == pid)
            return cur;
        cur = cur->next;
    }
    return ((void *)0);
}

variable_types:
start
struct pib *

return_type: struct pib { int flags; struct pib *next; int pid; long syscall; long long params[3]; long rval; struct pib *children; } *


decompiled_code:
__int64 __fastcall pid2pib(int a1)
{
if ( f_debug )
{
fprintf(stderr, "searching for %jd in pid list\n", a1);
fprintf(stderr, "head (%p) ->pid is %jd\n", (const void *)head, *(int *)(head + 16));
}
return pid2pib_helper(a1, head);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
if ( f_debug )
{
fprintf(stderr, "searching for %jd in pid list\n", a1);
fprintf(stderr, "head (%p) ->pid is %jd\n", (const void *)head, *(int *)(head + 16));
}
return func7(a1, head);
}

original_code:
static struct pib*
pid2pib(pid_t pid) {
    if (f_debug) {
        fprintf(stderr, "searching for %jd in pid list\n", (intmax_t)pid);
        fprintf(stderr, "head (%p) ->pid is %jd\n", head, (intmax_t)head->pid);
    }
    return pid2pib_helper(pid, head);
}

canonical_original_code:
static struct pib *pid2pib(int pid) {
    if (f_debug) {
        fprintf(stderr, "searching for %jd in pid list\n", (long)pid);
        fprintf(stderr, "head (%p) ->pid is %jd\n", head, (long)head->pid);
    }
    return pid2pib_helper(pid, head);
}

user_defined_types: struct pib { int flags; struct pib *next; int pid; long syscall; long long params[3]; long rval; struct pib *children; }


usage

decompiled_code:
size_t usage()
{
return fwrite("Usage: fdtrace COMMAND\n", 1uLL, 0x17uLL, stderr);
}

canonical_decompiled_code:
size_t func9()
{
return fwrite("Usage: fdtrace COMMAND\n", 1uLL, 0x17uLL, stderr);
}

original_code:
void usage() {
    fputs("Usage: fdtrace COMMAND\n", stderr);
}


decompiled_code:
__int64 __fastcall get_params(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 32) = ptrace(PTRACE_PEEKUSER, v1, 40LL, 0LL);
*(_QWORD *)(a1 + 40) = ptrace(PTRACE_PEEKUSER, v1, 88LL, 0LL);
result = ptrace(PTRACE_PEEKUSER, v1, 96LL, 0LL);
*(_QWORD *)(a1 + 48) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_QWORD *)(a1 + 32) = ptrace(PTRACE_PEEKUSER, v1, 40LL, 0LL);
*(_QWORD *)(a1 + 40) = ptrace(PTRACE_PEEKUSER, v1, 88LL, 0LL);
result = ptrace(PTRACE_PEEKUSER, v1, 96LL, 0LL);
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
void get_params(struct pib *pip) {
    pid_t pid = pip->pid;
    pip->params[0] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 5, ((void *)0));
    pip->params[1] = ptrace(PTRACE_PEEKUSER,
                            pid, 8 * 11, ((void *)0));
    pip->params[2] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 12, ((void *)0));
}

canonical_original_code:
void get_params(struct pib *pip) {
    int pid = pip->pid;
    pip->params[0] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 5, ((void *)0));
    pip->params[1] = ptrace(PTRACE_PEEKUSER,
                            pid, 8 * 11, ((void *)0));
    pip->params[2] = ptrace(PTRACE_PEEKUSER,
                           pid, 8 * 12, ((void *)0));
}


decompiled_code:
int __fastcall print_syscall(_QWORD *a1)
{
__int64 v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = a1[3];
if ( v1 == 2 )
{
strcpy(v3, "open");
goto LABEL_6;
}
if ( v1 <= 2 && v1 == 1 )
{
strcpy(v3, "write");
LABEL_6:
LODWORD(v1) = fprintf(stderr, "%s(%lld, %lld, %lld)\n", v3, a1[4], a1[5], a1[6]);
}
return v1;
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1)
{
__int64 v1; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

v1 = a1[3];
if ( v1 == 2 )
{
strcpy(v3, "open");
goto LABEL_6;
}
if ( v1 <= 2 && v1 == 1 )
{
strcpy(v3, "write");
LABEL_6:
LODWORD(v1) = fprintf(stderr, "%s(%lld, %lld, %lld)\n", v3, a1[4], a1[5], a1[6]);
}
return v1;
}

original_code:
void print_syscall(struct pib *pip) {
    char name[255];
    int argc;
    switch(pip->syscall) {
    case(2):
        strcpy(name, "open"); argc=3;
        break;
    case(3):
        strcpy(name, "close"); argc=1;
        break;
    case(32):
        strcpy(name, "dup"); argc=1;
        break;
    case(33):
        strcpy(name, "dup2"); argc=2;
        break;
    case(72):
        strcpy(name, "fnctl"); argc=-1;
        break;
    case(1):
        strcpy(name, "write"); argc=3;
        break;
    }
    switch(argc) {
    case(3):
        fprintf(stderr, "%s(%lld, %lld, %lld)\n", name, pip->params[0], pip->params[1], pip->params[2]);
        break;
    }
}

variable_types:
name
char [255]


decompiled_code:
void exit_syscall()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void exit_syscall(struct pib *pip) {
}

canonical_original_code:
void exit_syscall(struct pib *pip) {
}


decompiled_code:
int __fastcall enter_syscall(__int64 a1)
{
__int64 v1; // rax

v1 = *(_QWORD *)(a1 + 24);
if ( v1 > 3 )
{
if ( v1 > 33 )
{
if ( v1 != 72 )
return v1;
}
else if ( v1 <= 31 )
{
return v1;
}
goto LABEL_11;
}
if ( v1 > 1 )
{
LABEL_11:
*(_DWORD *)a1 |= 0x200u;
return v1;
}
if ( v1 == 1 )
{
if ( (*(_DWORD *)a1 & 0x200) != 0 )
{
list_fd(*(unsigned int *)(a1 + 16));
*(_DWORD *)a1 &= 0xFFFFFDFF;
}
get_params(a1);
LODWORD(v1) = print_syscall((_QWORD *)a1);
}
return v1;
}

original_code:
void enter_syscall(struct pib *pip) {
    switch(pip->syscall) {
    case(2):
    case(3):
    case(32):
    case(33):
    case(72):
        pip->flags |= 01000;
        break;
    case(0):
        break;
    case(1):
        if (pip->flags & 01000) {
            list_fd(pip->pid);
            pip->flags &= ~01000;
        }
        get_params(pip);
        print_syscall(pip);
    }
}


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

if ( a1 == 12 )
{
LODWORD(link_hdr_len) = 0;
}
else
{
if ( a1 > 12 )
{
if ( a1 != 108 )
{
LABEL_7:
LODWORD(link_hdr_len) = 0;
v1 = (const char *)pcap_datalink_val_to_name();
fprintf(stderr, "Warning: Link type %s not recognized.\n", v1);
return;
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
LODWORD(link_hdr_len) = 14;
return;
}
goto LABEL_7;
}
LODWORD(link_hdr_len) = 4;
}
}

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

if ( a1 == 12 )
{
LODWORD(link_hdr_len) = 0;
}
else
{
if ( a1 > 12 )
{
if ( a1 != 108 )
{
LABEL_7:
LODWORD(link_hdr_len) = 0;
v1 = (const char *)pcap_datalink_val_to_name();
fprintf(stderr, "Warning: Link type %s not recognized.\n", v1);
return;
}
}
else if ( a1 )
{
if ( a1 == 1 )
{
LODWORD(link_hdr_len) = 14;
return;
}
goto LABEL_7;
}
LODWORD(link_hdr_len) = 4;
}
}

original_code:
void set_link_type(const int dlt)
{
    switch (dlt) {
    case 1:
        link_hdr_len = 14;
        break;
    case 0:
    case 108:
        link_hdr_len = 4;
        break;
    case 12:
        link_hdr_len = 0;
        break;
    default:
        link_hdr_len = 0;
        fprintf(stderr, "Warning: Link type %s not recognized.\n", pcap_datalink_val_to_name(dlt));
    }
}

canonical_original_code:
void set_link_type(int dlt)
{
    switch (dlt) {
    case 1:
        link_hdr_len = 14;
        break;
    case 0:
    case 108:
        link_hdr_len = 4;
        break;
    case 12:
        link_hdr_len = 0;
        break;
    default:
        link_hdr_len = 0;
        fprintf(stderr, "Warning: Link type %s not recognized.\n", pcap_datalink_val_to_name(dlt));
    }
}

variable_types: dlt int


decompiled_code:
__int64 get_link_hdr_len()
{
return (unsigned int)link_hdr_len;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)link_hdr_len;
}

original_code:
u_int get_link_hdr_len()
{
    return link_hdr_len;
}

canonical_original_code:
unsigned int get_link_hdr_len()
{
    return link_hdr_len;
}

return_type: unsigned int


isBigEndian

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

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

original_code:
int isBigEndian()
{
   long int i = 1;
   const char *p = (const char *) &i;
   if (p[0] == 1)
      return 0;
   else
      return 1;
}

canonical_original_code:
int isBigEndian()
{
   long i = 1;
   char *p = (const char *) &i;
   if (p[0] == 1)
      return 0;
   else
      return 1;
}

variable_types: i long

variable_types:
p
char *


decompiled_code:
__int64 __fastcall unpack_packet(void *src, void *dest)
{
char *v2; // rdi
bool v3; // zf
unsigned __int8 v4; // al
__int16 v5; // ax
__int64 result; // rax

memcpy(dest, src, (unsigned int)link_hdr_len);
v2 = (char *)src + (unsigned int)link_hdr_len;
*((_BYTE *)dest + 14) = (unsigned __int8)*v2 >> 4;
*((_BYTE *)dest + 15) = *v2 & 0xF;
*((_BYTE *)dest + 16) = v2[1];
*((_WORD *)dest + 9) = *((_WORD *)v2 + 1);
*((_WORD *)dest + 10) = *((_WORD *)v2 + 2);
v3 = (unsigned int)isBigEndian() == 0;
v4 = v2[6];
if ( v3 )
{
*((_BYTE *)dest + 22) = v4 & 7;
v5 = *((_WORD *)v2 + 3);
HIBYTE(v5) &= 0xF8u;
}
else
{
*((_BYTE *)dest + 22) = v4 >> 5;
v5 = *((_WORD *)v2 + 3) & 0x1FFF;
}
*((_WORD *)dest + 12) = v5;
*(_QWORD *)((char *)dest + 26) = *((_QWORD *)v2 + 1);
result = *((unsigned int *)v2 + 4);
*(_DWORD *)((char *)dest + 34) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, void *dest)
{
char *v2; // rdi
bool v3; // zf
unsigned __int8 v4; // al
__int16 v5; // ax
__int64 result; // rax

memcpy(dest, src, (unsigned int)link_hdr_len);
v2 = (char *)src + (unsigned int)link_hdr_len;
*((_BYTE *)dest + 14) = (unsigned __int8)*v2 >> 4;
*((_BYTE *)dest + 15) = *v2 & 0xF;
*((_BYTE *)dest + 16) = v2[1];
*((_WORD *)dest + 9) = *((_WORD *)v2 + 1);
*((_WORD *)dest + 10) = *((_WORD *)v2 + 2);
v3 = (unsigned int)func2() == 0;
v4 = v2[6];
if ( v3 )
{
*((_BYTE *)dest + 22) = v4 & 7;
v5 = *((_WORD *)v2 + 3);
HIBYTE(v5) &= 0xF8u;
}
else
{
*((_BYTE *)dest + 22) = v4 >> 5;
v5 = *((_WORD *)v2 + 3) & 0x1FFF;
}
*((_WORD *)dest + 12) = v5;
*(_QWORD *)((char *)dest + 26) = *((_QWORD *)v2 + 1);
result = *((unsigned int *)v2 + 4);
*(_DWORD *)((char *)dest + 34) = result;
return result;
}

original_code:
void unpack_packet(const u_char* origPacket, struct packet_struct* parsedPacket,
                   size_t capturedSize)
{
    u_char icmpIpHdrOct=0;
    u_char icmpIpHdrProto=0;
    u_char icmpTcpHdrOct=0;
    memcpy((void*)(&(parsedPacket->dstMacAddr[0])), (const void*)origPacket, (size_t)link_hdr_len);
    const u_char* origIpPacket = origPacket+link_hdr_len;
    parsedPacket->ipVer = origIpPacket[0]>>4;
    parsedPacket->ipHdrLen = origIpPacket[0]&0x0f;
    parsedPacket->tos = origIpPacket[1];
    parsedPacket->packetLen = *((u_int16_t*)(origIpPacket+2));
    parsedPacket->id = *((u_int16_t*)(origIpPacket+4));
    if (isBigEndian()) {
        parsedPacket->flags = origIpPacket[6]>>5;
        parsedPacket->fragOffset = (*((u_int16_t*)(origIpPacket+6)))&0x1fff;
    } else {
        parsedPacket->flags = origIpPacket[6]&0x07;
        parsedPacket->fragOffset = (*((u_int16_t*)(origIpPacket+6)))&0xf8ff;
    }
    memcpy(&(parsedPacket->ttl), origIpPacket+8, 12);
}

canonical_original_code:
void unpack_packet(unsigned char *origPacket, struct packet_struct *parsedPacket, unsigned long capturedSize)
{
    unsigned char icmpIpHdrOct = 0;
    unsigned char icmpIpHdrProto = 0;
    unsigned char icmpTcpHdrOct = 0;
    memcpy((void *)(&(parsedPacket->dstMacAddr[0])), (void *)origPacket, (unsigned long)link_hdr_len);
    unsigned char *origIpPacket = origPacket+link_hdr_len;
    parsedPacket->ipVer = origIpPacket[0]>>4;
    parsedPacket->ipHdrLen = origIpPacket[0]&0x0f;
    parsedPacket->tos = origIpPacket[1];
    parsedPacket->packetLen = *((unsigned int *)(origIpPacket+2));
    parsedPacket->id = *((unsigned int *)(origIpPacket+4));
    if (isBigEndian()) {
        parsedPacket->flags = origIpPacket[6]>>5;
        parsedPacket->fragOffset = (*((unsigned int *)(origIpPacket+6)))&0x1fff;
    } else {
        parsedPacket->flags = origIpPacket[6]&0x07;
        parsedPacket->fragOffset = (*((unsigned int *)(origIpPacket+6)))&0xf8ff;
    }
    memcpy(&(parsedPacket->ttl), origIpPacket+8, 12);
}

variable_types:
origPacket
unsigned char *

variable_types: struct packet_struct { unsigned char dstMacAddr[6]; unsigned char srcMacAddr[6]; unsigned char etherProto[2]; unsigned char ipVer; unsigned char ipHdrLen; unsigned char tos; unsigned int packetLen; unsigned int id; unsigned char flags; unsigned int fragOffset; unsigned char ttl; unsigned char protocol; unsigned int hdrXsum; unsigned char srcIpQ1; unsigned char srcIpQ2; unsigned char srcIpQ3; unsigned char srcIpQ4; unsigned char dstIpQ1; unsigned char dstIpQ2; unsigned char dstIpQ3; unsigned char dstIpQ4; } *

variable_types:
capturedSize
unsigned long

variable_types:
icmpIpHdrOct
unsigned char

variable_types:
icmpIpHdrProto
unsigned char

variable_types:
icmpTcpHdrOct
unsigned char

variable_types:
origIpPacket
unsigned char *


initlist

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

result = malloc(0x18uLL);
head = (__int64)result;
*result = 0LL;
result[2] = result;
result[1] = result;
return result;
}

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

result = malloc(0x18uLL);
head = (__int64)result;
*result = 0LL;
result[2] = result;
result[1] = result;
return result;
}

original_code:
Dlinklist initlist()
{
 head = ((void *)0);
head = malloc(sizeof(Dlnode));
 head->data = ((void *)0);
 head->next = head;
 head->prior = head;
 return head;
}

canonical_original_code:
struct dlnode *initlist()
{
 head = ((void *)0);
head = malloc(sizeof(Dlnode));
 head->data = ((void *)0);
 head->next = head;
 head->prior = head;
 return head;
}

return_type: struct dlnode { void *data; struct dlnode *prior; } *


dinsertbefore

decompiled_code:
__int64 __fastcall dinsertbefore(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

if ( !a1 )
return 3LL;
v2 = dmakenode(a2);
if ( !v2 )
return 2LL;
v3 = *(_QWORD *)(a1 + 8);
v2[2] = a1;
v2[1] = v3;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL) = v2;
*(_QWORD *)(a1 + 8) = v2;
return 1LL;
}

original_code:
ret dinsertbefore(Dlinklist p, void *e)
{
 if(p!=((void *)0))
 {
  Dlinklist s;
  s = dmakenode(e);
  if(((void *)0) == s)
  return(ERROR);
  s->next = p;
  s->prior = p->prior;
  p->prior->next = s;
  p->prior = s;
  return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertbefore(struct dlnode *p, void *e)
{
 if(p!=((void *)0))
 {
  struct dlnode *s;
  s = dmakenode(e);
  if(((void *)0) == s)
  return(ERROR);
  s->next = p;
  s->prior = p->prior;
  p->prior->next = s;
  p->prior = s;
  return OK;
 }
 else return NO;
}

variable_types: struct dlnode { void *data; struct dlnode *prior; } *

variable_types:
e
void *

return_type: enum Ret { OK=1, ERROR=2, NO=3 }


dinsertbeforen

decompiled_code:
__int64 __fastcall dinsertbeforen(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbx
_QWORD *v5; // rdx
int v6; // eax
__int64 v7; // rax
__int64 result; // rax

v3 = a1;
if ( !a1 )
return 3LL;
v5 = dmakenode(a2);
if ( !v5 )
return 2LL;
if ( a3 > 0 )
{
v6 = 0;
do
{
++v6;
v3 = *(_QWORD *)(v3 + 16);
}
while ( a3 != v6 );
}
v7 = *(_QWORD *)(v3 + 8);
v5[2] = v3;
v5[1] = v7;
*(_QWORD *)(*(_QWORD *)(v3 + 8) + 16LL) = v5;
result = 1LL;
*(_QWORD *)(v3 + 8) = v5;
return result;
}

original_code:
ret dinsertbeforen(Dlinklist p, void *e, int index)
{
 if(p!=((void *)0))
 {
   Dlinklist s;
   int i;
   s = dmakenode(e);
   if(((void *)0) == s)
   return(ERROR);
   Dlinklist head = p;
   Dlinklist fhead = head;
   for(i=0;i<index;i++)
   {
    fhead = fhead->next;
   }
   s->next = fhead;
   s->prior = fhead->prior;
   fhead->prior->next = s;
   fhead->prior = s;
   return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertbeforen(struct dlnode *p, void *e, int index)
{
 if(p!=((void *)0))
 {
   struct dlnode *s;
   int i;
   s = dmakenode(e);
   if(((void *)0) == s)
   return(ERROR);
   struct dlnode *head = p;
   struct dlnode *fhead = head;
   for(i=0;i<index;i++)
   {
    fhead = fhead->next;
   }
   s->next = fhead;
   s->prior = fhead->prior;
   fhead->prior->next = s;
   fhead->prior = s;
   return OK;
 }
 else return NO;
}

variable_types: index int

variable_types: i int

user_defined_types: struct dlnode { void *data; struct dlnode *prior; }


dinsertafter

decompiled_code:
__int64 __fastcall dinsertafter(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

if ( !a1 )
return 3LL;
v2 = dmakenode(a2);
if ( !v2 )
return 2LL;
v3 = *(_QWORD *)(a1 + 16);
v2[1] = a1;
v2[2] = v3;
*(_QWORD *)(v3 + 8) = v2;
*(_QWORD *)(a1 + 16) = v2;
return 1LL;
}

original_code:
ret dinsertafter(Dlinklist p, void *e)
{
   if(p!=((void *)0))
 {
  Dlinklist s;
  s = dmakenode(e);
  if(s == ((void *)0))
  return(ERROR);
  s->next = p->next;
  s->prior = p;
  p->next->prior = s;
  p->next = s;
  return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertafter(struct dlnode *p, void *e)
{
   if(p!=((void *)0))
 {
  struct dlnode *s;
  s = dmakenode(e);
  if(s == ((void *)0))
  return(ERROR);
  s->next = p->next;
  s->prior = p;
  p->next->prior = s;
  p->next = s;
  return OK;
 }
 else return NO;
}


ddeletenode

decompiled_code:
__int64 __fastcall ddeletenode(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *i; // rcx
_QWORD *v4; // rax
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rax

result = 3LL;
if ( a1 )
{
for ( i = (_QWORD *)dgethead(a1)[2]; *i; i = *(_QWORD **)(v5 + 16) )
{
v4 = dlocateitem(i, a2);
if ( v4 )
{
v6 = v4[1];
v7 = v4[2];
*(_QWORD *)(v6 + 16) = v7;
*(_QWORD *)(v7 + 8) = v6;
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *i; // rcx
_QWORD *v4; // rax
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rax

result = 3LL;
if ( a1 )
{
for ( i = (_QWORD *)dgethead(a1)[2]; *i; i = *(_QWORD **)(v5 + 16) )
{
v4 = dlocateitem(i, a2);
if ( v4 )
{
v6 = v4[1];
v7 = v4[2];
*(_QWORD *)(v6 + 16) = v7;
*(_QWORD *)(v7 + 8) = v6;
}
}
result = 1LL;
}
return result;
}

original_code:
ret ddeletenode(Dlinklist p, void *e)
{
 if(p!=((void *)0))
 {
  Dlinklist head = dgethead(p);
  Dlinklist temp;
  Dlinklist tempp;
  for(temp=head->next;temp->data != ((void *)0);temp = temp->next)
  {
   tempp = dlocateitem(temp,e);
   if(tempp != ((void *)0))
   {
    tempp->prior->next = tempp->next;
    tempp->next->prior = tempp->prior;
   }
  }
 return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret ddeletenode(struct dlnode *p, void *e)
{
 if(p!=((void *)0))
 {
  struct dlnode *head = dgethead(p);
  struct dlnode *temp;
  struct dlnode *tempp;
  for(temp=head->next;temp->data != ((void *)0);temp = temp->next)
  {
   tempp = dlocateitem(temp,e);
   if(tempp != ((void *)0))
   {
    tempp->prior->next = tempp->next;
    tempp->next->prior = tempp->prior;
   }
  }
 return OK;
 }
 else return NO;
}


setitem

decompiled_code:
__int64 __fastcall setitem(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rax
__int64 v4; // rcx

result = 3LL;
if ( a1 )
{
v3 = dlocateitem(a1, a2);
if ( v3 )
*v3 = v4;
else
printf("can not find the node ");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rax
__int64 v4; // rcx

result = 3LL;
if ( a1 )
{
v3 = dlocateitem(a1, a2);
if ( v3 )
*v3 = v4;
else
printf("can not find the node ");
result = 1LL;
}
return result;
}

original_code:
ret setitem(Dlinklist p,void *e, void *edest)
{
 if(p)
 {
  Dlinklist retp = dlocateitem(p,e);
  if(retp == ((void *)0))
  {
   printf("can not find the node ");
  }
  else{
   retp->data = edest;
  }
 return OK;
 }
 else return NO;
}

canonical_original_code:
enum Ret setitem(struct dlnode *p, void *e, void *edest)
{
 if(p)
 {
  struct dlnode *retp = dlocateitem(p,e);
  if(retp == ((void *)0))
  {
   printf("can not find the node ");
  }
  else{
   retp->data = edest;
  }
 return OK;
 }
 else return NO;
}

variable_types:
edest
void *


dlistlength

decompiled_code:
__int64 __fastcall dlistlength(__int64 a1)
{
unsigned int i; // er8
_QWORD *v2; // rax

i = 0;
if ( a1 )
{
v2 = *(_QWORD **)(a1 + 16);
for ( i = 1; *v2; ++i )
v2 = (_QWORD *)v2[2];
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int i; // er8
_QWORD *v2; // rax

i = 0;
if ( a1 )
{
v2 = *(_QWORD **)(a1 + 16);
for ( i = 1; *v2; ++i )
v2 = (_QWORD *)v2[2];
}
return i;
}

original_code:
int dlistlength(Dlinklist p)
{
 if(p!=((void *)0))
 {
  int i=1;
  Dlinklist ptmp = p->next;
  while(ptmp->data !=((void *)0))
  {
   ptmp = ptmp->next;
   i++;
  }
  return(i);
 }
 else return(0);
}

canonical_original_code:
int dlistlength(struct dlnode *p)
{
 if(p!=((void *)0))
 {
  int i = 1;
  struct dlnode *ptmp = p->next;
  while(ptmp->data !=((void *)0))
  {
   ptmp = ptmp->next;
   i++;
  }
  return(i);
 }
 else return(0);
}


dinsertaftern

decompiled_code:
__int64 __fastcall dinsertaftern(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbx
int v5; // er8
__int64 result; // rax
int v7; // edx
_QWORD *v8; // rdx
int v9; // eax
__int64 v10; // rax

if ( !a1 )
return 3LL;
v4 = a1;
v5 = dlistlength(a1);
result = 3LL;
if ( v5 >= v7 )
{
v8 = dmakenode(a2);
if ( v8 )
{
if ( a3 > 0 )
{
v9 = 0;
do
{
++v9;
v4 = *(_QWORD *)(v4 + 16);
}
while ( a3 != v9 );
}
v10 = *(_QWORD *)(v4 + 16);
v8[1] = v4;
v8[2] = v10;
*(_QWORD *)(v10 + 8) = v8;
result = 1LL;
*(_QWORD *)(v4 + 16) = v8;
}
else
{
result = 2LL;
}
}
return result;
}

original_code:
ret dinsertaftern(Dlinklist p, void *e,int index)
{ if(p!=((void *)0))
 {
  int j=dlistlength(p);
  if(j+1 > index)
  {
   Dlinklist s;
   Dlinklist tmpp=p;
   int i;
   s = dmakenode(e);
   if(s == ((void *)0))
   return(ERROR);
   for(i=0;i<index;i++)
   {
    tmpp=tmpp->next;
   }
   s->next = tmpp->next;
   s->prior = tmpp;
   tmpp->next->prior = s;
   tmpp->next = s;
   return OK;
  }
  else return NO;
 }
 else return NO;
}

canonical_original_code:
enum Ret dinsertaftern(struct dlnode *p, void *e, int index)
{ if(p!=((void *)0))
 {
  int j = dlistlength(p);
  if(j+1 > index)
  {
   struct dlnode *s;
   struct dlnode *tmpp = p;
   int i;
   s = dmakenode(e);
   if(s == ((void *)0))
   return(ERROR);
   for(i=0;i<index;i++)
   {
    tmpp=tmpp->next;
   }
   s->next = tmpp->next;
   s->prior = tmpp;
   tmpp->next->prior = s;
   tmpp->next = s;
   return OK;
  }
  else return NO;
 }
 else return NO;
}

variable_types: j int


ddeletenoden

decompiled_code:
__int64 __fastcall ddeletenoden(_QWORD *a1, int a2)
{
int v2; // er8
__int64 result; // rax
int i; // eax
__int64 v5; // rax
__int64 v6; // rdx

if ( !a1 )
return 3LL;
v2 = dlistlength((__int64)a1);
result = 3LL;
if ( v2 >= a2 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
a1 = (_QWORD *)a1[2];
}
v5 = a1[1];
v6 = a1[2];
*(_QWORD *)(v6 + 8) = v5;
*(_QWORD *)(v5 + 16) = v6;
free(a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2)
{
int v2; // er8
__int64 result; // rax
int i; // eax
__int64 v5; // rax
__int64 v6; // rdx

if ( !a1 )
return 3LL;
v2 = func6((__int64)a1);
result = 3LL;
if ( v2 >= a2 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
a1 = (_QWORD *)a1[2];
}
v5 = a1[1];
v6 = a1[2];
*(_QWORD *)(v6 + 8) = v5;
*(_QWORD *)(v5 + 16) = v6;
free(a1);
result = 1LL;
}
return result;
}

original_code:
ret ddeletenoden(Dlinklist p,int index)
{
 if(p !=((void *)0)){
  int j=dlistlength(p);
  if(j<index)
  return NO;
  else
  {
   Dlinklist tmpp = p;
   int i;
   for(i=0;i<index;i++)
   {
    tmpp = tmpp->next;
   }
   tmpp->next->prior = tmpp->prior;
   tmpp->prior->next = tmpp->next;
   free(tmpp);
   return OK;
  }
  return NO;
 }
 else return NO;
}

canonical_original_code:
enum Ret ddeletenoden(struct dlnode *p, int index)
{
 if(p !=((void *)0)){
  int j = dlistlength(p);
  if(j<index)
  return NO;
  else
  {
   struct dlnode *tmpp = p;
   int i;
   for(i=0;i<index;i++)
   {
    tmpp = tmpp->next;
   }
   tmpp->next->prior = tmpp->prior;
   tmpp->prior->next = tmpp->next;
   free(tmpp);
   return OK;
  }
  return NO;
 }
 else return NO;
}


dscan

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

if ( !a1 )
return 0LL;
if ( (int)dlistlength((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
result = 0LL;
}
else
{
while ( (_QWORD *)a1[2] != a1 )
a2(*a1);
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( (int)func6((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
result = 0LL;
}
else
{
while ( (_QWORD *)a1[2] != a1 )
a2(*a1);
result = 0LL;
}
return result;
}

original_code:
Dlinklist dscan(Dlinklist p, VisitFunc visit)
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i=0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->next !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}

canonical_original_code:
struct dlnode *dscan(struct dlnode *p, void *visit(void *data))
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i = 0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->next !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}

variable_types:
p
struct dlnode *

variable_types:
visit
void *(void *data)

variable_types:
retp
void *


drescan

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

if ( !a1 )
return 0LL;
if ( (int)dlistlength((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
result = 0LL;
}
else
{
while ( (_QWORD *)a1[1] != a1 )
a2(*a1);
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
if ( (int)func6((__int64)a1) <= 0 )
{
printf("you only get a headlist without any item");
result = 0LL;
}
else
{
while ( (_QWORD *)a1[1] != a1 )
a2(*a1);
result = 0LL;
}
return result;
}

original_code:
Dlinklist drescan(Dlinklist p, VisitFunc visit)
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i=0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->prior !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}

canonical_original_code:
struct dlnode *drescan(struct dlnode *p, void *visit(void *data))
{
 if(p!=((void *)0))
 {
  void *retp = ((void *)0);
  if( p==((void *)0))
  {
   printf("Linklist error");
   return ((void *)0);
  }
  int i = 0;
       i = dlistlength(p);
  if(i< 1 )
  {
   printf("you only get a headlist without any item");
   return ((void *)0);
  }
  else
  {
   void *retp = ((void *)0);
   while(p->prior !=p)
   {
    retp = visit(p->data);
   }
  }
  return retp;
 }
 else return ((void *)0);
}


disempty

decompiled_code:
__int64 __fastcall disempty(__int64 a1)
{
if ( a1 )
return 2 * (unsigned int)(*(_QWORD *)(a1 + 16) == a1) + 1;
printf("a NULL list occored");
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( a1 )
return 2 * (unsigned int)(*(_QWORD *)(a1 + 16) == a1) + 1;
printf("a NULL list occored");
return 3LL;
}

original_code:
ret disempty(Dlinklist p)
{
 if(p==((void *)0))
 {
  printf("a NULL list occored");
  return NO;
 }
 else
 {
  if(p->next == p)
  return NO;
  else
  return OK;
 }
}

canonical_original_code:
enum Ret disempty(struct dlnode *p)
{
 if(p==((void *)0))
 {
  printf("a NULL list occored");
  return NO;
 }
 else
 {
  if(p->next == p)
  return NO;
  else
  return OK;
 }
}


sortlist

decompiled_code:
__int64 __fastcall sortlist(__int64 a1, int (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // r14
int v3; // er8
__int64 result; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbp
int v7; // er13
__int64 v8; // rax

if ( a1 )
{
v2 = malloc(0x18uLL);
v3 = dlistlength(a1);
result = 3LL;
if ( v3 > 2 )
{
do
{
v5 = *(_QWORD **)(a1 + 16);
v6 = (_QWORD *)v5[2];
if ( !*v6 )
break;
v7 = 0;
do
{
if ( a2(*v5) > 0 )
{
v8 = *v5;
v7 = 1;
*v5 = *v6;
*v2 = v8;
*v6 = v8;
}
v6 = (_QWORD *)v6[2];
v5 = (_QWORD *)v5[2];
}
while ( *v6 );
}
while ( v7 );
free(v2);
result = 1LL;
}
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // r14
int v3; // er8
__int64 result; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbp
int v7; // er13
__int64 v8; // rax

if ( a1 )
{
v2 = malloc(0x18uLL);
v3 = func6(a1);
result = 3LL;
if ( v3 > 2 )
{
do
{
v5 = *(_QWORD **)(a1 + 16);
v6 = (_QWORD *)v5[2];
if ( !*v6 )
break;
v7 = 0;
do
{
if ( a2(*v5) > 0 )
{
v8 = *v5;
v7 = 1;
*v5 = *v6;
*v2 = v8;
*v6 = v8;
}
v6 = (_QWORD *)v6[2];
v5 = (_QWORD *)v5[2];
}
while ( *v6 );
}
while ( v7 );
free(v2);
result = 1LL;
}
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

original_code:
ret sortlist(Dlinklist p,int cmpall(const void *a,const void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  Dlinklist p1=((void *)0);
  Dlinklist p2=((void *)0);
  Dlinklist p3=malloc(sizeof(Dlnode));
  int len = dlistlength(p);
  int j,i;
  if(len<3)
  {
   return NO;
  }
  else
  {
   int docmp=1;
   while(docmp)
   {
    p1 = p->next;
    p2 = p1->next;
    docmp =0;
    while(p2->data !=((void *)0))
    {
     if(cmpall(p1->data, p2->data) >0)
     {
      p3->data = p1->data;
      p1->data = p2->data;
      p2->data = p3->data;
      docmp = 1;
     }
     p1 = p1->next;
     p2=p2->next;
    }
   }
  }
  free(p3);
 return OK;
}
return NO;
}

canonical_original_code:
enum Ret sortlist(struct dlnode *p, int cmpall(void *a, void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  struct dlnode *p1 = ((void *)0);
  struct dlnode *p2 = ((void *)0);
  struct dlnode *p3 = malloc(sizeof(Dlnode));
  int len = dlistlength(p);
  int j; int i;
  if(len<3)
  {
   return NO;
  }
  else
  {
   int docmp = 1;
   while(docmp)
   {
    p1 = p->next;
    p2 = p1->next;
    docmp =0;
    while(p2->data !=((void *)0))
    {
     if(cmpall(p1->data, p2->data) >0)
     {
      p3->data = p1->data;
      p1->data = p2->data;
      p2->data = p3->data;
      docmp = 1;
     }
     p1 = p1->next;
     p2=p2->next;
    }
   }
  }
  free(p3);
 return OK;
}
return NO;
}

variable_types:
cmpall
int (void *a, void *b)

variable_types: len int

variable_types: docmp int


quicksort

original_code:
void quicksort(Dlinklist leftlist, Dlinklist rightlist , int left,int right, int cmpall(const void *a,const void *b))
{
 if(left < right)
 {
  Dlinklist baselist = leftlist;
  Dlinklist curleftlist = leftlist;
  Dlinklist currightlist = rightlist;
  leftlist = leftlist->prior;
  rightlist = rightlist->next;
  Dlinklist p;
  Dlinklist q;
  int curleft = left;
  int curright = right;
  while(curright > curleft)
  {
   while(curright > left && (cmpall(baselist->data,currightlist->data) < 0))
   {
    currightlist = currightlist->prior;
    curright--;
   }
   while(curleft < right && (cmpall(baselist->data,curleftlist->data) > 0))
   {
    curleftlist = curleftlist->next;
    curleft++;
   }
   if(curleft < curright)
   {
    p = curleftlist->prior;
    q = currightlist->next;
    curleftlist->next->prior = p;
    p->next = curleftlist->next;
    currightlist->prior->next=q;
    q->prior = currightlist->prior;
    currightlist->next = p->next;
    currightlist->prior = p;
    p->next->prior = currightlist;
    p->next =currightlist;
    curleftlist->next = q;
    curleftlist->prior = q->prior;
    q->prior->next = curleftlist;
    q->prior = curleftlist;
   curright--;
   curleft++;
   curleftlist = p->next->next;
   currightlist = q->prior->prior;
   }
  }
  if(left < curright)
  {
   quicksort(leftlist->next,currightlist->prior,left,curright-1,cmpall);
  }
  if(right > curleft)
  {
   quicksort(currightlist->next,rightlist->prior,curright+1,right,cmpall);
  }
 }
 exit(1);
}

canonical_original_code:
void quicksort(struct dlnode *leftlist, struct dlnode *rightlist, int left, int right, int cmpall(void *a, void *b))
{
 if(left < right)
 {
  struct dlnode *baselist = leftlist;
  struct dlnode *curleftlist = leftlist;
  struct dlnode *currightlist = rightlist;
  leftlist = leftlist->prior;
  rightlist = rightlist->next;
  struct dlnode *p;
  struct dlnode *q;
  int curleft = left;
  int curright = right;
  while(curright > curleft)
  {
   while(curright > left && (cmpall(baselist->data,currightlist->data) < 0))
   {
    currightlist = currightlist->prior;
    curright--;
   }
   while(curleft < right && (cmpall(baselist->data,curleftlist->data) > 0))
   {
    curleftlist = curleftlist->next;
    curleft++;
   }
   if(curleft < curright)
   {
    p = curleftlist->prior;
    q = currightlist->next;
    curleftlist->next->prior = p;
    p->next = curleftlist->next;
    currightlist->prior->next=q;
    q->prior = currightlist->prior;
    currightlist->next = p->next;
    currightlist->prior = p;
    p->next->prior = currightlist;
    p->next =currightlist;
    curleftlist->next = q;
    curleftlist->prior = q->prior;
    q->prior->next = curleftlist;
    q->prior = curleftlist;
   curright--;
   curleft++;
   curleftlist = p->next->next;
   currightlist = q->prior->prior;
   }
  }
  if(left < curright)
  {
   quicksort(leftlist->next,currightlist->prior,left,curright-1,cmpall);
  }
  if(right > curleft)
  {
   quicksort(currightlist->next,rightlist->prior,curright+1,right,cmpall);
  }
 }
 exit(1);
}

variable_types:
rightlist
struct dlnode *

variable_types: left int

variable_types: right int

variable_types: curleft int

variable_types: curright int


quicksortlist

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

if ( a1 )
{
v2 = dlistlength(a1);
if ( v2 > 1 )
{
quicksort(*(_QWORD **)(a1 + 16), *(_QWORD **)(a1 + 8), 1, v2 - 1, a2);
result = mergelist();
}
else
{
result = 1LL;
}
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

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

if ( a1 )
{
v2 = func6(a1);
if ( v2 > 1 )
{
func13(*(_QWORD **)(a1 + 16), *(_QWORD **)(a1 + 8), 1, v2 - 1, a2);
result = func15();
}
else
{
result = 1LL;
}
}
else
{
printf("a NULL list occord");
result = 3LL;
}
return result;
}

original_code:
ret quicksortlist(Dlinklist p,int cmpall(const void *a,const void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  int len = dlistlength(p);
  if(len < 2)
  {
   return OK;
  }
  else
  {
   int left = 1;
   int right = len - 1;
   quicksort(p->next, p->prior, left, right, cmpall);
  }
 }
}

canonical_original_code:
enum Ret quicksortlist(struct dlnode *p, int cmpall(void *a, void *b))
{
 if(p==((void *)0))
 {
  printf("a NULL list occord");
  return NO;
 }
 else
 {
  int len = dlistlength(p);
  if(len < 2)
  {
   return OK;
  }
  else
  {
   int left = 1;
   int right = len - 1;
   quicksort(p->next, p->prior, left, right, cmpall);
  }
 }
}

variable_types: struct dlnode { void *data; struct dlnode *prior; } *


myscan

decompiled_code:
int __fastcall myscan(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 16); *i; i = (_QWORD *)i[2] )
a2();
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 16); *i; i = (_QWORD *)i[2] )
a2();
return putchar(10);
}

original_code:
void myscan(Dlinklist list, VisitFunc visit)
{
 Dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->next;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->next;
    }
 printf("\n");
}

canonical_original_code:
void myscan(struct dlnode *list, void *visit(void *data))
{
 struct dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->next;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->next;
    }
 printf("\n");
}


myrescan

decompiled_code:
int __fastcall myrescan(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 8); *i; i = (_QWORD *)i[1] )
a2();
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, void (*a2)(void))
{
_QWORD *i; // rbx

for ( i = *(_QWORD **)(a1 + 8); *i; i = (_QWORD *)i[1] )
a2();
return putchar(10);
}

original_code:
void myrescan(Dlinklist list, VisitFunc visit)
{
 Dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->prior;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->prior;
    }
 printf("\n");
}

canonical_original_code:
void myrescan(struct dlnode *list, void *visit(void *data))
{
 struct dlnode *ipointer = ((void *)0);
    void *retp = ((void *)0);
    ipointer = list->prior;
    for (ipointer ; ipointer->data != ((void *)0); )
    {
        retp = visit(ipointer->data);
        ipointer = ipointer->prior;
    }
 printf("\n");
}


wordtolist

decompiled_code:
__int64 __fastcall wordtolist(_BYTE *a1, unsigned int a2, char a3)
{
__int64 v3; // rcx
__int64 result; // rax

if ( a3 == 108 )
return wordinsert(list, a1, a2, 108LL);
v3 = (unsigned int)a3;
switch ( *a1 )
{
case 'A':
case 'a':
result = wordinsert(lista, a1, a2, v3);
break;
case 'B':
case 'b':
result = wordinsert(listb, a1, a2, v3);
break;
case 'C':
case 'c':
result = wordinsert(listc, a1, a2, v3);
break;
case 'D':
case 'd':
result = wordinsert(listd, a1, a2, v3);
break;
case 'E':
case 'e':
result = wordinsert(liste, a1, a2, v3);
break;
case 'F':
case 'f':
result = wordinsert(listf, a1, a2, v3);
break;
case 'G':
case 'g':
result = wordinsert(listg, a1, a2, v3);
break;
case 'H':
case 'h':
result = wordinsert(listh, a1, a2, v3);
break;
case 'I':
case 'i':
result = wordinsert(listi, a1, a2, v3);
break;
case 'J':
case 'j':
result = wordinsert(listj, a1, a2, v3);
break;
case 'K':
case 'k':
result = wordinsert(listk, a1, a2, v3);
break;
case 'L':
case 'l':
result = wordinsert(listl, a1, a2, v3);
break;
case 'M':
case 'm':
result = wordinsert(listm, a1, a2, v3);
break;
case 'N':
case 'n':
result = wordinsert(listn, a1, a2, v3);
break;
case 'O':
case 'o':
result = wordinsert(listo, a1, a2, v3);
break;
case 'P':
case 'p':
result = wordinsert(listp, a1, a2, v3);
break;
case 'Q':
case 'q':
result = wordinsert(listq, a1, a2, v3);
break;
case 'R':
case 'r':
result = wordinsert(listr, a1, a2, v3);
break;
case 'S':
case 's':
result = wordinsert(lists, a1, a2, v3);
break;
case 'T':
case 't':
result = wordinsert(listt, a1, a2, v3);
break;
case 'U':
case 'u':
result = wordinsert(listu, a1, a2, v3);
break;
case 'V':
case 'v':
result = wordinsert(listv, a1, a2, v3);
break;
case 'W':
case 'w':
result = wordinsert(listw, a1, a2, v3);
break;
case 'X':
case 'x':
result = wordinsert(listx, a1, a2, v3);
break;
case 'Y':
case 'y':
result = wordinsert(listy, a1, a2, v3);
break;
case 'Z':
case 'z':
result = wordinsert(listz, a1, a2, v3);
break;
default:
result = wordinsert(list, a1, a2, v3);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned int a2, char a3)
{
__int64 v3; // rcx
__int64 result; // rax

if ( a3 == 108 )
return wordinsert(list, a1, a2, 108LL);
v3 = (unsigned int)a3;
switch ( *a1 )
{
case 'A':
case 'a':
result = wordinsert(lista, a1, a2, v3);
break;
case 'B':
case 'b':
result = wordinsert(listb, a1, a2, v3);
break;
case 'C':
case 'c':
result = wordinsert(listc, a1, a2, v3);
break;
case 'D':
case 'd':
result = wordinsert(listd, a1, a2, v3);
break;
case 'E':
case 'e':
result = wordinsert(liste, a1, a2, v3);
break;
case 'F':
case 'f':
result = wordinsert(listf, a1, a2, v3);
break;
case 'G':
case 'g':
result = wordinsert(listg, a1, a2, v3);
break;
case 'H':
case 'h':
result = wordinsert(listh, a1, a2, v3);
break;
case 'I':
case 'i':
result = wordinsert(listi, a1, a2, v3);
break;
case 'J':
case 'j':
result = wordinsert(listj, a1, a2, v3);
break;
case 'K':
case 'k':
result = wordinsert(listk, a1, a2, v3);
break;
case 'L':
case 'l':
result = wordinsert(listl, a1, a2, v3);
break;
case 'M':
case 'm':
result = wordinsert(listm, a1, a2, v3);
break;
case 'N':
case 'n':
result = wordinsert(listn, a1, a2, v3);
break;
case 'O':
case 'o':
result = wordinsert(listo, a1, a2, v3);
break;
case 'P':
case 'p':
result = wordinsert(listp, a1, a2, v3);
break;
case 'Q':
case 'q':
result = wordinsert(listq, a1, a2, v3);
break;
case 'R':
case 'r':
result = wordinsert(listr, a1, a2, v3);
break;
case 'S':
case 's':
result = wordinsert(lists, a1, a2, v3);
break;
case 'T':
case 't':
result = wordinsert(listt, a1, a2, v3);
break;
case 'U':
case 'u':
result = wordinsert(listu, a1, a2, v3);
break;
case 'V':
case 'v':
result = wordinsert(listv, a1, a2, v3);
break;
case 'W':
case 'w':
result = wordinsert(listw, a1, a2, v3);
break;
case 'X':
case 'x':
result = wordinsert(listx, a1, a2, v3);
break;
case 'Y':
case 'y':
result = wordinsert(listy, a1, a2, v3);
break;
case 'Z':
case 'z':
result = wordinsert(listz, a1, a2, v3);
break;
default:
result = wordinsert(list, a1, a2, v3);
break;
}
return result;
}

original_code:
void wordtolist(char *ss, int islistempty,char cnt)
{
 if(cnt == 'l')
 {
  wordinsert(list,ss,islistempty,cnt);
 }
 else
 {
  char firstch = ss[0];
  switch(firstch)
  {
   case 'a':
   case 'A': wordinsert(lista,ss,islistempty,cnt);break;
   case 'b':
   case 'B': wordinsert(listb,ss,islistempty,cnt);break;
   case 'c':
   case 'C': wordinsert(listc,ss,islistempty,cnt);break;
   case 'd':
   case 'D': wordinsert(listd,ss,islistempty,cnt);break;
   case 'e':
   case 'E': wordinsert(liste,ss,islistempty,cnt);break;
   case 'f':
   case 'F': wordinsert(listf,ss,islistempty,cnt);break;
   case 'g':
   case 'G': wordinsert(listg,ss,islistempty,cnt);break;
   case 'h':
   case 'H': wordinsert(listh,ss,islistempty,cnt);break;
   case 'i':
   case 'I': wordinsert(listi,ss,islistempty,cnt);break;
   case 'j':
   case 'J': wordinsert(listj,ss,islistempty,cnt);break;
   case 'k':
   case 'K': wordinsert(listk,ss,islistempty,cnt);break;
   case 'l':
   case 'L': wordinsert(listl,ss,islistempty,cnt);break;
   case 'm':
   case 'M': wordinsert(listm,ss,islistempty,cnt);break;
   case 'n':
   case 'N': wordinsert(listn,ss,islistempty,cnt);break;
   case 'o':
   case 'O': wordinsert(listo,ss,islistempty,cnt);break;
   case 'p':
   case 'P': wordinsert(listp,ss,islistempty,cnt);break;
   case 'q':
   case 'Q': wordinsert(listq,ss,islistempty,cnt);break;
   case 'r':
   case 'R': wordinsert(listr,ss,islistempty,cnt);break;
   case 's':
   case 'S': wordinsert(lists,ss,islistempty,cnt);break;
   case 't':
   case 'T': wordinsert(listt,ss,islistempty,cnt);break;
   case 'u':
   case 'U': wordinsert(listu,ss,islistempty,cnt);break;
   case 'v':
   case 'V': wordinsert(listv,ss,islistempty,cnt);break;
   case 'w':
   case 'W': wordinsert(listw,ss,islistempty,cnt);break;
   case 'x':
   case 'X': wordinsert(listx,ss,islistempty,cnt);break;
   case 'y':
   case 'Y': wordinsert(listy,ss,islistempty,cnt);break;
   case 'z':
   case 'Z': wordinsert(listz,ss,islistempty,cnt);break;
   default :wordinsert(list,ss,islistempty,cnt);break;
  }
 }
}

canonical_original_code:
void wordtolist(char *ss, int islistempty, char cnt)
{
 if(cnt == 'l')
 {
  wordinsert(list,ss,islistempty,cnt);
 }
 else
 {
  char firstch = ss[0];
  switch(firstch)
  {
   case 'a':
   case 'A': wordinsert(lista,ss,islistempty,cnt);break;
   case 'b':
   case 'B': wordinsert(listb,ss,islistempty,cnt);break;
   case 'c':
   case 'C': wordinsert(listc,ss,islistempty,cnt);break;
   case 'd':
   case 'D': wordinsert(listd,ss,islistempty,cnt);break;
   case 'e':
   case 'E': wordinsert(liste,ss,islistempty,cnt);break;
   case 'f':
   case 'F': wordinsert(listf,ss,islistempty,cnt);break;
   case 'g':
   case 'G': wordinsert(listg,ss,islistempty,cnt);break;
   case 'h':
   case 'H': wordinsert(listh,ss,islistempty,cnt);break;
   case 'i':
   case 'I': wordinsert(listi,ss,islistempty,cnt);break;
   case 'j':
   case 'J': wordinsert(listj,ss,islistempty,cnt);break;
   case 'k':
   case 'K': wordinsert(listk,ss,islistempty,cnt);break;
   case 'l':
   case 'L': wordinsert(listl,ss,islistempty,cnt);break;
   case 'm':
   case 'M': wordinsert(listm,ss,islistempty,cnt);break;
   case 'n':
   case 'N': wordinsert(listn,ss,islistempty,cnt);break;
   case 'o':
   case 'O': wordinsert(listo,ss,islistempty,cnt);break;
   case 'p':
   case 'P': wordinsert(listp,ss,islistempty,cnt);break;
   case 'q':
   case 'Q': wordinsert(listq,ss,islistempty,cnt);break;
   case 'r':
   case 'R': wordinsert(listr,ss,islistempty,cnt);break;
   case 's':
   case 'S': wordinsert(lists,ss,islistempty,cnt);break;
   case 't':
   case 'T': wordinsert(listt,ss,islistempty,cnt);break;
   case 'u':
   case 'U': wordinsert(listu,ss,islistempty,cnt);break;
   case 'v':
   case 'V': wordinsert(listv,ss,islistempty,cnt);break;
   case 'w':
   case 'W': wordinsert(listw,ss,islistempty,cnt);break;
   case 'x':
   case 'X': wordinsert(listx,ss,islistempty,cnt);break;
   case 'y':
   case 'Y': wordinsert(listy,ss,islistempty,cnt);break;
   case 'z':
   case 'Z': wordinsert(listz,ss,islistempty,cnt);break;
   default :wordinsert(list,ss,islistempty,cnt);break;
  }
 }
}

variable_types:
ss
char *

variable_types: islistempty int

variable_types: cnt char

variable_types: firstch char


decompiled_code:
int __fastcall cmp_list_word(__int64 a1, const char *a2)
{
return strcmp(*(const char **)(a1 + 8), a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, const char *a2)
{
return strcmp(*(const char **)(a1 + 8), a2);
}

original_code:
int cmp_list_word(const void *a, const void *b)
{
 STWD *p1 = (STWD *)a;
 char *p2 = (char *)b;
 return strcmp((const char *)p1->word, p2);
}

canonical_original_code:
int cmp_list_word(void *a, void *b)
{
 struct STWD *p1 = (STWD *)a;
 char *p2 = (char *)b;
 return strcmp((char *)p1->word, p2);
}

variable_types:
a
void *

variable_types:
b
void *


getwordstdin

decompiled_code:
size_t __fastcall getwordstdin(int a1, char a2)
{
int v2; // er14
unsigned int v3; // er12
__int64 v4; // rdx
__int64 v5; // rdx
size_t result; // rax
__int64 v7; // rdx
char v8; // [rsp+Fh] [rbp-129h] BYREF
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v2 = 0;
v3 = 1;
while ( (unsigned int)_isoc99_scanf(&unk_138, &v8) != -1 )
{
if ( (unsigned __int8)(v8 - 48) <= 9u || (unsigned __int8)(v8 - 97) <= 0x19u )
{
if ( a1 == 1 && (unsigned __int8)(v8 - 65) <= 0x19u )
goto LABEL_10;
LABEL_7:
v4 = v2++;
s[v4] = v8;
}
else if ( (unsigned __int8)(v8 - 65) > 0x19u )
{
s[v2] = 0;
if ( strlen(s) )
{
v7 = v3;
v3 = 0;
wordinsert(list, s, v7, (unsigned int)a2);
}
s[0] = 0;
v2 = 0;
}
else
{
if ( a1 != 1 )
goto LABEL_7;
LABEL_10:
v5 = v2++;
s[v5] = v8 + 32;
}
}
s[v2] = 0;
result = strlen(s);
if ( result )
result = wordinsert(list, s, v3, (unsigned int)a2);
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(int a1, char a2)
{
int v2; // er14
unsigned int v3; // er12
__int64 v4; // rdx
__int64 v5; // rdx
size_t result; // rax
__int64 v7; // rdx
char v8; // [rsp+Fh] [rbp-129h] BYREF
char s[296]; // [rsp+10h] [rbp-128h] BYREF

v2 = 0;
v3 = 1;
while ( (unsigned int)_isoc99_scanf(&unk_138, &v8) != -1 )
{
if ( (unsigned __int8)(v8 - 48) <= 9u || (unsigned __int8)(v8 - 97) <= 0x19u )
{
if ( a1 == 1 && (unsigned __int8)(v8 - 65) <= 0x19u )
goto LABEL_10;
LABEL_7:
v4 = v2++;
s[v4] = v8;
}
else if ( (unsigned __int8)(v8 - 65) > 0x19u )
{
s[v2] = 0;
if ( strlen(s) )
{
v7 = v3;
v3 = 0;
wordinsert(list, s, v7, (unsigned int)a2);
}
s[0] = 0;
v2 = 0;
}
else
{
if ( a1 != 1 )
goto LABEL_7;
LABEL_10:
v5 = v2++;
s[v5] = v8 + 32;
}
}
s[v2] = 0;
result = strlen(s);
if ( result )
result = wordinsert(list, s, v3, (unsigned int)a2);
return result;
}

original_code:
void getwordstdin(int uptolower,char cnt)
{
 char ss[256];
 char c;
 int i =0;
 int len = 0;
 int islistempty=1;
 while(scanf("%c",&c) != (-1))
 {
  if((c >= '0' && c<='9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
  {
   if(uptolower == 1)
   {
    if(c >= 'A' && c <= 'Z')
    {
     ss[i++] = c + 32;
    }
    else
    {
     ss[i++] = c;
    }
   }
   else
   {
    ss[i++] = c;
   }
  }
  else
  {
   ss[i++] = '\0';
   len = strlen(ss);
   if(len >0)
   {
    wordinsert(list,ss, islistempty,cnt);
    islistempty = 0;
   }
   i = 0;
   ss[i] = '\0';
  }
 }
 ss[i++] = '\0';
 len = strlen(ss);
 if(len >0)
  {
  wordinsert(list,ss,islistempty,cnt);
  islistempty = 0;
  }
}

canonical_original_code:
void getwordstdin(int uptolower, char cnt)
{
 char ss[256];
 char c;
 int i = 0;
 int len = 0;
 int islistempty = 1;
 while(scanf("%c",&c) != (-1))
 {
  if((c >= '0' && c<='9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
  {
   if(uptolower == 1)
   {
    if(c >= 'A' && c <= 'Z')
    {
     ss[i++] = c + 32;
    }
    else
    {
     ss[i++] = c;
    }
   }
   else
   {
    ss[i++] = c;
   }
  }
  else
  {
   ss[i++] = '\0';
   len = strlen(ss);
   if(len >0)
   {
    wordinsert(list,ss, islistempty,cnt);
    islistempty = 0;
   }
   i = 0;
   ss[i] = '\0';
  }
 }
 ss[i++] = '\0';
 len = strlen(ss);
 if(len >0)
  {
  wordinsert(list,ss,islistempty,cnt);
  islistempty = 0;
  }
}

variable_types: uptolower int

variable_types:
ss
char [256]

variable_types: c char

variable_types: i int


decompiled_code:
void __fastcall diag_similarity_transform(__int64 a1, int a2)
{
double *v3; // r13
__int64 i; // rbx
double v5; // xmm0_8
__int64 v6; // rbp
__int64 v7; // rsi
double *v8; // r12
double *v9; // rbx
double v10; // xmm0_8
__int64 v11; // rsi
__int64 v12; // [rsp+8h] [rbp-40h]

v12 = a2;
v3 = (double *)calloc(a2, 8uLL);
diag((__int64)v3, a1, a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v5 = v3[i];
v6 = a1;
v7 = a1 + i * 8;
cblas_dscal((unsigned int)a2, v7, (unsigned int)a2, v5);
}
v8 = v3;
v9 = &v3[i];
do
{
v10 = *v8;
v11 = v6;
++v8;
v6 += 8 * v12;
cblas_dscal((unsigned int)a2, v11, 1LL, v10);
}
while ( v8 != v9 );
}
free(v3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
double *v3; // r13
__int64 i; // rbx
double v5; // xmm0_8
__int64 v6; // rbp
__int64 v7; // rsi
double *v8; // r12
double *v9; // rbx
double v10; // xmm0_8
__int64 v11; // rsi
__int64 v12; // [rsp+8h] [rbp-40h]

v12 = a2;
v3 = (double *)calloc(a2, 8uLL);
func1((__int64)v3, a1, a2);
if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
{
v5 = v3[i];
v6 = a1;
v7 = a1 + i * 8;
cblas_dscal((unsigned int)a2, v7, (unsigned int)a2, v5);
}
v8 = v3;
v9 = &v3[i];
do
{
v10 = *v8;
v11 = v6;
++v8;
v6 += 8 * v12;
cblas_dscal((unsigned int)a2, v11, 1LL, v10);
}
while ( v8 != v9 );
}
free(v3);
}

original_code:
static void diag_similarity_transform(double *w, int n_patch)
{
    double *d = (double *)calloc(n_patch, sizeof(double));
    int i;
    diag(d, w, n_patch);
    for (i = 0; i < n_patch; i++)
        cblas_dscal(n_patch, d[i], &w[i], n_patch);
    for (i = 0; i < n_patch; i++)
        cblas_dscal(n_patch, d[i], &w[i * n_patch], 1);
    free(d);
}

variable_types:
w
double *

variable_types:
d
double *


original_code:
static void compute_l(double *w, int n_patch)
{
    int N = n_patch * n_patch;
    int i;
    for (i = 0; i < N; i++)
        w[i] = ((i % (n_patch + 1) == 0) ? 1.0 : 0.0) - w[i];
}

variable_types: N int


diag

original_code:
static void diag(double *d, const double *w, int n_patch)
{
    int i, j;
    double sum;
    for (j = 0; j < n_patch; j++){
        sum = 0;
        for (i = 0; i < n_patch; i++)
            sum += w[i + j * n_patch];
        d[j] = 1 / sqrt(sum);
    }
}

canonical_original_code:
static void diag(double *d, double *w, int n_patch)
{
    int i; int j;
    double sum;
    for (j = 0; j < n_patch; j++){
        sum = 0;
        for (i = 0; i < n_patch; i++)
            sum += w[i + j * n_patch];
        d[j] = 1 / sqrt(sum);
    }
}

variable_types: j int

variable_types: sum double


laplacian

decompiled_code:
void __fastcall laplacian(__int64 a1, int a2)
{
diag_similarity_transform(a1, a2);
compute_l(a1, a2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
func2(a1, a2);
func0(a1, a2);
}

original_code:
void laplacian(double *w, int n_patch)
{
    diag_similarity_transform(w, n_patch);
    compute_l(w, n_patch);
}


pairweight

decompiled_code:
__int64 __fastcall pairweight(__int64 a1, int a2, __int64 a3, __int64 a4, _DWORD *a5, int a6, int *a7)
{
return diff_reduce(a1, a3, a4, a5[1] * *a5, a6, *a7, a7[1], a2);
}

original_code:
void pairweight(double *w, int n_patch, double *feat, double *pos,
                int feat_dim[2], int pos_dim, int par[2], int option)
{
    diff_reduce(w, feat, pos, feat_dim[0] * feat_dim[1], pos_dim,
        par[0], par[1], n_patch);
}

variable_types:
feat
double *

variable_types:
pos
double *

variable_types:
par
int [2]

variable_types: option int


arggetc

repo: hcpa/rpi-usbcam

decompiled_code:
__int64 __fastcall arggetc(char **a1)
{
char *v1; // rbx
int v2; // esi
char v3; // al
bool v4; // cl
bool v5; // zf
char v6; // al
char *v7; // r12
__int64 result; // rax
char *v9; // rax

v1 = *a1;
v2 = **a1;
if ( !**a1 )
return 0xFFFFFFFFLL;
v3 = *((_BYTE *)a1 + 16);
v4 = (v3 & 4) == 0;
v5 = (v3 & 2) == 0;
v6 = *((_BYTE *)a1 + 17);
while ( 1 )
{
v7 = v1++;
if ( (_BYTE)v2 == 92 && v4 )
{
if ( v6 && v7[1] != 34 )
goto LABEL_10;
*a1 = v1;
if ( v7[1] )
{
*a1 = v7 + 2;
return (unsigned int)v7[1];
}
return 0xFFFFFFFFLL;
}
if ( (_BYTE)v2 != 34 || !v5 )
break;
*a1 = v1;
v6 = v6 == 0;
*((_BYTE *)a1 + 17) = v6;
v2 = *v1;
if ( !*v1 )
return 0xFFFFFFFFLL;
}
if ( v6 )
{
LABEL_10:
*a1 = v1;
return (unsigned int)*v7;
}
v9 = strchr(a1[1], v2);
*a1 = v1;
if ( v9 )
result = 4294967294LL;
else
result = (unsigned int)*v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1)
{
char *v1; // rbx
int v2; // esi
char v3; // al
bool v4; // cl
bool v5; // zf
char v6; // al
char *v7; // r12
__int64 result; // rax
char *v9; // rax

v1 = *a1;
v2 = **a1;
if ( !**a1 )
return 0xFFFFFFFFLL;
v3 = *((_BYTE *)a1 + 16);
v4 = (v3 & 4) == 0;
v5 = (v3 & 2) == 0;
v6 = *((_BYTE *)a1 + 17);
while ( 1 )
{
v7 = v1++;
if ( (_BYTE)v2 == 92 && v4 )
{
if ( v6 && v7[1] != 34 )
goto LABEL_10;
*a1 = v1;
if ( v7[1] )
{
*a1 = v7 + 2;
return (unsigned int)v7[1];
}
return 0xFFFFFFFFLL;
}
if ( (_BYTE)v2 != 34 || !v5 )
break;
*a1 = v1;
v6 = v6 == 0;
*((_BYTE *)a1 + 17) = v6;
v2 = *v1;
if ( !*v1 )
return 0xFFFFFFFFLL;
}
if ( v6 )
{
LABEL_10:
*a1 = v1;
return (unsigned int)*v7;
}
v9 = strchr(a1[1], v2);
*a1 = v1;
if ( v9 )
result = 4294967294LL;
else
result = (unsigned int)*v7;
return result;
}

variable_types: struct arg_t { char *s; char *sep; char opts; char quote; } *


argopts

original_code:
int argopts(arg_t *arg, char *src, char *sep, int opts)
{
 memset(arg, 0, sizeof(arg_t));
 arg->s = src;
 arg->sep = sep;
 arg->opts = opts;
 return(0);
}

canonical_original_code:
int argopts(struct arg_t *arg, char *src, char *sep, int opts)
{
 memset(arg, 0, sizeof(arg_t));
 arg->s = src;
 arg->sep = sep;
 arg->opts = opts;
 return(0);
}

variable_types:
src
char *

variable_types:
sep
char *

variable_types: opts int

user_defined_types: struct arg_t { char *s; char *sep; char opts; char quote; }


argncpy

original_code:
int argncpy(char *dst, size_t n, char *src, char *sep, int arg, int opt)
{
 arg_t s;
 char *d;
 size_t l;
 int r;
 argopts(&s, src, sep, opt);
 d = dst;
 *d = '\0';
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(0);
   d = dst;
   *d = '\0';
   l = 0;
   continue;
  }
  if(n > l)
  {
   *(d++) = r;
   *d = '\0';
   l++;
  }
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(0);
 return(-1);
}

canonical_original_code:
int argncpy(char *dst, unsigned long n, char *src, char *sep, int arg, int opt)
{
 struct arg_t s;
 char *d;
 unsigned long l;
 int r;
 argopts(&s, src, sep, opt);
 d = dst;
 *d = '\0';
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(0);
   d = dst;
   *d = '\0';
   l = 0;
   continue;
  }
  if(n > l)
  {
   *(d++) = r;
   *d = '\0';
   l++;
  }
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(0);
 return(-1);
}

variable_types:
dst
char *

variable_types:
n
unsigned long

variable_types: arg int

variable_types: opt int

variable_types: struct arg_t { char *s; char *sep; char opts; char quote; }

variable_types:
d
char *

variable_types:
l
unsigned long

variable_types: r int


arglen

decompiled_code:
__int64 __fastcall arglen(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
char v4; // r13
__int64 v6; // rbx
char v7; // bp
__int64 result; // rax
char *v9[9]; // [rsp+0h] [rbp-48h] BYREF

v4 = a4;
v6 = 0LL;
v7 = ((a4 >> 3) ^ 1) & 1;
argopts((__int64)v9, a1, a2, a4);
while ( 1 )
{
result = arggetc(v9);
if ( (_DWORD)result == -1 )
break;
while ( (_DWORD)result != -2 )
{
++v6;
result = arggetc(v9);
if ( (_DWORD)result == -1 )
goto LABEL_5;
}
if ( v7 && !v6 )
{
v6 = 0LL;
}
else
{
if ( !a3 )
return (unsigned int)v6;
--a3;
v6 = 0LL;
}
}
LABEL_5:
if ( !a3 && ((v4 & 8) != 0 || v6) )
return (unsigned int)v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, unsigned int a4)
{
char v4; // r13
__int64 v6; // rbx
char v7; // bp
__int64 result; // rax
char *v9[9]; // [rsp+0h] [rbp-48h] BYREF

v4 = a4;
v6 = 0LL;
v7 = ((a4 >> 3) ^ 1) & 1;
func1((__int64)v9, a1, a2, a4);
while ( 1 )
{
result = func0(v9);
if ( (_DWORD)result == -1 )
break;
while ( (_DWORD)result != -2 )
{
++v6;
result = func0(v9);
if ( (_DWORD)result == -1 )
goto LABEL_5;
}
if ( v7 && !v6 )
{
v6 = 0LL;
}
else
{
if ( !a3 )
return (unsigned int)v6;
--a3;
v6 = 0LL;
}
}
LABEL_5:
if ( !a3 && ((v4 & 8) != 0 || v6) )
return (unsigned int)v6;
return result;
}

original_code:
int arglen(char *src, char *sep, int arg, int opt)
{
 arg_t s;
 size_t l;
 int r;
 argopts(&s, src, sep, opt);
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(l);
   l = 0;
   continue;
  }
  l++;
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(l);
 return(-1);
}

canonical_original_code:
int arglen(char *src, char *sep, int arg, int opt)
{
 struct arg_t s;
 unsigned long l;
 int r;
 argopts(&s, src, sep, opt);
 l = 0;
 while((r = arggetc(&s)) != (-1))
 {
  if(r == (-2))
  {
   if(!(opt & (1 << 3)) && !l) continue;
   if(!arg--) return(l);
   l = 0;
   continue;
  }
  l++;
 }
 if(!arg && !(!(opt & (1 << 3)) && !l)) return(l);
 return(-1);
}


argcount

decompiled_code:
__int64 __fastcall argcount(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int i; // er12

for ( i = 0; (int)arglen(a1, a2, i, a3) >= 0; ++i )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int i; // er12

for ( i = 0; (int)func3(a1, a2, i, a3) >= 0; ++i )
;
return i;
}

original_code:
int argcount(char *src, char *sep, int opt)
{
 int count = 0;
 while(arglen(src, sep, count, opt) >= 0)
  count++;
 return(count);
}

variable_types: count int


argtol

decompiled_code:
__int64 __fastcall argtol(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, int a5)
{
char *v6; // rax
char *v7; // rbp
int *v8; // rax
int v9; // edx
int *v10; // rbx
__int64 v11; // r12
__int64 v12; // rax

v6 = argdup(a1, a2, a3, a4);
if ( !v6 )
return -1LL;
v7 = v6;
v8 = _errno_location();
v9 = a5;
*v8 = 0;
v10 = v8;
v11 = -1LL;
v12 = strtol(v7, 0LL, v9);
if ( !*v10 )
v11 = v12;
free(v7);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, int a5)
{
char *v6; // rax
char *v7; // rbp
int *v8; // rax
int v9; // edx
int *v10; // rbx
__int64 v11; // r12
__int64 v12; // rax

v6 = argdup(a1, a2, a3, a4);
if ( !v6 )
return -1LL;
v7 = v6;
v8 = _errno_location();
v9 = a5;
*v8 = 0;
v10 = v8;
v11 = -1LL;
v12 = strtol(v7, 0LL, v9);
if ( !*v10 )
v11 = v12;
free(v7);
return v11;
}

original_code:
long argtol(char *src, char *sep, int arg, int opt, int base)
{
 char *str;
 long val;
 str = argdup(src, sep, arg, opt);
 if(!str) return(-1);
 (*__errno_location ()) = 0;
 val = strtol(str, ((void *)0), base);
 if((*__errno_location ())) val = -1;
 free(str);
 return(val);
}

variable_types: base int

variable_types:
str
char *

variable_types: val long

return_type: long


decompiled_code:
__int64 __fastcall parse_font(char *src, void **a2, int *a3)
{
size_t v4; // r12
char *v5; // rax
char *v6; // r13
int v7; // eax
char *v8; // rax

if ( a3 == 0LL || a2 == 0LL || !src )
return 0xFFFFFFFFLL;
v4 = strlen(src);
v5 = strrchr(src, 58);
v6 = v5;
if ( v5 )
{
v7 = atoi(v5 + 1);
if ( v7 > 0 )
{
*a3 = v7;
v4 = v6 - src;
}
}
if ( *a2 )
free(*a2);
v8 = (char *)calloc(v4 + 1, 1uLL);
*a2 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
strncpy(v8, src, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src, void **a2, int *a3)
{
size_t v4; // r12
char *v5; // rax
char *v6; // r13
int v7; // eax
char *v8; // rax

if ( a3 == 0LL || a2 == 0LL || !src )
return 0xFFFFFFFFLL;
v4 = strlen(src);
v5 = strrchr(src, 58);
v6 = v5;
if ( v5 )
{
v7 = atoi(v5 + 1);
if ( v7 > 0 )
{
*a3 = v7;
v4 = v6 - src;
}
}
if ( *a2 )
free(*a2);
v8 = (char *)calloc(v4 + 1, 1uLL);
*a2 = v8;
if ( !v8 )
return 0xFFFFFFFFLL;
strncpy(v8, src, v4);
return 0LL;
}

original_code:
int parse_font(char *src, char **font, int *fontsize)
{
 char *p;
 size_t l;
 if(!src || !font || !fontsize) return(-1);
 l = strlen(src);
 if((p = strrchr(src, ':')))
 {
  int i = atoi(p + 1);
  if(i > 0)
  {
   *fontsize = i;
   l = p - src;
  }
 }
 if(*font) free(*font);
 *font = (char *) calloc(l + 1, 1);
 if(!*font) return(-1);
 strncpy(*font, src, l);
 return(0);
}

canonical_original_code:
int parse_font(char *src, char **font, int *fontsize)
{
 char *p;
 unsigned long l;
 if(!src || !font || !fontsize) return(-1);
 l = strlen(src);
 if((p = strrchr(src, ':')))
 {
  int i = atoi(p + 1);
  if(i > 0)
  {
   *fontsize = i;
   l = p - src;
  }
 }
 if(*font) free(*font);
 *font = (char *) calloc(l + 1, 1);
 if(!*font) return(-1);
 strncpy(*font, src, l);
 return(0);
}

variable_types:
font
char **

variable_types:
fontsize
int *

variable_types:
p
char *

variable_types: i int


strtrim

decompiled_code:
const char *__fastcall strtrim(const char *a1, const char *a2)
{
char *v2; // rbp
const char *v3; // r12
char i; // r14
size_t v5; // rbx
const char *result; // rax

v2 = (char *)a1;
v3 = &a1[strspn(a1, a2)];
for ( i = *v3; *v3; i = *v3 )
{
v5 = strspn(v3, a2);
if ( v5 == strlen(v3) )
break;
++v3;
*v2++ = i;
}
result = v3;
*v2 = 0;
return result;
}

canonical_decompiled_code:
const char *__fastcall func7(const char *a1, const char *a2)
{
char *v2; // rbp
const char *v3; // r12
char i; // r14
size_t v5; // rbx
const char *result; // rax

v2 = (char *)a1;
v3 = &a1[strspn(a1, a2)];
for ( i = *v3; *v3; i = *v3 )
{
v5 = strspn(v3, a2);
if ( v5 == strlen(v3) )
break;
++v3;
*v2++ = i;
}
result = v3;
*v2 = 0;
return result;
}

original_code:
char *strtrim(char *str, char *ws)
{
 char *s = str;
 str += strspn(str, ws);
 while(*str != '\0' && strspn(str, ws) != strlen(str))
  *(s++) = *(str++);
 *s = '\0';
 return(str);
}

variable_types:
ws
char *

variable_types:
s
char *

return_type: char *


dpixGetMax

original_code:
int32_t
dpixGetMax(hc_dpix_t *dpix,
           double *pmaxval,
           int32_t *pxmaxloc,
           int32_t *pymaxloc)
{
 int32_t i, j, w, h, xmaxloc, ymaxloc;
 double *data;
 double maxval;
    if (!pmaxval && !pxmaxloc && !pymaxloc)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 32, (1), "nothing to do");
  return(-1);
 }
    if (pmaxval) *pmaxval = 0.0;
    if (pxmaxloc) *pxmaxloc = 0;
    if (pymaxloc) *pymaxloc = 0;
    if (!dpix)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 40, (1), "dpix not defined");
  return(-1);
 }
    maxval = -1.0e40;
    xmaxloc = 0;
    ymaxloc = 0;
    w = dpix->width;
 h = dpix->height;
    data = dpix->data;
    for (i = 0; i < h; i++)
 {
        for (j = 0; j < w; j++)
  {
            if( (*data) > maxval )
   {
                maxval = (*data);
                xmaxloc = j;
                ymaxloc = i;
            }
   data++;
        }
    }
    if (pmaxval) *pmaxval = maxval;
    if (pxmaxloc) *pxmaxloc = xmaxloc;
    if (pymaxloc) *pymaxloc = ymaxloc;
    return 0;
}

canonical_original_code:
int dpixGetMax(struct hc_dpix_t *dpix, double *pmaxval, int *pxmaxloc, int *pymaxloc)
{
 int i; int j; int w; int h; int xmaxloc; int ymaxloc;
 double *data;
 double maxval;
    if (!pmaxval && !pxmaxloc && !pymaxloc)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 32, (1), "nothing to do");
  return(-1);
 }
    if (pmaxval) *pmaxval = 0.0;
    if (pxmaxloc) *pxmaxloc = 0;
    if (pymaxloc) *pymaxloc = 0;
    if (!dpix)
 {
        log_msg("fft.c", (char *) __FUNCTION__, 40, (1), "dpix not defined");
  return(-1);
 }
    maxval = -1.0e40;
    xmaxloc = 0;
    ymaxloc = 0;
    w = dpix->width;
 h = dpix->height;
    data = dpix->data;
    for (i = 0; i < h; i++)
 {
        for (j = 0; j < w; j++)
  {
            if( (*data) > maxval )
   {
                maxval = (*data);
                xmaxloc = j;
                ymaxloc = i;
            }
   data++;
        }
    }
    if (pmaxval) *pmaxval = maxval;
    if (pxmaxloc) *pxmaxloc = xmaxloc;
    if (pymaxloc) *pymaxloc = ymaxloc;
    return 0;
}

variable_types: struct hc_dpix_t { unsigned int width; unsigned int height; double *data; } *

variable_types:
pmaxval
double *

variable_types:
pxmaxloc
int *

variable_types:
pymaxloc
int *

variable_types: j int

variable_types: w int

variable_types: h int

variable_types: xmaxloc int

variable_types: ymaxloc int

variable_types:
data
double *

variable_types: maxval double


dpixNormalize

decompiled_code:
__int64 __fastcall dpixNormalize(int *a1)
{
int v2; // edi
int v3; // esi
double *v4; // rax
int i; // ecx
double *v6; // rdx
double v7; // xmm0_8
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
v3 = a1[1];
v4 = (double *)*((_QWORD *)a1 + 1);
if ( v3 )
{
for ( i = 0; i != v3; ++i )
{
v6 = &v4[(unsigned int)(v2 - 1) + 1];
if ( v2 )
{
do
{
v7 = *v4++;
*(v4 - 1) = v7 / (double)(v3 * v2);
}
while ( v4 != v6 );
}
}
}
result = 0LL;
}
else
{
log_msg("fft.c", "dpixNormalize", 104LL, 1LL, "dpixs not defined");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v2; // edi
int v3; // esi
double *v4; // rax
int i; // ecx
double *v6; // rdx
double v7; // xmm0_8
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
v3 = a1[1];
v4 = (double *)*((_QWORD *)a1 + 1);
if ( v3 )
{
for ( i = 0; i != v3; ++i )
{
v6 = &v4[(unsigned int)(v2 - 1) + 1];
if ( v2 )
{
do
{
v7 = *v4++;
*(v4 - 1) = v7 / (double)(v3 * v2);
}
while ( v4 != v6 );
}
}
}
result = 0LL;
}
else
{
log_msg("fft.c", "dpixNormalize", 104LL, 1LL, "dpixs not defined");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int32_t
dpixNormalize(hc_dpix_t *dpixs)
{
 int32_t i, j;
 double *data, n;
    if (!dpixs)
 {
  log_msg("fft.c", (char *) __FUNCTION__, 104, (1), "dpixs not defined");
  return(-1);
 }
 n = dpixs->width * dpixs->height;
 data = dpixs->data;
 for (i = 0; i < dpixs->height; i++)
  for (j = 0; j < dpixs->width; j++)
  {
   *data = (*data)/n;
   data++;
  }
 return 0;
}

canonical_original_code:
int dpixNormalize(struct hc_dpix_t *dpixs)
{
 int i; int j;
 double *data; double n;
    if (!dpixs)
 {
  log_msg("fft.c", (char *) __FUNCTION__, 104, (1), "dpixs not defined");
  return(-1);
 }
 n = dpixs->width * dpixs->height;
 data = dpixs->data;
 for (i = 0; i < dpixs->height; i++)
  for (j = 0; j < dpixs->width; j++)
  {
   *data = (*data)/n;
   data++;
  }
 return 0;
}

variable_types: n double

user_defined_types: struct hc_dpix_t { unsigned int width; unsigned int height; double *data; }


decompiled_code:
void __fastcall log_set_fd(int a1)
{
fd_log = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
fd_log = a1;
}

original_code:
void log_set_fd(int fd)
{
 fd_log = fd;
}

variable_types: fd int


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

if ( fd_log != 2 && !use_syslog )
{
result = close(fd_log);
fd_log = 2;
}
return result;
}

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

if ( fd_log != 2 && !use_syslog )
{
result = close(fd_log);
fd_log = 2;
}
return result;
}

original_code:
void log_close()
{
 if(fd_log == 2 || use_syslog) return;
 close(fd_log);
 fd_log = 2;
}


decompiled_code:
void __fastcall log_verbose(char a1)
{
verbose = a1;
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
verbose = a1;
}

original_code:
void log_verbose(char v)
{
 verbose = v;
}

variable_types: v char


decompiled_code:
void __fastcall log_quiet(char a1)
{
quiet = a1;
}

canonical_decompiled_code:
void __fastcall func3(char a1)
{
quiet = a1;
}

original_code:
void log_quiet(char v)
{
 quiet = v;
}

canonical_original_code:
void log_quiet(char v)
{
 quiet = v;
}


decompiled_code:
void __fastcall log_syslog(char a1)
{
use_syslog = a1;
if ( a1 )
openlog("test", 3, 8);
else
closelog();
}

canonical_decompiled_code:
void __fastcall func4(char a1)
{
use_syslog = a1;
if ( a1 )
openlog("test", 3, 8);
else
closelog();
}

original_code:
void log_syslog(char v)
{
 use_syslog = v;
 if(use_syslog) openlog("test", 0x01 | 0x02, (1<<3));
 else closelog();
}


decompiled_code:
char *__fastcall vmake_message(char *format, const __m128i *a2)
{
char *v2; // r12
int v3; // ebx
size_t v4; // r13
char *v5; // rax
__m128i v6; // xmm0
int v7; // eax
char *v9; // rdi
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v11; // [rsp+18h] [rbp-30h]

v2 = (char *)malloc(0x64uLL);
if ( v2 )
{
v3 = 100;
v4 = 100LL;
while ( 1 )
{
v6 = _mm_loadu_si128(a2);
v11 = a2[1].m128i_i64[0];
arg = v6;
v7 = vsnprintf(v2, v4, format, &arg);
if ( v7 < (unsigned int)v3 )
break;
v3 *= 2;
if ( v7 >= 0 )
v3 = v7 + 1;
v4 = v3;
v5 = (char *)realloc(v2, v3);
if ( !v5 )
{
v9 = v2;
v2 = 0LL;
free(v9);
return v2;
}
v2 = v5;
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func5(char *format, const __m128i *a2)
{
char *v2; // r12
int v3; // ebx
size_t v4; // r13
char *v5; // rax
__m128i v6; // xmm0
int v7; // eax
char *v9; // rdi
__m128i arg; // [rsp+8h] [rbp-40h] BYREF
__int64 v11; // [rsp+18h] [rbp-30h]

v2 = (char *)malloc(0x64uLL);
if ( v2 )
{
v3 = 100;
v4 = 100LL;
while ( 1 )
{
v6 = _mm_loadu_si128(a2);
v11 = a2[1].m128i_i64[0];
arg = v6;
v7 = vsnprintf(v2, v4, format, &arg);
if ( v7 < (unsigned int)v3 )
break;
v3 *= 2;
if ( v7 >= 0 )
v3 = v7 + 1;
v4 = v3;
v5 = (char *)realloc(v2, v3);
if ( !v5 )
{
v9 = v2;
v2 = 0LL;
free(v9);
return v2;
}
v2 = v5;
}
}
return v2;
}

original_code:
char *vmake_message(const char *fmt, va_list ap)
{
 int n, size = 100;
 char *p;
 p = (char *) malloc(size);
 if(!p) return(((void *)0));
 while(1)
 {
  char *np;
  va_list apc;
  __builtin_va_copy(apc,ap);
  n = vsnprintf(p, size, fmt, apc);
  if(n > -1 && n < size) return(p);
  if(n > -1) size = n + 1;
  else size *= 2;
  np = (char *) realloc(p, size);
  if(!np)
  {
   free(p);
   return(((void *)0));
  }
  p = np;
 }
 free(p);
        return(((void *)0));
}

canonical_original_code:
char *vmake_message(char *fmt, __builtin_va_list ap)
{
 int n; int size = 100;
 char *p;
 p = (char *) malloc(size);
 if(!p) return(((void *)0));
 while(1)
 {
  char *np;
  __builtin_va_list apc;
  __builtin_va_copy(apc,ap);
  n = vsnprintf(p, size, fmt, apc);
  if(n > -1 && n < size) return(p);
  if(n > -1) size = n + 1;
  else size *= 2;
  np = (char *) realloc(p, size);
  if(!np)
  {
   free(p);
   return(((void *)0));
  }
  p = np;
 }
 free(p);
        return(((void *)0));
}

variable_types:
fmt
char *

variable_types: n int

variable_types: size int

variable_types:
p
char *

variable_types:
np
char *


decompiled_code:
char *make_message(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return vmake_message(a1, (const __m128i *)va);
}

canonical_decompiled_code:
char *func6(char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func5(a1, (const __m128i *)va);
}

original_code:
char *make_message(const char *fmt, ... )
{
 va_list ap;
 char *msg;
 __builtin_va_start(ap,fmt);
 msg = vmake_message(fmt, ap);
 __builtin_va_end(ap);
 return(msg);
}

canonical_original_code:
char *make_message(char *fmt, ...)
{
 __builtin_va_list ap;
 char *msg;
 __builtin_va_start(ap,fmt);
 msg = vmake_message(fmt, ap);
 __builtin_va_end(ap);
 return(msg);
}

variable_types:
msg
char *


decompiled_code:
void log_msg(__int64 a1, const char *a2, unsigned int a3, char a4, char *a5, ...)
{
char *v6; // rax
char *v7; // r12
char *v8; // rbp
char *v9; // rax
unsigned __int8 v10; // bl
int v11; // edi
__int64 v12; // rdx
size_t v13; // rax
gcc_va_list va; // [rsp+18h] [rbp-E0h] BYREF

if ( fd_log == -1 )
return;
if ( (a4 & 0xFB) == 0 )
goto LABEL_9;
if ( a4 == 5 )
{
if ( !verbose )
return;
goto LABEL_10;
}
if ( a4 == 2 )
{
LABEL_9:
if ( quiet )
return;
goto LABEL_10;
}
if ( a4 != 3 )
{
LABEL_10:
va_start(va, a5);
v9 = vmake_message(a5, (const __m128i *)va);
v7 = v9;
if ( !v9 )
return;
v8 = make_message("%s\n", v9);
goto LABEL_12;
}
if ( !verbose )
return;
va_start(va, a5);
v6 = vmake_message(a5, (const __m128i *)va);
v7 = v6;
if ( !v6 )
return;
v8 = make_message("%s,%i: %s\n", a2, a3, v6);
LABEL_12:
if ( !v8 )
{
free(v7);
return;
}
if ( fd_log == 2 )
{
if ( use_syslog )
goto LABEL_15;
v12 = 31LL;
if ( a4 != 1 )
{
v12 = 1LL;
if ( a4 != 4 )
{
v12 = 36LL;
if ( a4 != 3 )
v12 = 0LL;
}
}
fprintf(stderr, "\x1B[%im", v12);
}
if ( use_syslog )
{
LABEL_15:
v10 = a4 - 1;
v11 = 6;
if ( v10 <= 2u )
v11 = CSWTCH_28[v10];
syslog(v11, "%s", v8);
goto LABEL_18;
}
v13 = strlen(v8);
write(fd_log, v8, v13);
LABEL_18:
if ( fd_log == 2 && !use_syslog )
fprintf(stderr, "\x1B[%im", 0LL);
free(v7);
free(v8);
}

canonical_decompiled_code:
void func7(__int64 a1, const char *a2, unsigned int a3, char a4, char *a5, ...)
{
char *v6; // rax
char *v7; // r12
char *v8; // rbp
char *v9; // rax
unsigned __int8 v10; // bl
int v11; // edi
__int64 v12; // rdx
size_t v13; // rax
gcc_va_list va; // [rsp+18h] [rbp-E0h] BYREF

if ( fd_log == -1 )
return;
if ( (a4 & 0xFB) == 0 )
goto LABEL_9;
if ( a4 == 5 )
{
if ( !verbose )
return;
goto LABEL_10;
}
if ( a4 == 2 )
{
LABEL_9:
if ( quiet )
return;
goto LABEL_10;
}
if ( a4 != 3 )
{
LABEL_10:
va_start(va, a5);
v9 = func5(a5, (const __m128i *)va);
v7 = v9;
if ( !v9 )
return;
v8 = func6("%s\n", v9);
goto LABEL_12;
}
if ( !verbose )
return;
va_start(va, a5);
v6 = func5(a5, (const __m128i *)va);
v7 = v6;
if ( !v6 )
return;
v8 = func6("%s,%i: %s\n", a2, a3, v6);
LABEL_12:
if ( !v8 )
{
free(v7);
return;
}
if ( fd_log == 2 )
{
if ( use_syslog )
goto LABEL_15;
v12 = 31LL;
if ( a4 != 1 )
{
v12 = 1LL;
if ( a4 != 4 )
{
v12 = 36LL;
if ( a4 != 3 )
v12 = 0LL;
}
}
fprintf(stderr, "\x1B[%im", v12);
}
if ( use_syslog )
{
LABEL_15:
v10 = a4 - 1;
v11 = 6;
if ( v10 <= 2u )
v11 = CSWTCH_28[v10];
syslog(v11, "%s", v8);
goto LABEL_18;
}
v13 = strlen(v8);
write(fd_log, v8, v13);
LABEL_18:
if ( fd_log == 2 && !use_syslog )
fprintf(stderr, "\x1B[%im", 0LL);
free(v7);
free(v8);
}

original_code:
void log_msg(char *file, char *function, int line, char l, char *s, ... )
{
 va_list ap;
 char *msg, *o;
 if(fd_log == -1) return;
 if(l == (0) && quiet) return;
 if(l == (4) && quiet) return;
 if(l == (5) && !verbose) return;
 if(l == (2) && quiet) return;
 if(l == (3) && !verbose) return;
 __builtin_va_start(ap,s);
 msg = vmake_message(s, ap);
 __builtin_va_end(ap);
 if(!msg) return;
 o = ((void *)0);
 if(l == (3)) o = make_message("%s,%i: %s\n", function, line, msg);
 else o = make_message("%s\n", msg);
 if(!o)
 {
  free(msg);
  return;
 }
 if(fd_log == 2 && !use_syslog)
 {
  int colour = -1;
  if(l == (1)) colour = (31);
  else if(l == (4)) colour = (1);
  else if(l == (3)) colour = (36);
  else colour = (0);
  if(!use_syslog) fprintf(stderr, "\033[%im", colour);
 }
 if(!use_syslog) write(fd_log, o, strlen(o));
 else
 {
  int p = 6;
  switch(l)
  {
  case (1): p = 3; break;
  case (2): p = 4; break;
  case (3): p = 7; break;
  }
  syslog(p, "%s", o);
 }
 if(fd_log == 2 && !use_syslog) fprintf(stderr, "\033[%im", (0));
 free(msg);
 free(o);
}

canonical_original_code:
void log_msg(char *file, char *function, int line, char l, char *s, ...)
{
 __builtin_va_list ap;
 char *msg; char *o;
 if(fd_log == -1) return;
 if(l == (0) && quiet) return;
 if(l == (4) && quiet) return;
 if(l == (5) && !verbose) return;
 if(l == (2) && quiet) return;
 if(l == (3) && !verbose) return;
 __builtin_va_start(ap,s);
 msg = vmake_message(s, ap);
 __builtin_va_end(ap);
 if(!msg) return;
 o = ((void *)0);
 if(l == (3)) o = make_message("%s,%i: %s\n", function, line, msg);
 else o = make_message("%s\n", msg);
 if(!o)
 {
  free(msg);
  return;
 }
 if(fd_log == 2 && !use_syslog)
 {
  int colour = -1;
  if(l == (1)) colour = (31);
  else if(l == (4)) colour = (1);
  else if(l == (3)) colour = (36);
  else colour = (0);
  if(!use_syslog) fprintf(stderr, "\033[%im", colour);
 }
 if(!use_syslog) write(fd_log, o, strlen(o));
 else
 {
  int p = 6;
  switch(l)
  {
  case (1): p = 3; break;
  case (2): p = 4; break;
  case (3): p = 7; break;
  }
  syslog(p, "%s", o);
 }
 if(fd_log == 2 && !use_syslog) fprintf(stderr, "\033[%im", (0));
 free(msg);
 free(o);
}

variable_types:
file
char *

variable_types:
function
char *

variable_types: line int

variable_types: l char

variable_types:
s
char *

variable_types:
o
char *

variable_types: colour int

variable_types: p int


decompiled_code:
__int64 __fastcall log_open(const char *a1)
{
unsigned int v1; // er12
int v3; // eax
int *v4; // rax
char *v5; // rax

v1 = 0;
if ( !a1 || use_syslog )
return v1;
v3 = open(a1, 1053761, 384LL);
v1 = v3;
if ( v3 == -1 )
{
log_msg((__int64)"log.c", "log_open", 0x3Au, 1, "Error opening log file '%s'...", a1);
v4 = _errno_location();
v5 = strerror(*v4);
log_msg((__int64)"log.c", "log_open", 0x3Bu, 1, "open: %s", v5);
return v1;
}
fd_log = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
unsigned int v1; // er12
int v3; // eax
int *v4; // rax
char *v5; // rax

v1 = 0;
if ( !a1 || use_syslog )
return v1;
v3 = open(a1, 1053761, 384LL);
v1 = v3;
if ( v3 == -1 )
{
func7((__int64)"log.c", "log_open", 0x3Au, 1, "Error opening log file '%s'...", a1);
v4 = _errno_location();
v5 = strerror(*v4);
func7((__int64)"log.c", "log_open", 0x3Bu, 1, "open: %s", v5);
return v1;
}
fd_log = v3;
return 0LL;
}

original_code:
int log_open(char *f)
{
 int fd;
 if(!f || use_syslog) return(0);
 fd = open(f, 0100 | 01 | 02000 | 04010000,
           0400 | 0200);
 if(fd == -1)
 {
  log_msg("log.c", (char *) __FUNCTION__, 58, (1), "Error opening log file '%s'...", f);
  log_msg("log.c", (char *) __FUNCTION__, 59, (1), "open: %s", strerror((*__errno_location ())));
  return(-1);
 }
 fd_log = fd;
 return(0);
}

variable_types:
f
char *


hcButterworthHiPassFilter

decompiled_code:
__int64 __fastcall hcButterworthHiPassFilter(__int128 a1, double a2)
{
_DWORD *v2; // rbp
__int64 v3; // r12

v2 = hcCreateButterworthHiPassFilter(*(_DWORD *)a1, *(_DWORD *)(a1 + 4), a2, (double)SDWORD2(a1));
double_save(*((_QWORD *)v2 + 1), (unsigned int)*v2, (unsigned int)v2[1], "filter.jpg");
*((_QWORD *)&a1 + 1) = v2;
v3 = hcApplyFilter(a1);
free(*((void **)v2 + 1));
free(v2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int128 a1, double a2)
{
_DWORD *v2; // rbp
__int64 v3; // r12

v2 = hcCreateButterworthHiPassFilter(*(_DWORD *)a1, *(_DWORD *)(a1 + 4), a2, (double)SDWORD2(a1));
double_save(*((_QWORD *)v2 + 1), (unsigned int)*v2, (unsigned int)v2[1], "filter.jpg");
*((_QWORD *)&a1 + 1) = v2;
v3 = func0(a1);
free(*((void **)v2 + 1));
free(v2);
return v3;
}

original_code:
hc_dpix_t *hcButterworthHiPassFilter( hc_dpix_t *src, double radius, uint32_t order)
{
 hc_dpix_t *filter;
 hc_dpix_t *result;
 filter = hcCreateButterworthHiPassFilter( src->width, src->height, radius, order);
 double_save(filter->data, filter->width, filter->height, "filter.jpg");
 result = hcApplyFilter( src, filter );
 free(filter->data);
 free(filter);
 return result;
}

canonical_original_code:
struct hc_dpix_t *hcButterworthHiPassFilter(struct hc_dpix_t *src, double radius, unsigned int order)
{
 struct hc_dpix_t *filter;
 struct hc_dpix_t *result;
 filter = hcCreateButterworthHiPassFilter( src->width, src->height, radius, order);
 double_save(filter->data, filter->width, filter->height, "filter.jpg");
 result = hcApplyFilter( src, filter );
 free(filter->data);
 free(filter);
 return result;
}

variable_types:
src
struct hc_dpix_t *

variable_types: radius double

variable_types:
order
unsigned int

variable_types: struct hc_dpix_t { unsigned int width; unsigned int height; double *data; } *


main

repo: hdevalence/binary-power

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+20h] [rbp-10h]
unsigned int v5; // [rsp+24h] [rbp-Ch]
unsigned int v6; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v6 = atoi(argv[1]);
v5 = atoi(argv[2]);
v4 = atoi(argv[3]);
for ( i = 0; i <= 99999999; ++i )
binary_exp_c(v6, v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+20h] [rbp-10h]
unsigned int v5; // [rsp+24h] [rbp-Ch]
unsigned int v6; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]

v6 = atoi(argv[1]);
v5 = atoi(argv[2]);
v4 = atoi(argv[3]);
for ( i = 0; i <= 99999999; ++i )
func7(v6, v5, v4);
return 0;
}

original_code:
int __attribute__((optimize("O0"))) main(int argc, char** argv)
{
 uint32_t x = atoi(argv[1]);
 uint32_t a = atoi(argv[2]);
 uint32_t p = atoi(argv[3]);
 uint32_t y;
 for(int i = 0; i < 100000000; ++i) {
  y = binary_exp_c(x,a,p);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned int x = atoi(argv[1]);
 unsigned int a = atoi(argv[2]);
 unsigned int p = atoi(argv[3]);
 unsigned int y;
 for(int i = 0; i < 100000000; ++i) {
  y = binary_exp_c(x,a,p);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
x
unsigned int

variable_types:
a
unsigned int

variable_types:
p
unsigned int

variable_types:
y
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall binary_exp_c(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8

if ( a2 > 1 )
{
v3 = 1;
do
{
if ( (a2 & 1) != 0 )
v3 = a1 * v3 % a3;
a2 >>= 1;
a1 = a1 * a1 % a3;
}
while ( a2 != 1 );
a1 *= v3;
}
return a1 % a3;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8

if ( a2 > 1 )
{
v3 = 1;
do
{
if ( (a2 & 1) != 0 )
v3 = a1 * v3 % a3;
a2 >>= 1;
a1 = a1 * a1 % a3;
}
while ( a2 != 1 );
a1 *= v3;
}
return a1 % a3;
}

original_code:
uint32_t binary_exp_c(uint32_t x, uint32_t a, uint32_t p)
{
 uint32_t r = 1;
 uint32_t y = x;
 while (a>1) {
  if (a & 1)
   r = ((r*y) % p);
  y = ((y*y) % p);
  a >>= 1;
 }
 return ((r*y) % p);
}

canonical_original_code:
unsigned int binary_exp_c(unsigned int x, unsigned int a, unsigned int p)
{
 unsigned int r = 1;
 unsigned int y = x;
 while (a>1) {
  if (a & 1)
   r = ((r*y) % p);
  y = ((y*y) % p);
  a >>= 1;
 }
 return ((r*y) % p);
}

variable_types:
r
unsigned int


decompiled_code:
__int64 __fastcall montgomery_ladder(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned int v4; // eax
unsigned int v5; // edi
signed int v6; // ecx
bool v7; // cf

v3 = a1;
_BitScanReverse(&v4, a2);
v5 = a1 * a1 % a3;
v6 = 30 - (v4 ^ 0x1F);
if ( v6 >= 0 )
{
do
{
while ( (a2 & (1 << v6)) != 0 )
{
v3 = v5 * v3 % a3;
v5 = v5 * v5 % a3;
v7 = v6-- == 0;
if ( v7 )
return v3;
}
v5 = v5 * v3 % a3;
v3 = v3 * v3 % a3;
v7 = v6-- == 0;
}
while ( !v7 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
unsigned int v4; // eax
unsigned int v5; // edi
signed int v6; // ecx
bool v7; // cf

v3 = a1;
_BitScanReverse(&v4, a2);
v5 = a1 * a1 % a3;
v6 = 30 - (v4 ^ 0x1F);
if ( v6 >= 0 )
{
do
{
while ( (a2 & (1 << v6)) != 0 )
{
v3 = v5 * v3 % a3;
v5 = v5 * v5 % a3;
v7 = v6-- == 0;
if ( v7 )
return v3;
}
v5 = v5 * v3 % a3;
v3 = v3 * v3 % a3;
v7 = v6-- == 0;
}
while ( !v7 );
}
return v3;
}

canonical_original_code:
unsigned int montgomery_ladder(unsigned int x, unsigned int a, unsigned int p)
{
 unsigned int x1 = x;
 unsigned int x2 = ((x*x) % p);
 int k = 31-__builtin_clz(a);
 for(int i = k-1; i >= 0; --i) {
  if( a & (1 << i)) {
   x1 = ((x1*x2) % p);
   x2 = ((x2*x2) % p);
  } else {
   x2 = ((x1*x2) % p);
   x1 = ((x1*x1) % p);
  }
 }
 return x1;
}

variable_types: k int