decompiled_code:
__int64 __fastcall dist_rect(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ebp
__int64 v4; // r15
int v5; // eax
int v6; // eax
int v7; // er12
__int64 result; // rax
int v9; // [rsp+Ch] [rbp-3Ch]
int v10; // [rsp+Ch] [rbp-3Ch]

v3 = a3;
v4 = a3 >> 32;
v9 = dist_line_xy(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a2));
v5 = dist_line_xy(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a2, v4);
if ( v9 <= v5 )
v5 = v9;
v10 = v5;
v6 = dist_line_xy(a1, SHIDWORD(a1), a2, v4, v3, v4);
v7 = v10;
if ( v10 > v6 )
v7 = v6;
result = dist_line_xy(a1, SHIDWORD(a1), v3, SHIDWORD(a2), v3, v4);
if ( v7 <= (int)result )
result = (unsigned int)v7;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ebp
__int64 v4; // r15
int v5; // eax
int v6; // eax
int v7; // er12
__int64 result; // rax
int v9; // [rsp+Ch] [rbp-3Ch]
int v10; // [rsp+Ch] [rbp-3Ch]

v3 = a3;
v4 = a3 >> 32;
v9 = func2(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a2));
v5 = func2(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a2, v4);
if ( v9 <= v5 )
v5 = v9;
v10 = v5;
v6 = func2(a1, SHIDWORD(a1), a2, v4, v3, v4);
v7 = v10;
if ( v10 > v6 )
v7 = v6;
result = func2(a1, SHIDWORD(a1), v3, SHIDWORD(a2), v3, v4);
if ( v7 <= (int)result )
result = (unsigned int)v7;
return result;
}

original_code:
unit_type dist_rect(struct coord p, struct coord a, struct coord b)
{
 unit_type d_min, d;
 d_min = dist_line_xy(p.x, p.y, a.x, a.y, b.x, a.y);
 d = dist_line_xy(p.x, p.y, a.x, a.y, a.x, b.y);
 if (d < d_min)
  d_min = d;
 d = dist_line_xy(p.x, p.y, a.x, b.y, b.x, b.y);
 if (d < d_min)
  d_min = d;
 d = dist_line_xy(p.x, p.y, b.x, a.y, b.x, b.y);
 if (d < d_min)
  d_min = d;
 return d_min;
}

canonical_original_code:
int dist_rect(struct coord p, struct coord a, struct coord b)
{
 int d_min; int d;
 d_min = dist_line_xy(p.x, p.y, a.x, a.y, b.x, a.y);
 d = dist_line_xy(p.x, p.y, a.x, a.y, a.x, b.y);
 if (d < d_min)
  d_min = d;
 d = dist_line_xy(p.x, p.y, a.x, b.y, b.x, b.y);
 if (d < d_min)
  d_min = d;
 d = dist_line_xy(p.x, p.y, b.x, a.y, b.x, b.y);
 if (d < d_min)
  d_min = d;
 return d_min;
}

variable_types: d int


repo: bert/fped

decompiled_code:
_BOOL8 __fastcall inside_rect(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax
__int64 v4; // [rsp+0h] [rbp-20h] BYREF
__int64 v5; // [rsp+8h] [rbp-18h] BYREF

v5 = a2;
v4 = a3;
sort_coord((int *)&v5, (int *)&v4);
result = 0LL;
if ( (int)v5 <= (int)a1 && (int)v4 >= (int)a1 && SHIDWORD(v5) <= SHIDWORD(a1) )
result = SHIDWORD(v4) >= SHIDWORD(a1);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func18(__int64 a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax
__int64 v4; // [rsp+0h] [rbp-20h] BYREF
__int64 v5; // [rsp+8h] [rbp-18h] BYREF

v5 = a2;
v4 = a3;
func14((int *)&v5, (int *)&v4);
result = 0LL;
if ( (int)v5 <= (int)a1 && (int)v4 >= (int)a1 && SHIDWORD(v5) <= SHIDWORD(a1) )
result = SHIDWORD(v4) >= SHIDWORD(a1);
return result;
}

original_code:
int inside_rect(struct coord p, struct coord a, struct coord b)
{
 sort_coord(&a, &b);
 if (p.x < a.x || p.x > b.x)
  return 0;
 if (p.y < a.y || p.y > b.y)
  return 0;
 return 1;
}

variable_types:
p
struct coord { int x; }

variable_types:
a
struct coord

variable_types:
b
struct coord

return_type: int


decompiled_code:
__int64 __fastcall dist_circle(__int64 a1, __int64 a2, int a3)
{
return (unsigned int)(int)COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)((int)hypot(
(double)((int)a1 - (int)a2),
(double)(HIDWORD(a1) - HIDWORD(a2)))
- a3)) & LC9);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2, int a3)
{
return (unsigned int)(int)COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)((int)hypot(
(double)((int)a1 - (int)a2),
(double)(HIDWORD(a1) - HIDWORD(a2)))
- a3)) & LC9);
}

original_code:
unit_type dist_circle(struct coord p, struct coord c, unit_type r)
{
 unit_type d;
 d = hypot(p.x-c.x, p.y-c.y);
 return fabs(d-r);
}

canonical_original_code:
int dist_circle(struct coord p, struct coord c, int r)
{
 int d;
 d = hypot(p.x-c.x, p.y-c.y);
 return fabs(d-r);
}

variable_types:
c
struct coord

variable_types: r int


decompiled_code:
__int64 __fastcall units_to_kicad(int a1)
{
return (unsigned int)(int)((double)a1 / 25.4);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(int)((double)a1 / 25.4);
}

original_code:
static inline int units_to_kicad(unit_type u)
{
 return (double) u/((25.4*10)/10.0);
}

canonical_original_code:
static inline int units_to_kicad(int u)
{
 return (double) u/((25.4*10)/10.0);
}

variable_types: u int


zeroize

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

result = a1;
if ( ((a1 + 1) & 0xFFFFFFFD) == 0 )
result = 0LL;
return result;
}

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

result = a1;
if ( ((a1 + 1) & 0xFFFFFFFD) == 0 )
result = 0LL;
return result;
}

original_code:
static unit_type zeroize(unit_type n)
{
 return n == -1 || n == 1 ? 0 : n;
}

canonical_original_code:
static int zeroize(int n)
{
 return n == -1 || n == 1 ? 0 : n;
}

variable_types: n int


decompiled_code:
__int64 __fastcall kicad_centric(__int64 a1, __int64 a2, int *a3, _DWORD *a4)
{
int v6; // edx
int v7; // eax
__int64 result; // rax
int v9; // [rsp+0h] [rbp-38h] BYREF
int v10; // [rsp+4h] [rbp-34h]
int v11; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch]

v11 = units_to_kicad(a1);
v12 = units_to_kicad(SHIDWORD(a1));
v9 = units_to_kicad(a2);
v10 = units_to_kicad(SHIDWORD(a2));
sort_coord(&v11, &v9);
v6 = v9;
*a4 = v9 - v11;
v7 = v10;
a4[1] = v10 - v12;
*a3 = (v11 + v6) / 2;
result = (unsigned int)(-(v12 + v7) / 2);
a3[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int *a3, _DWORD *a4)
{
int v6; // edx
int v7; // eax
__int64 result; // rax
int v9; // [rsp+0h] [rbp-38h] BYREF
int v10; // [rsp+4h] [rbp-34h]
int v11; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch]

v11 = func0(a1);
v12 = func0(SHIDWORD(a1));
v9 = func0(a2);
v10 = func0(SHIDWORD(a2));
sort_coord(&v11, &v9);
v6 = v9;
*a4 = v9 - v11;
v7 = v10;
a4[1] = v10 - v12;
*a3 = (v11 + v6) / 2;
result = (unsigned int)(-(v12 + v7) / 2);
a3[1] = result;
return result;
}

original_code:
static void kicad_centric(struct coord a, struct coord b,
    struct coord *center, struct coord *size)
{
 struct coord min, max;
 min.x = units_to_kicad(a.x);
 min.y = units_to_kicad(a.y);
 max.x = units_to_kicad(b.x);
 max.y = units_to_kicad(b.y);
 sort_coord(&min, &max);
 size->x = max.x-min.x;
 size->y = max.y-min.y;
 center->x = (min.x+max.x)/2;
 center->y = -(min.y+max.y)/2;
}

canonical_original_code:
static void kicad_centric(struct coord a, struct coord b, struct coord *center, struct coord *size)
{
 struct coord min; struct coord max;
 min.x = units_to_kicad(a.x);
 min.y = units_to_kicad(a.y);
 max.x = units_to_kicad(b.x);
 max.y = units_to_kicad(b.y);
 sort_coord(&min, &max);
 size->x = max.x-min.x;
 size->y = max.y-min.y;
 center->x = (min.x+max.x)/2;
 center->y = -(min.y+max.y)/2;
}

variable_types:
a
struct coord { int x; }

variable_types:
center
struct coord *

variable_types:
size
struct coord *

variable_types:
min
struct coord { int x; }

variable_types:
max
struct coord { int x; }

return_type: void


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

if ( a5 == 1 )
{
result = 0LL;
if ( (int)a3 - a2 < (int)a1
&& a2 + (int)a4 > (int)a1
&& HIDWORD(a3) - a2 < SHIDWORD(a1)
&& a2 + HIDWORD(a4) > SHIDWORD(a1) )
{
goto LABEL_4;
}
}
else
{
result = 0LL;
if ( (int)a3 - a2 <= (int)a1 && a2 + (int)a4 >= (int)a1 )
{
LABEL_4:
result = 0LL;
if ( HIDWORD(a3) - a2 <= SHIDWORD(a1) )
result = HIDWORD(a4) + a2 >= SHIDWORD(a1);
return result;
}
}
return result;
}

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

if ( a5 == 1 )
{
result = 0LL;
if ( (int)a3 - a2 < (int)a1
&& a2 + (int)a4 > (int)a1
&& HIDWORD(a3) - a2 < SHIDWORD(a1)
&& a2 + HIDWORD(a4) > SHIDWORD(a1) )
{
goto LABEL_4;
}
}
else
{
result = 0LL;
if ( (int)a3 - a2 <= (int)a1 && a2 + (int)a4 >= (int)a1 )
{
LABEL_4:
result = 0LL;
if ( HIDWORD(a3) - a2 <= SHIDWORD(a1) )
result = HIDWORD(a4) + a2 >= SHIDWORD(a1);
return result;
}
}
return result;
}

original_code:
static int circle_rect_overlap(struct coord c, unit_type r,
    struct coord min, struct coord max, enum allow_overlap allow)
{
 if (allow == ao_touch) {
  if (c.x <= min.x-r || c.x >= max.x+r)
   return 0;
  if (c.y <= min.y-r || c.y >= max.y+r)
   return 0;
 }
 if (c.x < min.x-r || c.x > max.x+r)
  return 0;
 if (c.y < min.y-r || c.y > max.y+r)
  return 0;
 return 1;
}

canonical_original_code:
static int circle_rect_overlap(struct coord c, int r, struct coord min, struct coord max, enum allow_overlap allow)
{
 if (allow == ao_touch) {
  if (c.x <= min.x-r || c.x >= max.x+r)
   return 0;
  if (c.y <= min.y-r || c.y >= max.y+r)
   return 0;
 }
 if (c.x < min.x-r || c.x > max.x+r)
  return 0;
 if (c.y < min.y-r || c.y > max.y+r)
  return 0;
 return 1;
}

variable_types:
c
struct coord { int x; }

variable_types:
min
struct coord

variable_types:
max
struct coord

variable_types: enum allow_overlap { ao_none=0, ao_touch=1, ao_any=2 }


decompiled_code:
_BOOL8 __fastcall rect_rect_overlap(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
if ( a5 == 1
&& (SHIDWORD(a2) <= SHIDWORD(a3) || (int)a2 <= (int)a3 || (int)a1 >= (int)a4 || SHIDWORD(a1) >= SHIDWORD(a4)) )
{
return 0LL;
}
if ( (int)a1 > (int)a4 || (int)a2 < (int)a3 )
return 0LL;
return SHIDWORD(a2) >= SHIDWORD(a3) && SHIDWORD(a1) <= SHIDWORD(a4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
if ( a5 == 1
&& (SHIDWORD(a2) <= SHIDWORD(a3) || (int)a2 <= (int)a3 || (int)a1 >= (int)a4 || SHIDWORD(a1) >= SHIDWORD(a4)) )
{
return 0LL;
}
if ( (int)a1 > (int)a4 || (int)a2 < (int)a3 )
return 0LL;
return SHIDWORD(a2) >= SHIDWORD(a3) && SHIDWORD(a1) <= SHIDWORD(a4);
}

original_code:
static int rect_rect_overlap(struct coord min1, struct coord max1,
    struct coord min2, struct coord max2, enum allow_overlap allow)
{
 if (allow == ao_touch) {
  if (max1.x <= min2.x || max2.x <= min1.x)
   return 0;
  if (max1.y <= min2.y || max2.y <= min1.y)
   return 0;
 }
 if (max1.x < min2.x || max2.x < min1.x)
  return 0;
 if (max1.y < min2.y || max2.y < min1.y)
  return 0;
 return 1;
}

user_defined_types: enum allow_overlap { ao_none=0, ao_touch=1, ao_any=2 }


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

if ( a5 == 1 )
result = (int)dist_point(a1, a3) < a4 + a2;
else
result = (int)dist_point(a1, a3) <= a4 + a2;
return result;
}

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

if ( a5 == 1 )
result = (int)dist_point(a1, a3) < a4 + a2;
else
result = (int)dist_point(a1, a3) <= a4 + a2;
return result;
}

original_code:
static int circle_circle_overlap(struct coord c1, unit_type r1,
    struct coord c2, unit_type r2, enum allow_overlap allow)
{
 if (allow == ao_touch)
  return dist_point(c1, c2) < r1+r2;
 return dist_point(c1, c2) <= r1+r2;
}

canonical_original_code:
static int circle_circle_overlap(struct coord c1, int r1, struct coord c2, int r2, enum allow_overlap allow)
{
 if (allow == ao_touch)
  return dist_point(c1, c2) < r1+r2;
 return dist_point(c1, c2) <= r1+r2;
}


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

if ( *(_DWORD *)a1 )
{
if ( *(_DWORD *)a2 )
result = circle_circle_overlap(
*(_QWORD *)(a1 + 4),
*(_DWORD *)(a1 + 12),
*(_QWORD *)(a2 + 4),
*(_DWORD *)(a2 + 12),
a3);
else
result = shapes_overlap(a2, a1, a3, a4, (unsigned int)a3);
}
else if ( *(_DWORD *)a2 )
{
result = circle_rect_overlap(
*(_QWORD *)(a2 + 4),
*(_DWORD *)(a2 + 12),
*(_QWORD *)(a1 + 16),
*(_QWORD *)(a1 + 24),
a3);
}
else
{
result = rect_rect_overlap(
*(_QWORD *)(a1 + 16),
*(_QWORD *)(a1 + 24),
*(_QWORD *)(a2 + 16),
*(_QWORD *)(a2 + 24),
a3);
}
return result;
}

original_code:
static int shapes_overlap(const struct shape *a, const struct shape *b,
    enum allow_overlap allow)
{
 if (a->circle && !b->circle)
  return shapes_overlap(b, a, allow);
 if (a->circle)
  return circle_circle_overlap(a->center, a->r, b->center, b->r,
      allow);
 if (b->circle)
  return circle_rect_overlap(b->center, b->r, a->min, a->max,
      allow);
 return rect_rect_overlap(a->min, a->max, b->min, b->max, allow);
}

canonical_original_code:
static int shapes_overlap(struct shape *a, struct shape *b, enum allow_overlap allow)
{
 if (a->circle && !b->circle)
  return shapes_overlap(b, a, allow);
 if (a->circle)
  return circle_circle_overlap(a->center, a->r, b->center, b->r,
      allow);
 if (b->circle)
  return circle_rect_overlap(b->center, b->r, a->min, a->max,
      allow);
 return rect_rect_overlap(a->min, a->max, b->min, b->max, allow);
}

variable_types: struct shape { int circle; struct coord { int x; } center; int r; struct coord min; } *

variable_types:
b
struct shape *

user_defined_types: struct shape { int circle; struct coord center; int r; struct coord min; }


decompiled_code:
__int64 __fastcall units_to_pcb(int a1)
{
return (unsigned int)(int)((double)a1 / 2.54);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(int)((double)a1 / 2.54);
}

original_code:
static inline int units_to_pcb(unit_type u)
{
 return (double) u/((25.4*10)/100.0);
}

canonical_original_code:
static inline int units_to_pcb(int u)
{
 return (double) u/((25.4*10)/100.0);
}


decompiled_code:
__int64 __fastcall pcb_centric(__int64 a1, __int64 a2, int *a3, _DWORD *a4)
{
int v6; // edx
int v7; // eax
__int64 result; // rax
int v9; // [rsp+0h] [rbp-38h] BYREF
int v10; // [rsp+4h] [rbp-34h]
int v11; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch]

v11 = units_to_pcb(a1);
v12 = units_to_pcb(SHIDWORD(a1));
v9 = units_to_pcb(a2);
v10 = units_to_pcb(SHIDWORD(a2));
sort_coord(&v11, &v9);
v6 = v9;
*a4 = v9 - v11;
v7 = v10;
a4[1] = v10 - v12;
*a3 = (v11 + v6) / 2;
result = (unsigned int)(-(v12 + v7) / 2);
a3[1] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, int *a3, _DWORD *a4)
{
int v6; // edx
int v7; // eax
__int64 result; // rax
int v9; // [rsp+0h] [rbp-38h] BYREF
int v10; // [rsp+4h] [rbp-34h]
int v11; // [rsp+8h] [rbp-30h] BYREF
int v12; // [rsp+Ch] [rbp-2Ch]

v11 = func0(a1);
v12 = func0(SHIDWORD(a1));
v9 = func0(a2);
v10 = func0(SHIDWORD(a2));
sort_coord(&v11, &v9);
v6 = v9;
*a4 = v9 - v11;
v7 = v10;
a4[1] = v10 - v12;
*a3 = (v11 + v6) / 2;
result = (unsigned int)(-(v12 + v7) / 2);
a3[1] = result;
return result;
}

original_code:
static void
pcb_centric
(
        struct coord a,
        struct coord b,
        struct coord *center,
        struct coord *size
)
{
        struct coord min;
        struct coord max;
        min.x = units_to_pcb (a.x);
        min.y = units_to_pcb (a.y);
        max.x = units_to_pcb (b.x);
        max.y = units_to_pcb (b.y);
        sort_coord (&min, &max);
        size->x = max.x - min.x;
        size->y = max.y - min.y;
        center->x = (min.x + max.x) / 2;
        center->y = -(min.y + max.y) / 2;
}

canonical_original_code:
static void pcb_centric(struct coord a, struct coord b, struct coord *center, struct coord *size)
{
        struct coord min;
        struct coord max;
        min.x = units_to_pcb (a.x);
        min.y = units_to_pcb (a.y);
        max.x = units_to_pcb (b.x);
        max.y = units_to_pcb (b.y);
        sort_coord (&min, &max);
        size->x = max.x - min.x;
        size->y = max.y - min.y;
        center->x = (min.x + max.x) / 2;
        center->y = -(min.y + max.y) / 2;
}


decompiled_code:
_BOOL8 __fastcall lt_x(int a1, int a2)
{
return a1 < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2)
{
return a1 < a2;
}

original_code:
int lt_x(struct coord a, struct coord b)
{
 return a.x < b.x;
}


decompiled_code:
_BOOL8 __fastcall lt_y(__int64 a1, __int64 a2)
{
return SHIDWORD(a1) < SHIDWORD(a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
return SHIDWORD(a1) < SHIDWORD(a2);
}

original_code:
int lt_y(struct coord a, struct coord b)
{
 return a.y < b.y;
}


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

result = 1LL;
if ( SHIDWORD(a2) <= SHIDWORD(a1) )
{
result = 0LL;
if ( HIDWORD(a2) == HIDWORD(a1) )
result = (int)a1 < (int)a2;
}
return result;
}

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

result = 1LL;
if ( SHIDWORD(a2) <= SHIDWORD(a1) )
{
result = 0LL;
if ( HIDWORD(a2) == HIDWORD(a1) )
result = (int)a1 < (int)a2;
}
return result;
}

original_code:
int lt_xy(struct coord a, struct coord b)
{
 return a.y < b.y || (a.y == b.y && a.x < b.x);
}


closer

decompiled_code:
_BOOL8 __fastcall closer(int a1, int a2)
{
signed int v2; // edx
signed int v3; // eax
_BOOL4 v4; // ecx

v2 = abs32(a1);
v3 = abs32(a2);
v4 = 1;
if ( v2 >= v3 )
{
v4 = 0;
if ( v2 <= v3 )
v4 = a1 > a2;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1, int a2)
{
signed int v2; // edx
signed int v3; // eax
_BOOL4 v4; // ecx

v2 = abs32(a1);
v3 = abs32(a2);
v4 = 1;
if ( v2 >= v3 )
{
v4 = 0;
if ( v2 <= v3 )
v4 = a1 > a2;
}
return v4;
}

original_code:
static int closer(int da, int db)
{
 int abs_a, abs_b;
 abs_a = da < 0 ? -da : da;
 abs_b = db < 0 ? -db : db;
 if (abs_a < abs_b)
  return 1;
 if (abs_a > abs_b)
  return 0;
 return da > db;
}

canonical_original_code:
static int closer(int da, int db)
{
 int abs_a; int abs_b;
 abs_a = da < 0 ? -da : da;
 abs_b = db < 0 ? -db : db;
 if (abs_a < abs_b)
  return 1;
 if (abs_a > abs_b)
  return 0;
 return da > db;
}

variable_types: da int

variable_types: db int


decompiled_code:
__int64 __fastcall better_next(_BOOL8 (__fastcall *a1)(__int64 a1, __int64 a2), __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // ebx
_BOOL4 v7; // eax

if ( !a1(a2, a3) )
return 1;
v6 = a1(a2, a4);
if ( v6 )
{
v6 = a1(a4, a3);
if ( v6 )
{
v6 = 1;
}
else
{
v7 = a1(a3, a4);
if ( a1 != lt_xy && !v7 )
{
if ( a1 )
{
if ( a1 != lt_y )
abort();
v6 = closer((int)a4 - (int)a2, (int)a3 - (int)a2);
}
else
{
v6 = closer(HIDWORD(a4) - HIDWORD(a2), HIDWORD(a3) - HIDWORD(a2));
}
}
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BOOL8 (__fastcall *a1)(__int64 a1, __int64 a2), __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // ebx
_BOOL4 v7; // eax

if ( !a1(a2, a3) )
return 1;
v6 = a1(a2, a4);
if ( v6 )
{
v6 = a1(a4, a3);
if ( v6 )
{
v6 = 1;
}
else
{
v7 = a1(a3, a4);
if ( a1 != lt_xy && !v7 )
{
if ( a1 )
{
if ( a1 != lt_y )
abort();
v6 = func3((int)a4 - (int)a2, (int)a3 - (int)a2);
}
else
{
v6 = func3(HIDWORD(a4) - HIDWORD(a2), HIDWORD(a3) - HIDWORD(a2));
}
}
}
}
return v6;
}

original_code:
static int better_next(lt_op_type lt,
    struct coord a0, struct coord b0, struct coord b)
{
 if (!lt(a0, b0))
  return 1;
 if (!lt(a0, b))
  return 0;
 if (lt(b, b0))
  return 1;
 if (lt(b0, b))
  return 0;
 if (lt == lt_xy)
  return 0;
 if (lt == lt_x)
  return closer(b.y-a0.y, b0.y-a0.y);
 if (lt == lt_y)
  return closer(b.x-a0.x, b0.x-a0.x);
 abort();
}

canonical_original_code:
static int better_next(int (*lt)(struct coord a, struct coord b), struct coord a0, struct coord b0, struct coord b)
{
 if (!lt(a0, b0))
  return 1;
 if (!lt(a0, b))
  return 0;
 if (lt(b, b0))
  return 1;
 if (lt(b0, b))
  return 0;
 if (lt == lt_xy)
  return 0;
 if (lt == lt_x)
  return closer(b.y-a0.y, b0.y-a0.y);
 if (lt == lt_y)
  return closer(b.x-a0.x, b0.x-a0.x);
 abort();
}

variable_types: int (*)(struct coord { int x; } a, struct coord b)

variable_types:
b
struct coord


decompiled_code:
__int64 __fastcall pad_type_to_layers(int a1)
{
__int64 result; // rax
int v2; // eax

switch ( a1 )
{
case 0:
v2 = 0x80000;
goto LABEL_4;
case 1:
v2 = 0;
LABEL_4:
result = v2 | 0x808000u;
break;
case 2:
result = 0x8000LL;
break;
case 3:
result = 0x80000LL;
break;
case 4:
result = 0x800000LL;
break;
default:
abort();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 result; // rax
int v2; // eax

switch ( a1 )
{
case 0:
v2 = 0x80000;
goto LABEL_4;
case 1:
v2 = 0;
LABEL_4:
result = v2 | 0x808000u;
break;
case 2:
result = 0x8000LL;
break;
case 3:
result = 0x80000LL;
break;
case 4:
result = 0x800000LL;
break;
default:
abort();
}
return result;
}

original_code:
layer_type pad_type_to_layers(enum pad_type type)
{
 layer_type layers = 0;
 switch (type) {
 case pt_normal:
  layers = (1 << layer_paste_top);
 case pt_bare:
  layers |= (1 << layer_top) | (1 << layer_mask_top);
  break;
 case pt_trace:
  layers = (1 << layer_top);
  break;
 case pt_paste:
  layers = (1 << layer_paste_top);
  break;
 case pt_mask:
  layers = (1 << layer_mask_top);
  break;
 default:
  abort();
 }
 return layers;
}

canonical_original_code:
unsigned int pad_type_to_layers(enum pad_type type)
{
 unsigned int layers = 0;
 switch (type) {
 case pt_normal:
  layers = (1 << layer_paste_top);
 case pt_bare:
  layers |= (1 << layer_top) | (1 << layer_mask_top);
  break;
 case pt_trace:
  layers = (1 << layer_top);
  break;
 case pt_paste:
  layers = (1 << layer_paste_top);
  break;
 case pt_mask:
  layers = (1 << layer_mask_top);
  break;
 default:
  abort();
 }
 return layers;
}

variable_types: enum pad_type { pt_normal=0, pt_bare=1, pt_trace=2, pt_paste=3, pt_mask=4, pt_n=5 }

variable_types:
layers
unsigned int

return_type: unsigned int


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

if ( (a1 & 0x8000) != 0 )
{
result = 0LL;
if ( (a1 & 0x80000) == 0 )
result = (unsigned int)((a1 & 0x800000) == 0) + 1;
}
else if ( (a1 & 0x80000) != 0 )
{
result = 3LL;
}
else
{
if ( (a1 & 0x800000) == 0 )
abort();
result = 4LL;
}
return result;
}

original_code:
enum pad_type layers_to_pad_type(layer_type layers)
{
 if (layers & (1 << layer_top)) {
  if (layers & (1 << layer_paste_top))
   return pt_normal;
  if (layers & (1 << layer_mask_top))
   return pt_bare;
  return pt_trace;
 } else {
  if (layers & (1 << layer_paste_top))
   return pt_paste;
  if (layers & (1 << layer_mask_top))
   return pt_mask;
  abort();
 }
}

canonical_original_code:
enum pad_type layers_to_pad_type(unsigned int layers)
{
 if (layers & (1 << layer_top)) {
  if (layers & (1 << layer_paste_top))
   return pt_normal;
  if (layers & (1 << layer_mask_top))
   return pt_bare;
  return pt_trace;
 } else {
  if (layers & (1 << layer_paste_top))
   return pt_paste;
  if (layers & (1 << layer_mask_top))
   return pt_mask;
  abort();
 }
}

return_type: enum pad_type { pt_normal=0, pt_bare=1, pt_trace=2, pt_paste=3, pt_mask=4, pt_n=5 }


decompiled_code:
const char *__fastcall pad_type_name(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "normal";
break;
case 1:
result = "bare";
break;
case 2:
result = "trace";
break;
case 3:
result = "paste";
break;
case 4:
result = "mask";
break;
default:
abort();
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "normal";
break;
case 1:
result = "bare";
break;
case 2:
result = "trace";
break;
case 3:
result = "paste";
break;
case 4:
result = "mask";
break;
default:
abort();
}
return result;
}

original_code:
const char *pad_type_name(enum pad_type type)
{
 switch (type) {
 case pt_normal:
  return "normal";
 case pt_bare:
  return "bare";
 case pt_trace:
  return "trace";
 case pt_paste:
  return "paste";
 case pt_mask:
  return "mask";
 default:
  abort();
 }
}

return_type: char *

user_defined_types: enum pad_type { pt_normal=0, pt_bare=1, pt_trace=2, pt_paste=3, pt_mask=4, pt_n=5 }


decompiled_code:
__int64 mech_hole_layers()
{
return 12582912LL;
}

original_code:
layer_type mech_hole_layers(void)
{
 return (1 << layer_mask_top) | (1 << layer_mask_bottom);
}

canonical_original_code:
unsigned int mech_hole_layers()
{
 return (1 << layer_mask_top) | (1 << layer_mask_bottom);
}


decompiled_code:
__int64 gui_cleanup_style()
{
return pango_font_description_free(item_list_font);
}

canonical_decompiled_code:
__int64 func3()
{
return pango_font_description_free(item_list_font);
}

original_code:
void gui_cleanup_style(void)
{
 pango_font_description_free(item_list_font);
}

canonical_original_code:
void gui_cleanup_style()
{
 pango_font_description_free(item_list_font);
}


decompiled_code:
__int64 __fastcall mm_to_units(double a1)
{
return (unsigned int)(int)(a1 * 10000.0);
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1)
{
return (unsigned int)(int)(a1 * 10000.0);
}

original_code:
static inline unit_type mm_to_units(double mm)
{
 return mm*(1000.0*10);
}

canonical_original_code:
static inline int mm_to_units(double mm)
{
 return mm*(1000.0*10);
}

variable_types: mm double


decompiled_code:
_BOOL8 __fastcall parse_scaling(char *nptr)
{
char *v1; // rax
char *v2; // rbx
double v3; // xmm0_8
_BOOL8 result; // rax
double v5; // xmm0_8
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = strchr(nptr, 120);
if ( v1 )
{
v2 = v1;
if ( nptr == v1
|| (v3 = strtod(nptr, endptr),
*(double *)&postscript_params[1] = (double)(int)mm_to_units(v3),
result = 0LL,
*endptr[0] == 120) )
{
result = 1LL;
if ( v2[1] )
{
v5 = strtod(v2 + 1, endptr);
*(double *)&postscript_params[2] = (double)(int)mm_to_units(v5);
result = *endptr[0] == 0;
}
}
}
else
{
postscript_params[0] = strtod(nptr, endptr);
result = *endptr[0] == 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *nptr)
{
char *v1; // rax
char *v2; // rbx
double v3; // xmm0_8
_BOOL8 result; // rax
double v5; // xmm0_8
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = strchr(nptr, 120);
if ( v1 )
{
v2 = v1;
if ( nptr == v1
|| (v3 = strtod(nptr, endptr),
*(double *)&postscript_params[1] = (double)(int)func0(v3),
result = 0LL,
*endptr[0] == 120) )
{
result = 1LL;
if ( v2[1] )
{
v5 = strtod(v2 + 1, endptr);
*(double *)&postscript_params[2] = (double)(int)func0(v5);
result = *endptr[0] == 0;
}
}
}
else
{
postscript_params[0] = strtod(nptr, endptr);
result = *endptr[0] == 0;
}
return result;
}

original_code:
static int parse_scaling(const char *arg)
{
 const char *x;
 char *end;
 x = strchr(arg, 'x');
 if (!x) {
  postscript_params.zoom = strtod(arg, &end);
  return !*end;
 }
 if (x != arg) {
  postscript_params.max_width = mm_to_units(strtod(arg, &end));
  if (*end != 'x')
   return 0;
 }
 if (x[1]) {
  postscript_params.max_height = mm_to_units(strtod(x+1, &end));
  if (*end)
   return 0;
 }
 return 1;
}

canonical_original_code:
static int parse_scaling(char *arg)
{
 char *x;
 char *end;
 x = strchr(arg, 'x');
 if (!x) {
  postscript_params.zoom = strtod(arg, &end);
  return !*end;
 }
 if (x != arg) {
  postscript_params.max_width = mm_to_units(strtod(arg, &end));
  if (*end != 'x')
   return 0;
 }
 if (x[1]) {
  postscript_params.max_height = mm_to_units(strtod(x+1, &end));
  if (*end)
   return 0;
 }
 return 1;
}

variable_types:
arg
char *

variable_types:
x
char *

variable_types:
end
char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"usage: %s [batch_mode] [cpp_option ...] [in_file [out_file]]\n"
"\n"
"Batch mode options:\n"
" -g [-1 package]\n"
" write gnuplot output, then exit\n"
" -k write KiCad output, then exit\n"
" -p write Postscript output, then exit\n"
" -P [-K] [-s scale] [-1 package]\n"
" write Postscript output (full page), then exit\n"
" -T test mode. Load file, then exit\n"
" -T -T test mode. Load file, dump to stdout, then exit\n"
"\n"
"Common options:\n"
" -1 name output only the specified package\n"
" -K show the pad type key\n"
" -s scale scale factor for -P (default: auto-scale)\n"
" -s [width]x[heigth]\n"
" auto-scale to fit within specified box. Dimensions in mm.\n"
" cpp_option -Idir, -Dname[=value], or -Uname\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(
stderr,
"usage: %s [batch_mode] [cpp_option ...] [in_file [out_file]]\n"
"\n"
"Batch mode options:\n"
" -g [-1 package]\n"
" write gnuplot output, then exit\n"
" -k write KiCad output, then exit\n"
" -p write Postscript output, then exit\n"
" -P [-K] [-s scale] [-1 package]\n"
" write Postscript output (full page), then exit\n"
" -T test mode. Load file, then exit\n"
" -T -T test mode. Load file, dump to stdout, then exit\n"
"\n"
"Common options:\n"
" -1 name output only the specified package\n"
" -K show the pad type key\n"
" -s scale scale factor for -P (default: auto-scale)\n"
" -s [width]x[heigth]\n"
" auto-scale to fit within specified box. Dimensions in mm.\n"
" cpp_option -Idir, -Dname[=value], or -Uname\n",
a1);
exit(1);
}

original_code:
static void usage(const char *name)
{
 fprintf(stderr,
"usage: %s [batch_mode] [cpp_option ...] [in_file [out_file]]\n\n"
"Batch mode options:\n"
"  -g [-1 package]\n"
"              write gnuplot output, then exit\n"
"  -k          write KiCad output, then exit\n"
"  -p          write Postscript output, then exit\n"
"  -P [-K] [-s scale] [-1 package]\n"
"              write Postscript output (full page), then exit\n"
"  -T          test mode. Load file, then exit\n"
"  -T -T       test mode. Load file, dump to stdout, then exit\n\n"
"Common options:\n"
"  -1 name     output only the specified package\n"
"  -K          show the pad type key\n"
"  -s scale    scale factor for -P (default: auto-scale)\n"
"  -s [width]x[heigth]\n"
"              auto-scale to fit within specified box. Dimensions in mm.\n"
"  cpp_option  -Idir, -Dname[=value], or -Uname\n"
    , name);
 exit(1);
}

canonical_original_code:
static void usage(char *name)
{
 fprintf(stderr,
"usage: %s [batch_mode] [cpp_option ...] [in_file [out_file]]\n\n"
"Batch mode options:\n"
"  -g [-1 package]\n"
"              write gnuplot output, then exit\n"
"  -k          write KiCad output, then exit\n"
"  -p          write Postscript output, then exit\n"
"  -P [-K] [-s scale] [-1 package]\n"
"              write Postscript output (full page), then exit\n"
"  -T          test mode. Load file, then exit\n"
"  -T -T       test mode. Load file, dump to stdout, then exit\n\n"
"Common options:\n"
"  -1 name     output only the specified package\n"
"  -K          show the pad type key\n"
"  -s scale    scale factor for -P (default: auto-scale)\n"
"  -s [width]x[heigth]\n"
"              auto-scale to fit within specified box. Dimensions in mm.\n"
"  cpp_option  -Idir, -Dname[=value], or -Uname\n"
    , name);
 exit(1);
}

variable_types:
name
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // r15
char *v5; // r14
int v6; // er13
int v7; // ebx
int *v8; // rdi
int v9; // eax
int v10; // ebp
int result; // eax
char *v12; // rax
char v13[3]; // [rsp+9h] [rbp-5Fh] BYREF
int v14; // [rsp+Ch] [rbp-5Ch] BYREF
_QWORD v15[3]; // [rsp+10h] [rbp-58h] BYREF
__int64 v16[8]; // [rsp+28h] [rbp-40h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // r15
char *v5; // r14
int v6; // er13
int v7; // ebx
int *v8; // rdi
int v9; // eax
int v10; // ebp
int result; // eax
char *v12; // rax
char v13[3]; // [rsp+9h] [rbp-5Fh] BYREF
int v14; // [rsp+Ch] [rbp-5Ch] BYREF
_QWORD v15[3]; // [rsp+10h] [rbp-58h] BYREF
__int64 v16[8]; // [rsp+28h] [rbp-40h] BYREF

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


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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
while ( *(_QWORD *)result != a2 )
{
if ( !*(_QWORD *)(result + 16) )
{
v5 = (__int64 *)(result + 16);
goto LABEL_7;
}
result = *(_QWORD *)(result + 16);
}
*(_DWORD *)(result + 8) += a3;
}
else
{
v5 = (__int64 *)(a1 + 8);
LABEL_7:
v6 = malloc(0x18uLL);
if ( !v6 )
abort();
*v5 = (__int64)v6;
*v6 = a2;
*(_DWORD *)(*v5 + 8) = a3;
result = *v5;
*(_QWORD *)(*v5 + 16) = 0LL;
++*(_DWORD *)(a2 + 16);
}
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
while ( *(_QWORD *)result != a2 )
{
if ( !*(_QWORD *)(result + 16) )
{
v5 = (__int64 *)(result + 16);
goto LABEL_7;
}
result = *(_QWORD *)(result + 16);
}
*(_DWORD *)(result + 8) += a3;
}
else
{
v5 = (__int64 *)(a1 + 8);
LABEL_7:
v6 = malloc(0x18uLL);
if ( !v6 )
abort();
*v5 = (__int64)v6;
*v6 = a2;
*(_DWORD *)(*v5 + 8) = a3;
result = *v5;
*(_QWORD *)(*v5 + 16) = 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; } **


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

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

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

result = malloc(0x18uLL);
if ( !result )
abort();
*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

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:
void doit()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
__int64 v3[4]; // [rsp+0h] [rbp-58h] BYREF
unsigned __int8 v4[3]; // [rsp+26h] [rbp-32h] BYREF
unsigned __int8 v5[7]; // [rsp+29h] [rbp-2Fh] BYREF
char v6[24]; // [rsp+30h] [rbp-28h] BYREF
__int64 v7[2]; // [rsp+48h] [rbp-10h] BYREF

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

canonical_decompiled_code:
void func2()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
__int64 v3[4]; // [rsp+0h] [rbp-58h] BYREF
unsigned __int8 v4[3]; // [rsp+26h] [rbp-32h] BYREF
unsigned __int8 v5[7]; // [rsp+29h] [rbp-2Fh] BYREF
char v6[24]; // [rsp+30h] [rbp-28h] BYREF
__int64 v7[2]; // [rsp+48h] [rbp-10h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
v7[0] = 0LL;
v0 = getenv("IBID");
parseHexString(v0, v5, 8LL);
v1 = getenv("IBCHAL");
parseHexString(v1, v4, 3LL);
v2 = getenv("IBSEC");
parseHexString(v2, v7, 8LL);
func0((__int64)v6, 0, (__int64)v3, (unsigned int *)v7, v4, v5);
func1((__int64)v6, 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 *[]


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


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

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
dd_destroyFill(*(_QWORD *)ptr + 40 * v3++);
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

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
dd_destroyFill(*(_QWORD *)ptr + 40 * v3++);
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


decompiled_code:
__int64 __fastcall ddShape_moveTo(__int64 a1, int a2, int a3)
{
char *v4; // rax
__int64 v5; // rax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rdx

v4 = ddShape_addRecord(a1);
*(_DWORD *)v4 = 1;
*((_DWORD *)v4 + 1) = a2;
*((_DWORD *)v4 + 2) = a3;
v5 = ddRect_containPoint(
*(_QWORD *)(a1 + 32),
*(_QWORD *)(a1 + 40),
(unsigned int)(a2 + *(_DWORD *)(a1 + 28) / -2),
(unsigned int)(*(_DWORD *)(a1 + 28) / -2 + a3));
*(_QWORD *)(a1 + 32) = v5;
*(_QWORD *)(a1 + 40) = v6;
result = ddRect_containPoint(
v5,
v6,
(unsigned int)(*(_DWORD *)(a1 + 28) / 2 + a2),
(unsigned int)(*(_DWORD *)(a1 + 28) / 2 + a3));
*(_QWORD *)(a1 + 32) = result;
*(_QWORD *)(a1 + 40) = v8;
return result;
}

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


decompiled_code:
__int64 __fastcall ddShape_lineTo(__int64 a1, int a2, int a3)
{
char *v4; // rax
__int64 v5; // rax
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rdx

v4 = ddShape_addRecord(a1);
*(_DWORD *)v4 = 8;
*((_DWORD *)v4 + 1) = a2;
*((_DWORD *)v4 + 2) = a3;
v5 = ddRect_containPoint(
*(_QWORD *)(a1 + 32),
*(_QWORD *)(a1 + 40),
(unsigned int)(a2 + *(_DWORD *)(a1 + 28) / -2),
(unsigned int)(*(_DWORD *)(a1 + 28) / -2 + a3));
*(_QWORD *)(a1 + 32) = v5;
*(_QWORD *)(a1 + 40) = v6;
result = ddRect_containPoint(
v5,
v6,
(unsigned int)(*(_DWORD *)(a1 + 28) / 2 + a2),
(unsigned int)(*(_DWORD *)(a1 + 28) / 2 + a3));
*(_QWORD *)(a1 + 32) = result;
*(_QWORD *)(a1 + 40) = v8;
return result;
}

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)
{
char *result; // rax

result = *(char **)(a1 + 16);
if ( !result || *(_DWORD *)&result[20 * *(int *)(a1 + 24) - 20] )
{
result = ddShape_addRecord(a1);
*(_DWORD *)result = 0;
}
return result;
}

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

result = *(char **)(a1 + 16);
if ( !result || *(_DWORD *)&result[20 * *(int *)(a1 + 24) - 20] )
{
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:
_DWORD *dd_newUpdateList()
{
_DWORD *result; // rax

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

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

result = malloc(0x10uLL);
*result = 0;
result[1] = 0;
*((_QWORD *)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 v4; // rbx
__int64 result; // rax

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

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

if ( *(int *)(a1 + 4) > 0 )
{
v4 = 0LL;
do
{
result = ddImage_blendRect(
a2,
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v4),
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16 * v4 + 8),
a3);
++v4;
}
while ( *(_DWORD *)(a1 + 4) > (int)v4 );
}
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
__int64 result; // rax

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

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

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

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:
void __fastcall ddUpdateList_makeIntegerRects(__int64 a1)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
__int64 v3; // rdx

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

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)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 v4; // rbx
__int64 v5; // rdx

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

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, int a3)
{
unsigned int v3; // eax
__int64 v4; // r8

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

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

v3 = a3;
v4 = a1 >> 32;
if ( (_DWORD)a1 == 0x7FFFFFFF )
{
v4 = (unsigned int)a3;
}
else
{
if ( a3 <= (int)a1 )
LODWORD(a1) = a3;
if ( a3 >= (int)v4 )
v4 = (unsigned int)a3;
v3 = 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) || (int)a1 > SHIDWORD(a3) || SHIDWORD(a1) < (int)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) || (int)a1 > SHIDWORD(a3) || SHIDWORD(a1) < (int)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)
{
__int64 v4; // rdi

if ( (_DWORD)a1 != 0x7FFFFFFF )
{
if ( *a3 >= (int)a1 )
{
v4 = a1 >> 32;
if ( *a3 > (int)v4 )
*a3 = v4;
}
else
{
*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


decompiled_code:
_DWORD *dd_newGradient()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
result[3] = 0;
return result;
}

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

result = malloc(0x10uLL);
*(_QWORD *)result = 0LL;
result[2] = 0;
result[3] = 0;
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)
{
int v5; // esi
__int64 result; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 > 0 && a3 == *(_WORD *)(*(_QWORD *)a1 + 24LL * v5 - 24) )
return ddGradient_set((_QWORD *)a1, v5 - 1, a2, a3);
*(_QWORD *)a1 = realloc(*(void **)a1, 24LL * (v5 + 1));
result = ddGradient_set((_QWORD *)a1, *(_DWORD *)(a1 + 8), a2, a3);
++*(_DWORD *)(a1 + 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned __int8 a3)
{
int v5; // esi
__int64 result; // rax

v5 = *(_DWORD *)(a1 + 8);
if ( v5 > 0 && a3 == *(_WORD *)(*(_QWORD *)a1 + 24LL * v5 - 24) )
return func3((_QWORD *)a1, v5 - 1, a2, a3);
*(_QWORD *)a1 = realloc(*(void **)a1, 24LL * (v5 + 1));
result = func3((_QWORD *)a1, *(_DWORD *)(a1 + 8), a2, a3);
++*(_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;
}