followDirEntry

decompiled_code:
__int64 __fastcall followDirEntry(__int64 a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
unsigned int v4; // ecx
int v5; // edi
unsigned __int16 v6; // dx

v2 = *(_BYTE *)(a1 + 11);
result = 0LL;
if ( v2 != 15 )
{
if ( (v2 & 8) != 0 )
{
puts("Volume label, not a file");
result = 0LL;
}
else
{
v4 = *(unsigned __int16 *)(a1 + 26);
if ( v4 <= 1 )
{
puts("Not a valid starting cluster");
result = 0LL;
}
else
{
v5 = (clusterSize + *(unsigned __int16 *)(a1 + 28) + (*(unsigned __int16 *)(a1 + 30) << 16) - 1) / clusterSize;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v6 = *(_WORD *)(a2 + 2LL * (int)v4);
v4 = v6;
}
while ( (unsigned __int16)(v6 - 1) <= 0xFEEu && v5 > (int)result );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char v2; // dl
__int64 result; // rax
unsigned int v4; // ecx
int v5; // edi
unsigned __int16 v6; // dx

v2 = *(_BYTE *)(a1 + 11);
result = 0LL;
if ( v2 != 15 )
{
if ( (v2 & 8) != 0 )
{
puts("Volume label, not a file");
result = 0LL;
}
else
{
v4 = *(unsigned __int16 *)(a1 + 26);
if ( v4 <= 1 )
{
puts("Not a valid starting cluster");
result = 0LL;
}
else
{
v5 = (clusterSize + *(unsigned __int16 *)(a1 + 28) + (*(unsigned __int16 *)(a1 + 30) << 16) - 1) / clusterSize;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v6 = *(_WORD *)(a2 + 2LL * (int)v4);
v4 = v6;
}
while ( (unsigned __int16)(v6 - 1) <= 0xFEEu && v5 > (int)result );
}
}
}
return result;
}

original_code:
int followDirEntry(dirEntry *e, unsigned short *sFAT){
 int cur =e->start;
 int next;
 int nclusters = 0;
 int size = ((e->length[0] & 0xffff) + (((long)(e->length[1] & 0xffff)) << 16));
 int nexpected = 0;
 nexpected = (size + clusterSize - 1) / clusterSize;
 if(e->attrib == 0x0f){
  return 0;
 }
 if(e->attrib & 0x08){
  printf("Volume label, not a file\n");
  return 0;
 }
 if(cur < 2){
  printf("Not a valid starting cluster\n");
  return 0;
 }
 do{
  nclusters++;
  next = sFAT[cur];
  cur = next;
 }while(next && (next < 0x0FF0) && (nclusters < nexpected));
 return nclusters;
}

canonical_original_code:
int followDirEntry(struct DIRENTRY *e, unsigned short *sFAT){
 int cur = e->start;
 int next;
 int nclusters = 0;
 int size = ((e->length[0] & 0xffff) + (((long)(e->length[1] & 0xffff)) << 16));
 int nexpected = 0;
 nexpected = (size + clusterSize - 1) / clusterSize;
 if(e->attrib == 0x0f){
  return 0;
 }
 if(e->attrib & 0x08){
  printf("Volume label, not a file\n");
  return 0;
 }
 if(cur < 2){
  printf("Not a valid starting cluster\n");
  return 0;
 }
 do{
  nclusters++;
  next = sFAT[cur];
  cur = next;
 }while(next && (next < 0x0FF0) && (nclusters < nexpected));
 return nclusters;
}

variable_types: cur int

variable_types: next int

variable_types: size int

variable_types: nexpected int


bufferFile

decompiled_code:
__int64 __fastcall bufferFile(const __m128i *a1, __int64 a2, void **a3)
{
void **v3; // r14
unsigned int v4; // er12
unsigned int v5; // eax
__m128i *v7; // r13
unsigned int v8; // er14
int v9; // ebp
int v10; // er15
unsigned int v11; // eax
unsigned __int16 v12; // ax
int v13; // ebx
const void **v14; // rax
__m128i *v15; // rsi
int v16; // [rsp+0h] [rbp-68h]
unsigned int v19; // [rsp+28h] [rbp-40h]
int v20; // [rsp+2Ch] [rbp-3Ch]

v3 = a3;
LOWORD(v4) = a1[1].m128i_i16[5];
v5 = followDirEntry((__int64)a1, a2);
v19 = v5;
*v3 = 0LL;
if ( v5 )
{
v4 = (unsigned __int16)v4;
*v3 = calloc((int)((spc * v5) << 9), 1uLL);
v7 = (__m128i *)malloc(0x20uLL);
*v7 = _mm_loadu_si128(a1);
v7[1] = _mm_loadu_si128(a1 + 1);
v20 = 0;
v16 = 0;
v8 = 0;
while ( 1 )
{
v14 = (const void **)((char *)indiceTable + 8 * (int)v4);
v15 = (__m128i *)*v14;
if ( *v14 )
{
if ( v15 == v7 )
{
printf("Loop found at index %d\n", v4);
printDirEntry((__int64)v7);
puts(&byte_FEB);
*a3 = 0LL;
return (unsigned int)-2;
}
if ( !memcmp(v7, v15, 0x20uLL) )
{
puts("Duplicate file found");
printDirEntry((__int64)v7);
puts(&byte_FEB);
*a3 = 0LL;
return (unsigned int)-2;
}
printf("Double link found at index %d for file (%p):\n", v4, v7);
printDirEntry((__int64)v7);
printf("The link was also accessed by (%p):\n", *((const void **)indiceTable + (int)v4));
printDirEntry(*((_QWORD *)indiceTable + (int)v4));
puts(&byte_FEB);
}
else
{
*v14 = v7;
v20 = 1;
}
if ( *((_BYTE *)badIndices + (int)v4) )
{
printf("Note: ");
printf("cluster %d marked as inconsistent. clusters read: %d,clusters expected: %d\n", v4, v8, v19);
printDirEntry((__int64)a1);
}
v9 = clusterSize;
v10 = fid;
lseek(fid, (int)(clusterSize * (dataStart + v4)), 0);
v11 = read(v10, (char *)*a3 + v16, v9);
if ( clusterSize != v11 )
{
printf("Disk read error, expected %d bytes, read %d\n", (unsigned int)clusterSize, v11);
printf("Attempting to read cluster %d\n", v4);
return (unsigned int)-1;
}
++v8;
v16 += v11;
v12 = *(_WORD *)(a2 + 2LL * (int)v4);
v13 = v12;
if ( (unsigned __int16)(v12 - 1) > 0xFEEu || (int)v19 <= (int)v8 )
break;
v4 = v12;
}
if ( !v20 )
free(v7);
if ( v13 )
{
if ( v13 <= 4079 )
{
printf(
"Incorrect file length, read %d cluster(s), next cluster would be at %d but should be an end of chain marker.\n",
v8,
(unsigned int)v13);
printDirEntry((__int64)a1);
puts(&byte_FEB);
v19 = -2;
}
else if ( v19 == v8 )
{
v19 = v8;
}
else
{
printf("Incorrect file length, chain ends at cluster %d, but thefile length gives %d clusters.\n", v8, v19);
printDirEntry((__int64)a1);
puts(&byte_FEB);
v19 = -2;
}
}
else
{
if ( v19 == v8 )
printf("Empty marker found in chain at index %d. I expected an end of chain marker.\n", v4);
else
printf("Empty marker found in chain at index %d, read %d clusters. I expected %d clusters.\n", v4, v8, v19);
printDirEntry((__int64)a1);
puts(&byte_FEB);
v19 = -2;
}
}
return v19;
}

canonical_decompiled_code:
__int64 __fastcall func2(const __m128i *a1, __int64 a2, void **a3)
{
void **v3; // r14
unsigned int v4; // er12
unsigned int v5; // eax
__m128i *v7; // r13
unsigned int v8; // er14
int v9; // ebp
int v10; // er15
unsigned int v11; // eax
unsigned __int16 v12; // ax
int v13; // ebx
const void **v14; // rax
__m128i *v15; // rsi
int v16; // [rsp+0h] [rbp-68h]
unsigned int v19; // [rsp+28h] [rbp-40h]
int v20; // [rsp+2Ch] [rbp-3Ch]

v3 = a3;
LOWORD(v4) = a1[1].m128i_i16[5];
v5 = func1((__int64)a1, a2);
v19 = v5;
*v3 = 0LL;
if ( v5 )
{
v4 = (unsigned __int16)v4;
*v3 = calloc((int)((spc * v5) << 9), 1uLL);
v7 = (__m128i *)malloc(0x20uLL);
*v7 = _mm_loadu_si128(a1);
v7[1] = _mm_loadu_si128(a1 + 1);
v20 = 0;
v16 = 0;
v8 = 0;
while ( 1 )
{
v14 = (const void **)((char *)indiceTable + 8 * (int)v4);
v15 = (__m128i *)*v14;
if ( *v14 )
{
if ( v15 == v7 )
{
printf("Loop found at index %d\n", v4);
func0((__int64)v7);
puts(&byte_FEB);
*a3 = 0LL;
return (unsigned int)-2;
}
if ( !memcmp(v7, v15, 0x20uLL) )
{
puts("Duplicate file found");
func0((__int64)v7);
puts(&byte_FEB);
*a3 = 0LL;
return (unsigned int)-2;
}
printf("Double link found at index %d for file (%p):\n", v4, v7);
func0((__int64)v7);
printf("The link was also accessed by (%p):\n", *((const void **)indiceTable + (int)v4));
func0(*((_QWORD *)indiceTable + (int)v4));
puts(&byte_FEB);
}
else
{
*v14 = v7;
v20 = 1;
}
if ( *((_BYTE *)badIndices + (int)v4) )
{
printf("Note: ");
printf("cluster %d marked as inconsistent. clusters read: %d,clusters expected: %d\n", v4, v8, v19);
func0((__int64)a1);
}
v9 = clusterSize;
v10 = fid;
lseek(fid, (int)(clusterSize * (dataStart + v4)), 0);
v11 = read(v10, (char *)*a3 + v16, v9);
if ( clusterSize != v11 )
{
printf("Disk read error, expected %d bytes, read %d\n", (unsigned int)clusterSize, v11);
printf("Attempting to read cluster %d\n", v4);
return (unsigned int)-1;
}
++v8;
v16 += v11;
v12 = *(_WORD *)(a2 + 2LL * (int)v4);
v13 = v12;
if ( (unsigned __int16)(v12 - 1) > 0xFEEu || (int)v19 <= (int)v8 )
break;
v4 = v12;
}
if ( !v20 )
free(v7);
if ( v13 )
{
if ( v13 <= 4079 )
{
printf(
"Incorrect file length, read %d cluster(s), next cluster would be at %d but should be an end of chain marker.\n",
v8,
(unsigned int)v13);
func0((__int64)a1);
puts(&byte_FEB);
v19 = -2;
}
else if ( v19 == v8 )
{
v19 = v8;
}
else
{
printf("Incorrect file length, chain ends at cluster %d, but thefile length gives %d clusters.\n", v8, v19);
func0((__int64)a1);
puts(&byte_FEB);
v19 = -2;
}
}
else
{
if ( v19 == v8 )
printf("Empty marker found in chain at index %d. I expected an end of chain marker.\n", v4);
else
printf("Empty marker found in chain at index %d, read %d clusters. I expected %d clusters.\n", v4, v8, v19);
func0((__int64)a1);
puts(&byte_FEB);
v19 = -2;
}
}
return v19;
}

original_code:
int bufferFile(dirEntry *e, unsigned short *sFAT, char **buffer){
 int cur = e->start;
 int nclusters = followDirEntry(e, sFAT);
 int nbytes;
 int nread = 0;
 int prev = cur;
 int offset = 0;
 int inTable = 0;
 dirEntry *copy = ((void *)0);
 (*buffer) = ((void *)0);
 if(nclusters == 0) return 0;
 *buffer = calloc(nclusters * bps * spc, 1);
 copy = malloc(sizeof(dirEntry));
 memcpy(copy, e, sizeof(dirEntry));
 do{
  if(indiceTable[cur] == ((void *)0)){
   inTable = 1;
   indiceTable[cur] = copy;
  }else if(indiceTable[cur] == copy){
   printf("Loop found at index %d\n", cur);
   printDirEntry(copy);
   puts("");
   (*buffer) = ((void *)0);
   return -2;
  }else if(!memcmp(copy, indiceTable[cur], sizeof(dirEntry))){
   printf("Duplicate file found\n");
   printDirEntry(copy);
   puts("");
   (*buffer) = ((void *)0);
   return -2;
  }else{
   printf("Double link found at index %d for file (%p):\n",
    cur, copy);
   printDirEntry(copy);
   printf("The link was also accessed by (%p):\n",
    indiceTable[cur]);
   printDirEntry(indiceTable[cur]);
   puts("");
  }
  if(badIndices[cur]){
   printf("Note: ");
   printf("cluster %d marked as inconsistent. clusters read: %d,"
    "clusters expected: %d\n", cur, nread, nclusters);
   printDirEntry(e);
  }
  lseek(fid, (cur + dataStart) * clusterSize, 0);
  nbytes = read(fid, (*buffer) + offset, clusterSize);
  if(clusterSize != nbytes){
   printf("Disk read error, expected %d bytes, read %d\n",
    clusterSize, nbytes);
   printf("Attempting to read cluster %d\n", cur);
   return -1;
  }
  nread++;
  offset += clusterSize;
  prev = cur;
  cur = sFAT[cur];
 }while(cur && (cur < 0x0FF0) && (nread < nclusters));
 if(!inTable){
  free(copy);
 }
 if(!cur){
  if(nread != nclusters){
   printf("Empty marker found in chain at index %d, read %d "
    "clusters. I expected %d clusters.\n", prev, nread,
    nclusters);
  }else{
   printf("Empty marker found in chain at index %d. I expected"
    " an end of chain marker.\n", prev);
  }
  printDirEntry(e);
  puts("");
  return -2;
 }else if(cur < 0x0FF0){
  printf("Incorrect file length, read %d cluster(s), next cluster"
   " would be at %d but should be an end of chain marker.\n",
   nread, cur);
  printDirEntry(e);
  puts("");
  return -2;
 }else if(nread != nclusters){
  printf("Incorrect file length, chain ends at cluster %d, but the"
   "file length gives %d clusters.\n", nread, nclusters);
  printDirEntry(e);
  puts("");
  return -2;
 }
 return nclusters;
}

canonical_original_code:
int bufferFile(struct DIRENTRY *e, unsigned short *sFAT, char **buffer){
 int cur = e->start;
 int nclusters = followDirEntry(e, sFAT);
 int nbytes;
 int nread = 0;
 int prev = cur;
 int offset = 0;
 int inTable = 0;
 struct DIRENTRY *copy = ((void *)0);
 (*buffer) = ((void *)0);
 if(nclusters == 0) return 0;
 *buffer = calloc(nclusters * bps * spc, 1);
 copy = malloc(sizeof(dirEntry));
 memcpy(copy, e, sizeof(dirEntry));
 do{
  if(indiceTable[cur] == ((void *)0)){
   inTable = 1;
   indiceTable[cur] = copy;
  }else if(indiceTable[cur] == copy){
   printf("Loop found at index %d\n", cur);
   printDirEntry(copy);
   puts("");
   (*buffer) = ((void *)0);
   return -2;
  }else if(!memcmp(copy, indiceTable[cur], sizeof(dirEntry))){
   printf("Duplicate file found\n");
   printDirEntry(copy);
   puts("");
   (*buffer) = ((void *)0);
   return -2;
  }else{
   printf("Double link found at index %d for file (%p):\n",
    cur, copy);
   printDirEntry(copy);
   printf("The link was also accessed by (%p):\n",
    indiceTable[cur]);
   printDirEntry(indiceTable[cur]);
   puts("");
  }
  if(badIndices[cur]){
   printf("Note: ");
   printf("cluster %d marked as inconsistent. clusters read: %d,"
    "clusters expected: %d\n", cur, nread, nclusters);
   printDirEntry(e);
  }
  lseek(fid, (cur + dataStart) * clusterSize, 0);
  nbytes = read(fid, (*buffer) + offset, clusterSize);
  if(clusterSize != nbytes){
   printf("Disk read error, expected %d bytes, read %d\n",
    clusterSize, nbytes);
   printf("Attempting to read cluster %d\n", cur);
   return -1;
  }
  nread++;
  offset += clusterSize;
  prev = cur;
  cur = sFAT[cur];
 }while(cur && (cur < 0x0FF0) && (nread < nclusters));
 if(!inTable){
  free(copy);
 }
 if(!cur){
  if(nread != nclusters){
   printf("Empty marker found in chain at index %d, read %d "
    "clusters. I expected %d clusters.\n", prev, nread,
    nclusters);
  }else{
   printf("Empty marker found in chain at index %d. I expected"
    " an end of chain marker.\n", prev);
  }
  printDirEntry(e);
  puts("");
  return -2;
 }else if(cur < 0x0FF0){
  printf("Incorrect file length, read %d cluster(s), next cluster"
   " would be at %d but should be an end of chain marker.\n",
   nread, cur);
  printDirEntry(e);
  puts("");
  return -2;
 }else if(nread != nclusters){
  printf("Incorrect file length, chain ends at cluster %d, but the"
   "file length gives %d clusters.\n", nread, nclusters);
  printDirEntry(e);
  puts("");
  return -2;
 }
 return nclusters;
}

variable_types: struct DIRENTRY { unsigned char name[8]; unsigned char ext[3]; unsigned char attrib; unsigned char zero[10]; unsigned short time; unsigned short date; unsigned short start; unsigned short length[2]; } *

variable_types:
sFAT
unsigned short *

variable_types:
buffer
char **

variable_types: nclusters int

variable_types: nbytes int

variable_types: nread int

variable_types: prev int

variable_types: offset int

variable_types: inTable int

return_type: int


expandFAT

original_code:
void expandFAT(unsigned char *FAT, unsigned short *sFAT, int entries){
 int i, j;
 for(i = 0, j = 0; i < entries; i += 2, j += 3){
  sFAT[i] = FAT[j] + 256 * (FAT[j + 1] & 0xf);
  sFAT[i + 1] = ((FAT[j + 1] >> 4) & 0xf) + 16 *FAT[j + 2];
 }
}

canonical_original_code:
void expandFAT(unsigned char *FAT, unsigned short *sFAT, int entries){
 int i; int j;
 for(i = 0, j = 0; i < entries; i += 2, j += 3){
  sFAT[i] = FAT[j] + 256 * (FAT[j + 1] & 0xf);
  sFAT[i + 1] = ((FAT[j + 1] >> 4) & 0xf) + 16 *FAT[j + 2];
 }
}

variable_types:
FAT
unsigned char *

variable_types: entries int

variable_types: i int

variable_types: j int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er14
int v5; // er15
int v6; // esi
int v7; // ecx
int v8; // er12
int v9; // ebp
void *v10; // rbx
int v11; // ebx
_WORD *v12; // r13
int v13; // ebx
unsigned int v14; // er12
void *v15; // r13
int result; // eax
__int64 v17; // rbx
char *v18; // rax
void **v19; // r12
__int64 v20; // r12
__int64 v21; // rdi
_QWORD *v22; // rcx
char *v23; // rdx
int v24; // [rsp+Ch] [rbp-23Ch]
char buf[11]; // [rsp+10h] [rbp-238h] BYREF
unsigned __int8 v26; // [rsp+1Bh] [rbp-22Dh]
unsigned __int8 v27; // [rsp+1Ch] [rbp-22Ch]
unsigned __int8 v28; // [rsp+1Dh] [rbp-22Bh]
unsigned __int8 v29; // [rsp+1Eh] [rbp-22Ah]
unsigned __int8 v30; // [rsp+1Fh] [rbp-229h]
unsigned __int8 v31; // [rsp+20h] [rbp-228h]
unsigned __int8 v32; // [rsp+21h] [rbp-227h]
unsigned __int8 v33; // [rsp+22h] [rbp-226h]
unsigned __int8 v34; // [rsp+23h] [rbp-225h]
unsigned __int8 v35; // [rsp+24h] [rbp-224h]
unsigned __int8 v36; // [rsp+25h] [rbp-223h]
unsigned __int8 v37; // [rsp+26h] [rbp-222h]
unsigned __int8 v38; // [rsp+27h] [rbp-221h]
unsigned __int8 v39; // [rsp+28h] [rbp-220h]
unsigned __int8 v40; // [rsp+29h] [rbp-21Fh]
unsigned __int8 v41; // [rsp+2Ah] [rbp-21Eh]
unsigned __int8 v42; // [rsp+2Bh] [rbp-21Dh]
unsigned __int8 v43; // [rsp+2Ch] [rbp-21Ch]
unsigned __int8 v44; // [rsp+2Dh] [rbp-21Bh]

printf("size of bootsector = %u\n", 512LL);
if ( argc <= 1 )
{
puts("Need one file argument");
exit(-1);
}
fid = open(argv[1], 0);
v3 = read(fid, buf, 0x200uLL);
if ( v3 != 512 )
{
printf("Read error %d\n", v3);
exit(-2);
}
printf("Serial nr. %u-%u-%u\n", (unsigned __int8)buf[8], (unsigned __int8)buf[9], (unsigned __int8)buf[10]);
v4 = v26 + (v27 << 8);
printf("bps = %hu\n", (unsigned int)v4);
spc = v28;
printf("spc = %hu\n", v28);
printf("res = %hu\n", v29 + (v30 << 8));
printf("NFats = %hu\n", v31);
v5 = v32 + (v33 << 8);
printf("Ndirs = %hu\n", (unsigned int)v5);
printf("Nsects = %hu\n", v34 + (v35 << 8));
printf("Media = %hu\n", v36);
printf("spf = %hu\n", v37 + (v38 << 8));
printf("spt = %hu\n", v39 + (v40 << 8));
printf("Nsides = %hu\n", v41 + (v42 << 8));
printf("Nhid = %hu\n", v43 + (v44 << 8));
if ( !v4 || !v31 || (v6 = v34 + (v35 << 8)) == 0 )
{
puts("This is not a FAT-12-type floppy format");
exit(-2);
}
v7 = (v38 << 8) + v37;
v8 = v7 * (v26 + (v27 << 8));
v24 = 2 * v8;
v9 = 2 * v8 / 3;
clusterSize = spc * v4;
printf(
"entries = %u, dataSectors = %u, clusters = %u\n",
(unsigned int)v9,
v6 - 1 - v7 * (unsigned int)v31,
(unsigned int)((v6 - 1 - v7 * v31) / v28));
v10 = malloc(v8);
FAT1 = v10;
FAT2 = malloc(v8);
if ( v8 != (unsigned int)read(fid, v10, v8) )
puts("Unexpected EOF");
if ( v31 > 1u )
{
v11 = 1;
do
{
if ( v8 != (unsigned int)read(fid, FAT2, v8) )
puts("Unexpected EOF");
++v11;
}
while ( v31 > v11 );
}
v12 = calloc(v9 + 1, 2uLL);
sFAT1 = v12;
sFAT2 = calloc(v9 + 1, 2uLL);
expandFAT((unsigned __int8 *)FAT1, v12, v9);
expandFAT((unsigned __int8 *)FAT2, sFAT2, v9);
v13 = (int)(v5 + ((unsigned __int64)v4 >> 5) - 1) / (int)((unsigned __int64)v4 >> 5);
v14 = v13 + v8 * v31 / v4 - 1;
dataStart = v14;
v15 = calloc(v5, 0x20uLL);
printf("dataStart = %d\n", v14);
badIndices = calloc(v9, 1uLL);
indiceTable = calloc(v9, 8uLL);
puts("\nChecking FAT");
compareFATs((__int64)sFAT1, (__int64)sFAT2, v9);
if ( v4 * v13 == (unsigned int)read(fid, v15, v4 * v13) )
{
puts("\n\nChecking files");
readDirectory((__int64)v15, v5, (__int64)sFAT1, v9);
puts("\n\nChecking unreferenced files");
checkLooseFiles((__int64)sFAT1, v9);
puts("\n\nChecking free space");
checkFreeSpace((__int64)sFAT1, v9);
puts("\n\nCleanup");
if ( v24 > 2 )
{
v17 = 0LL;
do
{
v20 = 8 * v17;
v21 = *((_QWORD *)indiceTable + v17);
if ( v21 )
{
printDirEntry(v21);
if ( v9 > (int)v17 + 1 )
{
v22 = (char *)indiceTable + v20;
v18 = (char *)indiceTable + v20 + 8;
v23 = (char *)indiceTable + 8 * v17 + 8 * (unsigned int)(v9 - 2 - v17) + 16;
do
{
if ( *(_QWORD *)v18 == *v22 )
*(_QWORD *)v18 = 0LL;
v18 += 8;
}
while ( v18 != v23 );
}
v19 = (void **)((char *)indiceTable + v20);
free(*v19);
*v19 = 0LL;
}
++v17;
}
while ( v9 > (int)v17 );
}
free(indiceTable);
free(badIndices);
free(v15);
free(sFAT1);
free(sFAT2);
free(FAT1);
free(FAT2);
result = 0;
}
else
{
puts("Unexpected EOF");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er14
int v5; // er15
int v6; // esi
int v7; // ecx
int v8; // er12
int v9; // ebp
void *v10; // rbx
int v11; // ebx
_WORD *v12; // r13
int v13; // ebx
unsigned int v14; // er12
void *v15; // r13
int result; // eax
__int64 v17; // rbx
char *v18; // rax
void **v19; // r12
__int64 v20; // r12
__int64 v21; // rdi
_QWORD *v22; // rcx
char *v23; // rdx
int v24; // [rsp+Ch] [rbp-23Ch]
char buf[11]; // [rsp+10h] [rbp-238h] BYREF
unsigned __int8 v26; // [rsp+1Bh] [rbp-22Dh]
unsigned __int8 v27; // [rsp+1Ch] [rbp-22Ch]
unsigned __int8 v28; // [rsp+1Dh] [rbp-22Bh]
unsigned __int8 v29; // [rsp+1Eh] [rbp-22Ah]
unsigned __int8 v30; // [rsp+1Fh] [rbp-229h]
unsigned __int8 v31; // [rsp+20h] [rbp-228h]
unsigned __int8 v32; // [rsp+21h] [rbp-227h]
unsigned __int8 v33; // [rsp+22h] [rbp-226h]
unsigned __int8 v34; // [rsp+23h] [rbp-225h]
unsigned __int8 v35; // [rsp+24h] [rbp-224h]
unsigned __int8 v36; // [rsp+25h] [rbp-223h]
unsigned __int8 v37; // [rsp+26h] [rbp-222h]
unsigned __int8 v38; // [rsp+27h] [rbp-221h]
unsigned __int8 v39; // [rsp+28h] [rbp-220h]
unsigned __int8 v40; // [rsp+29h] [rbp-21Fh]
unsigned __int8 v41; // [rsp+2Ah] [rbp-21Eh]
unsigned __int8 v42; // [rsp+2Bh] [rbp-21Dh]
unsigned __int8 v43; // [rsp+2Ch] [rbp-21Ch]
unsigned __int8 v44; // [rsp+2Dh] [rbp-21Bh]

printf("size of bootsector = %u\n", 512LL);
if ( argc <= 1 )
{
puts("Need one file argument");
exit(-1);
}
fid = open(argv[1], 0);
v3 = read(fid, buf, 0x200uLL);
if ( v3 != 512 )
{
printf("Read error %d\n", v3);
exit(-2);
}
printf("Serial nr. %u-%u-%u\n", (unsigned __int8)buf[8], (unsigned __int8)buf[9], (unsigned __int8)buf[10]);
v4 = v26 + (v27 << 8);
printf("bps = %hu\n", (unsigned int)v4);
spc = v28;
printf("spc = %hu\n", v28);
printf("res = %hu\n", v29 + (v30 << 8));
printf("NFats = %hu\n", v31);
v5 = v32 + (v33 << 8);
printf("Ndirs = %hu\n", (unsigned int)v5);
printf("Nsects = %hu\n", v34 + (v35 << 8));
printf("Media = %hu\n", v36);
printf("spf = %hu\n", v37 + (v38 << 8));
printf("spt = %hu\n", v39 + (v40 << 8));
printf("Nsides = %hu\n", v41 + (v42 << 8));
printf("Nhid = %hu\n", v43 + (v44 << 8));
if ( !v4 || !v31 || (v6 = v34 + (v35 << 8)) == 0 )
{
puts("This is not a FAT-12-type floppy format");
exit(-2);
}
v7 = (v38 << 8) + v37;
v8 = v7 * (v26 + (v27 << 8));
v24 = 2 * v8;
v9 = 2 * v8 / 3;
clusterSize = spc * v4;
printf(
"entries = %u, dataSectors = %u, clusters = %u\n",
(unsigned int)v9,
v6 - 1 - v7 * (unsigned int)v31,
(unsigned int)((v6 - 1 - v7 * v31) / v28));
v10 = malloc(v8);
FAT1 = v10;
FAT2 = malloc(v8);
if ( v8 != (unsigned int)read(fid, v10, v8) )
puts("Unexpected EOF");
if ( v31 > 1u )
{
v11 = 1;
do
{
if ( v8 != (unsigned int)read(fid, FAT2, v8) )
puts("Unexpected EOF");
++v11;
}
while ( v31 > v11 );
}
v12 = calloc(v9 + 1, 2uLL);
sFAT1 = v12;
sFAT2 = calloc(v9 + 1, 2uLL);
func4((unsigned __int8 *)FAT1, v12, v9);
func4((unsigned __int8 *)FAT2, sFAT2, v9);
v13 = (int)(v5 + ((unsigned __int64)v4 >> 5) - 1) / (int)((unsigned __int64)v4 >> 5);
v14 = v13 + v8 * v31 / v4 - 1;
dataStart = v14;
v15 = calloc(v5, 0x20uLL);
printf("dataStart = %d\n", v14);
badIndices = calloc(v9, 1uLL);
indiceTable = calloc(v9, 8uLL);
puts("\nChecking FAT");
func5((__int64)sFAT1, (__int64)sFAT2, v9);
if ( v4 * v13 == (unsigned int)read(fid, v15, v4 * v13) )
{
puts("\n\nChecking files");
func3((__int64)v15, v5, (__int64)sFAT1, v9);
puts("\n\nChecking unreferenced files");
func7((__int64)sFAT1, v9);
puts("\n\nChecking free space");
func6((__int64)sFAT1, v9);
puts("\n\nCleanup");
if ( v24 > 2 )
{
v17 = 0LL;
do
{
v20 = 8 * v17;
v21 = *((_QWORD *)indiceTable + v17);
if ( v21 )
{
func0(v21);
if ( v9 > (int)v17 + 1 )
{
v22 = (char *)indiceTable + v20;
v18 = (char *)indiceTable + v20 + 8;
v23 = (char *)indiceTable + 8 * v17 + 8 * (unsigned int)(v9 - 2 - v17) + 16;
do
{
if ( *(_QWORD *)v18 == *v22 )
*(_QWORD *)v18 = 0LL;
v18 += 8;
}
while ( v18 != v23 );
}
v19 = (void **)((char *)indiceTable + v20);
free(*v19);
*v19 = 0LL;
}
++v17;
}
while ( v9 > (int)v17 );
}
free(indiceTable);
free(badIndices);
free(v15);
free(sFAT1);
free(sFAT2);
free(FAT1);
free(FAT2);
result = 0;
}
else
{
puts("Unexpected EOF");
result = 1;
}
return result;
}

original_code:
int main(int argc, char * argv[]){
 BPB bootsector;
 int rv = 0;
 int entries;
 int NFATbytes;
 int dataSectors;
 int clusters;
 int i, j;
 int bps;
 int Ndirs;
 int NdirSectors;
 int nread;
 dirEntry *dirs;
 printf("size of bootsector = %u\n", (unsigned int) sizeof(BPB));
 if(argc > 1){
  fid = open(argv[1], 00);
 }else{
  printf("Need one file argument\n");
  exit(-1);
 }
 if((sizeof(BPB) != (rv = read(fid, &bootsector, sizeof(BPB))))){
  printf("Read error %d\n", rv);
  exit(-2);
 }
 printf("Serial nr. %u-%u-%u\n", bootsector.vsn[0], bootsector.vsn[1], bootsector.vsn[2]);
 printf("bps = %hu\n", bps = ((bootsector.bps[0] & 0xff) + 256 * (bootsector.bps[1] & 0xff)));
 printf("spc = %hu\n", spc = bootsector.spc);
 printf("res = %hu\n", ((bootsector.res[0] & 0xff) + 256 * (bootsector.res[1] & 0xff)));
 printf("NFats = %hu\n", bootsector.NFats);
 printf("Ndirs = %hu\n", Ndirs = ((bootsector.Ndirs[0] & 0xff) + 256 * (bootsector.Ndirs[1] & 0xff)));
 printf("Nsects = %hu\n", ((bootsector.Nsects[0] & 0xff) + 256 * (bootsector.Nsects[1] & 0xff)));
 printf("Media = %hu\n", bootsector.Media);
 printf("spf = %hu\n", ((bootsector.spf[0] & 0xff) + 256 * (bootsector.spf[1] & 0xff)));
 printf("spt = %hu\n", ((bootsector.spt[0] & 0xff) + 256 * (bootsector.spt[1] & 0xff)));
 printf("Nsides = %hu\n", ((bootsector.Nsides[0] & 0xff) + 256 * (bootsector.Nsides[1] & 0xff)));
 printf("Nhid = %hu\n", ((bootsector.Nhid[0] & 0xff) + 256 * (bootsector.Nhid[1] & 0xff)));
 if(!bps || !bootsector.NFats || !((bootsector.Nsects[0] & 0xff) + 256 * (bootsector.Nsects[1] & 0xff))){
  printf("This is not a FAT-12-type floppy format\n");
  exit(-2);
 }
 NFATbytes = ((bootsector.bps[0] & 0xff) + 256 * (bootsector.bps[1] & 0xff)) * ((bootsector.spf[0] & 0xff) + 256 * (bootsector.spf[1] & 0xff));
 entries = (2 * NFATbytes) / 3;
 dataSectors = ((bootsector.Nsects[0] & 0xff) + 256 * (bootsector.Nsects[1] & 0xff)) - 1 - bootsector.NFats * ((bootsector.spf[0] & 0xff) + 256 * (bootsector.spf[1] & 0xff));
 clusters = dataSectors / bootsector.spc;
 clusterSize = spc * bps;
 printf("entries = %u, dataSectors = %u, clusters = %u\n", entries, dataSectors, clusters);
 FAT1 = malloc(NFATbytes);
 FAT2 = malloc(NFATbytes);
 nread = read(fid, FAT1, NFATbytes);
 if(nread != NFATbytes){
  printf("Unexpected EOF\n");
 }
 for(i = 1; i < bootsector.NFats; i++){
  nread = read(fid, FAT2, NFATbytes);
  if(nread != NFATbytes){
   printf("Unexpected EOF\n");
  }
 }
 sFAT1 = calloc(entries + 1, sizeof(unsigned short));
 sFAT2 = calloc(entries + 1, sizeof(unsigned short));
 expandFAT(FAT1, sFAT1, entries);
 expandFAT(FAT2, sFAT2, entries);
 i = bps / sizeof(dirEntry);
 NdirSectors = (Ndirs + i - 1) / i;
 dataStart = 1 + (bootsector.NFats * NFATbytes) / bps + NdirSectors - 2;
 dirs = calloc(Ndirs, sizeof(dirEntry));
 printf("dataStart = %d\n", dataStart);
 badIndices = calloc(entries, 1);
 indiceTable = (dirEntry **) calloc(entries, sizeof(dirEntry *));
 printf("\nChecking FAT\n");
 compareFATs(sFAT1, sFAT2, entries);
 nread = read(fid, dirs, bps * NdirSectors);
 if(nread != bps * NdirSectors){
  printf("Unexpected EOF\n");
  return 1;
 }
 printf("\n\nChecking files\n");
 readDirectory(dirs, Ndirs, sFAT1, entries);
 printf("\n\nChecking unreferenced files\n");
 checkLooseFiles(sFAT1, entries);
 printf("\n\nChecking free space\n");
 checkFreeSpace(sFAT1, entries);
 printf("\n\nCleanup\n");
 for(i = 0; i < entries; i++){
  if(indiceTable[i] != ((void *)0)){
   printDirEntry(indiceTable[i]);
   for(j = i + 1; j < entries; j++){
    if(indiceTable[j] == indiceTable[i]){
     indiceTable[j] = ((void *)0);
    }
   }
   free(indiceTable[i]);
   indiceTable[i] = ((void *)0);
  }
 }
 free(indiceTable);
 free(badIndices);
 free(dirs);
 free(sFAT1);
 free(sFAT2);
 free(FAT1);
 free(FAT2);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 struct BPB bootsector;
 int rv = 0;
 int entries;
 int NFATbytes;
 int dataSectors;
 int clusters;
 int i; int j;
 int bps;
 int Ndirs;
 int NdirSectors;
 int nread;
 struct DIRENTRY *dirs;
 printf("size of bootsector = %u\n", (unsigned int) sizeof(BPB));
 if(argc > 1){
  fid = open(argv[1], 00);
 }else{
  printf("Need one file argument\n");
  exit(-1);
 }
 if((sizeof(BPB) != (rv = read(fid, &bootsector, sizeof(BPB))))){
  printf("Read error %d\n", rv);
  exit(-2);
 }
 printf("Serial nr. %u-%u-%u\n", bootsector.vsn[0], bootsector.vsn[1], bootsector.vsn[2]);
 printf("bps = %hu\n", bps = ((bootsector.bps[0] & 0xff) + 256 * (bootsector.bps[1] & 0xff)));
 printf("spc = %hu\n", spc = bootsector.spc);
 printf("res = %hu\n", ((bootsector.res[0] & 0xff) + 256 * (bootsector.res[1] & 0xff)));
 printf("NFats = %hu\n", bootsector.NFats);
 printf("Ndirs = %hu\n", Ndirs = ((bootsector.Ndirs[0] & 0xff) + 256 * (bootsector.Ndirs[1] & 0xff)));
 printf("Nsects = %hu\n", ((bootsector.Nsects[0] & 0xff) + 256 * (bootsector.Nsects[1] & 0xff)));
 printf("Media = %hu\n", bootsector.Media);
 printf("spf = %hu\n", ((bootsector.spf[0] & 0xff) + 256 * (bootsector.spf[1] & 0xff)));
 printf("spt = %hu\n", ((bootsector.spt[0] & 0xff) + 256 * (bootsector.spt[1] & 0xff)));
 printf("Nsides = %hu\n", ((bootsector.Nsides[0] & 0xff) + 256 * (bootsector.Nsides[1] & 0xff)));
 printf("Nhid = %hu\n", ((bootsector.Nhid[0] & 0xff) + 256 * (bootsector.Nhid[1] & 0xff)));
 if(!bps || !bootsector.NFats || !((bootsector.Nsects[0] & 0xff) + 256 * (bootsector.Nsects[1] & 0xff))){
  printf("This is not a FAT-12-type floppy format\n");
  exit(-2);
 }
 NFATbytes = ((bootsector.bps[0] & 0xff) + 256 * (bootsector.bps[1] & 0xff)) * ((bootsector.spf[0] & 0xff) + 256 * (bootsector.spf[1] & 0xff));
 entries = (2 * NFATbytes) / 3;
 dataSectors = ((bootsector.Nsects[0] & 0xff) + 256 * (bootsector.Nsects[1] & 0xff)) - 1 - bootsector.NFats * ((bootsector.spf[0] & 0xff) + 256 * (bootsector.spf[1] & 0xff));
 clusters = dataSectors / bootsector.spc;
 clusterSize = spc * bps;
 printf("entries = %u, dataSectors = %u, clusters = %u\n", entries, dataSectors, clusters);
 FAT1 = malloc(NFATbytes);
 FAT2 = malloc(NFATbytes);
 nread = read(fid, FAT1, NFATbytes);
 if(nread != NFATbytes){
  printf("Unexpected EOF\n");
 }
 for(i = 1; i < bootsector.NFats; i++){
  nread = read(fid, FAT2, NFATbytes);
  if(nread != NFATbytes){
   printf("Unexpected EOF\n");
  }
 }
 sFAT1 = calloc(entries + 1, sizeof(unsigned short));
 sFAT2 = calloc(entries + 1, sizeof(unsigned short));
 expandFAT(FAT1, sFAT1, entries);
 expandFAT(FAT2, sFAT2, entries);
 i = bps / sizeof(dirEntry);
 NdirSectors = (Ndirs + i - 1) / i;
 dataStart = 1 + (bootsector.NFats * NFATbytes) / bps + NdirSectors - 2;
 dirs = calloc(Ndirs, sizeof(dirEntry));
 printf("dataStart = %d\n", dataStart);
 badIndices = calloc(entries, 1);
 indiceTable = (struct DIRENTRY **) calloc(entries, sizeof(struct DIRENTRY *));
 printf("\nChecking FAT\n");
 compareFATs(sFAT1, sFAT2, entries);
 nread = read(fid, dirs, bps * NdirSectors);
 if(nread != bps * NdirSectors){
  printf("Unexpected EOF\n");
  return 1;
 }
 printf("\n\nChecking files\n");
 readDirectory(dirs, Ndirs, sFAT1, entries);
 printf("\n\nChecking unreferenced files\n");
 checkLooseFiles(sFAT1, entries);
 printf("\n\nChecking free space\n");
 checkFreeSpace(sFAT1, entries);
 printf("\n\nCleanup\n");
 for(i = 0; i < entries; i++){
  if(indiceTable[i] != ((void *)0)){
   printDirEntry(indiceTable[i]);
   for(j = i + 1; j < entries; j++){
    if(indiceTable[j] == indiceTable[i]){
     indiceTable[j] = ((void *)0);
    }
   }
   free(indiceTable[i]);
   indiceTable[i] = ((void *)0);
  }
 }
 free(indiceTable);
 free(badIndices);
 free(dirs);
 free(sFAT1);
 free(sFAT2);
 free(FAT1);
 free(FAT2);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct BPB { unsigned short BRA; unsigned short filler[3]; unsigned char vsn[3]; unsigned char bps[2]; unsigned char spc; unsigned char res[2]; unsigned char NFats; unsigned char Ndirs[2]; unsigned char Nsects[2]; unsigned char Media; unsigned char spf[2]; unsigned char spt[2]; unsigned char Nsides[2]; unsigned char Nhid[2]; unsigned char boot[482]; }

variable_types: rv int

variable_types: NFATbytes int

variable_types: dataSectors int

variable_types: clusters int

variable_types: bps int

variable_types: Ndirs int

variable_types: NdirSectors int

user_defined_types: struct DIRENTRY { unsigned char name[8]; unsigned char ext[3]; unsigned char attrib; unsigned char zero[10]; unsigned short time; unsigned short date; unsigned short start; unsigned short length[2]; }


GetRangeFromLine

repo: TomasGrimm/FCAS

original_code:
void GetRangeFromLine(char *line, SteppedVariable *steppedCell)
{
 char *token;
 int index = 0;
 int indexSuffix = 0;
 while (line[index] != '{')
 {
  steppedCell->preffix[index] = line[index];
  index++;
 }
 index = strcspn(line, "}");
 index++;
 while (line[index] != '\n')
 {
  steppedCell->suffix[indexSuffix] = line[index];
  index++;
  indexSuffix++;
 }
 token = strtok(strchr(line, '{'), "{:}");
 steppedCell->start = atof(token);
 token = strtok(((void *)0), "{:}");
 steppedCell->end = atof(token);
 token = strtok(((void *)0), "{:}");
 steppedCell->step = atof(token);
}

canonical_original_code:
void GetRangeFromLine(char *line, struct SteppedVariable *steppedCell)
{
 char *token;
 int index = 0;
 int indexSuffix = 0;
 while (line[index] != '{')
 {
  steppedCell->preffix[index] = line[index];
  index++;
 }
 index = strcspn(line, "}");
 index++;
 while (line[index] != '\n')
 {
  steppedCell->suffix[indexSuffix] = line[index];
  index++;
  indexSuffix++;
 }
 token = strtok(strchr(line, '{'), "{:}");
 steppedCell->start = atof(token);
 token = strtok(((void *)0), "{:}");
 steppedCell->end = atof(token);
 token = strtok(((void *)0), "{:}");
 steppedCell->step = atof(token);
}

variable_types:
line
char *

variable_types: struct SteppedVariable { char preffix[1000]; double start; double end; double step; char suffix[1000]; } *

variable_types:
token
char *

variable_types: index int

variable_types: indexSuffix int


GetVectorFromLine

original_code:
void GetVectorFromLine(char *line, VectorVariable *vectorCell)
{
 char *token;
 int index = 0;
 int indexSuffix = 0;
 while (line[index] != '{')
 {
  vectorCell->preffix[index] = line[index];
  index++;
 }
 index = strcspn(line, "}");
 index++;
 while (line[index] != '\n')
 {
  vectorCell->suffix[indexSuffix] = line[index];
  index++;
  indexSuffix++;
 }
 token = strtok(strchr(line, '{'), "{;}'\n");
 while (token != ((void *)0))
 {
  strcpy(vectorCell->values[vectorCell->numberOfValues++], token);
  token = strtok(((void *)0), "{;}'\n");
 }
}

canonical_original_code:
void GetVectorFromLine(char *line, struct VectorVariable *vectorCell)
{
 char *token;
 int index = 0;
 int indexSuffix = 0;
 while (line[index] != '{')
 {
  vectorCell->preffix[index] = line[index];
  index++;
 }
 index = strcspn(line, "}");
 index++;
 while (line[index] != '\n')
 {
  vectorCell->suffix[indexSuffix] = line[index];
  index++;
  indexSuffix++;
 }
 token = strtok(strchr(line, '{'), "{;}'\n");
 while (token != ((void *)0))
 {
  strcpy(vectorCell->values[vectorCell->numberOfValues++], token);
  token = strtok(((void *)0), "{;}'\n");
 }
}

variable_types: struct VectorVariable { char preffix[1000]; char values[1000][50]; char suffix[1000]; int numberOfValues; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // cf
bool v4; // zf
const char *v7; // rbx
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
const char **v11; // rbx
const char **v12; // rbp
const char **v14; // rbx
const char **v15; // rbp

v7 = argv[1];
v8 = (const char *)&unk_104;
v9 = 3LL;
v10 = v7;
do
{
if ( !v9 )
break;
v3 = *v10 < (unsigned int)*v8;
v4 = *v10++ == *v8++;
--v9;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
{
if ( argc > 2 )
{
v11 = argv + 2;
v12 = &argv[(unsigned int)(argc - 3) + 3];
do
TreatVariations(*v11++, v10, envp);
while ( v11 != v12 );
}
}
else if ( !strcmp(v7, "-a") )
{
if ( argc > 2 )
{
v14 = argv + 2;
v15 = &argv[(unsigned int)(argc - 3) + 3];
do
VerifySimulations(*v14++);
while ( v14 != v15 );
}
}
else if ( !strcmp(v7, "-h") )
{
puts("Usage format:");
puts("./TccEDA [-a | -c] <input files>");
puts("\t-a\tAnalisys mode - verifies the simulation output and calculates the fault coverage.");
puts("\t-c\tConfiguration mode - generates the variations used in the simulation process.");
puts("\t-h\tThis help.");
puts("\n<input files> depend on the chosen functionality:");
puts("\tfor the analysis mode, the input files are the assertions;");
puts("\tfor the configuration mode, the input files are the variations.");
}
else
{
puts("Invalid option.\nUse -h for help");
}
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int argvIndex = 2;
 if ((strcmp(argv[1], "-c")) == 0)
 {
  while(argvIndex < argc)
  {
   TreatVariations(argv[argvIndex]);
   argvIndex++;
  }
 }
 else if ((strcmp(argv[1], "-a")) == 0)
 {
  while(argvIndex < argc)
  {
   VerifySimulations(argv[argvIndex]);
   argvIndex++;
  }
 }
 else if ((strcmp(argv[1], "-h")) == 0)
 {
  printf("Usage format:\n");
  printf("./TccEDA [-a | -c] <input files>\n");
  printf("\t-a\tAnalisys mode - verifies the simulation output and calculates the fault coverage.\n");
  printf("\t-c\tConfiguration mode - generates the variations used in the simulation process.\n");
  printf("\t-h\tThis help.\n");
  printf("\n<input files> depend on the chosen functionality:\n");
  printf("\tfor the analysis mode, the input files are the assertions;\n");
  printf("\tfor the configuration mode, the input files are the variations.\n");
 }
 else
  printf("Invalid option.\nUse -h for help\n");
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int argvIndex = 2;
 if ((strcmp(argv[1], "-c")) == 0)
 {
  while(argvIndex < argc)
  {
   TreatVariations(argv[argvIndex]);
   argvIndex++;
  }
 }
 else if ((strcmp(argv[1], "-a")) == 0)
 {
  while(argvIndex < argc)
  {
   VerifySimulations(argv[argvIndex]);
   argvIndex++;
  }
 }
 else if ((strcmp(argv[1], "-h")) == 0)
 {
  printf("Usage format:\n");
  printf("./TccEDA [-a | -c] <input files>\n");
  printf("\t-a\tAnalisys mode - verifies the simulation output and calculates the fault coverage.\n");
  printf("\t-c\tConfiguration mode - generates the variations used in the simulation process.\n");
  printf("\t-h\tThis help.\n");
  printf("\n<input files> depend on the chosen functionality:\n");
  printf("\tfor the analysis mode, the input files are the assertions;\n");
  printf("\tfor the configuration mode, the input files are the variations.\n");
 }
 else
  printf("Invalid option.\nUse -h for help\n");
 return 0;
}

variable_types: argvIndex int


repo: TomaszOstaszewski/Mcast

decompiled_code:
__int64 __fastcall debug_outputlnA_impl(char *format, __gnuc_va_list arg)
{
int v2; // edx
__int64 result; // rax

v2 = vsnprintf((char *)&g_outputBuffer + __readfsqword(0), 0x100uLL, format, arg);
result = 0LL;
if ( v2 > 0 )
{
fputs((const char *)&g_outputBuffer + __readfsqword(0), stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *format, __gnuc_va_list arg)
{
int v2; // edx
__int64 result; // rax

v2 = vsnprintf((char *)&g_outputBuffer + __readfsqword(0), 0x100uLL, format, arg);
result = 0LL;
if ( v2 > 0 )
{
fputs((const char *)&g_outputBuffer + __readfsqword(0), stderr);
result = 1LL;
}
return result;
}

original_code:
static int debug_outputlnA_impl(const char * formatString, va_list args)
{
 int chars_printed;
 chars_printed = vsnprintf(g_outputBuffer, (256), formatString, args);
 if (chars_printed>0)
    {
  fprintf(stderr, "%s", g_outputBuffer);
  return 1;
    }
 return 0;
}

canonical_original_code:
static int debug_outputlnA_impl(char *formatString, __builtin_va_list args)
{
 int chars_printed;
 chars_printed = vsnprintf(g_outputBuffer, (256), formatString, args);
 if (chars_printed>0)
    {
  fprintf(stderr, "%s", g_outputBuffer);
  return 1;
    }
 return 0;
}

variable_types:
formatString
char *


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

__writefsbyte((unsigned int)&g_lines[g_write_offset], 0);
result = fputs(&g_lines[__readfsqword(0)], stderr);
g_write_offset = 0LL;
return result;
}

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

__writefsbyte((unsigned int)&g_lines[g_write_offset], 0);
result = fputs(&g_lines[__readfsqword(0)], stderr);
g_write_offset = 0LL;
return result;
}

original_code:
void debug_output_flush(void)
{
    g_lines[g_write_offset] = '\0';
    fprintf(stderr, "%s", &g_lines[0]);
    g_write_offset = 0;
}

canonical_original_code:
void debug_output_flush()
{
    g_lines[g_write_offset] = '\0';
    fprintf(stderr, "%s", &g_lines[0]);
    g_write_offset = 0;
}


decompiled_code:
__int64 debug_outputln_bufferedA(char *format, ...)
{
unsigned int v1; // eax
__int64 v2; // r8
unsigned __int64 v3; // rsi
char *v4; // rcx
char *v5; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsnprintf((char *)&g_outputBuffer + __readfsqword(0), 0x100uLL, format, arg);
if ( (int)v1 <= 0 )
return 0LL;
if ( (int)v1 <= 255 )
{
v2 = g_write_offset;
v3 = __readfsqword(0);
v4 = &g_lines[g_write_offset + v3];
v5 = (char *)&g_outputBuffer + v3;
if ( v1 >= 8 )
{
*(_QWORD *)v4 = g_outputBuffer;
*(_QWORD *)&v4[v1 - 8] = *(_QWORD *)&v5[v1 - 8];
qmemcpy(
(void *)((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - &v4[-((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * ((v1 + (_DWORD)v4 - (((_DWORD)v4 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v1 & 4) != 0 )
{
*(_DWORD *)v4 = g_outputBuffer;
*(_DWORD *)&v4[v1 - 4] = *(_DWORD *)&v5[v1 - 4];
}
else
{
*v4 = g_outputBuffer;
if ( (v1 & 2) != 0 )
*(_WORD *)&v4[v1 - 2] = *(_WORD *)&v5[v1 - 2];
}
g_write_offset = (int)v1 + v2;
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
unsigned int v1; // eax
__int64 v2; // r8
unsigned __int64 v3; // rsi
char *v4; // rcx
char *v5; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
v1 = vsnprintf((char *)&g_outputBuffer + __readfsqword(0), 0x100uLL, format, arg);
if ( (int)v1 <= 0 )
return 0LL;
if ( (int)v1 <= 255 )
{
v2 = g_write_offset;
v3 = __readfsqword(0);
v4 = &g_lines[g_write_offset + v3];
v5 = (char *)&g_outputBuffer + v3;
if ( v1 >= 8 )
{
*(_QWORD *)v4 = g_outputBuffer;
*(_QWORD *)&v4[v1 - 8] = *(_QWORD *)&v5[v1 - 8];
qmemcpy(
(void *)((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v5 - &v4[-((unsigned __int64)(v4 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * ((v1 + (_DWORD)v4 - (((_DWORD)v4 + 8) & 0xFFFFFFF8)) >> 3));
}
else if ( (v1 & 4) != 0 )
{
*(_DWORD *)v4 = g_outputBuffer;
*(_DWORD *)&v4[v1 - 4] = *(_DWORD *)&v5[v1 - 4];
}
else
{
*v4 = g_outputBuffer;
if ( (v1 & 2) != 0 )
*(_WORD *)&v4[v1 - 2] = *(_WORD *)&v5[v1 - 2];
}
g_write_offset = (int)v1 + v2;
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int debug_outputln_bufferedA(const char * formatString, ...)
{
 int chars_written;
 va_list args;
 __builtin_va_start(args,formatString);
 chars_written = vsnprintf(g_outputBuffer, (256), formatString, args);
 if (chars_written > 0)
    {
  if (chars_written >= (256))
  {
   return -1;
  }
  else
  {
   size_t new_length = chars_written;
   if (new_length >= (4096))
   {
    debug_output_flush();
   }
   memcpy(&g_lines[g_write_offset],g_outputBuffer,chars_written*sizeof(char));
   g_write_offset += chars_written;
  }
    }
    __builtin_va_end(args);
    return 0;
}

canonical_original_code:
int debug_outputln_bufferedA(char *formatString, ...)
{
 int chars_written;
 __builtin_va_list args;
 __builtin_va_start(args,formatString);
 chars_written = vsnprintf(g_outputBuffer, (256), formatString, args);
 if (chars_written > 0)
    {
  if (chars_written >= (256))
  {
   return -1;
  }
  else
  {
   unsigned long new_length = chars_written;
   if (new_length >= (4096))
   {
    debug_output_flush();
   }
   memcpy(&g_lines[g_write_offset],g_outputBuffer,chars_written*sizeof(char));
   g_write_offset += chars_written;
  }
    }
    __builtin_va_end(args);
    return 0;
}


decompiled_code:
__int64 debug_outputlnA(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return debug_outputlnA_impl(a1, arg);
}

canonical_decompiled_code:
__int64 func3(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return func0(a1, arg);
}

original_code:
int debug_outputlnA(const char * formatString, ...)
{
 int retval;
 va_list args;
 __builtin_va_start(args,formatString);
 retval = debug_outputlnA_impl(formatString, args);
 __builtin_va_end(args);
 return retval;
}

canonical_original_code:
int debug_outputlnA(char *formatString, ...)
{
 int retval;
 __builtin_va_list args;
 __builtin_va_start(args,formatString);
 retval = debug_outputlnA_impl(formatString, args);
 __builtin_va_end(args);
 return retval;
}

variable_types: retval int


decompiled_code:
__int64 debug_outputlnW(wchar_t *pwcs, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( wcstombs(&g_tmp_buffer[__readfsqword(0)], pwcs, 0x100uLL) == -1LL )
return 0xFFFFFFFFLL;
va_start(arg, pwcs);
return debug_outputlnA_impl(&g_tmp_buffer[__readfsqword(0)], arg);
}

canonical_decompiled_code:
__int64 func4(wchar_t *pwcs, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( wcstombs(&g_tmp_buffer[__readfsqword(0)], pwcs, 0x100uLL) == -1LL )
return 0xFFFFFFFFLL;
va_start(arg, pwcs);
return func0(&g_tmp_buffer[__readfsqword(0)], arg);
}

original_code:
int debug_outputlnW(const wchar_t * formatString, ...)
{
 int retval = -1;
 size_t bytes_written;
 bytes_written = wcstombs(g_tmp_buffer, formatString, sizeof(g_tmp_buffer));
 if ((bytes_written) != (-1))
 {
  va_list args;
  __builtin_va_start(args,formatString);
  retval = debug_outputlnA_impl(g_tmp_buffer, args);
  __builtin_va_end(args);
 }
 return retval;
}

canonical_original_code:
int debug_outputlnW(int *formatString, ...)
{
 int retval = -1;
 unsigned long bytes_written;
 bytes_written = wcstombs(g_tmp_buffer, formatString, sizeof(g_tmp_buffer));
 if ((bytes_written) != (-1))
 {
  __builtin_va_list args;
  __builtin_va_start(args,formatString);
  retval = debug_outputlnA_impl(g_tmp_buffer, args);
  __builtin_va_end(args);
 }
 return retval;
}

variable_types:
formatString
int *


decompiled_code:
__int64 __fastcall join_mcast_group_set_ttl(int fd, __int64 a2, __int64 a3, int a4)
{
int v5; // eax
int v6; // eax
unsigned int v7; // ebx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
int v16; // [rsp+Ch] [rbp-4Ch] BYREF
__m128i optval; // [rsp+10h] [rbp-48h] BYREF
int v18; // [rsp+20h] [rbp-38h]
int v19[12]; // [rsp+28h] [rbp-30h] BYREF

v16 = a4;
v5 = bind(fd, *(const struct sockaddr **)(a3 + 24), *(_DWORD *)(a3 + 16));
if ( v5 < 0 )
{
v7 = v5;
v9 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %d %8.8x\n", 28LL, "mcast_utils.c", v7, v9);
goto LABEL_10;
}
v6 = *(_DWORD *)(a2 + 4);
if ( v6 == 2 )
{
v19[0] = *(_DWORD *)(*(_QWORD *)(a2 + 24) + 4LL);
v19[1] = *(_DWORD *)(*(_QWORD *)(a3 + 24) + 4LL);
v7 = setsockopt(fd, 0, 35, v19, 8u);
if ( v7 == -1 )
{
v11 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 44LL, "mcast_utils.c", v11);
}
else
{
v7 = setsockopt(fd, 0, 32, (const void *)(*(_QWORD *)(a3 + 24) + 4LL), 4u);
if ( v7 == -1 )
{
v12 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 54LL, "mcast_utils.c", v12);
}
else
{
v7 = setsockopt(fd, 0, 33, &v16, 4u);
if ( v7 != -1 )
goto LABEL_7;
}
}
goto LABEL_10;
}
v7 = -1;
if ( v6 == 10 )
{
optval = _mm_loadu_si128((const __m128i *)(*(_QWORD *)(a2 + 24) + 8LL));
v18 = *(_DWORD *)(*(_QWORD *)(a3 + 24) + 24LL);
v7 = setsockopt(fd, 41, 20, &optval, 0x14u);
if ( v7 == -1 )
{
v13 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 78LL, "mcast_utils.c", v13);
}
else
{
v7 = setsockopt(fd, 41, 17, (const void *)(*(_QWORD *)(a3 + 24) + 24LL), 4u);
if ( v7 == -1 )
{
v14 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 88LL, "mcast_utils.c", v14);
}
else
{
v7 = setsockopt(fd, 41, 18, &v16, 4u);
if ( v7 != -1 )
goto LABEL_7;
v15 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 98LL, "mcast_utils.c", v15);
}
}
LABEL_10:
v10 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 109LL, "mcast_utils.c", v10);
return v7;
}
LABEL_7:
debug_outputlnA("%4.4u %s : %d\n", 106LL, "mcast_utils.c", v7);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, __int64 a3, int a4)
{
int v5; // eax
int v6; // eax
unsigned int v7; // ebx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
int v16; // [rsp+Ch] [rbp-4Ch] BYREF
__m128i optval; // [rsp+10h] [rbp-48h] BYREF
int v18; // [rsp+20h] [rbp-38h]
int v19[12]; // [rsp+28h] [rbp-30h] BYREF

v16 = a4;
v5 = bind(fd, *(const struct sockaddr **)(a3 + 24), *(_DWORD *)(a3 + 16));
if ( v5 < 0 )
{
v7 = v5;
v9 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %d %8.8x\n", 28LL, "mcast_utils.c", v7, v9);
goto LABEL_10;
}
v6 = *(_DWORD *)(a2 + 4);
if ( v6 == 2 )
{
v19[0] = *(_DWORD *)(*(_QWORD *)(a2 + 24) + 4LL);
v19[1] = *(_DWORD *)(*(_QWORD *)(a3 + 24) + 4LL);
v7 = setsockopt(fd, 0, 35, v19, 8u);
if ( v7 == -1 )
{
v11 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 44LL, "mcast_utils.c", v11);
}
else
{
v7 = setsockopt(fd, 0, 32, (const void *)(*(_QWORD *)(a3 + 24) + 4LL), 4u);
if ( v7 == -1 )
{
v12 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 54LL, "mcast_utils.c", v12);
}
else
{
v7 = setsockopt(fd, 0, 33, &v16, 4u);
if ( v7 != -1 )
goto LABEL_7;
}
}
goto LABEL_10;
}
v7 = -1;
if ( v6 == 10 )
{
optval = _mm_loadu_si128((const __m128i *)(*(_QWORD *)(a2 + 24) + 8LL));
v18 = *(_DWORD *)(*(_QWORD *)(a3 + 24) + 24LL);
v7 = setsockopt(fd, 41, 20, &optval, 0x14u);
if ( v7 == -1 )
{
v13 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 78LL, "mcast_utils.c", v13);
}
else
{
v7 = setsockopt(fd, 41, 17, (const void *)(*(_QWORD *)(a3 + 24) + 24LL), 4u);
if ( v7 == -1 )
{
v14 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 88LL, "mcast_utils.c", v14);
}
else
{
v7 = setsockopt(fd, 41, 18, &v16, 4u);
if ( v7 != -1 )
goto LABEL_7;
v15 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 98LL, "mcast_utils.c", v15);
}
}
LABEL_10:
v10 = get_last_socket_error();
debug_outputlnA("%4.4u %10.10s : %8.8x", 109LL, "mcast_utils.c", v10);
return v7;
}
LABEL_7:
debug_outputlnA("%4.4u %s : %d\n", 106LL, "mcast_utils.c", v7);
return v7;
}

original_code:
int join_mcast_group_set_ttl(SOCKET s, struct addrinfo const * group, struct addrinfo const * iface, int ttl)
{
    struct ip_mreq mreqv4;
    struct ipv6_mreq mreqv6;
    char *optval=((void *)0);
    int optlevel = 0,
                     option = 0,
                     optlen = 0,
                     rc;
    rc = bind(s, iface->ai_addr, iface->ai_addrlen);
    if (rc < 0)
    {
        debug_outputlnA("%4.4u %10.10s : %d %8.8x\n", 28, "mcast_utils.c", rc, get_last_socket_error());
        goto error;
    }
    switch (group->ai_family)
    {
        case 2:
            optlevel = IPPROTO_IP;
            option = 35;
            optval = (char *)& mreqv4;
            optlen = sizeof(mreqv4);
            mreqv4.imr_multiaddr.s_addr = ((LPSOCKADDR_IN )group->ai_addr)->sin_addr.s_addr;
            mreqv4.imr_interface.s_addr = ((LPSOCKADDR_IN )iface->ai_addr)->sin_addr.s_addr;
            rc = setsockopt(s, optlevel, option, (const char *)&mreqv4, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 44, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 32;
            optval = (char *) &((LPSOCKADDR_IN )iface->ai_addr)->sin_addr.s_addr;
            optlen = sizeof(((LPSOCKADDR_IN )iface->ai_addr)->sin_addr.s_addr);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 54, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 33;
            optval = (char *) &ttl;
            optlen = sizeof(ttl);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                goto error;
            }
            break;
        case 10:
            optlevel = IPPROTO_IPV6;
            option = 20;
            optval = (char *) &mreqv6;
            optlen = sizeof(mreqv6);
            mreqv6.ipv6mr_multiaddr = ((LPSOCKADDR_IN6 )group->ai_addr)->sin6_addr;
            mreqv6.ipv6mr_interface = ((LPSOCKADDR_IN6 )iface->ai_addr)->sin6_scope_id;
            rc = setsockopt(s, optlevel, option, (const char *)&mreqv6, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 78, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 17;
            optval = (char *) &((LPSOCKADDR_IN6 )iface->ai_addr)->sin6_scope_id;
            optlen = sizeof(((LPSOCKADDR_IN6 )iface->ai_addr)->sin6_scope_id);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 88, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 18;
            optval = (char *) &ttl;
            optlen = sizeof(ttl);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 98, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            break;
        default:
            rc = (-1);
            break;
    }
    debug_outputlnA("%4.4u %s : %d\n", 106, "mcast_utils.c", rc);
    return rc;
error:
    debug_outputlnA("%4.4u %10.10s : %8.8x", 109, "mcast_utils.c", get_last_socket_error());
    return rc;
}

canonical_original_code:
int join_mcast_group_set_ttl(int s, struct addrinfo *group, struct addrinfo *iface, int ttl)
{
    struct ip_mreq mreqv4;
    struct ipv6_mreq mreqv6;
    char *optval = ((void *)0);
    int optlevel = 0; int option = 0; int optlen = 0; int rc;
    rc = bind(s, iface->ai_addr, iface->ai_addrlen);
    if (rc < 0)
    {
        debug_outputlnA("%4.4u %10.10s : %d %8.8x\n", 28, "mcast_utils.c", rc, get_last_socket_error());
        goto error;
    }
    switch (group->ai_family)
    {
        case 2:
            optlevel = IPPROTO_IP;
            option = 35;
            optval = (char *)& mreqv4;
            optlen = sizeof(mreqv4);
            mreqv4.imr_multiaddr.s_addr = ((struct sockaddr_in * )group->ai_addr)->sin_addr.s_addr;
            mreqv4.imr_interface.s_addr = ((struct sockaddr_in * )iface->ai_addr)->sin_addr.s_addr;
            rc = setsockopt(s, optlevel, option, (char *)&mreqv4, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 44, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 32;
            optval = (char *) &((struct sockaddr_in * )iface->ai_addr)->sin_addr.s_addr;
            optlen = sizeof(((struct sockaddr_in * )iface->ai_addr)->sin_addr.s_addr);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 54, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 33;
            optval = (char *) &ttl;
            optlen = sizeof(ttl);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                goto error;
            }
            break;
        case 10:
            optlevel = IPPROTO_IPV6;
            option = 20;
            optval = (char *) &mreqv6;
            optlen = sizeof(mreqv6);
            mreqv6.ipv6mr_multiaddr = ((struct sockaddr_in6 * )group->ai_addr)->sin6_addr;
            mreqv6.ipv6mr_interface = ((struct sockaddr_in6 * )iface->ai_addr)->sin6_scope_id;
            rc = setsockopt(s, optlevel, option, (char *)&mreqv6, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 78, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 17;
            optval = (char *) &((struct sockaddr_in6 * )iface->ai_addr)->sin6_scope_id;
            optlen = sizeof(((struct sockaddr_in6 * )iface->ai_addr)->sin6_scope_id);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 88, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            option = 18;
            optval = (char *) &ttl;
            optlen = sizeof(ttl);
            rc = setsockopt(s, optlevel, option, optval, optlen);
            if ((-1) == rc)
            {
                debug_outputlnA("%4.4u %10.10s : %8.8x", 98, "mcast_utils.c", get_last_socket_error());
                goto error;
            }
            break;
        default:
            rc = (-1);
            break;
    }
    debug_outputlnA("%4.4u %s : %d\n", 106, "mcast_utils.c", rc);
    return rc;
error:
    debug_outputlnA("%4.4u %10.10s : %8.8x", 109, "mcast_utils.c", get_last_socket_error());
    return rc;
}

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

variable_types:
iface
struct addrinfo *

variable_types: ttl int

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

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

variable_types:
optval
char *

variable_types: optlevel int

variable_types: option int

variable_types: optlen int

variable_types: rc int

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }

user_defined_types: struct ipv6_mreq { struct in6_addr ipv6mr_multiaddr; unsigned int ipv6mr_interface; }

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

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


JoinMulticastGroup

original_code:
int JoinMulticastGroup(SOCKET s, struct addrinfo const *group, struct addrinfo const *iface)
{
    struct ip_mreq mreqv4;
    struct ipv6_mreq mreqv6;
    char *optval=((void *)0);
    int optlevel = 0,
                     option = 0,
                     optlen = 0,
                     rc;
    rc = (0);
    if (group->ai_family == 2)
    {
        optlevel = IPPROTO_IP;
        option = 35;
        optval = (char *)& mreqv4;
        optlen = sizeof(mreqv4);
        mreqv4.imr_multiaddr.s_addr = ((LPSOCKADDR_IN )group->ai_addr)->sin_addr.s_addr;
        mreqv4.imr_interface.s_addr = ((LPSOCKADDR_IN )iface->ai_addr)->sin_addr.s_addr;
    }
    else if (group->ai_family == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 20;
        optval = (char *) &mreqv6;
        optlen = sizeof(mreqv6);
        mreqv6.ipv6mr_multiaddr = ((LPSOCKADDR_IN6 )group->ai_addr)->sin6_addr;
        mreqv6.ipv6mr_interface = ((LPSOCKADDR_IN6 )iface->ai_addr)->sin6_scope_id;
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", group->ai_family);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

canonical_original_code:
int JoinMulticastGroup(int s, struct addrinfo *group, struct addrinfo *iface)
{
    struct ip_mreq mreqv4;
    struct ipv6_mreq mreqv6;
    char *optval = ((void *)0);
    int optlevel = 0; int option = 0; int optlen = 0; int rc;
    rc = (0);
    if (group->ai_family == 2)
    {
        optlevel = IPPROTO_IP;
        option = 35;
        optval = (char *)& mreqv4;
        optlen = sizeof(mreqv4);
        mreqv4.imr_multiaddr.s_addr = ((struct sockaddr_in * )group->ai_addr)->sin_addr.s_addr;
        mreqv4.imr_interface.s_addr = ((struct sockaddr_in * )iface->ai_addr)->sin_addr.s_addr;
    }
    else if (group->ai_family == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 20;
        optval = (char *) &mreqv6;
        optlen = sizeof(mreqv6);
        mreqv6.ipv6mr_multiaddr = ((struct sockaddr_in6 * )group->ai_addr)->sin6_addr;
        mreqv6.ipv6mr_interface = ((struct sockaddr_in6 * )iface->ai_addr)->sin6_scope_id;
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", group->ai_family);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

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

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


SetSendInterface

decompiled_code:
__int64 __fastcall SetSendInterface(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // eax
const void *v5; // rcx
int v6; // edx
__int64 v7; // rsi
__int64 v8; // rdx
__int64 v9; // rcx
unsigned int v10; // ebx
const char *v12; // rax
__int64 v13; // rdx
__int64 v14; // rcx

v4 = *(_DWORD *)(a2 + 4);
if ( v4 == 2 )
{
v5 = (const void *)(*(_QWORD *)(a2 + 24) + 4LL);
v6 = 32;
v7 = 0LL;
}
else
{
if ( v4 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", (const char *)v4, a3, a4);
return (unsigned int)-1;
}
v5 = (const void *)(*(_QWORD *)(a2 + 24) + 24LL);
v6 = 17;
v7 = 41LL;
}
v10 = setsockopt(a1, v7, v6, v5, 4u);
if ( v10 == -1 )
{
v12 = (const char *)get_last_socket_error(a1, v7, v8, v9);
debug_outputlnA("%s %4.4u : %d\n", v12, v13, v14);
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // eax
const void *v5; // rcx
int v6; // edx
__int64 v7; // rsi
__int64 v8; // rdx
__int64 v9; // rcx
unsigned int v10; // ebx
const char *v12; // rax
__int64 v13; // rdx
__int64 v14; // rcx

v4 = *(_DWORD *)(a2 + 4);
if ( v4 == 2 )
{
v5 = (const void *)(*(_QWORD *)(a2 + 24) + 4LL);
v6 = 32;
v7 = 0LL;
}
else
{
if ( v4 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", (const char *)v4, a3, a4);
return (unsigned int)-1;
}
v5 = (const void *)(*(_QWORD *)(a2 + 24) + 24LL);
v6 = 17;
v7 = 41LL;
}
v10 = setsockopt(a1, v7, v6, v5, 4u);
if ( v10 == -1 )
{
v12 = (const char *)get_last_socket_error(a1, v7, v8, v9);
debug_outputlnA("%s %4.4u : %d\n", v12, v13, v14);
}
return v10;
}

original_code:
int SetSendInterface(SOCKET s, struct addrinfo const *iface)
{
    char *optval=((void *)0);
    int optlevel = 0,
          option = 0,
          optlen = 0,
          rc;
    rc = (0);
    if (iface->ai_family == 2)
    {
        optlevel = IPPROTO_IP;
        option = 32;
        optval = (char *) &((LPSOCKADDR_IN )iface->ai_addr)->sin_addr.s_addr;
        optlen = sizeof(((LPSOCKADDR_IN )iface->ai_addr)->sin_addr.s_addr);
    }
    else if (iface->ai_family == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 17;
        optval = (char *) &((LPSOCKADDR_IN6 )iface->ai_addr)->sin6_scope_id;
        optlen = sizeof(((LPSOCKADDR_IN6 )iface->ai_addr)->sin6_scope_id);
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", iface->ai_family);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

canonical_original_code:
int SetSendInterface(int s, struct addrinfo *iface)
{
    char *optval = ((void *)0);
    int optlevel = 0; int option = 0; int optlen = 0; int rc;
    rc = (0);
    if (iface->ai_family == 2)
    {
        optlevel = IPPROTO_IP;
        option = 32;
        optval = (char *) &((struct sockaddr_in * )iface->ai_addr)->sin_addr.s_addr;
        optlen = sizeof(((struct sockaddr_in * )iface->ai_addr)->sin_addr.s_addr);
    }
    else if (iface->ai_family == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 17;
        optval = (char *) &((struct sockaddr_in6 * )iface->ai_addr)->sin6_scope_id;
        optlen = sizeof(((struct sockaddr_in6 * )iface->ai_addr)->sin6_scope_id);
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", iface->ai_family);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}


SetMulticastTtl

decompiled_code:
__int64 __fastcall SetMulticastTtl(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
__int64 v5; // rsi
unsigned int v6; // ebx
const char *v7; // rax
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

a3 = (unsigned __int8)a3;
optval[0] = (unsigned __int8)a3;
if ( (_DWORD)a2 == 2 )
{
v4 = 33;
v5 = 0LL;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return (unsigned int)-1;
}
v4 = 18;
v5 = 41LL;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v7 = (const char *)get_last_socket_error(a1, v5, v10, v11);
debug_outputlnA("%s %4.4u : %d\n", v7, v8, v9);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
__int64 v5; // rsi
unsigned int v6; // ebx
const char *v7; // rax
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

a3 = (unsigned __int8)a3;
optval[0] = (unsigned __int8)a3;
if ( (_DWORD)a2 == 2 )
{
v4 = 33;
v5 = 0LL;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return (unsigned int)-1;
}
v4 = 18;
v5 = 41LL;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v7 = (const char *)get_last_socket_error(a1, v5, v10, v11);
debug_outputlnA("%s %4.4u : %d\n", v7, v8, v9);
}
return v6;
}

original_code:
int SetMulticastTtl(SOCKET s, int af, uint8_t ub_ttl)
{
    char *optval=((void *)0);
    int optlevel = 0,
          option = 0,
          optlen = 0,
          rc;
    unsigned int ttl = ub_ttl;
    rc = (0);
    if (af == 2)
    {
        optlevel = IPPROTO_IP;
        option = 33;
        optval = (char *) &ttl;
        optlen = sizeof(ttl);
    }
    else if (af == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 18;
        optval = (char *) &ttl;
        optlen = sizeof(ttl);
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", af);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

canonical_original_code:
int SetMulticastTtl(int s, int af, unsigned char ub_ttl)
{
    char *optval = ((void *)0);
    int optlevel = 0; int option = 0; int optlen = 0; int rc;
    unsigned int ttl = ub_ttl;
    rc = (0);
    if (af == 2)
    {
        optlevel = IPPROTO_IP;
        option = 33;
        optval = (char *) &ttl;
        optlen = sizeof(ttl);
    }
    else if (af == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 18;
        optval = (char *) &ttl;
        optlen = sizeof(ttl);
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", af);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

variable_types: af int

variable_types:
ttl
unsigned int


SetMulticastLoopBack

decompiled_code:
__int64 __fastcall SetMulticastLoopBack(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
__int64 v5; // rsi
unsigned int v6; // ebx
const char *v7; // rax
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a3;
if ( (_DWORD)a2 == 2 )
{
v4 = 34;
v5 = 0LL;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return (unsigned int)-1;
}
v4 = 19;
v5 = 41LL;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v7 = (const char *)get_last_socket_error(a1, v5, v10, v11);
debug_outputlnA("%s %4.4u : %d\n", v7, v8, v9);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
__int64 v5; // rsi
unsigned int v6; // ebx
const char *v7; // rax
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // rdx
__int64 v11; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a3;
if ( (_DWORD)a2 == 2 )
{
v4 = 34;
v5 = 0LL;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return (unsigned int)-1;
}
v4 = 19;
v5 = 41LL;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v7 = (const char *)get_last_socket_error(a1, v5, v10, v11);
debug_outputlnA("%s %4.4u : %d\n", v7, v8, v9);
}
return v6;
}

original_code:
int SetMulticastLoopBack(SOCKET s, int af, int loopval)
{
    char *optval=((void *)0);
    int optlevel = 0,
          option = 0,
          optlen = 0,
          rc;
    rc = (0);
    if (af == 2)
    {
        optlevel = IPPROTO_IP;
        option = 34;
        optval = (char *) &loopval;
        optlen = sizeof(loopval);
    }
    else if (af == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 19;
        optval = (char *) &loopval;
        optlen = sizeof(loopval);
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", af);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

canonical_original_code:
int SetMulticastLoopBack(int s, int af, int loopval)
{
    char *optval = ((void *)0);
    int optlevel = 0; int option = 0; int optlen = 0; int rc;
    rc = (0);
    if (af == 2)
    {
        optlevel = IPPROTO_IP;
        option = 34;
        optval = (char *) &loopval;
        optlen = sizeof(loopval);
    }
    else if (af == 10)
    {
        optlevel = IPPROTO_IPV6;
        option = 19;
        optval = (char *) &loopval;
        optlen = sizeof(loopval);
    }
    else
    {
        debug_outputlnA("%s %4.4u : %d\n", af);
        rc = (-1);
    }
    if (rc != (-1))
    {
        rc = setsockopt(s, optlevel, option, optval, optlen);
        if (rc == (-1))
        {
            debug_outputlnA("%s %4.4u : %d\n", get_last_socket_error());
        }
    }
    return rc;
}

variable_types: loopval int


decompiled_code:
__int64 get_last_socket_error()
{
return *_errno_location();
}

canonical_decompiled_code:
__int64 func0()
{
return *_errno_location();
}

original_code:
unsigned long get_last_socket_error(void)
{
 return (*__errno_location ());
}

canonical_original_code:
unsigned long get_last_socket_error()
{
 return (*__errno_location ());
}

return_type: unsigned long


closesocket

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

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

original_code:
int closesocket(SOCKET s)
{
 return close(s);
}

canonical_original_code:
int closesocket(int s)
{
 return close(s);
}


decompiled_code:
_BOOL8 __fastcall setup_multicast_impl(const char *a1, unsigned int a2, const char *a3, const char *a4, __int64 a5)
{
unsigned int *v8; // rax
unsigned int *v9; // rdi
unsigned int v10; // eax
__int64 v11; // rdi
_BOOL4 v12; // ebp
__int64 v13; // rdi
__int64 v15; // rbx
__int64 v16; // rax
__int64 v17; // rbx
__int64 v18; // rax
__int64 v19; // rbx
__int64 v20; // rax
__int64 v21; // rbx
__int64 v22; // rax
__int64 v23; // rbx
__int64 v24; // rax

debug_outputlnA("%s %d : %s %s %s", "mcast-setup-linux.c", 92LL, a1, a3, a4);
v8 = (unsigned int *)ResolveAddressWithFlags(a3, a4, 0LL, 2LL, 17LL, 1LL);
*(_QWORD *)(a5 + 8) = v8;
if ( v8 )
{
dump_addrinfo(v8, "mcast-setup-linux.c", 0x63u);
v9 = (unsigned int *)ResolveAddressWithFlags(
a1,
a4,
*(unsigned int *)(*(_QWORD *)(a5 + 8) + 4LL),
*(unsigned int *)(*(_QWORD *)(a5 + 8) + 8LL),
*(unsigned int *)(*(_QWORD *)(a5 + 8) + 12LL),
1LL);
*(_QWORD *)a5 = v9;
if ( v9 )
{
dump_addrinfo(v9, "mcast-setup-linux.c", 0x6Bu);
v10 = socket(
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 4LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 8LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 12LL));
v11 = v10;
*(_DWORD *)(a5 + 16) = v10;
if ( v10 == -1 )
{
v19 = get_last_socket_error(0xFFFFFFFFLL);
v20 = get_last_socket_error(v11);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 115LL, v20, v19);
v12 = 0;
}
else
{
v12 = set_reuse_addr(v10);
if ( v12 )
{
v13 = *(unsigned int *)(a5 + 16);
if ( bind(v13, *(const struct sockaddr **)(*(_QWORD *)a5 + 24LL), *(_DWORD *)(*(_QWORD *)a5 + 16LL)) == -1 )
{
v23 = get_last_socket_error(v13);
v24 = get_last_socket_error(v13);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 126LL, v24, v23);
v12 = 0;
}
else
{
dump_locally_bound_socket(*(_DWORD *)(a5 + 16), "mcast-setup-linux.c", 0x81u);
join_mcast_group_set_ttl(*(unsigned int *)(a5 + 16), *(_QWORD *)(a5 + 8), *(_QWORD *)a5, a2);
v12 = 1;
}
}
else
{
v21 = get_last_socket_error(v11);
v22 = get_last_socket_error(v11);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 120LL, v22, v21);
}
}
}
else
{
v17 = ((__int64 (*)(void))get_last_socket_error)();
v18 = get_last_socket_error(0LL);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 104LL, v18, v17);
v12 = 0;
}
}
else
{
v15 = ((__int64 (*)(void))get_last_socket_error)();
v16 = ((__int64 (*)(void))get_last_socket_error)();
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 96LL, v16, v15);
v12 = 0;
}
return v12;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, unsigned int a2, const char *a3, const char *a4, __int64 a5)
{
unsigned int *v8; // rax
unsigned int *v9; // rdi
unsigned int v10; // eax
__int64 v11; // rdi
_BOOL4 v12; // ebp
__int64 v13; // rdi
__int64 v15; // rbx
__int64 v16; // rax
__int64 v17; // rbx
__int64 v18; // rax
__int64 v19; // rbx
__int64 v20; // rax
__int64 v21; // rbx
__int64 v22; // rax
__int64 v23; // rbx
__int64 v24; // rax

debug_outputlnA("%s %d : %s %s %s", "mcast-setup-linux.c", 92LL, a1, a3, a4);
v8 = (unsigned int *)ResolveAddressWithFlags(a3, a4, 0LL, 2LL, 17LL, 1LL);
*(_QWORD *)(a5 + 8) = v8;
if ( v8 )
{
func1(v8, "mcast-setup-linux.c", 0x63u);
v9 = (unsigned int *)ResolveAddressWithFlags(
a1,
a4,
*(unsigned int *)(*(_QWORD *)(a5 + 8) + 4LL),
*(unsigned int *)(*(_QWORD *)(a5 + 8) + 8LL),
*(unsigned int *)(*(_QWORD *)(a5 + 8) + 12LL),
1LL);
*(_QWORD *)a5 = v9;
if ( v9 )
{
func1(v9, "mcast-setup-linux.c", 0x6Bu);
v10 = socket(
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 4LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 8LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 12LL));
v11 = v10;
*(_DWORD *)(a5 + 16) = v10;
if ( v10 == -1 )
{
v19 = get_last_socket_error(0xFFFFFFFFLL);
v20 = get_last_socket_error(v11);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 115LL, v20, v19);
v12 = 0;
}
else
{
v12 = func2(v10);
if ( v12 )
{
v13 = *(unsigned int *)(a5 + 16);
if ( bind(v13, *(const struct sockaddr **)(*(_QWORD *)a5 + 24LL), *(_DWORD *)(*(_QWORD *)a5 + 16LL)) == -1 )
{
v23 = get_last_socket_error(v13);
v24 = get_last_socket_error(v13);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 126LL, v24, v23);
v12 = 0;
}
else
{
func3(*(_DWORD *)(a5 + 16), "mcast-setup-linux.c", 0x81u);
join_mcast_group_set_ttl(*(unsigned int *)(a5 + 16), *(_QWORD *)(a5 + 8), *(_QWORD *)a5, a2);
v12 = 1;
}
}
else
{
v21 = get_last_socket_error(v11);
v22 = get_last_socket_error(v11);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 120LL, v22, v21);
}
}
}
else
{
v17 = ((__int64 (*)(void))get_last_socket_error)();
v18 = get_last_socket_error(0LL);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 104LL, v18, v17);
v12 = 0;
}
}
else
{
v15 = ((__int64 (*)(void))get_last_socket_error)();
v16 = ((__int64 (*)(void))get_last_socket_error)();
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 96LL, v16, v15);
v12 = 0;
}
return v12;
}

original_code:
static int setup_multicast_impl(char * bindAddr, unsigned int nTTL, char * p_multicast_addr, char * p_port, struct mcast_connection * p_mcast_conn)
{
 int rc;
    debug_outputlnA("%s %d : %s %s %s", "mcast-setup-linux.c", 92, bindAddr, p_multicast_addr, p_port);
 p_mcast_conn->multiAddr_ = ResolveAddressWithFlags(p_multicast_addr, p_port, 0, SOCK_DGRAM, IPPROTO_UDP, 0x0001);
 if (((void *)0) == p_mcast_conn->multiAddr_)
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 96, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    dump_addrinfo(p_mcast_conn->multiAddr_, "mcast-setup-linux.c", 99);
 p_mcast_conn->bindAddr_ = ResolveAddressWithFlags(bindAddr, p_port, p_mcast_conn->multiAddr_->ai_family, p_mcast_conn->multiAddr_->ai_socktype, p_mcast_conn->multiAddr_->ai_protocol, 0x0001);
 if (((void *)0) == p_mcast_conn->bindAddr_)
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 104, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    dump_addrinfo(p_mcast_conn->bindAddr_, "mcast-setup-linux.c", 107);
 p_mcast_conn->socket_ = socket(p_mcast_conn->multiAddr_->ai_family, p_mcast_conn->multiAddr_->ai_socktype, p_mcast_conn->multiAddr_->ai_protocol);
 if (p_mcast_conn->socket_ == (-1))
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 115, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    if (!set_reuse_addr(p_mcast_conn->socket_))
    {
        debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 120, get_last_socket_error(), get_last_socket_error());
        goto cleanup;
    }
 rc = bind(p_mcast_conn->socket_, p_mcast_conn->bindAddr_->ai_addr, (int) p_mcast_conn->bindAddr_->ai_addrlen);
 if (rc == (-1))
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 126, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    dump_locally_bound_socket(p_mcast_conn->socket_, "mcast-setup-linux.c", 129);
    rc = join_mcast_group_set_ttl(p_mcast_conn->socket_, p_mcast_conn->multiAddr_, p_mcast_conn->bindAddr_, nTTL);
 return 1;
cleanup:
 return 0;
}

canonical_original_code:
static int setup_multicast_impl(char *bindAddr, unsigned int nTTL, char *p_multicast_addr, char *p_port, struct mcast_connection *p_mcast_conn)
{
 int rc;
    debug_outputlnA("%s %d : %s %s %s", "mcast-setup-linux.c", 92, bindAddr, p_multicast_addr, p_port);
 p_mcast_conn->multiAddr_ = ResolveAddressWithFlags(p_multicast_addr, p_port, 0, SOCK_DGRAM, IPPROTO_UDP, 0x0001);
 if (((void *)0) == p_mcast_conn->multiAddr_)
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 96, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    dump_addrinfo(p_mcast_conn->multiAddr_, "mcast-setup-linux.c", 99);
 p_mcast_conn->bindAddr_ = ResolveAddressWithFlags(bindAddr, p_port, p_mcast_conn->multiAddr_->ai_family, p_mcast_conn->multiAddr_->ai_socktype, p_mcast_conn->multiAddr_->ai_protocol, 0x0001);
 if (((void *)0) == p_mcast_conn->bindAddr_)
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 104, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    dump_addrinfo(p_mcast_conn->bindAddr_, "mcast-setup-linux.c", 107);
 p_mcast_conn->socket_ = socket(p_mcast_conn->multiAddr_->ai_family, p_mcast_conn->multiAddr_->ai_socktype, p_mcast_conn->multiAddr_->ai_protocol);
 if (p_mcast_conn->socket_ == (-1))
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 115, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    if (!set_reuse_addr(p_mcast_conn->socket_))
    {
        debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 120, get_last_socket_error(), get_last_socket_error());
        goto cleanup;
    }
 rc = bind(p_mcast_conn->socket_, p_mcast_conn->bindAddr_->ai_addr, (int) p_mcast_conn->bindAddr_->ai_addrlen);
 if (rc == (-1))
 {
  debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 126, get_last_socket_error(), get_last_socket_error());
  goto cleanup;
 }
    dump_locally_bound_socket(p_mcast_conn->socket_, "mcast-setup-linux.c", 129);
    rc = join_mcast_group_set_ttl(p_mcast_conn->socket_, p_mcast_conn->multiAddr_, p_mcast_conn->bindAddr_, nTTL);
 return 1;
cleanup:
 return 0;
}

variable_types:
bindAddr
char *

variable_types:
nTTL
unsigned int

variable_types: struct mcast_connection { 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; } *bindAddr_; struct addrinfo *multiAddr_; int socket_; } *

user_defined_types: struct mcast_connection { struct addrinfo *bindAddr_; struct addrinfo *multiAddr_; int socket_; }


decompiled_code:
_BOOL8 __fastcall setup_multicast_addr(const char *a1, unsigned __int8 a2, __int64 a3, __int64 a4)
{
char *v6; // r13
unsigned __int16 v7; // ax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v6 = inet_ntoa(*(struct in_addr *)(a3 + 4));
v7 = _bswap_16(*(_WORD *)(a3 + 2));
snprintf(s, 8uLL, "%d", v7);
return setup_multicast_impl(a1, a2, v6, s, a4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(const char *a1, unsigned __int8 a2, __int64 a3, __int64 a4)
{
char *v6; // r13
unsigned __int16 v7; // ax
char s[48]; // [rsp+8h] [rbp-30h] BYREF

v6 = inet_ntoa(*(struct in_addr *)(a3 + 4));
v7 = func0(*(_WORD *)(a3 + 2));
snprintf(s, 8uLL, "%d", v7);
return func4(a1, a2, v6, s, a4);
}

original_code:
static int setup_multicast_addr(char * bindAddr, uint8_t nTTL, struct sockaddr_in const * p_in_addr, struct mcast_connection * p_mcast_conn)
{
    char port[8];
    int result;
    char * inet_addr;
    inet_addr = inet_ntoa(p_in_addr->sin_addr);
    snprintf(port, 8, "%d", ntohs(p_in_addr->sin_port));
    result = setup_multicast_impl(bindAddr, nTTL, inet_addr, port, p_mcast_conn);
    return result;
}

canonical_original_code:
static int setup_multicast_addr(char *bindAddr, unsigned char nTTL, struct sockaddr_in *p_in_addr, struct mcast_connection *p_mcast_conn)
{
    char port[8];
    int result;
    char *inet_addr;
    inet_addr = inet_ntoa(p_in_addr->sin_addr);
    snprintf(port, 8, "%d", ntohs(p_in_addr->sin_port));
    result = setup_multicast_impl(bindAddr, nTTL, inet_addr, port, p_mcast_conn);
    return result;
}

variable_types:
nTTL
unsigned char

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

variable_types:
port
char [8]

variable_types: result int


decompiled_code:
_BOOL8 __fastcall setup_multicast_indirect(__int64 a1, __int64 a2)
{
return setup_multicast_addr(*(const char **)a1, *(_BYTE *)(a1 + 8), a1 + 12, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1, __int64 a2)
{
return func5(*(const char **)a1, *(_BYTE *)(a1 + 8), a1 + 12, a2);
}

original_code:
int setup_multicast_indirect(struct mcast_settings const * p_settings, struct mcast_connection * p_conn)
{
    return setup_multicast_addr(p_settings->bindAddr_, p_settings->nTTL_, &p_settings->mcast_addr_, p_conn);
}

canonical_original_code:
int setup_multicast_indirect(struct mcast_settings *p_settings, struct mcast_connection *p_conn)
{
    return setup_multicast_addr(p_settings->bindAddr_, p_settings->nTTL_, &p_settings->mcast_addr_, p_conn);
}

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

user_defined_types: struct mcast_settings { char *bindAddr_; int nTTL_; struct sockaddr_in mcast_addr_; }


decompiled_code:
ssize_t __fastcall mcast_sendto_flags(__int64 a1, const void *a2, size_t a3, int a4)
{
return sendto(
*(_DWORD *)(a1 + 16),
a2,
a3,
a4,
*(const struct sockaddr **)(*(_QWORD *)(a1 + 8) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 16LL));
}

canonical_decompiled_code:
ssize_t __fastcall func7(__int64 a1, const void *a2, size_t a3, int a4)
{
return sendto(
*(_DWORD *)(a1 + 16),
a2,
a3,
a4,
*(const struct sockaddr **)(*(_QWORD *)(a1 + 8) + 24LL),
*(_DWORD *)(*(_QWORD *)(a1 + 8) + 16LL));
}

original_code:
size_t mcast_sendto_flags(struct mcast_connection * p_conn, void const * p_data, size_t data_size, int flags)
{
    return sendto(p_conn->socket_, (const void *)p_data, data_size, flags, p_conn->multiAddr_->ai_addr, (int) p_conn->multiAddr_->ai_addrlen);
}

canonical_original_code:
unsigned long mcast_sendto_flags(struct mcast_connection *p_conn, void *p_data, unsigned long data_size, int flags)
{
    return sendto(p_conn->socket_, (void *)p_data, data_size, flags, p_conn->multiAddr_->ai_addr, (int) p_conn->multiAddr_->ai_addrlen);
}

variable_types: flags int


decompiled_code:
ssize_t __fastcall mcast_sendto(__int64 a1, const void *a2, size_t a3)
{
return mcast_sendto_flags(a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func8(__int64 a1, const void *a2, size_t a3)
{
return func7(a1, a2, a3, 0);
}

original_code:
size_t mcast_sendto(struct mcast_connection * p_conn, void const * p_data, size_t data_size)
{
    return mcast_sendto_flags(p_conn, p_data, data_size, 0);
}

canonical_original_code:
unsigned long mcast_sendto(struct mcast_connection *p_conn, void *p_data, unsigned long data_size)
{
    return mcast_sendto_flags(p_conn, p_data, data_size, 0);
}


decompiled_code:
ssize_t __fastcall mcast_recvfrom_flags(__int64 a1, void *a2, size_t a3, int a4)
{
return recvfrom(
*(_DWORD *)(a1 + 16),
a2,
a3,
a4,
*(struct sockaddr **)(*(_QWORD *)(a1 + 8) + 24LL),
(socklen_t *)(*(_QWORD *)(a1 + 8) + 16LL));
}

canonical_decompiled_code:
ssize_t __fastcall func9(__int64 a1, void *a2, size_t a3, int a4)
{
return recvfrom(
*(_DWORD *)(a1 + 16),
a2,
a3,
a4,
*(struct sockaddr **)(*(_QWORD *)(a1 + 8) + 24LL),
(socklen_t *)(*(_QWORD *)(a1 + 8) + 16LL));
}

original_code:
size_t mcast_recvfrom_flags(struct mcast_connection * p_conn, void * p_data, size_t data_size, int flags)
{
    return recvfrom(p_conn->socket_, p_data, data_size, flags, p_conn->multiAddr_->ai_addr, &p_conn->multiAddr_->ai_addrlen);
 }

canonical_original_code:
unsigned long mcast_recvfrom_flags(struct mcast_connection *p_conn, void *p_data, unsigned long data_size, int flags)
{
    return recvfrom(p_conn->socket_, p_data, data_size, flags, p_conn->multiAddr_->ai_addr, &p_conn->multiAddr_->ai_addrlen);
 }


decompiled_code:
__int64 __fastcall mcast_is_new_data(__int64 a1, unsigned __int64 a2)
{
struct timeval *v2; // r8
unsigned int v3; // ebx
__int64 v5; // rax
unsigned __int64 v6; // [rsp+0h] [rbp-98h] BYREF
unsigned __int64 v7; // [rsp+8h] [rbp-90h]
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v6 = 0LL;
v7 = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[*(_DWORD *)(a1 + 16) / 64] |= 1LL << (*(_DWORD *)(a1 + 16) % 64);
v2 = 0LL;
if ( a2 != 0xFFFFFFFF )
{
v6 = a2 / 0x3E8;
v7 = 1000 * (a2 % 0x3E8);
v2 = (struct timeval *)&v6;
}
v3 = select(0, &readfds, 0LL, 0LL, v2);
if ( v3 == -1 )
{
v5 = get_last_socket_error(0LL);
debug_outputlnA("%s %u : %u", "mcast-setup-linux.c", 191LL, v5);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int64 a2)
{
struct timeval *v2; // r8
unsigned int v3; // ebx
__int64 v5; // rax
unsigned __int64 v6; // [rsp+0h] [rbp-98h] BYREF
unsigned __int64 v7; // [rsp+8h] [rbp-90h]
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

v6 = 0LL;
v7 = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[*(_DWORD *)(a1 + 16) / 64] |= 1LL << (*(_DWORD *)(a1 + 16) % 64);
v2 = 0LL;
if ( a2 != 0xFFFFFFFF )
{
v6 = a2 / 0x3E8;
v7 = 1000 * (a2 % 0x3E8);
v2 = (struct timeval *)&v6;
}
v3 = select(0, &readfds, 0LL, 0LL, v2);
if ( v3 == -1 )
{
v5 = get_last_socket_error(0LL);
debug_outputlnA("%s %u : %u", "mcast-setup-linux.c", 191LL, v5);
}
return v3;
}

original_code:
int mcast_is_new_data(struct mcast_connection * p_conn, size_t dwTimeoutMs)
{
    fd_set read_sel;
    int result;
    struct timeval timeout, *p_timeout;
    memset(&timeout, 0, sizeof(struct timeval));
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_sel)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_sel)->__fds_bits)[((p_conn->socket_) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((p_conn->socket_) % (8 * (int) sizeof (__fd_mask)))))));
    if (0xffffffff == dwTimeoutMs)
        p_timeout = ((void *)0);
    else
    {
        timeout.tv_sec = dwTimeoutMs / 1000;
        timeout.tv_usec = (dwTimeoutMs - 1000*(dwTimeoutMs/1000))*1000;
        p_timeout = &timeout;
    }
    result = select(0 , &read_sel, ((void *)0), ((void *)0), p_timeout);
    if ((-1) == result)
    {
        debug_outputlnA("%s %u : %u", "mcast-setup-linux.c", 191, get_last_socket_error());
    }
    return result;
}

canonical_original_code:
int mcast_is_new_data(struct mcast_connection *p_conn, unsigned long dwTimeoutMs)
{
    struct fd_set read_sel;
    int result;
    struct timeval timeout; struct timeval *p_timeout;
    memset(&timeout, 0, sizeof(struct timeval));
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_sel)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_sel)->__fds_bits)[((p_conn->socket_) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((p_conn->socket_) % (8 * (int) sizeof (__fd_mask)))))));
    if (0xffffffff == dwTimeoutMs)
        p_timeout = ((void *)0);
    else
    {
        timeout.tv_sec = dwTimeoutMs / 1000;
        timeout.tv_usec = (dwTimeoutMs - 1000*(dwTimeoutMs/1000))*1000;
        p_timeout = &timeout;
    }
    result = select(0 , &read_sel, ((void *)0), ((void *)0), p_timeout);
    if ((-1) == result)
    {
        debug_outputlnA("%s %u : %u", "mcast-setup-linux.c", 191, get_last_socket_error());
    }
    return result;
}

variable_types:
dwTimeoutMs
unsigned long

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


decompiled_code:
ssize_t __fastcall mcast_recvfrom(__int64 a1, void *a2, size_t a3)
{
return mcast_recvfrom_flags(a1, a2, a3, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func11(__int64 a1, void *a2, size_t a3)
{
return func9(a1, a2, a3, 0);
}

original_code:
size_t mcast_recvfrom(struct mcast_connection * p_conn, void * p_data, size_t data_size)
{
    return mcast_recvfrom_flags(p_conn, p_data, data_size, 0);
}

canonical_original_code:
unsigned long mcast_recvfrom(struct mcast_connection *p_conn, void *p_data, unsigned long data_size)
{
    return mcast_recvfrom_flags(p_conn, p_data, data_size, 0);
}


decompiled_code:
__int64 __fastcall close_multicast(__int64 a1)
{
if ( a1 )
{
freeaddrinfo(*(struct addrinfo **)a1);
freeaddrinfo(*(struct addrinfo **)(a1 + 8));
closesocket(*(unsigned int *)(a1 + 16));
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
if ( a1 )
{
freeaddrinfo(*(struct addrinfo **)a1);
freeaddrinfo(*(struct addrinfo **)(a1 + 8));
closesocket(*(unsigned int *)(a1 + 16));
}
return 1LL;
}

original_code:
int close_multicast(struct mcast_connection * p_mcast_conn)
{
    if (((void *)0) != p_mcast_conn)
    {
        freeaddrinfo(p_mcast_conn->bindAddr_);
        freeaddrinfo(p_mcast_conn->multiAddr_);
        closesocket(p_mcast_conn->socket_);
    }
    return 1;
}

canonical_original_code:
int close_multicast(struct mcast_connection *p_mcast_conn)
{
    if (((void *)0) != p_mcast_conn)
    {
        freeaddrinfo(p_mcast_conn->bindAddr_);
        freeaddrinfo(p_mcast_conn->multiAddr_);
        closesocket(p_mcast_conn->socket_);
    }
    return 1;
}


decompiled_code:
_BOOL8 __fastcall set_reuse_addr(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 2, optval, 4u) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = 1;
return setsockopt(a1, 1, 2, optval, 4u) != -1;
}

original_code:
static int set_reuse_addr(SOCKET s)
{
    int optval, rc;
    optval = 1;
    rc = setsockopt(s, 1, 2, (char *)&optval, sizeof(optval));
    if (rc == (-1))
    {
        return 0;
    }
    return 1;
}

canonical_original_code:
static int set_reuse_addr(int s)
{
    int optval; int rc;
    optval = 1;
    rc = setsockopt(s, 1, 2, (char *)&optval, sizeof(optval));
    if (rc == (-1))
    {
        return 0;
    }
    return 1;
}

variable_types: s int

variable_types: optval int


decompiled_code:
__int64 format_string_into_buffer(char *a1, size_t a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
vsnprintf(a1, a2, a3, arg);
return 0LL;
}

canonical_decompiled_code:
__int64 func0(char *a1, size_t a2, const char *a3, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a3);
vsnprintf(a1, a2, a3, arg);
return 0LL;
}

original_code:
static int format_string_into_buffer(char * addrbuf, size_t addrbuflen, const char * format_string, ...)
{
    va_list args;
    __builtin_va_start(args,format_string);
    vsnprintf(addrbuf, addrbuflen, format_string, args);
    __builtin_va_end(args);
    return 0;
}

canonical_original_code:
static int format_string_into_buffer(char *addrbuf, unsigned long addrbuflen, char *format_string, ...)
{
    __builtin_va_list args;
    __builtin_va_start(args,format_string);
    vsnprintf(addrbuf, addrbuflen, format_string, args);
    __builtin_va_end(args);
    return 0;
}

variable_types:
addrbuf
char *

variable_types:
addrbuflen
unsigned long


sResolveAddress

decompiled_code:
struct addrinfo *__fastcall sResolveAddress(const char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
bool v6; // zf
struct addrinfo *result; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

pai = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_flags = a6;
req.ai_family = a3;
req.ai_socktype = a4;
req.ai_protocol = a5;
v6 = getaddrinfo(a1, a2, &req, &pai) == 0;
result = 0LL;
if ( v6 )
result = pai;
return result;
}

canonical_decompiled_code:
struct addrinfo *__fastcall func1(const char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
bool v6; // zf
struct addrinfo *result; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-38h] BYREF

pai = 0LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_flags = a6;
req.ai_family = a3;
req.ai_socktype = a4;
req.ai_protocol = a5;
v6 = getaddrinfo(a1, a2, &req, &pai) == 0;
result = 0LL;
if ( v6 )
result = pai;
return result;
}

original_code:
static struct addrinfo *sResolveAddress(char *addr, char *port, int af, int type, int proto, int flags)
{
    struct addrinfo hints,
                    *res = ((void *)0);
    int rc;
    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = flags;
    hints.ai_family = af;
    hints.ai_socktype = type;
    hints.ai_protocol = proto;
    rc = getaddrinfo(addr, port, &hints, &res);
    if (rc != 0)
    {
        return ((void *)0);
    }
    return res;
}

canonical_original_code:
static struct addrinfo *sResolveAddress(char *addr, char *port, int af, int type, int proto, int flags)
{
    struct addrinfo hints; struct addrinfo *res = ((void *)0);
    int rc;
    memset(&hints, 0, sizeof(hints));
    hints.ai_flags = flags;
    hints.ai_family = af;
    hints.ai_socktype = type;
    hints.ai_protocol = proto;
    rc = getaddrinfo(addr, port, &hints, &res);
    if (rc != 0)
    {
        return ((void *)0);
    }
    return res;
}

variable_types:
addr
char *

variable_types:
port
char *

variable_types: af int

variable_types: type int

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

variable_types: rc int