decompiled_code:
__int64 __fastcall ook_decode_pulse_width(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, _QWORD *a8, size_t *a9, int a10)
{
_BYTE *v13; // r10
unsigned int *v14; // rbx
__int64 v15; // r9
__int64 v16; // rax
int v17; // edx
int v18; // er8
unsigned int v20; // edi
__int64 v21; // rcx
unsigned int v22; // esi
size_t v23; // [rsp+0h] [rbp-50h]
void *ptr; // [rsp+8h] [rbp-48h]
unsigned int v27; // [rsp+1Ch] [rbp-34h]

v27 = *(_DWORD *)(a1 + 8);
v23 = (v27 + 7) >> 3;
v13 = malloc(v23);
ptr = v13;
if ( !v13 )
return 0xFFFFFFFFLL;
if ( !v27 )
goto LABEL_22;
v14 = (unsigned int *)(a1 + 16);
v15 = v27 - 1 + 2LL;
v16 = 1LL;
v17 = 0;
v18 = 0;
do
{
v27 = v16;
v20 = v16 - 1;
v21 = *v14;
v22 = v14[1];
if ( v22 < a6 || v22 > a7 )
{
if ( a10 )
fprintf(stderr, "low of %u was %u, not between %u and %u\n", v20, v22, a6, a7);
goto LABEL_6;
}
if ( (unsigned int)v21 >= a2 && (unsigned int)v21 <= a3 )
{
v18 *= 2;
++v17;
goto LABEL_8;
}
if ( (unsigned int)v21 < a4 || (unsigned int)v21 > a5 )
{
if ( a10 )
fprintf(stderr, "high of %u was %u, not between %u and %u or %u and %u\n", v20, v21, a2, a3, a4, a5);
LABEL_6:
free(ptr);
return 0xFFFFFFFFLL;
}
v18 = 2 * v18 + 1;
++v17;
LABEL_8:
if ( (_BYTE)v17 == 8 )
{
*v13++ = v18;
v17 = 0;
}
++v16;
v14 += 3;
}
while ( v16 != v15 );
if ( (_BYTE)v17 )
*v13 = v18;
LABEL_22:
*a8 = ptr;
*a9 = v23;
return v27;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5, unsigned int a6, unsigned int a7, _QWORD *a8, size_t *a9, int a10)
{
_BYTE *v13; // r10
unsigned int *v14; // rbx
__int64 v15; // r9
__int64 v16; // rax
int v17; // edx
int v18; // er8
unsigned int v20; // edi
__int64 v21; // rcx
unsigned int v22; // esi
size_t v23; // [rsp+0h] [rbp-50h]
void *ptr; // [rsp+8h] [rbp-48h]
unsigned int v27; // [rsp+1Ch] [rbp-34h]

v27 = *(_DWORD *)(a1 + 8);
v23 = (v27 + 7) >> 3;
v13 = malloc(v23);
ptr = v13;
if ( !v13 )
return 0xFFFFFFFFLL;
if ( !v27 )
goto LABEL_22;
v14 = (unsigned int *)(a1 + 16);
v15 = v27 - 1 + 2LL;
v16 = 1LL;
v17 = 0;
v18 = 0;
do
{
v27 = v16;
v20 = v16 - 1;
v21 = *v14;
v22 = v14[1];
if ( v22 < a6 || v22 > a7 )
{
if ( a10 )
fprintf(stderr, "low of %u was %u, not between %u and %u\n", v20, v22, a6, a7);
goto LABEL_6;
}
if ( (unsigned int)v21 >= a2 && (unsigned int)v21 <= a3 )
{
v18 *= 2;
++v17;
goto LABEL_8;
}
if ( (unsigned int)v21 < a4 || (unsigned int)v21 > a5 )
{
if ( a10 )
fprintf(stderr, "high of %u was %u, not between %u and %u or %u and %u\n", v20, v21, a2, a3, a4, a5);
LABEL_6:
free(ptr);
return 0xFFFFFFFFLL;
}
v18 = 2 * v18 + 1;
++v17;
LABEL_8:
if ( (_BYTE)v17 == 8 )
{
*v13++ = v18;
v17 = 0;
}
++v16;
v14 += 3;
}
while ( v16 != v15 );
if ( (_BYTE)v17 )
*v13 = v18;
LABEL_22:
*a8 = ptr;
*a9 = v23;
return v27;
}

original_code:
int ook_decode_pulse_width( struct ook_burst *burst,
       uint32_t minZeroHi, uint32_t maxZeroHi,
       uint32_t minOneHi, uint32_t maxOneHi,
       uint32_t minLow, uint32_t maxLow,
       unsigned char **dataReturn, size_t *dataLenReturn,
       int verbose)
{
    size_t dataLen = (burst->pulses + 7)/8;
    unsigned char *data = (unsigned char *)malloc( dataLen);
    if ( data == 0) goto Fail;
    unsigned char accum = 0;
    unsigned char *thumb = data;
    unsigned char bitsInAccum = 0;
    unsigned bits = 0;
    for ( int i = 0; i < burst->pulses; i++) {
 uint32_t hi = burst->pulse[i].hiNanoseconds;
 uint32_t low = burst->pulse[i].lowNanoseconds;
 if ( low < minLow || low > maxLow) {
     if ( verbose) fprintf(stderr,"low of %u was %u, not between %u and %u\n", i, low, minLow, maxLow);
     goto Fail;
 }
 if ( hi >= minZeroHi && hi <= maxZeroHi) {
     accum = (accum<<1);
     bitsInAccum++;
     bits++;
 } else if ( hi >= minOneHi && hi <= maxOneHi) {
     accum = ((accum<<1)|1);
     bitsInAccum++;
     bits++;
 } else {
     if ( verbose) fprintf(stderr,"high of %u was %u, not between %u and %u or %u and %u\n",
      i, hi, minZeroHi, maxZeroHi, minOneHi, maxOneHi);
     goto Fail;
 }
 if ( bitsInAccum == 8) {
     *thumb++ = accum;
     bitsInAccum = 0;
 }
    }
    if ( bitsInAccum != 0) {
 *thumb++ = accum;
 bitsInAccum = 0;
    }
    *dataReturn = data;
    *dataLenReturn = dataLen;
    return bits;
  Fail:
    if ( data) free(data);
    return -1;
}

canonical_original_code:
int ook_decode_pulse_width(struct ook_burst *burst, unsigned int minZeroHi, unsigned int maxZeroHi, unsigned int minOneHi, unsigned int maxOneHi, unsigned int minLow, unsigned int maxLow, unsigned char **dataReturn, unsigned long *dataLenReturn, int verbose)
{
    unsigned long dataLen = (burst->pulses + 7)/8;
    unsigned char *data = (unsigned char *)malloc( dataLen);
    if ( data == 0) goto Fail;
    unsigned char accum = 0;
    unsigned char *thumb = data;
    unsigned char bitsInAccum = 0;
    unsigned int bits = 0;
    for ( int i = 0; i < burst->pulses; i++) {
 unsigned int hi = burst->pulse[i].hiNanoseconds;
 unsigned int low = burst->pulse[i].lowNanoseconds;
 if ( low < minLow || low > maxLow) {
     if ( verbose) fprintf(stderr,"low of %u was %u, not between %u and %u\n", i, low, minLow, maxLow);
     goto Fail;
 }
 if ( hi >= minZeroHi && hi <= maxZeroHi) {
     accum = (accum<<1);
     bitsInAccum++;
     bits++;
 } else if ( hi >= minOneHi && hi <= maxOneHi) {
     accum = ((accum<<1)|1);
     bitsInAccum++;
     bits++;
 } else {
     if ( verbose) fprintf(stderr,"high of %u was %u, not between %u and %u or %u and %u\n",
      i, hi, minZeroHi, maxZeroHi, minOneHi, maxOneHi);
     goto Fail;
 }
 if ( bitsInAccum == 8) {
     *thumb++ = accum;
     bitsInAccum = 0;
 }
    }
    if ( bitsInAccum != 0) {
 *thumb++ = accum;
 bitsInAccum = 0;
    }
    *dataReturn = data;
    *dataLenReturn = dataLen;
    return bits;
  Fail:
    if ( data) free(data);
    return -1;
}

variable_types: struct ook_burst { unsigned long positionNanoseconds; unsigned int pulses; unsigned int allocatedPulses; struct ook_pulse { unsigned int hiNanoseconds; unsigned int lowNanoseconds; int frequencyOffsetHz; } pulse[]; } *

variable_types:
minZeroHi
unsigned int

variable_types:
maxZeroHi
unsigned int

variable_types:
minOneHi
unsigned int

variable_types:
maxOneHi
unsigned int

variable_types:
minLow
unsigned int

variable_types:
maxLow
unsigned int

variable_types:
dataReturn
unsigned char **

variable_types:
dataLenReturn
unsigned long *

variable_types:
dataLen
unsigned long

variable_types:
data
unsigned char *

variable_types:
accum
unsigned char

variable_types:
bitsInAccum
unsigned char

variable_types:
bits
unsigned int


repo: jimstudt/ook-decoder

decompiled_code:
__int64 __fastcall is_sync_bit(_QWORD *a1)
{
_BYTE *v1; // rdx
__int64 result; // rax
_BYTE *v3; // rax

v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = v1 + 1;
while ( !*v3 )
{
if ( ++v3 == v1 + 11 )
goto LABEL_2;
}
result = 0LL;
}
else
{
LABEL_2:
*a1 = v1 + 11;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
_BYTE *v1; // rdx
__int64 result; // rax
_BYTE *v3; // rax

v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = v1 + 1;
while ( !*v3 )
{
if ( ++v3 == v1 + 11 )
goto LABEL_2;
}
result = 0LL;
}
else
{
LABEL_2:
*a1 = v1 + 11;
result = 1LL;
}
return result;
}

original_code:
int is_sync_bit(unsigned char** data)
{
    if((*data)[0] == 1) {
        for(int i = 1; i < 11; ++i) {
            if((*data)[i] != 0) {
                return 0;
            }
        }
    }
    *data += 11;
    return 1;
}

canonical_original_code:
int is_sync_bit(unsigned char **data)
{
    if((*data)[0] == 1) {
        for(int i = 1; i < 11; ++i) {
            if((*data)[i] != 0) {
                return 0;
            }
        }
    }
    *data += 11;
    return 1;
}

variable_types:
data
unsigned char **

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall is_pause_bit(_QWORD *a1)
{
_BYTE *v1; // rdx
__int64 result; // rax
_BYTE *v3; // rax

v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = v1 + 1;
while ( !*v3 )
{
if ( ++v3 == v1 + 41 )
goto LABEL_2;
}
result = 0LL;
}
else
{
LABEL_2:
*a1 = v1 + 41;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
_BYTE *v1; // rdx
__int64 result; // rax
_BYTE *v3; // rax

v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = v1 + 1;
while ( !*v3 )
{
if ( ++v3 == v1 + 41 )
goto LABEL_2;
}
result = 0LL;
}
else
{
LABEL_2:
*a1 = v1 + 41;
result = 1LL;
}
return result;
}

original_code:
int is_pause_bit(unsigned char** data)
{
    if((*data)[0] == 1) {
        for(int i = 1; i < 41; ++i) {
            if((*data)[i] != 0) {
                return 0;
            }
        }
    }
    *data += 41;
    return 1;
}

canonical_original_code:
int is_pause_bit(unsigned char **data)
{
    if((*data)[0] == 1) {
        for(int i = 1; i < 41; ++i) {
            if((*data)[i] != 0) {
                return 0;
            }
        }
    }
    *data += 41;
    return 1;
}


decompiled_code:
__int64 __fastcall decode_physical_bit(_QWORD *a1)
{
_BYTE *v1; // rax
__int64 result; // rax
_BYTE *v3; // rdx

v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = v1 + 1;
while ( !*v3 )
{
if ( ++v3 == v1 + 6 )
goto LABEL_2;
}
*a1 = v1 + 2;
result = 1LL;
}
else
{
LABEL_2:
*a1 = v1 + 6;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
_BYTE *v1; // rax
__int64 result; // rax
_BYTE *v3; // rdx

v1 = (_BYTE *)*a1;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = v1 + 1;
while ( !*v3 )
{
if ( ++v3 == v1 + 6 )
goto LABEL_2;
}
*a1 = v1 + 2;
result = 1LL;
}
else
{
LABEL_2:
*a1 = v1 + 6;
result = 0LL;
}
return result;
}

original_code:
int decode_physical_bit(unsigned char** data)
{
    if((*data)[0] == 1) {
        for(int i = 1; i < 6; ++i) {
            if((*data)[i] != 0) {
                *data += 2;
                return 1;
            }
        }
    }
    *data += 6;
    return 0;
}

canonical_original_code:
int decode_physical_bit(unsigned char **data)
{
    if((*data)[0] == 1) {
        for(int i = 1; i < 6; ++i) {
            if((*data)[i] != 0) {
                *data += 2;
                return 1;
            }
        }
    }
    *data += 6;
    return 0;
}


decompiled_code:
__int64 __fastcall decode_logical_bit(_QWORD *a1)
{
unsigned int v1; // er12
unsigned int v2; // eax
unsigned int v3; // edx

v1 = decode_physical_bit(a1);
v2 = decode_physical_bit(a1);
if ( !v1 || (v3 = 1, v2) )
{
if ( v1 || (v3 = 0, !v2) )
{
v3 = -1;
if ( verbose )
{
fprintf(stderr, "incorrect physical bit sequence %d %d\n", v1, v2);
v3 = -1;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
unsigned int v1; // er12
unsigned int v2; // eax
unsigned int v3; // edx

v1 = func4(a1);
v2 = func4(a1);
if ( !v1 || (v3 = 1, v2) )
{
if ( v1 || (v3 = 0, !v2) )
{
v3 = -1;
if ( verbose )
{
fprintf(stderr, "incorrect physical bit sequence %d %d\n", v1, v2);
v3 = -1;
}
}
}
return v3;
}

original_code:
int decode_logical_bit(unsigned char** data)
{
    int first_bit = decode_physical_bit(data);
    int second_bit = decode_physical_bit(data);
    if(first_bit && !second_bit) {
        return 1;
    } else if(!first_bit && second_bit) {
        return 0;
    } else if(verbose) {
        fprintf(stderr, "incorrect physical bit sequence %d %d\n", first_bit, second_bit);
    }
    return -1;
}

canonical_original_code:
int decode_logical_bit(unsigned char **data)
{
    int first_bit = decode_physical_bit(data);
    int second_bit = decode_physical_bit(data);
    if(first_bit && !second_bit) {
        return 1;
    } else if(!first_bit && second_bit) {
        return 0;
    } else if(verbose) {
        fprintf(stderr, "incorrect physical bit sequence %d %d\n", first_bit, second_bit);
    }
    return -1;
}


decompiled_code:
__int64 __fastcall send_statsd_gauge(const char *a1)
{
unsigned int v1; // ebx
size_t v2; // rax
char s[128]; // [rsp+0h] [rbp-A0h] BYREF
struct sockaddr inp[2]; // [rsp+80h] [rbp-20h] BYREF

v1 = socket(2, 2, 17);
if ( v1 != -1 )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
*(_WORD *)inp[0].sa_data = _bswap_16(8125);
if ( inet_aton("127.0.0.1", (struct in_addr *)&inp[0].sa_data[2]) )
{
snprintf(s, 0x80uLL, "%s:1|g", a1);
v2 = strlen(s);
if ( sendto(v1, s, v2, 0, inp, 0x10u) == -1 )
{
v1 = -1;
}
else
{
close(v1);
v1 = 0;
}
}
else
{
fprintf(stderr, "inet_aton() failed for address '%s'\n", "127.0.0.1");
v1 = -1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
unsigned int v1; // ebx
size_t v2; // rax
char s[128]; // [rsp+0h] [rbp-A0h] BYREF
struct sockaddr inp[2]; // [rsp+80h] [rbp-20h] BYREF

v1 = socket(2, 2, 17);
if ( v1 != -1 )
{
*(_QWORD *)&inp[0].sa_family = 2LL;
*(_QWORD *)&inp[0].sa_data[6] = 0LL;
*(_WORD *)inp[0].sa_data = func1(8125);
if ( inet_aton("127.0.0.1", (struct in_addr *)&inp[0].sa_data[2]) )
{
snprintf(s, 0x80uLL, "%s:1|g", a1);
v2 = strlen(s);
if ( sendto(v1, s, v2, 0, inp, 0x10u) == -1 )
{
v1 = -1;
}
else
{
close(v1);
v1 = 0;
}
}
else
{
fprintf(stderr, "inet_aton() failed for address '%s'\n", "127.0.0.1");
v1 = -1;
}
}
return v1;
}

original_code:
int send_statsd_gauge(const char* metricName)
{
    struct sockaddr_in si_other;
    int s, slen = sizeof(si_other);
    char buf[128];
    if ((s = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
        return -1;
    }
    memset((char *) &si_other, 0, sizeof(si_other));
    si_other.sin_family = 2;
    si_other.sin_port = htons(8125);
    if (inet_aton("127.0.0.1", &si_other.sin_addr) == 0) {
        fprintf(stderr, "inet_aton() failed for address '%s'\n", "127.0.0.1");
        return -1;
    }
    snprintf(buf, sizeof(buf), "%s:1|g", metricName);
    if (sendto(s, buf, strlen(buf), 0, (struct sockaddr*)&si_other, slen) == -1) {
        return -1;
    }
    close(s);
    return 0;
}

canonical_original_code:
int send_statsd_gauge(char *metricName)
{
    struct sockaddr_in si_other;
    int s; int slen = sizeof(si_other);
    char buf[128];
    if ((s = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
        return -1;
    }
    memset((char *) &si_other, 0, sizeof(si_other));
    si_other.sin_family = 2;
    si_other.sin_port = htons(8125);
    if (inet_aton("127.0.0.1", &si_other.sin_addr) == 0) {
        fprintf(stderr, "inet_aton() failed for address '%s'\n", "127.0.0.1");
        return -1;
    }
    snprintf(buf, sizeof(buf), "%s:1|g", metricName);
    if (sendto(s, buf, strlen(buf), 0, (struct sockaddr *)&si_other, slen) == -1) {
        return -1;
    }
    close(s);
    return 0;
}

variable_types:
metricName
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: s int

variable_types: slen int

variable_types:
buf
char [128]

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
char *v4; // r13
char *v5; // r14
int v6; // eax
int v8; // er14
char *v9; // rbx
int *v10; // rax
char *v11; // rax
__int64 v12; // rcx
_DWORD *v13; // r8
_DWORD *v14; // rdi
unsigned int v15; // esi
unsigned int v16; // edx
unsigned __int8 v17; // r9
char *v18; // rax
_BYTE *v19; // rax
void *v20; // r13
int v21; // eax
const char *v22; // rcx
char *v23; // [rsp+0h] [rbp-D0h]
int v24; // [rsp+Ch] [rbp-C4h]
int v25; // [rsp+14h] [rbp-BCh] BYREF
void *ptr; // [rsp+18h] [rbp-B8h] BYREF
int longind[44]; // [rsp+20h] [rbp-B0h] BYREF

v3 = 0LL;
v24 = -1;
v4 = "127.0.0.1";
v5 = "3636";
v23 = "236.0.0.1";
while ( 2 )
{
longind[0] = 0;
v6 = getopt_long(argc, (char *const *)argv, "vh?f:a:p:i:m:", &options_0, longind);
if ( v6 != -1 )
{
switch ( v6 )
{
case '?':
case 'h':
showHelp(stdout);
return 0;
case 'a':
v23 = optarg;
continue;
case 'f':
v24 = atoi(optarg);
continue;
case 'i':
v4 = optarg;
continue;
case 'm':
v3 = optarg;
continue;
case 'p':
v5 = optarg;
continue;
case 'v':
verbose = 1;
continue;
default:
fwrite("Illegal option\n", 1uLL, 0xFuLL, stderr);
showHelp(stderr);
exit(1);
}
}
break;
}
v8 = ook_open(v23, v5, v4);
if ( v8 < 0 )
{
fwrite("Failed to open multicast interface\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v9 = (char *)malloc(0x1000uLL);
while ( 1 )
{
v25 = 128;
v21 = ook_decode_from_socket((unsigned int)v8, &ptr, longind, &v25, (unsigned int)verbose);
if ( v21 < 0 )
break;
if ( v21 )
{
memset(v9, 0, 0x1000uLL);
v12 = 0LL;
v13 = ptr;
if ( *((_DWORD *)ptr + 2) )
{
v14 = (char *)ptr + 20;
v15 = 0;
do
{
v9[v12] = 1;
v16 = *v14 / 0x3D090u;
v17 = v16 - 1;
if ( (_BYTE)v16 )
{
v18 = &v9[v12 + 1];
do
*v18++ = 0;
while ( v18 != &v9[v12 + 2 + v17] );
v12 += v17 + 2LL;
}
else
{
++v12;
}
++v15;
v14 += 3;
}
while ( v13[2] > v15 );
}
v19 = decode_nexa_p((__int64)v9);
v20 = v19;
if ( v19 )
{
if ( v24 == -1 || (*(_DWORD *)v19 & 0x3FFFFFF) == v24 )
{
if ( verbose )
{
v22 = "ON";
if ( (v19[3] & 8) == 0 )
v22 = "OFF";
fprintf(stderr, "transmitter code: %d: %s\n", *(_DWORD *)v19 & 0x3FFFFFF, v22);
}
if ( v3 )
send_statsd_gauge(v3);
}
}
else
{
fwrite("decoding error\n", 1uLL, 0xFuLL, stderr);
}
fflush(stdin);
free(v20);
free(ptr);
}
else
{
fwrite("Corrupt burst\n", 1uLL, 0xEuLL, stderr);
}
}
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Failed to decode from socket: %s\n", v11);
free(v9);
close(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
char *v4; // r13
char *v5; // r14
int v6; // eax
int v8; // er14
char *v9; // rbx
int *v10; // rax
char *v11; // rax
__int64 v12; // rcx
_DWORD *v13; // r8
_DWORD *v14; // rdi
unsigned int v15; // esi
unsigned int v16; // edx
unsigned __int8 v17; // r9
char *v18; // rax
_BYTE *v19; // rax
void *v20; // r13
int v21; // eax
const char *v22; // rcx
char *v23; // [rsp+0h] [rbp-D0h]
int v24; // [rsp+Ch] [rbp-C4h]
int v25; // [rsp+14h] [rbp-BCh] BYREF
void *ptr; // [rsp+18h] [rbp-B8h] BYREF
int longind[44]; // [rsp+20h] [rbp-B0h] BYREF

v3 = 0LL;
v24 = -1;
v4 = "127.0.0.1";
v5 = "3636";
v23 = "236.0.0.1";
while ( 2 )
{
longind[0] = 0;
v6 = getopt_long(argc, (char *const *)argv, "vh?f:a:p:i:m:", &options_0, longind);
if ( v6 != -1 )
{
switch ( v6 )
{
case '?':
case 'h':
func0(stdout);
return 0;
case 'a':
v23 = optarg;
continue;
case 'f':
v24 = atoi(optarg);
continue;
case 'i':
v4 = optarg;
continue;
case 'm':
v3 = optarg;
continue;
case 'p':
v5 = optarg;
continue;
case 'v':
verbose = 1;
continue;
default:
fwrite("Illegal option\n", 1uLL, 0xFuLL, stderr);
func0(stderr);
exit(1);
}
}
break;
}
v8 = ook_open(v23, v5, v4);
if ( v8 < 0 )
{
fwrite("Failed to open multicast interface\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v9 = (char *)malloc(0x1000uLL);
while ( 1 )
{
v25 = 128;
v21 = ook_decode_from_socket((unsigned int)v8, &ptr, longind, &v25, (unsigned int)verbose);
if ( v21 < 0 )
break;
if ( v21 )
{
memset(v9, 0, 0x1000uLL);
v12 = 0LL;
v13 = ptr;
if ( *((_DWORD *)ptr + 2) )
{
v14 = (char *)ptr + 20;
v15 = 0;
do
{
v9[v12] = 1;
v16 = *v14 / 0x3D090u;
v17 = v16 - 1;
if ( (_BYTE)v16 )
{
v18 = &v9[v12 + 1];
do
*v18++ = 0;
while ( v18 != &v9[v12 + 2 + v17] );
v12 += v17 + 2LL;
}
else
{
++v12;
}
++v15;
v14 += 3;
}
while ( v13[2] > v15 );
}
v19 = decode_nexa_p((__int64)v9);
v20 = v19;
if ( v19 )
{
if ( v24 == -1 || (*(_DWORD *)v19 & 0x3FFFFFF) == v24 )
{
if ( verbose )
{
v22 = "ON";
if ( (v19[3] & 8) == 0 )
v22 = "OFF";
fprintf(stderr, "transmitter code: %d: %s\n", *(_DWORD *)v19 & 0x3FFFFFF, v22);
}
if ( v3 )
func6(v3);
}
}
else
{
fwrite("decoding error\n", 1uLL, 0xFuLL, stderr);
}
fflush(stdin);
free(v20);
free(ptr);
}
else
{
fwrite("Corrupt burst\n", 1uLL, 0xEuLL, stderr);
}
}
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Failed to decode from socket: %s\n", v11);
free(v9);
close(v8);
return 0;
}

original_code:
int main( int argc, char **argv)
{
    const char *multicastAddress = "236.0.0.1";
    const char *multicastPort = "3636";
    const char *multicastInterface = "127.0.0.1";
    int32_t filterTransmitterCode = -1;
    const char *metricName = ((void *)0);
    for(;;) {
        int optionIndex = 0;
        static struct option options[] = {
            { "verbose", 0, 0, 'v' },
            { "help", 0, 0, 'h' },
            { "multicast-address", 1, 0, 'a'},
            { "multicast-port", 1, 0, 'p' },
            { "multicast-interface", 1, 0, 'i' },
            { "filter-transmitter-code", 1, 0, 'f' },
            { "metric-name", 1, 0, 'm' },
            { 0,0,0,0}
        };
        int c = getopt_long( argc, argv, "vh?f:a:p:i:m:", options, &optionIndex );
        if ( c == -1) break;
        switch(c) {
            case 'h':
            case '?':
                showHelp(stdout);
                return 0;
            case 'v':
                verbose = 1;
                break;
            case 'a':
                multicastAddress = optarg;
                break;
            case 'p':
                multicastPort = optarg;
                break;
            case 'i':
                multicastInterface = optarg;
                break;
            case 'f':
                filterTransmitterCode = atoi(optarg);
                break;
            case 'm':
                metricName = optarg;
                break;
            default:
                fprintf(stderr,"Illegal option\n");
                showHelp(stderr);
                exit(1);
        }
    }
    int sock = ook_open( multicastAddress, multicastPort, multicastInterface);
    if ( sock < 0) {
        fprintf(stderr,"Failed to open multicast interface\n");
        exit(1);
    }
    unsigned char *data = (unsigned char *)malloc(4096 * sizeof(unsigned char));
    for (;;) {
        struct ook_burst *burst;
        struct sockaddr_storage addr;
        socklen_t addrLen = sizeof(addr);
        int e = ook_decode_from_socket( sock, &burst, (struct sockaddr *)&addr, &addrLen, verbose);
        if ( e < 0) {
            fprintf(stderr,"Failed to decode from socket: %s\n", strerror((*__errno_location ())));
            break;
        }
        if ( e == 0) {
            fprintf(stderr,"Corrupt burst\n");
            continue;
        }
        size_t bits = 0;
        memset(data, 0, 4096 * sizeof(unsigned char));
        for ( int i = 0; i < burst->pulses; i++) {
            data[bits++] = 1;
            uint8_t zeros = burst->pulse[i].lowNanoseconds / 250000;
            while(zeros--) {
                data[bits++] = 0;
            }
        }
        struct nexa_p* packet = decode_nexa_p(data);
        if(packet) {
            if(filterTransmitterCode == -1 || packet->transmitter_code == filterTransmitterCode) {
                if(verbose) {
                    fprintf(stderr, "transmitter code: %d: %s\n", packet->transmitter_code,
                        packet->on_off ? "ON" : "OFF");
                }
                if(metricName) {
                    send_statsd_gauge(metricName);
                }
            }
        } else {
            fprintf(stderr, "decoding error\n");
        }
        fflush(stdin);
        free(packet);
        free(burst);
    }
    free(data);
    close(sock);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *multicastAddress = "236.0.0.1";
    char *multicastPort = "3636";
    char *multicastInterface = "127.0.0.1";
    int filterTransmitterCode = -1;
    char *metricName = ((void *)0);
    for(;;) {
        int optionIndex = 0;
        static struct option options[] = {
            { "verbose", 0, 0, 'v' },
            { "help", 0, 0, 'h' },
            { "multicast-address", 1, 0, 'a'},
            { "multicast-port", 1, 0, 'p' },
            { "multicast-interface", 1, 0, 'i' },
            { "filter-transmitter-code", 1, 0, 'f' },
            { "metric-name", 1, 0, 'm' },
            { 0,0,0,0}
        };
        int c = getopt_long( argc, argv, "vh?f:a:p:i:m:", options, &optionIndex );
        if ( c == -1) break;
        switch(c) {
            case 'h':
            case '?':
                showHelp(stdout);
                return 0;
            case 'v':
                verbose = 1;
                break;
            case 'a':
                multicastAddress = optarg;
                break;
            case 'p':
                multicastPort = optarg;
                break;
            case 'i':
                multicastInterface = optarg;
                break;
            case 'f':
                filterTransmitterCode = atoi(optarg);
                break;
            case 'm':
                metricName = optarg;
                break;
            default:
                fprintf(stderr,"Illegal option\n");
                showHelp(stderr);
                exit(1);
        }
    }
    int sock = ook_open( multicastAddress, multicastPort, multicastInterface);
    if ( sock < 0) {
        fprintf(stderr,"Failed to open multicast interface\n");
        exit(1);
    }
    unsigned char *data = (unsigned char *)malloc(4096 * sizeof(unsigned char));
    for (;;) {
        struct ook_burst *burst;
        struct sockaddr_storage addr;
        unsigned int addrLen = sizeof(addr);
        int e = ook_decode_from_socket( sock, &burst, (struct sockaddr *)&addr, &addrLen, verbose);
        if ( e < 0) {
            fprintf(stderr,"Failed to decode from socket: %s\n", strerror((*__errno_location ())));
            break;
        }
        if ( e == 0) {
            fprintf(stderr,"Corrupt burst\n");
            continue;
        }
        unsigned long bits = 0;
        memset(data, 0, 4096 * sizeof(unsigned char));
        for ( int i = 0; i < burst->pulses; i++) {
            data[bits++] = 1;
            unsigned char zeros = burst->pulse[i].lowNanoseconds / 250000;
            while(zeros--) {
                data[bits++] = 0;
            }
        }
        struct nexa_p *packet = decode_nexa_p(data);
        if(packet) {
            if(filterTransmitterCode == -1 || packet->transmitter_code == filterTransmitterCode) {
                if(verbose) {
                    fprintf(stderr, "transmitter code: %d: %s\n", packet->transmitter_code,
                        packet->on_off ? "ON" : "OFF");
                }
                if(metricName) {
                    send_statsd_gauge(metricName);
                }
            }
        } else {
            fprintf(stderr, "decoding error\n");
        }
        fflush(stdin);
        free(packet);
        free(burst);
    }
    free(data);
    close(sock);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
multicastAddress
char *

variable_types:
multicastPort
char *

variable_types:
multicastInterface
char *

variable_types: filterTransmitterCode int

variable_types: optionIndex int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: c int

variable_types: sock int

variable_types: struct ook_burst { unsigned long positionNanoseconds; unsigned int pulses; unsigned int allocatedPulses; struct ook_pulse { unsigned int hiNanoseconds; unsigned int lowNanoseconds; int frequencyOffsetHz; } pulse[]; } *

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
addrLen
unsigned int

variable_types: e int

variable_types:
bits
unsigned long

variable_types:
zeros
unsigned char

variable_types: struct nexa_p { unsigned int transmitter_code; unsigned char group_code; unsigned char on_off; unsigned char channel_bits; unsigned char unit_bits; } *

user_defined_types: struct ook_burst { unsigned long positionNanoseconds; unsigned int pulses; unsigned int allocatedPulses; struct ook_pulse pulse[]; }


countLines

decompiled_code:
__int64 __fastcall countLines(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1 == 10;
v1 = *v2++;
}
while ( v1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char v1; // al
char *v2; // rdi
unsigned int v3; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1 == 10;
v1 = *v2++;
}
while ( v1 );
return v3;
}

original_code:
int countLines(char* buf)
{ int i=0,counter=0;
  char a;
  while((a=buf[i]) != '\0')
  { if(a=='\n')
    { counter++;
    }
    i++;
  }
  return counter;
}

canonical_original_code:
int countLines(char *buf)
{ int i = 0; int counter = 0;
  char a;
  while((a=buf[i]) != '\0')
  { if(a=='\n')
    { counter++;
    }
    i++;
  }
  return counter;
}

variable_types:
buf
char *

variable_types: i int

variable_types: counter int

variable_types: a char


repo: jinie/memmgr

decompiled_code:
void __fastcall m_init(_QWORD *a1, __int64 a2)
{
if ( !a1 || !a2 || FBLHeader )
__assert_fail("heap && (size > 0) && (FBLHeader==NULL)", "memmgr.c", 0x2Cu, "m_init");
heapsize = a2;
heaparea = (__int64)a1;
FBLHeader = (__int64)a1;
*a1 = a2 - 16;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func7(_QWORD *a1, __int64 a2)
{
if ( !a1 || !a2 || FBLHeader )
__assert_fail("heap && (size > 0) && (FBLHeader==NULL)", "memmgr.c", 0x2Cu, "m_init");
heapsize = a2;
heaparea = (__int64)a1;
FBLHeader = (__int64)a1;
*a1 = a2 - 16;
a1[1] = 0LL;
}

original_code:
void m_init(unsigned char * heap, unsigned long size)
{
 ((void) sizeof ((heap && (size > 0) && (FBLHeader==((void *)0))) ? 1 : 0), __extension__ ({ if (heap && (size > 0) && (FBLHeader==((void *)0))) ; else __assert_fail ("heap && (size > 0) && (FBLHeader==NULL)", "memmgr.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 heapsize = size;
 heaparea = heap;
 FBLHeader=(FreeBlockType *)heaparea;
 FBLHeader->BlockSize = (heapsize - sizeof(FreeBlockType));
 FBLHeader->next = ((void *)0);
}

canonical_original_code:
void m_init(unsigned char *heap, unsigned long size)
{
 ((void) sizeof ((heap && (size > 0) && (FBLHeader==((void *)0))) ? 1 : 0), __extension__ ({ if (heap && (size > 0) && (FBLHeader==((void *)0))) ; else __assert_fail ("heap && (size > 0) && (FBLHeader==NULL)", "memmgr.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 heapsize = size;
 heaparea = heap;
 FBLHeader=(struct FreeBlockType_ *)heaparea;
 FBLHeader->BlockSize = (heapsize - sizeof(FreeBlockType));
 FBLHeader->next = ((void *)0);
}

variable_types:
heap
unsigned char *

variable_types:
size
unsigned long

return_type: void

user_defined_types: struct FreeBlockType_ { unsigned long BlockSize; struct FreeBlockType_ *next; }


decompiled_code:
void m_destroy()
{
FBLHeader = 0LL;
heaparea = 0LL;
heapsize = 0LL;
}

canonical_decompiled_code:
void func8()
{
FBLHeader = 0LL;
heaparea = 0LL;
heapsize = 0LL;
}

original_code:
void m_destroy(void)
{
 FBLHeader = ((void *)0);
 heaparea = ((void *)0);
        heapsize = 0;
}

canonical_original_code:
void m_destroy()
{
 FBLHeader = ((void *)0);
 heaparea = ((void *)0);
        heapsize = 0;
}


decompiled_code:
__int64 __fastcall m_malloc(unsigned __int64 a1)
{
unsigned __int64 *v1; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rcx
unsigned __int64 *v4; // rsi
__int64 v5; // rdx
_QWORD *v6; // rdi

v1 = (unsigned __int64 *)FBLHeader;
v2 = 8LL;
if ( a1 >= 8 )
v2 = a1;
v3 = (v2 & 3) + v2 + 8;
if ( !a1 || !heaparea )
__assert_fail("blocksize > 0 && heaparea != 0", "memmgr.c", 0x44u, "m_malloc");
v4 = 0LL;
v5 = FBLHeader;
if ( FBLHeader )
{
while ( *v1 < v3 )
{
v5 = v1[1];
v4 = v1;
if ( !v5 )
return v5;
v1 = (unsigned __int64 *)v1[1];
}
if ( *v1 > v3 )
{
v6 = (unsigned __int64 *)((char *)v1 + v3);
*v6 = *v1 - v3;
v6[1] = v1[1];
}
else
{
v6 = (_QWORD *)v1[1];
v3 = *v1;
}
if ( v4 )
v4[1] = (unsigned __int64)v6;
else
FBLHeader = (__int64)v6;
v1[1] = 0LL;
*v1 = v3;
v5 = (__int64)(v1 + 1);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int64 a1)
{
unsigned __int64 *v1; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rcx
unsigned __int64 *v4; // rsi
__int64 v5; // rdx
_QWORD *v6; // rdi

v1 = (unsigned __int64 *)FBLHeader;
v2 = 8LL;
if ( a1 >= 8 )
v2 = a1;
v3 = (v2 & 3) + v2 + 8;
if ( !a1 || !heaparea )
__assert_fail("blocksize > 0 && heaparea != 0", "memmgr.c", 0x44u, "m_malloc");
v4 = 0LL;
v5 = FBLHeader;
if ( FBLHeader )
{
while ( *v1 < v3 )
{
v5 = v1[1];
v4 = v1;
if ( !v5 )
return v5;
v1 = (unsigned __int64 *)v1[1];
}
if ( *v1 > v3 )
{
v6 = (unsigned __int64 *)((char *)v1 + v3);
*v6 = *v1 - v3;
v6[1] = v1[1];
}
else
{
v6 = (_QWORD *)v1[1];
v3 = *v1;
}
if ( v4 )
v4[1] = (unsigned __int64)v6;
else
FBLHeader = (__int64)v6;
v1[1] = 0LL;
*v1 = v3;
v5 = (__int64)(v1 + 1);
}
return v5;
}

original_code:
void * m_malloc(unsigned long blocksize)
{
 FreeBlockType *blockptr = FBLHeader, *previous = ((void *)0);
 unsigned long bsize = sizeof(UsedBlockType);
 bsize += (blocksize > (sizeof(FreeBlockType) - sizeof(UsedBlockType))) ? blocksize : (sizeof(FreeBlockType) - sizeof(UsedBlockType));
 bsize += bsize % 4;
  ((void) sizeof ((blocksize > 0 && heaparea != 0) ? 1 : 0), __extension__ ({ if (blocksize > 0 && heaparea != 0) ; else __assert_fail ("blocksize > 0 && heaparea != 0", "memmgr.c", 68, __extension__ __PRETTY_FUNCTION__); }));
   while(blockptr!=((void *)0))
   {
    if(blockptr->BlockSize >= bsize)
     break;
    else
    {
     previous = blockptr;
     blockptr=blockptr->next;
    }
   }
 if(blockptr!=((void *)0))
 {
  FreeBlockType *usedblock = (FreeBlockType *)blockptr;
  if(blockptr->BlockSize > bsize)
  {
   blockptr= (FreeBlockType*)((unsigned char *)blockptr+bsize );
   blockptr->BlockSize = usedblock->BlockSize - bsize;
   blockptr->next = usedblock->next;
  }
  else
  {
   bsize += (usedblock->BlockSize - bsize);
   blockptr = usedblock->next;
  }
  if(previous!=((void *)0))
   previous->next=blockptr;
  else
   FBLHeader = blockptr;
  usedblock->next = ((void *)0);
  usedblock->BlockSize = bsize;
  return((unsigned char *)usedblock+sizeof(UsedBlockType));
 }
 return(((void *)0));
}

canonical_original_code:
void *m_malloc(unsigned long blocksize)
{
 struct FreeBlockType_ *blockptr = FBLHeader; struct FreeBlockType_ *previous = ((void *)0);
 unsigned long bsize = sizeof(UsedBlockType);
 bsize += (blocksize > (sizeof(FreeBlockType) - sizeof(UsedBlockType))) ? blocksize : (sizeof(FreeBlockType) - sizeof(UsedBlockType));
 bsize += bsize % 4;
  ((void) sizeof ((blocksize > 0 && heaparea != 0) ? 1 : 0), __extension__ ({ if (blocksize > 0 && heaparea != 0) ; else __assert_fail ("blocksize > 0 && heaparea != 0", "memmgr.c", 68, __extension__ __PRETTY_FUNCTION__); }));
   while(blockptr!=((void *)0))
   {
    if(blockptr->BlockSize >= bsize)
     break;
    else
    {
     previous = blockptr;
     blockptr=blockptr->next;
    }
   }
 if(blockptr!=((void *)0))
 {
  struct FreeBlockType_ *usedblock = (FreeBlockType *)blockptr;
  if(blockptr->BlockSize > bsize)
  {
   blockptr= (struct FreeBlockType_ *)((unsigned char *)blockptr+bsize );
   blockptr->BlockSize = usedblock->BlockSize - bsize;
   blockptr->next = usedblock->next;
  }
  else
  {
   bsize += (usedblock->BlockSize - bsize);
   blockptr = usedblock->next;
  }
  if(previous!=((void *)0))
   previous->next=blockptr;
  else
   FBLHeader = blockptr;
  usedblock->next = ((void *)0);
  usedblock->BlockSize = bsize;
  return((unsigned char *)usedblock+sizeof(UsedBlockType));
 }
 return(((void *)0));
}

variable_types:
blocksize
unsigned long

variable_types: struct FreeBlockType_ { unsigned long BlockSize; struct FreeBlockType_ *next; } *

variable_types:
bsize
unsigned long

return_type: void *


decompiled_code:
unsigned __int64 m_largest_free_block()
{
unsigned __int64 *v0; // rax
unsigned __int64 v1; // rdx

v0 = (unsigned __int64 *)FBLHeader;
if ( !heaparea )
__assert_fail("heaparea", "memmgr.c", 0xA8u, "m_largest_free_block");
v1 = 0LL;
if ( FBLHeader )
{
do
{
if ( v1 < *v0 )
v1 = *v0;
v0 = (unsigned __int64 *)v0[1];
}
while ( v0 );
if ( v1 )
v1 = (v1 - 8) & 0xFFFFFFFFFFFFFFFCLL;
}
return v1;
}

canonical_decompiled_code:
unsigned __int64 func10()
{
unsigned __int64 *v0; // rax
unsigned __int64 v1; // rdx

v0 = (unsigned __int64 *)FBLHeader;
if ( !heaparea )
__assert_fail("heaparea", "memmgr.c", 0xA8u, "m_largest_free_block");
v1 = 0LL;
if ( FBLHeader )
{
do
{
if ( v1 < *v0 )
v1 = *v0;
v0 = (unsigned __int64 *)v0[1];
}
while ( v0 );
if ( v1 )
v1 = (v1 - 8) & 0xFFFFFFFFFFFFFFFCLL;
}
return v1;
}

original_code:
unsigned long m_largest_free_block(void)
{
 FreeBlockType *blockptr = FBLHeader;
 unsigned long blockfree = 0;
 ((void) sizeof ((heaparea) ? 1 : 0), __extension__ ({ if (heaparea) ; else __assert_fail ("heaparea", "memmgr.c", 168, __extension__ __PRETTY_FUNCTION__); }));
 while(blockptr!=((void *)0))
 {
  if(blockptr->BlockSize > blockfree)
   blockfree = blockptr->BlockSize;
  blockptr=blockptr->next;
 }
 if(blockfree > 0)
 {
  blockfree-=sizeof(UsedBlockType);
  blockfree-=blockfree%4;
 }
 return((blockfree > 0) ? blockfree : 0);
}

canonical_original_code:
unsigned long m_largest_free_block()
{
 struct FreeBlockType_ *blockptr = FBLHeader;
 unsigned long blockfree = 0;
 ((void) sizeof ((heaparea) ? 1 : 0), __extension__ ({ if (heaparea) ; else __assert_fail ("heaparea", "memmgr.c", 168, __extension__ __PRETTY_FUNCTION__); }));
 while(blockptr!=((void *)0))
 {
  if(blockptr->BlockSize > blockfree)
   blockfree = blockptr->BlockSize;
  blockptr=blockptr->next;
 }
 if(blockfree > 0)
 {
  blockfree-=sizeof(UsedBlockType);
  blockfree-=blockfree%4;
 }
 return((blockfree > 0) ? blockfree : 0);
}

variable_types:
blockfree
unsigned long

return_type: unsigned long


decompiled_code:
__int64 m_free_heap()
{
_QWORD *v0; // rax
__int64 v1; // rdx

v0 = (_QWORD *)FBLHeader;
if ( !heaparea )
__assert_fail("heaparea", "memmgr.c", 0xBDu, "m_free_heap");
v1 = 0LL;
if ( FBLHeader )
{
do
{
v1 += *v0;
v0 = (_QWORD *)v0[1];
}
while ( v0 );
}
return v1;
}

canonical_decompiled_code:
__int64 func11()
{
_QWORD *v0; // rax
__int64 v1; // rdx

v0 = (_QWORD *)FBLHeader;
if ( !heaparea )
__assert_fail("heaparea", "memmgr.c", 0xBDu, "m_free_heap");
v1 = 0LL;
if ( FBLHeader )
{
do
{
v1 += *v0;
v0 = (_QWORD *)v0[1];
}
while ( v0 );
}
return v1;
}

original_code:
unsigned long m_free_heap(void)
{
 FreeBlockType * blockptr = FBLHeader;
 unsigned long memfree=0;
 ((void) sizeof ((heaparea) ? 1 : 0), __extension__ ({ if (heaparea) ; else __assert_fail ("heaparea", "memmgr.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 while(blockptr!=((void *)0))
 {
  memfree += blockptr->BlockSize;
  blockptr=blockptr->next;
 }
 return(memfree);
}

canonical_original_code:
unsigned long m_free_heap()
{
 struct FreeBlockType_ *blockptr = FBLHeader;
 unsigned long memfree = 0;
 ((void) sizeof ((heaparea) ? 1 : 0), __extension__ ({ if (heaparea) ; else __assert_fail ("heaparea", "memmgr.c", 189, __extension__ __PRETTY_FUNCTION__); }));
 while(blockptr!=((void *)0))
 {
  memfree += blockptr->BlockSize;
  blockptr=blockptr->next;
 }
 return(memfree);
}

variable_types:
memfree
unsigned long


decompiled_code:
__int64 __fastcall m_strlen(_BYTE *a1)
{
__int64 result; // rax

if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_BYTE *a1)
{
__int64 result; // rax

if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

original_code:
size_t m_strlen(const unsigned char *S)
   {
   size_t Result;
   for (Result = 0; *S++; Result++);
   return Result;
   }

canonical_original_code:
unsigned long m_strlen(unsigned char *S)
   {
   unsigned long Result;
   for (Result = 0; *S++; Result++);
   return Result;
   }

variable_types:
S
unsigned char *

variable_types:
Result
unsigned long


decompiled_code:
__int64 __fastcall allocate_all(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
unsigned int v4; // er13

v2 = m_malloc(a2);
if ( !v2 )
return 0;
v3 = 1LL;
do
{
v4 = v3;
*(_QWORD *)(a1 + 8 * v3 - 8) = v2;
v2 = m_malloc(a2);
++v3;
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
unsigned int v4; // er13

v2 = func9(a2);
if ( !v2 )
return 0;
v3 = 1LL;
do
{
v4 = v3;
*(_QWORD *)(a1 + 8 * v3 - 8) = v2;
v2 = func9(a2);
++v3;
}
while ( v2 );
return v4;
}

original_code:
int allocate_all(void *ptarr[],size_t block_size){
    int i = 0;
    void *pt = m_malloc(block_size);
    while(pt!=((void *)0)){
        ptarr[i++] = pt;
        pt = m_malloc(block_size);
    }
    return i;
}

canonical_original_code:
int allocate_all(void *ptarr[], unsigned long block_size){
    int i = 0;
    void *pt = m_malloc(block_size);
    while(pt!=((void *)0)){
        ptarr[i++] = pt;
        pt = m_malloc(block_size);
    }
    return i;
}

variable_types:
ptarr
void *[]

variable_types:
pt
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // r13
__int64 v4; // rdx
__int64 v5; // rbx
unsigned __int64 v6; // rax
unsigned int *v7; // rbp
signed int v8; // ebx
__int64 v9; // rsi
unsigned int v10; // ebx
__int64 v11; // rdx
__int64 v12; // r14
unsigned __int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // rbx
unsigned __int64 v16; // rax
int v18[6]; // [rsp+0h] [rbp-48h] BYREF
char v19; // [rsp+18h] [rbp-30h] BYREF

v3 = malloc(0x1F4000uLL);
m_init(v3, 2048000LL);
v18[0] = 16;
v18[1] = 13;
v18[2] = 65;
v18[3] = 51;
v18[4] = 182;
v18[5] = 1;
v5 = m_free_heap(v3, 2048000LL, v4);
v6 = m_largest_free_block();
printf("Largest block available %ld, free heap size %ld\n", v6, v5);
v7 = (unsigned int *)v18;
do
{
v8 = *v7;
printf("Allocating all memory in %d byte blocks\n", *v7);
v9 = v8;
v10 = allocate_all((__int64)&ptarr_0, v8);
v12 = m_free_heap(&ptarr_0, v9, v11);
v13 = m_largest_free_block();
printf("Allocation failed for block %d, largest block available %u, free heap size %ld\n", v10, v13, v12);
printf("Deallocating %d blocks\n", v10);
free_all((_QWORD **)&ptarr_0);
v15 = m_free_heap(&ptarr_0, v10, v14);
v16 = m_largest_free_block();
printf("Deallocation done, largest block available %ld, free heap size %ld\n", v16, v15);
puts("================================================================================");
++v7;
}
while ( v7 != (unsigned int *)&v19 );
m_destroy();
free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // r13
__int64 v4; // rdx
__int64 v5; // rbx
unsigned __int64 v6; // rax
unsigned int *v7; // rbp
signed int v8; // ebx
__int64 v9; // rsi
unsigned int v10; // ebx
__int64 v11; // rdx
__int64 v12; // r14
unsigned __int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // rbx
unsigned __int64 v16; // rax
int v18[6]; // [rsp+0h] [rbp-48h] BYREF
char v19; // [rsp+18h] [rbp-30h] BYREF

v3 = malloc(0x1F4000uLL);
func7(v3, 2048000LL);
v18[0] = 16;
v18[1] = 13;
v18[2] = 65;
v18[3] = 51;
v18[4] = 182;
v18[5] = 1;
v5 = func11(v3, 2048000LL, v4);
v6 = func10();
printf("Largest block available %ld, free heap size %ld\n", v6, v5);
v7 = (unsigned int *)v18;
do
{
v8 = *v7;
printf("Allocating all memory in %d byte blocks\n", *v7);
v9 = v8;
v10 = func16((__int64)&ptarr_0, v8);
v12 = func11(&ptarr_0, v9, v11);
v13 = func10();
printf("Allocation failed for block %d, largest block available %u, free heap size %ld\n", v10, v13, v12);
printf("Deallocating %d blocks\n", v10);
free_all((_QWORD **)&ptarr_0);
v15 = func11(&ptarr_0, v10, v14);
v16 = func10();
printf("Deallocation done, largest block available %ld, free heap size %ld\n", v16, v15);
puts("================================================================================");
++v7;
}
while ( v7 != (unsigned int *)&v19 );
func8();
free(v3);
return 0;
}

original_code:
int main(void)
{
    unsigned char *charr= malloc(2048000);
    static void * ptarr[2048000];
    int max = 0;
    int i;
    int size;
    m_init(charr,2048000);
    const int sizes[] = {16,13,65,51,182,1};
    printf("Largest block available %ld, free heap size %ld\n",m_largest_free_block(),m_free_heap());
    for(size = 0; size < 6; size++){
        printf("Allocating all memory in %d byte blocks\n",sizes[size]);
        max = allocate_all(ptarr,sizes[size]);
        printf("Allocation failed for block %d, largest block available %u, free heap size %ld\n",max,(unsigned int)m_largest_free_block(),m_free_heap());
        printf("Deallocating %d blocks\n",max);
        free_all(ptarr);
        printf("Deallocation done, largest block available %ld, free heap size %ld\n",m_largest_free_block(),m_free_heap());
        printf("================================================================================\n");
    }
    m_destroy();
 free(charr);
    return(0);
}

canonical_original_code:
int main()
{
    unsigned char *charr = malloc(2048000);
    static void *ptarr[2048000];
    int max = 0;
    int i;
    int size;
    m_init(charr,2048000);
    int sizes[] = {16,13,65,51,182,1};
    printf("Largest block available %ld, free heap size %ld\n",m_largest_free_block(),m_free_heap());
    for(size = 0; size < 6; size++){
        printf("Allocating all memory in %d byte blocks\n",sizes[size]);
        max = allocate_all(ptarr,sizes[size]);
        printf("Allocation failed for block %d, largest block available %u, free heap size %ld\n",max,(unsigned int)m_largest_free_block(),m_free_heap());
        printf("Deallocating %d blocks\n",max);
        free_all(ptarr);
        printf("Deallocation done, largest block available %ld, free heap size %ld\n",m_largest_free_block(),m_free_heap());
        printf("================================================================================\n");
    }
    m_destroy();
 free(charr);
    return(0);
}

variable_types:
charr
unsigned char *

variable_types: max int

variable_types: size int

variable_types:
sizes
int []


repo: jintwo/sns

decompiled_code:
char *__fastcall label_to_string(__int64 a1, size_t *a2)
{
__int64 v2; // r13
size_t v3; // r14
char *v4; // rbx
const char *v5; // r15
size_t v6; // r12
char *v7; // rbp

v2 = a1;
if ( a1 )
{
v3 = 0LL;
v4 = 0LL;
do
{
v5 = *(const char **)v2;
v6 = strlen(*(const char **)v2);
v7 = (char *)malloc(v6 + 1);
strcpy(v7, v5);
v7[v6] = 46;
v3 += v6 + 1;
if ( v4 )
v4 = (char *)realloc(v4, v3);
else
v4 = (char *)malloc(v3);
strcat(v4, v7);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
else
{
v4 = 0LL;
v3 = 0LL;
}
v4[v3 - 1] = 0;
if ( a2 )
*a2 = v3;
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, size_t *a2)
{
__int64 v2; // r13
size_t v3; // r14
char *v4; // rbx
const char *v5; // r15
size_t v6; // r12
char *v7; // rbp

v2 = a1;
if ( a1 )
{
v3 = 0LL;
v4 = 0LL;
do
{
v5 = *(const char **)v2;
v6 = strlen(*(const char **)v2);
v7 = (char *)malloc(v6 + 1);
strcpy(v7, v5);
v7[v6] = 46;
v3 += v6 + 1;
if ( v4 )
v4 = (char *)realloc(v4, v3);
else
v4 = (char *)malloc(v3);
strcat(v4, v7);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
else
{
v4 = 0LL;
v3 = 0LL;
}
v4[v3 - 1] = 0;
if ( a2 )
*a2 = v3;
return v4;
}

original_code:
char *label_to_string(dns_labels_t *label, size_t *llen)
{
    char *result = ((void *)0);
    size_t total_len = 0;
    dns_labels_t *elem = label;
    while (elem) {
        size_t label_len = strlen(elem->label);
        char *current = malloc(label_len + 1);
        strcpy(current, elem->label);
        current[label_len] = '.';
        total_len += label_len + 1;
        if (!result)
            result = malloc(total_len);
        else
            result = realloc(result, total_len);
        strcat(result, current);
        elem = elem->next;
    }
    result[total_len - 1] = 0;
    if (llen)
        *llen = total_len;
    return result;
}

canonical_original_code:
char *label_to_string(struct label *label, unsigned long *llen)
{
    char *result = ((void *)0);
    unsigned long total_len = 0;
    struct label *elem = label;
    while (elem) {
        unsigned long label_len = strlen(elem->label);
        char *current = malloc(label_len + 1);
        strcpy(current, elem->label);
        current[label_len] = '.';
        total_len += label_len + 1;
        if (!result)
            result = malloc(total_len);
        else
            result = realloc(result, total_len);
        strcat(result, current);
        elem = elem->next;
    }
    result[total_len - 1] = 0;
    if (llen)
        *llen = total_len;
    return result;
}

variable_types: struct label { char *label; struct label *next; } *

variable_types:
llen
unsigned long *

variable_types:
result
char *

variable_types:
current
char *

return_type: char *


decompiled_code:
__int64 __fastcall reverse_label(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = a1;
if ( a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v2;
v2 = result;
if ( !v3 )
break;
result = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx
__int64 v3; // rdx

result = a1;
if ( a1 )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_QWORD *)(result + 8);
*(_QWORD *)(result + 8) = v2;
v2 = result;
if ( !v3 )
break;
result = v3;
}
}
return result;
}

original_code:
dns_labels_t *reverse_label(dns_labels_t *label)
{
    dns_labels_t *root = ((void *)0);
    while (label) {
        dns_labels_t *next = label->next;
        label->next = root;
        root = label;
        label = next;
    }
    return root;
}

canonical_original_code:
struct label *reverse_label(struct label *label)
{
    struct label *root = ((void *)0);
    while (label) {
        struct label *next = label->next;
        label->next = root;
        root = label;
        label = next;
    }
    return root;
}

variable_types:
label
struct label *

return_type: struct label { char *label; struct label *next; } *


decompiled_code:
__int64 __fastcall compare_labels(const __m128i *a1, const __m128i *a2)
{
__int64 v2; // rbp
__m128i *v3; // r13
__m128i *v4; // r12
__int64 v5; // rbx

LODWORD(v2) = 1;
if ( a1 != a2 )
{
v3 = (__m128i *)malloc(0x10uLL);
v4 = (__m128i *)malloc(0x10uLL);
copy_label(a1, v3);
copy_label(a2, v4);
v5 = reverse_label((__int64)v3);
v2 = reverse_label((__int64)v4);
if ( v5 == v2 )
{
LODWORD(v2) = 0;
}
else
{
while ( 1 )
{
if ( v5 && !strcmp(*(const char **)v5, "*") )
{
LODWORD(v2) = 1;
goto LABEL_10;
}
if ( !v2 )
goto LABEL_14;
if ( !strcmp(*(const char **)v2, "*") )
break;
if ( !v5 )
{
LABEL_14:
LOBYTE(v2) = (v2 | v5) == 0;
goto LABEL_10;
}
if ( strcmp(*(const char **)v5, *(const char **)v2) )
{
LODWORD(v2) = 0;
goto LABEL_10;
}
v5 = *(_QWORD *)(v5 + 8);
v2 = *(_QWORD *)(v2 + 8);
if ( v5 == v2 )
{
LODWORD(v2) = 0;
goto LABEL_10;
}
}
LODWORD(v2) = 1;
}
LABEL_10:
free(v3);
free(v4);
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(const __m128i *a1, const __m128i *a2)
{
__int64 v2; // rbp
__m128i *v3; // r13
__m128i *v4; // r12
__int64 v5; // rbx

LODWORD(v2) = 1;
if ( a1 != a2 )
{
v3 = (__m128i *)malloc(0x10uLL);
v4 = (__m128i *)malloc(0x10uLL);
func1(a1, v3);
func1(a2, v4);
v5 = func2((__int64)v3);
v2 = func2((__int64)v4);
if ( v5 == v2 )
{
LODWORD(v2) = 0;
}
else
{
while ( 1 )
{
if ( v5 && !strcmp(*(const char **)v5, "*") )
{
LODWORD(v2) = 1;
goto LABEL_10;
}
if ( !v2 )
goto LABEL_14;
if ( !strcmp(*(const char **)v2, "*") )
break;
if ( !v5 )
{
LABEL_14:
LOBYTE(v2) = (v2 | v5) == 0;
goto LABEL_10;
}
if ( strcmp(*(const char **)v5, *(const char **)v2) )
{
LODWORD(v2) = 0;
goto LABEL_10;
}
v5 = *(_QWORD *)(v5 + 8);
v2 = *(_QWORD *)(v2 + 8);
if ( v5 == v2 )
{
LODWORD(v2) = 0;
goto LABEL_10;
}
}
LODWORD(v2) = 1;
}
LABEL_10:
free(v3);
free(v4);
}
return (unsigned int)v2;
}

original_code:
_Bool compare_labels(dns_labels_t *l1, dns_labels_t *l2)
{
    if (l1 == l2)
        return 1;
    size_t label_size = sizeof(dns_labels_t);
    dns_labels_t *l1_ = malloc(label_size);
    dns_labels_t *l2_ = malloc(label_size);
    copy_label(l1, l1_);
    copy_label(l2, l2_);
    dns_labels_t *c1 = reverse_label(l1_);
    dns_labels_t *c2 = reverse_label(l2_);
    _Bool result = 0;
    while (c1 != c2) {
        if (c1 && !(strcmp(c1->label, "*"))) {
            result = 1;
            break;
        }
        if (c2 && !(strcmp(c2->label, "*"))) {
            result = 1;
            break;
        }
        if (c1 && c2) {
            if (!strcmp(c1->label, c2->label)) {
                c1 = c1->next;
                c2 = c2->next;
                continue;
            } else {
                result = 0;
                break;
            }
        } else if (!c1 && !c2) {
            result = 1;
            break;
        }
        break;
    }
    free(l1_);
    free(l2_);
    return result;
}

canonical_original_code:
_Bool compare_labels(struct label *l1, struct label *l2)
{
    if (l1 == l2)
        return 1;
    unsigned long label_size = sizeof(dns_labels_t);
    struct label *l1_ = malloc(label_size);
    struct label *l2_ = malloc(label_size);
    copy_label(l1, l1_);
    copy_label(l2, l2_);
    struct label *c1 = reverse_label(l1_);
    struct label *c2 = reverse_label(l2_);
    _Bool result = 0;
    while (c1 != c2) {
        if (c1 && !(strcmp(c1->label, "*"))) {
            result = 1;
            break;
        }
        if (c2 && !(strcmp(c2->label, "*"))) {
            result = 1;
            break;
        }
        if (c1 && c2) {
            if (!strcmp(c1->label, c2->label)) {
                c1 = c1->next;
                c2 = c2->next;
                continue;
            } else {
                result = 0;
                break;
            }
        } else if (!c1 && !c2) {
            result = 1;
            break;
        }
        break;
    }
    free(l1_);
    free(l2_);
    return result;
}

user_defined_types: struct label { char *label; struct label *next; }


decompiled_code:
void *__fastcall pack_label(__int64 a1, _QWORD *a2)
{
__int64 v2; // r13
void *v3; // rbp
const char *v4; // r15
size_t v5; // rax
char v6; // r12
size_t v7; // r14
char *v8; // rbx
size_t size; // [rsp+0h] [rbp-48h]

v2 = a1;
if ( a1 )
{
size = 0LL;
v3 = 0LL;
do
{
v4 = *(const char **)v2;
v5 = strlen(*(const char **)v2);
v6 = v5;
v7 = v5 + 1;
v8 = (char *)malloc(v5 + 1);
*v8 = v6;
strcpy(v8 + 1, v4);
size += v7;
if ( v3 )
v3 = realloc(v3, size);
else
v3 = malloc(size);
strcat((char *)v3, v8);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
else
{
v3 = 0LL;
size = 0LL;
}
*a2 = size + 1;
return v3;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, _QWORD *a2)
{
__int64 v2; // r13
void *v3; // rbp
const char *v4; // r15
size_t v5; // rax
char v6; // r12
size_t v7; // r14
char *v8; // rbx
size_t size; // [rsp+0h] [rbp-48h]

v2 = a1;
if ( a1 )
{
size = 0LL;
v3 = 0LL;
do
{
v4 = *(const char **)v2;
v5 = strlen(*(const char **)v2);
v6 = v5;
v7 = v5 + 1;
v8 = (char *)malloc(v5 + 1);
*v8 = v6;
strcpy(v8 + 1, v4);
size += v7;
if ( v3 )
v3 = realloc(v3, size);
else
v3 = malloc(size);
strcat((char *)v3, v8);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
}
else
{
v3 = 0LL;
size = 0LL;
}
*a2 = size + 1;
return v3;
}

original_code:
char *pack_label(dns_labels_t *label, size_t *llen)
{
    char *result = ((void *)0);
    size_t total_len = 0;
    dns_labels_t *elem = label;
    while (elem) {
        size_t label_len = strlen(elem->label);
        char *current = malloc(label_len + 1);
        *current = label_len;
        strcpy(current + 1, elem->label);
        total_len += label_len + 1;
        if (!result)
            result = malloc(total_len);
        else
            result = realloc(result, total_len);
        strcat(result, current);
        elem = elem->next;
    }
    *llen = total_len + 1;
    return result;
}

canonical_original_code:
char *pack_label(struct label *label, unsigned long *llen)
{
    char *result = ((void *)0);
    unsigned long total_len = 0;
    struct label *elem = label;
    while (elem) {
        unsigned long label_len = strlen(elem->label);
        char *current = malloc(label_len + 1);
        *current = label_len;
        strcpy(current + 1, elem->label);
        total_len += label_len + 1;
        if (!result)
            result = malloc(total_len);
        else
            result = realloc(result, total_len);
        strcat(result, current);
        elem = elem->next;
    }
    *llen = total_len + 1;
    return result;
}


decompiled_code:
void *__fastcall pack_header(__int64 a1)
{
void *v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

v1 = malloc(0xCuLL);
v2 = write_uint16(v1, a1, 1LL);
v3 = write_uint16(v2, a1 + 2, 1LL);
v4 = write_uint16(v3, a1 + 4, 1LL);
v5 = write_uint16(v4, a1 + 6, 1LL);
v6 = write_uint16(v5, a1 + 8, 1LL);
write_uint16(v6, a1 + 10, 1LL);
return v1;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1)
{
void *v1; // rbp
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

v1 = malloc(0xCuLL);
v2 = write_uint16(v1, a1, 1LL);
v3 = write_uint16(v2, a1 + 2, 1LL);
v4 = write_uint16(v3, a1 + 4, 1LL);
v5 = write_uint16(v4, a1 + 6, 1LL);
v6 = write_uint16(v5, a1 + 8, 1LL);
write_uint16(v6, a1 + 10, 1LL);
return v1;
}

original_code:
char *pack_header(dns_header_t *header)
{
    size_t header_len = sizeof(dns_header_t);
    char *buf = malloc(header_len);
    char *start = buf;
    buf = write_uint16(buf, &header->id, 1);
    buf = write_uint16(buf, (unsigned short *)&header->flags, 1);
    buf = write_uint16(buf, &header->qdcount, 1);
    buf = write_uint16(buf, &header->ancount, 1);
    buf = write_uint16(buf, &header->nscount, 1);
    buf = write_uint16(buf, &header->arcount, 1);
    return start;
}

canonical_original_code:
char *pack_header(struct dns_header_t *header)
{
    unsigned long header_len = sizeof(dns_header_t);
    char *buf = malloc(header_len);
    char *start = buf;
    buf = write_uint16(buf, &header->id, 1);
    buf = write_uint16(buf, (unsigned short *)&header->flags, 1);
    buf = write_uint16(buf, &header->qdcount, 1);
    buf = write_uint16(buf, &header->ancount, 1);
    buf = write_uint16(buf, &header->nscount, 1);
    buf = write_uint16(buf, &header->arcount, 1);
    return start;
}

variable_types: struct dns_header_t { unsigned short id; union { struct dns_flags_t { unsigned char qr; unsigned char opcode; unsigned char aa; unsigned char tc; unsigned char rd; unsigned char ra; unsigned char z; unsigned char rcode; } flags_s; unsigned short flags; } flags; unsigned short qdcount; } *

variable_types:
buf
char *

variable_types:
start
char *

user_defined_types: struct dns_header_t { unsigned short id; union { struct dns_flags_t flags_s; unsigned short flags; } flags; unsigned short qdcount; }


original_code:
void unpack_header(char *buf, dns_header_t *header)
{
    size_t header_len = sizeof(dns_header_t);
    char *buf_ = malloc(header_len);
    memcpy((void *)buf_, buf, header_len);
    buf_ = read_uint16(buf_, &header->id, 1);
    buf_ = read_uint16(buf_, (unsigned short *)&header->flags, 1);
    buf_ = read_uint16(buf_, &header->qdcount, 1);
    buf_ = read_uint16(buf_, &header->ancount, 1);
    buf_ = read_uint16(buf_, &header->nscount, 1);
    buf_ = read_uint16(buf_, &header->arcount, 1);
}

canonical_original_code:
void unpack_header(char *buf, struct dns_header_t *header)
{
    unsigned long header_len = sizeof(dns_header_t);
    char *buf_ = malloc(header_len);
    memcpy((void *)buf_, buf, header_len);
    buf_ = read_uint16(buf_, &header->id, 1);
    buf_ = read_uint16(buf_, (unsigned short *)&header->flags, 1);
    buf_ = read_uint16(buf_, &header->qdcount, 1);
    buf_ = read_uint16(buf_, &header->ancount, 1);
    buf_ = read_uint16(buf_, &header->nscount, 1);
    buf_ = read_uint16(buf_, &header->arcount, 1);
}

user_defined_types: struct dns_flags_t { unsigned char qr; unsigned char opcode; unsigned char aa; unsigned char tc; unsigned char rd; unsigned char ra; unsigned char z; unsigned char rcode; }


decompiled_code:
__int64 __fastcall unpack_question(_BYTE *a1, _QWORD *a2)
{
_QWORD *v2; // rbp
char *v3; // r12
size_t v4; // rbx
void *v5; // rax
char *v6; // rbx
_QWORD *v7; // r14
__int64 v8; // rax

v2 = malloc(0x10uLL);
*a2 = v2;
v3 = a1 + 1;
v4 = (char)*a1;
if ( *a1 )
{
do
{
v5 = malloc(v4);
*v2 = v5;
memcpy(v5, v3, v4);
v6 = &v3[v4];
v7 = v2;
v2 = malloc(0x10uLL);
v7[1] = v2;
v3 = v6 + 1;
v4 = *v6;
}
while ( v4 );
}
else
{
v7 = 0LL;
}
free((void *)v7[1]);
v7[1] = 0LL;
v8 = read_uint16(v3, a2 + 1, 1LL);
return read_uint16(v8, (char *)a2 + 10, 1LL);
}

original_code:
void unpack_question(char *buf, dns_question_t* question)
{
    char *qdata = buf;
    question->label = malloc(sizeof(dns_labels_t));
    dns_labels_t *elem = question->label;
    dns_labels_t *last = ((void *)0);
    size_t label_len;
    while ((label_len = *qdata++) != 0) {
        elem->label = malloc(label_len);
        memcpy(elem->label, qdata, label_len);
        qdata += label_len;
        last = elem;
        elem->next = malloc(sizeof(dns_labels_t));
        elem = elem->next;
    }
    free(last->next);
    last->next = ((void *)0);
    qdata = read_uint16(qdata, &question->qtype, 1);
    qdata = read_uint16(qdata, &question->qclass, 1);
}

canonical_original_code:
void unpack_question(char *buf, struct dns_question_t *question)
{
    char *qdata = buf;
    question->label = malloc(sizeof(dns_labels_t));
    struct label *elem = question->label;
    struct label *last = ((void *)0);
    unsigned long label_len;
    while ((label_len = *qdata++) != 0) {
        elem->label = malloc(label_len);
        memcpy(elem->label, qdata, label_len);
        qdata += label_len;
        last = elem;
        elem->next = malloc(sizeof(dns_labels_t));
        elem = elem->next;
    }
    free(last->next);
    last->next = ((void *)0);
    qdata = read_uint16(qdata, &question->qtype, 1);
    qdata = read_uint16(qdata, &question->qclass, 1);
}

variable_types: struct dns_question_t { struct label { char *label; struct label *next; } *label; unsigned short qtype; } *

variable_types:
qdata
char *

user_defined_types: struct dns_question_t { struct label *label; unsigned short qtype; }


decompiled_code:
int __fastcall dump_buffer(char *a1, __int64 a2)
{
char *v2; // rbx

v2 = a1;
printf("dump_buffer: ");
if ( a2 )
{
do
printf("0x%hhx ", (unsigned int)*v2++);
while ( &a1[a2] != v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func0(char *a1, __int64 a2)
{
char *v2; // rbx

v2 = a1;
printf("dump_buffer: ");
if ( a2 )
{
do
printf("0x%hhx ", (unsigned int)*v2++);
while ( &a1[a2] != v2 );
}
return putchar(10);
}

original_code:
void dump_buffer(void *buffer, size_t len)
{
    const char *ptr = buffer;
    printf("dump_buffer: ");
    for (int i = 0; i < len; i++) {
        printf("0x%hhx ", *ptr++);
    }
    printf("\n");
}

canonical_original_code:
void dump_buffer(void *buffer, unsigned long len)
{
    char *ptr = buffer;
    printf("dump_buffer: ");
    for (int i = 0; i < len; i++) {
        printf("0x%hhx ", *ptr++);
    }
    printf("\n");
}

variable_types:
buffer
void *

variable_types:
len
unsigned long

variable_types:
ptr
char *

variable_types: i int


repo: jite/jquake

decompiled_code:
__int64 __fastcall FChecks_CmdlineRequest(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_cmdline_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_cmdline_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_cmdline");
if ( (_DWORD)result )
{
if ( LODWORD(allow_f_cmdline[8]) )
{
Cbuf_AddText("say ", "f_cmdline");
Cbuf_AddText(com_args_original, "f_cmdline");
Cbuf_AddText("\n", "f_cmdline");
}
else
{
Cbuf_AddText("say disabled\n", "f_cmdline");
}
*(float *)&v2 = cls[1];
f_cmdline_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_cmdline_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_cmdline_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_cmdline");
if ( (_DWORD)result )
{
if ( LODWORD(allow_f_cmdline[8]) )
{
Cbuf_AddText("say ", "f_cmdline");
Cbuf_AddText(com_args_original, "f_cmdline");
Cbuf_AddText("\n", "f_cmdline");
}
else
{
Cbuf_AddText("say disabled\n", "f_cmdline");
}
*(float *)&v2 = cls[1];
f_cmdline_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_CmdlineRequest (const char *s)
{
 if (cl.spectator || (f_cmdline_reply_time && cls.realtime - f_cmdline_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_cmdline")) {
  if (!allow_f_cmdline.integer) {
   Cbuf_AddText("say disabled\n");
  } else {
   Cbuf_AddText("say ");
   Cbuf_AddText(com_args_original);
   Cbuf_AddText("\n");
  }
  f_cmdline_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_CmdlineRequest(char *s)
{
 if (cl.spectator || (f_cmdline_reply_time && cls.realtime - f_cmdline_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_cmdline")) {
  if (!allow_f_cmdline.integer) {
   Cbuf_AddText("say disabled\n");
  } else {
   Cbuf_AddText("say ");
   Cbuf_AddText(com_args_original);
   Cbuf_AddText("\n");
  }
  f_cmdline_reply_time = cls.realtime;
  return true;
 }
 return false;
}

variable_types:
s
char *

return_type: enum qbool { false=0, true=1 }


decompiled_code:
__int64 __fastcall FChecks_ScriptsRequest(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_scripts_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_scripts_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_scripts");
if ( (_DWORD)result )
{
FChecks_ScriptsResponse(a1, (__int64)"f_scripts");
*(float *)&v2 = cls[1];
f_scripts_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_scripts_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_scripts_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_scripts");
if ( (_DWORD)result )
{
func1(a1, (__int64)"f_scripts");
*(float *)&v2 = cls[1];
f_scripts_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_ScriptsRequest (const char *s)
{
 if (cl.spectator || (f_scripts_reply_time && cls.realtime - f_scripts_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_scripts")) {
  FChecks_ScriptsResponse();
  f_scripts_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_ScriptsRequest(char *s)
{
 if (cl.spectator || (f_scripts_reply_time && cls.realtime - f_scripts_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_scripts")) {
  FChecks_ScriptsResponse();
  f_scripts_reply_time = cls.realtime;
  return true;
 }
 return false;
}


decompiled_code:
__int64 __fastcall FChecks_VersionRequest(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_version_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_version_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_version");
if ( (_DWORD)result )
{
FChecks_VersionResponse();
*(float *)&v2 = cls[1];
f_version_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_version_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_version_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_version");
if ( (_DWORD)result )
{
func4();
*(float *)&v2 = cls[1];
f_version_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_VersionRequest (const char *s)
{
 if (cl.spectator || (f_version_reply_time && cls.realtime - f_version_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_version")) {
  FChecks_VersionResponse();
  f_version_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_VersionRequest(char *s)
{
 if (cl.spectator || (f_version_reply_time && cls.realtime - f_version_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_version")) {
  FChecks_VersionResponse();
  f_version_reply_time = cls.realtime;
  return true;
 }
 return false;
}


decompiled_code:
__int64 __fastcall FChecks_FakeshaftRequest(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_fshaft_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_fshaft_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_fakeshaft");
if ( (_DWORD)result )
{
FChecks_FakeshaftResponse(a1, (__int64)"f_fakeshaft");
*(float *)&v2 = cls[1];
f_fshaft_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_fshaft_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_fshaft_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_fakeshaft");
if ( (_DWORD)result )
{
func7(a1, (__int64)"f_fakeshaft");
*(float *)&v2 = cls[1];
f_fshaft_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_FakeshaftRequest (const char *s)
{
 if (cl.spectator || (f_fshaft_reply_time && cls.realtime - f_fshaft_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_fakeshaft")) {
  FChecks_FakeshaftResponse();
  f_fshaft_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_FakeshaftRequest(char *s)
{
 if (cl.spectator || (f_fshaft_reply_time && cls.realtime - f_fshaft_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_fakeshaft")) {
  FChecks_FakeshaftResponse();
  f_fshaft_reply_time = cls.realtime;
  return true;
 }
 return false;
}


decompiled_code:
__int64 __fastcall FChecks_SystemRequest(__int64 a1)
{
__int64 result; // rax
const char *v2; // rbx
int v3; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_system_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_system_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_system");
if ( (_DWORD)result )
{
v2 = "disabled";
if ( LODWORD(allow_f_system[8]) )
v2 = (const char *)SYSINFO_GetString();
Cbuf_AddText("say ", "f_system");
Cbuf_AddText(v2, "f_system");
Cbuf_AddText("\n", "f_system");
*(float *)&v3 = cls[1];
f_system_reply_time = v3;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
__int64 result; // rax
const char *v2; // rbx
int v3; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_system_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_system_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_system");
if ( (_DWORD)result )
{
v2 = "disabled";
if ( LODWORD(allow_f_system[8]) )
v2 = (const char *)SYSINFO_GetString();
Cbuf_AddText("say ", "f_system");
Cbuf_AddText(v2, "f_system");
Cbuf_AddText("\n", "f_system");
*(float *)&v3 = cls[1];
f_system_reply_time = v3;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_SystemRequest (const char *s)
{
 if (cl.spectator || (f_system_reply_time && cls.realtime - f_system_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_system")) {
  char *sys_string;
  sys_string = (allow_f_system.integer) ? SYSINFO_GetString() : "disabled";
  Cbuf_AddText("say ");
  Cbuf_AddText(sys_string);
  Cbuf_AddText("\n");
  f_system_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_SystemRequest(char *s)
{
 if (cl.spectator || (f_system_reply_time && cls.realtime - f_system_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_system")) {
  char *sys_string;
  sys_string = (allow_f_system.integer) ? SYSINFO_GetString() : "disabled";
  Cbuf_AddText("say ");
  Cbuf_AddText(sys_string);
  Cbuf_AddText("\n");
  f_system_reply_time = cls.realtime;
  return true;
 }
 return false;
}


decompiled_code:
__int64 __fastcall FChecks_SkinRequest(__int64 a1)
{
__int64 result; // rax
float v2; // ebx
_BYTE *v3; // rax
_BYTE *v4; // r12
int v5; // eax
float v6; // xmm0_4
float v7; // xmm0_4
__m128i v8; // xmm3
__m128i v9; // xmm2
int v10; // xmm0_4

result = HIDWORD(cls[1213]);
if ( (_DWORD)result )
{
v5 = 1;
goto LABEL_14;
}
if ( unk_15F0[148] )
{
v2 = r_fullbrightSkins[8];
if ( v2 < 0.0 || v2 > 1.0 )
return result;
goto LABEL_16;
}
v3 = (_BYTE *)Info_ValueForKey((unsigned int)((_DWORD)unk_15F0 + 4), "fbskins");
v4 = v3;
if ( !*v3 )
{
v2 = *(float *)&LC6;
v5 = 1;
if ( unk_15F0[133] )
goto LABEL_16;
LABEL_14:
v7 = r_fullbrightSkins[8];
v2 = *(float *)&LC6;
if ( v7 >= 0.0 )
{
v8 = 0LL;
*(float *)v8.m128i_i32 = (float)v5;
v9 = v8;
*(float *)v9.m128i_i32 = fminf((float)v5, v7);
v2 = COERCE_FLOAT(_mm_cvtsi128_si32(v9));
}
goto LABEL_16;
}
v2 = *(float *)&LC6;
if ( Q_atof(v3) >= 0.0 )
{
v6 = Q_atof(v4);
v5 = 1;
if ( v6 > 1.0 )
goto LABEL_14;
v5 = (int)Q_atof(v4);
v2 = *(float *)&LC6;
if ( v5 )
goto LABEL_14;
}
LABEL_16:
if ( unk_15F0[148] )
return 0LL;
if ( *(float *)&f_skins_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_skins_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_skins");
if ( (_DWORD)result )
{
FChecks_SkinsResponse(v2);
*(float *)&v10 = cls[1];
f_skins_reply_time = v10;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
float v2; // ebx
_BYTE *v3; // rax
_BYTE *v4; // r12
int v5; // eax
float v6; // xmm0_4
float v7; // xmm0_4
__m128i v8; // xmm3
__m128i v9; // xmm2
int v10; // xmm0_4

result = HIDWORD(cls[1213]);
if ( (_DWORD)result )
{
v5 = 1;
goto LABEL_14;
}
if ( unk_15F0[148] )
{
v2 = r_fullbrightSkins[8];
if ( v2 < 0.0 || v2 > 1.0 )
return result;
goto LABEL_16;
}
v3 = (_BYTE *)Info_ValueForKey((unsigned int)((_DWORD)unk_15F0 + 4), "fbskins");
v4 = v3;
if ( !*v3 )
{
v2 = *(float *)&LC6;
v5 = 1;
if ( unk_15F0[133] )
goto LABEL_16;
LABEL_14:
v7 = r_fullbrightSkins[8];
v2 = *(float *)&LC6;
if ( v7 >= 0.0 )
{
v8 = 0LL;
*(float *)v8.m128i_i32 = (float)v5;
v9 = v8;
*(float *)v9.m128i_i32 = fminf((float)v5, v7);
v2 = COERCE_FLOAT(_mm_cvtsi128_si32(v9));
}
goto LABEL_16;
}
v2 = *(float *)&LC6;
if ( Q_atof(v3) >= 0.0 )
{
v6 = Q_atof(v4);
v5 = 1;
if ( v6 > 1.0 )
goto LABEL_14;
v5 = (int)Q_atof(v4);
v2 = *(float *)&LC6;
if ( v5 )
goto LABEL_14;
}
LABEL_16:
if ( unk_15F0[148] )
return 0LL;
if ( *(float *)&f_skins_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_skins_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_skins");
if ( (_DWORD)result )
{
func6(v2);
*(float *)&v10 = cls[1];
f_skins_reply_time = v10;
result = 1LL;
}
}
return result;
}

original_code:
static qbool FChecks_SkinRequest (const char *s)
{
 char *fbs;
 qbool fbskins_policy = (cls.demoplayback || cl.spectator) ? 1 :
  *(fbs = Info_ValueForKey(cl.serverinfo, "fbskins")) ? ((0) >= (1) ? (0) : (Q_atof(fbs)) < (0) ? (0) : (Q_atof(fbs)) > (1) ? (1) : (Q_atof(fbs))) :
  cl.teamfortress ? 0 : 1;
 float fbskins = ((0) >= (fbskins_policy) ? (0) : (r_fullbrightSkins.value) < (0) ? (0) : (r_fullbrightSkins.value) > (fbskins_policy) ? (fbskins_policy) : (r_fullbrightSkins.value));
 if (cl.spectator || (f_skins_reply_time && cls.realtime - f_skins_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_skins")) {
  FChecks_SkinsResponse(fbskins);
  f_skins_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_SkinRequest(char *s)
{
 char *fbs;
 enum qbool fbskins_policy = (cls.demoplayback || cl.spectator) ? 1 :
  *(fbs = Info_ValueForKey(cl.serverinfo, "fbskins")) ? ((0) >= (1) ? (0) : (Q_atof(fbs)) < (0) ? (0) : (Q_atof(fbs)) > (1) ? (1) : (Q_atof(fbs))) :
  cl.teamfortress ? 0 : 1;
 float fbskins = ((0) >= (fbskins_policy) ? (0) : (r_fullbrightSkins.value) < (0) ? (0) : (r_fullbrightSkins.value) > (fbskins_policy) ? (fbskins_policy) : (r_fullbrightSkins.value));
 if (cl.spectator || (f_skins_reply_time && cls.realtime - f_skins_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_skins")) {
  FChecks_SkinsResponse(fbskins);
  f_skins_reply_time = cls.realtime;
  return true;
 }
 return false;
}

variable_types:
fbs
char *

variable_types: fbskins float


decompiled_code:
__int64 __fastcall FChecks_CheckFModRequest(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_mod_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_mod_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_modified");
if ( (_DWORD)result )
{
FMod_Response();
*(float *)&v2 = cls[1];
f_mod_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_mod_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_mod_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_modified");
if ( (_DWORD)result )
{
FMod_Response();
*(float *)&v2 = cls[1];
f_mod_reply_time = v2;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_CheckFModRequest (const char *s)
{
 if (cl.spectator || (f_mod_reply_time && cls.realtime - f_mod_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_modified")) {
  FMod_Response();
  f_mod_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_CheckFModRequest(char *s)
{
 if (cl.spectator || (f_mod_reply_time && cls.realtime - f_mod_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_modified")) {
  FMod_Response();
  f_mod_reply_time = cls.realtime;
  return true;
 }
 return false;
}


decompiled_code:
__int64 FChecks_FServerResponse_Text()
{
__int64 v0; // rdi
__int64 v1; // rdx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
__int16 v4; // [rsp+14h] [rbp-14h]

v0 = (unsigned int)((_DWORD)cls + 3480);
if ( !(unsigned int)NET_StringToAdr(v0, &v3) )
return 0LL;
if ( !v4 )
{
v0 = 27500LL;
v4 = ShortSwap(27500LL);
}
return NET_AdrToString(v0, &v3, v1);
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // rdi
__int64 v1; // rdx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
__int16 v4; // [rsp+14h] [rbp-14h]

v0 = (unsigned int)((_DWORD)cls + 3480);
if ( !(unsigned int)NET_StringToAdr(v0, &v3) )
return 0LL;
if ( !v4 )
{
v0 = 27500LL;
v4 = ShortSwap(27500LL);
}
return NET_AdrToString(v0, &v3, v1);
}

original_code:
static char *FChecks_FServerResponse_Text(void)
{
 netadr_t adr;
 if (!NET_StringToAdr (cls.servername, &adr))
  return ((void *)0);
 if (adr.port == 0)
  adr.port = ShortSwap(27500);
 return NET_AdrToString(adr);
}

canonical_original_code:
static char *FChecks_FServerResponse_Text()
{
 struct netadr_t adr;
 if (!NET_StringToAdr (cls.servername, &adr))
  return ((void *)0);
 if (adr.port == 0)
  adr.port = ShortSwap(27500);
 return NET_AdrToString(adr);
}

variable_types: struct netadr_t { enum netadrtype_t { NA_INVALID=0, NA_LOOPBACK=1, NA_IPv4=2, NA_IPv6=3 } type; union { unsigned char ip[4]; unsigned char ip6[16]; } address; unsigned short port; }

user_defined_types: struct netadr_t { enum netadrtype_t type; union { unsigned char ip[4]; unsigned char ip6[16]; } address; unsigned short port; }


decompiled_code:
__int64 __fastcall FChecks_CheckFServerRequest(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4
__int64 v3; // [rsp-28h] [rbp-28h] BYREF

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_server_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_server_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_server");
if ( (_DWORD)result )
{
result = NET_StringToAdr((unsigned int)((_DWORD)cls + 3480), &v3);
if ( (_DWORD)result )
{
FChecks_FServerResponse();
*(float *)&v2 = cls[1];
f_server_reply_time = v2;
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax
int v2; // xmm0_4
__int64 v3; // [rsp-28h] [rbp-28h] BYREF

result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_server_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_server_reply_time >= 20.0) )
{
result = Util_F_Match(a1, "f_server");
if ( (_DWORD)result )
{
result = NET_StringToAdr((unsigned int)((_DWORD)cls + 3480), &v3);
if ( (_DWORD)result )
{
func13();
*(float *)&v2 = cls[1];
f_server_reply_time = v2;
result = 1LL;
}
}
}
}
return result;
}

original_code:
static qbool FChecks_CheckFServerRequest (const char *s)
{
 netadr_t adr;
 if (cl.spectator || (f_server_reply_time && cls.realtime - f_server_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_server") && NET_StringToAdr (cls.servername, &adr)) {
  FChecks_FServerResponse();
  f_server_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_CheckFServerRequest(char *s)
{
 struct netadr_t adr;
 if (cl.spectator || (f_server_reply_time && cls.realtime - f_server_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_server") && NET_StringToAdr (cls.servername, &adr)) {
  FChecks_FServerResponse();
  f_server_reply_time = cls.realtime;
  return true;
 }
 return false;
}

user_defined_types: enum netadrtype_t { NA_INVALID=0, NA_LOOPBACK=1, NA_IPv4=2, NA_IPv6=3 }


decompiled_code:
__int64 __fastcall FChecks_RulesetFeatureAppend(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( a1 )
result = strlcat(a3, a2, a4);
else
result = strlcat(a5, a2, a6);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( a1 )
result = strlcat(a3, a2, a4);
else
result = strlcat(a5, a2, a6);
return result;
}

original_code:
void FChecks_RulesetFeatureAppend(qbool on, const char *code, char *feat_on_buf,
          size_t feat_on_size, char *feat_off_buf, size_t feat_off_size)
{
 if (on) {
  strlcat(feat_on_buf, code, feat_on_size);
 }
 else {
  strlcat(feat_off_buf, code, feat_off_size);
 }
}

canonical_original_code:
void FChecks_RulesetFeatureAppend(enum qbool on, char *code, char *feat_on_buf, unsigned long feat_on_size, char *feat_off_buf, unsigned long feat_off_size)
{
 if (on) {
  strlcat(feat_on_buf, code, feat_on_size);
 }
 else {
  strlcat(feat_off_buf, code, feat_off_size);
 }
}

variable_types:
on
enum qbool { false=0, true=1 }

variable_types:
code
char *


decompiled_code:
__int64 __fastcall FChecks_CheckFRulesetRequest(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax
size_t v3; // r12
__int64 v4; // rdx
__int64 v5; // rcx
char *v6; // rbx
const char *v7; // rcx
__int64 v8; // rax
__int64 v9; // rsi
__int64 v10; // rax
int v11; // xmm0_4

v1 = Rulesets_Ruleset();
result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_ruleset_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_ruleset_reply_time >= 20.0) )
{
v3 = strlen((const char *)&unk_15F0[4930 * unk_15F0[348510] + 348831]);
result = Util_F_Match(a1, "f_ruleset");
if ( (_DWORD)result )
{
v6 = FChecks_RulesetAdditionString(a1, (__int64)"f_ruleset", v4, v5);
v7 = (const char *)FChecks_FServerResponse_Text();
if ( !v7 )
v7 = "server-na";
v8 = v3;
if ( v3 > 0xF )
v8 = 15LL;
v9 = 15 - v8;
v10 = va("say \"%*s%21s %16s %s%s\"\n", 15 - v8, &unk_F4B, v7, "jqw0.3-dev", v1, v6);
Cbuf_AddText(v10, v9);
*(float *)&v11 = cls[1];
f_ruleset_reply_time = v11;
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax
size_t v3; // r12
__int64 v4; // rdx
__int64 v5; // rcx
char *v6; // rbx
const char *v7; // rcx
__int64 v8; // rax
__int64 v9; // rsi
__int64 v10; // rax
int v11; // xmm0_4

v1 = Rulesets_Ruleset();
result = 0LL;
if ( !unk_15F0[148] )
{
if ( *(float *)&f_ruleset_reply_time == 0.0 || (result = 0LL, cls[1] - *(float *)&f_ruleset_reply_time >= 20.0) )
{
v3 = strlen((const char *)&unk_15F0[4930 * unk_15F0[348510] + 348831]);
result = Util_F_Match(a1, "f_ruleset");
if ( (_DWORD)result )
{
v6 = func16(a1, (__int64)"f_ruleset", v4, v5);
v7 = (const char *)func12();
if ( !v7 )
v7 = "server-na";
v8 = v3;
if ( v3 > 0xF )
v8 = 15LL;
v9 = 15 - v8;
v10 = va("say \"%*s%21s %16s %s%s\"\n", 15 - v8, &unk_F4B, v7, "jqw0.3-dev", v1, v6);
Cbuf_AddText(v10, v9);
*(float *)&v11 = cls[1];
f_ruleset_reply_time = v11;
result = 1LL;
}
}
}
return result;
}

original_code:
static qbool FChecks_CheckFRulesetRequest (const char *s)
{
 char *fServer;
 const char *features;
 char *emptystring = "";
 char *brief_version = "jqw" "0.3-dev";
 char *ruleset = Rulesets_Ruleset();
 size_t name_len = strlen(cl.players[cl.playernum].name);
 size_t pad_len = 15 - ((name_len) < (15) ? (name_len) : (15));
 if (cl.spectator || (f_ruleset_reply_time && cls.realtime - f_ruleset_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_ruleset")) {
  features = FChecks_RulesetAdditionString();
  fServer = FChecks_FServerResponse_Text();
  if (!fServer) {
   fServer = "server-na";
  }
  Cbuf_AddText(va("say \"%*s%21s %16s %s%s\"\n",
   pad_len, emptystring, fServer, brief_version, ruleset, features));
  f_ruleset_reply_time = cls.realtime;
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FChecks_CheckFRulesetRequest(char *s)
{
 char *fServer;
 char *features;
 char *emptystring = "";
 char *brief_version = "jqw" "0.3-dev";
 char *ruleset = Rulesets_Ruleset();
 unsigned long name_len = strlen(cl.players[cl.playernum].name);
 unsigned long pad_len = 15 - ((name_len) < (15) ? (name_len) : (15));
 if (cl.spectator || (f_ruleset_reply_time && cls.realtime - f_ruleset_reply_time < 20))
  return false;
 if (Util_F_Match(s, "f_ruleset")) {
  features = FChecks_RulesetAdditionString();
  fServer = FChecks_FServerResponse_Text();
  if (!fServer) {
   fServer = "server-na";
  }
  Cbuf_AddText(va("say \"%*s%21s %16s %s%s\"\n",
   pad_len, emptystring, fServer, brief_version, ruleset, features));
  f_ruleset_reply_time = cls.realtime;
  return true;
 }
 return false;
}

variable_types:
fServer
char *

variable_types:
features
char *

variable_types:
emptystring
char *

variable_types:
ruleset
char *


decompiled_code:
__int64 __fastcall FChecks_CheckRequest(__int64 a1)
{
FChecks_VersionRequest(a1);
FChecks_CmdlineRequest(a1);
FChecks_SystemRequest(a1);
FChecks_SkinRequest(a1);
FChecks_ScriptsRequest(a1);
FChecks_FakeshaftRequest(a1);
FChecks_CheckFModRequest(a1);
FChecks_CheckFServerRequest(a1);
return FChecks_CheckFRulesetRequest(a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
func5(a1);
func2(a1);
func9(a1);
func10(a1);
func3(a1);
func8(a1);
func11(a1);
func14(a1);
return func17(a1);
}

original_code:
void FChecks_CheckRequest (const char *s)
{
 qbool fcheck = false;
 fcheck |= FChecks_VersionRequest (s);
 fcheck |= FChecks_CmdlineRequest (s);
 fcheck |= FChecks_SystemRequest (s);
 fcheck |= FChecks_SkinRequest (s);
 fcheck |= FChecks_ScriptsRequest (s);
 fcheck |= FChecks_FakeshaftRequest (s);
 fcheck |= FChecks_CheckFModRequest (s);
 fcheck |= FChecks_CheckFServerRequest (s);
 fcheck |= FChecks_CheckFRulesetRequest (s);
 if (fcheck)
  f_reply_time = cls.realtime;
}

canonical_original_code:
void FChecks_CheckRequest(char *s)
{
 enum qbool fcheck = false;
 fcheck |= FChecks_VersionRequest (s);
 fcheck |= FChecks_CmdlineRequest (s);
 fcheck |= FChecks_SystemRequest (s);
 fcheck |= FChecks_SkinRequest (s);
 fcheck |= FChecks_ScriptsRequest (s);
 fcheck |= FChecks_FakeshaftRequest (s);
 fcheck |= FChecks_CheckFModRequest (s);
 fcheck |= FChecks_CheckFServerRequest (s);
 fcheck |= FChecks_CheckFRulesetRequest (s);
 if (fcheck)
  f_reply_time = cls.realtime;
}

variable_types:
fcheck
enum qbool { false=0, true=1 }


decompiled_code:
__int64 FChecks_FRuleset_cmd()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rsi
const char *v3; // rdi
__int64 v4; // rcx
__int64 result; // rax

if ( (int)Cmd_Argc() <= 1 )
goto LABEL_6;
v2 = (const char *)Cmd_Argv(1LL);
v3 = "check";
v4 = 6LL;
do
{
if ( !v4 )
break;
v0 = *v2 < (unsigned int)*v3;
v1 = *v2++ == *v3++;
--v4;
}
while ( v1 );
if ( (!v0 && !v1) == v0 )
result = Cbuf_AddText("say \"f_ruleset\"\n", v2);
else
LABEL_6:
result = Com_Printf(
"Purpose:\n"
" All clients on the server should respond to \"f_ruleset\" message with their client settings in the rep"
"ly\n"
"Usage:\n"
" f_ruleset - prints this help\n"
" f_ruleset check - sends check message to all players on the server\n"
"Flags:\n"
" End of the reply is ruleset name + flags denoting enabled and disabled features:\n"
" m - modified models or sounds\n"
" s - movement scripts\n"
" f - enemy skin forcing\n"
" i - side step aid (strafescript)\n"
" flags that start with + mean feature is enabled, - means disabled\n");
return result;
}

canonical_decompiled_code:
__int64 func0()
{
bool v0; // cf
bool v1; // zf
const char *v2; // rsi
const char *v3; // rdi
__int64 v4; // rcx
__int64 result; // rax

if ( (int)Cmd_Argc() <= 1 )
goto LABEL_6;
v2 = (const char *)Cmd_Argv(1LL);
v3 = "check";
v4 = 6LL;
do
{
if ( !v4 )
break;
v0 = *v2 < (unsigned int)*v3;
v1 = *v2++ == *v3++;
--v4;
}
while ( v1 );
if ( (!v0 && !v1) == v0 )
result = Cbuf_AddText("say \"f_ruleset\"\n", v2);
else
LABEL_6:
result = Com_Printf(
"Purpose:\n"
" All clients on the server should respond to \"f_ruleset\" message with their client settings in the rep"
"ly\n"
"Usage:\n"
" f_ruleset - prints this help\n"
" f_ruleset check - sends check message to all players on the server\n"
"Flags:\n"
" End of the reply is ruleset name + flags denoting enabled and disabled features:\n"
" m - modified models or sounds\n"
" s - movement scripts\n"
" f - enemy skin forcing\n"
" i - side step aid (strafescript)\n"
" flags that start with + mean feature is enabled, - means disabled\n");
return result;
}

original_code:
void FChecks_FRuleset_cmd(void)
{
 if (Cmd_Argc() < 2 || strcmp(Cmd_Argv(1), "check") != 0) {
  Com_Printf("Purpose:\n  "
   "All clients on the server should respond to \"f_ruleset\" message with their client settings in the reply\n"
   "Usage:\n  f_ruleset - prints this help\n"
   "  f_ruleset check - sends check message to all players on the server\n"
   "Flags:\n  End of the reply is ruleset name + flags denoting enabled and disabled features:\n"
   "  m - modified models or sounds\n"
   "  s - movement scripts\n"
   "  f - enemy skin forcing\n"
   "  i - side step aid (strafescript)\n"
   "  flags that start with + mean feature is enabled, - means disabled\n");
 }
 else {
  Cbuf_AddText("say \"f_ruleset\"\n");
 }
}

canonical_original_code:
void FChecks_FRuleset_cmd()
{
 if (Cmd_Argc() < 2 || strcmp(Cmd_Argv(1), "check") != 0) {
  Com_Printf("Purpose:\n  "
   "All clients on the server should respond to \"f_ruleset\" message with their client settings in the reply\n"
   "Usage:\n  f_ruleset - prints this help\n"
   "  f_ruleset check - sends check message to all players on the server\n"
   "Flags:\n  End of the reply is ruleset name + flags denoting enabled and disabled features:\n"
   "  m - modified models or sounds\n"
   "  s - movement scripts\n"
   "  f - enemy skin forcing\n"
   "  i - side step aid (strafescript)\n"
   "  flags that start with + mean feature is enabled, - means disabled\n");
 }
 else {
  Cbuf_AddText("say \"f_ruleset\"\n");
 }
}


decompiled_code:
__int64 __fastcall FChecks_ScriptsResponse(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = allow_scripts[16];
if ( v2 <= 0 )
return Cbuf_AddText("say not using scripts\n", a2);
if ( v2 <= 1 )
return Cbuf_AddText("say using simple scripts\n", a2);
return Cbuf_AddText("say using advanced scripts\n", a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = allow_scripts[16];
if ( v2 <= 0 )
return Cbuf_AddText("say not using scripts\n", a2);
if ( v2 <= 1 )
return Cbuf_AddText("say using simple scripts\n", a2);
return Cbuf_AddText("say using advanced scripts\n", a2);
}

original_code:
static void FChecks_ScriptsResponse (void)
{
 if (allow_scripts.integer < 1)
  Cbuf_AddText ("say not using scripts\n");
 else if (allow_scripts.integer < 2)
  Cbuf_AddText ("say using simple scripts\n");
 else
  Cbuf_AddText ("say using advanced scripts\n");
}

canonical_original_code:
static void FChecks_ScriptsResponse()
{
 if (allow_scripts.integer < 1)
  Cbuf_AddText ("say not using scripts\n");
 else if (allow_scripts.integer < 2)
  Cbuf_AddText ("say using simple scripts\n");
 else
  Cbuf_AddText ("say using advanced scripts\n");
}


decompiled_code:
__int64 FChecks_VersionResponse()
{
const char *v0; // rsi
__int64 v1; // rax

v0 = (const char *)VersionString();
v1 = va("say jQuake %s Linux64:GL\n", v0);
return Cbuf_AddText(v1, v0);
}

canonical_decompiled_code:
__int64 func4()
{
const char *v0; // rsi
__int64 v1; // rax

v0 = (const char *)VersionString();
v1 = va("say jQuake %s Linux64:GL\n", v0);
return Cbuf_AddText(v1, v0);
}

original_code:
static void FChecks_VersionResponse (void)
{
 Cbuf_AddText (va("say jQuake %s " "Linux64" ":" "GL" "\n", VersionString()));
}

canonical_original_code:
static void FChecks_VersionResponse()
{
 Cbuf_AddText (va("say jQuake %s " "Linux64" ":" "GL" "\n", VersionString()));
}


decompiled_code:
__int64 __fastcall FChecks_SkinsResponse(float a1)
{
const char *v1; // rdx
const char *v2; // rsi
__int64 v3; // rax

v1 = ", enemy skins forcing";
if ( !enemyforceskins[16] )
v1 = (const char *)&unk_F4B;
if ( a1 <= 0.0 )
{
v2 = v1;
v3 = va("say not using fullbright skins%s\n", v1);
}
else
{
v2 = (const char *)(unsigned int)(int)(float)(a1 * 100.0);
v3 = va("say all skins %d%% fullbright%s\n", v2, v1);
}
return Cbuf_AddText(v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(float a1)
{
const char *v1; // rdx
const char *v2; // rsi
__int64 v3; // rax

v1 = ", enemy skins forcing";
if ( !enemyforceskins[16] )
v1 = (const char *)&unk_F4B;
if ( a1 <= 0.0 )
{
v2 = v1;
v3 = va("say not using fullbright skins%s\n", v1);
}
else
{
v2 = (const char *)(unsigned int)(int)(float)(a1 * 100.0);
v3 = va("say all skins %d%% fullbright%s\n", v2, v1);
}
return Cbuf_AddText(v3, v2);
}

original_code:
static void FChecks_SkinsResponse (float fbskins)
{
 char *sf = enemyforceskins.integer ? ", enemy skins forcing" : "";
 if (fbskins > 0)
  Cbuf_AddText (va("say all skins %d%% fullbright%s\n", (int) (fbskins * 100), sf));
 else
  Cbuf_AddText (va("say not using fullbright skins%s\n", sf));
}

canonical_original_code:
static void FChecks_SkinsResponse(float fbskins)
{
 char *sf = enemyforceskins.integer ? ", enemy skins forcing" : "";
 if (fbskins > 0)
  Cbuf_AddText (va("say all skins %d%% fullbright%s\n", (int) (fbskins * 100), sf));
 else
  Cbuf_AddText (va("say not using fullbright skins%s\n", sf));
}

variable_types:
sf
char *


decompiled_code:
__int64 __fastcall FChecks_FakeshaftResponse(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
__int64 v4; // rax

if ( LODWORD(cl_fakeshaft[16]) == 2 )
return Cbuf_AddText("say fakeshaft 2 (emulation of fakeshaft 0 for servers with antilag feature)\n", a2);
v2 = cl_fakeshaft[8];
if ( v2 > 0.999 )
return Cbuf_AddText("say fakeshaft on\n", a2);
if ( v2 < 0.001 )
return Cbuf_AddText("say fakeshaft off\n", a2);
v4 = va("say fakeshaft %.1f%%\n", v2 * 100.0);
return Cbuf_AddText(v4, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
double v2; // xmm0_8
__int64 v4; // rax

if ( LODWORD(cl_fakeshaft[16]) == 2 )
return Cbuf_AddText("say fakeshaft 2 (emulation of fakeshaft 0 for servers with antilag feature)\n", a2);
v2 = cl_fakeshaft[8];
if ( v2 > 0.999 )
return Cbuf_AddText("say fakeshaft on\n", a2);
if ( v2 < 0.001 )
return Cbuf_AddText("say fakeshaft off\n", a2);
v4 = va("say fakeshaft %.1f%%\n", v2 * 100.0);
return Cbuf_AddText(v4, a2);
}

original_code:
static void FChecks_FakeshaftResponse (void)
{
 if (cl_fakeshaft.integer == 2)
  Cbuf_AddText("say fakeshaft 2 (emulation of fakeshaft 0 for servers with antilag feature)\n");
 else if (cl_fakeshaft.value > 0.999)
  Cbuf_AddText("say fakeshaft on\n");
 else if (cl_fakeshaft.value < 0.001)
  Cbuf_AddText("say fakeshaft off\n");
 else
  Cbuf_AddText(va("say fakeshaft %.1f%%\n", cl_fakeshaft.value * 100.0));
}

canonical_original_code:
static void FChecks_FakeshaftResponse()
{
 if (cl_fakeshaft.integer == 2)
  Cbuf_AddText("say fakeshaft 2 (emulation of fakeshaft 0 for servers with antilag feature)\n");
 else if (cl_fakeshaft.value > 0.999)
  Cbuf_AddText("say fakeshaft on\n");
 else if (cl_fakeshaft.value < 0.001)
  Cbuf_AddText("say fakeshaft off\n");
 else
  Cbuf_AddText(va("say fakeshaft %.1f%%\n", cl_fakeshaft.value * 100.0));
}


decompiled_code:
const char *FChecks_FServerResponse()
{
const char *result; // rax
const char *v1; // rsi
__int64 v2; // rax

result = (const char *)FChecks_FServerResponse_Text();
if ( result )
{
v1 = result;
v2 = va("say jQuake f_server response: %s\n", result);
result = (const char *)Cbuf_AddText(v2, v1);
}
return result;
}

canonical_decompiled_code:
const char *func13()
{
const char *result; // rax
const char *v1; // rsi
__int64 v2; // rax

result = (const char *)func12();
if ( result )
{
v1 = result;
v2 = va("say jQuake f_server response: %s\n", result);
result = (const char *)Cbuf_AddText(v2, v1);
}
return result;
}

original_code:
static void FChecks_FServerResponse (void)
{
 char *text = FChecks_FServerResponse_Text();
 if (!text)
  return;
 Cbuf_AddText(va("say jQuake f_server response: %s\n", text));
}

canonical_original_code:
static void FChecks_FServerResponse()
{
 char *text = FChecks_FServerResponse_Text();
 if (!text)
  return;
 Cbuf_AddText(va("say jQuake f_server response: %s\n", text));
}

variable_types:
text
char *