crashdmesg

decompiled_code:
__int64 __fastcall crashdmesg(__int64 a1)
{
unsigned int v2; // er15
struct tm *v3; // rax
__int64 v4; // rcx
int v5; // eax
char *v6; // r12
unsigned int v7; // er13
__int64 v8; // rbx
__int64 v9; // r13
char *v10; // r13
char *v11; // rbx
int v12; // edi
char *v14; // rbx
int v15; // edi
unsigned int v16; // [rsp+8h] [rbp-130h]
time_t timer; // [rsp+18h] [rbp-120h] BYREF
__int64 v18; // [rsp+20h] [rbp-118h] BYREF
__int64 v19; // [rsp+28h] [rbp-110h] BYREF
__int64 v20; // [rsp+30h] [rbp-108h] BYREF
__int64 v21; // [rsp+38h] [rbp-100h] BYREF
__int64 v22; // [rsp+40h] [rbp-F8h] BYREF
__int64 v23; // [rsp+48h] [rbp-F0h] BYREF
__m128i v24; // [rsp+50h] [rbp-E8h] BYREF
int v25; // [rsp+60h] [rbp-D8h]
__int128 v26[3]; // [rsp+70h] [rbp-C8h] BYREF
__int64 v27; // [rsp+A0h] [rbp-98h]
__int128 v28[4]; // [rsp+B0h] [rbp-88h] BYREF
char v29; // [rsp+F0h] [rbp-48h]

v25 = 3827571;
v24 = _mm_load_si128((const __m128i *)&LC50);
v27 = 0LL;
v29 = 0;
timer = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v26[0] = 0LL;
v26[1] = 0LL;
v26[2] = 0LL;
v28[0] = 0LL;
v28[1] = 0LL;
v28[2] = 0LL;
v28[3] = 0LL;
fprintf(stdout, "%s: Validate vmcore ELF binary header.\n", "crashdmesg");
if ( (unsigned int)file_open(a1) )
{
v2 = 1;
fprintf(stderr, "%s Can not open vmcore file.\n", v24.m128i_i8);
return v2;
}
if ( (unsigned int)elf_validate_elfheader(a1) )
{
fprintf(stderr, "%s Failed to validate vmcore file.\n", v24.m128i_i8);
LABEL_28:
v2 = 1;
file_close(a1);
return v2;
}
fprintf(stdout, "%s: Read VMCOREINFO from NOTE segment.\n", "crashdmesg");
if ( (unsigned int)elf_read_vmcoreinfo(a1) )
{
fprintf(stderr, "%s Can not read VMCOREINFO.\n", v24.m128i_i8);
goto LABEL_28;
}
if ( (unsigned int)elf_read_osrelease(a1, v28, 65LL) )
{
fprintf(stderr, "%s Can not read OSRELEASE.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * OS Release: %s\n", "crashdmesg", (const char *)v28);
v2 = elf_read_crashtime(a1, &timer);
if ( v2 )
{
fprintf(stderr, "%s Can not read CRASHTIME.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * Crash Time: %ld,\n", "crashdmesg", timer);
v3 = localtime(&timer);
if ( !v3 )
{
v2 = 1;
fprintf(stderr, "%s localtime failed.\n", v24.m128i_i8);
return v2;
}
fprintf(
stdout,
"%s: %04d/%02d/%02d %02d:%02d:%02d\n",
"crashdmesg",
(unsigned int)(v3->tm_year + 1900),
(unsigned int)(v3->tm_mon + 1),
(unsigned int)v3->tm_mday,
(unsigned int)v3->tm_hour,
(unsigned int)v3->tm_min,
(unsigned int)v3->tm_sec);
fprintf(stdout, "%s: Read Symbol from VMCOREINFO.\n", "crashdmesg");
elf_search_vmcoreinfo_symbol(a1, "log_buf", &v18);
elf_search_vmcoreinfo_symbol(a1, "log_end", &v19);
elf_search_vmcoreinfo_symbol(a1, "log_buf_len", &v20);
elf_search_vmcoreinfo_symbol(a1, "logged_chars", &v21);
if ( !v18 || !v19 || !v20 || !v21 )
{
fprintf(stderr, "%s Can not read Symbol from VMCOREINFO.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * log_buf: 0x%016lx\n", "crashdmesg", v18);
fprintf(stdout, "%s: * log_end: 0x%016lx\n", "crashdmesg", v19);
fprintf(stdout, "%s: * log_buf_len: 0x%016lx\n", "crashdmesg", v20);
fprintf(stdout, "%s: * logged_chars: 0x%016lx\n", "crashdmesg", v21);
fprintf(stdout, "%s: Read LOAD section about Ring buffer..\n", "crashdmesg");
elf_read_load_uint64(a1, v26, v18, a1 + 4728);
elf_read_load_uint32(a1, v26, v19, a1 + 4736);
elf_read_load_int32(a1, v26, v20, a1 + 4740);
elf_read_load_uint32(a1, v26, v21, a1 + 4744);
v4 = *(_QWORD *)(a1 + 4728);
if ( !v4 || !*(_DWORD *)(a1 + 4736) || !*(_DWORD *)(a1 + 4740) || !*(_DWORD *)(a1 + 4744) )
{
fprintf(stderr, "%s Can not read value from LOAD segment.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * log_buf: 0x%016lx\n", "crashdmesg", v4);
fprintf(stdout, "%s: * log_end: 0x%08x\n", "crashdmesg", *(unsigned int *)(a1 + 4736));
fprintf(stdout, "%s: * log_buf_len: 0x%08x\n", "crashdmesg", *(unsigned int *)(a1 + 4740));
fprintf(stdout, "%s: * logged_chars: 0x%08x\n", "crashdmesg", *(unsigned int *)(a1 + 4744));
v5 = *(_DWORD *)(a1 + 4740);
if ( v5 > 0x100000 )
{
fprintf(stderr, "%s log_buf_len is too big.\n", v24.m128i_i8);
goto LABEL_28;
}
v6 = (char *)calloc(v5, 1uLL);
if ( !v6 )
{
fprintf(stderr, "%s Can not allocate memory.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: Calculating dump area address.\n", "crashdmesg");
v7 = *(_DWORD *)(a1 + 4744);
v8 = *(unsigned int *)(a1 + 4740);
if ( v7 < (unsigned int)v8 )
{
if ( !(unsigned int)elf_search_load_data(a1, v26, *(_QWORD *)(a1 + 4728), v7, &v22) )
{
fprintf(stdout, "%s: Ring buffer Part: 1/1\n", "crashdmesg");
fprintf(stdout, "%s: * File Offset: 0x%016lx\n", "crashdmesg", v22);
fprintf(stdout, "%s: * Size: 0x%08x\n", "crashdmesg", v7);
if ( !(unsigned int)file_read(a1, v6, v22, v7) )
{
v14 = v6;
fprintf(stdout, "%s: Dump ring buffer.\n", "crashdmesg");
fwrite(">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n", 1uLL, 0x38uLL, stdout);
while ( v14 != &v6[v7] )
{
v15 = *v14++;
fputc(v15, stdout);
}
goto LABEL_26;
}
goto LABEL_47;
}
goto LABEL_38;
}
if ( (unsigned int)v8 > 0x100000 )
{
fprintf(stderr, "%s Dump area size calculation failed.\n", v24.m128i_i8);
goto LABEL_39;
}
v16 = (v8 - 1) & *(_DWORD *)(a1 + 4736);
v9 = (unsigned int)v8 - v16;
if ( (unsigned int)elf_search_load_data(a1, v26, v16 + *(_QWORD *)(a1 + 4728), v9, &v22)
|| (unsigned int)elf_search_load_data(a1, v26, *(_QWORD *)(a1 + 4728), v16, &v23) )
{
LABEL_38:
fprintf(stderr, "%s Ring buffer not found in vmcore.\n", v24.m128i_i8);
LABEL_39:
free(v6);
goto LABEL_28;
}
fprintf(stdout, "%s: Ring buffer Part: 1/2\n", "crashdmesg");
fprintf(stdout, "%s: * File Offset: 0x%016lx\n", "crashdmesg", v22);
fprintf(stdout, "%s: * Size: 0x%08x\n", "crashdmesg", (unsigned int)v8 - v16);
fprintf(stdout, "%s: Ring buffer Part: 2/2\n", "crashdmesg");
fprintf(stdout, "%s: * File Offset: 0x%016lx\n", "crashdmesg", v23);
fprintf(stdout, "%s: * Size: 0x%08x\n", "crashdmesg", v16);
if ( (unsigned int)file_read(a1, v6, v22, v9) || (unsigned int)file_read(a1, &v6[v9], v23, v16) )
{
LABEL_47:
fprintf(stderr, "%s Can not read ring buffer.\n", v24.m128i_i8);
goto LABEL_39;
}
v10 = v6;
v11 = &v6[v8];
fprintf(stdout, "%s: Dump ring buffer.\n", "crashdmesg");
fwrite(">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n", 1uLL, 0x38uLL, stdout);
while ( v10 != v11 )
{
v12 = *v10++;
fputc(v12, stdout);
}
LABEL_26:
fwrite("<<<<<<<<<<[ END kernel ring buffer ]<<<<<<<<<<<<<<<<<\n", 1uLL, 0x38uLL, stdout);
fprintf(stdout, "%s: Dump complete.\n", "crashdmesg");
free(v6);
file_close(a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v2; // er15
struct tm *v3; // rax
__int64 v4; // rcx
int v5; // eax
char *v6; // r12
unsigned int v7; // er13
__int64 v8; // rbx
__int64 v9; // r13
char *v10; // r13
char *v11; // rbx
int v12; // edi
char *v14; // rbx
int v15; // edi
unsigned int v16; // [rsp+8h] [rbp-130h]
time_t timer; // [rsp+18h] [rbp-120h] BYREF
__int64 v18; // [rsp+20h] [rbp-118h] BYREF
__int64 v19; // [rsp+28h] [rbp-110h] BYREF
__int64 v20; // [rsp+30h] [rbp-108h] BYREF
__int64 v21; // [rsp+38h] [rbp-100h] BYREF
__int64 v22; // [rsp+40h] [rbp-F8h] BYREF
__int64 v23; // [rsp+48h] [rbp-F0h] BYREF
__m128i v24; // [rsp+50h] [rbp-E8h] BYREF
int v25; // [rsp+60h] [rbp-D8h]
__int128 v26[3]; // [rsp+70h] [rbp-C8h] BYREF
__int64 v27; // [rsp+A0h] [rbp-98h]
__int128 v28[4]; // [rsp+B0h] [rbp-88h] BYREF
char v29; // [rsp+F0h] [rbp-48h]

v25 = 3827571;
v24 = _mm_load_si128((const __m128i *)&LC50);
v27 = 0LL;
v29 = 0;
timer = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v26[0] = 0LL;
v26[1] = 0LL;
v26[2] = 0LL;
v28[0] = 0LL;
v28[1] = 0LL;
v28[2] = 0LL;
v28[3] = 0LL;
fprintf(stdout, "%s: Validate vmcore ELF binary header.\n", "crashdmesg");
if ( (unsigned int)file_open(a1) )
{
v2 = 1;
fprintf(stderr, "%s Can not open vmcore file.\n", v24.m128i_i8);
return v2;
}
if ( (unsigned int)elf_validate_elfheader(a1) )
{
fprintf(stderr, "%s Failed to validate vmcore file.\n", v24.m128i_i8);
LABEL_28:
v2 = 1;
file_close(a1);
return v2;
}
fprintf(stdout, "%s: Read VMCOREINFO from NOTE segment.\n", "crashdmesg");
if ( (unsigned int)elf_read_vmcoreinfo(a1) )
{
fprintf(stderr, "%s Can not read VMCOREINFO.\n", v24.m128i_i8);
goto LABEL_28;
}
if ( (unsigned int)elf_read_osrelease(a1, v28, 65LL) )
{
fprintf(stderr, "%s Can not read OSRELEASE.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * OS Release: %s\n", "crashdmesg", (const char *)v28);
v2 = elf_read_crashtime(a1, &timer);
if ( v2 )
{
fprintf(stderr, "%s Can not read CRASHTIME.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * Crash Time: %ld,\n", "crashdmesg", timer);
v3 = localtime(&timer);
if ( !v3 )
{
v2 = 1;
fprintf(stderr, "%s localtime failed.\n", v24.m128i_i8);
return v2;
}
fprintf(
stdout,
"%s: %04d/%02d/%02d %02d:%02d:%02d\n",
"crashdmesg",
(unsigned int)(v3->tm_year + 1900),
(unsigned int)(v3->tm_mon + 1),
(unsigned int)v3->tm_mday,
(unsigned int)v3->tm_hour,
(unsigned int)v3->tm_min,
(unsigned int)v3->tm_sec);
fprintf(stdout, "%s: Read Symbol from VMCOREINFO.\n", "crashdmesg");
elf_search_vmcoreinfo_symbol(a1, "log_buf", &v18);
elf_search_vmcoreinfo_symbol(a1, "log_end", &v19);
elf_search_vmcoreinfo_symbol(a1, "log_buf_len", &v20);
elf_search_vmcoreinfo_symbol(a1, "logged_chars", &v21);
if ( !v18 || !v19 || !v20 || !v21 )
{
fprintf(stderr, "%s Can not read Symbol from VMCOREINFO.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * log_buf: 0x%016lx\n", "crashdmesg", v18);
fprintf(stdout, "%s: * log_end: 0x%016lx\n", "crashdmesg", v19);
fprintf(stdout, "%s: * log_buf_len: 0x%016lx\n", "crashdmesg", v20);
fprintf(stdout, "%s: * logged_chars: 0x%016lx\n", "crashdmesg", v21);
fprintf(stdout, "%s: Read LOAD section about Ring buffer..\n", "crashdmesg");
elf_read_load_uint64(a1, v26, v18, a1 + 4728);
elf_read_load_uint32(a1, v26, v19, a1 + 4736);
elf_read_load_int32(a1, v26, v20, a1 + 4740);
elf_read_load_uint32(a1, v26, v21, a1 + 4744);
v4 = *(_QWORD *)(a1 + 4728);
if ( !v4 || !*(_DWORD *)(a1 + 4736) || !*(_DWORD *)(a1 + 4740) || !*(_DWORD *)(a1 + 4744) )
{
fprintf(stderr, "%s Can not read value from LOAD segment.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: * log_buf: 0x%016lx\n", "crashdmesg", v4);
fprintf(stdout, "%s: * log_end: 0x%08x\n", "crashdmesg", *(unsigned int *)(a1 + 4736));
fprintf(stdout, "%s: * log_buf_len: 0x%08x\n", "crashdmesg", *(unsigned int *)(a1 + 4740));
fprintf(stdout, "%s: * logged_chars: 0x%08x\n", "crashdmesg", *(unsigned int *)(a1 + 4744));
v5 = *(_DWORD *)(a1 + 4740);
if ( v5 > 0x100000 )
{
fprintf(stderr, "%s log_buf_len is too big.\n", v24.m128i_i8);
goto LABEL_28;
}
v6 = (char *)calloc(v5, 1uLL);
if ( !v6 )
{
fprintf(stderr, "%s Can not allocate memory.\n", v24.m128i_i8);
goto LABEL_28;
}
fprintf(stdout, "%s: Calculating dump area address.\n", "crashdmesg");
v7 = *(_DWORD *)(a1 + 4744);
v8 = *(unsigned int *)(a1 + 4740);
if ( v7 < (unsigned int)v8 )
{
if ( !(unsigned int)elf_search_load_data(a1, v26, *(_QWORD *)(a1 + 4728), v7, &v22) )
{
fprintf(stdout, "%s: Ring buffer Part: 1/1\n", "crashdmesg");
fprintf(stdout, "%s: * File Offset: 0x%016lx\n", "crashdmesg", v22);
fprintf(stdout, "%s: * Size: 0x%08x\n", "crashdmesg", v7);
if ( !(unsigned int)file_read(a1, v6, v22, v7) )
{
v14 = v6;
fprintf(stdout, "%s: Dump ring buffer.\n", "crashdmesg");
fwrite(">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n", 1uLL, 0x38uLL, stdout);
while ( v14 != &v6[v7] )
{
v15 = *v14++;
fputc(v15, stdout);
}
goto LABEL_26;
}
goto LABEL_47;
}
goto LABEL_38;
}
if ( (unsigned int)v8 > 0x100000 )
{
fprintf(stderr, "%s Dump area size calculation failed.\n", v24.m128i_i8);
goto LABEL_39;
}
v16 = (v8 - 1) & *(_DWORD *)(a1 + 4736);
v9 = (unsigned int)v8 - v16;
if ( (unsigned int)elf_search_load_data(a1, v26, v16 + *(_QWORD *)(a1 + 4728), v9, &v22)
|| (unsigned int)elf_search_load_data(a1, v26, *(_QWORD *)(a1 + 4728), v16, &v23) )
{
LABEL_38:
fprintf(stderr, "%s Ring buffer not found in vmcore.\n", v24.m128i_i8);
LABEL_39:
free(v6);
goto LABEL_28;
}
fprintf(stdout, "%s: Ring buffer Part: 1/2\n", "crashdmesg");
fprintf(stdout, "%s: * File Offset: 0x%016lx\n", "crashdmesg", v22);
fprintf(stdout, "%s: * Size: 0x%08x\n", "crashdmesg", (unsigned int)v8 - v16);
fprintf(stdout, "%s: Ring buffer Part: 2/2\n", "crashdmesg");
fprintf(stdout, "%s: * File Offset: 0x%016lx\n", "crashdmesg", v23);
fprintf(stdout, "%s: * Size: 0x%08x\n", "crashdmesg", v16);
if ( (unsigned int)file_read(a1, v6, v22, v9) || (unsigned int)file_read(a1, &v6[v9], v23, v16) )
{
LABEL_47:
fprintf(stderr, "%s Can not read ring buffer.\n", v24.m128i_i8);
goto LABEL_39;
}
v10 = v6;
v11 = &v6[v8];
fprintf(stdout, "%s: Dump ring buffer.\n", "crashdmesg");
fwrite(">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n", 1uLL, 0x38uLL, stdout);
while ( v10 != v11 )
{
v12 = *v10++;
fputc(v12, stdout);
}
LABEL_26:
fwrite("<<<<<<<<<<[ END kernel ring buffer ]<<<<<<<<<<<<<<<<<\n", 1uLL, 0x38uLL, stdout);
fprintf(stdout, "%s: Dump complete.\n", "crashdmesg");
free(v6);
file_close(a1);
return v2;
}

original_code:
static int crashdmesg(VMCore *vmcore)
{
 char estr[] = "[ERROR] crashdmesg:";
 int loop = 0;
 Elf64_Phdr phdr_cache;
 memset(&phdr_cache, 0x00, sizeof(Elf64_Phdr));
 char osrelease[65];
 memset(osrelease, 0x00, sizeof(osrelease));
 time_t crashtime = 0;
 struct tm *ct = ((void *)0);
 uint64_t log_buf_vaddr = 0;
 uint64_t log_end_vaddr = 0;
 uint64_t log_buf_len_vaddr = 0;
 uint64_t logged_chars_vaddr = 0;
 off_t ringbuffer1 = 0;
 uint32_t ringbuffer1_size = 0;
 off_t ringbuffer2 = 0;
 uint32_t ringbuffer2_size = 0;
 char *ringbuffer = ((void *)0);
 ((vmcore != ((void *)0)) ? (void) (0) : __assert_fail ("vmcore != NULL", "crashdmesg_main.c", 113, __extension__ __PRETTY_FUNCTION__));
 fprintf(stdout, "%s:  Validate vmcore ELF binary header.\n", "crashdmesg");
 if (file_open(&vmcore->file)) {
  fprintf(stderr, "%s Can not open vmcore file.\n", estr);
  return 1;
 }
 if (elf_validate_elfheader(vmcore)) {
  fprintf(stderr, "%s Failed to validate vmcore file.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:  Read VMCOREINFO from NOTE segment.\n", "crashdmesg");
 if (elf_read_vmcoreinfo(vmcore)) {
  fprintf(stderr, "%s Can not read VMCOREINFO.\n", estr);
  goto ERROR_CLOSE;
 }
 if (elf_read_osrelease(vmcore, osrelease, sizeof(osrelease))) {
  fprintf(stderr, "%s Can not read OSRELEASE.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * OS Release: %s\n", "crashdmesg", osrelease);
 if (elf_read_crashtime(vmcore, &crashtime)) {
  fprintf(stderr, "%s Can not read CRASHTIME.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * Crash Time: %ld,\n", "crashdmesg", crashtime);
 ct = localtime(&crashtime);
 if (ct == ((void *)0)) {
  fprintf(stderr, "%s localtime failed.\n", estr);
  return 1;
 }
 fprintf(stdout, "%s:                  %04d/%02d/%02d %02d:%02d:%02d\n",
         "crashdmesg", ct->tm_year+1900, ct->tm_mon+1, ct->tm_mday,
         ct->tm_hour, ct->tm_min, ct->tm_sec);
 fprintf(stdout, "%s:  Read Symbol from VMCOREINFO.\n", "crashdmesg");
 elf_search_vmcoreinfo_symbol(vmcore, "log_buf", &log_buf_vaddr);
 elf_search_vmcoreinfo_symbol(vmcore, "log_end", &log_end_vaddr);
 elf_search_vmcoreinfo_symbol(vmcore, "log_buf_len", &log_buf_len_vaddr);
 elf_search_vmcoreinfo_symbol(vmcore, "logged_chars", &logged_chars_vaddr);
 if ((! log_buf_vaddr) || (! log_end_vaddr) ||
     (! log_buf_len_vaddr) || (! logged_chars_vaddr)) {
  fprintf(stderr, "%s Can not read Symbol from VMCOREINFO.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * log_buf:      0x%016lx\n",
         "crashdmesg", log_buf_vaddr);
 fprintf(stdout, "%s:    * log_end:      0x%016lx\n",
         "crashdmesg", log_end_vaddr);
 fprintf(stdout, "%s:    * log_buf_len:  0x%016lx\n",
         "crashdmesg", log_buf_len_vaddr);
 fprintf(stdout, "%s:    * logged_chars: 0x%016lx\n",
         "crashdmesg", logged_chars_vaddr);
 fprintf(stdout, "%s:  Read LOAD section about Ring buffer..\n",
         "crashdmesg");
 elf_read_load_uint64(vmcore, &phdr_cache,
                      log_buf_vaddr, &vmcore->log_buf);
 elf_read_load_uint32(vmcore, &phdr_cache,
                      log_end_vaddr, &vmcore->log_end);
 elf_read_load_int32(vmcore, &phdr_cache,
                     log_buf_len_vaddr, &vmcore->log_buf_len);
 elf_read_load_uint32(vmcore, &phdr_cache,
                      logged_chars_vaddr, &vmcore->logged_chars);
 if ((! vmcore->log_buf) || (! vmcore->log_end) ||
     (! vmcore->log_buf_len) || (! vmcore->logged_chars)) {
  fprintf(stderr, "%s Can not read value from LOAD segment.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * log_buf:      0x%016lx\n",
         "crashdmesg", vmcore->log_buf);
 fprintf(stdout, "%s:    * log_end:              0x%08x\n",
         "crashdmesg", vmcore->log_end);
 fprintf(stdout, "%s:    * log_buf_len:          0x%08x\n",
         "crashdmesg", vmcore->log_buf_len);
 fprintf(stdout, "%s:    * logged_chars:         0x%08x\n",
         "crashdmesg", vmcore->logged_chars);
 if (vmcore->log_buf_len > 1048576) {
  fprintf(stderr, "%s log_buf_len is too big.\n", estr);
  goto ERROR_CLOSE;
 }
 ringbuffer = malloc(vmcore->log_buf_len);
 if (ringbuffer == ((void *)0)) {
  fprintf(stderr, "%s Can not allocate memory.\n", estr);
  goto ERROR_CLOSE;
 }
 memset(ringbuffer, 0x00, vmcore->log_buf_len);
 fprintf(stdout, "%s:  Calculating dump area address.\n", "crashdmesg");
 if ( vmcore->logged_chars < vmcore->log_buf_len ) {
  ringbuffer1_size = vmcore->logged_chars;
  if (elf_search_load_data(vmcore, &phdr_cache,
                           vmcore->log_buf, ringbuffer1_size,
                           &ringbuffer1)) {
   fprintf(stderr, "%s Ring buffer not found in vmcore.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:   Ring buffer Part: 1/1\n", "crashdmesg");
  fprintf(stdout, "%s:    * File Offset:  0x%016lx\n",
          "crashdmesg", ringbuffer1);
  fprintf(stdout, "%s:    * Size:                 0x%08x\n",
          "crashdmesg", ringbuffer1_size);
  if (file_read(&vmcore->file, (void*) ringbuffer,
             ringbuffer1, ringbuffer1_size)) {
   fprintf(stderr, "%s Can not read ring buffer.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:  Dump ring buffer.\n", "crashdmesg");
  fprintf(stdout,
          ">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n");
  for (loop = 0; loop < ringbuffer1_size; loop++) {
       fputc(ringbuffer[loop], stdout);
  }
  fprintf(stdout,
          "<<<<<<<<<<[ END kernel ring buffer   ]<<<<<<<<<<<<<<<<<\n");
 }
 else {
  ringbuffer1_size = vmcore->log_buf_len -
                     (vmcore->log_end & (vmcore->log_buf_len-1));
  ringbuffer2_size = vmcore->log_end & (vmcore->log_buf_len-1);
  if ( ((ringbuffer1_size + ringbuffer2_size) != vmcore->log_buf_len) ||
       ((ringbuffer1_size + ringbuffer2_size) > 1048576) ) {
   fprintf(stderr, "%s Dump area size calculation failed.\n", estr);
   goto ERROR_FREE;
  }
  if (elf_search_load_data(vmcore, &phdr_cache,
                           vmcore->log_buf +
                        (vmcore->log_end & (vmcore->log_buf_len-1)),
                           ringbuffer1_size, &ringbuffer1) ||
      elf_search_load_data(vmcore, &phdr_cache, vmcore->log_buf,
                           ringbuffer2_size, &ringbuffer2)) {
   fprintf(stderr, "%s Ring buffer not found in vmcore.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:   Ring buffer Part: 1/2\n", "crashdmesg");
  fprintf(stdout, "%s:    * File Offset:  0x%016lx\n",
          "crashdmesg", ringbuffer1);
  fprintf(stdout, "%s:    * Size:                 0x%08x\n",
          "crashdmesg", ringbuffer1_size);
  fprintf(stdout, "%s:   Ring buffer Part: 2/2\n", "crashdmesg");
  fprintf(stdout, "%s:    * File Offset:  0x%016lx\n",
          "crashdmesg", ringbuffer2);
  fprintf(stdout, "%s:    * Size:                 0x%08x\n",
          "crashdmesg", ringbuffer2_size);
  if (file_read(&vmcore->file, (void*) ringbuffer,
             ringbuffer1, ringbuffer1_size) ||
      file_read(&vmcore->file, (void*) ringbuffer + ringbuffer1_size,
                ringbuffer2, ringbuffer2_size)) {
   fprintf(stderr, "%s Can not read ring buffer.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:  Dump ring buffer.\n", "crashdmesg");
  fprintf(stdout,
          ">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n");
  for (loop = 0; loop < ringbuffer1_size + ringbuffer2_size ; loop++) {
   fputc(ringbuffer[loop], stdout);
  }
  fprintf(stdout,
          "<<<<<<<<<<[ END kernel ring buffer   ]<<<<<<<<<<<<<<<<<\n");
 }
 fprintf(stdout, "%s: Dump complete.\n", "crashdmesg");
 free(ringbuffer);
 file_close(&vmcore->file);
 return 0;
ERROR_FREE:
 free(ringbuffer);
ERROR_CLOSE:
 file_close(&vmcore->file);
 return 1;
}

canonical_original_code:
static int crashdmesg(struct VMCore *vmcore)
{
 char estr[] = "[ERROR] crashdmesg:";
 int loop = 0;
 struct Elf64_Phdr phdr_cache;
 memset(&phdr_cache, 0x00, sizeof(Elf64_Phdr));
 char osrelease[65];
 memset(osrelease, 0x00, sizeof(osrelease));
 long crashtime = 0;
 struct tm *ct = ((void *)0);
 unsigned long log_buf_vaddr = 0;
 unsigned long log_end_vaddr = 0;
 unsigned long log_buf_len_vaddr = 0;
 unsigned long logged_chars_vaddr = 0;
 long ringbuffer1 = 0;
 unsigned int ringbuffer1_size = 0;
 long ringbuffer2 = 0;
 unsigned int ringbuffer2_size = 0;
 char *ringbuffer = ((void *)0);
 ((vmcore != ((void *)0)) ? (void) (0) : __assert_fail ("vmcore != NULL", "crashdmesg_main.c", 113, __extension__ __PRETTY_FUNCTION__));
 fprintf(stdout, "%s:  Validate vmcore ELF binary header.\n", "crashdmesg");
 if (file_open(&vmcore->file)) {
  fprintf(stderr, "%s Can not open vmcore file.\n", estr);
  return 1;
 }
 if (elf_validate_elfheader(vmcore)) {
  fprintf(stderr, "%s Failed to validate vmcore file.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:  Read VMCOREINFO from NOTE segment.\n", "crashdmesg");
 if (elf_read_vmcoreinfo(vmcore)) {
  fprintf(stderr, "%s Can not read VMCOREINFO.\n", estr);
  goto ERROR_CLOSE;
 }
 if (elf_read_osrelease(vmcore, osrelease, sizeof(osrelease))) {
  fprintf(stderr, "%s Can not read OSRELEASE.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * OS Release: %s\n", "crashdmesg", osrelease);
 if (elf_read_crashtime(vmcore, &crashtime)) {
  fprintf(stderr, "%s Can not read CRASHTIME.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * Crash Time: %ld,\n", "crashdmesg", crashtime);
 ct = localtime(&crashtime);
 if (ct == ((void *)0)) {
  fprintf(stderr, "%s localtime failed.\n", estr);
  return 1;
 }
 fprintf(stdout, "%s:                  %04d/%02d/%02d %02d:%02d:%02d\n",
         "crashdmesg", ct->tm_year+1900, ct->tm_mon+1, ct->tm_mday,
         ct->tm_hour, ct->tm_min, ct->tm_sec);
 fprintf(stdout, "%s:  Read Symbol from VMCOREINFO.\n", "crashdmesg");
 elf_search_vmcoreinfo_symbol(vmcore, "log_buf", &log_buf_vaddr);
 elf_search_vmcoreinfo_symbol(vmcore, "log_end", &log_end_vaddr);
 elf_search_vmcoreinfo_symbol(vmcore, "log_buf_len", &log_buf_len_vaddr);
 elf_search_vmcoreinfo_symbol(vmcore, "logged_chars", &logged_chars_vaddr);
 if ((! log_buf_vaddr) || (! log_end_vaddr) ||
     (! log_buf_len_vaddr) || (! logged_chars_vaddr)) {
  fprintf(stderr, "%s Can not read Symbol from VMCOREINFO.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * log_buf:      0x%016lx\n",
         "crashdmesg", log_buf_vaddr);
 fprintf(stdout, "%s:    * log_end:      0x%016lx\n",
         "crashdmesg", log_end_vaddr);
 fprintf(stdout, "%s:    * log_buf_len:  0x%016lx\n",
         "crashdmesg", log_buf_len_vaddr);
 fprintf(stdout, "%s:    * logged_chars: 0x%016lx\n",
         "crashdmesg", logged_chars_vaddr);
 fprintf(stdout, "%s:  Read LOAD section about Ring buffer..\n",
         "crashdmesg");
 elf_read_load_uint64(vmcore, &phdr_cache,
                      log_buf_vaddr, &vmcore->log_buf);
 elf_read_load_uint32(vmcore, &phdr_cache,
                      log_end_vaddr, &vmcore->log_end);
 elf_read_load_int32(vmcore, &phdr_cache,
                     log_buf_len_vaddr, &vmcore->log_buf_len);
 elf_read_load_uint32(vmcore, &phdr_cache,
                      logged_chars_vaddr, &vmcore->logged_chars);
 if ((! vmcore->log_buf) || (! vmcore->log_end) ||
     (! vmcore->log_buf_len) || (! vmcore->logged_chars)) {
  fprintf(stderr, "%s Can not read value from LOAD segment.\n", estr);
  goto ERROR_CLOSE;
 }
 fprintf(stdout, "%s:    * log_buf:      0x%016lx\n",
         "crashdmesg", vmcore->log_buf);
 fprintf(stdout, "%s:    * log_end:              0x%08x\n",
         "crashdmesg", vmcore->log_end);
 fprintf(stdout, "%s:    * log_buf_len:          0x%08x\n",
         "crashdmesg", vmcore->log_buf_len);
 fprintf(stdout, "%s:    * logged_chars:         0x%08x\n",
         "crashdmesg", vmcore->logged_chars);
 if (vmcore->log_buf_len > 1048576) {
  fprintf(stderr, "%s log_buf_len is too big.\n", estr);
  goto ERROR_CLOSE;
 }
 ringbuffer = malloc(vmcore->log_buf_len);
 if (ringbuffer == ((void *)0)) {
  fprintf(stderr, "%s Can not allocate memory.\n", estr);
  goto ERROR_CLOSE;
 }
 memset(ringbuffer, 0x00, vmcore->log_buf_len);
 fprintf(stdout, "%s:  Calculating dump area address.\n", "crashdmesg");
 if ( vmcore->logged_chars < vmcore->log_buf_len ) {
  ringbuffer1_size = vmcore->logged_chars;
  if (elf_search_load_data(vmcore, &phdr_cache,
                           vmcore->log_buf, ringbuffer1_size,
                           &ringbuffer1)) {
   fprintf(stderr, "%s Ring buffer not found in vmcore.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:   Ring buffer Part: 1/1\n", "crashdmesg");
  fprintf(stdout, "%s:    * File Offset:  0x%016lx\n",
          "crashdmesg", ringbuffer1);
  fprintf(stdout, "%s:    * Size:                 0x%08x\n",
          "crashdmesg", ringbuffer1_size);
  if (file_read(&vmcore->file, (void *) ringbuffer,
             ringbuffer1, ringbuffer1_size)) {
   fprintf(stderr, "%s Can not read ring buffer.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:  Dump ring buffer.\n", "crashdmesg");
  fprintf(stdout,
          ">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n");
  for (loop = 0; loop < ringbuffer1_size; loop++) {
       fputc(ringbuffer[loop], stdout);
  }
  fprintf(stdout,
          "<<<<<<<<<<[ END kernel ring buffer   ]<<<<<<<<<<<<<<<<<\n");
 }
 else {
  ringbuffer1_size = vmcore->log_buf_len -
                     (vmcore->log_end & (vmcore->log_buf_len-1));
  ringbuffer2_size = vmcore->log_end & (vmcore->log_buf_len-1);
  if ( ((ringbuffer1_size + ringbuffer2_size) != vmcore->log_buf_len) ||
       ((ringbuffer1_size + ringbuffer2_size) > 1048576) ) {
   fprintf(stderr, "%s Dump area size calculation failed.\n", estr);
   goto ERROR_FREE;
  }
  if (elf_search_load_data(vmcore, &phdr_cache,
                           vmcore->log_buf +
                        (vmcore->log_end & (vmcore->log_buf_len-1)),
                           ringbuffer1_size, &ringbuffer1) ||
      elf_search_load_data(vmcore, &phdr_cache, vmcore->log_buf,
                           ringbuffer2_size, &ringbuffer2)) {
   fprintf(stderr, "%s Ring buffer not found in vmcore.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:   Ring buffer Part: 1/2\n", "crashdmesg");
  fprintf(stdout, "%s:    * File Offset:  0x%016lx\n",
          "crashdmesg", ringbuffer1);
  fprintf(stdout, "%s:    * Size:                 0x%08x\n",
          "crashdmesg", ringbuffer1_size);
  fprintf(stdout, "%s:   Ring buffer Part: 2/2\n", "crashdmesg");
  fprintf(stdout, "%s:    * File Offset:  0x%016lx\n",
          "crashdmesg", ringbuffer2);
  fprintf(stdout, "%s:    * Size:                 0x%08x\n",
          "crashdmesg", ringbuffer2_size);
  if (file_read(&vmcore->file, (void *) ringbuffer,
             ringbuffer1, ringbuffer1_size) ||
      file_read(&vmcore->file, (void *) ringbuffer + ringbuffer1_size,
                ringbuffer2, ringbuffer2_size)) {
   fprintf(stderr, "%s Can not read ring buffer.\n", estr);
   goto ERROR_FREE;
  }
  fprintf(stdout, "%s:  Dump ring buffer.\n", "crashdmesg");
  fprintf(stdout,
          ">>>>>>>>>>[ START kernel ring buffer ]>>>>>>>>>>>>>>>>>\n");
  for (loop = 0; loop < ringbuffer1_size + ringbuffer2_size ; loop++) {
   fputc(ringbuffer[loop], stdout);
  }
  fprintf(stdout,
          "<<<<<<<<<<[ END kernel ring buffer   ]<<<<<<<<<<<<<<<<<\n");
 }
 fprintf(stdout, "%s: Dump complete.\n", "crashdmesg");
 free(ringbuffer);
 file_close(&vmcore->file);
 return 0;
ERROR_FREE:
 free(ringbuffer);
ERROR_CLOSE:
 file_close(&vmcore->file);
 return 1;
}

variable_types: struct VMCore { struct File { char *filename; int fdesc; unsigned long size; } file; struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } elf_header; char vmcoreinfo[4096]; unsigned long vmcoreinfo_size; char *osrelease[65]; unsigned long osrelease_size; long crashtime; unsigned long log_buf; unsigned int log_end; int log_buf_len; unsigned int logged_chars; } *

variable_types:
estr
char []

variable_types: loop int

variable_types: struct Elf64_Phdr { unsigned int p_type; unsigned int p_flags; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_align; }

variable_types:
osrelease
char [65]

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

variable_types:
ringbuffer
char *

user_defined_types: struct VMCore { struct File file; struct Elf64_Ehdr elf_header; char vmcoreinfo[4096]; unsigned long vmcoreinfo_size; char *osrelease[65]; unsigned long osrelease_size; long crashtime; unsigned long log_buf; unsigned int log_end; int log_buf_len; unsigned int logged_chars; }


main

canonical_name: main

repo: hiro-dSn/crashdmesg

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[14]; // [rsp+2h] [rbp-12B6h] BYREF
const char *v5[597]; // [rsp+10h] [rbp-12A8h] BYREF

strcpy(v4, "[ERROR] main:");
memset(v5, 0, 0x1290uLL);
fprintf(stdout, "%s: %s start.\n", "crashdmesg");
if ( (unsigned int)parse_option(argc, (__int64)argv, v5) )
{
fprintf(stderr, "%s Invalid option.\n", v4);
print_usage();
result = 1;
}
else
{
fprintf(stdout, "%s: Target file: %s\n", "crashdmesg", v5[0]);
result = crashdmesg((__int64)v5);
if ( result )
{
fprintf(stderr, "%s Dump Failed.\n", v4);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
char v4[14]; // [rsp+2h] [rbp-12B6h] BYREF
const char *v5[597]; // [rsp+10h] [rbp-12A8h] BYREF

strcpy(v4, "[ERROR] main:");
memset(v5, 0, 0x1290uLL);
fprintf(stdout, "%s: %s start.\n", "crashdmesg");
if ( (unsigned int)func0(argc, (__int64)argv, v5) )
{
fprintf(stderr, "%s Invalid option.\n", v4);
func1();
result = 1;
}
else
{
fprintf(stdout, "%s: Target file: %s\n", "crashdmesg", v5[0]);
result = func2((__int64)v5);
if ( result )
{
fprintf(stderr, "%s Dump Failed.\n", v4);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 char estr[] = "[ERROR] main:";
 VMCore vmcore;
 memset(&vmcore, 0x00, sizeof(VMCore));
 fprintf(stdout, "%s:  %s start.\n", "crashdmesg", "crashdmesg");
 if (parse_option(argc, argv, &vmcore.file)) {
  fprintf(stderr, "%s Invalid option.\n", estr);
  print_usage();
  return 1;
 }
 fprintf(stdout, "%s:   Target file: %s\n", "crashdmesg", vmcore.file.filename);
 if (crashdmesg(&vmcore)) {
  fprintf(stderr, "%s Dump Failed.\n", estr);
  return 1;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char estr[] = "[ERROR] main:";
 struct VMCore vmcore;
 memset(&vmcore, 0x00, sizeof(VMCore));
 fprintf(stdout, "%s:  %s start.\n", "crashdmesg", "crashdmesg");
 if (parse_option(argc, argv, &vmcore.file)) {
  fprintf(stderr, "%s Invalid option.\n", estr);
  print_usage();
  return 1;
 }
 fprintf(stdout, "%s:   Target file: %s\n", "crashdmesg", vmcore.file.filename);
 if (crashdmesg(&vmcore)) {
  fprintf(stderr, "%s Dump Failed.\n", estr);
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct VMCore { struct File { char *filename; int fdesc; unsigned long size; } file; struct Elf64_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } elf_header; char vmcoreinfo[4096]; unsigned long vmcoreinfo_size; char *osrelease[65]; unsigned long osrelease_size; long crashtime; unsigned long log_buf; unsigned int log_end; int log_buf_len; unsigned int logged_chars; }

return_type: int


decompiled_code:
__int64 __fastcall file_open(__int64 a1)
{
int *v2; // rax
__m128i v3; // xmm0
unsigned int *v4; // rbp
const char *v5; // rdi
unsigned int v6; // er12
int v7; // eax
__int64 result; // rax
const char *v9; // rbx
char *v10; // rax
const char *v11; // r12
char *v12; // rax
const char *v13; // r9
__m128i v14; // [rsp+0h] [rbp-C8h] BYREF
char v15[8]; // [rsp+10h] [rbp-B8h] BYREF
struct stat v16; // [rsp+20h] [rbp-A8h] BYREF

v2 = _errno_location();
v3 = _mm_load_si128((const __m128i *)&LC6);
*v2 = 0;
v4 = (unsigned int *)v2;
strcpy(v15, "n:");
memset(&v16, 0, sizeof(v16));
v14 = v3;
if ( !a1 )
_assert_fail("file != NULL", "crashdmesg_fileutils.c", 0x18u, "file_open");
v5 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
{
v6 = 1;
fprintf(stderr, "%s Filename not specified.\n", v14.m128i_i8);
return v6;
}
v6 = *(_DWORD *)(a1 + 8);
if ( v6 )
{
fprintf(stderr, "%s File already opened.\n", v14.m128i_i8);
result = 1LL;
}
else
{
if ( stat(v5, &v16) != -1 )
{
v7 = open(*(const char **)a1, 0);
*(_DWORD *)(a1 + 8) = v7;
if ( v7 == -1 )
{
v11 = *(const char **)a1;
v12 = strerror(*v4);
v13 = v11;
v6 = 1;
fprintf(stderr, "%s Can not open file: [%d] %s: %s\n", v14.m128i_i8, *v4, v12, v13);
*(_DWORD *)(a1 + 8) = 0;
}
else
{
*(_QWORD *)(a1 + 16) = v16.st_size;
}
return v6;
}
v9 = *(const char **)a1;
v10 = strerror(*v4);
fprintf(stderr, "%s Get file stat failed: [%d] %s: %s\n", v14.m128i_i8, *v4, v10, v9);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int *v2; // rax
__m128i v3; // xmm0
unsigned int *v4; // rbp
const char *v5; // rdi
unsigned int v6; // er12
int v7; // eax
__int64 result; // rax
const char *v9; // rbx
char *v10; // rax
const char *v11; // r12
char *v12; // rax
const char *v13; // r9
__m128i v14; // [rsp+0h] [rbp-C8h] BYREF
char v15[8]; // [rsp+10h] [rbp-B8h] BYREF
struct stat v16; // [rsp+20h] [rbp-A8h] BYREF

v2 = _errno_location();
v3 = _mm_load_si128((const __m128i *)&LC6);
*v2 = 0;
v4 = (unsigned int *)v2;
strcpy(v15, "n:");
memset(&v16, 0, sizeof(v16));
v14 = v3;
if ( !a1 )
_assert_fail("file != NULL", "crashdmesg_fileutils.c", 0x18u, "file_open");
v5 = *(const char **)a1;
if ( !*(_QWORD *)a1 )
{
v6 = 1;
fprintf(stderr, "%s Filename not specified.\n", v14.m128i_i8);
return v6;
}
v6 = *(_DWORD *)(a1 + 8);
if ( v6 )
{
fprintf(stderr, "%s File already opened.\n", v14.m128i_i8);
result = 1LL;
}
else
{
if ( stat(v5, &v16) != -1 )
{
v7 = open(*(const char **)a1, 0);
*(_DWORD *)(a1 + 8) = v7;
if ( v7 == -1 )
{
v11 = *(const char **)a1;
v12 = strerror(*v4);
v13 = v11;
v6 = 1;
fprintf(stderr, "%s Can not open file: [%d] %s: %s\n", v14.m128i_i8, *v4, v12, v13);
*(_DWORD *)(a1 + 8) = 0;
}
else
{
*(_QWORD *)(a1 + 16) = v16.st_size;
}
return v6;
}
v9 = *(const char **)a1;
v10 = strerror(*v4);
fprintf(stderr, "%s Get file stat failed: [%d] %s: %s\n", v14.m128i_i8, *v4, v10, v9);
result = 1LL;
}
return result;
}

original_code:
int file_open(File *file)
{
 (*__errno_location ()) = 0;
 char estr[] = "[ERROR] file_open:";
 struct stat filestat;
 memset(&filestat, 0x00, sizeof(struct stat));
 ((file != ((void *)0)) ? (void) (0) : __assert_fail ("file != NULL", "crashdmesg_fileutils.c", 24, __extension__ __PRETTY_FUNCTION__));
 if (! file->filename) {
  fprintf(stderr, "%s Filename not specified.\n", estr);
  return 1;
 }
 if (file->fdesc) {
  fprintf(stderr, "%s File already opened.\n", estr);
  return 1;
 }
 if (stat(file->filename, &filestat) == -1) {
  fprintf(stderr, "%s Get file stat failed: [%d] %s: %s\n", estr,
          (*__errno_location ()), strerror((*__errno_location ())), file->filename);
  return 1;
 }
 file->fdesc = open(file->filename, 00|0);
 if (file->fdesc == -1) {
  fprintf(stderr, "%s Can not open file: [%d] %s: %s\n", estr,
         (*__errno_location ()), strerror((*__errno_location ())), file->filename);
  file->fdesc = 0;
  return 1;
 }
 file->size = (size_t) filestat.st_size;
 return 0;
}

canonical_original_code:
int file_open(struct File *file)
{
 (*__errno_location ()) = 0;
 char estr[] = "[ERROR] file_open:";
 struct stat filestat;
 memset(&filestat, 0x00, sizeof(struct stat));
 ((file != ((void *)0)) ? (void) (0) : __assert_fail ("file != NULL", "crashdmesg_fileutils.c", 24, __extension__ __PRETTY_FUNCTION__));
 if (! file->filename) {
  fprintf(stderr, "%s Filename not specified.\n", estr);
  return 1;
 }
 if (file->fdesc) {
  fprintf(stderr, "%s File already opened.\n", estr);
  return 1;
 }
 if (stat(file->filename, &filestat) == -1) {
  fprintf(stderr, "%s Get file stat failed: [%d] %s: %s\n", estr,
          (*__errno_location ()), strerror((*__errno_location ())), file->filename);
  return 1;
 }
 file->fdesc = open(file->filename, 00|0);
 if (file->fdesc == -1) {
  fprintf(stderr, "%s Can not open file: [%d] %s: %s\n", estr,
         (*__errno_location ()), strerror((*__errno_location ())), file->filename);
  file->fdesc = 0;
  return 1;
 }
 file->size = (unsigned long) filestat.st_size;
 return 0;
}

variable_types: struct File { char *filename; int fdesc; unsigned long size; } *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall file_close(__int64 a1)
{
int *v2; // rax
__m128i v3; // xmm0
int v4; // edi
int *v5; // rbp
int v6; // er8
__int64 result; // rax
const char *v8; // r12
char *v9; // rax
__m128i v10; // [rsp+0h] [rbp-38h] BYREF
int v11; // [rsp+10h] [rbp-28h]

v2 = _errno_location();
v3 = _mm_load_si128((const __m128i *)&LC9);
v11 = 3827059;
*v2 = 0;
v10 = v3;
if ( !a1 )
_assert_fail("file != NULL", "crashdmesg_fileutils.c", 0x41u, "file_close");
v4 = *(_DWORD *)(a1 + 8);
if ( v4 )
{
v5 = v2;
v6 = close(v4);
result = 0LL;
if ( v6 == -1 )
{
v8 = *(const char **)a1;
v9 = strerror(*v5);
fprintf(stderr, "%s Can not close file: [%d] %s: %s\n", v10.m128i_i8, (unsigned int)*v5, v9, v8);
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}
else
{
fprintf(stderr, "%s File is not opened.\n", v10.m128i_i8);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int *v2; // rax
__m128i v3; // xmm0
int v4; // edi
int *v5; // rbp
int v6; // er8
__int64 result; // rax
const char *v8; // r12
char *v9; // rax
__m128i v10; // [rsp+0h] [rbp-38h] BYREF
int v11; // [rsp+10h] [rbp-28h]

v2 = _errno_location();
v3 = _mm_load_si128((const __m128i *)&LC9);
v11 = 3827059;
*v2 = 0;
v10 = v3;
if ( !a1 )
_assert_fail("file != NULL", "crashdmesg_fileutils.c", 0x41u, "file_close");
v4 = *(_DWORD *)(a1 + 8);
if ( v4 )
{
v5 = v2;
v6 = close(v4);
result = 0LL;
if ( v6 == -1 )
{
v8 = *(const char **)a1;
v9 = strerror(*v5);
fprintf(stderr, "%s Can not close file: [%d] %s: %s\n", v10.m128i_i8, (unsigned int)*v5, v9, v8);
*(_DWORD *)(a1 + 8) = 0;
result = 1LL;
*(_QWORD *)(a1 + 16) = 0LL;
}
}
else
{
fprintf(stderr, "%s File is not opened.\n", v10.m128i_i8);
result = 1LL;
}
return result;
}

original_code:
int file_close(File *file)
{
 (*__errno_location ()) = 0;
 char estr[] = "[ERROR] file_close:";
 ((file != ((void *)0)) ? (void) (0) : __assert_fail ("file != NULL", "crashdmesg_fileutils.c", 65, __extension__ __PRETTY_FUNCTION__));
 if (! file->fdesc) {
  fprintf(stderr, "%s File is not opened.\n", estr);
  return 1;
 }
 if (close(file->fdesc) == -1) {
  fprintf(stderr, "%s Can not close file: [%d] %s: %s\n", estr,
         (*__errno_location ()), strerror((*__errno_location ())), file->filename);
  file->fdesc = 0;
  file->size = 0;
  return 1;
 }
 return 0;
}

canonical_original_code:
int file_close(struct File *file)
{
 (*__errno_location ()) = 0;
 char estr[] = "[ERROR] file_close:";
 ((file != ((void *)0)) ? (void) (0) : __assert_fail ("file != NULL", "crashdmesg_fileutils.c", 65, __extension__ __PRETTY_FUNCTION__));
 if (! file->fdesc) {
  fprintf(stderr, "%s File is not opened.\n", estr);
  return 1;
 }
 if (close(file->fdesc) == -1) {
  fprintf(stderr, "%s Can not close file: [%d] %s: %s\n", estr,
         (*__errno_location ()), strerror((*__errno_location ())), file->filename);
  file->fdesc = 0;
  file->size = 0;
  return 1;
 }
 return 0;
}

user_defined_types: struct File { char *filename; int fdesc; unsigned long size; }


decompiled_code:
__int64 __fastcall file_read(const char **a1, void *a2, __off_t a3, size_t a4)
{
int *v7; // rax
__m128i v8; // xmm0
int v9; // edi
unsigned int *v10; // r13
const char *v11; // rax
__int64 result; // rax
ssize_t v13; // r14
char *v14; // rax
char *v15; // rax
__m128i v16; // [rsp+0h] [rbp-48h] BYREF
__int16 v17; // [rsp+10h] [rbp-38h]
char v18; // [rsp+12h] [rbp-36h]

v7 = _errno_location();
v18 = 0;
v8 = _mm_load_si128((const __m128i *)&LC17);
*v7 = 0;
v17 = 14948;
v16 = v8;
if ( !a1 )
_assert_fail("file != NULL", "crashdmesg_fileutils.c", 0x61u, "file_read");
if ( !a2 )
_assert_fail("buffer != NULL", "crashdmesg_fileutils.c", 0x62u, "file_read");
if ( a3 < 0 )
_assert_fail("offset >= 0", "crashdmesg_fileutils.c", 0x63u, "file_read");
if ( !a4 )
_assert_fail("size > 0", "crashdmesg_fileutils.c", 0x64u, "file_read");
v9 = *((_DWORD *)a1 + 2);
if ( !v9 )
{
fprintf(stderr, "%s File is not opened.\n", v16.m128i_i8);
return 1LL;
}
v10 = (unsigned int *)v7;
v11 = a1[2];
if ( (unsigned __int64)v11 < a3 || (unsigned __int64)v11 < a3 + a4 )
{
fwrite("Read area overflowed.\n", 1uLL, 0x16uLL, stderr);
return 1LL;
}
if ( lseek(v9, a3, 0) == -1 )
{
v15 = strerror(*v10);
fprintf(stderr, "%s Seek failed: %s(0x%x) : [%d] %s\n", &v16, *a1, (unsigned int)a3, *v10, v15);
return 1LL;
}
v13 = read(*((_DWORD *)a1 + 2), a2, a4);
if ( v13 == -1 )
{
strerror(*v10);
fprintf(stderr, "%s Read failed: %s(0x%x:0x%x) : [%d] %s\n", &v16, *a1, (unsigned int)a3, (unsigned int)a4, *v10);
return 1LL;
}
result = 0LL;
if ( a4 != v13 )
{
v14 = strerror(*v10);
fprintf(
stderr,
"%s Can not read: %s(0x%x:0x%x,0x%x) : [%d] %s\n",
v16.m128i_i8,
*a1,
(unsigned int)a3,
(unsigned int)a4,
v13,
*v10,
v14);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char **a1, void *a2, __off_t a3, size_t a4)
{
int *v7; // rax
__m128i v8; // xmm0
int v9; // edi
unsigned int *v10; // r13
const char *v11; // rax
__int64 result; // rax
ssize_t v13; // r14
char *v14; // rax
char *v15; // rax
__m128i v16; // [rsp+0h] [rbp-48h] BYREF
__int16 v17; // [rsp+10h] [rbp-38h]
char v18; // [rsp+12h] [rbp-36h]

v7 = _errno_location();
v18 = 0;
v8 = _mm_load_si128((const __m128i *)&LC17);
*v7 = 0;
v17 = 14948;
v16 = v8;
if ( !a1 )
_assert_fail("file != NULL", "crashdmesg_fileutils.c", 0x61u, "file_read");
if ( !a2 )
_assert_fail("buffer != NULL", "crashdmesg_fileutils.c", 0x62u, "file_read");
if ( a3 < 0 )
_assert_fail("offset >= 0", "crashdmesg_fileutils.c", 0x63u, "file_read");
if ( !a4 )
_assert_fail("size > 0", "crashdmesg_fileutils.c", 0x64u, "file_read");
v9 = *((_DWORD *)a1 + 2);
if ( !v9 )
{
fprintf(stderr, "%s File is not opened.\n", v16.m128i_i8);
return 1LL;
}
v10 = (unsigned int *)v7;
v11 = a1[2];
if ( (unsigned __int64)v11 < a3 || (unsigned __int64)v11 < a3 + a4 )
{
fwrite("Read area overflowed.\n", 1uLL, 0x16uLL, stderr);
return 1LL;
}
if ( lseek(v9, a3, 0) == -1 )
{
v15 = strerror(*v10);
fprintf(stderr, "%s Seek failed: %s(0x%x) : [%d] %s\n", &v16, *a1, (unsigned int)a3, *v10, v15);
return 1LL;
}
v13 = read(*((_DWORD *)a1 + 2), a2, a4);
if ( v13 == -1 )
{
strerror(*v10);
fprintf(stderr, "%s Read failed: %s(0x%x:0x%x) : [%d] %s\n", &v16, *a1, (unsigned int)a3, (unsigned int)a4, *v10);
return 1LL;
}
result = 0LL;
if ( a4 != v13 )
{
v14 = strerror(*v10);
fprintf(
stderr,
"%s Can not read: %s(0x%x:0x%x,0x%x) : [%d] %s\n",
v16.m128i_i8,
*a1,
(unsigned int)a3,
(unsigned int)a4,
v13,
*v10,
v14);
result = 1LL;
}
return result;
}

original_code:
int file_read(File *file, void *buffer, off_t offset, size_t size)
{
 (*__errno_location ()) = 0;
 char estr[] = "[ERROR] file_read:";
 ssize_t readbytes = 0;
 ((file != ((void *)0)) ? (void) (0) : __assert_fail ("file != NULL", "crashdmesg_fileutils.c", 97, __extension__ __PRETTY_FUNCTION__));
 ((buffer != ((void *)0)) ? (void) (0) : __assert_fail ("buffer != NULL", "crashdmesg_fileutils.c", 98, __extension__ __PRETTY_FUNCTION__));
 ((offset >= 0) ? (void) (0) : __assert_fail ("offset >= 0", "crashdmesg_fileutils.c", 99, __extension__ __PRETTY_FUNCTION__));
 ((size > 0) ? (void) (0) : __assert_fail ("size > 0", "crashdmesg_fileutils.c", 100, __extension__ __PRETTY_FUNCTION__));
 if (! file->fdesc) {
  fprintf(stderr, "%s File is not opened.\n", estr);
  return 1;
 }
 if ((offset > file->size) || (offset + size > file->size)) {
  fprintf(stderr, "Read area overflowed.\n");
  return 1;
 }
 if (lseek(file->fdesc, offset, 0) == (off_t) -1) {
  fprintf(stderr, "%s Seek failed: %s(0x%x) : [%d] %s\n", estr,
          file->filename, (unsigned) offset, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 readbytes = read(file->fdesc, buffer, size);
 if (readbytes == -1) {
  fprintf(stderr, "%s Read failed: %s(0x%x:0x%x) : [%d] %s\n", estr,
          file->filename, (unsigned) offset, (unsigned) size,
          (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 else if (readbytes != (ssize_t) size) {
  fprintf(stderr, "%s Can not read: %s(0x%x:0x%x,0x%x) : [%d] %s\n",
          estr, file->filename, (unsigned) offset, (unsigned) size,
          (unsigned) readbytes, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}

canonical_original_code:
int file_read(struct File *file, void *buffer, long offset, unsigned long size)
{
 (*__errno_location ()) = 0;
 char estr[] = "[ERROR] file_read:";
 long readbytes = 0;
 ((file != ((void *)0)) ? (void) (0) : __assert_fail ("file != NULL", "crashdmesg_fileutils.c", 97, __extension__ __PRETTY_FUNCTION__));
 ((buffer != ((void *)0)) ? (void) (0) : __assert_fail ("buffer != NULL", "crashdmesg_fileutils.c", 98, __extension__ __PRETTY_FUNCTION__));
 ((offset >= 0) ? (void) (0) : __assert_fail ("offset >= 0", "crashdmesg_fileutils.c", 99, __extension__ __PRETTY_FUNCTION__));
 ((size > 0) ? (void) (0) : __assert_fail ("size > 0", "crashdmesg_fileutils.c", 100, __extension__ __PRETTY_FUNCTION__));
 if (! file->fdesc) {
  fprintf(stderr, "%s File is not opened.\n", estr);
  return 1;
 }
 if ((offset > file->size) || (offset + size > file->size)) {
  fprintf(stderr, "Read area overflowed.\n");
  return 1;
 }
 if (lseek(file->fdesc, offset, 0) == (off_t) -1) {
  fprintf(stderr, "%s Seek failed: %s(0x%x) : [%d] %s\n", estr,
          file->filename, (unsigned int) offset, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 readbytes = read(file->fdesc, buffer, size);
 if (readbytes == -1) {
  fprintf(stderr, "%s Read failed: %s(0x%x:0x%x) : [%d] %s\n", estr,
          file->filename, (unsigned int) offset, (unsigned int) size,
          (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 else if (readbytes != (long) size) {
  fprintf(stderr, "%s Can not read: %s(0x%x:0x%x,0x%x) : [%d] %s\n",
          estr, file->filename, (unsigned int) offset, (unsigned int) size,
          (unsigned int) readbytes, (*__errno_location ()), strerror((*__errno_location ())));
  return 1;
 }
 return 0;
}

variable_types:
buffer
void *

variable_types: offset long

variable_types:
size
unsigned long

variable_types: readbytes long


decompiled_code:
__int64 test_bs()
{
unsigned int v0; // eax
int v2; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v3[7]; // [rsp+10h] [rbp-38h] BYREF

fwrite("binary search test\n", 1uLL, 0x13uLL, stdout);
v2 = 7955041;
v3[0] = (__int64)"aby";
v3[1] = (__int64)"bus";
v3[2] = (__int64)"dog";
v3[3] = (__int64)"focus";
v3[4] = (__int64)"hear";
v0 = bs(&v2, v3, 5LL);
fprintf(stdout, "%i \n", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
int v2; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v3[7]; // [rsp+10h] [rbp-38h] BYREF

fwrite("binary search test\n", 1uLL, 0x13uLL, stdout);
v2 = 7955041;
v3[0] = (__int64)"aby";
v3[1] = (__int64)"bus";
v3[2] = (__int64)"dog";
v3[3] = (__int64)"focus";
v3[4] = (__int64)"hear";
v0 = bs(&v2, v3, 5LL);
fprintf(stdout, "%i \n", v0);
return 0LL;
}

original_code:
int test_bs()
{
  fprintf(stdout, "binary search test\n");
  char query[] = "aby";
  char *p[] = {"aby","bus","dog","focus","hear"};
  int res= bs(query, p, 5);
  fprintf(stdout, "%i \n",res);
  return(0);
}

canonical_original_code:
int test_bs()
{
  fprintf(stdout, "binary search test\n");
  char query[] = "aby";
  char *p[] = {"aby","bus","dog","focus","hear"};
  int res = bs(query, p, 5);
  fprintf(stdout, "%i \n",res);
  return(0);
}

variable_types:
query
char []

variable_types:
p
char *[]

variable_types: res int


printarray

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

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

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

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

original_code:
void printarray(int *array,int len)
{
  printf("[ ");
  int i=0;
  for(;i<len;i++)
    {
      printf("%d ",*(array+i));
    }
  printf("]\n");
}

canonical_original_code:
void printarray(int *array, int len)
{
  printf("[ ");
  int i = 0;
  for(;i<len;i++)
    {
      printf("%d ",*(array+i));
    }
  printf("]\n");
}

variable_types:
array
int *

variable_types: len int

variable_types: i int

return_type: void


original_code:
void test_insetSort()
{
  fprintf(stdout, "insert sort test\n");
  int a[] = {0,3,5,2,4,2,1,45,2,1,1,4,4,6,7,8,4,3};
  insertSort(a, 18);
  printarray(a,18);
}

variable_types:
a
int []


original_code:
void test_ss()
{
  fprintf(stdout, "selection sort test\n");
  int a[] = {0,3,5,2,4,2,1,45,2,1,1,4,4,6,7,8,4,3};
  selectionSort(a,18);
  printarray(a,18);
}


decompiled_code:
int test_bwt()
{
char *v0; // rbx
__int64 v1; // rax
char *v2; // rbx
__int64 v3; // rax
__int128 v5[2]; // [rsp+0h] [rbp-1C8h] BYREF
char v6[16]; // [rsp+20h] [rbp-1A8h] BYREF
char v7[180]; // [rsp+30h] [rbp-198h] BYREF
char v8; // [rsp+E4h] [rbp-E4h] BYREF
char v9[180]; // [rsp+F0h] [rbp-D8h] BYREF
char v10; // [rsp+1A4h] [rbp-24h] BYREF

v0 = v7;
fwrite("bwt transform test\n", 1uLL, 0x13uLL, stdout);
v5[0] = (__int128)_mm_load_si128((const __m128i *)&LC16);
strcpy(v6, "do something!");
v5[1] = (__int128)_mm_load_si128((const __m128i *)&LC17);
bwt(v5, 45LL, v7);
sortstring(v5, 45LL, v9);
do
{
v1 = *(int *)v0;
v0 += 4;
putchar(*((char *)v5 + v1));
}
while ( v0 != &v8 );
v2 = v9;
putchar(10);
do
{
v3 = *(int *)v2;
v2 += 4;
putchar(*((char *)v5 + v3));
}
while ( v2 != &v10 );
return putchar(10);
}

canonical_decompiled_code:
int func7()
{
char *v0; // rbx
__int64 v1; // rax
char *v2; // rbx
__int64 v3; // rax
__int128 v5[2]; // [rsp+0h] [rbp-1C8h] BYREF
char v6[16]; // [rsp+20h] [rbp-1A8h] BYREF
char v7[180]; // [rsp+30h] [rbp-198h] BYREF
char v8; // [rsp+E4h] [rbp-E4h] BYREF
char v9[180]; // [rsp+F0h] [rbp-D8h] BYREF
char v10; // [rsp+1A4h] [rbp-24h] BYREF

v0 = v7;
fwrite("bwt transform test\n", 1uLL, 0x13uLL, stdout);
v5[0] = (__int128)_mm_load_si128((const __m128i *)&LC16);
strcpy(v6, "do something!");
v5[1] = (__int128)_mm_load_si128((const __m128i *)&LC17);
bwt(v5, 45LL, v7);
sortstring(v5, 45LL, v9);
do
{
v1 = *(int *)v0;
v0 += 4;
putchar(*((char *)v5 + v1));
}
while ( v0 != &v8 );
v2 = v9;
putchar(10);
do
{
v3 = *(int *)v2;
v2 += 4;
putchar(*((char *)v5 + v3));
}
while ( v2 != &v10 );
return putchar(10);
}

original_code:
void test_bwt()
{
  fprintf(stdout, "bwt transform test\n");
  char x[]="this is a child who is eager to do something!";
  int pos[45],pos_s[45],i,m;
  bwt(x,45,pos);
  sortstring(x,45,pos_s);
  for(i=0;i<45;i++){
    m=pos[i];
    printf("%c",x[m]);
  }
  printf("\n");
  for(i=0;i<45;i++){
    m=pos_s[i];
    printf("%c",x[m]);
  }
  printf("\n");
}

canonical_original_code:
void test_bwt()
{
  fprintf(stdout, "bwt transform test\n");
  char x[] = "this is a child who is eager to do something!";
  int pos[45]; int pos_s[45]; int i; int m;
  bwt(x,45,pos);
  sortstring(x,45,pos_s);
  for(i=0;i<45;i++){
    m=pos[i];
    printf("%c",x[m]);
  }
  printf("\n");
  for(i=0;i<45;i++){
    m=pos_s[i];
    printf("%c",x[m]);
  }
  printf("\n");
}

variable_types:
x
char []

variable_types:
pos
int [45]

variable_types: m int


original_code:
void test_stack()
{
  fprintf(stdout, "stack struct test\n");
  char* friends[] = {"Aog","loi","Boy","oops","big",
    "Cowmax","whistle","herp","atom","tax","?what"};
  hgc_stack_t cstack;
  stackNew(&cstack, sizeof(char*));
  int i;
  for(i=0;i<10;i++)
    {
      stackPush(&cstack,
  friends+i);
      char* x;
      stackPop(&cstack,
        &x);
      fprintf(stdout,"%s ",x);
    }
  fprintf(stdout,"\n");
}

canonical_original_code:
void test_stack()
{
  fprintf(stdout, "stack struct test\n");
  char *friends[] = {"Aog","loi","Boy","oops","big",
    "Cowmax","whistle","herp","atom","tax","?what"};
  struct hgc_stack_t cstack;
  stackNew(&cstack, sizeof(char *));
  int i;
  for(i=0;i<10;i++)
    {
      stackPush(&cstack,
  friends+i);
      char *x;
      stackPop(&cstack,
        &x);
      fprintf(stdout,"%s ",x);
    }
  fprintf(stdout,"\n");
}

variable_types:
friends
char *[]

variable_types: struct hgc_stack_t { void *elems; int elemSize; int loglen; int alloclen; int n_nt; }

variable_types:
x
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
test_ms();
test_ss();
test_insetSort();
test_bs(argc, argv);
test_hs();
test_qs();
test_bwt();
test_align();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func4();
func3();
func2();
func0(argc, argv);
func5();
func6();
func7();
func10();
return 0;
}

original_code:
int main()
{
  test_ms();
  test_ss();
  test_insetSort();
  test_bs();
  test_hs();
  test_qs();
  test_bwt();
    test_align();
  return(0);
}


stackGrow

decompiled_code:
void *__fastcall stackGrow(__int64 a1)
{
int v1; // eax
void *result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = 2 * v1;
result = realloc(*(void **)a1, *(_DWORD *)(a1 + 8) * 2 * v1);
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
int v1; // eax
void *result; // rax

v1 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 16) = 2 * v1;
result = realloc(*(void **)a1, *(_DWORD *)(a1 + 8) * 2 * v1);
*(_QWORD *)a1 = result;
return result;
}

original_code:
static void stackGrow(hgc_stack_t* s)
{
  s->alloclen *= 2;
  s->elems = realloc(s->elems,
       s->alloclen * s->elemSize);
}

canonical_original_code:
static void stackGrow(struct hgc_stack_t *s)
{
  s->alloclen *= 2;
  s->elems = realloc(s->elems,
       s->alloclen * s->elemSize);
}

variable_types: struct hgc_stack_t { void *elems; int elemSize; int loglen; int alloclen; int n_nt; } *


stackNew

decompiled_code:
void *__fastcall stackNew(__int64 a1, int a2)
{
void *result; // rax

if ( a2 <= 0 )
_assert_fail("elemSize > 0", "hgc_stack.c", 0x11u, "stackNew");
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)(a1 + 16) = 4LL;
result = malloc(4 * a2);
*(_QWORD *)a1 = result;
if ( !result )
_assert_fail("s->elems != NULL", "hgc_stack.c", 0x17u, "stackNew");
return result;
}

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

if ( a2 <= 0 )
_assert_fail("elemSize > 0", "hgc_stack.c", 0x11u, "stackNew");
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = 0;
*(_QWORD *)(a1 + 16) = 4LL;
result = malloc(4 * a2);
*(_QWORD *)a1 = result;
if ( !result )
_assert_fail("s->elems != NULL", "hgc_stack.c", 0x17u, "stackNew");
return result;
}

original_code:
void stackNew(hgc_stack_t* s, int elemSize)
{
  ((void) sizeof ((elemSize > 0) ? 1 : 0), __extension__ ({ if (elemSize > 0) ; else __assert_fail ("elemSize > 0", "hgc_stack.c", 17, __extension__ __PRETTY_FUNCTION__); }));
  s->elemSize = elemSize;
  s->loglen = 0;
  s->n_nt = 0;
  s->alloclen = 4;
  s->elems = malloc( 4* elemSize);
  ((void) sizeof ((s->elems != ((void *)0)) ? 1 : 0), __extension__ ({ if (s->elems != ((void *)0)) ; else __assert_fail ("s->elems != NULL", "hgc_stack.c", 23, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void stackNew(struct hgc_stack_t *s, int elemSize)
{
  ((void) sizeof ((elemSize > 0) ? 1 : 0), __extension__ ({ if (elemSize > 0) ; else __assert_fail ("elemSize > 0", "hgc_stack.c", 17, __extension__ __PRETTY_FUNCTION__); }));
  s->elemSize = elemSize;
  s->loglen = 0;
  s->n_nt = 0;
  s->alloclen = 4;
  s->elems = malloc( 4* elemSize);
  ((void) sizeof ((s->elems != ((void *)0)) ? 1 : 0), __extension__ ({ if (s->elems != ((void *)0)) ; else __assert_fail ("s->elems != NULL", "hgc_stack.c", 23, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: elemSize int

user_defined_types: struct hgc_stack_t { void *elems; int elemSize; int loglen; int alloclen; int n_nt; }


stackDispose

decompiled_code:
void __fastcall stackDispose(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
free(*a1);
}

original_code:
void stackDispose(hgc_stack_t* s)
{
  free(s->elems);
}

canonical_original_code:
void stackDispose(struct hgc_stack_t *s)
{
  free(s->elems);
}


stackPush

original_code:
void stackPush(hgc_stack_t* s, void* elemAddr)
{
  if(s->loglen == s->alloclen)
    stackGrow(s);
  void* target = (char*) s->elems + s->loglen * s->elemSize;
  memcpy(target, elemAddr, s->elemSize);
  s->loglen++;
  if(*(char*)elemAddr != '-')
    s->n_nt++;
}

canonical_original_code:
void stackPush(struct hgc_stack_t *s, void *elemAddr)
{
  if(s->loglen == s->alloclen)
    stackGrow(s);
  void *target = (char*) s->elems + s->loglen * s->elemSize;
  memcpy(target, elemAddr, s->elemSize);
  s->loglen++;
  if(*(char *)elemAddr != '-')
    s->n_nt++;
}

variable_types:
elemAddr
void *

variable_types:
target
void *


treefree

decompiled_code:
void __fastcall treefree(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
treefree();
if ( *(_QWORD *)(a1 + 24) )
treefree();
free(*(void **)a1);
free((void *)a1);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
if ( *(_QWORD *)(a1 + 16) )
func0();
if ( *(_QWORD *)(a1 + 24) )
func0();
free(*(void **)a1);
free((void *)a1);
}

original_code:
void treefree(node_t* root)
{
  struct node_t *left,*right;
  if((left=root->left) != ((void *)0))
    treefree(left);
  if((right=root->right) != ((void *)0))
    treefree(right);
  free(root->word);
  free(root);
}

canonical_original_code:
void treefree(struct node_t *root)
{
  struct node_t *left; struct node_t *right;
  if((left=root->left) != ((void *)0))
    treefree(left);
  if((right=root->right) != ((void *)0))
    treefree(right);
  free(root->word);
  free(root);
}

variable_types: struct node_t { char *word; int count; int lvl; struct node_t *left; struct node_t *right; } *


treeprint

decompiled_code:
int __fastcall treeprint(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
treeprint(*(_QWORD *)(v1 + 16));
result = printf("%d %d %s\n", *(unsigned int *)(v1 + 12), *(unsigned int *)(v1 + 8), *(const char **)v1);
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( a1 )
{
v1 = a1;
do
{
func1(*(_QWORD *)(v1 + 16));
result = printf("%d %d %s\n", *(unsigned int *)(v1 + 12), *(unsigned int *)(v1 + 8), *(const char **)v1);
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
return result;
}

original_code:
void treeprint(node_t *p)
{
  if(p != ((void *)0))
    {
      treeprint(p->left);
      printf("%d %d %s\n",p->lvl,p->count,p->word);
      treeprint(p->right);
    }
}

canonical_original_code:
void treeprint(struct node_t *p)
{
  if(p != ((void *)0))
    {
      treeprint(p->left);
      printf("%d %d %s\n",p->lvl,p->count,p->word);
      treeprint(p->right);
    }
}

user_defined_types: struct node_t { char *word; int count; int lvl; struct node_t *left; struct node_t *right; }


decompiled_code:
void *__fastcall strdup_KR(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func2(void *src)
{
size_t v1; // r12
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src) + 1;
v2 = malloc(v1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1);
return v3;
}

original_code:
char *strdup_KR(char *s)
{
  char *p;
  p = (char *)malloc(strlen(s)+1);
  if(p != ((void *)0))
    strcpy(p,s);
  return p;
}

variable_types:
s
char *

variable_types:
p
char *

return_type: char *


talloc

decompiled_code:
void *talloc()
{
return malloc(0x20uLL);
}

canonical_decompiled_code:
void *func3()
{
return malloc(0x20uLL);
}

original_code:
node_t *talloc(void)
{
  return (node_t*) malloc(sizeof(node_t));
}

canonical_original_code:
struct node_t *talloc()
{
  return (struct node_t *) malloc(sizeof(node_t));
}

return_type: struct node_t { char *word; int count; int lvl; struct node_t *left; struct node_t *right; } *


decompiled_code:
int getch_KR()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getchar();
--bufp;
return buf[v0 - 1];
}

canonical_decompiled_code:
int func4()
{
int v0; // eax

v0 = bufp;
if ( bufp <= 0 )
return getchar();
--bufp;
return buf[v0 - 1];
}

original_code:
int getch_KR(void)
{
  return (bufp > 0) ? buf[--bufp]:getchar();
}

canonical_original_code:
int getch_KR()
{
  return (bufp > 0) ? buf[--bufp]:getchar();
}


decompiled_code:
int __fastcall ungetch_KR(char a1)
{
int result; // eax

result = bufp;
if ( bufp > 99 )
return puts("ungetch_KR: too many characters");
buf[bufp] = a1;
bufp = result + 1;
return result;
}

canonical_decompiled_code:
int __fastcall func5(char a1)
{
int result; // eax

result = bufp;
if ( bufp > 99 )
return puts("ungetch_KR: too many characters");
buf[bufp] = a1;
bufp = result + 1;
return result;
}

original_code:
void ungetch_KR(int c)
{
  if (bufp >= 100)
    printf("ungetch_KR: too many characters\n");
  else
    buf[bufp++] = c;
}

variable_types: c int


getword

decompiled_code:
int __fastcall getword(char *a1, int a2)
{
const unsigned __int16 **v2; // rbx
const unsigned __int16 *v3; // r12
int result; // eax
char *v5; // r14
char *v6; // r12
char v7; // al

v2 = _ctype_b_loc();
do
{
v3 = *v2;
result = getch_KR();
}
while ( (v3[result] & 0x2000) != 0 );
v5 = a1;
if ( result != -1 )
{
*a1 = result;
v5 = a1 + 1;
}
if ( ((*v2)[result] & 0x400) != 0 || result == 95 )
{
v6 = &v5[a2 - 2 + 1];
if ( a2 > 1 )
{
while ( 1 )
{
v7 = getch_KR();
*v5 = v7;
if ( ((*v2)[v7] & 8) == 0 && v7 != 95 )
break;
if ( v6 == ++v5 )
goto LABEL_11;
}
ungetch_KR(v7);
}
v6 = v5;
LABEL_11:
*v6 = 0;
result = *a1;
}
else
{
*v5 = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(char *a1, int a2)
{
const unsigned __int16 **v2; // rbx
const unsigned __int16 *v3; // r12
int result; // eax
char *v5; // r14
char *v6; // r12
char v7; // al

v2 = _ctype_b_loc();
do
{
v3 = *v2;
result = func4();
}
while ( (v3[result] & 0x2000) != 0 );
v5 = a1;
if ( result != -1 )
{
*a1 = result;
v5 = a1 + 1;
}
if ( ((*v2)[result] & 0x400) != 0 || result == 95 )
{
v6 = &v5[a2 - 2 + 1];
if ( a2 > 1 )
{
while ( 1 )
{
v7 = func4();
*v5 = v7;
if ( ((*v2)[v7] & 8) == 0 && v7 != 95 )
break;
if ( v6 == ++v5 )
goto LABEL_11;
}
func5(v7);
}
v6 = v5;
LABEL_11:
*v6 = 0;
result = *a1;
}
else
{
*v5 = 0;
}
return result;
}

original_code:
int getword(char *word,int lim)
{
  int c,getch_KR(void);
  void ungetch_KR(int);
  char *w = word;
  while (((*__ctype_b_loc ())[(int) ((c = getch_KR()))] & (unsigned short int) _ISspace))
    ;
  if( c != (-1) )
    *w++ = c;
  if(!(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISalpha)||c == '_')) {
    *w='\0';
    return c;
  }
  for (; --lim > 0;w++)
    {
      *w = getch_KR();
      if(!(((*__ctype_b_loc ())[(int) ((*w))] & (unsigned short int) _ISalnum)||*w=='_')) {
 ungetch_KR(*w);
 break;
      }
    }
  *w='\0';
  return word[0];
}

canonical_original_code:
int getword(char *word, int lim)
{
  int c; int getch_KR();
  void ungetch_KR(int);
  char *w = word;
  while (((*__ctype_b_loc ())[(int) ((c = getch_KR()))] & (unsigned short) _ISspace))
    ;
  if( c != (-1) )
    *w++ = c;
  if(!(((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISalpha)||c == '_')) {
    *w='\0';
    return c;
  }
  for (; --lim > 0;w++)
    {
      *w = getch_KR();
      if(!(((*__ctype_b_loc ())[(int) ((*w))] & (unsigned short) _ISalnum)||*w=='_')) {
 ungetch_KR(*w);
 break;
      }
    }
  *w='\0';
  return word[0];
}

variable_types:
word
char *

variable_types: lim int

variable_types:
w
char *


hash

decompiled_code:
__int64 __fastcall hash(_BYTE *a1)
{
int v1; // eax
unsigned int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 31 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return v2 % 0xA;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
int v1; // eax
unsigned int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 31 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return v2 % 0xA;
}

original_code:
unsigned hash(char *s)
{
  unsigned hashval;
  for(hashval=0;*s != '\0';s++)
    hashval = *s + 31*hashval;
  return hashval % 10;
}

canonical_original_code:
unsigned int hash(char *s)
{
  unsigned int hashval;
  for(hashval=0;*s != '\0';s++)
    hashval = *s + 31*hashval;
  return hashval % 10;
}

variable_types:
hashval
unsigned int

return_type: unsigned int


lookup

decompiled_code:
__int64 __fastcall lookup(char *s2)
{
__int64 i; // r12

for ( i = hashtab[(unsigned int)hash(s2)]; i; i = *(_QWORD *)i )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *s2)
{
__int64 i; // r12

for ( i = hashtab[(unsigned int)func7(s2)]; i; i = *(_QWORD *)i )
{
if ( !strcmp(*(const char **)(i + 8), s2) )
break;
}
return i;
}

original_code:
nlist_t *lookup(char *s)
{
  nlist_t *np;
  for(np=hashtab[hash(s)];np != ((void *)0); np=np->next)
    if(strcmp(np->name,s) == 0)
      return np;
  return ((void *)0);
}

canonical_original_code:
struct nlist_t *lookup(char *s)
{
  struct nlist_t *np;
  for(np=hashtab[hash(s)];np != ((void *)0); np=np->next)
    if(strcmp(np->name,s) == 0)
      return np;
  return ((void *)0);
}

variable_types: struct nlist_t { struct nlist_t *next; char *name; char *defn; } *


rnlist

decompiled_code:
void __fastcall rnlist(void **a1)
{
if ( a1 )
{
if ( *a1 )
rnlist();
free(a1[1]);
free(a1[2]);
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func9(void **a1)
{
if ( a1 )
{
if ( *a1 )
func9();
free(a1[1]);
free(a1[2]);
free(a1);
}
}

original_code:
void rnlist(nlist_t *pn)
{
  if(pn == ((void *)0))
    return;
  if(pn->next != ((void *)0))
    rnlist(pn->next);
  free(pn->name);
  free(pn->defn);
  free(pn);
  pn=((void *)0);
}

canonical_original_code:
void rnlist(struct nlist_t *pn)
{
  if(pn == ((void *)0))
    return;
  if(pn->next != ((void *)0))
    rnlist(pn->next);
  free(pn->name);
  free(pn->defn);
  free(pn);
  pn=((void *)0);
}

user_defined_types: struct nlist_t { struct nlist_t *next; char *name; char *defn; }


releaseHS

decompiled_code:
void releaseHS()
{
void ***v0; // rbx

v0 = (void ***)hashtab;
do
{
if ( *v0 )
rnlist(*v0);
++v0;
}
while ( v0 != (void ***)"%d %d %s\n" );
}

original_code:
void releaseHS(){
  int i;
  for(i=0;i<10;i++){
    if(hashtab[i] != ((void *)0))
      rnlist(hashtab[i]);
  }
}

variable_types: i int


undef

decompiled_code:
__int64 __fastcall undef(char *s1)
{
__int64 v1; // r13
__int64 v2; // rbp
char *v3; // r12
int v4; // er8
__int64 result; // rax

v2 = hashtab[(unsigned int)hash(s1)];
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(char **)(v2 + 8);
v4 = strcmp(s1, v3);
result = *(_QWORD *)v2;
if ( !v4 )
break;
v1 = v2;
if ( !result )
return result;
v2 = *(_QWORD *)v2;
}
*(_QWORD *)v1 = result;
free(v3);
free(*(void **)(v2 + 16));
free((void *)v2);
return *(_QWORD *)v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *s1)
{
__int64 v1; // r13
__int64 v2; // rbp
char *v3; // r12
int v4; // er8
__int64 result; // rax

v2 = hashtab[(unsigned int)func7(s1)];
if ( !v2 )
return 0LL;
while ( 1 )
{
v3 = *(char **)(v2 + 8);
v4 = strcmp(s1, v3);
result = *(_QWORD *)v2;
if ( !v4 )
break;
v1 = v2;
if ( !result )
return result;
v2 = *(_QWORD *)v2;
}
*(_QWORD *)v1 = result;
free(v3);
free(*(void **)(v2 + 16));
free((void *)v2);
return *(_QWORD *)v1;
}

original_code:
nlist_t *undef(char *s)
{
  nlist_t *np,*np_pre;
  for(np=hashtab[hash(s)];np!=((void *)0);np=np->next){
    if(strcmp(s,np->name) == 0){
      np_pre->next = np->next;
      np->next=((void *)0);
      free(np->name);
      free(np->defn);
      free(np);
      return np_pre->next;
    }
    np_pre = np;
  }
  return ((void *)0);
}

canonical_original_code:
struct nlist_t *undef(char *s)
{
  struct nlist_t *np; struct nlist_t *np_pre;
  for(np=hashtab[hash(s)];np!=((void *)0);np=np->next){
    if(strcmp(s,np->name) == 0){
      np_pre->next = np->next;
      np->next=((void *)0);
      free(np->name);
      free(np->defn);
      free(np);
      return np_pre->next;
    }
    np_pre = np;
  }
  return ((void *)0);
}

return_type: struct nlist_t { struct nlist_t *next; char *name; char *defn; } *


printnlist

decompiled_code:
int __fastcall printnlist(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rsi
int result; // eax
_QWORD *v4; // rbx
const char *v5; // rdx
const char *v6; // rsi

if ( a1 )
{
v1 = *(const char **)(a1 + 16);
v2 = *(const char **)(a1 + 8);
if ( !v1 )
v1 = "NULL";
if ( !v2 )
v2 = "NULL";
result = printf("(%s---%s)", v2, v1);
v4 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v5 = (const char *)v4[2];
v6 = (const char *)v4[1];
if ( !v5 )
v5 = "NULL";
if ( !v6 )
v6 = "NULL";
result = printf("->(%s---%s)", v6, v5);
v4 = (_QWORD *)*v4;
}
while ( v4 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
const char *v1; // rdx
const char *v2; // rsi
int result; // eax
_QWORD *v4; // rbx
const char *v5; // rdx
const char *v6; // rsi

if ( a1 )
{
v1 = *(const char **)(a1 + 16);
v2 = *(const char **)(a1 + 8);
if ( !v1 )
v1 = "NULL";
if ( !v2 )
v2 = "NULL";
result = printf("(%s---%s)", v2, v1);
v4 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v5 = (const char *)v4[2];
v6 = (const char *)v4[1];
if ( !v5 )
v5 = "NULL";
if ( !v6 )
v6 = "NULL";
result = printf("->(%s---%s)", v6, v5);
v4 = (_QWORD *)*v4;
}
while ( v4 );
}
}
return result;
}

original_code:
void printnlist(nlist_t* np)
{
  if(np == ((void *)0))
    return;
  char *n="NULL";
  printf("(%s---%s)",(np->name != ((void *)0)? np->name:n),(np->defn != ((void *)0)? np->defn:n));
  nlist_t* mp;
  for(mp=np->next;mp!=((void *)0);mp=mp->next)
    printf("->(%s---%s)",(mp->name!=((void *)0)?mp->name:n),(mp->defn != ((void *)0)? mp->defn:n));
  return;
}

canonical_original_code:
void printnlist(struct nlist_t *np)
{
  if(np == ((void *)0))
    return;
  char *n = "NULL";
  printf("(%s---%s)",(np->name != ((void *)0)? np->name:n),(np->defn != ((void *)0)? np->defn:n));
  struct nlist_t *mp;
  for(mp=np->next;mp!=((void *)0);mp=mp->next)
    printf("->(%s---%s)",(mp->name!=((void *)0)?mp->name:n),(mp->defn != ((void *)0)? mp->defn:n));
  return;
}

variable_types:
n
char *


printHS

decompiled_code:
int printHS()
{
const char *v0; // rbx
__int64 v1; // rdi
int result; // eax

v0 = (const char *)hashtab;
do
{
v1 = *(_QWORD *)v0;
v0 += 8;
printnlist(v1);
result = putchar(10);
}
while ( v0 != "%d %d %s\n" );
return result;
}

canonical_decompiled_code:
int func13()
{
const char *v0; // rbx
__int64 v1; // rdi
int result; // eax

v0 = (const char *)hashtab;
do
{
v1 = *(_QWORD *)v0;
v0 += 8;
func12(v1);
result = putchar(10);
}
while ( v0 != "%d %d %s\n" );
return result;
}

original_code:
void printHS(){
  int i;
  for(i=0;i<10;i++){
    printnlist(hashtab[i]);
    printf("\n");
  }
  return;
}


bs

decompiled_code:
__int64 __fastcall bs(char *s1, __int64 a2, int a3)
{
int v3; // edx
int v4; // ebx
int v5; // er14
int v6; // er12
int v7; // eax

v3 = a3 - 1;
if ( v3 >= 0 )
{
v4 = v3;
v5 = 0;
do
{
while ( 1 )
{
v6 = (v5 + v4) >> 1;
v7 = strcmp(s1, *(const char **)(a2 + 8LL * v6));
if ( v7 >= 0 )
break;
v4 = v6 - 1;
if ( v6 - 1 < v5 )
return (unsigned int)-1;
}
if ( !v7 )
return (unsigned int)v6;
v5 = v6 + 1;
}
while ( v4 >= v6 + 1 );
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, __int64 a2, int a3)
{
int v3; // edx
int v4; // ebx
int v5; // er14
int v6; // er12
int v7; // eax

v3 = a3 - 1;
if ( v3 >= 0 )
{
v4 = v3;
v5 = 0;
do
{
while ( 1 )
{
v6 = (v5 + v4) >> 1;
v7 = strcmp(s1, *(const char **)(a2 + 8LL * v6));
if ( v7 >= 0 )
break;
v4 = v6 - 1;
if ( v6 - 1 < v5 )
return (unsigned int)-1;
}
if ( !v7 )
return (unsigned int)v6;
v5 = v6 + 1;
}
while ( v4 >= v6 + 1 );
}
return (unsigned int)-1;
}

original_code:
int bs(char* query, char** against,int len)
{
  int cond;
  int low,high,mid;
  low = 0;
  high = len-1;
  while (low <= high) {
    mid = (low + high) / 2;
    if ((cond = strcmp(query, *(against + mid) )) < 0)
      high = mid - 1;
    else if (cond > 0)
      low = mid + 1;
    else
      return mid;
  }
  return -1;
}

canonical_original_code:
int bs(char *query, char **against, int len)
{
  int cond;
  int low; int high; int mid;
  low = 0;
  high = len-1;
  while (low <= high) {
    mid = (low + high) / 2;
    if ((cond = strcmp(query, *(against + mid) )) < 0)
      high = mid - 1;
    else if (cond > 0)
      low = mid + 1;
    else
      return mid;
  }
  return -1;
}

variable_types:
query
char *

variable_types:
against
char **

variable_types: len int

variable_types: cond int

variable_types: low int

variable_types: high int

variable_types: mid int


selectionSort

original_code:
void selectionSort(int* array,int n)
{
  int i=0,temp=0,j=0,min_ind=0;
  for(i=0;i<n;i++)
    {
      min_ind=i;
      for(j=i;j<n;j++)
 {
   if(array[j]<array[min_ind]) min_ind=j;
 }
      temp=array[min_ind];
      array[min_ind]=array[i];
      array[i]=temp;
    }
}

canonical_original_code:
void selectionSort(int *array, int n)
{
  int i = 0; int temp = 0; int j = 0; int min_ind = 0;
  for(i=0;i<n;i++)
    {
      min_ind=i;
      for(j=i;j<n;j++)
 {
   if(array[j]<array[min_ind]) min_ind=j;
 }
      temp=array[min_ind];
      array[min_ind]=array[i];
      array[i]=temp;
    }
}

variable_types:
array
int *

variable_types: n int

variable_types: temp int

variable_types: j int


bwt

decompiled_code:
size_t __fastcall bwt(__int64 a1, int a2, __int64 a3)
{
size_t result; // rax
size_t v6; // r13
__int64 v7; // r9
int v8; // esi
char v9; // cl
int v10; // edx
__int64 v11; // r8

result = strlen(prtchr);
if ( result )
{
v6 = result;
v7 = 0LL;
v8 = 0;
do
{
v9 = prtchr[v7];
if ( a2 > 0 )
{
result = 0LL;
do
{
v10 = result + 1;
if ( *(_BYTE *)(a1 + result) == v9 )
{
v11 = v8;
if ( a2 - 1 == (_DWORD)result )
v10 = 0;
++v8;
*(_DWORD *)(a3 + 4 * v11) = v10;
}
++result;
}
while ( a2 != result );
}
++v7;
}
while ( v6 != v7 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(__int64 a1, int a2, __int64 a3)
{
size_t result; // rax
size_t v6; // r13
__int64 v7; // r9
int v8; // esi
char v9; // cl
int v10; // edx
__int64 v11; // r8

result = strlen(prtchr);
if ( result )
{
v6 = result;
v7 = 0LL;
v8 = 0;
do
{
v9 = prtchr[v7];
if ( a2 > 0 )
{
result = 0LL;
do
{
v10 = result + 1;
if ( *(_BYTE *)(a1 + result) == v9 )
{
v11 = v8;
if ( a2 - 1 == (_DWORD)result )
v10 = 0;
++v8;
*(_DWORD *)(a3 + 4 * v11) = v10;
}
++result;
}
while ( a2 != result );
}
++v7;
}
while ( v6 != v7 );
}
return result;
}

original_code:
void bwt(char *str,int len,int *result)
{
  int prtchrNum=strlen(prtchr);
  int i=0,j=0,x=0;
  for(i=0;i<prtchrNum;i++){
    char ch=prtchr[i];
    for(j=0;j<len;j++){
      if(str[j] == ch)
 result[x++]=(j==(len-1)?0:(j+1));
    }
  }
}

canonical_original_code:
void bwt(char *str, int len, int *result)
{
  int prtchrNum = strlen(prtchr);
  int i = 0; int j = 0; int x = 0;
  for(i=0;i<prtchrNum;i++){
    char ch = prtchr[i];
    for(j=0;j<len;j++){
      if(str[j] == ch)
 result[x++]=(j==(len-1)?0:(j+1));
    }
  }
}

variable_types:
str
char *

variable_types:
result
int *

variable_types: prtchrNum int

variable_types: x int

variable_types: ch char


sortstring

decompiled_code:
size_t __fastcall sortstring(__int64 a1, int a2, __int64 a3)
{
size_t result; // rax
size_t v6; // r9
__int64 v7; // r8
int v8; // ecx
char v9; // dl
__int64 v10; // rdi

result = strlen(prtchr);
if ( result )
{
v6 = result;
v7 = 0LL;
v8 = 0;
do
{
v9 = prtchr[v7];
if ( a2 > 0 )
{
for ( result = 0LL; result != a2; ++result )
{
if ( *(_BYTE *)(a1 + result) == v9 )
{
v10 = v8++;
*(_DWORD *)(a3 + 4 * v10) = result;
}
}
}
++v7;
}
while ( v6 != v7 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1, int a2, __int64 a3)
{
size_t result; // rax
size_t v6; // r9
__int64 v7; // r8
int v8; // ecx
char v9; // dl
__int64 v10; // rdi

result = strlen(prtchr);
if ( result )
{
v6 = result;
v7 = 0LL;
v8 = 0;
do
{
v9 = prtchr[v7];
if ( a2 > 0 )
{
for ( result = 0LL; result != a2; ++result )
{
if ( *(_BYTE *)(a1 + result) == v9 )
{
v10 = v8++;
*(_DWORD *)(a3 + 4 * v10) = result;
}
}
}
++v7;
}
while ( v6 != v7 );
}
return result;
}

original_code:
void sortstring(char *str,int len,int *result)
{
  int prtchrNum=strlen(prtchr);
  int i=0,j=0,x=0;
  for(i=0;i<prtchrNum;i++){
    char ch=prtchr[i];
    for(j=0;j<len;j++){
      if(str[j] == ch)
 result[x++]=j;
    }
  }
}

canonical_original_code:
void sortstring(char *str, int len, int *result)
{
  int prtchrNum = strlen(prtchr);
  int i = 0; int j = 0; int x = 0;
  for(i=0;i<prtchrNum;i++){
    char ch = prtchr[i];
    for(j=0;j<len;j++){
      if(str[j] == ch)
 result[x++]=j;
    }
  }
}

variable_types: i int


rstrip

decompiled_code:
const char *__fastcall rstrip(const char *a1)
{
size_t v1; // rax
const char *v2; // rbx
const unsigned __int16 **v3; // rcx
__int64 v4; // rdx

v1 = strlen(a1);
v2 = &a1[v1];
if ( a1 < &a1[v1] )
{
v3 = _ctype_b_loc();
do
{
v4 = *(unsigned __int8 *)--v2;
if ( ((*v3)[v4] & 0x2000) == 0 )
break;
*v2 = 0;
}
while ( a1 != v2 );
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1)
{
size_t v1; // rax
const char *v2; // rbx
const unsigned __int16 **v3; // rcx
__int64 v4; // rdx

v1 = strlen(a1);
v2 = &a1[v1];
if ( a1 < &a1[v1] )
{
v3 = _ctype_b_loc();
do
{
v4 = *(unsigned __int8 *)--v2;
if ( ((*v3)[v4] & 0x2000) == 0 )
break;
*v2 = 0;
}
while ( a1 != v2 );
}
return a1;
}

original_code:
static char* rstrip(char* s)
{
    char* p = s + strlen(s);
    while (p > s && ((*__ctype_b_loc ())[(int) (((unsigned char)(*--p)))] & (unsigned short int) _ISspace))
        *p = '\0';
    return s;
}

canonical_original_code:
static char *rstrip(char *s)
{
    char *p = s + strlen(s);
    while (p > s && ((*__ctype_b_loc ())[(int) (((unsigned char)(*--p)))] & (unsigned short) _ISspace))
        *p = '\0';
    return s;
}

variable_types:
s
char *

variable_types:
p
char *


original_code:
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
                     void* user)
{
    char line[200];
    char section[50] = "";
    char prev_name[50] = "";
    char* start;
    char* end;
    char* name;
    char* value;
    int lineno = 0;
    int error = 0;
    while (reader(line, 200, stream) != ((void *)0)) {
        lineno++;
        start = line;
        if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
                           (unsigned char)start[1] == 0xBB &&
                           (unsigned char)start[2] == 0xBF) {
            start += 3;
        }
        start = lskip(rstrip(start));
        if (*start == ';' || *start == '#') {
        }
        else if (*prev_name && *start && start > line) {
            if (!handler(user, section, prev_name, start) && !error)
                error = lineno;
        }
        else if (*start == '[') {
            end = find_char_or_comment(start + 1, ']');
            if (*end == ']') {
                *end = '\0';
                strncpy0(section, start + 1, sizeof(section));
                *prev_name = '\0';
            }
            else if (!error) {
                error = lineno;
            }
        }
        else if (*start && *start != ';') {
            end = find_char_or_comment(start, '=');
            if (*end != '=') {
                end = find_char_or_comment(start, ':');
            }
            if (*end == '=' || *end == ':') {
                *end = '\0';
                name = rstrip(start);
                value = lskip(end + 1);
                end = find_char_or_comment(value, '\0');
                if (*end == ';')
                    *end = '\0';
                rstrip(value);
                strncpy0(prev_name, name, sizeof(prev_name));
                if (!handler(user, section, name, value) && !error)
                    error = lineno;
            }
            else if (!error) {
                error = lineno;
            }
        }
    }
    return error;
}

canonical_original_code:
int ini_parse_stream(char *(*reader)(char *str, int num, void *stream), void *stream, int (*handler)(void *user, char *section, char *name, char *value), void *user)
{
    char line[200];
    char section[50] = "";
    char prev_name[50] = "";
    char *start;
    char *end;
    char *name;
    char *value;
    int lineno = 0;
    int error = 0;
    while (reader(line, 200, stream) != ((void *)0)) {
        lineno++;
        start = line;
        if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
                           (unsigned char)start[1] == 0xBB &&
                           (unsigned char)start[2] == 0xBF) {
            start += 3;
        }
        start = lskip(rstrip(start));
        if (*start == ';' || *start == '#') {
        }
        else if (*prev_name && *start && start > line) {
            if (!handler(user, section, prev_name, start) && !error)
                error = lineno;
        }
        else if (*start == '[') {
            end = find_char_or_comment(start + 1, ']');
            if (*end == ']') {
                *end = '\0';
                strncpy0(section, start + 1, sizeof(section));
                *prev_name = '\0';
            }
            else if (!error) {
                error = lineno;
            }
        }
        else if (*start && *start != ';') {
            end = find_char_or_comment(start, '=');
            if (*end != '=') {
                end = find_char_or_comment(start, ':');
            }
            if (*end == '=' || *end == ':') {
                *end = '\0';
                name = rstrip(start);
                value = lskip(end + 1);
                end = find_char_or_comment(value, '\0');
                if (*end == ';')
                    *end = '\0';
                rstrip(value);
                strncpy0(prev_name, name, sizeof(prev_name));
                if (!handler(user, section, name, value) && !error)
                    error = lineno;
            }
            else if (!error) {
                error = lineno;
            }
        }
    }
    return error;
}

variable_types: char *(*)(char *str, int num, void *stream)

variable_types:
stream
void *

variable_types: int (*)(void *user, char *section, char *name, char *value)

variable_types:
user
void *

variable_types:
line
char [200]

variable_types:
section
char [50]

variable_types:
start
char *

variable_types:
end
char *

variable_types:
name
char *

variable_types:
value
char *

variable_types: lineno int

variable_types: error int


insertSort

original_code:
void insertSort(int* array,int n)
{
  int sp=1,key=0;
  for(;sp<=n-1;sp++)
    {
      key=*(array+sp);
      int i=sp-1;
      while(i>=0 && *(array+i) > key)
 {
   *(array+i+1)=*(array+i);
   i--;
 }
      *(array+i+1)=key;
    }
}

canonical_original_code:
void insertSort(int *array, int n)
{
  int sp = 1; int key = 0;
  for(;sp<=n-1;sp++)
    {
      key=*(array+sp);
      int i = sp-1;
      while(i>=0 && *(array+i) > key)
 {
   *(array+i+1)=*(array+i);
   i--;
 }
      *(array+i+1)=key;
    }
}

variable_types:
array
int *

variable_types: n int

variable_types: sp int

variable_types: key int


decompiled_code:
_BOOL8 __fastcall check_mp3(_BYTE *a1)
{
char v2; // [rsp+0h] [rbp-4h] BYREF

while ( *a1 )
++a1;
return strcmp(&v2, "mp3") != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
char v2; // [rsp+0h] [rbp-4h] BYREF

while ( *a1 )
++a1;
return strcmp(&v2, "mp3") != 0;
}

original_code:
int check_mp3(char *name)
{
 char buf[4];
 int i;
 while (*name != '\0')
  name++;
 name = name - 3;
 for (i = 0; i < 3; i++) {
  buf[i] = *name;
  name++;
 }
 buf[i] = '\0';
 return strcmp(buf, "mp3");
}

variable_types:
buf
char [4]

variable_types: i int


main

repo: hzcodec/x-plane

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
__int64 v4; // rbx
__int64 v5; // rsi
int *v6; // r12
unsigned int j; // er14
__int64 v8; // rbx
char *v9; // rbp
__int64 v10; // rdx
__int64 v11; // rsi
int i; // [rsp+Ch] [rbp-2Ch] BYREF
char v14; // [rsp+10h] [rbp-28h] BYREF

v3 = -93;
v4 = 0LL;
for ( i = 8402339; ; v3 = *((char *)&i + v4) )
{
printf("dec - indata[%i]: %d\n", (unsigned int)v4, v3);
v5 = (unsigned int)v4++;
printf("hex - indata[%i]: %02x\n\n", v5, v3);
if ( v4 == 4 )
break;
}
v6 = &i;
for ( j = -93; ; j = *(char *)v6 )
{
v8 = 0LL;
v9 = (char *)decimal2binary(j);
printf("Binary string of %d is: %s\n", j, v9);
do
{
v10 = (unsigned int)v9[v8];
v11 = (unsigned int)v8++;
printf("Bit[%d]: %c\n", v11, v10);
}
while ( v8 != 8 );
v6 = (int *)((char *)v6 + 1);
if ( v6 == (int *)&v14 )
break;
}
free(v9);
return 0;
}

original_code:
int main(void) {
    char indata[4] = {163,53,128,0};
    int sign = 0;
    char* p_binvalue;
    for (int i=0; i<4; i++) {
        printf("dec - indata[%i]: %d\n",i,indata[i]);
        printf("hex - indata[%i]: %02x\n\n",i,indata[i]);
    }
    if (indata[0] > 127) {
 sign = 1;
        printf("Value is negative. %d\n",sign);
    }
    for (int j=0; j<4; j++) {
        p_binvalue = decimal2binary(indata[j]);
        printf("Binary string of %d is: %s\n",indata[j],p_binvalue);
        for (int i=0; i<8; i++) {
            printf("Bit[%d]: %c\n",i,p_binvalue[i]);
        }
    }
    free(p_binvalue);
    return 0;
}

canonical_original_code:
int main() {
    char indata[4] = {163,53,128,0};
    int sign = 0;
    char *p_binvalue;
    for (int i = 0; i<4; i++) {
        printf("dec - indata[%i]: %d\n",i,indata[i]);
        printf("hex - indata[%i]: %02x\n\n",i,indata[i]);
    }
    if (indata[0] > 127) {
 sign = 1;
        printf("Value is negative. %d\n",sign);
    }
    for (int j = 0; j<4; j++) {
        p_binvalue = decimal2binary(indata[j]);
        printf("Binary string of %d is: %s\n",indata[j],p_binvalue);
        for (int i = 0; i<8; i++) {
            printf("Bit[%d]: %c\n",i,p_binvalue[i]);
        }
    }
    free(p_binvalue);
    return 0;
}

variable_types:
indata
char [4]

variable_types: sign int

variable_types: j int


inicializar

decompiled_code:
int __fastcall inicializar(int semid)
{
semctl(semid, 0, 17, 0LL);
return semctl(semid, 5, 16, 1LL);
}

canonical_decompiled_code:
int __fastcall func0(int semid)
{
semctl(semid, 0, 17, 0LL);
return semctl(semid, 5, 16, 1LL);
}

original_code:
void inicializar(int sem_id)
{
    union semaphore_union sem_union;
    sem_union.array = 0;
 semctl(sem_id, 0, 17, sem_union);
 sem_union.val = 1;
 semctl(sem_id, 5, 16, sem_union);
}

variable_types: union semaphore_union { int val; struct semid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; } *buf; unsigned short *array; struct seminfo { int semmap; int semmni; int semmns; int semmnu; int semmsl; int semopm; int semume; int semusz; int semvmx; int semaem; } *__buf; }

user_defined_types: union semaphore_union { int val; struct semid_ds *buf; unsigned short *array; struct seminfo *__buf; }

user_defined_types: struct semid_ds { struct ipc_perm sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; }


njugadores

decompiled_code:
int __fastcall njugadores(int a1, unsigned int a2)
{
return semctl(a1, 5, 16, a2);
}

canonical_decompiled_code:
int __fastcall func1(int a1, unsigned int a2)
{
return semctl(a1, 5, 16, a2);
}

original_code:
void njugadores(int sem_id, int n)
{
 union semaphore_union sem_union;
 sem_union.val = n;
 semctl(sem_id, 5, 16, sem_union);
}

user_defined_types: struct seminfo { int semmap; int semmni; int semmns; int semmnu; int semmsl; int semopm; int semume; int semusz; int semvmx; int semaem; }

user_defined_types: struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; }


destruir

decompiled_code:
int __fastcall destruir(int a1)
{
int result; // eax
int *v2; // rax

result = semctl(a1, 0, 0, 0LL);
if ( result == -1 )
{
v2 = _errno_location();
printf("error en la destruccion del semaforo! errno: %d", (unsigned int)*v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int result; // eax
int *v2; // rax

result = semctl(a1, 0, 0, 0LL);
if ( result == -1 )
{
v2 = _errno_location();
printf("error en la destruccion del semaforo! errno: %d", (unsigned int)*v2);
exit(1);
}
return result;
}

original_code:
void destruir (int sem_id) {
    union semaphore_union sem_union;
 if (semctl(sem_id, 0, 0, ((void *)0)) == -1) {
  printf("error en la destruccion del semaforo! errno: %d", (*__errno_location ()));
  exit(1);
 }
}

canonical_original_code:
void destruir(int sem_id) {
    union semaphore_union sem_union;
 if (semctl(sem_id, 0, 0, ((void *)0)) == -1) {
  printf("error en la destruccion del semaforo! errno: %d", (*__errno_location ()));
  exit(1);
 }
}


decompiled_code:
int __fastcall lock_s(int a1, unsigned __int16 a2)
{
int result; // eax
int *v3; // rax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 268500991;
result = semop(a1, &sops, 1uLL);
if ( result == -1 )
{
v3 = _errno_location();
printf("fallo lock %d\n", (unsigned int)*v3);
exit(2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, unsigned __int16 a2)
{
int result; // eax
int *v3; // rax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 268500991;
result = semop(a1, &sops, 1uLL);
if ( result == -1 )
{
v3 = _errno_location();
printf("fallo lock %d\n", (unsigned int)*v3);
exit(2);
}
return result;
}

original_code:
void lock_s(int sem_id, int sem_num)
{
    struct sembuf semaphore;
    semaphore.sem_num = sem_num;
    semaphore.sem_op = -1;
    semaphore.sem_flg = 0x1000;
    if (semop(sem_id, &semaphore, 1) == -1) {
        printf( "fallo lock %d\n", (*__errno_location ()));
        exit(2);
    }
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


decompiled_code:
int __fastcall unlock_s(int a1, unsigned __int16 a2)
{
int result; // eax
int *v3; // rax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 268435457;
result = semop(a1, &sops, 1uLL);
if ( result == -1 )
{
v3 = _errno_location();
printf("fallo unlock %d\n", (unsigned int)*v3);
exit(2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, unsigned __int16 a2)
{
int result; // eax
int *v3; // rax
struct sembuf sops; // [rsp+Ah] [rbp-Eh] BYREF

sops.sem_num = a2;
*(_DWORD *)&sops.sem_op = 268435457;
result = semop(a1, &sops, 1uLL);
if ( result == -1 )
{
v3 = _errno_location();
printf("fallo unlock %d\n", (unsigned int)*v3);
exit(2);
}
return result;
}

original_code:
void unlock_s(int sem_id, int sem_num)
{
    struct sembuf semaphore;
    semaphore.sem_num = sem_num;
    semaphore.sem_op = 1;
    semaphore.sem_flg = 0x1000;
    if (semop(sem_id, &semaphore, 1) == -1) {
        printf("fallo unlock %d\n", (*__errno_location ()));
        exit(2);
    }
}

user_defined_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }


comprobar

decompiled_code:
__int64 __fastcall comprobar(_DWORD *a1)
{
_DWORD *v1; // rax
int v2; // edx

LABEL_1:
if ( a1[1] == -1 )
{
while ( 1 )
;
}
v1 = a1;
v2 = a1[1];
while ( 1 )
{
if ( *v1 != v2 )
goto LABEL_1;
if ( v1 == a1 + 8 )
return 1LL;
v2 = v1[2];
++v1;
if ( v2 == -1 )
goto LABEL_1;
}
}

original_code:
int comprobar(int *tablero){
 int i,j;
 for (i = 0; i < 10; i = i++){
  for(j = 1; j < 10;j++)
   if(tablero[i*10 + j]==-1)
    break;
   else if( !(tablero[i*10 + j] == tablero[i*10 + j - 1]) )
    break;
   else if(j==9){
    return 1;
   }
 }
 for (j = 0; j < 10; j++){
  for(i = 1; i < 10; i++)
   if(tablero[i*10 + j]==-1)
    break;
   else if (tablero[i*10 + j] != tablero[(i-1)*10 + j])
    break;
   else if(i==9){
    return 1;
   }
 }
 for (i=1;i<10;i++){
  if(tablero[i*11]==-1)
   break;
  else if( !(tablero[i*11] == tablero[(i-1)*11]) )
   break;
  else if(i==9){
   return 1;
  }
 }
 for (i=2;i<11;i++){
  if(tablero[i*9]==-1)
   break;
  else if( !(tablero[i*9] == tablero[(i-1)*9]) )
   break;
  else if(i==10){
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int comprobar(int *tablero){
 int i; int j;
 for (i = 0; i < 10; i = i++){
  for(j = 1; j < 10;j++)
   if(tablero[i*10 + j]==-1)
    break;
   else if( !(tablero[i*10 + j] == tablero[i*10 + j - 1]) )
    break;
   else if(j==9){
    return 1;
   }
 }
 for (j = 0; j < 10; j++){
  for(i = 1; i < 10; i++)
   if(tablero[i*10 + j]==-1)
    break;
   else if (tablero[i*10 + j] != tablero[(i-1)*10 + j])
    break;
   else if(i==9){
    return 1;
   }
 }
 for (i=1;i<10;i++){
  if(tablero[i*11]==-1)
   break;
  else if( !(tablero[i*11] == tablero[(i-1)*11]) )
   break;
  else if(i==9){
   return 1;
  }
 }
 for (i=2;i<11;i++){
  if(tablero[i*9]==-1)
   break;
  else if( !(tablero[i*9] == tablero[(i-1)*9]) )
   break;
  else if(i==10){
   return 1;
  }
 }
 return 0;
}

variable_types:
tablero
int *


main

repo: jdubie/cat

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v5; // er12

if ( argc <= 0 )
return -1;
v3 = 1LL;
if ( argc == 1 )
{
v5 = 0;
print_fd(0);
}
else
{
do
{
v5 = print_filename(argv[v3], argv, envp);
if ( v5 == -1 )
{
printf("error opening file %d\n", (unsigned int)v3);
return v5;
}
++v3;
}
while ( argc > (int)v3 );
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v5; // er12

if ( argc <= 0 )
return -1;
v3 = 1LL;
if ( argc == 1 )
{
v5 = 0;
func7(0);
}
else
{
do
{
v5 = func8(argv[v3], argv, envp);
if ( v5 == -1 )
{
printf("error opening file %d\n", (unsigned int)v3);
return v5;
}
++v3;
}
while ( argc > (int)v3 );
v5 = 0;
}
return v5;
}

original_code:
int
main (int argc, char *argv[])
{
  if (argc < 1) {
    return -1;
  } else if (argc == 1) {
    print_fd (0);
  } else {
    int i;
    for (i = 1; i < argc; i++) {
      int status = print_filename (argv[i]);
      if (status == -1) {
        printf ("error opening file %d\n", i);
        return status;
      }
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  if (argc < 1) {
    return -1;
  } else if (argc == 1) {
    print_fd (0);
  } else {
    int i;
    for (i = 1; i < argc; i++) {
      int status = print_filename (argv[i]);
      if (status == -1) {
        printf ("error opening file %d\n", i);
        return status;
      }
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: status int


decompiled_code:
__int64 __fastcall print_fd(int fd)
{
int v1; // ebx
_BYTE v3[280]; // [rsp+0h] [rbp-118h] BYREF

do
{
v1 = read(fd, v3, 0x100uLL);
fwrite(v3, 1uLL, v1, _bss_start);
}
while ( v1 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
int v1; // ebx
_BYTE v3[280]; // [rsp+0h] [rbp-118h] BYREF

do
{
v1 = read(fd, v3, 0x100uLL);
fwrite(v3, 1uLL, v1, _bss_start);
}
while ( v1 );
return 0LL;
}

original_code:
int
print_fd (int fd)
{
  while (1) {
    char buf[256];
    ssize_t bytes_read = read (fd, buf, 256);
    fwrite (buf, sizeof(char), bytes_read, stdout);
    if (bytes_read == 0) break;
  }
  return 0;
}

canonical_original_code:
int print_fd(int fd)
{
  while (1) {
    char buf[256];
    long bytes_read = read (fd, buf, 256);
    fwrite (buf, sizeof(char), bytes_read, stdout);
    if (bytes_read == 0) break;
  }
  return 0;
}

variable_types: fd int

variable_types:
buf
char [256]