main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
int v4; // er13
int v6; // ebx
const char *v7; // r15
unsigned __int64 v8; // rdi
int v9; // eax
int result; // eax
int v11; // ebp
int v12; // er8
char *v13; // rax
char v14[15]; // [rsp+1h] [rbp-57h] BYREF
__int64 v15[9]; // [rsp+10h] [rbp-48h] BYREF

v3 = 0LL;
v4 = 0;
v6 = 0;
v7 = *argv;
strcpy(v14, "-?");
while ( 2 )
{
v8 = (unsigned int)argc;
v9 = getopt(argc, (char *const *)argv, "1:gkps:D:I:KPTU:");
if ( v9 != -1 )
{
switch ( v9 )
{
case '1':
v3 = optarg;
continue;
case 'D':
case 'I':
case 'U':
v14[1] = v9;
add_cpp_arg(v14);
add_cpp_arg(optarg);
continue;
case 'K':
LODWORD(postscript_params[5]) = 1;
continue;
case 'P':
if ( v6 )
goto LABEL_11;
v6 = 3;
continue;
case 'T':
++v4;
v6 = 5;
continue;
case 'g':
if ( v6 )
goto LABEL_11;
v6 = 4;
continue;
case 'k':
if ( v6 )
goto LABEL_11;
v6 = 1;
continue;
case 'p':
if ( v6 )
goto LABEL_11;
v6 = 2;
continue;
case 's':
if ( v6 != 3 || !parse_scaling(optarg) )
LABEL_11:
usage(*argv);
continue;
default:
goto LABEL_6;
}
}
break;
}
if ( (unsigned int)(v6 - 2) > 2 && v3 )
LABEL_6:
usage(v7);
if ( LODWORD(postscript_params[5]) )
{
if ( v6 != 3 )
goto LABEL_6;
}
else if ( !v6 )
{
v15[0] = (__int64)v7;
v8 = (unsigned __int64)&v14[3];
*(_DWORD *)&v14[3] = 1;
v15[1] = 0LL;
*(_QWORD *)&v14[7] = v15;
result = gui_init(&v14[3], &v14[7]);
if ( result )
return result;
}
v11 = argc - optind;
if ( v11 == 1 )
{
load_file((char *)argv[optind]);
save_file_name = (char *)argv[optind];
}
else if ( v11 == 2 )
{
load_file((char *)argv[optind]);
save_file_name = (char *)argv[optind + 1];
if ( !strcmp(save_file_name, "-") )
save_file_name = 0LL;
}
else
{
if ( v11 )
goto LABEL_6;
scan_empty();
yyparse(v8);
}
if ( !pkg_name )
{
v13 = strdup("_");
if ( !v13 )
main_cold();
pkg_name = v13;
}
reporter = &report_to_stderr;
v12 = instantiate();
result = 1;
if ( v12 )
{
switch ( v6 )
{
case 1:
write_kicad();
goto LABEL_35;
case 2:
write_ps(v3);
goto LABEL_35;
case 3:
write_ps_fullpage(v3);
goto LABEL_35;
case 4:
write_gnuplot(v3);
goto LABEL_35;
case 5:
if ( v4 > 1 )
dump(stdout, 0LL);
goto LABEL_35;
default:
result = gui_main();
if ( result )
return result;
LABEL_35:
purge();
inst_revert();
obj_cleanup();
unique_cleanup();
result = 0;
break;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
int v4; // er13
int v6; // ebx
const char *v7; // r15
unsigned __int64 v8; // rdi
int v9; // eax
int result; // eax
int v11; // ebp
int v12; // er8
char *v13; // rax
char v14[15]; // [rsp+1h] [rbp-57h] BYREF
__int64 v15[9]; // [rsp+10h] [rbp-48h] BYREF

v3 = 0LL;
v4 = 0;
v6 = 0;
v7 = *argv;
strcpy(v14, "-?");
while ( 2 )
{
v8 = (unsigned int)argc;
v9 = getopt(argc, (char *const *)argv, "1:gkps:D:I:KPTU:");
if ( v9 != -1 )
{
switch ( v9 )
{
case '1':
v3 = optarg;
continue;
case 'D':
case 'I':
case 'U':
v14[1] = v9;
add_cpp_arg(v14);
add_cpp_arg(optarg);
continue;
case 'K':
LODWORD(postscript_params[5]) = 1;
continue;
case 'P':
if ( v6 )
goto LABEL_11;
v6 = 3;
continue;
case 'T':
++v4;
v6 = 5;
continue;
case 'g':
if ( v6 )
goto LABEL_11;
v6 = 4;
continue;
case 'k':
if ( v6 )
goto LABEL_11;
v6 = 1;
continue;
case 'p':
if ( v6 )
goto LABEL_11;
v6 = 2;
continue;
case 's':
if ( v6 != 3 || !func2(optarg) )
LABEL_11:
func3(*argv);
continue;
default:
goto LABEL_6;
}
}
break;
}
if ( (unsigned int)(v6 - 2) > 2 && v3 )
LABEL_6:
func3(v7);
if ( LODWORD(postscript_params[5]) )
{
if ( v6 != 3 )
goto LABEL_6;
}
else if ( !v6 )
{
v15[0] = (__int64)v7;
v8 = (unsigned __int64)&v14[3];
*(_DWORD *)&v14[3] = 1;
v15[1] = 0LL;
*(_QWORD *)&v14[7] = v15;
result = gui_init(&v14[3], &v14[7]);
if ( result )
return result;
}
v11 = argc - optind;
if ( v11 == 1 )
{
func1((char *)argv[optind]);
save_file_name = (char *)argv[optind];
}
else if ( v11 == 2 )
{
func1((char *)argv[optind]);
save_file_name = (char *)argv[optind + 1];
if ( !strcmp(save_file_name, "-") )
save_file_name = 0LL;
}
else
{
if ( v11 )
goto LABEL_6;
scan_empty();
yyparse(v8);
}
if ( !pkg_name )
{
v13 = strdup("_");
if ( !v13 )
func5();
pkg_name = v13;
}
reporter = &report_to_stderr;
v12 = instantiate();
result = 1;
if ( v12 )
{
switch ( v6 )
{
case 1:
write_kicad();
goto LABEL_35;
case 2:
write_ps(v3);
goto LABEL_35;
case 3:
write_ps_fullpage(v3);
goto LABEL_35;
case 4:
write_gnuplot(v3);
goto LABEL_35;
case 5:
if ( v4 > 1 )
dump(stdout, 0LL);
goto LABEL_35;
default:
result = gui_main();
if ( result )
return result;
LABEL_35:
purge();
inst_revert();
obj_cleanup();
unique_cleanup();
result = 0;
break;
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 enum {
  batch_none = 0,
  batch_kicad,
  batch_ps,
  batch_ps_fullpage,
  batch_gnuplot,
  batch_test
 } batch = batch_none;
 char *name = *argv;
 char **fake_argv;
 char *args[2];
 int fake_argc;
 char opt[] = "-?";
 int error;
 int test_mode = 0;
 const char *one = ((void *)0);
 int c;
 while ((c = getopt(argc, argv, "1:gkps:D:I:KPTU:")) != (-1))
  switch (c) {
  case '1':
   one = optarg;
   break;
  case 'g':
   if (batch)
    usage(*argv);
   batch = batch_gnuplot;
   break;
  case 'k':
   if (batch)
    usage(*argv);
   batch = batch_kicad;
   break;
  case 'p':
   if (batch)
    usage(*argv);
   batch = batch_ps;
   break;
  case 'P':
   if (batch)
    usage(*argv);
   batch = batch_ps_fullpage;
   break;
  case 'K':
   postscript_params.show_key = 1;
   break;
  case 's':
   if (batch != batch_ps_fullpage)
    usage(*argv);
   if (!parse_scaling(optarg))
    usage(*argv);
   break;
  case 'T':
   batch = batch_test;
   test_mode++;
   break;
  case 'D':
  case 'U':
  case 'I':
   opt[1] = c;
   add_cpp_arg(opt);
   add_cpp_arg(optarg);
   break;
  default:
   usage(name);
  }
 if (one && batch != batch_ps && batch != batch_ps_fullpage &&
     batch != batch_gnuplot)
  usage(name);
 if (postscript_params.show_key && batch != batch_ps_fullpage)
  usage(name);
 if (!batch) {
  args[0] = name;
  args[1] = ((void *)0);
  fake_argc = 1;
  fake_argv = args;
  error = gui_init(&fake_argc, &fake_argv);
  if (error)
   return error;
 }
 switch (argc-optind) {
 case 0:
  scan_empty();
  (void) yyparse();
  break;
 case 1:
  load_file(argv[optind]);
  save_file_name = argv[optind];
  break;
 case 2:
  load_file(argv[optind]);
  save_file_name = argv[optind+1];
  if (!strcmp(save_file_name, "-"))
   save_file_name = ((void *)0);
  break;
 default:
  usage(name);
 }
 if (!pkg_name)
  pkg_name = ({ char *stralloc_tmp = strdup("_"); if (!stralloc_tmp) abort(); stralloc_tmp; });
 reporter = report_to_stderr;
 if (!instantiate())
  return 1;
 switch (batch) {
 case batch_none:
  error = gui_main();
  if (error)
   return error;
  break;
 case batch_kicad:
  write_kicad();
  break;
 case batch_ps:
  write_ps(one);
  break;
 case batch_ps_fullpage:
  write_ps_fullpage(one);
  break;
 case batch_gnuplot:
  write_gnuplot(one);
  break;
 case batch_test:
  if (test_mode > 1)
   dump(stdout, ((void *)0));
  break;
 default:
  abort();
 }
 purge();
 inst_revert();
 obj_cleanup();
 unique_cleanup();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 enum { batch_none=0, batch_kicad=1, batch_ps=2, batch_ps_fullpage=3, batch_gnuplot=4, batch_test=5 } batch = batch_none;
 char *name = *argv;
 char **fake_argv;
 char *args[2];
 int fake_argc;
 char opt[] = "-?";
 int error;
 int test_mode = 0;
 char *one = ((void *)0);
 int c;
 while ((c = getopt(argc, argv, "1:gkps:D:I:KPTU:")) != (-1))
  switch (c) {
  case '1':
   one = optarg;
   break;
  case 'g':
   if (batch)
    usage(*argv);
   batch = batch_gnuplot;
   break;
  case 'k':
   if (batch)
    usage(*argv);
   batch = batch_kicad;
   break;
  case 'p':
   if (batch)
    usage(*argv);
   batch = batch_ps;
   break;
  case 'P':
   if (batch)
    usage(*argv);
   batch = batch_ps_fullpage;
   break;
  case 'K':
   postscript_params.show_key = 1;
   break;
  case 's':
   if (batch != batch_ps_fullpage)
    usage(*argv);
   if (!parse_scaling(optarg))
    usage(*argv);
   break;
  case 'T':
   batch = batch_test;
   test_mode++;
   break;
  case 'D':
  case 'U':
  case 'I':
   opt[1] = c;
   add_cpp_arg(opt);
   add_cpp_arg(optarg);
   break;
  default:
   usage(name);
  }
 if (one && batch != batch_ps && batch != batch_ps_fullpage &&
     batch != batch_gnuplot)
  usage(name);
 if (postscript_params.show_key && batch != batch_ps_fullpage)
  usage(name);
 if (!batch) {
  args[0] = name;
  args[1] = ((void *)0);
  fake_argc = 1;
  fake_argv = args;
  error = gui_init(&fake_argc, &fake_argv);
  if (error)
   return error;
 }
 switch (argc-optind) {
 case 0:
  scan_empty();
  (void) yyparse();
  break;
 case 1:
  load_file(argv[optind]);
  save_file_name = argv[optind];
  break;
 case 2:
  load_file(argv[optind]);
  save_file_name = argv[optind+1];
  if (!strcmp(save_file_name, "-"))
   save_file_name = ((void *)0);
  break;
 default:
  usage(name);
 }
 if (!pkg_name)
  pkg_name = ({ char *stralloc_tmp = strdup("_"); if (!stralloc_tmp) abort(); stralloc_tmp; });
 reporter = report_to_stderr;
 if (!instantiate())
  return 1;
 switch (batch) {
 case batch_none:
  error = gui_main();
  if (error)
   return error;
  break;
 case batch_kicad:
  write_kicad();
  break;
 case batch_ps:
  write_ps(one);
  break;
 case batch_ps_fullpage:
  write_ps_fullpage(one);
  break;
 case batch_gnuplot:
  write_gnuplot(one);
  break;
 case batch_test:
  if (test_mode > 1)
   dump(stdout, ((void *)0));
  break;
 default:
  abort();
 }
 purge();
 inst_revert();
 obj_cleanup();
 unique_cleanup();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
args
char *[2]

variable_types:
opt
char []

variable_types: error int

variable_types:
one
char *

variable_types: c int


repo: bert/fped

decompiled_code:
char *__fastcall add_edge(__int64 a1, __int64 a2, int a3)
{
char *result; // rax
_QWORD *v5; // rbx

result = *(char **)(a1 + 8);
if ( result )
{
while ( 1 )
{
if ( *(_QWORD *)result == a2 )
{
*((_DWORD *)result + 2) += a3;
return result;
}
if ( !*((_QWORD *)result + 2) )
break;
result = (char *)*((_QWORD *)result + 2);
}
v5 = result + 16;
}
else
{
v5 = (_QWORD *)(a1 + 8);
}
result = (char *)malloc(0x18uLL);
if ( !result )
add_edge_cold();
*v5 = result;
*(_QWORD *)result = a2;
*((_DWORD *)result + 2) = a3;
*((_QWORD *)result + 2) = 0LL;
++*(_DWORD *)(a2 + 16);
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, __int64 a2, int a3)
{
char *result; // rax
_QWORD *v5; // rbx

result = *(char **)(a1 + 8);
if ( result )
{
while ( 1 )
{
if ( *(_QWORD *)result == a2 )
{
*((_DWORD *)result + 2) += a3;
return result;
}
if ( !*((_QWORD *)result + 2) )
break;
result = (char *)*((_QWORD *)result + 2);
}
v5 = result + 16;
}
else
{
v5 = (_QWORD *)(a1 + 8);
}
result = (char *)malloc(0x18uLL);
if ( !result )
func2();
*v5 = result;
*(_QWORD *)result = a2;
*((_DWORD *)result + 2) = a3;
*((_QWORD *)result + 2) = 0LL;
++*(_DWORD *)(a2 + 16);
return result;
}

original_code:
void add_edge(struct node *from, struct node *to, int priority)
{
 struct edge **edge;
 for (edge = &from->edges; *edge; edge = &(*edge)->next)
  if ((*edge)->to == to) {
   (*edge)->priority += priority;
   return;
  }
 *edge = ((struct edge *) ({ void *alloc_size_tmp = malloc(sizeof(struct edge)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 (*edge)->to = to;
 (*edge)->priority = priority;
 (*edge)->next = ((void *)0);
 to->incoming++;
}

variable_types: struct node { void *user; struct edge { struct node *to; int priority; struct edge *next; } *edges; int incoming; int priority; int decay; struct node *next; } *

variable_types:
to
struct node *

variable_types: priority int

variable_types: struct edge { struct node { void *user; struct edge *edges; int incoming; int priority; int decay; struct node *next; } *to; int priority; struct edge *next; } **

return_type: void


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

result = malloc(0x18uLL);
if ( !result )
begin_tsort_cold();
*result = 0LL;
result[1] = result;
*((_DWORD *)result + 4) = 0;
return result;
}

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

result = malloc(0x18uLL);
if ( !result )
func4();
*result = 0LL;
result[1] = result;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
struct tsort *begin_tsort(void)
{
 struct tsort *tsort;
 tsort = ((struct tsort *) ({ void *alloc_size_tmp = malloc(sizeof(struct tsort)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 tsort->nodes = ((void *)0);
 tsort->next_node = &tsort->nodes;
 tsort->n_nodes = 0;
 return tsort;
}

canonical_original_code:
struct tsort *begin_tsort()
{
 struct tsort *tsort;
 tsort = ((struct tsort *) ({ void *alloc_size_tmp = malloc(sizeof(struct tsort)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 tsort->nodes = ((void *)0);
 tsort->next_node = &tsort->nodes;
 tsort->n_nodes = 0;
 return tsort;
}

variable_types: struct tsort { struct node { void *user; struct edge { struct node *to; int priority; struct edge *next; } *edges; int incoming; int priority; int decay; struct node *next; } *nodes; struct node **next_node; int n_nodes; } *

user_defined_types: struct tsort { struct node *nodes; struct node **next_node; int n_nodes; }

user_defined_types: struct node { void *user; struct edge *edges; int incoming; int priority; int decay; struct node *next; }


decompiled_code:
double __fastcall units_to_mm(int a1)
{
return (double)a1 / 10000.0;
}

canonical_decompiled_code:
double __fastcall func0(int a1)
{
return (double)a1 / 10000.0;
}

original_code:
static inline double units_to_mm(unit_type u)
{
 return (double) u/(1000.0*10);
}

canonical_original_code:
static inline double units_to_mm(int u)
{
 return (double) u/(1000.0*10);
}

variable_types: u int

return_type: double


hexdump

repo: bertrik/ibutton-test

decompiled_code:
int __fastcall hexdump(__int64 a1, int a2, int a3)
{
int v3; // ebp
int v5; // er12
int v6; // er13
unsigned __int8 *v7; // r15
__int64 v8; // rsi
int result; // eax
bool v10; // [rsp+1Fh] [rbp-39h]

if ( a2 > 0 )
{
v3 = a2;
v10 = a3 > 0;
v5 = 0;
do
{
if ( v3 > a3 && v10 )
{
v3 -= a3;
v6 = a3;
}
else
{
v6 = v3;
v3 = 0;
}
v7 = (unsigned __int8 *)(a1 + v5);
do
{
v8 = *v7++;
printf("%02X", v8);
}
while ( v7 != (unsigned __int8 *)((unsigned int)(v6 - 1) + a1 + 1 + v5) );
v5 += v6;
result = putchar(10);
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2, int a3)
{
int v3; // ebp
int v5; // er12
int v6; // er13
unsigned __int8 *v7; // r15
__int64 v8; // rsi
int result; // eax
bool v10; // [rsp+1Fh] [rbp-39h]

if ( a2 > 0 )
{
v3 = a2;
v10 = a3 > 0;
v5 = 0;
do
{
if ( v3 > a3 && v10 )
{
v3 -= a3;
v6 = a3;
}
else
{
v6 = v3;
v3 = 0;
}
v7 = (unsigned __int8 *)(a1 + v5);
do
{
v8 = *v7++;
printf("%02X", v8);
}
while ( v7 != (unsigned __int8 *)((unsigned int)(v6 - 1) + a1 + 1 + v5) );
v5 += v6;
result = putchar(10);
}
while ( v3 );
}
return result;
}

original_code:
void hexdump(uint8_t *data, int size, int modulo)
{
    int i, len;
    int addr = 0;
    while (size > 0) {
        if ((modulo > 0) && (size > modulo)) {
            len = modulo;
        } else {
            len = size;
        }
        size -= len;
        for (i = 0; i < len; i++) {
            printf("%02X", data[addr++]);
        }
        printf("\n");
    }
}

canonical_original_code:
void hexdump(unsigned char *data, int size, int modulo)
{
    int i; int len;
    int addr = 0;
    while (size > 0) {
        if ((modulo > 0) && (size > modulo)) {
            len = modulo;
        } else {
            len = size;
        }
        size -= len;
        for (i = 0; i < len; i++) {
            printf("%02X", data[addr++]);
        }
        printf("\n");
    }
}

variable_types:
data
unsigned char *

variable_types: size int

variable_types: modulo int

variable_types: i int

variable_types: len int

variable_types: addr int


doit

decompiled_code:
int doit()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
unsigned __int8 v4[3]; // [rsp+Eh] [rbp-5Ah] BYREF
unsigned __int8 v5[7]; // [rsp+11h] [rbp-57h] BYREF
__int64 v6; // [rsp+18h] [rbp-50h] BYREF
char v7[32]; // [rsp+20h] [rbp-48h] BYREF
__int128 v8[2]; // [rsp+40h] [rbp-28h] BYREF

v8[0] = 0LL;
v8[1] = 0LL;
v6 = 0LL;
v0 = getenv("IBID");
parseHexString(v0, v5, 8LL);
v1 = getenv("IBCHAL");
parseHexString(v1, v4, 3LL);
v2 = getenv("IBSEC");
parseHexString(v2, &v6, 8LL);
calcmac_readauthpage_constprop_0((__int64)v7, (__int64)v8, (unsigned int *)&v6, v4, v5);
return hexdump((__int64)v7, 20, 0);
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
unsigned __int8 v4[3]; // [rsp+Eh] [rbp-5Ah] BYREF
unsigned __int8 v5[7]; // [rsp+11h] [rbp-57h] BYREF
__int64 v6; // [rsp+18h] [rbp-50h] BYREF
char v7[32]; // [rsp+20h] [rbp-48h] BYREF
__int128 v8[2]; // [rsp+40h] [rbp-28h] BYREF

v8[0] = 0LL;
v8[1] = 0LL;
v6 = 0LL;
v0 = getenv("IBID");
parseHexString(v0, v5, 8LL);
v1 = getenv("IBCHAL");
parseHexString(v1, v4, 3LL);
v2 = getenv("IBSEC");
parseHexString(v2, &v6, 8LL);
func0((__int64)v7, (__int64)v8, (unsigned int *)&v6, v4, v5);
return func1((__int64)v7, 20, 0);
}

original_code:
static void doit(void)
{
    uint8_t secret[8];
    uint8_t mac[20];
    uint8_t identity[7];
    uint8_t challenge[3];
    uint8_t data[32];
    memset(data, 0, sizeof(data));
    memset(secret, 0, sizeof(secret));
    parseHexString( getenv( "IBID" ), identity , 8 );
    parseHexString( getenv( "IBCHAL" ), challenge , 3 );
    parseHexString( getenv( "IBSEC" ), secret , 8 );
    calcmac_readauthpage(mac, 0, data, secret, challenge, identity);
    hexdump(mac, sizeof(mac), 0);
}

canonical_original_code:
static void doit()
{
    unsigned char secret[8];
    unsigned char mac[20];
    unsigned char identity[7];
    unsigned char challenge[3];
    unsigned char data[32];
    memset(data, 0, sizeof(data));
    memset(secret, 0, sizeof(secret));
    parseHexString( getenv( "IBID" ), identity , 8 );
    parseHexString( getenv( "IBCHAL" ), challenge , 3 );
    parseHexString( getenv( "IBSEC" ), secret , 8 );
    calcmac_readauthpage(mac, 0, data, secret, challenge, identity);
    hexdump(mac, sizeof(mac), 0);
}

variable_types:
secret
unsigned char [8]

variable_types:
mac
unsigned char [20]

variable_types:
identity
unsigned char [7]

variable_types:
challenge
unsigned char [3]

variable_types:
data
unsigned char [32]


main

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func2();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    (void) argc;
    (void) argv;
    doit();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

return_type: int


repo: beru/flirt

original_code:
static ddShapeRecord*
ddShape_addRecord(ddShape* s)
{
 s->records = realloc((s->records),((s->nRecords + 1) * sizeof(struct _ddShapeRecord)));
 return &(s->records[s->nRecords++]);
}

canonical_original_code:
static struct _ddShapeRecord *ddShape_addRecord(struct _ddShape *s)
{
 s->records = realloc((s->records),((s->nRecords + 1) * sizeof(struct _ddShapeRecord)));
 return &(s->records[s->nRecords++]);
}

variable_types: struct _ddShape { 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; } *fills; int nFills; struct _ddShapeRecord *records; int nRecords; int lineWidth; struct _ddRect { int left; int right; int top; int bottom; } bounds; int hasCurve; } *

return_type: struct _ddShapeRecord { enum ddShapeRecordType { SHAPERECORD_END=0, SHAPERECORD_MOVETO=1, SHAPERECORD_NEWFILL0=2, SHAPERECORD_NEWFILL1=3, SHAPERECORD_NEWLINE=4, SHAPERECORD_NEWPATH=5, SHAPERECORD_LINETO=8, SHAPERECORD_CURVETO=9 } type; union { struct { int x1; int y1; int x2; int y2; } coords; struct { int width; unsigned int color; } line; int fill; } data; } *

user_defined_types: struct _ddShapeRecord { enum ddShapeRecordType type; union { struct { int x1; int y1; int x2; int y2; } coords; struct { int width; unsigned int color; } line; int fill; } data; }

user_defined_types: struct _ddShape { struct _ddFill *fills; int nFills; struct _ddShapeRecord *records; int nRecords; int lineWidth; struct _ddRect bounds; int hasCurve; }

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

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

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


decompiled_code:
__m128i *dd_newShape()
{
__m128i *result; // rax
__m128i v1; // xmm0

result = (__m128i *)malloc(0x38uLL);
v1 = _mm_loadu_si128(&ddInvalidRect);
result->m128i_i32[2] = 0;
result->m128i_i64[0] = 0LL;
result[3].m128i_i32[0] = 0;
result[1].m128i_i64[0] = 0LL;
result[1].m128i_i64[1] = 0LL;
result[2] = v1;
return result;
}

original_code:
ddShape*
dd_newShape()
{
 ddShape* s = malloc(sizeof(struct _ddShape));
 s->bounds = ddInvalidRect;
 s->nRecords = 0;
 s->records = ((void *)0);
 s->nFills = 0;
 s->fills = ((void *)0);
 s->hasCurve = (boolean)0;
 s->lineWidth = 0;
 return s;
}

canonical_original_code:
struct _ddShape *dd_newShape()
{
 struct _ddShape *s = malloc(sizeof(struct _ddShape));
 s->bounds = ddInvalidRect;
 s->nRecords = 0;
 s->records = ((void *)0);
 s->nFills = 0;
 s->fills = ((void *)0);
 s->hasCurve = (int)0;
 s->lineWidth = 0;
 return s;
}

variable_types: struct _ddShape { 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; } *fills; int nFills; struct _ddShapeRecord { enum ddShapeRecordType { SHAPERECORD_END=0, SHAPERECORD_MOVETO=1, SHAPERECORD_NEWFILL0=2, SHAPERECORD_NEWFILL1=3, SHAPERECORD_NEWLINE=4, SHAPERECORD_NEWPATH=5, SHAPERECORD_LINETO=8, SHAPERECORD_CURVETO=9 } type; union { struct { int x1; int y1; int x2; int y2; } coords; struct { int width; unsigned int color; } line; int fill; } data; } *records; int nRecords; int lineWidth; struct _ddRect { int left; int right; int top; int bottom; } bounds; int hasCurve; } *


decompiled_code:
void __fastcall dd_destroyShape(void *ptr)
{
void *v2; // rdi
__int64 v3; // rbx
__int64 v4; // rdx

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
{
v4 = 5 * v3++;
dd_destroyFill(*(_QWORD *)ptr + 8 * v4);
}
while ( *((_DWORD *)ptr + 2) > (int)v3 );
}
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi
__int64 v3; // rbx
__int64 v4; // rdx

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
{
v4 = 5 * v3++;
dd_destroyFill(*(_QWORD *)ptr + 8 * v4);
}
while ( *((_DWORD *)ptr + 2) > (int)v3 );
}
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
free(ptr);
}

original_code:
void
dd_destroyShape(ddShape* s)
{
 int i;
 if ( s->records != ((void *)0) )
  free(s->records);
 for ( i = 0; i < s->nFills; ++i )
  dd_destroyFill(&s->fills[i]);
 if ( s->fills != ((void *)0) )
  free(s->fills);
 free(s);
}

canonical_original_code:
void dd_destroyShape(struct _ddShape *s)
{
 int i;
 if ( s->records != ((void *)0) )
  free(s->records);
 for ( i = 0; i < s->nFills; ++i )
  dd_destroyFill(&s->fills[i]);
 if ( s->fills != ((void *)0) )
  free(s->fills);
 free(s);
}

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

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: enum ddShapeRecordType { SHAPERECORD_END=0, SHAPERECORD_MOVETO=1, SHAPERECORD_NEWFILL0=2, SHAPERECORD_NEWFILL1=3, SHAPERECORD_NEWLINE=4, SHAPERECORD_NEWPATH=5, SHAPERECORD_LINETO=8, SHAPERECORD_CURVETO=9 }

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

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

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


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

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

original_code:
ddRect
ddShape_getBounds(ddShape* s)
{
 return s->bounds;
}

canonical_original_code:
struct _ddRect ddShape_getBounds(struct _ddShape *s)
{
 return s->bounds;
}

variable_types: struct _ddShape { 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; } *fills; int nFills; struct _ddShapeRecord { enum ddShapeRecordType { SHAPERECORD_END=0, SHAPERECORD_MOVETO=1, SHAPERECORD_NEWFILL0=2, SHAPERECORD_NEWFILL1=3, SHAPERECORD_NEWLINE=4, SHAPERECORD_NEWPATH=5, SHAPERECORD_LINETO=8, SHAPERECORD_CURVETO=9 } type; union { struct { int x1; int y1; int x2; int y2; } coords; struct { int width; unsigned int color; } line; int fill; } data; } *records; int nRecords; int lineWidth; struct _ddRect bounds; int hasCurve; } *

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


decompiled_code:
void __fastcall ddShape_setBounds(__int64 a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a1 + 32) = a2;
*(_QWORD *)(a1 + 40) = a3;
}

original_code:
void
ddShape_setBounds(ddShape* s, ddRect bounds)
{
 s->bounds = bounds;
}

canonical_original_code:
void ddShape_setBounds(struct _ddShape *s, struct _ddRect bounds)
{
 s->bounds = bounds;
}

variable_types:
bounds
struct _ddRect


original_code:
void
ddShape_moveTo(ddShape* s, fixed x, fixed y)
{
 ddShapeRecord* r = ddShape_addRecord(s);
 r->type = SHAPERECORD_MOVETO;
 r->data.coords.x1 = x;
 r->data.coords.y1 = y;
 s->bounds = ddRect_containPoint(s->bounds, x - s->lineWidth / 2, y - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x + s->lineWidth / 2, y + s->lineWidth / 2);
}

canonical_original_code:
void ddShape_moveTo(struct _ddShape *s, int x, int y)
{
 struct _ddShapeRecord *r = ddShape_addRecord(s);
 r->type = SHAPERECORD_MOVETO;
 r->data.coords.x1 = x;
 r->data.coords.y1 = y;
 s->bounds = ddRect_containPoint(s->bounds, x - s->lineWidth / 2, y - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x + s->lineWidth / 2, y + s->lineWidth / 2);
}

variable_types: x int

variable_types: y int

variable_types: struct _ddShapeRecord { enum ddShapeRecordType { SHAPERECORD_END=0, SHAPERECORD_MOVETO=1, SHAPERECORD_NEWFILL0=2, SHAPERECORD_NEWFILL1=3, SHAPERECORD_NEWLINE=4, SHAPERECORD_NEWPATH=5, SHAPERECORD_LINETO=8, SHAPERECORD_CURVETO=9 } type; union { struct { int x1; int y1; int x2; int y2; } coords; struct { int width; unsigned int color; } line; int fill; } data; } *


original_code:
void
ddShape_lineTo(ddShape* s, fixed x, fixed y)
{
 ddShapeRecord* r = ddShape_addRecord(s);
 r->type = SHAPERECORD_LINETO;
 r->data.coords.x1 = x;
 r->data.coords.y1 = y;
 s->bounds = ddRect_containPoint(s->bounds, x - s->lineWidth / 2, y - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x + s->lineWidth / 2, y + s->lineWidth / 2);
}

canonical_original_code:
void ddShape_lineTo(struct _ddShape *s, int x, int y)
{
 struct _ddShapeRecord *r = ddShape_addRecord(s);
 r->type = SHAPERECORD_LINETO;
 r->data.coords.x1 = x;
 r->data.coords.y1 = y;
 s->bounds = ddRect_containPoint(s->bounds, x - s->lineWidth / 2, y - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x + s->lineWidth / 2, y + s->lineWidth / 2);
}


original_code:
void
ddShape_curveTo(ddShape* s, fixed x1, fixed y1, fixed x2, fixed y2)
{
 ddShapeRecord* r = ddShape_addRecord(s);
 r->type = SHAPERECORD_CURVETO;
 r->data.coords.x1 = x1;
 r->data.coords.y1 = y1;
 r->data.coords.x2 = x2;
 r->data.coords.y2 = y2;
 s->bounds = ddRect_containPoint(s->bounds, x1 - s->lineWidth / 2, y1 - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x1 + s->lineWidth / 2, y1 + s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x2 - s->lineWidth / 2, y2 - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x2 + s->lineWidth / 2, y2 + s->lineWidth / 2);
 s->hasCurve = (boolean)1;
}

canonical_original_code:
void ddShape_curveTo(struct _ddShape *s, int x1, int y1, int x2, int y2)
{
 struct _ddShapeRecord *r = ddShape_addRecord(s);
 r->type = SHAPERECORD_CURVETO;
 r->data.coords.x1 = x1;
 r->data.coords.y1 = y1;
 r->data.coords.x2 = x2;
 r->data.coords.y2 = y2;
 s->bounds = ddRect_containPoint(s->bounds, x1 - s->lineWidth / 2, y1 - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x1 + s->lineWidth / 2, y1 + s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x2 - s->lineWidth / 2, y2 - s->lineWidth / 2);
 s->bounds = ddRect_containPoint(s->bounds, x2 + s->lineWidth / 2, y2 + s->lineWidth / 2);
 s->hasCurve = (int)1;
}


decompiled_code:
char *__fastcall ddShape_end(__int64 a1)
{
__int64 v1; // rax
char *result; // rax

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 || (result = (char *)*(unsigned int *)(v1 + 20LL * *(int *)(a1 + 24) - 20), (_DWORD)result) )
{
result = ddShape_addRecord(a1);
*(_DWORD *)result = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func9(__int64 a1)
{
__int64 v1; // rax
char *result; // rax

v1 = *(_QWORD *)(a1 + 16);
if ( !v1 || (result = (char *)*(unsigned int *)(v1 + 20LL * *(int *)(a1 + 24) - 20), (_DWORD)result) )
{
result = func0(a1);
*(_DWORD *)result = 0;
}
return result;
}

original_code:
void
ddShape_end(ddShape* s)
{
 ddShapeRecord* r;
 if ( s->records == ((void *)0) || s->records[s->nRecords-1].type != SHAPERECORD_END )
 {
  r = ddShape_addRecord(s);
  r->type = SHAPERECORD_END;
 }
}

canonical_original_code:
void ddShape_end(struct _ddShape *s)
{
 struct _ddShapeRecord *r;
 if ( s->records == ((void *)0) || s->records[s->nRecords-1].type != SHAPERECORD_END )
 {
  r = ddShape_addRecord(s);
  r->type = SHAPERECORD_END;
 }
}


original_code:
int
ddShape_addFill(ddShape* s, ddFill fill)
{
 s->fills = realloc((s->fills),(sizeof(ddFill) * (s->nFills + 1)));
 s->fills[s->nFills] = fill;
 return s->nFills++;
}

canonical_original_code:
int ddShape_addFill(struct _ddShape *s, struct _ddFill fill)
{
 s->fills = realloc((s->fills),(sizeof(ddFill) * (s->nFills + 1)));
 s->fills[s->nFills] = fill;
 return s->nFills++;
}

variable_types:
fill
struct _ddFill


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

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

original_code:
int
ddShape_getNFills(ddShape* s)
{
 return s->nFills;
}

canonical_original_code:
int ddShape_getNFills(struct _ddShape *s)
{
 return s->nFills;
}


decompiled_code:
int __fastcall dd_logShapeRecord(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned int a9)
{
int result; // eax

switch ( (int)a7 )
{
case 0:
result = fwrite("SHAPERECORD_END\n", 1uLL, 0x10uLL, stderr);
break;
case 1:
result = fprintf(stderr, "SHAPERECORD_MOVETO: (%i, %i)\n", HIDWORD(a7), (unsigned int)a8);
break;
case 2:
result = fprintf(stderr, "SHAPERECORD_NEWFILL0: 0x%x\n", HIDWORD(a7));
break;
case 3:
result = fprintf(stderr, "SHAPERECORD_NEWFILL1: 0x%x\n", HIDWORD(a7));
break;
case 4:
result = fprintf(stderr, "SHAPERECORD_NEWLINE: %i #%x\n", HIDWORD(a7), (unsigned int)a8);
break;
case 5:
result = fwrite("SHAPERECORD_NEWPATH\n", 1uLL, 0x14uLL, stderr);
break;
case 8:
result = fprintf(stderr, "SHAPERECORD_LINETO: (%i, %i)\n", HIDWORD(a7), (unsigned int)a8);
break;
case 9:
result = fprintf(
stderr,
"SHAPERECORD_CURVETO: (%i, %i), (%i, %i)\n",
HIDWORD(a7),
(unsigned int)a8,
HIDWORD(a8),
a9);
break;
default:
result = dd_error("Unknown shaperecord type: %i", (unsigned int)a7);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8, unsigned int a9)
{
int result; // eax

switch ( (int)a7 )
{
case 0:
result = fwrite("SHAPERECORD_END\n", 1uLL, 0x10uLL, stderr);
break;
case 1:
result = fprintf(stderr, "SHAPERECORD_MOVETO: (%i, %i)\n", HIDWORD(a7), (unsigned int)a8);
break;
case 2:
result = fprintf(stderr, "SHAPERECORD_NEWFILL0: 0x%x\n", HIDWORD(a7));
break;
case 3:
result = fprintf(stderr, "SHAPERECORD_NEWFILL1: 0x%x\n", HIDWORD(a7));
break;
case 4:
result = fprintf(stderr, "SHAPERECORD_NEWLINE: %i #%x\n", HIDWORD(a7), (unsigned int)a8);
break;
case 5:
result = fwrite("SHAPERECORD_NEWPATH\n", 1uLL, 0x14uLL, stderr);
break;
case 8:
result = fprintf(stderr, "SHAPERECORD_LINETO: (%i, %i)\n", HIDWORD(a7), (unsigned int)a8);
break;
case 9:
result = fprintf(
stderr,
"SHAPERECORD_CURVETO: (%i, %i), (%i, %i)\n",
HIDWORD(a7),
(unsigned int)a8,
HIDWORD(a8),
a9);
break;
default:
result = dd_error("Unknown shaperecord type: %i", (unsigned int)a7);
break;
}
return result;
}

original_code:
void
dd_logShapeRecord(ddShapeRecord record)
{
 switch ( record.type )
 {
  case SHAPERECORD_END:
   fprintf(stderr, "SHAPERECORD_END\n");
   break;
  case SHAPERECORD_MOVETO:
   fprintf(stderr, "SHAPERECORD_MOVETO: (%i, %i)\n", record.data.coords.x1, record.data.coords.y1);
   break;
  case SHAPERECORD_LINETO:
   fprintf(stderr, "SHAPERECORD_LINETO: (%i, %i)\n", record.data.coords.x1, record.data.coords.y1);
   break;
  case SHAPERECORD_CURVETO:
   fprintf(stderr, "SHAPERECORD_CURVETO: (%i, %i), (%i, %i)\n", record.data.coords.x1, record.data.coords.y1, record.data.coords.x2, record.data.coords.y2);
   break;
  case SHAPERECORD_NEWFILL0:
   fprintf(stderr, "SHAPERECORD_NEWFILL0: 0x%x\n", record.data.fill);
   break;
  case SHAPERECORD_NEWFILL1:
   fprintf(stderr, "SHAPERECORD_NEWFILL1: 0x%x\n", record.data.fill);
   break;
  case SHAPERECORD_NEWLINE:
   fprintf(stderr, "SHAPERECORD_NEWLINE: %i #%x\n", record.data.line.width, record.data.line.color);
   break;
  case SHAPERECORD_NEWPATH:
   fprintf(stderr, "SHAPERECORD_NEWPATH\n");
   break;
  default:
   dd_error("Unknown shaperecord type: %i", record.type);
 }
}

canonical_original_code:
void dd_logShapeRecord(struct _ddShapeRecord record)
{
 switch ( record.type )
 {
  case SHAPERECORD_END:
   fprintf(stderr, "SHAPERECORD_END\n");
   break;
  case SHAPERECORD_MOVETO:
   fprintf(stderr, "SHAPERECORD_MOVETO: (%i, %i)\n", record.data.coords.x1, record.data.coords.y1);
   break;
  case SHAPERECORD_LINETO:
   fprintf(stderr, "SHAPERECORD_LINETO: (%i, %i)\n", record.data.coords.x1, record.data.coords.y1);
   break;
  case SHAPERECORD_CURVETO:
   fprintf(stderr, "SHAPERECORD_CURVETO: (%i, %i), (%i, %i)\n", record.data.coords.x1, record.data.coords.y1, record.data.coords.x2, record.data.coords.y2);
   break;
  case SHAPERECORD_NEWFILL0:
   fprintf(stderr, "SHAPERECORD_NEWFILL0: 0x%x\n", record.data.fill);
   break;
  case SHAPERECORD_NEWFILL1:
   fprintf(stderr, "SHAPERECORD_NEWFILL1: 0x%x\n", record.data.fill);
   break;
  case SHAPERECORD_NEWLINE:
   fprintf(stderr, "SHAPERECORD_NEWLINE: %i #%x\n", record.data.line.width, record.data.line.color);
   break;
  case SHAPERECORD_NEWPATH:
   fprintf(stderr, "SHAPERECORD_NEWPATH\n");
   break;
  default:
   dd_error("Unknown shaperecord type: %i", record.type);
 }
}

variable_types: struct _ddShapeRecord { enum ddShapeRecordType { SHAPERECORD_END=0, SHAPERECORD_MOVETO=1, SHAPERECORD_NEWFILL0=2, SHAPERECORD_NEWFILL1=3, SHAPERECORD_NEWLINE=4, SHAPERECORD_NEWPATH=5, SHAPERECORD_LINETO=8, SHAPERECORD_CURVETO=9 } type; union { struct { int x1; int y1; int x2; int y2; } coords; struct { int width; unsigned int color; } line; int fill; } data; }


original_code:
void
dd_logShape(ddShape* shape)
{
 int i;
 for ( i = 0; i < shape->nRecords; ++i )
 {
  fprintf(stderr, "%02i: ", i);
  dd_logShapeRecord(shape->records[i]);
 }
}

canonical_original_code:
void dd_logShape(struct _ddShape *shape)
{
 int i;
 for ( i = 0; i < shape->nRecords; ++i )
 {
  fprintf(stderr, "%02i: ", i);
  dd_logShapeRecord(shape->records[i]);
 }
}

variable_types: i int


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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
ddUpdateList*
dd_newUpdateList()
{
 ddUpdateList* list = malloc(sizeof(ddUpdateList));
 list->nAlloced = 0;
 list->nRects = 0;
 list->rects = ((void *)0);
 return list;
}

canonical_original_code:
struct _ddUpdateList *dd_newUpdateList()
{
 struct _ddUpdateList *list = malloc(sizeof(ddUpdateList));
 list->nAlloced = 0;
 list->nRects = 0;
 list->rects = ((void *)0);
 return list;
}

variable_types: struct _ddUpdateList { int nAlloced; int nRects; struct _ddRect { int left; int right; int top; int bottom; } *rects; } *

user_defined_types: struct _ddUpdateList { int nAlloced; int nRects; struct _ddRect *rects; }


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

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

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

v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
dd_destroyUpdateList(ddUpdateList* list)
{
 if ( list->rects != ((void *)0) )
  free(list->rects);
 free(list);
}

canonical_original_code:
void dd_destroyUpdateList(struct _ddUpdateList *list)
{
 if ( list->rects != ((void *)0) )
  free(list->rects);
 free(list);
}


decompiled_code:
void __fastcall ddUpdateList_clear(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 0;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
*(_DWORD *)(a1 + 4) = 0;
}

original_code:
void
ddUpdateList_clear(ddUpdateList* list)
{
 list->nRects = 0;
}

canonical_original_code:
void ddUpdateList_clear(struct _ddUpdateList *list)
{
 list->nRects = 0;
}


original_code:
void
ddUpdateList_constrainToRect(ddUpdateList* list, ddRect bounds)
{
 int i, j;
 for ( i = 0, j = 0; i < list->nRects; ++i )
 {
  if ( ddRect_intersectsRect(list->rects[i], bounds) )
  {
   list->rects[j] = ddRect_intersectRect(list->rects[i], bounds);
   ++j;
  }
 }
 list->nRects = j;
}

canonical_original_code:
void ddUpdateList_constrainToRect(struct _ddUpdateList *list, struct _ddRect bounds)
{
 int i; int j;
 for ( i = 0, j = 0; i < list->nRects; ++i )
 {
  if ( ddRect_intersectsRect(list->rects[i], bounds) )
  {
   list->rects[j] = ddRect_intersectRect(list->rects[i], bounds);
   ++j;
  }
 }
 list->nRects = j;
}

variable_types: j int


decompiled_code:
__int64 __fastcall ddUpdateList_fillImageBackground(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // rax

result = *(unsigned int *)(a1 + 4);
if ( (int)result > 0 )
{
v5 = 0LL;
do
{
v6 = v5++;
result = ddImage_blendRect(
a2,
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v6),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v6 + 8),
a3);
}
while ( *(_DWORD *)(a1 + 4) > (int)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // rax

result = *(unsigned int *)(a1 + 4);
if ( (int)result > 0 )
{
v5 = 0LL;
do
{
v6 = v5++;
result = ddImage_blendRect(
a2,
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v6),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v6 + 8),
a3);
}
while ( *(_DWORD *)(a1 + 4) > (int)v5 );
}
return result;
}

original_code:
void
ddUpdateList_fillImageBackground(ddUpdateList* list,
         ddImage* image, ddColor background)
{
 int i;
 for ( i = 0; i < list->nRects; ++i )
  ddImage_blendRect(image, list->rects[i], background);
}

canonical_original_code:
void ddUpdateList_fillImageBackground(struct _ddUpdateList *list, struct _ddImage *image, unsigned int background)
{
 int i;
 for ( i = 0; i < list->nRects; ++i )
  ddImage_blendRect(image, list->rects[i], background);
}

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


decompiled_code:
__int64 __fastcall ddUpdateList_intersectsRect(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

if ( *(int *)(a1 + 4) <= 0 )
return 0LL;
v4 = 0LL;
do
{
if ( (unsigned int)ddRect_intersectsRect(
a2,
a3,
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v4),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v4 + 8)) )
return 1LL;
++v4;
}
while ( *(_DWORD *)(a1 + 4) > (int)v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

if ( *(int *)(a1 + 4) <= 0 )
return 0LL;
v4 = 0LL;
do
{
if ( (unsigned int)ddRect_intersectsRect(
a2,
a3,
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v4),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v4 + 8)) )
return 1LL;
++v4;
}
while ( *(_DWORD *)(a1 + 4) > (int)v4 );
return 0LL;
}

original_code:
int
ddUpdateList_intersectsRect(ddUpdateList* list, ddRect rect)
{
 int i;
 for ( i = 0; i < list->nRects; ++i )
 {
  if ( ddRect_intersectsRect(rect, list->rects[i]) )
   return 1;
 }
 return 0;
}

canonical_original_code:
int ddUpdateList_intersectsRect(struct _ddUpdateList *list, struct _ddRect rect)
{
 int i;
 for ( i = 0; i < list->nRects; ++i )
 {
  if ( ddRect_intersectsRect(rect, list->rects[i]) )
   return 1;
 }
 return 0;
}

variable_types:
rect
struct _ddRect


decompiled_code:
__int64 __fastcall ddUpdateList_makeIntegerRects(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 *v4; // rbx
__int64 v5; // rdx

result = *(unsigned int *)(a1 + 4);
if ( (int)result > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
v4 = (__int64 *)(*(_QWORD *)(a1 + 8) + 16 * v3);
result = ddRect_integerRect(*v4, v4[1]);
*v4 = result;
v4[1] = v5;
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 *v4; // rbx
__int64 v5; // rdx

result = *(unsigned int *)(a1 + 4);
if ( (int)result > 0 )
{
v2 = 0LL;
do
{
v3 = v2++;
v4 = (__int64 *)(*(_QWORD *)(a1 + 8) + 16 * v3);
result = ddRect_integerRect(*v4, v4[1]);
*v4 = result;
v4[1] = v5;
}
while ( *(_DWORD *)(a1 + 4) > (int)v2 );
}
return result;
}

original_code:
void
ddUpdateList_makeIntegerRects(ddUpdateList* list)
{
 int i;
 for ( i = 0; i < list->nRects; ++i )
  list->rects[i] = ddRect_integerRect(list->rects[i]);
}

canonical_original_code:
void ddUpdateList_makeIntegerRects(struct _ddUpdateList *list)
{
 int i;
 for ( i = 0; i < list->nRects; ++i )
  list->rects[i] = ddRect_integerRect(list->rects[i]);
}


original_code:
void
ddUpdateList_includeRect(ddUpdateList* list, ddRect rect)
{
 int i;
 int j;
 if ( !((rect).left != 0x7fffffff) )
  return;
 for ( i = 0; i < list->nRects; ++i )
 {
  ddRect hit = list->rects[i];
  if ( ddRect_intersectsRect(rect, hit) )
  {
   hit = ddRect_containRect(hit, rect);
   for ( j = i + 1; j < list->nRects; ++j )
   {
    if ( ddRect_intersectsRect(hit, list->rects[j]) )
    {
     hit = ddRect_containRect(hit, list->rects[j]);
     list->rects[j] = ddInvalidRect;
    }
   }
   list->rects[i] = hit;
   return;
  }
 }
 if ( list->nRects == list->nAlloced )
 {
  list->nAlloced += 4;
  list->rects = realloc((list->rects),(list->nAlloced * sizeof(ddRect)));
 }
 list->rects[list->nRects] = rect;
 ++list->nRects;
}

canonical_original_code:
void ddUpdateList_includeRect(struct _ddUpdateList *list, struct _ddRect rect)
{
 int i;
 int j;
 if ( !((rect).left != 0x7fffffff) )
  return;
 for ( i = 0; i < list->nRects; ++i )
 {
  struct _ddRect hit = list->rects[i];
  if ( ddRect_intersectsRect(rect, hit) )
  {
   hit = ddRect_containRect(hit, rect);
   for ( j = i + 1; j < list->nRects; ++j )
   {
    if ( ddRect_intersectsRect(hit, list->rects[j]) )
    {
     hit = ddRect_containRect(hit, list->rects[j]);
     list->rects[j] = ddInvalidRect;
    }
   }
   list->rects[i] = hit;
   return;
  }
 }
 if ( list->nRects == list->nAlloced )
 {
  list->nAlloced += 4;
  list->rects = realloc((list->rects),(list->nAlloced * sizeof(ddRect)));
 }
 list->rects[list->nRects] = rect;
 ++list->nRects;
}

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


decompiled_code:
__int64 __fastcall ddUpdateList_containingRect(__int64 a1)
{
int v2; // eax
__int64 v3; // rdi
__int64 v4; // rsi
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rdx

v2 = *(_DWORD *)(a1 + 4);
v3 = ddInvalidRect.m128i_i64[0];
v4 = ddInvalidRect.m128i_i64[1];
if ( v2 > 0 )
{
v5 = 0LL;
do
{
v6 = v5++;
v3 = ddRect_containRect(
v3,
v4,
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v6),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v6 + 8));
v4 = v7;
}
while ( *(_DWORD *)(a1 + 4) > (int)v5 );
}
return v3;
}

original_code:
ddRect
ddUpdateList_containingRect(ddUpdateList* list)
{
 int i;
 ddRect bounds = ddInvalidRect;
 for ( i = 0; i < list->nRects; ++i )
  bounds = ddRect_containRect(bounds, list->rects[i]);
 return bounds;
}

canonical_original_code:
struct _ddRect ddUpdateList_containingRect(struct _ddUpdateList *list)
{
 int i;
 struct _ddRect bounds = ddInvalidRect;
 for ( i = 0; i < list->nRects; ++i )
  bounds = ddRect_containRect(bounds, list->rects[i]);
 return bounds;
}

variable_types: struct _ddUpdateList { int nAlloced; int nRects; struct _ddRect *rects; } *


decompiled_code:
__int64 __fastcall dd_makeRect(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
ddRect
dd_makeRect(fixed left, fixed right, fixed top, fixed bottom)
{
 ddRect r;
 r.left = left;
 r.right = right;
 r.top = top;
 r.bottom = bottom;
 return r;
}

canonical_original_code:
struct _ddRect dd_makeRect(int left, int right, int top, int bottom)
{
 struct _ddRect r;
 r.left = left;
 r.right = right;
 r.top = top;
 r.bottom = bottom;
 return r;
}

variable_types: left int

variable_types: right int

variable_types: top int

variable_types: bottom int


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

result = (unsigned int)(HIDWORD(a1) - a1);
if ( (_DWORD)a1 == 0x7FFFFFFF )
result = 0LL;
return result;
}

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

result = (unsigned int)(HIDWORD(a1) - a1);
if ( (_DWORD)a1 == 0x7FFFFFFF )
result = 0LL;
return result;
}

original_code:
fixed
ddRect_getWidth(ddRect r)
{
 if ( ((r).left != 0x7fffffff) )
  return r.right - r.left;
 else
  return 0;
}

canonical_original_code:
int ddRect_getWidth(struct _ddRect r)
{
 if ( ((r).left != 0x7fffffff) )
  return r.right - r.left;
 else
  return 0;
}


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

result = (unsigned int)(HIDWORD(a2) - a2);
if ( a1 == 0x7FFFFFFF )
result = 0LL;
return result;
}

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

result = (unsigned int)(HIDWORD(a2) - a2);
if ( a1 == 0x7FFFFFFF )
result = 0LL;
return result;
}

original_code:
fixed
ddRect_getHeight(ddRect r)
{
 if ( ((r).left != 0x7fffffff) )
  return r.bottom - r.top;
 else
  return 0;
}

canonical_original_code:
int ddRect_getHeight(struct _ddRect r)
{
 if ( ((r).left != 0x7fffffff) )
  return r.bottom - r.top;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall ddRect_containPoint(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rax
__int64 v4; // r8

v3 = a3;
v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
{
v4 = a3;
}
else
{
if ( (int)a3 <= (int)a1 )
LODWORD(a1) = a3;
if ( (int)a3 >= (int)v4 )
v4 = a3;
v3 = (unsigned int)a1;
}
return (v4 << 32) | v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 v3; // rax
__int64 v4; // r8

v3 = a3;
v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
{
v4 = a3;
}
else
{
if ( (int)a3 <= (int)a1 )
LODWORD(a1) = a3;
if ( (int)a3 >= (int)v4 )
v4 = a3;
v3 = (unsigned int)a1;
}
return (v4 << 32) | v3;
}

original_code:
ddRect
ddRect_containPoint(ddRect rect, fixed x, fixed y)
{
 if ( ((rect).left != 0x7fffffff) )
 {
  if ( rect.left > x )
   rect.left = x;
  if ( rect.right < x )
   rect.right = x;
  if ( rect.top > y )
   rect.top = y;
  if ( rect.bottom < y )
   rect.bottom = y;
 }
 else
 {
  rect.left = rect.right = x;
  rect.top = rect.bottom = y;
 }
 return rect;
}

canonical_original_code:
struct _ddRect ddRect_containPoint(struct _ddRect rect, int x, int y)
{
 if ( ((rect).left != 0x7fffffff) )
 {
  if ( rect.left > x )
   rect.left = x;
  if ( rect.right < x )
   rect.right = x;
  if ( rect.top > y )
   rect.top = y;
  if ( rect.bottom < y )
   rect.bottom = y;
 }
 else
 {
  rect.left = rect.right = x;
  rect.top = rect.bottom = y;
 }
 return rect;
}

variable_types: x int


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

result = 0LL;
if ( (_DWORD)a1 != 0x7FFFFFFF && a3 >= (int)a1 && a3 <= SHIDWORD(a1) && a4 >= (int)a2 )
result = a4 <= SHIDWORD(a2);
return result;
}

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

result = 0LL;
if ( (_DWORD)a1 != 0x7FFFFFFF && a3 >= (int)a1 && a3 <= SHIDWORD(a1) && a4 >= (int)a2 )
result = a4 <= SHIDWORD(a2);
return result;
}

original_code:
boolean
ddRect_containsPoint(ddRect rect, fixed x, fixed y)
{
 if ( !((rect).left != 0x7fffffff) )
  return (boolean)0;
 return x >= rect.left && x <= rect.right &&
  y >= rect.top && y <= rect.bottom;
}

canonical_original_code:
int ddRect_containsPoint(struct _ddRect rect, int x, int y)
{
 if ( !((rect).left != 0x7fffffff) )
  return (int)0;
 return x >= rect.left && x <= rect.right &&
  y >= rect.top && y <= rect.bottom;
}

variable_types: y int


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

if ( (_DWORD)a3 == 0x7FFFFFFF || (_DWORD)a1 == 0x7FFFFFFF )
return 0LL;
result = 0LL;
if ( (int)a1 <= SHIDWORD(a3) && (int)a3 <= SHIDWORD(a1) && (int)a2 <= SHIDWORD(a4) )
result = SHIDWORD(a2) >= (int)a4;
return result;
}

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

if ( (_DWORD)a3 == 0x7FFFFFFF || (_DWORD)a1 == 0x7FFFFFFF )
return 0LL;
result = 0LL;
if ( (int)a1 <= SHIDWORD(a3) && (int)a3 <= SHIDWORD(a1) && (int)a2 <= SHIDWORD(a4) )
result = SHIDWORD(a2) >= (int)a4;
return result;
}

original_code:
boolean
ddRect_intersectsRect(ddRect r1, ddRect r2)
{
 if ( !((r1).left != 0x7fffffff) || !((r2).left != 0x7fffffff) )
  return (boolean)0;
 return !(r1.left > r2.right || r1.right < r2.left ||
    r1.top > r2.bottom || r1.bottom < r2.top);
}

canonical_original_code:
int ddRect_intersectsRect(struct _ddRect r1, struct _ddRect r2)
{
 if ( !((r1).left != 0x7fffffff) || !((r2).left != 0x7fffffff) )
  return (int)0;
 return !(r1.left > r2.right || r1.right < r2.left ||
    r1.top > r2.bottom || r1.bottom < r2.top);
}


decompiled_code:
__int64 __fastcall ddRect_intersectRect(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r8
__int64 v6; // rax

v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
return (v4 << 32) | 0x7FFFFFFF;
if ( (_DWORD)a3 == 0x7FFFFFFF )
return (a3 >> 32 << 32) | 0x7FFFFFFF;
if ( (int)a2 > SHIDWORD(a4) || SHIDWORD(a1) < (int)a3 || (int)a1 > SHIDWORD(a3) || SHIDWORD(a2) < (int)a4 )
return 0x7FFFFFFFLL;
if ( (int)a1 < (int)a3 )
LODWORD(a1) = a3;
v6 = HIDWORD(a3);
if ( (int)v4 <= SHIDWORD(a3) )
v6 = (unsigned int)v4;
return (v6 << 32) | (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r8
__int64 v6; // rax

v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
return (v4 << 32) | 0x7FFFFFFF;
if ( (_DWORD)a3 == 0x7FFFFFFF )
return (a3 >> 32 << 32) | 0x7FFFFFFF;
if ( (int)a2 > SHIDWORD(a4) || SHIDWORD(a1) < (int)a3 || (int)a1 > SHIDWORD(a3) || SHIDWORD(a2) < (int)a4 )
return 0x7FFFFFFFLL;
if ( (int)a1 < (int)a3 )
LODWORD(a1) = a3;
v6 = HIDWORD(a3);
if ( (int)v4 <= SHIDWORD(a3) )
v6 = (unsigned int)v4;
return (v6 << 32) | (unsigned int)a1;
}

original_code:
ddRect
ddRect_intersectRect(ddRect r1, ddRect r2)
{
 if ( !((r1).left != 0x7fffffff) )
  return r1;
 if ( !((r2).left != 0x7fffffff) )
  return r2;
 if ( r1.left > r2.right || r1.right < r2.left ||
   r1.top > r2.bottom || r1.bottom < r2.top )
  return ddInvalidRect;
 r1.left = (((r1.left)>(r2.left))?(r1.left):(r2.left));
 r1.right = (((r1.right)<(r2.right))?(r1.right):(r2.right));
 r1.top = (((r1.top)>(r2.top))?(r1.top):(r2.top));
 r1.bottom = (((r1.bottom)<(r2.bottom))?(r1.bottom):(r2.bottom));
 return r1;
}

canonical_original_code:
struct _ddRect ddRect_intersectRect(struct _ddRect r1, struct _ddRect r2)
{
 if ( !((r1).left != 0x7fffffff) )
  return r1;
 if ( !((r2).left != 0x7fffffff) )
  return r2;
 if ( r1.left > r2.right || r1.right < r2.left ||
   r1.top > r2.bottom || r1.bottom < r2.top )
  return ddInvalidRect;
 r1.left = (((r1.left)>(r2.left))?(r1.left):(r2.left));
 r1.right = (((r1.right)<(r2.right))?(r1.right):(r2.right));
 r1.top = (((r1.top)>(r2.top))?(r1.top):(r2.top));
 r1.bottom = (((r1.bottom)<(r2.bottom))?(r1.bottom):(r2.bottom));
 return r1;
}


decompiled_code:
__int64 __fastcall ddRect_containRect(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r9
__int64 v4; // rax

v3 = a1 >> 32;
if ( (_DWORD)a3 == 0x7FFFFFFF )
return (v3 << 32) | (unsigned int)a1;
if ( (_DWORD)a1 == 0x7FFFFFFF )
return (a3 >> 32 << 32) | (unsigned int)a3;
if ( (int)a1 > (int)a3 )
LODWORD(a1) = a3;
v4 = HIDWORD(a3);
if ( (int)v3 >= SHIDWORD(a3) )
v4 = (unsigned int)v3;
return (v4 << 32) | (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r9
__int64 v4; // rax

v3 = a1 >> 32;
if ( (_DWORD)a3 == 0x7FFFFFFF )
return (v3 << 32) | (unsigned int)a1;
if ( (_DWORD)a1 == 0x7FFFFFFF )
return (a3 >> 32 << 32) | (unsigned int)a3;
if ( (int)a1 > (int)a3 )
LODWORD(a1) = a3;
v4 = HIDWORD(a3);
if ( (int)v3 >= SHIDWORD(a3) )
v4 = (unsigned int)v3;
return (v4 << 32) | (unsigned int)a1;
}

original_code:
ddRect
ddRect_containRect(ddRect r1, ddRect r2)
{
 if ( !((r2).left != 0x7fffffff) )
  return r1;
 if ( !((r1).left != 0x7fffffff) )
  return r2;
 r1.left = (((r1.left)<(r2.left))?(r1.left):(r2.left));
 r1.right = (((r1.right)>(r2.right))?(r1.right):(r2.right));
 r1.top = (((r1.top)<(r2.top))?(r1.top):(r2.top));
 r1.bottom = (((r1.bottom)>(r2.bottom))?(r1.bottom):(r2.bottom));
 return r1;
}

canonical_original_code:
struct _ddRect ddRect_containRect(struct _ddRect r1, struct _ddRect r2)
{
 if ( !((r2).left != 0x7fffffff) )
  return r1;
 if ( !((r1).left != 0x7fffffff) )
  return r2;
 r1.left = (((r1.left)<(r2.left))?(r1.left):(r2.left));
 r1.right = (((r1.right)>(r2.right))?(r1.right):(r2.right));
 r1.top = (((r1.top)<(r2.top))?(r1.top):(r2.top));
 r1.bottom = (((r1.bottom)>(r2.bottom))?(r1.bottom):(r2.bottom));
 return r1;
}


decompiled_code:
unsigned __int64 __fastcall ddRect_integerRect(__int64 a1)
{
return (unsigned int)a1 & 0xFFFFFC00 | ((unsigned __int64)((HIDWORD(a1) + 1023) & 0xFFFFFC00) << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1)
{
return (unsigned int)a1 & 0xFFFFFC00 | ((unsigned __int64)((HIDWORD(a1) + 1023) & 0xFFFFFC00) << 32);
}

original_code:
ddRect
ddRect_integerRect(ddRect rect)
{
 rect.left = (rect.left >> 10) << 10;
 rect.top = (rect.top >> 10) << 10;
 rect.right = ((rect.right + ((1 << 10) - 1)) >> 10) << 10;
 rect.bottom = ((rect.bottom + ((1 << 10) - 1)) >> 10) << 10;
 return rect;
}

canonical_original_code:
struct _ddRect ddRect_integerRect(struct _ddRect rect)
{
 rect.left = (rect.left >> 10) << 10;
 rect.top = (rect.top >> 10) << 10;
 rect.right = ((rect.right + ((1 << 10) - 1)) >> 10) << 10;
 rect.bottom = ((rect.bottom + ((1 << 10) - 1)) >> 10) << 10;
 return rect;
}


decompiled_code:
__int64 __fastcall ddRect_constrain(__int64 a1, __int64 a2, int a3, __int64 a4)
{
__int64 v4; // rax

v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
return (v4 << 32) | 0x7FFFFFFF;
if ( a3 >= (int)a1 )
LODWORD(a1) = a3;
if ( (int)a4 > (int)v4 )
a4 = (unsigned int)v4;
return (a4 << 32) | (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3, __int64 a4)
{
__int64 v4; // rax

v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
return (v4 << 32) | 0x7FFFFFFF;
if ( a3 >= (int)a1 )
LODWORD(a1) = a3;
if ( (int)a4 > (int)v4 )
a4 = (unsigned int)v4;
return (a4 << 32) | (unsigned int)a1;
}

original_code:
ddRect
ddRect_constrain(ddRect rect, fixed left, fixed right, fixed top, fixed bottom)
{
 if ( !((rect).left != 0x7fffffff) )
  return rect;
 rect.left = (((rect.left)>(left))?(rect.left):(left));
 rect.right = (((rect.right)<(right))?(rect.right):(right));
 rect.top = (((rect.top)>(top))?(rect.top):(top));
 rect.bottom = (((rect.bottom)<(bottom))?(rect.bottom):(bottom));
 return rect;
}

canonical_original_code:
struct _ddRect ddRect_constrain(struct _ddRect rect, int left, int right, int top, int bottom)
{
 if ( !((rect).left != 0x7fffffff) )
  return rect;
 rect.left = (((rect.left)>(left))?(rect.left):(left));
 rect.right = (((rect.right)<(right))?(rect.right):(right));
 rect.top = (((rect.top)>(top))?(rect.top):(top));
 rect.bottom = (((rect.bottom)<(bottom))?(rect.bottom):(bottom));
 return rect;
}


decompiled_code:
void __fastcall ddRect_constrainPoint(__int64 a1, __int64 a2, _DWORD *a3, _DWORD *a4)
{
if ( (_DWORD)a1 != 0x7FFFFFFF )
{
if ( *a3 < (int)a1 || (a1 >>= 32, *a3 > (int)a1) )
*a3 = a1;
if ( *a4 >= (int)a2 )
{
if ( *a4 > SHIDWORD(a2) )
*a4 = HIDWORD(a2);
}
else
{
*a4 = a2;
}
}
}

original_code:
void
ddRect_constrainPoint(ddRect rect, fixed *x, fixed *y)
{
 if ( !((rect).left != 0x7fffffff) )
  return;
 if ( *x < rect.left )
  *x = rect.left;
 else if ( *x > rect.right )
  *x = rect.right;
 if ( *y < rect.top )
  *y = rect.top;
 else if ( *y > rect.bottom )
  *y = rect.bottom;
}

canonical_original_code:
void ddRect_constrainPoint(struct _ddRect rect, int *x, int *y)
{
 if ( !((rect).left != 0x7fffffff) )
  return;
 if ( *x < rect.left )
  *x = rect.left;
 else if ( *x > rect.right )
  *x = rect.right;
 if ( *y < rect.top )
  *y = rect.top;
 else if ( *y > rect.bottom )
  *y = rect.bottom;
}

variable_types:
x
int *

variable_types:
y
int *


decompiled_code:
unsigned __int64 __fastcall ddRect_displace(__int64 a1, __int64 a2, int a3)
{
return ((unsigned __int64)(unsigned int)(a3 + HIDWORD(a1)) << 32) | (unsigned int)(a3 + a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1, __int64 a2, int a3)
{
return ((unsigned __int64)(unsigned int)(a3 + HIDWORD(a1)) << 32) | (unsigned int)(a3 + a1);
}

original_code:
ddRect
ddRect_displace(ddRect r, int dx, int dy)
{
 r.left += dx;
 r.right += dx;
 r.top += dy;
 r.bottom += dy;
 return r;
}

canonical_original_code:
struct _ddRect ddRect_displace(struct _ddRect r, int dx, int dy)
{
 r.left += dx;
 r.right += dx;
 r.top += dy;
 r.bottom += dy;
 return r;
}

variable_types:
r
struct _ddRect

variable_types: dx int

variable_types: dy int


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:
_QWORD *dd_newGradient()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = malloc(0x10uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
ddGradient*
dd_newGradient()
{
 ddGradient* g = malloc(sizeof(ddGradient));
 g->entries = ((void *)0);
 g->nGrads = 0;
 g->band = 0;
 return g;
}

canonical_original_code:
struct _ddGradient *dd_newGradient()
{
 struct _ddGradient *g = malloc(sizeof(ddGradient));
 g->entries = ((void *)0);
 g->nGrads = 0;
 g->band = 0;
 return g;
}

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


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

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

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

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

original_code:
void
dd_destroyGradient(ddGradient* g)
{
 if ( g->entries != ((void *)0) )
  free(g->entries);
 free(g);
}

canonical_original_code:
void dd_destroyGradient(struct _ddGradient *g)
{
 if ( g->entries != ((void *)0) )
  free(g->entries);
 free(g);
}


original_code:
void
ddGradient_set(ddGradient* g, int idx, ddColor color, UInt8 ratio)
{
 struct _ddGradEntry* e = &(g->entries[idx]);
 e->ratio = ratio << 8;
 e->alpha = (((color)>>24)&0xff);
 e->red = (((color)>>16)&0xff);
 e->green = (((color)>>8)&0xff);
 e->blue = ((color)&0xff);
 if ( idx > 0 )
 {
  struct _ddGradEntry *l = &(g->entries[idx-1]);
  if ( e->ratio != l->ratio )
  {
   l->alphaslope = ((e->alpha - l->alpha) << 16) / (e->ratio - l->ratio);
   l->redslope = ((e->red - l->red) << 16) / (e->ratio - l->ratio);
   l->greenslope = ((e->green - l->green) << 16) / (e->ratio - l->ratio);
   l->blueslope = ((e->blue - l->blue) << 16) / (e->ratio - l->ratio);
  }
 }
}

canonical_original_code:
void ddGradient_set(struct _ddGradient *g, int idx, unsigned int color, unsigned char ratio)
{
 struct _ddGradEntry *e = &(g->entries[idx]);
 e->ratio = ratio << 8;
 e->alpha = (((color)>>24)&0xff);
 e->red = (((color)>>16)&0xff);
 e->green = (((color)>>8)&0xff);
 e->blue = ((color)&0xff);
 if ( idx > 0 )
 {
  struct _ddGradEntry *l = &(g->entries[idx-1]);
  if ( e->ratio != l->ratio )
  {
   l->alphaslope = ((e->alpha - l->alpha) << 16) / (e->ratio - l->ratio);
   l->redslope = ((e->red - l->red) << 16) / (e->ratio - l->ratio);
   l->greenslope = ((e->green - l->green) << 16) / (e->ratio - l->ratio);
   l->blueslope = ((e->blue - l->blue) << 16) / (e->ratio - l->ratio);
  }
 }
}

variable_types: idx int

variable_types:
ratio
unsigned char

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


original_code:
void
ddGradient_interpolate(ddGradient* g, ddGradient* g1, ddGradient* g2, UInt16 ratio)
{
 int i;
 unsigned int r1 = 0x10000 - ratio, r2 = ratio;
 for ( i = 0; i < g->nGrads; ++i )
 {
  struct _ddGradEntry *e1 = &(g1->entries[i]);
  struct _ddGradEntry *e2 = &(g2->entries[i]);
  ddColor c1 = ((((e1->alpha)&0xff)<<24)|(((e1->red)&0xff)<<16)|(((e1->green)&0xff)<<8)|((e1->blue)&0xff));
  ddColor c2 = ((((e2->alpha)&0xff)<<24)|(((e2->red)&0xff)<<16)|(((e2->green)&0xff)<<8)|((e2->blue)&0xff));
  ddGradient_set(g, i,
     ddColor_scale(c1, (r1 + 127) >> 8) + ddColor_scale(c2, (r2 + 127) >> 8),
     (r1 * e1->ratio + r2 * e2->ratio) >> 24);
 }
}

canonical_original_code:
void ddGradient_interpolate(struct _ddGradient *g, struct _ddGradient *g1, struct _ddGradient *g2, unsigned short ratio)
{
 int i;
 unsigned int r1 = 0x10000 - ratio; unsigned int r2 = ratio;
 for ( i = 0; i < g->nGrads; ++i )
 {
  struct _ddGradEntry *e1 = &(g1->entries[i]);
  struct _ddGradEntry *e2 = &(g2->entries[i]);
  unsigned int c1 = ((((e1->alpha)&0xff)<<24)|(((e1->red)&0xff)<<16)|(((e1->green)&0xff)<<8)|((e1->blue)&0xff));
  unsigned int c2 = ((((e2->alpha)&0xff)<<24)|(((e2->red)&0xff)<<16)|(((e2->green)&0xff)<<8)|((e2->blue)&0xff));
  ddGradient_set(g, i,
     ddColor_scale(c1, (r1 + 127) >> 8) + ddColor_scale(c2, (r2 + 127) >> 8),
     (r1 * e1->ratio + r2 * e2->ratio) >> 24);
 }
}

variable_types:
ratio
unsigned short

variable_types: i int


decompiled_code:
__int64 __fastcall ddGradient_add(__int64 a1, unsigned int a2, unsigned __int8 a3)
{
__int16 v3; // r13
int v5; // esi
_WORD *v7; // rdi
void *v8; // rax
int v9; // esi
__int64 result; // rax

v3 = a3;
v5 = *(_DWORD *)(a1 + 8);
v7 = *(_WORD **)a1;
if ( v5 > 0 && a3 == v7[12 * v5 - 12] )
return ddGradient_set((__int64 *)a1, v5 - 1, a2, a3);
v8 = realloc(v7, 24LL * (v5 + 1));
v9 = *(_DWORD *)(a1 + 8);
*(_QWORD *)a1 = v8;
result = ddGradient_set((__int64 *)a1, v9, a2, v3);
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void
ddGradient_add(ddGradient* g, ddColor color, UInt8 ratio)
{
 if ( g->nGrads > 0 && ratio == g->entries[g->nGrads-1].ratio )
 {
  ddGradient_set(g, g->nGrads-1, color, ratio);
  return;
 }
 g->entries = realloc((g->entries),(sizeof(struct _ddGradEntry) * (g->nGrads + 1)));
 ddGradient_set(g, g->nGrads, color, ratio);
 ++g->nGrads;
}

canonical_original_code:
void ddGradient_add(struct _ddGradient *g, unsigned int color, unsigned char ratio)
{
 if ( g->nGrads > 0 && ratio == g->entries[g->nGrads-1].ratio )
 {
  ddGradient_set(g, g->nGrads-1, color, ratio);
  return;
 }
 g->entries = realloc((g->entries),(sizeof(struct _ddGradEntry) * (g->nGrads + 1)));
 ddGradient_set(g, g->nGrads, color, ratio);
 ++g->nGrads;
}


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


decompiled_code:
__int64 __fastcall alpha_blend(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // edx
int v4; // eax
int v5; // ecx

result = a1;
v3 = HIBYTE(a1);
if ( HIBYTE(a1) != 255 && HIBYTE(a2) )
{
result = a2;
if ( v3 )
{
v4 = ddColor_scale(a2, 255 - v3);
result = (unsigned int)(v5 + v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // edx
int v4; // eax
int v5; // ecx

result = a1;
v3 = HIBYTE(a1);
if ( HIBYTE(a1) != 255 && HIBYTE(a2) )
{
result = a2;
if ( v3 )
{
v4 = func0(a2, 255 - v3);
result = (unsigned int)(v5 + v4);
}
}
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; } *


decompiled_code:
void __fastcall ddImage_compositeTempBuffer(__int64 a1, __int64 a2, int a3, int a4, int a5)
{
__int64 v5; // r10
unsigned int *v6; // r9
unsigned int *v7; // r10
unsigned int v8; // eax
unsigned int *v9; // r8

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

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2, int a3, int a4, int a5)
{
__int64 v5; // r10
unsigned int *v6; // r9
unsigned int *v7; // r10
unsigned int v8; // eax
unsigned int *v9; // r8

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

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

variable_types: right int

variable_types:
p
unsigned int *

variable_types: x int


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


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

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

variable_types:
color
unsigned int


decompiled_code:
void __fastcall ddImage_blendRect(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
int v4; // er10
__int64 v5; // rbp
unsigned int *v8; // r12
unsigned int v9; // edi
unsigned int *v10; // r8

if ( (_DWORD)a2 != 0x7FFFFFFF )
{
v4 = (int)a3 >> 10;
v5 = a3 >> 42;
if ( (int)a3 >> 10 < a3 >> 42 )
{
do
{
if ( (int)a2 >> 10 < a2 >> 42 )
{
v8 = (unsigned int *)(*(_QWORD *)(a1 + 16) + v4 * *(unsigned __int16 *)(a1 + 8) + 4LL * ((int)a2 >> 10));
do
{
v9 = *v8++;
*(v8 - 1) = alpha_blend(v9, a4);
}
while ( v8 != v10 );
}
++v4;
}
while ( v4 != (_DWORD)v5 );
}
}
}

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


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

variable_types:
p
unsigned char *

variable_types:
end
unsigned char *

variable_types: w int

variable_types: d int


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


decompiled_code:
// attributes: thunk
void __fastcall ddImage_clearRect(__int64 a1, __int64 a2, __int64 a3)
{
ddImage_fillRect_black(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, __int64 a2, __int64 a3)
{
func15(a1, a2, a3);
}

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


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; // rbp
const char *v2; // rax

fputs(a1, stderr);
fwrite(&unk_518, 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; // rbp
const char *v2; // rax

fputs(a1, stderr);
fwrite(&unk_518, 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: scale int


linearGradientRaster

decompiled_code:
__int64 __fastcall linearGradientRaster(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
__int64 v7; // rbx
int v8; // er15
__int64 result; // rax
__int64 v10; // rsi
unsigned __int64 *v11; // r13
_DWORD *v12; // r14
unsigned __int64 v13; // r15
unsigned __int64 v14; // rbx
unsigned int v15; // eax
unsigned __int64 v16; // rbx
unsigned int v17; // eax
unsigned int v18; // ecx
_QWORD *v19; // r12
_DWORD *v20; // r13
__int64 v21; // rbp
__int64 v22; // rbx
unsigned int v23; // eax
__int64 v24; // [rsp+10h] [rbp-60h]
int v25; // [rsp+18h] [rbp-58h]
int v26; // [rsp+1Ch] [rbp-54h]
unsigned int v27; // [rsp+30h] [rbp-40h] BYREF
int v28[15]; // [rsp+34h] [rbp-3Ch] BYREF

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