main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // er15
int v6; // er8
int v7; // edx
int v8; // ebp
unsigned int v9; // er14
void *v10; // rbx
int v11; // ebx
void *v12; // r13
int v13; // ebx
void *v14; // rbp
__int64 v16; // [rsp+0h] [rbp-248h]
_BYTE v17[11]; // [rsp+10h] [rbp-238h] BYREF
unsigned __int8 v18; // [rsp+1Bh] [rbp-22Dh]
unsigned __int8 v19; // [rsp+1Ch] [rbp-22Ch]
unsigned __int8 v20; // [rsp+1Dh] [rbp-22Bh]
unsigned __int8 v21; // [rsp+1Eh] [rbp-22Ah]
unsigned __int8 v22; // [rsp+1Fh] [rbp-229h]
unsigned __int8 v23; // [rsp+20h] [rbp-228h]
unsigned __int8 v24; // [rsp+21h] [rbp-227h]
unsigned __int8 v25; // [rsp+22h] [rbp-226h]
unsigned __int8 v26; // [rsp+23h] [rbp-225h]
unsigned __int8 v27; // [rsp+24h] [rbp-224h]
unsigned __int8 v28; // [rsp+25h] [rbp-223h]
unsigned __int8 v29; // [rsp+26h] [rbp-222h]
unsigned __int8 v30; // [rsp+27h] [rbp-221h]
unsigned __int8 v31; // [rsp+28h] [rbp-220h]
unsigned __int8 v32; // [rsp+29h] [rbp-21Fh]
unsigned __int8 v33; // [rsp+2Ah] [rbp-21Eh]
unsigned __int8 v34; // [rsp+2Bh] [rbp-21Dh]
unsigned __int8 v35; // [rsp+2Ch] [rbp-21Ch]
unsigned __int8 v36; // [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);
if ( chdir("extract") )
perror("Chdir");
if ( mkdir(argv[1], 0x1FFu) )
perror("Mkdir");
if ( chdir(argv[1]) )
perror("Chdir");
v3 = read(fid, v17, 0x200uLL);
if ( v3 != 512 )
{
printf("Read error %d\n", v3);
exit(-2);
}
printf("Serial nr. %u-%u-%u\n", v17[8], v17[9], v17[10]);
v4 = v18 + (v19 << 8);
printf("bps = %hu\n", (unsigned int)v4);
spc = v20;
printf("spc = %hu\n", v20);
printf("res = %hu\n", v21 + (v22 << 8));
printf("NFats = %hu\n", v23);
v5 = v24 + (v25 << 8);
printf("Ndirs = %hu\n", (unsigned int)v5);
printf("Nsects = %hu\n", v26 + (v27 << 8));
printf("Media = %hu\n", v28);
printf("spf = %hu\n", v29 + (v30 << 8));
printf("spt = %hu\n", v31 + (v32 << 8));
printf("Nsides = %hu\n", v33 + (v34 << 8));
printf("Nhid = %hu\n", v35 + (v36 << 8));
if ( !v4 || !v23 || (v6 = v26 + (v27 << 8)) == 0 )
{
puts("This is not a FAT-12-type floppy format");
exit(-2);
}
v7 = (v30 << 8) + v29;
v8 = v7 * (v18 + (v19 << 8));
v9 = 2 * v8 / 3u;
clusterSize = v4 * spc;
printf(
"entries = %u, dataSectors = %u, clusters = %u\n",
v9,
v6 - 1 - v7 * (unsigned int)v23,
(unsigned int)((v6 - 1 - v7 * v23) / v20));
v10 = malloc(v8);
FAT1 = (__int64)v10;
FAT2 = malloc(v8);
if ( v8 != (unsigned int)read(fid, v10, v8) )
puts("Unexpected EOF");
if ( v23 > 1u )
{
v11 = 1;
do
{
if ( v8 != (unsigned int)read(fid, FAT2, v8) )
puts("Unexpected EOF");
++v11;
}
while ( v23 > v11 );
}
v12 = calloc((int)(v9 + 1), 2uLL);
sFAT1 = (__int64)v12;
sFAT2 = (__int64)calloc((int)(v9 + 1), 2uLL);
expandFAT((unsigned __int8 *)FAT1, (__int64)v12, v9);
expandFAT((unsigned __int8 *)FAT2, sFAT2, v9);
printf(
"FAT1: %hu %hu %hu %hu %hu %hu\n",
*(unsigned __int16 *)sFAT1,
*(unsigned __int16 *)(sFAT1 + 2),
*(unsigned __int16 *)(sFAT1 + 4),
*(unsigned __int16 *)(sFAT1 + 6),
*(unsigned __int16 *)(sFAT1 + 8),
*(unsigned __int16 *)(sFAT1 + 10));
LODWORD(v16) = *(unsigned __int16 *)(sFAT2 + 10);
printf(
"FAT2: %hu %hu %hu %hu %hu %hu\n",
*(unsigned __int16 *)sFAT2,
*(unsigned __int16 *)(sFAT2 + 2),
*(unsigned __int16 *)(sFAT2 + 4),
*(unsigned __int16 *)(sFAT2 + 6),
*(unsigned __int16 *)(sFAT2 + 8),
v16);
v13 = (int)(v5 + ((unsigned __int64)v4 >> 5) - 1) / (int)((unsigned __int64)v4 >> 5);
dataStart = v13 + v8 * v23 / v4 - 1;
printf("dataStart = %d\n", (unsigned int)dataStart);
v14 = calloc(v5, 0x20uLL);
if ( v13 * v4 != (unsigned int)read(fid, v14, v13 * v4) )
puts("Unexpected EOF");
readDirectory((__int64)v14, v5, sFAT1);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // er12
int v5; // er15
int v6; // er8
int v7; // edx
int v8; // ebp
unsigned int v9; // er14
void *v10; // rbx
int v11; // ebx
void *v12; // r13
int v13; // ebx
void *v14; // rbp
__int64 v16; // [rsp+0h] [rbp-248h]
_BYTE v17[11]; // [rsp+10h] [rbp-238h] BYREF
unsigned __int8 v18; // [rsp+1Bh] [rbp-22Dh]
unsigned __int8 v19; // [rsp+1Ch] [rbp-22Ch]
unsigned __int8 v20; // [rsp+1Dh] [rbp-22Bh]
unsigned __int8 v21; // [rsp+1Eh] [rbp-22Ah]
unsigned __int8 v22; // [rsp+1Fh] [rbp-229h]
unsigned __int8 v23; // [rsp+20h] [rbp-228h]
unsigned __int8 v24; // [rsp+21h] [rbp-227h]
unsigned __int8 v25; // [rsp+22h] [rbp-226h]
unsigned __int8 v26; // [rsp+23h] [rbp-225h]
unsigned __int8 v27; // [rsp+24h] [rbp-224h]
unsigned __int8 v28; // [rsp+25h] [rbp-223h]
unsigned __int8 v29; // [rsp+26h] [rbp-222h]
unsigned __int8 v30; // [rsp+27h] [rbp-221h]
unsigned __int8 v31; // [rsp+28h] [rbp-220h]
unsigned __int8 v32; // [rsp+29h] [rbp-21Fh]
unsigned __int8 v33; // [rsp+2Ah] [rbp-21Eh]
unsigned __int8 v34; // [rsp+2Bh] [rbp-21Dh]
unsigned __int8 v35; // [rsp+2Ch] [rbp-21Ch]
unsigned __int8 v36; // [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);
if ( chdir("extract") )
perror("Chdir");
if ( mkdir(argv[1], 0x1FFu) )
perror("Mkdir");
if ( chdir(argv[1]) )
perror("Chdir");
v3 = read(fid, v17, 0x200uLL);
if ( v3 != 512 )
{
printf("Read error %d\n", v3);
exit(-2);
}
printf("Serial nr. %u-%u-%u\n", v17[8], v17[9], v17[10]);
v4 = v18 + (v19 << 8);
printf("bps = %hu\n", (unsigned int)v4);
spc = v20;
printf("spc = %hu\n", v20);
printf("res = %hu\n", v21 + (v22 << 8));
printf("NFats = %hu\n", v23);
v5 = v24 + (v25 << 8);
printf("Ndirs = %hu\n", (unsigned int)v5);
printf("Nsects = %hu\n", v26 + (v27 << 8));
printf("Media = %hu\n", v28);
printf("spf = %hu\n", v29 + (v30 << 8));
printf("spt = %hu\n", v31 + (v32 << 8));
printf("Nsides = %hu\n", v33 + (v34 << 8));
printf("Nhid = %hu\n", v35 + (v36 << 8));
if ( !v4 || !v23 || (v6 = v26 + (v27 << 8)) == 0 )
{
puts("This is not a FAT-12-type floppy format");
exit(-2);
}
v7 = (v30 << 8) + v29;
v8 = v7 * (v18 + (v19 << 8));
v9 = 2 * v8 / 3u;
clusterSize = v4 * spc;
printf(
"entries = %u, dataSectors = %u, clusters = %u\n",
v9,
v6 - 1 - v7 * (unsigned int)v23,
(unsigned int)((v6 - 1 - v7 * v23) / v20));
v10 = malloc(v8);
FAT1 = (__int64)v10;
FAT2 = malloc(v8);
if ( v8 != (unsigned int)read(fid, v10, v8) )
puts("Unexpected EOF");
if ( v23 > 1u )
{
v11 = 1;
do
{
if ( v8 != (unsigned int)read(fid, FAT2, v8) )
puts("Unexpected EOF");
++v11;
}
while ( v23 > v11 );
}
v12 = calloc((int)(v9 + 1), 2uLL);
sFAT1 = (__int64)v12;
sFAT2 = (__int64)calloc((int)(v9 + 1), 2uLL);
func4((unsigned __int8 *)FAT1, (__int64)v12, v9);
func4((unsigned __int8 *)FAT2, sFAT2, v9);
printf(
"FAT1: %hu %hu %hu %hu %hu %hu\n",
*(unsigned __int16 *)sFAT1,
*(unsigned __int16 *)(sFAT1 + 2),
*(unsigned __int16 *)(sFAT1 + 4),
*(unsigned __int16 *)(sFAT1 + 6),
*(unsigned __int16 *)(sFAT1 + 8),
*(unsigned __int16 *)(sFAT1 + 10));
LODWORD(v16) = *(unsigned __int16 *)(sFAT2 + 10);
printf(
"FAT2: %hu %hu %hu %hu %hu %hu\n",
*(unsigned __int16 *)sFAT2,
*(unsigned __int16 *)(sFAT2 + 2),
*(unsigned __int16 *)(sFAT2 + 4),
*(unsigned __int16 *)(sFAT2 + 6),
*(unsigned __int16 *)(sFAT2 + 8),
v16);
v13 = (int)(v5 + ((unsigned __int64)v4 >> 5) - 1) / (int)((unsigned __int64)v4 >> 5);
dataStart = v13 + v8 * v23 / v4 - 1;
printf("dataStart = %d\n", (unsigned int)dataStart);
v14 = calloc(v5, 0x20uLL);
if ( v13 * v4 != (unsigned int)read(fid, v14, v13 * v4) )
puts("Unexpected EOF");
func3((__int64)v14, v5, sFAT1);
return 0;
}

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: j int

variable_types: bps int

variable_types: Ndirs int

variable_types: NdirSectors int

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


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

return_type: void


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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
const char **v4; // rbx
const char **v5; // rbp
__int64 v6; // rdi
const char **v8; // rbx
const char **v9; // rbp
__int64 v10; // rdi

v3 = argv[1];
if ( *(_WORD *)v3 != 25389 || v3[2] )
{
if ( !strcmp(v3, "-a") )
{
if ( argc > 2 )
{
v8 = argv + 2;
v9 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v10 = (__int64)*v8++;
VerifySimulations(v10);
}
while ( v8 != v9 );
}
}
else if ( !strcmp(v3, "-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");
}
}
else if ( argc > 2 )
{
v4 = argv + 2;
v5 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v6 = (__int64)*v4++;
TreatVariations(v6, argv, envp);
}
while ( v4 != v5 );
}
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: argc int

variable_types:
argv
char *[]

variable_types: argvIndex int

return_type: int


repo: TomaszOstaszewski/Mcast

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

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

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

v2 = (char *)&g_outputBuffer + __readfsqword(0);
v3 = vsnprintf(v2, 0x100uLL, format, arg);
result = 0LL;
if ( v3 > 0 )
{
fputs(v2, 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 __int64 v1; // rbp
char *v2; // rbx
unsigned int v3; // eax
__int64 v4; // r8
char *v5; // rcx
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

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

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

va_start(arg, format);
v1 = __readfsqword(0);
v2 = (char *)&g_outputBuffer + v1;
v3 = vsnprintf((char *)&g_outputBuffer + v1, 0x100uLL, format, arg);
if ( (int)v3 <= 0 )
return 0LL;
if ( (int)v3 <= 255 )
{
v4 = g_write_offset;
v5 = &g_lines[g_write_offset + v1];
if ( v3 < 8 )
{
if ( (v3 & 4) != 0 )
{
*(_DWORD *)v5 = g_outputBuffer;
*(_DWORD *)&v5[v3 - 4] = *(_DWORD *)&v2[v3 - 4];
}
else
{
*v5 = g_outputBuffer;
if ( (v3 & 2) != 0 )
*(_WORD *)&v5[v3 - 2] = *(_WORD *)&v2[v3 - 2];
}
}
else
{
*(_QWORD *)v5 = g_outputBuffer;
*(_QWORD *)&v5[v3 - 8] = *(_QWORD *)&v2[v3 - 8];
qmemcpy(
(void *)((unsigned __int64)(v5 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v2 - &v5[-((unsigned __int64)(v5 + 8) & 0xFFFFFFFFFFFFFFF8LL)]),
8LL * ((v3 + (_DWORD)v5 - (((_DWORD)v5 + 8) & 0xFFFFFFF8)) >> 3));
}
g_write_offset = (int)v3 + v4;
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, ...)
{
char *v1; // rbp
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

v1 = (char *)&g_tmp_buffer + __readfsqword(0);
if ( wcstombs(v1, pwcs, 0x100uLL) == -1LL )
return 0xFFFFFFFFLL;
va_start(arg, pwcs);
return debug_outputlnA_impl(v1, arg);
}

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

v1 = (char *)&g_tmp_buffer + __readfsqword(0);
if ( wcstombs(v1, pwcs, 0x100uLL) == -1LL )
return 0xFFFFFFFFLL;
va_start(arg, pwcs);
return func0(v1, 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)
{
socklen_t v6; // edx
const struct sockaddr *v7; // rsi
int v8; // eax
int v9; // eax
unsigned int v10; // er12
int v11; // eax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
int v20[3]; // [rsp+Ch] [rbp-5Ch] BYREF
int v21[2]; // [rsp+18h] [rbp-50h] BYREF
__m128i optval; // [rsp+20h] [rbp-48h] BYREF
int v23; // [rsp+30h] [rbp-38h]

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

canonical_decompiled_code:
__int64 __fastcall func0(int fd, __int64 a2, __int64 a3, int a4)
{
socklen_t v6; // edx
const struct sockaddr *v7; // rsi
int v8; // eax
int v9; // eax
unsigned int v10; // er12
int v11; // eax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax
int v20[3]; // [rsp+Ch] [rbp-5Ch] BYREF
int v21[2]; // [rsp+18h] [rbp-50h] BYREF
__m128i optval; // [rsp+20h] [rbp-48h] BYREF
int v23; // [rsp+30h] [rbp-38h]

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

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(int a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v4; // er8
__int64 v5; // rcx
int v6; // edx
int v7; // esi
const void *v8; // rcx
unsigned int v9; // er12
__int64 v11; // rcx
const char *v12; // rax
__int64 v13; // rdx
__int64 v14; // rcx

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

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

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

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(int a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
int v5; // esi
unsigned int v6; // er12
const char *v8; // rax
__int64 v9; // rdx
__int64 v10; // 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 = 0;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return 0xFFFFFFFFLL;
}
v4 = 18;
v5 = 41;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v8 = (const char *)get_last_socket_error();
debug_outputlnA("%s %4.4u : %d\n", v8, v9, v10);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
int v5; // esi
unsigned int v6; // er12
const char *v8; // rax
__int64 v9; // rdx
__int64 v10; // 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 = 0;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return 0xFFFFFFFFLL;
}
v4 = 18;
v5 = 41;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v8 = (const char *)get_last_socket_error();
debug_outputlnA("%s %4.4u : %d\n", v8, v9, v10);
}
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(int a1, const char *a2, __int64 a3, __int64 a4)
{
int v4; // edx
int v5; // esi
unsigned int v6; // er12
const char *v8; // rax
__int64 v9; // rdx
__int64 v10; // rcx
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

optval[0] = a3;
if ( (_DWORD)a2 == 2 )
{
v4 = 34;
v5 = 0;
}
else
{
if ( (_DWORD)a2 != 10 )
{
debug_outputlnA("%s %4.4u : %d\n", a2, a3, a4);
return 0xFFFFFFFFLL;
}
v4 = 19;
v5 = 41;
}
v6 = setsockopt(a1, v5, v4, optval, 4u);
if ( v6 == -1 )
{
v8 = (const char *)get_last_socket_error();
debug_outputlnA("%s %4.4u : %d\n", v8, v9, v10);
}
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:
// attributes: thunk
int closesocket(int fd)
{
return close(fd);
}

canonical_decompiled_code:
int func1(int fd)
{
return close(fd);
}

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

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


decompiled_code:
__int64 __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; // rax
unsigned int v10; // eax
__int64 v11; // rdi
__int64 v12; // rdi
__int64 v14; // rbx
__int64 v15; // rax
__int64 v16; // rbx
__int64 v17; // rax
__int64 v18; // r8
__int64 v19; // rdx
__int64 v20; // rcx
__int64 v21; // rbx
__int64 v22; // rax
__int64 v23; // rbx
__int64 v24; // rax
__int64 v25; // rbx
__int64 v26; // 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_constprop_0(v8, 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_constprop_0(v9, 0x6Bu);
v10 = socket(
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 4LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 8LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 12LL));
*(_DWORD *)(a5 + 16) = v10;
v11 = v10;
if ( v10 == -1 )
{
v23 = get_last_socket_error(0xFFFFFFFFLL);
v24 = get_last_socket_error(v11);
v18 = v23;
v19 = 115LL;
v20 = v24;
}
else
{
if ( !set_reuse_addr(v10) )
{
v14 = get_last_socket_error(v11);
v15 = get_last_socket_error(v11);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 120LL, v15, v14);
return 0LL;
}
v12 = *(unsigned int *)(a5 + 16);
if ( bind(v12, *(const struct sockaddr **)(*(_QWORD *)a5 + 24LL), *(_DWORD *)(*(_QWORD *)a5 + 16LL)) != -1 )
{
dump_locally_bound_socket_constprop_0(*(_DWORD *)(a5 + 16));
join_mcast_group_set_ttl(*(unsigned int *)(a5 + 16), *(_QWORD *)(a5 + 8), *(_QWORD *)a5, a2);
return 1LL;
}
v25 = get_last_socket_error(v12);
v26 = get_last_socket_error(v12);
v18 = v25;
v19 = 126LL;
v20 = v26;
}
}
else
{
v21 = ((__int64 (*)(void))get_last_socket_error)();
v22 = get_last_socket_error(0LL);
v18 = v21;
v19 = 104LL;
v20 = v22;
}
}
else
{
v16 = ((__int64 (*)(void))get_last_socket_error)();
v17 = ((__int64 (*)(void))get_last_socket_error)();
v18 = v16;
v19 = 96LL;
v20 = v17;
}
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", v19, v20, v18);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, unsigned int a2, const char *a3, const char *a4, __int64 a5)
{
unsigned int *v8; // rax
unsigned int *v9; // rax
unsigned int v10; // eax
__int64 v11; // rdi
__int64 v12; // rdi
__int64 v14; // rbx
__int64 v15; // rax
__int64 v16; // rbx
__int64 v17; // rax
__int64 v18; // r8
__int64 v19; // rdx
__int64 v20; // rcx
__int64 v21; // rbx
__int64 v22; // rax
__int64 v23; // rbx
__int64 v24; // rax
__int64 v25; // rbx
__int64 v26; // 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 )
{
func3(v8, 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 )
{
func3(v9, 0x6Bu);
v10 = socket(
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 4LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 8LL),
*(_DWORD *)(*(_QWORD *)(a5 + 8) + 12LL));
*(_DWORD *)(a5 + 16) = v10;
v11 = v10;
if ( v10 == -1 )
{
v23 = get_last_socket_error(0xFFFFFFFFLL);
v24 = get_last_socket_error(v11);
v18 = v23;
v19 = 115LL;
v20 = v24;
}
else
{
if ( !func1(v10) )
{
v14 = get_last_socket_error(v11);
v15 = get_last_socket_error(v11);
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", 120LL, v15, v14);
return 0LL;
}
v12 = *(unsigned int *)(a5 + 16);
if ( bind(v12, *(const struct sockaddr **)(*(_QWORD *)a5 + 24LL), *(_DWORD *)(*(_QWORD *)a5 + 16LL)) != -1 )
{
func2(*(_DWORD *)(a5 + 16));
join_mcast_group_set_ttl(*(unsigned int *)(a5 + 16), *(_QWORD *)(a5 + 8), *(_QWORD *)a5, a2);
return 1LL;
}
v25 = get_last_socket_error(v12);
v26 = get_last_socket_error(v12);
v18 = v25;
v19 = 126LL;
v20 = v26;
}
}
else
{
v21 = ((__int64 (*)(void))get_last_socket_error)();
v22 = get_last_socket_error(0LL);
v18 = v21;
v19 = 104LL;
v20 = v22;
}
}
else
{
v16 = ((__int64 (*)(void))get_last_socket_error)();
v17 = ((__int64 (*)(void))get_last_socket_error)();
v18 = v16;
v19 = 96LL;
v20 = v17;
}
debug_outputlnA("%s %5.5d : %10.10d %8.8x", "mcast-setup-linux.c", v19, v20, v18);
return 0LL;
}

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:
__int64 __fastcall setup_multicast_addr(const char *a1, unsigned __int8 a2, __int64 a3, __int64 a4)
{
char *v6; // r13
unsigned __int16 v7; // ax
const char *v8; // rdx
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, v8, v7);
return setup_multicast_impl(a1, a2, v6, s, a4);
}

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

v6 = inet_ntoa(*(struct in_addr *)(a3 + 4));
v7 = func0(*(_WORD *)(a3 + 2));
snprintf(s, 8uLL, v8, 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:
__int64 __fastcall setup_multicast_indirect(__int64 a1, __int64 a2)
{
return setup_multicast_addr(*(const char **)a1, *(_BYTE *)(a1 + 8), a1 + 12, a2);
}

canonical_decompiled_code:
__int64 __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)
{
int v2; // ecx
int v3; // eax
struct timeval *v4; // r8
unsigned int v5; // er12
__int64 v7; // rax
__int128 v8; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int64 a2)
{
int v2; // ecx
int v3; // eax
struct timeval *v4; // r8
unsigned int v5; // er12
__int64 v7; // rax
__int128 v8; // [rsp+0h] [rbp-98h] BYREF
fd_set readfds; // [rsp+10h] [rbp-88h] BYREF

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

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 func1(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

req.ai_family = a3;
req.ai_socktype = a4;
pai = 0LL;
req.ai_flags = a6;
req.ai_protocol = a5;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
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

req.ai_family = a3;
req.ai_socktype = a4;
pai = 0LL;
req.ai_flags = a6;
req.ai_protocol = a5;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
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


FormatAddress

decompiled_code:
__int64 __fastcall FormatAddress(const struct sockaddr *a1, socklen_t a2, char *a3, unsigned int a4)
{
unsigned int v6; // er12
size_t v7; // r14
char serv[32]; // [rsp+0h] [rbp-458h] BYREF
char host[1080]; // [rsp+20h] [rbp-438h] BYREF

if ( !a1 || !a3 )
return (unsigned int)-1;
v6 = getnameinfo(a1, a2, host, 0x401u, serv, 0x20u, 3);
if ( v6 )
{
debug_outputlnA("%s %u : %d", "resolve.c", 66LL, v6);
return v6;
}
v7 = strlen(host);
if ( v7 + strlen(serv) + 1 > a4 )
return (unsigned int)-1;
if ( serv[0] == 48 )
return (unsigned int)format_string_into_buffer(a3, (int)a4, "%s", host);
if ( (a1->sa_family & 0xFFF7) == 2 )
return (unsigned int)format_string_into_buffer(a3, (int)a4, "%s:%s", host, serv);
*a3 = 0;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(const struct sockaddr *a1, socklen_t a2, char *a3, unsigned int a4)
{
unsigned int v6; // er12
size_t v7; // r14
char serv[32]; // [rsp+0h] [rbp-458h] BYREF
char host[1080]; // [rsp+20h] [rbp-438h] BYREF

if ( !a1 || !a3 )
return (unsigned int)-1;
v6 = getnameinfo(a1, a2, host, 0x401u, serv, 0x20u, 3);
if ( v6 )
{
debug_outputlnA("%s %u : %d", "resolve.c", 66LL, v6);
return v6;
}
v7 = strlen(host);
if ( v7 + strlen(serv) + 1 > a4 )
return (unsigned int)-1;
if ( serv[0] == 48 )
return (unsigned int)func0(a3, (int)a4, "%s", host);
if ( (a1->sa_family & 0xFFF7) == 2 )
return (unsigned int)func0(a3, (int)a4, "%s:%s", host, serv);
*a3 = 0;
return v6;
}

original_code:
int FormatAddress(struct sockaddr *sa, int salen, char *addrbuf, int addrbuflen)
{
    char host[1025],
            service[32];
    int hostlen = 1025,
            servlen = 32,
            rc;
    if ((sa == ((void *)0)) || (addrbuf == ((void *)0)))
        return (-1);
    rc = getnameinfo(sa, salen, host, hostlen, service, servlen, 1 | 2 );
    if (rc != 0)
    {
        debug_outputlnA("%s %u : %d", "resolve.c", 66, rc);
        return rc;
    }
    if ( (strlen(host) + strlen(service) + 1) > (unsigned)addrbuflen)
        return (-1);
    if (strncmp(service, "0", 1) != 0)
    {
        if (sa->sa_family == 2)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else if (sa->sa_family == 10)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else
            addrbuf[0] = '\0';
    }
    else
    {
        rc = format_string_into_buffer(addrbuf, addrbuflen, "%s", host);
    }
    return rc;
}

canonical_original_code:
int FormatAddress(struct sockaddr *sa, int salen, char *addrbuf, int addrbuflen)
{
    char host[1025]; char service[32];
    int hostlen = 1025; int servlen = 32; int rc;
    if ((sa == ((void *)0)) || (addrbuf == ((void *)0)))
        return (-1);
    rc = getnameinfo(sa, salen, host, hostlen, service, servlen, 1 | 2 );
    if (rc != 0)
    {
        debug_outputlnA("%s %u : %d", "resolve.c", 66, rc);
        return rc;
    }
    if ( (strlen(host) + strlen(service) + 1) > (unsigned int)addrbuflen)
        return (-1);
    if (strncmp(service, "0", 1) != 0)
    {
        if (sa->sa_family == 2)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else if (sa->sa_family == 10)
        {
            rc = format_string_into_buffer(addrbuf, addrbuflen, "%s:%s", host, service);
        }
        else
            addrbuf[0] = '\0';
    }
    else
    {
        rc = format_string_into_buffer(addrbuf, addrbuflen, "%s", host);
    }
    return rc;
}

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

variable_types: salen int

variable_types: addrbuflen int

variable_types:
host
char [1025]

variable_types:
service
char [32]

variable_types: hostlen int

variable_types: servlen int


ResolveAddress

decompiled_code:
struct addrinfo *__fastcall ResolveAddress(const char *a1, const char *a2, int a3, int a4, int a5)
{
return sResolveAddress(a1, a2, a3, a4, a5, a1 != 0LL);
}

canonical_decompiled_code:
struct addrinfo *__fastcall func3(const char *a1, const char *a2, int a3, int a4, int a5)
{
return func1(a1, a2, a3, a4, a5, a1 != 0LL);
}

original_code:
struct addrinfo *ResolveAddress(char *addr, char *port, int af, int type, int proto)
{
    int flags = 0;
    if (((void *)0) != addr)
        flags = 0x0001;
    return sResolveAddress(addr, port, af, type, proto, flags);
}

variable_types: flags int

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


ResolveAddressWithFlags

decompiled_code:
// attributes: thunk
struct addrinfo *__fastcall ResolveAddressWithFlags(const char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
return sResolveAddress(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
struct addrinfo *__fastcall func4(const char *a1, const char *a2, int a3, int a4, int a5, int a6)
{
return func1(a1, a2, a3, a4, a5, a6);
}

original_code:
struct addrinfo *ResolveAddressWithFlags(char *addr, char *port, int af, int type, int proto, int flags)
{
    return sResolveAddress(addr, port, af, type, proto, flags);
}


decompiled_code:
void sigint_handle()
{
g_stop_processing = 1;
}

canonical_decompiled_code:
void func0()
{
g_stop_processing = 1;
}

original_code:
static void sigint_handle(int signal)
{
    g_stop_processing = 1;
}

variable_types: signal int


decompiled_code:
__int64 __fastcall get_samples_buffer(__int64 a1)
{
return a1 + 44;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1 + 44;
}

original_code:
const int8_t * get_samples_buffer(struct master_riff_chunk const * p_header)
{
    wav_format_chunk_2_t const * p_wave_format_chunk;
    plainwaveformat_t const * p_plainwave;
    wav_subchunk_t const * p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return &p_subchunk->samples8_[0];
}

canonical_original_code:
char *get_samples_buffer(struct master_riff_chunk *p_header)
{
    struct wav_format_chunk_2 *p_wave_format_chunk;
    struct plainwaveformat *p_plainwave;
    struct wav_subchunk *p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return &p_subchunk->samples8_[0];
}

variable_types: struct master_riff_chunk { unsigned char ckid_[4]; unsigned int cksize_; union { struct wav_format_chunk_2 { unsigned char waveid_[4]; unsigned char ckid_[4]; unsigned int cksize_; union { unsigned short wFormatTag_; struct plainwaveformat { struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; } wavFormat_; struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } subchunk_; } plain_wav_; struct pcm_waveformat { struct waveformat_tag wf; unsigned short wBitsPerSample; struct wav_subchunk subchunk_; } pcm_wav_; struct extensiblewav { struct waveformat_tag wavFormat_; unsigned short cbSize_; unsigned short wValidBitsPerSample_; } ext_wav_; }; } format_chunk_2_; unsigned char data_u8_[1]; unsigned short data_u16_[1]; unsigned int data_u32_[1]; }; } *

variable_types: struct wav_format_chunk_2 { unsigned char waveid_[4]; unsigned char ckid_[4]; unsigned int cksize_; union { unsigned short wFormatTag_; struct plainwaveformat { struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; } wavFormat_; struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } subchunk_; } plain_wav_; struct pcm_waveformat { struct waveformat_tag wf; unsigned short wBitsPerSample; struct wav_subchunk subchunk_; } pcm_wav_; struct extensiblewav { struct waveformat_tag wavFormat_; unsigned short cbSize_; unsigned short wValidBitsPerSample_; } ext_wav_; }; } *

variable_types: struct plainwaveformat { struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; } wavFormat_; struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } subchunk_; } *

variable_types: struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; } *

return_type: char *

user_defined_types: struct master_riff_chunk { unsigned char ckid_[4]; unsigned int cksize_; union { struct wav_format_chunk_2 format_chunk_2_; unsigned char data_u8_[1]; unsigned short data_u16_[1]; unsigned int data_u32_[1]; }; }

user_defined_types: struct wav_format_chunk_2 { unsigned char waveid_[4]; unsigned char ckid_[4]; unsigned int cksize_; union { unsigned short wFormatTag_; struct plainwaveformat plain_wav_; struct pcm_waveformat pcm_wav_; struct extensiblewav ext_wav_; }; }

user_defined_types: struct plainwaveformat { struct waveformat_tag wavFormat_; struct wav_subchunk subchunk_; }


decompiled_code:
__int64 __fastcall get_samples_buffer_size(__int64 a1)
{
return *(unsigned int *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 40);
}

original_code:
size_t get_samples_buffer_size(struct master_riff_chunk const * p_header)
{
    wav_format_chunk_2_t const * p_wave_format_chunk;
    plainwaveformat_t const * p_plainwave;
    wav_subchunk_t const * p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return p_subchunk->subchunk_size_;
}

canonical_original_code:
unsigned long get_samples_buffer_size(struct master_riff_chunk *p_header)
{
    struct wav_format_chunk_2 *p_wave_format_chunk;
    struct plainwaveformat *p_plainwave;
    struct wav_subchunk *p_subchunk;
    p_wave_format_chunk = &p_header->format_chunk_2_;
    p_plainwave = &p_wave_format_chunk->plain_wav_;
    p_subchunk = &p_plainwave->subchunk_;
    return p_subchunk->subchunk_size_;
}

user_defined_types: struct wav_subchunk { unsigned char subchunkId_[4]; unsigned int subchunk_size_; union { char samples8_[1]; short samples16_[1]; int samples32_[1]; }; }

user_defined_types: struct waveformat_tag { unsigned short wFormatTag; unsigned short nChannels; unsigned int nSamplesPerSec; unsigned int nAvgBytesPerSec; unsigned short nBlockAlign; }

user_defined_types: struct pcm_waveformat { struct waveformat_tag wf; unsigned short wBitsPerSample; struct wav_subchunk subchunk_; }

user_defined_types: struct extensiblewav { struct waveformat_tag wavFormat_; unsigned short cbSize_; unsigned short wValidBitsPerSample_; }


canonical_original_code:
static void sigint_handle(int signal)
{
    g_stop_processing = 1;
}


decompiled_code:
int __fastcall dump_buffer(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
return fprintf(stderr, "%4.4u %s : %u \n", 31LL, "dump_buffer", a4);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
return fprintf(stderr, "%4.4u %s : %u \n", 31LL, "dump_buffer", a4);
}

original_code:
void dump_buffer(const uint8_t * p_buffer, size_t length, struct sockaddr * p_from, socklen_t from_length)
{
    fprintf(stderr, "%4.4u %s : %u \n", 31, __func__, from_length);
}

canonical_original_code:
void dump_buffer(unsigned char *p_buffer, unsigned long length, struct sockaddr *p_from, unsigned int from_length)
{
    fprintf(stderr, "%4.4u %s : %u \n", 31, __func__, from_length);
}

variable_types:
length
unsigned long


cut

repo: Tombapic/YoRo

decompiled_code:
__int64 __fastcall cut(__int64 a1, char *a2)
{
char *v2; // rax
char *v3; // rsi
__int64 v4; // rbx
__int64 result; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(a2, delim);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = 1LL;
do
{
strcpy(*(char **)(a1 + 8 * v4 - 8), v3);
v3 = strtok(0LL, delim);
result = (unsigned int)v4++;
}
while ( v3 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
char *v2; // rax
char *v3; // rsi
__int64 v4; // rbx
__int64 result; // rax
char delim[2]; // [rsp+Eh] [rbp-1Ah] BYREF

strcpy(delim, " ");
v2 = strtok(a2, delim);
if ( !v2 )
return 0LL;
v3 = v2;
v4 = 1LL;
do
{
strcpy(*(char **)(a1 + 8 * v4 - 8), v3);
v3 = strtok(0LL, delim);
result = (unsigned int)v4++;
}
while ( v3 );
return result;
}

original_code:
int cut(char** tableau,char* source)
{
 char delims[] = " ";
 char *result = ((void *)0);
 int i=0;
 int nombre_mots=0;
 result = strtok( source, delims );
 while( result != ((void *)0) )
 {
  strcpy(tableau[i],result);
  result = strtok( ((void *)0), delims );
  i++;
  nombre_mots= nombre_mots+1;
 }
 return nombre_mots;
}

canonical_original_code:
int cut(char **tableau, char *source)
{
 char delims[] = " ";
 char *result = ((void *)0);
 int i = 0;
 int nombre_mots = 0;
 result = strtok( source, delims );
 while( result != ((void *)0) )
 {
  strcpy(tableau[i],result);
  result = strtok( ((void *)0), delims );
  i++;
  nombre_mots= nombre_mots+1;
 }
 return nombre_mots;
}

variable_types:
tableau
char **

variable_types:
source
char *

variable_types:
delims
char []

variable_types:
result
char *

variable_types: i int


decompiled_code:
__int64 __fastcall search_request(int fd)
{
const void **v1; // r12
const void **v2; // rbx
unsigned int v3; // er14
char *v4; // rax
__int64 v5; // rbx
int v7; // [rsp+8h] [rbp-430h] BYREF
unsigned int v8; // [rsp+Ch] [rbp-42Ch] BYREF
int buf[128]; // [rsp+10h] [rbp-428h] BYREF
char s[552]; // [rsp+210h] [rbp-228h] BYREF

v8 = 0;
v1 = (const void **)malloc(0xF0uLL);
v2 = v1;
do
*v2++ = malloc(0x32uLL);
while ( v1 + 30 != v2 );
strcpy((char *)buf, "search");
v3 = send(fd, buf, 0x200uLL, 0);
if ( v3 == -1 )
{
printf("sock_err (send search)= %d\n", 0xFFFFFFFFLL);
return v3;
}
print_header();
puts(aAppuyezSurUneT_1);
getchar();
getchar();
fgets(s, 512, stdin);
v4 = strchr(s, 10);
if ( v4 )
*v4 = 0;
v7 = cut((__int64)v1, s);
if ( (unsigned int)send(fd, &v7, 0x200uLL, 0) != -1 )
{
if ( v7 <= 0 )
{
LABEL_12:
if ( (unsigned int)recv(fd, &v8, 0x200uLL, 0) != -1 )
{
print_header();
printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n", v8);
getchar();
return v8;
}
}
else
{
v5 = 0LL;
while ( (unsigned int)send(fd, v1[v5], 0x200uLL, 0) != -1 )
{
if ( v7 <= (int)++v5 )
goto LABEL_12;
}
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
const void **v1; // r12
const void **v2; // rbx
unsigned int v3; // er14
char *v4; // rax
__int64 v5; // rbx
int v7; // [rsp+8h] [rbp-430h] BYREF
unsigned int v8; // [rsp+Ch] [rbp-42Ch] BYREF
int buf[128]; // [rsp+10h] [rbp-428h] BYREF
char s[552]; // [rsp+210h] [rbp-228h] BYREF

v8 = 0;
v1 = (const void **)malloc(0xF0uLL);
v2 = v1;
do
*v2++ = malloc(0x32uLL);
while ( v1 + 30 != v2 );
strcpy((char *)buf, "search");
v3 = send(fd, buf, 0x200uLL, 0);
if ( v3 == -1 )
{
printf("sock_err (send search)= %d\n", 0xFFFFFFFFLL);
return v3;
}
func2();
puts(aAppuyezSurUneT_1);
getchar();
getchar();
fgets(s, 512, stdin);
v4 = strchr(s, 10);
if ( v4 )
*v4 = 0;
v7 = func4((__int64)v1, s);
if ( (unsigned int)send(fd, &v7, 0x200uLL, 0) != -1 )
{
if ( v7 <= 0 )
{
LABEL_12:
if ( (unsigned int)recv(fd, &v8, 0x200uLL, 0) != -1 )
{
func2();
printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n", v8);
getchar();
return v8;
}
}
else
{
v5 = 0LL;
while ( (unsigned int)send(fd, v1[v5], 0x200uLL, 0) != -1 )
{
if ( v7 <= (int)++v5 )
goto LABEL_12;
}
}
}
return (unsigned int)-1;
}

original_code:
int search_request(SOCKET sock)
{
 int sock_err=0;
 char buf[512];
 int i;
 int nbr_mots;
 int nbr_files=0;
 char text[512];
 char **tableau= (char**)malloc(30*sizeof(char*));
 for(i=0;i<30;i++){
  tableau[i] = (char*) malloc (50*sizeof(char));
 }
 strcpy(buf, "search");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) {
  printf("sock_err (send search)= %d\n",sock_err);
  return -1;
 }
 print_header();
 printf("Appuyez sur une touche, donnez la liste de vos mots clés, puis appuyez sur une touche.\n\n");
 getchar();
 getchar();
 fgets(text,sizeof text,stdin);
 char *p = strchr(text, '\n');
 if (p)
 {
  *p = 0;
 }
 nbr_mots = cut(tableau,text);
 sock_err = send(sock,&nbr_mots, 512, 0);
 if(sock_err == -1) return -1;
 for(i=0; i<nbr_mots;i++){
  sock_err = send(sock, tableau[i], 512, 0);
  if(sock_err == -1) return -1;
 }
 sock_err = recv(sock,&nbr_files, 512, 0);
 if(sock_err == -1) return -1;
 else
 {
  print_header();
  printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n" , nbr_files);
  getchar();
 }
 return nbr_files;
}

canonical_original_code:
int search_request(int sock)
{
 int sock_err = 0;
 char buf[512];
 int i;
 int nbr_mots;
 int nbr_files = 0;
 char text[512];
 char **tableau = (char**)malloc(30*sizeof(char*));
 for(i=0;i<30;i++){
  tableau[i] = (char *) malloc (50*sizeof(char));
 }
 strcpy(buf, "search");
 sock_err = send(sock, buf, 512, 0);
 if(sock_err == -1) {
  printf("sock_err (send search)= %d\n",sock_err);
  return -1;
 }
 print_header();
 printf("Appuyez sur une touche, donnez la liste de vos mots clés, puis appuyez sur une touche.\n\n");
 getchar();
 getchar();
 fgets(text,sizeof text,stdin);
 char *p = strchr(text, '\n');
 if (p)
 {
  *p = 0;
 }
 nbr_mots = cut(tableau,text);
 sock_err = send(sock,&nbr_mots, 512, 0);
 if(sock_err == -1) return -1;
 for(i=0; i<nbr_mots;i++){
  sock_err = send(sock, tableau[i], 512, 0);
  if(sock_err == -1) return -1;
 }
 sock_err = recv(sock,&nbr_files, 512, 0);
 if(sock_err == -1) return -1;
 else
 {
  print_header();
  printf("%d fichier(s) trouve(s), appuyez sur une touche pour les afficher.\n" , nbr_files);
  getchar();
 }
 return nbr_files;
}

variable_types: sock int

variable_types:
buf
char [512]

variable_types:
text
char [512]

variable_types:
p
char *