main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
unsigned int i; // er13
__int64 v5; // rax
unsigned int v6; // ebx
_QWORD *v7; // rax
const char *v8; // rdx
const char **v9; // rax
const char **v10; // rbp
unsigned int v11; // ebx
__int64 v12; // rdx
const char **v13; // rax
unsigned int v14; // eax
unsigned int v15; // eax
char s[12]; // [rsp+4h] [rbp-44h] BYREF
unsigned int v18; // [rsp+10h] [rbp-38h] BYREF
__int64 v19; // [rsp+18h] [rbp-30h]

if ( (unsigned int)config_load(&v18, "../example.conf", envp) )
error("Failed to load example.conf\n");
if ( v18 )
{
v3 = v19;
for ( i = 0; i < v18; ++i )
{
printf("[%s]\n", **(const char ***)(v3 + 8LL * i));
v3 = v19;
v5 = *(_QWORD *)(v19 + 8LL * i);
if ( *(_DWORD *)(v5 + 8) )
{
v6 = 0;
do
{
v7 = *(_QWORD **)(*(_QWORD *)(v5 + 16) + 8LL * v6);
v8 = (const char *)v7[1];
if ( !v8 )
v8 = "NO VALUE";
++v6;
printf("\t%s=%s\n", *v7, v8);
v3 = v19;
v5 = *(_QWORD *)(v19 + 8LL * i);
}
while ( *(_DWORD *)(v5 + 8) > v6 );
}
}
}
v9 = (const char **)config_find_section(&v18, "Second section");
v10 = v9;
if ( !v9 )
error("Second section not found\n");
printf("Keys from %s:\n", *v9);
if ( *((_DWORD *)v10 + 2) )
{
v11 = 0;
do
{
v12 = v11++;
printf("\t%s\n", **(const char ***)&v10[2][8 * v12]);
}
while ( *((_DWORD *)v10 + 2) > v11 );
}
v13 = (const char **)config_find_item(&v18, "Key2", 0LL);
printf("Item:\n\t%s=%s\n", *v13, v13[1]);
v14 = time(0LL);
srand(v14);
v15 = rand();
snprintf(s, 0xCuLL, "%d", v15);
config_add(&v18, "First section", "Random value from example", s);
config_save(&v18, "../example.conf");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
unsigned int i; // er13
__int64 v5; // rax
unsigned int v6; // ebx
_QWORD *v7; // rax
const char *v8; // rdx
const char **v9; // rax
const char **v10; // rbp
unsigned int v11; // ebx
__int64 v12; // rdx
const char **v13; // rax
unsigned int v14; // eax
unsigned int v15; // eax
char s[12]; // [rsp+4h] [rbp-44h] BYREF
unsigned int v18; // [rsp+10h] [rbp-38h] BYREF
__int64 v19; // [rsp+18h] [rbp-30h]

if ( (unsigned int)config_load(&v18, "../example.conf", envp) )
func0("Failed to load example.conf\n");
if ( v18 )
{
v3 = v19;
for ( i = 0; i < v18; ++i )
{
printf("[%s]\n", **(const char ***)(v3 + 8LL * i));
v3 = v19;
v5 = *(_QWORD *)(v19 + 8LL * i);
if ( *(_DWORD *)(v5 + 8) )
{
v6 = 0;
do
{
v7 = *(_QWORD **)(*(_QWORD *)(v5 + 16) + 8LL * v6);
v8 = (const char *)v7[1];
if ( !v8 )
v8 = "NO VALUE";
++v6;
printf("\t%s=%s\n", *v7, v8);
v3 = v19;
v5 = *(_QWORD *)(v19 + 8LL * i);
}
while ( *(_DWORD *)(v5 + 8) > v6 );
}
}
}
v9 = (const char **)config_find_section(&v18, "Second section");
v10 = v9;
if ( !v9 )
func0("Second section not found\n");
printf("Keys from %s:\n", *v9);
if ( *((_DWORD *)v10 + 2) )
{
v11 = 0;
do
{
v12 = v11++;
printf("\t%s\n", **(const char ***)&v10[2][8 * v12]);
}
while ( *((_DWORD *)v10 + 2) > v11 );
}
v13 = (const char **)config_find_item(&v18, "Key2", 0LL);
printf("Item:\n\t%s=%s\n", *v13, v13[1]);
v14 = time(0LL);
srand(v14);
v15 = rand();
snprintf(s, 0xCuLL, "%d", v15);
config_add(&v18, "First section", "Random value from example", s);
config_save(&v18, "../example.conf");
return 0;
}

variable_types:
i
unsigned int

variable_types:
key
char *

variable_types:
val
char *

variable_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } *


canonical_name: main

repo: Detegr/dtgconf

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **i; // rbp
std::ostream *v4; // r12
__int64 v5; // rax
_BYTE *v6; // r14
char v7; // si
std::ostream *v8; // rax
_QWORD *v9; // rbx
void **v10; // r12
void **v11; // r15
void **v12; // rdi
__int64 v13; // rax
__int64 v14; // rax
std::ostream *v15; // rax
_QWORD *v16; // rbx
char v17; // si
std::ostream *v18; // rax
std::ostream *v19; // rbp
__int64 v20; // rax
_BYTE *v21; // r12
__int64 (__fastcall *v22)(__int64, unsigned int); // rax
__int64 (__fastcall *v23)(__int64, unsigned int); // rax
unsigned int v24; // eax
unsigned int v25; // ebp
void **v27; // [rsp+10h] [rbp-2E8h] BYREF
void **v28; // [rsp+18h] [rbp-2E0h]
void *v29[2]; // [rsp+30h] [rbp-2C8h] BYREF
char v30; // [rsp+40h] [rbp-2B8h] BYREF
void *v31[2]; // [rsp+50h] [rbp-2A8h] BYREF
char v32[16]; // [rsp+60h] [rbp-298h] BYREF
void *v33[2]; // [rsp+70h] [rbp-288h] BYREF
char v34; // [rsp+80h] [rbp-278h] BYREF
void *v35[2]; // [rsp+90h] [rbp-268h] BYREF
char v36; // [rsp+A0h] [rbp-258h] BYREF
char v37[64]; // [rsp+B0h] [rbp-248h] BYREF
void *v38; // [rsp+F0h] [rbp-208h] BYREF
_QWORD *v39; // [rsp+F8h] [rbp-200h]
char v40; // [rsp+100h] [rbp-1F8h] BYREF
void *v41; // [rsp+130h] [rbp-1C8h] BYREF
void *v42; // [rsp+138h] [rbp-1C0h]
char v43[440]; // [rsp+140h] [rbp-1B8h] BYREF

std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v29,
"../../example/example.conf");
DtgConf::Config::Config(v37, v29);
DtgConf::Config::GetConfig((DtgConf::Config *)&v27);
for ( i = v27; v28 != i; i += 5 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[", 1LL);
v4 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *i, i[1]);
std::__ostream_insert<char,std::char_traits<char>>(v4, "]", 1LL);
v5 = *(_QWORD *)(*(_QWORD *)v4 - 24LL);
v6 = *(_BYTE **)((char *)v4 + v5 + 240);
if ( !v6 )
std::__throw_bad_cast();
if ( v6[56] )
{
v7 = v6[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v4 + v5 + 240));
v7 = 10;
v23 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v6 + 48LL);
if ( v23 != std::ctype<char>::do_widen )
v7 = v23((__int64)v6, 10u);
}
v8 = (std::ostream *)std::ostream::put(v4, v7);
std::ostream::flush(v8);
DtgConf::ConfigSection::Items[abi:cxx11](&v41, i);
v9 = v41;
v10 = (void **)v42;
if ( v41 != v42 )
{
do
{
PrintItem(v9);
v11 = (void **)v42;
v9 += 8;
}
while ( v42 != v9 );
v10 = (void **)v41;
if ( v9 != v41 )
{
do
{
v12 = (void **)v10[4];
if ( v12 != v10 + 6 )
operator delete(v12);
if ( *v10 != v10 + 2 )
operator delete(*v10);
v10 += 8;
}
while ( v11 != v10 );
v10 = (void **)v41;
}
}
if ( v10 )
operator delete(v10);
}
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)&v38,
"Second section");
DtgConf::Config::GetSection(&v41, v37, &v38);
if ( v38 != &v40 )
operator delete(v38);
v13 = std::operator<<<std::char_traits<char>>(&std::cout, "Keys from ");
v14 = std::__ostream_insert<char,std::char_traits<char>>(v13, v41, v42);
v15 = (std::ostream *)std::operator<<<std::char_traits<char>>(v14, ":");
std::endl<char,std::char_traits<char>>(v15);
DtgConf::ConfigSection::Items[abi:cxx11](&v38, &v41);
v16 = v38;
if ( v38 != v39 )
{
do
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "\t", 1LL);
v19 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *v16, v16[1]);
v20 = *(_QWORD *)(*(_QWORD *)v19 - 24LL);
v21 = *(_BYTE **)((char *)v19 + v20 + 240);
if ( !v21 )
std::__throw_bad_cast();
if ( v21[56] )
{
v17 = v21[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v19 + v20 + 240));
v17 = 10;
v22 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v21 + 48LL);
if ( v22 != std::ctype<char>::do_widen )
v17 = v22((__int64)v21, 10u);
}
v18 = (std::ostream *)std::ostream::put(v19, v17);
std::ostream::flush(v18);
v16 += 8;
}
while ( v39 != v16 );
}
std::vector<std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::~vector((__int64 *)&v38);
if ( v41 != v43 )
operator delete(v41);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string((__int64 *)&v41, "Key2");
DtgConf::Config::GetItem(&v38, v37, &v41);
if ( v41 != v43 )
operator delete(v41);
PrintItem(&v38);
v24 = time(0LL);
srand(v24);
v25 = rand();
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream(&v41);
std::ostream::operator<<(v43, v25);
v31[1] = 0LL;
v31[0] = v32;
v32[0] = 0;
std::operator>><char>(&v41, v31);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v35,
"Random value from example");
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v33,
"First section");
DtgConf::Config::Add(v37, v33, v35, v31);
if ( v33[0] != &v34 )
operator delete(v33[0]);
if ( v35[0] != &v36 )
operator delete(v35[0]);
DtgConf::Config::Save((DtgConf::Config *)v37);
if ( v31[0] != v32 )
operator delete(v31[0]);
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::~basic_stringstream(&v41);
std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>::~pair((__int64)&v38);
std::vector<DtgConf::ConfigSection>::~vector(&v27);
DtgConf::Config::~Config((DtgConf::Config *)v37);
if ( v29[0] != &v30 )
operator delete(v29[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void **i; // rbp
std::ostream *v4; // r12
__int64 v5; // rax
_BYTE *v6; // r14
char v7; // si
std::ostream *v8; // rax
_QWORD *v9; // rbx
void **v10; // r12
void **v11; // r15
void **v12; // rdi
__int64 v13; // rax
__int64 v14; // rax
std::ostream *v15; // rax
_QWORD *v16; // rbx
char v17; // si
std::ostream *v18; // rax
std::ostream *v19; // rbp
__int64 v20; // rax
_BYTE *v21; // r12
__int64 (__fastcall *v22)(__int64, unsigned int); // rax
__int64 (__fastcall *v23)(__int64, unsigned int); // rax
unsigned int v24; // eax
unsigned int v25; // ebp
void **v27; // [rsp+10h] [rbp-2E8h] BYREF
void **v28; // [rsp+18h] [rbp-2E0h]
void *v29[2]; // [rsp+30h] [rbp-2C8h] BYREF
char v30; // [rsp+40h] [rbp-2B8h] BYREF
void *v31[2]; // [rsp+50h] [rbp-2A8h] BYREF
char v32[16]; // [rsp+60h] [rbp-298h] BYREF
void *v33[2]; // [rsp+70h] [rbp-288h] BYREF
char v34; // [rsp+80h] [rbp-278h] BYREF
void *v35[2]; // [rsp+90h] [rbp-268h] BYREF
char v36; // [rsp+A0h] [rbp-258h] BYREF
char v37[64]; // [rsp+B0h] [rbp-248h] BYREF
void *v38; // [rsp+F0h] [rbp-208h] BYREF
_QWORD *v39; // [rsp+F8h] [rbp-200h]
char v40; // [rsp+100h] [rbp-1F8h] BYREF
void *v41; // [rsp+130h] [rbp-1C8h] BYREF
void *v42; // [rsp+138h] [rbp-1C0h]
char v43[440]; // [rsp+140h] [rbp-1B8h] BYREF

std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v29,
"../../example/example.conf");
DtgConf::Config::Config(v37, v29);
DtgConf::Config::GetConfig((DtgConf::Config *)&v27);
for ( i = v27; v28 != i; i += 5 )
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "[", 1LL);
v4 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *i, i[1]);
std::__ostream_insert<char,std::char_traits<char>>(v4, "]", 1LL);
v5 = *(_QWORD *)(*(_QWORD *)v4 - 24LL);
v6 = *(_BYTE **)((char *)v4 + v5 + 240);
if ( !v6 )
std::__throw_bad_cast();
if ( v6[56] )
{
v7 = v6[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v4 + v5 + 240));
v7 = 10;
v23 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v6 + 48LL);
if ( v23 != std::ctype<char>::do_widen )
v7 = v23((__int64)v6, 10u);
}
v8 = (std::ostream *)std::ostream::put(v4, v7);
std::ostream::flush(v8);
DtgConf::ConfigSection::Items[abi:cxx11](&v41, i);
v9 = v41;
v10 = (void **)v42;
if ( v41 != v42 )
{
do
{
func0(v9);
v11 = (void **)v42;
v9 += 8;
}
while ( v42 != v9 );
v10 = (void **)v41;
if ( v9 != v41 )
{
do
{
v12 = (void **)v10[4];
if ( v12 != v10 + 6 )
operator delete(v12);
if ( *v10 != v10 + 2 )
operator delete(*v10);
v10 += 8;
}
while ( v11 != v10 );
v10 = (void **)v41;
}
}
if ( v10 )
operator delete(v10);
}
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)&v38,
"Second section");
DtgConf::Config::GetSection(&v41, v37, &v38);
if ( v38 != &v40 )
operator delete(v38);
v13 = std::operator<<<std::char_traits<char>>(&std::cout, "Keys from ");
v14 = std::__ostream_insert<char,std::char_traits<char>>(v13, v41, v42);
v15 = (std::ostream *)std::operator<<<std::char_traits<char>>(v14, ":");
std::endl<char,std::char_traits<char>>(v15);
DtgConf::ConfigSection::Items[abi:cxx11](&v38, &v41);
v16 = v38;
if ( v38 != v39 )
{
do
{
std::__ostream_insert<char,std::char_traits<char>>(&std::cout, "\t", 1LL);
v19 = (std::ostream *)std::__ostream_insert<char,std::char_traits<char>>(&std::cout, *v16, v16[1]);
v20 = *(_QWORD *)(*(_QWORD *)v19 - 24LL);
v21 = *(_BYTE **)((char *)v19 + v20 + 240);
if ( !v21 )
std::__throw_bad_cast();
if ( v21[56] )
{
v17 = v21[67];
}
else
{
std::ctype<char>::_M_widen_init(*(_QWORD *)((char *)v19 + v20 + 240));
v17 = 10;
v22 = *(__int64 (__fastcall **)(__int64, unsigned int))(*(_QWORD *)v21 + 48LL);
if ( v22 != std::ctype<char>::do_widen )
v17 = v22((__int64)v21, 10u);
}
v18 = (std::ostream *)std::ostream::put(v19, v17);
std::ostream::flush(v18);
v16 += 8;
}
while ( v39 != v16 );
}
std::vector<std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::~func2((__int64 *)&v38);
if ( v41 != v43 )
operator delete(v41);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string((__int64 *)&v41, "Key2");
DtgConf::Config::GetItem(&v38, v37, &v41);
if ( v41 != v43 )
operator delete(v41);
func0(&v38);
v24 = time(0LL);
srand(v24);
v25 = rand();
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::basic_stringstream(&v41);
std::ostream::operator<<(v43, v25);
v31[1] = 0LL;
v31[0] = v32;
v32[0] = 0;
std::operator>><char>(&v41, v31);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v35,
"Random value from example");
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(
(__int64 *)v33,
"First section");
DtgConf::Config::Add(v37, v33, v35, v31);
if ( v33[0] != &v34 )
operator delete(v33[0]);
if ( v35[0] != &v36 )
operator delete(v35[0]);
DtgConf::Config::Save((DtgConf::Config *)v37);
if ( v31[0] != v32 )
operator delete(v31[0]);
std::__cxx11::basic_stringstream<char,std::char_traits<char>,std::allocator<char>>::~basic_stringstream(&v41);
std::pair<std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>>::~pair((__int64)&v38);
std::vector<DtgConf::ConfigSection>::~func2(&v27);
DtgConf::Config::~Config((DtgConf::Config *)v37);
if ( v29[0] != &v30 )
operator delete(v29[0]);
return 0;
}

original_code:
int main()
{
 struct config conf;
 if(config_load(&conf, "../example.conf"))
 {
  error("Failed to load example.conf\n");
 }
 for(unsigned i=0; i<conf.sectioncount; ++i)
 {
  printf("[%s]\n", conf.sections[i]->name);
  for(unsigned j=0; j<conf.sections[i]->itemcount; ++j)
  {
   char* key=conf.sections[i]->items[j]->key;
   char* val=conf.sections[i]->items[j]->val;
   printf("\t%s=%s\n", key, val?val:"NO VALUE");
  }
 }
 struct configsection* sect=config_find_section(&conf, "Second section");
 if(!sect) error("Second section not found\n");
 else
 {
  printf("Keys from %s:\n", sect->name);
  for(unsigned i=0; i<sect->itemcount; ++i)
  {
   printf("\t%s\n", sect->items[i]->key);
  }
 }
 struct configitem* item=config_find_item(&conf, "Key2", ((void *)0));
 printf("Item:\n\t%s=%s\n", item->key, item->val);
 srand(time(((void *)0)));
 int rnd=rand();
 char rndstr[12];
 snprintf(rndstr, 12, "%d", rnd);
 config_add(&conf, "First section", "Random value from example", rndstr);
 config_save(&conf, "../example.conf");
}

canonical_original_code:
int main()
{
 struct config conf;
 if(config_load(&conf, "../example.conf"))
 {
  error("Failed to load example.conf\n");
 }
 for(unsigned int i = 0; i<conf.sectioncount; ++i)
 {
  printf("[%s]\n", conf.sections[i]->name);
  for(unsigned int j = 0; j<conf.sections[i]->itemcount; ++j)
  {
   char *key = conf.sections[i]->items[j]->key;
   char *val = conf.sections[i]->items[j]->val;
   printf("\t%s=%s\n", key, val?val:"NO VALUE");
  }
 }
 struct configsection *sect = config_find_section(&conf, "Second section");
 if(!sect) error("Second section not found\n");
 else
 {
  printf("Keys from %s:\n", sect->name);
  for(unsigned int i = 0; i<sect->itemcount; ++i)
  {
   printf("\t%s\n", sect->items[i]->key);
  }
 }
 struct configitem *item = config_find_item(&conf, "Key2", ((void *)0));
 printf("Item:\n\t%s=%s\n", item->key, item->val);
 srand(time(((void *)0)));
 int rnd = rand();
 char rndstr[12];
 snprintf(rndstr, 12, "%d", rnd);
 config_add(&conf, "First section", "Random value from example", rndstr);
 config_save(&conf, "../example.conf");
}

variable_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem { char *key; char *val; } **items; } **sections; }

variable_types:
j
unsigned int

variable_types: rnd int

variable_types:
rndstr
char [12]

return_type: int

user_defined_types: struct config { unsigned int sectioncount; unsigned int size; struct configsection **sections; }

user_defined_types: struct configsection { char *name; unsigned int itemcount; unsigned int size; struct configitem **items; }


area

decompiled_code:
int __fastcall area(double (*a1)(void), double a2, double a3, double a4)
{
int v5; // ebp
double v6; // r12
double v7; // r15
double v8; // xmm2_8
double v9; // xmm1_8
double v10; // xmm0_8
int result; // eax
double v12; // [rsp+0h] [rbp-60h]
double i; // [rsp+0h] [rbp-60h]
double v14; // [rsp+8h] [rbp-58h]
double v16; // [rsp+28h] [rbp-38h]

v5 = 2;
v12 = a1();
v16 = a3 - a2;
v6 = (((double (__fastcall *)(double))a1)(a3) + v12) * 0.5 * (a3 - a2);
v7 = v6;
while ( 1 )
{
v8 = 0.0;
v9 = a2;
for ( i = v16 / (double)v5; a3 > v9; v8 = v8 + (v10 + v14) * 0.5 * i )
{
v14 = ((double (__fastcall *)(double))a1)(v9);
v10 = ((double (__fastcall *)(double))a1)(v9 + i);
v9 = v9 + i;
}
v5 *= 2;
result = printf("area: %f, var: %f\n", v8, v7);
*(_QWORD *)&v7 = COERCE_UNSIGNED_INT64(v6 - v8) & LC3;
if ( v7 <= a4 )
break;
v6 = v8;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(double (*a1)(void), double a2, double a3, double a4)
{
int v5; // ebp
double v6; // r12
double v7; // r15
double v8; // xmm2_8
double v9; // xmm1_8
double v10; // xmm0_8
int result; // eax
double v12; // [rsp+0h] [rbp-60h]
double i; // [rsp+0h] [rbp-60h]
double v14; // [rsp+8h] [rbp-58h]
double v16; // [rsp+28h] [rbp-38h]

v5 = 2;
v12 = a1();
v16 = a3 - a2;
v6 = (((double (__fastcall *)(double))a1)(a3) + v12) * 0.5 * (a3 - a2);
v7 = v6;
while ( 1 )
{
v8 = 0.0;
v9 = a2;
for ( i = v16 / (double)v5; a3 > v9; v8 = v8 + (v10 + v14) * 0.5 * i )
{
v14 = ((double (__fastcall *)(double))a1)(v9);
v10 = ((double (__fastcall *)(double))a1)(v9 + i);
v9 = v9 + i;
}
v5 *= 2;
result = printf("area: %f, var: %f\n", v8, v7);
*(_QWORD *)&v7 = COERCE_UNSIGNED_INT64(v6 - v8) & LC3;
if ( v7 <= a4 )
break;
v6 = v8;
}
return result;
}

original_code:
double area(double a, double b, double tolerance, double (*f)(double)){
 double h;
 int it = 2;
 double area = ((f(a) + f(b))/2.0)*(b-a);
 double var = area;
 do{
  double aux = area;
  area = 0.0;
  h = (b-a)/it;
  double step;
  for(step = a; step < b; step += h){
   area += ((f(step)+f(step+h))/2.0)*h;
  }
  it*=2;
  printf("area: %f, var: %f\n", area, var);
  var = fabs(aux - area);
 }while(var > tolerance);
 return area;
}

variable_types: a double

variable_types: b double

variable_types: tolerance double

variable_types:
f
double (*)(double)

variable_types: h double

variable_types: it int

variable_types: area double

variable_types: var double

variable_types: aux double

variable_types: step double

return_type: double


f

decompiled_code:
double __fastcall f(double a1)
{
return a1 * a1;
}

canonical_decompiled_code:
double __fastcall func0(double a1)
{
return a1 * a1;
}

original_code:
double f(double x){
 return x*x;
}

canonical_original_code:
double f(double x){
 return x*x;
}

variable_types: x double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
area(f, argv, envp, 1.0, 5.0, 0.1);
printf("%f\n", *(double *)&LC2);
return 0;
}

original_code:
int main(){
 double tolerance = 0.1;
 double a = 1.0, b = 5.0;
 double integral = area(a, b, tolerance, f);
 printf("%f\n", integral);
 return 0;
}

canonical_original_code:
int main(){
 double tolerance = 0.1;
 double a = 1.0; double b = 5.0;
 double integral = area(a, b, tolerance, f);
 printf("%f\n", integral);
 return 0;
}

variable_types: integral double


ttinit

repo: DigitalMars/Empire-for-VMS

decompiled_code:
__int64 ttinit()
{
int v0; // edx
__int64 result; // rax

initscr();
noecho();
cbreak();
init_colors();
v0 = LINES;
result = (unsigned int)COLS;
if ( LINES >= 65 )
v0 = 64;
lines = v0;
if ( COLS >= 107 )
result = 106LL;
cols = result;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // edx
__int64 result; // rax

initscr();
noecho();
cbreak();
init_colors();
v0 = LINES;
result = (unsigned int)COLS;
if ( LINES >= 65 )
v0 = 64;
lines = v0;
if ( COLS >= 107 )
result = 106LL;
cols = result;
return result;
}

original_code:
void
ttinit()
{
 (void) initscr();
 (void) noecho();
 (void) cbreak();
 init_colors();
 lines = LINES;
 cols = COLS;
 if (lines > 60 + 3 + 1)
  lines = 60 + 3 + 1;
 if (cols > 100 + 6)
  cols = 100 + 6;
}

return_type: void


decompiled_code:
__int64 clear_screen()
{
wclear(stdscr);
wrefresh(stdscr);
return kill_display();
}

canonical_decompiled_code:
__int64 func4()
{
wclear(stdscr);
wrefresh(stdscr);
return kill_display();
}

original_code:
void
clear_screen () {
 (void) wclear(stdscr);
 (void) wrefresh(stdscr);
 kill_display ();
}

canonical_original_code:
void clear_screen() {
 (void) wclear(stdscr);
 (void) wrefresh(stdscr);
 kill_display ();
}


redraw

decompiled_code:
int redraw()
{
clearok(curscr, 1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func5()
{
clearok(curscr, 1);
return wrefresh(stdscr);
}

original_code:
void
redraw () {
 (void) clearok (curscr, 1);
 (void) wrefresh(stdscr);
}

canonical_original_code:
void redraw() {
 (void) clearok (curscr, 1);
 (void) wrefresh(stdscr);
}


delay

decompiled_code:
int delay()
{
wrefresh(stdscr);
return napms(delay_time);
}

canonical_decompiled_code:
int func6()
{
wrefresh(stdscr);
return napms(delay_time);
}

original_code:
void
delay () {
 (void) wrefresh(stdscr);
 (void) napms (delay_time);
}

canonical_original_code:
void delay() {
 (void) wrefresh(stdscr);
 (void) napms (delay_time);
}


decompiled_code:
int close_disp()
{
wmove(stdscr, LINES - 1, 0);
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

canonical_decompiled_code:
int func7()
{
wmove(stdscr, LINES - 1, 0);
wclrtoeol(stdscr);
wrefresh(stdscr);
return endwin();
}

original_code:
void
close_disp()
{
 (void) wmove(stdscr,(LINES - 1),(0));
 (void) wclrtoeol(stdscr);
 (void) wrefresh(stdscr);
 (void) endwin ();
}


empend

decompiled_code:
void __noreturn empend()
{
close_disp();
exit(0);
}

canonical_decompiled_code:
void __noreturn func14()
{
func7();
exit(0);
}

original_code:
void
empend ()
{
 close_disp ();
 exit (0);
}

canonical_original_code:
void empend()
{
 close_disp ();
 exit (0);
}


ver

decompiled_code:
int ver()
{
return waddnstr(stdscr, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988", -1);
}

canonical_decompiled_code:
int func15()
{
return waddnstr(stdscr, "EMPIRE, Version 5.00 site Amdahl 1-Apr-1988", -1);
}

original_code:
void
ver ()
{
        (void) waddnstr(stdscr,("EMPIRE, Version 5.00 site Amdahl 1-Apr-1988"),-1);
}

canonical_original_code:
void ver()
{
        (void) waddnstr(stdscr,("EMPIRE, Version 5.00 site Amdahl 1-Apr-1988"),-1);
}


check

decompiled_code:
__int64 check()
{
__int64 i; // rbp
_QWORD *v1; // rax
unsigned __int64 v2; // r14
__int64 j; // r12
__int64 k; // rbx
__int64 v5; // rax
char *v6; // rbx
__int64 v7; // rbx
__int64 result; // rax

memset(in_free, 0, sizeof(in_free));
memset(in_obj, 0, sizeof(in_obj));
memset(in_loc, 0, sizeof(in_loc));
memset(in_cargo, 0, 0x4E20uLL);
for ( i = free_list; i; i = *(_QWORD *)i )
{
if ( in_free[0xEC4EC4EC4EC4EC5LL * ((i - (__int64)&object) >> 3)] )
assert("x", "util.c", 0x120u);
in_free[0xEC4EC4EC4EC4EC5LL * ((i - (__int64)&object) >> 3)] = 1;
if ( *(_WORD *)(i + 72) )
assert("x", "util.c", 0x122u);
v1 = *(_QWORD **)(i + 8);
if ( v1 && *v1 != i )
assert("x", "util.c", 0x124u);
}
v2 = (unsigned int)((_DWORD)map + 8);
for ( j = 0LL; j != 6000; ++j )
{
if ( *(_QWORD *)v2 && **(_QWORD **)v2 != j )
assert("x", "util.c", 0x12Du);
for ( k = *(_QWORD *)(v2 + 8); k; k = *(_QWORD *)(k + 16) )
{
if ( *(_QWORD *)(k + 56) != j )
assert("x", "util.c", 0x130u);
if ( *(__int16 *)(k + 72) <= 0 )
assert("x", "util.c", 0x131u);
if ( (unsigned int)(*(_DWORD *)(k + 48) - 1) > 1 )
assert("x", "util.c", 0x132u);
if ( in_loc[0xEC4EC4EC4EC4EC5LL * ((k - (__int64)&object) >> 3)] )
assert("x", "util.c", 0x135u);
in_loc[0xEC4EC4EC4EC4EC5LL * ((k - (__int64)&object) >> 3)] = 1;
v5 = *(_QWORD *)(k + 24);
if ( v5 && *(_QWORD *)(v5 + 16) != k )
assert("x", "util.c", 0x139u);
}
v2 += 24LL;
}
v6 = (char *)&city;
do
{
if ( (char *)map[3 * *(_QWORD *)v6 + 1] != v6 )
assert("x", "util.c", 0x140u);
v6 += 104;
}
while ( v6 != (char *)&city + 7280 );
v7 = 0LL;
check_obj((__int64)&comp_obj, 2);
check_obj((__int64)&user_obj, 1);
check_cargo(*((__int64 **)&user_obj + 5), 0);
check_cargo(*((__int64 **)&comp_obj + 5), 0);
check_cargo(*((__int64 **)&user_obj + 6), 1);
check_cargo(*((__int64 **)&comp_obj + 6), 1);
check_obj_cargo((char **)&comp_obj);
check_obj_cargo((char **)&user_obj);
do
{
result = (unsigned int)in_loc[v7];
if ( (_DWORD)result )
result = in_obj[v7] != 0;
if ( in_free[v7] == (_DWORD)result )
assert("x", "util.c", 0x156u);
++v7;
}
while ( v7 != 5000 );
return result;
}

original_code:
void
check () {
 void check_cargo(), check_obj(), check_obj_cargo();
 long i, j;
 piece_info_t *p;
 for (i = 0; i < 5000; i++) {
  in_free[i] = 0;
  in_obj[i] = 0;
  in_loc[i] = 0;
  in_cargo[i] = 0;
 }
 for (p = free_list; p != ((void *)0); p = p->piece_link.next) {
  i = p - object;
  if (!(!in_free[i])) assert ("x", "util.c", 288);;
  in_free[i] = 1;
  if (!(p->hits == 0)) assert ("x", "util.c", 290);;
  if (p->piece_link.prev)
   if (!(p->piece_link.prev->piece_link.next == p)) assert ("x", "util.c", 292);;
 }
 for (i = 0; i < (100 * 60); i++) {
  if (map[i].cityp) if (!(map[i].cityp->loc == i)) assert ("x", "util.c", 301);;
  for (p = map[i].objp; p != ((void *)0); p = p->loc_link.next) {
   if (!(p->loc == i)) assert ("x", "util.c", 304);;
   if (!(p->hits > 0)) assert ("x", "util.c", 305);;
   if (!(p->owner == 1 || p->owner == 2)) assert ("x", "util.c", 306);;
   j = p - object;
   if (!(!in_loc[j])) assert ("x", "util.c", 309);;
   in_loc[j] = 1;
   if (p->loc_link.prev)
    if (!(p->loc_link.prev->loc_link.next == p)) assert ("x", "util.c", 313);;
  }
 }
 for (i = 0; i < 70; i++)
  if (!(map[city[i].loc].cityp == &(city[i]))) assert ("x", "util.c", 320);;
 check_obj (comp_obj, 2);
 check_obj (user_obj, 1);
 check_cargo (user_obj[5], 0);
 check_cargo (comp_obj[5], 0);
 check_cargo (user_obj[6], 1);
 check_cargo (comp_obj[6], 1);
 check_obj_cargo (comp_obj);
 check_obj_cargo (user_obj);
 for (i = 0; i < 5000; i++)
  if (!(in_free[i] != (in_loc[i] && in_obj[i]))) assert ("x", "util.c", 342);;
}

canonical_original_code:
void check() {
 void check_cargo(); void check_obj(); void check_obj_cargo();
 long i; long j;
 struct piece_info *p;
 for (i = 0; i < 5000; i++) {
  in_free[i] = 0;
  in_obj[i] = 0;
  in_loc[i] = 0;
  in_cargo[i] = 0;
 }
 for (p = free_list; p != ((void *)0); p = p->piece_link.next) {
  i = p - object;
  if (!(!in_free[i])) assert ("x", "util.c", 288);;
  in_free[i] = 1;
  if (!(p->hits == 0)) assert ("x", "util.c", 290);;
  if (p->piece_link.prev)
   if (!(p->piece_link.prev->piece_link.next == p)) assert ("x", "util.c", 292);;
 }
 for (i = 0; i < (100 * 60); i++) {
  if (map[i].cityp) if (!(map[i].cityp->loc == i)) assert ("x", "util.c", 301);;
  for (p = map[i].objp; p != ((void *)0); p = p->loc_link.next) {
   if (!(p->loc == i)) assert ("x", "util.c", 304);;
   if (!(p->hits > 0)) assert ("x", "util.c", 305);;
   if (!(p->owner == 1 || p->owner == 2)) assert ("x", "util.c", 306);;
   j = p - object;
   if (!(!in_loc[j])) assert ("x", "util.c", 309);;
   in_loc[j] = 1;
   if (p->loc_link.prev)
    if (!(p->loc_link.prev->loc_link.next == p)) assert ("x", "util.c", 313);;
  }
 }
 for (i = 0; i < 70; i++)
  if (!(map[city[i].loc].cityp == &(city[i]))) assert ("x", "util.c", 320);;
 check_obj (comp_obj, 2);
 check_obj (user_obj, 1);
 check_cargo (user_obj[5], 0);
 check_cargo (comp_obj[5], 0);
 check_cargo (user_obj[6], 1);
 check_cargo (comp_obj[6], 1);
 check_obj_cargo (comp_obj);
 check_obj_cargo (user_obj);
 for (i = 0; i < 5000; i++)
  if (!(in_free[i] != (in_loc[i] && in_obj[i]))) assert ("x", "util.c", 342);;
}

variable_types: i long

variable_types: j long

variable_types: struct piece_info { struct link_t { struct piece_info *next; struct piece_info *prev; } piece_link; struct link_t loc_link; struct link_t cargo_link; int owner; int type; long loc; long func; short hits; int moved; struct piece_info *ship; struct piece_info *cargo; short count; short range; } *

user_defined_types: struct piece_info { struct link_t piece_link; struct link_t loc_link; struct link_t cargo_link; int owner; int type; long loc; long func; short hits; int moved; struct piece_info *ship; struct piece_info *cargo; short count; short range; }


decompiled_code:
__int64 __fastcall c_give(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdi
__int64 i; // rax
__int64 *v5; // rdx
__int64 v6; // rsi
__int64 result; // rax
int v8[74]; // [rsp+0h] [rbp-128h]

v2 = (unsigned int)((_DWORD)city + 8);
v3 = 0LL;
for ( i = 0LL; i != 70; ++i )
{
if ( !*(_BYTE *)v2 )
v8[v3++] = i;
v2 += 104LL;
}
if ( v3 )
{
v5 = &city[13 * v8[irand(v3, a2, v2)]];
v6 = *v5;
*((_BYTE *)v5 + 8) = 2;
*((_BYTE *)v5 + 96) = -1;
v5[11] = 0LL;
result = scan(&comp_map, v6);
}
else
{
error((int)"There are no unowned cities.", 0, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
result = ksend("There are no unowned cities.", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rdx
__int64 v3; // rdi
__int64 i; // rax
__int64 *v5; // rdx
__int64 v6; // rsi
__int64 result; // rax
int v8[74]; // [rsp+0h] [rbp-128h]

v2 = (unsigned int)((_DWORD)city + 8);
v3 = 0LL;
for ( i = 0LL; i != 70; ++i )
{
if ( !*(_BYTE *)v2 )
v8[v3++] = i;
v2 += 104LL;
}
if ( v3 )
{
v5 = &city[13 * v8[irand(v3, a2, v2)]];
v6 = *v5;
*((_BYTE *)v5 + 8) = 2;
*((_BYTE *)v5 + 96) = -1;
v5[11] = 0LL;
result = scan(&comp_map, v6);
}
else
{
error((int)"There are no unowned cities.", 0, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
result = ksend("There are no unowned cities.", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return result;
}

original_code:
void
c_give () {
 int unowned[70];
 long i, count;
 count = 0;
 for (i = 0; i < 70; i++) {
  if (city[i].owner == 0) {
   unowned[count] = i;
   count += 1;
  }
 }
 if (count == 0) {
  error ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  ksend ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  return;
 }
 i = irand (count);
 i = unowned[i];
 city[i].owner = 2;
 city[i].prod = ((char)255);
 city[i].work = 0;
 scan (comp_map, city[i].loc);
}

canonical_original_code:
void c_give() {
 int unowned[70];
 long i; long count;
 count = 0;
 for (i = 0; i < 70; i++) {
  if (city[i].owner == 0) {
   unowned[count] = i;
   count += 1;
  }
 }
 if (count == 0) {
  error ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  ksend ("There are no unowned cities.",0,0,0,0,0,0,0,0);
  return;
 }
 i = irand (count);
 i = unowned[i];
 city[i].owner = 2;
 city[i].prod = ((char)255);
 city[i].work = 0;
 scan (comp_map, city[i].loc);
}

variable_types:
unowned
int [70]

variable_types: count long


decompiled_code:
__int64 c_quit()
{
__int64 result; // rax

result = getyn("QUIT - Are you sure? ");
if ( (_DWORD)result )
result = empend();
return result;
}

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

result = getyn("QUIT - Are you sure? ");
if ( (_DWORD)result )
result = empend();
return result;
}

original_code:
void
c_quit () {
 if (getyn ("QUIT - Are you sure? ")) {
     empend ();
 }
}

canonical_original_code:
void c_quit() {
 if (getyn ("QUIT - Are you sure? ")) {
     empend ();
 }
}


decompiled_code:
__int64 c_sector()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(1LL, &user_map, v0);
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(1LL, &user_map, v0);
}

original_code:
void
c_sector () {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(1,user_map,num);
}

canonical_original_code:
void c_sector() {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(1,user_map,num);
}

variable_types: num int


decompiled_code:
__int64 c_examine()
{
unsigned int v0; // eax

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(2LL, &comp_map, v0);
}

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

v0 = get_range("Sector number? ", 0LL, 9LL);
return print_sector(2LL, &comp_map, v0);
}

original_code:
void
c_examine () {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(2,comp_map,num);
}

canonical_original_code:
void c_examine() {
 int num;
 num = get_range ("Sector number? ", 0, (5 * 2)-1);
 print_sector(2,comp_map,num);
}


decompiled_code:
void __noreturn c_movie()
{
wclear(stdscr);
while ( 1 )
{
comp_move(1LL);
print_zoom(&comp_map);
save_game();
}
}

canonical_decompiled_code:
void __noreturn func5()
{
wclear(stdscr);
while ( 1 )
{
comp_move(1LL);
print_zoom(&comp_map);
save_game();
}
}

original_code:
void
c_movie () {
 (void) wclear(stdscr);
 for (;;) {
  comp_move (1);
  print_zoom (comp_map);
  save_game ();
 }
}

canonical_original_code:
void c_movie() {
 (void) wclear(stdscr);
 for (;;) {
  comp_move (1);
  print_zoom (comp_map);
  save_game ();
 }
}


empire

decompiled_code:
void __noreturn empire()
{
int v0; // ebx
char v1; // al

ttinit();
rndini();
clear_screen();
wmove(stdscr, 7, 0);
ver();
pos_str(8LL, 0LL, "Detailed directions are in EMPIRE.DOC\n", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
if ( !(unsigned int)restore_game() )
init_game();
v0 = 0;
while ( 1 )
{
if ( automove )
{
while ( 1 )
{
++v0;
user_move();
comp_move(1LL);
if ( v0 % save_interval )
break;
save_game();
if ( !automove )
goto LABEL_7;
}
}
else
{
LABEL_7:
prompt(0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
prompt("Your orders? ", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
v1 = get_chx();
do_command((unsigned int)v1, 0LL);
}
}
}

canonical_decompiled_code:
void __noreturn func8()
{
int v0; // ebx
char v1; // al

ttinit();
rndini();
clear_screen();
wmove(stdscr, 7, 0);
ver();
pos_str(8LL, 0LL, "Detailed directions are in EMPIRE.DOC\n", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
if ( !(unsigned int)restore_game() )
init_game();
v0 = 0;
while ( 1 )
{
if ( automove )
{
while ( 1 )
{
++v0;
user_move();
comp_move(1LL);
if ( v0 % save_interval )
break;
save_game();
if ( !automove )
goto LABEL_7;
}
}
else
{
LABEL_7:
prompt(0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
wrefresh(stdscr);
prompt("Your orders? ", 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
v1 = get_chx();
func7((unsigned int)v1, 0LL);
}
}
}

original_code:
void
empire () {
 void do_command();
 void print_zoom();
 char order;
 int turn = 0;
 ttinit ();
 rndini ();
 clear_screen ();
 (void) wmove(stdscr,(7),(0));
 ver ();
 pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n",0,0,0,0,0,0,0,0);
 (void) wrefresh(stdscr);
 if (!restore_game ())
  init_game ();
 for (;;) {
     if (automove) {
  user_move ();
  comp_move (1);
  if (++turn % save_interval == 0)
   save_game ();
     }
     else {
  prompt (0,0,0,0,0,0,0,0,0);
  (void) wrefresh(stdscr);
         prompt ("Your orders? ",0,0,0,0,0,0,0,0);
         order = get_chx ();
  do_command (order);
     }
 }
}

canonical_original_code:
void empire() {
 void do_command();
 void print_zoom();
 char order;
 int turn = 0;
 ttinit ();
 rndini ();
 clear_screen ();
 (void) wmove(stdscr,(7),(0));
 ver ();
 pos_str (8, 0, "Detailed directions are in EMPIRE.DOC\n",0,0,0,0,0,0,0,0);
 (void) wrefresh(stdscr);
 if (!restore_game ())
  init_game ();
 for (;;) {
     if (automove) {
  user_move ();
  comp_move (1);
  if (++turn % save_interval == 0)
   save_game ();
     }
     else {
  prompt (0,0,0,0,0,0,0,0,0);
  (void) wrefresh(stdscr);
         prompt ("Your orders? ",0,0,0,0,0,0,0,0);
         order = get_chx ();
  do_command (order);
     }
 }
}

variable_types: order char

variable_types: turn int


rndini

decompiled_code:
void rndini()
{
unsigned __int16 v0; // ax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned __int16 v0; // ax

v0 = time(0LL);
srand(v0);
}

original_code:
void rndini()
{
 srand((unsigned)(time(0) & 0xFFFF));
}

canonical_original_code:
void rndini()
{
 srand((unsigned int)(time(0) & 0xFFFF));
}


bucleAccept

repo: Dinuuu/SDSockets

decompiled_code:
void __fastcall __noreturn bucleAccept(void *a1)
{
void *v1; // rbp
int v2; // er13
size_t v3; // r12
int v4; // eax
int v5; // er12
__int64 v6; // rax
int v7; // edx
socklen_t addr_len; // [rsp+Ch] [rbp-7Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF
char src[104]; // [rsp+20h] [rbp-68h] BYREF

v1 = 0LL;
while ( 1 )
{
addr_len = 16;
v2 = accept((int)a1, &addr, &addr_len);
if ( v2 < 0 )
{
perror("error en accept");
close((int)a1);
pthread_exit(0LL);
}
while ( 1 )
{
v4 = read(v2, src, 0x40uLL);
v5 = v4;
if ( v4 <= 0 )
break;
v3 = v4;
v1 = realloc(v1, v4);
memcpy(v1, src, v3);
}
v6 = unMarshallMsg(v1);
v7 = *(_DWORD *)v6;
if ( *(_DWORD *)v6 == 5 )
{
notifi_alta(*(_QWORD *)(v6 + 8));
if ( v5 )
goto LABEL_13;
}
else
{
if ( v7 == 6 )
{
notifi_baja(*(_QWORD *)(v6 + 8));
}
else if ( v7 == 3 )
{
notifi(*(_QWORD *)(v6 + 8), *(_QWORD *)(v6 + 16));
}
if ( v5 )
{
LABEL_13:
perror("error en read");
close((int)a1);
close(v2);
pthread_exit(0LL);
}
}
close(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
void *v1; // rbp
int v2; // er13
size_t v3; // r12
int v4; // eax
int v5; // er12
__int64 v6; // rax
int v7; // edx
socklen_t addr_len; // [rsp+Ch] [rbp-7Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF
char src[104]; // [rsp+20h] [rbp-68h] BYREF

v1 = 0LL;
while ( 1 )
{
addr_len = 16;
v2 = accept((int)a1, &addr, &addr_len);
if ( v2 < 0 )
{
perror("error en accept");
close((int)a1);
pthread_exit(0LL);
}
while ( 1 )
{
v4 = read(v2, src, 0x40uLL);
v5 = v4;
if ( v4 <= 0 )
break;
v3 = v4;
v1 = realloc(v1, v4);
memcpy(v1, src, v3);
}
v6 = unMarshallMsg(v1);
v7 = *(_DWORD *)v6;
if ( *(_DWORD *)v6 == 5 )
{
notifi_alta(*(_QWORD *)(v6 + 8));
if ( v5 )
goto LABEL_13;
}
else
{
if ( v7 == 6 )
{
notifi_baja(*(_QWORD *)(v6 + 8));
}
else if ( v7 == 3 )
{
notifi(*(_QWORD *)(v6 + 8), *(_QWORD *)(v6 + 16));
}
if ( v5 )
{
LABEL_13:
perror("error en read");
close((int)a1);
close(v2);
pthread_exit(0LL);
}
}
close(v2);
}
}

original_code:
void* bucleAccept(void* socket) {
 int socketNum = (int) socket;
 int s_conec, leido;
 unsigned int tam_dir;
 struct sockaddr_in dir_cliente;
 char buf[64];
 char * mensaje = ((void *)0);
 int mensajeLong = 0;
 while (1) {
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(socketNum, (struct sockaddr *) &dir_cliente,
    &tam_dir)) < 0) {
   perror("error en accept");
   close(socketNum);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, mensajeLong + leido * sizeof(char));
   memcpy((void*) mensaje, (void*) buf, leido);
  }
  notif notificacion = unMarshallMsg(mensaje);
  switch (notificacion->opt) {
  case 3:
   (*notifi)(notificacion->tema, notificacion->mensaje);
   break;
  case 5:
   (*notifi_alta)(notificacion->tema);
   break;
  case 6:
   (*notifi_baja)(notificacion->tema);
   break;
  }
  if (leido < 0) {
   perror("error en read");
   close(socketNum);
   close(s_conec);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  close(s_conec);
 }
 close(socketNum);
 pthread_exit(((void *)0) );
 return ((void *)0) ;
}

canonical_original_code:
void *bucleAccept(void *socket) {
 int socketNum = (int) socket;
 int s_conec; int leido;
 unsigned int tam_dir;
 struct sockaddr_in dir_cliente;
 char buf[64];
 char *mensaje = ((void *)0);
 int mensajeLong = 0;
 while (1) {
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(socketNum, (struct sockaddr *) &dir_cliente,
    &tam_dir)) < 0) {
   perror("error en accept");
   close(socketNum);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, mensajeLong + leido * sizeof(char));
   memcpy((void *) mensaje, (void *) buf, leido);
  }
  struct notificacion *notificacion = unMarshallMsg(mensaje);
  switch (notificacion->opt) {
  case 3:
   (*notifi)(notificacion->tema, notificacion->mensaje);
   break;
  case 5:
   (*notifi_alta)(notificacion->tema);
   break;
  case 6:
   (*notifi_baja)(notificacion->tema);
   break;
  }
  if (leido < 0) {
   perror("error en read");
   close(socketNum);
   close(s_conec);
   pthread_exit(((void *)0) );
   return ((void *)0) ;
  }
  close(s_conec);
 }
 close(socketNum);
 pthread_exit(((void *)0) );
 return ((void *)0) ;
}

variable_types:
socket
void *

variable_types: socketNum int

variable_types: leido int

variable_types:
buf
char [64]

variable_types:
mensaje
char *

variable_types: mensajeLong int

variable_types: struct notificacion { int opt; char *tema; char *mensaje; int puerto; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *cliente; } *

return_type: void *

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

user_defined_types: struct notificacion { int opt; char *tema; char *mensaje; int puerto; struct sockaddr_in *cliente; }

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


decompiled_code:
__int64 fin_subscriptor()
{
__int64 result; // rax

if ( !puerto )
return 0xFFFFFFFFLL;
enviarMensaje(4LL);
close(socketAbierto);
result = 0LL;
socketAbierto = 0;
puerto = 0;
threadId = 0LL;
return result;
}

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

if ( !puerto )
return 0xFFFFFFFFLL;
enviarMensaje(4LL);
close(socketAbierto);
result = 0LL;
socketAbierto = 0;
puerto = 0;
threadId = 0LL;
return result;
}

original_code:
int fin_subscriptor() {
 if (puerto == 0)
  return -1;
 enviarMensaje(4, puerto);
 close(socketAbierto);
 socketAbierto = 0;
 puerto = 0;
 threadId = 0;
 return 0;
}


decompiled_code:
__int64 alta_subscripcion_tema()
{
__int64 result; // rax

if ( puerto )
result = enviarMensaje(1LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

if ( puerto )
result = enviarMensaje(1LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int alta_subscripcion_tema(const char *tema) {
 if (puerto == 0)
  return -1;
 return enviarMensaje(1, tema, puerto);
}

canonical_original_code:
int alta_subscripcion_tema(char *tema) {
 if (puerto == 0)
  return -1;
 return enviarMensaje(1, tema, puerto);
}

variable_types:
tema
char *


decompiled_code:
__int64 baja_subscripcion_tema()
{
return enviarMensaje(2LL);
}

canonical_decompiled_code:
__int64 func4()
{
return enviarMensaje(2LL);
}

original_code:
int baja_subscripcion_tema(const char *tema) {
 return enviarMensaje(2, tema, puerto);
}

canonical_original_code:
int baja_subscripcion_tema(char *tema) {
 return enviarMensaje(2, tema, puerto);
}


decompiled_code:
__int64 __fastcall inicio_subscriptor(__int64 (__fastcall *a1)(_QWORD, _QWORD), __int64 (__fastcall *a2)(_QWORD), __int64 (__fastcall *a3)(_QWORD))
{
unsigned int v3; // er12
int v5; // eax
int v6; // ebp
unsigned __int16 v7; // ax
int optval; // [rsp+8h] [rbp-40h] BYREF
socklen_t len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-28h] BYREF

v3 = puerto;
if ( puerto )
return (unsigned int)-1;
notifi = a1;
notifi_alta = a2;
notifi_baja = a3;
optval = 1;
v5 = socket(2, 1, 6);
v6 = v5;
if ( v5 >= 0 )
{
if ( setsockopt(v5, 1, 2, &optval, 4u) < 0 )
{
v3 = 1;
perror("error en setsockopt");
return v3;
}
*(_QWORD *)&addr.sa_family = 2LL;
if ( bind(v6, &addr, 0x10u) < 0 )
{
v3 = 1;
perror("error en bind");
close(v6);
return v3;
}
if ( listen(v6, 64) < 0 )
{
v3 = 1;
perror("error en listen");
close(v6);
return v3;
}
len = 16;
getsockname(v6, &v11, &len);
v7 = _bswap_16(*(__int16 *)v11.sa_data);
socketAbierto = v6;
puerto = v7;
if ( (int)enviarMensaje(7LL) >= 0 )
{
pthread_create(&threadId, 0LL, (void *(*)(void *))bucleAccept, (void *)v6);
return v3;
}
return (unsigned int)-1;
}
perror("error creando socket");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 (__fastcall *a1)(_QWORD, _QWORD), __int64 (__fastcall *a2)(_QWORD), __int64 (__fastcall *a3)(_QWORD))
{
unsigned int v3; // er12
int v5; // eax
int v6; // ebp
unsigned __int16 v7; // ax
int optval; // [rsp+8h] [rbp-40h] BYREF
socklen_t len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr v11; // [rsp+20h] [rbp-28h] BYREF

v3 = puerto;
if ( puerto )
return (unsigned int)-1;
notifi = a1;
notifi_alta = a2;
notifi_baja = a3;
optval = 1;
v5 = socket(2, 1, 6);
v6 = v5;
if ( v5 >= 0 )
{
if ( setsockopt(v5, 1, 2, &optval, 4u) < 0 )
{
v3 = 1;
perror("error en setsockopt");
return v3;
}
*(_QWORD *)&addr.sa_family = 2LL;
if ( bind(v6, &addr, 0x10u) < 0 )
{
v3 = 1;
perror("error en bind");
close(v6);
return v3;
}
if ( listen(v6, 64) < 0 )
{
v3 = 1;
perror("error en listen");
close(v6);
return v3;
}
len = 16;
getsockname(v6, &v11, &len);
v7 = func0(*(__int16 *)v11.sa_data);
socketAbierto = v6;
puerto = v7;
if ( (int)enviarMensaje(7LL) >= 0 )
{
pthread_create(&threadId, 0LL, (void *(*)(void *))bucleAccept, (void *)v6);
return v3;
}
return (unsigned int)-1;
}
perror("error creando socket");
return 1LL;
}

original_code:
int inicio_subscriptor(void (*notif_evento)(const char *, const char *),
  void (*alta_tema)(const char *), void (*baja_tema)(const char *)) {
 if (puerto != 0)
  return -1;
 notifi = notif_evento;
 notifi_alta = alta_tema;
 notifi_baja = baja_tema;
 int s;
 struct sockaddr_in dir;
 int opcion = 1;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 dir.sin_port = 0;
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 struct sockaddr_in aux;
 int tam = sizeof(aux);
 getsockname(s, (void*) &aux, (socklen_t *) &tam);
 puerto = ntohs(aux.sin_port);
 socketAbierto = s;
 if (enviarMensaje(7, puerto) < 0)
  return -1;
 pthread_create(&threadId, ((void *)0), bucleAccept, (void*) s);
 return 0;
}

canonical_original_code:
int inicio_subscriptor(void (*notif_evento)(char *, char *), void (*alta_tema)(char *), void (*baja_tema)(char *)) {
 if (puerto != 0)
  return -1;
 notifi = notif_evento;
 notifi_alta = alta_tema;
 notifi_baja = baja_tema;
 int s;
 struct sockaddr_in dir;
 int opcion = 1;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((unsigned int) 0x00000000);
 dir.sin_port = 0;
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 struct sockaddr_in aux;
 int tam = sizeof(aux);
 getsockname(s, (void *) &aux, (unsigned int *) &tam);
 puerto = ntohs(aux.sin_port);
 socketAbierto = s;
 if (enviarMensaje(7, puerto) < 0)
  return -1;
 pthread_create(&threadId, ((void *)0), bucleAccept, (void *) s);
 return 0;
}

variable_types: s int

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

variable_types: opcion int

variable_types: tam int


decompiled_code:
int __fastcall baja_tema(const char *a1)
{
return printf("\n-> Recibida baja tema %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("\n-> Recibida baja tema %s\n", a1);
}

original_code:
static void baja_tema(const char *t) {
 printf("\n-> Recibida baja tema %s\n", t);
}

canonical_original_code:
static void baja_tema(char *t) {
 printf("\n-> Recibida baja tema %s\n", t);
}

variable_types:
t
char *


decompiled_code:
int __fastcall alta_tema(const char *a1)
{
return printf("\n-> Recibida alta tema %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("\n-> Recibida alta tema %s\n", a1);
}

original_code:
static void alta_tema(const char *t) {
 printf("\n-> Recibida alta tema %s\n", t);
}

canonical_original_code:
static void alta_tema(char *t) {
 printf("\n-> Recibida alta tema %s\n", t);
}


decompiled_code:
int __fastcall notificacion_evento(const char *a1, const char *a2)
{
return printf("\n-> Recibido evento %s con valor %s\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, const char *a2)
{
return printf("\n-> Recibido evento %s con valor %s\n", a1, a2);
}

original_code:
static void notificacion_evento(const char *t, const char *e) {
 printf("\n-> Recibido evento %s con valor %s\n", t, e);
}

canonical_original_code:
static void notificacion_evento(char *t, char *e) {
 printf("\n-> Recibido evento %s con valor %s\n", t, e);
}

variable_types:
e
char *


decompiled_code:
__int64 __fastcall leer_orden(_DWORD *a1, __int64 a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v3, 256, stdin) )
return 0LL;
if ( (unsigned int)_isoc99_sscanf(v3, "%u%64s", a1, a2) == 2 && *a1 <= 1u )
break;
puts("\nError formato de entrada");
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, __int64 a2)
{
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v3, 256, stdin) )
return 0LL;
if ( (unsigned int)_isoc99_sscanf(v3, "%u%64s", a1, a2) == 2 && *a1 <= 1u )
break;
puts("\nError formato de entrada");
}
return 1LL;
}

original_code:
static _Bool leer_orden(unsigned int *op, char *tema) {
 char linea[256];
 _Bool leido = 0;
 do {
  printf(
    "\nIntroduzca una línea con la operación (0 = alta; 1 = baja) y el tema\n");
  if (fgets(linea, 256, stdin) == ((void *)0) )
   return 0;
  if ((sscanf(linea, "%u%64s", op, tema) == 2) && (*op < 2))
   leido = 1;
  else
   printf("\nError formato de entrada\n");
 } while (!leido);
 return 1;
}

variable_types:
op
unsigned int *

variable_types:
linea
char [256]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+Ch] [rbp-4Ch] BYREF
char v5[72]; // [rsp+10h] [rbp-48h] BYREF

inicio_subscriptor(notificacion_evento, alta_tema, baja_tema);
while ( (unsigned __int8)leer_orden(&v4, (__int64)v5) )
{
if ( (int)(*(&ops + v4))(v5) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v4], v5);
}
fin_subscriptor();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // [rsp+Ch] [rbp-4Ch] BYREF
char v5[72]; // [rsp+10h] [rbp-48h] BYREF

inicio_subscriptor(notificacion_evento, alta_tema, baja_tema);
while ( (unsigned __int8)func3(&v4, (__int64)v5) )
{
if ( (int)(*(&ops + v4))(v5) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v4], v5);
}
fin_subscriptor();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 unsigned int op;
 char tema[64];
 inicio_subscriptor(notificacion_evento, alta_tema, baja_tema);
 while (leer_orden(&op, tema))
  if (ops[op](tema) < 0)
   fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[op], tema);
 fin_subscriptor();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
op
unsigned int

variable_types:
tema
char [64]


decompiled_code:
__int64 leer_evento()
{
char v1[280]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v1, 256, _bss_start) )
return 0LL;
if ( (unsigned int)__isoc99_sscanf() == 2 )
break;
puts("\nError formato de entrada");
}
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
char v1[280]; // [rsp+0h] [rbp-118h] BYREF

while ( 1 )
{
puts(aIntroduzcaUnaL);
if ( !fgets(v1, 256, _bss_start) )
return 0LL;
if ( (unsigned int)__isoc99_sscanf() == 2 )
break;
puts("\nError formato de entrada");
}
return 1LL;
}

original_code:
static _Bool leer_evento(char *tema, char *valor) {
 char linea[256];
 _Bool leido = 0;
 do {
  printf("\nIntroduzca una línea con el tema y el valor del evento\n");
  if (fgets(linea, 256, stdin) == ((void *)0) )
   return 0;
  if (sscanf(linea, "%64s%64s", tema, valor) == 2)
   leido = 1;
  else
   printf("\nError formato de entrada\n");
 } while (!leido);
 return 1;
}

variable_types:
valor
char *


decompiled_code:
__int64 __fastcall generar_evento(int a1, int a2, __int64 a3, int a4, int a5, int a6, char a7)
{
return enviarMensaje(3, a1, a2, a4, a5, a6, a7);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, __int64 a3, int a4, int a5, int a6, char a7)
{
return func13(3, a1, a2, a4, a5, a6, a7);
}

original_code:
int generar_evento(const char *tema, const char *valor) {
 return enviarMensaje(3, tema, valor);
}

canonical_original_code:
int generar_evento(char *tema, char *valor) {
 return enviarMensaje(3, tema, valor);
}


decompiled_code:
__int64 __fastcall eliminar_tema(int a1, __int64 a2, int a3, int a4, int a5, int a6, char a7)
{
return enviarMensaje(6, a1, a3, a4, a5, a6, a7);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, int a3, int a4, int a5, int a6, char a7)
{
return func13(6, a1, a3, a4, a5, a6, a7);
}

original_code:
int eliminar_tema(const char *tema) {
 return enviarMensaje(6, tema);
}

canonical_original_code:
int eliminar_tema(char *tema) {
 return enviarMensaje(6, tema);
}


conectarIntermediario

decompiled_code:
__int64 conectarIntermediario()
{
char *v0; // rbp
char *v1; // r12
struct hostent *v2; // rax
__int16 v3; // ax
int v4; // edx
int v5; // eax
unsigned int v6; // er12
int v8; // edi
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

v0 = getenv("SERVIDOR");
v1 = getenv("PUERTO");
v2 = gethostbyname(v0);
memcpy(&v9[0].sa_data[2], *(const void **)v2->h_addr_list, v2->h_length);
v3 = atoi(v1);
*(_WORD *)v9[0].sa_data = _bswap_16(v3);
v9[0].sa_family = 2;
v5 = socket(2, 1, v4);
if ( v5 < 0 )
{
v6 = -1;
perror("error creando socket");
}
else
{
v6 = v5;
if ( connect(v5, v9, 0x10u) < 0 )
{
perror("error en connect");
v8 = v6;
v6 = -1;
close(v8);
}
}
return v6;
}

canonical_decompiled_code:
__int64 func12()
{
char *v0; // rbp
char *v1; // r12
struct hostent *v2; // rax
__int16 v3; // ax
int v4; // edx
int v5; // eax
unsigned int v6; // er12
int v8; // edi
struct sockaddr v9[2]; // [rsp+0h] [rbp-28h] BYREF

v0 = getenv("SERVIDOR");
v1 = getenv("PUERTO");
v2 = gethostbyname(v0);
memcpy(&v9[0].sa_data[2], *(const void **)v2->h_addr_list, v2->h_length);
v3 = atoi(v1);
*(_WORD *)v9[0].sa_data = func11(v3);
v9[0].sa_family = 2;
v5 = socket(2, 1, v4);
if ( v5 < 0 )
{
v6 = -1;
perror("error creando socket");
}
else
{
v6 = v5;
if ( connect(v5, v9, 0x10u) < 0 )
{
perror("error en connect");
v8 = v6;
v6 = -1;
close(v8);
}
}
return v6;
}

original_code:
int conectarIntermediario() {
 struct hostent *host_info;
 char* servidor = getenv("SERVIDOR");
 char* puerto = getenv("PUERTO");
 struct sockaddr_in dir;
 int s;
 host_info = gethostbyname(servidor);
 memcpy(&dir.sin_addr.s_addr, host_info->h_addr_list[0], host_info->h_length);
 dir.sin_port = htons(atoi(puerto));
 dir.sin_family = 2;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return -1;
 }
 if (connect(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en connect");
  close(s);
  return -1;
 }
 return s;
}

canonical_original_code:
int conectarIntermediario() {
 struct hostent *host_info;
 char *servidor = getenv("SERVIDOR");
 char *puerto = getenv("PUERTO");
 struct sockaddr_in dir;
 int s;
 host_info = gethostbyname(servidor);
 memcpy(&dir.sin_addr.s_addr, host_info->h_addr_list[0], host_info->h_length);
 dir.sin_port = htons(atoi(puerto));
 dir.sin_family = 2;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return -1;
 }
 if (connect(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en connect");
  close(s);
  return -1;
 }
 return s;
}

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types:
servidor
char *

variable_types:
puerto
char *


enviarMensaje

decompiled_code:
__int64 enviarMensaje(unsigned int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned __int64 v9; // rbp
int v10; // er12
int v11; // er14
__int64 v12; // rbx
_QWORD *v13; // r13
char *v14; // r9
unsigned int v15; // edx
char v16; // r8
char v17; // di
char *v18; // rsi
__int64 v19; // rax
__int64 v20; // rcx
char *v21; // rcx
__int64 v22; // rax
int *v23; // rdx
int v24; // er15
_BYTE *v25; // rax
void *v26; // rbp
int v27; // ebx
int v29; // edi
int v30; // [rsp+Ch] [rbp-8Ch] BYREF
int buf; // [rsp+13h] [rbp-85h] BYREF
gcc_va_list va; // [rsp+18h] [rbp-80h] BYREF

v9 = a1;
v30 = 0;
v10 = conectarIntermediario();
if ( v10 >= 0 )
{
va_start(va, a9);
switch ( a1 )
{
case 1u:
case 2u:
case 5u:
case 6u:
v11 = 1;
v12 = 1LL;
v13 = malloc(8uLL);
goto LABEL_4;
case 3u:
v11 = 2;
v12 = 2LL;
v13 = malloc(0x10uLL);
LABEL_4:
v14 = (char *)va[0].reg_save_area;
v15 = va[0].gp_offset;
v16 = 0;
v17 = 0;
v18 = (char *)va[0].overflow_arg_area;
v19 = 0LL;
do
{
if ( v15 > 0x2F )
{
v21 = v18;
v16 = 1;
v18 += 8;
}
else
{
v20 = v15;
v17 = 1;
v15 += 8;
v21 = &v14[v20];
}
v13[v19++] = *(_QWORD *)v21;
}
while ( v11 > (int)v19 );
if ( v17 )
va[0].gp_offset = v15;
if ( v16 )
va[0].overflow_arg_area = v18;
break;
case 4u:
case 7u:
v11 = 0;
v12 = 0LL;
v13 = malloc(0LL);
break;
default:
v12 = 0LL;
v11 = 0;
v13 = malloc(0LL);
break;
}
if ( (unsigned int)v9 <= 7 )
{
v22 = 150LL;
if ( _bittest64(&v22, v9) )
{
if ( va[0].gp_offset > 0x2F )
{
v23 = (int *)va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
}
else
{
v23 = (int *)((char *)va[0].reg_save_area + va[0].gp_offset);
va[0].gp_offset += 8;
}
v24 = *v23;
v25 = malloc(5uLL);
*(_DWORD *)v25 = v24;
v25[4] = 0;
v13[v12] = v25;
}
}
v26 = (void *)marshallMsg((unsigned int)v9, v13, (unsigned int)v11, &v30);
if ( write(v10, v26, v30) < 0 )
{
perror("error en write");
v29 = v10;
v10 = -1;
close(v29);
free(v26);
}
else
{
shutdown(v10, 1);
if ( (int)read(v10, &buf, 5uLL) < 0 )
perror("Error en read de respuesta");
v27 = buf;
close(v10);
free(v26);
v10 = v27;
}
}
return (unsigned int)v10;
}

canonical_decompiled_code:
__int64 func13(unsigned int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned __int64 v9; // rbp
int v10; // er12
int v11; // er14
__int64 v12; // rbx
_QWORD *v13; // r13
char *v14; // r9
unsigned int v15; // edx
char v16; // r8
char v17; // di
char *v18; // rsi
__int64 v19; // rax
__int64 v20; // rcx
char *v21; // rcx
__int64 v22; // rax
int *v23; // rdx
int v24; // er15
_BYTE *v25; // rax
void *v26; // rbp
int v27; // ebx
int v29; // edi
int v30; // [rsp+Ch] [rbp-8Ch] BYREF
int buf; // [rsp+13h] [rbp-85h] BYREF
gcc_va_list va; // [rsp+18h] [rbp-80h] BYREF

v9 = a1;
v30 = 0;
v10 = func12();
if ( v10 >= 0 )
{
va_start(va, a9);
switch ( a1 )
{
case 1u:
case 2u:
case 5u:
case 6u:
v11 = 1;
v12 = 1LL;
v13 = malloc(8uLL);
goto LABEL_4;
case 3u:
v11 = 2;
v12 = 2LL;
v13 = malloc(0x10uLL);
LABEL_4:
v14 = (char *)va[0].reg_save_area;
v15 = va[0].gp_offset;
v16 = 0;
v17 = 0;
v18 = (char *)va[0].overflow_arg_area;
v19 = 0LL;
do
{
if ( v15 > 0x2F )
{
v21 = v18;
v16 = 1;
v18 += 8;
}
else
{
v20 = v15;
v17 = 1;
v15 += 8;
v21 = &v14[v20];
}
v13[v19++] = *(_QWORD *)v21;
}
while ( v11 > (int)v19 );
if ( v17 )
va[0].gp_offset = v15;
if ( v16 )
va[0].overflow_arg_area = v18;
break;
case 4u:
case 7u:
v11 = 0;
v12 = 0LL;
v13 = malloc(0LL);
break;
default:
v12 = 0LL;
v11 = 0;
v13 = malloc(0LL);
break;
}
if ( (unsigned int)v9 <= 7 )
{
v22 = 150LL;
if ( _bittest64(&v22, v9) )
{
if ( va[0].gp_offset > 0x2F )
{
v23 = (int *)va[0].overflow_arg_area;
va[0].overflow_arg_area = (char *)va[0].overflow_arg_area + 8;
}
else
{
v23 = (int *)((char *)va[0].reg_save_area + va[0].gp_offset);
va[0].gp_offset += 8;
}
v24 = *v23;
v25 = malloc(5uLL);
*(_DWORD *)v25 = v24;
v25[4] = 0;
v13[v12] = v25;
}
}
v26 = (void *)func14((unsigned int)v9, v13, (unsigned int)v11, &v30);
if ( write(v10, v26, v30) < 0 )
{
perror("error en write");
v29 = v10;
v10 = -1;
close(v29);
free(v26);
}
else
{
shutdown(v10, 1);
if ( (int)read(v10, &buf, 5uLL) < 0 )
perror("Error en read de respuesta");
v27 = buf;
close(v10);
free(v26);
v10 = v27;
}
}
return (unsigned int)v10;
}

original_code:
void enviarMensaje(int opt, char** argumentos, int cantArgumentos,
  struct sockaddr_in * cliente) {
 int s, longitud;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return;
 }
 if (connect(s, (struct sockaddr *) cliente, sizeof(struct sockaddr_in))
   < 0) {
  perror("error en connect");
  close(s);
  return;
 }
 char* mensajeAEnviar = marshallMsg(opt, argumentos, cantArgumentos,
   &longitud);
 if (write(s, mensajeAEnviar, longitud) < 0) {
  perror("error en write");
  close(s);
  return;
 }
 close(s);
 return;
}

canonical_original_code:
void enviarMensaje(int opt, char **argumentos, int cantArgumentos, struct sockaddr_in *cliente) {
 int s; int longitud;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return;
 }
 if (connect(s, (struct sockaddr *) cliente, sizeof(struct sockaddr_in))
   < 0) {
  perror("error en connect");
  close(s);
  return;
 }
 char *mensajeAEnviar = marshallMsg(opt, argumentos, cantArgumentos,
   &longitud);
 if (write(s, mensajeAEnviar, longitud) < 0) {
  perror("error en write");
  close(s);
  return;
 }
 close(s);
 return;
}

variable_types: opt int

variable_types:
argumentos
char **

variable_types: cantArgumentos int

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

variable_types: longitud int

variable_types:
mensajeAEnviar
char *


conectarIntermediario

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

variable_types: s int

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+Ch] [rbp-8Ch] BYREF
char v5[64]; // [rsp+10h] [rbp-88h] BYREF
char v6[72]; // [rsp+50h] [rbp-48h] BYREF

while ( (unsigned __int8)leer_orden(&v4, v5, v6) )
{
if ( ((int (__fastcall *)(char *, char *))ops[v4])(v5, v6) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v4], v5);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4; // [rsp+Ch] [rbp-8Ch] BYREF
char v5[64]; // [rsp+10h] [rbp-88h] BYREF
char v6[72]; // [rsp+50h] [rbp-48h] BYREF

while ( (unsigned __int8)func7(&v4, v5, v6) )
{
if ( ((int (__fastcall *)(char *, char *))ops[v4])(v5, v6) < 0 )
fprintf(stderr, "Error en %s sobre tema %s\n", ops_nom[v4], v5);
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 if (argc != 3) {
  perror("La cantidad de argumentos es invalida");
  return 1;
 }
 char * port = argv[1];
 int portInt = atoi(port);
 char* archivo = argv[2];
 lista_temas* listaTemas = inicializar_temas(archivo);
 int s, s_conec, leido;
 unsigned int tam_dir;
 struct sockaddr_in dir, dir_cliente;
 char buf[64];
 char mensajeRsp[5];
 int opcion = 1, resp = -1;
 char* mensaje = ((void *)0);
 int mensajeLong = 0;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 dir.sin_port = htons(portInt);
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 while (1) {
  mensajeLong = 0;
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(s, (struct sockaddr *) &dir_cliente, &tam_dir))
    < 0) {
   perror("error en accept");
   close(s);
   return 1;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, (mensajeLong + leido) * sizeof(char));
   memcpy((void*) (mensaje + mensajeLong), (void*) buf, leido);
   mensajeLong += leido;
  }
  notif notificacion = unMarshallMsg(mensaje);
  struct sockaddr_in peer;
  int tamanio = sizeof(peer);
  if (notificacion->opt == 1 || notificacion->opt == 2
    || notificacion->opt == 7 || notificacion->opt == 4) {
   getpeername(s_conec, (void *) &peer, (socklen_t *) &tamanio);
   notificacion->cliente = &peer;
  }
  resp = procesarNotificacion(notificacion, listaTemas);
  memcpy((void *) mensajeRsp, (void*) &resp, sizeof(int));
  mensajeRsp[4] = 0;
  if (write(s_conec, mensajeRsp, sizeof(int)+sizeof(char)) < 0) {
   free(mensaje);
   perror("error en write");
   close(s);
   close(s_conec);
   return 1;
  }
  close(s_conec);
 }
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if (argc != 3) {
  perror("La cantidad de argumentos es invalida");
  return 1;
 }
 char *port = argv[1];
 int portInt = atoi(port);
 char *archivo = argv[2];
 struct lista_temas *listaTemas = inicializar_temas(archivo);
 int s; int s_conec; int leido;
 unsigned int tam_dir;
 struct sockaddr_in dir; struct sockaddr_in dir_cliente;
 char buf[64];
 char mensajeRsp[5];
 int opcion = 1; int resp = -1;
 char *mensaje = ((void *)0);
 int mensajeLong = 0;
 if ((s = socket(2, SOCK_STREAM, IPPROTO_TCP)) < 0) {
  perror("error creando socket");
  return 1;
 }
 if (setsockopt(s, 1, 2, &opcion, sizeof(opcion)) < 0) {
  perror("error en setsockopt");
  return 1;
 }
 dir.sin_addr.s_addr = ((unsigned int) 0x00000000);
 dir.sin_port = htons(portInt);
 dir.sin_family = 2;
 if (bind(s, (struct sockaddr *) &dir, sizeof(dir)) < 0) {
  perror("error en bind");
  close(s);
  return 1;
 }
 if (listen(s, 64) < 0) {
  perror("error en listen");
  close(s);
  return 1;
 }
 while (1) {
  mensajeLong = 0;
  tam_dir = sizeof(dir_cliente);
  if ((s_conec = accept(s, (struct sockaddr *) &dir_cliente, &tam_dir))
    < 0) {
   perror("error en accept");
   close(s);
   return 1;
  }
  while ((leido = read(s_conec, buf, 64)) > 0) {
   mensaje = realloc(mensaje, (mensajeLong + leido) * sizeof(char));
   memcpy((void *) (mensaje + mensajeLong), (void *) buf, leido);
   mensajeLong += leido;
  }
  struct notificacion *notificacion = unMarshallMsg(mensaje);
  struct sockaddr_in peer;
  int tamanio = sizeof(peer);
  if (notificacion->opt == 1 || notificacion->opt == 2
    || notificacion->opt == 7 || notificacion->opt == 4) {
   getpeername(s_conec, (void *) &peer, (unsigned int *) &tamanio);
   notificacion->cliente = &peer;
  }
  resp = procesarNotificacion(notificacion, listaTemas);
  memcpy((void *) mensajeRsp, (void *) &resp, sizeof(int));
  mensajeRsp[4] = 0;
  if (write(s_conec, mensajeRsp, sizeof(int)+sizeof(char)) < 0) {
   free(mensaje);
   perror("error en write");
   close(s);
   close(s_conec);
   return 1;
  }
  close(s_conec);
 }
 close(s);
 return 0;
}

variable_types:
port
char *

variable_types: portInt int

variable_types:
archivo
char *

variable_types: struct lista_temas { struct tema { char *tema; int cantSuscript; struct suscriptor { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *cliente; } **suscriptores; } **temas; int cant_temas; } *

variable_types: leido int

variable_types:
buf
char [64]

variable_types:
mensajeRsp
char [5]

variable_types: opcion int

variable_types: resp int

variable_types:
mensaje
char *

variable_types: mensajeLong int

variable_types: struct notificacion { int opt; char *tema; char *mensaje; int puerto; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *cliente; } *

variable_types: tamanio int

user_defined_types: struct lista_temas { struct tema **temas; int cant_temas; }

user_defined_types: struct tema { char *tema; int cantSuscript; struct suscriptor **suscriptores; }

user_defined_types: struct suscriptor { struct sockaddr_in *cliente; }


usage

repo: Distrotech/cyrus-imapd

decompiled_code:
void __noreturn usage()
{
fwrite(
"Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix "
"<url>] [--olson-dir <directory>]\n",
1uLL,
0x95uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite(
"Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix "
"<url>] [--olson-dir <directory>]\n",
1uLL,
0x95uLL,
stderr);
exit(1);
}

original_code:
static void
usage (void)
{
  fprintf (stderr, "Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix <url>] [--olson-dir <directory>]\n");
  exit (1);
}

canonical_original_code:
static void usage()
{
  fprintf (stderr, "Usage: vzic [--dump] [--dump-changes] [--no-rrules] [--no-rdates] [--pure] [--output-dir <directory>] [--url-prefix <url>] [--olson-dir <directory>]\n");
  exit (1);
}


decompiled_code:
__int64 __fastcall free_link_data(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v4; // rbx

((void (*)(void))g_free)();
if ( a3 )
{
v4 = a3;
do
{
g_free(*v4);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
return g_list_free(a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, _QWORD *a3)
{
_QWORD *v4; // rbx

((void (*)(void))g_free)();
if ( a3 )
{
v4 = a3;
do
{
g_free(*v4);
v4 = (_QWORD *)v4[1];
}
while ( v4 );
}
return g_list_free(a3);
}

original_code:
static void
free_link_data (gpointer key,
                                 gpointer value,
                                 gpointer data)
{
  GList *link = data;
  g_free (key);
  while (link) {
    g_free (link->data);
    link = link->next;
  }
  g_list_free (data);
}

canonical_original_code:
static void free_link_data(void *key, void *value, void *data)
{
  struct _GList *link = data;
  g_free (key);
  while (link) {
    g_free (link->data);
    link = link->next;
  }
  g_list_free (data);
}

variable_types:
key
void *

variable_types:
value
void *

variable_types:
data
void *

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


decompiled_code:
__int64 __fastcall free_rule_array(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // rbx

if ( *(_DWORD *)(a2 + 8) )
{
v2 = 0LL;
do
{
while ( 1 )
{
v3 = *(_QWORD *)a2 + (v2 << 6);
if ( !*(_DWORD *)(v3 + 56) )
break;
if ( *(_DWORD *)(a2 + 8) <= (unsigned int)++v2 )
goto LABEL_6;
}
++v2;
g_free(*(_QWORD *)(v3 + 8));
g_free(*(_QWORD *)(v3 + 48));
}
while ( *(_DWORD *)(a2 + 8) > (unsigned int)v2 );
}
LABEL_6:
g_array_free(a2, 1LL);
return g_free(a1);
}

original_code:
static void
free_rule_array (gpointer key,
                                 gpointer value,
                                 gpointer data)
{
  char *name = key;
  GArray *rule_array = value;
  RuleData *rule;
  int i;
  for (i = 0; i < rule_array->len; i++) {
    rule = &(((RuleData*) (void *) (rule_array)->data) [(i)]);
    if (!rule->is_shallow_copy) {
      g_free (rule->type);
      g_free (rule->letter_s);
    }
  }
  g_array_free (rule_array, (!(0)));
  g_free (name);
}

canonical_original_code:
static void free_rule_array(void *key, void *value, void *data)
{
  char *name = key;
  struct _GArray *rule_array = value;
  struct _RuleData *rule;
  int i;
  for (i = 0; i < rule_array->len; i++) {
    rule = &(((struct _RuleData *) (void *) (rule_array)->data) [(i)]);
    if (!rule->is_shallow_copy) {
      g_free (rule->type);
      g_free (rule->letter_s);
    }
  }
  g_array_free (rule_array, (!(0)));
  g_free (name);
}

variable_types:
name
char *

variable_types: struct _GArray { char *data; unsigned int len; } *

variable_types: struct _RuleData { int from_year; int to_year; char *type; int in_month; enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 } on_day_code; int on_day_number; int on_day_weekday; int at_time_seconds; enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 } at_time_code; int save_seconds; char *letter_s; int is_shallow_copy; } *

variable_types: i int

user_defined_types: struct _RuleData { int from_year; int to_year; char *type; int in_month; enum DayCode on_day_code; int on_day_number; int on_day_weekday; int at_time_seconds; enum TimeCode at_time_code; int save_seconds; char *letter_s; int is_shallow_copy; }


original_code:
static void
free_zone_data (GArray *zone_data)
{
  ZoneData *zone;
  ZoneLineData *zone_line;
  int i, j;
  for (i = 0; i < zone_data->len; i++) {
    zone = &(((ZoneData*) (void *) (zone_data)->data) [(i)]);
    g_free (zone->zone_name);
    for (j = 0; j < zone->zone_line_data->len; j++) {
      zone_line = &(((ZoneLineData*) (void *) (zone->zone_line_data)->data) [(j)]);
      g_free (zone_line->rules);
      g_free (zone_line->format);
    }
    g_array_free (zone->zone_line_data, (!(0)));
  }
  g_array_free (zone_data, (!(0)));
}

canonical_original_code:
static void free_zone_data(struct _GArray *zone_data)
{
  struct _ZoneData *zone;
  struct _ZoneLineData *zone_line;
  int i; int j;
  for (i = 0; i < zone_data->len; i++) {
    zone = &(((struct _ZoneData *) (void *) (zone_data)->data) [(i)]);
    g_free (zone->zone_name);
    for (j = 0; j < zone->zone_line_data->len; j++) {
      zone_line = &(((struct _ZoneLineData *) (void *) (zone->zone_line_data)->data) [(j)]);
      g_free (zone_line->rules);
      g_free (zone_line->format);
    }
    g_array_free (zone->zone_line_data, (!(0)));
  }
  g_array_free (zone_data, (!(0)));
}

variable_types: struct _ZoneData { char *zone_name; struct _GArray { char *data; unsigned int len; } *zone_line_data; } *

variable_types: struct _ZoneLineData { int stdoff_seconds; char *rules; int save_seconds; char *format; int until_set; int until_year; int until_month; enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 } until_day_code; int until_day_number; int until_day_weekday; int until_time_seconds; enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 } until_time_code; } *

variable_types: j int

user_defined_types: struct _ZoneData { char *zone_name; struct _GArray *zone_line_data; }

user_defined_types: struct _ZoneLineData { int stdoff_seconds; char *rules; int save_seconds; char *format; int until_set; int until_year; int until_month; enum DayCode until_day_code; int until_day_number; int until_day_weekday; int until_time_seconds; enum TimeCode until_time_code; }


decompiled_code:
int __fastcall dump_compare_strings(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
return strcmp(*(const char **)a1, *(const char **)a2);
}

original_code:
static int
dump_compare_strings (const void *arg1,
                                 const void *arg2)
{
  char **a, **b;
  a = (char**) arg1;
  b = (char**) arg2;
  return strcmp (*a, *b);
}

canonical_original_code:
static int dump_compare_strings(void *arg1, void *arg2)
{
  char **a; char **b;
  a = (char **) arg1;
  b = (char **) arg2;
  return strcmp (*a, *b);
}

variable_types:
a
char **

variable_types:
b
char **


decompiled_code:
__int64 __fastcall dump_add_rule(__int64 a1, __int64 a2, __int64 a3)
{
return g_ptr_array_add(a3, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
return g_ptr_array_add(a3, a1);
}

original_code:
static void
dump_add_rule (char *name,
                                 GArray *rule_array,
                                 GPtrArray *name_array)
{
  g_ptr_array_add (name_array, name);
}

canonical_original_code:
static void dump_add_rule(char *name, struct _GArray *rule_array, struct _GPtrArray *name_array)
{
  g_ptr_array_add (name_array, name);
}

variable_types: struct _GPtrArray { void **pdata; unsigned int len; } *

user_defined_types: struct _GArray { char *data; unsigned int len; }


decompiled_code:
const char *__fastcall dump_time(unsigned int a1, int a2, int a3)
{
const char *v3; // r9
const char *v4; // r10
unsigned __int64 v5; // rcx
unsigned __int64 v6; // r8
unsigned int v7; // eax

v3 = (const char *)&unk_D68;
if ( a2 != 1 )
{
v3 = (const char *)&unk_D6C;
if ( a2 == 2 )
v3 = (const char *)&unk_D6A;
}
v4 = (const char *)&unk_D6C;
if ( (a1 & 0x80000000) != 0 )
{
a1 = -a1;
v4 = "-";
}
sign_4 = (__int64)v4;
v5 = a1 / 0xE10uLL;
v6 = a1 % 0xE10 / 0x3CuLL;
v7 = a1 % 0x3C;
if ( a3 && !((unsigned int)v6 | v7 | (unsigned int)v5) )
return "0";
if ( v7 )
sprintf(buffer_3, "%s%i:%02i:%02i%s", v4, v5, v6, v7, v3);
else
sprintf(buffer_3, "%s%i:%02i%s", v4, v5, v6, v3);
return buffer_3;
}

canonical_decompiled_code:
const char *__fastcall func2(unsigned int a1, int a2, int a3)
{
const char *v3; // r9
const char *v4; // r10
unsigned __int64 v5; // rcx
unsigned __int64 v6; // r8
unsigned int v7; // eax

v3 = (const char *)&unk_D68;
if ( a2 != 1 )
{
v3 = (const char *)&unk_D6C;
if ( a2 == 2 )
v3 = (const char *)&unk_D6A;
}
v4 = (const char *)&unk_D6C;
if ( (a1 & 0x80000000) != 0 )
{
a1 = -a1;
v4 = "-";
}
sign_4 = (__int64)v4;
v5 = a1 / 0xE10uLL;
v6 = a1 % 0xE10 / 0x3CuLL;
v7 = a1 % 0x3C;
if ( a3 && !((unsigned int)v6 | v7 | (unsigned int)v5) )
return "0";
if ( v7 )
sprintf(buffer_3, "%s%i:%02i:%02i%s", v4, v5, v6, v7, v3);
else
sprintf(buffer_3, "%s%i:%02i%s", v4, v5, v6, v3);
return buffer_3;
}

original_code:
char*
dump_time (int seconds,
                                 TimeCode time_code,
                                 gboolean use_zero)
{
  static char buffer[256], *sign;
  int hours, minutes;
  char *code;
  if (time_code == TIME_STANDARD)
    code = "s";
  else if (time_code == TIME_UNIVERSAL)
    code = "u";
  else
    code = "";
  if (seconds < 0) {
    seconds = -seconds;
    sign = "-";
  } else {
    sign = "";
  }
  hours = seconds / 3600;
  minutes = (seconds % 3600) / 60;
  seconds = seconds % 60;
  if (use_zero && hours == 0 && minutes == 0 && seconds == 0)
    return "0";
  else if (seconds == 0)
    sprintf (buffer, "%s%i:%02i%s", sign, hours, minutes, code);
  else
    sprintf (buffer, "%s%i:%02i:%02i%s", sign, hours, minutes, seconds, code);
  return buffer;
}

canonical_original_code:
char *dump_time(int seconds, enum TimeCode time_code, int use_zero)
{
  static char buffer[256]; static char *sign;
  int hours; int minutes;
  char *code;
  if (time_code == TIME_STANDARD)
    code = "s";
  else if (time_code == TIME_UNIVERSAL)
    code = "u";
  else
    code = "";
  if (seconds < 0) {
    seconds = -seconds;
    sign = "-";
  } else {
    sign = "";
  }
  hours = seconds / 3600;
  minutes = (seconds % 3600) / 60;
  seconds = seconds % 60;
  if (use_zero && hours == 0 && minutes == 0 && seconds == 0)
    return "0";
  else if (seconds == 0)
    sprintf (buffer, "%s%i:%02i%s", sign, hours, minutes, code);
  else
    sprintf (buffer, "%s%i:%02i:%02i%s", sign, hours, minutes, seconds, code);
  return buffer;
}

variable_types: seconds int

variable_types: enum TimeCode { TIME_WALL=0, TIME_STANDARD=1, TIME_UNIVERSAL=2 }

variable_types:
buffer
char [256]

variable_types:
sign
char *

variable_types: hours int

variable_types: minutes int

variable_types:
code
char *

return_type: char *


decompiled_code:
char *__fastcall dump_day_coded(unsigned int a1, unsigned int a2, int a3)
{
char *result; // rax

if ( a1 == 2 )
{
sprintf(buffer_2, "%s<=%i", weekdays_1[a3], a2);
result = buffer_2;
}
else if ( a1 > 2 )
{
if ( a1 != 3 )
{
fprintf(stderr, "Invalid day code: %i\n", a1);
exit(1);
}
sprintf(buffer_2, "last%s", weekdays_1[a3]);
result = buffer_2;
}
else
{
if ( a1 )
sprintf(buffer_2, "%s>=%i", weekdays_1[a3], a2);
else
sprintf(buffer_2, "%i", a2);
result = buffer_2;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1, unsigned int a2, int a3)
{
char *result; // rax

if ( a1 == 2 )
{
sprintf(buffer_2, "%s<=%i", weekdays_1[a3], a2);
result = buffer_2;
}
else if ( a1 > 2 )
{
if ( a1 != 3 )
{
fprintf(stderr, "Invalid day code: %i\n", a1);
exit(1);
}
sprintf(buffer_2, "last%s", weekdays_1[a3]);
result = buffer_2;
}
else
{
if ( a1 )
sprintf(buffer_2, "%s>=%i", weekdays_1[a3], a2);
else
sprintf(buffer_2, "%i", a2);
result = buffer_2;
}
return result;
}

original_code:
char*
dump_day_coded (DayCode day_code,
                                 int day_number,
                                 int day_weekday)
{
  static char buffer[256];
  static char *weekdays[] = { "Sun", "Mon", "Tue", "Wed",
                              "Thu", "Fri", "Sat" };
  switch (day_code) {
  case DAY_SIMPLE:
    sprintf (buffer, "%i", day_number);
    break;
  case DAY_WEEKDAY_ON_OR_AFTER:
    sprintf (buffer, "%s>=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_WEEKDAY_ON_OR_BEFORE:
    sprintf (buffer, "%s<=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_LAST_WEEKDAY:
    sprintf (buffer, "last%s", weekdays[day_weekday]);
    break;
  default:
    fprintf (stderr, "Invalid day code: %i\n", day_code);
    exit (1);
  }
  return buffer;
}

canonical_original_code:
char *dump_day_coded(enum DayCode day_code, int day_number, int day_weekday)
{
  static char buffer[256];
  static char *weekdays[] = { "Sun", "Mon", "Tue", "Wed",
                              "Thu", "Fri", "Sat" };
  switch (day_code) {
  case DAY_SIMPLE:
    sprintf (buffer, "%i", day_number);
    break;
  case DAY_WEEKDAY_ON_OR_AFTER:
    sprintf (buffer, "%s>=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_WEEKDAY_ON_OR_BEFORE:
    sprintf (buffer, "%s<=%i", weekdays[day_weekday], day_number);
    break;
  case DAY_LAST_WEEKDAY:
    sprintf (buffer, "last%s", weekdays[day_weekday]);
    break;
  default:
    fprintf (stderr, "Invalid day code: %i\n", day_code);
    exit (1);
  }
  return buffer;
}

variable_types: enum DayCode { DAY_SIMPLE=0, DAY_WEEKDAY_ON_OR_AFTER=1, DAY_WEEKDAY_ON_OR_BEFORE=2, DAY_LAST_WEEKDAY=3 }

variable_types:
weekdays
char *[]


decompiled_code:
const char *__fastcall dump_year(unsigned int a1)
{
const char *result; // rax

result = "min";
if ( a1 != 0x80000000 )
{
result = "max";
if ( a1 != 0x7FFFFFFF )
{
sprintf(buffer_0, "%i", a1);
result = buffer_0;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(unsigned int a1)
{
const char *result; // rax

result = "min";
if ( a1 != 0x80000000 )
{
result = "max";
if ( a1 != 0x7FFFFFFF )
{
sprintf(buffer_0, "%i", a1);
result = buffer_0;
}
}
return result;
}

original_code:
char*
dump_year (int year)
{
  static char buffer[256];
  if (year == (-0x7fffffff - 1))
    return "min";
  if (year == 0x7fffffff)
    return "max";
  sprintf (buffer, "%i", year);
  return buffer;
}

canonical_original_code:
char *dump_year(int year)
{
  static char buffer[256];
  if (year == (-0x7fffffff - 1))
    return "min";
  if (year == 0x7fffffff)
    return "max";
  sprintf (buffer, "%i", year);
  return buffer;
}

variable_types: year int


repo: Distrotech/dmake

decompiled_code:
void malloc_init()
{
void *v0; // rax
char *v1; // rdi
int v2; // eax
char *v3; // rdi
int v4; // eax
char *v5; // rdi
int v6; // eax
char *v7; // rax

if ( !malloc_data_start )
{
v0 = sbrk(0LL);
malloc_start[6] = 0;
malloc_data_start = v0;
malloc_data_end = v0;
malloc_end = malloc_start;
v1 = getenv("MALLOC_WARN");
if ( v1 )
{
v2 = atoi(v1);
mallopt(1, v2);
}
v3 = getenv("MALLOC_FATAL");
if ( v3 )
{
v4 = atoi(v3);
mallopt(2, v4);
}
v5 = getenv("MALLOC_CKCHAIN");
if ( v5 )
{
v6 = atoi(v5);
mallopt(4, v6);
}
v7 = getenv("MALLOC_ERRFILE");
if ( v7 )
mallopt(3, (int)v7);
}
}

canonical_decompiled_code:
void func0()
{
void *v0; // rax
char *v1; // rdi
int v2; // eax
char *v3; // rdi
int v4; // eax
char *v5; // rdi
int v6; // eax
char *v7; // rax

if ( !malloc_data_start )
{
v0 = sbrk(0LL);
malloc_start[6] = 0;
malloc_data_start = v0;
malloc_data_end = v0;
malloc_end = malloc_start;
v1 = getenv("MALLOC_WARN");
if ( v1 )
{
v2 = atoi(v1);
mallopt(1, v2);
}
v3 = getenv("MALLOC_FATAL");
if ( v3 )
{
v4 = atoi(v3);
mallopt(2, v4);
}
v5 = getenv("MALLOC_CKCHAIN");
if ( v5 )
{
v6 = atoi(v5);
mallopt(4, v6);
}
v7 = getenv("MALLOC_ERRFILE");
if ( v7 )
mallopt(3, (int)v7);
}
}

original_code:
void
malloc_init()
{
 char * cptr;
 char * getenv();
 union malloptarg m;
 extern char * malloc_data_end;
 extern char * malloc_data_start;
 extern struct mlist * malloc_end;
 extern struct mlist malloc_start;
 char * sbrk();
 if( malloc_data_start != (char *) 0)
 {
  return;
 }
 malloc_data_start = sbrk(0);
 malloc_data_end = malloc_data_start;
 malloc_start.s.size = 0;
 malloc_end = &malloc_start;
 if( (cptr=getenv("MALLOC_WARN")) != ((void *)0) )
 {
  m.i = atoi(cptr);
  (void) mallopt(1,m);
 }
 if( (cptr=getenv("MALLOC_FATAL")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(2,m);
 }
 if( (cptr=getenv("MALLOC_CKCHAIN")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(4,m);
 }
 if( (cptr=getenv("MALLOC_ERRFILE")) != ((void *)0))
 {
  m.str = cptr;
  (void) mallopt(3,m);
 }
}

canonical_original_code:
void malloc_init()
{
 char *cptr;
 char *getenv();
 union malloptarg m;
 extern char *malloc_data_end;
 extern char *malloc_data_start;
 extern struct mlist *malloc_end;
 extern struct mlist malloc_start;
 char *sbrk();
 if( malloc_data_start != (char *) 0)
 {
  return;
 }
 malloc_data_start = sbrk(0);
 malloc_data_end = malloc_data_start;
 malloc_start.s.size = 0;
 malloc_end = &malloc_start;
 if( (cptr=getenv("MALLOC_WARN")) != ((void *)0) )
 {
  m.i = atoi(cptr);
  (void) mallopt(1,m);
 }
 if( (cptr=getenv("MALLOC_FATAL")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(2,m);
 }
 if( (cptr=getenv("MALLOC_CKCHAIN")) != ((void *)0))
 {
  m.i = atoi(cptr);
  (void) mallopt(4,m);
 }
 if( (cptr=getenv("MALLOC_ERRFILE")) != ((void *)0))
 {
  m.str = cptr;
  (void) mallopt(3,m);
 }
}

variable_types:
cptr
char *

variable_types:
getenv
char *()

variable_types:
m
union malloptarg { int i; char *str; }

variable_types: struct mlist { struct mlist *next; struct mlist *prev; int flag; unsigned int r_size; union { unsigned int size; double unused_just_for_alignment; } s; char data[4]; } *

variable_types:
sbrk
char *()


setlink

repo: Distrotech/libdwarf

decompiled_code:
void __fastcall setlink(__int64 a1, int a2, __int64 a3)
{
if ( a2 < 0 )
*(_QWORD *)(a1 + 8) = a3;
else
*(_QWORD *)(a1 + 16) = a3;
}

original_code:
static void
setlink(struct ts_entry*t,int a,struct ts_entry *x)
{
    if(a < 0) {
        t->llink = x;
    } else {
        t->rlink = x;
    }
}

canonical_original_code:
static void setlink(struct ts_entry *t, int a, struct ts_entry *x)
{
    if(a < 0) {
        t->llink = x;
    } else {
        t->rlink = x;
    }
}

variable_types: struct ts_entry { void *keyptr; int balance; struct ts_entry *llink; struct ts_entry *rlink; } *

variable_types: a int

variable_types:
x
struct ts_entry *


getlink

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

result = *(_QWORD *)(a1 + 16);
if ( a2 < 0 )
result = *(_QWORD *)(a1 + 8);
return result;
}

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

result = *(_QWORD *)(a1 + 16);
if ( a2 < 0 )
result = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
static struct ts_entry*
getlink(struct ts_entry*t,int a)
{
    if(a < 0) {
        return(t->llink);
    }
    return(t->rlink);
}

canonical_original_code:
static struct ts_entry *getlink(struct ts_entry *t, int a)
{
    if(a < 0) {
        return(t->llink);
    }
    return(t->rlink);
}

variable_types:
t
struct ts_entry *

return_type: struct ts_entry { void *keyptr; unsigned char color; struct ts_entry *llink; struct ts_entry *rlink; } *


printlevel

decompiled_code:
int __fastcall printlevel(unsigned int a1)
{
int v1; // ebx
int result; // eax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

v1 = snprintf(s, 0xAuLL, "<%d>", a1);
for ( result = printf("%s", s); (int)(a1 + 4) > v1; result = putchar(32) )
++v1;
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1)
{
int v1; // ebx
int result; // eax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

v1 = snprintf(s, 0xAuLL, "<%d>", a1);
for ( result = printf("%s", s); (int)(a1 + 4) > v1; result = putchar(32) )
++v1;
return result;
}

original_code:
static void printlevel(int level)
{
    int len = 0;
    int targetlen = 4 + level;
    int shownlen = 0;
    char number[10];
    len = snprintf(number,sizeof(number),"<%d>",level);
    printf("%s",number);
    shownlen = len;
    while(shownlen < targetlen) {
        putchar(' ');
        ++shownlen;
    }
}

variable_types: level int

variable_types: len int

variable_types: targetlen int

variable_types: shownlen int

variable_types:
number
char [10]


repo: Distrotech/mgetty

decompiled_code:
void fwf_sig_alarm()
{
signal(14, fwf_sig_alarm);
lprintf(3LL, "Warning: got alarm signal!");
}

canonical_decompiled_code:
void func0()
{
signal(14, fwf_sig_alarm);
lprintf(3LL, "Warning: got alarm signal!");
}

original_code:
static RETSIGTYPE fwf_sig_alarm()
{
    signal( 14, fwf_sig_alarm );
    lprintf( 3, "Warning: got alarm signal!" );
    fwf_timeout = (1==1);
}

canonical_original_code:
static void fwf_sig_alarm()
{
    signal( 14, fwf_sig_alarm );
    lprintf( 3, "Warning: got alarm signal!" );
    fwf_timeout = (1==1);
}


decompiled_code:
__int64 __fastcall mdm_send(void *buf, int fd)
{
size_t v2; // rax
ssize_t v3; // rbx

delay(50LL);
lprintf(4LL, "mdm_send: '%s'", (const char *)buf);
v2 = strlen((const char *)buf);
v3 = write(fd, buf, v2);
if ( v3 == strlen((const char *)buf) && write(fd, "\r", 1uLL) == 1 )
return 0LL;
lprintf(1LL, "mdm_send: cannot write");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf, int fd)
{
size_t v2; // rax
ssize_t v3; // rbx

delay(50LL);
lprintf(4LL, "mdm_send: '%s'", (const char *)buf);
v2 = strlen((const char *)buf);
v3 = write(fd, buf, v2);
if ( v3 == strlen((const char *)buf) && write(fd, "\r", 1uLL) == 1 )
return 0LL;
lprintf(1LL, "mdm_send: cannot write");
return 0xFFFFFFFFLL;
}

original_code:
int mdm_send (char * send,int fd)
{
    delay(50);
    lprintf( 4, "mdm_send: '%s'", send );
    if ( write( fd, send, strlen( send ) ) != strlen( send ) ||
  write( fd, "\r", sizeof("\r")-1 ) !=
         ( sizeof("\r")-1 ) )
    {
 lprintf( 1, "mdm_send: cannot write" );
 return -1;
    }
    return 0;
}

canonical_original_code:
int mdm_send(char *send, int fd)
{
    delay(50);
    lprintf( 4, "mdm_send: '%s'", send );
    if ( write( fd, send, strlen( send ) ) != strlen( send ) ||
  write( fd, "\r", sizeof("\r")-1 ) !=
         ( sizeof("\r")-1 ) )
    {
 lprintf( 1, "mdm_send: cannot write" );
 return -1;
    }
    return 0;
}

variable_types:
send
char *

variable_types: fd int


decompiled_code:
char *__fastcall mdm_get_line(int a1)
{
int v1; // ebx
const unsigned __int16 *v2; // rdx
char v3; // al
__int64 v4; // rdx
char *result; // rax
char v6[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = 0;
lprintf(6LL, "got:");
while ( (unsigned int)mdm_read_byte(a1, v6) == 1 )
{
lputc(6LL, (unsigned int)v6[0]);
v2 = *_ctype_b_loc();
v3 = v6[0];
if ( (v2[v6[0]] & 0x4000) != 0 )
{
if ( v1 <= 199 )
{
v4 = v1++;
buffer_4[v4] = v6[0];
}
goto LABEL_6;
}
if ( v1 )
{
LABEL_6:
if ( v3 == 10 || v3 == 13 )
{
result = buffer_4;
buffer_4[v1] = 0;
return result;
}
}
}
lprintf(1LL, "mdm_get_line: cannot read byte, return");
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
int v1; // ebx
const unsigned __int16 *v2; // rdx
char v3; // al
__int64 v4; // rdx
char *result; // rax
char v6[25]; // [rsp+Fh] [rbp-19h] BYREF

v1 = 0;
lprintf(6LL, "got:");
while ( (unsigned int)func2(a1, v6) == 1 )
{
lputc(6LL, (unsigned int)v6[0]);
v2 = *_ctype_b_loc();
v3 = v6[0];
if ( (v2[v6[0]] & 0x4000) != 0 )
{
if ( v1 <= 199 )
{
v4 = v1++;
buffer_4[v4] = v6[0];
}
goto LABEL_6;
}
if ( v1 )
{
LABEL_6:
if ( v3 == 10 || v3 == 13 )
{
result = buffer_4;
buffer_4[v1] = 0;
return result;
}
}
}
lprintf(1LL, "mdm_get_line: cannot read byte, return");
return 0LL;
}

original_code:
char * mdm_get_line (int fd)
{
    static char buffer[200];
    int bufferp;
    char c;
    bufferp = 0;
    lprintf( 6, "got:" );
    do
    {
 if( mdm_read_byte( fd, &c ) != 1 )
 {
     lprintf( 1, "mdm_get_line: cannot read byte, return" );
     return ((void *)0);
 }
 lputc( 6, c );
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint) &&
      bufferp < sizeof(buffer) )
 {
     buffer[ bufferp++ ] = c;
 }
    }
    while ( bufferp == 0 || ( c != 0x0a && c != 0x0d ) );
    buffer[bufferp] = 0;
    return buffer;
}

canonical_original_code:
char *mdm_get_line(int fd)
{
    static char buffer[200];
    int bufferp;
    char c;
    bufferp = 0;
    lprintf( 6, "got:" );
    do
    {
 if( mdm_read_byte( fd, &c ) != 1 )
 {
     lprintf( 1, "mdm_get_line: cannot read byte, return" );
     return ((void *)0);
 }
 lputc( 6, c );
 if ( ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint) &&
      bufferp < sizeof(buffer) )
 {
     buffer[ bufferp++ ] = c;
 }
    }
    while ( bufferp == 0 || ( c != 0x0a && c != 0x0d ) );
    buffer[bufferp] = 0;
    return buffer;
}

variable_types:
buffer
char [200]

variable_types: bufferp int

variable_types: c char


decompiled_code:
__int64 __fastcall mdm_command(void *a1, int a2)
{
__int64 result; // rax
char *v3; // rax
char *v4; // rbp

result = mdm_send(a1, a2);
if ( (_DWORD)result != -1 )
{
signal(14, (__sighandler_t)fwf_sig_alarm);
alarm(0xAu);
do
{
v3 = mdm_get_line(a2);
v4 = v3;
if ( !v3 )
{
alarm(0);
signal(14, 0LL);
goto LABEL_12;
}
lprintf(5LL, "mdm_command: string '%s'", v3);
}
while ( (*v4 != 79 || v4[1] != 75 || v4[2]) && strcmp(v4, "ERROR") );
alarm(0);
signal(14, 0LL);
if ( strcmp(v4, "ERROR") )
{
lputs(4LL, " -> OK");
return 0LL;
}
LABEL_12:
lputs(4LL, " -> ERROR");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1, int a2)
{
__int64 result; // rax
char *v3; // rax
char *v4; // rbp

result = func1(a1, a2);
if ( (_DWORD)result != -1 )
{
signal(14, (__sighandler_t)fwf_sig_alarm);
alarm(0xAu);
do
{
v3 = func3(a2);
v4 = v3;
if ( !v3 )
{
alarm(0);
signal(14, 0LL);
goto LABEL_12;
}
lprintf(5LL, "mdm_command: string '%s'", v3);
}
while ( (*v4 != 79 || v4[1] != 75 || v4[2]) && strcmp(v4, "ERROR") );
alarm(0);
signal(14, 0LL);
if ( strcmp(v4, "ERROR") )
{
lputs(4LL, " -> OK");
return 0LL;
}
LABEL_12:
lputs(4LL, " -> ERROR");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int mdm_command (char * send,int fd)
{
    char * l;
    if ( mdm_send( send, fd ) == -1 ) return -1;
    signal( 14, fwf_sig_alarm ); alarm(10); fwf_timeout = (1==0);
    do
    {
 l = mdm_get_line( fd );
 if ( l == ((void *)0) ) break;
 lprintf( 5, "mdm_command: string '%s'", l );
    }
    while ( strcmp( l, "OK" ) != 0 && strcmp( l, "ERROR" ) != 0 );
    alarm(0); signal( 14, ((__sighandler_t) 0) );
    if ( l == ((void *)0) || strcmp( l, "ERROR" ) == 0 )
    {
 lputs( 4, " -> ERROR" );
 return -1;
    }
    lputs( 4, " -> OK" );
    return 0;
}

canonical_original_code:
int mdm_command(char *send, int fd)
{
    char *l;
    if ( mdm_send( send, fd ) == -1 ) return -1;
    signal( 14, fwf_sig_alarm ); alarm(10); fwf_timeout = (1==0);
    do
    {
 l = mdm_get_line( fd );
 if ( l == ((void *)0) ) break;
 lprintf( 5, "mdm_command: string '%s'", l );
    }
    while ( strcmp( l, "OK" ) != 0 && strcmp( l, "ERROR" ) != 0 );
    alarm(0); signal( 14, ((void (*)(int)) 0) );
    if ( l == ((void *)0) || strcmp( l, "ERROR" ) == 0 )
    {
 lputs( 4, " -> ERROR" );
 return -1;
    }
    lputs( 4, " -> OK" );
    return 0;
}

variable_types:
l
char *