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

v0 = ical_cals();
v1 = dummy_cals();
CALS = merge_cals(v1, v0);
return cal_load(SEL[0], SEL[1], SEL[2]);
}

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

v0 = ical_cals();
v1 = dummy_cals();
CALS = func2(v1, v0);
return func5(SEL[0], SEL[1], SEL[2]);
}

original_code:
void cal_init(void)
{
 CALS = merge_cals(
  dummy_cals(),
   ical_cals());
 cal_load(SEL.year, SEL.month, SEL.day, 1);
}

canonical_original_code:
void cal_init()
{
 CALS = merge_cals(
  dummy_cals(),
   ical_cals());
 cal_load(SEL.year, SEL.month, SEL.day, 1);
}


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

if ( (unsigned int)match(a1, "dummy") )
return dummy_config(a1, a2, a3, a4);
result = match(a1, "ical");
if ( (_DWORD)result )
result = ical_config(a1, a2, a3, a4);
return result;
}

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

if ( (unsigned int)match(a1, "dummy") )
return dummy_config(a1, a2, a3, a4);
result = match(a1, "ical");
if ( (_DWORD)result )
result = ical_config(a1, a2, a3, a4);
return result;
}

original_code:
void cal_config(const char *group, const char *name, const char *key, const char *value)
{
 if (match(group, "dummy"))
  dummy_config(group, name, key, value);
 else if (match(group, "ical"))
  ical_config(group, name, key, value);
}

canonical_original_code:
void cal_config(char *group, char *name, char *key, char *value)
{
 if (match(group, "dummy"))
  dummy_config(group, name, key, value);
 else if (match(group, "ical"))
  ical_config(group, name, key, value);
}

variable_types:
group
char *

variable_types:
name
char *

variable_types:
key
char *

variable_types:
value
char *

return_type: void


original_code:
event_t *find_event(date_t *target)
{
 int min = 0;
 event_t *event = ((void *)0);
 if (EVENT && compare(&EVENT->start, target) == 0)
  return EVENT;
 for (event_t *cur = EVENTS; cur; cur = cur->next) {
  if ((target->year != cur->start.year) ||
      (target->month != cur->start.month) ||
      (target->day != cur->start.day))
       continue;
  int diff = (target->hour - cur->start.hour) * 60 * 24 +
      (target->min - cur->start.min) * 60 +
      (target->sec - cur->start.sec);
  if (event == ((void *)0) || ((diff) > 0 ? (diff) : -(diff)) < min) {
   min = ((diff) > 0 ? (diff) : -(diff));
   event = cur;
  }
 }
 return event;
}

canonical_original_code:
struct event_t *find_event(struct date_t *target)
{
 int min = 0;
 struct event_t *event = ((void *)0);
 if (EVENT && compare(&EVENT->start, target) == 0)
  return EVENT;
 for (struct event_t *cur = EVENTS; cur; cur = cur->next) {
  if ((target->year != cur->start.year) ||
      (target->month != cur->start.month) ||
      (target->day != cur->start.day))
       continue;
  int diff = (target->hour - cur->start.hour) * 60 * 24 +
      (target->min - cur->start.min) * 60 +
      (target->sec - cur->start.sec);
  if (event == ((void *)0) || ((diff) > 0 ? (diff) : -(diff)) < min) {
   min = ((diff) > 0 ? (diff) : -(diff));
   event = cur;
  }
 }
 return event;
}

variable_types:
target
struct date_t *

variable_types: min 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: diff int

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

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


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

result = match(a1, "dummy");
if ( (_DWORD)result )
{
result = match(a3, "enable");
if ( (_DWORD)result )
{
result = get_bool(a4);
enable = result;
}
}
return result;
}

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

result = match(a1, "dummy");
if ( (_DWORD)result )
{
result = match(a3, "enable");
if ( (_DWORD)result )
{
result = get_bool(a4);
enable = result;
}
}
return result;
}

original_code:
void dummy_config(const char *group, const char *name, const char *key, const char *value)
{
 if (match(group, "dummy") && match(key, "enable"))
  enable = get_bool(value);
}

canonical_original_code:
void dummy_config(char *group, char *name, char *key, char *value)
{
 if (match(group, "dummy") && match(key, "enable"))
  enable = get_bool(value);
}


decompiled_code:
char **dummy_cals()
{
return cal;
}

canonical_decompiled_code:
char **func1()
{
return cal;
}

original_code:
cal_t *dummy_cals(void)
{
 return &cal;
}

canonical_original_code:
struct cal_t *dummy_cals()
{
 return &cal;
}

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


original_code:
event_t *dummy_events(date_t start, date_t end)
{
 event_t *last = &event;
 for (int i = 0; i < 8; i++) {
  last->next = alloc0(sizeof(event_t));
  last->next->cal = event.cal;
  last->next->start = event.start;
  last->next->end = event.end;
  last->next->name = strcopy(event.name);
  last->next->desc = strcopy(event.desc);
  date_t *s = &last->next->start;
  date_t *e = &last->next->end;
  add_days(&s->year, &s->month, &s->day, 7*i);
  add_days(&e->year, &e->month, &e->day, 7*i);
  last = last->next;
  last->next = ((void *)0);
 }
 return enable ? event.next : 0;
}

canonical_original_code:
struct event_t *dummy_events(struct date_t start, struct date_t end)
{
 struct event_t *last = &event;
 for (int i = 0; i < 8; i++) {
  last->next = alloc0(sizeof(event_t));
  last->next->cal = event.cal;
  last->next->start = event.start;
  last->next->end = event.end;
  last->next->name = strcopy(event.name);
  last->next->desc = strcopy(event.desc);
  struct date_t *s = &last->next->start;
  struct date_t *e = &last->next->end;
  add_days(&s->year, &s->month, &s->day, 7*i);
  add_days(&e->year, &e->month, &e->day, 7*i);
  last = last->next;
  last->next = ((void *)0);
 }
 return enable ? event.next : 0;
}

variable_types:
start
struct date_t

variable_types:
end
struct date_t

variable_types: i int

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

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


original_code:
todo_t *dummy_todos(date_t start, date_t end)
{
 todo_t *last = &todo;
 for (int i = 0; i < 6; i++) {
  last->next = alloc0(sizeof(event_t));
  last->next->cal = todo.cal;
  last->next->name = strcopy(todo.name);
  last->next->desc = strcopy(todo.desc);
  last->next->due = todo.due;
  last->next->status = todo.status;
  last = last->next;
  last->next = ((void *)0);
 }
 return enable ? todo.next : 0;
}

canonical_original_code:
struct todo_t *dummy_todos(struct date_t start, struct date_t end)
{
 struct todo_t *last = &todo;
 for (int i = 0; i < 6; i++) {
  last->next = alloc0(sizeof(event_t));
  last->next->cal = todo.cal;
  last->next->name = strcopy(todo.name);
  last->next->desc = strcopy(todo.desc);
  last->next->due = todo.due;
  last->next->status = todo.status;
  last = last->next;
  last->next = ((void *)0);
 }
 return enable ? todo.next : 0;
}

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:
void help_size()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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

variable_types: rows int

variable_types: cols int


decompiled_code:
int help_draw()
{
return mvwprintw(win, 0, 1, "%s\n", "help");
}

canonical_decompiled_code:
int func2()
{
return mvwprintw(win, 0, 1, "%s\n", "help");
}

original_code:
void help_draw(void)
{
 mvwprintw(win, 0, 1, "%s\n", "help");
}

canonical_original_code:
void help_draw()
{
 mvwprintw(win, 0, 1, "%s\n", "help");
}


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

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

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

canonical_original_code:
int help_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 __fastcall on_config(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
view_config();
return cal_config(a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
view_config();
return cal_config(a1, a2, a3, a4);
}

original_code:
static void on_config(const char *group, const char *name, const char *key, const char *value)
{
 view_config(group, name, key, value);
 cal_config(group, name, key, value);
}

canonical_original_code:
static void on_config(char *group, char *name, char *key, char *value)
{
 view_config(group, name, key, value);
 cal_config(group, name, key, value);
}

variable_types:
group
char *

variable_types:
name
char *

variable_types:
key
char *


decompiled_code:
void __noreturn on_sigint()
{
endwin();
exit(0);
}

canonical_decompiled_code:
void __noreturn func1()
{
endwin();
exit(0);
}

original_code:
static void on_sigint(int signum)
{
 endwin();
 exit(0);
}

variable_types: signum int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // eax
MEVENT v6; // [rsp+0h] [rbp-38h] BYREF

signal(2, (__sighandler_t)on_sigint);
if ( !getenv("ESCDELAY") )
putenv("ESCDELAY=25");
setlocale(6, &locale);
initscr();
cbreak();
noecho();
keypad(stdscr, 1);
start_color();
curs_set(0);
wtimeout(stdscr, 100);
use_default_colors();
mousemask(0xFFFFFFFuLL, 0LL);
init_pair(1, 2, -1);
init_pair(2, 1, -1);
init_pair(3, 1, -1);
init_pair(4, 3, -1);
init_pair(5, 2, -1);
init_pair(6, 4, -1);
init_pair(7, 2, -1);
init_pair(8, 5, -1);
init_pair(9, 1, -1);
conf_setup((unsigned int)argc, argv, ".lackeyrc", on_config);
util_init();
conf_init();
date_init();
cal_init();
view_init();
date_sync();
view_draw();
while ( 1 )
{
conf_sync();
v3 = wgetch(stdscr);
date_sync();
if ( v3 == 113 )
break;
switch ( v3 )
{
case 0x199u:
if ( !getmouse(&v6) )
{
LABEL_14:
v4 = view_run(v3, LODWORD(v6.bstate), (unsigned int)v6.y, (unsigned int)v6.x);
if ( v3 != -1 && !v4 )
debug("main: Unhandled key - Dec %3d, Hex %02x, Oct %03o, Chr <%c>", v3, v3, v3, v3);
}
break;
case 0xCu:
wclear(stdscr);
goto LABEL_8;
case 0x19Au:
endwin();
wrefresh(stdscr);
view_resize();
view_draw();
break;
case 7u:
LABEL_8:
view_resize();
view_draw();
break;
default:
goto LABEL_14;
}
}
endwin();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 signal(2, on_sigint);
 if (!getenv("ESCDELAY"))
  putenv("ESCDELAY=25");
 setlocale(6, "");
 initscr();
 cbreak();
 noecho();
 keypad(stdscr, 1);
 start_color();
 curs_set(0);
 wtimeout(stdscr,(100));
 use_default_colors();
 mousemask((((0010L) << (((6) - 1) * 5)) - 1), ((void *)0));
 init_pair(1, 2, -1);
 init_pair(2, 1, -1);
 init_pair(3, 1, -1);
 init_pair(4, 3, -1);
 init_pair(5, 2, -1);
 init_pair(6, 4, -1);
 init_pair(7, 2, -1);
 init_pair(8, 5, -1);
 init_pair(9, 1, -1);
 conf_setup(argc, argv, ".lackeyrc", on_config);
 util_init();
 conf_init();
 date_init();
 cal_init();
 view_init();
 date_sync();
 view_draw();
 while (1) {
  MEVENT btn;
  conf_sync();
  int chr = wgetch(stdscr);
  date_sync();
  if (chr == 'q')
   break;
  if (chr == 0631)
   if (getmouse(&btn) != (0))
    continue;
  switch (chr) {
   case 0632:
    endwin();
    wrefresh(stdscr);
    view_resize();
    view_draw();
    continue;
   case '\14':
    wclear(stdscr);
   case '\7':
    view_resize();
    view_draw();
    continue;
  }
  if (view_run(chr, btn.bstate, btn.y, btn.x))
   continue;
  if (chr == (-1))
   continue;
  debug("main: Unhandled key - Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>",
    chr, chr, chr, chr);
 }
 endwin();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 signal(2, on_sigint);
 if (!getenv("ESCDELAY"))
  putenv("ESCDELAY=25");
 setlocale(6, "");
 initscr();
 cbreak();
 noecho();
 keypad(stdscr, 1);
 start_color();
 curs_set(0);
 wtimeout(stdscr,(100));
 use_default_colors();
 mousemask((((0010L) << (((6) - 1) * 5)) - 1), ((void *)0));
 init_pair(1, 2, -1);
 init_pair(2, 1, -1);
 init_pair(3, 1, -1);
 init_pair(4, 3, -1);
 init_pair(5, 2, -1);
 init_pair(6, 4, -1);
 init_pair(7, 2, -1);
 init_pair(8, 5, -1);
 init_pair(9, 1, -1);
 conf_setup(argc, argv, ".lackeyrc", on_config);
 util_init();
 conf_init();
 date_init();
 cal_init();
 view_init();
 date_sync();
 view_draw();
 while (1) {
  struct MEVENT btn;
  conf_sync();
  int chr = wgetch(stdscr);
  date_sync();
  if (chr == 'q')
   break;
  if (chr == 0631)
   if (getmouse(&btn) != (0))
    continue;
  switch (chr) {
   case 0632:
    endwin();
    wrefresh(stdscr);
    view_resize();
    view_draw();
    continue;
   case '\14':
    wclear(stdscr);
   case '\7':
    view_resize();
    view_draw();
    continue;
  }
  if (view_run(chr, btn.bstate, btn.y, btn.x))
   continue;
  if (chr == (-1))
   continue;
  debug("main: Unhandled key - Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>",
    chr, chr, chr, chr);
 }
 endwin();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct MEVENT { short id; int x; unsigned int bstate; }

variable_types: chr int


decompiled_code:
void settings_size()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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


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

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

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

v0 = CALS;
if ( CALS )
{
v1 = 0;
v2 = 0;
do
{
v3 = strlen(*(const char **)v0);
if ( v3 > v2 )
v2 = v3;
v4 = strlen(*(const char **)(v0 + 8));
if ( v4 > v1 )
v1 = v4;
v0 = *(_QWORD *)(v0 + 24);
}
while ( v0 );
}
else
{
v1 = 0;
v2 = 0;
}
func1(win, "Current Settings\n");
func0(win, "Compact layout\n", &COMPACT);
result = func1(win, "\nLoaded Calendars\n");
for ( i = CALS; i; i = *(_QWORD *)(i + 24) )
{
v7 = *(const char **)(i + 16);
if ( !v7 )
v7 = "(no description)";
v8 = *(const char **)(i + 8);
v11 = strlen(v8);
v9 = *(const char **)i;
v10 = strlen(*(const char **)i);
result = wprintw(win, " %s:%*s \"%s\"%*s - %s\n", v9, v2 - v10, &unk_20D, v8, v1 - v11, &unk_20D, 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;
}


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

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

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

timer = time(0LL);
v0 = localtime(&timer);
SEL = v0->tm_year + 1900;
*(&SEL + 1) = v0->tm_mon;
result = (unsigned int)(v0->tm_mday - 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; } *


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

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

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

timer = time(0LL);
v0 = localtime(&timer);
NOW[0] = v0->tm_year + 1900;
NOW[1] = v0->tm_mon;
NOW[2] = v0->tm_mday - 1;
NOW[3] = v0->tm_hour;
NOW[4] = v0->tm_min;
result = (unsigned int)v0->tm_sec;
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 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);
}

variable_types: year int


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; // er12

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

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

v2 = func6(a1, a2);
return (unsigned int)((int)(v2 + func4(a1, a2) - 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)
{
struct tm v2; // [rsp+0h] [rbp-48h] BYREF

*(_QWORD *)&v2.tm_sec = 0LL;
*(_QWORD *)&v2.tm_wday = 0LL;
*(_QWORD *)&v2.tm_isdst = 0LL;
v2.tm_gmtoff = 0LL;
v2.tm_zone = 0LL;
v2.tm_min = a1[4];
v2.tm_hour = a1[3];
v2.tm_mday = a1[2] + 1;
v2.tm_mon = a1[1];
*(_QWORD *)&v2.tm_year = (unsigned int)(*a1 - 1900);
return mktime(&v2);
}

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

*(_QWORD *)&v2.tm_sec = 0LL;
*(_QWORD *)&v2.tm_wday = 0LL;
*(_QWORD *)&v2.tm_isdst = 0LL;
v2.tm_gmtoff = 0LL;
v2.tm_zone = 0LL;
v2.tm_min = a1[4];
v2.tm_hour = a1[3];
v2.tm_mday = a1[2] + 1;
v2.tm_mon = a1[1];
*(_QWORD *)&v2.tm_year = (unsigned int)(*a1 - 1900);
return mktime(&v2);
}

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


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; // ecx
unsigned int v4; // edx
int v5; // ecx
int v6; // edx
int v7; // ecx
int v8; // edx
int v9; // ecx
int v10; // edx

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

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax
unsigned int v3; // ecx
unsigned int v4; // edx
int v5; // ecx
int v6; // edx
int v7; // ecx
int v8; // edx
int v9; // ecx
int v10; // edx

result = 0xFFFFFFFFLL;
if ( *a1 >= *a2 )
{
result = 1LL;
if ( *a1 == *a2 )
{
v3 = a1[1];
v4 = a2[1];
result = 0xFFFFFFFFLL;
if ( v3 >= v4 )
{
result = 1LL;
if ( v3 == v4 )
{
v5 = a1[2];
v6 = a2[2];
result = 0xFFFFFFFFLL;
if ( v5 >= v6 )
{
result = 1LL;
if ( v5 == v6 )
{
v7 = a1[3];
v8 = a2[3];
result = 0xFFFFFFFFLL;
if ( v7 >= v8 )
{
result = 1LL;
if ( v7 == v8 )
{
v9 = a1[4];
v10 = a2[4];
result = 0xFFFFFFFFLL;
if ( v9 >= v10 )
result = v9 > v10;
}
}
}
}
}
}
}
}
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[5] = 0;
v7[0] = a2;
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 i; // ebx
char *v1; // rax
unsigned int v2; // eax
char *v3; // rax
unsigned int v4; // eax
unsigned int v5; // eax
int result; // eax

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

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

puts("Info");
puts(" Year Month Start Weeks Days");
for ( i = 0; i != 12; ++i )
{
printf(" %-5d", 2012LL);
v1 = func18(i);
printf(" %-10s", v1);
v2 = func6(0x7DCu, i);
v3 = func20(v2);
printf(" %-6s", v3);
v4 = func7(0x7DCu, i);
printf(" %-6d", v4);
v5 = func4(2012, i);
printf(" %-2d", v5);
result = putchar(10);
}
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_event(__int64 a1)
{
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
const char *v5; // rdx
WINDOW *v6; // rdi
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
char *v11; // rax
WINDOW *v12; // rdi
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // r9
char *v17; // rax
const char *v18; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Event\n");
v2 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v2 = "[none]";
wprintw(win, " Name: %s\n", v2);
v3 = *(const char **)(a1 + 8);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Description: %s\n", v3);
v4 = *(const char **)(a1 + 16);
if ( !v4 )
v4 = "[none]";
wprintw(win, " Location: %s\n", v4);
v5 = *(const char **)(a1 + 24);
if ( !v5 )
v5 = "[none]";
v6 = win;
wprintw(win, " Category: %s\n", v5);
v11 = timestr(
(__int64)v6,
(__int64)" Category: %s\n",
v7,
v8,
v9,
v10,
*(_QWORD *)(a1 + 32),
*(_QWORD *)(a1 + 40),
*(_QWORD *)(a1 + 48));
v12 = win;
wprintw(win, " Start Time: %s\n", v11);
v17 = timestr(
(__int64)v12,
(__int64)" Start Time: %s\n",
v13,
v14,
v15,
v16,
*(_QWORD *)(a1 + 56),
*(_QWORD *)(a1 + 64),
*(_QWORD *)(a1 + 72));
wprintw(win, " End Time: %s\n", v17);
v18 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v18 )
v18 = "[none]";
return wprintw(win, " Calendar: %s\n", v18);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
const char *v5; // rdx
WINDOW *v6; // rdi
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
char *v11; // rax
WINDOW *v12; // rdi
__int64 v13; // rdx
__int64 v14; // rcx
__int64 v15; // r8
__int64 v16; // r9
char *v17; // rax
const char *v18; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Event\n");
v2 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v2 = "[none]";
wprintw(win, " Name: %s\n", v2);
v3 = *(const char **)(a1 + 8);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Description: %s\n", v3);
v4 = *(const char **)(a1 + 16);
if ( !v4 )
v4 = "[none]";
wprintw(win, " Location: %s\n", v4);
v5 = *(const char **)(a1 + 24);
if ( !v5 )
v5 = "[none]";
v6 = win;
wprintw(win, " Category: %s\n", v5);
v11 = func2(
(__int64)v6,
(__int64)" Category: %s\n",
v7,
v8,
v9,
v10,
*(_QWORD *)(a1 + 32),
*(_QWORD *)(a1 + 40),
*(_QWORD *)(a1 + 48));
v12 = win;
wprintw(win, " Start Time: %s\n", v11);
v17 = func2(
(__int64)v12,
(__int64)" Start Time: %s\n",
v13,
v14,
v15,
v16,
*(_QWORD *)(a1 + 56),
*(_QWORD *)(a1 + 64),
*(_QWORD *)(a1 + 72));
wprintw(win, " End Time: %s\n", v17);
v18 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v18 )
v18 = "[none]";
return wprintw(win, " Calendar: %s\n", v18);
}

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


decompiled_code:
int __fastcall draw_todo(__int64 a1)
{
const char *v2; // rdx
const char *v3; // rdx
const char *v4; // rdx
WINDOW *v5; // rdi
__m128i v6; // xmm0
__int64 v7; // rdx
__int64 v8; // rcx
__int64 v9; // r8
__int64 v10; // r9
char *v11; // rax
WINDOW *v12; // rdi
__m128i v13; // xmm1
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
__int64 v17; // r9
char *v18; // rax
const char *v19; // rdx

wmove(win, 0, 0);
wprintw(win, "Edit Todo\n");
v2 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
v2 = "[none]";
wprintw(win, " Name: %s\n", v2);
v3 = *(const char **)(a1 + 8);
if ( !v3 )
v3 = "[none]";
wprintw(win, " Description: %s\n", v3);
v4 = *(const char **)(a1 + 16);
if ( !v4 )
v4 = "[none]";
wprintw(win, " Category: %s\n", v4);
v5 = win;
wprintw(win, " Completed: %d%%\n", *(unsigned int *)(a1 + 24));
v6 = _mm_loadu_si128((const __m128i *)(a1 + 28));
v11 = timestr(
(__int64)v5,
(__int64)" Completed: %d%%\n",
v7,
v8,
v9,
v10,
v6.m128i_i64[0],
v6.m128i_i64[1],
*(_QWORD *)(a1 + 44));
v12 = win;
wprintw(win, " Start Time: %s\n", v11);
v13 = _mm_loadu_si128((const __m128i *)(a1 + 52));
v18 = timestr(
(__int64)v12,
(__int64)" Start Time: %s\n",
v14,
v15,
v16,
v17,
v13.m128i_i64[0],
v13.m128i_i64[1],
*(_QWORD *)(a1 + 68));
wprintw(win, " Due Date: %s\n", v18);
v19 = *(const char **)(*(_QWORD *)(a1 + 80) + 8LL);
if ( !v19 )
v19 = "[none]";
return wprintw(win, " Calendar: %s\n", v19);
}

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


decompiled_code:
void edit_size()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

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 func7()
{
int result; // eax

result = EDIT;
if ( EDIT == 2 )
return func3(EVENT);
if ( EDIT == 3 )
result = func4(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 __fastcall edit_run(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
if ( EDIT == 2 )
return edit_event(EVENT, a1, a2, a3, a4);
if ( EDIT == 3 )
return edit_todo(TODO, a1, a2, a3, a4);
return EDIT == 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
if ( EDIT == 2 )
return func0(EVENT, a1, a2, a3, a4);
if ( EDIT == 3 )
return func1(TODO, a1, a2, a3, a4);
return EDIT == 1;
}

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; // ebx

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; // ebx

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()
{
int v0; // er14
unsigned int v1; // er12
__int64 v2; // rax
int v3; // ebx
int i; // er13
const char *v5; // rbx
double v6; // xmm0_8
double v7; // xmm0_8
__int64 v8; // rbx
int v9; // ebp
int v10; // eax
int v11; // er12
int k; // ebx
__int64 v13; // r15
__int64 v14; // r14
int v15; // eax
__int64 v16; // r8
unsigned int l; // er13
int m; // ebx
int result; // eax
int v20; // ebx
int v21; // ebx
int j; // [rsp+0h] [rbp-D8h]
unsigned int v23; // [rsp+0h] [rbp-D8h]
unsigned int v24; // [rsp+4h] [rbp-D4h]
float v25; // [rsp+8h] [rbp-D0h]
int v26; // [rsp+10h] [rbp-C8h]
unsigned int v27; // [rsp+14h] [rbp-C4h]
int v28; // [rsp+1Ch] [rbp-BCh]
__int64 v29; // [rsp+20h] [rbp-B8h]
unsigned int v30; // [rsp+2Ch] [rbp-ACh]
unsigned int v31; // [rsp+30h] [rbp-A8h]
unsigned int v32; // [rsp+34h] [rbp-A4h]
unsigned int v33; // [rsp+38h] [rbp-A0h]
int v34; // [rsp+3Ch] [rbp-9Ch]
int v35; // [rsp+40h] [rbp-98h]
int v36; // [rsp+44h] [rbp-94h]
int v37; // [rsp+48h] [rbp-90h]
int v38; // [rsp+4Ch] [rbp-8Ch]
int v39; // [rsp+5Ch] [rbp-7Ch] BYREF
__int64 v40[6]; // [rsp+60h] [rbp-78h] BYREF
unsigned int v41; // [rsp+94h] [rbp-44h] BYREF
unsigned int v42; // [rsp+98h] [rbp-40h] BYREF
int v43[15]; // [rsp+9Ch] [rbp-3Ch] BYREF

v38 = COMPACT;
v34 = 3 - COMPACT;
v25 = (float)(COLS - 6) / 7.0;
v43[0] = SEL[0];
v42 = SEL[1];
v41 = SEL[2];
v0 = day_of_week();
add_days(v43, &v42, &v41, (unsigned int)-v0);
cal_load((unsigned int)v43[0], v42, v41, 7LL);
v35 = (int)((float)((float)v0 * v25) + 0.5);
v36 = (int)((float)((float)(v0 + 1) * v25) + 0.5);
v1 = COMPACT;
if ( COMPACT )
v1 = 2359296;
wattr_on(win, v1, 0LL);
v2 = month_to_str(SEL[1]);
mvwprintw(win, 0, 0, "%-*s", (unsigned int)COLS, v2);
mvwprintw(win, 1, 0, "%-0*d", (unsigned int)COLS, SEL[0]);
wattr_off(win, v1, 0LL);
v3 = (int)((float)((float)v0 * v25) + 0.5) + 6;
if ( wmove(win, 0, v3) != -1 )
whline(win, 0x20uLL, (int)((float)((float)(v0 + 1) * v25) + 0.5) - (int)((float)((float)v0 * v25) + 0.5) - 1);
if ( wmove(win, 1, v3) != -1 )
whline(win, 0x20uLL, v36 - v35 - 1);
wattr_on(win, v1, 0LL);
for ( i = 0; i != 7; ++i )
{
if ( v25 < 10.0 )
v5 = (const char *)day_to_str((unsigned int)i);
else
v5 = (const char *)day_to_string((unsigned int)i);
if ( v0 == i )
{
wattrset(win, 0x200000);
v7 = (float)((float)i * v25) + 0.5;
mvwprintw(win, 0, (int)v7 + 6, "%s", v5);
mvwprintw(win, 1, (int)v7 + 6, "%02d/%02d", v42 + 1, v41 + 1);
wattrset(win, v1);
}
else
{
v6 = (float)((float)i * v25) + 0.5;
mvwprintw(win, 0, (int)v6 + 6, "%s", v5);
mvwprintw(win, 1, (int)v6 + 6, "%02d/%02d", v42 + 1, v41 + 1);
}
add_days(v43, &v42, &v41, 1LL);
}
wattr_off(win, v1, 0LL);
v8 = EVENTS;
add_days(v43, &v42, &v41, 4294967289LL);
v9 = 0;
for ( j = 0; j != 7; ++j )
{
v11 = 0;
while ( v8 )
{
if ( !(unsigned int)before(v8 + 32, (unsigned int)v43[0], v42, v41, 24LL, 0LL) )
break;
if ( !(unsigned int)before(v8 + 56, (unsigned int)v43[0], v42, v41, 0LL, 1LL)
&& (int)get_mins(v8 + 32, v8 + 56) > 1380 )
{
v10 = (int)((float)((float)j * v25) + 0.5);
event_line(
win,
v8,
(unsigned int)(v34 + v11++),
(unsigned int)(v10 + 6),
(unsigned int)((int)((float)((float)(j + 1) * v25) + 0.5) - 1 - v10),
2LL);
}
v8 = *(_QWORD *)(v8 + 88);
if ( v9 < v11 )
v9 = v11;
}
add_days(v43, &v42, &v41, 1LL);
}
v37 = v9;
if ( v9 )
v37 = (COMPACT == 0) + v9;
wshrink(times, (__PAIR64__(v34 + v37, COMPACT) - 1) >> 32);
wshrink(body, (__PAIR64__(v34 + v37, COMPACT) - 1) >> 32);
mvwprintw(
times,
COMPACT == 0,
0,
"%02d:%02d",
(unsigned int)((line / 4 - 1) % 12 + 1),
(unsigned int)(15 * line % 60));
for ( k = 0; k != 24; ++k )
mvwprintw(times, (COMPACT == 0) + 4 * k - line, 0, "%02d:%02d", (unsigned int)((k - 1) % 12 + 1), 0LL);
if ( !EVENT )
EVENT = find_event(SEL);
v13 = EVENTS;
add_days(v43, &v42, &v41, 4294967289LL);
v40[0] = 0LL;
v40[1] = 0LL;
v40[2] = 0LL;
v40[3] = 0LL;
v40[4] = 0LL;
v39 = 0;
v28 = 1;
v29 = 0LL;
do
{
v23 = 0;
v14 = v13;
do
{
for ( l = 0; l != 60; l += 15 )
{
for ( ; v14; v14 = *(_QWORD *)(v14 + 88) )
{
if ( !(unsigned int)before(
v14 + 32,
(unsigned int)v43[0],
v42,
v41,
(int)(l + 15) / 60 + v23,
(unsigned int)((int)(l + 15) % 60)) )
break;
if ( !(unsigned int)before(v14 + 32, (unsigned int)v43[0], v42, v41, v23, l)
&& (int)get_mins(v14 + 32, v14 + 56) <= 1380 )
{
v15 = get_col(v40, 5LL, v14, &v39);
v27 = (COMPACT == 0) + 4 * v23 + (int)l / 15 - line;
v26 = v15;
v24 = (int)((float)((float)(v28 - 1) * v25) + 0.5) + 3 * v15 + 1;
v16 = (unsigned int)((int)(get_mins(v14 + 32, v14 + 56) - 1) / 15 + 1);
if ( EVENT == v14 )
{
v29 = v14;
v33 = v16;
v32 = -3 * (v39 + ~v26) + (int)((float)((float)v28 * v25) + 0.5) - v24;
v31 = v27;
v30 = v24;
}
else
{
event_box(body, v14, v27, v24, v16, -3 * (v39 + ~v26) + (int)((float)((float)v28 * v25) + 0.5) - v24);
}
}
}
}
++v23;
}
while ( v23 != 24 );
v13 = v14;
add_days(v43, &v42, &v41, 1LL);
++v28;
}
while ( v28 != 8 );
if ( v29 )
event_box(body, v29, v31, v30, v33, v32);
if ( !COMPACT )
{
if ( wmove(win, 2 - v38, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( !COMPACT && v37 && wmove(win, 2 - v38 + v37, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
for ( m = 0; m != 7; ++m )
{
if ( wmove(body, COMPACT == 0, (int)((float)((float)m * v25) + 0.5)) != -1 )
wvline(body, LODWORD(acs_map[60]), LINES - v34 + COMPACT - 2 - v37);
}
if ( wmove(body, 0, v35) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v34);
if ( wmove(body, 0, v36) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v34);
result = line;
v20 = line + 6;
if ( line + 3 >= 0 )
v20 = line + 3;
v21 = v20 >> 2;
if ( line <= 92 )
{
do
{
if ( wmove(body, (COMPACT == 0) + 4 * v21 - line, v35) != -1 )
wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2352));
result = wmove(body, (COMPACT == 0) + 4 * v21 - line, v36);
if ( result != -1 )
result = wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2380));
++v21;
}
while ( v21 <= 23 );
}
if ( !COMPACT )
{
result = wmove(body, 0, v35);
if ( result != -1 )
result = whline(body, LODWORD(acs_map[24]), v36 - v35 + 1);
}
return result;
}

canonical_decompiled_code:
int func2()
{
int v0; // er14
unsigned int v1; // er12
__int64 v2; // rax
int v3; // ebx
int i; // er13
const char *v5; // rbx
double v6; // xmm0_8
double v7; // xmm0_8
__int64 v8; // rbx
int v9; // ebp
int v10; // eax
int v11; // er12
int k; // ebx
__int64 v13; // r15
__int64 v14; // r14
int v15; // eax
__int64 v16; // r8
unsigned int l; // er13
int m; // ebx
int result; // eax
int v20; // ebx
int v21; // ebx
int j; // [rsp+0h] [rbp-D8h]
unsigned int v23; // [rsp+0h] [rbp-D8h]
unsigned int v24; // [rsp+4h] [rbp-D4h]
float v25; // [rsp+8h] [rbp-D0h]
int v26; // [rsp+10h] [rbp-C8h]
unsigned int v27; // [rsp+14h] [rbp-C4h]
int v28; // [rsp+1Ch] [rbp-BCh]
__int64 v29; // [rsp+20h] [rbp-B8h]
unsigned int v30; // [rsp+2Ch] [rbp-ACh]
unsigned int v31; // [rsp+30h] [rbp-A8h]
unsigned int v32; // [rsp+34h] [rbp-A4h]
unsigned int v33; // [rsp+38h] [rbp-A0h]
int v34; // [rsp+3Ch] [rbp-9Ch]
int v35; // [rsp+40h] [rbp-98h]
int v36; // [rsp+44h] [rbp-94h]
int v37; // [rsp+48h] [rbp-90h]
int v38; // [rsp+4Ch] [rbp-8Ch]
int v39; // [rsp+5Ch] [rbp-7Ch] BYREF
__int64 v40[6]; // [rsp+60h] [rbp-78h] BYREF
unsigned int v41; // [rsp+94h] [rbp-44h] BYREF
unsigned int v42; // [rsp+98h] [rbp-40h] BYREF
int v43[15]; // [rsp+9Ch] [rbp-3Ch] BYREF

v38 = COMPACT;
v34 = 3 - COMPACT;
v25 = (float)(COLS - 6) / 7.0;
v43[0] = SEL[0];
v42 = SEL[1];
v41 = SEL[2];
v0 = day_of_week();
add_days(v43, &v42, &v41, (unsigned int)-v0);
cal_load((unsigned int)v43[0], v42, v41, 7LL);
v35 = (int)((float)((float)v0 * v25) + 0.5);
v36 = (int)((float)((float)(v0 + 1) * v25) + 0.5);
v1 = COMPACT;
if ( COMPACT )
v1 = 2359296;
wattr_on(win, v1, 0LL);
v2 = month_to_str(SEL[1]);
mvwprintw(win, 0, 0, "%-*s", (unsigned int)COLS, v2);
mvwprintw(win, 1, 0, "%-0*d", (unsigned int)COLS, SEL[0]);
wattr_off(win, v1, 0LL);
v3 = (int)((float)((float)v0 * v25) + 0.5) + 6;
if ( wmove(win, 0, v3) != -1 )
whline(win, 0x20uLL, (int)((float)((float)(v0 + 1) * v25) + 0.5) - (int)((float)((float)v0 * v25) + 0.5) - 1);
if ( wmove(win, 1, v3) != -1 )
whline(win, 0x20uLL, v36 - v35 - 1);
wattr_on(win, v1, 0LL);
for ( i = 0; i != 7; ++i )
{
if ( v25 < 10.0 )
v5 = (const char *)day_to_str((unsigned int)i);
else
v5 = (const char *)day_to_string((unsigned int)i);
if ( v0 == i )
{
wattrset(win, 0x200000);
v7 = (float)((float)i * v25) + 0.5;
mvwprintw(win, 0, (int)v7 + 6, "%s", v5);
mvwprintw(win, 1, (int)v7 + 6, "%02d/%02d", v42 + 1, v41 + 1);
wattrset(win, v1);
}
else
{
v6 = (float)((float)i * v25) + 0.5;
mvwprintw(win, 0, (int)v6 + 6, "%s", v5);
mvwprintw(win, 1, (int)v6 + 6, "%02d/%02d", v42 + 1, v41 + 1);
}
add_days(v43, &v42, &v41, 1LL);
}
wattr_off(win, v1, 0LL);
v8 = EVENTS;
add_days(v43, &v42, &v41, 4294967289LL);
v9 = 0;
for ( j = 0; j != 7; ++j )
{
v11 = 0;
while ( v8 )
{
if ( !(unsigned int)before(v8 + 32, (unsigned int)v43[0], v42, v41, 24LL, 0LL) )
break;
if ( !(unsigned int)before(v8 + 56, (unsigned int)v43[0], v42, v41, 0LL, 1LL)
&& (int)get_mins(v8 + 32, v8 + 56) > 1380 )
{
v10 = (int)((float)((float)j * v25) + 0.5);
event_line(
win,
v8,
(unsigned int)(v34 + v11++),
(unsigned int)(v10 + 6),
(unsigned int)((int)((float)((float)(j + 1) * v25) + 0.5) - 1 - v10),
2LL);
}
v8 = *(_QWORD *)(v8 + 88);
if ( v9 < v11 )
v9 = v11;
}
add_days(v43, &v42, &v41, 1LL);
}
v37 = v9;
if ( v9 )
v37 = (COMPACT == 0) + v9;
wshrink(times, (__PAIR64__(v34 + v37, COMPACT) - 1) >> 32);
wshrink(body, (__PAIR64__(v34 + v37, COMPACT) - 1) >> 32);
mvwprintw(
times,
COMPACT == 0,
0,
"%02d:%02d",
(unsigned int)((line / 4 - 1) % 12 + 1),
(unsigned int)(15 * line % 60));
for ( k = 0; k != 24; ++k )
mvwprintw(times, (COMPACT == 0) + 4 * k - line, 0, "%02d:%02d", (unsigned int)((k - 1) % 12 + 1), 0LL);
if ( !EVENT )
EVENT = find_event(SEL);
v13 = EVENTS;
add_days(v43, &v42, &v41, 4294967289LL);
v40[0] = 0LL;
v40[1] = 0LL;
v40[2] = 0LL;
v40[3] = 0LL;
v40[4] = 0LL;
v39 = 0;
v28 = 1;
v29 = 0LL;
do
{
v23 = 0;
v14 = v13;
do
{
for ( l = 0; l != 60; l += 15 )
{
for ( ; v14; v14 = *(_QWORD *)(v14 + 88) )
{
if ( !(unsigned int)before(
v14 + 32,
(unsigned int)v43[0],
v42,
v41,
(int)(l + 15) / 60 + v23,
(unsigned int)((int)(l + 15) % 60)) )
break;
if ( !(unsigned int)before(v14 + 32, (unsigned int)v43[0], v42, v41, v23, l)
&& (int)get_mins(v14 + 32, v14 + 56) <= 1380 )
{
v15 = get_col(v40, 5LL, v14, &v39);
v27 = (COMPACT == 0) + 4 * v23 + (int)l / 15 - line;
v26 = v15;
v24 = (int)((float)((float)(v28 - 1) * v25) + 0.5) + 3 * v15 + 1;
v16 = (unsigned int)((int)(get_mins(v14 + 32, v14 + 56) - 1) / 15 + 1);
if ( EVENT == v14 )
{
v29 = v14;
v33 = v16;
v32 = -3 * (v39 + ~v26) + (int)((float)((float)v28 * v25) + 0.5) - v24;
v31 = v27;
v30 = v24;
}
else
{
event_box(body, v14, v27, v24, v16, -3 * (v39 + ~v26) + (int)((float)((float)v28 * v25) + 0.5) - v24);
}
}
}
}
++v23;
}
while ( v23 != 24 );
v13 = v14;
add_days(v43, &v42, &v41, 1LL);
++v28;
}
while ( v28 != 8 );
if ( v29 )
event_box(body, v29, v31, v30, v33, v32);
if ( !COMPACT )
{
if ( wmove(win, 2 - v38, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( !COMPACT && v37 && wmove(win, 2 - v38 + v37, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
for ( m = 0; m != 7; ++m )
{
if ( wmove(body, COMPACT == 0, (int)((float)((float)m * v25) + 0.5)) != -1 )
wvline(body, LODWORD(acs_map[60]), LINES - v34 + COMPACT - 2 - v37);
}
if ( wmove(body, 0, v35) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v34);
if ( wmove(body, 0, v36) != -1 )
wvline_set(body, nc_wacs + 77, COMPACT + LINES + ~v34);
result = line;
v20 = line + 6;
if ( line + 3 >= 0 )
v20 = line + 3;
v21 = v20 >> 2;
if ( line <= 92 )
{
do
{
if ( wmove(body, (COMPACT == 0) + 4 * v21 - line, v35) != -1 )
wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2352));
result = wmove(body, (COMPACT == 0) + 4 * v21 - line, v36);
if ( result != -1 )
result = wadd_wch(body, (cchar_t *)((char *)nc_wacs + 2380));
++v21;
}
while ( v21 <= 23 );
}
if ( !COMPACT )
{
result = wmove(body, 0, v35);
if ( result != -1 )
result = whline(body, LODWORD(acs_map[24]), v36 - v35 + 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;
goto LABEL_22;
case 'i':
v4 = 0LL;
v5 = 4294967289LL;
goto LABEL_22;
case 'j':
v4 = 1LL;
v5 = 0LL;
goto LABEL_22;
case 'k':
v4 = 0xFFFFFFFFLL;
v5 = 0LL;
goto LABEL_22;
case 'l':
v4 = 0LL;
v5 = 1LL;
goto LABEL_22;
case 'o':
v4 = 0LL;
v5 = 7LL;
LABEL_22:
if ( (unsigned int)v4 | (unsigned int)v5 )
move_event(v4, v5, &line);
goto LABEL_12;
default:
return 0LL;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
result = 1LL;
}
else
{
if ( a1 == 25 )
{
v1 = -1;
}
else
{
if ( a1 != 5 )
return 0LL;
v1 = 1;
}
line += v1;
v2 = 0;
if ( line >= 0 )
v2 = line;
if ( v2 > 96 )
v2 = 96;
line = v2;
LABEL_12:
werase(win);
week_draw();
wrefresh(win);
result = 1LL;
}
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;
goto LABEL_22;
case 'i':
v4 = 0LL;
v5 = 4294967289LL;
goto LABEL_22;
case 'j':
v4 = 1LL;
v5 = 0LL;
goto LABEL_22;
case 'k':
v4 = 0xFFFFFFFFLL;
v5 = 0LL;
goto LABEL_22;
case 'l':
v4 = 0LL;
v5 = 1LL;
goto LABEL_22;
case 'o':
v4 = 0LL;
v5 = 7LL;
LABEL_22:
if ( (unsigned int)v4 | (unsigned int)v5 )
move_event(v4, v5, &line);
goto LABEL_12;
default:
return 0LL;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
result = 1LL;
}
else
{
if ( a1 == 25 )
{
v1 = -1;
}
else
{
if ( a1 != 5 )
return 0LL;
v1 = 1;
}
line += v1;
v2 = 0;
if ( line >= 0 )
v2 = line;
if ( v2 > 96 )
v2 = 96;
line = v2;
LABEL_12:
werase(win);
func2();
wrefresh(win);
result = 1LL;
}
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; // ebx
int v2; // eax
int v3; // edx
int v4; // ebx
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // edx

if ( a1 > 117 )
goto LABEL_26;
if ( a1 > 67 )
{
switch ( a1 )
{
case 'D':
v2 = LINES;
v1 = 0;
goto LABEL_7;
case 'G':
v2 = rows;
v1 = 0;
goto LABEL_7;
case 'U':
v2 = -LINES;
v1 = 0;
goto LABEL_7;
case 'd':
v2 = LINES / 2;
v1 = 0;
goto LABEL_7;
case 'g':
v2 = -line;
v1 = 0;
goto LABEL_7;
case 'j':
v8 = rows - 1;
v9 = 0;
if ( line >= 0 )
v9 = line;
if ( v8 > v9 )
v8 = v9;
line = v8;
if ( EVENT && *(_QWORD *)(EVENT + 88LL) )
EVENT = *(_QWORD *)(EVENT + 88LL);
v4 = 1;
goto LABEL_16;
case 'k':
v1 = -1;
v2 = 0;
goto LABEL_7;
case 'u':
v2 = LINES / -2;
v1 = 0;
goto LABEL_7;
default:
goto LABEL_26;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
return 1LL;
}
if ( a1 == 25 )
{
v1 = 0;
v2 = -1;
goto LABEL_7;
}
if ( a1 != 5 )
{
LABEL_26:
v6 = rows - 1;
v7 = 0;
if ( line >= 0 )
v7 = line;
if ( v6 > v7 )
v6 = v7;
line = v6;
v1 = 0;
v2 = 0;
LABEL_31:
v4 = v2 | v1;
if ( !v4 )
return v4 != 0;
goto LABEL_16;
}
v1 = 0;
v2 = 1;
LABEL_7:
v3 = line + v2;
if ( line + v2 < 0 )
v3 = 0;
if ( v3 > rows - 1 )
v3 = rows - 1;
line = v3;
if ( v1 >= 0 )
goto LABEL_31;
if ( EVENT )
{
if ( *(_QWORD *)(EVENT + 96LL) )
EVENT = *(_QWORD *)(EVENT + 96LL);
}
v4 = -1;
LABEL_16:
werase(win);
events_draw();
wrefresh(win);
return v4 != 0;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebx
int v2; // eax
int v3; // edx
int v4; // ebx
int v6; // eax
int v7; // edx
int v8; // eax
int v9; // edx

if ( a1 > 117 )
goto LABEL_26;
if ( a1 > 67 )
{
switch ( a1 )
{
case 'D':
v2 = LINES;
v1 = 0;
goto LABEL_7;
case 'G':
v2 = rows;
v1 = 0;
goto LABEL_7;
case 'U':
v2 = -LINES;
v1 = 0;
goto LABEL_7;
case 'd':
v2 = LINES / 2;
v1 = 0;
goto LABEL_7;
case 'g':
v2 = -line;
v1 = 0;
goto LABEL_7;
case 'j':
v8 = rows - 1;
v9 = 0;
if ( line >= 0 )
v9 = line;
if ( v8 > v9 )
v8 = v9;
line = v8;
if ( EVENT && *(_QWORD *)(EVENT + 88LL) )
EVENT = *(_QWORD *)(EVENT + 88LL);
v4 = 1;
goto LABEL_16;
case 'k':
v1 = -1;
v2 = 0;
goto LABEL_7;
case 'u':
v2 = LINES / -2;
v1 = 0;
goto LABEL_7;
default:
goto LABEL_26;
}
}
if ( a1 == 10 )
{
view_edit(2LL);
return 1LL;
}
if ( a1 == 25 )
{
v1 = 0;
v2 = -1;
goto LABEL_7;
}
if ( a1 != 5 )
{
LABEL_26:
v6 = rows - 1;
v7 = 0;
if ( line >= 0 )
v7 = line;
if ( v6 > v7 )
v6 = v7;
line = v6;
v1 = 0;
v2 = 0;
LABEL_31:
v4 = v2 | v1;
if ( !v4 )
return v4 != 0;
goto LABEL_16;
}
v1 = 0;
v2 = 1;
LABEL_7:
v3 = line + v2;
if ( line + v2 < 0 )
v3 = 0;
if ( v3 > rows - 1 )
v3 = rows - 1;
line = v3;
if ( v1 >= 0 )
goto LABEL_31;
if ( EVENT )
{
if ( *(_QWORD *)(EVENT + 96LL) )
EVENT = *(_QWORD *)(EVENT + 96LL);
}
v4 = -1;
LABEL_16:
werase(win);
func2();
wrefresh(win);
return v4 != 0;
}

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