decompiled_code:
__int64 __fastcall free_stack(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int
free_stack(Stack *stack)
{
  free(stack->entries);
  free(stack);
  return 0;
}

canonical_original_code:
int free_stack(struct StackImpl *stack)
{
  free(stack->entries);
  free(stack);
  return 0;
}

variable_types: struct StackImpl { int index; int size; void **entries; } *


repo: shortsnout/misc

original_code:
int
push_stack(Stack *stack, StackEntry entry)
{
  enum { STACK_INC = 16 };
  if (stack->index >= stack->size) {
    stack->entries = realloc(stack->entries,
                             (stack->size += STACK_INC)*sizeof(StackEntry));
    if (stack->entries == ((void *)0)) return (*__errno_location ());
  }
  stack->entries[stack->index++] = entry;
  return 0;
}

canonical_original_code:
int push_stack(struct StackImpl *stack, void *entry)
{
  enum { STACK_INC = 16 };
  if (stack->index >= stack->size) {
    stack->entries = realloc(stack->entries,
                             (stack->size += STACK_INC)*sizeof(StackEntry));
    if (stack->entries == ((void *)0)) return (*__errno_location ());
  }
  stack->entries[stack->index++] = entry;
  return 0;
}

variable_types:
entry
void *

return_type: int

user_defined_types: struct StackImpl { int index; int size; void **entries; }


decompiled_code:
__int64 __fastcall pop_stack(__int64 a1, _QWORD *a2)
{
__int64 v2; // rdx
int v3; // eax

if ( *(int *)a1 <= 0 )
return 14LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v3;
*a2 = *(_QWORD *)(v2 + 8LL * v3);
return 0LL;
}

original_code:
int
pop_stack(Stack *stack, StackEntry *entryP)
{
  if (stack->index <= 0) {
    return 14;
  }
  *entryP = stack->entries[--stack->index];
  return 0;
}

canonical_original_code:
int pop_stack(struct StackImpl *stack, void **entryP)
{
  if (stack->index <= 0) {
    return 14;
  }
  *entryP = stack->entries[--stack->index];
  return 0;
}

variable_types:
entryP
void **


decompiled_code:
__int64 __fastcall size_stack(_DWORD *a1, _DWORD *a2)
{
*a2 = *a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, _DWORD *a2)
{
*a2 = *a1;
return 0LL;
}

original_code:
int
size_stack(const Stack *stack, int *numEntryP)
{
  *numEntryP = stack->index;
  return 0;
}

canonical_original_code:
int size_stack(struct StackImpl *stack, int *numEntryP)
{
  *numEntryP = stack->index;
  return 0;
}

variable_types:
numEntryP
int *


decompiled_code:
__int64 __fastcall peek_stack(__int64 a1, int a2, _QWORD *a3)
{
unsigned int v3; // ecx

if ( a2 < 0 )
return 14;
v3 = 14;
if ( *(_DWORD *)a1 > a2 )
{
*a3 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (*(_DWORD *)a1 - 1 - a2));
v3 = 0;
}
return v3;
}

original_code:
int
peek_stack(const Stack *stack, int index, StackEntry *entryP)
{
  if (index < 0 || index >= stack->index) {
    return 14;
  }
  *entryP = stack->entries[stack->index - 1 - index];
  return 0;
}

canonical_original_code:
int peek_stack(struct StackImpl *stack, int index, void **entryP)
{
  if (index < 0 || index >= stack->index) {
    return 14;
  }
  *entryP = stack->entries[stack->index - 1 - index];
  return 0;
}

variable_types: index int


decompiled_code:
__int64 __fastcall new_matrix(int a1, int a2, _QWORD *a3)
{
_QWORD *v4; // rbx

v4 = malloc(0x10uLL);
v4[1] = malloc(4LL * a2 * a1);
*(_DWORD *)v4 = a1;
*((_DWORD *)v4 + 1) = a2;
*a3 = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, _QWORD *a3)
{
_QWORD *v4; // rbx

v4 = malloc(0x10uLL);
v4[1] = malloc(4LL * a2 * a1);
*(_DWORD *)v4 = a1;
*((_DWORD *)v4 + 1) = a2;
*a3 = v4;
return 0LL;
}

original_code:
int new_matrix(int numRows, int numCols, Matrix **matrix) {
  Matrix *matrixP = (Matrix *)malloc( sizeof(Matrix) );
  matrixP->data = (int *)malloc( numRows * numCols * sizeof(int) );
  if(matrixP == ((void *)0)) {
    return (*__errno_location ());
  }
  matrixP->rows = numRows;
  matrixP->columns = numCols;
  *matrix = matrixP;
  return 0;
}

canonical_original_code:
int new_matrix(int numRows, int numCols, struct MatrixImpl **matrix) {
  struct MatrixImpl *matrixP = (Matrix *)malloc( sizeof(Matrix) );
  matrixP->data = (int *)malloc( numRows * numCols * sizeof(int) );
  if(matrixP == ((void *)0)) {
    return (*__errno_location ());
  }
  matrixP->rows = numRows;
  matrixP->columns = numCols;
  *matrix = matrixP;
  return 0;
}

variable_types: numRows int

variable_types: numCols int

variable_types: struct MatrixImpl { int rows; int columns; int *data; } **


decompiled_code:
__int64 __fastcall free_matrix(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
int free_matrix(Matrix *matrix) {
  free(matrix->data);
  free(matrix);
  return 0;
}

canonical_original_code:
int free_matrix(struct MatrixImpl *matrix) {
  free(matrix->data);
  free(matrix);
  return 0;
}

variable_types: struct MatrixImpl { int rows; int columns; int *data; } *


decompiled_code:
__int64 __fastcall get_matrix_dimensions(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
if ( a2 )
*a2 = *a1;
if ( a3 )
*a3 = a1[1];
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
if ( a2 )
*a2 = *a1;
if ( a3 )
*a3 = a1[1];
return 0LL;
}

original_code:
int get_matrix_dimensions(const Matrix *matrix, int *numRowsP, int *numColsP) {
  if(numRowsP != ((void *)0)) {
    *numRowsP = matrix->rows;
  }
  if(numColsP != ((void *)0)) {
    *numColsP = matrix->columns;
  }
  return 0;
}

canonical_original_code:
int get_matrix_dimensions(struct MatrixImpl *matrix, int *numRowsP, int *numColsP) {
  if(numRowsP != ((void *)0)) {
    *numRowsP = matrix->rows;
  }
  if(numColsP != ((void *)0)) {
    *numColsP = matrix->columns;
  }
  return 0;
}

variable_types:
numRowsP
int *

variable_types:
numColsP
int *

user_defined_types: struct MatrixImpl { int rows; int columns; int *data; }


decompiled_code:
__int64 __fastcall get_matrix_entry(__int64 a1, int a2, int a3, _DWORD *a4)
{
int v4; // er12

v4 = *(_DWORD *)(a1 + 4);
if ( a2 < 0 || v4 <= a2 )
return 44LL;
if ( *(_DWORD *)a1 <= a3 || a3 < 0 )
return 44LL;
if ( !a4 )
a4 = malloc(4uLL);
*a4 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * (a3 + v4 * a2));
return 0LL;
}

original_code:
int get_matrix_entry(const Matrix *matrix, int i, int j, int *value) {
  if(i >= matrix->columns || i < 0) {
    return 44;
  }
  if(j >= matrix->rows || j < 0) {
    return 44;
  }
  if(value == ((void *)0))
      value = (int *)malloc(sizeof(int));
  *value = matrix->data[ i * matrix->columns + j ];
  return 0;
}

canonical_original_code:
int get_matrix_entry(struct MatrixImpl *matrix, int i, int j, int *value) {
  if(i >= matrix->columns || i < 0) {
    return 44;
  }
  if(j >= matrix->rows || j < 0) {
    return 44;
  }
  if(value == ((void *)0))
      value = (int *)malloc(sizeof(int));
  *value = matrix->data[ i * matrix->columns + j ];
  return 0;
}

variable_types: i int

variable_types: j int

variable_types:
value
int *


decompiled_code:
__int64 __fastcall set_matrix_entry(__int64 a1, int a2, int a3, int a4)
{
int v5; // edx

v5 = *(_DWORD *)(a1 + 4);
if ( a2 < 0 || v5 <= a2 )
return 44LL;
if ( *(_DWORD *)a1 <= a3 || a3 < 0 )
return 44LL;
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 4LL * (v5 * a2 + a3)) = a4;
return 0LL;
}

original_code:
int set_matrix_entry(Matrix *matrix, int i, int j, int value) {
  if(i >= matrix->columns || i < 0) {
    return 44;
  }
  if(j >= matrix->rows || j < 0) {
    return 44;
  }
  matrix->data[ i * matrix->columns + j ] = value;
  return 0;
}

canonical_original_code:
int set_matrix_entry(struct MatrixImpl *matrix, int i, int j, int value) {
  if(i >= matrix->columns || i < 0) {
    return 44;
  }
  if(j >= matrix->rows || j < 0) {
    return 44;
  }
  matrix->data[ i * matrix->columns + j ] = value;
  return 0;
}

variable_types: value int


original_code:
int add_matrix(const Matrix *a, const Matrix *b, Matrix *c) {
  if(a->rows != b->rows || a->columns != b->columns) {
    return 22;
  }
  for(int i = 0; i < a->rows * a->columns; ++i) {
    c->data[i] = a->data[i] + b->data[i];
  }
  return 0;
}

canonical_original_code:
int add_matrix(struct MatrixImpl *a, struct MatrixImpl *b, struct MatrixImpl *c) {
  if(a->rows != b->rows || a->columns != b->columns) {
    return 22;
  }
  for(int i = 0; i < a->rows * a->columns; ++i) {
    c->data[i] = a->data[i] + b->data[i];
  }
  return 0;
}

variable_types:
b
struct MatrixImpl *

variable_types:
c
struct MatrixImpl *


original_code:
int multiply_matrix(const Matrix *a, const Matrix *b, Matrix *c) {
  if(a->columns != b->rows) {
    return 22;
  }
  int columns = b->columns, rows = a->rows;
  for (int i = 0; i < rows; ++i) {
    for (int j = 0; j < columns; ++j) {
      c->data[i * columns + j] = 0;
      for (int k = 0; k < columns; ++k) {
        c->data[i * columns + j] += a->data[i * columns + k] * b->data[k * columns + j];
      }
    }
  }
  return 0;
}

canonical_original_code:
int multiply_matrix(struct MatrixImpl *a, struct MatrixImpl *b, struct MatrixImpl *c) {
  if(a->columns != b->rows) {
    return 22;
  }
  int columns = b->columns; int rows = a->rows;
  for (int i = 0; i < rows; ++i) {
    for (int j = 0; j < columns; ++j) {
      c->data[i * columns + j] = 0;
      for (int k = 0; k < columns; ++k) {
        c->data[i * columns + j] += a->data[i * columns + k] * b->data[k * columns + j];
      }
    }
  }
  return 0;
}

variable_types: columns int

variable_types: rows int

variable_types: k int


repo: shouya/bar

decompiled_code:
void __fastcall destroy_blockmap(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void destroy_blockmap(struct blockmap_t* bm) {
  free(bm->buf);
  free(bm);
}

canonical_original_code:
void destroy_blockmap(struct blockmap_t *bm) {
  free(bm->buf);
  free(bm);
}

variable_types: struct blockmap_t { int w; struct block_t { unsigned char occupied; unsigned char shape; unsigned char flags; } *buf; } *

return_type: void

user_defined_types: struct blockmap_t { int w; struct block_t *buf; }


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

result = *(void **)a2;
if ( *(_QWORD *)a1 == *(_QWORD *)a2 )
result = memcpy(*(void **)(a1 + 8), *(const void **)(a2 + 8), 3LL * *(_DWORD *)(a2 + 4) * *(_DWORD *)a2);
return result;
}

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

result = *(void **)a2;
if ( *(_QWORD *)a1 == *(_QWORD *)a2 )
result = memcpy(*(void **)(a1 + 8), *(const void **)(a2 + 8), 3LL * *(_DWORD *)(a2 + 4) * *(_DWORD *)a2);
return result;
}

original_code:
void copy_blockmap(struct blockmap_t* dest, const struct blockmap_t* src) {
  if (dest->w != src->w || dest->h != src->h) return;
  memcpy(dest->buf, src->buf, src->w * src->h * sizeof(struct block_t));
}

canonical_original_code:
void copy_blockmap(struct blockmap_t *dest, struct blockmap_t *src) {
  if (dest->w != src->w || dest->h != src->h) return;
  memcpy(dest->buf, src->buf, src->w * src->h * sizeof(struct block_t));
}

variable_types:
src
struct blockmap_t *

user_defined_types: struct block_t { unsigned char occupied; unsigned char shape; unsigned char flags; }


original_code:
void reset_shapebuf(struct shapebuf_t* sb, int new_shape) {
  int i, j;
  if (new_shape == -1) {
    sb->w = sb->h = 0;
    if (sb->buf) free(sb->buf);
    sb->buf = 0;
    sb->shape = -1;
    return;
  }
  sb->w = g_shps[new_shape].w;
  sb->h = g_shps[new_shape].h;
  if (sb->buf) free(sb->buf);
  sb->buf = calloc(sb->w * sb->h, sizeof(unsigned char));
  sb->x = sb->y = sb->rotate = 0;
  sb->shape = new_shape;
  for (i = 0; i != sb->w; ++i) {
    for (j = 0; j != sb->h; ++j) {
      sb->buf[j*sb->w+i] = g_shps[new_shape].pix[j][i];
    }
  }
}

canonical_original_code:
void reset_shapebuf(struct shapebuf_t *sb, int new_shape) {
  int i; int j;
  if (new_shape == -1) {
    sb->w = sb->h = 0;
    if (sb->buf) free(sb->buf);
    sb->buf = 0;
    sb->shape = -1;
    return;
  }
  sb->w = g_shps[new_shape].w;
  sb->h = g_shps[new_shape].h;
  if (sb->buf) free(sb->buf);
  sb->buf = calloc(sb->w * sb->h, sizeof(unsigned char));
  sb->x = sb->y = sb->rotate = 0;
  sb->shape = new_shape;
  for (i = 0; i != sb->w; ++i) {
    for (j = 0; j != sb->h; ++j) {
      sb->buf[j*sb->w+i] = g_shps[new_shape].pix[j][i];
    }
  }
}

variable_types: struct shapebuf_t { int w; unsigned char *buf; } *


decompiled_code:
int *__fastcall create_shapebuf(int a1)
{
int *v1; // rbx

v1 = (int *)calloc(1uLL, 0x20uLL);
reset_shapebuf(v1, a1);
return v1;
}

canonical_decompiled_code:
int *__fastcall func3(int a1)
{
int *v1; // rbx

v1 = (int *)calloc(1uLL, 0x20uLL);
func2(v1, a1);
return v1;
}

original_code:
struct shapebuf_t* create_shapebuf(int shape) {
  struct shapebuf_t* sb;
  sb = calloc(1, sizeof(struct shapebuf_t));
  reset_shapebuf(sb, shape);
  return sb;
}

canonical_original_code:
struct shapebuf_t *create_shapebuf(int shape) {
  struct shapebuf_t *sb;
  sb = calloc(1, sizeof(struct shapebuf_t));
  reset_shapebuf(sb, shape);
  return sb;
}

variable_types: shape int

return_type: struct shapebuf_t { int w; unsigned char *buf; } *


decompiled_code:
void __fastcall destroy_shapebuf(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void destroy_shapebuf(struct shapebuf_t* sb) {
  free(sb->buf);
  free(sb);
}

canonical_original_code:
void destroy_shapebuf(struct shapebuf_t *sb) {
  free(sb->buf);
  free(sb);
}

user_defined_types: struct shapebuf_t { int w; unsigned char *buf; }


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

result = *a2;
if ( *(const void **)a1 == *a2 )
{
memcpy(*(void **)(a1 + 24), a2[3], *((int *)a2 + 1) * (__int64)*(int *)a2);
*(_DWORD *)a1 = *(_DWORD *)a2;
*(_DWORD *)(a1 + 4) = *((_DWORD *)a2 + 1);
*(_DWORD *)(a1 + 16) = *((_DWORD *)a2 + 4);
*(_DWORD *)(a1 + 20) = *((_DWORD *)a2 + 5);
*(_DWORD *)(a1 + 12) = *((_DWORD *)a2 + 3);
result = (const void *)*((unsigned int *)a2 + 2);
*(_DWORD *)(a1 + 8) = (_DWORD)result;
}
return result;
}

original_code:
void copy_shapebuf(struct shapebuf_t* dest, const struct shapebuf_t* src) {
  if (dest->w != src->w || dest->h != src->h) return;
  memcpy(dest->buf, src->buf, sizeof(unsigned char)* src->w * src->h);
  dest->w=src->w; dest->h=src->h; dest->x=src->x; dest->y=src->y;
  dest->rotate=src->rotate; dest->shape=src->shape;
}

canonical_original_code:
void copy_shapebuf(struct shapebuf_t *dest, struct shapebuf_t *src) {
  if (dest->w != src->w || dest->h != src->h) return;
  memcpy(dest->buf, src->buf, sizeof(unsigned char)* src->w * src->h);
  dest->w=src->w; dest->h=src->h; dest->x=src->x; dest->y=src->y;
  dest->rotate=src->rotate; dest->shape=src->shape;
}

variable_types:
src
struct shapebuf_t *


decompiled_code:
__int64 __fastcall clear_blockmap(__int64 a1)
{
int v1; // ecx
__int64 result; // rax
int v3; // edx

v1 = 0;
if ( *(_DWORD *)a1 )
{
do
{
v3 = 0;
if ( *(_DWORD *)(a1 + 4) )
{
do
{
result = *(_QWORD *)(a1 + 8) + 3LL * (v1 + *(_DWORD *)a1 * v3);
*(_WORD *)result = 0;
*(_BYTE *)(result + 2) = 0;
++v3;
}
while ( *(_DWORD *)(a1 + 4) != v3 );
}
++v1;
}
while ( *(_DWORD *)a1 != v1 );
}
return result;
}

original_code:
void clear_blockmap(struct blockmap_t* bm) {
  int i, j;
  for (i = 0; i != bm->w; ++i) {
    for (j = 0; j != bm->h; ++j) {
      memset(&bm->buf[j*bm->w+i], 0, sizeof(struct block_t));
    }
  }
}

canonical_original_code:
void clear_blockmap(struct blockmap_t *bm) {
  int i; int j;
  for (i = 0; i != bm->w; ++i) {
    for (j = 0; j != bm->h; ++j) {
      memset(&bm->buf[j*bm->w+i], 0, sizeof(struct block_t));
    }
  }
}


decompiled_code:
unsigned __int64 __fastcall rotate_sb(unsigned int *a1, int a2)
{
unsigned __int64 result; // rax
unsigned int v5; // ecx
__int64 v6; // r15
__int64 v7; // rdi
int v8; // ebx
__int64 v9; // rsi
int i; // eax
_BYTE *v11; // rdx
__int64 j; // rdx
unsigned int v13; // er12
unsigned int v14; // [rsp+8h] [rbp-38h]
int v15; // [rsp+Ch] [rbp-34h]

result = (unsigned int)(a2 + 1);
if ( (unsigned int)result <= 2 )
{
result = *a1;
v14 = result;
if ( (_DWORD)result )
{
v5 = a1[1];
v15 = result - 1;
v6 = (unsigned int)result;
v7 = 0LL;
v8 = 0;
v9 = (int)result;
do
{
if ( v5 )
{
v11 = (_BYTE *)(*((_QWORD *)a1 + 3) + v7);
for ( i = 0; i != v5; ++i )
{
if ( *v11 )
{
if ( a2 == 1 )
{
xb_1[v8] = v5 - 1 - i;
yb_0[v8] = v7;
}
else if ( a2 == -1 )
{
xb_1[v8] = i;
yb_0[v8] = v15 - v7;
}
else
{
xb_1[v8] = v7;
yb_0[v8] = i;
}
++v8;
}
v11 += v9;
}
}
++v7;
}
while ( v7 != v6 );
if ( !a2 )
goto LABEL_17;
}
else
{
if ( !a2 )
{
LABEL_20:
v13 = a1[3] + a2;
a1[3] = v13;
if ( v13 == -1 )
{
a1[3] = 3;
}
else if ( v13 == 4 )
{
a1[3] = 0;
}
return result;
}
v8 = 0;
}
*a1 = a1[1];
a1[1] = v14;
LABEL_17:
result = (unsigned __int64)memset(*((void **)a1 + 3), 0, (int)(a1[1] * *a1));
if ( v8 )
{
for ( j = 0LL; j != v8; ++j )
{
result = (int)(xb_1[j] + *a1 * yb_0[j]);
*(_BYTE *)(*((_QWORD *)a1 + 3) + result) = 1;
}
}
goto LABEL_20;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned int *a1, int a2)
{
unsigned __int64 result; // rax
unsigned int v5; // ecx
__int64 v6; // r15
__int64 v7; // rdi
int v8; // ebx
__int64 v9; // rsi
int i; // eax
_BYTE *v11; // rdx
__int64 j; // rdx
unsigned int v13; // er12
unsigned int v14; // [rsp+8h] [rbp-38h]
int v15; // [rsp+Ch] [rbp-34h]

result = (unsigned int)(a2 + 1);
if ( (unsigned int)result <= 2 )
{
result = *a1;
v14 = result;
if ( (_DWORD)result )
{
v5 = a1[1];
v15 = result - 1;
v6 = (unsigned int)result;
v7 = 0LL;
v8 = 0;
v9 = (int)result;
do
{
if ( v5 )
{
v11 = (_BYTE *)(*((_QWORD *)a1 + 3) + v7);
for ( i = 0; i != v5; ++i )
{
if ( *v11 )
{
if ( a2 == 1 )
{
xb_1[v8] = v5 - 1 - i;
yb_0[v8] = v7;
}
else if ( a2 == -1 )
{
xb_1[v8] = i;
yb_0[v8] = v15 - v7;
}
else
{
xb_1[v8] = v7;
yb_0[v8] = i;
}
++v8;
}
v11 += v9;
}
}
++v7;
}
while ( v7 != v6 );
if ( !a2 )
goto LABEL_17;
}
else
{
if ( !a2 )
{
LABEL_20:
v13 = a1[3] + a2;
a1[3] = v13;
if ( v13 == -1 )
{
a1[3] = 3;
}
else if ( v13 == 4 )
{
a1[3] = 0;
}
return result;
}
v8 = 0;
}
*a1 = a1[1];
a1[1] = v14;
LABEL_17:
result = (unsigned __int64)memset(*((void **)a1 + 3), 0, (int)(a1[1] * *a1));
if ( v8 )
{
for ( j = 0LL; j != v8; ++j )
{
result = (int)(xb_1[j] + *a1 * yb_0[j]);
*(_BYTE *)(*((_QWORD *)a1 + 3) + result) = 1;
}
}
goto LABEL_20;
}
return result;
}

original_code:
void rotate_sb(struct shapebuf_t* sb, int dir) {
  static int xb[3*4];
  static int yb[3*4];
  int p = 0, i, j;
  if (dir != 1 && dir != -1 && dir != 0) return;
  for (i = 0; i != sb->w; ++i) {
    for (j = 0; j != sb->h; ++j) {
      if (sb->buf[j*sb->w+i]) {
        if (dir == 1) {
          xb[p] = sb->h - (j+1);
          yb[p] = i;
        } else if (dir == -1) {
          xb[p] = j;
          yb[p] = sb->w - (i+1);
        } else {
          xb[p] = i;
          yb[p] = j;
        }
        ++p;
      }
    }
  }
  if (dir) {
    int tmp = sb->w;
    sb->w = sb->h; sb->h = tmp;
  }
  memset(sb->buf, 0, sb->w*sb->h);
  for (i = 0; i != p; ++i) {
    sb->buf[yb[i]*sb->w+xb[i]] = 1;
  }
  sb->rotate += dir;
  if (sb->rotate == -1) sb->rotate = 3;
  if (sb->rotate == 4) sb->rotate = 0;
}

canonical_original_code:
void rotate_sb(struct shapebuf_t *sb, int dir) {
  static int xb[-1];
  static int yb[-1];
  int p = 0; int i; int j;
  if (dir != 1 && dir != -1 && dir != 0) return;
  for (i = 0; i != sb->w; ++i) {
    for (j = 0; j != sb->h; ++j) {
      if (sb->buf[j*sb->w+i]) {
        if (dir == 1) {
          xb[p] = sb->h - (j+1);
          yb[p] = i;
        } else if (dir == -1) {
          xb[p] = j;
          yb[p] = sb->w - (i+1);
        } else {
          xb[p] = i;
          yb[p] = j;
        }
        ++p;
      }
    }
  }
  if (dir) {
    int tmp = sb->w;
    sb->w = sb->h; sb->h = tmp;
  }
  memset(sb->buf, 0, sb->w*sb->h);
  for (i = 0; i != p; ++i) {
    sb->buf[yb[i]*sb->w+xb[i]] = 1;
  }
  sb->rotate += dir;
  if (sb->rotate == -1) sb->rotate = 3;
  if (sb->rotate == 4) sb->rotate = 0;
}

variable_types: dir int

variable_types:
xb
int [-1]

variable_types:
yb
int [-1]

variable_types: p int

variable_types: tmp int


original_code:
void move_sb(struct shapebuf_t* sb, int offx, int offy) {
  sb->x += offx;
  sb->y += offy;
}

canonical_original_code:
void move_sb(struct shapebuf_t *sb, int offx, int offy) {
  sb->x += offx;
  sb->y += offy;
}

variable_types: offx int

variable_types: offy int


decompiled_code:
__int64 __fastcall check_sb(__int64 a1, int *a2)
{
unsigned int v2; // er11
int v3; // ebx
int v4; // er12
int i; // er10
__int64 j; // rax
int v7; // ecx
int v8; // er13
int v9; // edx

if ( a2[2] == -1 )
return (unsigned int)-3;
v2 = a2[1];
if ( v2 )
{
v3 = *a2;
v4 = 0;
for ( i = 0; i != v2; ++i )
{
if ( v3 )
{
for ( j = 0LL; j != *a2; ++j )
{
if ( *(_BYTE *)(*((_QWORD *)a2 + 3) + v4 + j) )
{
v7 = a2[5] + i;
v8 = a2[4] + j;
if ( v8 < 0 )
return (unsigned int)-1;
v9 = *(_DWORD *)a1;
if ( v7 < 0 || v9 <= v8 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 4) <= v7 )
return (unsigned int)-1;
if ( *(_BYTE *)(*(_QWORD *)(a1 + 8) + 3LL * (v8 + v7 * v9)) )
return (unsigned int)-2;
}
}
}
v4 += v3;
}
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int *a2)
{
unsigned int v2; // er11
int v3; // ebx
int v4; // er12
int i; // er10
__int64 j; // rax
int v7; // ecx
int v8; // er13
int v9; // edx

if ( a2[2] == -1 )
return (unsigned int)-3;
v2 = a2[1];
if ( v2 )
{
v3 = *a2;
v4 = 0;
for ( i = 0; i != v2; ++i )
{
if ( v3 )
{
for ( j = 0LL; j != *a2; ++j )
{
if ( *(_BYTE *)(*((_QWORD *)a2 + 3) + v4 + j) )
{
v7 = a2[5] + i;
v8 = a2[4] + j;
if ( v8 < 0 )
return (unsigned int)-1;
v9 = *(_DWORD *)a1;
if ( v7 < 0 || v9 <= v8 )
return (unsigned int)-1;
if ( *(_DWORD *)(a1 + 4) <= v7 )
return (unsigned int)-1;
if ( *(_BYTE *)(*(_QWORD *)(a1 + 8) + 3LL * (v8 + v7 * v9)) )
return (unsigned int)-2;
}
}
}
v4 += v3;
}
v2 = 0;
}
return v2;
}

original_code:
int check_sb(const struct blockmap_t* bm, const struct shapebuf_t* sb) {
  int i, j, x, y;
  if (sb->shape == -1) return -3;
  for (j = 0; j != sb->h; ++j) {
    for (i = 0; i != sb->w; ++i) {
      if (sb->buf[j*sb->w+i]) {
        x = i + sb->x;
        y = j + sb->y;
        if (x<0 || x>=bm->w || y<0 || y>=bm->h) {
          return -1;
        } else if (bm->buf[y*bm->w+x].occupied) {
          return -2;
        }
      }
    }
  }
  return 0;
}

canonical_original_code:
int check_sb(struct blockmap_t *bm, struct shapebuf_t *sb) {
  int i; int j; int x; int y;
  if (sb->shape == -1) return -3;
  for (j = 0; j != sb->h; ++j) {
    for (i = 0; i != sb->w; ++i) {
      if (sb->buf[j*sb->w+i]) {
        x = i + sb->x;
        y = j + sb->y;
        if (x<0 || x>=bm->w || y<0 || y>=bm->h) {
          return -1;
        } else if (bm->buf[y*bm->w+x].occupied) {
          return -2;
        }
      }
    }
  }
  return 0;
}

variable_types: i int

variable_types: j int

variable_types: x int

variable_types: y int


decompiled_code:
void __fastcall soft_reset_sb(int *a1, int a2, _DWORD *a3, signed int a4)
{
int v6; // ebx
int v7; // eax

reset_shapebuf(a1, a2);
if ( a1[2] != -1 )
{
a1[4] = (*a3 - *a1) / 2;
v6 = 0;
do
{
if ( !(unsigned int)check_sb((__int64)a3, a1) )
break;
v7 = 1 - v6;
if ( v6 >= 0 )
v7 = ~v6;
v6 = v7;
a1[4] += v7;
}
while ( (int)abs32(v7) < a4 );
}
}

original_code:
void soft_reset_sb(struct shapebuf_t* sb, int new_shape,
                   const struct blockmap_t* bm, int lim) {
  int n = 0;
  reset_shapebuf(sb, new_shape);
  if (sb->shape == -1) return;
  sb->x = (bm->w - sb->w) / 2;
  do {
    if (check_sb(bm, sb) != 0) {
      if (n < 0) {
        n = 1 - n;
      } else {
        n = -1 - n;
      }
      sb->x += n;
    } else {
      break;
    }
  } while (abs(n) < lim);
}

canonical_original_code:
void soft_reset_sb(struct shapebuf_t *sb, int new_shape, struct blockmap_t *bm, int lim) {
  int n = 0;
  reset_shapebuf(sb, new_shape);
  if (sb->shape == -1) return;
  sb->x = (bm->w - sb->w) / 2;
  do {
    if (check_sb(bm, sb) != 0) {
      if (n < 0) {
        n = 1 - n;
      } else {
        n = -1 - n;
      }
      sb->x += n;
    } else {
      break;
    }
  } while (abs(n) < lim);
}

variable_types: lim int

variable_types: n int


decompiled_code:
unsigned __int64 __fastcall soft_rotate_sb(unsigned int *a1, int a2, int *a3, signed int a4)
{
unsigned int v6; // ebx
unsigned int v7; // edx
int v8; // ebx
int v9; // eax
int v10; // ebx
int v11; // ebx
unsigned __int64 result; // rax
int v13; // eax
unsigned int v14; // [rsp+Ch] [rbp-34h]

v14 = a1[4];
v6 = *a1;
rotate_sb(a1, a2);
v7 = *a1;
v8 = v6 - *a1;
if ( (v8 & 1) != 0 )
{
v9 = v8 - 1;
if ( v8 >= 0 )
v9 = v8 + 1;
v8 = v9;
}
v10 = a1[4] + v8 / 2;
if ( v10 < 0 )
v10 = 0;
a1[4] = v10;
if ( v10 >= *a3 )
a1[4] = *a3 - v7;
v11 = 0;
while ( 1 )
{
result = check_sb((__int64)a3, (int *)a1);
if ( !(_DWORD)result )
break;
v13 = 1 - v11;
if ( v11 >= 0 )
v13 = ~v11;
v11 = v13;
a1[4] += v13;
if ( (int)abs32(v13) >= a4 )
{
result = check_sb((__int64)a3, (int *)a1);
if ( (_DWORD)result )
{
a1[4] = v14;
result = rotate_sb(a1, -a2);
}
return result;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(unsigned int *a1, int a2, int *a3, signed int a4)
{
unsigned int v6; // ebx
unsigned int v7; // edx
int v8; // ebx
int v9; // eax
int v10; // ebx
int v11; // ebx
unsigned __int64 result; // rax
int v13; // eax
unsigned int v14; // [rsp+Ch] [rbp-34h]

v14 = a1[4];
v6 = *a1;
func7(a1, a2);
v7 = *a1;
v8 = v6 - *a1;
if ( (v8 & 1) != 0 )
{
v9 = v8 - 1;
if ( v8 >= 0 )
v9 = v8 + 1;
v8 = v9;
}
v10 = a1[4] + v8 / 2;
if ( v10 < 0 )
v10 = 0;
a1[4] = v10;
if ( v10 >= *a3 )
a1[4] = *a3 - v7;
v11 = 0;
while ( 1 )
{
result = func9((__int64)a3, (int *)a1);
if ( !(_DWORD)result )
break;
v13 = 1 - v11;
if ( v11 >= 0 )
v13 = ~v11;
v11 = v13;
a1[4] += v13;
if ( (int)abs32(v13) >= a4 )
{
result = func9((__int64)a3, (int *)a1);
if ( (_DWORD)result )
{
a1[4] = v14;
result = func7(a1, -a2);
}
return result;
}
}
return result;
}

original_code:
void soft_rotate_sb(struct shapebuf_t* sb, int dir,
                    const struct blockmap_t* bm, int lim) {
  int n = 0, differ, ox;
  ox = sb->x;
  differ = sb->w;
  rotate_sb(sb, dir);
  differ -= sb->w;
  if (differ % 2) {
    if (differ < 0) differ -= 1;
    else differ += 1;
  }
  differ /= 2;
  sb->x += differ;
  if (sb->x < 0) {
    sb->x = 0;
  }
  if (sb->x >= bm->w) {
    sb->x = bm->w-sb->w;
  }
  do {
    if (check_sb(bm, sb) != 0) {
      if (n < 0) {
        n = 1 - n;
      } else {
        n = -1 - n;
      }
      sb->x += n;
    } else {
      return;
    }
  } while (abs(n) < lim);
  if (check_sb(bm, sb) != 0) {
    sb->x = ox;
    rotate_sb(sb, -dir);
    return;
  }
}

canonical_original_code:
void soft_rotate_sb(struct shapebuf_t *sb, int dir, struct blockmap_t *bm, int lim) {
  int n = 0; int differ; int ox;
  ox = sb->x;
  differ = sb->w;
  rotate_sb(sb, dir);
  differ -= sb->w;
  if (differ % 2) {
    if (differ < 0) differ -= 1;
    else differ += 1;
  }
  differ /= 2;
  sb->x += differ;
  if (sb->x < 0) {
    sb->x = 0;
  }
  if (sb->x >= bm->w) {
    sb->x = bm->w-sb->w;
  }
  do {
    if (check_sb(bm, sb) != 0) {
      if (n < 0) {
        n = 1 - n;
      } else {
        n = -1 - n;
      }
      sb->x += n;
    } else {
      return;
    }
  } while (abs(n) < lim);
  if (check_sb(bm, sb) != 0) {
    sb->x = ox;
    rotate_sb(sb, -dir);
    return;
  }
}

variable_types: struct blockmap_t { int w; struct block_t { unsigned char occupied; unsigned char shape; unsigned char flags; } *buf; } *

variable_types: differ int

variable_types: ox int


decompiled_code:
void __fastcall soft_move_sb(int *a1, int a2, int a3, __int64 a4)
{
move_sb((__int64)a1, a2, a3);
if ( (unsigned int)check_sb(a4, a1) )
move_sb((__int64)a1, -a2, -a3);
}

canonical_decompiled_code:
void __fastcall func12(int *a1, int a2, int a3, __int64 a4)
{
func8((__int64)a1, a2, a3);
if ( (unsigned int)func9(a4, a1) )
func8((__int64)a1, -a2, -a3);
}

original_code:
void soft_move_sb(struct shapebuf_t* sb, int offx, int offy,
                  struct blockmap_t* bm) {
  move_sb(sb, offx, offy);
  if (check_sb(bm, sb) != 0) {
    move_sb(sb, -offx, -offy);
  }
}

canonical_original_code:
void soft_move_sb(struct shapebuf_t *sb, int offx, int offy, struct blockmap_t *bm) {
  move_sb(sb, offx, offy);
  if (check_sb(bm, sb) != 0) {
    move_sb(sb, -offx, -offy);
  }
}

variable_types: struct shapebuf_t { int w; unsigned char *buf; } *


decompiled_code:
void __fastcall hard_drop_sb(int *a1, __int64 a2)
{
while ( !(unsigned int)check_sb(a2, a1) )
move_sb((__int64)a1, 0, 1);
move_sb((__int64)a1, 0, -1);
}

canonical_decompiled_code:
void __fastcall func13(int *a1, __int64 a2)
{
while ( !(unsigned int)func9(a2, a1) )
func8((__int64)a1, 0, 1);
func8((__int64)a1, 0, -1);
}

original_code:
void hard_drop_sb(struct shapebuf_t* sb, const struct blockmap_t* bm) {
  while (check_sb(bm, sb) == 0) {
    move_sb(sb, 0, 1);
  }
  move_sb(sb, 0, -1);
}

canonical_original_code:
void hard_drop_sb(struct shapebuf_t *sb, struct blockmap_t *bm) {
  while (check_sb(bm, sb) == 0) {
    move_sb(sb, 0, 1);
  }
  move_sb(sb, 0, -1);
}


decompiled_code:
__int64 __fastcall merge_sb(__int64 a1, int *a2)
{
__int64 result; // rax
int v4; // esi
int v5; // edx
int v6; // er8
int v7; // eax

result = check_sb(a1, a2);
if ( !(_DWORD)result )
{
v4 = 0;
if ( a2[1] )
{
do
{
result = (unsigned int)*a2;
v5 = 0;
if ( (_DWORD)result )
{
do
{
if ( *(_BYTE *)(*((_QWORD *)a2 + 3) + v5 + v4 * (int)result) )
{
v6 = a2[4] + v5;
v7 = a2[5] + v4;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + 3LL * (v6 + *(_DWORD *)a1 * v7)) = 1;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + 3LL * (v6 + *(_DWORD *)a1 * v7) + 1) = a2[2];
}
++v5;
result = (unsigned int)*a2;
}
while ( (_DWORD)result != v5 );
}
++v4;
}
while ( a2[1] != v4 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int *a2)
{
__int64 result; // rax
int v4; // esi
int v5; // edx
int v6; // er8
int v7; // eax

result = func9(a1, a2);
if ( !(_DWORD)result )
{
v4 = 0;
if ( a2[1] )
{
do
{
result = (unsigned int)*a2;
v5 = 0;
if ( (_DWORD)result )
{
do
{
if ( *(_BYTE *)(*((_QWORD *)a2 + 3) + v5 + v4 * (int)result) )
{
v6 = a2[4] + v5;
v7 = a2[5] + v4;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + 3LL * (v6 + *(_DWORD *)a1 * v7)) = 1;
*(_BYTE *)(*(_QWORD *)(a1 + 8) + 3LL * (v6 + *(_DWORD *)a1 * v7) + 1) = a2[2];
}
++v5;
result = (unsigned int)*a2;
}
while ( (_DWORD)result != v5 );
}
++v4;
}
while ( a2[1] != v4 );
}
}
return result;
}

original_code:
void merge_sb(struct blockmap_t* bm, const struct shapebuf_t* sb) {
  int i, j, x, y;
  if (check_sb(bm, sb) != 0) return;
  for (j = 0; j != sb->h; ++j) {
    for (i = 0; i != sb->w; ++i) {
      if (sb->buf[j*sb->w+i]) {
        x = i + sb->x;
        y = j + sb->y;
        bm->buf[y*bm->w+x].occupied = 1;
        bm->buf[y*bm->w+x].shape = sb->shape;
      }
    }
  }
}

canonical_original_code:
void merge_sb(struct blockmap_t *bm, struct shapebuf_t *sb) {
  int i; int j; int x; int y;
  if (check_sb(bm, sb) != 0) return;
  for (j = 0; j != sb->h; ++j) {
    for (i = 0; i != sb->w; ++i) {
      if (sb->buf[j*sb->w+i]) {
        x = i + sb->x;
        y = j + sb->y;
        bm->buf[y*bm->w+x].occupied = 1;
        bm->buf[y*bm->w+x].shape = sb->shape;
      }
    }
  }
}


original_code:
int check_bm_lines(const struct blockmap_t* bm, int* lnbuf, int bufsz) {
  int i, j, fullline, num = 0;
  for (j = bm->h-1; j >= 0; --j) {
    fullline = 1;
    for (i = 0; i != bm->w; ++i) {
      if (!bm->buf[j*bm->w+i].occupied) {
        fullline = 0;
        break;
      }
    }
    if (fullline) {
      ++num;
      if (bufsz != 0) {
        lnbuf[num-1] = j;
        if (num >= bufsz) {
          return bufsz;
        }
      }
    }
  }
  return num;
}

canonical_original_code:
int check_bm_lines(struct blockmap_t *bm, int *lnbuf, int bufsz) {
  int i; int j; int fullline; int num = 0;
  for (j = bm->h-1; j >= 0; --j) {
    fullline = 1;
    for (i = 0; i != bm->w; ++i) {
      if (!bm->buf[j*bm->w+i].occupied) {
        fullline = 0;
        break;
      }
    }
    if (fullline) {
      ++num;
      if (bufsz != 0) {
        lnbuf[num-1] = j;
        if (num >= bufsz) {
          return bufsz;
        }
      }
    }
  }
  return num;
}

variable_types:
lnbuf
int *

variable_types: bufsz int

variable_types: fullline int

variable_types: num int


decompiled_code:
__int64 __fastcall kill_bm_lines(int *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // r15
__int64 v5; // r14
int v6; // ebx
unsigned int v7; // [rsp+4h] [rbp-4Ch]
__int64 v8; // [rsp+8h] [rbp-48h]
__int64 v9; // [rsp+10h] [rbp-40h]

result = *(_QWORD *)(g_cfg[1] + 40LL);
if ( result )
return ((__int64 (__fastcall *)(int *, __int64))result)(a1, a2);
if ( a3 )
{
v4 = a2 + 4;
v9 = a3 - 1;
v8 = a3;
v5 = 0LL;
result = a3 - 2;
v7 = a3 - 2;
do
{
v6 = *(_DWORD *)(v4 - 4) - 1;
if ( v6 >= 0 )
{
do
{
result = (__int64)memcpy(
(void *)(*((_QWORD *)a1 + 1) + 3LL * *a1 * (v6 + 1)),
(const void *)(*((_QWORD *)a1 + 1) + 3LL * v6 * *a1),
3LL * *a1);
--v6;
}
while ( v6 != -1 );
}
if ( v5 == v9 )
break;
result = v4;
do
{
if ( *(_DWORD *)result < *(_DWORD *)(v4 - 4) )
++*(_DWORD *)result;
result += 4LL;
}
while ( result != a2 + 4 * (v5 + v7 - (unsigned int)v5) + 8 );
++v5;
v4 += 4LL;
}
while ( v5 != v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // r15
__int64 v5; // r14
int v6; // ebx
unsigned int v7; // [rsp+4h] [rbp-4Ch]
__int64 v8; // [rsp+8h] [rbp-48h]
__int64 v9; // [rsp+10h] [rbp-40h]

result = *(_QWORD *)(g_cfg[1] + 40LL);
if ( result )
return ((__int64 (__fastcall *)(int *, __int64))result)(a1, a2);
if ( a3 )
{
v4 = a2 + 4;
v9 = a3 - 1;
v8 = a3;
v5 = 0LL;
result = a3 - 2;
v7 = a3 - 2;
do
{
v6 = *(_DWORD *)(v4 - 4) - 1;
if ( v6 >= 0 )
{
do
{
result = (__int64)memcpy(
(void *)(*((_QWORD *)a1 + 1) + 3LL * *a1 * (v6 + 1)),
(const void *)(*((_QWORD *)a1 + 1) + 3LL * v6 * *a1),
3LL * *a1);
--v6;
}
while ( v6 != -1 );
}
if ( v5 == v9 )
break;
result = v4;
do
{
if ( *(_DWORD *)result < *(_DWORD *)(v4 - 4) )
++*(_DWORD *)result;
result += 4LL;
}
while ( result != a2 + 4 * (v5 + v7 - (unsigned int)v5) + 8 );
++v5;
v4 += 4LL;
}
while ( v5 != v8 );
}
return result;
}

original_code:
void kill_bm_lines(struct blockmap_t* bm, int* lnbuf, int len) {
  int n = 0, j, i;
  if (g_cfg.ctrl->kill_bm_lines) {
    (*g_cfg.ctrl->kill_bm_lines)(bm, lnbuf, len);
    return;
  }
  for (; n != len; ++n) {
    for (j = lnbuf[n]-1; j >= 0; --j) {
      memcpy(&(bm->buf[(j+1)*bm->w]), &(bm->buf[j*bm->w]),
             sizeof(struct block_t) * bm->w);
    }
    for (i = n+1; i != len; ++i) {
      if (lnbuf[i] < lnbuf[n]) {
        lnbuf[i] += 1;
      }
    }
  }
}

canonical_original_code:
void kill_bm_lines(struct blockmap_t *bm, int *lnbuf, int len) {
  int n = 0; int j; int i;
  if (g_cfg.ctrl->kill_bm_lines) {
    (*g_cfg.ctrl->kill_bm_lines)(bm, lnbuf, len);
    return;
  }
  for (; n != len; ++n) {
    for (j = lnbuf[n]-1; j >= 0; --j) {
      memcpy(&(bm->buf[(j+1)*bm->w]), &(bm->buf[j*bm->w]),
             sizeof(struct block_t) * bm->w);
    }
    for (i = n+1; i != len; ++i) {
      if (lnbuf[i] < lnbuf[n]) {
        lnbuf[i] += 1;
      }
    }
  }
}

variable_types: len int


decompiled_code:
void __fastcall set_ghost(__int64 a1, __int64 a2, __int64 a3)
{
if ( *(_QWORD *)a3 != *(_QWORD *)a2 )
{
free(*(void **)(a3 + 24));
*(_QWORD *)(a3 + 24) = calloc(*(_DWORD *)(a2 + 4) * *(_DWORD *)a2, 1uLL);
}
copy_shapebuf(a3, (const void **)a2);
hard_drop_sb((int *)a3, a1);
}

original_code:
void set_ghost(const struct blockmap_t* bm,
               const struct shapebuf_t* sb,
               struct shapebuf_t* ghost) {
  if (ghost->w != sb->w || ghost->h != sb->h) {
    free(ghost->buf);
    ghost->buf = calloc(sb->w * sb->h, sizeof(unsigned char));
  }
  copy_shapebuf(ghost, sb);
  hard_drop_sb(ghost, bm);
}

canonical_original_code:
void set_ghost(struct blockmap_t *bm, struct shapebuf_t *sb, struct shapebuf_t *ghost) {
  if (ghost->w != sb->w || ghost->h != sb->h) {
    free(ghost->buf);
    ghost->buf = calloc(sb->w * sb->h, sizeof(unsigned char));
  }
  copy_shapebuf(ghost, sb);
  hard_drop_sb(ghost, bm);
}

variable_types:
ghost
struct shapebuf_t *


decompiled_code:
void __fastcall swap_hold(int *a1, int *a2, __int64 (*a3)(void), _DWORD *a4, signed int a5)
{
int v7; // er15

v7 = a2[2];
if ( *a1 == -1 )
*a1 = a3();
if ( a4 )
soft_reset_sb(a2, *a1, a4, a5);
else
reset_shapebuf(a2, *a1);
*a1 = v7;
}

original_code:
void swap_hold(int* holdbuf, struct shapebuf_t* sb, int(*getnext)(void),
               const struct blockmap_t* bm, int lim) {
  int swp = sb->shape;
  if (*holdbuf == -1) {
    *holdbuf = (*getnext)();
  }
  if (bm != ((void *)0)) {
    soft_reset_sb(sb, *holdbuf, bm, lim);
  } else {
    reset_shapebuf(sb, *holdbuf);
  }
  *holdbuf = swp;
}

canonical_original_code:
void swap_hold(int *holdbuf, struct shapebuf_t *sb, int (*getnext)(), struct blockmap_t *bm, int lim) {
  int swp = sb->shape;
  if (*holdbuf == -1) {
    *holdbuf = (*getnext)();
  }
  if (bm != ((void *)0)) {
    soft_reset_sb(sb, *holdbuf, bm, lim);
  } else {
    reset_shapebuf(sb, *holdbuf);
  }
  *holdbuf = swp;
}

variable_types:
holdbuf
int *

variable_types:
getnext
int (*)()

variable_types: swp int


decompiled_code:
__int64 __fastcall steady_sb(int *a1, int *a2, int a3, signed int a4)
{
unsigned int v6; // eax
char v8[48]; // [rsp+0h] [rbp-30h] BYREF

merge_sb((__int64)a1, a2);
v6 = check_bm_lines(a1, (__int64)v8, 4u);
if ( v6 )
kill_bm_lines(a1, (__int64)v8, v6);
soft_reset_sb(a2, a3, a1, a4);
return (unsigned int)-((unsigned int)check_sb((__int64)a1, a2) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func19(int *a1, int *a2, int a3, signed int a4)
{
unsigned int v6; // eax
char v8[48]; // [rsp+0h] [rbp-30h] BYREF

func14((__int64)a1, a2);
v6 = func15(a1, (__int64)v8, 4u);
if ( v6 )
func16(a1, (__int64)v8, v6);
func10(a2, a3, a1, a4);
return (unsigned int)-((unsigned int)func9((__int64)a1, a2) != 0);
}

original_code:
int steady_sb(struct blockmap_t* bm, struct shapebuf_t* sb,
              int nxtshp, int lim) {
  int lnbuf[4], num_clear;
  merge_sb(bm, sb);
  if ((num_clear = check_bm_lines(bm, lnbuf, 4)) != 0) {
    kill_bm_lines(bm, lnbuf, num_clear);
  }
  soft_reset_sb(sb, nxtshp, bm, lim);
  if (check_sb(bm, sb) != 0) {
    return -1;
  } else {
    return 0;
  }
}

canonical_original_code:
int steady_sb(struct blockmap_t *bm, struct shapebuf_t *sb, int nxtshp, int lim) {
  int lnbuf[4]; int num_clear;
  merge_sb(bm, sb);
  if ((num_clear = check_bm_lines(bm, lnbuf, 4)) != 0) {
    kill_bm_lines(bm, lnbuf, num_clear);
  }
  soft_reset_sb(sb, nxtshp, bm, lim);
  if (check_sb(bm, sb) != 0) {
    return -1;
  } else {
    return 0;
  }
}

variable_types: nxtshp int

variable_types:
lnbuf
int [4]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init_game(argc, argv, envp);
main_loop();
destroy_game();
return 0;
}

original_code:
int main(int argc, char** argv) {
  init_game();
  main_loop();
  destroy_game();
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  init_game();
  main_loop();
  destroy_game();
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 default_init_shapes()
{
_DWORD *v0; // r13
__int64 v1; // rbx
__int64 v2; // r12
__int64 result; // rax

g_numshp = 7;
g_shps = (__int64)calloc(7uLL, 0x20uLL);
v0 = &shp_pix;
v1 = 0LL;
do
{
*(_DWORD *)(g_shps + 32 * v1) = v1;
fillpixels(g_shps + 32 * v1 + 4, v0, 4);
v2 = g_shps + 32 * v1;
*(_DWORD *)(v2 + 24) = shp_sz[2 * v1];
*(_DWORD *)(v2 + 28) = dword_264[2 * v1];
result = shp_color[v1];
*(_QWORD *)(v2 + 16) = result;
++v1;
v0 += 8;
}
while ( g_numshp != (_DWORD)v1 );
return result;
}

original_code:
void default_init_shapes(void) {
  int i = 0;
  g_numshp = 7;
  g_shps = calloc(g_numshp, sizeof(struct shape_t));
  for (; i != g_numshp; ++i) {
    g_shps[i].no = i;
    fillpixels(g_shps[i].pix, shp_pix[i], 4);
    g_shps[i].w = shp_sz[i][0];
    g_shps[i].h = shp_sz[i][1];
    g_shps[i].color = shp_color[i];
  }
}

canonical_original_code:
void default_init_shapes() {
  int i = 0;
  g_numshp = 7;
  g_shps = calloc(g_numshp, sizeof(struct shape_t));
  for (; i != g_numshp; ++i) {
    g_shps[i].no = i;
    fillpixels(g_shps[i].pix, shp_pix[i], 4);
    g_shps[i].w = shp_sz[i][0];
    g_shps[i].h = shp_sz[i][1];
    g_shps[i].color = shp_color[i];
  }
}

variable_types: i int

user_defined_types: struct shape_t { int no; unsigned char pix[4][3]; unsigned long color; int w; }


clrscr

decompiled_code:
__int64 clrscr()
{
return SDL_FillRect(*(_QWORD *)g_ui, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return SDL_FillRect(*(_QWORD *)g_ui, 0LL, 0LL);
}

original_code:
void clrscr(void) {
  SDL_FillRect(g_ui->scr, 0, 0);
}

canonical_original_code:
void clrscr() {
  SDL_FillRect(g_ui->scr, 0, 0);
}


update

decompiled_code:
__int64 update()
{
return SDL_Flip(*(_QWORD *)g_ui);
}

canonical_decompiled_code:
__int64 func2()
{
return SDL_Flip(*(_QWORD *)g_ui);
}

original_code:
void update(void) {
  SDL_Flip(g_ui->scr);
}

canonical_original_code:
void update() {
  SDL_Flip(g_ui->scr);
}


decompiled_code:
void destroy_ui()
{
if ( g_ui )
{
if ( *(_QWORD *)g_ui )
SDL_FreeSurface();
free(g_ui);
}
}

canonical_decompiled_code:
void func4()
{
if ( g_ui )
{
if ( *(_QWORD *)g_ui )
SDL_FreeSurface();
free(g_ui);
}
}

original_code:
void destroy_ui(void) {
  if (g_ui) {
    if (g_ui->scr) {
      SDL_FreeSurface(g_ui->scr);
    }
    free(g_ui);
  }
}

canonical_original_code:
void destroy_ui() {
  if (g_ui) {
    if (g_ui->scr) {
      SDL_FreeSurface(g_ui->scr);
    }
    free(g_ui);
  }
}


decompiled_code:
__int64 util_delay()
{
return SDL_Delay();
}

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

original_code:
void util_delay(unsigned long ms) {
  SDL_Delay(ms);
}

variable_types:
ms
unsigned long


decompiled_code:
__int64 util_getticks()
{
return (unsigned int)SDL_GetTicks();
}

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

original_code:
unsigned long util_getticks(void) {
  return SDL_GetTicks();
}

canonical_original_code:
unsigned long util_getticks() {
  return SDL_GetTicks();
}

return_type: unsigned long


decompiled_code:
void init_graphic()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void init_graphic(void) {
}

canonical_original_code:
void init_graphic() {
}


decompiled_code:
void __fastcall destroy_queue(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_queue(struct queue_t* queue) {
  free(queue->queue);
  free(queue);
}

canonical_original_code:
void destroy_queue(struct queue_t *queue) {
  free(queue->queue);
  free(queue);
}

variable_types: struct queue_t { int *queue; int capacity; int range; int *randbuf; int randptr; } *


original_code:
int shift_randbuf(struct queue_t* q) {
  int i, rnd, cert;
  if (q->randptr > 0) {
    return q->randbuf[--q->randptr];
  }
  do {
    cert = 1;
    rnd = rand() % q->range;
    for (i = 0; i != q->randptr; ++i) {
      if (rnd == q->randbuf[i]) {
        cert = 0;
        break;
      }
    }
    if (cert) q->randbuf[q->randptr++] = rnd;
  } while (q->randptr != q->capacity);
  return shift_randbuf(q);
}

canonical_original_code:
int shift_randbuf(struct queue_t *q) {
  int i; int rnd; int cert;
  if (q->randptr > 0) {
    return q->randbuf[--q->randptr];
  }
  do {
    cert = 1;
    rnd = rand() % q->range;
    for (i = 0; i != q->randptr; ++i) {
      if (rnd == q->randbuf[i]) {
        cert = 0;
        break;
      }
    }
    if (cert) q->randbuf[q->randptr++] = rnd;
  } while (q->randptr != q->capacity);
  return shift_randbuf(q);
}

variable_types: rnd int

variable_types: cert int

user_defined_types: struct queue_t { int *queue; int capacity; int range; int *randbuf; int randptr; }


original_code:
int shift_queue(struct queue_t* q) {
  int elm = q->queue[0], i;
  for (i = 1; i != q->capacity; ++i) {
    q->queue[i-1] = q->queue[i];
  }
  q->queue[q->capacity-1] = shift_randbuf(q);
  return elm;
}

canonical_original_code:
int shift_queue(struct queue_t *q) {
  int elm = q->queue[0]; int i;
  for (i = 1; i != q->capacity; ++i) {
    q->queue[i-1] = q->queue[i];
  }
  q->queue[q->capacity-1] = shift_randbuf(q);
  return elm;
}

variable_types: elm int


repo: shouya/clisp

decompiled_code:
void __fastcall scope_destroy(void *ptr)
{
htab_destroy(*((_QWORD *)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
htab_destroy(*((_QWORD *)ptr + 1));
free(ptr);
}

original_code:
void scope_destroy(Scope* scope) {
  htab_destroy(scope->symtab);
  free(scope);
}

canonical_original_code:
void scope_destroy(struct _Scope *scope) {
  htab_destroy(scope->symtab);
  free(scope);
}

variable_types: struct _Scope { struct _Scope *parent; struct _Htab { int n_nodes; int size; void (*free_handler)(void *v); void *(*dup_handler)(void *v); struct _HtabNode { char *key; void *value; } **nodes; } *symtab; } *

user_defined_types: struct _Scope { struct _Scope *parent; struct _Htab *symtab; }

user_defined_types: struct _Htab { int n_nodes; int size; void (*free_handler)(void *v); void *(*dup_handler)(void *v); struct _HtabNode **nodes; }


decompiled_code:
_BOOL8 __fastcall scope_del_symbol(__int64 a1)
{
return (unsigned int)htab_del(*(_QWORD *)(a1 + 8)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return (unsigned int)htab_del(*(_QWORD *)(a1 + 8)) != 0;
}

original_code:
int scope_del_symbol(Scope* s, const char* name) {
  if (htab_del(s->symtab, name) == 0)
    return 0;
  return 1;
}

canonical_original_code:
int scope_del_symbol(struct _Scope *s, char *name) {
  if (htab_del(s->symtab, name) == 0)
    return 0;
  return 1;
}

variable_types:
name
char *

user_defined_types: struct _HtabNode { char *key; void *value; }


decompiled_code:
void __fastcall htab_destroy(void *ptr)
{
__int64 v1; // rbx
void **v2; // rax
void (__fastcall *v3)(_QWORD); // rax

if ( *((_DWORD *)ptr + 1) )
{
v1 = 0LL;
do
{
v2 = *(void ***)(*((_QWORD *)ptr + 3) + 8 * v1);
if ( v2 )
{
free(*v2);
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
if ( v3 )
v3(*(_QWORD *)(*(_QWORD *)(*((_QWORD *)ptr + 3) + 8 * v1) + 8LL));
free(*(void **)(*((_QWORD *)ptr + 3) + 8 * v1));
}
++v1;
}
while ( *((_DWORD *)ptr + 1) != (_DWORD)v1 );
}
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void htab_destroy(Htab* htab) {
  int i = 0;
  for (; i != htab->size; ++i) {
    if (htab->nodes[i]) {
      free(htab->nodes[i]->key);
      if (htab->free_handler) {
        (*htab->free_handler)(htab->nodes[i]->value);
      }
      free(htab->nodes[i]);
    }
  }
  free(htab->nodes);
  free(htab);
}

canonical_original_code:
void htab_destroy(struct _Htab *htab) {
  int i = 0;
  for (; i != htab->size; ++i) {
    if (htab->nodes[i]) {
      free(htab->nodes[i]->key);
      if (htab->free_handler) {
        (*htab->free_handler)(htab->nodes[i]->value);
      }
      free(htab->nodes[i]);
    }
  }
  free(htab->nodes);
  free(htab);
}

variable_types: struct _Htab { int n_nodes; int size; void (*free_handler)(void *v); void *(*dup_handler)(void *v); struct _HtabNode { char *key; void *value; } **nodes; } *


original_code:
void htab_foreach(Htab* htab, HtabEach each) {
  int i = 0;
  for (; i != htab->size; ++i) {
    if (htab->nodes[i] == ((void *)0)) continue;
    (*each)(htab->nodes[i]->key, htab->nodes[i]->value);
  }
}

canonical_original_code:
void htab_foreach(struct _Htab *htab, void (*each)(char *k, void *v)) {
  int i = 0;
  for (; i != htab->size; ++i) {
    if (htab->nodes[i] == ((void *)0)) continue;
    (*each)(htab->nodes[i]->key, htab->nodes[i]->value);
  }
}

variable_types:
each
void (*)(char *k, void *v)


decompiled_code:
unsigned __int64 __fastcall htab_string_hash(char *a1, unsigned __int64 a2)
{
char *v3; // rsi
char v4; // cl
unsigned __int64 v5; // rax

v3 = a1 + 1;
v4 = *a1;
if ( *a1 )
{
v5 = 0LL;
do
{
v5 = v4 + 65600 * v5 - v5;
v4 = *v3++;
}
while ( v4 );
}
else
{
v5 = 0LL;
}
return v5 % a2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char *a1, unsigned __int64 a2)
{
char *v3; // rsi
char v4; // cl
unsigned __int64 v5; // rax

v3 = a1 + 1;
v4 = *a1;
if ( *a1 )
{
v5 = 0LL;
do
{
v5 = v4 + 65600 * v5 - v5;
v4 = *v3++;
}
while ( v4 );
}
else
{
v5 = 0LL;
}
return v5 % a2;
}

original_code:
unsigned long htab_string_hash(const char* str, unsigned long hash_size) {
  unsigned long hash = 0;
  int c;
  while ((c = *str++) != 0)
    hash = c + (hash << 6) + (hash << 16) - hash;
  return hash % hash_size;
}

canonical_original_code:
unsigned long htab_string_hash(char *str, unsigned long hash_size) {
  unsigned long hash = 0;
  int c;
  while ((c = *str++) != 0)
    hash = c + (hash << 6) + (hash << 16) - hash;
  return hash % hash_size;
}

variable_types:
str
char *

variable_types:
hash
unsigned long

variable_types: c int


original_code:
int htab_set(Htab* htab, const char* k, const void* v) {
  unsigned long hash = htab_string_hash(k, htab->size);
  if (htab->nodes[hash] == ((void *)0)) {
    htab->nodes[hash] = calloc(1, sizeof(HtabNode));
    htab->nodes[hash]->key = malloc(sizeof(char) * (strlen(k)+1));
    strcpy(htab->nodes[hash]->key, k);
    ++htab->n_nodes;
  } else {
    if (htab->free_handler) {
        (*htab->free_handler)(htab->nodes[hash]->value);
    }
  }
  if (htab->dup_handler) {
    htab->nodes[hash]->value = (*htab->dup_handler)(v);
  } else {
    htab->nodes[hash]->value = (void*)v;
  }
  return 0;
}

canonical_original_code:
int htab_set(struct _Htab *htab, char *k, void *v) {
  unsigned long hash = htab_string_hash(k, htab->size);
  if (htab->nodes[hash] == ((void *)0)) {
    htab->nodes[hash] = calloc(1, sizeof(HtabNode));
    htab->nodes[hash]->key = malloc(sizeof(char) * (strlen(k)+1));
    strcpy(htab->nodes[hash]->key, k);
    ++htab->n_nodes;
  } else {
    if (htab->free_handler) {
        (*htab->free_handler)(htab->nodes[hash]->value);
    }
  }
  if (htab->dup_handler) {
    htab->nodes[hash]->value = (*htab->dup_handler)(v);
  } else {
    htab->nodes[hash]->value = (void *)v;
  }
  return 0;
}

variable_types:
k
char *

variable_types:
v
void *


original_code:
int htab_del(Htab* htab, const char* k) {
  unsigned long hash = htab_string_hash(k, htab->size);
  if (htab->nodes[hash] == ((void *)0)) {
    return 1;
  }
  free(htab->nodes[hash]->key);
  if (htab->free_handler) {
    (*htab->free_handler)(htab->nodes[hash]->value);
  }
  free(htab->nodes[hash]);
  htab->nodes[hash] = ((void *)0);
  --htab->n_nodes;
  return 0;
}

canonical_original_code:
int htab_del(struct _Htab *htab, char *k) {
  unsigned long hash = htab_string_hash(k, htab->size);
  if (htab->nodes[hash] == ((void *)0)) {
    return 1;
  }
  free(htab->nodes[hash]->key);
  if (htab->free_handler) {
    (*htab->free_handler)(htab->nodes[hash]->value);
  }
  free(htab->nodes[hash]);
  htab->nodes[hash] = ((void *)0);
  --htab->n_nodes;
  return 0;
}


decompiled_code:
__int64 __fastcall htab_find(__int64 a1, char *a2, _QWORD *a3)
{
__int64 v4; // rax
unsigned int v5; // edx

v4 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8 * htab_string_hash(a2, *(int *)(a1 + 4)));
if ( !v4 )
return (unsigned int)-1;
v5 = 0;
if ( a3 )
*a3 = *(_QWORD *)(v4 + 8);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2, _QWORD *a3)
{
__int64 v4; // rax
unsigned int v5; // edx

v4 = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8 * func2(a2, *(int *)(a1 + 4)));
if ( !v4 )
return (unsigned int)-1;
v5 = 0;
if ( a3 )
*a3 = *(_QWORD *)(v4 + 8);
return v5;
}

original_code:
int htab_find(const Htab* htab, const char* key, void** value) {
  unsigned long hash = htab_string_hash(key, htab->size);
  if (htab->nodes[hash] == ((void *)0)) return -1;
  if (value) {
    *value = htab->nodes[hash]->value;
  }
  return 0;
}

canonical_original_code:
int htab_find(struct _Htab *htab, char *key, void **value) {
  unsigned long hash = htab_string_hash(key, htab->size);
  if (htab->nodes[hash] == ((void *)0)) return -1;
  if (value) {
    *value = htab->nodes[hash]->value;
  }
  return 0;
}

variable_types:
key
char *

variable_types:
value
void **


repo: shramov/ring

decompiled_code:
__int64 __fastcall size_aligned(int a1)
{
return a1 + (-a1 & 7u);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return a1 + (-a1 & 7u);
}

original_code:
static ring_size_t size_aligned(ring_size_t x)
{
    return x + (-x & (align - 1));
}

canonical_original_code:
static int size_aligned(int x)
{
    return x + (-x & (align - 1));
}

variable_types: x int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
test_bufring(argc, argv, envp);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
exit(0);
}

original_code:
int main(void)
{
 test_bufring();
 exit(0);
}

canonical_original_code:
int main()
{
 test_bufring();
 exit(0);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbp
unsigned __int64 v4; // rax
double v6; // [rsp+8h] [rbp-40h]
pthread_t th; // [rsp+10h] [rbp-38h] BYREF
pthread_t newthread; // [rsp+18h] [rbp-30h] BYREF
char arg[40]; // [rsp+20h] [rbp-28h] BYREF

if ( argc == 4 )
{
iterations = strtoul(argv[1], 0LL, 0);
v3 = strtoul(argv[2], 0LL, 0);
rb_size = v3;
v4 = strtoul(argv[3], 0LL, 0);
e_size = v4;
if ( v3 > 0xF )
{
if ( v4 <= 0x2718 )
{
if ( !(unsigned int)ring_init(arg, v3, 0LL) )
{
start = clock();
if ( !pthread_create(&newthread, 0LL, consumer, arg) )
{
if ( !pthread_create(&th, 0LL, producer, arg) )
{
if ( !pthread_join(th, 0LL) )
{
if ( !pthread_join(newthread, 0LL) )
{
end = clock();
v6 = (double)((int)end - (int)start) / 1000000.0;
ringops = 1;
start = clock();
if ( !pthread_create(&newthread, 0LL, consumer, arg) )
{
if ( !pthread_create(&th, 0LL, producer, arg) )
{
if ( !pthread_join(th, 0LL) )
{
if ( !pthread_join(newthread, 0LL) )
{
end = clock();
printf(
"dt=%fs, nsecs per msg: %g\n",
(double)((int)end - (int)start) / 1000000.0 - v6,
((double)((int)end - (int)start) / 1000000.0 - v6) * 1000000000.0 / (double)iterations);
printf("overruns %d underruns %d\n", overruns, underruns);
exit(0);
}
_assert_fail("!pthread_join(c, NULL)", "mttest.c", 0x64u, "main");
}
_assert_fail("!pthread_join(p, NULL)", "mttest.c", 0x63u, "main");
}
_assert_fail("!pthread_create(&p, NULL, producer, rb)", "mttest.c", 0x62u, "main");
}
_assert_fail("!pthread_create(&c, NULL, consumer, rb)", "mttest.c", 0x61u, "main");
}
_assert_fail("!pthread_join(c, NULL)", "mttest.c", 0x5Au, "main");
}
_assert_fail("!pthread_join(p, NULL)", "mttest.c", 0x59u, "main");
}
_assert_fail("!pthread_create(&p, NULL, producer, rb)", "mttest.c", 0x58u, "main");
}
_assert_fail("!pthread_create(&c, NULL, consumer, rb)", "mttest.c", 0x57u, "main");
}
_assert_fail("ring_init(rb, rb_size, 0) == 0", "mttest.c", 0x55u, "main");
}
_assert_fail("e_size <= sizeof(elem_t)", "mttest.c", 0x53u, "main");
}
_assert_fail("rb_size >= 16", "mttest.c", 0x52u, "main");
}
fprintf(stderr, "%s: <iterations> <buffer size> <elemnt size>\n", *argv);
return 1;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Nokia5110_Initialize("/dev/spidev0.0", 24LL, 25LL);
Nokia5110_RPi();
sleep(2u);
Nokia5110_DrawString(0LL, 0LL, "RPi-Nokia5110\n\n hello world");
Nokia5110_Flush();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func10("/dev/spidev0.0", 24LL, 25LL);
func7();
sleep(2u);
func12(0LL, 0LL, "RPi-Nokia5110\n\n hello world");
func9();
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
  Nokia5110_Initialize(("/dev/spidev0.0"), (24), (25));
  Nokia5110_RPi();
  sleep(2);
  Nokia5110_DrawString(0, 0, "RPi-Nokia5110\n\n hello world");
  Nokia5110_Flush();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  Nokia5110_Initialize(("/dev/spidev0.0"), (24), (25));
  Nokia5110_RPi();
  sleep(2);
  Nokia5110_DrawString(0, 0, "RPi-Nokia5110\n\n hello world");
  Nokia5110_Flush();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 Nokia5110_RPi()
{
tbuff_ = 0x80;
byte_4044C1 = 64;
gpio_write((unsigned int)dc_pin_, 0LL);
RPiSPI_Transfer(&tbuff_, &rbuff_, 2LL);
gpio_write((unsigned int)dc_pin_, 1LL);
return RPiSPI_Transfer(&rpi_logo_, &rbuff_, 504LL);
}

canonical_decompiled_code:
__int64 func7()
{
tbuff_ = 0x80;
byte_4044C1 = 64;
func18((unsigned int)dc_pin_, 0LL);
func23(&tbuff_, &rbuff_, 2LL);
func18((unsigned int)dc_pin_, 1LL);
return func23(&rpi_logo_, &rbuff_, 504LL);
}

original_code:
void Nokia5110_RPi(void)
{
  tbuff_[0] = 0x80;
  tbuff_[1] = 0x40;
  gpio_write(dc_pin_, 0);
  RPiSPI_Transfer(tbuff_, rbuff_, 2);
  gpio_write(dc_pin_, 1);
  RPiSPI_Transfer(rpi_logo_, rbuff_, sizeof(rpi_logo_));
  return;
}

canonical_original_code:
void Nokia5110_RPi()
{
  tbuff_[0] = 0x80;
  tbuff_[1] = 0x40;
  gpio_write(dc_pin_, 0);
  RPiSPI_Transfer(tbuff_, rbuff_, 2);
  gpio_write(dc_pin_, 1);
  RPiSPI_Transfer(rpi_logo_, rbuff_, sizeof(rpi_logo_));
  return;
}


decompiled_code:
char *Nokia5110_Clear()
{
char *result; // rax

result = &vram_;
do
*result++ = 0;
while ( result != (char *)&unk_4042B8 );
return result;
}

canonical_decompiled_code:
char *func8()
{
char *result; // rax

result = &vram_;
do
*result++ = 0;
while ( result != (char *)&unk_4042B8 );
return result;
}

original_code:
void Nokia5110_Clear(void)
{
  int i, j;
  for(i = 0; i < sizeof(vram_); i++)
    vram_[i] = 0;
  return;
}

canonical_original_code:
void Nokia5110_Clear()
{
  int i; int j;
  for(i = 0; i < sizeof(vram_); i++)
    vram_[i] = 0;
  return;
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 Nokia5110_Flush()
{
tbuff_ = 0x80;
byte_4044C1 = 64;
gpio_write((unsigned int)dc_pin_, 0LL);
RPiSPI_Transfer(&tbuff_, &rbuff_, 2LL);
gpio_write((unsigned int)dc_pin_, 1LL);
return RPiSPI_Transfer(&vram_, &rbuff_, 504LL);
}

canonical_decompiled_code:
__int64 func9()
{
tbuff_ = 0x80;
byte_4044C1 = 64;
func18((unsigned int)dc_pin_, 0LL);
func23(&tbuff_, &rbuff_, 2LL);
func18((unsigned int)dc_pin_, 1LL);
return func23(&vram_, &rbuff_, 504LL);
}

original_code:
void Nokia5110_Flush(void)
{
  tbuff_[0] = 0x80;
  tbuff_[1] = 0x40;
  gpio_write(dc_pin_, 0);
  RPiSPI_Transfer(tbuff_, rbuff_, 2);
  gpio_write(dc_pin_, 1);
  RPiSPI_Transfer(vram_, rbuff_, sizeof(vram_));
  return;
}

canonical_original_code:
void Nokia5110_Flush()
{
  tbuff_[0] = 0x80;
  tbuff_[1] = 0x40;
  gpio_write(dc_pin_, 0);
  RPiSPI_Transfer(tbuff_, rbuff_, 2);
  gpio_write(dc_pin_, 1);
  RPiSPI_Transfer(vram_, rbuff_, sizeof(vram_));
  return;
}


decompiled_code:
__int64 __fastcall Nokia5110_Initialize(__int64 a1, int a2, int a3)
{
reset_pin_ = a2;
dc_pin_ = a3;
setup_io();
output_gpio((unsigned int)reset_pin_);
output_gpio((unsigned int)dc_pin_);
gpio_write((unsigned int)reset_pin_, 0LL);
usleep(0x186A0u);
gpio_write((unsigned int)reset_pin_, 1LL);
RPiSPI_Open(a1, 0LL, 8LL, 2000000LL, 0LL);
tbuff_ = 33;
byte_4044C1 = -112;
byte_4044C2 = 32;
byte_4044C3 = 12;
gpio_write((unsigned int)dc_pin_, 0LL);
RPiSPI_Transfer(&tbuff_, &rbuff_, 4LL);
Nokia5110_Clear();
return Nokia5110_Flush();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, int a3)
{
reset_pin_ = a2;
dc_pin_ = a3;
func19();
func14((unsigned int)reset_pin_);
func14((unsigned int)dc_pin_);
func18((unsigned int)reset_pin_, 0LL);
usleep(0x186A0u);
func18((unsigned int)reset_pin_, 1LL);
func32(a1, 0LL, 8LL, 2000000LL, 0LL);
tbuff_ = 33;
byte_4044C1 = -112;
byte_4044C2 = 32;
byte_4044C3 = 12;
func18((unsigned int)dc_pin_, 0LL);
func23(&tbuff_, &rbuff_, 4LL);
func8();
return func9();
}

original_code:
void Nokia5110_Initialize(const char *spidev, int reset_pin, int dc_pin)
{
  reset_pin_ = reset_pin;
  dc_pin_ = dc_pin;
  setup_io();
  output_gpio(reset_pin_);
  output_gpio(dc_pin_);
  gpio_write(reset_pin_, 0);
  usleep(100000);
  gpio_write(reset_pin_, 1);
  RPiSPI_Open(spidev, 0, 8, 2000000, 0);
  tbuff_[0] = 0x21;
  tbuff_[1] = 0x90;
  tbuff_[2] = 0x20;
  tbuff_[3] = 0x0C;
  gpio_write(dc_pin_, 0);
  RPiSPI_Transfer(tbuff_, rbuff_, 4);
  Nokia5110_Clear();
  Nokia5110_Flush();
  return;
}

canonical_original_code:
void Nokia5110_Initialize(char *spidev, int reset_pin, int dc_pin)
{
  reset_pin_ = reset_pin;
  dc_pin_ = dc_pin;
  setup_io();
  output_gpio(reset_pin_);
  output_gpio(dc_pin_);
  gpio_write(reset_pin_, 0);
  usleep(100000);
  gpio_write(reset_pin_, 1);
  RPiSPI_Open(spidev, 0, 8, 2000000, 0);
  tbuff_[0] = 0x21;
  tbuff_[1] = 0x90;
  tbuff_[2] = 0x20;
  tbuff_[3] = 0x0C;
  gpio_write(dc_pin_, 0);
  RPiSPI_Transfer(tbuff_, rbuff_, 4);
  Nokia5110_Clear();
  Nokia5110_Flush();
  return;
}

variable_types:
spidev
char *


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

result = (unsigned int)(a3 - 32);
if ( (unsigned __int8)(a3 - 32) <= 0x5Eu )
{
for ( result = 0LL; result != 6; ++result )
vram_[84 * a2 + 6 * a1 + result] = *(_BYTE *)(result + 6LL * (char)a3 + 4202368);
}
return result;
}

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

result = (unsigned int)(a3 - 32);
if ( (unsigned __int8)(a3 - 32) <= 0x5Eu )
{
for ( result = 0LL; result != 6; ++result )
vram_[84 * a2 + 6 * a1 + result] = *(_BYTE *)(result + 6LL * (char)a3 + 4202368);
}
return result;
}

original_code:
void Nokia5110_DrawChar(int x, int y, char ch)
{
  int j;
  if(' ' <= ch && ch <= '~')
    for(j = 0; j < FONT_WIDTH; j++)
      vram_[y * LCD_WIDTH + x * FONT_WIDTH + j] = ascii_[ch - ' '][j];
}

variable_types: y int

variable_types: ch char


decompiled_code:
__int64 __fastcall Nokia5110_DrawString(int a1, int a2, _BYTE *a3)
{
_BYTE *v5; // rbx
char v6; // dl
__int64 result; // rax

v5 = a3;
v6 = *a3;
if ( v6 )
{
while ( 1 )
{
if ( v6 == 10 )
{
++a2;
a1 = 0;
}
else if ( v6 > 10 )
{
if ( v6 != 13 )
{
LABEL_13:
result = Nokia5110_DrawChar(a1++, a2, v6);
if ( a1 == 14 )
{
++a2;
a1 = 0;
}
goto LABEL_4;
}
a1 = 0;
}
else if ( v6 == 8 )
{
result = a1 > 0;
a1 -= result;
}
else if ( v6 != 9 )
{
goto LABEL_13;
}
LABEL_4:
if ( a2 != 6 )
{
v6 = *++v5;
if ( *v5 )
continue;
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2, _BYTE *a3)
{
_BYTE *v5; // rbx
char v6; // dl
__int64 result; // rax

v5 = a3;
v6 = *a3;
if ( v6 )
{
while ( 1 )
{
if ( v6 == 10 )
{
++a2;
a1 = 0;
}
else if ( v6 > 10 )
{
if ( v6 != 13 )
{
LABEL_13:
result = func11(a1++, a2, v6);
if ( a1 == 14 )
{
++a2;
a1 = 0;
}
goto LABEL_4;
}
a1 = 0;
}
else if ( v6 == 8 )
{
result = a1 > 0;
a1 -= result;
}
else if ( v6 != 9 )
{
goto LABEL_13;
}
LABEL_4:
if ( a2 != 6 )
{
v6 = *++v5;
if ( *v5 )
continue;
}
return result;
}
}
return result;
}

original_code:
void Nokia5110_DrawString(int x, int y, const char *str)
{
  while(*str != '\0')
  {
    switch(*str)
    {
    case '\b': if(1 <= x) x--; break;
    case '\r': x = 0; break;
    case '\n': x = 0; y++; break;
    case '\t': break;
    default:
      Nokia5110_DrawChar(x, y, *str);
      if(++x == COLUMNS){ x = 0; y++; }
    }
    if(y == ROWS) break;
    str++;
  }
  return;
}

canonical_original_code:
void Nokia5110_DrawString(int x, int y, char *str)
{
  while(*str != '\0')
  {
    switch(*str)
    {
    case '\b': if(1 <= x) x--; break;
    case '\r': x = 0; break;
    case '\n': x = 0; y++; break;
    case '\t': break;
    default:
      Nokia5110_DrawChar(x, y, *str);
      if(++x == COLUMNS){ x = 0; y++; }
    }
    if(y == ROWS) break;
    str++;
  }
  return;
}


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

result = 0LL;
if ( a1 <= 0x19 )
result = (unsigned int)valid_port[a1];
return result;
}

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

result = 0LL;
if ( a1 <= 0x19 )
result = (unsigned int)valid_port[a1];
return result;
}

original_code:
int port_avail(int port)
{
 if ((port < 0) || (port > 25))
  return (0);
 return ((int)valid_port[port]);
}

variable_types: port int


decompiled_code:
__int64 __fastcall gpio_read(char a1)
{
__int64 result; // rax

result = port_avail(a1);
if ( (_DWORD)result )
result = (*(_DWORD *)(gpio + 52) & (1 << a1)) != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(char a1)
{
__int64 result; // rax

result = func16(a1);
if ( (_DWORD)result )
result = (*(_DWORD *)(gpio + 52) & (1 << a1)) != 0;
return result;
}

original_code:
int gpio_read(int port)
{
 if (!port_avail(port))
  return(0);
 return( (*(gpio+13) & (1<<port)) ? 1 : 0);
}


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

result = port_avail(a1);
if ( (_DWORD)result )
{
if ( a2 )
{
result = (unsigned int)(1 << a1);
*(_DWORD *)(gpio + 28) = result;
}
else
{
result = (unsigned int)(1 << a1);
*(_DWORD *)(gpio + 40) = result;
}
}
return result;
}

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

result = func16(a1);
if ( (_DWORD)result )
{
if ( a2 )
{
result = (unsigned int)(1 << a1);
*(_DWORD *)(gpio + 28) = result;
}
else
{
result = (unsigned int)(1 << a1);
*(_DWORD *)(gpio + 40) = result;
}
}
return result;
}

original_code:
void gpio_write(int port, int data)
{
 if (!port_avail(port))
  return;
 if (data == 0)
  *(gpio+10) = 1<<port;
 else *(gpio+7) = 1<<port;
}

variable_types: data int


decompiled_code:
void setup_io()
{
int v0; // ebx
char *v1; // rax
void *v2; // rax

if ( !initialized_0 )
{
initialized_0 = 1;
v0 = open("/dev/mem", 1052674);
mem_fd = v0;
if ( v0 < 0 )
{
puts("can't open /dev/mem ");
exit(-1);
}
v1 = malloc(0x1FFFuLL);
gpio_mem = v1;
if ( !v1 )
{
puts("allocation error ");
exit(-1);
}
if ( ((unsigned __int16)v1 & 0xFFF) != 0 )
gpio_mem = (char *)v1 - ((unsigned __int16)v1 & 0xFFF) + 4096;
v2 = mmap(gpio_mem, 0x1000uLL, 3, 17, v0, 538968064LL);
gpio_map = (__int64)v2;
if ( (__int64)v2 < 0 )
{
printf("mmap error %d\n", (unsigned int)v2);
exit(-1);
}
gpio = (__int64)v2;
}
}

canonical_decompiled_code:
void func19()
{
int v0; // ebx
char *v1; // rax
void *v2; // rax

if ( !initialized_0 )
{
initialized_0 = 1;
v0 = open("/dev/mem", 1052674);
mem_fd = v0;
if ( v0 < 0 )
{
puts("can't open /dev/mem ");
exit(-1);
}
v1 = malloc(0x1FFFuLL);
gpio_mem = v1;
if ( !v1 )
{
puts("allocation error ");
exit(-1);
}
if ( ((unsigned __int16)v1 & 0xFFF) != 0 )
gpio_mem = (char *)v1 - ((unsigned __int16)v1 & 0xFFF) + 4096;
v2 = mmap(gpio_mem, 0x1000uLL, 3, 17, v0, 538968064LL);
gpio_map = (__int64)v2;
if ( (__int64)v2 < 0 )
{
printf("mmap error %d\n", (unsigned int)v2);
exit(-1);
}
gpio = (__int64)v2;
}
}

original_code:
void setup_io()
{
  static int initialized = 0;
  if(initialized) return;
  initialized = 1;
  if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0)
  {
    printf("can't open /dev/mem \n");
    exit (-1);
  }
  if ((gpio_mem = (char *)malloc((4*1024) + ((4*1024)-1))) == ((void *)0))
  {
    printf("allocation error \n");
    exit (-1);
  }
  if ((unsigned long)gpio_mem % (4*1024))
   gpio_mem += (4*1024) - ((unsigned long)gpio_mem % (4*1024));
  gpio_map = (char *)mmap(
    (caddr_t)gpio_mem,
    (4*1024),
    0x1|0x2,
    0x01|0x10,
    mem_fd,
    (0x20000000 + 0x200000)
  );
  if ((long)gpio_map < 0)
  {
    printf("mmap error %d\n", (int)gpio_map);
    exit (-1);
  }
  gpio = (volatile unsigned *)gpio_map;
}

canonical_original_code:
void setup_io()
{
  static int initialized = 0;
  if(initialized) return;
  initialized = 1;
  if ((mem_fd = open("/dev/mem", 02|04010000) ) < 0)
  {
    printf("can't open /dev/mem \n");
    exit (-1);
  }
  if ((gpio_mem = (char *)malloc((4*1024) + ((4*1024)-1))) == ((void *)0))
  {
    printf("allocation error \n");
    exit (-1);
  }
  if ((unsigned long)gpio_mem % (4*1024))
   gpio_mem += (4*1024) - ((unsigned long)gpio_mem % (4*1024));
  gpio_map = (char *)mmap(
    (char *)gpio_mem,
    (4*1024),
    0x1|0x2,
    0x01|0x10,
    mem_fd,
    (0x20000000 + 0x200000)
  );
  if ((long)gpio_map < 0)
  {
    printf("mmap error %d\n", (int)gpio_map);
    exit (-1);
  }
  gpio = (unsigned int *)gpio_map;
}

variable_types: initialized int


decompiled_code:
int RPiSPI_Close()
{
return close(file_descriptor_);
}

canonical_decompiled_code:
int func20()
{
return close(file_descriptor_);
}

original_code:
void RPiSPI_Close(void)
{
  close(file_descriptor_);
}

canonical_original_code:
void RPiSPI_Close()
{
  close(file_descriptor_);
}


decompiled_code:
__int64 RPiSPI_IsOpen()
{
return (unsigned int)object_validity_;
}

canonical_decompiled_code:
__int64 func21()
{
return (unsigned int)object_validity_;
}

original_code:
int RPiSPI_IsOpen()
{
  return object_validity_;
}


decompiled_code:
__int64 RPiSPI_get_last_error()
{
return (unsigned int)last_error_;
}

canonical_decompiled_code:
__int64 func22()
{
return (unsigned int)last_error_;
}

original_code:
int RPiSPI_get_last_error(void)
{
  return last_error_;
}

canonical_original_code:
int RPiSPI_get_last_error()
{
  return last_error_;
}


decompiled_code:
int __fastcall RPiSPI_Transfer(__int64 a1, __int64 a2, int a3)
{
__int64 v4[2]; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+10h] [rbp-18h]
int v6; // [rsp+14h] [rbp-14h]
__int16 v7; // [rsp+18h] [rbp-10h]
char v8; // [rsp+1Ah] [rbp-Eh]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
v7 = delay_;
v6 = bits_per_sec_;
v8 = bits_per_word_;
return ioctl(file_descriptor_, 0x40206B00uLL, v4);
}

canonical_decompiled_code:
int __fastcall func23(__int64 a1, __int64 a2, int a3)
{
__int64 v4[2]; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+10h] [rbp-18h]
int v6; // [rsp+14h] [rbp-14h]
__int16 v7; // [rsp+18h] [rbp-10h]
char v8; // [rsp+1Ah] [rbp-Eh]

v4[0] = a1;
v4[1] = a2;
v5 = a3;
v7 = delay_;
v6 = bits_per_sec_;
v8 = bits_per_word_;
return ioctl(file_descriptor_, 0x40206B00uLL, v4);
}

original_code:
int RPiSPI_Transfer(const void *transmit_buffer, void *receive_buffer, size_t length)
{
  struct spi_ioc_transfer tr;
  tr.tx_buf = (unsigned long)transmit_buffer;
  tr.rx_buf = (unsigned long)receive_buffer;
  tr.len = length;
  tr.delay_usecs = delay_;
  tr.speed_hz = bits_per_sec_;
  tr.bits_per_word = bits_per_word_;
  return ioctl(file_descriptor_, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char[((((1)*(sizeof (struct spi_ioc_transfer))) < (1 << 14)) ? ((1)*(sizeof (struct spi_ioc_transfer))) : 0)])))) << ((0 +8)+8))), &tr);
}

canonical_original_code:
int RPiSPI_Transfer(void *transmit_buffer, void *receive_buffer, unsigned long length)
{
  struct spi_ioc_transfer tr;
  tr.tx_buf = (unsigned long)transmit_buffer;
  tr.rx_buf = (unsigned long)receive_buffer;
  tr.len = length;
  tr.delay_usecs = delay_;
  tr.speed_hz = bits_per_sec_;
  tr.bits_per_word = bits_per_word_;
  return ioctl(file_descriptor_, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((0)) << 0) | ((((sizeof(char [-1])))) << ((0 +8)+8))), &tr);
}

variable_types:
length
unsigned long

variable_types: struct spi_ioc_transfer { unsigned long long tx_buf; unsigned long long rx_buf; unsigned int len; unsigned int speed_hz; unsigned short delay_usecs; unsigned char bits_per_word; unsigned char cs_change; unsigned char tx_nbits; unsigned char rx_nbits; unsigned short pad; }


decompiled_code:
__int64 RPiSPI_get_mode()
{
int v0; // edx
__int64 result; // rax

v0 = ioctl(file_descriptor_, 0x80016B01uLL, &mode_);
result = (unsigned __int8)mode_;
if ( v0 == -1 )
{
last_error_ = 2;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func24()
{
int v0; // edx
__int64 result; // rax

v0 = ioctl(file_descriptor_, 0x80016B01uLL, &mode_);
result = (unsigned __int8)mode_;
if ( v0 == -1 )
{
last_error_ = 2;
result = 0xFFFFFFFFLL;
}
return result;
}

variable_types: ret int

return_type: unsigned char


decompiled_code:
int __fastcall RPiSPI_set_mode(char a1)
{
int result; // eax

mode_ = a1;
result = ioctl(file_descriptor_, 0x40016B01uLL, &mode_);
if ( result == -1 )
last_error_ = 3;
return result;
}

canonical_decompiled_code:
int __fastcall func25(char a1)
{
int result; // eax

mode_ = a1;
result = ioctl(file_descriptor_, 0x40016B01uLL, &mode_);
if ( result == -1 )
last_error_ = 3;
return result;
}

variable_types:
mode
unsigned char


decompiled_code:
__int64 RPiSPI_get_bits_per_word()
{
int v0; // edx
__int64 result; // rax

v0 = ioctl(file_descriptor_, 0x80016B03uLL, &bits_per_word_);
result = (unsigned __int8)bits_per_word_;
if ( v0 == -1 )
{
last_error_ = 4;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func26()
{
int v0; // edx
__int64 result; // rax

v0 = ioctl(file_descriptor_, 0x80016B03uLL, &bits_per_word_);
result = (unsigned __int8)bits_per_word_;
if ( v0 == -1 )
{
last_error_ = 4;
result = 0xFFFFFFFFLL;
}
return result;
}


decompiled_code:
int __fastcall RPiSPI_set_bits_per_word(char a1)
{
int result; // eax

bits_per_word_ = a1;
result = ioctl(file_descriptor_, 0x40016B03uLL, &bits_per_word_);
if ( result == -1 )
last_error_ = 5;
return result;
}

canonical_decompiled_code:
int __fastcall func27(char a1)
{
int result; // eax

bits_per_word_ = a1;
result = ioctl(file_descriptor_, 0x40016B03uLL, &bits_per_word_);
if ( result == -1 )
last_error_ = 5;
return result;
}

original_code:
int RPiSPI_set_bits_per_word(uint8_t bits_per_word)
{
  bits_per_word_ = bits_per_word;
  int ret = ioctl(file_descriptor_, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((3)) << 0) | ((((sizeof(__u8)))) << ((0 +8)+8))), &bits_per_word_);
  if(ret == -1) last_error_ = (0x05);
  return ret;
}

canonical_original_code:
int RPiSPI_set_bits_per_word(unsigned char bits_per_word)
{
  bits_per_word_ = bits_per_word;
  int ret = ioctl(file_descriptor_, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((3)) << 0) | ((((sizeof(__u8)))) << ((0 +8)+8))), &bits_per_word_);
  if(ret == -1) last_error_ = (0x05);
  return ret;
}


decompiled_code:
__int64 RPiSPI_get_bits_per_sec()
{
int v0; // edx
__int64 result; // rax

v0 = ioctl(file_descriptor_, 0x80046B04uLL, &bits_per_sec_);
result = (unsigned int)bits_per_sec_;
if ( v0 == -1 )
{
last_error_ = 6;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func28()
{
int v0; // edx
__int64 result; // rax

v0 = ioctl(file_descriptor_, 0x80046B04uLL, &bits_per_sec_);
result = (unsigned int)bits_per_sec_;
if ( v0 == -1 )
{
last_error_ = 6;
result = 0xFFFFFFFFLL;
}
return result;
}

return_type: unsigned int


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

bits_per_sec_ = a1;
result = ioctl(file_descriptor_, 0x40046B04uLL, &bits_per_sec_);
if ( result == -1 )
last_error_ = 7;
return result;
}

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

bits_per_sec_ = a1;
result = ioctl(file_descriptor_, 0x40046B04uLL, &bits_per_sec_);
if ( result == -1 )
last_error_ = 7;
return result;
}

original_code:
int RPiSPI_set_bits_per_sec(uint32_t bits_per_sec)
{
  bits_per_sec_ = bits_per_sec;
  int ret = ioctl(file_descriptor_, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((4)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &bits_per_sec_);
  if(ret == -1) last_error_ = (0x07);
  return ret;
}

canonical_original_code:
int RPiSPI_set_bits_per_sec(unsigned int bits_per_sec)
{
  bits_per_sec_ = bits_per_sec;
  int ret = ioctl(file_descriptor_, (((1U) << (((0 +8)+8)+14)) | ((('k')) << (0 +8)) | (((4)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &bits_per_sec_);
  if(ret == -1) last_error_ = (0x07);
  return ret;
}


decompiled_code:
__int64 RPiSPI_get_delay()
{
return (unsigned __int16)delay_;
}

canonical_decompiled_code:
__int64 func30()
{
return (unsigned __int16)delay_;
}

original_code:
uint16_t RPiSPI_get_delay(void)
{
  if(0 <= delay_)
  {
    return delay_;
  }
  else
  {
    last_error_ = (0x08);
    return -1;
  }
}

canonical_original_code:
unsigned short RPiSPI_get_delay()
{
  if(0 <= delay_)
  {
    return delay_;
  }
  else
  {
    last_error_ = (0x08);
    return -1;
  }
}

return_type: unsigned short


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

result = a1;
delay_ = a1;
return result;
}

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

result = a1;
delay_ = a1;
return result;
}

original_code:
uint16_t RPiSPI_set_delay(uint16_t delay)
{
  if(0 <= delay)
  {
    return (delay_ = delay);
  }
  else
  {
    last_error_ = (0x09);
    return -1;
  }
}

canonical_original_code:
unsigned short RPiSPI_set_delay(unsigned short delay)
{
  if(0 <= delay)
  {
    return (delay_ = delay);
  }
  else
  {
    last_error_ = (0x09);
    return -1;
  }
}

variable_types:
delay
unsigned short


decompiled_code:
__int64 __fastcall RPiSPI_Open(const char *a1, char a2, char a3, int a4, unsigned __int8 a5)
{
file_descriptor_ = open(a1, 2);
object_validity_ = file_descriptor_ != -1;
last_error_ = file_descriptor_ == -1;
RPiSPI_set_mode(a2);
RPiSPI_set_bits_per_word(a3);
RPiSPI_set_bits_per_sec(a4);
return RPiSPI_set_delay(a5);
}

canonical_decompiled_code:
__int64 __fastcall func32(const char *a1, char a2, char a3, int a4, unsigned __int8 a5)
{
file_descriptor_ = open(a1, 2);
object_validity_ = file_descriptor_ != -1;
last_error_ = file_descriptor_ == -1;
func25(a2);
func27(a3);
func29(a4);
return func31(a5);
}

original_code:
void RPiSPI_Open(const char* device, uint8_t mode, uint8_t bits_per_word, uint32_t bits_per_sec, uint8_t delay)
{
  file_descriptor_ = open(device, 02);
  object_validity_ = (file_descriptor_ != -1);
  if(!object_validity_)
    last_error_ = (0x01);
  else
    last_error_ = 0;
  RPiSPI_set_mode(mode);
  RPiSPI_set_bits_per_word(bits_per_word);
  RPiSPI_set_bits_per_sec(bits_per_sec);
  RPiSPI_set_delay(delay);
}

canonical_original_code:
void RPiSPI_Open(char *device, unsigned char mode, unsigned char bits_per_word, unsigned int bits_per_sec, unsigned char delay)
{
  file_descriptor_ = open(device, 02);
  object_validity_ = (file_descriptor_ != -1);
  if(!object_validity_)
    last_error_ = (0x01);
  else
    last_error_ = 0;
  RPiSPI_set_mode(mode);
  RPiSPI_set_bits_per_word(bits_per_word);
  RPiSPI_set_bits_per_sec(bits_per_sec);
  RPiSPI_set_delay(delay);
}

variable_types:
device
char *

variable_types:
delay
unsigned char


myget

repo: shurizzle/brainfuck

decompiled_code:
__int64 myget()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
struct termios v5; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

v0 = fileno(stdin);
tcgetattr(v0, &termios_p);
*(__m128i *)&v5.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v5.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v5.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v5.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v5.c_ospeed = termios_p.c_ospeed;
cfmakeraw(&termios_p);
v1 = fileno(stdin);
tcsetattr(v1, 0, &termios_p);
v2 = getchar();
v3 = fileno(stdin);
tcsetattr(v3, 0, &v5);
return v2;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
struct termios v5; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

v0 = fileno(stdin);
tcgetattr(v0, &termios_p);
*(__m128i *)&v5.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v5.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v5.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v5.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v5.c_ospeed = termios_p.c_ospeed;
cfmakeraw(&termios_p);
v1 = fileno(stdin);
tcsetattr(v1, 0, &termios_p);
v2 = getchar();
v3 = fileno(stdin);
tcsetattr(v3, 0, &v5);
return v2;
}

original_code:
char
myget (void) {
    struct termios t, old;
    char ch;
    tcgetattr(fileno(stdin), &t);
    old = t;
    cfmakeraw(&t);
    tcsetattr(fileno(stdin), 0, &t);
    ch = getchar();
    tcsetattr(fileno(stdin), 0, &old);
    return ch;
}

canonical_original_code:
char myget() {
    struct termios t; struct termios old;
    char ch;
    tcgetattr(fileno(stdin), &t);
    old = t;
    cfmakeraw(&t);
    tcsetattr(fileno(stdin), 0, &t);
    ch = getchar();
    tcsetattr(fileno(stdin), 0, &old);
    return ch;
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: char


decompiled_code:
__int64 get_width()
{
int v0; // eax
int v1; // edx
__int64 result; // rax
int v3; // eax
char v4[2]; // [rsp+8h] [rbp-10h] BYREF
unsigned __int16 v5; // [rsp+Ah] [rbp-Eh]

v0 = fileno(_bss_start);
v1 = isatty(v0);
result = 80LL;
if ( v1 )
{
v3 = fileno(_bss_start);
ioctl(v3, 0x5413uLL, v4);
result = v5;
if ( !v5 )
result = 80LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
int v1; // edx
__int64 result; // rax
int v3; // eax
char v4[2]; // [rsp+8h] [rbp-10h] BYREF
unsigned __int16 v5; // [rsp+Ah] [rbp-Eh]

v0 = fileno(_bss_start);
v1 = isatty(v0);
result = 80LL;
if ( v1 )
{
v3 = fileno(_bss_start);
ioctl(v3, 0x5413uLL, v4);
result = v5;
if ( !v5 )
result = 80LL;
}
return result;
}

original_code:
unsigned short
get_width() {
    struct winsize w;
    if (!isatty(fileno(stdout))) {
        return 80;
    }
    ioctl(fileno(stdout), 0x5413, &w);
    return w.ws_col < 1 ? 80 : w.ws_col;
}

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
int __fastcall print_debug(unsigned int *a1)
{
unsigned int *v1; // r12
__int64 v2; // rbx
char *v3; // r13
unsigned __int64 v4; // r14
unsigned int *v5; // rax
unsigned int *v6; // rbx
int v7; // ebp
int result; // eax
int v9; // edi

v1 = a1;
v2 = (unsigned int)get_width();
v3 = (char *)calloc(9uLL, 1uLL);
sprintf(v3, "0x%%-%ux", 10LL);
LODWORD(v4) = 1;
if ( (unsigned __int16)v2 > 0xDu )
v4 = (2454267027u * ((unsigned __int64)(v2 << 48) >> 49)) >> 34;
v5 = a1;
do
{
v6 = v5;
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
}
while ( v5 );
v7 = 0;
do
{
if ( v6 == v1 )
{
putchar(91);
printf(v3, *v1);
v9 = 93;
}
else
{
putchar(32);
printf(v3, *v1);
v9 = 32;
}
result = putchar(v9);
if ( (_DWORD)v4 == ++v7 )
{
result = putchar(10);
v7 = 0;
}
v6 = (unsigned int *)*((_QWORD *)v6 + 2);
}
while ( v6 );
if ( v7 )
result = putchar(10);
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned int *a1)
{
unsigned int *v1; // r12
__int64 v2; // rbx
char *v3; // r13
unsigned __int64 v4; // r14
unsigned int *v5; // rax
unsigned int *v6; // rbx
int v7; // ebp
int result; // eax
int v9; // edi

v1 = a1;
v2 = (unsigned int)func8();
v3 = (char *)calloc(9uLL, 1uLL);
sprintf(v3, "0x%%-%ux", 10LL);
LODWORD(v4) = 1;
if ( (unsigned __int16)v2 > 0xDu )
v4 = (2454267027u * ((unsigned __int64)(v2 << 48) >> 49)) >> 34;
v5 = a1;
do
{
v6 = v5;
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
}
while ( v5 );
v7 = 0;
do
{
if ( v6 == v1 )
{
putchar(91);
printf(v3, *v1);
v9 = 93;
}
else
{
putchar(32);
printf(v3, *v1);
v9 = 32;
}
result = putchar(v9);
if ( (_DWORD)v4 == ++v7 )
{
result = putchar(10);
v7 = 0;
}
v6 = (unsigned int *)*((_QWORD *)v6 + 2);
}
while ( v6 );
if ( v7 )
result = putchar(10);
return result;
}

original_code:
void
print_debug(Stack *current) {
    Stack *stack = current;
    unsigned int el = (unsigned int) log10((0x7fffffff * 2U + 1U)) + 1;
    unsigned int epl = ((unsigned int) get_width()) / (el + 4);
    unsigned int ce = 0;
    const char *template = (const char *) calloc(log10(el) + 8, sizeof(char));
    sprintf((char *) template, "0x%%-%ux", el);
    epl = epl < 1 ? 1 : epl;
    while (stack->prev != ((void *)0)) {
        stack = stack->prev;
    }
    do {
        putchar(stack == current ? '[' : ' ');
        printf(template, current->mem);
        putchar(stack == current ? ']' : ' ');
        if (++ce == epl) {
            ce = 0;
            putchar(10);
        }
    } while ((stack = stack->next) != ((void *)0));
    if (ce != 0) {
        putchar(10);
    }
}

canonical_original_code:
void print_debug(struct Stack *current) {
    struct Stack *stack = current;
    unsigned int el = (unsigned int) log10((0x7fffffff * 2U + 1U)) + 1;
    unsigned int epl = ((unsigned int) get_width()) / (el + 4);
    unsigned int ce = 0;
    char *template = (const char *) calloc(log10(el) + 8, sizeof(char));
    sprintf((char *) template, "0x%%-%ux", el);
    epl = epl < 1 ? 1 : epl;
    while (stack->prev != ((void *)0)) {
        stack = stack->prev;
    }
    do {
        putchar(stack == current ? '[' : ' ');
        printf(template, current->mem);
        putchar(stack == current ? ']' : ' ');
        if (++ce == epl) {
            ce = 0;
            putchar(10);
        }
    } while ((stack = stack->next) != ((void *)0));
    if (ce != 0) {
        putchar(10);
    }
}

variable_types: struct Stack { unsigned int mem; struct Stack *prev; struct Stack *next; } *

variable_types:
el
unsigned int

variable_types:
epl
unsigned int

variable_types:
ce
unsigned int

variable_types:
template
char *


JmpNew

decompiled_code:
void *JmpNew()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func10()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
Jmp *
JmpNew (void)
{
    return (Jmp *) calloc (1, sizeof (Jmp));
}

canonical_original_code:
struct Jmp *JmpNew()
{
    return (struct Jmp *) calloc (1, sizeof (Jmp));
}

return_type: struct Jmp { long offset; struct Jmp *next; } *


JmpGet

decompiled_code:
__int64 __fastcall JmpGet(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
long int
JmpGet (Jmp * jmps)
{
    return jmps->offset;
}

canonical_original_code:
long JmpGet(struct Jmp *jmps)
{
    return jmps->offset;
}

variable_types: struct Jmp { long offset; struct Jmp *next; } *

return_type: long


JmpFreeSingle

decompiled_code:
void __fastcall JmpFreeSingle(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func12(void *a1)
{
free(a1);
}

original_code:
void
JmpFreeSingle (Jmp * jmp)
{
    free (jmp);
}

canonical_original_code:
void JmpFreeSingle(struct Jmp *jmp)
{
    free (jmp);
}

user_defined_types: struct Jmp { long offset; struct Jmp *next; }


JmpDeleteFirst

decompiled_code:
void __fastcall JmpDeleteFirst(__int64 a1)
{
void *v1; // rax

v1 = *(void **)a1;
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
JmpFreeSingle(v1);
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
void *v1; // rax

v1 = *(void **)a1;
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
func12(v1);
}

original_code:
void
JmpDeleteFirst (Jmp ** jmps)
{
    Jmp * tmp = *jmps;
    *jmps = (*jmps)->next;
    JmpFreeSingle (tmp);
}

canonical_original_code:
void JmpDeleteFirst(struct Jmp **jmps)
{
    struct Jmp *tmp = *jmps;
    *jmps = (*jmps)->next;
    JmpFreeSingle (tmp);
}

variable_types: struct Jmp { long offset; struct Jmp *next; } **


StackNew

decompiled_code:
void *StackNew()
{
return calloc(1uLL, 0x18uLL);
}

canonical_decompiled_code:
void *func15()
{
return calloc(1uLL, 0x18uLL);
}

original_code:
Stack *
StackNew (void)
{
    return (Stack *) calloc (1, sizeof (Stack));
}

canonical_original_code:
struct Stack *StackNew()
{
    return (struct Stack *) calloc (1, sizeof (Stack));
}

return_type: struct Stack { unsigned int mem; struct Stack *prev; struct Stack *next; } *


StackGet

decompiled_code:
__int64 __fastcall StackGet(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int *a1)
{
return *a1;
}

original_code:
int
StackGet (Stack * stack)
{
    return stack->mem;
}

canonical_original_code:
int StackGet(struct Stack *stack)
{
    return stack->mem;
}

user_defined_types: struct Stack { unsigned int mem; struct Stack *prev; struct Stack *next; }


StackFreeSingle

decompiled_code:
void __fastcall StackFreeSingle(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func22(void *a1)
{
free(a1);
}

original_code:
void
StackFreeSingle (Stack * stack)
{
    free (stack);
}

canonical_original_code:
void StackFreeSingle(struct Stack *stack)
{
    free (stack);
}


repo: sibberovski/game-of-life

decompiled_code:
void *__fastcall game_alloc(__int64 a1, int a2, int a3)
{
void *result; // rax
__int64 v4; // rbx
_QWORD *v5; // rbp

*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
result = malloc(8LL * a3);
*(_QWORD *)a1 = result;
if ( a2 > 0 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)(*(_QWORD *)a1 + v4);
result = malloc(a2);
*v5 = result;
v4 += 8LL;
}
while ( v4 != 8LL * (unsigned int)a2 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, int a2, int a3)
{
void *result; // rax
__int64 v4; // rbx
_QWORD *v5; // rbp

*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = a3;
result = malloc(8LL * a3);
*(_QWORD *)a1 = result;
if ( a2 > 0 )
{
v4 = 0LL;
do
{
v5 = (_QWORD *)(*(_QWORD *)a1 + v4);
result = malloc(a2);
*v5 = result;
v4 += 8LL;
}
while ( v4 != 8LL * (unsigned int)a2 );
}
return result;
}

original_code:
void game_alloc(game* g, int width, int height)
{
 int i;
 g->width = width;
 g->height = height;
 g->board = malloc(sizeof(char*) * height);
 for (i = 0; i < width; ++i) {
  g->board[i] = malloc(sizeof(char) * width);
 }
}

canonical_original_code:
void game_alloc(struct game *g, int width, int height)
{
 int i;
 g->width = width;
 g->height = height;
 g->board = malloc(sizeof(char *) * height);
 for (i = 0; i < width; ++i) {
  g->board[i] = malloc(sizeof(char) * width);
 }
}

variable_types: struct game { char **board; int width; int height; } *

variable_types: width int

variable_types: height int

variable_types: i int


original_code:
void init_game(game *g)
{
 int x, y;
 for (y = 0; y < g->height; ++y) {
  for (x = 0; x < g->width; ++x) {
   if ((rand() % 100) > 92) {
    g->board[y][x] = '#';
   }
   else {
    g->board[y][x] = ' ';
   }
  }
 }
}

canonical_original_code:
void init_game(struct game *g)
{
 int x; int y;
 for (y = 0; y < g->height; ++y) {
  for (x = 0; x < g->width; ++x) {
   if ((rand() % 100) > 92) {
    g->board[y][x] = '#';
   }
   else {
    g->board[y][x] = ' ';
   }
  }
 }
}

variable_types: x int

variable_types: y int

user_defined_types: struct game { char **board; int width; int height; }


original_code:
int alive_neighbours(game *g, int x, int y)
{
 int alive = 0;
 int x_offs, y_offs;
 for (y_offs = -1; y_offs <= 1; ++y_offs) {
  for (x_offs = -1; x_offs <= 1; ++x_offs) {
   if ((x + x_offs >= 0) && (x + x_offs < g->width) &&
    (y + y_offs >= 0) && (y + y_offs < g->height))
   {
    if ((x_offs == 0) && (y_offs == 0)) {
     continue;
    }
    if (g->board[y + y_offs][x + x_offs] == '#') {
     ++alive;
    }
   }
  }
 }
 return alive;
}

canonical_original_code:
int alive_neighbours(struct game *g, int x, int y)
{
 int alive = 0;
 int x_offs; int y_offs;
 for (y_offs = -1; y_offs <= 1; ++y_offs) {
  for (x_offs = -1; x_offs <= 1; ++x_offs) {
   if ((x + x_offs >= 0) && (x + x_offs < g->width) &&
    (y + y_offs >= 0) && (y + y_offs < g->height))
   {
    if ((x_offs == 0) && (y_offs == 0)) {
     continue;
    }
    if (g->board[y + y_offs][x + x_offs] == '#') {
     ++alive;
    }
   }
  }
 }
 return alive;
}

variable_types: alive int


cleanup

decompiled_code:
void __fastcall __noreturn cleanup(int status)
{
endwin();
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(int status)
{
endwin();
exit(status);
}

original_code:
void cleanup(int error)
{
 endwin();
 exit(error);
}

variable_types: error int


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

result = *(void **)(a2 + 8);
if ( (void *)a1[1] != result )
{
fwrite("copy_game handed games of different sizes. Exiting\n", 1uLL, 0x33uLL, stderr);
cleanup(1);
}
for ( i = 0LL; *(_DWORD *)(a2 + 12) > (int)i; ++i )
result = memcpy(*(void **)(*a1 + 8 * i), *(const void **)(*(_QWORD *)a2 + 8 * i), *(int *)(a2 + 8));
return result;
}

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

result = *(void **)(a2 + 8);
if ( (void *)a1[1] != result )
{
fwrite("copy_game handed games of different sizes. Exiting\n", 1uLL, 0x33uLL, stderr);
func10(1);
}
for ( i = 0LL; *(_DWORD *)(a2 + 12) > (int)i; ++i )
result = memcpy(*(void **)(*a1 + 8 * i), *(const void **)(*(_QWORD *)a2 + 8 * i), *(int *)(a2 + 8));
return result;
}

original_code:
void copy_game(game *to, game *from)
{
 if ((to->width != from->width) || (to->height != from->height)) {
  fprintf(stderr, "copy_game handed games of different sizes. Exiting\n");
  cleanup(1);
 }
 int i;
 for (i = 0; i < from->height; ++i) {
  memcpy(to->board[i], from->board[i], from->width);
 }
}

canonical_original_code:
void copy_game(struct game *to, struct game *from)
{
 if ((to->width != from->width) || (to->height != from->height)) {
  fprintf(stderr, "copy_game handed games of different sizes. Exiting\n");
  cleanup(1);
 }
 int i;
 for (i = 0; i < from->height; ++i) {
  memcpy(to->board[i], from->board[i], from->width);
 }
}

variable_types:
from
struct game *


main

original_code:
int main(int argc, char **argv)
{
 int height, width;
 int x, y;
 game current_game;
 game prev_game;
 srand(time(((void *)0)));
 initscr();
 (height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 game_alloc(&current_game, width, height);
 game_alloc(&prev_game, width, height);
 init_game(&current_game);
 copy_game(&prev_game, &current_game);
 for (;;) {
  wmove(stdscr,(0),(0));
  for (y = 0; y < current_game.height; ++y) {
   for (x = 0; x < current_game.width; ++x) {
    waddch(stdscr,(current_game.board[y][x]));
   }
  }
  for (y = 0; y < current_game.height; ++y) {
   for (x = 0; x < current_game.width; ++x) {
    int alive = alive_neighbours(&current_game, x, y);
    if ((alive < 2) || (alive > 3)) {
     current_game.board[y][x] = ' ';
    }
    else if ((alive == 3) || (alive == 2 && current_game.board[y][x] == '#')) {
     current_game.board[y][x] = '#';
    }
   }
  }
  copy_game(&prev_game, &current_game);
  wrefresh(stdscr);
  usleep(200000);
 }
 cleanup(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int height; int width;
 int x; int y;
 struct game current_game;
 struct game prev_game;
 srand(time(((void *)0)));
 initscr();
 (height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 game_alloc(&current_game, width, height);
 game_alloc(&prev_game, width, height);
 init_game(&current_game);
 copy_game(&prev_game, &current_game);
 for (;;) {
  wmove(stdscr,(0),(0));
  for (y = 0; y < current_game.height; ++y) {
   for (x = 0; x < current_game.width; ++x) {
    waddch(stdscr,(current_game.board[y][x]));
   }
  }
  for (y = 0; y < current_game.height; ++y) {
   for (x = 0; x < current_game.width; ++x) {
    int alive = alive_neighbours(&current_game, x, y);
    if ((alive < 2) || (alive > 3)) {
     current_game.board[y][x] = ' ';
    }
    else if ((alive == 3) || (alive == 2 && current_game.board[y][x] == '#')) {
     current_game.board[y][x] = '#';
    }
   }
  }
  copy_game(&prev_game, &current_game);
  wrefresh(stdscr);
  usleep(200000);
 }
 cleanup(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct game { char **board; int width; int height; }


repo: sidmanu/LibLog

decompiled_code:
void *log_entry_init()
{
return malloc(0x218uLL);
}

canonical_decompiled_code:
void *func6()
{
return malloc(0x218uLL);
}

original_code:
log_entry_t*
log_entry_init()
{
 log_entry_t *ent;
 ent = (log_entry_t *) malloc (sizeof(log_entry_t));
 if (!ent) {
  return ((void *)0);
 }
 return ent;
}

canonical_original_code:
struct log_entry_ *log_entry_init()
{
 struct log_entry_ *ent;
 ent = (struct log_entry_ *) malloc (sizeof(log_entry_t));
 if (!ent) {
  return ((void *)0);
 }
 return ent;
}

variable_types: struct log_entry_ { struct timeval { long tv_sec; long tv_usec; } time; enum log_level { LOG_CRITICAL=0, LOG_ERROR=1, LOG_WARNING=2, LOG_DEBUG=3, LOG_INFO=4, LOG_VERBOSE=5 } level; char log_str[512]; } *

user_defined_types: struct log_entry_ { struct timeval time; enum log_level level; char log_str[512]; }