toStdout

decompiled_code:
__int64 __fastcall toStdout(__int64 a1, char a2, char a3)
{
__int64 v3; // rax

v3 = TeeWiggleIterator(a1, (__int64)stdout, a2, a3);
return runWiggleIterator(v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, char a2, char a3)
{
__int64 v3; // rax

v3 = func7(a1, (__int64)stdout, a2, a3);
return runWiggleIterator(v3);
}

original_code:
void toStdout(WiggleIterator * wi, char bedGraph, char holdFire) {
 runWiggleIterator(TeeWiggleIterator(wi, stdout, bedGraph, holdFire));
}

canonical_original_code:
void toStdout(struct wiggleIterator_st *wi, char bedGraph, char holdFire) {
 runWiggleIterator(TeeWiggleIterator(wi, stdout, bedGraph, holdFire));
}

variable_types: bedGraph char

variable_types: holdFire char


repo: Ensembl/WiggleTools

original_code:
static inline int ceillog2(int a)
{
 int oa;
 int i;
 int b;
 int cons;
 oa = a;
 b = (sizeof(int) * 8) / 2;
 i = 0;
 while (b) {
  i = (i << 1);
  cons = ((int) 1) << b;
  if (a >= cons) {
   a /= cons;
   i = i | 1;
  } else
   a &= cons - 1;
  b /= 2;
 }
 if ((((int) 1 << i)) == oa)
  return i;
 else
  return i + 1;
}

variable_types: a int

variable_types: oa int

variable_types: i int

variable_types: b int

variable_types: cons int

return_type: int


compareValueSetPairs

decompiled_code:
__int64 __fastcall compareValueSetPairs(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(double *)a2 <= *(double *)a1 )
result = *(double *)a1 > *(double *)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(double *)a2 <= *(double *)a1 )
result = *(double *)a1 > *(double *)a2;
return result;
}

original_code:
static int compareValueSetPairs(const void * A, const void * B) {
 ValueSetPair * vspA = (ValueSetPair *) A;
 ValueSetPair * vspB = (ValueSetPair *) B;
 if (vspA->value < vspB->value)
  return -1;
 if (vspA->value > vspB->value)
  return 1;
 return 0;
}

canonical_original_code:
static int compareValueSetPairs(void *A, void *B) {
 struct valueSetPair_st *vspA = (ValueSetPair *) A;
 struct valueSetPair_st *vspB = (ValueSetPair *) B;
 if (vspA->value < vspB->value)
  return -1;
 if (vspA->value > vspB->value)
  return 1;
 return 0;
}

variable_types:
A
void *

variable_types:
B
void *

variable_types: struct valueSetPair_st { double value; char set; } *


goToNextBlock

decompiled_code:
__int64 __fastcall goToNextBlock(__int64 a1)
{
pthread_mutex_t *v1; // rbp
_QWORD *v3; // r12
int v4; // eax
unsigned int v5; // er8
int v6; // eax
pthread_cond_t *v7; // rdi
void *v8; // rdi

v1 = (pthread_mutex_t *)(a1 + 56);
v3 = *(_QWORD **)(a1 + 24);
++i_0;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 56));
v4 = *(_DWORD *)(a1 + 40);
v5 = 1;
if ( v4 >= 0 )
{
v6 = v4 - 1;
v7 = (pthread_cond_t *)(a1 + 96);
*(_DWORD *)(a1 + 40) = v6;
if ( !v6 && !*(_BYTE *)(a1 + 144) )
{
pthread_cond_wait(v7, v1);
v7 = (pthread_cond_t *)(a1 + 96);
}
pthread_cond_signal(v7);
pthread_mutex_unlock(v1);
v8 = (void *)v3[20000];
*(_QWORD *)(a1 + 24) = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 160024LL);
free(v8);
free(v3);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
pthread_mutex_t *v1; // rbp
_QWORD *v3; // r12
int v4; // eax
unsigned int v5; // er8
int v6; // eax
pthread_cond_t *v7; // rdi
void *v8; // rdi

v1 = (pthread_mutex_t *)(a1 + 56);
v3 = *(_QWORD **)(a1 + 24);
++i_0;
pthread_mutex_lock((pthread_mutex_t *)(a1 + 56));
v4 = *(_DWORD *)(a1 + 40);
v5 = 1;
if ( v4 >= 0 )
{
v6 = v4 - 1;
v7 = (pthread_cond_t *)(a1 + 96);
*(_DWORD *)(a1 + 40) = v6;
if ( !v6 && !*(_BYTE *)(a1 + 144) )
{
pthread_cond_wait(v7, v1);
v7 = (pthread_cond_t *)(a1 + 96);
}
pthread_cond_signal(v7);
pthread_mutex_unlock(v1);
v8 = (void *)v3[20000];
*(_QWORD *)(a1 + 24) = *(_QWORD *)(*(_QWORD *)(a1 + 24) + 160024LL);
free(v8);
free(v3);
v5 = 0;
}
return v5;
}

original_code:
static void goToNextBlock(BufferedReaderData * data) {
 BlockData * prevBlockData = data->blockData;
 data->blockData = data->blockData->next;
 data->readIndex = 0;
 destroyBlockData(prevBlockData);
}

canonical_original_code:
static void goToNextBlock(struct bufferedReaderData_st *data) {
 struct blockData_st *prevBlockData = data->blockData;
 data->blockData = data->blockData->next;
 data->readIndex = 0;
 destroyBlockData(prevBlockData);
}

variable_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st { char **chrom; int *start; int *finish; double *value; int count; struct blockData_st *next; } *blockData; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } count_mutex; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } count_cond; int blockCount; int readIndex; void *readerData; char killed; } *

return_type: void

user_defined_types: struct bufferedReaderData_st { unsigned long downloaderThreadID; struct blockData_st *blockData; union pthread_mutex_t count_mutex; union pthread_cond_t count_cond; int blockCount; int readIndex; void *readerData; char killed; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

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


timespecAdd

repo: ErikOnBike/light-play

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

v2 = *a1 + *a2;
result = a1[1] + a2[1];
*a1 = v2;
a1[1] = result;
if ( result > 999999999 )
{
result -= 1000000000LL;
*a1 = v2 + 1;
a1[1] = result;
}
return result;
}

original_code:
void timespecAdd(struct timespec *time, const struct timespec *delta) {
 time->tv_sec += delta->tv_sec;
 time->tv_nsec += delta->tv_nsec;
 if(time->tv_nsec >= 1000000000L) {
  time->tv_sec++;
  time->tv_nsec -= 1000000000L;
 }
}

canonical_original_code:
void timespecAdd(struct timespec *time, struct timespec *delta) {
 time->tv_sec += delta->tv_sec;
 time->tv_nsec += delta->tv_nsec;
 if(time->tv_nsec >= 1000000000L) {
  time->tv_sec++;
  time->tv_nsec -= 1000000000L;
 }
}

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

variable_types:
delta
struct timespec *


getRandomNumber

decompiled_code:
__int64 __fastcall getRandomNumber(int *a1)
{
unsigned int v1; // er12
__int64 result; // rax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v1 = (unsigned __int8)isSeeded_0;
if ( isSeeded_0 )
goto LABEL_5;
if ( clock_gettime(1, &v3) )
{
logWrite(1LL, "utils.c", "Cannot read the internal clock for using it in generating (pseudo)random numbers");
result = v1;
}
else
{
if ( v3.tv_nsec + v3.tv_sec )
{
srand(LODWORD(v3.tv_nsec) + LODWORD(v3.tv_sec));
isSeeded_0 = 1;
LABEL_5:
*a1 = rand();
return 1LL;
}
logWrite(1LL, "utils.c", "Clock returned value 0 which cannot be used for generating (pseudo)random numbers");
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
unsigned int v1; // er12
__int64 result; // rax
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v1 = (unsigned __int8)isSeeded_0;
if ( isSeeded_0 )
goto LABEL_5;
if ( clock_gettime(1, &v3) )
{
logWrite(1LL, "utils.c", "Cannot read the internal clock for using it in generating (pseudo)random numbers");
result = v1;
}
else
{
if ( v3.tv_nsec + v3.tv_sec )
{
srand(LODWORD(v3.tv_nsec) + LODWORD(v3.tv_sec));
isSeeded_0 = 1;
LABEL_5:
*a1 = rand();
return 1LL;
}
logWrite(1LL, "utils.c", "Clock returned value 0 which cannot be used for generating (pseudo)random numbers");
result = v1;
}
return result;
}

original_code:
_Bool getRandomNumber(uint32_t *randomValue) {
 static _Bool isSeeded = 0;
 struct timespec timeSpec;
 if(!isSeeded) {
  if(clock_gettime(1, &timeSpec) != 0) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read the internal clock for using it in generating (pseudo)random numbers");
   return 0;
  }
  if(timeSpec.tv_sec + timeSpec.tv_nsec == 0) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Clock returned value 0 which cannot be used for generating (pseudo)random numbers");
   return 0;
  }
  srand((unsigned int)(timeSpec.tv_sec + timeSpec.tv_nsec));
  isSeeded = 1;
 }
 if(sizeof(int) == sizeof(uint32_t)) {
  *randomValue = rand();
 } else if(2 * sizeof(int) == sizeof(uint32_t)) {
  *randomValue = ((uint32_t)rand()) << 16 && rand();
 } else {
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Size of 'int' is unexpected and therefore (pseudo)random numbers can be less strong");
  *randomValue = (uint32_t)rand();
 }
 return 1;
}

canonical_original_code:
_Bool getRandomNumber(unsigned int *randomValue) {
 static _Bool isSeeded = 0;
 struct timespec timeSpec;
 if(!isSeeded) {
  if(clock_gettime(1, &timeSpec) != 0) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read the internal clock for using it in generating (pseudo)random numbers");
   return 0;
  }
  if(timeSpec.tv_sec + timeSpec.tv_nsec == 0) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Clock returned value 0 which cannot be used for generating (pseudo)random numbers");
   return 0;
  }
  srand((unsigned int)(timeSpec.tv_sec + timeSpec.tv_nsec));
  isSeeded = 1;
 }
 if(sizeof(int) == sizeof(unsigned int)) {
  *randomValue = rand();
 } else if(2 * sizeof(int) == sizeof(unsigned int)) {
  *randomValue = ((unsigned int)rand()) << 16 && rand();
 } else {
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Size of 'int' is unexpected and therefore (pseudo)random numbers can be less strong");
  *randomValue = (unsigned int)rand();
 }
 return 1;
}

variable_types:
randomValue
unsigned int *

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


decompiled_code:
unsigned __int64 __fastcall MD5_Update(unsigned int *a1, char *a2, size_t a3)
{
char *v3; // r13
size_t v4; // r12
_DWORD *v6; // rbx
unsigned int v7; // edi
unsigned int v8; // eax
unsigned int v9; // edx
unsigned int v10; // eax
unsigned int v11; // edi
__int64 v12; // rcx
__int64 v13; // rax
_QWORD *v14; // rdi
unsigned __int64 result; // rax
unsigned __int64 v16; // rsi
signed __int64 v17; // r13
unsigned int v18; // edx
__int64 v19; // rcx
size_t v20; // rdx
unsigned __int64 v21; // r8
char *v22; // rdi
char *v23; // r10
unsigned int v24; // edi
unsigned int v25; // edi
unsigned int v26; // edx
__int64 v27; // rsi

v3 = a2;
v4 = a3;
v6 = a1 + 6;
v7 = *a1;
v8 = a1[1];
v9 = (v7 + a3) & 0x1FFFFFFF;
*a1 = v9;
v10 = (v4 >> 29) + (v9 < v7) + v8;
v11 = v7 & 0x3F;
a1[1] = v10;
if ( v11 )
{
v12 = v11;
v13 = 64 - v12;
v14 = (_QWORD *)((char *)a1 + v11 + 24);
if ( v4 < 64 - v12 )
return (unsigned __int64)memcpy(v14, a2, v4);
if ( (unsigned int)v13 >= 8 )
{
v21 = (unsigned __int64)(v14 + 1) & 0xFFFFFFFFFFFFFFF8LL;
*v14 = *(_QWORD *)a2;
*(_QWORD *)((char *)v14 + (unsigned int)v13 - 8) = *(_QWORD *)&a2[(unsigned int)v13 - 8];
v22 = (char *)v14 - v21;
v23 = (char *)(a2 - v22);
v24 = (v13 + (_DWORD)v22) & 0xFFFFFFF8;
if ( v24 >= 8 )
{
v25 = v24 & 0xFFFFFFF8;
v26 = 0;
do
{
v27 = v26;
v26 += 8;
*(_QWORD *)(v21 + v27) = *(_QWORD *)&v23[v27];
}
while ( v26 < v25 );
}
}
else if ( (v13 & 4) != 0 )
{
*(_DWORD *)v14 = *(_DWORD *)a2;
*(_DWORD *)((char *)v14 + (unsigned int)v13 - 4) = *(_DWORD *)&a2[(unsigned int)v13 - 4];
}
else if ( (_DWORD)v13 )
{
*(_BYTE *)v14 = *a2;
if ( (v13 & 2) != 0 )
*(_WORD *)((char *)v14 + (unsigned int)v13 - 2) = *(_WORD *)&a2[(unsigned int)v13 - 2];
}
v6 = a1 + 6;
v3 += v13;
v4 = v12 + v4 - 64;
body(a1, a1 + 6, 64LL);
}
if ( v4 > 0x3F )
{
v20 = v4;
LODWORD(v4) = v4 & 0x3F;
v3 = (char *)body(a1, v3, v20 & 0xFFFFFFFFFFFFFFC0LL);
}
result = (unsigned int)v4;
if ( (unsigned int)v4 < 8 )
{
if ( (v4 & 4) != 0 )
{
*v6 = *(_DWORD *)v3;
*(_DWORD *)((char *)v6 + (unsigned int)v4 - 4) = *(_DWORD *)&v3[(unsigned int)v4 - 4];
}
else if ( (_DWORD)v4 )
{
*(_BYTE *)v6 = *v3;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v6 + (unsigned int)v4 - 2) = *(_WORD *)&v3[(unsigned int)v4 - 2];
}
}
else
{
v16 = (unsigned __int64)(v6 + 2) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)v6 = *(_QWORD *)v3;
*(_QWORD *)((char *)v6 + (unsigned int)v4 - 8) = *(_QWORD *)&v3[(unsigned int)v4 - 8];
v17 = v3 - ((char *)v6 - v16);
result = ((_DWORD)v4 + (_DWORD)v6 - (_DWORD)v16) & 0xFFFFFFF8;
if ( (unsigned int)result >= 8 )
{
result = ((_DWORD)v4 + (_DWORD)v6 - (_DWORD)v16) & 0xFFFFFFF8;
v18 = 0;
do
{
v19 = v18;
v18 += 8;
*(_QWORD *)(v16 + v19) = *(_QWORD *)(v17 + v19);
}
while ( v18 < (unsigned int)result );
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned int *a1, char *a2, size_t a3)
{
char *v3; // r13
size_t v4; // r12
_DWORD *v6; // rbx
unsigned int v7; // edi
unsigned int v8; // eax
unsigned int v9; // edx
unsigned int v10; // eax
unsigned int v11; // edi
__int64 v12; // rcx
__int64 v13; // rax
_QWORD *v14; // rdi
unsigned __int64 result; // rax
unsigned __int64 v16; // rsi
signed __int64 v17; // r13
unsigned int v18; // edx
__int64 v19; // rcx
size_t v20; // rdx
unsigned __int64 v21; // r8
char *v22; // rdi
char *v23; // r10
unsigned int v24; // edi
unsigned int v25; // edi
unsigned int v26; // edx
__int64 v27; // rsi

v3 = a2;
v4 = a3;
v6 = a1 + 6;
v7 = *a1;
v8 = a1[1];
v9 = (v7 + a3) & 0x1FFFFFFF;
*a1 = v9;
v10 = (v4 >> 29) + (v9 < v7) + v8;
v11 = v7 & 0x3F;
a1[1] = v10;
if ( v11 )
{
v12 = v11;
v13 = 64 - v12;
v14 = (_QWORD *)((char *)a1 + v11 + 24);
if ( v4 < 64 - v12 )
return (unsigned __int64)memcpy(v14, a2, v4);
if ( (unsigned int)v13 >= 8 )
{
v21 = (unsigned __int64)(v14 + 1) & 0xFFFFFFFFFFFFFFF8LL;
*v14 = *(_QWORD *)a2;
*(_QWORD *)((char *)v14 + (unsigned int)v13 - 8) = *(_QWORD *)&a2[(unsigned int)v13 - 8];
v22 = (char *)v14 - v21;
v23 = (char *)(a2 - v22);
v24 = (v13 + (_DWORD)v22) & 0xFFFFFFF8;
if ( v24 >= 8 )
{
v25 = v24 & 0xFFFFFFF8;
v26 = 0;
do
{
v27 = v26;
v26 += 8;
*(_QWORD *)(v21 + v27) = *(_QWORD *)&v23[v27];
}
while ( v26 < v25 );
}
}
else if ( (v13 & 4) != 0 )
{
*(_DWORD *)v14 = *(_DWORD *)a2;
*(_DWORD *)((char *)v14 + (unsigned int)v13 - 4) = *(_DWORD *)&a2[(unsigned int)v13 - 4];
}
else if ( (_DWORD)v13 )
{
*(_BYTE *)v14 = *a2;
if ( (v13 & 2) != 0 )
*(_WORD *)((char *)v14 + (unsigned int)v13 - 2) = *(_WORD *)&a2[(unsigned int)v13 - 2];
}
v6 = a1 + 6;
v3 += v13;
v4 = v12 + v4 - 64;
body(a1, a1 + 6, 64LL);
}
if ( v4 > 0x3F )
{
v20 = v4;
LODWORD(v4) = v4 & 0x3F;
v3 = (char *)body(a1, v3, v20 & 0xFFFFFFFFFFFFFFC0LL);
}
result = (unsigned int)v4;
if ( (unsigned int)v4 < 8 )
{
if ( (v4 & 4) != 0 )
{
*v6 = *(_DWORD *)v3;
*(_DWORD *)((char *)v6 + (unsigned int)v4 - 4) = *(_DWORD *)&v3[(unsigned int)v4 - 4];
}
else if ( (_DWORD)v4 )
{
*(_BYTE *)v6 = *v3;
if ( (v4 & 2) != 0 )
*(_WORD *)((char *)v6 + (unsigned int)v4 - 2) = *(_WORD *)&v3[(unsigned int)v4 - 2];
}
}
else
{
v16 = (unsigned __int64)(v6 + 2) & 0xFFFFFFFFFFFFFFF8LL;
*(_QWORD *)v6 = *(_QWORD *)v3;
*(_QWORD *)((char *)v6 + (unsigned int)v4 - 8) = *(_QWORD *)&v3[(unsigned int)v4 - 8];
v17 = v3 - ((char *)v6 - v16);
result = ((_DWORD)v4 + (_DWORD)v6 - (_DWORD)v16) & 0xFFFFFFF8;
if ( (unsigned int)result >= 8 )
{
result = ((_DWORD)v4 + (_DWORD)v6 - (_DWORD)v16) & 0xFFFFFFF8;
v18 = 0;
do
{
v19 = v18;
v18 += 8;
*(_QWORD *)(v16 + v19) = *(_QWORD *)(v17 + v19);
}
while ( v18 < (unsigned int)result );
}
}
return result;
}

original_code:
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
{
 MD5_u32plus saved_lo;
 unsigned long used, available;
 saved_lo = ctx->lo;
 if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
  ctx->hi++;
 ctx->hi += size >> 29;
 used = saved_lo & 0x3f;
 if (used) {
  available = 64 - used;
  if (size < available) {
   memcpy(&ctx->buffer[used], data, size);
   return;
  }
  memcpy(&ctx->buffer[used], data, available);
  data = (const unsigned char *)data + available;
  size -= available;
  body(ctx, ctx->buffer, 64);
 }
 if (size >= 64) {
  data = body(ctx, data, size & ~(unsigned long)0x3f);
  size &= 0x3f;
 }
 memcpy(ctx->buffer, data, size);
}

canonical_original_code:
void MD5_Update(struct MD5_CTX *ctx, void *data, unsigned long size)
{
 unsigned int saved_lo;
 unsigned long used; unsigned long available;
 saved_lo = ctx->lo;
 if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
  ctx->hi++;
 ctx->hi += size >> 29;
 used = saved_lo & 0x3f;
 if (used) {
  available = 64 - used;
  if (size < available) {
   memcpy(&ctx->buffer[used], data, size);
   return;
  }
  memcpy(&ctx->buffer[used], data, available);
  data = (unsigned char *)data + available;
  size -= available;
  body(ctx, ctx->buffer, 64);
 }
 if (size >= 64) {
  data = body(ctx, data, size & ~(unsigned long)0x3f);
  size &= 0x3f;
 }
 memcpy(ctx->buffer, data, size);
}

variable_types: struct MD5_CTX { unsigned int lo; unsigned int a; unsigned char buffer[64]; unsigned int block[16]; } *

variable_types:
data
void *

variable_types:
size
unsigned long

variable_types:
used
unsigned long

variable_types:
available
unsigned long


original_code:
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
{
 unsigned long used, available;
 used = ctx->lo & 0x3f;
 ctx->buffer[used++] = 0x80;
 available = 64 - used;
 if (available < 8) {
  memset(&ctx->buffer[used], 0, available);
  body(ctx, ctx->buffer, 64);
  used = 0;
  available = 64;
 }
 memset(&ctx->buffer[used], 0, available - 8);
 ctx->lo <<= 3;
 ctx->buffer[56] = ctx->lo;
 ctx->buffer[57] = ctx->lo >> 8;
 ctx->buffer[58] = ctx->lo >> 16;
 ctx->buffer[59] = ctx->lo >> 24;
 ctx->buffer[60] = ctx->hi;
 ctx->buffer[61] = ctx->hi >> 8;
 ctx->buffer[62] = ctx->hi >> 16;
 ctx->buffer[63] = ctx->hi >> 24;
 body(ctx, ctx->buffer, 64);
 result[0] = ctx->a;
 result[1] = ctx->a >> 8;
 result[2] = ctx->a >> 16;
 result[3] = ctx->a >> 24;
 result[4] = ctx->b;
 result[5] = ctx->b >> 8;
 result[6] = ctx->b >> 16;
 result[7] = ctx->b >> 24;
 result[8] = ctx->c;
 result[9] = ctx->c >> 8;
 result[10] = ctx->c >> 16;
 result[11] = ctx->c >> 24;
 result[12] = ctx->d;
 result[13] = ctx->d >> 8;
 result[14] = ctx->d >> 16;
 result[15] = ctx->d >> 24;
 memset(ctx, 0, sizeof(*ctx));
}

canonical_original_code:
void MD5_Final(unsigned char *result, struct MD5_CTX *ctx)
{
 unsigned long used; unsigned long available;
 used = ctx->lo & 0x3f;
 ctx->buffer[used++] = 0x80;
 available = 64 - used;
 if (available < 8) {
  memset(&ctx->buffer[used], 0, available);
  body(ctx, ctx->buffer, 64);
  used = 0;
  available = 64;
 }
 memset(&ctx->buffer[used], 0, available - 8);
 ctx->lo <<= 3;
 ctx->buffer[56] = ctx->lo;
 ctx->buffer[57] = ctx->lo >> 8;
 ctx->buffer[58] = ctx->lo >> 16;
 ctx->buffer[59] = ctx->lo >> 24;
 ctx->buffer[60] = ctx->hi;
 ctx->buffer[61] = ctx->hi >> 8;
 ctx->buffer[62] = ctx->hi >> 16;
 ctx->buffer[63] = ctx->hi >> 24;
 body(ctx, ctx->buffer, 64);
 result[0] = ctx->a;
 result[1] = ctx->a >> 8;
 result[2] = ctx->a >> 16;
 result[3] = ctx->a >> 24;
 result[4] = ctx->b;
 result[5] = ctx->b >> 8;
 result[6] = ctx->b >> 16;
 result[7] = ctx->b >> 24;
 result[8] = ctx->c;
 result[9] = ctx->c >> 8;
 result[10] = ctx->c >> 16;
 result[11] = ctx->c >> 24;
 result[12] = ctx->d;
 result[13] = ctx->d >> 8;
 result[14] = ctx->d >> 16;
 result[15] = ctx->d >> 24;
 memset(ctx, 0, sizeof(*ctx));
}

variable_types:
result
unsigned char *

user_defined_types: struct MD5_CTX { unsigned int lo; unsigned int a; unsigned char buffer[64]; unsigned int block[16]; }


networkGetAddressInfo

decompiled_code:
__int64 __fastcall networkGetAddressInfo(char *name, char *service, int a3, struct addrinfo **a4)
{
int v4; // er8
__int64 result; // rax
struct addrinfo v6; // [rsp+0h] [rbp-48h] BYREF

*(_OWORD *)&v6.ai_flags = 0LL;
*(_OWORD *)&v6.ai_addrlen = 0LL;
*(_OWORD *)&v6.ai_canonname = 0LL;
if ( a3 == 1 )
{
v6.ai_flags = 1;
*(_QWORD *)&v6.ai_socktype = 0x1100000002LL;
}
else
{
if ( a3 )
{
logWrite(1LL, "network.c", "Unsupported connection type. Unclear how to setup a connection. Failing.");
return 0LL;
}
*(_QWORD *)&v6.ai_socktype = 0x600000001LL;
}
v4 = getaddrinfo(name, service, &v6, a4);
result = 1LL;
if ( v4 )
{
logWrite(1LL, "network.c", "Cannot get address information for host \"%s\" with port \"%s\".");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name, char *service, int a3, struct addrinfo **a4)
{
int v4; // er8
__int64 result; // rax
struct addrinfo v6; // [rsp+0h] [rbp-48h] BYREF

*(_OWORD *)&v6.ai_flags = 0LL;
*(_OWORD *)&v6.ai_addrlen = 0LL;
*(_OWORD *)&v6.ai_canonname = 0LL;
if ( a3 == 1 )
{
v6.ai_flags = 1;
*(_QWORD *)&v6.ai_socktype = 0x1100000002LL;
}
else
{
if ( a3 )
{
logWrite(1LL, "network.c", "Unsupported connection type. Unclear how to setup a connection. Failing.");
return 0LL;
}
*(_QWORD *)&v6.ai_socktype = 0x600000001LL;
}
v4 = getaddrinfo(name, service, &v6, a4);
result = 1LL;
if ( v4 )
{
logWrite(1LL, "network.c", "Cannot get address information for host \"%s\" with port \"%s\".");
result = 0LL;
}
return result;
}

original_code:
_Bool networkGetAddressInfo(const char *hostName, const char *portName, NetworkConnectionType connectionType, struct addrinfo **addressInfo) {
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 if(connectionType == UDP_CONNECTION) {
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = IPPROTO_UDP;
  hints.ai_flags = 0x0001;
 } else if(connectionType == TCP_CONNECTION) {
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  hints.ai_flags = 0;
 } else {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unsupported connection type. Unclear how to setup a connection. Failing.");
  return 0;
 }
 hints.ai_family = 0;
 hints.ai_canonname = ((void *)0);
 hints.ai_addr = ((void *)0);
 hints.ai_next = ((void *)0);
 if(getaddrinfo(hostName, portName, &hints, addressInfo) != 0) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot get address information for host \"%s\" with port \"%s\".", hostName == ((void *)0) ? "<any>" : hostName, portName);
  return 0;
 }
 return 1;
}

canonical_original_code:
_Bool networkGetAddressInfo(char *hostName, char *portName, enum NetworkConnectionType connectionType, struct addrinfo **addressInfo) {
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 if(connectionType == UDP_CONNECTION) {
  hints.ai_socktype = SOCK_DGRAM;
  hints.ai_protocol = IPPROTO_UDP;
  hints.ai_flags = 0x0001;
 } else if(connectionType == TCP_CONNECTION) {
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  hints.ai_flags = 0;
 } else {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unsupported connection type. Unclear how to setup a connection. Failing.");
  return 0;
 }
 hints.ai_family = 0;
 hints.ai_canonname = ((void *)0);
 hints.ai_addr = ((void *)0);
 hints.ai_next = ((void *)0);
 if(getaddrinfo(hostName, portName, &hints, addressInfo) != 0) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot get address information for host \"%s\" with port \"%s\".", hostName == ((void *)0) ? "<any>" : hostName, portName);
  return 0;
 }
 return 1;
}

variable_types:
hostName
char *

variable_types:
portName
char *

variable_types: enum NetworkConnectionType { TCP_CONNECTION=0, UDP_CONNECTION=1 }

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

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


networkCopySocketAddress

decompiled_code:
__int64 __fastcall networkCopySocketAddress(void **a1, unsigned int *a2, const void *a3, unsigned int a4)
{
size_t v4; // r12
unsigned int v6; // er13

v4 = a4;
*a2 = a4;
v6 = voidBufferAllocate(a1, a4, "socket address");
if ( (_BYTE)v6 )
memcpy(*a1, a3, v4);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1, unsigned int *a2, const void *a3, unsigned int a4)
{
size_t v4; // r12
unsigned int v6; // er13

v4 = a4;
*a2 = a4;
v6 = voidBufferAllocate(a1, a4, "socket address");
if ( (_BYTE)v6 )
memcpy(*a1, a3, v4);
return v6;
}

original_code:
_Bool networkCopySocketAddress(struct sockaddr **destinationAddress, socklen_t *destinationAddressSize, struct sockaddr *sourceAddress, socklen_t sourceAddressSize) {
 *destinationAddressSize = sourceAddressSize;
 if(!voidBufferAllocate((void **)destinationAddress, sourceAddressSize, "socket address")) {
  return 0;
 }
 memcpy(*destinationAddress, sourceAddress, sourceAddressSize);
 return 1;
}

canonical_original_code:
_Bool networkCopySocketAddress(struct sockaddr **destinationAddress, unsigned int *destinationAddressSize, struct sockaddr *sourceAddress, unsigned int sourceAddressSize) {
 *destinationAddressSize = sourceAddressSize;
 if(!voidBufferAllocate((void **)destinationAddress, sourceAddressSize, "socket address")) {
  return 0;
 }
 memcpy(*destinationAddress, sourceAddress, sourceAddressSize);
 return 1;
}

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

variable_types:
destinationAddressSize
unsigned int *

variable_types:
sourceAddress
struct sockaddr *

variable_types:
sourceAddressSize
unsigned int


networkCopyAddressInfo

decompiled_code:
__int64 __fastcall networkCopyAddressInfo(__int64 a1, char *a2, char *a3)
{
int v5; // edi
__int64 result; // rax
unsigned __int8 v7; // al
int *v8; // rax
unsigned __int8 v9; // [rsp+Fh] [rbp-39h]
socklen_t len; // [rsp+14h] [rbp-34h] BYREF
struct addrinfo *ai; // [rsp+18h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v5 = *(_DWORD *)a1;
len = 16;
if ( getsockname(v5, &addr, &len) )
{
v8 = _errno_location();
logWrite(1LL, "network.c", "Cannot retrieve local address from socket (errno = %d)", (unsigned int)*v8);
result = 0LL;
}
else if ( (unsigned __int8)networkCopySocketAddress((void **)(a1 + 16), (unsigned int *)(a1 + 24), &addr, len)
&& (unsigned __int8)networkGetAddressInfo(a2, a3, 1, &ai) )
{
if ( (ai->ai_family & 0xFFFFFFF7) == 2 )
{
v7 = networkCopySocketAddress((void **)(a1 + 32), (unsigned int *)(a1 + 40), ai->ai_addr, ai->ai_addrlen);
}
else
{
logWrite(
1LL,
"network.c",
"Unknown ai_family %d found when retrieving remote address.",
(unsigned int)ai->ai_family);
v7 = 0;
}
v9 = v7;
freeaddrinfo(ai);
result = v9;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char *a2, char *a3)
{
int v5; // edi
__int64 result; // rax
unsigned __int8 v7; // al
int *v8; // rax
unsigned __int8 v9; // [rsp+Fh] [rbp-39h]
socklen_t len; // [rsp+14h] [rbp-34h] BYREF
struct addrinfo *ai; // [rsp+18h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v5 = *(_DWORD *)a1;
len = 16;
if ( getsockname(v5, &addr, &len) )
{
v8 = _errno_location();
logWrite(1LL, "network.c", "Cannot retrieve local address from socket (errno = %d)", (unsigned int)*v8);
result = 0LL;
}
else if ( (unsigned __int8)func1((void **)(a1 + 16), (unsigned int *)(a1 + 24), &addr, len)
&& (unsigned __int8)func0(a2, a3, 1, &ai) )
{
if ( (ai->ai_family & 0xFFFFFFF7) == 2 )
{
v7 = func1((void **)(a1 + 32), (unsigned int *)(a1 + 40), ai->ai_addr, ai->ai_addrlen);
}
else
{
logWrite(
1LL,
"network.c",
"Unknown ai_family %d found when retrieving remote address.",
(unsigned int)ai->ai_family);
v7 = 0;
}
v9 = v7;
freeaddrinfo(ai);
result = v9;
}
else
{
result = 0LL;
}
return result;
}

original_code:
_Bool networkCopyAddressInfo(NetworkConnection *networkConnection, const char *hostName, const char *portName) {
 struct sockaddr localAddress;
 socklen_t localAddressSize;
 struct addrinfo* remoteAddressInfo;
 _Bool result;
 localAddressSize = sizeof(struct sockaddr);
 if(getsockname(networkConnection->socketDescriptor, &localAddress, &localAddressSize) != 0) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot retrieve local address from socket (errno = %d)", (*__errno_location ()));
  return 0;
 }
 if(!networkCopySocketAddress(&networkConnection->localAddress, &networkConnection->localAddressSize, &localAddress, localAddressSize)) {
  return 0;
 }
 if(!networkGetAddressInfo(hostName, portName, UDP_CONNECTION, &remoteAddressInfo)) {
  return 0;
 }
 result = 1;
 if(remoteAddressInfo->ai_family == 2 || remoteAddressInfo->ai_family == 10) {
  if(!networkCopySocketAddress(&networkConnection->remoteAddress, &networkConnection->remoteAddressSize, remoteAddressInfo->ai_addr, remoteAddressInfo->ai_addrlen)) {
   result = 0;
  }
 } else {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unknown ai_family %d found when retrieving remote address.", remoteAddressInfo->ai_family);
  result = 0;
 }
 freeaddrinfo(remoteAddressInfo);
 return result;
}

canonical_original_code:
_Bool networkCopyAddressInfo(struct NetworkConnectionStruct *networkConnection, char *hostName, char *portName) {
 struct sockaddr localAddress;
 unsigned int localAddressSize;
 struct addrinfo *remoteAddressInfo;
 _Bool result;
 localAddressSize = sizeof(struct sockaddr);
 if(getsockname(networkConnection->socketDescriptor, &localAddress, &localAddressSize) != 0) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot retrieve local address from socket (errno = %d)", (*__errno_location ()));
  return 0;
 }
 if(!networkCopySocketAddress(&networkConnection->localAddress, &networkConnection->localAddressSize, &localAddress, localAddressSize)) {
  return 0;
 }
 if(!networkGetAddressInfo(hostName, portName, UDP_CONNECTION, &remoteAddressInfo)) {
  return 0;
 }
 result = 1;
 if(remoteAddressInfo->ai_family == 2 || remoteAddressInfo->ai_family == 10) {
  if(!networkCopySocketAddress(&networkConnection->remoteAddress, &networkConnection->remoteAddressSize, remoteAddressInfo->ai_addr, remoteAddressInfo->ai_addrlen)) {
   result = 0;
  }
 } else {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unknown ai_family %d found when retrieving remote address.", remoteAddressInfo->ai_family);
  result = 0;
 }
 freeaddrinfo(remoteAddressInfo);
 return result;
}

variable_types: struct NetworkConnectionStruct { int socketDescriptor; enum NetworkConnectionType { TCP_CONNECTION=0, UDP_CONNECTION=1 } connectionType; _Bool isClient; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *localAddress; unsigned int localAddressSize; struct sockaddr *remoteAddress; unsigned int remoteAddressSize; } *

variable_types:
localAddressSize
unsigned int

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

user_defined_types: struct NetworkConnectionStruct { int socketDescriptor; enum NetworkConnectionType connectionType; _Bool isClient; struct sockaddr *localAddress; unsigned int localAddressSize; struct sockaddr *remoteAddress; unsigned int remoteAddressSize; }


networkCloseSocket

decompiled_code:
__int64 __fastcall networkCloseSocket(__int64 a1)
{
unsigned int v1; // er12
int v3; // edi
__int64 v5; // rcx
int *v6; // rax

v1 = 1;
v3 = *(_DWORD *)a1;
if ( v3 != -1 )
{
v1 = *(unsigned __int8 *)(a1 + 8);
if ( (_BYTE)v1 )
{
if ( !shutdown(v3, 2) || (v5 = (unsigned int)*_errno_location(), (_DWORD)v5 == 107) )
{
v3 = *(_DWORD *)a1;
}
else
{
v1 = 0;
logWrite(1LL, "network.c", "Cannot shutdown the network connection with the server. (errno = %d)", v5);
v3 = *(_DWORD *)a1;
}
}
else
{
v1 = 1;
}
if ( close(v3) )
{
v6 = _errno_location();
v1 = 0;
logWrite(1LL, "network.c", "Cannot close the socket connection with the server. (errno = %d)", (unsigned int)*v6);
}
*(_DWORD *)a1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // er12
int v3; // edi
__int64 v5; // rcx
int *v6; // rax

v1 = 1;
v3 = *(_DWORD *)a1;
if ( v3 != -1 )
{
v1 = *(unsigned __int8 *)(a1 + 8);
if ( (_BYTE)v1 )
{
if ( !shutdown(v3, 2) || (v5 = (unsigned int)*_errno_location(), (_DWORD)v5 == 107) )
{
v3 = *(_DWORD *)a1;
}
else
{
v1 = 0;
logWrite(1LL, "network.c", "Cannot shutdown the network connection with the server. (errno = %d)", v5);
v3 = *(_DWORD *)a1;
}
}
else
{
v1 = 1;
}
if ( close(v3) )
{
v6 = _errno_location();
v1 = 0;
logWrite(1LL, "network.c", "Cannot close the socket connection with the server. (errno = %d)", (unsigned int)*v6);
}
*(_DWORD *)a1 = -1;
}
return v1;
}

original_code:
_Bool networkCloseSocket(NetworkConnection *networkConnection) {
 _Bool result;
 result = 1;
 if(networkConnection->socketDescriptor != -1) {
  if(networkConnection->isClient) {
   if(shutdown(networkConnection->socketDescriptor, SHUT_RDWR) != 0) {
    if((*__errno_location ()) != 107) {
     logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot shutdown the network connection with the server. (errno = %d)", (*__errno_location ()));
     result = 0;
    }
   }
  }
  if(close(networkConnection->socketDescriptor) != 0) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot close the socket connection with the server. (errno = %d)", (*__errno_location ()));
   result = 0;
  }
  networkConnection->socketDescriptor = -1;
 }
 return result;
}

canonical_original_code:
_Bool networkCloseSocket(struct NetworkConnectionStruct *networkConnection) {
 _Bool result;
 result = 1;
 if(networkConnection->socketDescriptor != -1) {
  if(networkConnection->isClient) {
   if(shutdown(networkConnection->socketDescriptor, SHUT_RDWR) != 0) {
    if((*__errno_location ()) != 107) {
     logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot shutdown the network connection with the server. (errno = %d)", (*__errno_location ()));
     result = 0;
    }
   }
  }
  if(close(networkConnection->socketDescriptor) != 0) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot close the socket connection with the server. (errno = %d)", (*__errno_location ()));
   result = 0;
  }
  networkConnection->socketDescriptor = -1;
 }
 return result;
}

user_defined_types: enum NetworkConnectionType { TCP_CONNECTION=0, UDP_CONNECTION=1 }

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


networkGetAddressName

decompiled_code:
__int64 __fastcall networkGetAddressName(unsigned __int16 *a1, char *a2, socklen_t a3)
{
__int64 v3; // rcx
int *v5; // rax
int *v6; // rax

v3 = *a1;
if ( (_WORD)v3 == 2 )
{
if ( !inet_ntop(2, a1 + 2, a2, a3) )
{
v5 = _errno_location();
logWrite(1LL, "network.c", "Cannot retrieve IPv4 address through inet_ntop (errno = %d)", (unsigned int)*v5);
return 0LL;
}
}
else
{
if ( (_WORD)v3 != 10 )
{
logWrite(1LL, "network.c", "Unknown sa_family %d found when retrieving IP address", v3);
return 0LL;
}
if ( !inet_ntop(10, a1 + 4, a2, a3) )
{
v6 = _errno_location();
logWrite(1LL, "network.c", "Cannot retrieve IPv6 address through inet_ntop (errno = %d)", (unsigned int)*v6);
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int16 *a1, char *a2, socklen_t a3)
{
__int64 v3; // rcx
int *v5; // rax
int *v6; // rax

v3 = *a1;
if ( (_WORD)v3 == 2 )
{
if ( !inet_ntop(2, a1 + 2, a2, a3) )
{
v5 = _errno_location();
logWrite(1LL, "network.c", "Cannot retrieve IPv4 address through inet_ntop (errno = %d)", (unsigned int)*v5);
return 0LL;
}
}
else
{
if ( (_WORD)v3 != 10 )
{
logWrite(1LL, "network.c", "Unknown sa_family %d found when retrieving IP address", v3);
return 0LL;
}
if ( !inet_ntop(10, a1 + 4, a2, a3) )
{
v6 = _errno_location();
logWrite(1LL, "network.c", "Cannot retrieve IPv6 address through inet_ntop (errno = %d)", (unsigned int)*v6);
return 0LL;
}
}
return 1LL;
}

original_code:
_Bool networkGetAddressName(struct sockaddr *address, char *addressName, int maxAddressNameSize) {
 if(address->sa_family == 2) {
  if(inet_ntop(2, &((struct sockaddr_in *)address)->sin_addr, addressName, (socklen_t)maxAddressNameSize) == ((void *)0)) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot retrieve IPv4 address through inet_ntop (errno = %d)", (*__errno_location ()));
   return 0;
  }
 } else if(address->sa_family == 10) {
  if(inet_ntop(10, &((struct sockaddr_in6 *)address)->sin6_addr, addressName, (socklen_t)maxAddressNameSize) == ((void *)0)) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot retrieve IPv6 address through inet_ntop (errno = %d)", (*__errno_location ()));
   return 0;
  }
 } else {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unknown sa_family %d found when retrieving IP address", address->sa_family);
  return 0;
 }
 return 1;
}

canonical_original_code:
_Bool networkGetAddressName(struct sockaddr *address, char *addressName, int maxAddressNameSize) {
 if(address->sa_family == 2) {
  if(inet_ntop(2, &((struct sockaddr_in *)address)->sin_addr, addressName, (unsigned int)maxAddressNameSize) == ((void *)0)) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot retrieve IPv4 address through inet_ntop (errno = %d)", (*__errno_location ()));
   return 0;
  }
 } else if(address->sa_family == 10) {
  if(inet_ntop(10, &((struct sockaddr_in6 *)address)->sin6_addr, addressName, (unsigned int)maxAddressNameSize) == ((void *)0)) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot retrieve IPv6 address through inet_ntop (errno = %d)", (*__errno_location ()));
   return 0;
  }
 } else {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unknown sa_family %d found when retrieving IP address", address->sa_family);
  return 0;
 }
 return 1;
}

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

variable_types:
addressName
char *

variable_types: maxAddressNameSize int

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 in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


networkReceiveMessageInternal

decompiled_code:
__int64 __fastcall networkReceiveMessageInternal(__int64 a1, void *a2, size_t a3, ssize_t *a4, int a5)
{
int v6; // edi
ssize_t v7; // rbx
__int64 result; // rax
int *v9; // rax
socklen_t addr_len; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

if ( !a1 )
return 0LL;
if ( *(_BYTE *)(a1 + 8) )
{
v7 = recv(*(_DWORD *)a1, a2, a3, a5);
}
else
{
v6 = *(_DWORD *)a1;
addr_len = 16;
addr = 0LL;
v7 = recvfrom(v6, a2, a3, a5, &addr, &addr_len);
}
if ( v7 == -1 )
{
v9 = _errno_location();
logWrite(1LL, "network.c", "Cannot receive network message from host. (errno = %d)", (unsigned int)*v9);
result = 0LL;
}
else
{
if ( !v7 )
logWrite(
2LL,
"network.c",
"Cannot receive network message from host (host may already have closed the connection).");
*a4 = v7;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, void *a2, size_t a3, ssize_t *a4, int a5)
{
int v6; // edi
ssize_t v7; // rbx
__int64 result; // rax
int *v9; // rax
socklen_t addr_len; // [rsp+0h] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-28h] BYREF

if ( !a1 )
return 0LL;
if ( *(_BYTE *)(a1 + 8) )
{
v7 = recv(*(_DWORD *)a1, a2, a3, a5);
}
else
{
v6 = *(_DWORD *)a1;
addr_len = 16;
addr = 0LL;
v7 = recvfrom(v6, a2, a3, a5, &addr, &addr_len);
}
if ( v7 == -1 )
{
v9 = _errno_location();
logWrite(1LL, "network.c", "Cannot receive network message from host. (errno = %d)", (unsigned int)*v9);
result = 0LL;
}
else
{
if ( !v7 )
logWrite(
2LL,
"network.c",
"Cannot receive network message from host (host may already have closed the connection).");
*a4 = v7;
result = 1LL;
}
return result;
}

original_code:
_Bool networkReceiveMessageInternal(NetworkConnection *networkConnection, uint8_t *messageBuffer, size_t maxMessageSize, size_t *messageSize, int flags) {
 struct sockaddr remoteAddress;
 socklen_t remoteAddressSize;
 ssize_t result;
 if(networkConnection == ((void *)0)) {
  return 0;
 }
 if(networkConnection->isClient) {
  result = recv(networkConnection->socketDescriptor, messageBuffer, maxMessageSize, flags);
 } else {
  remoteAddressSize = sizeof(struct sockaddr);
  memset(&remoteAddress, 0, remoteAddressSize);
  result = recvfrom(networkConnection->socketDescriptor, messageBuffer, maxMessageSize, flags, &remoteAddress, &remoteAddressSize);
 }
 if(result == -1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot receive network message from host. (errno = %d)", (*__errno_location ()));
  return 0;
 } else if(result == 0) {
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Cannot receive network message from host (host may already have closed the connection).");
 }
 *messageSize = result;
 return 1;
}

canonical_original_code:
_Bool networkReceiveMessageInternal(struct NetworkConnectionStruct *networkConnection, unsigned char *messageBuffer, unsigned long maxMessageSize, unsigned long *messageSize, int flags) {
 struct sockaddr remoteAddress;
 unsigned int remoteAddressSize;
 long result;
 if(networkConnection == ((void *)0)) {
  return 0;
 }
 if(networkConnection->isClient) {
  result = recv(networkConnection->socketDescriptor, messageBuffer, maxMessageSize, flags);
 } else {
  remoteAddressSize = sizeof(struct sockaddr);
  memset(&remoteAddress, 0, remoteAddressSize);
  result = recvfrom(networkConnection->socketDescriptor, messageBuffer, maxMessageSize, flags, &remoteAddress, &remoteAddressSize);
 }
 if(result == -1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot receive network message from host. (errno = %d)", (*__errno_location ()));
  return 0;
 } else if(result == 0) {
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Cannot receive network message from host (host may already have closed the connection).");
 }
 *messageSize = result;
 return 1;
}

variable_types:
messageBuffer
unsigned char *

variable_types:
maxMessageSize
unsigned long

variable_types:
messageSize
unsigned long *

variable_types: flags int

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

variable_types:
remoteAddressSize
unsigned int

variable_types: result long


networkGetConnectionType

decompiled_code:
__int64 __fastcall networkGetConnectionType(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
NetworkConnectionType networkGetConnectionType(NetworkConnection *networkConnection) {
 return networkConnection->connectionType;
}

canonical_original_code:
enum NetworkConnectionType networkGetConnectionType(struct NetworkConnectionStruct *networkConnection) {
 return networkConnection->connectionType;
}

return_type: enum NetworkConnectionType { TCP_CONNECTION=0, UDP_CONNECTION=1 }


networkGetLocalAddressName

decompiled_code:
__int64 __fastcall networkGetLocalAddressName(__int64 a1, char *a2, socklen_t a3)
{
return networkGetAddressName(*(unsigned __int16 **)(a1 + 16), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, socklen_t a3)
{
return func4(*(unsigned __int16 **)(a1 + 16), a2, a3);
}

original_code:
_Bool networkGetLocalAddressName(NetworkConnection *networkConnection, char *addressName, int maxAddressNameSize) {
 return networkGetAddressName(networkConnection->localAddress, addressName, maxAddressNameSize);
}

canonical_original_code:
_Bool networkGetLocalAddressName(struct NetworkConnectionStruct *networkConnection, char *addressName, int maxAddressNameSize) {
 return networkGetAddressName(networkConnection->localAddress, addressName, maxAddressNameSize);
}


networkGetRemoteAddressName

decompiled_code:
__int64 __fastcall networkGetRemoteAddressName(__int64 a1, char *a2, socklen_t a3)
{
return networkGetAddressName(*(unsigned __int16 **)(a1 + 32), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2, socklen_t a3)
{
return func4(*(unsigned __int16 **)(a1 + 32), a2, a3);
}

original_code:
_Bool networkGetRemoteAddressName(NetworkConnection *networkConnection, char *addressName, int maxAddressNameSize) {
 return networkGetAddressName(networkConnection->remoteAddress, addressName, maxAddressNameSize);
}

canonical_original_code:
_Bool networkGetRemoteAddressName(struct NetworkConnectionStruct *networkConnection, char *addressName, int maxAddressNameSize) {
 return networkGetAddressName(networkConnection->remoteAddress, addressName, maxAddressNameSize);
}


networkSendMessage

decompiled_code:
__int64 __fastcall networkSendMessage(__int64 a1, const void *a2, size_t a3)
{
int v4; // er10
ssize_t v5; // rax
int *v7; // rax
int *v8; // rax

if ( !a1 )
return 0LL;
v4 = *(_DWORD *)a1;
if ( *(_BYTE *)(a1 + 8) )
v5 = send(v4, a2, a3, 0);
else
v5 = sendto(v4, a2, a3, 0, *(const struct sockaddr **)(a1 + 32), *(_DWORD *)(a1 + 40));
if ( v5 == -1 )
{
v8 = _errno_location();
logWrite(1LL, "network.c", "Cannot send network message to server. (errno = %d)", (unsigned int)*v8);
}
else
{
if ( a3 == v5 )
return 1LL;
v7 = _errno_location();
logWrite(
1LL,
"network.c",
"Cannot send full network message to server (ie partial send). (errno = %d)",
(unsigned int)*v7);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const void *a2, size_t a3)
{
int v4; // er10
ssize_t v5; // rax
int *v7; // rax
int *v8; // rax

if ( !a1 )
return 0LL;
v4 = *(_DWORD *)a1;
if ( *(_BYTE *)(a1 + 8) )
v5 = send(v4, a2, a3, 0);
else
v5 = sendto(v4, a2, a3, 0, *(const struct sockaddr **)(a1 + 32), *(_DWORD *)(a1 + 40));
if ( v5 == -1 )
{
v8 = _errno_location();
logWrite(1LL, "network.c", "Cannot send network message to server. (errno = %d)", (unsigned int)*v8);
}
else
{
if ( a3 == v5 )
return 1LL;
v7 = _errno_location();
logWrite(
1LL,
"network.c",
"Cannot send full network message to server (ie partial send). (errno = %d)",
(unsigned int)*v7);
}
return 0LL;
}

original_code:
_Bool networkSendMessage(NetworkConnection *networkConnection, uint8_t *messageBuffer, size_t messageSize) {
 ssize_t result;
 if(networkConnection == ((void *)0)) {
  return 0;
 }
 if(networkConnection->isClient) {
  result = send(networkConnection->socketDescriptor, messageBuffer, messageSize, 0);
 } else {
  result = sendto(networkConnection->socketDescriptor, messageBuffer, messageSize, 0, networkConnection->remoteAddress, networkConnection->remoteAddressSize);
 }
 if(result == -1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot send network message to server. (errno = %d)", (*__errno_location ()));
  return 0;
 } else if(result != messageSize) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot send full network message to server (ie partial send). (errno = %d)", (*__errno_location ()));
  return 0;
 }
 return 1;
}

canonical_original_code:
_Bool networkSendMessage(struct NetworkConnectionStruct *networkConnection, unsigned char *messageBuffer, unsigned long messageSize) {
 long result;
 if(networkConnection == ((void *)0)) {
  return 0;
 }
 if(networkConnection->isClient) {
  result = send(networkConnection->socketDescriptor, messageBuffer, messageSize, 0);
 } else {
  result = sendto(networkConnection->socketDescriptor, messageBuffer, messageSize, 0, networkConnection->remoteAddress, networkConnection->remoteAddressSize);
 }
 if(result == -1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot send network message to server. (errno = %d)", (*__errno_location ()));
  return 0;
 } else if(result != messageSize) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot send full network message to server (ie partial send). (errno = %d)", (*__errno_location ()));
  return 0;
 }
 return 1;
}

variable_types:
messageSize
unsigned long


networkReceiveMessage

decompiled_code:
__int64 __fastcall networkReceiveMessage(__int64 a1, void *a2, size_t a3, ssize_t *a4)
{
return networkReceiveMessageInternal(a1, a2, a3, a4, 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, void *a2, size_t a3, ssize_t *a4)
{
return func5(a1, a2, a3, a4, 0);
}

original_code:
_Bool networkReceiveMessage(NetworkConnection *networkConnection, uint8_t *messageBuffer, size_t maxMessageSize, size_t *messageSize) {
 return networkReceiveMessageInternal(networkConnection, messageBuffer, maxMessageSize, messageSize, 0);
}

canonical_original_code:
_Bool networkReceiveMessage(struct NetworkConnectionStruct *networkConnection, unsigned char *messageBuffer, unsigned long maxMessageSize, unsigned long *messageSize) {
 return networkReceiveMessageInternal(networkConnection, messageBuffer, maxMessageSize, messageSize, 0);
}


networkIsMessageAvailable

decompiled_code:
char __fastcall networkIsMessageAvailable(__int64 a1)
{
char result; // al
char v2; // [rsp+7h] [rbp-11h] BYREF
ssize_t v3[2]; // [rsp+8h] [rbp-10h] BYREF

result = networkReceiveMessageInternal(a1, &v2, 1uLL, v3, 2);
if ( result )
result = v3[0] == 1;
return result;
}

canonical_decompiled_code:
char __fastcall func11(__int64 a1)
{
char result; // al
char v2; // [rsp+7h] [rbp-11h] BYREF
ssize_t v3[2]; // [rsp+8h] [rbp-10h] BYREF

result = func5(a1, &v2, 1uLL, v3, 2);
if ( result )
result = v3[0] == 1;
return result;
}

original_code:
_Bool networkIsMessageAvailable(NetworkConnection *networkConnection) {
 uint8_t byte;
 size_t size;
 return networkReceiveMessageInternal(networkConnection, &byte, 1, &size, MSG_PEEK) && size == 1;
}

canonical_original_code:
_Bool networkIsMessageAvailable(struct NetworkConnectionStruct *networkConnection) {
 unsigned char byte;
 unsigned long size;
 return networkReceiveMessageInternal(networkConnection, &byte, 1, &size, MSG_PEEK) && size == 1;
}

variable_types:
byte
unsigned char

variable_types:
size
unsigned long


networkCloseConnection

decompiled_code:
__int64 __fastcall networkCloseConnection(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi

v1 = 1;
v3 = *a1;
if ( v3 )
{
v1 = networkCloseSocket(v3);
if ( !(unsigned __int8)voidBufferFree(*a1 + 16) )
v1 = 0;
if ( !(unsigned __int8)voidBufferFree(*a1 + 32) )
v1 = 0;
if ( !(unsigned __int8)voidBufferFree(a1) )
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi

v1 = 1;
v3 = *a1;
if ( v3 )
{
v1 = func3(v3);
if ( !(unsigned __int8)voidBufferFree(*a1 + 16) )
v1 = 0;
if ( !(unsigned __int8)voidBufferFree(*a1 + 32) )
v1 = 0;
if ( !(unsigned __int8)voidBufferFree(a1) )
v1 = 0;
}
return v1;
}

original_code:
_Bool networkCloseConnection(NetworkConnection **networkConnection) {
 _Bool result;
 result = 1;
 if(*networkConnection != ((void *)0)) {
  if(!networkCloseSocket(*networkConnection)) {
   result = 0;
  }
  if(!voidBufferFree((void **)&(*networkConnection)->localAddress)) {
   result = 0;
  }
  if(!voidBufferFree((void **)&(*networkConnection)->remoteAddress)) {
   result = 0;
  }
  if(!voidBufferFree((void **)networkConnection)) {
   result = 0;
  }
 }
 return result;
}

canonical_original_code:
_Bool networkCloseConnection(struct NetworkConnectionStruct **networkConnection) {
 _Bool result;
 result = 1;
 if(*networkConnection != ((void *)0)) {
  if(!networkCloseSocket(*networkConnection)) {
   result = 0;
  }
  if(!voidBufferFree((void **)&(*networkConnection)->localAddress)) {
   result = 0;
  }
  if(!voidBufferFree((void **)&(*networkConnection)->remoteAddress)) {
   result = 0;
  }
  if(!voidBufferFree((void **)networkConnection)) {
   result = 0;
  }
 }
 return result;
}

variable_types: struct NetworkConnectionStruct { int socketDescriptor; enum NetworkConnectionType { TCP_CONNECTION=0, UDP_CONNECTION=1 } connectionType; _Bool isClient; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *localAddress; unsigned int localAddressSize; struct sockaddr *remoteAddress; unsigned int remoteAddressSize; } **


networkOpenConnection

decompiled_code:
__int64 __fastcall networkOpenConnection(char *name, char *service, int a3, char a4)
{
int v4; // er15
char v5; // r14
__int64 v8; // rax
char *v9; // rdi
struct addrinfo *v10; // rbp
const char *v11; // r15
int *v12; // r13
int v13; // edi
socklen_t v14; // edx
const struct sockaddr *v15; // rsi
__int64 v16; // rax
const char *v17; // r9
const char *v18; // rcx
__int64 result; // rax
int *v20; // rax
const char *v21; // rcx
__int64 v24; // [rsp+10h] [rbp-48h] BYREF
struct addrinfo *ai; // [rsp+18h] [rbp-40h] BYREF

v4 = a3;
v5 = a4;
if ( !(unsigned __int8)voidBufferAllocate(&v24, 48LL, "network connection") )
return 0LL;
v8 = v24;
v9 = 0LL;
if ( v5 )
v9 = name;
*(_DWORD *)v24 = -1;
*(_DWORD *)(v8 + 4) = v4;
*(_BYTE *)(v8 + 8) = 0;
*(_QWORD *)(v8 + 16) = 0LL;
*(_DWORD *)(v8 + 24) = 0;
*(_QWORD *)(v8 + 32) = 0LL;
*(_DWORD *)(v8 + 40) = 0;
if ( (unsigned __int8)networkGetAddressInfo(v9, service, v4, &ai) )
{
v10 = ai;
if ( ai )
{
v11 = "connect";
v12 = (int *)v24;
if ( !v5 )
v11 = "bind";
while ( 2 )
{
if ( *v12 == -1 )
{
while ( 1 )
{
*v12 = socket(v10->ai_family, v10->ai_socktype, v10->ai_protocol);
v13 = *(_DWORD *)v24;
if ( *(_DWORD *)v24 != -1 )
break;
v20 = _errno_location();
v21 = (const char *)&unk_85A;
if ( v10->ai_next )
v21 = " (going to try another address)";
logWrite(
1LL,
"network.c",
"Cannot open a socket for the network connection%s. (errno = %d)",
v21,
(unsigned int)*v20);
v10 = v10->ai_next;
*(_DWORD *)v24 = -1;
if ( !v10 )
goto LABEL_24;
LABEL_16:
v12 = (int *)v24;
if ( *(_DWORD *)v24 != -1 )
goto LABEL_17;
}
v14 = v10->ai_addrlen;
v15 = v10->ai_addr;
if ( a4 )
{
if ( connect(v13, v15, v14) )
{
LABEL_12:
v16 = (unsigned int)*_errno_location();
v17 = (const char *)&unk_85A;
if ( v10->ai_next )
v17 = " (going to try another address)";
logWrite(
1LL,
"network.c",
"Cannot %s network connection to host \"%s\" on the opened socket%s. (errno = %d)",
v11,
name,
v17,
v16);
networkCloseSocket(v24);
v10 = v10->ai_next;
LABEL_15:
if ( !v10 )
goto LABEL_24;
goto LABEL_16;
}
}
else if ( bind(v13, v15, v14) )
{
goto LABEL_12;
}
if ( (unsigned __int8)networkCopyAddressInfo(v24, name, service) )
{
v12 = (int *)v24;
*(_BYTE *)(v24 + 8) = a4;
continue;
}
networkCloseSocket(v24);
v10 = v10->ai_next;
goto LABEL_15;
}
break;
}
}
else
{
LABEL_24:
networkCloseConnection(&v24);
}
LABEL_17:
freeaddrinfo(ai);
v18 = "UDP";
if ( a3 != 1 )
{
v18 = "TCP";
if ( a3 )
v18 = "(unknown type)";
}
logWrite(4LL, "network.c", "Opened network %s connection to host %s on port %s", v18, name, service);
result = v24;
}
else
{
networkCloseConnection(&v24);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *name, char *service, int a3, char a4)
{
int v4; // er15
char v5; // r14
__int64 v8; // rax
char *v9; // rdi
struct addrinfo *v10; // rbp
const char *v11; // r15
int *v12; // r13
int v13; // edi
socklen_t v14; // edx
const struct sockaddr *v15; // rsi
__int64 v16; // rax
const char *v17; // r9
const char *v18; // rcx
__int64 result; // rax
int *v20; // rax
const char *v21; // rcx
__int64 v24; // [rsp+10h] [rbp-48h] BYREF
struct addrinfo *ai; // [rsp+18h] [rbp-40h] BYREF

v4 = a3;
v5 = a4;
if ( !(unsigned __int8)voidBufferAllocate(&v24, 48LL, "network connection") )
return 0LL;
v8 = v24;
v9 = 0LL;
if ( v5 )
v9 = name;
*(_DWORD *)v24 = -1;
*(_DWORD *)(v8 + 4) = v4;
*(_BYTE *)(v8 + 8) = 0;
*(_QWORD *)(v8 + 16) = 0LL;
*(_DWORD *)(v8 + 24) = 0;
*(_QWORD *)(v8 + 32) = 0LL;
*(_DWORD *)(v8 + 40) = 0;
if ( (unsigned __int8)func0(v9, service, v4, &ai) )
{
v10 = ai;
if ( ai )
{
v11 = "connect";
v12 = (int *)v24;
if ( !v5 )
v11 = "bind";
while ( 2 )
{
if ( *v12 == -1 )
{
while ( 1 )
{
*v12 = socket(v10->ai_family, v10->ai_socktype, v10->ai_protocol);
v13 = *(_DWORD *)v24;
if ( *(_DWORD *)v24 != -1 )
break;
v20 = _errno_location();
v21 = (const char *)&unk_85A;
if ( v10->ai_next )
v21 = " (going to try another address)";
logWrite(
1LL,
"network.c",
"Cannot open a socket for the network connection%s. (errno = %d)",
v21,
(unsigned int)*v20);
v10 = v10->ai_next;
*(_DWORD *)v24 = -1;
if ( !v10 )
goto LABEL_24;
LABEL_16:
v12 = (int *)v24;
if ( *(_DWORD *)v24 != -1 )
goto LABEL_17;
}
v14 = v10->ai_addrlen;
v15 = v10->ai_addr;
if ( a4 )
{
if ( connect(v13, v15, v14) )
{
LABEL_12:
v16 = (unsigned int)*_errno_location();
v17 = (const char *)&unk_85A;
if ( v10->ai_next )
v17 = " (going to try another address)";
logWrite(
1LL,
"network.c",
"Cannot %s network connection to host \"%s\" on the opened socket%s. (errno = %d)",
v11,
name,
v17,
v16);
func3(v24);
v10 = v10->ai_next;
LABEL_15:
if ( !v10 )
goto LABEL_24;
goto LABEL_16;
}
}
else if ( bind(v13, v15, v14) )
{
goto LABEL_12;
}
if ( (unsigned __int8)func2(v24, name, service) )
{
v12 = (int *)v24;
*(_BYTE *)(v24 + 8) = a4;
continue;
}
func3(v24);
v10 = v10->ai_next;
goto LABEL_15;
}
break;
}
}
else
{
LABEL_24:
func12(&v24);
}
LABEL_17:
freeaddrinfo(ai);
v18 = "UDP";
if ( a3 != 1 )
{
v18 = "TCP";
if ( a3 )
v18 = "(unknown type)";
}
logWrite(4LL, "network.c", "Opened network %s connection to host %s on port %s", v18, name, service);
result = v24;
}
else
{
func12(&v24);
result = 0LL;
}
return result;
}

original_code:
NetworkConnection *networkOpenConnection(const char *hostName, const char *portName, NetworkConnectionType connectionType, _Bool makeClient) {
 NetworkConnection *networkConnection;
 struct addrinfo* addressInfoResult;
 struct addrinfo* addressInfo;
 int connectResult;
 if(!voidBufferAllocate((void **)&networkConnection, sizeof(NetworkConnection), "network connection")) {
  return ((void *)0);
 }
 networkConnection->socketDescriptor = -1;
 networkConnection->connectionType = connectionType;
 networkConnection->isClient = 0;
 networkConnection->localAddress = ((void *)0);
 networkConnection->localAddressSize = 0;
 networkConnection->remoteAddress = ((void *)0);
 networkConnection->remoteAddressSize = 0;
 if(!networkGetAddressInfo(makeClient ? hostName : ((void *)0), portName, connectionType, &addressInfoResult)) {
  networkCloseConnection(&networkConnection);
  return ((void *)0);
 }
 addressInfo = addressInfoResult;
 while(addressInfo != ((void *)0) && networkConnection->socketDescriptor == -1) {
  networkConnection->socketDescriptor = socket(addressInfo->ai_family, addressInfo->ai_socktype, addressInfo->ai_protocol);
  if(networkConnection->socketDescriptor != -1) {
   if(makeClient) {
    connectResult = connect(networkConnection->socketDescriptor, addressInfo->ai_addr, addressInfo->ai_addrlen);
   } else {
    connectResult = bind(networkConnection->socketDescriptor, addressInfo->ai_addr, addressInfo->ai_addrlen);
   }
   if(connectResult == 0) {
    if(networkCopyAddressInfo(networkConnection, hostName, portName)) {
     networkConnection->isClient = makeClient;
    } else {
     networkCloseSocket(networkConnection);
     addressInfo = addressInfo->ai_next;
    }
   } else {
    logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot %s network connection to host \"%s\" on the opened socket%s. (errno = %d)", makeClient ? "connect" : "bind", hostName, addressInfo->ai_next != ((void *)0) ? " (going to try another address)" : "", (*__errno_location ()));
    networkCloseSocket(networkConnection);
    addressInfo = addressInfo->ai_next;
   }
  } else {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot open a socket for the network connection%s. (errno = %d)", addressInfo->ai_next != ((void *)0) ? " (going to try another address)" : "", (*__errno_location ()));
   networkConnection->socketDescriptor = -1;
   addressInfo = addressInfo->ai_next;
  }
 }
 if(addressInfo == ((void *)0)) {
  networkCloseConnection(&networkConnection);
 }
 freeaddrinfo(addressInfoResult);
 logWrite(LOG_LEVEL_DEBUG, LOG_COMPONENT_NAME, "Opened network %s connection to host %s on port %s", connectionType == UDP_CONNECTION ? "UDP" : (connectionType == TCP_CONNECTION ? "TCP" : "(unknown type)"), hostName, portName);
 return networkConnection;
}

canonical_original_code:
struct NetworkConnectionStruct *networkOpenConnection(char *hostName, char *portName, enum NetworkConnectionType connectionType, _Bool makeClient) {
 struct NetworkConnectionStruct *networkConnection;
 struct addrinfo *addressInfoResult;
 struct addrinfo *addressInfo;
 int connectResult;
 if(!voidBufferAllocate((void **)&networkConnection, sizeof(NetworkConnection), "network connection")) {
  return ((void *)0);
 }
 networkConnection->socketDescriptor = -1;
 networkConnection->connectionType = connectionType;
 networkConnection->isClient = 0;
 networkConnection->localAddress = ((void *)0);
 networkConnection->localAddressSize = 0;
 networkConnection->remoteAddress = ((void *)0);
 networkConnection->remoteAddressSize = 0;
 if(!networkGetAddressInfo(makeClient ? hostName : ((void *)0), portName, connectionType, &addressInfoResult)) {
  networkCloseConnection(&networkConnection);
  return ((void *)0);
 }
 addressInfo = addressInfoResult;
 while(addressInfo != ((void *)0) && networkConnection->socketDescriptor == -1) {
  networkConnection->socketDescriptor = socket(addressInfo->ai_family, addressInfo->ai_socktype, addressInfo->ai_protocol);
  if(networkConnection->socketDescriptor != -1) {
   if(makeClient) {
    connectResult = connect(networkConnection->socketDescriptor, addressInfo->ai_addr, addressInfo->ai_addrlen);
   } else {
    connectResult = bind(networkConnection->socketDescriptor, addressInfo->ai_addr, addressInfo->ai_addrlen);
   }
   if(connectResult == 0) {
    if(networkCopyAddressInfo(networkConnection, hostName, portName)) {
     networkConnection->isClient = makeClient;
    } else {
     networkCloseSocket(networkConnection);
     addressInfo = addressInfo->ai_next;
    }
   } else {
    logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot %s network connection to host \"%s\" on the opened socket%s. (errno = %d)", makeClient ? "connect" : "bind", hostName, addressInfo->ai_next != ((void *)0) ? " (going to try another address)" : "", (*__errno_location ()));
    networkCloseSocket(networkConnection);
    addressInfo = addressInfo->ai_next;
   }
  } else {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot open a socket for the network connection%s. (errno = %d)", addressInfo->ai_next != ((void *)0) ? " (going to try another address)" : "", (*__errno_location ()));
   networkConnection->socketDescriptor = -1;
   addressInfo = addressInfo->ai_next;
  }
 }
 if(addressInfo == ((void *)0)) {
  networkCloseConnection(&networkConnection);
 }
 freeaddrinfo(addressInfoResult);
 logWrite(LOG_LEVEL_DEBUG, LOG_COMPONENT_NAME, "Opened network %s connection to host %s on port %s", connectionType == UDP_CONNECTION ? "UDP" : (connectionType == TCP_CONNECTION ? "TCP" : "(unknown type)"), hostName, portName);
 return networkConnection;
}

variable_types:
hostName
char *

variable_types:
portName
char *

variable_types: struct NetworkConnectionStruct { int socketDescriptor; enum NetworkConnectionType { TCP_CONNECTION=0, UDP_CONNECTION=1 } connectionType; _Bool isClient; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *localAddress; unsigned int localAddressSize; struct sockaddr *remoteAddress; unsigned int remoteAddressSize; } *

variable_types: connectResult int


rtspResponseCreate

decompiled_code:
_QWORD *rtspResponseCreate()
{
_QWORD *result; // rax
_QWORD *v1; // [rsp+8h] [rbp-10h] BYREF

if ( !(unsigned __int8)voidBufferAllocate(&v1, 24LL, "RTSP response") )
return 0LL;
result = v1;
*v1 = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax
_QWORD *v1; // [rsp+8h] [rbp-10h] BYREF

if ( !(unsigned __int8)voidBufferAllocate(&v1, 24LL, "RTSP response") )
return 0LL;
result = v1;
*v1 = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
RTSPResponse *rtspResponseCreate() {
 RTSPResponse *rtspResponse;
 if(!voidBufferAllocate((void **)&rtspResponse, sizeof(RTSPResponse), "RTSP response")) {
  return ((void *)0);
 }
 rtspResponse->responseBuffer = ((void *)0);
 rtspResponse->responseBufferSize = 0;
 rtspResponse->maxResponseBufferSize = 0;
 return rtspResponse;
}

canonical_original_code:
struct RTSPResponseStruct *rtspResponseCreate() {
 struct RTSPResponseStruct *rtspResponse;
 if(!voidBufferAllocate((void **)&rtspResponse, sizeof(RTSPResponse), "RTSP response")) {
  return ((void *)0);
 }
 rtspResponse->responseBuffer = ((void *)0);
 rtspResponse->responseBufferSize = 0;
 rtspResponse->maxResponseBufferSize = 0;
 return rtspResponse;
}

variable_types: struct RTSPResponseStruct { unsigned char *responseBuffer; unsigned long responseBufferSize; unsigned long maxResponseBufferSize; } *


rtspResponseGetStatus

decompiled_code:
__int64 __fastcall rtspResponseGetStatus(unsigned __int8 **a1, _WORD *a2)
{
unsigned __int8 *v2; // r8
const unsigned __int16 **v4; // rax
unsigned __int8 *v5; // [rsp+8h] [rbp-20h]
__int16 v6; // [rsp+1Eh] [rbp-Ah] BYREF

v2 = *a1;
if ( *a1 && (unsigned __int64)a1[1] > 0xB )
{
if ( *(_DWORD *)v2 != 1347638354
|| v2[4] != 47
|| (v5 = *a1, v4 = _ctype_b_loc(), ((*v4)[v5[5]] & 0x800) == 0)
|| v5[6] != 46
|| ((*v4)[v5[7]] & 0x800) == 0
|| v5[8] != 32 )
{
logWrite(
1LL,
"rtspresponse.c",
"RTSP Response does not contain correct protocol name and version. Expected \"RTSP/<digit>.<digit><space>\" found \"%.*s\"",
9LL);
return 0LL;
}
if ( (unsigned int)_isoc99_sscanf(v5 + 9, "%hi", &v6) == 1 )
{
*a2 = v6;
return 1LL;
}
logWrite(1LL, "rtspresponse.c", "Cannot read status value from RTSP response");
}
else
{
logWrite(1LL, "rtspresponse.c", "RTSP Response does not contain (enough) buffer content to retrieve status.");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 **a1, _WORD *a2)
{
unsigned __int8 *v2; // r8
const unsigned __int16 **v4; // rax
unsigned __int8 *v5; // [rsp+8h] [rbp-20h]
__int16 v6; // [rsp+1Eh] [rbp-Ah] BYREF

v2 = *a1;
if ( *a1 && (unsigned __int64)a1[1] > 0xB )
{
if ( *(_DWORD *)v2 != 1347638354
|| v2[4] != 47
|| (v5 = *a1, v4 = _ctype_b_loc(), ((*v4)[v5[5]] & 0x800) == 0)
|| v5[6] != 46
|| ((*v4)[v5[7]] & 0x800) == 0
|| v5[8] != 32 )
{
logWrite(
1LL,
"rtspresponse.c",
"RTSP Response does not contain correct protocol name and version. Expected \"RTSP/<digit>.<digit><space>\" found \"%.*s\"",
9LL);
return 0LL;
}
if ( (unsigned int)_isoc99_sscanf(v5 + 9, "%hi", &v6) == 1 )
{
*a2 = v6;
return 1LL;
}
logWrite(1LL, "rtspresponse.c", "Cannot read status value from RTSP response");
}
else
{
logWrite(1LL, "rtspresponse.c", "RTSP Response does not contain (enough) buffer content to retrieve status.");
}
return 0LL;
}

original_code:
_Bool rtspResponseGetStatus(RTSPResponse *rtspResponse, int16_t *status) {
 int16_t intValue;
 if(rtspResponse->responseBuffer == ((void *)0) || rtspResponse->responseBufferSize < 12) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response does not contain (enough) buffer content to retrieve status.");
  return 0;
 }
 if(memcmp(rtspResponse->responseBuffer, "RTSP/", 5) != 0 || !((*__ctype_b_loc ())[(int) ((rtspResponse->responseBuffer[5]))] & (unsigned short int) _ISdigit) || rtspResponse->responseBuffer[6] != '.' || !((*__ctype_b_loc ())[(int) ((rtspResponse->responseBuffer[7]))] & (unsigned short int) _ISdigit) || rtspResponse->responseBuffer[8] != ' ') {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response does not contain correct protocol name and version. Expected \"RTSP/<digit>.<digit><space>\" found \"%.*s\"", 9, rtspResponse->responseBuffer);
  return 0;
 }
 if(sscanf((char *)rtspResponse->responseBuffer + 9, "%" "hi", &intValue) != 1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read status value from RTSP response");
  return 0;
 }
 *status = intValue;
 return 1;
}

canonical_original_code:
_Bool rtspResponseGetStatus(struct RTSPResponseStruct *rtspResponse, short *status) {
 short intValue;
 if(rtspResponse->responseBuffer == ((void *)0) || rtspResponse->responseBufferSize < 12) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response does not contain (enough) buffer content to retrieve status.");
  return 0;
 }
 if(memcmp(rtspResponse->responseBuffer, "RTSP/", 5) != 0 || !((*__ctype_b_loc ())[(int) ((rtspResponse->responseBuffer[5]))] & (unsigned short) _ISdigit) || rtspResponse->responseBuffer[6] != '.' || !((*__ctype_b_loc ())[(int) ((rtspResponse->responseBuffer[7]))] & (unsigned short) _ISdigit) || rtspResponse->responseBuffer[8] != ' ') {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response does not contain correct protocol name and version. Expected \"RTSP/<digit>.<digit><space>\" found \"%.*s\"", 9, rtspResponse->responseBuffer);
  return 0;
 }
 if(sscanf((char *)rtspResponse->responseBuffer + 9, "%" "hi", &intValue) != 1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read status value from RTSP response");
  return 0;
 }
 *status = intValue;
 return 1;
}

variable_types:
status
short *

variable_types: intValue short

user_defined_types: struct RTSPResponseStruct { unsigned char *responseBuffer; unsigned long responseBufferSize; unsigned long maxResponseBufferSize; }


rtspResponseGetSequenceNumber

decompiled_code:
__int64 __fastcall rtspResponseGetSequenceNumber(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-Ch] BYREF

v2 = rtspResponseFindValueForKey(a1, "CSeq", 0LL);
if ( v2 )
{
if ( (unsigned int)_isoc99_sscanf(v2, "%u", &v4) == 1 )
{
*a2 = v4;
result = 1LL;
}
else
{
logWrite(1LL, "rtspresponse.c", "Cannot read CSeq value from RTSP response");
result = 0LL;
}
}
else
{
logWrite(2LL, "rtspresponse.c", "No CSeq value in RTSP response (continuing anyway)");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax
int v4; // [rsp+Ch] [rbp-Ch] BYREF

v2 = func0(a1, "CSeq", 0LL);
if ( v2 )
{
if ( (unsigned int)_isoc99_sscanf(v2, "%u", &v4) == 1 )
{
*a2 = v4;
result = 1LL;
}
else
{
logWrite(1LL, "rtspresponse.c", "Cannot read CSeq value from RTSP response");
result = 0LL;
}
}
else
{
logWrite(2LL, "rtspresponse.c", "No CSeq value in RTSP response (continuing anyway)");
result = 1LL;
}
return result;
}

original_code:
_Bool rtspResponseGetSequenceNumber(RTSPResponse *rtspResponse, uint32_t *sequenceNumber) {
 uint8_t *value;
 uint32_t uint32Value;
 value = rtspResponseFindValueForKey(rtspResponse, "CSeq", ((void *)0));
 if(value != ((void *)0)) {
  if(sscanf((char *)value, "%" "u", &uint32Value) != 1) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read CSeq value from RTSP response");
   return 0;
  }
  *sequenceNumber = uint32Value;
 } else {
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "No CSeq value in RTSP response (continuing anyway)");
 }
 return 1;
}

canonical_original_code:
_Bool rtspResponseGetSequenceNumber(struct RTSPResponseStruct *rtspResponse, unsigned int *sequenceNumber) {
 unsigned char *value;
 unsigned int uint32Value;
 value = rtspResponseFindValueForKey(rtspResponse, "CSeq", ((void *)0));
 if(value != ((void *)0)) {
  if(sscanf((char *)value, "%" "u", &uint32Value) != 1) {
   logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read CSeq value from RTSP response");
   return 0;
  }
  *sequenceNumber = uint32Value;
 } else {
  logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "No CSeq value in RTSP response (continuing anyway)");
 }
 return 1;
}

variable_types:
sequenceNumber
unsigned int *

variable_types:
value
unsigned char *


rtspResponseGetSession

decompiled_code:
__int64 __fastcall rtspResponseGetSession(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v5; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 0;
v3 = rtspResponseFindValueForKey(a1, "Session", 0LL);
if ( !v3 )
return v2;
if ( (unsigned int)_isoc99_sscanf(v3, "%x", &v5) == 1 )
{
v2 = 1;
*a2 = v5;
return v2;
}
logWrite(1LL, "rtspresponse.c", "Cannot read Session value from RTSP response");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _DWORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax
int v5; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 0;
v3 = func0(a1, "Session", 0LL);
if ( !v3 )
return v2;
if ( (unsigned int)_isoc99_sscanf(v3, "%x", &v5) == 1 )
{
v2 = 1;
*a2 = v5;
return v2;
}
logWrite(1LL, "rtspresponse.c", "Cannot read Session value from RTSP response");
return 0LL;
}

original_code:
_Bool rtspResponseGetSession(RTSPResponse *rtspResponse, uint32_t *session) {
 uint8_t *value;
 uint32_t uint32Value;
 value = rtspResponseFindValueForKey(rtspResponse, "Session", ((void *)0));
 if(value == ((void *)0)) {
  return 0;
 }
 if(sscanf((char *)value, "%" "x", &uint32Value) != 1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read Session value from RTSP response");
  return 0;
 }
 *session = uint32Value;
 return 1;
}

canonical_original_code:
_Bool rtspResponseGetSession(struct RTSPResponseStruct *rtspResponse, unsigned int *session) {
 unsigned char *value;
 unsigned int uint32Value;
 value = rtspResponseFindValueForKey(rtspResponse, "Session", ((void *)0));
 if(value == ((void *)0)) {
  return 0;
 }
 if(sscanf((char *)value, "%" "x", &uint32Value) != 1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read Session value from RTSP response");
  return 0;
 }
 *session = uint32Value;
 return 1;
}

variable_types:
session
unsigned int *


rtspResponseGetServerPort

decompiled_code:
__int64 __fastcall rtspResponseGetServerPort(__int64 a1, _WORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax
__int16 v5; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = 0;
v3 = rtspResponseFindValueForKey(a1, "Transport", "server_port");
if ( !v3 )
return v2;
if ( (unsigned int)_isoc99_sscanf(v3, "%hi", &v5) == 1 )
{
v2 = 1;
*a2 = v5;
return v2;
}
logWrite(1LL, "rtspresponse.c", "Cannot read Transport:server_port value from RTSP response");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _WORD *a2)
{
unsigned int v2; // er12
__int64 v3; // rax
__int16 v5; // [rsp+Eh] [rbp-1Ah] BYREF

v2 = 0;
v3 = func0(a1, "Transport", "server_port");
if ( !v3 )
return v2;
if ( (unsigned int)_isoc99_sscanf(v3, "%hi", &v5) == 1 )
{
v2 = 1;
*a2 = v5;
return v2;
}
logWrite(1LL, "rtspresponse.c", "Cannot read Transport:server_port value from RTSP response");
return 0LL;
}

original_code:
_Bool rtspResponseGetServerPort(RTSPResponse *rtspResponse, int16_t *serverPort) {
 uint8_t *value;
 int16_t int16Value;
 value = rtspResponseFindValueForKey(rtspResponse, "Transport", "server_port");
 if(value == ((void *)0)) {
  return 0;
 }
 if(sscanf((char *)value, "%" "hi", &int16Value) != 1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read Transport:server_port value from RTSP response");
  return 0;
 }
 *serverPort = int16Value;
 return 1;
}

canonical_original_code:
_Bool rtspResponseGetServerPort(struct RTSPResponseStruct *rtspResponse, short *serverPort) {
 unsigned char *value;
 short int16Value;
 value = rtspResponseFindValueForKey(rtspResponse, "Transport", "server_port");
 if(value == ((void *)0)) {
  return 0;
 }
 if(sscanf((char *)value, "%" "hi", &int16Value) != 1) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot read Transport:server_port value from RTSP response");
  return 0;
 }
 *serverPort = int16Value;
 return 1;
}

variable_types:
serverPort
short *


rtspResponseGetAuthenticationResponse

decompiled_code:
__int64 __fastcall rtspResponseGetAuthenticationResponse(_QWORD *a1, void *a2, unsigned int a3, unsigned int *a4, void *a5, unsigned int a6, unsigned int *a7)
{
const void *v10; // rax
size_t v11; // r14
char *v12; // rax
char *v13; // rcx
const char *v14; // rdx
char *v15; // rbx
__int64 result; // rax
size_t v17; // r8
void *v18; // r10
const void *v19; // r11
bool v20; // dl
char v21; // al
unsigned int v22; // ebx
char *v23; // r14
char *v24; // r9
size_t *v25; // rax
char *v26; // r8
size_t v27; // [rsp+8h] [rbp-60h]
unsigned int v28; // [rsp+8h] [rbp-60h]
size_t v29; // [rsp+8h] [rbp-60h]
void *src; // [rsp+18h] [rbp-50h]
void *srca; // [rsp+18h] [rbp-50h]
unsigned int n[16]; // [rsp+28h] [rbp-40h] BYREF

v10 = (const void *)rtspResponseFindValueForKey((__int64)a1, "WWW-Authenticate", 0LL);
if ( !v10 )
return 0LL;
v27 = (size_t)v10;
v11 = a1[1] - ((unsigned __int64)v10 - *a1);
v12 = (char *)memchr(v10, 10, v11);
v13 = (char *)v11;
v14 = "RTSP Response has field WWW-Authenticate with unknown content %.*s";
v15 = v12;
if ( !v12 )
goto LABEL_6;
v13 = &v12[-v27];
if ( (__int64)&v12[-v27] <= 6
|| *(_DWORD *)v27 != 1701275972
|| *(_WORD *)(v27 + 4) != 29811
|| *(_BYTE *)(v27 + 6) != 32 )
{
v14 = "RTSP Response has field WWW-Authenticate with unknown method %.*s";
LABEL_6:
logWrite(1LL, "rtspresponse.c", v14, v13, v27);
return 0LL;
}
v17 = v27 + 7;
v18 = 0LL;
v19 = 0LL;
while ( 1 )
{
v20 = v18 == 0LL || v19 == 0LL;
LABEL_12:
if ( v17 >= (unsigned __int64)v15 )
break;
if ( !v20 )
goto LABEL_19;
while ( 1 )
{
v21 = *(_BYTE *)v17;
if ( *(_BYTE *)v17 != 32 )
break;
if ( v15 == (char *)++v17 )
goto LABEL_12;
}
if ( v17 >= (unsigned __int64)v15 )
break;
if ( (__int64)&v15[-v17] <= 6 )
goto LABEL_27;
if ( *(_DWORD *)v17 == 1818322290 && *(_WORD *)(v17 + 4) == 15725 && *(_BYTE *)(v17 + 6) == 34 )
{
v24 = (char *)(v17 + 7);
v25 = (size_t *)n;
v19 = (const void *)(v17 + 7);
}
else
{
if ( *(_DWORD *)v17 != 1668181870 || *(_WORD *)(v17 + 4) != 15717 || *(_BYTE *)(v17 + 6) != 34 )
{
LABEL_27:
v23 = (char *)v17;
while ( v21 != 34 )
{
if ( v15 <= ++v23 )
goto LABEL_56;
v21 = *v23;
}
if ( v23 < v15 && *(v23 - 1) == 61 )
{
srca = v18;
v29 = (size_t)v19;
logWrite(
2LL,
"rtspresponse.c",
"Unknown field %.*s found in WWW-Authenticate. Skipping the value.",
&v23[-v17]);
v18 = srca;
v24 = v23 + 1;
v25 = 0LL;
v19 = (const void *)v29;
goto LABEL_34;
}
LABEL_56:
logWrite(1LL, "rtspresponse.c", "Unknown field %.*s in WWW-Authenticate.", &v15[-v17], v17);
return 0LL;
}
v24 = (char *)(v17 + 7);
v25 = (size_t *)&n[1];
v18 = (void *)(v17 + 7);
}
LABEL_34:
if ( v24 >= v15 )
goto LABEL_55;
v26 = v24;
while ( *v26 != 34 )
{
if ( v15 == ++v26 )
goto LABEL_55;
}
if ( v15 <= v26 )
{
LABEL_55:
logWrite(1LL, "rtspresponse.c", "Incomplete field value (not properly terminated by a double quote).");
return 0LL;
}
if ( v25 )
*(_DWORD *)v25 = (_DWORD)v26 - (_DWORD)v24;
v17 = (size_t)(v26 + 1);
if ( (unsigned __int64)v15 > v17 )
{
do
{
if ( *(_BYTE *)v17 != 32 && *(_BYTE *)v17 != 44 )
break;
++v17;
}
while ( v15 != (char *)v17 );
}
}
if ( v20 )
{
logWrite(1LL, "rtspresponse.c", "RTSP Response incomplete, fields 'realm' or 'nonce' not present.");
return 0LL;
}
LABEL_19:
v22 = n[0];
if ( n[0] > a3 || n[1] > a6 )
{
logWrite(
1LL,
"rtspresponse.c",
"RTSP Response contains value(s) which are too long for buffer. Buffer for 'realm' is %u and buffer for 'nonce' is %u.",
a3,
a6);
result = 0LL;
}
else
{
v28 = n[1];
src = v18;
memcpy(a2, v19, n[0]);
*a4 = v22;
memcpy(a5, src, v28);
*a7 = v28;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, void *a2, unsigned int a3, unsigned int *a4, void *a5, unsigned int a6, unsigned int *a7)
{
const void *v10; // rax
size_t v11; // r14
char *v12; // rax
char *v13; // rcx
const char *v14; // rdx
char *v15; // rbx
__int64 result; // rax
size_t v17; // r8
void *v18; // r10
const void *v19; // r11
bool v20; // dl
char v21; // al
unsigned int v22; // ebx
char *v23; // r14
char *v24; // r9
size_t *v25; // rax
char *v26; // r8
size_t v27; // [rsp+8h] [rbp-60h]
unsigned int v28; // [rsp+8h] [rbp-60h]
size_t v29; // [rsp+8h] [rbp-60h]
void *src; // [rsp+18h] [rbp-50h]
void *srca; // [rsp+18h] [rbp-50h]
unsigned int n[16]; // [rsp+28h] [rbp-40h] BYREF

v10 = (const void *)func0((__int64)a1, "WWW-Authenticate", 0LL);
if ( !v10 )
return 0LL;
v27 = (size_t)v10;
v11 = a1[1] - ((unsigned __int64)v10 - *a1);
v12 = (char *)memchr(v10, 10, v11);
v13 = (char *)v11;
v14 = "RTSP Response has field WWW-Authenticate with unknown content %.*s";
v15 = v12;
if ( !v12 )
goto LABEL_6;
v13 = &v12[-v27];
if ( (__int64)&v12[-v27] <= 6
|| *(_DWORD *)v27 != 1701275972
|| *(_WORD *)(v27 + 4) != 29811
|| *(_BYTE *)(v27 + 6) != 32 )
{
v14 = "RTSP Response has field WWW-Authenticate with unknown method %.*s";
LABEL_6:
logWrite(1LL, "rtspresponse.c", v14, v13, v27);
return 0LL;
}
v17 = v27 + 7;
v18 = 0LL;
v19 = 0LL;
while ( 1 )
{
v20 = v18 == 0LL || v19 == 0LL;
LABEL_12:
if ( v17 >= (unsigned __int64)v15 )
break;
if ( !v20 )
goto LABEL_19;
while ( 1 )
{
v21 = *(_BYTE *)v17;
if ( *(_BYTE *)v17 != 32 )
break;
if ( v15 == (char *)++v17 )
goto LABEL_12;
}
if ( v17 >= (unsigned __int64)v15 )
break;
if ( (__int64)&v15[-v17] <= 6 )
goto LABEL_27;
if ( *(_DWORD *)v17 == 1818322290 && *(_WORD *)(v17 + 4) == 15725 && *(_BYTE *)(v17 + 6) == 34 )
{
v24 = (char *)(v17 + 7);
v25 = (size_t *)n;
v19 = (const void *)(v17 + 7);
}
else
{
if ( *(_DWORD *)v17 != 1668181870 || *(_WORD *)(v17 + 4) != 15717 || *(_BYTE *)(v17 + 6) != 34 )
{
LABEL_27:
v23 = (char *)v17;
while ( v21 != 34 )
{
if ( v15 <= ++v23 )
goto LABEL_56;
v21 = *v23;
}
if ( v23 < v15 && *(v23 - 1) == 61 )
{
srca = v18;
v29 = (size_t)v19;
logWrite(
2LL,
"rtspresponse.c",
"Unknown field %.*s found in WWW-Authenticate. Skipping the value.",
&v23[-v17]);
v18 = srca;
v24 = v23 + 1;
v25 = 0LL;
v19 = (const void *)v29;
goto LABEL_34;
}
LABEL_56:
logWrite(1LL, "rtspresponse.c", "Unknown field %.*s in WWW-Authenticate.", &v15[-v17], v17);
return 0LL;
}
v24 = (char *)(v17 + 7);
v25 = (size_t *)&n[1];
v18 = (void *)(v17 + 7);
}
LABEL_34:
if ( v24 >= v15 )
goto LABEL_55;
v26 = v24;
while ( *v26 != 34 )
{
if ( v15 == ++v26 )
goto LABEL_55;
}
if ( v15 <= v26 )
{
LABEL_55:
logWrite(1LL, "rtspresponse.c", "Incomplete field value (not properly terminated by a double quote).");
return 0LL;
}
if ( v25 )
*(_DWORD *)v25 = (_DWORD)v26 - (_DWORD)v24;
v17 = (size_t)(v26 + 1);
if ( (unsigned __int64)v15 > v17 )
{
do
{
if ( *(_BYTE *)v17 != 32 && *(_BYTE *)v17 != 44 )
break;
++v17;
}
while ( v15 != (char *)v17 );
}
}
if ( v20 )
{
logWrite(1LL, "rtspresponse.c", "RTSP Response incomplete, fields 'realm' or 'nonce' not present.");
return 0LL;
}
LABEL_19:
v22 = n[0];
if ( n[0] > a3 || n[1] > a6 )
{
logWrite(
1LL,
"rtspresponse.c",
"RTSP Response contains value(s) which are too long for buffer. Buffer for 'realm' is %u and buffer for 'nonce' is %u.",
a3,
a6);
result = 0LL;
}
else
{
v28 = n[1];
src = v18;
memcpy(a2, v19, n[0]);
*a4 = v22;
memcpy(a5, src, v28);
*a7 = v28;
result = 1LL;
}
return result;
}

original_code:
_Bool rtspResponseGetAuthenticationResponse(RTSPResponse *rtspResponse, char *realmBuffer, uint32_t maxRealmBufferSize, uint32_t *realmBufferSize, char *nonceBuffer, uint32_t maxNonceBufferSize, uint32_t *nonceBufferSize) {
 char *value;
 char *endValue;
 char *realmValue;
 uint32_t realmValueSize;
 char *nonceValue;
 uint32_t nonceValueSize;
 uint32_t *fieldValueSize;
 char *tempValue;
 value = (char *)rtspResponseFindValueForKey(rtspResponse, "WWW-Authenticate", ((void *)0));
 if(value == ((void *)0)) {
  return 0;
 }
 realmValue = ((void *)0);
 nonceValue = ((void *)0);
 endValue = memchr(value, ((uint8_t)'\n'), rtspResponse->responseBufferSize - (value - (char *)rtspResponse->responseBuffer));
 if(endValue == ((void *)0)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response has field WWW-Authenticate with unknown content %.*s", rtspResponse->responseBufferSize - (value - (char *)rtspResponse->responseBuffer), value);
  return 0;
 }
 if(endValue - value < 7 || memcmp(value, "Digest ", 7) != 0) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response has field WWW-Authenticate with unknown method %.*s", endValue - value, value);
  return 0;
 }
 value += 7;
 while(value < endValue && (realmValue == ((void *)0) || nonceValue == ((void *)0))) {
  while(value < endValue && *value == ' ') {
   value++;
  }
  if(value < endValue) {
   if(endValue - value >= 7 && memcmp(value, "realm=\"", 7) == 0) {
    value += 7;
    realmValue = value;
    fieldValueSize = &realmValueSize;
   } else if(endValue - value >= 7 && memcmp(value, "nonce=\"", 7) == 0) {
    value += 7;
    nonceValue = value;
    fieldValueSize = &nonceValueSize;
   } else {
    tempValue = value;
    while(value < endValue && *value != '"') {
     value++;
    }
    if(value >= endValue || *(value - 1) != '=') {
     logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unknown field %.*s in WWW-Authenticate.", endValue - tempValue, tempValue);
     return 0;
    }
    logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Unknown field %.*s found in WWW-Authenticate. Skipping the value.", value - tempValue, tempValue);
    value++;
    fieldValueSize = ((void *)0);
   }
   tempValue = value;
   while(value < endValue && *value != '"') {
    value++;
   }
   if(value >= endValue) {
    logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Incomplete field value (not properly terminated by a double quote).");
    return 0;
   }
   if(fieldValueSize != ((void *)0)) {
    *fieldValueSize = value - tempValue;
   }
   value++;
   while(value < endValue && (*value == ' ' || *value == ',')) {
    value++;
   }
  }
 }
 if(realmValue == ((void *)0) || nonceValue == ((void *)0)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response incomplete, fields 'realm' or 'nonce' not present.");
  return 0;
 }
 if(maxRealmBufferSize < realmValueSize || maxNonceBufferSize < nonceValueSize) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response contains value(s) which are too long for buffer. Buffer for 'realm' is %" "u" " and buffer for 'nonce' is %" "u" ".", maxRealmBufferSize, maxNonceBufferSize);
  return 0;
 }
 memcpy(realmBuffer, realmValue, realmValueSize);
 *realmBufferSize = realmValueSize;
 memcpy(nonceBuffer, nonceValue, nonceValueSize);
 *nonceBufferSize = nonceValueSize;
 return 1;
}

canonical_original_code:
_Bool rtspResponseGetAuthenticationResponse(struct RTSPResponseStruct *rtspResponse, char *realmBuffer, unsigned int maxRealmBufferSize, unsigned int *realmBufferSize, char *nonceBuffer, unsigned int maxNonceBufferSize, unsigned int *nonceBufferSize) {
 char *value;
 char *endValue;
 char *realmValue;
 unsigned int realmValueSize;
 char *nonceValue;
 unsigned int nonceValueSize;
 unsigned int *fieldValueSize;
 char *tempValue;
 value = (char *)rtspResponseFindValueForKey(rtspResponse, "WWW-Authenticate", ((void *)0));
 if(value == ((void *)0)) {
  return 0;
 }
 realmValue = ((void *)0);
 nonceValue = ((void *)0);
 endValue = memchr(value, ((unsigned char)'\n'), rtspResponse->responseBufferSize - (value - (char *)rtspResponse->responseBuffer));
 if(endValue == ((void *)0)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response has field WWW-Authenticate with unknown content %.*s", rtspResponse->responseBufferSize - (value - (char *)rtspResponse->responseBuffer), value);
  return 0;
 }
 if(endValue - value < 7 || memcmp(value, "Digest ", 7) != 0) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response has field WWW-Authenticate with unknown method %.*s", endValue - value, value);
  return 0;
 }
 value += 7;
 while(value < endValue && (realmValue == ((void *)0) || nonceValue == ((void *)0))) {
  while(value < endValue && *value == ' ') {
   value++;
  }
  if(value < endValue) {
   if(endValue - value >= 7 && memcmp(value, "realm=\"", 7) == 0) {
    value += 7;
    realmValue = value;
    fieldValueSize = &realmValueSize;
   } else if(endValue - value >= 7 && memcmp(value, "nonce=\"", 7) == 0) {
    value += 7;
    nonceValue = value;
    fieldValueSize = &nonceValueSize;
   } else {
    tempValue = value;
    while(value < endValue && *value != '"') {
     value++;
    }
    if(value >= endValue || *(value - 1) != '=') {
     logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Unknown field %.*s in WWW-Authenticate.", endValue - tempValue, tempValue);
     return 0;
    }
    logWrite(LOG_LEVEL_WARNING, LOG_COMPONENT_NAME, "Unknown field %.*s found in WWW-Authenticate. Skipping the value.", value - tempValue, tempValue);
    value++;
    fieldValueSize = ((void *)0);
   }
   tempValue = value;
   while(value < endValue && *value != '"') {
    value++;
   }
   if(value >= endValue) {
    logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Incomplete field value (not properly terminated by a double quote).");
    return 0;
   }
   if(fieldValueSize != ((void *)0)) {
    *fieldValueSize = value - tempValue;
   }
   value++;
   while(value < endValue && (*value == ' ' || *value == ',')) {
    value++;
   }
  }
 }
 if(realmValue == ((void *)0) || nonceValue == ((void *)0)) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response incomplete, fields 'realm' or 'nonce' not present.");
  return 0;
 }
 if(maxRealmBufferSize < realmValueSize || maxNonceBufferSize < nonceValueSize) {
  logWrite(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "RTSP Response contains value(s) which are too long for buffer. Buffer for 'realm' is %" "u" " and buffer for 'nonce' is %" "u" ".", maxRealmBufferSize, maxNonceBufferSize);
  return 0;
 }
 memcpy(realmBuffer, realmValue, realmValueSize);
 *realmBufferSize = realmValueSize;
 memcpy(nonceBuffer, nonceValue, nonceValueSize);
 *nonceBufferSize = nonceValueSize;
 return 1;
}

variable_types:
realmBuffer
char *

variable_types:
maxRealmBufferSize
unsigned int

variable_types:
realmBufferSize
unsigned int *

variable_types:
nonceBuffer
char *

variable_types:
maxNonceBufferSize
unsigned int

variable_types:
nonceBufferSize
unsigned int *

variable_types:
value
char *

variable_types:
endValue
char *

variable_types:
realmValue
char *

variable_types:
realmValueSize
unsigned int

variable_types:
nonceValue
char *

variable_types:
nonceValueSize
unsigned int

variable_types:
fieldValueSize
unsigned int *

variable_types:
tempValue
char *


rtspResponseFree

decompiled_code:
__int64 __fastcall rtspResponseFree(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi

v1 = 1;
v3 = *a1;
if ( v3 )
{
v1 = voidBufferFree(v3);
if ( !(unsigned __int8)voidBufferFree(a1) )
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
unsigned int v1; // er12
__int64 v3; // rdi

v1 = 1;
v3 = *a1;
if ( v3 )
{
v1 = voidBufferFree(v3);
if ( !(unsigned __int8)voidBufferFree(a1) )
v1 = 0;
}
return v1;
}

original_code:
_Bool rtspResponseFree(RTSPResponse **rtspResponse) {
 _Bool result;
 result = 1;
 if(*rtspResponse != ((void *)0)) {
  if(!voidBufferFree((void **)&(*rtspResponse)->responseBuffer)) {
   result = 0;
  }
  if(!voidBufferFree((void **)rtspResponse)) {
   result = 0;
  }
 }
 return result;
}

canonical_original_code:
_Bool rtspResponseFree(struct RTSPResponseStruct **rtspResponse) {
 _Bool result;
 result = 1;
 if(*rtspResponse != ((void *)0)) {
  if(!voidBufferFree((void **)&(*rtspResponse)->responseBuffer)) {
   result = 0;
  }
  if(!voidBufferFree((void **)rtspResponse)) {
   result = 0;
  }
 }
 return result;
}

variable_types: struct RTSPResponseStruct { unsigned char *responseBuffer; unsigned long responseBufferSize; unsigned long maxResponseBufferSize; } **


logSetLogLevel

decompiled_code:
void __fastcall logSetLogLevel(int a1)
{
defaultLogLevel = a1;
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
defaultLogLevel = a1;
}

original_code:
void logSetLogLevel(LogLevel newDefaultlogLevel) {
 defaultLogLevel = newDefaultlogLevel;
}

canonical_original_code:
void logSetLogLevel(enum LogLevel newDefaultlogLevel) {
 defaultLogLevel = newDefaultlogLevel;
}

variable_types: enum LogLevel { LOG_LEVEL_FATAL=0, LOG_LEVEL_ERROR=1, LOG_LEVEL_WARNING=2, LOG_LEVEL_INFO=3, LOG_LEVEL_DEBUG=4 }


logWrite

original_code:
_Bool logWrite(LogLevel logLevel, const char *componentName, const char *logFormat, ...) {
 _Bool result;
 va_list argumentList;
 if(logLevel > defaultLogLevel) {
  return 1;
 }
 __builtin_va_start(argumentList,logFormat);
 result = logWriteMessage(logFile != ((void *)0) ? logFile : stderr, logLevel, componentName, logFormat, argumentList);
 __builtin_va_end(argumentList);
 return result;
}

canonical_original_code:
_Bool logWrite(enum LogLevel logLevel, char *componentName, char *logFormat, ...) {
 _Bool result;
 __builtin_va_list argumentList;
 if(logLevel > defaultLogLevel) {
  return 1;
 }
 __builtin_va_start(argumentList,logFormat);
 result = logWriteMessage(logFile != ((void *)0) ? logFile : stderr, logLevel, componentName, logFormat, argumentList);
 __builtin_va_end(argumentList);
 return result;
}

variable_types:
componentName
char *

variable_types:
logFormat
char *

user_defined_types: enum LogLevel { LOG_LEVEL_FATAL=0, LOG_LEVEL_ERROR=1, LOG_LEVEL_WARNING=2, LOG_LEVEL_INFO=3, LOG_LEVEL_DEBUG=4 }


logClose

decompiled_code:
__int64 logClose()
{
__int64 result; // rax
int *v1; // rax

result = 1LL;
if ( logFile )
{
if ( logFileOpenedLocally )
{
if ( fclose(logFile) )
{
v1 = _errno_location();
logWriteInternal_constprop_0(1LL, "log.c", "Cannot close logfile. (errno = %d)", (unsigned int)*v1);
result = 0LL;
logFile = 0LL;
}
else
{
logFile = 0LL;
result = 1LL;
}
}
else
{
logFile = 0LL;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
int *v1; // rax

result = 1LL;
if ( logFile )
{
if ( logFileOpenedLocally )
{
if ( fclose(logFile) )
{
v1 = _errno_location();
func1(1LL, "log.c", "Cannot close logfile. (errno = %d)", (unsigned int)*v1);
result = 0LL;
logFile = 0LL;
}
else
{
logFile = 0LL;
result = 1LL;
}
}
else
{
logFile = 0LL;
result = 1LL;
}
}
return result;
}

original_code:
_Bool logClose() {
 if(logFile != ((void *)0)) {
  if(logFileOpenedLocally) {
   if(fclose(logFile) != 0) {
    logWriteInternal(LOG_LEVEL_ERROR, LOG_COMPONENT_NAME, "Cannot close logfile. (errno = %d)", (*__errno_location ()));
    logFile = ((void *)0);
    return 0;
   }
  }
  logFile = ((void *)0);
 }
 return 1;
}


rtspRequestReset

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

v2 = *(_BYTE **)(a1 + 8);
if ( v2 )
{
*v2 = 0;
result = 1LL;
*(_QWORD *)(a1 + 16) = 1LL;
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
result = 1LL;
}
*(_QWORD *)(a1 + 40) = 0LL;
*(_DWORD *)a1 = a2;
return result;
}

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

v2 = *(_BYTE **)(a1 + 8);
if ( v2 )
{
*v2 = 0;
result = 1LL;
*(_QWORD *)(a1 + 16) = 1LL;
}
else
{
*(_QWORD *)(a1 + 16) = 0LL;
result = 1LL;
}
*(_QWORD *)(a1 + 40) = 0LL;
*(_DWORD *)a1 = a2;
return result;
}

original_code:
_Bool rtspRequestReset(RTSPRequest *rtspRequest, RTSPRequestMethod requestMethod) {
 if(rtspRequest->headerBuffer != ((void *)0)) {
  rtspRequest->headerBuffer[0] = '\0';
  rtspRequest->headerBufferSize = 1;
 } else {
  rtspRequest->headerBufferSize = 0;
 }
 rtspRequest->contentBufferSize = 0;
 rtspRequest->requestMethod = requestMethod;
 return 1;
}

canonical_original_code:
_Bool rtspRequestReset(struct RTSPRequestStruct *rtspRequest, enum RTSPRequestMethod requestMethod) {
 if(rtspRequest->headerBuffer != ((void *)0)) {
  rtspRequest->headerBuffer[0] = '\0';
  rtspRequest->headerBufferSize = 1;
 } else {
  rtspRequest->headerBufferSize = 0;
 }
 rtspRequest->contentBufferSize = 0;
 rtspRequest->requestMethod = requestMethod;
 return 1;
}

variable_types: struct RTSPRequestStruct { enum RTSPRequestMethod { RTSP_METHOD_OPTIONS=0, RTSP_METHOD_ANNOUNCE=1, RTSP_METHOD_SETUP=2, RTSP_METHOD_RECORD=3, RTSP_METHOD_SET_PARAMETER=4, RTSP_METHOD_FLUSH=5, RTSP_METHOD_TEARDOWN=6 } requestMethod; unsigned char *headerBuffer; unsigned long headerBufferSize; unsigned long maxHeaderBufferSize; unsigned char *contentBuffer; unsigned long contentBufferSize; } *

user_defined_types: struct RTSPRequestStruct { enum RTSPRequestMethod requestMethod; unsigned char *headerBuffer; unsigned long headerBufferSize; unsigned long maxHeaderBufferSize; unsigned char *contentBuffer; unsigned long contentBufferSize; }


rtspRequestGetMethodName

decompiled_code:
char *__fastcall rtspRequestGetMethodName(unsigned int *a1)
{
return (&METHOD_NAMES)[*a1];
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int *a1)
{
return (&METHOD_NAMES)[*a1];
}

original_code:
const char *rtspRequestGetMethodName(RTSPRequest *rtspRequest) {
 return METHOD_NAMES[rtspRequest->requestMethod];
}

canonical_original_code:
char *rtspRequestGetMethodName(struct RTSPRequestStruct *rtspRequest) {
 return METHOD_NAMES[rtspRequest->requestMethod];
}

return_type: char *

user_defined_types: enum RTSPRequestMethod { RTSP_METHOD_OPTIONS=0, RTSP_METHOD_ANNOUNCE=1, RTSP_METHOD_SETUP=2, RTSP_METHOD_RECORD=3, RTSP_METHOD_SET_PARAMETER=4, RTSP_METHOD_FLUSH=5, RTSP_METHOD_TEARDOWN=6 }