decompiled_code:
__int64 __fastcall bitset_or(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rsi

result = *a1;
if ( (_DWORD)result != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x76u, "bitset_or");
if ( (_DWORD)result )
{
v3 = *((_QWORD *)a1 + 1);
v4 = *(_QWORD *)(a2 + 8);
result = 0LL;
do
{
*(_DWORD *)(v3 + 4 * result) |= *(_DWORD *)(v4 + 4 * result);
++result;
}
while ( *a1 != (_DWORD)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rsi

result = *a1;
if ( (_DWORD)result != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x76u, "bitset_or");
if ( (_DWORD)result )
{
v3 = *((_QWORD *)a1 + 1);
v4 = *(_QWORD *)(a2 + 8);
result = 0LL;
do
{
*(_DWORD *)(v3 + 4 * result) |= *(_DWORD *)(v4 + 4 * result);
++result;
}
while ( *a1 != (_DWORD)result );
}
return result;
}

original_code:
void bitset_or(struct bitset *a, const struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  a->v[i] |= b->v[i];
}

canonical_original_code:
void bitset_or(struct bitset *a, struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 118, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  a->v[i] |= b->v[i];
}


repo: bert/fped

decompiled_code:
__int64 __fastcall bitset_ge(unsigned int *a1, __int64 a2)
{
__int64 v2; // rcx
__int64 v3; // rdi
__int64 v4; // rsi
__int64 v5; // rdx

v2 = *a1;
if ( (_DWORD)v2 != *(_DWORD *)a2 )
_assert_fail("a->v_n == b->v_n", "bitset.c", 0x80u, "bitset_ge");
if ( !(_DWORD)v2 )
return 1LL;
v3 = *((_QWORD *)a1 + 1);
v4 = *(_QWORD *)(a2 + 8);
v5 = 0LL;
while ( (*(_DWORD *)(v4 + 4 * v5) & ~*(_DWORD *)(v3 + 4 * v5)) == 0 )
{
if ( v2 == ++v5 )
return 1LL;
}
return 0LL;
}

original_code:
int bitset_ge(const struct bitset *a, const struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 128, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  if (~a->v[i] & b->v[i])
   return 0;
 return 1;
}

canonical_original_code:
int bitset_ge(struct bitset *a, struct bitset *b)
{
 int i;
 ((void) sizeof ((a->v_n == b->v_n) ? 1 : 0), __extension__ ({ if (a->v_n == b->v_n) ; else __assert_fail ("a->v_n == b->v_n", "bitset.c", 128, __extension__ __PRETTY_FUNCTION__); }));
 for (i = 0; i != a->v_n; i++)
  if (~a->v[i] & b->v[i])
   return 0;
 return 1;
}

variable_types: struct bitset { int v_n; unsigned int *v; } *

variable_types:
b
struct bitset *

variable_types: i int

return_type: int


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

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

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

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

original_code:
static inline int coord_eq(struct coord a, struct coord b)
{
 return a.x == b.x && a.y == b.y;
}

variable_types:
a
struct coord { int x; }

variable_types:
b
struct coord


decompiled_code:
__int64 meas_highlight_b()
{
return inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

canonical_decompiled_code:
__int64 func2()
{
return inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

original_code:
static void meas_highlight_b(void)
{
 inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

canonical_original_code:
static void meas_highlight_b()
{
 inst_highlight_vecs(meas_pick_vec_b, meas_inst);
}

return_type: void


decompiled_code:
__int64 meas_highlight_a()
{
return inst_highlight_vecs(meas_pick_vec_a, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return inst_highlight_vecs(meas_pick_vec_a, 0LL);
}

original_code:
static void meas_highlight_a(void)
{
 inst_highlight_vecs(meas_pick_vec_a, ((void *)0));
}

canonical_original_code:
static void meas_highlight_a()
{
 inst_highlight_vecs(meas_pick_vec_a, ((void *)0));
}


decompiled_code:
__int64 cancel_drag_new_meas()
{
meas_inst = 0LL;
highlight = 0LL;
return redraw();
}

canonical_decompiled_code:
__int64 func10()
{
meas_inst = 0LL;
highlight = 0LL;
return redraw();
}

original_code:
static void cancel_drag_new_meas(void)
{
 meas_inst = ((void *)0);
 highlight = ((void *)0);
 redraw();
}

canonical_original_code:
static void cancel_drag_new_meas()
{
 meas_inst = ((void *)0);
 highlight = ((void *)0);
 redraw();
}


decompiled_code:
__int64 tool_selected_meas()
{
highlight = meas_highlight_a;
return redraw();
}

canonical_decompiled_code:
__int64 func12()
{
highlight = meas_highlight_a;
return redraw();
}

original_code:
static void tool_selected_meas(void)
{
 highlight = meas_highlight_a;
 redraw();
}

canonical_original_code:
static void tool_selected_meas()
{
 highlight = meas_highlight_a;
 redraw();
}


decompiled_code:
__int64 tool_selected_meas_xy()
{
meas_dsc = (__int64)&meas_dsc_xy;
return tool_selected_meas();
}

canonical_decompiled_code:
__int64 func13()
{
meas_dsc = (__int64)&meas_dsc_xy;
return func12();
}

original_code:
static void tool_selected_meas_xy(void)
{
 meas_dsc = &meas_dsc_xy;
 tool_selected_meas();
}

canonical_original_code:
static void tool_selected_meas_xy()
{
 meas_dsc = &meas_dsc_xy;
 tool_selected_meas();
}


decompiled_code:
__int64 tool_selected_meas_x()
{
meas_dsc = (__int64)&meas_dsc_x;
return tool_selected_meas();
}

canonical_decompiled_code:
__int64 func14()
{
meas_dsc = (__int64)&meas_dsc_x;
return func12();
}

original_code:
static void tool_selected_meas_x(void)
{
 meas_dsc = &meas_dsc_x;
 tool_selected_meas();
}

canonical_original_code:
static void tool_selected_meas_x()
{
 meas_dsc = &meas_dsc_x;
 tool_selected_meas();
}


decompiled_code:
__int64 tool_selected_meas_y()
{
meas_dsc = (__int64)&meas_dsc_y;
return tool_selected_meas();
}

canonical_decompiled_code:
__int64 func15()
{
meas_dsc = (__int64)&meas_dsc_y;
return func12();
}

original_code:
static void tool_selected_meas_y(void)
{
 meas_dsc = &meas_dsc_y;
 tool_selected_meas();
}

canonical_original_code:
static void tool_selected_meas_y()
{
 meas_dsc = &meas_dsc_y;
 tool_selected_meas();
}


decompiled_code:
__int64 end_drag_move_meas()
{
highlight = 0LL;
return redraw();
}

canonical_decompiled_code:
__int64 func22()
{
highlight = 0LL;
return redraw();
}

original_code:
void end_drag_move_meas(void)
{
 highlight = ((void *)0);
 redraw();
}

canonical_original_code:
void end_drag_move_meas()
{
 highlight = ((void *)0);
 redraw();
}


decompiled_code:
// attributes: thunk
__int64 tool_deselected_meas()
{
return end_drag_move_meas();
}

canonical_decompiled_code:
__int64 func23()
{
return func22();
}

original_code:
static void tool_deselected_meas(void)
{
 highlight = ((void *)0);
 redraw();
}

canonical_original_code:
static void tool_deselected_meas()
{
 highlight = ((void *)0);
 redraw();
}


decompiled_code:
__int64 draw_D()
{
__int64 result; // rax

result = over_D_save_and_draw(over_D_user, over_pos);
buf_D = result;
return result;
}

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

result = over_D_save_and_draw(over_D_user, over_pos);
buf_D = result;
return result;
}

original_code:
static void draw_D(void)
{
 buf_D = over_D_save_and_draw(over_D_user, over_pos);
 ;
}

canonical_original_code:
static void draw_D()
{
 buf_D = over_D_save_and_draw(over_D_user, over_pos);
 ;
}


decompiled_code:
__int64 draw_H()
{
__int64 result; // rax

result = over_H_save_and_draw(over_H_user);
buf_H = result;
return result;
}

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

result = over_H_save_and_draw(over_H_user);
buf_H = result;
return result;
}

original_code:
static void draw_H(void)
{
 buf_H = over_H_save_and_draw(over_H_user);
 ;
}

canonical_original_code:
static void draw_H()
{
 buf_H = over_H_save_and_draw(over_H_user);
 ;
}


decompiled_code:
__int64 over_leave()
{
__int64 result; // rax

if ( state == 1 )
{
result = restore_pix_buf(buf_H);
state = 0;
}
else
{
if ( state != 3 )
over_leave_cold();
restore_pix_buf(buf_D);
restore_pix_buf(buf_H);
result = draw_D();
state = 2;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

if ( state == 1 )
{
result = restore_pix_buf(buf_H);
state = 0;
}
else
{
if ( state != 3 )
func9();
restore_pix_buf(buf_D);
restore_pix_buf(buf_H);
result = func0();
state = 2;
}
return result;
}

original_code:
void over_leave(void)
{
 ;
 switch (state) {
 case HOVER:
  ; restore_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; restore_pix_buf(buf_H);
  ;
  ; draw_D();
  ; state = DRAG; break;;
 default:
  abort();
 }
}

canonical_original_code:
void over_leave()
{
 ;
 switch (state) {
 case HOVER:
  ; restore_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; restore_pix_buf(buf_H);
  ;
  ; draw_D();
  ; state = DRAG; break;;
 default:
  abort();
 }
}


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

result = (unsigned int)state;
over_pos = a1;
if ( state == 2 )
{
restore_pix_buf(buf_D);
over_pos = a1;
result = draw_D();
state = 2;
}
else if ( (unsigned int)state > 2 )
{
if ( state != 3 )
over_move_cold();
restore_pix_buf(buf_D);
over_pos = a1;
result = draw_D();
state = 3;
}
return result;
}

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

result = (unsigned int)state;
over_pos = a1;
if ( state == 2 )
{
restore_pix_buf(buf_D);
over_pos = a1;
result = func0();
state = 2;
}
else if ( (unsigned int)state > 2 )
{
if ( state != 3 )
func11();
restore_pix_buf(buf_D);
over_pos = a1;
result = func0();
state = 3;
}
return result;
}

original_code:
void over_move(struct coord pos)
{
 over_pos = pos;
 ;
 switch (state) {
 case NOTHING:
  break;
 case HOVER:
  break;
 case DRAG:
  ; restore_pix_buf(buf_D);
  ; over_pos = pos;
  ;
  ; draw_D();
  ; state = DRAG; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; over_pos = pos;
  ;
  ; draw_D();
  ; state = BOTH; break;;
 default:
  abort();
 }
}

variable_types:
pos
struct coord { int x; }


decompiled_code:
__int64 over_end()
{
__int64 result; // rax

if ( state == 2 )
{
result = restore_pix_buf(buf_D);
state = 0;
}
else
{
if ( state != 3 )
over_end_cold();
result = restore_pix_buf(buf_D);
state = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

if ( state == 2 )
{
result = restore_pix_buf(buf_D);
state = 0;
}
else
{
if ( state != 3 )
func12();
result = restore_pix_buf(buf_D);
state = 1;
}
return result;
}

original_code:
void over_end(void)
{
 ;
 switch (state) {
 case DRAG:
  ; restore_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; state = HOVER; break;;
 default:
  abort();
 }
}

canonical_original_code:
void over_end()
{
 ;
 switch (state) {
 case DRAG:
  ; restore_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; restore_pix_buf(buf_D);
  ; state = HOVER; break;;
 default:
  abort();
 }
}


decompiled_code:
__int64 over_reset()
{
__int64 result; // rax

result = (unsigned int)state;
if ( state == 2 )
{
result = free_pix_buf(buf_D);
state = 0;
return result;
}
if ( (unsigned int)state > 2 )
{
if ( state != 3 )
over_reset_cold();
free_pix_buf(buf_D);
}
else if ( !state )
{
return result;
}
result = free_pix_buf(buf_H);
state = 0;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

result = (unsigned int)state;
if ( state == 2 )
{
result = free_pix_buf(buf_D);
state = 0;
return result;
}
if ( (unsigned int)state > 2 )
{
if ( state != 3 )
func13();
free_pix_buf(buf_D);
}
else if ( !state )
{
return result;
}
result = free_pix_buf(buf_H);
state = 0;
return result;
}

original_code:
void over_reset(void)
{
 ;
 switch (state) {
 case NOTHING:
  break;
 case HOVER:
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case DRAG:
  ; free_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; free_pix_buf(buf_D);
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 default:
  abort();
 }
}

canonical_original_code:
void over_reset()
{
 ;
 switch (state) {
 case NOTHING:
  break;
 case HOVER:
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 case DRAG:
  ; free_pix_buf(buf_D);
  ; state = NOTHING; break;;
 case BOTH:
  ; free_pix_buf(buf_D);
  ; free_pix_buf(buf_H);
  ; state = NOTHING; break;;
 default:
  abort();
 }
}


decompiled_code:
char *__fastcall stralloc_vprintf(char *format, __gnuc_va_list arg)
{
size_t v2; // rbp
char *v3; // rax
char *v4; // r12
__m128i arga; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

arga = _mm_loadu_si128((const __m128i *)arg);
v7 = *((_QWORD *)arg + 2);
v2 = vsnprintf(0LL, 0LL, format, &arga) + 1;
v3 = (char *)malloc(v2);
if ( !v3 )
stralloc_vprintf_cold();
v4 = v3;
vsnprintf(v3, v2, format, arg);
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *format, __gnuc_va_list arg)
{
size_t v2; // rbp
char *v3; // rax
char *v4; // r12
__m128i arga; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+18h] [rbp-30h]

arga = _mm_loadu_si128((const __m128i *)arg);
v7 = *((_QWORD *)arg + 2);
v2 = vsnprintf(0LL, 0LL, format, &arga) + 1;
v3 = (char *)malloc(v2);
if ( !v3 )
func6();
v4 = v3;
vsnprintf(v3, v2, format, arg);
return v4;
}

original_code:
char *stralloc_vprintf(const char *fmt, va_list ap)
{
 va_list aq;
 char *buf;
 int n;
 __builtin_va_copy(aq,ap);
 n = vsnprintf(((void *)0), 0, fmt, aq);
 __builtin_va_end(aq);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 vsnprintf(buf, n+1, fmt, ap);
 return buf;
}

canonical_original_code:
char *stralloc_vprintf(char *fmt, __builtin_va_list ap)
{
 __builtin_va_list aq;
 char *buf;
 int n;
 __builtin_va_copy(aq,ap);
 n = vsnprintf(((void *)0), 0, fmt, aq);
 __builtin_va_end(aq);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 vsnprintf(buf, n+1, fmt, ap);
 return buf;
}

variable_types:
fmt
char *

variable_types:
buf
char *

variable_types: n int

return_type: char *


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

va_start(arg, a1);
return stralloc_vprintf(a1, arg);
}

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

va_start(arg, a1);
return func0(a1, arg);
}

original_code:
char *stralloc_printf(const char *fmt, ...)
{
 va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 return s;
}

canonical_original_code:
char *stralloc_printf(char *fmt, ...)
{
 __builtin_va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 return s;
}

variable_types:
s
char *


decompiled_code:
_BOOL8 __fastcall is_id_char(char a1, int a2)
{
_BOOL8 result; // rax

if ( (unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u || a1 == 95 )
return 1LL;
result = 0LL;
if ( !a2 )
result = (unsigned __int8)(a1 - 48) <= 9u;
return result;
}

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

if ( (unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u || a1 == 95 )
return 1LL;
result = 0LL;
if ( !a2 )
result = (unsigned __int8)(a1 - 48) <= 9u;
return result;
}

original_code:
int is_id_char(char c, int first)
{
 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
  return 1;
 if (first)
  return 0;
 return c >= '0' && c <= '9';
}

variable_types: c char

variable_types: first int


decompiled_code:
_BOOL8 __fastcall is_id(char *a1)
{
char v2; // di
_BOOL8 result; // rax
char *v4; // rdx
__int64 v5; // rdx

v2 = *a1;
result = 0LL;
if ( v2 )
{
v4 = a1;
while ( 1 )
{
result = is_id_char(v2, a1 == v4);
if ( !result )
break;
v2 = *(_BYTE *)(v5 + 1);
v4 = (char *)(v5 + 1);
if ( !v2 )
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *a1)
{
char v2; // di
_BOOL8 result; // rax
char *v4; // rdx
__int64 v5; // rdx

v2 = *a1;
result = 0LL;
if ( v2 )
{
v4 = a1;
while ( 1 )
{
result = func2(v2, a1 == v4);
if ( !result )
break;
v2 = *(_BYTE *)(v5 + 1);
v4 = (char *)(v5 + 1);
if ( !v2 )
return 1LL;
}
}
return result;
}

original_code:
int is_id(const char *s)
{
 const char *p;
 if (!*s)
  return 0;
 for (p = s; *p; p++)
  if (!is_id_char(*p, s == p))
   return 0;
 return 1;
}

canonical_original_code:
int is_id(char *s)
{
 char *p;
 if (!*s)
  return 0;
 for (p = s; *p; p++)
  if (!is_id_char(*p, s == p))
   return 0;
 return 1;
}

variable_types:
p
char *


unique

decompiled_code:
const char *__fastcall unique(char *s)
{
char *v1; // rbx
const char *v2; // r12
char **v4; // rax
char **v5; // r12
char *v6; // rax
void **v7; // rbx

v1 = (char *)uniques;
if ( uniques )
{
while ( 1 )
{
v2 = *(const char **)v1;
if ( !strcmp(s, *(const char **)v1) )
return v2;
if ( !*((_QWORD *)v1 + 1) )
break;
v1 = (char *)*((_QWORD *)v1 + 1);
}
v7 = (void **)(v1 + 8);
}
else
{
v7 = &uniques;
}
v4 = (char **)malloc(0x10uLL);
v5 = v4;
if ( !v4 || (*v7 = v4, (v6 = strdup(s)) == 0LL) )
unique_cold();
*v5 = v6;
v5[1] = 0LL;
return *(const char **)*v7;
}

canonical_decompiled_code:
const char *__fastcall func4(char *s)
{
char *v1; // rbx
const char *v2; // r12
char **v4; // rax
char **v5; // r12
char *v6; // rax
void **v7; // rbx

v1 = (char *)uniques;
if ( uniques )
{
while ( 1 )
{
v2 = *(const char **)v1;
if ( !strcmp(s, *(const char **)v1) )
return v2;
if ( !*((_QWORD *)v1 + 1) )
break;
v1 = (char *)*((_QWORD *)v1 + 1);
}
v7 = (void **)(v1 + 8);
}
else
{
v7 = &uniques;
}
v4 = (char **)malloc(0x10uLL);
v5 = v4;
if ( !v4 || (*v7 = v4, (v6 = strdup(s)) == 0LL) )
func7();
*v5 = v6;
v5[1] = 0LL;
return *(const char **)*v7;
}

original_code:
const char *unique(const char *s)
{
 struct unique **walk;
 for (walk = &uniques; *walk; walk = &(*walk)->next)
  if (!strcmp(s, (*walk)->s))
   return (*walk)->s;
 *walk = ((struct unique *) ({ void *alloc_size_tmp = malloc(sizeof(struct unique)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 (*walk)->s = ({ char *stralloc_tmp = strdup(s); if (!stralloc_tmp) abort(); stralloc_tmp; });
 (*walk)->next = ((void *)0);
 return (*walk)->s;
}

canonical_original_code:
char *unique(char *s)
{
 struct unique **walk;
 for (walk = &uniques; *walk; walk = &(*walk)->next)
  if (!strcmp(s, (*walk)->s))
   return (*walk)->s;
 *walk = ((struct unique *) ({ void *alloc_size_tmp = malloc(sizeof(struct unique)); if (!alloc_size_tmp) abort(); alloc_size_tmp; }));
 (*walk)->s = ({ char *stralloc_tmp = strdup(s); if (!stralloc_tmp) abort(); stralloc_tmp; });
 (*walk)->next = ((void *)0);
 return (*walk)->s;
}

variable_types: struct unique { char *s; struct unique *next; } **


decompiled_code:
void unique_cleanup()
{
void **v0; // rbx
void **v1; // rax

v0 = (void **)uniques;
if ( uniques )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(uniques);
uniques = v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func5()
{
void **v0; // rbx
void **v1; // rax

v0 = (void **)uniques;
if ( uniques )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(uniques);
uniques = v0;
}
while ( v0 );
}
}

original_code:
void unique_cleanup(void)
{
 struct unique *next;
 while (uniques) {
  next = uniques->next;
  free(uniques->s);
  free(uniques);
  uniques = next;
 }
}

canonical_original_code:
void unique_cleanup()
{
 struct unique *next;
 while (uniques) {
  next = uniques->next;
  free(uniques->s);
  free(uniques);
  uniques = next;
 }
}

variable_types: struct unique { char *s; struct unique *next; } *


decompiled_code:
void kill_cpp(void)
{
if ( cpp_pid )
kill(cpp_pid, 15);
}

canonical_decompiled_code:
void func0(void)
{
if ( cpp_pid )
kill(cpp_pid, 15);
}

original_code:
static void kill_cpp(void)
{
    if (cpp_pid)
 (void) kill(cpp_pid,15);
}

canonical_original_code:
static void kill_cpp()
{
    if (cpp_pid)
 (void) kill(cpp_pid,15);
}


decompiled_code:
char **__fastcall add_cpp_arg(char *s)
{
char *v1; // rbp
__int64 v2; // rbx
char **v3; // r12
char **result; // rax
int v5; // er13

v1 = s;
v2 = cpp_argc;
if ( cpp_argc )
{
v5 = cpp_argc + 1;
result = (char **)realloc(cpp_argv, 8LL * (cpp_argc + 1));
cpp_argv = result;
v3 = result;
if ( result )
{
if ( (_DWORD)v2 != 1 )
goto LABEL_4;
goto LABEL_3;
}
LABEL_10:
perror("realloc");
exit(1);
}
cpp_argc = 1;
cpp_argv = (char **)realloc(cpp_argv, 0x10uLL);
v3 = cpp_argv;
if ( !cpp_argv )
goto LABEL_10;
LABEL_3:
result = (char **)cpp_command;
v5 = 2;
v2 = 1LL;
*v3 = cpp_command;
LABEL_4:
if ( s )
{
result = (char **)strdup(s);
v1 = (char *)result;
if ( !result )
{
perror("strdup");
exit(1);
}
}
v3[v2] = v1;
cpp_argc = v5;
return result;
}

canonical_decompiled_code:
char **__fastcall func1(char *s)
{
char *v1; // rbp
__int64 v2; // rbx
char **v3; // r12
char **result; // rax
int v5; // er13

v1 = s;
v2 = cpp_argc;
if ( cpp_argc )
{
v5 = cpp_argc + 1;
result = (char **)realloc(cpp_argv, 8LL * (cpp_argc + 1));
cpp_argv = result;
v3 = result;
if ( result )
{
if ( (_DWORD)v2 != 1 )
goto LABEL_4;
goto LABEL_3;
}
LABEL_10:
perror("realloc");
exit(1);
}
cpp_argc = 1;
cpp_argv = (char **)realloc(cpp_argv, 0x10uLL);
v3 = cpp_argv;
if ( !cpp_argv )
goto LABEL_10;
LABEL_3:
result = (char **)cpp_command;
v5 = 2;
v2 = 1LL;
*v3 = cpp_command;
LABEL_4:
if ( s )
{
result = (char **)strdup(s);
v1 = (char *)result;
if ( !result )
{
perror("strdup");
exit(1);
}
}
v3[v2] = v1;
cpp_argc = v5;
return result;
}

original_code:
void add_cpp_arg(const char *arg)
{
    if (!cpp_argc)
 cpp_argc = 1;
    cpp_argv = realloc(cpp_argv,sizeof(const char *)*(cpp_argc+1));
    if (!cpp_argv) {
 perror("realloc");
 exit(1);
    }
    if (cpp_argc == 1)
 cpp_argv[0] = cpp_command;
    if (arg) {
 arg = strdup(arg);
 if (!arg) {
     perror("strdup");
     exit(1);
 }
    }
    cpp_argv[cpp_argc++] = arg;
}

canonical_original_code:
void add_cpp_arg(char *arg)
{
    if (!cpp_argc)
 cpp_argc = 1;
    cpp_argv = realloc(cpp_argv,sizeof(char *)*(cpp_argc+1));
    if (!cpp_argv) {
 perror("realloc");
 exit(1);
    }
    if (cpp_argc == 1)
 cpp_argv[0] = cpp_command;
    if (arg) {
 arg = strdup(arg);
 if (!arg) {
     perror("strdup");
     exit(1);
 }
    }
    cpp_argv[cpp_argc++] = arg;
}

variable_types:
arg
char *


decompiled_code:
void __fastcall run_cpp(char *s, int fd, int a3)
{
__pid_t v4; // eax
char **v5; // rbp
char *v6; // rdi
char **i; // rbx
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
if ( s )
add_cpp_arg(s);
add_cpp_arg(0LL);
v4 = fork();
cpp_pid = v4;
if ( v4 < 0 )
{
perror("fork");
exit(1);
}
if ( !v4 )
{
if ( close(pipedes[0]) < 0 || a3 != -1 && close(a3) < 0 )
goto LABEL_22;
if ( fd != -1 && dup2(fd, 0) < 0 || dup2(pipedes[1], 1) < 0 )
{
LABEL_21:
perror("dup2");
exit(1);
}
if ( execvp(cpp_command, cpp_argv) < 0 )
{
perror(cpp_command);
exit(1);
}
}
if ( close(pipedes[1]) < 0 )
goto LABEL_22;
real_stdin = dup(0);
if ( real_stdin < 0 )
{
perror("dup");
exit(1);
}
if ( fd != -1 && close(fd) < 0 )
{
LABEL_22:
perror("close");
exit(1);
}
if ( dup2(pipedes[0], 0) < 0 )
goto LABEL_21;
v5 = cpp_argv;
v6 = cpp_argv[1];
for ( i = cpp_argv + 1; v6; ++i )
{
free(v6);
v6 = i[1];
}
free(v5);
cpp_argv = 0LL;
cpp_argc = 0;
}

canonical_decompiled_code:
void __fastcall func2(char *s, int fd, int a3)
{
__pid_t v4; // eax
char **v5; // rbp
char *v6; // rdi
char **i; // rbx
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
if ( s )
func1(s);
func1(0LL);
v4 = fork();
cpp_pid = v4;
if ( v4 < 0 )
{
perror("fork");
exit(1);
}
if ( !v4 )
{
if ( close(pipedes[0]) < 0 || a3 != -1 && close(a3) < 0 )
goto LABEL_22;
if ( fd != -1 && dup2(fd, 0) < 0 || dup2(pipedes[1], 1) < 0 )
{
LABEL_21:
perror("dup2");
exit(1);
}
if ( execvp(cpp_command, cpp_argv) < 0 )
{
perror(cpp_command);
exit(1);
}
}
if ( close(pipedes[1]) < 0 )
goto LABEL_22;
real_stdin = dup(0);
if ( real_stdin < 0 )
{
perror("dup");
exit(1);
}
if ( fd != -1 && close(fd) < 0 )
{
LABEL_22:
perror("close");
exit(1);
}
if ( dup2(pipedes[0], 0) < 0 )
goto LABEL_21;
v5 = cpp_argv;
v6 = cpp_argv[1];
for ( i = cpp_argv + 1; v6; ++i )
{
free(v6);
v6 = i[1];
}
free(v5);
cpp_argv = 0LL;
cpp_argc = 0;
}

original_code:
static void run_cpp(const char *name,int fd,int close_fd)
{
    char **arg;
    int fds[2];
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    if (name)
 add_cpp_arg(name);
    add_cpp_arg(((void *)0));
    cpp_pid = fork();
    if (cpp_pid < 0) {
        perror("fork");
        exit(1);
    }
    if (!cpp_pid) {
 if (close(fds[0]) < 0) {
     perror("close");
     exit(1);
 }
 if (close_fd != -1 && close(close_fd) < 0) {
     perror("close");
     exit(1);
 }
 if (fd != -1 && dup2(fd,0) < 0) {
     perror("dup2");
     exit(1);
 }
 if (dup2(fds[1],1) < 0) {
     perror("dup2");
     exit(1);
 }
 if (execvp(cpp_command,(char **) cpp_argv) < 0) {
     perror(cpp_command);
     exit(1);
 }
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    real_stdin = dup(0);
    if (real_stdin < 0) {
 perror("dup");
 exit(1);
    }
    if (fd != -1 && close(fd) < 0) {
 perror("close");
 exit(1);
    }
    if (dup2(fds[0],0) < 0) {
 perror("dup2");
 exit(1);
    }
    for (arg = (char **) cpp_argv+1; *arg; arg++)
 free(*arg);
    free(cpp_argv);
    cpp_argv = ((void *)0);
    cpp_argc = 0;
}

canonical_original_code:
static void run_cpp(char *name, int fd, int close_fd)
{
    char **arg;
    int fds[2];
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    if (name)
 add_cpp_arg(name);
    add_cpp_arg(((void *)0));
    cpp_pid = fork();
    if (cpp_pid < 0) {
        perror("fork");
        exit(1);
    }
    if (!cpp_pid) {
 if (close(fds[0]) < 0) {
     perror("close");
     exit(1);
 }
 if (close_fd != -1 && close(close_fd) < 0) {
     perror("close");
     exit(1);
 }
 if (fd != -1 && dup2(fd,0) < 0) {
     perror("dup2");
     exit(1);
 }
 if (dup2(fds[1],1) < 0) {
     perror("dup2");
     exit(1);
 }
 if (execvp(cpp_command,(char **) cpp_argv) < 0) {
     perror(cpp_command);
     exit(1);
 }
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    real_stdin = dup(0);
    if (real_stdin < 0) {
 perror("dup");
 exit(1);
    }
    if (fd != -1 && close(fd) < 0) {
 perror("close");
 exit(1);
    }
    if (dup2(fds[0],0) < 0) {
 perror("dup2");
 exit(1);
    }
    for (arg = (char **) cpp_argv+1; *arg; arg++)
 free(*arg);
    free(cpp_argv);
    cpp_argv = ((void *)0);
    cpp_argc = 0;
}

variable_types:
name
char *

variable_types: fd int

variable_types:
arg
char **

variable_types:
fds
int [2]


decompiled_code:
void __fastcall add_cpp_Wp(const char *a1)
{
char *v1; // rax
char *v2; // r12
char *v3; // rbp
char *v4; // rax
char *v5; // rdi

v1 = strdup(a1);
if ( !v1 )
{
perror("strdup");
exit(1);
}
v2 = v1;
v3 = v1;
while ( 1 )
{
v4 = strchr(v3, 44);
if ( !v4 )
break;
*v4 = 0;
v5 = v3;
v3 = v4 + 1;
add_cpp_arg(v5);
}
add_cpp_arg(v3);
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(const char *a1)
{
char *v1; // rax
char *v2; // r12
char *v3; // rbp
char *v4; // rax
char *v5; // rdi

v1 = strdup(a1);
if ( !v1 )
{
perror("strdup");
exit(1);
}
v2 = v1;
v3 = v1;
while ( 1 )
{
v4 = strchr(v3, 44);
if ( !v4 )
break;
*v4 = 0;
v5 = v3;
v3 = v4 + 1;
func1(v5);
}
func1(v3);
free(v2);
}

original_code:
void add_cpp_Wp(const char *arg)
{
    char *tmp = strdup(arg);
    char *curr,*end;
    if (!tmp) {
 perror("strdup");
 exit(1);
    }
    curr = tmp;
    do {
 end = strchr(curr,',');
 if (end)
     *end++ = 0;
 add_cpp_arg(curr);
 curr = end;
    }
    while (end);
    free(tmp);
}

canonical_original_code:
void add_cpp_Wp(char *arg)
{
    char *tmp = strdup(arg);
    char *curr; char *end;
    if (!tmp) {
 perror("strdup");
 exit(1);
    }
    curr = tmp;
    do {
 end = strchr(curr,',');
 if (end)
     *end++ = 0;
 add_cpp_arg(curr);
 curr = end;
    }
    while (end);
    free(tmp);
}

variable_types:
tmp
char *

variable_types:
curr
char *

variable_types:
end
char *


decompiled_code:
int __fastcall run_cpp_on_file(char *a1)
{
run_cpp(a1, -(a1 != 0LL), -1);
return atexit(kill_cpp);
}

canonical_decompiled_code:
int __fastcall func4(char *a1)
{
func2(a1, -(a1 != 0LL), -1);
return atexit(kill_cpp);
}

original_code:
void run_cpp_on_file(const char *name)
{
    run_cpp(name,name ? -1 : 0,-1);
    atexit(kill_cpp);
}

canonical_original_code:
void run_cpp_on_file(char *name)
{
    run_cpp(name,name ? -1 : 0,-1);
    atexit(kill_cpp);
}


decompiled_code:
int __fastcall run_cpp_on_string(void *buf)
{
char *v1; // rbp
__pid_t v2; // eax
int i; // ebx
int v4; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)buf;
if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
run_cpp(0LL, pipedes[0], pipedes[1]);
v2 = fork();
if ( v2 < 0 )
{
perror("fork");
exit(1);
}
if ( !v2 )
{
for ( i = strlen((const char *)buf); i; i -= v4 )
{
v4 = write(pipedes[1], v1, i);
if ( v4 < 0 )
break;
v1 += v4;
}
exit(0);
}
if ( close(pipedes[1]) < 0 )
{
perror("close");
exit(1);
}
return atexit(kill_cpp);
}

canonical_decompiled_code:
int __fastcall func5(void *buf)
{
char *v1; // rbp
__pid_t v2; // eax
int i; // ebx
int v4; // eax
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)buf;
if ( pipe(pipedes) < 0 )
{
perror("pipe");
exit(1);
}
func2(0LL, pipedes[0], pipedes[1]);
v2 = fork();
if ( v2 < 0 )
{
perror("fork");
exit(1);
}
if ( !v2 )
{
for ( i = strlen((const char *)buf); i; i -= v4 )
{
v4 = write(pipedes[1], v1, i);
if ( v4 < 0 )
break;
v1 += v4;
}
exit(0);
}
if ( close(pipedes[1]) < 0 )
{
perror("close");
exit(1);
}
return atexit(kill_cpp);
}

original_code:
void run_cpp_on_string(const char *str)
{
    int fds[2];
    pid_t pid;
    int left,wrote;
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    run_cpp(((void *)0),fds[0],fds[1]);
    pid = fork();
    if (pid < 0) {
 perror("fork");
 exit(1);
    }
    if (!pid) {
 for (left = strlen(str); left; left -= wrote) {
     wrote = write(fds[1],str,left);
     if (wrote < 0)
  break;
     str += wrote;
 }
 exit(0);
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    atexit(kill_cpp);
}

canonical_original_code:
void run_cpp_on_string(char *str)
{
    int fds[2];
    int pid;
    int left; int wrote;
    if (pipe(fds) < 0) {
        perror("pipe");
        exit(1);
    }
    run_cpp(((void *)0),fds[0],fds[1]);
    pid = fork();
    if (pid < 0) {
 perror("fork");
 exit(1);
    }
    if (!pid) {
 for (left = strlen(str); left; left -= wrote) {
     wrote = write(fds[1],str,left);
     if (wrote < 0)
  break;
     str += wrote;
 }
 exit(0);
    }
    if (close(fds[1]) < 0) {
 perror("close");
 exit(1);
    }
    atexit(kill_cpp);
}

variable_types:
str
char *

variable_types: pid int

variable_types: left int

variable_types: wrote int


decompiled_code:
int reap_cpp()
{
int result; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

cpp_pid = 0;
if ( waitpid(0, &stat_loc, 0) < 0 )
{
perror("waitpid");
exit(1);
}
if ( stat_loc )
{
if ( (stat_loc & 0x7F) != 0 )
{
if ( (char)((stat_loc & 0x7F) + 1) <= 1 )
fprintf(stderr, "cpp terminated with incomprehensible status %d\n", (unsigned int)stat_loc);
else
fprintf(stderr, "cpp terminated with signal %d\n", stat_loc & 0x7F);
exit(1);
}
exit(BYTE1(stat_loc));
}
result = dup2(real_stdin, 0);
if ( result < 0 )
{
perror("dup2");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
int stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

cpp_pid = 0;
if ( waitpid(0, &stat_loc, 0) < 0 )
{
perror("waitpid");
exit(1);
}
if ( stat_loc )
{
if ( (stat_loc & 0x7F) != 0 )
{
if ( (char)((stat_loc & 0x7F) + 1) <= 1 )
fprintf(stderr, "cpp terminated with incomprehensible status %d\n", (unsigned int)stat_loc);
else
fprintf(stderr, "cpp terminated with signal %d\n", stat_loc & 0x7F);
exit(1);
}
exit(BYTE1(stat_loc));
}
result = dup2(real_stdin, 0);
if ( result < 0 )
{
perror("dup2");
exit(1);
}
return result;
}

original_code:
void reap_cpp(void)
{
    int status;
    cpp_pid = 0;
    if (waitpid(cpp_pid,&status,0) < 0) {
 perror("waitpid");
 exit(1);
    }
    if (!status) {
 if (dup2(real_stdin,0) < 0) {
     perror("dup2");
     exit(1);
 }
 return;
    }
    if ((((status) & 0x7f) == 0))
 exit((((status) & 0xff00) >> 8));
    if ((((signed char) (((status) & 0x7f) + 1) >> 1) > 0))
 fprintf(stderr,"cpp terminated with signal %d\n",((status) & 0x7f));
    else
 fprintf(stderr,"cpp terminated with incomprehensible status %d\n",
   status);
    exit(1);
}

canonical_original_code:
void reap_cpp()
{
    int status;
    cpp_pid = 0;
    if (waitpid(cpp_pid,&status,0) < 0) {
 perror("waitpid");
 exit(1);
    }
    if (!status) {
 if (dup2(real_stdin,0) < 0) {
     perror("dup2");
     exit(1);
 }
 return;
    }
    if ((((status) & 0x7f) == 0))
 exit((((status) & 0xff00) >> 8));
    if ((((char) (((status) & 0x7f) + 1) >> 1) > 0))
 fprintf(stderr,"cpp terminated with signal %d\n",((status) & 0x7f));
    else
 fprintf(stderr,"cpp terminated with incomprehensible status %d\n",
   status);
    exit(1);
}

variable_types: status int


decompiled_code:
char *__fastcall merge3(void *ptr, char *s, void *a3)
{
size_t v4; // rbx
size_t v5; // r12
size_t v6; // rax
char *v7; // rax
char *v8; // r12

v4 = strlen(s);
v5 = strlen((const char *)ptr);
v6 = strlen((const char *)a3);
v7 = (char *)malloc(v6 + v4 + v5 + 1);
if ( !v7 )
merge3_cold();
v8 = v7;
sprintf(v7, "%s%s%s", (const char *)ptr, s, (const char *)a3);
free(ptr);
free(a3);
return v8;
}

canonical_decompiled_code:
char *__fastcall func1(void *ptr, char *s, void *a3)
{
size_t v4; // rbx
size_t v5; // r12
size_t v6; // rax
char *v7; // rax
char *v8; // r12

v4 = strlen(s);
v5 = strlen((const char *)ptr);
v6 = strlen((const char *)a3);
v7 = (char *)malloc(v6 + v4 + v5 + 1);
if ( !v7 )
func7();
v8 = v7;
sprintf(v7, "%s%s%s", (const char *)ptr, s, (const char *)a3);
free(ptr);
free(a3);
return v8;
}

original_code:
static char *merge3(char *a, const char *op, char *b)
{
 char *buf;
 buf = ({ void *alloc_size_tmp = malloc(strlen(op)+strlen(a)+strlen(b)+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 sprintf(buf, "%s%s%s", a, op, b);
 free(a);
 free(b);
 return buf;
}

canonical_original_code:
static char *merge3(char *a, char *op, char *b)
{
 char *buf;
 buf = ({ void *alloc_size_tmp = malloc(strlen(op)+strlen(a)+strlen(b)+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 sprintf(buf, "%s%s%s", a, op, b);
 free(a);
 free(b);
 return buf;
}

variable_types:
a
char *

variable_types:
op
char *

variable_types:
b
char *

variable_types:
buf
char *


decompiled_code:
__int64 __fastcall set_extension(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbp
char *v4; // rdi
char *v5; // rax
__int64 v6; // r12

v2 = strdup(a1);
if ( !v2 )
set_extension_cold();
v3 = v2;
v4 = strrchr(v2, 47);
if ( !v4 )
v4 = v3;
v5 = strrchr(v4, 46);
if ( v5 )
*v5 = 0;
v6 = stralloc_printf("%s.%s", v3, a2);
free(v3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
char *v2; // rax
char *v3; // rbp
char *v4; // rdi
char *v5; // rax
__int64 v6; // r12

v2 = strdup(a1);
if ( !v2 )
func12();
v3 = v2;
v4 = strrchr(v2, 47);
if ( !v4 )
v4 = v3;
v5 = strrchr(v4, 46);
if ( v5 )
*v5 = 0;
v6 = stralloc_printf("%s.%s", v3, a2);
free(v3);
return v6;
}

original_code:
char *set_extension(const char *name, const char *ext)
{
 char *s = ({ char *stralloc_tmp = strdup(name); if (!stralloc_tmp) abort(); stralloc_tmp; });
 char *slash, *dot;
 char *res;
 slash = strrchr(s, '/');
 dot = strrchr(slash ? slash : s, '.');
 if (dot)
  *dot = 0;
 res = stralloc_printf("%s.%s", s, ext);
 free(s);
 return res;
}

canonical_original_code:
char *set_extension(char *name, char *ext)
{
 char *s = ({ char *stralloc_tmp = strdup(name); if (!stralloc_tmp) abort(); stralloc_tmp; });
 char *slash; char *dot;
 char *res;
 slash = strrchr(s, '/');
 dot = strrchr(slash ? slash : s, '.');
 if (dot)
  *dot = 0;
 res = stralloc_printf("%s.%s", s, ext);
 free(s);
 return res;
}

variable_types:
ext
char *

variable_types:
s
char *

variable_types:
slash
char *

variable_types:
dot
char *

variable_types:
res
char *


decompiled_code:
__int64 __fastcall file_exists(char *s)
{
int v1; // er8
__int64 result; // rax
int *v3; // r8
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(s, &v4);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
result = 0LL;
if ( *v3 != 2 )
{
perror(s);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s)
{
int v1; // er8
__int64 result; // rax
int *v3; // r8
struct stat v4; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(s, &v4);
result = 1LL;
if ( v1 < 0 )
{
v3 = _errno_location();
result = 0LL;
if ( *v3 != 2 )
{
perror(s);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int file_exists(const char *name)
{
 struct stat st;
 if (stat(name, &st) >= 0)
  return 1;
 if ((*__errno_location ()) == 2)
  return 0;
 perror(name);
 return -1;
}

canonical_original_code:
int file_exists(char *name)
{
 struct stat st;
 if (stat(name, &st) >= 0)
  return 1;
 if ((*__errno_location ()) == 2)
  return 0;
 perror(name);
 return -1;
}

variable_types:
name
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void save_fpd()
{
if ( save_file_name )
{
save_with_backup(save_file_name, (unsigned int (__fastcall *)(FILE *, __int64))&dump, 0LL);
}
else if ( !(unsigned int)dump(stdout, 0LL) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void func6()
{
if ( save_file_name )
{
func5(save_file_name, (unsigned int (__fastcall *)(FILE *, __int64))&dump, 0LL);
}
else if ( !(unsigned int)dump(stdout, 0LL) )
{
perror("stdout");
}
}

original_code:
void save_fpd(void)
{
 if (save_file_name) {
  save_with_backup(save_file_name, dump, ((void *)0));
 } else {
  if (!dump(stdout, ((void *)0)))
   perror("stdout");
 }
}

canonical_original_code:
void save_fpd()
{
 if (save_file_name) {
  save_with_backup(save_file_name, dump, ((void *)0));
 } else {
  if (!dump(stdout, ((void *)0)))
   perror("stdout");
 }
}


decompiled_code:
void write_kicad()
{
char *v0; // rbp

if ( save_file_name )
{
v0 = (char *)set_extension(save_file_name, "mod");
save_to(v0, (unsigned int (__fastcall *)(FILE *, __int64))&kicad, 0LL);
free(v0);
}
else if ( !(unsigned int)kicad(stdout, 0LL) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void func7()
{
char *v0; // rbp

if ( save_file_name )
{
v0 = (char *)func0(save_file_name, "mod");
func2(v0, (unsigned int (__fastcall *)(FILE *, __int64))&kicad, 0LL);
free(v0);
}
else if ( !(unsigned int)kicad(stdout, 0LL) )
{
perror("stdout");
}
}

original_code:
void write_kicad(void)
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "mod");
  save_to(name, kicad, ((void *)0));
  free(name);
 } else {
  if (!kicad(stdout, ((void *)0)))
   perror("stdout");
 }
}

canonical_original_code:
void write_kicad()
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "mod");
  save_to(name, kicad, ((void *)0));
  free(name);
 } else {
  if (!kicad(stdout, ((void *)0)))
   perror("stdout");
 }
}


decompiled_code:
void write_pcb()
{
char *v0; // rbp

if ( save_file_name )
{
v0 = (char *)set_extension(save_file_name, "fp");
pcb_save_to(v0, (unsigned int (__fastcall *)(FILE *))&pcb);
free(v0);
}
else if ( !(unsigned int)pcb(stdout) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void func8()
{
char *v0; // rbp

if ( save_file_name )
{
v0 = (char *)func0(save_file_name, "fp");
func4(v0, (unsigned int (__fastcall *)(FILE *))&pcb);
free(v0);
}
else if ( !(unsigned int)pcb(stdout) )
{
perror("stdout");
}
}

original_code:
void write_pcb (void)
{
        char *name;
        if (save_file_name)
        {
                name = set_extension (save_file_name, "fp");
                pcb_save_to (name, pcb);
                free (name);
        }
        else
        {
                if (!pcb (stdout))
                {
                        perror ("stdout");
                }
        }
}

canonical_original_code:
void write_pcb()
{
        char *name;
        if (save_file_name)
        {
                name = set_extension (save_file_name, "fp");
                pcb_save_to (name, pcb);
                free (name);
        }
        else
        {
                if (!pcb (stdout))
                {
                        perror ("stdout");
                }
        }
}


decompiled_code:
void __fastcall write_ps(__int64 a1)
{
do_write_ps((unsigned int (__fastcall *)(FILE *, __int64))&postscript, a1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
func3((unsigned int (__fastcall *)(FILE *, __int64))&postscript, a1);
}

original_code:
void write_ps(const char *one)
{
 do_write_ps(postscript, one);
}

canonical_original_code:
void write_ps(char *one)
{
 do_write_ps(postscript, one);
}

variable_types:
one
char *


decompiled_code:
void __fastcall write_ps_fullpage(__int64 a1)
{
do_write_ps((unsigned int (__fastcall *)(FILE *, __int64))&postscript_fullpage, a1);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
func3((unsigned int (__fastcall *)(FILE *, __int64))&postscript_fullpage, a1);
}

original_code:
void write_ps_fullpage(const char *one)
{
 do_write_ps(postscript_fullpage, one);
}

canonical_original_code:
void write_ps_fullpage(char *one)
{
 do_write_ps(postscript_fullpage, one);
}


decompiled_code:
void __fastcall write_gnuplot(__int64 a1)
{
char *v1; // rbp

if ( save_file_name )
{
v1 = (char *)set_extension(save_file_name, "gp");
save_to(v1, (unsigned int (__fastcall *)(FILE *, __int64))&gnuplot, a1);
free(v1);
}
else if ( !(unsigned int)gnuplot(stdout, a1) )
{
perror("stdout");
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
char *v1; // rbp

if ( save_file_name )
{
v1 = (char *)func0(save_file_name, "gp");
func2(v1, (unsigned int (__fastcall *)(FILE *, __int64))&gnuplot, a1);
free(v1);
}
else if ( !(unsigned int)gnuplot(stdout, a1) )
{
perror("stdout");
}
}

original_code:
void write_gnuplot(const char *one)
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "gp");
  save_to(name, gnuplot, one);
  free(name);
 } else {
  if (!gnuplot(stdout, one))
   perror("stdout");
 }
}

canonical_original_code:
void write_gnuplot(char *one)
{
 char *name;
 if (save_file_name) {
  name = set_extension(save_file_name, "gp");
  save_to(name, gnuplot, one);
  free(name);
 } else {
  if (!gnuplot(stdout, one))
   perror("stdout");
 }
}


decompiled_code:
void __fastcall __noreturn report_to_stderr(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void report_to_stderr(const char *s)
{
 fprintf(stderr, "%s\n", s);
 exit(1);
}

canonical_original_code:
void report_to_stderr(char *s)
{
 fprintf(stderr, "%s\n", s);
 exit(1);
}


yywarn

decompiled_code:
int __fastcall yywarn(const char *a1)
{
return fprintf(stderr, "%d: warning: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "%d: warning: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
}

original_code:
void yywarn(const char *s)
{
 fprintf(stderr, "%d: warning: %s near \"%s\"\n", lineno, s, yytext);
}

canonical_original_code:
void yywarn(char *s)
{
 fprintf(stderr, "%d: warning: %s near \"%s\"\n", lineno, s, yytext);
}


decompiled_code:
void __fastcall __noreturn report_parse_error(const char *a1)
{
fprintf(stderr, "%d: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
fprintf(stderr, "%d: %s near \"%s\"\n", (unsigned int)lineno, a1, yytext);
exit(1);
}

original_code:
void report_parse_error(const char *s)
{
 fprintf(stderr, "%d: %s near \"%s\"\n", lineno, s, yytext);
 exit(1);
}

canonical_original_code:
void report_parse_error(char *s)
{
 fprintf(stderr, "%d: %s near \"%s\"\n", lineno, s, yytext);
 exit(1);
}


fail

decompiled_code:
void __noreturn fail(__int64 a1, ...)
{
__int64 v1; // rbp
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = stralloc_vprintf(a1, va);
reporter(v1);
}

canonical_decompiled_code:
void __noreturn func3(__int64 a1, ...)
{
__int64 v1; // rbp
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = stralloc_vprintf(a1, va);
reporter(v1);
}

original_code:
void fail(const char *fmt, ...)
{
 va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 reporter(s);
 free(s);
}

canonical_original_code:
void fail(char *fmt, ...)
{
 __builtin_va_list ap;
 char *s;
 __builtin_va_start(ap,fmt);
 s = stralloc_vprintf(fmt, ap);
 __builtin_va_end(ap);
 reporter(s);
 free(s);
}

variable_types:
fmt
char *


yyerrorf

decompiled_code:
void __noreturn yyerrorf(const char *a1, ...)
{
size_t v1; // r12
char *v2; // rax
const char *v3; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a1);
v1 = vsnprintf(0LL, 0LL, a1, arg) + 1;
v2 = (char *)malloc(v1);
v3 = v2;
if ( v2 )
{
va_end(arg);
va_start(arg, a1);
vsnprintf(v2, v1, a1, arg);
fail((__int64)"%s", v3);
}
yyerrorf_cold();
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
size_t v1; // r12
char *v2; // rax
const char *v3; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a1);
v1 = vsnprintf(0LL, 0LL, a1, arg) + 1;
v2 = (char *)malloc(v1);
v3 = v2;
if ( v2 )
{
va_end(arg);
va_start(arg, a1);
vsnprintf(v2, v1, a1, arg);
func3((__int64)"%s", v3);
}
func6();
}

original_code:
void yyerrorf(const char *fmt, ...)
{
 va_list ap;
 char *buf;
 int n;
 __builtin_va_start(ap,fmt);
 n = vsnprintf(((void *)0), 0, fmt, ap);
 __builtin_va_end(ap);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, n+1, fmt, ap);
 __builtin_va_end(ap);
 fail("%s", buf);
 free(buf);
}

canonical_original_code:
void yyerrorf(char *fmt, ...)
{
 __builtin_va_list ap;
 char *buf;
 int n;
 __builtin_va_start(ap,fmt);
 n = vsnprintf(((void *)0), 0, fmt, ap);
 __builtin_va_end(ap);
 buf = ({ void *alloc_size_tmp = malloc(n+1); if (!alloc_size_tmp) abort(); alloc_size_tmp; });
 __builtin_va_start(ap,fmt);
 vsnprintf(buf, n+1, fmt, ap);
 __builtin_va_end(ap);
 fail("%s", buf);
 free(buf);
}

variable_types: n int


yyerror

decompiled_code:
void __fastcall __noreturn yyerror(const char *a1)
{
yyerrorf("%s", a1);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
func4("%s", a1);
}

original_code:
void yyerror(const char *s)
{
 yyerrorf("%s", s);
}

canonical_original_code:
void yyerror(char *s)
{
 yyerrorf("%s", s);
}


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


decompiled_code:
double __fastcall units_to_mil(int a1)
{
return (double)a1 / 254.0;
}

canonical_decompiled_code:
double __fastcall func1(int a1)
{
return (double)a1 / 254.0;
}

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

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


decompiled_code:
__int64 __fastcall dist_line_xy(int a1, int a2, int a3, int a4, int a5, int a6)
{
double v10; // xmm0_8
__int64 result; // rax
double v12; // xmm0_8
double v13; // xmm2_8
double v14; // xmm4_8
double v15; // xmm5_8
double v16; // xmm0_8
double v17; // xmm0_8
int v18; // [rsp+0h] [rbp-50h]
double v19; // [rsp+8h] [rbp-48h]
unsigned int v20; // [rsp+14h] [rbp-3Ch]

v18 = (int)hypot((double)(a3 - a1), (double)(a4 - a2));
v10 = hypot((double)(a5 - a1), (double)(a6 - a2));
result = (unsigned int)v18;
if ( (int)v10 <= v18 )
result = (unsigned int)(int)v10;
if ( a3 != a5 || a4 != a6 )
{
v20 = result;
v19 = (double)(a4 - a6);
v12 = hypot((double)(a3 - a5), v19);
v13 = (double)(a3 - a5);
v14 = (double)(a1 - a5);
result = v20;
v15 = (double)(a2 - a6);
v16 = (v13 * v14 + v19 * v15) / v12 / v12;
if ( v16 >= 0.0 && v16 <= 1.0 )
{
v17 = hypot((double)(int)(v14 - v16 * v13), (double)(int)(v15 - (double)(a4 - a6) * v16));
result = v20;
if ( (int)v20 > (int)v17 )
result = (unsigned int)(int)v17;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4, int a5, int a6)
{
double v10; // xmm0_8
__int64 result; // rax
double v12; // xmm0_8
double v13; // xmm2_8
double v14; // xmm4_8
double v15; // xmm5_8
double v16; // xmm0_8
double v17; // xmm0_8
int v18; // [rsp+0h] [rbp-50h]
double v19; // [rsp+8h] [rbp-48h]
unsigned int v20; // [rsp+14h] [rbp-3Ch]

v18 = (int)hypot((double)(a3 - a1), (double)(a4 - a2));
v10 = hypot((double)(a5 - a1), (double)(a6 - a2));
result = (unsigned int)v18;
if ( (int)v10 <= v18 )
result = (unsigned int)(int)v10;
if ( a3 != a5 || a4 != a6 )
{
v20 = result;
v19 = (double)(a4 - a6);
v12 = hypot((double)(a3 - a5), v19);
v13 = (double)(a3 - a5);
v14 = (double)(a1 - a5);
result = v20;
v15 = (double)(a2 - a6);
v16 = (v13 * v14 + v19 * v15) / v12 / v12;
if ( v16 >= 0.0 && v16 <= 1.0 )
{
v17 = hypot((double)(int)(v14 - v16 * v13), (double)(int)(v15 - (double)(a4 - a6) * v16));
result = v20;
if ( (int)v20 > (int)v17 )
result = (unsigned int)(int)v17;
}
}
return result;
}

original_code:
static unit_type dist_line_xy(unit_type px, unit_type py,
    unit_type ax, unit_type ay, unit_type bx, unit_type by)
{
 unit_type d_min, d;
 double a, f;
 d_min = hypot(ax-px, ay-py);
 d = hypot(bx-px, by-py);
 if (d < d_min)
  d_min = d;
 if (ax != bx || ay != by) {
  ax -= bx;
  ay -= by;
  bx = px-bx;
  by = py-by;
  a = hypot(ax, ay);
  f = ((double) ax*bx+(double) ay*by)/a/a;
  if (f >= 0 && f <= 1) {
   bx -= f*ax;
   by -= f*ay;
   d = hypot(bx, by);
   if (d < d_min)
    d_min = d;
  }
 }
 return d_min;
}

canonical_original_code:
static int dist_line_xy(int px, int py, int ax, int ay, int bx, int by)
{
 int d_min; int d;
 double a; double f;
 d_min = hypot(ax-px, ay-py);
 d = hypot(bx-px, by-py);
 if (d < d_min)
  d_min = d;
 if (ax != bx || ay != by) {
  ax -= bx;
  ay -= by;
  bx = px-bx;
  by = py-by;
  a = hypot(ax, ay);
  f = ((double) ax*bx+(double) ay*by)/a/a;
  if (f >= 0 && f <= 1) {
   bx -= f*ax;
   by -= f*ay;
   d = hypot(bx, by);
   if (d < d_min)
    d_min = d;
  }
 }
 return d_min;
}

variable_types: px int

variable_types: py int

variable_types: ax int

variable_types: ay int

variable_types: bx int

variable_types: by int

variable_types: d int

variable_types: a double

variable_types: f double


decompiled_code:
double __fastcall mm_to_mil(int a1, double a2)
{
return pow(0.0254, (double)-a1) * a2;
}

canonical_decompiled_code:
double __fastcall func3(int a1, double a2)
{
return pow(0.0254, (double)-a1) * a2;
}

original_code:
double mm_to_mil(double mm, int exponent)
{
 return mm*pow(0.0254, -exponent);
}

variable_types: mm double

variable_types: exponent int


decompiled_code:
double __fastcall mil_to_mm(int a1, double a2)
{
return pow(0.0254, (double)a1) * a2;
}

canonical_decompiled_code:
double __fastcall func4(int a1, double a2)
{
return pow(0.0254, (double)a1) * a2;
}

original_code:
double mil_to_mm(double mil, int exponent)
{
 return mil*pow(0.0254, exponent);
}

variable_types: mil double


normalize

decompiled_code:
unsigned __int64 __fastcall normalize(__int64 a1, int a2)
{
double v2; // xmm3_8

v2 = hypot((double)(int)a1, (double)SHIDWORD(a1));
return ((unsigned __int64)(unsigned int)(int)((double)SHIDWORD(a1) * ((double)a2 / v2)) << 32) | (unsigned int)(int)((double)(int)a1 * ((double)a2 / v2));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1, int a2)
{
double v2; // xmm3_8

v2 = hypot((double)(int)a1, (double)SHIDWORD(a1));
return ((unsigned __int64)(unsigned int)(int)((double)SHIDWORD(a1) * ((double)a2 / v2)) << 32) | (unsigned int)(int)((double)(int)a1 * ((double)a2 / v2));
}

original_code:
struct coord normalize(struct coord v, unit_type len)
{
 double f;
 f = len/hypot(v.x, v.y);
 v.x *= f;
 v.y *= f;
 return v;
}

canonical_original_code:
struct coord normalize(struct coord v, int len)
{
 double f;
 f = len/hypot(v.x, v.y);
 v.x *= f;
 v.y *= f;
 return v;
}

variable_types:
v
struct coord

variable_types: len int

return_type: struct coord { int x; }


rotate

decompiled_code:
unsigned __int64 __fastcall rotate(__int64 a1, double a2)
{
double v3; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2 * 3.141592653589793 / 180.0, sinx, &v3);
return ((unsigned __int64)(unsigned int)(int)(v3 * (double)SHIDWORD(a1) + (double)(int)a1 * sinx[0]) << 32) | (unsigned int)(int)((double)(int)a1 * v3 - (double)SHIDWORD(a1) * sinx[0]);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, double a2)
{
double v3; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

sincos(a2 * 3.141592653589793 / 180.0, sinx, &v3);
return ((unsigned __int64)(unsigned int)(int)(v3 * (double)SHIDWORD(a1) + (double)(int)a1 * sinx[0]) << 32) | (unsigned int)(int)((double)(int)a1 * v3 - (double)SHIDWORD(a1) * sinx[0]);
}

original_code:
struct coord rotate(struct coord v, double angle)
{
 double rad = 3.14159265358979323846*angle/180.0;
 struct coord res;
 res.x = v.x*cos(rad)-v.y*sin(rad);
 res.y = v.y*cos(rad)+v.x*sin(rad);
 return res;
}

variable_types: angle double

variable_types: rad double

variable_types:
res
struct coord { int x; }


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

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

original_code:
struct coord add_vec(struct coord a, struct coord b)
{
 a.x += b.x;
 a.y += b.y;
 return a;
}

variable_types:
a
struct coord

variable_types:
b
struct coord


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

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

original_code:
struct coord sub_vec(struct coord a, struct coord b)
{
 a.x -= b.x;
 a.y -= b.y;
 return a;
}


decompiled_code:
__int64 __fastcall neg_vec(__int64 a1)
{
return -a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return -a1;
}

original_code:
struct coord neg_vec(struct coord v)
{
 v.x = -v.x;
 v.y = -v.y;
 return v;
}


decompiled_code:
unsigned __int64 __fastcall rotate_r(__int64 a1, int a2, double a3)
{
double v4; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a3 / 180.0 * 3.141592653589793, sinx, &v4);
return ((unsigned __int64)(unsigned int)(int)((double)SHIDWORD(a1) + sinx[0] * (double)a2) << 32) | (unsigned int)(int)((double)a2 * v4 + (double)(int)a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(__int64 a1, int a2, double a3)
{
double v4; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

sincos(a3 / 180.0 * 3.141592653589793, sinx, &v4);
return ((unsigned __int64)(unsigned int)(int)((double)SHIDWORD(a1) + sinx[0] * (double)a2) << 32) | (unsigned int)(int)((double)a2 * v4 + (double)(int)a1);
}

original_code:
struct coord rotate_r(struct coord c, unit_type r, double angle)
{
 struct coord p;
 angle = angle/180.0*3.14159265358979323846;
 p.x = c.x+r*cos(angle);
 p.y = c.y+r*sin(angle);
 return p;
}

canonical_original_code:
struct coord rotate_r(struct coord c, int r, double angle)
{
 struct coord p;
 angle = angle/180.0*3.14159265358979323846;
 p.x = c.x+r*cos(angle);
 p.y = c.y+r*sin(angle);
 return p;
}

variable_types:
c
struct coord

variable_types: r int

variable_types:
p
struct coord { int x; }


decompiled_code:
double __fastcall theta_vec(__int64 a1)
{
double result; // xmm0_8

result = atan2((double)SHIDWORD(a1), (double)(int)a1) / 3.141592653589793 * 180.0;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

canonical_decompiled_code:
double __fastcall func11(__int64 a1)
{
double result; // xmm0_8

result = atan2((double)SHIDWORD(a1), (double)(int)a1) / 3.141592653589793 * 180.0;
if ( result < 0.0 )
result = result + 360.0;
return result;
}

variable_types:
v
struct coord { int x; }


theta

decompiled_code:
double __fastcall theta(__int64 a1, __int64 a2)
{
return theta_vec((unsigned int)(a2 - a1) | ((unsigned __int64)(unsigned int)(HIDWORD(a2) - HIDWORD(a1)) << 32));
}

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

original_code:
double theta(struct coord c, struct coord p)
{
 p.x -= c.x;
 p.y -= c.y;
 return theta_vec(p);
}

variable_types:
c
struct coord { int x; }

variable_types:
p
struct coord


decompiled_code:
__int64 __fastcall dist_point(__int64 a1, __int64 a2)
{
return (unsigned int)(int)hypot((double)((int)a1 - (int)a2), (double)(HIDWORD(a1) - HIDWORD(a2)));
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2)
{
return (unsigned int)(int)hypot((double)((int)a1 - (int)a2), (double)(HIDWORD(a1) - HIDWORD(a2)));
}

original_code:
unit_type dist_point(struct coord a, struct coord b)
{
 return hypot(a.x-b.x, a.y-b.y);
}

canonical_original_code:
int dist_point(struct coord a, struct coord b)
{
 return hypot(a.x-b.x, a.y-b.y);
}

variable_types:
a
struct coord { int x; }


decompiled_code:
__int64 __fastcall dist_line(__int64 a1, __int64 a2, __int64 a3)
{
return dist_line_xy(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a3));
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
return func2(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a3));
}

original_code:
unit_type dist_line(struct coord p, struct coord a, struct coord b)
{
 return dist_line_xy(p.x, p.y, a.x, a.y, b.x, b.y);
}

canonical_original_code:
int dist_line(struct coord p, struct coord a, struct coord b)
{
 return dist_line_xy(p.x, p.y, a.x, a.y, b.x, b.y);
}


decompiled_code:
__int64 __fastcall dist_rect(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r15
int v4; // er13
int v5; // ebp
int v6; // eax
int v7; // eax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r15
int v4; // er13
int v5; // ebp
int v6; // eax
int v7; // eax
__int64 result; // rax

v3 = a3 >> 32;
v4 = a3;
v5 = func2(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a3, SHIDWORD(a2));
v6 = func2(a1, SHIDWORD(a1), a2, SHIDWORD(a2), a2, v3);
if ( v5 > v6 )
v5 = v6;
v7 = func2(a1, SHIDWORD(a1), a2, v3, v4, v3);
if ( v5 > v7 )
v5 = v7;
result = func2(a1, SHIDWORD(a1), v4, SHIDWORD(a2), v4, v3);
if ( v5 <= (int)result )
result = (unsigned int)v5;
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


decompiled_code:
_BOOL8 __fastcall inside_rect(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ecx
int v4; // er8
_BOOL8 result; // rax
__int64 v6; // [rsp+0h] [rbp-10h] BYREF
__int64 v7; // [rsp+8h] [rbp-8h] BYREF

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

canonical_decompiled_code:
_BOOL8 __fastcall func17(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ecx
int v4; // er8
_BOOL8 result; // rax
__int64 v6; // [rsp+0h] [rbp-10h] BYREF
__int64 v7; // [rsp+8h] [rbp-8h] BYREF

v7 = a2;
v6 = a3;
func13((int *)&v7, (int *)&v6);
result = 0LL;
if ( (int)v7 <= v3 && (int)v6 >= v3 && SHIDWORD(v7) <= v4 )
result = SHIDWORD(v6) >= v4;
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;
}


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 func18(__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);
}


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 = 0LL;
if ( ((a1 + 1) & 0xFFFFFFFD) != 0 )
result = a1;
return result;
}

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

result = 0LL;
if ( ((a1 + 1) & 0xFFFFFFFD) != 0 )
result = a1;
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-28h] BYREF
int v10; // [rsp+4h] [rbp-24h]
int v11; // [rsp+8h] [rbp-20h] BYREF
int v12; // [rsp+Ch] [rbp-1Ch]

v9 = units_to_kicad(a1);
v10 = units_to_kicad(SHIDWORD(a1));
v11 = units_to_kicad(a2);
v12 = units_to_kicad(SHIDWORD(a2));
sort_coord(&v9, &v11);
v6 = v11;
*a4 = v11 - v9;
v7 = v10 + v12;
a4[1] = v12 - v10;
*a3 = (v6 + v9) / 2;
result = (unsigned int)(-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-28h] BYREF
int v10; // [rsp+4h] [rbp-24h]
int v11; // [rsp+8h] [rbp-20h] BYREF
int v12; // [rsp+Ch] [rbp-1Ch]

v9 = func0(a1);
v10 = func0(SHIDWORD(a1));
v11 = func0(a2);
v12 = func0(SHIDWORD(a2));
sort_coord(&v9, &v11);
v6 = v11;
*a4 = v11 - v9;
v7 = v10 + v12;
a4[1] = v12 - v10;
*a3 = (v6 + v9) / 2;
result = (unsigned int)(-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:
center
struct coord *

variable_types:
size
struct coord *

variable_types:
min
struct coord { int x; }

variable_types:
max
struct coord { int x; }


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

v6 = a3 - a2;
v7 = a3 >> 32;
result = 0LL;
if ( a5 == 1 )
{
if ( (int)a1 > v6 && a2 + (int)a4 > (int)a1 && (int)v7 - a2 < SHIDWORD(a1) && a2 + HIDWORD(a4) > SHIDWORD(a1) )
goto LABEL_4;
}
else if ( (int)a1 >= v6 && (int)a1 <= a2 + (int)a4 )
{
LABEL_4:
result = 0LL;
if ( (int)v7 - 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)
{
int v6; // edx
__int64 v7; // r9
_BOOL8 result; // rax

v6 = a3 - a2;
v7 = a3 >> 32;
result = 0LL;
if ( a5 == 1 )
{
if ( (int)a1 > v6 && a2 + (int)a4 > (int)a1 && (int)v7 - a2 < SHIDWORD(a1) && a2 + HIDWORD(a4) > SHIDWORD(a1) )
goto LABEL_4;
}
else if ( (int)a1 >= v6 && (int)a1 <= a2 + (int)a4 )
{
LABEL_4:
result = 0LL;
if ( (int)v7 - 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:
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)
{
_BOOL8 result; // rax

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

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

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

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)
{
int v5; // ebx
_BOOL8 result; // rax

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

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

v5 = a2 + a4;
if ( a5 == 1 )
result = (int)dist_point(a1, a3) < v5;
else
result = (int)dist_point(a1, a3) <= v5;
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:
_BOOL8 __fastcall shapes_overlap(int *a1, int *a2, int a3)
{
int v3; // eax
_BOOL8 result; // rax
int *v5; // rt0

v3 = *a2;
if ( *a1 )
{
if ( !v3 )
return circle_rect_overlap(*(_QWORD *)(a1 + 1), a1[3], *((_QWORD *)a2 + 2), *((_QWORD *)a2 + 3), a3);
result = circle_circle_overlap(*(_QWORD *)(a1 + 1), a1[3], *(_QWORD *)(a2 + 1), a2[3], a3);
}
else
{
if ( v3 )
{
v5 = a2;
a2 = a1;
a1 = v5;
return circle_rect_overlap(*(_QWORD *)(a1 + 1), a1[3], *((_QWORD *)a2 + 2), *((_QWORD *)a2 + 3), a3);
}
result = rect_rect_overlap(*((_QWORD *)a1 + 2), *((_QWORD *)a1 + 3), *((_QWORD *)a2 + 2), *((_QWORD *)a2 + 3), 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-28h] BYREF
int v10; // [rsp+4h] [rbp-24h]
int v11; // [rsp+8h] [rbp-20h] BYREF
int v12; // [rsp+Ch] [rbp-1Ch]

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int *a3, _DWORD *a4)
{
int v6; // edx
int v7; // eax
__int64 result; // rax
int v9; // [rsp+0h] [rbp-28h] BYREF
int v10; // [rsp+4h] [rbp-24h]
int v11; // [rsp+8h] [rbp-20h] BYREF
int v12; // [rsp+Ch] [rbp-1Ch]

v9 = func0(a1);
v10 = func0(SHIDWORD(a1));
v11 = func0(a2);
v12 = func0(SHIDWORD(a2));
sort_coord(&v9, &v11);
v6 = v11;
*a4 = v11 - v9;
v7 = v10 + v12;
a4[1] = v12 - v10;
*a3 = (v6 + v9) / 2;
result = (unsigned int)(-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;
}

variable_types:
b
struct coord


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)
{
_BOOL4 v2; // er8
signed int v3; // edx
signed int v4; // eax

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

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

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

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:
_BOOL8 __fastcall better_next(_BOOL8 (__fastcall *a1)(__int64 a1, __int64 a2), __int64 a2, __int64 a3, __int64 a4)
{
if ( !a1(a2, a3) )
return 1LL;
if ( !a1(a2, a4) )
return 0LL;
if ( a1(a4, a3) )
return 1LL;
if ( a1(a3, a4) || a1 == lt_xy )
return 0LL;
if ( !a1 )
return closer(HIDWORD(a4) - HIDWORD(a2), HIDWORD(a3) - HIDWORD(a2));
if ( a1 != lt_y )
better_next_cold();
return closer((int)a4 - (int)a2, (int)a3 - (int)a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_BOOL8 (__fastcall *a1)(__int64 a1, __int64 a2), __int64 a2, __int64 a3, __int64 a4)
{
if ( !a1(a2, a3) )
return 1LL;
if ( !a1(a2, a4) )
return 0LL;
if ( a1(a4, a3) )
return 1LL;
if ( a1(a3, a4) || a1 == lt_xy )
return 0LL;
if ( !a1 )
return func3(HIDWORD(a4) - HIDWORD(a2), HIDWORD(a3) - HIDWORD(a2));
if ( a1 != lt_y )
func12();
return func3((int)a4 - (int)a2, (int)a3 - (int)a2);
}

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)


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

switch ( a1 )
{
case 0:
result = 8945664LL;
break;
case 1:
result = 8421376LL;
break;
case 2:
result = 0x8000LL;
break;
case 3:
result = 0x80000LL;
break;
case 4:
result = 0x800000LL;
break;
default:
JUMPOUT(0x3D5LL);
}
return result;
}

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

switch ( a1 )
{
case 0:
result = 8945664LL;
break;
case 1:
result = 8421376LL;
break;
case 2:
result = 0x8000LL;
break;
case 3:
result = 0x80000LL;
break;
case 4:
result = 0x800000LL;
break;
default:
JUMPOUT(0x3D5LL);
}
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)
{
int v1; // edx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // edx
__int64 result; // rax

v1 = a1 & 0x80000;
if ( (a1 & 0x8000) != 0 )
{
result = 0LL;
if ( !v1 )
result = (unsigned int)((a1 & 0x800000) == 0) + 1;
}
else if ( v1 )
{
result = 3LL;
}
else
{
if ( (a1 & 0x800000) == 0 )
func9();
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:
char *__fastcall pad_type_name(unsigned int a1)
{
if ( a1 > 4 )
pad_type_name_cold();
return CSWTCH_8[a1];
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
if ( a1 > 4 )
func10();
return CSWTCH_8[a1];
}

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

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
int v4; // eax
char *v5; // rdx
double v6; // xmm0_8
_BOOL8 result; // rax
double v8; // xmm0_8
double v9; // xmm0_8
char *v10; // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = strchr(nptr, 120);
if ( v1 )
{
v2 = v1;
if ( nptr == v1
|| (v3 = strtod(nptr, endptr),
v4 = mm_to_units(v3),
v5 = endptr[0],
v6 = (double)v4,
result = 0LL,
*(double *)&postscript_params[1] = v6,
*v5 == 120) )
{
result = 1LL;
if ( v2[1] )
{
v8 = strtod(v2 + 1, endptr);
v9 = (double)(int)mm_to_units(v8);
v10 = endptr[0];
*(double *)&postscript_params[2] = v9;
result = *v10 == 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
int v4; // eax
char *v5; // rdx
double v6; // xmm0_8
_BOOL8 result; // rax
double v8; // xmm0_8
double v9; // xmm0_8
char *v10; // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = strchr(nptr, 120);
if ( v1 )
{
v2 = v1;
if ( nptr == v1
|| (v3 = strtod(nptr, endptr),
v4 = func0(v3),
v5 = endptr[0],
v6 = (double)v4,
result = 0LL,
*(double *)&postscript_params[1] = v6,
*v5 == 120) )
{
result = 1LL;
if ( v2[1] )
{
v8 = strtod(v2 + 1, endptr);
v9 = (double)(int)func0(v8);
v10 = endptr[0];
*(double *)&postscript_params[2] = v9;
result = *v10 == 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 *