repo: Distrotech/selinux

decompiled_code:
_QWORD *queue_create()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
result[1] = 0LL;
*result = 0LL;
}
return result;
}

original_code:
queue_t queue_create(void)
{
 queue_t q;
 q = (queue_t) malloc(sizeof(struct queue_info));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = q->tail = ((void *)0);
 return q;
}

canonical_original_code:
struct queue_info *queue_create()
{
 struct queue_info *q;
 q = (struct queue_info *) malloc(sizeof(struct queue_info));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = q->tail = ((void *)0);
 return q;
}

variable_types: struct queue_info { struct queue_node { void *element; struct queue_node *next; } *head; struct queue_node *tail; } *

user_defined_types: struct queue_info { struct queue_node *head; struct queue_node *tail; }


decompiled_code:
__int64 __fastcall queue_insert(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1 == 0LL;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
{
a1[1] = v2;
*a1 = v2;
result = 0LL;
}
else
{
*(_QWORD *)(a1[1] + 8LL) = v2;
a1[1] = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1 == 0LL;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
{
a1[1] = v2;
*a1 = v2;
result = 0LL;
}
else
{
*(_QWORD *)(a1[1] + 8LL) = v2;
a1[1] = v2;
result = 0LL;
}
return result;
}

original_code:
int queue_insert(queue_t q, queue_element_t e)
{
 queue_node_ptr_t newnode;
 if (!q)
  return -1;
 newnode = (queue_node_ptr_t) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  q->tail->next = newnode;
  q->tail = newnode;
 }
 return 0;
}

canonical_original_code:
int queue_insert(struct queue_info *q, void *e)
{
 struct queue_node *newnode;
 if (!q)
  return -1;
 newnode = (struct queue_node *) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  q->tail->next = newnode;
  q->tail = newnode;
 }
 return 0;
}

variable_types:
e
void *

variable_types: struct queue_node { void *element; struct queue_node *next; } *

return_type: int


decompiled_code:
__int64 __fastcall queue_push(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
{
v2[1] = v3;
*a1 = (__int64)v2;
result = 0LL;
}
else
{
a1[1] = (__int64)v2;
*a1 = (__int64)v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *a1;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
{
v2[1] = v3;
*a1 = (__int64)v2;
result = 0LL;
}
else
{
a1[1] = (__int64)v2;
*a1 = (__int64)v2;
result = 0LL;
}
return result;
}

original_code:
int queue_push(queue_t q, queue_element_t e)
{
 queue_node_ptr_t newnode;
 if (!q)
  return -1;
 newnode = (queue_node_ptr_t) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  newnode->next = q->head;
  q->head = newnode;
 }
 return 0;
}

canonical_original_code:
int queue_push(struct queue_info *q, void *e)
{
 struct queue_node *newnode;
 if (!q)
  return -1;
 newnode = (struct queue_node *) malloc(sizeof(struct queue_node));
 if (newnode == ((void *)0))
  return -1;
 newnode->element = e;
 newnode->next = ((void *)0);
 if (q->head == ((void *)0)) {
  q->head = q->tail = newnode;
 } else {
  newnode->next = q->head;
  q->head = newnode;
 }
 return 0;
}

user_defined_types: struct queue_node { void *element; struct queue_node *next; }


original_code:
queue_element_t queue_remove(queue_t q)
{
 queue_node_ptr_t node;
 queue_element_t e;
 if (!q)
  return ((void *)0);
 if (q->head == ((void *)0))
  return ((void *)0);
 node = q->head;
 q->head = q->head->next;
 if (q->head == ((void *)0))
  q->tail = ((void *)0);
 e = node->element;
 free(node);
 return e;
}

canonical_original_code:
void *queue_remove(struct queue_info *q)
{
 struct queue_node *node;
 void *e;
 if (!q)
  return ((void *)0);
 if (q->head == ((void *)0))
  return ((void *)0);
 node = q->head;
 q->head = q->head->next;
 if (q->head == ((void *)0))
  q->tail = ((void *)0);
 e = node->element;
 free(node);
 return e;
}

return_type: void *


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

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
while ( v2 );
}
free(ptr);
}
}

original_code:
void queue_destroy(queue_t q)
{
 queue_node_ptr_t p, temp;
 if (!q)
  return;
 p = q->head;
 while (p != ((void *)0)) {
  temp = p;
  p = p->next;
  free(temp);
 }
 free(q);
}

canonical_original_code:
void queue_destroy(struct queue_info *q)
{
 struct queue_node *p; struct queue_node *temp;
 if (!q)
  return;
 p = q->head;
 while (p != ((void *)0)) {
  temp = p;
  p = p->next;
  free(temp);
 }
 free(q);
}

return_type: void


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

if ( !a1 )
return 0LL;
v4 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
result = a2(*v4, a3);
if ( (_DWORD)result )
break;
v4 = (_QWORD *)v4[1];
if ( !v4 )
return 0LL;
}
return result;
}

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

if ( !a1 )
return 0LL;
v4 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
result = a2(*v4, a3);
if ( (_DWORD)result )
break;
v4 = (_QWORD *)v4[1];
if ( !v4 )
return 0LL;
}
return result;
}

original_code:
int queue_map(queue_t q, int (*f) (queue_element_t, void *), void *vp)
{
 queue_node_ptr_t p;
 int ret;
 if (!q)
  return 0;
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret)
   return ret;
  p = p->next;
 }
 return 0;
}

canonical_original_code:
int queue_map(struct queue_info *q, int (*f)(void *, void *), void *vp)
{
 struct queue_node *p;
 int ret;
 if (!q)
  return 0;
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret)
   return ret;
  p = p->next;
 }
 return 0;
}

variable_types:
f
int (*)(void *, void *)

variable_types:
vp
void *

variable_types: ret int


original_code:
void queue_map_remove_on_error(queue_t q,
          int (*f) (queue_element_t, void *),
          void (*g) (queue_element_t, void *), void *vp)
{
 queue_node_ptr_t p, last, temp;
 int ret;
 if (!q)
  return;
 last = ((void *)0);
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret) {
   if (last) {
    last->next = p->next;
    if (last->next == ((void *)0))
     q->tail = last;
   } else {
    q->head = p->next;
    if (q->head == ((void *)0))
     q->tail = ((void *)0);
   }
   temp = p;
   p = p->next;
   g(temp->element, vp);
   free(temp);
  } else {
   last = p;
   p = p->next;
  }
 }
 return;
}

canonical_original_code:
void queue_map_remove_on_error(struct queue_info *q, int (*f)(void *, void *), void (*g)(void *, void *), void *vp)
{
 struct queue_node *p; struct queue_node *last; struct queue_node *temp;
 int ret;
 if (!q)
  return;
 last = ((void *)0);
 p = q->head;
 while (p != ((void *)0)) {
  ret = f(p->element, vp);
  if (ret) {
   if (last) {
    last->next = p->next;
    if (last->next == ((void *)0))
     q->tail = last;
   } else {
    q->head = p->next;
    if (q->head == ((void *)0))
     q->tail = ((void *)0);
   }
   temp = p;
   p = p->next;
   g(temp->element, vp);
   free(temp);
  } else {
   last = p;
   p = p->next;
  }
 }
 return;
}

variable_types:
g
void (*)(void *, void *)


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
char *v4; // r12
int v5; // er15
char *v6; // r15
__int64 v7; // rax
__int64 v9; // rax
const char *v10; // rdx
int v11; // [rsp+8h] [rbp-620h]
int v12; // [rsp+Ch] [rbp-61Ch]
struct option longopts; // [rsp+10h] [rbp-618h] BYREF
const char *v14; // [rsp+30h] [rbp-5F8h]
int v15; // [rsp+38h] [rbp-5F0h]
__int64 v16; // [rsp+40h] [rbp-5E8h]
int v17; // [rsp+48h] [rbp-5E0h]
const char *v18; // [rsp+50h] [rbp-5D8h]
int v19; // [rsp+58h] [rbp-5D0h]
__int64 v20; // [rsp+60h] [rbp-5C8h]
int v21; // [rsp+68h] [rbp-5C0h]
const char *v22; // [rsp+70h] [rbp-5B8h]
int v23; // [rsp+78h] [rbp-5B0h]
__int64 v24; // [rsp+80h] [rbp-5A8h]
int v25; // [rsp+88h] [rbp-5A0h]
const char *v26; // [rsp+90h] [rbp-598h]
int v27; // [rsp+98h] [rbp-590h]
__int64 v28; // [rsp+A0h] [rbp-588h]
int v29; // [rsp+A8h] [rbp-580h]
const char *v30; // [rsp+B0h] [rbp-578h]
int v31; // [rsp+B8h] [rbp-570h]
__int64 v32; // [rsp+C0h] [rbp-568h]
int v33; // [rsp+C8h] [rbp-560h]
__int64 v34; // [rsp+D0h] [rbp-558h]
int v35; // [rsp+D8h] [rbp-550h]
__int64 v36; // [rsp+E0h] [rbp-548h]
int v37; // [rsp+E8h] [rbp-540h]
int v38[160]; // [rsp+F0h] [rbp-538h] BYREF
char v39[696]; // [rsp+370h] [rbp-2B8h] BYREF

v3 = "policy.conf";
v4 = 0LL;
longopts.name = "help";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 104;
v14 = "output";
v15 = 1;
v16 = 0LL;
v17 = 111;
v18 = "binary";
v19 = 0;
v20 = 0LL;
v21 = 98;
v22 = "version";
v23 = 0;
v24 = 0LL;
v25 = 86;
v26 = "handle-unknown";
v27 = 1;
v28 = 0LL;
v29 = 85;
v30 = "mls";
v31 = 0;
v32 = 0LL;
v33 = 77;
v34 = 0LL;
v35 = 0;
v36 = 0LL;
v37 = 0;
v11 = 0;
v12 = 0;
while ( 1 )
{
v5 = getopt_long(argc, (char *const *)argv, "ho:bVU:mM", &longopts, 0LL);
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'M':
mlspol = 1;
continue;
case 'U':
v6 = optarg;
if ( !strcasecmp(optarg, "deny") )
{
handle_unknown = 0;
}
else if ( !strcasecmp(v6, "reject") )
{
handle_unknown = 2;
}
else
{
if ( strcasecmp(v6, "allow") )
goto LABEL_42;
handle_unknown = 4;
}
break;
case 'V':
v11 = 1;
continue;
case 'b':
v12 = 1;
v3 = "policy";
continue;
case 'm':
policy_type = 2;
policyvers = 19;
continue;
case 'o':
v4 = optarg;
continue;
default:
goto LABEL_42;
}
}
if ( v11 )
{
printf("Module versions %d-%d\n", 4LL, 19LL);
exit(0);
}
if ( handle_unknown )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: Handling of unknown classes and permissions is only valid in the base module.\n", *argv);
goto LABEL_45;
}
if ( v12 )
{
LABEL_19:
v7 = optind;
if ( argc == optind || (++optind, v3 = argv[v7], argc == optind) )
{
printf("%s: loading policy configuration from %s\n", *argv, v3);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
if ( (unsigned int)read_binary_policy((__int64)v38, v3, *argv) == -1 )
goto LABEL_45;
goto LABEL_22;
}
LABEL_42:
usage(*argv);
}
}
else if ( v12 )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: -b and -m are incompatible with each other.\n", *argv);
goto LABEL_45;
}
goto LABEL_19;
}
v9 = optind;
if ( argc != optind )
{
++optind;
v3 = argv[v9];
if ( argc != optind )
goto LABEL_42;
}
printf("%s: loading policy configuration from %s\n", *argv, v3);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
if ( (unsigned int)policydb_init(v38) )
{
fprintf(stderr, "%s: out of memory!\n", *argv);
return v5;
}
v10 = *argv;
v38[0] = policy_type;
v38[8] = mlspol;
v38[159] = handle_unknown;
if ( (unsigned int)read_source_policy(v38, v3, v10) == -1 )
goto LABEL_45;
if ( (unsigned int)hierarchy_check_constraints(0LL, v38) )
return v5;
LABEL_22:
if ( v38[0] == 1 )
{
if ( (unsigned int)policydb_init(v39) )
{
fprintf(stderr, "%s: policydb_init failed\n", *argv);
goto LABEL_45;
}
if ( (unsigned int)link_modules(0LL, v38, 0LL, 0LL, 0LL) )
{
fprintf(stderr, "%s: link modules failed\n", *argv);
goto LABEL_45;
}
if ( (unsigned int)expand_module(0LL, v38, v39, 0LL, 1LL) )
{
fprintf(stderr, "%s: expand module failed\n", *argv);
goto LABEL_45;
}
policydb_destroy(v39);
}
v5 = policydb_load_isids(v38, &sidtab);
if ( v5
|| (sepol_sidtab_destroy(&sidtab), printf("%s: policy configuration loaded\n", *argv), v4)
&& (unsigned int)write_binary_policy(v38, v4, *argv) == -1 )
{
LABEL_45:
exit(1);
}
policydb_destroy(v38);
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
char *v4; // r12
int v5; // er15
char *v6; // r15
__int64 v7; // rax
__int64 v9; // rax
const char *v10; // rdx
int v11; // [rsp+8h] [rbp-620h]
int v12; // [rsp+Ch] [rbp-61Ch]
struct option longopts; // [rsp+10h] [rbp-618h] BYREF
const char *v14; // [rsp+30h] [rbp-5F8h]
int v15; // [rsp+38h] [rbp-5F0h]
__int64 v16; // [rsp+40h] [rbp-5E8h]
int v17; // [rsp+48h] [rbp-5E0h]
const char *v18; // [rsp+50h] [rbp-5D8h]
int v19; // [rsp+58h] [rbp-5D0h]
__int64 v20; // [rsp+60h] [rbp-5C8h]
int v21; // [rsp+68h] [rbp-5C0h]
const char *v22; // [rsp+70h] [rbp-5B8h]
int v23; // [rsp+78h] [rbp-5B0h]
__int64 v24; // [rsp+80h] [rbp-5A8h]
int v25; // [rsp+88h] [rbp-5A0h]
const char *v26; // [rsp+90h] [rbp-598h]
int v27; // [rsp+98h] [rbp-590h]
__int64 v28; // [rsp+A0h] [rbp-588h]
int v29; // [rsp+A8h] [rbp-580h]
const char *v30; // [rsp+B0h] [rbp-578h]
int v31; // [rsp+B8h] [rbp-570h]
__int64 v32; // [rsp+C0h] [rbp-568h]
int v33; // [rsp+C8h] [rbp-560h]
__int64 v34; // [rsp+D0h] [rbp-558h]
int v35; // [rsp+D8h] [rbp-550h]
__int64 v36; // [rsp+E0h] [rbp-548h]
int v37; // [rsp+E8h] [rbp-540h]
int v38[160]; // [rsp+F0h] [rbp-538h] BYREF
char v39[696]; // [rsp+370h] [rbp-2B8h] BYREF

v3 = "policy.conf";
v4 = 0LL;
longopts.name = "help";
longopts.has_arg = 0;
longopts.flag = 0LL;
longopts.val = 104;
v14 = "output";
v15 = 1;
v16 = 0LL;
v17 = 111;
v18 = "binary";
v19 = 0;
v20 = 0LL;
v21 = 98;
v22 = "version";
v23 = 0;
v24 = 0LL;
v25 = 86;
v26 = "handle-unknown";
v27 = 1;
v28 = 0LL;
v29 = 85;
v30 = "mls";
v31 = 0;
v32 = 0LL;
v33 = 77;
v34 = 0LL;
v35 = 0;
v36 = 0LL;
v37 = 0;
v11 = 0;
v12 = 0;
while ( 1 )
{
v5 = getopt_long(argc, (char *const *)argv, "ho:bVU:mM", &longopts, 0LL);
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'M':
mlspol = 1;
continue;
case 'U':
v6 = optarg;
if ( !strcasecmp(optarg, "deny") )
{
handle_unknown = 0;
}
else if ( !strcasecmp(v6, "reject") )
{
handle_unknown = 2;
}
else
{
if ( strcasecmp(v6, "allow") )
goto LABEL_42;
handle_unknown = 4;
}
break;
case 'V':
v11 = 1;
continue;
case 'b':
v12 = 1;
v3 = "policy";
continue;
case 'm':
policy_type = 2;
policyvers = 19;
continue;
case 'o':
v4 = optarg;
continue;
default:
goto LABEL_42;
}
}
if ( v11 )
{
printf("Module versions %d-%d\n", 4LL, 19LL);
exit(0);
}
if ( handle_unknown )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: Handling of unknown classes and permissions is only valid in the base module.\n", *argv);
goto LABEL_45;
}
if ( v12 )
{
LABEL_19:
v7 = optind;
if ( argc == optind || (++optind, v3 = argv[v7], argc == optind) )
{
printf("%s: loading policy configuration from %s\n", *argv, v3);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
if ( (unsigned int)func1((__int64)v38, v3, *argv) == -1 )
goto LABEL_45;
goto LABEL_22;
}
LABEL_42:
func0(*argv);
}
}
else if ( v12 )
{
if ( policy_type != 1 )
{
fprintf(stderr, "%s: -b and -m are incompatible with each other.\n", *argv);
goto LABEL_45;
}
goto LABEL_19;
}
v9 = optind;
if ( argc != optind )
{
++optind;
v3 = argv[v9];
if ( argc != optind )
goto LABEL_42;
}
printf("%s: loading policy configuration from %s\n", *argv, v3);
sepol_set_policydb(v38);
sepol_set_sidtab(&sidtab);
if ( (unsigned int)policydb_init(v38) )
{
fprintf(stderr, "%s: out of memory!\n", *argv);
return v5;
}
v10 = *argv;
v38[0] = policy_type;
v38[8] = mlspol;
v38[159] = handle_unknown;
if ( (unsigned int)read_source_policy(v38, v3, v10) == -1 )
goto LABEL_45;
if ( (unsigned int)hierarchy_check_constraints(0LL, v38) )
return v5;
LABEL_22:
if ( v38[0] == 1 )
{
if ( (unsigned int)policydb_init(v39) )
{
fprintf(stderr, "%s: policydb_init failed\n", *argv);
goto LABEL_45;
}
if ( (unsigned int)link_modules(0LL, v38, 0LL, 0LL, 0LL) )
{
fprintf(stderr, "%s: link modules failed\n", *argv);
goto LABEL_45;
}
if ( (unsigned int)expand_module(0LL, v38, v39, 0LL, 1LL) )
{
fprintf(stderr, "%s: expand module failed\n", *argv);
goto LABEL_45;
}
policydb_destroy(v39);
}
v5 = policydb_load_isids(v38, &sidtab);
if ( v5
|| (sepol_sidtab_destroy(&sidtab), printf("%s: policy configuration loaded\n", *argv), v4)
&& (unsigned int)func2(v38, v4, *argv) == -1 )
{
LABEL_45:
exit(1);
}
policydb_destroy(v38);
return v5;
}

original_code:
int main(int argc, char **argv)
{
 char *file = txtfile, *outfile = ((void *)0);
 unsigned int binary = 0;
 int ch;
 int show_version = 0;
 policydb_t modpolicydb;
 struct option long_options[] = {
  {"help", 0, ((void *)0), 'h'},
  {"output", 1, ((void *)0), 'o'},
  {"binary", 0, ((void *)0), 'b'},
  {"version", 0, ((void *)0), 'V'},
  {"handle-unknown", 1, ((void *)0), 'U'},
  {"mls", 0, ((void *)0), 'M'},
  {((void *)0), 0, ((void *)0), 0}
 };
 while ((ch = getopt_long(argc, argv, "ho:bVU:mM", long_options, ((void *)0))) != -1) {
  switch (ch) {
  case 'h':
   usage(argv[0]);
   break;
  case 'o':
   outfile = optarg;
   break;
  case 'b':
   binary = 1;
   file = binfile;
   break;
  case 'V':
   show_version = 1;
   break;
  case 'U':
   if (!strcasecmp(optarg, "deny")) {
    handle_unknown = 0;
    break;
   }
   if (!strcasecmp(optarg, "reject")) {
    handle_unknown = 2;
    break;
   }
   if (!strcasecmp(optarg, "allow")) {
    handle_unknown = 4;
    break;
   }
   usage(argv[0]);
  case 'm':
   policy_type = 2;
   policyvers = 19;
   break;
  case 'M':
   mlspol = 1;
   break;
  default:
   usage(argv[0]);
  }
 }
 if (show_version) {
  printf("Module versions %d-%d\n",
         4, 19);
  exit(0);
 }
 if (handle_unknown && (policy_type != 1)) {
  fprintf(stderr, "%s:  Handling of unknown classes and permissions is only valid in the base module.\n", argv[0]);
  exit(1);
 }
 if (binary && (policy_type != 1)) {
  fprintf(stderr, "%s:  -b and -m are incompatible with each other.\n", argv[0]);
  exit(1);
 }
 if (optind != argc) {
  file = argv[optind++];
  if (optind != argc)
   usage(argv[0]);
 }
 printf("%s:  loading policy configuration from %s\n", argv[0], file);
 sepol_set_policydb(&modpolicydb);
 sepol_set_sidtab(&sidtab);
 if (binary) {
  if (read_binary_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
 } else {
  if (policydb_init(&modpolicydb)) {
   fprintf(stderr, "%s: out of memory!\n", argv[0]);
   return -1;
  }
  modpolicydb.policy_type = policy_type;
  modpolicydb.mls = mlspol;
  modpolicydb.handle_unknown = handle_unknown;
  if (read_source_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
  if (hierarchy_check_constraints(((void *)0), &modpolicydb)) {
   return -1;
  }
 }
 if (modpolicydb.policy_type == 1) {
  policydb_t kernpolicydb;
  if (policydb_init(&kernpolicydb)) {
   fprintf(stderr, "%s:  policydb_init failed\n", argv[0]);
   exit(1);
  }
  if (link_modules(((void *)0), &modpolicydb, ((void *)0), 0, 0)) {
   fprintf(stderr, "%s:  link modules failed\n", argv[0]);
   exit(1);
  }
  if (expand_module(((void *)0), &modpolicydb, &kernpolicydb, 0, 1)) {
   fprintf(stderr, "%s:  expand module failed\n", argv[0]);
   exit(1);
  }
  policydb_destroy(&kernpolicydb);
 }
 if (policydb_load_isids(&modpolicydb, &sidtab))
  exit(1);
 sepol_sidtab_destroy(&sidtab);
 printf("%s:  policy configuration loaded\n", argv[0]);
 if (outfile &&
     write_binary_policy(&modpolicydb, outfile, argv[0]) == -1) {
  exit(1);
 }
 policydb_destroy(&modpolicydb);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *file = txtfile; char *outfile = ((void *)0);
 unsigned int binary = 0;
 int ch;
 int show_version = 0;
 struct policydb modpolicydb;
 struct option long_options[] = {
  {"help", 0, ((void *)0), 'h'},
  {"output", 1, ((void *)0), 'o'},
  {"binary", 0, ((void *)0), 'b'},
  {"version", 0, ((void *)0), 'V'},
  {"handle-unknown", 1, ((void *)0), 'U'},
  {"mls", 0, ((void *)0), 'M'},
  {((void *)0), 0, ((void *)0), 0}
 };
 while ((ch = getopt_long(argc, argv, "ho:bVU:mM", long_options, ((void *)0))) != -1) {
  switch (ch) {
  case 'h':
   usage(argv[0]);
   break;
  case 'o':
   outfile = optarg;
   break;
  case 'b':
   binary = 1;
   file = binfile;
   break;
  case 'V':
   show_version = 1;
   break;
  case 'U':
   if (!strcasecmp(optarg, "deny")) {
    handle_unknown = 0;
    break;
   }
   if (!strcasecmp(optarg, "reject")) {
    handle_unknown = 2;
    break;
   }
   if (!strcasecmp(optarg, "allow")) {
    handle_unknown = 4;
    break;
   }
   usage(argv[0]);
  case 'm':
   policy_type = 2;
   policyvers = 19;
   break;
  case 'M':
   mlspol = 1;
   break;
  default:
   usage(argv[0]);
  }
 }
 if (show_version) {
  printf("Module versions %d-%d\n",
         4, 19);
  exit(0);
 }
 if (handle_unknown && (policy_type != 1)) {
  fprintf(stderr, "%s:  Handling of unknown classes and permissions is only valid in the base module.\n", argv[0]);
  exit(1);
 }
 if (binary && (policy_type != 1)) {
  fprintf(stderr, "%s:  -b and -m are incompatible with each other.\n", argv[0]);
  exit(1);
 }
 if (optind != argc) {
  file = argv[optind++];
  if (optind != argc)
   usage(argv[0]);
 }
 printf("%s:  loading policy configuration from %s\n", argv[0], file);
 sepol_set_policydb(&modpolicydb);
 sepol_set_sidtab(&sidtab);
 if (binary) {
  if (read_binary_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
 } else {
  if (policydb_init(&modpolicydb)) {
   fprintf(stderr, "%s: out of memory!\n", argv[0]);
   return -1;
  }
  modpolicydb.policy_type = policy_type;
  modpolicydb.mls = mlspol;
  modpolicydb.handle_unknown = handle_unknown;
  if (read_source_policy(&modpolicydb, file, argv[0]) == -1) {
   exit(1);
  }
  if (hierarchy_check_constraints(((void *)0), &modpolicydb)) {
   return -1;
  }
 }
 if (modpolicydb.policy_type == 1) {
  struct policydb kernpolicydb;
  if (policydb_init(&kernpolicydb)) {
   fprintf(stderr, "%s:  policydb_init failed\n", argv[0]);
   exit(1);
  }
  if (link_modules(((void *)0), &modpolicydb, ((void *)0), 0, 0)) {
   fprintf(stderr, "%s:  link modules failed\n", argv[0]);
   exit(1);
  }
  if (expand_module(((void *)0), &modpolicydb, &kernpolicydb, 0, 1)) {
   fprintf(stderr, "%s:  expand module failed\n", argv[0]);
   exit(1);
  }
  policydb_destroy(&kernpolicydb);
 }
 if (policydb_load_isids(&modpolicydb, &sidtab))
  exit(1);
 sepol_sidtab_destroy(&sidtab);
 printf("%s:  policy configuration loaded\n", argv[0]);
 if (outfile &&
     write_binary_policy(&modpolicydb, outfile, argv[0]) == -1) {
  exit(1);
 }
 policydb_destroy(&modpolicydb);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
file
char *

variable_types:
outfile
char *

variable_types:
binary
unsigned int

variable_types: ch int

variable_types: struct policydb { unsigned int policy_type; char *name; char *version; int target_platform; int unsupported_format; int mls; struct symtab_t { struct hashtab_val { struct hashtab_node { char *key; void *datum; struct hashtab_node *next; } **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab_val *h, char *key); int (*keycmp)(struct hashtab_val *h, char *key1, char *key2); } *table; unsigned int nprim; } symtab[8]; char **sym_val_to_name[8]; struct class_datum { struct symtab_datum { unsigned int value; } s; char *comkey; struct common_datum { struct symtab_datum s; struct symtab_t permissions; } *comdatum; struct symtab_t permissions; struct constraint_node { unsigned int permissions; struct constraint_expr { unsigned int expr_type; unsigned int attr; unsigned int op; struct ebitmap { struct ebitmap_node { unsigned int startbit; unsigned long map; struct ebitmap_node *next; } *node; unsigned int highbit; } names; struct type_set { struct ebitmap types; struct ebitmap negset; unsigned int flags; } *type_names; struct constraint_expr *next; } *expr; struct constraint_node *next; } *constraints; struct constraint_node *validatetrans; char default_user; char default_role; char default_type; char default_range; } **class_val_to_struct; struct role_datum { struct symtab_datum s; struct ebitmap dominates; struct type_set types; struct ebitmap cache; unsigned int bounds; unsigned int flavor; struct ebitmap roles; } **role_val_to_struct; struct user_datum { struct symtab_datum s; struct role_set { struct ebitmap roles; unsigned int flags; } roles; struct mls_semantic_range { struct mls_semantic_level { unsigned int sens; struct mls_semantic_cat { unsigned int low; unsigned int high; struct mls_semantic_cat *next; } *cat; } level[2]; } range; struct mls_semantic_level dfltlevel; struct ebitmap cache; struct mls_range { struct mls_level { unsigned int sens; struct ebitmap cat; } level[2]; } exp_range; struct mls_level exp_dfltlevel; unsigned int bounds; } **user_val_to_struct; struct type_datum { struct symtab_datum s; unsigned int primary; unsigned int flavor; struct ebitmap types; unsigned int flags; unsigned int bounds; } **type_val_to_struct; struct symtab_t scope[8]; struct avrule_block { struct avrule_decl { unsigned int decl_id; unsigned int enabled; struct cond_node { int cur_state; struct cond_expr { unsigned int expr_type; unsigned int bool; struct cond_expr *next; } *expr; struct cond_av_list { struct avtab_node { struct avtab_key { unsigned short source_type; unsigned short target_type; unsigned short target_class; unsigned short specified; } key; struct avtab_datum { unsigned int data; struct avtab_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; } *xperms; } datum; struct avtab_node *next; void *parse_context; unsigned int merged; } *node; struct cond_av_list *next; } *true_list; struct cond_av_list *false_list; struct avrule { unsigned int specified; unsigned int flags; struct type_set stypes; struct type_set ttypes; struct class_perm_node { unsigned int tclass; unsigned int data; struct class_perm_node *next; } *perms; struct av_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; } *xperms; unsigned long line; char *source_filename; unsigned long source_line; struct avrule *next; } *avtrue_list; struct avrule *avfalse_list; unsigned int nbools; unsigned int bool_ids[5]; unsigned int expr_pre_comp; struct cond_node *next; unsigned int flags; } *cond_list; struct avrule *avrules; struct role_trans_rule { struct role_set roles; struct type_set types; struct ebitmap classes; unsigned int new_role; struct role_trans_rule *next; } *role_tr_rules; struct role_allow_rule { struct role_set roles; struct role_set new_roles; struct role_allow_rule *next; } *role_allow_rules; struct range_trans_rule { struct type_set stypes; struct type_set ttypes; struct ebitmap tclasses; struct mls_semantic_range trange; struct range_trans_rule *next; } *range_tr_rules; struct scope_index { struct ebitmap scope[8]; struct ebitmap *class_perms_map; unsigned int class_perms_len; } required; struct scope_index declared; struct filename_trans_rule { struct type_set stypes; struct type_set ttypes; unsigned int tclass; char *name; unsigned int otype; struct filename_trans_rule *next; } *filename_trans_rules; struct symtab_t symtab[8]; char *module_name; struct avrule_decl *next; } *branch_list; struct avrule_decl *enabled; unsigned int flags; struct avrule_block *next; } *global; struct avrule_decl **decl_val_to_struct; struct avtab { struct avtab_node **htable; unsigned int nel; unsigned int nslot; unsigned int mask; } te_avtab; struct cond_bool_datum { struct symtab_datum s; int state; unsigned int flags; } **bool_val_to_struct; struct avtab te_cond_avtab; struct cond_node *cond_list; struct role_trans { unsigned int role; unsigned int type; unsigned int tclass; unsigned int new_role; struct role_trans *next; } *role_tr; struct role_allow { unsigned int role; unsigned int new_role; struct role_allow *next; } *role_allow; struct ocontext { union { char *name; struct { unsigned char protocol; unsigned short low_port; unsigned short high_port; } port; struct { unsigned int addr; unsigned int mask; } node; struct { unsigned int addr[4]; unsigned int mask[4]; } node6; unsigned int device; unsigned short pirq; struct { unsigned long low_iomem; unsigned long high_iomem; } iomem; struct { unsigned int low_ioport; unsigned int high_ioport; } ioport; struct { unsigned long subnet_prefix; unsigned short low_pkey; unsigned short high_pkey; } ibpkey; struct { char *dev_name; unsigned char port; } ibendport; } u; union { unsigned int sclass; unsigned int behavior; } v; struct context_struct { unsigned int user; unsigned int role; unsigned int type; struct mls_range range; } context[2]; unsigned int sid[2]; struct ocontext *next; } *ocontexts[9]; struct genfs { char *fstype; struct ocontext *head; struct genfs *next; } *genfs; struct hashtab_val *range_tr; struct hashtab_val *filename_trans; struct ebitmap *type_attr_map; struct ebitmap *attr_type_map; struct ebitmap policycaps; struct ebitmap permissive_map; unsigned int policyvers; unsigned int handle_unknown; }

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

user_defined_types: struct policydb { unsigned int policy_type; char *name; char *version; int target_platform; int unsupported_format; int mls; struct symtab_t symtab[8]; char **sym_val_to_name[8]; struct class_datum **class_val_to_struct; struct role_datum **role_val_to_struct; struct user_datum **user_val_to_struct; struct type_datum **type_val_to_struct; struct symtab_t scope[8]; struct avrule_block *global; struct avrule_decl **decl_val_to_struct; struct avtab te_avtab; struct cond_bool_datum **bool_val_to_struct; struct avtab te_cond_avtab; struct cond_node *cond_list; struct role_trans *role_tr; struct role_allow *role_allow; struct ocontext *ocontexts[9]; struct genfs *genfs; struct hashtab_val *range_tr; struct hashtab_val *filename_trans; struct ebitmap *type_attr_map; struct ebitmap *attr_type_map; struct ebitmap policycaps; struct ebitmap permissive_map; unsigned int policyvers; unsigned int handle_unknown; }

user_defined_types: struct symtab_t { struct hashtab_val *table; unsigned int nprim; }

user_defined_types: struct avrule_block { struct avrule_decl *branch_list; struct avrule_decl *enabled; unsigned int flags; struct avrule_block *next; }

user_defined_types: struct class_datum { struct symtab_datum s; char *comkey; struct common_datum *comdatum; struct symtab_t permissions; struct constraint_node *constraints; struct constraint_node *validatetrans; char default_user; char default_role; char default_type; char default_range; }

user_defined_types: struct user_datum { struct symtab_datum s; struct role_set roles; struct mls_semantic_range range; struct mls_semantic_level dfltlevel; struct ebitmap cache; struct mls_range exp_range; struct mls_level exp_dfltlevel; unsigned int bounds; }

user_defined_types: struct ocontext { union { char *name; struct { unsigned char protocol; unsigned short low_port; unsigned short high_port; } port; struct { unsigned int addr; unsigned int mask; } node; struct { unsigned int addr[4]; unsigned int mask[4]; } node6; unsigned int device; unsigned short pirq; struct { unsigned long low_iomem; unsigned long high_iomem; } iomem; struct { unsigned int low_ioport; unsigned int high_ioport; } ioport; struct { unsigned long subnet_prefix; unsigned short low_pkey; unsigned short high_pkey; } ibpkey; struct { char *dev_name; unsigned char port; } ibendport; } u; union { unsigned int sclass; unsigned int behavior; } v; struct context_struct context[2]; unsigned int sid[2]; struct ocontext *next; }

user_defined_types: struct hashtab_val { struct hashtab_node **htable; unsigned int size; unsigned int nel; unsigned int (*hash_value)(struct hashtab_val *h, char *key); int (*keycmp)(struct hashtab_val *h, char *key1, char *key2); }

user_defined_types: struct mls_semantic_range { struct mls_semantic_level level[2]; }

user_defined_types: struct mls_range { struct mls_level level[2]; }

user_defined_types: struct avrule_decl { unsigned int decl_id; unsigned int enabled; struct cond_node *cond_list; struct avrule *avrules; struct role_trans_rule *role_tr_rules; struct role_allow_rule *role_allow_rules; struct range_trans_rule *range_tr_rules; struct scope_index required; struct scope_index declared; struct filename_trans_rule *filename_trans_rules; struct symtab_t symtab[8]; char *module_name; struct avrule_decl *next; }

user_defined_types: struct constraint_node { unsigned int permissions; struct constraint_expr *expr; struct constraint_node *next; }

user_defined_types: struct mls_semantic_level { unsigned int sens; struct mls_semantic_cat *cat; }

user_defined_types: struct cond_node { int cur_state; struct cond_expr *expr; struct cond_av_list *true_list; struct cond_av_list *false_list; struct avrule *avtrue_list; struct avrule *avfalse_list; unsigned int nbools; unsigned int bool_ids[5]; unsigned int expr_pre_comp; struct cond_node *next; unsigned int flags; }

user_defined_types: struct constraint_expr { unsigned int expr_type; unsigned int attr; unsigned int op; struct ebitmap names; struct type_set *type_names; struct constraint_expr *next; }

user_defined_types: struct ebitmap { struct ebitmap_node *node; unsigned int highbit; }

user_defined_types: struct cond_av_list { struct avtab_node *node; struct cond_av_list *next; }

user_defined_types: struct avrule { unsigned int specified; unsigned int flags; struct type_set stypes; struct type_set ttypes; struct class_perm_node *perms; struct av_extended_perms *xperms; unsigned long line; char *source_filename; unsigned long source_line; struct avrule *next; }

user_defined_types: struct avtab_node { struct avtab_key key; struct avtab_datum datum; struct avtab_node *next; void *parse_context; unsigned int merged; }

user_defined_types: struct avtab_datum { unsigned int data; struct avtab_extended_perms *xperms; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("usage: %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", a1);
puts("Build base and policy modules.");
puts("Options:");
printf(" INPUT build module from INPUT (else read from \"%s\")\n", "policy.conf");
puts(" -V show policy versions created by this program");
puts(" -b treat input as a binary policy file");
puts(" -h print usage");
puts(" -U OPTION How to handle unknown classes and permissions");
puts(" deny: Deny unknown kernel checks");
puts(" reject: Reject loading of policy with unknowns");
puts(" allow: Allow unknown kernel checks");
puts(" -m build a policy module instead of a base module");
puts(" -M enable MLS policy");
puts(" -o FILE write module to FILE (else just check syntax)");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("usage: %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", a1);
puts("Build base and policy modules.");
puts("Options:");
printf(" INPUT build module from INPUT (else read from \"%s\")\n", "policy.conf");
puts(" -V show policy versions created by this program");
puts(" -b treat input as a binary policy file");
puts(" -h print usage");
puts(" -U OPTION How to handle unknown classes and permissions");
puts(" deny: Deny unknown kernel checks");
puts(" reject: Reject loading of policy with unknowns");
puts(" allow: Allow unknown kernel checks");
puts(" -m build a policy module instead of a base module");
puts(" -M enable MLS policy");
puts(" -o FILE write module to FILE (else just check syntax)");
exit(1);
}

original_code:
static void usage(char *progname)
{
 printf("usage:  %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", progname);
 printf("Build base and policy modules.\n");
 printf("Options:\n");
 printf("  INPUT      build module from INPUT (else read from \"%s\")\n",
        txtfile);
 printf("  -V         show policy versions created by this program\n");
 printf("  -b         treat input as a binary policy file\n");
 printf("  -h         print usage\n");
 printf("  -U OPTION  How to handle unknown classes and permissions\n");
 printf("               deny: Deny unknown kernel checks\n");
 printf("               reject: Reject loading of policy with unknowns\n");
 printf("               allow: Allow unknown kernel checks\n");
 printf("  -m         build a policy module instead of a base module\n");
 printf("  -M         enable MLS policy\n");
 printf("  -o FILE    write module to FILE (else just check syntax)\n");
 exit(1);
}

variable_types:
progname
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

if ( argc != 3 )
usage(*argv);
v3 = fopen(argv[1], "r");
if ( v3 )
{
if ( (int)sepol_set_policydb_from_file() >= 0 )
{
fclose(v3);
if ( (int)sepol_check_context() >= 0 )
{
printf("%s is valid\n", argv[2]);
exit(0);
}
fprintf(stderr, "%s is not valid\n", argv[2]);
exit(1);
}
v4 = __errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Error while processing %s: %s\n", argv[1], v5);
}
else
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Can't open '%s': %s\n", argv[1], v7);
}
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int *v4; // rax
char *v5; // rax
int *v6; // rax
char *v7; // rax

if ( argc != 3 )
func7(*argv);
v3 = fopen(argv[1], "r");
if ( v3 )
{
if ( (int)sepol_set_policydb_from_file() >= 0 )
{
fclose(v3);
if ( (int)sepol_check_context() >= 0 )
{
printf("%s is valid\n", argv[2]);
exit(0);
}
fprintf(stderr, "%s is not valid\n", argv[2]);
exit(1);
}
v4 = __errno_location();
v5 = strerror(*v4);
fprintf(stderr, "Error while processing %s: %s\n", argv[1], v5);
}
else
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Can't open '%s': %s\n", argv[1], v7);
}
exit(1);
}

user_defined_types: struct policydb { unsigned int policy_type; char *name; char *version; int target_platform; int unsupported_format; int mls; struct symtab_t symtab[8]; char **sym_val_to_name[8]; struct class_datum **class_val_to_struct; struct role_datum **role_val_to_struct; struct user_datum **user_val_to_struct; struct type_datum **type_val_to_struct; struct symtab_t scope[8]; struct avrule_block *global; struct avrule_decl **decl_val_to_struct; struct avtab te_avtab; struct cond_bool_datum **bool_val_to_struct; struct avtab te_cond_avtab; struct cond_node *cond_list; struct role_trans *role_tr; struct role_allow *role_allow; struct ocontext *ocontexts[9]; struct genfs *genfs; struct hashtab_val *range_tr; struct hashtab_val *filename_trans; struct ebitmap *type_attr_map; struct ebitmap *attr_type_map; struct ebitmap policycaps; struct ebitmap permissive_map; unsigned int policyvers; unsigned int handle_unknown; }

user_defined_types: struct avtab { struct avtab_node **htable; unsigned int nel; unsigned int nslot; unsigned int mask; }

user_defined_types: struct option { char *name; int has_arg; int *flag; int val; }

user_defined_types: struct symtab_t { struct hashtab_val *table; unsigned int nprim; }

user_defined_types: struct avrule_block { struct avrule_decl *branch_list; struct avrule_decl *enabled; unsigned int flags; struct avrule_block *next; }

user_defined_types: struct role_trans { unsigned int role; unsigned int type; unsigned int tclass; unsigned int new_role; struct role_trans *next; }

user_defined_types: struct role_allow { unsigned int role; unsigned int new_role; struct role_allow *next; }

user_defined_types: struct genfs { char *fstype; struct ocontext *head; struct genfs *next; }

user_defined_types: struct role_datum { struct symtab_datum s; struct ebitmap dominates; struct type_set types; struct ebitmap cache; unsigned int bounds; unsigned int flavor; struct ebitmap roles; }

user_defined_types: struct type_datum { struct symtab_datum s; unsigned int primary; unsigned int flavor; struct ebitmap types; unsigned int flags; unsigned int bounds; }

user_defined_types: struct cond_bool_datum { struct symtab_datum s; int state; unsigned int flags; }

user_defined_types: struct symtab_datum { unsigned int value; }

user_defined_types: struct role_set { struct ebitmap roles; unsigned int flags; }

user_defined_types: struct common_datum { struct symtab_datum s; struct symtab_t permissions; }

user_defined_types: struct scope_index { struct ebitmap scope[8]; struct ebitmap *class_perms_map; unsigned int class_perms_len; }

user_defined_types: struct context_struct { unsigned int user; unsigned int role; unsigned int type; struct mls_range range; }

user_defined_types: struct mls_level { unsigned int sens; struct ebitmap cat; }

user_defined_types: struct role_trans_rule { struct role_set roles; struct type_set types; struct ebitmap classes; unsigned int new_role; struct role_trans_rule *next; }

user_defined_types: struct role_allow_rule { struct role_set roles; struct role_set new_roles; struct role_allow_rule *next; }

user_defined_types: struct range_trans_rule { struct type_set stypes; struct type_set ttypes; struct ebitmap tclasses; struct mls_semantic_range trange; struct range_trans_rule *next; }

user_defined_types: struct filename_trans_rule { struct type_set stypes; struct type_set ttypes; unsigned int tclass; char *name; unsigned int otype; struct filename_trans_rule *next; }

user_defined_types: struct hashtab_node { char *key; void *datum; struct hashtab_node *next; }

user_defined_types: struct mls_semantic_cat { unsigned int low; unsigned int high; struct mls_semantic_cat *next; }

user_defined_types: struct cond_expr { unsigned int expr_type; unsigned int bool; struct cond_expr *next; }

user_defined_types: struct type_set { struct ebitmap types; struct ebitmap negset; unsigned int flags; }

user_defined_types: struct ebitmap_node { unsigned int startbit; unsigned long map; struct ebitmap_node *next; }

user_defined_types: struct class_perm_node { unsigned int tclass; unsigned int data; struct class_perm_node *next; }

user_defined_types: struct av_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; }

user_defined_types: struct avtab_key { unsigned short source_type; unsigned short target_type; unsigned short target_class; unsigned short specified; }

user_defined_types: struct avtab_extended_perms { unsigned char specified; unsigned char driver; unsigned int perms[8]; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
printf("usage: %s policy context\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
printf("usage: %s policy context\n", a1);
exit(1);
}

canonical_original_code:
static void usage(char *progname)
{
 printf("usage:  %s [-h] [-V] [-b] [-U handle_unknown] [-m] [-M] [-o FILE] [INPUT]\n", progname);
 printf("Build base and policy modules.\n");
 printf("Options:\n");
 printf("  INPUT      build module from INPUT (else read from \"%s\")\n",
        txtfile);
 printf("  -V         show policy versions created by this program\n");
 printf("  -b         treat input as a binary policy file\n");
 printf("  -h         print usage\n");
 printf("  -U OPTION  How to handle unknown classes and permissions\n");
 printf("               deny: Deny unknown kernel checks\n");
 printf("               reject: Reject loading of policy with unknowns\n");
 printf("               allow: Allow unknown kernel checks\n");
 printf("  -m         build a policy module instead of a base module\n");
 printf("  -M         enable MLS policy\n");
 printf("  -o FILE    write module to FILE (else just check syntax)\n");
 exit(1);
}


repo: Distrotech/sysklogd

decompiled_code:
__int64 __fastcall check_pid(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12

v1 = read_pid(a1);
if ( !v1 )
return 0;
v2 = v1;
if ( getpid() == v1 )
return 0;
if ( !kill(v2, 0) )
return v2;
if ( *_errno_location() == 3 )
return 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // er12

v1 = func0(a1);
if ( !v1 )
return 0;
v2 = v1;
if ( getpid() == v1 )
return 0;
if ( !kill(v2, 0) )
return v2;
if ( *_errno_location() == 3 )
return 0;
return v2;
}

original_code:
int check_pid (char *pidfile)
{
  int pid = read_pid(pidfile);
  if ((!pid) || (pid == getpid ()))
    return 0;
  if (kill(pid, 0) && (*__errno_location ()) == 3)
   return(0);
  return pid;
}

canonical_original_code:
int check_pid(char *pidfile)
{
  int pid = read_pid(pidfile);
  if ((!pid) || (pid == getpid ()))
    return 0;
  if (kill(pid, 0) && (*__errno_location ()) == 3)
   return(0);
  return pid;
}

variable_types:
pidfile
char *

variable_types: pid int


decompiled_code:
// attributes: thunk
int remove_pid(const char *name)
{
return unlink(name);
}

canonical_decompiled_code:
int func3(const char *name)
{
return unlink(name);
}

original_code:
int remove_pid (char *pidfile)
{
  return unlink (pidfile);
}

canonical_original_code:
int remove_pid(char *pidfile)
{
  return unlink (pidfile);
}


copyin

decompiled_code:
__int64 __fastcall copyin(__int64 a1, int a2, __int64 a3, int a4, const char *a5)
{
__int64 i; // rbx
unsigned int v8; // er12
char v9; // bp

if ( a2 > a4 )
a2 = a4;
if ( a2 <= 0 )
return 0;
for ( i = 0LL; i != a2; v8 = ++i )
{
v8 = i;
v9 = *(_BYTE *)(a3 + i);
if ( strchr(a5, v9) )
break;
*(_BYTE *)(a1 + i) = v9;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3, int a4, const char *a5)
{
__int64 i; // rbx
unsigned int v8; // er12
char v9; // bp

if ( a2 > a4 )
a2 = a4;
if ( a2 <= 0 )
return 0;
for ( i = 0LL; i != a2; v8 = ++i )
{
v8 = i;
v9 = *(_BYTE *)(a3 + i);
if ( strchr(a5, v9) )
break;
*(_BYTE *)(a1 + i) = v9;
}
return v8;
}

original_code:
static int copyin( char *line, int space,
                   const char *ptr, int len,
                   const char *delim )
{
    auto int i;
    auto int count;
    count = len < space ? len : space;
    for(i=0; i<count && !strchr(delim, *ptr); i++ ) { *line++ = *ptr++; }
    return( i );
}

canonical_original_code:
static int copyin(char *line, int space, char *ptr, int len, char *delim)
{
    auto int i;
    auto int count;
    count = len < space ? len : space;
    for(i=0; i<count && !strchr(delim, *ptr); i++ ) { *line++ = *ptr++; }
    return( i );
}

variable_types:
line
char *

variable_types: space int

variable_types:
ptr
char *

variable_types: len int

variable_types:
delim
char *

variable_types: i int

variable_types: count int


ReloadSymbols

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

result = (unsigned int)symbol_lookup;
if ( symbol_lookup )
{
if ( reload_symbols > 1 )
InitKsyms(symfile);
result = InitMsyms();
}
change_state = 0;
reload_symbols = 0;
return result;
}

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

result = (unsigned int)symbol_lookup;
if ( symbol_lookup )
{
if ( reload_symbols > 1 )
InitKsyms(symfile);
result = InitMsyms();
}
change_state = 0;
reload_symbols = 0;
return result;
}

original_code:
static void ReloadSymbols()
{
 if (symbol_lookup) {
  if ( reload_symbols > 1 )
   InitKsyms(symfile);
  InitMsyms();
 }
 reload_symbols = change_state = 0;
 return;
}


GetKernelLogSrc

decompiled_code:
__int64 GetKernelLogSrc()
{
__int64 result; // rax
int *v1; // rbx
char *v2; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( console_log_level != -1 && klogctl(8, 0LL, console_log_level) < 0 && *_errno_location() == 22 )
Syslog(4, "Cannot set console log level - disabling console output.");
if ( use_syscall || stat("/proc/kmsg", &v3) < 0 && *_errno_location() == 2 )
{
klogctl(1, 0LL, 0);
Syslog(6, "klogd %s.%s, log source = ksyslog started.", "1.5", "0");
result = 2LL;
}
else
{
kmsg = open("/proc/kmsg", 0);
if ( kmsg < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "klogd: Cannot open proc file system, %d - %s.\n", (unsigned int)*v1, v2);
klogctl(7, 0LL, 0);
exit(1);
}
Syslog(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax
int *v1; // rbx
char *v2; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( console_log_level != -1 && klogctl(8, 0LL, console_log_level) < 0 && *_errno_location() == 22 )
func7(4, "Cannot set console log level - disabling console output.");
if ( use_syscall || stat("/proc/kmsg", &v3) < 0 && *_errno_location() == 2 )
{
klogctl(1, 0LL, 0);
func7(6, "klogd %s.%s, log source = ksyslog started.", "1.5", "0");
result = 2LL;
}
else
{
kmsg = open("/proc/kmsg", 0);
if ( kmsg < 0 )
{
v1 = _errno_location();
v2 = strerror(*v1);
fprintf(stderr, "klogd: Cannot open proc file system, %d - %s.\n", (unsigned int)*v1, v2);
klogctl(7, 0LL, 0);
exit(1);
}
func7(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
result = 1LL;
}
return result;
}

original_code:
static enum LOGSRC GetKernelLogSrc(void)
{
 auto struct stat sb;
 if ( (console_log_level != -1)
 && (klogctl(8, ((void *)0), console_log_level) < 0) && ((*__errno_location ()) == 22) )
 {
  Syslog(4, "Cannot set console log level - disabling "
         "console output.");
 }
 if ( use_syscall ||
     ((stat("/proc/kmsg", &sb) < 0) && ((*__errno_location ()) == 2)) )
 {
    klogctl(1, ((void *)0), 0);
  Syslog(6, "klogd %s.%s, log source = ksyslog "
         "started.", "1.5", "0");
  return(kernel);
 }
 if ( (kmsg = open("/proc/kmsg", 00)) < 0 )
 {
  fprintf(stderr, "klogd: Cannot open proc file system, " "%d - %s.\n", (*__errno_location ()), strerror((*__errno_location ())));
  klogctl(7, ((void *)0), 0);
  exit(1);
 }
 Syslog(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
 return(proc);
}

canonical_original_code:
static enum LOGSRC GetKernelLogSrc()
{
 auto struct stat sb;
 if ( (console_log_level != -1)
 && (klogctl(8, ((void *)0), console_log_level) < 0) && ((*__errno_location ()) == 22) )
 {
  Syslog(4, "Cannot set console log level - disabling "
         "console output.");
 }
 if ( use_syscall ||
     ((stat("/proc/kmsg", &sb) < 0) && ((*__errno_location ()) == 2)) )
 {
    klogctl(1, ((void *)0), 0);
  Syslog(6, "klogd %s.%s, log source = ksyslog "
         "started.", "1.5", "0");
  return(kernel);
 }
 if ( (kmsg = open("/proc/kmsg", 00)) < 0 )
 {
  fprintf(stderr, "klogd: Cannot open proc file system, " "%d - %s.\n", (*__errno_location ()), strerror((*__errno_location ())));
  klogctl(7, ((void *)0), 0);
  exit(1);
 }
 Syslog(6, "klogd %s.%s, log source = %s started.", "1.5", "0", "/proc/kmsg");
 return(proc);
}

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

return_type: enum LOGSRC { none=0, proc=1, kernel=2 }

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


ChangeLogging

decompiled_code:
void ChangeLogging()
{
int v0; // eax

Syslog(6, "klogd %s.%s, ---------- state change ----------\n", "1.5", "0");
if ( reload_symbols > 0 )
{
ReloadSymbols();
}
else if ( caught_TSTP == 1 )
{
CloseLogSrc();
logsrc = 0;
change_state = 0;
}
else if ( logsrc )
{
Syslog(6, "Kernel logging re-started after SIGSTOP.");
change_state = 0;
}
else
{
v0 = GetKernelLogSrc();
change_state = 0;
logsrc = v0;
}
}

canonical_decompiled_code:
void func12()
{
int v0; // eax

func7(6, "klogd %s.%s, ---------- state change ----------\n", "1.5", "0");
if ( reload_symbols > 0 )
{
func5();
}
else if ( caught_TSTP == 1 )
{
func8();
logsrc = 0;
change_state = 0;
}
else if ( logsrc )
{
func7(6, "Kernel logging re-started after SIGSTOP.");
change_state = 0;
}
else
{
v0 = func11();
change_state = 0;
logsrc = v0;
}
}

original_code:
static void ChangeLogging(void)
{
 if ( terminate == 1 )
  Terminate();
 Syslog(6, "klogd %s.%s, ---------- state change ----------\n", "1.5", "0");
 if ( reload_symbols > 0 )
 {
  ReloadSymbols();
  return;
 }
 if ( caught_TSTP == 1 )
 {
  CloseLogSrc();
  logsrc = none;
  change_state = 0;
  return;
 }
 if ( logsrc != none )
 {
  Syslog(6, "Kernel logging re-started after SIGSTOP.");
  change_state = 0;
  return;
 }
 logsrc = GetKernelLogSrc();
 change_state = 0;
 return;
}

canonical_original_code:
static void ChangeLogging()
{
 if ( terminate == 1 )
  Terminate();
 Syslog(6, "klogd %s.%s, ---------- state change ----------\n", "1.5", "0");
 if ( reload_symbols > 0 )
 {
  ReloadSymbols();
  return;
 }
 if ( caught_TSTP == 1 )
 {
  CloseLogSrc();
  logsrc = none;
  change_state = 0;
  return;
 }
 if ( logsrc != none )
 {
  Syslog(6, "Kernel logging re-started after SIGSTOP.");
  change_state = 0;
  return;
 }
 logsrc = GetKernelLogSrc();
 change_state = 0;
 return;
}


LogProcLine

decompiled_code:
void LogProcLine()
{
int v0; // eax
int *v1; // rax
unsigned int *v2; // rbx
char *v3; // rax

memset(log_buffer, 0, sizeof(log_buffer));
v0 = read(kmsg, log_buffer, 0xFFFuLL);
if ( v0 >= 0 )
{
LogLine_constprop_0(v0);
}
else
{
v1 = _errno_location();
v2 = (unsigned int *)v1;
if ( *v1 != 4 )
{
v3 = strerror(*v1);
Syslog(3, "Cannot read proc file system: %d - %s.", *v2, v3);
}
}
}

canonical_decompiled_code:
void func14()
{
int v0; // eax
int *v1; // rax
unsigned int *v2; // rbx
char *v3; // rax

memset(log_buffer, 0, sizeof(log_buffer));
v0 = read(kmsg, log_buffer, 0xFFFuLL);
if ( v0 >= 0 )
{
func13(v0);
}
else
{
v1 = _errno_location();
v2 = (unsigned int *)v1;
if ( *v1 != 4 )
{
v3 = strerror(*v1);
func7(3, "Cannot read proc file system: %d - %s.", *v2, v3);
}
}
}

original_code:
static void LogProcLine(void)
{
 auto int rdcnt;
 memset(log_buffer, '\0', sizeof(log_buffer));
 if ( (rdcnt = read(kmsg, log_buffer, sizeof(log_buffer)-1)) < 0 )
 {
  if ( (*__errno_location ()) == 4 )
   return;
  Syslog(3, "Cannot read proc file system: %d - %s.", (*__errno_location ()), strerror((*__errno_location ())));
 }
 else
  LogLine(log_buffer, rdcnt);
 return;
}

canonical_original_code:
static void LogProcLine()
{
 auto int rdcnt;
 memset(log_buffer, '\0', sizeof(log_buffer));
 if ( (rdcnt = read(kmsg, log_buffer, sizeof(log_buffer)-1)) < 0 )
 {
  if ( (*__errno_location ()) == 4 )
   return;
  Syslog(3, "Cannot read proc file system: %d - %s.", (*__errno_location ()), strerror((*__errno_location ())));
 }
 else
  LogLine(log_buffer, rdcnt);
 return;
}

variable_types: rdcnt int


LogKernelLine

decompiled_code:
void LogKernelLine()
{
int v0; // eax
int *v1; // rax
unsigned int *v2; // rbx
char *v3; // rax

memset(log_buffer, 0, sizeof(log_buffer));
v0 = klogctl(2, log_buffer, 4095);
if ( v0 >= 0 )
{
LogLine_constprop_0(v0);
}
else
{
v1 = _errno_location();
v2 = (unsigned int *)v1;
if ( *v1 != 4 )
{
v3 = strerror(*v1);
fprintf(stderr, "klogd: Error return from sys_sycall: %d - %s\n", *v2, v3);
}
}
}

canonical_decompiled_code:
void func15()
{
int v0; // eax
int *v1; // rax
unsigned int *v2; // rbx
char *v3; // rax

memset(log_buffer, 0, sizeof(log_buffer));
v0 = klogctl(2, log_buffer, 4095);
if ( v0 >= 0 )
{
func13(v0);
}
else
{
v1 = _errno_location();
v2 = (unsigned int *)v1;
if ( *v1 != 4 )
{
v3 = strerror(*v1);
fprintf(stderr, "klogd: Error return from sys_sycall: %d - %s\n", *v2, v3);
}
}
}

original_code:
static void LogKernelLine(void)
{
 auto int rdcnt;
 memset(log_buffer, '\0', sizeof(log_buffer));
 if ( (rdcnt = klogctl(2, log_buffer, sizeof(log_buffer)-1)) < 0 )
 {
  if ( (*__errno_location ()) == 4 )
   return;
  fprintf(stderr, "klogd: Error return from sys_sycall: " "%d - %s\n", (*__errno_location ()), strerror((*__errno_location ())));
 }
 else
  LogLine(log_buffer, rdcnt);
 return;
}

canonical_original_code:
static void LogKernelLine()
{
 auto int rdcnt;
 memset(log_buffer, '\0', sizeof(log_buffer));
 if ( (rdcnt = klogctl(2, log_buffer, sizeof(log_buffer)-1)) < 0 )
 {
  if ( (*__errno_location ()) == 4 )
   return;
  fprintf(stderr, "klogd: Error return from sys_sycall: " "%d - %s\n", (*__errno_location ()), strerror((*__errno_location ())));
 }
 else
  LogLine(log_buffer, rdcnt);
 return;
}


FreeSymbols

decompiled_code:
void FreeSymbols()
{
void *v0; // r12
int v1; // ebx
void **v2; // rbp
void *v3; // rdi

v0 = sym_array;
v1 = 0;
v2 = (void **)((char *)sym_array + 8);
while ( num_syms > v1 )
{
v3 = *v2;
++v1;
v2 += 2;
free(v3);
}
free(v0);
sym_array = 0LL;
num_syms = 0;
}

canonical_decompiled_code:
void func0()
{
void *v0; // r12
int v1; // ebx
void **v2; // rbp
void *v3; // rdi

v0 = sym_array;
v1 = 0;
v2 = (void **)((char *)sym_array + 8);
while ( num_syms > v1 )
{
v3 = *v2;
++v1;
v2 += 2;
free(v3);
}
free(v0);
sym_array = 0LL;
num_syms = 0;
}

original_code:
static void FreeSymbols()
{
 auto int lp;
 for(lp = 0; lp < num_syms; ++lp)
  free(sym_array[lp].name);
 free(sym_array);
 sym_array = (struct sym_table *) 0;
 num_syms = 0;
 return;
}

variable_types: lp int

user_defined_types: struct sym_table { unsigned long value; char *name; }


closelog

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

result = close(LogFile);
LogFile = -1;
connected = 0;
return result;
}

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

result = close(LogFile);
LogFile = -1;
connected = 0;
return result;
}

original_code:
void
closelog()
{
 (void) close(LogFile);
 LogFile = -1;
 connected = 0;
}


syslog

decompiled_code:
void syslog(unsigned int a1, char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
vsyslog(a1, a2, va);
}

canonical_decompiled_code:
void func3(unsigned int a1, char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func2(a1, a2, va);
}

original_code:
void
syslog(int pri, const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 vsyslog(pri, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void syslog(int pri, char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 vsyslog(pri, fmt, ap);
 __builtin_va_end(ap);
}

variable_types: pri int

variable_types:
fmt
char *


FreeModules

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

if ( num_modules )
{
v0 = (char *)sym_array_modules;
if ( sym_array_modules )
{
if ( num_modules > 0 )
{
v1 = 0LL;
v2 = 24LL * num_modules;
do
{
while ( 1 )
{
v3 = &v0[v1];
v4 = *(_DWORD *)&v0[v1 + 8];
if ( v4 )
break;
v1 += 24LL;
if ( v1 == v2 )
goto LABEL_12;
}
v5 = 0LL;
if ( v4 > 0 )
{
do
{
v6 = v5++;
free(*(void **)(*(_QWORD *)v3 + 16 * v6 + 8));
}
while ( *((_DWORD *)v3 + 2) > (int)v5 );
}
free(*(void **)v3);
v7 = (void *)*((_QWORD *)v3 + 2);
if ( v7 )
free(v7);
v1 += 24LL;
v0 = (char *)sym_array_modules;
}
while ( v1 != v2 );
}
LABEL_12:
free(v0);
sym_array_modules = 0LL;
num_modules = 0;
}
}
}

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

if ( num_modules )
{
v0 = (char *)sym_array_modules;
if ( sym_array_modules )
{
if ( num_modules > 0 )
{
v1 = 0LL;
v2 = 24LL * num_modules;
do
{
while ( 1 )
{
v3 = &v0[v1];
v4 = *(_DWORD *)&v0[v1 + 8];
if ( v4 )
break;
v1 += 24LL;
if ( v1 == v2 )
goto LABEL_12;
}
v5 = 0LL;
if ( v4 > 0 )
{
do
{
v6 = v5++;
free(*(void **)(*(_QWORD *)v3 + 16 * v6 + 8));
}
while ( *((_DWORD *)v3 + 2) > (int)v5 );
}
free(*(void **)v3);
v7 = (void *)*((_QWORD *)v3 + 2);
if ( v7 )
free(v7);
v1 += 24LL;
v0 = (char *)sym_array_modules;
}
while ( v1 != v2 );
}
LABEL_12:
free(v0);
sym_array_modules = 0LL;
num_modules = 0;
}
}
}

original_code:
static void FreeModules()
{
 auto int nmods,
   nsyms;
 auto struct Module *mp;
 have_modules = 0;
 if ( num_modules == 0 )
  return;
 if ( sym_array_modules == ((void *)0) )
  return;
 for (nmods = 0; nmods < num_modules; ++nmods)
 {
  mp = &sym_array_modules[nmods];
  if ( mp->num_syms == 0 )
   continue;
  for (nsyms= 0; nsyms < mp->num_syms; ++nsyms)
   free(mp->sym_array[nsyms].name);
  free(mp->sym_array);
  if ( mp->name != ((void *)0) )
   free(mp->name);
 }
 free(sym_array_modules);
 sym_array_modules = (struct Module *) 0;
 num_modules = 0;
 return;
}

canonical_original_code:
static void FreeModules()
{
 auto int nmods; auto int nsyms;
 auto struct Module *mp;
 have_modules = 0;
 if ( num_modules == 0 )
  return;
 if ( sym_array_modules == ((void *)0) )
  return;
 for (nmods = 0; nmods < num_modules; ++nmods)
 {
  mp = &sym_array_modules[nmods];
  if ( mp->num_syms == 0 )
   continue;
  for (nsyms= 0; nsyms < mp->num_syms; ++nsyms)
   free(mp->sym_array[nsyms].name);
  free(mp->sym_array);
  if ( mp->name != ((void *)0) )
   free(mp->name);
 }
 free(sym_array_modules);
 sym_array_modules = (struct Module *) 0;
 num_modules = 0;
 return;
}

variable_types: nmods int

variable_types: nsyms int

variable_types: struct Module { struct sym_table { unsigned long value; char *name; } *sym_array; int num_syms; char *name; } *

user_defined_types: struct Module { struct sym_table *sym_array; int num_syms; char *name; }


isVoid

repo: Djeef/Indexation

decompiled_code:
_BOOL8 __fastcall isVoid(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int isVoid(HistogramSound *tab) {
 return(tab->begin == ((void *)0));
}

canonical_original_code:
int isVoid(struct HistogramSound *tab) {
 return(tab->begin == ((void *)0));
}

variable_types: struct HistogramSound { struct HistogramSoundCell { int key; int value; struct HistogramSoundCell *nextCell; } *begin; struct HistogramSoundCell *end; } *

user_defined_types: struct HistogramSound { struct HistogramSoundCell *begin; struct HistogramSoundCell *end; }


getHistogramSoundCell

decompiled_code:
__int64 __fastcall getHistogramSoundCell(__int64 *a1, int a2)
{
_BOOL4 v2; // er8
__int64 result; // rax

v2 = isVoid(a1);
result = 0LL;
if ( !v2 )
{
for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)result == a2 )
break;
}
}
return result;
}

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

v2 = func0(a1);
result = 0LL;
if ( !v2 )
{
for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)result == a2 )
break;
}
}
return result;
}

original_code:
HistogramSoundCell* getHistogramSoundCell(HistogramSound *tab, int key) {
 HistogramSoundCell *currentCell = ((void *)0);
 if(!isVoid(tab)) {
  currentCell = tab->begin;
  while(currentCell != ((void *)0)) {
   if(currentCell->key == key) {
    break;
   }
   currentCell = currentCell->nextCell;
  }
 }
 return(currentCell);
}

canonical_original_code:
struct HistogramSoundCell *getHistogramSoundCell(struct HistogramSound *tab, int key) {
 struct HistogramSoundCell *currentCell = ((void *)0);
 if(!isVoid(tab)) {
  currentCell = tab->begin;
  while(currentCell != ((void *)0)) {
   if(currentCell->key == key) {
    break;
   }
   currentCell = currentCell->nextCell;
  }
 }
 return(currentCell);
}

variable_types: struct HistogramSound { struct HistogramSoundCell *begin; struct HistogramSoundCell *end; } *

variable_types: key int

variable_types: struct HistogramSoundCell { int key; int value; struct HistogramSoundCell *nextCell; } *


initTab

decompiled_code:
__int64 __fastcall initTab(__int64 *a1, int a2)
{
int i; // ebx
int v4; // esi
__int64 result; // rax

*a1 = 0LL;
a1[1] = 0LL;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
v4 = i;
result = changeValueAt(a1, v4, 0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
int i; // ebx
int v4; // esi
__int64 result; // rax

*a1 = 0LL;
a1[1] = 0LL;
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
v4 = i;
result = func2(a1, v4, 0);
}
}
return result;
}

original_code:
void initTab(HistogramSound *tab, int nbValues) {
 int i;
 tab->begin = ((void *)0);
 tab->end = ((void *)0);
 for(i = 0; i < nbValues; i++) {
  changeValueAt(tab, i, 0);
 }
}

canonical_original_code:
void initTab(struct HistogramSound *tab, int nbValues) {
 int i;
 tab->begin = ((void *)0);
 tab->end = ((void *)0);
 for(i = 0; i < nbValues; i++) {
  changeValueAt(tab, i, 0);
 }
}

variable_types: nbValues int

user_defined_types: struct HistogramSoundCell { int key; int value; struct HistogramSoundCell *nextCell; }


addValue

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

result = getHistogramSoundCell(a1, a2);
if ( !result )
return changeValueAt(a1, a2, 1);
++*(_DWORD *)(result + 4);
return result;
}

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

result = func1(a1, a2);
if ( !result )
return func2(a1, a2, 1);
++*(_DWORD *)(result + 4);
return result;
}

original_code:
void addValue(HistogramSound *tab, int key) {
 HistogramSoundCell *currentCell = getHistogramSoundCell(tab, key);
 if(currentCell == ((void *)0)) {
  changeValueAt(tab, key, 1);
 } else {
  currentCell->value++;
 }
}

canonical_original_code:
void addValue(struct HistogramSound *tab, int key) {
 struct HistogramSoundCell *currentCell = getHistogramSoundCell(tab, key);
 if(currentCell == ((void *)0)) {
  changeValueAt(tab, key, 1);
 } else {
  currentCell->value++;
 }
}


decompiled_code:
__int64 __fastcall init_descriptor(__int64 a1)
{
_BYTE *v1; // rax
void *v2; // rax
__int64 result; // rax

v1 = calloc(0x1EuLL, 1uLL);
*(_QWORD *)a1 = v1;
*v1 = 0;
v2 = malloc(0x10uLL);
*(_QWORD *)(a1 + 8) = v2;
result = init_histogram(v2);
*(_DWORD *)(a1 + 16) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_BYTE *v1; // rax
void *v2; // rax
__int64 result; // rax

v1 = calloc(0x1EuLL, 1uLL);
*(_QWORD *)a1 = v1;
*v1 = 0;
v2 = malloc(0x10uLL);
*(_QWORD *)(a1 + 8) = v2;
result = init_histogram(v2);
*(_DWORD *)(a1 + 16) = 0;
return result;
}

original_code:
void init_descriptor(Descriptor *d) {
 d->id = (char*)calloc(30, sizeof(char));
 strcpy(d->id, "\0");
 d->ptr_histo = (Histogram*)malloc(sizeof(Histogram));
 init_histogram(d->ptr_histo);
 d->nb_words = 0;
}

canonical_original_code:
void init_descriptor(struct Descriptor *d) {
 d->id = (char *)calloc(30, sizeof(char));
 strcpy(d->id, "\0");
 d->ptr_histo = (struct Histogram *)malloc(sizeof(Histogram));
 init_histogram(d->ptr_histo);
 d->nb_words = 0;
}

variable_types: struct Descriptor { char *id; struct Histogram { struct Cel { char key[1000]; int value; struct Cel *ptr_next_cel; } *begin; struct Cel *end; } *ptr_histo; int nb_words; } *

user_defined_types: struct Descriptor { char *id; struct Histogram *ptr_histo; int nb_words; }

user_defined_types: struct Histogram { struct Cel *begin; struct Cel *end; }


decompiled_code:
void __fastcall free_descriptor(__int64 a1)
{
free_histogram(*(_QWORD *)(a1 + 8));
free(*(void **)a1);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
free_histogram(*(_QWORD *)(a1 + 8));
free(*(void **)a1);
}

original_code:
void free_descriptor(Descriptor *d) {
 free_histogram(d->ptr_histo);
 free(d->id);
}

canonical_original_code:
void free_descriptor(struct Descriptor *d) {
 free_histogram(d->ptr_histo);
 free(d->id);
}

user_defined_types: struct Cel { char key[1000]; int value; struct Cel *ptr_next_cel; }


original_code:
void add_value(char *key, Descriptor *d) {
 Cel *current_cel;
 Cel *newc;
 if(is_void(d->ptr_histo)) {
  newc = (Cel*)malloc(sizeof(Cel));
  strcpy(newc->key, key);
  newc->value = 1;
  newc->ptr_next_cel = ((void *)0);
  d->ptr_histo->begin = newc;
  d->ptr_histo->end = newc;
 } else {
  current_cel = d->ptr_histo->begin;
  while (current_cel != ((void *)0)) {
   if (strcmp(current_cel->key, key) == 0) {
    current_cel->value++;
    break;
   } else {
    current_cel = current_cel->ptr_next_cel;
   }
  }
  if (current_cel == ((void *)0)) {
   newc = (Cel*)malloc(sizeof(Cel));
   strcpy(newc->key, key);
   newc->value = 1;
   newc->ptr_next_cel = ((void *)0);
   d->ptr_histo->end->ptr_next_cel = newc;
   d->ptr_histo->end = d->ptr_histo->end->ptr_next_cel;
  }
 }
}

canonical_original_code:
void add_value(char *key, struct Descriptor *d) {
 struct Cel *current_cel;
 struct Cel *newc;
 if(is_void(d->ptr_histo)) {
  newc = (struct Cel *)malloc(sizeof(Cel));
  strcpy(newc->key, key);
  newc->value = 1;
  newc->ptr_next_cel = ((void *)0);
  d->ptr_histo->begin = newc;
  d->ptr_histo->end = newc;
 } else {
  current_cel = d->ptr_histo->begin;
  while (current_cel != ((void *)0)) {
   if (strcmp(current_cel->key, key) == 0) {
    current_cel->value++;
    break;
   } else {
    current_cel = current_cel->ptr_next_cel;
   }
  }
  if (current_cel == ((void *)0)) {
   newc = (struct Cel *)malloc(sizeof(Cel));
   strcpy(newc->key, key);
   newc->value = 1;
   newc->ptr_next_cel = ((void *)0);
   d->ptr_histo->end->ptr_next_cel = newc;
   d->ptr_histo->end = d->ptr_histo->end->ptr_next_cel;
  }
 }
}

variable_types:
key
char *

variable_types: struct Cel { char key[1000]; int value; struct Cel *ptr_next_cel; } *


initWavHeader

original_code:
void initWavHeader(WavHeader *wavHeader) {
 memset(wavHeader, 0, sizeof(WavHeader));
}

canonical_original_code:
void initWavHeader(struct WavHeader *wavHeader) {
 memset(wavHeader, 0, sizeof(WavHeader));
}

variable_types: struct WavHeader { char chunkId[4]; int chunkSize; char format[4]; char subChunk1Id[4]; int subChunk1Size; short audioFormat; short numChannels; int sampleRate; int byteRate; short blockAlign; short bitsPerSample; char subChunk2Id[4]; int subChunk2Size; } *


calculateScore

original_code:
int calculateScore(Histogram* hist) {
 int i;
 for(i = 0; i < hist->nbValue; i++) {
  hist->score += (i+1)*hist->matrixHisto[1][i];
 }
}

canonical_original_code:
int calculateScore(struct Histogram *hist) {
 int i;
 for(i = 0; i < hist->nbValue; i++) {
  hist->score += (i+1)*hist->matrixHisto[1][i];
 }
}

variable_types: struct Histogram { int nbValue; int score; int **matrixHisto; } *

variable_types: i int


decompiled_code:
_BOOL8 __fastcall is_void(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int is_void(Histogram *h) {
 return(h->begin == ((void *)0));
}

canonical_original_code:
int is_void(struct Histogram *h) {
 return(h->begin == ((void *)0));
}

variable_types: struct Histogram { struct Cel { char key[1000]; int value; struct Cel *ptr_next_cel; } *begin; struct Cel *end; } *


decompiled_code:
__int64 __fastcall get_nb_words(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 1008);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1)
{
__int64 v1; // rax
unsigned int i; // er8

v1 = *a1;
for ( i = 0; v1; ++i )
v1 = *(_QWORD *)(v1 + 1008);
return i;
}

original_code:
int get_nb_words(Histogram *h) {
 Cel *current_cel = h->begin;
 int nb_words = 0;
 while (current_cel != ((void *)0)) {
  nb_words++;
  current_cel = current_cel->ptr_next_cel;
 }
 return nb_words;
}

canonical_original_code:
int get_nb_words(struct Histogram *h) {
 struct Cel *current_cel = h->begin;
 int nb_words = 0;
 while (current_cel != ((void *)0)) {
  nb_words++;
  current_cel = current_cel->ptr_next_cel;
 }
 return nb_words;
}


decompiled_code:
int __fastcall add_key_value(char **a1, const char *a2, int a3)
{
char *v4; // rbx
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rdx

if ( is_void(a1) )
{
v6 = (char *)malloc(0x3F8uLL);
v5 = strcpy(v6, a2);
*((_DWORD *)v5 + 250) = a3;
*((_QWORD *)v5 + 126) = 0LL;
*a1 = v5;
a1[1] = v5;
}
else
{
v4 = *a1;
if ( *a1 )
{
while ( 1 )
{
LODWORD(v5) = strcmp(v4, a2);
if ( !(_DWORD)v5 )
break;
v4 = (char *)*((_QWORD *)v4 + 126);
if ( !v4 )
goto LABEL_8;
}
*((_DWORD *)v4 + 250) = a3;
}
else
{
LABEL_8:
v7 = (char *)malloc(0x3F8uLL);
v8 = strcpy(v7, a2);
*((_QWORD *)v8 + 126) = 0LL;
v9 = v8;
*((_DWORD *)v8 + 250) = a3;
v5 = a1[1];
*((_QWORD *)v5 + 126) = v9;
a1[1] = v9;
}
}
return (int)v5;
}

original_code:
void add_key_value(Histogram *h, char *key, int value) {
 Cel *current_cel;
 Cel *newc;
 if(is_void(h)) {
  newc = (Cel*)malloc(sizeof(Cel));
  strcpy(newc->key, key);
  newc->value = value;
  newc->ptr_next_cel = ((void *)0);
  h->begin = newc;
  h->end = newc;
 } else {
  current_cel = h->begin;
  while (current_cel != ((void *)0)) {
   if (strcmp(current_cel->key, key) == 0) {
    current_cel->value = value;
    break;
   } else {
    current_cel = current_cel->ptr_next_cel;
   }
  }
  if (current_cel == ((void *)0)) {
   newc = (Cel*)malloc(sizeof(Cel));
   strcpy(newc->key, key);
   newc->value = value;
   newc->ptr_next_cel = ((void *)0);
   h->end->ptr_next_cel = newc;
   h->end = h->end->ptr_next_cel;
  }
 }
}

canonical_original_code:
void add_key_value(struct Histogram *h, char *key, int value) {
 struct Cel *current_cel;
 struct Cel *newc;
 if(is_void(h)) {
  newc = (struct Cel *)malloc(sizeof(Cel));
  strcpy(newc->key, key);
  newc->value = value;
  newc->ptr_next_cel = ((void *)0);
  h->begin = newc;
  h->end = newc;
 } else {
  current_cel = h->begin;
  while (current_cel != ((void *)0)) {
   if (strcmp(current_cel->key, key) == 0) {
    current_cel->value = value;
    break;
   } else {
    current_cel = current_cel->ptr_next_cel;
   }
  }
  if (current_cel == ((void *)0)) {
   newc = (struct Cel *)malloc(sizeof(Cel));
   strcpy(newc->key, key);
   newc->value = value;
   newc->ptr_next_cel = ((void *)0);
   h->end->ptr_next_cel = newc;
   h->end = h->end->ptr_next_cel;
  }
 }
}

variable_types: value int


decompiled_code:
int __fastcall get_value(__int64 *a1, const char *a2)
{
_DWORD *v2; // rdx
__int64 v3; // rbx
_DWORD *v4; // r12
int result; // eax

if ( is_void(a1) )
return -1;
v3 = *a1;
v4 = v2;
if ( !*a1 )
return -1;
while ( 1 )
{
result = strcmp((const char *)v3, a2);
if ( !result )
break;
v3 = *(_QWORD *)(v3 + 1008);
if ( !v3 )
return -1;
}
*v4 = *(_DWORD *)(v3 + 1000);
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 *a1, const char *a2)
{
_DWORD *v2; // rdx
__int64 v3; // rbx
_DWORD *v4; // r12
int result; // eax

if ( func1(a1) )
return -1;
v3 = *a1;
v4 = v2;
if ( !*a1 )
return -1;
while ( 1 )
{
result = strcmp((const char *)v3, a2);
if ( !result )
break;
v3 = *(_QWORD *)(v3 + 1008);
if ( !v3 )
return -1;
}
*v4 = *(_DWORD *)(v3 + 1000);
return result;
}

original_code:
int get_value(Histogram *h, char *key, int *value) {
 Cel *current_cel;
 if(is_void(h)) {
  return(-1);
 } else {
  current_cel = h->begin;
  while(current_cel != ((void *)0)) {
   if(strcmp(current_cel->key, key) == 0) {
    *value = current_cel->value;
    return(0);
    break;
   } else {
    current_cel = current_cel->ptr_next_cel;
   }
  }
 }
 return(-1);
}

canonical_original_code:
int get_value(struct Histogram *h, char *key, int *value) {
 struct Cel *current_cel;
 if(is_void(h)) {
  return(-1);
 } else {
  current_cel = h->begin;
  while(current_cel != ((void *)0)) {
   if(strcmp(current_cel->key, key) == 0) {
    *value = current_cel->value;
    return(0);
    break;
   } else {
    current_cel = current_cel->ptr_next_cel;
   }
  }
 }
 return(-1);
}

variable_types:
value
int *


initWavData

decompiled_code:
void __fastcall initWavData(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)a1 = 0;
}

original_code:
void initWavData(WavData *wavData) {
        wavData->begin = ((void *)0);
        wavData->end = ((void *)0);
        wavData->size = 0;
}

canonical_original_code:
void initWavData(struct WavData *wavData) {
        wavData->begin = ((void *)0);
        wavData->end = ((void *)0);
        wavData->size = 0;
}

variable_types: struct WavData { int size; struct CelWavData { short sample; struct CelWavData *nextCell; } *begin; struct CelWavData *end; } *

user_defined_types: struct WavData { int size; struct CelWavData *begin; struct CelWavData *end; }


quantifyRGB

decompiled_code:
__int64 __fastcall quantifyRGB(void **a1, int a2, int a3, int a4, const char *a5)
{
int v5; // er14
int v6; // er13
int v7; // er12
int v9; // ebp
__int64 result; // rax
__int64 v11; // r15
int v12; // ebp
int v13; // ecx
int v14; // edx
int v15; // ecx
char *v16; // rax
int v17; // ebp
__int64 v18; // r15
int v19; // er14
int v20; // edx
int v21; // ecx
char *v22; // rax
int v23; // er12
__int64 v24; // rbp
int v25; // ecx
char *v26; // rax

v5 = a2;
v6 = a4;
v7 = a3;
if ( a4 <= 255 && a3 <= 255 && a2 <= 255 )
{
v9 = *((_DWORD *)a1 + 2);
*a1 = malloc(12LL * v9);
result = (unsigned int)(8 - v9);
if ( (int)result <= 7 )
{
v11 = 0LL;
v12 = 7;
do
{
v15 = (int)pow(2.0, (double)v12);
v16 = (char *)*a1;
if ( v5 % v15 < v5 )
{
*(_DWORD *)&v16[v11] = 1;
v5 -= v15;
}
else
{
*(_DWORD *)&v16[v11] = 0;
}
v13 = v12;
result = (unsigned int)(8 - *((_DWORD *)a1 + 2));
v14 = 8 - v12--;
v11 += 4LL;
}
while ( (int)result <= v12 );
if ( (int)result <= 7 )
{
v17 = 7;
v18 = 4LL * v14;
v19 = 16 - v13;
do
{
v21 = (int)pow(2.0, (double)v17);
v22 = (char *)*a1;
if ( v7 % v21 < v7 )
{
*(_DWORD *)&v22[v18] = 1;
v7 -= v21;
}
else
{
*(_DWORD *)&v22[v18] = 0;
}
v20 = 8 - *((_DWORD *)a1 + 2);
v18 += 4LL;
result = (unsigned int)(v19 - v17--);
}
while ( v20 <= v17 );
if ( v20 <= 7 )
{
v23 = 7;
v24 = 4LL * (int)result;
do
{
v25 = (int)pow(2.0, (double)v23);
v26 = (char *)*a1;
if ( v6 % v25 < v6 )
{
*(_DWORD *)&v26[v24] = 1;
v6 -= v25;
}
else
{
*(_DWORD *)&v26[v24] = 0;
}
--v23;
result = (unsigned int)(8 - *((_DWORD *)a1 + 2));
v24 += 4LL;
}
while ( (int)result <= v23 );
}
}
}
}
else
{
fwrite("\x1B[31m", 1uLL, 5uLL, stderr);
fprintf(
stderr,
"> ERROR: RGB level higher than 255: value = R: %d / G: %d / B: %d (in file: %s)\n",
(unsigned int)a2,
(unsigned int)v7,
(unsigned int)v6,
a5);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
fflush(stdout);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int quantifyRGB(Quantification* quant, int redValue, int greenValue, int blueValue, char* filename) {
 int powerOfTwo, exponent, positionQuantWord;
 if(redValue <= 255 && greenValue <= 255 && blueValue <= 255) {
  quant->quantifyingNumber = (int*)malloc(((quant->nbBit)*3)*sizeof(int));
  positionQuantWord = 0;
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((redValue%powerOfTwo) <= (redValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    redValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((greenValue%powerOfTwo) <= (greenValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    greenValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((blueValue%powerOfTwo) <= (blueValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    blueValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
 } else {
  fprintf(stderr, "\033[31m");
  fprintf(stderr, "> ERROR: RGB level higher than 255: value = R: %d / G: %d / B: %d (in file: %s)\n", redValue, greenValue, blueValue, filename);
  fprintf(stderr, "\033[00m");
  fflush(stdout);
  return -1;
 }
}

canonical_original_code:
int quantifyRGB(struct Quantification *quant, int redValue, int greenValue, int blueValue, char *filename) {
 int powerOfTwo; int exponent; int positionQuantWord;
 if(redValue <= 255 && greenValue <= 255 && blueValue <= 255) {
  quant->quantifyingNumber = (int *)malloc(((quant->nbBit)*3)*sizeof(int));
  positionQuantWord = 0;
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((redValue%powerOfTwo) <= (redValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    redValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((greenValue%powerOfTwo) <= (greenValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    greenValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((blueValue%powerOfTwo) <= (blueValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    blueValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
 } else {
  fprintf(stderr, "\033[31m");
  fprintf(stderr, "> ERROR: RGB level higher than 255: value = R: %d / G: %d / B: %d (in file: %s)\n", redValue, greenValue, blueValue, filename);
  fprintf(stderr, "\033[00m");
  fflush(stdout);
  return -1;
 }
}

variable_types: struct Quantification { int *quantifyingNumber; int nbBit; } *

variable_types: redValue int

variable_types: greenValue int

variable_types: blueValue int

variable_types:
filename
char *

variable_types: powerOfTwo int

variable_types: exponent int

variable_types: positionQuantWord int


quantifyBW

decompiled_code:
__int64 __fastcall quantifyBW(void **a1, int a2, const char *a3)
{
int v3; // er12
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbp
int v7; // ebx
int v8; // ecx
char *v9; // rax

v3 = a2;
if ( a2 > 255 )
{
fwrite("\x1B[31m", 1uLL, 5uLL, stderr);
fprintf(stderr, "> ERROR: Grey level higher than 255: value = %d (in file: %s)\n", (unsigned int)a2, a3);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
fflush(stdout);
result = 0xFFFFFFFFLL;
}
else
{
v4 = *((int *)a1 + 2);
*a1 = malloc(4 * v4);
result = (unsigned int)(8 - v4);
if ( (int)result <= 7 )
{
v6 = 0LL;
v7 = 7;
do
{
v8 = (int)pow(2.0, (double)v7);
v9 = (char *)*a1;
if ( v3 % v8 < v3 )
{
*(_DWORD *)&v9[v6] = 1;
v3 -= v8;
}
else
{
*(_DWORD *)&v9[v6] = 0;
}
--v7;
result = (unsigned int)(8 - *((_DWORD *)a1 + 2));
v6 += 4LL;
}
while ( (int)result <= v7 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1, int a2, const char *a3)
{
int v3; // er12
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbp
int v7; // ebx
int v8; // ecx
char *v9; // rax

v3 = a2;
if ( a2 > 255 )
{
fwrite("\x1B[31m", 1uLL, 5uLL, stderr);
fprintf(stderr, "> ERROR: Grey level higher than 255: value = %d (in file: %s)\n", (unsigned int)a2, a3);
fwrite("\x1B[00m", 1uLL, 5uLL, stderr);
fflush(stdout);
result = 0xFFFFFFFFLL;
}
else
{
v4 = *((int *)a1 + 2);
*a1 = malloc(4 * v4);
result = (unsigned int)(8 - v4);
if ( (int)result <= 7 )
{
v6 = 0LL;
v7 = 7;
do
{
v8 = (int)pow(2.0, (double)v7);
v9 = (char *)*a1;
if ( v3 % v8 < v3 )
{
*(_DWORD *)&v9[v6] = 1;
v3 -= v8;
}
else
{
*(_DWORD *)&v9[v6] = 0;
}
--v7;
result = (unsigned int)(8 - *((_DWORD *)a1 + 2));
v6 += 4LL;
}
while ( (int)result <= v7 );
}
}
return result;
}

original_code:
int quantifyBW(Quantification* quant, int greyValue, char* filename) {
 int powerOfTwo, exponent, positionQuantWord;
 if(greyValue <= 255) {
  quant->quantifyingNumber = (int*)malloc((quant->nbBit)*sizeof(int));
  positionQuantWord = 0;
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((greyValue%powerOfTwo) <= (greyValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    greyValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
 } else {
  fprintf(stderr, "\033[31m");
  fprintf(stderr, "> ERROR: Grey level higher than 255: value = %d (in file: %s)\n", greyValue, filename);
  fprintf(stderr, "\033[00m");
  fflush(stdout);
  return -1;
 }
}

canonical_original_code:
int quantifyBW(struct Quantification *quant, int greyValue, char *filename) {
 int powerOfTwo; int exponent; int positionQuantWord;
 if(greyValue <= 255) {
  quant->quantifyingNumber = (int *)malloc((quant->nbBit)*sizeof(int));
  positionQuantWord = 0;
  for(exponent = 7; exponent >= (8-quant->nbBit); exponent--) {
   powerOfTwo = pow(2, exponent);
   if((greyValue%powerOfTwo) <= (greyValue-1)) {
    quant->quantifyingNumber[positionQuantWord] = 1;
    greyValue -= powerOfTwo;
   } else {
    quant->quantifyingNumber[positionQuantWord] = 0;
   }
   positionQuantWord++;
  }
 } else {
  fprintf(stderr, "\033[31m");
  fprintf(stderr, "> ERROR: Grey level higher than 255: value = %d (in file: %s)\n", greyValue, filename);
  fprintf(stderr, "\033[00m");
  fflush(stdout);
  return -1;
 }
}

variable_types: greyValue int

user_defined_types: struct Quantification { int *quantifyingNumber; int nbBit; }


calculateMatrixRGBQuantification

original_code:
int calculateMatrixRGBQuantification(PictureRGB* pictRGB, Quantification* quant, Histogram* hist, char* filename) {
 int i, j, k, exponent, quantifyingLevel;
 int redValue, blueValue, greenValue;
 for(i = 0; i < pictRGB->sizeY; i++) {
  for(j = 0; j < pictRGB->sizeX; j++) {
   redValue = pictRGB->matrixRed[i][j];
   greenValue = pictRGB->matrixGreen[i][j];
   blueValue = pictRGB->matrixBlue[i][j];
   quantifyRGB(&(*quant), redValue, greenValue, blueValue, filename);
   exponent = ((quant->nbBit)*(pictRGB->component)) - 1;
   quantifyingLevel = 0;
   for(k = 0; k < ((quant->nbBit)*(pictRGB->component)); k++) {
    if(quant->quantifyingNumber[k] == 1) {
     quantifyingLevel += pow(2, exponent);
    }
    exponent--;
   }
   hist->matrixHisto[1][quantifyingLevel]++;
  }
 }
}

canonical_original_code:
int calculateMatrixRGBQuantification(struct PictureRGB *pictRGB, struct Quantification *quant, struct Histogram *hist, char *filename) {
 int i; int j; int k; int exponent; int quantifyingLevel;
 int redValue; int blueValue; int greenValue;
 for(i = 0; i < pictRGB->sizeY; i++) {
  for(j = 0; j < pictRGB->sizeX; j++) {
   redValue = pictRGB->matrixRed[i][j];
   greenValue = pictRGB->matrixGreen[i][j];
   blueValue = pictRGB->matrixBlue[i][j];
   quantifyRGB(&(*quant), redValue, greenValue, blueValue, filename);
   exponent = ((quant->nbBit)*(pictRGB->component)) - 1;
   quantifyingLevel = 0;
   for(k = 0; k < ((quant->nbBit)*(pictRGB->component)); k++) {
    if(quant->quantifyingNumber[k] == 1) {
     quantifyingLevel += pow(2, exponent);
    }
    exponent--;
   }
   hist->matrixHisto[1][quantifyingLevel]++;
  }
 }
}

variable_types: struct PictureRGB { char *filename; int sizeX; int sizeY; int component; int **matrixRed; int **matrixGreen; int **matrixBlue; } *

variable_types: j int

variable_types: k int

variable_types: quantifyingLevel int

user_defined_types: struct Histogram { int nbValue; int score; int **matrixHisto; }


calculateMatrixBWQuantification

original_code:
int calculateMatrixBWQuantification(PictureBW* pictBW, Quantification* quant, Histogram* hist, char* filename) {
 int i, j, k, exponent, quantifyingLevel;
 int greyValue;
 for(i = 0; i < pictBW->sizeY; i++) {
  for(j = 0; j < pictBW->sizeX; j++) {
   greyValue = pictBW->matrixGrey[i][j];
   quantifyBW(&(*quant), greyValue, filename);
   exponent = quant->nbBit - 1;
   quantifyingLevel = 0;
   for(k = 0; k < ((quant->nbBit)*(pictBW->component)); k++) {
    if(quant->quantifyingNumber[k] == 1) {
     quantifyingLevel += pow(2, exponent);
    }
    exponent--;
   }
   hist->matrixHisto[1][quantifyingLevel]++;
  }
 }
}

canonical_original_code:
int calculateMatrixBWQuantification(struct PictureBW *pictBW, struct Quantification *quant, struct Histogram *hist, char *filename) {
 int i; int j; int k; int exponent; int quantifyingLevel;
 int greyValue;
 for(i = 0; i < pictBW->sizeY; i++) {
  for(j = 0; j < pictBW->sizeX; j++) {
   greyValue = pictBW->matrixGrey[i][j];
   quantifyBW(&(*quant), greyValue, filename);
   exponent = quant->nbBit - 1;
   quantifyingLevel = 0;
   for(k = 0; k < ((quant->nbBit)*(pictBW->component)); k++) {
    if(quant->quantifyingNumber[k] == 1) {
     quantifyingLevel += pow(2, exponent);
    }
    exponent--;
   }
   hist->matrixHisto[1][quantifyingLevel]++;
  }
 }
}

variable_types: struct PictureBW { char *filename; int sizeX; int sizeY; int component; int **matrixGrey; } *

variable_types: struct Histogram { int nbValue; int score; int **matrixHisto; } *

variable_types: i int


decompiled_code:
__int64 __fastcall rl_max_size(__int64 a1)
{
if ( !a1 )
_assert_fail("rl != NULL", "readlines.c", 0xFu, "rl_max_size");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
_assert_fail("rl != NULL", "readlines.c", 0xFu, "rl_max_size");
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t rl_max_size(struct RL* rl){
    ((void) sizeof ((rl != ((void *)0)) ? 1 : 0), __extension__ ({ if (rl != ((void *)0)) ; else __assert_fail ("rl != NULL", "readlines.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    return rl->max_size;
}

canonical_original_code:
unsigned long rl_max_size(struct RL *rl){
    ((void) sizeof ((rl != ((void *)0)) ? 1 : 0), __extension__ ({ if (rl != ((void *)0)) ; else __assert_fail ("rl != NULL", "readlines.c", 15, __extension__ __PRETTY_FUNCTION__); }));
    return rl->max_size;
}

variable_types: struct RL { int fd; unsigned long max_size; } *

return_type: unsigned long


decompiled_code:
__int64 __fastcall rl_close(void *ptr)
{
unsigned int v1; // er12

if ( !ptr )
_assert_fail("rl != NULL", "readlines.c", 0x14u, "rl_close");
v1 = close(*(_DWORD *)ptr);
free(ptr);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
unsigned int v1; // er12

if ( !ptr )
_assert_fail("rl != NULL", "readlines.c", 0x14u, "rl_close");
v1 = close(*(_DWORD *)ptr);
free(ptr);
return v1;
}

original_code:
int rl_close(struct RL* rl){
    ((void) sizeof ((rl != ((void *)0)) ? 1 : 0), __extension__ ({ if (rl != ((void *)0)) ; else __assert_fail ("rl != NULL", "readlines.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    int ret = close(rl->fd);
    free(rl);
    return ret;
}

canonical_original_code:
int rl_close(struct RL *rl){
    ((void) sizeof ((rl != ((void *)0)) ? 1 : 0), __extension__ ({ if (rl != ((void *)0)) ; else __assert_fail ("rl != NULL", "readlines.c", 20, __extension__ __PRETTY_FUNCTION__); }));
    int ret = close(rl->fd);
    free(rl);
    return ret;
}

variable_types: ret int

user_defined_types: struct RL { int fd; unsigned long max_size; }


decompiled_code:
ssize_t __fastcall rl_readline(__int64 a1, char *a2, size_t a3)
{
unsigned __int64 v4; // r14
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rax
ssize_t result; // rax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( !a1 )
_assert_fail("rl != NULL", "readlines.c", 0x1Bu, "rl_readline");
v4 = a3 + 1;
memset(a2, 0, a3);
v5 = read(*(_DWORD *)a1, a2, 1uLL);
if ( !v5 )
return 0LL;
while ( 1 )
{
if ( a2[v5 - 1] == 10 )
return (unsigned int)v5;
v6 = *(_QWORD *)(a1 + 8);
if ( v4 <= v5 || v5 >= v6 )
break;
v5 += read(*(_DWORD *)a1, &a2[v5], 1uLL);
if ( !v5 )
return 0LL;
}
if ( v6 + 1 == v5 )
return 4294967293LL;
if ( v5 != a3 )
return 4294965959LL;
while ( 1 )
{
result = read(*(_DWORD *)a1, buf, 1uLL);
if ( !(_DWORD)result )
break;
if ( buf[0] == 10 )
return 4294967294LL;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1, char *a2, size_t a3)
{
unsigned __int64 v4; // r14
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rax
ssize_t result; // rax
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( !a1 )
_assert_fail("rl != NULL", "readlines.c", 0x1Bu, "rl_readline");
v4 = a3 + 1;
memset(a2, 0, a3);
v5 = read(*(_DWORD *)a1, a2, 1uLL);
if ( !v5 )
return 0LL;
while ( 1 )
{
if ( a2[v5 - 1] == 10 )
return (unsigned int)v5;
v6 = *(_QWORD *)(a1 + 8);
if ( v4 <= v5 || v5 >= v6 )
break;
v5 += read(*(_DWORD *)a1, &a2[v5], 1uLL);
if ( !v5 )
return 0LL;
}
if ( v6 + 1 == v5 )
return 4294967293LL;
if ( v5 != a3 )
return 4294965959LL;
while ( 1 )
{
result = read(*(_DWORD *)a1, buf, 1uLL);
if ( !(_DWORD)result )
break;
if ( buf[0] == 10 )
return 4294967294LL;
}
return result;
}

original_code:
int rl_readline(struct RL* rl, char* buf, size_t buf_size){
    ((void) sizeof ((rl != ((void *)0)) ? 1 : 0), __extension__ ({ if (rl != ((void *)0)) ; else __assert_fail ("rl != NULL", "readlines.c", 27, __extension__ __PRETTY_FUNCTION__); }));
    size_t pos = 0;
    memset(buf,0,buf_size);
    if( (pos = read(rl->fd, buf, sizeof(char))) == 0)
        return 0;
    while (buf[pos-1] != '\n' && pos < buf_size+1 && pos < rl->max_size)
    {
        pos += read(rl->fd, &buf[pos], sizeof(char));
        if(pos == 0)
            return 0;
    }
    if(buf[pos-1] == '\n')
        return pos;
    if(pos == rl->max_size+1)
        return -3;
    if(pos == buf_size){
        char tmp;
        do{
            int has_read = read(rl->fd, &tmp, sizeof(char));
            if(has_read == 0)
                return 0;
        } while(tmp != '\n');
        return -2;
    }
    return -1337;
}

canonical_original_code:
int rl_readline(struct RL *rl, char *buf, unsigned long buf_size){
    ((void) sizeof ((rl != ((void *)0)) ? 1 : 0), __extension__ ({ if (rl != ((void *)0)) ; else __assert_fail ("rl != NULL", "readlines.c", 27, __extension__ __PRETTY_FUNCTION__); }));
    unsigned long pos = 0;
    memset(buf,0,buf_size);
    if( (pos = read(rl->fd, buf, sizeof(char))) == 0)
        return 0;
    while (buf[pos-1] != '\n' && pos < buf_size+1 && pos < rl->max_size)
    {
        pos += read(rl->fd, &buf[pos], sizeof(char));
        if(pos == 0)
            return 0;
    }
    if(buf[pos-1] == '\n')
        return pos;
    if(pos == rl->max_size+1)
        return -3;
    if(pos == buf_size){
        char tmp;
        do{
            int has_read = read(rl->fd, &tmp, sizeof(char));
            if(has_read == 0)
                return 0;
        } while(tmp != '\n');
        return -2;
    }
    return -1337;
}

variable_types:
buf
char *

variable_types:
pos
unsigned long

variable_types: tmp char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // er12
char s[64]; // [rsp+10h] [rbp-448h] BYREF
char v7[1032]; // [rsp+50h] [rbp-408h] BYREF

v3 = argv[1];
file = fopen(argv[2], "w+");
pcap = pcap_open_live();
if ( pcap )
{
lnet = libnet_init();
if ( lnet )
{
v4 = set_local_fields(0LL, v3);
if ( v4 )
{
v4 = 1;
puts("set_local_fields failed");
}
else
{
sprintf(s, "udp and dst port %d", 13579LL);
pcap_compile();
pcap_setfilter();
memset(&sources, 0, 0x8000uLL);
pcap_loop();
libnet_destroy();
pcap_close();
fclose(file);
}
}
else
{
v4 = 1;
puts("libnet init error!");
fputs(v7, _bss_start);
pcap_close();
}
}
else
{
v4 = 1;
puts("pcap init error!");
fputs(v7, _bss_start);
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // er12
char s[64]; // [rsp+10h] [rbp-448h] BYREF
char v7[1032]; // [rsp+50h] [rbp-408h] BYREF

v3 = argv[1];
file = fopen(argv[2], "w+");
pcap = pcap_open_live();
if ( pcap )
{
lnet = libnet_init();
if ( lnet )
{
v4 = func14(0LL, v3);
if ( v4 )
{
v4 = 1;
puts("set_local_fields failed");
}
else
{
sprintf(s, "udp and dst port %d", 13579LL);
pcap_compile();
pcap_setfilter();
memset(&sources, 0, 0x8000uLL);
pcap_loop();
libnet_destroy();
pcap_close();
fclose(file);
}
}
else
{
v4 = 1;
puts("libnet init error!");
fputs(v7, _bss_start);
pcap_close();
}
}
else
{
v4 = 1;
puts("pcap init error!");
fputs(v7, _bss_start);
}
return v4;
}

original_code:
int main(int agrc, char** argv)
{
    char err_buf[1024];
    char* dev = argv[1];
    file = fopen(argv[2], "w+");
    pcap = pcap_open_live(dev, 65536, 1, 0, err_buf);
    if (pcap == ((void *)0)) {
        printf("pcap init error!\n");
        fprintf(stderr, "%s", err_buf);
        return 1;
    }
    lnet = libnet_init(0x00, dev, err_buf);
    if (lnet == ((void *)0)) {
        printf("libnet init error!\n");
        fprintf(stderr, "%s", err_buf);
        pcap_close(pcap);
        return 1;
    }
    if (set_local_fields() != 0) {
        printf("set_local_fields failed\n");
        return 1;
    }
    char pattern[64];
    sprintf(pattern, "udp and dst port %d", 13579);
    struct bpf_program filter;
    pcap_compile(pcap, &filter, pattern, 1, 0);
    pcap_setfilter(pcap, &filter);
    memset(sources, 0, sizeof(sources));
    pcap_loop(pcap, -1, parse_packet, ((void *)0));
    libnet_destroy(lnet);
    pcap_close(pcap);
    fclose(file);
    return 0;
}

canonical_original_code:
int main(int agrc, char **argv)
{
    char err_buf[1024];
    char *dev = argv[1];
    file = fopen(argv[2], "w+");
    pcap = pcap_open_live(dev, 65536, 1, 0, err_buf);
    if (pcap == ((void *)0)) {
        printf("pcap init error!\n");
        fprintf(stderr, "%s", err_buf);
        return 1;
    }
    lnet = libnet_init(0x00, dev, err_buf);
    if (lnet == ((void *)0)) {
        printf("libnet init error!\n");
        fprintf(stderr, "%s", err_buf);
        pcap_close(pcap);
        return 1;
    }
    if (set_local_fields() != 0) {
        printf("set_local_fields failed\n");
        return 1;
    }
    char pattern[64];
    sprintf(pattern, "udp and dst port %d", 13579);
    struct bpf_program filter;
    pcap_compile(pcap, &filter, pattern, 1, 0);
    pcap_setfilter(pcap, &filter);
    memset(sources, 0, sizeof(sources));
    pcap_loop(pcap, -1, parse_packet, ((void *)0));
    libnet_destroy(lnet);
    pcap_close(pcap);
    fclose(file);
    return 0;
}

variable_types: agrc int

variable_types:
argv
char **

variable_types:
dev
char *

variable_types:
pattern
char [64]

variable_types: struct bpf_program { unsigned int bf_len; struct bpf_insn { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *bf_insns; }

user_defined_types: struct bpf_program { unsigned int bf_len; struct bpf_insn *bf_insns; }