decompiled_code:
__int64 __fastcall insert_queue_data(__int64 a1, const void *a2, size_t a3)
{
unsigned int v4; // ebp
int v5; // eax

if ( queue_is_full(a1) )
{
fwrite("queue is full\n", 1uLL, 0xEuLL, stderr);
v4 = -1;
}
else
{
v4 = 0;
if ( a3 > 0x40 )
{
fprintf(stderr, "data is too big: data_size=%zu, max_size=%zu\n", a3, 0x40uLL);
v4 = -1;
}
else
{
memcpy((void *)(*(_QWORD *)(a1 + 16) + (int)(*(_DWORD *)(a1 + 12) << 6)), a2, a3);
v5 = *(_DWORD *)(a1 + 12);
*(_QWORD *)(a1 + 8LL * v5 + 24) = a3;
*(_DWORD *)(a1 + 12) = (unsigned __int64)(v5 + 1) % *(_QWORD *)a1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const void *a2, size_t a3)
{
unsigned int v4; // ebp
int v5; // eax

if ( func9(a1) )
{
fwrite("queue is full\n", 1uLL, 0xEuLL, stderr);
v4 = -1;
}
else
{
v4 = 0;
if ( a3 > 0x40 )
{
fprintf(stderr, "data is too big: data_size=%zu, max_size=%zu\n", a3, 0x40uLL);
v4 = -1;
}
else
{
memcpy((void *)(*(_QWORD *)(a1 + 16) + (int)(*(_DWORD *)(a1 + 12) << 6)), a2, a3);
v5 = *(_DWORD *)(a1 + 12);
*(_QWORD *)(a1 + 8LL * v5 + 24) = a3;
*(_DWORD *)(a1 + 12) = (unsigned __int64)(v5 + 1) % *(_QWORD *)a1;
}
}
return v4;
}

original_code:
int insert_queue_data( queue_t *queue, const unsigned char *data, size_t data_size)
{
 if (queue_is_full( queue)) {
  fprintf( stderr, "queue is full\n");
  return -1;
 }
 if (data_size > 64) {
  fprintf( stderr, "data is too big: data_size=%zu, max_size=%zu\n", data_size, 64);
  return -1;
 }
 memcpy( &queue->data[queue->rear * 64], data, data_size);
 queue->data_size[queue->rear] = data_size;
 queue->rear = (queue->rear + 1) % queue->size;
 return 0;
}

canonical_original_code:
int insert_queue_data(struct queue_s *queue, unsigned char *data, unsigned long data_size)
{
 if (queue_is_full( queue)) {
  fprintf( stderr, "queue is full\n");
  return -1;
 }
 if (data_size > 64) {
  fprintf( stderr, "data is too big: data_size=%zu, max_size=%zu\n", data_size, 64);
  return -1;
 }
 memcpy( &queue->data[queue->rear * 64], data, data_size);
 queue->data_size[queue->rear] = data_size;
 queue->rear = (queue->rear + 1) % queue->size;
 return 0;
}

variable_types:
data
unsigned char *

user_defined_types: struct queue_s { unsigned long size; int front; int rear; unsigned char *data; unsigned long data_size[128]; }


repo: hanmouse/test

original_code:
int get_queue_data( queue_t *queue, unsigned char *data, size_t *data_size)
{
 *data_size = 0;
 if (queue_is_empty( queue)) {
  return 0;
 }
 memcpy( data, &queue->data[queue->front * 64], queue->data_size[queue->front]);
 *data_size = queue->data_size[queue->front];
 queue->front = (queue->front + 1) % queue->size;
 return 0;
}

canonical_original_code:
int get_queue_data(struct queue_s *queue, unsigned char *data, unsigned long *data_size)
{
 *data_size = 0;
 if (queue_is_empty( queue)) {
  return 0;
 }
 memcpy( data, &queue->data[queue->front * 64], queue->data_size[queue->front]);
 *data_size = queue->data_size[queue->front];
 queue->front = (queue->front + 1) % queue->size;
 return 0;
}

variable_types: struct queue_s { unsigned long size; int front; int rear; unsigned char *data; unsigned long data_size[128]; } *

return_type: int


original_code:
void clear_buffer( void)
{
 memset( buffer, 0, sizeof( buffer));
}

canonical_original_code:
void clear_buffer()
{
 memset( buffer, 0, sizeof( buffer));
}

return_type: void


next

decompiled_code:
__int64 __fastcall next(char a1)
{
return (a1 + 1) & 0xF;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return (a1 + 1) & 0xF;
}

original_code:
int next( int current)
{
 return (current + 1) & (16 - 1);
}

canonical_original_code:
int next(int current)
{
 return (current + 1) & (16 - 1);
}

variable_types: current int


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

while ( *((_DWORD *)&buffer + (int)next(add_here)) )
;
*((_DWORD *)&buffer + add_here) = a1;
result = next(add_here);
add_here = result;
return result;
}

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

while ( *((_DWORD *)&buffer + (int)func8(add_here)) )
;
*((_DWORD *)&buffer + add_here) = a1;
result = func8(add_here);
add_here = result;
return result;
}

original_code:
void add_to_buffer( int value)
{
 while (buffer[next( add_here)]) {}
 buffer[add_here] = value;
 add_here = next( add_here);
}

canonical_original_code:
void add_to_buffer(int value)
{
 while (buffer[next( add_here)]) {}
 buffer[add_here] = value;
 add_here = next( add_here);
}

variable_types: value int


decompiled_code:
__int64 remove_from_buffer()
{
while ( !*((_DWORD *)&buffer + remove_here) )
;
*((_DWORD *)&buffer + remove_here) = 0;
remove_here = next(remove_here);
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
while ( !*((_DWORD *)&buffer + remove_here) )
;
*((_DWORD *)&buffer + remove_here) = 0;
remove_here = func8(remove_here);
return 0LL;
}

original_code:
int remove_from_buffer( void)
{
 int value;
 while (value = buffer[remove_here] == 0) {}
 buffer[remove_here] = 0;
 remove_here = next( remove_here);
 return value;
}

canonical_original_code:
int remove_from_buffer()
{
 int value;
 while (value = buffer[remove_here] == 0) {}
 buffer[remove_here] = 0;
 remove_here = next( remove_here);
 return value;
}


producer

decompiled_code:
void *__fastcall producer(void *a1)
{
int i; // ebx
void *result; // rax

for ( i = 1; i != 10000000; ++i )
result = (void *)add_to_buffer(i);
return result;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
int i; // ebx
void *result; // rax

for ( i = 1; i != 10000000; ++i )
result = (void *)func9(i);
return result;
}

original_code:
void *producer( void *param)
{
 int i;
 for (i = 1; i < 10000000; i++) {
  add_to_buffer( i);
 }
}

canonical_original_code:
void *producer(void *param)
{
 int i;
 for (i = 1; i < 10000000; i++) {
  add_to_buffer( i);
 }
}

variable_types:
param
void *

variable_types: i int

return_type: void *


consumer

decompiled_code:
void *__fastcall consumer(void *a1)
{
void *result; // rax

do
result = (void *)remove_from_buffer(a1);
while ( (_DWORD)result != 9999999 );
return result;
}

canonical_decompiled_code:
void *__fastcall func12(void *a1)
{
void *result; // rax

do
result = (void *)func11(a1);
while ( (_DWORD)result != 9999999 );
return result;
}

original_code:
void *consumer( void *param)
{
 while (remove_from_buffer() != 9999999) {}
}

canonical_original_code:
void *consumer(void *param)
{
 while (remove_from_buffer() != 9999999) {}
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t v4; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

clear_buffer();
pthread_create(&v4, 0LL, producer, 0LL);
pthread_create(newthread, 0LL, consumer, 0LL);
pthread_join((pthread_t)&v4, 0LL);
pthread_join((pthread_t)newthread, 0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t v4; // [rsp+0h] [rbp-18h] BYREF
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

func7();
pthread_create(&v4, 0LL, producer, 0LL);
pthread_create(newthread, 0LL, consumer, 0LL);
pthread_join((pthread_t)&v4, 0LL);
pthread_join((pthread_t)newthread, 0LL);
return 0;
}

original_code:
int main( int argc, char **argv)
{
 pthread_t threads[2];
 clear_buffer();
 pthread_create( &threads[0], ((void *)0), producer, 0);
 pthread_create( &threads[1], ((void *)0), consumer, 0);
 pthread_join( &threads[0], ((void *)0));
 pthread_join( &threads[1], ((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned long threads[2];
 clear_buffer();
 pthread_create( &threads[0], ((void *)0), producer, 0);
 pthread_create( &threads[1], ((void *)0), consumer, 0);
 pthread_join( &threads[0], ((void *)0));
 pthread_join( &threads[1], ((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
threads
unsigned long [2]


decompiled_code:
void *__fastcall count_func(void *a1)
{
int v1; // ebx
__int64 v2; // rcx

v1 = 10;
do
{
v2 = __readfsdword(0xFFFFFFFC) + 1;
__writefsdword(0xFFFFFFFC, v2);
fprintf(stderr, "[thread %d] count=%d\n", (unsigned int)a1, v2);
usleep(0x3E8u);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
int v1; // ebx
__int64 v2; // rcx

v1 = 10;
do
{
v2 = __readfsdword(0xFFFFFFFC) + 1;
__writefsdword(0xFFFFFFFC, v2);
fprintf(stderr, "[thread %d] count=%d\n", (unsigned int)a1, v2);
usleep(0x3E8u);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *count_func( void *param)
{
 int thread_id = (int) param;
 int i;
 for (i = 0; i < 10; i++) {
  count++;
  fprintf( stderr, "[thread %d] count=%d\n", thread_id, count);
  usleep( 1000);
 }
 return ((void *)0);
}

canonical_original_code:
void *count_func(void *param)
{
 int thread_id = (int) param;
 int i;
 for (i = 0; i < 10; i++) {
  count++;
  fprintf( stderr, "[thread %d] count=%d\n", thread_id, count);
  usleep( 1000);
 }
 return ((void *)0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 *v3; // rbx
pthread_t *v4; // r12
char *v5; // rbp
_BYTE v7[80]; // [rsp+0h] [rbp-68h] BYREF
__int64 v8; // [rsp+50h] [rbp-18h] BYREF

v3 = (__int64 *)v7;
v4 = (pthread_t *)v7;
v5 = 0LL;
do
pthread_create(v4++, 0LL, count_func, v5++);
while ( v5 != (char *)10 );
do
pthread_join((pthread_t)v3++, 0LL);
while ( v3 != &v8 );
return 0;
}

original_code:
int main( int argc, char **argv)
{
 int i;
 pthread_t threads[10];
 for (i = 0; i < 10; i++) {
  pthread_create( &threads[i], ((void *)0), count_func, (void *) i);
 }
 for (i = 0; i < 10; i++) {
  pthread_join( &threads[i], ((void *)0));
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 unsigned long threads[10];
 for (i = 0; i < 10; i++) {
  pthread_create( &threads[i], ((void *)0), count_func, (void *) i);
 }
 for (i = 0; i < 10; i++) {
  pthread_join( &threads[i], ((void *)0));
 }
 return 0;
}

variable_types:
threads
unsigned long [10]


count

decompiled_code:
__int64 __fastcall count(void *a1)
{
int v1; // ebx
char *v2; // rax
int v3; // eax
unsigned int v4; // er13
int v5; // eax
unsigned int v6; // er13
int v7; // eax
int v8; // eax
unsigned int v9; // er13
char *v10; // rax
char *v11; // rax
struct timeval v13; // [rsp+0h] [rbp-38h] BYREF

v1 = 10;
while ( 1 )
{
v3 = gettimeofday(&v13, 0LL);
v4 = v3;
if ( v3 < 0 )
{
v2 = strerror(v3);
fprintf(stderr, "gettimeofday() failed: E=%d[ %s ]\n", v4, v2);
goto LABEL_3;
}
v5 = pthread_mutex_lock(&mutex);
v6 = v5;
if ( v5 )
break;
printf("[thread %d] number=%d\n", (unsigned int)a1, (unsigned int)++number);
v7 = rand_r((unsigned int *)&v13.tv_usec);
usleep(v7 % 10000);
v8 = pthread_mutex_unlock(&mutex);
v9 = v8;
if ( v8 )
{
v10 = strerror(v8);
fprintf(stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", v9, v10);
return (int)a1;
}
LABEL_3:
if ( !--v1 )
return (int)a1;
}
v11 = strerror(v5);
fprintf(stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", v6, v11);
return (int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *a1)
{
int v1; // ebx
char *v2; // rax
int v3; // eax
unsigned int v4; // er13
int v5; // eax
unsigned int v6; // er13
int v7; // eax
int v8; // eax
unsigned int v9; // er13
char *v10; // rax
char *v11; // rax
struct timeval v13; // [rsp+0h] [rbp-38h] BYREF

v1 = 10;
while ( 1 )
{
v3 = gettimeofday(&v13, 0LL);
v4 = v3;
if ( v3 < 0 )
{
v2 = strerror(v3);
fprintf(stderr, "gettimeofday() failed: E=%d[ %s ]\n", v4, v2);
goto LABEL_3;
}
v5 = pthread_mutex_lock(&mutex);
v6 = v5;
if ( v5 )
break;
printf("[thread %d] number=%d\n", (unsigned int)a1, (unsigned int)++number);
v7 = rand_r((unsigned int *)&v13.tv_usec);
usleep(v7 % 10000);
v8 = pthread_mutex_unlock(&mutex);
v9 = v8;
if ( v8 )
{
v10 = strerror(v8);
fprintf(stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", v9, v10);
return (int)a1;
}
LABEL_3:
if ( !--v1 )
return (int)a1;
}
v11 = strerror(v5);
fprintf(stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", v6, v11);
return (int)a1;
}

original_code:
void *count( void *param)
{
 int i;
 int id = (int) param;
 int e;
 struct timeval tv;
 useconds_t usleep_time;
 for (i = 0; i < 10; i++) {
  e = gettimeofday( &tv, ((void *)0));
  if (e < 0) {
   fprintf( stderr, "gettimeofday() failed: E=%d[ %s ]\n", e, strerror( e));
   continue;
  }
  e = pthread_mutex_lock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
  number++;
  printf( "[thread %d] number=%d\n", id, number);
  usleep_time = rand_r( &tv.tv_usec) % 10000;
  usleep( usleep_time);
  e = pthread_mutex_unlock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
 }
 return (void *) id;
}

canonical_original_code:
void *count(void *param)
{
 int i;
 int id = (int) param;
 int e;
 struct timeval tv;
 unsigned int usleep_time;
 for (i = 0; i < 10; i++) {
  e = gettimeofday( &tv, ((void *)0));
  if (e < 0) {
   fprintf( stderr, "gettimeofday() failed: E=%d[ %s ]\n", e, strerror( e));
   continue;
  }
  e = pthread_mutex_lock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_lock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
  number++;
  printf( "[thread %d] number=%d\n", id, number);
  usleep_time = rand_r( &tv.tv_usec) % 10000;
  usleep( usleep_time);
  e = pthread_mutex_unlock( &mutex);
  if (e) {
   fprintf( stderr, "pthread_mutex_unlock() failed: E=%d[ %s ]\n", e, strerror( e));
   break;
  }
 }
 return (void *) id;
}

variable_types: id int

variable_types: e int

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


main

repo: haosdent/sniffer

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // er15
__int64 *v5; // rdx
__int64 v6; // rax
_DWORD *v7; // rax
int v8; // ebx
int v9; // er12
__int16 v10; // r13
__int16 v11; // r14
__int64 v12[2]; // [rsp+0h] [rbp-8E8h] BYREF
__int64 buf[2]; // [rsp+10h] [rbp-8D8h] BYREF
char v14[2032]; // [rsp+20h] [rbp-8C8h] BYREF
struct sigaction v15; // [rsp+810h] [rbp-D8h] BYREF

puts("Use Ctrl + C to kill this program. The results would be written to result.txt.");
sigemptyset(&v15.sa_mask);
v15.sa_handler = (__sighandler_t)break_handler;
v15.sa_flags = 0;
sigaction(2, &v15, 0LL);
sigaction(15, &v15, 0LL);
sigaction(3, &v15, 0LL);
buf[0] = 0LL;
buf[1] = 0LL;
memset(v14, 0, sizeof(v14));
v12[0] = (__int64)v12;
v12[1] = (__int64)v12;
record_list = (__int64)v12;
v3 = _bswap_16(3);
v4 = socket(17, 3, v3);
while ( 1 )
{
while ( 1 )
{
if ( (int)recvfrom(v4, buf, 0x800uLL, 0, 0LL, 0LL) <= 41 )
{
printf("Incomplete packet");
close(v4);
exit(0);
}
v8 = convert_ip(&v14[10]);
v9 = convert_ip(&v14[14]);
v10 = (unsigned __int8)v14[19] + ((unsigned __int8)v14[18] << 8);
v11 = (unsigned __int8)v14[21] + ((unsigned __int8)v14[20] << 8);
v6 = v12[0] - 24;
if ( v12 != (__int64 *)v12[0] )
break;
LABEL_9:
v7 = malloc(0x28uLL);
*v7 = v8;
v7[2] = v9;
*((_WORD *)v7 + 2) = v10;
*((_WORD *)v7 + 6) = v11;
v7[4] = 1;
list_add((_QWORD *)v7 + 3, v12);
}
while ( *(_DWORD *)v6 != v8 || *(_DWORD *)(v6 + 8) != v9 || *(_WORD *)(v6 + 4) != v10 || *(_WORD *)(v6 + 12) != v11 )
{
v5 = *(__int64 **)(v6 + 24);
v6 = (__int64)(v5 - 3);
if ( v12 == v5 )
goto LABEL_9;
}
++*(_DWORD *)(v6 + 16);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned __int16 v3; // ax
int v4; // er15
__int64 *v5; // rdx
__int64 v6; // rax
_DWORD *v7; // rax
int v8; // ebx
int v9; // er12
__int16 v10; // r13
__int16 v11; // r14
__int64 v12[2]; // [rsp+0h] [rbp-8E8h] BYREF
__int64 buf[2]; // [rsp+10h] [rbp-8D8h] BYREF
char v14[2032]; // [rsp+20h] [rbp-8C8h] BYREF
struct sigaction v15; // [rsp+810h] [rbp-D8h] BYREF

puts("Use Ctrl + C to kill this program. The results would be written to result.txt.");
sigemptyset(&v15.sa_mask);
v15.sa_handler = (__sighandler_t)break_handler;
v15.sa_flags = 0;
sigaction(2, &v15, 0LL);
sigaction(15, &v15, 0LL);
sigaction(3, &v15, 0LL);
buf[0] = 0LL;
buf[1] = 0LL;
memset(v14, 0, sizeof(v14));
v12[0] = (__int64)v12;
v12[1] = (__int64)v12;
record_list = (__int64)v12;
v3 = func3(3);
v4 = socket(17, 3, v3);
while ( 1 )
{
while ( 1 )
{
if ( (int)recvfrom(v4, buf, 0x800uLL, 0, 0LL, 0LL) <= 41 )
{
printf("Incomplete packet");
close(v4);
exit(0);
}
v8 = convert_ip(&v14[10]);
v9 = convert_ip(&v14[14]);
v10 = (unsigned __int8)v14[19] + ((unsigned __int8)v14[18] << 8);
v11 = (unsigned __int8)v14[21] + ((unsigned __int8)v14[20] << 8);
v6 = v12[0] - 24;
if ( v12 != (__int64 *)v12[0] )
break;
LABEL_9:
v7 = malloc(0x28uLL);
*v7 = v8;
v7[2] = v9;
*((_WORD *)v7 + 2) = v10;
*((_WORD *)v7 + 6) = v11;
v7[4] = 1;
func1((_QWORD *)v7 + 3, v12);
}
while ( *(_DWORD *)v6 != v8 || *(_DWORD *)(v6 + 8) != v9 || *(_WORD *)(v6 + 4) != v10 || *(_WORD *)(v6 + 12) != v11 )
{
v5 = *(__int64 **)(v6 + 24);
v6 = (__int64)(v5 - 3);
if ( v12 == v5 )
goto LABEL_9;
}
++*(_DWORD *)(v6 + 16);
}
}

original_code:
int main(int argc, char *argv[])
{
 int sd;
 unsigned char buf[2048] = {0};
 for(;;){
  buf[0] = 0;
 };
}

variable_types:
argv
char *[]

variable_types: sd int

variable_types:
buf
unsigned char [2048]


decompiled_code:
__int64 __fastcall convert_ip(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
__int64 result; // rax

v1 = a1 + 4;
LODWORD(result) = 0;
do
result = (unsigned int)*a1++ + ((_DWORD)result << 8);
while ( v1 != a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rcx
__int64 result; // rax

v1 = a1 + 4;
LODWORD(result) = 0;
do
result = (unsigned int)*a1++ + ((_DWORD)result << 8);
while ( v1 != a1 );
return result;
}

original_code:
uint32_t convert_ip(unsigned char *start)
{
 uint32_t result = 0;
 int i;
 for (i = 0; i < 4; i++) {
  result *= 256;
  result += *start;
  start++;
 };
 return result;
}

canonical_original_code:
unsigned int convert_ip(unsigned char *start)
{
 unsigned int result = 0;
 int i;
 for (i = 0; i < 4; i++) {
  result *= 256;
  result += *start;
  start++;
 };
 return result;
}

variable_types:
start
unsigned char *

variable_types:
result
unsigned int

return_type: unsigned int


strrep

repo: haozhigh/fftz

decompiled_code:
__int64 __fastcall strrep(char *dest, char *src, char *s, char *a4)
{
char *v6; // rbx
size_t v7; // rax

v6 = strstr(dest, s);
if ( !v6 )
return 0xFFFFFFFFLL;
do
{
mystrncpy(src, (__int64)dest, (_DWORD)v6 - (_DWORD)dest);
strcat(src, a4);
v7 = strlen(s);
strcat(src, &v6[v7]);
strcpy(dest, src);
v6 = strstr(dest, s);
}
while ( v6 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *dest, char *src, char *s, char *a4)
{
char *v6; // rbx
size_t v7; // rax

v6 = strstr(dest, s);
if ( !v6 )
return 0xFFFFFFFFLL;
do
{
func0(src, (__int64)dest, (_DWORD)v6 - (_DWORD)dest);
strcat(src, a4);
v7 = strlen(s);
strcat(src, &v6[v7]);
strcpy(dest, src);
v6 = strstr(dest, s);
}
while ( v6 );
return 0LL;
}

original_code:
int strrep(char *src, char * src_temp, char *match, char *replace){
 char *find_pos;
 find_pos = strstr(src, match);
 if((!find_pos) || (!match))
  return -1;
 while(find_pos){
  mystrncpy(src_temp, src, find_pos - src);
  strcat(src_temp, replace);
  strcat(src_temp, find_pos + strlen(match));
  strcpy(src, src_temp);
  find_pos = strstr(src, match);
 }
 return 0;
}

canonical_original_code:
int strrep(char *src, char *src_temp, char *match, char *replace){
 char *find_pos;
 find_pos = strstr(src, match);
 if((!find_pos) || (!match))
  return -1;
 while(find_pos){
  mystrncpy(src_temp, src, find_pos - src);
  strcat(src_temp, replace);
  strcat(src_temp, find_pos + strlen(match));
  strcpy(src, src_temp);
  find_pos = strstr(src, match);
 }
 return 0;
}

variable_types:
src
char *

variable_types:
match
char *

variable_types:
replace
char *


repo: harlanji/university-coursework

decompiled_code:
double get_timeofday()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double get_timeofday() {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_sec+(tv.tv_usec/1000000.0);
}

return_type: double

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


strrev

decompiled_code:
char *__fastcall strrev(char *dest)
{
int v1; // ebp
char *v2; // rbx
char *v3; // rdx
char *v4; // rax

v1 = strlen(dest);
v2 = (char *)malloc(v1 + 1);
if ( v2 )
{
v2[v1] = 0;
if ( v1 - 1 >= 0 )
{
v3 = &dest[v1 - 1];
v4 = v2;
do
*v4++ = *v3--;
while ( v4 != &v2[v1 - 1 + 1] );
}
}
strcpy(dest, v2);
free(v2);
return dest;
}

canonical_decompiled_code:
char *__fastcall func1(char *dest)
{
int v1; // ebp
char *v2; // rbx
char *v3; // rdx
char *v4; // rax

v1 = strlen(dest);
v2 = (char *)malloc(v1 + 1);
if ( v2 )
{
v2[v1] = 0;
if ( v1 - 1 >= 0 )
{
v3 = &dest[v1 - 1];
v4 = v2;
do
*v4++ = *v3--;
while ( v4 != &v2[v1 - 1 + 1] );
}
}
strcpy(dest, v2);
free(v2);
return dest;
}

original_code:
char* strrev(char * string) {
 int length = strlen(string);
 char * result = malloc(length+1);
 if( result != ((void *)0) ) {
  int i,j;
  result[length] = '\0';
  for ( i = length-1, j=0; i >= 0; i--, j++ )
   result[j] = string[i];
 }
 strcpy(string, result);
 free(result);
 return string;
}

canonical_original_code:
char *strrev(char *string) {
 int length = strlen(string);
 char *result = malloc(length+1);
 if( result != ((void *)0) ) {
  int i; int j;
  result[length] = '\0';
  for ( i = length-1, j=0; i >= 0; i--, j++ )
   result[j] = string[i];
 }
 strcpy(string, result);
 free(result);
 return string;
}

variable_types:
string
char *

variable_types: length int

variable_types:
result
char *

variable_types: j int

return_type: char *


decompiled_code:
_BOOL8 __fastcall parse_args(int a1, __int64 a2, _QWORD *a3, _QWORD *a4, int *a5)
{
_BOOL8 result; // rax
int v7; // eax

result = 0LL;
if ( a1 > 2 )
{
*a3 = *(_QWORD *)(a2 + 8);
*a4 = *(_QWORD *)(a2 + 16);
result = 1LL;
if ( a5 )
{
if ( a1 <= 3 )
{
*a5 = 1;
result = 1LL;
}
else
{
v7 = atoi(*(const char **)(a2 + 24));
*a5 = v7;
result = v7 != 0;
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, __int64 a2, _QWORD *a3, _QWORD *a4, int *a5)
{
_BOOL8 result; // rax
int v7; // eax

result = 0LL;
if ( a1 > 2 )
{
*a3 = *(_QWORD *)(a2 + 8);
*a4 = *(_QWORD *)(a2 + 16);
result = 1LL;
if ( a5 )
{
if ( a1 <= 3 )
{
*a5 = 1;
result = 1LL;
}
else
{
v7 = atoi(*(const char **)(a2 + 24));
*a5 = v7;
result = v7 != 0;
}
}
}
return result;
}

original_code:
int parse_args( int argc, char* argv[], char** file1, char** file2, int* p ) {
 if( argc < 3 ) {
  return 0;
 }
 *file1 = argv[1];
 *file2 = argv[2];
 if( p != ((void *)0)) {
  if(argc >= 4) {
   *p = atoi( argv[3] );
   if( !*p ) {
    return 0;
   }
  } else {
   *p = 1;
  }
 }
 return 1;
}

canonical_original_code:
int parse_args(int argc, char *argv[], char **file1, char **file2, int *p) {
 if( argc < 3 ) {
  return 0;
 }
 *file1 = argv[1];
 *file2 = argv[2];
 if( p != ((void *)0)) {
  if(argc >= 4) {
   *p = atoi( argv[3] );
   if( !*p ) {
    return 0;
   }
  } else {
   *p = 1;
  }
 }
 return 1;
}

variable_types: argc int

variable_types:
p
int *


decompiled_code:
void *__fastcall grid_init(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // eax
size_t v6; // rbx
void *v7; // rax

*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
v4 = strlen(a2);
*(_DWORD *)a1 = v4;
v5 = strlen(a3);
*(_DWORD *)(a1 + 4) = v5;
v6 = 8LL * (v5 + 1) * (v4 + 1);
v7 = malloc(v6);
*(_QWORD *)(a1 + 24) = v7;
return memset(v7, 0, v6);
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, const char *a2, const char *a3)
{
int v4; // ebx
int v5; // eax
size_t v6; // rbx
void *v7; // rax

*(_QWORD *)(a1 + 8) = a2;
*(_QWORD *)(a1 + 16) = a3;
v4 = strlen(a2);
*(_DWORD *)a1 = v4;
v5 = strlen(a3);
*(_DWORD *)(a1 + 4) = v5;
v6 = 8LL * (v5 + 1) * (v4 + 1);
v7 = malloc(v6);
*(_QWORD *)(a1 + 24) = v7;
return memset(v7, 0, v6);
}

original_code:
void grid_init(grid_t* grid, const char* s1, const char* s2) {
 grid->s1 = s1;
 grid->s2 = s2;
 grid->m = strlen(s1);
 grid->n = strlen(s2);
 size_t size = (grid->m + 1) * (grid->n + 1) * sizeof(cell_t);
 grid->cells = (cell_t*)malloc( size );
 memset( grid->cells, 0, size );
}

canonical_original_code:
void grid_init(struct grid_t *grid, char *s1, char *s2) {
 grid->s1 = s1;
 grid->s2 = s2;
 grid->m = strlen(s1);
 grid->n = strlen(s2);
 unsigned long size = (grid->m + 1) * (grid->n + 1) * sizeof(cell_t);
 grid->cells = (struct cell_t *)malloc( size );
 memset( grid->cells, 0, size );
}

variable_types: struct grid_t { int m; int n; char *s1; char *s2; struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; } *cells; } *

variable_types:
size
unsigned long

user_defined_types: struct grid_t { int m; int n; char *s1; char *s2; struct cell_t *cells; }


decompiled_code:
__int64 __fastcall grid_cell(__int64 a1, int a2, int a3)
{
return *(_QWORD *)(a1 + 24) + 8LL * (a3 + a2 * (*(_DWORD *)a1 + 1));
}

original_code:
cell_t* grid_cell(const grid_t* grid, const int i, const int j) {
 return &(grid->cells[ (grid->m + 1)*i + j ]);
}

canonical_original_code:
struct cell_t *grid_cell(struct grid_t *grid, int i, int j) {
 return &(grid->cells[ (grid->m + 1)*i + j ]);
}

variable_types: struct grid_t { int m; int n; char *s1; char *s2; struct cell_t *cells; } *

variable_types: i int

return_type: struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; } *


decompiled_code:
void *__fastcall grid_alloc_block(int a1, int a2)
{
return malloc(8LL * a2 * a1);
}

canonical_decompiled_code:
void *__fastcall func7(int a1, int a2)
{
return malloc(8LL * a2 * a1);
}

original_code:
cell_t* grid_alloc_block( const int h, const int w ) {
 cell_t* block = (cell_t*)malloc( h * w * sizeof(cell_t) );
 return block;
}

canonical_original_code:
struct cell_t *grid_alloc_block(int h, int w) {
 struct cell_t *block = (cell_t*)malloc( h * w * sizeof(cell_t) );
 return block;
}

variable_types: h int

variable_types: w int

variable_types: struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; } *


decompiled_code:
void *__fastcall grid_serialize_block(__int64 a1, int a2, int a3, int a4, int a5)
{
int v5; // ebx
char *v9; // rax
size_t v10; // r12
char *v11; // rbp
int v12; // er13
const void *v13; // rax
void *v15; // [rsp+8h] [rbp-40h]

v5 = a2;
v9 = (char *)grid_alloc_block(a4, a5);
v15 = v9;
if ( a4 > 0 )
{
v10 = 8LL * a5;
v11 = v9;
v12 = a2 + a4;
do
{
v13 = (const void *)grid_cell(a1, v5, a3);
memcpy(v11, v13, v10);
++v5;
v11 += v10;
}
while ( v5 != v12 );
}
return v15;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, int a2, int a3, int a4, int a5)
{
int v5; // ebx
char *v9; // rax
size_t v10; // r12
char *v11; // rbp
int v12; // er13
const void *v13; // rax
void *v15; // [rsp+8h] [rbp-40h]

v5 = a2;
v9 = (char *)func7(a4, a5);
v15 = v9;
if ( a4 > 0 )
{
v10 = 8LL * a5;
v11 = v9;
v12 = a2 + a4;
do
{
v13 = (const void *)func6(a1, v5, a3);
memcpy(v11, v13, v10);
++v5;
v11 += v10;
}
while ( v5 != v12 );
}
return v15;
}

original_code:
cell_t* grid_serialize_block( const grid_t* grid, const int y, const int x, const int h, const int w ) {
 cell_t* serialized = grid_alloc_block(h, w);
 int i;
 for( i = 0; i < h; i++ ) {
  cell_t* cell = grid_cell( grid, y + i, x );
  memcpy(&serialized[w*i], cell, w*sizeof(cell_t));
 }
 return serialized;
}

canonical_original_code:
struct cell_t *grid_serialize_block(struct grid_t *grid, int y, int x, int h, int w) {
 struct cell_t *serialized = grid_alloc_block(h, w);
 int i;
 for( i = 0; i < h; i++ ) {
  struct cell_t *cell = grid_cell( grid, y + i, x );
  memcpy(&serialized[w*i], cell, w*sizeof(cell_t));
 }
 return serialized;
}

variable_types: y int

variable_types: x int

user_defined_types: struct cell_t { int len; enum { none=0, up=1, left=2, upleft=3 } dir; }


decompiled_code:
void __fastcall grid_deserialize_block(__int64 a1, char *a2, int a3, int a4, int a5, int a6)
{
size_t v8; // r12
int v9; // ebx
int v10; // er13
void *v11; // rax

if ( a5 > 0 )
{
v8 = 8LL * a6;
v9 = a3;
v10 = a5 + a3;
do
{
v11 = (void *)grid_cell(a1, v9, a4);
memcpy(v11, a2, v8);
++v9;
a2 += v8;
}
while ( v9 != v10 );
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, char *a2, int a3, int a4, int a5, int a6)
{
size_t v8; // r12
int v9; // ebx
int v10; // er13
void *v11; // rax

if ( a5 > 0 )
{
v8 = 8LL * a6;
v9 = a3;
v10 = a5 + a3;
do
{
v11 = (void *)func6(a1, v9, a4);
memcpy(v11, a2, v8);
++v9;
a2 += v8;
}
while ( v9 != v10 );
}
}

original_code:
void grid_deserialize_block( const grid_t* grid, const cell_t* serialized, const int y, const int x, const int h, const int w ) {
 int i;
 for( i = 0; i < h; i++ ) {
  cell_t* cell = grid_cell( grid, y + i, x );
  memcpy(cell, &serialized[w*i], w*sizeof(cell_t));
 }
}

canonical_original_code:
void grid_deserialize_block(struct grid_t *grid, struct cell_t *serialized, int y, int x, int h, int w) {
 int i;
 for( i = 0; i < h; i++ ) {
  struct cell_t *cell = grid_cell( grid, y + i, x );
  memcpy(cell, &serialized[w*i], w*sizeof(cell_t));
 }
}

variable_types:
serialized
struct cell_t *


original_code:
void lcs_length_block( const grid_t* grid, const int y, const int x, const int h, const int w ) {
 int i, j;
 for(i = y; i < y + h; i++) {
  for(j = x; j < x + w; j++) {
   cell_t* cell = grid_cell( grid, i, j );
   if(grid->s1[i-1] == grid->s2[j-1]) {
    cell->len = grid_cell( grid, i-1, j-1 )->len + 1;
    cell->dir = upleft;
   } else {
    cell_t* cell_up = grid_cell( grid, i-1, j );
    cell_t* cell_left = grid_cell( grid, i, j-1 );
    if(cell_up->len >= cell_left->len) {
     cell->len = cell_up->len;
     cell->dir = up;
    } else {
     cell->len = cell_left->len;
     cell->dir = left;
    }
   }
  }
 }
}

canonical_original_code:
void lcs_length_block(struct grid_t *grid, int y, int x, int h, int w) {
 int i; int j;
 for(i = y; i < y + h; i++) {
  for(j = x; j < x + w; j++) {
   struct cell_t *cell = grid_cell( grid, i, j );
   if(grid->s1[i-1] == grid->s2[j-1]) {
    cell->len = grid_cell( grid, i-1, j-1 )->len + 1;
    cell->dir = upleft;
   } else {
    struct cell_t *cell_up = grid_cell( grid, i-1, j );
    struct cell_t *cell_left = grid_cell( grid, i, j-1 );
    if(cell_up->len >= cell_left->len) {
     cell->len = cell_up->len;
     cell->dir = up;
    } else {
     cell->len = cell_left->len;
     cell->dir = left;
    }
   }
  }
 }
}


max

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code:
int max(int a, int b) {
 return a > b ? a : b;
}

variable_types: a int

variable_types: b int


original_code:
int queue_init( queue_t* q, int capacity ) {
 q->capacity = capacity;
 q->head = 0;
 q->tail = 0;
 q->size = 0;
 q->items = (void**)malloc( capacity * sizeof(void*) );
 return q->items == ((void *)0) ? -1 : 0;
}

canonical_original_code:
int queue_init(struct queue *q, int capacity) {
 q->capacity = capacity;
 q->head = 0;
 q->tail = 0;
 q->size = 0;
 q->items = (void **)malloc( capacity * sizeof(void *) );
 return q->items == ((void *)0) ? -1 : 0;
}

variable_types: struct queue { int capacity; int size; int head; int tail; void **items; } *

variable_types: capacity int


decompiled_code:
void __fastcall queue_destroy(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void queue_destroy( queue_t* q ) {
 free( q->items );
}

canonical_original_code:
void queue_destroy(struct queue *q) {
 free( q->items );
}

user_defined_types: struct queue { int capacity; int size; int head; int tail; void **items; }


original_code:
int queue_requeue( queue_t* q, void* item ) {
 int i;
 for(i = 0; i < q->size; i++) {
  int pos = q_pos(q, q->head + i);
  if( item == q->items[pos] ) {
   int j;
   for(j = i; j < q->size - 1; j++) {
    int from = q_pos(q, q->head + j + 1);
    int to = q_pos(q, q->head + j);
    q->items[ to ] = q->items[ from ];
   }
   int current_tail = q_pos(q, q->tail - 1);
   q->items[ current_tail ] = item;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int queue_requeue(struct queue *q, void *item) {
 int i;
 for(i = 0; i < q->size; i++) {
  int pos = q_pos(q, q->head + i);
  if( item == q->items[pos] ) {
   int j;
   for(j = i; j < q->size - 1; j++) {
    int from = q_pos(q, q->head + j + 1);
    int to = q_pos(q, q->head + j);
    q->items[ to ] = q->items[ from ];
   }
   int current_tail = q_pos(q, q->tail - 1);
   q->items[ current_tail ] = item;
   return 0;
  }
 }
 return -1;
}

variable_types:
item
void *

variable_types: pos int

variable_types: j int

variable_types: from int

variable_types: to int


decompiled_code:
_BOOL8 __fastcall queue_isempty(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int queue_isempty( queue_t* q ) {
 return q->size == 0;
}

canonical_original_code:
int queue_isempty(struct queue *q) {
 return q->size == 0;
}


decompiled_code:
__int64 __fastcall queue_dequeue(__int64 a1)
{
int v1; // ebp
int v2; // edx
__int64 result; // rax

if ( queue_isempty(a1) )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
v2 = q_pos((_DWORD *)a1, v1 + 1);
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v1);
*(_DWORD *)(a1 + 8) = v2;
--*(_DWORD *)(a1 + 4);
return result;
}

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

if ( func4(a1) )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
v2 = func0((_DWORD *)a1, v1 + 1);
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v1);
*(_DWORD *)(a1 + 8) = v2;
--*(_DWORD *)(a1 + 4);
return result;
}

original_code:
void* queue_dequeue( queue_t* q ) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int new_head = q_pos(q, q->head + 1);
 void* item = q->items[ q->head ];
 q->head = new_head;
 q->size--;
 return item;
}

canonical_original_code:
void *queue_dequeue(struct queue *q) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int new_head = q_pos(q, q->head + 1);
 void *item = q->items[ q->head ];
 q->head = new_head;
 q->size--;
 return item;
}


decompiled_code:
__int64 __fastcall queue_search(__int64 a1, unsigned int (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
int v4; // er12
int v5; // ebp
__int64 v6; // r15

if ( queue_isempty(a1) )
return 0LL;
v4 = 0;
if ( *(int *)a1 <= 0 )
return 0LL;
while ( 1 )
{
v5 = q_pos((_DWORD *)a1, *(_DWORD *)(a1 + 8) + v4);
v6 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v5);
if ( a2(a1, v6, a3) )
break;
if ( *(_DWORD *)(a1 + 12) - 1 == v5 )
return 0LL;
if ( *(_DWORD *)a1 <= ++v4 )
return 0LL;
}
return v6;
}

original_code:
void* queue_search( queue_t* q, queue_search_cb cb, void* arg ) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int i;
 for( i = 0; i < q->capacity; i++ ) {
  int pos = q_pos(q, q->head + i);
  void* item = q->items[ pos ];
  if( cb( q, item, arg ) ) {
   return item;
  }
  if( pos == q->tail - 1 ) {
    return (void*)((void *)0);
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *queue_search(struct queue *q, int (*cb)(struct queue *q, void *item, void *arg), void *arg) {
 if( queue_isempty( q ) ) {
  return ((void *)0);
 }
 int i;
 for( i = 0; i < q->capacity; i++ ) {
  int pos = q_pos(q, q->head + i);
  void *item = q->items[ pos ];
  if( cb( q, item, arg ) ) {
   return item;
  }
  if( pos == q->tail - 1 ) {
    return (void *)((void *)0);
  }
 }
 return ((void *)0);
}

variable_types: int (*)(struct queue *q, void *item, void *arg)

variable_types:
arg
void *


decompiled_code:
_BOOL8 __fastcall queue_isfull(_DWORD *a1)
{
return a1[1] == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_DWORD *a1)
{
return a1[1] == *a1;
}

original_code:
int queue_isfull( queue_t* q ) {
 return q->size == q->capacity;
}

canonical_original_code:
int queue_isfull(struct queue *q) {
 return q->size == q->capacity;
}


decompiled_code:
__int64 __fastcall queue_enqueue(__int64 a1, __int64 a2)
{
int v2; // ebp
int v3; // er12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
v3 = q_pos((_DWORD *)a1, v2 + 1);
result = queue_isfull((_DWORD *)a1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v2) = a2;
*(_DWORD *)(a1 + 12) = v3;
++*(_DWORD *)(a1 + 4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
int v2; // ebp
int v3; // er12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
v3 = func0((_DWORD *)a1, v2 + 1);
result = func7((_DWORD *)a1);
if ( (_DWORD)result )
return 0xFFFFFFFFLL;
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v2) = a2;
*(_DWORD *)(a1 + 12) = v3;
++*(_DWORD *)(a1 + 4);
return result;
}

original_code:
int queue_enqueue( queue_t* q, void* item ) {
 int new_tail = q_pos(q, q->tail + 1);
 if( queue_isfull( q ) ) {
  return -1;
 }
 q->items[ q->tail ] = item;
 q->tail = new_tail;
 q->size++;
 return 0;
}

canonical_original_code:
int queue_enqueue(struct queue *q, void *item) {
 int new_tail = q_pos(q, q->tail + 1);
 if( queue_isfull( q ) ) {
  return -1;
 }
 q->items[ q->tail ] = item;
 q->tail = new_tail;
 q->size++;
 return 0;
}


decompiled_code:
__int64 __fastcall prodcon_queue_init(pthread_cond_t *cond, int a2)
{
unsigned int v2; // ebx

*((_DWORD *)&cond[3].__align + 4) = 0;
if ( pthread_cond_init(cond + 1, 0LL) == -1 )
{
v2 = -1;
fwrite("pthread_cond_init error for full queue condition", 1uLL, 0x30uLL, stderr);
}
else
{
v2 = pthread_cond_init(cond, 0LL);
if ( v2 == -1 )
{
fwrite("pthread_cond_init error for empty queue condition", 1uLL, 0x31uLL, stderr);
}
else
{
v2 = pthread_mutex_init((pthread_mutex_t *)&cond[2], 0LL);
if ( v2 == -1 )
{
fwrite("pthread_mutex_init error on queue", 1uLL, 0x21uLL, stderr);
}
else
{
v2 = queue_init((__int64)(&cond[2].__align + 5), a2);
if ( v2 == -1 )
fwrite("queue_init error", 1uLL, 0x10uLL, stderr);
else
v2 = 0;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(pthread_cond_t *cond, int a2)
{
unsigned int v2; // ebx

*((_DWORD *)&cond[3].__align + 4) = 0;
if ( pthread_cond_init(cond + 1, 0LL) == -1 )
{
v2 = -1;
fwrite("pthread_cond_init error for full queue condition", 1uLL, 0x30uLL, stderr);
}
else
{
v2 = pthread_cond_init(cond, 0LL);
if ( v2 == -1 )
{
fwrite("pthread_cond_init error for empty queue condition", 1uLL, 0x31uLL, stderr);
}
else
{
v2 = pthread_mutex_init((pthread_mutex_t *)&cond[2], 0LL);
if ( v2 == -1 )
{
fwrite("pthread_mutex_init error on queue", 1uLL, 0x21uLL, stderr);
}
else
{
v2 = func1((__int64)(&cond[2].__align + 5), a2);
if ( v2 == -1 )
fwrite("queue_init error", 1uLL, 0x10uLL, stderr);
else
v2 = 0;
}
}
}
return v2;
}

original_code:
int prodcon_queue_init( prodcon_queue_t* q, int capacity ) {
 q->consume_all = 0;
 if (pthread_cond_init( &q->full_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for full queue condition");
  return -1;
 }
 if (pthread_cond_init( &q->empty_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for empty queue condition");
  return -1;
 }
 if (pthread_mutex_init( &q->mx, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_mutex_init error on queue");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "queue_init error");
  return -1;
 }
 return 0;
}

canonical_original_code:
int prodcon_queue_init(struct prodcon_queue *q, int capacity) {
 q->consume_all = 0;
 if (pthread_cond_init( &q->full_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for full queue condition");
  return -1;
 }
 if (pthread_cond_init( &q->empty_cv, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_cond_init error for empty queue condition");
  return -1;
 }
 if (pthread_mutex_init( &q->mx, ((void *)0) ) == -1) {
  fprintf(stderr, "pthread_mutex_init error on queue");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "queue_init error");
  return -1;
 }
 return 0;
}

variable_types: struct prodcon_queue { union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } empty_cv; union pthread_cond_t full_cv; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mx; struct queue { int capacity; int size; int head; int tail; void **items; } q; int consume_all; } *

user_defined_types: struct prodcon_queue { union pthread_cond_t empty_cv; union pthread_cond_t full_cv; union pthread_mutex_t mx; struct queue q; int consume_all; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
int __fastcall prodcon_queue_destroy(pthread_cond_t *cond)
{
int result; // eax

queue_destroy((__int64)(&cond[2].__align + 5));
if ( pthread_mutex_destroy((pthread_mutex_t *)&cond[2]) == -1 )
return fwrite("Failed to destroy prodcon mutex lock", 1uLL, 0x24uLL, stderr);
if ( pthread_cond_destroy(cond + 1) == -1 )
return fwrite("Failed to destroy prodcon full_cv", 1uLL, 0x21uLL, stderr);
result = pthread_cond_destroy(cond);
if ( result == -1 )
result = fwrite("Failed to destroy prodcon empty_cv", 1uLL, 0x22uLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func10(pthread_cond_t *cond)
{
int result; // eax

func2((__int64)(&cond[2].__align + 5));
if ( pthread_mutex_destroy((pthread_mutex_t *)&cond[2]) == -1 )
return fwrite("Failed to destroy prodcon mutex lock", 1uLL, 0x24uLL, stderr);
if ( pthread_cond_destroy(cond + 1) == -1 )
return fwrite("Failed to destroy prodcon full_cv", 1uLL, 0x21uLL, stderr);
result = pthread_cond_destroy(cond);
if ( result == -1 )
result = fwrite("Failed to destroy prodcon empty_cv", 1uLL, 0x22uLL, stderr);
return result;
}

original_code:
void prodcon_queue_destroy( prodcon_queue_t* q) {
 queue_destroy( &q->q );
 if (pthread_mutex_destroy( &q->mx ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon mutex lock");
  return;
 }
 if (pthread_cond_destroy( &q->full_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon full_cv");
  return;
 }
 if (pthread_cond_destroy( &q->empty_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon empty_cv");
  return;
 }
}

canonical_original_code:
void prodcon_queue_destroy(struct prodcon_queue *q) {
 queue_destroy( &q->q );
 if (pthread_mutex_destroy( &q->mx ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon mutex lock");
  return;
 }
 if (pthread_cond_destroy( &q->full_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon full_cv");
  return;
 }
 if (pthread_cond_destroy( &q->empty_cv ) == -1) {
  fprintf(stderr, "Failed to destroy prodcon empty_cv");
  return;
 }
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall queue_produce(pthread_cond_t *cond, __int64 a2)
{
pthread_mutex_t *v2; // r12
unsigned int v3; // ebx

v2 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( 1 )
{
v3 = queue_isfull(&cond[2].__nwaiters);
if ( !v3 )
break;
pthread_cond_wait(cond, v2);
}
queue_enqueue((__int64)(&cond[2].__align + 5), a2);
pthread_cond_signal(cond + 1);
if ( pthread_mutex_unlock(v2) == -1 )
{
fwrite("queue_produce - Failed to release lock.", 1uLL, 0x27uLL, stderr);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(pthread_cond_t *cond, __int64 a2)
{
pthread_mutex_t *v2; // r12
unsigned int v3; // ebx

v2 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( 1 )
{
v3 = func7(&cond[2].__nwaiters);
if ( !v3 )
break;
pthread_cond_wait(cond, v2);
}
func8((__int64)(&cond[2].__align + 5), a2);
pthread_cond_signal(cond + 1);
if ( pthread_mutex_unlock(v2) == -1 )
{
fwrite("queue_produce - Failed to release lock.", 1uLL, 0x27uLL, stderr);
v3 = -1;
}
return v3;
}

original_code:
int queue_produce( prodcon_queue_t* q, void* item ) {
 pthread_mutex_lock( &q->mx );
 while( queue_isfull(&q->q) ) {
  pthread_cond_wait( &q->empty_cv, &q->mx );
 }
 queue_enqueue( &q->q, item );
 pthread_cond_signal( &q->full_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_produce - Failed to release lock.");
  return -1;
 }
 return 0;
}

canonical_original_code:
int queue_produce(struct prodcon_queue *q, void *item) {
 pthread_mutex_lock( &q->mx );
 while( queue_isfull(&q->q) ) {
  pthread_cond_wait( &q->empty_cv, &q->mx );
 }
 queue_enqueue( &q->q, item );
 pthread_cond_signal( &q->full_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_produce - Failed to release lock.");
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall queue_consume(pthread_cond_t *cond)
{
pthread_mutex_t *v1; // rbp
__int64 v2; // r12

v1 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( queue_isempty((__int64)(&cond[2].__align + 5)) )
{
if ( *((_DWORD *)&cond[3].__align + 4) )
return -1LL;
pthread_cond_wait(cond + 1, v1);
}
v2 = queue_dequeue((__int64)(&cond[2].__align + 5));
pthread_cond_signal(cond);
if ( pthread_mutex_unlock(v1) == -1 )
{
fwrite("queue_consume - Failed to release lock.", 1uLL, 0x27uLL, stderr);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(pthread_cond_t *cond)
{
pthread_mutex_t *v1; // rbp
__int64 v2; // r12

v1 = (pthread_mutex_t *)&cond[2];
pthread_mutex_lock((pthread_mutex_t *)&cond[2]);
while ( func4((__int64)(&cond[2].__align + 5)) )
{
if ( *((_DWORD *)&cond[3].__align + 4) )
return -1LL;
pthread_cond_wait(cond + 1, v1);
}
v2 = func5((__int64)(&cond[2].__align + 5));
pthread_cond_signal(cond);
if ( pthread_mutex_unlock(v1) == -1 )
{
fwrite("queue_consume - Failed to release lock.", 1uLL, 0x27uLL, stderr);
v2 = 0LL;
}
return v2;
}

original_code:
void* queue_consume( prodcon_queue_t* q ) {
 pthread_mutex_lock( &q->mx );
 while( queue_isempty(&q->q) ) {
  if( q->consume_all ) {
   return (void*)-1;
  }
  pthread_cond_wait( &q->full_cv, &q->mx );
 }
 void* item = queue_dequeue( &q->q );
 pthread_cond_signal( &q->empty_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_consume - Failed to release lock.");
  return ((void *)0);
 }
 return item;
}

canonical_original_code:
void *queue_consume(struct prodcon_queue *q) {
 pthread_mutex_lock( &q->mx );
 while( queue_isempty(&q->q) ) {
  if( q->consume_all ) {
   return (void *)-1;
  }
  pthread_cond_wait( &q->full_cv, &q->mx );
 }
 void *item = queue_dequeue( &q->q );
 pthread_cond_signal( &q->empty_cv );
 if (pthread_mutex_unlock( &q->mx ) == -1) {
  fprintf(stderr, "queue_consume - Failed to release lock.");
  return ((void *)0);
 }
 return item;
}


decompiled_code:
int __fastcall queue_consume_all(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 96));
*(_DWORD *)(a1 + 160) = 1;
while ( !queue_isempty(a1 + 136) )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 96));
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 96));
*(_DWORD *)(a1 + 160) = 1;
while ( !func4(a1 + 136) )
pthread_cond_broadcast((pthread_cond_t *)(a1 + 48));
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 96));
}

original_code:
void queue_consume_all( prodcon_queue_t* q ) {
 pthread_mutex_lock( &q->mx );
 q->consume_all = 1;
 while( !queue_isempty( &q->q ) ) {
  pthread_cond_broadcast( &q->full_cv );
 }
 pthread_mutex_unlock( &q->mx );
}

canonical_original_code:
void queue_consume_all(struct prodcon_queue *q) {
 pthread_mutex_lock( &q->mx );
 q->consume_all = 1;
 while( !queue_isempty( &q->q ) ) {
  pthread_cond_broadcast( &q->full_cv );
 }
 pthread_mutex_unlock( &q->mx );
}


decompiled_code:
__int64 __fastcall rwlock_queue_init(pthread_rwlock_t *a1, int a2)
{
unsigned int v2; // ebx

if ( pthread_rwlock_init(a1, 0LL) == -1 )
{
v2 = -1;
fwrite("Failed to initialize RW lock", 1uLL, 0x1CuLL, stderr);
}
else
{
v2 = queue_init((__int64)&a1[1], a2);
if ( v2 == -1 )
fwrite("Failed to initialize RW queue", 1uLL, 0x1DuLL, stderr);
else
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func14(pthread_rwlock_t *a1, int a2)
{
unsigned int v2; // ebx

if ( pthread_rwlock_init(a1, 0LL) == -1 )
{
v2 = -1;
fwrite("Failed to initialize RW lock", 1uLL, 0x1CuLL, stderr);
}
else
{
v2 = func1((__int64)&a1[1], a2);
if ( v2 == -1 )
fwrite("Failed to initialize RW queue", 1uLL, 0x1DuLL, stderr);
else
v2 = 0;
}
return v2;
}

original_code:
int rwlock_queue_init( rwlock_queue_t* q, int capacity ) {
 if (pthread_rwlock_init( &q->rwl, ((void *)0) ) == -1) {
  fprintf(stderr, "Failed to initialize RW lock");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "Failed to initialize RW queue");
  return -1;
 }
 return 0;
}

canonical_original_code:
int rwlock_queue_init(struct rwlock_queue *q, int capacity) {
 if (pthread_rwlock_init( &q->rwl, ((void *)0) ) == -1) {
  fprintf(stderr, "Failed to initialize RW lock");
  return -1;
 }
 if (queue_init( &q->q, capacity ) == -1) {
  fprintf(stderr, "Failed to initialize RW queue");
  return -1;
 }
 return 0;
}

variable_types: struct rwlock_queue { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } rwl; struct queue { int capacity; int size; int head; int tail; void **items; } q; } *

user_defined_types: struct rwlock_queue { union pthread_rwlock_t rwl; struct queue q; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }


decompiled_code:
int __fastcall rwlock_queue_destroy(pthread_rwlock_t *rwlock)
{
int result; // eax

queue_destroy((__int64)&rwlock[1]);
result = pthread_rwlock_destroy(rwlock);
if ( result == -1 )
result = fwrite("Failed to destry RW lock", 1uLL, 0x18uLL, stderr);
return result;
}

canonical_decompiled_code:
int __fastcall func15(pthread_rwlock_t *rwlock)
{
int result; // eax

func2((__int64)&rwlock[1]);
result = pthread_rwlock_destroy(rwlock);
if ( result == -1 )
result = fwrite("Failed to destry RW lock", 1uLL, 0x18uLL, stderr);
return result;
}

original_code:
void rwlock_queue_destroy( rwlock_queue_t* q ) {
 queue_destroy( &q->q );
 if (pthread_rwlock_destroy( &q->rwl ) == -1) {
  fprintf(stderr, "Failed to destry RW lock");
 }
}

canonical_original_code:
void rwlock_queue_destroy(struct rwlock_queue *q) {
 queue_destroy( &q->q );
 if (pthread_rwlock_destroy( &q->rwl ) == -1) {
  fprintf(stderr, "Failed to destry RW lock");
 }
}

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }


decompiled_code:
__int64 __fastcall queue_write(pthread_rwlock_t *rwlock, __int64 a2)
{
unsigned int v2; // ebp

pthread_rwlock_wrlock(rwlock);
v2 = queue_enqueue((__int64)&rwlock[1], a2);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(pthread_rwlock_t *rwlock, __int64 a2)
{
unsigned int v2; // ebp

pthread_rwlock_wrlock(rwlock);
v2 = func8((__int64)&rwlock[1], a2);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
v2 = -1;
}
return v2;
}

original_code:
int queue_write( rwlock_queue_t* q, void* item ) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_enqueue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}

canonical_original_code:
int queue_write(struct rwlock_queue *q, void *item) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_enqueue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}


decompiled_code:
__int64 __fastcall queue_rewrite(pthread_rwlock_t *rwlock, __int64 a2)
{
unsigned int v2; // ebp

pthread_rwlock_wrlock(rwlock);
v2 = queue_requeue((__int64)&rwlock[1], a2);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func17(pthread_rwlock_t *rwlock, __int64 a2)
{
unsigned int v2; // ebp

pthread_rwlock_wrlock(rwlock);
v2 = func3((__int64)&rwlock[1], a2);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("queue_write - Failed to release RW lock", 1uLL, 0x27uLL, stderr);
v2 = -1;
}
return v2;
}

original_code:
int queue_rewrite( rwlock_queue_t* q, void* item ) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_requeue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}

canonical_original_code:
int queue_rewrite(struct rwlock_queue *q, void *item) {
 int return_status;
 pthread_rwlock_wrlock( &q->rwl );
 return_status = queue_requeue( &q->q, item );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_write - Failed to release RW lock");
  return -1;
 }
 return return_status;
}


decompiled_code:
__int64 __fastcall queue_read(pthread_rwlock_t *rwlock)
{
__int64 v1; // rbp

pthread_rwlock_wrlock(rwlock);
v1 = queue_dequeue((__int64)&rwlock[1]);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("queue_read - Failed to release RW lock", 1uLL, 0x26uLL, stderr);
v1 = -1LL;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func18(pthread_rwlock_t *rwlock)
{
__int64 v1; // rbp

pthread_rwlock_wrlock(rwlock);
v1 = func5((__int64)&rwlock[1]);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("queue_read - Failed to release RW lock", 1uLL, 0x26uLL, stderr);
v1 = -1LL;
}
return v1;
}

original_code:
void* queue_read( rwlock_queue_t* q ) {
 pthread_rwlock_wrlock( &q->rwl );
 void* item = queue_dequeue( &q->q );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_read - Failed to release RW lock");
  return (void*)-1;
 }
 return item;
}

canonical_original_code:
void *queue_read(struct rwlock_queue *q) {
 pthread_rwlock_wrlock( &q->rwl );
 void *item = queue_dequeue( &q->q );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "queue_read - Failed to release RW lock");
  return (void *)-1;
 }
 return item;
}


decompiled_code:
__int64 __fastcall rwlock_queue_search(pthread_rwlock_t *rwlock, unsigned int (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
__int64 v4; // rbp

pthread_rwlock_rdlock(rwlock);
v4 = queue_search((__int64)&rwlock[1], a2, a3);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("rwlock_queue_search - Failed to release RW lock", 1uLL, 0x2FuLL, stderr);
v4 = 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func19(pthread_rwlock_t *rwlock, unsigned int (__fastcall *a2)(__int64, __int64, __int64), __int64 a3)
{
__int64 v4; // rbp

pthread_rwlock_rdlock(rwlock);
v4 = func6((__int64)&rwlock[1], a2, a3);
if ( pthread_rwlock_unlock(rwlock) == -1 )
{
fwrite("rwlock_queue_search - Failed to release RW lock", 1uLL, 0x2FuLL, stderr);
v4 = 0LL;
}
return v4;
}

original_code:
void* rwlock_queue_search( rwlock_queue_t* q, queue_search_cb cb, void* arg ) {
 pthread_rwlock_rdlock( &q->rwl );
 void* item = queue_search( &q->q, cb, arg );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "rwlock_queue_search - Failed to release RW lock");
  return (void*)((void *)0);
 }
 return item;
}

canonical_original_code:
void *rwlock_queue_search(struct rwlock_queue *q, int (*cb)(struct queue *q, void *item, void *arg), void *arg) {
 pthread_rwlock_rdlock( &q->rwl );
 void *item = queue_search( &q->q, cb, arg );
 if (pthread_rwlock_unlock( &q->rwl ) == -1) {
  fprintf(stderr, "rwlock_queue_search - Failed to release RW lock");
  return (void *)((void *)0);
 }
 return item;
}


decompiled_code:
int timer_malloc()
{
void **v0; // rbx
char *v1; // rbp
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v6[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v7[24]; // [rsp+138A0h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v0 = (void **)v6;
v1 = v6;
do
{
*(_QWORD *)v1 = malloc(0x40uLL);
v1 += 8;
}
while ( v1 != v7 );
do
free(*v0++);
while ( v0 != (void **)v7 );
gettimeofday(&v4, 0LL);
v2 = comp_time(tv.tv_sec, tv.tv_usec, v4.tv_sec, v4.tv_usec);
return fprintf(stderr, "Time taken for mallocs = %f msec\n", v2 / 1000.0);
}

canonical_decompiled_code:
int func7()
{
void **v0; // rbx
char *v1; // rbp
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v6[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v7[24]; // [rsp+138A0h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v0 = (void **)v6;
v1 = v6;
do
{
*(_QWORD *)v1 = malloc(0x40uLL);
v1 += 8;
}
while ( v1 != v7 );
do
free(*v0++);
while ( v0 != (void **)v7 );
gettimeofday(&v4, 0LL);
v2 = func9(tv.tv_sec, tv.tv_usec, v4.tv_sec, v4.tv_usec);
return fprintf(stderr, "Time taken for mallocs = %f msec\n", v2 / 1000.0);
}

original_code:
void timer_malloc() {
 char* mem_list[10000];
    struct timeval time_start, time_end;
    int j,i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void timer_malloc() {
 char *mem_list[10000];
    struct timeval time_start; struct timeval time_end;
    int j; int i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

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

variable_types: i int


decompiled_code:
int timer_mm()
{
int v0; // ebx
int i; // ebx
double v2; // xmm0_8
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch]
struct timeval v6; // [rsp+20h] [rbp-28h] BYREF
struct timeval tv; // [rsp+30h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
if ( (unsigned int)mm_init(&v4, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
mm_get(&v4);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
mm_put(&v4, v4 + v5 * i);
mm_release(&v4);
gettimeofday(&v6, 0LL);
v2 = comp_time(tv.tv_sec, tv.tv_usec, v6.tv_sec, v6.tv_usec);
return fprintf(stderr, "Time taken for MM = %f msec\n", v2 / 1000.0);
}

canonical_decompiled_code:
int func8()
{
int v0; // ebx
int i; // ebx
double v2; // xmm0_8
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch]
struct timeval v6; // [rsp+20h] [rbp-28h] BYREF
struct timeval tv; // [rsp+30h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
if ( (unsigned int)func10(&v4, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
func11(&v4);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
func12(&v4, v4 + v5 * i);
func13(&v4);
gettimeofday(&v6, 0LL);
v2 = func9(tv.tv_sec, tv.tv_usec, v6.tv_sec, v6.tv_usec);
return fprintf(stderr, "Time taken for MM = %f msec\n", v2 / 1000.0);
}

original_code:
void timer_mm() {
 struct timeval time_start, time_end;
 int j,i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void*) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n",
   comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void timer_mm() {
 struct timeval time_start; struct timeval time_end;
 int j; int i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 struct mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void *) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n",
   comp_time (time_start, time_end)/1000.0);
}

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; }


original_code:
double comp_time (struct timeval times, struct timeval timee)
{
  double elap = 0.0;
  if (timee.tv_sec > times.tv_sec) {
    elap += (((double)(timee.tv_sec - times.tv_sec -1))*1000000.0);
    elap += timee.tv_usec + (1000000-times.tv_usec);
  }
  else {
    elap = timee.tv_usec - times.tv_usec;
  }
  return ((unsigned long)(elap));
}

canonical_original_code:
double comp_time(struct timeval times, struct timeval timee)
{
  double elap = 0.0;
  if (timee.tv_sec > times.tv_sec) {
    elap += (((double)(timee.tv_sec - times.tv_sec -1))*1000000.0);
    elap += timee.tv_usec + (1000000-times.tv_usec);
  }
  else {
    elap = timee.tv_usec - times.tv_usec;
  }
  return ((unsigned long)(elap));
}

variable_types:
timee
struct timeval

variable_types: elap double


decompiled_code:
__int64 __fastcall mm_init(__int64 a1, unsigned int a2, unsigned int a3)
{
void *v4; // rax

*(_QWORD *)a1 = malloc((int)(a3 * a2));
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
v4 = malloc((int)a2);
*(_QWORD *)(a1 + 16) = v4;
memset(v4, 0, (int)a2);
*(_DWORD *)(a1 + 24) = -1;
printf("%i chunks of %i bytes have been allocated.\n", a2, a3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2, unsigned int a3)
{
void *v4; // rax

*(_QWORD *)a1 = malloc((int)(a3 * a2));
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
v4 = malloc((int)a2);
*(_QWORD *)(a1 + 16) = v4;
memset(v4, 0, (int)a2);
*(_DWORD *)(a1 + 24) = -1;
printf("%i chunks of %i bytes have been allocated.\n", a2, a3);
return 1LL;
}

original_code:
int mm_init (mm_t *MM, int hm, int sz) {
 if ((MM->blocks = malloc(hm * sz)) == -1) {
  fprintf(stderr, "Failed to allocate memory.");
  return -1;
 }
 MM->total_chunks = hm;
 MM->size = sz;
 if((MM->allocated = (char*)malloc(hm)) == -1 ) {
  fprintf(stderr, "Failed to allocate array to keep track of allocated memory.");
  free(MM->blocks);
  return -1;
 }
 memset(MM->allocated, 0, hm);
 MM->last_allocated = -1;
 printf("%i chunks of %i bytes have been allocated.\n", hm, sz);
 return 1;
}

canonical_original_code:
int mm_init(struct mm_t *MM, int hm, int sz) {
 if ((MM->blocks = malloc(hm * sz)) == -1) {
  fprintf(stderr, "Failed to allocate memory.");
  return -1;
 }
 MM->total_chunks = hm;
 MM->size = sz;
 if((MM->allocated = (char *)malloc(hm)) == -1 ) {
  fprintf(stderr, "Failed to allocate array to keep track of allocated memory.");
  free(MM->blocks);
  return -1;
 }
 memset(MM->allocated, 0, hm);
 MM->last_allocated = -1;
 printf("%i chunks of %i bytes have been allocated.\n", hm, sz);
 return 1;
}

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; } *

variable_types: hm int

variable_types: sz int


decompiled_code:
__int64 __fastcall mm_get(__int64 a1)
{
int v2; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v2 <= 0 )
{
LABEL_6:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, stderr);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v2 + v3;
while ( 1 )
{
v6 = v4 % v2;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v2);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_6;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v2; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v2 <= 0 )
{
LABEL_6:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, stderr);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v2 + v3;
while ( 1 )
{
v6 = v4 % v2;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v2);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_6;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

original_code:
void* mm_get (mm_t *MM) {
 void* chunk;
 int length = MM->total_chunks;
 int base = MM->last_allocated + 1;
 int i;
 for (i = 0; i < length; i++) {
  int slot = (base + i) % length;
  if (MM->allocated[ slot ] == 0) {
   MM->allocated[ slot ] = 1;
   MM->last_allocated = slot;
   chunk = MM->blocks + slot * MM->size;
   return chunk;
  }
 }
 fprintf(stderr, "No more memory chunks are available!");
 return -1;
}

canonical_original_code:
void *mm_get(struct mm_t *MM) {
 void *chunk;
 int length = MM->total_chunks;
 int base = MM->last_allocated + 1;
 int i;
 for (i = 0; i < length; i++) {
  int slot = (base + i) % length;
  if (MM->allocated[ slot ] == 0) {
   MM->allocated[ slot ] = 1;
   MM->last_allocated = slot;
   chunk = MM->blocks + slot * MM->size;
   return chunk;
  }
 }
 fprintf(stderr, "No more memory chunks are available!");
 return -1;
}

variable_types:
chunk
void *

variable_types: length int

variable_types: base int

variable_types: slot int

user_defined_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; }


original_code:
void mm_put (mm_t *MM, void *chunk) {
 int i;
 int index = ((unsigned int)chunk - (unsigned int)MM->blocks) / MM->size;
 MM->allocated[index] = 0;
 memset(chunk, 0, MM->size);
}

canonical_original_code:
void mm_put(struct mm_t *MM, void *chunk) {
 int i;
 int index = ((unsigned int)chunk - (unsigned int)MM->blocks) / MM->size;
 MM->allocated[index] = 0;
 memset(chunk, 0, MM->size);
}

variable_types: index int


original_code:
void mm_release (mm_t *MM) {
 free(MM->blocks);
 free(MM->allocated);
 memset(MM, 0, sizeof(mm_t));
}

canonical_original_code:
void mm_release(struct mm_t *MM) {
 free(MM->blocks);
 free(MM->allocated);
 memset(MM, 0, sizeof(mm_t));
}


decompiled_code:
int timer_example()
{
unsigned int i; // ebx
double v1; // xmm0_8
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
for ( i = 0; i != 10; ++i )
printf("%i ", i);
gettimeofday(&v3, 0LL);
v1 = comp_time(tv.tv_sec, tv.tv_usec, v3.tv_sec, v3.tv_usec);
return fprintf(stderr, "Time taken = %f msec\n", v1 / 1000.0);
}

canonical_decompiled_code:
int func14()
{
unsigned int i; // ebx
double v1; // xmm0_8
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
for ( i = 0; i != 10; ++i )
printf("%i ", i);
gettimeofday(&v3, 0LL);
v1 = func9(tv.tv_sec, tv.tv_usec, v3.tv_sec, v3.tv_usec);
return fprintf(stderr, "Time taken = %f msec\n", v1 / 1000.0);
}

original_code:
void timer_example ()
{
    struct timeval time_start, time_end;
    int j;
    j = gettimeofday (&time_start, (void *)((void *)0));
    int i;
 for (i = 0; i < 10; i++){
  printf("%i ", i);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void timer_example()
{
    struct timeval time_start; struct timeval time_end;
    int j;
    j = gettimeofday (&time_start, (void *)((void *)0));
    int i;
 for (i = 0; i < 10; i++){
  printf("%i ", i);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int i; // ebx

if ( argc == 2 )
{
result = atoi(argv[1]);
for ( i = result; i > 0; --i )
{
timer_malloc();
timer_mm();
result = puts("\n");
}
}
else
{
timer_malloc();
timer_mm();
result = puts("\n");
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int i; // ebx

if ( argc == 2 )
{
result = atoi(argv[1]);
for ( i = result; i > 0; --i )
{
func7();
func8();
result = puts("\n");
}
}
else
{
func7();
func8();
result = puts("\n");
}
return result;
}

original_code:
void main(int argc, char* argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--) {
  timer_malloc();
  timer_mm();
  printf("\n\n");
 }
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--) {
  timer_malloc();
  timer_mm();
  printf("\n\n");
 }
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int __fastcall calc_blocks(int a1, int a2, int a3, int a4)
{
int v6; // er12
double v7; // xmm0_8
__m128d v8; // xmm3
__m128d v9; // xmm1
unsigned int v10; // er13
int v11; // er15
int result; // eax
unsigned int v13; // er14
unsigned int v14; // ebp
unsigned int v15; // ebx
signed int v16; // er12
unsigned int v17; // eax
__int64 v18; // r8
unsigned int v19; // eax
unsigned int v20; // ebx
unsigned int v21; // [rsp+Ch] [rbp-3Ch]

v6 = a3 + a4;
v7 = (double)a3 / (double)a2;
v8.m128d_f64[0] = v7;
if ( fabs((double)a3 / (double)a2) < 4.503599627370496e15 )
{
v9.m128d_f64[0] = (double)(int)v7;
*(_QWORD *)&v8.m128d_f64[0] = COERCE_UNSIGNED_INT64(
COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v8, v9) & 0x3FF0000000000000LL)
+ v9.m128d_f64[0]) | *(_QWORD *)&v7 & 0x8000000000000000LL;
}
v10 = (int)v8.m128d_f64[0];
v11 = v6 / 10;
if ( a3 / (int)v8.m128d_f64[0] > a1 )
puts("error: impossible configuration of max blocks/threads and the input.");
result = printf("nt=%i, bw=%i, bh=%i, nd=%i\n", (unsigned int)a2, v10, 10LL, (unsigned int)v11);
if ( v6 > 9 )
{
v13 = -a4;
v14 = 0;
v21 = a3 - 1;
do
{
v15 = max(v13, 0);
v16 = min(v14, v21);
v17 = max(1u, v16 - v15);
for ( result = printf("sx=%i, sf=%i, nb=%i, nb=%i\n", v15, (unsigned int)v16, v17, v18);
v16 >= (int)v15;
v15 = v20 + 1 )
{
v19 = v14 + v15;
v20 = v10 * v15;
result = printf("%i: [%i, %i]\n", v14, 10 * v19, v20);
}
++v14;
++v13;
}
while ( v11 > (int)v14 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2, int a3, int a4)
{
int v6; // er12
double v7; // xmm0_8
__m128d v8; // xmm3
__m128d v9; // xmm1
unsigned int v10; // er13
int v11; // er15
int result; // eax
unsigned int v13; // er14
unsigned int v14; // ebp
unsigned int v15; // ebx
signed int v16; // er12
unsigned int v17; // eax
__int64 v18; // r8
unsigned int v19; // eax
unsigned int v20; // ebx
unsigned int v21; // [rsp+Ch] [rbp-3Ch]

v6 = a3 + a4;
v7 = (double)a3 / (double)a2;
v8.m128d_f64[0] = v7;
if ( fabs((double)a3 / (double)a2) < 4.503599627370496e15 )
{
v9.m128d_f64[0] = (double)(int)v7;
*(_QWORD *)&v8.m128d_f64[0] = COERCE_UNSIGNED_INT64(
COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v8, v9) & 0x3FF0000000000000LL)
+ v9.m128d_f64[0]) | *(_QWORD *)&v7 & 0x8000000000000000LL;
}
v10 = (int)v8.m128d_f64[0];
v11 = v6 / 10;
if ( a3 / (int)v8.m128d_f64[0] > a1 )
puts("error: impossible configuration of max blocks/threads and the input.");
result = printf("nt=%i, bw=%i, bh=%i, nd=%i\n", (unsigned int)a2, v10, 10LL, (unsigned int)v11);
if ( v6 > 9 )
{
v13 = -a4;
v14 = 0;
v21 = a3 - 1;
do
{
v15 = func7(v13, 0);
v16 = func8(v14, v21);
v17 = func7(1u, v16 - v15);
for ( result = printf("sx=%i, sf=%i, nb=%i, nb=%i\n", v15, (unsigned int)v16, v17, v18);
v16 >= (int)v15;
v15 = v20 + 1 )
{
v19 = v14 + v15;
v20 = v10 * v15;
result = printf("%i: [%i, %i]\n", v14, 10 * v19, v20);
}
++v14;
++v13;
}
while ( v11 > (int)v14 );
}
return result;
}

original_code:
void calc_blocks(int maxb, int maxt, int w, int h) {
 int d = w + h;
 int nt, bh, bw, nd;
 nt = maxt;
 bw = ceil((double)w / (double)nt);
 bh = 10;
 nd = d / bh;
 if(w/bw > maxb) {
  printf("error: impossible configuration of max blocks/threads and the input.\n");
 }
 printf("nt=%i, bw=%i, bh=%i, nd=%i\n", nt, bw, bh, nd);
 int r;
 for(r = 0; r < nd; r++) {
  int sx = max(r - h, 0);
  int fx = min(r, w - 1);
  int nb = max(1, fx - sx);
  printf("sx=%i, sf=%i, nb=%i, nb=%i\n", sx, fx, nb);
  int x;
  for(x = sx; x <= fx; x++) {
   int y = x + r;
   x *= bw;
   y *= bh;
   printf("%i: [%i, %i]\n", r, y, x);
  }
 }
}

canonical_original_code:
void calc_blocks(int maxb, int maxt, int w, int h) {
 int d = w + h;
 int nt; int bh; int bw; int nd;
 nt = maxt;
 bw = ceil((double)w / (double)nt);
 bh = 10;
 nd = d / bh;
 if(w/bw > maxb) {
  printf("error: impossible configuration of max blocks/threads and the input.\n");
 }
 printf("nt=%i, bw=%i, bh=%i, nd=%i\n", nt, bw, bh, nd);
 int r;
 for(r = 0; r < nd; r++) {
  int sx = max(r - h, 0);
  int fx = min(r, w - 1);
  int nb = max(1, fx - sx);
  printf("sx=%i, sf=%i, nb=%i, nb=%i\n", sx, fx, nb);
  int x;
  for(x = sx; x <= fx; x++) {
   int y = x + r;
   x *= bw;
   y *= bh;
   printf("%i: [%i, %i]\n", r, y, x);
  }
 }
}

variable_types: maxb int

variable_types: maxt int

variable_types: w int

variable_types: h int

variable_types: d int

variable_types: nt int

variable_types: bh int

variable_types: bw int

variable_types: nd int

variable_types: r int

variable_types: sx int

variable_types: fx int

variable_types: nb int

variable_types: x int

variable_types: y int


original_code:
int test_calc(int maxb, int maxt, int w, int h) {
 if(maxt*maxb > w) {
  return -1;
 }
 int bw = maxt;
 int bh = 10;
 int nby = ceil( (double)h / (double)bh );
 int nbx = ceil( (double)w / (double)bw );
 int nd = nbx + nby - 1;
 int d;
 for(d = 0; d < nd; d++) {
 }
}

variable_types: nby int

variable_types: nbx int


max

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 >= (int)a2 )
result = a1;
return result;
}

original_code:
int max(int a, int b) {
    if(a > b) return a;
    else return b;
}

variable_types: a int

variable_types: b int


min

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
int min(int a, int b) {
    if(a < b) return a;
    else return b;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
calc_blocks(5, 2, 60, 80);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func9(5, 2, 60, 80);
return 0;
}

original_code:
int main() {
 calc_blocks(5, 2, 60, 80);
}


merge

original_code:
void merge(const int* a, const int* b, const unsigned long n, int* out) {
 unsigned long cura=0, curb=0, curout=0;
 while( cura < n && curb < n ) {
  if( a[ cura ] < b[ curb ] ) {
   out[ curout ] = a[ cura ];
   cura++;
  } else {
   out[ curout ] = b[ curb ];
   curb++;
  }
  curout++;
 }
 while( curb < n ) {
  out[ curout ] = b[ curb ];
  curb++; curout++;
 }
 while( cura < n ) {
  out[ curout ] = a[ cura ];
  cura++; curout++;
 }
}

canonical_original_code:
void merge(int *a, int *b, unsigned long n, int *out) {
 unsigned long cura = 0; unsigned long curb = 0; unsigned long curout = 0;
 while( cura < n && curb < n ) {
  if( a[ cura ] < b[ curb ] ) {
   out[ curout ] = a[ cura ];
   cura++;
  } else {
   out[ curout ] = b[ curb ];
   curb++;
  }
  curout++;
 }
 while( curb < n ) {
  out[ curout ] = b[ curb ];
  curb++; curout++;
 }
 while( cura < n ) {
  out[ curout ] = a[ cura ];
  cura++; curout++;
 }
}

variable_types:
a
int *

variable_types:
b
int *

variable_types:
n
unsigned long

variable_types:
out
int *

variable_types:
cura
unsigned long

variable_types:
curb
unsigned long

variable_types:
curout
unsigned long


decompiled_code:
double get_timeofday()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

canonical_decompiled_code:
double func8()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (double)SLODWORD(v1.tv_usec) / 1000000.0 + (double)SLODWORD(v1.tv_sec);
}

original_code:
double get_timeofday() {
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 return tv.tv_sec+(tv.tv_usec/1000000.0);
}

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


original_code:
void merge_helper(int *input, unsigned long left, unsigned long right, int *scratch)
{
    if(right == left + 1)
    {
        return;
    }
    else
    {
        unsigned long i = 0;
        unsigned long length = right - left;
        unsigned long midpoint_distance = length/2;
        unsigned long l = left, r = left + midpoint_distance;
        merge_helper(input, left, left + midpoint_distance, scratch);
        merge_helper(input, left + midpoint_distance, right, scratch);
        for(i = 0; i < length; i++)
        {
            if(l < left + midpoint_distance &&
                    (r == right || min(input[l], input[r]) == input[l]))
            {
                scratch[i] = input[l];
                l++;
            }
            else
            {
                scratch[i] = input[r];
                r++;
            }
        }
        for(i = left; i < right; i++)
        {
            input[i] = scratch[i - left];
        }
    }
}

canonical_original_code:
void merge_helper(int *input, unsigned long left, unsigned long right, int *scratch)
{
    if(right == left + 1)
    {
        return;
    }
    else
    {
        unsigned long i = 0;
        unsigned long length = right - left;
        unsigned long midpoint_distance = length/2;
        unsigned long l = left; unsigned long r = left + midpoint_distance;
        merge_helper(input, left, left + midpoint_distance, scratch);
        merge_helper(input, left + midpoint_distance, right, scratch);
        for(i = 0; i < length; i++)
        {
            if(l < left + midpoint_distance &&
                    (r == right || min(input[l], input[r]) == input[l]))
            {
                scratch[i] = input[l];
                l++;
            }
            else
            {
                scratch[i] = input[r];
                r++;
            }
        }
        for(i = left; i < right; i++)
        {
            input[i] = scratch[i - left];
        }
    }
}

variable_types:
input
int *

variable_types:
left
unsigned long

variable_types:
right
unsigned long

variable_types:
scratch
int *

variable_types:
i
unsigned long

variable_types:
length
unsigned long

variable_types:
l
unsigned long

variable_types:
r
unsigned long


mergesort

decompiled_code:
__int64 __fastcall mergesort(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax
void *v3; // rbx

v2 = malloc(4 * a2);
if ( !v2 )
return 0LL;
v3 = v2;
merge_helper(a1, 0LL, a2, (__int64)v2);
free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned __int64 a2)
{
void *v2; // rax
void *v3; // rbx

v2 = malloc(4 * a2);
if ( !v2 )
return 0LL;
v3 = v2;
func11(a1, 0LL, a2, (__int64)v2);
free(v3);
return 1LL;
}

original_code:
int mergesort(int *input, unsigned long size)
{
    int *scratch = (int *)malloc(size * sizeof(int));
    if(scratch != ((void *)0))
    {
        merge_helper(input, 0, size, scratch);
        free(scratch);
        return 1;
    }
    else
    {
        return 0;
    }
}

variable_types:
size
unsigned long


min

decompiled_code:
unsigned __int64 __fastcall min(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = a2;
if ( a1 <= a2 )
result = a1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

result = a2;
if ( a1 <= a2 )
result = a1;
return result;
}

original_code:
unsigned long min(unsigned long x, unsigned long y)
{
    if(x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

variable_types:
x
unsigned long

variable_types:
y
unsigned long

return_type: unsigned long


decompiled_code:
__sighandler_t handle_complete_messages()
{
void (*v0)(int); // r14
__int64 *v1; // rbx
__m128i *v2; // r13

v0 = signal(14, (__sighandler_t)1);
v1 = g_messages;
do
{
if ( *((_DWORD *)v1 + 2) != -1 && *((_DWORD *)v1 + 1) == *(_DWORD *)v1 )
{
v2 = assemble_message((int *)v1);
printf("GOT IT: msg_id=%d, message=%s\n", *((unsigned int *)v1 + 2), v2->m128i_i8);
free(v2);
*((_DWORD *)v1 + 2) = -1;
}
v1 += 12;
}
while ( v1 != (__int64 *)&which_pkt_2 );
return signal(14, v0);
}

canonical_decompiled_code:
__sighandler_t func8()
{
void (*v0)(int); // r14
__int64 *v1; // rbx
__m128i *v2; // r13

v0 = signal(14, (__sighandler_t)1);
v1 = g_messages;
do
{
if ( *((_DWORD *)v1 + 2) != -1 && *((_DWORD *)v1 + 1) == *(_DWORD *)v1 )
{
v2 = assemble_message((int *)v1);
printf("GOT IT: msg_id=%d, message=%s\n", *((unsigned int *)v1 + 2), v2->m128i_i8);
free(v2);
*((_DWORD *)v1 + 2) = -1;
}
v1 += 12;
}
while ( v1 != (__int64 *)&which_pkt_2 );
return signal(14, v0);
}

original_code:
void handle_complete_messages() {
 void* old_handler = signal(14, ((__sighandler_t) 1));
 int i;
 for( i = 0; i < 15; i++ ) {
  if( g_messages[ i ].id == -1 ) {
   continue;
  }
  if( g_messages[ i ].how_many_arrived == g_messages[ i ].num_packets ) {
   char* msg = assemble_message( &g_messages[ i ] );
   printf( "GOT IT: msg_id=%d, message=%s\n", g_messages[ i ].id, msg );
   free( msg );
   g_messages[ i ].id = -1;
  }
 }
 signal(14, old_handler);
}

canonical_original_code:
void handle_complete_messages() {
 void *old_handler = signal(14, ((__sighandler_t) 1));
 int i;
 for( i = 0; i < 15; i++ ) {
  if( g_messages[ i ].id == -1 ) {
   continue;
  }
  if( g_messages[ i ].how_many_arrived == g_messages[ i ].num_packets ) {
   char *msg = assemble_message( &g_messages[ i ] );
   printf( "GOT IT: msg_id=%d, message=%s\n", g_messages[ i ].id, msg );
   free( msg );
   g_messages[ i ].id = -1;
  }
 }
 signal(14, old_handler);
}

variable_types: i int

variable_types:
msg
char *


original_code:
void packet_handler(int sig)
{
 void* old_handler = signal(sig, ((__sighandler_t) 1));
  packet_t pkt = get_packet();
  if(pkt.msg_id == -1) {
   g_has_more = 0;
  }
  g_messages[ pkt.msg_id ].id = pkt.msg_id;
  g_messages[ pkt.msg_id ].num_packets = pkt.how_many;
  g_messages[ pkt.msg_id ].how_many_arrived++;
 void* memory = mm_get(&g_MM);
 memcpy(memory, pkt.data, 56);
 g_messages[ pkt.msg_id ].data[ pkt.which ] = memory;
 signal(sig, old_handler);
}

canonical_original_code:
void packet_handler(int sig)
{
 void *old_handler = signal(sig, ((__sighandler_t) 1));
  struct packet_t pkt = get_packet();
  if(pkt.msg_id == -1) {
   g_has_more = 0;
  }
  g_messages[ pkt.msg_id ].id = pkt.msg_id;
  g_messages[ pkt.msg_id ].num_packets = pkt.how_many;
  g_messages[ pkt.msg_id ].how_many_arrived++;
 void *memory = mm_get(&g_MM);
 memcpy(memory, pkt.data, 56);
 g_messages[ pkt.msg_id ].data[ pkt.which ] = memory;
 signal(sig, old_handler);
}

variable_types: sig int

variable_types: struct packet_t { int how_many; int which; int msg_id; char data[56]; }

variable_types:
memory
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rax
void (*v4)(int); // rbx
struct itimerval v6; // [rsp+0h] [rbp-28h] BYREF

v3 = dword_404328;
do
{
*v3 = -1;
v3 += 24;
}
while ( v3 != &num_packets_4 );
if ( (unsigned int)mm_init(&g_MM, 100LL, 64LL) == -1 )
fwrite("failed to initialize mm for packets", 1uLL, 0x23uLL, _bss_start);
v4 = signal(14, packet_handler);
v6.it_interval.tv_sec = 0LL;
v6.it_interval.tv_usec = 50000LL;
v6.it_value.tv_sec = 0LL;
v6.it_value.tv_usec = 100LL;
setitimer(ITIMER_REAL, &v6, 0LL);
while ( g_has_more )
{
handle_complete_messages();
pause();
}
v6.it_interval.tv_usec = 0LL;
v6.it_interval.tv_sec = 0LL;
setitimer(ITIMER_REAL, &v6, 0LL);
signal(14, v4);
mm_release(&g_MM);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int *v3; // rax
void (*v4)(int); // rbx
struct itimerval v6; // [rsp+0h] [rbp-28h] BYREF

v3 = dword_404328;
do
{
*v3 = -1;
v3 += 24;
}
while ( v3 != &num_packets_4 );
if ( (unsigned int)func10(&g_MM, 100LL, 64LL) == -1 )
fwrite("failed to initialize mm for packets", 1uLL, 0x23uLL, _bss_start);
v4 = signal(14, packet_handler);
v6.it_interval.tv_sec = 0LL;
v6.it_interval.tv_usec = 50000LL;
v6.it_value.tv_sec = 0LL;
v6.it_value.tv_usec = 100LL;
setitimer(ITIMER_REAL, &v6, 0LL);
while ( g_has_more )
{
func8();
pause();
}
v6.it_interval.tv_usec = 0LL;
v6.it_interval.tv_sec = 0LL;
setitimer(ITIMER_REAL, &v6, 0LL);
signal(14, v4);
func13(&g_MM);
return 0;
}

original_code:
int main (int argc, char **argv)
{
 int i;
 for( i = 0; i < 15; i++ ) {
  g_messages[ i ].id = -1;
 }
 if(mm_init (&g_MM, 100, 64) == -1){
  fprintf(stderr, "failed to initialize mm for packets");
 }
 void* old_handler = signal(14, packet_handler);
 struct itimerval itv;
 itv.it_interval.tv_sec = 0;
 itv.it_interval.tv_usec = 50000;
 itv.it_value.tv_sec = 0;
 itv.it_value.tv_usec = 100;
 setitimer( ITIMER_REAL, &itv, ((void *)0) );
 while( g_has_more ) {
  handle_complete_messages();
  pause();
 }
    itv.it_interval.tv_sec = itv.it_interval.tv_usec = 0;
    setitimer( ITIMER_REAL, &itv, ((void *)0) );
 signal(14, old_handler);
 mm_release(&g_MM);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i;
 for( i = 0; i < 15; i++ ) {
  g_messages[ i ].id = -1;
 }
 if(mm_init (&g_MM, 100, 64) == -1){
  fprintf(stderr, "failed to initialize mm for packets");
 }
 void *old_handler = signal(14, packet_handler);
 struct itimerval itv;
 itv.it_interval.tv_sec = 0;
 itv.it_interval.tv_usec = 50000;
 itv.it_value.tv_sec = 0;
 itv.it_value.tv_usec = 100;
 setitimer( ITIMER_REAL, &itv, ((void *)0) );
 while( g_has_more ) {
  handle_complete_messages();
  pause();
 }
    itv.it_interval.tv_sec = itv.it_interval.tv_usec = 0;
    setitimer( ITIMER_REAL, &itv, ((void *)0) );
 signal(14, old_handler);
 mm_release(&g_MM);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
int main_mm()
{
int v0; // ebx
int i; // ebx
double v2; // xmm0_8
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch]
struct timeval v6; // [rsp+20h] [rbp-28h] BYREF
struct timeval tv; // [rsp+30h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
if ( (unsigned int)mm_init(&v4, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
mm_get(&v4);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
mm_put(&v4, v4 + v5 * i);
mm_release(&v4);
gettimeofday(&v6, 0LL);
v2 = comp_time(tv.tv_sec, tv.tv_usec, v6.tv_sec, v6.tv_usec);
return fprintf(stderr, "Time taken for MM = %f msec\n\n", v2 / 1000.0);
}

canonical_decompiled_code:
int func7()
{
int v0; // ebx
int i; // ebx
double v2; // xmm0_8
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
int v5; // [rsp+Ch] [rbp-3Ch]
struct timeval v6; // [rsp+20h] [rbp-28h] BYREF
struct timeval tv; // [rsp+30h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
if ( (unsigned int)func9(&v4, 10000LL, 64LL) == -1 )
perror("failed to initialize mm");
v0 = 10000;
do
{
func10(&v4);
--v0;
}
while ( v0 );
for ( i = 0; i != 10000; ++i )
func11(&v4, v4 + v5 * i);
func12(&v4);
gettimeofday(&v6, 0LL);
v2 = func8(tv.tv_sec, tv.tv_usec, v6.tv_sec, v6.tv_usec);
return fprintf(stderr, "Time taken for MM = %f msec\n\n", v2 / 1000.0);
}

original_code:
void main_mm() {
 struct timeval time_start, time_end;
 int j,i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void*) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n\n",
   comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void main_mm() {
 struct timeval time_start; struct timeval time_end;
 int j; int i;
 j = gettimeofday (&time_start, (void *)((void *)0));
 struct mm_t MM;
 if(mm_init (&MM, 10000, 64) == -1){
  perror("failed to initialize mm");
 }
 for (i = 0; i < 10000; i++){
  mm_get (&MM);
 }
 for (i = 0; i < 10000; i++){
  mm_put (&MM, (void *) (MM.blocks + i * MM.size));
 }
 mm_release(&MM);
 j = gettimeofday (&time_end, (void *)((void *)0));
 fprintf (stderr, "Time taken for MM =  %f msec\n\n",
   comp_time (time_start, time_end)/1000.0);
}

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

variable_types: j int

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; }


original_code:
double comp_time (struct timeval times, struct timeval timee)
{
  double elap = 0.0;
  if (timee.tv_sec > times.tv_sec) {
    elap += (((double)(timee.tv_sec - times.tv_sec -1))*1000000.0);
    elap += timee.tv_usec + (1000000-times.tv_usec);
  }
  else {
    elap = timee.tv_usec - times.tv_usec;
  }
  return ((unsigned long)(elap));
}

variable_types:
timee
struct timeval

variable_types: elap double


canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2, unsigned int a3)
{
void *v4; // rax

*(_QWORD *)a1 = malloc((int)(a3 * a2));
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
v4 = malloc((int)a2);
*(_QWORD *)(a1 + 16) = v4;
memset(v4, 0, (int)a2);
*(_DWORD *)(a1 + 24) = -1;
printf("%i chunks of %i bytes have been allocated.\n", a2, a3);
return 1LL;
}

original_code:
int mm_init (mm_t *MM, int hm, int sz) {
 if ((MM->blocks = malloc(hm * sz)) == -1) {
  fprintf(stderr, "Failed to allocate memory.");
  return -1;
 }
 MM->total_chunks = hm;
 MM->size = sz;
 if((MM->allocated = (char*)malloc(hm)) == -1 ) {
  fprintf(stderr, "Failed to allocate array to keep track of allocated memory.");
  free(MM->blocks);
  return -1;
 }
 memset(MM->allocated, 0, hm);
 MM->last_allocated = -1;
 printf("%i chunks of %i bytes have been allocated.\n", hm, sz);
 return 1;
}

variable_types: struct mm_t { char *blocks; int total_chunks; int size; char *allocated; int last_allocated; } *

variable_types: hm int

variable_types: sz int


canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v2; // esi
int v3; // edi
int v4; // ecx
int v5; // edi
int v6; // edx
_BYTE *v7; // rax
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 8);
v3 = *(_DWORD *)(a1 + 24);
if ( v2 <= 0 )
{
LABEL_6:
fwrite("No more memory chunks are available!", 1uLL, 0x24uLL, stderr);
result = -1LL;
}
else
{
v4 = v3 + 1;
v5 = v2 + v3;
while ( 1 )
{
v6 = v4 % v2;
v7 = (_BYTE *)(*(_QWORD *)(a1 + 16) + v4 % v2);
if ( !*v7 )
break;
if ( v4 == v5 )
goto LABEL_6;
++v4;
}
*v7 = 1;
*(_DWORD *)(a1 + 24) = v6;
result = *(_QWORD *)a1 + *(_DWORD *)(a1 + 12) * v6;
}
return result;
}

original_code:
void* mm_get (mm_t *MM) {
 void* chunk;
 int length = MM->total_chunks;
 int base = MM->last_allocated + 1;
 int i;
 for (i = 0; i < length; i++) {
  int slot = (base + i) % length;
  if (MM->allocated[ slot ] == 0) {
   MM->allocated[ slot ] = 1;
   MM->last_allocated = slot;
   chunk = MM->blocks + slot * MM->size;
   return chunk;
  }
 }
 fprintf(stderr, "No more memory chunks are available!");
 return -1;
}

variable_types:
chunk
void *

variable_types: length int

variable_types: base int

variable_types: slot int


original_code:
void mm_put (mm_t *MM, void *chunk) {
 int i;
 int index = ((unsigned int)chunk - (unsigned int)MM->blocks) / MM->size;
 MM->allocated[index] = 0;
 memset(chunk, 0, MM->size);
}

variable_types: i int

variable_types: index int


original_code:
void mm_release (mm_t *MM) {
 free(MM->blocks);
 free(MM->allocated);
 memset(MM, 0, sizeof(mm_t));
}


canonical_decompiled_code:
int func13()
{
unsigned int i; // ebx
double v1; // xmm0_8
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
struct timeval tv; // [rsp+10h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
for ( i = 0; i != 10; ++i )
printf("%i ", i);
gettimeofday(&v3, 0LL);
v1 = func8(tv.tv_sec, tv.tv_usec, v3.tv_sec, v3.tv_usec);
return fprintf(stderr, "Time taken = %f msec\n", v1 / 1000.0);
}

original_code:
void timer_example ()
{
    struct timeval time_start, time_end;
    int j;
    j = gettimeofday (&time_start, (void *)((void *)0));
    int i;
 for (i = 0; i < 10; i++){
  printf("%i ", i);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken =  %f msec\n",
      comp_time (time_start, time_end)/1000.0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int i; // ebx

if ( argc != 2 )
return main_mm();
result = atoi(argv[1]);
for ( i = result; i > 0; --i )
result = main_mm();
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int i; // ebx

if ( argc != 2 )
return func7();
result = atoi(argv[1]);
for ( i = result; i > 0; --i )
result = func7();
return result;
}

original_code:
void main(int argc, char* argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_mm();
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_mm();
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int main_malloc()
{
void **v0; // rbx
char *v1; // rbp
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v6[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v7[24]; // [rsp+138A0h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v0 = (void **)v6;
v1 = v6;
do
{
*(_QWORD *)v1 = malloc(0x40uLL);
v1 += 8;
}
while ( v1 != v7 );
do
free(*v0++);
while ( v0 != (void **)v7 );
gettimeofday(&v4, 0LL);
v2 = comp_time(tv.tv_sec, tv.tv_usec, v4.tv_sec, v4.tv_usec);
return fprintf(stderr, "Time taken for mallocs = %f msec\n\n", v2 / 1000.0);
}

canonical_decompiled_code:
int func7()
{
void **v0; // rbx
char *v1; // rbp
double v2; // xmm0_8
struct timeval v4; // [rsp+0h] [rbp-138B8h] BYREF
struct timeval tv; // [rsp+10h] [rbp-138A8h] BYREF
char v6[80000]; // [rsp+20h] [rbp-13898h] BYREF
char v7[24]; // [rsp+138A0h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
v0 = (void **)v6;
v1 = v6;
do
{
*(_QWORD *)v1 = malloc(0x40uLL);
v1 += 8;
}
while ( v1 != v7 );
do
free(*v0++);
while ( v0 != (void **)v7 );
gettimeofday(&v4, 0LL);
v2 = func8(tv.tv_sec, tv.tv_usec, v4.tv_sec, v4.tv_usec);
return fprintf(stderr, "Time taken for mallocs = %f msec\n\n", v2 / 1000.0);
}

original_code:
void main_malloc() {
 char* mem_list[10000];
    struct timeval time_start, time_end;
    int j,i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n\n",
      comp_time (time_start, time_end)/1000.0);
}

canonical_original_code:
void main_malloc() {
 char *mem_list[10000];
    struct timeval time_start; struct timeval time_end;
    int j; int i;
    j = gettimeofday (&time_start, (void *)((void *)0));
 for (i = 0; i < 10000; i++){
  mem_list[i] = malloc(64);
 }
 for (i = 0; i < 10000; i++){
  free(mem_list[i]);
 }
    j = gettimeofday (&time_end, (void *)((void *)0));
    fprintf (stderr, "Time taken for mallocs =  %f msec\n\n",
      comp_time (time_start, time_end)/1000.0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int i; // ebx

if ( argc != 2 )
return main_malloc();
result = atoi(argv[1]);
for ( i = result; i > 0; --i )
result = main_malloc();
return result;
}

original_code:
void main(int argc, char* argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_malloc();
}

canonical_original_code:
void main(int argc, char *argv[]) {
 int i = 1;
 if(argc == 2) {
  i = atoi(argv[1]);
 }
 for(;i>0; i--)
  main_malloc();
}


repo: harmanpa/crecon

decompiled_code:
const char *msgpack_version()
{
return "5.6.0";
}

canonical_decompiled_code:
const char *func0()
{
return "5.6.0";
}

original_code:
const char* msgpack_version(void)
{
 return "5.6.0";
}


decompiled_code:
__int64 msgpack_version_major()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 5LL;
}

original_code:
int msgpack_version_major(void)
{
 return 5;
}

canonical_original_code:
int msgpack_version_major()
{
 return 5;
}