decompiled_code:
char __fastcall xmlsat_StartElement(_DWORD *a1, const char *a2, const char **a3)
{
const char *v3; // rax
const char **v4; // rbx
const char *v5; // rsi
const char **v6; // rbx
const char **v7; // rbx
int v8; // eax
__int64 v9; // rdx
int v10; // eax
__int64 v11; // rdx
const char *v12; // rsi
const char **v13; // rbx
const char *v14; // rsi
int v15; // eax
const char *v16; // rsi
const char **v17; // rbx
const char **v18; // rbx
bool v19; // zf
unsigned __int8 **v20; // rbx

LOBYTE(v3) = (_BYTE)a2;
if ( !strcmp(a2, "satellite") )
{
*a1 = 1;
}
else if ( !strcmp(a2, "transponder") )
{
*a1 = 2;
freq = 0;
pol = 86;
srate = 27500;
if ( a3 )
{
v3 = *a3;
if ( *a3 )
{
v4 = a3 + 1;
do
{
if ( !strcmp(v3, "freq") )
{
freq = atoi(*v4) / 1000;
}
else if ( !strcmp(v3, "srate") )
{
srate = atoi(*v4) / 1000;
}
else if ( !strcmp(v3, "polarity") )
{
pol = **v4;
}
v4 += 2;
v3 = *(v4 - 1);
}
while ( v3 );
}
}
}
else if ( !strcmp(a2, "service") )
{
if ( a3 )
{
pnr = 0;
ca = 0;
v5 = *a3;
if ( *a3 )
{
v6 = a3 + 1;
do
{
v19 = strcmp(v5, "id") == 0;
LOBYTE(v3) = !v19;
if ( v19 )
{
LODWORD(v3) = atoi(*v6);
pnr = (int)v3;
}
v6 += 2;
v5 = *(v6 - 1);
}
while ( v5 );
}
}
}
else if ( !strcmp(a2, "stream") )
{
if ( a3 )
{
streamtype_1 = 0;
pid_0 = 0;
v3 = *a3;
if ( *a3 )
{
v7 = a3 + 1;
do
{
if ( !strcmp(v3, "type") )
{
streamtype_1 = atoi(*v7);
}
else if ( !strcmp(v3, "pid") )
{
pid_0 = atoi(*v7);
}
v7 += 2;
v3 = *(v7 - 1);
}
while ( v3 );
if ( (unsigned int)(streamtype_1 - 1) <= 1 )
{
LOBYTE(v3) = pid_0;
vpid = pid_0;
}
else
{
LOBYTE(v3) = streamtype_1 - 3;
if ( (unsigned int)(streamtype_1 - 3) <= 1 )
{
in_audio_stream = 1;
v8 = n_apids;
v9 = n_apids;
apid[n_apids] = pid_0;
is_ac3[v9] = 0;
lang[4 * v9] = 0;
LODWORD(v3) = v8 + 1;
n_apids = (int)v3;
}
}
}
}
}
else if ( !strcmp(a2, "ac3_descriptor") )
{
if ( streamtype_1 == 6 )
{
v10 = n_apids;
v11 = n_apids;
is_ac3[n_apids] = 1;
apid[v11] = pid_0;
lang[4 * v11] = 0;
LODWORD(v3) = v10 + 1;
n_apids = (int)v3;
in_audio_stream = 1;
}
}
else if ( !strcmp(a2, "ca_system_descriptor") )
{
ca = 1;
v12 = *a3;
if ( *a3 )
{
v13 = a3 + 1;
do
{
v19 = strcmp(v12, "system_id") == 0;
LOBYTE(v3) = !v19;
if ( v19 )
{
v14 = *v13;
if ( **v13 )
{
v15 = n_ca++;
LOBYTE(v3) = (unsigned __int8)strcpy(&ca_systems[256 * (__int64)v15], v14);
}
}
v13 += 2;
v12 = *(v13 - 1);
}
while ( v12 );
}
}
else if ( !strcmp(a2, "iso_639") )
{
if ( in_audio_stream )
{
if ( a3 )
{
canal_radio_id = 0;
v16 = *a3;
if ( *a3 )
{
v17 = a3 + 1;
do
{
v19 = strcmp(v16, "language") == 0;
LOBYTE(v3) = !v19;
if ( v19 && **v17 )
LOBYTE(v3) = (unsigned __int8)strcpy(&lang[4 * n_apids - 4], *v17);
v17 += 2;
v16 = *(v17 - 1);
}
while ( v16 );
}
}
}
}
else if ( !strcmp(a2, "canal_radio") )
{
ignore_service = 1;
if ( a3 )
{
canal_radio_id = 0;
v3 = *a3;
if ( *a3 )
{
v18 = a3 + 1;
do
{
if ( !memcmp(v3, "id", 3uLL) )
{
canal_radio_id = atoi(*v18);
}
else if ( !strcmp(v3, "name") )
{
my_strcpy((__int64)service_name, (unsigned __int8 *)*v18);
}
v18 += 2;
v3 = *(v18 - 1);
}
while ( v3 );
}
}
}
else
{
v19 = strcmp(a2, "description") == 0;
LOBYTE(v3) = !v19;
if ( a3 )
{
if ( v19 )
{
type = 0;
LOBYTE(service_name[0]) = 0;
provider_name = 0;
v3 = *a3;
if ( *a3 )
{
v20 = (unsigned __int8 **)(a3 + 1);
do
{
if ( !strcmp(v3, "service_name") )
{
my_strcpy((__int64)service_name, *v20);
}
else if ( !strcmp(v3, "provider_name") )
{
my_strcpy((__int64)&provider_name, *v20);
}
else if ( !strcmp(v3, "type") )
{
type = atoi((const char *)*v20);
}
v20 += 2;
v3 = (const char *)*(v20 - 1);
}
while ( v3 );
}
}
}
}
return (char)v3;
}

canonical_decompiled_code:
char __fastcall func13(_DWORD *a1, const char *a2, const char **a3)
{
const char *v3; // rax
const char **v4; // rbx
const char *v5; // rsi
const char **v6; // rbx
const char **v7; // rbx
int v8; // eax
__int64 v9; // rdx
int v10; // eax
__int64 v11; // rdx
const char *v12; // rsi
const char **v13; // rbx
const char *v14; // rsi
int v15; // eax
const char *v16; // rsi
const char **v17; // rbx
const char **v18; // rbx
bool v19; // zf
unsigned __int8 **v20; // rbx

LOBYTE(v3) = (_BYTE)a2;
if ( !strcmp(a2, "satellite") )
{
*a1 = 1;
}
else if ( !strcmp(a2, "transponder") )
{
*a1 = 2;
freq = 0;
pol = 86;
srate = 27500;
if ( a3 )
{
v3 = *a3;
if ( *a3 )
{
v4 = a3 + 1;
do
{
if ( !strcmp(v3, "freq") )
{
freq = atoi(*v4) / 1000;
}
else if ( !strcmp(v3, "srate") )
{
srate = atoi(*v4) / 1000;
}
else if ( !strcmp(v3, "polarity") )
{
pol = **v4;
}
v4 += 2;
v3 = *(v4 - 1);
}
while ( v3 );
}
}
}
else if ( !strcmp(a2, "service") )
{
if ( a3 )
{
pnr = 0;
ca = 0;
v5 = *a3;
if ( *a3 )
{
v6 = a3 + 1;
do
{
v19 = strcmp(v5, "id") == 0;
LOBYTE(v3) = !v19;
if ( v19 )
{
LODWORD(v3) = atoi(*v6);
pnr = (int)v3;
}
v6 += 2;
v5 = *(v6 - 1);
}
while ( v5 );
}
}
}
else if ( !strcmp(a2, "stream") )
{
if ( a3 )
{
streamtype_1 = 0;
pid_0 = 0;
v3 = *a3;
if ( *a3 )
{
v7 = a3 + 1;
do
{
if ( !strcmp(v3, "type") )
{
streamtype_1 = atoi(*v7);
}
else if ( !strcmp(v3, "pid") )
{
pid_0 = atoi(*v7);
}
v7 += 2;
v3 = *(v7 - 1);
}
while ( v3 );
if ( (unsigned int)(streamtype_1 - 1) <= 1 )
{
LOBYTE(v3) = pid_0;
vpid = pid_0;
}
else
{
LOBYTE(v3) = streamtype_1 - 3;
if ( (unsigned int)(streamtype_1 - 3) <= 1 )
{
in_audio_stream = 1;
v8 = n_apids;
v9 = n_apids;
apid[n_apids] = pid_0;
is_ac3[v9] = 0;
lang[4 * v9] = 0;
LODWORD(v3) = v8 + 1;
n_apids = (int)v3;
}
}
}
}
}
else if ( !strcmp(a2, "ac3_descriptor") )
{
if ( streamtype_1 == 6 )
{
v10 = n_apids;
v11 = n_apids;
is_ac3[n_apids] = 1;
apid[v11] = pid_0;
lang[4 * v11] = 0;
LODWORD(v3) = v10 + 1;
n_apids = (int)v3;
in_audio_stream = 1;
}
}
else if ( !strcmp(a2, "ca_system_descriptor") )
{
ca = 1;
v12 = *a3;
if ( *a3 )
{
v13 = a3 + 1;
do
{
v19 = strcmp(v12, "system_id") == 0;
LOBYTE(v3) = !v19;
if ( v19 )
{
v14 = *v13;
if ( **v13 )
{
v15 = n_ca++;
LOBYTE(v3) = (unsigned __int8)strcpy(&ca_systems[256 * (__int64)v15], v14);
}
}
v13 += 2;
v12 = *(v13 - 1);
}
while ( v12 );
}
}
else if ( !strcmp(a2, "iso_639") )
{
if ( in_audio_stream )
{
if ( a3 )
{
canal_radio_id = 0;
v16 = *a3;
if ( *a3 )
{
v17 = a3 + 1;
do
{
v19 = strcmp(v16, "language") == 0;
LOBYTE(v3) = !v19;
if ( v19 && **v17 )
LOBYTE(v3) = (unsigned __int8)strcpy(&lang[4 * n_apids - 4], *v17);
v17 += 2;
v16 = *(v17 - 1);
}
while ( v16 );
}
}
}
}
else if ( !strcmp(a2, "canal_radio") )
{
ignore_service = 1;
if ( a3 )
{
canal_radio_id = 0;
v3 = *a3;
if ( *a3 )
{
v18 = a3 + 1;
do
{
if ( !memcmp(v3, "id", 3uLL) )
{
canal_radio_id = atoi(*v18);
}
else if ( !strcmp(v3, "name") )
{
func12((__int64)service_name, (unsigned __int8 *)*v18);
}
v18 += 2;
v3 = *(v18 - 1);
}
while ( v3 );
}
}
}
else
{
v19 = strcmp(a2, "description") == 0;
LOBYTE(v3) = !v19;
if ( a3 )
{
if ( v19 )
{
type = 0;
LOBYTE(service_name[0]) = 0;
provider_name = 0;
v3 = *a3;
if ( *a3 )
{
v20 = (unsigned __int8 **)(a3 + 1);
do
{
if ( !strcmp(v3, "service_name") )
{
func12((__int64)service_name, *v20);
}
else if ( !strcmp(v3, "provider_name") )
{
func12((__int64)&provider_name, *v20);
}
else if ( !strcmp(v3, "type") )
{
type = atoi((const char *)*v20);
}
v20 += 2;
v3 = (const char *)*(v20 - 1);
}
while ( v3 );
}
}
}
}
return (char)v3;
}

original_code:
static void xmlsat_StartElement(xmlsatParseState *state, const char *name,
                               const char **attrs) {
  int i;
  static int streamtype;
  static int pid;
    if (strcmp(name,"satellite")==0) {
       state->state=PARSER_IN_SATELLITE;
    } else if (strcmp(name,"transponder")==0) {
        state->state=PARSER_IN_TRANSPONDER;
        freq=0;
        pol='V';
        srate=27500;
        if (attrs!=((void *)0)) {
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"freq")==0) {
                freq=atoi(attrs[i+1])/1000;
              } else if (strcmp(attrs[i],"srate")==0) {
                srate=atoi(attrs[i+1])/1000;
              } else if (strcmp(attrs[i],"polarity")==0) {
                pol=attrs[i+1][0];
              }
           }
        }
    } else if (strcmp(name,"service")==0) {
        if (attrs!=((void *)0)) {
           pnr=0;
           ca=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"id")==0) {
                pnr=atoi(attrs[i+1]);
              }
           }
        }
    } else if (strcmp(name,"stream")==0) {
        if (attrs!=((void *)0)) {
           streamtype=0;
           pid=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"type")==0) {
                streamtype=atoi(attrs[i+1]);
              } else if (strcmp(attrs[i],"pid")==0) {
                pid=atoi(attrs[i+1]);
              }
           }
           if ((streamtype==1) || (streamtype==2)) {
             vpid=pid;
           } else if ((streamtype==3) || (streamtype==4)) {
             in_audio_stream=1;
             apid[n_apids]=pid;
             is_ac3[n_apids]=0;
             lang[n_apids][0]=0;
             n_apids++;
           } else if (streamtype==6) {
           }
        }
    } else if (strcmp(name,"ac3_descriptor")==0) {
      if (streamtype==6) {
        is_ac3[n_apids]=1;
        apid[n_apids]=pid;
        lang[n_apids][0]=0;
        n_apids++;
        in_audio_stream=1;
      }
    } else if (strcmp(name,"ca_system_descriptor")==0) {
      ca=1;
      for (i=0;attrs[i]!=((void *)0);i+=2) {
         if (strcmp(attrs[i],"system_id")==0) {
           if (strlen(attrs[i+1])>0) {
             strcpy(ca_systems[n_ca++],attrs[i+1]);
           }
         }
      }
    } else if (strcmp(name,"iso_639")==0) {
      if (in_audio_stream) {
        if (attrs!=((void *)0)) {
           canal_radio_id=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"language")==0) {
                if (strlen(attrs[i+1])>0) {
                  strcpy(lang[n_apids-1],attrs[i+1]);
                }
              }
           }
        }
      }
    } else if (strcmp(name,"canal_radio")==0) {
        ignore_service=1;
        if (attrs!=((void *)0)) {
           canal_radio_id=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"id")==0) {
                canal_radio_id=atoi(attrs[i+1]);
              } else if (strcmp(attrs[i],"name")==0) {
                my_strcpy((unsigned char*)service_name,(unsigned char*)attrs[i+1]);
              }
           }
        }
    } else if (strcmp(name,"description")==0) {
        if (attrs!=((void *)0)) {
           type=0;
           service_name[0]=0;
           provider_name[0]=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"service_name")==0) {
                my_strcpy((unsigned char*)service_name,(unsigned char*)attrs[i+1]);
              } else if (strcmp(attrs[i],"provider_name")==0) {
                my_strcpy((unsigned char*)provider_name,(unsigned char*)attrs[i+1]);
              } else if (strcmp(attrs[i],"type")==0) {
                type=atoi(attrs[i+1]);
              }
           }
       }
   }
}

canonical_original_code:
static void xmlsat_StartElement(struct _xmlsatParseState *state, char *name, char **attrs) {
  int i;
  static int streamtype;
  static int pid;
    if (strcmp(name,"satellite")==0) {
       state->state=PARSER_IN_SATELLITE;
    } else if (strcmp(name,"transponder")==0) {
        state->state=PARSER_IN_TRANSPONDER;
        freq=0;
        pol='V';
        srate=27500;
        if (attrs!=((void *)0)) {
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"freq")==0) {
                freq=atoi(attrs[i+1])/1000;
              } else if (strcmp(attrs[i],"srate")==0) {
                srate=atoi(attrs[i+1])/1000;
              } else if (strcmp(attrs[i],"polarity")==0) {
                pol=attrs[i+1][0];
              }
           }
        }
    } else if (strcmp(name,"service")==0) {
        if (attrs!=((void *)0)) {
           pnr=0;
           ca=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"id")==0) {
                pnr=atoi(attrs[i+1]);
              }
           }
        }
    } else if (strcmp(name,"stream")==0) {
        if (attrs!=((void *)0)) {
           streamtype=0;
           pid=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"type")==0) {
                streamtype=atoi(attrs[i+1]);
              } else if (strcmp(attrs[i],"pid")==0) {
                pid=atoi(attrs[i+1]);
              }
           }
           if ((streamtype==1) || (streamtype==2)) {
             vpid=pid;
           } else if ((streamtype==3) || (streamtype==4)) {
             in_audio_stream=1;
             apid[n_apids]=pid;
             is_ac3[n_apids]=0;
             lang[n_apids][0]=0;
             n_apids++;
           } else if (streamtype==6) {
           }
        }
    } else if (strcmp(name,"ac3_descriptor")==0) {
      if (streamtype==6) {
        is_ac3[n_apids]=1;
        apid[n_apids]=pid;
        lang[n_apids][0]=0;
        n_apids++;
        in_audio_stream=1;
      }
    } else if (strcmp(name,"ca_system_descriptor")==0) {
      ca=1;
      for (i=0;attrs[i]!=((void *)0);i+=2) {
         if (strcmp(attrs[i],"system_id")==0) {
           if (strlen(attrs[i+1])>0) {
             strcpy(ca_systems[n_ca++],attrs[i+1]);
           }
         }
      }
    } else if (strcmp(name,"iso_639")==0) {
      if (in_audio_stream) {
        if (attrs!=((void *)0)) {
           canal_radio_id=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"language")==0) {
                if (strlen(attrs[i+1])>0) {
                  strcpy(lang[n_apids-1],attrs[i+1]);
                }
              }
           }
        }
      }
    } else if (strcmp(name,"canal_radio")==0) {
        ignore_service=1;
        if (attrs!=((void *)0)) {
           canal_radio_id=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"id")==0) {
                canal_radio_id=atoi(attrs[i+1]);
              } else if (strcmp(attrs[i],"name")==0) {
                my_strcpy((unsigned char *)service_name,(unsigned char *)attrs[i+1]);
              }
           }
        }
    } else if (strcmp(name,"description")==0) {
        if (attrs!=((void *)0)) {
           type=0;
           service_name[0]=0;
           provider_name[0]=0;
           for (i=0;attrs[i]!=((void *)0);i+=2) {
              if (strcmp(attrs[i],"service_name")==0) {
                my_strcpy((unsigned char *)service_name,(unsigned char *)attrs[i+1]);
              } else if (strcmp(attrs[i],"provider_name")==0) {
                my_strcpy((unsigned char *)provider_name,(unsigned char *)attrs[i+1]);
              } else if (strcmp(attrs[i],"type")==0) {
                type=atoi(attrs[i+1]);
              }
           }
       }
   }
}

variable_types:
attrs
char **

variable_types: streamtype int

variable_types: pid int


initrtp

repo: linuxstb/dvbtools

decompiled_code:
int __fastcall initrtp(__int64 a1, char a2)
{
int result; // eax

*(_BYTE *)a1 = 2;
*(_BYTE *)(a1 + 1) = 2 * a2;
*(_WORD *)(a1 + 2) = rand();
*(_DWORD *)(a1 + 4) = rand();
result = rand();
*(_DWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, char a2)
{
int result; // eax

*(_BYTE *)a1 = 2;
*(_BYTE *)(a1 + 1) = 2 * a2;
*(_WORD *)(a1 + 2) = rand();
*(_DWORD *)(a1 + 4) = rand();
result = rand();
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
void initrtp(struct rtpheader *foo,int pt) {
  foo->b.v=2;
  foo->b.p=0;
  foo->b.x=0;
  foo->b.cc=0;
  foo->b.m=0;
  foo->b.pt=pt;
  foo->b.sequence=rand() & 65535;
  foo->timestamp=rand();
  foo->ssrc=rand();
}

canonical_original_code:
void initrtp(struct rtpheader *foo, int pt) {
  foo->b.v=2;
  foo->b.p=0;
  foo->b.x=0;
  foo->b.cc=0;
  foo->b.m=0;
  foo->b.pt=pt;
  foo->b.sequence=rand() & 65535;
  foo->timestamp=rand();
  foo->ssrc=rand();
}

variable_types: struct rtpheader { struct rtpbits { unsigned int v; unsigned int p; unsigned int x; unsigned int cc; unsigned int m; unsigned int pt; unsigned int sequence; } b; int timestamp; int ssrc; } *

variable_types: pt int

return_type: void

user_defined_types: struct rtpheader { struct rtpbits b; int timestamp; int ssrc; }


sendrtp

decompiled_code:
ssize_t __fastcall sendrtp(int a1, struct sockaddr *a2, unsigned int *a3, void *a4, int a5)
{
size_t v7; // r15
void *v8; // rsp
int v9; // eax
char v10; // r13
_DWORD v12[2]; // [rsp+0h] [rbp-50h] BYREF
void *src; // [rsp+8h] [rbp-48h] BYREF
struct sockaddr *addr; // [rsp+10h] [rbp-40h]
int fd; // [rsp+1Ch] [rbp-34h]

fd = a1;
addr = a2;
src = a4;
v7 = a5;
v8 = alloca(a5 + 20LL);
v9 = _bswap_32(*a3);
v10 = v9;
v12[0] = v9;
v12[1] = _bswap_32(a3[1]);
memcpy(&src, src, v7);
fprintf(stderr, "v=%x %x\n", *(_BYTE *)a3 & 3, (unsigned int)v10);
return sendto(fd, v12, a5 + 3, 0, addr, 0x10u);
}

canonical_decompiled_code:
ssize_t __fastcall func11(int a1, struct sockaddr *a2, unsigned int *a3, void *a4, int a5)
{
size_t v7; // r15
void *v8; // rsp
int v9; // eax
char v10; // r13
_DWORD v12[2]; // [rsp+0h] [rbp-50h] BYREF
void *src; // [rsp+8h] [rbp-48h] BYREF
struct sockaddr *addr; // [rsp+10h] [rbp-40h]
int fd; // [rsp+1Ch] [rbp-34h]

fd = a1;
addr = a2;
src = a4;
v7 = a5;
v8 = alloca(a5 + 20LL);
v9 = func8(*a3);
v10 = v9;
v12[0] = v9;
v12[1] = func8(a3[1]);
memcpy(&src, src, v7);
fprintf(stderr, "v=%x %x\n", *(_BYTE *)a3 & 3, (unsigned int)v10);
return sendto(fd, v12, a5 + 3, 0, addr, 0x10u);
}

original_code:
int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len) {
  char *buf=(char*)__builtin_alloca (len+sizeof(struct rtpheader));
  int *cast=(int *)foo;
  int *outcast=(int *)buf;
  outcast[0]=htonl(cast[0]);
  outcast[1]=htonl(cast[1]);
  memmove(outcast+2,data,len);
  fprintf(stderr,"v=%x %x\n",foo->b.v,buf[0]);
  return sendto(fd,buf,len+3,0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr));
}

canonical_original_code:
int sendrtp(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len) {
  char *buf = (char*)__builtin_alloca (len+sizeof(struct rtpheader));
  int *cast = (int *)foo;
  int *outcast = (int *)buf;
  outcast[0]=htonl(cast[0]);
  outcast[1]=htonl(cast[1]);
  memmove(outcast+2,data,len);
  fprintf(stderr,"v=%x %x\n",foo->b.v,buf[0]);
  return sendto(fd,buf,len+3,0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr));
}

variable_types: fd int

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:
data
char *

variable_types: len int

variable_types:
buf
char *

variable_types:
cast
int *

variable_types:
outcast
int *

return_type: int

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

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

user_defined_types: struct rtpbits { unsigned int v; unsigned int p; unsigned int x; unsigned int cc; unsigned int m; unsigned int pt; unsigned int sequence; }


original_code:
int getrtp2(int fd, struct rtpheader *rh, char** data, int* lengthData) {
  static char buf[1600];
  unsigned int intP;
  char* charP = (char*) &intP;
  int headerSize;
  int lengthPacket;
  lengthPacket=recv(fd,buf,1590,0);
  if (lengthPacket==0)
    exit(1);
  if (lengthPacket<0) {
    fprintf(stderr,"socket read error\n");
    exit(2);
  }
  if (lengthPacket<12) {
    fprintf(stderr,"packet too small (%d) to be an rtp frame (>12bytes)\n",lengthPacket);
    exit(3);
  }
  rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
  rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
  rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
  rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
  rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
  rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
  intP = 0;
  memcpy(charP+2,&buf[2],2);
  rh->b.sequence = ntohl(intP);
  intP = 0;
  memcpy(charP,&buf[4],4);
  rh->timestamp = ntohl(intP);
  headerSize = 12 + 4*rh->b.cc;
  *lengthData = lengthPacket - headerSize;
  *data = (char*) buf + headerSize;
  return(0);
}

canonical_original_code:
int getrtp2(int fd, struct rtpheader *rh, char **data, int *lengthData) {
  static char buf[1600];
  unsigned int intP;
  char *charP = (char*) &intP;
  int headerSize;
  int lengthPacket;
  lengthPacket=recv(fd,buf,1590,0);
  if (lengthPacket==0)
    exit(1);
  if (lengthPacket<0) {
    fprintf(stderr,"socket read error\n");
    exit(2);
  }
  if (lengthPacket<12) {
    fprintf(stderr,"packet too small (%d) to be an rtp frame (>12bytes)\n",lengthPacket);
    exit(3);
  }
  rh->b.v = (unsigned int) ((buf[0]>>6)&0x03);
  rh->b.p = (unsigned int) ((buf[0]>>5)&0x01);
  rh->b.x = (unsigned int) ((buf[0]>>4)&0x01);
  rh->b.cc = (unsigned int) ((buf[0]>>0)&0x0f);
  rh->b.m = (unsigned int) ((buf[1]>>7)&0x01);
  rh->b.pt = (unsigned int) ((buf[1]>>0)&0x7f);
  intP = 0;
  memcpy(charP+2,&buf[2],2);
  rh->b.sequence = ntohl(intP);
  intP = 0;
  memcpy(charP,&buf[4],4);
  rh->timestamp = ntohl(intP);
  headerSize = 12 + 4*rh->b.cc;
  *lengthData = lengthPacket - headerSize;
  *data = (char *) buf + headerSize;
  return(0);
}

variable_types:
data
char **

variable_types:
lengthData
int *

variable_types:
buf
char [1600]

variable_types:
intP
unsigned int

variable_types:
charP
char *

variable_types: headerSize int

variable_types: lengthPacket int


original_code:
int sendrtp2(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len) {
  char *buf=(char*)__builtin_alloca (len+72);
  unsigned int intP;
  char* charP = (char*) &intP;
  int headerSize;
  buf[0] = 0x00;
  buf[0] |= ((((char) foo->b.v)<<6)&0xc0);
  buf[0] |= ((((char) foo->b.p)<<5)&0x20);
  buf[0] |= ((((char) foo->b.x)<<4)&0x10);
  buf[0] |= ((((char) foo->b.cc)<<0)&0x0f);
  buf[1] = 0x00;
  buf[1] |= ((((char) foo->b.m)<<7)&0x80);
  buf[1] |= ((((char) foo->b.pt)<<0)&0x7f);
  intP = htonl(foo->b.sequence);
  memcpy(&buf[2],charP+2,2);
  intP = htonl(foo->timestamp);
  memcpy(&buf[4],&intP,4);
  buf[8] = 0x0f;
  buf[9] = 0x0f;
  buf[10] = 0x0f;
  buf[11] = 0x0f;
  headerSize = 12 + 4*foo->b.cc;
  memcpy(buf+headerSize,data,len);
  foo->b.sequence++;
  return sendto(fd,buf,len+headerSize,0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr));
}

canonical_original_code:
int sendrtp2(int fd, struct sockaddr_in *sSockAddr, struct rtpheader *foo, char *data, int len) {
  char *buf = (char*)__builtin_alloca (len+72);
  unsigned int intP;
  char *charP = (char*) &intP;
  int headerSize;
  buf[0] = 0x00;
  buf[0] |= ((((char) foo->b.v)<<6)&0xc0);
  buf[0] |= ((((char) foo->b.p)<<5)&0x20);
  buf[0] |= ((((char) foo->b.x)<<4)&0x10);
  buf[0] |= ((((char) foo->b.cc)<<0)&0x0f);
  buf[1] = 0x00;
  buf[1] |= ((((char) foo->b.m)<<7)&0x80);
  buf[1] |= ((((char) foo->b.pt)<<0)&0x7f);
  intP = htonl(foo->b.sequence);
  memcpy(&buf[2],charP+2,2);
  intP = htonl(foo->timestamp);
  memcpy(&buf[4],&intP,4);
  buf[8] = 0x0f;
  buf[9] = 0x0f;
  buf[10] = 0x0f;
  buf[11] = 0x0f;
  headerSize = 12 + 4*foo->b.cc;
  memcpy(buf+headerSize,data,len);
  foo->b.sequence++;
  return sendto(fd,buf,len+headerSize,0,(struct sockaddr *)sSockAddr,sizeof(*sSockAddr));
}


getrtp

decompiled_code:
__int64 __fastcall getrtp(int a1, __int64 a2, _QWORD *a3, _DWORD *a4)
{
ssize_t v6; // rax

v6 = recv(a1, &buf_0, 0x636uLL, 0);
*a4 = v6 - 3;
*a3 = &unk_4040C3;
fprintf(stderr, "[%d] %02x %x\n", v6, (unsigned int)byte_4040C8, (unsigned int)buf_0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, __int64 a2, _QWORD *a3, _DWORD *a4)
{
ssize_t v6; // rax

v6 = recv(a1, &buf_0, 0x636uLL, 0);
*a4 = v6 - 3;
*a3 = &unk_4040C3;
fprintf(stderr, "[%d] %02x %x\n", v6, (unsigned int)byte_4040C8, (unsigned int)buf_0);
return 0LL;
}

original_code:
int getrtp(int fd, struct rtpheader *rh, char** data, int* lengthData) {
  static char buf[1600];
  int headerSize;
  int lengthPacket;
  lengthPacket=recv(fd,buf,1590,0);
  headerSize = 3;
  *lengthData = lengthPacket - headerSize;
  *data = (char*) buf + headerSize;
  fprintf(stderr,"[%d] %02x %x\n",lengthPacket,buf[8],buf[0]);
  return(0);
}

canonical_original_code:
int getrtp(int fd, struct rtpheader *rh, char **data, int *lengthData) {
  static char buf[1600];
  int headerSize;
  int lengthPacket;
  lengthPacket=recv(fd,buf,1590,0);
  headerSize = 3;
  *lengthData = lengthPacket - headerSize;
  *data = (char *) buf + headerSize;
  fprintf(stderr,"[%d] %02x %x\n",lengthPacket,buf[8],buf[0]);
  return(0);
}


makesocket

decompiled_code:
__int64 __fastcall makesocket(char *cp, __int16 a2, char a3, __int64 a4)
{
int v5; // eax
unsigned int v6; // ebx
char v8; // [rsp+Ah] [rbp-2Eh] BYREF
char v9; // [rsp+Bh] [rbp-2Dh] BYREF
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

optval[0] = 1;
v9 = a3;
v8 = 0;
v5 = socket(2, 2, 0);
if ( v5 < 0 )
{
fwrite("socket() failed.\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
v6 = v5;
*(_WORD *)a4 = 2;
*(_WORD *)(a4 + 2) = _bswap_16(a2);
*(_DWORD *)(a4 + 4) = inet_addr(cp);
if ( setsockopt(v6, 1, 2, optval, 4u) < 0 )
{
fwrite("setsockopt SO_REUSEADDR failed\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
if ( setsockopt(v6, 0, 33, &v9, 1u) < 0 )
{
fwrite("setsockopt IP_MULTICAST_TTL failed. multicast in kernel?\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
v8 = 1;
if ( setsockopt(v6, 0, 34, &v8, 1u) < 0 )
{
fwrite("setsockopt IP_MULTICAST_LOOP failed. multicast in kernel?\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *cp, __int16 a2, char a3, __int64 a4)
{
int v5; // eax
unsigned int v6; // ebx
char v8; // [rsp+Ah] [rbp-2Eh] BYREF
char v9; // [rsp+Bh] [rbp-2Dh] BYREF
int optval[11]; // [rsp+Ch] [rbp-2Ch] BYREF

optval[0] = 1;
v9 = a3;
v8 = 0;
v5 = socket(2, 2, 0);
if ( v5 < 0 )
{
fwrite("socket() failed.\n", 1uLL, 0x11uLL, stderr);
exit(1);
}
v6 = v5;
*(_WORD *)a4 = 2;
*(_WORD *)(a4 + 2) = func9(a2);
*(_DWORD *)(a4 + 4) = inet_addr(cp);
if ( setsockopt(v6, 1, 2, optval, 4u) < 0 )
{
fwrite("setsockopt SO_REUSEADDR failed\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
if ( setsockopt(v6, 0, 33, &v9, 1u) < 0 )
{
fwrite("setsockopt IP_MULTICAST_TTL failed. multicast in kernel?\n", 1uLL, 0x3AuLL, stderr);
exit(1);
}
v8 = 1;
if ( setsockopt(v6, 0, 34, &v8, 1u) < 0 )
{
fwrite("setsockopt IP_MULTICAST_LOOP failed. multicast in kernel?\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
return v6;
}

original_code:
int makesocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr) {
  int iRet, iLoop = 1;
  struct sockaddr_in sin;
  char cTtl = (char)TTL;
  char cLoop=0;
  int iSocket = socket( 2, SOCK_DGRAM, 0 );
  if (iSocket < 0) {
    fprintf(stderr,"socket() failed.\n");
    exit(1);
  }
  sSockAddr->sin_family = sin.sin_family = 2;
  sSockAddr->sin_port = sin.sin_port = htons(port);
  sSockAddr->sin_addr.s_addr = inet_addr(szAddr);
  iRet = setsockopt(iSocket, 1, 2, &iLoop, sizeof(int));
  if (iRet < 0) {
    fprintf(stderr,"setsockopt SO_REUSEADDR failed\n");
    exit(1);
  }
  iRet = setsockopt(iSocket, IPPROTO_IP, 33, &cTtl, sizeof(char));
  if (iRet < 0) {
    fprintf(stderr,"setsockopt IP_MULTICAST_TTL failed.  multicast in kernel?\n");
    exit(1);
  }
  cLoop = 1;
  iRet = setsockopt(iSocket, IPPROTO_IP, 34,
                    &cLoop, sizeof(char));
  if (iRet < 0) {
    fprintf(stderr,"setsockopt IP_MULTICAST_LOOP failed.  multicast in kernel?\n");
    exit(1);
  }
  return iSocket;
}

canonical_original_code:
int makesocket(char *szAddr, unsigned short port, int TTL, struct sockaddr_in *sSockAddr) {
  int iRet; int iLoop = 1;
  struct sockaddr_in sin;
  char cTtl = (char)TTL;
  char cLoop = 0;
  int iSocket = socket( 2, SOCK_DGRAM, 0 );
  if (iSocket < 0) {
    fprintf(stderr,"socket() failed.\n");
    exit(1);
  }
  sSockAddr->sin_family = sin.sin_family = 2;
  sSockAddr->sin_port = sin.sin_port = htons(port);
  sSockAddr->sin_addr.s_addr = inet_addr(szAddr);
  iRet = setsockopt(iSocket, 1, 2, &iLoop, sizeof(int));
  if (iRet < 0) {
    fprintf(stderr,"setsockopt SO_REUSEADDR failed\n");
    exit(1);
  }
  iRet = setsockopt(iSocket, IPPROTO_IP, 33, &cTtl, sizeof(char));
  if (iRet < 0) {
    fprintf(stderr,"setsockopt IP_MULTICAST_TTL failed.  multicast in kernel?\n");
    exit(1);
  }
  cLoop = 1;
  iRet = setsockopt(iSocket, IPPROTO_IP, 34,
                    &cLoop, sizeof(char));
  if (iRet < 0) {
    fprintf(stderr,"setsockopt IP_MULTICAST_LOOP failed.  multicast in kernel?\n");
    exit(1);
  }
  return iSocket;
}

variable_types:
szAddr
char *

variable_types:
port
unsigned short

variable_types: TTL int

variable_types: iRet int

variable_types: iLoop int

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: cTtl char

variable_types: cLoop char

variable_types: iSocket int


makeclientsocket

decompiled_code:
__int64 __fastcall makeclientsocket(char *cp, __int16 a2, char a3, __int64 a4)
{
unsigned int v4; // ebp
unsigned int v5; // eax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
int optval[8]; // [rsp+18h] [rbp-20h] BYREF

v4 = makesocket(cp, a2, a3, a4);
v7.sa_family = 2;
*(_WORD *)v7.sa_data = _bswap_16(a2);
*(_DWORD *)&v7.sa_data[2] = inet_addr(cp);
if ( bind(v4, &v7, 0x10u) )
{
perror("bind failed");
exit(1);
}
v5 = inet_addr(cp);
if ( (unsigned int)_bswap_32(v5) >> 28 == 14 )
{
optval[0] = inet_addr(cp);
optval[1] = 0;
if ( setsockopt(v4, 0, 35, optval, 8u) )
{
perror("setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)");
exit(1);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *cp, __int16 a2, char a3, __int64 a4)
{
unsigned int v4; // ebp
unsigned int v5; // eax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
int optval[8]; // [rsp+18h] [rbp-20h] BYREF

v4 = func15(cp, a2, a3, a4);
v7.sa_family = 2;
*(_WORD *)v7.sa_data = func9(a2);
*(_DWORD *)&v7.sa_data[2] = inet_addr(cp);
if ( bind(v4, &v7, 0x10u) )
{
perror("bind failed");
exit(1);
}
v5 = inet_addr(cp);
if ( (unsigned int)func8(v5) >> 28 == 14 )
{
optval[0] = inet_addr(cp);
optval[1] = 0;
if ( setsockopt(v4, 0, 35, optval, 8u) )
{
perror("setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)");
exit(1);
}
}
return v4;
}

original_code:
int makeclientsocket(char *szAddr,unsigned short port,int TTL,struct sockaddr_in *sSockAddr) {
  int socket=makesocket(szAddr,port,TTL,sSockAddr);
  struct ip_mreq blub;
  struct sockaddr_in sin;
  unsigned int tempaddr;
  sin.sin_family=2;
  sin.sin_port=htons(port);
  sin.sin_addr.s_addr=inet_addr(szAddr);
  if (bind(socket,(struct sockaddr *)&sin,sizeof(sin))) {
    perror("bind failed");
    exit(1);
  }
  tempaddr=inet_addr(szAddr);
  if ((ntohl(tempaddr) >> 28) == 0xe) {
    blub.imr_multiaddr.s_addr = inet_addr(szAddr);
    blub.imr_interface.s_addr = 0;
    if (setsockopt(socket,IPPROTO_IP,35,&blub,sizeof(blub))) {
      perror("setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)");
      exit(1);
    }
  }
  return socket;
}

canonical_original_code:
int makeclientsocket(char *szAddr, unsigned short port, int TTL, struct sockaddr_in *sSockAddr) {
  int socket = makesocket(szAddr,port,TTL,sSockAddr);
  struct ip_mreq blub;
  struct sockaddr_in sin;
  unsigned int tempaddr;
  sin.sin_family=2;
  sin.sin_port=htons(port);
  sin.sin_addr.s_addr=inet_addr(szAddr);
  if (bind(socket,(struct sockaddr *)&sin,sizeof(sin))) {
    perror("bind failed");
    exit(1);
  }
  tempaddr=inet_addr(szAddr);
  if ((ntohl(tempaddr) >> 28) == 0xe) {
    blub.imr_multiaddr.s_addr = inet_addr(szAddr);
    blub.imr_interface.s_addr = 0;
    if (setsockopt(socket,IPPROTO_IP,35,&blub,sizeof(blub))) {
      perror("setsockopt IP_ADD_MEMBERSHIP failed (multicast kernel?)");
      exit(1);
    }
  }
  return socket;
}

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

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

variable_types:
tempaddr
unsigned int

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


decompiled_code:
__int64 __fastcall check_status(int fd, int a2, __int64 a3, int a4)
{
int v6; // er13
__int64 result; // rax
int *v8; // r14
int v9; // edx
struct pollfd fds; // [rsp+8h] [rbp-60h] BYREF
int v11; // [rsp+10h] [rbp-58h] BYREF
unsigned int v12; // [rsp+14h] [rbp-54h]
unsigned int v13; // [rsp+1Ch] [rbp-4Ch]
unsigned int v14; // [rsp+20h] [rbp-48h]
int v15; // [rsp+38h] [rbp-30h] BYREF
int v16[11]; // [rsp+3Ch] [rbp-2Ch] BYREF

while ( ioctl(fd, 0x80286F4EuLL, &v11) >= 0 )
;
if ( ioctl(fd, 0x40246F4CuLL, a3) < 0 )
{
perror("ERROR tuning channel\n");
result = 0xFFFFFFFFLL;
}
else
{
fds.fd = fd;
fds.events = 2;
v11 = 0;
while ( (v11 & 0x30) == 0 )
{
fwrite("polling....\n", 1uLL, 0xCuLL, stderr);
if ( poll(&fds, 1uLL, 10000) > 0 )
{
if ( (fds.revents & 2) != 0 )
{
fwrite("Getting frontend event\n", 1uLL, 0x17uLL, stderr);
v6 = ioctl(fd, 0x80286F4EuLL, &v11);
if ( v6 < 0 )
{
v8 = _errno_location();
if ( *v8 != 75 )
{
perror("FE_GET_EVENT");
fprintf(stderr, "status = %d\n", (unsigned int)v6);
fprintf(stderr, "errno = %d\n", (unsigned int)*v8);
return 0xFFFFFFFFLL;
}
fprintf(stderr, "Overflow error, trying again (status = %d, errno = %d)", (unsigned int)v6, 75LL);
}
}
print_status(stderr, v11);
}
}
if ( (v11 & 0x10) != 0 )
{
switch ( a2 )
{
case 1:
fprintf(stderr, "Event: Frequency: %d\n", v12);
fprintf(stderr, " SymbolRate: %d\n", v13);
fprintf(stderr, " FEC_inner: %d\n", v14);
break;
case 2:
fprintf(stderr, "Event: Frequency: %d\n", v12);
break;
case 0:
fprintf(stderr, "Event: Frequency: %d\n", v12 + (a4 == 0 ? 9750000 : 10600000));
fprintf(stderr, " SymbolRate: %d\n", v13);
fprintf(stderr, " FEC_inner: %d\n", v14);
fputc(10, stderr);
break;
}
v16[0] = 0;
if ( ioctl(fd, 0x80046F46uLL, v16) >= 0 )
fprintf(stderr, "Bit error rate: %d\n", (unsigned int)v16[0]);
v16[0] = 0;
if ( ioctl(fd, 0x80026F47uLL, v16) >= 0 )
fprintf(stderr, "Signal strength: %d\n", (unsigned int)v16[0]);
v16[0] = 0;
if ( ioctl(fd, 0x80026F48uLL, v16) >= 0 )
fprintf(stderr, "SNR: %d\n", (unsigned int)v16[0]);
v15 = 0;
v9 = ioctl(fd, 0x80046F45uLL, &v15);
result = 0LL;
if ( v9 >= 0 )
{
print_status(stderr, v15);
result = 0LL;
}
}
else
{
fwrite("Not able to lock to the signal on the given frequency\n", 1uLL, 0x36uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, int a2, __int64 a3, int a4)
{
int v6; // er13
__int64 result; // rax
int *v8; // r14
int v9; // edx
struct pollfd fds; // [rsp+8h] [rbp-60h] BYREF
int v11; // [rsp+10h] [rbp-58h] BYREF
unsigned int v12; // [rsp+14h] [rbp-54h]
unsigned int v13; // [rsp+1Ch] [rbp-4Ch]
unsigned int v14; // [rsp+20h] [rbp-48h]
int v15; // [rsp+38h] [rbp-30h] BYREF
int v16[11]; // [rsp+3Ch] [rbp-2Ch] BYREF

while ( ioctl(fd, 0x80286F4EuLL, &v11) >= 0 )
;
if ( ioctl(fd, 0x40246F4CuLL, a3) < 0 )
{
perror("ERROR tuning channel\n");
result = 0xFFFFFFFFLL;
}
else
{
fds.fd = fd;
fds.events = 2;
v11 = 0;
while ( (v11 & 0x30) == 0 )
{
fwrite("polling....\n", 1uLL, 0xCuLL, stderr);
if ( poll(&fds, 1uLL, 10000) > 0 )
{
if ( (fds.revents & 2) != 0 )
{
fwrite("Getting frontend event\n", 1uLL, 0x17uLL, stderr);
v6 = ioctl(fd, 0x80286F4EuLL, &v11);
if ( v6 < 0 )
{
v8 = _errno_location();
if ( *v8 != 75 )
{
perror("FE_GET_EVENT");
fprintf(stderr, "status = %d\n", (unsigned int)v6);
fprintf(stderr, "errno = %d\n", (unsigned int)*v8);
return 0xFFFFFFFFLL;
}
fprintf(stderr, "Overflow error, trying again (status = %d, errno = %d)", (unsigned int)v6, 75LL);
}
}
func0(stderr, v11);
}
}
if ( (v11 & 0x10) != 0 )
{
switch ( a2 )
{
case 1:
fprintf(stderr, "Event: Frequency: %d\n", v12);
fprintf(stderr, " SymbolRate: %d\n", v13);
fprintf(stderr, " FEC_inner: %d\n", v14);
break;
case 2:
fprintf(stderr, "Event: Frequency: %d\n", v12);
break;
case 0:
fprintf(stderr, "Event: Frequency: %d\n", v12 + (a4 == 0 ? 9750000 : 10600000));
fprintf(stderr, " SymbolRate: %d\n", v13);
fprintf(stderr, " FEC_inner: %d\n", v14);
fputc(10, stderr);
break;
}
v16[0] = 0;
if ( ioctl(fd, 0x80046F46uLL, v16) >= 0 )
fprintf(stderr, "Bit error rate: %d\n", (unsigned int)v16[0]);
v16[0] = 0;
if ( ioctl(fd, 0x80026F47uLL, v16) >= 0 )
fprintf(stderr, "Signal strength: %d\n", (unsigned int)v16[0]);
v16[0] = 0;
if ( ioctl(fd, 0x80026F48uLL, v16) >= 0 )
fprintf(stderr, "SNR: %d\n", (unsigned int)v16[0]);
v15 = 0;
v9 = ioctl(fd, 0x80046F45uLL, &v15);
result = 0LL;
if ( v9 >= 0 )
{
func0(stderr, v15);
result = 0LL;
}
}
else
{
fwrite("Not able to lock to the signal on the given frequency\n", 1uLL, 0x36uLL, stderr);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int check_status(int fd_frontend,int type, struct dvb_frontend_parameters* feparams,int hi_lo) {
  int32_t strength;
  fe_status_t festatus;
  struct dvb_frontend_event event;
  struct pollfd pfd[1];
  int status;
  while(1) {
 if (ioctl(fd_frontend, (((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((78)) << 0) | ((((sizeof(struct dvb_frontend_event)))) << ((0 +8)+8))), &event) < 0)
 break;
  }
  if (ioctl(fd_frontend,(((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((76)) << 0) | ((((sizeof(struct dvb_frontend_parameters)))) << ((0 +8)+8))),feparams) < 0) {
    perror("ERROR tuning channel\n");
    return -1;
  }
  pfd[0].fd = fd_frontend;
  pfd[0].events = 0x002;
  event.status=0;
  while (((event.status & FE_TIMEDOUT)==0) && ((event.status & FE_HAS_LOCK)==0)) {
    fprintf(stderr,"polling....\n");
    if (poll(pfd,1,10000) > 0){
      if (pfd[0].revents & 0x002){
        fprintf(stderr,"Getting frontend event\n");
        if ((status = ioctl(fd_frontend, (((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((78)) << 0) | ((((sizeof(struct dvb_frontend_event)))) << ((0 +8)+8))), &event)) < 0){
   if ((*__errno_location ()) != 75) {
     perror("FE_GET_EVENT");
     fprintf(stderr,"status = %d\n", status);
     fprintf(stderr,"errno = %d\n", (*__errno_location ()));
     return -1;
   }
   else fprintf(stderr,"Overflow error, trying again (status = %d, errno = %d)", status, (*__errno_location ()));
        }
      }
      print_status(stderr,event.status);
    }
  }
  if (event.status & FE_HAS_LOCK) {
      switch(type) {
         case FE_OFDM:
           fprintf(stderr,"Event:  Frequency: %d\n",event.parameters.frequency);
           break;
         case FE_QPSK:
           fprintf(stderr,"Event:  Frequency: %d\n",(unsigned int)((event.parameters.frequency)+(hi_lo ? (10600*1000UL) : (9750*1000UL))));
           fprintf(stderr,"        SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate);
           fprintf(stderr,"        FEC_inner:  %d\n",event.parameters.u.qpsk.fec_inner);
           fprintf(stderr,"\n");
           break;
         case FE_QAM:
           fprintf(stderr,"Event:  Frequency: %d\n",event.parameters.frequency);
           fprintf(stderr,"        SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate);
           fprintf(stderr,"        FEC_inner:  %d\n",event.parameters.u.qpsk.fec_inner);
           break;
         default:
           break;
      }
      strength=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((70)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))),&strength) >= 0)
      fprintf(stderr,"Bit error rate: %d\n",strength);
      strength=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((71)) << 0) | ((((sizeof(__u16)))) << ((0 +8)+8))),&strength) >= 0)
      fprintf(stderr,"Signal strength: %d\n",strength);
      strength=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((72)) << 0) | ((((sizeof(__u16)))) << ((0 +8)+8))),&strength) >= 0)
      fprintf(stderr,"SNR: %d\n",strength);
      festatus=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((69)) << 0) | ((((sizeof(fe_status_t)))) << ((0 +8)+8))),&festatus) >= 0)
      print_status(stderr,festatus);
    } else {
    fprintf(stderr,"Not able to lock to the signal on the given frequency\n");
    return -1;
  }
  return 0;
}

canonical_original_code:
int check_status(int fd_frontend, int type, struct dvb_frontend_parameters *feparams, int hi_lo) {
  int strength;
  enum fe_status festatus;
  struct dvb_frontend_event event;
  struct pollfd pfd[1];
  int status;
  while(1) {
 if (ioctl(fd_frontend, (((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((78)) << 0) | ((((sizeof(struct dvb_frontend_event)))) << ((0 +8)+8))), &event) < 0)
 break;
  }
  if (ioctl(fd_frontend,(((1U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((76)) << 0) | ((((sizeof(struct dvb_frontend_parameters)))) << ((0 +8)+8))),feparams) < 0) {
    perror("ERROR tuning channel\n");
    return -1;
  }
  pfd[0].fd = fd_frontend;
  pfd[0].events = 0x002;
  event.status=0;
  while (((event.status & FE_TIMEDOUT)==0) && ((event.status & FE_HAS_LOCK)==0)) {
    fprintf(stderr,"polling....\n");
    if (poll(pfd,1,10000) > 0){
      if (pfd[0].revents & 0x002){
        fprintf(stderr,"Getting frontend event\n");
        if ((status = ioctl(fd_frontend, (((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((78)) << 0) | ((((sizeof(struct dvb_frontend_event)))) << ((0 +8)+8))), &event)) < 0){
   if ((*__errno_location ()) != 75) {
     perror("FE_GET_EVENT");
     fprintf(stderr,"status = %d\n", status);
     fprintf(stderr,"errno = %d\n", (*__errno_location ()));
     return -1;
   }
   else fprintf(stderr,"Overflow error, trying again (status = %d, errno = %d)", status, (*__errno_location ()));
        }
      }
      print_status(stderr,event.status);
    }
  }
  if (event.status & FE_HAS_LOCK) {
      switch(type) {
         case FE_OFDM:
           fprintf(stderr,"Event:  Frequency: %d\n",event.parameters.frequency);
           break;
         case FE_QPSK:
           fprintf(stderr,"Event:  Frequency: %d\n",(unsigned int)((event.parameters.frequency)+(hi_lo ? (10600*1000UL) : (9750*1000UL))));
           fprintf(stderr,"        SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate);
           fprintf(stderr,"        FEC_inner:  %d\n",event.parameters.u.qpsk.fec_inner);
           fprintf(stderr,"\n");
           break;
         case FE_QAM:
           fprintf(stderr,"Event:  Frequency: %d\n",event.parameters.frequency);
           fprintf(stderr,"        SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate);
           fprintf(stderr,"        FEC_inner:  %d\n",event.parameters.u.qpsk.fec_inner);
           break;
         default:
           break;
      }
      strength=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((70)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))),&strength) >= 0)
      fprintf(stderr,"Bit error rate: %d\n",strength);
      strength=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((71)) << 0) | ((((sizeof(__u16)))) << ((0 +8)+8))),&strength) >= 0)
      fprintf(stderr,"Signal strength: %d\n",strength);
      strength=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((72)) << 0) | ((((sizeof(__u16)))) << ((0 +8)+8))),&strength) >= 0)
      fprintf(stderr,"SNR: %d\n",strength);
      festatus=0;
      if(ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((69)) << 0) | ((((sizeof(fe_status_t)))) << ((0 +8)+8))),&festatus) >= 0)
      print_status(stderr,festatus);
    } else {
    fprintf(stderr,"Not able to lock to the signal on the given frequency\n");
    return -1;
  }
  return 0;
}

variable_types: type int

variable_types: struct dvb_frontend_parameters { unsigned int frequency; enum fe_spectral_inversion { INVERSION_OFF=0, INVERSION_ON=1, INVERSION_AUTO=2 } inversion; union { struct dvb_qpsk_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; } qpsk; struct dvb_qam_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } qam; struct dvb_ofdm_parameters { enum fe_bandwidth { BANDWIDTH_8_MHZ=0, BANDWIDTH_7_MHZ=1, BANDWIDTH_6_MHZ=2, BANDWIDTH_AUTO=3, BANDWIDTH_5_MHZ=4, BANDWIDTH_10_MHZ=5, BANDWIDTH_1_712_MHZ=6 } bandwidth; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_HP; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_LP; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } constellation; enum fe_transmit_mode { TRANSMISSION_MODE_2K=0, TRANSMISSION_MODE_8K=1, TRANSMISSION_MODE_AUTO=2, TRANSMISSION_MODE_4K=3, TRANSMISSION_MODE_1K=4, TRANSMISSION_MODE_16K=5, TRANSMISSION_MODE_32K=6, TRANSMISSION_MODE_C1=7, TRANSMISSION_MODE_C3780=8 } transmission_mode; enum fe_guard_interval { GUARD_INTERVAL_1_32=0, GUARD_INTERVAL_1_16=1, GUARD_INTERVAL_1_8=2, GUARD_INTERVAL_1_4=3, GUARD_INTERVAL_AUTO=4, GUARD_INTERVAL_1_128=5, GUARD_INTERVAL_19_128=6, GUARD_INTERVAL_19_256=7, GUARD_INTERVAL_PN420=8, GUARD_INTERVAL_PN595=9, GUARD_INTERVAL_PN945=10 } guard_interval; enum fe_hierarchy { HIERARCHY_NONE=0, HIERARCHY_1=1, HIERARCHY_2=2, HIERARCHY_4=3, HIERARCHY_AUTO=4 } hierarchy_information; } ofdm; struct dvb_vsb_parameters { enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } vsb; } u; } *

variable_types: strength int

variable_types: struct dvb_frontend_event { enum fe_status { FE_NONE=0, FE_HAS_SIGNAL=1, FE_HAS_CARRIER=2, FE_HAS_VITERBI=4, FE_HAS_SYNC=8, FE_HAS_LOCK=16, FE_TIMEDOUT=32, FE_REINIT=64 } status; struct dvb_frontend_parameters { unsigned int frequency; enum fe_spectral_inversion { INVERSION_OFF=0, INVERSION_ON=1, INVERSION_AUTO=2 } inversion; union { struct dvb_qpsk_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; } qpsk; struct dvb_qam_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } qam; struct dvb_ofdm_parameters { enum fe_bandwidth { BANDWIDTH_8_MHZ=0, BANDWIDTH_7_MHZ=1, BANDWIDTH_6_MHZ=2, BANDWIDTH_AUTO=3, BANDWIDTH_5_MHZ=4, BANDWIDTH_10_MHZ=5, BANDWIDTH_1_712_MHZ=6 } bandwidth; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_HP; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_LP; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } constellation; enum fe_transmit_mode { TRANSMISSION_MODE_2K=0, TRANSMISSION_MODE_8K=1, TRANSMISSION_MODE_AUTO=2, TRANSMISSION_MODE_4K=3, TRANSMISSION_MODE_1K=4, TRANSMISSION_MODE_16K=5, TRANSMISSION_MODE_32K=6, TRANSMISSION_MODE_C1=7, TRANSMISSION_MODE_C3780=8 } transmission_mode; enum fe_guard_interval { GUARD_INTERVAL_1_32=0, GUARD_INTERVAL_1_16=1, GUARD_INTERVAL_1_8=2, GUARD_INTERVAL_1_4=3, GUARD_INTERVAL_AUTO=4, GUARD_INTERVAL_1_128=5, GUARD_INTERVAL_19_128=6, GUARD_INTERVAL_19_256=7, GUARD_INTERVAL_PN420=8, GUARD_INTERVAL_PN595=9, GUARD_INTERVAL_PN945=10 } guard_interval; enum fe_hierarchy { HIERARCHY_NONE=0, HIERARCHY_1=1, HIERARCHY_2=2, HIERARCHY_4=3, HIERARCHY_AUTO=4 } hierarchy_information; } ofdm; struct dvb_vsb_parameters { enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } vsb; } u; } parameters; }

variable_types: struct pollfd { int fd; short events; short revents; } [1]

variable_types: status int

user_defined_types: struct dvb_frontend_event { enum fe_status status; struct dvb_frontend_parameters parameters; }

user_defined_types: struct dvb_frontend_parameters { unsigned int frequency; enum fe_spectral_inversion inversion; union { struct dvb_qpsk_parameters qpsk; struct dvb_qam_parameters qam; struct dvb_ofdm_parameters ofdm; struct dvb_vsb_parameters vsb; } u; }

user_defined_types: struct dvb_qpsk_parameters { unsigned int symbol_rate; enum fe_code_rate fec_inner; }

user_defined_types: struct dvb_qam_parameters { unsigned int symbol_rate; enum fe_code_rate fec_inner; enum fe_modulation modulation; }

user_defined_types: struct dvb_ofdm_parameters { enum fe_bandwidth bandwidth; enum fe_code_rate code_rate_HP; enum fe_code_rate code_rate_LP; enum fe_modulation constellation; enum fe_transmit_mode transmission_mode; enum fe_guard_interval guard_interval; enum fe_hierarchy hierarchy_information; }

user_defined_types: struct dvb_vsb_parameters { enum fe_modulation modulation; }


decompiled_code:
__int64 __fastcall tune_it(int fd, unsigned int a2, unsigned int a3, char a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12)
{
unsigned int v12; // ebx
__int64 result; // rax
unsigned int v16; // ebx
const __int32_t **v17; // r15
__int32_t v18; // er14
__int64 v19; // rdx
const char *v20; // r9
char v23[128]; // [rsp+10h] [rbp-118h] BYREF
int v24; // [rsp+90h] [rbp-98h]
unsigned int v25; // [rsp+C0h] [rbp-68h] BYREF
int v26; // [rsp+C4h] [rbp-64h]
unsigned int v27; // [rsp+C8h] [rbp-60h]
int v28; // [rsp+CCh] [rbp-5Ch]
int v29; // [rsp+D0h] [rbp-58h]
int v30; // [rsp+D4h] [rbp-54h]
int v31; // [rsp+D8h] [rbp-50h]
int v32; // [rsp+DCh] [rbp-4Ch]
int v33; // [rsp+E0h] [rbp-48h]

v12 = a2;
if ( ioctl(fd, 0x80A86F3DuLL, v23) < 0 )
{
perror("FE_GET_INFO: ");
result = 0xFFFFFFFFLL;
}
else
{
fprintf(stderr, "Using DVB card \"%s\"\n", v23);
if ( v24 == 1 )
{
fprintf(stderr, "tuning DVB-C to %d, srate=%d\n", a2, a3);
v25 = a2;
v26 = 0;
v27 = a3;
v28 = 9;
v29 = a8;
v16 = 0;
}
else if ( v24 == 2 )
{
if ( a2 <= 0xF423F )
v12 = 1000 * a2;
v25 = v12;
v26 = 0;
v27 = a12;
v28 = a9;
v29 = 0;
v30 = a8;
v31 = a10;
v32 = a11;
v33 = 0;
fprintf(stderr, "tuning DVB-T (%s) to %u Hz, Bandwidth: %d\n", "in United Kingdom", v12, (unsigned int)a12);
v16 = 0;
}
else
{
if ( v24 )
{
fwrite("Unknown FE type. Aborting\n", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
v17 = _ctype_toupper_loc();
v18 = (*v17)[a4];
if ( a2 > 0xB2871F )
{
v19 = a2 - 10600000;
v16 = 1;
}
else
{
v19 = a2 - 9750000;
v16 = 0;
}
v25 = v19;
v20 = "on";
if ( a5 )
v20 = "off";
fprintf(
stderr,
"tuning DVB-S to Freq: %u, Pol:%c Srate=%d, 22kHz tone=%s, LNB: %d\n",
v19,
(unsigned int)(char)v18,
a3,
v20,
(unsigned __int8)a7);
v26 = a6;
v27 = a3;
v28 = 9;
setup_switch((unsigned int)fd, (unsigned int)(unsigned __int8)a7 - 1, (*v17)[(char)v18] != 86, v16, 0LL);
usleep(0xC350u);
}
usleep(0x186A0u);
result = check_status(fd, v24, (__int64)&v25, v16);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, unsigned int a2, unsigned int a3, char a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12)
{
unsigned int v12; // ebx
__int64 result; // rax
unsigned int v16; // ebx
const __int32_t **v17; // r15
__int32_t v18; // er14
__int64 v19; // rdx
const char *v20; // r9
char v23[128]; // [rsp+10h] [rbp-118h] BYREF
int v24; // [rsp+90h] [rbp-98h]
unsigned int v25; // [rsp+C0h] [rbp-68h] BYREF
int v26; // [rsp+C4h] [rbp-64h]
unsigned int v27; // [rsp+C8h] [rbp-60h]
int v28; // [rsp+CCh] [rbp-5Ch]
int v29; // [rsp+D0h] [rbp-58h]
int v30; // [rsp+D4h] [rbp-54h]
int v31; // [rsp+D8h] [rbp-50h]
int v32; // [rsp+DCh] [rbp-4Ch]
int v33; // [rsp+E0h] [rbp-48h]

v12 = a2;
if ( ioctl(fd, 0x80A86F3DuLL, v23) < 0 )
{
perror("FE_GET_INFO: ");
result = 0xFFFFFFFFLL;
}
else
{
fprintf(stderr, "Using DVB card \"%s\"\n", v23);
if ( v24 == 1 )
{
fprintf(stderr, "tuning DVB-C to %d, srate=%d\n", a2, a3);
v25 = a2;
v26 = 0;
v27 = a3;
v28 = 9;
v29 = a8;
v16 = 0;
}
else if ( v24 == 2 )
{
if ( a2 <= 0xF423F )
v12 = 1000 * a2;
v25 = v12;
v26 = 0;
v27 = a12;
v28 = a9;
v29 = 0;
v30 = a8;
v31 = a10;
v32 = a11;
v33 = 0;
fprintf(stderr, "tuning DVB-T (%s) to %u Hz, Bandwidth: %d\n", "in United Kingdom", v12, (unsigned int)a12);
v16 = 0;
}
else
{
if ( v24 )
{
fwrite("Unknown FE type. Aborting\n", 1uLL, 0x1AuLL, stderr);
exit(-1);
}
v17 = _ctype_toupper_loc();
v18 = (*v17)[a4];
if ( a2 > 0xB2871F )
{
v19 = a2 - 10600000;
v16 = 1;
}
else
{
v19 = a2 - 9750000;
v16 = 0;
}
v25 = v19;
v20 = "on";
if ( a5 )
v20 = "off";
fprintf(
stderr,
"tuning DVB-S to Freq: %u, Pol:%c Srate=%d, 22kHz tone=%s, LNB: %d\n",
v19,
(unsigned int)(char)v18,
a3,
v20,
(unsigned __int8)a7);
v26 = a6;
v27 = a3;
v28 = 9;
setup_switch((unsigned int)fd, (unsigned int)(unsigned __int8)a7 - 1, (*v17)[(char)v18] != 86, v16, 0LL);
usleep(0xC350u);
}
usleep(0x186A0u);
result = func1(fd, v24, (__int64)&v25, v16);
}
return result;
}

original_code:
int tune_it(int fd_frontend, unsigned int freq, unsigned int srate, char pol, int tone, fe_spectral_inversion_t specInv, unsigned char diseqc,fe_modulation_t modulation,fe_code_rate_t HP_CodeRate,fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth) {
  int res;
  struct dvb_frontend_parameters feparams;
  int hiband = 0;
  static int uncommitted_switch_pos = 0;
  struct dvb_frontend_info fe_info;
  uint32_t if_freq = 0;
  if ( (res = ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((61)) << 0) | ((((sizeof(struct dvb_frontend_info)))) << ((0 +8)+8))), &fe_info) < 0)){
     perror("FE_GET_INFO: ");
     return -1;
  }
  fprintf(stderr,"Using DVB card \"%s\"\n",fe_info.name);
  switch(fe_info.type) {
    case FE_OFDM:
      if (freq < 1000000) freq*=1000UL;
      feparams.frequency=freq;
      feparams.inversion=INVERSION_OFF;
      feparams.u.ofdm.bandwidth=bandwidth;
      feparams.u.ofdm.code_rate_HP=HP_CodeRate;
      feparams.u.ofdm.code_rate_LP=(0);
      feparams.u.ofdm.constellation=modulation;
      feparams.u.ofdm.transmission_mode=TransmissionMode;
      feparams.u.ofdm.guard_interval=guardInterval;
      feparams.u.ofdm.hierarchy_information=HIERARCHY_NONE;
      fprintf(stderr,"tuning DVB-T (%s) to %u Hz, Bandwidth: %d\n","in United Kingdom",freq, bandwidth);
      break;
    case FE_QPSK:
      pol = toupper(pol);
      if (freq < (11700*1000UL)) {
        feparams.frequency=(freq-(9750*1000UL));
        hiband = 0;
      } else {
        feparams.frequency=(freq-(10600*1000UL));
        hiband = 1;
      }
      fprintf(stderr,"tuning DVB-S to Freq: %u, Pol:%c Srate=%d, 22kHz tone=%s, LNB: %d\n",feparams.frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off", diseqc);
      feparams.inversion=specInv;
      feparams.u.qpsk.symbol_rate=srate;
      feparams.u.qpsk.fec_inner=FEC_AUTO;
      setup_switch (fd_frontend,
                   diseqc-1,
                   (toupper(pol)=='V' ? 0 : 1),
                   hiband,
                   uncommitted_switch_pos);
      usleep(50000);
      break;
    case FE_QAM:
      fprintf(stderr,"tuning DVB-C to %d, srate=%d\n",freq,srate);
      feparams.frequency=freq;
      feparams.inversion=INVERSION_OFF;
      feparams.u.qam.symbol_rate = srate;
      feparams.u.qam.fec_inner = FEC_AUTO;
      feparams.u.qam.modulation = modulation;
      break;
    default:
      fprintf(stderr,"Unknown FE type. Aborting\n");
      exit(-1);
  }
  usleep(100000);
  return(check_status(fd_frontend,fe_info.type,&feparams,hiband));
}

canonical_original_code:
int tune_it(int fd_frontend, unsigned int freq, unsigned int srate, char pol, int tone, enum fe_spectral_inversion specInv, unsigned char diseqc, enum fe_modulation modulation, enum fe_code_rate HP_CodeRate, enum fe_transmit_mode TransmissionMode, enum fe_guard_interval guardInterval, enum fe_bandwidth bandwidth) {
  int res;
  struct dvb_frontend_parameters feparams;
  int hiband = 0;
  static int uncommitted_switch_pos = 0;
  struct dvb_frontend_info fe_info;
  unsigned int if_freq = 0;
  if ( (res = ioctl(fd_frontend,(((2U) << (((0 +8)+8)+14)) | ((('o')) << (0 +8)) | (((61)) << 0) | ((((sizeof(struct dvb_frontend_info)))) << ((0 +8)+8))), &fe_info) < 0)){
     perror("FE_GET_INFO: ");
     return -1;
  }
  fprintf(stderr,"Using DVB card \"%s\"\n",fe_info.name);
  switch(fe_info.type) {
    case FE_OFDM:
      if (freq < 1000000) freq*=1000UL;
      feparams.frequency=freq;
      feparams.inversion=INVERSION_OFF;
      feparams.u.ofdm.bandwidth=bandwidth;
      feparams.u.ofdm.code_rate_HP=HP_CodeRate;
      feparams.u.ofdm.code_rate_LP=(0);
      feparams.u.ofdm.constellation=modulation;
      feparams.u.ofdm.transmission_mode=TransmissionMode;
      feparams.u.ofdm.guard_interval=guardInterval;
      feparams.u.ofdm.hierarchy_information=HIERARCHY_NONE;
      fprintf(stderr,"tuning DVB-T (%s) to %u Hz, Bandwidth: %d\n","in United Kingdom",freq, bandwidth);
      break;
    case FE_QPSK:
      pol = toupper(pol);
      if (freq < (11700*1000UL)) {
        feparams.frequency=(freq-(9750*1000UL));
        hiband = 0;
      } else {
        feparams.frequency=(freq-(10600*1000UL));
        hiband = 1;
      }
      fprintf(stderr,"tuning DVB-S to Freq: %u, Pol:%c Srate=%d, 22kHz tone=%s, LNB: %d\n",feparams.frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off", diseqc);
      feparams.inversion=specInv;
      feparams.u.qpsk.symbol_rate=srate;
      feparams.u.qpsk.fec_inner=FEC_AUTO;
      setup_switch (fd_frontend,
                   diseqc-1,
                   (toupper(pol)=='V' ? 0 : 1),
                   hiband,
                   uncommitted_switch_pos);
      usleep(50000);
      break;
    case FE_QAM:
      fprintf(stderr,"tuning DVB-C to %d, srate=%d\n",freq,srate);
      feparams.frequency=freq;
      feparams.inversion=INVERSION_OFF;
      feparams.u.qam.symbol_rate = srate;
      feparams.u.qam.fec_inner = FEC_AUTO;
      feparams.u.qam.modulation = modulation;
      break;
    default:
      fprintf(stderr,"Unknown FE type. Aborting\n");
      exit(-1);
  }
  usleep(100000);
  return(check_status(fd_frontend,fe_info.type,&feparams,hiband));
}

variable_types:
freq
unsigned int

variable_types:
srate
unsigned int

variable_types: pol char

variable_types: tone int

variable_types:
diseqc
unsigned char

variable_types: res int

variable_types: struct dvb_frontend_parameters { unsigned int frequency; enum fe_spectral_inversion { INVERSION_OFF=0, INVERSION_ON=1, INVERSION_AUTO=2 } inversion; union { struct dvb_qpsk_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; } qpsk; struct dvb_qam_parameters { unsigned int symbol_rate; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } fec_inner; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } qam; struct dvb_ofdm_parameters { enum fe_bandwidth { BANDWIDTH_8_MHZ=0, BANDWIDTH_7_MHZ=1, BANDWIDTH_6_MHZ=2, BANDWIDTH_AUTO=3, BANDWIDTH_5_MHZ=4, BANDWIDTH_10_MHZ=5, BANDWIDTH_1_712_MHZ=6 } bandwidth; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_HP; enum fe_code_rate { FEC_NONE=0, FEC_1_2=1, FEC_2_3=2, FEC_3_4=3, FEC_4_5=4, FEC_5_6=5, FEC_6_7=6, FEC_7_8=7, FEC_8_9=8, FEC_AUTO=9, FEC_3_5=10, FEC_9_10=11, FEC_2_5=12 } code_rate_LP; enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } constellation; enum fe_transmit_mode { TRANSMISSION_MODE_2K=0, TRANSMISSION_MODE_8K=1, TRANSMISSION_MODE_AUTO=2, TRANSMISSION_MODE_4K=3, TRANSMISSION_MODE_1K=4, TRANSMISSION_MODE_16K=5, TRANSMISSION_MODE_32K=6, TRANSMISSION_MODE_C1=7, TRANSMISSION_MODE_C3780=8 } transmission_mode; enum fe_guard_interval { GUARD_INTERVAL_1_32=0, GUARD_INTERVAL_1_16=1, GUARD_INTERVAL_1_8=2, GUARD_INTERVAL_1_4=3, GUARD_INTERVAL_AUTO=4, GUARD_INTERVAL_1_128=5, GUARD_INTERVAL_19_128=6, GUARD_INTERVAL_19_256=7, GUARD_INTERVAL_PN420=8, GUARD_INTERVAL_PN595=9, GUARD_INTERVAL_PN945=10 } guard_interval; enum fe_hierarchy { HIERARCHY_NONE=0, HIERARCHY_1=1, HIERARCHY_2=2, HIERARCHY_4=3, HIERARCHY_AUTO=4 } hierarchy_information; } ofdm; struct dvb_vsb_parameters { enum fe_modulation { QPSK=0, QAM_16=1, QAM_32=2, QAM_64=3, QAM_128=4, QAM_256=5, QAM_AUTO=6, VSB_8=7, VSB_16=8, PSK_8=9, APSK_16=10, APSK_32=11, DQPSK=12, QAM_4_NR=13 } modulation; } vsb; } u; }

variable_types: hiband int

variable_types: struct dvb_frontend_info { char name[128]; enum fe_type { FE_QPSK=0, FE_QAM=1, FE_OFDM=2, FE_ATSC=3 } type; unsigned int frequency_min; unsigned int frequency_max; unsigned int frequency_stepsize; unsigned int frequency_tolerance; unsigned int symbol_rate_min; unsigned int symbol_rate_max; unsigned int symbol_rate_tolerance; unsigned int notifier_delay; enum fe_caps { FE_IS_STUPID=0, FE_CAN_INVERSION_AUTO=1, FE_CAN_FEC_1_2=2, FE_CAN_FEC_2_3=4, FE_CAN_FEC_3_4=8, FE_CAN_FEC_4_5=16, FE_CAN_FEC_5_6=32, FE_CAN_FEC_6_7=64, FE_CAN_FEC_7_8=128, FE_CAN_FEC_8_9=256, FE_CAN_FEC_AUTO=512, FE_CAN_QPSK=1024, FE_CAN_QAM_16=2048, FE_CAN_QAM_32=4096, FE_CAN_QAM_64=8192, FE_CAN_QAM_128=16384, FE_CAN_QAM_256=32768, FE_CAN_QAM_AUTO=65536, FE_CAN_TRANSMISSION_MODE_AUTO=131072, FE_CAN_BANDWIDTH_AUTO=262144, FE_CAN_GUARD_INTERVAL_AUTO=524288, FE_CAN_HIERARCHY_AUTO=1048576, FE_CAN_8VSB=2097152, FE_CAN_16VSB=4194304, FE_HAS_EXTENDED_CAPS=8388608, FE_CAN_MULTISTREAM=67108864, FE_CAN_TURBO_FEC=134217728, FE_CAN_2G_MODULATION=268435456, FE_NEEDS_BENDING=536870912, FE_CAN_RECOVER=1073741824, FE_CAN_MUTE_TS=2147483648 } caps; }

user_defined_types: struct dvb_frontend_info { char name[128]; enum fe_type type; unsigned int frequency_min; unsigned int frequency_max; unsigned int frequency_stepsize; unsigned int frequency_tolerance; unsigned int symbol_rate_min; unsigned int symbol_rate_max; unsigned int symbol_rate_tolerance; unsigned int notifier_delay; enum fe_caps caps; }


decompiled_code:
size_t __fastcall freesat_huffman_to_string(_BYTE *a1, int a2, __int64 a3, unsigned int a4)
{
char v5; // al
size_t result; // rax
bool v8; // zf
_DWORD *v9; // r12
char *v10; // rax
int v11; // ecx
unsigned int v12; // er9
unsigned int v13; // edi
unsigned __int8 v14; // dl
int v15; // er8
int v16; // er14
unsigned __int8 v17; // cl
int v18; // esi
unsigned int v19; // ecx
unsigned int v20; // eax
char *v21; // r10
unsigned __int64 v22; // r15
int v23; // ecx
int v24; // edx
char *v26; // [rsp+10h] [rbp-48h]

v5 = *(_BYTE *)(a3 + 1);
if ( (unsigned __int8)(v5 - 1) <= 1u )
{
v8 = v5 == 1;
v9 = &fsat_index_1;
if ( v5 != 1 )
v9 = &fsat_index_2;
v10 = (char *)&fsat_table_2;
if ( v8 )
v10 = (char *)&fsat_table_1;
v26 = v10;
memset(a1, 0, a2);
if ( a4 <= 2 )
{
v12 = 2;
v13 = 0;
}
else
{
v11 = 24;
v12 = 2;
v13 = 0;
do
{
v13 |= *(unsigned __int8 *)(a3 + v12++) << v11;
v11 -= 8;
}
while ( v12 <= 5 && v12 < a4 );
}
v14 = 0;
v15 = 0;
v16 = 0;
while ( 1 )
{
if ( v14 == 1 )
{
result = HIBYTE(v13);
if ( (v13 & 0x80000000) != 0 )
{
v17 = HIBYTE(v13);
v18 = 8;
goto LABEL_37;
}
if ( SHIBYTE(v13) > 31 )
{
v17 = HIBYTE(v13);
v14 = HIBYTE(v13);
v18 = 8;
LABEL_37:
result = v16;
a1[v16++] = v17;
goto LABEL_38;
}
v14 = 0;
v18 = 8;
}
else
{
v19 = v9[(char)v14];
v20 = v9[(char)v14 + 1];
if ( v19 >= v20 )
return fwrite("ERROR: Missing in table\n", 1uLL, 0x18uLL, stderr);
v21 = &v26[8 * v19];
v22 = (unsigned __int64)&v26[8 * (v20 - v19) + 8 * (unsigned __int64)v19];
while ( 1 )
{
LOWORD(v18) = *((_WORD *)v21 + 2);
v24 = 0;
result = 0x80000000LL;
v23 = 0;
if ( (__int16)v18 > 0 )
{
do
{
v23 |= result;
result = (unsigned int)result >> 1;
++v24;
}
while ( (_WORD)v24 != (_WORD)v18 );
}
if ( (v13 & v23) == *(_DWORD *)v21 )
break;
v21 += 8;
if ( v21 == (char *)v22 )
return fwrite("ERROR: Missing in table\n", 1uLL, 0x18uLL, stderr);
}
v14 = v21[6];
v18 = (__int16)v18;
v17 = v14;
if ( v14 > 1u )
goto LABEL_37;
}
LABEL_38:
if ( v18 )
{
LODWORD(result) = 0;
do
{
v13 *= 2;
if ( a4 > v12 )
v13 |= ((int)*(unsigned __int8 *)(a3 + v12) >> (7 - v15)) & 1;
if ( v15 == 7 )
{
++v12;
v15 = 0;
}
else
{
++v15;
}
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v18 );
}
if ( !v14 || a4 + 4 <= v12 )
return result;
}
}
result = (size_t)a1;
*a1 = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(_BYTE *a1, int a2, __int64 a3, unsigned int a4)
{
char v5; // al
size_t result; // rax
bool v8; // zf
_DWORD *v9; // r12
char *v10; // rax
int v11; // ecx
unsigned int v12; // er9
unsigned int v13; // edi
unsigned __int8 v14; // dl
int v15; // er8
int v16; // er14
unsigned __int8 v17; // cl
int v18; // esi
unsigned int v19; // ecx
unsigned int v20; // eax
char *v21; // r10
unsigned __int64 v22; // r15
int v23; // ecx
int v24; // edx
char *v26; // [rsp+10h] [rbp-48h]

v5 = *(_BYTE *)(a3 + 1);
if ( (unsigned __int8)(v5 - 1) <= 1u )
{
v8 = v5 == 1;
v9 = &fsat_index_1;
if ( v5 != 1 )
v9 = &fsat_index_2;
v10 = (char *)&fsat_table_2;
if ( v8 )
v10 = (char *)&fsat_table_1;
v26 = v10;
memset(a1, 0, a2);
if ( a4 <= 2 )
{
v12 = 2;
v13 = 0;
}
else
{
v11 = 24;
v12 = 2;
v13 = 0;
do
{
v13 |= *(unsigned __int8 *)(a3 + v12++) << v11;
v11 -= 8;
}
while ( v12 <= 5 && v12 < a4 );
}
v14 = 0;
v15 = 0;
v16 = 0;
while ( 1 )
{
if ( v14 == 1 )
{
result = HIBYTE(v13);
if ( (v13 & 0x80000000) != 0 )
{
v17 = HIBYTE(v13);
v18 = 8;
goto LABEL_37;
}
if ( SHIBYTE(v13) > 31 )
{
v17 = HIBYTE(v13);
v14 = HIBYTE(v13);
v18 = 8;
LABEL_37:
result = v16;
a1[v16++] = v17;
goto LABEL_38;
}
v14 = 0;
v18 = 8;
}
else
{
v19 = v9[(char)v14];
v20 = v9[(char)v14 + 1];
if ( v19 >= v20 )
return fwrite("ERROR: Missing in table\n", 1uLL, 0x18uLL, stderr);
v21 = &v26[8 * v19];
v22 = (unsigned __int64)&v26[8 * (v20 - v19) + 8 * (unsigned __int64)v19];
while ( 1 )
{
LOWORD(v18) = *((_WORD *)v21 + 2);
v24 = 0;
result = 0x80000000LL;
v23 = 0;
if ( (__int16)v18 > 0 )
{
do
{
v23 |= result;
result = (unsigned int)result >> 1;
++v24;
}
while ( (_WORD)v24 != (_WORD)v18 );
}
if ( (v13 & v23) == *(_DWORD *)v21 )
break;
v21 += 8;
if ( v21 == (char *)v22 )
return fwrite("ERROR: Missing in table\n", 1uLL, 0x18uLL, stderr);
}
v14 = v21[6];
v18 = (__int16)v18;
v17 = v14;
if ( v14 > 1u )
goto LABEL_37;
}
LABEL_38:
if ( v18 )
{
LODWORD(result) = 0;
do
{
v13 *= 2;
if ( a4 > v12 )
v13 |= ((int)*(unsigned __int8 *)(a3 + v12) >> (7 - v15)) & 1;
if ( v15 == 7 )
{
++v12;
v15 = 0;
}
else
{
++v15;
}
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v18 );
}
if ( !v14 || a4 + 4 <= v12 )
return result;
}
}
result = (size_t)a1;
*a1 = 0;
return result;
}

original_code:
void freesat_huffman_to_string(unsigned char* uncompressed, int outsize, const unsigned char *src, int size)
{
    struct fsattab *fsat_table;
    unsigned int *fsat_index;
    if (src[1] == 1 || src[1] == 2)
    {
        if (src[1] == 1)
        {
            fsat_table = fsat_table_1;
            fsat_index = fsat_index_1;
        } else {
            fsat_table = fsat_table_2;
            fsat_index = fsat_index_2;
        }
        memset(uncompressed,0,outsize);
        int p = 0;
        unsigned value = 0, byte = 2, bit = 0;
        while (byte < 6 && byte < size)
        {
            value |= src[byte] << ((5-byte) * 8);
            byte++;
        }
        char lastch = '\0';
        do
        {
            _Bool found = 0;
            unsigned bitShift = 0;
            char nextCh = '\0';
            if (lastch == '\1')
            {
                found = 1;
                nextCh = (value >> 24) & 0xff;
                bitShift = 8;
                if ((nextCh & 0x80) == 0)
                {
                    if (nextCh < ' ')
                        nextCh = '\0';
                    lastch = nextCh;
                }
            }
            else
            {
                unsigned indx = (unsigned)lastch;
                unsigned j;
                for (j = fsat_index[indx]; j < fsat_index[indx+1]; j++)
                {
                    unsigned mask = 0, maskbit = 0x80000000;
                    short kk;
                    for (kk = 0; kk < fsat_table[j].bits; kk++)
                    {
                        mask |= maskbit;
                        maskbit >>= 1;
                    }
                    if ((value & mask) == fsat_table[j].value)
                    {
                        nextCh = fsat_table[j].next;
                        bitShift = fsat_table[j].bits;
                        found = 1;
                        lastch = nextCh;
                        break;
                    }
                }
            }
            if (found)
            {
                if (nextCh != '\0' && nextCh != '\1')
                {
                    uncompressed[p++] = nextCh;
                }
                unsigned b;
                for (b = 0; b < bitShift; b++)
                {
                    value = (value << 1) & 0xfffffffe;
                    if (byte < size)
                        value |= (src[byte] >> (7-bit)) & 1;
                    if (bit == 7)
                    {
                        bit = 0;
                        byte++;
                    }
                    else bit++;
                }
            }
            else
            {
         fprintf(stderr,"ERROR: Missing in table\n");
                return;
            }
        } while (lastch != '\0' && byte < size+4);
        return;
    } else {
      uncompressed[0] = 0;
    }
}

canonical_original_code:
void freesat_huffman_to_string(unsigned char *uncompressed, int outsize, unsigned char *src, int size)
{
    struct fsattab *fsat_table;
    unsigned int *fsat_index;
    if (src[1] == 1 || src[1] == 2)
    {
        if (src[1] == 1)
        {
            fsat_table = fsat_table_1;
            fsat_index = fsat_index_1;
        } else {
            fsat_table = fsat_table_2;
            fsat_index = fsat_index_2;
        }
        memset(uncompressed,0,outsize);
        int p = 0;
        unsigned int value = 0; unsigned int byte = 2; unsigned int bit = 0;
        while (byte < 6 && byte < size)
        {
            value |= src[byte] << ((5-byte) * 8);
            byte++;
        }
        char lastch = '\0';
        do
        {
            _Bool found = 0;
            unsigned int bitShift = 0;
            char nextCh = '\0';
            if (lastch == '\1')
            {
                found = 1;
                nextCh = (value >> 24) & 0xff;
                bitShift = 8;
                if ((nextCh & 0x80) == 0)
                {
                    if (nextCh < ' ')
                        nextCh = '\0';
                    lastch = nextCh;
                }
            }
            else
            {
                unsigned int indx = (unsigned)lastch;
                unsigned int j;
                for (j = fsat_index[indx]; j < fsat_index[indx+1]; j++)
                {
                    unsigned int mask = 0; unsigned int maskbit = 0x80000000;
                    short kk;
                    for (kk = 0; kk < fsat_table[j].bits; kk++)
                    {
                        mask |= maskbit;
                        maskbit >>= 1;
                    }
                    if ((value & mask) == fsat_table[j].value)
                    {
                        nextCh = fsat_table[j].next;
                        bitShift = fsat_table[j].bits;
                        found = 1;
                        lastch = nextCh;
                        break;
                    }
                }
            }
            if (found)
            {
                if (nextCh != '\0' && nextCh != '\1')
                {
                    uncompressed[p++] = nextCh;
                }
                unsigned int b;
                for (b = 0; b < bitShift; b++)
                {
                    value = (value << 1) & 0xfffffffe;
                    if (byte < size)
                        value |= (src[byte] >> (7-bit)) & 1;
                    if (bit == 7)
                    {
                        bit = 0;
                        byte++;
                    }
                    else bit++;
                }
            }
            else
            {
         fprintf(stderr,"ERROR: Missing in table\n");
                return;
            }
        } while (lastch != '\0' && byte < size+4);
        return;
    } else {
      uncompressed[0] = 0;
    }
}

variable_types:
uncompressed
unsigned char *

variable_types: outsize int

variable_types:
src
unsigned char *

variable_types: size int

variable_types: struct fsattab { unsigned int value; short bits; char next; } *

variable_types: p int

variable_types:
value
unsigned int

variable_types:
byte
unsigned int

variable_types:
bit
unsigned int

variable_types: lastch char

variable_types:
bitShift
unsigned int

variable_types: nextCh char

variable_types:
indx
unsigned int

variable_types:
j
unsigned int

variable_types:
mask
unsigned int

variable_types:
maskbit
unsigned int

variable_types: kk short

variable_types:
b
unsigned int


decompiled_code:
__int64 __fastcall diseqc_send_msg(int fd, unsigned int a2, _QWORD *a3, unsigned int a4, unsigned int a5)
{
unsigned int v8; // ebx

v8 = ioctl(fd, 0x6F42uLL, 1LL);
if ( !v8 )
{
v8 = ioctl(fd, 0x6F43uLL, a2);
if ( !v8 )
{
msleep(0xFu);
if ( *a3 )
{
while ( 1 )
{
v8 = ioctl(fd, 0x40076F3FuLL);
if ( v8 )
break;
if ( !*++a3 )
goto LABEL_7;
}
}
else
{
LABEL_7:
msleep(0xFu);
v8 = ioctl(fd, 0x6F41uLL, a5);
if ( !v8 )
{
msleep(0xFu);
v8 = ioctl(fd, 0x6F42uLL, a4);
msleep(0xFu);
}
}
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, unsigned int a2, _QWORD *a3, unsigned int a4, unsigned int a5)
{
unsigned int v8; // ebx

v8 = ioctl(fd, 0x6F42uLL, 1LL);
if ( !v8 )
{
v8 = ioctl(fd, 0x6F43uLL, a2);
if ( !v8 )
{
func0(0xFu);
if ( *a3 )
{
while ( 1 )
{
v8 = ioctl(fd, 0x40076F3FuLL);
if ( v8 )
break;
if ( !*++a3 )
goto LABEL_7;
}
}
else
{
LABEL_7:
func0(0xFu);
v8 = ioctl(fd, 0x6F41uLL, a5);
if ( !v8 )
{
func0(0xFu);
v8 = ioctl(fd, 0x6F42uLL, a4);
func0(0xFu);
}
}
}
}
return v8;
}

variable_types: fd int

variable_types: enum fe_sec_voltage { SEC_VOLTAGE_13=0, SEC_VOLTAGE_18=1, SEC_VOLTAGE_OFF=2 }

variable_types: struct diseqc_cmd { struct dvb_diseqc_master_cmd { unsigned char msg[6]; unsigned char msg_len; } cmd; unsigned int wait; } **

variable_types: enum fe_sec_tone_mode { SEC_TONE_ON=0, SEC_TONE_OFF=1 }

variable_types: enum fe_sec_mini_cmd { SEC_MINI_A=0, SEC_MINI_B=1 }

variable_types: err int

user_defined_types: struct diseqc_cmd { struct dvb_diseqc_master_cmd cmd; unsigned int wait; }


decompiled_code:
__int64 __fastcall setup_switch(int fd, int a2, int a3, int a4, unsigned int a5)
{
_BOOL4 v6; // er14
_BOOL4 v7; // er13
unsigned int v8; // eax
__int64 v10[9]; // [rsp+0h] [rbp-48h] BYREF

v10[1] = 0LL;
if ( a5 > 0xF )
return 4294967274LL;
v10[0] = (__int64)&uncommitted_switch_cmds + 12 * (int)a5;
v6 = a4 == 0;
v7 = a3 != 0;
diseqc_send_msg(fd, v7, v10, v6, a2 & 1);
v8 = v7 + 2 * (a4 + 2 * a2);
if ( v8 > 0xF )
return 4294967274LL;
v10[0] = (__int64)&committed_switch_cmds + 12 * (int)v8;
return diseqc_send_msg(fd, v7, v10, v6, a2 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, int a2, int a3, int a4, unsigned int a5)
{
_BOOL4 v6; // er14
_BOOL4 v7; // er13
unsigned int v8; // eax
__int64 v10[9]; // [rsp+0h] [rbp-48h] BYREF

v10[1] = 0LL;
if ( a5 > 0xF )
return 4294967274LL;
v10[0] = (__int64)&uncommitted_switch_cmds + 12 * (int)a5;
v6 = a4 == 0;
v7 = a3 != 0;
func1(fd, v7, v10, v6, a2 & 1);
v8 = v7 + 2 * (a4 + 2 * a2);
if ( v8 > 0xF )
return 4294967274LL;
v10[0] = (__int64)&committed_switch_cmds + 12 * (int)v8;
return func1(fd, v7, v10, v6, a2 & 1);
}

original_code:
int setup_switch (int frontend_fd, int switch_pos, int voltage_18, int hiband, int uncommitted_switch_pos)
{
 int i;
 int err;
 struct diseqc_cmd *cmd[2] = { ((void *)0), ((void *)0) };
 i = uncommitted_switch_pos;
 if (i < 0 || i >= (int) (sizeof(uncommitted_switch_cmds)/sizeof(struct diseqc_cmd)))
  return -22;
 cmd[0] = &uncommitted_switch_cmds[i];
 diseqc_send_msg (frontend_fd,
  voltage_18 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
  cmd,
  hiband ? SEC_TONE_ON : SEC_TONE_OFF,
  switch_pos % 2 ? SEC_MINI_B : SEC_MINI_A);
 i = 4 * switch_pos + 2 * hiband + (voltage_18 ? 1 : 0);
 if (i < 0 || i >= (int) (sizeof(committed_switch_cmds)/sizeof(struct diseqc_cmd)))
  return -22;
 cmd[0] = &committed_switch_cmds[i];
 err = diseqc_send_msg (frontend_fd,
  voltage_18 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
  cmd,
  hiband ? SEC_TONE_ON : SEC_TONE_OFF,
  switch_pos % 2 ? SEC_MINI_B : SEC_MINI_A);
 return err;
}

canonical_original_code:
int setup_switch(int frontend_fd, int switch_pos, int voltage_18, int hiband, int uncommitted_switch_pos)
{
 int i;
 int err;
 struct diseqc_cmd *cmd[2] = { ((void *)0), ((void *)0) };
 i = uncommitted_switch_pos;
 if (i < 0 || i >= (int) (sizeof(uncommitted_switch_cmds)/sizeof(struct diseqc_cmd)))
  return -22;
 cmd[0] = &uncommitted_switch_cmds[i];
 diseqc_send_msg (frontend_fd,
  voltage_18 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
  cmd,
  hiband ? SEC_TONE_ON : SEC_TONE_OFF,
  switch_pos % 2 ? SEC_MINI_B : SEC_MINI_A);
 i = 4 * switch_pos + 2 * hiband + (voltage_18 ? 1 : 0);
 if (i < 0 || i >= (int) (sizeof(committed_switch_cmds)/sizeof(struct diseqc_cmd)))
  return -22;
 cmd[0] = &committed_switch_cmds[i];
 err = diseqc_send_msg (frontend_fd,
  voltage_18 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
  cmd,
  hiband ? SEC_TONE_ON : SEC_TONE_OFF,
  switch_pos % 2 ? SEC_MINI_B : SEC_MINI_A);
 return err;
}

variable_types: hiband int

variable_types: i int

variable_types: struct diseqc_cmd { struct dvb_diseqc_master_cmd { unsigned char msg[6]; unsigned char msg_len; } cmd; unsigned int wait; } *[2]


xmlify

decompiled_code:
int *__fastcall xmlify(char a1)
{
if ( a1 == 38 )
{
strcpy((char *)&xmlify_result, "&");
return &xmlify_result;
}
if ( a1 <= 38 )
{
if ( !a1 )
{
LOBYTE(xmlify_result) = 0;
return &xmlify_result;
}
if ( a1 == 34 )
{
strcpy((char *)&xmlify_result, """);
return &xmlify_result;
}
LABEL_13:
LOBYTE(xmlify_result) = a1;
BYTE1(xmlify_result) = 0;
return &xmlify_result;
}
if ( a1 == 60 )
{
strcpy((char *)&xmlify_result, "<");
return &xmlify_result;
}
if ( a1 != 62 )
goto LABEL_13;
strcpy((char *)&xmlify_result, ">");
return &xmlify_result;
}

canonical_decompiled_code:
int *__fastcall func0(char a1)
{
if ( a1 == 38 )
{
strcpy((char *)&xmlify_result, "&");
return &xmlify_result;
}
if ( a1 <= 38 )
{
if ( !a1 )
{
LOBYTE(xmlify_result) = 0;
return &xmlify_result;
}
if ( a1 == 34 )
{
strcpy((char *)&xmlify_result, """);
return &xmlify_result;
}
LABEL_13:
LOBYTE(xmlify_result) = a1;
BYTE1(xmlify_result) = 0;
return &xmlify_result;
}
if ( a1 == 60 )
{
strcpy((char *)&xmlify_result, "<");
return &xmlify_result;
}
if ( a1 != 62 )
goto LABEL_13;
strcpy((char *)&xmlify_result, ">");
return &xmlify_result;
}

original_code:
char* xmlify (char c) {
  switch(c) {
    case '&': strcpy(xmlify_result,"&");
              break;
    case '<': strcpy(xmlify_result,"<");
              break;
    case '>': strcpy(xmlify_result,">");
              break;
    case '\"': strcpy(xmlify_result,""");
              break;
    case 0: xmlify_result[0]=0;
              break;
    default: xmlify_result[0]=c;
             xmlify_result[1]=0;
             break;
 }
 return(xmlify_result);
}

canonical_original_code:
char *xmlify(char c) {
  switch(c) {
    case '&': strcpy(xmlify_result,"&");
              break;
    case '<': strcpy(xmlify_result,"<");
              break;
    case '>': strcpy(xmlify_result,">");
              break;
    case '\"': strcpy(xmlify_result,""");
              break;
    case 0: xmlify_result[0]=0;
              break;
    default: xmlify_result[0]=c;
             xmlify_result[1]=0;
             break;
 }
 return(xmlify_result);
}

variable_types: c char

return_type: char *


decompiled_code:
__int64 __fastcall get_unscanned(__int64 a1)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)(a1 + 32) )
{
a1 = *(_QWORD *)(a1 + 40);
if ( !a1 )
return 0LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
return 0LL;
while ( *(_DWORD *)(a1 + 32) )
{
a1 = *(_QWORD *)(a1 + 40);
if ( !a1 )
return 0LL;
}
return a1;
}

original_code:
transponder_t* get_unscanned(transponder_t* transponders) {
  transponder_t* t;
  t=transponders;
  while (t!=((void *)0)) {
    if (t->scanned==0) { return(t); };
    t=t->next;
  }
  return ((void *)0);
}

canonical_original_code:
struct _transponder_t *get_unscanned(struct _transponder_t *transponders) {
  struct _transponder_t *t;
  t=transponders;
  while (t!=((void *)0)) {
    if (t->scanned==0) { return(t); };
    t=t->next;
  }
  return ((void *)0);
}

variable_types:
transponders
struct _transponder_t *

variable_types: struct _transponder_t { int id; int onid; unsigned int freq; int srate; int pos; int we_flag; char pol; int mod; int scanned; struct _transponder_t *next; } *