decompiled_code:
void __fastcall move_event(int a1, unsigned int a2, int *a3)
{
__int64 v6; // rdi
int v7; // er13
__int64 v8; // rsi
int v9; // ecx
int v10; // edx
int v11; // eax
__int64 v12; // rax
const __m128i *v13; // rax
__m128i v14; // xmm1
__int64 v15; // rax
_BYTE v16[24]; // [rsp+0h] [rbp-48h] BYREF

if ( !a1 )
goto LABEL_8;
v6 = EVENT;
if ( !EVENT )
goto LABEL_8;
v7 = 0;
if ( a1 > 0 )
{
do
{
v8 = *(_QWORD *)(v6 + 88);
if ( !v8 )
break;
if ( !(unsigned int)same_day(v6 + 32, v8 + 32) )
break;
++v7;
v6 = *(_QWORD *)(EVENT + 88LL);
EVENT = v6;
}
while ( a1 != v7 );
LABEL_8:
if ( !a2 )
goto LABEL_9;
goto LABEL_21;
}
while ( *(_QWORD *)(v6 + 88) )
{
if ( (unsigned int)same_day(v6 + 32, *(_QWORD *)(v6 + 96) + 32LL) )
{
--v7;
v6 = *(_QWORD *)(EVENT + 96LL);
EVENT = v6;
if ( a1 != v7 )
continue;
}
goto LABEL_8;
}
if ( a2 )
{
LABEL_21:
add_days(&SEL, (unsigned int)((_DWORD)&SEL + 4), (unsigned int)((_DWORD)&SEL + 8), a2);
*(_QWORD *)&v16[16] = *((_QWORD *)&SEL + 2);
*(__m128i *)v16 = _mm_loadu_si128((const __m128i *)&SEL);
if ( EVENT )
{
v12 = *(_QWORD *)(EVENT + 44LL);
*(_DWORD *)&v16[20] = *(_DWORD *)(EVENT + 52LL);
*(_QWORD *)&v16[12] = v12;
}
v13 = (const __m128i *)find_event(v16);
EVENT = v13;
if ( v13 )
{
v14 = _mm_loadu_si128(v13 + 2);
v15 = v13[3].m128i_i64[0];
SEL = v14;
*((_QWORD *)&SEL + 2) = v15;
}
}
LABEL_9:
if ( a3 && EVENT && !(unsigned int)all_day(EVENT + 32LL, EVENT + 56LL) )
{
v9 = LINES + 2 * COMPACT - 4;
v10 = *(_DWORD *)(EVENT + 48LL) / 15 + 4 * *(_DWORD *)(EVENT + 44LL);
v11 = *a3;
if ( v10 + 3 >= *a3 + v9 )
{
v11 = v10 - v9 + 4;
*a3 = v11;
}
if ( v10 < v11 )
*a3 = v10;
}
}

canonical_decompiled_code:
void __fastcall func5(int a1, unsigned int a2, int *a3)
{
__int64 v6; // rdi
int v7; // er13
__int64 v8; // rsi
int v9; // ecx
int v10; // edx
int v11; // eax
__int64 v12; // rax
const __m128i *v13; // rax
__m128i v14; // xmm1
__int64 v15; // rax
_BYTE v16[24]; // [rsp+0h] [rbp-48h] BYREF

if ( !a1 )
goto LABEL_8;
v6 = EVENT;
if ( !EVENT )
goto LABEL_8;
v7 = 0;
if ( a1 > 0 )
{
do
{
v8 = *(_QWORD *)(v6 + 88);
if ( !v8 )
break;
if ( !(unsigned int)same_day(v6 + 32, v8 + 32) )
break;
++v7;
v6 = *(_QWORD *)(EVENT + 88LL);
EVENT = v6;
}
while ( a1 != v7 );
LABEL_8:
if ( !a2 )
goto LABEL_9;
goto LABEL_21;
}
while ( *(_QWORD *)(v6 + 88) )
{
if ( (unsigned int)same_day(v6 + 32, *(_QWORD *)(v6 + 96) + 32LL) )
{
--v7;
v6 = *(_QWORD *)(EVENT + 96LL);
EVENT = v6;
if ( a1 != v7 )
continue;
}
goto LABEL_8;
}
if ( a2 )
{
LABEL_21:
add_days(&SEL, (unsigned int)((_DWORD)&SEL + 4), (unsigned int)((_DWORD)&SEL + 8), a2);
*(_QWORD *)&v16[16] = *((_QWORD *)&SEL + 2);
*(__m128i *)v16 = _mm_loadu_si128((const __m128i *)&SEL);
if ( EVENT )
{
v12 = *(_QWORD *)(EVENT + 44LL);
*(_DWORD *)&v16[20] = *(_DWORD *)(EVENT + 52LL);
*(_QWORD *)&v16[12] = v12;
}
v13 = (const __m128i *)find_event(v16);
EVENT = v13;
if ( v13 )
{
v14 = _mm_loadu_si128(v13 + 2);
v15 = v13[3].m128i_i64[0];
SEL = v14;
*((_QWORD *)&SEL + 2) = v15;
}
}
LABEL_9:
if ( a3 && EVENT && !(unsigned int)all_day(EVENT + 32LL, EVENT + 56LL) )
{
v9 = LINES + 2 * COMPACT - 4;
v10 = *(_DWORD *)(EVENT + 48LL) / 15 + 4 * *(_DWORD *)(EVENT + 44LL);
v11 = *a3;
if ( v10 + 3 >= *a3 + v9 )
{
v11 = v10 - v9 + 4;
*a3 = v11;
}
if ( v10 < v11 )
*a3 = v10;
}
}

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

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

variable_types: events int

variable_types:
line
int *

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

variable_types: lines int

variable_types: begin int


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

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

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

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

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

variable_types: rows int

variable_types: cols int

variable_types: hdr int

return_type: void


decompiled_code:
int day_draw()
{
const char *v0; // rbp
unsigned int v1; // eax
const char *v2; // rbx
unsigned int v3; // er13
__int64 v4; // rbx
int v5; // er14
__int64 v6; // rdx
int v7; // eax
int v8; // ebx
int v9; // edx
int v10; // esi
__int64 v11; // rbx
unsigned int v12; // er15
unsigned int v13; // er12
unsigned int v14; // edi
int v15; // eax
int v16; // eax
int result; // eax
unsigned int v18; // eax
__int64 v19; // [rsp+0h] [rbp-E8h]
unsigned int v20; // [rsp+10h] [rbp-D8h]
unsigned int v21; // [rsp+1Ch] [rbp-CCh]
int v22; // [rsp+24h] [rbp-C4h]
double v23; // [rsp+28h] [rbp-C0h]
double v24; // [rsp+30h] [rbp-B8h]
double v25; // [rsp+38h] [rbp-B0h]
int v26; // [rsp+4Ch] [rbp-9Ch]
int v27; // [rsp+5Ch] [rbp-8Ch] BYREF
__int128 v28[8]; // [rsp+60h] [rbp-88h] BYREF

v0 = (const char *)month_to_string(SEL[1]);
v1 = day_of_week(SEL[0], SEL[1], SEL[2]);
v2 = (const char *)day_to_string(v1);
v3 = (COMPACT == 0) + 1;
cal_load(SEL[0], SEL[1], SEL[2], 1LL);
if ( COMPACT )
wattr_on(win, 0x240000uLL, 0LL);
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x20uLL, COLS);
mvwprintw(win, 0, 0, "%s, %s %d", v2, v0, SEL[2] + 1);
LODWORD(v19) = SEL[2] + 1;
mvwprintw(win, 0, COLS - 10, "%d-%02d-%02d", SEL[0], SEL[1] + 1, v19);
if ( COMPACT )
wattr_off(win, 0x240000uLL, 0LL);
v4 = EVENTS;
v26 = 0;
v5 = 0;
if ( EVENTS )
{
while ( (unsigned int)before(v4 + 32, SEL[0], SEL[1], SEL[2], 24LL, 0LL) )
{
if ( (unsigned int)before(v4 + 56, SEL[0], SEL[1], SEL[2], 0LL, 1LL) || (int)get_mins(v4 + 32, v4 + 56) <= 1380 )
{
v4 = *(_QWORD *)(v4 + 88);
if ( !v4 )
break;
}
else
{
v6 = v3 + v5++;
event_line(win, v4, v6, 6LL, (unsigned int)(COLS - 6), 3LL);
v4 = *(_QWORD *)(v4 + 88);
if ( !v4 )
break;
}
}
v26 = v5;
v7 = v5;
if ( v5 )
{
if ( !COMPACT )
{
v26 = v5 + 1;
v7 = v5 + 1;
}
v3 += v7;
}
}
wshrink(times, v3);
wshrink(body, v3);
v8 = 0;
mvwprintw(times, 0, 0, "%02d:%02d", (unsigned int)((line / 4 - 1) % 12 + 1), (unsigned int)(15 * line % 60));
do
{
v9 = v8 - 1;
v10 = 4 * v8++ - line;
mvwprintw(times, v10, 0, "%02d:%02d", (unsigned int)(v9 % 12 + 1), 0LL);
}
while ( v8 != 24 );
if ( !EVENT )
EVENT = find_event(SEL);
v27 = 0;
v11 = EVENTS;
v12 = 0;
v28[0] = 0LL;
v28[1] = 0LL;
v28[2] = 0LL;
v28[3] = 0LL;
v28[4] = 0LL;
do
{
LABEL_23:
v21 = 0;
while ( 1 )
{
v13 = v21;
v14 = v21 + 15;
v21 += 15;
if ( !v11 )
break;
while ( (unsigned int)before(v11 + 32, SEL[0], SEL[1], SEL[2], v12 + v14 / 0x3C, v14 % 0x3C) )
{
if ( (unsigned int)before(v11 + 32, SEL[0], SEL[1], SEL[2], v12, v13)
|| (int)get_mins(v11 + 32, v11 + 56) > 1380 )
{
v11 = *(_QWORD *)(v11 + 88);
if ( !v11 )
break;
}
else
{
v15 = get_col(v28, 10, v11, &v27);
v20 = 4 * v12 + (int)v13 / 15 - line;
v25 = (double)v15;
v23 = (double)v27;
v24 = (double)(COLS - 6);
v22 = (int)(((double)v15 + 0.0) * v24 / (double)v27 + 0.5);
v16 = get_mins(v11 + 32, v11 + 56);
event_box(
body,
v11,
v20,
(unsigned int)(v22 + 1),
(unsigned int)((v16 - 1) / 15 + 1),
(unsigned int)((int)((v25 + 1.0) * v24 / v23 + 0.5) - v22));
v11 = *(_QWORD *)(v11 + 88);
if ( !v11 )
break;
}
}
if ( v21 == 60 )
goto LABEL_32;
}
v18 = v21;
if ( v21 != 60 )
{
while ( v18 != 45 )
{
v18 += 30;
if ( v18 == 60 )
{
if ( ++v12 != 24 )
goto LABEL_23;
goto LABEL_33;
}
}
}
LABEL_32:
++v12;
}
while ( v12 != 24 );
LABEL_33:
if ( !COMPACT )
{
if ( wmove(win, 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( !COMPACT && v26 && wmove(win, v26 + 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
result = wmove(body, 0, 0);
if ( result != -1 )
result = wvline(body, LODWORD(acs_map[60]), LINES + 2 * COMPACT - 4);
return result;
}

canonical_decompiled_code:
int func8()
{
const char *v0; // rbp
unsigned int v1; // eax
const char *v2; // rbx
unsigned int v3; // er13
__int64 v4; // rbx
int v5; // er14
__int64 v6; // rdx
int v7; // eax
int v8; // ebx
int v9; // edx
int v10; // esi
__int64 v11; // rbx
unsigned int v12; // er15
unsigned int v13; // er12
unsigned int v14; // edi
int v15; // eax
int v16; // eax
int result; // eax
unsigned int v18; // eax
__int64 v19; // [rsp+0h] [rbp-E8h]
unsigned int v20; // [rsp+10h] [rbp-D8h]
unsigned int v21; // [rsp+1Ch] [rbp-CCh]
int v22; // [rsp+24h] [rbp-C4h]
double v23; // [rsp+28h] [rbp-C0h]
double v24; // [rsp+30h] [rbp-B8h]
double v25; // [rsp+38h] [rbp-B0h]
int v26; // [rsp+4Ch] [rbp-9Ch]
int v27; // [rsp+5Ch] [rbp-8Ch] BYREF
__int128 v28[8]; // [rsp+60h] [rbp-88h] BYREF

v0 = (const char *)month_to_string(SEL[1]);
v1 = day_of_week(SEL[0], SEL[1], SEL[2]);
v2 = (const char *)day_to_string(v1);
v3 = (COMPACT == 0) + 1;
cal_load(SEL[0], SEL[1], SEL[2], 1LL);
if ( COMPACT )
wattr_on(win, 0x240000uLL, 0LL);
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x20uLL, COLS);
mvwprintw(win, 0, 0, "%s, %s %d", v2, v0, SEL[2] + 1);
LODWORD(v19) = SEL[2] + 1;
mvwprintw(win, 0, COLS - 10, "%d-%02d-%02d", SEL[0], SEL[1] + 1, v19);
if ( COMPACT )
wattr_off(win, 0x240000uLL, 0LL);
v4 = EVENTS;
v26 = 0;
v5 = 0;
if ( EVENTS )
{
while ( (unsigned int)before(v4 + 32, SEL[0], SEL[1], SEL[2], 24LL, 0LL) )
{
if ( (unsigned int)before(v4 + 56, SEL[0], SEL[1], SEL[2], 0LL, 1LL) || (int)get_mins(v4 + 32, v4 + 56) <= 1380 )
{
v4 = *(_QWORD *)(v4 + 88);
if ( !v4 )
break;
}
else
{
v6 = v3 + v5++;
event_line(win, v4, v6, 6LL, (unsigned int)(COLS - 6), 3LL);
v4 = *(_QWORD *)(v4 + 88);
if ( !v4 )
break;
}
}
v26 = v5;
v7 = v5;
if ( v5 )
{
if ( !COMPACT )
{
v26 = v5 + 1;
v7 = v5 + 1;
}
v3 += v7;
}
}
wshrink(times, v3);
wshrink(body, v3);
v8 = 0;
mvwprintw(times, 0, 0, "%02d:%02d", (unsigned int)((line / 4 - 1) % 12 + 1), (unsigned int)(15 * line % 60));
do
{
v9 = v8 - 1;
v10 = 4 * v8++ - line;
mvwprintw(times, v10, 0, "%02d:%02d", (unsigned int)(v9 % 12 + 1), 0LL);
}
while ( v8 != 24 );
if ( !EVENT )
EVENT = find_event(SEL);
v27 = 0;
v11 = EVENTS;
v12 = 0;
v28[0] = 0LL;
v28[1] = 0LL;
v28[2] = 0LL;
v28[3] = 0LL;
v28[4] = 0LL;
do
{
LABEL_23:
v21 = 0;
while ( 1 )
{
v13 = v21;
v14 = v21 + 15;
v21 += 15;
if ( !v11 )
break;
while ( (unsigned int)before(v11 + 32, SEL[0], SEL[1], SEL[2], v12 + v14 / 0x3C, v14 % 0x3C) )
{
if ( (unsigned int)before(v11 + 32, SEL[0], SEL[1], SEL[2], v12, v13)
|| (int)get_mins(v11 + 32, v11 + 56) > 1380 )
{
v11 = *(_QWORD *)(v11 + 88);
if ( !v11 )
break;
}
else
{
v15 = func4(v28, 10, v11, &v27);
v20 = 4 * v12 + (int)v13 / 15 - line;
v25 = (double)v15;
v23 = (double)v27;
v24 = (double)(COLS - 6);
v22 = (int)(((double)v15 + 0.0) * v24 / (double)v27 + 0.5);
v16 = get_mins(v11 + 32, v11 + 56);
event_box(
body,
v11,
v20,
(unsigned int)(v22 + 1),
(unsigned int)((v16 - 1) / 15 + 1),
(unsigned int)((int)((v25 + 1.0) * v24 / v23 + 0.5) - v22));
v11 = *(_QWORD *)(v11 + 88);
if ( !v11 )
break;
}
}
if ( v21 == 60 )
goto LABEL_32;
}
v18 = v21;
if ( v21 != 60 )
{
while ( v18 != 45 )
{
v18 += 30;
if ( v18 == 60 )
{
if ( ++v12 != 24 )
goto LABEL_23;
goto LABEL_33;
}
}
}
LABEL_32:
++v12;
}
while ( v12 != 24 );
LABEL_33:
if ( !COMPACT )
{
if ( wmove(win, 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
if ( !COMPACT && v26 && wmove(win, v26 + 1, 0) != -1 )
whline(win, HIDWORD(acs_map[56]), COLS);
}
result = wmove(body, 0, 0);
if ( result != -1 )
result = wvline(body, LODWORD(acs_map[60]), LINES + 2 * COMPACT - 4);
return result;
}

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

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

variable_types:
mstr
char *

variable_types:
dstr
char *

variable_types: y int

variable_types: allday int

variable_types: h int

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

variable_types: ncols int

variable_types: m int

variable_types: col int

variable_types: left int

variable_types: right int

variable_types: row int

variable_types: height 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 day_run(int a1)
{
int v1; // eax
int v2; // eax
__int64 result; // rax
int v4; // edi
unsigned int v5; // esi

if ( a1 > 111 )
return 0LL;
if ( a1 > 103 )
{
switch ( a1 )
{
case 'h':
v4 = 0;
v5 = -1;
break;
case 'i':
v4 = 0;
v5 = -7;
break;
case 'j':
v4 = 1;
v5 = 0;
break;
case 'k':
v4 = -1;
v5 = 0;
break;
case 'l':
v4 = 0;
v5 = 1;
break;
case 'o':
v4 = 0;
v5 = 7;
break;
default:
goto LABEL_17;
}
move_event(v4, v5, &line);
LABEL_12:
werase(win);
day_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 func9(int a1)
{
int v1; // eax
int v2; // eax
__int64 result; // rax
int v4; // edi
unsigned int v5; // esi

if ( a1 > 111 )
return 0LL;
if ( a1 > 103 )
{
switch ( a1 )
{
case 'h':
v4 = 0;
v5 = -1;
break;
case 'i':
v4 = 0;
v5 = -7;
break;
case 'j':
v4 = 1;
v5 = 0;
break;
case 'k':
v4 = -1;
v5 = 0;
break;
case 'l':
v4 = 0;
v5 = 1;
break;
case 'o':
v4 = 0;
v5 = 7;
break;
default:
goto LABEL_17;
}
func5(v4, v5, &line);
LABEL_12:
werase(win);
func8();
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 day_run(int key, mmask_t btn, int row, int col)
{
 int days = 0, events = 0, lines = 0;
 switch (key) {
  case 'h': days = -1; break;
  case 'l': days = 1; break;
  case 'i': days = -7; break;
  case 'o': days = 7; break;
  case 'k': events = -1; break;
  case 'j': events = 1; break;
  case '\031': lines = -1; break;
  case '\005': lines = 1; break;
  case '\012': view_edit(EDIT_EVENT); return 1;
  default: return 0;
 }
 if (lines)
  line = ((((line+lines) > (0) ? (line+lines) : (0))) < (24*4) ? (((line+lines) > (0) ? (line+lines) : (0))) : (24*4));
 if (days || events)
  move_event(events, days, &line);
 werase(win);
 day_draw();
 wrefresh(win);
 return 1;
}

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

variable_types: key int

variable_types:
btn
unsigned int

variable_types: days int

variable_types: events int

variable_types: lines int

return_type: int


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

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

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

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

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

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


strsub

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( a2 == (_BYTE)result )
*a1 = a3;
++a1;
}
return result;
}

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

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( a2 == (_BYTE)result )
*a1 = a3;
++a1;
}
return result;
}

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

variable_types:
str
char *

variable_types: find char

variable_types: repl char

variable_types:
cur
char *


strcopy

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

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

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

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

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

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

return_type: char *


match

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

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

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

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

variable_types:
a
char *

variable_types:
b
char *


debug

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

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

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

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

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

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

variable_types:
fmt
char *


error

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

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

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

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

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

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


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

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

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

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

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

variable_types: size int

variable_types:
data
void *

return_type: void *


decompiled_code:
void todo_size()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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

variable_types: rows int

variable_types: cols int


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

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

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

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

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

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

variable_types: row int


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

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

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

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

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

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

variable_types: key int

variable_types: col int

variable_types: scroll int

variable_types: move int

variable_types: ref int

variable_types: extra int

variable_types: next int

variable_types: ymax int


repo: AnthonyDiGirolamo/gdbase

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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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


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

if ( a1 && *(_DWORD *)(a1 + 12) >= a2 && a2 >= 0 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
else
result = 0LL;
return result;
}

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

if ( a1 && *(_DWORD *)(a1 + 12) >= a2 && a2 >= 0 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
else
result = 0LL;
return result;
}

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

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

variable_types: index int


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

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

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

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

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

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

variable_types:
item
void *


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

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

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

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

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

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


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

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


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

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

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

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

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

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

variable_types: i int


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


main

canonical_name: main

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

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

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

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

variable_types: argc int

variable_types:
argv
char **

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

variable_types: c char


printArray

repo: AntonioCS/challenges

decompiled_code:
int __fastcall printArray(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

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

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, int a2)
{
__int64 v2; // rbp
unsigned int *v3; // rbx
__int64 v4; // rsi

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

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

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

variable_types:
a
int []

variable_types: size int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rsp
__int64 v4; // rdx
_BYTE v6[3]; // [rsp+0h] [rbp-30h] BYREF
char v7; // [rsp+3h] [rbp-2Dh] BYREF
int v8; // [rsp+Ch] [rbp-24h]

v8 = 0;
__isoc99_scanf();
v3 = alloca(0LL);
*(_DWORD *)(4 * ((unsigned __int64)&v7 >> 2)) = *(_DWORD *)&v6[-4];
printArray(v6, 0LL, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rsp
__int64 v4; // rdx
_BYTE v6[3]; // [rsp+0h] [rbp-30h] BYREF
char v7; // [rsp+3h] [rbp-2Dh] BYREF
int v8; // [rsp+Ch] [rbp-24h]

v8 = 0;
__isoc99_scanf();
v3 = alloca(0LL);
*(_DWORD *)(4 * ((unsigned __int64)&v7 >> 2)) = *(_DWORD *)&v6[-4];
func7(v6, 0LL, v4);
return 0;
}

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

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

variable_types: sizeOfArray int

variable_types:
array
int [-1]

variable_types: tmp int

variable_types: tm int


repo: ArchAssault-Project/hydra

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

variable_types:
buf
char *

variable_types: len int

variable_types: pos int

variable_types: key int

variable_types: k int


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

*(_WORD *)(a1 + 2) = a2;
*(_WORD *)a1 = 2;
result = (unsigned __int16)seq;
*(_DWORD *)(a1 + 6) = a3;
++seq;
*(_WORD *)(a1 + 4) = result;
return result;
}

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

*(_WORD *)(a1 + 2) = a2;
*(_WORD *)a1 = 2;
result = (unsigned __int16)seq;
*(_DWORD *)(a1 + 6) = a3;
++seq;
*(_WORD *)(a1 + 4) = result;
return result;
}

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

variable_types:
cmd
unsigned short

variable_types:
uin
unsigned long


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

variable_types: s int

variable_types:
login
char *

variable_types:
pass
char *

variable_types:
buf
char [256]


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

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

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

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

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

variable_types:
buf
char [64]


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


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

v2 = strtoul(a2, 0LL, 10);
v4 = 655362;
v5 = seq;
v6 = v2;
return hydra_send(a1, &v4, 10LL, 0LL);
}

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

v2 = strtoul(a2, 0LL, 10);
v4 = 655362;
v5 = seq;
v6 = v2;
return hydra_send(a1, &v4, 10LL, 0LL);
}

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


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

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

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

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


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

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

variable_types:
key
unsigned char *

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

variable_types: i int

variable_types:
tk
unsigned char [16]

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


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

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

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


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

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

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

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

variable_types:
text
unsigned char *


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

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

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

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

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

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

variable_types:
digest
unsigned char *

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


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

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

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

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

variable_types:
key
unsigned char [16]

variable_types:
data
unsigned char *

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


vncEncryptBytes

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

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

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

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

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

variable_types:
bytes
unsigned char *

variable_types:
passwd
char *

variable_types:
key
unsigned char [8]


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

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

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


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

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

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


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

LOBYTE(v4) = 6;
v2 = strlen(a2);
HIBYTE(v4) = v2;
memcpy(dest, a2, v2 + 1);
return hydra_send(a1, &v4, (unsigned int)(v2 + 2), 0LL);
}

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

LOBYTE(v4) = 6;
v2 = strlen(a2);
HIBYTE(v4) = v2;
memcpy(dest, a2, v2 + 1);
return hydra_send(a1, &v4, (unsigned int)(v2 + 2), 0LL);
}

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

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

variable_types: s int

variable_types:
bptr
char *

variable_types:
clientcryptheader
char []


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

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

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

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

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

variable_types:
buffer
char *

variable_types: size int


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

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

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

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

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

variable_types:
buf
char *

variable_types: pos int


decompiled_code:
int __fastcall print_encrypted_str(char *s)
{
size_t v1; // rbx
__int64 v2; // rsi

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

canonical_decompiled_code:
int __fastcall func3(char *s)
{
size_t v1; // rbx
__int64 v2; // rsi

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

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

variable_types:
str
char *

variable_types: i int


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

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

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

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

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

variable_types:
cleartxt
char *

variable_types:
passwd
char [128]


decompiled_code:
char *__fastcall pca_decrypt(char *dest)
{
char *result; // rax
size_t v2; // rbx
size_t v3; // rax
char v4[152]; // [rsp+0h] [rbp-98h] BYREF

result = (char *)(unsigned __int8)*dest;
if ( (_BYTE)result )
{
v2 = 0LL;
v4[0] = (unsigned __int8)result ^ 0xAB;
while ( 1 )
{
++v2;
v3 = strlen(dest);
if ( v3 <= v2 )
break;
v4[v2] = (v2 - 1) ^ dest[v2] ^ dest[v2 - 1];
}
v4[v3] = 0;
result = strcpy(dest, v4);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *dest)
{
char *result; // rax
size_t v2; // rbx
size_t v3; // rax
char v4[152]; // [rsp+0h] [rbp-98h] BYREF

result = (char *)(unsigned __int8)*dest;
if ( (_BYTE)result )
{
v2 = 0LL;
v4[0] = (unsigned __int8)result ^ 0xAB;
while ( 1 )
{
++v2;
v3 = strlen(dest);
if ( v3 <= v2 )
break;
v4[v2] = (v2 - 1) ^ dest[v2] ^ dest[v2 - 1];
}
v4[v3] = 0;
result = strcpy(dest, v4);
}
return result;
}

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

variable_types:
password
char *

variable_types:
cleartext
char [128]


debugprintf

decompiled_code:
int __fastcall debugprintf(const char *a1)
{
int result; // eax

result = pcadebug;
if ( pcadebug )
result = printf("debug: %s\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
int result; // eax

result = pcadebug;
if ( pcadebug )
result = printf("debug: %s\n", a1);
return result;
}

original_code:
void debugprintf(char *msg) {
  if (pcadebug)
    printf("debug: %s\n", msg);
}

variable_types:
msg
char *


decompiled_code:
int __fastcall empty_register(char *s, const char *a2, const char *a3, __int64 a4, unsigned int a5, const char *a6)
{
*(_QWORD *)s = 0LL;
*((_QWORD *)s + 127) = 0LL;
memset(
(void *)((unsigned __int64)(s + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)s - (((_DWORD)s + 8) & 0xFFFFFFF8) + 1024) >> 3));
return snprintf(
s,
0x400uLL,
"REGISTER sip:%s SIP/2.0\r\n"
"Via: SIP/2.0/UDP %s:%i\r\n"
"From: <sip:%s@%s>\r\n"
"To: <sip:%s@%s>\r\n"
"Call-ID: 1337@%s\r\n"
"CSeq: %i REGISTER\r\n"
"Content-Length: 0\r\n"
"\r\n",
a2,
a3,
a5,
a6,
a2,
a6,
a2,
a2,
(unsigned int)cseq);
}

canonical_decompiled_code:
int __fastcall func1(char *s, const char *a2, const char *a3, __int64 a4, unsigned int a5, const char *a6)
{
*(_QWORD *)s = 0LL;
*((_QWORD *)s + 127) = 0LL;
memset(
(void *)((unsigned __int64)(s + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)s - (((_DWORD)s + 8) & 0xFFFFFFF8) + 1024) >> 3));
return snprintf(
s,
0x400uLL,
"REGISTER sip:%s SIP/2.0\r\n"
"Via: SIP/2.0/UDP %s:%i\r\n"
"From: <sip:%s@%s>\r\n"
"To: <sip:%s@%s>\r\n"
"Call-ID: 1337@%s\r\n"
"CSeq: %i REGISTER\r\n"
"Content-Length: 0\r\n"
"\r\n",
a2,
a3,
a5,
a6,
a2,
a6,
a2,
a2,
(unsigned int)cseq);
}

original_code:
void empty_register(char *buf, char *host, char *lhost, int port, int lport, char *user) {
  memset(buf, 0, 1024);
  snprintf(buf, 1024,
           "REGISTER sip:%s SIP/2.0\r\n"
           "Via: SIP/2.0/UDP %s:%i\r\n"
           "From: <sip:%s@%s>\r\n"
           "To: <sip:%s@%s>\r\n" "Call-ID: 1337@%s\r\n" "CSeq: %i REGISTER\r\n" "Content-Length: 0\r\n\r\n", host, lhost, lport, user, host, user, host, host, cseq);
}

variable_types:
host
char *

variable_types:
lhost
char *

variable_types: port int

variable_types: lport int

variable_types:
user
char *


decompiled_code:
__int64 __fastcall get_sip_code(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-80Ch] BYREF
char v3; // [rsp+10h] [rbp-808h] BYREF
char v4; // [rsp+410h] [rbp-408h] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "%s %i %s", &v3, &v2, &v4) == 3 )
result = v2;
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // [rsp+Ch] [rbp-80Ch] BYREF
char v3; // [rsp+10h] [rbp-808h] BYREF
char v4; // [rsp+410h] [rbp-408h] BYREF

if ( (unsigned int)_isoc99_sscanf(a1, "%s %i %s", &v3, &v2, &v4) == 3 )
result = v2;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int get_sip_code(char *buf) {
  int code;
  char tmpbuf[1024], word[1024];
  if (sscanf(buf, "%s %i %s", tmpbuf, &code, word) != 3)
    return -1;
  return code;
}

canonical_original_code:
int get_sip_code(char *buf) {
  int code;
  char tmpbuf[1024]; char word[1024];
  if (sscanf(buf, "%s %i %s", tmpbuf, &code, word) != 3)
    return -1;
  return code;
}

variable_types: code int

variable_types:
tmpbuf
char [1024]

variable_types:
word
char [1024]


decompiled_code:
const char *__fastcall get_iface_ip(int a1)
{
__int64 v1; // r12
__int16 v2; // ax
socklen_t v3; // edx
struct sockaddr *v4; // rbp
const char *v5; // r12
size_t v6; // rax
unsigned int v7; // ebx
char *v8; // rax
__int64 v9; // rax
unsigned int v10; // ebx
unsigned int v11; // ebx
unsigned int v12; // eax
__int64 v13; // rdx
const char *result; // rax
socklen_t len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr v16; // [rsp+10h] [rbp-48h] BYREF
char buf[8]; // [rsp+20h] [rbp-38h] BYREF

v1 = (unsigned int)socket(2, 2, 0);
v16.sa_family = 2;
v2 = _bswap_16_constprop_0(v1, &v16, 16LL);
*(_DWORD *)&v16.sa_data[2] = a1;
*(_WORD *)v16.sa_data = v2;
if ( connect(v1, &v16, v3) )
{
perror("connect");
close(v1);
result = 0LL;
}
else
{
len = 16;
v4 = (struct sockaddr *)malloc(0x10uLL);
if ( getsockname(v1, v4, &len) )
{
perror("getsockname");
close(v1);
free(v4);
result = 0LL;
}
else
{
close(v1);
v5 = inet_ntop(2, &v4->sa_data[2], buf, 0x20u);
if ( v5 )
{
v6 = strlen(buf);
v7 = v6 + 1;
v8 = (char *)malloc(v6 + 1);
v5 = v8;
if ( v7 < 8 )
{
if ( (v7 & 4) != 0 )
{
*(_DWORD *)v8 = *(_DWORD *)buf;
*(_DWORD *)&v8[v7 - 4] = *(_DWORD *)&v16.sa_data[v7 + 10];
}
else if ( v7 )
{
*v8 = buf[0];
if ( (v7 & 2) != 0 )
*(_WORD *)&v8[v7 - 2] = *(_WORD *)&v16.sa_data[v7 + 12];
}
}
else
{
v9 = v7;
v10 = v7 - 1;
*(_QWORD *)&v5[v9 - 8] = *(_QWORD *)&v16.sa_data[v9 + 6];
if ( v10 >= 8 )
{
v11 = v10 & 0xFFFFFFF8;
v12 = 0;
do
{
v13 = v12;
v12 += 8;
*(_QWORD *)&v5[v13] = *(_QWORD *)&buf[v13];
}
while ( v12 < v11 );
}
}
free(v4);
}
else
{
perror("inet_ntop");
free(v4);
}
result = v5;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(int a1)
{
__int64 v1; // r12
__int16 v2; // ax
socklen_t v3; // edx
struct sockaddr *v4; // rbp
const char *v5; // r12
size_t v6; // rax
unsigned int v7; // ebx
char *v8; // rax
__int64 v9; // rax
unsigned int v10; // ebx
unsigned int v11; // ebx
unsigned int v12; // eax
__int64 v13; // rdx
const char *result; // rax
socklen_t len; // [rsp+Ch] [rbp-4Ch] BYREF
struct sockaddr v16; // [rsp+10h] [rbp-48h] BYREF
char buf[8]; // [rsp+20h] [rbp-38h] BYREF

v1 = (unsigned int)socket(2, 2, 0);
v16.sa_family = 2;
v2 = func0(v1, &v16, 16LL);
*(_DWORD *)&v16.sa_data[2] = a1;
*(_WORD *)v16.sa_data = v2;
if ( connect(v1, &v16, v3) )
{
perror("connect");
close(v1);
result = 0LL;
}
else
{
len = 16;
v4 = (struct sockaddr *)malloc(0x10uLL);
if ( getsockname(v1, v4, &len) )
{
perror("getsockname");
close(v1);
free(v4);
result = 0LL;
}
else
{
close(v1);
v5 = inet_ntop(2, &v4->sa_data[2], buf, 0x20u);
if ( v5 )
{
v6 = strlen(buf);
v7 = v6 + 1;
v8 = (char *)malloc(v6 + 1);
v5 = v8;
if ( v7 < 8 )
{
if ( (v7 & 4) != 0 )
{
*(_DWORD *)v8 = *(_DWORD *)buf;
*(_DWORD *)&v8[v7 - 4] = *(_DWORD *)&v16.sa_data[v7 + 10];
}
else if ( v7 )
{
*v8 = buf[0];
if ( (v7 & 2) != 0 )
*(_WORD *)&v8[v7 - 2] = *(_WORD *)&v16.sa_data[v7 + 12];
}
}
else
{
v9 = v7;
v10 = v7 - 1;
*(_QWORD *)&v5[v9 - 8] = *(_QWORD *)&v16.sa_data[v9 + 6];
if ( v10 >= 8 )
{
v11 = v10 & 0xFFFFFFF8;
v12 = 0;
do
{
v13 = v12;
v12 += 8;
*(_QWORD *)&v5[v13] = *(_QWORD *)&buf[v13];
}
while ( v12 < v11 );
}
}
free(v4);
}
else
{
perror("inet_ntop");
free(v4);
}
result = v5;
}
}
return result;
}

original_code:
char *get_iface_ip(unsigned long int ip) {
  int sfd;
  sfd = socket(2, SOCK_DGRAM, 0);
  struct sockaddr_in tparamet;
  tparamet.sin_family = 2;
  tparamet.sin_port = htons(2000);
  tparamet.sin_addr.s_addr = ip;
  if (connect(sfd, (const struct sockaddr *) &tparamet, sizeof(struct sockaddr_in))) {
    perror("connect");
    close(sfd);
    return ((void *)0);
  }
  struct sockaddr_in *local = malloc(sizeof(struct sockaddr_in));
  int size = sizeof(struct sockaddr_in);
  if (getsockname(sfd, (void *) local, (socklen_t *) & size)) {
    perror("getsockname");
    close(sfd);
    free(local);
    return ((void *)0);
  }
  close(sfd);
  char buff[32];
  if (!inet_ntop(2, (void *) &local->sin_addr, buff, 32)) {
    perror("inet_ntop");
    free(local);
    return ((void *)0);
  }
  char *str = malloc(sizeof(char) * (strlen(buff) + 1));
  strcpy(str, buff);
  free(local);
  return str;
}

canonical_original_code:
char *get_iface_ip(unsigned long ip) {
  int sfd;
  sfd = socket(2, SOCK_DGRAM, 0);
  struct sockaddr_in tparamet;
  tparamet.sin_family = 2;
  tparamet.sin_port = htons(2000);
  tparamet.sin_addr.s_addr = ip;
  if (connect(sfd, (struct sockaddr *) &tparamet, sizeof(struct sockaddr_in))) {
    perror("connect");
    close(sfd);
    return ((void *)0);
  }
  struct sockaddr_in *local = malloc(sizeof(struct sockaddr_in));
  int size = sizeof(struct sockaddr_in);
  if (getsockname(sfd, (void *) local, (unsigned int *) & size)) {
    perror("getsockname");
    close(sfd);
    free(local);
    return ((void *)0);
  }
  close(sfd);
  char buff[32];
  if (!inet_ntop(2, (void *) &local->sin_addr, buff, 32)) {
    perror("inet_ntop");
    free(local);
    return ((void *)0);
  }
  char *str = malloc(sizeof(char) * (strlen(buff) + 1));
  strcpy(str, buff);
  free(local);
  return str;
}

variable_types:
ip
unsigned long

variable_types: sfd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: size int

variable_types:
buff
char [32]

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }