decompiled_code:
void __fastcall mark_recursive_tree(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v3; // rsi

if ( a2 )
{
if ( !(unsigned int)find_and_mark(*(unsigned __int64 **)(a1 + 24), (unsigned __int64)a2, 40) )
_assert_fail(
"find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))",
"src/l-mempool-scan.inc",
9u,
"mark_recursive_tree");
mark_recursive_tree(a1, a2[2]);
mark_recursive_tree(a1, a2[3]);
mark_recursive_tree(a1, a2[4]);
mark_recursive_lambda(a1, a2[1]);
v3 = *a2;
if ( *a2 )
{
if ( !(unsigned int)find_and_mark(*(unsigned __int64 **)(a1 + 24), v3, 24) )
_assert_fail(
"find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))",
"src/l-mempool-scan.inc",
0x11u,
"mark_recursive_tree");
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 v3; // rsi

if ( a2 )
{
if ( !(unsigned int)func1(*(unsigned __int64 **)(a1 + 24), (unsigned __int64)a2, 40) )
_assert_fail(
"find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))",
"src/l-mempool-scan.inc",
9u,
"mark_recursive_tree");
func4(a1, a2[2]);
func4(a1, a2[3]);
func4(a1, a2[4]);
func3(a1, a2[1]);
v3 = *a2;
if ( *a2 )
{
if ( !(unsigned int)func1(*(unsigned __int64 **)(a1 + 24), v3, 24) )
_assert_fail(
"find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))",
"src/l-mempool-scan.inc",
0x11u,
"mark_recursive_tree");
}
}
}

original_code:
static void
mark_recursive_tree (LMempool *pool, LTreeNode *node)
{
 if (node == ((void *)0))
  return;
 ((void) sizeof ((find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))", "src/l-mempool-scan.inc", 9, __extension__ __PRETTY_FUNCTION__); }));
 mark_recursive_tree (pool, node->left);
 mark_recursive_tree (pool, node->right);
 mark_recursive_tree (pool, node->lazy);
 mark_recursive_lambda (pool, node->lambda);
 if (node->token != ((void *)0))
  ((void) sizeof ((find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))", "src/l-mempool-scan.inc", 17, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void mark_recursive_tree(struct _LMempool *pool, struct _LTreeNode *node)
{
 if (node == ((void *)0))
  return;
 ((void) sizeof ((find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (node), sizeof (LTreeNode))", "src/l-mempool-scan.inc", 9, __extension__ __PRETTY_FUNCTION__); }));
 mark_recursive_tree (pool, node->left);
 mark_recursive_tree (pool, node->right);
 mark_recursive_tree (pool, node->lazy);
 mark_recursive_lambda (pool, node->lambda);
 if (node->token != ((void *)0))
  ((void) sizeof ((find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (node->token), sizeof (LToken))", "src/l-mempool-scan.inc", 17, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: struct _LTreeNode { struct LToken { char *name; int idx; struct _LLambda { struct _LListNode { struct LToken *token; struct _LListNode *next; } *args; struct _LTreeNode *body; struct _LLambda *next; } *parent; } *token; struct _LLambda *lambda; struct _LTreeNode *left; } *

user_defined_types: struct _LTreeNode { struct LToken *token; struct _LLambda *lambda; struct _LTreeNode *left; }


repo: sanjoy/L

decompiled_code:
void __fastcall mark_recursive_assignment(__int64 a1, unsigned __int64 a2)
{
if ( !(unsigned int)find_and_mark(*(unsigned __int64 **)(a1 + 24), a2, 24) )
_assert_fail(
"find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))",
"src/l-mempool-scan.inc",
0x17u,
"mark_recursive_assignment");
if ( !(unsigned int)find_and_mark(*(unsigned __int64 **)(a1 + 24), *(_QWORD *)a2, 24) )
_assert_fail(
"find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))",
"src/l-mempool-scan.inc",
0x18u,
"mark_recursive_assignment");
mark_recursive_tree(a1, *(unsigned __int64 **)(a2 + 8));
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, unsigned __int64 a2)
{
if ( !(unsigned int)func1(*(unsigned __int64 **)(a1 + 24), a2, 24) )
_assert_fail(
"find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))",
"src/l-mempool-scan.inc",
0x17u,
"mark_recursive_assignment");
if ( !(unsigned int)func1(*(unsigned __int64 **)(a1 + 24), *(_QWORD *)a2, 24) )
_assert_fail(
"find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))",
"src/l-mempool-scan.inc",
0x18u,
"mark_recursive_assignment");
func4(a1, *(unsigned __int64 **)(a2 + 8));
}

original_code:
static void
mark_recursive_assignment (LMempool *pool, LAssignment *assignment)
{
 ((void) sizeof ((find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))", "src/l-mempool-scan.inc", 23, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))", "src/l-mempool-scan.inc", 24, __extension__ __PRETTY_FUNCTION__); }));
 mark_recursive_tree (pool, assignment->rhs);
}

canonical_original_code:
static void mark_recursive_assignment(struct _LMempool *pool, struct _LAssignment *assignment)
{
 ((void) sizeof ((find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (assignment), sizeof (LAssignment))", "src/l-mempool-scan.inc", 23, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))) ? 1 : 0), __extension__ ({ if (find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))) ; else __assert_fail ("find_and_mark ((pool)->blocks, (assignment->lhs), sizeof (LToken))", "src/l-mempool-scan.inc", 24, __extension__ __PRETTY_FUNCTION__); }));
 mark_recursive_tree (pool, assignment->rhs);
}

variable_types: struct _LMempool { unsigned long page_size; int dev_zero_fd; unsigned long total_bytes; struct _MempoolNode { void *begin; int offset; struct _MempoolNode *next; } *blocks; } *

variable_types: struct _LAssignment { struct LToken { char *name; int idx; struct _LLambda { struct _LListNode { struct LToken *token; struct _LListNode *next; } *args; struct _LTreeNode { struct LToken *token; struct _LLambda *lambda; struct _LTreeNode *left; } *body; struct _LLambda *next; } *parent; } *lhs; struct _LTreeNode *rhs; struct _LAssignment *next; } *

return_type: void

user_defined_types: struct _LMempool { unsigned long page_size; int dev_zero_fd; unsigned long total_bytes; struct _MempoolNode *blocks; }

user_defined_types: struct _LAssignment { struct LToken *lhs; struct _LTreeNode *rhs; struct _LAssignment *next; }

user_defined_types: struct LToken { char *name; int idx; struct _LLambda *parent; }

user_defined_types: struct _LLambda { struct _LListNode *args; struct _LTreeNode *body; struct _LLambda *next; }


original_code:
void *
l_mempool_alloc (LMempool *pool, size_t size)
{
 void *ret;
 if (size == 0)
  return ((void *)0);
 if (pool->gc) {
  if (size % (sizeof (void *)) != 0)
   size = (size / (sizeof (void *)) + 1) * (sizeof (void *));
 }
 if ((pool->blocks->real_end - pool->blocks->end) < size) {
  do { size_t sz = (size), offset; MempoolNode *new_node = ((void *)0); if ((sz % ((pool)->page_size)) != 0) sz = (sz / ((pool)->page_size) + 1) * ((pool)->page_size); if ((new_node = (mmap (((void *)0), sz, 0x1 | 0x2, 0x02, pool->dev_zero_fd, 0))) == (void *) -1) perror ("ALLOC_NEW_NODE"); new_node->begin = ((char *) new_node) + sizeof (MempoolNode); offset = (sz / ((sizeof (void *)) * 8) + 1); if (offset % (sizeof (void *)) != 0) offset = (offset / (sizeof (void *)) + 1) * (sizeof (void *)); new_node->end = ((char *) (new_node->begin)) + offset; new_node->real_end = ((char *) new_node) + sz; new_node->next = (pool)->blocks; new_node->offset = offset; ((void) sizeof ((new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ? 1 : 0), __extension__ ({ if (new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ; else __assert_fail ("new_node->offset >= (((new_node->real_end - new_node->begin) / SIZEOF_PTR) / 8 + 1)", "src/l-mempool.c", 115, __extension__ __PRETTY_FUNCTION__); })); (pool)->blocks = new_node; (pool)->total_bytes += sz; } while (0);
 }
 ret = pool->blocks->end;
 pool->blocks->end += size;
 return ret;
}

canonical_original_code:
void *l_mempool_alloc(struct _LMempool *pool, unsigned long size)
{
 void *ret;
 if (size == 0)
  return ((void *)0);
 if (pool->gc) {
  if (size % (sizeof (void *)) != 0)
   size = (size / (sizeof (void *)) + 1) * (sizeof (void *));
 }
 if ((pool->blocks->real_end - pool->blocks->end) < size) {
  do { unsigned long sz = (size); unsigned long offset; struct _MempoolNode *new_node = ((void *)0); if ((sz % ((pool)->page_size)) != 0) sz = (sz / ((pool)->page_size) + 1) * ((pool)->page_size); if ((new_node = (mmap (((void *)0), sz, 0x1 | 0x2, 0x02, pool->dev_zero_fd, 0))) == (void *) -1) perror ("ALLOC_NEW_NODE"); new_node->begin = ((char *) new_node) + sizeof (MempoolNode); offset = (sz / ((sizeof (void *)) * 8) + 1); if (offset % (sizeof (void *)) != 0) offset = (offset / (sizeof (void *)) + 1) * (sizeof (void *)); new_node->end = ((char *) (new_node->begin)) + offset; new_node->real_end = ((char *) new_node) + sz; new_node->next = (pool)->blocks; new_node->offset = offset; ((void) sizeof ((new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ? 1 : 0), __extension__ ({ if (new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ; else __assert_fail ("new_node->offset >= (((new_node->real_end - new_node->begin) / SIZEOF_PTR) / 8 + 1)", "src/l-mempool.c", 115, __extension__ __PRETTY_FUNCTION__); })); (pool)->blocks = new_node; (pool)->total_bytes += sz; } while (0);
 }
 ret = pool->blocks->end;
 pool->blocks->end += size;
 return ret;
}

variable_types:
size
unsigned long

variable_types:
ret
void *

variable_types:
sz
unsigned long

variable_types:
offset
unsigned long

variable_types: struct _MempoolNode { void *begin; int offset; struct _MempoolNode *next; } *

return_type: void *


decompiled_code:
unsigned __int64 __fastcall l_mempool_pre_alloc(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
size_t v3; // rbx
_QWORD *v4; // r12

result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 16LL) - *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
if ( result < a2 )
{
v3 = a2 + 40;
if ( (a2 + 40) % *(_QWORD *)a1 )
v3 = *(_QWORD *)a1 * (v3 / *(_QWORD *)a1 + 1);
v4 = mmap(0LL, v3, 3, 2, *(_DWORD *)(a1 + 8), 0LL);
if ( v4 == (_QWORD *)-1LL )
perror("ALLOC_NEW_NODE");
*v4 = v4 + 5;
result = (v3 >> 6) + 1;
if ( (result & 7) != 0 )
result = 8 * (result >> 3) + 8;
v4[1] = (char *)v4 + result + 40;
v4[2] = (char *)v4 + v3;
v4[4] = *(_QWORD *)(a1 + 24);
*((_DWORD *)v4 + 6) = result;
result = (int)result;
if ( (int)result < ((v3 - 40) >> 6) + 1 )
_assert_fail(
"new_node->offset >= (((new_node->real_end - new_node->begin) / SIZEOF_PTR) / 8 + 1)",
"src/l-mempool.c",
0x7Fu,
"l_mempool_pre_alloc");
*(_QWORD *)(a1 + 24) = v4;
*(_QWORD *)(a1 + 16) += v3;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax
size_t v3; // rbx
_QWORD *v4; // r12

result = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 16LL) - *(_QWORD *)(*(_QWORD *)(a1 + 24) + 8LL);
if ( result < a2 )
{
v3 = a2 + 40;
if ( (a2 + 40) % *(_QWORD *)a1 )
v3 = *(_QWORD *)a1 * (v3 / *(_QWORD *)a1 + 1);
v4 = mmap(0LL, v3, 3, 2, *(_DWORD *)(a1 + 8), 0LL);
if ( v4 == (_QWORD *)-1LL )
perror("ALLOC_NEW_NODE");
*v4 = v4 + 5;
result = (v3 >> 6) + 1;
if ( (result & 7) != 0 )
result = 8 * (result >> 3) + 8;
v4[1] = (char *)v4 + result + 40;
v4[2] = (char *)v4 + v3;
v4[4] = *(_QWORD *)(a1 + 24);
*((_DWORD *)v4 + 6) = result;
result = (int)result;
if ( (int)result < ((v3 - 40) >> 6) + 1 )
_assert_fail(
"new_node->offset >= (((new_node->real_end - new_node->begin) / SIZEOF_PTR) / 8 + 1)",
"src/l-mempool.c",
0x7Fu,
"l_mempool_pre_alloc");
*(_QWORD *)(a1 + 24) = v4;
*(_QWORD *)(a1 + 16) += v3;
}
return result;
}

original_code:
void
l_mempool_pre_alloc (LMempool *pool, size_t size)
{
 if ((pool->blocks->real_end - pool->blocks->end) < size)
  do { size_t sz = (size + sizeof (MempoolNode)), offset; MempoolNode *new_node = ((void *)0); if ((sz % ((pool)->page_size)) != 0) sz = (sz / ((pool)->page_size) + 1) * ((pool)->page_size); if ((new_node = (mmap (((void *)0), sz, 0x1 | 0x2, 0x02, pool->dev_zero_fd, 0))) == (void *) -1) perror ("ALLOC_NEW_NODE"); new_node->begin = ((char *) new_node) + sizeof (MempoolNode); offset = (sz / ((sizeof (void *)) * 8) + 1); if (offset % (sizeof (void *)) != 0) offset = (offset / (sizeof (void *)) + 1) * (sizeof (void *)); new_node->end = ((char *) (new_node->begin)) + offset; new_node->real_end = ((char *) new_node) + sz; new_node->next = (pool)->blocks; new_node->offset = offset; ((void) sizeof ((new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ? 1 : 0), __extension__ ({ if (new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ; else __assert_fail ("new_node->offset >= (((new_node->real_end - new_node->begin) / SIZEOF_PTR) / 8 + 1)", "src/l-mempool.c", 127, __extension__ __PRETTY_FUNCTION__); })); (pool)->blocks = new_node; (pool)->total_bytes += sz; } while (0);
}

canonical_original_code:
void l_mempool_pre_alloc(struct _LMempool *pool, unsigned long size)
{
 if ((pool->blocks->real_end - pool->blocks->end) < size)
  do { unsigned long sz = (size + sizeof (MempoolNode)); unsigned long offset; struct _MempoolNode *new_node = ((void *)0); if ((sz % ((pool)->page_size)) != 0) sz = (sz / ((pool)->page_size) + 1) * ((pool)->page_size); if ((new_node = (mmap (((void *)0), sz, 0x1 | 0x2, 0x02, pool->dev_zero_fd, 0))) == (void *) -1) perror ("ALLOC_NEW_NODE"); new_node->begin = ((char *) new_node) + sizeof (MempoolNode); offset = (sz / ((sizeof (void *)) * 8) + 1); if (offset % (sizeof (void *)) != 0) offset = (offset / (sizeof (void *)) + 1) * (sizeof (void *)); new_node->end = ((char *) (new_node->begin)) + offset; new_node->real_end = ((char *) new_node) + sz; new_node->next = (pool)->blocks; new_node->offset = offset; ((void) sizeof ((new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ? 1 : 0), __extension__ ({ if (new_node->offset >= (((new_node->real_end - new_node->begin) / (sizeof (void *))) / 8 + 1)) ; else __assert_fail ("new_node->offset >= (((new_node->real_end - new_node->begin) / SIZEOF_PTR) / 8 + 1)", "src/l-mempool.c", 127, __extension__ __PRETTY_FUNCTION__); })); (pool)->blocks = new_node; (pool)->total_bytes += sz; } while (0);
}

user_defined_types: struct _MempoolNode { void *begin; int offset; struct _MempoolNode *next; }


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

v2 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[4];
munmap(v3, v3[2] - (_QWORD)v3);
}
close(*((_DWORD *)ptr + 2));
free(ptr);
}

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

v2 = (_QWORD *)*((_QWORD *)ptr + 3);
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[4];
munmap(v3, v3[2] - (_QWORD)v3);
}
close(*((_DWORD *)ptr + 2));
free(ptr);
}

original_code:
void
l_mempool_destroy (LMempool *pool)
{
 MempoolNode *i, *j;
 i = pool->blocks;
 while (i != ((void *)0)) {
  j = i->next;
  munmap (i, i->real_end - (void *) i);
  i = j;
 }
 close (pool->dev_zero_fd);
 free (pool);
}

canonical_original_code:
void l_mempool_destroy(struct _LMempool *pool)
{
 struct _MempoolNode *i; struct _MempoolNode *j;
 i = pool->blocks;
 while (i != ((void *)0)) {
  j = i->next;
  munmap (i, i->real_end - (void *) i);
  i = j;
 }
 close (pool->dev_zero_fd);
 free (pool);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
l_start_repl(0LL, argv, envp);
else
l_start_repl(argv[1], argv, envp);
return 0;
}

original_code:
int
main (int argc, char **argv)
{
 if (argc < 2) {
  l_start_repl (((void *)0));
 } else {
  l_start_repl (argv [1]);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 if (argc < 2) {
  l_start_repl (((void *)0));
 } else {
  l_start_repl (argv [1]);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
void __fastcall replace_nonfree(__int64 *a1, __int64 a2, int a3)
{
__int64 v3; // rax
__int64 v4; // rax

if ( a1 )
{
v3 = a1[1];
if ( v3 )
{
replace_nonfree(*(_QWORD *)(v3 + 8));
}
else
{
v4 = *a1;
if ( *a1 && !*(_QWORD *)(v4 + 16) && *(_DWORD *)(v4 + 8) == a3 )
*(_QWORD *)(v4 + 16) = a2;
}
replace_nonfree(a1[2]);
replace_nonfree(a1[3]);
}
}

original_code:
static void
replace_nonfree (LTreeNode *node, LLambda *parent, int token_idx)
{
 if (node != ((void *)0)) {
  if (node->lambda != ((void *)0)) {
   replace_nonfree (node->lambda->body, parent, token_idx);
  } else if (node->token != ((void *)0) && node->token->parent == ((void *)0) &&
             node->token->idx == token_idx) {
   node->token->parent = parent;
  }
  replace_nonfree (node->left, parent, token_idx);
  replace_nonfree (node->right, parent, token_idx);
 }
}

canonical_original_code:
static void replace_nonfree(struct _LTreeNode *node, struct _LLambda *parent, int token_idx)
{
 if (node != ((void *)0)) {
  if (node->lambda != ((void *)0)) {
   replace_nonfree (node->lambda->body, parent, token_idx);
  } else if (node->token != ((void *)0) && node->token->parent == ((void *)0) &&
             node->token->idx == token_idx) {
   node->token->parent = parent;
  }
  replace_nonfree (node->left, parent, token_idx);
  replace_nonfree (node->right, parent, token_idx);
 }
}

variable_types:
parent
struct _LLambda *

user_defined_types: struct _LListNode { struct LToken *token; struct _LListNode *next; }


decompiled_code:
_BOOL8 __fastcall replace_by_token_id_predicate(__int64 a1, _DWORD *a2)
{
return *(_DWORD *)(a1 + 8) == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, _DWORD *a2)
{
return *(_DWORD *)(a1 + 8) == *a2;
}

original_code:
static int
replace_by_token_id_predicate (LToken *token, void *user_data)
{
 int token_id = *((int *) user_data);
 return token->idx == token_id;
}

canonical_original_code:
static int replace_by_token_id_predicate(struct LToken *token, void *user_data)
{
 int token_id = *((int *) user_data);
 return token->idx == token_id;
}

variable_types: struct LToken { char *name; int idx; struct _LLambda { struct _LListNode { struct LToken *token; struct _LListNode *next; } *args; struct _LTreeNode { struct LToken *token; struct _LLambda *lambda; struct _LTreeNode *left; } *body; struct _LLambda *next; } *parent; } *


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

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

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

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

original_code:
static int
replace_by_param_id_predicate (LToken *token, void *user_data)
{
 ReplaceByParamArgs *args = user_data;
 return (args->parent == token->parent && args->param_idx == token->idx);
}

canonical_original_code:
static int replace_by_param_id_predicate(struct LToken *token, void *user_data)
{
 struct ReplaceByParamArgs *args = user_data;
 return (args->parent == token->parent && args->param_idx == token->idx);
}

variable_types: struct ReplaceByParamArgs { int param_idx; struct _LLambda { struct _LListNode { struct LToken { char *name; int idx; struct _LLambda *parent; } *token; struct _LListNode *next; } *args; struct _LTreeNode { struct LToken *token; struct _LLambda *lambda; struct _LTreeNode *left; } *body; struct _LLambda *next; } *parent; } *

user_defined_types: struct ReplaceByParamArgs { int param_idx; struct _LLambda *parent; }


strsplit

repo: santhoshn/panchanga

decompiled_code:
__int64 __fastcall strsplit(char *a1, char a2)
{
char v2; // al
int v3; // edx

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
if ( a2 == v2 )
{
*a1 = 32;
++v3;
}
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return (unsigned int)(v3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char a2)
{
char v2; // al
int v3; // edx

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
if ( a2 == v2 )
{
*a1 = 32;
++v3;
}
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return (unsigned int)(v3 + 1);
}

original_code:
int strsplit(char *str, char c)
{
 int n=0;
 char *tmp;
 for(tmp=str; *tmp; tmp++)
  if(*tmp==c) {
   *tmp=' ';
   n++;
  }
 return n+1;
}

canonical_original_code:
int strsplit(char *str, char c)
{
 int n = 0;
 char *tmp;
 for(tmp=str; *tmp; tmp++)
  if(*tmp==c) {
   *tmp=' ';
   n++;
  }
 return n+1;
}

variable_types:
str
char *

variable_types: c char

variable_types: n int

variable_types:
tmp
char *


decompiled_code:
void __fastcall __noreturn show_usage(int status)
{
fwrite("Usage: panchanga -d dd/mm/yyy -t hh:mm -z [+/-]hh:mm\n", 1uLL, 0x35uLL, stderr);
fwrite("-d : Date in dd/mm/yyyy format.\n", 1uLL, 0x20uLL, stderr);
fwrite("-t : Time in hh:mm 24-hour format.\n", 1uLL, 0x23uLL, stderr);
fwrite("-z : Zone with respect to GMT in [+/-]hh:mm format.\n", 1uLL, 0x34uLL, stderr);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int status)
{
fwrite("Usage: panchanga -d dd/mm/yyy -t hh:mm -z [+/-]hh:mm\n", 1uLL, 0x35uLL, stderr);
fwrite("-d : Date in dd/mm/yyyy format.\n", 1uLL, 0x20uLL, stderr);
fwrite("-t : Time in hh:mm 24-hour format.\n", 1uLL, 0x23uLL, stderr);
fwrite("-z : Zone with respect to GMT in [+/-]hh:mm format.\n", 1uLL, 0x34uLL, stderr);
exit(status);
}

original_code:
void show_usage(int ret)
{
 fprintf(stderr,"Usage: panchanga -d dd/mm/yyy -t hh:mm -z [+/-]hh:mm\n");
 fprintf(stderr,"-d : Date in dd/mm/yyyy format.\n");
 fprintf(stderr,"-t : Time in hh:mm 24-hour format.\n");
 fprintf(stderr,"-z : Zone with respect to GMT in [+/-]hh:mm format.\n");
 exit(ret);
}

variable_types: ret int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
double v4; // xmm0_8
__int64 v6; // [rsp+0h] [rbp-218h] BYREF
char v7[64]; // [rsp+10h] [rbp-208h] BYREF
char v8[64]; // [rsp+50h] [rbp-1C8h] BYREF
char v9[64]; // [rsp+90h] [rbp-188h] BYREF
char v10[64]; // [rsp+D0h] [rbp-148h] BYREF
char v11[64]; // [rsp+110h] [rbp-108h] BYREF
char v12[40]; // [rsp+150h] [rbp-C8h] BYREF
int v13; // [rsp+178h] [rbp-A0h] BYREF
int v14; // [rsp+17Ch] [rbp-9Ch] BYREF
unsigned int v15; // [rsp+180h] [rbp-98h] BYREF
unsigned int v16; // [rsp+184h] [rbp-94h] BYREF
double v17; // [rsp+188h] [rbp-90h] BYREF
double v18; // [rsp+190h] [rbp-88h] BYREF
double v19; // [rsp+198h] [rbp-80h] BYREF
char dest[8]; // [rsp+1A0h] [rbp-78h] BYREF
__int64 v21; // [rsp+1A8h] [rbp-70h]
int v22; // [rsp+1B0h] [rbp-68h]
char v23[8]; // [rsp+1C0h] [rbp-58h] BYREF
__int64 v24; // [rsp+1C8h] [rbp-50h]
int v25; // [rsp+1D0h] [rbp-48h]
char v26[8]; // [rsp+1E0h] [rbp-38h] BYREF
__int64 v27; // [rsp+1E8h] [rbp-30h]
int v28; // [rsp+1F0h] [rbp-28h]

*(_QWORD *)v26 = 0LL;
v27 = 0LL;
v28 = 0;
*(_QWORD *)v23 = 0LL;
v24 = 0LL;
v25 = 0;
*(_QWORD *)dest = 0LL;
v21 = 0LL;
v22 = 0;
opterr = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "d:t:z:h");
if ( v3 == -1 )
break;
if ( v3 == 116 )
{
strcpy(v23, optarg);
}
else if ( v3 > 116 )
{
if ( v3 != 122 )
goto LABEL_14;
strcpy(dest, optarg);
}
else
{
if ( v3 != 100 )
{
if ( v3 == 104 )
show_usage(0);
if ( v3 == 63 )
{
fprintf(stderr, "Unknown option `-%c'.\n", (unsigned int)optopt);
exit(1);
}
LABEL_14:
abort();
}
strcpy(v26, optarg);
}
}
if ( !v26[0] || !v23[0] || !dest[0] )
show_usage(1);
if ( (unsigned int)strsplit(v26, 47) != 3 )
show_usage(1);
_isoc99_sscanf(v26, "%lf %d %d", &v19, &v16, &v15);
if ( (unsigned int)strsplit(v23, 58) != 2 )
show_usage(1);
_isoc99_sscanf(v23, "%lf %d", &v18, &v14);
v18 = (double)v14 / 60.0 + v18;
if ( (unsigned int)strsplit(dest, 58) != 2 )
show_usage(1);
_isoc99_sscanf(dest, "%lf %d", &v17, &v13);
if ( v17 < 0.0 )
*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64((double)v13 / 60.0) ^ LC10;
else
v4 = (double)v13 / 60.0;
v17 = v17 + v4;
calculate_panchanga((unsigned int)(int)v19, v16, v15, &v6, v18);
printf("Tithi : %s, %s Paksha\n", v9, v11);
printf("Nakshatra : %s\n", v8);
printf("Yoga : %s\n", v7);
printf("Karana : %s\n", v10);
printf("Rashi : %s\n", v12);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
double v4; // xmm0_8
__int64 v6; // [rsp+0h] [rbp-218h] BYREF
char v7[64]; // [rsp+10h] [rbp-208h] BYREF
char v8[64]; // [rsp+50h] [rbp-1C8h] BYREF
char v9[64]; // [rsp+90h] [rbp-188h] BYREF
char v10[64]; // [rsp+D0h] [rbp-148h] BYREF
char v11[64]; // [rsp+110h] [rbp-108h] BYREF
char v12[40]; // [rsp+150h] [rbp-C8h] BYREF
int v13; // [rsp+178h] [rbp-A0h] BYREF
int v14; // [rsp+17Ch] [rbp-9Ch] BYREF
unsigned int v15; // [rsp+180h] [rbp-98h] BYREF
unsigned int v16; // [rsp+184h] [rbp-94h] BYREF
double v17; // [rsp+188h] [rbp-90h] BYREF
double v18; // [rsp+190h] [rbp-88h] BYREF
double v19; // [rsp+198h] [rbp-80h] BYREF
char dest[8]; // [rsp+1A0h] [rbp-78h] BYREF
__int64 v21; // [rsp+1A8h] [rbp-70h]
int v22; // [rsp+1B0h] [rbp-68h]
char v23[8]; // [rsp+1C0h] [rbp-58h] BYREF
__int64 v24; // [rsp+1C8h] [rbp-50h]
int v25; // [rsp+1D0h] [rbp-48h]
char v26[8]; // [rsp+1E0h] [rbp-38h] BYREF
__int64 v27; // [rsp+1E8h] [rbp-30h]
int v28; // [rsp+1F0h] [rbp-28h]

*(_QWORD *)v26 = 0LL;
v27 = 0LL;
v28 = 0;
*(_QWORD *)v23 = 0LL;
v24 = 0LL;
v25 = 0;
*(_QWORD *)dest = 0LL;
v21 = 0LL;
v22 = 0;
opterr = 0;
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "d:t:z:h");
if ( v3 == -1 )
break;
if ( v3 == 116 )
{
strcpy(v23, optarg);
}
else if ( v3 > 116 )
{
if ( v3 != 122 )
goto LABEL_14;
strcpy(dest, optarg);
}
else
{
if ( v3 != 100 )
{
if ( v3 == 104 )
func1(0);
if ( v3 == 63 )
{
fprintf(stderr, "Unknown option `-%c'.\n", (unsigned int)optopt);
exit(1);
}
LABEL_14:
abort();
}
strcpy(v26, optarg);
}
}
if ( !v26[0] || !v23[0] || !dest[0] )
func1(1);
if ( (unsigned int)func0(v26, 47) != 3 )
func1(1);
_isoc99_sscanf(v26, "%lf %d %d", &v19, &v16, &v15);
if ( (unsigned int)func0(v23, 58) != 2 )
func1(1);
_isoc99_sscanf(v23, "%lf %d", &v18, &v14);
v18 = (double)v14 / 60.0 + v18;
if ( (unsigned int)func0(dest, 58) != 2 )
func1(1);
_isoc99_sscanf(dest, "%lf %d", &v17, &v13);
if ( v17 < 0.0 )
*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64((double)v13 / 60.0) ^ LC10;
else
v4 = (double)v13 / 60.0;
v17 = v17 + v4;
calculate_panchanga((unsigned int)(int)v19, v16, v15, &v6, v18);
printf("Tithi : %s, %s Paksha\n", v9, v11);
printf("Nakshatra : %s\n", v8);
printf("Yoga : %s\n", v7);
printf("Karana : %s\n", v10);
printf("Rashi : %s\n", v12);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char date[20]={0}, time[20]={0}, zone[20]={0};
 double dd, hr, zhr;
 int mm, yy, mn, zmn, c;
 struct panchanga pdata;
 opterr = 0;
 while((c=getopt(argc,argv,"d:t:z:h"))!=-1) {
       switch(c) {
   case 'd':
    strcpy(date,optarg);
    break;
   case 't':
    strcpy(time,optarg);
    break;
   case 'z':
    strcpy(zone,optarg);
    break;
   case 'h':
    show_usage(0);
   case '?':
    fprintf(stderr, "Unknown option `-%c'.\n", optopt);
    exit(1);
         default:
    abort();
  }
        }
 if(!date[0] || !time[0] || !zone[0])
  show_usage(1);
 if(strsplit(date,'/')!=3)
  show_usage(1);
 sscanf(date,"%lf %d %d",&dd,&mm,&yy);
 if(strsplit(time,':')!=2)
  show_usage(1);
 sscanf(time,"%lf %d",&hr,&mn);
 hr+=mn/60.0;
 if(strsplit(zone,':')!=2)
  show_usage(1);
 sscanf(zone,"%lf %d",&zhr,&zmn);
 zhr+=(zhr<0.0)?-(zmn/60.0):(zmn/60.0);
 calculate_panchanga(dd, mm, yy, hr, zhr, &pdata);
 printf("Tithi     : %s, %s Paksha\n", pdata.dtithi, pdata.dpaksha);
 printf("Nakshatra : %s\n", pdata.dnakshatra);
 printf("Yoga      : %s\n", pdata.dyoga);
 printf("Karana    : %s\n", pdata.dkarana);
 printf("Rashi     : %s\n", pdata.drashi);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char date[20] = {0}; char time[20] = {0}; char zone[20] = {0};
 double dd; double hr; double zhr;
 int mm; int yy; int mn; int zmn; int c;
 struct panchanga pdata;
 opterr = 0;
 while((c=getopt(argc,argv,"d:t:z:h"))!=-1) {
       switch(c) {
   case 'd':
    strcpy(date,optarg);
    break;
   case 't':
    strcpy(time,optarg);
    break;
   case 'z':
    strcpy(zone,optarg);
    break;
   case 'h':
    show_usage(0);
   case '?':
    fprintf(stderr, "Unknown option `-%c'.\n", optopt);
    exit(1);
         default:
    abort();
  }
        }
 if(!date[0] || !time[0] || !zone[0])
  show_usage(1);
 if(strsplit(date,'/')!=3)
  show_usage(1);
 sscanf(date,"%lf %d %d",&dd,&mm,&yy);
 if(strsplit(time,':')!=2)
  show_usage(1);
 sscanf(time,"%lf %d",&hr,&mn);
 hr+=mn/60.0;
 if(strsplit(zone,':')!=2)
  show_usage(1);
 sscanf(zone,"%lf %d",&zhr,&zmn);
 zhr+=(zhr<0.0)?-(zmn/60.0):(zmn/60.0);
 calculate_panchanga(dd, mm, yy, hr, zhr, &pdata);
 printf("Tithi     : %s, %s Paksha\n", pdata.dtithi, pdata.dpaksha);
 printf("Nakshatra : %s\n", pdata.dnakshatra);
 printf("Yoga      : %s\n", pdata.dyoga);
 printf("Karana    : %s\n", pdata.dkarana);
 printf("Rashi     : %s\n", pdata.drashi);
}

variable_types:
date
char [20]

variable_types:
time
char [20]

variable_types:
zone
char [20]

variable_types: dd double

variable_types: hr double

variable_types: zhr double

variable_types: mm int

variable_types: yy int

variable_types: mn int

variable_types: zmn int

variable_types: c int

variable_types: struct panchanga { char dtoday[16]; char dyoga[64]; char dnakshatra[64]; char dtithi[64]; char dkarana[64]; char dpaksha[64]; char drashi[32]; }


variable_types: d double

variable_types: t double

variable_types: o double

variable_types: l double

variable_types: ayan double

return_type: double


variable_types: w double

variable_types: a double

variable_types: e double

variable_types: M double

variable_types: E double

variable_types: x double

variable_types: y double

variable_types: r double

variable_types: v double

variable_types: tmp double


original_code:
void calculate_panchanga(int dd, int mm, int yy, double hr, double zhr, struct panchanga *pdata)
{
 double d, ayanamsa, slon, mlon, tmlon, tslon;
 int n;
 d = (367*yy-7*(yy+(mm+9)/12)/4+275*mm/9+dd-730530);
 ayanamsa = calc_ayanamsa(d);
 slon = sun_long(d+((hr-zhr)/24.0));
 mlon = moon_long(d+((hr-zhr)/24.0));
 tmlon = mlon+((mlon<slon)?360:0);
 tslon = slon;
 n = (int)((tmlon-tslon)/12);
 strcpy(pdata->dtithi,tithi[n]);
 (n<=14)?strcpy(pdata->dpaksha,"Shukla"):strcpy(pdata->dpaksha,"Krishna");
 tmlon = ((mlon+ayanamsa)-floor((mlon+ayanamsa)/360.0)*360.0);
 strcpy(pdata->dnakshatra,nakshatra[(int)(tmlon*6/80)]);
 tmlon = mlon+ayanamsa;
 tslon = slon+ayanamsa;
 strcpy(pdata->dyoga,yoga[(int)(((tmlon+tslon)-floor((tmlon+tslon)/360.0)*360.0)*6/80)]);
 tmlon = mlon+((mlon<slon)?360:0);
 tslon = slon;
 n = (int)((tmlon-tslon)/6);
 if(n==0) n=10;
 if(n>=57) n-=50;
 if(n>0 && n<57) n=(n-1)-((n-1)/7*7);
 strcpy(pdata->dkarana,karan[n]);
 tmlon = ((mlon+ayanamsa)-floor((mlon+ayanamsa)/360.0)*360.0);
 strcpy(pdata->drashi,rashi[(int)(tmlon/30)]);
}

canonical_original_code:
void calculate_panchanga(int dd, int mm, int yy, double hr, double zhr, struct panchanga *pdata)
{
 double d; double ayanamsa; double slon; double mlon; double tmlon; double tslon;
 int n;
 d = (367*yy-7*(yy+(mm+9)/12)/4+275*mm/9+dd-730530);
 ayanamsa = calc_ayanamsa(d);
 slon = sun_long(d+((hr-zhr)/24.0));
 mlon = moon_long(d+((hr-zhr)/24.0));
 tmlon = mlon+((mlon<slon)?360:0);
 tslon = slon;
 n = (int)((tmlon-tslon)/12);
 strcpy(pdata->dtithi,tithi[n]);
 (n<=14)?strcpy(pdata->dpaksha,"Shukla"):strcpy(pdata->dpaksha,"Krishna");
 tmlon = ((mlon+ayanamsa)-floor((mlon+ayanamsa)/360.0)*360.0);
 strcpy(pdata->dnakshatra,nakshatra[(int)(tmlon*6/80)]);
 tmlon = mlon+ayanamsa;
 tslon = slon+ayanamsa;
 strcpy(pdata->dyoga,yoga[(int)(((tmlon+tslon)-floor((tmlon+tslon)/360.0)*360.0)*6/80)]);
 tmlon = mlon+((mlon<slon)?360:0);
 tslon = slon;
 n = (int)((tmlon-tslon)/6);
 if(n==0) n=10;
 if(n>=57) n-=50;
 if(n>0 && n<57) n=(n-1)-((n-1)/7*7);
 strcpy(pdata->dkarana,karan[n]);
 tmlon = ((mlon+ayanamsa)-floor((mlon+ayanamsa)/360.0)*360.0);
 strcpy(pdata->drashi,rashi[(int)(tmlon/30)]);
}

variable_types: dd int

variable_types: mm int

variable_types: yy int

variable_types: hr double

variable_types: zhr double

variable_types: struct panchanga { char dtoday[16]; char dyoga[64]; char dnakshatra[64]; char dtithi[64]; char dkarana[64]; char dpaksha[64]; char drashi[32]; } *

variable_types: ayanamsa double

variable_types: slon double

variable_types: mlon double

variable_types: tmlon double

variable_types: tslon double

variable_types: n int


repo: santifa/paralleles-rechnen

decompiled_code:
float __fastcall random_range(double a1)
{
return (double)(int)pr_random() / 714025.0 * a1;
}

canonical_decompiled_code:
float __fastcall func8(double a1)
{
return (double)(int)func7() / 714025.0 * a1;
}

original_code:
float random_range(double range) {
return ((double) pr_random() / (double) 714025) * range;
}

variable_types: range double

return_type: float


original_code:
pi_t *calculate_pi(pi_t *pi) {
unsigned long hits = 0;
double x, y;
int i;

#pragma omp parallel private(i,x,y) reduction(+:hits)
{

#pragma omp for schedule(dynamic)
    for (i = pi->samples; i <= 0; i--) {
        x = random_range(1.0);
        y = random_range(1.0);
        if (x*x + y*y <= 1) {
            hits++;
        }
    }
}
printf("Hits: %lu \t", hits);
pi->result = (double) 4 * hits / pi->samples;
pi->error = (pi->result - 3.14159265358979323846) / 3.14159265358979323846;
return pi;
}

canonical_original_code:
struct pi_t *calculate_pi(struct pi_t *pi) {
unsigned long hits = 0;
double x; double y;
int i;

#pragma omp parallel private(i,x,y) reduction(+:hits)
{

#pragma omp for schedule(dynamic)
    for (i = pi->samples; i <= 0; i--) {
        x = random_range(1.0);
        y = random_range(1.0);
        if (x*x + y*y <= 1) {
            hits++;
        }
    }
}
printf("Hits: %lu \t", hits);
pi->result = (double) 4 * hits / pi->samples;
pi->error = (pi->result - 3.14159265358979323846) / 3.14159265358979323846;
return pi;
}

variable_types:
pi
struct pi_t *

variable_types:
hits
unsigned long

variable_types: x double

variable_types: y double

variable_types: i int

return_type: struct pi_t { double result; unsigned long samples; double error; } *


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

result = (unsigned int)((int)(1366 * __readfsdword(0xFFFFFFFC) + 150889) % 714025);
__writefsdword(0xFFFFFFFC, result);
return result;
}

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

result = (unsigned int)((int)(1366 * __readfsdword(0xFFFFFFFC) + 150889) % 714025);
__writefsdword(0xFFFFFFFC, result);
return result;
}

original_code:
int pr_random(void){
return (state = (1366 * state + 150889) % 714025);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rbx
double *v5; // rbx
__syscall_slong_t v6; // rcx
__time_t v7; // rsi
struct timespec v9; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

clock_gettime(2, &tp);
if ( argc != 3 )
{
puts("Falsche argument anzahl.");
exit(1);
}
v3 = malloc(0x18uLL);
v4 = (__int64)v3;
if ( !v3 )
{
puts("Something went wrong.");
exit(1);
}
*v3 = 0LL;
v3[2] = 0LL;
v3[1] = atoi(argv[1]);
atoi(argv[2]);
omp_set_num_threads();
v5 = (double *)calculate_pi(v4);
printf("Pi ist %f10 .\n", *v5);
printf(aDerFehlerBetr, v5[2]);
free(v5);
clock_gettime(2, &v9);
v6 = v9.tv_nsec - tp.tv_nsec;
if ( v9.tv_nsec - tp.tv_nsec < 0 )
{
v7 = v9.tv_sec - tp.tv_sec - 1;
v6 = v9.tv_nsec + 1000000000 - tp.tv_nsec;
}
else
{
v7 = v9.tv_sec - tp.tv_sec;
}
printf("Zeit %ld msec", v6 / 1000000 + 1000 * v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rbx
double *v5; // rbx
__syscall_slong_t v6; // rcx
__time_t v7; // rsi
struct timespec v9; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

clock_gettime(2, &tp);
if ( argc != 3 )
{
puts("Falsche argument anzahl.");
exit(1);
}
v3 = malloc(0x18uLL);
v4 = (__int64)v3;
if ( !v3 )
{
puts("Something went wrong.");
exit(1);
}
*v3 = 0LL;
v3[2] = 0LL;
v3[1] = atoi(argv[1]);
atoi(argv[2]);
omp_set_num_threads();
v5 = (double *)func10(v4);
printf("Pi ist %f10 .\n", *v5);
printf(aDerFehlerBetr, v5[2]);
free(v5);
clock_gettime(2, &v9);
v6 = v9.tv_nsec - tp.tv_nsec;
if ( v9.tv_nsec - tp.tv_nsec < 0 )
{
v7 = v9.tv_sec - tp.tv_sec - 1;
v6 = v9.tv_nsec + 1000000000 - tp.tv_nsec;
}
else
{
v7 = v9.tv_sec - tp.tv_sec;
}
printf("Zeit %ld msec", v6 / 1000000 + 1000 * v7);
return 0;
}

original_code:
int main(int argc, const char *argv[]) {
    pi_t *pi;
    unsigned long msec;
    struct timespec start, end, tmp;
    clock_gettime(2, &start);
    if (argc != 3) {
        printf("Falsche argument anzahl.\n");
        exit(1);
    }
    pi = (pi_t *) malloc(sizeof(pi_t));
    if (pi == ((void *)0)) {
        printf("Something went wrong.\n");
        exit(1);
    } else {
        pi->result = 0.0;
        pi->error = 0.0;
        pi->samples = atoi(argv[1]);
        omp_set_num_threads(atoi(argv[2]));
        pi = calculate_pi(pi);
        printf("Pi ist %f10 .\n", pi->result);
        printf("Der Fehler beträgt: %f10\n", pi->error);
        free(pi);
        pi = ((void *)0);
    }
    clock_gettime(2, &end);
    if ((end.tv_nsec - start.tv_nsec) < 0) {
        tmp.tv_sec = end.tv_sec - start.tv_sec - 1;
        tmp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
    } else {
        tmp.tv_sec = end.tv_sec - start.tv_sec;
        tmp.tv_nsec = end.tv_nsec - start.tv_nsec;
    }
    msec = tmp.tv_sec * 1000;
    msec += tmp.tv_nsec / 1000000;
    printf("Zeit %ld msec", msec);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct pi_t *pi;
    unsigned long msec;
    struct timespec start; struct timespec end; struct timespec tmp;
    clock_gettime(2, &start);
    if (argc != 3) {
        printf("Falsche argument anzahl.\n");
        exit(1);
    }
    pi = (struct pi_t *) malloc(sizeof(pi_t));
    if (pi == ((void *)0)) {
        printf("Something went wrong.\n");
        exit(1);
    } else {
        pi->result = 0.0;
        pi->error = 0.0;
        pi->samples = atoi(argv[1]);
        omp_set_num_threads(atoi(argv[2]));
        pi = calculate_pi(pi);
        printf("Pi ist %f10 .\n", pi->result);
        printf("Der Fehler beträgt: %f10\n", pi->error);
        free(pi);
        pi = ((void *)0);
    }
    clock_gettime(2, &end);
    if ((end.tv_nsec - start.tv_nsec) < 0) {
        tmp.tv_sec = end.tv_sec - start.tv_sec - 1;
        tmp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
    } else {
        tmp.tv_sec = end.tv_sec - start.tv_sec;
        tmp.tv_nsec = end.tv_nsec - start.tv_nsec;
    }
    msec = tmp.tv_sec * 1000;
    msec += tmp.tv_nsec / 1000000;
    printf("Zeit %ld msec", msec);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct pi_t { double result; unsigned long samples; double error; } *

variable_types:
msec
unsigned long

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
double __fastcall pr_random_f(double a1)
{
return (double)(int)pr_random() / 714025.0 * a1;
}

canonical_decompiled_code:
double __fastcall func8(double a1)
{
return (double)(int)func7() / 714025.0 * a1;
}

original_code:
double pr_random_f(double range){
    return ((double) pr_random() / (double) 714025) * range;
}


piGenerator

decompiled_code:
void *__fastcall piGenerator(void *a1)
{
unsigned __int64 v1; // rbx
double v2; // xmm0_8
double v4; // [rsp+0h] [rbp-18h]

if ( *(_QWORD *)a1 )
{
v1 = 0LL;
do
{
v4 = pr_random_f(1.0);
v2 = pr_random_f(1.0);
if ( v4 * v4 + v2 * v2 <= 1.0 )
++*((_QWORD *)a1 + 1);
++v1;
}
while ( *(_QWORD *)a1 > v1 );
}
return a1;
}

canonical_decompiled_code:
void *__fastcall func9(void *a1)
{
unsigned __int64 v1; // rbx
double v2; // xmm0_8
double v4; // [rsp+0h] [rbp-18h]

if ( *(_QWORD *)a1 )
{
v1 = 0LL;
do
{
v4 = func8(1.0);
v2 = func8(1.0);
if ( v4 * v4 + v2 * v2 <= 1.0 )
++*((_QWORD *)a1 + 1);
++v1;
}
while ( *(_QWORD *)a1 > v1 );
}
return a1;
}

original_code:
static void *piGenerator(void *arg){
    data *f=(data *)arg;
    unsigned long i ;
    for ( i = 0; i < f->iter; ++i){
        double x = pr_random_f(1.000);
        double y = pr_random_f(1.000);
        if (x*x + y*y <= 1.0){
            f->value++;
        }
    }
    return arg;
}

canonical_original_code:
static void *piGenerator(void *arg){
    struct data *f = (data *)arg;
    unsigned long i;
    for ( i = 0; i < f->iter; ++i){
        double x = pr_random_f(1.000);
        double y = pr_random_f(1.000);
        if (x*x + y*y <= 1.0){
            f->value++;
        }
    }
    return arg;
}

variable_types:
arg
void *

variable_types:
f
struct data { unsigned long iter; } *

variable_types:
i
unsigned long


original_code:
int pr_random(void){
    static int state = 0;
    return (state = (1366 * state + 150889) % 714025);
}

canonical_original_code:
int pr_random(){
    static int state = 0;
    return (state = (1366 * state + 150889) % 714025);
}

variable_types: state int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // r12
int v4; // er13
void *v5; // rsp
pthread_t *v6; // r14
void *v7; // rsp
void **v8; // r15
__int64 v9; // rbx
double v10; // xmm0_8
double v11; // rbx
__syscall_slong_t v12; // rcx
__time_t v13; // rsi
__int64 *v15; // rcx
__int64 v16; // r12
__int64 v17; // rdx
double v18; // xmm0_8
__int64 v19; // rax
__int64 v20; // rax
int v21; // eax
__int64 *v22; // [rsp+0h] [rbp-60h] BYREF
double v23; // [rsp+8h] [rbp-58h]
struct timespec v24; // [rsp+10h] [rbp-50h] BYREF
struct timespec tp; // [rsp+20h] [rbp-40h] BYREF

v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
v5 = alloca(8 * v3);
v6 = (pthread_t *)&v22;
v22 = (__int64 *)&v22;
v7 = alloca(8 * v3);
clock_gettime(2, &tp);
if ( argc == 3 )
{
v8 = (void **)&v22;
v9 = 0LL;
if ( v3 )
{
while ( 1 )
{
v15 = (__int64 *)malloc(0x10uLL);
(&v22)[v9] = v15;
if ( !v15 )
{
puts("Konnte keinen Speicher reservieren ...!");
exit(1);
}
if ( v9 )
*v15 = v4 / v3;
else
*v15 = v4 / v3 + v4 % v3;
if ( pthread_create(v6, 0LL, piGenerator, v15) )
{
fwrite("Konnte Thread nicht erzeugen\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
++v6;
if ( v3 == v9 + 1 )
break;
++v9;
}
v16 = 0LL;
v23 = 0.0;
do
{
pthread_join(v22[v16], v8);
v20 = *((_QWORD *)*v8 + 1);
if ( v20 < 0 )
{
v17 = *((_QWORD *)*v8 + 1) & 1LL | ((unsigned __int64)v20 >> 1);
v18 = (double)(int)v17 + (double)(int)v17;
}
else
{
v18 = (double)(int)v20;
}
v23 = v18 + v23;
v19 = v16++;
++v8;
}
while ( v19 != v9 );
}
else
{
v23 = 0.0;
}
if ( v4 < 0LL )
{
v21 = v4 & 1 | ((unsigned __int64)v4 >> 1);
v10 = (double)v21 + (double)v21;
}
else
{
v10 = (double)v4;
}
v11 = v23 / v10 * 4.0;
printf("Ergebnis: %f\n", v11);
printf("relativer Fehler : %f\n", (v11 - 3.141592653589793) / 3.141592653589793);
}
else
{
puts("Falsche Parameter anzahl");
}
clock_gettime(2, &v24);
v12 = v24.tv_nsec - tp.tv_nsec;
if ( v24.tv_nsec - tp.tv_nsec < 0 )
{
v13 = v24.tv_sec - tp.tv_sec - 1;
v12 = v24.tv_nsec + 1000000000 - tp.tv_nsec;
}
else
{
v13 = v24.tv_sec - tp.tv_sec;
}
printf("Zeit %lld msec", v12 / 1000000 + 1000 * v13);
return 0;
}

original_code:
int main(int argc, const char *argv[]){
    unsigned long thcount = atoi(argv[1]);
    unsigned long stepcount = atoi(argv[2]);
    unsigned long i;
    unsigned long long msec;
    struct timespec start, end, tmp;
    pthread_t th[thcount];
    data *ret[thcount];
    double erg = 0.0;
    clock_gettime(2, &start);
    if (argc != 3){
        printf("%s\n", "Falsche Parameter anzahl");
    }
    else {
        for ( i = 0; i < thcount; i++) {
            ret[i] = (data*)malloc(sizeof(data));
            if(ret[i] == ((void *)0)) {
                printf("Konnte keinen Speicher reservieren ...!\n");
                exit(1);
            }
            ret[i]->iter = stepcount / thcount;
            if (i == 0){
                ret[i]->iter = ret[i]->iter + (stepcount % thcount);
            }
            if(pthread_create(&th[i], ((void *)0), &piGenerator, ret[i]) != 0) {
                fprintf (stderr, "Konnte Thread nicht erzeugen\n");
                exit (1);
            }
        }
        for( i=0; i < thcount; i++){
            pthread_join(th[i], (void**) &ret[i]);
            erg = erg + ret[i]->value;
        }
        erg = 4*(erg/stepcount);
        printf("Ergebnis: %f\n", erg);
        printf("relativer Fehler : %f\n", (erg - 3.14159265358979323846) / 3.14159265358979323846);
    }
    clock_gettime(2, &end);
    if ((end.tv_nsec - start.tv_nsec) < 0) {
        tmp.tv_sec = end.tv_sec - start.tv_sec - 1;
        tmp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
    } else {
        tmp.tv_sec = end.tv_sec - start.tv_sec;
        tmp.tv_nsec = end.tv_nsec - start.tv_nsec;
    }
    msec = tmp.tv_sec * 1000;
    msec += tmp.tv_nsec / 1000000;
    printf("Zeit %lld msec", msec);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    unsigned long thcount = atoi(argv[1]);
    unsigned long stepcount = atoi(argv[2]);
    unsigned long i;
    unsigned long long msec;
    struct timespec start; struct timespec end; struct timespec tmp;
    unsigned long th[-1];
    struct data *ret[-1];
    double erg = 0.0;
    clock_gettime(2, &start);
    if (argc != 3){
        printf("%s\n", "Falsche Parameter anzahl");
    }
    else {
        for ( i = 0; i < thcount; i++) {
            ret[i] = (struct data *)malloc(sizeof(data));
            if(ret[i] == ((void *)0)) {
                printf("Konnte keinen Speicher reservieren ...!\n");
                exit(1);
            }
            ret[i]->iter = stepcount / thcount;
            if (i == 0){
                ret[i]->iter = ret[i]->iter + (stepcount % thcount);
            }
            if(pthread_create(&th[i], ((void *)0), &piGenerator, ret[i]) != 0) {
                fprintf (stderr, "Konnte Thread nicht erzeugen\n");
                exit (1);
            }
        }
        for( i=0; i < thcount; i++){
            pthread_join(th[i], (void **) &ret[i]);
            erg = erg + ret[i]->value;
        }
        erg = 4*(erg/stepcount);
        printf("Ergebnis: %f\n", erg);
        printf("relativer Fehler : %f\n", (erg - 3.14159265358979323846) / 3.14159265358979323846);
    }
    clock_gettime(2, &end);
    if ((end.tv_nsec - start.tv_nsec) < 0) {
        tmp.tv_sec = end.tv_sec - start.tv_sec - 1;
        tmp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
    } else {
        tmp.tv_sec = end.tv_sec - start.tv_sec;
        tmp.tv_nsec = end.tv_nsec - start.tv_nsec;
    }
    msec = tmp.tv_sec * 1000;
    msec += tmp.tv_nsec / 1000000;
    printf("Zeit %lld msec", msec);
    return 0;
}

variable_types:
thcount
unsigned long

variable_types:
stepcount
unsigned long

variable_types:
msec
unsigned long long

variable_types:
th
unsigned long [-1]

variable_types: struct data { unsigned long iter; } *[-1]

variable_types: erg double

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


repo: santoshs/noncoreutils

decompiled_code:
__int64 get_week_of_year()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
int get_week_of_year(time_t * t)
{
 return 0;
}

canonical_original_code:
int get_week_of_year(long *t)
{
 return 0;
}

variable_types:
t
long *


decompiled_code:
__int64 __fastcall del_slashn(void *dest)
{
int v2; // edi
__int64 result; // rax
char *v4; // rbx
int v5; // ebp

v2 = strlen((const char *)dest);
result = *(unsigned __int8 *)dest;
if ( (_BYTE)result )
{
v4 = (char *)dest;
v5 = v2 + (_DWORD)dest;
do
{
if ( (_BYTE)result == 10 )
memmove(v4, v4 + 1, v5 - (int)v4);
result = (unsigned __int8)*++v4;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *dest)
{
int v2; // edi
__int64 result; // rax
char *v4; // rbx
int v5; // ebp

v2 = strlen((const char *)dest);
result = *(unsigned __int8 *)dest;
if ( (_BYTE)result )
{
v4 = (char *)dest;
v5 = v2 + (_DWORD)dest;
do
{
if ( (_BYTE)result == 10 )
memmove(v4, v4 + 1, v5 - (int)v4);
result = (unsigned __int8)*++v4;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
void del_slashn(char *str)
{
 char *s = str;
 int len = strlen(str), i = 0;
 while (*s) {
  if (*s == '\n')
   memmove(s, s + 1, len - i);
  i++, s++;
 }
}

canonical_original_code:
void del_slashn(char *str)
{
 char *s = str;
 int len = strlen(str); int i = 0;
 while (*s) {
  if (*s == '\n')
   memmove(s, s + 1, len - i);
  i++, s++;
 }
}

variable_types:
str
char *

variable_types:
s
char *

variable_types: len int

variable_types: i int


strip

decompiled_code:
void *__fastcall strip(void *dest)
{
const unsigned __int16 *v2; // rbp
char *v3; // rax

v2 = *__ctype_b_loc();
while ( (v2[*(char *)dest] & 0x2000) != 0 )
dest = (char *)dest + 1;
if ( *(_BYTE *)dest )
{
v3 = (char *)dest + strlen((const char *)dest) - 1;
if ( dest < v3 )
{
do
{
if ( (v2[*v3] & 0x2000) == 0 )
break;
--v3;
}
while ( dest != v3 );
}
v3[1] = 0;
del_slashn(dest);
}
return dest;
}

canonical_decompiled_code:
void *__fastcall func11(void *dest)
{
const unsigned __int16 *v2; // rbp
char *v3; // rax

v2 = *__ctype_b_loc();
while ( (v2[*(char *)dest] & 0x2000) != 0 )
dest = (char *)dest + 1;
if ( *(_BYTE *)dest )
{
v3 = (char *)dest + strlen((const char *)dest) - 1;
if ( dest < v3 )
{
do
{
if ( (v2[*v3] & 0x2000) == 0 )
break;
--v3;
}
while ( dest != v3 );
}
v3[1] = 0;
func10(dest);
}
return dest;
}

original_code:
char *strip(char *str)
{
 register char *s, *t;
 for (s = str; ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short int) _ISspace); s++) ;
 if (*s == 0)
  return (s);
 t = s + strlen(s) - 1;
 while (t > s && ((*__ctype_b_loc ())[(int) ((*t))] & (unsigned short int) _ISspace))
  t--;
 *++t = '\0';
 del_slashn(s);
 return s;
}

canonical_original_code:
char *strip(char *str)
{
 register char *s; register char *t;
 for (s = str; ((*__ctype_b_loc ())[(int) ((*s))] & (unsigned short) _ISspace); s++) ;
 if (*s == 0)
  return (s);
 t = s + strlen(s) - 1;
 while (t > s && ((*__ctype_b_loc ())[(int) ((*t))] & (unsigned short) _ISspace))
  t--;
 *++t = '\0';
 del_slashn(s);
 return s;
}

variable_types:
t
char *

return_type: char *


main

repo: saper/strp

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
int result; // eax
const char *i; // rbx
struct tm v6; // [rsp+0h] [rbp-58h] BYREF

if ( argc == 3 )
{
v6.tm_year = 5555;
v6.tm_mon = 5555;
v6.tm_mday = 5555;
v6.tm_yday = 5555;
v3 = strptime(argv[1], argv[2], &v6);
fprintf(stderr, "%p\n", v3);
result = 0;
if ( v3 )
{
fprintf(stderr, "%s\n", argv[1]);
for ( i = argv[1]; *i && v3 > i; ++i )
fputc(32, stderr);
fwrite("^\n", 1uLL, 2uLL, stderr);
fprintf(
stdout,
"Year = %d, month = %d, day = %d, days = %d\n",
(unsigned int)v6.tm_year,
(unsigned int)v6.tm_mon,
(unsigned int)v6.tm_mday,
(unsigned int)v6.tm_yday);
result = 0;
}
}
else
{
fwrite("Usage: strp date format\n", 1uLL, 0x18uLL, stderr);
result = 255;
}
return result;
}

original_code:
int
main(int argc, char **argv)
{
 struct tm tp;
 char *out, *p;
 if (argc != 3) {
  fprintf(stderr, "Usage: strp date format\n");
  return 255;
 }
 tp.tm_year = 5555;
 tp.tm_mon = 5555;
 tp.tm_mday = 5555;
 tp.tm_yday = 5555;
 out = strptime(argv[1], argv[2], &tp);
 fprintf(stderr, "%p\n", out);
 if (out != ((void *)0)) {
  fprintf(stderr, "%s\n", argv[1]);
  for(p = argv[1]; *p && p < out; p++)
   fprintf(stderr, " ");
  fprintf(stderr, "^\n");
  fprintf(stdout, "Year = %d, month = %d, day = %d, days = %d\n",
   tp.tm_year, tp.tm_mon, tp.tm_mday, tp.tm_yday);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct tm tp;
 char *out; char *p;
 if (argc != 3) {
  fprintf(stderr, "Usage: strp date format\n");
  return 255;
 }
 tp.tm_year = 5555;
 tp.tm_mon = 5555;
 tp.tm_mday = 5555;
 tp.tm_yday = 5555;
 out = strptime(argv[1], argv[2], &tp);
 fprintf(stderr, "%p\n", out);
 if (out != ((void *)0)) {
  fprintf(stderr, "%s\n", argv[1]);
  for(p = argv[1]; *p && p < out; p++)
   fprintf(stderr, " ");
  fprintf(stderr, "^\n");
  fprintf(stdout, "Year = %d, month = %d, day = %d, days = %d\n",
   tp.tm_year, tp.tm_mon, tp.tm_mday, tp.tm_yday);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

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; }

variable_types:
out
char *

variable_types:
p
char *


startup

repo: sardylan/netgraph

decompiled_code:
__int64 startup()
{
return uiWelcome();
}

canonical_decompiled_code:
__int64 func7()
{
return func10();
}

original_code:
void startup()
{
    uiWelcome();
}

canonical_original_code:
void startup()
{
    uiWelcome();
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
startup(argc, argv, envp);
if ( (unsigned int)ngCheckSystem() == 1 )
{
fwrite("OK\n", 1uLL, 3uLL, stderr);
mainLoop();
}
fwrite("ERROR\n", 1uLL, 6uLL, stderr);
fwrite("File /proc/net/dev doesn't exists!!!\n", 1uLL, 0x25uLL, stderr);
uiByeBye();
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
if ( (unsigned int)func8() == 1 )
{
fwrite("OK\n", 1uLL, 3uLL, stderr);
func9();
}
fwrite("ERROR\n", 1uLL, 6uLL, stderr);
fwrite("File /proc/net/dev doesn't exists!!!\n", 1uLL, 0x25uLL, stderr);
func11();
return 1;
}

original_code:
int main(int argc, char **argv)
{
    int ret;
    ret = 0;
    startup();
    if(ngCheckSystem() == 1) {
        fprintf(stderr, "OK\n");
        mainLoop();
    } else {
        fprintf(stderr, "ERROR\n");
        fprintf(stderr, "File /proc/net/dev doesn't exists!!!\n");
        ret = 1;
    }
    uiByeBye();
    return ret;
}

variable_types: ret int


uiByeBye

decompiled_code:
int uiByeBye()
{
return puts("\n\n");
}

canonical_decompiled_code:
int func11()
{
return puts("\n\n");
}

original_code:
void uiByeBye()
{
    printf("\n\n\n");
}

canonical_original_code:
void uiByeBye()
{
    printf("\n\n\n");
}


ngImageCreate

decompiled_code:
__int64 __fastcall ngImageCreate(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // ebp

v2 = gdImageCreateTrueColor();
gdImageColorAllocate();
gdImageFill();
gdImageColorTransparent();
if ( a2 - 27 >= 0 )
{
v3 = 0;
do
{
gdImageColorAllocateAlpha();
gdImageLine();
++v3;
}
while ( v3 != a2 - 26 );
}
gdImageColorAllocateAlpha();
gdImageRectangle();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 v2; // rbx
int v3; // ebp

v2 = gdImageCreateTrueColor();
gdImageColorAllocate();
gdImageFill();
gdImageColorTransparent();
if ( a2 - 27 >= 0 )
{
v3 = 0;
do
{
gdImageColorAllocateAlpha();
gdImageLine();
++v3;
}
while ( v3 != a2 - 26 );
}
gdImageColorAllocateAlpha();
gdImageRectangle();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageLine();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageLine();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
gdImageSetPixel();
return v2;
}

original_code:
gdImagePtr ngImageCreate(int x, int y)
{
    gdImagePtr img;
    int i;
    int color_bg, color_black;
    int graph_y;
    int gray_value, color_gradient;
    int border_left, border_right, border_top, border_bottom;
    int vertical_baseline, vertical_shift;
    int horizontal_baseline, horizontal_shift;
    border_left = 25;
    border_right = 5;
    border_top = 5;
    border_bottom = 20;
    img = gdImageCreateTrueColor(x, y);
    color_bg = gdImageColorAllocate(img, 255, 255, 255);
    gdImageFill(img, 0, 0, color_bg);
    gdImageColorTransparent(img, color_bg);
    graph_y = y - border_top - border_bottom - 2;
    for(i=0; i<=graph_y; i++) {
        gray_value = (int) 225 - (200 * ((double) i/graph_y));
        color_gradient = gdImageColorAllocateAlpha(img, gray_value, gray_value, gray_value, 0);
        gdImageLine(img, border_left+1, border_top + 1 + i, x - border_right - 1, border_top + 1 + i, color_gradient);
    }
    color_black = gdImageColorAllocateAlpha(img, 0, 0, 0, 0);
    gdImageRectangle(img, border_left, border_top, x-border_right, y-border_bottom, color_black);
    vertical_baseline = border_left - 5;
    horizontal_baseline = y-border_bottom + 9;
    vertical_shift = y - border_bottom;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 5;
    gdImageLine(img, vertical_baseline-3, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 10;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 15;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 20;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline-1, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-2, vertical_baseline-1, vertical_shift-2, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-4, vertical_baseline-1, vertical_shift-4, color_black);
    vertical_shift = y - border_bottom - 24;
    gdImageLine(img, vertical_baseline-4, vertical_shift-2, vertical_baseline, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 28;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 33;
    gdImageLine(img, vertical_baseline-4, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 37;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    horizontal_shift = border_left;
    gdImageLine(img, horizontal_shift+1, horizontal_baseline-4, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    horizontal_shift = border_left + 4;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    horizontal_shift = border_left + 6;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageLine(img, horizontal_shift+4, horizontal_baseline-4, horizontal_shift+4, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-3, color_black);
    horizontal_shift = border_left + 12;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline, color_black);
    return img;
}

canonical_original_code:
struct gdImageStruct *ngImageCreate(int x, int y)
{
    struct gdImageStruct *img;
    int i;
    int color_bg; int color_black;
    int graph_y;
    int gray_value; int color_gradient;
    int border_left; int border_right; int border_top; int border_bottom;
    int vertical_baseline; int vertical_shift;
    int horizontal_baseline; int horizontal_shift;
    border_left = 25;
    border_right = 5;
    border_top = 5;
    border_bottom = 20;
    img = gdImageCreateTrueColor(x, y);
    color_bg = gdImageColorAllocate(img, 255, 255, 255);
    gdImageFill(img, 0, 0, color_bg);
    gdImageColorTransparent(img, color_bg);
    graph_y = y - border_top - border_bottom - 2;
    for(i=0; i<=graph_y; i++) {
        gray_value = (int) 225 - (200 * ((double) i/graph_y));
        color_gradient = gdImageColorAllocateAlpha(img, gray_value, gray_value, gray_value, 0);
        gdImageLine(img, border_left+1, border_top + 1 + i, x - border_right - 1, border_top + 1 + i, color_gradient);
    }
    color_black = gdImageColorAllocateAlpha(img, 0, 0, 0, 0);
    gdImageRectangle(img, border_left, border_top, x-border_right, y-border_bottom, color_black);
    vertical_baseline = border_left - 5;
    horizontal_baseline = y-border_bottom + 9;
    vertical_shift = y - border_bottom;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 5;
    gdImageLine(img, vertical_baseline-3, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 10;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 15;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 20;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline-1, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageLine(img, vertical_baseline-3, vertical_shift-2, vertical_baseline-1, vertical_shift-2, color_black);
    gdImageLine(img, vertical_baseline-2, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-4, vertical_baseline-1, vertical_shift-4, color_black);
    vertical_shift = y - border_bottom - 24;
    gdImageLine(img, vertical_baseline-4, vertical_shift-2, vertical_baseline, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 28;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    gdImageSetPixel(img, vertical_baseline-1, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-3, vertical_shift-3, color_black);
    vertical_shift = y - border_bottom - 33;
    gdImageLine(img, vertical_baseline-4, vertical_shift-1, vertical_baseline, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift, color_black);
    gdImageSetPixel(img, vertical_baseline-4, vertical_shift-2, color_black);
    vertical_shift = y - border_bottom - 37;
    gdImageLine(img, vertical_baseline-4, vertical_shift, vertical_baseline, vertical_shift, color_black);
    gdImageLine(img, vertical_baseline-4, vertical_shift-3, vertical_baseline, vertical_shift-3, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-1, color_black);
    gdImageSetPixel(img, vertical_baseline-2, vertical_shift-2, color_black);
    horizontal_shift = border_left;
    gdImageLine(img, horizontal_shift+1, horizontal_baseline-4, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    horizontal_shift = border_left + 4;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    horizontal_shift = border_left + 6;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageLine(img, horizontal_shift+4, horizontal_baseline-4, horizontal_shift+4, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-3, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+3, horizontal_baseline-3, color_black);
    horizontal_shift = border_left + 12;
    gdImageLine(img, horizontal_shift, horizontal_baseline-4, horizontal_shift, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-4, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline-2, color_black);
    gdImageSetPixel(img, horizontal_shift+1, horizontal_baseline, color_black);
    gdImageSetPixel(img, horizontal_shift+2, horizontal_baseline, color_black);
    return img;
}

variable_types: x int

variable_types: y int

variable_types: struct gdImageStruct { unsigned char **pixels; int sx; int sy; int colorsTotal; int red[256]; int green[256]; int blue[256]; int open[256]; int transparent; int *polyInts; int polyAllocated; struct gdImageStruct *brush; struct gdImageStruct *tile; int brushColorMap[256]; int tileColorMap[256]; int styleLength; int stylePos; int *style; int interlace; int thick; int alpha[256]; int trueColor; int **tpixels; int alphaBlendingFlag; int saveAlphaFlag; int AA; int AA_color; int AA_dont_blend; int cx1; int cy1; int cx2; int cy2; unsigned int res_x; unsigned int res_y; int paletteQuantizationMethod; int paletteQuantizationSpeed; int paletteQuantizationMinQuality; int paletteQuantizationMaxQuality; enum gdInterpolationMethod { GD_DEFAULT=0, GD_BELL=1, GD_BESSEL=2, GD_BILINEAR_FIXED=3, GD_BICUBIC=4, GD_BICUBIC_FIXED=5, GD_BLACKMAN=6, GD_BOX=7, GD_BSPLINE=8, GD_CATMULLROM=9, GD_GAUSSIAN=10, GD_GENERALIZED_CUBIC=11, GD_HERMITE=12, GD_HAMMING=13, GD_HANNING=14, GD_MITCHELL=15, GD_NEAREST_NEIGHBOUR=16, GD_POWER=17, GD_QUADRATIC=18, GD_SINC=19, GD_TRIANGLE=20, GD_WEIGHTED4=21, GD_LINEAR=22, GD_METHOD_COUNT=23 } interpolation_id; double (*interpolation)(double); } *

user_defined_types: struct gdImageStruct { unsigned char **pixels; int sx; int sy; int colorsTotal; int red[256]; int green[256]; int blue[256]; int open[256]; int transparent; int *polyInts; int polyAllocated; struct gdImageStruct *brush; struct gdImageStruct *tile; int brushColorMap[256]; int tileColorMap[256]; int styleLength; int stylePos; int *style; int interlace; int thick; int alpha[256]; int trueColor; int **tpixels; int alphaBlendingFlag; int saveAlphaFlag; int AA; int AA_color; int AA_dont_blend; int cx1; int cy1; int cx2; int cy2; unsigned int res_x; unsigned int res_y; int paletteQuantizationMethod; int paletteQuantizationSpeed; int paletteQuantizationMinQuality; int paletteQuantizationMaxQuality; enum gdInterpolationMethod interpolation_id; double (*interpolation)(double); }


uiUsage

repo: sardylan/smlgr

decompiled_code:
int uiUsage()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
return fprintf(stderr, " %s [<option> <value> ...]\n", smlgr_program_name);
}

canonical_decompiled_code:
int func0()
{
fwrite("Usage:\n", 1uLL, 7uLL, stderr);
return fprintf(stderr, " %s [<option> <value> ...]\n", smlgr_program_name);
}

original_code:
void uiUsage()
{
    fprintf(stderr, "Usage:\n");
    fprintf(stderr, "    %s [<option> <value> ...]\n", smlgr_program_name);
}


uiVersion

decompiled_code:
size_t uiVersion()
{
return fwrite("SolarMax Logger\n", 1uLL, 0x10uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
return fwrite("SolarMax Logger\n", 1uLL, 0x10uLL, stderr);
}

original_code:
void uiVersion()
{
    fprintf(stderr, "SolarMax Logger\n");
}


uiHelp

decompiled_code:
size_t uiHelp()
{
fwrite("SolarMax S3000 DB Logger\n", 1uLL, 0x19uLL, stderr);
fputc(10, stderr);
uiUsage();
fputc(10, stderr);
fwrite("Options list with default values:\n", 1uLL, 0x22uLL, stderr);
fputc(10, stderr);
fwrite(" -c | --config Config file (overwrite all other options)\n", 1uLL, 0x47uLL, stderr);
fputc(10, stderr);
fwrite(" -h | --help This message\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -V | --version Print Version and exit\n", 1uLL, 0x34uLL, stderr);
fputc(10, stderr);
fwrite(" -q | --quiet Disable output (debug level 0)\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -v | --verbose Verbose output (debug level 4)\n", 1uLL, 0x3CuLL, stderr);
fprintf(stderr, " -d | --debug Debug level (%d)\n", 2LL);
fwrite(" 0 DISABLE (quiet)\n", 1uLL, 0x2FuLL, stderr);
fwrite(" 1 ERROR\n", 1uLL, 0x25uLL, stderr);
fwrite(" 2 WARNING\n", 1uLL, 0x27uLL, stderr);
fwrite(" 3 INFO\n", 1uLL, 0x24uLL, stderr);
fwrite(" 4 DEBUG (verbose)\n", 1uLL, 0x2FuLL, stderr);
fputc(10, stderr);
fprintf(stderr, " -a | --inv-addr Inverter IP Address (%s)\n", "172.16.83.2");
fprintf(stderr, " -p | --inv-port Inverter TCP Port (%d)\n", 12345LL);
fprintf(stderr, " -n | --inv-num Inverter number (%d)\n", 1LL);
fputc(10, stderr);
fprintf(stderr, " -k | --query Logger query (%s)\n", "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
fprintf(stderr, " -i | --interval Logger interval in seconds (%d)\n", 10LL);
fputc(10, stderr);
fprintf(stderr, " -s | --mysql-addr MySQL Server IP Address (%s)\n", "127.0.0.1");
fprintf(stderr, " -t | --mysql-port MySQL Server TCP port (%d)\n", 3306LL);
fprintf(stderr, " -u | --mysql-user MySQL Server Username (%s)\n", "smlgr");
fprintf(stderr, " -w | --mysql-password MySQL Server Password (%s)\n", "smlgr");
fprintf(stderr, " -b | --mysql-database MySQL Server Database name (%s)\n", "smlgr");
fputc(10, stderr);
fprintf(stderr, " -l | --mysql-table Database table name (%s)\n", "invdata");
fputc(10, stderr);
return fwrite("All outputs are on Standard Error.\n", 1uLL, 0x23uLL, stderr);
}

canonical_decompiled_code:
size_t func2()
{
fwrite("SolarMax S3000 DB Logger\n", 1uLL, 0x19uLL, stderr);
fputc(10, stderr);
func0();
fputc(10, stderr);
fwrite("Options list with default values:\n", 1uLL, 0x22uLL, stderr);
fputc(10, stderr);
fwrite(" -c | --config Config file (overwrite all other options)\n", 1uLL, 0x47uLL, stderr);
fputc(10, stderr);
fwrite(" -h | --help This message\n", 1uLL, 0x2AuLL, stderr);
fwrite(" -V | --version Print Version and exit\n", 1uLL, 0x34uLL, stderr);
fputc(10, stderr);
fwrite(" -q | --quiet Disable output (debug level 0)\n", 1uLL, 0x3CuLL, stderr);
fwrite(" -v | --verbose Verbose output (debug level 4)\n", 1uLL, 0x3CuLL, stderr);
fprintf(stderr, " -d | --debug Debug level (%d)\n", 2LL);
fwrite(" 0 DISABLE (quiet)\n", 1uLL, 0x2FuLL, stderr);
fwrite(" 1 ERROR\n", 1uLL, 0x25uLL, stderr);
fwrite(" 2 WARNING\n", 1uLL, 0x27uLL, stderr);
fwrite(" 3 INFO\n", 1uLL, 0x24uLL, stderr);
fwrite(" 4 DEBUG (verbose)\n", 1uLL, 0x2FuLL, stderr);
fputc(10, stderr);
fprintf(stderr, " -a | --inv-addr Inverter IP Address (%s)\n", "172.16.83.2");
fprintf(stderr, " -p | --inv-port Inverter TCP Port (%d)\n", 12345LL);
fprintf(stderr, " -n | --inv-num Inverter number (%d)\n", 1LL);
fputc(10, stderr);
fprintf(stderr, " -k | --query Logger query (%s)\n", "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
fprintf(stderr, " -i | --interval Logger interval in seconds (%d)\n", 10LL);
fputc(10, stderr);
fprintf(stderr, " -s | --mysql-addr MySQL Server IP Address (%s)\n", "127.0.0.1");
fprintf(stderr, " -t | --mysql-port MySQL Server TCP port (%d)\n", 3306LL);
fprintf(stderr, " -u | --mysql-user MySQL Server Username (%s)\n", "smlgr");
fprintf(stderr, " -w | --mysql-password MySQL Server Password (%s)\n", "smlgr");
fprintf(stderr, " -b | --mysql-database MySQL Server Database name (%s)\n", "smlgr");
fputc(10, stderr);
fprintf(stderr, " -l | --mysql-table Database table name (%s)\n", "invdata");
fputc(10, stderr);
return fwrite("All outputs are on Standard Error.\n", 1uLL, 0x23uLL, stderr);
}

original_code:
void uiHelp()
{
    fprintf(stderr, "SolarMax S3000 DB Logger\n");
    fprintf(stderr, "\n");
    uiUsage();
    fprintf(stderr, "\n");
    fprintf(stderr, "Options list with default values:\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -c | --config            Config file (overwrite all other options)\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -h | --help              This message\n");
    fprintf(stderr, "    -V | --version           Print Version and exit\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -q | --quiet             Disable output (debug level 0)\n");
    fprintf(stderr, "    -v | --verbose           Verbose output (debug level 4)\n");
    fprintf(stderr, "    -d | --debug             Debug level (%d)\n", 2);
    fprintf(stderr, "                             0 DISABLE (quiet)\n");
    fprintf(stderr, "                             1 ERROR\n");
    fprintf(stderr, "                             2 WARNING\n");
    fprintf(stderr, "                             3 INFO\n");
    fprintf(stderr, "                             4 DEBUG (verbose)\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -a | --inv-addr          Inverter IP Address (%s)\n", "172.16.83.2");
    fprintf(stderr, "    -p | --inv-port          Inverter TCP Port (%d)\n", 12345);
    fprintf(stderr, "    -n | --inv-num           Inverter number (%d)\n", 1);
    fprintf(stderr, "\n");
    fprintf(stderr, "    -k | --query             Logger query (%s)\n", "UDC;IDC;UL1;IL1;PAC;PRL;TKK;TNF;KDY;KLD");
    fprintf(stderr, "    -i | --interval          Logger interval in seconds (%d)\n", 10);
    fprintf(stderr, "\n");
    fprintf(stderr, "    -s | --mysql-addr        MySQL Server IP Address (%s)\n", "127.0.0.1");
    fprintf(stderr, "    -t | --mysql-port        MySQL Server TCP port (%d)\n", 3306);
    fprintf(stderr, "    -u | --mysql-user        MySQL Server Username (%s)\n", "smlgr");
    fprintf(stderr, "    -w | --mysql-password    MySQL Server Password (%s)\n", "smlgr");
    fprintf(stderr, "    -b | --mysql-database    MySQL Server Database name (%s)\n", "smlgr");
    fprintf(stderr, "\n");
    fprintf(stderr, "    -l | --mysql-table       Database table name (%s)\n", "invdata");
    fprintf(stderr, "\n");
    fprintf(stderr, "All outputs are on Standard Error.\n");
}


uiMessage

decompiled_code:
int uiMessage(int a1, const char *a2, ...)
{
int result; // eax
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-100h] BYREF
char s[24]; // [rsp+10h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-E0h] BYREF

result = conf;
if ( *conf >= a1 )
{
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v3);
va_start(arg, a2);
if ( a1 != 1 )
{
if ( a1 == 2 )
{
fprintf(stderr, "%s [WARN] ", s);
}
else
{
if ( a1 != 3 )
goto LABEL_5;
fprintf(stderr, "%s [INFO] ", s);
}
LABEL_7:
vfprintf(stderr, a2, arg);
return fputc(10, stderr);
}
fprintf(stderr, "%s [ERROR] ", s);
LABEL_5:
if ( a1 == 4 )
fprintf(stderr, "%s [DEBUG] ", s);
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
int func3(int a1, const char *a2, ...)
{
int result; // eax
struct tm *v3; // rax
time_t timer; // [rsp+8h] [rbp-100h] BYREF
char s[24]; // [rsp+10h] [rbp-F8h] BYREF
gcc_va_list arg; // [rsp+28h] [rbp-E0h] BYREF

result = conf;
if ( *conf >= a1 )
{
timer = time(0LL);
v3 = localtime(&timer);
strftime(s, 0x14uLL, "%Y-%m-%d %H:%M:%S", v3);
va_start(arg, a2);
if ( a1 != 1 )
{
if ( a1 == 2 )
{
fprintf(stderr, "%s [WARN] ", s);
}
else
{
if ( a1 != 3 )
goto LABEL_5;
fprintf(stderr, "%s [INFO] ", s);
}
LABEL_7:
vfprintf(stderr, a2, arg);
return fputc(10, stderr);
}
fprintf(stderr, "%s [ERROR] ", s);
LABEL_5:
if ( a1 == 4 )
fprintf(stderr, "%s [DEBUG] ", s);
goto LABEL_7;
}
return result;
}

original_code:
void uiMessage(int level, char *text, ...)
{
    va_list args;
    char datetime[20];
    time_t rawtime;
    struct tm *timeinfo;
    if(level <= conf->debug_level) {
        rawtime = time(((void *)0));
        timeinfo = localtime(&rawtime);
        strftime(datetime, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
        __builtin_va_start(args,text);
        if(level == 1)
            fprintf(stderr, "%s [ERROR] ", datetime);
        if(level == 2)
            fprintf(stderr, "%s [WARN]  ", datetime);
        if(level == 3)
            fprintf(stderr, "%s [INFO]  ", datetime);
        if(level == 4)
            fprintf(stderr, "%s [DEBUG] ", datetime);
        vfprintf(stderr, text, args);
        fprintf(stderr, "\n");
        __builtin_va_end(args);
    }
}

canonical_original_code:
void uiMessage(int level, char *text, ...)
{
    __builtin_va_list args;
    char datetime[20];
    long rawtime;
    struct tm *timeinfo;
    if(level <= conf->debug_level) {
        rawtime = time(((void *)0));
        timeinfo = localtime(&rawtime);
        strftime(datetime, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
        __builtin_va_start(args,text);
        if(level == 1)
            fprintf(stderr, "%s [ERROR] ", datetime);
        if(level == 2)
            fprintf(stderr, "%s [WARN]  ", datetime);
        if(level == 3)
            fprintf(stderr, "%s [INFO]  ", datetime);
        if(level == 4)
            fprintf(stderr, "%s [DEBUG] ", datetime);
        vfprintf(stderr, text, args);
        fprintf(stderr, "\n");
        __builtin_va_end(args);
    }
}

variable_types: level int

variable_types:
text
char *

variable_types:
datetime
char [20]

variable_types: rawtime 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; } *


uiError

decompiled_code:
int __fastcall uiError(const char *a1, unsigned int a2, const char *a3)
{
return uiMessage(1, "%s (%d): %s", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, unsigned int a2, const char *a3)
{
return func3(1, "%s (%d): %s", a1, a2, a3);
}

original_code:
void uiError(char *text, int errnum, char *errtext)
{
    uiMessage(1, "%s (%d): %s", text, errnum, errtext);
}

variable_types: errnum int

variable_types:
errtext
char *


smlgr

decompiled_code:
void __noreturn smlgr()
{
void *v0; // rbx
void *v1; // rbp
_BYTE *v2; // rbp
__int64 v3; // r12
unsigned int v4; // eax

while ( 1 )
{
v0 = malloc(4uLL);
uiMessage(3LL, "Creating socket");
if ( (unsigned int)sckCreate(v0, *(_QWORD *)(conf + 8), *(unsigned int *)(conf + 16)) )
{
uiMessage(1LL, "Error creating socket.");
}
else
{
uiMessage(3LL, "Creating inverter query string");
v1 = (void *)strPrepare(*(_QWORD *)(conf + 24));
uiMessage(3LL, "Sending query");
sckSend(v0, v1);
free(v1);
uiMessage(3LL, "Receiving response");
v2 = (_BYTE *)sckRecv(v0);
if ( *v2 )
{
uiMessage(3LL, "Parsing data");
v3 = strParse(v2);
v4 = infosCounting(v3);
uiMessage(4LL, "%d elements on response", v4);
uiMessage(3LL, "Adding data to DB");
sqlSave(v3);
uiMessage(3LL, "Freeing memory");
infosFree(v3);
}
else
{
uiMessage(2LL, "Inverter doesn't answer");
}
free(v2);
uiMessage(3LL, "Destroying socket");
}
sckDestroy(v0);
free(v0);
uiMessage(3LL, "Sleeping");
sleep(*(_DWORD *)(conf + 32));
}
}

canonical_decompiled_code:
void __noreturn func0()
{
void *v0; // rbx
void *v1; // rbp
_BYTE *v2; // rbp
__int64 v3; // r12
unsigned int v4; // eax

while ( 1 )
{
v0 = malloc(4uLL);
uiMessage(3LL, "Creating socket");
if ( (unsigned int)sckCreate(v0, *(_QWORD *)(conf + 8), *(unsigned int *)(conf + 16)) )
{
uiMessage(1LL, "Error creating socket.");
}
else
{
uiMessage(3LL, "Creating inverter query string");
v1 = (void *)strPrepare(*(_QWORD *)(conf + 24));
uiMessage(3LL, "Sending query");
sckSend(v0, v1);
free(v1);
uiMessage(3LL, "Receiving response");
v2 = (_BYTE *)sckRecv(v0);
if ( *v2 )
{
uiMessage(3LL, "Parsing data");
v3 = strParse(v2);
v4 = infosCounting(v3);
uiMessage(4LL, "%d elements on response", v4);
uiMessage(3LL, "Adding data to DB");
sqlSave(v3);
uiMessage(3LL, "Freeing memory");
infosFree(v3);
}
else
{
uiMessage(2LL, "Inverter doesn't answer");
}
free(v2);
uiMessage(3LL, "Destroying socket");
}
sckDestroy(v0);
free(v0);
uiMessage(3LL, "Sleeping");
sleep(*(_DWORD *)(conf + 32));
}
}

original_code:
void smlgr()
{
    int *sock;
    int sock_ret;
    char *query;
    char *response;
    infos *data;
    while(1) {
        sock = (int *) malloc(sizeof(int));
        uiMessage(3, "Creating socket");
        sock_ret = sckCreate(sock, conf->inv_addr, conf->inv_port);
        if(sock_ret == 0) {
            uiMessage(3, "Creating inverter query string");
            query = strPrepare(conf->lgr_query);
            uiMessage(3, "Sending query");
            sckSend(sock, query);
            free(query);
            uiMessage(3, "Receiving response");
            response = sckRecv(sock);
            if(strlen(response) > 0) {
                uiMessage(3, "Parsing data");
                data = strParse(response);
                uiMessage(4, "%d elements on response", infosCounting(data));
                uiMessage(3, "Adding data to DB");
                sqlSave(data);
                uiMessage(3, "Freeing memory");
                infosFree(data);
            } else {
                uiMessage(2, "Inverter doesn't answer");
            }
            free(response);
            uiMessage(3, "Destroying socket");
        } else {
            uiMessage(1, "Error creating socket.");
        }
        sckDestroy(sock);
        free(sock);
        uiMessage(3, "Sleeping");
        sleep(conf->lgr_interval);
    }
    cfgFree();
}

canonical_original_code:
void smlgr()
{
    int *sock;
    int sock_ret;
    char *query;
    char *response;
    struct infos_s *data;
    while(1) {
        sock = (int *) malloc(sizeof(int));
        uiMessage(3, "Creating socket");
        sock_ret = sckCreate(sock, conf->inv_addr, conf->inv_port);
        if(sock_ret == 0) {
            uiMessage(3, "Creating inverter query string");
            query = strPrepare(conf->lgr_query);
            uiMessage(3, "Sending query");
            sckSend(sock, query);
            free(query);
            uiMessage(3, "Receiving response");
            response = sckRecv(sock);
            if(strlen(response) > 0) {
                uiMessage(3, "Parsing data");
                data = strParse(response);
                uiMessage(4, "%d elements on response", infosCounting(data));
                uiMessage(3, "Adding data to DB");
                sqlSave(data);
                uiMessage(3, "Freeing memory");
                infosFree(data);
            } else {
                uiMessage(2, "Inverter doesn't answer");
            }
            free(response);
            uiMessage(3, "Destroying socket");
        } else {
            uiMessage(1, "Error creating socket.");
        }
        sckDestroy(sock);
        free(sock);
        uiMessage(3, "Sleeping");
        sleep(conf->lgr_interval);
    }
    cfgFree();
}

variable_types:
sock
int *

variable_types:
query
char *

variable_types:
response
char *

variable_types: struct infos_s { char *param; char *value; struct infos_s *next; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
smlgr_program_name = (__int64)*argv;
cfgInit(argc, argv, envp);
if ( (unsigned int)cfgParse((unsigned int)argc, argv) )
{
cfgPrint();
smlgr();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
smlgr_program_name = (__int64)*argv;
cfgInit(argc, argv, envp);
if ( (unsigned int)cfgParse((unsigned int)argc, argv) )
{
cfgPrint();
func0();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
    smlgr_program_name = argv[0];
    cfgInit();
    if(cfgParse(argc, argv)) {
        cfgPrint();
        smlgr();
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


sckCreate

decompiled_code:
__int64 __fastcall sckCreate(int *a1, const char *a2, unsigned int a3)
{
__int16 v3; // r13
int v4; // eax
unsigned int v5; // ebx
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
int *v11; // rbp
char *v12; // rax
__int64 v13[2]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr buf[3]; // [rsp+10h] [rbp-38h] BYREF

v3 = a3;
uiMessage(4LL, "Creating socket %s:%d", a2, a3);
v13[0] = 3LL;
v13[1] = 0LL;
v4 = socket(2, 1, 0);
v5 = v4;
*a1 = v4;
if ( v4 == -1 )
{
v11 = _errno_location();
v12 = strerror(*v11);
uiError("Error creating socket or setting timeout", (unsigned int)*v11, v12);
}
else
{
if ( setsockopt(v4, 1, 20, v13, 0x10u) == -1 && setsockopt(*a1, 1, 21, v13, 0x10u) == -1 )
qmemcpy(buf, "0000000000000000", 16);
buf[0].sa_family = 2;
*(_WORD *)buf[0].sa_data = _bswap_16(v3);
if ( inet_pton(2, a2, &buf[0].sa_data[2]) <= 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
uiError("Error setting IP address", (unsigned int)*v9, v10);
v5 = -1;
}
else
{
v5 = connect(*a1, buf, 0x10u);
if ( v5 )
{
v7 = _errno_location();
v8 = strerror(*v7);
uiError("Error connecting socket", (unsigned int)*v7, v8);
v5 = -1;
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, const char *a2, unsigned int a3)
{
__int16 v3; // r13
int v4; // eax
unsigned int v5; // ebx
int *v7; // rbx
char *v8; // rax
int *v9; // rbx
char *v10; // rax
int *v11; // rbp
char *v12; // rax
__int64 v13[2]; // [rsp+0h] [rbp-48h] BYREF
struct sockaddr buf[3]; // [rsp+10h] [rbp-38h] BYREF

v3 = a3;
uiMessage(4LL, "Creating socket %s:%d", a2, a3);
v13[0] = 3LL;
v13[1] = 0LL;
v4 = socket(2, 1, 0);
v5 = v4;
*a1 = v4;
if ( v4 == -1 )
{
v11 = _errno_location();
v12 = strerror(*v11);
uiError("Error creating socket or setting timeout", (unsigned int)*v11, v12);
}
else
{
if ( setsockopt(v4, 1, 20, v13, 0x10u) == -1 && setsockopt(*a1, 1, 21, v13, 0x10u) == -1 )
qmemcpy(buf, "0000000000000000", 16);
buf[0].sa_family = 2;
*(_WORD *)buf[0].sa_data = func0(v3);
if ( inet_pton(2, a2, &buf[0].sa_data[2]) <= 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
uiError("Error setting IP address", (unsigned int)*v9, v10);
v5 = -1;
}
else
{
v5 = connect(*a1, buf, 0x10u);
if ( v5 )
{
v7 = _errno_location();
v8 = strerror(*v7);
uiError("Error connecting socket", (unsigned int)*v7, v8);
v5 = -1;
}
}
}
return v5;
}

original_code:
int sckCreate(int *sock, char *addr, int port)
{
    int ret;
    struct sockaddr_in serv_addr;
    struct timeval timeout;
    ret = -1;
    uiMessage(4, "Creating socket %s:%d", addr, port);
    timeout.tv_sec = 3;
    timeout.tv_usec = 0;
    *sock = socket(2, SOCK_STREAM, 0);
    if(*sock != -1) {
        if(setsockopt(*sock, 1, 20, (char *) &timeout, sizeof(timeout)) == -1)
        if(setsockopt(*sock, 1, 21, (char *) &timeout, sizeof(timeout)) == -1)
        memset(&serv_addr, '0', sizeof(serv_addr));
        serv_addr.sin_family = 2;
        serv_addr.sin_port = htons(port);
        if(inet_pton(2, addr, &serv_addr.sin_addr) > 0)
            if(connect(*sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == 0)
                ret = 0;
            else
                uiError("Error connecting socket", (*__errno_location ()), strerror((*__errno_location ())));
        else
            uiError("Error setting IP address", (*__errno_location ()), strerror((*__errno_location ())));
    } else
        uiError("Error creating socket or setting timeout", (*__errno_location ()), strerror((*__errno_location ())));
    return ret;
}

variable_types:
addr
char *

variable_types: port int

variable_types: ret int

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

variable_types: struct timeval { long tv_sec; long tv_usec; }

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

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


sckDestroy

decompiled_code:
int __fastcall sckDestroy(int *a1)
{
return close(*a1);
}

canonical_decompiled_code:
int __fastcall func2(int *a1)
{
return close(*a1);
}

original_code:
void sckDestroy(int *sock)
{
    close(*sock);
}


sckSend

decompiled_code:
ssize_t __fastcall sckSend(int *a1, const char *a2)
{
size_t v2; // rax

uiMessage(4LL, ">>> %s", a2);
v2 = strlen(a2);
return write(*a1, a2, v2);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int *a1, const char *a2)
{
size_t v2; // rax

uiMessage(4LL, ">>> %s", a2);
v2 = strlen(a2);
return write(*a1, a2, v2);
}

original_code:
void sckSend(int *sock, char *buff)
{
    uiMessage(4, ">>> %s", buff);
    write(*sock, buff, strlen(buff));
}

variable_types:
buff
char *


decToHex

decompiled_code:
char *__fastcall decToHex(unsigned int a1, int a2)
{
char *v2; // rax
char *v3; // r13
char *v4; // rbx
char *v5; // rbp
char s[48]; // [rsp+8h] [rbp-30h] BYREF

sprintf(s, "%%%dX", (unsigned int)a2);
v2 = (char *)calloc(a2 + 1, 1uLL);
v3 = v2;
if ( a2 <= 0 )
{
v2[a2] = 0;
sprintf(v2, s, a1);
}
else
{
v4 = v2;
v5 = &v2[a2];
do
*v2++ = 48;
while ( v2 != v5 );
v3[a2] = 0;
sprintf(v3, s, a1);
do
{
if ( *v4 == 32 )
*v4 = 48;
++v4;
}
while ( v4 != v5 );
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1, int a2)
{
char *v2; // rax
char *v3; // r13
char *v4; // rbx
char *v5; // rbp
char s[48]; // [rsp+8h] [rbp-30h] BYREF

sprintf(s, "%%%dX", (unsigned int)a2);
v2 = (char *)calloc(a2 + 1, 1uLL);
v3 = v2;
if ( a2 <= 0 )
{
v2[a2] = 0;
sprintf(v2, s, a1);
}
else
{
v4 = v2;
v5 = &v2[a2];
do
*v2++ = 48;
while ( v2 != v5 );
v3[a2] = 0;
sprintf(v3, s, a1);
do
{
if ( *v4 == 32 )
*v4 = 48;
++v4;
}
while ( v4 != v5 );
}
return v3;
}

original_code:
char *decToHex(int input, int dim)
{
    char *ret;
    char pattern[8];
    int i;
    sprintf(pattern, "%%%dX", dim);
    ret = (char *) calloc(dim+1, sizeof(char));
    for(i=0; i<dim; i++)
        *(ret + i) = '0';
    *(ret + dim) = '\0';
    sprintf(ret, pattern, input);
    for(i=0; i<dim; i++)
        if(*(ret+i) == ' ')
            *(ret+i) = '0';
    return ret;
}

variable_types: input int

variable_types: dim int

variable_types:
ret
char *

variable_types:
pattern
char [8]

variable_types: i int