decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
timer_t timerid; // [rsp+0h] [rbp-80h] BYREF
char msgp[16]; // [rsp+8h] [rbp-78h] BYREF
struct itimerspec value; // [rsp+18h] [rbp-68h] BYREF
struct sigevent evp; // [rsp+38h] [rbp-48h] BYREF

*(_OWORD *)&evp.sigev_value.sival_int = 0LL;
evp._sigev_un._sigev_thread._attribute = 0LL;
evp.sigev_value.sival_int = 111;
evp.sigev_notify = 2;
evp._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
*((_OWORD *)&evp._sigev_un._sigev_thread + 1) = 0LL;
*((_OWORD *)&evp._sigev_un._sigev_thread + 2) = 0LL;
if ( timer_create(1, &evp, &timerid) == -1 )
{
perror("fail to timer_create");
exit(-1);
}
value.it_interval.tv_sec = 2LL;
value.it_interval.tv_nsec = 0LL;
value.it_value.tv_sec = 5LL;
value.it_value.tv_nsec = 0LL;
if ( timer_settime(timerid, 0, &value, 0LL) == -1 )
{
perror("fail to timer_settime");
exit(-1);
}
puts("waiting for alarm to go off");
v3 = msgget(0, 950);
if ( v3 >= 0 )
{
puts("msgget success.");
if ( msgrcv(v3, msgp, 1uLL, 0LL, 0) == -1 )
perror("msgrcv fail");
puts("done");
exit(0);
}
perror("msgget fail");
return 0;
}

original_code:
int main()
{
    int nMsgID = -1;
    timer_t timerid;
    struct sigevent evp;
    memset(&evp, 0, sizeof(struct sigevent));
    evp.sigev_value.sival_int = 111;
    evp.sigev_notify = SIGEV_THREAD;
    evp._sigev_un._sigev_thread._function = timer_thread;
    if (timer_create(1, &evp, &timerid) == -1)
    {
        perror("fail to timer_create");
        exit(-1);
    }
    struct itimerspec it;
    it.it_interval.tv_sec = 2;
    it.it_interval.tv_nsec = 0;
    it.it_value.tv_sec = 5;
    it.it_value.tv_nsec = 0;
    if (timer_settime(timerid, 0, &it, ((void *)0)) == -1)
    {
        perror("fail to timer_settime");
        exit(-1);
    }
    printf("waiting for alarm to go off\n");
    nMsgID = msgget(((__key_t) 0), 0666 | 01000);
    if( nMsgID < 0 )
    {
        perror("msgget fail" );
        return;
    }
    printf("msgget success.\n");
    struct msgst msg_st;
    if( -1 == msgrcv( nMsgID, (void*)&msg_st, 1, 0, 0 ) )
    {
        perror("msgrcv fail");
    }
    printf("done\n");
    exit(0);
}

canonical_original_code:
int main()
{
    int nMsgID = -1;
    void *timerid;
    struct sigevent evp;
    memset(&evp, 0, sizeof(struct sigevent));
    evp.sigev_value.sival_int = 111;
    evp.sigev_notify = SIGEV_THREAD;
    evp._sigev_un._sigev_thread._function = timer_thread;
    if (timer_create(1, &evp, &timerid) == -1)
    {
        perror("fail to timer_create");
        exit(-1);
    }
    struct itimerspec it;
    it.it_interval.tv_sec = 2;
    it.it_interval.tv_nsec = 0;
    it.it_value.tv_sec = 5;
    it.it_value.tv_nsec = 0;
    if (timer_settime(timerid, 0, &it, ((void *)0)) == -1)
    {
        perror("fail to timer_settime");
        exit(-1);
    }
    printf("waiting for alarm to go off\n");
    nMsgID = msgget(((int) 0), 0666 | 01000);
    if( nMsgID < 0 )
    {
        perror("msgget fail" );
        return;
    }
    printf("msgget success.\n");
    struct msgst msg_st;
    if( -1 == msgrcv( nMsgID, (void *)&msg_st, 1, 0, 0 ) )
    {
        perror("msgrcv fail");
    }
    printf("done\n");
    exit(0);
}

variable_types:
timerid
void *

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

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

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

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

user_defined_types: struct msgst { long msg_type; char buf[1]; }


main

canonical_name: main

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

v3 = syscall(39LL, argv, envp);
v4 = getpid();
printf(" syscall: %d,\t\tusermode-API: %d \n\n", v3, v4);
return 0;
}

original_code:
int main ()
{
 int sys_pid = syscall(39);
 int api_pid = getpid();
 printf (" syscall: %d,\t\tusermode-API: %d \n\n", sys_pid, api_pid );
 return 0;
}

canonical_original_code:
int main()
{
 int sys_pid = syscall(39);
 int api_pid = getpid();
 printf (" syscall: %d,\t\tusermode-API: %d \n\n", sys_pid, api_pid );
 return 0;
}

return_type: int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er12
__int64 v5; // r14
__int64 v6; // r13
double v8; // [rsp+0h] [rbp-58h]
double v9; // [rsp+0h] [rbp-58h]
double v10; // [rsp+8h] [rbp-50h]
double v11; // [rsp+8h] [rbp-50h]
struct timezone tz; // [rsp+18h] [rbp-40h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF

if ( argc != 3 )
{
printf("Usage: %s <max num> <num threads>\n", *argv);
exit(-1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
gettimeofday(&tv, &tz);
v8 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
v5 = sieve_parallel(v3);
gettimeofday(&tv, &tz);
v9 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec) - v8;
gettimeofday(&tv, &tz);
v10 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
v6 = sieve_serial(v3);
gettimeofday(&tv, &tz);
v11 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec) - v10;
check(v6, v5, v3);
printf("n=%d\tt=%d\tSpeedup=%f\n", v3, v4, v11 / v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // er12
__int64 v5; // r14
__int64 v6; // r13
double v8; // [rsp+0h] [rbp-58h]
double v9; // [rsp+0h] [rbp-58h]
double v10; // [rsp+8h] [rbp-50h]
double v11; // [rsp+8h] [rbp-50h]
struct timezone tz; // [rsp+18h] [rbp-40h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF

if ( argc != 3 )
{
printf("Usage: %s <max num> <num threads>\n", *argv);
exit(-1);
}
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
gettimeofday(&tv, &tz);
v8 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
v5 = sieve_parallel(v3);
gettimeofday(&tv, &tz);
v9 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec) - v8;
gettimeofday(&tv, &tz);
v10 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
v6 = sieve_serial(v3);
gettimeofday(&tv, &tz);
v11 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec) - v10;
func9(v6, v5, v3);
printf("n=%d\tt=%d\tSpeedup=%f\n", v3, v4, v11 / v9);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int n, numThreads, sqrtN;
  int i,k;
  int *list_ser, *list_par;
  double time_ser, time_par, speedup;
  double time_start, time_end;
  struct timeval tv;
  struct timezone tz;
  if(argc != 3)
  {
    printf("Usage: %s <max num> <num threads>\n",argv[0]);
    exit(-1);
  }
  n = atoi(argv[1]);
  numThreads = atoi(argv[2]);
  gettimeofday(&tv, &tz);
  time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  list_par = sieve_parallel(n);
  gettimeofday(&tv, &tz);
  time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  time_par = time_end - time_start;
  gettimeofday(&tv, &tz);
  time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  list_ser = sieve_serial(n);
  gettimeofday(&tv, &tz);
  time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  time_ser = time_end - time_start;
  check(list_ser,list_par,n);
  speedup = time_ser/time_par;
  printf("n=%d\tt=%d\tSpeedup=%f\n",n,numThreads,speedup);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int n; int numThreads; int sqrtN;
  int i; int k;
  int *list_ser; int *list_par;
  double time_ser; double time_par; double speedup;
  double time_start; double time_end;
  struct timeval tv;
  struct timezone tz;
  if(argc != 3)
  {
    printf("Usage: %s <max num> <num threads>\n",argv[0]);
    exit(-1);
  }
  n = atoi(argv[1]);
  numThreads = atoi(argv[2]);
  gettimeofday(&tv, &tz);
  time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  list_par = sieve_parallel(n);
  gettimeofday(&tv, &tz);
  time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  time_par = time_end - time_start;
  gettimeofday(&tv, &tz);
  time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  list_ser = sieve_serial(n);
  gettimeofday(&tv, &tz);
  time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  time_ser = time_end - time_start;
  check(list_ser,list_par,n);
  speedup = time_ser/time_par;
  printf("n=%d\tt=%d\tSpeedup=%f\n",n,numThreads,speedup);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n int

variable_types: numThreads int

variable_types: sqrtN int

variable_types: i int

variable_types: k int

variable_types: speedup double

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

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


check

decompiled_code:
void __fastcall check(__int64 a1, __int64 a2, int a3)
{
__int64 v5; // rsi
__int64 v6; // rdx
__int64 v7; // rcx

if ( a3 > 1 )
{
v5 = 2LL;
do
{
v6 = *(unsigned int *)(a1 + 4 * v5);
v7 = *(unsigned int *)(a2 + 4 * v5);
if ( (_DWORD)v6 != (_DWORD)v7 )
{
printf("Error : Serial and OpenMP result do not match index=%d\tser=%d\tpar=%d\n", v5, v6, v7);
exit(-1);
}
++v5;
}
while ( a3 >= (int)v5 );
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, int a3)
{
__int64 v5; // rsi
__int64 v6; // rdx
__int64 v7; // rcx

if ( a3 > 1 )
{
v5 = 2LL;
do
{
v6 = *(unsigned int *)(a1 + 4 * v5);
v7 = *(unsigned int *)(a2 + 4 * v5);
if ( (_DWORD)v6 != (_DWORD)v7 )
{
printf("Error : Serial and OpenMP result do not match index=%d\tser=%d\tpar=%d\n", v5, v6, v7);
exit(-1);
}
++v5;
}
while ( a3 >= (int)v5 );
}
}

original_code:
void check(int *a, int *b, int n)
{
  int i;
  for(i=2;i<=n;i++)
    if(a[i]!=b[i])
    {
      printf("Error : Serial and OpenMP result do not match index=%d\tser=%d\tpar=%d\n",i,a[i],b[i]);
      exit(-1);
    }
}

variable_types:
a
int *

variable_types:
b
int *

return_type: void


repo: karibou/makedumpfile-next

decompiled_code:
__int64 cache_init()
{
char *v0; // rax
__int64 *v1; // rdx
__int64 result; // rax
int *v3; // rax
char *v4; // rax

cachebuf = (__int64)malloc(8LL * *(_QWORD *)(info + 648LL));
if ( cachebuf )
{
v0 = (char *)&entries;
v1 = &pool;
do
{
*v1 = (__int64)v0;
v0 += 48;
++v1;
}
while ( v0 != (char *)&unk_560 );
result = 1LL;
}
else
{
result = message_level & 4;
if ( (message_level & 4) != 0 )
{
fwrite("cache_init", 1uLL, 0xAuLL, stderr);
fwrite(&unk_560, 1uLL, 2uLL, stderr);
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Can't allocate memory for cache. %s\n", v4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax
__int64 *v1; // rdx
__int64 result; // rax
int *v3; // rax
char *v4; // rax

cachebuf = (__int64)malloc(8LL * *(_QWORD *)(info + 648LL));
if ( cachebuf )
{
v0 = (char *)&entries;
v1 = &pool;
do
{
*v1 = (__int64)v0;
v0 += 48;
++v1;
}
while ( v0 != (char *)&unk_560 );
result = 1LL;
}
else
{
result = message_level & 4;
if ( (message_level & 4) != 0 )
{
fwrite("cache_init", 1uLL, 0xAuLL, stderr);
fwrite(&unk_560, 1uLL, 2uLL, stderr);
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Can't allocate memory for cache. %s\n", v4);
result = 0LL;
}
}
return result;
}

original_code:
int
cache_init(void)
{
 int i;
 cachebuf = malloc(info->page_size * 8);
 if (cachebuf == ((void *)0)) {
  do { if (message_level & (0x004)) { fprintf(stderr, __FUNCTION__); fprintf(stderr, ": "); fprintf(stderr, "Can't allocate memory for cache. %s\n", strerror((*__errno_location ()))); } } while (0);
  return (0);
 }
 for (i = 0; i < 8; ++i)
  pool[i] = &entries[i];
 return (1);
}

canonical_original_code:
int cache_init()
{
 int i;
 cachebuf = malloc(info->page_size * 8);
 if (cachebuf == ((void *)0)) {
  do { if (message_level & (0x004)) { fprintf(stderr, __FUNCTION__); fprintf(stderr, ": "); fprintf(stderr, "Can't allocate memory for cache. %s\n", strerror((*__errno_location ()))); } } while (0);
  return (0);
 }
 for (i = 0; i < 8; ++i)
  pool[i] = &entries[i];
 return (1);
}


decompiled_code:
char *__fastcall cache_alloc(__int64 a1)
{
int v1; // eax
char *v2; // r12
__int64 v3; // rax
__int64 v4; // rdx
void (__fastcall *v6)(char *); // rax

v1 = avail;
if ( avail )
{
--avail;
v2 = (char *)pool[v1 - 1];
}
else
{
v2 = (char *)qword_398;
if ( !qword_398 )
return v2;
remove_entry(&used, qword_398);
v6 = (void (__fastcall *)(char *))*((_QWORD *)v2 + 5);
if ( v6 )
v6(v2);
}
v3 = info;
*(_QWORD *)v2 = a1;
v4 = *(_QWORD *)(v3 + 648);
*((_QWORD *)v2 + 5) = 0LL;
*((_QWORD *)v2 + 2) = v4;
*((_QWORD *)v2 + 1) = cachebuf + v4 * (int)(-1431655765 * ((v2 - (char *)&entries) >> 4));
add_entry((__int64 *)&pending, (__int64)v2);
return v2;
}

original_code:
struct cache_entry *
cache_alloc(unsigned long long paddr)
{
 struct cache_entry *entry = ((void *)0);
 int idx;
 if (avail) {
  entry = pool[--avail];
 } else if (used.tail) {
  entry = used.tail;
  remove_entry(&used, entry);
  if (entry->discard)
   entry->discard(entry);
 } else
  return ((void *)0);
 idx = entry - entries;
 entry->paddr = paddr;
 entry->bufptr = cachebuf + idx * info->page_size;
 entry->buflen = info->page_size;
 entry->discard = ((void *)0);
 add_entry(&pending, entry);
 return entry;
}

canonical_original_code:
struct cache_entry *cache_alloc(unsigned long long paddr)
{
 struct cache_entry *entry = ((void *)0);
 int idx;
 if (avail) {
  entry = pool[--avail];
 } else if (used.tail) {
  entry = used.tail;
  remove_entry(&used, entry);
  if (entry->discard)
   entry->discard(entry);
 } else
  return ((void *)0);
 idx = entry - entries;
 entry->paddr = paddr;
 entry->bufptr = cachebuf + idx * info->page_size;
 entry->buflen = info->page_size;
 entry->discard = ((void *)0);
 add_entry(&pending, entry);
 return entry;
}

variable_types:
paddr
unsigned long long

variable_types: struct cache_entry { unsigned long long paddr; void *bufptr; unsigned long buflen; struct cache_entry *next; void (*discard)(struct cache_entry *); } *

variable_types: idx int


decompiled_code:
__int64 __fastcall cache_free(__int64 a1)
{
__int64 result; // rax
int v2; // edx
__int64 v3; // rcx

remove_entry(pending, a1);
result = avail;
v2 = avail + 1;
pool[avail] = v3;
avail = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
int v2; // edx
__int64 v3; // rcx

func1(pending, a1);
result = avail;
v2 = avail + 1;
pool[avail] = v3;
avail = v2;
return result;
}

original_code:
void
cache_free(struct cache_entry *entry)
{
 remove_entry(&pending, entry);
 pool[avail++] = entry;
}

user_defined_types: struct cache_entry { unsigned long long paddr; void *bufptr; unsigned long buflen; struct cache_entry *next; void (*discard)(struct cache_entry *); }


main

repo: karl-nilsson/theseus

original_code:
int main(int argc, char **argv){
    setlocale(6, "en_US.UTF-8");
    size_t size = 10;
    int c;
    while((c=getopt(argc, argv, "s:")) != -1){
        switch(c){
            case 's':
                size = atoi(optarg);
                break;
            case '?':
            default:
                abort();
        }
    }
    srand(time(((void *)0)));
    cell **maze = malloc(size * sizeof(cell*));
    for(int i = 0; i < size; i++) {
        maze[i] = malloc(size * sizeof(cell));
    }
    for(int i = 0; i < size; i++) {
        for(int j = 0; j < size; j++) {
            maze[i][j].state = 0x00;
            maze[i][j].x_pos = j;
            maze[i][j].y_pos = i;
            maze[i][j].n = (i == 0 ? ((void *)0) : &maze[i-1][j]);
            maze[i][j].e = (j == size-1 ? ((void *)0) : &maze[i][j+1]);
            maze[i][j].s = (i == size-1 ? ((void *)0) : &maze[i+1][j]);
            maze[i][j].w = (j == 0 ? ((void *)0) : &maze[i][j-1]);
        }
    }
    cell **stack = malloc(size * size * sizeof(cell*));
    size_t stack_size = 0;
    cell cur = maze[0][0];
    cur.state = 0x10;
    stack[stack_size] = &cur;
    stack_size++;
    gen_maze(maze, stack, stack_size);
    maze[size-1][size-1].state += 0x20;
    print_maze(maze, size);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv){
    setlocale(6, "en_US.UTF-8");
    unsigned long size = 10;
    int c;
    while((c=getopt(argc, argv, "s:")) != -1){
        switch(c){
            case 's':
                size = atoi(optarg);
                break;
            case '?':
            default:
                abort();
        }
    }
    srand(time(((void *)0)));
    struct cell **maze = malloc(size * sizeof(cell*));
    for(int i = 0; i < size; i++) {
        maze[i] = malloc(size * sizeof(cell));
    }
    for(int i = 0; i < size; i++) {
        for(int j = 0; j < size; j++) {
            maze[i][j].state = 0x00;
            maze[i][j].x_pos = j;
            maze[i][j].y_pos = i;
            maze[i][j].n = (i == 0 ? ((void *)0) : &maze[i-1][j]);
            maze[i][j].e = (j == size-1 ? ((void *)0) : &maze[i][j+1]);
            maze[i][j].s = (i == size-1 ? ((void *)0) : &maze[i+1][j]);
            maze[i][j].w = (j == 0 ? ((void *)0) : &maze[i][j-1]);
        }
    }
    struct cell **stack = malloc(size * size * sizeof(cell*));
    unsigned long stack_size = 0;
    struct cell cur = maze[0][0];
    cur.state = 0x10;
    stack[stack_size] = &cur;
    stack_size++;
    gen_maze(maze, stack, stack_size);
    maze[size-1][size-1].state += 0x20;
    print_maze(maze, size);
    return 0;
}

variable_types:
argv
char **

variable_types:
size
unsigned long

variable_types: c int

variable_types: struct cell { unsigned char state; unsigned int x_pos; struct cell *n; } **

variable_types: j int


decompiled_code:
int __fastcall print_maze(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v3; // r13
__int64 v4; // r12
unsigned __int64 i; // r12
unsigned __int64 v6; // r14
__int64 v7; // rax
unsigned __int64 v8; // rbx

v3 = a2 + 2;
if ( a2 == -2LL )
{
putchar(10);
}
else
{
v4 = 0LL;
do
{
++v4;
putchar(45);
}
while ( v4 != v3 );
putchar(10);
if ( !a2 )
{
v3 = 2LL;
LABEL_10:
v8 = 0LL;
do
{
++v8;
putchar(45);
}
while ( v3 > v8 );
return putchar(10);
}
}
for ( i = 0LL; i < a2; ++i )
{
v6 = 0LL;
putchar(124);
do
{
v7 = 3 * v6++;
printf("%lc", *(_DWORD *)&tiles[4 * (*(_BYTE *)(*a1 + 16 * v7) & 0xF)]);
}
while ( a2 > v6 );
++a1;
puts("|");
}
if ( a2 != -2LL )
goto LABEL_10;
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func8(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v3; // r13
__int64 v4; // r12
unsigned __int64 i; // r12
unsigned __int64 v6; // r14
__int64 v7; // rax
unsigned __int64 v8; // rbx

v3 = a2 + 2;
if ( a2 == -2LL )
{
putchar(10);
}
else
{
v4 = 0LL;
do
{
++v4;
putchar(45);
}
while ( v4 != v3 );
putchar(10);
if ( !a2 )
{
v3 = 2LL;
LABEL_10:
v8 = 0LL;
do
{
++v8;
putchar(45);
}
while ( v3 > v8 );
return putchar(10);
}
}
for ( i = 0LL; i < a2; ++i )
{
v6 = 0LL;
putchar(124);
do
{
v7 = 3 * v6++;
printf("%lc", *(_DWORD *)&tiles[4 * (*(_BYTE *)(*a1 + 16 * v7) & 0xF)]);
}
while ( a2 > v6 );
++a1;
puts("|");
}
if ( a2 != -2LL )
goto LABEL_10;
return putchar(10);
}

original_code:
void print_maze(cell **maze, size_t size) {
    for(int i = 0; i < size+2; i++) {
        printf("-");
    }
    printf("\n");
    for(int i = 0; i < size; i++) {
        printf("|");
        for(int j = 0; j < size; j++) {
            printf("%lc", tiles[maze[i][j].state & 0x0F]);
        }
        printf("|\n");
    }
    for(int i = 0; i < size+2; i++) {
        printf("-");
    }
    printf("\n");
}

canonical_original_code:
void print_maze(struct cell **maze, unsigned long size) {
    for(int i = 0; i < size+2; i++) {
        printf("-");
    }
    printf("\n");
    for(int i = 0; i < size; i++) {
        printf("|");
        for(int j = 0; j < size; j++) {
            printf("%lc", tiles[maze[i][j].state & 0x0F]);
        }
        printf("|\n");
    }
    for(int i = 0; i < size+2; i++) {
        printf("-");
    }
    printf("\n");
}

user_defined_types: struct cell { unsigned char state; unsigned int x_pos; struct cell *n; }


visited

decompiled_code:
bool __fastcall visited(_BYTE *a1)
{
return *a1 != 0;
}

canonical_decompiled_code:
bool __fastcall func9(_BYTE *a1)
{
return *a1 != 0;
}

original_code:
_Bool visited(cell *c) {
    return (c->state && 0x40);
}

canonical_original_code:
_Bool visited(struct cell *c) {
    return (c->state && 0x40);
}

variable_types: struct cell { unsigned char state; unsigned int x_pos; struct cell *n; } *


decompiled_code:
__int64 __fastcall random_neighbor(__int64 a1, _QWORD *a2)
{
unsigned __int64 v2; // rbp
_QWORD *v3; // r12
__int64 v4; // rdx
__int64 v5; // rdx
_BYTE *v6; // rdx
__int64 v7; // rcx
__int64 v8; // rdx

v2 = 0LL;
v3 = malloc(0x20uLL);
if ( a2[2] && !visited((_BYTE *)a2[2]) )
{
*v3 = v4;
v2 = 1LL;
}
if ( a2[3] && !visited((_BYTE *)a2[3]) )
v3[v2++] = v5;
v6 = (_BYTE *)a2[5];
if ( a2[4] && !visited((_BYTE *)a2[4]) )
{
v3[v2++] = v7;
if ( !v6 || visited(v6) )
return v3[rand() % v2];
goto LABEL_11;
}
if ( v6 && !visited(v6) )
{
LABEL_11:
v3[v2++] = v8;
return v3[rand() % v2];
}
if ( v2 )
return v3[rand() % v2];
return 0LL;
}

original_code:
cell *random_neighbor(cell **maze, cell *src){
    size_t s = 0;
    cell **neighbors = malloc(4 * sizeof(cell*));
    if(src->n && ! visited(src->n)){
        neighbors[s] = src->n;
        s++;
    }
    if(src->e && ! visited(src->e)){
        neighbors[s] = src->e;
        s++;
    }
     if(src->s && ! visited(src->s)){
        neighbors[s] = src->s;
        s++;
    }
    if(src->w && ! visited(src->w) ){
        neighbors[s] = src->w;
        s++;
    }
    if(s){
        return neighbors[rand() % s];
    }else{
        return ((void *)0);
    }
}

canonical_original_code:
struct cell *random_neighbor(struct cell **maze, struct cell *src){
    unsigned long s = 0;
    struct cell **neighbors = malloc(4 * sizeof(cell*));
    if(src->n && ! visited(src->n)){
        neighbors[s] = src->n;
        s++;
    }
    if(src->e && ! visited(src->e)){
        neighbors[s] = src->e;
        s++;
    }
     if(src->s && ! visited(src->s)){
        neighbors[s] = src->s;
        s++;
    }
    if(src->w && ! visited(src->w) ){
        neighbors[s] = src->w;
        s++;
    }
    if(s){
        return neighbors[rand() % s];
    }else{
        return ((void *)0);
    }
}

variable_types:
maze
struct cell **

variable_types:
src
struct cell *

variable_types:
s
unsigned long

return_type: struct cell { unsigned char state; unsigned int x_pos; struct cell *n; } *


decompiled_code:
__int64 __fastcall cell_value(_BYTE *a1)
{
return *a1 & 0x3F;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
return *a1 & 0x3F;
}

original_code:
unsigned char cell_value(cell *c) {
    return 0x3F & c->state;
}

canonical_original_code:
unsigned char cell_value(struct cell *c) {
    return 0x3F & c->state;
}

return_type: unsigned char


main

repo: karlredgate/sumner-tunnel

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

if ( argc <= 5 )
{
fprintf(stderr, "usage: %s interface-name local-address local-port remote-address remote-port\n", *argv);
exit(-1);
}
v3 = tap_open(argv[1]);
v4 = socket_open(argv[2], argv[3], argv[4], argv[5]);
loop(v3, v4);
}

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

if ( argc <= 5 )
{
fprintf(stderr, "usage: %s interface-name local-address local-port remote-address remote-port\n", *argv);
exit(-1);
}
v3 = func7(argv[1]);
v4 = func9(argv[2], argv[3], argv[4], argv[5]);
func12(v3, v4);
}

original_code:
int
main( int argc, char **argv ) {
    if ( argc < 6 ) {
        fprintf( stderr, "usage: %s interface-name"
                                  " local-address local-port"
                                  " remote-address remote-port\n", argv[0] );
        exit( -1 );
    }
    int tap = tap_open( argv[1] );
    int sock = socket_open( argv[2], argv[3], argv[4], argv[5] );
    loop( tap, sock );
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if ( argc < 6 ) {
        fprintf( stderr, "usage: %s interface-name"
                                  " local-address local-port"
                                  " remote-address remote-port\n", argv[0] );
        exit( -1 );
    }
    int tap = tap_open( argv[1] );
    int sock = socket_open( argv[2], argv[3], argv[4], argv[5] );
    loop( tap, sock );
    return 0;
}

variable_types: argc int

variable_types: tap int

variable_types: sock int


decompiled_code:
__int64 __fastcall tap_open(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
__int128 v4; // [rsp+0h] [rbp-48h] BYREF
__int128 v5; // [rsp+10h] [rbp-38h]
__int64 v6; // [rsp+20h] [rbp-28h]

v1 = open("/dev/net/tun", 2);
if ( v1 < 0 )
{
perror("open tunnel driver");
exit(-1);
}
v2 = v1;
v5 = 0LL;
LOWORD(v5) = 4098;
v6 = 0LL;
v4 = 0LL;
snprintf((char *)&v4, 0x10uLL, "%s", a1);
if ( ioctl(v2, 0x400454CAuLL, &v4) < 0 )
{
perror("create tunnel device");
exit(-1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v1; // eax
unsigned int v2; // er12
__int128 v4; // [rsp+0h] [rbp-48h] BYREF
__int128 v5; // [rsp+10h] [rbp-38h]
__int64 v6; // [rsp+20h] [rbp-28h]

v1 = open("/dev/net/tun", 2);
if ( v1 < 0 )
{
perror("open tunnel driver");
exit(-1);
}
v2 = v1;
v5 = 0LL;
LOWORD(v5) = 4098;
v6 = 0LL;
v4 = 0LL;
snprintf((char *)&v4, 0x10uLL, "%s", a1);
if ( ioctl(v2, 0x400454CAuLL, &v4) < 0 )
{
perror("create tunnel device");
exit(-1);
}
return v2;
}

original_code:
static int
tap_open( char *name ) {
    int tap = open( "/dev/net/tun", 02 );
    if ( tap < 0 ) {
        perror( "open tunnel driver" );
        exit( -1 );
    }
    struct ifreq request;
    memset( &request, 0, sizeof(request) );
    request.ifr_ifru.ifru_flags = 0x0002 | 0x1000;
    snprintf( request.ifr_ifrn.ifrn_name, 16, "%s", name );
    if ( ioctl(tap, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &request) < 0 ) {
        perror( "create tunnel device" );
        exit( -1 );
    }
    return tap;
}

canonical_original_code:
static int tap_open(char *name) {
    int tap = open( "/dev/net/tun", 02 );
    if ( tap < 0 ) {
        perror( "open tunnel driver" );
        exit( -1 );
    }
    struct ifreq request;
    memset( &request, 0, sizeof(request) );
    request.ifr_ifru.ifru_flags = 0x0002 | 0x1000;
    snprintf( request.ifr_ifrn.ifrn_name, 16, "%s", name );
    if ( ioctl(tap, (((1U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((202)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &request) < 0 ) {
        perror( "create tunnel device" );
        exit( -1 );
    }
    return tap;
}

variable_types:
name
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


parse

decompiled_code:
struct addrinfo *__fastcall parse(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *result; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_flags = 1056;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
if ( v2 <= 0 )
{
if ( v2 == -8 )
{
fprintf(stderr, "bad service '%s'\n", a2);
LABEL_8:
exit(-1);
}
if ( v2 == -2 )
{
fprintf(stderr, "bad address '%s'\n", a1);
goto LABEL_8;
}
}
fprintf(stderr, "address parse error = %d\n", (unsigned int)v2);
exit(-1);
}
result = pai;
if ( !pai )
{
fprintf(stderr, "cannot translate: %s:%s\n", a1, a2);
exit(-1);
}
return result;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func8(const char *a1, const char *a2)
{
int v2; // eax
struct addrinfo *result; // rax
struct addrinfo *pai; // [rsp+0h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-48h] BYREF

*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_flags = 1056;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_canonname = 0LL;
v2 = getaddrinfo(a1, a2, &req, &pai);
if ( v2 )
{
if ( v2 <= 0 )
{
if ( v2 == -8 )
{
fprintf(stderr, "bad service '%s'\n", a2);
LABEL_8:
exit(-1);
}
if ( v2 == -2 )
{
fprintf(stderr, "bad address '%s'\n", a1);
goto LABEL_8;
}
}
fprintf(stderr, "address parse error = %d\n", (unsigned int)v2);
exit(-1);
}
result = pai;
if ( !pai )
{
fprintf(stderr, "cannot translate: %s:%s\n", a1, a2);
exit(-1);
}
return result;
}

original_code:
static struct addrinfo*
parse( char *address, char *service ) {
    struct addrinfo hints = {
        .ai_family = 0,
        .ai_socktype = SOCK_DGRAM,
        .ai_protocol = 0,
        .ai_flags = (0x0400 | 0x0020),
    };
    struct addrinfo *info;
    int error = getaddrinfo( address, service, &hints, &info );
    switch ( error ) {
    case 0: break;
    case -8:
        fprintf( stderr, "bad service '%s'\n", service );
        exit( -1 );
    case -2:
        fprintf( stderr, "bad address '%s'\n", address );
        exit( -1 );
    default:
        fprintf( stderr, "address parse error = %d\n", error );
        exit( -1 );
    }
    if ( info == ((void *)0) ) {
        fprintf( stderr, "cannot translate: %s:%s\n", address, service );
        exit( -1 );
    }
    return info;
}

canonical_original_code:
static struct addrinfo *parse(char *address, char *service) {
    struct addrinfo hints = {
        .ai_family = 0,
        .ai_socktype = SOCK_DGRAM,
        .ai_protocol = 0,
        .ai_flags = (0x0400 | 0x0020),
    };
    struct addrinfo *info;
    int error = getaddrinfo( address, service, &hints, &info );
    switch ( error ) {
    case 0: break;
    case -8:
        fprintf( stderr, "bad service '%s'\n", service );
        exit( -1 );
    case -2:
        fprintf( stderr, "bad address '%s'\n", address );
        exit( -1 );
    default:
        fprintf( stderr, "address parse error = %d\n", error );
        exit( -1 );
    }
    if ( info == ((void *)0) ) {
        fprintf( stderr, "cannot translate: %s:%s\n", address, service );
        exit( -1 );
    }
    return info;
}

variable_types:
address
char *

variable_types:
service
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: error int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
__int64 __fastcall socket_open(const char *a1, const char *a2, const char *a3, const char *a4)
{
struct addrinfo *v6; // rbx
struct addrinfo *v7; // rbp
int v8; // eax
unsigned int v9; // er12

v6 = parse(a1, a2);
v7 = parse(a3, a4);
v8 = socket(v6->ai_family, v6->ai_socktype, v6->ai_protocol);
if ( v8 < 0 )
{
perror("socket");
exit(-1);
}
v9 = v8;
if ( bind(v8, v6->ai_addr, v6->ai_addrlen) < 0 )
{
perror("bind");
exit(-1);
}
if ( connect(v9, v7->ai_addr, v7->ai_addrlen) < 0 )
{
perror("connect");
exit(-1);
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1, const char *a2, const char *a3, const char *a4)
{
struct addrinfo *v6; // rbx
struct addrinfo *v7; // rbp
int v8; // eax
unsigned int v9; // er12

v6 = func8(a1, a2);
v7 = func8(a3, a4);
v8 = socket(v6->ai_family, v6->ai_socktype, v6->ai_protocol);
if ( v8 < 0 )
{
perror("socket");
exit(-1);
}
v9 = v8;
if ( bind(v8, v6->ai_addr, v6->ai_addrlen) < 0 )
{
perror("bind");
exit(-1);
}
if ( connect(v9, v7->ai_addr, v7->ai_addrlen) < 0 )
{
perror("connect");
exit(-1);
}
return v9;
}

original_code:
static int
socket_open( char *laddr, char *lport, char *raddr, char *rport ) {
    int error;
    struct addrinfo *local = parse( laddr, lport );
    struct addrinfo *remote = parse( raddr, rport );
    int sock = socket( local->ai_family, local->ai_socktype, local->ai_protocol );
    if ( sock < 0 ) {
        perror( "socket" );
        exit( -1 );
    }
    error = bind( sock, local->ai_addr, local->ai_addrlen );
    if ( error < 0 ) {
        perror( "bind" );
        exit( -1 );
    }
    error = connect( sock, remote->ai_addr, remote->ai_addrlen );
    if ( error < 0 ) {
        perror( "connect" );
        exit( -1 );
    }
    return sock;
}

canonical_original_code:
static int socket_open(char *laddr, char *lport, char *raddr, char *rport) {
    int error;
    struct addrinfo *local = parse( laddr, lport );
    struct addrinfo *remote = parse( raddr, rport );
    int sock = socket( local->ai_family, local->ai_socktype, local->ai_protocol );
    if ( sock < 0 ) {
        perror( "socket" );
        exit( -1 );
    }
    error = bind( sock, local->ai_addr, local->ai_addrlen );
    if ( error < 0 ) {
        perror( "bind" );
        exit( -1 );
    }
    error = connect( sock, remote->ai_addr, remote->ai_addrlen );
    if ( error < 0 ) {
        perror( "connect" );
        exit( -1 );
    }
    return sock;
}

variable_types:
laddr
char *

variable_types:
lport
char *

variable_types:
raddr
char *

variable_types:
rport
char *

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


forward

decompiled_code:
ssize_t __fastcall forward(int a1, int a2, _QWORD *a3)
{
signed __int64 v4; // rbp
ssize_t v5; // r12
ssize_t result; // rax
_BYTE v7[2072]; // [rsp+0h] [rbp-818h] BYREF

v4 = read(a1, v7, 0x800uLL);
v5 = write(a2, v7, v4);
if ( v5 < 0 )
perror("write");
if ( v4 > v5 )
perror("write");
a3[1] += v4;
result = v5;
++*a3;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(int a1, int a2, _QWORD *a3)
{
signed __int64 v4; // rbp
ssize_t v5; // r12
ssize_t result; // rax
_BYTE v7[2072]; // [rsp+0h] [rbp-818h] BYREF

v4 = read(a1, v7, 0x800uLL);
v5 = write(a2, v7, v4);
if ( v5 < 0 )
perror("write");
if ( v4 > v5 )
perror("write");
a3[1] += v4;
result = v5;
++*a3;
return result;
}

original_code:
static ssize_t
forward( int in, int out, struct dirstats *s ) {
    unsigned char buffer[2048];
    ssize_t octets = read( in, buffer, sizeof(buffer) );
    ssize_t written = write( out, buffer, octets );
    if ( written < 0 ) {
        perror( "write" );
    }
    if ( written < octets ) {
        perror( "write" );
    }
    s->pkts++;
    s->octets += octets;
    return written;
}

canonical_original_code:
static long forward(int in, int out, struct dirstats *s) {
    unsigned char buffer[2048];
    long octets = read( in, buffer, sizeof(buffer) );
    long written = write( out, buffer, octets );
    if ( written < 0 ) {
        perror( "write" );
    }
    if ( written < octets ) {
        perror( "write" );
    }
    s->pkts++;
    s->octets += octets;
    return written;
}

variable_types: in int

variable_types: out int

variable_types: struct dirstats { long pkts; long octets; long dropped; } *

variable_types:
buffer
unsigned char [2048]

variable_types: octets long

variable_types: written long

return_type: long


loop

decompiled_code:
void __fastcall __noreturn loop(int a1, int a2)
{
int v2; // er12
int v3; // ebx
__int64 v4; // r12
__int64 v5; // r15
__int64 v6; // rbx
__int64 v7; // r14
int v8; // eax
struct timeval timeout; // [rsp+8h] [rbp-108h] BYREF
__int128 v10[2]; // [rsp+18h] [rbp-F8h] BYREF
__int128 v11; // [rsp+38h] [rbp-D8h] BYREF
__int64 v12; // [rsp+48h] [rbp-C8h]
fd_set readfds; // [rsp+58h] [rbp-B8h] BYREF

v2 = a2 + 63;
v3 = a1 + 63;
if ( a2 >= 0 )
v2 = a2;
v10[0] = 0LL;
v10[1] = 0LL;
v4 = v2 >> 6;
v11 = 0LL;
v12 = 0LL;
v5 = 1LL << (a2 % 64);
if ( a1 >= 0 )
v3 = a1;
v6 = v3 >> 6;
v7 = 1LL << (a1 % 64);
while ( 1 )
{
while ( 1 )
{
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v4] |= v5;
readfds.fds_bits[v6] |= v7;
v8 = select(32, &readfds, 0LL, 0LL, &timeout);
if ( v8 != -1 )
break;
perror("select");
}
if ( v8 )
{
if ( (readfds.fds_bits[v6] & v7) != 0 )
{
forward(a1, a2, &v11);
++LODWORD(v10[0]);
}
if ( (readfds.fds_bits[v4] & v5) != 0 )
{
forward(a2, a1, (_QWORD *)v10 + 1);
++LODWORD(v10[0]);
}
}
else
{
idle((__int64)v10);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func12(int a1, int a2)
{
int v2; // er12
int v3; // ebx
__int64 v4; // r12
__int64 v5; // r15
__int64 v6; // rbx
__int64 v7; // r14
int v8; // eax
struct timeval timeout; // [rsp+8h] [rbp-108h] BYREF
__int128 v10[2]; // [rsp+18h] [rbp-F8h] BYREF
__int128 v11; // [rsp+38h] [rbp-D8h] BYREF
__int64 v12; // [rsp+48h] [rbp-C8h]
fd_set readfds; // [rsp+58h] [rbp-B8h] BYREF

v2 = a2 + 63;
v3 = a1 + 63;
if ( a2 >= 0 )
v2 = a2;
v10[0] = 0LL;
v10[1] = 0LL;
v4 = v2 >> 6;
v11 = 0LL;
v12 = 0LL;
v5 = 1LL << (a2 % 64);
if ( a1 >= 0 )
v3 = a1;
v6 = v3 >> 6;
v7 = 1LL << (a1 % 64);
while ( 1 )
{
while ( 1 )
{
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v4] |= v5;
readfds.fds_bits[v6] |= v7;
v8 = select(32, &readfds, 0LL, 0LL, &timeout);
if ( v8 != -1 )
break;
perror("select");
}
if ( v8 )
{
if ( (readfds.fds_bits[v6] & v7) != 0 )
{
func11(a1, a2, &v11);
++LODWORD(v10[0]);
}
if ( (readfds.fds_bits[v4] & v5) != 0 )
{
func11(a2, a1, (_QWORD *)v10 + 1);
++LODWORD(v10[0]);
}
}
else
{
func10((__int64)v10);
}
}
}

original_code:
static void
loop( int tap, int sock ) {
    struct tunnel_stats s;
    memset( &s, 0, sizeof(s) );
    struct timeval timeout;
    fd_set fds;
    for (;;) {
        timeout.tv_sec = 5;
        timeout.tv_usec = 0;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
        ((void) (((&fds)->__fds_bits)[((tap) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((tap) % (8 * (int) sizeof (__fd_mask)))))));
        int result = select( 32, &fds, ((void *)0), ((void *)0), &timeout );
        if ( result == -1 ) {
            perror( "select" );
            continue;
        }
        if ( result == 0 ) {
            idle( &s );
            continue;
        }
        if ( ((((&fds)->__fds_bits)[((tap) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((tap) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
            ssize_t octets = forward( tap, sock, &(s.tx) );
            s.epoch += 1;
            if ( debug ) printf( "tap->sock %zd octets\n", octets );
        }
        if ( ((((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
            ssize_t octets = forward( sock, tap, &(s.rx) );
            s.epoch += 1;
            if ( debug ) printf( "sock->tap %zd octets\n", octets );
        }
    }
}

canonical_original_code:
static void loop(int tap, int sock) {
    struct tunnel_stats s;
    memset( &s, 0, sizeof(s) );
    struct timeval timeout;
    struct fd_set fds;
    for (;;) {
        timeout.tv_sec = 5;
        timeout.tv_usec = 0;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))));
        ((void) (((&fds)->__fds_bits)[((tap) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((tap) % (8 * (int) sizeof (__fd_mask)))))));
        int result = select( 32, &fds, ((void *)0), ((void *)0), &timeout );
        if ( result == -1 ) {
            perror( "select" );
            continue;
        }
        if ( result == 0 ) {
            idle( &s );
            continue;
        }
        if ( ((((&fds)->__fds_bits)[((tap) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((tap) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
            long octets = forward( tap, sock, &(s.tx) );
            s.epoch += 1;
            if ( debug ) printf( "tap->sock %zd octets\n", octets );
        }
        if ( ((((&fds)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
            long octets = forward( sock, tap, &(s.rx) );
            s.epoch += 1;
            if ( debug ) printf( "sock->tap %zd octets\n", octets );
        }
    }
}

variable_types: tap int

variable_types: sock int

variable_types: struct tunnel_stats { int epoch; int written; struct dirstats { long pkts; long octets; long dropped; } rx; struct dirstats tx; }

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

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

variable_types: result int

user_defined_types: struct tunnel_stats { int epoch; int written; struct dirstats rx; struct dirstats tx; }


kvprintf

repo: kartorz/linix

decompiled_code:
__int64 __fastcall kvprintf(char *a1, const char **a2)
{
__int64 result; // rax
char *v4; // rbx
int v5; // edi
char *v6; // rbp
__int64 v7; // rdi
const char *v8; // rbx

result = (__int64)a1;
v4 = a1 + 1;
v5 = *a1;
if ( v5 )
{
while ( v5 == 37 )
{
v6 = (char *)(result + 2);
result = *(unsigned __int8 *)(result + 1);
if ( (_BYTE)result == 115 )
{
v8 = *a2;
if ( !*a2 )
{
v8 = "(null)";
goto LABEL_17;
}
while ( *v8 )
{
LABEL_17:
++v8;
result = ((__int64 (*)(void))vd_putchar)();
}
++a2;
LABEL_4:
v5 = *v6;
v4 = v6 + 1;
if ( !*v6 )
return result;
goto LABEL_5;
}
if ( (char)result <= 115 )
{
if ( (_BYTE)result == 100 )
goto LABEL_4;
}
else if ( (_BYTE)result == 117 || (_BYTE)result == 120 )
{
goto LABEL_4;
}
v7 = *(unsigned int *)a2++;
v4 = v6 + 1;
result = vd_putchar(v7);
v5 = *v6;
if ( !*v6 )
return result;
LABEL_5:
result = (__int64)v6;
}
result = ((__int64 (*)(void))vd_putchar)();
v6 = v4;
goto LABEL_4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, const char **a2)
{
__int64 result; // rax
char *v4; // rbx
int v5; // edi
char *v6; // rbp
__int64 v7; // rdi
const char *v8; // rbx

result = (__int64)a1;
v4 = a1 + 1;
v5 = *a1;
if ( v5 )
{
while ( v5 == 37 )
{
v6 = (char *)(result + 2);
result = *(unsigned __int8 *)(result + 1);
if ( (_BYTE)result == 115 )
{
v8 = *a2;
if ( !*a2 )
{
v8 = "(null)";
goto LABEL_17;
}
while ( *v8 )
{
LABEL_17:
++v8;
result = ((__int64 (*)(void))vd_putchar)();
}
++a2;
LABEL_4:
v5 = *v6;
v4 = v6 + 1;
if ( !*v6 )
return result;
goto LABEL_5;
}
if ( (char)result <= 115 )
{
if ( (_BYTE)result == 100 )
goto LABEL_4;
}
else if ( (_BYTE)result == 117 || (_BYTE)result == 120 )
{
goto LABEL_4;
}
v7 = *(unsigned int *)a2++;
v4 = v6 + 1;
result = vd_putchar(v7);
v5 = *v6;
if ( !*v6 )
return result;
LABEL_5:
result = (__int64)v6;
}
result = ((__int64 (*)(void))vd_putchar)();
v6 = v4;
goto LABEL_4;
}
return result;
}

original_code:
static void kvprintf(const char *format, char* arg[])
{
    int c;
    char buf[20];
    while ((c = *format++) != 0)
    {
        if (c != '%')
            vd_putchar (c);
        else
        {
            char *p;
            c = *format++;
            switch (c)
            {
            case 'd':
            case 'u':
            case 'x':
                break;
            case 's':
                p = *arg++;
                if (! p)
                    p = "(null)";
            string:
                while (*p)
                    vd_putchar (*p++);
                break;
            default:
                vd_putchar (*((int *) arg++));
                break;
            }
        }
    }
}

canonical_original_code:
static void kvprintf(char *format, char *arg[])
{
    int c;
    char buf[20];
    while ((c = *format++) != 0)
    {
        if (c != '%')
            vd_putchar (c);
        else
        {
            char *p;
            c = *format++;
            switch (c)
            {
            case 'd':
            case 'u':
            case 'x':
                break;
            case 's':
                p = *arg++;
                if (! p)
                    p = "(null)";
            string:
                while (*p)
                    vd_putchar (*p++);
                break;
            default:
                vd_putchar (*((int *) arg++));
                break;
            }
        }
    }
}

variable_types:
format
char *

variable_types:
arg
char *[]

variable_types: c int

variable_types:
buf
char [20]

variable_types:
p
char *


kprintf

decompiled_code:
__int64 __fastcall kprintf(char *a1)
{
const char *v2; // [rsp+10h] [rbp-8h] BYREF

return kvprintf(a1, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
const char *v2; // [rsp+10h] [rbp-8h] BYREF

return func0(a1, &v2);
}

original_code:
void kprintf(const char *fmt, ...)
{
    char **arg = (char **) &fmt;
    arg++;
    kvprintf(fmt, arg);
}

canonical_original_code:
void kprintf(char *fmt, ...)
{
    char **arg = (char **) &fmt;
    arg++;
    kvprintf(fmt, arg);
}

variable_types:
fmt
char *

variable_types:
arg
char **


kmain

decompiled_code:
__int64 kmain()
{
return arch_init();
}

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

original_code:
void kmain(unsigned long magic, unsigned long addr)
{
    arch_init();
}

variable_types:
magic
unsigned long

variable_types:
addr
unsigned long


decompiled_code:
unsigned __int64 __fastcall multiboot_check(__int64 a1, unsigned int *a2)
{
unsigned __int64 result; // rax
unsigned int v4; // er12
unsigned int *v5; // rbp
const char *v6; // rcx
__int64 v7; // rdx
__int64 v8; // rsi
unsigned int *v9; // rbp
unsigned int *v10; // r12

cls();
if ( a1 != 732803074 )
return kprintf("Invalid magic number: 0x%x\n", (unsigned int)a1);
kprintf("Welcome linix\n flags = 0x%x\n", *a2);
result = *a2;
if ( (result & 1) != 0 )
{
kprintf("mem_lower = %uKB, mem_upper = %uKB\n", a2[1], a2[2]);
result = *a2;
if ( (result & 2) == 0 )
{
LABEL_5:
if ( (result & 4) == 0 )
goto LABEL_6;
goto LABEL_20;
}
}
else if ( (result & 2) == 0 )
{
goto LABEL_5;
}
kprintf("boot_device = 0x%x\n", a2[3]);
result = *a2;
if ( (result & 4) == 0 )
{
LABEL_6:
if ( (result & 8) == 0 )
goto LABEL_7;
LABEL_14:
v4 = 0;
kprintf("mods_count = %d, mods_addr = 0x%x\n", a2[5], a2[6]);
v5 = (unsigned int *)a2[6];
if ( a2[5] )
{
do
{
v6 = (const char *)v5[2];
v7 = v5[1];
v8 = *v5;
++v4;
v5 += 4;
kprintf(" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n", v8, v7, v6);
}
while ( a2[5] > v4 );
}
result = *a2;
if ( (*a2 & 0x30) != 48 )
goto LABEL_8;
return kprintf("Both bits 4 and 5 are set.\n");
}
LABEL_20:
kprintf("cmdline = %s\n", (const char *)a2[4]);
result = *a2;
if ( (result & 8) != 0 )
goto LABEL_14;
LABEL_7:
if ( (result & 0x30) == 48 )
return kprintf("Both bits 4 and 5 are set.\n");
LABEL_8:
if ( (result & 0x10) != 0 )
{
kprintf("multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n", a2[7], a2[8], a2[9]);
result = *a2;
}
if ( (result & 0x20) != 0 )
{
kprintf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shndx = 0x%x\n", a2[7], a2[8], a2[9], a2[10]);
result = *a2;
}
if ( (result & 0x40) != 0 )
{
result = kprintf("mmap_addr = 0x%x, mmap_length = 0x%x\n", a2[12], a2[11]);
v9 = (unsigned int *)a2[12];
v10 = v9;
if ( (unsigned int)v9 < (unsigned int)v9 + a2[11] )
{
do
{
kprintf(
" size = 0x%x, base_addr = 0x%x%x, length = 0x%x%x, type = 0x%x\n",
*v9,
HIDWORD(*(_QWORD *)(v9 + 1)),
(unsigned int)*(_QWORD *)(v9 + 1),
HIDWORD(*(_QWORD *)(v9 + 3)),
(unsigned int)*(_QWORD *)(v9 + 3),
v9[5]);
v10 = (unsigned int *)((char *)v10 + *v9 + 4);
result = a2[12] + a2[11];
v9 = v10;
}
while ( (unsigned __int64)v10 < result );
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned int *a2)
{
unsigned __int64 result; // rax
unsigned int v4; // er12
unsigned int *v5; // rbp
const char *v6; // rcx
__int64 v7; // rdx
__int64 v8; // rsi
unsigned int *v9; // rbp
unsigned int *v10; // r12

cls();
if ( a1 != 732803074 )
return kprintf("Invalid magic number: 0x%x\n", (unsigned int)a1);
kprintf("Welcome linix\n flags = 0x%x\n", *a2);
result = *a2;
if ( (result & 1) != 0 )
{
kprintf("mem_lower = %uKB, mem_upper = %uKB\n", a2[1], a2[2]);
result = *a2;
if ( (result & 2) == 0 )
{
LABEL_5:
if ( (result & 4) == 0 )
goto LABEL_6;
goto LABEL_20;
}
}
else if ( (result & 2) == 0 )
{
goto LABEL_5;
}
kprintf("boot_device = 0x%x\n", a2[3]);
result = *a2;
if ( (result & 4) == 0 )
{
LABEL_6:
if ( (result & 8) == 0 )
goto LABEL_7;
LABEL_14:
v4 = 0;
kprintf("mods_count = %d, mods_addr = 0x%x\n", a2[5], a2[6]);
v5 = (unsigned int *)a2[6];
if ( a2[5] )
{
do
{
v6 = (const char *)v5[2];
v7 = v5[1];
v8 = *v5;
++v4;
v5 += 4;
kprintf(" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n", v8, v7, v6);
}
while ( a2[5] > v4 );
}
result = *a2;
if ( (*a2 & 0x30) != 48 )
goto LABEL_8;
return kprintf("Both bits 4 and 5 are set.\n");
}
LABEL_20:
kprintf("cmdline = %s\n", (const char *)a2[4]);
result = *a2;
if ( (result & 8) != 0 )
goto LABEL_14;
LABEL_7:
if ( (result & 0x30) == 48 )
return kprintf("Both bits 4 and 5 are set.\n");
LABEL_8:
if ( (result & 0x10) != 0 )
{
kprintf("multiboot_aout_symbol_table: tabsize = 0x%0x, strsize = 0x%x, addr = 0x%x\n", a2[7], a2[8], a2[9]);
result = *a2;
}
if ( (result & 0x20) != 0 )
{
kprintf("multiboot_elf_sec: num = %u, size = 0x%x, addr = 0x%x, shndx = 0x%x\n", a2[7], a2[8], a2[9], a2[10]);
result = *a2;
}
if ( (result & 0x40) != 0 )
{
result = kprintf("mmap_addr = 0x%x, mmap_length = 0x%x\n", a2[12], a2[11]);
v9 = (unsigned int *)a2[12];
v10 = v9;
if ( (unsigned int)v9 < (unsigned int)v9 + a2[11] )
{
do
{
kprintf(
" size = 0x%x, base_addr = 0x%x%x, length = 0x%x%x, type = 0x%x\n",
*v9,
HIDWORD(*(_QWORD *)(v9 + 1)),
(unsigned int)*(_QWORD *)(v9 + 1),
HIDWORD(*(_QWORD *)(v9 + 3)),
(unsigned int)*(_QWORD *)(v9 + 3),
v9[5]);
v10 = (unsigned int *)((char *)v10 + *v9 + 4);
result = a2[12] + a2[11];
v9 = v10;
}
while ( (unsigned __int64)v10 < result );
}
}
return result;
}

original_code:
static void multiboot_check(unsigned long magic, unsigned long addr)
{
    multiboot_info_t *mbi;
    cls ();
    if (magic != 0x2BADB002)
    {
        kprintf ("Invalid magic number: 0x%x\n", (unsigned) magic);
        return;
    }
    mbi = (multiboot_info_t *) addr;
    kprintf ("Welcome linix\n flags = 0x%x\n", (unsigned) mbi->flags);
    if (((mbi->flags) & (1 << (0))))
        kprintf ("mem_lower = %uKB, mem_upper = %uKB\n",
                (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper);
    if (((mbi->flags) & (1 << (1))))
        kprintf ("boot_device = 0x%x\n", (unsigned) mbi->boot_device);
    if (((mbi->flags) & (1 << (2))))
        kprintf ("cmdline = %s\n", (char *) mbi->cmdline);
    if (((mbi->flags) & (1 << (3))))
    {
        multiboot_module_t *mod;
        int i;
        kprintf ("mods_count = %d, mods_addr = 0x%x\n",
                (int) mbi->mods_count, (int) mbi->mods_addr);
        for (i = 0, mod = (multiboot_module_t *) mbi->mods_addr;
             i < mbi->mods_count;
             i++, mod++)
            kprintf (" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n",
                    (unsigned) mod->mod_start,
                    (unsigned) mod->mod_end,
                    (char *) mod->cmdline);
    }
    if (((mbi->flags) & (1 << (4))) && ((mbi->flags) & (1 << (5))))
    {
        kprintf ("Both bits 4 and 5 are set.\n");
        return;
    }
    if (((mbi->flags) & (1 << (4))))
    {
        multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym);
        kprintf ("multiboot_aout_symbol_table: tabsize = 0x%0x, "
                "strsize = 0x%x, addr = 0x%x\n",
                (unsigned) multiboot_aout_sym->tabsize,
                (unsigned) multiboot_aout_sym->strsize,
                (unsigned) multiboot_aout_sym->addr);
    }
    if (((mbi->flags) & (1 << (5))))
    {
        multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec);
        kprintf ("multiboot_elf_sec: num = %u, size = 0x%x,"
                " addr = 0x%x, shndx = 0x%x\n",
                (unsigned) multiboot_elf_sec->num, (unsigned) multiboot_elf_sec->size,
                (unsigned) multiboot_elf_sec->addr, (unsigned) multiboot_elf_sec->shndx);
    }
    if (((mbi->flags) & (1 << (6))))
    {
        multiboot_memory_map_t *mmap;
        kprintf ("mmap_addr = 0x%x, mmap_length = 0x%x\n",
                (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length);
        for (mmap = (multiboot_memory_map_t *) mbi->mmap_addr;
             (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
             mmap = (multiboot_memory_map_t *) ((unsigned long) mmap
                                                + mmap->size + sizeof (mmap->size)))
            kprintf (" size = 0x%x, base_addr = 0x%x%x,"
                    " length = 0x%x%x, type = 0x%x\n",
                    (unsigned) mmap->size,
                    mmap->addr >> 32,
                    mmap->addr & 0xffffffff,
                    mmap->len >> 32,
                    mmap->len & 0xffffffff,
                    (unsigned) mmap->type);
    }
}

canonical_original_code:
static void multiboot_check(unsigned long magic, unsigned long addr)
{
    struct multiboot_info *mbi;
    cls ();
    if (magic != 0x2BADB002)
    {
        kprintf ("Invalid magic number: 0x%x\n", (unsigned int) magic);
        return;
    }
    mbi = (struct multiboot_info *) addr;
    kprintf ("Welcome linix\n flags = 0x%x\n", (unsigned int) mbi->flags);
    if (((mbi->flags) & (1 << (0))))
        kprintf ("mem_lower = %uKB, mem_upper = %uKB\n",
                (unsigned int) mbi->mem_lower, (unsigned int) mbi->mem_upper);
    if (((mbi->flags) & (1 << (1))))
        kprintf ("boot_device = 0x%x\n", (unsigned int) mbi->boot_device);
    if (((mbi->flags) & (1 << (2))))
        kprintf ("cmdline = %s\n", (char *) mbi->cmdline);
    if (((mbi->flags) & (1 << (3))))
    {
        struct multiboot_mod_list *mod;
        int i;
        kprintf ("mods_count = %d, mods_addr = 0x%x\n",
                (int) mbi->mods_count, (int) mbi->mods_addr);
        for (i = 0, mod = (struct multiboot_mod_list *) mbi->mods_addr;
             i < mbi->mods_count;
             i++, mod++)
            kprintf (" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n",
                    (unsigned int) mod->mod_start,
                    (unsigned int) mod->mod_end,
                    (char *) mod->cmdline);
    }
    if (((mbi->flags) & (1 << (4))) && ((mbi->flags) & (1 << (5))))
    {
        kprintf ("Both bits 4 and 5 are set.\n");
        return;
    }
    if (((mbi->flags) & (1 << (4))))
    {
        struct multiboot_aout_symbol_table *multiboot_aout_sym = &(mbi->u.aout_sym);
        kprintf ("multiboot_aout_symbol_table: tabsize = 0x%0x, "
                "strsize = 0x%x, addr = 0x%x\n",
                (unsigned int) multiboot_aout_sym->tabsize,
                (unsigned int) multiboot_aout_sym->strsize,
                (unsigned int) multiboot_aout_sym->addr);
    }
    if (((mbi->flags) & (1 << (5))))
    {
        struct multiboot_elf_section_header_table *multiboot_elf_sec = &(mbi->u.elf_sec);
        kprintf ("multiboot_elf_sec: num = %u, size = 0x%x,"
                " addr = 0x%x, shndx = 0x%x\n",
                (unsigned int) multiboot_elf_sec->num, (unsigned int) multiboot_elf_sec->size,
                (unsigned int) multiboot_elf_sec->addr, (unsigned int) multiboot_elf_sec->shndx);
    }
    if (((mbi->flags) & (1 << (6))))
    {
        struct multiboot_mmap_entry *mmap;
        kprintf ("mmap_addr = 0x%x, mmap_length = 0x%x\n",
                (unsigned int) mbi->mmap_addr, (unsigned int) mbi->mmap_length);
        for (mmap = (struct multiboot_mmap_entry *) mbi->mmap_addr;
             (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length;
             mmap = (struct multiboot_mmap_entry *) ((unsigned long) mmap
                                                + mmap->size + sizeof (mmap->size)))
            kprintf (" size = 0x%x, base_addr = 0x%x%x,"
                    " length = 0x%x%x, type = 0x%x\n",
                    (unsigned int) mmap->size,
                    mmap->addr >> 32,
                    mmap->addr & 0xffffffff,
                    mmap->len >> 32,
                    mmap->len & 0xffffffff,
                    (unsigned int) mmap->type);
    }
}

variable_types: struct multiboot_info { unsigned int flags; unsigned int mem_lower; unsigned int mem_upper; unsigned int boot_device; unsigned int cmdline; unsigned int mods_count; unsigned int mods_addr; union { struct multiboot_aout_symbol_table { unsigned int tabsize; unsigned int strsize; unsigned int addr; unsigned int reserved; } aout_sym; struct multiboot_elf_section_header_table { unsigned int num; unsigned int size; unsigned int addr; unsigned int shndx; } elf_sec; } u; unsigned int mmap_length; unsigned int mmap_addr; unsigned int drives_length; unsigned int drives_addr; unsigned int config_table; unsigned int boot_loader_name; unsigned int apm_table; unsigned int vbe_control_info; unsigned int vbe_mode_info; unsigned short vbe_mode; unsigned short vbe_interface_seg; unsigned short vbe_interface_off; unsigned short vbe_interface_len; } *

variable_types: struct multiboot_mod_list { unsigned int mod_start; unsigned int mod_end; unsigned int cmdline; unsigned int pad; } *

variable_types: i int

variable_types: struct multiboot_aout_symbol_table { unsigned int tabsize; unsigned int strsize; unsigned int addr; unsigned int reserved; } *

variable_types: struct multiboot_elf_section_header_table { unsigned int num; unsigned int size; unsigned int addr; unsigned int shndx; } *

variable_types: struct multiboot_mmap_entry { unsigned int size; unsigned long long addr; unsigned long long len; unsigned int type; } *

user_defined_types: struct multiboot_info { unsigned int flags; unsigned int mem_lower; unsigned int mem_upper; unsigned int boot_device; unsigned int cmdline; unsigned int mods_count; unsigned int mods_addr; union { struct multiboot_aout_symbol_table aout_sym; struct multiboot_elf_section_header_table elf_sec; } u; unsigned int mmap_length; unsigned int mmap_addr; unsigned int drives_length; unsigned int drives_addr; unsigned int config_table; unsigned int boot_loader_name; unsigned int apm_table; unsigned int vbe_control_info; unsigned int vbe_mode_info; unsigned short vbe_mode; unsigned short vbe_interface_seg; unsigned short vbe_interface_off; unsigned short vbe_interface_len; }


boot

decompiled_code:
// attributes: thunk
unsigned __int64 __fastcall boot(__int64 a1, unsigned int *a2)
{
return multiboot_check(a1, a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned int *a2)
{
return func0(a1, a2);
}

original_code:
void boot(unsigned long magic, unsigned long addr)
{
    multiboot_check(magic, addr);
}


strchr

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

if ( !a2 )
result = 0LL;
return result;
}

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

if ( !a2 )
result = 0LL;
return result;
}

original_code:
char *strchr(const char *s, int c)
{
    if(!s || c == '\0')
        return (void *)0;
    strchr_comm(s, c, 0);
}

canonical_original_code:
char *strchr(char *s, int c)
{
    if(!s || c == '\0')
        return (void *)0;
    strchr_comm(s, c, 0);
}

variable_types:
s
char *

return_type: char *


strrchr

decompiled_code:
// attributes: thunk
__int64 __fastcall strrchr(__int64 a1, int a2)
{
return strchr(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return func0(a1, a2);
}

original_code:
char *strrchr(const char *s, int c)
{
    if(!s || c == '\0')
        return (void *)0;
    strchr_comm(s, c, 1);
}

canonical_original_code:
char *strrchr(char *s, int c)
{
    if(!s || c == '\0')
        return (void *)0;
    strchr_comm(s, c, 1);
}


strlen

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

if ( !a1 )
return 0LL;
if ( !*a1 )
return (unsigned int)-1;
v1 = 0;
do
v2 = v1++;
while ( a1[v1] );
return v2;
}

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

if ( !a1 )
return 0LL;
if ( !*a1 )
return (unsigned int)-1;
v1 = 0;
do
v2 = v1++;
while ( a1[v1] );
return v2;
}

original_code:
size_t strlen(const char *s)
{
    size_t i = 0;
    if(s == (void *)0)
        return 0;
    while(s[i] != '\0') ++i;
    return i-1;
}

canonical_original_code:
unsigned int strlen(char *s)
{
    unsigned int i = 0;
    if(s == (void *)0)
        return 0;
    while(s[i] != '\0') ++i;
    return i-1;
}

variable_types:
i
unsigned int

return_type: unsigned int


memset

decompiled_code:
__int64 __fastcall memset(__int64 a1, char a2, unsigned int a3)
{
if ( !a1 || !a3 )
return 0LL;
memset(a1 + a3 - 1LL - (a3 - 1), (unsigned int)a2, a3);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, unsigned int a3)
{
if ( !a1 || !a3 )
return 0LL;
func0(a1 + a3 - 1LL - (a3 - 1), (unsigned int)a2, a3);
return a1;
}

original_code:
void *memset(void *s, int c, size_t n)
{
    char *d = (char *)s;
    if(!s || !n)
        return (void *)0;
    d = s+n-1;
    for(; n>0; --n)
    {
        *(d--) = c;
    }
    return s;
}

canonical_original_code:
void *memset(void *s, int c, unsigned int n)
{
    char *d = (char *)s;
    if(!s || !n)
        return (void *)0;
    d = s+n-1;
    for(; n>0; --n)
    {
        *(d--) = c;
    }
    return s;
}

variable_types:
s
void *

variable_types:
n
unsigned int

variable_types:
d
char *

return_type: void *


repo: kassisdion/Raytracer

original_code:
char *mlx_int_get_line(char *ptr,int *pos,int size)
{
  int pos2;
  int pos3;
  int pos4;
  if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1)
    return ((char *)0);
  if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1)
    return ((char *)0);
  *(ptr+*pos+pos2) = 0;
  *(ptr+*pos+pos2+1+pos3) = 0;
  pos4 = *pos+pos2+1;
  *pos += pos2+pos3+2;
  return (ptr+pos4);
}

canonical_original_code:
char *mlx_int_get_line(char *ptr, int *pos, int size)
{
  int pos2;
  int pos3;
  int pos4;
  if ((pos2 = mlx_int_str_str(ptr+*pos,"\"",size-*pos))==-1)
    return ((char *)0);
  if ((pos3 = mlx_int_str_str(ptr+*pos+pos2+1,"\"",size-*pos-pos2-1))==-1)
    return ((char *)0);
  *(ptr+*pos+pos2) = 0;
  *(ptr+*pos+pos2+1+pos3) = 0;
  pos4 = *pos+pos2+1;
  *pos += pos2+pos3+2;
  return (ptr+pos4);
}

variable_types:
ptr
char *

variable_types:
pos
int *

variable_types: size int


decompiled_code:
char *__fastcall mlx_int_static_line(__int64 a1, int *a2)
{
__int64 v2; // rax
const char *v3; // rbp
int v4; // eax
char *v5; // r8
size_t v6; // r12
int v7; // ebx

v2 = *a2;
v3 = *(const char **)(a1 + 8 * v2);
*a2 = v2 + 1;
v4 = strlen(v3);
v5 = copy_0;
v6 = v4 + 1;
if ( len_1 >= v4 )
goto LABEL_6;
v7 = v4;
if ( copy_0 )
free(copy_0);
copy_0 = (char *)malloc(v6);
v5 = copy_0;
if ( copy_0 )
{
len_1 = v7;
LABEL_6:
v5 = strncpy(v5, v3, v6);
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, int *a2)
{
__int64 v2; // rax
const char *v3; // rbp
int v4; // eax
char *v5; // r8
size_t v6; // r12
int v7; // ebx

v2 = *a2;
v3 = *(const char **)(a1 + 8 * v2);
*a2 = v2 + 1;
v4 = strlen(v3);
v5 = copy_0;
v6 = v4 + 1;
if ( len_1 >= v4 )
goto LABEL_6;
v7 = v4;
if ( copy_0 )
free(copy_0);
copy_0 = (char *)malloc(v6);
v5 = copy_0;
if ( copy_0 )
{
len_1 = v7;
LABEL_6:
v5 = strncpy(v5, v3, v6);
}
return v5;
}

original_code:
char *mlx_int_static_line(char **xpm_data,int *pos,int size)
{
  static char *copy = 0;
  static int len = 0;
  int len2;
  char *str;
  str = xpm_data[(*pos)++];
  if ((len2 = strlen(str))>len)
    {
      if (copy)
 free(copy);
      if (!(copy = malloc(len2+1)))
 return ((char *)0);
      len = len2;
    }
  strncpy(copy, str, len2+1);
  return (copy);
}

canonical_original_code:
char *mlx_int_static_line(char **xpm_data, int *pos, int size)
{
  static char *copy = 0;
  static int len = 0;
  int len2;
  char *str;
  str = xpm_data[(*pos)++];
  if ((len2 = strlen(str))>len)
    {
      if (copy)
 free(copy);
      if (!(copy = malloc(len2+1)))
 return ((char *)0);
      len = len2;
    }
  strncpy(copy, str, len2+1);
  return (copy);
}

variable_types:
copy
char *

variable_types: len int

variable_types:
str
char *


decompiled_code:
__int64 __fastcall mlx_int_get_col_name(char *a1, int a2)
{
__int64 result; // rax
char *v3; // rcx
int v4; // edx

if ( !a2 )
return 0LL;
LODWORD(result) = 0;
v3 = &a1[a2];
do
{
v4 = *a1++;
result = (unsigned int)(v4 + ((_DWORD)result << 8));
}
while ( a1 != v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
__int64 result; // rax
char *v3; // rcx
int v4; // edx

if ( !a2 )
return 0LL;
LODWORD(result) = 0;
v3 = &a1[a2];
do
{
v4 = *a1++;
result = (unsigned int)(v4 + ((_DWORD)result << 8));
}
while ( a1 != v3 );
return result;
}

original_code:
int mlx_int_get_col_name(char *str,int size)
{
  int result;
  result = 0;
  while (size--)
    result = (result<<8)+*(str++);
  return (result);
}

canonical_original_code:
int mlx_int_get_col_name(char *str, int size)
{
  int result;
  result = 0;
  while (size--)
    result = (result<<8)+*(str++);
  return (result);
}

variable_types: result int


decompiled_code:
__int64 __fastcall mlx_int_get_text_rgb(char *s2, const char *a2)
{
char *v2; // r12
const char *v3; // rdi
__int64 v4; // rbx
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = s2;
if ( *s2 == 35 )
return strtol(s2 + 1, 0LL, 16);
if ( a2 )
{
v2 = v6;
snprintf(v6, 0x40uLL, "%s %s", s2, a2);
}
v3 = (const char *)mlx_col_name;
if ( !mlx_col_name )
return 0LL;
v4 = 0LL;
while ( strcasecmp(v3, v2) )
{
++v4;
v3 = (const char *)*((_QWORD *)&mlx_col_name + 2 * v4);
if ( !v3 )
return 0LL;
}
return *((unsigned int *)&mlx_col_name + 4 * (int)v4 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, const char *a2)
{
char *v2; // r12
const char *v3; // rdi
__int64 v4; // rbx
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = s2;
if ( *s2 == 35 )
return strtol(s2 + 1, 0LL, 16);
if ( a2 )
{
v2 = v6;
snprintf(v6, 0x40uLL, "%s %s", s2, a2);
}
v3 = (const char *)mlx_col_name;
if ( !mlx_col_name )
return 0LL;
v4 = 0LL;
while ( strcasecmp(v3, v2) )
{
++v4;
v3 = (const char *)*((_QWORD *)&mlx_col_name + 2 * v4);
if ( !v3 )
return 0LL;
}
return *((unsigned int *)&mlx_col_name + 4 * (int)v4 + 2);
}

original_code:
int mlx_int_get_text_rgb(char *name, char *end)
{
  int i;
  char buff[64];
  if (*name == '#')
    return (strtol(name+1,0,16));
  if (end)
    {
      snprintf(buff, 64, "%s %s", name, end);
      name = buff;
    }
  i = 0;
  while (mlx_col_name[i].name)
    {
      if (!strcasecmp(mlx_col_name[i].name, name))
 return (mlx_col_name[i].color);
      i ++;
    }
  return (0);
}

variable_types:
name
char *

variable_types:
end
char *

variable_types:
buff
char [64]


decompiled_code:
__int64 __fastcall mlx_int_file_get_rid_comment(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
int v3; // eax
int v4; // eax
__int64 v5; // r12
int v6; // eax
__int64 result; // rax

while ( 1 )
{
v4 = mlx_int_str_str_cote(a1, "/*", a2);
if ( v4 == -1 )
break;
v2 = v4;
v3 = mlx_int_str_str(a1 + v4 + 2, "*/", a2 - v4 - 2);
memset((void *)(a1 + v2), 32, v3 + 4);
}
while ( 1 )
{
result = mlx_int_str_str_cote(a1, "//", a2);
if ( (_DWORD)result == -1 )
break;
v5 = (int)result;
v6 = mlx_int_str_str(a1 + (int)result + 2, "\n", a2 - (unsigned int)result - 2);
memset((void *)(a1 + v5), 32, v6 + 3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
int v3; // eax
int v4; // eax
__int64 v5; // r12
int v6; // eax
__int64 result; // rax

while ( 1 )
{
v4 = mlx_int_str_str_cote(a1, "/*", a2);
if ( v4 == -1 )
break;
v2 = v4;
v3 = mlx_int_str_str(a1 + v4 + 2, "*/", a2 - v4 - 2);
memset((void *)(a1 + v2), 32, v3 + 4);
}
while ( 1 )
{
result = mlx_int_str_str_cote(a1, "//", a2);
if ( (_DWORD)result == -1 )
break;
v5 = (int)result;
v6 = mlx_int_str_str(a1 + (int)result + 2, "\n", a2 - (unsigned int)result - 2);
memset((void *)(a1 + v5), 32, v6 + 3);
}
return result;
}

original_code:
int mlx_int_file_get_rid_comment(char *ptr, int size)
{
  int com_begin;
  int com_end;
  while ((com_begin = mlx_int_str_str_cote(ptr,"/*",size))!=-1)
    {
      com_end = mlx_int_str_str(ptr+com_begin+2,"*/",size-com_begin-2);
      memset(ptr+com_begin,' ',com_end+4);
    }
  while ((com_begin = mlx_int_str_str_cote(ptr,"//",size))!=-1)
    {
      com_end = mlx_int_str_str(ptr+com_begin+2,"\n",size-com_begin-2);
      memset(ptr+com_begin,' ',com_end+3);
    }
}


decompiled_code:
__int64 expose_win1()
{
return mlx_put_image_to_window(mlx, win1, im3, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return mlx_put_image_to_window(mlx, win1, im3, 0LL, 0LL);
}

original_code:
int expose_win1(void *p)
{
  mlx_put_image_to_window(mlx,win1,im3,0,0);
}

variable_types:
p
void *


decompiled_code:
__int64 expose_win2()
{
mlx_put_image_to_window(mlx, win2, im4, 0LL, 0LL);
return mlx_put_image_to_window(mlx, win2, im2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
mlx_put_image_to_window(mlx, win2, im4, 0LL, 0LL);
return mlx_put_image_to_window(mlx, win2, im2, 0LL, 0LL);
}

original_code:
int expose_win2(void *p)
{
  mlx_put_image_to_window(mlx,win2,im4,0,0);
  mlx_put_image_to_window(mlx,win2,im2,0,0);
}


decompiled_code:
int __fastcall mouse_win1(unsigned int a1, unsigned int a2, unsigned int a3)
{
return printf("Mouse in Win1, button %d at %dx%d.\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, unsigned int a2, unsigned int a3)
{
return printf("Mouse in Win1, button %d at %dx%d.\n", a1, a2, a3);
}

original_code:
int mouse_win1(int button,int x,int y, void *p)
{
  printf("Mouse in Win1, button %d at %dx%d.\n",button,x,y);
}

canonical_original_code:
int mouse_win1(int button, int x, int y, void *p)
{
  printf("Mouse in Win1, button %d at %dx%d.\n",button,x,y);
}

variable_types: button int

variable_types: x int

variable_types: y int


decompiled_code:
int __fastcall mouse_win2(unsigned int a1, unsigned int a2, unsigned int a3)
{
return printf("Mouse in Win2, button %d at %dx%d.\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, unsigned int a2, unsigned int a3)
{
return printf("Mouse in Win2, button %d at %dx%d.\n", a1, a2, a3);
}

original_code:
int mouse_win2(int button,int x,int y, void *p)
{
  printf("Mouse in Win2, button %d at %dx%d.\n",button,x,y);
}

canonical_original_code:
int mouse_win2(int button, int x, int y, void *p)
{
  printf("Mouse in Win2, button %d at %dx%d.\n",button,x,y);
}


decompiled_code:
int __fastcall mouse_win3(unsigned int a1, unsigned int a2)
{
return printf("Mouse moving in Win3, at %dx%d.\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func4(unsigned int a1, unsigned int a2)
{
return printf("Mouse moving in Win3, at %dx%d.\n", a1, a2);
}

original_code:
int mouse_win3(int x,int y, void *p)
{
  printf("Mouse moving in Win3, at %dx%d.\n",x,y);
}

canonical_original_code:
int mouse_win3(int x, int y, void *p)
{
  printf("Mouse moving in Win3, at %dx%d.\n",x,y);
}


decompiled_code:
int __fastcall key_win1(unsigned int a1)
{
int result; // eax

result = printf("Key in Win1 : %d\n", a1);
if ( a1 == 65307 )
exit(0);
return result;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
int result; // eax

result = printf("Key in Win1 : %d\n", a1);
if ( a1 == 65307 )
exit(0);
return result;
}

original_code:
int key_win1(int key,void *p)
{
  printf("Key in Win1 : %d\n",key);
  if (key==0xFF1B)
    exit(0);
}

canonical_original_code:
int key_win1(int key, void *p)
{
  printf("Key in Win1 : %d\n",key);
  if (key==0xFF1B)
    exit(0);
}

variable_types: key int


decompiled_code:
int __fastcall key_win2(unsigned int a1)
{
int result; // eax

result = printf("Key in Win2 : %d\n", a1);
if ( a1 == 65307 )
exit(0);
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
int result; // eax

result = printf("Key in Win2 : %d\n", a1);
if ( a1 == 65307 )
exit(0);
return result;
}

original_code:
int key_win2(int key,void *p)
{
  printf("Key in Win2 : %d\n",key);
  if (key==0xFF1B)
    exit(0);
}

canonical_original_code:
int key_win2(int key, void *p)
{
  printf("Key in Win2 : %d\n",key);
  if (key==0xFF1B)
    exit(0);
}


decompiled_code:
int __fastcall key_win3(unsigned int a1)
{
int result; // eax

result = printf("Key in Win3 : %d\n", a1);
if ( a1 == 65307 )
result = mlx_destroy_window(mlx, win3);
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
int result; // eax

result = printf("Key in Win3 : %d\n", a1);
if ( a1 == 65307 )
result = mlx_destroy_window(mlx, win3);
return result;
}

original_code:
int key_win3(int key,void *p)
{
  printf("Key in Win3 : %d\n",key);
  if (key==0xFF1B)
    mlx_destroy_window(mlx,win3);
}

canonical_original_code:
int key_win3(int key, void *p)
{
  printf("Key in Win3 : %d\n",key);
  if (key==0xFF1B)
    mlx_destroy_window(mlx,win3);
}


decompiled_code:
__int64 __fastcall color_map_1(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v5; // er14
unsigned int v6; // er15
unsigned int v7; // er13
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

if ( a2 )
{
result = (unsigned int)(a3 - 1);
v5 = 255;
v8 = a3 - 1;
v6 = a2 - 1;
do
{
if ( a3 )
{
v7 = v8;
do
{
mlx_pixel_put(
mlx,
a1,
v6,
v7,
(unsigned int)((((int)(255 * v7) / a3) << 8) + ((v5 / a2) << 16) + (int)(255 * v6) / a2));
result = v7--;
}
while ( (_DWORD)result );
}
--v6;
v5 += 255;
}
while ( v6 != -1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v5; // er14
unsigned int v6; // er15
unsigned int v7; // er13
unsigned int v8; // [rsp+Ch] [rbp-3Ch]

if ( a2 )
{
result = (unsigned int)(a3 - 1);
v5 = 255;
v8 = a3 - 1;
v6 = a2 - 1;
do
{
if ( a3 )
{
v7 = v8;
do
{
mlx_pixel_put(
mlx,
a1,
v6,
v7,
(unsigned int)((((int)(255 * v7) / a3) << 8) + ((v5 / a2) << 16) + (int)(255 * v6) / a2));
result = v7--;
}
while ( (_DWORD)result );
}
--v6;
v5 += 255;
}
while ( v6 != -1 );
}
return result;
}

original_code:
int color_map_1(void *win,int w,int h)
{
  int x;
  int y;
  int color;
  x = w;
  while (x--)
    {
      y = h;
      while (y--)
        {
          color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
   mlx_pixel_put(mlx,win,x,y,color);
        }
    }
}

canonical_original_code:
int color_map_1(void *win, int w, int h)
{
  int x;
  int y;
  int color;
  x = w;
  while (x--)
    {
      y = h;
      while (y--)
        {
          color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
   mlx_pixel_put(mlx,win,x,y,color);
        }
    }
}

variable_types:
win
void *

variable_types: w int

variable_types: h int

variable_types: color int


original_code:
int color_map_2(unsigned char *data,int bpp,int sl,int w,int h,int endian, int type)
{
  int x;
  int y;
  int opp;
  int dec;
  int color;
  int color2;
  unsigned char *ptr;
  opp = bpp/8;
  printf("(opp : %d) ",opp);
  y = h;
  while (y--)
    {
      ptr = data+y*sl;
      x = w;
      while (x--)
        {
   if (type==2)
     color = (y*255)/w+((((w-x)*255)/w)<<16)
       +(((y*255)/h)<<8);
   else
     color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
          color2 = mlx_get_color_value(mlx,color);
   dec = opp;
   while (dec--)
     if (endian==local_endian)
       {
  if (endian)
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[4-opp+dec];
  else
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[dec];
       }
     else
       {
  if (endian)
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[opp-1-dec];
  else
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[3-dec];
       }
        }
    }
}

canonical_original_code:
int color_map_2(unsigned char *data, int bpp, int sl, int w, int h, int endian, int type)
{
  int x;
  int y;
  int opp;
  int dec;
  int color;
  int color2;
  unsigned char *ptr;
  opp = bpp/8;
  printf("(opp : %d) ",opp);
  y = h;
  while (y--)
    {
      ptr = data+y*sl;
      x = w;
      while (x--)
        {
   if (type==2)
     color = (y*255)/w+((((w-x)*255)/w)<<16)
       +(((y*255)/h)<<8);
   else
     color = (x*255)/w+((((w-x)*255)/w)<<16)+(((y*255)/h)<<8);
          color2 = mlx_get_color_value(mlx,color);
   dec = opp;
   while (dec--)
     if (endian==local_endian)
       {
  if (endian)
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[4-opp+dec];
  else
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[dec];
       }
     else
       {
  if (endian)
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[opp-1-dec];
  else
    *(ptr+x*opp+dec) = ((unsigned char *)(&color2))[3-dec];
       }
        }
    }
}

variable_types:
data
unsigned char *

variable_types: bpp int

variable_types: sl int

variable_types: endian int

variable_types: type int

variable_types: opp int

variable_types: dec int

variable_types:
ptr
unsigned char *


original_code:
int mlx_int_str_str(char *str,char *find,int len)
{
  int len_f;
  int pos;
  char *s;
  char *f;
  len_f = strlen(find);
  if (len_f>len)
    return (-1);
  pos = 0;
  while (*(str+len_f-1))
    {
      s = str;
      f = find;
      while (*(f++) == *(s++))
        if (!*f)
          return (pos);
      str ++;
      pos ++;
    }
  return (-1);
}

canonical_original_code:
int mlx_int_str_str(char *str, char *find, int len)
{
  int len_f;
  int pos;
  char *s;
  char *f;
  len_f = strlen(find);
  if (len_f>len)
    return (-1);
  pos = 0;
  while (*(str+len_f-1))
    {
      s = str;
      f = find;
      while (*(f++) == *(s++))
        if (!*f)
          return (pos);
      str ++;
      pos ++;
    }
  return (-1);
}

variable_types:
str
char *

variable_types:
find
char *

variable_types: len int

variable_types: pos int

variable_types:
s
char *

variable_types:
f
char *


original_code:
int mlx_int_str_str_cote(char *str,char *find,int len)
{
  int len_f;
  int pos;
  char *s;
  char *f;
  int cote;
  len_f = strlen(find);
  if (len_f>len)
    return (-1);
  cote = 0;
  pos = 0;
  while (*(str+len_f-1))
    {
      if (*str=='"')
 cote = 1-cote;
      if (!cote)
 {
   s = str;
   f = find;
   while (*(f++) == *(s++))
     if (!*f)
       return (pos);
 }
      str ++;
      pos ++;
    }
  return (-1);
}

canonical_original_code:
int mlx_int_str_str_cote(char *str, char *find, int len)
{
  int len_f;
  int pos;
  char *s;
  char *f;
  int cote;
  len_f = strlen(find);
  if (len_f>len)
    return (-1);
  cote = 0;
  pos = 0;
  while (*(str+len_f-1))
    {
      if (*str=='"')
 cote = 1-cote;
      if (!cote)
 {
   s = str;
   f = find;
   while (*(f++) == *(s++))
     if (!*f)
       return (pos);
 }
      str ++;
      pos ++;
    }
  return (-1);
}

variable_types: cote int


decompiled_code:
void mlx_int_param_undef()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int mlx_int_param_undef()
{
}

canonical_original_code:
int mlx_int_param_undef()
{
}


repo: kassouf/Sinc

decompiled_code:
int __fastcall Parse_Shape(int a1)
{
if ( a1 == 1 )
return printf("Gauss\t");
if ( a1 == 2 )
return printf("Square\t");
if ( a1 )
return printf("Unknown\t");
return printf("Sinc\t");
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
if ( a1 == 1 )
return printf("Gauss\t");
if ( a1 == 2 )
return printf("Square\t");
if ( a1 )
return printf("Unknown\t");
return printf("Sinc\t");
}

original_code:
static void Parse_Shape(int shape){
  switch(shape){
    case 0:
      printf("Sinc\t");
      break;
    case 1:
      printf("Gauss\t");
      break;
    case 2:
      printf("Square\t");
      break;
    default:
      printf("Unknown\t");
      break;
    }
}

variable_types: shape int


decompiled_code:
double __fastcall pmk_sinc(double a1, double a2, double a3)
{
if ( a3 == 0.0 )
return 0.0;
if ( a1 == a2 )
return *(double *)&LC5;
return sin((a1 - a2) / a3) / ((a1 - a2) / a3);
}

canonical_decompiled_code:
double __fastcall func1(double a1, double a2, double a3)
{
if ( a3 == 0.0 )
return 0.0;
if ( a1 == a2 )
return *(double *)&LC5;
return sin((a1 - a2) / a3) / ((a1 - a2) / a3);
}

original_code:
static double pmk_sinc(double x, double m, double d){
  double param;
  double result = 0;
  if (d == 0.0){
    result =0;
  }else if (x==m){
    result = 1;
  }else{
    param = (x-m)/d;
    result = sin(param)/param;
  }
  return result;
}

variable_types: x double

variable_types: m double

variable_types: d double

variable_types: param double

variable_types: result double

return_type: double


decompiled_code:
void __fastcall pmk_gauss(double a1, double a2, double a3)
{
if ( a3 != 0.0 && a1 != a2 )
exp(COERCE_DOUBLE(COERCE_UNSIGNED_INT64((a1 - a2) / a3 * ((a1 - a2) / a3)) ^ LC6));
}

canonical_decompiled_code:
void __fastcall func2(double a1, double a2, double a3)
{
if ( a3 != 0.0 && a1 != a2 )
exp(COERCE_DOUBLE(COERCE_UNSIGNED_INT64((a1 - a2) / a3 * ((a1 - a2) / a3)) ^ LC6));
}

original_code:
static double pmk_gauss(double x, double m, double d){
  double parameter;
  double result;
  if (d == 0){
    result = 0;
  }else if(x == m){
    result = 1;
  }else{
    parameter = (x-m)/d;
    parameter = parameter * parameter;
    result = exp(-parameter);
  }
  return result;
}

variable_types: parameter double


decompiled_code:
void __fastcall Get_Aj(double *a1, double a2)
{
__int64 v2; // rdx

v2 = *(unsigned int *)a1;
if ( (_DWORD)v2 )
{
if ( (_DWORD)v2 == 1 )
pmk_gauss(a2, a1[1], a1[2]);
else
printf("in %s: Fuzzy If part %d not supported yet\n", "Get_Aj", v2);
}
else
{
pmk_sinc(a2, a1[1], a1[2]);
}
}

canonical_decompiled_code:
void __fastcall func3(double *a1, double a2)
{
__int64 v2; // rdx

v2 = *(unsigned int *)a1;
if ( (_DWORD)v2 )
{
if ( (_DWORD)v2 == 1 )
func2(a2, a1[1], a1[2]);
else
printf("in %s: Fuzzy If part %d not supported yet\n", "Get_Aj", v2);
}
else
{
func1(a2, a1[1], a1[2]);
}
}

original_code:
double Get_Aj(double x, rule *r){
  double aj = 0.0;
  switch (r->if_shape){
  case 0:
    aj = pmk_sinc(x, r->ifs[0], r->ifs[1]);
    break;
  case 1:
    aj = pmk_gauss(x, r->ifs[0], r->ifs[1]);
    break;
  default:
    printf("in %s: Fuzzy If part %d not supported yet\n",__FUNCTION__, r->if_shape);
    break;
  }
  return aj;
}

canonical_original_code:
double Get_Aj(double x, struct _rule *r){
  double aj = 0.0;
  switch (r->if_shape){
  case 0:
    aj = pmk_sinc(x, r->ifs[0], r->ifs[1]);
    break;
  case 1:
    aj = pmk_gauss(x, r->ifs[0], r->ifs[1]);
    break;
  default:
    printf("in %s: Fuzzy If part %d not supported yet\n",__FUNCTION__, r->if_shape);
    break;
  }
  return aj;
}

variable_types: struct _rule { int if_shape; int then_shape; double ifs[2]; double then[2]; } *

variable_types: aj double


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

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = malloc(40LL * a2);
*(_QWORD *)(a1 + 16) = malloc(8LL * a2);
result = malloc(8LL * a2);
*(_QWORD *)(a1 + 24) = result;
return result;
}

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

*(_DWORD *)a1 = a2;
*(_QWORD *)(a1 + 8) = malloc(40LL * a2);
*(_QWORD *)(a1 + 16) = malloc(8LL * a2);
result = malloc(8LL * a2);
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
void Init_SAM(SAM *s, int num_rules){
  s->num_rules = num_rules;
  s->rules = (rule *)malloc(sizeof(rule)*num_rules);
  s->aj = (double *)malloc(sizeof(double)*num_rules);
  s->pj = (double *)malloc(sizeof(double)*num_rules);
}

canonical_original_code:
void Init_SAM(struct _SAM *s, int num_rules){
  s->num_rules = num_rules;
  s->rules = (struct _rule *)malloc(sizeof(rule)*num_rules);
  s->aj = (double *)malloc(sizeof(double)*num_rules);
  s->pj = (double *)malloc(sizeof(double)*num_rules);
}

variable_types: struct _SAM { int num_rules; struct _rule { int if_shape; int then_shape; double ifs[2]; double then[2]; } *rules; double *aj; double *pj; } *

user_defined_types: struct _SAM { int num_rules; struct _rule *rules; double *aj; double *pj; }


decompiled_code:
void __noreturn Init_SAM_with_rules()
{
printf("%s not yet supported", "Init_SAM_with_rules");
exit(3);
}

canonical_decompiled_code:
void __noreturn func5()
{
printf("%s not yet supported", "Init_SAM_with_rules");
exit(3);
}

original_code:
void Init_SAM_with_rules(SAM *s, int num_rules, rule *rules){
  printf("%s not yet supported",__FUNCTION__);
  exit(3);
}

canonical_original_code:
void Init_SAM_with_rules(struct _SAM *s, int num_rules, struct _rule *rules){
  printf("%s not yet supported",__FUNCTION__);
  exit(3);
}

variable_types:
rules
struct _rule *

user_defined_types: struct _rule { int if_shape; int then_shape; double ifs[2]; double then[2]; }


decompiled_code:
void __fastcall Free_SAM(void **a1)
{
free(a1[1]);
free(a1[2]);
free(a1[3]);
}

canonical_decompiled_code:
void __fastcall func6(void **a1)
{
free(a1[1]);
free(a1[2]);
free(a1[3]);
}

original_code:
void Free_SAM(SAM *s){
  free(s->rules);
  free(s->aj);
  free(s->pj);
}

canonical_original_code:
void Free_SAM(struct _SAM *s){
  free(s->rules);
  free(s->aj);
  free(s->pj);
}


original_code:
void Set_Vj(rule *r, double Vj){
  switch (r->then_shape){
  case 1:
    r->then[1] = Vj/(2.506628274631000502415765284811);
    break;
  default:
    r->then[1] = Vj;
    break;
  }
}

canonical_original_code:
void Set_Vj(struct _rule *r, double Vj){
  switch (r->then_shape){
  case 1:
    r->then[1] = Vj/(2.506628274631000502415765284811);
    break;
  default:
    r->then[1] = Vj;
    break;
  }
}

variable_types: Vj double


decompiled_code:
double __fastcall Get_Vj(__int64 a1)
{
double result; // xmm0_8

result = *(double *)(a1 + 32);
if ( *(_DWORD *)(a1 + 4) == 1 )
result = result * 2.506628274631001;
return result;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1)
{
double result; // xmm0_8

result = *(double *)(a1 + 32);
if ( *(_DWORD *)(a1 + 4) == 1 )
result = result * 2.506628274631001;
return result;
}

original_code:
double Get_Vj(rule *r){
  double Vj;
  switch (r->then_shape){
  case 1:
    Vj = r->then[1]*(2.506628274631000502415765284811);
    break;
  default:
    Vj = r->then[1];
    break;
    }
  return Vj;
}

canonical_original_code:
double Get_Vj(struct _rule *r){
  double Vj;
  switch (r->then_shape){
  case 1:
    Vj = r->then[1]*(2.506628274631000502415765284811);
    break;
  default:
    Vj = r->then[1];
    break;
    }
  return Vj;
}


decompiled_code:
double __fastcall Get_AjVj(double *a1, double a2)
{
Get_Aj(a1, a2);
return Get_Vj((__int64)a1) * a2;
}

canonical_decompiled_code:
double __fastcall func9(double *a1, double a2)
{
func3(a1, a2);
return func8((__int64)a1) * a2;
}

original_code:
double Get_AjVj(double x, rule *r){
  return Get_Aj(x, r) * Get_Vj(r);
}

canonical_original_code:
double Get_AjVj(double x, struct _rule *r){
  return Get_Aj(x, r) * Get_Vj(r);
}


decompiled_code:
int __fastcall Print_Rules(unsigned int *a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rbx
double v5; // xmm0_8

printf("Total Number of rules: %d\t Rule summary:\n", *a1);
puts("Rule #\tIF Shape\tIF Mean\tIF Dispersion\tThen Shape\tThen Centroid\tThen Volume");
if ( (int)*a1 > 0 )
{
v1 = 0LL;
do
{
printf("%03d\t", (unsigned int)(v1 + 1));
v2 = 5 * v1++;
v3 = 8 * v2;
Parse_Shape(*(_DWORD *)(*((_QWORD *)a1 + 1) + 8 * v2));
printf("%0.4f\t%0.4f\t", *(double *)(v3 + *((_QWORD *)a1 + 1) + 8), *(double *)(v3 + *((_QWORD *)a1 + 1) + 16));
Parse_Shape(*(_DWORD *)(*((_QWORD *)a1 + 1) + v3 + 4));
v4 = *((_QWORD *)a1 + 1) + v3;
v5 = Get_Vj(v4);
printf("%0.4f\t%0.4f\n", *(double *)(v4 + 24), v5);
}
while ( (int)*a1 > (int)v1 );
}
return puts("\nDone.");
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rbx
double v5; // xmm0_8

printf("Total Number of rules: %d\t Rule summary:\n", *a1);
puts("Rule #\tIF Shape\tIF Mean\tIF Dispersion\tThen Shape\tThen Centroid\tThen Volume");
if ( (int)*a1 > 0 )
{
v1 = 0LL;
do
{
printf("%03d\t", (unsigned int)(v1 + 1));
v2 = 5 * v1++;
v3 = 8 * v2;
func0(*(_DWORD *)(*((_QWORD *)a1 + 1) + 8 * v2));
printf("%0.4f\t%0.4f\t", *(double *)(v3 + *((_QWORD *)a1 + 1) + 8), *(double *)(v3 + *((_QWORD *)a1 + 1) + 16));
func0(*(_DWORD *)(*((_QWORD *)a1 + 1) + v3 + 4));
v4 = *((_QWORD *)a1 + 1) + v3;
v5 = func8(v4);
printf("%0.4f\t%0.4f\n", *(double *)(v4 + 24), v5);
}
while ( (int)*a1 > (int)v1 );
}
return puts("\nDone.");
}

original_code:
void Print_Rules(SAM *s){
  int i;
  printf("Total Number of rules: %d\t Rule summary:\n", s->num_rules);
  printf("Rule #\tIF Shape\tIF Mean\tIF Dispersion\tThen Shape\tThen Centroid\tThen Volume\n");
  for (i=0; i< s->num_rules; i++){
    printf("%03d\t",i+1);
    Parse_Shape(s->rules[i].if_shape);
    printf("%0.4f\t%0.4f\t",
    s->rules[i].ifs[0],
    s->rules[i].ifs[1]);
    Parse_Shape(s->rules[i].then_shape);
    printf("%0.4f\t%0.4f\n",
    s->rules[i].then[0],
    Get_Vj((&( (s)->rules[i]))));
  }
  printf("\nDone.\n");
}

canonical_original_code:
void Print_Rules(struct _SAM *s){
  int i;
  printf("Total Number of rules: %d\t Rule summary:\n", s->num_rules);
  printf("Rule #\tIF Shape\tIF Mean\tIF Dispersion\tThen Shape\tThen Centroid\tThen Volume\n");
  for (i=0; i< s->num_rules; i++){
    printf("%03d\t",i+1);
    Parse_Shape(s->rules[i].if_shape);
    printf("%0.4f\t%0.4f\t",
    s->rules[i].ifs[0],
    s->rules[i].ifs[1]);
    Parse_Shape(s->rules[i].then_shape);
    printf("%0.4f\t%0.4f\n",
    s->rules[i].then[0],
    Get_Vj((&( (s)->rules[i]))));
  }
  printf("\nDone.\n");
}

variable_types: i int


decompiled_code:
void __fastcall Set_Cj(__int64 a1, double a2)
{
*(double *)(a1 + 24) = a2;
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, double a2)
{
*(double *)(a1 + 24) = a2;
}

original_code:
void Set_Cj(rule *r, double Cj){
  r->then[0] = Cj;
}

canonical_original_code:
void Set_Cj(struct _rule *r, double Cj){
  r->then[0] = Cj;
}

variable_types: Cj double


decompiled_code:
double __fastcall Get_Cj(__int64 a1)
{
return *(double *)(a1 + 24);
}

canonical_decompiled_code:
double __fastcall func12(__int64 a1)
{
return *(double *)(a1 + 24);
}

original_code:
double Get_Cj(rule *r){
  return r->then[0];
}

canonical_original_code:
double Get_Cj(struct _rule *r){
  return r->then[0];
}


decompiled_code:
__int64 __fastcall Fuzz_SAM(_QWORD *a1, double a2)
{
__int64 v3; // rbx
double *v4; // rax
__int64 v5; // rdx
double *v6; // r12
__int64 v7; // rbx
double *v8; // r14
double *v9; // r13
double v10; // xmm0_8
double v11; // xmm0_8
__int64 result; // rax
double v13; // xmm0_8
__int64 v14; // rsi
__int64 v15; // rcx
double v16; // xmm2_8
double v17; // xmm1_8
double v18; // xmm0_8
__int64 v19; // rax
__int64 v20; // rcx
__int64 v21; // rdx
double v22; // [rsp+0h] [rbp-40h]

v3 = *(int *)a1;
v4 = (double *)malloc(8 * v3);
if ( (int)v3 <= 0 )
goto LABEL_10;
v22 = 0.0;
v5 = a1[2];
v6 = v4;
v7 = 0LL;
do
{
v8 = (double *)(v5 + 8 * v7);
v9 = (double *)(a1[1] + 40 * v7);
Get_Aj(v9, a2);
*v8 = a2;
v10 = Get_Vj((__int64)v9);
v11 = v10 * *(double *)(v5 + 8 * v7);
result = *(unsigned int *)a1;
v6[v7] = v11;
v13 = v11 + v22;
++v7;
v22 = v13;
}
while ( (int)result > (int)v7 );
if ( v13 == 0.0 )
{
LABEL_10:
printf("%s: denominator is zero!\n", "Fuzz_SAM");
fflush(stdout);
exit(2);
}
if ( (int)result > 0 )
{
v14 = a1[3];
v15 = a1[1];
v16 = 0.0;
result = 0LL;
do
{
v17 = v6[result] / v22;
*(double *)(v14 + 8 * result) = v17;
v18 = Get_Cj(v15);
result = v19 + 1;
v15 = v20 + 40;
v16 = v16 + v17 * v18;
}
while ( v21 != result );
}
return result;
}

original_code:
double Fuzz_SAM(double x, SAM *s){
  int i;
  double den = 0;
  double *temp = malloc(s->num_rules*sizeof(double));
  double fuzz;
  rule *r;
  den = 0.0;
  for (i = 0; i < s->num_rules; i++){
    r = (&( (s)->rules[i]));
    s->aj[i]= Get_Aj(x, r);
    temp[i]= s->aj[i] * Get_Vj(r);
    den += temp[i];
  }
  fuzz = 0.0;
  if (den == 0){
    printf("%s: denominator is zero!\n",__FUNCTION__);
    fflush(stdout);
    exit(2);
  }
  for (i = 0; i<s->num_rules; i++){
    r = (&( (s)->rules[i]));
    s->pj[i]=temp[i]/den;
    fuzz += s->pj[i] * Get_Cj(r);
  }
  return fuzz;
}

canonical_original_code:
double Fuzz_SAM(double x, struct _SAM *s){
  int i;
  double den = 0;
  double *temp = malloc(s->num_rules*sizeof(double));
  double fuzz;
  struct _rule *r;
  den = 0.0;
  for (i = 0; i < s->num_rules; i++){
    r = (&( (s)->rules[i]));
    s->aj[i]= Get_Aj(x, r);
    temp[i]= s->aj[i] * Get_Vj(r);
    den += temp[i];
  }
  fuzz = 0.0;
  if (den == 0){
    printf("%s: denominator is zero!\n",__FUNCTION__);
    fflush(stdout);
    exit(2);
  }
  for (i = 0; i<s->num_rules; i++){
    r = (&( (s)->rules[i]));
    s->pj[i]=temp[i]/den;
    fuzz += s->pj[i] * Get_Cj(r);
  }
  return fuzz;
}

variable_types: den double

variable_types:
temp
double *

variable_types: fuzz double


original_code:
static void Learn_If_Gauss(rule *r, double mu, double x, double error, double df_daj, double aj){
  double argument;
  double daj_dm;
  double daj_dd;
  double mj = r->ifs[0];
  double dj = r->ifs[1];
  if (dj != 0){
    daj_dm = 2 * mu * error * df_daj * aj * (x - mj)/(dj*dj);
    daj_dd = 2 * mu * error * df_daj * aj * ((x - mj)*(x - mj)) / (dj * dj * dj);
  }else{
    daj_dm = 0;
    daj_dd = 0;
  }
  r->ifs[0] = mj + daj_dm;
  r->ifs[1] = dj + daj_dd;
}

canonical_original_code:
static void Learn_If_Gauss(struct _rule *r, double mu, double x, double error, double df_daj, double aj){
  double argument;
  double daj_dm;
  double daj_dd;
  double mj = r->ifs[0];
  double dj = r->ifs[1];
  if (dj != 0){
    daj_dm = 2 * mu * error * df_daj * aj * (x - mj)/(dj*dj);
    daj_dd = 2 * mu * error * df_daj * aj * ((x - mj)*(x - mj)) / (dj * dj * dj);
  }else{
    daj_dm = 0;
    daj_dd = 0;
  }
  r->ifs[0] = mj + daj_dm;
  r->ifs[1] = dj + daj_dd;
}

variable_types: mu double

variable_types: error double

variable_types: argument double

variable_types: mj double

variable_types: dj double


decompiled_code:
__int64 __fastcall Learn_Then(__int64 a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm0_8
double v6; // xmm4_8
double v7; // xmm2_8
double v10; // [rsp+18h] [rbp-20h]

v10 = Get_Cj();
v5 = Get_Vj(a1);
v6 = a2 * a3 * a4 + v10;
if ( v5 == 0.0 )
{
v7 = 0.0;
}
else
{
v7 = a4 / v5 * ((v10 - a5) * (a2 * a3)) + v5;
if ( v7 < 0.0 )
*(_QWORD *)&v7 ^= LC1;
}
Set_Cj(a1, v6);
return Set_Vj(a1, v7);
}

original_code:
static void Learn_Then(rule *r, double mu, double error, double pj, double F_x){
  double new_vj;
  double new_cj;
  double cj = Get_Cj(r);
  double vj = Get_Vj(r);
  new_cj = cj + mu * error * pj;
  if(vj != 0){
    new_vj = vj + mu * error * (cj - F_x)*(pj/vj);
  }else{
    new_vj = 0;
  }
  new_vj = ((new_vj)<0?-(new_vj):(new_vj));
  Set_Cj(r, new_cj);
  Set_Vj(r, new_vj);
}

canonical_original_code:
static void Learn_Then(struct _rule *r, double mu, double error, double pj, double F_x){
  double new_vj;
  double new_cj;
  double cj = Get_Cj(r);
  double vj = Get_Vj(r);
  new_cj = cj + mu * error * pj;
  if(vj != 0){
    new_vj = vj + mu * error * (cj - F_x)*(pj/vj);
  }else{
    new_vj = 0;
  }
  new_vj = ((new_vj)<0?-(new_vj):(new_vj));
  Set_Cj(r, new_cj);
  Set_Vj(r, new_vj);
}

variable_types: pj double

variable_types: cj double

variable_types: vj double


Learn

original_code:
void Learn(SAM* s, double x, double f_x, double mu){
  double error;
  double F_x;
  int i;
  double df_daj;
  rule *r;
  double aj;
  double pj;
  F_x = Fuzz_SAM(x, s);
  error = (f_x - F_x);
  for (i=0; i< s->num_rules; i++){
    r = &(s->rules[i]);
    aj = s->aj[i];
    pj = s->pj[i];
    if (aj!=0){
      df_daj = (Get_Cj(r) - F_x) * pj / aj;
    }else{
      df_daj = 0;
    }
    switch(r->if_shape){
    case 0:
      Learn_If_Sinc(r, mu, x, error, df_daj, aj);
      break;
    case 1:
      Learn_If_Gauss(r, mu, x, error, df_daj, aj);
      break;
    default:
      printf("%s: %d if learning not yet supported",__FUNCTION__, r->if_shape);
      exit(3);
    }
    Learn_Then(r, mu, error, pj, F_x);
  }
}

canonical_original_code:
void Learn(struct _SAM *s, double x, double f_x, double mu){
  double error;
  double F_x;
  int i;
  double df_daj;
  struct _rule *r;
  double aj;
  double pj;
  F_x = Fuzz_SAM(x, s);
  error = (f_x - F_x);
  for (i=0; i< s->num_rules; i++){
    r = &(s->rules[i]);
    aj = s->aj[i];
    pj = s->pj[i];
    if (aj!=0){
      df_daj = (Get_Cj(r) - F_x) * pj / aj;
    }else{
      df_daj = 0;
    }
    switch(r->if_shape){
    case 0:
      Learn_If_Sinc(r, mu, x, error, df_daj, aj);
      break;
    case 1:
      Learn_If_Gauss(r, mu, x, error, df_daj, aj);
      break;
    default:
      printf("%s: %d if learning not yet supported",__FUNCTION__, r->if_shape);
      exit(3);
    }
    Learn_Then(r, mu, error, pj, F_x);
  }
}

variable_types: x double

variable_types: struct _rule { int if_shape; int then_shape; double ifs[2]; double then[2]; } *

variable_types: aj double