decompiled_code:
void __fastcall msg_queue_destroy_and_free(__int64 a1, int a2)
{
int v3; // eax
_QWORD *v4; // rbx
_QWORD *v5; // rdi

if ( a1 )
{
v3 = *(_DWORD *)(a1 + 36);
if ( (v3 & 2) != 0 )
{
if ( !(unsigned int)remove_reference() )
return;
v3 = *(_DWORD *)(a1 + 36);
}
if ( (v3 & 1) != 0 )
futex_get((volatile signed __int32 *)(a1 + 32));
v4 = *(_QWORD **)(a1 + 16);
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)v4[2];
free_message(v5);
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) == 0 )
{
if ( !a2 )
return;
LABEL_10:
futex_get(mem_lock);
qm_free(shm_block, a1);
futex_release(mem_lock);
return;
}
futex_release((volatile __int32 *)(a1 + 32));
if ( a2 )
goto LABEL_10;
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2)
{
int v3; // eax
_QWORD *v4; // rbx
_QWORD *v5; // rdi

if ( a1 )
{
v3 = *(_DWORD *)(a1 + 36);
if ( (v3 & 2) != 0 )
{
if ( !(unsigned int)remove_reference() )
return;
v3 = *(_DWORD *)(a1 + 36);
}
if ( (v3 & 1) != 0 )
func3((volatile signed __int32 *)(a1 + 32));
v4 = *(_QWORD **)(a1 + 16);
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)v4[2];
func10(v5);
}
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) == 0 )
{
if ( !a2 )
return;
LABEL_10:
func3(mem_lock);
qm_free(shm_block, a1);
func1(mem_lock);
return;
}
func1((volatile __int32 *)(a1 + 32));
if ( a2 )
goto LABEL_10;
}
}

original_code:
static inline void msg_queue_destroy_and_free(msg_queue_t *q, int do_free)
{
 mq_message_t *m,*n;
 if (!q) return;
 if (q->flags & 2) {
  if (!remove_reference(&q->ref)) {
   return;
  }
 }
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 while (m) {
  n = m->next;
  free_message(m);
  m = n;
 }
 q->first = ((void *)0);
 q->last = ((void *)0);
 if (q->flags & 1) {
  futex_release(&q->q_mutex);
  ;
 }
 if (do_free) do { futex_get(mem_lock); qm_free(shm_block, (q)); futex_release(mem_lock); }while(0);
}

canonical_original_code:
static inline void msg_queue_destroy_and_free(struct msg_queue *q, int do_free)
{
 struct _mq_message_t *m; struct _mq_message_t *n;
 if (!q) return;
 if (q->flags & 2) {
  if (!remove_reference(&q->ref)) {
   return;
  }
 }
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 while (m) {
  n = m->next;
  free_message(m);
  m = n;
 }
 q->first = ((void *)0);
 q->last = ((void *)0);
 if (q->flags & 1) {
  futex_release(&q->q_mutex);
  ;
 }
 if (do_free) do { futex_get(mem_lock); qm_free(shm_block, (q)); futex_release(mem_lock); }while(0);
}

variable_types: struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *

user_defined_types: struct msg_queue { struct reference_counter_data_t ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; }

user_defined_types: struct reference_counter_data_t { int cntr; struct atomic_t *mutex; }


repo: virtualolson/who

decompiled_code:
__int64 __fastcall push_message(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // eax
__int64 v4; // rdx
unsigned int v5; // er12

if ( !a1 || !a2 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a1 + 36);
*(_QWORD *)(a2 + 16) = 0LL;
v3 = v2 & 1;
if ( !v3 )
{
v4 = *(_QWORD *)(a1 + 24);
if ( v4 )
goto LABEL_5;
LABEL_8:
*(_QWORD *)(a1 + 16) = a2;
v5 = 0;
*(_QWORD *)(a1 + 24) = a2;
if ( !v3 )
return v5;
goto LABEL_9;
}
futex_get((volatile signed __int32 *)(a1 + 32));
v4 = *(_QWORD *)(a1 + 24);
v3 = *(_DWORD *)(a1 + 36) & 1;
if ( !v4 )
goto LABEL_8;
LABEL_5:
*(_QWORD *)(v4 + 16) = a2;
v5 = 0;
*(_QWORD *)(a1 + 24) = a2;
if ( !v3 )
return v5;
LABEL_9:
futex_release((volatile __int32 *)(a1 + 32));
return 0LL;
}

original_code:
int push_message(msg_queue_t *q, mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->last) q->last->next = m;
 else {
  q->first = m;
  q->last = m;
 }
 q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}

canonical_original_code:
int push_message(struct msg_queue *q, struct _mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->last) q->last->next = m;
 else {
  q->first = m;
  q->last = m;
 }
 q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}

variable_types:
m
struct _mq_message_t *

return_type: int

user_defined_types: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; }


original_code:
int mq_add_to_top(msg_queue_t *q, mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m->next = q->first;
 q->first = m;
 if (!q->last) q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}

canonical_original_code:
int mq_add_to_top(struct msg_queue *q, struct _mq_message_t *m)
{
 if ((!q) || (!m)) return -1;
 m->next = ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m->next = q->first;
 q->first = m;
 if (!q->last) q->last = m;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return 0;
}


original_code:
mq_message_t *pop_message(msg_queue_t *q)
{
 mq_message_t *m;
 if (!q) return ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 if (m) {
  if (q->first == q->last) {
   q->first = ((void *)0);
   q->last = ((void *)0);
  }
  else q->first = m->next;
  m->next = ((void *)0);
 }
 if (q->flags & 1) futex_release(&q->q_mutex);
 return m;
}

canonical_original_code:
struct _mq_message_t *pop_message(struct msg_queue *q)
{
 struct _mq_message_t *m;
 if (!q) return ((void *)0);
 if (q->flags & 1) futex_get(&q->q_mutex);
 m = q->first;
 if (m) {
  if (q->first == q->last) {
   q->first = ((void *)0);
   q->last = ((void *)0);
  }
  else q->first = m->next;
  m->next = ((void *)0);
 }
 if (q->flags & 1) futex_release(&q->q_mutex);
 return m;
}

variable_types: struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *

variable_types: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *


decompiled_code:
_BOOL8 __fastcall is_msg_queue_empty(__int64 a1)
{
_BOOL4 v1; // er12

if ( (*(_BYTE *)(a1 + 36) & 1) == 0 )
return *(_QWORD *)(a1 + 16) == 0LL;
futex_get((volatile signed __int32 *)(a1 + 32));
v1 = *(_QWORD *)(a1 + 16) == 0LL;
if ( (*(_BYTE *)(a1 + 36) & 1) == 0 )
return v1;
futex_release((volatile __int32 *)(a1 + 32));
return v1;
}

original_code:
int is_msg_queue_empty(msg_queue_t *q)
{
 int res = 1;
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->first) res = 0;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return res;
}

canonical_original_code:
int is_msg_queue_empty(struct msg_queue *q)
{
 int res = 1;
 if (q->flags & 1) futex_get(&q->q_mutex);
 if (q->first) res = 0;
 if (q->flags & 1) futex_release(&q->q_mutex);
 return res;
}

variable_types: res int


original_code:
int msg_queue_init_ex(msg_queue_t *q, int synchronize)
{
 if (synchronize) {
  futex_init(&q->q_mutex);
  q->flags = 1;
 }
 else q->flags = 0;
 q->first = ((void *)0);
 q->last = ((void *)0);
 return 0;
}

canonical_original_code:
int msg_queue_init_ex(struct msg_queue *q, int synchronize)
{
 if (synchronize) {
  futex_init(&q->q_mutex);
  q->flags = 1;
 }
 else q->flags = 0;
 q->first = ((void *)0);
 q->last = ((void *)0);
 return 0;
}

variable_types: synchronize int


decompiled_code:
__int64 __fastcall msg_queue_init(__int64 a1)
{
return msg_queue_init_ex(a1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func16(a1, 1);
}

original_code:
int msg_queue_init(msg_queue_t *q)
{
 return msg_queue_init_ex(q, 1);
}

canonical_original_code:
int msg_queue_init(struct msg_queue *q)
{
 return msg_queue_init_ex(q, 1);
}


decompiled_code:
void __fastcall msg_queue_destroy(__int64 a1)
{
msg_queue_destroy_and_free(a1, 0);
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1)
{
func11(a1, 0);
}

original_code:
void msg_queue_destroy(msg_queue_t *q)
{
 msg_queue_destroy_and_free(q, 0);
}

canonical_original_code:
void msg_queue_destroy(struct msg_queue *q)
{
 msg_queue_destroy_and_free(q, 0);
}

return_type: void


decompiled_code:
void __fastcall msg_queue_free(__int64 a1)
{
msg_queue_destroy_and_free(a1, 1);
}

canonical_decompiled_code:
void __fastcall func19(__int64 a1)
{
func11(a1, 1);
}

original_code:
void msg_queue_free(msg_queue_t *q)
{
 msg_queue_destroy_and_free(q, 1);
}

canonical_original_code:
void msg_queue_free(struct msg_queue *q)
{
 msg_queue_destroy_and_free(q, 1);
}


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

if ( a2 )
{
result = init_reference_counter(a2, a1);
*(_DWORD *)(a1 + 36) |= 2u;
}
else
{
*(_DWORD *)(a1 + 36) &= 0xFFFFFFFD;
}
return result;
}

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

if ( a2 )
{
result = init_reference_counter(a2, a1);
*(_DWORD *)(a1 + 36) |= 2u;
}
else
{
*(_DWORD *)(a1 + 36) &= 0xFFFFFFFD;
}
return result;
}

original_code:
void msg_queue_init_ref_cnt(msg_queue_t *q, reference_counter_group_t *grp)
{
 if (grp) {
  init_reference_counter(grp, &q->ref);
  q->flags |= 2;
 }
 else q->flags &= ~2;
}

canonical_original_code:
void msg_queue_init_ref_cnt(struct msg_queue *q, struct reference_counter_group_t *grp)
{
 if (grp) {
  init_reference_counter(grp, &q->ref);
  q->flags |= 2;
 }
 else q->flags &= ~2;
}

variable_types: struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *


decompiled_code:
__int64 __fastcall user2uid(__uid_t *a1, __gid_t *a2, const char *a3)
{
struct passwd *v4; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a3 )
return 0xFFFFFFFFLL;
*a1 = strtol(a3, &endptr, 10);
if ( !endptr || *endptr )
{
v4 = getpwnam(a3);
if ( !v4 )
return 0xFFFFFFFFLL;
*a1 = v4->pw_uid;
if ( a2 )
*a2 = v4->pw_gid;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__uid_t *a1, __gid_t *a2, const char *a3)
{
struct passwd *v4; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a3 )
return 0xFFFFFFFFLL;
*a1 = strtol(a3, &endptr, 10);
if ( !endptr || *endptr )
{
v4 = getpwnam(a3);
if ( !v4 )
return 0xFFFFFFFFLL;
*a1 = v4->pw_uid;
if ( a2 )
*a2 = v4->pw_gid;
}
return 0LL;
}

original_code:
int user2uid(int* uid, int* gid, char* user)
{
 char* tmp;
 struct passwd *pw_entry;
 if (user){
  *uid=strtol(user, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   pw_entry=getpwnam(user);
   if (pw_entry==0){
    goto error;
   }
   *uid=pw_entry->pw_uid;
   if (gid) *gid=pw_entry->pw_gid;
  }
  return 0;
 }
error:
 return -1;
}

canonical_original_code:
int user2uid(int *uid, int *gid, char *user)
{
 char *tmp;
 struct passwd *pw_entry;
 if (user){
  *uid=strtol(user, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   pw_entry=getpwnam(user);
   if (pw_entry==0){
    goto error;
   }
   *uid=pw_entry->pw_uid;
   if (gid) *gid=pw_entry->pw_gid;
  }
  return 0;
 }
error:
 return -1;
}

variable_types:
uid
int *

variable_types:
gid
int *

variable_types:
user
char *

variable_types:
tmp
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
__int64 __fastcall group2gid(__gid_t *a1, const char *a2)
{
__gid_t v2; // eax
char *v3; // rdx
unsigned int v4; // er8
struct group *v5; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
v2 = strtol(a2, &endptr, 10);
v3 = endptr;
*a1 = v2;
if ( !v3 || (v4 = 0, *v3) )
{
v5 = getgrnam(a2);
if ( v5 )
{
v4 = 0;
*a1 = v5->gr_gid;
}
else
{
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__gid_t *a1, const char *a2)
{
__gid_t v2; // eax
char *v3; // rdx
unsigned int v4; // er8
struct group *v5; // rax
char *endptr; // [rsp+0h] [rbp-20h] BYREF

if ( !a2 )
return 0xFFFFFFFFLL;
v2 = strtol(a2, &endptr, 10);
v3 = endptr;
*a1 = v2;
if ( !v3 || (v4 = 0, *v3) )
{
v5 = getgrnam(a2);
if ( v5 )
{
v4 = 0;
*a1 = v5->gr_gid;
}
else
{
v4 = -1;
}
}
return v4;
}

original_code:
int group2gid(int* gid, char* group)
{
 char* tmp;
 struct group *gr_entry;
 if (group){
  *gid=strtol(group, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   gr_entry=getgrnam(group);
   if (gr_entry==0){
    goto error;
   }
   *gid=gr_entry->gr_gid;
  }
  return 0;
 }
 error:
 return -1;
}

canonical_original_code:
int group2gid(int *gid, char *group)
{
 char *tmp;
 struct group *gr_entry;
 if (group){
  *gid=strtol(group, &tmp, 10);
  if ((tmp==0) ||(*tmp)){
   gr_entry=getgrnam(group);
   if (gr_entry==0){
    goto error;
   }
   *gid=gr_entry->gr_gid;
  }
  return 0;
 }
 error:
 return -1;
}

variable_types:
group
char *

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
time_t __fastcall local2utc(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = gmtime(&timer);
v1->tm_isdst = -1;
return mktime(v1);
}

canonical_decompiled_code:
time_t __fastcall func3(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = gmtime(&timer);
v1->tm_isdst = -1;
return mktime(v1);
}

original_code:
time_t local2utc(time_t in)
{
 struct tm* tt;
 tt = gmtime(&in);
 tt->tm_isdst = -1;
 return mktime(tt);
}

canonical_original_code:
long local2utc(long in)
{
 struct tm *tt;
 tt = gmtime(&in);
 tt->tm_isdst = -1;
 return mktime(tt);
}

variable_types: in long

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

return_type: long


decompiled_code:
time_t __fastcall utc2local(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = localtime(&timer);
return timegm(v1);
}

canonical_decompiled_code:
time_t __fastcall func4(time_t a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

timer = a1;
v1 = localtime(&timer);
return func2(v1);
}

original_code:
time_t utc2local(time_t in)
{
 struct tm* tt;
 tt = localtime(&in);
 return timegm(tt);
}

canonical_original_code:
long utc2local(long in)
{
 struct tm *tt;
 tt = localtime(&in);
 return timegm(tt);
}

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


decompiled_code:
__int64 __fastcall get_sys_version(_DWORD *a1, _DWORD *a2, unsigned int *a3)
{
int v5; // ebx
int v6; // esi
unsigned int v7; // eax
int v8; // er15
int v10; // eax
int v11; // er14
int v12; // esi
char *endptr; // [rsp+8h] [rbp-1D0h] BYREF
struct utsname name; // [rsp+10h] [rbp-1C8h] BYREF

memset(&name, 0, 0x180uLL);
*(_WORD *)&name.domainname[63] = 0;
*(_DWORD *)&name.domainname[59] = 0;
uname(&name);
v5 = strtol(name.release, &endptr, 10);
if ( *endptr == 46 )
{
++endptr;
v10 = strtol(endptr, &endptr, 10);
v11 = v10;
v8 = v10;
if ( *endptr == 46 )
{
++endptr;
v7 = strtol(endptr, &endptr, 10);
v6 = v11 << 8;
}
else
{
v12 = v10;
v7 = 0;
v6 = v12 << 8;
}
}
else
{
v6 = 0;
v7 = 0;
v8 = 0;
}
if ( a1 )
*a1 = v5;
if ( a2 )
*a2 = v8;
if ( a3 )
*a3 = v7;
return (v5 << 16) | v6 | v7;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _DWORD *a2, unsigned int *a3)
{
int v5; // ebx
int v6; // esi
unsigned int v7; // eax
int v8; // er15
int v10; // eax
int v11; // er14
int v12; // esi
char *endptr; // [rsp+8h] [rbp-1D0h] BYREF
struct utsname name; // [rsp+10h] [rbp-1C8h] BYREF

memset(&name, 0, 0x180uLL);
*(_WORD *)&name.domainname[63] = 0;
*(_DWORD *)&name.domainname[59] = 0;
uname(&name);
v5 = strtol(name.release, &endptr, 10);
if ( *endptr == 46 )
{
++endptr;
v10 = strtol(endptr, &endptr, 10);
v11 = v10;
v8 = v10;
if ( *endptr == 46 )
{
++endptr;
v7 = strtol(endptr, &endptr, 10);
v6 = v11 << 8;
}
else
{
v12 = v10;
v7 = 0;
v6 = v12 << 8;
}
}
else
{
v6 = 0;
v7 = 0;
v8 = 0;
}
if ( a1 )
*a1 = v5;
if ( a2 )
*a2 = v8;
if ( a3 )
*a3 = v7;
return (v5 << 16) | v6 | v7;
}

original_code:
unsigned int get_sys_version(int* major, int* minor, int* minor2)
{
 struct utsname un;
 int m1;
 int m2;
 int m3;
 char* p;
 memset (&un, 0, sizeof(un));
 m1=m2=m3=0;
 uname(&un);
 m1=strtol(un.release, &p, 10);
 if (*p=='.'){
  p++;
  m2=strtol(p, &p, 10);
  if (*p=='.'){
   p++;
   m3=strtol(p, &p, 10);
  }
 }
 if (major) *major=m1;
 if (minor) *minor=m2;
 if (minor2) *minor2=m3;
 return ((m1<<16)|(m2<<8)|(m3));
}

canonical_original_code:
unsigned int get_sys_version(int *major, int *minor, int *minor2)
{
 struct utsname un;
 int m1;
 int m2;
 int m3;
 char *p;
 memset (&un, 0, sizeof(un));
 m1=m2=m3=0;
 uname(&un);
 m1=strtol(un.release, &p, 10);
 if (*p=='.'){
  p++;
  m2=strtol(p, &p, 10);
  if (*p=='.'){
   p++;
   m3=strtol(p, &p, 10);
  }
 }
 if (major) *major=m1;
 if (minor) *minor=m2;
 if (minor2) *minor2=m3;
 return ((m1<<16)|(m2<<8)|(m3));
}

variable_types:
major
int *

variable_types:
minor
int *

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; }

variable_types:
p
char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall add_virtual_subscriptions_to_rlmi(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v4; // er15
_DWORD *v5; // r14
unsigned int v6; // ebp
int v7; // esi
unsigned int v8; // ebp
unsigned int v9; // eax
int v10; // [rsp+8h] [rbp-A0h]
const char *v11; // [rsp+8h] [rbp-A0h]
__int64 v12; // [rsp+10h] [rbp-98h]
int v13; // [rsp+20h] [rbp-88h]
char v15[16]; // [rsp+30h] [rbp-78h] BYREF
char v16[8]; // [rsp+40h] [rbp-68h] BYREF
int v17; // [rsp+48h] [rbp-60h]
char s[88]; // [rsp+50h] [rbp-58h] BYREF

result = *(unsigned int *)(a2 + 228);
v13 = result;
v12 = a2 + 224;
if ( (int)result > 0 )
{
v4 = 0;
do
{
while ( 2 )
{
result = ptr_vector_get(v12, v4);
v5 = (_DWORD *)result;
if ( result )
{
v6 = 0;
dstr_append_zt(a1, "\t<resource uri=\"");
dstr_append_str(a1, v5 + 38);
dstr_append_zt(a1, "\">\r\n");
v10 = v5[19];
if ( v10 > 0 )
{
v7 = v5[19] & 3;
if ( !v7 )
goto LABEL_70;
if ( v7 != 1 )
{
if ( v7 != 2 )
{
if ( !(unsigned int)vector_get(v5 + 18, 0LL, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
v6 = 1;
}
if ( !(unsigned int)vector_get(v5 + 18, v6, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
++v6;
}
if ( !(unsigned int)vector_get(v5 + 18, v6, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
if ( v10 != ++v6 )
{
LABEL_70:
do
{
if ( !(unsigned int)vector_get(v5 + 18, v6, v15) )
{
if ( v17 > 0 )
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
else
{
dstr_append_zt(a1, "\t\t<name>");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
v8 = v6 + 1;
if ( !(unsigned int)vector_get(v5 + 18, v8, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
if ( !(unsigned int)vector_get(v5 + 18, v8 + 1, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
if ( !(unsigned int)vector_get(v5 + 18, v8 + 2, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
v6 = v8 + 3;
}
while ( v10 != v6 );
}
}
sprintf(s, "vs%di%d", v4, 1LL);
dstr_append_zt(a1, "\t\t<instance id=\"");
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\" state=\"");
switch ( v5[36] )
{
case 0:
dstr_append_zt(a1, "pending\"");
if ( (int)get_debug_level("rls", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
process_no,
v9,
v11,
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
}
--dprint_crit;
}
goto LABEL_45;
case 1:
dstr_append_zt(a1, "active\"");
goto LABEL_45;
case 2:
dstr_append_zt(a1, "pending\"");
goto LABEL_45;
case 3:
case 5:
dstr_append_zt(a1, "terminated\" reason=\"closed\"");
goto LABEL_45;
case 4:
case 6:
dstr_append_zt(a1, "terminated\" reason=\"timeout\"");
if ( (int)v5[30] <= 0 )
goto LABEL_50;
goto LABEL_46;
default:
LABEL_45:
if ( (int)v5[30] <= 0 )
{
LABEL_50:
dstr_append_zt(a1, "/>\r\n");
}
else
{
LABEL_46:
sprintf(s, "%d", v4);
dstr_append_zt(a1, " cid=\"");
dstr_append_zt(a1, a3);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\"/>\r\n");
}
++v4;
result = dstr_append_zt(a1, "\t</resource>\r\n");
if ( v13 == v4 )
return result;
continue;
}
}
break;
}
++v4;
}
while ( v13 != v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v4; // er15
_DWORD *v5; // r14
unsigned int v6; // ebp
int v7; // esi
unsigned int v8; // ebp
unsigned int v9; // eax
int v10; // [rsp+8h] [rbp-A0h]
const char *v11; // [rsp+8h] [rbp-A0h]
__int64 v12; // [rsp+10h] [rbp-98h]
int v13; // [rsp+20h] [rbp-88h]
char v15[16]; // [rsp+30h] [rbp-78h] BYREF
char v16[8]; // [rsp+40h] [rbp-68h] BYREF
int v17; // [rsp+48h] [rbp-60h]
char s[88]; // [rsp+50h] [rbp-58h] BYREF

result = *(unsigned int *)(a2 + 228);
v13 = result;
v12 = a2 + 224;
if ( (int)result > 0 )
{
v4 = 0;
do
{
while ( 2 )
{
result = ptr_vector_get(v12, v4);
v5 = (_DWORD *)result;
if ( result )
{
v6 = 0;
dstr_append_zt(a1, "\t<resource uri=\"");
dstr_append_str(a1, v5 + 38);
dstr_append_zt(a1, "\">\r\n");
v10 = v5[19];
if ( v10 > 0 )
{
v7 = v5[19] & 3;
if ( !v7 )
goto LABEL_70;
if ( v7 != 1 )
{
if ( v7 != 2 )
{
if ( !(unsigned int)vector_get(v5 + 18, 0LL, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
v6 = 1;
}
if ( !(unsigned int)vector_get(v5 + 18, v6, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
++v6;
}
if ( !(unsigned int)vector_get(v5 + 18, v6, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
if ( v10 != ++v6 )
{
LABEL_70:
do
{
if ( !(unsigned int)vector_get(v5 + 18, v6, v15) )
{
if ( v17 > 0 )
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
else
{
dstr_append_zt(a1, "\t\t<name>");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
v8 = v6 + 1;
if ( !(unsigned int)vector_get(v5 + 18, v8, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
if ( !(unsigned int)vector_get(v5 + 18, v8 + 1, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
if ( !(unsigned int)vector_get(v5 + 18, v8 + 2, v15) )
{
if ( v17 <= 0 )
{
dstr_append_zt(a1, "\t\t<name>");
}
else
{
dstr_append_zt(a1, "\t\t<name language=\"");
dstr_append_str(a1, v16);
dstr_append_zt(a1, "\">");
}
dstr_append_str(a1, v15);
dstr_append_zt(a1, "</name>\r\n");
}
v6 = v8 + 3;
}
while ( v10 != v6 );
}
}
sprintf(s, "vs%di%d", v4, 1LL);
dstr_append_zt(a1, "\t\t<instance id=\"");
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\" state=\"");
switch ( v5[36] )
{
case 0:
dstr_append_zt(a1, "pending\"");
if ( (int)get_debug_level("rls", 3LL) >= -1 && !dprint_crit )
{
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v11 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
fprintf(
stderr,
"%2d(%d) %s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
process_no,
v9,
v11,
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
if ( log_color )
dprint_color_reset();
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): generating RLMI for an unitialized virtual subscription!\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:67]: ",
"add_virtual_subscriptions_to_rlmi");
}
--dprint_crit;
}
goto LABEL_45;
case 1:
dstr_append_zt(a1, "active\"");
goto LABEL_45;
case 2:
dstr_append_zt(a1, "pending\"");
goto LABEL_45;
case 3:
case 5:
dstr_append_zt(a1, "terminated\" reason=\"closed\"");
goto LABEL_45;
case 4:
case 6:
dstr_append_zt(a1, "terminated\" reason=\"timeout\"");
if ( (int)v5[30] <= 0 )
goto LABEL_50;
goto LABEL_46;
default:
LABEL_45:
if ( (int)v5[30] <= 0 )
{
LABEL_50:
dstr_append_zt(a1, "/>\r\n");
}
else
{
LABEL_46:
sprintf(s, "%d", v4);
dstr_append_zt(a1, " cid=\"");
dstr_append_zt(a1, a3);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\"/>\r\n");
}
++v4;
result = dstr_append_zt(a1, "\t</resource>\r\n");
if ( v13 == v4 )
return result;
continue;
}
}
break;
}
++v4;
}
while ( v13 != v4 );
}
return result;
}

original_code:
static void add_virtual_subscriptions_to_rlmi(dstring_t *doc, rl_subscription_t *s, const char *part_id)
{
 int i, j, ncnt, cnt;
 virtual_subscription_t *vs;
 vs_display_name_t dn;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  dstr_append_zt(doc, "\t<resource uri=\"");
  dstr_append_str(doc, &vs->uri);
  dstr_append_zt(doc, "\">\r\n");
  ncnt = (&vs->display_names)->element_count;
  for (j = 0; j < ncnt; j++) {
   if (vector_get(&vs->display_names, j, &dn) != 0) continue;
   if (dn.lang.len > 0) {
    dstr_append_zt(doc, "\t\t<name language=\"");
    dstr_append_str(doc, &dn.lang);
    dstr_append_zt(doc, "\">");
   }
   else dstr_append_zt(doc, "\t\t<name>");
   dstr_append_str(doc, &dn.name);
   dstr_append_zt(doc, "</name>\r\n");
  }
  sprintf(tmp, "vs%di%d", i, 1);
  dstr_append_zt(doc, "\t\t<instance id=\"");
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\" state=\"");
  switch (vs->status) {
   case subscription_active:
     dstr_append_zt(doc, "active\"");
     break;
   case subscription_pending:
     dstr_append_zt(doc, "pending\"");
     break;
   case subscription_terminated_pending:
   case subscription_terminated:
     dstr_append_zt(doc, "terminated\" reason=\"closed\"");
     break;
   case subscription_terminated_pending_to:
   case subscription_terminated_to:
     dstr_append_zt(doc,
      "terminated\" reason=\"timeout\"");
     break;
   case subscription_uninitialized:
     dstr_append_zt(doc, "pending\"");
     do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
     break;
  }
  if (vs->state_document.len > 0) {
   sprintf(tmp, "%d", i);
   dstr_append_zt(doc, " cid=\"");
   dstr_append_zt(doc, part_id);
   dstr_append_zt(doc, tmp);
   dstr_append_zt(doc, "\"/>\r\n");
  }
  else dstr_append_zt(doc, "/>\r\n");
  dstr_append_zt(doc, "\t</resource>\r\n");
 }
}

canonical_original_code:
static void add_virtual_subscriptions_to_rlmi(struct _dstring_t *doc, struct _rl_subscription_t *s, char *part_id)
{
 int i; int j; int ncnt; int cnt;
 struct _virtual_subscription_t *vs;
 struct vs_display_name_t dn;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  dstr_append_zt(doc, "\t<resource uri=\"");
  dstr_append_str(doc, &vs->uri);
  dstr_append_zt(doc, "\">\r\n");
  ncnt = (&vs->display_names)->element_count;
  for (j = 0; j < ncnt; j++) {
   if (vector_get(&vs->display_names, j, &dn) != 0) continue;
   if (dn.lang.len > 0) {
    dstr_append_zt(doc, "\t\t<name language=\"");
    dstr_append_str(doc, &dn.lang);
    dstr_append_zt(doc, "\">");
   }
   else dstr_append_zt(doc, "\t\t<name>");
   dstr_append_str(doc, &dn.name);
   dstr_append_zt(doc, "</name>\r\n");
  }
  sprintf(tmp, "vs%di%d", i, 1);
  dstr_append_zt(doc, "\t\t<instance id=\"");
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\" state=\"");
  switch (vs->status) {
   case subscription_active:
     dstr_append_zt(doc, "active\"");
     break;
   case subscription_pending:
     dstr_append_zt(doc, "pending\"");
     break;
   case subscription_terminated_pending:
   case subscription_terminated:
     dstr_append_zt(doc, "terminated\" reason=\"closed\"");
     break;
   case subscription_terminated_pending_to:
   case subscription_terminated_to:
     dstr_append_zt(doc,
      "terminated\" reason=\"timeout\"");
     break;
   case subscription_uninitialized:
     dstr_append_zt(doc, "pending\"");
     do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "generating RLMI for an unitialized virtual subscription!\n", ("rls" " [" "rlmi_doc.c" ":" "67" "]: ") , __func__); } } (dprint_crit--); } } while(0);
     break;
  }
  if (vs->state_document.len > 0) {
   sprintf(tmp, "%d", i);
   dstr_append_zt(doc, " cid=\"");
   dstr_append_zt(doc, part_id);
   dstr_append_zt(doc, tmp);
   dstr_append_zt(doc, "\"/>\r\n");
  }
  else dstr_append_zt(doc, "/>\r\n");
  dstr_append_zt(doc, "\t</resource>\r\n");
 }
}

variable_types: struct _dstring_t { struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; } *first; struct _dstr_buff_t *last; int len; int buff_size; int error; } *

variable_types: struct _rl_subscription_t { enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 } type; struct xcap_query_params_t { struct _str { char *s; int len; } xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } xcap_params; union { struct _subscription_data_t { struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; } expiration; struct dlg { struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; } id; struct dlg_seq { unsigned int value; unsigned char is_set; } loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 } state; struct rr { struct name_addr { struct _str name; struct _str uri; int len; } nameaddr; struct param { enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 } type; struct _str name; struct _str body; int len; struct param *next; } *r2; struct param *params; int len; struct rr *next; } *route_set; struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; } hooks; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *send_sock; } *dialog; void *usr_data; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; } external; struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t { struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; } *first_param; void *subscriber_data; } local_subscription_pres_data; struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t { struct _str name; struct _notifier_domain_t { struct atomic_t mutex; struct atomic_t data_mutex; struct _str name; struct _notifier_package_t *first_package; struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; } *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *rc_grp; } *domain; struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; } display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; } *vs; } internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; } *

variable_types: i int

variable_types: j int

variable_types: ncnt int

variable_types: cnt int

variable_types: struct _virtual_subscription_t { struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *dst; struct _str { char *s; int len; } record_id; struct _str subscriber_id; struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; } *first_param; void *subscriber_data; } local_subscription_pres_data; struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t { struct _str name; struct _notifier_domain_t { struct atomic_t mutex; struct atomic_t data_mutex; struct _str name; struct _notifier_package_t *first_package; struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; } *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *rc_grp; } *domain; struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *local_subscription_pres; struct _rl_subscription_t { enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 } type; struct xcap_query_params_t { struct _str xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } xcap_params; union { struct _subscription_data_t { struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; } expiration; struct dlg { struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; } id; struct dlg_seq { unsigned int value; unsigned char is_set; } loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 } state; struct rr { struct name_addr { struct _str name; struct _str uri; int len; } nameaddr; struct param { enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 } type; struct _str name; struct _str body; int len; struct param *next; } *r2; struct param *params; int len; struct rr *next; } *route_set; struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; } hooks; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *send_sock; } *dialog; void *usr_data; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; } external; struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t *vs; } internal; } u; int doc_version; int changed; struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; } vs; struct _str from_uid; char dbid[48]; } *local_subscription_list; struct vector_t display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; } *

variable_types: struct vs_display_name_t { struct _str { char *s; int len; } name; struct _str lang; }

variable_types:
tmp
char [32]

user_defined_types: struct vs_display_name_t { struct _str name; struct _str lang; }

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: struct _rl_subscription_t { enum rls_subscription_type_t type; struct xcap_query_params_t xcap_params; union { struct _subscription_data_t external; struct internal_subscription_data_t internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; }

user_defined_types: struct _virtual_subscription_t { struct _qsa_subscription_data_t local_subscription_pres_data; struct _qsa_subscription_t *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; }

user_defined_types: struct cfg_group_core { int debug; int log_facility; int memdbg; int use_dst_blacklist; unsigned int blst_timeout; unsigned int blst_max_mem; unsigned int blst_udp_imask; unsigned int blst_tcp_imask; unsigned int blst_tls_imask; unsigned int blst_sctp_imask; int dns_try_ipv6; int dns_try_naptr; int dns_udp_pref; int dns_tcp_pref; int dns_tls_pref; int dns_sctp_pref; int dns_retr_time; int dns_retr_no; int dns_servers_no; int dns_search_list; int dns_search_fmatch; int dns_reinit; int use_dns_cache; int dns_cache_flags; int use_dns_failover; int dns_srv_lb; unsigned int dns_neg_cache_ttl; unsigned int dns_cache_min_ttl; unsigned int dns_cache_max_ttl; unsigned int dns_cache_max_mem; int dns_cache_del_nonexp; int dns_cache_rec_pref; int mem_dump_pkg; int mem_dump_shm; int max_while_loops; int udp_mtu; int udp_mtu_try_proto; int udp4_raw; int udp4_raw_mtu; int udp4_raw_ttl; int force_rport; int memlog; int mem_summary; int mem_safety; int mem_join; int corelog; int latency_log; int latency_limit_db; int latency_limit_action; }

user_defined_types: struct _qsa_subscription_data_t { struct msg_queue *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t *first_param; void *subscriber_data; }

user_defined_types: struct _subscription_data_t { struct _time_event_data_t expiration; struct dlg *dialog; void *usr_data; enum subscription_status_t status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; }

user_defined_types: struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; }

user_defined_types: struct dlg { struct dlg_id id; struct dlg_seq loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state state; struct rr *route_set; struct dlg_hooks hooks; struct socket_info *send_sock; }

user_defined_types: struct _notifier_package_t { struct _str name; struct _notifier_domain_t *domain; struct _notifier_t *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; }

user_defined_types: struct rr { struct name_addr nameaddr; struct param *r2; struct param *params; int len; struct rr *next; }

user_defined_types: struct socket_info { int socket; struct _str name; struct ip_addr address; struct _str address_str; struct _str port_no_str; enum si_flags flags; union sockaddr_union su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info useinfo; }

user_defined_types: struct _notifier_domain_t { struct atomic_t mutex; struct atomic_t data_mutex; struct _str name; struct _notifier_package_t *first_package; struct _qsa_content_type_t *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t *rc_grp; }

user_defined_types: union sockaddr_union { struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; }

user_defined_types: struct param { enum ptype type; struct _str name; struct _str body; int len; struct param *next; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; }


decompiled_code:
void __fastcall add_virtual_subscriptions_documents(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er12
unsigned int i; // er14
__int64 v7; // rax
__int64 v8; // r15
unsigned int v9; // eax
struct _IO_FILE *v10; // rdi
const char *v13; // [rsp+18h] [rbp-60h]
char s[88]; // [rsp+20h] [rbp-58h] BYREF

v4 = *(_DWORD *)(a2 + 228);
if ( v4 > 0 )
{
for ( i = 0; v4 != i; ++i )
{
while ( 1 )
{
v7 = ptr_vector_get(a2 + 224, i);
v8 = v7;
if ( !v7 || *(int *)(v7 + 120) <= 0 )
goto LABEL_4;
if ( *(int *)(v7 + 136) <= 0 )
break;
dstr_append(a1, "--", 2LL);
dstr_append_zt(a1, a3);
dstr_append(a1, "\r\n", 2LL);
sprintf(s, "%d", i);
dstr_append_zt(a1, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(a1, a4);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\r\nContent-Type: ");
dstr_append_str(a1, v8 + 128);
dstr_append_zt(a1, "\r\n\r\n");
dstr_append_str(a1, v8 + 112);
dstr_append(a1, "\r\n", 2LL);
dstr_append(a1, "\r\n", 2LL);
LABEL_4:
if ( v4 == ++i )
return;
}
if ( (int)get_debug_level("rls", 3LL) < -1 || dprint_crit )
goto LABEL_4;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
v10 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't send resource status document for unknown type\n",
process_no,
v9,
v13,
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
if ( log_color )
((void (__fastcall *)(struct _IO_FILE *, const char *))dprint_color_reset)(
v10,
"%2d(%d) %s: %s%s(): can't send resource status document for unknown type\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't send resource status document for unknown type\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
}
--dprint_crit;
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er12
unsigned int i; // er14
__int64 v7; // rax
__int64 v8; // r15
unsigned int v9; // eax
struct _IO_FILE *v10; // rdi
const char *v13; // [rsp+18h] [rbp-60h]
char s[88]; // [rsp+20h] [rbp-58h] BYREF

v4 = *(_DWORD *)(a2 + 228);
if ( v4 > 0 )
{
for ( i = 0; v4 != i; ++i )
{
while ( 1 )
{
v7 = ptr_vector_get(a2 + 224, i);
v8 = v7;
if ( !v7 || *(int *)(v7 + 120) <= 0 )
goto LABEL_4;
if ( *(int *)(v7 + 136) <= 0 )
break;
dstr_append(a1, "--", 2LL);
dstr_append_zt(a1, a3);
dstr_append(a1, "\r\n", 2LL);
sprintf(s, "%d", i);
dstr_append_zt(a1, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(a1, a4);
dstr_append_zt(a1, s);
dstr_append_zt(a1, "\r\nContent-Type: ");
dstr_append_str(a1, v8 + 128);
dstr_append_zt(a1, "\r\n\r\n");
dstr_append_str(a1, v8 + 112);
dstr_append(a1, "\r\n", 2LL);
dstr_append(a1, "\r\n", 2LL);
LABEL_4:
if ( v4 == ++i )
return;
}
if ( (int)get_debug_level("rls", 3LL) < -1 || dprint_crit )
goto LABEL_4;
++dprint_crit;
if ( log_stderr )
{
if ( log_color )
dprint_color(0xFFFFFFFFLL);
v13 = (const char *)*((_QWORD *)&log_level_info + 8);
v9 = my_pid();
v10 = stderr;
fprintf(
stderr,
"%2d(%d) %s: %s%s(): can't send resource status document for unknown type\n",
process_no,
v9,
v13,
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
if ( log_color )
((void (__fastcall *)(struct _IO_FILE *, const char *))dprint_color_reset)(
v10,
"%2d(%d) %s: %s%s(): can't send resource status document for unknown type\n");
}
else
{
syslog(
*((_DWORD *)&log_level_info + 18) | *(_DWORD *)(core_cfg + 4LL),
"%s: %s%s(): can't send resource status document for unknown type\n",
*((const char **)&log_level_info + 8),
"rls [rlmi_doc.c:102]: ",
"add_virtual_subscriptions_documents");
}
--dprint_crit;
}
}
}

original_code:
static void add_virtual_subscriptions_documents(dstring_t *doc,
  rl_subscription_t *s, const char *boundary_str, const char *part_id)
{
 int i, cnt;
 virtual_subscription_t *vs;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  if (vs->state_document.len < 1) {
   vs = vs->next;
   continue;
  }
  if (vs->content_type.len < 1) {
   do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't send resource status document for unknown type\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   vs = vs->next;
   continue;
  }
  dstr_append(doc, "--", 2);
  dstr_append_zt(doc, boundary_str);
  dstr_append(doc, "\r\n", 2);
  sprintf(tmp, "%d", i);
  dstr_append_zt(doc, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
  dstr_append_zt(doc, part_id);
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\r\nContent-Type: ");
  dstr_append_str(doc, &vs->content_type);
  dstr_append_zt(doc, "\r\n\r\n");
  dstr_append_str(doc, &vs->state_document);
  dstr_append(doc, "\r\n", 2);
  dstr_append(doc, "\r\n", 2);
 }
}

canonical_original_code:
static void add_virtual_subscriptions_documents(struct _dstring_t *doc, struct _rl_subscription_t *s, char *boundary_str, char *part_id)
{
 int i; int cnt;
 struct _virtual_subscription_t *vs;
 char tmp[32];
 cnt = (&s->vs)->element_count;
 for (i = 0; i < cnt; i++) {
  vs = ptr_vector_get(&s->vs, i);
  if (!vs) continue;
  if (vs->state_document.len < 1) {
   vs = vs->next;
   continue;
  }
  if (vs->content_type.len < 1) {
   do { if (get_debug_level("rls", (sizeof("rls")-1)) >= ((-1)) && (dprint_crit==0)) { (dprint_crit++); if (__builtin_expect(!!((((-1)) >= -5) && (((-1)) <= 3)), 1)){ if (__builtin_expect(!!(log_stderr), 0)) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s: %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { syslog((log_level_info[((-1)) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s: %s" "%s(): " "can't send resource status document for unknown type\n", (log_level_info[((-1)) - (-5)].name), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } else { if (log_stderr) { if (__builtin_expect(!!(log_color), 0)) dprint_color((-1)); fprintf(stderr, "%2d(%d) %s" "%s(): " "can't send resource status document for unknown type\n", process_no, my_pid(), ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); if (__builtin_expect(!!(log_color), 0)) dprint_color_reset(); } else { if (((-1))<-5) syslog((log_level_info[(-5) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); else syslog((log_level_info[(3) - (-5)].syslog_level) | (((0) != 0) ? (0) : ((struct cfg_group_core *)core_cfg)->log_facility), "%s" "%s(): " "can't send resource status document for unknown type\n", ("rls" " [" "rlmi_doc.c" ":" "102" "]: ") , __func__); } } (dprint_crit--); } } while(0);
   vs = vs->next;
   continue;
  }
  dstr_append(doc, "--", 2);
  dstr_append_zt(doc, boundary_str);
  dstr_append(doc, "\r\n", 2);
  sprintf(tmp, "%d", i);
  dstr_append_zt(doc, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
  dstr_append_zt(doc, part_id);
  dstr_append_zt(doc, tmp);
  dstr_append_zt(doc, "\r\nContent-Type: ");
  dstr_append_str(doc, &vs->content_type);
  dstr_append_zt(doc, "\r\n\r\n");
  dstr_append_str(doc, &vs->state_document);
  dstr_append(doc, "\r\n", 2);
  dstr_append(doc, "\r\n", 2);
 }
}

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 }

user_defined_types: struct xcap_query_params_t { struct _str xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; }

user_defined_types: enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 }

user_defined_types: struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; }

user_defined_types: struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t *vs; }

user_defined_types: struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; }

user_defined_types: struct msg_queue { struct reference_counter_data_t ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; }

user_defined_types: struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; }

user_defined_types: struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; }

user_defined_types: struct reference_counter_data_t { int cntr; struct atomic_t *mutex; }

user_defined_types: struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; }

user_defined_types: struct dlg_seq { unsigned int value; unsigned char is_set; }

user_defined_types: enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 }

user_defined_types: struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; }

user_defined_types: struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; }

user_defined_types: struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; }

user_defined_types: struct name_addr { struct _str name; struct _str uri; int len; }

user_defined_types: struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; }

user_defined_types: enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 }

user_defined_types: struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; }

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

user_defined_types: struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; }

user_defined_types: struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; }

user_defined_types: enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall create_rlmi_document(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12
unsigned int v5; // eax
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v8; // ebp
unsigned int v9; // eax
__int64 v10; // rax
char v12[32]; // [rsp+10h] [rbp-158h] BYREF
char v13[32]; // [rsp+30h] [rbp-138h] BYREF
char v14[32]; // [rsp+50h] [rbp-118h] BYREF
char s[64]; // [rsp+70h] [rbp-F8h] BYREF
char v16[64]; // [rsp+B0h] [rbp-B8h] BYREF
char v17[120]; // [rsp+F0h] [rbp-78h] BYREF

if ( a2 == 0 || a1 == 0 || !a3 )
return 0xFFFFFFFFLL;
v4 = rand();
v5 = rand();
sprintf(s, "qwW%dpPdxX%d", v5, v4);
v6 = rand();
v7 = rand();
sprintf(v16, "RewXdpxR%dxA%d", v7, v6);
v8 = rand();
v9 = rand();
sprintf(v17, "id%di%dx", v9, v8);
dstr_init(v12, 256LL);
dstr_append(v12, "--", 2LL);
dstr_append_zt(v12, v16);
dstr_append(v12, "\r\n", 2LL);
dstr_append_zt(v12, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(v12, s);
dstr_append_zt(v12, "\r\n");
dstr_append_zt(v12, "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
dstr_append(v12, "\r\n", 2LL);
dstr_append_zt(v12, "<?xml version=\"1.0\"?>\r\n<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" uri=\"");
v10 = rls_get_uri(a3);
dstr_append_str(v12, v10);
dstr_append_zt(v12, "\" version=\"");
sprintf(v14, "%d", *(unsigned int *)(a3 + 216));
dstr_append_zt(v12, v14);
dstr_append_zt(v12, "\" fullState=\"true\">\r\n");
add_virtual_subscriptions_to_rlmi((__int64)v12, a3, (__int64)v17);
dstr_append_zt(v12, "</list>\r\n\r\n");
add_virtual_subscriptions_documents((__int64)v12, a3, (__int64)v16, (__int64)v17);
dstr_append(v12, "--", 2LL);
dstr_append_zt(v12, v16);
dstr_append(v12, "--\r\n", 4LL);
dstr_append(v12, "\r\n", 2LL);
dstr_init(v13, 256LL);
dstr_append_zt(v13, "multipart/related;type=\"application/rlmi+xml\";start=\"");
dstr_append_zt(v13, s);
dstr_append_zt(v13, "\";boundary=\"");
dstr_append_zt(v13, v16);
dstr_append_zt(v13, "\";");
dstr_get_str(v12, a1);
dstr_destroy(v12);
dstr_get_str(v13, a2);
dstr_destroy(v13);
++*(_DWORD *)(a3 + 216);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // er12
unsigned int v5; // eax
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v8; // ebp
unsigned int v9; // eax
__int64 v10; // rax
char v12[32]; // [rsp+10h] [rbp-158h] BYREF
char v13[32]; // [rsp+30h] [rbp-138h] BYREF
char v14[32]; // [rsp+50h] [rbp-118h] BYREF
char s[64]; // [rsp+70h] [rbp-F8h] BYREF
char v16[64]; // [rsp+B0h] [rbp-B8h] BYREF
char v17[120]; // [rsp+F0h] [rbp-78h] BYREF

if ( a2 == 0 || a1 == 0 || !a3 )
return 0xFFFFFFFFLL;
v4 = rand();
v5 = rand();
sprintf(s, "qwW%dpPdxX%d", v5, v4);
v6 = rand();
v7 = rand();
sprintf(v16, "RewXdpxR%dxA%d", v7, v6);
v8 = rand();
v9 = rand();
sprintf(v17, "id%di%dx", v9, v8);
dstr_init(v12, 256LL);
dstr_append(v12, "--", 2LL);
dstr_append_zt(v12, v16);
dstr_append(v12, "\r\n", 2LL);
dstr_append_zt(v12, "Content-Transfer-Encoding: binary\r\nContent-ID: ");
dstr_append_zt(v12, s);
dstr_append_zt(v12, "\r\n");
dstr_append_zt(v12, "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
dstr_append(v12, "\r\n", 2LL);
dstr_append_zt(v12, "<?xml version=\"1.0\"?>\r\n<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" uri=\"");
v10 = rls_get_uri(a3);
dstr_append_str(v12, v10);
dstr_append_zt(v12, "\" version=\"");
sprintf(v14, "%d", *(unsigned int *)(a3 + 216));
dstr_append_zt(v12, v14);
dstr_append_zt(v12, "\" fullState=\"true\">\r\n");
func0((__int64)v12, a3, (__int64)v17);
dstr_append_zt(v12, "</list>\r\n\r\n");
func1((__int64)v12, a3, (__int64)v16, (__int64)v17);
dstr_append(v12, "--", 2LL);
dstr_append_zt(v12, v16);
dstr_append(v12, "--\r\n", 4LL);
dstr_append(v12, "\r\n", 2LL);
dstr_init(v13, 256LL);
dstr_append_zt(v13, "multipart/related;type=\"application/rlmi+xml\";start=\"");
dstr_append_zt(v13, s);
dstr_append_zt(v13, "\";boundary=\"");
dstr_append_zt(v13, v16);
dstr_append_zt(v13, "\";");
dstr_get_str(v12, a1);
dstr_destroy(v12);
dstr_get_str(v13, a2);
dstr_destroy(v13);
++*(_DWORD *)(a3 + 216);
return 0LL;
}

original_code:
int create_rlmi_document(str *dst, str *content_type_dst, rl_subscription_t *s, int full_info)
{
 dstring_t doc, cont;
 char tmp[32];
 char start_str[64];
 char boundary_str[64];
 char part_id[64];
 if ((!s) || (!dst) || (!content_type_dst)) return (-1);
 sprintf(start_str, "qwW%dpPdxX%d", rand(), rand());
 sprintf(boundary_str, "RewXdpxR%dxA%d", rand(), rand());
 sprintf(part_id, "id%di%dx", rand(), rand());
 dstr_init(&doc, 256);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
   "Content-Transfer-Encoding: binary\r\n"
   "Content-ID: ");
 dstr_append_zt(&doc, start_str);
 dstr_append_zt(&doc, "\r\n");
 dstr_append_zt(&doc,
  "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
  "<?xml version=\"1.0\"?>\r\n"
  "<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" "
  "uri=\"");
 dstr_append_str(&doc, rls_get_uri(s));
 dstr_append_zt(&doc, "\" version=\"");
 sprintf(tmp, "%d", s->doc_version);
 dstr_append_zt(&doc, tmp);
 dstr_append_zt(&doc, "\" fullState=\"true\">\r\n");
 add_virtual_subscriptions_to_rlmi(&doc, s, part_id);
 dstr_append_zt(&doc, "</list>\r\n\r\n");
 add_virtual_subscriptions_documents(&doc, s, boundary_str, part_id);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "--\r\n", 4);
 dstr_append(&doc, "\r\n", 2);
 dstr_init(&cont, 256);
 dstr_append_zt(&cont,
   "multipart/related;type=\"application/rlmi+xml\";"
   "start=\"");
 dstr_append_zt(&cont, start_str);
 dstr_append_zt(&cont, "\";boundary=\"");
 dstr_append_zt(&cont, boundary_str);
 dstr_append_zt(&cont, "\";");
 dstr_get_str(&doc, dst);
 dstr_destroy(&doc);
 dstr_get_str(&cont, content_type_dst);
 dstr_destroy(&cont);
 s->doc_version++;
 return 0;
}

canonical_original_code:
int create_rlmi_document(struct _str *dst, struct _str *content_type_dst, struct _rl_subscription_t *s, int full_info)
{
 struct _dstring_t doc; struct _dstring_t cont;
 char tmp[32];
 char start_str[64];
 char boundary_str[64];
 char part_id[64];
 if ((!s) || (!dst) || (!content_type_dst)) return (-1);
 sprintf(start_str, "qwW%dpPdxX%d", rand(), rand());
 sprintf(boundary_str, "RewXdpxR%dxA%d", rand(), rand());
 sprintf(part_id, "id%di%dx", rand(), rand());
 dstr_init(&doc, 256);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
   "Content-Transfer-Encoding: binary\r\n"
   "Content-ID: ");
 dstr_append_zt(&doc, start_str);
 dstr_append_zt(&doc, "\r\n");
 dstr_append_zt(&doc,
  "Content-Type: application/rlmi+xml;charset=\"UTF-8\"\r\n");
 dstr_append(&doc, "\r\n", 2);
 dstr_append_zt(&doc,
  "<?xml version=\"1.0\"?>\r\n"
  "<list xmlns=\"urn:ietf:params:xml:ns:rlmi\" "
  "uri=\"");
 dstr_append_str(&doc, rls_get_uri(s));
 dstr_append_zt(&doc, "\" version=\"");
 sprintf(tmp, "%d", s->doc_version);
 dstr_append_zt(&doc, tmp);
 dstr_append_zt(&doc, "\" fullState=\"true\">\r\n");
 add_virtual_subscriptions_to_rlmi(&doc, s, part_id);
 dstr_append_zt(&doc, "</list>\r\n\r\n");
 add_virtual_subscriptions_documents(&doc, s, boundary_str, part_id);
 dstr_append(&doc, "--", 2);
 dstr_append_zt(&doc, boundary_str);
 dstr_append(&doc, "--\r\n", 4);
 dstr_append(&doc, "\r\n", 2);
 dstr_init(&cont, 256);
 dstr_append_zt(&cont,
   "multipart/related;type=\"application/rlmi+xml\";"
   "start=\"");
 dstr_append_zt(&cont, start_str);
 dstr_append_zt(&cont, "\";boundary=\"");
 dstr_append_zt(&cont, boundary_str);
 dstr_append_zt(&cont, "\";");
 dstr_get_str(&doc, dst);
 dstr_destroy(&doc);
 dstr_get_str(&cont, content_type_dst);
 dstr_destroy(&cont);
 s->doc_version++;
 return 0;
}

variable_types:
dst
struct _str { char *s; int len; } *

variable_types: struct _rl_subscription_t { enum rls_subscription_type_t { rls_internal_subscription=0, rls_external_subscription=1 } type; struct xcap_query_params_t { struct _str xcap_root; struct _str auth_user; struct _str auth_pass; int enable_unverified_ssl_peer; } xcap_params; union { struct _subscription_data_t { struct _time_event_data_t { unsigned int tick_time; void (*cb)(struct _time_event_data_t *s); void *cb_param; void *cb_param1; struct _time_event_data_t *next; struct _time_event_data_t *prev; } expiration; struct dlg { struct dlg_id { struct _str call_id; struct _str rem_tag; struct _str loc_tag; } id; struct dlg_seq { unsigned int value; unsigned char is_set; } loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state { DLG_NEW=0, DLG_EARLY=1, DLG_CONFIRMED=2, DLG_DESTROYED=3 } state; struct rr { struct name_addr { struct _str name; struct _str uri; int len; } nameaddr; struct param { enum ptype { P_OTHER=0, P_Q=1, P_EXPIRES=2, P_METHODS=3, P_RECEIVED=4, P_TRANSPORT=5, P_LR=6, P_R2=7, P_MADDR=8, P_TTL=9, P_DSTIP=10, P_DSTPORT=11, P_INSTANCE=12, P_REG_ID=13, P_FTAG=14, P_CALL_ID=15, P_FROM_TAG=16, P_TO_TAG=17, P_ISD=18, P_SLA=19, P_MA=20, P_OB=21 } type; struct _str name; struct _str body; int len; struct param *next; } *r2; struct param *params; int len; struct rr *next; } *route_set; struct dlg_hooks { struct _str ru; struct _str nh; struct _str *request_uri; struct _str *next_hop; struct rr *first_route; struct _str *last_route; } hooks; struct socket_info { int socket; struct _str name; struct ip_addr { unsigned int af; unsigned int len; union { unsigned long addrl[-1]; unsigned int addr32[4]; unsigned short addr16[8]; unsigned char addr[16]; } u; } address; struct _str address_str; struct _str port_no_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } s; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } sin6; } su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags { SI_NONE=0, SI_IS_IP=1, SI_IS_LO=2, SI_IS_MCAST=4, SI_IS_ANY=8, SI_IS_MHOMED=16 } flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; } *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info { struct _str name; unsigned short port_no; struct _str port_no_str; struct _str address_str; struct ip_addr address; struct _str sock_str; } useinfo; } *send_sock; } *dialog; void *usr_data; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; } external; struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t { struct _qsa_subscription_data_t { struct msg_queue { struct reference_counter_data_t { int cntr; struct atomic_t { int val; } *mutex; } ref; struct _mq_message_t { void *data; int data_len; struct _mq_message_t *next; void (*destroy_function)(void *); enum { message_allocated_with_data=0, message_holding_data_ptr=1 } allocation_style; char data_buf[1]; } *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; } *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t { struct _str name; struct _str value; char buf[1]; } *first_param; void *subscriber_data; } local_subscription_pres_data; struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t { struct _str name; struct _notifier_domain_t { struct atomic_t mutex; struct atomic_t data_mutex; struct _str name; struct _notifier_package_t *first_package; struct _qsa_content_type_t { struct _qsa_content_type_t *next; struct _str name; void (*destroy_func)(void *); char buf[1]; } *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t { int mutex_cnt; int mutex_to_assign; struct atomic_t mutexes[1]; } *rc_grp; } *domain; struct _notifier_t { int (*subscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void (*unsubscribe)(struct _notifier_t *n, struct _qsa_subscription_t *subscription); void *user_data; struct _notifier_package_t *package; struct _notifier_t *prev; } *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; } *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; } *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t { int element_size; int element_count; int allocated_count; int allocation_count; void *data; } display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t { subscription_uninitialized=0, subscription_active=1, subscription_pending=2, subscription_terminated=3, subscription_terminated_to=4, subscription_terminated_pending=5, subscription_terminated_pending_to=6 } status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; } *vs; } internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; } *

variable_types: struct _dstring_t { struct _dstr_buff_t { int len; int used; struct _dstr_buff_t *next; char data[1]; } *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: struct _dstring_t { struct _dstr_buff_t *first; struct _dstr_buff_t *last; int len; int buff_size; int error; }

user_defined_types: struct _rl_subscription_t { enum rls_subscription_type_t type; struct xcap_query_params_t xcap_params; union { struct _subscription_data_t external; struct internal_subscription_data_t internal; } u; int doc_version; int changed; struct vector_t vs; struct _str from_uid; char dbid[48]; }

user_defined_types: struct _subscription_data_t { struct _time_event_data_t expiration; struct dlg *dialog; void *usr_data; enum subscription_status_t status; struct _subscription_data_t *next; struct _subscription_data_t *prev; struct _str contact; struct _str record_id; struct _str package; struct _str subscriber; }

user_defined_types: struct internal_subscription_data_t { struct _str *package; struct _str *record_id; struct _str *subscriber_id; struct _virtual_subscription_t *vs; }

user_defined_types: struct dlg { struct dlg_id id; struct dlg_seq loc_seq; struct dlg_seq rem_seq; struct _str loc_uri; struct _str rem_uri; struct _str rem_target; struct _str dst_uri; struct _str loc_dname; struct _str rem_dname; unsigned char secure; enum dlg_state state; struct rr *route_set; struct dlg_hooks hooks; struct socket_info *send_sock; }

user_defined_types: struct _virtual_subscription_t { struct _qsa_subscription_data_t local_subscription_pres_data; struct _qsa_subscription_t *local_subscription_pres; struct _rl_subscription_t *local_subscription_list; struct vector_t display_names; struct _rl_subscription_t *subscription; int changed; struct _str state_document; struct _str content_type; enum subscription_status_t status; struct _str uri; struct _virtual_subscription_t *next; struct _virtual_subscription_t *prev; char dbid[48]; char uri_str[1]; }

user_defined_types: struct _qsa_subscription_data_t { struct msg_queue *dst; struct _str record_id; struct _str subscriber_id; struct _qsa_subscription_params_t *first_param; void *subscriber_data; }

user_defined_types: struct rr { struct name_addr nameaddr; struct param *r2; struct param *params; int len; struct rr *next; }

user_defined_types: struct socket_info { int socket; struct _str name; struct ip_addr address; struct _str address_str; struct _str port_no_str; enum si_flags flags; union sockaddr_union su; struct socket_info *next; struct socket_info *prev; unsigned short port_no; char proto; struct _str sock_str; struct addr_info *addr_info_lst; int workers; int workers_tcpidx; struct advertise_info useinfo; }

user_defined_types: struct _qsa_subscription_t { struct atomic_t *mutex; struct _notifier_package_t *package; int allow_notifications; struct _qsa_subscription_data_t *data; struct _qsa_subscription_t *prev; struct reference_counter_data_t ref; }

user_defined_types: union sockaddr_union { struct sockaddr s; struct sockaddr_in sin; struct sockaddr_in6 sin6; }

user_defined_types: struct msg_queue { struct reference_counter_data_t ref; struct _mq_message_t *first; struct _mq_message_t *last; struct atomic_t q_mutex; unsigned int flags; }

user_defined_types: struct param { enum ptype type; struct _str name; struct _str body; int len; struct param *next; }

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

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct addr_info { struct _str name; struct ip_addr address; struct _str address_str; enum si_flags flags; union sockaddr_union su; struct addr_info *next; struct addr_info *prev; }

user_defined_types: struct _notifier_package_t { struct _str name; struct _notifier_domain_t *domain; struct _notifier_t *first_notifier; struct _qsa_subscription_t *first_subscription; struct _notifier_package_t *next; }

user_defined_types: struct _notifier_domain_t { struct atomic_t mutex; struct atomic_t data_mutex; struct _str name; struct _notifier_package_t *first_package; struct _qsa_content_type_t *first_content_type; struct reference_counter_data_t ref; struct reference_counter_group_t *rc_grp; }