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

v2 = spn_hash_value(a2);
return v2 & modulo_mask_isra_0(*(_QWORD *)(a1 + 24));
}

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

v2 = spn_hash_value(a2);
return v2 & func3(*(_QWORD *)(a1 + 24));
}

original_code:
static size_t hash_index(SpnHashMap *hm, const SpnValue *key)
{
 return spn_hash_value(key) & modulo_mask(hm);
}

canonical_original_code:
static unsigned long hash_index(struct SpnHashMap *hm, struct SpnValue *key)
{
 return spn_hash_value(key) & modulo_mask(hm);
}

variable_types:
key
struct SpnValue *


decompiled_code:
__int64 __fastcall insert_into_bucket(__m128i *a1, const __m128i *a2, const __m128i *a3, int a4)
{
__int64 result; // rax

result = bucket_is_empty_isra_0(a1->m128i_i32[0], a1[1].m128i_i32[0]);
if ( !(_DWORD)result )
_assert_fail("bucket_is_empty(bucket)", "src/hashmap.c", 0x30u, "insert_into_bucket");
if ( !a2->m128i_i8[0] )
_assert_fail("notnil(key)", "src/hashmap.c", 0x31u, "insert_into_bucket");
if ( !a3->m128i_i8[0] )
_assert_fail("notnil(value)", "src/hashmap.c", 0x32u, "insert_into_bucket");
if ( a4 )
{
spn_value_retain(a2);
result = spn_value_retain(a3);
}
*a1 = _mm_loadu_si128(a2);
a1[1] = _mm_loadu_si128(a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__m128i *a1, const __m128i *a2, const __m128i *a3, int a4)
{
__int64 result; // rax

result = func5(a1->m128i_i32[0], a1[1].m128i_i32[0]);
if ( !(_DWORD)result )
_assert_fail("bucket_is_empty(bucket)", "src/hashmap.c", 0x30u, "insert_into_bucket");
if ( !a2->m128i_i8[0] )
_assert_fail("notnil(key)", "src/hashmap.c", 0x31u, "insert_into_bucket");
if ( !a3->m128i_i8[0] )
_assert_fail("notnil(value)", "src/hashmap.c", 0x32u, "insert_into_bucket");
if ( a4 )
{
spn_value_retain(a2);
result = spn_value_retain(a3);
}
*a1 = _mm_loadu_si128(a2);
a1[1] = _mm_loadu_si128(a3);
return result;
}

original_code:
static void insert_into_bucket(
 Bucket *bucket,
 const SpnValue *key,
 const SpnValue *value,
 int should_retain
)
{
 ((bucket_is_empty(bucket)) ? (void) (0) : __assert_fail ("bucket_is_empty(bucket)", "src/hashmap.c", 48, __extension__ __PRETTY_FUNCTION__));
 (((((((key)->type) & 0x00ff)) != SPN_TTAG_NIL)) ? (void) (0) : __assert_fail ("notnil(key)", "src/hashmap.c", 49, __extension__ __PRETTY_FUNCTION__));
 (((((((value)->type) & 0x00ff)) != SPN_TTAG_NIL)) ? (void) (0) : __assert_fail ("notnil(value)", "src/hashmap.c", 50, __extension__ __PRETTY_FUNCTION__));
 if (should_retain) {
  spn_value_retain(key);
  spn_value_retain(value);
 }
 bucket->key = *key;
 bucket->value = *value;
}

canonical_original_code:
static void insert_into_bucket(struct Bucket *bucket, struct SpnValue *key, struct SpnValue *value, int should_retain)
{
 ((bucket_is_empty(bucket)) ? (void) (0) : __assert_fail ("bucket_is_empty(bucket)", "src/hashmap.c", 48, __extension__ __PRETTY_FUNCTION__));
 (((((((key)->type) & 0x00ff)) != SPN_TTAG_NIL)) ? (void) (0) : __assert_fail ("notnil(key)", "src/hashmap.c", 49, __extension__ __PRETTY_FUNCTION__));
 (((((((value)->type) & 0x00ff)) != SPN_TTAG_NIL)) ? (void) (0) : __assert_fail ("notnil(value)", "src/hashmap.c", 50, __extension__ __PRETTY_FUNCTION__));
 if (should_retain) {
  spn_value_retain(key);
  spn_value_retain(value);
 }
 bucket->key = *key;
 bucket->value = *value;
}

variable_types: struct Bucket { struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } key; struct SpnValue value; } *

variable_types:
value
struct SpnValue *

return_type: void

user_defined_types: struct Bucket { struct SpnValue key; struct SpnValue value; }


decompiled_code:
__int64 __fastcall find_key(_QWORD *a1, __int64 a2)
{
unsigned __int64 v2; // r13
__int64 v3; // rbx
_DWORD *v4; // r15

if ( !a1[3] )
return 0LL;
v2 = 0LL;
v3 = hash_index((__int64)a1, a2);
while ( 1 )
{
v4 = (_DWORD *)(32 * v3 + a1[2]);
if ( (unsigned int)bucket_is_used_isra_0(*v4, v4[4]) )
{
if ( (unsigned int)spn_value_equal(v4, a2) )
break;
}
++v2;
v3 = modulo_mask_isra_0(a1[3]) & (v3 + 1);
if ( a1[5] < v2 )
return 0LL;
}
return 32 * v3 + a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
unsigned __int64 v2; // r13
__int64 v3; // rbx
_DWORD *v4; // r15

if ( !a1[3] )
return 0LL;
v2 = 0LL;
v3 = func4((__int64)a1, a2);
while ( 1 )
{
v4 = (_DWORD *)(32 * v3 + a1[2]);
if ( (unsigned int)func7(*v4, v4[4]) )
{
if ( (unsigned int)spn_value_equal(v4, a2) )
break;
}
++v2;
v3 = func3(a1[3]) & (v3 + 1);
if ( a1[5] < v2 )
return 0LL;
}
return 32 * v3 + a1[2];
}

original_code:
static Bucket *find_key(SpnHashMap *hm, const SpnValue *key)
{
 size_t h, hash_offset;
 if (hm->allocsize == 0) {
  return ((void *)0);
 }
 h = hash_index(hm, key);
 hash_offset = 0;
 do {
  if (bucket_is_used(&hm->buckets[h])
   && spn_value_equal(&hm->buckets[h].key, key)) {
   return &hm->buckets[h];
  }
  h = (h + 1) & modulo_mask(hm);
  hash_offset++;
 } while (hash_offset <= hm->max_hash_offset);
 return ((void *)0);
}

canonical_original_code:
static struct Bucket *find_key(struct SpnHashMap *hm, struct SpnValue *key)
{
 unsigned long h; unsigned long hash_offset;
 if (hm->allocsize == 0) {
  return ((void *)0);
 }
 h = hash_index(hm, key);
 hash_offset = 0;
 do {
  if (bucket_is_used(&hm->buckets[h])
   && spn_value_equal(&hm->buckets[h].key, key)) {
   return &hm->buckets[h];
  }
  h = (h + 1) & modulo_mask(hm);
  hash_offset++;
 } while (hash_offset <= hm->max_hash_offset);
 return ((void *)0);
}

variable_types: struct SpnHashMap { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct Bucket *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; } *

variable_types:
h
unsigned long

return_type: struct Bucket { struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } key; struct SpnValue value; } *

user_defined_types: struct SpnHashMap { struct SpnObject base; struct Bucket *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; }

user_defined_types: struct SpnObject { struct SpnClass *isa; unsigned int refcnt; }


original_code:
static void expand_and_rehash(SpnHashMap *hm)
{
 Bucket *oldbuckets = hm->buckets;
 size_t oldsize = hm->allocsize;
 size_t i;
 hm->allocsize = oldsize ? oldsize * 2 : 8;
 hm->buckets = alloc_bucket_array(hm->allocsize);
 hm->count = 0;
 hm->max_hash_offset = 0;
 for (i = 0; i < oldsize; i++) {
  if (bucket_is_used(&oldbuckets[i])) {
   insert_nonexistent_norehash(hm, &oldbuckets[i].key, &oldbuckets[i].value, 0);
  }
 }
 free(oldbuckets);
}

canonical_original_code:
static void expand_and_rehash(struct SpnHashMap *hm)
{
 struct Bucket *oldbuckets = hm->buckets;
 unsigned long oldsize = hm->allocsize;
 unsigned long i;
 hm->allocsize = oldsize ? oldsize * 2 : 8;
 hm->buckets = alloc_bucket_array(hm->allocsize);
 hm->count = 0;
 hm->max_hash_offset = 0;
 for (i = 0; i < oldsize; i++) {
  if (bucket_is_used(&oldbuckets[i])) {
   insert_nonexistent_norehash(hm, &oldbuckets[i].key, &oldbuckets[i].value, 0);
  }
 }
 free(oldbuckets);
}

variable_types: struct SpnHashMap { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct Bucket { struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } key; struct SpnValue value; } *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; } *

variable_types:
oldsize
unsigned long

variable_types:
i
unsigned long


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

result = (_QWORD *)spn_object_new(&spn_class_hashmap);
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

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

result = (_QWORD *)spn_object_new(&spn_class_hashmap);
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

original_code:
SpnHashMap *spn_hashmap_new()
{
 SpnHashMap *hm = spn_object_new(&spn_class_hashmap);
 hm->buckets = ((void *)0);
 hm->allocsize = 0;
 hm->count = 0;
 hm->max_hash_offset = 0;
 return hm;
}

canonical_original_code:
struct SpnHashMap *spn_hashmap_new()
{
 struct SpnHashMap *hm = spn_object_new(&spn_class_hashmap);
 hm->buckets = ((void *)0);
 hm->allocsize = 0;
 hm->count = 0;
 hm->max_hash_offset = 0;
 return hm;
}

return_type: struct SpnHashMap { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct Bucket { struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } key; struct SpnValue value; } *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; } *


decompiled_code:
__int64 __fastcall spn_hashmap_count(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return *(_QWORD *)(a1 + 32);
}

original_code:
size_t spn_hashmap_count(SpnHashMap *hm)
{
 return hm->count;
}

canonical_original_code:
unsigned long spn_hashmap_count(struct SpnHashMap *hm)
{
 return hm->count;
}

return_type: unsigned long

user_defined_types: struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); }

user_defined_types: struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; }


decompiled_code:
__int64 spn_makehashmap()
{
_QWORD *v0; // rax

v0 = spn_hashmap_new();
return spn_makeobject(v0);
}

canonical_decompiled_code:
__int64 func13()
{
_QWORD *v0; // rax

v0 = func11();
return spn_makeobject(v0);
}

original_code:
SpnValue spn_makehashmap(void)
{
 return spn_makeobject(spn_hashmap_new());
}

canonical_original_code:
struct SpnValue spn_makehashmap()
{
 return spn_makeobject(spn_hashmap_new());
}

return_type: struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; }


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

v2 = find_key(a1, a2);
if ( v2 )
result = *(_QWORD *)(v2 + 16);
else
result = spn_nilval.m128i_i64[0];
return result;
}

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

v2 = func8(a1, a2);
if ( v2 )
result = *(_QWORD *)(v2 + 16);
else
result = spn_nilval.m128i_i64[0];
return result;
}

original_code:
SpnValue spn_hashmap_get(SpnHashMap *hm, const SpnValue *key)
{
 Bucket *node = find_key(hm, key);
 return node ? node->value : spn_nilval;
}

canonical_original_code:
struct SpnValue spn_hashmap_get(struct SpnHashMap *hm, struct SpnValue *key)
{
 struct Bucket *node = find_key(hm, key);
 return node ? node->value : spn_nilval;
}

variable_types: struct SpnHashMap { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct Bucket { struct SpnValue key; struct SpnValue value; } *buckets; unsigned long allocsize; unsigned long count; unsigned long max_hash_offset; } *


decompiled_code:
__int64 __fastcall spn_hashmap_get_strkey(_QWORD *a1)
{
__int64 v1; // rdx
int v3; // [rsp+0h] [rbp-50h] BYREF
__int64 v4; // [rsp+8h] [rbp-48h]
char v5[64]; // [rsp+10h] [rbp-40h] BYREF

spn_string_emplace_nonretained_for_hashmap(v5);
v3 = spn_makeobject(v5);
v4 = v1;
return spn_hashmap_get(a1, (__int64)&v3);
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1)
{
__int64 v1; // rdx
int v3; // [rsp+0h] [rbp-50h] BYREF
__int64 v4; // [rsp+8h] [rbp-48h]
char v5[64]; // [rsp+10h] [rbp-40h] BYREF

spn_string_emplace_nonretained_for_hashmap(v5);
v3 = spn_makeobject(v5);
v4 = v1;
return func14(a1, (__int64)&v3);
}

original_code:
SpnValue spn_hashmap_get_strkey(SpnHashMap *hm, const char *key)
{
 SpnString key_str = spn_string_emplace_nonretained_for_hashmap(key);
 SpnValue key_val = spn_makeobject(&key_str);
 return spn_hashmap_get(hm, &key_val);
}

canonical_original_code:
struct SpnValue spn_hashmap_get_strkey(struct SpnHashMap *hm, char *key)
{
 struct SpnString key_str = spn_string_emplace_nonretained_for_hashmap(key);
 struct SpnValue key_val = spn_makeobject(&key_str);
 return spn_hashmap_get(hm, &key_val);
}

variable_types:
key
char *

variable_types: struct SpnString { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; char *cstr; unsigned long len; int dealloc; int ishashed; unsigned long hash; }

variable_types: struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; }

user_defined_types: struct SpnString { struct SpnObject base; char *cstr; unsigned long len; int dealloc; int ishashed; unsigned long hash; }


decompiled_code:
__int64 __fastcall spn_hashmap_set_strkey(_QWORD *a1, __int64 a2, const __m128i *a3)
{
__int32 v4; // eax
__int64 v5; // rdx
__m128i v7[3]; // [rsp+0h] [rbp-30h] BYREF

v4 = spn_makestring(a2);
v7[0].m128i_i64[1] = v5;
v7[0].m128i_i32[0] = v4;
spn_hashmap_set(a1, v7, a3);
return spn_value_release(v7);
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD *a1, __int64 a2, const __m128i *a3)
{
__int32 v4; // eax
__int64 v5; // rdx
__m128i v7[3]; // [rsp+0h] [rbp-30h] BYREF

v4 = spn_makestring(a2);
v7[0].m128i_i64[1] = v5;
v7[0].m128i_i32[0] = v4;
spn_hashmap_set(a1, v7, a3);
return spn_value_release(v7);
}

original_code:
void spn_hashmap_set_strkey(SpnHashMap *hm, const char *key, const SpnValue *val)
{
 SpnValue str = spn_makestring(key);
 spn_hashmap_set(hm, &str, val);
 spn_value_release(&str);
}

canonical_original_code:
void spn_hashmap_set_strkey(struct SpnHashMap *hm, char *key, struct SpnValue *val)
{
 struct SpnValue str = spn_makestring(key);
 spn_hashmap_set(hm, &str, val);
 spn_value_release(&str);
}

variable_types:
val
struct SpnValue *


decompiled_code:
unsigned __int64 __fastcall spn_hashmap_next(__int64 a1, unsigned __int64 a2, __m128i *a3, __m128i *a4)
{
unsigned __int64 v4; // r12
unsigned __int64 v5; // r15
const __m128i *i; // rbx
unsigned __int64 result; // rax

v4 = *(_QWORD *)(a1 + 24);
v5 = a2;
if ( v4 <= a2 )
return 0LL;
for ( i = (const __m128i *)(*(_QWORD *)(a1 + 16) + 32 * a2); ; i += 2 )
{
++v5;
if ( (unsigned int)bucket_is_used_isra_0(i->m128i_i32[0], i[1].m128i_i32[0]) )
break;
if ( v4 <= v5 )
return 0LL;
}
result = v5;
*a3 = _mm_loadu_si128(i);
*a4 = _mm_loadu_si128(i + 1);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func17(__int64 a1, unsigned __int64 a2, __m128i *a3, __m128i *a4)
{
unsigned __int64 v4; // r12
unsigned __int64 v5; // r15
const __m128i *i; // rbx
unsigned __int64 result; // rax

v4 = *(_QWORD *)(a1 + 24);
v5 = a2;
if ( v4 <= a2 )
return 0LL;
for ( i = (const __m128i *)(*(_QWORD *)(a1 + 16) + 32 * a2); ; i += 2 )
{
++v5;
if ( (unsigned int)func7(i->m128i_i32[0], i[1].m128i_i32[0]) )
break;
if ( v4 <= v5 )
return 0LL;
}
result = v5;
*a3 = _mm_loadu_si128(i);
*a4 = _mm_loadu_si128(i + 1);
return result;
}

original_code:
size_t spn_hashmap_next(SpnHashMap *hm, size_t cursor, SpnValue *key, SpnValue *val)
{
 size_t size = hm->allocsize;
 size_t i;
 for (i = cursor; i < size; i++) {
  Bucket *bucket = &hm->buckets[i];
  if (bucket_is_used(bucket)) {
   *key = bucket->key;
   *val = bucket->value;
   return i + 1;
  }
 }
 return 0;
}

canonical_original_code:
unsigned long spn_hashmap_next(struct SpnHashMap *hm, unsigned long cursor, struct SpnValue *key, struct SpnValue *val)
{
 unsigned long size = hm->allocsize;
 unsigned long i;
 for (i = cursor; i < size; i++) {
  struct Bucket *bucket = &hm->buckets[i];
  if (bucket_is_used(bucket)) {
   *key = bucket->key;
   *val = bucket->value;
   return i + 1;
  }
 }
 return 0;
}

variable_types:
cursor
unsigned long

variable_types:
size
unsigned long


original_code:
static void free_array(void *obj)
{
 SpnArray *arr = obj;
 size_t i;
 for (i = 0; i < arr->count; i++) {
  spn_value_release(&arr->vector[i]);
 }
 free(arr->vector);
}

canonical_original_code:
static void free_array(void *obj)
{
 struct SpnArray *arr = obj;
 unsigned long i;
 for (i = 0; i < arr->count; i++) {
  spn_value_release(&arr->vector[i]);
 }
 free(arr->vector);
}

variable_types:
obj
void *

variable_types: struct SpnArray { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } *vector; unsigned long count; unsigned long allocsize; } *

user_defined_types: struct SpnArray { struct SpnObject base; struct SpnValue *vector; unsigned long count; unsigned long allocsize; }


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

result = (_QWORD *)spn_object_new(&spn_class_array);
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

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

result = (_QWORD *)spn_object_new(&spn_class_array);
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
return result;
}

original_code:
SpnArray *spn_array_new(void)
{
 SpnArray *array = spn_object_new(&spn_class_array);
 array->vector = ((void *)0);
 array->count = 0;
 array->allocsize = 0;
 return array;
}

canonical_original_code:
struct SpnArray *spn_array_new()
{
 struct SpnArray *array = spn_object_new(&spn_class_array);
 array->vector = ((void *)0);
 array->count = 0;
 array->allocsize = 0;
 return array;
}

return_type: struct SpnArray { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct SpnValue { int type; union { int b; long i; double f; void *p; void *o; } v; } *vector; unsigned long count; unsigned long allocsize; } *


decompiled_code:
__int64 __fastcall spn_array_count(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t spn_array_count(SpnArray *arr)
{
 return arr->count;
}

canonical_original_code:
unsigned long spn_array_count(struct SpnArray *arr)
{
 return arr->count;
}


decompiled_code:
__int64 __fastcall spn_array_get(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx

v2 = *(_QWORD *)(a1 + 24);
if ( v2 > a2 )
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * a2);
spn_die("array index %lu is too high (size = %lu)\n", a2, v2);
return spn_array_set();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx

v2 = *(_QWORD *)(a1 + 24);
if ( v2 > a2 )
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * a2);
spn_die("array index %lu is too high (size = %lu)\n", a2, v2);
return func4();
}

original_code:
SpnValue spn_array_get(SpnArray *arr, size_t index)
{
 if (index >= arr->count) {
  unsigned long ulindex = index, ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 return arr->vector[index];
}

canonical_original_code:
struct SpnValue spn_array_get(struct SpnArray *arr, unsigned long index)
{
 if (index >= arr->count) {
  unsigned long ulindex = index; unsigned long ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 return arr->vector[index];
}

variable_types: struct SpnArray { struct SpnObject { struct SpnClass { unsigned long instsz; unsigned long UID; char *name; int (*equal)(void *, void *); int (*compare)(void *, void *); unsigned long (*hashfn)(void *); char *(*description)(void *, int); void (*destructor)(void *); } *isa; unsigned int refcnt; } base; struct SpnValue *vector; unsigned long count; unsigned long allocsize; } *

variable_types:
index
unsigned long

variable_types:
ulindex
unsigned long

variable_types:
ulcount
unsigned long


decompiled_code:
__int64 __fastcall spn_array_set(__int64 a1, unsigned __int64 a2, const __m128i *a3)
{
unsigned __int64 v4; // rdx
__int64 result; // rax

v4 = *(_QWORD *)(a1 + 24);
if ( v4 <= a2 )
{
spn_die("array index %lu is too high (size = %lu)\n", a2, v4);
result = spn_array_insert();
}
else
{
spn_value_retain(a3);
spn_value_release(16 * a2 + *(_QWORD *)(a1 + 16));
result = *(_QWORD *)(a1 + 16);
*(__m128i *)(result + 16 * a2) = _mm_loadu_si128(a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2, const __m128i *a3)
{
unsigned __int64 v4; // rdx
__int64 result; // rax

v4 = *(_QWORD *)(a1 + 24);
if ( v4 <= a2 )
{
spn_die("array index %lu is too high (size = %lu)\n", a2, v4);
result = func5();
}
else
{
spn_value_retain(a3);
spn_value_release(16 * a2 + *(_QWORD *)(a1 + 16));
result = *(_QWORD *)(a1 + 16);
*(__m128i *)(result + 16 * a2) = _mm_loadu_si128(a3);
}
return result;
}

original_code:
void spn_array_set(SpnArray *arr, size_t index, const SpnValue *val)
{
 if (index >= arr->count) {
  unsigned long ulindex = index, ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 spn_value_retain(val);
 spn_value_release(&arr->vector[index]);
 arr->vector[index] = *val;
}

canonical_original_code:
void spn_array_set(struct SpnArray *arr, unsigned long index, struct SpnValue *val)
{
 if (index >= arr->count) {
  unsigned long ulindex = index; unsigned long ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 spn_value_retain(val);
 spn_value_release(&arr->vector[index]);
 arr->vector[index] = *val;
}


decompiled_code:
__int64 __fastcall spn_array_insert(_QWORD *a1, unsigned __int64 a2, const __m128i *a3)
{
unsigned __int64 v3; // r13
unsigned __int64 v7; // rsi
__int64 result; // rax
__int64 v9; // rax
__int64 v10; // rdi

v3 = a1[3];
if ( v3 < a2 )
{
spn_die("array index %lu is too high (size = %lu)\n", a2, a1[3]);
return spn_array_remove();
}
v7 = a1[4];
a1[3] = v3 + 1;
if ( !v7 )
{
a1[4] = 8LL;
v9 = spn_malloc(128LL);
v7 = a1[4];
a1[2] = v9;
if ( v7 >= a1[3] )
goto LABEL_4;
LABEL_8:
v10 = a1[2];
a1[4] = 2 * v7;
a1[2] = spn_realloc(v10, 32 * v7);
goto LABEL_4;
}
if ( v7 < v3 + 1 )
goto LABEL_8;
LABEL_4:
if ( v3 > a2 )
memmove((void *)(16 * (a2 + 1) + a1[2]), (const void *)(a1[2] + 16 * (a2 + 1) - 16), 16 * (v3 - a2));
result = spn_value_retain(a3);
*(__m128i *)(a1[2] + 16 * a2) = _mm_loadu_si128(a3);
return result;
}

original_code:
void spn_array_insert(SpnArray *arr, size_t index, const SpnValue *val)
{
 size_t i, maxindex;
 if (index > arr->count) {
  unsigned long ulindex = index, ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 maxindex = arr->count++;
 if (arr->allocsize == 0) {
  arr->allocsize = 8;
  arr->vector = spn_malloc(arr->allocsize * sizeof arr->vector[0]);
 }
 if (arr->count > arr->allocsize) {
  arr->allocsize *= 2;
  arr->vector = spn_realloc(arr->vector, arr->allocsize * sizeof arr->vector[0]);
 }
 for (i = maxindex; i > index; i--) {
  arr->vector[i] = arr->vector[i - 1];
 }
 spn_value_retain(val);
 arr->vector[index] = *val;
}

canonical_original_code:
void spn_array_insert(struct SpnArray *arr, unsigned long index, struct SpnValue *val)
{
 unsigned long i; unsigned long maxindex;
 if (index > arr->count) {
  unsigned long ulindex = index; unsigned long ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 maxindex = arr->count++;
 if (arr->allocsize == 0) {
  arr->allocsize = 8;
  arr->vector = spn_malloc(arr->allocsize * sizeof arr->vector[0]);
 }
 if (arr->count > arr->allocsize) {
  arr->allocsize *= 2;
  arr->vector = spn_realloc(arr->vector, arr->allocsize * sizeof arr->vector[0]);
 }
 for (i = maxindex; i > index; i--) {
  arr->vector[i] = arr->vector[i - 1];
 }
 spn_value_retain(val);
 arr->vector[index] = *val;
}

variable_types:
maxindex
unsigned long


decompiled_code:
void *__fastcall spn_array_remove(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdx
void *result; // rax

v2 = *(_QWORD *)(a1 + 24);
if ( v2 <= a2 )
{
spn_die("array index %lu is too high (size = %lu)\n", a2, v2);
result = (void *)spn_array_push();
}
else
{
spn_value_release(16 * a2 + *(_QWORD *)(a1 + 16));
v3 = *(_QWORD *)(a1 + 24);
result = (void *)(v3 - 1);
*(_QWORD *)(a1 + 24) = v3 - 1;
if ( v3 - 1 > a2 )
result = memmove(
(void *)(16 * a2 + *(_QWORD *)(a1 + 16)),
(const void *)(*(_QWORD *)(a1 + 16) + 16 * a2 + 16),
16 * (~a2 + v3));
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdx
void *result; // rax

v2 = *(_QWORD *)(a1 + 24);
if ( v2 <= a2 )
{
spn_die("array index %lu is too high (size = %lu)\n", a2, v2);
result = (void *)func7();
}
else
{
spn_value_release(16 * a2 + *(_QWORD *)(a1 + 16));
v3 = *(_QWORD *)(a1 + 24);
result = (void *)(v3 - 1);
*(_QWORD *)(a1 + 24) = v3 - 1;
if ( v3 - 1 > a2 )
result = memmove(
(void *)(16 * a2 + *(_QWORD *)(a1 + 16)),
(const void *)(*(_QWORD *)(a1 + 16) + 16 * a2 + 16),
16 * (~a2 + v3));
}
return result;
}

original_code:
void spn_array_remove(SpnArray *arr, size_t index)
{
 size_t i;
 if (index >= arr->count) {
  unsigned long ulindex = index, ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 spn_value_release(&arr->vector[index]);
 arr->count--;
 for (i = index; i < arr->count; i++) {
  arr->vector[i] = arr->vector[i + 1];
 }
}

canonical_original_code:
void spn_array_remove(struct SpnArray *arr, unsigned long index)
{
 unsigned long i;
 if (index >= arr->count) {
  unsigned long ulindex = index; unsigned long ulcount = arr->count;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 spn_value_release(&arr->vector[index]);
 arr->count--;
 for (i = index; i < arr->count; i++) {
  arr->vector[i] = arr->vector[i + 1];
 }
}


decompiled_code:
__int64 __fastcall spn_array_push(_QWORD *a1, const __m128i *a2)
{
return spn_array_insert(a1, a1[3], a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, const __m128i *a2)
{
return func5(a1, a1[3], a2);
}

original_code:
void spn_array_push(SpnArray *arr, const SpnValue *val)
{
 spn_array_insert(arr, arr->count, val);
}

canonical_original_code:
void spn_array_push(struct SpnArray *arr, struct SpnValue *val)
{
 spn_array_insert(arr, arr->count, val);
}


decompiled_code:
void *__fastcall spn_array_pop(__int64 a1)
{
__int64 v1; // rsi

v1 = *(_QWORD *)(a1 + 24);
if ( v1 )
return spn_array_remove(a1, v1 - 1);
spn_die("cannot pop an empty array");
return (void *)spn_array_setsize();
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1)
{
__int64 v1; // rsi

v1 = *(_QWORD *)(a1 + 24);
if ( v1 )
return func6(a1, v1 - 1);
spn_die("cannot pop an empty array");
return (void *)func9();
}

original_code:
void spn_array_pop(SpnArray *arr)
{
 if (arr->count == 0) {
  spn_die("cannot pop an empty array");
 }
 spn_array_remove(arr, arr->count - 1);
}

canonical_original_code:
void spn_array_pop(struct SpnArray *arr)
{
 if (arr->count == 0) {
  spn_die("cannot pop an empty array");
 }
 spn_array_remove(arr, arr->count - 1);
}


decompiled_code:
__int64 __fastcall spn_array_setsize(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r14
unsigned __int64 v3; // rbx
__int64 v4; // r12
__int64 result; // rax

v2 = a1[3];
v3 = a2;
if ( v2 < a2 )
{
v4 = a1[3];
do
{
++v4;
result = spn_array_push(a1, &spn_nilval);
}
while ( a2 != v4 );
}
if ( v2 > a2 )
{
do
{
++v3;
result = (__int64)spn_array_pop((__int64)a1);
}
while ( v2 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r14
unsigned __int64 v3; // rbx
__int64 v4; // r12
__int64 result; // rax

v2 = a1[3];
v3 = a2;
if ( v2 < a2 )
{
v4 = a1[3];
do
{
++v4;
result = func7(a1, &spn_nilval);
}
while ( a2 != v4 );
}
if ( v2 > a2 )
{
do
{
++v3;
result = (__int64)func8((__int64)a1);
}
while ( v2 != v3 );
}
return result;
}

original_code:
void spn_array_setsize(SpnArray *arr, size_t newsize)
{
 size_t oldsize = arr->count, i;
 for (i = oldsize; i < newsize; i++) {
  spn_array_push(arr, &spn_nilval);
 }
 for (i = newsize; i < oldsize; i++) {
  spn_array_pop(arr);
 }
}

canonical_original_code:
void spn_array_setsize(struct SpnArray *arr, unsigned long newsize)
{
 unsigned long oldsize = arr->count; unsigned long i;
 for (i = oldsize; i < newsize; i++) {
  spn_array_push(arr, &spn_nilval);
 }
 for (i = newsize; i < oldsize; i++) {
  spn_array_pop(arr);
 }
}

variable_types:
newsize
unsigned long


original_code:
void spn_array_inject(SpnArray *arr, size_t index, SpnArray *other)
{
 size_t i, j;
 size_t n_arr = arr->count, n_other = other->count;
 if (index > n_arr) {
  unsigned long ulindex = index, ulcount = n_arr;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 spn_array_setsize(arr, n_arr + n_other);
 for (i = n_arr; i > index; i--) {
  arr->vector[i - 1 + n_other] = arr->vector[i - 1];
 }
 for (i = index, j = 0; j < n_other; i++, j++) {
  spn_value_retain(&other->vector[j]);
  arr->vector[i] = other->vector[j];
 }
}

canonical_original_code:
void spn_array_inject(struct SpnArray *arr, unsigned long index, struct SpnArray *other)
{
 unsigned long i; unsigned long j;
 unsigned long n_arr = arr->count; unsigned long n_other = other->count;
 if (index > n_arr) {
  unsigned long ulindex = index; unsigned long ulcount = n_arr;
  spn_die("array index %lu is too high (size = %lu)\n", ulindex, ulcount);
 }
 spn_array_setsize(arr, n_arr + n_other);
 for (i = n_arr; i > index; i--) {
  arr->vector[i - 1 + n_other] = arr->vector[i - 1];
 }
 for (i = index, j = 0; j < n_other; i++, j++) {
  spn_value_retain(&other->vector[j]);
  arr->vector[i] = other->vector[j];
 }
}

variable_types:
other
struct SpnArray *

variable_types:
j
unsigned long


decompiled_code:
__int64 spn_makearray()
{
_QWORD *v0; // rax

v0 = spn_array_new();
return spn_makeobject(v0);
}

canonical_decompiled_code:
__int64 func11()
{
_QWORD *v0; // rax

v0 = func1();
return spn_makeobject(v0);
}

original_code:
SpnValue spn_makearray(void)
{
 return spn_makeobject(spn_array_new());
}

canonical_original_code:
struct SpnValue spn_makearray()
{
 return spn_makeobject(spn_array_new());
}


decompiled_code:
_BOOL8 __fastcall type_equal(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int type_equal(const char *p, const char *q)
{
 return strcmp(p, q) == 0;
}

canonical_original_code:
int type_equal(char *p, char *q)
{
 return strcmp(p, q) == 0;
}

variable_types:
p
char *

variable_types:
q
char *

return_type: int


decompiled_code:
__int64 __fastcall ast_type_needs_children(char *s1)
{
char **v1; // rbx
const char *i; // rsi

v1 = off_808;
for ( i = "block"; strcmp(s1, i); i = *v1++ )
{
if ( v1 == &off_808[6] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *s1)
{
char **v1; // rbx
const char *i; // rsi

v1 = off_808;
for ( i = "block"; strcmp(s1, i); i = *v1++ )
{
if ( v1 == &off_808[6] )
return 0LL;
}
return 1LL;
}

original_code:
int ast_type_needs_children(const char *type)
{
 static const char *const partypes[] = {
  "block",
  "program",
  "call",
  "vardecl",
  "constdecl",
  "array",
  "hashmap"
 };
 size_t i;
 for (i = 0; i < (sizeof(partypes) / sizeof(partypes[0])); i++) {
  if (strcmp(type, partypes[i]) == 0) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int ast_type_needs_children(char *type)
{
 static char *partypes[] = {
  "block",
  "program",
  "call",
  "vardecl",
  "constdecl",
  "array",
  "hashmap"
 };
 unsigned long i;
 for (i = 0; i < (sizeof(partypes) / sizeof(partypes[0])); i++) {
  if (strcmp(type, partypes[i]) == 0) {
   return 1;
  }
 }
 return 0;
}

variable_types:
type
char *

variable_types:
partypes
char *[]

variable_types:
i
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
char *v4; // r14
int v5; // er12
int v6; // eax

if ( getuid() && getgid() )
{
fwrite("You must run rUserAdd as root, Exiting...\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
if ( argc <= 1 )
goto LABEL_20;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "c:a:vp:d:");
if ( v6 == -1 )
break;
if ( v6 == 100 )
{
del_user(_bss_start);
return 0;
}
if ( v6 > 100 )
{
if ( v6 != 112 )
goto LABEL_20;
v3 = _bss_start;
v5 = 1;
}
else
{
if ( v6 != 97 )
{
if ( v6 == 99 )
{
pwd_check(_bss_start);
return 0;
}
LABEL_20:
usage(*argv);
}
v4 = _bss_start;
}
}
if ( !v5 )
v3 = "ash123";
pwd_insert(v4, v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
char *v4; // r14
int v5; // er12
int v6; // eax

if ( getuid() && getgid() )
{
fwrite("You must run rUserAdd as root, Exiting...\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
if ( argc <= 1 )
goto LABEL_20;
v5 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "c:a:vp:d:");
if ( v6 == -1 )
break;
if ( v6 == 100 )
{
func8(_bss_start);
return 0;
}
if ( v6 > 100 )
{
if ( v6 != 112 )
goto LABEL_20;
v3 = _bss_start;
v5 = 1;
}
else
{
if ( v6 != 97 )
{
if ( v6 == 99 )
{
func7(_bss_start);
return 0;
}
LABEL_20:
func9(*argv);
}
v4 = _bss_start;
}
}
if ( !v5 )
v3 = "ash123";
func10(v4, v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char *user_name;
 char *password;
 int opt,pflag=0;
 if (getuid() != 0 && getgid() != 0)
 {
  fprintf(stderr,"You must run rUserAdd as root, Exiting...\n");
  exit(1);
 }
 if (argc < 2)
 {
  usage(argv[0]);
  exit(1);
 }
 while ((opt = getopt(argc,argv,"c:a:vp:d:")) != -1 )
 {
  switch(opt)
  {
   case 'c':
    user_name = optarg;
    pwd_check(user_name);
    return 0;
   case 'd':
    user_name = optarg;
    del_user(user_name);
    return 0;
   case 'a':
    user_name = optarg;
    break;
   case 'p':
    password = optarg;
    pflag = 1;
    break;
   case 'v':
   default:
    usage(argv[0]);
    break;
  }
 }
 if (!pflag)
  password = "ash123";
 pwd_insert(user_name, password);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *user_name;
 char *password;
 int opt; int pflag = 0;
 if (getuid() != 0 && getgid() != 0)
 {
  fprintf(stderr,"You must run rUserAdd as root, Exiting...\n");
  exit(1);
 }
 if (argc < 2)
 {
  usage(argv[0]);
  exit(1);
 }
 while ((opt = getopt(argc,argv,"c:a:vp:d:")) != -1 )
 {
  switch(opt)
  {
   case 'c':
    user_name = optarg;
    pwd_check(user_name);
    return 0;
   case 'd':
    user_name = optarg;
    del_user(user_name);
    return 0;
   case 'a':
    user_name = optarg;
    break;
   case 'p':
    password = optarg;
    pflag = 1;
    break;
   case 'v':
   default:
    usage(argv[0]);
    break;
  }
 }
 if (!pflag)
  password = "ash123";
 pwd_insert(user_name, password);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
password
char *

variable_types: opt int

variable_types: pflag int


decompiled_code:
__int64 __fastcall pwd_check(const char *a1)
{
__int64 result; // rax

if ( getpwnam(a1) )
{
fprintf(stderr, "%s: User exists.\n", a1);
result = 0LL;
}
else
{
fprintf(stderr, "%s: User does not exist.\n", a1);
result = 1LL;
}
return result;
}

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

if ( getpwnam(a1) )
{
fprintf(stderr, "%s: User exists.\n", a1);
result = 0LL;
}
else
{
fprintf(stderr, "%s: User does not exist.\n", a1);
result = 1LL;
}
return result;
}

original_code:
static int pwd_check(const char *name)
{
 struct passwd *passwd = ((void *)0);
 passwd = getpwnam(name);
 if (passwd == ((void *)0))
 {
  fprintf(stderr, "%s: User does not exist.\n",name);
  return 1;
 }
 fprintf(stderr, "%s: User exists.\n",name);
 return 0;
}

canonical_original_code:
static int pwd_check(char *name)
{
 struct passwd *passwd = ((void *)0);
 passwd = getpwnam(name);
 if (passwd == ((void *)0))
 {
  fprintf(stderr, "%s: User does not exist.\n",name);
  return 1;
 }
 fprintf(stderr, "%s: User exists.\n",name);
 return 0;
}

variable_types:
name
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
system("clear");
fwrite("#########################################################################\n", 1uLL, 0x4AuLL, stderr);
fwrite("# #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# Ashiyane Digital Security Team #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# Ashiyane ROOT User add #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# rUserAdd v0.2 #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# Thanks to Pr0grammer for his idea #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# By HAMIDx9 #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# #\n", 1uLL, 0x4AuLL, stderr);
fwrite("#########################################################################\n\n", 1uLL, 0x4BuLL, stderr);
fprintf(stderr, " Usage[0]: %s -c user_name\t\t// check existance of a username\n", a1);
fprintf(stderr, " Usage[1]: %s -a user_name -p password\t// add a user with an exact password\n", a1);
fprintf(stderr, " Usage[2]: %s -a user_name\t\t// add a user with default pass : ash123\n", a1);
fprintf(stderr, " Usage[3]: %s -d user_name\t\t\t// delete a user\n\n", a1);
fflush(stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
system("clear");
fwrite("#########################################################################\n", 1uLL, 0x4AuLL, stderr);
fwrite("# #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# Ashiyane Digital Security Team #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# Ashiyane ROOT User add #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# rUserAdd v0.2 #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# Thanks to Pr0grammer for his idea #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# By HAMIDx9 #\n", 1uLL, 0x4AuLL, stderr);
fwrite("# #\n", 1uLL, 0x4AuLL, stderr);
fwrite("#########################################################################\n\n", 1uLL, 0x4BuLL, stderr);
fprintf(stderr, " Usage[0]: %s -c user_name\t\t// check existance of a username\n", a1);
fprintf(stderr, " Usage[1]: %s -a user_name -p password\t// add a user with an exact password\n", a1);
fprintf(stderr, " Usage[2]: %s -a user_name\t\t// add a user with default pass : ash123\n", a1);
fprintf(stderr, " Usage[3]: %s -d user_name\t\t\t// delete a user\n\n", a1);
fflush(stderr);
exit(1);
}

original_code:
static void usage(const char *program)
{
 system("clear");
 fprintf(stderr, "#########################################################################\n");
 fprintf(stderr, "#                                                                       #\n");
 fprintf(stderr, "#                  Ashiyane Digital Security Team                       #\n");
 fprintf(stderr, "#                        Ashiyane ROOT User add                         #\n");
 fprintf(stderr, "#                            rUserAdd v0.2                              #\n");
 fprintf(stderr, "#                 Thanks to Pr0grammer for his idea                     #\n");
 fprintf(stderr, "#                             By  HAMIDx9                               #\n");
 fprintf(stderr, "#                                                                       #\n");
 fprintf(stderr, "#########################################################################\n\n");
 fprintf(stderr, " Usage[0]: %s -c user_name\t\t// check existance of a username\n",program);
 fprintf(stderr, " Usage[1]: %s -a user_name -p password\t// add a user with an exact password\n",program);
 fprintf(stderr, " Usage[2]: %s -a user_name\t\t// add a user with default pass : ash123\n",program);
 fprintf(stderr, " Usage[3]: %s -d user_name\t	\t// delete a user\n\n",program);
 fflush(stderr);
 exit(1);
}

canonical_original_code:
static void usage(char *program)
{
 system("clear");
 fprintf(stderr, "#########################################################################\n");
 fprintf(stderr, "#                                                                       #\n");
 fprintf(stderr, "#                  Ashiyane Digital Security Team                       #\n");
 fprintf(stderr, "#                        Ashiyane ROOT User add                         #\n");
 fprintf(stderr, "#                            rUserAdd v0.2                              #\n");
 fprintf(stderr, "#                 Thanks to Pr0grammer for his idea                     #\n");
 fprintf(stderr, "#                             By  HAMIDx9                               #\n");
 fprintf(stderr, "#                                                                       #\n");
 fprintf(stderr, "#########################################################################\n\n");
 fprintf(stderr, " Usage[0]: %s -c user_name\t\t// check existance of a username\n",program);
 fprintf(stderr, " Usage[1]: %s -a user_name -p password\t// add a user with an exact password\n",program);
 fprintf(stderr, " Usage[2]: %s -a user_name\t\t// add a user with default pass : ash123\n",program);
 fprintf(stderr, " Usage[3]: %s -d user_name\t	\t// delete a user\n\n",program);
 fflush(stderr);
 exit(1);
}

variable_types:
program
char *


main

repo: HKervadec/Matrique

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
int v5; // ebp
__int16 v6; // si
int v7; // er12
__int64 v8; // rdx
__int64 v9; // r14
unsigned int v10; // er15
unsigned int v11; // ebp
__int64 v12; // rbx
WINDOW *v13; // rdi
struct timespec v14; // [rsp+0h] [rbp-48h] BYREF

v3 = time(0LL);
srand(v3);
initscr();
if ( !has_colors() )
{
endwin();
puts("Your terminal does not support color");
exit(1);
}
v4 = 400;
v5 = 0;
curs_set(0);
use_default_colors();
start_color();
do
{
init_color(v5, 0, v4, 0);
v6 = v5++;
v4 += 37;
init_pair(v5, v6, -1);
}
while ( v5 != 16 );
v14.tv_sec = 0LL;
v14.tv_nsec = 64000000LL;
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v7 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v8 = (unsigned int)(stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1);
}
else
{
v7 = -1;
v8 = 0xFFFFFFFFLL;
}
v9 = initFLArray((unsigned int)v7, (unsigned int)v7, v8);
while ( 1 )
{
v13 = stdscr__NCURSES6_TINFO_5_0_19991023;
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v10 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v11 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1;
}
else
{
v10 = -1;
v11 = -1;
}
if ( v7 > 0 )
{
v12 = v9;
do
{
updateFL(v12, v10, v11);
printFL(v12, v10, v11);
v12 += 24LL;
}
while ( v9 + 24LL * (unsigned int)(v7 - 1) + 24 != v12 );
v13 = stdscr__NCURSES6_TINFO_5_0_19991023;
}
wrefresh(v13);
nanosleep(&v14, 0LL);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
int v5; // ebp
__int16 v6; // si
int v7; // er12
__int64 v8; // rdx
__int64 v9; // r14
unsigned int v10; // er15
unsigned int v11; // ebp
__int64 v12; // rbx
WINDOW *v13; // rdi
struct timespec v14; // [rsp+0h] [rbp-48h] BYREF

v3 = time(0LL);
srand(v3);
initscr();
if ( !has_colors() )
{
endwin();
puts("Your terminal does not support color");
exit(1);
}
v4 = 400;
v5 = 0;
curs_set(0);
use_default_colors();
start_color();
do
{
init_color(v5, 0, v4, 0);
v6 = v5++;
v4 += 37;
init_pair(v5, v6, -1);
}
while ( v5 != 16 );
v14.tv_sec = 0LL;
v14.tv_nsec = 64000000LL;
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v7 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v8 = (unsigned int)(stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1);
}
else
{
v7 = -1;
v8 = 0xFFFFFFFFLL;
}
v9 = func14((unsigned int)v7, (unsigned int)v7, v8);
while ( 1 )
{
v13 = stdscr__NCURSES6_TINFO_5_0_19991023;
if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v10 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v11 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1;
}
else
{
v10 = -1;
v11 = -1;
}
if ( v7 > 0 )
{
v12 = v9;
do
{
func15(v12, v10, v11);
func10(v12, v10, v11);
v12 += 24LL;
}
while ( v9 + 24LL * (unsigned int)(v7 - 1) + 24 != v12 );
v13 = stdscr__NCURSES6_TINFO_5_0_19991023;
}
wrefresh(v13);
nanosleep(&v14, 0LL);
}
}

original_code:
int main(int argc, char *argv[]){
 srand(time(((void *)0)));
 initscr();
 if(has_colors() == 0)
 { endwin();
  printf("Your terminal does not support color\n");
  exit(1);
 }
 curs_set(0);
 use_default_colors();
 start_color();
 for(int i = 0 ; i < 16 ; i++){
  const int green_step = ((1000 - 400) / 16) ;
  init_color(i, 0, 400 + i * green_step, 0);
  init_pair(i+1, i, -1);
 }
 const struct timespec sleep_time = {0, 4*16*1000*1000};
 int row, col;
 (row = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), col = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 int arrow_number = row;
 FL *fL = initFLArray(arrow_number, row, col);
 while(1){
  (row = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), col = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  for(int j = 0 ; j < arrow_number ; j++){
   updateFL(&(fL[j]), row, col);
   printFL(&fL[j], row, col);
  }
  wrefresh(stdscr);
  nanosleep(&sleep_time, ((void *)0));
 }
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 srand(time(((void *)0)));
 initscr();
 if(has_colors() == 0)
 { endwin();
  printf("Your terminal does not support color\n");
  exit(1);
 }
 curs_set(0);
 use_default_colors();
 start_color();
 for(int i = 0; i < 16 ; i++){
  int green_step = ((1000 - 400) / 16);
  init_color(i, 0, 400 + i * green_step, 0);
  init_pair(i+1, i, -1);
 }
 struct timespec sleep_time = {0, 4*16*1000*1000};
 int row; int col;
 (row = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), col = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 int arrow_number = row;
 struct FL *fL = initFLArray(arrow_number, row, col);
 while(1){
  (row = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), col = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  for(int j = 0; j < arrow_number ; j++){
   updateFL(&(fL[j]), row, col);
   printFL(&fL[j], row, col);
  }
  wrefresh(stdscr);
  nanosleep(&sleep_time, ((void *)0));
 }
 endwin();
 return 0;
}

variable_types:
argv
char *[]

variable_types: i int

variable_types: struct timespec { long tv_sec; long tv_nsec; }

variable_types: row int

variable_types: col int

variable_types: struct FL { int x; int y; int status; int size; char *arrow; } *

variable_types: j int


emptyScreen

decompiled_code:
int emptyScreen()
{
return wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
}

canonical_decompiled_code:
int func7()
{
return wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
}

original_code:
void emptyScreen(){
 wclear(stdscr);
}

canonical_original_code:
void emptyScreen(){
 wclear(stdscr);
}


emptyLastLine

decompiled_code:
void emptyLastLine()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
void emptyLastLine(int row, int col){
}

canonical_original_code:
void emptyLastLine(int row, int col){
}


emptyLine

decompiled_code:
int __fastcall emptyLine(int a1, int a2)
{
int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = mvprintw(a1, i, " ");
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2)
{
int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = mvprintw(a1, i, " ");
}
return result;
}

original_code:
void emptyLine(int line, int col){
 for(int i = 0 ; i < col ; i++){
  mvprintw(line, i, " ");
 }
}

canonical_original_code:
void emptyLine(int line, int col){
 for(int i = 0; i < col ; i++){
  mvprintw(line, i, " ");
 }
}

variable_types: line int


printFL

variable_types: lim int

user_defined_types: struct FL { int x; int y; int status; int size; char *arrow; }


randomChar

decompiled_code:
__int64 randomChar()
{
return (unsigned int)(rand() % 95 + 32);
}

canonical_decompiled_code:
__int64 func11()
{
return (unsigned int)(rand() % 95 + 32);
}

original_code:
char randomChar(){
 return rand() % (127 - 32) + 32;
}

return_type: char


resetFL

original_code:
void resetFL(FL *fL, int row, int col){
 fL->x = rand() % (row + fL->size) - row ;
 fL->y = rand() % col;
 fL->status = rand() % fL->size;
 for(int i = 0 ; i < fL->status ; i++){
  fL->arrow[i] = randomChar();
 }
}

canonical_original_code:
void resetFL(struct FL *fL, int row, int col){
 fL->x = rand() % (row + fL->size) - row ;
 fL->y = rand() % col;
 fL->status = rand() % fL->size;
 for(int i = 0; i < fL->status ; i++){
  fL->arrow[i] = randomChar();
 }
}


initFL

decompiled_code:
__int64 __fastcall initFL(__int64 a1, int a2, int a3, int a4)
{
*(_DWORD *)(a1 + 12) = a4;
*(_QWORD *)(a1 + 16) = malloc(a4);
return resetFL(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2, int a3, int a4)
{
*(_DWORD *)(a1 + 12) = a4;
*(_QWORD *)(a1 + 16) = malloc(a4);
return func12(a1, a2, a3);
}

original_code:
void initFL(FL *fL, int row, int col, int length){
 fL->size = length;
 fL->arrow = malloc(fL->size * sizeof(char));
 resetFL(fL, row, col);
}

canonical_original_code:
void initFL(struct FL *fL, int row, int col, int length){
 fL->size = length;
 fL->arrow = malloc(fL->size * sizeof(char));
 resetFL(fL, row, col);
}

variable_types: length int


initFLArray

decompiled_code:
char *__fastcall initFLArray(int a1, int a2, int a3)
{
char *v4; // rax
char *v5; // r14
__int64 v6; // rbx
char *v7; // r13

v4 = (char *)malloc(24LL * a1);
v5 = v4;
if ( a1 > 0 )
{
v6 = (__int64)v4;
v7 = &v4[24 * a1];
do
{
initFL(v6, a2, a3, 16);
v6 += 24LL;
}
while ( (char *)v6 != v7 );
}
return v5;
}

original_code:
FL *initFLArray(int size, int row, int col){
 FL *fL = malloc(size * sizeof(FL));
 for(int i = 0 ; i < size ; i++){
  initFL(&fL[i], row, col, 16);
 }
 return fL;
}

canonical_original_code:
struct FL *initFLArray(int size, int row, int col){
 struct FL *fL = malloc(size * sizeof(FL));
 for(int i = 0; i < size ; i++){
  initFL(&fL[i], row, col, 16);
 }
 return fL;
}

variable_types: size int

return_type: struct FL { int x; int y; int status; int size; char *arrow; } *


updateFL

original_code:
void updateFL(FL *fL, int row, int col){
 fL->x += 1;
 if(fL->x > row){
  resetFL(fL, row, col);
 }
 fL->status = (fL->status >= fL->size) ? fL->size : fL->status+1;
 for(int i = fL->status-1 ; i >= 1 ; i--){
  fL->arrow[i] = fL->arrow[i-1];
 }
 fL->arrow[0] = randomChar();
}

canonical_original_code:
void updateFL(struct FL *fL, int row, int col){
 fL->x += 1;
 if(fL->x > row){
  resetFL(fL, row, col);
 }
 fL->status = (fL->status >= fL->size) ? fL->size : fL->status+1;
 for(int i = fL->status-1; i >= 1 ; i--){
  fL->arrow[i] = fL->arrow[i-1];
 }
 fL->arrow[0] = randomChar();
}


doColWise

repo: HPC-Sect/ZeroSample

decompiled_code:
void __fastcall __noreturn doColWise(void *a1)
{
int v1; // ecx
int v2; // er10
double *v3; // rdx
_QWORD *v4; // r8
__int64 v5; // rsi
__int64 v6; // rdi
unsigned __int64 v7; // r9
__int64 v8; // rax

v1 = dist_col * ((_DWORD)a1 - 1);
if ( v1 < v1 + dist_col )
{
v2 = row;
v3 = (double *)Res;
v4 = InMat;
v5 = 8LL * v1;
v6 = row;
v7 = 8 * (v1 + (unsigned __int64)(unsigned int)(dist_col - 1) + 1);
do
{
v8 = 0LL;
if ( v2 > 0 )
{
do
{
v3[v8] = v3[v8] + *(double *)(v4[v8] + v5);
++v8;
}
while ( v6 != v8 );
}
v5 += 8LL;
}
while ( v5 != v7 );
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ecx
int v2; // er10
double *v3; // rdx
_QWORD *v4; // r8
__int64 v5; // rsi
__int64 v6; // rdi
unsigned __int64 v7; // r9
__int64 v8; // rax

v1 = dist_col * ((_DWORD)a1 - 1);
if ( v1 < v1 + dist_col )
{
v2 = row;
v3 = (double *)Res;
v4 = InMat;
v5 = 8LL * v1;
v6 = row;
v7 = 8 * (v1 + (unsigned __int64)(unsigned int)(dist_col - 1) + 1);
do
{
v8 = 0LL;
if ( v2 > 0 )
{
do
{
v3[v8] = v3[v8] + *(double *)(v4[v8] + v5);
++v8;
}
while ( v6 != v8 );
}
v5 += 8LL;
}
while ( v5 != v7 );
}
pthread_exit(0LL);
}

original_code:
void *doColWise(int myId)
{
    int iRow;
    int CurCol = 0;
    for (CurCol = ((myId - 1) * dist_col); CurCol <= ((myId * dist_col) - 1); CurCol++)
      for(iRow = 0 ;iRow < row; iRow++)
        Res[iRow] += InMat[iRow][CurCol];
    pthread_exit(((void *)0));
}

variable_types: myId int

variable_types: iRow int

variable_types: CurCol int

return_type: void *


decompiled_code:
int __fastcall find_entries(void *a1)
{
__int64 v1; // rsi
int v2; // ebx
int v3; // ebp
__int64 v4; // rax
int v5; // ebx

v1 = *(unsigned int *)a1;
v2 = iterations * v1;
v3 = iterations * v1 + iterations;
printf("Thread %d doing iterations %d to %d\n", v1, (unsigned int)(iterations * v1), (unsigned int)(v3 - 1));
if ( v2 >= v3 )
{
v5 = 0;
}
else
{
v4 = v2;
v5 = 0;
do
{
if ( *(double *)&search_no == a[v4] )
++v5;
++v4;
}
while ( v3 > (int)v4 );
}
pthread_mutex_lock(&count_mutex);
count += v5;
return pthread_mutex_unlock(&count_mutex);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
__int64 v1; // rsi
int v2; // ebx
int v3; // ebp
__int64 v4; // rax
int v5; // ebx

v1 = *(unsigned int *)a1;
v2 = iterations * v1;
v3 = iterations * v1 + iterations;
printf("Thread %d doing iterations %d to %d\n", v1, (unsigned int)(iterations * v1), (unsigned int)(v3 - 1));
if ( v2 >= v3 )
{
v5 = 0;
}
else
{
v4 = v2;
v5 = 0;
do
{
if ( *(double *)&search_no == a[v4] )
++v5;
++v4;
}
while ( v3 > (int)v4 );
}
pthread_mutex_lock(&count_mutex);
count += v5;
return pthread_mutex_unlock(&count_mutex);
}

original_code:
void *find_entries(void *tid)
{
        int i, start, *mytid, end;
        int local_count =0;
        mytid = (int *) tid;
        start = (*mytid * iterations);
        end = start + iterations;
        printf ("Thread %d doing iterations %d to %d\n",*mytid,start,end-1);
        for (i=start; i < end ; i++) {
                if ( a[i] == search_no ) {
                        local_count ++;
                }
        }
        pthread_mutex_lock (&count_mutex);
        count = count + local_count;
        pthread_mutex_unlock (&count_mutex);
}

canonical_original_code:
void *find_entries(void *tid)
{
        int i; int start; int *mytid; int end;
        int local_count = 0;
        mytid = (int *) tid;
        start = (*mytid * iterations);
        end = start + iterations;
        printf ("Thread %d doing iterations %d to %d\n",*mytid,start,end-1);
        for (i=start; i < end ; i++) {
                if ( a[i] == search_no ) {
                        local_count ++;
                }
        }
        pthread_mutex_lock (&count_mutex);
        count = count + local_count;
        pthread_mutex_unlock (&count_mutex);
}

variable_types:
tid
void *

variable_types: start int

variable_types:
mytid
int *

variable_types: end int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v4; // rdx
const char *v5; // rdi
int v6; // eax
const char *v7; // rdi
int v8; // eax
__int64 v9; // rbx
pthread_t *v10; // r12
_DWORD *v11; // rbx
unsigned int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
int v15; // ebp
pthread_t *v16; // r13
unsigned int v17; // eax
__int64 v18; // rbx
unsigned int v19; // eax
unsigned int v20; // eax
unsigned int v21; // eax
double v23; // [rsp+0h] [rbp-98h]
double v24; // [rsp+8h] [rbp-90h]
struct timezone tz; // [rsp+18h] [rbp-80h] BYREF
struct timeval tv; // [rsp+20h] [rbp-78h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-68h] BYREF

printf(format, argv, envp);
printf(off_402080);
printf(off_4023C8);
printf(format);
printf(off_4020D0);
puts(s);
v4 = 0LL;
do
{
a[(_QWORD)v4] = (double)((unsigned int)v4 % 0xA) + 1.0;
v4 = (char *)v4 + 1;
}
while ( v4 != &unk_5F5E100 );
v5 = "Syntax : exec <Number to be search> <Number of thread>";
if ( argc != 3 )
return puts(v5);
v6 = atoi(argv[1]);
v7 = argv[2];
*(double *)&search_no = (double)v6;
v8 = atoi(v7);
num_threads = v8;
if ( v8 > 8 )
{
v5 = "Number of thread should be less than or equal to 8";
return puts(v5);
}
v9 = v8;
iterations = (__int64)&unk_5F5E100 / v8;
v10 = (pthread_t *)malloc(8LL * v8);
v11 = malloc(4 * v9);
gettimeofday(&tv, &tz);
v23 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
v12 = pthread_mutex_init(&count_mutex, 0LL);
if ( v12 )
{
printf("\n ERROR : Return code from pthread_mutex_init() is %d ", v12);
exit(-1);
}
v13 = pthread_attr_init(&attr);
if ( v13 )
{
printf("\n ERROR : Return code from pthread_attr_init() is %d ", v13);
exit(-1);
}
v14 = pthread_attr_setdetachstate(&attr, 0);
v15 = v14;
if ( v14 )
{
printf("\n ERROR : Return code from pthread_attr_setdetachstate() is %d ", v14);
exit(-1);
}
v16 = v10;
if ( num_threads > 0 )
{
do
{
*v11 = v15;
v17 = pthread_create(v16, &attr, find_entries, v11);
if ( v17 )
{
printf("\n ERROR : Return code from pthread_create() is %d ", v17);
exit(-1);
}
++v15;
++v11;
++v16;
}
while ( num_threads > v15 );
if ( num_threads > 0 )
{
v18 = 0LL;
do
{
v19 = pthread_join(v10[v18], 0LL);
if ( v19 )
{
printf("\n ERROR : Return code from pthread_join() is %d ", v19);
exit(-1);
}
++v18;
}
while ( num_threads > (int)v18 );
}
}
gettimeofday(&tv, &tz);
v24 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
printf("Number of search element found in list Count= %d\n", (unsigned int)count);
printf("Time in Seconds (T) : %lf\n", v24 - v23);
v20 = pthread_attr_destroy(&attr);
if ( v20 )
{
printf("\n ERROR : Return code from pthread_attr_destroy() is %d ", v20);
exit(-1);
}
v21 = pthread_mutex_destroy(&count_mutex);
if ( v21 )
{
printf("\n ERROR : Return code from pthread_mutex_destroy() is %d ", v21);
exit(-1);
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
        int i,start,ret_count;
 int *tids;
        pthread_t * threads;
 pthread_attr_t attr;
        double time_start, time_end;
        struct timeval tv;
        struct timezone tz;
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC):  February-2008");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Finding k matches in the given Array");
        printf("\n\t\t..........................................................................\n");
        for (i=0;i<100000000;i++){
                a[i] = (i %10)+1.0;
        }
 if (argc != 3) {
  printf ("Syntax : exec <Number to be search> <Number of thread>\n");
  return ;
 }
        search_no = atoi(argv[1]);
        num_threads = atoi(argv[2]);
 if (num_threads > 8) {
  printf ("Number of thread should be less than or equal to 8\n");
  return ;
 }
 iterations = 100000000/num_threads;
 threads = (pthread_t *) malloc(sizeof(pthread_t) * num_threads);
 tids = (int *) malloc(sizeof(int) * num_threads);
 gettimeofday(&tv, &tz);
        time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
 ret_count = pthread_mutex_init(&count_mutex, ((void *)0));
 if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count=pthread_attr_init(&attr);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
       if(ret_count)
       {
  printf("\n ERROR : Return code from pthread_attr_setdetachstate() is %d ",ret_count);
  exit(-1);
       }
        for (i=0; i<num_threads; i++) {
                tids[i] = i;
                ret_count = pthread_create(&threads[i], &attr,find_entries, (void *) &tids[i]);
                if(ret_count)
      {
   printf("\n ERROR : Return code from pthread_create() is %d ",ret_count);
   exit(-1);
      }
         }
        for (i=0; i<num_threads; i++) {
                ret_count = pthread_join(threads[i], ((void *)0));
      if(ret_count)
      {
   printf("\n ERROR : Return code from pthread_join() is %d ",ret_count);
   exit(-1);
      }
         }
         gettimeofday(&tv, &tz);
         time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
 printf("Number of search element found in list Count= %d\n",count);
 printf("Time in Seconds (T)         :  %lf\n", time_end - time_start);
        ret_count = pthread_attr_destroy(&attr);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_destroy() is %d ",ret_count);
  exit(-1);
     }
        ret_count = pthread_mutex_destroy(&count_mutex);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_destroy() is %d ",ret_count);
  exit(-1);
     }
}

canonical_original_code:
int main(int argc, char *argv[]) {
        int i; int start; int ret_count;
 int *tids;
        unsigned long *threads;
 union pthread_attr_t attr;
        double time_start; double time_end;
        struct timeval tv;
        struct timezone tz;
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC):  February-2008");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Finding k matches in the given Array");
        printf("\n\t\t..........................................................................\n");
        for (i=0;i<100000000;i++){
                a[i] = (i %10)+1.0;
        }
 if (argc != 3) {
  printf ("Syntax : exec <Number to be search> <Number of thread>\n");
  return ;
 }
        search_no = atoi(argv[1]);
        num_threads = atoi(argv[2]);
 if (num_threads > 8) {
  printf ("Number of thread should be less than or equal to 8\n");
  return ;
 }
 iterations = 100000000/num_threads;
 threads = (unsigned long *) malloc(sizeof(pthread_t) * num_threads);
 tids = (int *) malloc(sizeof(int) * num_threads);
 gettimeofday(&tv, &tz);
        time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
 ret_count = pthread_mutex_init(&count_mutex, ((void *)0));
 if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count=pthread_attr_init(&attr);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
       if(ret_count)
       {
  printf("\n ERROR : Return code from pthread_attr_setdetachstate() is %d ",ret_count);
  exit(-1);
       }
        for (i=0; i<num_threads; i++) {
                tids[i] = i;
                ret_count = pthread_create(&threads[i], &attr,find_entries, (void *) &tids[i]);
                if(ret_count)
      {
   printf("\n ERROR : Return code from pthread_create() is %d ",ret_count);
   exit(-1);
      }
         }
        for (i=0; i<num_threads; i++) {
                ret_count = pthread_join(threads[i], ((void *)0));
      if(ret_count)
      {
   printf("\n ERROR : Return code from pthread_join() is %d ",ret_count);
   exit(-1);
      }
         }
         gettimeofday(&tv, &tz);
         time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
 printf("Number of search element found in list Count= %d\n",count);
 printf("Time in Seconds (T)         :  %lf\n", time_end - time_start);
        ret_count = pthread_attr_destroy(&attr);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_destroy() is %d ",ret_count);
  exit(-1);
     }
        ret_count = pthread_mutex_destroy(&count_mutex);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_destroy() is %d ",ret_count);
  exit(-1);
     }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types:
tids
int *

variable_types:
threads
unsigned long *

variable_types: union pthread_attr_t { char __size[56]; long __align; }

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

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


decompiled_code:
void *__fastcall thread_function_datarace(void *a1)
{
int v1; // ebx
int v2; // ebp

v1 = myglobal + 1;
v2 = myglobal + 21;
do
{
printf("\nIn thread_function_datarace..\t");
sleep(1u);
myglobal = v1++;
}
while ( v1 != v2 );
return 0LL;
}

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

v1 = myglobal + 1;
v2 = myglobal + 21;
do
{
printf("\nIn thread_function_datarace..\t");
sleep(1u);
myglobal = v1++;
}
while ( v1 != v2 );
return 0LL;
}

original_code:
void *thread_function_datarace(void *arg)
{
   int i,j;
   for ( i=0; i<20; i++ )
 {
      j=myglobal;
      j=j+1;
      printf("\nIn thread_function_datarace..\t");
     sleep(1);
      myglobal=j;
   }
   return ((void *)0);
}

canonical_original_code:
void *thread_function_datarace(void *arg)
{
   int i; int j;
   for ( i=0; i<20; i++ )
 {
      j=myglobal;
      j=j+1;
      printf("\nIn thread_function_datarace..\t");
     sleep(1);
      myglobal=j;
   }
   return ((void *)0);
}

variable_types:
arg
void *

variable_types: j int


decompiled_code:
void *__fastcall thread_function_mutex(void *a1)
{
int v1; // ebp
int v2; // ebx

v1 = 20;
do
{
pthread_mutex_lock(&mymutex);
v2 = myglobal;
printf("\nIn thread_function_mutex..\t");
sleep(0);
myglobal = v2 + 1;
pthread_mutex_unlock(&mymutex);
--v1;
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebp
int v2; // ebx

v1 = 20;
do
{
pthread_mutex_lock(&mymutex);
v2 = myglobal;
printf("\nIn thread_function_mutex..\t");
sleep(0);
myglobal = v2 + 1;
pthread_mutex_unlock(&mymutex);
--v1;
}
while ( v1 );
return 0LL;
}

original_code:
void *thread_function_mutex(void *arg)
{
   int i,j;
   for ( i=0; i<20; i++ )
 {
      pthread_mutex_lock(&mymutex);
  j=myglobal;
      j=j+1;
      printf("\nIn thread_function_mutex..\t");
     sleep(0.1);
      myglobal=j;
  pthread_mutex_unlock(&mymutex);
   }
   return ((void *)0);
}

canonical_original_code:
void *thread_function_mutex(void *arg)
{
   int i; int j;
   for ( i=0; i<20; i++ )
 {
      pthread_mutex_lock(&mymutex);
  j=myglobal;
      j=j+1;
      printf("\nIn thread_function_mutex..\t");
     sleep(0.1);
      myglobal=j;
  pthread_mutex_unlock(&mymutex);
   }
   return ((void *)0);
}


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

if ( !pthread_create(newthread, 0LL, thread_function_datarace, 0LL) )
{
v3 = 20;
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
printf("\n\t\t Email : RarchK");
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : Pthread code to illustrate data race condition and its solution \n ");
puts("\n\t\t..........................................................................");
do
{
++myglobal;
printf("\nIn main..\t");
sleep(1u);
--v3;
}
while ( v3 );
if ( pthread_join(newthread[0], 0LL) )
{
LABEL_11:
printf("error joining thread.");
abort();
}
printf("\nValue of myglobal in thread_function_datarace is : %d\n", (unsigned int)myglobal);
puts("\n ----------------------------------------------------------------------------------------------------");
myglobal = 0;
if ( !pthread_create(newthread, 0LL, thread_function_mutex, 0LL) )
{
v4 = 20;
do
{
pthread_mutex_lock(&mymutex);
++myglobal;
pthread_mutex_unlock(&mymutex);
printf("\nIn main..\t");
sleep(1u);
--v4;
}
while ( v4 );
if ( !pthread_join(newthread[0], 0LL) )
{
putchar(10);
printf("\nValue of myglobal in thread_function_mutex is : %d\n", (unsigned int)myglobal);
exit(0);
}
goto LABEL_11;
}
}
printf("error creating thread.");
abort();
}

original_code:
int main(void)
{
   pthread_t mythread;
   int i;
   if ( pthread_create( &mythread, ((void *)0), thread_function_datarace, ((void *)0)) )
 {
      printf("error creating thread.");
      abort();
   }
 printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Pthread code to illustrate data race condition and its solution \n ");
        printf("\n\t\t..........................................................................\n");
   for ( i=0; i<20; i++)
 {
      myglobal=myglobal+1;
      printf("\nIn main..\t");
      sleep(1);
   }
   if ( pthread_join ( mythread, ((void *)0) ) )
 {
      printf("error joining thread.");
      abort();
   }
   printf("\nValue of myglobal in thread_function_datarace is :  %d\n",myglobal);
 printf("\n ----------------------------------------------------------------------------------------------------\n");
 myglobal = 0;
 if ( pthread_create( &mythread, ((void *)0), thread_function_mutex, ((void *)0)) )
        {
                printf("error creating thread.");
                abort();
        }
        for ( i=0; i<20; i++)
        {
                pthread_mutex_lock(&mymutex);
      myglobal=myglobal+1;
      pthread_mutex_unlock(&mymutex);
      printf("\nIn main..\t");
      sleep(1);
        }
        if ( pthread_join ( mythread, ((void *)0) ) )
        {
                printf("error joining thread.");
                abort();
        }
 printf("\n");
        printf("\nValue of myglobal in thread_function_mutex is :  %d\n",myglobal);
   exit(0);
}

canonical_original_code:
int main()
{
   unsigned long mythread;
   int i;
   if ( pthread_create( &mythread, ((void *)0), thread_function_datarace, ((void *)0)) )
 {
      printf("error creating thread.");
      abort();
   }
 printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Pthread code to illustrate data race condition and its solution \n ");
        printf("\n\t\t..........................................................................\n");
   for ( i=0; i<20; i++)
 {
      myglobal=myglobal+1;
      printf("\nIn main..\t");
      sleep(1);
   }
   if ( pthread_join ( mythread, ((void *)0) ) )
 {
      printf("error joining thread.");
      abort();
   }
   printf("\nValue of myglobal in thread_function_datarace is :  %d\n",myglobal);
 printf("\n ----------------------------------------------------------------------------------------------------\n");
 myglobal = 0;
 if ( pthread_create( &mythread, ((void *)0), thread_function_mutex, ((void *)0)) )
        {
                printf("error creating thread.");
                abort();
        }
        for ( i=0; i<20; i++)
        {
                pthread_mutex_lock(&mymutex);
      myglobal=myglobal+1;
      pthread_mutex_unlock(&mymutex);
      printf("\nIn main..\t");
      sleep(1);
        }
        if ( pthread_join ( mythread, ((void *)0) ) )
        {
                printf("error joining thread.");
                abort();
        }
 printf("\n");
        printf("\nValue of myglobal in thread_function_mutex is :  %d\n",myglobal);
   exit(0);
}

variable_types:
mythread
unsigned long


myPartOfCalc

decompiled_code:
int __fastcall myPartOfCalc(void *a1)
{
int v1; // edi
double v2; // xmm1_8
double v3; // xmm0_8
double v5; // [rsp+8h] [rbp-10h]

v1 = (_DWORD)a1 + 1;
if ( v1 > numberOfIntervals )
{
v2 = 0.0;
}
else
{
v2 = 0.0;
do
{
v3 = (double)v1;
v1 += numberOfIntervals;
v2 = v2
+ *(double *)&four
/ ((v3 - *(double *)&distance)
* *(double *)&intervalWidth
* ((v3 - *(double *)&distance)
* *(double *)&intervalWidth)
+ 1.0);
}
while ( v1 <= numberOfIntervals );
}
v5 = v2 * *(double *)&intervalWidth;
pthread_mutex_lock(&area_mutex);
*(double *)&area = v5 + *(double *)&area;
return pthread_mutex_unlock(&area_mutex);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
int v1; // edi
double v2; // xmm1_8
double v3; // xmm0_8
double v5; // [rsp+8h] [rbp-10h]

v1 = (_DWORD)a1 + 1;
if ( v1 > numberOfIntervals )
{
v2 = 0.0;
}
else
{
v2 = 0.0;
do
{
v3 = (double)v1;
v1 += numberOfIntervals;
v2 = v2
+ *(double *)&four
/ ((v3 - *(double *)&distance)
* *(double *)&intervalWidth
* ((v3 - *(double *)&distance)
* *(double *)&intervalWidth)
+ 1.0);
}
while ( v1 <= numberOfIntervals );
}
v5 = v2 * *(double *)&intervalWidth;
pthread_mutex_lock(&area_mutex);
*(double *)&area = v5 + *(double *)&area;
return pthread_mutex_unlock(&area_mutex);
}

original_code:
void myPartOfCalc(int myID)
{
        int myInterval;
        double myIntervalMidPoint, myArea = 0.0, result;
        for (myInterval = myID + 1; myInterval <= numberOfIntervals; myInterval += numberOfIntervals)
        {
         myIntervalMidPoint = ((double) myInterval - distance) * intervalWidth;
         myArea += (four / (1.0 + myIntervalMidPoint * myIntervalMidPoint));
        }
        result = myArea * intervalWidth;
        pthread_mutex_lock(&area_mutex);
        area += result;
        pthread_mutex_unlock(&area_mutex);
}

canonical_original_code:
void myPartOfCalc(int myID)
{
        int myInterval;
        double myIntervalMidPoint; double myArea = 0.0; double result;
        for (myInterval = myID + 1; myInterval <= numberOfIntervals; myInterval += numberOfIntervals)
        {
         myIntervalMidPoint = ((double) myInterval - distance) * intervalWidth;
         myArea += (four / (1.0 + myIntervalMidPoint * myIntervalMidPoint));
        }
        result = myArea * intervalWidth;
        pthread_mutex_lock(&area_mutex);
        area += result;
        pthread_mutex_unlock(&area_mutex);
}

variable_types: myID int

variable_types: myInterval int

variable_types: myIntervalMidPoint double

variable_types: myArea double

variable_types: result double


doMyWork

decompiled_code:
int __fastcall doMyWork(void *a1)
{
__int64 v1; // rax
int v2; // ecx
unsigned int v3; // ebx
int v4; // edx

printf(
"\n %d: I am taking the interval: %d - %d.",
(unsigned int)a1,
(unsigned int)((_DWORD)a1 * dist - dist),
(unsigned int)((_DWORD)a1 * dist - 1));
LODWORD(v1) = dist * ((_DWORD)a1 - 1);
v2 = v1 + dist;
if ( (int)v1 >= (int)v1 + dist )
{
v3 = 0;
}
else
{
v1 = (int)v1;
v3 = 0;
do
{
v4 = *(_DWORD *)(VecB + 4 * v1) * *(_DWORD *)(VecA + 4 * v1);
++v1;
v3 += v4;
}
while ( v2 > (int)v1 );
}
printf("\n %d: My Local Sum: %d.", (unsigned int)a1, v3);
pthread_mutex_lock(&mutex_sum);
sum += v3;
return pthread_mutex_unlock(&mutex_sum);
}

canonical_decompiled_code:
int __fastcall func7(void *a1)
{
__int64 v1; // rax
int v2; // ecx
unsigned int v3; // ebx
int v4; // edx

printf(
"\n %d: I am taking the interval: %d - %d.",
(unsigned int)a1,
(unsigned int)((_DWORD)a1 * dist - dist),
(unsigned int)((_DWORD)a1 * dist - 1));
LODWORD(v1) = dist * ((_DWORD)a1 - 1);
v2 = v1 + dist;
if ( (int)v1 >= (int)v1 + dist )
{
v3 = 0;
}
else
{
v1 = (int)v1;
v3 = 0;
do
{
v4 = *(_DWORD *)(VecB + 4 * v1) * *(_DWORD *)(VecA + 4 * v1);
++v1;
v3 += v4;
}
while ( v2 > (int)v1 );
}
printf("\n %d: My Local Sum: %d.", (unsigned int)a1, v3);
pthread_mutex_lock(&mutex_sum);
sum += v3;
return pthread_mutex_unlock(&mutex_sum);
}

original_code:
void * doMyWork(int myId)
{
 int counter, mySum = 0;
 printf("\n %d: I am taking the interval: %d - %d.", myId, ((myId - 1) * dist), ((myId * dist) - 1));
  for (counter = ((myId - 1) * dist); counter <= ((myId * dist) - 1); counter++)
   mySum += VecA[counter] * VecB[counter];
  printf("\n %d: My Local Sum: %d.", myId, mySum);
  pthread_mutex_lock(&mutex_sum);
  sum += mySum;
  pthread_mutex_unlock(&mutex_sum);
  return;
}

canonical_original_code:
void *doMyWork(int myId)
{
 int counter; int mySum = 0;
 printf("\n %d: I am taking the interval: %d - %d.", myId, ((myId - 1) * dist), ((myId * dist) - 1));
  for (counter = ((myId - 1) * dist); counter <= ((myId * dist) - 1); counter++)
   mySum += VecA[counter] * VecB[counter];
  printf("\n %d: My Local Sum: %d.", myId, mySum);
  pthread_mutex_lock(&mutex_sum);
  sum += mySum;
  pthread_mutex_unlock(&mutex_sum);
  return;
}

variable_types: myId int

variable_types: counter int

variable_types: mySum int


decompiled_code:
void __fastcall __noreturn find_min(void *a1)
{
__int64 v1; // rdi
__int64 v2; // rdx
int v3; // ebx
__int64 *i; // rax

v1 = partial_list_size * ((int)a1 - 1);
v2 = *((_QWORD *)list + v1);
v3 = v2;
if ( v1 < partial_list_size + v1 )
{
for ( i = (__int64 *)((char *)list + 8 * v1 + 8); ; ++i )
{
if ( v3 > v2 )
v3 = v2;
if ( i == (__int64 *)((char *)list + 8 * partial_list_size + 8 * v1) )
break;
v2 = *i;
}
}
pthread_mutex_lock(&minimum_value_lock);
if ( minimum_value > v3 )
minimum_value = v3;
pthread_mutex_unlock(&minimum_value_lock);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
__int64 v1; // rdi
__int64 v2; // rdx
int v3; // ebx
__int64 *i; // rax

v1 = partial_list_size * ((int)a1 - 1);
v2 = *((_QWORD *)list + v1);
v3 = v2;
if ( v1 < partial_list_size + v1 )
{
for ( i = (__int64 *)((char *)list + 8 * v1 + 8); ; ++i )
{
if ( v3 > v2 )
v3 = v2;
if ( i == (__int64 *)((char *)list + 8 * partial_list_size + 8 * v1) )
break;
v2 = *i;
}
}
pthread_mutex_lock(&minimum_value_lock);
if ( minimum_value > v3 )
minimum_value = v3;
pthread_mutex_unlock(&minimum_value_lock);
pthread_exit(0LL);
}

original_code:
void *find_min(void * myid ) {
     int my_min;
     long int counter;
     int myId = (int)myid;
     my_min = list[(myId-1)*partial_list_size];
     for (counter = ((myId - 1) * partial_list_size); counter <= ((myId * partial_list_size) - 1); counter++){
        if (list[counter] < my_min)
            my_min = list[counter];
     }
    pthread_mutex_lock(&minimum_value_lock) ;
    if (my_min < minimum_value)
       minimum_value = my_min;
    pthread_mutex_unlock(&minimum_value_lock) ;
    pthread_exit(((void *)0));
}

canonical_original_code:
void *find_min(void *myid) {
     int my_min;
     long counter;
     int myId = (int)myid;
     my_min = list[(myId-1)*partial_list_size];
     for (counter = ((myId - 1) * partial_list_size); counter <= ((myId * partial_list_size) - 1); counter++){
        if (list[counter] < my_min)
            my_min = list[counter];
     }
    pthread_mutex_lock(&minimum_value_lock) ;
    if (my_min < minimum_value)
       minimum_value = my_min;
    pthread_mutex_unlock(&minimum_value_lock) ;
    pthread_exit(((void *)0));
}

variable_types:
myid
void *

variable_types: counter long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // edx
int v5; // eax
__int64 v6; // rbx
double v7; // xmm0_8
__int64 v8; // rbx
unsigned int v9; // edi
pthread_t *v10; // rbp
unsigned int v11; // eax
unsigned int v12; // eax
pthread_t *v13; // r12
char *v14; // rbx
pthread_t *v15; // rdi
unsigned int v16; // eax
__int64 i; // rbx
unsigned int v18; // eax
unsigned int v19; // eax
double v21; // [rsp+0h] [rbp-98h]
double v22; // [rsp+8h] [rbp-90h]
struct timezone tz; // [rsp+18h] [rbp-80h] BYREF
struct timeval tv; // [rsp+20h] [rbp-78h] BYREF
pthread_attr_t attr; // [rsp+30h] [rbp-68h] BYREF

printf("\n\t\t--------------------------------------------------------------------------");
printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
printf("\n\t\t C-DAC Multi Core Benchmark Suite 1.0");
printf("\n\t\t Email : RarchK");
printf("\n\t\t---------------------------------------------------------------------------");
printf("\n\t\t Objective : Sorting Single Dimension Array (Integer Operations)\n ");
printf("\n\t\t Performance of Sorting a Minimum value in a large Single Dimension Array ");
puts("\n\t\t on Multi Socket Multi Core Processor using 1/2/4/8 threads ");
puts("\n\t\t..........................................................................");
if ( argc != 3 )
{
printf("\t\t Very Few Arguments\n ");
puts("\t\t Syntax : exec <Class-Size> <Threads>");
exit(-1);
}
v3 = argv[1];
v4 = atoi(argv[2]);
v5 = *(unsigned __int8 *)v3;
if ( v5 == 65 && !v3[1] )
{
CLASS_SIZE = 10000000LL;
v5 = *(unsigned __int8 *)v3;
}
if ( v5 == 66 && !v3[1] )
{
CLASS_SIZE = 100000000LL;
v5 = *(unsigned __int8 *)v3;
}
if ( v5 == 67 && !v3[1] )
CLASS_SIZE = 1000000000LL;
NumThreads = v4;
NumElements = CLASS_SIZE;
printf("\n\t\t Array Size : %ld", CLASS_SIZE);
printf("\n\t\t Threads : %d", (unsigned int)NumThreads);
putchar(10);
if ( NumThreads <= 0 )
{
puts("\n Number of threads must be greater than zero. Aborting ...");
}
else if ( ((NumThreads - 4) & 0xFFFFFFFB) != 0 && (unsigned int)(NumThreads - 1) > 1 )
{
puts("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...");
}
else if ( NumElements % NumThreads )
{
puts("\n Number of threads not a factor of Integer List size. Aborting.");
}
else
{
v6 = 8 * NumElements;
partial_list_size = NumElements / NumThreads;
list = malloc(8 * NumElements);
if ( v6 < 0 )
v7 = (double)(int)((unsigned __int64)v6 >> 1) + (double)(int)((unsigned __int64)v6 >> 1);
else
v7 = (double)(int)v6;
v8 = 0LL;
gettimeofday(&tv, &tz);
v9 = NumElements;
v21 = (double)SLODWORD(tv.tv_usec) / 1000000.0 + (double)SLODWORD(tv.tv_sec);
if ( NumElements > 0 )
{
do
{
srand48(v9);
*((_QWORD *)list + v8) = (unsigned int)(int)((double)(rand() % 1000) + 1.0);
v9 = NumElements;
++v8;
}
while ( NumElements > v8 );
}
v10 = (pthread_t *)malloc(8LL * NumThreads);
minimum_value = *(_QWORD *)list;
v11 = pthread_mutex_init(&minimum_value_lock, 0LL);
if ( v11 )
{
printf("\n ERROR : Return code from pthread_mutex_init() is %d ", v11);
exit(-1);
}
v12 = pthread_attr_init(&attr);
if ( v12 )
{
printf("\n ERROR : Return code from pthread_attr_init() is %d ", v12);
exit(-1);
}
v13 = v10;
v14 = 0LL;
pthread_attr_setscope(&attr, 0);
while ( NumThreads > (int)v14 )
{
++v14;
v15 = v13++;
v16 = pthread_create(v15, &attr, find_min, v14);
if ( v16 )
{
printf("\n ERROR : Return code from pthread_create() is %d ", v16);
exit(-1);
}
}
for ( i = 0LL; NumThreads > (int)i; ++i )
{
v18 = pthread_join(v10[i], 0LL);
if ( v18 )
{
printf("\n ERROR : Return code from pthread_join() is %d ", v18);
exit(-1);
}
}
v19 = pthread_attr_destroy(&attr);
if ( v19 )
{
printf("\n ERROR : Return code from pthread_attr_destroy() is %d ", v19);
exit(-1);
}
gettimeofday(&tv, &tz);
v22 = (double)SLODWORD(tv.tv_sec) + (double)SLODWORD(tv.tv_usec) / 1000000.0;
printf("\n\t\t Minimum Value found in the Integer list : %d", (unsigned int)minimum_value);
printf("\n\t\t Memory Utilised : %lf MB", (v7 + 0.0) * 0.00000095367431640625);
printf("\n\t\t Time Taken in Seconds (T) : %lf Seconds", v22 - v21);
puts("\n\t\t..........................................................................");
free(list);
free(v10);
}
return 0;
}

original_code:
int main (int argc,char * argv[])
{
        pthread_t *threads;
        pthread_attr_t pta;
        int iteration,THREADS,ret_count;
        double time_start, time_end;
        struct timeval tv;
        struct timezone tz;
        double MemoryUsed = 0.0;
 char * CLASS;
        int counter;
        printf("\n\t\t--------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
        printf("\n\t\t C-DAC Multi Core Benchmark Suite 1.0");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Sorting Single Dimension Array (Integer Operations)\n ");
        printf("\n\t\t Performance of Sorting a Minimum value in a large Single Dimension Array ");
        printf("\n\t\t on Multi Socket Multi Core Processor using 1/2/4/8 threads \n");
        printf("\n\t\t..........................................................................\n");
         if( argc != 3 ){
            printf("\t\t Very Few Arguments\n ");
            printf("\t\t Syntax : exec <Class-Size> <Threads>\n");
            exit(-1);
         }
         else {
            CLASS = argv[1];
            THREADS = atoi(argv[2]);
         }
         if( strcmp(CLASS, "A" )==0){
            CLASS_SIZE = 10000000;
         }
         if( strcmp(CLASS, "B" )==0){
            CLASS_SIZE = 100000000;
         }
        if( strcmp(CLASS, "C" )==0){
            CLASS_SIZE = 1000000000;
        }
        NumElements = CLASS_SIZE;
        NumThreads = THREADS;
        printf("\n\t\t Array Size  :  %ld",NumElements);
        printf("\n\t\t Threads     :  %d",NumThreads);
        printf("\n");
        if (NumThreads < 1 )
        {
           printf("\n Number of threads must be greater than zero. Aborting ...\n");
           return 0;
        }
        if ((NumThreads != 1) && (NumThreads != 2) && (NumThreads != 4) && (NumThreads != 8))
        {
           printf("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...\n");
           return 0;
        }
        if ( ( NumElements % NumThreads ) != 0 )
        {
           printf("\n Number of threads not a factor of Integer List size. Aborting.\n");
     return 0 ;
        }
        partial_list_size = NumElements / NumThreads;
        list = (long int *)malloc(sizeof(long int) * NumElements);
        MemoryUsed += ( NumElements * sizeof(long int));
        gettimeofday(&tv, &tz);
        time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        for(counter = 0 ; counter < NumElements ; counter++){
            srand48((unsigned int)NumElements);
            list[counter] = (rand()%1000)+1.0;
        }
        threads = (pthread_t *)malloc(sizeof(pthread_t)*NumThreads);
        minimum_value = list[0];
        ret_count=pthread_mutex_init(&minimum_value_lock, ((void *)0));
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count=pthread_attr_init(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_init() is %d ",ret_count);
  exit(-1);
     }
        pthread_attr_setscope(&pta,PTHREAD_SCOPE_SYSTEM);
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_create(&threads[counter],&pta,(void *(*) (void *)) find_min,(void *) (counter+1));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_create() is %d ",ret_count);
  exit(-1);
        }
 }
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_join(threads[counter],((void *)0));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_join() is %d ",ret_count);
  exit(-1);
        }
        }
        ret_count=pthread_attr_destroy(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_destroy() is %d ",ret_count);
  exit(-1);
     }
        gettimeofday(&tv, &tz);
        time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        printf("\n\t\t Minimum Value found in the Integer list     :  %d",minimum_value);
        printf("\n\t\t Memory Utilised                             :  %lf MB",(MemoryUsed / (1024*1024)));
        printf("\n\t\t Time Taken in Seconds  (T)                  :  %lf Seconds",( time_end - time_start));
        printf("\n\t\t..........................................................................\n");
        free(list);
        free(threads);
        return 0;
 }

canonical_original_code:
int main(int argc, char *argv[])
{
        unsigned long *threads;
        union pthread_attr_t pta;
        int iteration; int THREADS; int ret_count;
        double time_start; double time_end;
        struct timeval tv;
        struct timezone tz;
        double MemoryUsed = 0.0;
 char *CLASS;
        int counter;
        printf("\n\t\t--------------------------------------------------------------------------");
        printf("\n\t\t Centre for Development of Advanced Computing (C-DAC)");
        printf("\n\t\t C-DAC Multi Core Benchmark Suite 1.0");
        printf("\n\t\t Email : RarchK");
        printf("\n\t\t---------------------------------------------------------------------------");
        printf("\n\t\t Objective : Sorting Single Dimension Array (Integer Operations)\n ");
        printf("\n\t\t Performance of Sorting a Minimum value in a large Single Dimension Array ");
        printf("\n\t\t on Multi Socket Multi Core Processor using 1/2/4/8 threads \n");
        printf("\n\t\t..........................................................................\n");
         if( argc != 3 ){
            printf("\t\t Very Few Arguments\n ");
            printf("\t\t Syntax : exec <Class-Size> <Threads>\n");
            exit(-1);
         }
         else {
            CLASS = argv[1];
            THREADS = atoi(argv[2]);
         }
         if( strcmp(CLASS, "A" )==0){
            CLASS_SIZE = 10000000;
         }
         if( strcmp(CLASS, "B" )==0){
            CLASS_SIZE = 100000000;
         }
        if( strcmp(CLASS, "C" )==0){
            CLASS_SIZE = 1000000000;
        }
        NumElements = CLASS_SIZE;
        NumThreads = THREADS;
        printf("\n\t\t Array Size  :  %ld",NumElements);
        printf("\n\t\t Threads     :  %d",NumThreads);
        printf("\n");
        if (NumThreads < 1 )
        {
           printf("\n Number of threads must be greater than zero. Aborting ...\n");
           return 0;
        }
        if ((NumThreads != 1) && (NumThreads != 2) && (NumThreads != 4) && (NumThreads != 8))
        {
           printf("\n Number of Threads must be 1 or 2 or 4 or 8. Aborting ...\n");
           return 0;
        }
        if ( ( NumElements % NumThreads ) != 0 )
        {
           printf("\n Number of threads not a factor of Integer List size. Aborting.\n");
     return 0 ;
        }
        partial_list_size = NumElements / NumThreads;
        list = (long *)malloc(sizeof(long) * NumElements);
        MemoryUsed += ( NumElements * sizeof(long));
        gettimeofday(&tv, &tz);
        time_start = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        for(counter = 0 ; counter < NumElements ; counter++){
            srand48((unsigned int)NumElements);
            list[counter] = (rand()%1000)+1.0;
        }
        threads = (unsigned long *)malloc(sizeof(pthread_t)*NumThreads);
        minimum_value = list[0];
        ret_count=pthread_mutex_init(&minimum_value_lock, ((void *)0));
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_mutex_init() is %d ",ret_count);
  exit(-1);
     }
        ret_count=pthread_attr_init(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_init() is %d ",ret_count);
  exit(-1);
     }
        pthread_attr_setscope(&pta,PTHREAD_SCOPE_SYSTEM);
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_create(&threads[counter],&pta,(void *(*)(void *)) find_min,(void *) (counter+1));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_create() is %d ",ret_count);
  exit(-1);
        }
 }
        for(counter = 0 ; counter < NumThreads ; counter++)
 {
           ret_count=pthread_join(threads[counter],((void *)0));
        if(ret_count)
        {
  printf("\n ERROR : Return code from pthread_join() is %d ",ret_count);
  exit(-1);
        }
        }
        ret_count=pthread_attr_destroy(&pta);
     if(ret_count)
     {
  printf("\n ERROR : Return code from pthread_attr_destroy() is %d ",ret_count);
  exit(-1);
     }
        gettimeofday(&tv, &tz);
        time_end = (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
        printf("\n\t\t Minimum Value found in the Integer list     :  %d",minimum_value);
        printf("\n\t\t Memory Utilised                             :  %lf MB",(MemoryUsed / (1024*1024)));
        printf("\n\t\t Time Taken in Seconds  (T)                  :  %lf Seconds",( time_end - time_start));
        printf("\n\t\t..........................................................................\n");
        free(list);
        free(threads);
        return 0;
 }

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
threads
unsigned long *

variable_types: iteration int

variable_types: THREADS int

variable_types: MemoryUsed double

variable_types:
CLASS
char *

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }

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

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


decompiled_code:
void *queue_init()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
void *result; // rax

v0 = malloc(0x30uLL);
q = (__int64)v0;
v1 = malloc(0x10uLL);
v1[1] = 0LL;
v0[1] = v1;
v0[2] = v1;
result = malloc(0x28uLL);
*(_DWORD *)v0 = 0;
v0[3] = result;
return result;
}

canonical_decompiled_code:
void *func7()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
void *result; // rax

v0 = malloc(0x30uLL);
q = (__int64)v0;
v1 = malloc(0x10uLL);
v1[1] = 0LL;
v0[1] = v1;
v0[2] = v1;
result = malloc(0x28uLL);
*(_DWORD *)v0 = 0;
v0[3] = result;
return result;
}

original_code:
void
queue_init ()
{
  q = (queue *) malloc (sizeof (queue));
  q->front = (struct node *) malloc (sizeof (struct node));
  q->front->next = ((void *)0);
  q->rear = q->front;
  q->mutex = (pthread_mutex_t *) malloc (sizeof (pthread_mutex_t));
  q->contains = 0;
  return;
}

canonical_original_code:
void queue_init()
{
  q = (struct queue *) malloc (sizeof (queue));
  q->front = (struct node *) malloc (sizeof (struct node));
  q->front->next = ((void *)0);
  q->rear = q->front;
  q->mutex = (union pthread_mutex_t *) malloc (sizeof (pthread_mutex_t));
  q->contains = 0;
  return;
}

user_defined_types: struct node { int data; struct node *next; }

user_defined_types: struct queue { int contains; struct node *front; struct node *rear; union pthread_mutex_t *mutex; union pthread_cond_t *queue_full; union pthread_cond_t *queue_empty; }

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; }

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

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

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]; }


dequeue

decompiled_code:
double dequeue()
{
__int64 v0; // rax
int *v1; // rdi
__int64 v2; // rdx
double result; // xmm0_8

v0 = q;
v1 = *(int **)(q + 8);
v2 = *((_QWORD *)v1 + 1);
result = (double)*v1;
--*(_DWORD *)q;
*(_QWORD *)(v0 + 8) = v2;
free(v1);
return result;
}

canonical_decompiled_code:
double func9()
{
__int64 v0; // rax
int *v1; // rdi
__int64 v2; // rdx
double result; // xmm0_8

v0 = q;
v1 = *(int **)(q + 8);
v2 = *((_QWORD *)v1 + 1);
result = (double)*v1;
--*(_DWORD *)q;
*(_QWORD *)(v0 + 8) = v2;
free(v1);
return result;
}

original_code:
double
dequeue ()
{
  struct node *tmp = q->front;
  q->front = q->front->next;
  double retval = tmp->data;
  q->contains--;
  free (tmp);
  return retval;
}

canonical_original_code:
double dequeue()
{
  struct node *tmp = q->front;
  q->front = q->front->next;
  double retval = tmp->data;
  q->contains--;
  free (tmp);
  return retval;
}

variable_types: struct node { int data; struct node *next; } *

variable_types: retval double

return_type: double


BusyWork

decompiled_code:
void __fastcall __noreturn BusyWork(void *a1)
{
int v1; // ebx
double v2; // xmm0_8
double v3; // [rsp+0h] [rbp-10h]

v1 = 1000000;
v3 = 0.0;
do
{
v2 = (double)(int)random() + v3;
v3 = v2;
--v1;
}
while ( v1 );
printf("result = %e\n", v2);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // ebx
double v2; // xmm0_8
double v3; // [rsp+0h] [rbp-10h]

v1 = 1000000;
v3 = 0.0;
do
{
v2 = (double)(int)random() + v3;
v3 = v2;
--v1;
}
while ( v1 );
printf("result = %e\n", v2);
pthread_exit(0LL);
}

original_code:
void *BusyWork(void *null)
{
   int i;
   double result=0.0;
   for (i=0; i<1000000; i++)
   {
     result = result + (double)random();
   }
   printf("result = %e\n",result);
   pthread_exit((void *) 0);
}

canonical_original_code:
void *BusyWork(void *null)
{
   int i;
   double result = 0.0;
   for (i=0; i<1000000; i++)
   {
     result = result + (double)random();
   }
   printf("result = %e\n",result);
   pthread_exit((void *) 0);
}

variable_types: i int