decompiled_code:
__int64 __fastcall DDB_blockDataByte(__int64 a1)
{
return a1 + 6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return a1 + 6;
}

original_code:
unsigned char *
DDB_blockDataByte(struct DownloadDataBlock *ddb)
{
 return ((unsigned char *) ddb) + sizeof(struct DownloadDataBlock);
}

canonical_original_code:
unsigned char *DDB_blockDataByte(struct DownloadDataBlock *ddb)
{
 return ((unsigned char *) ddb) + sizeof(struct DownloadDataBlock);
}


repo: thiakil/rb-download

decompiled_code:
__int64 __fastcall DSI_privateDataByte(__int64 a1)
{
if ( *(_WORD *)(a1 + 20) )
fatal("Unexpected DSI format");
return a1 + 24;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( *(_WORD *)(a1 + 20) )
fatal("Unexpected DSI format");
return a1 + 24;
}

original_code:
unsigned char *
DSI_privateDataByte(struct DownloadServerInitiate *dsi)
{
 if(dsi->compatibilityDescriptor.compatibilityDescriptorLength != 0)
  fatal("Unexpected DSI format");
 return ((unsigned char *) dsi) + sizeof(struct DownloadServerInitiate);
}

canonical_original_code:
unsigned char *DSI_privateDataByte(struct DownloadServerInitiate *dsi)
{
 if(dsi->compatibilityDescriptor.compatibilityDescriptorLength != 0)
  fatal("Unexpected DSI format");
 return ((unsigned char *) dsi) + sizeof(struct DownloadServerInitiate);
}

variable_types: struct DownloadServerInitiate { unsigned char serverId[20]; struct CompatibilityDescriptor { unsigned short compatibilityDescriptorLength; } compatibilityDescriptor; unsigned short privateDataLength; } *

return_type: unsigned char *

user_defined_types: struct DownloadServerInitiate { unsigned char serverId[20]; struct CompatibilityDescriptor compatibilityDescriptor; unsigned short privateDataLength; }


decompiled_code:
char *__fastcall make_carousel_root(unsigned __int16 a1, unsigned int a2)
{
int v4; // edi
char *v5; // rax
int v6; // edi
char *v7; // rax
int v8; // edi
char *v9; // rax

strcpy(carousel_root, "carousels");
if ( mkdir(carousel_root, 0x1EDu) < 0 )
{
v4 = *_errno_location();
if ( v4 != 17 )
{
v5 = strerror(v4);
fatal("Unable to create carousel directory '%s': %s", carousel_root, v5);
}
}
snprintf(carousel_root, 0x1000uLL, "%s/%u", "carousels", a1);
if ( mkdir(carousel_root, 0x1EDu) < 0 )
{
v8 = *_errno_location();
if ( v8 != 17 )
{
v9 = strerror(v8);
fatal("Unable to create carousel directory '%s': %s", carousel_root, v9);
}
}
snprintf(carousel_root, 0x1000uLL, "%s/%u/%u", "carousels", a1, a2);
if ( mkdir(carousel_root, 0x1EDu) >= 0 )
return carousel_root;
v6 = *_errno_location();
if ( v6 == 17 )
return carousel_root;
v7 = strerror(v6);
fatal("Unable to create carousel directory '%s': %s", carousel_root, v7);
return carousel_root;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int16 a1, unsigned int a2)
{
int v4; // edi
char *v5; // rax
int v6; // edi
char *v7; // rax
int v8; // edi
char *v9; // rax

strcpy(carousel_root, "carousels");
if ( mkdir(carousel_root, 0x1EDu) < 0 )
{
v4 = *_errno_location();
if ( v4 != 17 )
{
v5 = strerror(v4);
fatal("Unable to create carousel directory '%s': %s", carousel_root, v5);
}
}
snprintf(carousel_root, 0x1000uLL, "%s/%u", "carousels", a1);
if ( mkdir(carousel_root, 0x1EDu) < 0 )
{
v8 = *_errno_location();
if ( v8 != 17 )
{
v9 = strerror(v8);
fatal("Unable to create carousel directory '%s': %s", carousel_root, v9);
}
}
snprintf(carousel_root, 0x1000uLL, "%s/%u/%u", "carousels", a1, a2);
if ( mkdir(carousel_root, 0x1EDu) >= 0 )
return carousel_root;
v6 = *_errno_location();
if ( v6 == 17 )
return carousel_root;
v7 = strerror(v6);
fatal("Unable to create carousel directory '%s': %s", carousel_root, v7);
return carousel_root;
}

original_code:
char *
make_carousel_root(uint16_t elementary_pid, uint32_t carousel_id)
{
 snprintf(_carousel_root, sizeof(_carousel_root), "%s", "carousels");
 if(mkdir(_carousel_root, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror((*__errno_location ())));
 snprintf(_carousel_root, sizeof(_carousel_root), "%s/%u", "carousels", elementary_pid);
 if(mkdir(_carousel_root, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror((*__errno_location ())));
 snprintf(_carousel_root, sizeof(_carousel_root), "%s/%u/%u", "carousels", elementary_pid, carousel_id);
 if(mkdir(_carousel_root, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror((*__errno_location ())));
 return _carousel_root;
}

canonical_original_code:
char *make_carousel_root(unsigned short elementary_pid, unsigned int carousel_id)
{
 snprintf(_carousel_root, sizeof(_carousel_root), "%s", "carousels");
 if(mkdir(_carousel_root, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror((*__errno_location ())));
 snprintf(_carousel_root, sizeof(_carousel_root), "%s/%u", "carousels", elementary_pid);
 if(mkdir(_carousel_root, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror((*__errno_location ())));
 snprintf(_carousel_root, sizeof(_carousel_root), "%s/%u/%u", "carousels", elementary_pid, carousel_id);
 if(mkdir(_carousel_root, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create carousel directory '%s': %s", _carousel_root, strerror((*__errno_location ())));
 return _carousel_root;
}

return_type: char *


decompiled_code:
char *__fastcall convert_key(__int64 a1, int a2)
{
__int64 i; // rbx
char *result; // rax

if ( (unsigned int)(2 * a2 + 1) > 0x1000 )
fatal("objectKey too long");
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
ascii_key[2 * i] = hex_digit(*(_BYTE *)(a1 + i) >> 4);
byte_641[2 * i] = hex_digit(*(_BYTE *)(a1 + i) & 0xF);
}
}
result = ascii_key;
ascii_key[2 * a2] = 0;
return result;
}

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

if ( (unsigned int)(2 * a2 + 1) > 0x1000 )
fatal("objectKey too long");
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
{
ascii_key[2 * i] = hex_digit(*(_BYTE *)(a1 + i) >> 4);
byte_641[2 * i] = hex_digit(*(_BYTE *)(a1 + i) & 0xF);
}
}
result = ascii_key;
ascii_key[2 * a2] = 0;
return result;
}

original_code:
char *
convert_key(char *key, uint32_t size)
{
 uint32_t i;
 if(sizeof(_ascii_key) < (size * 2) + 1)
  fatal("objectKey too long");
 for(i=0; i<size; i++)
 {
  _ascii_key[i * 2] = hex_digit((key[i] >> 4) & 0x0f);
  _ascii_key[(i * 2) + 1] = hex_digit(key[i] & 0x0f);
 }
 _ascii_key[size * 2] = '\0';
 return _ascii_key;
}

canonical_original_code:
char *convert_key(char *key, unsigned int size)
{
 unsigned int i;
 if(sizeof(_ascii_key) < (size * 2) + 1)
  fatal("objectKey too long");
 for(i=0; i<size; i++)
 {
  _ascii_key[i * 2] = hex_digit((key[i] >> 4) & 0x0f);
  _ascii_key[(i * 2) + 1] = hex_digit(key[i] & 0x0f);
 }
 _ascii_key[size * 2] = '\0';
 return _ascii_key;
}

variable_types:
key
char *

variable_types:
size
unsigned int

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall make_service_root(unsigned __int16 a1, const char *a2, unsigned __int16 a3, unsigned int a4, unsigned __int16 a5, __int64 a6, int a7)
{
char *v12; // rax
int v14; // edi
char *v15; // rax
int v16; // edi
char *v17; // rax
char v18[4096]; // [rsp+0h] [rbp-3038h] BYREF
char s[4096]; // [rsp+1000h] [rbp-2038h] BYREF
char name[4152]; // [rsp+2000h] [rbp-1038h] BYREF

strcpy(v18, "services");
if ( mkdir(v18, 0x1EDu) < 0 )
{
v14 = *_errno_location();
if ( v14 != 17 )
{
v15 = strerror(v14);
fatal("Unable to create services directory '%s': %s", v18, v15);
}
}
v12 = convert_key(a6, a7);
snprintf(s, 0x1000uLL, "../%s/%u/%u/%s-%u-%s", "carousels", a3, a4, a2, a5, v12);
snprintf(name, 0x1000uLL, "%s/%u", v18, a1);
unlink(name);
if ( symlink(s, name) < 0 )
{
v16 = *_errno_location();
if ( v16 != 17 )
{
v17 = strerror(v16);
fatal("Unable to create link '%s' to '%s': %s", name, s, v17);
}
}
return verbose("Added service root '%s' -> '%s'", name, s);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, const char *a2, unsigned __int16 a3, unsigned int a4, unsigned __int16 a5, __int64 a6, int a7)
{
char *v12; // rax
int v14; // edi
char *v15; // rax
int v16; // edi
char *v17; // rax
char v18[4096]; // [rsp+0h] [rbp-3038h] BYREF
char s[4096]; // [rsp+1000h] [rbp-2038h] BYREF
char name[4152]; // [rsp+2000h] [rbp-1038h] BYREF

strcpy(v18, "services");
if ( mkdir(v18, 0x1EDu) < 0 )
{
v14 = *_errno_location();
if ( v14 != 17 )
{
v15 = strerror(v14);
fatal("Unable to create services directory '%s': %s", v18, v15);
}
}
v12 = func1(a6, a7);
snprintf(s, 0x1000uLL, "../%s/%u/%u/%s-%u-%s", "carousels", a3, a4, a2, a5, v12);
snprintf(name, 0x1000uLL, "%s/%u", v18, a1);
unlink(name);
if ( symlink(s, name) < 0 )
{
v16 = *_errno_location();
if ( v16 != 17 )
{
v17 = strerror(v16);
fatal("Unable to create link '%s' to '%s': %s", name, s, v17);
}
}
return verbose("Added service root '%s' -> '%s'", name, s);
}

original_code:
void
make_service_root(uint16_t service_id, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size)
{
 char dirname[4096];
 char *ascii_key;
 char realfile[4096];
 char linkfile[4096];
 snprintf(dirname, sizeof(dirname), "%s", "services");
 if(mkdir(dirname, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create services directory '%s': %s", dirname, strerror((*__errno_location ())));
 ascii_key = convert_key(key, key_size);
 snprintf(realfile, sizeof(realfile), "../%s/%u/%u/%s-%u-%s", "carousels", elementary_pid, carousel_id, kind, module_id, ascii_key);
 snprintf(linkfile, sizeof(linkfile), "%s/%u", dirname, service_id);
 unlink(linkfile);
 if(symlink(realfile, linkfile) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror((*__errno_location ())));
 verbose("Added service root '%s' -> '%s'", linkfile, realfile);
 return;
}

canonical_original_code:
void make_service_root(unsigned short service_id, char *kind, unsigned short elementary_pid, unsigned int carousel_id, unsigned short module_id, char *key, unsigned int key_size)
{
 char dirname[4096];
 char *ascii_key;
 char realfile[4096];
 char linkfile[4096];
 snprintf(dirname, sizeof(dirname), "%s", "services");
 if(mkdir(dirname, 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create services directory '%s': %s", dirname, strerror((*__errno_location ())));
 ascii_key = convert_key(key, key_size);
 snprintf(realfile, sizeof(realfile), "../%s/%u/%u/%s-%u-%s", "carousels", elementary_pid, carousel_id, kind, module_id, ascii_key);
 snprintf(linkfile, sizeof(linkfile), "%s/%u", dirname, service_id);
 unlink(linkfile);
 if(symlink(realfile, linkfile) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror((*__errno_location ())));
 verbose("Added service root '%s' -> '%s'", linkfile, realfile);
 return;
}

variable_types:
kind
char *

variable_types:
dirname
char [4096]

variable_types:
realfile
char [4096]

variable_types:
linkfile
char [4096]

return_type: void


decompiled_code:
__int64 __fastcall add_dir_entry(const char *a1, const char *a2, int a3, const char *a4, unsigned __int16 a5, unsigned int a6, unsigned __int16 a7, __int64 a8, int a9)
{
char *v12; // rax
int *v14; // rax
char *v15; // rax
char s[4096]; // [rsp+10h] [rbp-2038h] BYREF
char name[4152]; // [rsp+1010h] [rbp-1038h] BYREF

v12 = convert_key(a8, a9);
snprintf(s, 0x1000uLL, "../../../../%s/%u/%u/%s-%u-%s", "carousels", a5, a6, a4, a7, v12);
snprintf(name, 0x1000uLL, "%s/%.*s", a1, a3, a2);
unlink(name);
if ( symlink(s, name) < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fatal("Unable to create link '%s' to '%s': %s", name, s, v15);
}
return verbose("Added directory entry '%s' -> '%s'", name, s);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char *a2, int a3, const char *a4, unsigned __int16 a5, unsigned int a6, unsigned __int16 a7, __int64 a8, int a9)
{
char *v12; // rax
int *v14; // rax
char *v15; // rax
char s[4096]; // [rsp+10h] [rbp-2038h] BYREF
char name[4152]; // [rsp+1010h] [rbp-1038h] BYREF

v12 = func1(a8, a9);
snprintf(s, 0x1000uLL, "../../../../%s/%u/%u/%s-%u-%s", "carousels", a5, a6, a4, a7, v12);
snprintf(name, 0x1000uLL, "%s/%.*s", a1, a3, a2);
unlink(name);
if ( symlink(s, name) < 0 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fatal("Unable to create link '%s' to '%s': %s", name, s, v15);
}
return verbose("Added directory entry '%s' -> '%s'", name, s);
}

original_code:
void
add_dir_entry(char *dir, char *entry, uint32_t entry_size, char *kind, uint16_t elementary_pid, uint32_t carousel_id, uint16_t module_id, char *key, uint32_t key_size)
{
 char *ascii_key;
 char realfile[4096];
 char linkfile[4096];
 ascii_key = convert_key(key, key_size);
 snprintf(realfile, sizeof(realfile), "../../../../%s/%u/%u/%s-%u-%s", "carousels", elementary_pid, carousel_id, kind, module_id, ascii_key);
 snprintf(linkfile, sizeof(linkfile), "%s/%.*s", dir, entry_size, entry);
 unlink(linkfile);
 if(symlink(realfile, linkfile) < 0)
  fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror((*__errno_location ())));
 verbose("Added directory entry '%s' -> '%s'", linkfile, realfile);
 return;
}

canonical_original_code:
void add_dir_entry(char *dir, char *entry, unsigned int entry_size, char *kind, unsigned short elementary_pid, unsigned int carousel_id, unsigned short module_id, char *key, unsigned int key_size)
{
 char *ascii_key;
 char realfile[4096];
 char linkfile[4096];
 ascii_key = convert_key(key, key_size);
 snprintf(realfile, sizeof(realfile), "../../../../%s/%u/%u/%s-%u-%s", "carousels", elementary_pid, carousel_id, kind, module_id, ascii_key);
 snprintf(linkfile, sizeof(linkfile), "%s/%.*s", dir, entry_size, entry);
 unlink(linkfile);
 if(symlink(realfile, linkfile) < 0)
  fatal("Unable to create link '%s' to '%s': %s", linkfile, realfile, strerror((*__errno_location ())));
 verbose("Added directory entry '%s' -> '%s'", linkfile, realfile);
 return;
}

variable_types:
dir
char *

variable_types:
entry
char *


decompiled_code:
__int64 __fastcall get_host_addr(const char *a1, _DWORD *a2)
{
struct hostent *v2; // rax

v2 = gethostbyname(a1);
if ( !v2 || v2->h_addrtype != 2 )
return 0xFFFFFFFFLL;
*a2 = **(_DWORD **)v2->h_addr_list;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, _DWORD *a2)
{
struct hostent *v2; // rax

v2 = gethostbyname(a1);
if ( !v2 || v2->h_addrtype != 2 )
return 0xFFFFFFFFLL;
*a2 = **(_DWORD **)v2->h_addr_list;
return 0LL;
}

original_code:
static int
get_host_addr(char *host, struct in_addr *output)
{
 struct hostent *he;
 int error = 0;
 if(((he = gethostbyname(host)) != ((void *)0)) && (he->h_addrtype == 2))
  memcpy(output, he->h_addr_list[0], sizeof(struct in_addr));
 else
  error = -1;
 return error;
}

variable_types:
host
char *

variable_types: struct in_addr { unsigned int s_addr; } *

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

variable_types: error int

return_type: int


decompiled_code:
__pid_t __fastcall dead_child(int a1)
{
__pid_t result; // eax

if ( a1 == 17 )
result = wait(0LL);
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func2(int a1)
{
__pid_t result; // eax

if ( a1 == 17 )
result = wait(0LL);
return result;
}

original_code:
static void
dead_child(int signo)
{
 if(signo == 17)
  wait(((void *)0));
 return;
}

variable_types: signo int


decompiled_code:
__int64 __fastcall parse_addr(char *nptr, _DWORD *a2, __int16 *a3)
{
char *v4; // rax
char *v5; // rbx
const char *v6; // r14
__int16 v7; // ax
__int64 result; // rax
__int64 v9; // rbx
const unsigned __int16 **v10; // rax
char *v11; // rdx
const unsigned __int16 *v12; // rcx
unsigned __int16 v13; // ax
__int16 v14; // ax
__int16 v15; // ax

if ( !nptr )
return 0LL;
v4 = strchr(nptr, 58);
v5 = v4;
if ( v4 )
{
*v4 = 0;
v6 = v4 + 1;
if ( (int)get_host_addr(nptr, a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = atoi(v6);
*a3 = _bswap_16(v7);
result = 0LL;
*v5 = 58;
}
}
else
{
v9 = *nptr;
if ( (_BYTE)v9 )
{
v10 = _ctype_b_loc();
v11 = nptr;
v12 = *v10;
while ( 1 )
{
++v11;
v13 = v12[v9];
v9 = *v11;
v14 = v13 & 0x800;
if ( !(_BYTE)v9 )
break;
if ( !v14 )
goto LABEL_13;
}
if ( v14 )
goto LABEL_11;
LABEL_13:
result = (unsigned int)((int)get_host_addr(nptr, a2) >> 31);
}
else
{
LABEL_11:
v15 = atoi(nptr);
*a3 = _bswap_16(v15);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr, _DWORD *a2, __int16 *a3)
{
char *v4; // rax
char *v5; // rbx
const char *v6; // r14
__int16 v7; // ax
__int64 result; // rax
__int64 v9; // rbx
const unsigned __int16 **v10; // rax
char *v11; // rdx
const unsigned __int16 *v12; // rcx
unsigned __int16 v13; // ax
__int16 v14; // ax
__int16 v15; // ax

if ( !nptr )
return 0LL;
v4 = strchr(nptr, 58);
v5 = v4;
if ( v4 )
{
*v4 = 0;
v6 = v4 + 1;
if ( (int)func0(nptr, a2) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v7 = atoi(v6);
*a3 = func1(v7);
result = 0LL;
*v5 = 58;
}
}
else
{
v9 = *nptr;
if ( (_BYTE)v9 )
{
v10 = _ctype_b_loc();
v11 = nptr;
v12 = *v10;
while ( 1 )
{
++v11;
v13 = v12[v9];
v9 = *v11;
v14 = v13 & 0x800;
if ( !(_BYTE)v9 )
break;
if ( !v14 )
goto LABEL_13;
}
if ( v14 )
goto LABEL_11;
LABEL_13:
result = (unsigned int)((int)func0(nptr, a2) >> 31);
}
else
{
LABEL_11:
v15 = atoi(nptr);
*a3 = func1(v15);
result = 0LL;
}
}
return result;
}

original_code:
int
parse_addr(char *str, struct in_addr *ip, in_port_t *port)
{
 char *p;
 int ishost;
 if(str == ((void *)0))
  return 0;
 if((p = strchr(str, ':')) != ((void *)0))
 {
  *(p++) = '\0';
  if(get_host_addr(str, ip) < 0)
   return -1;
  *port = htons(atoi(p));
  *(--p) = ':';
 }
 else
 {
  ishost = 0;
  for(p=str; *p && !ishost; p++)
   ishost = !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISdigit);
  if(ishost)
  {
   if(get_host_addr(str, ip) < 0)
    return -1;
  }
  else
  {
   *port = htons(atoi(str));
  }
 }
 return 0;
}

canonical_original_code:
int parse_addr(char *str, struct in_addr *ip, unsigned short *port)
{
 char *p;
 int ishost;
 if(str == ((void *)0))
  return 0;
 if((p = strchr(str, ':')) != ((void *)0))
 {
  *(p++) = '\0';
  if(get_host_addr(str, ip) < 0)
   return -1;
  *port = htons(atoi(p));
  *(--p) = ':';
 }
 else
 {
  ishost = 0;
  for(p=str; *p && !ishost; p++)
   ishost = !((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISdigit);
  if(ishost)
  {
   if(get_host_addr(str, ip) < 0)
    return -1;
  }
  else
  {
   *port = htons(atoi(str));
  }
 }
 return 0;
}

variable_types:
str
char *

variable_types:
port
unsigned short *

variable_types:
p
char *

variable_types: ishost int


decompiled_code:
void __fastcall __noreturn start_downloader(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned __int16 a6, unsigned int a7)
{
unsigned int v10; // ebx
const char *v11; // rdx
__int64 v12; // rbp
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v10 = a6;
v13[0] = 0;
if ( !(unsigned __int8)tune_service_id(a1, a2, a5, a6, v13) )
error((int)"Unable to retune; let's hope you're already tuned to the right frequency...", a2, v11);
v12 = find_mheg((unsigned int)a1, a3, a4, a5, v10, a7);
verbose("Carousel ID=%u", *(unsigned int *)(v12 + 8204));
verbose("Boot PID=%u", *(unsigned __int16 *)(v12 + 8208));
verbose("Video PID=%u", *(unsigned __int16 *)(v12 + 8214));
verbose("Audio PID=%u", *(unsigned __int16 *)(v12 + 8210));
load_carousel(v12);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned __int16 a6, unsigned int a7)
{
unsigned int v10; // ebx
const char *v11; // rdx
__int64 v12; // rbp
int v13[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v10 = a6;
v13[0] = 0;
if ( !(unsigned __int8)tune_service_id(a1, a2, a5, a6, v13) )
error((int)"Unable to retune; let's hope you're already tuned to the right frequency...", a2, v11);
v12 = find_mheg((unsigned int)a1, a3, a4, a5, v10, a7);
verbose("Carousel ID=%u", *(unsigned int *)(v12 + 8204));
verbose("Boot PID=%u", *(unsigned __int16 *)(v12 + 8208));
verbose("Video PID=%u", *(unsigned __int16 *)(v12 + 8214));
verbose("Audio PID=%u", *(unsigned __int16 *)(v12 + 8210));
load_carousel(v12);
exit(0);
}

original_code:
struct carousel *
start_downloader(unsigned int adapter, unsigned int frontend, unsigned int demux, unsigned int dvr, unsigned int timeout, uint16_t service_id, int carousel_id)
{
 struct carousel *car;
 pid_t child;
  int tuner_fd = 0;
  if(!tune_service_id(adapter, frontend, timeout, service_id, &tuner_fd))
    error("Unable to retune; let's hope you're already tuned to the right frequency...");
  car = find_mheg(adapter, demux, dvr, timeout, service_id, carousel_id);
  verbose("Carousel ID=%u", car->carousel_id);
  verbose("Boot PID=%u", car->boot_pid);
  verbose("Video PID=%u", car->video_pid);
  verbose("Audio PID=%u", car->audio_pid);
    load_carousel(car);
    exit(0);
 car->downloader = child;
 return car;
}

canonical_original_code:
struct carousel *start_downloader(unsigned int adapter, unsigned int frontend, unsigned int demux, unsigned int dvr, unsigned int timeout, unsigned short service_id, int carousel_id)
{
 struct carousel *car;
 int child;
  int tuner_fd = 0;
  if(!tune_service_id(adapter, frontend, timeout, service_id, &tuner_fd))
    error("Unable to retune; let's hope you're already tuned to the right frequency...");
  car = find_mheg(adapter, demux, dvr, timeout, service_id, carousel_id);
  verbose("Carousel ID=%u", car->carousel_id);
  verbose("Boot PID=%u", car->boot_pid);
  verbose("Video PID=%u", car->video_pid);
  verbose("Audio PID=%u", car->audio_pid);
    load_carousel(car);
    exit(0);
 car->downloader = child;
 return car;
}

variable_types:
adapter
unsigned int

variable_types:
frontend
unsigned int

variable_types:
demux
unsigned int

variable_types:
dvr
unsigned int

variable_types:
timeout
unsigned int

variable_types: struct carousel { char demux_device[4096]; char dvr_device[4096]; unsigned int timeout; int downloader; unsigned short network_id; unsigned short service_id; unsigned int carousel_id; unsigned short boot_pid; unsigned short audio_pid; unsigned char audio_type; unsigned short video_pid; unsigned char video_type; unsigned short current_pid; struct assoc { unsigned int nassocs; unsigned short *pids; unsigned short *sids; unsigned char *types; } assoc; int npids; struct pid_fds { unsigned short pid; int fd_ctrl; int fd_data; } *pids; _Bool got_dsi; unsigned int nmodules; struct module { unsigned short module_id; unsigned int download_id; unsigned char version; unsigned short block_size; unsigned short nblocks; unsigned int blocks_left; _Bool *got_block; unsigned int size; unsigned char *data; } *modules; } *

variable_types: child int

user_defined_types: struct carousel { char demux_device[4096]; char dvr_device[4096]; unsigned int timeout; int downloader; unsigned short network_id; unsigned short service_id; unsigned int carousel_id; unsigned short boot_pid; unsigned short audio_pid; unsigned char audio_type; unsigned short video_pid; unsigned char video_type; unsigned short current_pid; struct assoc assoc; int npids; struct pid_fds *pids; _Bool got_dsi; unsigned int nmodules; struct module *modules; }


decompiled_code:
void __fastcall __noreturn start_listener(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned __int16 a7, unsigned int a8)
{
int *v12; // rax
char *v13; // rax
struct sigaction v14; // [rsp+0h] [rbp-D8h] BYREF

v14.sa_handler = (__sighandler_t)dead_child;
sigemptyset(&v14.sa_mask);
v14.sa_flags = 0;
if ( sigaction(17, &v14, 0LL) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fatal("signal: SIGCHLD: %s", v13);
}
start_downloader(a2, a3, a4, a5, a6, a7, a8);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned __int16 a7, unsigned int a8)
{
int *v12; // rax
char *v13; // rax
struct sigaction v14; // [rsp+0h] [rbp-D8h] BYREF

v14.sa_handler = (__sighandler_t)dead_child;
sigemptyset(&v14.sa_mask);
v14.sa_flags = 0;
if ( sigaction(17, &v14, 0LL) < 0 )
{
v12 = _errno_location();
v13 = strerror(*v12);
fatal("signal: SIGCHLD: %s", v13);
}
func4(a2, a3, a4, a5, a6, a7, a8);
}

original_code:
void
start_listener(struct sockaddr_in *listen_addr, unsigned int adapter, unsigned int frontend, unsigned int demux, unsigned int dvr, unsigned int timeout, uint16_t service_id, int carousel_id)
{
 struct listen_data listen_data;
 struct sigaction action;
 int sockopt;
 int listen_sock;
 int accept_sock;
 fd_set read_fds;
 socklen_t addr_len;
 struct sockaddr_in client_addr;
 pid_t child;
 action.__sigaction_handler.sa_handler = dead_child;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if(sigaction(17, &action, ((void *)0)) < 0)
  fatal("signal: SIGCHLD: %s", strerror((*__errno_location ())));
 listen_data.carousel = start_downloader(adapter, frontend, demux, dvr, timeout, service_id, carousel_id);
 action.__sigaction_handler.sa_sigaction = hup_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 4;
 if(sigaction(1, &action, ((void *)0)) < 0)
  fatal("signal: SIGHUP: %s", strerror((*__errno_location ())));
 verbose("Listening on %s:%u", inet_ntoa(listen_addr->sin_addr), ntohs(listen_addr->sin_port));
 if((listen_sock = socket(2, SOCK_STREAM, 0)) < 0)
  fatal("socket: %s", strerror((*__errno_location ())));
 sockopt = 1;
 if(setsockopt(listen_sock, 1, 2, &sockopt, sizeof(sockopt)) < 0)
  fatal("setsockopt: SO_REUSEADDR: %s", strerror((*__errno_location ())));
 if(bind(listen_sock, (struct sockaddr *) listen_addr, sizeof(struct sockaddr_in)) < 0)
  fatal("bind: %s", strerror((*__errno_location ())));
 if(listen(listen_sock, 5) < 0)
  fatal("listen: %s", strerror((*__errno_location ())));
 while(1)
 {
  if(retune_id != -1)
  {
   verbose("Retune to service_id %d", retune_id);
   kill(listen_data.carousel->downloader, 9);
   cache_flush();
   listen_data.carousel = start_downloader(adapter, frontend, demux, dvr, timeout, retune_id, -1);
   retune_id = -1;
  }
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((listen_sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listen_sock) % (8 * (int) sizeof (__fd_mask)))))));
  if(select(listen_sock + 1, &read_fds, ((void *)0), ((void *)0), ((void *)0)) < 0)
  {
   if((*__errno_location ()) != 4)
    error("select: %s", strerror((*__errno_location ())));
   continue;
  }
  if(!((((&read_fds)->__fds_bits)[((listen_sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listen_sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   continue;
  addr_len = sizeof(client_addr);
  if((accept_sock = accept(listen_sock, (struct sockaddr *) &client_addr, &addr_len)) < 0)
  {
   error("accept: %s", strerror((*__errno_location ())));
   continue;
  }
  if((child = fork()) < 0)
  {
   fatal("fork: %s", strerror((*__errno_location ())));
  }
  else if(child == 0)
  {
   close(listen_sock);
   handle_connection(&listen_data, accept_sock, &client_addr);
   close(accept_sock);
   _exit(0);
  }
  else
  {
   close(accept_sock);
  }
 }
 close(listen_sock);
 return;
}

canonical_original_code:
void start_listener(struct sockaddr_in *listen_addr, unsigned int adapter, unsigned int frontend, unsigned int demux, unsigned int dvr, unsigned int timeout, unsigned short service_id, int carousel_id)
{
 struct listen_data listen_data;
 struct sigaction action;
 int sockopt;
 int listen_sock;
 int accept_sock;
 struct fd_set read_fds;
 unsigned int addr_len;
 struct sockaddr_in client_addr;
 int child;
 action.__sigaction_handler.sa_handler = dead_child;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 0;
 if(sigaction(17, &action, ((void *)0)) < 0)
  fatal("signal: SIGCHLD: %s", strerror((*__errno_location ())));
 listen_data.carousel = start_downloader(adapter, frontend, demux, dvr, timeout, service_id, carousel_id);
 action.__sigaction_handler.sa_sigaction = hup_handler;
 sigemptyset(&action.sa_mask);
 action.sa_flags = 4;
 if(sigaction(1, &action, ((void *)0)) < 0)
  fatal("signal: SIGHUP: %s", strerror((*__errno_location ())));
 verbose("Listening on %s:%u", inet_ntoa(listen_addr->sin_addr), ntohs(listen_addr->sin_port));
 if((listen_sock = socket(2, SOCK_STREAM, 0)) < 0)
  fatal("socket: %s", strerror((*__errno_location ())));
 sockopt = 1;
 if(setsockopt(listen_sock, 1, 2, &sockopt, sizeof(sockopt)) < 0)
  fatal("setsockopt: SO_REUSEADDR: %s", strerror((*__errno_location ())));
 if(bind(listen_sock, (struct sockaddr *) listen_addr, sizeof(struct sockaddr_in)) < 0)
  fatal("bind: %s", strerror((*__errno_location ())));
 if(listen(listen_sock, 5) < 0)
  fatal("listen: %s", strerror((*__errno_location ())));
 while(1)
 {
  if(retune_id != -1)
  {
   verbose("Retune to service_id %d", retune_id);
   kill(listen_data.carousel->downloader, 9);
   cache_flush();
   listen_data.carousel = start_downloader(adapter, frontend, demux, dvr, timeout, retune_id, -1);
   retune_id = -1;
  }
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&read_fds)->__fds_bits)[((listen_sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listen_sock) % (8 * (int) sizeof (__fd_mask)))))));
  if(select(listen_sock + 1, &read_fds, ((void *)0), ((void *)0), ((void *)0)) < 0)
  {
   if((*__errno_location ()) != 4)
    error("select: %s", strerror((*__errno_location ())));
   continue;
  }
  if(!((((&read_fds)->__fds_bits)[((listen_sock) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listen_sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))
   continue;
  addr_len = sizeof(client_addr);
  if((accept_sock = accept(listen_sock, (struct sockaddr *) &client_addr, &addr_len)) < 0)
  {
   error("accept: %s", strerror((*__errno_location ())));
   continue;
  }
  if((child = fork()) < 0)
  {
   fatal("fork: %s", strerror((*__errno_location ())));
  }
  else if(child == 0)
  {
   close(listen_sock);
   handle_connection(&listen_data, accept_sock, &client_addr);
   close(accept_sock);
   _exit(0);
  }
  else
  {
   close(accept_sock);
  }
 }
 close(listen_sock);
 return;
}

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: struct listen_data { struct carousel { char demux_device[4096]; char dvr_device[4096]; unsigned int timeout; int downloader; unsigned short network_id; unsigned short service_id; unsigned int carousel_id; unsigned short boot_pid; unsigned short audio_pid; unsigned char audio_type; unsigned short video_pid; unsigned char video_type; unsigned short current_pid; struct assoc { unsigned int nassocs; unsigned short *pids; unsigned short *sids; unsigned char *types; } assoc; int npids; struct pid_fds { unsigned short pid; int fd_ctrl; int fd_data; } *pids; _Bool got_dsi; unsigned int nmodules; struct module { unsigned short module_id; unsigned int download_id; unsigned char version; unsigned short block_size; unsigned short nblocks; unsigned int blocks_left; _Bool *got_block; unsigned int size; unsigned char *data; } *modules; } *carousel; }

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: sockopt int

user_defined_types: struct listen_data { struct carousel *carousel; }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

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

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

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
bool __fastcall is_audio_stream(unsigned __int8 a1)
{
bool result; // al

if ( a1 > 4u )
result = a1 == 17;
else
result = a1 > 2u;
return result;
}

canonical_decompiled_code:
bool __fastcall func2(unsigned __int8 a1)
{
bool result; // al

if ( a1 > 4u )
result = a1 == 17;
else
result = a1 > 2u;
return result;
}

original_code:
_Bool
is_audio_stream(uint8_t stream_type)
{
 switch(stream_type)
 {
 case 0x03:
 case 0x04:
 case 0x11:
  return 1;
 default:
  return 0;
 }
}

canonical_original_code:
_Bool is_audio_stream(unsigned char stream_type)
{
 switch(stream_type)
 {
 case 0x03:
 case 0x04:
 case 0x11:
  return 1;
 default:
  return 0;
 }
}


decompiled_code:
__int64 __fastcall free_module(__int64 a1)
{
safe_free(*(_QWORD *)(a1 + 40));
return safe_free(*(_QWORD *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
safe_free(*(_QWORD *)(a1 + 40));
return safe_free(*(_QWORD *)(a1 + 24));
}

original_code:
void
free_module(struct module *mod)
{
 safe_free(mod->data);
 safe_free(mod->got_block);
 return;
}

variable_types: struct module { unsigned short module_id; unsigned int download_id; unsigned char version; unsigned short block_size; unsigned short nblocks; unsigned int blocks_left; _Bool *got_block; unsigned int size; unsigned char *data; } *


original_code:
void
delete_module(struct carousel *car, uint32_t num)
{
 uint32_t size;
 free_module(&car->modules[num]);
 size = ((car->nmodules - 1) - num) * sizeof(struct module);
 if(size > 0)
  memmove(&car->modules[num], &car->modules[num + 1], size);
 car->nmodules --;
 return;
}

canonical_original_code:
void delete_module(struct carousel *car, unsigned int num)
{
 unsigned int size;
 free_module(&car->modules[num]);
 size = ((car->nmodules - 1) - num) * sizeof(struct module);
 if(size > 0)
  memmove(&car->modules[num], &car->modules[num + 1], size);
 car->nmodules --;
 return;
}

variable_types:
num
unsigned int

variable_types:
size
unsigned int

user_defined_types: struct module { unsigned short module_id; unsigned int download_id; unsigned char version; unsigned short block_size; unsigned short nblocks; unsigned int blocks_left; _Bool *got_block; unsigned int size; unsigned char *data; }

user_defined_types: struct assoc { unsigned int nassocs; unsigned short *pids; unsigned short *sids; unsigned char *types; }

user_defined_types: struct pid_fds { unsigned short pid; int fd_ctrl; int fd_data; }


decompiled_code:
__int64 __fastcall find_module(__int64 a1, __int16 a2, unsigned __int8 a3, int a4)
{
int v6; // ecx
__int64 v8; // rax
unsigned int v10; // esi
__int64 v11; // r8
__int64 result; // rax

v6 = *(_DWORD *)(a1 + 8276);
if ( v6 )
{
v8 = *(_QWORD *)(a1 + 8280);
v10 = 0;
while ( 1 )
{
v11 = v8;
if ( *(_WORD *)v8 == a2 && *(_DWORD *)(v8 + 4) == a4 )
{
if ( *(_BYTE *)(v8 + 8) == a3 )
goto LABEL_10;
if ( *(_BYTE *)(v8 + 8) < a3 )
break;
}
++v10;
v8 += 48LL;
if ( v6 == v10 )
goto LABEL_9;
}
delete_module(a1, v10);
result = 0LL;
}
else
{
LABEL_9:
v11 = 0LL;
LABEL_10:
result = v11;
}
return result;
}

original_code:
struct module *
find_module(struct carousel *car, uint16_t module_id, uint8_t version, uint32_t download_id)
{
 unsigned int i;
 for(i=0; i<car->nmodules; i++)
 {
  if(car->modules[i].module_id == module_id
  && car->modules[i].download_id == download_id)
  {
   if(car->modules[i].version == version)
   {
    return &car->modules[i];
   }
   else if(car->modules[i].version < version)
   {
    delete_module(car, i);
    return ((void *)0);
   }
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct module *find_module(struct carousel *car, unsigned short module_id, unsigned char version, unsigned int download_id)
{
 unsigned int i;
 for(i=0; i<car->nmodules; i++)
 {
  if(car->modules[i].module_id == module_id
  && car->modules[i].download_id == download_id)
  {
   if(car->modules[i].version == version)
   {
    return &car->modules[i];
   }
   else if(car->modules[i].version < version)
   {
    delete_module(car, i);
    return ((void *)0);
   }
  }
 }
 return ((void *)0);
}

variable_types: struct carousel { char demux_device[4096]; char dvr_device[4096]; unsigned int timeout; int downloader; unsigned short network_id; unsigned short service_id; unsigned int carousel_id; unsigned short boot_pid; unsigned short audio_pid; unsigned char audio_type; unsigned short video_pid; unsigned char video_type; unsigned short current_pid; struct assoc { unsigned int nassocs; unsigned short *pids; unsigned short *sids; unsigned char *types; } assoc; int npids; struct pid_fds { unsigned short pid; int fd_ctrl; int fd_data; } *pids; _Bool got_dsi; unsigned int nmodules; struct module *modules; } *

variable_types:
version
unsigned char

variable_types:
i
unsigned int

return_type: struct module { unsigned short module_id; unsigned int download_id; unsigned char version; unsigned short block_size; unsigned short nblocks; unsigned int blocks_left; _Bool *got_block; unsigned int size; unsigned char *data; } *


decompiled_code:
void __fastcall download_block(__int64 a1, unsigned __int16 *a2, unsigned __int16 a3, const void *a4, unsigned int a5)
{
_BYTE *v6; // rax
int v8; // edi
unsigned int v9; // er12
__int64 v10; // rsi
__int64 v11; // rcx
const void *v12; // rdx
size_t v13; // rax
void *v14; // rdi

if ( a2[6] <= a3 )
{
error((int)"download_block: moduleId=%u block=%u nblocks=%u", *a2, (const char *)a3);
}
else
{
v6 = (_BYTE *)(*((_QWORD *)a2 + 3) + a3);
if ( !*v6 )
{
v8 = a2[5];
v9 = a3;
*v6 = 1;
memcpy((void *)(*((_QWORD *)a2 + 5) + a3 * v8), a4, a5);
v10 = *a2;
v11 = (unsigned int)(*((_DWORD *)a2 + 4) - 1);
*((_DWORD *)a2 + 4) = v11;
verbose("download_block: module=%u block=%u left=%u", v10, v9, v11);
if ( !*((_DWORD *)a2 + 4) )
{
verbose("got module %u (size=%u)", *a2, *((unsigned int *)a2 + 8));
v12 = (const void *)*((_QWORD *)a2 + 5);
if ( memcmp(v12, "BIOP", 4uLL) )
{
vhexdump(*((_QWORD *)a2 + 5), *((unsigned int *)a2 + 8));
uncompress_module((__int64)a2);
verbose("uncompressed size=%u", *((unsigned int *)a2 + 8));
v12 = (const void *)*((_QWORD *)a2 + 5);
}
if ( (unsigned __int8)process_biop(a1, a2, v12, *((unsigned int *)a2 + 8)) )
{
safe_free(*((_QWORD *)a2 + 5));
*((_QWORD *)a2 + 5) = 0LL;
}
else
{
v13 = a2[6];
v14 = (void *)*((_QWORD *)a2 + 3);
*((_DWORD *)a2 + 4) = v13;
memset(v14, 0, v13);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, unsigned __int16 *a2, unsigned __int16 a3, const void *a4, unsigned int a5)
{
_BYTE *v6; // rax
int v8; // edi
unsigned int v9; // er12
__int64 v10; // rsi
__int64 v11; // rcx
const void *v12; // rdx
size_t v13; // rax
void *v14; // rdi

if ( a2[6] <= a3 )
{
error((int)"download_block: moduleId=%u block=%u nblocks=%u", *a2, (const char *)a3);
}
else
{
v6 = (_BYTE *)(*((_QWORD *)a2 + 3) + a3);
if ( !*v6 )
{
v8 = a2[5];
v9 = a3;
*v6 = 1;
memcpy((void *)(*((_QWORD *)a2 + 5) + a3 * v8), a4, a5);
v10 = *a2;
v11 = (unsigned int)(*((_DWORD *)a2 + 4) - 1);
*((_DWORD *)a2 + 4) = v11;
verbose("download_block: module=%u block=%u left=%u", v10, v9, v11);
if ( !*((_DWORD *)a2 + 4) )
{
verbose("got module %u (size=%u)", *a2, *((unsigned int *)a2 + 8));
v12 = (const void *)*((_QWORD *)a2 + 5);
if ( memcmp(v12, "BIOP", 4uLL) )
{
vhexdump(*((_QWORD *)a2 + 5), *((unsigned int *)a2 + 8));
func5((__int64)a2);
verbose("uncompressed size=%u", *((unsigned int *)a2 + 8));
v12 = (const void *)*((_QWORD *)a2 + 5);
}
if ( (unsigned __int8)process_biop(a1, a2, v12, *((unsigned int *)a2 + 8)) )
{
safe_free(*((_QWORD *)a2 + 5));
*((_QWORD *)a2 + 5) = 0LL;
}
else
{
v13 = a2[6];
v14 = (void *)*((_QWORD *)a2 + 3);
*((_DWORD *)a2 + 4) = v13;
memset(v14, 0, v13);
}
}
}
}
}

original_code:
void
download_block(struct carousel *car, struct module *mod, uint16_t block, unsigned char *data, uint32_t length)
{
 if(block >= mod->nblocks)
 {
  error("download_block: moduleId=%u block=%u nblocks=%u", mod->module_id, block, mod->nblocks);
  return;
 }
 if(mod->got_block[block])
  return;
 mod->got_block[block] = 1;
 memcpy(mod->data + (block * mod->block_size), data, length);
 mod->blocks_left --;
 verbose("download_block: module=%u block=%u left=%u", mod->module_id, block, mod->blocks_left);
 if(mod->blocks_left == 0)
 {
  verbose("got module %u (size=%u)", mod->module_id, mod->size);
  if(strncmp((char *) mod->data, "BIOP", 4) != 0)
  {
   vhexdump(mod->data, mod->size);
   uncompress_module(mod);
   verbose("uncompressed size=%u", mod->size);
  }
  if(process_biop(car, mod, (struct BIOPMessageHeader *) mod->data, mod->size))
  {
   safe_free(mod->data);
   mod->data = ((void *)0);
  }
  else
  {
   mod->blocks_left = mod->nblocks;
   bzero(mod->got_block, mod->nblocks * sizeof(_Bool));
  }
 }
 return;
}

canonical_original_code:
void download_block(struct carousel *car, struct module *mod, unsigned short block, unsigned char *data, unsigned int length)
{
 if(block >= mod->nblocks)
 {
  error("download_block: moduleId=%u block=%u nblocks=%u", mod->module_id, block, mod->nblocks);
  return;
 }
 if(mod->got_block[block])
  return;
 mod->got_block[block] = 1;
 memcpy(mod->data + (block * mod->block_size), data, length);
 mod->blocks_left --;
 verbose("download_block: module=%u block=%u left=%u", mod->module_id, block, mod->blocks_left);
 if(mod->blocks_left == 0)
 {
  verbose("got module %u (size=%u)", mod->module_id, mod->size);
  if(strncmp((char *) mod->data, "BIOP", 4) != 0)
  {
   vhexdump(mod->data, mod->size);
   uncompress_module(mod);
   verbose("uncompressed size=%u", mod->size);
  }
  if(process_biop(car, mod, (struct BIOPMessageHeader *) mod->data, mod->size))
  {
   safe_free(mod->data);
   mod->data = ((void *)0);
  }
  else
  {
   mod->blocks_left = mod->nblocks;
   bzero(mod->got_block, mod->nblocks * sizeof(_Bool));
  }
 }
 return;
}

variable_types:
mod
struct module *

variable_types:
block
unsigned short

variable_types:
data
unsigned char *

variable_types:
length
unsigned int

user_defined_types: struct BIOPMessageHeader { char magic[4]; struct BIOPVersion biop_version; unsigned char byte_order; unsigned char message_type; unsigned int message_size; }

user_defined_types: struct BIOPVersion { unsigned char major; unsigned char minor; }


decompiled_code:
__int64 cache_init()
{
__int64 result; // rax
int v1; // edi
char *v2; // rax

if ( mkdir("cache", 0x1EDu) >= 0 || (v1 = *_errno_location(), v1 == 17) )
{
cache_flush();
result = 1LL;
}
else
{
v2 = strerror(v1);
fatal("Unable to create cache directory '%s': %s", "cache", v2);
cache_flush();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int v1; // edi
char *v2; // rax

if ( mkdir("cache", 0x1EDu) >= 0 || (v1 = *_errno_location(), v1 == 17) )
{
func2();
result = 1LL;
}
else
{
v2 = strerror(v1);
fatal("Unable to create cache directory '%s': %s", "cache", v2);
func2();
result = 1LL;
}
return result;
}

original_code:
_Bool
cache_init(void)
{
 if(mkdir("cache", 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create cache directory '%s': %s", "cache", strerror((*__errno_location ())));
 cache_flush();
 return 1;
}

canonical_original_code:
_Bool cache_init()
{
 if(mkdir("cache", 0755) < 0 && (*__errno_location ()) != 17)
  fatal("Unable to create cache directory '%s': %s", "cache", strerror((*__errno_location ())));
 cache_flush();
 return 1;
}


decompiled_code:
__int64 __fastcall add_demux_filter(const char *errnum, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
int *v5; // rax
char *v6; // rax
int *v7; // rax
int v8; // eax
const char *v9; // rdx
int v10; // edi
__int16 v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+2h] [rbp-36h]
__int16 v13; // [rsp+6h] [rbp-32h]
__int64 v14; // [rsp+8h] [rbp-30h]
int v15; // [rsp+10h] [rbp-28h]

v2 = open(errnum, 2);
if ( v2 < 0 )
{
v5 = _errno_location();
v3 = -1;
v6 = strerror(*v5);
error((int)"open '%s': %s", (int)errnum, v6);
}
else
{
v3 = v2;
v13 = 0;
v14 = 0x1400000002LL;
v12 = 0;
v11 = a2;
v15 = 4;
if ( ioctl(v2, 0x40146F2CuLL, &v11) < 0 )
{
v7 = _errno_location();
v8 = (unsigned int)strerror(*v7);
error((int)"ioctl DMX_SET_PES_FILTER: %s", v8, v9);
v10 = v3;
v3 = -1;
close(v10);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *errnum, __int16 a2)
{
int v2; // eax
unsigned int v3; // er12
int *v5; // rax
char *v6; // rax
int *v7; // rax
int v8; // eax
const char *v9; // rdx
int v10; // edi
__int16 v11; // [rsp+0h] [rbp-38h] BYREF
int v12; // [rsp+2h] [rbp-36h]
__int16 v13; // [rsp+6h] [rbp-32h]
__int64 v14; // [rsp+8h] [rbp-30h]
int v15; // [rsp+10h] [rbp-28h]

v2 = open(errnum, 2);
if ( v2 < 0 )
{
v5 = _errno_location();
v3 = -1;
v6 = strerror(*v5);
error((int)"open '%s': %s", (int)errnum, v6);
}
else
{
v3 = v2;
v13 = 0;
v14 = 0x1400000002LL;
v12 = 0;
v11 = a2;
v15 = 4;
if ( ioctl(v2, 0x40146F2CuLL, &v11) < 0 )
{
v7 = _errno_location();
v8 = (unsigned int)strerror(*v7);
error((int)"ioctl DMX_SET_PES_FILTER: %s", v8, v9);
v10 = v3;
v3 = -1;
close(v10);
}
}
return v3;
}

original_code:
int
add_demux_filter(char *demux_dev, uint16_t pid, dmx_pes_type_t pes_type)
{
 int fd;
 struct dmx_pes_filter_params pes_filter;
 if((fd = open(demux_dev, 02)) < 0)
 {
  error("open '%s': %s", demux_dev, strerror((*__errno_location ())));
  return -1;
 }
 bzero(&pes_filter, sizeof(pes_filter));
 pes_filter.input = DMX_IN_FRONTEND;
 pes_filter.output = DMX_OUT_TS_TAP;
 pes_filter.flags = 4;
 pes_filter.pid = pid;
 pes_type = DMX_PES_OTHER;
 pes_filter.pes_type = pes_type;
 if(ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((44)) << 0) | ((((sizeof(struct dmx_pes_filter_params)))) << ((0 +8)+8))), &pes_filter) < 0)
 {
  error("ioctl DMX_SET_PES_FILTER: %s", strerror((*__errno_location ())));
  close(fd);
  return -1;
 }
 return fd;
}

canonical_original_code:
int add_demux_filter(char *demux_dev, unsigned short pid, enum dmx_ts_pes pes_type)
{
 int fd;
 struct dmx_pes_filter_params pes_filter;
 if((fd = open(demux_dev, 02)) < 0)
 {
  error("open '%s': %s", demux_dev, strerror((*__errno_location ())));
  return -1;
 }
 bzero(&pes_filter, sizeof(pes_filter));
 pes_filter.input = DMX_IN_FRONTEND;
 pes_filter.output = DMX_OUT_TS_TAP;
 pes_filter.flags = 4;
 pes_filter.pid = pid;
 pes_type = DMX_PES_OTHER;
 pes_filter.pes_type = pes_type;
 if(ioctl(fd, (((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((44)) << 0) | ((((sizeof(struct dmx_pes_filter_params)))) << ((0 +8)+8))), &pes_filter) < 0)
 {
  error("ioctl DMX_SET_PES_FILTER: %s", strerror((*__errno_location ())));
  close(fd);
  return -1;
 }
 return fd;
}

variable_types:
pid
unsigned short

variable_types: fd int

variable_types: struct dmx_pes_filter_params { unsigned short pid; enum dmx_input { DMX_IN_FRONTEND=0, DMX_IN_DVR=1 } input; enum dmx_output { DMX_OUT_DECODER=0, DMX_OUT_TAP=1, DMX_OUT_TS_TAP=2, DMX_OUT_TSDEMUX_TAP=3 } output; enum dmx_ts_pes { DMX_PES_AUDIO0=0, DMX_PES_VIDEO0=1, DMX_PES_TELETEXT0=2, DMX_PES_SUBTITLE0=3, DMX_PES_PCR0=4, DMX_PES_AUDIO1=5, DMX_PES_VIDEO1=6, DMX_PES_TELETEXT1=7, DMX_PES_SUBTITLE1=8, DMX_PES_PCR1=9, DMX_PES_AUDIO2=10, DMX_PES_VIDEO2=11, DMX_PES_TELETEXT2=12, DMX_PES_SUBTITLE2=13, DMX_PES_PCR2=14, DMX_PES_AUDIO3=15, DMX_PES_VIDEO3=16, DMX_PES_TELETEXT3=17, DMX_PES_SUBTITLE3=18, DMX_PES_PCR3=19, DMX_PES_OTHER=20 } pes_type; unsigned int flags; }

user_defined_types: struct dmx_pes_filter_params { unsigned short pid; enum dmx_input input; enum dmx_output output; enum dmx_ts_pes pes_type; unsigned int flags; }


decompiled_code:
__int64 __fastcall list_channels(unsigned int a1, unsigned int a2, unsigned int a3)
{
int v3; // ebx
int v4; // eax
int v5; // er13
unsigned __int16 v6; // ax
__int16 i; // bp
int v8; // ebx
char *v9; // rdi
__int64 v10; // rsi
int v11; // er15
int v12; // ebx
unsigned __int16 v13; // ax
unsigned __int8 v14; // r14
__int64 result; // rax
unsigned __int8 v16; // [rsp+Ah] [rbp-203Eh]
unsigned __int8 v17; // [rsp+Bh] [rbp-203Dh]
char s[4096]; // [rsp+10h] [rbp-2038h] BYREF
char v20; // [rsp+1010h] [rbp-1038h] BYREF
char v21[4151]; // [rsp+1011h] [rbp-1037h]

snprintf(s, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
puts("Channels on this mutiplex:\n");
puts("ID\tChannel");
puts("==\t=======");
v16 = 0;
do
{
if ( !(unsigned __int8)read_sdt(s, a3, &v20, v16) )
fatal("Unable to read SDT");
v3 = 11;
v17 = v21[6];
v4 = 11;
v5 = (unsigned __int16)((((unsigned __int8)v21[0] << 8) & 0xF00) + (unsigned __int8)v21[1] + 3) - 4;
if ( v5 > 11 )
{
do
{
printf("%u\t", (unsigned __int16)((unsigned __int8)*(&v20 + v4 + 1) + ((unsigned __int8)*(&v20 + v4) << 8)));
v6 = v3 + 3;
v3 += 5;
for ( i = (unsigned __int8)v21[v6] + (((unsigned __int8)*(&v20 + v6) << 8) & 0xF00); i; i += -2 - v11 )
{
while ( 1 )
{
v10 = (unsigned __int8)*(&v20 + (unsigned __int16)v3);
v11 = (unsigned __int8)v21[(unsigned __int16)v3];
if ( (_BYTE)v10 == 72 )
break;
v8 = v3 + 2;
vverbose("desc_tag: %u", v10);
v9 = &v20 + (unsigned __int16)v8;
v3 = v11 + v8;
vhexdump(v9, (unsigned __int8)v11);
i += -2 - v11;
if ( !i )
goto LABEL_10;
}
v12 = v3 + 3 + (unsigned __int8)*(&v20 + (unsigned __int16)(v3 + 3));
v13 = v12 + 1;
v12 += 2;
v14 = *(&v20 + v13);
printf("%.*s\n", v14, &v20 + (unsigned __int16)v12);
v3 = v14 + v12;
}
LABEL_10:
v4 = (unsigned __int16)v3;
}
while ( (unsigned __int16)v3 < v5 );
}
result = ++v16;
}
while ( v17 >= v16 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, unsigned int a3)
{
int v3; // ebx
int v4; // eax
int v5; // er13
unsigned __int16 v6; // ax
__int16 i; // bp
int v8; // ebx
char *v9; // rdi
__int64 v10; // rsi
int v11; // er15
int v12; // ebx
unsigned __int16 v13; // ax
unsigned __int8 v14; // r14
__int64 result; // rax
unsigned __int8 v16; // [rsp+Ah] [rbp-203Eh]
unsigned __int8 v17; // [rsp+Bh] [rbp-203Dh]
char s[4096]; // [rsp+10h] [rbp-2038h] BYREF
char v20; // [rsp+1010h] [rbp-1038h] BYREF
char v21[4151]; // [rsp+1011h] [rbp-1037h]

snprintf(s, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
puts("Channels on this mutiplex:\n");
puts("ID\tChannel");
puts("==\t=======");
v16 = 0;
do
{
if ( !(unsigned __int8)read_sdt(s, a3, &v20, v16) )
fatal("Unable to read SDT");
v3 = 11;
v17 = v21[6];
v4 = 11;
v5 = (unsigned __int16)((((unsigned __int8)v21[0] << 8) & 0xF00) + (unsigned __int8)v21[1] + 3) - 4;
if ( v5 > 11 )
{
do
{
printf("%u\t", (unsigned __int16)((unsigned __int8)*(&v20 + v4 + 1) + ((unsigned __int8)*(&v20 + v4) << 8)));
v6 = v3 + 3;
v3 += 5;
for ( i = (unsigned __int8)v21[v6] + (((unsigned __int8)*(&v20 + v6) << 8) & 0xF00); i; i += -2 - v11 )
{
while ( 1 )
{
v10 = (unsigned __int8)*(&v20 + (unsigned __int16)v3);
v11 = (unsigned __int8)v21[(unsigned __int16)v3];
if ( (_BYTE)v10 == 72 )
break;
v8 = v3 + 2;
vverbose("desc_tag: %u", v10);
v9 = &v20 + (unsigned __int16)v8;
v3 = v11 + v8;
vhexdump(v9, (unsigned __int8)v11);
i += -2 - v11;
if ( !i )
goto LABEL_10;
}
v12 = v3 + 3 + (unsigned __int8)*(&v20 + (unsigned __int16)(v3 + 3));
v13 = v12 + 1;
v12 += 2;
v14 = *(&v20 + v13);
printf("%.*s\n", v14, &v20 + (unsigned __int16)v12);
v3 = v14 + v12;
}
LABEL_10:
v4 = (unsigned __int16)v3;
}
while ( (unsigned __int16)v3 < v5 );
}
result = ++v16;
}
while ( v17 >= v16 );
return result;
}

original_code:
void
list_channels(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 uint16_t size;
 uint16_t offset;
 uint16_t service_id;
 uint16_t desc_loop_length;
 uint8_t desc_tag;
 uint8_t desc_length;
 uint8_t name_len;
 uint8_t sn, lsn;
 snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 printf("Channels on this mutiplex:\n\n");
 printf("ID\tChannel\n");
 printf("==\t=======\n");
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn))
   fatal("Unable to read SDT");
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
   printf("%u\t", service_id);
   offset += 3;
   desc_loop_length = ((sdt[offset] & 0x0f) << 8) + sdt[offset+1];
   offset += 2;
   while(desc_loop_length != 0)
   {
    desc_tag = sdt[offset];
    desc_length = sdt[offset+1];
    offset += 2;
    desc_loop_length -= 2;
    if(desc_tag == 0x48)
    {
     offset += 1;
     name_len = sdt[offset];
     offset += 1 + name_len;
     name_len = sdt[offset];
     offset += 1;
     printf("%.*s\n", name_len, &sdt[offset]);
     offset += name_len;
    }
    else
    {
     vverbose("desc_tag: %u", desc_tag);
     vhexdump(&sdt[offset], desc_length);
     offset += desc_length;
    }
    desc_loop_length -= desc_length;
   }
  }
 }
 return;
}

canonical_original_code:
void list_channels(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 unsigned short size;
 unsigned short offset;
 unsigned short service_id;
 unsigned short desc_loop_length;
 unsigned char desc_tag;
 unsigned char desc_length;
 unsigned char name_len;
 unsigned char sn; unsigned char lsn;
 snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 printf("Channels on this mutiplex:\n\n");
 printf("ID\tChannel\n");
 printf("==\t=======\n");
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn))
   fatal("Unable to read SDT");
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
   printf("%u\t", service_id);
   offset += 3;
   desc_loop_length = ((sdt[offset] & 0x0f) << 8) + sdt[offset+1];
   offset += 2;
   while(desc_loop_length != 0)
   {
    desc_tag = sdt[offset];
    desc_length = sdt[offset+1];
    offset += 2;
    desc_loop_length -= 2;
    if(desc_tag == 0x48)
    {
     offset += 1;
     name_len = sdt[offset];
     offset += 1 + name_len;
     name_len = sdt[offset];
     offset += 1;
     printf("%.*s\n", name_len, &sdt[offset]);
     offset += name_len;
    }
    else
    {
     vverbose("desc_tag: %u", desc_tag);
     vhexdump(&sdt[offset], desc_length);
     offset += desc_length;
    }
    desc_loop_length -= desc_length;
   }
  }
 }
 return;
}

variable_types:
adapter
unsigned int

variable_types:
demux
unsigned int

variable_types:
timeout
unsigned int

variable_types:
sdt
unsigned char [4096]

variable_types:
size
unsigned short

variable_types:
offset
unsigned short

variable_types:
sn
unsigned char

variable_types:
lsn
unsigned char


decompiled_code:
__int64 __fastcall get_first_service_id(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned __int8 v4; // bp
const char *v5; // rdx
unsigned __int8 v6; // r14
unsigned __int16 v7; // bx
unsigned int v8; // er12
char v10[4096]; // [rsp+0h] [rbp-2028h] BYREF
char v11[11]; // [rsp+1000h] [rbp-1028h] BYREF
unsigned __int8 v12; // [rsp+100Bh] [rbp-101Dh]
unsigned __int8 v13; // [rsp+100Ch] [rbp-101Ch]

v4 = 0;
snprintf(v10, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
while ( (unsigned __int8)read_sdt(v10, a3, v11, v4) )
{
v6 = v11[7];
v7 = (((unsigned __int8)v11[1] << 8) & 0xF00) + (unsigned __int8)v11[2] + 3;
while ( v7 > 0xFu )
{
v8 = v13 + (v12 << 8);
fprintf(stderr, "%d\n", (unsigned __int16)(v13 + (v12 << 8)));
if ( (_WORD)v8 )
return v8;
}
if ( v6 < ++v4 )
return 0;
}
v8 = 0;
error((int)"Unable to read SDT", a3, v5);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned __int8 v4; // bp
const char *v5; // rdx
unsigned __int8 v6; // r14
unsigned __int16 v7; // bx
unsigned int v8; // er12
char v10[4096]; // [rsp+0h] [rbp-2028h] BYREF
char v11[11]; // [rsp+1000h] [rbp-1028h] BYREF
unsigned __int8 v12; // [rsp+100Bh] [rbp-101Dh]
unsigned __int8 v13; // [rsp+100Ch] [rbp-101Ch]

v4 = 0;
snprintf(v10, 0x1000uLL, "/dev/dvb/adapter%u/demux%u", a1, a2);
while ( (unsigned __int8)read_sdt(v10, a3, v11, v4) )
{
v6 = v11[7];
v7 = (((unsigned __int8)v11[1] << 8) & 0xF00) + (unsigned __int8)v11[2] + 3;
while ( v7 > 0xFu )
{
v8 = v13 + (v12 << 8);
fprintf(stderr, "%d\n", (unsigned __int16)(v13 + (v12 << 8)));
if ( (_WORD)v8 )
return v8;
}
if ( v6 < ++v4 )
return 0;
}
v8 = 0;
error((int)"Unable to read SDT", a3, v5);
return v8;
}

original_code:
uint16_t
get_first_service_id(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 uint16_t size;
 uint16_t offset;
 uint16_t service_id;
 uint8_t sn, lsn;
  snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn)){
   error("Unable to read SDT");
   return 0;
  }
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
      fprintf(stderr, "%d\n", service_id);
      if (service_id > 0)
        return service_id;
    }
  }
  return 0;
}

canonical_original_code:
unsigned short get_first_service_id(unsigned int adapter, unsigned int demux, unsigned int timeout)
{
 char demux_dev[4096];
 unsigned char sdt[4096];
 unsigned short size;
 unsigned short offset;
 unsigned short service_id;
 unsigned char sn; unsigned char lsn;
  snprintf(demux_dev, sizeof(demux_dev), "/dev/dvb/adapter%u/demux%u", adapter, demux);
 for(sn=0, lsn=0; sn<=lsn; sn++)
 {
  if(!read_sdt(demux_dev, timeout, sdt, sn)){
   error("Unable to read SDT");
   return 0;
  }
  size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
  lsn = sdt[7];
  offset = 11;
  while(offset < (size - 4))
  {
   service_id = (sdt[offset] << 8) + sdt[offset+1];
      fprintf(stderr, "%d\n", service_id);
      if (service_id > 0)
        return service_id;
    }
  }
  return 0;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall Literal_app(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 16) = a2;
return a1;
}

original_code:
static Literal_t *Literal_app(Literal_t *lit1, Literal_t *lit2) {
   lit1->next = lit2;
   return lit1;
}

canonical_original_code:
static struct Literal_t *Literal_app(struct Literal_t *lit1, struct Literal_t *lit2) {
   lit1->next = lit2;
   return lit1;
}

return_type: struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *

user_defined_types: struct Literal_t { enum data_type t; union LitVal val; struct Literal_t *next; }


litDouble

decompiled_code:
double *__fastcall litDouble(double a1)
{
double *result; // rax

result = (double *)calloc(1uLL, 0x18uLL);
*(_DWORD *)result = 1;
result[1] = a1;
return result;
}

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

result = (double *)calloc(1uLL, 0x18uLL);
*(_DWORD *)result = 1;
result[1] = a1;
return result;
}

original_code:
Literal_t *litDouble(double d) {
   Literal_t *lval = (Literal_t *)calloc(1, sizeof(Literal_t));
   lval->t = TYPE_DOUBLE;
   lval->val.dval = d;
   return lval;
}

canonical_original_code:
struct Literal_t *litDouble(double d) {
   struct Literal_t *lval = (Literal_t *)calloc(1, sizeof(Literal_t));
   lval->t = TYPE_DOUBLE;
   lval->val.dval = d;
   return lval;
}

variable_types: d double

variable_types: struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *


decompiled_code:
int __fastcall Literal_print(unsigned int *a1)
{
const char *v1; // rax
unsigned int v2; // eax
int result; // eax
__int64 v4; // [rsp+0h] [rbp-78h] BYREF

v1 = (const char *)typeToString(*a1, &v4);
printf("%s ", v1);
v2 = *a1;
if ( *a1 == 2 )
return printf("'%c'", (unsigned int)*((char *)a1 + 8));
if ( v2 > 2 )
{
if ( v2 == 3 )
result = printf("\"%s\"", *((const char **)a1 + 1));
else
result = printf("(unknown type)");
}
else if ( v2 )
{
result = printf("%f", *((double *)a1 + 1));
}
else
{
result = printf("%d", a1[2]);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int *a1)
{
const char *v1; // rax
unsigned int v2; // eax
int result; // eax
__int64 v4; // [rsp+0h] [rbp-78h] BYREF

v1 = (const char *)typeToString(*a1, &v4);
printf("%s ", v1);
v2 = *a1;
if ( *a1 == 2 )
return printf("'%c'", (unsigned int)*((char *)a1 + 8));
if ( v2 > 2 )
{
if ( v2 == 3 )
result = printf("\"%s\"", *((const char **)a1 + 1));
else
result = printf("(unknown type)");
}
else if ( v2 )
{
result = printf("%f", *((double *)a1 + 1));
}
else
{
result = printf("%d", a1[2]);
}
return result;
}

original_code:
void Literal_print(Literal_t *val) {
   char buf[100];
   printf("%s ", typeToString(val->t, buf));
   switch (val->t) {
      case TYPE_INT:
         printf("%d", val->val.ival);
         break;
      case TYPE_DOUBLE:
         printf("%f", val->val.dval);
         break;
      case TYPE_CHAR:
         printf("'%c'", val->val.cval);
         break;
      case TYPE_TEXT:
         printf("\"%s\"", val->val.strval);
         break;
      default:
         printf("(unknown type)");
   }
}

canonical_original_code:
void Literal_print(struct Literal_t *val) {
   char buf[100];
   printf("%s ", typeToString(val->t, buf));
   switch (val->t) {
      case TYPE_INT:
         printf("%d", val->val.ival);
         break;
      case TYPE_DOUBLE:
         printf("%f", val->val.dval);
         break;
      case TYPE_CHAR:
         printf("'%c'", val->val.cval);
         break;
      case TYPE_TEXT:
         printf("\"%s\"", val->val.strval);
         break;
      default:
         printf("(unknown type)");
   }
}

variable_types:
buf
char [100]

user_defined_types: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }

user_defined_types: union LitVal { int ival; double dval; char cval; char *strval; }


decompiled_code:
int __fastcall Literal_printList(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
Literal_print((unsigned int *)v1);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
func2((unsigned int *)v1);
v1 = *(_QWORD *)(v1 + 16);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

original_code:
void Literal_printList(Literal_t *val_list) {
   int first = 1;
   printf("[");
   while (val_list) {
      if (first) first = 0; else printf(", ");
      Literal_print(val_list);
      val_list = val_list->next;
   }
   printf("]");
}

canonical_original_code:
void Literal_printList(struct Literal_t *val_list) {
   int first = 1;
   printf("[");
   while (val_list) {
      if (first) first = 0; else printf(", ");
      Literal_print(val_list);
      val_list = val_list->next;
   }
   printf("]");
}

variable_types: first int


decompiled_code:
__int64 __fastcall Literal_append(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 )
return a2;
v2 = Literal_append(*(_QWORD *)(a1 + 16));
return Literal_app(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 )
return a2;
v2 = func4(*(_QWORD *)(a1 + 16));
return func0(a1, v2);
}

original_code:
Literal_t *Literal_append(Literal_t *lit1, Literal_t *lit2) {
   if (!lit1) return lit2;
   return Literal_app(lit1, Literal_append(lit1->next, lit2));
}

canonical_original_code:
struct Literal_t *Literal_append(struct Literal_t *lit1, struct Literal_t *lit2) {
   if (!lit1) return lit2;
   return Literal_app(lit1, Literal_append(lit1->next, lit2));
}


decompiled_code:
void __fastcall Literal_free(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Literal_free(Literal_t *lval) {
   if (lval->t == TYPE_TEXT)
      free(lval->val.strval);
   free(lval);
}

canonical_original_code:
void Literal_free(struct Literal_t *lval) {
   if (lval->t == TYPE_TEXT)
      free(lval->val.strval);
   free(lval);
}


decompiled_code:
void __fastcall Literal_freeList(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
}
}

original_code:
void Literal_freeList(Literal_t *lval) {
   Literal_t *temp;
   while (lval) {
      temp = lval;
      lval = lval->next;
      free(temp);
   }
}

canonical_original_code:
void Literal_freeList(struct Literal_t *lval) {
   struct Literal_t *temp;
   while (lval) {
      temp = lval;
      lval = lval->next;
      free(temp);
   }
}


decompiled_code:
void __fastcall vector_resize(_QWORD *a1, unsigned __int64 a2)
{
size_t v2; // rbx
void *v3; // rax
void *v4; // r13
void *v5; // r12

v2 = 1LL;
if ( a2 > 1 )
{
do
v2 *= 2LL;
while ( a2 > v2 );
}
v3 = calloc(v2, 8uLL);
v4 = (void *)a1[2];
v5 = v3;
memcpy(v3, v4, 8LL * *a1);
free(v4);
a1[2] = v5;
a1[1] = v2;
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, unsigned __int64 a2)
{
size_t v2; // rbx
void *v3; // rax
void *v4; // r13
void *v5; // r12

v2 = 1LL;
if ( a2 > 1 )
{
do
v2 *= 2LL;
while ( a2 > v2 );
}
v3 = calloc(v2, 8uLL);
v4 = (void *)a1[2];
v5 = v3;
memcpy(v3, v4, 8LL * *a1);
free(v4);
a1[2] = v5;
a1[1] = v2;
}

original_code:
static void vector_resize(vector_t *vec, size_t new_size) {
   size_t max_size = 1;
   while (max_size < new_size)
      max_size *= 2;
   void **temp = (void **)calloc(max_size, sizeof(void *));
   memcpy(temp, vec->data, vec->size * sizeof(void *));
   free(vec->data);
   vec->data = temp;
   vec->max_size = max_size;
}

canonical_original_code:
static void vector_resize(struct vector_s *vec, unsigned long new_size) {
   unsigned long max_size = 1;
   while (max_size < new_size)
      max_size *= 2;
   void **temp = (void **)calloc(max_size, sizeof(void *));
   memcpy(temp, vec->data, vec->size * sizeof(void *));
   free(vec->data);
   vec->data = temp;
   vec->max_size = max_size;
}

variable_types: struct vector_s { unsigned long size; void **data; void (*free)(void *); } *

variable_types:
temp
void **


decompiled_code:
int __fastcall vector_setAt(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v3; // rax

if ( *a1 <= a2 )
{
LODWORD(v3) = fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", a2);
}
else
{
v3 = a1[2];
*(_QWORD *)(v3 + 8 * a2) = a3;
}
return v3;
}

canonical_decompiled_code:
int __fastcall func2(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v3; // rax

if ( *a1 <= a2 )
{
LODWORD(v3) = fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", a2);
}
else
{
v3 = a1[2];
*(_QWORD *)(v3 + 8 * a2) = a3;
}
return v3;
}

original_code:
void vector_setAt(vector_t *vector, size_t i, void *data) {
   if (i < vector->size)
      vector->data[i] = data;
   else
      fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", i);
}

canonical_original_code:
void vector_setAt(struct vector_s *vector, unsigned long i, void *data) {
   if (i < vector->size)
      vector->data[i] = data;
   else
      fprintf(stderr, "vector_setAt error: index %lu out of bounds, nothing added\n", i);
}

variable_types:
i
unsigned long

variable_types:
data
void *

user_defined_types: struct vector_s { unsigned long size; void **data; void (*free)(void *); }


decompiled_code:
__int64 __fastcall vector_pop(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 v3; // rsi
__int64 v4; // r12

v1 = a1[2];
v2 = *a1 - 1;
v3 = a1[1] >> 1;
*a1 = v2;
v4 = *(_QWORD *)(v1 + 8 * v2);
if ( v2 > v3 )
return *(_QWORD *)(v1 + 8 * v2);
vector_resize(a1, v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 *a1)
{
unsigned __int64 v1; // rdx
unsigned __int64 v2; // rax
unsigned __int64 v3; // rsi
__int64 v4; // r12

v1 = a1[2];
v2 = *a1 - 1;
v3 = a1[1] >> 1;
*a1 = v2;
v4 = *(_QWORD *)(v1 + 8 * v2);
if ( v2 > v3 )
return *(_QWORD *)(v1 + 8 * v2);
func0(a1, v3);
return v4;
}

original_code:
void *vector_pop(vector_t *vec) {
   void *ret = vec->data[--vec->size];
   if (vec->size <= (vec->max_size)/2)
      vector_resize(vec, (vec->max_size)/2);
   return ret;
}

canonical_original_code:
void *vector_pop(struct vector_s *vec) {
   void *ret = vec->data[--vec->size];
   if (vec->size <= (vec->max_size)/2)
      vector_resize(vec, (vec->max_size)/2);
   return ret;
}

variable_types:
ret
void *

return_type: void *


decompiled_code:
__int64 __fastcall vector_getAt(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 > a2 )
return *(_QWORD *)(a1[2] + 8 * a2);
fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 > a2 )
return *(_QWORD *)(a1[2] + 8 * a2);
fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", a2);
return 0LL;
}

original_code:
void *vector_getAt(vector_t *vec, size_t i) {
   if (i < vec->size)
      return vec->data[i];
   fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", i);
   return ((void *)0);
}

canonical_original_code:
void *vector_getAt(struct vector_s *vec, unsigned long i) {
   if (i < vec->size)
      return vec->data[i];
   fprintf(stderr, "vector_getAt error: index %lu out of bounds, returning null\n", i);
   return ((void *)0);
}


decompiled_code:
__int64 __fastcall vector_size(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
size_t vector_size(vector_t *vector) {
   return vector->size;
}

canonical_original_code:
unsigned long vector_size(struct vector_s *vector) {
   return vector->size;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall vector_print(unsigned __int64 *a1, __int64 (__fastcall *a2)(__int64))
{
unsigned __int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax

if ( *a1 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1[2] + 8 * v3++);
result = a2(v4);
}
while ( *a1 > v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 *a1, __int64 (__fastcall *a2)(__int64))
{
unsigned __int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax

if ( *a1 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(a1[2] + 8 * v3++);
result = a2(v4);
}
while ( *a1 > v3 );
}
return result;
}

original_code:
void vector_print(vector_t *vector, void (*print) (void *)) {
   size_t i;
   for (i=0; i<vector->size; ++i) {
      print(vector->data[i]);
   }
}

canonical_original_code:
void vector_print(struct vector_s *vector, void (*print)(void *)) {
   unsigned long i;
   for (i=0; i<vector->size; ++i) {
      print(vector->data[i]);
   }
}

variable_types:
print
void (*)(void *)


decompiled_code:
int __fastcall vector_printStrings(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // rsi
const char *v3; // rax

v1 = 0LL;
printf("string_vec[");
if ( *a1 )
{
while ( 1 )
{
v2 = v1++;
v3 = (const char *)vector_getAt(a1, v2);
printf("%s", v3);
if ( *a1 <= v1 )
break;
if ( v1 )
printf(", ");
}
}
return puts("]");
}

canonical_decompiled_code:
int __fastcall func7(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // rsi
const char *v3; // rax

v1 = 0LL;
printf("string_vec[");
if ( *a1 )
{
while ( 1 )
{
v2 = v1++;
v3 = (const char *)func4(a1, v2);
printf("%s", v3);
if ( *a1 <= v1 )
break;
if ( v1 )
printf(", ");
}
}
return puts("]");
}

original_code:
void vector_printStrings(vector_t *vector) {
   size_t i;
   printf("string_vec[");
   for (i=0; i<vector->size; ++i) {
      if (i != 0) printf(", ");
      printf("%s", (char *)vector_getAt(vector, i));
   }
   printf("]\n");
}

canonical_original_code:
void vector_printStrings(struct vector_s *vector) {
   unsigned long i;
   printf("string_vec[");
   for (i=0; i<vector->size; ++i) {
      if (i != 0) printf(", ");
      printf("%s", (char *)vector_getAt(vector, i));
   }
   printf("]\n");
}


decompiled_code:
void __fastcall vector_clear(unsigned __int64 *a1)
{
unsigned __int64 v1; // rbx
void (*v2)(void); // rax

if ( a1 )
{
if ( *a1 )
{
v1 = 0LL;
do
{
if ( *(_QWORD *)(a1[2] + 8 * v1) )
{
v2 = (void (*)(void))a1[3];
if ( v2 )
v2();
}
++v1;
}
while ( *a1 > v1 );
}
*a1 = 0LL;
a1[1] = 0LL;
}
}

original_code:
void vector_clear(vector_t *vector) {
   size_t i;
   if (!vector) return;
   for (i = 0; i < vector->size; ++i) {
      if (vector->data[i] && vector->free) {
         vector->free(vector->data[i]);
      }
   }
   vector->size = 0;
   vector->max_size = 0;
}

canonical_original_code:
void vector_clear(struct vector_s *vector) {
   unsigned long i;
   if (!vector) return;
   for (i = 0; i < vector->size; ++i) {
      if (vector->data[i] && vector->free) {
         vector->free(vector->data[i]);
      }
   }
   vector->size = 0;
   vector->max_size = 0;
}


decompiled_code:
void __fastcall vector_setDeleteFunc(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
}

original_code:
void vector_setDeleteFunc(vector_t *vector, void (*free) (void *)) {
   if (vector)
      vector->free = free;
}

canonical_original_code:
void vector_setDeleteFunc(struct vector_s *vector, void (*free)(void *)) {
   if (vector)
      vector->free = free;
}

variable_types:
free
void (*)(void *)


decompiled_code:
char *random_str()
{
int v0; // eax
__int64 v1; // rbx
unsigned __int64 v2; // rbp
char *v3; // rax
__int64 v4; // rdx
char *v5; // r12
char *v6; // r13
char *v7; // rbx

v0 = rand() % 15;
v1 = v0;
v2 = v0 + 5;
v3 = (char *)malloc(v0 + 6);
v4 = (unsigned int)word_count;
v5 = v3;
++word_count;
sprintf(v3, "%4d ", v4);
if ( v2 <= 5 )
{
v2 = 5LL;
}
else
{
v6 = v5 + 5;
v7 = &v5[v1 + 5];
do
*v6++ = rand() % 26 + 97;
while ( v6 != v7 );
}
v5[v2] = 0;
return v5;
}

canonical_decompiled_code:
char *func10()
{
int v0; // eax
__int64 v1; // rbx
unsigned __int64 v2; // rbp
char *v3; // rax
__int64 v4; // rdx
char *v5; // r12
char *v6; // r13
char *v7; // rbx

v0 = rand() % 15;
v1 = v0;
v2 = v0 + 5;
v3 = (char *)malloc(v0 + 6);
v4 = (unsigned int)word_count;
v5 = v3;
++word_count;
sprintf(v3, "%4d ", v4);
if ( v2 <= 5 )
{
v2 = 5LL;
}
else
{
v6 = v5 + 5;
v7 = &v5[v1 + 5];
do
*v6++ = rand() % 26 + 97;
while ( v6 != v7 );
}
v5[v2] = 0;
return v5;
}

original_code:
char *random_str() {
   size_t size = rand() % 15, i;
   char *str = (char *)malloc(size + 6);
   sprintf(str, "%4d ", word_count++);
   for (i=5; i<size+5; ++i)
      str[i] = (rand() % 26) + 'a';
   str[i] = '\0';
   return str;
}

canonical_original_code:
char *random_str() {
   unsigned long size = rand() % 15; unsigned long i;
   char *str = (char *)malloc(size + 6);
   sprintf(str, "%4d ", word_count++);
   for (i=5; i<size+5; ++i)
      str[i] = (rand() % 26) + 'a';
   str[i] = '\0';
   return str;
}

variable_types:
size
unsigned long

variable_types:
str
char *


decompiled_code:
__int64 __fastcall vec_main(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
unsigned __int64 *v8; // rbx
unsigned __int64 v9; // rbp
unsigned __int64 v10; // rsi
const char *v11; // rax
int v12; // er12
char *v13; // rbp
int v14; // ebp
const char *v15; // rax

v8 = vector_withData(3uLL, a1, a2, a3, a4, a5, a6, a7, a8, "hello", "hi", "how are you");
if ( *v8 )
{
v9 = 0LL;
do
{
v10 = v9++;
v11 = (const char *)vector_getAt(v8, v10);
puts(v11);
}
while ( *v8 > v9 );
}
v12 = 1000;
do
{
v13 = random_str();
printf("pushing %s, size is %lu, max_size %lu\n", v13, *v8, v8[1]);
vector_push(v8, (__int64)v13);
--v12;
}
while ( v12 );
v14 = 500;
printf("printing vector %lu %lu\n", *v8, v8[1]);
fflush(stdout);
do
{
v15 = (const char *)vector_pop(v8);
printf("popped %s, size is %lu, max_size %lu\n", v15, *v8, v8[1]);
--v14;
}
while ( v14 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
unsigned __int64 *v8; // rbx
unsigned __int64 v9; // rbp
unsigned __int64 v10; // rsi
const char *v11; // rax
int v12; // er12
char *v13; // rbp
int v14; // ebp
const char *v15; // rax

v8 = func1(3uLL, a1, a2, a3, a4, a5, a6, a7, a8, "hello", "hi", "how are you");
if ( *v8 )
{
v9 = 0LL;
do
{
v10 = v9++;
v11 = (const char *)func4(v8, v10);
puts(v11);
}
while ( *v8 > v9 );
}
v12 = 1000;
do
{
v13 = func10();
printf("pushing %s, size is %lu, max_size %lu\n", v13, *v8, v8[1]);
vector_push(v8, (__int64)v13);
--v12;
}
while ( v12 );
v14 = 500;
printf("printing vector %lu %lu\n", *v8, v8[1]);
fflush(stdout);
do
{
v15 = (const char *)func3(v8);
printf("popped %s, size is %lu, max_size %lu\n", v15, *v8, v8[1]);
--v14;
}
while ( v14 );
return 0LL;
}

original_code:
int vec_main(int argc, char const *argv[])
{
   vector_t *vec = vector_withData(3, "hello", "hi", "how are you");
   int i;
   for (i=0; i<vec->size; ++i)
      printf("%s\n", (char *)vector_getAt(vec, i));
   for (i=0; i<1000; ++i) {
      char *str = random_str();
      printf("pushing %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
      vector_push(vec, str);
   }
   printf("printing vector %lu %lu\n", vec->size, vec->max_size); fflush(stdout);
   for (i=0; i<500; ++i) {
      char *str = (char *)vector_pop(vec);
      printf("popped %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
   }
   return 0;
}

canonical_original_code:
int vec_main(int argc, char *argv[])
{
   struct vector_s *vec = vector_withData(3, "hello", "hi", "how are you");
   int i;
   for (i=0; i<vec->size; ++i)
      printf("%s\n", (char *)vector_getAt(vec, i));
   for (i=0; i<1000; ++i) {
      char *str = random_str();
      printf("pushing %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
      vector_push(vec, str);
   }
   printf("printing vector %lu %lu\n", vec->size, vec->max_size); fflush(stdout);
   for (i=0; i<500; ++i) {
      char *str = (char *)vector_pop(vec);
      printf("popped %s, size is %lu, max_size %lu\n", str, vec->size, vec->max_size);
   }
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
void __fastcall vector_free(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void vector_free(vector_t *vector) {
   free(vector->data);
}

canonical_original_code:
void vector_free(struct vector_s *vector) {
   free(vector->data);
}


decompiled_code:
__int64 __fastcall StrList_app(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 8) = a2;
return a1;
}

original_code:
static StrList_t *StrList_app(StrList_t *list1, StrList_t *list2) {
   list1->next = list2;
   return list1;
}

canonical_original_code:
static struct StrList_t *StrList_app(struct StrList_t *list1, struct StrList_t *list2) {
   list1->next = list2;
   return list1;
}

return_type: struct StrList_t { char *str; struct StrList_t *next; } *


typeToString

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

result = a2;
if ( a1 == 2 )
{
strcpy(a2, "char");
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
strcpy(a2, "text");
}
else if ( a1 )
{
strcpy(a2, "double");
}
else
{
*(_DWORD *)a2 = 7630441;
}
return result;
}

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

result = a2;
if ( a1 == 2 )
{
strcpy(a2, "char");
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
strcpy(a2, "text");
}
else if ( a1 )
{
strcpy(a2, "double");
}
else
{
*(_DWORD *)a2 = 7630441;
}
return result;
}

original_code:
char *typeToString(enum data_type type, char *buf) {
   switch (type) {
      case TYPE_INT:
         sprintf(buf, "int");
         break;
      case TYPE_DOUBLE:
         sprintf(buf, "double");
         break;
      case TYPE_CHAR:
         sprintf(buf, "char");
         break;
      case TYPE_TEXT:
         sprintf(buf, "text");
         break;
   }
   return buf;
}

variable_types: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }

variable_types:
buf
char *


decompiled_code:
int __fastcall StrList_print(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
printf("%s", *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
putchar(91);
if ( a1 )
{
while ( 1 )
{
printf("%s", *(const char **)v1);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
break;
printf(", ");
}
}
return putchar(93);
}

original_code:
void StrList_print(StrList_t *list) {
   int first = 1;
   printf("[");
   while (list) {
      if (first) first=0; else printf(", ");
      printf("%s", list->str);
      list = list->next;
   }
   printf("]");
}

canonical_original_code:
void StrList_print(struct StrList_t *list) {
   int first = 1;
   printf("[");
   while (list) {
      if (first) first=0; else printf(", ");
      printf("%s", list->str);
      list = list->next;
   }
   printf("]");
}

variable_types: struct StrList_t { char *str; struct StrList_t *next; } *


upInd

decompiled_code:
int upInd()
{
++ind;
return putchar(10);
}

canonical_decompiled_code:
int func5()
{
++ind;
return putchar(10);
}

original_code:
void upInd() {
   ind++;
   printf("\n");
}

canonical_original_code:
void upInd() {
   ind++;
   printf("\n");
}


downInd

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

--ind;
putchar(10);
result = ind;
if ( ind < 0 )
result = printf("error, ind is < 0");
return result;
}

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

--ind;
putchar(10);
result = ind;
if ( ind < 0 )
result = printf("error, ind is < 0");
return result;
}

original_code:
void downInd() {
   ind--;
   printf("\n");
   if (ind < 0) printf("error, ind is < 0");
}


decompiled_code:
int indent_print(char *format, ...)
{
int v1; // ebx
size_t v2; // rax
bool v3; // cc
gcc_va_list arg; // [rsp+8h] [rbp-1470h] BYREF
char s[5008]; // [rsp+20h] [rbp-1458h] BYREF

v1 = 0;
if ( ind > 0 )
{
do
{
while ( !v1 )
{
v1 = 1;
strcpy(s, "\t");
if ( ind <= 1 )
goto LABEL_6;
}
++v1;
v2 = strlen(s);
v3 = ind <= v1;
*(_WORD *)&s[v2] = 9;
}
while ( !v3 );
}
else
{
ind = 0;
}
LABEL_6:
va_start(arg, format);
vsnprintf(&s[ind], 0x1388uLL, format, arg);
fputs(s, stdout);
return fflush(stdout);
}

canonical_decompiled_code:
int func7(char *format, ...)
{
int v1; // ebx
size_t v2; // rax
bool v3; // cc
gcc_va_list arg; // [rsp+8h] [rbp-1470h] BYREF
char s[5008]; // [rsp+20h] [rbp-1458h] BYREF

v1 = 0;
if ( ind > 0 )
{
do
{
while ( !v1 )
{
v1 = 1;
strcpy(s, "\t");
if ( ind <= 1 )
goto LABEL_6;
}
++v1;
v2 = strlen(s);
v3 = ind <= v1;
*(_WORD *)&s[v2] = 9;
}
while ( !v3 );
}
else
{
ind = 0;
}
LABEL_6:
va_start(arg, format);
vsnprintf(&s[ind], 0x1388uLL, format, arg);
fputs(s, stdout);
return fflush(stdout);
}

original_code:
void indent_print(const char *format,...)
{
   int i;
   va_list argptr;
   char buffer[5000];
   if (ind < 1) ind = 0;
   for (i=0; i<ind; ++i) {
      if (i == 0)
         sprintf(buffer, "\t");
      else
         strcat(buffer, "\t");
   }
   __builtin_va_start(argptr,format);
   vsnprintf(buffer + ind, 5000, format, argptr);
   __builtin_va_end(argptr);
   fputs(buffer, stdout);
   fflush(stdout);
}

canonical_original_code:
void indent_print(char *format, ...)
{
   int i;
   __builtin_va_list argptr;
   char buffer[5000];
   if (ind < 1) ind = 0;
   for (i=0; i<ind; ++i) {
      if (i == 0)
         sprintf(buffer, "\t");
      else
         strcat(buffer, "\t");
   }
   __builtin_va_start(argptr,format);
   vsnprintf(buffer + ind, 5000, format, argptr);
   __builtin_va_end(argptr);
   fputs(buffer, stdout);
   fflush(stdout);
}

variable_types:
format
char *

variable_types:
buffer
char [5000]


decompiled_code:
__int64 __fastcall StrList_append(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 )
return a2;
v2 = StrList_append(*(_QWORD *)(a1 + 8));
return StrList_app(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 )
return a2;
v2 = func8(*(_QWORD *)(a1 + 8));
return func0(a1, v2);
}

original_code:
StrList_t *StrList_append(StrList_t *list1, StrList_t *list2) {
   if (!list1) return list2;
   return StrList_app(list1, StrList_append(list1->next, list2));
}

canonical_original_code:
struct StrList_t *StrList_append(struct StrList_t *list1, struct StrList_t *list2) {
   if (!list1) return list2;
   return StrList_app(list1, StrList_append(list1->next, list2));
}

user_defined_types: struct StrList_t { char *str; struct StrList_t *next; }


decompiled_code:
__int64 __fastcall app_col(__int64 a1, __int64 a2)
{
*(_QWORD *)(a1 + 32) = a2;
return a1;
}

original_code:
static Column_t *app_col(Column_t *col1, Column_t *col2) {
   col1->next = col2;
   return col1;
}

canonical_original_code:
static struct Column_t *app_col(struct Column_t *col1, struct Column_t *col2) {
   col1->next = col2;
   return col1;
}

return_type: struct Column_t { char *name; enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } type; struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *default_val; unsigned int size; struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *check; } constraint; struct Constraint_t *next; } *constraints; unsigned long offset; struct Column_t *next; } *

user_defined_types: struct Column_t { char *name; enum data_type type; struct Constraint_t *constraints; unsigned long offset; struct Column_t *next; }

user_defined_types: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

user_defined_types: struct Condition_t { enum CondType t; union { struct CondComp comp; struct CondBinary binary; struct CondUnary unary; struct CondIn in; } cond; }

user_defined_types: struct CondComp { struct Expression_s *expr1; }

user_defined_types: struct Expression_s { enum ExprType t; union { struct ExprTerm term; struct ExprBinary binary; struct ExprUnary unary; } expr; char *alias; struct Expression_s *next; }

user_defined_types: struct ExprTerm { enum TermType t; union { char *id; struct Literal_t *val; struct ColumnReference_t *ref; struct Func f; }; }

user_defined_types: struct Func { enum FuncType t; struct Expression_s *expr; }


decompiled_code:
void __fastcall deleteConstraint_ts(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdx

if ( a1 )
{
v1 = a1;
do
{
while ( 1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 32);
if ( *(_DWORD *)v2 != 4 )
break;
Literal_free(*(_QWORD *)(v2 + 8));
if ( !v1 )
return;
}
if ( *(_DWORD *)v2 == 6 )
Condition_free(*(_QWORD *)(v2 + 8));
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdx

if ( a1 )
{
v1 = a1;
do
{
while ( 1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 32);
if ( *(_DWORD *)v2 != 4 )
break;
Literal_free(*(_QWORD *)(v2 + 8));
if ( !v1 )
return;
}
if ( *(_DWORD *)v2 == 6 )
Condition_free(*(_QWORD *)(v2 + 8));
}
while ( v1 );
}
}

original_code:
static void deleteConstraint_ts(Constraint_t *constraint) {
   if (constraint) {
      Constraint_t *next = constraint->next;
      switch (constraint->t) {
         case CONS_DEFAULT:
            Literal_free(constraint->constraint.default_val);
            break;
         case CONS_CHECK:
            Condition_free(constraint->constraint.check);
            break;
         default:
            break;
      }
      deleteConstraint_ts(next);
   }
}

canonical_original_code:
static void deleteConstraint_ts(struct Constraint_t *constraint) {
   if (constraint) {
      struct Constraint_t *next = constraint->next;
      switch (constraint->t) {
         case CONS_DEFAULT:
            Literal_free(constraint->constraint.default_val);
            break;
         case CONS_CHECK:
            Condition_free(constraint->constraint.check);
            break;
         default:
            break;
      }
      deleteConstraint_ts(next);
   }
}

variable_types: struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *default_val; unsigned int size; struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *check; } constraint; struct Constraint_t *next; } *


NotNull

decompiled_code:
void *NotNull()
{
return calloc(1uLL, 0x28uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(1uLL, 0x28uLL);
}

original_code:
Constraint_t *NotNull(void) {
   Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_NOT_NULL;
   return con;
}

canonical_original_code:
struct Constraint_t *NotNull() {
   struct Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_NOT_NULL;
   return con;
}

return_type: struct Constraint_t { enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 } t; union { struct ForeignKeyRef_t { char *col_name; } ref; struct Literal_t { enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 } t; union LitVal { int ival; double dval; char cval; char *strval; } val; struct Literal_t *next; } *default_val; unsigned int size; struct Condition_t { enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 } t; union { struct CondComp { struct Expression_s { enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 } t; union { struct ExprTerm { enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 } t; union { char *id; struct Literal_t *val; struct ColumnReference_t { char *tableName; } *ref; struct Func { enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 } t; struct Expression_s *expr; } f; }; } term; struct ExprBinary { struct Expression_s *expr1; } binary; struct ExprUnary { struct Expression_s *expr; } unary; } expr; char *alias; struct Expression_s *next; } *expr1; } comp; struct CondBinary { struct Condition_t *cond1; } binary; struct CondUnary { struct Condition_t *cond; } unary; struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; } in; } cond; } *check; } constraint; struct Constraint_t *next; } *


AutoIncrement

decompiled_code:
_DWORD *AutoIncrement()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x28uLL);
*result = 5;
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x28uLL);
*result = 5;
return result;
}

original_code:
Constraint_t *AutoIncrement(void) {
   Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_AUTO_INCREMENT;
   return con;
}

canonical_original_code:
struct Constraint_t *AutoIncrement() {
   struct Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_AUTO_INCREMENT;
   return con;
}

user_defined_types: enum constraint_type { CONS_NOT_NULL=0, CONS_UNIQUE=1, CONS_PRIMARY_KEY=2, CONS_FOREIGN_KEY=3, CONS_DEFAULT=4, CONS_AUTO_INCREMENT=5, CONS_CHECK=6, CONS_SIZE=7 }

user_defined_types: struct ForeignKeyRef_t { char *col_name; }

user_defined_types: enum CondType { RA_COND_EQ=0, RA_COND_LT=1, RA_COND_GT=2, RA_COND_LEQ=3, RA_COND_GEQ=4, RA_COND_AND=5, RA_COND_OR=6, RA_COND_NOT=7, RA_COND_IN=8 }

user_defined_types: struct CondBinary { struct Condition_t *cond1; }

user_defined_types: struct CondUnary { struct Condition_t *cond; }

user_defined_types: struct CondIn { struct Expression_s *expr; struct Literal_t *values_list; }

user_defined_types: enum ExprType { EXPR_TERM=0, EXPR_PLUS=1, EXPR_MINUS=2, EXPR_MULTIPLY=3, EXPR_DIVIDE=4, EXPR_CONCAT=5, EXPR_NEG=6 }

user_defined_types: struct ExprBinary { struct Expression_s *expr1; }

user_defined_types: struct ExprUnary { struct Expression_s *expr; }

user_defined_types: enum TermType { TERM_LITERAL=0, TERM_ID=1, TERM_NULL=2, TERM_COLREF=3, TERM_FUNC=4 }

user_defined_types: struct ColumnReference_t { char *tableName; }

user_defined_types: enum FuncType { FUNC_MAX=0, FUNC_MIN=1, FUNC_COUNT=2, FUNC_AVG=3, FUNC_SUM=4 }


PrimaryKey

decompiled_code:
_DWORD *PrimaryKey()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x28uLL);
*result = 2;
return result;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x28uLL);
*result = 2;
return result;
}

original_code:
Constraint_t *PrimaryKey(void) {
   Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_PRIMARY_KEY;
   return con;
}

canonical_original_code:
struct Constraint_t *PrimaryKey() {
   struct Constraint_t *con = (Constraint_t *)calloc(1, sizeof(Constraint_t));
   con->t = CONS_PRIMARY_KEY;
   return con;
}

user_defined_types: struct Constraint_t { enum constraint_type t; union { struct ForeignKeyRef_t ref; struct Literal_t *default_val; unsigned int size; struct Condition_t *check; } constraint; struct Constraint_t *next; }

user_defined_types: struct Literal_t { enum data_type t; union LitVal val; struct Literal_t *next; }

user_defined_types: struct Condition_t { enum CondType t; union { struct CondComp comp; struct CondBinary binary; struct CondUnary unary; struct CondIn in; } cond; }

user_defined_types: enum data_type { TYPE_INT=0, TYPE_DOUBLE=1, TYPE_CHAR=2, TYPE_TEXT=3 }

user_defined_types: union LitVal { int ival; double dval; char cval; char *strval; }