radialGradientRaster

decompiled_code:
__int64 __fastcall radialGradientRaster(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v8; // rax
int v9; // er15
__int64 v10; // r12
double v11; // xmm0_8
int v12; // eax
double v13; // xmm1_8
double v14; // xmm0_8
double v15; // xmm0_8
__int64 result; // rax
int v17; // edi
unsigned int *v18; // r13
_QWORD *v19; // r14
__int64 v20; // r15
unsigned int v21; // eax
unsigned int v22; // eax
unsigned int v23; // eax
unsigned int v24; // eax
int v25; // esi
unsigned int *v26; // rbp
_QWORD *v27; // r14
__int64 v28; // rbx
__int64 v29; // r15
unsigned int v30; // eax
unsigned int v31; // eax
unsigned int v32; // eax
int v33; // [rsp+10h] [rbp-60h]
int v34; // [rsp+14h] [rbp-5Ch]
int v35; // [rsp+18h] [rbp-58h]
unsigned __int64 v36; // [rsp+18h] [rbp-58h]
__int64 v37; // [rsp+20h] [rbp-50h]
int v38; // [rsp+30h] [rbp-40h] BYREF
int v39[15]; // [rsp+34h] [rbp-3Ch] BYREF

v8 = *(_QWORD *)(a2 + 64);
v9 = *(_DWORD *)(a2 + 76);
v39[0] = a3 << 10;
v10 = *(_QWORD *)(a2 + 8);
v37 = v8;
v35 = *(_DWORD *)(a2 + 80);
v38 = v9 << 10;
ddMatrix_apply(&v38, v39);
if ( v39[0] < 0 )
{
v11 = *(double *)&LC0;
v12 = v38;
v13 = (double)-v39[0] * 0.0009765625;
if ( v38 >= 0 )
goto LABEL_3;
LABEL_13:
v14 = v11 * (double)-v12;
goto LABEL_4;
}
v11 = *(double *)&LC0;
v12 = v38;
v13 = (double)v39[0] * 0.0009765625;
if ( v38 < 0 )
goto LABEL_13;
LABEL_3:
v14 = v11 * (double)v12;
LABEL_4:
v15 = hypot(v14, v13);
v33 = *(_DWORD *)(a2 + 40);
v34 = *(_DWORD *)(a2 + 48);
result = a4 >> 48;
if ( ddEmptyCXform[3] == HIWORD(a4)
&& ddEmptyCXform[0] == (_WORD)a4
&& (result = (unsigned int)((int)a4 >> 16), ddEmptyCXform[1] == WORD1(a4))
&& (result = a4 << 16 >> 48, ddEmptyCXform[2] == (_WORD)result)
&& (result = a5 >> 48, ddEmptyCXform[7] == HIWORD(a5))
&& ddEmptyCXform[4] == (_WORD)a5
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
if ( v9 < v35 )
{
LODWORD(result) = v38;
v25 = v39[0];
v26 = (unsigned int *)(a1 + 4LL * v9);
v27 = (_QWORD *)(v37 + 8LL * v9);
v28 = v37 + 8 * ((unsigned int)(v35 - 1 - v9) + (__int64)v9) + 8;
do
{
v29 = *v27 >> 12;
v30 = fixed_sqrt((unsigned int)(((int)result >> 5) * ((int)result >> 5) + (v25 >> 5) * (v25 >> 5)), v15);
v31 = ddGradient_getColor(v10, v30);
v32 = ddColor_premultiply(v31);
if ( (_BYTE)v29 == 0xFF )
*v26 = v32;
else
*v26 += ddColor_scale(v32, (unsigned __int8)v29);
++v27;
++v26;
result = (unsigned int)(v38 + v33);
v25 = v39[0] + v34;
v38 += v33;
v39[0] += v34;
}
while ( (_QWORD *)v28 != v27 );
}
}
else if ( v9 < v35 )
{
v17 = v38;
LODWORD(result) = v39[0];
v18 = (unsigned int *)(a1 + 4LL * v9);
v19 = (_QWORD *)(v37 + 8LL * v9);
v36 = v37 + 8 * (v9 + (unsigned __int64)(unsigned int)(v35 - 1 - v9)) + 8;
do
{
v20 = *v19 >> 12;
v21 = fixed_sqrt((unsigned int)(((int)result >> 5) * ((int)result >> 5) + (v17 >> 5) * (v17 >> 5)), v15);
v22 = ddGradient_getColor(v10, v21);
v23 = ddCXform_apply(a4, a5, v22);
v24 = ddColor_premultiply(v23);
if ( (_BYTE)v20 == 0xFF )
*v18 = v24;
else
*v18 += ddColor_scale(v24, (unsigned __int8)v20);
++v19;
++v18;
v17 = v38 + v33;
result = (unsigned int)(v39[0] + v34);
v38 += v33;
v39[0] += v34;
}
while ( v19 != (_QWORD *)v36 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v8; // rax
int v9; // er15
__int64 v10; // r12
double v11; // xmm0_8
int v12; // eax
double v13; // xmm1_8
double v14; // xmm0_8
double v15; // xmm0_8
__int64 result; // rax
int v17; // edi
unsigned int *v18; // r13
_QWORD *v19; // r14
__int64 v20; // r15
unsigned int v21; // eax
unsigned int v22; // eax
unsigned int v23; // eax
unsigned int v24; // eax
int v25; // esi
unsigned int *v26; // rbp
_QWORD *v27; // r14
__int64 v28; // rbx
__int64 v29; // r15
unsigned int v30; // eax
unsigned int v31; // eax
unsigned int v32; // eax
int v33; // [rsp+10h] [rbp-60h]
int v34; // [rsp+14h] [rbp-5Ch]
int v35; // [rsp+18h] [rbp-58h]
unsigned __int64 v36; // [rsp+18h] [rbp-58h]
__int64 v37; // [rsp+20h] [rbp-50h]
int v38; // [rsp+30h] [rbp-40h] BYREF
int v39[15]; // [rsp+34h] [rbp-3Ch] BYREF

v8 = *(_QWORD *)(a2 + 64);
v9 = *(_DWORD *)(a2 + 76);
v39[0] = a3 << 10;
v10 = *(_QWORD *)(a2 + 8);
v37 = v8;
v35 = *(_DWORD *)(a2 + 80);
v38 = v9 << 10;
ddMatrix_apply(&v38, v39);
if ( v39[0] < 0 )
{
v11 = *(double *)&LC0;
v12 = v38;
v13 = (double)-v39[0] * 0.0009765625;
if ( v38 >= 0 )
goto LABEL_3;
LABEL_13:
v14 = v11 * (double)-v12;
goto LABEL_4;
}
v11 = *(double *)&LC0;
v12 = v38;
v13 = (double)v39[0] * 0.0009765625;
if ( v38 < 0 )
goto LABEL_13;
LABEL_3:
v14 = v11 * (double)v12;
LABEL_4:
v15 = hypot(v14, v13);
v33 = *(_DWORD *)(a2 + 40);
v34 = *(_DWORD *)(a2 + 48);
result = a4 >> 48;
if ( ddEmptyCXform[3] == HIWORD(a4)
&& ddEmptyCXform[0] == (_WORD)a4
&& (result = (unsigned int)((int)a4 >> 16), ddEmptyCXform[1] == WORD1(a4))
&& (result = a4 << 16 >> 48, ddEmptyCXform[2] == (_WORD)result)
&& (result = a5 >> 48, ddEmptyCXform[7] == HIWORD(a5))
&& ddEmptyCXform[4] == (_WORD)a5
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
if ( v9 < v35 )
{
LODWORD(result) = v38;
v25 = v39[0];
v26 = (unsigned int *)(a1 + 4LL * v9);
v27 = (_QWORD *)(v37 + 8LL * v9);
v28 = v37 + 8 * ((unsigned int)(v35 - 1 - v9) + (__int64)v9) + 8;
do
{
v29 = *v27 >> 12;
v30 = fixed_sqrt((unsigned int)(((int)result >> 5) * ((int)result >> 5) + (v25 >> 5) * (v25 >> 5)), v15);
v31 = ddGradient_getColor(v10, v30);
v32 = func1(v31);
if ( (_BYTE)v29 == 0xFF )
*v26 = v32;
else
*v26 += func0(v32, (unsigned __int8)v29);
++v27;
++v26;
result = (unsigned int)(v38 + v33);
v25 = v39[0] + v34;
v38 += v33;
v39[0] += v34;
}
while ( (_QWORD *)v28 != v27 );
}
}
else if ( v9 < v35 )
{
v17 = v38;
LODWORD(result) = v39[0];
v18 = (unsigned int *)(a1 + 4LL * v9);
v19 = (_QWORD *)(v37 + 8LL * v9);
v36 = v37 + 8 * (v9 + (unsigned __int64)(unsigned int)(v35 - 1 - v9)) + 8;
do
{
v20 = *v19 >> 12;
v21 = fixed_sqrt((unsigned int)(((int)result >> 5) * ((int)result >> 5) + (v17 >> 5) * (v17 >> 5)), v15);
v22 = ddGradient_getColor(v10, v21);
v23 = ddCXform_apply(a4, a5, v22);
v24 = func1(v23);
if ( (_BYTE)v20 == 0xFF )
*v18 = v24;
else
*v18 += func0(v24, (unsigned __int8)v20);
++v19;
++v18;
v17 = v38 + v33;
result = (unsigned int)(v39[0] + v34);
v38 += v33;
v39[0] += v34;
}
while ( v19 != (_QWORD *)v36 );
}
return result;
}

original_code:
void
radialGradientRaster(ddColor* buffer, ddFillInstance* fill, int y, ddCXform cXform)
{
 UInt32* alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x;
 ddGradient* grad = fill->fill.data.gradient.gradient;
 ddColor color = (ddColor)0;
 fixed d;
 fixed dpx, dpy;
 fixed px = ((left)<<10);
 fixed py = ((y)<<10);
 ddMatrix_apply(fill->inverse, &px, &py);
 d = ((int)floor((hypot((((px)<0)?(-(-(px)/(double)(1<<10))):((px)/(double)(1<<10))), (((py)<0)?(-(-(py)/(double)(1<<10))):((py)/(double)(1<<10)))))*(1<<10)+0.5));
 dpx = fill->inverse.a;
 dpy = fill->inverse.c;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   int tx = px >> (10 / 2);
   int ty = py >> (10 / 2);
   d = fixed_sqrt((unsigned)(tx * tx + ty * ty));
   color = ddGradient_getColor(grad, d);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   int tx = px >> (10 / 2);
   int ty = py >> (10 / 2);
   d = fixed_sqrt((unsigned)(tx * tx + ty * ty));
   color = ddGradient_getColor(grad, d);
   color = ddCXform_apply(cXform, color);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
}

canonical_original_code:
void radialGradientRaster(unsigned int *buffer, struct _ddFillInstance *fill, int y, struct _ddCXform cXform)
{
 unsigned long *alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x;
 struct _ddGradient *grad = fill->fill.data.gradient.gradient;
 unsigned int color = (ddColor)0;
 int d;
 int dpx; int dpy;
 int px = ((left)<<10);
 int py = ((y)<<10);
 ddMatrix_apply(fill->inverse, &px, &py);
 d = ((int)floor((hypot((((px)<0)?(-(-(px)/(double)(1<<10))):((px)/(double)(1<<10))), (((py)<0)?(-(-(py)/(double)(1<<10))):((py)/(double)(1<<10)))))*(1<<10)+0.5));
 dpx = fill->inverse.a;
 dpy = fill->inverse.c;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   int tx = px >> (10 / 2);
   int ty = py >> (10 / 2);
   d = fixed_sqrt((unsigned int)(tx * tx + ty * ty));
   color = ddGradient_getColor(grad, d);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   int tx = px >> (10 / 2);
   int ty = py >> (10 / 2);
   d = fixed_sqrt((unsigned int)(tx * tx + ty * ty));
   color = ddGradient_getColor(grad, d);
   color = ddCXform_apply(cXform, color);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
}

variable_types: y int

variable_types: x int

variable_types: struct _ddGradient { struct _ddGradEntry { unsigned short ratio; unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; int redslope; int greenslope; int blueslope; int alphaslope; } *entries; int nGrads; int band; } *

variable_types:
color
unsigned int

variable_types: d int

variable_types: dpx int

variable_types: dpy int

variable_types: tx int

variable_types: ty int

user_defined_types: struct _ddCXform { short rMult; short gMult; short bMult; short aMult; short rAdd; short gAdd; short bAdd; short aAdd; }


repo: beru/flirt

original_code:
static inline ddColor
ddColor_scale(ddColor color, int scale)
{
 if ( scale == 0xff )
  return color;
 return ((((color&0xff000000)>>8)*scale) & 0xff000000) |
  (((((color&0x00ff0000)*scale) & 0xff000000) |
 (((color&0x0000ff00)*scale) & 0x00ff0000) |
 (((color&0x000000ff)*scale) & 0x0000ff00)) >> 8);
}

canonical_original_code:
static inline unsigned int ddColor_scale(unsigned int color, int scale)
{
 if ( scale == 0xff )
  return color;
 return ((((color&0xff000000)>>8)*scale) & 0xff000000) |
  (((((color&0x00ff0000)*scale) & 0xff000000) |
 (((color&0x0000ff00)*scale) & 0x00ff0000) |
 (((color&0x000000ff)*scale) & 0x0000ff00)) >> 8);
}

variable_types: scale int

return_type: unsigned int


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

result = (unsigned int)(*(_DWORD *)a1 - 2);
if ( (unsigned int)result <= 1 )
result = dd_destroyGradient(*(_QWORD *)(a1 + 8));
return result;
}

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

result = (unsigned int)(*(_DWORD *)a1 - 2);
if ( (unsigned int)result <= 1 )
result = dd_destroyGradient(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
void
dd_destroyFill(ddFill* fill)
{
 if ( fill->type == FILL_RADIAL_GRADIENT || fill->type == FILL_LINEAR_GRADIENT )
  dd_destroyGradient(fill->data.gradient.gradient);
}

canonical_original_code:
void dd_destroyFill(struct _ddFill *fill)
{
 if ( fill->type == FILL_RADIAL_GRADIENT || fill->type == FILL_LINEAR_GRADIENT )
  dd_destroyGradient(fill->data.gradient.gradient);
}

variable_types: struct _ddFill { enum ddFillType { FILL_NONE=0, FILL_SOLID=1, FILL_RADIAL_GRADIENT=2, FILL_LINEAR_GRADIENT=3, FILL_CLIPPED_BITMAP=4, FILL_TILED_BITMAP=5 } type; union { unsigned int color; struct { struct _ddImage { enum ddImageFlags { DDIMAGE_DEFAULT=0, DDIMAGE_ALLOCEDBUFFER=1 } flags; unsigned short width; unsigned short height; unsigned short rowstride; unsigned char *data; } *image; struct _ddMatrix { int a; int b; int c; int d; int dx; int dy; } matrix; } bitmap; struct { struct _ddGradient { struct _ddGradEntry { unsigned short ratio; unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; int redslope; int greenslope; int blueslope; int alphaslope; } *entries; int nGrads; int band; } *gradient; struct _ddMatrix matrix; } gradient; } data; } *

return_type: void

user_defined_types: struct _ddFill { enum ddFillType type; union { unsigned int color; struct { struct _ddImage *image; struct _ddMatrix matrix; } bitmap; struct { struct _ddGradient *gradient; struct _ddMatrix matrix; } gradient; } data; }

user_defined_types: struct _ddImage { enum ddImageFlags flags; unsigned short width; unsigned short height; unsigned short rowstride; unsigned char *data; }

user_defined_types: struct _ddGradient { struct _ddGradEntry *entries; int nGrads; int band; }


decompiled_code:
void __fastcall ddFill_interpolate(__m128i *a1, unsigned int *a2, _DWORD *a3, unsigned __int16 a4)
{
__int64 v5; // rsi
int v7; // eax
int v8; // er8
unsigned int v9; // er13
unsigned __int8 v10; // [rsp+Dh] [rbp-4Bh]
__m128i v11; // [rsp+10h] [rbp-48h] BYREF
__int64 v12; // [rsp+20h] [rbp-38h]

v5 = *a2;
if ( (_DWORD)v5 == *a3 )
{
if ( (unsigned int)v5 > 3 )
{
if ( (unsigned int)(v5 - 4) > 1 )
{
dd_error("unknown fill type in ddFill_interpolate: %i", v5);
}
else
{
ddMatrix_interpolate(&v11, a4);
a1[1] = _mm_loadu_si128(&v11);
a1[2].m128i_i64[0] = v12;
}
}
else if ( (unsigned int)v5 > 1 )
{
v9 = a4;
ddGradient_interpolate(a1->m128i_i64[1], *((_QWORD *)a2 + 1), *((_QWORD *)a3 + 1), a4);
ddMatrix_interpolate(&v11, v9);
a1[1] = _mm_loadu_si128(&v11);
a1[2].m128i_i64[0] = v12;
}
else if ( (_DWORD)v5 )
{
v10 = HIBYTE(a4);
ddColor_scale(a2[2], (0x10000 - a4) >> 8);
v7 = ddColor_scale(a3[2], v10);
a1->m128i_i32[2] = v7 + v8;
}
}
else
{
dd_warn("mismatched fill types in ddFill_interpolate");
}
}

canonical_decompiled_code:
void __fastcall func2(__m128i *a1, unsigned int *a2, _DWORD *a3, unsigned __int16 a4)
{
__int64 v5; // rsi
int v7; // eax
int v8; // er8
unsigned int v9; // er13
unsigned __int8 v10; // [rsp+Dh] [rbp-4Bh]
__m128i v11; // [rsp+10h] [rbp-48h] BYREF
__int64 v12; // [rsp+20h] [rbp-38h]

v5 = *a2;
if ( (_DWORD)v5 == *a3 )
{
if ( (unsigned int)v5 > 3 )
{
if ( (unsigned int)(v5 - 4) > 1 )
{
dd_error("unknown fill type in ddFill_interpolate: %i", v5);
}
else
{
ddMatrix_interpolate(&v11, a4);
a1[1] = _mm_loadu_si128(&v11);
a1[2].m128i_i64[0] = v12;
}
}
else if ( (unsigned int)v5 > 1 )
{
v9 = a4;
ddGradient_interpolate(a1->m128i_i64[1], *((_QWORD *)a2 + 1), *((_QWORD *)a3 + 1), a4);
ddMatrix_interpolate(&v11, v9);
a1[1] = _mm_loadu_si128(&v11);
a1[2].m128i_i64[0] = v12;
}
else if ( (_DWORD)v5 )
{
v10 = HIBYTE(a4);
func0(a2[2], (0x10000 - a4) >> 8);
v7 = func0(a3[2], v10);
a1->m128i_i32[2] = v7 + v8;
}
}
else
{
dd_warn("mismatched fill types in ddFill_interpolate");
}
}

original_code:
void
ddFill_interpolate(ddFill* fill, ddFill* fill1, ddFill* fill2, UInt16 ratio)
{
 if ( fill1->type != fill2->type )
 {
  dd_warn("mismatched fill types in ddFill_interpolate");
  return;
 }
 switch ( fill1->type )
 {
  case FILL_NONE:
   break;
  case FILL_SOLID:
  {
   fill->data.color =
    ddColor_scale(fill1->data.color, (0x10000 - ratio) >> 8) +
    ddColor_scale(fill2->data.color, ratio >> 8);
   break;
  }
  case FILL_RADIAL_GRADIENT:
  case FILL_LINEAR_GRADIENT:
  {
   ddGradient_interpolate(fill->data.gradient.gradient,
        fill1->data.gradient.gradient,
        fill2->data.gradient.gradient, ratio);
   fill->data.gradient.matrix =
    ddMatrix_interpolate(fill1->data.gradient.matrix,
       fill2->data.gradient.matrix, ratio);
   break;
  }
  case FILL_CLIPPED_BITMAP:
  case FILL_TILED_BITMAP:
  {
   fill->data.bitmap.matrix =
    ddMatrix_interpolate(fill1->data.bitmap.matrix,
      fill2->data.bitmap.matrix, ratio);
   break;
  }
  default:
   dd_error("unknown fill type in ddFill_interpolate: %i", fill1->type);
 }
}

canonical_original_code:
void ddFill_interpolate(struct _ddFill *fill, struct _ddFill *fill1, struct _ddFill *fill2, unsigned short ratio)
{
 if ( fill1->type != fill2->type )
 {
  dd_warn("mismatched fill types in ddFill_interpolate");
  return;
 }
 switch ( fill1->type )
 {
  case FILL_NONE:
   break;
  case FILL_SOLID:
  {
   fill->data.color =
    ddColor_scale(fill1->data.color, (0x10000 - ratio) >> 8) +
    ddColor_scale(fill2->data.color, ratio >> 8);
   break;
  }
  case FILL_RADIAL_GRADIENT:
  case FILL_LINEAR_GRADIENT:
  {
   ddGradient_interpolate(fill->data.gradient.gradient,
        fill1->data.gradient.gradient,
        fill2->data.gradient.gradient, ratio);
   fill->data.gradient.matrix =
    ddMatrix_interpolate(fill1->data.gradient.matrix,
       fill2->data.gradient.matrix, ratio);
   break;
  }
  case FILL_CLIPPED_BITMAP:
  case FILL_TILED_BITMAP:
  {
   fill->data.bitmap.matrix =
    ddMatrix_interpolate(fill1->data.bitmap.matrix,
      fill2->data.bitmap.matrix, ratio);
   break;
  }
  default:
   dd_error("unknown fill type in ddFill_interpolate: %i", fill1->type);
 }
}

variable_types:
ratio
unsigned short

user_defined_types: enum ddFillType { FILL_NONE=0, FILL_SOLID=1, FILL_RADIAL_GRADIENT=2, FILL_LINEAR_GRADIENT=3, FILL_CLIPPED_BITMAP=4, FILL_TILED_BITMAP=5 }

user_defined_types: struct _ddMatrix { int a; int b; int c; int d; int dx; int dy; }

user_defined_types: enum ddImageFlags { DDIMAGE_DEFAULT=0, DDIMAGE_ALLOCEDBUFFER=1 }

user_defined_types: struct _ddGradEntry { unsigned short ratio; unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; int redslope; int greenslope; int blueslope; int alphaslope; }


decompiled_code:
void __fastcall dd_destroyFillInstance(__int64 a1)
{
void *v1; // rdi

v1 = *(void **)(a1 + 64);
if ( v1 )
free(v1);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
void *v1; // rdi

v1 = *(void **)(a1 + 64);
if ( v1 )
free(v1);
}

original_code:
void
dd_destroyFillInstance(ddFillInstance* fill)
{
 if ( fill->alphaBuffer != ((void *)0) )
  free(fill->alphaBuffer);
}

canonical_original_code:
void dd_destroyFillInstance(struct _ddFillInstance *fill)
{
 if ( fill->alphaBuffer != ((void *)0) )
  free(fill->alphaBuffer);
}

variable_types: struct _ddFillInstance { struct _ddFill { enum ddFillType { FILL_NONE=0, FILL_SOLID=1, FILL_RADIAL_GRADIENT=2, FILL_LINEAR_GRADIENT=3, FILL_CLIPPED_BITMAP=4, FILL_TILED_BITMAP=5 } type; union { unsigned int color; struct { struct _ddImage { enum ddImageFlags { DDIMAGE_DEFAULT=0, DDIMAGE_ALLOCEDBUFFER=1 } flags; unsigned short width; unsigned short height; unsigned short rowstride; unsigned char *data; } *image; struct _ddMatrix { int a; int b; int c; int d; int dx; int dy; } matrix; } bitmap; struct { struct _ddGradient { struct _ddGradEntry { unsigned short ratio; unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; int redslope; int greenslope; int blueslope; int alphaslope; } *entries; int nGrads; int band; } *gradient; struct _ddMatrix matrix; } gradient; } data; } fill; struct _ddMatrix inverse; unsigned long *alphaBuffer; int size; int left; int right; struct _ddFillInstance *next; int listed; } *

user_defined_types: struct _ddFillInstance { struct _ddFill fill; struct _ddMatrix inverse; unsigned long *alphaBuffer; int size; int left; int right; struct _ddFillInstance *next; int listed; }


decompiled_code:
int dd_warn_default(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

canonical_decompiled_code:
int func0(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
return putchar(10);
}

original_code:
static void dd_warn_default(const char* msg, ...)
{
 va_list args;
 __builtin_va_start(args,msg);
 vprintf(msg, args);
 putchar('\n');
 __builtin_va_end(args);
}

canonical_original_code:
static void dd_warn_default(char *msg, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,msg);
 vprintf(msg, args);
 putchar('\n');
 __builtin_va_end(args);
}

variable_types:
msg
char *


decompiled_code:
void __noreturn dd_error_default(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
putchar(10);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func1(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
vprintf(a1, arg);
putchar(10);
exit(-1);
}

original_code:
static void dd_error_default(const char* msg, ...)
{
 va_list args;
 __builtin_va_start(args,msg);
 vprintf(msg, args);
 putchar('\n');
 __builtin_va_end(args);
 exit(-1);
}

canonical_original_code:
static void dd_error_default(char *msg, ...)
{
 __builtin_va_list args;
 __builtin_va_start(args,msg);
 vprintf(msg, args);
 putchar('\n');
 __builtin_va_end(args);
 exit(-1);
}


decompiled_code:
__int64 dd_init()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
boolean
dd_init()
{
 return (boolean)1;
}

canonical_original_code:
int dd_init()
{
 return (int)1;
}

return_type: int


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

gettimeofday(&v1, 0LL);
return 1000 * (v1.tv_sec - dd_startTime) + v1.tv_usec / 1000;
}

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

gettimeofday(&v1, 0LL);
return 1000 * (v1.tv_sec - dd_startTime) + v1.tv_usec / 1000;
}

original_code:
unsigned long
dd_getTicks()
{
 struct timeval t;
 gettimeofday(&t, ((void *)0));
 return (t.tv_sec - dd_startTime) * 1000 + t.tv_usec / 1000;
}

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

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall dd_makeCXform(unsigned __int16 a1, unsigned __int16 a2, unsigned __int16 a3, __int64 a4)
{
return (a4 << 48) | ((unsigned __int64)a3 << 32) | ((unsigned __int64)a2 << 16) | a1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int16 a1, unsigned __int16 a2, unsigned __int16 a3, __int64 a4)
{
return (a4 << 48) | ((unsigned __int64)a3 << 32) | ((unsigned __int64)a2 << 16) | a1;
}

original_code:
ddCXform
dd_makeCXform(SInt16 rMult, SInt16 gMult, SInt16 bMult, SInt16 aMult,
    SInt16 rAdd, SInt16 gAdd, SInt16 bAdd, SInt16 aAdd)
{
 ddCXform cXform;
 cXform.rMult = rMult;
 cXform.gMult = gMult;
 cXform.bMult = bMult;
 cXform.aMult = aMult;
 cXform.rAdd = rAdd;
 cXform.gAdd = gAdd;
 cXform.bAdd = bAdd;
 cXform.aAdd = aAdd;
 return cXform;
}

canonical_original_code:
struct _ddCXform dd_makeCXform(short rMult, short gMult, short bMult, short aMult, short rAdd, short gAdd, short bAdd, short aAdd)
{
 struct _ddCXform cXform;
 cXform.rMult = rMult;
 cXform.gMult = gMult;
 cXform.bMult = bMult;
 cXform.aMult = aMult;
 cXform.rAdd = rAdd;
 cXform.gAdd = gAdd;
 cXform.bAdd = bAdd;
 cXform.aAdd = aAdd;
 return cXform;
}

variable_types: rMult short

variable_types: gMult short

variable_types: bMult short

variable_types: aMult short

variable_types: rAdd short

variable_types: gAdd short

variable_types: bAdd short

variable_types: aAdd short

variable_types: struct _ddCXform { short rMult; short gMult; short bMult; short aMult; short rAdd; short gAdd; short bAdd; short aAdd; }


original_code:
ddCXform
ddCXform_compose(ddCXform c1, ddCXform c2)
{
 ddCXform target;
 if ( (((c1).aMult == ddEmptyCXform.aMult) && ((c1).rMult == ddEmptyCXform.rMult) && ((c1).gMult == ddEmptyCXform.gMult) && ((c1).bMult == ddEmptyCXform.bMult) && ((c1).aAdd == ddEmptyCXform.aAdd) && ((c1).rAdd == ddEmptyCXform.rAdd) && ((c1).gAdd == ddEmptyCXform.gAdd) && ((c1).bAdd == ddEmptyCXform.bAdd)) )
  return c2;
 if ( (((c2).aMult == ddEmptyCXform.aMult) && ((c2).rMult == ddEmptyCXform.rMult) && ((c2).gMult == ddEmptyCXform.gMult) && ((c2).bMult == ddEmptyCXform.bMult) && ((c2).aAdd == ddEmptyCXform.aAdd) && ((c2).rAdd == ddEmptyCXform.rAdd) && ((c2).gAdd == ddEmptyCXform.gAdd) && ((c2).bAdd == ddEmptyCXform.bAdd)) )
  return c1;
 target.rMult = (SInt16)(((int)c1.rMult * c2.rMult) >> 8);
 target.gMult = (SInt16)(((int)c1.gMult * c2.gMult) >> 8);
 target.bMult = (SInt16)(((int)c1.bMult * c2.bMult) >> 8);
 target.aMult = (SInt16)(((int)c1.aMult * c2.aMult) >> 8);
 target.rAdd = c1.rAdd + c2.rAdd;
 target.gAdd = c1.gAdd + c2.gAdd;
 target.bAdd = c1.bAdd + c2.bAdd;
 target.aAdd = c1.aAdd + c2.aAdd;
 return target;
}

canonical_original_code:
struct _ddCXform ddCXform_compose(struct _ddCXform c1, struct _ddCXform c2)
{
 struct _ddCXform target;
 if ( (((c1).aMult == ddEmptyCXform.aMult) && ((c1).rMult == ddEmptyCXform.rMult) && ((c1).gMult == ddEmptyCXform.gMult) && ((c1).bMult == ddEmptyCXform.bMult) && ((c1).aAdd == ddEmptyCXform.aAdd) && ((c1).rAdd == ddEmptyCXform.rAdd) && ((c1).gAdd == ddEmptyCXform.gAdd) && ((c1).bAdd == ddEmptyCXform.bAdd)) )
  return c2;
 if ( (((c2).aMult == ddEmptyCXform.aMult) && ((c2).rMult == ddEmptyCXform.rMult) && ((c2).gMult == ddEmptyCXform.gMult) && ((c2).bMult == ddEmptyCXform.bMult) && ((c2).aAdd == ddEmptyCXform.aAdd) && ((c2).rAdd == ddEmptyCXform.rAdd) && ((c2).gAdd == ddEmptyCXform.gAdd) && ((c2).bAdd == ddEmptyCXform.bAdd)) )
  return c1;
 target.rMult = (SInt16)(((int)c1.rMult * c2.rMult) >> 8);
 target.gMult = (SInt16)(((int)c1.gMult * c2.gMult) >> 8);
 target.bMult = (SInt16)(((int)c1.bMult * c2.bMult) >> 8);
 target.aMult = (SInt16)(((int)c1.aMult * c2.aMult) >> 8);
 target.rAdd = c1.rAdd + c2.rAdd;
 target.gAdd = c1.gAdd + c2.gAdd;
 target.bAdd = c1.bAdd + c2.bAdd;
 target.aAdd = c1.aAdd + c2.aAdd;
 return target;
}

return_type: struct _ddCXform { short rMult; short gMult; short bMult; short aMult; short rAdd; short gAdd; short bAdd; short aAdd; }


original_code:
ddColor
ddCXform_apply(ddCXform cXform, ddColor color)
{
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
  return color;
 return ((((((((((((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff)))>(0))?((((((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff))):(0)))&0xff)<<24)|(((((((((((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff)))>(0))?((((((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff))):(0)))&0xff)<<16)|(((((((((((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff)))>(0))?((((((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff))):(0)))&0xff)<<8)|((((((((((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff)))>(0))?((((((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff))):(0)))&0xff));
}

canonical_original_code:
unsigned int ddCXform_apply(struct _ddCXform cXform, unsigned int color)
{
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
  return color;
 return ((((((((((((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff)))>(0))?((((((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff))):(0)))&0xff)<<24)|(((((((((((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff)))>(0))?((((((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff))):(0)))&0xff)<<16)|(((((((((((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff)))>(0))?((((((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff))):(0)))&0xff)<<8)|((((((((((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff)))>(0))?((((((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff))):(0)))&0xff));
}

variable_types:
color
unsigned int


original_code:
ddColor
ddCXform_applyPremultiplied(ddCXform cXform, ddColor color)
{
 int alpha;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
  return color;
 alpha = ((((((((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff)))>(0))?((((((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((signed)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff))):(0));
 color = ((((0xff)&0xff)<<24)|(((((((((((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff)))>(0))?((((((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((signed)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff))):(0)))&0xff)<<16)|(((((((((((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff)))>(0))?((((((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((signed)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff))):(0)))&0xff)<<8)|((((((((((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff)))>(0))?((((((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((signed)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff))):(0)))&0xff));
 if ( alpha == 0xff )
  return color;
 else if ( alpha == 0 )
  return (ddColor)0;
 else
  return ddColor_scale(color, alpha);
}

canonical_original_code:
unsigned int ddCXform_applyPremultiplied(struct _ddCXform cXform, unsigned int color)
{
 int alpha;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
  return color;
 alpha = ((((((((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff)))>(0))?((((((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd))<(0xff))?(((int)(((((color)>>24)&0xff) * cXform.aMult) >> 8) + cXform.aAdd)):(0xff))):(0));
 color = ((((0xff)&0xff)<<24)|(((((((((((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff)))>(0))?((((((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd))<(0xff))?(((int)(((((color)>>16)&0xff) * cXform.rMult) >> 8) + cXform.rAdd)):(0xff))):(0)))&0xff)<<16)|(((((((((((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff)))>(0))?((((((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd))<(0xff))?(((int)(((((color)>>8)&0xff) * cXform.gMult) >> 8) + cXform.gAdd)):(0xff))):(0)))&0xff)<<8)|((((((((((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff)))>(0))?((((((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd))<(0xff))?(((int)((((color)&0xff) * cXform.bMult) >> 8) + cXform.bAdd)):(0xff))):(0)))&0xff));
 if ( alpha == 0xff )
  return color;
 else if ( alpha == 0 )
  return (unsigned int)0;
 else
  return ddColor_scale(color, alpha);
}

variable_types: alpha int


decompiled_code:
_BOOL8 __fastcall ddCXform_equals(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a3
&& (unsigned __int64)(a1 << 16) >> 48 == (unsigned __int64)(a3 << 16) >> 48
&& HIWORD(a1) == HIWORD(a3)
&& (_DWORD)a2 == (_DWORD)a4
&& (unsigned __int64)(a2 << 16) >> 48 == (unsigned __int64)(a4 << 16) >> 48 )
{
result = HIWORD(a2) == HIWORD(a4);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a3
&& (unsigned __int64)(a1 << 16) >> 48 == (unsigned __int64)(a3 << 16) >> 48
&& HIWORD(a1) == HIWORD(a3)
&& (_DWORD)a2 == (_DWORD)a4
&& (unsigned __int64)(a2 << 16) >> 48 == (unsigned __int64)(a4 << 16) >> 48 )
{
result = HIWORD(a2) == HIWORD(a4);
}
return result;
}

original_code:
boolean
ddCXform_equals(ddCXform a, ddCXform b)
{
 return (a.rMult == b.rMult) && (a.gMult == b.gMult) &&
    (a.bMult == b.bMult) && (a.aMult == b.aMult) &&
    (a.rAdd == b.rAdd) && (a.gAdd == b.gAdd) &&
    (a.bAdd == b.bAdd) && (a.aAdd == b.aAdd);
}

canonical_original_code:
int ddCXform_equals(struct _ddCXform a, struct _ddCXform b)
{
 return (a.rMult == b.rMult) && (a.gMult == b.gMult) &&
    (a.bMult == b.bMult) && (a.aMult == b.aMult) &&
    (a.rAdd == b.rAdd) && (a.gAdd == b.gAdd) &&
    (a.bAdd == b.bAdd) && (a.aAdd == b.aAdd);
}

variable_types:
b
struct _ddCXform


solidRaster

decompiled_code:
__int64 __fastcall solidRaster(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v6; // er13
int v7; // ebx
__int64 v8; // r12
unsigned int v9; // eax
__int64 result; // rax
unsigned int v11; // edi
_QWORD *v12; // r8
unsigned int *v13; // r9
unsigned __int64 v14; // r11
unsigned int v15; // edx
unsigned __int8 v16; // si
int v17; // er10

v6 = *(_DWORD *)(a2 + 76);
v7 = *(_DWORD *)(a2 + 80);
v8 = *(_QWORD *)(a2 + 64);
v9 = ddCXform_apply(a4, a5, *(unsigned int *)(a2 + 8));
result = ddColor_premultiply(v9);
if ( v6 < v7 )
{
v11 = result;
v12 = (_QWORD *)(v8 + 8LL * v6);
v13 = (unsigned int *)(a1 + 4LL * v6);
v14 = v8 + 8 * (v6 + (unsigned __int64)(unsigned int)(v7 - 1 - v6)) + 8;
do
{
while ( 1 )
{
result = *v12 >> 12;
v16 = result;
if ( (_BYTE)result != 0xFF )
break;
++v12;
*v13++ = v11;
if ( (_QWORD *)v14 == v12 )
return result;
}
if ( (_BYTE)result )
{
v15 = HIBYTE(*v13);
result = v15 + (unsigned __int8)result;
if ( (unsigned int)result <= 0xFF || (v16 = ~(_BYTE)v15, (_BYTE)v15 != 0xFF) )
{
result = ddColor_scale(v11, v16);
*v13 = result + v17;
}
}
++v12;
++v13;
}
while ( (_QWORD *)v14 != v12 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
int v6; // er13
int v7; // ebx
__int64 v8; // r12
unsigned int v9; // eax
__int64 result; // rax
unsigned int v11; // edi
_QWORD *v12; // r8
unsigned int *v13; // r9
unsigned __int64 v14; // r11
unsigned int v15; // edx
unsigned __int8 v16; // si
int v17; // er10

v6 = *(_DWORD *)(a2 + 76);
v7 = *(_DWORD *)(a2 + 80);
v8 = *(_QWORD *)(a2 + 64);
v9 = ddCXform_apply(a4, a5, *(unsigned int *)(a2 + 8));
result = func1(v9);
if ( v6 < v7 )
{
v11 = result;
v12 = (_QWORD *)(v8 + 8LL * v6);
v13 = (unsigned int *)(a1 + 4LL * v6);
v14 = v8 + 8 * (v6 + (unsigned __int64)(unsigned int)(v7 - 1 - v6)) + 8;
do
{
while ( 1 )
{
result = *v12 >> 12;
v16 = result;
if ( (_BYTE)result != 0xFF )
break;
++v12;
*v13++ = v11;
if ( (_QWORD *)v14 == v12 )
return result;
}
if ( (_BYTE)result )
{
v15 = HIBYTE(*v13);
result = v15 + (unsigned __int8)result;
if ( (unsigned int)result <= 0xFF || (v16 = ~(_BYTE)v15, (_BYTE)v15 != 0xFF) )
{
result = func0(v11, v16);
*v13 = result + v17;
}
}
++v12;
++v13;
}
while ( (_QWORD *)v14 != v12 );
}
return result;
}

original_code:
void
solidRaster(ddColor* buffer, ddFillInstance* fill, int y, ddCXform cXform)
{
 UInt32* alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x;
 ddColor color = ddCXform_apply(cXform, fill->fill.data.color);
 color = ddColor_premultiply(color);
 for ( x = left; x < right; ++x )
 {
  UInt8 c = alpha[x] >> ((2*10)-8);
  if ( (unsigned int)c + (((buffer[x])>>24)&0xff) > 0xff )
   dd_log("alpha > 0xff in line buffer!");
  if ( c == 0xff )
   buffer[x] = color;
  else if ( c > 0 )
  {
   if ( (unsigned int)c + (((buffer[x])>>24)&0xff) > 0xff )
    c = 0xff - (((buffer[x])>>24)&0xff);
   if ( c > 0 )
    buffer[x] += ddColor_scale(color, c);
  }
 }
}

canonical_original_code:
void solidRaster(unsigned int *buffer, struct _ddFillInstance *fill, int y, struct _ddCXform cXform)
{
 unsigned long *alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x;
 unsigned int color = ddCXform_apply(cXform, fill->fill.data.color);
 color = ddColor_premultiply(color);
 for ( x = left; x < right; ++x )
 {
  unsigned char c = alpha[x] >> ((2*10)-8);
  if ( (unsigned int)c + (((buffer[x])>>24)&0xff) > 0xff )
   dd_log("alpha > 0xff in line buffer!");
  if ( c == 0xff )
   buffer[x] = color;
  else if ( c > 0 )
  {
   if ( (unsigned int)c + (((buffer[x])>>24)&0xff) > 0xff )
    c = 0xff - (((buffer[x])>>24)&0xff);
   if ( c > 0 )
    buffer[x] += ddColor_scale(color, c);
  }
 }
}

variable_types:
buffer
unsigned int *

variable_types: y int

variable_types:
alpha
unsigned long *

variable_types: left int

variable_types: right int

variable_types: x int

variable_types:
c
unsigned char


interp

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

result = a2;
if ( a2 != a3 )
result = (unsigned __int16)((BYTE1(a2) + (unsigned __int16)((a1 * (BYTE1(a3) - (unsigned int)BYTE1(a2))) >> 10)) << 8) | ((BYTE2(a2) + ((a1 * (BYTE2(a3) - (unsigned int)BYTE2(a2))) >> 10)) << 16) & 0xFF0000 | (unsigned __int8)(a2 + ((a1 * ((unsigned __int8)a3 - (unsigned int)(unsigned __int8)a2)) >> 10)) | ((HIBYTE(a2) + ((unsigned int)(a1 * (HIBYTE(a3) - HIBYTE(a2))) >> 10)) << 24);
return result;
}

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

result = a2;
if ( a2 != a3 )
result = (unsigned __int16)((BYTE1(a2) + (unsigned __int16)((a1 * (BYTE1(a3) - (unsigned int)BYTE1(a2))) >> 10)) << 8) | ((BYTE2(a2) + ((a1 * (BYTE2(a3) - (unsigned int)BYTE2(a2))) >> 10)) << 16) & 0xFF0000 | (unsigned __int8)(a2 + ((a1 * ((unsigned __int8)a3 - (unsigned int)(unsigned __int8)a2)) >> 10)) | ((HIBYTE(a2) + ((unsigned int)(a1 * (HIBYTE(a3) - HIBYTE(a2))) >> 10)) << 24);
return result;
}

variable_types: f int

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types: red int

variable_types: green int

variable_types: blue int


tiledBitmapRaster

original_code:
void
tiledBitmapRaster(ddColor* buffer, ddFillInstance* fill, int y, ddCXform cXform)
{
 UInt32* alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x = left;
 ddImage* bitmap = fill->fill.data.bitmap.image;
 ddMatrix matrix = fill->inverse;
 ddColor color;
 fixed px, py, dpx, dpy;
 px = ((x)<<10);
 py = ((y)<<10);
 ddMatrix_apply(matrix, &px, &py);
 dpx = matrix.a;
 dpy = matrix.c;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   color = ddImage_getTiledPixel_blended(bitmap, px, py);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   color = ddImage_getTiledPixel_blended(bitmap, px, py);
   color = ddCXform_applyPremultiplied(cXform, color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
}

canonical_original_code:
void tiledBitmapRaster(unsigned int *buffer, struct _ddFillInstance *fill, int y, struct _ddCXform cXform)
{
 unsigned long *alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x = left;
 struct _ddImage *bitmap = fill->fill.data.bitmap.image;
 struct _ddMatrix matrix = fill->inverse;
 unsigned int color;
 int px; int py; int dpx; int dpy;
 px = ((x)<<10);
 py = ((y)<<10);
 ddMatrix_apply(matrix, &px, &py);
 dpx = matrix.a;
 dpy = matrix.c;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   color = ddImage_getTiledPixel_blended(bitmap, px, py);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   color = ddImage_getTiledPixel_blended(bitmap, px, py);
   color = ddCXform_applyPremultiplied(cXform, color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
}

variable_types: struct _ddFillInstance { struct _ddFill { enum ddFillType { FILL_NONE=0, FILL_SOLID=1, FILL_RADIAL_GRADIENT=2, FILL_LINEAR_GRADIENT=3, FILL_CLIPPED_BITMAP=4, FILL_TILED_BITMAP=5 } type; union { unsigned int color; struct { struct _ddImage { enum ddImageFlags { DDIMAGE_DEFAULT=0, DDIMAGE_ALLOCEDBUFFER=1 } flags; unsigned short width; unsigned short height; unsigned short rowstride; unsigned char *data; } *image; struct _ddMatrix { int a; int b; int c; int d; int dx; int dy; } matrix; } bitmap; struct { struct _ddGradient { struct _ddGradEntry { unsigned short ratio; unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; int redslope; int greenslope; int blueslope; int alphaslope; } *entries; int nGrads; int band; } *gradient; struct _ddMatrix matrix; } gradient; } data; } fill; struct _ddMatrix inverse; unsigned long *alphaBuffer; int size; int left; int right; struct _ddFillInstance *next; int listed; } *

variable_types: struct _ddCXform { short rMult; short gMult; short bMult; short aMult; short rAdd; short gAdd; short bAdd; short aAdd; }

variable_types: px int

variable_types: py int

variable_types: dpx int

variable_types: dpy int


clippedBitmapRaster

original_code:
void
clippedBitmapRaster(ddColor* buffer, ddFillInstance* fill, int y, ddCXform cXform)
{
 UInt32* alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x = left;
 ddImage* bitmap = fill->fill.data.bitmap.image;
 ddMatrix matrix = fill->inverse;
 ddColor color = (ddColor)0;
 fixed px, py, dpx, dpy;
 px = ((x)<<10);
 py = ((y)<<10);
 ddMatrix_apply(matrix, &px, &py);
 dpx = matrix.a;
 dpy = matrix.c;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   color = ddImage_getClippedPixel_blended(bitmap, px, py);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   color = ddImage_getClippedPixel_blended(bitmap, px, py);
   color = ddCXform_applyPremultiplied(cXform, color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
}

canonical_original_code:
void clippedBitmapRaster(unsigned int *buffer, struct _ddFillInstance *fill, int y, struct _ddCXform cXform)
{
 unsigned long *alpha = fill->alphaBuffer;
 int left = fill->left;
 int right = fill->right;
 int x = left;
 struct _ddImage *bitmap = fill->fill.data.bitmap.image;
 struct _ddMatrix matrix = fill->inverse;
 unsigned int color = (ddColor)0;
 int px; int py; int dpx; int dpy;
 px = ((x)<<10);
 py = ((y)<<10);
 ddMatrix_apply(matrix, &px, &py);
 dpx = matrix.a;
 dpy = matrix.c;
 if ( (((cXform).aMult == ddEmptyCXform.aMult) && ((cXform).rMult == ddEmptyCXform.rMult) && ((cXform).gMult == ddEmptyCXform.gMult) && ((cXform).bMult == ddEmptyCXform.bMult) && ((cXform).aAdd == ddEmptyCXform.aAdd) && ((cXform).rAdd == ddEmptyCXform.rAdd) && ((cXform).gAdd == ddEmptyCXform.gAdd) && ((cXform).bAdd == ddEmptyCXform.bAdd)) )
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   color = ddImage_getClippedPixel_blended(bitmap, px, py);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   color = ddImage_getClippedPixel_blended(bitmap, px, py);
   color = ddCXform_applyPremultiplied(cXform, color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dpx;
   py += dpy;
  }
 }
}

variable_types:
buffer
unsigned int *

variable_types: y int

variable_types:
alpha
unsigned long *

variable_types: struct _ddImage { enum ddImageFlags { DDIMAGE_DEFAULT=0, DDIMAGE_ALLOCEDBUFFER=1 } flags; unsigned short width; unsigned short height; unsigned short rowstride; unsigned char *data; } *

variable_types: struct _ddMatrix { int a; int b; int c; int d; int dx; int dy; }

variable_types:
color
unsigned int


decompiled_code:
__int64 dd_newMP3Decoder()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
ddMP3Decoder*
dd_newMP3Decoder()
{
 return ((void *)0);
}

canonical_original_code:
struct _ddMP3Decoder *dd_newMP3Decoder()
{
 return ((void *)0);
}

return_type: struct _ddMP3Decoder { int fubar; } *


decompiled_code:
void dd_destroyMP3Decoder()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
dd_destroyMP3Decoder(ddMP3Decoder* decoder)
{
}

canonical_original_code:
void dd_destroyMP3Decoder(struct _ddMP3Decoder *decoder)
{
}

variable_types:
decoder
struct _ddMP3Decoder { int fubar; } *


decompiled_code:
__int64 ddMP3Decoder_decodeFrame()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
boolean
ddMP3Decoder_decodeFrame(ddMP3Decoder* decoder, ddSoundTransform xform, unsigned char** dataPtr, int datalength, int delay, ddAudioSample** bufferPtr, int size)
{
 return 0;
}

canonical_original_code:
int ddMP3Decoder_decodeFrame(struct _ddMP3Decoder *decoder, struct _ddSoundTransform xform, unsigned char **dataPtr, int datalength, int delay, struct ddAudioSample **bufferPtr, int size)
{
 return 0;
}

variable_types: struct _ddSoundTransform { float leftToLeft; float leftToRight; float rightToLeft; float rightToRight; }

variable_types:
dataPtr
unsigned char **

variable_types: datalength int

variable_types: delay int

variable_types: struct ddAudioSample { int left; int right; } **

variable_types: size int


decompiled_code:
__int64 __fastcall fixed_sqrt(unsigned int a1)
{
unsigned __int64 v1; // rsi
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rsi
unsigned __int64 v4; // rax
__int64 result; // rax
char v6; // al

if ( a1 <= 0xFFFF )
{
if ( a1 <= 0xFF )
return 32 * (unsigned int)((unsigned __int8)sqq_table_0[a1] >> 4);
v2 = a1;
if ( a1 <= 0xFFF )
{
if ( a1 <= 0x3FF )
v6 = (unsigned __int8)sqq_table_0[a1 >> 2] >> 3;
else
v6 = (unsigned __int8)sqq_table_0[a1 >> 4] >> 2;
v4 = (unsigned __int8)(v6 + 1);
}
else if ( a1 <= 0x3FFF )
{
v4 = (unsigned __int8)(((unsigned __int8)sqq_table_0[a1 >> 6] >> 1) + 1);
}
else
{
v4 = (unsigned __int8)sqq_table_0[a1 >> 8] + 1LL;
}
goto LABEL_8;
}
if ( a1 <= 0xFFFFFF )
{
v2 = a1;
if ( a1 <= 0xFFFFF )
{
if ( a1 <= 0x3FFFF )
v3 = 2 * (unsigned __int8)sqq_table_0[a1 >> 10];
else
v3 = 4 * (unsigned __int8)sqq_table_0[a1 >> 12];
}
else if ( a1 <= 0x3FFFFF )
{
v3 = 8 * (unsigned __int8)sqq_table_0[a1 >> 14];
}
else
{
v3 = 16 * (unsigned __int8)sqq_table_0[HIWORD(a1)];
}
goto LABEL_7;
}
if ( a1 <= 0xFFFFFFF )
{
if ( a1 <= 0x3FFFFFF )
v1 = 32 * (unsigned __int8)sqq_table_0[a1 >> 18];
else
v1 = (unsigned __int8)sqq_table_0[a1 >> 20] << 6;
goto LABEL_6;
}
if ( a1 <= 0x3FFFFFFF )
{
v1 = (unsigned __int8)sqq_table_0[a1 >> 22] << 7;
goto LABEL_6;
}
result = 2097120LL;
if ( a1 <= 0xFFFE0000 )
{
v1 = (unsigned __int8)sqq_table_0[HIBYTE(a1)] << 8;
LABEL_6:
v2 = a1;
v3 = (v1 + a1 / v1 + 1) >> 1;
LABEL_7:
v4 = (v3 + v2 / v3 + 1) >> 1;
LABEL_8:
result = 32 * ((unsigned int)v4 - (v2 < v4 * v4));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
unsigned __int64 v1; // rsi
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rsi
unsigned __int64 v4; // rax
__int64 result; // rax
char v6; // al

if ( a1 <= 0xFFFF )
{
if ( a1 <= 0xFF )
return 32 * (unsigned int)((unsigned __int8)sqq_table_0[a1] >> 4);
v2 = a1;
if ( a1 <= 0xFFF )
{
if ( a1 <= 0x3FF )
v6 = (unsigned __int8)sqq_table_0[a1 >> 2] >> 3;
else
v6 = (unsigned __int8)sqq_table_0[a1 >> 4] >> 2;
v4 = (unsigned __int8)(v6 + 1);
}
else if ( a1 <= 0x3FFF )
{
v4 = (unsigned __int8)(((unsigned __int8)sqq_table_0[a1 >> 6] >> 1) + 1);
}
else
{
v4 = (unsigned __int8)sqq_table_0[a1 >> 8] + 1LL;
}
goto LABEL_8;
}
if ( a1 <= 0xFFFFFF )
{
v2 = a1;
if ( a1 <= 0xFFFFF )
{
if ( a1 <= 0x3FFFF )
v3 = 2 * (unsigned __int8)sqq_table_0[a1 >> 10];
else
v3 = 4 * (unsigned __int8)sqq_table_0[a1 >> 12];
}
else if ( a1 <= 0x3FFFFF )
{
v3 = 8 * (unsigned __int8)sqq_table_0[a1 >> 14];
}
else
{
v3 = 16 * (unsigned __int8)sqq_table_0[HIWORD(a1)];
}
goto LABEL_7;
}
if ( a1 <= 0xFFFFFFF )
{
if ( a1 <= 0x3FFFFFF )
v1 = 32 * (unsigned __int8)sqq_table_0[a1 >> 18];
else
v1 = (unsigned __int8)sqq_table_0[a1 >> 20] << 6;
goto LABEL_6;
}
if ( a1 <= 0x3FFFFFFF )
{
v1 = (unsigned __int8)sqq_table_0[a1 >> 22] << 7;
goto LABEL_6;
}
result = 2097120LL;
if ( a1 <= 0xFFFE0000 )
{
v1 = (unsigned __int8)sqq_table_0[HIBYTE(a1)] << 8;
LABEL_6:
v2 = a1;
v3 = (v1 + a1 / v1 + 1) >> 1;
LABEL_7:
v4 = (v3 + v2 / v3 + 1) >> 1;
LABEL_8:
result = 32 * ((unsigned int)v4 - (v2 < v4 * v4));
}
return result;
}

variable_types:
x
unsigned int

variable_types:
xn
unsigned long


decompiled_code:
__int64 __fastcall ddFillInstance_getRasterMethod(unsigned int *a1)
{
__int64 v1; // rsi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( (unsigned int)v1 <= 5 )
return CSWTCH_2[v1];
dd_warn("Unknown fill type: %i", v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
__int64 v1; // rsi

if ( !a1 )
return 0LL;
v1 = *a1;
if ( (unsigned int)v1 <= 5 )
return CSWTCH_2[v1];
dd_warn("Unknown fill type: %i", v1);
return 0LL;
}

original_code:
ddRasterMethod
ddFillInstance_getRasterMethod(ddFillInstance* f)
{
 if ( f == ((void *)0) )
  return ((void *)0);
 switch ( f->fill.type )
 {
  case FILL_NONE:
   return ((void *)0);
  case FILL_SOLID:
   return solidRaster;
  case FILL_RADIAL_GRADIENT:
   return radialGradientRaster;
  case FILL_LINEAR_GRADIENT:
   return linearGradientRaster;
  case FILL_CLIPPED_BITMAP:
   return clippedBitmapRaster;
  case FILL_TILED_BITMAP:
   return tiledBitmapRaster;
  default:
   dd_warn("Unknown fill type: %i", f->fill.type);
   return ((void *)0);
 }
}

canonical_original_code:
void (*ddFillInstance_getRasterMethod(struct _ddFillInstance *f))(unsigned int *buffer, struct _ddFillInstance *fill, int y, struct _ddCXform cXform)
{
 if ( f == ((void *)0) )
  return ((void *)0);
 switch ( f->fill.type )
 {
  case FILL_NONE:
   return ((void *)0);
  case FILL_SOLID:
   return solidRaster;
  case FILL_RADIAL_GRADIENT:
   return radialGradientRaster;
  case FILL_LINEAR_GRADIENT:
   return linearGradientRaster;
  case FILL_CLIPPED_BITMAP:
   return clippedBitmapRaster;
  case FILL_TILED_BITMAP:
   return tiledBitmapRaster;
  default:
   dd_warn("Unknown fill type: %i", f->fill.type);
   return ((void *)0);
 }
}

variable_types:
f
struct _ddFillInstance *

return_type: void (*)(unsigned int *buffer, struct _ddFillInstance { struct _ddFill { enum ddFillType { FILL_NONE=0, FILL_SOLID=1, FILL_RADIAL_GRADIENT=2, FILL_LINEAR_GRADIENT=3, FILL_CLIPPED_BITMAP=4, FILL_TILED_BITMAP=5 } type; union { unsigned int color; struct { struct _ddImage { enum ddImageFlags { DDIMAGE_DEFAULT=0, DDIMAGE_ALLOCEDBUFFER=1 } flags; unsigned short width; unsigned short height; unsigned short rowstride; unsigned char *data; } *image; struct _ddMatrix { int a; int b; int c; int d; int dx; int dy; } matrix; } bitmap; struct { struct _ddGradient { struct _ddGradEntry { unsigned short ratio; unsigned char red; unsigned char green; unsigned char blue; unsigned char alpha; int redslope; int greenslope; int blueslope; int alphaslope; } *entries; int nGrads; int band; } *gradient; struct _ddMatrix matrix; } gradient; } data; } fill; struct _ddMatrix inverse; unsigned long *alphaBuffer; int size; int left; int right; struct _ddFillInstance *next; int listed; } *fill, int y, struct _ddCXform { short rMult; short gMult; short bMult; short aMult; short rAdd; short gAdd; short bAdd; short aAdd; } cXform)


decompiled_code:
__int64 __fastcall dd_hashFunction(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t *v3; // rcx
__int64 result; // rax

v1 = *a1;
if ( !(_BYTE)v1 )
return 0LL;
v2 = a1;
v3 = *_ctype_tolower_loc();
LODWORD(result) = 0;
do
{
result = (unsigned int)(v3[v1] + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((int)(result & 0xF0000000) >> 24) ^ (unsigned int)result & 0xFFFFFFF;
v1 = *++v2;
}
while ( (_BYTE)v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t *v3; // rcx
__int64 result; // rax

v1 = *a1;
if ( !(_BYTE)v1 )
return 0LL;
v2 = a1;
v3 = *_ctype_tolower_loc();
LODWORD(result) = 0;
do
{
result = (unsigned int)(v3[v1] + 16 * result);
if ( (result & 0xF0000000) != 0 )
result = ((int)(result & 0xF0000000) >> 24) ^ (unsigned int)result & 0xFFFFFFF;
v1 = *++v2;
}
while ( (_BYTE)v1 );
return result;
}

original_code:
unsigned int
dd_hashFunction(const char* name)
{
 int code = 0, loop;
 const char* p = name;
 while ( *p != '\0' )
 {
  code = (code << 4) + tolower(*p);
  if ( (loop = (code & 0xF0000000)) != 0 )
  {
   code = code ^ (loop >> 24);
   code = code ^ loop;
  }
  ++p;
 }
 return code;
}

canonical_original_code:
unsigned int dd_hashFunction(char *name)
{
 int code = 0; int loop;
 char *p = name;
 while ( *p != '\0' )
 {
  code = (code << 4) + tolower(*p);
  if ( (loop = (code & 0xF0000000)) != 0 )
  {
   code = code ^ (loop >> 24);
   code = code ^ loop;
  }
  ++p;
 }
 return code;
}

variable_types:
name
char *

variable_types: code int

variable_types: loop int

variable_types:
p
char *


original_code:
static inline ddColor
ddColor_scale(ddColor color, int scale)
{
 if ( scale == 0xff )
  return color;
 return ((((color&0xff000000)>>8)*scale) & 0xff000000) |
  (((((color&0x00ff0000)*scale) & 0xff000000) |
 (((color&0x0000ff00)*scale) & 0x00ff0000) |
 (((color&0x000000ff)*scale) & 0x0000ff00)) >> 8);
}

canonical_original_code:
static inline unsigned int ddColor_scale(unsigned int color, int scale)
{
 if ( scale == 0xff )
  return color;
 return ((((color&0xff000000)>>8)*scale) & 0xff000000) |
  (((((color&0x00ff0000)*scale) & 0xff000000) |
 (((color&0x0000ff00)*scale) & 0x00ff0000) |
 (((color&0x000000ff)*scale) & 0x0000ff00)) >> 8);
}

variable_types: scale int


BitArrayDestroy

repo: betamos/Huffman-coding

decompiled_code:
void __fastcall BitArrayDestroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void BitArrayDestroy(bit_array_t *ba)
{
    if (ba != ((void *)0))
    {
        if (ba->array != ((void *)0))
        {
            free(ba->array);
        }
        free(ba);
    }
}

canonical_original_code:
void BitArrayDestroy(struct bit_array_t *ba)
{
    if (ba != ((void *)0))
    {
        if (ba->array != ((void *)0))
        {
            free(ba->array);
        }
        free(ba);
    }
}

variable_types: struct bit_array_t { unsigned char *array; unsigned int numBits; } *


BitArraySize

decompiled_code:
__int64 __fastcall BitArraySize(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
unsigned int BitArraySize(bit_array_t *ba) {
    return ba->numBits;
}

canonical_original_code:
unsigned int BitArraySize(struct bit_array_t *ba) {
    return ba->numBits;
}

user_defined_types: struct bit_array_t { unsigned char *array; unsigned int numBits; }


BitArraySetAll

original_code:
void BitArraySetAll(bit_array_t *ba)
{
    int bits;
    unsigned char mask;
    if (ba == ((void *)0))
    {
        return;
    }
    memset((void *)(ba->array), (0x7f * 2 + 1), ((((ba->numBits) - 1) / 8) + 1));
    bits = ba->numBits % 8;
    if (bits != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - bits);
        ba->array[((ba->numBits - 1) / 8)] = mask;
    }
}

canonical_original_code:
void BitArraySetAll(struct bit_array_t *ba)
{
    int bits;
    unsigned char mask;
    if (ba == ((void *)0))
    {
        return;
    }
    memset((void *)(ba->array), (0x7f * 2 + 1), ((((ba->numBits) - 1) / 8) + 1));
    bits = ba->numBits % 8;
    if (bits != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - bits);
        ba->array[((ba->numBits - 1) / 8)] = mask;
    }
}

variable_types: bits int

variable_types:
mask
unsigned char


BitArrayClearAll

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

if ( a1 )
result = memset(*(void **)a1, 0, ((unsigned int)(*(_DWORD *)(a1 + 8) - 1) >> 3) + 1);
return result;
}

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

if ( a1 )
result = memset(*(void **)a1, 0, ((unsigned int)(*(_DWORD *)(a1 + 8) - 1) >> 3) + 1);
return result;
}

original_code:
void BitArrayClearAll(bit_array_t *ba)
{
    if (ba == ((void *)0))
    {
        return;
    }
    memset((void *)(ba->array), 0, ((((ba->numBits) - 1) / 8) + 1));
}

canonical_original_code:
void BitArrayClearAll(struct bit_array_t *ba)
{
    if (ba == ((void *)0))
    {
        return;
    }
    memset((void *)(ba->array), 0, ((((ba->numBits) - 1) / 8) + 1));
}


BitArrayClearBit

decompiled_code:
__int64 __fastcall BitArrayClearBit(__int64 a1, unsigned int a2)
{
char v2; // cl
__int64 result; // rax

if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) > a2 )
{
v2 = ~(_BYTE)a2 & 7;
result = (unsigned int)~(1 << v2);
*(_BYTE *)(*(_QWORD *)a1 + (a2 >> 3)) &= ~(1 << v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
char v2; // cl
__int64 result; // rax

if ( a1 )
{
if ( *(_DWORD *)(a1 + 8) > a2 )
{
v2 = ~(_BYTE)a2 & 7;
result = (unsigned int)~(1 << v2);
*(_BYTE *)(*(_QWORD *)a1 + (a2 >> 3)) &= ~(1 << v2);
}
}
return result;
}

original_code:
void BitArrayClearBit(bit_array_t *ba, unsigned int bit)
{
    unsigned char mask;
    if (ba == ((void *)0))
    {
        return;
    }
    if (ba->numBits <= bit)
    {
        return;
    }
    mask = (1 << (8 - 1 - ((bit) % 8)));
    mask = ~mask;
    ba->array[((bit) / 8)] &= mask;
}

canonical_original_code:
void BitArrayClearBit(struct bit_array_t *ba, unsigned int bit)
{
    unsigned char mask;
    if (ba == ((void *)0))
    {
        return;
    }
    if (ba->numBits <= bit)
    {
        return;
    }
    mask = (1 << (8 - 1 - ((bit) % 8)));
    mask = ~mask;
    ba->array[((bit) / 8)] &= mask;
}

variable_types:
bit
unsigned int


BitArrayGetBits

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

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

original_code:
void *BitArrayGetBits(bit_array_t *ba)
{
    return ((void *)(ba->array));
}

canonical_original_code:
void *BitArrayGetBits(struct bit_array_t *ba)
{
    return ((void *)(ba->array));
}

return_type: void *


BitArrayTestBit

decompiled_code:
__int64 __fastcall BitArrayTestBit(_QWORD *a1, unsigned int a2)
{
return ((int)*(unsigned __int8 *)(*a1 + (a2 >> 3)) >> (~(_BYTE)a2 & 7)) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, unsigned int a2)
{
return ((int)*(unsigned __int8 *)(*a1 + (a2 >> 3)) >> (~(_BYTE)a2 & 7)) & 1;
}

original_code:
int BitArrayTestBit(bit_array_t *ba, unsigned int bit)
{
    return((ba->array[((bit) / 8)] & (1 << (8 - 1 - ((bit) % 8)))) != 0);
}

canonical_original_code:
int BitArrayTestBit(struct bit_array_t *ba, unsigned int bit)
{
    return((ba->array[((bit) / 8)] & (1 << (8 - 1 - ((bit) % 8)))) != 0);
}


BitArrayCopy

decompiled_code:
void __fastcall BitArrayCopy(__int64 a1, __int64 a2)
{
int v2; // eax

if ( a1 && a2 )
{
v2 = *(_DWORD *)(a2 + 8);
if ( v2 == *(_DWORD *)(a1 + 8) )
memcpy(*(void **)a1, *(const void **)a2, ((unsigned int)(v2 - 1) >> 3) + 1);
}
}

original_code:
void BitArrayCopy(bit_array_t *dest, const bit_array_t *src)
{
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src->numBits != dest->numBits)
    {
        return;
    }
    memcpy((void *)(dest->array), (void *)(src->array),
        ((((src->numBits) - 1) / 8) + 1));
}

canonical_original_code:
void BitArrayCopy(struct bit_array_t *dest, struct bit_array_t *src)
{
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src->numBits != dest->numBits)
    {
        return;
    }
    memcpy((void *)(dest->array), (void *)(src->array),
        ((((src->numBits) - 1) / 8) + 1));
}

variable_types:
src
struct bit_array_t *


BitArrayNCopy

decompiled_code:
void __fastcall BitArrayNCopy(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax

if ( a2 )
{
if ( a1 )
{
v3 = *(_DWORD *)(a2 + 8);
if ( v3 >= a3 && *(_DWORD *)(a1 + 8) >= a3 )
memcpy(*(void **)a1, *(const void **)a2, ((v3 - 1) >> 3) + 1);
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, unsigned int a3)
{
unsigned int v3; // eax

if ( a2 )
{
if ( a1 )
{
v3 = *(_DWORD *)(a2 + 8);
if ( v3 >= a3 && *(_DWORD *)(a1 + 8) >= a3 )
memcpy(*(void **)a1, *(const void **)a2, ((v3 - 1) >> 3) + 1);
}
}
}

original_code:
void BitArrayNCopy(bit_array_t *dest, const bit_array_t *src, unsigned int n)
{
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (n > src->numBits || n > dest->numBits)
    {
        return;
    }
    memcpy((void *)(dest->array), (void *)(src->array),
        ((((src->numBits) - 1) / 8) + 1));
}

canonical_original_code:
void BitArrayNCopy(struct bit_array_t *dest, struct bit_array_t *src, unsigned int n)
{
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (n > src->numBits || n > dest->numBits)
    {
        return;
    }
    memcpy((void *)(dest->array), (void *)(src->array),
        ((((src->numBits) - 1) / 8) + 1));
}

variable_types:
n
unsigned int


BitArrayAnd

original_code:
void BitArrayAnd(bit_array_t *dest,
                 const bit_array_t *src1,
                 const bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] & src2->array[i];
    }
}

canonical_original_code:
void BitArrayAnd(struct bit_array_t *dest, struct bit_array_t *src1, struct bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] & src2->array[i];
    }
}

variable_types: i int


BitArrayOr

original_code:
void BitArrayOr(bit_array_t *dest,
           const bit_array_t *src1,
           const bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] | src2->array[i];
    }
}

canonical_original_code:
void BitArrayOr(struct bit_array_t *dest, struct bit_array_t *src1, struct bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] | src2->array[i];
    }
}


BitArrayXor

original_code:
void BitArrayXor(bit_array_t *dest,
            const bit_array_t *src1,
            const bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] ^ src2->array[i];
    }
}

canonical_original_code:
void BitArrayXor(struct bit_array_t *dest, struct bit_array_t *src1, struct bit_array_t *src2)
{
    int i;
    if (src1 == ((void *)0))
    {
        return;
    }
    if (src2 == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src1->numBits != dest->numBits)
    {
        return;
    }
    if (src2->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = src1->array[i] ^ src2->array[i];
    }
}


BitArrayNot

original_code:
void BitArrayNot(bit_array_t *dest,
            const bit_array_t *src)
{
    int i, bits;
    unsigned char mask;
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = ~(src->array[i]);
    }
    bits = dest->numBits % 8;
    if (bits != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - bits);
        dest->array[((dest->numBits - 1) / 8)] &= mask;
    }
}

canonical_original_code:
void BitArrayNot(struct bit_array_t *dest, struct bit_array_t *src)
{
    int i; int bits;
    unsigned char mask;
    if (src == ((void *)0))
    {
        return;
    }
    if (dest == ((void *)0))
    {
        return;
    }
    if (src->numBits != dest->numBits)
    {
        return;
    }
    for(i = 0; i < ((((dest->numBits) - 1) / 8) + 1); i++)
    {
        dest->array[i] = ~(src->array[i]);
    }
    bits = dest->numBits % 8;
    if (bits != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - bits);
        dest->array[((dest->numBits - 1) / 8)] &= mask;
    }
}


BitArrayShiftLeft

original_code:
void BitArrayShiftLeft(bit_array_t *ba, unsigned int shifts)
{
    int i, j;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = 0; (i + chars) < ((((ba->numBits) - 1) / 8) + 1); i++)
        {
            ba->array[i] = ba->array[i + chars];
        }
        for (i = ((((ba->numBits) - 1) / 8) + 1); chars > 0; chars--)
        {
            ba->array[i - chars] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = 0; j < ((ba->numBits - 1) / 8); j++)
        {
            ba->array[j] <<= 1;
            if (ba->array[j + 1] & (1 << (8 - 1)))
            {
                ba->array[j] |= 0x01;
            }
        }
        ba->array[((ba->numBits - 1) / 8)] <<= 1;
    }
}

canonical_original_code:
void BitArrayShiftLeft(struct bit_array_t *ba, unsigned int shifts)
{
    int i; int j;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = 0; (i + chars) < ((((ba->numBits) - 1) / 8) + 1); i++)
        {
            ba->array[i] = ba->array[i + chars];
        }
        for (i = ((((ba->numBits) - 1) / 8) + 1); chars > 0; chars--)
        {
            ba->array[i - chars] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = 0; j < ((ba->numBits - 1) / 8); j++)
        {
            ba->array[j] <<= 1;
            if (ba->array[j + 1] & (1 << (8 - 1)))
            {
                ba->array[j] |= 0x01;
            }
        }
        ba->array[((ba->numBits - 1) / 8)] <<= 1;
    }
}

variable_types:
shifts
unsigned int

variable_types: j int

variable_types: chars int


BitArrayShiftRight

original_code:
void BitArrayShiftRight(bit_array_t *ba, unsigned int shifts)
{
    int i, j;
    unsigned char mask;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = ((ba->numBits - 1) / 8); (i - chars) >= 0; i--)
        {
            ba->array[i] = ba->array[i - chars];
        }
        for (; chars > 0; chars--)
        {
            ba->array[chars - 1] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = ((ba->numBits - 1) / 8); j > 0; j--)
        {
            ba->array[j] >>= 1;
            if (ba->array[j - 1] & 0x01)
            {
                ba->array[j] |= (1 << (8 - 1));
            }
        }
        ba->array[0] >>= 1;
    }
    i = ba->numBits % 8;
    if (i != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - i);
        ba->array[((ba->numBits - 1) / 8)] &= mask;
    }
}

canonical_original_code:
void BitArrayShiftRight(struct bit_array_t *ba, unsigned int shifts)
{
    int i; int j;
    unsigned char mask;
    int chars = shifts / 8;
    shifts = shifts % 8;
    if (ba == ((void *)0))
    {
        return;
    }
    if (shifts >= ba->numBits)
    {
        BitArrayClearAll(ba);
        return;
    }
    if (chars > 0)
    {
        for (i = ((ba->numBits - 1) / 8); (i - chars) >= 0; i--)
        {
            ba->array[i] = ba->array[i - chars];
        }
        for (; chars > 0; chars--)
        {
            ba->array[chars - 1] = 0;
        }
    }
    for (i = 0; i < shifts; i++)
    {
        for (j = ((ba->numBits - 1) / 8); j > 0; j--)
        {
            ba->array[j] >>= 1;
            if (ba->array[j - 1] & 0x01)
            {
                ba->array[j] |= (1 << (8 - 1));
            }
        }
        ba->array[0] >>= 1;
    }
    i = ba->numBits % 8;
    if (i != 0)
    {
        mask = (0x7f * 2 + 1) << (8 - i);
        ba->array[((ba->numBits - 1) / 8)] &= mask;
    }
}


BitArrayDecrement

original_code:
void BitArrayDecrement(bit_array_t *ba)
{
    int i;
    unsigned char maxValue;
    unsigned char one;
    if (ba == ((void *)0))
    {
        return;
    }
    i = (ba->numBits % 8);
    if (i != 0)
    {
        maxValue = (0x7f * 2 + 1) << (8 - i);
        one = 1 << (8 - i);
    }
    else
    {
        maxValue = (0x7f * 2 + 1);
        one = 1;
    }
    for (i = ((ba->numBits - 1) / 8); i >= 0; i--)
    {
        if (ba->array[i] >= one)
        {
            ba->array[i] = ba->array[i] - one;
            return;
        }
        else
        {
            ba->array[i] = maxValue;
            maxValue = (0x7f * 2 + 1);
            one = 1;
        }
    }
}

canonical_original_code:
void BitArrayDecrement(struct bit_array_t *ba)
{
    int i;
    unsigned char maxValue;
    unsigned char one;
    if (ba == ((void *)0))
    {
        return;
    }
    i = (ba->numBits % 8);
    if (i != 0)
    {
        maxValue = (0x7f * 2 + 1) << (8 - i);
        one = 1 << (8 - i);
    }
    else
    {
        maxValue = (0x7f * 2 + 1);
        one = 1;
    }
    for (i = ((ba->numBits - 1) / 8); i >= 0; i--)
    {
        if (ba->array[i] >= one)
        {
            ba->array[i] = ba->array[i] - one;
            return;
        }
        else
        {
            ba->array[i] = maxValue;
            maxValue = (0x7f * 2 + 1);
            one = 1;
        }
    }
}

variable_types:
maxValue
unsigned char

variable_types:
one
unsigned char


BitArrayCompare

decompiled_code:
__int64 __fastcall BitArrayCompare(__int64 *a1, __int64 *a2)
{
unsigned int v2; // ecx
int v3; // edx
__int64 result; // rax
__int64 v5; // r8
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rcx
unsigned __int8 v9; // dl
int v10; // esi

if ( a1 )
{
v2 = *((_DWORD *)a1 + 2);
if ( a2 )
{
v3 = *((_DWORD *)a2 + 2);
result = v2 - v3;
if ( v3 == v2 )
{
v5 = *a1;
v6 = 0LL;
v7 = *a2;
v8 = ((unsigned int)(v3 - 1) >> 3) + 1;
do
{
v9 = *(_BYTE *)(v5 + v6);
v10 = *(unsigned __int8 *)(v7 + v6);
if ( v9 != (_BYTE)v10 )
return (unsigned int)v9 - v10;
++v6;
}
while ( v8 != v6 );
result = 0LL;
}
}
else
{
result = v2;
}
}
else
{
result = 0LL;
if ( a2 )
result = (unsigned int)-*((_DWORD *)a2 + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 *a1, __int64 *a2)
{
unsigned int v2; // ecx
int v3; // edx
__int64 result; // rax
__int64 v5; // r8
__int64 v6; // rax
__int64 v7; // rdi
__int64 v8; // rcx
unsigned __int8 v9; // dl
int v10; // esi

if ( a1 )
{
v2 = *((_DWORD *)a1 + 2);
if ( a2 )
{
v3 = *((_DWORD *)a2 + 2);
result = v2 - v3;
if ( v3 == v2 )
{
v5 = *a1;
v6 = 0LL;
v7 = *a2;
v8 = ((unsigned int)(v3 - 1) >> 3) + 1;
do
{
v9 = *(_BYTE *)(v5 + v6);
v10 = *(unsigned __int8 *)(v7 + v6);
if ( v9 != (_BYTE)v10 )
return (unsigned int)v9 - v10;
++v6;
}
while ( v8 != v6 );
result = 0LL;
}
}
else
{
result = v2;
}
}
else
{
result = 0LL;
if ( a2 )
result = (unsigned int)-*((_DWORD *)a2 + 2);
}
return result;
}

original_code:
int BitArrayCompare(const bit_array_t *ba1, const bit_array_t *ba2)
{
    int i;
    if (ba1 == ((void *)0))
    {
        if (ba2 == ((void *)0))
        {
            return 0;
        }
        else
        {
            return -(ba2->numBits);
        }
    }
    if (ba2 == ((void *)0))
    {
        return (ba1->numBits);
    }
    if (ba1->numBits != ba2->numBits)
    {
        return(ba1->numBits - ba2->numBits);
    }
    for(i = 0; i <= ((ba1->numBits - 1) / 8); i++)
    {
        if (ba1->array[i] != ba2->array[i])
        {
            return(ba1->array[i] - ba2->array[i]);
        }
    }
    return 0;
}

canonical_original_code:
int BitArrayCompare(struct bit_array_t *ba1, struct bit_array_t *ba2)
{
    int i;
    if (ba1 == ((void *)0))
    {
        if (ba2 == ((void *)0))
        {
            return 0;
        }
        else
        {
            return -(ba2->numBits);
        }
    }
    if (ba2 == ((void *)0))
    {
        return (ba1->numBits);
    }
    if (ba1->numBits != ba2->numBits)
    {
        return(ba1->numBits - ba2->numBits);
    }
    for(i = 0; i <= ((ba1->numBits - 1) / 8); i++)
    {
        if (ba1->array[i] != ba2->array[i])
        {
            return(ba1->array[i] - ba2->array[i]);
        }
    }
    return 0;
}


decompiled_code:
void __fastcall pqueue_delete(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
else
{
fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40LL, "Priority Queue is already NULL. Nothing to free.");
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(ptr);
}
else
{
fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40LL, "Priority Queue is already NULL. Nothing to free.");
}
}

original_code:
void pqueue_delete(PQueue *q) {
    if (q == ((void *)0)) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40, ("Priority Queue is already NULL. Nothing to free."));
        return;
    }
    free(q->data);
    free(q);
}

canonical_original_code:
void pqueue_delete(struct PQueue_s *q) {
    if (q == ((void *)0)) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 40, ("Priority Queue is already NULL. Nothing to free."));
        return;
    }
    free(q->data);
    free(q);
}

variable_types: struct PQueue_s { unsigned long size; unsigned long capacity; void **data; int (*cmp)(void *d1, void *d2); } *


decompiled_code:
int __fastcall pqueue_enqueue(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rdx
__int64 v5; // rcx
unsigned __int64 v6; // rdx
__int64 v7; // r12

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53LL, "q");
exit(-1);
}
v2 = *a1;
if ( *a1 >= a1[1] )
{
LODWORD(v3) = fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
55LL,
"Priority Queue is full. Cannot add another element .");
}
else
{
*(_QWORD *)(a1[2] + 8 * v2) = a2;
LODWORD(v3) = v2 + 1;
for ( *a1 = v2 + 1; v2; *(_QWORD *)(v3 + 8 * v2) = v5 )
{
v6 = v2;
v2 >>= 1;
v7 = 8 * v6;
LODWORD(v3) = ((__int64 (__fastcall *)(_QWORD, _QWORD))a1[3])(
*(_QWORD *)(a1[2] + 8 * v6),
*(_QWORD *)(a1[2] + 8 * v2));
if ( (int)v3 <= 0 )
break;
v4 = a1[2];
v5 = *(_QWORD *)(v4 + v7);
*(_QWORD *)(v4 + v7) = *(_QWORD *)(v4 + 8 * v2);
v3 = a1[2];
}
}
return v3;
}

canonical_decompiled_code:
int __fastcall func1(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rdx
__int64 v5; // rcx
unsigned __int64 v6; // rdx
__int64 v7; // r12

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53LL, "q");
exit(-1);
}
v2 = *a1;
if ( *a1 >= a1[1] )
{
LODWORD(v3) = fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
55LL,
"Priority Queue is full. Cannot add another element .");
}
else
{
*(_QWORD *)(a1[2] + 8 * v2) = a2;
LODWORD(v3) = v2 + 1;
for ( *a1 = v2 + 1; v2; *(_QWORD *)(v3 + 8 * v2) = v5 )
{
v6 = v2;
v2 >>= 1;
v7 = 8 * v6;
LODWORD(v3) = ((__int64 (__fastcall *)(_QWORD, _QWORD))a1[3])(
*(_QWORD *)(a1[2] + 8 * v6),
*(_QWORD *)(a1[2] + 8 * v2));
if ( (int)v3 <= 0 )
break;
v4 = a1[2];
v5 = *(_QWORD *)(v4 + v7);
*(_QWORD *)(v4 + v7) = *(_QWORD *)(v4 + 8 * v2);
v3 = a1[2];
}
}
return v3;
}

original_code:
void pqueue_enqueue(PQueue *q, const void *data) {
    size_t i;
    void *tmp = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53, "q"); exit(-1); } };
    if (q->size >= q->capacity) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 55, ("Priority Queue is full. Cannot add another element ."));
        return;
    }
    q->data[q->size] = (void*) data;
    i = q->size;
    q->size++;
    while(i > 0 && q->cmp(q->data[i], q->data[((i) / 2)]) > 0) {
        tmp = q->data[i];
        q->data[i] = q->data[((i) / 2)];
        q->data[((i) / 2)] = tmp;
        i = ((i) / 2);
    }
}

canonical_original_code:
void pqueue_enqueue(struct PQueue_s *q, void *data) {
    unsigned long i;
    void *tmp = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 53, "q"); exit(-1); } };
    if (q->size >= q->capacity) {
        fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 55, ("Priority Queue is full. Cannot add another element ."));
        return;
    }
    q->data[q->size] = (void *) data;
    i = q->size;
    q->size++;
    while(i > 0 && q->cmp(q->data[i], q->data[((i) / 2)]) > 0) {
        tmp = q->data[i];
        q->data[i] = q->data[((i) / 2)];
        q->data[((i) / 2)] = tmp;
        i = ((i) / 2);
    }
}

variable_types:
data
void *

variable_types:
i
unsigned long

variable_types:
tmp
void *

user_defined_types: struct PQueue_s { unsigned long size; unsigned long capacity; void **data; int (*cmp)(void *d1, void *d2); }


original_code:
void pqueue_heapify(PQueue *q, size_t idx) {
    void *tmp = ((void *)0);
    size_t l_idx, r_idx, lrg_idx;
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 93, "q"); exit(-1); } };
    l_idx = (2 * (idx) + 1);
    r_idx = (2 * (idx) + 2);
    if (l_idx < q->size && q->cmp(q->data[l_idx], q->data[idx]) > 0) {
        lrg_idx = l_idx;
    } else {
        lrg_idx = idx;
    }
    if (r_idx < q->size && q->cmp(q->data[r_idx], q->data[lrg_idx]) > 0) {
        lrg_idx = r_idx;
    }
    if (lrg_idx != idx) {
        tmp = q->data[lrg_idx];
        q->data[lrg_idx] = q->data[idx];
        q->data[idx] = tmp;
        pqueue_heapify(q, lrg_idx);
    }
}

canonical_original_code:
void pqueue_heapify(struct PQueue_s *q, unsigned long idx) {
    void *tmp = ((void *)0);
    unsigned long l_idx; unsigned long r_idx; unsigned long lrg_idx;
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 93, "q"); exit(-1); } };
    l_idx = (2 * (idx) + 1);
    r_idx = (2 * (idx) + 2);
    if (l_idx < q->size && q->cmp(q->data[l_idx], q->data[idx]) > 0) {
        lrg_idx = l_idx;
    } else {
        lrg_idx = idx;
    }
    if (r_idx < q->size && q->cmp(q->data[r_idx], q->data[lrg_idx]) > 0) {
        lrg_idx = r_idx;
    }
    if (lrg_idx != idx) {
        tmp = q->data[lrg_idx];
        q->data[lrg_idx] = q->data[idx];
        q->data[idx] = tmp;
        pqueue_heapify(q, lrg_idx);
    }
}

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall pqueue_dequeue(__int64 *a1)
{
__int64 v1; // rax
__int64 *v2; // rdx
__int64 v3; // r12
__int64 result; // rax

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77LL, "q");
exit(-1);
}
v1 = *a1;
if ( *a1 )
{
v2 = (__int64 *)a1[2];
v3 = *v2;
*v2 = v2[v1 - 1];
*a1 = v1 - 1;
pqueue_heapify((__int64)a1, 0LL);
result = v3;
}
else
{
fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
78LL,
"Priority Queue underflow . Cannot remove another element .");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rax
__int64 *v2; // rdx
__int64 v3; // r12
__int64 result; // rax

if ( !a1 )
{
fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77LL, "q");
exit(-1);
}
v1 = *a1;
if ( *a1 )
{
v2 = (__int64 *)a1[2];
v3 = *v2;
*v2 = v2[v1 - 1];
*a1 = v1 - 1;
func2((__int64)a1, 0LL);
result = v3;
}
else
{
fprintf(
stderr,
"%s:%d %s",
"lib/pqueue/pqueue.c",
78LL,
"Priority Queue underflow . Cannot remove another element .");
result = 0LL;
}
return result;
}

original_code:
void *pqueue_dequeue(PQueue *q) {
    void *data = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77, "q"); exit(-1); } };
    if (q->size < 1) { fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 78, ("Priority Queue underflow . Cannot remove another element .")); return ((void *)0); } data = q->data[0];
    q->data[0] = q->data[q->size-1];
    q->size--;
    pqueue_heapify(q, 0);
    return (data);
}

canonical_original_code:
void *pqueue_dequeue(struct PQueue_s *q) {
    void *data = ((void *)0);
    { if (((void *)0) == (q)) { fprintf(stderr, "%s:%d NULL POINTER: %s n", "lib/pqueue/pqueue.c", 77, "q"); exit(-1); } };
    if (q->size < 1) { fprintf(stderr, "%s:%d %s", "lib/pqueue/pqueue.c", 78, ("Priority Queue underflow . Cannot remove another element .")); return ((void *)0); } data = q->data[0];
    q->data[0] = q->data[q->size-1];
    q->size--;
    pqueue_heapify(q, 0);
    return (data);
}


DetermineEndianess

decompiled_code:
__int64 DetermineEndianess()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
endian_t DetermineEndianess(void)
{
    endian_t endian;
    endian_test_t endianTest;
    endianTest.word = 1;
    if (endianTest.bytes[0] == 1)
    {
        endian = BF_LITTLE_ENDIAN;
    }
    else if (endianTest.bytes[sizeof(unsigned long) - 1] == 1)
    {
        endian = BF_BIG_ENDIAN;
    }
    else
    {
        endian = BF_UNKNOWN_ENDIAN;
    }
    return endian;
}

canonical_original_code:
enum endian_t DetermineEndianess()
{
    enum endian_t endian;
    union endian_test_t endianTest;
    endianTest.word = 1;
    if (endianTest.bytes[0] == 1)
    {
        endian = BF_LITTLE_ENDIAN;
    }
    else if (endianTest.bytes[sizeof(unsigned long) - 1] == 1)
    {
        endian = BF_BIG_ENDIAN;
    }
    else
    {
        endian = BF_UNKNOWN_ENDIAN;
    }
    return endian;
}

variable_types: enum endian_t { BF_UNKNOWN_ENDIAN=0, BF_LITTLE_ENDIAN=1, BF_BIG_ENDIAN=2 }

variable_types: union endian_test_t { unsigned long word; unsigned char bytes[-1]; }


decompiled_code:
__int64 __fastcall compress_bytestats2tree(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rdi
__int64 v5; // rax
unsigned int v6; // ebx
__int64 v7; // r13
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // r13

v2 = 0LL;
v3 = pqueue_new(compare, *(unsigned int *)(a1 + 4));
do
{
while ( !*(_DWORD *)(a1 + 4 * v2 + 8) )
{
if ( ++v2 == 256 )
goto LABEL_5;
}
v4 = (unsigned int)v2++;
v5 = tree_create_leaf(v4);
pqueue_enqueue(v3, v5);
}
while ( v2 != 256 );
LABEL_5:
if ( *(_DWORD *)(a1 + 4) > 1u )
{
v6 = 1;
do
{
++v6;
v7 = pqueue_dequeue(v3);
v8 = pqueue_dequeue(v3);
v9 = tree_create_branch(v7, v8);
pqueue_enqueue(v3, v9);
}
while ( *(_DWORD *)(a1 + 4) > v6 );
}
v10 = pqueue_dequeue(v3);
pqueue_delete(v3);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rdi
__int64 v5; // rax
unsigned int v6; // ebx
__int64 v7; // r13
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // r13

v2 = 0LL;
v3 = pqueue_new(compare, *(unsigned int *)(a1 + 4));
do
{
while ( !*(_DWORD *)(a1 + 4 * v2 + 8) )
{
if ( ++v2 == 256 )
goto LABEL_5;
}
v4 = (unsigned int)v2++;
v5 = tree_create_leaf(v4);
pqueue_enqueue(v3, v5);
}
while ( v2 != 256 );
LABEL_5:
if ( *(_DWORD *)(a1 + 4) > 1u )
{
v6 = 1;
do
{
++v6;
v7 = pqueue_dequeue(v3);
v8 = pqueue_dequeue(v3);
v9 = tree_create_branch(v7, v8);
pqueue_enqueue(v3, v9);
}
while ( *(_DWORD *)(a1 + 4) > v6 );
}
v10 = pqueue_dequeue(v3);
pqueue_delete(v3);
return v10;
}

original_code:
tree_node* compress_bytestats2tree(compress_bytestats *stats) {
  void* pq = pqueue_new(_compare, (size_t) stats->uniquebytes);
  tree_node *leaf, *leaf2;
  int i;
  for (i = 0; i < 256; i++) {
    if (stats->counts[i] > 0) {
      leaf = tree_create_leaf(i, stats->counts[i]);
      pqueue_enqueue(pq, (void *) leaf);
    }
  }
  for (i = 1; i < stats->uniquebytes; i++) {
    leaf = (tree_node *) pqueue_dequeue(pq);
    leaf2 = (tree_node *) pqueue_dequeue(pq);
    pqueue_enqueue(pq, (void *) tree_create_branch(leaf, leaf2));
  }
  leaf = (tree_node *) pqueue_dequeue(pq);
  pqueue_delete(pq);
  return leaf;
}

canonical_original_code:
struct tree_node *compress_bytestats2tree(struct compress_bytestats *stats) {
  void *pq = pqueue_new(_compare, (size_t) stats->uniquebytes);
  struct tree_node *leaf; struct tree_node *leaf2;
  int i;
  for (i = 0; i < 256; i++) {
    if (stats->counts[i] > 0) {
      leaf = tree_create_leaf(i, stats->counts[i]);
      pqueue_enqueue(pq, (void *) leaf);
    }
  }
  for (i = 1; i < stats->uniquebytes; i++) {
    leaf = (struct tree_node *) pqueue_dequeue(pq);
    leaf2 = (struct tree_node *) pqueue_dequeue(pq);
    pqueue_enqueue(pq, (void *) tree_create_branch(leaf, leaf2));
  }
  leaf = (struct tree_node *) pqueue_dequeue(pq);
  pqueue_delete(pq);
  return leaf;
}

variable_types: struct compress_bytestats { unsigned int totalcount; unsigned int uniquebytes; unsigned int counts[256]; } *

variable_types:
pq
void *

variable_types: struct tree_node { unsigned char content; unsigned int count; struct tree_node *left; } *


main

canonical_name: main

repo: betasam/apptemplate

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

result = s32f_app_init(v4, s32f_fibonacci_app, envp);
if ( !result )
result = s32f_app_exec(v4, (unsigned int)argc, argv);
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

result = func7(v4, s32f_fibonacci_app, envp);
if ( !result )
result = func8(v4, (unsigned int)argc, argv);
return result;
}

original_code:
int main(int argc, char *argv[])
{
    int s32v_retval = 0;
    app_t main_app;
    s32v_retval = s32f_app_init(&main_app, &s32f_fibonacci_app);
    if (s32v_retval == 0) {
        s32v_retval = s32f_app_exec(&main_app, argc, argv);
    }
    return s32v_retval;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int s32v_retval = 0;
    struct _app_s main_app;
    s32v_retval = s32f_app_init(&main_app, &s32f_fibonacci_app);
    if (s32v_retval == 0) {
        s32v_retval = s32f_app_exec(&main_app, argc, argv);
    }
    return s32v_retval;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _app_s { int s32v_state; int (*main)(int argc, char *argv[]); int s32v_return; }


repo: bezeredi/libdstructs

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

if ( a1 )
result = *(unsigned int *)(a1 + 24);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 24);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int ll_size(llist_t* const list) {
   return (list ? list->__size : -1);
}

canonical_original_code:
int ll_size(struct __llist_s *list) {
   return (list ? list->__size : -1);
}

variable_types: struct __llist_s { void *__first; void *__last; unsigned long __elem_size; int __size; } *


decompiled_code:
__int64 __fastcall ll_contains(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r12

if ( !a1 )
return 0LL;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return 0LL;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, const void *a2)
{
__int64 v2; // rbx
size_t v3; // r12

if ( !a1 )
return 0LL;
v2 = *a1;
v3 = a1[2];
if ( !*a1 )
return 0LL;
while ( memcmp(a2, *(const void **)v2, v3) )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
int ll_contains(llist_t* const list, void* const elem) {
   __node_t *temp;
   size_t num_bytes;
   if(!list) return !1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return 1;
      temp = temp->next;
   }
   return !1;
}

canonical_original_code:
int ll_contains(struct __llist_s *list, void *elem) {
   struct __node_s *temp;
   unsigned long num_bytes;
   if(!list) return !1;
   temp = list->__first;
   num_bytes = list->__elem_size;
   while(temp) {
      if(memcmp(elem, temp->element, num_bytes) == 0)
         return 1;
      temp = temp->next;
   }
   return !1;
}

variable_types:
elem
void *

variable_types: struct __node_s { void *element; int index; struct __node_s *prev; struct __node_s *next; } *

user_defined_types: struct __llist_s { void *__first; void *__last; unsigned long __elem_size; int __size; }


original_code:
int ll_add(llist_t* const list, int index, void* const elem) {
   __node_t *temp, *new;
   int count;
   if(!list) return !1;
   if(index < 0 || index > list->__size)
      return !1;
   new = malloc(sizeof(__node_t));
   if(!new) return !1;
   new->element = elem;
   new->index = index;
   new->prev = ((void *)0);
   new->next = ((void *)0);
   if((!ll_first(list))) {
      list->__first = new;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == list->__size) {
      temp = list->__last;
      temp->next = new;
      new->prev = temp;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == 0) {
      new->next = list->__first;
      ((__node_t*) list->__first)->prev = new;
      list->__first = new;
   }
   else {
      count = 0;
      temp = list->__first;
      while(temp->next) {
         if(count == index) {
            new->next = temp->next;
            new->prev = temp;
            temp->next->prev = new;
            temp->next = new;
            break;
         }
         temp = temp->next;
         count++;
      }
   }
   temp = new->next;
   list->__size++;
   return 1;
}

canonical_original_code:
int ll_add(struct __llist_s *list, int index, void *elem) {
   struct __node_s *temp; struct __node_s *new;
   int count;
   if(!list) return !1;
   if(index < 0 || index > list->__size)
      return !1;
   new = malloc(sizeof(__node_t));
   if(!new) return !1;
   new->element = elem;
   new->index = index;
   new->prev = ((void *)0);
   new->next = ((void *)0);
   if((!ll_first(list))) {
      list->__first = new;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == list->__size) {
      temp = list->__last;
      temp->next = new;
      new->prev = temp;
      list->__last = new;
      list->__size++;
      return 1;
   }
   if(index == 0) {
      new->next = list->__first;
      ((struct __node_s *) list->__first)->prev = new;
      list->__first = new;
   }
   else {
      count = 0;
      temp = list->__first;
      while(temp->next) {
         if(count == index) {
            new->next = temp->next;
            new->prev = temp;
            temp->next->prev = new;
            temp->next = new;
            break;
         }
         temp = temp->next;
         count++;
      }
   }
   temp = new->next;
   list->__size++;
   return 1;
}

variable_types: index int

variable_types: count int

user_defined_types: struct __node_s { void *element; int index; struct __node_s *prev; struct __node_s *next; }


decompiled_code:
__int64 __fastcall ll_addf(__int64 a1, __int64 a2)
{
return ll_add(a1, 0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return func2(a1, 0, a2);
}

original_code:
void ll_addf(llist_t* const list, void* const elem) {
   ll_add(list, 0, elem);
}

canonical_original_code:
void ll_addf(struct __llist_s *list, void *elem) {
   ll_add(list, 0, elem);
}


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

if ( a1 )
result = ll_add(a1, *(_DWORD *)(a1 + 24), a2);
return result;
}

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

if ( a1 )
result = func2(a1, *(_DWORD *)(a1 + 24), a2);
return result;
}

original_code:
void ll_addl(llist_t* const list, void* const elem) {
   if(!list) return;
   ll_add(list, list->__size, elem);
}

canonical_original_code:
void ll_addl(struct __llist_s *list, void *elem) {
   if(!list) return;
   ll_add(list, list->__size, elem);
}