decompiled_code:
__int64 __fastcall parse_ascii_diff_record(char *src, int a2, int a3, __int64 a4, int a5)
{
double v5; // xmm0_8
unsigned int v8; // er12
char *v9; // rdi
int v10; // eax
float v11; // xmm3_4
int v12; // ebp
__int64 v13; // rbx
char *v14; // rdi
char *v16; // r15
__int64 v18; // [rsp+10h] [rbp-564h]
int v19; // [rsp+18h] [rbp-55Ch]
char *s2[4]; // [rsp+1Ch] [rbp-558h]
char s1[128]; // [rsp+3Ch] [rbp-538h] BYREF
char s[128]; // [rsp+BCh] [rbp-4B8h] BYREF
char dest[16]; // [rsp+13Ch] [rbp-438h] BYREF
char v24[1008]; // [rsp+14Ch] [rbp-428h] BYREF

v5 = 0.0;
v8 = 0;
memset(v24, 0, sizeof(v24));
v18 = 0x38D1B7173A83126FLL;
s2[0] = (char *)&unk_5421;
s2[1] = (char *)&unk_5423;
s2[2] = (char *)&unk_5425;
v19 = 981668463;
*(_OWORD *)dest = 0LL;
strncpy(dest, src, 0x3FFuLL);
while ( 1 )
{
if ( (int)v8 >= a5 )
goto LABEL_18;
if ( dest[0] )
break;
LABEL_12:
if ( (int)mem_get_line(0LL, dest, 1024LL, v5) <= 0 )
return v8;
}
if ( (unsigned __int8)(dest[0] - 29) <= 1u )
{
ssl_printf("parse_ascii_diff_record() : End of packet. record count = %d\n", v8);
LABEL_18:
mem_unget_line(0LL, dest, v5);
return v8;
}
if ( (int)get_key_common(dest, &unk_5427, s1, v5) < 0 )
{
ssl_printf("parse_ascii_diff_record() : Wrong record. record count = %d\n", v8);
mem_unget_line(0LL, dest, v5);
return v8;
}
if ( !strcmp(s1, s2[a2]) )
{
get_value2_isra_0(dest, s);
ssl_printf("#%d value [%s]\n", v8, s);
v9 = strtok(s, ";");
if ( v9 )
{
v10 = atoi(v9);
HIDWORD(v5) = 0;
v11 = *((float *)&v18 + a2);
v12 = v10;
v13 = (int)(v8 + 1);
*(float *)&v5 = (float)v10 * v11;
*(_DWORD *)(a4 + 4LL * (int)v8) = LODWORD(v5);
if ( a3 )
{
while ( 1 )
{
v8 = v13;
v14 = strtok(0LL, ";");
if ( !v14 )
break;
HIDWORD(v5) = 0;
v12 += atoi(v14);
*(float *)&v5 = (float)v12 * v11;
*(_DWORD *)(a4 + 4 * v13++) = LODWORD(v5);
}
}
else
{
while ( 1 )
{
v8 = v13;
v16 = strtok(0LL, ";");
if ( !v16 )
break;
ssl_printf("#%d prev = %d\n", (unsigned int)v13, (unsigned int)v12);
HIDWORD(v5) = 0;
v12 -= atoi(v16);
*(float *)&v5 = (float)v12 * v11;
*(_DWORD *)(a4 + 4 * v13++) = LODWORD(v5);
}
}
}
goto LABEL_12;
}
ssl_printf("parse_ascii_diff_record() : Wrong label. record count = %d\n", v8);
mem_unget_line(0LL, dest, v5);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, int a2, int a3, __int64 a4, int a5)
{
double v5; // xmm0_8
unsigned int v8; // er12
char *v9; // rdi
int v10; // eax
float v11; // xmm3_4
int v12; // ebp
__int64 v13; // rbx
char *v14; // rdi
char *v16; // r15
__int64 v18; // [rsp+10h] [rbp-564h]
int v19; // [rsp+18h] [rbp-55Ch]
char *s2[4]; // [rsp+1Ch] [rbp-558h]
char s1[128]; // [rsp+3Ch] [rbp-538h] BYREF
char s[128]; // [rsp+BCh] [rbp-4B8h] BYREF
char dest[16]; // [rsp+13Ch] [rbp-438h] BYREF
char v24[1008]; // [rsp+14Ch] [rbp-428h] BYREF

v5 = 0.0;
v8 = 0;
memset(v24, 0, sizeof(v24));
v18 = 0x38D1B7173A83126FLL;
s2[0] = (char *)&unk_5421;
s2[1] = (char *)&unk_5423;
s2[2] = (char *)&unk_5425;
v19 = 981668463;
*(_OWORD *)dest = 0LL;
strncpy(dest, src, 0x3FFuLL);
while ( 1 )
{
if ( (int)v8 >= a5 )
goto LABEL_18;
if ( dest[0] )
break;
LABEL_12:
if ( (int)mem_get_line(0LL, dest, 1024LL, v5) <= 0 )
return v8;
}
if ( (unsigned __int8)(dest[0] - 29) <= 1u )
{
ssl_printf("parse_ascii_diff_record() : End of packet. record count = %d\n", v8);
LABEL_18:
mem_unget_line(0LL, dest, v5);
return v8;
}
if ( (int)get_key_common(dest, &unk_5427, s1, v5) < 0 )
{
ssl_printf("parse_ascii_diff_record() : Wrong record. record count = %d\n", v8);
mem_unget_line(0LL, dest, v5);
return v8;
}
if ( !strcmp(s1, s2[a2]) )
{
func0(dest, s);
ssl_printf("#%d value [%s]\n", v8, s);
v9 = strtok(s, ";");
if ( v9 )
{
v10 = atoi(v9);
HIDWORD(v5) = 0;
v11 = *((float *)&v18 + a2);
v12 = v10;
v13 = (int)(v8 + 1);
*(float *)&v5 = (float)v10 * v11;
*(_DWORD *)(a4 + 4LL * (int)v8) = LODWORD(v5);
if ( a3 )
{
while ( 1 )
{
v8 = v13;
v14 = strtok(0LL, ";");
if ( !v14 )
break;
HIDWORD(v5) = 0;
v12 += atoi(v14);
*(float *)&v5 = (float)v12 * v11;
*(_DWORD *)(a4 + 4 * v13++) = LODWORD(v5);
}
}
else
{
while ( 1 )
{
v8 = v13;
v16 = strtok(0LL, ";");
if ( !v16 )
break;
ssl_printf("#%d prev = %d\n", (unsigned int)v13, (unsigned int)v12);
HIDWORD(v5) = 0;
v12 -= atoi(v16);
*(float *)&v5 = (float)v12 * v11;
*(_DWORD *)(a4 + 4 * v13++) = LODWORD(v5);
}
}
}
goto LABEL_12;
}
ssl_printf("parse_ascii_diff_record() : Wrong label. record count = %d\n", v8);
mem_unget_line(0LL, dest, v5);
return v8;
}

original_code:
int parse_ascii_diff_record(char *first_line, int type, int rev, float *list, int max)
{
 int count = 0;
 char line[1024] = {0, };
 char key[128];
 char value[128];
 char *ptr;
 int prev;
 int roll_back = 0;
 char *type_str[] = {
  "R",
  "A",
  "Z",
 };
 float convert_val[] = {
  1.0/1000.0,
  1.0/10000.0,
  1.0/1000.0,
 };
 strncpy(line, first_line, sizeof(line)-1);
 do {
  if ( count >= max ) {
   roll_back = 1;
   break;
  }
  if ( line[0] == 0 ) {
   continue;
  }
  if ( line[0] == 0x1E || line[0] == 0x1d) {
   ((void (*)(char *, ...))ssl_printf)("parse_ascii_diff_record() : End of packet. record count = %d\n", count);
   roll_back = 1;
   break;
  }
  if ( get_key_common(line, "=", key) < 0 ) {
   ((void (*)(char *, ...))ssl_printf)("parse_ascii_diff_record() : Wrong record. record count = %d\n", count);
   roll_back = 1;
   break;
  }
  if ( strcmp(key, type_str[type]) != 0 ) {
   ((void (*)(char *, ...))ssl_printf)("parse_ascii_diff_record() : Wrong label. record count = %d\n", count);
   roll_back = 1;
   break;
  }
  get_value2(line, value);
  ((void (*)(char *, ...))ssl_printf)("#%d value [%s]\n", count, value);
  ptr = strtok(value, ";");
  if ( !ptr ) {
   continue;
  }
  prev = atoi(ptr);
  list[count] = (float)prev * convert_val[type];
  count++;
  if ( rev ) {
   while ( (ptr = strtok(((void *)0), ";") ) != ((void *)0) ) {
    prev += atoi(ptr);
    list[count] = (float)prev * convert_val[type];
    count++;
   }
  } else {
   while ( (ptr = strtok(((void *)0), ";") ) != ((void *)0) ) {
    ((void (*)(char *, ...))ssl_printf)("#%d prev = %d\n", count, prev);
    prev -= atoi(ptr);
    list[count] = (float)prev * convert_val[type];
    count++;
   }
  }
 } while ( mem_get_line(((void *)0), line, sizeof(line)) > 0 );
 if ( roll_back) {
  mem_unget_line(((void *)0), line);
 }
 return count;
}

variable_types: type int

variable_types: rev int

variable_types:
list
float *

variable_types: max int

variable_types: count int

variable_types:
line
char [1024]

variable_types:
key
char [128]

variable_types:
value
char [128]

variable_types:
ptr
char *

variable_types: prev int


decompiled_code:
__int64 __fastcall parse_angle(__int64 a1, __int64 a2, double a3)
{
int v4; // eax
char src[4]; // [rsp+8h] [rbp-820h] BYREF
char dest[4]; // [rsp+Ch] [rbp-81Ch] BYREF
char v7[1024]; // [rsp+10h] [rbp-818h] BYREF
__int16 v8[524]; // [rsp+410h] [rbp-418h] BYREF

*(_DWORD *)src = 13;
set_parse_param_sep_str(";");
strncpy(dest, &mem_get_line_sep_str, 4uLL);
strncpy(&mem_get_line_sep_str, src, 8uLL);
mem_get_line(a1, v7, 0LL, a3);
if ( (int)mem_get_line(0LL, v7, 1024LL, a3) >= 0 && v7[0] != 29 )
{
if ( v7[0] == 28 )
v7[0] = 32;
if ( (int)get_key_common(v7, &unk_5427, v8, a3) >= 0 && v8[0] == 65 )
{
v4 = parse_ascii_diff_record(v7, 1, 0, a2, 1440);
if ( v4 < 0 )
ssl_printf("iso16824_to_epc_comm_frame_data() : R error. %d\n", (unsigned int)v4);
else
ssl_printf("record count = %d\n", (unsigned int)v4);
}
}
strncpy(&mem_get_line_sep_str, dest, 8uLL);
return set_parse_param_sep_str(" ");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, double a3)
{
int v4; // eax
char src[4]; // [rsp+8h] [rbp-820h] BYREF
char dest[4]; // [rsp+Ch] [rbp-81Ch] BYREF
char v7[1024]; // [rsp+10h] [rbp-818h] BYREF
__int16 v8[524]; // [rsp+410h] [rbp-418h] BYREF

*(_DWORD *)src = 13;
set_parse_param_sep_str(";");
strncpy(dest, &mem_get_line_sep_str, 4uLL);
strncpy(&mem_get_line_sep_str, src, 8uLL);
mem_get_line(a1, v7, 0LL, a3);
if ( (int)mem_get_line(0LL, v7, 1024LL, a3) >= 0 && v7[0] != 29 )
{
if ( v7[0] == 28 )
v7[0] = 32;
if ( (int)get_key_common(v7, &unk_5427, v8, a3) >= 0 && v8[0] == 65 )
{
v4 = func1(v7, 1, 0, a2, 1440);
if ( v4 < 0 )
ssl_printf("iso16824_to_epc_comm_frame_data() : R error. %d\n", (unsigned int)v4);
else
ssl_printf("record count = %d\n", (unsigned int)v4);
}
}
strncpy(&mem_get_line_sep_str, dest, 8uLL);
return set_parse_param_sep_str(" ");
}

original_code:
static void parse_angle(char *buf, float *list)
{
 char epc_comm_cr_str[4] = "\x0d";
 char line_buf[1024];
 char key[1024];
 int ret = 0;
 char prev_sep[4] = {0, };
 int i;
 set_parse_param_sep_str( ";" );
 strncpy(prev_sep, (mem_get_line_sep_str), sizeof(prev_sep));
 do { strncpy(mem_get_line_sep_str, epc_comm_cr_str, 8); } while(0);
 mem_get_line(buf, line_buf, 0);
 for ( i = 0 ; i < 1 ; i ++)
 {
  if ( mem_get_line(((void *)0), line_buf, sizeof(line_buf)) < 0 ) {
   break;
  }
  if ( line_buf[0] == 0x1d ) {
   break;
  }
  if ( line_buf[0] == 0x1c ) {
   line_buf[0] = ' ';
  }
  if ( get_key_common(line_buf, "=", key) < 0 ) {
   continue;
  }
  if ( (strcmp(key, "A") == 0 ) ) {
   if ( ( ret = parse_ascii_diff_record(line_buf, 1, 0, list, 1440)) < 0 ) {
    ((void (*)(char *, ...))ssl_printf)("iso16824_to_epc_comm_frame_data() : R error. %d\n", ret);
    continue;
   }
   ((void (*)(char *, ...))ssl_printf)("record count = %d\n", ret);
   continue;
  }
 }
 do { strncpy(mem_get_line_sep_str, prev_sep, 8); } while(0);
 set_parse_param_sep_str(" ");
}

variable_types:
buf
char *

variable_types:
key
char [1024]

variable_types: ret int

variable_types: i int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v4; // rbx
__int64 v5; // rsi
double v6; // xmm0_8
double v7; // xmm1_8
float v9[1440]; // [rsp+0h] [rbp-2D08h] BYREF
float v10[1442]; // [rsp+1680h] [rbp-1688h] BYREF

v4 = 0LL;
memset(v9, 0, sizeof(v9));
memset(v10, 0, 0x1680uLL);
puts("ASCII diff test");
parse_angle((__int64)normal_angle, (__int64)v9, v3);
parse_angle((__int64)reverse_angle, (__int64)v10, v3);
do
{
v5 = (unsigned int)v4;
v6 = v9[v4];
v7 = v10[v4++];
ssl_printf("[%d] %f %f\n", v5, v6, v7);
}
while ( v4 != 1440 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm0_8
__int64 v4; // rbx
__int64 v5; // rsi
double v6; // xmm0_8
double v7; // xmm1_8
float v9[1440]; // [rsp+0h] [rbp-2D08h] BYREF
float v10[1442]; // [rsp+1680h] [rbp-1688h] BYREF

v4 = 0LL;
memset(v9, 0, sizeof(v9));
memset(v10, 0, 0x1680uLL);
puts("ASCII diff test");
func2((__int64)normal_angle, (__int64)v9, v3);
func2((__int64)reverse_angle, (__int64)v10, v3);
do
{
v5 = (unsigned int)v4;
v6 = v9[v4];
v7 = v10[v4++];
ssl_printf("[%d] %f %f\n", v5, v6, v7);
}
while ( v4 != 1440 );
return 0;
}

original_code:
int main(void)
{
 float normal_list[1440] = { 0.0, };
 float reverse_list[1440] = { 0.0, };
 int i;
 printf("ASCII diff test\n");
 parse_angle(normal_angle, normal_list);
 parse_angle(reverse_angle, reverse_list);
 for ( i = 0 ; i < 1440; i++ )
 {
  ((void (*)(char *, ...))ssl_printf)("[%d] %f %f\n", i, normal_list[i], reverse_list[i]);
 }
 return 0;
}

canonical_original_code:
int main()
{
 float normal_list[1440] = { 0.0, };
 float reverse_list[1440] = { 0.0, };
 int i;
 printf("ASCII diff test\n");
 parse_angle(normal_angle, normal_list);
 parse_angle(reverse_angle, reverse_list);
 for ( i = 0 ; i < 1440; i++ )
 {
  ((void (*)(char *, ...))ssl_printf)("[%d] %f %f\n", i, normal_list[i], reverse_list[i]);
 }
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall read_file(int fd, __int64 a2, int a3)
{
int v3; // ebx
int v4; // er13
int v5; // eax

if ( a3 <= 0 )
{
v4 = 0;
}
else
{
v3 = a3;
v4 = 0;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), v3);
if ( v5 <= 0 )
break;
v4 += v5;
v3 -= v5;
if ( v4 >= v3 )
return (unsigned int)v4;
}
if ( v5 )
v4 = v5;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, int a3)
{
int v3; // ebx
int v4; // er13
int v5; // eax

if ( a3 <= 0 )
{
v4 = 0;
}
else
{
v3 = a3;
v4 = 0;
while ( 1 )
{
v5 = read(fd, (void *)(a2 + v4), v3);
if ( v5 <= 0 )
break;
v4 += v5;
v3 -= v5;
if ( v4 >= v3 )
return (unsigned int)v4;
}
if ( v5 )
v4 = v5;
}
return (unsigned int)v4;
}

original_code:
static int read_file(int fd, unsigned char *buf, int size)
{
 int rd_idx = 0;
 int ret;
 while( rd_idx < size ) {
  ret = read(fd, &buf[rd_idx], size);
  if ( ret <= 0 ) {
   break;
  }
  rd_idx += ret;
  size -= ret;
 }
 if ( ret < 0 ) {
  return ret;
 }
 return rd_idx;
}

variable_types: fd int

variable_types:
buf
unsigned char *

variable_types: size int


repo: newbg/romfser

decompiled_code:
__int64 __fastcall extract_inode(__int64 a1, __int64 a2)
{
const char *v2; // r14
unsigned int v4; // er12
int v5; // er13
const void *v6; // rsi
int v7; // eax
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = (const char *)(a2 + 16);
if ( strcmp((const char *)(a2 + 16), (const char *)(a1 + 8)) )
return (unsigned int)-1;
v4 = 0;
snprintf(v9, 0x400uLL, "./%s%s", (const char *)(a1 + 98), v2);
if ( (_bswap_32(*(_DWORD *)a2) & 7) == 1 )
{
if ( mkdir(v9, 0x1EDu) == -1 )
{
v4 = -1;
perror("mkdir");
}
}
else
{
v5 = open(v9, 65);
if ( v5 == -1 && (v5 = open(v2, 65), v5 == -1) )
{
v4 = -1;
perror("open");
}
else
{
v6 = (const void *)(a2 + ((strlen(v2) + 15) & 0xFFFFFFFFFFFFFFF0LL) + 17);
v7 = _bswap_32(*(_DWORD *)(a2 + 8));
if ( write(v5, v6, v7) == -1 )
{
v4 = -1;
perror("write");
}
else
{
close(v5);
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
const char *v2; // r14
unsigned int v4; // er12
int v5; // er13
const void *v6; // rsi
int v7; // eax
char v9[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = (const char *)(a2 + 16);
if ( strcmp((const char *)(a2 + 16), (const char *)(a1 + 8)) )
return (unsigned int)-1;
v4 = 0;
snprintf(v9, 0x400uLL, "./%s%s", (const char *)(a1 + 98), v2);
if ( (func0(*(_DWORD *)a2) & 7) == 1 )
{
if ( mkdir(v9, 0x1EDu) == -1 )
{
v4 = -1;
perror("mkdir");
}
}
else
{
v5 = open(v9, 65);
if ( v5 == -1 && (v5 = open(v2, 65), v5 == -1) )
{
v4 = -1;
perror("open");
}
else
{
v6 = (const void *)(a2 + ((strlen(v2) + 15) & 0xFFFFFFFFFFFFFFF0LL) + 17);
v7 = func0(*(_DWORD *)(a2 + 8));
if ( write(v5, v6, v7) == -1 )
{
v4 = -1;
perror("write");
}
else
{
close(v5);
}
}
}
return v4;
}

original_code:
int extract_inode(struct func_desc *func, struct romfs_file *file)
{
 int filefd=0,size=0;
 char *writeptr;
 char fpath[1024];
 if (strcmp(file->name, func->name))
  return -1;
 snprintf(fpath, 1024, "./%s%s",func->parentstr, file->name);
 if ((htonl(file->next)&0x7) == ROMFS_DIR)
 {
  if (mkdir(fpath, 0755) == -1)
  {
   perror("mkdir");
   return -1;
  }
 }
 else
 {
  if ((filefd = open(fpath, 0100|01)) == -1)
  {
   if ((filefd = open(file->name, 0100|01)) == -1)
   {
    perror("open");
    return -1;
   }
  }
  writeptr = (char*)((char*)file + sizeof(struct romfs_file)+(((strlen(file->name))+15)&~15)+1);
  size = htonl(file->size);
  if (write(filefd, writeptr, size) == -1)
  {
   perror("write");
   return -1;
  }
  close(filefd);
 }
 return 0;
}

canonical_original_code:
int extract_inode(struct func_desc *func, struct romfs_file *file)
{
 int filefd = 0; int size = 0;
 char *writeptr;
 char fpath[1024];
 if (strcmp(file->name, func->name))
  return -1;
 snprintf(fpath, 1024, "./%s%s",func->parentstr, file->name);
 if ((htonl(file->next)&0x7) == ROMFS_DIR)
 {
  if (mkdir(fpath, 0755) == -1)
  {
   perror("mkdir");
   return -1;
  }
 }
 else
 {
  if ((filefd = open(fpath, 0100|01)) == -1)
  {
   if ((filefd = open(file->name, 0100|01)) == -1)
   {
    perror("open");
    return -1;
   }
  }
  writeptr = (char *)((char *)file + sizeof(struct romfs_file)+(((strlen(file->name))+15)&~15)+1);
  size = htonl(file->size);
  if (write(filefd, writeptr, size) == -1)
  {
   perror("write");
   return -1;
  }
  close(filefd);
 }
 return 0;
}

variable_types: struct func_desc { int (*func)(); char name[45]; char sname[45]; char parentstr[1024]; } *

variable_types: struct romfs_file { unsigned int next; unsigned int spec; unsigned int size; unsigned int check; char name[]; } *

variable_types: filefd int

variable_types:
writeptr
char *

variable_types:
fpath
char [1024]


decompiled_code:
__int64 __fastcall sub_inode(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
unsigned int v4; // ebp
unsigned int v5; // er12
_DWORD *v6; // rbx
unsigned int v7; // eax
unsigned int v8; // edx
__int64 v9; // rdx
size_t v10; // rax
__int64 v11; // [rsp+0h] [rbp-1048h]
char *s; // [rsp+8h] [rbp-1040h]
_QWORD buf[519]; // [rsp+10h] [rbp-1038h] BYREF

s = (char *)(a2 + 16);
if ( strcmp((const char *)(a1 + 8), (const char *)(a2 + 16)) )
return 0;
v4 = 0;
v2 = open((const char *)(a1 + 53), 0);
if ( v2 == -1 )
{
perror("open");
return v2;
}
v5 = 4096;
v6 = (_DWORD *)(a2 + ((strlen(s) + 15) & 0xFFFFFFFFFFFFFFF0LL) + 17);
v7 = _bswap_32(*(_DWORD *)(a2 + 8));
v8 = v7;
if ( v7 <= 0xFFF )
v5 = v7;
while ( v4 < v8 )
{
v11 = v5;
read(v2, buf, v5);
v9 = v11;
if ( v5 < 8 )
{
if ( (v5 & 4) != 0 )
{
*v6 = buf[0];
*(_DWORD *)((char *)v6 + v9 - 4) = *(_DWORD *)((char *)buf + v9 - 4);
}
else if ( v5 )
{
*(_BYTE *)v6 = buf[0];
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)v6 + v9 - 2) = *(_WORD *)((char *)buf + v9 - 2);
}
}
else
{
*(_QWORD *)v6 = buf[0];
*(_QWORD *)((char *)v6 + v9 - 8) = *(char **)((char *)&s + v9);
qmemcpy(
(void *)((unsigned __int64)(v6 + 2) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)buf - ((char *)v6 - ((unsigned __int64)(v6 + 2) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v5 + (_DWORD)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8)) >> 3));
}
v6 = (_DWORD *)((char *)v6 + v9);
v4 += 4096;
v8 = _bswap_32(*(_DWORD *)(a2 + 8));
}
LODWORD(v11) = v8;
v10 = strlen(s);
v2 = msync((void *)a2, (unsigned int)(v11 + 17) + ((v10 + 15) & 0xFFFFFFFFFFFFFFF0LL), 4);
if ( v2 != -1 )
return 0;
perror("msync");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
unsigned int v4; // ebp
unsigned int v5; // er12
_DWORD *v6; // rbx
unsigned int v7; // eax
unsigned int v8; // edx
__int64 v9; // rdx
size_t v10; // rax
__int64 v11; // [rsp+0h] [rbp-1048h]
char *s; // [rsp+8h] [rbp-1040h]
_QWORD buf[519]; // [rsp+10h] [rbp-1038h] BYREF

s = (char *)(a2 + 16);
if ( strcmp((const char *)(a1 + 8), (const char *)(a2 + 16)) )
return 0;
v4 = 0;
v2 = open((const char *)(a1 + 53), 0);
if ( v2 == -1 )
{
perror("open");
return v2;
}
v5 = 4096;
v6 = (_DWORD *)(a2 + ((strlen(s) + 15) & 0xFFFFFFFFFFFFFFF0LL) + 17);
v7 = func0(*(_DWORD *)(a2 + 8));
v8 = v7;
if ( v7 <= 0xFFF )
v5 = v7;
while ( v4 < v8 )
{
v11 = v5;
read(v2, buf, v5);
v9 = v11;
if ( v5 < 8 )
{
if ( (v5 & 4) != 0 )
{
*v6 = buf[0];
*(_DWORD *)((char *)v6 + v9 - 4) = *(_DWORD *)((char *)buf + v9 - 4);
}
else if ( v5 )
{
*(_BYTE *)v6 = buf[0];
if ( (v5 & 2) != 0 )
*(_WORD *)((char *)v6 + v9 - 2) = *(_WORD *)((char *)buf + v9 - 2);
}
}
else
{
*(_QWORD *)v6 = buf[0];
*(_QWORD *)((char *)v6 + v9 - 8) = *(char **)((char *)&s + v9);
qmemcpy(
(void *)((unsigned __int64)(v6 + 2) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)buf - ((char *)v6 - ((unsigned __int64)(v6 + 2) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * ((v5 + (_DWORD)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8)) >> 3));
}
v6 = (_DWORD *)((char *)v6 + v9);
v4 += 4096;
v8 = func0(*(_DWORD *)(a2 + 8));
}
LODWORD(v11) = v8;
v10 = strlen(s);
v2 = msync((void *)a2, (unsigned int)(v11 + 17) + ((v10 + 15) & 0xFFFFFFFFFFFFFFF0LL), 4);
if ( v2 != -1 )
return 0;
perror("msync");
return v2;
}

original_code:
int sub_inode(struct func_desc *func, struct romfs_file *file)
{
 int filefd,i,readsiz=0;
 char *writeptr;
 char readstring[4096];
 if (strcmp(func->name, file->name))
  return 0;
 if ((filefd = open(func->sname, 00)) == -1)
 {
  perror("open");
  return -1;
 }
 writeptr = (char*)((char*)file + sizeof(struct romfs_file)+(((strlen(file->name))+15)&~15)+1);
 readsiz = htonl(file->size)<4096 ? htonl(file->size) : 4096;
 for(i=0;i<htonl(file->size);i+=4096)
 {
  read(filefd, readstring, readsiz);
  memcpy(writeptr, readstring, readsiz);
  writeptr+=readsiz;
 }
 if (msync(file, htonl(file->size)+sizeof(struct romfs_file)+(((strlen(file->name))+15)&~15)+1, 4) == -1)
 {
  perror("msync");
  return -1;
 }
 return 0;
}

canonical_original_code:
int sub_inode(struct func_desc *func, struct romfs_file *file)
{
 int filefd; int i; int readsiz = 0;
 char *writeptr;
 char readstring[4096];
 if (strcmp(func->name, file->name))
  return 0;
 if ((filefd = open(func->sname, 00)) == -1)
 {
  perror("open");
  return -1;
 }
 writeptr = (char *)((char *)file + sizeof(struct romfs_file)+(((strlen(file->name))+15)&~15)+1);
 readsiz = htonl(file->size)<4096 ? htonl(file->size) : 4096;
 for(i=0;i<htonl(file->size);i+=4096)
 {
  read(filefd, readstring, readsiz);
  memcpy(writeptr, readstring, readsiz);
  writeptr+=readsiz;
 }
 if (msync(file, htonl(file->size)+sizeof(struct romfs_file)+(((strlen(file->name))+15)&~15)+1, 4) == -1)
 {
  perror("msync");
  return -1;
 }
 return 0;
}

variable_types: readsiz int

variable_types:
readstring
char [4096]

user_defined_types: struct romfs_file { unsigned int next; unsigned int spec; unsigned int size; unsigned int check; char name[]; }

user_defined_types: struct func_desc { int (*func)(); char name[45]; char sname[45]; char parentstr[1024]; }


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
printf("Exit with error: %s\n", a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
printf("Exit with error: %s\n", a1);
exit(-1);
}

original_code:
void error(char *err)
{
 printf("Exit with error: %s\n", err);
 exit (-1);
}

variable_types:
err
char *


decompiled_code:
__int64 __fastcall print_inode(const char *a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 v4; // rbp
__int64 *v5; // rbx
int v6; // eax
__int64 result; // rax
char v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = 0;
while ( 1 )
{
if ( a2 == v2 )
error("possible borken fs endless loop\n");
v4 = addrptr + a2;
v5 = &exec_funcs;
if ( exec_funcs )
{
do
{
snprintf((char *)v5 + 98, 0x400uLL, "%s", a1);
((void (__fastcall *)(__int64 *, __int64))*v5)(v5, v4);
v5 += 141;
}
while ( *v5 );
}
v6 = _bswap_32(*(_DWORD *)v4);
if ( *(_BYTE *)(v4 + 16) != 46 && (v6 & 7) == 1 )
break;
v2 = a2;
result = v6 & 0x7FFFFFF0;
if ( !(_DWORD)result )
return result;
LABEL_8:
a2 = result;
}
snprintf(v8, 0x400uLL, "%s%s/", a1, (const char *)(v4 + 16));
print_inode(v8, a2 + 32, a2);
result = _bswap_32(*(_DWORD *)v4) & 0x7FFFFFF0;
if ( (_DWORD)result )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 v4; // rbp
__int64 *v5; // rbx
int v6; // eax
__int64 result; // rax
char v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = 0;
while ( 1 )
{
if ( a2 == v2 )
func3("possible borken fs endless loop\n");
v4 = addrptr + a2;
v5 = &exec_funcs;
if ( exec_funcs )
{
do
{
snprintf((char *)v5 + 98, 0x400uLL, "%s", a1);
((void (__fastcall *)(__int64 *, __int64))*v5)(v5, v4);
v5 += 141;
}
while ( *v5 );
}
v6 = func0(*(_DWORD *)v4);
if ( *(_BYTE *)(v4 + 16) != 46 && (v6 & 7) == 1 )
break;
v2 = a2;
result = v6 & 0x7FFFFFF0;
if ( !(_DWORD)result )
return result;
LABEL_8:
a2 = result;
}
snprintf(v8, 0x400uLL, "%s%s/", a1, (const char *)(v4 + 16));
func4(v8, a2 + 32, a2);
result = func0(*(_DWORD *)v4) & 0x7FFFFFF0;
if ( (_DWORD)result )
goto LABEL_8;
return result;
}

original_code:
void print_inode(char *parent, unsigned off, unsigned offparent)
{
 unsigned oldoff=0,i,cnt;
 struct romfs_file *tempfile;
 char customparent[1024];
 for(cnt=0;;cnt++)
 {
  if (oldoff == off)
  {
   error("possible borken fs endless loop\n");
  }
  tempfile = (struct romfs_file*)((char*)addrptr+off);
  for(i=0;exec_funcs[i].func!=((void *)0);i++)
  {
   snprintf(exec_funcs[i].parentstr, 1024, "%s",parent);
   exec_funcs[i].func(&exec_funcs[i], tempfile);
  }
  if (tempfile->name[0] != '.' && (htonl(tempfile->next)&0x7) == ROMFS_DIR)
  {
   snprintf(customparent, 1024, "%s%s/",parent,tempfile->name);
   print_inode(customparent, off+32, off);
  }
  oldoff = off;
  off = (htonl(tempfile->next)&0x7ffffff0);
  if (off == 0)
  {
   return;
  }
 }
}

canonical_original_code:
void print_inode(char *parent, unsigned int off, unsigned int offparent)
{
 unsigned int oldoff = 0; unsigned int i; unsigned int cnt;
 struct romfs_file *tempfile;
 char customparent[1024];
 for(cnt=0;;cnt++)
 {
  if (oldoff == off)
  {
   error("possible borken fs endless loop\n");
  }
  tempfile = (struct romfs_file *)((char *)addrptr+off);
  for(i=0;exec_funcs[i].func!=((void *)0);i++)
  {
   snprintf(exec_funcs[i].parentstr, 1024, "%s",parent);
   exec_funcs[i].func(&exec_funcs[i], tempfile);
  }
  if (tempfile->name[0] != '.' && (htonl(tempfile->next)&0x7) == ROMFS_DIR)
  {
   snprintf(customparent, 1024, "%s%s/",parent,tempfile->name);
   print_inode(customparent, off+32, off);
  }
  oldoff = off;
  off = (htonl(tempfile->next)&0x7ffffff0);
  if (off == 0)
  {
   return;
  }
 }
}

variable_types:
parent
char *

variable_types:
off
unsigned int

variable_types:
offparent
unsigned int

variable_types:
oldoff
unsigned int

variable_types:
i
unsigned int

variable_types:
cnt
unsigned int

variable_types:
customparent
char [1024]


decompiled_code:
__int64 __fastcall count_slashes(char *a1)
{
char v1; // al
unsigned int v2; // er8
__int64 v3; // rdx

v1 = *a1;
v2 = 0;
if ( *a1 )
{
LODWORD(v3) = 0;
do
{
v2 += v1 == 92;
v3 = (unsigned int)(v3 + 1);
v1 = a1[v3];
}
while ( v1 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1)
{
char v1; // al
unsigned int v2; // er8
__int64 v3; // rdx

v1 = *a1;
v2 = 0;
if ( *a1 )
{
LODWORD(v3) = 0;
do
{
v2 += v1 == 92;
v3 = (unsigned int)(v3 + 1);
v1 = a1[v3];
}
while ( v1 );
}
return v2;
}

original_code:
unsigned count_slashes(char *str)
{
 unsigned i,slashes;
 for(i=0,slashes=0;str[i]!=0;i++)
  if (str[i] == '\\')
   slashes++;
 return slashes;
}

canonical_original_code:
unsigned int count_slashes(char *str)
{
 unsigned int i; unsigned int slashes;
 for(i=0,slashes=0;str[i]!=0;i++)
  if (str[i] == '\\')
   slashes++;
 return slashes;
}

variable_types:
str
char *

variable_types:
slashes
unsigned int

return_type: unsigned int


original_code:
size_t my_strlcpy(char *d, char *s, size_t len)
{
 size_t cnt;
 if (!len)
  return 0;
 for (cnt = 0; cnt < len-1 && cnt < strlen(s); cnt++)
  d[cnt] = s[cnt];
 d[cnt] = '\0';
 return cnt;
}

canonical_original_code:
unsigned long my_strlcpy(char *d, char *s, unsigned long len)
{
 unsigned long cnt;
 if (!len)
  return 0;
 for (cnt = 0; cnt < len-1 && cnt < strlen(s); cnt++)
  d[cnt] = s[cnt];
 d[cnt] = '\0';
 return cnt;
}

variable_types:
d
char *

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
cnt
unsigned long

return_type: unsigned long


report

original_code:
int report(struct func_desc *func, struct romfs_file *file)
{
 char tempname[1024];
 if (file->name[0] != '.')
  snprintf(tempname, sizeof(tempname), "%s%s",func->parentstr,file->name);
 else
  my_strlcpy(tempname, file->name, 1024);
 printf("%-45s", tempname);
 printf("%-15u", htonl(file->next)&0x7ffffff0);
 printf("%-15u", htonl(file->size));
 printf("%-15s", specs[(htonl(file->next)&0x7)]);
 printf("%-10s\n", (htonl(file->next)&ROMFS_EXEC) ? "Yes" : "No");
 return 0;
}

variable_types: struct func_desc { int (*func)(); char name[45]; char sname[45]; char parentstr[1024]; } *

variable_types: struct romfs_file { unsigned int next; unsigned int spec; unsigned int size; unsigned int check; char name[]; } *

variable_types:
tempname
char [1024]


decompiled_code:
__int64 __fastcall extract_image(__int64 a1, __int64 a2)
{
if ( strlen((const char *)(a2 + 16)) <= 2 && *(_BYTE *)(a2 + 16) == 46 )
return 0LL;
my_strlcpy((_BYTE *)(a1 + 8), (const char *)(a2 + 16), 45LL);
return extract_inode(a1, a2);
}

original_code:
int extract_image(struct func_desc *func, struct romfs_file *file)
{
 if (strlen(file->name) <= 2 && file->name[0] == '.')
  return 0;
 my_strlcpy(func->name, file->name, 45);
 return extract_inode(func, file);
}


main

repo: newnuy/ttpm

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 2
&& (*(_QWORD *)&argc = argv[1], argv = (const char **)"--version", !strcmp(*(const char **)&argc, "--version")) )
{
printVersion();
}
else
{
startMenu(*(_QWORD *)&argc, argv, envp);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc == 2 && strcmp(*++argv, "--version") == 0) {
        printVersion();
        return 0;
    }
    startMenu();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


isTwoDoubleNumEqual

decompiled_code:
_BOOL8 __fastcall isTwoDoubleNumEqual(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a2) & LC0) < 0.00001;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(double a1, double a2)
{
return COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a1 - a2) & LC0) < 0.00001;
}

original_code:
int isTwoDoubleNumEqual(double d1, double d2)
{
    if (fabs(d1 - d2) < 1e-5)
        return 1;
    else
        return 0;
}


pauseUntilStdInputEnter

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

printf("\nInput Enter to Return...");
do
result = getchar();
while ( result != 10 );
return result;
}

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

printf("\nInput Enter to Return...");
do
result = getchar();
while ( result != 10 );
return result;
}

original_code:
void pauseUntilStdInputEnter(void)
{
    printf("\nInput Enter to Return...");
    while (getchar() != '\n')
        ;
}

canonical_original_code:
void pauseUntilStdInputEnter()
{
    printf("\nInput Enter to Return...");
    while (getchar() != '\n')
        ;
}


discardStdinEnter

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

do
result = getchar();
while ( result != 10 );
return result;
}

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

do
result = getchar();
while ( result != 10 );
return result;
}

original_code:
void discardStdinEnter(void)
{
    while (getchar() != '\n')
        ;
}

canonical_original_code:
void discardStdinEnter()
{
    while (getchar() != '\n')
        ;
}


repo: nezumisama/glmpdvis

original_code:
int parse_cmd_arg(int argc, char **argv, cmd_arg_config *conf) {
    --argc;
    while (argc) {
        ++argv;
        if (!strcmp(*argv, "-c")) {
            if (--argc) {
                ++argv;
                conf->config_file_path = *argv;
                --argc;
            } else return 1;
            continue;
        }
        if (!strcmp(*argv, "-h")) {
            --argc;
            conf->helpfun(conf->helpfundat);
            continue;
        }
        if (!strcmp(*argv, "-v")) {
            --argc;
            conf->verfun(conf->verfundat);
            continue;
        }
    }
    return 0;
}

canonical_original_code:
int parse_cmd_arg(int argc, char **argv, struct cmd_arg_config *conf) {
    --argc;
    while (argc) {
        ++argv;
        if (!strcmp(*argv, "-c")) {
            if (--argc) {
                ++argv;
                conf->config_file_path = *argv;
                --argc;
            } else return 1;
            continue;
        }
        if (!strcmp(*argv, "-h")) {
            --argc;
            conf->helpfun(conf->helpfundat);
            continue;
        }
        if (!strcmp(*argv, "-v")) {
            --argc;
            conf->verfun(conf->verfundat);
            continue;
        }
    }
    return 0;
}

variable_types:
argv
char **

variable_types: struct cmd_arg_config { char *config_file_path; void (*helpfun)(void *data); void *helpfundat; } *


decompiled_code:
void __fastcall __noreturn cmd_arg_default_helpfun(const char *a1)
{
printf(
"Usage: %s [OPTION]\n"
"\t-h - help (this text)\n"
"\t-v - version information\n"
"\t-c filename - use configuration file \"filename\"\n",
a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
printf(
"Usage: %s [OPTION]\n"
"\t-h - help (this text)\n"
"\t-v - version information\n"
"\t-c filename - use configuration file \"filename\"\n",
a1);
exit(0);
}

original_code:
void cmd_arg_default_helpfun(void *data) {
    char * name = (char *) data;
    printf("Usage: %s [OPTION]\n"
           "\t-h - help (this text)\n"
           "\t-v - version information\n"
           "\t-c filename - use configuration file \"filename\"\n", name);
    exit(0);
}

canonical_original_code:
void cmd_arg_default_helpfun(void *data) {
    char *name = (char *) data;
    printf("Usage: %s [OPTION]\n"
           "\t-h - help (this text)\n"
           "\t-v - version information\n"
           "\t-c filename - use configuration file \"filename\"\n", name);
    exit(0);
}

variable_types:
data
void *

variable_types:
name
char *


decompiled_code:
__int64 __fastcall config_parser_parse(const char *a1, __int64 a2)
{
int v2; // eax
int *v3; // rsi
int v4; // edx
int v6; // [rsp+0h] [rbp-18h] BYREF
__int64 v7; // [rsp+8h] [rbp-10h]

v2 = *(_DWORD *)(a2 + 16);
v7 = a2;
if ( v2 )
{
v3 = (int *)(a2 + 64);
v2 = 0;
do
{
v4 = *v3;
v3 += 12;
++v2;
}
while ( v4 );
}
v6 = v2;
return config_parser_parse_low(
a1,
(void (__fastcall *)(char *, char *, __int64))config_parser_def_option_callback,
(__int64)&v6);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2)
{
int v2; // eax
int *v3; // rsi
int v4; // edx
int v6; // [rsp+0h] [rbp-18h] BYREF
__int64 v7; // [rsp+8h] [rbp-10h]

v2 = *(_DWORD *)(a2 + 16);
v7 = a2;
if ( v2 )
{
v3 = (int *)(a2 + 64);
v2 = 0;
do
{
v4 = *v3;
v3 += 12;
++v2;
}
while ( v4 );
}
v6 = v2;
return func0(
a1,
(void (__fastcall *)(char *, char *, __int64))config_parser_def_option_callback,
(__int64)&v6);
}

original_code:
int config_parser_parse(const char * filename,
                        config_parser_option * options) {
    config_parser_options opts;
    int i = 0;
    opts.options = options;
    while (options[i].type) ++i;
    opts.n = i;
    return config_parser_parse_low(filename, config_parser_def_option_callback,
                                   &opts);
}

canonical_original_code:
int config_parser_parse(char *filename, struct config_parser_option *options) {
    struct config_parser_options opts;
    int i = 0;
    opts.options = options;
    while (options[i].type) ++i;
    opts.n = i;
    return config_parser_parse_low(filename, config_parser_def_option_callback,
                                   &opts);
}

variable_types:
filename
char *

variable_types: struct config_parser_options { int n; struct config_parser_option { char *name; void *ptr; int type; char *default_val; char **enum_ptr; int filled; } *options; }

variable_types: i int

user_defined_types: struct config_parser_options { int n; struct config_parser_option *options; }


decompiled_code:
int __fastcall config_parser_bool_parser(char *s1, _DWORD *a2)
{
const char *v3; // rsi
char **v4; // r12
int result; // eax
const char *v6; // rsi
char **v7; // r12

v3 = true_strings_1[0];
if ( true_strings_1[0] )
{
v4 = true_strings_1;
while ( 1 )
{
result = strcmp(s1, v3);
if ( !result )
break;
v3 = v4[1];
++v4;
if ( !v3 )
goto LABEL_6;
}
*a2 = 1;
}
else
{
LABEL_6:
v6 = false_strings_0[0];
if ( false_strings_0[0] )
{
v7 = false_strings_0;
while ( 1 )
{
result = strcmp(s1, v6);
if ( !result )
break;
v6 = v7[1];
++v7;
if ( !v6 )
goto LABEL_11;
}
*a2 = 0;
}
else
{
LABEL_11:
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1, _DWORD *a2)
{
const char *v3; // rsi
char **v4; // r12
int result; // eax
const char *v6; // rsi
char **v7; // r12

v3 = true_strings_1[0];
if ( true_strings_1[0] )
{
v4 = true_strings_1;
while ( 1 )
{
result = strcmp(s1, v3);
if ( !result )
break;
v3 = v4[1];
++v4;
if ( !v3 )
goto LABEL_6;
}
*a2 = 1;
}
else
{
LABEL_6:
v6 = false_strings_0[0];
if ( false_strings_0[0] )
{
v7 = false_strings_0;
while ( 1 )
{
result = strcmp(s1, v6);
if ( !result )
break;
v6 = v7[1];
++v7;
if ( !v6 )
goto LABEL_11;
}
*a2 = 0;
}
else
{
LABEL_11:
result = -1;
}
}
return result;
}

original_code:
int config_parser_bool_parser(char* data, int* out) {
    static char * true_strings[] = { "true", "yes", 0 };
    static char * false_strings[] = { "false", "no", 0 };
    char **s = &true_strings[0];
    while (*s) {
        if (!strcmp(data, *s)) {
            *out = 1;
            return 0;
        }
        ++s;
    }
    s = &false_strings[0];
    while (*s) {
        if (!strcmp(data, *s)) {
            *out = 0;
            return 0;
        }
        ++s;
    }
    return -1;
}

canonical_original_code:
int config_parser_bool_parser(char *data, int *out) {
    static char *true_strings[] = { "true", "yes", 0 };
    static char *false_strings[] = { "false", "no", 0 };
    char **s = &true_strings[0];
    while (*s) {
        if (!strcmp(data, *s)) {
            *out = 1;
            return 0;
        }
        ++s;
    }
    s = &false_strings[0];
    while (*s) {
        if (!strcmp(data, *s)) {
            *out = 0;
            return 0;
        }
        ++s;
    }
    return -1;
}

variable_types:
data
char *

variable_types:
out
int *

variable_types:
s
char **


canonical_original_code:
int config_parser_color_parser(char *data, struct color *out) {
    unsigned int r; unsigned int g; unsigned int b; unsigned int a;
    if (sscanf(data, "%2x%2x%2x", &r, &g, &b) < 3) return -1;
    if (sscanf(data + 6, "%2x", &a) != 1) a = 0xff;
    out->r = r*0.00392156862745098; out->g = g*0.00392156862745098;
    out->b = b*0.00392156862745098; out->a = a*0.00392156862745098;
    return 0;
}

variable_types:
out
struct color { float r; } *

variable_types:
r
unsigned int

variable_types:
g
unsigned int

variable_types:
b
unsigned int

variable_types:
a
unsigned int


decompiled_code:
int __fastcall config_parser_def_option_callback(char *s1, char *a2, int *a3)
{
_DWORD *v3; // rax
__int64 v4; // r15
__int64 v6; // r12
unsigned __int64 v7; // rbx
__int64 v8; // r13
unsigned __int64 v9; // rbx
size_t v10; // rax
void **v11; // rbp
unsigned __int64 v12; // rbx
int v14; // [rsp+1Ch] [rbp-3Ch] BYREF

v3 = (_DWORD *)*a3;
if ( (int)v3 > 0 )
{
v4 = *((_QWORD *)a3 + 1);
v6 = 48LL * (_QWORD)v3;
v7 = 0LL;
while ( 1 )
{
v8 = v4 + v7;
LODWORD(v3) = strcmp(s1, *(const char **)(v4 + v7));
if ( !(_DWORD)v3 )
break;
v7 += 48LL;
if ( v7 == v6 )
return (int)v3;
}
LODWORD(v3) = *(_DWORD *)(v8 + 16);
switch ( (int)v3 )
{
case 1:
v10 = strlen(a2);
v11 = *(void ***)(v8 + 8);
*v11 = malloc(v10 + 1);
strcpy(**(char ***)(v8 + 8), a2);
v3 = (_DWORD *)*((_QWORD *)a3 + 1);
v3[v7 / 4 + 10] = 1;
break;
case 2:
LODWORD(v3) = _isoc99_sscanf(a2, "%d", &v14);
if ( (_DWORD)v3 )
{
v9 = *((_QWORD *)a3 + 1) + v7;
v3 = *(_DWORD **)(v9 + 8);
*v3 = v14;
*(_DWORD *)(v9 + 40) = 1;
}
break;
case 3:
LODWORD(v3) = _isoc99_sscanf(a2, "%f", &v14);
if ( (_DWORD)v3 )
{
v12 = *((_QWORD *)a3 + 1) + v7;
v3 = *(_DWORD **)(v12 + 8);
*v3 = v14;
*(_DWORD *)(v12 + 40) = 1;
}
break;
case 4:
LODWORD(v3) = config_parser_color_parser((__int64)a2, *(_QWORD *)(v8 + 8));
if ( !(_DWORD)v3 )
goto LABEL_7;
break;
case 5:
LODWORD(v3) = config_parser_bool_parser(a2, *(_DWORD **)(v8 + 8));
if ( !(_DWORD)v3 )
{
LABEL_7:
v3 = (_DWORD *)*((_QWORD *)a3 + 1);
v3[v7 / 4 + 10] = 1;
}
break;
default:
return (int)v3;
}
}
return (int)v3;
}

original_code:
void config_parser_def_option_callback(char * name, char * value, void* data) {
    config_parser_options * opts = data;
    int ival;
    float fval;
    for (int i = 0; i < opts->n; ++i) {
        if (!strcmp(name, opts->options[i].name)) {
            switch (opts->options[i].type) {
                case 1:
                    *((char **) opts->options[i].ptr) = malloc(strlen(value)
                                                               + 1);
                    strcpy(*((char **) opts->options[i].ptr), value);
                    opts->options[i].filled = 1;
                    break;
                case 2:
                    if (sscanf(value, "%d", &ival)) {
                        *((int*) opts->options[i].ptr) = ival;
                        opts->options[i].filled = 1;
                    }
                    break;
                case 3:
                    if (sscanf(value, "%f", &fval)) {
                        *((float*) opts->options[i].ptr) = fval;
                        opts->options[i].filled = 1;
                    }
                    break;
                case 5:
                    if (!config_parser_bool_parser(value, ((int*) opts-> options[i].ptr)))
                        opts->options[i].filled = 1;
                    break;
                case 4:
                    if (!config_parser_color_parser(value, ((color*) opts-> options[i].ptr)))
                        opts->options[i].filled = 1;
                    break;
            }
            break;
        }
    }
}

canonical_original_code:
void config_parser_def_option_callback(char *name, char *value, void *data) {
    struct config_parser_options *opts = data;
    int ival;
    float fval;
    for (int i = 0; i < opts->n; ++i) {
        if (!strcmp(name, opts->options[i].name)) {
            switch (opts->options[i].type) {
                case 1:
                    *((char **) opts->options[i].ptr) = malloc(strlen(value)
                                                               + 1);
                    strcpy(*((char **) opts->options[i].ptr), value);
                    opts->options[i].filled = 1;
                    break;
                case 2:
                    if (sscanf(value, "%d", &ival)) {
                        *((int *) opts->options[i].ptr) = ival;
                        opts->options[i].filled = 1;
                    }
                    break;
                case 3:
                    if (sscanf(value, "%f", &fval)) {
                        *((float *) opts->options[i].ptr) = fval;
                        opts->options[i].filled = 1;
                    }
                    break;
                case 5:
                    if (!config_parser_bool_parser(value, ((int *) opts-> options[i].ptr)))
                        opts->options[i].filled = 1;
                    break;
                case 4:
                    if (!config_parser_color_parser(value, ((struct color *) opts-> options[i].ptr)))
                        opts->options[i].filled = 1;
                    break;
            }
            break;
        }
    }
}

variable_types:
value
char *

variable_types: struct config_parser_options { int n; struct config_parser_option { char *name; void *ptr; int type; char *default_val; char **enum_ptr; int filled; } *options; } *

variable_types: ival int

variable_types: fval float


decompiled_code:
void __fastcall config_parser_fill_defaults(__int64 a1)
{
int v1; // esi
__int64 v2; // rbx
int *v3; // rax
int v4; // edx
int v5; // ecx
int v6; // eax
char *v7; // rsi
char *v8; // rdi
int v9; // [rsp+0h] [rbp-18h] BYREF
__int64 v10; // [rsp+8h] [rbp-10h]

v1 = *(_DWORD *)(a1 + 16);
v10 = a1;
if ( v1 )
{
v2 = a1;
v3 = (int *)(a1 + 64);
v4 = 0;
do
{
v5 = *v3;
v3 += 12;
++v4;
}
while ( v5 );
v9 = v4;
do
{
while ( *(_DWORD *)(v2 + 40) )
{
v6 = *(_DWORD *)(v2 + 64);
v2 += 48LL;
if ( !v6 )
return;
}
v7 = *(char **)(v2 + 24);
v8 = *(char **)v2;
v2 += 48LL;
config_parser_def_option_callback(v8, v7, &v9);
}
while ( *(_DWORD *)(v2 + 16) );
}
}

original_code:
void config_parser_fill_defaults(config_parser_option * options) {
    config_parser_option *o = &options[0];
    config_parser_options opts;
    int i = 0;
    opts.options = options;
    while (options[i].type) ++i;
    opts.n = i;
    while (o->type != 0) {
        if (!o->filled) {
            config_parser_def_option_callback((char*) o->name,
                                              (char*) o->default_val, &opts);
        }
        ++o;
    }
}

canonical_original_code:
void config_parser_fill_defaults(struct config_parser_option *options) {
    struct config_parser_option *o = &options[0];
    struct config_parser_options opts;
    int i = 0;
    opts.options = options;
    while (options[i].type) ++i;
    opts.n = i;
    while (o->type != 0) {
        if (!o->filled) {
            config_parser_def_option_callback((char *) o->name,
                                              (char *) o->default_val, &opts);
        }
        ++o;
    }
}

variable_types: struct config_parser_option { char *name; void *ptr; int type; char *default_val; char **enum_ptr; int filled; } *


decompiled_code:
__int64 __fastcall config_parser_load_config(const char *a1, __int64 a2)
{
unsigned int v2; // er12

v2 = config_parser_parse(a1, a2);
if ( !v2 )
config_parser_fill_defaults(a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, __int64 a2)
{
unsigned int v2; // er12

v2 = func1(a1, a2);
if ( !v2 )
func5(a2);
return v2;
}

original_code:
int config_parser_load_config(const char* filename,
                              config_parser_option *options) {
    int ret = config_parser_parse(filename, options);
    if (ret) return ret;
    config_parser_fill_defaults(options);
    return 0;
}

canonical_original_code:
int config_parser_load_config(char *filename, struct config_parser_option *options) {
    int ret = config_parser_parse(filename, options);
    if (ret) return ret;
    config_parser_fill_defaults(options);
    return 0;
}

variable_types: ret int

user_defined_types: struct config_parser_option { char *name; void *ptr; int type; char *default_val; char **enum_ptr; int filled; }


repo: nfd/filepirate

original_code:
static inline _Bool fp_strstr(unsigned int dirname_len, char *dirname,
  unsigned int filename_len, char *filename,
  unsigned int needle_len, char *needle,
  int *goodness)
{
 int idx_hay = filename_len, idx_needle = needle_len, contig = 0, contig_filename = 0;
 char *hay = filename;
 int last_match_idx = idx_hay;
 while (1) {
  if (idx_hay == -1) {
   if (hay == filename) {
    hay = dirname;
    idx_hay = dirname_len;
    last_match_idx = -1;
    contig_filename = contig;
    contig = 0;
   } else {
    break;
   }
  }
  if (idx_needle == -1) {
   break;
  }
  if (hay[idx_hay] == needle[idx_needle]) {
   idx_needle --;
   if (idx_hay + 1 == last_match_idx)
    contig ++;
   last_match_idx = idx_hay;
  }
  idx_hay --;
 }
 if (goodness) {
  *goodness = contig_filename + contig;
 }
 return idx_needle == -1;
}

canonical_original_code:
static inline _Bool fp_strstr(unsigned int dirname_len, char *dirname, unsigned int filename_len, char *filename, unsigned int needle_len, char *needle, int *goodness)
{
 int idx_hay = filename_len; int idx_needle = needle_len; int contig = 0; int contig_filename = 0;
 char *hay = filename;
 int last_match_idx = idx_hay;
 while (1) {
  if (idx_hay == -1) {
   if (hay == filename) {
    hay = dirname;
    idx_hay = dirname_len;
    last_match_idx = -1;
    contig_filename = contig;
    contig = 0;
   } else {
    break;
   }
  }
  if (idx_needle == -1) {
   break;
  }
  if (hay[idx_hay] == needle[idx_needle]) {
   idx_needle --;
   if (idx_hay + 1 == last_match_idx)
    contig ++;
   last_match_idx = idx_hay;
  }
  idx_hay --;
 }
 if (goodness) {
  *goodness = contig_filename + contig;
 }
 return idx_needle == -1;
}

variable_types:
dirname
char *

variable_types:
filename
char *

variable_types:
needle
char *

variable_types:
goodness
int *

variable_types: contig int

variable_types:
hay
char *


decompiled_code:
__int64 __fastcall try_pool_alloc(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rsi

result = *(_QWORD *)(a1 + 8);
v3 = result + a2;
if ( *(_QWORD *)(a1 + 16) < v3 )
return 0LL;
*(_QWORD *)(a1 + 8) = v3;
if ( !result )
_assert_fail("mem != 0", "cfilepirate.c", 0x64u, "try_pool_alloc");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int64 v3; // rsi

result = *(_QWORD *)(a1 + 8);
v3 = result + a2;
if ( *(_QWORD *)(a1 + 16) < v3 )
return 0LL;
*(_QWORD *)(a1 + 8) = v3;
if ( !result )
_assert_fail("mem != 0", "cfilepirate.c", 0x64u, "try_pool_alloc");
return result;
}

original_code:
static uintptr_t try_pool_alloc(struct memory_pool *pool, size_t size)
{
 uintptr_t pool_next_next = pool->next + size;
 if(pool_next_next > pool->size) {
  return 0;
 } else {
  uintptr_t mem = pool->next;
  pool->next = pool_next_next;
  ((mem != 0) ? (void) (0) : __assert_fail ("mem != 0", "cfilepirate.c", 100, __extension__ __PRETTY_FUNCTION__));
  return mem;
 }
}

canonical_original_code:
static unsigned long try_pool_alloc(struct memory_pool *pool, unsigned long size)
{
 unsigned long pool_next_next = pool->next + size;
 if(pool_next_next > pool->size) {
  return 0;
 } else {
  unsigned long mem = pool->next;
  pool->next = pool_next_next;
  ((mem != 0) ? (void) (0) : __assert_fail ("mem != 0", "cfilepirate.c", 100, __extension__ __PRETTY_FUNCTION__));
  return mem;
 }
}

variable_types: struct memory_pool { unsigned char *start; unsigned long next; unsigned long size; } *

variable_types:
size
unsigned long

variable_types:
mem
unsigned long


decompiled_code:
__int64 __fastcall passes_filter(__int64 a1, const char *a2)
{
__int64 **v2; // rbx
__int64 **v4; // rbx

v2 = *(__int64 ***)(a1 + 48);
if ( v2 )
{
while ( fnmatch((const char *)v2[1], a2, 0) )
{
v2 = (__int64 **)*v2;
if ( !v2 )
return 0LL;
}
return 1LL;
}
v4 = *(__int64 ***)(a1 + 56);
if ( !v4 )
return 1LL;
while ( fnmatch((const char *)v4[1], a2, 0) )
{
v4 = (__int64 **)*v4;
if ( !v4 )
return 1LL;
}
return 0LL;
}

original_code:
static inline _Bool passes_filter(struct filepirate *fp, char *name)
{
 if (fp->positive_filter) {
  for (struct filter_element *filter = fp->positive_filter; filter; filter = filter->next) {
   if (fnmatch(filter->s, name, 0) == 0) {
    return 1;
   }
  }
  return 0;
 }
 if (fp->negative_filter) {
  for (struct filter_element *filter = fp->negative_filter; filter; filter = filter->next) {
   if (fnmatch(filter->s, name, 0) == 0) {
    return 0;
   }
  }
 }
 return 1;
}

variable_types: struct filepirate { char *root_dirname; unsigned char *files; unsigned char *files_end; struct memory_pool { unsigned char *start; unsigned long next; unsigned long size; } main_pool; struct filter_element { struct filter_element *next; char *s; } *positive_filter; struct filter_element *negative_filter; } *

variable_types:
name
char *

user_defined_types: struct filepirate { char *root_dirname; unsigned char *files; unsigned char *files_end; struct memory_pool main_pool; struct filter_element *positive_filter; struct filter_element *negative_filter; }


decompiled_code:
void *__fastcall pool_expand(__int64 a1)
{
void *result; // rax
__int64 v2; // rbp

result = *(void **)(a1 + 16);
v2 = 2LL * (_QWORD)result;
if ( (unsigned __int64)(2LL * (_QWORD)result) <= 0x4000000 )
{
result = realloc(*(void **)a1, 2LL * (_QWORD)result);
if ( result )
{
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 16) = v2;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1)
{
void *result; // rax
__int64 v2; // rbp

result = *(void **)(a1 + 16);
v2 = 2LL * (_QWORD)result;
if ( (unsigned __int64)(2LL * (_QWORD)result) <= 0x4000000 )
{
result = realloc(*(void **)a1, 2LL * (_QWORD)result);
if ( result )
{
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 16) = v2;
}
}
return result;
}

original_code:
static void pool_expand(struct memory_pool *pool)
{
 size_t new = pool->size * 2;
 uint8_t *pool_new_start;
 if (new > (64 * 1024 * 1024))
  return;
 pool_new_start = realloc(pool->start, new);
 if (pool_new_start == ((void *)0)) {
  return;
 }
 pool->start = pool_new_start;
 pool->size = new;
}

canonical_original_code:
static void pool_expand(struct memory_pool *pool)
{
 unsigned long new = pool->size * 2;
 unsigned char *pool_new_start;
 if (new > (64 * 1024 * 1024))
  return;
 pool_new_start = realloc(pool->start, new);
 if (pool_new_start == ((void *)0)) {
  return;
 }
 pool->start = pool_new_start;
 pool->size = new;
}

variable_types:
new
unsigned long

user_defined_types: struct memory_pool { unsigned char *start; unsigned long next; unsigned long size; }


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

result = try_pool_alloc(a1, a2);
if ( !result )
{
pool_expand(a1);
result = try_pool_alloc(a1, a2);
}
return result;
}

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

result = func2(a1, a2);
if ( !result )
{
func4(a1);
result = func2(a1, a2);
}
return result;
}

original_code:
static uintptr_t pool_alloc(struct memory_pool *pool, size_t size)
{
 uintptr_t addr;
 addr = try_pool_alloc(pool, size);
 if (addr == 0) {
  pool_expand(pool);
  addr = try_pool_alloc(pool, size);
 }
 return addr;
}

canonical_original_code:
static unsigned long pool_alloc(struct memory_pool *pool, unsigned long size)
{
 unsigned long addr;
 addr = try_pool_alloc(pool, size);
 if (addr == 0) {
  pool_expand(pool);
  addr = try_pool_alloc(pool, size);
 }
 return addr;
}

variable_types:
addr
unsigned long


alloc

decompiled_code:
__int64 __fastcall alloc(__int64 a1, __int64 a2)
{
return pool_alloc(a1 + 24, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
return func5(a1 + 24, a2);
}

original_code:
static inline uintptr_t alloc(struct filepirate *fp, size_t size)
{
 return pool_alloc(&(fp->main_pool), size);
}

canonical_original_code:
static inline unsigned long alloc(struct filepirate *fp, unsigned long size)
{
 return pool_alloc(&(fp->main_pool), size);
}

user_defined_types: struct filter_element { struct filter_element *next; char *s; }


decompiled_code:
void __fastcall fp_deinit_dir(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func7(void **a1)
{
void *v2; // rdi

v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}

original_code:
static void fp_deinit_dir(struct filepirate *fp)
{
 if(fp->root_dirname) {
  free(fp->root_dirname);
  fp->root_dirname = ((void *)0);
 }
}


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

free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
result = 1LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
result = 1LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

original_code:
static _Bool pool_free(struct memory_pool *pool)
{
 free(pool->start);
 pool->start = ((void *)0);
 pool->size = 0;
 pool->next = 0;
 return 1;
}


decompiled_code:
void __fastcall fp_filter_add(void *src, __int64 *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
size_t v4; // r13
void *v5; // rax
__int64 v6; // rax

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = v2;
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
v3[1] = v5;
if ( v5 )
{
memcpy(v5, src, v4);
v6 = *a2;
*a2 = (__int64)v3;
*v3 = v6;
}
else
{
free(v3);
}
}
}

canonical_decompiled_code:
void __fastcall func10(void *src, __int64 *a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rbp
size_t v4; // r13
void *v5; // rax
__int64 v6; // rax

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = v2;
v4 = strlen((const char *)src) + 1;
v5 = malloc(v4);
v3[1] = v5;
if ( v5 )
{
memcpy(v5, src, v4);
v6 = *a2;
*a2 = (__int64)v3;
*v3 = v6;
}
else
{
free(v3);
}
}
}

original_code:
static void fp_filter_add(char *s, struct filter_element **dst)
{
 struct filter_element *elem = malloc(sizeof(struct filter_element));
 if(!elem)
  return;
 elem->s = malloc(strlen(s) + 1);
 if(!elem->s) {
  free(elem);
  return;
 }
 strcpy(elem->s, s);
 elem->next = *dst;
 *dst = elem;
}

variable_types:
s
char *

variable_types: struct filter_element { struct filter_element *next; char *s; } **


decompiled_code:
__int64 __fastcall pool_init(_QWORD *a1)
{
void *v1; // rax
__int64 result; // rax

v1 = malloc(0x100000uLL);
*a1 = v1;
if ( v1 )
{
a1[2] = 0x100000LL;
result = 1LL;
a1[1] = 4LL;
}
else
{
puts("pool_init malloc]");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
void *v1; // rax
__int64 result; // rax

v1 = malloc(0x100000uLL);
*a1 = v1;
if ( v1 )
{
a1[2] = 0x100000LL;
result = 1LL;
a1[1] = 4LL;
}
else
{
puts("pool_init malloc]");
result = 0LL;
}
return result;
}

original_code:
static _Bool pool_init(struct memory_pool *pool)
{
 pool->start = malloc((1 * 1024 * 1024));
 if (!pool->start) {
  printf("pool_init malloc]\n");
  return 0;
 }
 pool->size = (1 * 1024 * 1024);
 pool->next = 4;
 return 1;
}


decompiled_code:
__int64 __fastcall fp_init_dir_recurse(__int64 a1)
{
__int64 v1; // r14
char v2; // bl
__int64 v3; // r13
FTS *v4; // rbp
FTSENT *v5; // r15
u_short v6; // ax
char v8; // al
char v9; // cl
struct _ftsent *v10; // rbx
__int64 v11; // rax
char *v12; // rax
__int64 v13; // rax
__int64 v14; // rsi
char *v15; // rax
__int64 v16; // rsi
_BYTE *v17; // rax
char v18; // [rsp+Fh] [rbp-49h]
char v19; // [rsp+Fh] [rbp-49h]
char v20; // [rsp+Fh] [rbp-49h]
char *v21[9]; // [rsp+10h] [rbp-48h] BYREF

v1 = 0LL;
v2 = 0;
v3 = *(_QWORD *)(a1 + 32);
v21[0] = ".";
v21[1] = 0LL;
v4 = fts_open(v21, 4, 0LL);
if ( v4 )
{
LABEL_2:
while ( 1 )
{
v5 = fts_read(v4);
if ( !v5 )
break;
while ( 1 )
{
if ( v5->fts_level > 0 && v5->fts_name[0] == 46 )
{
fts_set(v4, v5, 4);
goto LABEL_2;
}
v6 = v5->fts_info;
if ( (v6 & 7) == 0 )
break;
v2 = 0;
v5 = fts_read(v4);
if ( !v5 )
goto LABEL_7;
}
if ( (v6 & 8) != 0 )
{
v8 = passes_filter(a1, v5->fts_name);
v9 = v8;
if ( v8 )
{
if ( !v2 )
{
v10 = v5->fts_parent;
if ( v1 )
{
v20 = v8;
v16 = alloc(a1, 5LL);
write_uint_isra_0(*(_QWORD *)(a1 + 24), v16);
v17 = (_BYTE *)get_ptr_isra_0(*(_QWORD *)(a1 + 24), v16 + 4);
v9 = v20;
*v17 = 0;
}
v18 = v9;
v11 = alloc(a1, v10->fts_pathlen + 5LL);
v1 = v11 + 4;
write_uint_isra_0(*(_QWORD *)(a1 + 24), v11);
v12 = (char *)get_ptr_isra_0(*(_QWORD *)(a1 + 24), v1);
strncpy(v12, v10->fts_path, v10->fts_pathlen);
v13 = get_ptr_isra_0(*(_QWORD *)(a1 + 24), v1);
v9 = v18;
*(_BYTE *)(v13 + v10->fts_pathlen) = 0;
}
v19 = v9;
v14 = alloc(a1, v5->fts_namelen + 5LL);
write_uint_isra_0(*(_QWORD *)(a1 + 24), v14);
v15 = (char *)get_ptr_isra_0(*(_QWORD *)(a1 + 24), v14 + 4);
strcpy(v15, v5->fts_name);
v2 = v19;
}
}
}
LABEL_7:
if ( *_errno_location() )
{
v3 = 0LL;
printf("fts_read");
}
else if ( fts_close(v4) )
{
v3 = 0LL;
printf("fts_close");
}
}
else
{
v3 = 0LL;
printf("fts_open");
}
return v3;
}

original_code:
static uintptr_t fp_init_dir_recurse(struct filepirate *fp)
{
 uintptr_t first = 0;
 uintptr_t dirent_start = 0;
 uintptr_t tmp = 0;
 _Bool dir_written = 0;
 FTSENT *node;
 first = fp->main_pool.next;
 char *cwd_only[] = {".", 0};
 FTS *tree = fts_open(cwd_only, 0x0004, 0);
 if (!tree) {
  printf("fts_open");
  return 0;
 }
 while ((node = fts_read(tree))) {
  if (node->fts_level > 0 && node->fts_name[0] == '.')
   fts_set(tree, node, 4);
  else if (node->fts_info & 1) {
   dir_written = 0;
  } else if (node->fts_info & 6) {
   dir_written = 0;
  } else if ((node->fts_info & 8) && passes_filter(fp, node->fts_name)) {
   if (dir_written == 0) {
    FTSENT *parent = node->fts_parent;
    if (dirent_start) {
     tmp = alloc(fp, sizeof(unsigned int) + 1);
     write_uint(fp, tmp, 0);
     tmp += sizeof(unsigned int);
     *((char *)get_ptr(fp, tmp)) = '\0';
    }
    dirent_start = alloc(fp, sizeof(unsigned int) + parent->fts_pathlen + 1);
    write_uint(fp, dirent_start, parent->fts_pathlen + 1);
    dirent_start += sizeof(unsigned int);
    strncpy((char *)get_ptr(fp, dirent_start), parent->fts_path, parent->fts_pathlen);
    *((char *)(get_ptr(fp, dirent_start) + parent->fts_pathlen)) = '\0';
    dir_written = 1;
   }
   tmp = alloc(fp, sizeof(unsigned int) + node->fts_namelen + 1);
   write_uint(fp, tmp, node->fts_namelen + 1);
   tmp += sizeof(unsigned int);
   strcpy((char *)get_ptr(fp, tmp), node->fts_name);
  }
 }
 if ((*__errno_location ())) {
  printf("fts_read");
  return 0;
 }
 if (fts_close(tree)) {
  printf("fts_close");
  return 0;
 }
 return first;
}

canonical_original_code:
static unsigned long fp_init_dir_recurse(struct filepirate *fp)
{
 unsigned long first = 0;
 unsigned long dirent_start = 0;
 unsigned long tmp = 0;
 _Bool dir_written = 0;
 struct _ftsent *node;
 first = fp->main_pool.next;
 char *cwd_only[] = {".", 0};
 struct FTS *tree = fts_open(cwd_only, 0x0004, 0);
 if (!tree) {
  printf("fts_open");
  return 0;
 }
 while ((node = fts_read(tree))) {
  if (node->fts_level > 0 && node->fts_name[0] == '.')
   fts_set(tree, node, 4);
  else if (node->fts_info & 1) {
   dir_written = 0;
  } else if (node->fts_info & 6) {
   dir_written = 0;
  } else if ((node->fts_info & 8) && passes_filter(fp, node->fts_name)) {
   if (dir_written == 0) {
    struct _ftsent *parent = node->fts_parent;
    if (dirent_start) {
     tmp = alloc(fp, sizeof(unsigned int) + 1);
     write_uint(fp, tmp, 0);
     tmp += sizeof(unsigned int);
     *((char *)get_ptr(fp, tmp)) = '\0';
    }
    dirent_start = alloc(fp, sizeof(unsigned int) + parent->fts_pathlen + 1);
    write_uint(fp, dirent_start, parent->fts_pathlen + 1);
    dirent_start += sizeof(unsigned int);
    strncpy((char *)get_ptr(fp, dirent_start), parent->fts_path, parent->fts_pathlen);
    *((char *)(get_ptr(fp, dirent_start) + parent->fts_pathlen)) = '\0';
    dir_written = 1;
   }
   tmp = alloc(fp, sizeof(unsigned int) + node->fts_namelen + 1);
   write_uint(fp, tmp, node->fts_namelen + 1);
   tmp += sizeof(unsigned int);
   strcpy((char *)get_ptr(fp, tmp), node->fts_name);
  }
 }
 if ((*__errno_location ())) {
  printf("fts_read");
  return 0;
 }
 if (fts_close(tree)) {
  printf("fts_close");
  return 0;
 }
 return first;
}

variable_types:
first
unsigned long

variable_types:
tmp
unsigned long

variable_types: struct FTS { struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; 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; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *fts_statp; char fts_name[1]; } *fts_cur; struct _ftsent *fts_child; struct _ftsent **fts_array; unsigned long fts_dev; char *fts_path; int fts_rfd; int fts_pathlen; int fts_nitems; int (*fts_compar)(void *, void *); int fts_options; } *

user_defined_types: struct _ftsent { struct _ftsent *fts_cycle; struct _ftsent *fts_parent; struct _ftsent *fts_link; long fts_number; void *fts_pointer; char *fts_accpath; char *fts_path; int fts_errno; int fts_symfd; unsigned short fts_pathlen; unsigned short fts_namelen; unsigned long fts_ino; unsigned long fts_dev; unsigned long fts_nlink; short fts_level; unsigned short fts_info; unsigned short fts_flags; unsigned short fts_instr; struct stat *fts_statp; char fts_name[1]; }

user_defined_types: struct FTS { struct _ftsent *fts_cur; struct _ftsent *fts_child; struct _ftsent **fts_array; unsigned long fts_dev; char *fts_path; int fts_rfd; int fts_pathlen; int fts_nitems; int (*fts_compar)(void *, void *); int fts_options; }

user_defined_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; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
bool __fastcall fp_init_dir(char **a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
int v4; // er12
__int64 v5; // rbp
char *v6; // rax
char *v7; // rdx
bool result; // al

if ( *a1 )
_assert_fail("fp->root_dirname == NULL", "cfilepirate.c", 0xFBu, "fp_init_dir");
v2 = strlen(a2);
v3 = (char *)malloc(v2 + 1);
*a1 = v3;
strcpy(v3, a2);
v4 = open(".", 0);
if ( v4 < 0 )
_assert_fail("cwd >= 0", "cfilepirate.c", 0x101u, "fp_init_dir");
chdir(a2);
v5 = fp_init_dir_recurse((__int64)a1);
fchdir(v4);
close(v4);
v6 = a1[3];
v7 = &v6[v5];
a1[2] = &v6[(_QWORD)a1[4]];
result = v5 != 0;
a1[1] = v7;
return result;
}

canonical_decompiled_code:
bool __fastcall func15(char **a1, const char *a2)
{
size_t v2; // rax
char *v3; // rax
int v4; // er12
__int64 v5; // rbp
char *v6; // rax
char *v7; // rdx
bool result; // al

if ( *a1 )
_assert_fail("fp->root_dirname == NULL", "cfilepirate.c", 0xFBu, "fp_init_dir");
v2 = strlen(a2);
v3 = (char *)malloc(v2 + 1);
*a1 = v3;
strcpy(v3, a2);
v4 = open(".", 0);
if ( v4 < 0 )
_assert_fail("cwd >= 0", "cfilepirate.c", 0x101u, "fp_init_dir");
chdir(a2);
v5 = func14((__int64)a1);
fchdir(v4);
close(v4);
v6 = a1[3];
v7 = &v6[v5];
a1[2] = &v6[(_QWORD)a1[4]];
result = v5 != 0;
a1[1] = v7;
return result;
}

original_code:
_Bool fp_init_dir(struct filepirate *fp, char *dirname)
{
 int cwd;
 uintptr_t files_index;
 ((fp->root_dirname == ((void *)0)) ? (void) (0) : __assert_fail ("fp->root_dirname == NULL", "cfilepirate.c", 251, __extension__ __PRETTY_FUNCTION__));
 fp->root_dirname = malloc(strlen(dirname) + 1);
 strcpy(fp->root_dirname, dirname);
 cwd = open(".", 00);
 ((cwd >= 0) ? (void) (0) : __assert_fail ("cwd >= 0", "cfilepirate.c", 257, __extension__ __PRETTY_FUNCTION__));
 chdir(dirname);
 files_index = fp_init_dir_recurse(fp);
 fchdir(cwd);
 close(cwd);
 fp->files = fp->main_pool.start + files_index;
 fp->files_end = fp->files + fp->main_pool.next - files_index;
 return files_index != 0;
}

canonical_original_code:
_Bool fp_init_dir(struct filepirate *fp, char *dirname)
{
 int cwd;
 unsigned long files_index;
 ((fp->root_dirname == ((void *)0)) ? (void) (0) : __assert_fail ("fp->root_dirname == NULL", "cfilepirate.c", 251, __extension__ __PRETTY_FUNCTION__));
 fp->root_dirname = malloc(strlen(dirname) + 1);
 strcpy(fp->root_dirname, dirname);
 cwd = open(".", 00);
 ((cwd >= 0) ? (void) (0) : __assert_fail ("cwd >= 0", "cfilepirate.c", 257, __extension__ __PRETTY_FUNCTION__));
 chdir(dirname);
 files_index = fp_init_dir_recurse(fp);
 fchdir(cwd);
 close(cwd);
 fp->files = fp->main_pool.start + files_index;
 fp->files_end = fp->files + fp->main_pool.next - files_index;
 return files_index != 0;
}

variable_types:
dirname
char *

variable_types: cwd int


decompiled_code:
void __fastcall fp_candidate_list_destroy(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[4];
free(v3);
*(_QWORD *)ptr = v2;
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[4];
free(v3);
*(_QWORD *)ptr = v2;
}
while ( v2 );
}
free(ptr);
}

original_code:
void fp_candidate_list_destroy(struct candidate_list *list)
{
 while(list->best) {
  struct candidate *tmp = list->best->worse;
  free(list->best);
  list->best = tmp;
 }
 free(list);
}

variable_types: struct candidate_list { struct candidate { char *dirname; char *filename; int goodness; struct candidate *better; } *best; struct candidate *worst; int max_candidates; } *

user_defined_types: struct candidate_list { struct candidate *best; struct candidate *worst; int max_candidates; }


original_code:
_Bool fp_get_candidates(struct filepirate *fp, char *buffer, int buffer_ptr, struct candidate_list *candidates)
{
 char *files;
 int file_count = 0;
 int previous_best_goodness = -1;
 _Bool new_directory = 1;
 unsigned int dirname_len, filename_len;
 char *dirname = ((void *)0);
 new_directory = 1;
 files = (char *)fp->files;
 candidate_list_reset(candidates);
 for(file_count = 0; file_count < candidates->max_candidates && files < (char *)fp->files_end; ) {
  if (new_directory) {
   dirname_len = *(unsigned int *)files;
   files += sizeof(unsigned int);
   dirname = files;
   files += dirname_len;
   new_directory = 0;
  }
  filename_len = *(unsigned int *)files;
  files += sizeof(unsigned int);
  if (filename_len == 0) {
   files += 1;
   new_directory = 1;
  } else {
   int goodness;
   if (fp_strstr(dirname_len - 1, dirname, filename_len - 1, files, buffer_ptr - 1, buffer, &goodness) == 1) {
    if(goodness >= previous_best_goodness) {
     candidate_list_add(candidates, dirname, files, goodness);
     previous_best_goodness = goodness;
    }
   }
   files += filename_len;
  }
 }
 return 1;
}

canonical_original_code:
_Bool fp_get_candidates(struct filepirate *fp, char *buffer, int buffer_ptr, struct candidate_list *candidates)
{
 char *files;
 int file_count = 0;
 int previous_best_goodness = -1;
 _Bool new_directory = 1;
 unsigned int dirname_len; unsigned int filename_len;
 char *dirname = ((void *)0);
 new_directory = 1;
 files = (char *)fp->files;
 candidate_list_reset(candidates);
 for(file_count = 0; file_count < candidates->max_candidates && files < (char *)fp->files_end; ) {
  if (new_directory) {
   dirname_len = *(unsigned int *)files;
   files += sizeof(unsigned int);
   dirname = files;
   files += dirname_len;
   new_directory = 0;
  }
  filename_len = *(unsigned int *)files;
  files += sizeof(unsigned int);
  if (filename_len == 0) {
   files += 1;
   new_directory = 1;
  } else {
   int goodness;
   if (fp_strstr(dirname_len - 1, dirname, filename_len - 1, files, buffer_ptr - 1, buffer, &goodness) == 1) {
    if(goodness >= previous_best_goodness) {
     candidate_list_add(candidates, dirname, files, goodness);
     previous_best_goodness = goodness;
    }
   }
   files += filename_len;
  }
 }
 return 1;
}

variable_types:
buffer
char *

variable_types:
files
char *

variable_types: goodness int

user_defined_types: struct candidate { char *dirname; char *filename; int goodness; struct candidate *better; }


decompiled_code:
void *fp_init()
{
_QWORD *v0; // rax
void *v1; // r12
void *v3; // rdi

v0 = calloc(0x40uLL, 1uLL);
v1 = v0;
if ( v0 && !(unsigned __int8)pool_init(v0 + 3) )
{
v3 = v1;
v1 = 0LL;
free(v3);
}
return v1;
}

canonical_decompiled_code:
void *func18()
{
_QWORD *v0; // rax
void *v1; // r12
void *v3; // rdi

v0 = calloc(0x40uLL, 1uLL);
v1 = v0;
if ( v0 && !(unsigned __int8)func11(v0 + 3) )
{
v3 = v1;
v1 = 0LL;
free(v3);
}
return v1;
}

original_code:
struct filepirate *fp_init()
{
 struct filepirate *fp;
 fp = calloc(sizeof *fp, 1);
 if (fp == ((void *)0))
  return ((void *)0);
 fp->positive_filter = fp->negative_filter = ((void *)0);
 if (pool_init(&(fp->main_pool)) == 0) {
  free(fp);
  return ((void *)0);
 }
 return fp;
}

return_type: struct filepirate { char *root_dirname; unsigned char *files; unsigned char *files_end; struct memory_pool { unsigned char *start; unsigned long next; unsigned long size; } main_pool; struct filter_element { struct filter_element *next; char *s; } *positive_filter; struct filter_element *negative_filter; } *


decompiled_code:
__int64 __fastcall fp_deinit(void *ptr)
{
unsigned int v1; // er12

fp_deinit_dir((void **)ptr);
v1 = pool_free((__int64)ptr + 24);
if ( (_BYTE)v1 )
{
free(ptr);
}
else
{
deinit_filter((_QWORD **)ptr + 7);
deinit_filter((_QWORD **)ptr + 6);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func19(void *ptr)
{
unsigned int v1; // er12

func7((void **)ptr);
v1 = func8((__int64)ptr + 24);
if ( (_BYTE)v1 )
{
free(ptr);
}
else
{
func9((_QWORD **)ptr + 7);
func9((_QWORD **)ptr + 6);
}
return v1;
}

original_code:
_Bool fp_deinit(struct filepirate *fp)
{
 fp_deinit_dir(fp);
 if (pool_free(&fp->main_pool)) {
  free (fp);
  return 1;
 }
 deinit_filter(&(fp->negative_filter));
 deinit_filter(&(fp->positive_filter));
 return 0;
}


decompiled_code:
void __fastcall fp_filter_add_negative(__int64 a1, void *a2)
{
fp_filter_add(a2, (__int64 *)(a1 + 56));
}

original_code:
void fp_filter_add_negative(struct filepirate *fp, char *negative)
{
 fp_filter_add(negative, &(fp->negative_filter));
}

variable_types:
negative
char *


decompiled_code:
void __fastcall fp_filter_add_positive(__int64 a1, void *a2)
{
fp_filter_add(a2, (__int64 *)(a1 + 48));
}

original_code:
void fp_filter_add_positive(struct filepirate *fp, char *positive)
{
 fp_filter_add(positive, &(fp->positive_filter));
}

variable_types:
positive
char *


decompiled_code:
void __fastcall fp_filter(__int64 a1, void **a2, void **a3)
{
void **i; // rbp
void *v4; // rsi
void **v5; // rbx
void *v6; // rsi

if ( a3 )
{
for ( i = a3; ; ++i )
{
v4 = *i;
fp_filter_add_negative(a1, v4);
}
}
v5 = a2;
if ( a2 )
{
while ( 1 )
{
v6 = *v5++;
fp_filter_add_positive(a1, v6);
}
}
}

original_code:
void fp_filter(struct filepirate *fp, char **positive, char **negative)
{
 for(char **s = negative; s; s++) {
  fp_filter_add_negative(fp, *s);
 }
 for(char **s = positive; s; s++) {
  fp_filter_add_positive(fp, *s);
 }
}

variable_types: struct filepirate { char *root_dirname; unsigned char *files; unsigned char *files_end; struct memory_pool { unsigned char *start; unsigned long next; unsigned long size; } main_pool; struct filter_element { struct filter_element *next; char *s; } *positive_filter; struct filter_element *negative_filter; } *

variable_types:
positive
char **

variable_types:
negative
char **

variable_types:
s
char **


main

repo: nfischer/tuningfork

original_code:
int main(int argc, char** argv) {
  double freq = -1;
  double duration = -1;;
  char fname[MAX_NAME_LEN];
  char channel[MAX_NAME_LEN];
  fname[0] = '\0';
  int k;
  for (k = 1; k < argc; k++) {
    char* option = argv[k];
    if (strcmp(option, "--help") == 0 || strcmp(option, "-h") == 0) {
      usage(1);
      return 0;
    } else if (strcmp(option, "--default") != 0 && k == argc-1) {
      usage(2);
      return 1;
    }
    if (strcmp(option, "--freq") == 0 || strcmp(option, "-f") == 0) {
      sscanf(argv[++k], "%lf", &freq);
    } else if (strcmp(option, "--duration") == 0 || strcmp(option, "-d") == 0) {
      sscanf(argv[++k], "%lf", &duration);
    } else if (strcmp(option, "--name") == 0 || strcmp(option, "-n") == 0) {
      strcpy(fname, argv[++k]);
      strcat(fname, "\n");
    } else if (strcmp(option, "--channel") == 0 || strcmp(option, "-c") == 0) {
      strcpy(channel, argv[++k]);
    } else if (strcmp(option, "--help") == 0 || strcmp(option, "-h") == 0) {
      usage(1);
      return 0;
    } else if (strcmp(option, "--defaults") == 0 || strcmp(option, "--default") == 0) {
      printf("defaults\n");
      freq = 440;
      duration = 10;
      strcpy(fname, "A440.wav\n");
    } else {
      fprintf(stderr, "unknown option `%s`\n", option);
      usage(2);
      return 1;
    }
  }
  int shouldEatCharacters = (freq == -1 || duration == -1);
  int hasInputErrors = 0;
  if (freq == -1) {
    printf("Input desired frequency (Hz): ");
    if (scanf("%lf", &freq) != 1) {
      hasInputErrors = 1;
    }
  }
  if (duration == -1) {
    printf("Input desired duration (sec): ");
    if (scanf("%lf", &duration) != 1) {
      hasInputErrors = 1;
    }
  }
  if (strcmp(channel, "") == 0) {
    strcpy(channel, "both");
  }
  if (shouldEatCharacters) {
    char garbageChar;
    for (garbageChar = getchar(); garbageChar != '\n'; garbageChar = getchar() );
  }
  if (strcmp(fname, "") == 0) {
    printf("Enter desired file name: ");
    if (hasInputErrors) {
      fprintf(stderr, "Error reading user input\n");
      exit(1);
    }
    if (fgets(fname, MAX_NAME_LEN, stdin) == ((void *)0)) {
      fprintf(stderr, "Error reading user input\n");
      exit(1);
    }
  }
  checkInputFormat(freq, duration, fname, channel);
  genFile(freq, duration, fname, channel);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
  double freq = -1;
  double duration = -1;;
  char fname[-1];
  char channel[-1];
  fname[0] = '\0';
  int k;
  for (k = 1; k < argc; k++) {
    char *option = argv[k];
    if (strcmp(option, "--help") == 0 || strcmp(option, "-h") == 0) {
      usage(1);
      return 0;
    } else if (strcmp(option, "--default") != 0 && k == argc-1) {
      usage(2);
      return 1;
    }
    if (strcmp(option, "--freq") == 0 || strcmp(option, "-f") == 0) {
      sscanf(argv[++k], "%lf", &freq);
    } else if (strcmp(option, "--duration") == 0 || strcmp(option, "-d") == 0) {
      sscanf(argv[++k], "%lf", &duration);
    } else if (strcmp(option, "--name") == 0 || strcmp(option, "-n") == 0) {
      strcpy(fname, argv[++k]);
      strcat(fname, "\n");
    } else if (strcmp(option, "--channel") == 0 || strcmp(option, "-c") == 0) {
      strcpy(channel, argv[++k]);
    } else if (strcmp(option, "--help") == 0 || strcmp(option, "-h") == 0) {
      usage(1);
      return 0;
    } else if (strcmp(option, "--defaults") == 0 || strcmp(option, "--default") == 0) {
      printf("defaults\n");
      freq = 440;
      duration = 10;
      strcpy(fname, "A440.wav\n");
    } else {
      fprintf(stderr, "unknown option `%s`\n", option);
      usage(2);
      return 1;
    }
  }
  int shouldEatCharacters = (freq == -1 || duration == -1);
  int hasInputErrors = 0;
  if (freq == -1) {
    printf("Input desired frequency (Hz): ");
    if (scanf("%lf", &freq) != 1) {
      hasInputErrors = 1;
    }
  }
  if (duration == -1) {
    printf("Input desired duration (sec): ");
    if (scanf("%lf", &duration) != 1) {
      hasInputErrors = 1;
    }
  }
  if (strcmp(channel, "") == 0) {
    strcpy(channel, "both");
  }
  if (shouldEatCharacters) {
    char garbageChar;
    for (garbageChar = getchar(); garbageChar != '\n'; garbageChar = getchar() );
  }
  if (strcmp(fname, "") == 0) {
    printf("Enter desired file name: ");
    if (hasInputErrors) {
      fprintf(stderr, "Error reading user input\n");
      exit(1);
    }
    if (fgets(fname, MAX_NAME_LEN, stdin) == ((void *)0)) {
      fprintf(stderr, "Error reading user input\n");
      exit(1);
    }
  }
  checkInputFormat(freq, duration, fname, channel);
  genFile(freq, duration, fname, channel);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: freq double

variable_types: duration double

variable_types:
fname
char [-1]

variable_types:
channel
char [-1]

variable_types: k int

variable_types:
option
char *

variable_types: shouldEatCharacters int

variable_types: hasInputErrors int

variable_types: garbageChar char


usage

decompiled_code:
int __fastcall usage(int a1)
{
bool v1; // zf
FILE *v2; // rdi

v1 = a1 == 1;
v2 = (FILE *)stdout;
if ( !v1 )
v2 = stderr;
return fprintf(
v2,
"%s\n",
"Usage: tf [OPTION]...\n"
"\n"
"Creates a .wav file with single frequency\n"
"\n"
"OPTIONS:\n"
" -f, --freq {NUM} specify frequency (default = 440Hz)\n"
" -d, --duration {NUM} specify time duration (default = 10s)\n"
" -n, --name {FILE} specify file name (default = A440.wav)\n"
" -c, --channel {both,left,right} specify only left or right channel (default = both)\n"
" -h, --help display this help menu");
}

canonical_decompiled_code:
int __fastcall func7(int a1)
{
bool v1; // zf
FILE *v2; // rdi

v1 = a1 == 1;
v2 = (FILE *)stdout;
if ( !v1 )
v2 = stderr;
return fprintf(
v2,
"%s\n",
"Usage: tf [OPTION]...\n"
"\n"
"Creates a .wav file with single frequency\n"
"\n"
"OPTIONS:\n"
" -f, --freq {NUM} specify frequency (default = 440Hz)\n"
" -d, --duration {NUM} specify time duration (default = 10s)\n"
" -n, --name {FILE} specify file name (default = A440.wav)\n"
" -c, --channel {both,left,right} specify only left or right channel (default = both)\n"
" -h, --help display this help menu");
}

original_code:
void usage(int fd) {
  char *message = "Usage: tf [OPTION]...\n\nCreates a .wav file with single frequency\n\nOPTIONS:\n  -f, --freq {NUM}                  specify frequency (default = 440Hz)\n  -d, --duration {NUM}              specify time duration (default = 10s)\n  -n, --name {FILE}                 specify file name (default = A440.wav)\n  -c, --channel {both,left,right}   specify only left or right channel (default = both)\n  -h, --help                        display this help menu";
  fprintf(fd == 1 ? stdout : stderr, "%s\n", message);
  return;
}

variable_types: fd int

variable_types:
message
char *


checkInputFormat

decompiled_code:
size_t __fastcall checkInputFormat(char *s, const char *a2, double a3, double a4)
{
int v4; // er12
__int64 v5; // rdx
size_t result; // rax

if ( a3 <= 0.0 || (v4 = 0, a3 > 22050.0) )
{
v4 = 1;
fprintf(
stderr,
"ERROR: You must input a frequency value in the range %d < frequency <= %d. Exiting with status (1)\n",
0LL,
22050LL);
}
if ( a4 <= 0.0 || a4 > 6000.0 )
{
v4 = 1;
fprintf(
stderr,
"ERROR: You must input a duration value in the range %d < duration <= %d. Exiting with status (1)\n",
0LL,
6000LL);
}
LODWORD(result) = strlen(s);
v5 = (int)result;
LODWORD(result) = result - 1;
s[v5 - 1] = 0;
if ( !*s )
{
fwrite("ERROR: You must input a nonempty file name. Exiting with status (1)\n", 1uLL, 0x44uLL, stderr);
if ( !strcmp(a2, "both") || !strcmp(a2, "left") || !strcmp(a2, "right") )
LABEL_21:
exit(1);
LABEL_20:
fwrite("ERROR: channel should be {both|left|right}\n", 1uLL, 0x2BuLL, stderr);
goto LABEL_21;
}
if ( strcmp(a2, "both") && strcmp(a2, "left") && strcmp(a2, "right") )
goto LABEL_20;
if ( v4 == 1 )
goto LABEL_21;
if ( (int)result <= 4
|| (result = (int)result, s[(int)result - 4] != 46)
|| s[(int)result - 3] != 119
|| s[(int)result - 2] != 97
|| s[(int)result - 1] != 118 )
{
result = strlen(s);
strcpy(&s[result], ".wav");
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(char *s, const char *a2, double a3, double a4)
{
int v4; // er12
__int64 v5; // rdx
size_t result; // rax

if ( a3 <= 0.0 || (v4 = 0, a3 > 22050.0) )
{
v4 = 1;
fprintf(
stderr,
"ERROR: You must input a frequency value in the range %d < frequency <= %d. Exiting with status (1)\n",
0LL,
22050LL);
}
if ( a4 <= 0.0 || a4 > 6000.0 )
{
v4 = 1;
fprintf(
stderr,
"ERROR: You must input a duration value in the range %d < duration <= %d. Exiting with status (1)\n",
0LL,
6000LL);
}
LODWORD(result) = strlen(s);
v5 = (int)result;
LODWORD(result) = result - 1;
s[v5 - 1] = 0;
if ( !*s )
{
fwrite("ERROR: You must input a nonempty file name. Exiting with status (1)\n", 1uLL, 0x44uLL, stderr);
if ( !strcmp(a2, "both") || !strcmp(a2, "left") || !strcmp(a2, "right") )
LABEL_21:
exit(1);
LABEL_20:
fwrite("ERROR: channel should be {both|left|right}\n", 1uLL, 0x2BuLL, stderr);
goto LABEL_21;
}
if ( strcmp(a2, "both") && strcmp(a2, "left") && strcmp(a2, "right") )
goto LABEL_20;
if ( v4 == 1 )
goto LABEL_21;
if ( (int)result <= 4
|| (result = (int)result, s[(int)result - 4] != 46)
|| s[(int)result - 3] != 119
|| s[(int)result - 2] != 97
|| s[(int)result - 1] != 118 )
{
result = strlen(s);
strcpy(&s[result], ".wav");
}
return result;
}

original_code:
void checkInputFormat(double freq, double duration, char* fname, char* channel)
{
  int shouldExit = 0;
  if (freq <= MIN_FREQ || freq > MAX_FREQ) {
    fprintf(stderr,
            "ERROR: You must input a frequency value in the range %d < frequency <= %d. Exiting with status (1)\n",
            (int)MIN_FREQ, (int)MAX_FREQ);
    shouldExit = 1;
  }
  if (duration <= MIN_DURATION || duration > MAX_DURATION) {
    fprintf(stderr,"ERROR: You must input a duration value in the range %d < duration <= %d. Exiting with status (1)\n", (int)MIN_DURATION, (int)MAX_DURATION);
    shouldExit = 1;
  }
  int nameLen = strlen(fname);
  fname[nameLen-1] = '\0';
  nameLen--;
  if (strcmp(fname, "") == 0) {
    fprintf(stderr,"ERROR: You must input a nonempty file name. Exiting with status (1)\n");
    shouldExit = 1;
  }
  if (strcmp(channel, "both") != 0 &&
      strcmp(channel, "left") != 0 &&
      strcmp(channel, "right") != 0) {
    fprintf(stderr,"ERROR: channel should be {both|left|right}\n");
    shouldExit = 1;
  }
  if (shouldExit == 1)
    exit(1);
  char nameV = fname[nameLen-1];
  char nameA = fname[nameLen-2];
  char nameW = fname[nameLen-3];
  char nameP = fname[nameLen-4];
  int shouldExtend;
  if (nameLen > 4) {
    if (nameP == '.' && nameW == 'w' && nameA == 'a' && nameV == 'v')
      shouldExtend = 0;
    else
      shouldExtend = 1;
  } else {
    shouldExtend = 1;
  }
  if (shouldExtend == 1)
    strcat(fname, ".wav");
  return;
}

canonical_original_code:
void checkInputFormat(double freq, double duration, char *fname, char *channel)
{
  int shouldExit = 0;
  if (freq <= MIN_FREQ || freq > MAX_FREQ) {
    fprintf(stderr,
            "ERROR: You must input a frequency value in the range %d < frequency <= %d. Exiting with status (1)\n",
            (int)MIN_FREQ, (int)MAX_FREQ);
    shouldExit = 1;
  }
  if (duration <= MIN_DURATION || duration > MAX_DURATION) {
    fprintf(stderr,"ERROR: You must input a duration value in the range %d < duration <= %d. Exiting with status (1)\n", (int)MIN_DURATION, (int)MAX_DURATION);
    shouldExit = 1;
  }
  int nameLen = strlen(fname);
  fname[nameLen-1] = '\0';
  nameLen--;
  if (strcmp(fname, "") == 0) {
    fprintf(stderr,"ERROR: You must input a nonempty file name. Exiting with status (1)\n");
    shouldExit = 1;
  }
  if (strcmp(channel, "both") != 0 &&
      strcmp(channel, "left") != 0 &&
      strcmp(channel, "right") != 0) {
    fprintf(stderr,"ERROR: channel should be {both|left|right}\n");
    shouldExit = 1;
  }
  if (shouldExit == 1)
    exit(1);
  char nameV = fname[nameLen-1];
  char nameA = fname[nameLen-2];
  char nameW = fname[nameLen-3];
  char nameP = fname[nameLen-4];
  int shouldExtend;
  if (nameLen > 4) {
    if (nameP == '.' && nameW == 'w' && nameA == 'a' && nameV == 'v')
      shouldExtend = 0;
    else
      shouldExtend = 1;
  } else {
    shouldExtend = 1;
  }
  if (shouldExtend == 1)
    strcat(fname, ".wav");
  return;
}

variable_types:
fname
char *

variable_types:
channel
char *

variable_types: shouldExit int

variable_types: nameLen int

variable_types: nameV char

variable_types: nameA char

variable_types: nameW char

variable_types: nameP char

variable_types: shouldExtend int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("static int x;");
puts("extern int y;");
puts("Inside f2");
f1_printx("Inside f2", argv);
f2_printx();
f1_printy();
f2_printy();
puts("assign y = 40;");
y = 40;
f1_printy();
f2_printy();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("static int x;");
puts("extern int y;");
puts("Inside f2");
func9("Inside f2", argv);
func7();
func10();
func8();
puts("assign y = 40;");
y = 40;
func10();
func8();
return 0;
}

original_code:
int main(int argc, char* argv[]) {
    printf("static int x;\n");
    printf("extern int y;\n");
    printf("Inside f2\n");
    f1_printx();
    f2_printx();
    f1_printy();
    f2_printy();
    printf("assign y = 40;\n");
    y = 40;
    f1_printy();
    f2_printy();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    printf("static int x;\n");
    printf("extern int y;\n");
    printf("Inside f2\n");
    f1_printx();
    f2_printx();
    f1_printy();
    f2_printy();
    printf("assign y = 40;\n");
    y = 40;
    f1_printy();
    f2_printy();
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
int f2_printx()
{
return printf("f2.x = %d\n", 20LL);
}

canonical_decompiled_code:
int func7()
{
return printf("f2.x = %d\n", 20LL);
}

original_code: void f2_printx() { printf("f2.x = %d\n", x); }


decompiled_code:
int f2_printy()
{
return printf("f2.y = %d\n", (unsigned int)y);
}

canonical_decompiled_code:
int func8()
{
return printf("f2.y = %d\n", (unsigned int)y);
}

original_code: void f2_printy() { printf("f2.y = %d\n", y); }


decompiled_code:
int f1_printx()
{
return printf("f1.x = %d\n", 10LL);
}

canonical_decompiled_code:
int func9()
{
return printf("f1.x = %d\n", 10LL);
}

original_code: void f1_printx() { printf("f1.x = %d\n", x); }


decompiled_code:
int f1_printy()
{
return printf("f1.y = %d\n", (unsigned int)y);
}

canonical_decompiled_code:
int func10()
{
return printf("f1.y = %d\n", (unsigned int)y);
}

original_code: void f1_printy() { printf("f1.y = %d\n", y); }


NullFree

decompiled_code:
void NullFree()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: static void NullFree(void *freeme) { }

canonical_original_code: static void NullFree(void *freeme) { }

variable_types:
freeme
void *


decompiled_code:
__int64 __fastcall FNVHash64(unsigned __int8 *a1, int a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rsi
__int64 v4; // rdx

result = 0xCBF29CE484222325LL;
v3 = &a1[a2];
if ( a1 < v3 )
{
do
{
v4 = *a1++;
result = 0x100000001B3LL * (v4 ^ result);
}
while ( v3 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, int a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rsi
__int64 v4; // rdx

result = 0xCBF29CE484222325LL;
v3 = &a1[a2];
if ( a1 < v3 )
{
do
{
v4 = *a1++;
result = 0x100000001B3LL * (v4 ^ result);
}
while ( v3 != a1 );
}
return result;
}

original_code:
uint64_t FNVHash64(unsigned char *buffer, unsigned int len) {
  static const uint64_t FNV1_64_INIT = 0xcbf29ce484222325ULL;
  static const uint64_t FNV_64_PRIME = 0x100000001b3ULL;
  unsigned char *bp = (unsigned char *) buffer;
  unsigned char *be = bp + len;
  uint64_t hval = FNV1_64_INIT;
  while (bp < be) {
    hval ^= (uint64_t) * bp++;
    hval *= FNV_64_PRIME;
  }
  return hval;
}

canonical_original_code:
unsigned long FNVHash64(unsigned char *buffer, unsigned int len) {
  static unsigned long FNV1_64_INIT = 0xcbf29ce484222325ULL;
  static unsigned long FNV_64_PRIME = 0x100000001b3ULL;
  unsigned char *bp = (unsigned char *) buffer;
  unsigned char *be = bp + len;
  unsigned long hval = FNV1_64_INIT;
  while (bp < be) {
    hval ^= (unsigned long) * bp++;
    hval *= FNV_64_PRIME;
  }
  return hval;
}

variable_types:
buffer
unsigned char *

variable_types:
len
unsigned int

variable_types:
bp
unsigned char *

variable_types:
be
unsigned char *

variable_types:
hval
unsigned long


decompiled_code:
__int64 __fastcall FNVHashInt64(unsigned __int64 a1)
{
void **v1; // rax
unsigned __int8 v3[8]; // [rsp+8h] [rbp-8h] BYREF
void *retaddr; // [rsp+10h] [rbp+0h] BYREF

v1 = (void **)v3;
do
{
*(_BYTE *)v1 = a1;
v1 = (void **)((char *)v1 + 1);
a1 >>= 8;
}
while ( v1 != &retaddr );
return FNVHash64(v3, 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1)
{
void **v1; // rax
unsigned __int8 v3[8]; // [rsp+8h] [rbp-8h] BYREF
void *retaddr; // [rsp+10h] [rbp+0h] BYREF

v1 = (void **)v3;
do
{
*(_BYTE *)v1 = a1;
v1 = (void **)((char *)v1 + 1);
a1 >>= 8;
}
while ( v1 != &retaddr );
return func4(v3, 8);
}

original_code:
uint64_t FNVHashInt64(uint64_t hashme) {
  unsigned char buf[8];
  int i;
  for (i = 0; i < 8; i++) {
    buf[i] = (unsigned char) (hashme & 0x00000000000000FFULL);
    hashme >>= 8;
  }
  return FNVHash64(buf, 8);
}

canonical_original_code:
unsigned long FNVHashInt64(unsigned long hashme) {
  unsigned char buf[8];
  int i;
  for (i = 0; i < 8; i++) {
    buf[i] = (unsigned char) (hashme & 0x00000000000000FFULL);
    hashme >>= 8;
  }
  return FNVHash64(buf, 8);
}

variable_types:
hashme
unsigned long

variable_types:
buf
unsigned char [8]

variable_types: i int


AssertionFailure

decompiled_code:
int __fastcall AssertionFailure(const char *a1, const char *a2, const char *a3, unsigned int a4)
{
int result; // eax

if ( !strcmp(a2, a3) )
result = fprintf(stderr, "Assert333(%s) failed in file %s, line %d\n", a1, a2, a4);
else
result = fprintf(stderr, "Assert333(%s) failed in file %s (included from %s), line %d\n", a1, a2, a3, a4);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2, const char *a3, unsigned int a4)
{
int result; // eax

if ( !strcmp(a2, a3) )
result = fprintf(stderr, "Assert333(%s) failed in file %s, line %d\n", a1, a2, a4);
else
result = fprintf(stderr, "Assert333(%s) failed in file %s (included from %s), line %d\n", a1, a2, a3, a4);
return result;
}

original_code:
void AssertionFailure(const char *exp, const char *file,
                      const char *baseFile, int line) {
  if (!strcmp(file, baseFile)) {
    fprintf(stderr,
            "Assert333(%s) failed in file %s, line %d\n", exp, file, line);
  } else {
    fprintf(stderr,
            "Assert333(%s) failed in file %s (included from %s), line %d\n",
            exp, file, baseFile, line);
  }
}

canonical_original_code:
void AssertionFailure(char *exp, char *file, char *baseFile, int line) {
  if (!strcmp(file, baseFile)) {
    fprintf(stderr,
            "Assert333(%s) failed in file %s, line %d\n", exp, file, line);
  } else {
    fprintf(stderr,
            "Assert333(%s) failed in file %s (included from %s), line %d\n",
            exp, file, baseFile, line);
  }
}

variable_types:
exp
char *

variable_types:
file
char *

variable_types:
baseFile
char *

variable_types: line int


ExamplePayloadFree

decompiled_code:
void __fastcall ExamplePayloadFree(void *ptr)
{
if ( ptr )
{
free(ptr);
}
else
{
AssertionFailure("payload != NULL", "example_program_ll.c", "example_program_ll.c", 99LL);
free(0LL);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
free(ptr);
}
else
{
AssertionFailure("payload != NULL", "example_program_ll.c", "example_program_ll.c", 99LL);
free(0LL);
}
}

original_code:
void ExamplePayloadFree(void *payload) {
  if (payload != ((void *)0)) ; else AssertionFailure("payload != NULL", "example_program_ll.c", "example_program_ll.c", 99);
  free(payload);
}

variable_types:
payload
void *


ExampleValueFree

decompiled_code:
void __fastcall ExampleValueFree(void *ptr)
{
if ( ptr )
{
free(ptr);
}
else
{
AssertionFailure("value != NULL", "example_program_ht.c", "example_program_ht.c", 111LL);
free(0LL);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(ptr);
}
else
{
AssertionFailure("value != NULL", "example_program_ht.c", "example_program_ht.c", 111LL);
free(0LL);
}
}

original_code:
void ExampleValueFree(void *value) {
  if (value != ((void *)0)) ; else AssertionFailure("value != NULL", "example_program_ht.c", "example_program_ht.c", 111);
  free(value);
}

variable_types:
value
void *


repo: nichelnich/yalib

decompiled_code:
__int64 __fastcall ya_timer_entry_set_usr_data(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("this", "src/timer.c", 0xA9u, "ya_timer_entry_set_usr_data");
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 24LL) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("this", "src/timer.c", 0xA9u, "ya_timer_entry_set_usr_data");
*(_QWORD *)(*(_QWORD *)(a1 + 96) + 24LL) = a2;
return 0LL;
}

original_code:
static ya_status_t ya_timer_entry_set_usr_data(void *this, void *usr_data)
{
 ((void) sizeof ((this) ? 1 : 0), __extension__ ({ if (this) ; else __assert_fail ("this", "src/timer.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 ((struct ya_timer_entry_private *)(((ya_timer_entry_t *)this)->private))->user_data = usr_data;
 return YA_SUCCESS;
}

canonical_original_code:
static int ya_timer_entry_set_usr_data(void *this, void *usr_data)
{
 ((void) sizeof ((this) ? 1 : 0), __extension__ ({ if (this) ; else __assert_fail ("this", "src/timer.c", 169, __extension__ __PRETTY_FUNCTION__); }));
 ((struct ya_timer_entry_private *)(((struct _ya_timer_entry *)this)->private))->user_data = usr_data;
 return YA_SUCCESS;
}

variable_types:
this
void *

user_defined_types: struct ya_timer_entry_private { int id; struct ya_time_val _timer_value; void *user_data; void (*cb)(struct _ya_timer_entry *entry); struct _ya_timer_heap *heap; }

user_defined_types: struct _ya_timer_entry { struct BASE_CLASS_OBJECT _; void *private; void (*dtor)(void *obj); int (*schedule)(void *_this, struct _ya_timer_heap *heap, struct ya_time_val *delay); int (*cancel)(void *_this); int (*get_id)(void *_this); void *(*get_usr_data)(void *_this); int (*set_usr_data)(void *_this, void *usr_data); }

user_defined_types: struct ya_time_val { long sec; long msec; }

user_defined_types: struct BASE_CLASS_OBJECT { struct ya_list_t list_node; void (*dtor)(void *obj); int ref; char class_name[64]; }

user_defined_types: struct ya_list_t { void *prev; void *next; }

user_defined_types: struct _ya_timer_heap { struct BASE_CLASS_OBJECT _; void *private; void (*dtor)(void *obj); void (*set_lock)(void *_this, union pthread_mutex_t *lock, int auto_del); unsigned int (*poll)(void *_this); }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


decompiled_code:
__int64 __fastcall ya_timer_entry_get_usr_data(__int64 a1)
{
if ( !a1 )
_assert_fail("this", "src/timer.c", 0xA3u, "ya_timer_entry_get_usr_data");
return *(_QWORD *)(*(_QWORD *)(a1 + 96) + 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("this", "src/timer.c", 0xA3u, "ya_timer_entry_get_usr_data");
return *(_QWORD *)(*(_QWORD *)(a1 + 96) + 24LL);
}

original_code:
static void *ya_timer_entry_get_usr_data(void *this)
{
 ((void) sizeof ((this) ? 1 : 0), __extension__ ({ if (this) ; else __assert_fail ("this", "src/timer.c", 163, __extension__ __PRETTY_FUNCTION__); }));
 return ((struct ya_timer_entry_private *)(((ya_timer_entry_t *)this)->private))->user_data;
}

canonical_original_code:
static void *ya_timer_entry_get_usr_data(void *this)
{
 ((void) sizeof ((this) ? 1 : 0), __extension__ ({ if (this) ; else __assert_fail ("this", "src/timer.c", 163, __extension__ __PRETTY_FUNCTION__); }));
 return ((struct ya_timer_entry_private *)(((struct _ya_timer_entry *)this)->private))->user_data;
}

return_type: void *


decompiled_code:
__int64 __fastcall ya_timer_entry_get_id(__int64 a1)
{
if ( !a1 )
_assert_fail("this", "src/timer.c", 0x9Du, "ya_timer_entry_get_id");
return **(unsigned int **)(a1 + 96);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
_assert_fail("this", "src/timer.c", 0x9Du, "ya_timer_entry_get_id");
return **(unsigned int **)(a1 + 96);
}

original_code:
static int ya_timer_entry_get_id(void *this)
{
 ((void) sizeof ((this) ? 1 : 0), __extension__ ({ if (this) ; else __assert_fail ("this", "src/timer.c", 157, __extension__ __PRETTY_FUNCTION__); }));
 return ((struct ya_timer_entry_private *)(((ya_timer_entry_t *)this)->private))->id;
}

canonical_original_code:
static int ya_timer_entry_get_id(void *this)
{
 ((void) sizeof ((this) ? 1 : 0), __extension__ ({ if (this) ; else __assert_fail ("this", "src/timer.c", 157, __extension__ __PRETTY_FUNCTION__); }));
 return ((struct ya_timer_entry_private *)(((struct _ya_timer_entry *)this)->private))->id;
}