push

decompiled_code:
__int64 __fastcall push(__int64 *a1, int a2)
{
__int64 v2; // rbp
__int64 result; // rax
int *v4; // rbx
char *v5; // r8
int *v6; // rbx
char *v7; // r8
_QWORD *v8; // rax
int *v9; // rbx
char *v10; // r8

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( *(_BYTE *)(v2 + 4) )
{
v8 = malloc(0x18uLL);
if ( v8 )
{
v8[2] = 0LL;
v8[1] = v2;
*(_DWORD *)v8 = a2;
*((_BYTE *)v8 + 4) = 1;
*(_QWORD *)(v2 + 16) = v8;
*a1 = (__int64)v8;
result = 0LL;
}
else
{
v9 = __errno_location();
v10 = "None";
if ( *v9 )
v10 = strerror(*v9);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 50LL, v10);
*v9 = 0;
result = 0xFFFFFFFFLL;
}
}
else
{
*(_DWORD *)v2 = a2;
*(_BYTE *)(v2 + 4) = 1;
result = 0LL;
}
}
else
{
v6 = __errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 43LL, v7);
*v6 = 0;
result = 0xFFFFFFFFLL;
}
}
else
{
v4 = __errno_location();
v5 = "None";
if ( *v4 )
v5 = strerror(*v4);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 40LL, v5);
*v4 = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1, int a2)
{
__int64 v2; // rbp
__int64 result; // rax
int *v4; // rbx
char *v5; // r8
int *v6; // rbx
char *v7; // r8
_QWORD *v8; // rax
int *v9; // rbx
char *v10; // r8

if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
if ( *(_BYTE *)(v2 + 4) )
{
v8 = malloc(0x18uLL);
if ( v8 )
{
v8[2] = 0LL;
v8[1] = v2;
*(_DWORD *)v8 = a2;
*((_BYTE *)v8 + 4) = 1;
*(_QWORD *)(v2 + 16) = v8;
*a1 = (__int64)v8;
result = 0LL;
}
else
{
v9 = __errno_location();
v10 = "None";
if ( *v9 )
v10 = strerror(*v9);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 50LL, v10);
*v9 = 0;
result = 0xFFFFFFFFLL;
}
}
else
{
*(_DWORD *)v2 = a2;
*(_BYTE *)(v2 + 4) = 1;
result = 0LL;
}
}
else
{
v6 = __errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 43LL, v7);
*v6 = 0;
result = 0xFFFFFFFFLL;
}
}
else
{
v4 = __errno_location();
v5 = "None";
if ( *v4 )
v5 = strerror(*v4);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 40LL, v5);
*v4 = 0;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int push(linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 40, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 43, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     if(!_el->set) {
   _el->val = i;
   _el->set = 1;
     } else {
   linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 50, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->prev = ((void *)0);
   el_new->next = _el;
   el_new->val = i;
   el_new->set = 1;
   _el->prev = el_new;
   *el = el_new;
     }
     return 0;
error:
     return -1;
}

canonical_original_code:
int push(struct linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 40, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 43, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     if(!_el->set) {
   _el->val = i;
   _el->set = 1;
     } else {
   struct linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 50, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->prev = ((void *)0);
   el_new->next = _el;
   el_new->val = i;
   el_new->set = 1;
   _el->prev = el_new;
   *el = el_new;
     }
     return 0;
error:
     return -1;
}

variable_types: struct linked_element { int val; _Bool set; struct linked_element *next; } **


repo: pcx/misc

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

for ( result = a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

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

for ( result = a1; result && *(_QWORD *)(result + 8); result = *(_QWORD *)(result + 8) )
;
return result;
}

original_code:
linked_element *get_tail(linked_element *el)
{
     while(1) {
   if(el && el->next) {
        el = el->next;
   } else {
        return el;
   }
     }
}

canonical_original_code:
struct linked_element *get_tail(struct linked_element *el)
{
     while(1) {
   if(el && el->next) {
        el = el->next;
   } else {
        return el;
   }
     }
}

variable_types:
el
struct linked_element *

return_type: struct linked_element { int val; _Bool set; struct linked_element *next; } *


inject

decompiled_code:
__int64 __fastcall inject(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rbx
_QWORD *v5; // rax
__int64 result; // rax
int *v7; // rbx
char *v8; // r8
int *v9; // rbx
char *v10; // r8
int *v11; // rbx
char *v12; // r8
_QWORD *v13; // rax

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
v3 = get_tail(v2);
v4 = v3;
if ( v3 )
{
if ( !*(_BYTE *)(v3 + 4) )
{
*(_DWORD *)v3 = a2;
*(_BYTE *)(v3 + 4) = 1;
return 0LL;
}
v5 = malloc(0x18uLL);
if ( v5 )
{
v5[1] = 0LL;
*(_DWORD *)v5 = a2;
*((_BYTE *)v5 + 4) = 1;
v5[2] = v4;
*(_QWORD *)(v4 + 8) = v5;
return 0LL;
}
}
else
{
v13 = malloc(0x18uLL);
if ( v13 )
{
v13[1] = 0LL;
*(_DWORD *)v13 = a2;
*((_BYTE *)v13 + 4) = 1;
v13[2] = 0LL;
return 0LL;
}
}
v11 = __errno_location();
v12 = "None";
if ( *v11 )
v12 = strerror(*v11);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 97LL, v12);
*v11 = 0;
result = 1LL;
}
else
{
v9 = __errno_location();
v10 = "None";
if ( *v9 )
v10 = strerror(*v9);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 88LL, v10);
*v9 = 0;
result = 1LL;
}
}
else
{
v7 = __errno_location();
v8 = "None";
if ( *v7 )
v8 = strerror(*v7);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 85LL, v8);
*v7 = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1, int a2)
{
__int64 v2; // rdi
__int64 v3; // rax
__int64 v4; // rbx
_QWORD *v5; // rax
__int64 result; // rax
int *v7; // rbx
char *v8; // r8
int *v9; // rbx
char *v10; // r8
int *v11; // rbx
char *v12; // r8
_QWORD *v13; // rax

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
v3 = func11(v2);
v4 = v3;
if ( v3 )
{
if ( !*(_BYTE *)(v3 + 4) )
{
*(_DWORD *)v3 = a2;
*(_BYTE *)(v3 + 4) = 1;
return 0LL;
}
v5 = malloc(0x18uLL);
if ( v5 )
{
v5[1] = 0LL;
*(_DWORD *)v5 = a2;
*((_BYTE *)v5 + 4) = 1;
v5[2] = v4;
*(_QWORD *)(v4 + 8) = v5;
return 0LL;
}
}
else
{
v13 = malloc(0x18uLL);
if ( v13 )
{
v13[1] = 0LL;
*(_DWORD *)v13 = a2;
*((_BYTE *)v13 + 4) = 1;
v13[2] = 0LL;
return 0LL;
}
}
v11 = __errno_location();
v12 = "None";
if ( *v11 )
v12 = strerror(*v11);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/linked_list.c", 97LL, v12);
*v11 = 0;
result = 1LL;
}
else
{
v9 = __errno_location();
v10 = "None";
if ( *v9 )
v10 = strerror(*v9);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty pointer to linked_element.\n", "src/linked_list.c", 88LL, v10);
*v9 = 0;
result = 1LL;
}
}
else
{
v7 = __errno_location();
v8 = "None";
if ( *v7 )
v8 = strerror(*v7);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 85LL, v8);
*v7 = 0;
result = 1LL;
}
return result;
}

original_code:
int inject(linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 85, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 88, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *tail_element = get_tail(_el);
     if(tail_element && !tail_element->set) {
   tail_element->val = i;
   tail_element->set = 1;
   return 0;
     } else {
   linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 97, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->next = ((void *)0);
   el_new->val = i;
   el_new->set = 1;
   if(!tail_element) {
        el_new->prev = ((void *)0);
        tail_element = el_new;
   } else {
        el_new->prev = tail_element;
        tail_element->next = el_new;
   }
   return 0;
     }
error:
     return 1;
}

canonical_original_code:
int inject(struct linked_element **el, int i)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 85, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty pointer to linked_element." "\n", "src/linked_list.c", 88, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *tail_element = get_tail(_el);
     if(tail_element && !tail_element->set) {
   tail_element->val = i;
   tail_element->set = 1;
   return 0;
     } else {
   struct linked_element *el_new = malloc(sizeof (linked_element));
   if(!((el_new))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/linked_list.c", 97, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
   el_new->next = ((void *)0);
   el_new->val = i;
   el_new->set = 1;
   if(!tail_element) {
        el_new->prev = ((void *)0);
        tail_element = el_new;
   } else {
        el_new->prev = tail_element;
        tail_element->next = el_new;
   }
   return 0;
     }
error:
     return 1;
}

variable_types: i int

variable_types: struct linked_element { int val; _Bool set; struct linked_element *next; } *

return_type: int


pop

decompiled_code:
__int64 __fastcall pop(_BYTE **a1)
{
_BYTE *v1; // rax
unsigned int v2; // ebx
int *v4; // rbx
char *v5; // r8
int *v6; // rbx
char *v7; // r8
int *v8; // rbx
char *v9; // r8

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
if ( v1[4] )
{
v2 = *(_DWORD *)v1;
*a1 = (_BYTE *)*((_QWORD *)v1 + 1);
free(v1);
}
else
{
v8 = __errno_location();
v9 = "None";
if ( *v8 )
v9 = strerror(*v8);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) _el->set should not be false. Something's wrong.\n",
"src/linked_list.c",
130LL,
v9);
*v8 = 0;
v2 = -1;
}
}
else
{
v6 = __errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty ponter to linked_element.\n", "src/linked_list.c", 120LL, v7);
*v6 = 0;
v2 = -1;
}
}
else
{
v4 = __errno_location();
v5 = "None";
if ( *v4 )
v5 = strerror(*v4);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 117LL, v5);
*v4 = 0;
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func13(_BYTE **a1)
{
_BYTE *v1; // rax
unsigned int v2; // ebx
int *v4; // rbx
char *v5; // r8
int *v6; // rbx
char *v7; // r8
int *v8; // rbx
char *v9; // r8

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
if ( v1[4] )
{
v2 = *(_DWORD *)v1;
*a1 = (_BYTE *)*((_QWORD *)v1 + 1);
free(v1);
}
else
{
v8 = __errno_location();
v9 = "None";
if ( *v8 )
v9 = strerror(*v8);
fprintf(
stderr,
"[ERROR] (%s:%d: errno: %s) _el->set should not be false. Something's wrong.\n",
"src/linked_list.c",
130LL,
v9);
*v8 = 0;
v2 = -1;
}
}
else
{
v6 = __errno_location();
v7 = "None";
if ( *v6 )
v7 = strerror(*v6);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Empty ponter to linked_element.\n", "src/linked_list.c", 120LL, v7);
*v6 = 0;
v2 = -1;
}
}
else
{
v4 = __errno_location();
v5 = "None";
if ( *v4 )
v5 = strerror(*v4);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Invalid pointer to *linked_element.\n", "src/linked_list.c", 117LL, v5);
*v4 = 0;
v2 = -1;
}
return v2;
}

original_code:
int pop(linked_element **el)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 117, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty ponter to linked_element." "\n", "src/linked_list.c", 120, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     int i = 0;
     if(_el->set) {
   i = _el->val;
   *el = _el->next? _el->next: ((void *)0);
   free(_el);
   return i;
     } else {
   { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "_el->set should not be false. Something's wrong." "\n", "src/linked_list.c", 130, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     }
error:
     return -1;
}

canonical_original_code:
int pop(struct linked_element **el)
{
     if(!(el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Invalid pointer to *linked_element." "\n", "src/linked_list.c", 117, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     struct linked_element *_el = *el;
     if(!(_el)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Empty ponter to linked_element." "\n", "src/linked_list.c", 120, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     int i = 0;
     if(_el->set) {
   i = _el->val;
   *el = _el->next? _el->next: ((void *)0);
   free(_el);
   return i;
     } else {
   { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "_el->set should not be false. Something's wrong." "\n", "src/linked_list.c", 130, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
     }
error:
     return -1;
}

user_defined_types: struct linked_element { int val; _Bool set; struct linked_element *next; }


getFileSize

decompiled_code:
__off_t __fastcall getFileSize(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)fstat(a1, &v2) == -1 )
result = -1LL;
else
result = v2.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func7(int a1)
{
__off_t result; // rax
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func12(a1, &v2) == -1 )
result = -1LL;
else
result = v2.st_size;
return result;
}

original_code:
off_t getFileSize(int fd) {
 struct stat statInfo;
 if (fstat(fd, &statInfo) == -1) {
  return -1;
 }
 return statInfo.st_size;
}

canonical_original_code:
long getFileSize(int fd) {
 struct stat statInfo;
 if (fstat(fd, &statInfo) == -1) {
  return -1;
 }
 return statInfo.st_size;
}

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


setupClient

decompiled_code:
__int64 __fastcall setupClient(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
int *v6; // rax
char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(_bss_start, "getaddrinfo failed: %s\n", v7);
return (unsigned int)-1;
}
v2 = pai;
if ( !pai )
{
LABEL_10:
freeaddrinfo(pai);
fwrite("failed to setup client\n", 1uLL, 0x17uLL, _bss_start);
return (unsigned int)-1;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
LABEL_9:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_10;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v4);
goto LABEL_9;
}
freeaddrinfo(pai);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2)
{
struct addrinfo *v2; // rbx
int v3; // eax
unsigned int v4; // ebp
int *v6; // rax
char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(_bss_start, "getaddrinfo failed: %s\n", v7);
return (unsigned int)-1;
}
v2 = pai;
if ( !pai )
{
LABEL_10:
freeaddrinfo(pai);
fwrite("failed to setup client\n", 1uLL, 0x17uLL, _bss_start);
return (unsigned int)-1;
}
while ( 1 )
{
v3 = socket(v2->ai_family, v2->ai_socktype, v2->ai_protocol);
v4 = v3;
if ( v3 != -1 )
break;
LABEL_9:
v2 = v2->ai_next;
if ( !v2 )
goto LABEL_10;
}
if ( connect(v3, v2->ai_addr, v2->ai_addrlen) == -1 )
{
close(v4);
goto LABEL_9;
}
freeaddrinfo(pai);
return v4;
}

original_code:
int setupClient(const char* address, const char* port) {
 int clientSocket = 0;
 struct addrinfo addrInfo;
 struct addrinfo* result;
 struct addrinfo* resNext;
 memset((void*)&addrInfo, 0, sizeof(struct addrinfo));
 addrInfo.ai_family = 0;
 addrInfo.ai_socktype = SOCK_STREAM;
 int ret = getaddrinfo(address, port, &addrInfo, &result);
 if (ret != 0) {
  fprintf(stderr, "getaddrinfo failed: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 for (resNext = result; resNext != ((void *)0); resNext = resNext->ai_next) {
  clientSocket = socket(resNext->ai_family, resNext->ai_socktype, resNext->ai_protocol);
  if (clientSocket == -1) {
   continue;
  }
  if (connect(clientSocket, resNext->ai_addr, resNext->ai_addrlen) == -1) {
   close(clientSocket);
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if (resNext == ((void *)0)) {
  fprintf(stderr, "failed to setup client\n");
  return -1;
 }
 return clientSocket;
}

canonical_original_code:
int setupClient(char *address, char *port) {
 int clientSocket = 0;
 struct addrinfo addrInfo;
 struct addrinfo *result;
 struct addrinfo *resNext;
 memset((void *)&addrInfo, 0, sizeof(struct addrinfo));
 addrInfo.ai_family = 0;
 addrInfo.ai_socktype = SOCK_STREAM;
 int ret = getaddrinfo(address, port, &addrInfo, &result);
 if (ret != 0) {
  fprintf(stderr, "getaddrinfo failed: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 for (resNext = result; resNext != ((void *)0); resNext = resNext->ai_next) {
  clientSocket = socket(resNext->ai_family, resNext->ai_socktype, resNext->ai_protocol);
  if (clientSocket == -1) {
   continue;
  }
  if (connect(clientSocket, resNext->ai_addr, resNext->ai_addrlen) == -1) {
   close(clientSocket);
   continue;
  }
  break;
 }
 freeaddrinfo(result);
 if (resNext == ((void *)0)) {
  fprintf(stderr, "failed to setup client\n");
  return -1;
 }
 return clientSocket;
}

variable_types:
address
char *

variable_types:
port
char *

variable_types: clientSocket int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: ret int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


getNameInDir

decompiled_code:
const char *__fastcall getNameInDir(const char *a1)
{
const char *v1; // rbx
size_t v2; // rax
int v3; // edx
const char *v4; // rax
const char *v5; // rdx

v1 = a1;
v2 = strlen(a1);
v3 = v2;
v4 = &a1[v2 - 1];
if ( v3 > 0 )
{
v5 = &v4[~(unsigned __int64)(unsigned int)(v3 - 1)];
while ( *v4 != 47 )
{
if ( --v4 == v5 )
return v1;
}
v1 = v4 + 1;
}
return v1;
}

canonical_decompiled_code:
const char *__fastcall func9(const char *a1)
{
const char *v1; // rbx
size_t v2; // rax
int v3; // edx
const char *v4; // rax
const char *v5; // rdx

v1 = a1;
v2 = strlen(a1);
v3 = v2;
v4 = &a1[v2 - 1];
if ( v3 > 0 )
{
v5 = &v4[~(unsigned __int64)(unsigned int)(v3 - 1)];
while ( *v4 != 47 )
{
if ( --v4 == v5 )
return v1;
}
v1 = v4 + 1;
}
return v1;
}

original_code:
char* getNameInDir(char* fileName) {
 int fileNameLength = strlen(fileName);
 char* end = fileName + strlen(fileName) - 1;
 int i = 0;
 for (i = 0; i < fileNameLength; ++i) {
  if (*end == '/') {
   return ++end;
  }
  --end;
 }
 return fileName;
}

canonical_original_code:
char *getNameInDir(char *fileName) {
 int fileNameLength = strlen(fileName);
 char *end = fileName + strlen(fileName) - 1;
 int i = 0;
 for (i = 0; i < fileNameLength; ++i) {
  if (*end == '/') {
   return ++end;
  }
  --end;
 }
 return fileName;
}

variable_types:
fileName
char *

variable_types: fileNameLength int

variable_types:
end
char *

return_type: char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
const char *v5; // rbp
__off_t v6; // r13
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
unsigned __int16 buf[21]; // [rsp+Eh] [rbp-2Ah] BYREF

if ( argc == 4 )
{
v3 = setupClient(argv[1], argv[2]);
if ( v3 != -1 )
{
v4 = open(argv[3], 0);
if ( v4 == -1 )
{
fprintf(_bss_start, "failed to open file %s\n", argv[3]);
close(v3);
v3 = -1;
}
else
{
v5 = getNameInDir(argv[3]);
v6 = getFileSize(v4);
buf[0] = strlen(v5);
if ( write(v3, buf, 2uLL) == -1 || write(v3, v5, buf[0]) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "failed to write to server: %s\n", v9);
close(v3);
close(v4);
v3 = -1;
}
else if ( sendfile(v3, v4, 0LL, v6) == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "failed to send file to server: %s\n", v11);
close(v3);
close(v4);
v3 = -1;
}
else
{
close(v3);
close(v4);
printf("File %s was sent successfully\n", v5);
v3 = 0;
}
}
}
}
else
{
fwrite("Usage: ./client host port file\n", 1uLL, 0x1FuLL, _bss_start);
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er12
const char *v5; // rbp
__off_t v6; // r13
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
unsigned __int16 buf[21]; // [rsp+Eh] [rbp-2Ah] BYREF

if ( argc == 4 )
{
v3 = func8(argv[1], argv[2]);
if ( v3 != -1 )
{
v4 = open(argv[3], 0);
if ( v4 == -1 )
{
fprintf(_bss_start, "failed to open file %s\n", argv[3]);
close(v3);
v3 = -1;
}
else
{
v5 = func9(argv[3]);
v6 = func7(v4);
buf[0] = strlen(v5);
if ( write(v3, buf, 2uLL) == -1 || write(v3, v5, buf[0]) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(_bss_start, "failed to write to server: %s\n", v9);
close(v3);
close(v4);
v3 = -1;
}
else if ( sendfile(v3, v4, 0LL, v6) == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "failed to send file to server: %s\n", v11);
close(v3);
close(v4);
v3 = -1;
}
else
{
close(v3);
close(v4);
printf("File %s was sent successfully\n", v5);
v3 = 0;
}
}
}
}
else
{
fwrite("Usage: ./client host port file\n", 1uLL, 0x1FuLL, _bss_start);
v3 = -1;
}
return v3;
}

original_code:
int main(int argc, char** argv) {
 if (argc != 4) {
  fprintf(stderr, "Usage: ./client host port file\n");
  return -1;
 }
 int clientSocket = setupClient(argv[1], argv[2]);
 if (clientSocket == -1) {
  return -1;
 }
 int fileToSend = open(argv[3], 00);
 if (fileToSend == -1) {
  fprintf(stderr, "failed to open file %s\n", argv[3]);
  close(clientSocket);
  return -1;
 }
 char* nameToSend = getNameInDir(argv[3]);
 off_t fileToSendLength = getFileSize(fileToSend);
 unsigned short nameToSendLength = strlen(nameToSend);
 if (write(clientSocket, &nameToSendLength, sizeof(nameToSendLength)) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (write(clientSocket, nameToSend, nameToSendLength) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (sendfile(clientSocket, fileToSend, ((void *)0), fileToSendLength) == -1) {
  fprintf(stderr, "failed to send file to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 close(clientSocket);
 close(fileToSend);
 printf("File %s was sent successfully\n", nameToSend);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc != 4) {
  fprintf(stderr, "Usage: ./client host port file\n");
  return -1;
 }
 int clientSocket = setupClient(argv[1], argv[2]);
 if (clientSocket == -1) {
  return -1;
 }
 int fileToSend = open(argv[3], 00);
 if (fileToSend == -1) {
  fprintf(stderr, "failed to open file %s\n", argv[3]);
  close(clientSocket);
  return -1;
 }
 char *nameToSend = getNameInDir(argv[3]);
 long fileToSendLength = getFileSize(fileToSend);
 unsigned short nameToSendLength = strlen(nameToSend);
 if (write(clientSocket, &nameToSendLength, sizeof(nameToSendLength)) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (write(clientSocket, nameToSend, nameToSendLength) == -1) {
  fprintf(stderr, "failed to write to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 if (sendfile(clientSocket, fileToSend, ((void *)0), fileToSendLength) == -1) {
  fprintf(stderr, "failed to send file to server: %s\n", strerror((*__errno_location ())));
  close(clientSocket);
  close(fileToSend);
  return -1;
 }
 close(clientSocket);
 close(fileToSend);
 printf("File %s was sent successfully\n", nameToSend);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fileToSend int

variable_types:
nameToSend
char *

variable_types: fileToSendLength long

variable_types:
nameToSendLength
unsigned short


original_code:
int main(void) {
    h5md_file file;
    h5md_particles_group beads;
    h5md_element obs_sin;
    hid_t vls_t;
    herr_t status;
    int i, j;
    double r[16][3];
    int species[16], dims[2];
    double mysin;
    char *boundary[] = {"periodic", "periodic", "none"};
    double edges[3] = {25, 25, 15};
    char *vls_data;
    vls_data = "Custom parameter value";
    H5open();
    file = h5md_create_file("data_use_ch5md.h5", "Pierre de Buyl", ((void *)0), "ch5md.use_h5md", "N/A");
    beads = h5md_create_particles_group(file, "beads");
    vls_t = H5Tcopy((H5open(), H5T_C_S1_g));
    H5Tset_size(vls_t, ((size_t)(-1)));
    dims[0] = 16;
    dims[1] = 3;
    beads.position = h5md_create_time_data(beads.group, "position", 2, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    for (i=0;i<16;i++) {
      r[i][0] = i;
      species[i] = 1;
    }
    h5md_create_box(&beads, 3, boundary, 1, edges, &beads.position);
    beads.species = h5md_create_fixed_data_simple(beads.group, "species", 1, dims, (H5open(), H5T_NATIVE_INT_g), species);
    i = 12345;
    h5md_create_fixed_data_scalar(file.observables, "scalar_dset", (H5open(), H5T_NATIVE_INT_g), &i);
    obs_sin = h5md_create_time_data(file.observables, "sin", 0, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    h5md_create_fixed_data_scalar(file.parameters, "custom_parameter", vls_t, &vls_data);
    for (j=0;j<2;j++) {
      for (i=0;i<16;i++) r[i][0] += 0.1*i*i;
      h5md_append(beads.position, r, j+1, (double) j+1);
      h5md_append(beads.box_edges, edges, j+1, (double) j+1);
      mysin = sin((double) j);
      h5md_append(obs_sin, &mysin, j+1, (double) j+1);
    }
    status = H5Tclose(vls_t);
    h5md_close_element(beads.position);
    h5md_close_file(file);
    H5close();
    return 0;
}

canonical_original_code:
int main() {
    struct h5md_file file;
    struct h5md_particles_group_struct beads;
    struct h5md_element_struct obs_sin;
    long vls_t;
    int status;
    int i; int j;
    double r[16][3];
    int species[16]; int dims[2];
    double mysin;
    char *boundary[] = {"periodic", "periodic", "none"};
    double edges[3] = {25, 25, 15};
    char *vls_data;
    vls_data = "Custom parameter value";
    H5open();
    file = h5md_create_file("data_use_ch5md.h5", "Pierre de Buyl", ((void *)0), "ch5md.use_h5md", "N/A");
    beads = h5md_create_particles_group(file, "beads");
    vls_t = H5Tcopy((H5open(), H5T_C_S1_g));
    H5Tset_size(vls_t, ((unsigned long)(-1)));
    dims[0] = 16;
    dims[1] = 3;
    beads.position = h5md_create_time_data(beads.group, "position", 2, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    for (i=0;i<16;i++) {
      r[i][0] = i;
      species[i] = 1;
    }
    h5md_create_box(&beads, 3, boundary, 1, edges, &beads.position);
    beads.species = h5md_create_fixed_data_simple(beads.group, "species", 1, dims, (H5open(), H5T_NATIVE_INT_g), species);
    i = 12345;
    h5md_create_fixed_data_scalar(file.observables, "scalar_dset", (H5open(), H5T_NATIVE_INT_g), &i);
    obs_sin = h5md_create_time_data(file.observables, "sin", 0, dims, (H5open(), H5T_NATIVE_DOUBLE_g), ((void *)0));
    h5md_create_fixed_data_scalar(file.parameters, "custom_parameter", vls_t, &vls_data);
    for (j=0;j<2;j++) {
      for (i=0;i<16;i++) r[i][0] += 0.1*i*i;
      h5md_append(beads.position, r, j+1, (double) j+1);
      h5md_append(beads.box_edges, edges, j+1, (double) j+1);
      mysin = sin((double) j);
      h5md_append(obs_sin, &mysin, j+1, (double) j+1);
    }
    status = H5Tclose(vls_t);
    h5md_close_element(beads.position);
    h5md_close_file(file);
    H5close();
    return 0;
}

variable_types: struct h5md_file { long id; int version[2]; long particles; long observables; long parameters; }

variable_types: struct h5md_particles_group_struct { long group; struct h5md_element_struct { long group; long step; long time; long value; long datatype; int is_time; int current_step; struct h5md_element_struct *link; struct h5md_particles_group_struct *particles_group; } position; long box; struct h5md_element_struct box_edges; struct h5md_element_struct image; struct h5md_element_struct velocity; struct h5md_element_struct force; struct h5md_element_struct mass; struct h5md_element_struct species; struct h5md_element_struct id; struct h5md_element_struct charge; int local_size_max; }

variable_types: struct h5md_element_struct { long group; long step; long time; long value; long datatype; int is_time; int current_step; struct h5md_element_struct *link; struct h5md_particles_group_struct { long group; struct h5md_element_struct position; long box; struct h5md_element_struct box_edges; struct h5md_element_struct image; struct h5md_element_struct velocity; struct h5md_element_struct force; struct h5md_element_struct mass; struct h5md_element_struct species; struct h5md_element_struct id; struct h5md_element_struct charge; int local_size_max; } *particles_group; }

variable_types: status int

variable_types: i int

variable_types: j int

variable_types:
r
double [16][3]

variable_types:
species
int [16]

variable_types:
dims
int [2]

variable_types: mysin double

variable_types:
boundary
char *[]

variable_types:
edges
double [3]


decompiled_code:
__int64 __fastcall lcs_naive(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
int v6; // er14
__int64 result; // rax

if ( !a3 )
return 0LL;
if ( !a4 )
return 0LL;
if ( *(_BYTE *)(a1 + (int)a3 - 1) == *(_BYTE *)(a2 + (int)a4 - 1) )
return (unsigned int)lcs_naive(a1, a2, a3 - 1, a4 - 1) + 1;
v6 = lcs_naive(a1, a2, a3, a4 - 1);
result = lcs_naive(a1, a2, a3 - 1, a4);
if ( v6 >= (int)result )
result = (unsigned int)v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4)
{
int v6; // er14
__int64 result; // rax

if ( !a3 )
return 0LL;
if ( !a4 )
return 0LL;
if ( *(_BYTE *)(a1 + (int)a3 - 1) == *(_BYTE *)(a2 + (int)a4 - 1) )
return (unsigned int)func7(a1, a2, a3 - 1, a4 - 1) + 1;
v6 = func7(a1, a2, a3, a4 - 1);
result = func7(a1, a2, a3 - 1, a4);
if ( v6 >= (int)result )
result = (unsigned int)v6;
return result;
}

original_code:
int lcs_naive(char* X, char* Y, int m, int n, char** ans)
{
 if (m == 0 || n == 0)
        return 0;
    if(X[m-1] == Y[n-1])
        return 1 + lcs_naive(X, Y, m-1, n-1, ans);
    else
        return ((lcs_naive(X, Y, m, n-1, ans)) > (lcs_naive(X, Y, m-1, n, ans)) ? (lcs_naive(X, Y, m, n-1, ans)) : (lcs_naive(X, Y, m-1, n, ans)));
}

canonical_original_code:
int lcs_naive(char *X, char *Y, int m, int n, char **ans)
{
 if (m == 0 || n == 0)
        return 0;
    if(X[m-1] == Y[n-1])
        return 1 + lcs_naive(X, Y, m-1, n-1, ans);
    else
        return ((lcs_naive(X, Y, m, n-1, ans)) > (lcs_naive(X, Y, m-1, n, ans)) ? (lcs_naive(X, Y, m, n-1, ans)) : (lcs_naive(X, Y, m-1, n, ans)));
}

variable_types:
X
char *

variable_types:
Y
char *

variable_types: m int

variable_types: n int

variable_types:
ans
char **


decompiled_code:
void *__fastcall lcs_malloc(size_t a1)
{
memusage += a1;
return malloc(a1);
}

canonical_decompiled_code:
void *__fastcall func8(size_t a1)
{
memusage += a1;
return malloc(a1);
}

original_code:
void* lcs_malloc (size_t size)
{
    memusage += (long)size;
    return malloc(size);
}

canonical_original_code:
void *lcs_malloc(unsigned long size)
{
    memusage += (long)size;
    return malloc(size);
}

variable_types:
size
unsigned long

return_type: void *


timeit

decompiled_code:
double __fastcall timeit(__int64 (__fastcall *a1)(__int64, __int64, _QWORD, _QWORD, __int64), int a2, __int64 a3, __int64 a4, unsigned int a5, unsigned int a6, __int64 a7)
{
int i; // ebx
double v11; // xmm0_8
unsigned int v13; // [rsp+Ch] [rbp-4Ch]
double v15; // [rsp+18h] [rbp-40h]

getrusage(RUSAGE_SELF, &ruse);
v15 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec));
if ( a2 <= 0 )
{
v13 = 0;
}
else
{
for ( i = 0; i != a2; ++i )
v13 = a1(a3, a4, a5, a6, a7);
}
getrusage(RUSAGE_SELF, &ruse);
v11 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec))
- v15;
printf(
"# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
v13,
(unsigned int)a2,
v11,
v11 / (double)a2);
return v11 / (double)a2;
}

canonical_decompiled_code:
double __fastcall func9(__int64 (__fastcall *a1)(__int64, __int64, _QWORD, _QWORD, __int64), int a2, __int64 a3, __int64 a4, unsigned int a5, unsigned int a6, __int64 a7)
{
int i; // ebx
double v11; // xmm0_8
unsigned int v13; // [rsp+Ch] [rbp-4Ch]
double v15; // [rsp+18h] [rbp-40h]

getrusage(RUSAGE_SELF, &ruse);
v15 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec));
if ( a2 <= 0 )
{
v13 = 0;
}
else
{
for ( i = 0; i != a2; ++i )
v13 = a1(a3, a4, a5, a6, a7);
}
getrusage(RUSAGE_SELF, &ruse);
v11 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec))
- v15;
printf(
"# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
v13,
(unsigned int)a2,
v11,
v11 / (double)a2);
return v11 / (double)a2;
}

original_code:
double timeit( int (*lcs)(char*,char*,int,int,char**),
               int ittr,
               char* s1, char* s2,
               int m, int n,
               char** ans )
{
    double start, end;
    int i=0;
    int numrecurse=0;
    start = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    while( i<ittr ){
        numrecurse = lcs(s1, s2, m, n, ans);
        i++;
    }
    end = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    double avgTime = (end-start)/ittr;
    printf("# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
            numrecurse, ittr, (end-start), avgTime);
    return avgTime;
}

canonical_original_code:
double timeit(int (*lcs)(char *, char *, int, int, char **), int ittr, char *s1, char *s2, int m, int n, char **ans)
{
    double start; double end;
    int i = 0;
    int numrecurse = 0;
    start = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    while( i<ittr ){
        numrecurse = lcs(s1, s2, m, n, ans);
        i++;
    }
    end = (getrusage(RUSAGE_SELF,&ruse), ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec + 1e-6 * (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec));
    double avgTime = (end-start)/ittr;
    printf("# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
            numrecurse, ittr, (end-start), avgTime);
    return avgTime;
}

variable_types: int (*)(char *, char *, int, int, char **)

variable_types: ittr int

variable_types: start double

variable_types: end double

variable_types: numrecurse int

variable_types: avgTime double

return_type: double


canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
memusage += a1;
return malloc(a1);
}


canonical_decompiled_code:
double __fastcall func8(__int64 (__fastcall *a1)(__int64, __int64, _QWORD, _QWORD, __int64), int a2, __int64 a3, __int64 a4, unsigned int a5, unsigned int a6, __int64 a7)
{
int i; // ebx
double v11; // xmm0_8
unsigned int v13; // [rsp+Ch] [rbp-4Ch]
double v15; // [rsp+18h] [rbp-40h]

getrusage(RUSAGE_SELF, &ruse);
v15 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec));
if ( a2 <= 0 )
{
v13 = 0;
}
else
{
for ( i = 0; i != a2; ++i )
v13 = a1(a3, a4, a5, a6, a7);
}
getrusage(RUSAGE_SELF, &ruse);
v11 = (double)(LODWORD(ruse.ru_utime.tv_usec) + LODWORD(ruse.ru_stime.tv_usec)) * 0.000001
+ (double)(LODWORD(ruse.ru_utime.tv_sec) + LODWORD(ruse.ru_stime.tv_sec))
- v15;
printf(
"# of Recursive Calls: %d\nTime for %d runs (in ms):%f\nAverage Time:%f\n",
v13,
(unsigned int)a2,
v11,
v11 / (double)a2);
return v11 / (double)a2;
}

variable_types: i int


debug

decompiled_code:
int __fastcall debug(const char *a1)
{
printf(a1);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
printf(a1);
return fflush(stdout);
}

original_code:
void debug(const char* msg){
    printf(msg);fflush(stdout);
}

canonical_original_code:
void debug(char *msg){
    printf(msg);fflush(stdout);
}

variable_types:
msg
char *

return_type: void


decompiled_code:
int __fastcall debug_printarray(int a1, unsigned int *a2)
{
unsigned int *v2; // rbx

putchar(91);
if ( a1 > 0 )
{
v2 = a2;
do
printf("%d,", *v2++);
while ( v2 != &a2[a1 - 1 + 1] );
}
puts("]");
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func10(int a1, unsigned int *a2)
{
unsigned int *v2; // rbx

putchar(91);
if ( a1 > 0 )
{
v2 = a2;
do
printf("%d,", *v2++);
while ( v2 != &a2[a1 - 1 + 1] );
}
puts("]");
return fflush(stdout);
}

original_code:
void debug_printarray( const int l, const int* a ){
    printf("[");
    for( int i=0; i< l; i++){
        printf("%d,",a[i]);
    }
    printf("]\n");fflush(stdout);
}

canonical_original_code:
void debug_printarray(int l, int *a){
    printf("[");
    for( int i = 0; i< l; i++){
        printf("%d,",a[i]);
    }
    printf("]\n");fflush(stdout);
}

variable_types: l int

variable_types:
a
int *


algorithmA

variable_types:
A
char *

variable_types:
B
char *

variable_types:
L
int ***

variable_types:
LL
int **

variable_types: j int


algorithmB

variable_types: m int

variable_types: n int

variable_types:
K
int **


strsplit

decompiled_code:
void *__fastcall strsplit(int a1, int a2, char *a3, _QWORD *a4, _QWORD *a5)
{
char *v7; // r15
void *v8; // rbp
size_t v9; // rbx
void *v10; // rax

v7 = &a3[a2];
v8 = lcs_malloc(a2 + 1);
*a4 = v8;
memcpy(v8, a3, a2);
*((_BYTE *)v8 + a2) = 0;
v9 = a1 - a2 + 1;
v10 = lcs_malloc(v9);
*a5 = v10;
return memcpy(v10, v7, v9);
}

canonical_decompiled_code:
void *__fastcall func14(int a1, int a2, char *a3, _QWORD *a4, _QWORD *a5)
{
char *v7; // r15
void *v8; // rbp
size_t v9; // rbx
void *v10; // rax

v7 = &a3[a2];
v8 = func7(a2 + 1);
*a4 = v8;
memcpy(v8, a3, a2);
*((_BYTE *)v8 + a2) = 0;
v9 = a1 - a2 + 1;
v10 = func7(v9);
*a5 = v10;
return memcpy(v10, v7, v9);
}

original_code:
void strsplit( int len, int i, char* s, char** front, char** back ) {
    int bl = len-i+1;
    char* bs = s+( i*sizeof(char) );
    *front = (char*)lcs_malloc( (i+1)*sizeof(char) );
    memcpy( *front, s, i*sizeof(char) );
    (*front)[i] = '\0';
    *back = (char*)lcs_malloc( bl*sizeof(char) );
    memcpy( *back, bs, bl*sizeof(char) );
}

canonical_original_code:
void strsplit(int len, int i, char *s, char **front, char **back) {
    int bl = len-i+1;
    char *bs = s+( i*sizeof(char) );
    *front = (char *)lcs_malloc( (i+1)*sizeof(char) );
    memcpy( *front, s, i*sizeof(char) );
    (*front)[i] = '\0';
    *back = (char *)lcs_malloc( bl*sizeof(char) );
    memcpy( *back, bs, bl*sizeof(char) );
}

variable_types: len int

variable_types:
s
char *

variable_types:
front
char **

variable_types:
back
char **

variable_types: bl int

variable_types:
bs
char *


algorithmC

original_code:
int algorithmC( int m, int n, char* A, char* B, char** C ){
    if( n == 0 ){ return 0; }
    if( m == 1 ){
        for(int i=0; i<n; i++){
            if(A[0] == B[i]){
                const char ch[] = { B[i], '\0' };
                strcat(*C, ch);
                break;
            }
        }
        return 0;
    }
    int i = m/2;
    char *A_1i, A_mi1[m-i+1], *A_i1m;
        strsplit( m, i, A, &A_1i, &A_i1m );
        strcpy(A_mi1, A_i1m);
        strrev( A_mi1 );
    char B_n1[n];
        strcpy(B_n1, B);
        strrev( B_n1 );
    int** L = (int**)lcs_malloc( 2 * sizeof(int*) );
    algorithmB( i, n, A_1i, B, &L[0] );
    algorithmB( m-i, n, A_mi1, B_n1, &L[1] );
    int k=0,M=0;
    for(int j=0; j <= n; j++){ M = ((M) > (L[0][j] + L[1][n-j]) ? (M) : (L[0][j] + L[1][n-j])); }
    for(int j=0; j <= n; j++){ if(L[0][j]+L[1][n-j] == M){ k=j; break;} }
    free(L[0]); free(L[1]); free(L);
    char *B_1k, *B_k1n; strsplit( n, k, B, &B_1k, &B_k1n );
    int rec = algorithmC( i, k, A_1i, B_1k, C )
            + algorithmC( m-i, n-k, A_i1m, B_k1n, C );
    free( A_1i ); free( A_i1m );
    free( B_1k ); free( B_k1n );
    return rec+2;
}

canonical_original_code:
int algorithmC(int m, int n, char *A, char *B, char **C){
    if( n == 0 ){ return 0; }
    if( m == 1 ){
        for(int i = 0; i<n; i++){
            if(A[0] == B[i]){
                char ch[] = { B[i], '\0' };
                strcat(*C, ch);
                break;
            }
        }
        return 0;
    }
    int i = m/2;
    char *A_1i; char A_mi1[-1]; char *A_i1m;
        strsplit( m, i, A, &A_1i, &A_i1m );
        strcpy(A_mi1, A_i1m);
        strrev( A_mi1 );
    char B_n1[-1];
        strcpy(B_n1, B);
        strrev( B_n1 );
    int **L = (int**)lcs_malloc( 2 * sizeof(int*) );
    algorithmB( i, n, A_1i, B, &L[0] );
    algorithmB( m-i, n, A_mi1, B_n1, &L[1] );
    int k = 0; int M = 0;
    for(int j = 0; j <= n; j++){ M = ((M) > (L[0][j] + L[1][n-j]) ? (M) : (L[0][j] + L[1][n-j])); }
    for(int j = 0; j <= n; j++){ if(L[0][j]+L[1][n-j] == M){ k=j; break;} }
    free(L[0]); free(L[1]); free(L);
    char *B_1k; char *B_k1n; strsplit( n, k, B, &B_1k, &B_k1n );
    int rec = algorithmC( i, k, A_1i, B_1k, C )
            + algorithmC( m-i, n-k, A_i1m, B_k1n, C );
    free( A_1i ); free( A_i1m );
    free( B_1k ); free( B_k1n );
    return rec+2;
}

variable_types:
C
char **

variable_types: i int

variable_types:
ch
char []

variable_types:
L
int **

variable_types: k int

variable_types: M int

variable_types: rec int


Hirshberg

decompiled_code:
__int64 __fastcall Hirshberg(char *a1, char *a2, int a3, int a4, char **a5)
{
__int64 result; // rax

**a5 = 0;
if ( a3 < a4 )
result = algorithmC(a4, a3, a2, a1, a5);
else
result = algorithmC(a3, a4, a1, a2, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, char *a2, int a3, int a4, char **a5)
{
__int64 result; // rax

**a5 = 0;
if ( a3 < a4 )
result = func15(a4, a3, a2, a1, a5);
else
result = func15(a3, a4, a1, a2, a5);
return result;
}

original_code:
int Hirshberg( char* A, char* B, int m, int n, char** C ){
    int r;
    strcpy(*C, "");
    if( m >= n ) {
        r = algorithmC( m, n, A, B, C );
    }else{
        r = algorithmC( n, m, B, A, C );
    }
    return r;
}

canonical_original_code:
int Hirshberg(char *A, char *B, int m, int n, char **C){
    int r;
    strcpy(*C, "");
    if( m >= n ) {
        r = algorithmC( m, n, A, B, C );
    }else{
        r = algorithmC( n, m, B, A, C );
    }
    return r;
}

variable_types:
A
char *

variable_types:
B
char *

variable_types: r int


timeit

variable_types: int (*)(char *, char *, int, int, char **)

variable_types: ittr int

variable_types: m int

variable_types: n int

variable_types:
ans
char **

variable_types: start double

variable_types: end double

variable_types: numrecurse int

variable_types: avgTime double


original_code:
int lcs_with_memo( char *X, char *Y, int m, int n, int** arr )
{
    if (m == 0 || n == 0) return 0;
    if (arr[m][n]==0){
        if (X[m-1] == Y[n-1])
            arr[m][n] = 1 + lcs_with_memo(X, Y, m-1, n-1, arr);
        else
            arr[m][n] = ((lcs_with_memo(X, Y, m, n-1, arr)) > (lcs_with_memo(X, Y, m-1, n, arr)) ? (lcs_with_memo(X, Y, m, n-1, arr)) : (lcs_with_memo(X, Y, m-1, n, arr)));
    }
    return arr[m][n];
}

canonical_original_code:
int lcs_with_memo(char *X, char *Y, int m, int n, int **arr)
{
    if (m == 0 || n == 0) return 0;
    if (arr[m][n]==0){
        if (X[m-1] == Y[n-1])
            arr[m][n] = 1 + lcs_with_memo(X, Y, m-1, n-1, arr);
        else
            arr[m][n] = ((lcs_with_memo(X, Y, m, n-1, arr)) > (lcs_with_memo(X, Y, m-1, n, arr)) ? (lcs_with_memo(X, Y, m, n-1, arr)) : (lcs_with_memo(X, Y, m-1, n, arr)));
    }
    return arr[m][n];
}

variable_types:
X
char *

variable_types:
Y
char *

variable_types:
arr
int **


decompiled_code:
__int64 __fastcall lcs_memo(__int64 a1, __int64 a2, signed int a3, signed int a4)
{
void **v6; // rax
void **v7; // rbp
signed int v8; // er12
__int64 v9; // rax
void **v10; // rbx
unsigned int v11; // er12
void **ptr; // [rsp+8h] [rbp-50h]

v6 = (void **)lcs_malloc(8LL * (a3 + 1));
ptr = v6;
if ( a3 >= 0 )
{
v7 = v6;
v8 = 0;
do
{
*v7 = lcs_malloc(4LL * (a4 + 1));
if ( a4 >= 0 )
{
v9 = 0LL;
do
{
*(_DWORD *)((char *)*v7 + v9) = 0;
v9 += 4LL;
}
while ( v9 != 4LL * (unsigned int)a4 + 4 );
}
++v8;
++v7;
}
while ( a3 >= v8 );
}
v10 = ptr;
v11 = lcs_with_memo(a1, a2, a3, a4, (__int64)ptr);
if ( a3 > 0 )
{
do
free(*v10++);
while ( v10 != &ptr[a3] );
}
free(ptr);
return v11;
}

original_code:
int lcs_memo( char *X, char *Y, int m, int n, char** ans)
{
    int** arr = (int**)lcs_malloc((m+1) * sizeof(int*));
    for(int i=0; i <= m; i++) {
        arr[i] = (int *)lcs_malloc((n+1) * sizeof(int));
        for(int j=0; j <= n; j++){
            arr[i][j] = 0;
        }
    }
    int res = lcs_with_memo( X, Y, m, n, arr );
    for(int i=0; i < m; i++) { free(arr[i]); }
    free(arr);
    return res;
}

canonical_original_code:
int lcs_memo(char *X, char *Y, int m, int n, char **ans)
{
    int **arr = (int**)lcs_malloc((m+1) * sizeof(int*));
    for(int i = 0; i <= m; i++) {
        arr[i] = (int *)lcs_malloc((n+1) * sizeof(int));
        for(int j = 0; j <= n; j++){
            arr[i][j] = 0;
        }
    }
    int res = lcs_with_memo( X, Y, m, n, arr );
    for(int i = 0; i < m; i++) { free(arr[i]); }
    free(arr);
    return res;
}

variable_types: i int

variable_types: j int

variable_types: res int


decompiled_code:
void __fastcall print_lcs(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // eax

if ( (_DWORD)a3 && (_DWORD)a4 )
{
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 8LL * (int)a3) + 4LL * (int)a4);
if ( v4 == 1 )
{
print_lcs(a1, a2, (unsigned int)(a3 - 1), (unsigned int)(a4 - 1));
}
else if ( v4 == 2 )
{
print_lcs(a1, a2, (unsigned int)(a3 - 1), a4);
}
else
{
print_lcs(a1, a2, a3, (unsigned int)(a4 - 1));
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // eax

if ( (_DWORD)a3 && (_DWORD)a4 )
{
v4 = *(_DWORD *)(*(_QWORD *)(a1 + 8LL * (int)a3) + 4LL * (int)a4);
if ( v4 == 1 )
{
func9(a1, a2, (unsigned int)(a3 - 1), (unsigned int)(a4 - 1));
}
else if ( v4 == 2 )
{
func9(a1, a2, (unsigned int)(a3 - 1), a4);
}
else
{
func9(a1, a2, a3, (unsigned int)(a4 - 1));
}
}
}

original_code:
void print_lcs(int** b, char* X, int i, int j){
    if (i==0 || j==0)
        return;
    if (b[i][j] == 1){
        print_lcs(b,X,i-1,j-1);
    }
    else if(b[i][j] == 2){
        print_lcs(b,X,i-1,j);
    }
    else{
        print_lcs(b,X,i,j-1);
    }
}

canonical_original_code:
void print_lcs(int **b, char *X, int i, int j){
    if (i==0 || j==0)
        return;
    if (b[i][j] == 1){
        print_lcs(b,X,i-1,j-1);
    }
    else if(b[i][j] == 2){
        print_lcs(b,X,i-1,j);
    }
    else{
        print_lcs(b,X,i,j-1);
    }
}

variable_types:
b
int **


variable_types:
c
int **


repo: pdkelly/flvjoin

decompiled_code:
size_t write_flv_header()
{
__int64 ptr; // [rsp+3h] [rbp-15h] BYREF
int v2; // [rsp+Bh] [rbp-Dh]
char v3; // [rsp+Fh] [rbp-9h]

ptr = 0x501564C46LL;
v2 = 9;
v3 = 0;
if ( !quiet )
fprintf(stderr, "Writing FLV header to %s\n", &filepath);
return fwrite(&ptr, 1uLL, 0xDuLL, outfile);
}

canonical_decompiled_code:
size_t func0()
{
__int64 ptr; // [rsp+3h] [rbp-15h] BYREF
int v2; // [rsp+Bh] [rbp-Dh]
char v3; // [rsp+Fh] [rbp-9h]

ptr = 0x501564C46LL;
v2 = 9;
v3 = 0;
if ( !quiet )
fprintf(stderr, "Writing FLV header to %s\n", &filepath);
return fwrite(&ptr, 1uLL, 0xDuLL, outfile);
}

original_code:
static void write_flv_header(void)
{
    const unsigned char header[] = {'F', 'L', 'V', 1, 5, 0, 0, 0, 9, 0, 0, 0, 0};
    if(!quiet)
        fprintf(stderr,"Writing FLV header to %s\n", filepath);
    fwrite( header, 1, sizeof(header), outfile );
    return;
}

canonical_original_code:
static void write_flv_header()
{
    unsigned char header[] = {'F', 'L', 'V', 1, 5, 0, 0, 0, 9, 0, 0, 0, 0};
    if(!quiet)
        fprintf(stderr,"Writing FLV header to %s\n", filepath);
    fwrite( header, 1, sizeof(header), outfile );
    return;
}

variable_types:
header
unsigned char []


decompiled_code:
size_t __fastcall write_output(const void *a1, size_t a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

result = fwrite(a1, 1uLL, a2, outfile);
if ( result != a2 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR while writing to output file %s: %s\n", &filepath, v4);
exit(1);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(const void *a1, size_t a2)
{
size_t result; // rax
int *v3; // rax
char *v4; // rax

result = fwrite(a1, 1uLL, a2, outfile);
if ( result != a2 )
{
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "ERROR while writing to output file %s: %s\n", &filepath, v4);
exit(1);
}
return result;
}

original_code:
static void write_output(unsigned char *buffer, size_t bytes)
{
    if( fwrite(buffer, 1, bytes, outfile) != bytes )
    {
        fprintf(stderr, "ERROR while writing to output file %s: %s\n",
                filepath, strerror((*__errno_location ())));
        exit(1);
    }
    return;
}

canonical_original_code:
static void write_output(unsigned char *buffer, unsigned long bytes)
{
    if( fwrite(buffer, 1, bytes, outfile) != bytes )
    {
        fprintf(stderr, "ERROR while writing to output file %s: %s\n",
                filepath, strerror((*__errno_location ())));
        exit(1);
    }
    return;
}

variable_types:
buffer
unsigned char *

variable_types:
bytes
unsigned long


decompiled_code:
int __fastcall write_packet(__int64 a1, int a2)
{
unsigned int v2; // ebp
int result; // eax
const void *v4; // rax
const void *v5; // rax
const void *v6; // rax
const void *v7; // rax

if ( !seq_header_written_9 && (_QWORD)xmmword_E70 && *(_BYTE *)a1 == 9 )
{
seq_header_written_9 = 1;
dword_E68 = *(_DWORD *)(a1 + 8);
write_packet(&seq_header_pkt);
}
v2 = *(_DWORD *)(a1 + 8) + a2;
*(_DWORD *)(a1 + 8) = v2;
if ( *(_BYTE *)a1 == 8 && (result = v2, v2 <= last_audio_timestamp) )
{
if ( !quiet )
result = fprintf(
stderr,
"Dropping overlapping audio packet with timestamp %d; last audio packet at %d\n",
v2,
last_audio_timestamp);
}
else
{
write_output((const void *)a1, 1uLL);
v4 = (const void *)format_ui24(*(unsigned int *)(a1 + 4));
write_output(v4, 3uLL);
v5 = (const void *)format_ui24(*(unsigned int *)(a1 + 8));
write_output(v5, 4uLL);
v6 = (const void *)format_ui24(*(unsigned int *)(a1 + 12));
write_output(v6, 3uLL);
write_output(*(const void **)(a1 + 16), *(unsigned int *)(a1 + 4));
v7 = (const void *)format_ui32(*(unsigned int *)(a1 + 24));
write_output(v7, 4uLL);
if ( *(_BYTE *)a1 == 9 )
{
last_video_timestamp = *(_DWORD *)(a1 + 8);
}
else if ( *(_BYTE *)a1 == 8 )
{
last_audio_timestamp = *(unsigned int *)(a1 + 8);
}
result = *(_DWORD *)(a1 + 4);
last_packet_size = result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // ebp
int result; // eax
const void *v4; // rax
const void *v5; // rax
const void *v6; // rax
const void *v7; // rax

if ( !seq_header_written_9 && (_QWORD)xmmword_E70 && *(_BYTE *)a1 == 9 )
{
seq_header_written_9 = 1;
dword_E68 = *(_DWORD *)(a1 + 8);
func2(&seq_header_pkt);
}
v2 = *(_DWORD *)(a1 + 8) + a2;
*(_DWORD *)(a1 + 8) = v2;
if ( *(_BYTE *)a1 == 8 && (result = v2, v2 <= last_audio_timestamp) )
{
if ( !quiet )
result = fprintf(
stderr,
"Dropping overlapping audio packet with timestamp %d; last audio packet at %d\n",
v2,
last_audio_timestamp);
}
else
{
func1((const void *)a1, 1uLL);
v4 = (const void *)format_ui24(*(unsigned int *)(a1 + 4));
func1(v4, 3uLL);
v5 = (const void *)format_ui24(*(unsigned int *)(a1 + 8));
func1(v5, 4uLL);
v6 = (const void *)format_ui24(*(unsigned int *)(a1 + 12));
func1(v6, 3uLL);
func1(*(const void **)(a1 + 16), *(unsigned int *)(a1 + 4));
v7 = (const void *)format_ui32(*(unsigned int *)(a1 + 24));
func1(v7, 4uLL);
if ( *(_BYTE *)a1 == 9 )
{
last_video_timestamp = *(_DWORD *)(a1 + 8);
}
else if ( *(_BYTE *)a1 == 8 )
{
last_audio_timestamp = *(unsigned int *)(a1 + 8);
}
result = *(_DWORD *)(a1 + 4);
last_packet_size = result;
}
return result;
}

original_code:
static void write_packet(struct FLVpacket *packet, long file_start_timestamp)
{
    static char seq_header_written;
    if(!seq_header_written && seq_header_pkt.data && packet->type == 9)
    {
        seq_header_written = 1;
        seq_header_pkt.timestamp = packet->timestamp;
        write_packet(&seq_header_pkt, file_start_timestamp);
    }
    packet->timestamp += file_start_timestamp;
    if( packet->type == 8 && (long)packet->timestamp <= last_audio_timestamp )
    {
        if(!quiet)
            fprintf(stderr, "Dropping overlapping audio packet with timestamp %d; last audio packet at %d\n",
                    packet->timestamp, (unsigned int)last_audio_timestamp);
        return;
    }
    write_output(&packet->type, 1);
    write_output(format_ui24(packet->datasize), 3);
    write_output(format_ui24(packet->timestamp), 4);
    write_output(format_ui24(packet->streamid), 3);
    write_output(packet->data, packet->datasize);
    write_output(format_ui32(packet->backptr), 4);
    if( packet->type == 9 )
        last_video_timestamp = packet->timestamp;
    if( packet->type == 8 )
        last_audio_timestamp = packet->timestamp;
    last_packet_size = packet->datasize;
    return;
}

variable_types: struct FLVpacket { unsigned char type; unsigned int datasize; unsigned char *data; unsigned int backptr; } *


decompiled_code:
void close_output()
{
int *v0; // rax
char *v1; // rax

if ( outfile != stdout )
{
if ( fclose(outfile) )
{
v0 = _errno_location();
v1 = strerror(*v0);
fprintf(stderr, "ERROR while closing output file %s: %s\n", &filepath, v1);
exit(1);
}
}
}

canonical_decompiled_code:
void func3()
{
int *v0; // rax
char *v1; // rax

if ( outfile != stdout )
{
if ( fclose(outfile) )
{
v0 = _errno_location();
v1 = strerror(*v0);
fprintf(stderr, "ERROR while closing output file %s: %s\n", &filepath, v1);
exit(1);
}
}
}

original_code:
static void close_output(void)
{
    if( outfile != stdout && fclose(outfile) != 0 )
    {
        fprintf(stderr, "ERROR while closing output file %s: %s\n",
                filepath, strerror((*__errno_location ())));
        exit(1);
    }
    return;
}

canonical_original_code:
static void close_output()
{
    if( outfile != stdout && fclose(outfile) != 0 )
    {
        fprintf(stderr, "ERROR while closing output file %s: %s\n",
                filepath, strerror((*__errno_location ())));
        exit(1);
    }
    return;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
__int64 v5; // rax
char *v6; // rax
int v7; // eax
__int64 v8; // rsi
double v10; // [rsp+0h] [rbp-C28h] BYREF
double v11; // [rsp+8h] [rbp-C20h] BYREF
struct stat v12[7]; // [rsp+10h] [rbp-C18h] BYREF
char s[2072]; // [rsp+410h] [rbp-818h] BYREF

filepath = 0;
v3 = 32000;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "o:f:b:ndqh");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'b':
v3 = atoi(optarg);
break;
case 'd':
exit(0);
case 'f':
frame_interval = (int)(1000.0 / atof(optarg) + 0.5);
break;
case 'n':
no_meta = 1;
break;
case 'o':
strncpy(&filepath, optarg, 0x400uLL);
break;
case 'q':
quiet = 1;
break;
default:
fprintf(stderr, "%s v%s\n", "flvjoin", "0.92");
fwrite("\nSynopsis: Reads a list of FLV files (with optional in-point and out-point)\n", 1uLL, 0x4CuLL, stderr);
fwrite("from standard input and joins them together into one larger FLV file.\n\n", 1uLL, 0x47uLL, stderr);
fprintf(stderr, "Usage: %s -o <filename> [-f <framerate>] [-b <bitrate>] [-n] [-q] [-h]\n\n", "flvjoin");
fwrite(" -o <filename> Output File (- for stdout)\n", 1uLL, 0x2EuLL, stderr);
fprintf(
stderr,
" -f <framerate> Video frame rate in frames per second (default %.2f)\n",
1000.0 / (double)frame_interval);
fprintf(stderr, " -b <bitrate> Audio bitrate in bits per second (default %d)\n", (unsigned int)v3);
fwrite(" -n Don't write metadata to output file\n", 1uLL, 0x37uLL, stderr);
fwrite(" -q Don't display progress information\n", 1uLL, 0x36uLL, stderr);
fwrite(" -h Display this usage message and exit\n", 1uLL, 0x37uLL, stderr);
fputc(10, stderr);
exit(0);
}
}
if ( filepath )
{
if ( !strcmp(&filepath, "-") || stat(&filepath, v12) )
{
open_output("wb");
write_flv_header();
if ( !no_meta )
{
v5 = generate_metadata_packet(outfile);
write_packet(v5, 0);
}
while ( fgets(s, 2048, stdin) )
{
v6 = strchr(s, 10);
if ( v6 )
*v6 = 0;
v7 = _isoc99_sscanf(s, "%1023s %lf %lf", v12, &v10, &v11);
if ( v7 <= 2 )
v11 = *(double *)&LC37;
if ( v7 <= 1 )
v10 = 0.0;
append_file((const char *)v12, (int)(1000.0 * v10 + 0.5), (int)(1000.0 * v11 + 0.5));
}
if ( !no_meta )
{
if ( !quiet )
fwrite("Writing metadata...\n", 1uLL, 0x14uLL, stderr);
if ( (unsigned int)last_video_timestamp < last_audio_timestamp )
v8 = (unsigned int)(last_audio_timestamp + (int)((double)last_packet_size * 1000.0 * 8.0 / (double)v3 + 0.5));
else
v8 = (unsigned int)(frame_interval + last_video_timestamp);
write_metadata(outfile, v8);
}
if ( !quiet )
fprintf(stderr, "Closing output file %s\n", &filepath);
close_output();
exit(0);
}
fprintf(stderr, "ERROR: File %s exists; won't write header.\n", &filepath);
exit(1);
}
fwrite("ERROR: Output file must be specified with the -o option. (Use - for stdout).\n", 1uLL, 0x4DuLL, stderr);
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
__int64 v5; // rax
char *v6; // rax
int v7; // eax
__int64 v8; // rsi
double v10; // [rsp+0h] [rbp-C28h] BYREF
double v11; // [rsp+8h] [rbp-C20h] BYREF
struct stat v12[7]; // [rsp+10h] [rbp-C18h] BYREF
char s[2072]; // [rsp+410h] [rbp-818h] BYREF

filepath = 0;
v3 = 32000;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "o:f:b:ndqh");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'b':
v3 = atoi(optarg);
break;
case 'd':
exit(0);
case 'f':
frame_interval = (int)(1000.0 / atof(optarg) + 0.5);
break;
case 'n':
no_meta = 1;
break;
case 'o':
strncpy(&filepath, optarg, 0x400uLL);
break;
case 'q':
quiet = 1;
break;
default:
fprintf(stderr, "%s v%s\n", "flvjoin", "0.92");
fwrite("\nSynopsis: Reads a list of FLV files (with optional in-point and out-point)\n", 1uLL, 0x4CuLL, stderr);
fwrite("from standard input and joins them together into one larger FLV file.\n\n", 1uLL, 0x47uLL, stderr);
fprintf(stderr, "Usage: %s -o <filename> [-f <framerate>] [-b <bitrate>] [-n] [-q] [-h]\n\n", "flvjoin");
fwrite(" -o <filename> Output File (- for stdout)\n", 1uLL, 0x2EuLL, stderr);
fprintf(
stderr,
" -f <framerate> Video frame rate in frames per second (default %.2f)\n",
1000.0 / (double)frame_interval);
fprintf(stderr, " -b <bitrate> Audio bitrate in bits per second (default %d)\n", (unsigned int)v3);
fwrite(" -n Don't write metadata to output file\n", 1uLL, 0x37uLL, stderr);
fwrite(" -q Don't display progress information\n", 1uLL, 0x36uLL, stderr);
fwrite(" -h Display this usage message and exit\n", 1uLL, 0x37uLL, stderr);
fputc(10, stderr);
exit(0);
}
}
if ( filepath )
{
if ( !strcmp(&filepath, "-") || stat(&filepath, v12) )
{
open_output("wb");
func0();
if ( !no_meta )
{
v5 = generate_metadata_packet(outfile);
func2(v5, 0);
}
while ( fgets(s, 2048, stdin) )
{
v6 = strchr(s, 10);
if ( v6 )
*v6 = 0;
v7 = _isoc99_sscanf(s, "%1023s %lf %lf", v12, &v10, &v11);
if ( v7 <= 2 )
v11 = *(double *)&LC37;
if ( v7 <= 1 )
v10 = 0.0;
func5((const char *)v12, (int)(1000.0 * v10 + 0.5), (int)(1000.0 * v11 + 0.5));
}
if ( !no_meta )
{
if ( !quiet )
fwrite("Writing metadata...\n", 1uLL, 0x14uLL, stderr);
if ( (unsigned int)last_video_timestamp < last_audio_timestamp )
v8 = (unsigned int)(last_audio_timestamp + (int)((double)last_packet_size * 1000.0 * 8.0 / (double)v3 + 0.5));
else
v8 = (unsigned int)(frame_interval + last_video_timestamp);
write_metadata(outfile, v8);
}
if ( !quiet )
fprintf(stderr, "Closing output file %s\n", &filepath);
func3();
exit(0);
}
fprintf(stderr, "ERROR: File %s exists; won't write header.\n", &filepath);
exit(1);
}
fwrite("ERROR: Output file must be specified with the -o option. (Use - for stdout).\n", 1uLL, 0x4DuLL, stderr);
exit(1);
}

original_code:
int main (int argc, char ** argv)
{
    char buffer[2*1024];
    int audio_bitrate = 32000;
    int opt;
    filepath[0] = '\0';
    while ( (opt = getopt(argc, argv, "o:f:b:ndqh")) != -1 )
    {
        switch (opt)
        {
            case 'o':
                strncpy(filepath, optarg, sizeof(filepath));
                break;
            case 'f':
                frame_interval = (int)(0.5 + 1000 / atof(optarg));
                break;
            case 'b':
                audio_bitrate = atoi(optarg);
                break;
            case 'n':
                no_meta = 1;
                break;
            case 'd':
                exit(0);
            case 'q':
                quiet = 1;
                break;
            case 'h':
            default:
                fprintf(stderr,"%s v%s\n", "flvjoin", "0.92");
                fprintf(stderr,"\nSynopsis: Reads a list of FLV files (with optional in-point and out-point)\n");
                fprintf(stderr,"from standard input and joins them together into one larger FLV file.\n\n");
                fprintf(stderr,"Usage: %s -o <filename> [-f <framerate>] [-b <bitrate>] [-n] [-q] [-h]\n\n", "flvjoin");
                fprintf(stderr,"   -o <filename>   Output File (- for stdout)\n");
                fprintf(stderr,"   -f <framerate>  Video frame rate in frames per second (default %.2f)\n", 1000.0 / frame_interval);
                fprintf(stderr,"   -b <bitrate>    Audio bitrate in bits per second (default %d)\n", audio_bitrate);
                fprintf(stderr,"   -n              Don't write metadata to output file\n");
                fprintf(stderr,"   -q              Don't display progress information\n");
                fprintf(stderr,"   -h              Display this usage message and exit\n");
                fprintf(stderr,"\n");
                exit(0);
        }
    }
    if( strlen(filepath) == 0 )
    {
        fprintf(stderr, "ERROR: Output file must be specified with the -o option. (Use - for stdout).\n");
        exit(1);
    }
    {
        struct stat s;
        struct FLVpacket *packet;
        if( strcmp(filepath, "-") != 0 && stat(filepath, &s) == 0 )
        {
            fprintf(stderr,"ERROR: File %s exists; won't write header.\n", filepath);
            exit(1);
        }
        open_output("wb");
        write_flv_header();
        if(!no_meta)
        {
            packet = generate_metadata_packet(outfile);
            write_packet(packet, 0);
        }
    }
    while( fgets(buffer, sizeof(buffer), stdin) )
    {
        int num_params;
        double mark_in, mark_out;
        char infile[1024];
        char *newline = strchr(buffer, '\n');
        if(newline)
            *newline = '\0';
        num_params = sscanf(buffer, "%1023s %lf %lf", infile, &mark_in, &mark_out);
        if(num_params < 3)
            mark_out = 99999;
        if(num_params < 2)
            mark_in = 0;
        append_file(infile, (unsigned int)(0.5 + mark_in*1000), (unsigned int)(0.5 + mark_out*1000));
    }
    if(!no_meta)
    {
        unsigned int duration;
        if(!quiet)
            fprintf(stderr, "Writing metadata...\n");
        if(last_video_timestamp >= last_audio_timestamp)
            duration = last_video_timestamp + frame_interval;
        else
            duration = last_audio_timestamp + (unsigned int)(0.5 + 1000.0 * last_packet_size * 8 / audio_bitrate);
        write_metadata(outfile, duration);
    }
    if( !quiet )
        fprintf(stderr, "Closing output file %s\n", filepath);
    close_output();
    exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
    char buffer[-1];
    int audio_bitrate = 32000;
    int opt;
    filepath[0] = '\0';
    while ( (opt = getopt(argc, argv, "o:f:b:ndqh")) != -1 )
    {
        switch (opt)
        {
            case 'o':
                strncpy(filepath, optarg, sizeof(filepath));
                break;
            case 'f':
                frame_interval = (int)(0.5 + 1000 / atof(optarg));
                break;
            case 'b':
                audio_bitrate = atoi(optarg);
                break;
            case 'n':
                no_meta = 1;
                break;
            case 'd':
                exit(0);
            case 'q':
                quiet = 1;
                break;
            case 'h':
            default:
                fprintf(stderr,"%s v%s\n", "flvjoin", "0.92");
                fprintf(stderr,"\nSynopsis: Reads a list of FLV files (with optional in-point and out-point)\n");
                fprintf(stderr,"from standard input and joins them together into one larger FLV file.\n\n");
                fprintf(stderr,"Usage: %s -o <filename> [-f <framerate>] [-b <bitrate>] [-n] [-q] [-h]\n\n", "flvjoin");
                fprintf(stderr,"   -o <filename>   Output File (- for stdout)\n");
                fprintf(stderr,"   -f <framerate>  Video frame rate in frames per second (default %.2f)\n", 1000.0 / frame_interval);
                fprintf(stderr,"   -b <bitrate>    Audio bitrate in bits per second (default %d)\n", audio_bitrate);
                fprintf(stderr,"   -n              Don't write metadata to output file\n");
                fprintf(stderr,"   -q              Don't display progress information\n");
                fprintf(stderr,"   -h              Display this usage message and exit\n");
                fprintf(stderr,"\n");
                exit(0);
        }
    }
    if( strlen(filepath) == 0 )
    {
        fprintf(stderr, "ERROR: Output file must be specified with the -o option. (Use - for stdout).\n");
        exit(1);
    }
    {
        struct stat s;
        struct FLVpacket *packet;
        if( strcmp(filepath, "-") != 0 && stat(filepath, &s) == 0 )
        {
            fprintf(stderr,"ERROR: File %s exists; won't write header.\n", filepath);
            exit(1);
        }
        open_output("wb");
        write_flv_header();
        if(!no_meta)
        {
            packet = generate_metadata_packet(outfile);
            write_packet(packet, 0);
        }
    }
    while( fgets(buffer, sizeof(buffer), stdin) )
    {
        int num_params;
        double mark_in; double mark_out;
        char infile[1024];
        char *newline = strchr(buffer, '\n');
        if(newline)
            *newline = '\0';
        num_params = sscanf(buffer, "%1023s %lf %lf", infile, &mark_in, &mark_out);
        if(num_params < 3)
            mark_out = 99999;
        if(num_params < 2)
            mark_in = 0;
        append_file(infile, (unsigned int)(0.5 + mark_in*1000), (unsigned int)(0.5 + mark_out*1000));
    }
    if(!no_meta)
    {
        unsigned int duration;
        if(!quiet)
            fprintf(stderr, "Writing metadata...\n");
        if(last_video_timestamp >= last_audio_timestamp)
            duration = last_video_timestamp + frame_interval;
        else
            duration = last_audio_timestamp + (unsigned int)(0.5 + 1000.0 * last_packet_size * 8 / audio_bitrate);
        write_metadata(outfile, duration);
    }
    if( !quiet )
        fprintf(stderr, "Closing output file %s\n", filepath);
    close_output();
    exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buffer
char [-1]

variable_types: opt int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
infile
char [1024]

variable_types:
newline
char *

variable_types:
duration
unsigned int

user_defined_types: struct FLVpacket { unsigned char type; unsigned int datasize; unsigned char *data; unsigned int backptr; }


original_code:
double conv_double(const unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(double *)ptr;
   else
   {
       int i = 0, j = sizeof(double);
       unsigned char doublebuff[sizeof(double)];
       while( --j >= 0 )
           doublebuff[j] = ptr[i++];
       return *(double *)doublebuff;
   }
}

canonical_original_code:
double conv_double(unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(double *)ptr;
   else
   {
       int i = 0; int j = sizeof(double);
       unsigned char doublebuff[-1];
       while( --j >= 0 )
           doublebuff[j] = ptr[i++];
       return *(double *)doublebuff;
   }
}

variable_types:
ptr
unsigned char *

variable_types: i int

variable_types:
doublebuff
unsigned char [-1]


decompiled_code:
char __fastcall conv_ui32(__int64 a1)
{
return *(_BYTE *)(a1 + 3);
}

canonical_decompiled_code:
char __fastcall func1(__int64 a1)
{
return *(_BYTE *)(a1 + 3);
}

original_code:
unsigned int conv_ui32(const unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(unsigned int *)ptr;
   else
   {
       int i = 0, j = 4;
       unsigned char intbuff[4];
       while( --j >= 0 )
           intbuff[j] = ptr[i++];
       return *(unsigned int *)intbuff;
   }
}

canonical_original_code:
unsigned int conv_ui32(unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(unsigned int *)ptr;
   else
   {
       int i = 0; int j = 4;
       unsigned char intbuff[4];
       while( --j >= 0 )
           intbuff[j] = ptr[i++];
       return *(unsigned int *)intbuff;
   }
}

variable_types: j int

variable_types:
intbuff
unsigned char [4]

return_type: unsigned int


decompiled_code:
char __fastcall conv_ui24(__int64 a1)
{
return *(_BYTE *)(a1 + 2);
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1)
{
return *(_BYTE *)(a1 + 2);
}

original_code:
unsigned int conv_ui24(const unsigned char *ptr, unsigned char highbyte)
{
   unsigned char intbuff[4];
   int i = 0, j;
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
   {
       intbuff[0] = highbyte;
       memcpy(&intbuff[1], ptr, 3);
   }
   else
   {
       intbuff[3] = highbyte;
       for( j = 2; j >= 0; j-- )
           intbuff[j] = ptr[i++];
   }
   return *(unsigned int *)intbuff;
}

canonical_original_code:
unsigned int conv_ui24(unsigned char *ptr, unsigned char highbyte)
{
   unsigned char intbuff[4];
   int i = 0; int j;
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
   {
       intbuff[0] = highbyte;
       memcpy(&intbuff[1], ptr, 3);
   }
   else
   {
       intbuff[3] = highbyte;
       for( j = 2; j >= 0; j-- )
           intbuff[j] = ptr[i++];
   }
   return *(unsigned int *)intbuff;
}

variable_types:
highbyte
unsigned char


decompiled_code:
__int16 __fastcall conv_ui16(_BYTE *a1)
{
__int16 result; // ax

LOBYTE(result) = a1[1];
HIBYTE(result) = *a1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(_BYTE *a1)
{
__int16 result; // ax

LOBYTE(result) = a1[1];
HIBYTE(result) = *a1;
return result;
}

original_code:
unsigned short conv_ui16(const unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(unsigned short *)ptr;
   else
   {
       unsigned char intbuff[2];
       intbuff[0] = ptr[1];
       intbuff[1] = ptr[0];
       return *(unsigned short *)intbuff;
   }
}

canonical_original_code:
unsigned short conv_ui16(unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(unsigned short *)ptr;
   else
   {
       unsigned char intbuff[2];
       intbuff[0] = ptr[1];
       intbuff[1] = ptr[0];
       return *(unsigned short *)intbuff;
   }
}

variable_types:
intbuff
unsigned char [2]

return_type: unsigned short


decompiled_code:
__int16 __fastcall conv_si16(_BYTE *a1)
{
__int16 result; // ax

LOBYTE(result) = a1[1];
HIBYTE(result) = *a1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func4(_BYTE *a1)
{
__int16 result; // ax

LOBYTE(result) = a1[1];
HIBYTE(result) = *a1;
return result;
}

original_code:
short conv_si16(const unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(short *)ptr;
   else
   {
       unsigned char intbuff[2];
       intbuff[0] = ptr[1];
       intbuff[1] = ptr[0];
       return *(short *)intbuff;
   }
}

canonical_original_code:
short conv_si16(unsigned char *ptr)
{
   if( (((unsigned char *) (&byte_order_test))[0] == 0) )
       return *(short *)ptr;
   else
   {
       unsigned char intbuff[2];
       intbuff[0] = ptr[1];
       intbuff[1] = ptr[0];
       return *(short *)intbuff;
   }
}

return_type: short


decompiled_code:
char *__fastcall format_ui32(int a1)
{
outbuff_2 = HIBYTE(a1);
byte_117 = BYTE2(a1);
byte_118 = BYTE1(a1);
byte_119 = a1;
return &outbuff_2;
}

canonical_decompiled_code:
char *__fastcall func6(int a1)
{
outbuff_2 = HIBYTE(a1);
byte_117 = BYTE2(a1);
byte_118 = BYTE1(a1);
byte_119 = a1;
return &outbuff_2;
}

original_code:
unsigned char *format_ui32(unsigned int number)
{
    static unsigned char outbuff[4];
    int i, j = 0;
    if( (((unsigned char *) (&byte_order_test))[0] == 0) )
        memcpy(outbuff, (unsigned char *)&number, 4);
    else
    {
        for( i = 3; i >= 0; i-- )
            outbuff[j++] = ((unsigned char *) &number)[i];
    }
    return outbuff;
}

canonical_original_code:
unsigned char *format_ui32(unsigned int number)
{
    static unsigned char outbuff[4];
    int i; int j = 0;
    if( (((unsigned char *) (&byte_order_test))[0] == 0) )
        memcpy(outbuff, (unsigned char *)&number, 4);
    else
    {
        for( i = 3; i >= 0; i-- )
            outbuff[j++] = ((unsigned char *) &number)[i];
    }
    return outbuff;
}

variable_types:
number
unsigned int

variable_types:
outbuff
unsigned char [4]

return_type: unsigned char *


decompiled_code:
char *__fastcall format_ui24(int a1)
{
byte_115 = HIBYTE(a1);
outbuff_1 = BYTE2(a1);
byte_113 = BYTE1(a1);
byte_114 = a1;
return &outbuff_1;
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
byte_115 = HIBYTE(a1);
outbuff_1 = BYTE2(a1);
byte_113 = BYTE1(a1);
byte_114 = a1;
return &outbuff_1;
}

original_code:
unsigned char *format_ui24(unsigned int number)
{
    static unsigned char outbuff[4];
    int i, j = 0;
    if( (((unsigned char *) (&byte_order_test))[0] == 0) )
    {
        outbuff[3] = ((unsigned char *)&number)[0];
        for( i = 1; i < 4; i++ )
            outbuff[j++] = ((unsigned char *)&number)[i];
    }
    else
    {
        outbuff[3] = ((unsigned char *) &number)[3];
        for( i = 2; i >= 0; i-- )
            outbuff[j++] = ((unsigned char *) &number)[i];
    }
    return outbuff;
}

canonical_original_code:
unsigned char *format_ui24(unsigned int number)
{
    static unsigned char outbuff[4];
    int i; int j = 0;
    if( (((unsigned char *) (&byte_order_test))[0] == 0) )
    {
        outbuff[3] = ((unsigned char *)&number)[0];
        for( i = 1; i < 4; i++ )
            outbuff[j++] = ((unsigned char *)&number)[i];
    }
    else
    {
        outbuff[3] = ((unsigned char *) &number)[3];
        for( i = 2; i >= 0; i-- )
            outbuff[j++] = ((unsigned char *) &number)[i];
    }
    return outbuff;
}


decompiled_code:
char __fastcall add_meta_item(const char *a1, double a2)
{
int v2; // eax
bool v3; // zf

LOBYTE(v2) = (_BYTE)a1;
if ( a2 != -1.0 )
{
if ( !strcmp(a1, "width") )
{
qword_A08 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "height") )
{
qword_A10 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "framerate") )
{
qword_A18 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "videocodecid") )
{
qword_A20 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "audiosamplerate") )
{
qword_A28 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "audiosamplesize") )
{
qword_A30 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "stereo") )
{
v2 = (int)a2;
byte_A38 = (int)a2;
}
else
{
v3 = strcmp(a1, "audiocodecid") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
qword_A40 = *(_QWORD *)&a2;
}
}
return v2;
}

canonical_decompiled_code:
char __fastcall func4(const char *a1, double a2)
{
int v2; // eax
bool v3; // zf

LOBYTE(v2) = (_BYTE)a1;
if ( a2 != -1.0 )
{
if ( !strcmp(a1, "width") )
{
qword_A08 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "height") )
{
qword_A10 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "framerate") )
{
qword_A18 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "videocodecid") )
{
qword_A20 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "audiosamplerate") )
{
qword_A28 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "audiosamplesize") )
{
qword_A30 = *(_QWORD *)&a2;
}
else if ( !strcmp(a1, "stereo") )
{
v2 = (int)a2;
byte_A38 = (int)a2;
}
else
{
v3 = strcmp(a1, "audiocodecid") == 0;
LOBYTE(v2) = !v3;
if ( v3 )
qword_A40 = *(_QWORD *)&a2;
}
}
return v2;
}

original_code:
static void add_meta_item(const char *name, double value)
{
    if(value == -1)
        return;
    if(strcmp(name, "width") == 0)
        meta.width = value;
    else if(strcmp(name, "height") == 0)
        meta.height = value;
    else if(strcmp(name, "framerate") == 0)
        meta.framerate = value;
    else if(strcmp(name, "videocodecid") == 0)
        meta.videocodecid = value;
    else if(strcmp(name, "audiosamplerate") == 0)
        meta.audiosamplerate = value;
    else if(strcmp(name, "audiosamplesize") == 0)
        meta.audiosamplesize = value;
    else if(strcmp(name, "stereo") == 0)
        meta.stereo = (char)value;
    else if(strcmp(name, "audiocodecid") == 0)
        meta.audiocodecid = value;
    return;
}

canonical_original_code:
static void add_meta_item(char *name, double value)
{
    if(value == -1)
        return;
    if(strcmp(name, "width") == 0)
        meta.width = value;
    else if(strcmp(name, "height") == 0)
        meta.height = value;
    else if(strcmp(name, "framerate") == 0)
        meta.framerate = value;
    else if(strcmp(name, "videocodecid") == 0)
        meta.videocodecid = value;
    else if(strcmp(name, "audiosamplerate") == 0)
        meta.audiosamplerate = value;
    else if(strcmp(name, "audiosamplesize") == 0)
        meta.audiosamplesize = value;
    else if(strcmp(name, "stereo") == 0)
        meta.stereo = (char)value;
    else if(strcmp(name, "audiocodecid") == 0)
        meta.audiocodecid = value;
    return;
}

variable_types:
name
char *

variable_types: value double


decompiled_code:
double __fastcall parse_number(const void **a1, double result)
{
unsigned __int8 *v3; // rax
__int64 v4; // rdi
unsigned __int16 v5; // ax
int v6; // ebp
int i; // er12
unsigned int v8; // esi
int v9; // er12
int j; // ebp
unsigned int v11; // eax
char v12[1048]; // [rsp+0h] [rbp-418h] BYREF

v3 = (unsigned __int8 *)*a1;
v4 = (__int64)*a1 + 1;
*a1 = (const void *)v4;
switch ( *v3 )
{
case 0u:
conv_double();
*a1 = (char *)*a1 + 8;
break;
case 1u:
result = (double)v3[1];
*a1 = v3 + 2;
break;
case 2u:
v5 = conv_ui16(v4, result);
*a1 = (const void *)parse_script_string((__int64)*a1 + 2, v5, 0LL);
result = *(double *)&LC1;
break;
case 3u:
parse_script_object(a1);
result = *(double *)&LC1;
break;
case 7u:
result = (double)(unsigned __int16)conv_ui16(v4, result);
*a1 = (char *)*a1 + 2;
break;
case 8u:
v6 = conv_ui32();
*a1 = (char *)*a1 + 4;
result = *(double *)&LC1;
if ( v6 > 0 )
{
for ( i = 0; i != v6; ++i )
{
v8 = (unsigned __int16)conv_ui16(*a1, result);
*a1 = (const void *)parse_script_string((__int64)*a1 + 2, v8, (__int64)v12);
result = parse_number(a1);
add_meta_item(v12, result);
}
result = *(double *)&LC1;
}
break;
case 0xAu:
v9 = conv_ui32();
*a1 = (char *)*a1 + 4;
result = *(double *)&LC1;
if ( v9 > 0 )
{
for ( j = 0; j != v9; ++j )
result = parse_number(a1);
}
break;
case 0xBu:
result = ((double (*)(void))conv_double)() / 1000.0;
*a1 = (char *)*a1 + 10;
break;
case 0xCu:
v11 = conv_ui32();
*a1 = (const void *)parse_script_string((__int64)*a1 + 2, v11, 0LL);
result = *(double *)&LC1;
break;
default:
fprintf(stderr, "WARNING: Unhandled script variable type %d\n", *v3);
result = *(double *)&LC1;
break;
}
return result;
}

canonical_decompiled_code:
double __fastcall func6(const void **a1, double result)
{
unsigned __int8 *v3; // rax
__int64 v4; // rdi
unsigned __int16 v5; // ax
int v6; // ebp
int i; // er12
unsigned int v8; // esi
int v9; // er12
int j; // ebp
unsigned int v11; // eax
char v12[1048]; // [rsp+0h] [rbp-418h] BYREF

v3 = (unsigned __int8 *)*a1;
v4 = (__int64)*a1 + 1;
*a1 = (const void *)v4;
switch ( *v3 )
{
case 0u:
conv_double();
*a1 = (char *)*a1 + 8;
break;
case 1u:
result = (double)v3[1];
*a1 = v3 + 2;
break;
case 2u:
v5 = conv_ui16(v4, result);
*a1 = (const void *)func0((__int64)*a1 + 2, v5, 0LL);
result = *(double *)&LC1;
break;
case 3u:
func5(a1);
result = *(double *)&LC1;
break;
case 7u:
result = (double)(unsigned __int16)conv_ui16(v4, result);
*a1 = (char *)*a1 + 2;
break;
case 8u:
v6 = conv_ui32();
*a1 = (char *)*a1 + 4;
result = *(double *)&LC1;
if ( v6 > 0 )
{
for ( i = 0; i != v6; ++i )
{
v8 = (unsigned __int16)conv_ui16(*a1, result);
*a1 = (const void *)func0((__int64)*a1 + 2, v8, (__int64)v12);
result = func6(a1);
func4(v12, result);
}
result = *(double *)&LC1;
}
break;
case 0xAu:
v9 = conv_ui32();
*a1 = (char *)*a1 + 4;
result = *(double *)&LC1;
if ( v9 > 0 )
{
for ( j = 0; j != v9; ++j )
result = func6(a1);
}
break;
case 0xBu:
result = ((double (*)(void))conv_double)() / 1000.0;
*a1 = (char *)*a1 + 10;
break;
case 0xCu:
v11 = conv_ui32();
*a1 = (const void *)func0((__int64)*a1 + 2, v11, 0LL);
result = *(double *)&LC1;
break;
default:
fprintf(stderr, "WARNING: Unhandled script variable type %d\n", *v3);
result = *(double *)&LC1;
break;
}
return result;
}

original_code:
static double parse_number(unsigned char **pos)
{
    unsigned char variable_type = *(*pos)++;
    double value = -1;
    switch( variable_type )
    {
        case 0:
            value = conv_double(*pos);
            *pos += sizeof(double);
            break;
        case 1:
            value = (double)**pos;
            (*pos)++;
            break;
        case 2:
            *pos = parse_script_string(*pos + 2, conv_ui16(*pos), ((void *)0));
            break;
        case 3:
            parse_script_object(pos);
            break;
        case 7:
            value = conv_ui16(*pos);
            *pos += 2;
            break;
        case 8:
     {
         int array_length = conv_ui32(*pos);
  int count;
  *pos += 4;
  for( count = 0; count < array_length; count++ )
  {
             char buff[1024];
      double val;
      *pos = parse_script_string(*pos + 2, conv_ui16(*pos), buff);
      val = parse_number(pos);
                    add_meta_item(buff, val);
  }
     }
            break;
        case 10:
     {
         int array_length = conv_ui32(*pos);
  int count;
  *pos += 4;
  for( count = 0; count < array_length; count++ )
      value = parse_number(pos);
     }
            break;
        case 11:
            value = conv_double(*pos) / 1000;
     *pos += sizeof(double);
     *pos += 2;
            break;
        case 12:
            *pos = parse_script_string(*pos + 2, conv_ui32(*pos), ((void *)0));
            break;
        default:
            fprintf(stderr, "WARNING: Unhandled script variable type %d\n", variable_type);
            break;
   }
    return value;
}

variable_types:
pos
unsigned char **

variable_types: count int

variable_types:
buff
char [1024]

variable_types: val double


decompiled_code:
__int64 __fastcall extract_metadata(__int64 a1, double a2)
{
unsigned int v2; // er12
_BYTE *v4; // rdi
unsigned __int16 v5; // ax
char v7[1032]; // [rsp+0h] [rbp-428h] BYREF
__int64 v8; // [rsp+408h] [rbp-20h] BYREF

v2 = 0;
if ( *(_BYTE *)a1 == 18 )
{
v4 = *(_BYTE **)(a1 + 16);
v8 = (__int64)(v4 + 1);
if ( *v4 == 2 )
{
v2 = 0;
if ( *(_DWORD *)(a1 + 4) == 6 )
return v2;
++v4;
}
else
{
v8 = (__int64)v4;
}
v2 = 0;
do
{
v5 = conv_ui16(v4, a2);
v8 = parse_script_string(v8 + 2, v5, (__int64)v7);
if ( !strcmp(v7, "onMetaData") )
v2 = 1;
a2 = parse_number((const void **)&v8, a2);
add_meta_item(v7, a2);
v4 = (_BYTE *)v8;
}
while ( v8 - *(_QWORD *)(a1 + 16) <= (unsigned int)(*(_DWORD *)(a1 + 4) - 6) );
}
return v2;
}

original_code:
int extract_metadata(struct FLVpacket *packet)
{
    unsigned char *pos = packet->data;
    unsigned char marker;
    int found_metadata_marker = 0;
    if(packet->type != 18)
        return 0;
    marker = *(pos++);
    if( marker != 2 )
        pos--;
    while(pos - packet->data <= packet->datasize - 6)
    {
        char buff[1024];
        double val;
        pos = parse_script_string(pos + 2, conv_ui16(pos), buff);
        if(strcmp(buff, "onMetaData") == 0)
            found_metadata_marker = 1;
        val = parse_number(&pos);
        add_meta_item(buff, val);
    }
    return found_metadata_marker;
}

variable_types: struct FLVpacket { unsigned char type; unsigned int datasize; unsigned char *data; unsigned int backptr; } *

variable_types:
pos
unsigned char *

variable_types:
marker
unsigned char


decompiled_code:
__int64 __fastcall parse_script_string(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 i; // rax
unsigned int v4; // eax

if ( a3 )
{
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
*(_BYTE *)(a3 + i) = *(_BYTE *)(a1 + i);
v4 = a2;
}
else
{
v4 = 0;
}
*(_BYTE *)(a3 + v4) = 0;
}
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 i; // rax
unsigned int v4; // eax

if ( a3 )
{
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
*(_BYTE *)(a3 + i) = *(_BYTE *)(a1 + i);
v4 = a2;
}
else
{
v4 = 0;
}
*(_BYTE *)(a3 + v4) = 0;
}
return a1 + a2;
}

original_code:
static unsigned char *parse_script_string(unsigned char *pos, unsigned int string_length, char *buff)
{
    if(buff)
    {
        unsigned int count;
        for( count = 0; count < string_length; count++)
            buff[count] = (char)pos[count];
        buff[count] = '\0';
    }
    pos += string_length;
    return pos;
}

variable_types:
buff
char *

variable_types:
count
unsigned int