decompiled_code:
int month_draw()
{
const char *v0; // rbx
int v1; // er15
int v2; // ebp
int v3; // er12
double v4; // xmm0_8
size_t v5; // rax
double v6; // xmm1_8
float v7; // xmm4_4
unsigned int i; // ebx
const char *v9; // r8
int v10; // er12
__int64 v11; // rbx
unsigned int v12; // er14
int v13; // er12
int v14; // eax
int v15; // er13
int v16; // eax
int v17; // er15
int j; // ebx
unsigned int v19; // ebp
int l; // ebx
int v21; // er12
int v22; // er14
int v23; // eax
int v24; // ecx
int v25; // ebx
int v26; // ebp
int v27; // er12
int v28; // er13
int result; // eax
float v30; // [rsp+Ch] [rbp-5Ch]
float v31; // [rsp+10h] [rbp-58h]
int v32; // [rsp+10h] [rbp-58h]
float v33; // [rsp+14h] [rbp-54h]
int v34; // [rsp+18h] [rbp-50h]
unsigned int v35; // [rsp+1Ch] [rbp-4Ch]
int k; // [rsp+1Ch] [rbp-4Ch]
int v37; // [rsp+20h] [rbp-48h]
float v38; // [rsp+24h] [rbp-44h]
int v39; // [rsp+24h] [rbp-44h]
int v40; // [rsp+28h] [rbp-40h]
float v41; // [rsp+28h] [rbp-40h]

v0 = (const char *)month_to_string(SEL[1]);
v34 = start_of_month(SEL[0], SEL[1]);
v40 = days_in_month(SEL[0], SEL[1]);
v1 = weeks_in_month(SEL[0], SEL[1]);
v2 = COMPACT;
v37 = (COMPACT == 0) + 3;
v3 = COLS;
v4 = (float)COLS * 0.5;
v5 = strlen(v0) + 5;
if ( (v5 & 0x8000000000000000LL) != 0LL )
v6 = (double)(int)(v5 & 1 | (v5 >> 1)) + (double)(int)(v5 & 1 | (v5 >> 1));
else
v6 = (double)(int)v5;
v7 = v4 - v6 * 0.5;
v31 = v7;
v33 = (float)(v3 - 1) / 7.0;
v30 = (float)(v2 - v37 + LINES - 2) / (float)v1;
cal_load(SEL[0], SEL[1], 0LL, (unsigned int)v40);
if ( COMPACT )
{
wattr_on(win, 0x240000uLL, 0LL);
if ( COMPACT )
{
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x240020uLL, COLS);
if ( COMPACT && wmove(win, 1, 0) != -1 )
whline(win, 0x240020uLL, COLS);
}
}
mvwprintw(win, 0, (int)v31, "%s %d", v0, SEL[0]);
for ( i = 0; i != 7; ++i )
{
if ( v33 < 10.0 )
v9 = (const char *)day_to_str(i);
else
v9 = (const char *)day_to_string(i);
mvwprintw(win, 1, (int)((float)((float)((float)(int)i * v33) + 1.0) + 0.5), "%s", v9);
}
if ( !COMPACT || (wattr_off(win, 0x240000uLL, 0LL), !COMPACT) )
{
if ( wmove(win, 2, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
if ( v40 > 0 )
{
v10 = 0;
v32 = v1;
while ( 1 )
{
if ( SEL[2] == v10 )
wattr_on(win, 0x200000uLL, 0LL);
v38 = (float)v37;
mvwprintw(
win,
(int)((float)((float)((float)((v10 + v34) / 7) * v30) + (float)v37) + 0.5),
(int)((float)((float)((float)((v10 + v34) % 7) * v33) + 1.0) + 0.5),
"%d",
(unsigned int)(v10 + 1));
if ( SEL[2] == v10 )
wattr_off(win, 0x200000uLL, 0LL);
if ( v10 + 1 == v40 )
break;
++v10;
}
v11 = EVENTS;
v12 = 0;
while ( 1 )
{
v14 = (int)(v12 + v34) / 7;
v13 = (int)((float)((float)((float)v14 * v30) + v38) + 0.5);
v15 = (int)((float)((float)((float)(v14 + 1) * v30) + v38) + 0.5) - 2;
v16 = (int)(v12 + v34) % 7;
v17 = (int)((float)((float)((float)v16 * v33) + 1.0) + 0.5);
v35 = (int)((float)((float)((float)(v16 + 1) * v33) + 1.0) + 0.5) - (v17 + 3) - 1;
if ( v11 )
break;
LABEL_39:
if ( v40 == ++v12 )
{
v1 = v32;
goto LABEL_43;
}
}
while ( 1 )
{
if ( !(unsigned int)before(v11 + 32, SEL[0], SEL[1], v12, 24LL, 0LL) )
goto LABEL_39;
if ( !(unsigned int)before(v11 + 32, SEL[0], SEL[1], v12, 0LL, 0LL) )
break;
LABEL_33:
v11 = *(_QWORD *)(v11 + 88);
if ( !v11 )
goto LABEL_39;
}
if ( v15 == v13 )
{
if ( wmove(win, v13, v17) != -1 )
whline(win, LODWORD(acs_map[23]), 2);
}
else if ( v15 < v13 )
{
goto LABEL_32;
}
event_line(win, v11, (unsigned int)v13, (unsigned int)(v17 + 3), v35, 0LL);
LABEL_32:
++v13;
goto LABEL_33;
}
LABEL_43:
if ( v1 > 1 )
{
for ( j = 1; j != v1; ++j )
{
if ( wmove(win, (int)((float)((float)((float)j * v30) + (float)(v37 - 1)) + 0.5), 1) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS - 2);
}
}
v39 = (v34 + v40 - 1) % 7 + 1;
for ( k = 1; k != 7; ++k )
{
v21 = v34 > k;
v22 = v1 - (v39 < k);
v41 = (float)v37;
if ( wmove(win, (int)((float)((float)((float)v21 * v30) + (float)v37) + 0.5), (int)((float)((float)k * v33) + 0.5)) != -1 )
wvline(win, LODWORD(acs_map[60]), (int)(float)((float)(v22 - v21) * v30));
if ( v1 > 1 )
{
for ( l = 1; l != v1; ++l )
{
if ( v21 == l )
{
v19 = HIDWORD(acs_map[59]);
}
else if ( v22 == l )
{
v19 = acs_map[59];
}
else
{
v19 = acs_map[55];
}
if ( wmove(
win,
(int)((float)((float)((float)l * v30) + (float)(v37 - 1)) + 0.5),
(int)((float)((float)k * v33) + 0.5)) != -1 )
waddch(win, v19);
}
}
}
v23 = day_of_week(SEL[0], SEL[1], SEL[2]);
v24 = SEL[2] + v34;
v25 = (int)((float)((float)v23 * v33) + 0.5);
v26 = (int)((float)((float)(v23 + 1) * v33) + 0.5);
v27 = (int)((float)((float)((float)((float)(v24 / 7) * v30) + v41) - 1.0) + 0.5);
v28 = (int)((float)((float)((float)((float)(v24 / 7 + 1) * v30) + v41) - 1.0) + 0.5);
if ( wmove(win, v27, v25) != -1 )
wvline_set(win, nc_wacs + 77, v28 - v27);
if ( wmove(win, v27, v26) != -1 )
wvline_set(win, nc_wacs + 77, v28 - v27);
if ( wmove(win, v27, v25) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v26 - v25);
if ( wmove(win, v28, v25) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v26 - v25);
if ( wmove(win, v27, v25) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2128));
if ( wmove(win, v27, v26) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2100));
if ( wmove(win, v28, v25) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2156));
result = wmove(win, v28, v26);
if ( result != -1 )
result = wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2072));
return result;
}

canonical_decompiled_code:
int func2()
{
const char *v0; // rbx
int v1; // er15
int v2; // ebp
int v3; // er12
double v4; // xmm0_8
size_t v5; // rax
double v6; // xmm1_8
float v7; // xmm4_4
unsigned int i; // ebx
const char *v9; // r8
int v10; // er12
__int64 v11; // rbx
unsigned int v12; // er14
int v13; // er12
int v14; // eax
int v15; // er13
int v16; // eax
int v17; // er15
int j; // ebx
unsigned int v19; // ebp
int l; // ebx
int v21; // er12
int v22; // er14
int v23; // eax
int v24; // ecx
int v25; // ebx
int v26; // ebp
int v27; // er12
int v28; // er13
int result; // eax
float v30; // [rsp+Ch] [rbp-5Ch]
float v31; // [rsp+10h] [rbp-58h]
int v32; // [rsp+10h] [rbp-58h]
float v33; // [rsp+14h] [rbp-54h]
int v34; // [rsp+18h] [rbp-50h]
unsigned int v35; // [rsp+1Ch] [rbp-4Ch]
int k; // [rsp+1Ch] [rbp-4Ch]
int v37; // [rsp+20h] [rbp-48h]
float v38; // [rsp+24h] [rbp-44h]
int v39; // [rsp+24h] [rbp-44h]
int v40; // [rsp+28h] [rbp-40h]
float v41; // [rsp+28h] [rbp-40h]

v0 = (const char *)month_to_string(SEL[1]);
v34 = start_of_month(SEL[0], SEL[1]);
v40 = days_in_month(SEL[0], SEL[1]);
v1 = weeks_in_month(SEL[0], SEL[1]);
v2 = COMPACT;
v37 = (COMPACT == 0) + 3;
v3 = COLS;
v4 = (float)COLS * 0.5;
v5 = strlen(v0) + 5;
if ( (v5 & 0x8000000000000000LL) != 0LL )
v6 = (double)(int)(v5 & 1 | (v5 >> 1)) + (double)(int)(v5 & 1 | (v5 >> 1));
else
v6 = (double)(int)v5;
v7 = v4 - v6 * 0.5;
v31 = v7;
v33 = (float)(v3 - 1) / 7.0;
v30 = (float)(v2 - v37 + LINES - 2) / (float)v1;
cal_load(SEL[0], SEL[1], 0LL, (unsigned int)v40);
if ( COMPACT )
{
wattr_on(win, 0x240000uLL, 0LL);
if ( COMPACT )
{
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x240020uLL, COLS);
if ( COMPACT && wmove(win, 1, 0) != -1 )
whline(win, 0x240020uLL, COLS);
}
}
mvwprintw(win, 0, (int)v31, "%s %d", v0, SEL[0]);
for ( i = 0; i != 7; ++i )
{
if ( v33 < 10.0 )
v9 = (const char *)day_to_str(i);
else
v9 = (const char *)day_to_string(i);
mvwprintw(win, 1, (int)((float)((float)((float)(int)i * v33) + 1.0) + 0.5), "%s", v9);
}
if ( !COMPACT || (wattr_off(win, 0x240000uLL, 0LL), !COMPACT) )
{
if ( wmove(win, 2, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
if ( v40 > 0 )
{
v10 = 0;
v32 = v1;
while ( 1 )
{
if ( SEL[2] == v10 )
wattr_on(win, 0x200000uLL, 0LL);
v38 = (float)v37;
mvwprintw(
win,
(int)((float)((float)((float)((v10 + v34) / 7) * v30) + (float)v37) + 0.5),
(int)((float)((float)((float)((v10 + v34) % 7) * v33) + 1.0) + 0.5),
"%d",
(unsigned int)(v10 + 1));
if ( SEL[2] == v10 )
wattr_off(win, 0x200000uLL, 0LL);
if ( v10 + 1 == v40 )
break;
++v10;
}
v11 = EVENTS;
v12 = 0;
while ( 1 )
{
v14 = (int)(v12 + v34) / 7;
v13 = (int)((float)((float)((float)v14 * v30) + v38) + 0.5);
v15 = (int)((float)((float)((float)(v14 + 1) * v30) + v38) + 0.5) - 2;
v16 = (int)(v12 + v34) % 7;
v17 = (int)((float)((float)((float)v16 * v33) + 1.0) + 0.5);
v35 = (int)((float)((float)((float)(v16 + 1) * v33) + 1.0) + 0.5) - (v17 + 3) - 1;
if ( v11 )
break;
LABEL_39:
if ( v40 == ++v12 )
{
v1 = v32;
goto LABEL_43;
}
}
while ( 1 )
{
if ( !(unsigned int)before(v11 + 32, SEL[0], SEL[1], v12, 24LL, 0LL) )
goto LABEL_39;
if ( !(unsigned int)before(v11 + 32, SEL[0], SEL[1], v12, 0LL, 0LL) )
break;
LABEL_33:
v11 = *(_QWORD *)(v11 + 88);
if ( !v11 )
goto LABEL_39;
}
if ( v15 == v13 )
{
if ( wmove(win, v13, v17) != -1 )
whline(win, LODWORD(acs_map[23]), 2);
}
else if ( v15 < v13 )
{
goto LABEL_32;
}
event_line(win, v11, (unsigned int)v13, (unsigned int)(v17 + 3), v35, 0LL);
LABEL_32:
++v13;
goto LABEL_33;
}
LABEL_43:
if ( v1 > 1 )
{
for ( j = 1; j != v1; ++j )
{
if ( wmove(win, (int)((float)((float)((float)j * v30) + (float)(v37 - 1)) + 0.5), 1) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS - 2);
}
}
v39 = (v34 + v40 - 1) % 7 + 1;
for ( k = 1; k != 7; ++k )
{
v21 = v34 > k;
v22 = v1 - (v39 < k);
v41 = (float)v37;
if ( wmove(win, (int)((float)((float)((float)v21 * v30) + (float)v37) + 0.5), (int)((float)((float)k * v33) + 0.5)) != -1 )
wvline(win, LODWORD(acs_map[60]), (int)(float)((float)(v22 - v21) * v30));
if ( v1 > 1 )
{
for ( l = 1; l != v1; ++l )
{
if ( v21 == l )
{
v19 = HIDWORD(acs_map[59]);
}
else if ( v22 == l )
{
v19 = acs_map[59];
}
else
{
v19 = acs_map[55];
}
if ( wmove(
win,
(int)((float)((float)((float)l * v30) + (float)(v37 - 1)) + 0.5),
(int)((float)((float)k * v33) + 0.5)) != -1 )
waddch(win, v19);
}
}
}
v23 = day_of_week(SEL[0], SEL[1], SEL[2]);
v24 = SEL[2] + v34;
v25 = (int)((float)((float)v23 * v33) + 0.5);
v26 = (int)((float)((float)(v23 + 1) * v33) + 0.5);
v27 = (int)((float)((float)((float)((float)(v24 / 7) * v30) + v41) - 1.0) + 0.5);
v28 = (int)((float)((float)((float)((float)(v24 / 7 + 1) * v30) + v41) - 1.0) + 0.5);
if ( wmove(win, v27, v25) != -1 )
wvline_set(win, nc_wacs + 77, v28 - v27);
if ( wmove(win, v27, v26) != -1 )
wvline_set(win, nc_wacs + 77, v28 - v27);
if ( wmove(win, v27, v25) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v26 - v25);
if ( wmove(win, v28, v25) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v26 - v25);
if ( wmove(win, v27, v25) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2128));
if ( wmove(win, v27, v26) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2100));
if ( wmove(win, v28, v25) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2156));
result = wmove(win, v28, v26);
if ( result != -1 )
result = wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2072));
return result;
}

original_code:
void month_draw(void)
{
 const char *name = month_to_string(SEL.month);
 const int start = start_of_month(SEL.year, SEL.month);
 const int days = days_in_month(SEL.year, SEL.month);
 const int weeks = weeks_in_month(SEL.year, SEL.month);
 const int hdr = COMPACT ? 3 : 4;
 const float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0;
 const float hstep = (float)(COLS-1)/7.0;
 const float vstep = (float)(LINES-2-hdr+COMPACT)/weeks;
 cal_load(SEL.year, SEL.month, 0, days);
 if (COMPACT) wattr_on(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 if (COMPACT) (wmove((win),(0),(0)) == (-1) ? (-1) : whline((win),(' ' | ((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))),(COLS)));
 if (COMPACT) (wmove((win),(1),(0)) == (-1) ? (-1) : whline((win),(' ' | ((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))),(COLS)));
 mvwprintw(win, 0, midpt, "%s %d", name, SEL.year);
 for (int d = 0; d < 7; d++) {
  const char *str = hstep >= 10 ? day_to_string(d+SUN) : day_to_str(d+SUN);
  mvwprintw(win, 1, ((int)((1+d*hstep)+0.5)), "%s", str);
 }
 if (COMPACT) wattr_off(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 if (!COMPACT) (wmove((win),(2),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 for (int d = 0; d < days; d++) {
  int row = (start + d) / 7;
  int col = (start + d) % 7;
  if (d == SEL.day) wattr_on(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
  mvwprintw(win, ((int)((hdr+row*vstep)+0.5)), ((int)((1+col*hstep)+0.5)), "%d", d+1);
  if (d == SEL.day) wattr_off(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
 }
 event_t *event = EVENTS;
 for (int d = 0; d < days; d++) {
  int y = ((int)((hdr+(((start + d) / 7) )*vstep)+0.5));
  int e = ((int)((hdr+(((start + d) / 7)+1)*vstep)+0.5))-2;
  int x = ((int)((1 +(((start + d) % 7) )*hstep)+0.5))+3;
  int w = ((int)((1 +(((start + d) % 7)+1)*hstep)+0.5))-x-1;
  while (event && before(&event->start, SEL.year, SEL.month, d, 24, 0)) {
   if (!before(&event->start, SEL.year, SEL.month, d, 0, 0)){
    if (y == e) (wmove((win),(y),(x-3)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('.'))])),(2)));
    if (y <= e) event_line(win, event, y, x, w, 0);
    y++;
   }
   event = event->next;
  }
 }
 for (int w = 1; w < weeks; w++)
  (wmove((win),(((int)((hdr-1+w*vstep)+0.5))),(1)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS-2)));
 for (int d = 1; d < 7; d++) {
  int top = d >= start ? 0 : 1;
  int bot = d <= (start+days-1)%7+1 ? weeks : weeks-1;
  (wmove((win),(((int)((hdr+top*vstep)+0.5))),(((int)((d*hstep)+0.5)))) == (-1) ? (-1) : wvline((win),((acs_map[(unsigned char)(('x'))])),((bot-top)*vstep)));
  for (int w = 1; w < weeks; w++) {
   int chr = w == top ? (acs_map[(unsigned char)(('w'))]) :
      w == bot ? (acs_map[(unsigned char)(('v'))]) : (acs_map[(unsigned char)(('n'))]);
   (wmove((win),(((int)((hdr-1+w*vstep)+0.5))),(((int)((d*hstep)+0.5)))) == (-1) ? (-1) : waddch((win),(chr)));
  }
 }
 int col = day_of_week(SEL.year, SEL.month, SEL.day);
 int row = (start+SEL.day) / 7;
 int l = ((int)(((col+0)*hstep)+0.5));
 int r = ((int)(((col+1)*hstep)+0.5));
 int t = ((int)(((row+0)*vstep+hdr-1)+0.5));
 int b = ((int)(((row+1)*vstep+hdr-1)+0.5));
 (wmove(win,(t),(l)) == (-1) ? (-1) : wvline_set((win),((&_nc_wacs[(unsigned char)(('X'))])),(b-t)));
 (wmove(win,(t),(r)) == (-1) ? (-1) : wvline_set((win),((&_nc_wacs[(unsigned char)(('X'))])),(b-t)));
 (wmove(win,(t),(l)) == (-1) ? (-1) : whline_set((win),((&_nc_wacs[(unsigned char)(('Q'))])),(r-l)));
 (wmove(win,(b),(l)) == (-1) ? (-1) : whline_set((win),((&_nc_wacs[(unsigned char)(('Q'))])),(r-l)));
 (wmove(win,(t),(l)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('L'))]))));
 (wmove(win,(t),(r)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('K'))]))));
 (wmove(win,(b),(l)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('M'))]))));
 (wmove(win,(b),(r)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('J'))]))));
}

canonical_original_code:
void month_draw()
{
 char *name = month_to_string(SEL.month);
 int start = start_of_month(SEL.year, SEL.month);
 int days = days_in_month(SEL.year, SEL.month);
 int weeks = weeks_in_month(SEL.year, SEL.month);
 int hdr = COMPACT ? 3 : 4;
 float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0;
 float hstep = (float)(COLS-1)/7.0;
 float vstep = (float)(LINES-2-hdr+COMPACT)/weeks;
 cal_load(SEL.year, SEL.month, 0, days);
 if (COMPACT) wattr_on(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 if (COMPACT) (wmove((win),(0),(0)) == (-1) ? (-1) : whline((win),(' ' | ((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))),(COLS)));
 if (COMPACT) (wmove((win),(1),(0)) == (-1) ? (-1) : whline((win),(' ' | ((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))),(COLS)));
 mvwprintw(win, 0, midpt, "%s %d", name, SEL.year);
 for (int d = 0; d < 7; d++) {
  char *str = hstep >= 10 ? day_to_string(d+SUN) : day_to_str(d+SUN);
  mvwprintw(win, 1, ((int)((1+d*hstep)+0.5)), "%s", str);
 }
 if (COMPACT) wattr_off(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 if (!COMPACT) (wmove((win),(2),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 for (int d = 0; d < days; d++) {
  int row = (start + d) / 7;
  int col = (start + d) % 7;
  if (d == SEL.day) wattr_on(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
  mvwprintw(win, ((int)((hdr+row*vstep)+0.5)), ((int)((1+col*hstep)+0.5)), "%d", d+1);
  if (d == SEL.day) wattr_off(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
 }
 struct event_t *event = EVENTS;
 for (int d = 0; d < days; d++) {
  int y = ((int)((hdr+(((start + d) / 7) )*vstep)+0.5));
  int e = ((int)((hdr+(((start + d) / 7)+1)*vstep)+0.5))-2;
  int x = ((int)((1 +(((start + d) % 7) )*hstep)+0.5))+3;
  int w = ((int)((1 +(((start + d) % 7)+1)*hstep)+0.5))-x-1;
  while (event && before(&event->start, SEL.year, SEL.month, d, 24, 0)) {
   if (!before(&event->start, SEL.year, SEL.month, d, 0, 0)){
    if (y == e) (wmove((win),(y),(x-3)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('.'))])),(2)));
    if (y <= e) event_line(win, event, y, x, w, 0);
    y++;
   }
   event = event->next;
  }
 }
 for (int w = 1; w < weeks; w++)
  (wmove((win),(((int)((hdr-1+w*vstep)+0.5))),(1)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS-2)));
 for (int d = 1; d < 7; d++) {
  int top = d >= start ? 0 : 1;
  int bot = d <= (start+days-1)%7+1 ? weeks : weeks-1;
  (wmove((win),(((int)((hdr+top*vstep)+0.5))),(((int)((d*hstep)+0.5)))) == (-1) ? (-1) : wvline((win),((acs_map[(unsigned char)(('x'))])),((bot-top)*vstep)));
  for (int w = 1; w < weeks; w++) {
   int chr = w == top ? (acs_map[(unsigned char)(('w'))]) :
      w == bot ? (acs_map[(unsigned char)(('v'))]) : (acs_map[(unsigned char)(('n'))]);
   (wmove((win),(((int)((hdr-1+w*vstep)+0.5))),(((int)((d*hstep)+0.5)))) == (-1) ? (-1) : waddch((win),(chr)));
  }
 }
 int col = day_of_week(SEL.year, SEL.month, SEL.day);
 int row = (start+SEL.day) / 7;
 int l = ((int)(((col+0)*hstep)+0.5));
 int r = ((int)(((col+1)*hstep)+0.5));
 int t = ((int)(((row+0)*vstep+hdr-1)+0.5));
 int b = ((int)(((row+1)*vstep+hdr-1)+0.5));
 (wmove(win,(t),(l)) == (-1) ? (-1) : wvline_set((win),((&_nc_wacs[(unsigned char)(('X'))])),(b-t)));
 (wmove(win,(t),(r)) == (-1) ? (-1) : wvline_set((win),((&_nc_wacs[(unsigned char)(('X'))])),(b-t)));
 (wmove(win,(t),(l)) == (-1) ? (-1) : whline_set((win),((&_nc_wacs[(unsigned char)(('Q'))])),(r-l)));
 (wmove(win,(b),(l)) == (-1) ? (-1) : whline_set((win),((&_nc_wacs[(unsigned char)(('Q'))])),(r-l)));
 (wmove(win,(t),(l)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('L'))]))));
 (wmove(win,(t),(r)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('K'))]))));
 (wmove(win,(b),(l)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('M'))]))));
 (wmove(win,(b),(r)) == (-1) ? (-1) : wadd_wch((win),((&_nc_wacs[(unsigned char)(('J'))]))));
}

variable_types:
name
char *

variable_types: start int

variable_types: weeks int

variable_types: hdr int

variable_types: midpt float

variable_types: hstep float

variable_types: vstep float

variable_types: d int

variable_types:
str
char *

variable_types: y int

variable_types: e int

variable_types: x int

variable_types: w int

variable_types: top int

variable_types: bot int

variable_types: chr int

variable_types: l int

variable_types: r int

variable_types: t int

variable_types: b int

user_defined_types: struct cal_t { char *type; char *name; char *desc; struct cal_t *next; }


decompiled_code:
_BOOL8 __fastcall month_run(int a1)
{
unsigned int v1; // ebx
int v2; // ecx
int v3; // ebp

switch ( a1 )
{
case 'h':
v1 = 0;
v2 = -1;
goto LABEL_4;
case 'i':
v1 = -1;
v2 = 0;
goto LABEL_4;
case 'j':
v1 = 0;
v2 = 7;
goto LABEL_4;
case 'k':
v1 = 0;
v2 = -7;
goto LABEL_4;
case 'l':
v1 = 0;
v2 = 1;
goto LABEL_4;
case 'o':
v1 = 1;
v2 = 0;
LABEL_4:
v3 = v1 | v2;
add_days(SEL, (unsigned int)((_DWORD)SEL + 4), (unsigned int)((_DWORD)SEL + 8));
add_months(SEL, (unsigned int)((_DWORD)SEL + 4), v1);
werase(win);
month_draw();
wrefresh(win);
break;
default:
v3 = 0;
break;
}
return v3 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
unsigned int v1; // ebx
int v2; // ecx
int v3; // ebp

switch ( a1 )
{
case 'h':
v1 = 0;
v2 = -1;
goto LABEL_4;
case 'i':
v1 = -1;
v2 = 0;
goto LABEL_4;
case 'j':
v1 = 0;
v2 = 7;
goto LABEL_4;
case 'k':
v1 = 0;
v2 = -7;
goto LABEL_4;
case 'l':
v1 = 0;
v2 = 1;
goto LABEL_4;
case 'o':
v1 = 1;
v2 = 0;
LABEL_4:
v3 = v1 | v2;
add_days(SEL, (unsigned int)((_DWORD)SEL + 4), (unsigned int)((_DWORD)SEL + 8));
add_months(SEL, (unsigned int)((_DWORD)SEL + 4), v1);
werase(win);
func2();
wrefresh(win);
break;
default:
v3 = 0;
break;
}
return v3 != 0;
}

original_code:
int month_run(int key, mmask_t btn, int row, int col)
{
 int days = 0, months = 0;
 switch (key)
 {
  case 'h': days = -1; break;
  case 'j': days = 7; break;
  case 'k': days = -7; break;
  case 'l': days = 1; break;
  case 'i': months = -1; break;
  case 'o': months = 1; break;
 }
 if (days || months) {
  add_days(&SEL.year, &SEL.month, &SEL.day, days);
  add_months(&SEL.year, &SEL.month, months);
  werase(win);
  month_draw();
  wrefresh(win);
 }
 return days || months;
}

canonical_original_code:
int month_run(int key, unsigned int btn, int row, int col)
{
 int days = 0; int months = 0;
 switch (key)
 {
  case 'h': days = -1; break;
  case 'j': days = 7; break;
  case 'k': days = -7; break;
  case 'l': days = 1; break;
  case 'i': months = -1; break;
  case 'o': months = 1; break;
 }
 if (days || months) {
  add_days(&SEL.year, &SEL.month, &SEL.day, days);
  add_months(&SEL.year, &SEL.month, months);
  werase(win);
  month_draw();
  wrefresh(win);
 }
 return days || months;
}

variable_types: key int

variable_types:
btn
unsigned int

variable_types: row int

variable_types: col int

variable_types: days int

variable_types: months int

return_type: int


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

if ( a2 <= 0 )
return (unsigned int)(a2 - 1);
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !*(_QWORD *)(a1 + 8 * v2) )
break;
if ( ++v2 == a2 )
return (unsigned int)(a2 - 1);
}
return v3;
}

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

if ( a2 <= 0 )
return (unsigned int)(a2 - 1);
v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !*(_QWORD *)(a1 + 8 * v2) )
break;
if ( ++v2 == a2 )
return (unsigned int)(a2 - 1);
}
return v3;
}

original_code:
static int next_free(event_t **list, int n)
{
 for (int i = 0; i < n; i++)
  if (!list[i])
   return i;
 return n-1;
}

canonical_original_code:
static int next_free(struct event_t **list, int n)
{
 for (int i = 0; i < n; i++)
  if (!list[i])
   return i;
 return n-1;
}

variable_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t end; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct event_t *next; struct event_t *prev; } **

variable_types: n int

variable_types: i int

user_defined_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t start; struct date_t end; struct cal_t *cal; struct event_t *next; struct event_t *prev; }

user_defined_types: struct date_t { int year; enum month_t month; int day; int hour; int min; int sec; }


decompiled_code:
__int64 __fastcall count_busy(_QWORD *a1, int a2)
{
_QWORD *v2; // rax
unsigned int v3; // edx

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 -= (*v2++ == 0LL) - 1;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

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

if ( a2 <= 0 )
return 0;
v2 = a1;
v3 = 0;
do
v3 -= (*v2++ == 0LL) - 1;
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
return v3;
}

original_code:
static int count_busy(event_t **list, int n)
{
 int sum = 0;
 for (int i = 0; i < n; i++)
  if (list[i])
   sum++;
 return sum;
}

canonical_original_code:
static int count_busy(struct event_t **list, int n)
{
 int sum = 0;
 for (int i = 0; i < n; i++)
  if (list[i])
   sum++;
 return sum;
}

variable_types: sum int

user_defined_types: enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 }


original_code:
static void clear_old(event_t **list, int n, event_t *cur)
{
 for (int i = 0; i < n; i++)
  if (list[i] && compare(&list[i]->end, &cur->start) <= 0)
   list[i] = ((void *)0);
}

canonical_original_code:
static void clear_old(struct event_t **list, int n, struct event_t *cur)
{
 for (int i = 0; i < n; i++)
  if (list[i] && compare(&list[i]->end, &cur->start) <= 0)
   list[i] = ((void *)0);
}

variable_types:
cur
struct event_t *

return_type: void


decompiled_code:
__int64 __fastcall get_ncols(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
void *v4; // rsp
unsigned int v5; // er13
int v6; // eax
int v7; // eax
__int64 v8; // rdx
_QWORD v10[4]; // [rsp+0h] [rbp-20h] BYREF

v2 = a1;
v3 = 8LL * a2;
v4 = alloca(v3);
memset(v10, 0, v3);
if ( !a1 )
return 0;
v5 = 0;
do
{
v6 = next_free((__int64)v10, a2);
v10[v6] = v2;
v7 = v6 + 1;
if ( (int)v5 < v7 )
v5 = v7;
v8 = *(_QWORD *)(v2 + 88);
if ( !v8 )
break;
clear_old(v10, a2, v8);
if ( !(unsigned int)count_busy(v10, a2) )
break;
v2 = *(_QWORD *)(v2 + 88);
}
while ( v2 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
void *v4; // rsp
unsigned int v5; // er13
int v6; // eax
int v7; // eax
__int64 v8; // rdx
_QWORD v10[4]; // [rsp+0h] [rbp-20h] BYREF

v2 = a1;
v3 = 8LL * a2;
v4 = alloca(v3);
memset(v10, 0, v3);
if ( !a1 )
return 0;
v5 = 0;
do
{
v6 = func0((__int64)v10, a2);
v10[v6] = v2;
v7 = v6 + 1;
if ( (int)v5 < v7 )
v5 = v7;
v8 = *(_QWORD *)(v2 + 88);
if ( !v8 )
break;
func2(v10, a2, v8);
if ( !(unsigned int)func1(v10, a2) )
break;
v2 = *(_QWORD *)(v2 + 88);
}
while ( v2 );
return v5;
}

original_code:
static int get_ncols(event_t *event, int n)
{
 int ncols = 0;
 event_t *preview[n];
 memset(preview, 0, sizeof(preview));
 for (event_t *cur = event; cur; cur = cur->next) {
  int col = next_free(preview, n);
  preview[col] = cur;
  ncols = ((ncols) > (col+1) ? (ncols) : (col+1));
  if (cur->next)
   clear_old(preview, n, cur->next);
  if (count_busy(preview, n) == 0)
   break;
 }
 return ncols;
}

canonical_original_code:
static int get_ncols(struct event_t *event, int n)
{
 int ncols = 0;
 struct event_t *preview[-1];
 memset(preview, 0, sizeof(preview));
 for (struct event_t *cur = event; cur; cur = cur->next) {
  int col = next_free(preview, n);
  preview[col] = cur;
  ncols = ((ncols) > (col+1) ? (ncols) : (col+1));
  if (cur->next)
   clear_old(preview, n, cur->next);
  if (count_busy(preview, n) == 0)
   break;
 }
 return ncols;
}

variable_types: ncols int

variable_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t end; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct event_t *next; struct event_t *prev; } *[-1]


decompiled_code:
__int64 __fastcall get_col(_QWORD *a1, int a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax

clear_old(a1, a2, a3);
if ( !(unsigned int)count_busy(a1, a2) )
*a4 = get_ncols(a3, a2);
result = next_free((__int64)a1, a2);
a1[(int)result] = a3;
return result;
}

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

func2(a1, a2, a3);
if ( !(unsigned int)func1(a1, a2) )
*a4 = func3(a3, a2);
result = func0((__int64)a1, a2);
a1[(int)result] = a3;
return result;
}

original_code:
int get_col(event_t **list, int n, event_t *event, int *ncols)
{
 clear_old(list, n, event);
 if (count_busy(list, n) == 0)
  *ncols = get_ncols(event, n);
 int col = next_free(list, n);
 list[col] = event;
 return col;
}

canonical_original_code:
int get_col(struct event_t **list, int n, struct event_t *event, int *ncols)
{
 clear_old(list, n, event);
 if (count_busy(list, n) == 0)
  *ncols = get_ncols(event, n);
 int col = next_free(list, n);
 list[col] = event;
 return col;
}

variable_types:
event
struct event_t *

variable_types:
ncols
int *


decompiled_code:
void __fastcall move_event(int a1, unsigned int a2, int *a3)
{
int v5; // er13
__int64 v6; // rsi
int v7; // eax
const __m128i *v8; // rax
__m128i v9; // [rsp+0h] [rbp-48h] BYREF
__int64 v10; // [rsp+10h] [rbp-38h]

if ( a1 && EVENT )
{
v5 = 0;
if ( a1 <= 0 )
{
do
{
if ( !*(_QWORD *)(EVENT + 88LL) )
break;
if ( !(unsigned int)same_day(EVENT + 32LL, *(_QWORD *)(EVENT + 96LL) + 32LL) )
break;
EVENT = *(_QWORD *)(EVENT + 96LL);
--v5;
}
while ( a1 != v5 );
}
else
{
do
{
v6 = *(_QWORD *)(EVENT + 88LL);
if ( !v6 )
break;
if ( !(unsigned int)same_day(EVENT + 32LL, v6 + 32) )
break;
EVENT = *(_QWORD *)(EVENT + 88LL);
++v5;
}
while ( a1 != v5 );
}
}
if ( a2 )
{
add_days(&SEL, (unsigned int)((_DWORD)&SEL + 4), (unsigned int)((_DWORD)&SEL + 8), a2);
v9 = _mm_loadu_si128((const __m128i *)&SEL);
v10 = *((_QWORD *)&SEL + 2);
if ( EVENT )
{
v9.m128i_i32[3] = *(_DWORD *)(EVENT + 44LL);
v10 = *(_QWORD *)(EVENT + 48LL);
}
v8 = (const __m128i *)find_event(&v9);
EVENT = v8;
if ( v8 )
{
SEL = _mm_loadu_si128(v8 + 2);
*((_QWORD *)&SEL + 2) = v8[3].m128i_i64[0];
}
}
if ( a3 && EVENT && !(unsigned int)all_day(EVENT + 32LL, EVENT + 56LL) )
{
v7 = *(_DWORD *)(EVENT + 48LL) / 15 + 4 * *(_DWORD *)(EVENT + 44LL);
if ( v7 + 3 >= *a3 + LINES + 2 * COMPACT - 4 )
*a3 = v7 - (LINES + 2 * COMPACT - 4) + 4;
if ( *a3 > v7 )
*a3 = v7;
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, unsigned int a2, int *a3)
{
int v5; // er13
__int64 v6; // rsi
int v7; // eax
const __m128i *v8; // rax
__m128i v9; // [rsp+0h] [rbp-48h] BYREF
__int64 v10; // [rsp+10h] [rbp-38h]

if ( a1 && EVENT )
{
v5 = 0;
if ( a1 <= 0 )
{
do
{
if ( !*(_QWORD *)(EVENT + 88LL) )
break;
if ( !(unsigned int)same_day(EVENT + 32LL, *(_QWORD *)(EVENT + 96LL) + 32LL) )
break;
EVENT = *(_QWORD *)(EVENT + 96LL);
--v5;
}
while ( a1 != v5 );
}
else
{
do
{
v6 = *(_QWORD *)(EVENT + 88LL);
if ( !v6 )
break;
if ( !(unsigned int)same_day(EVENT + 32LL, v6 + 32) )
break;
EVENT = *(_QWORD *)(EVENT + 88LL);
++v5;
}
while ( a1 != v5 );
}
}
if ( a2 )
{
add_days(&SEL, (unsigned int)((_DWORD)&SEL + 4), (unsigned int)((_DWORD)&SEL + 8), a2);
v9 = _mm_loadu_si128((const __m128i *)&SEL);
v10 = *((_QWORD *)&SEL + 2);
if ( EVENT )
{
v9.m128i_i32[3] = *(_DWORD *)(EVENT + 44LL);
v10 = *(_QWORD *)(EVENT + 48LL);
}
v8 = (const __m128i *)find_event(&v9);
EVENT = v8;
if ( v8 )
{
SEL = _mm_loadu_si128(v8 + 2);
*((_QWORD *)&SEL + 2) = v8[3].m128i_i64[0];
}
}
if ( a3 && EVENT && !(unsigned int)all_day(EVENT + 32LL, EVENT + 56LL) )
{
v7 = *(_DWORD *)(EVENT + 48LL) / 15 + 4 * *(_DWORD *)(EVENT + 44LL);
if ( v7 + 3 >= *a3 + LINES + 2 * COMPACT - 4 )
*a3 = v7 - (LINES + 2 * COMPACT - 4) + 4;
if ( *a3 > v7 )
*a3 = v7;
}
}

original_code:
void move_event(int events, int days, int *line)
{
 if (events && EVENT) {
  for (int i=0; i<events && EVENT->next &&
    same_day(&EVENT->start, &EVENT->next->start); i++)
   EVENT = EVENT->next;
  for (int i=0; i>events && EVENT->next &&
    same_day(&EVENT->start, &EVENT->prev->start); i--)
   EVENT = EVENT->prev;
 }
 if (days) {
  add_days(&SEL.year, &SEL.month, &SEL.day, days);
  date_t target = SEL;
  if (EVENT) {
   target.hour = EVENT->start.hour;
   target.min = EVENT->start.min;
   target.sec = EVENT->start.sec;
  }
  if ((EVENT = find_event(&target)))
   SEL = EVENT->start;
 }
 if (line && EVENT && !all_day(&EVENT->start, &EVENT->end)) {
  int lines = LINES-4+COMPACT+COMPACT;
  int begin = EVENT->start.hour * 4
            + EVENT->start.min / 15;
  if (begin+4 > *line+lines)
   *line = begin-lines+4;
  if (begin < *line)
   *line = begin;
 }
}

canonical_original_code:
void move_event(int events, int days, int *line)
{
 if (events && EVENT) {
  for (int i = 0; i<events && EVENT->next &&
    same_day(&EVENT->start, &EVENT->next->start); i++)
   EVENT = EVENT->next;
  for (int i = 0; i>events && EVENT->next &&
    same_day(&EVENT->start, &EVENT->prev->start); i--)
   EVENT = EVENT->prev;
 }
 if (days) {
  add_days(&SEL.year, &SEL.month, &SEL.day, days);
  struct date_t target = SEL;
  if (EVENT) {
   target.hour = EVENT->start.hour;
   target.min = EVENT->start.min;
   target.sec = EVENT->start.sec;
  }
  if ((EVENT = find_event(&target)))
   SEL = EVENT->start;
 }
 if (line && EVENT && !all_day(&EVENT->start, &EVENT->end)) {
  int lines = LINES-4+COMPACT+COMPACT;
  int begin = EVENT->start.hour * 4
            + EVENT->start.min / 15;
  if (begin+4 > *line+lines)
   *line = begin-lines+4;
  if (begin < *line)
   *line = begin;
 }
}

variable_types: events int

variable_types:
line
int *

variable_types: struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; }

variable_types: lines int

variable_types: begin int


decompiled_code:
__int64 __fastcall day_size(int a1, int a2)
{
unsigned int v2; // ebx

v2 = 2 - COMPACT;
wmvresize(times, (unsigned int)(2 - COMPACT), 0LL, (unsigned int)(a1 - (2 - COMPACT)), 5LL);
return wmvresize(body, v2, 5LL, a1 - v2, (unsigned int)(a2 - 5));
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
unsigned int v2; // ebx

v2 = 2 - COMPACT;
wmvresize(times, (unsigned int)(2 - COMPACT), 0LL, (unsigned int)(a1 - (2 - COMPACT)), 5LL);
return wmvresize(body, v2, 5LL, a1 - v2, (unsigned int)(a2 - 5));
}

original_code:
void day_size(int rows, int cols)
{
 int hdr = 2-COMPACT;
 wmvresize(times, hdr, 0, rows-hdr, 5);
 wmvresize(body, hdr, 5, rows-hdr, cols-5);
}

variable_types: rows int

variable_types: cols int

variable_types: hdr int


decompiled_code:
int day_draw()
{
const char *v0; // rbp
unsigned int v1; // eax
const char *v2; // rbx
int v3; // er13
__int64 v4; // rbx
unsigned int v5; // er13
int i; // ebx
__int64 v7; // rbx
unsigned int j; // er15
double v9; // xmm1_8
int v10; // eax
unsigned int k; // er13
int result; // eax
__int64 v13; // [rsp+0h] [rbp-E8h]
double v14; // [rsp+30h] [rbp-B8h]
double v15; // [rsp+38h] [rbp-B0h]
int v16; // [rsp+40h] [rbp-A8h]
unsigned int v17; // [rsp+44h] [rbp-A4h]
int v18; // [rsp+4Ch] [rbp-9Ch]
int v19; // [rsp+5Ch] [rbp-8Ch] BYREF
__int64 v20[17]; // [rsp+60h] [rbp-88h] BYREF

v0 = (const char *)month_to_string(SEL[1]);
v1 = day_of_week(SEL[0], SEL[1], SEL[2]);
v2 = (const char *)day_to_string(v1);
v3 = (COMPACT == 0) + 1;
cal_load(SEL[0], SEL[1], SEL[2], 1LL);
if ( COMPACT )
wattr_on(win, 0x240000uLL, 0LL);
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x20uLL, COLS);
mvwprintw(win, 0, 0, "%s, %s %d", v2, v0, SEL[2] + 1);
LODWORD(v13) = SEL[2] + 1;
mvwprintw(win, 0, COLS - 10, "%d-%02d-%02d", SEL[0], SEL[1] + 1, v13);
if ( COMPACT )
wattr_off(win, 0x240000uLL, 0LL);
v4 = EVENTS;
v18 = 0;
if ( EVENTS )
{
do
{
if ( !(unsigned int)before(v4 + 32, SEL[0], SEL[1], SEL[2], 24LL, 0LL) )
break;
if ( !(unsigned int)before(v4 + 56, SEL[0], SEL[1], SEL[2], 0LL, 1LL) && (int)get_mins(v4 + 32, v4 + 56) > 1380 )
event_line(win, v4, (unsigned int)(v3 + v18++), 6LL, (unsigned int)(COLS - 6), 3LL);
v4 = *(_QWORD *)(v4 + 88);
}
while ( v4 );
if ( v18 )
v18 += COMPACT == 0;
}
v5 = v18 + v3;
wshrink(times, v5);
wshrink(body, v5);
mvwprintw(times, 0, 0, "%02d:%02d", (unsigned int)((line / 4 - 1) % 12 + 1), (unsigned int)(15 * line % 60));
for ( i = 0; i != 24; ++i )
mvwprintw(times, 4 * i - line, 0, "%02d:%02d", (unsigned int)((i - 1) % 12 + 1), 0LL);
if ( !EVENT )
EVENT = find_event(SEL);
v7 = EVENTS;
v20[0] = 0LL;
v20[1] = 0LL;
v20[2] = 0LL;
v20[3] = 0LL;
v20[4] = 0LL;
v20[5] = 0LL;
v20[6] = 0LL;
v20[7] = 0LL;
v20[8] = 0LL;
v20[9] = 0LL;
v19 = 0;
for ( j = 0; j != 24; ++j )
{
for ( k = 0; k != 60; k += 15 )
{
for ( ; v7; v7 = *(_QWORD *)(v7 + 88) )
{
if ( !(unsigned int)before(
v7 + 32,
SEL[0],
SEL[1],
SEL[2],
j + (int)(k + 15) / 60,
(unsigned int)((int)(k + 15) % 60)) )
break;
if ( !(unsigned int)before(v7 + 32, SEL[0], SEL[1], SEL[2], j, k) && (int)get_mins(v7 + 32, v7 + 56) <= 1380 )
{
v9 = (double)(int)get_col(v20, 10, v7, &v19);
v14 = (double)(COLS - 6);
v15 = (double)v19;
v16 = (int)((v9 + 0.0) * v14 / (double)v19 + 0.5);
v17 = 4 * j + (int)k / 15 - line;
v10 = get_mins(v7 + 32, v7 + 56);
event_box(
body,
v7,
v17,
(unsigned int)(v16 + 1),
(unsigned int)((v10 - 1) / 15 + 1),
(unsigned int)((int)((v9 + 1.0) * v14 / v15 + 0.5) - v16));
}
}
}
}
if ( !COMPACT )
{
if ( wmove(win, 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( !COMPACT && v18 && wmove(win, v18 + 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
result = wmove(body, 0, 0);
if ( result != -1 )
result = wvline(body, LODWORD(acs_map[60]), LINES + 2 * COMPACT - 4);
return result;
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rbp
unsigned int v1; // eax
const char *v2; // rbx
int v3; // er13
__int64 v4; // rbx
unsigned int v5; // er13
int i; // ebx
__int64 v7; // rbx
unsigned int j; // er15
double v9; // xmm1_8
int v10; // eax
unsigned int k; // er13
int result; // eax
__int64 v13; // [rsp+0h] [rbp-E8h]
double v14; // [rsp+30h] [rbp-B8h]
double v15; // [rsp+38h] [rbp-B0h]
int v16; // [rsp+40h] [rbp-A8h]
unsigned int v17; // [rsp+44h] [rbp-A4h]
int v18; // [rsp+4Ch] [rbp-9Ch]
int v19; // [rsp+5Ch] [rbp-8Ch] BYREF
__int64 v20[17]; // [rsp+60h] [rbp-88h] BYREF

v0 = (const char *)month_to_string(SEL[1]);
v1 = day_of_week(SEL[0], SEL[1], SEL[2]);
v2 = (const char *)day_to_string(v1);
v3 = (COMPACT == 0) + 1;
cal_load(SEL[0], SEL[1], SEL[2], 1LL);
if ( COMPACT )
wattr_on(win, 0x240000uLL, 0LL);
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x20uLL, COLS);
mvwprintw(win, 0, 0, "%s, %s %d", v2, v0, SEL[2] + 1);
LODWORD(v13) = SEL[2] + 1;
mvwprintw(win, 0, COLS - 10, "%d-%02d-%02d", SEL[0], SEL[1] + 1, v13);
if ( COMPACT )
wattr_off(win, 0x240000uLL, 0LL);
v4 = EVENTS;
v18 = 0;
if ( EVENTS )
{
do
{
if ( !(unsigned int)before(v4 + 32, SEL[0], SEL[1], SEL[2], 24LL, 0LL) )
break;
if ( !(unsigned int)before(v4 + 56, SEL[0], SEL[1], SEL[2], 0LL, 1LL) && (int)get_mins(v4 + 32, v4 + 56) > 1380 )
event_line(win, v4, (unsigned int)(v3 + v18++), 6LL, (unsigned int)(COLS - 6), 3LL);
v4 = *(_QWORD *)(v4 + 88);
}
while ( v4 );
if ( v18 )
v18 += COMPACT == 0;
}
v5 = v18 + v3;
wshrink(times, v5);
wshrink(body, v5);
mvwprintw(times, 0, 0, "%02d:%02d", (unsigned int)((line / 4 - 1) % 12 + 1), (unsigned int)(15 * line % 60));
for ( i = 0; i != 24; ++i )
mvwprintw(times, 4 * i - line, 0, "%02d:%02d", (unsigned int)((i - 1) % 12 + 1), 0LL);
if ( !EVENT )
EVENT = find_event(SEL);
v7 = EVENTS;
v20[0] = 0LL;
v20[1] = 0LL;
v20[2] = 0LL;
v20[3] = 0LL;
v20[4] = 0LL;
v20[5] = 0LL;
v20[6] = 0LL;
v20[7] = 0LL;
v20[8] = 0LL;
v20[9] = 0LL;
v19 = 0;
for ( j = 0; j != 24; ++j )
{
for ( k = 0; k != 60; k += 15 )
{
for ( ; v7; v7 = *(_QWORD *)(v7 + 88) )
{
if ( !(unsigned int)before(
v7 + 32,
SEL[0],
SEL[1],
SEL[2],
j + (int)(k + 15) / 60,
(unsigned int)((int)(k + 15) % 60)) )
break;
if ( !(unsigned int)before(v7 + 32, SEL[0], SEL[1], SEL[2], j, k) && (int)get_mins(v7 + 32, v7 + 56) <= 1380 )
{
v9 = (double)(int)func4(v20, 10, v7, &v19);
v14 = (double)(COLS - 6);
v15 = (double)v19;
v16 = (int)((v9 + 0.0) * v14 / (double)v19 + 0.5);
v17 = 4 * j + (int)k / 15 - line;
v10 = get_mins(v7 + 32, v7 + 56);
event_box(
body,
v7,
v17,
(unsigned int)(v16 + 1),
(unsigned int)((v10 - 1) / 15 + 1),
(unsigned int)((int)((v9 + 1.0) * v14 / v15 + 0.5) - v16));
}
}
}
}
if ( !COMPACT )
{
if ( wmove(win, 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( !COMPACT && v18 && wmove(win, v18 + 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
result = wmove(body, 0, 0);
if ( result != -1 )
result = wvline(body, LODWORD(acs_map[60]), LINES + 2 * COMPACT - 4);
return result;
}

original_code:
void day_draw(void)
{
 const char *mstr = month_to_string(SEL.month);
 const char *dstr = day_to_string(day_of_week(SEL.year, SEL.month, SEL.day));
 int y = !COMPACT+1;
 event_t *event;
 cal_load(SEL.year, SEL.month, SEL.day, 1);
 if (COMPACT) wattr_on(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 (wmove((win),(0),(0)) == (-1) ? (-1) : whline((win),(' '),(COLS)));
 mvwprintw(win, 0, 0, "%s, %s %d", dstr, mstr, SEL.day+1);
 mvwprintw(win, 0, COLS-10, "%d-%02d-%02d", SEL.year, SEL.month+1, SEL.day+1);
 if (COMPACT) wattr_off(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 event = EVENTS;
 int allday = 0;
 while (event && before(&event->start, SEL.year, SEL.month, SEL.day, 24, 0)) {
  if (!before(&event->end, SEL.year, SEL.month, SEL.day, 0, 1) &&
      get_mins(&event->start, &event->end) > 23*60)
   event_line(win, event, y+allday++, 6, COLS-6, 0x2 | 0x1);
  event = event->next;
 }
 if (allday && !COMPACT)
  allday++;
 wshrink(times, y+allday);
 wshrink(body, y+allday);
 mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
 for (int h = 0; h < 24; h++)
  mvwprintw(times, h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
 if (!EVENT)
  EVENT = find_event(&SEL);
 event = EVENTS;
 event_t *active[10] = {};
 int ncols = 0;
 for (int h = 0; h < 24; h++)
 for (int m = 0; m < 60; m+=15)
 while (event && before(&event->start,
   SEL.year, SEL.month, SEL.day, h+(m+15)/60, (m+15)%60)) {
  if (!before(&event->start, SEL.year, SEL.month, SEL.day, h, m) &&
      get_mins(&event->start, &event->end) <= 23*60) {
   int col = get_col(active, (sizeof(active)/sizeof((active)[0])), event, &ncols);
   int left = ((int)(((col+0.0)*(COLS-6)/ncols)+0.5)) + 1;
   int right = ((int)(((col+1.0)*(COLS-6)/ncols)+0.5)) + 1;
   int row = h*4 + m/15 - line;
   int height = (get_mins(&event->start, &event->end)-1)/15+1;
   event_box(body, event, row, left, height, right-left);
  }
  event = event->next;
 }
 if (!COMPACT)
  (wmove((win),(1),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 if (!COMPACT && allday)
  (wmove((win),(allday+1),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 (wmove((body),(0),(0)) == (-1) ? (-1) : wvline((body),((acs_map[(unsigned char)(('x'))])),(LINES-4+COMPACT+COMPACT)));
}

canonical_original_code:
void day_draw()
{
 char *mstr = month_to_string(SEL.month);
 char *dstr = day_to_string(day_of_week(SEL.year, SEL.month, SEL.day));
 int y = !COMPACT+1;
 struct event_t *event;
 cal_load(SEL.year, SEL.month, SEL.day, 1);
 if (COMPACT) wattr_on(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 (wmove((win),(0),(0)) == (-1) ? (-1) : whline((win),(' '),(COLS)));
 mvwprintw(win, 0, 0, "%s, %s %d", dstr, mstr, SEL.day+1);
 mvwprintw(win, 0, COLS-10, "%d-%02d-%02d", SEL.year, SEL.month+1, SEL.day+1);
 if (COMPACT) wattr_off(win, (attr_t)(((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8))), ((void *)0));
 event = EVENTS;
 int allday = 0;
 while (event && before(&event->start, SEL.year, SEL.month, SEL.day, 24, 0)) {
  if (!before(&event->end, SEL.year, SEL.month, SEL.day, 0, 1) &&
      get_mins(&event->start, &event->end) > 23*60)
   event_line(win, event, y+allday++, 6, COLS-6, 0x2 | 0x1);
  event = event->next;
 }
 if (allday && !COMPACT)
  allday++;
 wshrink(times, y+allday);
 wshrink(body, y+allday);
 mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
 for (int h = 0; h < 24; h++)
  mvwprintw(times, h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
 if (!EVENT)
  EVENT = find_event(&SEL);
 event = EVENTS;
 struct event_t *active[10] = {};
 int ncols = 0;
 for (int h = 0; h < 24; h++)
 for (int m = 0; m < 60; m+=15)
 while (event && before(&event->start,
   SEL.year, SEL.month, SEL.day, h+(m+15)/60, (m+15)%60)) {
  if (!before(&event->start, SEL.year, SEL.month, SEL.day, h, m) &&
      get_mins(&event->start, &event->end) <= 23*60) {
   int col = get_col(active, (sizeof(active)/sizeof((active)[0])), event, &ncols);
   int left = ((int)(((col+0.0)*(COLS-6)/ncols)+0.5)) + 1;
   int right = ((int)(((col+1.0)*(COLS-6)/ncols)+0.5)) + 1;
   int row = h*4 + m/15 - line;
   int height = (get_mins(&event->start, &event->end)-1)/15+1;
   event_box(body, event, row, left, height, right-left);
  }
  event = event->next;
 }
 if (!COMPACT)
  (wmove((win),(1),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 if (!COMPACT && allday)
  (wmove((win),(allday+1),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 (wmove((body),(0),(0)) == (-1) ? (-1) : wvline((body),((acs_map[(unsigned char)(('x'))])),(LINES-4+COMPACT+COMPACT)));
}

variable_types:
mstr
char *

variable_types:
dstr
char *

variable_types: y int

variable_types: allday int

variable_types: h int

variable_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t end; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct event_t *next; struct event_t *prev; } *[10]

variable_types: m int

variable_types: col int

variable_types: left int

variable_types: right int

variable_types: row int

variable_types: height int


decompiled_code:
__int64 __fastcall day_run(int a1)
{
int v1; // eax
int v2; // eax
__int64 result; // rax
int v4; // edi
unsigned int v5; // esi

if ( a1 > 111 )
return 0LL;
if ( a1 > 103 )
{
switch ( a1 )
{
case 'h':
v4 = 0;
v5 = -1;
goto LABEL_22;
case 'i':
v4 = 0;
v5 = -7;
goto LABEL_22;
case 'j':
v4 = 1;
v5 = 0;
goto LABEL_22;
case 'k':
v4 = -1;
v5 = 0;
goto LABEL_22;
case 'l':
v4 = 0;
v5 = 1;
goto LABEL_22;
case 'o':
v4 = 0;
v5 = 7;
LABEL_22:
if ( v4 | v5 )
move_event(v4, v5, &line);
goto LABEL_12;
default:
return 0LL;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
result = 1LL;
}
else
{
if ( a1 == 25 )
{
v1 = -1;
}
else
{
if ( a1 != 5 )
return 0LL;
v1 = 1;
}
line += v1;
v2 = 0;
if ( line >= 0 )
v2 = line;
if ( v2 > 96 )
v2 = 96;
line = v2;
LABEL_12:
werase(win);
day_draw();
wrefresh(win);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // eax
int v2; // eax
__int64 result; // rax
int v4; // edi
unsigned int v5; // esi

if ( a1 > 111 )
return 0LL;
if ( a1 > 103 )
{
switch ( a1 )
{
case 'h':
v4 = 0;
v5 = -1;
goto LABEL_22;
case 'i':
v4 = 0;
v5 = -7;
goto LABEL_22;
case 'j':
v4 = 1;
v5 = 0;
goto LABEL_22;
case 'k':
v4 = -1;
v5 = 0;
goto LABEL_22;
case 'l':
v4 = 0;
v5 = 1;
goto LABEL_22;
case 'o':
v4 = 0;
v5 = 7;
LABEL_22:
if ( v4 | v5 )
func5(v4, v5, &line);
goto LABEL_12;
default:
return 0LL;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
result = 1LL;
}
else
{
if ( a1 == 25 )
{
v1 = -1;
}
else
{
if ( a1 != 5 )
return 0LL;
v1 = 1;
}
line += v1;
v2 = 0;
if ( line >= 0 )
v2 = line;
if ( v2 > 96 )
v2 = 96;
line = v2;
LABEL_12:
werase(win);
func8();
wrefresh(win);
result = 1LL;
}
return result;
}

original_code:
int day_run(int key, mmask_t btn, int row, int col)
{
 int days = 0, events = 0, lines = 0;
 switch (key) {
  case 'h': days = -1; break;
  case 'l': days = 1; break;
  case 'i': days = -7; break;
  case 'o': days = 7; break;
  case 'k': events = -1; break;
  case 'j': events = 1; break;
  case '\031': lines = -1; break;
  case '\005': lines = 1; break;
  case '\012': view_edit(EDIT_EVENT); return 1;
  default: return 0;
 }
 if (lines)
  line = ((((line+lines) > (0) ? (line+lines) : (0))) < (24*4) ? (((line+lines) > (0) ? (line+lines) : (0))) : (24*4));
 if (days || events)
  move_event(events, days, &line);
 werase(win);
 day_draw();
 wrefresh(win);
 return 1;
}

canonical_original_code:
int day_run(int key, unsigned int btn, int row, int col)
{
 int days = 0; int events = 0; int lines = 0;
 switch (key) {
  case 'h': days = -1; break;
  case 'l': days = 1; break;
  case 'i': days = -7; break;
  case 'o': days = 7; break;
  case 'k': events = -1; break;
  case 'j': events = 1; break;
  case '\031': lines = -1; break;
  case '\005': lines = 1; break;
  case '\012': view_edit(EDIT_EVENT); return 1;
  default: return 0;
 }
 if (lines)
  line = ((((line+lines) > (0) ? (line+lines) : (0))) < (24*4) ? (((line+lines) > (0) ? (line+lines) : (0))) : (24*4));
 if (days || events)
  move_event(events, days, &line);
 werase(win);
 day_draw();
 wrefresh(win);
 return 1;
}

variable_types: key int

variable_types:
btn
unsigned int

variable_types: days int

variable_types: events int

variable_types: lines int


decompiled_code:
FILE *util_init()
{
FILE *result; // rax

result = fopen("/tmp/lackey.log", "w+");
debug_fd = result;
return result;
}

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

result = fopen("/tmp/lackey.log", "w+");
debug_fd = result;
return result;
}

original_code:
void util_init(void)
{
 debug_fd = fopen("/tmp/lackey.log", "w+");
}

canonical_original_code:
void util_init()
{
 debug_fd = fopen("/tmp/lackey.log", "w+");
}


strsub

decompiled_code:
__int64 __fastcall strsub(_BYTE *a1, char a2, char a3)
{
__int64 result; // rax

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( a2 == (_BYTE)result )
*a1 = a3;
++a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, char a2, char a3)
{
__int64 result; // rax

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( a2 == (_BYTE)result )
*a1 = a3;
++a1;
}
return result;
}

original_code:
void strsub(char *str, char find, char repl)
{
 for (char *cur = str; *cur; cur++)
  if (*cur == find)
   *cur = repl;
}

variable_types:
str
char *

variable_types: find char

variable_types: repl char

variable_types:
cur
char *


strcopy

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

if ( a1 )
result = strdup(a1);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = strdup(a1);
else
result = 0LL;
return result;
}

original_code:
char *strcopy(const char *str)
{
 if (str == ((void *)0))
  return ((void *)0);
 return strdup(str);
}

canonical_original_code:
char *strcopy(char *str)
{
 if (str == ((void *)0))
  return ((void *)0);
 return strdup(str);
}

return_type: char *


match

decompiled_code:
_BOOL8 __fastcall match(const char *a1, const char *a2)
{
if ( a1 == a2 )
return 1LL;
if ( a1 && a2 )
return strcmp(a1, a2) == 0;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const char *a2)
{
if ( a1 == a2 )
return 1LL;
if ( a1 && a2 )
return strcmp(a1, a2) == 0;
return 0LL;
}

original_code:
int match(const char *a, const char *b)
{
 if (a == b)
  return 1;
 if (!a || !b)
  return 0;
 return !strcmp(a, b);
}

canonical_original_code:
int match(char *a, char *b)
{
 if (a == b)
  return 1;
 if (!a || !b)
  return 0;
 return !strcmp(a, b);
}

variable_types:
a
char *

variable_types:
b
char *


debug

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

va_start(va, a1);
return message(0LL, "debug", a1, (const __m128i *)va);
}

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

va_start(va, a1);
return func0(0LL, "debug", a1, (const __m128i *)va);
}

original_code:
void debug(char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 message(((void *)0), "debug", fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void debug(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 message(((void *)0), "debug", fmt, ap);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


error

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

va_start(va, a1);
fflush(stdout);
fflush(stderr);
message(stderr, "error", a1, (const __m128i *)va);
if ( stdscr )
{
wgetch(stdscr);
endwin();
}
exit(-1);
}

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

va_start(va, a1);
fflush(stdout);
fflush(stderr);
func0(stderr, "error", a1, (const __m128i *)va);
if ( stdscr )
{
wgetch(stdscr);
endwin();
}
exit(-1);
}

original_code:
void error(char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 fflush(stdout);
 fflush(stderr);
 message(stderr, "error", fmt, ap);
 __builtin_va_end(ap);
 if (stdscr) {
  wgetch(stdscr);
  endwin();
 }
 exit(-1);
}

canonical_original_code:
void error(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 fflush(stdout);
 fflush(stderr);
 message(stderr, "error", fmt, ap);
 __builtin_va_end(ap);
 if (stdscr) {
  wgetch(stdscr);
  endwin();
 }
 exit(-1);
}


decompiled_code:
void *__fastcall alloc0(int a1)
{
void *result; // rax

result = calloc(1uLL, a1);
if ( !result )
error("memory allocation failed");
return result;
}

canonical_decompiled_code:
void *__fastcall func8(int a1)
{
void *result; // rax

result = calloc(1uLL, a1);
if ( !result )
func7("memory allocation failed");
return result;
}

original_code:
void *alloc0(int size)
{
 void *data = calloc(1, size);
 if (!data)
  error("memory allocation failed");
 return data;
}

variable_types: size int

variable_types:
data
void *

return_type: void *


decompiled_code:
void todo_size()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void todo_size(int rows, int cols)
{
}

canonical_original_code:
void todo_size(int rows, int cols)
{
}

variable_types: rows int

variable_types: cols int


decompiled_code:
__int64 todo_draw()
{
int v0; // eax
int v1; // eax
__int64 result; // rax

TODO = 0LL;
items = 0;
v0 = print_group(win, -line, TODOS, show_new, "New Tasks", 0, 0);
v1 = print_group(win, v0, TODOS, show_started, "Started Tasks", 1u, 99);
result = line + (unsigned int)print_group(win, v1, TODOS, show_finished, "Finished Tasks", 0x64u, 100) - 1;
rows = result;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
int v1; // eax
__int64 result; // rax

TODO = 0LL;
items = 0;
v0 = func1(win, -line, TODOS, show_new, "New Tasks", 0, 0);
v1 = func1(win, v0, TODOS, show_started, "Started Tasks", 1u, 99);
result = line + (unsigned int)func1(win, v1, TODOS, show_finished, "Finished Tasks", 0x64u, 100) - 1;
rows = result;
return result;
}

original_code:
void todo_draw(void)
{
 int row = -line;
 TODO = 0;
 items = 0;
 row = print_group(win, row, TODOS,
  show_new, "New Tasks", NEW, NEW);
 row = print_group(win, row, TODOS,
  show_started, "Started Tasks", NEW+1, DONE-1);
 row = print_group(win, row, TODOS,
  show_finished, "Finished Tasks", DONE, DONE);
 rows = row+line-1;
}

canonical_original_code:
void todo_draw()
{
 int row = -line;
 TODO = 0;
 items = 0;
 row = print_group(win, row, TODOS,
  show_new, "New Tasks", NEW, NEW);
 row = print_group(win, row, TODOS,
  show_started, "Started Tasks", NEW+1, DONE-1);
 row = print_group(win, row, TODOS,
  show_finished, "Finished Tasks", DONE, DONE);
 rows = row+line-1;
}

variable_types: row int


decompiled_code:
__int64 __fastcall todo_run(int a1)
{
int v1; // edi
int v2; // er10
unsigned int v3; // ebx
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // eax
int v8; // edx
int v9; // eax
int v10; // edx
int v11; // eax
int v12; // edi

if ( a1 > 115 )
{
v3 = 0;
v1 = 0;
v2 = 0;
v4 = 0;
}
else
{
if ( a1 > 70 )
{
switch ( a1 )
{
case 'G':
v2 = rows;
v1 = 0;
goto LABEL_7;
case 'f':
show_finished ^= 1u;
v1 = 0;
v2 = 0;
goto LABEL_7;
case 'g':
v2 = -line;
v1 = 0;
goto LABEL_7;
case 'j':
v1 = 1;
v2 = 0;
goto LABEL_7;
case 'k':
v4 = first;
if ( first )
v4 = -2;
v3 = 1;
v1 = -1;
v2 = 0;
break;
case 'n':
show_new ^= 1u;
v1 = 0;
v2 = 0;
goto LABEL_7;
case 's':
show_started ^= 1u;
v1 = 0;
v2 = 0;
goto LABEL_7;
default:
v3 = 0;
v1 = 0;
v2 = 0;
goto LABEL_18;
}
goto LABEL_21;
}
switch ( a1 )
{
case 10:
view_edit(3LL);
return 1;
case 25:
v1 = 0;
v2 = -1;
goto LABEL_7;
case 5:
v1 = 0;
v2 = 1;
LABEL_7:
v3 = 1;
LABEL_18:
if ( v1 <= 0 )
{
v4 = 0;
}
else
{
v4 = last;
if ( last )
v4 = 2;
}
goto LABEL_21;
}
v3 = 0;
v1 = 0;
v2 = 0;
v4 = 0;
}
LABEL_21:
v5 = v4 + v1 + srow + line;
v6 = -2;
if ( win )
v6 = win->_maxy;
if ( v5 - line < 0 )
{
v7 = line - 1;
do
v8 = v7--;
while ( v5 - v8 < 0 );
line = v8;
}
v9 = line;
if ( v6 < v5 - line )
{
v10 = line + 1;
do
v9 = v10++;
while ( v5 - v9 > v6 );
}
v11 = v2 + v9;
if ( v11 < 0 )
v11 = 0;
if ( rows - 1 <= v11 )
v11 = rows - 1;
line = v11;
v12 = cursor + v1;
if ( v12 < 0 )
v12 = 0;
if ( v12 > items - 1 )
v12 = items - 1;
cursor = v12;
if ( v3 )
{
werase(win);
todo_draw();
wrefresh(win);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // edi
int v2; // er10
unsigned int v3; // ebx
int v4; // edx
int v5; // ecx
int v6; // er8
int v7; // eax
int v8; // edx
int v9; // eax
int v10; // edx
int v11; // eax
int v12; // edi

if ( a1 > 115 )
{
v3 = 0;
v1 = 0;
v2 = 0;
v4 = 0;
}
else
{
if ( a1 > 70 )
{
switch ( a1 )
{
case 'G':
v2 = rows;
v1 = 0;
goto LABEL_7;
case 'f':
show_finished ^= 1u;
v1 = 0;
v2 = 0;
goto LABEL_7;
case 'g':
v2 = -line;
v1 = 0;
goto LABEL_7;
case 'j':
v1 = 1;
v2 = 0;
goto LABEL_7;
case 'k':
v4 = first;
if ( first )
v4 = -2;
v3 = 1;
v1 = -1;
v2 = 0;
break;
case 'n':
show_new ^= 1u;
v1 = 0;
v2 = 0;
goto LABEL_7;
case 's':
show_started ^= 1u;
v1 = 0;
v2 = 0;
goto LABEL_7;
default:
v3 = 0;
v1 = 0;
v2 = 0;
goto LABEL_18;
}
goto LABEL_21;
}
switch ( a1 )
{
case 10:
view_edit(3LL);
return 1;
case 25:
v1 = 0;
v2 = -1;
goto LABEL_7;
case 5:
v1 = 0;
v2 = 1;
LABEL_7:
v3 = 1;
LABEL_18:
if ( v1 <= 0 )
{
v4 = 0;
}
else
{
v4 = last;
if ( last )
v4 = 2;
}
goto LABEL_21;
}
v3 = 0;
v1 = 0;
v2 = 0;
v4 = 0;
}
LABEL_21:
v5 = v4 + v1 + srow + line;
v6 = -2;
if ( win )
v6 = win->_maxy;
if ( v5 - line < 0 )
{
v7 = line - 1;
do
v8 = v7--;
while ( v5 - v8 < 0 );
line = v8;
}
v9 = line;
if ( v6 < v5 - line )
{
v10 = line + 1;
do
v9 = v10++;
while ( v5 - v9 > v6 );
}
v11 = v2 + v9;
if ( v11 < 0 )
v11 = 0;
if ( rows - 1 <= v11 )
v11 = rows - 1;
line = v11;
v12 = cursor + v1;
if ( v12 < 0 )
v12 = 0;
if ( v12 > items - 1 )
v12 = items - 1;
cursor = v12;
if ( v3 )
{
werase(win);
func4();
wrefresh(win);
}
return v3;
}

original_code:
int todo_run(int key, mmask_t btn, int row, int col)
{
 int scroll = 0, move = 0, ref = 0;
 switch (key)
 {
  case 'g': ref = 1; scroll = -line; break;
  case 'G': ref = 1; scroll = rows; break;
  case '\005': ref = 1; scroll = 1; break;
  case '\031': ref = 1; scroll = -1; break;
  case 'j': ref = 1; move = 1; break;
  case 'k': ref = 1; move = -1; break;
  case 'n': ref = 1; show_new ^= 1; break;
  case 's': ref = 1; show_started ^= 1; break;
  case 'f': ref = 1; show_finished ^= 1; break;
  case '\012':
   view_edit(EDIT_TODO);
   return 1;
 }
 int extra = 0;
 if (move < 0 && first) extra = -2;
 if (move > 0 && last) extra = 2;
 int next = line + srow + move + extra;
 int ymax = ((0 != (const void *)((win))) ? ((win)->_maxy + 1) : (-1))-1;
 while (next-line < 0) line--;
 while (next-line > ymax) line++;
 line = ((((line+scroll) > (0) ? (line+scroll) : (0))) < (rows-1) ? (((line+scroll) > (0) ? (line+scroll) : (0))) : (rows-1));
 cursor = ((((cursor+move) > (0) ? (cursor+move) : (0))) < (items-1) ? (((cursor+move) > (0) ? (cursor+move) : (0))) : (items-1));
 if (ref) {
  werase(win);
  todo_draw();
  wrefresh(win);
 }
 return ref;
}

canonical_original_code:
int todo_run(int key, unsigned int btn, int row, int col)
{
 int scroll = 0; int move = 0; int ref = 0;
 switch (key)
 {
  case 'g': ref = 1; scroll = -line; break;
  case 'G': ref = 1; scroll = rows; break;
  case '\005': ref = 1; scroll = 1; break;
  case '\031': ref = 1; scroll = -1; break;
  case 'j': ref = 1; move = 1; break;
  case 'k': ref = 1; move = -1; break;
  case 'n': ref = 1; show_new ^= 1; break;
  case 's': ref = 1; show_started ^= 1; break;
  case 'f': ref = 1; show_finished ^= 1; break;
  case '\012':
   view_edit(EDIT_TODO);
   return 1;
 }
 int extra = 0;
 if (move < 0 && first) extra = -2;
 if (move > 0 && last) extra = 2;
 int next = line + srow + move + extra;
 int ymax = ((0 != (const void *)((win))) ? ((win)->_maxy + 1) : (-1))-1;
 while (next-line < 0) line--;
 while (next-line > ymax) line++;
 line = ((((line+scroll) > (0) ? (line+scroll) : (0))) < (rows-1) ? (((line+scroll) > (0) ? (line+scroll) : (0))) : (rows-1));
 cursor = ((((cursor+move) > (0) ? (cursor+move) : (0))) < (items-1) ? (((cursor+move) > (0) ? (cursor+move) : (0))) : (items-1));
 if (ref) {
  werase(win);
  todo_draw();
  wrefresh(win);
 }
 return ref;
}

variable_types: key int

variable_types: col int

variable_types: scroll int

variable_types: move int

variable_types: ref int

variable_types: extra int

variable_types: next int

variable_types: ymax int


repo: AnthonyDiGirolamo/gdbase

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

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

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

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

original_code:
Vector* vector_new() {
 Vector* v;
 v = (Vector*) malloc(sizeof(Vector));
 v->cap = 0;
 v->size = 0;
 v->data = ((void *)0);
 return v;
}

canonical_original_code:
struct s_vector *vector_new() {
 struct s_vector *v;
 v = (struct s_vector *) malloc(sizeof(Vector));
 v->cap = 0;
 v->size = 0;
 v->data = ((void *)0);
 return v;
}

variable_types: struct s_vector { void **data; int cap; int size; } *


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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 12);
else
result = 0LL;
return result;
}

original_code:
int vector_size(Vector *v) {
 if (v == ((void *)0)) return 0;
 return v->size;
}

canonical_original_code:
int vector_size(struct s_vector *v) {
 if (v == ((void *)0)) return 0;
 return v->size;
}

user_defined_types: struct s_vector { void **data; int cap; int size; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
int vector_capacity(Vector *v) {
 if (v == ((void *)0)) return 0;
 return v->cap;
}

canonical_original_code:
int vector_capacity(struct s_vector *v) {
 if (v == ((void *)0)) return 0;
 return v->cap;
}


decompiled_code:
__int64 __fastcall vector_getItem(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 12) < a2 || a2 < 0 )
return 0LL;
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 12) < a2 || a2 < 0 )
return 0LL;
return *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}

original_code:
void* vector_getItem(Vector *v, int index) {
 if (v == ((void *)0)) return ((void *)0);
 if (index > v->size) return ((void *)0);
 if (index < 0) return ((void *)0);
 return v->data[index];
}

canonical_original_code:
void *vector_getItem(struct s_vector *v, int index) {
 if (v == ((void *)0)) return ((void *)0);
 if (index > v->size) return ((void *)0);
 if (index < 0) return ((void *)0);
 return v->data[index];
}

variable_types: index int


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

if ( !a1 )
return 1LL;
result = 1LL;
if ( *(_DWORD *)(a1 + 12) >= a2 )
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
result = 0LL;
}
return result;
}

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

if ( !a1 )
return 1LL;
result = 1LL;
if ( *(_DWORD *)(a1 + 12) >= a2 )
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
result = 0LL;
}
return result;
}

original_code:
int vector_setItem(Vector *v, int index, void *item) {
 if (v == ((void *)0)) return 1;
 if (index > v->size) return 1;
 v->data[index] = item;
 return 0;
}

canonical_original_code:
int vector_setItem(struct s_vector *v, int index, void *item) {
 if (v == ((void *)0)) return 1;
 if (index > v->size) return 1;
 v->data[index] = item;
 return 0;
}

variable_types:
item
void *


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

*(_QWORD *)a1 = realloc(*(void **)a1, 8LL * (2 * *(_DWORD *)(a1 + 8) + 1));
result = (unsigned int)(2 * *(_DWORD *)(a1 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

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

*(_QWORD *)a1 = realloc(*(void **)a1, 8LL * (2 * *(_DWORD *)(a1 + 8) + 1));
result = (unsigned int)(2 * *(_DWORD *)(a1 + 8) + 1);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
void vector_resize(Vector *v) {
 v->data = realloc(v->data, sizeof(void*) * (v->cap*2 +1) );
 v->cap = v->cap*2+1;
}

canonical_original_code:
void vector_resize(struct s_vector *v) {
 v->data = realloc(v->data, sizeof(void *) * (v->cap*2 +1) );
 v->cap = v->cap*2+1;
}


decompiled_code:
__int64 __fastcall vector_addItem(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // eax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 12) >= *(_DWORD *)(a1 + 8) )
vector_resize(a1);
v2 = *(_QWORD *)a1;
v3 = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = v3 + 1;
*(_QWORD *)(v2 + 8LL * v3) = a2;
return *(unsigned int *)(a1 + 12);
}

original_code:
int vector_addItem(Vector *v, void *item) {
 if (v == ((void *)0)) return -1;
 if (v->size >= v->cap) vector_resize(v);
 v->data[v->size++] = item;
 return v->size;
}

canonical_original_code:
int vector_addItem(struct s_vector *v, void *item) {
 if (v == ((void *)0)) return -1;
 if (v->size >= v->cap) vector_resize(v);
 v->data[v->size++] = item;
 return v->size;
}


decompiled_code:
__int64 __fastcall vector_findItem(__int64 a1, __int64 a2)
{
int v2; // ecx
_QWORD *v3; // rdx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD *)(a1 + 12);
if ( v2 <= 0 )
{
result = 0LL;
}
else
{
v3 = *(_QWORD **)a1;
result = 0LL;
while ( *v3 != a2 )
{
result = (unsigned int)(result + 1);
++v3;
if ( (_DWORD)result == v2 )
return 0xFFFFFFFFLL;
}
}
if ( v2 == (_DWORD)result )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
int v2; // ecx
_QWORD *v3; // rdx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *(_DWORD *)(a1 + 12);
if ( v2 <= 0 )
{
result = 0LL;
}
else
{
v3 = *(_QWORD **)a1;
result = 0LL;
while ( *v3 != a2 )
{
result = (unsigned int)(result + 1);
++v3;
if ( (_DWORD)result == v2 )
return 0xFFFFFFFFLL;
}
}
if ( v2 == (_DWORD)result )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int vector_findItem(Vector *v, void *item) {
 int i;
 if (v == ((void *)0)) return -1;
 for (i = 0; i < v->size; i++) {
  if (v->data[i] == item) break;
 }
 if (v->size == i) return -1;
 return i;
}

canonical_original_code:
int vector_findItem(struct s_vector *v, void *item) {
 int i;
 if (v == ((void *)0)) return -1;
 for (i = 0; i < v->size; i++) {
  if (v->data[i] == item) break;
 }
 if (v->size == i) return -1;
 return i;
}

variable_types: i int


decompiled_code:
__int64 __fastcall vector_findString(__int64 a1, const char *a2)
{
int v2; // er13
const char **v3; // rbp
unsigned int v4; // ebx

if ( !a1 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a1 + 12);
if ( v2 <= 0 )
{
v4 = 0;
}
else
{
v3 = *(const char ***)a1;
v4 = 0;
while ( strcasecmp(*v3, a2) )
{
++v4;
++v3;
if ( v4 == v2 )
return (unsigned int)-1;
}
}
if ( v2 == v4 )
v4 = -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
int v2; // er13
const char **v3; // rbp
unsigned int v4; // ebx

if ( !a1 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a1 + 12);
if ( v2 <= 0 )
{
v4 = 0;
}
else
{
v3 = *(const char ***)a1;
v4 = 0;
while ( strcasecmp(*v3, a2) )
{
++v4;
++v3;
if ( v4 == v2 )
return (unsigned int)-1;
}
}
if ( v2 == v4 )
v4 = -1;
return v4;
}

original_code:
int vector_findString(Vector *v, void *item) {
 int i;
 if (v == ((void *)0)) return -1;
 for (i = 0; i < v->size; i++) {
  if ( strcasecmp((char*)v->data[i], (char*)item) == 0 ) break;
 }
 if (v->size == i) return -1;
 return i;
}

canonical_original_code:
int vector_findString(struct s_vector *v, void *item) {
 int i;
 if (v == ((void *)0)) return -1;
 for (i = 0; i < v->size; i++) {
  if ( strcasecmp((char *)v->data[i], (char *)item) == 0 ) break;
 }
 if (v->size == i) return -1;
 return i;
}


decompiled_code:
char *get_prefix()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x2000uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "prefix") < 0 )
return 0LL;
v1 = vector_findString(keys, "prefix");
v2 = (const char *)vector_getItem(values, v1);
strcpy(v0, v2);
return v0;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x2000uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "prefix") < 0 )
return 0LL;
v1 = vector_findString(keys, "prefix");
v2 = (const char *)vector_getItem(values, v1);
strcpy(v0, v2);
return v0;
}

original_code:
char* get_prefix() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char*) malloc(8192 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "prefix") > -1) {
   sprintf(return_string, "%s", (char*) vector_getItem(values, vector_findString(keys, "prefix")));
   return return_string;
  } else
   return ((void *)0);
 }
}

canonical_original_code:
char *get_prefix() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char *) malloc(8192 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "prefix") > -1) {
   sprintf(return_string, "%s", (char *) vector_getItem(values, vector_findString(keys, "prefix")));
   return return_string;
  } else
   return ((void *)0);
 }
}


decompiled_code:
char *get_timeout()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x2000uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "timeout") < 0 )
return 0LL;
v1 = vector_findString(keys, "timeout");
v2 = (const char *)vector_getItem(values, v1);
strcpy(v0, v2);
return v0;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x2000uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "timeout") < 0 )
return 0LL;
v1 = vector_findString(keys, "timeout");
v2 = (const char *)vector_getItem(values, v1);
strcpy(v0, v2);
return v0;
}

original_code:
char* get_timeout() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char*) malloc(8192 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "timeout") > -1) {
   sprintf(return_string, "%s", (char*) vector_getItem(values, vector_findString(keys, "timeout")));
   return return_string;
  } else
   return ((void *)0);
 }
}

canonical_original_code:
char *get_timeout() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char *) malloc(8192 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "timeout") > -1) {
   sprintf(return_string, "%s", (char *) vector_getItem(values, vector_findString(keys, "timeout")));
   return return_string;
  } else
   return ((void *)0);
 }
}


decompiled_code:
char *get_gdb()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x2000uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "gdb") < 0 )
return 0LL;
v1 = vector_findString(keys, "gdb");
v2 = (const char *)vector_getItem(values, v1);
strcpy(v0, v2);
return v0;
}

canonical_decompiled_code:
char *func2()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x2000uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "gdb") < 0 )
return 0LL;
v1 = vector_findString(keys, "gdb");
v2 = (const char *)vector_getItem(values, v1);
strcpy(v0, v2);
return v0;
}

original_code:
char* get_gdb() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char*) malloc(8192 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "gdb") > -1) {
   sprintf(return_string, "%s", (char*) vector_getItem(values, vector_findString(keys, "gdb")));
   return return_string;
  } else
   return ((void *)0);
 }
}

canonical_original_code:
char *get_gdb() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char *) malloc(8192 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "gdb") > -1) {
   sprintf(return_string, "%s", (char *) vector_getItem(values, vector_findString(keys, "gdb")));
   return return_string;
  } else
   return ((void *)0);
 }
}


decompiled_code:
char *get_connectdb()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // r14
unsigned int v3; // eax
const char *v4; // r13
unsigned int v5; // eax
const char *v6; // r12
unsigned int v7; // eax
const char *v8; // rbp
unsigned int v9; // eax
const char *v10; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x400uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "database.name") < 0 )
return 0LL;
v1 = vector_findString(keys, "database.password");
v2 = (const char *)vector_getItem(values, v1);
v3 = vector_findString(keys, "database.user");
v4 = (const char *)vector_getItem(values, v3);
v5 = vector_findString(keys, "database.port");
v6 = (const char *)vector_getItem(values, v5);
v7 = vector_findString(keys, "database.host");
v8 = (const char *)vector_getItem(values, v7);
v9 = vector_findString(keys, "database.name");
v10 = (const char *)vector_getItem(values, v9);
sprintf(v0, " dbname=%s host=%s port=%s user=%s password=%s ", v10, v8, v6, v4, v2);
return v0;
}

canonical_decompiled_code:
char *func3()
{
char *v0; // rbx
unsigned int v1; // eax
const char *v2; // r14
unsigned int v3; // eax
const char *v4; // r13
unsigned int v5; // eax
const char *v6; // r12
unsigned int v7; // eax
const char *v8; // rbp
unsigned int v9; // eax
const char *v10; // rax

if ( !parsed )
return 0LL;
v0 = (char *)malloc(0x400uLL);
if ( !v0 )
{
fwrite("malloc failed\n", 1uLL, 0xEuLL, stderr);
exit(1);
}
if ( (int)vector_findString(keys, "database.name") < 0 )
return 0LL;
v1 = vector_findString(keys, "database.password");
v2 = (const char *)vector_getItem(values, v1);
v3 = vector_findString(keys, "database.user");
v4 = (const char *)vector_getItem(values, v3);
v5 = vector_findString(keys, "database.port");
v6 = (const char *)vector_getItem(values, v5);
v7 = vector_findString(keys, "database.host");
v8 = (const char *)vector_getItem(values, v7);
v9 = vector_findString(keys, "database.name");
v10 = (const char *)vector_getItem(values, v9);
sprintf(v0, " dbname=%s host=%s port=%s user=%s password=%s ", v10, v8, v6, v4, v2);
return v0;
}

original_code:
char* get_connectdb() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char*) malloc(1024 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "database.name") > -1) {
   sprintf(return_string,
           " dbname=%s host=%s port=%s user=%s password=%s ",
           (char*) vector_getItem(values, vector_findString(keys, "database.name")),
           (char*) vector_getItem(values, vector_findString(keys, "database.host")),
           (char*) vector_getItem(values, vector_findString(keys, "database.port")),
           (char*) vector_getItem(values, vector_findString(keys, "database.user")),
           (char*) vector_getItem(values, vector_findString(keys, "database.password"))
          );
   return return_string;
  } else
   return ((void *)0);
 }
}

canonical_original_code:
char *get_connectdb() {
 if (!parsed) return ((void *)0);
 else {
  char *return_string;
  return_string = (char *) malloc(1024 * sizeof(char));
  if(return_string==((void *)0)){fprintf(stderr,"malloc failed\n");exit(1);};
  if (vector_findString(keys, "database.name") > -1) {
   sprintf(return_string,
           " dbname=%s host=%s port=%s user=%s password=%s ",
           (char *) vector_getItem(values, vector_findString(keys, "database.name")),
           (char *) vector_getItem(values, vector_findString(keys, "database.host")),
           (char *) vector_getItem(values, vector_findString(keys, "database.port")),
           (char *) vector_getItem(values, vector_findString(keys, "database.user")),
           (char *) vector_getItem(values, vector_findString(keys, "database.password"))
          );
   return return_string;
  } else
   return ((void *)0);
 }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // ebx
unsigned int v5; // er12
char v6; // al

v3 = 0;
v4 = 0;
v5 = 0;
while ( 1 )
{
v6 = getchar();
if ( v6 == -1 )
break;
if ( v6 == 10 )
{
++v3;
}
else if ( v6 == 32 )
{
++v5;
}
else
{
v4 += v6 == 9;
}
}
printf("Newlines: %d\nBlanks: %d\nTabs: %d\n", v3, v5, v4);
return 0;
}

original_code:
int main(int argc, char **argv) {
    filecounts f = defaults;
    char c;
    while ((c = getchar()) != (-1)) {
        if (c == '\n') {
            f.newlines++;
        }
        else if (c == ' ') {
            f.blanks++;
        }
        else if (c == '\t') {
            f.tabs++;
        }
    }
    printf("Newlines: %d\nBlanks: %d\nTabs: %d\n",f.newlines,f.blanks,f.tabs);
}

canonical_original_code:
int main(int argc, char **argv) {
    struct filecounts f = defaults;
    char c;
    while ((c = getchar()) != (-1)) {
        if (c == '\n') {
            f.newlines++;
        }
        else if (c == ' ') {
            f.blanks++;
        }
        else if (c == '\t') {
            f.tabs++;
        }
    }
    printf("Newlines: %d\nBlanks: %d\nTabs: %d\n",f.newlines,f.blanks,f.tabs);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct filecounts { int blanks; int tabs; int newlines; }

variable_types: c char


printArray

repo: AntonioCS/challenges

decompiled_code:
int __fastcall printArray(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, int a2)
{
unsigned int *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
printf("%d ", *v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return putchar(10);
}

original_code:
void printArray(int a[],int size) {
    for (int i = 0;i<size;i++) {
        printf("%d ",a[i]);
    }
    printf("\n");
}

canonical_original_code:
void printArray(int a[], int size) {
    for (int i = 0;i<size;i++) {
        printf("%d ",a[i]);
    }
    printf("\n");
}

variable_types:
a
int []

variable_types: size int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rsp
unsigned int v5[3]; // [rsp+0h] [rbp-40h] BYREF
int v6; // [rsp+Ch] [rbp-34h]

v6 = 0;
__isoc99_scanf();
v3 = alloca(0LL);
*(_DWORD *)(4 * (((unsigned __int64)v5 + 3) >> 2)) = v5[-1];
printArray(v5, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rsp
unsigned int v5[3]; // [rsp+0h] [rbp-40h] BYREF
int v6; // [rsp+Ch] [rbp-34h]

v6 = 0;
__isoc99_scanf();
v3 = alloca(0LL);
*(_DWORD *)(4 * (((unsigned __int64)v5 + 3) >> 2)) = v5[-1];
func7(v5, v6);
return 0;
}

original_code:
int main(int argc, char** argv) {
    int sizeOfArray = 0;
    scanf("%d",&sizeOfArray);
    int array[sizeOfArray];
    int tmp = 0;
    for (int i = 0; i < sizeOfArray;i++) {
        scanf("%d",&array[i]);
    }
    tmp = array[sizeOfArray-1];
    int tm = 0;
    for (int i = sizeOfArray-2;i >= 0;i--) {
        if (array[i] > tmp) {
            array[i+1] = array[i];
        }
        else {
   if (i == (sizeOfArray-2)) {
    tm = 1;
          printArray(array,sizeOfArray);
    break;
   }
            array[i+1] = tmp;
            tm = 1;
   break;
        }
        printArray(array,sizeOfArray);
    }
    if (tm == 0) {
        array[0] = tmp;
    }
    printArray(array,sizeOfArray);
}

canonical_original_code:
int main(int argc, char **argv) {
    int sizeOfArray = 0;
    scanf("%d",&sizeOfArray);
    int array[-1];
    int tmp = 0;
    for (int i = 0; i < sizeOfArray;i++) {
        scanf("%d",&array[i]);
    }
    tmp = array[sizeOfArray-1];
    int tm = 0;
    for (int i = sizeOfArray-2;i >= 0;i--) {
        if (array[i] > tmp) {
            array[i+1] = array[i];
        }
        else {
   if (i == (sizeOfArray-2)) {
    tm = 1;
          printArray(array,sizeOfArray);
    break;
   }
            array[i+1] = tmp;
            tm = 1;
   break;
        }
        printArray(array,sizeOfArray);
    }
    if (tm == 0) {
        array[0] = tmp;
    }
    printArray(array,sizeOfArray);
}

variable_types: sizeOfArray int

variable_types:
array
int [-1]

variable_types: tmp int

variable_types: tm int


repo: ArchAssault-Project/hydra

canonical_original_code:
void fix_packet(char *buf, int len) {
  unsigned long c1; unsigned long c2;
  unsigned long r1; unsigned long r2;
  int pos; int key; int k;
  c1 = buf[8];
  c1 <<= 8;
  c1 |= buf[4];
  c1 <<= 8;
  c1 |= buf[2];
  c1 <<= 8;
  c1 |= buf[6];
  r1 = (rand() % (len - 0x18)) + 0x18;
  r2 = rand() & 0xff;
  c2 = r1;
  c2 <<= 8;
  c2 |= buf[r1];
  c2 <<= 8;
  c2 |= r2;
  c2 <<= 8;
  c2 |= icq5_table[r2];
  c2 ^= 0xff00ff;
  c1 ^= c2;
  buf[0x14] = c1 & 0xff;
  buf[0x15] = (c1 >> 8) & 0xff;
  buf[0x16] = (c1 >> 16) & 0xff;
  buf[0x17] = (c1 >> 24) & 0xff;
  key = len * 0x68656c6cL;
  key += c1;
  pos = 0xa;
  for (; pos < len; pos += 4)
    k = key + icq5_table[pos & 0xff];
}

variable_types:
buf
char *

variable_types: len int

variable_types: pos int

variable_types: key int

variable_types: k int


original_code:
void icq_header(char *buf, unsigned short cmd, unsigned long uin) {
  buf[0] = 0x02;
  buf[1] = 0x00;
  buf[2] = cmd & 0xff;
  buf[3] = (cmd >> 8) & 0xff;
  buf[4] = seq & 0xff;
  buf[5] = (seq++ >> 8) & 0xff;
  buf[6] = uin & 0xff;
  buf[7] = (uin >> 8) & 0xff;
  buf[8] = (uin >> 16) & 0xff;
  buf[9] = (uin >> 24) & 0xff;
}

variable_types:
cmd
unsigned short

variable_types:
uin
unsigned long


original_code:
int icq_login(int s, char *login, char *pass) {
  unsigned long uin = strtoul(login, ((void *)0), 10);
  char buf[256];
  int len;
  bzero(buf, sizeof(buf));
  icq_header(buf, 0x03e8, uin);
  len = strlen(pass) + 1;
  buf[14] = len;
  memcpy(&buf[16], pass, len);
  buf[16 + len] = 0x78;
  buf[24 + len] = 0x04;
  buf[29 + len] = 0x02;
  buf[39 + len] = 0x08;
  buf[41 + len] = 0x78;
  return (hydra_send(s, buf, 43 + len, 0));
}

variable_types: s int

variable_types:
login
char *

variable_types:
pass
char *

variable_types:
buf
char [256]


decompiled_code:
__int64 __fastcall icq_login_1(unsigned int a1, const char *a2)
{
unsigned __int64 v2; // rax
_BYTE v4[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = strtoul(a2, 0LL, 10);
icq_header((__int64)v4, 1100, v2);
return hydra_send(a1, v4, 10LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, const char *a2)
{
unsigned __int64 v2; // rax
_BYTE v4[72]; // [rsp+0h] [rbp-48h] BYREF

v2 = strtoul(a2, 0LL, 10);
func1((__int64)v4, 1100, v2);
return hydra_send(a1, v4, 10LL, 0LL);
}

original_code:
int icq_login_1(int s, char *login) {
  unsigned long uin = strtoul(login, ((void *)0), 10);
  char buf[64];
  icq_header(buf, 0x044c, uin);
  return (hydra_send(s, buf, 10, 0));
}

variable_types:
buf
char [64]


decompiled_code:
__int64 __fastcall icq_disconnect(unsigned int a1, const char *a2)
{
unsigned __int64 v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
_QWORD v5[3]; // [rsp+8h] [rbp-40h] BYREF
__int64 v6; // [rsp+20h] [rbp-28h]
__int64 v7; // [rsp+28h] [rbp-20h]
__int64 v8; // [rsp+30h] [rbp-18h]
__int64 v9; // [rsp+38h] [rbp-10h]

v2 = strtoul(a2, 0LL, 10);
v4 = 0LL;
v5[0] = 0LL;
v5[1] = 0LL;
v5[2] = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
icq_header((__int64)&v4, 1080, v2);
BYTE2(v5[0]) = 20;
strcpy((char *)v5 + 4, "B_USER_DISCONNECTED");
LOBYTE(v6) = 5;
return hydra_send(a1, &v4, 34LL, 0LL);
}

original_code:
int icq_disconnect(int s, char *login) {
  unsigned long uin = strtoul(login, ((void *)0), 10);
  char buf[64];
  bzero(buf, sizeof(buf));
  icq_header(buf, 0x0438, uin);
  buf[10] = 20;
  memcpy(&buf[12], "B_USER_DISCONNECTED", 20);
  buf[32] = 0x5;
  return (hydra_send(s, buf, 34, 0));
}


decompiled_code:
__int64 __fastcall icq_ack(unsigned int a1, const char *a2)
{
int v2; // eax
char v4[4]; // [rsp+0h] [rbp-48h] BYREF
__int16 v5; // [rsp+4h] [rbp-44h]
int v6; // [rsp+6h] [rbp-42h]

v2 = strtoul(a2, 0LL, 10);
v4[0] = 2;
v4[1] = 0;
v4[2] = 10;
v4[3] = 0;
v5 = seq;
v6 = v2;
return hydra_send(a1, v4, 10LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, const char *a2)
{
int v2; // eax
char v4[4]; // [rsp+0h] [rbp-48h] BYREF
__int16 v5; // [rsp+4h] [rbp-44h]
int v6; // [rsp+6h] [rbp-42h]

v2 = strtoul(a2, 0LL, 10);
v4[0] = 2;
v4[1] = 0;
v4[2] = 10;
v4[3] = 0;
v5 = seq;
v6 = v2;
return hydra_send(a1, v4, 10LL, 0LL);
}

original_code:
int icq_ack(int s, char *login) {
  unsigned long uin = strtoul(login, ((void *)0), 10);
  char buf[64];
  buf[0] = 0x02;
  buf[1] = 0x00;
  buf[2] = 0x0a;
  buf[3] = 0x0;
  buf[4] = seq & 0xff;
  buf[5] = (seq >> 8) & 0xff;
  buf[6] = uin & 0xff;
  buf[7] = (uin >> 8) & 0xff;
  buf[8] = (uin >> 16) & 0xff;
  buf[9] = (uin >> 24) & 0xff;
  return (hydra_send(s, buf, 10, 0));
}


decompiled_code:
int dummy_firebird()
{
return putchar(10);
}

canonical_decompiled_code:
int func0()
{
return putchar(10);
}

original_code:
void dummy_firebird() {
  printf("\n");
}

canonical_original_code:
void dummy_firebird() {
  printf("\n");
}


original_code:
void hmac_md5_init_rfc2104(const unsigned char *key, int key_len, HMACMD5Context *ctx)
{
        int i;
 unsigned char tk[16];
        if (key_len > 64) {
                MD5_CTX tctx;
                MD5_Init(&tctx);
                MD5_Update(&tctx, (void *)key, key_len);
                MD5_Final(tk, &tctx);
                key = tk;
                key_len = 16;
        }
        memset((char *)&(ctx->k_ipad), 0, sizeof(ctx->k_ipad));
        memset((char *)&(ctx->k_opad), 0, sizeof(ctx->k_opad));
        memcpy( ctx->k_ipad, key, key_len);
        memcpy( ctx->k_opad, key, key_len);
        for (i=0; i<64; i++) {
                ctx->k_ipad[i] ^= 0x36;
                ctx->k_opad[i] ^= 0x5c;
        }
        MD5_Init(&ctx->ctx);
        MD5_Update(&ctx->ctx, ctx->k_ipad, 64);
}

canonical_original_code:
void hmac_md5_init_rfc2104(unsigned char *key, int key_len, struct HMACMD5Context *ctx)
{
        int i;
 unsigned char tk[16];
        if (key_len > 64) {
                struct MD5state_st tctx;
                MD5_Init(&tctx);
                MD5_Update(&tctx, (void *)key, key_len);
                MD5_Final(tk, &tctx);
                key = tk;
                key_len = 16;
        }
        memset((char *)&(ctx->k_ipad), 0, sizeof(ctx->k_ipad));
        memset((char *)&(ctx->k_opad), 0, sizeof(ctx->k_opad));
        memcpy( ctx->k_ipad, key, key_len);
        memcpy( ctx->k_opad, key, key_len);
        for (i=0; i<64; i++) {
                ctx->k_ipad[i] ^= 0x36;
                ctx->k_opad[i] ^= 0x5c;
        }
        MD5_Init(&ctx->ctx);
        MD5_Update(&ctx->ctx, ctx->k_ipad, 64);
}

variable_types:
key
unsigned char *

variable_types: struct HMACMD5Context { struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; } ctx; unsigned char k_ipad[65]; unsigned char k_opad[65]; } *

variable_types: i int

variable_types:
tk
unsigned char [16]

user_defined_types: struct HMACMD5Context { struct MD5state_st ctx; unsigned char k_ipad[65]; unsigned char k_opad[65]; }


original_code:
void hmac_md5_init_limK_to_64(const unsigned char* key, int key_len,
   HMACMD5Context *ctx)
{
        int i;
        if (key_len > 64) {
                key_len = 64;
        }
        memset((char *)&(ctx->k_ipad), 0, sizeof(ctx->k_ipad));
        memset((char *)&(ctx->k_opad), 0, sizeof(ctx->k_opad));
        memcpy( ctx->k_ipad, key, key_len);
        memcpy( ctx->k_opad, key, key_len);
        for (i=0; i<64; i++) {
                ctx->k_ipad[i] ^= 0x36;
                ctx->k_opad[i] ^= 0x5c;
        }
        MD5_Init(&ctx->ctx);
        MD5_Update(&ctx->ctx, ctx->k_ipad, 64);
}

canonical_original_code:
void hmac_md5_init_limK_to_64(unsigned char *key, int key_len, struct HMACMD5Context *ctx)
{
        int i;
        if (key_len > 64) {
                key_len = 64;
        }
        memset((char *)&(ctx->k_ipad), 0, sizeof(ctx->k_ipad));
        memset((char *)&(ctx->k_opad), 0, sizeof(ctx->k_opad));
        memcpy( ctx->k_ipad, key, key_len);
        memcpy( ctx->k_opad, key, key_len);
        for (i=0; i<64; i++) {
                ctx->k_ipad[i] ^= 0x36;
                ctx->k_opad[i] ^= 0x5c;
        }
        MD5_Init(&ctx->ctx);
        MD5_Update(&ctx->ctx, ctx->k_ipad, 64);
}

user_defined_types: struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }


decompiled_code:
__int64 __fastcall hmac_md5_update(__int64 a1, int a2, __int64 a3)
{
return MD5_Update(a3, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3)
{
return MD5_Update(a3, a1, a2);
}

original_code:
void hmac_md5_update(const unsigned char *text, int text_len, HMACMD5Context *ctx)
{
        MD5_Update(&ctx->ctx, (void *)text, text_len);
}

canonical_original_code:
void hmac_md5_update(unsigned char *text, int text_len, struct HMACMD5Context *ctx)
{
        MD5_Update(&ctx->ctx, (void *)text, text_len);
}

variable_types:
text
unsigned char *


decompiled_code:
__int64 __fastcall hmac_md5_final(__int64 a1, __int64 a2)
{
_BYTE v3[120]; // [rsp+0h] [rbp-78h] BYREF

MD5_Final(a1, a2);
MD5_Init(v3);
MD5_Update(v3, a2 + 157, 64LL);
MD5_Update(v3, a1, 16LL);
return MD5_Final(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_BYTE v3[120]; // [rsp+0h] [rbp-78h] BYREF

MD5_Final(a1, a2);
MD5_Init(v3);
MD5_Update(v3, a2 + 157, 64LL);
MD5_Update(v3, a1, 16LL);
return MD5_Final(a1, v3);
}

original_code:
void hmac_md5_final(unsigned char *digest, HMACMD5Context *ctx)
{
        MD5_CTX ctx_o;
        MD5_Final(digest, &ctx->ctx);
        MD5_Init(&ctx_o);
        MD5_Update(&ctx_o, ctx->k_opad, 64);
        MD5_Update(&ctx_o, digest, 16);
        MD5_Final(digest, &ctx_o);
}

canonical_original_code:
void hmac_md5_final(unsigned char *digest, struct HMACMD5Context *ctx)
{
        struct MD5state_st ctx_o;
        MD5_Final(digest, &ctx->ctx);
        MD5_Init(&ctx_o);
        MD5_Update(&ctx_o, ctx->k_opad, 64);
        MD5_Update(&ctx_o, digest, 16);
        MD5_Final(digest, &ctx_o);
}

variable_types:
digest
unsigned char *

variable_types: struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; }


decompiled_code:
__int64 __fastcall hmac_md5(_QWORD *a1, __int64 a2, int a3, __int64 a4)
{
_BYTE v7[248]; // [rsp+0h] [rbp-F8h] BYREF

hmac_md5_init_limK_to_64(a1, 16, (__int64)v7);
if ( a3 )
hmac_md5_update(a2, a3, (__int64)v7);
return hmac_md5_final(a4, (__int64)v7);
}

original_code:
void hmac_md5( unsigned char key[16], unsigned char *data, int data_len, unsigned char *digest)
{
 HMACMD5Context ctx;
 hmac_md5_init_limK_to_64(key, 16, &ctx);
 if (data_len != 0)
 {
  hmac_md5_update(data, data_len, &ctx);
 }
 hmac_md5_final(digest, &ctx);
}

canonical_original_code:
void hmac_md5(unsigned char key[16], unsigned char *data, int data_len, unsigned char *digest)
{
 struct HMACMD5Context ctx;
 hmac_md5_init_limK_to_64(key, 16, &ctx);
 if (data_len != 0)
 {
  hmac_md5_update(data, data_len, &ctx);
 }
 hmac_md5_final(digest, &ctx);
}

variable_types:
key
unsigned char [16]

variable_types:
data
unsigned char *

variable_types: struct HMACMD5Context { struct MD5state_st { unsigned int A; unsigned int Nl; unsigned int data[-1]; unsigned int num; } ctx; unsigned char k_ipad[65]; unsigned char k_opad[65]; }


vncEncryptBytes

decompiled_code:
__int64 __fastcall vncEncryptBytes(__int64 a1, const char *a2)
{
size_t i; // rbx
size_t v3; // rdx
char v4; // al
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v3 = strlen(a2);
v4 = 0;
if ( v3 > i )
v4 = a2[i];
v6[i] = v4;
}
deskey(v6, 0LL);
des(a1, a1);
return des(a1 + 8, a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
size_t i; // rbx
size_t v3; // rdx
char v4; // al
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0LL; i != 8; ++i )
{
v3 = strlen(a2);
v4 = 0;
if ( v3 > i )
v4 = a2[i];
v6[i] = v4;
}
deskey(v6, 0LL);
des(a1, a1);
return des(a1 + 8, a1 + 8);
}

original_code:
void vncEncryptBytes(unsigned char *bytes, char *passwd) {
  unsigned char key[8];
  int i;
  for (i = 0; i < 8; i++) {
    if (i < strlen(passwd)) {
      key[i] = passwd[i];
    } else {
      key[i] = 0;
    }
  }
  deskey(key, 0);
  for (i = 0; i < 16; i += 8) {
    des(bytes + i, bytes + i);
  }
}

variable_types:
bytes
unsigned char *

variable_types:
passwd
char *

variable_types:
key
unsigned char [8]


decompiled_code:
int dummy_svn()
{
return putchar(10);
}

original_code:
void dummy_svn() {
  printf("\n");
}

canonical_original_code:
void dummy_svn() {
  printf("\n");
}


decompiled_code:
int dummy_sapr3()
{
return putchar(10);
}

original_code:
void dummy_sapr3() {
  printf("\n");
}

canonical_original_code:
void dummy_sapr3() {
  printf("\n");
}


decompiled_code:
__int64 __fastcall send_cstring(unsigned int a1, const char *a2)
{
int v2; // eax
char v4[2]; // [rsp+0h] [rbp-88h] BYREF
char dest[134]; // [rsp+2h] [rbp-86h] BYREF

v4[0] = 6;
v4[1] = strlen(a2);
strcpy(dest, a2);
v2 = strlen(a2);
return hydra_send(a1, v4, (unsigned int)(v2 + 2), 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, const char *a2)
{
int v2; // eax
char v4[2]; // [rsp+0h] [rbp-88h] BYREF
char dest[134]; // [rsp+2h] [rbp-86h] BYREF

v4[0] = 6;
v4[1] = strlen(a2);
strcpy(dest, a2);
v2 = strlen(a2);
return hydra_send(a1, v4, (unsigned int)(v2 + 2), 0LL);
}

original_code:
int send_cstring(int s, char *crypted_string) {
  char buffer2[100], *bptr = buffer2;
  char clientcryptheader[] = "\x06";
  memset(buffer2, 0, sizeof(clientcryptheader));
  bptr = buffer2;
  buffer2[0] = 6;
  bptr++;
  buffer2[1] = strlen(crypted_string);
  bptr++;
  strcpy(bptr, crypted_string);
  return hydra_send(s, buffer2, 2 + strlen(crypted_string), 0);
}

canonical_original_code:
int send_cstring(int s, char *crypted_string) {
  char buffer2[100]; char *bptr = buffer2;
  char clientcryptheader[] = "\x06";
  memset(buffer2, 0, sizeof(clientcryptheader));
  bptr = buffer2;
  buffer2[0] = 6;
  bptr++;
  buffer2[1] = strlen(crypted_string);
  bptr++;
  strcpy(bptr, crypted_string);
  return hydra_send(s, buffer2, 2 + strlen(crypted_string), 0);
}

variable_types: s int

variable_types:
bptr
char *

variable_types:
clientcryptheader
char []


decompiled_code:
int __fastcall show_buffer(char *a1, __int64 a2)
{
char *v2; // rbx

printf("size: %d, buffer:\n", a2);
if ( (int)a2 > 0 )
{
v2 = a1;
do
putchar(*v2++);
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(char *a1, __int64 a2)
{
char *v2; // rbx

printf("size: %d, buffer:\n", a2);
if ( (int)a2 > 0 )
{
v2 = a1;
do
putchar(*v2++);
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return putchar(10);
}

original_code:
void show_buffer(char *buffer, int size) {
  int i;
  printf("size: %d, buffer:\n", size);
  for (i = 0; i < size; i++) {
    printf("%c", buffer[i]);
  }
  printf("\n");
}

variable_types:
buffer
char *

variable_types: size int


decompiled_code:
void __fastcall clean_buffer(_BYTE *a1, int a2)
{
_BYTE *v2; // rax

if ( a2 > 0 )
{
v2 = a1;
do
{
if ( (unsigned int)((char)*v2 - 32) > 0x5E )
*v2 = 46;
++v2;
}
while ( v2 != &a1[a2 - 1 + 1] );
}
}

original_code:
void clean_buffer(char *buf, int size) {
  int i;
  for (i = 0; i < size; i++) {
    int pos = buf[i];
    if (pos < 32 || pos > 126) {
      buf[i] = 46;
    }
  }
}

variable_types:
buf
char *

variable_types: pos int


decompiled_code:
int __fastcall print_encrypted_str(char *s)
{
size_t i; // rbx

printf("encode string: ");
for ( i = 0LL; strlen(s) > i; ++i )
printf("%x ", (unsigned int)s[i]);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func3(char *s)
{
size_t i; // rbx

printf("encode string: ");
for ( i = 0LL; strlen(s) > i; ++i )
printf("%x ", (unsigned int)s[i]);
return putchar(10);
}

original_code:
void print_encrypted_str(char *str) {
  int i;
  printf("encode string: ");
  for (i = 0; i < strlen(str); i++) {
    printf("%x ", str[i]);
  }
  printf("\n");
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
char *__fastcall pca_encrypt(char *dest)
{
char *result; // rax
__int64 i; // rbx
size_t v3; // rax
char v4; // [rsp+1h] [rbp-99h]
char v5[152]; // [rsp+2h] [rbp-98h] BYREF

result = strcpy(v5, dest);
if ( *dest )
{
v5[0] ^= 0xABu;
for ( i = 0LL; ; v5[i] ^= (i - 1) ^ *(&v4 + i) )
{
v3 = strlen(v5);
if ( v3 <= ++i )
break;
}
v5[v3] = 0;
result = strcpy(dest, v5);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *dest)
{
char *result; // rax
__int64 i; // rbx
size_t v3; // rax
char v4; // [rsp+1h] [rbp-99h]
char v5[152]; // [rsp+2h] [rbp-98h] BYREF

result = strcpy(v5, dest);
if ( *dest )
{
v5[0] ^= 0xABu;
for ( i = 0LL; ; v5[i] ^= (i - 1) ^ *(&v4 + i) )
{
v3 = strlen(v5);
if ( v3 <= ++i )
break;
}
v5[v3] = 0;
result = strcpy(dest, v5);
}
return result;
}

original_code:
void pca_encrypt(char *cleartxt) {
  char passwd[128];
  int i;
  strcpy(passwd, cleartxt);
  if (strlen(cleartxt) > 0) {
    passwd[0] = (passwd[0] ^ 0xab);
    for (i = 1; i < strlen(passwd); i++)
      passwd[i] = passwd[i - 1] ^ passwd[i] ^ (i - 1);
    passwd[strlen(passwd)] = '\0';
    strcpy(cleartxt, passwd);
  }
}

variable_types:
cleartxt
char *

variable_types:
passwd
char [128]