displayText

decompiled_code:
int __fastcall displayText(int a1, const char *a2)
{
int result; // eax

if ( intermediateValueFile )
{
if ( displayLevel >= a1 )
{
fprintf(intermediateValueFile, a2);
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, const char *a2)
{
int result; // eax

if ( intermediateValueFile )
{
if ( displayLevel >= a1 )
{
fprintf(intermediateValueFile, a2);
fputc(10, intermediateValueFile);
result = fputc(10, intermediateValueFile);
}
}
return result;
}

original_code:
void displayText(int level, const char *text)
{
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, text);
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}

canonical_original_code:
void displayText(int level, char *text)
{
    if ((intermediateValueFile) && (level <= displayLevel)) {
        fprintf(intermediateValueFile, text);
        fprintf(intermediateValueFile, "\n");
        fprintf(intermediateValueFile, "\n");
    }
}


main

canonical_name: main

repo: jimmycao/slurm-client

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx

operation("get total nodes and slots", argv, envp);
operation("get available nodes and slots", argv, v3);
operation("deallocate slurm_jobid=418 job_return_code=0:slurm_jobid=417 job_return_code=-1", argv, v4);
return 0;
}

original_code:
int main(void)
{
  char *query_total = "get total nodes and slots";
  operation(query_total);
  char *query_available = "get available nodes and slots";
  operation(query_available);
  char *deallocate = "deallocate slurm_jobid=418 job_return_code=0:slurm_jobid=417 job_return_code=-1";
        operation(deallocate);
        return 0;
}

canonical_original_code:
int main()
{
  char *query_total = "get total nodes and slots";
  operation(query_total);
  char *query_available = "get available nodes and slots";
  operation(query_available);
  char *deallocate = "deallocate slurm_jobid=418 job_return_code=0:slurm_jobid=417 job_return_code=-1";
        operation(deallocate);
        return 0;
}

variable_types:
deallocate
char *

return_type: int


operation

decompiled_code:
__int64 __fastcall operation(void *buf)
{
int v1; // eax
int v2; // ebp
socklen_t v3; // edx
size_t v4; // rax
__int64 result; // rax
__int16 v6; // [rsp+Ch] [rbp-203Ch] BYREF
char cp[16]; // [rsp+10h] [rbp-2038h] BYREF
struct sockaddr v8; // [rsp+20h] [rbp-2028h] BYREF
char bufa[8216]; // [rsp+30h] [rbp-2018h] BYREF

get_IP_PORT(cp, &v6);
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("ERROR: socket");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
v8 = 0LL;
v8.sa_family = 2;
*(_DWORD *)&v8.sa_data[2] = inet_addr(cp);
*(_WORD *)v8.sa_data = _bswap_16(v6);
if ( connect(v2, &v8, v3) < 0 )
{
perror("ERROR: connect");
result = 0xFFFFFFFFLL;
}
else
{
v4 = strlen((const char *)buf);
if ( send(v2, buf, v4 + 1, 0) < 0 )
{
perror("ERROR: send");
result = 0xFFFFFFFFLL;
}
else if ( recv(v2, bufa, 0x2000uLL, 0) < 0 )
{
perror("ERROR: recv");
result = 0xFFFFFFFFLL;
}
else
{
close(v2);
printf("recv_buf = %s\n", bufa);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf)
{
int v1; // eax
int v2; // ebp
socklen_t v3; // edx
size_t v4; // rax
__int64 result; // rax
__int16 v6; // [rsp+Ch] [rbp-203Ch] BYREF
char cp[16]; // [rsp+10h] [rbp-2038h] BYREF
struct sockaddr v8; // [rsp+20h] [rbp-2028h] BYREF
char bufa[8216]; // [rsp+30h] [rbp-2018h] BYREF

get_IP_PORT(cp, &v6);
v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
perror("ERROR: socket");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
v8 = 0LL;
v8.sa_family = 2;
*(_DWORD *)&v8.sa_data[2] = inet_addr(cp);
*(_WORD *)v8.sa_data = func0(v6);
if ( connect(v2, &v8, v3) < 0 )
{
perror("ERROR: connect");
result = 0xFFFFFFFFLL;
}
else
{
v4 = strlen((const char *)buf);
if ( send(v2, buf, v4 + 1, 0) < 0 )
{
perror("ERROR: send");
result = 0xFFFFFFFFLL;
}
else if ( recv(v2, bufa, 0x2000uLL, 0) < 0 )
{
perror("ERROR: recv");
result = 0xFFFFFFFFLL;
}
else
{
close(v2);
printf("recv_buf = %s\n", bufa);
result = 0LL;
}
}
}
return result;
}

original_code:
int operation(char *cmd_str)
{
 char IP[16];
 uint32_t PORT;
 struct sockaddr_in address;
 int socket_fd;
 char recv_buf[8192];
 get_IP_PORT(IP, &PORT);
 if(socket_fd = socket(2, SOCK_STREAM, 0), socket_fd < 0){
  perror("ERROR: socket");
  return -1;
 }
 bzero(&address, sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = inet_addr(IP);
 address.sin_port = htons(PORT);
 if(connect(socket_fd, (struct sockaddr*)&address, sizeof(address)) < 0){
  perror("ERROR: connect");
  return -1;
 }
 if(send(socket_fd, cmd_str, strlen(cmd_str) + 1, 0) < 0){
  perror("ERROR: send");
  return -1;
 }
 if(recv(socket_fd, recv_buf, 8192, 0) < 0){
  perror("ERROR: recv");
  return -1;
 }
 close(socket_fd);
 printf("recv_buf = %s\n", recv_buf);
 return 0;
}

canonical_original_code:
int operation(char *cmd_str)
{
 char IP[16];
 unsigned int PORT;
 struct sockaddr_in address;
 int socket_fd;
 char recv_buf[8192];
 get_IP_PORT(IP, &PORT);
 if(socket_fd = socket(2, SOCK_STREAM, 0), socket_fd < 0){
  perror("ERROR: socket");
  return -1;
 }
 bzero(&address, sizeof(address));
 address.sin_family = 2;
 address.sin_addr.s_addr = inet_addr(IP);
 address.sin_port = htons(PORT);
 if(connect(socket_fd, (struct sockaddr *)&address, sizeof(address)) < 0){
  perror("ERROR: connect");
  return -1;
 }
 if(send(socket_fd, cmd_str, strlen(cmd_str) + 1, 0) < 0){
  perror("ERROR: send");
  return -1;
 }
 if(recv(socket_fd, recv_buf, 8192, 0) < 0){
  perror("ERROR: recv");
  return -1;
 }
 close(socket_fd);
 printf("recv_buf = %s\n", recv_buf);
 return 0;
}

variable_types:
IP
char [16]

variable_types:
PORT
unsigned int

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

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


repo: jimstudt/ook-decoder

decompiled_code:
__int64 __fastcall ook_add_pulse(__int64 a1, int a2, int a3, int a4)
{
unsigned int v4; // eax
_DWORD *v5; // r8

v4 = *(_DWORD *)(a1 + 8);
if ( v4 >= *(_DWORD *)(a1 + 12) )
return 0xFFFFFFFFLL;
v5 = (_DWORD *)(a1 + 12LL * v4);
v5[4] = a2;
v5[5] = a3;
v5[6] = a4;
*(_DWORD *)(a1 + 8) = v4 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3, int a4)
{
unsigned int v4; // eax
_DWORD *v5; // r8

v4 = *(_DWORD *)(a1 + 8);
if ( v4 >= *(_DWORD *)(a1 + 12) )
return 0xFFFFFFFFLL;
v5 = (_DWORD *)(a1 + 12LL * v4);
v5[4] = a2;
v5[5] = a3;
v5[6] = a4;
*(_DWORD *)(a1 + 8) = v4 + 1;
return 0LL;
}

original_code:
int ook_add_pulse( struct ook_burst *burst, uint32_t hiNs, uint32_t lowNs, int32_t freqOffsetHz)
{
    if ( burst->pulses < burst->allocatedPulses) {
 burst->pulse[burst->pulses].hiNanoseconds = hiNs;
 burst->pulse[burst->pulses].lowNanoseconds = lowNs;
 burst->pulse[burst->pulses].frequencyOffsetHz = freqOffsetHz;
 burst->pulses++;
 return 0;
    }
    return -1;
}

canonical_original_code:
int ook_add_pulse(struct ook_burst *burst, unsigned int hiNs, unsigned int lowNs, int freqOffsetHz)
{
    if ( burst->pulses < burst->allocatedPulses) {
 burst->pulse[burst->pulses].hiNanoseconds = hiNs;
 burst->pulse[burst->pulses].lowNanoseconds = lowNs;
 burst->pulse[burst->pulses].frequencyOffsetHz = freqOffsetHz;
 burst->pulses++;
 return 0;
    }
    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:
hiNs
unsigned int

variable_types:
lowNs
unsigned int

variable_types: freqOffsetHz int

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


original_code:
int ook_encode( struct ook_burst *burst, void **dataReturn, size_t *sizeReturn)
{
    size_t maxSize = sizeof(*burst) + sizeof(burst->pulse[0])*burst->pulses + 64 ;
    void *data = malloc( maxSize);
    if ( data == 0) return -1;
    void *thumb = data;
    size_t left = maxSize;
    uint32_t vers = 0x36360001;
    { if ( left < 4) goto Overflow; memcpy( thumb, &(vers), 4); thumb+=4; left-=4; };
    { if ( left < 8) goto Overflow; memcpy( thumb, &(burst->positionNanoseconds), 8); thumb+=8; left-=8; };
    { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulses), 4); thumb+=4; left-=4; };
    for ( int i = 0; i < burst->pulses; i++) {
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].hiNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].lowNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].frequencyOffsetHz), 4); thumb+=4; left-=4; };
    }
    *dataReturn = data;
    *sizeReturn = thumb-data;
    return 0;
  Overflow:
    return -1;
}

canonical_original_code:
int ook_encode(struct ook_burst *burst, void **dataReturn, unsigned long *sizeReturn)
{
    unsigned long maxSize = sizeof(*burst) + sizeof(burst->pulse[0])*burst->pulses + 64;
    void *data = malloc( maxSize);
    if ( data == 0) return -1;
    void *thumb = data;
    unsigned long left = maxSize;
    unsigned int vers = 0x36360001;
    { if ( left < 4) goto Overflow; memcpy( thumb, &(vers), 4); thumb+=4; left-=4; };
    { if ( left < 8) goto Overflow; memcpy( thumb, &(burst->positionNanoseconds), 8); thumb+=8; left-=8; };
    { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulses), 4); thumb+=4; left-=4; };
    for ( int i = 0; i < burst->pulses; i++) {
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].hiNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].lowNanoseconds), 4); thumb+=4; left-=4; };
 { if ( left < 4) goto Overflow; memcpy( thumb, &(burst->pulse[i].frequencyOffsetHz), 4); thumb+=4; left-=4; };
    }
    *dataReturn = data;
    *sizeReturn = thumb-data;
    return 0;
  Overflow:
    return -1;
}

variable_types:
dataReturn
void **

variable_types:
sizeReturn
unsigned long *

variable_types:
maxSize
unsigned long

variable_types:
data
void *

variable_types:
thumb
void *

variable_types:
left
unsigned long

variable_types:
vers
unsigned int

variable_types: i int

user_defined_types: struct ook_pulse { unsigned int hiNanoseconds; unsigned int lowNanoseconds; int frequencyOffsetHz; }


original_code:
int ook_decode_from_socket( int sock, struct ook_burst **burstReturn, struct sockaddr *from, socklen_t *fromLen, int verbose)
{
    struct ook_burst *burst = 0;
    unsigned char buf[65536];
    int e=0;
    do {
 e = recvfrom( sock, buf, sizeof(buf), 0, from, fromLen);
 if ( e == -1 && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4)) continue;
 if ( e == -1) return -1;
    } while(0);
    if ( verbose) fprintf(stderr,"Received %u bytes\n", e);
    uint32_t left = e;
    unsigned char *thumb = buf;
    uint32_t vers = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    if ( vers != 0x36360001) goto Fail;
    uint64_t pos = ({ uint64_t v; if ( left<8) goto Fail; memcpy(&v,thumb,8); thumb+=8; left -= 8; v; });
    uint32_t pulses = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    burst = ook_allocate_burst( pulses);
    if ( !burst) goto Fail;
    burst->positionNanoseconds = pos;
    for ( int i = 0; i < pulses; i++) {
 uint32_t hi = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 uint32_t low = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 int32_t freq = ({ int32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 if ( ook_add_pulse( burst, hi, low, freq) < 0) goto Fail;
    }
    if ( left > 0) goto Fail;
    *burstReturn = burst;
    return 1;
  Fail:
    *burstReturn = 0;
    if (burst) free(burst);
    return 0;
}

canonical_original_code:
int ook_decode_from_socket(int sock, struct ook_burst **burstReturn, struct sockaddr *from, unsigned int *fromLen, int verbose)
{
    struct ook_burst *burst = 0;
    unsigned char buf[65536];
    int e = 0;
    do {
 e = recvfrom( sock, buf, sizeof(buf), 0, from, fromLen);
 if ( e == -1 && ((*__errno_location ()) == 11 || (*__errno_location ()) == 4)) continue;
 if ( e == -1) return -1;
    } while(0);
    if ( verbose) fprintf(stderr,"Received %u bytes\n", e);
    unsigned int left = e;
    unsigned char *thumb = buf;
    unsigned int vers = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    if ( vers != 0x36360001) goto Fail;
    unsigned long pos = ({ uint64_t v; if ( left<8) goto Fail; memcpy(&v,thumb,8); thumb+=8; left -= 8; v; });
    unsigned int pulses = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
    burst = ook_allocate_burst( pulses);
    if ( !burst) goto Fail;
    burst->positionNanoseconds = pos;
    for ( int i = 0; i < pulses; i++) {
 unsigned int hi = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 unsigned int low = ({ uint32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 int freq = ({ int32_t v; if ( left<4) goto Fail; memcpy(&v,thumb,4); thumb+=4; left -= 4; v; });
 if ( ook_add_pulse( burst, hi, low, freq) < 0) goto Fail;
    }
    if ( left > 0) goto Fail;
    *burstReturn = burst;
    return 1;
  Fail:
    *burstReturn = 0;
    if (burst) free(burst);
    return 0;
}

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 { unsigned short sa_family; char sa_data[14]; } *

variable_types:
fromLen
unsigned int *

variable_types: verbose int

variable_types:
buf
unsigned char [65536]

variable_types: e int

variable_types:
left
unsigned int

variable_types:
thumb
unsigned char *

variable_types:
pos
unsigned long

variable_types:
pulses
unsigned int

variable_types:
hi
unsigned int

variable_types:
low
unsigned int

variable_types: freq int


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, _QWORD *a9, int a10)
{
__int64 v13; // r14
_BYTE *v14; // r9
int v15; // eax
__int64 v16; // rdx
int v17; // esi
unsigned int *v18; // rdi
unsigned int v19; // er10
__int64 v20; // rcx
unsigned int v21; // er11
unsigned int v22; // er8
_BYTE *ptr; // [rsp+10h] [rbp-40h]
int v25; // [rsp+18h] [rbp-38h]

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

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, _QWORD *a9, int a10)
{
__int64 v13; // r14
_BYTE *v14; // r9
int v15; // eax
__int64 v16; // rdx
int v17; // esi
unsigned int *v18; // rdi
unsigned int v19; // er10
__int64 v20; // rcx
unsigned int v21; // er11
unsigned int v22; // er8
_BYTE *ptr; // [rsp+10h] [rbp-40h]
int v25; // [rsp+18h] [rbp-38h]

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

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


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

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

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

v1 = *a1 + 11;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = (_BYTE *)(*a1 + 1);
while ( !*v3 )
{
if ( ++v3 == (_BYTE *)v1 )
goto LABEL_2;
}
result = 0LL;
}
else
{
LABEL_2:
result = 1LL;
*a1 = v1;
}
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


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

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

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

v1 = *a1 + 41;
if ( *(_BYTE *)*a1 == 1 )
{
v3 = (_BYTE *)(*a1 + 1);
while ( !*v3 )
{
if ( ++v3 == (_BYTE *)v1 )
goto LABEL_2;
}
result = 0LL;
}
else
{
LABEL_2:
result = 1LL;
*a1 = v1;
}
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(__int64 *a1)
{
_BYTE *v1; // rdx
__int64 v2; // rcx
__int64 result; // rax
_BYTE *v4; // rax

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
_BYTE *v1; // rdx
__int64 v2; // rcx
__int64 result; // rax
_BYTE *v4; // rax

v1 = (_BYTE *)*a1;
v2 = *a1 + 6;
if ( *(_BYTE *)*a1 == 1 )
{
v4 = v1 + 1;
while ( !*v4 )
{
if ( ++v4 == (_BYTE *)v2 )
goto LABEL_2;
}
result = 1LL;
*a1 = (__int64)(v1 + 2);
}
else
{
LABEL_2:
result = 0LL;
*a1 = v2;
}
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(__int64 *a1)
{
unsigned int v1; // er13
unsigned int v2; // eax
unsigned int v3; // er12

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

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

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

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)
{
int v1; // er12
size_t v2; // rax
struct in_addr inp[4]; // [rsp+0h] [rbp-A0h] BYREF
char s[144]; // [rsp+10h] [rbp-90h] BYREF

v1 = socket(2, 2, 17);
if ( v1 != -1 )
{
*(_OWORD *)&inp[0].s_addr = 0LL;
LOWORD(inp[0].s_addr) = 2;
HIWORD(inp[0].s_addr) = _bswap_16_constprop_0(2LL, 2LL);
if ( inet_aton("127.0.0.1", &inp[1]) )
{
snprintf(s, 0x80uLL, "%s:1|g", a1);
v2 = strlen(s);
if ( sendto(v1, s, v2, 0, (const struct sockaddr *)inp, 0x10u) != -1 )
{
close(v1);
return 0LL;
}
}
else
{
fprintf(stderr, "inet_aton() failed for address '%s'\n", "127.0.0.1");
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
int v1; // er12
size_t v2; // rax
struct in_addr inp[4]; // [rsp+0h] [rbp-A0h] BYREF
char s[144]; // [rsp+10h] [rbp-90h] BYREF

v1 = socket(2, 2, 17);
if ( v1 != -1 )
{
*(_OWORD *)&inp[0].s_addr = 0LL;
LOWORD(inp[0].s_addr) = 2;
HIWORD(inp[0].s_addr) = func1(2LL, 2LL);
if ( inet_aton("127.0.0.1", &inp[1]) )
{
snprintf(s, 0x80uLL, "%s:1|g", a1);
v2 = strlen(s);
if ( sendto(v1, s, v2, 0, (const struct sockaddr *)inp, 0x10u) != -1 )
{
close(v1);
return 0LL;
}
}
else
{
fprintf(stderr, "inet_aton() failed for address '%s'\n", "127.0.0.1");
}
}
return 0xFFFFFFFFLL;
}

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]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
int v4; // er13
char *v5; // r15
int v6; // eax
int v8; // er12
char *v9; // r15
int v10; // eax
_DWORD *v11; // r10
_DWORD *v12; // r9
unsigned int v13; // er8
__int64 v14; // rsi
unsigned int v15; // edi
unsigned __int8 v16; // dl
char *v17; // rcx
__int64 v18; // rax
_BYTE *v19; // rax
_BYTE *v20; // r8
const char *v21; // rcx
int *v22; // rax
char *v23; // rax
char *v24; // [rsp+0h] [rbp-D0h]
char *ptr; // [rsp+8h] [rbp-C8h]
void *ptra; // [rsp+8h] [rbp-C8h]
_BYTE *ptrb; // [rsp+8h] [rbp-C8h]
_BYTE *ptrc; // [rsp+8h] [rbp-C8h]
int v29; // [rsp+14h] [rbp-BCh] BYREF
void *v30; // [rsp+18h] [rbp-B8h] BYREF
int longind[44]; // [rsp+20h] [rbp-B0h] BYREF

v3 = 0LL;
v4 = -1;
v5 = "127.0.0.1";
v24 = "3636";
ptr = "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':
ptr = optarg;
continue;
case 'f':
v4 = atoi(optarg);
continue;
case 'i':
v5 = optarg;
continue;
case 'm':
v3 = optarg;
continue;
case 'p':
v24 = optarg;
continue;
case 'v':
verbose = 1;
continue;
default:
fwrite("Illegal option\n", 1uLL, 0xFuLL, stderr);
showHelp(stderr);
exit(1);
}
}
break;
}
v8 = ook_open(ptr, v24, v5);
if ( v8 < 0 )
{
fwrite("Failed to open multicast interface\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v9 = (char *)malloc(0x1000uLL);
while ( 1 )
{
v29 = 128;
v10 = ook_decode_from_socket((unsigned int)v8, &v30, longind, &v29, (unsigned int)verbose);
if ( v10 < 0 )
break;
if ( v10 )
{
v11 = v30;
memset(v9, 0, 0x1000uLL);
if ( v11[2] )
{
v12 = v11 + 5;
v13 = 0;
v14 = 0LL;
do
{
v9[v14] = 1;
v15 = *v12 / 0x3D090u;
v16 = v15 - 1;
if ( (_BYTE)v15 )
{
v17 = &v9[v14 + 1];
v18 = v16 + 1LL;
if ( (unsigned int)v18 < 8 )
{
if ( (v18 & 4) != 0 )
{
*(_DWORD *)v17 = 0;
*(_DWORD *)&v17[v18 - 4] = 0;
}
else if ( v16 != -1 )
{
*v17 = 0;
if ( (v18 & 2) != 0 )
*(_WORD *)&v17[v18 - 2] = 0;
}
}
else
{
*(_QWORD *)v17 = 0LL;
*(_QWORD *)&v17[v18 - 8] = 0LL;
memset(
(void *)((unsigned __int64)(v17 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v18 + (_DWORD)v17 - (((_DWORD)v17 + 8) & 0xFFFFFFF8)) >> 3));
}
v14 += v16 + 2LL;
}
else
{
++v14;
}
++v13;
v12 += 3;
}
while ( v11[2] > v13 );
}
v19 = decode_nexa_p((__int64)v9);
v20 = v19;
if ( v19 )
{
if ( v4 == -1 || (*(_DWORD *)v19 & 0x3FFFFFF) == v4 )
{
if ( verbose )
{
v21 = "ON";
if ( (v19[3] & 8) == 0 )
v21 = "OFF";
ptrb = v19;
fprintf(stderr, "transmitter code: %d: %s\n", *(_DWORD *)v19 & 0x3FFFFFF, v21);
v20 = ptrb;
}
if ( v3 )
{
ptrc = v20;
send_statsd_gauge(v3);
v20 = ptrc;
}
}
}
else
{
fwrite("decoding error\n", 1uLL, 0xFuLL, stderr);
v20 = 0LL;
}
ptra = v20;
fflush(stdin);
free(ptra);
free(v30);
}
else
{
fwrite("Corrupt burst\n", 1uLL, 0xEuLL, stderr);
}
}
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "Failed to decode from socket: %s\n", v23);
free(v9);
close(v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
int v4; // er13
char *v5; // r15
int v6; // eax
int v8; // er12
char *v9; // r15
int v10; // eax
_DWORD *v11; // r10
_DWORD *v12; // r9
unsigned int v13; // er8
__int64 v14; // rsi
unsigned int v15; // edi
unsigned __int8 v16; // dl
char *v17; // rcx
__int64 v18; // rax
_BYTE *v19; // rax
_BYTE *v20; // r8
const char *v21; // rcx
int *v22; // rax
char *v23; // rax
char *v24; // [rsp+0h] [rbp-D0h]
char *ptr; // [rsp+8h] [rbp-C8h]
void *ptra; // [rsp+8h] [rbp-C8h]
_BYTE *ptrb; // [rsp+8h] [rbp-C8h]
_BYTE *ptrc; // [rsp+8h] [rbp-C8h]
int v29; // [rsp+14h] [rbp-BCh] BYREF
void *v30; // [rsp+18h] [rbp-B8h] BYREF
int longind[44]; // [rsp+20h] [rbp-B0h] BYREF

v3 = 0LL;
v4 = -1;
v5 = "127.0.0.1";
v24 = "3636";
ptr = "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':
ptr = optarg;
continue;
case 'f':
v4 = atoi(optarg);
continue;
case 'i':
v5 = optarg;
continue;
case 'm':
v3 = optarg;
continue;
case 'p':
v24 = optarg;
continue;
case 'v':
verbose = 1;
continue;
default:
fwrite("Illegal option\n", 1uLL, 0xFuLL, stderr);
func0(stderr);
exit(1);
}
}
break;
}
v8 = ook_open(ptr, v24, v5);
if ( v8 < 0 )
{
fwrite("Failed to open multicast interface\n", 1uLL, 0x23uLL, stderr);
exit(1);
}
v9 = (char *)malloc(0x1000uLL);
while ( 1 )
{
v29 = 128;
v10 = ook_decode_from_socket((unsigned int)v8, &v30, longind, &v29, (unsigned int)verbose);
if ( v10 < 0 )
break;
if ( v10 )
{
v11 = v30;
memset(v9, 0, 0x1000uLL);
if ( v11[2] )
{
v12 = v11 + 5;
v13 = 0;
v14 = 0LL;
do
{
v9[v14] = 1;
v15 = *v12 / 0x3D090u;
v16 = v15 - 1;
if ( (_BYTE)v15 )
{
v17 = &v9[v14 + 1];
v18 = v16 + 1LL;
if ( (unsigned int)v18 < 8 )
{
if ( (v18 & 4) != 0 )
{
*(_DWORD *)v17 = 0;
*(_DWORD *)&v17[v18 - 4] = 0;
}
else if ( v16 != -1 )
{
*v17 = 0;
if ( (v18 & 2) != 0 )
*(_WORD *)&v17[v18 - 2] = 0;
}
}
else
{
*(_QWORD *)v17 = 0LL;
*(_QWORD *)&v17[v18 - 8] = 0LL;
memset(
(void *)((unsigned __int64)(v17 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v18 + (_DWORD)v17 - (((_DWORD)v17 + 8) & 0xFFFFFFF8)) >> 3));
}
v14 += v16 + 2LL;
}
else
{
++v14;
}
++v13;
v12 += 3;
}
while ( v11[2] > v13 );
}
v19 = decode_nexa_p((__int64)v9);
v20 = v19;
if ( v19 )
{
if ( v4 == -1 || (*(_DWORD *)v19 & 0x3FFFFFF) == v4 )
{
if ( verbose )
{
v21 = "ON";
if ( (v19[3] & 8) == 0 )
v21 = "OFF";
ptrb = v19;
fprintf(stderr, "transmitter code: %d: %s\n", *(_DWORD *)v19 & 0x3FFFFFF, v21);
v20 = ptrb;
}
if ( v3 )
{
ptrc = v20;
func6(v3);
v20 = ptrc;
}
}
}
else
{
fwrite("decoding error\n", 1uLL, 0xFuLL, stderr);
v20 = 0LL;
}
ptra = v20;
fflush(stdin);
free(ptra);
free(v30);
}
else
{
fwrite("Corrupt burst\n", 1uLL, 0xEuLL, stderr);
}
}
v22 = _errno_location();
v23 = strerror(*v22);
fprintf(stderr, "Failed to decode from socket: %s\n", v23);
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; } *


countLines

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

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

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

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
++v2;
v3 += v1 == 10;
v1 = *(v2 - 1);
}
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


main

repo: jinie/memmgr

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
char *v4; // r14
void *v5; // r12
__int64 v6; // r13
__int64 v7; // rax
unsigned int v8; // ebp
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
__int64 v14[2]; // [rsp+4h] [rbp-44h] BYREF
int v15; // [rsp+14h] [rbp-34h]
char v16; // [rsp+18h] [rbp-30h] BYREF

v3 = 16;
v4 = (char *)v14;
v5 = malloc(0x1F4000uLL);
m_init(v5, 2048000LL);
v15 = 1;
v14[0] = 0x410000000DLL;
v14[1] = 0xB600000033LL;
v6 = m_free_heap();
v7 = m_largest_free_block();
printf("Largest block available %ld, free heap size %ld\n", v7, v6);
while ( 1 )
{
printf("Allocating all memory in %d byte blocks\n", (unsigned int)v3);
v8 = allocate_all(&ptarr_0, v3);
v9 = m_free_heap();
v10 = m_largest_free_block();
printf("Allocation failed for block %d, largest block available %u, free heap size %ld\n", v8, v10, v9);
printf("Deallocating %d blocks\n", v8);
free_all(&ptarr_0);
v11 = m_free_heap();
v12 = m_largest_free_block();
printf("Deallocation done, largest block available %ld, free heap size %ld\n", v12, v11);
puts("================================================================================");
if ( v4 == &v16 )
break;
v3 = *(_DWORD *)v4;
v4 += 4;
}
m_destroy();
free(v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
char *v4; // r14
void *v5; // r12
__int64 v6; // r13
__int64 v7; // rax
unsigned int v8; // ebp
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
__int64 v14[2]; // [rsp+4h] [rbp-44h] BYREF
int v15; // [rsp+14h] [rbp-34h]
char v16; // [rsp+18h] [rbp-30h] BYREF

v3 = 16;
v4 = (char *)v14;
v5 = malloc(0x1F4000uLL);
func7(v5, 2048000LL);
v15 = 1;
v14[0] = 0x410000000DLL;
v14[1] = 0xB600000033LL;
v6 = func11();
v7 = func10();
printf("Largest block available %ld, free heap size %ld\n", v7, v6);
while ( 1 )
{
printf("Allocating all memory in %d byte blocks\n", (unsigned int)v3);
v8 = func17(&ptarr_0, v3);
v9 = func11();
v10 = func10();
printf("Allocation failed for block %d, largest block available %u, free heap size %ld\n", v8, v10, v9);
printf("Deallocating %d blocks\n", v8);
free_all(&ptarr_0);
v11 = func11();
v12 = func10();
printf("Deallocation done, largest block available %ld, free heap size %ld\n", v12, v11);
puts("================================================================================");
if ( v4 == &v16 )
break;
v3 = *(_DWORD *)v4;
v4 += 4;
}
func8();
free(v5);
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 []


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)
{
__int64 v1; // rdx
unsigned __int64 *v2; // rax
unsigned __int64 v3; // rcx
unsigned __int64 *v4; // rsi
__int64 v5; // r8
unsigned __int64 v6; // rdx
_QWORD *v8; // rdi

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

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

v1 = 8LL;
v2 = (unsigned __int64 *)FBLHeader;
if ( a1 >= 8 )
v1 = a1;
v3 = (v1 & 3) + v1 + 8;
if ( !a1 || !heaparea )
__assert_fail("blocksize > 0 && heaparea != 0", "memmgr.c", 0x44u, "m_malloc");
v4 = 0LL;
v5 = 0LL;
if ( FBLHeader )
{
while ( 1 )
{
v6 = *v2;
v5 = v2[1];
if ( *v2 >= v3 )
break;
v4 = v2;
if ( !v5 )
return v5;
v2 = (unsigned __int64 *)v2[1];
}
if ( *v2 > v3 )
{
v8 = (unsigned __int64 *)((char *)v2 + v3);
*v8 = v6 - v3;
v6 = v3;
v8[1] = v5;
v5 = (__int64)v2 + v3;
if ( v4 )
goto LABEL_12;
}
else if ( v4 )
{
LABEL_12:
v4[1] = v5;
LABEL_13:
v2[1] = 0LL;
v5 = (__int64)(v2 + 1);
*v2 = v6;
return v5;
}
FBLHeader = v5;
goto LABEL_13;
}
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; // r8
unsigned __int64 v2; // rdx

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

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

v0 = (unsigned __int64 *)FBLHeader;
if ( !heaparea )
__assert_fail("heaparea", "memmgr.c", 0xA8u, "m_largest_free_block");
v1 = 0LL;
if ( FBLHeader )
{
do
{
v2 = *v0;
v0 = (unsigned __int64 *)v0[1];
if ( v1 < v2 )
v1 = v2;
}
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; // r8

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; // r8

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

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

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

result = 0LL;
if ( *a1 )
{
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 0LL;
v3 = 1LL;
do
{
*(_QWORD *)(a1 + 8 * v3 - 8) = v2;
v4 = v3++;
v2 = m_malloc(a2);
}
while ( v2 );
return v4;
}

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

v2 = func9(a2);
if ( !v2 )
return 0LL;
v3 = 1LL;
do
{
*(_QWORD *)(a1 + 8 * v3 - 8) = v2;
v4 = v3++;
v2 = func9(a2);
}
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 *


repo: jintwo/sns

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

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

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

if ( a1 )
{
v2 = a1;
v3 = 0LL;
v4 = 0LL;
do
{
src = *(const char **)v2;
v5 = strlen(*(const char **)v2);
v3 += v5 + 1;
v6 = malloc(v5 + 1);
memcpy(v6, src, v5);
*((_BYTE *)v6 + v5) = 46;
if ( v4 )
v4 = realloc(v4, v3);
else
v4 = malloc(v3);
strcat((char *)v4, (const char *)v6);
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 );
v7 = (__int64)v4 + v3 - 1;
}
else
{
v4 = 0LL;
v7 = -1LL;
v3 = 0LL;
}
*(_BYTE *)v7 = 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)
{
unsigned int v2; // er15
__m128i *v3; // r13
__m128i *v4; // r12
__int64 v5; // rbx
__int64 v6; // rbp
const char *v7; // rsi

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);
v6 = reverse_label((__int64)v4);
if ( v5 == v6 )
{
LABEL_9:
v2 = 0;
}
else
{
while ( 1 )
{
if ( v5 && **(_BYTE **)v5 == 42 && !*(_BYTE *)(*(_QWORD *)v5 + 1LL) )
goto LABEL_13;
if ( !v6 )
break;
v7 = *(const char **)v6;
if ( **(_BYTE **)v6 == 42 && !v7[1] )
{
LABEL_13:
v2 = 1;
goto LABEL_10;
}
if ( !v5 )
break;
if ( !strcmp(*(const char **)v5, v7) )
{
v5 = *(_QWORD *)(v5 + 8);
v6 = *(_QWORD *)(v6 + 8);
if ( v5 != v6 )
continue;
}
goto LABEL_9;
}
LOBYTE(v2) = (v6 | v5) == 0;
}
LABEL_10:
free(v3);
free(v4);
}
return 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, __int64 *a2)
{
__int64 v2; // rbx
size_t v3; // r13
void *v4; // r12
size_t v5; // rax
size_t v6; // r14
char v7; // r15
char *v8; // rax
const char *v9; // rbp
__int64 v10; // r13
const char *src; // [rsp+0h] [rbp-48h]

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

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

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

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; // r12
__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; // r12
__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)
{
char *v3; // r14
_QWORD *v4; // rax
size_t v5; // rbx
_QWORD *v6; // rbp
_QWORD *v7; // r13
void *v8; // rax
size_t v9; // rdx
char *v10; // rsi
char *v11; // rbx
_QWORD *v12; // rax
__int64 v13; // rax

v3 = a1 + 1;
v4 = malloc(0x10uLL);
*a2 = v4;
v5 = (char)*a1;
if ( !*a1 )
unpack_question_cold();
v6 = v4;
do
{
v7 = v6;
v8 = malloc(v5);
v9 = v5;
v10 = v3;
v11 = &v3[v5];
*v6 = v8;
v3 = v11 + 1;
memcpy(v8, v10, v9);
v12 = malloc(0x10uLL);
v6[1] = v12;
v5 = *v11;
v6 = v12;
}
while ( v5 );
free(v12);
v7[1] = 0LL;
v13 = read_uint16(v3, a2 + 1, 1LL);
return read_uint16(v13, (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
char *v3; // rbp
__int64 v4; // rsi

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

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

v2 = a1;
printf("dump_buffer: ");
if ( a2 )
{
v3 = &a1[a2];
do
{
v4 = (unsigned int)*v2++;
printf("0x%hhx ", v4);
}
while ( v2 != v3 );
}
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

if ( unk_16E0[148] || *(float *)&f_cmdline_reply_time != 0.0 && cls[1] - *(float *)&f_cmdline_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_cmdline") )
return 0LL;
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");
}
result = 1LL;
*(float *)&v2 = cls[1];
f_cmdline_reply_time = v2;
return result;
}

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

if ( unk_16E0[148] || *(float *)&f_cmdline_reply_time != 0.0 && cls[1] - *(float *)&f_cmdline_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_cmdline") )
return 0LL;
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");
}
result = 1LL;
*(float *)&v2 = cls[1];
f_cmdline_reply_time = v2;
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

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

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

if ( unk_16E0[148] || *(float *)&f_scripts_reply_time != 0.0 && cls[1] - *(float *)&f_scripts_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_scripts") )
return 0LL;
func1(a1, (__int64)"f_scripts");
result = 1LL;
*(float *)&v2 = cls[1];
f_scripts_reply_time = v2;
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

if ( unk_16E0[148] || *(float *)&f_version_reply_time != 0.0 && cls[1] - *(float *)&f_version_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_version") )
return 0LL;
FChecks_VersionResponse();
result = 1LL;
*(float *)&v2 = cls[1];
f_version_reply_time = v2;
return result;
}

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

if ( unk_16E0[148] || *(float *)&f_version_reply_time != 0.0 && cls[1] - *(float *)&f_version_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_version") )
return 0LL;
func4();
result = 1LL;
*(float *)&v2 = cls[1];
f_version_reply_time = v2;
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

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

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

if ( unk_16E0[148] || *(float *)&f_fshaft_reply_time != 0.0 && cls[1] - *(float *)&f_fshaft_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_fakeshaft") )
return 0LL;
func7(a1, (__int64)"f_fakeshaft");
result = 1LL;
*(float *)&v2 = cls[1];
f_fshaft_reply_time = v2;
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; // rbp
int v3; // xmm0_4

if ( unk_16E0[148] || *(float *)&f_system_reply_time != 0.0 && cls[1] - *(float *)&f_system_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_system") )
return 0LL;
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");
result = 1LL;
*(float *)&v3 = cls[1];
f_system_reply_time = v3;
return result;
}

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

if ( unk_16E0[148] || *(float *)&f_system_reply_time != 0.0 && cls[1] - *(float *)&f_system_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_system") )
return 0LL;
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");
result = 1LL;
*(float *)&v3 = cls[1];
f_system_reply_time = v3;
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
int v2; // eax
float v3; // xmm0_4
int v4; // edx
float v5; // xmm2_4
int v6; // xmm0_4
_BYTE *v7; // rax
_BYTE *v8; // r12
float v9; // xmm0_4

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

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

if ( HIDWORD(cls[1213]) )
{
LABEL_4:
v2 = 1;
goto LABEL_5;
}
if ( unk_16E0[148] )
return 0LL;
v7 = (_BYTE *)Info_ValueForKey((unsigned int)((_DWORD)unk_16E0 + 4), "fbskins");
v8 = v7;
if ( !*v7 )
{
if ( unk_16E0[133] )
{
v4 = unk_16E0[148];
v5 = 0.0;
goto LABEL_7;
}
goto LABEL_4;
}
v9 = Q_atof(v7);
v4 = unk_16E0[148];
v5 = 0.0;
if ( v9 < 0.0 )
goto LABEL_7;
v5 = 0.0;
if ( Q_atof(v8) > 1.0 )
goto LABEL_4;
v2 = (int)Q_atof(v8);
if ( !v2 )
{
v4 = unk_16E0[148];
goto LABEL_7;
}
LABEL_5:
v3 = r_fullbrightSkins[8];
v4 = unk_16E0[148];
v5 = 0.0;
if ( v3 >= 0.0 )
v5 = fminf((float)v2, v3);
LABEL_7:
if ( v4
|| *(float *)&f_skins_reply_time != 0.0 && cls[1] - *(float *)&f_skins_reply_time < 20.0
|| !(unsigned int)Util_F_Match(a1, "f_skins") )
{
return 0LL;
}
func6(v5);
result = 1LL;
*(float *)&v6 = cls[1];
f_skins_reply_time = v6;
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

if ( unk_16E0[148] || *(float *)&f_mod_reply_time != 0.0 && cls[1] - *(float *)&f_mod_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_modified") )
return 0LL;
FMod_Response();
result = 1LL;
*(float *)&v2 = cls[1];
f_mod_reply_time = v2;
return result;
}

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

if ( unk_16E0[148] || *(float *)&f_mod_reply_time != 0.0 && cls[1] - *(float *)&f_mod_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_modified") )
return 0LL;
FMod_Response();
result = 1LL;
*(float *)&v2 = cls[1];
f_mod_reply_time = v2;
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

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

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

if ( unk_16E0[148] || *(float *)&f_server_reply_time != 0.0 && cls[1] - *(float *)&f_server_reply_time < 20.0 )
return 0LL;
if ( !(unsigned int)Util_F_Match(a1, "f_server")
|| !(unsigned int)NET_StringToAdr((unsigned int)((_DWORD)cls + 3480), &v3) )
{
return 0LL;
}
func13();
result = 1LL;
*(float *)&v2 = cls[1];
f_server_reply_time = v2;
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)
{
if ( !a1 )
{
a4 = a6;
a3 = a5;
}
return strlcat(a3, a2, a4);
}

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 *