parseNode

decompiled_code:
__int64 __fastcall parseNode(__int64 a1)
{
int v1; // ebp
char *v2; // rcx
__int64 result; // rax
__int64 v4; // rdx
char v5; // si
__int64 v6; // rax
char *v7; // rdx
__int64 v8; // rax
__int64 v9; // r12
__int64 v10; // rax

v1 = chrPtr;
clearWhiteSpace();
v2 = (char *)xmlArray;
result = (unsigned int)chrPtr;
v4 = chrPtr;
v5 = *((_BYTE *)xmlArray + chrPtr);
if ( v5 )
{
do
{
while ( 1 )
{
if ( v5 != 60 || (v7 = &v2[v4 + 1], *v7 == 47) )
{
chrPtr = v1;
v10 = readXMLTextNode();
return xmlAddChildNode(a1, v10);
}
chrPtr = result + 1;
if ( *v7 != 63 )
break;
chrPtr = result + 2;
v6 = readXMLDeclerationNode();
xmlAddChildNode(a1, v6);
moveToChar(62);
++chrPtr;
clearWhiteSpace();
LABEL_4:
v2 = (char *)xmlArray;
result = (unsigned int)chrPtr;
v4 = chrPtr;
v5 = *((_BYTE *)xmlArray + chrPtr);
if ( !v5 )
return result;
}
v8 = readXMLElementNode();
v9 = xmlAddChildNode(a1, v8);
getAttributes(v9);
moveToChar(62);
++chrPtr;
parseNode(v9);
clearWhiteSpace();
if ( *((_BYTE *)xmlArray + chrPtr) == 60 )
{
moveToChar(62);
if ( *((_BYTE *)xmlArray + chrPtr) == 62 )
++chrPtr;
}
clearWhiteSpace();
v2 = (char *)xmlArray;
result = (unsigned int)chrPtr;
v4 = chrPtr;
v5 = *((_BYTE *)xmlArray + chrPtr);
if ( v5 != 60 )
goto LABEL_4;
}
while ( *((_BYTE *)xmlArray + chrPtr + 1) != 47 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // ebp
char *v2; // rcx
__int64 result; // rax
__int64 v4; // rdx
char v5; // si
__int64 v6; // rax
char *v7; // rdx
__int64 v8; // rax
__int64 v9; // r12
__int64 v10; // rax

v1 = chrPtr;
func2();
v2 = (char *)xmlArray;
result = (unsigned int)chrPtr;
v4 = chrPtr;
v5 = *((_BYTE *)xmlArray + chrPtr);
if ( v5 )
{
do
{
while ( 1 )
{
if ( v5 != 60 || (v7 = &v2[v4 + 1], *v7 == 47) )
{
chrPtr = v1;
v10 = func10();
return xmlAddChildNode(a1, v10);
}
chrPtr = result + 1;
if ( *v7 != 63 )
break;
chrPtr = result + 2;
v6 = func8();
xmlAddChildNode(a1, v6);
func3(62);
++chrPtr;
func2();
LABEL_4:
v2 = (char *)xmlArray;
result = (unsigned int)chrPtr;
v4 = chrPtr;
v5 = *((_BYTE *)xmlArray + chrPtr);
if ( !v5 )
return result;
}
v8 = func9();
v9 = xmlAddChildNode(a1, v8);
func5(v9);
func3(62);
++chrPtr;
func11(v9);
func2();
if ( *((_BYTE *)xmlArray + chrPtr) == 60 )
{
func3(62);
if ( *((_BYTE *)xmlArray + chrPtr) == 62 )
++chrPtr;
}
func2();
v2 = (char *)xmlArray;
result = (unsigned int)chrPtr;
v4 = chrPtr;
v5 = *((_BYTE *)xmlArray + chrPtr);
if ( v5 != 60 )
goto LABEL_4;
}
while ( *((_BYTE *)xmlArray + chrPtr + 1) != 47 );
}
return result;
}

original_code:
void parseNode(XMLNode *node)
{
  int prevChrPtr = chrPtr;
  clearWhiteSpace();
  while(xmlArray[chrPtr] != '\0'){
    if(xmlArray[chrPtr] == '<' && xmlArray[chrPtr + 1] != '/'){
      chrPtr++;
      if(xmlArray[chrPtr] == '?'){
        chrPtr++;
        xmlAddChildNode(node, readXMLDeclerationNode());
        moveToChar('>');
        chrPtr++;
        clearWhiteSpace();
      }
      else{
        XMLNode* childNode = xmlAddChildNode(node, readXMLElementNode());
        getAttributes(childNode);
        moveToChar('>');
        chrPtr++;
        parseNode(childNode);
        clearWhiteSpace();
        if(xmlArray[chrPtr] == '<'){
          moveToChar('>');
          if(xmlArray[chrPtr] == '>'){
            chrPtr++;
          }
        }
        clearWhiteSpace();
        if(xmlArray[chrPtr] == '<' && xmlArray[chrPtr + 1] == '/')
          break;
      }
    }
    else{
      chrPtr = prevChrPtr;
      xmlAddChildNode(node, readXMLTextNode());
      break;
    }
  }
}

canonical_original_code:
void parseNode(struct XMLNode_item *node)
{
  int prevChrPtr = chrPtr;
  clearWhiteSpace();
  while(xmlArray[chrPtr] != '\0'){
    if(xmlArray[chrPtr] == '<' && xmlArray[chrPtr + 1] != '/'){
      chrPtr++;
      if(xmlArray[chrPtr] == '?'){
        chrPtr++;
        xmlAddChildNode(node, readXMLDeclerationNode());
        moveToChar('>');
        chrPtr++;
        clearWhiteSpace();
      }
      else{
        struct XMLNode_item *childNode = xmlAddChildNode(node, readXMLElementNode());
        getAttributes(childNode);
        moveToChar('>');
        chrPtr++;
        parseNode(childNode);
        clearWhiteSpace();
        if(xmlArray[chrPtr] == '<'){
          moveToChar('>');
          if(xmlArray[chrPtr] == '>'){
            chrPtr++;
          }
        }
        clearWhiteSpace();
        if(xmlArray[chrPtr] == '<' && xmlArray[chrPtr + 1] == '/')
          break;
      }
    }
    else{
      chrPtr = prevChrPtr;
      xmlAddChildNode(node, readXMLTextNode());
      break;
    }
  }
}

variable_types: prevChrPtr int


xmlRead

decompiled_code:
__int64 __fastcall xmlRead(const char *a1)
{
__int64 v1; // rbx

chrPtr = 0;
loadXMLFile(a1);
v1 = xmlCreateNode("Document", "Main Document", 0LL);
parseNode(v1);
free(xmlArray);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1)
{
__int64 v1; // rbx

chrPtr = 0;
func0(a1);
v1 = xmlCreateNode("Document", "Main Document", 0LL);
func11(v1);
free(xmlArray);
return v1;
}

original_code:
XMLNode *xmlRead(char* file)
{
 chrPtr = 0;
  loadXMLFile(file);
  XMLNode *docNode = xmlCreateNode("Document", "Main Document", ((void *)0));
  parseNode(docNode);
  free(xmlArray);
  return docNode;
}

canonical_original_code:
struct XMLNode_item *xmlRead(char *file)
{
 chrPtr = 0;
  loadXMLFile(file);
  struct XMLNode_item *docNode = xmlCreateNode("Document", "Main Document", ((void *)0));
  parseNode(docNode);
  free(xmlArray);
  return docNode;
}

variable_types:
file
char *

variable_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item { char *Name; char *Value; } **Attributes; } *

user_defined_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item **Attributes; }


assignString

decompiled_code:
void __fastcall assignString(_QWORD *a1, const char *a2)
{
size_t v2; // rax
void *v3; // r12
size_t v4; // rax

if ( a2 )
{
v2 = strlen(a2);
v3 = malloc(v2 + 1);
*a1 = v3;
v4 = strlen(a2);
memcpy(v3, a2, v4);
*((_BYTE *)v3 + strlen(a2)) = 0;
}
else
{
*a1 = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, const char *a2)
{
size_t v2; // rax
void *v3; // r12
size_t v4; // rax

if ( a2 )
{
v2 = strlen(a2);
v3 = malloc(v2 + 1);
*a1 = v3;
v4 = strlen(a2);
memcpy(v3, a2, v4);
*((_BYTE *)v3 + strlen(a2)) = 0;
}
else
{
*a1 = 0LL;
}
}

original_code:
void assignString(char** field, char* value)
{
  if(value == ((void *)0))
  {
    *field = ((void *)0);
  }
  else
  {
    *field= (char*)malloc((strlen(value) + 1)*sizeof(char));
    memmove(*field, value, strlen(value));
    (*field)[strlen(value)] = '\0';
  }
}

canonical_original_code:
void assignString(char **field, char *value)
{
  if(value == ((void *)0))
  {
    *field = ((void *)0);
  }
  else
  {
    *field= (char *)malloc((strlen(value) + 1)*sizeof(char));
    memmove(*field, value, strlen(value));
    (*field)[strlen(value)] = '\0';
  }
}

variable_types:
field
char **

variable_types:
value
char *

return_type: void


xmlGetText

decompiled_code:
__int64 __fastcall xmlGetText(__int64 a1)
{
return *(_QWORD *)(**(_QWORD **)(a1 + 40) + 16LL);
}

original_code:
char* xmlGetText(XMLNode *node)
{
  return node->ChildNodes[0]->Value;
}

canonical_original_code:
char *xmlGetText(struct XMLNode_item *node)
{
  return node->ChildNodes[0]->Value;
}

return_type: char *

user_defined_types: struct Attribute_item { char *Name; char *Value; }


xmlGetAttribute

decompiled_code:
const char **__fastcall xmlGetAttribute(__int64 a1, const char *a2)
{
int v2; // eax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

v2 = *(_DWORD *)(a1 + 32);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ****)(a1 + 48);
v4 = (__int64)&v3[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(**v3, a2) )
break;
if ( ++v3 == (const char ***)v4 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
const char **__fastcall func2(__int64 a1, const char *a2)
{
int v2; // eax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

v2 = *(_DWORD *)(a1 + 32);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ****)(a1 + 48);
v4 = (__int64)&v3[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(**v3, a2) )
break;
if ( ++v3 == (const char ***)v4 )
return 0LL;
}
return v5;
}

original_code:
Attribute* xmlGetAttribute(XMLNode *node, char* attributeName)
{
  int i = 0;
  Attribute* attribute = ((void *)0);
  for(i = 0; i < node->AttributesCount; i++)
  {
    if(strcmp(node->Attributes[i]->Name, attributeName) == 0)
    {
      attribute = node->Attributes[i];
      break;
    }
  }
  return attribute;
}

canonical_original_code:
struct Attribute_item *xmlGetAttribute(struct XMLNode_item *node, char *attributeName)
{
  int i = 0;
  struct Attribute_item *attribute = ((void *)0);
  for(i = 0; i < node->AttributesCount; i++)
  {
    if(strcmp(node->Attributes[i]->Name, attributeName) == 0)
    {
      attribute = node->Attributes[i];
      break;
    }
  }
  return attribute;
}

variable_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item **Attributes; } *

variable_types:
attributeName
char *

variable_types: i int

variable_types: struct Attribute_item { char *Name; char *Value; } *


createEmptyXMLNode

original_code:
XMLNode* createEmptyXMLNode()
{
  XMLNode* newNode = (XMLNode *)malloc(sizeof(XMLNode));
  newNode->ChildrenCount = 0;
  newNode->ChildrenArraySize = 1;
  newNode->ChildNodes = (XMLNode **)malloc(sizeof(XMLNode*));
  newNode->AttributesCount = 0;
  newNode->AttributesArraySize = 1;
  newNode->Attributes = (Attribute **)malloc(sizeof(Attribute*));
  newNode->NodeType = '\0';
  newNode->Name = '\0';
  newNode->Value = '\0';
  return newNode;
}

canonical_original_code:
struct XMLNode_item *createEmptyXMLNode()
{
  struct XMLNode_item *newNode = (XMLNode *)malloc(sizeof(XMLNode));
  newNode->ChildrenCount = 0;
  newNode->ChildrenArraySize = 1;
  newNode->ChildNodes = (struct XMLNode_item **)malloc(sizeof(struct XMLNode_item *));
  newNode->AttributesCount = 0;
  newNode->AttributesArraySize = 1;
  newNode->Attributes = (struct Attribute_item **)malloc(sizeof(struct Attribute_item *));
  newNode->NodeType = '\0';
  newNode->Name = '\0';
  newNode->Value = '\0';
  return newNode;
}

return_type: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item { char *Name; char *Value; } **Attributes; } *


GetText

decompiled_code:
__int64 __fastcall GetText(__int64 a1)
{
return *(_QWORD *)(**(_QWORD **)(a1 + 40) + 16LL);
}

original_code:
char* GetText(XMLNode* node)
{
  return node->ChildNodes[0]->Value;
}

canonical_original_code:
char *GetText(struct XMLNode_item *node)
{
  return node->ChildNodes[0]->Value;
}


xmlAddAttribute

original_code:
void xmlAddAttribute(XMLNode *xmlNode, char *atrribute, char *value)
{
  if(xmlNode->AttributesCount == xmlNode->AttributesArraySize)
  {
    xmlNode->AttributesArraySize = 2 * xmlNode->AttributesArraySize;
    xmlNode->Attributes = realloc(
      xmlNode->Attributes, xmlNode->AttributesArraySize * sizeof(Attribute*));
  }
  xmlNode->AttributesCount++;
  xmlNode->Attributes[xmlNode->AttributesCount - 1] = (Attribute *)malloc(sizeof(Attribute));
  assignString(&(xmlNode->Attributes[xmlNode->AttributesCount - 1]->Name), atrribute);
  int valueLength = (int)strlen(value);
  if(value[valueLength - 1] == '\n')
    value[valueLength - 1] = ' ';
  assignString(&(xmlNode->Attributes[xmlNode->AttributesCount - 1]->Value), value);
}

canonical_original_code:
void xmlAddAttribute(struct XMLNode_item *xmlNode, char *atrribute, char *value)
{
  if(xmlNode->AttributesCount == xmlNode->AttributesArraySize)
  {
    xmlNode->AttributesArraySize = 2 * xmlNode->AttributesArraySize;
    xmlNode->Attributes = realloc(
      xmlNode->Attributes, xmlNode->AttributesArraySize * sizeof(struct Attribute_item *));
  }
  xmlNode->AttributesCount++;
  xmlNode->Attributes[xmlNode->AttributesCount - 1] = (struct Attribute_item *)malloc(sizeof(Attribute));
  assignString(&(xmlNode->Attributes[xmlNode->AttributesCount - 1]->Name), atrribute);
  int valueLength = (int)strlen(value);
  if(value[valueLength - 1] == '\n')
    value[valueLength - 1] = ' ';
  assignString(&(xmlNode->Attributes[xmlNode->AttributesCount - 1]->Value), value);
}

variable_types:
atrribute
char *

variable_types: valueLength int


xmlAddChildNode

original_code:
XMLNode *xmlAddChildNode(XMLNode *parentNode, XMLNode *childNode)
{
  if(parentNode->ChildrenCount == parentNode->ChildrenArraySize)
  {
    parentNode->ChildrenArraySize = parentNode->ChildrenArraySize * 2;
    parentNode->ChildNodes =
      realloc(parentNode->ChildNodes, parentNode->ChildrenArraySize * sizeof(XMLNode*));
  }
  parentNode->ChildrenCount++;
  int currentChildIndex = parentNode->ChildrenCount - 1;
  parentNode->ChildNodes[currentChildIndex] = childNode;
  return childNode;
}

canonical_original_code:
struct XMLNode_item *xmlAddChildNode(struct XMLNode_item *parentNode, struct XMLNode_item *childNode)
{
  if(parentNode->ChildrenCount == parentNode->ChildrenArraySize)
  {
    parentNode->ChildrenArraySize = parentNode->ChildrenArraySize * 2;
    parentNode->ChildNodes =
      realloc(parentNode->ChildNodes, parentNode->ChildrenArraySize * sizeof(struct XMLNode_item *));
  }
  parentNode->ChildrenCount++;
  int currentChildIndex = parentNode->ChildrenCount - 1;
  parentNode->ChildNodes[currentChildIndex] = childNode;
  return childNode;
}

variable_types:
parentNode
struct XMLNode_item *

variable_types:
childNode
struct XMLNode_item *

variable_types: currentChildIndex int


xmlGetChildNode

decompiled_code:
const char **__fastcall xmlGetChildNode(__int64 a1, const char *a2)
{
int v2; // eax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

v2 = *(_DWORD *)(a1 + 24);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ****)(a1 + 40);
v4 = (__int64)&v3[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(**v3, a2) )
break;
if ( ++v3 == (const char ***)v4 )
return 0LL;
}
return v5;
}

canonical_decompiled_code:
const char **__fastcall func7(__int64 a1, const char *a2)
{
int v2; // eax
const char ***v3; // rbx
__int64 v4; // r13
const char **v5; // rbp

v2 = *(_DWORD *)(a1 + 24);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ****)(a1 + 40);
v4 = (__int64)&v3[(unsigned int)(v2 - 1) + 1];
while ( 1 )
{
v5 = *v3;
if ( !strcmp(**v3, a2) )
break;
if ( ++v3 == (const char ***)v4 )
return 0LL;
}
return v5;
}

original_code:
XMLNode* xmlGetChildNode(XMLNode *parentNode, char* childName)
{
  XMLNode *returnNode = ((void *)0);
  int i = 0;
  for(i = 0; i < parentNode->ChildrenCount; i++)
  {
    if(strcmp(parentNode->ChildNodes[i]->Name, childName) == 0)
    {
      returnNode = parentNode->ChildNodes[i];
      break;
    }
  }
  return returnNode;
}

canonical_original_code:
struct XMLNode_item *xmlGetChildNode(struct XMLNode_item *parentNode, char *childName)
{
  struct XMLNode_item *returnNode = ((void *)0);
  int i = 0;
  for(i = 0; i < parentNode->ChildrenCount; i++)
  {
    if(strcmp(parentNode->ChildNodes[i]->Name, childName) == 0)
    {
      returnNode = parentNode->ChildNodes[i];
      break;
    }
  }
  return returnNode;
}

variable_types:
childName
char *


freeAttribute

decompiled_code:
void __fastcall freeAttribute(void **a1)
{
free(*a1);
free(a1[1]);
}

canonical_decompiled_code:
void __fastcall func8(void **a1)
{
free(*a1);
free(a1[1]);
}

original_code:
void freeAttribute(Attribute *attribute)
{
  free(attribute->Name);
  free(attribute->Value);
}

canonical_original_code:
void freeAttribute(struct Attribute_item *attribute)
{
  free(attribute->Name);
  free(attribute->Value);
}


xmlFree

original_code:
void xmlFree(XMLNode *node)
{
  free(node->Name);
  free(node->NodeType);
  free(node->Value);
  int i = 0;
  for(i=0; i < node->AttributesCount; i++)
  {
    freeAttribute(node->Attributes[i]);
  }
  i = 0;
  for(i=0; i < node->ChildrenCount; i++)
  {
    xmlFree(node->ChildNodes[i]);
  }
  free(node->ChildNodes);
  free(node->Attributes);
  free(node);
}

canonical_original_code:
void xmlFree(struct XMLNode_item *node)
{
  free(node->Name);
  free(node->NodeType);
  free(node->Value);
  int i = 0;
  for(i=0; i < node->AttributesCount; i++)
  {
    freeAttribute(node->Attributes[i]);
  }
  i = 0;
  for(i=0; i < node->ChildrenCount; i++)
  {
    xmlFree(node->ChildNodes[i]);
  }
  free(node->ChildNodes);
  free(node->Attributes);
  free(node);
}


repo: linux-sunxi/cedarx-libs

decompiled_code:
void *__fastcall mem_alloc(size_t size)
{
return malloc((unsigned int)size);
}

canonical_decompiled_code:
void *__fastcall func0(size_t size)
{
return malloc((unsigned int)size);
}

original_code:
void* mem_alloc(u32 size)
{
 return malloc(size);
}

canonical_original_code:
void *mem_alloc(unsigned int size)
{
 return malloc(size);
}

variable_types:
size
unsigned int

return_type: void *


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

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

original_code:
void mem_free(void* p)
{
 free(p);
}

canonical_original_code:
void mem_free(void *p)
{
 free(p);
}

variable_types:
p
void *


decompiled_code:
void *__fastcall mem_set(void *a1, int a2, unsigned int a3)
{
return memset(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func4(void *a1, int a2, unsigned int a3)
{
return memset(a1, a2, a3);
}

original_code:
void mem_set(void* mem, u32 value, u32 size)
{
 memset(mem, value, size);
}

canonical_original_code:
void mem_set(void *mem, unsigned int value, unsigned int size)
{
 memset(mem, value, size);
}

variable_types:
mem
void *

variable_types:
value
unsigned int


decompiled_code:
void *__fastcall mem_cpy(void *a1, const void *a2, unsigned int a3)
{
return memcpy(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func5(void *a1, const void *a2, unsigned int a3)
{
return memcpy(a1, a2, a3);
}

original_code:
void mem_cpy(void* dst, void* src, u32 size)
{
 memcpy(dst, src, size);
}

canonical_original_code:
void mem_cpy(void *dst, void *src, unsigned int size)
{
 memcpy(dst, src, size);
}

variable_types:
dst
void *

variable_types:
src
void *


decompiled_code:
void mem_flush_cache()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void mem_flush_cache(u8* mem, u32 size)
{
}

canonical_original_code:
void mem_flush_cache(unsigned char *mem, unsigned int size)
{
}

variable_types:
mem
unsigned char *


decompiled_code:
pthread_mutex_t *semaphore_create()
{
pthread_mutex_t *v0; // rbx

v0 = (pthread_mutex_t *)malloc(0x28uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

canonical_decompiled_code:
pthread_mutex_t *func8()
{
pthread_mutex_t *v0; // rbx

v0 = (pthread_mutex_t *)malloc(0x28uLL);
pthread_mutex_init(v0, 0LL);
return v0;
}

original_code:
Handle semaphore_create(u32 cnt)
{
 pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 pthread_mutex_init(mutex, ((void *)0));
 return (Handle)(mutex);
}

canonical_original_code:
void *semaphore_create(unsigned int cnt)
{
 union pthread_mutex_t *mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
 pthread_mutex_init(mutex, ((void *)0));
 return (Handle)(mutex);
}

variable_types:
cnt
unsigned int

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

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

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


decompiled_code:
__int64 __fastcall semaphore_delete(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr)
{
pthread_mutex_destroy((pthread_mutex_t *)ptr);
free(ptr);
return 0LL;
}

original_code:
s32 semaphore_delete(Handle h, u32 opt)
{
 pthread_mutex_destroy((pthread_mutex_t *)h);
 if(h)
 {
  free(h);
  h = ((void *)0);
 }
 return 0;
}

canonical_original_code:
int semaphore_delete(void *h, unsigned int opt)
{
 pthread_mutex_destroy((union pthread_mutex_t *)h);
 if(h)
 {
  free(h);
  h = ((void *)0);
 }
 return 0;
}

variable_types:
h
void *

variable_types:
opt
unsigned int

return_type: int

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


decompiled_code:
__int64 __fastcall semaphore_pend(pthread_mutex_t *a1)
{
pthread_mutex_lock(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(pthread_mutex_t *a1)
{
pthread_mutex_lock(a1);
return 0LL;
}

original_code:
s32 semaphore_pend(Handle h, u32 timeout)
{
 pthread_mutex_lock((pthread_mutex_t *)h);
 return 0;
}

canonical_original_code:
int semaphore_pend(void *h, unsigned int timeout)
{
 pthread_mutex_lock((union pthread_mutex_t *)h);
 return 0;
}

variable_types:
timeout
unsigned int


decompiled_code:
__int64 __fastcall semaphore_post(pthread_mutex_t *a1)
{
pthread_mutex_unlock(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(pthread_mutex_t *a1)
{
pthread_mutex_unlock(a1);
return 0LL;
}

original_code:
s32 semaphore_post(Handle h)
{
 pthread_mutex_unlock((pthread_mutex_t *)h);
 return 0;
}

canonical_original_code:
int semaphore_post(void *h)
{
 pthread_mutex_unlock((union pthread_mutex_t *)h);
 return 0;
}


decompiled_code:
int __fastcall sys_sleep(int a1)
{
return usleep(1000 * a1);
}

canonical_decompiled_code:
int __fastcall func13(int a1)
{
return usleep(1000 * a1);
}

original_code:
void sys_sleep(u32 ms)
{
 usleep(ms*1000);
}

canonical_original_code:
void sys_sleep(unsigned int ms)
{
 usleep(ms*1000);
}

variable_types:
ms
unsigned int


decompiled_code:
__int64 awprintf_init()
{
log_line_buffer = (char *)mem_alloc(1024LL);
return (unsigned int)-(log_line_buffer == 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
log_line_buffer = (char *)mem_alloc(1024LL);
return (unsigned int)-(log_line_buffer == 0LL);
}

original_code:
int awprintf_init(void)
{
 log_line_buffer = (char*)mem_alloc(1024);
 if(log_line_buffer == ((void *)0))
 {
  return -1;
 }
 return 0;
}

canonical_original_code:
int awprintf_init()
{
 log_line_buffer = (char *)mem_alloc(1024);
 if(log_line_buffer == ((void *)0))
 {
  return -1;
 }
 return 0;
}


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

if ( log_line_buffer )
{
result = mem_free();
log_line_buffer = 0LL;
}
return result;
}

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

if ( log_line_buffer )
{
result = mem_free();
log_line_buffer = 0LL;
}
return result;
}

original_code:
void awprintf_exit(void)
{
 if(log_line_buffer != ((void *)0))
 {
  mem_free(log_line_buffer);
  log_line_buffer = ((void *)0);
 }
 return;
}

canonical_original_code:
void awprintf_exit()
{
 if(log_line_buffer != ((void *)0))
 {
  mem_free(log_line_buffer);
  log_line_buffer = ((void *)0);
 }
 return;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
u8* vbv_get_base_addr(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return ((void *)0);
    }
    return v->vbv_buf;
}

canonical_original_code:
unsigned char *vbv_get_base_addr(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return ((void *)0);
    }
    return v->vbv_buf;
}

variable_types:
vbv
void *

variable_types: struct VBV_MANAGER { void *mutex; unsigned char *vbv_buf; unsigned char *vbv_buf_end; unsigned char *read_addr; unsigned char *write_addr; unsigned int valid_size; unsigned int max_size; struct STREAM_FIFO { struct STREAM_FRAME { struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 } stream_type; unsigned int pict_prop; } vstream; unsigned int id; struct STREAM_FRAME *next; } *in_frames; unsigned int read_index; unsigned int write_index; unsigned int frame_num; unsigned int max_frame_num; } frame_fifo; struct STREAM_QUEUE { unsigned int frame_num; struct STREAM_FRAME *head; } frame_queue; void *parent; } *

return_type: unsigned char *

user_defined_types: struct VBV_MANAGER { void *mutex; unsigned char *vbv_buf; unsigned char *vbv_buf_end; unsigned char *read_addr; unsigned char *write_addr; unsigned int valid_size; unsigned int max_size; struct STREAM_FIFO frame_fifo; struct STREAM_QUEUE frame_queue; void *parent; }

user_defined_types: struct STREAM_FIFO { struct STREAM_FRAME *in_frames; unsigned int read_index; unsigned int write_index; unsigned int frame_num; unsigned int max_frame_num; }

user_defined_types: struct STREAM_FRAME { struct VIDEO_STREAM_DATA vstream; unsigned int id; struct STREAM_FRAME *next; }

user_defined_types: struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE stream_type; unsigned int pict_prop; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 44);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 44);
else
result = 0LL;
return result;
}

original_code:
u32 vbv_get_buffer_size(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if(v == ((void *)0))
    {
        return 0;
    }
    return v->max_size;
}

canonical_original_code:
unsigned int vbv_get_buffer_size(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if(v == ((void *)0))
    {
        return 0;
    }
    return v->max_size;
}

return_type: unsigned int

user_defined_types: struct STREAM_QUEUE { unsigned int frame_num; struct STREAM_FRAME *head; }

user_defined_types: enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 }


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

result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a1 + 56) = result;
*(_QWORD *)(a2 + 8) = a1;
++*(_DWORD *)a2;
return result;
}

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

result = *(_QWORD *)(a2 + 8);
*(_QWORD *)(a1 + 56) = result;
*(_QWORD *)(a2 + 8) = a1;
++*(_DWORD *)a2;
return result;
}

original_code:
static void enqueue_to_head(stream_frame_t* stream, stream_queue_t* q)
{
    stream->next = q->head;
    q->head = stream;
    q->frame_num++;
    return;
}

canonical_original_code:
static void enqueue_to_head(struct STREAM_FRAME *stream, struct STREAM_QUEUE *q)
{
    stream->next = q->head;
    q->head = stream;
    q->frame_num++;
    return;
}

variable_types: struct STREAM_FRAME { struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 } stream_type; unsigned int pict_prop; } vstream; unsigned int id; struct STREAM_FRAME *next; } *

variable_types: struct STREAM_QUEUE { unsigned int frame_num; struct STREAM_FRAME *head; } *


decompiled_code:
__int64 __fastcall enqueue_to_tail(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a2 + 8);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 56);
}
while ( result );
*(_QWORD *)(v3 + 56) = a1;
*(_QWORD *)(a1 + 56) = 0LL;
++*(_DWORD *)a2;
}
else
{
*(_QWORD *)(a2 + 8) = a1;
*(_QWORD *)(a1 + 56) = 0LL;
++*(_DWORD *)a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = *(_QWORD *)(a2 + 8);
if ( result )
{
do
{
v3 = result;
result = *(_QWORD *)(result + 56);
}
while ( result );
*(_QWORD *)(v3 + 56) = a1;
*(_QWORD *)(a1 + 56) = 0LL;
++*(_DWORD *)a2;
}
else
{
*(_QWORD *)(a2 + 8) = a1;
*(_QWORD *)(a1 + 56) = 0LL;
++*(_DWORD *)a2;
}
return result;
}

original_code:
static void enqueue_to_tail(stream_frame_t* stream, stream_queue_t* q)
{
    stream_frame_t* node;
    node = q->head;
    if(node == ((void *)0))
    {
        q->head = stream;
        q->head->next = ((void *)0);
        q->frame_num++;
        return;
    }
    else
    {
        while(node->next != ((void *)0))
            node = node->next;
        node->next = stream;
        stream->next = ((void *)0);
        q->frame_num++;
        return;
    }
}

canonical_original_code:
static void enqueue_to_tail(struct STREAM_FRAME *stream, struct STREAM_QUEUE *q)
{
    struct STREAM_FRAME *node;
    node = q->head;
    if(node == ((void *)0))
    {
        q->head = stream;
        q->head->next = ((void *)0);
        q->frame_num++;
        return;
    }
    else
    {
        while(node->next != ((void *)0))
            node = node->next;
        node->next = stream;
        stream->next = ((void *)0);
        q->frame_num++;
        return;
    }
}


dequeue

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

if ( !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 56);
*(_QWORD *)(result + 56) = 0LL;
--*(_DWORD *)a1;
return result;
}

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

if ( !*(_DWORD *)a1 )
return 0LL;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 56);
*(_QWORD *)(result + 56) = 0LL;
--*(_DWORD *)a1;
return result;
}

original_code:
static stream_frame_t* dequeue(stream_queue_t* q)
{
    stream_frame_t* node;
    if(q->frame_num == 0)
        return ((void *)0);
    node = q->head;
    q->head = q->head->next;
    node->next = ((void *)0);
    q->frame_num--;
    return node;
}

canonical_original_code:
static struct STREAM_FRAME *dequeue(struct STREAM_QUEUE *q)
{
    struct STREAM_FRAME *node;
    if(q->frame_num == 0)
        return ((void *)0);
    node = q->head;
    q->head = q->head->next;
    node->next = ((void *)0);
    q->frame_num--;
    return node;
}

return_type: struct STREAM_FRAME { struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 } stream_type; unsigned int pict_prop; } vstream; unsigned int id; struct STREAM_FRAME *next; } *


decompiled_code:
__int64 __fastcall vbv_request_stream_frame(_QWORD *a1)
{
__int64 v1; // rbp

if ( !a1 )
return 0LL;
v1 = 0LL;
if ( !(unsigned int)lock(a1) )
{
v1 = dequeue((__int64)(a1 + 9));
unlock(a1);
if ( v1 )
*(_DWORD *)(v1 + 36) = *(_DWORD *)(v1 + 48);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 v1; // rbp

if ( !a1 )
return 0LL;
v1 = 0LL;
if ( !(unsigned int)func5(a1) )
{
v1 = func4((__int64)(a1 + 9));
func6(a1);
if ( v1 )
*(_DWORD *)(v1 + 36) = *(_DWORD *)(v1 + 48);
}
return v1;
}

original_code:
vstream_data_t* vbv_request_stream_frame(Handle vbv)
{
    stream_frame_t* frame;
    vbv_t* v;
    v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return ((void *)0);
    }
    if (lock(v) != 0)
    {
        return ((void *)0);
    }
    frame = dequeue(&v->frame_queue);
    if(frame == ((void *)0))
    {
        unlock(v);
        return ((void *)0);
    }
    unlock(v);
    frame->vstream.id = frame->id;
    return &frame->vstream;
}

canonical_original_code:
struct VIDEO_STREAM_DATA *vbv_request_stream_frame(void *vbv)
{
    struct STREAM_FRAME *frame;
    struct VBV_MANAGER *v;
    v = (struct VBV_MANAGER *)vbv;
    if (v == ((void *)0))
    {
        return ((void *)0);
    }
    if (lock(v) != 0)
    {
        return ((void *)0);
    }
    frame = dequeue(&v->frame_queue);
    if(frame == ((void *)0))
    {
        unlock(v);
        return ((void *)0);
    }
    unlock(v);
    frame->vstream.id = frame->id;
    return &frame->vstream;
}

return_type: struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 } stream_type; unsigned int pict_prop; } *


original_code:
Handle vbv_init(u32 vbv_size, u32 max_frame_num)
{
    u32 i;
    u8* vbv_buf;
    vbv_t* vbv;
    if(vbv_size == 0 || max_frame_num == 0)
        return ((void *)0);
    vbv_buf = (u8*)mem_palloc(vbv_size, 1024);
    if (vbv_buf == ((void *)0))
        return ((void *)0);
    vbv = (vbv_t*)mem_alloc(sizeof(vbv_t));
    if (vbv == ((void *)0))
    {
        mem_pfree(vbv_buf);
        return ((void *)0);
    }
    mem_set(vbv, 0, sizeof(vbv_t));
    vbv->frame_fifo.in_frames = (stream_frame_t*)mem_alloc(max_frame_num*sizeof(stream_frame_t));
    if (vbv->frame_fifo.in_frames == ((void *)0))
    {
        mem_free(vbv);
        mem_pfree(vbv_buf);
        return ((void *)0);
    }
    mem_set(vbv->frame_fifo.in_frames, 0, max_frame_num*sizeof(stream_frame_t));
    for(i=0; i<max_frame_num; i++)
    {
        vbv->frame_fifo.in_frames[i].id = i;
    }
    vbv->mutex = semaphore_create(1);
    if (vbv->mutex == ((void *)0))
    {
        mem_free(vbv->frame_fifo.in_frames);
        mem_free(vbv);
        mem_pfree(vbv_buf);
        return ((void *)0);
    }
    vbv->vbv_buf = vbv_buf;
    vbv->max_size = vbv_size;
    vbv->vbv_buf_end = vbv_buf + vbv_size - 1;
    vbv->read_addr = vbv_buf;
    vbv->write_addr = vbv->vbv_buf;
    vbv->valid_size = 0;
    vbv->frame_fifo.frame_num = 0;
    vbv->frame_fifo.read_index = 0;
    vbv->frame_fifo.write_index = 0;
    vbv->frame_fifo.max_frame_num = max_frame_num;
    vbv->frame_queue.frame_num = 0;
    vbv->frame_queue.head = ((void *)0);
    return (Handle)vbv;
}

canonical_original_code:
void *vbv_init(unsigned int vbv_size, unsigned int max_frame_num)
{
    unsigned int i;
    unsigned char *vbv_buf;
    struct VBV_MANAGER *vbv;
    if(vbv_size == 0 || max_frame_num == 0)
        return ((void *)0);
    vbv_buf = (unsigned char *)mem_palloc(vbv_size, 1024);
    if (vbv_buf == ((void *)0))
        return ((void *)0);
    vbv = (struct VBV_MANAGER *)mem_alloc(sizeof(vbv_t));
    if (vbv == ((void *)0))
    {
        mem_pfree(vbv_buf);
        return ((void *)0);
    }
    mem_set(vbv, 0, sizeof(vbv_t));
    vbv->frame_fifo.in_frames = (struct STREAM_FRAME *)mem_alloc(max_frame_num*sizeof(stream_frame_t));
    if (vbv->frame_fifo.in_frames == ((void *)0))
    {
        mem_free(vbv);
        mem_pfree(vbv_buf);
        return ((void *)0);
    }
    mem_set(vbv->frame_fifo.in_frames, 0, max_frame_num*sizeof(stream_frame_t));
    for(i=0; i<max_frame_num; i++)
    {
        vbv->frame_fifo.in_frames[i].id = i;
    }
    vbv->mutex = semaphore_create(1);
    if (vbv->mutex == ((void *)0))
    {
        mem_free(vbv->frame_fifo.in_frames);
        mem_free(vbv);
        mem_pfree(vbv_buf);
        return ((void *)0);
    }
    vbv->vbv_buf = vbv_buf;
    vbv->max_size = vbv_size;
    vbv->vbv_buf_end = vbv_buf + vbv_size - 1;
    vbv->read_addr = vbv_buf;
    vbv->write_addr = vbv->vbv_buf;
    vbv->valid_size = 0;
    vbv->frame_fifo.frame_num = 0;
    vbv->frame_fifo.read_index = 0;
    vbv->frame_fifo.write_index = 0;
    vbv->frame_fifo.max_frame_num = max_frame_num;
    vbv->frame_queue.frame_num = 0;
    vbv->frame_queue.head = ((void *)0);
    return (void *)vbv;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall vbv_release(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
semaphore_delete(v2, 1LL);
*a1 = 0LL;
}
v3 = a1[1];
if ( v3 )
{
mem_pfree(v3);
a1[1] = 0LL;
}
v4 = a1[6];
if ( v4 )
{
mem_free(v4);
a1[6] = 0LL;
}
result = mem_free(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
semaphore_delete(v2, 1LL);
*a1 = 0LL;
}
v3 = a1[1];
if ( v3 )
{
mem_pfree(v3);
a1[1] = 0LL;
}
v4 = a1[6];
if ( v4 )
{
mem_free(v4);
a1[6] = 0LL;
}
result = mem_free(a1);
}
return result;
}

original_code:
void vbv_release(Handle vbv)
{
    vbv_t* v;
    v = (vbv_t*)vbv;
    if (v)
    {
        if (v->mutex != ((void *)0))
        {
         semaphore_delete(v->mutex, 1);
            v->mutex = ((void *)0);
        }
        if (v->vbv_buf != ((void *)0))
        {
            mem_pfree(v->vbv_buf);
            v->vbv_buf = ((void *)0);
        }
        if (v->frame_fifo.in_frames)
        {
            mem_free(v->frame_fifo.in_frames);
            v->frame_fifo.in_frames = ((void *)0);
        }
        mem_free(v);
    }
    return;
}

canonical_original_code:
void vbv_release(void *vbv)
{
    struct VBV_MANAGER *v;
    v = (struct VBV_MANAGER *)vbv;
    if (v)
    {
        if (v->mutex != ((void *)0))
        {
         semaphore_delete(v->mutex, 1);
            v->mutex = ((void *)0);
        }
        if (v->vbv_buf != ((void *)0))
        {
            mem_pfree(v->vbv_buf);
            v->vbv_buf = ((void *)0);
        }
        if (v->frame_fifo.in_frames)
        {
            mem_free(v->frame_fifo.in_frames);
            v->frame_fifo.in_frames = ((void *)0);
        }
        mem_free(v);
    }
    return;
}


decompiled_code:
__int64 __fastcall vbv_request_buffer(_QWORD *a1, unsigned int *a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v8; // edx
unsigned int v9; // edx

if ( a2 == 0LL || a1 == 0LL || !a4 )
return (unsigned int)-1;
v6 = lock((_QWORD *)a4);
if ( v6 )
return (unsigned int)-1;
if ( *(_DWORD *)(a4 + 64) >= *(_DWORD *)(a4 + 68) || (v7 = *(_DWORD *)(a4 + 40), v8 = *(_DWORD *)(a4 + 44), v7 >= v8) )
{
unlock((_QWORD *)a4);
v6 = -1;
}
else
{
*a1 = *(_QWORD *)(a4 + 32);
v9 = v8 - v7;
if ( v9 > a3 )
v9 = a3;
*a2 = v9;
unlock((_QWORD *)a4);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1, unsigned int *a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v8; // edx
unsigned int v9; // edx

if ( a2 == 0LL || a1 == 0LL || !a4 )
return (unsigned int)-1;
v6 = func5((_QWORD *)a4);
if ( v6 )
return (unsigned int)-1;
if ( *(_DWORD *)(a4 + 64) >= *(_DWORD *)(a4 + 68) || (v7 = *(_DWORD *)(a4 + 40), v8 = *(_DWORD *)(a4 + 44), v7 >= v8) )
{
func6((_QWORD *)a4);
v6 = -1;
}
else
{
*a1 = *(_QWORD *)(a4 + 32);
v9 = v8 - v7;
if ( v9 > a3 )
v9 = a3;
*a2 = v9;
func6((_QWORD *)a4);
}
return v6;
}

original_code:
s32 vbv_request_buffer(u8** buf, u32* buf_size, u32 require_size, Handle vbv)
{
    vbv_t* v;
    u32 free_size;
    v = (vbv_t*)vbv;
    if (v == ((void *)0) || buf == ((void *)0) || buf_size == ((void *)0))
    {
        return -1;
    }
    if(lock(v) != 0)
        return -1;
    if (v->frame_fifo.frame_num >= v->frame_fifo.max_frame_num)
    {
        unlock(v);
        return -1;
    }
    if (v->valid_size < v->max_size)
    {
        free_size = v->max_size - v->valid_size;
        if (require_size > free_size)
            require_size = free_size;
        *buf = v->write_addr;
        *buf_size = require_size;
        unlock(v);
        return 0;
    }
    else
    {
        unlock(v);
        return -1;
    }
}

canonical_original_code:
int vbv_request_buffer(unsigned char **buf, unsigned int *buf_size, unsigned int require_size, void *vbv)
{
    struct VBV_MANAGER *v;
    unsigned int free_size;
    v = (struct VBV_MANAGER *)vbv;
    if (v == ((void *)0) || buf == ((void *)0) || buf_size == ((void *)0))
    {
        return -1;
    }
    if(lock(v) != 0)
        return -1;
    if (v->frame_fifo.frame_num >= v->frame_fifo.max_frame_num)
    {
        unlock(v);
        return -1;
    }
    if (v->valid_size < v->max_size)
    {
        free_size = v->max_size - v->valid_size;
        if (require_size > free_size)
            require_size = free_size;
        *buf = v->write_addr;
        *buf_size = require_size;
        unlock(v);
        return 0;
    }
    else
    {
        unlock(v);
        return -1;
    }
}

variable_types:
buf
unsigned char **


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

original_code:
void vbv_set_free_vbs_sem_cb(free_buffer_sem_cb cb, Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v != ((void *)0))
    {
     v->free_buffer_sem = cb;
    }
    return;
}

canonical_original_code:
void vbv_set_free_vbs_sem_cb(void (*cb)(void *handle), void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v != ((void *)0))
    {
     v->free_buffer_sem = cb;
    }
    return;
}

variable_types:
cb
void (*)(void *handle)

variable_types: struct VBV_MANAGER { void *mutex; unsigned char *vbv_buf; unsigned char *vbv_buf_end; unsigned char *read_addr; unsigned char *write_addr; unsigned int valid_size; unsigned int max_size; struct STREAM_FIFO { struct STREAM_FRAME { struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 } stream_type; unsigned int pict_prop; } vstream; unsigned int id; struct STREAM_FRAME *next; } *in_frames; unsigned int read_index; unsigned int write_index; unsigned int frame_num; unsigned int max_frame_num; } frame_fifo; struct STREAM_QUEUE { unsigned int frame_num; struct STREAM_FRAME *head; } frame_queue; void (*free_buffer_sem)(void *handle); void *parent; } *

user_defined_types: struct VBV_MANAGER { void *mutex; unsigned char *vbv_buf; unsigned char *vbv_buf_end; unsigned char *read_addr; unsigned char *write_addr; unsigned int valid_size; unsigned int max_size; struct STREAM_FIFO frame_fifo; struct STREAM_QUEUE frame_queue; void (*free_buffer_sem)(void *handle); void *parent; }


decompiled_code:
void __fastcall vbv_free_vbs_sem(_QWORD *a1)
{
void (*v1)(void); // rax

if ( a1 && !(unsigned int)lock(a1) )
{
v1 = (void (*)(void))a1[11];
if ( v1 )
{
if ( a1[12] )
v1();
}
unlock(a1);
}
}

canonical_decompiled_code:
void __fastcall func14(_QWORD *a1)
{
void (*v1)(void); // rax

if ( a1 && !(unsigned int)func5(a1) )
{
v1 = (void (*)(void))a1[11];
if ( v1 )
{
if ( a1[12] )
v1();
}
func6(a1);
}
}

original_code:
void vbv_free_vbs_sem(Handle vbv)
{
    vbv_t* v;
    v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return;
    }
    if (lock(v) != 0)
    {
        return;
    }
    if(v->free_buffer_sem && v->parent)
    {
     v->free_buffer_sem(v->parent);
    }
    unlock(v);
}

canonical_original_code:
void vbv_free_vbs_sem(void *vbv)
{
    struct VBV_MANAGER *v;
    v = (struct VBV_MANAGER *)vbv;
    if (v == ((void *)0))
    {
        return;
    }
    if (lock(v) != 0)
    {
        return;
    }
    if(v->free_buffer_sem && v->parent)
    {
     v->free_buffer_sem(v->parent);
    }
    unlock(v);
}


original_code:
void vbv_flush_stream_frame(vstream_data_t* stream, Handle vbv)
{
    u32 read_index;
    vbv_t* v;
    v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return;
    }
    if (lock(v) != 0)
    {
        return;
    }
    if (v->frame_fifo.frame_num == 0)
    {
        unlock(v);
        return;
    }
    read_index = v->frame_fifo.read_index;
    if(stream != &v->frame_fifo.in_frames[read_index].vstream)
    {
        unlock(v);
        return;
    }
    read_index++;
    if (read_index == v->frame_fifo.max_frame_num)
    {
        read_index = 0;
    }
    v->frame_fifo.read_index = read_index;
    v->frame_fifo.frame_num--;
    v->valid_size -= stream->length;
    v->read_addr += stream->length;
    if (v->read_addr > v->vbv_buf_end)
    {
        v->read_addr -= v->max_size;
    }
    unlock(v);
    return;
}

canonical_original_code:
void vbv_flush_stream_frame(struct VIDEO_STREAM_DATA *stream, void *vbv)
{
    unsigned int read_index;
    struct VBV_MANAGER *v;
    v = (struct VBV_MANAGER *)vbv;
    if (v == ((void *)0))
    {
        return;
    }
    if (lock(v) != 0)
    {
        return;
    }
    if (v->frame_fifo.frame_num == 0)
    {
        unlock(v);
        return;
    }
    read_index = v->frame_fifo.read_index;
    if(stream != &v->frame_fifo.in_frames[read_index].vstream)
    {
        unlock(v);
        return;
    }
    read_index++;
    if (read_index == v->frame_fifo.max_frame_num)
    {
        read_index = 0;
    }
    v->frame_fifo.read_index = read_index;
    v->frame_fifo.frame_num--;
    v->valid_size -= stream->length;
    v->read_addr += stream->length;
    if (v->read_addr > v->vbv_buf_end)
    {
        v->read_addr -= v->max_size;
    }
    unlock(v);
    return;
}

variable_types: struct VIDEO_STREAM_DATA { unsigned char *data; unsigned int length; unsigned long long pts; unsigned long long pcr; unsigned char valid; unsigned int id; enum CEDARV_STREAM_TYPE { CEDARV_STREAM_TYPE_MAJOR=0, CEDARV_STREAM_TYPE_MINOR=1 } stream_type; unsigned int pict_prop; } *


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

if ( a1 )
result = *(unsigned int *)(a1 + 72);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 72);
else
result = 0LL;
return result;
}

original_code:
u32 vbv_get_stream_num(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->frame_queue.frame_num;
}

canonical_original_code:
unsigned int vbv_get_stream_num(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->frame_queue.frame_num;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 32);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 32);
else
result = 0LL;
return result;
}

original_code:
u8* vbv_get_current_write_addr(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return ((void *)0);
    }
    return v->write_addr;
}

canonical_original_code:
unsigned char *vbv_get_current_write_addr(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return ((void *)0);
    }
    return v->write_addr;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 40);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 40);
else
result = 0LL;
return result;
}

original_code:
u32 vbv_get_valid_data_size(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->valid_size;
}

canonical_original_code:
unsigned int vbv_get_valid_data_size(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->valid_size;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 64);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 64);
else
result = 0LL;
return result;
}

original_code:
u32 vbv_get_valid_frame_num(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->frame_fifo.frame_num;
}

canonical_original_code:
unsigned int vbv_get_valid_frame_num(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->frame_fifo.frame_num;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 68);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 68);
else
result = 0LL;
return result;
}

original_code:
u32 vbv_get_max_stream_frame_num(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->frame_fifo.max_frame_num;
}

canonical_original_code:
unsigned int vbv_get_max_stream_frame_num(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v == ((void *)0))
    {
        return 0;
    }
    return v->frame_fifo.max_frame_num;
}


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

original_code:
void vbv_set_parent(void* parent, Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v != ((void *)0))
    {
     v->parent = parent;
    }
    return;
}

canonical_original_code:
void vbv_set_parent(void *parent, void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v != ((void *)0))
    {
     v->parent = parent;
    }
    return;
}

variable_types:
parent
void *


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

if ( a1 )
result = *(_QWORD *)(a1 + 96);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 96);
else
result = 0LL;
return result;
}

original_code:
void* vbv_get_parent(Handle vbv)
{
    vbv_t* v = (vbv_t*)vbv;
    if (v != ((void *)0))
     return v->parent;
    else
     return ((void *)0);
}

canonical_original_code:
void *vbv_get_parent(void *vbv)
{
    struct VBV_MANAGER *v = (vbv_t*)vbv;
    if (v != ((void *)0))
     return v->parent;
    else
     return ((void *)0);
}


decompiled_code:
void __fastcall flush_stream_frame(__int64 a1, _QWORD *a2)
{
vbv_flush_stream_frame(a1, (__int64)a2);
vbv_free_vbs_sem(a2);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, _QWORD *a2)
{
func15(a1, (__int64)a2);
func14(a2);
}

original_code:
static void flush_stream_frame(vstream_data_t* stream, Handle vbv)
{
    vbv_flush_stream_frame(stream, vbv);
    vbv_free_vbs_sem(vbv);
}

canonical_original_code:
static void flush_stream_frame(struct VIDEO_STREAM_DATA *stream, void *vbv)
{
    vbv_flush_stream_frame(stream, vbv);
    vbv_free_vbs_sem(vbv);
}


decompiled_code:
void ve_enable_intr()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void ve_enable_intr(u8 enable)
{
}

canonical_original_code:
static void ve_enable_intr(unsigned char enable)
{
}

variable_types:
enable
unsigned char


decompiled_code:
__int64 ve_get_reg_base_addr()
{
return *((unsigned int *)cedarv_osal_ctx + 3);
}

canonical_decompiled_code:
__int64 func1()
{
return *((unsigned int *)cedarv_osal_ctx + 3);
}

original_code:
static u32 ve_get_reg_base_addr(void)
{
 return cedarv_osal_ctx->env_info.address_macc;
}

canonical_original_code:
static unsigned int ve_get_reg_base_addr()
{
 return cedarv_osal_ctx->env_info.address_macc;
}


decompiled_code:
__int64 ve_get_memtype()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 5LL;
}

original_code:
static memtype_e ve_get_memtype(void)
{
    return MEMTYPE_DDR3_32BITS;
}

canonical_original_code:
static enum MEMORY_TYPE ve_get_memtype()
{
    return MEMTYPE_DDR3_32BITS;
}

return_type: enum MEMORY_TYPE { MEMTYPE_DDR1_16BITS=0, MEMTYPE_DDR1_32BITS=1, MEMTYPE_DDR2_16BITS=2, MEMTYPE_DDR2_32BITS=3, MEMTYPE_DDR3_16BITS=4, MEMTYPE_DDR3_32BITS=5 }


decompiled_code:
int ve_reset_hardware()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x103uLL, 0LL);
}

canonical_decompiled_code:
int func4()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x103uLL, 0LL);
}

original_code:
static void ve_reset_hardware(void)
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_RESET_VE, 0);
    return;
}

canonical_original_code:
static void ve_reset_hardware()
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_RESET_VE, 0);
    return;
}


decompiled_code:
__int64 cedarv_wait_ve_ready()
{
return (unsigned int)(ioctl(*(_DWORD *)cedarv_osal_ctx, 0x102uLL, 2LL) - 1);
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)(ioctl(*(_DWORD *)cedarv_osal_ctx, 0x102uLL, 2LL) - 1);
}

original_code:
int cedarv_wait_ve_ready()
{
    int status;
 status = ioctl(cedarv_osal_ctx->fd, IOCTL_WAIT_VE, 2);
 return (status - 1);
}

variable_types: status int


decompiled_code:
__int64 ve_wait_intr()
{
return cedarv_wait_ve_ready();
}

canonical_decompiled_code:
__int64 func6()
{
return func5();
}

original_code:
static s32 ve_wait_intr(void)
{
 return cedarv_wait_ve_ready();
}

canonical_original_code:
static int ve_wait_intr()
{
 return cedarv_wait_ve_ready();
}


decompiled_code:
int cedarv_request_ve_core()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x206uLL, 0LL);
}

canonical_decompiled_code:
int func7()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x206uLL, 0LL);
}

original_code:
void cedarv_request_ve_core()
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_ENGINE_REQ, 0);
}


decompiled_code:
int cedarv_release_ve_core()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x207uLL, 0LL);
}

canonical_decompiled_code:
int func8()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x207uLL, 0LL);
}

original_code:
void cedarv_release_ve_core()
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_ENGINE_REL, 0);
}


decompiled_code:
__int64 avs_counter_get_time_ms()
{
unsigned int v0; // eax
__int64 v1; // rbx

pthread_mutex_lock(&cedarv_osal_mutex);
v0 = ioctl(*(_DWORD *)cedarv_osal_ctx, 0x201uLL, 0LL);
if ( ((avs_cnt_last ^ v0) & 0x80000000) != 0 )
wall_clock += 0xFFFFFFFFLL;
avs_cnt_last = v0;
v1 = (wall_clock + v0) / 50;
pthread_mutex_unlock(&cedarv_osal_mutex);
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // eax
__int64 v1; // rbx

pthread_mutex_lock(&cedarv_osal_mutex);
v0 = ioctl(*(_DWORD *)cedarv_osal_ctx, 0x201uLL, 0LL);
if ( ((avs_cnt_last ^ v0) & 0x80000000) != 0 )
wall_clock += 0xFFFFFFFFLL;
avs_cnt_last = v0;
v1 = (wall_clock + v0) / 50;
pthread_mutex_unlock(&cedarv_osal_mutex);
return v1;
}

original_code:
long long avs_counter_get_time_ms()
{
 unsigned int avs_cnt_curr;
 long long val;
 pthread_mutex_lock(&cedarv_osal_mutex);
 avs_cnt_curr = ioctl(cedarv_osal_ctx->fd, IOCTL_GETVALUE_AVS2, 0);
 if((avs_cnt_curr ^ avs_cnt_last)>>31){
  wall_clock += 0x00000000ffffffffLL;
 }
 avs_cnt_last = avs_cnt_curr;
 val = (wall_clock + avs_cnt_curr) / ((50*1000) / 1000);
 pthread_mutex_unlock(&cedarv_osal_mutex);
 return val;
}

variable_types:
val
long long

return_type: long long


decompiled_code:
int cedarv_enable_ve_core()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x104uLL, 0LL);
}

canonical_decompiled_code:
int func12()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x104uLL, 0LL);
}

original_code:
void cedarv_enable_ve_core()
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_ENABLE_VE, 0);
}


decompiled_code:
int cedarv_disable_ve_core()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x105uLL, 0LL);
}

canonical_decompiled_code:
int func13()
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x105uLL, 0LL);
}

original_code:
void cedarv_disable_ve_core()
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_DISABLE_VE, 0);
}


decompiled_code:
int __fastcall cedarv_set_ve_freq(unsigned int a1)
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x106uLL, a1);
}

canonical_decompiled_code:
int __fastcall func14(unsigned int a1)
{
return ioctl(*(_DWORD *)cedarv_osal_ctx, 0x106uLL, a1);
}

original_code:
void cedarv_set_ve_freq(int freq)
{
 ioctl(cedarv_osal_ctx->fd, IOCTL_SET_VE_FREQ, freq);
}

variable_types: freq int


decompiled_code:
int __fastcall ve_enable_clock(char a1, unsigned int a2)
{
if ( !a1 )
return cedarv_disable_ve_core();
cedarv_enable_ve_core();
return cedarv_set_ve_freq(a2 / 0xF4240);
}

canonical_decompiled_code:
int __fastcall func15(char a1, unsigned int a2)
{
if ( !a1 )
return func13();
func12();
return func14(a2 / 0xF4240);
}

original_code:
static void ve_enable_clock(u8 enable, u32 speed)
{
    if(enable)
    {
     cedarv_enable_ve_core();
     cedarv_set_ve_freq(speed / 1000000);
    }
    else
    {
     cedarv_disable_ve_core();
    }
}

canonical_original_code:
static void ve_enable_clock(unsigned char enable, unsigned int speed)
{
    if(enable)
    {
     cedarv_enable_ve_core();
     cedarv_set_ve_freq(speed / 1000000);
    }
    else
    {
     cedarv_disable_ve_core();
    }
}

variable_types:
speed
unsigned int


decompiled_code:
void ve_init_clock()
{
;
}

canonical_decompiled_code:
void func16()
{
;
}

original_code:
void ve_init_clock(void)
{
    return;
}

canonical_original_code:
void ve_init_clock()
{
    return;
}


decompiled_code:
void ve_release_clock()
{
;
}

canonical_decompiled_code:
void func17()
{
;
}

original_code:
void ve_release_clock(void)
{
    return;
}

canonical_original_code:
void ve_release_clock()
{
    return;
}


decompiled_code:
__int64 __fastcall fib_base(unsigned __int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = 1LL;
if ( a1 > 2 )
{
v2 = fib_base(a1 - 2);
result = v2 + fib_base(a1 - 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = 1LL;
if ( a1 > 2 )
{
v2 = func7(a1 - 2);
result = v2 + func7(a1 - 1);
}
return result;
}

original_code:
fibnum fib_base(fibnum x)
{
 if(x <= 2) return 1;
 else return (fib_base(x-2) + fib_base(x-1));
}

canonical_original_code:
unsigned long fib_base(unsigned long x)
{
 if(x <= 2) return 1;
 else return (fib_base(x-2) + fib_base(x-1));
}

variable_types:
x
unsigned long

return_type: unsigned long


decompiled_code:
void *__fastcall fib_th2(void *a1)
{
*((_QWORD *)a1 + 2) = fib_base(*((_QWORD *)a1 + 1));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
*((_QWORD *)a1 + 2) = func7(*((_QWORD *)a1 + 1));
return 0LL;
}

original_code:
void *fib_th2(void *arg)
{
 struct th *th = (struct th *)arg;
 ((void)0);
 th->y = fib_base(th->x);
 return ((void *) (0)) ;
}

variable_types:
arg
void *

variable_types: struct th { unsigned long th; unsigned long x; unsigned long y; } *


original_code:
void *fib_th1(void *arg)
{
 struct th *th = (struct th *)arg;
 ((void)0);
 th->y = fib(th->x);
 return ((void *) (0)) ;
}

user_defined_types: struct th { unsigned long th; unsigned long x; unsigned long y; }


fib

decompiled_code:
__int64 __fastcall fib(int a1)
{
__int64 result; // rax
pthread_t th[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v3; // [rsp+10h] [rbp-38h]
pthread_t newthread[2]; // [rsp+20h] [rbp-28h] BYREF
__int64 v5; // [rsp+30h] [rbp-18h]

result = 1LL;
if ( a1 > 2 )
{
th[1] = a1 - 2;
newthread[1] = a1 - 1;
v5 = 0LL;
v3 = 0LL;
pthread_create(th, 0LL, fib_th2, th);
pthread_create(newthread, 0LL, fib_th2, newthread);
pthread_join(th[0], 0LL);
pthread_join(newthread[0], 0LL);
result = v3 + v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
__int64 result; // rax
pthread_t th[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v3; // [rsp+10h] [rbp-38h]
pthread_t newthread[2]; // [rsp+20h] [rbp-28h] BYREF
__int64 v5; // [rsp+30h] [rbp-18h]

result = 1LL;
if ( a1 > 2 )
{
th[1] = a1 - 2;
newthread[1] = a1 - 1;
v5 = 0LL;
v3 = 0LL;
pthread_create(th, 0LL, fib_th2, th);
pthread_create(newthread, 0LL, fib_th2, newthread);
pthread_join(th[0], 0LL);
pthread_join(newthread[0], 0LL);
result = v3 + v5;
}
return result;
}

original_code:
fibnum fib (int x)
{
 ((void)0);
 if(x <= 2) return 1;
 else
 {
  struct th th1, th2;
  th1.x = (fibnum) (x-2);
  th2.x = (fibnum) (x-1);
  th1.y = th2.y = 0;
  pthread_create(&th1.th, ((void *)0), fib_th2, (void *)(&th1));
  pthread_create(&th2.th, ((void *)0), fib_th2, (void *)(&th2));
  pthread_join(th1.th, ((void *)0));
  pthread_join(th2.th, ((void *)0));
  return (th1.y + th2.y);
 }
}

canonical_original_code:
unsigned long fib(int x)
{
 ((void)0);
 if(x <= 2) return 1;
 else
 {
  struct th th1; struct th th2;
  th1.x = (fibnum) (x-2);
  th2.x = (fibnum) (x-1);
  th1.y = th2.y = 0;
  pthread_create(&th1.th, ((void *)0), fib_th2, (void *)(&th1));
  pthread_create(&th2.th, ((void *)0), fib_th2, (void *)(&th2));
  pthread_join(th1.th, ((void *)0));
  pthread_join(th2.th, ((void *)0));
  return (th1.y + th2.y);
 }
}

variable_types: x int

variable_types: struct th { unsigned long th; unsigned long x; unsigned long y; }


main

canonical_name: main

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

v3 = (unsigned int)atoi(argv[1]);
printf("arg is: %d\n", v3);
v4 = fib(v3);
printf("fib(%d) = %lu\n", (unsigned int)v3, v4);
return 0;
}

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

v3 = (unsigned int)atoi(argv[1]);
printf("arg is: %d\n", v3);
v4 = func9(v3);
printf("fib(%d) = %lu\n", (unsigned int)v3, v4);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int x = atoi(argv[1]);
 printf("arg is: %d\n", x);
 printf("fib(%d) = %""l" "u""\n",x, fib(x));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: linuxstb/dvbtools

decompiled_code:
time_t __fastcall scan_date()
{
time_t v0; // rbp
int v1; // eax
int v2; // ebx
int v3; // ebp
char v5; // [rsp+0h] [rbp-1068h]
struct pollfd fds; // [rsp+8h] [rbp-1060h] BYREF
__int16 v7; // [rsp+10h] [rbp-1058h] BYREF
__int64 v8; // [rsp+12h] [rbp-1056h]
__int64 v9; // [rsp+1Ah] [rbp-104Eh]
__int64 v10; // [rsp+22h] [rbp-1046h]
__int64 v11; // [rsp+2Ah] [rbp-103Eh]
int v12; // [rsp+44h] [rbp-1024h]
int v13; // [rsp+48h] [rbp-1020h]
char buf[3]; // [rsp+50h] [rbp-1018h] BYREF
unsigned __int8 v15[4117]; // [rsp+53h] [rbp-1015h] BYREF

v1 = open("/dev/dvb/adapter0/demux0", 2050);
if ( v1 < 0 )
{
perror("fd_date DEVICE: ");
v0 = -1LL;
}
else
{
v2 = v1;
v7 = 20;
v8 = 112LL;
v9 = 0LL;
v10 = 255LL;
v11 = 0LL;
v12 = 0;
v13 = 4;
if ( ioctl(v1, 0x403C6F2BuLL, &v7) < 0 )
{
perror("DATE - DMX_SET_FILTER:");
close(v2);
v0 = -1LL;
}
else
{
fds.fd = v2;
fds.events = 2;
if ( poll(&fds, 1uLL, 10000) < 0 )
{
errmsg("TIMEOUT reading from fd_date\n", v5);
close(v2);
}
else
{
if ( read(v2, buf, 3uLL) != 3 )
{
errmsg("Nothing to read from fd_date - try tuning to a multiplex?\n", v5);
exit(1);
}
v3 = (unsigned __int8)buf[2] | ((unsigned __int8)buf[1] << 8) & 0xF00;
if ( v3 != (unsigned int)read(v2, v15, v3) )
{
errmsg("Under-read bytes for DATE - wanted %d, got %d\n", v5);
exit(1);
}
v0 = convert_date(v15);
close(v2);
}
}
}
return v0;
}

canonical_decompiled_code:
time_t __fastcall func8()
{
time_t v0; // rbp
int v1; // eax
int v2; // ebx
int v3; // ebp
char v5; // [rsp+0h] [rbp-1068h]
struct pollfd fds; // [rsp+8h] [rbp-1060h] BYREF
__int16 v7; // [rsp+10h] [rbp-1058h] BYREF
__int64 v8; // [rsp+12h] [rbp-1056h]
__int64 v9; // [rsp+1Ah] [rbp-104Eh]
__int64 v10; // [rsp+22h] [rbp-1046h]
__int64 v11; // [rsp+2Ah] [rbp-103Eh]
int v12; // [rsp+44h] [rbp-1024h]
int v13; // [rsp+48h] [rbp-1020h]
char buf[3]; // [rsp+50h] [rbp-1018h] BYREF
unsigned __int8 v15[4117]; // [rsp+53h] [rbp-1015h] BYREF

v1 = open("/dev/dvb/adapter0/demux0", 2050);
if ( v1 < 0 )
{
perror("fd_date DEVICE: ");
v0 = -1LL;
}
else
{
v2 = v1;
v7 = 20;
v8 = 112LL;
v9 = 0LL;
v10 = 255LL;
v11 = 0LL;
v12 = 0;
v13 = 4;
if ( ioctl(v1, 0x403C6F2BuLL, &v7) < 0 )
{
perror("DATE - DMX_SET_FILTER:");
close(v2);
v0 = -1LL;
}
else
{
fds.fd = v2;
fds.events = 2;
if ( poll(&fds, 1uLL, 10000) < 0 )
{
func10("TIMEOUT reading from fd_date\n", v5);
close(v2);
}
else
{
if ( read(v2, buf, 3uLL) != 3 )
{
func10("Nothing to read from fd_date - try tuning to a multiplex?\n", v5);
exit(1);
}
v3 = (unsigned __int8)buf[2] | ((unsigned __int8)buf[1] << 8) & 0xF00;
if ( v3 != (unsigned int)read(v2, v15, v3) )
{
func10("Under-read bytes for DATE - wanted %d, got %d\n", v5);
exit(1);
}
v0 = func7(v15);
close(v2);
}
}
}
return v0;
}

original_code:
time_t scan_date() {
  int fd_date;
  int n,seclen;
  int i;
  time_t t;
  unsigned char buf[4096];
  struct dmx_sct_filter_params sctFilterParams;
  struct pollfd ufd;
  t = 0;
  if((fd_date = open("/dev/dvb/adapter0/demux0",02|04000)) < 0){
      perror("fd_date DEVICE: ");
      return -1;
  }
  sctFilterParams.pid=0x14;
  memset(&sctFilterParams.filter.filter,0,16);
  memset(&sctFilterParams.filter.mask,0,16);
  sctFilterParams.timeout = 0;
  sctFilterParams.flags = 4;
  sctFilterParams.filter.filter[0]=0x70;
  sctFilterParams.filter.mask[0]=0xff;
  if (ioctl(fd_date,(((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((43)) << 0) | ((((sizeof(struct dmx_sct_filter_params)))) << ((0 +8)+8))),&sctFilterParams) < 0) {
    perror("DATE - DMX_SET_FILTER:");
    close(fd_date);
    return -1;
  }
  ufd.fd=fd_date;
  ufd.events=0x002;
  if (poll(&ufd,1,10000) < 0) {
     errmsg("TIMEOUT reading from fd_date\n");
     close(fd_date);
     return;
  }
  if (read(fd_date,buf,3)==3) {
    seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff);
    n = read(fd_date,buf+3,seclen);
    if (n==seclen) {
      t = convert_date(&(buf[3]));
    } else {
      errmsg("Under-read bytes for DATE - wanted %d, got %d\n",seclen,n);
      exit(1);
    }
  } else {
    errmsg("Nothing to read from fd_date - try tuning to a multiplex?\n");
    exit(1);
  }
  close(fd_date);
  return(t);
}

canonical_original_code:
long scan_date() {
  int fd_date;
  int n; int seclen;
  int i;
  long t;
  unsigned char buf[4096];
  struct dmx_sct_filter_params sctFilterParams;
  struct pollfd ufd;
  t = 0;
  if((fd_date = open("/dev/dvb/adapter0/demux0",02|04000)) < 0){
      perror("fd_date DEVICE: ");
      return -1;
  }
  sctFilterParams.pid=0x14;
  memset(&sctFilterParams.filter.filter,0,16);
  memset(&sctFilterParams.filter.mask,0,16);
  sctFilterParams.timeout = 0;
  sctFilterParams.flags = 4;
  sctFilterParams.filter.filter[0]=0x70;
  sctFilterParams.filter.mask[0]=0xff;
  if (ioctl(fd_date,(((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((43)) << 0) | ((((sizeof(struct dmx_sct_filter_params)))) << ((0 +8)+8))),&sctFilterParams) < 0) {
    perror("DATE - DMX_SET_FILTER:");
    close(fd_date);
    return -1;
  }
  ufd.fd=fd_date;
  ufd.events=0x002;
  if (poll(&ufd,1,10000) < 0) {
     errmsg("TIMEOUT reading from fd_date\n");
     close(fd_date);
     return;
  }
  if (read(fd_date,buf,3)==3) {
    seclen=((buf[1] & 0x0f) << 8) | (buf[2] & 0xff);
    n = read(fd_date,buf+3,seclen);
    if (n==seclen) {
      t = convert_date(&(buf[3]));
    } else {
      errmsg("Under-read bytes for DATE - wanted %d, got %d\n",seclen,n);
      exit(1);
    }
  } else {
    errmsg("Nothing to read from fd_date - try tuning to a multiplex?\n");
    exit(1);
  }
  close(fd_date);
  return(t);
}

variable_types: n int

variable_types: seclen int

variable_types: i int

variable_types: t long

variable_types:
buf
unsigned char [4096]

variable_types: struct dmx_sct_filter_params { unsigned short pid; struct dmx_filter { unsigned char filter[16]; unsigned char mask[16]; unsigned char mode[16]; } filter; unsigned int timeout; unsigned int flags; }

variable_types: struct pollfd { int fd; short events; short revents; }

return_type: long

user_defined_types: struct dmx_sct_filter_params { unsigned short pid; struct dmx_filter filter; unsigned int timeout; unsigned int flags; }


decompiled_code:
int __fastcall set_time(const time_t *a1)
{
int result; // eax

result = stime(a1);
if ( result )
{
perror("Unable to set time");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const time_t *a1)
{
int result; // eax

result = stime(a1);
if ( result )
{
perror("Unable to set time");
exit(1);
}
return result;
}

original_code:
int set_time(time_t *new_time)
{
  if (stime(new_time)) {
    perror("Unable to set time");
    exit(1);
  }
}

canonical_original_code:
int set_time(long *new_time)
{
  if (stime(new_time)) {
    perror("Unable to set time");
    exit(1);
  }
}


errmsg

decompiled_code:
int errmsg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: ", (const char *)ProgName);
return vfprintf(stderr, format, arg);
}

canonical_decompiled_code:
int func10(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fprintf(stderr, "%s: ", (const char *)ProgName);
return vfprintf(stderr, format, arg);
}

original_code:
void
errmsg(char *message, ...)
{
  va_list ap;
  __builtin_va_start(ap,message);
  fprintf(stderr, "%s: ", ProgName);
  vfprintf(stderr, message, ap);
  __builtin_va_end(ap);
}

canonical_original_code:
void errmsg(char *message, ...)
{
  __builtin_va_list ap;
  __builtin_va_start(ap,message);
  fprintf(stderr, "%s: ", ProgName);
  vfprintf(stderr, message, ap);
  __builtin_va_end(ap);
}

variable_types:
message
char *


usage

decompiled_code:
void __noreturn usage()
{
fprintf(stderr, "usage: %s [-p] [-s] [-f] [-q] [-h]\n", (const char *)ProgName);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11()
{
fprintf(stderr, "usage: %s [-p] [-s] [-f] [-q] [-h]\n", (const char *)ProgName);
exit(1);
}

original_code:
void
usage()
{
  fprintf(stderr, "usage: %s [-p] [-s] [-f] [-q] [-h]\n", ProgName);
  exit(1);
}


help

decompiled_code:
void __noreturn help()
{
fprintf(
stderr,
"\n"
"help:\n"
"%s [-p] [-s] [-f] [-q] [-h]\n"
" --print\t(print current time, DTT time and delta)\n"
" --set\t(set the system clock to DTT time)\n"
" --force\t(force the setting of the clock)\n"
" --quiet\t(be silent)\n"
" --help\t(display this message)\n",
(const char *)ProgName);
exit(1);
}

canonical_decompiled_code:
void __noreturn func12()
{
fprintf(
stderr,
"\n"
"help:\n"
"%s [-p] [-s] [-f] [-q] [-h]\n"
" --print\t(print current time, DTT time and delta)\n"
" --set\t(set the system clock to DTT time)\n"
" --force\t(force the setting of the clock)\n"
" --quiet\t(be silent)\n"
" --help\t(display this message)\n",
(const char *)ProgName);
exit(1);
}

original_code:
void
help()
{
  fprintf(stderr,
   "\nhelp:\n"
   "%s [-p] [-s] [-f] [-q] [-h]\n"
   "  --print	(print current time, DTT time and delta)\n"
   "  --set	(set the system clock to DTT time)\n"
   "  --force	(force the setting of the clock)\n"
   "  --quiet	(be silent)\n"
   "  --help	(display this message)\n", ProgName);
  exit(1);
}


decompiled_code:
int __fastcall do_options(int argc, char **argv)
{
int result; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
result = getopt_long(argc, argv, "psfqh", &Long_Options_0, longind);
if ( result == -1 )
return result;
if ( result > 115 )
goto LABEL_16;
if ( result > 101 )
{
switch ( result )
{
case 'f':
do_force = 1;
continue;
case 'h':
help();
return result;
case 'p':
do_print = 1;
continue;
case 'q':
do_quiet = 1;
continue;
case 's':
do_set = 1;
continue;
default:
goto LABEL_16;
}
}
if ( result )
{
if ( result == 63 )
usage();
LABEL_16:
fprintf(stderr, "%s: unknown getopt error - returned code %02x\n", (const char *)ProgName, (unsigned int)result);
exit(1);
}
printf("long option index %d\n", (unsigned int)longind[0]);
if ( longind[0] > 4u )
{
fprintf(stderr, "%s: unknown long option %d\n", (const char *)ProgName, (unsigned int)longind[0]);
usage();
}
}
}

canonical_decompiled_code:
int __fastcall func13(int argc, char **argv)
{
int result; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
while ( 1 )
{
result = getopt_long(argc, argv, "psfqh", &Long_Options_0, longind);
if ( result == -1 )
return result;
if ( result > 115 )
goto LABEL_16;
if ( result > 101 )
{
switch ( result )
{
case 'f':
do_force = 1;
continue;
case 'h':
func12();
return result;
case 'p':
do_print = 1;
continue;
case 'q':
do_quiet = 1;
continue;
case 's':
do_set = 1;
continue;
default:
goto LABEL_16;
}
}
if ( result )
{
if ( result == 63 )
func11();
LABEL_16:
fprintf(stderr, "%s: unknown getopt error - returned code %02x\n", (const char *)ProgName, (unsigned int)result);
exit(1);
}
printf("long option index %d\n", (unsigned int)longind[0]);
if ( longind[0] > 4u )
{
fprintf(stderr, "%s: unknown long option %d\n", (const char *)ProgName, (unsigned int)longind[0]);
func11();
}
}
}

original_code:
int
do_options(int arg_count, char** arg_strings)
{
  static struct option Long_Options[]=
    {
      {"print", 0, 0, 'p'},
      {"set", 0, 0, 's'},
      {"force", 0, 0, 'f'},
      {"quiet", 0, 0, 'q'},
      {"help", 0, 0, 'h'},
      {0, 0, 0, 0}
    };
  int c;
  int Option_Index = 0;
  while (1)
    {
      c = getopt_long(arg_count, arg_strings, "psfqh", Long_Options, &Option_Index);
      if (c == (-1))
 break;
      switch (c)
 {
      case 'p':
 do_print = 1;
 break;
      case 's':
 do_set = 1;
 break;
      case 'f':
 do_force = 1;
 break;
      case 'q':
 do_quiet = 1;
 break;
      case 'h':
 help();
 break;
      case '?':
 usage();
 break;
      case 0:
 printf("long option index %d\n", Option_Index);
 switch (Option_Index)
   {
 case 0:
 case 1:
 case 2:
 case 3:
 case 4:
   break;
 default:
   fprintf(stderr, "%s: unknown long option %d\n", ProgName, Option_Index);
   usage();
   }
 break;
     default:
   fprintf(stderr, "%s: unknown getopt error - returned code %02x\n", ProgName, c);
   exit(1);
 }
    }
}

canonical_original_code:
int do_options(int arg_count, char **arg_strings)
{
  static struct option Long_Options[] = {
      {"print", 0, 0, 'p'},
      {"set", 0, 0, 's'},
      {"force", 0, 0, 'f'},
      {"quiet", 0, 0, 'q'},
      {"help", 0, 0, 'h'},
      {0, 0, 0, 0}
    };
  int c;
  int Option_Index = 0;
  while (1)
    {
      c = getopt_long(arg_count, arg_strings, "psfqh", Long_Options, &Option_Index);
      if (c == (-1))
 break;
      switch (c)
 {
      case 'p':
 do_print = 1;
 break;
      case 's':
 do_set = 1;
 break;
      case 'f':
 do_force = 1;
 break;
      case 'q':
 do_quiet = 1;
 break;
      case 'h':
 help();
 break;
      case '?':
 usage();
 break;
      case 0:
 printf("long option index %d\n", Option_Index);
 switch (Option_Index)
   {
 case 0:
 case 1:
 case 2:
 case 3:
 case 4:
   break;
 default:
   fprintf(stderr, "%s: unknown long option %d\n", ProgName, Option_Index);
   usage();
   }
 break;
     default:
   fprintf(stderr, "%s: unknown getopt error - returned code %02x\n", ProgName, c);
   exit(1);
 }
    }
}

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: c int


original_code:
time_t convert_date(char *dvb_buf)
{
  int i;
  int year, month, day, hour, min, sec;
  long int mjd;
  struct tm dvb_time;
  mjd = (dvb_buf[0] & 0xff) << 8;
  mjd += (dvb_buf[1] & 0xff);
  hour = ((((dvb_buf[2] & 0xff & 0xf0) >> 4) * 10) + (dvb_buf[2] & 0xff & 0x0f));
  min = ((((dvb_buf[3] & 0xff & 0xf0) >> 4) * 10) + (dvb_buf[3] & 0xff & 0x0f));
  sec = ((((dvb_buf[4] & 0xff & 0xf0) >> 4) * 10) + (dvb_buf[4] & 0xff & 0x0f));
  year = (int)((mjd - 15078.2)/365.25);
  month = (int)((mjd - 14956.1 - (int)(year * 365.25))/30.6001);
  day = mjd - 14956 - (int)(year * 365.25) - (int)(month * 30.6001);
  if (month == 14 || month == 15)
    i = 1;
  else
    i = 0;
  year += i;
  month = month - 1 - i * 12;
  dvb_time.tm_sec = sec;
  dvb_time.tm_min = min;
  dvb_time.tm_hour = hour;
  dvb_time.tm_mday = day;
  dvb_time.tm_mon = month - 1;
  dvb_time.tm_year = year;
  dvb_time.tm_isdst = 0;
  dvb_time.tm_wday = 0;
  dvb_time.tm_yday = 0;
  return(mktime(&dvb_time));
}

canonical_original_code:
long convert_date(char *dvb_buf)
{
  int i;
  int year; int month; int day; int hour; int min; int sec;
  long mjd;
  struct tm dvb_time;
  mjd = (dvb_buf[0] & 0xff) << 8;
  mjd += (dvb_buf[1] & 0xff);
  hour = ((((dvb_buf[2] & 0xff & 0xf0) >> 4) * 10) + (dvb_buf[2] & 0xff & 0x0f));
  min = ((((dvb_buf[3] & 0xff & 0xf0) >> 4) * 10) + (dvb_buf[3] & 0xff & 0x0f));
  sec = ((((dvb_buf[4] & 0xff & 0xf0) >> 4) * 10) + (dvb_buf[4] & 0xff & 0x0f));
  year = (int)((mjd - 15078.2)/365.25);
  month = (int)((mjd - 14956.1 - (int)(year * 365.25))/30.6001);
  day = mjd - 14956 - (int)(year * 365.25) - (int)(month * 30.6001);
  if (month == 14 || month == 15)
    i = 1;
  else
    i = 0;
  year += i;
  month = month - 1 - i * 12;
  dvb_time.tm_sec = sec;
  dvb_time.tm_min = min;
  dvb_time.tm_hour = hour;
  dvb_time.tm_mday = day;
  dvb_time.tm_mon = month - 1;
  dvb_time.tm_year = year;
  dvb_time.tm_isdst = 0;
  dvb_time.tm_wday = 0;
  dvb_time.tm_yday = 0;
  return(mktime(&dvb_time));
}

variable_types: year int

variable_types: month int

variable_types: day int

variable_types: hour int

variable_types: min int

variable_types: sec int

variable_types: mjd long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v5; // rax
char *v6; // rax
char *v7; // rax
time_t v8; // [rsp+0h] [rbp-18h] BYREF
time_t timer[2]; // [rsp+8h] [rbp-10h] BYREF

do_print = 0;
do_force = 0;
do_set = 0;
do_quiet = 0;
ProgName = (__int64)*argv;
do_options(argc, (char **)argv);
if ( do_quiet && do_print )
{
errmsg("quiet and print options are mutually exclusive.\n", v8);
exit(1);
}
timer[0] = scan_date();
if ( !timer[0] )
{
errmsg("Unable to get time from multiplex.\n", v8);
exit(1);
}
time(&v8);
v3 = timer[0] - v8;
if ( do_print )
{
v5 = ctime(&v8);
fprintf(_bss_start, "System time: %s", v5);
v6 = ctime(timer);
fprintf(_bss_start, " DTT time: %s", v6);
fprintf(_bss_start, " Offset: %d seconds\n", v3);
}
else if ( !do_quiet )
{
v7 = ctime(timer);
fputs(v7, _bss_start);
}
if ( do_set )
{
if ( (__int64)abs64(v3) > 1800 && !do_force )
{
errmsg("multiplex time differs by more than %d from system.\n", v8);
errmsg("use -f to force system clock to new time.\n", v8);
exit(1);
}
set_time(timer);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
char *v5; // rax
char *v6; // rax
char *v7; // rax
time_t v8; // [rsp+0h] [rbp-18h] BYREF
time_t timer[2]; // [rsp+8h] [rbp-10h] BYREF

do_print = 0;
do_force = 0;
do_set = 0;
do_quiet = 0;
ProgName = (__int64)*argv;
func13(argc, (char **)argv);
if ( do_quiet && do_print )
{
func10("quiet and print options are mutually exclusive.\n", v8);
exit(1);
}
timer[0] = func8();
if ( !timer[0] )
{
func10("Unable to get time from multiplex.\n", v8);
exit(1);
}
time(&v8);
v3 = timer[0] - v8;
if ( do_print )
{
v5 = ctime(&v8);
fprintf(_bss_start, "System time: %s", v5);
v6 = ctime(timer);
fprintf(_bss_start, " DTT time: %s", v6);
fprintf(_bss_start, " Offset: %d seconds\n", v3);
}
else if ( !do_quiet )
{
v7 = ctime(timer);
fputs(v7, _bss_start);
}
if ( do_set )
{
if ( (__int64)abs64(v3) > 1800 && !do_force )
{
func10("multiplex time differs by more than %d from system.\n", v8);
func10("use -f to force system clock to new time.\n", v8);
exit(1);
}
func9(timer);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
  time_t dvb_time;
  time_t real_time;
  time_t offset;
  do_print = 0;
  do_force = 0;
  do_set = 0;
  do_quiet = 0;
  ProgName = argv[0];
  do_options(argc, argv);
  if (do_quiet && do_print) {
    errmsg("quiet and print options are mutually exclusive.\n");
    exit(1);
  }
  dvb_time = scan_date();
  if (dvb_time == 0) {
    errmsg("Unable to get time from multiplex.\n");
    exit(1);
  }
  time(&real_time);
  offset = dvb_time - real_time;
  if (do_print) {
    fprintf(stdout, "System time: %s", ctime(&real_time));
    fprintf(stdout, "   DTT time: %s", ctime(&dvb_time));
    fprintf(stdout, "     Offset: %d seconds\n", offset);
  } else if (!do_quiet) {
    fprintf(stdout, "%s", ctime(&dvb_time));
  }
  if (do_set) {
    if (labs(offset) > 30*60) {
      if (do_force) {
        set_time(&dvb_time);
      } else {
 errmsg("multiplex time differs by more than %d from system.\n", 30*60);
 errmsg("use -f to force system clock to new time.\n");
        exit(1);
      }
    } else {
      set_time(&dvb_time);
    }
  }
  return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  long dvb_time;
  long real_time;
  long offset;
  do_print = 0;
  do_force = 0;
  do_set = 0;
  do_quiet = 0;
  ProgName = argv[0];
  do_options(argc, argv);
  if (do_quiet && do_print) {
    errmsg("quiet and print options are mutually exclusive.\n");
    exit(1);
  }
  dvb_time = scan_date();
  if (dvb_time == 0) {
    errmsg("Unable to get time from multiplex.\n");
    exit(1);
  }
  time(&real_time);
  offset = dvb_time - real_time;
  if (do_print) {
    fprintf(stdout, "System time: %s", ctime(&real_time));
    fprintf(stdout, "   DTT time: %s", ctime(&dvb_time));
    fprintf(stdout, "     Offset: %d seconds\n", offset);
  } else if (!do_quiet) {
    fprintf(stdout, "%s", ctime(&dvb_time));
  }
  if (do_set) {
    if (labs(offset) > 30*60) {
      if (do_force) {
        set_time(&dvb_time);
      } else {
 errmsg("multiplex time differs by more than %d from system.\n", 30*60);
 errmsg("use -f to force system clock to new time.\n");
        exit(1);
      }
    } else {
      set_time(&dvb_time);
    }
  }
  return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: offset long


decompiled_code:
void xmlsat_Characters()
{
;
}

canonical_decompiled_code:
void func9()
{
;
}

original_code:
static void xmlsat_Characters(xmlsatParseState *state, const char *chars,int len) {
}

canonical_original_code:
static void xmlsat_Characters(struct _xmlsatParseState *state, char *chars, int len) {
}

variable_types: struct _xmlsatParseState { enum ParserState { PARSER_START=0, PARSER_IN_SATELLITE=1, PARSER_IN_TRANSPONDER=2, PARSER_IN_SERVICE=3, PARSER_IN_STREAM=4, PARSER_END=5 } state; } *

variable_types:
chars
char *

variable_types: len int

user_defined_types: struct _xmlsatParseState { enum ParserState state; }


decompiled_code:
char __fastcall xmlsat_EndElement(__int64 a1, const char *a2)
{
char result; // al
int v3; // ebp
__int64 v4; // rsi
__int64 v5; // r8
__int64 v6; // rcx
const char *v7; // rdx
int v8; // edx
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // rbx
bool v13; // zf

result = (char)a2;
if ( !strcmp(a2, "stream") )
{
in_audio_stream = 0;
return result;
}
if ( !strcmp(a2, "canal_radio") )
{
result = ca;
if ( !ca || !fta )
result = printf(
"%s (RADIO):%d:%c:%s:%d:%d:%d:%d:%d:%d\n",
(const char *)service_name,
(unsigned int)freq,
(unsigned int)pol,
diseqc,
(unsigned int)srate,
(unsigned int)vpid,
apid[0],
(unsigned int)tpid,
(unsigned int)ca,
(unsigned int)pnr);
n_apids = 0;
n_ca = 0;
return result;
}
if ( !strcmp(a2, "service") )
{
if ( !LOBYTE(service_name[0]) )
{
result = 110;
service_name[0] = 0x656D616E206F6ELL;
}
v3 = ignore_service;
if ( ignore_service )
goto LABEL_34;
result = type;
if ( type != 130 && type != 155 )
{
result = type - 1;
if ( (unsigned int)(type - 1) > 1 )
goto LABEL_34;
}
if ( ca && fta )
goto LABEL_34;
result = vpid;
if ( vpid )
{
v4 = (unsigned int)srate;
v5 = (unsigned int)pol;
v6 = (unsigned int)freq;
v7 = (const char *)&unk_402004;
}
else
{
if ( n_apids <= 0 && !tpid )
{
LABEL_34:
LOBYTE(service_name[0]) = 0;
n_apids = 0;
n_ca = 0;
vpid = 0;
tpid = 0;
pnr = 0;
ca = 0;
type = 0;
ignore_service = 0;
return result;
}
v4 = (unsigned int)srate;
v5 = (unsigned int)pol;
v6 = (unsigned int)freq;
v7 = "RADIO";
}
printf("%s (%s):%d:%c:%s:%d:%d:", (const char *)service_name, v7, v6, v5, diseqc, v4, (unsigned int)vpid);
if ( n_apids > 0 )
{
v8 = v3;
v9 = 0LL;
do
{
if ( !is_ac3[v9] )
{
if ( v8 )
putchar(44);
printf("%d", apid[v9]);
v8 = 1;
}
++v9;
}
while ( n_apids > (int)v9 );
if ( n_apids > 0 )
{
v10 = 0LL;
do
{
v3 += is_ac3[v10];
v11 = v10++;
}
while ( n_apids - 1 != v11 );
if ( v3 )
{
putchar(59);
if ( n_apids > 0 )
{
v12 = 0LL;
do
{
if ( is_ac3[v12] )
printf("%d", apid[v12]);
++v12;
}
while ( n_apids > (int)v12 );
}
}
}
}
printf(":%d", (unsigned int)tpid);
if ( ca )
printf(":1");
else
printf(":0");
result = printf(":%d\n", (unsigned int)pnr);
goto LABEL_34;
}
v13 = strcmp(a2, "transponder") == 0;
result = !v13;
if ( v13 )
{
freq = 0;
pol = 0;
srate = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func10(__int64 a1, const char *a2)
{
char result; // al
int v3; // ebp
__int64 v4; // rsi
__int64 v5; // r8
__int64 v6; // rcx
const char *v7; // rdx
int v8; // edx
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // rbx
bool v13; // zf

result = (char)a2;
if ( !strcmp(a2, "stream") )
{
in_audio_stream = 0;
return result;
}
if ( !strcmp(a2, "canal_radio") )
{
result = ca;
if ( !ca || !fta )
result = printf(
"%s (RADIO):%d:%c:%s:%d:%d:%d:%d:%d:%d\n",
(const char *)service_name,
(unsigned int)freq,
(unsigned int)pol,
diseqc,
(unsigned int)srate,
(unsigned int)vpid,
apid[0],
(unsigned int)tpid,
(unsigned int)ca,
(unsigned int)pnr);
n_apids = 0;
n_ca = 0;
return result;
}
if ( !strcmp(a2, "service") )
{
if ( !LOBYTE(service_name[0]) )
{
result = 110;
service_name[0] = 0x656D616E206F6ELL;
}
v3 = ignore_service;
if ( ignore_service )
goto LABEL_34;
result = type;
if ( type != 130 && type != 155 )
{
result = type - 1;
if ( (unsigned int)(type - 1) > 1 )
goto LABEL_34;
}
if ( ca && fta )
goto LABEL_34;
result = vpid;
if ( vpid )
{
v4 = (unsigned int)srate;
v5 = (unsigned int)pol;
v6 = (unsigned int)freq;
v7 = (const char *)&unk_402004;
}
else
{
if ( n_apids <= 0 && !tpid )
{
LABEL_34:
LOBYTE(service_name[0]) = 0;
n_apids = 0;
n_ca = 0;
vpid = 0;
tpid = 0;
pnr = 0;
ca = 0;
type = 0;
ignore_service = 0;
return result;
}
v4 = (unsigned int)srate;
v5 = (unsigned int)pol;
v6 = (unsigned int)freq;
v7 = "RADIO";
}
printf("%s (%s):%d:%c:%s:%d:%d:", (const char *)service_name, v7, v6, v5, diseqc, v4, (unsigned int)vpid);
if ( n_apids > 0 )
{
v8 = v3;
v9 = 0LL;
do
{
if ( !is_ac3[v9] )
{
if ( v8 )
putchar(44);
printf("%d", apid[v9]);
v8 = 1;
}
++v9;
}
while ( n_apids > (int)v9 );
if ( n_apids > 0 )
{
v10 = 0LL;
do
{
v3 += is_ac3[v10];
v11 = v10++;
}
while ( n_apids - 1 != v11 );
if ( v3 )
{
putchar(59);
if ( n_apids > 0 )
{
v12 = 0LL;
do
{
if ( is_ac3[v12] )
printf("%d", apid[v12]);
++v12;
}
while ( n_apids > (int)v12 );
}
}
}
}
printf(":%d", (unsigned int)tpid);
if ( ca )
printf(":1");
else
printf(":0");
result = printf(":%d\n", (unsigned int)pnr);
goto LABEL_34;
}
v13 = strcmp(a2, "transponder") == 0;
result = !v13;
if ( v13 )
{
freq = 0;
pol = 0;
srate = 0;
}
return result;
}

original_code:
static void xmlsat_EndElement(xmlsatParseState *state, const char *name) {
  int i,x;
  if (strcmp(name,"stream")==0) {
    in_audio_stream=0;
  } else if (strcmp(name,"canal_radio")==0) {
    if ((ca==0) || (fta==0)) printf("%s (RADIO):%d:%c:%s:%d:%d:%d:%d:%d:%d\n",service_name,freq,pol,diseqc,srate,vpid,apid[0],tpid,ca,pnr);
     n_apids=0;
     n_ca=0;
  } else if (strcmp(name,"service")==0) {
     if (service_name[0]==0) strcpy(service_name,"no name");
     if ((ignore_service==0) && ((type==1) || (type==2) || (type==155) || (type==130))) {
       if (((ca==0) || (fta==0)) && (((vpid!=0) || (n_apids>0) || (tpid!=0)))) {
         printf("%s (%s):%d:%c:%s:%d:%d:",service_name,((vpid==0) ? "RADIO" : "TV"),freq,pol,diseqc,srate,vpid);
         x=0;
         for (i=0;i<n_apids;i++) {
           if (!is_ac3[i]) {
      if (x) printf(",");
             x=1;
             printf("%d",apid[i]);
           }
         }
         x=0;
         for (i=0;i<n_apids;i++) x+=is_ac3[i];
         if (x) {
           printf(";");
           for (i=0;i<n_apids;i++) {
             x=0;
             if (is_ac3[i]) {
               if (x) printf(",");
               x=1;
               printf("%d",apid[i]);
             }
           }
         }
         printf(":%d",tpid);
         if (ca==0) {
           printf(":0");
         } else {
           printf(":1");
         }
         printf(":%d\n",pnr);
       }
     }
     service_name[0]=0;
     n_apids=0;
     n_ca=0;
     vpid=0;
     tpid=0;
     pnr=0;
     ca=0;
     type=0;
     ignore_service=0;
  } else if (strcmp(name,"transponder")==0) {
    freq=0;
    pol=0;
    srate=0;
  }
}

canonical_original_code:
static void xmlsat_EndElement(struct _xmlsatParseState *state, char *name) {
  int i; int x;
  if (strcmp(name,"stream")==0) {
    in_audio_stream=0;
  } else if (strcmp(name,"canal_radio")==0) {
    if ((ca==0) || (fta==0)) printf("%s (RADIO):%d:%c:%s:%d:%d:%d:%d:%d:%d\n",service_name,freq,pol,diseqc,srate,vpid,apid[0],tpid,ca,pnr);
     n_apids=0;
     n_ca=0;
  } else if (strcmp(name,"service")==0) {
     if (service_name[0]==0) strcpy(service_name,"no name");
     if ((ignore_service==0) && ((type==1) || (type==2) || (type==155) || (type==130))) {
       if (((ca==0) || (fta==0)) && (((vpid!=0) || (n_apids>0) || (tpid!=0)))) {
         printf("%s (%s):%d:%c:%s:%d:%d:",service_name,((vpid==0) ? "RADIO" : "TV"),freq,pol,diseqc,srate,vpid);
         x=0;
         for (i=0;i<n_apids;i++) {
           if (!is_ac3[i]) {
      if (x) printf(",");
             x=1;
             printf("%d",apid[i]);
           }
         }
         x=0;
         for (i=0;i<n_apids;i++) x+=is_ac3[i];
         if (x) {
           printf(";");
           for (i=0;i<n_apids;i++) {
             x=0;
             if (is_ac3[i]) {
               if (x) printf(",");
               x=1;
               printf("%d",apid[i]);
             }
           }
         }
         printf(":%d",tpid);
         if (ca==0) {
           printf(":0");
         } else {
           printf(":1");
         }
         printf(":%d\n",pnr);
       }
     }
     service_name[0]=0;
     n_apids=0;
     n_ca=0;
     vpid=0;
     tpid=0;
     pnr=0;
     ca=0;
     type=0;
     ignore_service=0;
  } else if (strcmp(name,"transponder")==0) {
    freq=0;
    pol=0;
    srate=0;
  }
}

variable_types:
name
char *

variable_types: i int

variable_types: x int

user_defined_types: enum ParserState { PARSER_START=0, PARSER_IN_SATELLITE=1, PARSER_IN_TRANSPONDER=2, PARSER_IN_SERVICE=3, PARSER_IN_STREAM=4, PARSER_END=5 }