original_code:
int create_map(map **inhashmap, int thetype, long start_size, int rsize_factor, double ld_factor) {
   bucket *curr = ((void *)0);
   map *hashmap = ((void *)0);
   int i;
   hashmap = (map*)malloc(sizeof(map));
   hashmap->size = 0;
   hashmap->bucketsize = start_size;
   hashmap->resize_factor = rsize_factor;
   hashmap->load_factor = ld_factor;
   hashmap->currentload = 0.0;
   hashmap->bucketsused = 0;
   hashmap->scale = rand()% 4 + 1;
   hashmap->offset = rand() % hashmap->bucketsize;
   hashmap->type = thetype;
   hashmap->start = (bucket*)malloc((sizeof(bucket) * hashmap->bucketsize));
   if( hashmap->start == ((void *)0)) {
      perror("malloc of buckets failed");
      return FAILURE;
   }
   else {
      curr = hashmap->start;
      for(i=0; i < hashmap->bucketsize; i++) {
         curr->start = ((void *)0);
         curr->index = i;
         curr->count = 0;
         curr++;
      }
   }
   *inhashmap = hashmap;
   return SUCCESS;
}

canonical_original_code:
int create_map(struct map **inhashmap, int thetype, long start_size, int rsize_factor, double ld_factor) {
   struct bucket *curr = ((void *)0);
   struct map *hashmap = ((void *)0);
   int i;
   hashmap = (struct map *)malloc(sizeof(map));
   hashmap->size = 0;
   hashmap->bucketsize = start_size;
   hashmap->resize_factor = rsize_factor;
   hashmap->load_factor = ld_factor;
   hashmap->currentload = 0.0;
   hashmap->bucketsused = 0;
   hashmap->scale = rand()% 4 + 1;
   hashmap->offset = rand() % hashmap->bucketsize;
   hashmap->type = thetype;
   hashmap->start = (struct bucket *)malloc((sizeof(bucket) * hashmap->bucketsize));
   if( hashmap->start == ((void *)0)) {
      perror("malloc of buckets failed");
      return FAILURE;
   }
   else {
      curr = hashmap->start;
      for(i=0; i < hashmap->bucketsize; i++) {
         curr->start = ((void *)0);
         curr->index = i;
         curr->count = 0;
         curr++;
      }
   }
   *inhashmap = hashmap;
   return SUCCESS;
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } **

variable_types: thetype int


repo: josephburns/map

decompiled_code:
__int64 __fastcall map_init(_QWORD *a1, int a2)
{
return create_map(a1, a2, 5LL, 2, 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2)
{
return func0(a1, a2, 5LL, 2, 0.5);
}

original_code:
int map_init(map **themap,int type) {
   return create_map(themap, type, (long)5, (long)2, (double)0.5);
}

canonical_original_code:
int map_init(struct map **themap, int type) {
   return create_map(themap, type, (long)5, (long)2, (double)0.5);
}

variable_types: type int

return_type: int

user_defined_types: struct map { struct bucket *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status type; }

user_defined_types: enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 }

user_defined_types: struct bucket { struct kvpair *start; unsigned long index; long count; }

user_defined_types: struct kvpair { void *key; void *value; struct kvpair *next; }


isempty

decompiled_code:
_BOOL8 __fastcall isempty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int isempty(map *themap) {
   return ((themap->size) > 0 ? FALSE : TRUE);
}

canonical_original_code:
int isempty(struct map *themap) {
   return ((themap->size) > 0 ? FALSE : TRUE);
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } *


decompiled_code:
__int64 __fastcall map_size(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
unsigned long map_size(map *themap) {
   return themap->size;
}

canonical_original_code:
unsigned long map_size(struct map *themap) {
   return themap->size;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall k_hash(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 1]();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 1]();
}

original_code:
unsigned long k_hash(map *themap,void *key) {
   return mapfntab[themap->type].fn_hash(themap,key);
}

canonical_original_code:
unsigned long k_hash(struct map *themap, void *key) {
   return mapfntab[themap->type].fn_hash(themap,key);
}

variable_types:
key
void *


decompiled_code:
__int64 __fastcall kv_put(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 2]();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 2]();
}

original_code:
int kv_put(map **ppthemap, void *key, void *value) {
   int code;
   code = mapfntab[(*ppthemap)->type].fn_put(ppthemap, key, value);
   return code;
}

canonical_original_code:
int kv_put(struct map **ppthemap, void *key, void *value) {
   int code;
   code = mapfntab[(*ppthemap)->type].fn_put(ppthemap, key, value);
   return code;
}

variable_types:
value
void *

variable_types: code int


decompiled_code:
__int64 __fastcall kv_get(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 3]();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 3]();
}

original_code:
int kv_get(map *themap, void *key, void **newvalue) {
   return mapfntab[themap->type].fn_get(themap, key, newvalue);
}

canonical_original_code:
int kv_get(struct map *themap, void *key, void **newvalue) {
   return mapfntab[themap->type].fn_get(themap, key, newvalue);
}

variable_types:
newvalue
void **


decompiled_code:
__int64 __fastcall kv_remove(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 4]();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 4]();
}

original_code:
int kv_remove(map *themap, void *key) {
   return mapfntab[themap->type].fn_remove(themap, key);
}

canonical_original_code:
int kv_remove(struct map *themap, void *key) {
   return mapfntab[themap->type].fn_remove(themap, key);
}


decompiled_code:
__int64 __fastcall map_destroy(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 5]();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 5]();
}

original_code:
int map_destroy(map *themap) {
   return mapfntab[themap->type].fn_destroy(themap);
}

canonical_original_code:
int map_destroy(struct map *themap) {
   return mapfntab[themap->type].fn_destroy(themap);
}


decompiled_code:
__int64 __fastcall map_rehash(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 6]();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 6]();
}

original_code:
int map_rehash(map **themap) {
   return mapfntab[(*themap)->type].fn_rehash(themap);
}

canonical_original_code:
int map_rehash(struct map **themap) {
   return mapfntab[(*themap)->type].fn_rehash(themap);
}


decompiled_code:
__int64 __fastcall map_keys(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 7]();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 7]();
}

original_code:
int map_keys(map *themap, void ***keyptr) {
   return mapfntab[themap->type].fn_keys(themap,keyptr);
}

canonical_original_code:
int map_keys(struct map *themap, void ***keyptr) {
   return mapfntab[themap->type].fn_keys(themap,keyptr);
}

variable_types:
keyptr
void ***


decompiled_code:
__int64 __fastcall chptr_hash(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int8 v2; // al
__int64 v3; // rcx

v1 = a1 + 1;
v2 = *a1;
if ( !*a1 )
return 5381LL;
v3 = 5381LL;
do
{
v3 += 32 * v3 + v2;
v2 = *v1++;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rsi
unsigned __int8 v2; // al
__int64 v3; // rcx

v1 = a1 + 1;
v2 = *a1;
if ( !*a1 )
return 5381LL;
v3 = 5381LL;
do
{
v3 += 32 * v3 + v2;
v2 = *v1++;
}
while ( v2 );
return v3;
}

original_code:
unsigned long chptr_hash(unsigned char *str) {
   unsigned long hashvalue = 5381;
   int c;
   while ((c = *str++))
      hashvalue = ((hashvalue << 5) + hashvalue) + c;
   return hashvalue;
}

variable_types:
str
unsigned char *

variable_types:
hashvalue
unsigned long

variable_types: c int


decompiled_code:
unsigned __int64 __fastcall sp_k_hash(__int64 a1, unsigned __int8 *a2)
{
return (*(unsigned int *)(a1 + 60) + chptr_hash(a2) * (unsigned __int64)*(unsigned int *)(a1 + 56))
% *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int8 *a2)
{
return (*(unsigned int *)(a1 + 60) + func0(a2) * (unsigned __int64)*(unsigned int *)(a1 + 56))
% *(_QWORD *)(a1 + 8);
}

original_code:
unsigned long sp_k_hash(map* themap, void* string) {
   return ((themap->scale) * chptr_hash((char*)string) + themap->offset) % themap->bucketsize;
}

canonical_original_code:
unsigned long sp_k_hash(struct map *themap, void *string) {
   return ((themap->scale) * chptr_hash((char *)string) + themap->offset) % themap->bucketsize;
}

variable_types:
string
void *


decompiled_code:
__int64 __fastcall sp_kv_get(_QWORD *a1, unsigned __int8 *a2, char **a3)
{
__int64 v4; // rbx
__int64 result; // rax
size_t v6; // rax
char *v7; // rax

v4 = *(_QWORD *)(*a1 + 24 * sp_k_hash((__int64)a1, a2));
if ( v4 )
{
while ( strcmp(*(const char **)v4, (const char *)a2) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_4;
}
v6 = strlen(*(const char **)(v4 + 8));
v7 = (char *)malloc(v6 + 1);
*a3 = v7;
strcpy(v7, *(const char **)(v4 + 8));
result = 1LL;
}
else
{
LABEL_4:
*a3 = 0LL;
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, unsigned __int8 *a2, char **a3)
{
__int64 v4; // rbx
__int64 result; // rax
size_t v6; // rax
char *v7; // rax

v4 = *(_QWORD *)(*a1 + 24 * func1((__int64)a1, a2));
if ( v4 )
{
while ( strcmp(*(const char **)v4, (const char *)a2) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_4;
}
v6 = strlen(*(const char **)(v4 + 8));
v7 = (char *)malloc(v6 + 1);
*a3 = v7;
strcpy(v7, *(const char **)(v4 + 8));
result = 1LL;
}
else
{
LABEL_4:
*a3 = 0LL;
result = 2LL;
}
return result;
}

original_code:
int sp_kv_get(map *themap, void *key, void **value) {
 unsigned long code = 0;
 bucket* buck = ((void *)0);
 kvpair *kvcurr = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char*)kvcurr->key),(char*)key) == 0) {
     (*value) = malloc(sizeof(char) * strlen(kvcurr->value) + 1);
         strcpy((*value),kvcurr->value);
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

canonical_original_code:
int sp_kv_get(struct map *themap, void *key, void **value) {
 unsigned long code = 0;
 struct bucket *buck = ((void *)0);
 struct kvpair *kvcurr = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char *)kvcurr->key),(char *)key) == 0) {
     (*value) = malloc(sizeof(char) * strlen(kvcurr->value) + 1);
         strcpy((*value),kvcurr->value);
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

variable_types:
value
void **

variable_types:
code
unsigned long

variable_types: struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *


original_code:
int sp_kv_remove(map *themap, void *searchstring) {
 bucket *bucketptr=((void *)0);
 kvpair *prev=((void *)0),*curr=((void *)0);
 int i=0,code;
 code = sp_k_hash(themap, (char*)searchstring);
 bucketptr = themap->start + code;
 if(bucketptr == ((void *)0))
  return FALSE;
 else {
  prev = curr = bucketptr->start;
  while(curr != ((void *)0)) {
    if(strcmp(curr->key, (char*)searchstring)==0) {
    if(i==0)
     bucketptr->start = curr->next;
    else
     prev->next = curr->next;
    if(curr->key != ((void *)0))
     free((void*)curr->key);
            curr->key = ((void *)0);
    if(curr->value != ((void *)0))
     free((void*)curr->value);
            curr->value = ((void *)0);
            if(curr != ((void *)0))
               free((void*)curr);
            curr = prev = ((void *)0);
    return TRUE;
   }
   prev = curr;
   curr = curr->next;
   i++;
  }
  return NOTFOUND;
 }
}

canonical_original_code:
int sp_kv_remove(struct map *themap, void *searchstring) {
 struct bucket *bucketptr = ((void *)0);
 struct kvpair *prev = ((void *)0); struct kvpair *curr = ((void *)0);
 int i = 0; int code;
 code = sp_k_hash(themap, (char *)searchstring);
 bucketptr = themap->start + code;
 if(bucketptr == ((void *)0))
  return FALSE;
 else {
  prev = curr = bucketptr->start;
  while(curr != ((void *)0)) {
    if(strcmp(curr->key, (char *)searchstring)==0) {
    if(i==0)
     bucketptr->start = curr->next;
    else
     prev->next = curr->next;
    if(curr->key != ((void *)0))
     free((void *)curr->key);
            curr->key = ((void *)0);
    if(curr->value != ((void *)0))
     free((void *)curr->value);
            curr->value = ((void *)0);
            if(curr != ((void *)0))
               free((void *)curr);
            curr = prev = ((void *)0);
    return TRUE;
   }
   prev = curr;
   curr = curr->next;
   i++;
  }
  return NOTFOUND;
 }
}

variable_types:
searchstring
void *

variable_types: struct kvpair { void *key; void *value; struct kvpair *next; } *

variable_types: i int


original_code:
int sp_map_destroy(map *themap) {
 bucket *bucketptr = ((void *)0);
 kvpair *kvcurr = ((void *)0), *kvprev = ((void *)0);
 int i=0;
 bucketptr = themap->start;
 for(i=0; i < themap->bucketsize; i++) {
  if(bucketptr->start != ((void *)0)) {
   kvcurr = bucketptr->start;
   while(kvcurr != ((void *)0)) {
    if(kvcurr->key != ((void *)0))
     free(kvcurr->key);
    kvcurr->key = ((void *)0);
    if(kvcurr->value != ((void *)0))
     free(kvcurr->value);
    kvcurr->value = ((void *)0);
    kvprev = kvcurr;
    kvcurr = kvcurr->next;
    kvprev->next = ((void *)0);
    if(kvprev != ((void *)0))
     free((void*)kvprev);
    kvprev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start != ((void *)0))
  free((void*)themap->start);
   themap->start = ((void *)0);
 themap = ((void *)0);
   return SUCCESS;
}

canonical_original_code:
int sp_map_destroy(struct map *themap) {
 struct bucket *bucketptr = ((void *)0);
 struct kvpair *kvcurr = ((void *)0); struct kvpair *kvprev = ((void *)0);
 int i = 0;
 bucketptr = themap->start;
 for(i=0; i < themap->bucketsize; i++) {
  if(bucketptr->start != ((void *)0)) {
   kvcurr = bucketptr->start;
   while(kvcurr != ((void *)0)) {
    if(kvcurr->key != ((void *)0))
     free(kvcurr->key);
    kvcurr->key = ((void *)0);
    if(kvcurr->value != ((void *)0))
     free(kvcurr->value);
    kvcurr->value = ((void *)0);
    kvprev = kvcurr;
    kvcurr = kvcurr->next;
    kvprev->next = ((void *)0);
    if(kvprev != ((void *)0))
     free((void *)kvprev);
    kvprev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start != ((void *)0))
  free((void *)themap->start);
   themap->start = ((void *)0);
 themap = ((void *)0);
   return SUCCESS;
}


decompiled_code:
__int64 __fastcall sp_map_keys(__int64 *a1, _QWORD *a2)
{
size_t v2; // r15
char **v3; // rax
char **v4; // rbp
__int64 v5; // rdx
__int64 v6; // rax
__int64 v7; // r12
__int64 v8; // r13
__int64 result; // rax
__int64 i; // rbx
size_t v11; // rax
char *v12; // rdi

v2 = 8 * a1[2] + 8;
v3 = (char **)malloc(v2);
if ( v3 )
{
v4 = v3;
v5 = *a1;
v6 = a1[1];
if ( v6 )
{
v7 = v5 + 24;
v8 = v5 + 24 * v6;
while ( 1 )
{
for ( i = *(_QWORD *)(v7 - 24); i; i = *(_QWORD *)(i + 16) )
{
v11 = strlen(*(const char **)i);
v12 = (char *)malloc(v11 + 1);
*v4 = v12;
if ( v12 )
{
strcpy(v12, *(const char **)i);
++v4;
}
}
if ( v8 == v7 )
break;
v7 += 24LL;
}
}
*v4 = 0LL;
*a2 = (char *)v4 - v2 + 8;
result = 1LL;
}
else
{
perror("key list malloc failed\n");
result = 0LL;
}
return result;
}

original_code:
int sp_map_keys(map *themap, void ***inkeys) {
 bucket *bucketptr=((void *)0);
   kvpair *curr=((void *)0);
   void **pkeys = ((void *)0);
   int i=0;
 pkeys = (void**)malloc(sizeof(char*) * ((themap->size)+1));
   if(pkeys == ((void *)0)) {
    perror("key list malloc failed\n");
      return FAILURE;
   }
   bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    *pkeys = (char*)malloc(sizeof(char) * (strlen(curr->key)+1));
    if((*pkeys)!=((void *)0)) {
     strcpy((*pkeys),curr->key);
     pkeys++;
    }
    curr = curr->next;
   }
  }
  bucketptr++;
 }
 *pkeys = ((void *)0);
   *inkeys = pkeys -= themap->size;
   return SUCCESS;
}

canonical_original_code:
int sp_map_keys(struct map *themap, void ***inkeys) {
 struct bucket *bucketptr = ((void *)0);
   struct kvpair *curr = ((void *)0);
   void **pkeys = ((void *)0);
   int i = 0;
 pkeys = (void **)malloc(sizeof(char *) * ((themap->size)+1));
   if(pkeys == ((void *)0)) {
    perror("key list malloc failed\n");
      return FAILURE;
   }
   bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    *pkeys = (char *)malloc(sizeof(char) * (strlen(curr->key)+1));
    if((*pkeys)!=((void *)0)) {
     strcpy((*pkeys),curr->key);
     pkeys++;
    }
    curr = curr->next;
   }
  }
  bucketptr++;
 }
 *pkeys = ((void *)0);
   *inkeys = pkeys -= themap->size;
   return SUCCESS;
}

variable_types:
inkeys
void ***

variable_types:
pkeys
void **


nextprobableprime

decompiled_code:
__int64 __fastcall nextprobableprime(__int64 a1)
{
return a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return a1 + 1;
}

original_code:
unsigned long nextprobableprime(unsigned long num) {
 return num + 1;
}

variable_types:
num
unsigned long


original_code:
int sp_map_rehash(map **incmap) {
   map *themap = *incmap;
 map *pnewmap = ((void *)0);
 kvpair *curr=((void *)0),*prev=((void *)0);
 bucket *bucketptr=((void *)0);
   status code;
 long i=0;
   pnewmap = (map*)malloc(sizeof(map));
   code = create_map(&pnewmap, themap->type, nextprobableprime((themap->bucketsize) * (themap->resize_factor)), themap->resize_factor, themap->load_factor);
 bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    kv_put(&pnewmap, (void*)curr->key, (void*)curr->value);
    prev = curr;
    curr = curr->next;
    if((prev->key)!=((void *)0))
       free((void*)prev->key);
    prev->key = ((void *)0);
    if((prev->value)!=((void *)0))
     free((void*)prev->value);
    prev->value = ((void *)0);
            if(prev!=((void *)0))
               free((void*)prev);
            prev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start!=((void *)0))
  free((void*)themap->start);
 themap->start = ((void *)0);
   if(themap!=((void *)0))
      free((void*)themap);
   themap = ((void *)0);
   *incmap = pnewmap;
   return SUCCESS;
}

canonical_original_code:
int sp_map_rehash(struct map **incmap) {
   struct map *themap = *incmap;
 struct map *pnewmap = ((void *)0);
 struct kvpair *curr = ((void *)0); struct kvpair *prev = ((void *)0);
 struct bucket *bucketptr = ((void *)0);
   enum status code;
 long i = 0;
   pnewmap = (struct map *)malloc(sizeof(map));
   code = create_map(&pnewmap, themap->type, nextprobableprime((themap->bucketsize) * (themap->resize_factor)), themap->resize_factor, themap->load_factor);
 bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    kv_put(&pnewmap, (void *)curr->key, (void *)curr->value);
    prev = curr;
    curr = curr->next;
    if((prev->key)!=((void *)0))
       free((void *)prev->key);
    prev->key = ((void *)0);
    if((prev->value)!=((void *)0))
     free((void *)prev->value);
    prev->value = ((void *)0);
            if(prev!=((void *)0))
               free((void *)prev);
            prev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start!=((void *)0))
  free((void *)themap->start);
 themap->start = ((void *)0);
   if(themap!=((void *)0))
      free((void *)themap);
   themap = ((void *)0);
   *incmap = pnewmap;
   return SUCCESS;
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } **

variable_types: i long


decompiled_code:
__int64 __fastcall sp_kv_put(__int64 *a1, unsigned __int8 *a2, char *a3)
{
double *v4; // r12
__int64 v5; // rbx
__int64 *v6; // r15
__int64 v7; // rbx
_QWORD *v8; // rax
__int64 v9; // rax
bool v10; // sf
unsigned __int64 v11; // rax
double v12; // xmm0_8
__int64 v13; // rax
double v14; // xmm1_8
double v15; // xmm0_8
__int64 result; // rax
__int64 v17; // rdx
_QWORD *v18; // rax
void *v19; // rdi
char *v20; // rax

v4 = (double *)*a1;
v5 = *(_QWORD *)*a1;
v6 = (__int64 *)(v5 + 24 * sp_k_hash(*a1, a2));
v7 = *v6;
if ( *v6 )
{
while ( strcmp(*(const char **)v7, (const char *)a2) )
{
if ( !*(_QWORD *)(v7 + 16) )
{
v18 = sp_createkvpair((char *)a2, a3);
if ( v18 )
{
++*((_QWORD *)v4 + 2);
*(_QWORD *)(v7 + 16) = v18;
result = 1LL;
}
else
{
perror("allocate of kvpair at end of list failed");
result = 0LL;
}
return result;
}
v7 = *(_QWORD *)(v7 + 16);
}
v19 = *(void **)(v7 + 8);
if ( v19 )
free(v19);
v20 = (char *)malloc(9uLL);
*(_QWORD *)(v7 + 8) = v20;
strcpy(v20, a3);
result = 1LL;
}
else
{
v8 = sp_createkvpair((char *)a2, a3);
*v6 = (__int64)v8;
if ( v8 )
{
++*((_QWORD *)v4 + 2);
v9 = *((_QWORD *)v4 + 3);
v10 = v9 + 1 < 0;
v11 = v9 + 1;
*((_QWORD *)v4 + 3) = v11;
if ( v10 )
v12 = (double)(int)(v11 & 1 | (v11 >> 1)) + (double)(int)(v11 & 1 | (v11 >> 1));
else
v12 = (double)(int)v11;
v13 = *((_QWORD *)v4 + 1);
if ( v13 < 0 )
{
v17 = (_QWORD)v4[1] & 1LL | ((unsigned __int64)v13 >> 1);
v14 = (double)(int)v17 + (double)(int)v17;
}
else
{
v14 = (double)(int)v13;
}
v15 = v12 / v14;
v4[5] = v15;
result = 1LL;
if ( v15 > v4[6] )
{
sp_map_rehash(a1);
result = 1LL;
}
}
else
{
perror("new kvpair allocation failed");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, unsigned __int8 *a2, char *a3)
{
double *v4; // r12
__int64 v5; // rbx
__int64 *v6; // r15
__int64 v7; // rbx
_QWORD *v8; // rax
__int64 v9; // rax
bool v10; // sf
unsigned __int64 v11; // rax
double v12; // xmm0_8
__int64 v13; // rax
double v14; // xmm1_8
double v15; // xmm0_8
__int64 result; // rax
__int64 v17; // rdx
_QWORD *v18; // rax
void *v19; // rdi
char *v20; // rax

v4 = (double *)*a1;
v5 = *(_QWORD *)*a1;
v6 = (__int64 *)(v5 + 24 * func1(*a1, a2));
v7 = *v6;
if ( *v6 )
{
while ( strcmp(*(const char **)v7, (const char *)a2) )
{
if ( !*(_QWORD *)(v7 + 16) )
{
v18 = sp_createkvpair((char *)a2, a3);
if ( v18 )
{
++*((_QWORD *)v4 + 2);
*(_QWORD *)(v7 + 16) = v18;
result = 1LL;
}
else
{
perror("allocate of kvpair at end of list failed");
result = 0LL;
}
return result;
}
v7 = *(_QWORD *)(v7 + 16);
}
v19 = *(void **)(v7 + 8);
if ( v19 )
free(v19);
v20 = (char *)malloc(9uLL);
*(_QWORD *)(v7 + 8) = v20;
strcpy(v20, a3);
result = 1LL;
}
else
{
v8 = sp_createkvpair((char *)a2, a3);
*v6 = (__int64)v8;
if ( v8 )
{
++*((_QWORD *)v4 + 2);
v9 = *((_QWORD *)v4 + 3);
v10 = v9 + 1 < 0;
v11 = v9 + 1;
*((_QWORD *)v4 + 3) = v11;
if ( v10 )
v12 = (double)(int)(v11 & 1 | (v11 >> 1)) + (double)(int)(v11 & 1 | (v11 >> 1));
else
v12 = (double)(int)v11;
v13 = *((_QWORD *)v4 + 1);
if ( v13 < 0 )
{
v17 = (_QWORD)v4[1] & 1LL | ((unsigned __int64)v13 >> 1);
v14 = (double)(int)v17 + (double)(int)v17;
}
else
{
v14 = (double)(int)v13;
}
v15 = v12 / v14;
v4[5] = v15;
result = 1LL;
if ( v15 > v4[6] )
{
func7(a1);
result = 1LL;
}
}
else
{
perror("new kvpair allocation failed");
result = 0LL;
}
}
return result;
}

original_code:
int sp_kv_put(map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 bucket *bucketptr;
 char *prev = ((void *)0);
   map *themap = *inmap;
   char* key = (char*)inkey;
   char* value = (char*)invalue;
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = sp_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    sp_map_rehash(inmap);
   }
  }
 }
 else {
  kvpair *entry,*preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
    prev = entry->value;
    if(prev != ((void *)0))
     free((void*)prev);
    prev = ((void *)0);
    entry->value = (char*)malloc(sizeof(value) + 1);
    strcpy(entry->value,value);
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = sp_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int sp_kv_put(struct map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 struct bucket *bucketptr;
 char *prev = ((void *)0);
   struct map *themap = *inmap;
   char *key = (char*)inkey;
   char *value = (char*)invalue;
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = sp_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    sp_map_rehash(inmap);
   }
  }
 }
 else {
  struct kvpair *entry; struct kvpair *preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
    prev = entry->value;
    if(prev != ((void *)0))
     free((void *)prev);
    prev = ((void *)0);
    entry->value = (char *)malloc(sizeof(value) + 1);
    strcpy(entry->value,value);
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = sp_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

variable_types:
inkey
void *

variable_types:
invalue
void *

variable_types:
prev
char *

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } *

variable_types:
key
char *

variable_types:
value
char *


decompiled_code:
__int64 __fastcall si_kv_put(__int64 *a1, unsigned __int8 *a2, __int64 *a3)
{
double *v3; // r12
__int64 v4; // r13
__int64 v5; // rbx
__int64 *v6; // r15
__int64 v7; // rbx
_QWORD *v8; // rax
__int64 v9; // rax
bool v10; // sf
unsigned __int64 v11; // rax
double v12; // xmm0_8
__int64 v13; // rax
double v14; // xmm1_8
double v15; // xmm0_8
__int64 result; // rax
__int64 v17; // rdx
_QWORD *v18; // rax

v3 = (double *)*a1;
v4 = *a3;
v5 = *(_QWORD *)*a1;
v6 = (__int64 *)(v5 + 24 * sp_k_hash(*a1, a2));
v7 = *v6;
if ( *v6 )
{
while ( 1 )
{
if ( !strcmp(*(const char **)v7, (const char *)a2) )
{
**(_QWORD **)(v7 + 8) = v4;
return 1LL;
}
if ( !*(_QWORD *)(v7 + 16) )
break;
v7 = *(_QWORD *)(v7 + 16);
}
v18 = si_createkvpair((char *)a2, v4);
if ( v18 )
{
++*((_QWORD *)v3 + 2);
*(_QWORD *)(v7 + 16) = v18;
result = 1LL;
}
else
{
perror("allocate of kvpair at end of list failed");
result = 0LL;
}
}
else
{
v8 = si_createkvpair((char *)a2, v4);
*v6 = (__int64)v8;
if ( v8 )
{
++*((_QWORD *)v3 + 2);
v9 = *((_QWORD *)v3 + 3);
v10 = v9 + 1 < 0;
v11 = v9 + 1;
*((_QWORD *)v3 + 3) = v11;
if ( v10 )
v12 = (double)(int)(v11 & 1 | (v11 >> 1)) + (double)(int)(v11 & 1 | (v11 >> 1));
else
v12 = (double)(int)v11;
v13 = *((_QWORD *)v3 + 1);
if ( v13 < 0 )
{
v17 = (_QWORD)v3[1] & 1LL | ((unsigned __int64)v13 >> 1);
v14 = (double)(int)v17 + (double)(int)v17;
}
else
{
v14 = (double)(int)v13;
}
v15 = v12 / v14;
v3[5] = v15;
result = 1LL;
if ( v15 > v3[6] )
{
map_rehash(a1);
result = 1LL;
}
}
else
{
perror("new kvpair allocation failed");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, unsigned __int8 *a2, __int64 *a3)
{
double *v3; // r12
__int64 v4; // r13
__int64 v5; // rbx
__int64 *v6; // r15
__int64 v7; // rbx
_QWORD *v8; // rax
__int64 v9; // rax
bool v10; // sf
unsigned __int64 v11; // rax
double v12; // xmm0_8
__int64 v13; // rax
double v14; // xmm1_8
double v15; // xmm0_8
__int64 result; // rax
__int64 v17; // rdx
_QWORD *v18; // rax

v3 = (double *)*a1;
v4 = *a3;
v5 = *(_QWORD *)*a1;
v6 = (__int64 *)(v5 + 24 * func1(*a1, a2));
v7 = *v6;
if ( *v6 )
{
while ( 1 )
{
if ( !strcmp(*(const char **)v7, (const char *)a2) )
{
**(_QWORD **)(v7 + 8) = v4;
return 1LL;
}
if ( !*(_QWORD *)(v7 + 16) )
break;
v7 = *(_QWORD *)(v7 + 16);
}
v18 = si_createkvpair((char *)a2, v4);
if ( v18 )
{
++*((_QWORD *)v3 + 2);
*(_QWORD *)(v7 + 16) = v18;
result = 1LL;
}
else
{
perror("allocate of kvpair at end of list failed");
result = 0LL;
}
}
else
{
v8 = si_createkvpair((char *)a2, v4);
*v6 = (__int64)v8;
if ( v8 )
{
++*((_QWORD *)v3 + 2);
v9 = *((_QWORD *)v3 + 3);
v10 = v9 + 1 < 0;
v11 = v9 + 1;
*((_QWORD *)v3 + 3) = v11;
if ( v10 )
v12 = (double)(int)(v11 & 1 | (v11 >> 1)) + (double)(int)(v11 & 1 | (v11 >> 1));
else
v12 = (double)(int)v11;
v13 = *((_QWORD *)v3 + 1);
if ( v13 < 0 )
{
v17 = (_QWORD)v3[1] & 1LL | ((unsigned __int64)v13 >> 1);
v14 = (double)(int)v17 + (double)(int)v17;
}
else
{
v14 = (double)(int)v13;
}
v15 = v12 / v14;
v3[5] = v15;
result = 1LL;
if ( v15 > v3[6] )
{
map_rehash(a1);
result = 1LL;
}
}
else
{
perror("new kvpair allocation failed");
result = 0LL;
}
}
return result;
}

original_code:
int si_kv_put(map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 bucket *bucketptr;
   map *themap = *inmap;
   char* key = (char*)inkey;
   long value = *((long*)invalue);
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = si_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    map_rehash(inmap);
   }
  }
 }
 else {
  kvpair *entry,*preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
            (*((long*)entry->value)) = value;
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = si_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int si_kv_put(struct map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 struct bucket *bucketptr;
   struct map *themap = *inmap;
   char *key = (char*)inkey;
   long value = *((long*)invalue);
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = si_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    map_rehash(inmap);
   }
  }
 }
 else {
  struct kvpair *entry; struct kvpair *preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
            (*((long *)entry->value)) = value;
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = si_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

variable_types: value long


decompiled_code:
__int64 __fastcall si_kv_get(_QWORD *a1, unsigned __int8 *a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
_QWORD *v6; // rax

v4 = *(_QWORD *)(*a1 + 24 * sp_k_hash((__int64)a1, a2));
if ( v4 )
{
while ( strcmp(*(const char **)v4, (const char *)a2) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_4;
}
v6 = malloc(8uLL);
if ( v6 )
{
*v6 = **(_QWORD **)(v4 + 8);
*a3 = v6;
}
result = 1LL;
}
else
{
LABEL_4:
*a3 = 0LL;
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, unsigned __int8 *a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
_QWORD *v6; // rax

v4 = *(_QWORD *)(*a1 + 24 * func1((__int64)a1, a2));
if ( v4 )
{
while ( strcmp(*(const char **)v4, (const char *)a2) )
{
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
goto LABEL_4;
}
v6 = malloc(8uLL);
if ( v6 )
{
*v6 = **(_QWORD **)(v4 + 8);
*a3 = v6;
}
result = 1LL;
}
else
{
LABEL_4:
*a3 = 0LL;
result = 2LL;
}
return result;
}

original_code:
int si_kv_get(map *themap,void *key,void **value) {
 unsigned long code = 0;
 bucket* buck = ((void *)0);
 kvpair *kvcurr = ((void *)0);
   long *plong = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char*)kvcurr->key),(char*)key) == 0) {
     plong = (void*)malloc(sizeof(long));
         if(plong != ((void *)0)) {
            *plong = *((long*)kvcurr->value);
            *value = (void*)plong;
         }
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

canonical_original_code:
int si_kv_get(struct map *themap, void *key, void **value) {
 unsigned long code = 0;
 struct bucket *buck = ((void *)0);
 struct kvpair *kvcurr = ((void *)0);
   long *plong = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char *)kvcurr->key),(char *)key) == 0) {
     plong = (void *)malloc(sizeof(long));
         if(plong != ((void *)0)) {
            *plong = *((long *)kvcurr->value);
            *value = (void *)plong;
         }
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

variable_types:
key
void *

variable_types:
value
void **

variable_types:
code
unsigned long

variable_types:
plong
long *


FichaEnTurno

repo: joseprous/damas-chinas

decompiled_code:
__int64 __fastcall FichaEnTurno(int a1)
{
int v1; // ecx
__int64 v2; // rax

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( turnos[7 * modo + turno + v2] != a1 )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ecx
__int64 v2; // rax

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( turnos[7 * modo + turno + v2] != a1 )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

original_code:
int FichaEnTurno(int ficha)
{
 int i;
 for (i=0;i<fichasxturno[modo];i++)
 {
  if (ficha == turnos[modo][turno+i]) return 1;
 }
 return 0;
}

variable_types: ficha int

variable_types: i int


DameContrario

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

switch ( a1 )
{
case 2:
result = 3LL;
break;
case 3:
result = 2LL;
break;
case 4:
result = 5LL;
break;
case 5:
result = 4LL;
break;
case 6:
result = 7LL;
break;
case 7:
result = 6LL;
break;
default:
return result;
}
return result;
}

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

switch ( a1 )
{
case 2:
result = 3LL;
break;
case 3:
result = 2LL;
break;
case 4:
result = 5LL;
break;
case 5:
result = 4LL;
break;
case 6:
result = 7LL;
break;
case 7:
result = 6LL;
break;
default:
return result;
}
return result;
}

original_code:
int DameContrario(int ficha)
{
 switch (ficha)
 {
  case 2: return 3;
  case 3: return 2;
  case 4: return 5;
  case 5: return 4;
  case 7: return 6;
  case 6: return 7;
 }
}


ComerFicha

decompiled_code:
void __fastcall ComerFicha(int a1, int a2)
{
int v2; // er12

if ( comer )
{
v2 = tablero[13 * a1 + a2];
if ( !(unsigned int)FichaEnTurno(v2) )
{
++fichas_comidas[v2 - 2];
tablero[13 * a1 + a2] = 1;
++puntajes[turno];
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
int v2; // er12

if ( comer )
{
v2 = tablero[13 * a1 + a2];
if ( !(unsigned int)func0(v2) )
{
++fichas_comidas[v2 - 2];
tablero[13 * a1 + a2] = 1;
++puntajes[turno];
}
}
}

original_code:
void ComerFicha(int m,int n)
{
 if (!comer){return;}
 if (FichaEnTurno(tablero[m][n])){return;}
 fichas_comidas[(tablero[m][n]-2)]++;
 tablero[m][n] = 1;
 puntajes[turno]++;
}

canonical_original_code:
void ComerFicha(int m, int n)
{
 if (!comer){return;}
 if (FichaEnTurno(tablero[m][n])){return;}
 fichas_comidas[(tablero[m][n]-2)]++;
 tablero[m][n] = 1;
 puntajes[turno]++;
}

variable_types: m int

variable_types: n int

return_type: void


MovidaValida

decompiled_code:
__int64 __fastcall MovidaValida(int a1, int a2, unsigned int a3, unsigned int a4, int a5)
{
__int64 result; // rax
int v6; // er9
int v7; // er10
int v8; // ebx
int v9; // er11
bool v10; // dl
int v11; // ebp
int v12; // ebp

if ( a3 > 0x10 || a4 > 0xC )
return 0LL;
result = (unsigned int)tablero[13 * a3 + a4];
if ( (_DWORD)result != 1 )
return 0LL;
v6 = a3 - a1;
v7 = a4 - a2;
if ( a3 != a1 )
v6 = ((int)(a3 - a1) >> 31) | 1;
if ( v7 )
v7 = (v7 >> 31) | 1;
v8 = -1;
if ( (a1 & 1) == 0 )
v8 = 1;
v9 = a1 + 2 * v6;
if ( v6 )
{
if ( v9 == a3 && v7 + a2 == a4 )
{
if ( v7 )
{
v11 = a2 + (v8 + 1) / 2 - 1 + (v7 + 1) / 2;
if ( tablero[13 * (v9 - v6) + v11] > 1 )
{
result = 2LL;
if ( !a5 )
{
ComerFicha(v9 - v6, v11);
result = 2LL;
}
return result;
}
}
}
}
if ( a3 != a1 )
{
v10 = v9 - v6 == a3;
if ( a4 == a2 && v10 )
return result;
LABEL_15:
result = 0LL;
if ( v10 )
result = v8 + a2 == a4;
return result;
}
v12 = a2 + 2 * v7;
if ( v12 == a4 && tablero[13 * a1 + a4 - v7] > 1 )
{
result = 2LL;
if ( !a5 )
{
ComerFicha(a1, a4 - v7);
result = 2LL;
}
}
else
{
v10 = v9 - v6 == a3;
if ( (a4 != a2 || !v10) && v12 - v7 != a4 )
goto LABEL_15;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, unsigned int a3, unsigned int a4, int a5)
{
__int64 result; // rax
int v6; // er9
int v7; // er10
int v8; // ebx
int v9; // er11
bool v10; // dl
int v11; // ebp
int v12; // ebp

if ( a3 > 0x10 || a4 > 0xC )
return 0LL;
result = (unsigned int)tablero[13 * a3 + a4];
if ( (_DWORD)result != 1 )
return 0LL;
v6 = a3 - a1;
v7 = a4 - a2;
if ( a3 != a1 )
v6 = ((int)(a3 - a1) >> 31) | 1;
if ( v7 )
v7 = (v7 >> 31) | 1;
v8 = -1;
if ( (a1 & 1) == 0 )
v8 = 1;
v9 = a1 + 2 * v6;
if ( v6 )
{
if ( v9 == a3 && v7 + a2 == a4 )
{
if ( v7 )
{
v11 = a2 + (v8 + 1) / 2 - 1 + (v7 + 1) / 2;
if ( tablero[13 * (v9 - v6) + v11] > 1 )
{
result = 2LL;
if ( !a5 )
{
func2(v9 - v6, v11);
result = 2LL;
}
return result;
}
}
}
}
if ( a3 != a1 )
{
v10 = v9 - v6 == a3;
if ( a4 == a2 && v10 )
return result;
LABEL_15:
result = 0LL;
if ( v10 )
result = v8 + a2 == a4;
return result;
}
v12 = a2 + 2 * v7;
if ( v12 == a4 && tablero[13 * a1 + a4 - v7] > 1 )
{
result = 2LL;
if ( !a5 )
{
func2(a1, a4 - v7);
result = 2LL;
}
}
else
{
v10 = v9 - v6 == a3;
if ( (a4 != a2 || !v10) && v12 - v7 != a4 )
goto LABEL_15;
}
return result;
}

original_code:
int MovidaValida(int m0, int n0, int m1, int n1,int mirar)
{
 if ( (m1 < 0 || m1 > 16) || (n1 < 0 || n1 > 12)) {return 0;}
 if (tablero[m1][n1]!=1) {return 0;}
 int rest_m = (m1-m0);
 int rest_n = (n1-n0);
 int dist_m = abs(rest_m);
 int dist_n = abs(rest_n);
 int sent_m = (rest_m) ? (rest_m)/dist_m : 0 ;
 int sent_n = (rest_n) ? (rest_n)/dist_n : 0;
 int paridad = (m0%2==0) ? 1 : -1;
 if( (m0+(2*sent_m)==m1 && sent_m!=0 ) && (n0+(sent_n)==n1 && sent_n!=0))
 {
  if (tablero[m0+(sent_m)][n0-1+((paridad+1)/2)+((sent_n+1)/2)]>1)
  {
   if (!mirar){ComerFicha(m0+(sent_m),n0-1+((paridad+1)/2)+((sent_n+1)/2));}
   return 2;
  }
 }
 if( m0==m1 && (n0+(2*sent_n)==n1 && tablero[m0][n0+(sent_n)]>1) )
 {
  if(!mirar){ComerFicha(m0,n0+(sent_n));}
  return 2;
 }
 if( m0+(sent_m)==m1 && n0==n1 ) {return 1;}
 if( m0==m1 && n0+(sent_n)==n1 ) {return 1;}
 if( m0+(sent_m) == m1 && n0+paridad == n1 ) {return 1;}
 return 0;
}

canonical_original_code:
int MovidaValida(int m0, int n0, int m1, int n1, int mirar)
{
 if ( (m1 < 0 || m1 > 16) || (n1 < 0 || n1 > 12)) {return 0;}
 if (tablero[m1][n1]!=1) {return 0;}
 int rest_m = (m1-m0);
 int rest_n = (n1-n0);
 int dist_m = abs(rest_m);
 int dist_n = abs(rest_n);
 int sent_m = (rest_m) ? (rest_m)/dist_m : 0;
 int sent_n = (rest_n) ? (rest_n)/dist_n : 0;
 int paridad = (m0%2==0) ? 1 : -1;
 if( (m0+(2*sent_m)==m1 && sent_m!=0 ) && (n0+(sent_n)==n1 && sent_n!=0))
 {
  if (tablero[m0+(sent_m)][n0-1+((paridad+1)/2)+((sent_n+1)/2)]>1)
  {
   if (!mirar){ComerFicha(m0+(sent_m),n0-1+((paridad+1)/2)+((sent_n+1)/2));}
   return 2;
  }
 }
 if( m0==m1 && (n0+(2*sent_n)==n1 && tablero[m0][n0+(sent_n)]>1) )
 {
  if(!mirar){ComerFicha(m0,n0+(sent_n));}
  return 2;
 }
 if( m0+(sent_m)==m1 && n0==n1 ) {return 1;}
 if( m0==m1 && n0+(sent_n)==n1 ) {return 1;}
 if( m0+(sent_m) == m1 && n0+paridad == n1 ) {return 1;}
 return 0;
}

variable_types: mirar int

variable_types: paridad int


TotalFichasTurno

decompiled_code:
__int64 __fastcall TotalFichasTurno(int a1)
{
int v2; // edi
__int64 v3; // rdx
unsigned int v4; // ecx

v2 = fichasxturno[modo];
if ( v2 <= 0 )
return 0;
v3 = 0LL;
v4 = 0;
do
v4 += 10 - fichas_comidas[turnos[7 * modo + a1 + v3++] - 2];
while ( v2 > (int)v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v2; // edi
__int64 v3; // rdx
unsigned int v4; // ecx

v2 = fichasxturno[modo];
if ( v2 <= 0 )
return 0;
v3 = 0LL;
v4 = 0;
do
v4 += 10 - fichas_comidas[turnos[7 * modo + a1 + v3++] - 2];
while ( v2 > (int)v3 );
return v4;
}

original_code:
int TotalFichasTurno(int algunturno)
{
 int i,total;
 total = 0;
 for(i=0;i<fichasxturno[modo];i++)
 {
  total+= (10 -fichas_comidas[(turnos[modo][algunturno+i]-2)]);
 }
 return total;
}

canonical_original_code:
int TotalFichasTurno(int algunturno)
{
 int i; int total;
 total = 0;
 for(i=0;i<fichasxturno[modo];i++)
 {
  total+= (10 -fichas_comidas[(turnos[modo][algunturno+i]-2)]);
 }
 return total;
}

variable_types: algunturno int

variable_types: total int


TurnoSobreviviente

decompiled_code:
__int64 TurnoSobreviviente()
{
int v0; // er13
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r12

if ( !turnos[7 * modo] )
return 1LL;
v0 = turno;
v1 = 0;
v2 = modo;
v3 = 7LL * modo;
do
{
if ( v0 != v1 && (unsigned int)TotalFichasTurno(v1) )
return 0LL;
v1 += fichasxturno[v2];
}
while ( turnos[v3 + v1] );
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // er13
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r12

if ( !turnos[7 * modo] )
return 1LL;
v0 = turno;
v1 = 0;
v2 = modo;
v3 = 7LL * modo;
do
{
if ( v0 != v1 && (unsigned int)func4(v1) )
return 0LL;
v1 += fichasxturno[v2];
}
while ( turnos[v3 + v1] );
return 1LL;
}

original_code:
int TurnoSobreviviente()
{
 int i;
 for(i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
   if(i!=turno && TotalFichasTurno(i)){return 0;}
 }
 return 1;
}


FichasEnBase

decompiled_code:
__int64 __fastcall FichasEnBase(int a1)
{
__int64 v2; // rdi
char *v3; // rax
char *v4; // rdi
unsigned int v5; // er8

v2 = 80LL * (int)(DameContrario(a1) - 2);
v3 = (char *)&iniciales + v2;
v4 = (char *)&iniciales + v2 + 80;
v5 = 0;
do
{
if ( tablero[13 * *(int *)v3 + *((int *)v3 + 1)] == a1 )
++v5;
v3 += 8;
}
while ( v3 != v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v2; // rdi
char *v3; // rax
char *v4; // rdi
unsigned int v5; // er8

v2 = 80LL * (int)(func1(a1) - 2);
v3 = (char *)&iniciales + v2;
v4 = (char *)&iniciales + v2 + 80;
v5 = 0;
do
{
if ( tablero[13 * *(int *)v3 + *((int *)v3 + 1)] == a1 )
++v5;
v3 += 8;
}
while ( v3 != v4 );
return v5;
}

original_code:
int FichasEnBase(int ficha)
{
 int i,j,cont;
 cont = 0;
 i = (DameContrario(ficha)-2);
 for (j=0;j<20;j+=2)
 {
  if (tablero[iniciales[i][j]][iniciales[i][j+1]] == ficha){cont++;}
 }
 return cont;
}

canonical_original_code:
int FichasEnBase(int ficha)
{
 int i; int j; int cont;
 cont = 0;
 i = (DameContrario(ficha)-2);
 for (j=0;j<20;j+=2)
 {
  if (tablero[iniciales[i][j]][iniciales[i][j+1]] == ficha){cont++;}
 }
 return cont;
}

variable_types: j int

variable_types: cont int


PuntajeTurno

decompiled_code:
__int64 __fastcall PuntajeTurno(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // rbx
int *v4; // r12
int v5; // ebp

v1 = fichasxturno[modo];
if ( v1 <= 0 )
{
v5 = 0;
}
else
{
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
v5 = 0;
do
v5 += FichasEnBase(*v3++);
while ( v3 != v4 );
}
return (unsigned int)(puntajes[a1] + v5);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // rbx
int *v4; // r12
int v5; // ebp

v1 = fichasxturno[modo];
if ( v1 <= 0 )
{
v5 = 0;
}
else
{
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
v5 = 0;
do
v5 += func6(*v3++);
while ( v3 != v4 );
}
return (unsigned int)(puntajes[a1] + v5);
}

original_code:
int PuntajeTurno(int algunturno)
{
 int i,acumulado;
 acumulado = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  acumulado+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return (puntajes[algunturno]+acumulado);
}

canonical_original_code:
int PuntajeTurno(int algunturno)
{
 int i; int acumulado;
 acumulado = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  acumulado+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return (puntajes[algunturno]+acumulado);
}

variable_types: acumulado int


TotalFichasEnBase

decompiled_code:
__int64 __fastcall TotalFichasEnBase(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // rbx
int *v4; // r12
unsigned int v5; // ebp

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0;
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
v5 = 0;
do
v5 += FichasEnBase(*v3++);
while ( v3 != v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // rbx
int *v4; // r12
unsigned int v5; // ebp

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0;
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
v5 = 0;
do
v5 += func6(*v3++);
while ( v3 != v4 );
return v5;
}

original_code:
int TotalFichasEnBase(int algunturno)
{
 int i,fichasenbase = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  fichasenbase+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return fichasenbase;
}

canonical_original_code:
int TotalFichasEnBase(int algunturno)
{
 int i; int fichasenbase = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  fichasenbase+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return fichasenbase;
}

variable_types: fichasenbase int


FinJuego

decompiled_code:
__int64 FinJuego()
{
int v0; // er13
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r12
int v4; // er14
int v5; // eax

if ( !turnos[7 * modo] )
return comer != 0;
v0 = comer;
v1 = 0;
v2 = modo;
v3 = 7LL * modo;
while ( 1 )
{
v4 = TotalFichasTurno(v1);
v5 = TotalFichasEnBase(v1);
if ( !v0 )
break;
if ( v4 != v5 )
return 0LL;
LABEL_4:
v1 += fichasxturno[v2];
if ( !turnos[v3 + v1] )
return comer != 0;
}
if ( v4 != v5 )
goto LABEL_4;
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // er13
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r12
int v4; // er14
int v5; // eax

if ( !turnos[7 * modo] )
return comer != 0;
v0 = comer;
v1 = 0;
v2 = modo;
v3 = 7LL * modo;
while ( 1 )
{
v4 = func4(v1);
v5 = func8(v1);
if ( !v0 )
break;
if ( v4 != v5 )
return 0LL;
LABEL_4:
v1 += fichasxturno[v2];
if ( !turnos[v3 + v1] )
return comer != 0;
}
if ( v4 != v5 )
goto LABEL_4;
return 1LL;
}

original_code:
int FinJuego()
{
 int i,fichasenbase,fichastotal;
 fichasenbase = fichastotal = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  fichastotal = TotalFichasTurno(i);
  fichasenbase = TotalFichasEnBase(i);
  if (comer)
  {
   if (fichasenbase!=fichastotal){return 0;}
  }
  else
  {
   if (fichasenbase==fichastotal)
   {
    return 1;
   }
  }
 }
 if (!comer){return 0;}
 return 1;
}

canonical_original_code:
int FinJuego()
{
 int i; int fichasenbase; int fichastotal;
 fichasenbase = fichastotal = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  fichastotal = TotalFichasTurno(i);
  fichasenbase = TotalFichasEnBase(i);
  if (comer)
  {
   if (fichasenbase!=fichastotal){return 0;}
  }
  else
  {
   if (fichasenbase==fichastotal)
   {
    return 1;
   }
  }
 }
 if (!comer){return 0;}
 return 1;
}

variable_types: fichastotal int


TurnoGanador

decompiled_code:
__int64 TurnoGanador()
{
int v0; // esi
int *v1; // r12
_BOOL4 v2; // er15
int v3; // er14
int v4; // ebp
int v5; // ebx
int v6; // eax
int v8; // [rsp+Ch] [rbp-34h]

if ( !turnos[7 * modo] )
return 0;
v0 = fichasxturno[modo];
v1 = &turnos[v0 + 8LL * modo - modo];
v8 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
do
{
v5 = PuntajeTurno(v4);
if ( v5 >= v3 && (unsigned int)TotalFichasTurno(v4) )
{
v2 = v5 == v3;
v8 = v4;
v3 = v5;
}
v4 += v0;
v1 += v0;
}
while ( v1[-v0] );
v6 = -1;
if ( !v2 )
v6 = v8;
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // esi
int *v1; // r12
_BOOL4 v2; // er15
int v3; // er14
int v4; // ebp
int v5; // ebx
int v6; // eax
int v8; // [rsp+Ch] [rbp-34h]

if ( !turnos[7 * modo] )
return 0;
v0 = fichasxturno[modo];
v1 = &turnos[v0 + 8LL * modo - modo];
v8 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
do
{
v5 = func7(v4);
if ( v5 >= v3 && (unsigned int)func4(v4) )
{
v2 = v5 == v3;
v8 = v4;
v3 = v5;
}
v4 += v0;
v1 += v0;
}
while ( v1[-v0] );
v6 = -1;
if ( !v2 )
v6 = v8;
return (unsigned int)v6;
}

original_code:
int TurnoGanador()
{
 int i,mayorpuntaje,mayorturno,empate,puntaje;
 empate = 0;
 mayorpuntaje = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  puntaje = PuntajeTurno(i);
  if (puntaje>=mayorpuntaje && TotalFichasTurno(i)!=0)
  {
   if (puntaje==mayorpuntaje){empate = 1;}else{empate=0;}
   mayorturno = i;
   mayorpuntaje = puntaje;
  }
 }
 if(empate) {return -1;}
 return mayorturno;
}

canonical_original_code:
int TurnoGanador()
{
 int i; int mayorpuntaje; int mayorturno; int empate; int puntaje;
 empate = 0;
 mayorpuntaje = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  puntaje = PuntajeTurno(i);
  if (puntaje>=mayorpuntaje && TotalFichasTurno(i)!=0)
  {
   if (puntaje==mayorpuntaje){empate = 1;}else{empate=0;}
   mayorturno = i;
   mayorpuntaje = puntaje;
  }
 }
 if(empate) {return -1;}
 return mayorturno;
}

variable_types: mayorpuntaje int

variable_types: mayorturno int

variable_types: empate int

variable_types: puntaje int


SigueJugando

decompiled_code:
_BOOL8 __fastcall SigueJugando(unsigned int a1, int a2)
{
int v2; // edx
_BOOL8 result; // rax
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx

v2 = MovidaValida(a1, a2, a1 - 2, a2 + 1, 1);
result = 1LL;
if ( !v2 )
{
v4 = MovidaValida(a1, a2, a1 - 2, a2 - 1, 1);
result = 1LL;
if ( !v4 )
{
v5 = MovidaValida(a1, a2, a1, a2 - 2, 1);
result = 1LL;
if ( !v5 )
{
v6 = MovidaValida(a1, a2, a1, a2 + 2, 1);
result = 1LL;
if ( !v6 )
{
v7 = MovidaValida(a1, a2, a1 + 2, a2 - 1, 1);
result = 1LL;
if ( !v7 )
result = (unsigned int)MovidaValida(a1, a2, a1 + 2, a2 + 1, 1) != 0;
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(unsigned int a1, int a2)
{
int v2; // edx
_BOOL8 result; // rax
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx

v2 = func3(a1, a2, a1 - 2, a2 + 1, 1);
result = 1LL;
if ( !v2 )
{
v4 = func3(a1, a2, a1 - 2, a2 - 1, 1);
result = 1LL;
if ( !v4 )
{
v5 = func3(a1, a2, a1, a2 - 2, 1);
result = 1LL;
if ( !v5 )
{
v6 = func3(a1, a2, a1, a2 + 2, 1);
result = 1LL;
if ( !v6 )
{
v7 = func3(a1, a2, a1 + 2, a2 - 1, 1);
result = 1LL;
if ( !v7 )
result = (unsigned int)func3(a1, a2, a1 + 2, a2 + 1, 1) != 0;
}
}
}
}
return result;
}

original_code:
int SigueJugando(int m,int n)
{
 if (MovidaValida(m,n,m-2,n+1,1)) return 1;
 if (MovidaValida(m,n,m-2,n-1,1)) return 1;
 if (MovidaValida(m,n,m,n-2,1)) return 1;
 if (MovidaValida(m,n,m,n+2,1)) return 1;
 if (MovidaValida(m,n,m+2,n-1,1)) return 1;
 if (MovidaValida(m,n,m+2,n+1,1)) return 1;
 return 0;
}

canonical_original_code:
int SigueJugando(int m, int n)
{
 if (MovidaValida(m,n,m-2,n+1,1)) return 1;
 if (MovidaValida(m,n,m-2,n-1,1)) return 1;
 if (MovidaValida(m,n,m,n-2,1)) return 1;
 if (MovidaValida(m,n,m,n+2,1)) return 1;
 if (MovidaValida(m,n,m+2,n-1,1)) return 1;
 if (MovidaValida(m,n,m+2,n+1,1)) return 1;
 return 0;
}


SiguienteTurno

decompiled_code:
__int64 SiguienteTurno()
{
int v0; // er12
__int64 v1; // rbp
int v2; // er13
int v3; // ebx
__int64 result; // rax

v0 = fichasxturno[modo];
v1 = 7LL * modo;
while ( 1 )
{
turno += v0;
if ( !turnos[v1 + turno] )
turno = 0;
v2 = turno;
v3 = TotalFichasTurno(turno);
if ( v3 )
{
result = TotalFichasEnBase(v2);
if ( (_DWORD)result != v3 )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // er12
__int64 v1; // rbp
int v2; // er13
int v3; // ebx
__int64 result; // rax

v0 = fichasxturno[modo];
v1 = 7LL * modo;
while ( 1 )
{
turno += v0;
if ( !turnos[v1 + turno] )
turno = 0;
v2 = turno;
v3 = func4(turno);
if ( v3 )
{
result = func8(v2);
if ( (_DWORD)result != v3 )
break;
}
}
return result;
}

original_code:
void SiguienteTurno()
{
 int totalfichasturno = 0;
 do
 {
  if (turnos[modo][turno+=fichasxturno[modo]] == 0){turno = 0;}
  totalfichasturno = TotalFichasTurno(turno);
 }
 while((totalfichasturno==0)||(totalfichasturno==TotalFichasEnBase(turno)));
}

variable_types: totalfichasturno int


PintarTablero

decompiled_code:
int *__fastcall PintarTablero(int a1)
{
__int64 v2; // rdi
int *result; // rax
char *v4; // rdi

v2 = 80LL * (a1 - 2);
result = (int *)((char *)&iniciales + v2);
v4 = (char *)&iniciales + v2 + 80;
do
{
tablero[13 * *result + result[1]] = a1;
result += 2;
}
while ( result != (int *)v4 );
return result;
}

canonical_decompiled_code:
int *__fastcall func13(int a1)
{
__int64 v2; // rdi
int *result; // rax
char *v4; // rdi

v2 = 80LL * (a1 - 2);
result = (int *)((char *)&iniciales + v2);
v4 = (char *)&iniciales + v2 + 80;
do
{
tablero[13 * *result + result[1]] = a1;
result += 2;
}
while ( result != (int *)v4 );
return result;
}

original_code:
void PintarTablero(int ficha)
{
 int i,j;
 i = (ficha-2);
 for (j=0;j<(10*2);j+=2)
 {
  tablero[iniciales[i][j]][iniciales[i][j+1]] = ficha;
 }
}

canonical_original_code:
void PintarTablero(int ficha)
{
 int i; int j;
 i = (ficha-2);
 for (j=0;j<(10*2);j+=2)
 {
  tablero[iniciales[i][j]][iniciales[i][j+1]] = ficha;
 }
}

variable_types: ficha int

variable_types: i int


InicializarTablero

decompiled_code:
__int64 InicializarTablero()
{
__int64 result; // rax
int v1; // edi
int v2; // ebx

result = 7LL * modo;
v1 = turnos[7 * modo];
if ( v1 )
{
v2 = 0;
do
{
PintarTablero(v1);
result = ++v2 + 8LL * modo - modo;
v1 = turnos[result];
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
int v1; // edi
int v2; // ebx

result = 7LL * modo;
v1 = turnos[7 * modo];
if ( v1 )
{
v2 = 0;
do
{
func13(v1);
result = ++v2 + 8LL * modo - modo;
v1 = turnos[result];
}
while ( v1 );
}
return result;
}

original_code:
void InicializarTablero()
{
 int i = 0;
 while(turnos[modo][i]!=0)
 {
  PintarTablero(turnos[modo][i]);
  i++;
 }
}


CreateGrid

repo: joseprous/kianagy

decompiled_code:
int __fastcall CreateGrid(__int64 a1, unsigned int a2)
{
unsigned int v3; // ecx
__int64 v4; // rbx
unsigned int v5; // ebp
__int64 v6; // rsi

LODWORD(start) = (int)*(double *)a1;
HIDWORD(start) = (int)*(double *)(a1 + 8);
v3 = (int)*(double *)(a1 + 16);
*((_DWORD *)&start + 2) = v3;
object = CreateWorldObject(size, *((unsigned int *)&size + 2), start, v3);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
if ( v4 )
{
v5 = 0;
do
{
BrushToGrid(*(_QWORD *)(v4 + 16), object, a2);
v4 = *(_QWORD *)(v4 + 24);
v6 = v5++;
printf("%d...\n", v6);
}
while ( v4 );
}
else
{
v5 = 0;
}
return printf("Brushes = %d\n", v5);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v3; // ecx
__int64 v4; // rbx
unsigned int v5; // ebp
__int64 v6; // rsi

LODWORD(start) = (int)*(double *)a1;
HIDWORD(start) = (int)*(double *)(a1 + 8);
v3 = (int)*(double *)(a1 + 16);
*((_DWORD *)&start + 2) = v3;
object = CreateWorldObject(size, *((unsigned int *)&size + 2), start, v3);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
if ( v4 )
{
v5 = 0;
do
{
BrushToGrid(*(_QWORD *)(v4 + 16), object, a2);
v4 = *(_QWORD *)(v4 + 24);
v6 = v5++;
printf("%d...\n", v6);
}
while ( v4 );
}
else
{
v5 = 0;
}
return printf("Brushes = %d\n", v5);
}

original_code:
void CreateGrid(struct map *m,int mode)
{
 int i;
 struct brushlist *bl;
 start.x = m->start.x;
 start.y = m->start.y;
 start.z = m->start.z;
 object = CreateWorldObject(size,start);
 i=0;
 bl=m->entities->ent.brushes;
 while(bl)
 {
  BrushToGrid(bl->bsh,object,mode);
  bl=bl->next;
  printf("%d...\n",i++);
 }
 printf("Brushes = %d\n",i);
}

canonical_original_code:
void CreateGrid(struct map *m, int mode)
{
 int i;
 struct brushlist *bl;
 start.x = m->start.x;
 start.y = m->start.y;
 start.z = m->start.z;
 object = CreateWorldObject(size,start);
 i=0;
 bl=m->entities->ent.brushes;
 while(bl)
 {
  BrushToGrid(bl->bsh,object,mode);
  bl=bl->next;
  printf("%d...\n",i++);
 }
 printf("Brushes = %d\n",i);
}

variable_types: struct map { struct vector { double x; } start; struct entitylist { struct entity { struct headerlist { char *str1; struct headerlist *next; } *header; struct brushlist { int used; struct rawbrush { int num; struct points { struct vector p[3]; } *planes; struct texture { char *name; } *textures; } *rbsh; struct brush { unsigned long draw; int num; struct poly { int num; struct vector *vertexes; struct vector center; struct vector normal; struct texture tex; } *polys; } *bsh; struct brushlist *next; } *brushes; } ent; struct entitylist *next; } *entities; } *

variable_types: mode int

variable_types: struct brushlist { int used; struct rawbrush { int num; struct points { struct vector { double x; } p[3]; } *planes; struct texture { char *name; } *textures; } *rbsh; struct brush { unsigned long draw; int num; struct poly { int num; struct vector *vertexes; struct vector center; struct vector normal; struct texture tex; } *polys; } *bsh; struct brushlist *next; } *

user_defined_types: struct map { struct vector start; struct entitylist *entities; }

user_defined_types: struct brushlist { int used; struct rawbrush *rbsh; struct brush *bsh; struct brushlist *next; }

user_defined_types: struct entitylist { struct entity ent; struct entitylist *next; }

user_defined_types: struct rawbrush { int num; struct points *planes; struct texture *textures; }

user_defined_types: struct brush { unsigned long draw; int num; struct poly *polys; }

user_defined_types: struct entity { struct headerlist *header; struct brushlist *brushes; }


main

canonical_name: main

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

if ( argc == 7 )
{
LODWORD(size) = atoi(argv[3]);
HIDWORD(size) = atoi(argv[4]);
*((_DWORD *)&size + 2) = atoi(argv[5]);
if ( (unsigned int)parsemap(argv[1]) )
{
v4 = atoi(argv[6]);
printf(
"Map has been parsed, size = (%d,%d,%d) on %d mode.\n",
(unsigned int)size,
HIDWORD(size),
*((unsigned int *)&size + 2),
v4);
v5 = atoi(argv[6]);
CreateGrid(currentmap, v5);
ObjectToFile(object, argv[2]);
DestroyWorldObject(object);
}
}
else
{
puts("usage: test <input.map:file> <output.bcf:file> <x:integer> <y:integer> <z:integer> <mode:bin>");
}
return 0;
}

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

if ( argc == 7 )
{
LODWORD(size) = atoi(argv[3]);
HIDWORD(size) = atoi(argv[4]);
*((_DWORD *)&size + 2) = atoi(argv[5]);
if ( (unsigned int)parsemap(argv[1]) )
{
v4 = atoi(argv[6]);
printf(
"Map has been parsed, size = (%d,%d,%d) on %d mode.\n",
(unsigned int)size,
HIDWORD(size),
*((unsigned int *)&size + 2),
v4);
v5 = atoi(argv[6]);
func0(currentmap, v5);
ObjectToFile(object, argv[2]);
DestroyWorldObject(object);
}
}
else
{
puts("usage: test <input.map:file> <output.bcf:file> <x:integer> <y:integer> <z:integer> <mode:bin>");
}
return 0;
}

original_code:
int main(int argc, char** argv)
{
 if(argc!=7){
  printf("usage: test <input.map:file> <output.bcf:file> <x:integer> <y:integer> <z:integer> <mode:bin>\n");
  return 0;
 }
 size.x = atoi(argv[3]);
 size.y = atoi(argv[4]);
 size.z = atoi(argv[5]);
 if(!parsemap(argv[1]))return 0;
 printf("Map has been parsed, size = (%d,%d,%d) on %d mode.\n",size.x,size.y,size.z,atoi(argv[6]));
 CreateGrid(currentmap,atoi(argv[6]));
 ObjectToFile(object,argv[2]);
 DestroyWorldObject(object);
   return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if(argc!=7){
  printf("usage: test <input.map:file> <output.bcf:file> <x:integer> <y:integer> <z:integer> <mode:bin>\n");
  return 0;
 }
 size.x = atoi(argv[3]);
 size.y = atoi(argv[4]);
 size.z = atoi(argv[5]);
 if(!parsemap(argv[1]))return 0;
 printf("Map has been parsed, size = (%d,%d,%d) on %d mode.\n",size.x,size.y,size.z,atoi(argv[6]));
 CreateGrid(currentmap,atoi(argv[6]));
 ObjectToFile(object,argv[2]);
 DestroyWorldObject(object);
   return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 load_weapons()
{
__int64 result; // rax

if ( !(unsigned int)ReadMD2Model("models/pknight/w_sshotgun.md2", &weapons) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_rlauncher.md2", (unsigned int)((_DWORD)&weapons + 120)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/a_grenades.md2", (unsigned int)((_DWORD)&weapons + 240)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_bfg.md2", (unsigned int)((_DWORD)&weapons + 360)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_chaingun.md2", (unsigned int)((_DWORD)&weapons + 480)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_glauncher.md2", (unsigned int)((_DWORD)&weapons + 600)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_hyperblaster.md2", (unsigned int)((_DWORD)&weapons + 720)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_railgun.md2", (unsigned int)((_DWORD)&weapons + 840)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_shotgun.md2", (unsigned int)((_DWORD)&weapons + 960)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_blaster.md2", (unsigned int)((_DWORD)&weapons + 1080)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_grapple.md2", (unsigned int)((_DWORD)&weapons + 1200)) )
exit(1);
result = ReadMD2Model("models/pknight/w_machinegun.md2", (unsigned int)((_DWORD)&weapons + 1320));
if ( !(_DWORD)result )
exit(1);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

if ( !(unsigned int)ReadMD2Model("models/pknight/w_sshotgun.md2", &weapons) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_rlauncher.md2", (unsigned int)((_DWORD)&weapons + 120)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/a_grenades.md2", (unsigned int)((_DWORD)&weapons + 240)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_bfg.md2", (unsigned int)((_DWORD)&weapons + 360)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_chaingun.md2", (unsigned int)((_DWORD)&weapons + 480)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_glauncher.md2", (unsigned int)((_DWORD)&weapons + 600)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_hyperblaster.md2", (unsigned int)((_DWORD)&weapons + 720)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_railgun.md2", (unsigned int)((_DWORD)&weapons + 840)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_shotgun.md2", (unsigned int)((_DWORD)&weapons + 960)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_blaster.md2", (unsigned int)((_DWORD)&weapons + 1080)) )
exit(1);
if ( !(unsigned int)ReadMD2Model("models/pknight/w_grapple.md2", (unsigned int)((_DWORD)&weapons + 1200)) )
exit(1);
result = ReadMD2Model("models/pknight/w_machinegun.md2", (unsigned int)((_DWORD)&weapons + 1320));
if ( !(_DWORD)result )
exit(1);
return result;
}

original_code:
void load_weapons()
{
 if (!ReadMD2Model ("models/pknight/w_sshotgun.md2", &weapons[0])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_rlauncher.md2", &weapons[1])) exit (1);
 if (!ReadMD2Model ("models/pknight/a_grenades.md2", &weapons[2])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_bfg.md2", &weapons[3])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_chaingun.md2", &weapons[4])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_glauncher.md2", &weapons[5])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_hyperblaster.md2", &weapons[6])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_railgun.md2", &weapons[7])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_shotgun.md2", &weapons[8])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_blaster.md2", &weapons[9])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_grapple.md2", &weapons[10])) exit (1);
 if (!ReadMD2Model ("models/pknight/w_machinegun.md2", &weapons[11])) exit (1);
}


decompiled_code:
__int64 load_models()
{
if ( !(unsigned int)ReadMD2Model("models/Ogros.md2", models) )
exit(1);
models[31] = 10;
models[392] = 40;
models[753] = 45;
models[122] = 40;
models[483] = 45;
models[302] = 40;
models[663] = 45;
models[212] = 40;
models[573] = 45;
models[33] = 0;
models[394] = 39;
models[44] = 0;
models[405] = 39;
models[30] = 0;
if ( !(unsigned int)ReadMD2Model("models/pknight/tris.md2", (unsigned int)((_DWORD)models + 6032)) )
exit(1);
models[1539] = 10;
models[1900] = 40;
models[2261] = 45;
models[1630] = 40;
models[1991] = 45;
models[1810] = 40;
models[2171] = 45;
models[1720] = 40;
models[2081] = 45;
models[1541] = 0;
models[1902] = 39;
models[1552] = 46;
models[1913] = 53;
models[1538] = 1;
if ( !(unsigned int)ReadMD2Model("models/Gargoyle.md2", (unsigned int)((_DWORD)models + 3016)) )
exit(1);
models[785] = 30;
models[794] = 20;
models[1155] = 34;
models[784] = 0;
return load_weapons();
}

canonical_decompiled_code:
__int64 func1()
{
if ( !(unsigned int)ReadMD2Model("models/Ogros.md2", models) )
exit(1);
models[31] = 10;
models[392] = 40;
models[753] = 45;
models[122] = 40;
models[483] = 45;
models[302] = 40;
models[663] = 45;
models[212] = 40;
models[573] = 45;
models[33] = 0;
models[394] = 39;
models[44] = 0;
models[405] = 39;
models[30] = 0;
if ( !(unsigned int)ReadMD2Model("models/pknight/tris.md2", (unsigned int)((_DWORD)models + 6032)) )
exit(1);
models[1539] = 10;
models[1900] = 40;
models[2261] = 45;
models[1630] = 40;
models[1991] = 45;
models[1810] = 40;
models[2171] = 45;
models[1720] = 40;
models[2081] = 45;
models[1541] = 0;
models[1902] = 39;
models[1552] = 46;
models[1913] = 53;
models[1538] = 1;
if ( !(unsigned int)ReadMD2Model("models/Gargoyle.md2", (unsigned int)((_DWORD)models + 3016)) )
exit(1);
models[785] = 30;
models[794] = 20;
models[1155] = 34;
models[784] = 0;
return func0();
}

original_code:
void load_models()
{
 if (!ReadMD2Model ("models/Ogros.md2", &models[0].md2file)) exit (1);
 models[0].fps=10;
 models[0].iniframes[360]=40;
 models[0].endframes[360]=45;
 models[0].iniframes[90]=40;
 models[0].endframes[90]=45;
 models[0].iniframes[270]=40;
 models[0].endframes[270]=45;
 models[0].iniframes[180]=40;
 models[0].endframes[180]=45;
 models[0].iniframes[1]=0;
 models[0].endframes[1]=39;
 models[0].iniframes[12]=0;
 models[0].endframes[12]=39;
 models[0].hasweapon=0;
 if (!ReadMD2Model ("models/pknight/tris.md2", &models[2].md2file)) exit (1);
 models[2].fps=10;
 models[2].iniframes[360]=40;
 models[2].endframes[360]=45;
 models[2].iniframes[90]=40;
 models[2].endframes[90]=45;
 models[2].iniframes[270]=40;
 models[2].endframes[270]=45;
 models[2].iniframes[180]=40;
 models[2].endframes[180]=45;
 models[2].iniframes[1]=0;
 models[2].endframes[1]=39;
 models[2].iniframes[12]=46;
 models[2].endframes[12]=53;
 models[2].hasweapon=1;
 if (!ReadMD2Model ("models/Gargoyle.md2", &models[1].md2file)) exit (1);
 models[1].fps=30;
 models[1].iniframes[8]=20;
 models[1].endframes[8]=34;
 models[1].hasweapon=0;
 load_weapons();
}


drawplayer

decompiled_code:
__int64 __fastcall drawplayer(__int64 a1)
{
__int64 v1; // rax
float v2; // xmm0_4
__int64 v3; // rax

glPushMatrix();
glTranslatef(*(float *)(a1 + 20), *(float *)(a1 + 28), *(float *)(a1 + 24));
glPushMatrix();
glRotatef(*(float *)(a1 + 32), 0.0, 0.0, 1.0);
if ( *(_DWORD *)a1 )
{
glCallList(transport_list);
}
else
{
glTranslatef(0.0, 0.0, 8.0);
glFrontFace(2304LL);
v1 = *(int *)(a1 + 8);
v2 = (curent_time - last_time) * (double)models[754 * v1 + 31] + *(float *)(a1 + 332);
*(float *)(a1 + 332) = v2;
v3 = *(int *)(a1 + 40) + 754 * v1;
Animate((unsigned int)models[v3 + 32], (unsigned int)models[v3 + 393], a1 + 328, a1 + 332);
RenderFrameItpWithGLCmds(
*(unsigned int *)(a1 + 328),
&models[754 * *(int *)(a1 + 8)],
*(float *)(a1 + 332),
*(float *)(a1 + 32));
if ( models[754 * *(int *)(a1 + 8) + 30] )
RenderFrameItpWithGLCmds(
*(unsigned int *)(a1 + 328),
(char *)&weapons + 120 * *(int *)(a1 + 12),
*(float *)(a1 + 332),
*(float *)(a1 + 32));
}
glPopMatrix();
if ( !*(_DWORD *)a1 )
{
glColor3f(0.0, 0.0);
glPushMatrix();
glDisable(2912LL);
glRasterPos3f(0.0, 0.0, 40.0);
glPrint("(%d) %s", *(unsigned int *)(a1 + 16), (const char *)(a1 + 301));
if ( (unsigned int)SDL_GetTicks() <= *(_DWORD *)(a1 + 320) + 10000 )
{
glRasterPos3f(0.0, 0.0, 50.0);
glPrint("%s", (const char *)(a1 + 44));
}
glEnable(2912LL);
glPopMatrix();
}
return glPopMatrix();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
float v2; // xmm0_4
__int64 v3; // rax

glPushMatrix();
glTranslatef(*(float *)(a1 + 20), *(float *)(a1 + 28), *(float *)(a1 + 24));
glPushMatrix();
glRotatef(*(float *)(a1 + 32), 0.0, 0.0, 1.0);
if ( *(_DWORD *)a1 )
{
glCallList(transport_list);
}
else
{
glTranslatef(0.0, 0.0, 8.0);
glFrontFace(2304LL);
v1 = *(int *)(a1 + 8);
v2 = (curent_time - last_time) * (double)models[754 * v1 + 31] + *(float *)(a1 + 332);
*(float *)(a1 + 332) = v2;
v3 = *(int *)(a1 + 40) + 754 * v1;
Animate((unsigned int)models[v3 + 32], (unsigned int)models[v3 + 393], a1 + 328, a1 + 332);
RenderFrameItpWithGLCmds(
*(unsigned int *)(a1 + 328),
&models[754 * *(int *)(a1 + 8)],
*(float *)(a1 + 332),
*(float *)(a1 + 32));
if ( models[754 * *(int *)(a1 + 8) + 30] )
RenderFrameItpWithGLCmds(
*(unsigned int *)(a1 + 328),
(char *)&weapons + 120 * *(int *)(a1 + 12),
*(float *)(a1 + 332),
*(float *)(a1 + 32));
}
glPopMatrix();
if ( !*(_DWORD *)a1 )
{
glColor3f(0.0, 0.0);
glPushMatrix();
glDisable(2912LL);
glRasterPos3f(0.0, 0.0, 40.0);
glPrint("(%d) %s", *(unsigned int *)(a1 + 16), (const char *)(a1 + 301));
if ( (unsigned int)SDL_GetTicks() <= *(_DWORD *)(a1 + 320) + 10000 )
{
glRasterPos3f(0.0, 0.0, 50.0);
glPrint("%s", (const char *)(a1 + 44));
}
glEnable(2912LL);
glPopMatrix();
}
return glPopMatrix();
}

original_code:
void drawplayer(struct player *p)
{
 glPushMatrix();
  glTranslatef(p->x,p->y,p->z);
  glPushMatrix();
   glRotatef(p->dir,0,0,1);
   if(p->tipo==0){
    glTranslatef(0,0,8);
    glFrontFace(0x0900);
    p->interp+=models[p->model].fps * (curent_time - last_time);
    Animate (models[p->model].iniframes[p->acc], models[p->model].endframes[p->acc], &p->n, &p->interp);
    RenderFrameItpWithGLCmds (p->n, p->interp, &models[p->model].md2file,p->dir);
    if(models[p->model].hasweapon){
     RenderFrameItpWithGLCmds (p->n, p->interp, &weapons[p->weapon],p->dir);
    }
   }else{
    glCallList(transport_list);
   }
  glPopMatrix();
  if(p->tipo==0){
   glColor3f(0,0,0);
   glPushMatrix();
    glDisable(0x0B60);
    glRasterPos3f( 0,0, 40 );
    glPrint( "(%d) %s",p->hp,p->name);
    if(SDL_GetTicks()<=p->txt_ini_time+10000){
     glRasterPos3f( 0,0,50);
     glPrint( "%s",p->txt);
    }
    glEnable(0x0B60);
   glPopMatrix();
  }
 glPopMatrix();
}

variable_types: struct player { int tipo; int id; int model; int weapon; int hp; float x; float dir; float vel; int acc; char txt[-1]; char name[-1]; int txt_ini_time; int alive; int n; float interp; struct player *next; } *


drawpj

decompiled_code:
__int64 drawpj()
{
__int64 v0; // rdx
__int64 v1; // rax
float v2; // xmm0_4
__int64 v3; // rax

glPushMatrix();
glTranslatef(*(float *)(pj + 20LL), *(float *)(pj + 28LL), *(float *)(pj + 24LL));
glPushMatrix();
glRotatef(COERCE_FLOAT(pj_ang ^ LC22), 0.0, 0.0, 1.0);
glTranslatef(0.0, 0.0, 8.0);
glFrontFace(2304LL);
v0 = pj;
v1 = *(int *)(pj + 8LL);
v2 = (curent_time - last_time) * (double)models[754 * v1 + 31] + *(float *)(pj + 332LL);
*(float *)(pj + 332LL) = v2;
v3 = *(int *)(v0 + 40) + 754 * v1;
Animate((unsigned int)models[v3 + 32], (unsigned int)models[v3 + 393], v0 + 328, v0 + 332);
RenderFrameItpWithGLCmds(
*(unsigned int *)(pj + 328LL),
&models[754 * *(int *)(pj + 8LL)],
*(float *)(pj + 332LL),
COERCE_FLOAT(pj_ang ^ LC22));
if ( models[754 * *(int *)(pj + 8LL) + 30] )
RenderFrameItpWithGLCmds(
*(unsigned int *)(pj + 328LL),
(char *)&weapons + 120 * *(int *)(pj + 12LL),
*(float *)(pj + 332LL),
COERCE_FLOAT(pj_ang ^ LC22));
glPopMatrix();
glColor3f(0.0, 0.0);
glPushMatrix();
glRasterPos3f(0.0, 0.0, 40.0);
glPrint("(%d) %s", *(unsigned int *)(pj + 16LL), (const char *)(pj + 301LL));
if ( (unsigned int)SDL_GetTicks() <= *(_DWORD *)(pj + 320LL) + 10000 )
{
glRasterPos3f(0.0, 0.0, 50.0);
glPrint("%s", (const char *)(pj + 44LL));
}
glPopMatrix();
return glPopMatrix();
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
__int64 v1; // rax
float v2; // xmm0_4
__int64 v3; // rax

glPushMatrix();
glTranslatef(*(float *)(pj + 20LL), *(float *)(pj + 28LL), *(float *)(pj + 24LL));
glPushMatrix();
glRotatef(COERCE_FLOAT(pj_ang ^ LC22), 0.0, 0.0, 1.0);
glTranslatef(0.0, 0.0, 8.0);
glFrontFace(2304LL);
v0 = pj;
v1 = *(int *)(pj + 8LL);
v2 = (curent_time - last_time) * (double)models[754 * v1 + 31] + *(float *)(pj + 332LL);
*(float *)(pj + 332LL) = v2;
v3 = *(int *)(v0 + 40) + 754 * v1;
Animate((unsigned int)models[v3 + 32], (unsigned int)models[v3 + 393], v0 + 328, v0 + 332);
RenderFrameItpWithGLCmds(
*(unsigned int *)(pj + 328LL),
&models[754 * *(int *)(pj + 8LL)],
*(float *)(pj + 332LL),
COERCE_FLOAT(pj_ang ^ LC22));
if ( models[754 * *(int *)(pj + 8LL) + 30] )
RenderFrameItpWithGLCmds(
*(unsigned int *)(pj + 328LL),
(char *)&weapons + 120 * *(int *)(pj + 12LL),
*(float *)(pj + 332LL),
COERCE_FLOAT(pj_ang ^ LC22));
glPopMatrix();
glColor3f(0.0, 0.0);
glPushMatrix();
glRasterPos3f(0.0, 0.0, 40.0);
glPrint("(%d) %s", *(unsigned int *)(pj + 16LL), (const char *)(pj + 301LL));
if ( (unsigned int)SDL_GetTicks() <= *(_DWORD *)(pj + 320LL) + 10000 )
{
glRasterPos3f(0.0, 0.0, 50.0);
glPrint("%s", (const char *)(pj + 44LL));
}
glPopMatrix();
return glPopMatrix();
}

original_code:
void drawpj()
{
  glPushMatrix();
   glTranslatef(pj->x,pj->y,pj->z);
   glPushMatrix();
    glRotatef(-pj_ang,0,0,1);
    glTranslatef(0,0,8);
    glFrontFace(0x0900);
    pj->interp+=models[pj->model].fps * (curent_time - last_time);
    Animate (models[pj->model].iniframes[pj->acc], models[pj->model].endframes[pj->acc], &pj->n, &pj->interp);
    RenderFrameItpWithGLCmds (pj->n, pj->interp, &models[pj->model].md2file,-pj_ang);
    if(models[pj->model].hasweapon){
     RenderFrameItpWithGLCmds (pj->n, pj->interp, &weapons[pj->weapon],-pj_ang);
    }
   glPopMatrix();
   glColor3f(0,0,0);
   glPushMatrix();
    glRasterPos3f( 0,0, 40);
    glPrint( "(%d) %s",pj->hp,pj->name);
    if(SDL_GetTicks()<=pj->txt_ini_time+10000){
     glRasterPos3f( 0,0, 50 );
     glPrint( "%s",pj->txt);
    }
   glPopMatrix();
  glPopMatrix();
}


salir

decompiled_code:
void __noreturn salir()
{
send_msg(3LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
send_msg(3LL);
exit(0);
}

original_code:
void salir()
{
 send_msg(3);
 exit (0);
}

canonical_original_code:
void salir()
{
 send_msg(3);
 exit (0);
}


otherkeys

decompiled_code:
__int64 otherkeys()
{
_BYTE *v0; // rax
unsigned int v1; // edx

v0 = (_BYTE *)SDL_GetKeyState(0LL);
if ( v0[100] )
{
send_msg(270LL);
v1 = 1;
}
else if ( v0[97] )
{
send_msg(90LL);
v1 = 1;
}
else if ( v0[119] )
{
send_msg(360LL);
v1 = 1;
}
else if ( v0[115] )
{
send_msg(180LL);
v1 = 1;
}
else
{
if ( v0[113] )
{
if ( fly )
{
send_msg(9LL);
return 1;
}
}
else if ( v0[101] && fly )
{
send_msg(10LL);
return 1;
}
v1 = 0;
if ( v0[32] )
{
send_msg(5LL);
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
_BYTE *v0; // rax
unsigned int v1; // edx

v0 = (_BYTE *)SDL_GetKeyState(0LL);
if ( v0[100] )
{
send_msg(270LL);
v1 = 1;
}
else if ( v0[97] )
{
send_msg(90LL);
v1 = 1;
}
else if ( v0[119] )
{
send_msg(360LL);
v1 = 1;
}
else if ( v0[115] )
{
send_msg(180LL);
v1 = 1;
}
else
{
if ( v0[113] )
{
if ( fly )
{
send_msg(9LL);
return 1;
}
}
else if ( v0[101] && fly )
{
send_msg(10LL);
return 1;
}
v1 = 0;
if ( v0[32] )
{
send_msg(5LL);
v1 = 1;
}
}
return v1;
}

original_code:
int otherkeys()
{
 Uint8 * keystate;
 keystate = SDL_GetKeyState(((void *)0));
 if(keystate[SDLK_d]){
  send_msg(270);
  return 1;
 }
 if(keystate[SDLK_a]){
  send_msg(90);
  return 1;
 }
 if(keystate[SDLK_w]){
  send_msg(360);
  return 1;
 }
 if(keystate[SDLK_s]){
  send_msg(180);
  return 1;
 }
 if(keystate[SDLK_q]){
  if(fly){
   send_msg(9);
   return 1;
  }
 }
 if(keystate[SDLK_e]){
  if(fly){
   send_msg(10);
   return 1;
  }
 }
 if(keystate[SDLK_SPACE]){
  send_msg(5);
  return 1;
 }
 return 0;
}

canonical_original_code:
int otherkeys()
{
 unsigned char *keystate;
 keystate = SDL_GetKeyState(((void *)0));
 if(keystate[SDLK_d]){
  send_msg(270);
  return 1;
 }
 if(keystate[SDLK_a]){
  send_msg(90);
  return 1;
 }
 if(keystate[SDLK_w]){
  send_msg(360);
  return 1;
 }
 if(keystate[SDLK_s]){
  send_msg(180);
  return 1;
 }
 if(keystate[SDLK_q]){
  if(fly){
   send_msg(9);
   return 1;
  }
 }
 if(keystate[SDLK_e]){
  if(fly){
   send_msg(10);
   return 1;
  }
 }
 if(keystate[SDLK_SPACE]){
  send_msg(5);
  return 1;
 }
 return 0;
}

variable_types:
keystate
unsigned char *


decompiled_code:
__int64 handle_events()
{
unsigned int v0; // eax
__int16 v1; // bx
char v2; // bp
int v3; // eax
char v4; // al
__m128 v5; // xmm1
__m128 v6; // xmm0
__m128 v7; // xmm0
__int64 result; // rax
unsigned int v9; // ebx

while ( 1 )
{
result = SDL_PollEvent(&event);
if ( !(_DWORD)result )
return result;
switch ( event )
{
case 2:
v0 = *((_DWORD *)&event + 2);
if ( escribiendo )
{
switch ( v0 )
{
case 0xDu:
escribiendo = 0;
send_txt();
pj_txtbuf = 0;
SDL_EnableUNICODE(0LL);
break;
case 0x1Bu:
escribiendo = 0;
pj_txtbuf = 0;
SDL_EnableUNICODE(0LL);
break;
case 8u:
*(&pj_txtbuf + (int)(strlen(&pj_txtbuf) - 1)) = 0;
break;
default:
v1 = *((_WORD *)&event + 8);
if ( (v1 & 0xFF80) == 0 )
{
v2 = *((_WORD *)&event + 8);
if ( (_BYTE)v1 )
{
v3 = strlen(&pj_txtbuf);
if ( (_BYTE)v1 == 59 )
v2 = 44;
*(&pj_txtbuf + v3) = v2;
*(&pj_txtbuf + v3 + 1) = 0;
}
}
break;
}
}
else if ( v0 > 0x77 )
{
if ( v0 == 275 )
{
rotcam(-10.0, 0.0);
}
else if ( v0 == 276 )
{
rotcam(10.0, 0.0);
}
}
else if ( v0 > 0x1A )
{
switch ( v0 )
{
case 0x1Bu:
salir();
return result;
case 0x20u:
send_msg(5LL);
break;
case 0x31u:
send_msg2(12LL, &unk_57C);
break;
case 0x32u:
send_msg2(12LL, &unk_57E);
break;
case 0x61u:
send_msg(90LL);
break;
case 0x63u:
banvf = 0;
break;
case 0x64u:
send_msg(270LL);
break;
case 0x65u:
if ( fly )
send_msg(10LL);
break;
case 0x66u:
if ( fly )
{
send_msg(11LL);
fly = 0;
}
else
{
send_msg(8LL);
fly = 1;
}
break;
case 0x71u:
if ( fly )
send_msg(9LL);
break;
case 0x73u:
send_msg(180LL);
break;
case 0x74u:
escribiendo = 1;
pj_txtbuf = 0;
SDL_EnableUNICODE(1LL);
break;
case 0x77u:
send_msg(360LL);
break;
default:
continue;
}
}
break;
case 3:
if ( !(unsigned int)otherkeys() )
{
*(_DWORD *)(pj + 36LL) = 0;
send_msg(1LL);
}
break;
case 4:
if ( mover == 2 )
{
rotcam((float)*((__int16 *)&event + 4), (float)*((__int16 *)&event + 5));
pj_ang = cam_ang;
v9 = lastmsg + 25;
if ( v9 < (unsigned int)SDL_GetTicks() )
otherkeys();
}
if ( mover == 1 )
rotcam((float)*((__int16 *)&event + 4), (float)*((__int16 *)&event + 5));
break;
case 5:
v4 = *(&event + 2);
if ( v4 == 1 )
{
mover = 1;
}
else if ( v4 == 3 )
{
mover = 2;
cam_ang = pj_ang;
rotcam(0.0, 0.0);
}
break;
case 6:
if ( (*(&event + 2) & 0xFD) == 1 )
{
mover = 0;
if ( !(unsigned int)otherkeys() )
send_msg(1LL);
}
if ( *(&event + 2) == 5 )
{
cam_dist = cam_dist + 10.0;
rotcam(0.0, 0.0);
}
if ( *(&event + 2) == 4 )
{
v5 = (__m128)cam_dist;
v5.m128_f32[0] = cam_dist - 10.0;
v6.m128_f32[0] = cam_dist - 10.0;
v7 = _mm_cmplt_ss(v6, (__m128)(unsigned int)LC1);
cam_dist = _mm_andnot_ps(v7, v5).m128_u32[0] | LC1 & v7.m128_i32[0];
rotcam(0.0, 0.0);
}
break;
case 12:
salir();
return result;
default:
continue;
}
}
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
__int16 v1; // bx
char v2; // bp
int v3; // eax
char v4; // al
__m128 v5; // xmm1
__m128 v6; // xmm0
__m128 v7; // xmm0
__int64 result; // rax
unsigned int v9; // ebx

while ( 1 )
{
result = SDL_PollEvent(&event);
if ( !(_DWORD)result )
return result;
switch ( event )
{
case 2:
v0 = *((_DWORD *)&event + 2);
if ( escribiendo )
{
switch ( v0 )
{
case 0xDu:
escribiendo = 0;
send_txt();
pj_txtbuf = 0;
SDL_EnableUNICODE(0LL);
break;
case 0x1Bu:
escribiendo = 0;
pj_txtbuf = 0;
SDL_EnableUNICODE(0LL);
break;
case 8u:
*(&pj_txtbuf + (int)(strlen(&pj_txtbuf) - 1)) = 0;
break;
default:
v1 = *((_WORD *)&event + 8);
if ( (v1 & 0xFF80) == 0 )
{
v2 = *((_WORD *)&event + 8);
if ( (_BYTE)v1 )
{
v3 = strlen(&pj_txtbuf);
if ( (_BYTE)v1 == 59 )
v2 = 44;
*(&pj_txtbuf + v3) = v2;
*(&pj_txtbuf + v3 + 1) = 0;
}
}
break;
}
}
else if ( v0 > 0x77 )
{
if ( v0 == 275 )
{
rotcam(-10.0, 0.0);
}
else if ( v0 == 276 )
{
rotcam(10.0, 0.0);
}
}
else if ( v0 > 0x1A )
{
switch ( v0 )
{
case 0x1Bu:
func0();
return result;
case 0x20u:
send_msg(5LL);
break;
case 0x31u:
send_msg2(12LL, &unk_57C);
break;
case 0x32u:
send_msg2(12LL, &unk_57E);
break;
case 0x61u:
send_msg(90LL);
break;
case 0x63u:
banvf = 0;
break;
case 0x64u:
send_msg(270LL);
break;
case 0x65u:
if ( fly )
send_msg(10LL);
break;
case 0x66u:
if ( fly )
{
send_msg(11LL);
fly = 0;
}
else
{
send_msg(8LL);
fly = 1;
}
break;
case 0x71u:
if ( fly )
send_msg(9LL);
break;
case 0x73u:
send_msg(180LL);
break;
case 0x74u:
escribiendo = 1;
pj_txtbuf = 0;
SDL_EnableUNICODE(1LL);
break;
case 0x77u:
send_msg(360LL);
break;
default:
continue;
}
}
break;
case 3:
if ( !(unsigned int)func1() )
{
*(_DWORD *)(pj + 36LL) = 0;
send_msg(1LL);
}
break;
case 4:
if ( mover == 2 )
{
rotcam((float)*((__int16 *)&event + 4), (float)*((__int16 *)&event + 5));
pj_ang = cam_ang;
v9 = lastmsg + 25;
if ( v9 < (unsigned int)SDL_GetTicks() )
func1();
}
if ( mover == 1 )
rotcam((float)*((__int16 *)&event + 4), (float)*((__int16 *)&event + 5));
break;
case 5:
v4 = *(&event + 2);
if ( v4 == 1 )
{
mover = 1;
}
else if ( v4 == 3 )
{
mover = 2;
cam_ang = pj_ang;
rotcam(0.0, 0.0);
}
break;
case 6:
if ( (*(&event + 2) & 0xFD) == 1 )
{
mover = 0;
if ( !(unsigned int)func1() )
send_msg(1LL);
}
if ( *(&event + 2) == 5 )
{
cam_dist = cam_dist + 10.0;
rotcam(0.0, 0.0);
}
if ( *(&event + 2) == 4 )
{
v5 = (__m128)cam_dist;
v5.m128_f32[0] = cam_dist - 10.0;
v6.m128_f32[0] = cam_dist - 10.0;
v7 = _mm_cmplt_ss(v6, (__m128)(unsigned int)LC1);
cam_dist = _mm_andnot_ps(v7, v5).m128_u32[0] | LC1 & v7.m128_i32[0];
rotcam(0.0, 0.0);
}
break;
case 12:
func0();
return result;
default:
continue;
}
}
}

original_code:
int handle_events()
{
 while (SDL_PollEvent(&event)){
  SDL_keysym keysym;
  switch (event.type){
   case SDL_KEYDOWN:
    keysym = event.key.keysym;
    if(escribiendo){
     int len;
     switch (keysym.sym) {
      case SDLK_RETURN:
       escribiendo=0;
       send_txt();
       pj_txtbuf[0]=0;
       SDL_EnableUNICODE(0);
       break;
      case SDLK_BACKSPACE:
       len=strlen(pj_txtbuf);
       pj_txtbuf[len-1]=0;
       break;
      case SDLK_ESCAPE:
       escribiendo=0;
       pj_txtbuf[0]=0;
       SDL_EnableUNICODE(0);
       break;
      default:
       if ( (keysym.unicode & 0xFF80) == 0 ) {
        char ch;
        ch = keysym.unicode & 0x7F;
        if(ch){
         len=strlen(pj_txtbuf);
         if(ch==';'){
          pj_txtbuf[len]=',';
         }else{
          pj_txtbuf[len]=ch;
         }
         pj_txtbuf[len+1]=0;
        }
       }else {
       }
       break;
     }
    }else{
     switch (keysym.sym) {
             case SDLK_c:
        banvf=0;
        break;
      case SDLK_d:
       send_msg(270);
       break;
      case SDLK_a:
       send_msg(90);
       break;
      case SDLK_w:
       send_msg(360);
       break;
      case SDLK_s:
       send_msg(180);
       break;
      case SDLK_SPACE:
       send_msg(5);
       break;
      case SDLK_LEFT:
       rotcam(10,0);
       break;
      case SDLK_RIGHT:
       rotcam(-10,0);
       break;
      case SDLK_UP:
       break;
      case SDLK_DOWN:
       break;
      case SDLK_t:
       escribiendo=1;
       pj_txtbuf[0]=0;
       SDL_EnableUNICODE(1);
       break;
      case SDLK_q:
       if(fly) send_msg(9);
       break;
      case SDLK_e:
       if(fly) send_msg(10);
       break;
      case SDLK_1:
       send_msg2(12,"0");
       break;
      case SDLK_2:
       send_msg2(12,"1");
       break;
      case SDLK_f:
       if(fly){
        send_msg(11);
        fly=0;
       }else{
        send_msg(8);
        fly=1;
       }
       break;
      case SDLK_ESCAPE:
       salir();
       break;
     }
    }
    break;
   case SDL_KEYUP:
    if(!otherkeys()){
     pj->vel=0;
     send_msg(1);
    }
    break;
   case SDL_MOUSEBUTTONDOWN:
    if(event.button.button == 1){
     mover=1;
    }
    if(event.button.button == 3){
     mover=2;
     cam_ang=pj_ang;
     rotcam(0,0);
    }
    break;
   case SDL_MOUSEBUTTONUP:
    if(event.button.button == 1 || event.button.button == 3){
     mover=0;
     if(!otherkeys())send_msg(1);
    }
    if(event.button.button == 5){
     cam_dist+=10;
     rotcam(0,0);
    }
    if(event.button.button == 4){
     cam_dist-=10;
     if(cam_dist<10)cam_dist=10;
     rotcam(0,0);
    }
    break;
   case SDL_MOUSEMOTION:
    if(mover==2){
     rotcam(event.motion.xrel,event.motion.yrel);
     pj_ang=cam_ang;
     if(lastmsg+25<SDL_GetTicks()){
      otherkeys();
     }
    }
    if(mover==1){
     rotcam(event.motion.xrel,event.motion.yrel);
    }
    break;
   case SDL_QUIT:
    salir();
    break;
  }
 }
 return 0;
}

canonical_original_code:
int handle_events()
{
 while (SDL_PollEvent(&event)){
  struct SDL_keysym keysym;
  switch (event.type){
   case SDL_KEYDOWN:
    keysym = event.key.keysym;
    if(escribiendo){
     int len;
     switch (keysym.sym) {
      case SDLK_RETURN:
       escribiendo=0;
       send_txt();
       pj_txtbuf[0]=0;
       SDL_EnableUNICODE(0);
       break;
      case SDLK_BACKSPACE:
       len=strlen(pj_txtbuf);
       pj_txtbuf[len-1]=0;
       break;
      case SDLK_ESCAPE:
       escribiendo=0;
       pj_txtbuf[0]=0;
       SDL_EnableUNICODE(0);
       break;
      default:
       if ( (keysym.unicode & 0xFF80) == 0 ) {
        char ch;
        ch = keysym.unicode & 0x7F;
        if(ch){
         len=strlen(pj_txtbuf);
         if(ch==';'){
          pj_txtbuf[len]=',';
         }else{
          pj_txtbuf[len]=ch;
         }
         pj_txtbuf[len+1]=0;
        }
       }else {
       }
       break;
     }
    }else{
     switch (keysym.sym) {
             case SDLK_c:
        banvf=0;
        break;
      case SDLK_d:
       send_msg(270);
       break;
      case SDLK_a:
       send_msg(90);
       break;
      case SDLK_w:
       send_msg(360);
       break;
      case SDLK_s:
       send_msg(180);
       break;
      case SDLK_SPACE:
       send_msg(5);
       break;
      case SDLK_LEFT:
       rotcam(10,0);
       break;
      case SDLK_RIGHT:
       rotcam(-10,0);
       break;
      case SDLK_UP:
       break;
      case SDLK_DOWN:
       break;
      case SDLK_t:
       escribiendo=1;
       pj_txtbuf[0]=0;
       SDL_EnableUNICODE(1);
       break;
      case SDLK_q:
       if(fly) send_msg(9);
       break;
      case SDLK_e:
       if(fly) send_msg(10);
       break;
      case SDLK_1:
       send_msg2(12,"0");
       break;
      case SDLK_2:
       send_msg2(12,"1");
       break;
      case SDLK_f:
       if(fly){
        send_msg(11);
        fly=0;
       }else{
        send_msg(8);
        fly=1;
       }
       break;
      case SDLK_ESCAPE:
       salir();
       break;
     }
    }
    break;
   case SDL_KEYUP:
    if(!otherkeys()){
     pj->vel=0;
     send_msg(1);
    }
    break;
   case SDL_MOUSEBUTTONDOWN:
    if(event.button.button == 1){
     mover=1;
    }
    if(event.button.button == 3){
     mover=2;
     cam_ang=pj_ang;
     rotcam(0,0);
    }
    break;
   case SDL_MOUSEBUTTONUP:
    if(event.button.button == 1 || event.button.button == 3){
     mover=0;
     if(!otherkeys())send_msg(1);
    }
    if(event.button.button == 5){
     cam_dist+=10;
     rotcam(0,0);
    }
    if(event.button.button == 4){
     cam_dist-=10;
     if(cam_dist<10)cam_dist=10;
     rotcam(0,0);
    }
    break;
   case SDL_MOUSEMOTION:
    if(mover==2){
     rotcam(event.motion.xrel,event.motion.yrel);
     pj_ang=cam_ang;
     if(lastmsg+25<SDL_GetTicks()){
      otherkeys();
     }
    }
    if(mover==1){
     rotcam(event.motion.xrel,event.motion.yrel);
    }
    break;
   case SDL_QUIT:
    salir();
    break;
  }
 }
 return 0;
}

variable_types: struct SDL_keysym { unsigned char scancode; enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 } sym; enum SDLMod { KMOD_NONE=0, KMOD_LSHIFT=1, KMOD_RSHIFT=2, KMOD_LCTRL=64, KMOD_RCTRL=128, KMOD_LALT=256, KMOD_RALT=512, KMOD_LMETA=1024, KMOD_RMETA=2048, KMOD_NUM=4096, KMOD_CAPS=8192, KMOD_MODE=16384, KMOD_RESERVED=32768 } mod; unsigned short unicode; }

variable_types: len int

variable_types: ch char

user_defined_types: struct SDL_keysym { unsigned char scancode; enum SDLKey sym; enum SDLMod mod; unsigned short unicode; }


decompiled_code:
__int64 __fastcall send_msg(unsigned int a1)
{
unsigned int v1; // eax
size_t v2; // rax
__int64 result; // rax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = SDL_GetTicks();
if ( lastmsg + 25 >= v1 )
SDL_Delay(v1 - lastmsg + 25);
sprintf(v4, "%d %f ", a1, (float)(360.0 - pj_ang));
v2 = strlen(v4);
if ( send(sockfd, v4, v2, 0) == -1 )
perror("send");
result = SDL_GetTicks();
lastmsg = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned int v1; // eax
size_t v2; // rax
__int64 result; // rax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v1 = SDL_GetTicks();
if ( lastmsg + 25 >= v1 )
SDL_Delay(v1 - lastmsg + 25);
sprintf(v4, "%d %f ", a1, (float)(360.0 - pj_ang));
v2 = strlen(v4);
if ( send(sockfd, v4, v2, 0) == -1 )
perror("send");
result = SDL_GetTicks();
lastmsg = result;
return result;
}

original_code:
void send_msg(int code)
{
 char msg[20];
 Uint32 t=SDL_GetTicks();
 if(lastmsg+25>=t){
  SDL_Delay(t-lastmsg+25);
 }
 sprintf(msg,"%d %f ",code,360-pj_ang);
 if (send(sockfd, msg, strlen(msg), 0) == -1) perror("send");
 lastmsg=SDL_GetTicks();
}

canonical_original_code:
void send_msg(int code)
{
 char msg[20];
 unsigned int t = SDL_GetTicks();
 if(lastmsg+25>=t){
  SDL_Delay(t-lastmsg+25);
 }
 sprintf(msg,"%d %f ",code,360-pj_ang);
 if (send(sockfd, msg, strlen(msg), 0) == -1) perror("send");
 lastmsg=SDL_GetTicks();
}

variable_types: code int

variable_types:
msg
char [20]

variable_types:
t
unsigned int


decompiled_code:
__int64 __fastcall send_msg2(unsigned int a1, const char *a2)
{
unsigned int v2; // eax
size_t v3; // rax
__int64 result; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = SDL_GetTicks();
if ( lastmsg + 25 >= v2 )
SDL_Delay(v2 - lastmsg + 25);
sprintf(v5, "%d %f %s..", a1, (float)(360.0 - pj_ang), a2);
v3 = strlen(v5);
if ( send(sockfd, v5, v3, 0) == -1 )
perror("send");
result = SDL_GetTicks();
lastmsg = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, const char *a2)
{
unsigned int v2; // eax
size_t v3; // rax
__int64 result; // rax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v2 = SDL_GetTicks();
if ( lastmsg + 25 >= v2 )
SDL_Delay(v2 - lastmsg + 25);
sprintf(v5, "%d %f %s..", a1, (float)(360.0 - pj_ang), a2);
v3 = strlen(v5);
if ( send(sockfd, v5, v3, 0) == -1 )
perror("send");
result = SDL_GetTicks();
lastmsg = result;
return result;
}

original_code:
void send_msg2(int code,char *txt)
{
 char msg[20];
 Uint32 t=SDL_GetTicks();
 if(lastmsg+25>=t){
  SDL_Delay(t-lastmsg+25);
 }
 sprintf(msg,"%d %f %s..",code,360-pj_ang,txt);
 if (send(sockfd, msg, strlen(msg), 0) == -1) perror("send");
 lastmsg=SDL_GetTicks();
}

canonical_original_code:
void send_msg2(int code, char *txt)
{
 char msg[20];
 unsigned int t = SDL_GetTicks();
 if(lastmsg+25>=t){
  SDL_Delay(t-lastmsg+25);
 }
 sprintf(msg,"%d %f %s..",code,360-pj_ang,txt);
 if (send(sockfd, msg, strlen(msg), 0) == -1) perror("send");
 lastmsg=SDL_GetTicks();
}

variable_types:
txt
char *