decompiled_code:
int settings_draw()
{
int v0; // er15
int v1; // er12
__int64 v2; // rbx
size_t v3; // rax
size_t v4; // rax
__int64 v5; // rbx
int result; // eax
const char *v7; // rbp
__int64 v8; // r12
size_t v9; // rax
const char *v10; // r14
size_t v11; // r13
size_t v12; // rax
__int64 i; // [rsp+8h] [rbp-40h]

v0 = 0;
v1 = 0;
v2 = CALS;
while ( v2 )
{
v3 = strlen(*(const char **)v2);
if ( v3 > v0 )
v0 = v3;
v4 = strlen(*(const char **)(v2 + 8));
v2 = *(_QWORD *)(v2 + 24);
if ( v4 > v1 )
v1 = v4;
}
heading(win, "Current Settings\n");
checkbox_constprop_0(win);
heading(win, "\nLoaded Calendars\n");
v5 = CALS;
result = v1;
for ( i = v1; v5; v5 = *(_QWORD *)(v5 + 24) )
{
v7 = *(const char **)(v5 + 16);
v8 = *(_QWORD *)(v5 + 8);
if ( !v7 )
v7 = "(no description)";
v9 = strlen(*(const char **)(v5 + 8));
v10 = *(const char **)v5;
v11 = v9;
v12 = strlen(*(const char **)v5);
result = wprintw(win, " %s:%*s \"%s\"%*s - %s\n", v10, v0 - v12, &unk_215, v8, i - v11, &unk_215, v7);
}
return result;
}

canonical_decompiled_code:
int func4()
{
int v0; // er15
int v1; // er12
__int64 v2; // rbx
size_t v3; // rax
size_t v4; // rax
__int64 v5; // rbx
int result; // eax
const char *v7; // rbp
__int64 v8; // r12
size_t v9; // rax
const char *v10; // r14
size_t v11; // r13
size_t v12; // rax
__int64 i; // [rsp+8h] [rbp-40h]

v0 = 0;
v1 = 0;
v2 = CALS;
while ( v2 )
{
v3 = strlen(*(const char **)v2);
if ( v3 > v0 )
v0 = v3;
v4 = strlen(*(const char **)(v2 + 8));
v2 = *(_QWORD *)(v2 + 24);
if ( v4 > v1 )
v1 = v4;
}
func0(win, "Current Settings\n");
func1(win);
func0(win, "\nLoaded Calendars\n");
v5 = CALS;
result = v1;
for ( i = v1; v5; v5 = *(_QWORD *)(v5 + 24) )
{
v7 = *(const char **)(v5 + 16);
v8 = *(_QWORD *)(v5 + 8);
if ( !v7 )
v7 = "(no description)";
v9 = strlen(*(const char **)(v5 + 8));
v10 = *(const char **)v5;
v11 = v9;
v12 = strlen(*(const char **)v5);
result = wprintw(win, " %s:%*s \"%s\"%*s - %s\n", v10, v0 - v12, &unk_215, v8, i - v11, &unk_215, v7);
}
return result;
}

original_code:
void settings_draw(void)
{
 int wtype = 0, wname = 0;
 for (cal_t *cal = CALS; cal; cal = cal->next) {
  if (strlen(cal->type) > wtype)
   wtype = strlen(cal->type);
  if (strlen(cal->name) > wname)
   wname = strlen(cal->name);
 }
 heading(win, "Current Settings\n");
 checkbox(win, "Compact layout\n", &COMPACT);
 heading(win, "\nLoaded Calendars\n");
 for (cal_t *cal = CALS; cal; cal = cal->next)
  wprintw(win, "    " "%s:%*s \"%s\"%*s - %s\n",
   cal->type, wtype-strlen(cal->type), "",
   cal->name, wname-strlen(cal->name), "",
   cal->desc ?: "(no description)");
}

canonical_original_code:
void settings_draw()
{
 int wtype = 0; int wname = 0;
 for (struct cal_t *cal = CALS; cal; cal = cal->next) {
  if (strlen(cal->type) > wtype)
   wtype = strlen(cal->type);
  if (strlen(cal->name) > wname)
   wname = strlen(cal->name);
 }
 heading(win, "Current Settings\n");
 checkbox(win, "Compact layout\n", &COMPACT);
 heading(win, "\nLoaded Calendars\n");
 for (struct cal_t *cal = CALS; cal; cal = cal->next)
  wprintw(win, "    " "%s:%*s \"%s\"%*s - %s\n",
   cal->type, wtype-strlen(cal->type), "",
   cal->name, wname-strlen(cal->name), "",
   cal->desc ?: "(no description)");
}

variable_types: wtype int

variable_types: wname int

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


decompiled_code:
__int64 settings_run()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0LL;
}

original_code:
int settings_run(int key, mmask_t btn, int row, int col)
{
 return 0;
}

canonical_original_code:
int settings_run(int key, unsigned int btn, int row, int col)
{
 return 0;
}

variable_types: key int

variable_types:
btn
unsigned int

variable_types: row int

variable_types: col int

return_type: int


decompiled_code:
__int64 date_init()
{
struct tm *v0; // rax
int v1; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
SEL[0] = v0->tm_year + 1900;
v1 = v0->tm_mon;
LODWORD(v0) = v0->tm_mday;
SEL[1] = v1;
result = (unsigned int)((_DWORD)v0 - 1);
SEL[2] = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
struct tm *v0; // rax
int v1; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
SEL[0] = v0->tm_year + 1900;
v1 = v0->tm_mon;
LODWORD(v0) = v0->tm_mday;
SEL[1] = v1;
result = (unsigned int)((_DWORD)v0 - 1);
SEL[2] = result;
return result;
}

original_code:
void date_init(void)
{
 time_t sec = time(((void *)0));
 struct tm *tm = localtime(&sec);
 SEL.year = tm->tm_year+1900;
 SEL.month = tm->tm_mon;
 SEL.day = tm->tm_mday-1;
}

canonical_original_code:
void date_init()
{
 long sec = time(((void *)0));
 struct tm *tm = localtime(&sec);
 SEL.year = tm->tm_year+1900;
 SEL.month = tm->tm_mon;
 SEL.day = tm->tm_mday-1;
}

variable_types: sec long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

return_type: void


decompiled_code:
__int64 date_sync()
{
struct tm *v0; // rax
int v1; // esi
int v2; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = v0->tm_mday;
NOW[0] = v0->tm_year + 1900;
NOW[1] = v0->tm_mon;
NOW[2] = v1 - 1;
NOW[3] = v0->tm_hour;
v2 = v0->tm_min;
result = (unsigned int)v0->tm_sec;
NOW[4] = v2;
NOW[5] = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
struct tm *v0; // rax
int v1; // esi
int v2; // edx
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = v0->tm_mday;
NOW[0] = v0->tm_year + 1900;
NOW[1] = v0->tm_mon;
NOW[2] = v1 - 1;
NOW[3] = v0->tm_hour;
v2 = v0->tm_min;
result = (unsigned int)v0->tm_sec;
NOW[4] = v2;
NOW[5] = result;
return result;
}

original_code:
void date_sync(void)
{
 time_t sec = time(((void *)0));
 struct tm *tm = localtime(&sec);
 NOW.year = tm->tm_year+1900;
 NOW.month = tm->tm_mon;
 NOW.day = tm->tm_mday-1;
 NOW.hour = tm->tm_hour;
 NOW.min = tm->tm_min;
 NOW.sec = tm->tm_sec;
}

canonical_original_code:
void date_sync()
{
 long sec = time(((void *)0));
 struct tm *tm = localtime(&sec);
 NOW.year = tm->tm_year+1900;
 NOW.month = tm->tm_mon;
 NOW.day = tm->tm_mday-1;
 NOW.hour = tm->tm_hour;
 NOW.min = tm->tm_min;
 NOW.sec = tm->tm_sec;
}

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


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

result = 1LL;
if ( __ROR4__(-1030792151 * a1 + 85899344, 4) > 0xA3D70Au )
{
result = (unsigned int)(a1 % 100);
if ( a1 % 100 )
result = (a1 & 3) == 0;
}
return result;
}

variable_types: year int


decompiled_code:
__int64 __fastcall days_in_year(int a1)
{
return (unsigned int)is_leap_year(a1) + 365;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned int)func2(a1) + 365;
}

original_code:
int days_in_year(year_t year)
{
 return 365 + is_leap_year(year);
}

canonical_original_code:
int days_in_year(int year)
{
 return 365 + is_leap_year(year);
}


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

result = (unsigned int)mdays_6[a2];
if ( a2 == 1 )
result = (unsigned int)is_leap_year(a1) + 28;
return result;
}

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

result = (unsigned int)mdays_6[a2];
if ( a2 == 1 )
result = (unsigned int)func2(a1) + 28;
return result;
}

original_code:
int days_in_month(year_t year, month_t month)
{
 static int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 int days = mdays[month];
 if (month == FEB)
  days += is_leap_year(year);
 return days;
}

canonical_original_code:
int days_in_month(int year, enum month_t month)
{
 static int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 int days = mdays[month];
 if (month == FEB)
  days += is_leap_year(year);
 return days;
}

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

variable_types:
mdays
int []

variable_types: days int


original_code:
wday_t day_of_week(year_t year, month_t month, day_t day)
{
 static int tmp[] = {0, 3, 2, 5, 0, 3,
              5, 1, 4, 6, 2, 4};
 if (month < MAR)
  year--;
 int start = year + year / 4
           - year / 100
           + year / 400
           + tmp[month];
 return (start + day + 1) % 7;
}

canonical_original_code:
enum wday_t day_of_week(int year, enum month_t month, int day)
{
 static int tmp[] = {0, 3, 2, 5, 0, 3,
              5, 1, 4, 6, 2, 4};
 if (month < MAR)
  year--;
 int start = year + year / 4
           - year / 100
           + year / 400
           + tmp[month];
 return (start + day + 1) % 7;
}

variable_types: day int

variable_types:
tmp
int []

variable_types: start int

return_type: enum wday_t { SUN=0, MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6 }

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 }


decompiled_code:
__int64 __fastcall start_of_month(unsigned int a1, unsigned int a2)
{
return day_of_week(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
return func5(a1, a2, 0);
}

original_code:
wday_t start_of_month(year_t year, month_t month)
{
 return day_of_week(year, month, 0);
}

canonical_original_code:
enum wday_t start_of_month(int year, enum month_t month)
{
 return day_of_week(year, month, 0);
}

user_defined_types: enum wday_t { SUN=0, MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6 }


decompiled_code:
__int64 __fastcall weeks_in_month(unsigned int a1, unsigned int a2)
{
int v2; // er10
int v3; // er11
int v4; // eax
int v5; // ecx

start_of_month(a1, a2);
v4 = days_in_month(v2, v3);
return (unsigned int)((v5 + v4 - 1) / 7 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2)
{
int v2; // er10
int v3; // er11
int v4; // eax
int v5; // ecx

func6(a1, a2);
v4 = func4(v2, v3);
return (unsigned int)((v5 + v4 - 1) / 7 + 1);
}

original_code:
int weeks_in_month(year_t year, month_t month)
{
 int start = start_of_month(year, month);
 int days = days_in_month(year, month);
 return ((start + days)-1) / 7 + 1;
}

canonical_original_code:
int weeks_in_month(int year, enum month_t month)
{
 int start = start_of_month(year, month);
 int days = days_in_month(year, month);
 return ((start + days)-1) / 7 + 1;
}


decompiled_code:
__int64 __fastcall add_months(int *a1, int *a2, int a3)
{
int v3; // edx
__int64 result; // rax

v3 = *a2 + a3 + 12 * *a1;
*a1 = v3 / 12;
result = (unsigned int)(12 * (v3 / 12));
*a2 = v3 % 12;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, int *a2, int a3)
{
int v3; // edx
__int64 result; // rax

v3 = *a2 + a3 + 12 * *a1;
*a1 = v3 / 12;
result = (unsigned int)(12 * (v3 / 12));
*a2 = v3 % 12;
return result;
}

original_code:
void add_months(year_t *year, month_t *month, int months)
{
 int total = *year*12 + *month + months;
 *year = total / 12;
 *month = total % 12;
}

canonical_original_code:
void add_months(int *year, enum month_t *month, int months)
{
 int total = *year*12 + *month + months;
 *year = total / 12;
 *month = total % 12;
}

variable_types:
year
int *

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

variable_types: months int

variable_types: total int


decompiled_code:
time_t __fastcall get_time(_DWORD *a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

v1 = a1[4];
*(_OWORD *)&v5.tm_sec = 0LL;
v5.tm_min = v1;
v2 = a1[3];
*(_OWORD *)&v5.tm_mon = 0LL;
v5.tm_hour = v2;
v3 = a1[2];
v5.tm_zone = 0LL;
*(_OWORD *)&v5.tm_isdst = 0LL;
v5.tm_mday = v3 + 1;
v5.tm_mon = a1[1];
v5.tm_year = *a1 - 1900;
return mktime(&v5);
}

canonical_decompiled_code:
time_t __fastcall func10(_DWORD *a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
struct tm v5; // [rsp+0h] [rbp-48h] BYREF

v1 = a1[4];
*(_OWORD *)&v5.tm_sec = 0LL;
v5.tm_min = v1;
v2 = a1[3];
*(_OWORD *)&v5.tm_mon = 0LL;
v5.tm_hour = v2;
v3 = a1[2];
v5.tm_zone = 0LL;
*(_OWORD *)&v5.tm_isdst = 0LL;
v5.tm_mday = v3 + 1;
v5.tm_mon = a1[1];
v5.tm_year = *a1 - 1900;
return mktime(&v5);
}

original_code:
stamp_t get_time(date_t *date)
{
 return mktime(&(struct tm){
  .tm_year = date->year-1900,
  .tm_mon = date->month,
  .tm_mday = date->day+1,
  .tm_hour = date->hour,
  .tm_min = date->min});
}

canonical_original_code:
long long get_time(struct date_t *date)
{
 return mktime(&(struct tm){
  .tm_year = date->year-1900,
  .tm_mon = date->month,
  .tm_mday = date->day+1,
  .tm_hour = date->hour,
  .tm_min = date->min});
}

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

return_type: long long

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


decompiled_code:
time_t __fastcall get_mins(_DWORD *a1, _DWORD *a2)
{
time_t v2; // rbx

v2 = get_time(a2);
return (v2 - get_time(a1)) / 60;
}

canonical_decompiled_code:
time_t __fastcall func11(_DWORD *a1, _DWORD *a2)
{
time_t v2; // rbx

v2 = func10(a2);
return (v2 - func10(a1)) / 60;
}

original_code:
int get_mins(date_t *start, date_t *end)
{
 return (get_time(end)-get_time(start))/60;
}

canonical_original_code:
int get_mins(struct date_t *start, struct date_t *end)
{
 return (get_time(end)-get_time(start))/60;
}

variable_types:
end
struct date_t *


compare

decompiled_code:
__int64 __fastcall compare(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // edx
int v4; // edx
int v5; // edx
int v6; // eax
bool v7; // cc

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
{
result = 1LL;
if ( *a1 == *a2 )
{
v3 = a2[1];
result = 0xFFFFFFFFLL;
if ( a1[1] >= v3 )
{
result = 1LL;
if ( a1[1] == v3 )
{
v4 = a2[2];
result = 0xFFFFFFFFLL;
if ( a1[2] >= v4 )
{
result = 1LL;
if ( a1[2] == v4 )
{
v5 = a2[3];
result = 0xFFFFFFFFLL;
if ( a1[3] >= v5 )
{
result = 1LL;
if ( a1[3] == v5 )
{
v6 = a2[4];
v7 = a1[4] < v6;
result = a1[4] > v6;
if ( v7 )
result = 0xFFFFFFFFLL;
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // edx
int v4; // edx
int v5; // edx
int v6; // eax
bool v7; // cc

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
{
result = 1LL;
if ( *a1 == *a2 )
{
v3 = a2[1];
result = 0xFFFFFFFFLL;
if ( a1[1] >= v3 )
{
result = 1LL;
if ( a1[1] == v3 )
{
v4 = a2[2];
result = 0xFFFFFFFFLL;
if ( a1[2] >= v4 )
{
result = 1LL;
if ( a1[2] == v4 )
{
v5 = a2[3];
result = 0xFFFFFFFFLL;
if ( a1[3] >= v5 )
{
result = 1LL;
if ( a1[3] == v5 )
{
v6 = a2[4];
v7 = a1[4] < v6;
result = a1[4] > v6;
if ( v7 )
result = 0xFFFFFFFFLL;
}
}
}
}
}
}
}
}
return result;
}

original_code:
int compare(date_t *a, date_t *b)
{
 int rval = a->year < b->year ? -1 : a->year > b->year ? 1 :
            a->month < b->month ? -1 : a->month > b->month ? 1 :
            a->day < b->day ? -1 : a->day > b->day ? 1 :
            a->hour < b->hour ? -1 : a->hour > b->hour ? 1 :
            a->min < b->min ? -1 : a->min > b->min ? 1 : 0;
 return rval;
}

canonical_original_code:
int compare(struct date_t *a, struct date_t *b)
{
 int rval = a->year < b->year ? -1 : a->year > b->year ? 1 :
            a->month < b->month ? -1 : a->month > b->month ? 1 :
            a->day < b->day ? -1 : a->day > b->day ? 1 :
            a->hour < b->hour ? -1 : a->hour > b->hour ? 1 :
            a->min < b->min ? -1 : a->min > b->min ? 1 : 0;
 return rval;
}

variable_types:
b
struct date_t *

variable_types: rval int


decompiled_code:
_BOOL8 __fastcall same_day(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 && a1[1] == a2[1] )
result = a1[2] == a2[2];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(_DWORD *a1, _DWORD *a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == *a2 && a1[1] == a2[1] )
result = a1[2] == a2[2];
return result;
}

original_code:
int same_day(date_t *a, date_t *b)
{
 return a->year == b->year &&
        a->month == b->month &&
        a->day == b->day;
}

canonical_original_code:
int same_day(struct date_t *a, struct date_t *b)
{
 return a->year == b->year &&
        a->month == b->month &&
        a->day == b->day;
}


before

decompiled_code:
__int64 __fastcall before(_DWORD *a1, int a2, int a3, int a4, int a5, int a6)
{
int v7[8]; // [rsp+0h] [rbp-20h] BYREF

v7[0] = a2;
v7[5] = 0;
v7[1] = a3;
v7[2] = a4;
v7[3] = a5;
v7[4] = a6;
return (unsigned int)compare(a1, v7) >> 31;
}

original_code:
int before(date_t *start, int year, int month, int day, int hour, int min)
{
 return compare(start, &(date_t){year, month, day, hour, min}) < 0;
}

canonical_original_code:
int before(struct date_t *start, int year, int month, int day, int hour, int min)
{
 return compare(start, &(struct date_t){year, month, day, hour, min}) < 0;
}

variable_types: month int

variable_types: hour int

variable_types: min int


original_code:
int all_day(date_t *start, date_t *end)
{
 date_t test = *start;
 add_days(&test.year, &test.month, &test.day, 1);
 return compare(&test, end) <= 0;
}

canonical_original_code:
int all_day(struct date_t *start, struct date_t *end)
{
 struct date_t test = *start;
 add_days(&test.year, &test.month, &test.day, 1);
 return compare(&test, end) <= 0;
}

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


decompiled_code:
_BOOL8 __fastcall no_date(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int no_date(date_t *date)
{
 return date->year == 0;
}

canonical_original_code:
int no_date(struct date_t *date)
{
 return date->year == 0;
}


decompiled_code:
char *__fastcall month_to_str(unsigned int a1)
{
return map_4[a1 % 0xC];
}

canonical_decompiled_code:
char *__fastcall func17(unsigned int a1)
{
return map_4[a1 % 0xC];
}

original_code:
const char *month_to_str(month_t month)
{
 static const char *map[] =
  { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", };
 return map[month%12];
}

canonical_original_code:
char *month_to_str(enum month_t month)
{
 static char *map[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", };
 return map[month%12];
}

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

variable_types:
map
char *[]

return_type: char *


decompiled_code:
char *__fastcall month_to_string(unsigned int a1)
{
return map_3[a1 % 0xC];
}

canonical_decompiled_code:
char *__fastcall func18(unsigned int a1)
{
return map_3[a1 % 0xC];
}

original_code:
const char *month_to_string(month_t month)
{
 static const char *map[] =
  { "January", "February", "March", "April",
    "May", "June", "July", "August",
    "September", "October", "November", "December" };
 return map[month%12];
}

canonical_original_code:
char *month_to_string(enum month_t month)
{
 static char *map[] = { "January", "February", "March", "April",
    "May", "June", "July", "August",
    "September", "October", "November", "December" };
 return map[month%12];
}


decompiled_code:
char *__fastcall day_to_st(unsigned int a1)
{
return map_2[a1 % 7];
}

canonical_decompiled_code:
char *__fastcall func19(unsigned int a1)
{
return map_2[a1 % 7];
}

original_code:
const char *day_to_st(wday_t day)
{
 static const char *map[] =
  { "Su","Mo", "Tu", "We", "Th", "Fr", "Sa" };
 return map[day%7];
}

canonical_original_code:
char *day_to_st(enum wday_t day)
{
 static char *map[] = { "Su","Mo", "Tu", "We", "Th", "Fr", "Sa" };
 return map[day%7];
}

variable_types: enum wday_t { SUN=0, MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6 }


decompiled_code:
char *__fastcall day_to_str(unsigned int a1)
{
return map_1[a1 % 7];
}

canonical_decompiled_code:
char *__fastcall func20(unsigned int a1)
{
return map_1[a1 % 7];
}

original_code:
const char *day_to_str(wday_t day)
{
 static const char *map[] =
  { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
 return map[day%7];
}

canonical_original_code:
char *day_to_str(enum wday_t day)
{
 static char *map[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
 return map[day%7];
}


decompiled_code:
char *__fastcall day_to_string(unsigned int a1)
{
return map_0[a1 % 7];
}

canonical_decompiled_code:
char *__fastcall func21(unsigned int a1)
{
return map_0[a1 % 7];
}

original_code:
const char *day_to_string(wday_t day)
{
 static const char *map[] =
  { "Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday" };
 return map[day%7];
}

canonical_original_code:
char *day_to_string(enum wday_t day)
{
 static char *map[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday" };
 return map[day%7];
}


decompiled_code:
int date_test()
{
unsigned int v0; // ebx
char *v1; // rax
unsigned int v2; // eax
char *v3; // rax
unsigned int v4; // eax
int v5; // esi
unsigned int v6; // eax
int result; // eax

v0 = 0;
puts("Info");
puts(" Year Month Start Weeks Days");
do
{
printf(" %-5d", 2012LL);
v1 = month_to_string(v0);
printf(" %-10s", v1);
v2 = start_of_month(0x7DCu, v0);
v3 = day_to_str(v2);
printf(" %-6s", v3);
v4 = weeks_in_month(0x7DCu, v0);
printf(" %-6d", v4);
v5 = v0++;
v6 = days_in_month(2012, v5);
printf(" %-2d", v6);
result = putchar(10);
}
while ( v0 != 12 );
return result;
}

canonical_decompiled_code:
int func22()
{
unsigned int v0; // ebx
char *v1; // rax
unsigned int v2; // eax
char *v3; // rax
unsigned int v4; // eax
int v5; // esi
unsigned int v6; // eax
int result; // eax

v0 = 0;
puts("Info");
puts(" Year Month Start Weeks Days");
do
{
printf(" %-5d", 2012LL);
v1 = func18(v0);
printf(" %-10s", v1);
v2 = func6(0x7DCu, v0);
v3 = func20(v2);
printf(" %-6s", v3);
v4 = func7(0x7DCu, v0);
printf(" %-6d", v4);
v5 = v0++;
v6 = func4(2012, v5);
printf(" %-2d", v6);
result = putchar(10);
}
while ( v0 != 12 );
return result;
}

original_code:
void date_test(void)
{
 printf("Info\n");
 printf("  Year   Month       Start   Weeks   Days\n");
 for (int y = 2012; y <= 2012; y++)
 for (int m = JAN; m <= DEC; m++) {
  printf("  %-5d", y);
  printf("  %-10s", month_to_string(m));
  printf("  %-6s", day_to_str(start_of_month(y,m)));
  printf("  %-6d", weeks_in_month(y,m));
  printf("  %-2d", days_in_month(y,m));
  printf("\n");
 }
}

canonical_original_code:
void date_test()
{
 printf("Info\n");
 printf("  Year   Month       Start   Weeks   Days\n");
 for (int y = 2012; y <= 2012; y++)
 for (int m = JAN; m <= DEC; m++) {
  printf("  %-5d", y);
  printf("  %-10s", month_to_string(m));
  printf("  %-6s", day_to_str(start_of_month(y,m)));
  printf("  %-6d", weeks_in_month(y,m));
  printf("  %-2d", days_in_month(y,m));
  printf("\n");
 }
}

variable_types: y int

variable_types: m int


decompiled_code:
int __fastcall draw_todo(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
char *v4; // rax
char *v5; // rax
const char *v6; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Todo\n");
v1 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v1 = "[none]";
wprintw(win, " Name: %s\n", v1);
v2 = *(const char **)(a1 + 8);
if ( !v2 )
v2 = "[none]";
wprintw(win, " Description: %s\n", v2);
v3 = *(const char **)(a1 + 16);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Category: %s\n", v3);
wprintw(win, " Completed: %d%%\n", *(unsigned int *)(a1 + 24));
v4 = timestr_isra_0(
*(_DWORD *)(a1 + 28),
*(_DWORD *)(a1 + 32),
*(_DWORD *)(a1 + 36),
*(_DWORD *)(a1 + 40),
*(unsigned int *)(a1 + 44));
wprintw(win, " Start Time: %s\n", v4);
v5 = timestr_isra_0(
*(_DWORD *)(a1 + 52),
*(_DWORD *)(a1 + 56),
*(_DWORD *)(a1 + 60),
*(_DWORD *)(a1 + 64),
*(unsigned int *)(a1 + 68));
wprintw(win, " Due Date: %s\n", v5);
v6 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v6 )
v6 = "[none]";
return wprintw(win, " Calendar: %s\n", v6);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
char *v4; // rax
char *v5; // rax
const char *v6; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Todo\n");
v1 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v1 = "[none]";
wprintw(win, " Name: %s\n", v1);
v2 = *(const char **)(a1 + 8);
if ( !v2 )
v2 = "[none]";
wprintw(win, " Description: %s\n", v2);
v3 = *(const char **)(a1 + 16);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Category: %s\n", v3);
wprintw(win, " Completed: %d%%\n", *(unsigned int *)(a1 + 24));
v4 = func1(
*(_DWORD *)(a1 + 28),
*(_DWORD *)(a1 + 32),
*(_DWORD *)(a1 + 36),
*(_DWORD *)(a1 + 40),
*(unsigned int *)(a1 + 44));
wprintw(win, " Start Time: %s\n", v4);
v5 = func1(
*(_DWORD *)(a1 + 52),
*(_DWORD *)(a1 + 56),
*(_DWORD *)(a1 + 60),
*(_DWORD *)(a1 + 64),
*(unsigned int *)(a1 + 68));
wprintw(win, " Due Date: %s\n", v5);
v6 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v6 )
v6 = "[none]";
return wprintw(win, " Calendar: %s\n", v6);
}

original_code:
static void draw_todo(todo_t *todo)
{
 wmove(win, 0, 0);
 wprintw(win, "Edit Todo\n");
 wprintw(win, "    Name:        %s\n", todo->name ?: "[none]");
 wprintw(win, "    Description: %s\n", todo->desc ?: "[none]");
 wprintw(win, "    Category:    %s\n", todo->cat ?: "[none]");
 wprintw(win, "    Completed:   %d%%\n", todo->status);
 wprintw(win, "    Start Time:  %s\n", timestr(todo->start));
 wprintw(win, "    Due Date:    %s\n", timestr(todo->due));
 wprintw(win, "    Calendar:    %s\n", todo->cal->name ?: "[none]");
}

canonical_original_code:
static void draw_todo(struct todo_t *todo)
{
 wmove(win, 0, 0);
 wprintw(win, "Edit Todo\n");
 wprintw(win, "    Name:        %s\n", todo->name ?: "[none]");
 wprintw(win, "    Description: %s\n", todo->desc ?: "[none]");
 wprintw(win, "    Category:    %s\n", todo->cat ?: "[none]");
 wprintw(win, "    Completed:   %d%%\n", todo->status);
 wprintw(win, "    Start Time:  %s\n", timestr(todo->start));
 wprintw(win, "    Due Date:    %s\n", timestr(todo->due));
 wprintw(win, "    Calendar:    %s\n", todo->cal->name ?: "[none]");
}

variable_types: struct todo_t { char *name; char *desc; char *cat; enum status_t { NEW=0, DONE=100 } status; 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 due; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct todo_t *next; struct todo_t *prev; } *

user_defined_types: struct todo_t { char *name; char *desc; char *cat; enum status_t status; struct date_t start; struct date_t due; struct cal_t *cal; struct todo_t *next; struct todo_t *prev; }


decompiled_code:
int __fastcall draw_event(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
char *v5; // rax
char *v6; // rax
const char *v7; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Event\n");
v1 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v1 = "[none]";
wprintw(win, " Name: %s\n", v1);
v2 = *(const char **)(a1 + 8);
if ( !v2 )
v2 = "[none]";
wprintw(win, " Description: %s\n", v2);
v3 = *(const char **)(a1 + 16);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Location: %s\n", v3);
v4 = *(const char **)(a1 + 24);
if ( !v4 )
v4 = "[none]";
wprintw(win, " Category: %s\n", v4);
v5 = timestr_isra_0(
*(_DWORD *)(a1 + 32),
*(_DWORD *)(a1 + 36),
*(_DWORD *)(a1 + 40),
*(_DWORD *)(a1 + 44),
*(unsigned int *)(a1 + 48));
wprintw(win, " Start Time: %s\n", v5);
v6 = timestr_isra_0(
*(_DWORD *)(a1 + 56),
*(_DWORD *)(a1 + 60),
*(_DWORD *)(a1 + 64),
*(_DWORD *)(a1 + 68),
*(unsigned int *)(a1 + 72));
wprintw(win, " End Time: %s\n", v6);
v7 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v7 )
v7 = "[none]";
return wprintw(win, " Calendar: %s\n", v7);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
char *v5; // rax
char *v6; // rax
const char *v7; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Event\n");
v1 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v1 = "[none]";
wprintw(win, " Name: %s\n", v1);
v2 = *(const char **)(a1 + 8);
if ( !v2 )
v2 = "[none]";
wprintw(win, " Description: %s\n", v2);
v3 = *(const char **)(a1 + 16);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Location: %s\n", v3);
v4 = *(const char **)(a1 + 24);
if ( !v4 )
v4 = "[none]";
wprintw(win, " Category: %s\n", v4);
v5 = func1(
*(_DWORD *)(a1 + 32),
*(_DWORD *)(a1 + 36),
*(_DWORD *)(a1 + 40),
*(_DWORD *)(a1 + 44),
*(unsigned int *)(a1 + 48));
wprintw(win, " Start Time: %s\n", v5);
v6 = func1(
*(_DWORD *)(a1 + 56),
*(_DWORD *)(a1 + 60),
*(_DWORD *)(a1 + 64),
*(_DWORD *)(a1 + 68),
*(unsigned int *)(a1 + 72));
wprintw(win, " End Time: %s\n", v6);
v7 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v7 )
v7 = "[none]";
return wprintw(win, " Calendar: %s\n", v7);
}

original_code:
static void draw_event(event_t *event)
{
 wmove(win, 0, 0);
 wprintw(win, "Edit Event\n");
 wprintw(win, "    Name:        %s\n", event->name ?: "[none]");
 wprintw(win, "    Description: %s\n", event->desc ?: "[none]");
 wprintw(win, "    Location:    %s\n", event->loc ?: "[none]");
 wprintw(win, "    Category:    %s\n", event->cat ?: "[none]");
 wprintw(win, "    Start Time:  %s\n", timestr(event->start));
 wprintw(win, "    End Time:    %s\n", timestr(event->end));
 wprintw(win, "    Calendar:    %s\n", event->cal->name ?: "[none]");
}

canonical_original_code:
static void draw_event(struct event_t *event)
{
 wmove(win, 0, 0);
 wprintw(win, "Edit Event\n");
 wprintw(win, "    Name:        %s\n", event->name ?: "[none]");
 wprintw(win, "    Description: %s\n", event->desc ?: "[none]");
 wprintw(win, "    Location:    %s\n", event->loc ?: "[none]");
 wprintw(win, "    Category:    %s\n", event->cat ?: "[none]");
 wprintw(win, "    Start Time:  %s\n", timestr(event->start));
 wprintw(win, "    End Time:    %s\n", timestr(event->end));
 wprintw(win, "    Calendar:    %s\n", event->cal->name ?: "[none]");
}

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

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


decompiled_code:
void edit_size()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

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

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

variable_types: rows int

variable_types: cols int


decompiled_code:
int edit_draw()
{
int result; // eax

result = EDIT;
if ( EDIT == 2 )
return draw_event(EVENT);
if ( EDIT == 3 )
result = draw_todo(TODO);
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax

result = EDIT;
if ( EDIT == 2 )
return func3(EVENT);
if ( EDIT == 3 )
result = func2(TODO);
return result;
}

original_code:
void edit_draw(void)
{
 switch (EDIT) {
  case EDIT_CAL: break;
  case EDIT_EVENT: draw_event(EVENT); break;
  case EDIT_TODO: draw_todo(TODO); break;
  default: break;
 }
}

canonical_original_code:
void edit_draw()
{
 switch (EDIT) {
  case EDIT_CAL: break;
  case EDIT_EVENT: draw_event(EVENT); break;
  case EDIT_TODO: draw_todo(TODO); break;
  default: break;
 }
}


decompiled_code:
__int64 edit_run()
{
if ( EDIT == 1 )
return 1LL;
if ( (unsigned int)(EDIT - 2) > 1 )
return 0LL;
return edit_event_constprop_0();
}

canonical_decompiled_code:
__int64 func7()
{
if ( EDIT == 1 )
return 1LL;
if ( (unsigned int)(EDIT - 2) > 1 )
return 0LL;
return func0();
}

original_code:
int edit_run(int key, mmask_t btn, int row, int col)
{
 switch (EDIT) {
  case EDIT_CAL: return 1;
  case EDIT_EVENT: return edit_event(EVENT, key, btn, row, col);
  case EDIT_TODO: return edit_todo(TODO, key, btn, row, col);
  default: return 0;
 }
}

canonical_original_code:
int edit_run(int key, unsigned int btn, int row, int col)
{
 switch (EDIT) {
  case EDIT_CAL: return 1;
  case EDIT_EVENT: return edit_event(EVENT, key, btn, row, col);
  case EDIT_TODO: return edit_todo(TODO, key, btn, row, col);
  default: return 0;
 }
}

variable_types: key int

variable_types:
btn
unsigned int

variable_types: row int

variable_types: col int


decompiled_code:
__int64 __fastcall week_size(int a1, int a2)
{
unsigned int v2; // ebp

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

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

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

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

variable_types: hdr int


decompiled_code:
int week_draw()
{
unsigned int v0; // ebp
unsigned int v1; // esi
unsigned int v2; // edx
int v3; // er12
int v4; // er13
__int64 v5; // rax
unsigned int v6; // ebx
__int64 v7; // rax
WINDOW *v8; // rdi
const char *v9; // r14
double v10; // xmm0_8
__int64 v11; // rax
double v12; // xmm0_8
int v13; // er13
int v14; // ebx
__int64 v15; // r14
int v16; // ebp
__int64 v17; // rdx
int v18; // eax
int v19; // esi
int v20; // ebx
int v21; // ebx
__int64 v22; // r8
int v23; // esi
__int64 v24; // r15
unsigned int v25; // er14
unsigned int v26; // ebp
unsigned int v27; // edi
__int64 v28; // r8
int v29; // eax
int v30; // ebx
int v31; // eax
int v32; // ebx
int v33; // ebx
int result; // eax
int v35; // [rsp+0h] [rbp-D8h]
unsigned int v36; // [rsp+0h] [rbp-D8h]
unsigned int v37; // [rsp+Ch] [rbp-CCh]
float v38; // [rsp+10h] [rbp-C8h]
int v39; // [rsp+18h] [rbp-C0h]
unsigned int v40; // [rsp+1Ch] [rbp-BCh]
int v41; // [rsp+2Ch] [rbp-ACh]
__int64 v42; // [rsp+30h] [rbp-A8h]
int v43; // [rsp+38h] [rbp-A0h]
unsigned int v44; // [rsp+3Ch] [rbp-9Ch]
unsigned int v45; // [rsp+40h] [rbp-98h]
unsigned int v46; // [rsp+44h] [rbp-94h]
unsigned int v47; // [rsp+48h] [rbp-90h]
int v48; // [rsp+4Ch] [rbp-8Ch]
int v49; // [rsp+50h] [rbp-88h]
int v50; // [rsp+54h] [rbp-84h]
int v51; // [rsp+58h] [rbp-80h]
int v52; // [rsp+5Ch] [rbp-7Ch]
unsigned int v53; // [rsp+60h] [rbp-78h] BYREF
unsigned int v54; // [rsp+64h] [rbp-74h] BYREF
unsigned int v55; // [rsp+68h] [rbp-70h] BYREF
int v56; // [rsp+6Ch] [rbp-6Ch] BYREF
__int128 v57[2]; // [rsp+70h] [rbp-68h] BYREF
__int64 v58; // [rsp+90h] [rbp-48h]

v0 = 0;
v1 = SEL[1];
v2 = SEL[2];
v53 = SEL[0];
v48 = 3 - COMPACT;
v54 = v1;
v55 = v2;
v52 = COMPACT;
v38 = (float)(COLS - 6) / 7.0;
v3 = day_of_week();
add_days(&v53, &v54, &v55, (unsigned int)-v3);
cal_load(v53, v54, v55, 7LL);
v4 = COMPACT;
v49 = (int)((float)((float)v3 * v38) + 0.5);
v50 = (int)((float)((float)(v3 + 1) * v38) + 0.5);
if ( COMPACT )
{
v0 = 2359296;
v4 = 2359296;
}
wattr_on(win, v0, 0LL);
v5 = month_to_str(SEL[1]);
mvwprintw(win, 0, 0, "%-*s", (unsigned int)COLS, v5);
mvwprintw(win, 1, 0, "%-0*d", (unsigned int)COLS, SEL[0]);
wattr_off(win, v0, 0LL);
if ( wmove(win, 0, v49 + 6) != -1 )
whline(win, 0x20uLL, v50 - v49 - 1);
if ( wmove(win, 1, v49 + 6) != -1 )
whline(win, 0x20uLL, v50 - v49 - 1);
v6 = 0;
wattr_on(win, v0, 0LL);
do
{
if ( v38 >= 10.0 )
{
v7 = day_to_string(v6);
v8 = win;
v9 = (const char *)v7;
if ( v3 != v6 )
goto LABEL_9;
}
else
{
v11 = day_to_str(v6);
v8 = win;
v9 = (const char *)v11;
if ( v3 != v6 )
{
LABEL_9:
v10 = (float)((float)(int)v6 * v38) + 0.5;
mvwprintw(v8, 0, (int)v10 + 6, "%s", v9);
mvwprintw(win, 1, (int)v10 + 6, "%02d/%02d", v54 + 1, v55 + 1);
goto LABEL_10;
}
}
wattrset(v8, 0x200000);
v12 = (float)((float)v3 * v38) + 0.5;
mvwprintw(win, 0, (int)v12 + 6, "%s", v9);
mvwprintw(win, 1, (int)v12 + 6, "%02d/%02d", v54 + 1, v55 + 1);
wattrset(win, v4);
LABEL_10:
++v6;
add_days(&v53, &v54, &v55, 1LL);
}
while ( v6 != 7 );
v13 = 0;
v14 = 0;
wattr_off(win, v0, 0LL);
v15 = EVENTS;
add_days(&v53, &v54, &v55, 4294967289LL);
do
{
v35 = v13;
v16 = 0;
++v13;
if ( v15 )
{
while ( (unsigned int)before(v15 + 32, v53, v54, v55, 24LL, 0LL) )
{
if ( (unsigned int)before(v15 + 56, v53, v54, v55, 0LL, 1LL) || (int)get_mins(v15 + 32, v15 + 56) <= 1380 )
{
v15 = *(_QWORD *)(v15 + 88);
if ( v14 < v16 )
v14 = v16;
if ( !v15 )
break;
}
else
{
v17 = (unsigned int)(v48 + v16++);
v18 = (int)((float)((float)v35 * v38) + 0.5);
event_line(
win,
v15,
v17,
(unsigned int)(v18 + 6),
(unsigned int)((int)((float)((float)v13 * v38) + 0.5) - 1 - v18),
2LL);
v15 = *(_QWORD *)(v15 + 88);
if ( v14 < v16 )
v14 = v16;
if ( !v15 )
break;
}
}
}
add_days(&v53, &v54, &v55, 1LL);
}
while ( v13 != 7 );
v19 = v14;
v51 = v14;
v20 = v48;
if ( v19 )
{
v20 = v19 + v48;
if ( !COMPACT )
v20 = ++v51 + v48;
}
wshrink(times, (__PAIR64__(v20, COMPACT) - 1) >> 32);
wshrink(body, (__PAIR64__(v20, COMPACT) - 1) >> 32);
v21 = 0;
mvwprintw(
times,
COMPACT == 0,
0,
"%02d:%02d",
(unsigned int)((line / 4 - 1) % 12 + 1),
(unsigned int)(15 * line % 60));
do
{
v22 = (unsigned int)((v21 - 1) % 12 + 1);
v23 = (COMPACT == 0) + 4 * v21++ - line;
mvwprintw(times, v23, 0, "%02d:%02d", v22, 0LL);
}
while ( v21 != 24 );
if ( !EVENT )
EVENT = find_event(SEL);
v24 = EVENTS;
add_days(&v53, &v54, &v55, 4294967289LL);
v56 = 0;
v58 = 0LL;
v41 = 0;
v42 = 0LL;
v57[0] = 0LL;
v57[1] = 0LL;
while ( 2 )
{
v25 = 0;
v43 = v41++;
while ( 2 )
{
v37 = 0;
while ( 2 )
{
v26 = v37;
v27 = v37 + 15;
v37 += 15;
if ( v24 )
{
while ( 1 )
{
LABEL_40:
if ( !(unsigned int)before(v24 + 32, v53, v54, v55, v25 + v27 / 0x3C, v27 % 0x3C) )
goto LABEL_45;
if ( (unsigned int)before(v24 + 32, v53, v54, v55, v25, v26) || (int)get_mins(v24 + 32, v24 + 56) > 1380 )
goto LABEL_39;
v39 = get_col(v57, 5LL, v24, &v56);
v40 = (COMPACT == 0) + 4 * v25 + (int)v26 / 15 - line;
v36 = (int)((float)((float)v43 * v38) + 0.5) + 3 * v39 + 1;
v28 = (unsigned int)((int)(get_mins(v24 + 32, v24 + 56) - 1) / 15 + 1);
if ( EVENT == v24 )
break;
event_box(body, v24, v40, v36, v28, -3 * (v56 + ~v39) + (int)((float)((float)v41 * v38) + 0.5) - v36);
v24 = *(_QWORD *)(v24 + 88);
if ( !v24 )
goto LABEL_45;
}
v42 = v24;
v44 = v28;
v45 = -3 * (v56 + ~v39) + (int)((float)((float)v41 * v38) + 0.5) - v36;
v46 = v40;
v47 = (int)((float)((float)v43 * v38) + 0.5) + 3 * v39 + 1;
LABEL_39:
v24 = *(_QWORD *)(v24 + 88);
if ( !v24 )
goto LABEL_45;
goto LABEL_40;
}
LABEL_45:
if ( v37 != 60 )
continue;
break;
}
if ( ++v25 != 24 )
continue;
break;
}
add_days(&v53, &v54, &v55, 1LL);
if ( v41 != 7 )
continue;
break;
}
if ( v42 )
event_box(body, v42, v46, v47, v44, v45);
v29 = COMPACT;
if ( !COMPACT )
{
if ( wmove(win, 2 - v52, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
v29 = COMPACT;
if ( v51 && !COMPACT )
{
if ( wmove(win, 2 - v52 + v51, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
v29 = COMPACT;
}
}
v30 = 0;
while ( 1 )
{
if ( wmove(body, v29 == 0, (int)((float)((float)v30 * v38) + 0.5)) != -1 )
wvline(body, LODWORD(acs_map[60]), LINES - v48 + COMPACT - 2 - v51);
if ( ++v30 == 7 )
break;
v29 = COMPACT;
}
if ( wmove(body, 0, v49) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v48);
if ( wmove(body, 0, v50) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v48);
v31 = line;
v32 = line + 6;
if ( line + 3 >= 0 )
v32 = line + 3;
v33 = v32 >> 2;
if ( line <= 92 )
{
while ( 1 )
{
if ( wmove(body, 4 * v33 - v31 + (COMPACT == 0), v49) != -1 )
wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2352));
if ( wmove(body, (COMPACT == 0) + 4 * v33 - line, v50) != -1 )
wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2380));
if ( ++v33 == 24 )
break;
v31 = line;
}
}
result = COMPACT;
if ( !COMPACT )
{
result = wmove(body, 0, v49);
if ( result != -1 )
result = whline(body, LODWORD(acs_map[24]), v50 - v49 + 1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
unsigned int v0; // ebp
unsigned int v1; // esi
unsigned int v2; // edx
int v3; // er12
int v4; // er13
__int64 v5; // rax
unsigned int v6; // ebx
__int64 v7; // rax
WINDOW *v8; // rdi
const char *v9; // r14
double v10; // xmm0_8
__int64 v11; // rax
double v12; // xmm0_8
int v13; // er13
int v14; // ebx
__int64 v15; // r14
int v16; // ebp
__int64 v17; // rdx
int v18; // eax
int v19; // esi
int v20; // ebx
int v21; // ebx
__int64 v22; // r8
int v23; // esi
__int64 v24; // r15
unsigned int v25; // er14
unsigned int v26; // ebp
unsigned int v27; // edi
__int64 v28; // r8
int v29; // eax
int v30; // ebx
int v31; // eax
int v32; // ebx
int v33; // ebx
int result; // eax
int v35; // [rsp+0h] [rbp-D8h]
unsigned int v36; // [rsp+0h] [rbp-D8h]
unsigned int v37; // [rsp+Ch] [rbp-CCh]
float v38; // [rsp+10h] [rbp-C8h]
int v39; // [rsp+18h] [rbp-C0h]
unsigned int v40; // [rsp+1Ch] [rbp-BCh]
int v41; // [rsp+2Ch] [rbp-ACh]
__int64 v42; // [rsp+30h] [rbp-A8h]
int v43; // [rsp+38h] [rbp-A0h]
unsigned int v44; // [rsp+3Ch] [rbp-9Ch]
unsigned int v45; // [rsp+40h] [rbp-98h]
unsigned int v46; // [rsp+44h] [rbp-94h]
unsigned int v47; // [rsp+48h] [rbp-90h]
int v48; // [rsp+4Ch] [rbp-8Ch]
int v49; // [rsp+50h] [rbp-88h]
int v50; // [rsp+54h] [rbp-84h]
int v51; // [rsp+58h] [rbp-80h]
int v52; // [rsp+5Ch] [rbp-7Ch]
unsigned int v53; // [rsp+60h] [rbp-78h] BYREF
unsigned int v54; // [rsp+64h] [rbp-74h] BYREF
unsigned int v55; // [rsp+68h] [rbp-70h] BYREF
int v56; // [rsp+6Ch] [rbp-6Ch] BYREF
__int128 v57[2]; // [rsp+70h] [rbp-68h] BYREF
__int64 v58; // [rsp+90h] [rbp-48h]

v0 = 0;
v1 = SEL[1];
v2 = SEL[2];
v53 = SEL[0];
v48 = 3 - COMPACT;
v54 = v1;
v55 = v2;
v52 = COMPACT;
v38 = (float)(COLS - 6) / 7.0;
v3 = day_of_week();
add_days(&v53, &v54, &v55, (unsigned int)-v3);
cal_load(v53, v54, v55, 7LL);
v4 = COMPACT;
v49 = (int)((float)((float)v3 * v38) + 0.5);
v50 = (int)((float)((float)(v3 + 1) * v38) + 0.5);
if ( COMPACT )
{
v0 = 2359296;
v4 = 2359296;
}
wattr_on(win, v0, 0LL);
v5 = month_to_str(SEL[1]);
mvwprintw(win, 0, 0, "%-*s", (unsigned int)COLS, v5);
mvwprintw(win, 1, 0, "%-0*d", (unsigned int)COLS, SEL[0]);
wattr_off(win, v0, 0LL);
if ( wmove(win, 0, v49 + 6) != -1 )
whline(win, 0x20uLL, v50 - v49 - 1);
if ( wmove(win, 1, v49 + 6) != -1 )
whline(win, 0x20uLL, v50 - v49 - 1);
v6 = 0;
wattr_on(win, v0, 0LL);
do
{
if ( v38 >= 10.0 )
{
v7 = day_to_string(v6);
v8 = win;
v9 = (const char *)v7;
if ( v3 != v6 )
goto LABEL_9;
}
else
{
v11 = day_to_str(v6);
v8 = win;
v9 = (const char *)v11;
if ( v3 != v6 )
{
LABEL_9:
v10 = (float)((float)(int)v6 * v38) + 0.5;
mvwprintw(v8, 0, (int)v10 + 6, "%s", v9);
mvwprintw(win, 1, (int)v10 + 6, "%02d/%02d", v54 + 1, v55 + 1);
goto LABEL_10;
}
}
wattrset(v8, 0x200000);
v12 = (float)((float)v3 * v38) + 0.5;
mvwprintw(win, 0, (int)v12 + 6, "%s", v9);
mvwprintw(win, 1, (int)v12 + 6, "%02d/%02d", v54 + 1, v55 + 1);
wattrset(win, v4);
LABEL_10:
++v6;
add_days(&v53, &v54, &v55, 1LL);
}
while ( v6 != 7 );
v13 = 0;
v14 = 0;
wattr_off(win, v0, 0LL);
v15 = EVENTS;
add_days(&v53, &v54, &v55, 4294967289LL);
do
{
v35 = v13;
v16 = 0;
++v13;
if ( v15 )
{
while ( (unsigned int)before(v15 + 32, v53, v54, v55, 24LL, 0LL) )
{
if ( (unsigned int)before(v15 + 56, v53, v54, v55, 0LL, 1LL) || (int)get_mins(v15 + 32, v15 + 56) <= 1380 )
{
v15 = *(_QWORD *)(v15 + 88);
if ( v14 < v16 )
v14 = v16;
if ( !v15 )
break;
}
else
{
v17 = (unsigned int)(v48 + v16++);
v18 = (int)((float)((float)v35 * v38) + 0.5);
event_line(
win,
v15,
v17,
(unsigned int)(v18 + 6),
(unsigned int)((int)((float)((float)v13 * v38) + 0.5) - 1 - v18),
2LL);
v15 = *(_QWORD *)(v15 + 88);
if ( v14 < v16 )
v14 = v16;
if ( !v15 )
break;
}
}
}
add_days(&v53, &v54, &v55, 1LL);
}
while ( v13 != 7 );
v19 = v14;
v51 = v14;
v20 = v48;
if ( v19 )
{
v20 = v19 + v48;
if ( !COMPACT )
v20 = ++v51 + v48;
}
wshrink(times, (__PAIR64__(v20, COMPACT) - 1) >> 32);
wshrink(body, (__PAIR64__(v20, COMPACT) - 1) >> 32);
v21 = 0;
mvwprintw(
times,
COMPACT == 0,
0,
"%02d:%02d",
(unsigned int)((line / 4 - 1) % 12 + 1),
(unsigned int)(15 * line % 60));
do
{
v22 = (unsigned int)((v21 - 1) % 12 + 1);
v23 = (COMPACT == 0) + 4 * v21++ - line;
mvwprintw(times, v23, 0, "%02d:%02d", v22, 0LL);
}
while ( v21 != 24 );
if ( !EVENT )
EVENT = find_event(SEL);
v24 = EVENTS;
add_days(&v53, &v54, &v55, 4294967289LL);
v56 = 0;
v58 = 0LL;
v41 = 0;
v42 = 0LL;
v57[0] = 0LL;
v57[1] = 0LL;
while ( 2 )
{
v25 = 0;
v43 = v41++;
while ( 2 )
{
v37 = 0;
while ( 2 )
{
v26 = v37;
v27 = v37 + 15;
v37 += 15;
if ( v24 )
{
while ( 1 )
{
LABEL_40:
if ( !(unsigned int)before(v24 + 32, v53, v54, v55, v25 + v27 / 0x3C, v27 % 0x3C) )
goto LABEL_45;
if ( (unsigned int)before(v24 + 32, v53, v54, v55, v25, v26) || (int)get_mins(v24 + 32, v24 + 56) > 1380 )
goto LABEL_39;
v39 = get_col(v57, 5LL, v24, &v56);
v40 = (COMPACT == 0) + 4 * v25 + (int)v26 / 15 - line;
v36 = (int)((float)((float)v43 * v38) + 0.5) + 3 * v39 + 1;
v28 = (unsigned int)((int)(get_mins(v24 + 32, v24 + 56) - 1) / 15 + 1);
if ( EVENT == v24 )
break;
event_box(body, v24, v40, v36, v28, -3 * (v56 + ~v39) + (int)((float)((float)v41 * v38) + 0.5) - v36);
v24 = *(_QWORD *)(v24 + 88);
if ( !v24 )
goto LABEL_45;
}
v42 = v24;
v44 = v28;
v45 = -3 * (v56 + ~v39) + (int)((float)((float)v41 * v38) + 0.5) - v36;
v46 = v40;
v47 = (int)((float)((float)v43 * v38) + 0.5) + 3 * v39 + 1;
LABEL_39:
v24 = *(_QWORD *)(v24 + 88);
if ( !v24 )
goto LABEL_45;
goto LABEL_40;
}
LABEL_45:
if ( v37 != 60 )
continue;
break;
}
if ( ++v25 != 24 )
continue;
break;
}
add_days(&v53, &v54, &v55, 1LL);
if ( v41 != 7 )
continue;
break;
}
if ( v42 )
event_box(body, v42, v46, v47, v44, v45);
v29 = COMPACT;
if ( !COMPACT )
{
if ( wmove(win, 2 - v52, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
v29 = COMPACT;
if ( v51 && !COMPACT )
{
if ( wmove(win, 2 - v52 + v51, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
v29 = COMPACT;
}
}
v30 = 0;
while ( 1 )
{
if ( wmove(body, v29 == 0, (int)((float)((float)v30 * v38) + 0.5)) != -1 )
wvline(body, LODWORD(acs_map[60]), LINES - v48 + COMPACT - 2 - v51);
if ( ++v30 == 7 )
break;
v29 = COMPACT;
}
if ( wmove(body, 0, v49) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v48);
if ( wmove(body, 0, v50) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v48);
v31 = line;
v32 = line + 6;
if ( line + 3 >= 0 )
v32 = line + 3;
v33 = v32 >> 2;
if ( line <= 92 )
{
while ( 1 )
{
if ( wmove(body, 4 * v33 - v31 + (COMPACT == 0), v49) != -1 )
wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2352));
if ( wmove(body, (COMPACT == 0) + 4 * v33 - line, v50) != -1 )
wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2380));
if ( ++v33 == 24 )
break;
v31 = line;
}
}
result = COMPACT;
if ( !COMPACT )
{
result = wmove(body, 0, v49);
if ( result != -1 )
result = whline(body, LODWORD(acs_map[24]), v50 - v49 + 1);
}
return result;
}

original_code:
void week_draw(void)
{
 int x = 6;
 int y = 3 - COMPACT;
 const float hstep = (float)(COLS-x)/7.0;
 int ex, ey, ew, eh;
 event_t *event, *ee;
 year_t year = SEL.year;
 month_t month = SEL.month;
 day_t day = SEL.day;
 int shift = day_of_week(year, month, day);
 add_days(&year, &month, &day, -shift);
 cal_load(year, month, day, 7);
 int l = ((int)(((shift+0)*hstep)+0.5));
 int r = ((int)(((shift+1)*hstep)+0.5));
 int rev = COMPACT ? ((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8)) : 0;
 wattr_on(win, (attr_t)(rev), ((void *)0));
 mvwprintw(win, 0, 0, "%-*s", COLS, month_to_str(SEL.month));
 mvwprintw(win, 1, 0, "%-0*d", COLS, SEL.year);
 wattr_off(win, (attr_t)(rev), ((void *)0));
 (wmove((win),(0),(x+l)) == (-1) ? (-1) : whline((win),(' '),(r-l-1)));
 (wmove((win),(1),(x+l)) == (-1) ? (-1) : whline((win),(' '),(r-l-1)));
 wattr_on(win, (attr_t)(rev), ((void *)0));
 for (int d = 0; d < 7; d++) {
  const char *str = hstep >= 10 ? day_to_string(d) : day_to_str(d);
  if (d == shift) wattrset(win, ((chtype)((1U)) << ((13) + 8)));
  mvwprintw(win, 0, x+((int)((d*hstep)+0.5)), "%s", str);
  mvwprintw(win, 1, x+((int)((d*hstep)+0.5)), "%02d/%02d", month+1, day+1);
  if (d == shift) wattrset(win, rev);
  add_days(&year, &month, &day, 1);
 }
 wattr_off(win, (attr_t)(rev), ((void *)0));
 int allday = 0;
 event = EVENTS;
 add_days(&year, &month, &day, -7);
 for (int d = 0; d < 7; d++) {
  int n = 0;
  while (event && before(&event->start, year, month, day, 24, 0)) {
   if (!before(&event->end, year, month, day, 0, 1) &&
       get_mins(&event->start, &event->end) > 23*60) {
    int s = ((int)((d*hstep)+0.5));
    int w = ((int)(((d+1)*hstep)+0.5)) - 1 - s;
    event_line(win, event, y+n++, x+s, w, 0x2);
   }
   event = event->next;
   if (n > allday)
    allday = n;
  }
  add_days(&year,&month,&day,1);
 }
 if (allday && !COMPACT)
  allday++;
 wshrink(times, y+allday-!COMPACT);
 wshrink(body, y+allday-!COMPACT);
 mvwprintw(times, !COMPACT, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
 for (int h = 0; h < 24; h++)
  mvwprintw(times, !COMPACT+h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
 if (!EVENT)
  EVENT = find_event(&SEL);
 ee = ((void *)0);
 event = EVENTS;
 add_days(&year, &month, &day, -7);
 event_t *active[5] = {};
 int ncols = 0;
 for (int d = 0; d < 7; d++, add_days(&year,&month,&day,1))
 for (int h = 0; h < 24; h++)
 for (int m = 0; m < 60; m+=15)
 while (event && before(&event->start,
   year, month, day, h+(m+15)/60, (m+15)%60)) {
  if (!before(&event->start, year, month, day, h, m) &&
      get_mins(&event->start, &event->end) <= 23*60) {
   int col = get_col(active, (sizeof(active)/sizeof((active)[0])), event, &ncols);
   int y = h*4 + m/15 - line + !COMPACT;
   int x = ((int)((d*hstep)+0.5)) + 1 + (col*3);
   int h = (get_mins(&event->start, &event->end)-1)/15+1;
   int w = ((int)(((d+1)*hstep)+0.5)) - x - ((ncols-1)-col)*3;
   if (event == EVENT) {
    ee = event; ex = x; ey = y; ew = w; eh = h;
   } else
    event_box(body, event, y, x, h, w);
  }
  event = event->next;
 }
 if (ee)
  event_box(body, ee, ey, ex, eh, ew);
 if (!COMPACT)
  (wmove((win),(y-1),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 if (!COMPACT && allday)
  (wmove((win),(y-1+allday),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 for (int d = 0; d < 7; d++)
  (wmove((body),(!COMPACT),(((int)((d*hstep)+0.5)))) == (-1) ? (-1) : wvline((body),((acs_map[(unsigned char)(('x'))])),(LINES-y-2+COMPACT-allday)));
 (wmove(body,(0),(l)) == (-1) ? (-1) : wvline_set((body),((&_nc_wacs[(unsigned char)(('X'))])),(LINES-y-1+COMPACT)));
 (wmove(body,(0),(r)) == (-1) ? (-1) : wvline_set((body),((&_nc_wacs[(unsigned char)(('X'))])),(LINES-y-1+COMPACT)));
 for (int h = (line+3)/4; h < 24; h++) {
  (wmove(body,(h*4-line+!COMPACT),(l)) == (-1) ? (-1) : wadd_wch((body),((&_nc_wacs[(unsigned char)(('T'))]))));
  (wmove(body,(h*4-line+!COMPACT),(r)) == (-1) ? (-1) : wadd_wch((body),((&_nc_wacs[(unsigned char)(('U'))]))));
 }
 if (!COMPACT)
  (wmove((body),(0),(l)) == (-1) ? (-1) : whline((body),((acs_map[(unsigned char)(('0'))])),(r-l+1)));
}

canonical_original_code:
void week_draw()
{
 int x = 6;
 int y = 3 - COMPACT;
 float hstep = (float)(COLS-x)/7.0;
 int ex; int ey; int ew; int eh;
 struct event_t *event; struct event_t *ee;
 int year = SEL.year;
 enum month_t month = SEL.month;
 int day = SEL.day;
 int shift = day_of_week(year, month, day);
 add_days(&year, &month, &day, -shift);
 cal_load(year, month, day, 7);
 int l = ((int)(((shift+0)*hstep)+0.5));
 int r = ((int)(((shift+1)*hstep)+0.5));
 int rev = COMPACT ? ((chtype)((1U)) << ((10) + 8)) | ((chtype)((1U)) << ((13) + 8)) : 0;
 wattr_on(win, (attr_t)(rev), ((void *)0));
 mvwprintw(win, 0, 0, "%-*s", COLS, month_to_str(SEL.month));
 mvwprintw(win, 1, 0, "%-0*d", COLS, SEL.year);
 wattr_off(win, (attr_t)(rev), ((void *)0));
 (wmove((win),(0),(x+l)) == (-1) ? (-1) : whline((win),(' '),(r-l-1)));
 (wmove((win),(1),(x+l)) == (-1) ? (-1) : whline((win),(' '),(r-l-1)));
 wattr_on(win, (attr_t)(rev), ((void *)0));
 for (int d = 0; d < 7; d++) {
  char *str = hstep >= 10 ? day_to_string(d) : day_to_str(d);
  if (d == shift) wattrset(win, ((chtype)((1U)) << ((13) + 8)));
  mvwprintw(win, 0, x+((int)((d*hstep)+0.5)), "%s", str);
  mvwprintw(win, 1, x+((int)((d*hstep)+0.5)), "%02d/%02d", month+1, day+1);
  if (d == shift) wattrset(win, rev);
  add_days(&year, &month, &day, 1);
 }
 wattr_off(win, (attr_t)(rev), ((void *)0));
 int allday = 0;
 event = EVENTS;
 add_days(&year, &month, &day, -7);
 for (int d = 0; d < 7; d++) {
  int n = 0;
  while (event && before(&event->start, year, month, day, 24, 0)) {
   if (!before(&event->end, year, month, day, 0, 1) &&
       get_mins(&event->start, &event->end) > 23*60) {
    int s = ((int)((d*hstep)+0.5));
    int w = ((int)(((d+1)*hstep)+0.5)) - 1 - s;
    event_line(win, event, y+n++, x+s, w, 0x2);
   }
   event = event->next;
   if (n > allday)
    allday = n;
  }
  add_days(&year,&month,&day,1);
 }
 if (allday && !COMPACT)
  allday++;
 wshrink(times, y+allday-!COMPACT);
 wshrink(body, y+allday-!COMPACT);
 mvwprintw(times, !COMPACT, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
 for (int h = 0; h < 24; h++)
  mvwprintw(times, !COMPACT+h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
 if (!EVENT)
  EVENT = find_event(&SEL);
 ee = ((void *)0);
 event = EVENTS;
 add_days(&year, &month, &day, -7);
 struct event_t *active[5] = {};
 int ncols = 0;
 for (int d = 0; d < 7; d++, add_days(&year,&month,&day,1))
 for (int h = 0; h < 24; h++)
 for (int m = 0; m < 60; m+=15)
 while (event && before(&event->start,
   year, month, day, h+(m+15)/60, (m+15)%60)) {
  if (!before(&event->start, year, month, day, h, m) &&
      get_mins(&event->start, &event->end) <= 23*60) {
   int col = get_col(active, (sizeof(active)/sizeof((active)[0])), event, &ncols);
   int y = h*4 + m/15 - line + !COMPACT;
   int x = ((int)((d*hstep)+0.5)) + 1 + (col*3);
   int h = (get_mins(&event->start, &event->end)-1)/15+1;
   int w = ((int)(((d+1)*hstep)+0.5)) - x - ((ncols-1)-col)*3;
   if (event == EVENT) {
    ee = event; ex = x; ey = y; ew = w; eh = h;
   } else
    event_box(body, event, y, x, h, w);
  }
  event = event->next;
 }
 if (ee)
  event_box(body, ee, ey, ex, eh, ew);
 if (!COMPACT)
  (wmove((win),(y-1),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 if (!COMPACT && allday)
  (wmove((win),(y-1+allday),(0)) == (-1) ? (-1) : whline((win),((acs_map[(unsigned char)(('q'))])),(COLS)));
 for (int d = 0; d < 7; d++)
  (wmove((body),(!COMPACT),(((int)((d*hstep)+0.5)))) == (-1) ? (-1) : wvline((body),((acs_map[(unsigned char)(('x'))])),(LINES-y-2+COMPACT-allday)));
 (wmove(body,(0),(l)) == (-1) ? (-1) : wvline_set((body),((&_nc_wacs[(unsigned char)(('X'))])),(LINES-y-1+COMPACT)));
 (wmove(body,(0),(r)) == (-1) ? (-1) : wvline_set((body),((&_nc_wacs[(unsigned char)(('X'))])),(LINES-y-1+COMPACT)));
 for (int h = (line+3)/4; h < 24; h++) {
  (wmove(body,(h*4-line+!COMPACT),(l)) == (-1) ? (-1) : wadd_wch((body),((&_nc_wacs[(unsigned char)(('T'))]))));
  (wmove(body,(h*4-line+!COMPACT),(r)) == (-1) ? (-1) : wadd_wch((body),((&_nc_wacs[(unsigned char)(('U'))]))));
 }
 if (!COMPACT)
  (wmove((body),(0),(l)) == (-1) ? (-1) : whline((body),((acs_map[(unsigned char)(('0'))])),(r-l+1)));
}

variable_types: x int

variable_types: hstep float

variable_types: ex int

variable_types: ey int

variable_types: ew int

variable_types: eh int

variable_types: year int

variable_types: day int

variable_types: shift int

variable_types: l int

variable_types: r int

variable_types: rev int

variable_types: d int

variable_types:
str
char *

variable_types: allday int

variable_types: n int

variable_types: s int

variable_types: w 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; } *[5]

variable_types: ncols int


decompiled_code:
__int64 __fastcall week_run(int a1)
{
int v1; // eax
int v2; // eax
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // eax
int v2; // eax
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rsi

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

original_code:
int week_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);
 week_draw();
 wrefresh(win);
 return 1;
}

canonical_original_code:
int week_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);
 week_draw();
 wrefresh(win);
 return 1;
}

variable_types: key int

variable_types:
btn
unsigned int

variable_types: row int

variable_types: col int

variable_types: days int

variable_types: events int

variable_types: lines int


decompiled_code:
void events_size()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

variable_types: rows int

variable_types: cols int


original_code:
void events_draw(void)
{
 int days = 2*7;
 int min = 12;
 date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
 date_t cur = {SEL.year, SEL.month, SEL.day-1, 0, 0};
 date_t end = {SEL.year, SEL.month, SEL.day, 24, 0};
 add_days(&end.year, &end.month, &end.day, days);
 cal_load(SEL.year, SEL.month, SEL.day, days);
 int row = 0;
 int count = 0;
 event_t *event = EVENTS;
 while (event && (count < min || compare(&event->start, &end) < 0)) {
  if (compare(&start, &event->start) <= 0) {
   date_t next = event->start;
   int newdate = cur.year != next.year ||
                 cur.month != next.month ||
                 cur.day != next.day ;
   int newtime = cur.hour != next.hour ||
                 cur.min != next.min ;
   if (EVENT == ((void *)0) || compare(&EVENT->start, &start) < 0)
    EVENT = event;
   if ((newdate || newtime) && row != 0)
    row++;
   if (newdate && row != 0)
    row++;
   if (newdate) {
    wday_t wday = day_of_week(next.year, next.month, next.day);
    wattr_on(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
    mvwprintw(win, row-line, 0, "%04d-%02d-%02d",
     next.year, next.month+1, next.day+1);
    mvwprintw(win, row-line, 13, "%s, %s %d",
     day_to_string(wday), month_to_string(next.month), next.day+1);
    wattr_off(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
    row++;
   }
   event_line(win, event, row++-line, 4, COLS-4,
     0x1 | 0x2);
   if (event->name && event->desc) {
    int n = ((COLS-14) < (strcspn(event->desc, "\n")) ? (COLS-14) : (strcspn(event->desc, "\n")));
    mvwprintw(win, row++-line, 14, "%.*s", n, event->desc);
   }
   cur = next;
   count += 1;
  }
  event = event->next;
 }
 rows = row;
}

canonical_original_code:
void events_draw()
{
 int days = 2*7;
 int min = 12;
 struct date_t start = {SEL.year, SEL.month, SEL.day, 0, 0};
 struct date_t cur = {SEL.year, SEL.month, SEL.day-1, 0, 0};
 struct date_t end = {SEL.year, SEL.month, SEL.day, 24, 0};
 add_days(&end.year, &end.month, &end.day, days);
 cal_load(SEL.year, SEL.month, SEL.day, days);
 int row = 0;
 int count = 0;
 struct event_t *event = EVENTS;
 while (event && (count < min || compare(&event->start, &end) < 0)) {
  if (compare(&start, &event->start) <= 0) {
   struct date_t next = event->start;
   int newdate = cur.year != next.year ||
                 cur.month != next.month ||
                 cur.day != next.day;
   int newtime = cur.hour != next.hour ||
                 cur.min != next.min;
   if (EVENT == ((void *)0) || compare(&EVENT->start, &start) < 0)
    EVENT = event;
   if ((newdate || newtime) && row != 0)
    row++;
   if (newdate && row != 0)
    row++;
   if (newdate) {
    enum wday_t wday = day_of_week(next.year, next.month, next.day);
    wattr_on(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
    mvwprintw(win, row-line, 0, "%04d-%02d-%02d",
     next.year, next.month+1, next.day+1);
    mvwprintw(win, row-line, 13, "%s, %s %d",
     day_to_string(wday), month_to_string(next.month), next.day+1);
    wattr_off(win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
    row++;
   }
   event_line(win, event, row++-line, 4, COLS-4,
     0x1 | 0x2);
   if (event->name && event->desc) {
    int n = ((COLS-14) < (strcspn(event->desc, "\n")) ? (COLS-14) : (strcspn(event->desc, "\n")));
    mvwprintw(win, row++-line, 14, "%.*s", n, event->desc);
   }
   cur = next;
   count += 1;
  }
  event = event->next;
 }
 rows = row;
}

variable_types: min int

variable_types: count 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; } *

variable_types: newdate int

variable_types: newtime int

variable_types: enum wday_t { SUN=0, MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6 }


decompiled_code:
__int64 __fastcall events_run(int a1)
{
int v1; // edx
int v2; // eax
__int64 result; // rax
int v4; // edx
int v5; // eax
__int64 v6; // rax
int v7; // eax
int v8; // edx
bool v9; // sf
int v10; // eax
bool v11; // sf
int v12; // edx
int v13; // edx
int v14; // ecx
int v15; // edx

if ( a1 > 117 )
goto LABEL_4;
if ( a1 > 67 )
{
switch ( a1 )
{
case 'D':
result = (unsigned int)LINES;
v11 = line + LINES < 0;
v12 = line + LINES;
goto LABEL_36;
case 'G':
result = (unsigned int)rows;
v13 = line + rows;
if ( line + rows < 0 )
v13 = 0;
if ( v13 > rows - 1 )
v13 = rows - 1;
line = v13;
goto LABEL_41;
case 'U':
v14 = LINES;
goto LABEL_49;
case 'd':
result = (unsigned int)(LINES / 2);
v11 = line + LINES / 2 < 0;
v12 = line + LINES / 2;
goto LABEL_36;
case 'g':
v15 = rows - 1;
result = (unsigned int)-line;
if ( rows - 1 > 0 )
v15 = 0;
line = v15;
goto LABEL_41;
case 'j':
v7 = rows - 1;
v8 = 0;
if ( line >= 0 )
v8 = line;
if ( v7 > v8 )
v7 = v8;
line = v7;
if ( !EVENT )
goto LABEL_17;
v6 = *(_QWORD *)(EVENT + 88LL);
if ( !v6 )
goto LABEL_17;
goto LABEL_16;
case 'k':
v4 = 0;
v5 = rows - 1;
if ( line >= 0 )
v4 = line;
if ( v5 > v4 )
v5 = v4;
line = v5;
if ( !EVENT )
goto LABEL_17;
v6 = *(_QWORD *)(EVENT + 96LL);
if ( !v6 )
goto LABEL_17;
LABEL_16:
EVENT = v6;
goto LABEL_17;
case 'u':
v14 = LINES / 2;
LABEL_49:
result = (unsigned int)-v14;
v11 = line - v14 < 0;
v12 = line - v14;
LABEL_36:
if ( v11 )
v12 = 0;
if ( v12 > rows - 1 )
v12 = rows - 1;
line = v12;
LABEL_41:
if ( (_DWORD)result )
goto LABEL_17;
return result;
default:
goto LABEL_4;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
return 1LL;
}
if ( a1 != 25 )
{
if ( a1 == 5 )
{
v9 = line + 1 < 0;
v10 = line + 1;
goto LABEL_28;
}
LABEL_4:
v1 = 0;
v2 = rows - 1;
if ( line >= 0 )
v1 = line;
if ( v2 > v1 )
v2 = v1;
line = v2;
return 0LL;
}
v9 = line - 1 < 0;
v10 = line - 1;
LABEL_28:
if ( v9 )
v10 = 0;
if ( v10 > rows - 1 )
v10 = rows - 1;
line = v10;
LABEL_17:
werase(win);
events_draw();
wrefresh(win);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // edx
int v2; // eax
__int64 result; // rax
int v4; // edx
int v5; // eax
__int64 v6; // rax
int v7; // eax
int v8; // edx
bool v9; // sf
int v10; // eax
bool v11; // sf
int v12; // edx
int v13; // edx
int v14; // ecx
int v15; // edx

if ( a1 > 117 )
goto LABEL_4;
if ( a1 > 67 )
{
switch ( a1 )
{
case 'D':
result = (unsigned int)LINES;
v11 = line + LINES < 0;
v12 = line + LINES;
goto LABEL_36;
case 'G':
result = (unsigned int)rows;
v13 = line + rows;
if ( line + rows < 0 )
v13 = 0;
if ( v13 > rows - 1 )
v13 = rows - 1;
line = v13;
goto LABEL_41;
case 'U':
v14 = LINES;
goto LABEL_49;
case 'd':
result = (unsigned int)(LINES / 2);
v11 = line + LINES / 2 < 0;
v12 = line + LINES / 2;
goto LABEL_36;
case 'g':
v15 = rows - 1;
result = (unsigned int)-line;
if ( rows - 1 > 0 )
v15 = 0;
line = v15;
goto LABEL_41;
case 'j':
v7 = rows - 1;
v8 = 0;
if ( line >= 0 )
v8 = line;
if ( v7 > v8 )
v7 = v8;
line = v7;
if ( !EVENT )
goto LABEL_17;
v6 = *(_QWORD *)(EVENT + 88LL);
if ( !v6 )
goto LABEL_17;
goto LABEL_16;
case 'k':
v4 = 0;
v5 = rows - 1;
if ( line >= 0 )
v4 = line;
if ( v5 > v4 )
v5 = v4;
line = v5;
if ( !EVENT )
goto LABEL_17;
v6 = *(_QWORD *)(EVENT + 96LL);
if ( !v6 )
goto LABEL_17;
LABEL_16:
EVENT = v6;
goto LABEL_17;
case 'u':
v14 = LINES / 2;
LABEL_49:
result = (unsigned int)-v14;
v11 = line - v14 < 0;
v12 = line - v14;
LABEL_36:
if ( v11 )
v12 = 0;
if ( v12 > rows - 1 )
v12 = rows - 1;
line = v12;
LABEL_41:
if ( (_DWORD)result )
goto LABEL_17;
return result;
default:
goto LABEL_4;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
return 1LL;
}
if ( a1 != 25 )
{
if ( a1 == 5 )
{
v9 = line + 1 < 0;
v10 = line + 1;
goto LABEL_28;
}
LABEL_4:
v1 = 0;
v2 = rows - 1;
if ( line >= 0 )
v1 = line;
if ( v2 > v1 )
v2 = v1;
line = v2;
return 0LL;
}
v9 = line - 1 < 0;
v10 = line - 1;
LABEL_28:
if ( v9 )
v10 = 0;
if ( v10 > rows - 1 )
v10 = rows - 1;
line = v10;
LABEL_17:
werase(win);
func2();
wrefresh(win);
return 1LL;
}

original_code:
int events_run(int key, mmask_t btn, int row, int col)
{
 int scroll = 0, move = 0;
 switch (key)
 {
  case 'g': scroll = -line; break;
  case 'G': scroll = rows; break;
  case '\005': scroll = 1; break;
  case '\031': scroll = -1; break;
  case 'd': scroll = LINES/2; break;
  case 'u': scroll = -LINES/2; break;
  case 'D': scroll = LINES; break;
  case 'U': scroll = -LINES; break;
  case 'j': move = 1; break;
  case 'k': move = -1; break;
  case '\012':
   view_edit(EDIT_EVENT);
   return 1;
 }
 line = ((((line+scroll) > (0) ? (line+scroll) : (0))) < (rows-1) ? (((line+scroll) > (0) ? (line+scroll) : (0))) : (rows-1));
 for (int i=0; i<move && EVENT && EVENT->next; i++)
  EVENT = EVENT->next;
 for (int i=0; i>move && EVENT && EVENT->prev; i--)
  EVENT = EVENT->prev;
 if (scroll || move) {
  werase(win);
  events_draw();
  wrefresh(win);
 }
 return scroll || move;
}

canonical_original_code:
int events_run(int key, unsigned int btn, int row, int col)
{
 int scroll = 0; int move = 0;
 switch (key)
 {
  case 'g': scroll = -line; break;
  case 'G': scroll = rows; break;
  case '\005': scroll = 1; break;
  case '\031': scroll = -1; break;
  case 'd': scroll = LINES/2; break;
  case 'u': scroll = -LINES/2; break;
  case 'D': scroll = LINES; break;
  case 'U': scroll = -LINES; break;
  case 'j': move = 1; break;
  case 'k': move = -1; break;
  case '\012':
   view_edit(EDIT_EVENT);
   return 1;
 }
 line = ((((line+scroll) > (0) ? (line+scroll) : (0))) < (rows-1) ? (((line+scroll) > (0) ? (line+scroll) : (0))) : (rows-1));
 for (int i = 0; i<move && EVENT && EVENT->next; i++)
  EVENT = EVENT->next;
 for (int i = 0; i>move && EVENT && EVENT->prev; i--)
  EVENT = EVENT->prev;
 if (scroll || move) {
  werase(win);
  events_draw();
  wrefresh(win);
 }
 return scroll || move;
}

variable_types: scroll int

variable_types: move int

variable_types: i int


decompiled_code:
void month_size()
{
;
}

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

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


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

v0 = (const char *)month_to_string(SEL[1]);
v40 = start_of_month(SEL[0], SEL[1]);
v41 = days_in_month(SEL[0], SEL[1]);
v1 = weeks_in_month(SEL[0], SEL[1]);
v2 = COMPACT;
v3 = COLS;
v45 = v1;
v43 = (COMPACT == 0) + 3;
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 = 0LL;
*(float *)v7.m128i_i32 = v4 - v6 * 0.5;
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(v7));
v36 = (float)(v3 - 1) / 7.0;
v34 = (float)(v2 - v43 + LINES - 2) / (float)v45;
cal_load(SEL[0], SEL[1], 0LL, (unsigned int)v41);
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);
}
}
v9 = (int)v8;
v10 = 0;
mvwprintw(win, 0, v9, "%s %d", v0, SEL[0]);
do
{
if ( v36 >= 10.0 )
v11 = (const char *)day_to_string(v10);
else
v11 = (const char *)day_to_str(v10);
v12 = (float)(int)v10++ * v36;
mvwprintw(win, 1, (int)((float)(v12 + 1.0) + 0.5), "%s", v11);
}
while ( v10 != 7 );
if ( !COMPACT || (wattr_off(win, 0x240000uLL, 0LL), !COMPACT) )
{
if ( wmove(win, 2, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( v41 <= 0 )
goto LABEL_71;
LABEL_13:
v13 = 0;
v39 = (float)v43;
while ( 1 )
{
if ( SEL[2] == v13 )
wattr_on(win, 0x200000uLL, 0LL);
v14 = v13 + 1;
mvwprintw(
win,
(int)((float)((float)((float)((v13 + v40) / 7) * v34) + v39) + 0.5),
(int)((float)((float)((float)((v13 + v40) % 7) * v36) + 1.0) + 0.5),
"%d",
(unsigned int)(v13 + 1));
if ( SEL[2] == v13 )
{
wattr_off(win, 0x200000uLL, 0LL);
if ( v14 == v41 )
{
LABEL_20:
v15 = EVENTS;
v16 = 0;
while ( 1 )
{
v17 = (int)(v16 + v40) / 7;
v18 = (int)((float)((float)((float)v17 * v34) + v39) + 0.5);
v19 = (int)(v16 + v40) % 7;
v20 = (int)((float)((float)((float)(v17 + 1) * v34) + v39) + 0.5) - 2;
v21 = (int)((float)((float)((float)v19 * v36) + 1.0) + 0.5) + 3;
v37 = (int)((float)((float)((float)v19 * v36) + 1.0) + 0.5);
v35 = (int)((float)((float)((float)(v19 + 1) * v36) + 1.0) + 0.5) - v21 - 1;
if ( v15 )
break;
LABEL_32:
v15 = 0LL;
LABEL_33:
if ( v41 == ++v16 )
goto LABEL_34;
}
while ( 2 )
{
if ( !(unsigned int)before(v15 + 32, SEL[0], SEL[1], v16, 24LL, 0LL) )
goto LABEL_33;
if ( !(unsigned int)before(v15 + 32, SEL[0], SEL[1], v16, 0LL, 0LL) )
{
if ( v20 == v18 )
{
if ( wmove(win, v20, v37) != -1 )
whline(win, LODWORD(acs_map[23]), 2);
LABEL_31:
event_line(win, v15, (unsigned int)v18, v21, v35, 0LL);
}
else if ( v20 >= v18 )
{
goto LABEL_31;
}
++v18;
}
v15 = *(_QWORD *)(v15 + 88);
if ( !v15 )
goto LABEL_32;
continue;
}
}
}
else if ( v14 == v41 )
{
goto LABEL_20;
}
++v13;
}
}
if ( v41 > 0 )
goto LABEL_13;
LABEL_71:
v39 = (float)v43;
LABEL_34:
if ( v45 > 1 )
{
for ( i = 1; i != v45; ++i )
{
if ( wmove(win, (int)((float)((float)((float)i * v34) + (float)(v43 - 1)) + 0.5), 1) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS - 2);
}
}
v38 = 1;
v42 = (v40 + v41 - 1) % 7 + 1;
v44 = v43 - 1;
do
{
v23 = v40 > v38;
v24 = v45 - (v42 < v38);
if ( wmove(win, (int)((float)((float)((float)v23 * v34) + v39) + 0.5), (int)((float)((float)v38 * v36) + 0.5)) != -1 )
wvline(win, LODWORD(acs_map[60]), (int)(float)((float)(v24 - v23) * v34));
if ( v45 > 1 )
{
for ( j = 1; j != v45; ++j )
{
if ( v23 == j )
{
v26 = HIDWORD(acs_map[59]);
}
else if ( v24 == j )
{
v26 = acs_map[59];
}
else
{
v26 = acs_map[55];
}
if ( wmove(
win,
(int)((float)((float)((float)j * v34) + (float)v44) + 0.5),
(int)((float)((float)v38 * v36) + 0.5)) != -1 )
waddch(win, v26);
}
}
++v38;
}
while ( v38 != 7 );
v27 = day_of_week(SEL[0], SEL[1], SEL[2]);
v28 = SEL[2] + v40;
v29 = (int)((float)((float)v27 * v36) + 0.5);
v30 = (int)((float)((float)(v27 + 1) * v36) + 0.5);
v31 = (int)((float)((float)((float)((float)(v28 / 7) * v34) + v39) - 1.0) + 0.5);
v32 = (int)((float)((float)((float)((float)(v28 / 7 + 1) * v34) + v39) - 1.0) + 0.5);
if ( wmove(win, v31, v29) != -1 )
wvline_set(win, nc_wacs + 77, v32 - v31);
if ( wmove(win, v31, v30) != -1 )
wvline_set(win, nc_wacs + 77, v32 - v31);
if ( wmove(win, v31, v29) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v30 - v29);
if ( wmove(win, v32, v29) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v30 - v29);
if ( wmove(win, v31, v29) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2128));
if ( wmove(win, v31, v30) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2100));
if ( wmove(win, v32, v29) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2156));
result = wmove(win, v32, v30);
if ( result != -1 )
result = wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2072));
return result;
}

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

v0 = (const char *)month_to_string(SEL[1]);
v40 = start_of_month(SEL[0], SEL[1]);
v41 = days_in_month(SEL[0], SEL[1]);
v1 = weeks_in_month(SEL[0], SEL[1]);
v2 = COMPACT;
v3 = COLS;
v45 = v1;
v43 = (COMPACT == 0) + 3;
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 = 0LL;
*(float *)v7.m128i_i32 = v4 - v6 * 0.5;
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(v7));
v36 = (float)(v3 - 1) / 7.0;
v34 = (float)(v2 - v43 + LINES - 2) / (float)v45;
cal_load(SEL[0], SEL[1], 0LL, (unsigned int)v41);
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);
}
}
v9 = (int)v8;
v10 = 0;
mvwprintw(win, 0, v9, "%s %d", v0, SEL[0]);
do
{
if ( v36 >= 10.0 )
v11 = (const char *)day_to_string(v10);
else
v11 = (const char *)day_to_str(v10);
v12 = (float)(int)v10++ * v36;
mvwprintw(win, 1, (int)((float)(v12 + 1.0) + 0.5), "%s", v11);
}
while ( v10 != 7 );
if ( !COMPACT || (wattr_off(win, 0x240000uLL, 0LL), !COMPACT) )
{
if ( wmove(win, 2, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( v41 <= 0 )
goto LABEL_71;
LABEL_13:
v13 = 0;
v39 = (float)v43;
while ( 1 )
{
if ( SEL[2] == v13 )
wattr_on(win, 0x200000uLL, 0LL);
v14 = v13 + 1;
mvwprintw(
win,
(int)((float)((float)((float)((v13 + v40) / 7) * v34) + v39) + 0.5),
(int)((float)((float)((float)((v13 + v40) % 7) * v36) + 1.0) + 0.5),
"%d",
(unsigned int)(v13 + 1));
if ( SEL[2] == v13 )
{
wattr_off(win, 0x200000uLL, 0LL);
if ( v14 == v41 )
{
LABEL_20:
v15 = EVENTS;
v16 = 0;
while ( 1 )
{
v17 = (int)(v16 + v40) / 7;
v18 = (int)((float)((float)((float)v17 * v34) + v39) + 0.5);
v19 = (int)(v16 + v40) % 7;
v20 = (int)((float)((float)((float)(v17 + 1) * v34) + v39) + 0.5) - 2;
v21 = (int)((float)((float)((float)v19 * v36) + 1.0) + 0.5) + 3;
v37 = (int)((float)((float)((float)v19 * v36) + 1.0) + 0.5);
v35 = (int)((float)((float)((float)(v19 + 1) * v36) + 1.0) + 0.5) - v21 - 1;
if ( v15 )
break;
LABEL_32:
v15 = 0LL;
LABEL_33:
if ( v41 == ++v16 )
goto LABEL_34;
}
while ( 2 )
{
if ( !(unsigned int)before(v15 + 32, SEL[0], SEL[1], v16, 24LL, 0LL) )
goto LABEL_33;
if ( !(unsigned int)before(v15 + 32, SEL[0], SEL[1], v16, 0LL, 0LL) )
{
if ( v20 == v18 )
{
if ( wmove(win, v20, v37) != -1 )
whline(win, LODWORD(acs_map[23]), 2);
LABEL_31:
event_line(win, v15, (unsigned int)v18, v21, v35, 0LL);
}
else if ( v20 >= v18 )
{
goto LABEL_31;
}
++v18;
}
v15 = *(_QWORD *)(v15 + 88);
if ( !v15 )
goto LABEL_32;
continue;
}
}
}
else if ( v14 == v41 )
{
goto LABEL_20;
}
++v13;
}
}
if ( v41 > 0 )
goto LABEL_13;
LABEL_71:
v39 = (float)v43;
LABEL_34:
if ( v45 > 1 )
{
for ( i = 1; i != v45; ++i )
{
if ( wmove(win, (int)((float)((float)((float)i * v34) + (float)(v43 - 1)) + 0.5), 1) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS - 2);
}
}
v38 = 1;
v42 = (v40 + v41 - 1) % 7 + 1;
v44 = v43 - 1;
do
{
v23 = v40 > v38;
v24 = v45 - (v42 < v38);
if ( wmove(win, (int)((float)((float)((float)v23 * v34) + v39) + 0.5), (int)((float)((float)v38 * v36) + 0.5)) != -1 )
wvline(win, LODWORD(acs_map[60]), (int)(float)((float)(v24 - v23) * v34));
if ( v45 > 1 )
{
for ( j = 1; j != v45; ++j )
{
if ( v23 == j )
{
v26 = HIDWORD(acs_map[59]);
}
else if ( v24 == j )
{
v26 = acs_map[59];
}
else
{
v26 = acs_map[55];
}
if ( wmove(
win,
(int)((float)((float)((float)j * v34) + (float)v44) + 0.5),
(int)((float)((float)v38 * v36) + 0.5)) != -1 )
waddch(win, v26);
}
}
++v38;
}
while ( v38 != 7 );
v27 = day_of_week(SEL[0], SEL[1], SEL[2]);
v28 = SEL[2] + v40;
v29 = (int)((float)((float)v27 * v36) + 0.5);
v30 = (int)((float)((float)(v27 + 1) * v36) + 0.5);
v31 = (int)((float)((float)((float)((float)(v28 / 7) * v34) + v39) - 1.0) + 0.5);
v32 = (int)((float)((float)((float)((float)(v28 / 7 + 1) * v34) + v39) - 1.0) + 0.5);
if ( wmove(win, v31, v29) != -1 )
wvline_set(win, nc_wacs + 77, v32 - v31);
if ( wmove(win, v31, v30) != -1 )
wvline_set(win, nc_wacs + 77, v32 - v31);
if ( wmove(win, v31, v29) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v30 - v29);
if ( wmove(win, v32, v29) != -1 )
whline_set(win, (cchar_t *)((char *)nc_wacs + 2268), v30 - v29);
if ( wmove(win, v31, v29) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2128));
if ( wmove(win, v31, v30) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2100));
if ( wmove(win, v32, v29) != -1 )
wadd_wch(win, (cchar_t *)((char *)nc_wacs + 2156));
result = wmove(win, v32, v30);
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:
__int64 __fastcall month_run(int a1)
{
__int64 v1; // rdi
__int64 result; // rax
int v3; // ecx
unsigned int v4; // er12

v1 = (unsigned int)(a1 - 104);
result = 0LL;
if ( (unsigned int)v1 <= 7 )
{
v3 = CSWTCH_89[v1];
v4 = CSWTCH_90[v1];
result = v4 | v3;
if ( v4 | v3 )
{
add_days(SEL, (unsigned int)((_DWORD)SEL + 4), (unsigned int)((_DWORD)SEL + 8));
add_months(SEL, (unsigned int)((_DWORD)SEL + 4), v4);
werase(win);
month_draw();
wrefresh(win);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
__int64 v1; // rdi
__int64 result; // rax
int v3; // ecx
unsigned int v4; // er12

v1 = (unsigned int)(a1 - 104);
result = 0LL;
if ( (unsigned int)v1 <= 7 )
{
v3 = CSWTCH_89[v1];
v4 = CSWTCH_90[v1];
result = v4 | v3;
if ( v4 | v3 )
{
add_days(SEL, (unsigned int)((_DWORD)SEL + 4), (unsigned int)((_DWORD)SEL + 8));
add_months(SEL, (unsigned int)((_DWORD)SEL + 4), v4);
werase(win);
func2();
wrefresh(win);
result = 1LL;
}
}
return result;
}

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


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

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

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

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

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


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

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

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

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

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


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 *


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

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

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 *