original_code:
ddColor
ddGradient_getColor(ddGradient* g, int ratio)
{
 struct _ddGradEntry *e;
 while ( g->band > 0 && g->entries[g->band].ratio > ratio )
  --g->band;
 while ( g->band < g->nGrads-1 && g->entries[g->band+1].ratio < ratio )
  ++g->band;
 e = &(g->entries[g->band]);
 if ( g->band == g->nGrads-1 )
  return ((((e->alpha)&0xff)<<24)|(((e->red)&0xff)<<16)|(((e->green)&0xff)<<8)|((e->blue)&0xff));
 ratio -= e->ratio;
 if ( ratio <= 0 )
  return ((((e->alpha)&0xff)<<24)|(((e->red)&0xff)<<16)|(((e->green)&0xff)<<8)|((e->blue)&0xff));
 else
  return ((((e->alpha + ((e->alphaslope * ratio) >> 16))&0xff)<<24)|(((e->red + ((e->redslope * ratio) >> 16))&0xff)<<16)|(((e->green + ((e->greenslope * ratio) >> 16))&0xff)<<8)|((e->blue + ((e->blueslope * ratio) >> 16))&0xff));
}

canonical_original_code:
unsigned int ddGradient_getColor(struct _ddGradient *g, int ratio)
{
 struct _ddGradEntry *e;
 while ( g->band > 0 && g->entries[g->band].ratio > ratio )
  --g->band;
 while ( g->band < g->nGrads-1 && g->entries[g->band+1].ratio < ratio )
  ++g->band;
 e = &(g->entries[g->band]);
 if ( g->band == g->nGrads-1 )
  return ((((e->alpha)&0xff)<<24)|(((e->red)&0xff)<<16)|(((e->green)&0xff)<<8)|((e->blue)&0xff));
 ratio -= e->ratio;
 if ( ratio <= 0 )
  return ((((e->alpha)&0xff)<<24)|(((e->red)&0xff)<<16)|(((e->green)&0xff)<<8)|((e->blue)&0xff));
 else
  return ((((e->alpha + ((e->alphaslope * ratio) >> 16))&0xff)<<24)|(((e->red + ((e->redslope * ratio) >> 16))&0xff)<<16)|(((e->green + ((e->greenslope * ratio) >> 16))&0xff)<<8)|((e->blue + ((e->blueslope * ratio) >> 16))&0xff));
}

variable_types: ratio int


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:
color
unsigned int

variable_types: scale int

return_type: unsigned int


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

v2 = HIBYTE(a1);
result = a1;
if ( HIBYTE(a1) != 0xFF && HIBYTE(a2) )
{
result = a2;
if ( v2 )
result = a1 + (unsigned int)ddColor_scale(a2, 255 - v2);
}
return result;
}

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

v2 = HIBYTE(a1);
result = a1;
if ( HIBYTE(a1) != 0xFF && HIBYTE(a2) )
{
result = a2;
if ( v2 )
result = a1 + (unsigned int)func0(a2, 255 - v2);
}
return result;
}

original_code:
static ddColor inline
alpha_blend(ddColor c1, ddColor c2)
{
 UInt8 alpha1 = (((c1)>>24)&0xff);
 if ( alpha1 == 0xff || (((c2)>>24)&0xff) == 0 )
  return c1;
 if ( (((c1)>>24)&0xff) == 0 )
  return c2;
 return c1 + ddColor_scale(c2, 0xff - alpha1);
}

canonical_original_code:
static inline unsigned int alpha_blend(unsigned int c1, unsigned int c2)
{
 unsigned char alpha1 = (((c1)>>24)&0xff);
 if ( alpha1 == 0xff || (((c2)>>24)&0xff) == 0 )
  return c1;
 if ( (((c1)>>24)&0xff) == 0 )
  return c2;
 return c1 + ddColor_scale(c2, 0xff - alpha1);
}


decompiled_code:
void __fastcall dd_destroyImage(void *ptr)
{
if ( (*(_BYTE *)ptr & 1) != 0 )
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( (*(_BYTE *)ptr & 1) != 0 )
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
dd_destroyImage(ddImage* image)
{
 if ( image->flags & DDIMAGE_ALLOCEDBUFFER )
  free(image->data);
 free(image);
}

canonical_original_code:
void dd_destroyImage(struct _ddImage *image)
{
 if ( image->flags & DDIMAGE_ALLOCEDBUFFER )
  free(image->data);
 free(image);
}

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

return_type: void

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


decompiled_code:
__int64 __fastcall ddImage_compositeTempBuffer(__int64 a1, __int64 a2, int a3, int a4, int a5)
{
__int64 result; // rax
unsigned int *v6; // rbx
unsigned int *v7; // rbp
__int64 v8; // r12

result = 4LL * a4;
v6 = (unsigned int *)(*(_QWORD *)(a1 + 16) + result + a3 * *(unsigned __int16 *)(a1 + 8));
if ( a4 < a5 )
{
v7 = (unsigned int *)(a2 + result);
v8 = (__int64)&v6[a5 - 1 - a4 + 1];
do
{
result = alpha_blend(*v6, *v7);
*v6++ = result;
++v7;
}
while ( v6 != (unsigned int *)v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, int a4, int a5)
{
__int64 result; // rax
unsigned int *v6; // rbx
unsigned int *v7; // rbp
__int64 v8; // r12

result = 4LL * a4;
v6 = (unsigned int *)(*(_QWORD *)(a1 + 16) + result + a3 * *(unsigned __int16 *)(a1 + 8));
if ( a4 < a5 )
{
v7 = (unsigned int *)(a2 + result);
v8 = (__int64)&v6[a5 - 1 - a4 + 1];
do
{
result = func1(*v6, *v7);
*v6++ = result;
++v7;
}
while ( v6 != (unsigned int *)v8 );
}
return result;
}

original_code:
void
ddImage_compositeTempBuffer(ddImage* image, ddColor* buffer, int y, int left, int right)
{
 ddColor* p = (ddColor*)(image->data + y * image->rowstride);
 int x;
 p += left;
 for ( x = left; x < right; ++x )
 {
  *p = alpha_blend(*p, buffer[x]);
  ++p;
 }
}

canonical_original_code:
void ddImage_compositeTempBuffer(struct _ddImage *image, unsigned int *buffer, int y, int left, int right)
{
 unsigned int *p = (ddColor*)(image->data + y * image->rowstride);
 int x;
 p += left;
 for ( x = left; x < right; ++x )
 {
  *p = alpha_blend(*p, buffer[x]);
  ++p;
 }
}

variable_types:
buffer
unsigned int *

variable_types: y int

variable_types: left int

variable_types: right int

variable_types:
p
unsigned int *

variable_types: x int

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


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

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

original_code:
UInt8*
ddImage_getData(ddImage* image)
{
 return image->data;
}

canonical_original_code:
unsigned char *ddImage_getData(struct _ddImage *image)
{
 return image->data;
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall ddImage_getRowstride(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 8);
}

original_code:
int
ddImage_getRowstride(ddImage* image)
{
 return image->rowstride;
}

canonical_original_code:
int ddImage_getRowstride(struct _ddImage *image)
{
 return image->rowstride;
}

return_type: int


decompiled_code:
__int64 __fastcall ddImage_getWidth(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 4);
}

original_code:
int
ddImage_getWidth(ddImage* image)
{
 return image->width;
}

canonical_original_code:
int ddImage_getWidth(struct _ddImage *image)
{
 return image->width;
}


decompiled_code:
__int64 __fastcall ddImage_getHeight(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 6);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned __int16 *)(a1 + 6);
}

original_code:
int
ddImage_getHeight(ddImage* image)
{
 return image->height;
}

canonical_original_code:
int ddImage_getHeight(struct _ddImage *image)
{
 return image->height;
}


decompiled_code:
void __fastcall ddImage_setBuffer(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void
ddImage_setBuffer(ddImage* image, UInt8* buffer)
{
 image->data = buffer;
}

canonical_original_code:
void ddImage_setBuffer(struct _ddImage *image, unsigned char *buffer)
{
 image->data = buffer;
}

variable_types:
buffer
unsigned char *


original_code:
void
ddImage_clear(ddImage* image, ddColor color)
{
 int x, y;
 for ( y = 0; y < image->height; ++y )
 {
  ddColor* row = (ddColor*)(image->data + (y * image->rowstride));
  for ( x = 0; x < image->width; ++x )
   row[x] = color;
 }
}

canonical_original_code:
void ddImage_clear(struct _ddImage *image, unsigned int color)
{
 int x; int y;
 for ( y = 0; y < image->height; ++y )
 {
  unsigned int *row = (ddColor*)(image->data + (y * image->rowstride));
  for ( x = 0; x < image->width; ++x )
   row[x] = color;
 }
}

variable_types:
row
unsigned int *


decompiled_code:
void *__fastcall ddImage_clearWhite(__int64 a1)
{
return memset(*(void **)(a1 + 16), 255, 4LL * *(unsigned __int16 *)(a1 + 6) * *(unsigned __int16 *)(a1 + 8));
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1)
{
return memset(*(void **)(a1 + 16), 255, 4LL * *(unsigned __int16 *)(a1 + 6) * *(unsigned __int16 *)(a1 + 8));
}

original_code:
void
ddImage_clearWhite(ddImage* image)
{
 memset(image->data, 0xff, image->rowstride * image->height * sizeof(ddColor));
}

canonical_original_code:
void ddImage_clearWhite(struct _ddImage *image)
{
 memset(image->data, 0xff, image->rowstride * image->height * sizeof(ddColor));
}


decompiled_code:
void *__fastcall ddImage_clearBlack(__int64 a1)
{
return memset(*(void **)(a1 + 16), 0, 4LL * *(unsigned __int16 *)(a1 + 6) * *(unsigned __int16 *)(a1 + 8));
}

canonical_decompiled_code:
void *__fastcall func11(__int64 a1)
{
return memset(*(void **)(a1 + 16), 0, 4LL * *(unsigned __int16 *)(a1 + 6) * *(unsigned __int16 *)(a1 + 8));
}

original_code:
void
ddImage_clearBlack(ddImage* image)
{
 memset(image->data, 0, image->rowstride * image->height * sizeof(ddColor));
}

canonical_original_code:
void ddImage_clearBlack(struct _ddImage *image)
{
 memset(image->data, 0, image->rowstride * image->height * sizeof(ddColor));
}


original_code:
void
ddImage_fillRect(ddImage* image, ddRect rect, ddColor color)
{
 int x, y;
 if ( !((rect).left != 0x7fffffff) )
  return;
 for ( y = ((rect.top)>>10); y < ((rect.bottom)>>10); ++y )
 {
  ddColor* row = (ddColor*)(image->data + (y * image->rowstride));
  for ( x = ((rect.left)>>10); x < ((rect.right)>>10); ++x )
   row[x] = color;
 }
}

canonical_original_code:
void ddImage_fillRect(struct _ddImage *image, struct _ddRect rect, unsigned int color)
{
 int x; int y;
 if ( !((rect).left != 0x7fffffff) )
  return;
 for ( y = ((rect.top)>>10); y < ((rect.bottom)>>10); ++y )
 {
  unsigned int *row = (ddColor*)(image->data + (y * image->rowstride));
  for ( x = ((rect.left)>>10); x < ((rect.right)>>10); ++x )
   row[x] = color;
 }
}

variable_types: struct _ddRect { int left; int right; int top; int bottom; }


original_code:
void
ddImage_blendRect(ddImage* image, ddRect rect, ddColor color)
{
 int x, y;
 if ( !((rect).left != 0x7fffffff) )
  return;
 for ( y = ((rect.top)>>10); y < ((rect.bottom)>>10); ++y )
 {
  for ( x = ((rect.left)>>10); x < ((rect.right)>>10); ++x )
  {
   ddColor *p = (ddColor*)(image->data + y * image->rowstride + x * sizeof(ddColor));
   *p = alpha_blend(*p, color);
  }
 }
}

canonical_original_code:
void ddImage_blendRect(struct _ddImage *image, struct _ddRect rect, unsigned int color)
{
 int x; int y;
 if ( !((rect).left != 0x7fffffff) )
  return;
 for ( y = ((rect.top)>>10); y < ((rect.bottom)>>10); ++y )
 {
  for ( x = ((rect.left)>>10); x < ((rect.right)>>10); ++x )
  {
   unsigned int *p = (ddColor*)(image->data + y * image->rowstride + x * sizeof(ddColor));
   *p = alpha_blend(*p, color);
  }
 }
}

user_defined_types: struct _ddRect { int left; int right; int top; int bottom; }


original_code:
void
ddImage_clearRect(ddImage* image, ddRect rect)
{
 UInt8 *p, *end;
 int w, d;
 if ( !((rect).left != 0x7fffffff) )
  return;
 p = image->data + ((rect.top)>>10) * image->rowstride + ((rect.left)>>10) * sizeof(ddColor);
 end = p + (((rect.bottom)>>10) - ((rect.top)>>10)) * image->rowstride;
 w = (((rect.right)>>10) - ((rect.left)>>10)) * sizeof(ddColor);
 d = image->rowstride;
 while ( p < end )
 {
  memset(p, 0, w);
  p += d;
 }
}

canonical_original_code:
void ddImage_clearRect(struct _ddImage *image, struct _ddRect rect)
{
 unsigned char *p; unsigned char *end;
 int w; int d;
 if ( !((rect).left != 0x7fffffff) )
  return;
 p = image->data + ((rect.top)>>10) * image->rowstride + ((rect.left)>>10) * sizeof(ddColor);
 end = p + (((rect.bottom)>>10) - ((rect.top)>>10)) * image->rowstride;
 w = (((rect.right)>>10) - ((rect.left)>>10)) * sizeof(ddColor);
 d = image->rowstride;
 while ( p < end )
 {
  memset(p, 0, w);
  p += d;
 }
}

variable_types:
p
unsigned char *

variable_types:
end
unsigned char *

variable_types: w int

variable_types: d int


original_code:
void
ddImage_fillRect_white(ddImage* image, ddRect rect)
{
 UInt8 *p, *end;
 int w, d;
 if ( !((rect).left != 0x7fffffff) )
  return;
 p = image->data + ((rect.top)>>10) * image->rowstride + ((rect.left)>>10) * sizeof(ddColor);
 end = p + (((rect.bottom)>>10) - ((rect.top)>>10)) * image->rowstride;
 w = (((rect.right)>>10) - ((rect.left)>>10)) * sizeof(ddColor);
 d = image->rowstride;
 while ( p < end )
 {
  memset(p, 0xff, w);
  p += d;
 }
}

canonical_original_code:
void ddImage_fillRect_white(struct _ddImage *image, struct _ddRect rect)
{
 unsigned char *p; unsigned char *end;
 int w; int d;
 if ( !((rect).left != 0x7fffffff) )
  return;
 p = image->data + ((rect.top)>>10) * image->rowstride + ((rect.left)>>10) * sizeof(ddColor);
 end = p + (((rect.bottom)>>10) - ((rect.top)>>10)) * image->rowstride;
 w = (((rect.right)>>10) - ((rect.left)>>10)) * sizeof(ddColor);
 d = image->rowstride;
 while ( p < end )
 {
  memset(p, 0xff, w);
  p += d;
 }
}


original_code:
void
ddImage_fillRect_black(ddImage* image, ddRect rect)
{
 UInt8 *p, *end;
 int w, d;
 if ( !((rect).left != 0x7fffffff) )
  return;
 p = image->data + ((rect.top)>>10) * image->rowstride + ((rect.left)>>10) * sizeof(ddColor);
 end = p + (((rect.bottom)>>10) - ((rect.top)>>10)) * image->rowstride;
 w = (((rect.right)>>10) - ((rect.left)>>10)) * sizeof(ddColor);
 d = image->rowstride;
 while ( p < end )
 {
  memset(p, 0, w);
  p += d;
 }
}

canonical_original_code:
void ddImage_fillRect_black(struct _ddImage *image, struct _ddRect rect)
{
 unsigned char *p; unsigned char *end;
 int w; int d;
 if ( !((rect).left != 0x7fffffff) )
  return;
 p = image->data + ((rect.top)>>10) * image->rowstride + ((rect.left)>>10) * sizeof(ddColor);
 end = p + (((rect.bottom)>>10) - ((rect.top)>>10)) * image->rowstride;
 w = (((rect.right)>>10) - ((rect.left)>>10)) * sizeof(ddColor);
 d = image->rowstride;
 while ( p < end )
 {
  memset(p, 0, w);
  p += d;
 }
}


mixaudio

decompiled_code:
__int64 __fastcall mixaudio(__int64 a1, __int64 a2, int a3)
{
int v4; // edx

v4 = a3 + 3;
if ( a3 >= 0 )
v4 = a3;
return ringBuffer_writeSamplesToStream(ring, a2, (unsigned int)(v4 >> 2));
}

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

v4 = a3 + 3;
if ( a3 >= 0 )
v4 = a3;
return ringBuffer_writeSamplesToStream(ring, a2, (unsigned int)(v4 >> 2));
}

original_code:
void
mixaudio(void* unused, Uint8* stream, int len)
{
 ringBuffer_writeSamplesToStream(ring, stream, len / 4);
}

canonical_original_code:
void mixaudio(void *unused, unsigned char *stream, int len)
{
 ringBuffer_writeSamplesToStream(ring, stream, len / 4);
}

variable_types:
unused
void *

variable_types:
stream
unsigned char *

variable_types: len int


doNothing

decompiled_code:
void doNothing()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void doNothing(char *msg, ...)
{
}

canonical_original_code:
void doNothing(char *msg, ...)
{
}

variable_types:
msg
char *


sdlerror

decompiled_code:
void __fastcall __noreturn sdlerror(const char *a1)
{
FILE *v1; // rbx
const char *v2; // rax

fputs(a1, stderr);
fwrite(&unk_590, 1uLL, 2uLL, stderr);
v1 = stderr;
v2 = (const char *)SDL_GetError();
fputs(v2, v1);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
FILE *v1; // rbx
const char *v2; // rax

fputs(a1, stderr);
fwrite(&unk_590, 1uLL, 2uLL, stderr);
v1 = stderr;
v2 = (const char *)SDL_GetError();
fputs(v2, v1);
fputc(10, stderr);
exit(1);
}

original_code:
void sdlerror(char* msg)
{
 fputs(msg, stderr);
 fputs(": ", stderr);
 fputs(SDL_GetError(), stderr);
 fputs("\n", stderr);
 exit(1);
}

canonical_original_code:
void sdlerror(char *msg)
{
 fputs(msg, stderr);
 fputs(": ", stderr);
 fputs(SDL_GetError(), stderr);
 fputs("\n", stderr);
 exit(1);
}


decompiled_code:
__int64 dd_initSDL()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
__int16 v2; // [rsp+4h] [rbp-24h]
char v3; // [rsp+6h] [rbp-22h]
__int16 v4; // [rsp+8h] [rbp-20h]
__int64 (__fastcall *v5)(__int64, __int64, int); // [rsp+10h] [rbp-18h]
__int64 v6; // [rsp+18h] [rbp-10h]

if ( (int)SDL_Init(1048624LL) < 0 )
sdlerror("Couldn't initialize SDL");
screen = SDL_SetVideoMode(320LL, 240LL, 32LL, 1LL);
if ( !screen )
sdlerror("Couldn't set SDL video mode");
v1 = 22100;
v2 = -28656;
v3 = 2;
v4 = 2048;
v5 = mixaudio;
v6 = 0LL;
ring = newRingBuffer(44000LL);
result = SDL_OpenAudio(&v1, 0LL);
if ( (int)result < 0 )
sdlerror("Unable to open audio");
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int v1; // [rsp+0h] [rbp-28h] BYREF
__int16 v2; // [rsp+4h] [rbp-24h]
char v3; // [rsp+6h] [rbp-22h]
__int16 v4; // [rsp+8h] [rbp-20h]
__int64 (__fastcall *v5)(__int64, __int64, int); // [rsp+10h] [rbp-18h]
__int64 v6; // [rsp+18h] [rbp-10h]

if ( (int)SDL_Init(1048624LL) < 0 )
func2("Couldn't initialize SDL");
screen = SDL_SetVideoMode(320LL, 240LL, 32LL, 1LL);
if ( !screen )
func2("Couldn't set SDL video mode");
v1 = 22100;
v2 = -28656;
v3 = 2;
v4 = 2048;
v5 = mixaudio;
v6 = 0LL;
ring = newRingBuffer(44000LL);
result = SDL_OpenAudio(&v1, 0LL);
if ( (int)result < 0 )
func2("Unable to open audio");
return result;
}

original_code:
void
dd_initSDL()
{
 if ( SDL_Init(0x00000020 | 0x00000010 | 0x00100000) < 0 )
  sdlerror("Couldn't initialize SDL");
 screen = SDL_SetVideoMode(320, 240, 32, 0x00000001);
 if ( screen == ((void *)0) )
  sdlerror("Couldn't set SDL video mode");
 SDL_AudioSpec fmt;
 fmt.freq = 22100;
 fmt.format = 0x9010;
 fmt.channels = 2;
 fmt.samples = 2048;
 fmt.callback = mixaudio;
 fmt.userdata = ((void *)0);
 ring = newRingBuffer(44000);
 if ( SDL_OpenAudio(&fmt, ((void *)0)) < 0 )
  sdlerror("Unable to open audio");
}

canonical_original_code:
void dd_initSDL()
{
 if ( SDL_Init(0x00000020 | 0x00000010 | 0x00100000) < 0 )
  sdlerror("Couldn't initialize SDL");
 screen = SDL_SetVideoMode(320, 240, 32, 0x00000001);
 if ( screen == ((void *)0) )
  sdlerror("Couldn't set SDL video mode");
 struct SDL_AudioSpec fmt;
 fmt.freq = 22100;
 fmt.format = 0x9010;
 fmt.channels = 2;
 fmt.samples = 2048;
 fmt.callback = mixaudio;
 fmt.userdata = ((void *)0);
 ring = newRingBuffer(44000);
 if ( SDL_OpenAudio(&fmt, ((void *)0)) < 0 )
  sdlerror("Unable to open audio");
}

variable_types: struct SDL_AudioSpec { int freq; unsigned short format; unsigned char channels; unsigned char silence; unsigned short samples; unsigned short padding; unsigned int size; void (*callback)(void *userdata, unsigned char *stream, int len); void *userdata; }


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:
color
unsigned int

variable_types: scale int


linearGradientRaster

decompiled_code:
__int64 __fastcall linearGradientRaster(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v6; // r15
int v7; // ebx
int v8; // er14
__int64 result; // rax
_QWORD *v10; // rbp
_DWORD *v11; // r12
unsigned __int64 v12; // r15
_QWORD *v13; // r13
_DWORD *v14; // rbp
unsigned __int64 v15; // r12
__int64 v16; // rbx
unsigned int v17; // eax
__int64 v18; // rbx
unsigned int v19; // eax
unsigned int v20; // eax
__int64 v22; // [rsp+18h] [rbp-58h]
signed int v23; // [rsp+24h] [rbp-4Ch]
int v24; // [rsp+30h] [rbp-40h] BYREF
unsigned int v25[15]; // [rsp+34h] [rbp-3Ch] BYREF

v6 = *(_QWORD *)(a2 + 64);
v7 = *(_DWORD *)(a2 + 76);
v23 = *(_DWORD *)(a2 + 80);
v22 = *(_QWORD *)(a2 + 8);
v25[0] = v7 << 10;
v24 = a3 << 10;
ddMatrix_apply(v25, &v24);
v8 = *(_DWORD *)(a2 + 40);
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))
&& (result = (unsigned __int16)a5, ddEmptyCXform[4] == (_WORD)a5)
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
result = (unsigned int)v23;
if ( v7 < v23 )
{
v13 = (_QWORD *)(v6 + 8LL * v7);
v14 = (_DWORD *)(a1 + 4LL * v7);
v15 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v23 - 1 - v7)) + 8;
do
{
v16 = *v13 >> 12;
v17 = ddGradient_getColor(v22, (unsigned int)((signed int)(v25[0] + 65280) / 2));
result = ddColor_premultiply(v17);
if ( (_BYTE)v16 == 0xFF )
{
*v14 = result;
}
else
{
result = ddColor_scale(result, (unsigned __int8)v16);
*v14 += result;
}
v25[0] += v8;
++v13;
++v14;
}
while ( v13 != (_QWORD *)v15 );
}
}
else if ( v7 < v23 )
{
v10 = (_QWORD *)(v6 + 8LL * v7);
v11 = (_DWORD *)(a1 + 4LL * v7);
v12 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v23 - 1 - v7)) + 8;
do
{
v18 = *v10 >> 12;
v19 = ddGradient_getColor(v22, v25[0]);
v20 = ddCXform_apply(a4, a5, v19);
result = ddColor_premultiply(v20);
if ( (_BYTE)v18 == 0xFF )
{
*v11 = result;
}
else
{
result = ddColor_scale(result, (unsigned __int8)v18);
*v11 += result;
}
v25[0] += v8;
++v10;
++v11;
}
while ( v10 != (_QWORD *)v12 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v6; // r15
int v7; // ebx
int v8; // er14
__int64 result; // rax
_QWORD *v10; // rbp
_DWORD *v11; // r12
unsigned __int64 v12; // r15
_QWORD *v13; // r13
_DWORD *v14; // rbp
unsigned __int64 v15; // r12
__int64 v16; // rbx
unsigned int v17; // eax
__int64 v18; // rbx
unsigned int v19; // eax
unsigned int v20; // eax
__int64 v22; // [rsp+18h] [rbp-58h]
signed int v23; // [rsp+24h] [rbp-4Ch]
int v24; // [rsp+30h] [rbp-40h] BYREF
unsigned int v25[15]; // [rsp+34h] [rbp-3Ch] BYREF

v6 = *(_QWORD *)(a2 + 64);
v7 = *(_DWORD *)(a2 + 76);
v23 = *(_DWORD *)(a2 + 80);
v22 = *(_QWORD *)(a2 + 8);
v25[0] = v7 << 10;
v24 = a3 << 10;
ddMatrix_apply(v25, &v24);
v8 = *(_DWORD *)(a2 + 40);
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))
&& (result = (unsigned __int16)a5, ddEmptyCXform[4] == (_WORD)a5)
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
result = (unsigned int)v23;
if ( v7 < v23 )
{
v13 = (_QWORD *)(v6 + 8LL * v7);
v14 = (_DWORD *)(a1 + 4LL * v7);
v15 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v23 - 1 - v7)) + 8;
do
{
v16 = *v13 >> 12;
v17 = ddGradient_getColor(v22, (unsigned int)((signed int)(v25[0] + 65280) / 2));
result = func1(v17);
if ( (_BYTE)v16 == 0xFF )
{
*v14 = result;
}
else
{
result = func0(result, (unsigned __int8)v16);
*v14 += result;
}
v25[0] += v8;
++v13;
++v14;
}
while ( v13 != (_QWORD *)v15 );
}
}
else if ( v7 < v23 )
{
v10 = (_QWORD *)(v6 + 8LL * v7);
v11 = (_DWORD *)(a1 + 4LL * v7);
v12 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v23 - 1 - v7)) + 8;
do
{
v18 = *v10 >> 12;
v19 = ddGradient_getColor(v22, v25[0]);
v20 = ddCXform_apply(a4, a5, v19);
result = func1(v20);
if ( (_BYTE)v18 == 0xFF )
{
*v11 = result;
}
else
{
result = func0(result, (unsigned __int8)v18);
*v11 += result;
}
v25[0] += v8;
++v10;
++v11;
}
while ( v10 != (_QWORD *)v12 );
}
return result;
}

original_code:
void
linearGradientRaster(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;
 fixed dx;
 fixed px = ((left)<<10);
 fixed py = ((y)<<10);
 ddMatrix_apply(fill->inverse, &px, &py);
 dx = fill->inverse.a;
 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 = ddGradient_getColor(grad, (px + 65280) / 2);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dx;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   UInt8 c = alpha[x] >> ((2*10)-8);
   color = ddGradient_getColor(grad, px);
   color = ddCXform_apply(cXform, color);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dx;
  }
 }
}

canonical_original_code:
void linearGradientRaster(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;
 int dx;
 int px = ((left)<<10);
 int py = ((y)<<10);
 ddMatrix_apply(fill->inverse, &px, &py);
 dx = fill->inverse.a;
 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 = ddGradient_getColor(grad, (px + 65280) / 2);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dx;
  }
 }
 else
 {
  for ( x = left; x < right; ++x )
  {
   unsigned char c = alpha[x] >> ((2*10)-8);
   color = ddGradient_getColor(grad, px);
   color = ddCXform_apply(cXform, color);
   color = ddColor_premultiply(color);
   if ( c == 0xff )
    buffer[x] = color;
   else
    buffer[x] += ddColor_scale(color, c);
   px += dx;
  }
 }
}

variable_types:
buffer
unsigned int *

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: y int

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

variable_types:
alpha
unsigned long *

variable_types: left int

variable_types: right int

variable_types: dx int

variable_types: px int

variable_types: py int

variable_types:
c
unsigned char

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

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

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


radialGradientRaster

decompiled_code:
__int64 __fastcall radialGradientRaster(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // r15
int v6; // ebx
int v7; // eax
double v8; // xmm1_8
int v9; // eax
double v10; // xmm0_8
int v11; // er13
int v12; // er14
__int64 result; // rax
_QWORD *v14; // rbp
_DWORD *v15; // r12
unsigned __int64 v16; // r15
unsigned int *v17; // rbp
unsigned __int64 v18; // r12
__int64 v19; // rbx
__int64 v20; // rsi
unsigned int v21; // eax
unsigned int v22; // eax
__int64 v23; // rbx
unsigned int v24; // eax
unsigned int v25; // eax
unsigned int v26; // eax
_QWORD *v28; // [rsp+8h] [rbp-68h]
__int64 v30; // [rsp+18h] [rbp-58h]
signed int v31; // [rsp+24h] [rbp-4Ch]
int v32; // [rsp+30h] [rbp-40h] BYREF
int v33[15]; // [rsp+34h] [rbp-3Ch] BYREF

v5 = *(_QWORD *)(a2 + 64);
v6 = *(_DWORD *)(a2 + 76);
v31 = *(_DWORD *)(a2 + 80);
v30 = *(_QWORD *)(a2 + 8);
v33[0] = v6 << 10;
v32 = a3 << 10;
ddMatrix_apply(v33, &v32);
v7 = v32;
if ( v32 < 0 )
v7 = -v32;
v8 = (double)v7 * 0.0009765625;
v9 = v33[0];
if ( v33[0] < 0 )
v9 = -v33[0];
v10 = hypot((double)v9 * 0.0009765625, v8);
v11 = *(_DWORD *)(a2 + 40);
v12 = *(_DWORD *)(a2 + 48);
result = a4 >> 48;
if ( ddEmptyCXform[3] == HIWORD(a4)
&& (result = (unsigned __int16)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))
&& (result = (unsigned __int16)a5, ddEmptyCXform[4] == (_WORD)a5)
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
result = (unsigned int)v31;
if ( v6 < v31 )
{
v28 = (_QWORD *)(v5 + 8LL * v6);
v17 = (unsigned int *)(a1 + 4LL * v6);
v18 = v5 + 8 * (v6 + (unsigned __int64)(unsigned int)(v31 - 1 - v6)) + 8;
do
{
v19 = *v28 >> 12;
v20 = (unsigned int)fixed_sqrt((unsigned int)((v33[0] >> 5) * (v33[0] >> 5) + (v32 >> 5) * (v32 >> 5)), v10);
v21 = ddGradient_getColor(v30, v20);
v22 = ddColor_premultiply(v21);
if ( (_BYTE)v19 == 0xFF )
*v17 = v22;
else
*v17 += ddColor_scale(v22, (unsigned __int8)v19);
v33[0] += v11;
v32 += v12;
result = (__int64)++v28;
++v17;
}
while ( v28 != (_QWORD *)v18 );
}
}
else if ( v6 < v31 )
{
v14 = (_QWORD *)(v5 + 8LL * v6);
v15 = (_DWORD *)(a1 + 4LL * v6);
v16 = v5 + 8 * (v6 + (unsigned __int64)(unsigned int)(v31 - 1 - v6)) + 8;
do
{
v23 = *v14 >> 12;
v24 = fixed_sqrt((unsigned int)((v32 >> 5) * (v32 >> 5) + (v33[0] >> 5) * (v33[0] >> 5)), v10);
v25 = ddGradient_getColor(v30, v24);
v26 = ddCXform_apply(a4, a5, v25);
result = ddColor_premultiply(v26);
if ( (_BYTE)v23 == 0xFF )
{
*v15 = result;
}
else
{
result = ddColor_scale(result, (unsigned __int8)v23);
*v15 += result;
}
v33[0] += v11;
v32 += v12;
++v14;
++v15;
}
while ( v14 != (_QWORD *)v16 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // r15
int v6; // ebx
int v7; // eax
double v8; // xmm1_8
int v9; // eax
double v10; // xmm0_8
int v11; // er13
int v12; // er14
__int64 result; // rax
_QWORD *v14; // rbp
_DWORD *v15; // r12
unsigned __int64 v16; // r15
unsigned int *v17; // rbp
unsigned __int64 v18; // r12
__int64 v19; // rbx
__int64 v20; // rsi
unsigned int v21; // eax
unsigned int v22; // eax
__int64 v23; // rbx
unsigned int v24; // eax
unsigned int v25; // eax
unsigned int v26; // eax
_QWORD *v28; // [rsp+8h] [rbp-68h]
__int64 v30; // [rsp+18h] [rbp-58h]
signed int v31; // [rsp+24h] [rbp-4Ch]
int v32; // [rsp+30h] [rbp-40h] BYREF
int v33[15]; // [rsp+34h] [rbp-3Ch] BYREF

v5 = *(_QWORD *)(a2 + 64);
v6 = *(_DWORD *)(a2 + 76);
v31 = *(_DWORD *)(a2 + 80);
v30 = *(_QWORD *)(a2 + 8);
v33[0] = v6 << 10;
v32 = a3 << 10;
ddMatrix_apply(v33, &v32);
v7 = v32;
if ( v32 < 0 )
v7 = -v32;
v8 = (double)v7 * 0.0009765625;
v9 = v33[0];
if ( v33[0] < 0 )
v9 = -v33[0];
v10 = hypot((double)v9 * 0.0009765625, v8);
v11 = *(_DWORD *)(a2 + 40);
v12 = *(_DWORD *)(a2 + 48);
result = a4 >> 48;
if ( ddEmptyCXform[3] == HIWORD(a4)
&& (result = (unsigned __int16)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))
&& (result = (unsigned __int16)a5, ddEmptyCXform[4] == (_WORD)a5)
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
result = (unsigned int)v31;
if ( v6 < v31 )
{
v28 = (_QWORD *)(v5 + 8LL * v6);
v17 = (unsigned int *)(a1 + 4LL * v6);
v18 = v5 + 8 * (v6 + (unsigned __int64)(unsigned int)(v31 - 1 - v6)) + 8;
do
{
v19 = *v28 >> 12;
v20 = (unsigned int)fixed_sqrt((unsigned int)((v33[0] >> 5) * (v33[0] >> 5) + (v32 >> 5) * (v32 >> 5)), v10);
v21 = ddGradient_getColor(v30, v20);
v22 = func1(v21);
if ( (_BYTE)v19 == 0xFF )
*v17 = v22;
else
*v17 += func0(v22, (unsigned __int8)v19);
v33[0] += v11;
v32 += v12;
result = (__int64)++v28;
++v17;
}
while ( v28 != (_QWORD *)v18 );
}
}
else if ( v6 < v31 )
{
v14 = (_QWORD *)(v5 + 8LL * v6);
v15 = (_DWORD *)(a1 + 4LL * v6);
v16 = v5 + 8 * (v6 + (unsigned __int64)(unsigned int)(v31 - 1 - v6)) + 8;
do
{
v23 = *v14 >> 12;
v24 = fixed_sqrt((unsigned int)((v32 >> 5) * (v32 >> 5) + (v33[0] >> 5) * (v33[0] >> 5)), v10);
v25 = ddGradient_getColor(v30, v24);
v26 = ddCXform_apply(a4, a5, v25);
result = func1(v26);
if ( (_BYTE)v23 == 0xFF )
{
*v15 = result;
}
else
{
result = func0(result, (unsigned __int8)v23);
*v15 += result;
}
v33[0] += v11;
v32 += v12;
++v14;
++v15;
}
while ( v14 != (_QWORD *)v16 );
}
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: 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: 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; }

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


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


decompiled_code:
void __fastcall ddFill_interpolate(__m128i *a1, unsigned int *a2, _DWORD *a3, unsigned __int16 a4)
{
__int64 v5; // rsi
unsigned __int8 v7; // r12^1
int v8; // ebx
unsigned int v9; // er12
__m128i v10; // [rsp+0h] [rbp-48h] BYREF
__int64 v11; // [rsp+10h] [rbp-38h]

v5 = *a2;
if ( (_DWORD)v5 == *a3 )
{
v7 = HIBYTE(a4);
if ( (unsigned int)v5 > 3 )
{
if ( (unsigned int)(v5 - 4) > 1 )
{
dd_error("unknown fill type in ddFill_interpolate: %i", v5);
}
else
{
ddMatrix_interpolate(&v10, a4);
a1[1] = _mm_loadu_si128(&v10);
a1[2].m128i_i64[0] = v11;
}
}
else if ( (unsigned int)v5 > 1 )
{
v9 = a4;
ddGradient_interpolate(a1->m128i_i64[1], *((_QWORD *)a2 + 1), *((_QWORD *)a3 + 1), a4);
ddMatrix_interpolate(&v10, v9);
a1[1] = _mm_loadu_si128(&v10);
a1[2].m128i_i64[0] = v11;
}
else if ( (_DWORD)v5 )
{
v8 = ddColor_scale(a2[2], (0x10000 - a4) >> 8);
a1->m128i_i32[2] = ddColor_scale(a3[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
unsigned __int8 v7; // r12^1
int v8; // ebx
unsigned int v9; // er12
__m128i v10; // [rsp+0h] [rbp-48h] BYREF
__int64 v11; // [rsp+10h] [rbp-38h]

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


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


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)
{
__int64 v5; // r13
int v6; // er15
int v7; // er12
unsigned int v8; // eax
__int64 result; // rax
unsigned int v10; // er14
_QWORD *v11; // rbx
unsigned int *v12; // rbp
unsigned __int64 v13; // r13
unsigned __int8 v14; // si
unsigned int v15; // er12
unsigned int v16; // edx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // r13
int v6; // er15
int v7; // er12
unsigned int v8; // eax
__int64 result; // rax
unsigned int v10; // er14
_QWORD *v11; // rbx
unsigned int *v12; // rbp
unsigned __int64 v13; // r13
unsigned __int8 v14; // si
unsigned int v15; // er12
unsigned int v16; // edx

v5 = *(_QWORD *)(a2 + 64);
v6 = *(_DWORD *)(a2 + 76);
v7 = *(_DWORD *)(a2 + 80);
v8 = ddCXform_apply(a4, a5, *(unsigned int *)(a2 + 8));
result = func1(v8);
if ( v6 < v7 )
{
v10 = result;
v11 = (_QWORD *)(v5 + 8LL * v6);
v12 = (unsigned int *)(a1 + 4LL * v6);
v13 = v5 + 8 * (v6 + (unsigned __int64)(unsigned int)(v7 - 1 - v6)) + 8;
do
{
result = *v11 >> 12;
v14 = result;
if ( (_BYTE)result == 0xFF )
{
*v12 = v10;
}
else if ( (_BYTE)result )
{
v15 = *v12;
v16 = HIBYTE(*v12);
result = v16 + (unsigned __int8)result;
if ( (unsigned int)result <= 0xFF || (v14 = ~(_BYTE)v16, (_BYTE)v16 != 0xFF) )
{
result = func0(v10, v14);
*v12 = result + v15;
}
}
++v11;
++v12;
}
while ( v11 != (_QWORD *)v13 );
}
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 = a3;
if ( a2 != a3 )
result = ((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) | (unsigned __int16)((BYTE1(a2) + (unsigned __int16)((a1 * (BYTE1(a3) - (unsigned int)BYTE1(a2))) >> 10)) << 8);
return result;
}

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

result = a3;
if ( a2 != a3 )
result = ((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) | (unsigned __int16)((BYTE1(a2) + (unsigned __int16)((a1 * (BYTE1(a3) - (unsigned int)BYTE1(a2))) >> 10)) << 8);
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

decompiled_code:
__int64 __fastcall tiledBitmapRaster(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // rbp
__int64 v6; // r15
int v7; // ebx
int v8; // er13
int v9; // er14
__int64 result; // rax
_QWORD *v11; // rbp
_DWORD *v12; // r12
unsigned __int64 v13; // r15
unsigned int *v14; // rbp
__int64 v15; // rbx
int v16; // er15
int v17; // er12
unsigned int v18; // eax
__int64 v19; // rbx
unsigned int v20; // eax
_QWORD *v22; // [rsp+8h] [rbp-88h]
unsigned __int64 v24; // [rsp+10h] [rbp-80h]
__int64 v25; // [rsp+18h] [rbp-78h]
signed int v26; // [rsp+20h] [rbp-70h]
int v27; // [rsp+30h] [rbp-60h] BYREF
int v28; // [rsp+34h] [rbp-5Ch] BYREF
__m128i v29; // [rsp+38h] [rbp-58h]
__int64 v30; // [rsp+48h] [rbp-48h]

v5 = a4;
v6 = *(_QWORD *)(a2 + 64);
v7 = *(_DWORD *)(a2 + 76);
v26 = *(_DWORD *)(a2 + 80);
v25 = *(_QWORD *)(a2 + 8);
v29 = _mm_loadu_si128((const __m128i *)(a2 + 40));
v30 = *(_QWORD *)(a2 + 56);
v8 = *(_DWORD *)(a2 + 40);
v9 = *(_DWORD *)(a2 + 48);
v28 = v7 << 10;
v27 = a3 << 10;
ddMatrix_apply(&v28, &v27);
result = v5 >> 48;
if ( ddEmptyCXform[3] == HIWORD(v5)
&& (result = (unsigned __int16)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))
&& (result = (unsigned __int16)a5, ddEmptyCXform[4] == (_WORD)a5)
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
result = (unsigned int)v26;
if ( v7 < v26 )
{
v22 = (_QWORD *)(v6 + 8LL * v7);
v14 = (unsigned int *)(a1 + 4LL * v7);
v24 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v26 - 1 - v7)) + 8;
do
{
v15 = *v22 >> 12;
v16 = v27;
v17 = v28;
v18 = ddImage_getTiledPixel_blended(v25, v28, v27);
if ( (_BYTE)v15 == 0xFF )
*v14 = v18;
else
*v14 += ddColor_scale(v18, (unsigned __int8)v15);
v28 = v8 + v17;
v27 = v9 + v16;
result = (__int64)++v22;
++v14;
}
while ( v22 != (_QWORD *)v24 );
}
}
else if ( v7 < v26 )
{
v11 = (_QWORD *)(v6 + 8LL * v7);
v12 = (_DWORD *)(a1 + 4LL * v7);
v13 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v26 - 1 - v7)) + 8;
do
{
v19 = *v11 >> 12;
v20 = ddImage_getTiledPixel_blended(v25, v28, v27);
result = ddCXform_applyPremultiplied(a4, a5, v20);
if ( (_BYTE)v19 == 0xFF )
{
*v12 = result;
}
else
{
result = ddColor_scale(result, (unsigned __int8)v19);
*v12 += result;
}
v28 += v8;
v27 += v9;
++v11;
++v12;
}
while ( v11 != (_QWORD *)v13 );
}
return result;
}

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

decompiled_code:
__int64 __fastcall clippedBitmapRaster(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // rbp
__int64 v6; // r15
int v7; // ebx
int v8; // er13
int v9; // er14
__int64 result; // rax
_QWORD *v11; // rbp
_DWORD *v12; // r12
unsigned __int64 v13; // r15
unsigned int *v14; // rbp
__int64 v15; // rbx
int v16; // er15
int v17; // er12
unsigned int v18; // eax
__int64 v19; // rbx
unsigned int v20; // eax
_QWORD *v22; // [rsp+8h] [rbp-88h]
unsigned __int64 v24; // [rsp+10h] [rbp-80h]
__int64 v25; // [rsp+18h] [rbp-78h]
signed int v26; // [rsp+20h] [rbp-70h]
int v27; // [rsp+30h] [rbp-60h] BYREF
int v28; // [rsp+34h] [rbp-5Ch] BYREF
__m128i v29; // [rsp+38h] [rbp-58h]
__int64 v30; // [rsp+48h] [rbp-48h]

v5 = a4;
v6 = *(_QWORD *)(a2 + 64);
v7 = *(_DWORD *)(a2 + 76);
v26 = *(_DWORD *)(a2 + 80);
v25 = *(_QWORD *)(a2 + 8);
v29 = _mm_loadu_si128((const __m128i *)(a2 + 40));
v30 = *(_QWORD *)(a2 + 56);
v8 = *(_DWORD *)(a2 + 40);
v9 = *(_DWORD *)(a2 + 48);
v28 = v7 << 10;
v27 = a3 << 10;
ddMatrix_apply(&v28, &v27);
result = v5 >> 48;
if ( ddEmptyCXform[3] == HIWORD(v5)
&& (result = (unsigned __int16)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))
&& (result = (unsigned __int16)a5, ddEmptyCXform[4] == (_WORD)a5)
&& (result = (unsigned int)((int)a5 >> 16), ddEmptyCXform[5] == WORD1(a5))
&& (result = a5 << 16 >> 48, ddEmptyCXform[6] == (_WORD)result) )
{
result = (unsigned int)v26;
if ( v7 < v26 )
{
v22 = (_QWORD *)(v6 + 8LL * v7);
v14 = (unsigned int *)(a1 + 4LL * v7);
v24 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v26 - 1 - v7)) + 8;
do
{
v15 = *v22 >> 12;
v16 = v27;
v17 = v28;
v18 = ddImage_getClippedPixel_blended(v25, v28, v27);
if ( (_BYTE)v15 == 0xFF )
*v14 = v18;
else
*v14 += ddColor_scale(v18, (unsigned __int8)v15);
v28 = v8 + v17;
v27 = v9 + v16;
result = (__int64)++v22;
++v14;
}
while ( v22 != (_QWORD *)v24 );
}
}
else if ( v7 < v26 )
{
v11 = (_QWORD *)(v6 + 8LL * v7);
v12 = (_DWORD *)(a1 + 4LL * v7);
v13 = v6 + 8 * (v7 + (unsigned __int64)(unsigned int)(v26 - 1 - v7)) + 8;
do
{
v19 = *v11 >> 12;
v20 = ddImage_getClippedPixel_blended(v25, v28, v27);
result = ddCXform_applyPremultiplied(a4, a5, v20);
if ( (_BYTE)v19 == 0xFF )
{
*v12 = result;
}
else
{
result = ddColor_scale(result, (unsigned __int8)v19);
*v12 += result;
}
v28 += v8;
v27 += v9;
++v11;
++v12;
}
while ( v11 != (_QWORD *)v13 );
}
return result;
}

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)
{
__int64 result; // rax
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rcx
unsigned __int64 v4; // rax
char v5; // al

if ( a1 <= 0xFFFF )
{
if ( a1 <= 0xFF )
return 32 * (unsigned int)((unsigned __int8)sqq_table_0[a1] >> 4);
if ( a1 <= 0xFFF )
{
if ( a1 <= 0x3FF )
v5 = (unsigned __int8)sqq_table_0[a1 >> 2] >> 3;
else
v5 = (unsigned __int8)sqq_table_0[a1 >> 4] >> 2;
v4 = (unsigned __int8)(v5 + 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;
}
}
else
{
if ( a1 <= 0xFFFFFF )
{
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)];
}
}
else
{
if ( a1 <= 0xFFFFFFF )
{
if ( a1 <= 0x3FFFFFF )
v2 = 32 * (unsigned __int8)sqq_table_0[a1 >> 18];
else
v2 = (unsigned __int8)sqq_table_0[a1 >> 20] << 6;
}
else if ( a1 <= 0x3FFFFFFF )
{
v2 = (unsigned __int8)sqq_table_0[a1 >> 22] << 7;
}
else
{
result = 2097120LL;
if ( a1 > 0xFFFE0000 )
return result;
v2 = (unsigned __int8)sqq_table_0[HIBYTE(a1)] << 8;
}
v3 = (v2 + a1 / v2 + 1) >> 1;
}
v4 = (v3 + a1 / v3 + 1) >> 1;
}
return 32 * ((unsigned int)v4 - (a1 < v4 * v4));
}

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

if ( a1 <= 0xFFFF )
{
if ( a1 <= 0xFF )
return 32 * (unsigned int)((unsigned __int8)sqq_table_0[a1] >> 4);
if ( a1 <= 0xFFF )
{
if ( a1 <= 0x3FF )
v5 = (unsigned __int8)sqq_table_0[a1 >> 2] >> 3;
else
v5 = (unsigned __int8)sqq_table_0[a1 >> 4] >> 2;
v4 = (unsigned __int8)(v5 + 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;
}
}
else
{
if ( a1 <= 0xFFFFFF )
{
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)];
}
}
else
{
if ( a1 <= 0xFFFFFFF )
{
if ( a1 <= 0x3FFFFFF )
v2 = 32 * (unsigned __int8)sqq_table_0[a1 >> 18];
else
v2 = (unsigned __int8)sqq_table_0[a1 >> 20] << 6;
}
else if ( a1 <= 0x3FFFFFFF )
{
v2 = (unsigned __int8)sqq_table_0[a1 >> 22] << 7;
}
else
{
result = 2097120LL;
if ( a1 > 0xFFFE0000 )
return result;
v2 = (unsigned __int8)sqq_table_0[HIBYTE(a1)] << 8;
}
v3 = (v2 + a1 / v2 + 1) >> 1;
}
v4 = (v3 + a1 / v3 + 1) >> 1;
}
return 32 * ((unsigned int)v4 - (a1 < v4 * v4));
}

variable_types:
x
unsigned int

variable_types:
xn
unsigned long


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

if ( !a1 )
return 0LL;
v1 = *a1;
switch ( (int)v1 )
{
case 0:
result = 0LL;
break;
case 1:
result = &solidRaster;
break;
case 2:
result = &radialGradientRaster;
break;
case 3:
result = &linearGradientRaster;
break;
case 4:
result = &clippedBitmapRaster;
break;
case 5:
result = &tiledBitmapRaster;
break;
default:
dd_warn("Unknown fill type: %i", v1);
result = 0LL;
break;
}
return result;
}

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

if ( !a1 )
return 0LL;
v1 = *a1;
switch ( (int)v1 )
{
case 0:
result = 0LL;
break;
case 1:
result = &solidRaster;
break;
case 2:
result = &radialGradientRaster;
break;
case 3:
result = &linearGradientRaster;
break;
case 4:
result = &clippedBitmapRaster;
break;
case 5:
result = &tiledBitmapRaster;
break;
default:
dd_warn("Unknown fill type: %i", v1);
result = 0LL;
break;
}
return result;
}

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(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const __int32_t *v3; // rcx
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
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 ( *v2 );
return result;
}

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

v1 = *a1;
if ( !*a1 )
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 ( *v2 );
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 ( a1 )
{
if ( a2 )
{
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 ( a1 )
{
if ( a2 )
{
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